xattr_trusted.c 1.72 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1
#include <linux/reiserfs_fs.h>
2
#include <linux/capability.h>
Linus Torvalds's avatar
Linus Torvalds committed
3 4 5 6 7 8 9 10 11 12
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/pagemap.h>
#include <linux/xattr.h>
#include <linux/reiserfs_xattr.h>
#include <asm/uaccess.h>

#define XATTR_TRUSTED_PREFIX "trusted."

static int
13
trusted_get(struct inode *inode, const char *name, void *buffer, size_t size)
Linus Torvalds's avatar
Linus Torvalds committed
14
{
15 16
	if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
		return -EINVAL;
Linus Torvalds's avatar
Linus Torvalds committed
17

18 19
	if (!reiserfs_xattrs(inode->i_sb))
		return -EOPNOTSUPP;
Linus Torvalds's avatar
Linus Torvalds committed
20

21 22
	if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
		return -EPERM;
Linus Torvalds's avatar
Linus Torvalds committed
23

24
	return reiserfs_xattr_get(inode, name, buffer, size);
Linus Torvalds's avatar
Linus Torvalds committed
25 26 27
}

static int
28 29
trusted_set(struct inode *inode, const char *name, const void *buffer,
	    size_t size, int flags)
Linus Torvalds's avatar
Linus Torvalds committed
30
{
31 32
	if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
		return -EINVAL;
Linus Torvalds's avatar
Linus Torvalds committed
33

34 35
	if (!reiserfs_xattrs(inode->i_sb))
		return -EOPNOTSUPP;
Linus Torvalds's avatar
Linus Torvalds committed
36

37 38
	if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
		return -EPERM;
Linus Torvalds's avatar
Linus Torvalds committed
39

40
	return reiserfs_xattr_set(inode, name, buffer, size, flags);
Linus Torvalds's avatar
Linus Torvalds committed
41 42
}

43
static int trusted_del(struct inode *inode, const char *name)
Linus Torvalds's avatar
Linus Torvalds committed
44
{
45 46
	if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
		return -EINVAL;
Linus Torvalds's avatar
Linus Torvalds committed
47

48 49
	if (!reiserfs_xattrs(inode->i_sb))
		return -EOPNOTSUPP;
Linus Torvalds's avatar
Linus Torvalds committed
50

51 52
	if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
		return -EPERM;
Linus Torvalds's avatar
Linus Torvalds committed
53

54
	return 0;
Linus Torvalds's avatar
Linus Torvalds committed
55 56 57
}

static int
58
trusted_list(struct inode *inode, const char *name, int namelen, char *out)
Linus Torvalds's avatar
Linus Torvalds committed
59
{
60
	int len = namelen;
Linus Torvalds's avatar
Linus Torvalds committed
61

62 63
	if (!reiserfs_xattrs(inode->i_sb))
		return 0;
Linus Torvalds's avatar
Linus Torvalds committed
64

65 66
	if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
		return 0;
Linus Torvalds's avatar
Linus Torvalds committed
67

68 69
	if (out)
		memcpy(out, name, len);
Linus Torvalds's avatar
Linus Torvalds committed
70

71
	return len;
Linus Torvalds's avatar
Linus Torvalds committed
72 73 74 75 76 77 78 79 80
}

struct reiserfs_xattr_handler trusted_handler = {
	.prefix = XATTR_TRUSTED_PREFIX,
	.get = trusted_get,
	.set = trusted_set,
	.del = trusted_del,
	.list = trusted_list,
};