xref: /openbmc/linux/fs/reiserfs/xattr_security.c (revision 9ac8d3fb)
1 #include <linux/reiserfs_fs.h>
2 #include <linux/errno.h>
3 #include <linux/fs.h>
4 #include <linux/pagemap.h>
5 #include <linux/xattr.h>
6 #include <linux/reiserfs_xattr.h>
7 #include <asm/uaccess.h>
8 
9 static int
10 security_get(struct inode *inode, const char *name, void *buffer, size_t size)
11 {
12 	if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
13 		return -EINVAL;
14 
15 	if (is_reiserfs_priv_object(inode))
16 		return -EPERM;
17 
18 	return reiserfs_xattr_get(inode, name, buffer, size);
19 }
20 
21 static int
22 security_set(struct inode *inode, const char *name, const void *buffer,
23 	     size_t size, int flags)
24 {
25 	if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
26 		return -EINVAL;
27 
28 	if (is_reiserfs_priv_object(inode))
29 		return -EPERM;
30 
31 	return reiserfs_xattr_set(inode, name, buffer, size, flags);
32 }
33 
34 static int security_del(struct inode *inode, const char *name)
35 {
36 	if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
37 		return -EINVAL;
38 
39 	if (is_reiserfs_priv_object(inode))
40 		return -EPERM;
41 
42 	return 0;
43 }
44 
45 static int
46 security_list(struct inode *inode, const char *name, int namelen, char *out)
47 {
48 	int len = namelen;
49 
50 	if (is_reiserfs_priv_object(inode))
51 		return 0;
52 
53 	if (out)
54 		memcpy(out, name, len);
55 
56 	return len;
57 }
58 
59 struct reiserfs_xattr_handler security_handler = {
60 	.prefix = XATTR_SECURITY_PREFIX,
61 	.get = security_get,
62 	.set = security_set,
63 	.del = security_del,
64 	.list = security_list,
65 };
66