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 | 1709399 | 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 |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 11 | trusted_get(const struct xattr_handler *handler, struct dentry *unused, |
| 12 | struct inode *inode, const char *name, void *buffer, size_t size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 14 | if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode)) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 15 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 17 | return reiserfs_xattr_get(inode, xattr_full_name(handler, name), |
Al Viro | 79a628d | 2016-04-10 18:50:48 -0400 | [diff] [blame] | 18 | buffer, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 22 | trusted_set(const struct xattr_handler *handler, struct dentry *unused, |
| 23 | struct inode *inode, const char *name, const void *buffer, |
| 24 | size_t size, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 26 | if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode)) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 27 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 29 | return reiserfs_xattr_set(inode, |
Al Viro | 79a628d | 2016-04-10 18:50:48 -0400 | [diff] [blame] | 30 | xattr_full_name(handler, name), |
| 31 | buffer, size, flags); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 34 | static bool trusted_list(struct dentry *dentry) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 35 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 36 | return capable(CAP_SYS_ADMIN) && !IS_PRIVATE(d_inode(dentry)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Stephen Hemminger | 94d09a9 | 2010-05-13 17:53:19 -0700 | [diff] [blame] | 39 | const struct xattr_handler reiserfs_xattr_trusted_handler = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | .prefix = XATTR_TRUSTED_PREFIX, |
| 41 | .get = trusted_get, |
| 42 | .set = trusted_set, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | .list = trusted_list, |
| 44 | }; |