]> git.proxmox.com Git - qemu.git/blob - hw/virtio-9p-xattr-user.c
Merge remote branch 'spice/config.2' into staging
[qemu.git] / hw / virtio-9p-xattr-user.c
1 /*
2 * Virtio 9p user. xattr callback
3 *
4 * Copyright IBM, Corp. 2010
5 *
6 * Authors:
7 * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
12 */
13
14 #include <sys/types.h>
15 #include "virtio.h"
16 #include "virtio-9p.h"
17 #include "file-op-9p.h"
18 #include "virtio-9p-xattr.h"
19
20
21 static ssize_t mp_user_getxattr(FsContext *ctx, const char *path,
22 const char *name, void *value, size_t size)
23 {
24 if (strncmp(name, "user.virtfs.", 12) == 0) {
25 /*
26 * Don't allow fetch of user.virtfs namesapce
27 * in case of mapped security
28 */
29 errno = ENOATTR;
30 return -1;
31 }
32 return lgetxattr(rpath(ctx, path), name, value, size);
33 }
34
35 static ssize_t mp_user_listxattr(FsContext *ctx, const char *path,
36 char *name, void *value, size_t size)
37 {
38 int name_size = strlen(name) + 1;
39 if (strncmp(name, "user.virtfs.", 12) == 0) {
40
41 /* check if it is a mapped posix acl */
42 if (strncmp(name, "user.virtfs.system.posix_acl_", 29) == 0) {
43 /* adjust the name and size */
44 name += 12;
45 name_size -= 12;
46 } else {
47 /*
48 * Don't allow fetch of user.virtfs namesapce
49 * in case of mapped security
50 */
51 return 0;
52 }
53 }
54 if (!value) {
55 return name_size;
56 }
57
58 if (size < name_size) {
59 errno = ERANGE;
60 return -1;
61 }
62
63 strncpy(value, name, name_size);
64 return name_size;
65 }
66
67 static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name,
68 void *value, size_t size, int flags)
69 {
70 if (strncmp(name, "user.virtfs.", 12) == 0) {
71 /*
72 * Don't allow fetch of user.virtfs namesapce
73 * in case of mapped security
74 */
75 errno = EACCES;
76 return -1;
77 }
78 return lsetxattr(rpath(ctx, path), name, value, size, flags);
79 }
80
81 static int mp_user_removexattr(FsContext *ctx,
82 const char *path, const char *name)
83 {
84 if (strncmp(name, "user.virtfs.", 12) == 0) {
85 /*
86 * Don't allow fetch of user.virtfs namesapce
87 * in case of mapped security
88 */
89 errno = EACCES;
90 return -1;
91 }
92 return lremovexattr(rpath(ctx, path), name);
93 }
94
95 XattrOperations mapped_user_xattr = {
96 .name = "user.",
97 .getxattr = mp_user_getxattr,
98 .setxattr = mp_user_setxattr,
99 .listxattr = mp_user_listxattr,
100 .removexattr = mp_user_removexattr,
101 };
102
103 XattrOperations passthrough_user_xattr = {
104 .name = "user.",
105 .getxattr = pt_getxattr,
106 .setxattr = pt_setxattr,
107 .listxattr = pt_listxattr,
108 .removexattr = pt_removexattr,
109 };