]>
Commit | Line | Data |
---|---|---|
fc22118d | 1 | /* |
267ae092 | 2 | * 9p user. xattr callback |
fc22118d AK |
3 | * |
4 | * Copyright IBM, Corp. 2010 | |
5 | * | |
6 | * Authors: | |
7 | * Aneesh Kumar K.V <[email protected]> | |
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 | ||
6f569084 CS |
14 | /* |
15 | * Not so fast! You might want to read the 9p developer docs first: | |
16 | * https://wiki.qemu.org/Documentation/9p | |
17 | */ | |
18 | ||
fbc04127 | 19 | #include "qemu/osdep.h" |
ebe74f8b | 20 | #include "9p.h" |
353ac78d | 21 | #include "fsdev/file-op-9p.h" |
267ae092 | 22 | #include "9p-xattr.h" |
fc22118d AK |
23 | |
24 | ||
25 | static ssize_t mp_user_getxattr(FsContext *ctx, const char *path, | |
26 | const char *name, void *value, size_t size) | |
27 | { | |
28 | if (strncmp(name, "user.virtfs.", 12) == 0) { | |
29 | /* | |
a0984714 | 30 | * Don't allow fetch of user.virtfs namespace |
fc22118d AK |
31 | * in case of mapped security |
32 | */ | |
33 | errno = ENOATTR; | |
34 | return -1; | |
35 | } | |
56ad3e54 | 36 | return local_getxattr_nofollow(ctx, path, name, value, size); |
fc22118d AK |
37 | } |
38 | ||
39 | static ssize_t mp_user_listxattr(FsContext *ctx, const char *path, | |
40 | char *name, void *value, size_t size) | |
41 | { | |
42 | int name_size = strlen(name) + 1; | |
43 | if (strncmp(name, "user.virtfs.", 12) == 0) { | |
70fc55eb AK |
44 | |
45 | /* check if it is a mapped posix acl */ | |
46 | if (strncmp(name, "user.virtfs.system.posix_acl_", 29) == 0) { | |
47 | /* adjust the name and size */ | |
48 | name += 12; | |
49 | name_size -= 12; | |
50 | } else { | |
51 | /* | |
a0984714 | 52 | * Don't allow fetch of user.virtfs namespace |
70fc55eb AK |
53 | * in case of mapped security |
54 | */ | |
55 | return 0; | |
56 | } | |
fc22118d AK |
57 | } |
58 | if (!value) { | |
59 | return name_size; | |
60 | } | |
61 | ||
62 | if (size < name_size) { | |
63 | errno = ERANGE; | |
64 | return -1; | |
65 | } | |
66 | ||
9238c209 JM |
67 | /* name_size includes the trailing NUL. */ |
68 | memcpy(value, name, name_size); | |
fc22118d AK |
69 | return name_size; |
70 | } | |
71 | ||
72 | static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name, | |
73 | void *value, size_t size, int flags) | |
74 | { | |
75 | if (strncmp(name, "user.virtfs.", 12) == 0) { | |
76 | /* | |
a0984714 | 77 | * Don't allow fetch of user.virtfs namespace |
fc22118d AK |
78 | * in case of mapped security |
79 | */ | |
80 | errno = EACCES; | |
81 | return -1; | |
82 | } | |
3e36aba7 | 83 | return local_setxattr_nofollow(ctx, path, name, value, size, flags); |
fc22118d AK |
84 | } |
85 | ||
86 | static int mp_user_removexattr(FsContext *ctx, | |
87 | const char *path, const char *name) | |
88 | { | |
89 | if (strncmp(name, "user.virtfs.", 12) == 0) { | |
90 | /* | |
a0984714 | 91 | * Don't allow fetch of user.virtfs namespace |
fc22118d AK |
92 | * in case of mapped security |
93 | */ | |
94 | errno = EACCES; | |
95 | return -1; | |
96 | } | |
72f0d0bf | 97 | return local_removexattr_nofollow(ctx, path, name); |
fc22118d AK |
98 | } |
99 | ||
100 | XattrOperations mapped_user_xattr = { | |
101 | .name = "user.", | |
102 | .getxattr = mp_user_getxattr, | |
103 | .setxattr = mp_user_setxattr, | |
104 | .listxattr = mp_user_listxattr, | |
105 | .removexattr = mp_user_removexattr, | |
106 | }; | |
107 | ||
108 | XattrOperations passthrough_user_xattr = { | |
109 | .name = "user.", | |
110 | .getxattr = pt_getxattr, | |
111 | .setxattr = pt_setxattr, | |
112 | .listxattr = pt_listxattr, | |
113 | .removexattr = pt_removexattr, | |
114 | }; |