Al Viro | f466c6f | 2012-03-17 01:16:43 -0400 | [diff] [blame] | 1 | #include "reiserfs.h" |
Randy Dunlap | 16f7e0f | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 2 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | #include <linux/errno.h> |
| 4 | #include <linux/fs.h> |
| 5 | #include <linux/pagemap.h> |
| 6 | #include <linux/xattr.h> |
Al Viro | c45ac88 | 2012-03-17 00:59:06 -0400 | [diff] [blame] | 7 | #include "xattr.h" |
Fabian Frederick | 17093991 | 2014-08-08 14:21:12 -0700 | [diff] [blame] | 8 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | static int |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 11 | trusted_get(const struct xattr_handler *handler, struct dentry *dentry, |
| 12 | const char *name, void *buffer, size_t size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 14 | if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) |
| 15 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 17 | if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(d_inode(dentry))) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 18 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 20 | return reiserfs_xattr_get(d_inode(dentry), name, buffer, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | static int |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 24 | trusted_set(const struct xattr_handler *handler, struct dentry *dentry, |
| 25 | const char *name, const void *buffer, size_t size, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 27 | if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) |
| 28 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 30 | if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(d_inode(dentry))) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 31 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 33 | return reiserfs_xattr_set(d_inode(dentry), name, buffer, size, flags); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 36 | static size_t trusted_list(const struct xattr_handler *handler, |
| 37 | struct dentry *dentry, char *list, size_t list_size, |
| 38 | const char *name, size_t name_len) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 39 | { |
Jeff Mahoney | 48b32a3 | 2009-03-30 14:02:38 -0400 | [diff] [blame] | 40 | const size_t len = name_len + 1; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 41 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 42 | if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(d_inode(dentry))) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 43 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Jeff Mahoney | 48b32a3 | 2009-03-30 14:02:38 -0400 | [diff] [blame] | 45 | if (list && len <= list_size) { |
| 46 | memcpy(list, name, name_len); |
| 47 | list[name_len] = '\0'; |
| 48 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 49 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Stephen Hemminger | 94d09a9 | 2010-05-13 17:53:19 -0700 | [diff] [blame] | 52 | const struct xattr_handler reiserfs_xattr_trusted_handler = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | .prefix = XATTR_TRUSTED_PREFIX, |
| 54 | .get = trusted_get, |
| 55 | .set = trusted_set, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | .list = trusted_list, |
| 57 | }; |