blob: 024a938ca60f1a77238703f648f78733f64f8df4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/reiserfs_fs.h>
Randy Dunlap16f7e0f2006-01-11 12:17:46 -08002#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07003#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
12static int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070013trusted_get(struct inode *inode, const char *name, void *buffer, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070014{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070015 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
16 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070018 if (!reiserfs_xattrs(inode->i_sb))
19 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070021 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
22 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070024 return reiserfs_xattr_get(inode, name, buffer, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025}
26
27static int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070028trusted_set(struct inode *inode, const char *name, const void *buffer,
29 size_t size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070031 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
32 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070034 if (!reiserfs_xattrs(inode->i_sb))
35 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070037 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
38 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070040 return reiserfs_xattr_set(inode, name, buffer, size, flags);
41}
42
43static 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 Torvalds1da177e2005-04-16 15:20:36 -070055}
56
57static int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070058trusted_list(struct inode *inode, const char *name, int namelen, char *out)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070060 int len = namelen;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070062 if (!reiserfs_xattrs(inode->i_sb))
63 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070065 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
66 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070068 if (out)
69 memcpy(out, name, len);
70
71 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074struct 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};