blob: 5eeb0c48ba46deb225ec2cc94518746aebceabd3 [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
Christoph Hellwig431547b2009-11-13 09:52:56 +000011trusted_get(struct dentry *dentry, const char *name, void *buffer, size_t size,
12 int handler_flags)
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
Christoph Hellwig431547b2009-11-13 09:52:56 +000017 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(dentry->d_inode))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070018 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Christoph Hellwig431547b2009-11-13 09:52:56 +000020 return reiserfs_xattr_get(dentry->d_inode, name, buffer, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021}
22
23static int
Christoph Hellwig431547b2009-11-13 09:52:56 +000024trusted_set(struct dentry *dentry, const char *name, const void *buffer,
25 size_t size, int flags, int handler_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
Christoph Hellwig431547b2009-11-13 09:52:56 +000030 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(dentry->d_inode))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070031 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Christoph Hellwig431547b2009-11-13 09:52:56 +000033 return reiserfs_xattr_set(dentry->d_inode, name, buffer, size, flags);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070034}
35
Christoph Hellwig431547b2009-11-13 09:52:56 +000036static size_t trusted_list(struct dentry *dentry, char *list, size_t list_size,
37 const char *name, size_t name_len, int handler_flags)
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070038{
Jeff Mahoney48b32a32009-03-30 14:02:38 -040039 const size_t len = name_len + 1;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070040
Christoph Hellwig431547b2009-11-13 09:52:56 +000041 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(dentry->d_inode))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070042 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Jeff Mahoney48b32a32009-03-30 14:02:38 -040044 if (list && len <= list_size) {
45 memcpy(list, name, name_len);
46 list[name_len] = '\0';
47 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070048 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
Stephen Hemminger94d09a92010-05-13 17:53:19 -070051const struct xattr_handler reiserfs_xattr_trusted_handler = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 .prefix = XATTR_TRUSTED_PREFIX,
53 .get = trusted_get,
54 .set = trusted_set,
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 .list = trusted_list,
56};