Merge git://git.infradead.org/~dwmw2/random-2.6
[pandora-kernel.git] / fs / reiserfs / xattr_trusted.c
1 #include <linux/reiserfs_fs.h>
2 #include <linux/capability.h>
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 static int
11 trusted_get(struct inode *inode, const char *name, void *buffer, size_t size)
12 {
13         if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
14                 return -EINVAL;
15
16         if (!reiserfs_xattrs(inode->i_sb))
17                 return -EOPNOTSUPP;
18
19         if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
20                 return -EPERM;
21
22         return reiserfs_xattr_get(inode, name, buffer, size);
23 }
24
25 static int
26 trusted_set(struct inode *inode, const char *name, const void *buffer,
27             size_t size, int flags)
28 {
29         if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
30                 return -EINVAL;
31
32         if (!reiserfs_xattrs(inode->i_sb))
33                 return -EOPNOTSUPP;
34
35         if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
36                 return -EPERM;
37
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;
53 }
54
55 static int
56 trusted_list(struct inode *inode, const char *name, int namelen, char *out)
57 {
58         int len = namelen;
59
60         if (!reiserfs_xattrs(inode->i_sb))
61                 return 0;
62
63         if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
64                 return 0;
65
66         if (out)
67                 memcpy(out, name, len);
68
69         return len;
70 }
71
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 };