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