blob: a865042f75e2e2c0cbb46150e150e1b0911e31b0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/reiserfs_fs.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>
7#include <linux/reiserfs_xattr.h>
8#include <asm/uaccess.h>
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010static int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070011trusted_get(struct inode *inode, const char *name, void *buffer, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070012{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070013 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
14 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Jeff Mahoney48b32a32009-03-30 14:02:38 -040016 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070017 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070019 return reiserfs_xattr_get(inode, name, buffer, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070020}
21
22static int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070023trusted_set(struct inode *inode, const char *name, const void *buffer,
24 size_t size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070025{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070026 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
27 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Jeff Mahoney48b32a32009-03-30 14:02:38 -040029 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070030 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070032 return reiserfs_xattr_set(inode, name, buffer, size, flags);
33}
34
Jeff Mahoney48b32a32009-03-30 14:02:38 -040035static size_t trusted_list(struct inode *inode, char *list, size_t list_size,
36 const char *name, size_t name_len)
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070037{
Jeff Mahoney48b32a32009-03-30 14:02:38 -040038 const size_t len = name_len + 1;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070039
Jeff Mahoney48b32a32009-03-30 14:02:38 -040040 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070041 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Jeff Mahoney48b32a32009-03-30 14:02:38 -040043 if (list && len <= list_size) {
44 memcpy(list, name, name_len);
45 list[name_len] = '\0';
46 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070047 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048}
49
Jeff Mahoney48b32a32009-03-30 14:02:38 -040050struct xattr_handler reiserfs_xattr_trusted_handler = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 .prefix = XATTR_TRUSTED_PREFIX,
52 .get = trusted_get,
53 .set = trusted_set,
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 .list = trusted_list,
55};