diff options
author | Vyacheslav Dubeyko <slava@dubeyko.com> | 2013-02-27 20:03:03 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-02-27 22:10:10 -0500 |
commit | 127e5f5ae51eff44c9bff673f24e8587caa4e29f (patch) | |
tree | c36b2b22e18241b43a85e8719603ba0e6a897d68 /fs/hfsplus/xattr_security.c | |
parent | 3e05ca20fb570b456bd9841b5ff489d865e8c563 (diff) |
hfsplus: rework functionality of getting, setting and deleting of extended attributes
Rework functionality of getting, setting and deleting of extended attributes.
Signed-off-by: Vyacheslav Dubeyko <slava@dubeyko.com>
Reported-by: Hin-Tak Leung <htl10@users.sourceforge.net>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Jan Kara <jack@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/hfsplus/xattr_security.c')
-rw-r--r-- | fs/hfsplus/xattr_security.c | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/fs/hfsplus/xattr_security.c b/fs/hfsplus/xattr_security.c new file mode 100644 index 000000000000..83b842f113c5 --- /dev/null +++ b/fs/hfsplus/xattr_security.c | |||
@@ -0,0 +1,104 @@ | |||
1 | /* | ||
2 | * linux/fs/hfsplus/xattr_trusted.c | ||
3 | * | ||
4 | * Vyacheslav Dubeyko <slava@dubeyko.com> | ||
5 | * | ||
6 | * Handler for storing security labels as extended attributes. | ||
7 | */ | ||
8 | |||
9 | #include <linux/security.h> | ||
10 | #include "hfsplus_fs.h" | ||
11 | #include "xattr.h" | ||
12 | |||
13 | static int hfsplus_security_getxattr(struct dentry *dentry, const char *name, | ||
14 | void *buffer, size_t size, int type) | ||
15 | { | ||
16 | char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] = {0}; | ||
17 | size_t len = strlen(name); | ||
18 | |||
19 | if (!strcmp(name, "")) | ||
20 | return -EINVAL; | ||
21 | |||
22 | if (len + XATTR_SECURITY_PREFIX_LEN > HFSPLUS_ATTR_MAX_STRLEN) | ||
23 | return -EOPNOTSUPP; | ||
24 | |||
25 | strcpy(xattr_name, XATTR_SECURITY_PREFIX); | ||
26 | strcpy(xattr_name + XATTR_SECURITY_PREFIX_LEN, name); | ||
27 | |||
28 | return hfsplus_getxattr(dentry, xattr_name, buffer, size); | ||
29 | } | ||
30 | |||
31 | static int hfsplus_security_setxattr(struct dentry *dentry, const char *name, | ||
32 | const void *buffer, size_t size, int flags, int type) | ||
33 | { | ||
34 | char xattr_name[HFSPLUS_ATTR_MAX_STRLEN + 1] = {0}; | ||
35 | size_t len = strlen(name); | ||
36 | |||
37 | if (!strcmp(name, "")) | ||
38 | return -EINVAL; | ||
39 | |||
40 | if (len + XATTR_SECURITY_PREFIX_LEN > HFSPLUS_ATTR_MAX_STRLEN) | ||
41 | return -EOPNOTSUPP; | ||
42 | |||
43 | strcpy(xattr_name, XATTR_SECURITY_PREFIX); | ||
44 | strcpy(xattr_name + XATTR_SECURITY_PREFIX_LEN, name); | ||
45 | |||
46 | return hfsplus_setxattr(dentry, xattr_name, buffer, size, flags); | ||
47 | } | ||
48 | |||
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) | ||
51 | { | ||
52 | /* | ||
53 | * This method is not used. | ||
54 | * It is used hfsplus_listxattr() instead of generic_listxattr(). | ||
55 | */ | ||
56 | return -EOPNOTSUPP; | ||
57 | } | ||
58 | |||
59 | static int hfsplus_initxattrs(struct inode *inode, | ||
60 | const struct xattr *xattr_array, | ||
61 | void *fs_info) | ||
62 | { | ||
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; | ||
67 | |||
68 | for (xattr = xattr_array; xattr->name != NULL; xattr++) { | ||
69 | xattr_name_len = strlen(xattr->name); | ||
70 | |||
71 | if (xattr_name_len == 0) | ||
72 | continue; | ||
73 | |||
74 | if (xattr_name_len + XATTR_SECURITY_PREFIX_LEN > | ||
75 | HFSPLUS_ATTR_MAX_STRLEN) | ||
76 | return -EOPNOTSUPP; | ||
77 | |||
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); | ||
83 | |||
84 | err = __hfsplus_setxattr(inode, xattr_name, | ||
85 | xattr->value, xattr->value_len, 0); | ||
86 | if (err) | ||
87 | break; | ||
88 | } | ||
89 | return err; | ||
90 | } | ||
91 | |||
92 | int hfsplus_init_security(struct inode *inode, struct inode *dir, | ||
93 | const struct qstr *qstr) | ||
94 | { | ||
95 | return security_inode_init_security(inode, dir, qstr, | ||
96 | &hfsplus_initxattrs, NULL); | ||
97 | } | ||
98 | |||
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, | ||
104 | }; | ||