blob: f15a5f9e84ce1a83e2052b7852a21bff727f105c [file] [log] [blame]
Al Virof466c6f2012-03-17 01:16:43 -04001#include "reiserfs.h"
Randy Dunlap16f7e0f2006-01-11 12:17:46 -08002#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07003#include <linux/errno.h>
4#include <linux/fs.h>
5#include <linux/pagemap.h>
6#include <linux/xattr.h>
Al Viroc45ac882012-03-17 00:59:06 -04007#include "xattr.h"
Fabian Frederick17093992014-08-08 14:21:12 -07008#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Linus Torvalds1da177e2005-04-16 15:20:36 -070010static int
Al Virob2968212016-04-10 20:48:24 -040011trusted_get(const struct xattr_handler *handler, struct dentry *unused,
12 struct inode *inode, const char *name, void *buffer, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070013{
Al Virob2968212016-04-10 20:48:24 -040014 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070015 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Al Virob2968212016-04-10 20:48:24 -040017 return reiserfs_xattr_get(inode, xattr_full_name(handler, name),
Al Viro79a628d2016-04-10 18:50:48 -040018 buffer, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070019}
20
21static int
Al Viro59301222016-05-27 10:19:30 -040022trusted_set(const struct xattr_handler *handler, struct dentry *unused,
23 struct inode *inode, const char *name, const void *buffer,
24 size_t size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070025{
Al Viro59301222016-05-27 10:19:30 -040026 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070027 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Al Viro59301222016-05-27 10:19:30 -040029 return reiserfs_xattr_set(inode,
Al Viro79a628d2016-04-10 18:50:48 -040030 xattr_full_name(handler, name),
31 buffer, size, flags);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070032}
33
Andreas Gruenbacher764a5c62015-12-02 14:44:43 +010034static bool trusted_list(struct dentry *dentry)
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070035{
Andreas Gruenbacher764a5c62015-12-02 14:44:43 +010036 return capable(CAP_SYS_ADMIN) && !IS_PRIVATE(d_inode(dentry));
Linus Torvalds1da177e2005-04-16 15:20:36 -070037}
38
Stephen Hemminger94d09a92010-05-13 17:53:19 -070039const struct xattr_handler reiserfs_xattr_trusted_handler = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 .prefix = XATTR_TRUSTED_PREFIX,
41 .get = trusted_get,
42 .set = trusted_set,
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 .list = trusted_list,
44};