Merge tag 'arm64-stable' of git://git.kernel.org/pub/scm/linux/kernel/git/cmarinas...
[linux-2.6.git] / fs / hfsplus / xattr_security.c
blob83b842f113c5924ccaf91607ae9158695eb6a273
1 /*
2 * linux/fs/hfsplus/xattr_trusted.c
4 * Vyacheslav Dubeyko <slava@dubeyko.com>
6 * Handler for storing security labels as extended attributes.
7 */
9 #include <linux/security.h>
10 #include "hfsplus_fs.h"
11 #include "xattr.h"
13 static int hfsplus_security_getxattr(struct dentry *dentry, const char *name,
14 void *buffer, size_t size, int type)
16 char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] = {0};
17 size_t len = strlen(name);
19 if (!strcmp(name, ""))
20 return -EINVAL;
22 if (len + XATTR_SECURITY_PREFIX_LEN > HFSPLUS_ATTR_MAX_STRLEN)
23 return -EOPNOTSUPP;
25 strcpy(xattr_name, XATTR_SECURITY_PREFIX);
26 strcpy(xattr_name + XATTR_SECURITY_PREFIX_LEN, name);
28 return hfsplus_getxattr(dentry, xattr_name, buffer, size);
31 static int hfsplus_security_setxattr(struct dentry *dentry, const char *name,
32 const void *buffer, size_t size, int flags, int type)
34 char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] = {0};
35 size_t len = strlen(name);
37 if (!strcmp(name, ""))
38 return -EINVAL;
40 if (len + XATTR_SECURITY_PREFIX_LEN > HFSPLUS_ATTR_MAX_STRLEN)
41 return -EOPNOTSUPP;
43 strcpy(xattr_name, XATTR_SECURITY_PREFIX);
44 strcpy(xattr_name + XATTR_SECURITY_PREFIX_LEN, name);
46 return hfsplus_setxattr(dentry, xattr_name, buffer, size, flags);
49 static size_t hfsplus_security_listxattr(struct dentry *dentry, char *list,
50 size_t list_size, const char *name, size_t name_len, int type)
53 * This method is not used.
54 * It is used hfsplus_listxattr() instead of generic_listxattr().
56 return -EOPNOTSUPP;
59 static int hfsplus_initxattrs(struct inode *inode,
60 const struct xattr *xattr_array,
61 void *fs_info)
63 const struct xattr *xattr;
64 char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] = {0};
65 size_t xattr_name_len;
66 int err = 0;
68 for (xattr = xattr_array; xattr->name != NULL; xattr++) {
69 xattr_name_len = strlen(xattr->name);
71 if (xattr_name_len == 0)
72 continue;
74 if (xattr_name_len + XATTR_SECURITY_PREFIX_LEN >
75 HFSPLUS_ATTR_MAX_STRLEN)
76 return -EOPNOTSUPP;
78 strcpy(xattr_name, XATTR_SECURITY_PREFIX);
79 strcpy(xattr_name +
80 XATTR_SECURITY_PREFIX_LEN, xattr->name);
81 memset(xattr_name +
82 XATTR_SECURITY_PREFIX_LEN + xattr_name_len, 0, 1);
84 err = __hfsplus_setxattr(inode, xattr_name,
85 xattr->value, xattr->value_len, 0);
86 if (err)
87 break;
89 return err;
92 int hfsplus_init_security(struct inode *inode, struct inode *dir,
93 const struct qstr *qstr)
95 return security_inode_init_security(inode, dir, qstr,
96 &hfsplus_initxattrs, NULL);
99 const struct xattr_handler hfsplus_xattr_security_handler = {
100 .prefix = XATTR_SECURITY_PREFIX,
101 .list = hfsplus_security_listxattr,
102 .get = hfsplus_security_getxattr,
103 .set = hfsplus_security_setxattr,