Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/reiserfs_fs.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> |
| 7 | #include <linux/reiserfs_xattr.h> |
| 8 | #include <asm/uaccess.h> |
| 9 | |
| 10 | #define XATTR_TRUSTED_PREFIX "trusted." |
| 11 | |
| 12 | static int |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 13 | trusted_get(struct inode *inode, const char *name, void *buffer, size_t size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 15 | if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) |
| 16 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 18 | if (!reiserfs_xattrs(inode->i_sb)) |
| 19 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 21 | if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode))) |
| 22 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 24 | return reiserfs_xattr_get(inode, name, buffer, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | static int |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 28 | trusted_set(struct inode *inode, const char *name, const void *buffer, |
| 29 | size_t size, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 31 | if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) |
| 32 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 34 | if (!reiserfs_xattrs(inode->i_sb)) |
| 35 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 37 | if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode))) |
| 38 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 40 | return reiserfs_xattr_set(inode, name, buffer, size, flags); |
| 41 | } |
| 42 | |
| 43 | static int trusted_del(struct inode *inode, const char *name) |
| 44 | { |
| 45 | if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) |
| 46 | return -EINVAL; |
| 47 | |
| 48 | if (!reiserfs_xattrs(inode->i_sb)) |
| 49 | return -EOPNOTSUPP; |
| 50 | |
| 51 | if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode))) |
| 52 | return -EPERM; |
| 53 | |
| 54 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | static int |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 58 | trusted_list(struct inode *inode, const char *name, int namelen, char *out) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 60 | int len = namelen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 62 | if (!reiserfs_xattrs(inode->i_sb)) |
| 63 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 65 | if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode))) |
| 66 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 68 | if (out) |
| 69 | memcpy(out, name, len); |
| 70 | |
| 71 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | struct reiserfs_xattr_handler trusted_handler = { |
| 75 | .prefix = XATTR_TRUSTED_PREFIX, |
| 76 | .get = trusted_get, |
| 77 | .set = trusted_set, |
| 78 | .del = trusted_del, |
| 79 | .list = trusted_list, |
| 80 | }; |