blob: 5ed48da3d02b5f2f03f2facb8c4be7cc788e15f3 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Al Virof466c6f2012-03-17 01:16:43 -04002#include "reiserfs.h"
Randy Dunlap16f7e0f2006-01-11 12:17:46 -08003#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004#include <linux/errno.h>
5#include <linux/fs.h>
6#include <linux/pagemap.h>
7#include <linux/xattr.h>
Al Viroc45ac882012-03-17 00:59:06 -04008#include "xattr.h"
Fabian Frederick170939912014-08-08 14:21:12 -07009#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Linus Torvalds1da177e2005-04-16 15:20:36 -070011static int
Al Virob2968212016-04-10 20:48:24 -040012trusted_get(const struct xattr_handler *handler, struct dentry *unused,
13 struct inode *inode, const char *name, void *buffer, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070014{
Al Virob2968212016-04-10 20:48:24 -040015 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070016 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Al Virob2968212016-04-10 20:48:24 -040018 return reiserfs_xattr_get(inode, xattr_full_name(handler, name),
Al Viro79a628d2016-04-10 18:50:48 -040019 buffer, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070020}
21
22static int
Al Viro59301222016-05-27 10:19:30 -040023trusted_set(const struct xattr_handler *handler, struct dentry *unused,
24 struct inode *inode, const char *name, const void *buffer,
25 size_t size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026{
Al Viro59301222016-05-27 10:19:30 -040027 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070028 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Al Viro59301222016-05-27 10:19:30 -040030 return reiserfs_xattr_set(inode,
Al Viro79a628d2016-04-10 18:50:48 -040031 xattr_full_name(handler, name),
32 buffer, size, flags);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070033}
34
Andreas Gruenbacher764a5c62015-12-02 14:44:43 +010035static bool trusted_list(struct dentry *dentry)
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070036{
Andreas Gruenbacher764a5c62015-12-02 14:44:43 +010037 return capable(CAP_SYS_ADMIN) && !IS_PRIVATE(d_inode(dentry));
Linus Torvalds1da177e2005-04-16 15:20:36 -070038}
39
Stephen Hemminger94d09a92010-05-13 17:53:19 -070040const struct xattr_handler reiserfs_xattr_trusted_handler = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 .prefix = XATTR_TRUSTED_PREFIX,
42 .get = trusted_get,
43 .set = trusted_set,
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 .list = trusted_list,
45};