]> git.proxmox.com Git - qemu.git/blame - hw/9pfs/virtio-9p-posix-acl.c
configure: fix detection for xattr.h on modern distributions
[qemu.git] / hw / 9pfs / virtio-9p-posix-acl.c
CommitLineData
70fc55eb
AK
1/*
2 * Virtio 9p system.posix* xattr callback
3 *
4 * Copyright IBM, Corp. 2010
5 *
6 * Authors:
7 * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
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>
4f26f2b6 15#include "qemu-xattr.h"
873c3213 16#include "hw/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
26static ssize_t mp_pacl_getxattr(FsContext *ctx, const char *path,
27 const char *name, void *value, size_t size)
28{
faa44e3d
VJJ
29 char buffer[PATH_MAX];
30 return lgetxattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, value, size);
70fc55eb
AK
31}
32
33static ssize_t mp_pacl_listxattr(FsContext *ctx, const char *path,
34 char *name, void *value, size_t osize)
35{
36 ssize_t len = sizeof(ACL_ACCESS);
37
38 if (!value) {
39 return len;
40 }
41
42 if (osize < len) {
43 errno = ERANGE;
44 return -1;
45 }
46
47 strncpy(value, ACL_ACCESS, len);
48 return 0;
49}
50
51static int mp_pacl_setxattr(FsContext *ctx, const char *path, const char *name,
52 void *value, size_t size, int flags)
53{
faa44e3d
VJJ
54 char buffer[PATH_MAX];
55 return lsetxattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, value,
56 size, flags);
70fc55eb
AK
57}
58
59static int mp_pacl_removexattr(FsContext *ctx,
60 const char *path, const char *name)
61{
62 int ret;
faa44e3d
VJJ
63 char buffer[PATH_MAX];
64 ret = lremovexattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS);
70fc55eb
AK
65 if (ret == -1 && errno == ENODATA) {
66 /*
a0994761 67 * We don't get ENODATA error when trying to remove a
70fc55eb
AK
68 * posix acl that is not present. So don't throw the error
69 * even in case of mapped security model
70 */
71 errno = 0;
72 ret = 0;
73 }
74 return ret;
75}
76
77static ssize_t mp_dacl_getxattr(FsContext *ctx, const char *path,
78 const char *name, void *value, size_t size)
79{
faa44e3d
VJJ
80 char buffer[PATH_MAX];
81 return lgetxattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT, value, size);
70fc55eb
AK
82}
83
84static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path,
85 char *name, void *value, size_t osize)
86{
87 ssize_t len = sizeof(ACL_DEFAULT);
88
89 if (!value) {
90 return len;
91 }
92
93 if (osize < len) {
94 errno = ERANGE;
95 return -1;
96 }
97
98 strncpy(value, ACL_DEFAULT, len);
99 return 0;
100}
101
102static int mp_dacl_setxattr(FsContext *ctx, const char *path, const char *name,
103 void *value, size_t size, int flags)
104{
faa44e3d
VJJ
105 char buffer[PATH_MAX];
106 return lsetxattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT, value,
107 size, flags);
70fc55eb
AK
108}
109
110static int mp_dacl_removexattr(FsContext *ctx,
111 const char *path, const char *name)
112{
a0994761 113 int ret;
faa44e3d
VJJ
114 char buffer[PATH_MAX];
115 ret = lremovexattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT);
a0994761
AK
116 if (ret == -1 && errno == ENODATA) {
117 /*
118 * We don't get ENODATA error when trying to remove a
119 * posix acl that is not present. So don't throw the error
120 * even in case of mapped security model
121 */
122 errno = 0;
123 ret = 0;
124 }
125 return ret;
70fc55eb
AK
126}
127
128
129XattrOperations mapped_pacl_xattr = {
130 .name = "system.posix_acl_access",
131 .getxattr = mp_pacl_getxattr,
132 .setxattr = mp_pacl_setxattr,
133 .listxattr = mp_pacl_listxattr,
134 .removexattr = mp_pacl_removexattr,
135};
136
137XattrOperations mapped_dacl_xattr = {
138 .name = "system.posix_acl_default",
139 .getxattr = mp_dacl_getxattr,
140 .setxattr = mp_dacl_setxattr,
141 .listxattr = mp_dacl_listxattr,
142 .removexattr = mp_dacl_removexattr,
143};
144
145XattrOperations passthrough_acl_xattr = {
146 .name = "system.posix_acl_",
147 .getxattr = pt_getxattr,
148 .setxattr = pt_setxattr,
149 .listxattr = pt_listxattr,
150 .removexattr = pt_removexattr,
151};
152
153XattrOperations none_acl_xattr = {
154 .name = "system.posix_acl_",
155 .getxattr = notsup_getxattr,
156 .setxattr = notsup_setxattr,
157 .listxattr = notsup_listxattr,
158 .removexattr = notsup_removexattr,
159};