2 * linux/fs/hfsplus/xattr_trusted.c
4 * Vyacheslav Dubeyko <slava@dubeyko.com>
6 * Handler for storing security labels as extended attributes.
9 #include <linux/security.h>
10 #include "hfsplus_fs.h"
14 static int hfsplus_security_getxattr(struct dentry
*dentry
, const char *name
,
15 void *buffer
, size_t size
, int type
)
17 char xattr_name
[HFSPLUS_ATTR_MAX_STRLEN
+ 1] = {0};
18 size_t len
= strlen(name
);
20 if (!strcmp(name
, ""))
23 if (len
+ XATTR_SECURITY_PREFIX_LEN
> HFSPLUS_ATTR_MAX_STRLEN
)
26 strcpy(xattr_name
, XATTR_SECURITY_PREFIX
);
27 strcpy(xattr_name
+ XATTR_SECURITY_PREFIX_LEN
, name
);
29 return hfsplus_getxattr(dentry
, xattr_name
, buffer
, size
);
32 static int hfsplus_security_setxattr(struct dentry
*dentry
, const char *name
,
33 const void *buffer
, size_t size
, int flags
, int type
)
35 char xattr_name
[HFSPLUS_ATTR_MAX_STRLEN
+ 1] = {0};
36 size_t len
= strlen(name
);
38 if (!strcmp(name
, ""))
41 if (len
+ XATTR_SECURITY_PREFIX_LEN
> HFSPLUS_ATTR_MAX_STRLEN
)
44 strcpy(xattr_name
, XATTR_SECURITY_PREFIX
);
45 strcpy(xattr_name
+ XATTR_SECURITY_PREFIX_LEN
, name
);
47 return hfsplus_setxattr(dentry
, xattr_name
, buffer
, size
, flags
);
50 static size_t hfsplus_security_listxattr(struct dentry
*dentry
, char *list
,
51 size_t list_size
, const char *name
, size_t name_len
, int type
)
54 * This method is not used.
55 * It is used hfsplus_listxattr() instead of generic_listxattr().
60 static int hfsplus_initxattrs(struct inode
*inode
,
61 const struct xattr
*xattr_array
,
64 const struct xattr
*xattr
;
65 char xattr_name
[HFSPLUS_ATTR_MAX_STRLEN
+ 1] = {0};
66 size_t xattr_name_len
;
69 for (xattr
= xattr_array
; xattr
->name
!= NULL
; xattr
++) {
70 xattr_name_len
= strlen(xattr
->name
);
72 if (xattr_name_len
== 0)
75 if (xattr_name_len
+ XATTR_SECURITY_PREFIX_LEN
>
76 HFSPLUS_ATTR_MAX_STRLEN
)
79 strcpy(xattr_name
, XATTR_SECURITY_PREFIX
);
81 XATTR_SECURITY_PREFIX_LEN
, xattr
->name
);
83 XATTR_SECURITY_PREFIX_LEN
+ xattr_name_len
, 0, 1);
85 err
= __hfsplus_setxattr(inode
, xattr_name
,
86 xattr
->value
, xattr
->value_len
, 0);
93 int hfsplus_init_security(struct inode
*inode
, struct inode
*dir
,
94 const struct qstr
*qstr
)
96 return security_inode_init_security(inode
, dir
, qstr
,
97 &hfsplus_initxattrs
, NULL
);
100 int hfsplus_init_inode_security(struct inode
*inode
,
102 const struct qstr
*qstr
)
106 err
= hfsplus_init_posix_acl(inode
, dir
);
108 err
= hfsplus_init_security(inode
, dir
, qstr
);
112 const struct xattr_handler hfsplus_xattr_security_handler
= {
113 .prefix
= XATTR_SECURITY_PREFIX
,
114 .list
= hfsplus_security_listxattr
,
115 .get
= hfsplus_security_getxattr
,
116 .set
= hfsplus_security_setxattr
,