2 * 9p system.posix* xattr callback
4 * Copyright IBM, Corp. 2010
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 <sys/types.h>
15 #include "qemu/xattr.h"
17 #include "fsdev/file-op-9p.h"
20 #define MAP_ACL_ACCESS "user.virtfs.system.posix_acl_access"
21 #define MAP_ACL_DEFAULT "user.virtfs.system.posix_acl_default"
22 #define ACL_ACCESS "system.posix_acl_access"
23 #define ACL_DEFAULT "system.posix_acl_default"
25 static ssize_t mp_pacl_getxattr(FsContext *ctx, const char *path,
26 const char *name, void *value, size_t size)
31 buffer = rpath(ctx, path);
32 ret = lgetxattr(buffer, MAP_ACL_ACCESS, value, size);
37 static ssize_t mp_pacl_listxattr(FsContext *ctx, const char *path,
38 char *name, void *value, size_t osize)
40 ssize_t len = sizeof(ACL_ACCESS);
51 /* len includes the trailing NUL */
52 memcpy(value, ACL_ACCESS, len);
56 static int mp_pacl_setxattr(FsContext *ctx, const char *path, const char *name,
57 void *value, size_t size, int flags)
62 buffer = rpath(ctx, path);
63 ret = lsetxattr(buffer, MAP_ACL_ACCESS, value, size, flags);
68 static int mp_pacl_removexattr(FsContext *ctx,
69 const char *path, const char *name)
74 buffer = rpath(ctx, path);
75 ret = lremovexattr(buffer, MAP_ACL_ACCESS);
76 if (ret == -1 && errno == ENODATA) {
78 * We don't get ENODATA error when trying to remove a
79 * posix acl that is not present. So don't throw the error
80 * even in case of mapped security model
89 static ssize_t mp_dacl_getxattr(FsContext *ctx, const char *path,
90 const char *name, void *value, size_t size)
95 buffer = rpath(ctx, path);
96 ret = lgetxattr(buffer, MAP_ACL_DEFAULT, value, size);
101 static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path,
102 char *name, void *value, size_t osize)
104 ssize_t len = sizeof(ACL_DEFAULT);
115 /* len includes the trailing NUL */
116 memcpy(value, ACL_DEFAULT, len);
120 static int mp_dacl_setxattr(FsContext *ctx, const char *path, const char *name,
121 void *value, size_t size, int flags)
126 buffer = rpath(ctx, path);
127 ret = lsetxattr(buffer, MAP_ACL_DEFAULT, value, size, flags);
132 static int mp_dacl_removexattr(FsContext *ctx,
133 const char *path, const char *name)
138 buffer = rpath(ctx, path);
139 ret = lremovexattr(buffer, MAP_ACL_DEFAULT);
140 if (ret == -1 && errno == ENODATA) {
142 * We don't get ENODATA error when trying to remove a
143 * posix acl that is not present. So don't throw the error
144 * even in case of mapped security model
154 XattrOperations mapped_pacl_xattr = {
155 .name = "system.posix_acl_access",
156 .getxattr = mp_pacl_getxattr,
157 .setxattr = mp_pacl_setxattr,
158 .listxattr = mp_pacl_listxattr,
159 .removexattr = mp_pacl_removexattr,
162 XattrOperations mapped_dacl_xattr = {
163 .name = "system.posix_acl_default",
164 .getxattr = mp_dacl_getxattr,
165 .setxattr = mp_dacl_setxattr,
166 .listxattr = mp_dacl_listxattr,
167 .removexattr = mp_dacl_removexattr,
170 XattrOperations passthrough_acl_xattr = {
171 .name = "system.posix_acl_",
172 .getxattr = pt_getxattr,
173 .setxattr = pt_setxattr,
174 .listxattr = pt_listxattr,
175 .removexattr = pt_removexattr,
178 XattrOperations none_acl_xattr = {
179 .name = "system.posix_acl_",
180 .getxattr = notsup_getxattr,
181 .setxattr = notsup_setxattr,
182 .listxattr = notsup_listxattr,
183 .removexattr = notsup_removexattr,