blob: 60abe2bb1f980bbb11de6d2b161ea16946bc595a [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
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070016 if (!reiserfs_xattrs(inode->i_sb))
17 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070019 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
20 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070022 return reiserfs_xattr_get(inode, name, buffer, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070023}
24
25static int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070026trusted_set(struct inode *inode, const char *name, const void *buffer,
27 size_t size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070029 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
30 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070032 if (!reiserfs_xattrs(inode->i_sb))
33 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070035 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
36 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070038 return reiserfs_xattr_set(inode, name, buffer, size, flags);
39}
40
41static int trusted_del(struct inode *inode, const char *name)
42{
43 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
44 return -EINVAL;
45
46 if (!reiserfs_xattrs(inode->i_sb))
47 return -EOPNOTSUPP;
48
49 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
50 return -EPERM;
51
52 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053}
54
55static int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070056trusted_list(struct inode *inode, const char *name, int namelen, char *out)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070058 int len = namelen;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070060 if (!reiserfs_xattrs(inode->i_sb))
61 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070063 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
64 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070066 if (out)
67 memcpy(out, name, len);
68
69 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070}
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072struct reiserfs_xattr_handler trusted_handler = {
73 .prefix = XATTR_TRUSTED_PREFIX,
74 .get = trusted_get,
75 .set = trusted_set,
76 .del = trusted_del,
77 .list = trusted_list,
78};