These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / fs / reiserfs / xattr_trusted.c
1 #include "reiserfs.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 "xattr.h"
8 #include <linux/uaccess.h>
9
10 static int
11 trusted_get(const struct xattr_handler *handler, struct dentry *dentry,
12             const char *name, void *buffer, size_t size)
13 {
14         if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
15                 return -EINVAL;
16
17         if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(d_inode(dentry)))
18                 return -EPERM;
19
20         return reiserfs_xattr_get(d_inode(dentry), name, buffer, size);
21 }
22
23 static int
24 trusted_set(const struct xattr_handler *handler, struct dentry *dentry,
25             const char *name, const void *buffer, size_t size, int flags)
26 {
27         if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
28                 return -EINVAL;
29
30         if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(d_inode(dentry)))
31                 return -EPERM;
32
33         return reiserfs_xattr_set(d_inode(dentry), name, buffer, size, flags);
34 }
35
36 static size_t trusted_list(const struct xattr_handler *handler,
37                            struct dentry *dentry, char *list, size_t list_size,
38                            const char *name, size_t name_len)
39 {
40         const size_t len = name_len + 1;
41
42         if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(d_inode(dentry)))
43                 return 0;
44
45         if (list && len <= list_size) {
46                 memcpy(list, name, name_len);
47                 list[name_len] = '\0';
48         }
49         return len;
50 }
51
52 const struct xattr_handler reiserfs_xattr_trusted_handler = {
53         .prefix = XATTR_TRUSTED_PREFIX,
54         .get = trusted_get,
55         .set = trusted_set,
56         .list = trusted_list,
57 };