Blame view

fs/hfsplus/xattr_security.c 2.18 KB
127e5f5ae   Vyacheslav Dubeyko   hfsplus: rework f...
1
2
3
4
5
6
7
8
9
  /*
   * linux/fs/hfsplus/xattr_trusted.c
   *
   * Vyacheslav Dubeyko <slava@dubeyko.com>
   *
   * Handler for storing security labels as extended attributes.
   */
  
  #include <linux/security.h>
bf29e886b   Hin-Tak Leung   hfsplus: correct ...
10
  #include <linux/nls.h>
127e5f5ae   Vyacheslav Dubeyko   hfsplus: rework f...
11
12
  #include "hfsplus_fs.h"
  #include "xattr.h"
b4c1107cc   Vyacheslav Dubeyko   hfsplus: integrat...
13
  #include "acl.h"
127e5f5ae   Vyacheslav Dubeyko   hfsplus: rework f...
14

d9a82a040   Andreas Gruenbacher   xattr handlers: P...
15
  static int hfsplus_security_getxattr(const struct xattr_handler *handler,
b296821a7   Al Viro   xattr_handler: pa...
16
17
  				     struct dentry *unused, struct inode *inode,
  				     const char *name, void *buffer, size_t size)
127e5f5ae   Vyacheslav Dubeyko   hfsplus: rework f...
18
  {
b296821a7   Al Viro   xattr_handler: pa...
19
  	return hfsplus_getxattr(inode, name, buffer, size,
a3cef4cd6   Fabian Frederick   fs/hfsplus: move ...
20
21
  				XATTR_SECURITY_PREFIX,
  				XATTR_SECURITY_PREFIX_LEN);
127e5f5ae   Vyacheslav Dubeyko   hfsplus: rework f...
22
  }
d9a82a040   Andreas Gruenbacher   xattr handlers: P...
23
  static int hfsplus_security_setxattr(const struct xattr_handler *handler,
593012268   Al Viro   switch xattr_hand...
24
25
26
  				     struct dentry *unused, struct inode *inode,
  				     const char *name, const void *buffer,
  				     size_t size, int flags)
127e5f5ae   Vyacheslav Dubeyko   hfsplus: rework f...
27
  {
593012268   Al Viro   switch xattr_hand...
28
  	return hfsplus_setxattr(inode, name, buffer, size, flags,
5e61473ea   Fabian Frederick   fs/hfsplus: move ...
29
30
  				XATTR_SECURITY_PREFIX,
  				XATTR_SECURITY_PREFIX_LEN);
127e5f5ae   Vyacheslav Dubeyko   hfsplus: rework f...
31
  }
127e5f5ae   Vyacheslav Dubeyko   hfsplus: rework f...
32
33
34
35
36
  static int hfsplus_initxattrs(struct inode *inode,
  				const struct xattr *xattr_array,
  				void *fs_info)
  {
  	const struct xattr *xattr;
bf29e886b   Hin-Tak Leung   hfsplus: correct ...
37
  	char *xattr_name;
127e5f5ae   Vyacheslav Dubeyko   hfsplus: rework f...
38
  	int err = 0;
bf29e886b   Hin-Tak Leung   hfsplus: correct ...
39
40
41
42
  	xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1,
  		GFP_KERNEL);
  	if (!xattr_name)
  		return -ENOMEM;
127e5f5ae   Vyacheslav Dubeyko   hfsplus: rework f...
43
  	for (xattr = xattr_array; xattr->name != NULL; xattr++) {
127e5f5ae   Vyacheslav Dubeyko   hfsplus: rework f...
44

bf29e886b   Hin-Tak Leung   hfsplus: correct ...
45
  		if (!strcmp(xattr->name, ""))
127e5f5ae   Vyacheslav Dubeyko   hfsplus: rework f...
46
  			continue;
127e5f5ae   Vyacheslav Dubeyko   hfsplus: rework f...
47
48
49
50
  		strcpy(xattr_name, XATTR_SECURITY_PREFIX);
  		strcpy(xattr_name +
  			XATTR_SECURITY_PREFIX_LEN, xattr->name);
  		memset(xattr_name +
bf29e886b   Hin-Tak Leung   hfsplus: correct ...
51
  			XATTR_SECURITY_PREFIX_LEN + strlen(xattr->name), 0, 1);
127e5f5ae   Vyacheslav Dubeyko   hfsplus: rework f...
52
53
54
55
56
57
  
  		err = __hfsplus_setxattr(inode, xattr_name,
  					xattr->value, xattr->value_len, 0);
  		if (err)
  			break;
  	}
bf29e886b   Hin-Tak Leung   hfsplus: correct ...
58
  	kfree(xattr_name);
127e5f5ae   Vyacheslav Dubeyko   hfsplus: rework f...
59
60
61
62
63
64
65
66
67
  	return err;
  }
  
  int hfsplus_init_security(struct inode *inode, struct inode *dir,
  				const struct qstr *qstr)
  {
  	return security_inode_init_security(inode, dir, qstr,
  					&hfsplus_initxattrs, NULL);
  }
b4c1107cc   Vyacheslav Dubeyko   hfsplus: integrat...
68
69
70
71
72
73
74
75
76
77
78
  int hfsplus_init_inode_security(struct inode *inode,
  						struct inode *dir,
  						const struct qstr *qstr)
  {
  	int err;
  
  	err = hfsplus_init_posix_acl(inode, dir);
  	if (!err)
  		err = hfsplus_init_security(inode, dir, qstr);
  	return err;
  }
127e5f5ae   Vyacheslav Dubeyko   hfsplus: rework f...
79
80
  const struct xattr_handler hfsplus_xattr_security_handler = {
  	.prefix	= XATTR_SECURITY_PREFIX,
127e5f5ae   Vyacheslav Dubeyko   hfsplus: rework f...
81
82
83
  	.get	= hfsplus_security_getxattr,
  	.set	= hfsplus_security_setxattr,
  };