Commit 0ddaf72c authored by Andreas Gruenbacher's avatar Andreas Gruenbacher Committed by Al Viro

squashfs: xattr simplifications

Now that the xattr handler is passed to the xattr handler operations, we
have access to the attribute name prefix, so simplify the squashfs xattr
handlers a bit.
Signed-off-by: default avatarAndreas Gruenbacher <agruenba@redhat.com>
Cc: Phillip Lougher <phillip@squashfs.org.uk>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent e409de99
...@@ -212,96 +212,68 @@ static int squashfs_xattr_get(struct inode *inode, int name_index, ...@@ -212,96 +212,68 @@ static int squashfs_xattr_get(struct inode *inode, int name_index,
} }
/* static size_t squashfs_xattr_handler_list(const struct xattr_handler *handler,
* User namespace support struct dentry *d, char *list,
*/ size_t list_size, const char *name,
static size_t squashfs_user_list(const struct xattr_handler *handler, size_t name_len)
struct dentry *d, char *list, size_t list_size,
const char *name, size_t name_len)
{ {
if (list && XATTR_USER_PREFIX_LEN <= list_size) int len = strlen(handler->prefix);
memcpy(list, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN);
return XATTR_USER_PREFIX_LEN; if (list && len <= list_size)
memcpy(list, handler->prefix, len);
return len;
} }
static int squashfs_user_get(const struct xattr_handler *handler, static int squashfs_xattr_handler_get(const struct xattr_handler *handler,
struct dentry *d, const char *name, void *buffer, struct dentry *d, const char *name,
size_t size) void *buffer, size_t size)
{ {
if (name[0] == '\0') if (name[0] == '\0')
return -EINVAL; return -EINVAL;
return squashfs_xattr_get(d_inode(d), SQUASHFS_XATTR_USER, name, return squashfs_xattr_get(d_inode(d), handler->flags, name,
buffer, size); buffer, size);
} }
/*
* User namespace support
*/
static const struct xattr_handler squashfs_xattr_user_handler = { static const struct xattr_handler squashfs_xattr_user_handler = {
.prefix = XATTR_USER_PREFIX, .prefix = XATTR_USER_PREFIX,
.list = squashfs_user_list, .flags = SQUASHFS_XATTR_USER,
.get = squashfs_user_get .list = squashfs_xattr_handler_list,
.get = squashfs_xattr_handler_get
}; };
/* /*
* Trusted namespace support * Trusted namespace support
*/ */
static size_t squashfs_trusted_list(const struct xattr_handler *handler, static size_t squashfs_trusted_xattr_handler_list(const struct xattr_handler *handler,
struct dentry *d, char *list, struct dentry *d, char *list,
size_t list_size, const char *name, size_t list_size, const char *name,
size_t name_len) size_t name_len)
{ {
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return 0; return 0;
return squashfs_xattr_handler_list(handler, d, list, list_size, name,
if (list && XATTR_TRUSTED_PREFIX_LEN <= list_size) name_len);
memcpy(list, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN);
return XATTR_TRUSTED_PREFIX_LEN;
}
static int squashfs_trusted_get(const struct xattr_handler *handler,
struct dentry *d, const char *name,
void *buffer, size_t size)
{
if (name[0] == '\0')
return -EINVAL;
return squashfs_xattr_get(d_inode(d), SQUASHFS_XATTR_TRUSTED, name,
buffer, size);
} }
static const struct xattr_handler squashfs_xattr_trusted_handler = { static const struct xattr_handler squashfs_xattr_trusted_handler = {
.prefix = XATTR_TRUSTED_PREFIX, .prefix = XATTR_TRUSTED_PREFIX,
.list = squashfs_trusted_list, .flags = SQUASHFS_XATTR_TRUSTED,
.get = squashfs_trusted_get .list = squashfs_trusted_xattr_handler_list,
.get = squashfs_xattr_handler_get
}; };
/* /*
* Security namespace support * Security namespace support
*/ */
static size_t squashfs_security_list(const struct xattr_handler *handler,
struct dentry *d, char *list,
size_t list_size, const char *name,
size_t name_len)
{
if (list && XATTR_SECURITY_PREFIX_LEN <= list_size)
memcpy(list, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN);
return XATTR_SECURITY_PREFIX_LEN;
}
static int squashfs_security_get(const struct xattr_handler *handler,
struct dentry *d, const char *name,
void *buffer, size_t size)
{
if (name[0] == '\0')
return -EINVAL;
return squashfs_xattr_get(d_inode(d), SQUASHFS_XATTR_SECURITY, name,
buffer, size);
}
static const struct xattr_handler squashfs_xattr_security_handler = { static const struct xattr_handler squashfs_xattr_security_handler = {
.prefix = XATTR_SECURITY_PREFIX, .prefix = XATTR_SECURITY_PREFIX,
.list = squashfs_security_list, .flags = SQUASHFS_XATTR_SECURITY,
.get = squashfs_security_get .list = squashfs_xattr_handler_list,
.get = squashfs_xattr_handler_get
}; };
static const struct xattr_handler *squashfs_xattr_handler(int type) static const struct xattr_handler *squashfs_xattr_handler(int type)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment