Kyle Swenson | 8d8f654 | 2021-03-15 11:02:55 -0600 | [diff] [blame^] | 1 | #include "reiserfs.h" |
| 2 | #include <linux/capability.h> |
| 3 | #include <linux/errno.h> |
| 4 | #include <linux/fs.h> |
| 5 | #include <linux/pagemap.h> |
| 6 | #include <linux/xattr.h> |
| 7 | #include "xattr.h" |
| 8 | #include <linux/uaccess.h> |
| 9 | |
| 10 | static int |
| 11 | trusted_get(const struct xattr_handler *handler, struct dentry *dentry, |
| 12 | const char *name, void *buffer, size_t size) |
| 13 | { |
| 14 | if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(d_inode(dentry))) |
| 15 | return -EPERM; |
| 16 | |
| 17 | return reiserfs_xattr_get(d_inode(dentry), |
| 18 | xattr_full_name(handler, name), |
| 19 | buffer, size); |
| 20 | } |
| 21 | |
| 22 | static int |
| 23 | trusted_set(const struct xattr_handler *handler, struct dentry *dentry, |
| 24 | const char *name, const void *buffer, size_t size, int flags) |
| 25 | { |
| 26 | if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(d_inode(dentry))) |
| 27 | return -EPERM; |
| 28 | |
| 29 | return reiserfs_xattr_set(d_inode(dentry), |
| 30 | xattr_full_name(handler, name), |
| 31 | buffer, size, flags); |
| 32 | } |
| 33 | |
| 34 | static size_t trusted_list(const struct xattr_handler *handler, |
| 35 | struct dentry *dentry, char *list, size_t list_size, |
| 36 | const char *name, size_t name_len) |
| 37 | { |
| 38 | const size_t len = name_len + 1; |
| 39 | |
| 40 | if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(d_inode(dentry))) |
| 41 | return 0; |
| 42 | |
| 43 | if (list && len <= list_size) { |
| 44 | memcpy(list, name, name_len); |
| 45 | list[name_len] = '\0'; |
| 46 | } |
| 47 | return len; |
| 48 | } |
| 49 | |
| 50 | const struct xattr_handler reiserfs_xattr_trusted_handler = { |
| 51 | .prefix = XATTR_TRUSTED_PREFIX, |
| 52 | .get = trusted_get, |
| 53 | .set = trusted_set, |
| 54 | .list = trusted_list, |
| 55 | }; |