]> bbs.cooldavid.org Git - net-next-2.6.git/blame - fs/reiserfs/xattr_trusted.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6
[net-next-2.6.git] / fs / reiserfs / xattr_trusted.c
CommitLineData
1da177e4 1#include <linux/reiserfs_fs.h>
16f7e0fe 2#include <linux/capability.h>
1da177e4
LT
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
1da177e4 10static int
431547b3
CH
11trusted_get(struct dentry *dentry, const char *name, void *buffer, size_t size,
12 int handler_flags)
1da177e4 13{
bd4c625c
LT
14 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
15 return -EINVAL;
1da177e4 16
431547b3 17 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(dentry->d_inode))
bd4c625c 18 return -EPERM;
1da177e4 19
431547b3 20 return reiserfs_xattr_get(dentry->d_inode, name, buffer, size);
1da177e4
LT
21}
22
23static int
431547b3
CH
24trusted_set(struct dentry *dentry, const char *name, const void *buffer,
25 size_t size, int flags, int handler_flags)
1da177e4 26{
bd4c625c
LT
27 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
28 return -EINVAL;
1da177e4 29
431547b3 30 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(dentry->d_inode))
bd4c625c 31 return -EPERM;
1da177e4 32
431547b3 33 return reiserfs_xattr_set(dentry->d_inode, name, buffer, size, flags);
1da177e4
LT
34}
35
431547b3
CH
36static size_t trusted_list(struct dentry *dentry, char *list, size_t list_size,
37 const char *name, size_t name_len, int handler_flags)
1da177e4 38{
48b32a35 39 const size_t len = name_len + 1;
1da177e4 40
431547b3 41 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(dentry->d_inode))
bd4c625c 42 return 0;
1da177e4 43
48b32a35
JM
44 if (list && len <= list_size) {
45 memcpy(list, name, name_len);
46 list[name_len] = '\0';
47 }
bd4c625c 48 return len;
1da177e4
LT
49}
50
94d09a98 51const struct xattr_handler reiserfs_xattr_trusted_handler = {
1da177e4
LT
52 .prefix = XATTR_TRUSTED_PREFIX,
53 .get = trusted_get,
54 .set = trusted_set,
1da177e4
LT
55 .list = trusted_list,
56};