]>
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 <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 | ||
26 | static ssize_t mp_pacl_getxattr(FsContext *ctx, const char *path, | |
27 | const char *name, void *value, size_t size) | |
28 | { | |
faa44e3d VJ |
29 | char buffer[PATH_MAX]; |
30 | return lgetxattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, value, size); | |
70fc55eb AK |
31 | } |
32 | ||
33 | static 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 | ||
9238c209 JM |
47 | /* len includes the trailing NUL */ |
48 | memcpy(value, ACL_ACCESS, len); | |
70fc55eb AK |
49 | return 0; |
50 | } | |
51 | ||
52 | static int mp_pacl_setxattr(FsContext *ctx, const char *path, const char *name, | |
53 | void *value, size_t size, int flags) | |
54 | { | |
faa44e3d VJ |
55 | char buffer[PATH_MAX]; |
56 | return lsetxattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, value, | |
57 | size, flags); | |
70fc55eb AK |
58 | } |
59 | ||
60 | static int mp_pacl_removexattr(FsContext *ctx, | |
61 | const char *path, const char *name) | |
62 | { | |
63 | int ret; | |
faa44e3d VJ |
64 | char buffer[PATH_MAX]; |
65 | ret = lremovexattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS); | |
70fc55eb AK |
66 | if (ret == -1 && errno == ENODATA) { |
67 | /* | |
a0994761 | 68 | * We don't get ENODATA error when trying to remove a |
70fc55eb AK |
69 | * posix acl that is not present. So don't throw the error |
70 | * even in case of mapped security model | |
71 | */ | |
72 | errno = 0; | |
73 | ret = 0; | |
74 | } | |
75 | return ret; | |
76 | } | |
77 | ||
78 | static ssize_t mp_dacl_getxattr(FsContext *ctx, const char *path, | |
79 | const char *name, void *value, size_t size) | |
80 | { | |
faa44e3d VJ |
81 | char buffer[PATH_MAX]; |
82 | return lgetxattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT, value, size); | |
70fc55eb AK |
83 | } |
84 | ||
85 | static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path, | |
86 | char *name, void *value, size_t osize) | |
87 | { | |
88 | ssize_t len = sizeof(ACL_DEFAULT); | |
89 | ||
90 | if (!value) { | |
91 | return len; | |
92 | } | |
93 | ||
94 | if (osize < len) { | |
95 | errno = ERANGE; | |
96 | return -1; | |
97 | } | |
98 | ||
9238c209 JM |
99 | /* len includes the trailing NUL */ |
100 | memcpy(value, ACL_ACCESS, len); | |
70fc55eb AK |
101 | return 0; |
102 | } | |
103 | ||
104 | static int mp_dacl_setxattr(FsContext *ctx, const char *path, const char *name, | |
105 | void *value, size_t size, int flags) | |
106 | { | |
faa44e3d VJ |
107 | char buffer[PATH_MAX]; |
108 | return lsetxattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT, value, | |
109 | size, flags); | |
70fc55eb AK |
110 | } |
111 | ||
112 | static int mp_dacl_removexattr(FsContext *ctx, | |
113 | const char *path, const char *name) | |
114 | { | |
a0994761 | 115 | int ret; |
faa44e3d VJ |
116 | char buffer[PATH_MAX]; |
117 | ret = lremovexattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT); | |
a0994761 AK |
118 | if (ret == -1 && errno == ENODATA) { |
119 | /* | |
120 | * We don't get ENODATA error when trying to remove a | |
121 | * posix acl that is not present. So don't throw the error | |
122 | * even in case of mapped security model | |
123 | */ | |
124 | errno = 0; | |
125 | ret = 0; | |
126 | } | |
127 | return ret; | |
70fc55eb AK |
128 | } |
129 | ||
130 | ||
131 | XattrOperations mapped_pacl_xattr = { | |
132 | .name = "system.posix_acl_access", | |
133 | .getxattr = mp_pacl_getxattr, | |
134 | .setxattr = mp_pacl_setxattr, | |
135 | .listxattr = mp_pacl_listxattr, | |
136 | .removexattr = mp_pacl_removexattr, | |
137 | }; | |
138 | ||
139 | XattrOperations mapped_dacl_xattr = { | |
140 | .name = "system.posix_acl_default", | |
141 | .getxattr = mp_dacl_getxattr, | |
142 | .setxattr = mp_dacl_setxattr, | |
143 | .listxattr = mp_dacl_listxattr, | |
144 | .removexattr = mp_dacl_removexattr, | |
145 | }; | |
146 | ||
147 | XattrOperations passthrough_acl_xattr = { | |
148 | .name = "system.posix_acl_", | |
149 | .getxattr = pt_getxattr, | |
150 | .setxattr = pt_setxattr, | |
151 | .listxattr = pt_listxattr, | |
152 | .removexattr = pt_removexattr, | |
153 | }; | |
154 | ||
155 | XattrOperations none_acl_xattr = { | |
156 | .name = "system.posix_acl_", | |
157 | .getxattr = notsup_getxattr, | |
158 | .setxattr = notsup_setxattr, | |
159 | .listxattr = notsup_listxattr, | |
160 | .removexattr = notsup_removexattr, | |
161 | }; |