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
6 This patch add security xattr set/get/list APIs to
7 support security attributes in Ocfs2.
9 Signed-off-by: Tiger Yang <tiger.yang@oracle.com>
10 Signed-off-by: Mark Fasheh <mfasheh@suse.com>
12 fs/ocfs2/xattr.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
13 fs/ocfs2/xattr.h | 1 +
14 2 files changed, 48 insertions(+), 0 deletions(-)
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
21 #include <linux/init.h>
22 #include <linux/module.h>
23 #include <linux/string.h>
24 +#include <linux/security.h>
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,
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,
42 struct ocfs2_xattr_info {
43 @@ -4977,6 +4980,50 @@ out:
47 + * 'security' attributes support
49 +static size_t ocfs2_xattr_security_list(struct inode *inode, char *list,
50 + size_t list_size, const char *name,
53 + const size_t prefix_len = XATTR_SECURITY_PREFIX_LEN;
54 + const size_t total_len = prefix_len + name_len + 1;
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';
64 +static int ocfs2_xattr_security_get(struct inode *inode, const char *name,
65 + void *buffer, size_t size)
67 + if (strcmp(name, "") == 0)
69 + return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_SECURITY, name,
73 +static int ocfs2_xattr_security_set(struct inode *inode, const char *name,
74 + const void *value, size_t size, int flags)
76 + if (strcmp(name, "") == 0)
79 + return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_SECURITY, name, value,
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,
91 * 'trusted' attributes support
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 {
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[];
105 ssize_t ocfs2_listxattr(struct dentry *, char *, size_t);