Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-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 (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
17                 return -EPERM;
18
19         return reiserfs_xattr_get(inode, name, buffer, size);
20 }
21
22 static int
23 trusted_set(struct inode *inode, const char *name, const void *buffer,
24             size_t size, int flags)
25 {
26         if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
27                 return -EINVAL;
28
29         if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
30                 return -EPERM;
31
32         return reiserfs_xattr_set(inode, name, buffer, size, flags);
33 }
34
35 static size_t trusted_list(struct inode *inode, char *list, size_t list_size,
36                            const char *name, size_t name_len)
37 {
38         const size_t len = name_len + 1;
39
40         if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
41                 return 0;
42
43         if (list && len <= list_size) {
44                 memcpy(list, name, name_len);
45                 list[name_len] = '\0';
46         }
47         return len;
48 }
49
50 struct xattr_handler reiserfs_xattr_trusted_handler = {
51         .prefix = XATTR_TRUSTED_PREFIX,
52         .get = trusted_get,
53         .set = trusted_set,
54         .list = trusted_list,
55 };