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"
13 static int hfsplus_security_getxattr(struct dentry
*dentry
, const char *name
,
14 void *buffer
, size_t size
, int type
)
16 char xattr_name
[HFSPLUS_ATTR_MAX_STRLEN
+ 1] = {0};
17 size_t len
= strlen(name
);
19 if (!strcmp(name
, ""))
22 if (len
+ XATTR_SECURITY_PREFIX_LEN
> HFSPLUS_ATTR_MAX_STRLEN
)
25 strcpy(xattr_name
, XATTR_SECURITY_PREFIX
);
26 strcpy(xattr_name
+ XATTR_SECURITY_PREFIX_LEN
, name
);
28 return hfsplus_getxattr(dentry
, xattr_name
, buffer
, size
);
31 static int hfsplus_security_setxattr(struct dentry
*dentry
, const char *name
,
32 const void *buffer
, size_t size
, int flags
, int type
)
34 char xattr_name
[HFSPLUS_ATTR_MAX_STRLEN
+ 1] = {0};
35 size_t len
= strlen(name
);
37 if (!strcmp(name
, ""))
40 if (len
+ XATTR_SECURITY_PREFIX_LEN
> HFSPLUS_ATTR_MAX_STRLEN
)
43 strcpy(xattr_name
, XATTR_SECURITY_PREFIX
);
44 strcpy(xattr_name
+ XATTR_SECURITY_PREFIX_LEN
, name
);
46 return hfsplus_setxattr(dentry
, xattr_name
, buffer
, size
, flags
);
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
)
53 * This method is not used.
54 * It is used hfsplus_listxattr() instead of generic_listxattr().
59 static int hfsplus_initxattrs(struct inode
*inode
,
60 const struct xattr
*xattr_array
,
63 const struct xattr
*xattr
;
64 char xattr_name
[HFSPLUS_ATTR_MAX_STRLEN
+ 1] = {0};
65 size_t xattr_name_len
;
68 for (xattr
= xattr_array
; xattr
->name
!= NULL
; xattr
++) {
69 xattr_name_len
= strlen(xattr
->name
);
71 if (xattr_name_len
== 0)
74 if (xattr_name_len
+ XATTR_SECURITY_PREFIX_LEN
>
75 HFSPLUS_ATTR_MAX_STRLEN
)
78 strcpy(xattr_name
, XATTR_SECURITY_PREFIX
);
80 XATTR_SECURITY_PREFIX_LEN
, xattr
->name
);
82 XATTR_SECURITY_PREFIX_LEN
+ xattr_name_len
, 0, 1);
84 err
= __hfsplus_setxattr(inode
, xattr_name
,
85 xattr
->value
, xattr
->value_len
, 0);
92 int hfsplus_init_security(struct inode
*inode
, struct inode
*dir
,
93 const struct qstr
*qstr
)
95 return security_inode_init_security(inode
, dir
, qstr
,
96 &hfsplus_initxattrs
, NULL
);
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
,