Wed, 28 Dec 2016 17:27:14 +0100
fixes some memory errors and startup with broken config
51 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2013 Olaf Wintermann. All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #include <stdio.h> | |
30 | #include <stdlib.h> | |
73
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
31 | #include <unistd.h> |
51 | 32 | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
33 | #include "../util/util.h" |
51 | 34 | #include "../util/pool.h" |
35 | #include "../safs/auth.h" | |
73
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
36 | #include "log.h" |
51 | 37 | #include "acl.h" |
38 | ||
39 | void acllist_createhandle(Session *sn, Request *rq) { | |
40 | ACLListHandle *handle = pool_malloc(sn->pool, sizeof(ACLListHandle)); | |
41 | handle->defaultauthdb = NULL; | |
42 | handle->listhead = NULL; | |
43 | handle->listtail = NULL; | |
44 | rq->acllist = handle; | |
45 | } | |
46 | ||
52
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
47 | /* |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
48 | * append or prepend an ACL |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
49 | */ |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
50 | void acllist_add(Session *sn, Request *rq, ACLList *acl, int append) { |
51 | 51 | if(!rq->acllist) { |
52 | acllist_createhandle(sn, rq); | |
53 | } | |
54 | ACLListHandle *list = rq->acllist; | |
55 | ||
56 | if(!list->defaultauthdb && acl->authdb) { | |
57 | list->defaultauthdb = acl->authdb; | |
58 | } | |
59 | ||
60 | ACLListElm *elm = pool_malloc(sn->pool, sizeof(ACLListElm)); | |
61 | elm->acl = acl; | |
62 | elm->next = NULL; | |
63 | if(list->listhead == NULL) { | |
64 | list->listhead = elm; | |
65 | list->listtail = elm; | |
66 | } else { | |
52
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
67 | if(append) { |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
68 | list->listtail->next = elm; |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
69 | list->listtail = elm; |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
70 | } else { |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
71 | elm->next = list->listhead; |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
72 | list->listhead = elm; |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
73 | } |
51 | 74 | } |
75 | } | |
76 | ||
52
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
77 | void acllist_append(Session *sn, Request *rq, ACLList *acl) { |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
78 | acllist_add(sn, rq, acl, 1); |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
79 | } |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
80 | |
51 | 81 | void acllist_prepend(Session *sn, Request *rq, ACLList *acl) { |
52
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
82 | acllist_add(sn, rq, acl, 0); |
51 | 83 | } |
84 | ||
54 | 85 | uint32_t acl_oflag2mask(int oflags) { |
86 | /* TODO: | |
87 | * maybe there is a plattform where O_RDWR is not O_RDONLY | O_WRONLY | |
88 | */ | |
89 | uint32_t access_mask = 0; | |
90 | if((oflags & O_RDONLY) == O_RDONLY) { | |
91 | access_mask |= ACL_READ_DATA; | |
92 | } | |
93 | if((oflags & O_WRONLY) == O_WRONLY) { | |
94 | access_mask |= ACL_WRITE_DATA; | |
95 | } | |
96 | return access_mask; | |
97 | } | |
51 | 98 | |
54 | 99 | User* acllist_getuser(Session *sn, Request *rq, ACLListHandle *list) { |
100 | if(!sn || !rq || !list) { | |
101 | return NULL; | |
51 | 102 | } |
103 | ||
104 | // get user | |
105 | User *user = NULL; | |
106 | if(list->defaultauthdb) { | |
107 | char *usr; | |
108 | char *pw; | |
109 | if(!basicauth_getuser(sn, rq, &usr, &pw)) { | |
66
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
110 | int pwok; |
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
111 | user = authdb_get_and_verify(list->defaultauthdb, usr, pw, &pwok); |
51 | 112 | if(!user) { |
66
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
113 | // wrong user or wrong password |
54 | 114 | return NULL; |
51 | 115 | } |
116 | // ok - user is authenticated | |
117 | } | |
54 | 118 | } |
119 | ||
120 | return user; | |
121 | } | |
122 | ||
123 | void acl_set_error_status(Session *sn, Request *rq, ACLList *acl, User *user) { | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
124 | if(sn == NULL || rq == NULL) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
125 | return; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
126 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
127 | |
54 | 128 | if(!user) { |
129 | char *value = NULL; | |
130 | if(acl->authprompt) { | |
131 | size_t realmlen = strlen(acl->authprompt); | |
132 | size_t len = realmlen + 16; | |
133 | value = pool_malloc(sn->pool, len); | |
134 | if(value) { | |
135 | snprintf( | |
136 | value, | |
137 | len, | |
138 | "Basic realm=\"%s\"", | |
139 | acl->authprompt); | |
140 | } | |
141 | } | |
142 | if(!value) { | |
143 | value = "Basic realm=\"login\""; | |
144 | } | |
145 | pblock_nvinsert("www-authenticate", value, rq->srvhdrs); | |
146 | protocol_status(sn, rq, PROTOCOL_UNAUTHORIZED, NULL); | |
51 | 147 | } else { |
54 | 148 | protocol_status(sn, rq, PROTOCOL_FORBIDDEN, NULL); |
149 | } | |
150 | } | |
151 | ||
152 | int acl_evaluate(Session *sn, Request *rq, int access_mask) { | |
153 | ACLListHandle *list = rq->acllist; | |
154 | if(!list) { | |
155 | return REQ_PROCEED; | |
156 | } | |
157 | ||
158 | // we combine access_mask with the required access rights | |
159 | access_mask |= rq->aclreqaccess; | |
160 | ||
161 | // get user | |
162 | User *user = acllist_getuser(sn, rq, list); | |
163 | ||
164 | // evalutate all ACLs | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
165 | ACLList *acl = acl_evallist(list, user, access_mask, NULL); |
54 | 166 | if(acl) { |
167 | acl_set_error_status(sn, rq, acl, user); | |
168 | // TODO: don't free the user here | |
169 | if(user) { | |
170 | user->free(user); | |
171 | } | |
51 | 172 | return REQ_ABORTED; |
173 | } | |
174 | ||
54 | 175 | // access allowed, we can free the user |
176 | if(user) { | |
177 | user->free(user); | |
178 | } | |
179 | ||
180 | return REQ_PROCEED; | |
181 | } | |
182 | ||
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
183 | ACLList* acl_evallist( |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
184 | ACLListHandle *list, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
185 | User *user, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
186 | int access_mask, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
187 | ACLList **externacl) |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
188 | { |
54 | 189 | if(!list) { |
190 | return NULL; | |
191 | } | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
192 | if(externacl) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
193 | *externacl = NULL; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
194 | } |
54 | 195 | |
51 | 196 | // evaluate each acl until one denies access |
197 | ACLListElm *elm = list->listhead; | |
198 | while(elm) { | |
199 | ACLList *acl = elm->acl; | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
200 | if(acl->isextern) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
201 | // set externacl to the first external acl |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
202 | if(externacl && *externacl == NULL) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
203 | *externacl = acl; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
204 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
205 | } else if(!acl->check(acl, user, access_mask)) { |
51 | 206 | // the acl denies access |
54 | 207 | return acl; |
51 | 208 | } |
209 | elm = elm->next; | |
210 | } | |
211 | ||
212 | // ok - all acls allowed access | |
54 | 213 | |
214 | return NULL; | |
51 | 215 | } |
216 | ||
54 | 217 | int wsacl_affects_user(WSAce *ace, User *user) { |
52
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
218 | int check_access = 0; |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
219 | |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
220 | /* |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
221 | * an ace can affect |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
222 | * a named user or group (ace->who is set) |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
223 | * the owner of the resource (ACL_OWNER is set) |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
224 | * the owning group of the resource (ACL_GROUP is set) |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
225 | * everyone (ACL_EVERYONE is set) |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
226 | * |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
227 | * Only one of this conditions should be true. The behavior on |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
228 | * illegal flag combination is undefined. We assume that the acls |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
229 | * are created correctly by the configuration loader. |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
230 | */ |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
231 | |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
232 | if(ace->who && user) { |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
233 | // this ace is defined for a named user or group |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
234 | if((ace->flags & ACL_IDENTIFIER_GROUP) == ACL_IDENTIFIER_GROUP) { |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
235 | if(user->check_group(user, ace->who)) { |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
236 | // the user is in the group |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
237 | check_access = 1; |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
238 | } |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
239 | } else { |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
240 | if(!strcmp(user->name, ace->who)) { |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
241 | check_access = 1; |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
242 | } |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
243 | } |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
244 | } else if((ace->flags & ACL_OWNER) == ACL_OWNER) { |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
245 | // TODO |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
246 | } else if((ace->flags & ACL_GROUP) == ACL_GROUP) { |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
247 | // TODO |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
248 | } else if((ace->flags & ACL_EVERYONE) == ACL_EVERYONE) { |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
249 | check_access = 1; |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
250 | } |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
251 | |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
252 | return check_access; |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
253 | } |
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
254 | |
54 | 255 | int wsacl_check(WSAcl *acl, User *user, int access_mask) { |
51 | 256 | int allow = 0; |
257 | uint32_t allowed_access = 0; | |
258 | // check each access control entry | |
259 | for(int i=0;i<acl->acenum;i++) { | |
54 | 260 | WSAce *ace = acl->ace[i]; |
52
aced2245fb1c
new pathcheck saf and code cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
261 | if(wsacl_affects_user(ace, user)) { |
51 | 262 | if(ace->type == ACL_TYPE_ALLOWED) { |
263 | // add all new access rights | |
54 | 264 | allowed_access |= (access_mask & ace->access_mask); |
51 | 265 | // check if we have all requested rights |
266 | if((allowed_access & access_mask) == access_mask) { | |
267 | allow = 1; | |
268 | break; | |
269 | } | |
270 | } else { | |
271 | // ACL_TYPE_DENIED | |
272 | ||
273 | if((ace->access_mask & access_mask) != 0) { | |
274 | // access denied | |
275 | break; | |
276 | } | |
277 | } | |
278 | } | |
279 | } | |
280 | ||
281 | // TODO: events | |
282 | ||
54 | 283 | return allow; // allow is 0, if no ace set it to 1 |
51 | 284 | } |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
285 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
286 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
287 | /* filesystem acl functions */ |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
288 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
289 | #if defined (__SVR4) && defined (__sun) |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
290 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
291 | #include <sys/acl.h> |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
292 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
293 | int solaris_acl_check( |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
294 | char *path, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
295 | struct stat *s, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
296 | uint32_t mask, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
297 | uid_t uid, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
298 | gid_t gid); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
299 | int solaris_acl_affects_user( |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
300 | ace_t *ace, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
301 | uid_t uid, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
302 | gid_t gid, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
303 | uid_t owner, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
304 | gid_t owninggroup); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
305 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
306 | int fs_acl_check(SysACL *acl, User *user, char *path, uint32_t access_mask) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
307 | sstr_t p; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
308 | if(path[0] != '/') { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
309 | size_t n = 128; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
310 | char *cwd = malloc(n); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
311 | while(!getcwd(cwd, n)) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
312 | if(errno == ERANGE) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
313 | n *= 2; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
314 | cwd = realloc(cwd, n); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
315 | } else { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
316 | free(cwd); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
317 | return 0; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
318 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
319 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
320 | sstr_t wd = sstr(cwd); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
321 | sstr_t pp = sstr(path); |
100
e9bb8449df02
fixed solaris build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
93
diff
changeset
|
322 | |
e9bb8449df02
fixed solaris build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
93
diff
changeset
|
323 | p = sstrcat(3, wd, sstrn("/", 1), pp); |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
324 | } else { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
325 | p = sstrdup(sstr(path)); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
326 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
327 | if(p.ptr[p.length-1] == '/') { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
328 | p.ptr[p.length-1] = 0; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
329 | p.length--; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
330 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
331 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
332 | // get uid/gid |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
333 | struct passwd pw; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
334 | if(user) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
335 | char *pwbuf = malloc(DEF_PWBUF); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
336 | if(pwbuf == NULL) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
337 | free(p.ptr); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
338 | return 0; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
339 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
340 | if(!util_getpwnam(user->name, &pw, pwbuf, DEF_PWBUF)) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
341 | free(pwbuf); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
342 | free(p.ptr); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
343 | return 0; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
344 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
345 | free(pwbuf); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
346 | acl->user_uid = pw.pw_uid; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
347 | acl->user_gid = pw.pw_gid; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
348 | } else { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
349 | acl->user_uid = -1; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
350 | acl->user_gid = -1; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
351 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
352 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
353 | // translate access_mask |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
354 | uint32_t mask = 0; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
355 | if((access_mask & ACL_READ_DATA) == ACL_READ_DATA) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
356 | mask |= ACE_READ_DATA; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
357 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
358 | if((access_mask & ACL_WRITE_DATA) == ACL_WRITE_DATA) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
359 | mask |= ACE_WRITE_DATA; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
360 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
361 | if((access_mask & ACL_ADD_FILE) == ACL_ADD_FILE) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
362 | mask |= ACE_ADD_FILE; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
363 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
364 | if((access_mask & ACL_READ_XATTR) == ACL_READ_XATTR) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
365 | mask |= ACE_READ_NAMED_ATTRS; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
366 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
367 | if((access_mask & ACL_WRITE_XATTR) == ACL_WRITE_XATTR) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
368 | mask |= ACE_WRITE_NAMED_ATTRS; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
369 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
370 | if((access_mask & ACL_EXECUTE) == ACL_EXECUTE) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
371 | mask |= ACE_EXECUTE; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
372 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
373 | if((access_mask & ACL_DELETE) == ACL_DELETE) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
374 | mask |= ACE_DELETE_CHILD; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
375 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
376 | if((access_mask & ACL_READ_ATTRIBUTES) == ACL_READ_ATTRIBUTES) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
377 | mask |= ACE_READ_ATTRIBUTES; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
378 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
379 | if((access_mask & ACL_WRITE_ATTRIBUTES) == ACL_WRITE_ATTRIBUTES) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
380 | mask |= ACE_WRITE_ATTRIBUTES; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
381 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
382 | if((access_mask & ACL_LIST) == ACL_LIST) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
383 | mask |= ACE_LIST_DIRECTORY; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
384 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
385 | if((access_mask & ACL_READ_ACL) == ACL_READ_ACL) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
386 | mask |= ACE_READ_ACL; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
387 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
388 | if((access_mask & ACL_WRITE_ACL) == ACL_WRITE_ACL) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
389 | mask |= ACE_WRITE_ACL; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
390 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
391 | if((access_mask & ACL_WRITE_OWNER) == ACL_WRITE_OWNER) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
392 | mask |= ACE_WRITE_OWNER; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
393 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
394 | if((access_mask & ACL_SYNCHRONIZE) == ACL_SYNCHRONIZE) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
395 | mask |= ACE_SYNCHRONIZE; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
396 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
397 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
398 | /* |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
399 | * If the vfs wants to create new files, path does not name an existing |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
400 | * file. In this case, we check if the user has the ACE_ADD_FILE |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
401 | * permission for the parent directory |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
402 | */ |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
403 | struct stat s; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
404 | if(stat(p.ptr, &s)) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
405 | if(errno != ENOENT) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
406 | perror("fs_acl_check: stat"); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
407 | free(p.ptr); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
408 | return 0; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
409 | } else { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
410 | mask = ACE_ADD_FILE; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
411 | p = util_path_remove_last(p); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
412 | if(stat(p.ptr, &s)) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
413 | free(p.ptr); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
414 | return 0; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
415 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
416 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
417 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
418 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
419 | /* |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
420 | * perform a acl check for the path and each parent directory |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
421 | * we don't check the file system root |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
422 | * |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
423 | * after the first check, we check only search permission for the |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
424 | * directories |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
425 | */ |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
426 | if(!solaris_acl_check(p.ptr, &s, mask, pw.pw_uid, pw.pw_gid)) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
427 | free(p.ptr); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
428 | return 0; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
429 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
430 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
431 | p = util_path_remove_last(p); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
432 | mask = ACE_LIST_DIRECTORY; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
433 | while(p.length > 1) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
434 | if(stat(p.ptr, &s)) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
435 | free(p.ptr); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
436 | return 0; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
437 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
438 | if(!solaris_acl_check(p.ptr, &s, mask, pw.pw_uid, pw.pw_gid)) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
439 | free(p.ptr); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
440 | return 0; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
441 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
442 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
443 | // cut the last file name from the path |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
444 | p = util_path_remove_last(p); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
445 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
446 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
447 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
448 | return 1; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
449 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
450 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
451 | int solaris_acl_check( |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
452 | char *path, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
453 | struct stat *s, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
454 | uint32_t mask, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
455 | uid_t uid, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
456 | gid_t gid) |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
457 | { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
458 | //printf("solaris_acl_check %s\n", path); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
459 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
460 | int nace = acl(path, ACE_GETACLCNT, 0, NULL); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
461 | if(nace == -1) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
462 | perror("acl: ACE_GETACLCNT"); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
463 | // TODO: log error |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
464 | return 0; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
465 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
466 | ace_t *aces = calloc(nace, sizeof(ace_t)); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
467 | if(acl(path, ACE_GETACL, nace, aces) == 1) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
468 | perror("acl: ACE_GETACL"); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
469 | // TODO: log error |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
470 | free(aces); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
471 | return 0; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
472 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
473 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
474 | int allow = 0; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
475 | uint32_t allowed_access = 0; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
476 | for(int i=0;i<nace;i++) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
477 | ace_t ace = aces[i]; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
478 | if(solaris_acl_affects_user(&ace, uid, gid, s->st_uid, s->st_gid)) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
479 | if(ace.a_type == ACE_ACCESS_ALLOWED_ACE_TYPE) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
480 | // add all new access rights |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
481 | allowed_access |= (mask & ace.a_access_mask); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
482 | // check if we have all requested rights |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
483 | if((allowed_access & mask) == mask) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
484 | allow = 1; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
485 | break; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
486 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
487 | } else if(ace.a_type == ACE_ACCESS_DENIED_ACE_TYPE) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
488 | // ACL_TYPE_DENIED |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
489 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
490 | if((ace.a_access_mask & mask) != 0) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
491 | // access denied |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
492 | break; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
493 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
494 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
495 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
496 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
497 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
498 | free(aces); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
499 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
500 | //printf("return %d\n", allow); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
501 | return allow; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
502 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
503 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
504 | int solaris_acl_affects_user( |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
505 | ace_t *ace, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
506 | uid_t uid, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
507 | gid_t gid, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
508 | uid_t owner, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
509 | gid_t owninggroup) |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
510 | { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
511 | /* |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
512 | * mostly the same as wsacl_affects_user |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
513 | */ |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
514 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
515 | int check_access = 0; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
516 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
517 | if((ace->a_flags & ACE_OWNER) == ACE_OWNER) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
518 | if(uid == owner) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
519 | check_access = 1; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
520 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
521 | } else if((ace->a_flags & ACE_GROUP) == ACE_GROUP) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
522 | if(gid == owninggroup) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
523 | check_access = 1; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
524 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
525 | } else if((ace->a_flags & ACE_EVERYONE) == ACE_EVERYONE) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
526 | check_access = 1; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
527 | } else if(ace->a_who != -1 && uid != 0) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
528 | // this ace is defined for a named user or group |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
529 | if((ace->a_flags & ACE_IDENTIFIER_GROUP) == ACE_IDENTIFIER_GROUP) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
530 | // TODO: check all groups |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
531 | if(ace->a_who == gid) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
532 | // the user is in the group |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
533 | check_access = 1; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
534 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
535 | } else { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
536 | if(ace->a_who == uid) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
537 | check_access = 1; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
538 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
539 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
540 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
541 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
542 | return check_access; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
543 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
544 | |
73
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
545 | void fs_acl_finish() { |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
546 | |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
547 | } |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
548 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
549 | #endif |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
550 | |
69
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
551 | /* |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
552 | * generic code for all non acl unices |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
553 | * TODO: don't use OSX in the preprocessor directive |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
554 | */ |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
555 | #ifdef OSX |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
556 | |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
557 | int fs_acl_check(SysACL *acl, User *user, char *path, uint32_t access_mask) { |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
558 | return 1; |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
559 | } |
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
560 | |
73
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
561 | void fs_acl_finish() { |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
562 | |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
563 | } |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
564 | |
69
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
565 | #endif |
73
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
566 | |
109
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
567 | #ifdef BSD |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
568 | |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
569 | int fs_acl_check(SysACL *acl, User *user, char *path, uint32_t access_mask) { |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
570 | return 1; |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
571 | } |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
572 | |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
573 | void fs_acl_finish() { |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
574 | |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
575 | } |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
576 | |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
577 | #endif |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
578 | |
73
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
579 | |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
580 | #ifdef LINUX |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
581 | |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
582 | #include <sys/fsuid.h> |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
583 | |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
584 | int fs_acl_check(SysACL *acl, User *user, char *path, uint32_t access_mask) { |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
585 | struct passwd *ws_pw = conf_getglobals()->Vuserpw; |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
586 | if(!ws_pw) { |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
587 | log_ereport(LOG_FAILURE, "fs_acl_check: unknown webserver uid/gid"); |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
588 | return 1; |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
589 | } |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
590 | |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
591 | // get uid/gid |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
592 | struct passwd pw; |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
593 | if(user) { |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
594 | char *pwbuf = malloc(DEF_PWBUF); |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
595 | if(pwbuf == NULL) { |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
596 | return 0; |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
597 | } |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
598 | if(!util_getpwnam(user->name, &pw, pwbuf, DEF_PWBUF)) { |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
599 | free(pwbuf); |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
600 | return 0; |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
601 | } |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
602 | free(pwbuf); |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
603 | acl->user_uid = pw.pw_uid; |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
604 | acl->user_gid = pw.pw_gid; |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
605 | } else { |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
606 | acl->user_uid = 0; |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
607 | acl->user_gid = 0; |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
608 | } |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
609 | |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
610 | // set fs uid/gid |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
611 | if(acl->user_uid != 0) { |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
612 | if(setfsuid(pw.pw_uid)) { |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
613 | log_ereport( |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
614 | LOG_FAILURE, |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
615 | "Cannot set fsuid to uid: %u", pw.pw_uid); |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
616 | } |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
617 | if(setfsgid(pw.pw_gid)) { |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
618 | log_ereport( |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
619 | LOG_FAILURE, |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
620 | "Cannot set fsgid to gid: %u", pw.pw_gid); |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
621 | } |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
622 | } |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
623 | |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
624 | |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
625 | return 1; |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
626 | } |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
627 | |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
628 | void fs_acl_finish() { |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
629 | struct passwd *pw = conf_getglobals()->Vuserpw; |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
630 | if(!pw) { |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
631 | log_ereport( |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
632 | LOG_FAILURE, |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
633 | "global configuration broken (Vuserpw is null)"); |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
634 | return; |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
635 | } |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
636 | if(setfsuid(pw->pw_uid)) { |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
637 | log_ereport( |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
638 | LOG_FAILURE, |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
639 | "Cannot set fsuid back to server uid: %u", pw->pw_uid); |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
640 | } |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
641 | if(setfsgid(pw->pw_gid)) { |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
642 | log_ereport( |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
643 | LOG_FAILURE, |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
644 | "Cannot set fsgid back to server gid: %u", pw->pw_gid); |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
645 | } |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
646 | } |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
647 | |
79fa26ecd135
added file system ACLs for linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
648 | #endif |