blob: a338adf1b8b4816c19ca84557a0142179f93b9a7 [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 Frederick170939912014-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 Gruenbacherd9a82a02015-10-04 19:18:51 +020036static size_t trusted_list(const struct xattr_handler *handler,
37 struct dentry *dentry, char *list, size_t list_size,
38 const char *name, size_t name_len)
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070039{
Jeff Mahoney48b32a32009-03-30 14:02:38 -040040 const size_t len = name_len + 1;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070041
David Howells2b0143b2015-03-17 22:25:59 +000042 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(d_inode(dentry)))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070043 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Jeff Mahoney48b32a32009-03-30 14:02:38 -040045 if (list && len <= list_size) {
46 memcpy(list, name, name_len);
47 list[name_len] = '\0';
48 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070049 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050}
51
Stephen Hemminger94d09a92010-05-13 17:53:19 -070052const struct xattr_handler reiserfs_xattr_trusted_handler = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 .prefix = XATTR_TRUSTED_PREFIX,
54 .get = trusted_get,
55 .set = trusted_set,
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 .list = trusted_list,
57};