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 "qemu/osdep.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)
28 return local_getxattr_nofollow(ctx, path, MAP_ACL_ACCESS, value, size);
31 static ssize_t mp_pacl_listxattr(FsContext *ctx, const char *path,
32 char *name, void *value, size_t osize)
34 ssize_t len = sizeof(ACL_ACCESS);
45 /* len includes the trailing NUL */
46 memcpy(value, ACL_ACCESS, len);
50 static int mp_pacl_setxattr(FsContext *ctx, const char *path, const char *name,
51 void *value, size_t size, int flags)
56 buffer = rpath(ctx, path);
57 ret = lsetxattr(buffer, MAP_ACL_ACCESS, value, size, flags);
62 static int mp_pacl_removexattr(FsContext *ctx,
63 const char *path, const char *name)
68 buffer = rpath(ctx, path);
69 ret = lremovexattr(buffer, MAP_ACL_ACCESS);
70 if (ret == -1 && errno == ENODATA) {
72 * We don't get ENODATA error when trying to remove a
73 * posix acl that is not present. So don't throw the error
74 * even in case of mapped security model
83 static ssize_t mp_dacl_getxattr(FsContext *ctx, const char *path,
84 const char *name, void *value, size_t size)
86 return local_getxattr_nofollow(ctx, path, MAP_ACL_DEFAULT, value, size);
89 static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path,
90 char *name, void *value, size_t osize)
92 ssize_t len = sizeof(ACL_DEFAULT);
103 /* len includes the trailing NUL */
104 memcpy(value, ACL_DEFAULT, len);
108 static int mp_dacl_setxattr(FsContext *ctx, const char *path, const char *name,
109 void *value, size_t size, int flags)
114 buffer = rpath(ctx, path);
115 ret = lsetxattr(buffer, MAP_ACL_DEFAULT, value, size, flags);
120 static int mp_dacl_removexattr(FsContext *ctx,
121 const char *path, const char *name)
126 buffer = rpath(ctx, path);
127 ret = lremovexattr(buffer, MAP_ACL_DEFAULT);
128 if (ret == -1 && errno == ENODATA) {
130 * We don't get ENODATA error when trying to remove a
131 * posix acl that is not present. So don't throw the error
132 * even in case of mapped security model
142 XattrOperations mapped_pacl_xattr = {
143 .name = "system.posix_acl_access",
144 .getxattr = mp_pacl_getxattr,
145 .setxattr = mp_pacl_setxattr,
146 .listxattr = mp_pacl_listxattr,
147 .removexattr = mp_pacl_removexattr,
150 XattrOperations mapped_dacl_xattr = {
151 .name = "system.posix_acl_default",
152 .getxattr = mp_dacl_getxattr,
153 .setxattr = mp_dacl_setxattr,
154 .listxattr = mp_dacl_listxattr,
155 .removexattr = mp_dacl_removexattr,
158 XattrOperations passthrough_acl_xattr = {
159 .name = "system.posix_acl_",
160 .getxattr = pt_getxattr,
161 .setxattr = pt_setxattr,
162 .listxattr = pt_listxattr,
163 .removexattr = pt_removexattr,
166 XattrOperations none_acl_xattr = {
167 .name = "system.posix_acl_",
168 .getxattr = notsup_getxattr,
169 .setxattr = notsup_setxattr,
170 .listxattr = notsup_listxattr,
171 .removexattr = notsup_removexattr,