2010-10-18 11:58:16 +02:00
|
|
|
/*
|
|
|
|
* Virtio 9p user. xattr callback
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2011-06-01 09:05:14 +02:00
|
|
|
#include "hw/virtio.h"
|
2010-10-18 11:58:16 +02:00
|
|
|
#include "virtio-9p.h"
|
2011-01-28 13:39:08 +01:00
|
|
|
#include "fsdev/file-op-9p.h"
|
2010-10-18 11:58:16 +02:00
|
|
|
#include "virtio-9p-xattr.h"
|
|
|
|
|
|
|
|
|
|
|
|
static ssize_t mp_user_getxattr(FsContext *ctx, const char *path,
|
|
|
|
const char *name, void *value, size_t size)
|
|
|
|
{
|
2011-06-01 09:05:14 +02:00
|
|
|
char buffer[PATH_MAX];
|
2010-10-18 11:58:16 +02:00
|
|
|
if (strncmp(name, "user.virtfs.", 12) == 0) {
|
|
|
|
/*
|
|
|
|
* Don't allow fetch of user.virtfs namesapce
|
|
|
|
* in case of mapped security
|
|
|
|
*/
|
|
|
|
errno = ENOATTR;
|
|
|
|
return -1;
|
|
|
|
}
|
2011-06-01 09:05:14 +02:00
|
|
|
return lgetxattr(rpath(ctx, path, buffer), name, value, size);
|
2010-10-18 11:58:16 +02: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 11:58:16 +02: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 11:58:16 +02:00
|
|
|
}
|
|
|
|
if (!value) {
|
|
|
|
return name_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size < name_size) {
|
|
|
|
errno = ERANGE;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
strncpy(value, name, name_size);
|
|
|
|
return name_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name,
|
|
|
|
void *value, size_t size, int flags)
|
|
|
|
{
|
2011-06-01 09:05:14 +02:00
|
|
|
char buffer[PATH_MAX];
|
2010-10-18 11:58:16 +02:00
|
|
|
if (strncmp(name, "user.virtfs.", 12) == 0) {
|
|
|
|
/*
|
|
|
|
* Don't allow fetch of user.virtfs namesapce
|
|
|
|
* in case of mapped security
|
|
|
|
*/
|
|
|
|
errno = EACCES;
|
|
|
|
return -1;
|
|
|
|
}
|
2011-06-01 09:05:14 +02:00
|
|
|
return lsetxattr(rpath(ctx, path, buffer), name, value, size, flags);
|
2010-10-18 11:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mp_user_removexattr(FsContext *ctx,
|
|
|
|
const char *path, const char *name)
|
|
|
|
{
|
2011-06-01 09:05:14 +02:00
|
|
|
char buffer[PATH_MAX];
|
2010-10-18 11:58:16 +02:00
|
|
|
if (strncmp(name, "user.virtfs.", 12) == 0) {
|
|
|
|
/*
|
|
|
|
* Don't allow fetch of user.virtfs namesapce
|
|
|
|
* in case of mapped security
|
|
|
|
*/
|
|
|
|
errno = EACCES;
|
|
|
|
return -1;
|
|
|
|
}
|
2011-06-01 09:05:14 +02:00
|
|
|
return lremovexattr(rpath(ctx, path, buffer), name);
|
2010-10-18 11:58:16 +02: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,
|
|
|
|
};
|