diff options
author | Tiger Yang <tiger.yang@oracle.com> | 2008-11-13 22:16:27 -0500 |
---|---|---|
committer | Mark Fasheh <mfasheh@suse.com> | 2009-01-05 11:34:20 -0500 |
commit | 923f7f3102b80403152e05aee3d55ecfce240440 (patch) | |
tree | 54184688eb9dcc4ff4521348a31fd8313470d33a /fs | |
parent | 6c3faba4421e230d77a181c260972229c542dec9 (diff) |
ocfs2: add security xattr API
This patch add security xattr set/get/list APIs to
support security attributes in Ocfs2.
Signed-off-by: Tiger Yang <tiger.yang@oracle.com>
Signed-off-by: Mark Fasheh <mfasheh@suse.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ocfs2/xattr.c | 47 | ||||
-rw-r--r-- | fs/ocfs2/xattr.h | 1 |
2 files changed, 48 insertions, 0 deletions
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index 6480254fe396..db03162914cc 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/init.h> | 35 | #include <linux/init.h> |
36 | #include <linux/module.h> | 36 | #include <linux/module.h> |
37 | #include <linux/string.h> | 37 | #include <linux/string.h> |
38 | #include <linux/security.h> | ||
38 | 39 | ||
39 | #define MLOG_MASK_PREFIX ML_XATTR | 40 | #define MLOG_MASK_PREFIX ML_XATTR |
40 | #include <cluster/masklog.h> | 41 | #include <cluster/masklog.h> |
@@ -88,12 +89,14 @@ static struct ocfs2_xattr_def_value_root def_xv = { | |||
88 | struct xattr_handler *ocfs2_xattr_handlers[] = { | 89 | struct xattr_handler *ocfs2_xattr_handlers[] = { |
89 | &ocfs2_xattr_user_handler, | 90 | &ocfs2_xattr_user_handler, |
90 | &ocfs2_xattr_trusted_handler, | 91 | &ocfs2_xattr_trusted_handler, |
92 | &ocfs2_xattr_security_handler, | ||
91 | NULL | 93 | NULL |
92 | }; | 94 | }; |
93 | 95 | ||
94 | static struct xattr_handler *ocfs2_xattr_handler_map[OCFS2_XATTR_MAX] = { | 96 | static struct xattr_handler *ocfs2_xattr_handler_map[OCFS2_XATTR_MAX] = { |
95 | [OCFS2_XATTR_INDEX_USER] = &ocfs2_xattr_user_handler, | 97 | [OCFS2_XATTR_INDEX_USER] = &ocfs2_xattr_user_handler, |
96 | [OCFS2_XATTR_INDEX_TRUSTED] = &ocfs2_xattr_trusted_handler, | 98 | [OCFS2_XATTR_INDEX_TRUSTED] = &ocfs2_xattr_trusted_handler, |
99 | [OCFS2_XATTR_INDEX_SECURITY] = &ocfs2_xattr_security_handler, | ||
97 | }; | 100 | }; |
98 | 101 | ||
99 | struct ocfs2_xattr_info { | 102 | struct ocfs2_xattr_info { |
@@ -4977,6 +4980,50 @@ out: | |||
4977 | } | 4980 | } |
4978 | 4981 | ||
4979 | /* | 4982 | /* |
4983 | * 'security' attributes support | ||
4984 | */ | ||
4985 | static size_t ocfs2_xattr_security_list(struct inode *inode, char *list, | ||
4986 | size_t list_size, const char *name, | ||
4987 | size_t name_len) | ||
4988 | { | ||
4989 | const size_t prefix_len = XATTR_SECURITY_PREFIX_LEN; | ||
4990 | const size_t total_len = prefix_len + name_len + 1; | ||
4991 | |||
4992 | if (list && total_len <= list_size) { | ||
4993 | memcpy(list, XATTR_SECURITY_PREFIX, prefix_len); | ||
4994 | memcpy(list + prefix_len, name, name_len); | ||
4995 | list[prefix_len + name_len] = '\0'; | ||
4996 | } | ||
4997 | return total_len; | ||
4998 | } | ||
4999 | |||
5000 | static int ocfs2_xattr_security_get(struct inode *inode, const char *name, | ||
5001 | void *buffer, size_t size) | ||
5002 | { | ||
5003 | if (strcmp(name, "") == 0) | ||
5004 | return -EINVAL; | ||
5005 | return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_SECURITY, name, | ||
5006 | buffer, size); | ||
5007 | } | ||
5008 | |||
5009 | static int ocfs2_xattr_security_set(struct inode *inode, const char *name, | ||
5010 | const void *value, size_t size, int flags) | ||
5011 | { | ||
5012 | if (strcmp(name, "") == 0) | ||
5013 | return -EINVAL; | ||
5014 | |||
5015 | return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_SECURITY, name, value, | ||
5016 | size, flags); | ||
5017 | } | ||
5018 | |||
5019 | struct xattr_handler ocfs2_xattr_security_handler = { | ||
5020 | .prefix = XATTR_SECURITY_PREFIX, | ||
5021 | .list = ocfs2_xattr_security_list, | ||
5022 | .get = ocfs2_xattr_security_get, | ||
5023 | .set = ocfs2_xattr_security_set, | ||
5024 | }; | ||
5025 | |||
5026 | /* | ||
4980 | * 'trusted' attributes support | 5027 | * 'trusted' attributes support |
4981 | */ | 5028 | */ |
4982 | static size_t ocfs2_xattr_trusted_list(struct inode *inode, char *list, | 5029 | static size_t ocfs2_xattr_trusted_list(struct inode *inode, char *list, |
diff --git a/fs/ocfs2/xattr.h b/fs/ocfs2/xattr.h index 8fbdc163c839..55c5256ff563 100644 --- a/fs/ocfs2/xattr.h +++ b/fs/ocfs2/xattr.h | |||
@@ -32,6 +32,7 @@ enum ocfs2_xattr_type { | |||
32 | 32 | ||
33 | extern struct xattr_handler ocfs2_xattr_user_handler; | 33 | extern struct xattr_handler ocfs2_xattr_user_handler; |
34 | extern struct xattr_handler ocfs2_xattr_trusted_handler; | 34 | extern struct xattr_handler ocfs2_xattr_trusted_handler; |
35 | extern struct xattr_handler ocfs2_xattr_security_handler; | ||
35 | extern struct xattr_handler *ocfs2_xattr_handlers[]; | 36 | extern struct xattr_handler *ocfs2_xattr_handlers[]; |
36 | 37 | ||
37 | ssize_t ocfs2_listxattr(struct dentry *, char *, size_t); | 38 | ssize_t ocfs2_listxattr(struct dentry *, char *, size_t); |