blob: 2501f7e66ab9413effe8c08ec8607b9f90cb3b65 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/reiserfs_fs.h>
2#include <linux/errno.h>
3#include <linux/fs.h>
4#include <linux/pagemap.h>
5#include <linux/xattr.h>
6#include <linux/reiserfs_xattr.h>
7#include <asm/uaccess.h>
8
9#define XATTR_TRUSTED_PREFIX "trusted."
10
11static int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070012trusted_get(struct inode *inode, const char *name, void *buffer, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070013{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070014 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
15 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070017 if (!reiserfs_xattrs(inode->i_sb))
18 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070020 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
21 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070023 return reiserfs_xattr_get(inode, name, buffer, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024}
25
26static int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070027trusted_set(struct inode *inode, const char *name, const void *buffer,
28 size_t size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070030 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
31 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070033 if (!reiserfs_xattrs(inode->i_sb))
34 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070036 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
37 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070039 return reiserfs_xattr_set(inode, name, buffer, size, flags);
40}
41
42static int trusted_del(struct inode *inode, const char *name)
43{
44 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
45 return -EINVAL;
46
47 if (!reiserfs_xattrs(inode->i_sb))
48 return -EOPNOTSUPP;
49
50 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
51 return -EPERM;
52
53 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054}
55
56static int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070057trusted_list(struct inode *inode, const char *name, int namelen, char *out)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070059 int len = namelen;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070061 if (!reiserfs_xattrs(inode->i_sb))
62 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070064 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
65 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070067 if (out)
68 memcpy(out, name, len);
69
70 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073struct reiserfs_xattr_handler trusted_handler = {
74 .prefix = XATTR_TRUSTED_PREFIX,
75 .get = trusted_get,
76 .set = trusted_set,
77 .del = trusted_del,
78 .list = trusted_list,
79};