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 <linux/nls.h>
12 #include "hfsplus_fs.h"
16 static int hfsplus_security_getxattr(struct dentry
*dentry
, const char *name
,
17 void *buffer
, size_t size
, int type
)
22 if (!strcmp(name
, ""))
25 xattr_name
= kmalloc(NLS_MAX_CHARSET_SIZE
* HFSPLUS_ATTR_MAX_STRLEN
+ 1,
29 strcpy(xattr_name
, XATTR_SECURITY_PREFIX
);
30 strcpy(xattr_name
+ XATTR_SECURITY_PREFIX_LEN
, name
);
32 res
= hfsplus_getxattr(dentry
, xattr_name
, buffer
, size
);
37 static int hfsplus_security_setxattr(struct dentry
*dentry
, const char *name
,
38 const void *buffer
, size_t size
, int flags
, int type
)
43 if (!strcmp(name
, ""))
46 xattr_name
= kmalloc(NLS_MAX_CHARSET_SIZE
* HFSPLUS_ATTR_MAX_STRLEN
+ 1,
50 strcpy(xattr_name
, XATTR_SECURITY_PREFIX
);
51 strcpy(xattr_name
+ XATTR_SECURITY_PREFIX_LEN
, name
);
53 res
= hfsplus_setxattr(dentry
, xattr_name
, buffer
, size
, flags
);
58 static size_t hfsplus_security_listxattr(struct dentry
*dentry
, char *list
,
59 size_t list_size
, const char *name
, size_t name_len
, int type
)
62 * This method is not used.
63 * It is used hfsplus_listxattr() instead of generic_listxattr().
68 static int hfsplus_initxattrs(struct inode
*inode
,
69 const struct xattr
*xattr_array
,
72 const struct xattr
*xattr
;
76 xattr_name
= kmalloc(NLS_MAX_CHARSET_SIZE
* HFSPLUS_ATTR_MAX_STRLEN
+ 1,
80 for (xattr
= xattr_array
; xattr
->name
!= NULL
; xattr
++) {
82 if (!strcmp(xattr
->name
, ""))
85 strcpy(xattr_name
, XATTR_SECURITY_PREFIX
);
87 XATTR_SECURITY_PREFIX_LEN
, xattr
->name
);
89 XATTR_SECURITY_PREFIX_LEN
+ strlen(xattr
->name
), 0, 1);
91 err
= __hfsplus_setxattr(inode
, xattr_name
,
92 xattr
->value
, xattr
->value_len
, 0);
100 int hfsplus_init_security(struct inode
*inode
, struct inode
*dir
,
101 const struct qstr
*qstr
)
103 return security_inode_init_security(inode
, dir
, qstr
,
104 &hfsplus_initxattrs
, NULL
);
107 int hfsplus_init_inode_security(struct inode
*inode
,
109 const struct qstr
*qstr
)
113 err
= hfsplus_init_posix_acl(inode
, dir
);
115 err
= hfsplus_init_security(inode
, dir
, qstr
);
119 const struct xattr_handler hfsplus_xattr_security_handler
= {
120 .prefix
= XATTR_SECURITY_PREFIX
,
121 .list
= hfsplus_security_listxattr
,
122 .get
= hfsplus_security_getxattr
,
123 .set
= hfsplus_security_setxattr
,