blob: 64b67aa643a96909b2759824fcbfdd0fda43c562 [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
Andreas Gruenbacherd9a82a02015-10-04 19:18:51 +020011trusted_get(const struct xattr_handler *handler, struct dentry *dentry,
12 const char *name, void *buffer, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070013{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070014 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
15 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
David Howells2b0143b2015-03-17 22:25:59 +000017 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(d_inode(dentry)))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070018 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
David Howells2b0143b2015-03-17 22:25:59 +000020 return reiserfs_xattr_get(d_inode(dentry), name, buffer, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021}
22
23static int
Andreas Gruenbacherd9a82a02015-10-04 19:18:51 +020024trusted_set(const struct xattr_handler *handler, struct dentry *dentry,
25 const char *name, const void *buffer, size_t size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070027 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
28 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
David Howells2b0143b2015-03-17 22:25:59 +000030 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(d_inode(dentry)))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070031 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
David Howells2b0143b2015-03-17 22:25:59 +000033 return reiserfs_xattr_set(d_inode(dentry), name, buffer, size, flags);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070034}
35
Andreas Gruenbacher764a5c62015-12-02 14:44:43 +010036static bool trusted_list(struct dentry *dentry)
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070037{
Andreas Gruenbacher764a5c62015-12-02 14:44:43 +010038 return capable(CAP_SYS_ADMIN) && !IS_PRIVATE(d_inode(dentry));
Linus Torvalds1da177e2005-04-16 15:20:36 -070039}
40
Stephen Hemminger94d09a92010-05-13 17:53:19 -070041const struct xattr_handler reiserfs_xattr_trusted_handler = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 .prefix = XATTR_TRUSTED_PREFIX,
43 .get = trusted_get,
44 .set = trusted_set,
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 .list = trusted_list,
46};