]>
Commit | Line | Data |
---|---|---|
70fc55eb AK |
1 | /* |
2 | * Virtio 9p system.posix* xattr callback | |
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 | ||
14 | #include <sys/types.h> | |
1de7afc9 | 15 | #include "qemu/xattr.h" |
0d09e41a | 16 | #include "hw/virtio/virtio.h" |
70fc55eb | 17 | #include "virtio-9p.h" |
353ac78d | 18 | #include "fsdev/file-op-9p.h" |
70fc55eb AK |
19 | #include "virtio-9p-xattr.h" |
20 | ||
21 | #define MAP_ACL_ACCESS "user.virtfs.system.posix_acl_access" | |
22 | #define MAP_ACL_DEFAULT "user.virtfs.system.posix_acl_default" | |
23 | #define ACL_ACCESS "system.posix_acl_access" | |
24 | #define ACL_DEFAULT "system.posix_acl_default" | |
25 | ||
26 | static ssize_t mp_pacl_getxattr(FsContext *ctx, const char *path, | |
27 | const char *name, void *value, size_t size) | |
28 | { | |
4fa4ce71 CG |
29 | char *buffer; |
30 | ssize_t ret; | |
31 | ||
32 | buffer = rpath(ctx, path); | |
33 | ret = lgetxattr(buffer, MAP_ACL_ACCESS, value, size); | |
34 | g_free(buffer); | |
35 | return ret; | |
70fc55eb AK |
36 | } |
37 | ||
38 | static ssize_t mp_pacl_listxattr(FsContext *ctx, const char *path, | |
39 | char *name, void *value, size_t osize) | |
40 | { | |
41 | ssize_t len = sizeof(ACL_ACCESS); | |
42 | ||
43 | if (!value) { | |
44 | return len; | |
45 | } | |
46 | ||
47 | if (osize < len) { | |
48 | errno = ERANGE; | |
49 | return -1; | |
50 | } | |
51 | ||
9238c209 JM |
52 | /* len includes the trailing NUL */ |
53 | memcpy(value, ACL_ACCESS, len); | |
70fc55eb AK |
54 | return 0; |
55 | } | |
56 | ||
57 | static int mp_pacl_setxattr(FsContext *ctx, const char *path, const char *name, | |
58 | void *value, size_t size, int flags) | |
59 | { | |
4fa4ce71 CG |
60 | char *buffer; |
61 | int ret; | |
62 | ||
63 | buffer = rpath(ctx, path); | |
64 | ret = lsetxattr(buffer, MAP_ACL_ACCESS, value, size, flags); | |
65 | g_free(buffer); | |
66 | return ret; | |
70fc55eb AK |
67 | } |
68 | ||
69 | static int mp_pacl_removexattr(FsContext *ctx, | |
70 | const char *path, const char *name) | |
71 | { | |
72 | int ret; | |
4fa4ce71 CG |
73 | char *buffer; |
74 | ||
75 | buffer = rpath(ctx, path); | |
76 | ret = lremovexattr(buffer, MAP_ACL_ACCESS); | |
70fc55eb AK |
77 | if (ret == -1 && errno == ENODATA) { |
78 | /* | |
a0994761 | 79 | * We don't get ENODATA error when trying to remove a |
70fc55eb AK |
80 | * posix acl that is not present. So don't throw the error |
81 | * even in case of mapped security model | |
82 | */ | |
83 | errno = 0; | |
84 | ret = 0; | |
85 | } | |
4fa4ce71 | 86 | g_free(buffer); |
70fc55eb AK |
87 | return ret; |
88 | } | |
89 | ||
90 | static ssize_t mp_dacl_getxattr(FsContext *ctx, const char *path, | |
91 | const char *name, void *value, size_t size) | |
92 | { | |
4fa4ce71 CG |
93 | char *buffer; |
94 | ssize_t ret; | |
95 | ||
96 | buffer = rpath(ctx, path); | |
97 | ret = lgetxattr(buffer, MAP_ACL_DEFAULT, value, size); | |
98 | g_free(buffer); | |
99 | return ret; | |
70fc55eb AK |
100 | } |
101 | ||
102 | static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path, | |
103 | char *name, void *value, size_t osize) | |
104 | { | |
105 | ssize_t len = sizeof(ACL_DEFAULT); | |
106 | ||
107 | if (!value) { | |
108 | return len; | |
109 | } | |
110 | ||
111 | if (osize < len) { | |
112 | errno = ERANGE; | |
113 | return -1; | |
114 | } | |
115 | ||
9238c209 JM |
116 | /* len includes the trailing NUL */ |
117 | memcpy(value, ACL_ACCESS, len); | |
70fc55eb AK |
118 | return 0; |
119 | } | |
120 | ||
121 | static int mp_dacl_setxattr(FsContext *ctx, const char *path, const char *name, | |
122 | void *value, size_t size, int flags) | |
123 | { | |
4fa4ce71 CG |
124 | char *buffer; |
125 | int ret; | |
126 | ||
127 | buffer = rpath(ctx, path); | |
128 | ret = lsetxattr(buffer, MAP_ACL_DEFAULT, value, size, flags); | |
129 | g_free(buffer); | |
130 | return ret; | |
70fc55eb AK |
131 | } |
132 | ||
133 | static int mp_dacl_removexattr(FsContext *ctx, | |
134 | const char *path, const char *name) | |
135 | { | |
a0994761 | 136 | int ret; |
4fa4ce71 CG |
137 | char *buffer; |
138 | ||
139 | buffer = rpath(ctx, path); | |
140 | ret = lremovexattr(buffer, MAP_ACL_DEFAULT); | |
a0994761 AK |
141 | if (ret == -1 && errno == ENODATA) { |
142 | /* | |
143 | * We don't get ENODATA error when trying to remove a | |
144 | * posix acl that is not present. So don't throw the error | |
145 | * even in case of mapped security model | |
146 | */ | |
147 | errno = 0; | |
148 | ret = 0; | |
149 | } | |
4fa4ce71 | 150 | g_free(buffer); |
a0994761 | 151 | return ret; |
70fc55eb AK |
152 | } |
153 | ||
154 | ||
155 | XattrOperations mapped_pacl_xattr = { | |
156 | .name = "system.posix_acl_access", | |
157 | .getxattr = mp_pacl_getxattr, | |
158 | .setxattr = mp_pacl_setxattr, | |
159 | .listxattr = mp_pacl_listxattr, | |
160 | .removexattr = mp_pacl_removexattr, | |
161 | }; | |
162 | ||
163 | XattrOperations mapped_dacl_xattr = { | |
164 | .name = "system.posix_acl_default", | |
165 | .getxattr = mp_dacl_getxattr, | |
166 | .setxattr = mp_dacl_setxattr, | |
167 | .listxattr = mp_dacl_listxattr, | |
168 | .removexattr = mp_dacl_removexattr, | |
169 | }; | |
170 | ||
171 | XattrOperations passthrough_acl_xattr = { | |
172 | .name = "system.posix_acl_", | |
173 | .getxattr = pt_getxattr, | |
174 | .setxattr = pt_setxattr, | |
175 | .listxattr = pt_listxattr, | |
176 | .removexattr = pt_removexattr, | |
177 | }; | |
178 | ||
179 | XattrOperations none_acl_xattr = { | |
180 | .name = "system.posix_acl_", | |
181 | .getxattr = notsup_getxattr, | |
182 | .setxattr = notsup_setxattr, | |
183 | .listxattr = notsup_listxattr, | |
184 | .removexattr = notsup_removexattr, | |
185 | }; |