9pfs: local: lsetxattr: don't follow symlinks
[qemu/kevin.git] / hw / 9pfs / 9p-xattr-user.c
blob1840a5db66f3f92b9ac8b36ce05b313d3e34888f
1 /*
2 * 9p user. xattr callback
4 * Copyright IBM, Corp. 2010
6 * Authors:
7 * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
14 #include "qemu/osdep.h"
15 #include "9p.h"
16 #include "fsdev/file-op-9p.h"
17 #include "9p-xattr.h"
20 static ssize_t mp_user_getxattr(FsContext *ctx, const char *path,
21 const char *name, void *value, size_t size)
23 if (strncmp(name, "user.virtfs.", 12) == 0) {
25 * Don't allow fetch of user.virtfs namesapce
26 * in case of mapped security
28 errno = ENOATTR;
29 return -1;
31 return local_getxattr_nofollow(ctx, path, name, value, size);
34 static ssize_t mp_user_listxattr(FsContext *ctx, const char *path,
35 char *name, void *value, size_t size)
37 int name_size = strlen(name) + 1;
38 if (strncmp(name, "user.virtfs.", 12) == 0) {
40 /* check if it is a mapped posix acl */
41 if (strncmp(name, "user.virtfs.system.posix_acl_", 29) == 0) {
42 /* adjust the name and size */
43 name += 12;
44 name_size -= 12;
45 } else {
47 * Don't allow fetch of user.virtfs namesapce
48 * in case of mapped security
50 return 0;
53 if (!value) {
54 return name_size;
57 if (size < name_size) {
58 errno = ERANGE;
59 return -1;
62 /* name_size includes the trailing NUL. */
63 memcpy(value, name, name_size);
64 return name_size;
67 static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name,
68 void *value, size_t size, int flags)
70 if (strncmp(name, "user.virtfs.", 12) == 0) {
72 * Don't allow fetch of user.virtfs namesapce
73 * in case of mapped security
75 errno = EACCES;
76 return -1;
78 return local_setxattr_nofollow(ctx, path, name, value, size, flags);
81 static int mp_user_removexattr(FsContext *ctx,
82 const char *path, const char *name)
84 char *buffer;
85 int ret;
87 if (strncmp(name, "user.virtfs.", 12) == 0) {
89 * Don't allow fetch of user.virtfs namesapce
90 * in case of mapped security
92 errno = EACCES;
93 return -1;
95 buffer = rpath(ctx, path);
96 ret = lremovexattr(buffer, name);
97 g_free(buffer);
98 return ret;
101 XattrOperations mapped_user_xattr = {
102 .name = "user.",
103 .getxattr = mp_user_getxattr,
104 .setxattr = mp_user_setxattr,
105 .listxattr = mp_user_listxattr,
106 .removexattr = mp_user_removexattr,
109 XattrOperations passthrough_user_xattr = {
110 .name = "user.",
111 .getxattr = pt_getxattr,
112 .setxattr = pt_setxattr,
113 .listxattr = pt_listxattr,
114 .removexattr = pt_removexattr,