Commit | Line | Data |
---|---|---|
f466c6fd | 1 | #include "reiserfs.h" |
16f7e0fe | 2 | #include <linux/capability.h> |
1da177e4 LT |
3 | #include <linux/errno.h> |
4 | #include <linux/fs.h> | |
5 | #include <linux/pagemap.h> | |
6 | #include <linux/xattr.h> | |
c45ac888 | 7 | #include "xattr.h" |
17093991 | 8 | #include <linux/uaccess.h> |
1da177e4 | 9 | |
1da177e4 | 10 | static int |
431547b3 CH |
11 | trusted_get(struct dentry *dentry, const char *name, void *buffer, size_t size, |
12 | int handler_flags) | |
1da177e4 | 13 | { |
bd4c625c LT |
14 | if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) |
15 | return -EINVAL; | |
1da177e4 | 16 | |
2b0143b5 | 17 | if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(d_inode(dentry))) |
bd4c625c | 18 | return -EPERM; |
1da177e4 | 19 | |
2b0143b5 | 20 | return reiserfs_xattr_get(d_inode(dentry), name, buffer, size); |
1da177e4 LT |
21 | } |
22 | ||
23 | static int | |
431547b3 CH |
24 | trusted_set(struct dentry *dentry, const char *name, const void *buffer, |
25 | size_t size, int flags, int handler_flags) | |
1da177e4 | 26 | { |
bd4c625c LT |
27 | if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) |
28 | return -EINVAL; | |
1da177e4 | 29 | |
2b0143b5 | 30 | if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(d_inode(dentry))) |
bd4c625c | 31 | return -EPERM; |
1da177e4 | 32 | |
2b0143b5 | 33 | return reiserfs_xattr_set(d_inode(dentry), name, buffer, size, flags); |
1da177e4 LT |
34 | } |
35 | ||
431547b3 CH |
36 | static size_t trusted_list(struct dentry *dentry, char *list, size_t list_size, |
37 | const char *name, size_t name_len, int handler_flags) | |
1da177e4 | 38 | { |
48b32a35 | 39 | const size_t len = name_len + 1; |
1da177e4 | 40 | |
2b0143b5 | 41 | if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(d_inode(dentry))) |
bd4c625c | 42 | return 0; |
1da177e4 | 43 | |
48b32a35 JM |
44 | if (list && len <= list_size) { |
45 | memcpy(list, name, name_len); | |
46 | list[name_len] = '\0'; | |
47 | } | |
bd4c625c | 48 | return len; |
1da177e4 LT |
49 | } |
50 | ||
94d09a98 | 51 | const struct xattr_handler reiserfs_xattr_trusted_handler = { |
1da177e4 LT |
52 | .prefix = XATTR_TRUSTED_PREFIX, |
53 | .get = trusted_get, | |
54 | .set = trusted_set, | |
1da177e4 LT |
55 | .list = trusted_list, |
56 | }; |