]> Git Repo - qemu.git/blob - hw/9pfs/9p-posix-acl.c
9pfs: local: lgetxattr: don't follow symlinks
[qemu.git] / hw / 9pfs / 9p-posix-acl.c
1 /*
2  * 9p system.posix* xattr callback
3  *
4  * Copyright IBM, Corp. 2010
5  *
6  * Authors:
7  * Aneesh Kumar K.V <[email protected]>
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 "qemu/osdep.h"
15 #include "qemu/xattr.h"
16 #include "9p.h"
17 #include "fsdev/file-op-9p.h"
18 #include "9p-xattr.h"
19
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"
24
25 static ssize_t mp_pacl_getxattr(FsContext *ctx, const char *path,
26                                 const char *name, void *value, size_t size)
27 {
28     return local_getxattr_nofollow(ctx, path, MAP_ACL_ACCESS, value, size);
29 }
30
31 static ssize_t mp_pacl_listxattr(FsContext *ctx, const char *path,
32                                  char *name, void *value, size_t osize)
33 {
34     ssize_t len = sizeof(ACL_ACCESS);
35
36     if (!value) {
37         return len;
38     }
39
40     if (osize < len) {
41         errno = ERANGE;
42         return -1;
43     }
44
45     /* len includes the trailing NUL */
46     memcpy(value, ACL_ACCESS, len);
47     return 0;
48 }
49
50 static int mp_pacl_setxattr(FsContext *ctx, const char *path, const char *name,
51                             void *value, size_t size, int flags)
52 {
53     char *buffer;
54     int ret;
55
56     buffer = rpath(ctx, path);
57     ret = lsetxattr(buffer, MAP_ACL_ACCESS, value, size, flags);
58     g_free(buffer);
59     return ret;
60 }
61
62 static int mp_pacl_removexattr(FsContext *ctx,
63                                const char *path, const char *name)
64 {
65     int ret;
66     char *buffer;
67
68     buffer = rpath(ctx, path);
69     ret  = lremovexattr(buffer, MAP_ACL_ACCESS);
70     if (ret == -1 && errno == ENODATA) {
71         /*
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
75          */
76         errno = 0;
77         ret = 0;
78     }
79     g_free(buffer);
80     return ret;
81 }
82
83 static ssize_t mp_dacl_getxattr(FsContext *ctx, const char *path,
84                                 const char *name, void *value, size_t size)
85 {
86     return local_getxattr_nofollow(ctx, path, MAP_ACL_DEFAULT, value, size);
87 }
88
89 static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path,
90                                  char *name, void *value, size_t osize)
91 {
92     ssize_t len = sizeof(ACL_DEFAULT);
93
94     if (!value) {
95         return len;
96     }
97
98     if (osize < len) {
99         errno = ERANGE;
100         return -1;
101     }
102
103     /* len includes the trailing NUL */
104     memcpy(value, ACL_DEFAULT, len);
105     return 0;
106 }
107
108 static int mp_dacl_setxattr(FsContext *ctx, const char *path, const char *name,
109                             void *value, size_t size, int flags)
110 {
111     char *buffer;
112     int ret;
113
114     buffer = rpath(ctx, path);
115     ret = lsetxattr(buffer, MAP_ACL_DEFAULT, value, size, flags);
116     g_free(buffer);
117     return ret;
118 }
119
120 static int mp_dacl_removexattr(FsContext *ctx,
121                                const char *path, const char *name)
122 {
123     int ret;
124     char *buffer;
125
126     buffer = rpath(ctx, path);
127     ret  = lremovexattr(buffer, MAP_ACL_DEFAULT);
128     if (ret == -1 && errno == ENODATA) {
129         /*
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
133          */
134         errno = 0;
135         ret = 0;
136     }
137     g_free(buffer);
138     return ret;
139 }
140
141
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,
148 };
149
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,
156 };
157
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,
164 };
165
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,
172 };
This page took 0.032693 seconds and 4 git commands to generate.