xattr_trusted.c 1.15 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0
2
#include "reiserfs.h"
3
#include <linux/capability.h>
Linus Torvalds's avatar
Linus Torvalds committed
4 5 6 7
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/pagemap.h>
#include <linux/xattr.h>
8
#include "xattr.h"
9
#include <linux/uaccess.h>
Linus Torvalds's avatar
Linus Torvalds committed
10 11

static int
12 13
trusted_get(const struct xattr_handler *handler, struct dentry *unused,
	    struct inode *inode, const char *name, void *buffer, size_t size)
Linus Torvalds's avatar
Linus Torvalds committed
14
{
15
	if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
16
		return -EPERM;
Linus Torvalds's avatar
Linus Torvalds committed
17

18
	return reiserfs_xattr_get(inode, xattr_full_name(handler, name),
19
				  buffer, size);
Linus Torvalds's avatar
Linus Torvalds committed
20 21 22
}

static int
23 24 25
trusted_set(const struct xattr_handler *handler, struct dentry *unused,
	    struct inode *inode, const char *name, const void *buffer,
	    size_t size, int flags)
Linus Torvalds's avatar
Linus Torvalds committed
26
{
27
	if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
28
		return -EPERM;
Linus Torvalds's avatar
Linus Torvalds committed
29

30
	return reiserfs_xattr_set(inode,
31 32
				  xattr_full_name(handler, name),
				  buffer, size, flags);
Linus Torvalds's avatar
Linus Torvalds committed
33 34
}

35
static bool trusted_list(struct dentry *dentry)
Linus Torvalds's avatar
Linus Torvalds committed
36
{
37
	return capable(CAP_SYS_ADMIN) && !IS_PRIVATE(d_inode(dentry));
Linus Torvalds's avatar
Linus Torvalds committed
38 39
}

40
const struct xattr_handler reiserfs_xattr_trusted_handler = {
Linus Torvalds's avatar
Linus Torvalds committed
41 42 43 44 45
	.prefix = XATTR_TRUSTED_PREFIX,
	.get = trusted_get,
	.set = trusted_set,
	.list = trusted_list,
};