2012-03-16 23:16:43 -06:00
|
|
|
#include "reiserfs.h"
|
2006-01-11 13:17:46 -07:00
|
|
|
#include <linux/capability.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/xattr.h>
|
2012-03-16 22:59:06 -06:00
|
|
|
#include "xattr.h"
|
2014-08-08 15:21:12 -06:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
static int
|
2009-11-13 02:52:56 -07:00
|
|
|
trusted_get(struct dentry *dentry, const char *name, void *buffer, size_t size,
|
|
|
|
int handler_flags)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-07-12 21:21:28 -06:00
|
|
|
if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
|
|
|
|
return -EINVAL;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-11-13 02:52:56 -07:00
|
|
|
if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(dentry->d_inode))
|
2005-07-12 21:21:28 -06:00
|
|
|
return -EPERM;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-11-13 02:52:56 -07:00
|
|
|
return reiserfs_xattr_get(dentry->d_inode, name, buffer, size);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-11-13 02:52:56 -07:00
|
|
|
trusted_set(struct dentry *dentry, const char *name, const void *buffer,
|
|
|
|
size_t size, int flags, int handler_flags)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-07-12 21:21:28 -06:00
|
|
|
if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
|
|
|
|
return -EINVAL;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-11-13 02:52:56 -07:00
|
|
|
if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(dentry->d_inode))
|
2005-07-12 21:21:28 -06:00
|
|
|
return -EPERM;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-11-13 02:52:56 -07:00
|
|
|
return reiserfs_xattr_set(dentry->d_inode, name, buffer, size, flags);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2009-11-13 02:52:56 -07:00
|
|
|
static size_t trusted_list(struct dentry *dentry, char *list, size_t list_size,
|
|
|
|
const char *name, size_t name_len, int handler_flags)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2009-03-30 12:02:38 -06:00
|
|
|
const size_t len = name_len + 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-11-13 02:52:56 -07:00
|
|
|
if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(dentry->d_inode))
|
2005-07-12 21:21:28 -06:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-03-30 12:02:38 -06:00
|
|
|
if (list && len <= list_size) {
|
|
|
|
memcpy(list, name, name_len);
|
|
|
|
list[name_len] = '\0';
|
|
|
|
}
|
2005-07-12 21:21:28 -06:00
|
|
|
return len;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2010-05-13 18:53:19 -06:00
|
|
|
const struct xattr_handler reiserfs_xattr_trusted_handler = {
|
2005-04-16 16:20:36 -06:00
|
|
|
.prefix = XATTR_TRUSTED_PREFIX,
|
|
|
|
.get = trusted_get,
|
|
|
|
.set = trusted_set,
|
|
|
|
.list = trusted_list,
|
|
|
|
};
|