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