]>
Commit | Line | Data |
---|---|---|
00e5a55c BS |
1 | From: Tiger Yang <tiger.yang@oracle.com> |
2 | Date: Fri, 14 Nov 2008 11:16:27 +0800 | |
3 | Subject: ocfs2: add security xattr API | |
4 | Patch-mainline: 2.6.29 | |
5 | ||
6 | This patch add security xattr set/get/list APIs to | |
7 | support security attributes in Ocfs2. | |
8 | ||
9 | Signed-off-by: Tiger Yang <tiger.yang@oracle.com> | |
10 | Signed-off-by: Mark Fasheh <mfasheh@suse.com> | |
11 | --- | |
12 | fs/ocfs2/xattr.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ | |
13 | fs/ocfs2/xattr.h | 1 + | |
14 | 2 files changed, 48 insertions(+), 0 deletions(-) | |
15 | ||
16 | diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c | |
17 | index 6480254..db03162 100644 | |
18 | --- a/fs/ocfs2/xattr.c | |
19 | +++ b/fs/ocfs2/xattr.c | |
20 | @@ -35,6 +35,7 @@ | |
21 | #include <linux/init.h> | |
22 | #include <linux/module.h> | |
23 | #include <linux/string.h> | |
24 | +#include <linux/security.h> | |
25 | ||
26 | #define MLOG_MASK_PREFIX ML_XATTR | |
27 | #include <cluster/masklog.h> | |
28 | @@ -88,12 +89,14 @@ static struct ocfs2_xattr_def_value_root def_xv = { | |
29 | struct xattr_handler *ocfs2_xattr_handlers[] = { | |
30 | &ocfs2_xattr_user_handler, | |
31 | &ocfs2_xattr_trusted_handler, | |
32 | + &ocfs2_xattr_security_handler, | |
33 | NULL | |
34 | }; | |
35 | ||
36 | static struct xattr_handler *ocfs2_xattr_handler_map[OCFS2_XATTR_MAX] = { | |
37 | [OCFS2_XATTR_INDEX_USER] = &ocfs2_xattr_user_handler, | |
38 | [OCFS2_XATTR_INDEX_TRUSTED] = &ocfs2_xattr_trusted_handler, | |
39 | + [OCFS2_XATTR_INDEX_SECURITY] = &ocfs2_xattr_security_handler, | |
40 | }; | |
41 | ||
42 | struct ocfs2_xattr_info { | |
43 | @@ -4977,6 +4980,50 @@ out: | |
44 | } | |
45 | ||
46 | /* | |
47 | + * 'security' attributes support | |
48 | + */ | |
49 | +static size_t ocfs2_xattr_security_list(struct inode *inode, char *list, | |
50 | + size_t list_size, const char *name, | |
51 | + size_t name_len) | |
52 | +{ | |
53 | + const size_t prefix_len = XATTR_SECURITY_PREFIX_LEN; | |
54 | + const size_t total_len = prefix_len + name_len + 1; | |
55 | + | |
56 | + if (list && total_len <= list_size) { | |
57 | + memcpy(list, XATTR_SECURITY_PREFIX, prefix_len); | |
58 | + memcpy(list + prefix_len, name, name_len); | |
59 | + list[prefix_len + name_len] = '\0'; | |
60 | + } | |
61 | + return total_len; | |
62 | +} | |
63 | + | |
64 | +static int ocfs2_xattr_security_get(struct inode *inode, const char *name, | |
65 | + void *buffer, size_t size) | |
66 | +{ | |
67 | + if (strcmp(name, "") == 0) | |
68 | + return -EINVAL; | |
69 | + return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_SECURITY, name, | |
70 | + buffer, size); | |
71 | +} | |
72 | + | |
73 | +static int ocfs2_xattr_security_set(struct inode *inode, const char *name, | |
74 | + const void *value, size_t size, int flags) | |
75 | +{ | |
76 | + if (strcmp(name, "") == 0) | |
77 | + return -EINVAL; | |
78 | + | |
79 | + return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_SECURITY, name, value, | |
80 | + size, flags); | |
81 | +} | |
82 | + | |
83 | +struct xattr_handler ocfs2_xattr_security_handler = { | |
84 | + .prefix = XATTR_SECURITY_PREFIX, | |
85 | + .list = ocfs2_xattr_security_list, | |
86 | + .get = ocfs2_xattr_security_get, | |
87 | + .set = ocfs2_xattr_security_set, | |
88 | +}; | |
89 | + | |
90 | +/* | |
91 | * 'trusted' attributes support | |
92 | */ | |
93 | static size_t ocfs2_xattr_trusted_list(struct inode *inode, char *list, | |
94 | diff --git a/fs/ocfs2/xattr.h b/fs/ocfs2/xattr.h | |
95 | index 8fbdc16..55c5256 100644 | |
96 | --- a/fs/ocfs2/xattr.h | |
97 | +++ b/fs/ocfs2/xattr.h | |
98 | @@ -32,6 +32,7 @@ enum ocfs2_xattr_type { | |
99 | ||
100 | extern struct xattr_handler ocfs2_xattr_user_handler; | |
101 | extern struct xattr_handler ocfs2_xattr_trusted_handler; | |
102 | +extern struct xattr_handler ocfs2_xattr_security_handler; | |
103 | extern struct xattr_handler *ocfs2_xattr_handlers[]; | |
104 | ||
105 | ssize_t ocfs2_listxattr(struct dentry *, char *, size_t); | |
106 | -- | |
107 | 1.5.6 | |
108 |