m68k: Replace gen_im32() by tcg_const_i32()
[qemu.git] / hw / 9pfs / virtio-9p-posix-acl.c
blob575abe86b0951f638e05828200159154834f219f
1 /*
2 * Virtio 9p system.posix* xattr callback
4 * Copyright IBM, Corp. 2010
6 * Authors:
7 * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
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 <attr/xattr.h>
16 #include "virtio.h"
17 #include "virtio-9p.h"
18 #include "fsdev/file-op-9p.h"
19 #include "virtio-9p-xattr.h"
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"
26 static ssize_t mp_pacl_getxattr(FsContext *ctx, const char *path,
27 const char *name, void *value, size_t size)
29 return lgetxattr(rpath(ctx, path), MAP_ACL_ACCESS, value, size);
32 static ssize_t mp_pacl_listxattr(FsContext *ctx, const char *path,
33 char *name, void *value, size_t osize)
35 ssize_t len = sizeof(ACL_ACCESS);
37 if (!value) {
38 return len;
41 if (osize < len) {
42 errno = ERANGE;
43 return -1;
46 strncpy(value, ACL_ACCESS, len);
47 return 0;
50 static int mp_pacl_setxattr(FsContext *ctx, const char *path, const char *name,
51 void *value, size_t size, int flags)
53 return lsetxattr(rpath(ctx, path), MAP_ACL_ACCESS, value, size, flags);
56 static int mp_pacl_removexattr(FsContext *ctx,
57 const char *path, const char *name)
59 int ret;
60 ret = lremovexattr(rpath(ctx, path), MAP_ACL_ACCESS);
61 if (ret == -1 && errno == ENODATA) {
63 * We don't get ENODATA error when trying to remove a
64 * posix acl that is not present. So don't throw the error
65 * even in case of mapped security model
67 errno = 0;
68 ret = 0;
70 return ret;
73 static ssize_t mp_dacl_getxattr(FsContext *ctx, const char *path,
74 const char *name, void *value, size_t size)
76 return lgetxattr(rpath(ctx, path), MAP_ACL_DEFAULT, value, size);
79 static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path,
80 char *name, void *value, size_t osize)
82 ssize_t len = sizeof(ACL_DEFAULT);
84 if (!value) {
85 return len;
88 if (osize < len) {
89 errno = ERANGE;
90 return -1;
93 strncpy(value, ACL_DEFAULT, len);
94 return 0;
97 static int mp_dacl_setxattr(FsContext *ctx, const char *path, const char *name,
98 void *value, size_t size, int flags)
100 return lsetxattr(rpath(ctx, path), MAP_ACL_DEFAULT, value, size, flags);
103 static int mp_dacl_removexattr(FsContext *ctx,
104 const char *path, const char *name)
106 int ret;
107 ret = lremovexattr(rpath(ctx, path), MAP_ACL_DEFAULT);
108 if (ret == -1 && errno == ENODATA) {
110 * We don't get ENODATA error when trying to remove a
111 * posix acl that is not present. So don't throw the error
112 * even in case of mapped security model
114 errno = 0;
115 ret = 0;
117 return ret;
121 XattrOperations mapped_pacl_xattr = {
122 .name = "system.posix_acl_access",
123 .getxattr = mp_pacl_getxattr,
124 .setxattr = mp_pacl_setxattr,
125 .listxattr = mp_pacl_listxattr,
126 .removexattr = mp_pacl_removexattr,
129 XattrOperations mapped_dacl_xattr = {
130 .name = "system.posix_acl_default",
131 .getxattr = mp_dacl_getxattr,
132 .setxattr = mp_dacl_setxattr,
133 .listxattr = mp_dacl_listxattr,
134 .removexattr = mp_dacl_removexattr,
137 XattrOperations passthrough_acl_xattr = {
138 .name = "system.posix_acl_",
139 .getxattr = pt_getxattr,
140 .setxattr = pt_setxattr,
141 .listxattr = pt_listxattr,
142 .removexattr = pt_removexattr,
145 XattrOperations none_acl_xattr = {
146 .name = "system.posix_acl_",
147 .getxattr = notsup_getxattr,
148 .setxattr = notsup_setxattr,
149 .listxattr = notsup_listxattr,
150 .removexattr = notsup_removexattr,