2010-10-18 17:58:16 +08:00
|
|
|
/*
|
2015-11-19 02:31:52 +08:00
|
|
|
* 9p user. xattr callback
|
2010-10-18 17:58:16 +08:00
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2010
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
|
|
* the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-05-06 21:12:23 +08:00
|
|
|
/*
|
|
|
|
* Not so fast! You might want to read the 9p developer docs first:
|
|
|
|
* https://wiki.qemu.org/Documentation/9p
|
|
|
|
*/
|
|
|
|
|
2016-01-27 02:17:10 +08:00
|
|
|
#include "qemu/osdep.h"
|
2016-01-08 02:18:02 +08:00
|
|
|
#include "9p.h"
|
2011-01-28 20:39:08 +08:00
|
|
|
#include "fsdev/file-op-9p.h"
|
2015-11-19 02:31:52 +08:00
|
|
|
#include "9p-xattr.h"
|
2010-10-18 17:58:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
static ssize_t mp_user_getxattr(FsContext *ctx, const char *path,
|
|
|
|
const char *name, void *value, size_t size)
|
|
|
|
{
|
|
|
|
if (strncmp(name, "user.virtfs.", 12) == 0) {
|
|
|
|
/*
|
|
|
|
* Don't allow fetch of user.virtfs namesapce
|
|
|
|
* in case of mapped security
|
|
|
|
*/
|
|
|
|
errno = ENOATTR;
|
|
|
|
return -1;
|
|
|
|
}
|
2017-02-27 06:42:26 +08:00
|
|
|
return local_getxattr_nofollow(ctx, path, name, value, size);
|
2010-10-18 17:58:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t mp_user_listxattr(FsContext *ctx, const char *path,
|
|
|
|
char *name, void *value, size_t size)
|
|
|
|
{
|
|
|
|
int name_size = strlen(name) + 1;
|
|
|
|
if (strncmp(name, "user.virtfs.", 12) == 0) {
|
2010-10-18 17:58:16 +08:00
|
|
|
|
|
|
|
/* check if it is a mapped posix acl */
|
|
|
|
if (strncmp(name, "user.virtfs.system.posix_acl_", 29) == 0) {
|
|
|
|
/* adjust the name and size */
|
|
|
|
name += 12;
|
|
|
|
name_size -= 12;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Don't allow fetch of user.virtfs namesapce
|
|
|
|
* in case of mapped security
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
2010-10-18 17:58:16 +08:00
|
|
|
}
|
|
|
|
if (!value) {
|
|
|
|
return name_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size < name_size) {
|
|
|
|
errno = ERANGE;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-10-04 19:09:56 +08:00
|
|
|
/* name_size includes the trailing NUL. */
|
|
|
|
memcpy(value, name, name_size);
|
2010-10-18 17:58:16 +08:00
|
|
|
return name_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name,
|
|
|
|
void *value, size_t size, int flags)
|
|
|
|
{
|
|
|
|
if (strncmp(name, "user.virtfs.", 12) == 0) {
|
|
|
|
/*
|
|
|
|
* Don't allow fetch of user.virtfs namesapce
|
|
|
|
* in case of mapped security
|
|
|
|
*/
|
|
|
|
errno = EACCES;
|
|
|
|
return -1;
|
|
|
|
}
|
2017-02-27 06:42:43 +08:00
|
|
|
return local_setxattr_nofollow(ctx, path, name, value, size, flags);
|
2010-10-18 17:58:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mp_user_removexattr(FsContext *ctx,
|
|
|
|
const char *path, const char *name)
|
|
|
|
{
|
|
|
|
if (strncmp(name, "user.virtfs.", 12) == 0) {
|
|
|
|
/*
|
|
|
|
* Don't allow fetch of user.virtfs namesapce
|
|
|
|
* in case of mapped security
|
|
|
|
*/
|
|
|
|
errno = EACCES;
|
|
|
|
return -1;
|
|
|
|
}
|
2017-02-27 06:42:51 +08:00
|
|
|
return local_removexattr_nofollow(ctx, path, name);
|
2010-10-18 17:58:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
XattrOperations mapped_user_xattr = {
|
|
|
|
.name = "user.",
|
|
|
|
.getxattr = mp_user_getxattr,
|
|
|
|
.setxattr = mp_user_setxattr,
|
|
|
|
.listxattr = mp_user_listxattr,
|
|
|
|
.removexattr = mp_user_removexattr,
|
|
|
|
};
|
|
|
|
|
|
|
|
XattrOperations passthrough_user_xattr = {
|
|
|
|
.name = "user.",
|
|
|
|
.getxattr = pt_getxattr,
|
|
|
|
.setxattr = pt_setxattr,
|
|
|
|
.listxattr = pt_listxattr,
|
|
|
|
.removexattr = pt_removexattr,
|
|
|
|
};
|