Print this page
NEX-6096 Enable compile warnings re. parentheses in smbsrv
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Jean McCormack <jean.mccormack@nexenta.com>
OS-139 POSIX write should imply DELETE_CHILD on directories - and some additional considerations
SMB-50 User-mode SMB server
Includes work by these authors:
Thomas Keiser <thomas.keiser@nexenta.com>
Albert Lee <trisk@nexenta.com>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/common/acl/acl_common.c
+++ new/usr/src/common/acl/acl_common.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
24 24 */
25 25
26 26 #include <sys/types.h>
27 27 #include <sys/stat.h>
28 28 #include <sys/errno.h>
29 29 #include <sys/avl.h>
30 30 #if defined(_KERNEL) || defined(_FAKE_KERNEL)
31 31 #include <sys/debug.h>
32 32 #include <sys/kmem.h>
33 33 #include <sys/systm.h>
34 34 #include <sys/sysmacros.h>
35 35 #include <acl/acl_common.h>
36 36 #else
37 37 #include <errno.h>
38 38 #include <stdlib.h>
39 39 #include <stddef.h>
40 40 #include <strings.h>
41 41 #include <unistd.h>
42 42 #include <assert.h>
43 43 #include <grp.h>
44 44 #include <pwd.h>
45 45 #include <acl_common.h>
46 46 #define ASSERT assert
47 47 #endif
48 48
49 49 #define ACE_POSIX_SUPPORTED_BITS (ACE_READ_DATA | \
50 50 ACE_WRITE_DATA | ACE_APPEND_DATA | ACE_EXECUTE | \
51 51 ACE_READ_ATTRIBUTES | ACE_READ_ACL | ACE_WRITE_ACL)
52 52
53 53
54 54 #define ACL_SYNCHRONIZE_SET_DENY 0x0000001
55 55 #define ACL_SYNCHRONIZE_SET_ALLOW 0x0000002
56 56 #define ACL_SYNCHRONIZE_ERR_DENY 0x0000004
57 57 #define ACL_SYNCHRONIZE_ERR_ALLOW 0x0000008
58 58
59 59 #define ACL_WRITE_OWNER_SET_DENY 0x0000010
60 60 #define ACL_WRITE_OWNER_SET_ALLOW 0x0000020
61 61 #define ACL_WRITE_OWNER_ERR_DENY 0x0000040
62 62 #define ACL_WRITE_OWNER_ERR_ALLOW 0x0000080
63 63
64 64 #define ACL_DELETE_SET_DENY 0x0000100
65 65 #define ACL_DELETE_SET_ALLOW 0x0000200
66 66 #define ACL_DELETE_ERR_DENY 0x0000400
67 67 #define ACL_DELETE_ERR_ALLOW 0x0000800
68 68
69 69 #define ACL_WRITE_ATTRS_OWNER_SET_DENY 0x0001000
70 70 #define ACL_WRITE_ATTRS_OWNER_SET_ALLOW 0x0002000
71 71 #define ACL_WRITE_ATTRS_OWNER_ERR_DENY 0x0004000
72 72 #define ACL_WRITE_ATTRS_OWNER_ERR_ALLOW 0x0008000
73 73
74 74 #define ACL_WRITE_ATTRS_WRITER_SET_DENY 0x0010000
75 75 #define ACL_WRITE_ATTRS_WRITER_SET_ALLOW 0x0020000
76 76 #define ACL_WRITE_ATTRS_WRITER_ERR_DENY 0x0040000
77 77 #define ACL_WRITE_ATTRS_WRITER_ERR_ALLOW 0x0080000
78 78
79 79 #define ACL_WRITE_NAMED_WRITER_SET_DENY 0x0100000
80 80 #define ACL_WRITE_NAMED_WRITER_SET_ALLOW 0x0200000
81 81 #define ACL_WRITE_NAMED_WRITER_ERR_DENY 0x0400000
82 82 #define ACL_WRITE_NAMED_WRITER_ERR_ALLOW 0x0800000
83 83
84 84 #define ACL_READ_NAMED_READER_SET_DENY 0x1000000
85 85 #define ACL_READ_NAMED_READER_SET_ALLOW 0x2000000
86 86 #define ACL_READ_NAMED_READER_ERR_DENY 0x4000000
87 87 #define ACL_READ_NAMED_READER_ERR_ALLOW 0x8000000
88 88
89 89
90 90 #define ACE_VALID_MASK_BITS (\
91 91 ACE_READ_DATA | \
92 92 ACE_LIST_DIRECTORY | \
93 93 ACE_WRITE_DATA | \
94 94 ACE_ADD_FILE | \
95 95 ACE_APPEND_DATA | \
96 96 ACE_ADD_SUBDIRECTORY | \
97 97 ACE_READ_NAMED_ATTRS | \
98 98 ACE_WRITE_NAMED_ATTRS | \
99 99 ACE_EXECUTE | \
100 100 ACE_DELETE_CHILD | \
101 101 ACE_READ_ATTRIBUTES | \
102 102 ACE_WRITE_ATTRIBUTES | \
103 103 ACE_DELETE | \
104 104 ACE_READ_ACL | \
105 105 ACE_WRITE_ACL | \
106 106 ACE_WRITE_OWNER | \
107 107 ACE_SYNCHRONIZE)
108 108
109 109 #define ACE_MASK_UNDEFINED 0x80000000
110 110
111 111 #define ACE_VALID_FLAG_BITS (ACE_FILE_INHERIT_ACE | \
112 112 ACE_DIRECTORY_INHERIT_ACE | \
113 113 ACE_NO_PROPAGATE_INHERIT_ACE | ACE_INHERIT_ONLY_ACE | \
114 114 ACE_SUCCESSFUL_ACCESS_ACE_FLAG | ACE_FAILED_ACCESS_ACE_FLAG | \
115 115 ACE_IDENTIFIER_GROUP | ACE_OWNER | ACE_GROUP | ACE_EVERYONE)
116 116
117 117 /*
118 118 * ACL conversion helpers
119 119 */
120 120
121 121 typedef enum {
122 122 ace_unused,
123 123 ace_user_obj,
124 124 ace_user,
125 125 ace_group, /* includes GROUP and GROUP_OBJ */
126 126 ace_other_obj
127 127 } ace_to_aent_state_t;
128 128
129 129 typedef struct acevals {
130 130 uid_t key;
131 131 avl_node_t avl;
132 132 uint32_t mask;
133 133 uint32_t allowed;
134 134 uint32_t denied;
135 135 int aent_type;
136 136 } acevals_t;
137 137
138 138 typedef struct ace_list {
139 139 acevals_t user_obj;
140 140 avl_tree_t user;
141 141 int numusers;
142 142 acevals_t group_obj;
143 143 avl_tree_t group;
144 144 int numgroups;
145 145 acevals_t other_obj;
146 146 uint32_t acl_mask;
147 147 int hasmask;
148 148 int dfacl_flag;
149 149 ace_to_aent_state_t state;
150 150 int seen; /* bitmask of all aclent_t a_type values seen */
151 151 } ace_list_t;
152 152
153 153 /*
154 154 * Generic shellsort, from K&R (1st ed, p 58.), somewhat modified.
155 155 * v = Ptr to array/vector of objs
156 156 * n = # objs in the array
157 157 * s = size of each obj (must be multiples of a word size)
158 158 * f = ptr to function to compare two objs
159 159 * returns (-1 = less than, 0 = equal, 1 = greater than
160 160 */
161 161 void
162 162 ksort(caddr_t v, int n, int s, int (*f)())
163 163 {
164 164 int g, i, j, ii;
165 165 unsigned int *p1, *p2;
166 166 unsigned int tmp;
167 167
168 168 /* No work to do */
169 169 if (v == NULL || n <= 1)
170 170 return;
171 171
172 172 /* Sanity check on arguments */
173 173 ASSERT(((uintptr_t)v & 0x3) == 0 && (s & 0x3) == 0);
174 174 ASSERT(s > 0);
175 175 for (g = n / 2; g > 0; g /= 2) {
176 176 for (i = g; i < n; i++) {
177 177 for (j = i - g; j >= 0 &&
178 178 (*f)(v + j * s, v + (j + g) * s) == 1;
179 179 j -= g) {
180 180 p1 = (void *)(v + j * s);
181 181 p2 = (void *)(v + (j + g) * s);
182 182 for (ii = 0; ii < s / 4; ii++) {
183 183 tmp = *p1;
184 184 *p1++ = *p2;
185 185 *p2++ = tmp;
186 186 }
187 187 }
188 188 }
189 189 }
190 190 }
191 191
192 192 /*
193 193 * Compare two acls, all fields. Returns:
194 194 * -1 (less than)
195 195 * 0 (equal)
196 196 * +1 (greater than)
197 197 */
198 198 int
199 199 cmp2acls(void *a, void *b)
200 200 {
201 201 aclent_t *x = (aclent_t *)a;
202 202 aclent_t *y = (aclent_t *)b;
203 203
204 204 /* Compare types */
205 205 if (x->a_type < y->a_type)
206 206 return (-1);
207 207 if (x->a_type > y->a_type)
208 208 return (1);
209 209 /* Equal types; compare id's */
210 210 if (x->a_id < y->a_id)
211 211 return (-1);
212 212 if (x->a_id > y->a_id)
213 213 return (1);
214 214 /* Equal ids; compare perms */
215 215 if (x->a_perm < y->a_perm)
216 216 return (-1);
217 217 if (x->a_perm > y->a_perm)
218 218 return (1);
219 219 /* Totally equal */
220 220 return (0);
221 221 }
222 222
223 223 /*ARGSUSED*/
224 224 static void *
225 225 cacl_realloc(void *ptr, size_t size, size_t new_size)
226 226 {
227 227 #if defined(_KERNEL) || defined(_FAKE_KERNEL)
228 228 void *tmp;
229 229
230 230 tmp = kmem_alloc(new_size, KM_SLEEP);
231 231 (void) memcpy(tmp, ptr, (size < new_size) ? size : new_size);
232 232 kmem_free(ptr, size);
233 233 return (tmp);
234 234 #else
235 235 return (realloc(ptr, new_size));
236 236 #endif
237 237 }
238 238
239 239 static int
240 240 cacl_malloc(void **ptr, size_t size)
241 241 {
242 242 #if defined(_KERNEL) || defined(_FAKE_KERNEL)
243 243 *ptr = kmem_zalloc(size, KM_SLEEP);
244 244 return (0);
245 245 #else
246 246 *ptr = calloc(1, size);
247 247 if (*ptr == NULL)
248 248 return (errno);
249 249
250 250 return (0);
251 251 #endif
252 252 }
253 253
254 254 /*ARGSUSED*/
255 255 static void
256 256 cacl_free(void *ptr, size_t size)
257 257 {
258 258 #if defined(_KERNEL) || defined(_FAKE_KERNEL)
259 259 kmem_free(ptr, size);
260 260 #else
261 261 free(ptr);
262 262 #endif
263 263 }
264 264
265 265 acl_t *
266 266 acl_alloc(enum acl_type type)
267 267 {
268 268 acl_t *aclp;
269 269
270 270 if (cacl_malloc((void **)&aclp, sizeof (acl_t)) != 0)
271 271 return (NULL);
272 272
273 273 aclp->acl_aclp = NULL;
274 274 aclp->acl_cnt = 0;
275 275
276 276 switch (type) {
277 277 case ACE_T:
278 278 aclp->acl_type = ACE_T;
279 279 aclp->acl_entry_size = sizeof (ace_t);
280 280 break;
281 281 case ACLENT_T:
282 282 aclp->acl_type = ACLENT_T;
283 283 aclp->acl_entry_size = sizeof (aclent_t);
284 284 break;
285 285 default:
286 286 acl_free(aclp);
287 287 aclp = NULL;
288 288 }
289 289 return (aclp);
290 290 }
291 291
292 292 /*
293 293 * Free acl_t structure
294 294 */
295 295 void
296 296 acl_free(acl_t *aclp)
297 297 {
298 298 int acl_size;
299 299
300 300 if (aclp == NULL)
301 301 return;
302 302
303 303 if (aclp->acl_aclp) {
304 304 acl_size = aclp->acl_cnt * aclp->acl_entry_size;
305 305 cacl_free(aclp->acl_aclp, acl_size);
306 306 }
307 307
308 308 cacl_free(aclp, sizeof (acl_t));
309 309 }
310 310
311 311 static uint32_t
312 312 access_mask_set(int haswriteperm, int hasreadperm, int isowner, int isallow)
313 313 {
314 314 uint32_t access_mask = 0;
315 315 int acl_produce;
316 316 int synchronize_set = 0, write_owner_set = 0;
317 317 int delete_set = 0, write_attrs_set = 0;
318 318 int read_named_set = 0, write_named_set = 0;
319 319
320 320 acl_produce = (ACL_SYNCHRONIZE_SET_ALLOW |
321 321 ACL_WRITE_ATTRS_OWNER_SET_ALLOW |
322 322 ACL_WRITE_ATTRS_WRITER_SET_DENY);
323 323
324 324 if (isallow) {
325 325 synchronize_set = ACL_SYNCHRONIZE_SET_ALLOW;
326 326 write_owner_set = ACL_WRITE_OWNER_SET_ALLOW;
327 327 delete_set = ACL_DELETE_SET_ALLOW;
328 328 if (hasreadperm)
329 329 read_named_set = ACL_READ_NAMED_READER_SET_ALLOW;
330 330 if (haswriteperm)
331 331 write_named_set = ACL_WRITE_NAMED_WRITER_SET_ALLOW;
332 332 if (isowner)
333 333 write_attrs_set = ACL_WRITE_ATTRS_OWNER_SET_ALLOW;
334 334 else if (haswriteperm)
335 335 write_attrs_set = ACL_WRITE_ATTRS_WRITER_SET_ALLOW;
336 336 } else {
337 337
338 338 synchronize_set = ACL_SYNCHRONIZE_SET_DENY;
339 339 write_owner_set = ACL_WRITE_OWNER_SET_DENY;
340 340 delete_set = ACL_DELETE_SET_DENY;
341 341 if (hasreadperm)
342 342 read_named_set = ACL_READ_NAMED_READER_SET_DENY;
343 343 if (haswriteperm)
344 344 write_named_set = ACL_WRITE_NAMED_WRITER_SET_DENY;
345 345 if (isowner)
346 346 write_attrs_set = ACL_WRITE_ATTRS_OWNER_SET_DENY;
347 347 else if (haswriteperm)
348 348 write_attrs_set = ACL_WRITE_ATTRS_WRITER_SET_DENY;
349 349 else
350 350 /*
351 351 * If the entity is not the owner and does not
352 352 * have write permissions ACE_WRITE_ATTRIBUTES will
353 353 * always go in the DENY ACE.
354 354 */
355 355 access_mask |= ACE_WRITE_ATTRIBUTES;
356 356 }
357 357
358 358 if (acl_produce & synchronize_set)
359 359 access_mask |= ACE_SYNCHRONIZE;
360 360 if (acl_produce & write_owner_set)
361 361 access_mask |= ACE_WRITE_OWNER;
362 362 if (acl_produce & delete_set)
363 363 access_mask |= ACE_DELETE;
364 364 if (acl_produce & write_attrs_set)
365 365 access_mask |= ACE_WRITE_ATTRIBUTES;
366 366 if (acl_produce & read_named_set)
367 367 access_mask |= ACE_READ_NAMED_ATTRS;
368 368 if (acl_produce & write_named_set)
369 369 access_mask |= ACE_WRITE_NAMED_ATTRS;
370 370
371 371 return (access_mask);
372 372 }
373 373
374 374 /*
375 375 * Given an mode_t, convert it into an access_mask as used
376 376 * by nfsace, assuming aclent_t -> nfsace semantics.
377 377 */
378 378 static uint32_t
379 379 mode_to_ace_access(mode_t mode, boolean_t isdir, int isowner, int isallow)
380 380 {
381 381 uint32_t access = 0;
382 382 int haswriteperm = 0;
383 383 int hasreadperm = 0;
384 384
385 385 if (isallow) {
386 386 haswriteperm = (mode & S_IWOTH);
387 387 hasreadperm = (mode & S_IROTH);
388 388 } else {
389 389 haswriteperm = !(mode & S_IWOTH);
390 390 hasreadperm = !(mode & S_IROTH);
391 391 }
392 392
393 393 /*
394 394 * The following call takes care of correctly setting the following
395 395 * mask bits in the access_mask:
396 396 * ACE_SYNCHRONIZE, ACE_WRITE_OWNER, ACE_DELETE,
397 397 * ACE_WRITE_ATTRIBUTES, ACE_WRITE_NAMED_ATTRS, ACE_READ_NAMED_ATTRS
398 398 */
399 399 access = access_mask_set(haswriteperm, hasreadperm, isowner, isallow);
400 400
401 401 if (isallow) {
402 402 access |= ACE_READ_ACL | ACE_READ_ATTRIBUTES;
403 403 if (isowner)
404 404 access |= ACE_WRITE_ACL;
405 405 } else {
406 406 if (! isowner)
407 407 access |= ACE_WRITE_ACL;
408 408 }
409 409
410 410 /* read */
411 411 if (mode & S_IROTH) {
412 412 access |= ACE_READ_DATA;
413 413 }
414 414 /* write */
415 415 if (mode & S_IWOTH) {
416 416 access |= ACE_WRITE_DATA |
417 417 ACE_APPEND_DATA;
418 418 if (isdir)
419 419 access |= ACE_DELETE_CHILD;
420 420 }
421 421 /* exec */
422 422 if (mode & S_IXOTH) {
423 423 access |= ACE_EXECUTE;
424 424 }
425 425
426 426 return (access);
427 427 }
428 428
429 429 /*
430 430 * Given an nfsace (presumably an ALLOW entry), make a
431 431 * corresponding DENY entry at the address given.
432 432 */
433 433 static void
434 434 ace_make_deny(ace_t *allow, ace_t *deny, int isdir, int isowner)
435 435 {
436 436 (void) memcpy(deny, allow, sizeof (ace_t));
437 437
438 438 deny->a_who = allow->a_who;
439 439
440 440 deny->a_type = ACE_ACCESS_DENIED_ACE_TYPE;
441 441 deny->a_access_mask ^= ACE_POSIX_SUPPORTED_BITS;
442 442 if (isdir)
443 443 deny->a_access_mask ^= ACE_DELETE_CHILD;
444 444
445 445 deny->a_access_mask &= ~(ACE_SYNCHRONIZE | ACE_WRITE_OWNER |
446 446 ACE_DELETE | ACE_WRITE_ATTRIBUTES | ACE_READ_NAMED_ATTRS |
447 447 ACE_WRITE_NAMED_ATTRS);
448 448 deny->a_access_mask |= access_mask_set((allow->a_access_mask &
449 449 ACE_WRITE_DATA), (allow->a_access_mask & ACE_READ_DATA), isowner,
450 450 B_FALSE);
451 451 }
452 452 /*
453 453 * Make an initial pass over an array of aclent_t's. Gather
454 454 * information such as an ACL_MASK (if any), number of users,
455 455 * number of groups, and whether the array needs to be sorted.
456 456 */
457 457 static int
458 458 ln_aent_preprocess(aclent_t *aclent, int n,
459 459 int *hasmask, mode_t *mask,
460 460 int *numuser, int *numgroup, int *needsort)
461 461 {
462 462 int error = 0;
463 463 int i;
464 464 int curtype = 0;
465 465
466 466 *hasmask = 0;
467 467 *mask = 07;
468 468 *needsort = 0;
469 469 *numuser = 0;
470 470 *numgroup = 0;
471 471
472 472 for (i = 0; i < n; i++) {
473 473 if (aclent[i].a_type < curtype)
474 474 *needsort = 1;
475 475 else if (aclent[i].a_type > curtype)
476 476 curtype = aclent[i].a_type;
477 477 if (aclent[i].a_type & USER)
478 478 (*numuser)++;
479 479 if (aclent[i].a_type & (GROUP | GROUP_OBJ))
480 480 (*numgroup)++;
481 481 if (aclent[i].a_type & CLASS_OBJ) {
482 482 if (*hasmask) {
483 483 error = EINVAL;
484 484 goto out;
485 485 } else {
486 486 *hasmask = 1;
487 487 *mask = aclent[i].a_perm;
488 488 }
489 489 }
490 490 }
491 491
492 492 if ((! *hasmask) && (*numuser + *numgroup > 1)) {
493 493 error = EINVAL;
494 494 goto out;
495 495 }
496 496
497 497 out:
498 498 return (error);
499 499 }
500 500
501 501 /*
502 502 * Convert an array of aclent_t into an array of nfsace entries,
503 503 * following POSIX draft -> nfsv4 conversion semantics as outlined in
504 504 * the IETF draft.
505 505 */
506 506 static int
507 507 ln_aent_to_ace(aclent_t *aclent, int n, ace_t **acepp, int *rescount, int isdir)
508 508 {
509 509 int error = 0;
510 510 mode_t mask;
511 511 int numuser, numgroup, needsort;
512 512 int resultsize = 0;
513 513 int i, groupi = 0, skip;
514 514 ace_t *acep, *result = NULL;
515 515 int hasmask;
516 516
517 517 error = ln_aent_preprocess(aclent, n, &hasmask, &mask,
518 518 &numuser, &numgroup, &needsort);
519 519 if (error != 0)
520 520 goto out;
521 521
522 522 /* allow + deny for each aclent */
523 523 resultsize = n * 2;
524 524 if (hasmask) {
525 525 /*
526 526 * stick extra deny on the group_obj and on each
527 527 * user|group for the mask (the group_obj was added
528 528 * into the count for numgroup)
529 529 */
530 530 resultsize += numuser + numgroup;
531 531 /* ... and don't count the mask itself */
532 532 resultsize -= 2;
533 533 }
534 534
535 535 /* sort the source if necessary */
536 536 if (needsort)
537 537 ksort((caddr_t)aclent, n, sizeof (aclent_t), cmp2acls);
538 538
539 539 if (cacl_malloc((void **)&result, resultsize * sizeof (ace_t)) != 0)
540 540 goto out;
541 541
542 542 acep = result;
543 543
544 544 for (i = 0; i < n; i++) {
545 545 /*
546 546 * don't process CLASS_OBJ (mask); mask was grabbed in
547 547 * ln_aent_preprocess()
548 548 */
549 549 if (aclent[i].a_type & CLASS_OBJ)
550 550 continue;
551 551
552 552 /* If we need an ACL_MASK emulator, prepend it now */
553 553 if ((hasmask) &&
554 554 (aclent[i].a_type & (USER | GROUP | GROUP_OBJ))) {
555 555 acep->a_type = ACE_ACCESS_DENIED_ACE_TYPE;
556 556 acep->a_flags = 0;
557 557 if (aclent[i].a_type & GROUP_OBJ) {
558 558 acep->a_who = (uid_t)-1;
559 559 acep->a_flags |=
560 560 (ACE_IDENTIFIER_GROUP|ACE_GROUP);
561 561 } else if (aclent[i].a_type & USER) {
562 562 acep->a_who = aclent[i].a_id;
563 563 } else {
564 564 acep->a_who = aclent[i].a_id;
565 565 acep->a_flags |= ACE_IDENTIFIER_GROUP;
566 566 }
567 567 if (aclent[i].a_type & ACL_DEFAULT) {
568 568 acep->a_flags |= ACE_INHERIT_ONLY_ACE |
569 569 ACE_FILE_INHERIT_ACE |
570 570 ACE_DIRECTORY_INHERIT_ACE;
571 571 }
572 572 /*
573 573 * Set the access mask for the prepended deny
574 574 * ace. To do this, we invert the mask (found
575 575 * in ln_aent_preprocess()) then convert it to an
576 576 * DENY ace access_mask.
577 577 */
578 578 acep->a_access_mask = mode_to_ace_access((mask ^ 07),
579 579 isdir, 0, 0);
580 580 acep += 1;
581 581 }
582 582
583 583 /* handle a_perm -> access_mask */
584 584 acep->a_access_mask = mode_to_ace_access(aclent[i].a_perm,
585 585 isdir, aclent[i].a_type & USER_OBJ, 1);
586 586
587 587 /* emulate a default aclent */
588 588 if (aclent[i].a_type & ACL_DEFAULT) {
589 589 acep->a_flags |= ACE_INHERIT_ONLY_ACE |
590 590 ACE_FILE_INHERIT_ACE |
591 591 ACE_DIRECTORY_INHERIT_ACE;
592 592 }
593 593
594 594 /*
595 595 * handle a_perm and a_id
596 596 *
597 597 * this must be done last, since it involves the
598 598 * corresponding deny aces, which are handled
599 599 * differently for each different a_type.
600 600 */
601 601 if (aclent[i].a_type & USER_OBJ) {
602 602 acep->a_who = (uid_t)-1;
603 603 acep->a_flags |= ACE_OWNER;
604 604 ace_make_deny(acep, acep + 1, isdir, B_TRUE);
605 605 acep += 2;
606 606 } else if (aclent[i].a_type & USER) {
607 607 acep->a_who = aclent[i].a_id;
608 608 ace_make_deny(acep, acep + 1, isdir, B_FALSE);
609 609 acep += 2;
610 610 } else if (aclent[i].a_type & (GROUP_OBJ | GROUP)) {
611 611 if (aclent[i].a_type & GROUP_OBJ) {
612 612 acep->a_who = (uid_t)-1;
613 613 acep->a_flags |= ACE_GROUP;
614 614 } else {
615 615 acep->a_who = aclent[i].a_id;
616 616 }
617 617 acep->a_flags |= ACE_IDENTIFIER_GROUP;
618 618 /*
619 619 * Set the corresponding deny for the group ace.
620 620 *
621 621 * The deny aces go after all of the groups, unlike
622 622 * everything else, where they immediately follow
623 623 * the allow ace.
624 624 *
625 625 * We calculate "skip", the number of slots to
626 626 * skip ahead for the deny ace, here.
627 627 *
628 628 * The pattern is:
629 629 * MD1 A1 MD2 A2 MD3 A3 D1 D2 D3
630 630 * thus, skip is
631 631 * (2 * numgroup) - 1 - groupi
632 632 * (2 * numgroup) to account for MD + A
633 633 * - 1 to account for the fact that we're on the
634 634 * access (A), not the mask (MD)
635 635 * - groupi to account for the fact that we have
636 636 * passed up groupi number of MD's.
637 637 */
638 638 skip = (2 * numgroup) - 1 - groupi;
639 639 ace_make_deny(acep, acep + skip, isdir, B_FALSE);
640 640 /*
641 641 * If we just did the last group, skip acep past
642 642 * all of the denies; else, just move ahead one.
643 643 */
644 644 if (++groupi >= numgroup)
645 645 acep += numgroup + 1;
646 646 else
647 647 acep += 1;
648 648 } else if (aclent[i].a_type & OTHER_OBJ) {
649 649 acep->a_who = (uid_t)-1;
650 650 acep->a_flags |= ACE_EVERYONE;
651 651 ace_make_deny(acep, acep + 1, isdir, B_FALSE);
652 652 acep += 2;
653 653 } else {
654 654 error = EINVAL;
655 655 goto out;
656 656 }
657 657 }
658 658
659 659 *acepp = result;
660 660 *rescount = resultsize;
661 661
662 662 out:
663 663 if (error != 0) {
664 664 if ((result != NULL) && (resultsize > 0)) {
665 665 cacl_free(result, resultsize * sizeof (ace_t));
666 666 }
667 667 }
668 668
669 669 return (error);
670 670 }
671 671
672 672 static int
673 673 convert_aent_to_ace(aclent_t *aclentp, int aclcnt, boolean_t isdir,
674 674 ace_t **retacep, int *retacecnt)
675 675 {
676 676 ace_t *acep;
677 677 ace_t *dfacep;
678 678 int acecnt = 0;
679 679 int dfacecnt = 0;
680 680 int dfaclstart = 0;
681 681 int dfaclcnt = 0;
682 682 aclent_t *aclp;
683 683 int i;
684 684 int error;
685 685 int acesz, dfacesz;
686 686
687 687 ksort((caddr_t)aclentp, aclcnt, sizeof (aclent_t), cmp2acls);
688 688
689 689 for (i = 0, aclp = aclentp; i < aclcnt; aclp++, i++) {
690 690 if (aclp->a_type & ACL_DEFAULT)
691 691 break;
692 692 }
693 693
694 694 if (i < aclcnt) {
695 695 dfaclstart = i;
696 696 dfaclcnt = aclcnt - i;
697 697 }
698 698
699 699 if (dfaclcnt && !isdir) {
700 700 return (EINVAL);
701 701 }
702 702
703 703 error = ln_aent_to_ace(aclentp, i, &acep, &acecnt, isdir);
704 704 if (error)
705 705 return (error);
706 706
707 707 if (dfaclcnt) {
708 708 error = ln_aent_to_ace(&aclentp[dfaclstart], dfaclcnt,
709 709 &dfacep, &dfacecnt, isdir);
710 710 if (error) {
711 711 if (acep) {
712 712 cacl_free(acep, acecnt * sizeof (ace_t));
713 713 }
714 714 return (error);
715 715 }
716 716 }
717 717
718 718 if (dfacecnt != 0) {
719 719 acesz = sizeof (ace_t) * acecnt;
720 720 dfacesz = sizeof (ace_t) * dfacecnt;
721 721 acep = cacl_realloc(acep, acesz, acesz + dfacesz);
722 722 if (acep == NULL)
723 723 return (ENOMEM);
724 724 if (dfaclcnt) {
725 725 (void) memcpy(acep + acecnt, dfacep, dfacesz);
726 726 }
727 727 }
728 728 if (dfaclcnt)
729 729 cacl_free(dfacep, dfacecnt * sizeof (ace_t));
730 730
731 731 *retacecnt = acecnt + dfacecnt;
732 732 *retacep = acep;
733 733 return (0);
734 734 }
735 735
736 736 static int
737 737 ace_mask_to_mode(uint32_t mask, o_mode_t *modep, boolean_t isdir)
738 738 {
739 739 int error = 0;
740 740 o_mode_t mode = 0;
741 741 uint32_t bits, wantbits;
742 742
743 743 /* read */
744 744 if (mask & ACE_READ_DATA)
745 745 mode |= S_IROTH;
746 746
747 747 /* write */
748 748 wantbits = (ACE_WRITE_DATA | ACE_APPEND_DATA);
749 749 if (isdir)
750 750 wantbits |= ACE_DELETE_CHILD;
751 751 bits = mask & wantbits;
752 752 if (bits != 0) {
753 753 if (bits != wantbits) {
754 754 error = ENOTSUP;
755 755 goto out;
756 756 }
757 757 mode |= S_IWOTH;
758 758 }
759 759
760 760 /* exec */
761 761 if (mask & ACE_EXECUTE) {
762 762 mode |= S_IXOTH;
763 763 }
764 764
765 765 *modep = mode;
766 766
767 767 out:
768 768 return (error);
769 769 }
770 770
771 771 static void
772 772 acevals_init(acevals_t *vals, uid_t key)
773 773 {
774 774 bzero(vals, sizeof (*vals));
775 775 vals->allowed = ACE_MASK_UNDEFINED;
776 776 vals->denied = ACE_MASK_UNDEFINED;
777 777 vals->mask = ACE_MASK_UNDEFINED;
778 778 vals->key = key;
779 779 }
780 780
781 781 static void
782 782 ace_list_init(ace_list_t *al, int dfacl_flag)
783 783 {
784 784 acevals_init(&al->user_obj, NULL);
785 785 acevals_init(&al->group_obj, NULL);
786 786 acevals_init(&al->other_obj, NULL);
787 787 al->numusers = 0;
788 788 al->numgroups = 0;
789 789 al->acl_mask = 0;
790 790 al->hasmask = 0;
791 791 al->state = ace_unused;
792 792 al->seen = 0;
793 793 al->dfacl_flag = dfacl_flag;
794 794 }
795 795
796 796 /*
797 797 * Find or create an acevals holder for a given id and avl tree.
798 798 *
799 799 * Note that only one thread will ever touch these avl trees, so
800 800 * there is no need for locking.
801 801 */
802 802 static acevals_t *
803 803 acevals_find(ace_t *ace, avl_tree_t *avl, int *num)
804 804 {
805 805 acevals_t key, *rc;
806 806 avl_index_t where;
807 807
808 808 key.key = ace->a_who;
809 809 rc = avl_find(avl, &key, &where);
810 810 if (rc != NULL)
811 811 return (rc);
812 812
813 813 /* this memory is freed by ln_ace_to_aent()->ace_list_free() */
814 814 if (cacl_malloc((void **)&rc, sizeof (acevals_t)) != 0)
815 815 return (NULL);
816 816
817 817 acevals_init(rc, ace->a_who);
818 818 avl_insert(avl, rc, where);
819 819 (*num)++;
820 820
821 821 return (rc);
822 822 }
823 823
824 824 static int
825 825 access_mask_check(ace_t *acep, int mask_bit, int isowner)
826 826 {
827 827 int set_deny, err_deny;
828 828 int set_allow, err_allow;
829 829 int acl_consume;
830 830 int haswriteperm, hasreadperm;
831 831
832 832 if (acep->a_type == ACE_ACCESS_DENIED_ACE_TYPE) {
833 833 haswriteperm = (acep->a_access_mask & ACE_WRITE_DATA) ? 0 : 1;
834 834 hasreadperm = (acep->a_access_mask & ACE_READ_DATA) ? 0 : 1;
835 835 } else {
836 836 haswriteperm = (acep->a_access_mask & ACE_WRITE_DATA) ? 1 : 0;
837 837 hasreadperm = (acep->a_access_mask & ACE_READ_DATA) ? 1 : 0;
838 838 }
839 839
840 840 acl_consume = (ACL_SYNCHRONIZE_ERR_DENY |
841 841 ACL_DELETE_ERR_DENY |
842 842 ACL_WRITE_OWNER_ERR_DENY |
843 843 ACL_WRITE_OWNER_ERR_ALLOW |
844 844 ACL_WRITE_ATTRS_OWNER_SET_ALLOW |
845 845 ACL_WRITE_ATTRS_OWNER_ERR_DENY |
846 846 ACL_WRITE_ATTRS_WRITER_SET_DENY |
847 847 ACL_WRITE_ATTRS_WRITER_ERR_ALLOW |
848 848 ACL_WRITE_NAMED_WRITER_ERR_DENY |
849 849 ACL_READ_NAMED_READER_ERR_DENY);
850 850
851 851 if (mask_bit == ACE_SYNCHRONIZE) {
852 852 set_deny = ACL_SYNCHRONIZE_SET_DENY;
853 853 err_deny = ACL_SYNCHRONIZE_ERR_DENY;
854 854 set_allow = ACL_SYNCHRONIZE_SET_ALLOW;
855 855 err_allow = ACL_SYNCHRONIZE_ERR_ALLOW;
856 856 } else if (mask_bit == ACE_WRITE_OWNER) {
857 857 set_deny = ACL_WRITE_OWNER_SET_DENY;
858 858 err_deny = ACL_WRITE_OWNER_ERR_DENY;
859 859 set_allow = ACL_WRITE_OWNER_SET_ALLOW;
860 860 err_allow = ACL_WRITE_OWNER_ERR_ALLOW;
861 861 } else if (mask_bit == ACE_DELETE) {
862 862 set_deny = ACL_DELETE_SET_DENY;
863 863 err_deny = ACL_DELETE_ERR_DENY;
864 864 set_allow = ACL_DELETE_SET_ALLOW;
865 865 err_allow = ACL_DELETE_ERR_ALLOW;
866 866 } else if (mask_bit == ACE_WRITE_ATTRIBUTES) {
867 867 if (isowner) {
868 868 set_deny = ACL_WRITE_ATTRS_OWNER_SET_DENY;
869 869 err_deny = ACL_WRITE_ATTRS_OWNER_ERR_DENY;
870 870 set_allow = ACL_WRITE_ATTRS_OWNER_SET_ALLOW;
871 871 err_allow = ACL_WRITE_ATTRS_OWNER_ERR_ALLOW;
872 872 } else if (haswriteperm) {
873 873 set_deny = ACL_WRITE_ATTRS_WRITER_SET_DENY;
874 874 err_deny = ACL_WRITE_ATTRS_WRITER_ERR_DENY;
875 875 set_allow = ACL_WRITE_ATTRS_WRITER_SET_ALLOW;
876 876 err_allow = ACL_WRITE_ATTRS_WRITER_ERR_ALLOW;
877 877 } else {
878 878 if ((acep->a_access_mask & mask_bit) &&
879 879 (acep->a_type & ACE_ACCESS_ALLOWED_ACE_TYPE)) {
880 880 return (ENOTSUP);
881 881 }
882 882 return (0);
883 883 }
884 884 } else if (mask_bit == ACE_READ_NAMED_ATTRS) {
885 885 if (!hasreadperm)
886 886 return (0);
887 887
888 888 set_deny = ACL_READ_NAMED_READER_SET_DENY;
889 889 err_deny = ACL_READ_NAMED_READER_ERR_DENY;
890 890 set_allow = ACL_READ_NAMED_READER_SET_ALLOW;
891 891 err_allow = ACL_READ_NAMED_READER_ERR_ALLOW;
892 892 } else if (mask_bit == ACE_WRITE_NAMED_ATTRS) {
893 893 if (!haswriteperm)
894 894 return (0);
895 895
896 896 set_deny = ACL_WRITE_NAMED_WRITER_SET_DENY;
897 897 err_deny = ACL_WRITE_NAMED_WRITER_ERR_DENY;
898 898 set_allow = ACL_WRITE_NAMED_WRITER_SET_ALLOW;
899 899 err_allow = ACL_WRITE_NAMED_WRITER_ERR_ALLOW;
900 900 } else {
901 901 return (EINVAL);
902 902 }
903 903
904 904 if (acep->a_type == ACE_ACCESS_DENIED_ACE_TYPE) {
905 905 if (acl_consume & set_deny) {
906 906 if (!(acep->a_access_mask & mask_bit)) {
907 907 return (ENOTSUP);
908 908 }
909 909 } else if (acl_consume & err_deny) {
910 910 if (acep->a_access_mask & mask_bit) {
911 911 return (ENOTSUP);
912 912 }
913 913 }
914 914 } else {
915 915 /* ACE_ACCESS_ALLOWED_ACE_TYPE */
916 916 if (acl_consume & set_allow) {
917 917 if (!(acep->a_access_mask & mask_bit)) {
918 918 return (ENOTSUP);
919 919 }
920 920 } else if (acl_consume & err_allow) {
921 921 if (acep->a_access_mask & mask_bit) {
922 922 return (ENOTSUP);
923 923 }
924 924 }
925 925 }
926 926 return (0);
927 927 }
928 928
929 929 static int
930 930 ace_to_aent_legal(ace_t *acep)
931 931 {
932 932 int error = 0;
933 933 int isowner;
934 934
935 935 /* only ALLOW or DENY */
936 936 if ((acep->a_type != ACE_ACCESS_ALLOWED_ACE_TYPE) &&
937 937 (acep->a_type != ACE_ACCESS_DENIED_ACE_TYPE)) {
938 938 error = ENOTSUP;
939 939 goto out;
940 940 }
941 941
942 942 /* check for invalid flags */
943 943 if (acep->a_flags & ~(ACE_VALID_FLAG_BITS)) {
944 944 error = EINVAL;
945 945 goto out;
946 946 }
947 947
948 948 /* some flags are illegal */
949 949 if (acep->a_flags & (ACE_SUCCESSFUL_ACCESS_ACE_FLAG |
950 950 ACE_FAILED_ACCESS_ACE_FLAG |
951 951 ACE_NO_PROPAGATE_INHERIT_ACE)) {
952 952 error = ENOTSUP;
953 953 goto out;
954 954 }
955 955
956 956 /* check for invalid masks */
957 957 if (acep->a_access_mask & ~(ACE_VALID_MASK_BITS)) {
958 958 error = EINVAL;
959 959 goto out;
960 960 }
961 961
962 962 if ((acep->a_flags & ACE_OWNER)) {
963 963 isowner = 1;
964 964 } else {
965 965 isowner = 0;
966 966 }
967 967
968 968 error = access_mask_check(acep, ACE_SYNCHRONIZE, isowner);
969 969 if (error)
970 970 goto out;
971 971
972 972 error = access_mask_check(acep, ACE_WRITE_OWNER, isowner);
973 973 if (error)
974 974 goto out;
975 975
976 976 error = access_mask_check(acep, ACE_DELETE, isowner);
977 977 if (error)
978 978 goto out;
979 979
980 980 error = access_mask_check(acep, ACE_WRITE_ATTRIBUTES, isowner);
981 981 if (error)
982 982 goto out;
983 983
984 984 error = access_mask_check(acep, ACE_READ_NAMED_ATTRS, isowner);
985 985 if (error)
986 986 goto out;
987 987
988 988 error = access_mask_check(acep, ACE_WRITE_NAMED_ATTRS, isowner);
989 989 if (error)
990 990 goto out;
991 991
992 992 /* more detailed checking of masks */
993 993 if (acep->a_type == ACE_ACCESS_ALLOWED_ACE_TYPE) {
994 994 if (! (acep->a_access_mask & ACE_READ_ATTRIBUTES)) {
995 995 error = ENOTSUP;
996 996 goto out;
997 997 }
998 998 if ((acep->a_access_mask & ACE_WRITE_DATA) &&
999 999 (! (acep->a_access_mask & ACE_APPEND_DATA))) {
1000 1000 error = ENOTSUP;
1001 1001 goto out;
1002 1002 }
1003 1003 if ((! (acep->a_access_mask & ACE_WRITE_DATA)) &&
1004 1004 (acep->a_access_mask & ACE_APPEND_DATA)) {
1005 1005 error = ENOTSUP;
1006 1006 goto out;
1007 1007 }
1008 1008 }
1009 1009
1010 1010 /* ACL enforcement */
1011 1011 if ((acep->a_access_mask & ACE_READ_ACL) &&
1012 1012 (acep->a_type != ACE_ACCESS_ALLOWED_ACE_TYPE)) {
1013 1013 error = ENOTSUP;
1014 1014 goto out;
1015 1015 }
1016 1016 if (acep->a_access_mask & ACE_WRITE_ACL) {
1017 1017 if ((acep->a_type == ACE_ACCESS_DENIED_ACE_TYPE) &&
1018 1018 (isowner)) {
1019 1019 error = ENOTSUP;
1020 1020 goto out;
1021 1021 }
1022 1022 if ((acep->a_type == ACE_ACCESS_ALLOWED_ACE_TYPE) &&
1023 1023 (! isowner)) {
1024 1024 error = ENOTSUP;
1025 1025 goto out;
1026 1026 }
1027 1027 }
1028 1028
1029 1029 out:
1030 1030 return (error);
1031 1031 }
1032 1032
1033 1033 static int
1034 1034 ace_allow_to_mode(uint32_t mask, o_mode_t *modep, boolean_t isdir)
1035 1035 {
1036 1036 /* ACE_READ_ACL and ACE_READ_ATTRIBUTES must both be set */
1037 1037 if ((mask & (ACE_READ_ACL | ACE_READ_ATTRIBUTES)) !=
1038 1038 (ACE_READ_ACL | ACE_READ_ATTRIBUTES)) {
1039 1039 return (ENOTSUP);
1040 1040 }
1041 1041
1042 1042 return (ace_mask_to_mode(mask, modep, isdir));
1043 1043 }
1044 1044
1045 1045 static int
1046 1046 acevals_to_aent(acevals_t *vals, aclent_t *dest, ace_list_t *list,
1047 1047 uid_t owner, gid_t group, boolean_t isdir)
1048 1048 {
1049 1049 int error;
1050 1050 uint32_t flips = ACE_POSIX_SUPPORTED_BITS;
1051 1051
1052 1052 if (isdir)
1053 1053 flips |= ACE_DELETE_CHILD;
1054 1054 if (vals->allowed != (vals->denied ^ flips)) {
1055 1055 error = ENOTSUP;
1056 1056 goto out;
1057 1057 }
1058 1058 if ((list->hasmask) && (list->acl_mask != vals->mask) &&
1059 1059 (vals->aent_type & (USER | GROUP | GROUP_OBJ))) {
1060 1060 error = ENOTSUP;
1061 1061 goto out;
1062 1062 }
1063 1063 error = ace_allow_to_mode(vals->allowed, &dest->a_perm, isdir);
1064 1064 if (error != 0)
1065 1065 goto out;
1066 1066 dest->a_type = vals->aent_type;
1067 1067 if (dest->a_type & (USER | GROUP)) {
1068 1068 dest->a_id = vals->key;
1069 1069 } else if (dest->a_type & USER_OBJ) {
1070 1070 dest->a_id = owner;
1071 1071 } else if (dest->a_type & GROUP_OBJ) {
1072 1072 dest->a_id = group;
1073 1073 } else if (dest->a_type & OTHER_OBJ) {
1074 1074 dest->a_id = 0;
1075 1075 } else {
1076 1076 error = EINVAL;
1077 1077 goto out;
1078 1078 }
1079 1079
1080 1080 out:
1081 1081 return (error);
1082 1082 }
1083 1083
1084 1084
1085 1085 static int
1086 1086 ace_list_to_aent(ace_list_t *list, aclent_t **aclentp, int *aclcnt,
1087 1087 uid_t owner, gid_t group, boolean_t isdir)
1088 1088 {
1089 1089 int error = 0;
1090 1090 aclent_t *aent, *result = NULL;
1091 1091 acevals_t *vals;
1092 1092 int resultcount;
1093 1093
1094 1094 if ((list->seen & (USER_OBJ | GROUP_OBJ | OTHER_OBJ)) !=
1095 1095 (USER_OBJ | GROUP_OBJ | OTHER_OBJ)) {
1096 1096 return (ENOTSUP);
1097 1097 }
1098 1098
1099 1099 if ((! list->hasmask) && (list->numusers + list->numgroups > 0)) {
1100 1100 return (ENOTSUP);
1101 1101 }
1102 1102
1103 1103 resultcount = 3 + list->numusers + list->numgroups;
1104 1104 /*
1105 1105 * This must be the same condition as below, when we add the CLASS_OBJ
1106 1106 * (aka ACL mask)
1107 1107 */
1108 1108 if ((list->hasmask) || (! list->dfacl_flag))
1109 1109 resultcount += 1;
1110 1110
1111 1111 if (cacl_malloc((void **)&result,
1112 1112 resultcount * sizeof (aclent_t)) != 0) {
1113 1113 error = ENOMEM;
1114 1114 goto out;
1115 1115 }
1116 1116 aent = result;
1117 1117
1118 1118 /* USER_OBJ */
1119 1119 if (!(list->user_obj.aent_type & USER_OBJ)) {
1120 1120 error = EINVAL;
1121 1121 goto out;
1122 1122 }
1123 1123
1124 1124 error = acevals_to_aent(&list->user_obj, aent, list, owner, group,
1125 1125 isdir);
1126 1126
1127 1127 if (error != 0)
1128 1128 goto out;
1129 1129 ++aent;
1130 1130 /* USER */
1131 1131 vals = NULL;
1132 1132 for (vals = avl_first(&list->user); vals != NULL;
1133 1133 vals = AVL_NEXT(&list->user, vals)) {
1134 1134 if (!(vals->aent_type & USER)) {
1135 1135 error = EINVAL;
1136 1136 goto out;
1137 1137 }
1138 1138 error = acevals_to_aent(vals, aent, list, owner, group,
1139 1139 isdir);
1140 1140 if (error != 0)
1141 1141 goto out;
1142 1142 ++aent;
1143 1143 }
1144 1144 /* GROUP_OBJ */
1145 1145 if (!(list->group_obj.aent_type & GROUP_OBJ)) {
1146 1146 error = EINVAL;
1147 1147 goto out;
1148 1148 }
1149 1149 error = acevals_to_aent(&list->group_obj, aent, list, owner, group,
1150 1150 isdir);
1151 1151 if (error != 0)
1152 1152 goto out;
1153 1153 ++aent;
1154 1154 /* GROUP */
1155 1155 vals = NULL;
1156 1156 for (vals = avl_first(&list->group); vals != NULL;
1157 1157 vals = AVL_NEXT(&list->group, vals)) {
1158 1158 if (!(vals->aent_type & GROUP)) {
1159 1159 error = EINVAL;
1160 1160 goto out;
1161 1161 }
1162 1162 error = acevals_to_aent(vals, aent, list, owner, group,
1163 1163 isdir);
1164 1164 if (error != 0)
1165 1165 goto out;
1166 1166 ++aent;
1167 1167 }
1168 1168 /*
1169 1169 * CLASS_OBJ (aka ACL_MASK)
1170 1170 *
1171 1171 * An ACL_MASK is not fabricated if the ACL is a default ACL.
1172 1172 * This is to follow UFS's behavior.
1173 1173 */
1174 1174 if ((list->hasmask) || (! list->dfacl_flag)) {
1175 1175 if (list->hasmask) {
1176 1176 uint32_t flips = ACE_POSIX_SUPPORTED_BITS;
1177 1177 if (isdir)
1178 1178 flips |= ACE_DELETE_CHILD;
1179 1179 error = ace_mask_to_mode(list->acl_mask ^ flips,
1180 1180 &aent->a_perm, isdir);
1181 1181 if (error != 0)
1182 1182 goto out;
1183 1183 } else {
1184 1184 /* fabricate the ACL_MASK from the group permissions */
1185 1185 error = ace_mask_to_mode(list->group_obj.allowed,
1186 1186 &aent->a_perm, isdir);
1187 1187 if (error != 0)
1188 1188 goto out;
1189 1189 }
1190 1190 aent->a_id = 0;
1191 1191 aent->a_type = CLASS_OBJ | list->dfacl_flag;
1192 1192 ++aent;
1193 1193 }
1194 1194 /* OTHER_OBJ */
1195 1195 if (!(list->other_obj.aent_type & OTHER_OBJ)) {
1196 1196 error = EINVAL;
1197 1197 goto out;
1198 1198 }
1199 1199 error = acevals_to_aent(&list->other_obj, aent, list, owner, group,
1200 1200 isdir);
1201 1201 if (error != 0)
1202 1202 goto out;
1203 1203 ++aent;
1204 1204
1205 1205 *aclentp = result;
1206 1206 *aclcnt = resultcount;
1207 1207
1208 1208 out:
1209 1209 if (error != 0) {
1210 1210 if (result != NULL)
1211 1211 cacl_free(result, resultcount * sizeof (aclent_t));
1212 1212 }
1213 1213
1214 1214 return (error);
1215 1215 }
1216 1216
1217 1217
1218 1218 /*
1219 1219 * free all data associated with an ace_list
1220 1220 */
1221 1221 static void
1222 1222 ace_list_free(ace_list_t *al)
1223 1223 {
1224 1224 acevals_t *node;
1225 1225 void *cookie;
1226 1226
1227 1227 if (al == NULL)
1228 1228 return;
1229 1229
1230 1230 cookie = NULL;
1231 1231 while ((node = avl_destroy_nodes(&al->user, &cookie)) != NULL)
1232 1232 cacl_free(node, sizeof (acevals_t));
1233 1233 cookie = NULL;
1234 1234 while ((node = avl_destroy_nodes(&al->group, &cookie)) != NULL)
1235 1235 cacl_free(node, sizeof (acevals_t));
1236 1236
1237 1237 avl_destroy(&al->user);
1238 1238 avl_destroy(&al->group);
1239 1239
1240 1240 /* free the container itself */
1241 1241 cacl_free(al, sizeof (ace_list_t));
1242 1242 }
1243 1243
1244 1244 static int
1245 1245 acevals_compare(const void *va, const void *vb)
1246 1246 {
1247 1247 const acevals_t *a = va, *b = vb;
1248 1248
1249 1249 if (a->key == b->key)
1250 1250 return (0);
1251 1251
1252 1252 if (a->key > b->key)
1253 1253 return (1);
1254 1254
1255 1255 else
1256 1256 return (-1);
1257 1257 }
1258 1258
1259 1259 /*
1260 1260 * Convert a list of ace_t entries to equivalent regular and default
1261 1261 * aclent_t lists. Return error (ENOTSUP) when conversion is not possible.
1262 1262 */
1263 1263 static int
1264 1264 ln_ace_to_aent(ace_t *ace, int n, uid_t owner, gid_t group,
1265 1265 aclent_t **aclentp, int *aclcnt, aclent_t **dfaclentp, int *dfaclcnt,
1266 1266 boolean_t isdir)
1267 1267 {
1268 1268 int error = 0;
1269 1269 ace_t *acep;
1270 1270 uint32_t bits;
1271 1271 int i;
1272 1272 ace_list_t *normacl = NULL, *dfacl = NULL, *acl;
1273 1273 acevals_t *vals;
1274 1274
1275 1275 *aclentp = NULL;
1276 1276 *aclcnt = 0;
1277 1277 *dfaclentp = NULL;
1278 1278 *dfaclcnt = 0;
1279 1279
1280 1280 /* we need at least user_obj, group_obj, and other_obj */
1281 1281 if (n < 6) {
1282 1282 error = ENOTSUP;
1283 1283 goto out;
1284 1284 }
1285 1285 if (ace == NULL) {
1286 1286 error = EINVAL;
1287 1287 goto out;
1288 1288 }
1289 1289
1290 1290 error = cacl_malloc((void **)&normacl, sizeof (ace_list_t));
1291 1291 if (error != 0)
1292 1292 goto out;
1293 1293
1294 1294 avl_create(&normacl->user, acevals_compare, sizeof (acevals_t),
1295 1295 offsetof(acevals_t, avl));
1296 1296 avl_create(&normacl->group, acevals_compare, sizeof (acevals_t),
1297 1297 offsetof(acevals_t, avl));
1298 1298
1299 1299 ace_list_init(normacl, 0);
1300 1300
1301 1301 error = cacl_malloc((void **)&dfacl, sizeof (ace_list_t));
1302 1302 if (error != 0)
1303 1303 goto out;
1304 1304
1305 1305 avl_create(&dfacl->user, acevals_compare, sizeof (acevals_t),
1306 1306 offsetof(acevals_t, avl));
1307 1307 avl_create(&dfacl->group, acevals_compare, sizeof (acevals_t),
1308 1308 offsetof(acevals_t, avl));
1309 1309 ace_list_init(dfacl, ACL_DEFAULT);
1310 1310
1311 1311 /* process every ace_t... */
1312 1312 for (i = 0; i < n; i++) {
1313 1313 acep = &ace[i];
1314 1314
1315 1315 /* rule out certain cases quickly */
1316 1316 error = ace_to_aent_legal(acep);
1317 1317 if (error != 0)
1318 1318 goto out;
1319 1319
1320 1320 /*
1321 1321 * Turn off these bits in order to not have to worry about
1322 1322 * them when doing the checks for compliments.
1323 1323 */
1324 1324 acep->a_access_mask &= ~(ACE_WRITE_OWNER | ACE_DELETE |
1325 1325 ACE_SYNCHRONIZE | ACE_WRITE_ATTRIBUTES |
1326 1326 ACE_READ_NAMED_ATTRS | ACE_WRITE_NAMED_ATTRS);
1327 1327
1328 1328 /* see if this should be a regular or default acl */
1329 1329 bits = acep->a_flags &
1330 1330 (ACE_INHERIT_ONLY_ACE |
1331 1331 ACE_FILE_INHERIT_ACE |
1332 1332 ACE_DIRECTORY_INHERIT_ACE);
1333 1333 if (bits != 0) {
1334 1334 /* all or nothing on these inherit bits */
1335 1335 if (bits != (ACE_INHERIT_ONLY_ACE |
1336 1336 ACE_FILE_INHERIT_ACE |
1337 1337 ACE_DIRECTORY_INHERIT_ACE)) {
1338 1338 error = ENOTSUP;
1339 1339 goto out;
1340 1340 }
1341 1341 acl = dfacl;
1342 1342 } else {
1343 1343 acl = normacl;
1344 1344 }
1345 1345
1346 1346 if ((acep->a_flags & ACE_OWNER)) {
1347 1347 if (acl->state > ace_user_obj) {
1348 1348 error = ENOTSUP;
1349 1349 goto out;
1350 1350 }
1351 1351 acl->state = ace_user_obj;
1352 1352 acl->seen |= USER_OBJ;
1353 1353 vals = &acl->user_obj;
1354 1354 vals->aent_type = USER_OBJ | acl->dfacl_flag;
1355 1355 } else if ((acep->a_flags & ACE_EVERYONE)) {
1356 1356 acl->state = ace_other_obj;
1357 1357 acl->seen |= OTHER_OBJ;
1358 1358 vals = &acl->other_obj;
1359 1359 vals->aent_type = OTHER_OBJ | acl->dfacl_flag;
1360 1360 } else if (acep->a_flags & ACE_IDENTIFIER_GROUP) {
1361 1361 if (acl->state > ace_group) {
1362 1362 error = ENOTSUP;
1363 1363 goto out;
1364 1364 }
1365 1365 if ((acep->a_flags & ACE_GROUP)) {
1366 1366 acl->seen |= GROUP_OBJ;
1367 1367 vals = &acl->group_obj;
1368 1368 vals->aent_type = GROUP_OBJ | acl->dfacl_flag;
1369 1369 } else {
1370 1370 acl->seen |= GROUP;
1371 1371 vals = acevals_find(acep, &acl->group,
1372 1372 &acl->numgroups);
1373 1373 if (vals == NULL) {
1374 1374 error = ENOMEM;
1375 1375 goto out;
1376 1376 }
1377 1377 vals->aent_type = GROUP | acl->dfacl_flag;
1378 1378 }
1379 1379 acl->state = ace_group;
1380 1380 } else {
1381 1381 if (acl->state > ace_user) {
1382 1382 error = ENOTSUP;
1383 1383 goto out;
1384 1384 }
1385 1385 acl->state = ace_user;
1386 1386 acl->seen |= USER;
1387 1387 vals = acevals_find(acep, &acl->user,
1388 1388 &acl->numusers);
1389 1389 if (vals == NULL) {
1390 1390 error = ENOMEM;
1391 1391 goto out;
1392 1392 }
1393 1393 vals->aent_type = USER | acl->dfacl_flag;
1394 1394 }
1395 1395
1396 1396 if (!(acl->state > ace_unused)) {
1397 1397 error = EINVAL;
1398 1398 goto out;
1399 1399 }
1400 1400
1401 1401 if (acep->a_type == ACE_ACCESS_ALLOWED_ACE_TYPE) {
1402 1402 /* no more than one allowed per aclent_t */
1403 1403 if (vals->allowed != ACE_MASK_UNDEFINED) {
1404 1404 error = ENOTSUP;
1405 1405 goto out;
1406 1406 }
1407 1407 vals->allowed = acep->a_access_mask;
1408 1408 } else {
1409 1409 /*
1410 1410 * it's a DENY; if there was a previous DENY, it
1411 1411 * must have been an ACL_MASK.
1412 1412 */
1413 1413 if (vals->denied != ACE_MASK_UNDEFINED) {
1414 1414 /* ACL_MASK is for USER and GROUP only */
1415 1415 if ((acl->state != ace_user) &&
1416 1416 (acl->state != ace_group)) {
1417 1417 error = ENOTSUP;
1418 1418 goto out;
1419 1419 }
1420 1420
1421 1421 if (! acl->hasmask) {
1422 1422 acl->hasmask = 1;
1423 1423 acl->acl_mask = vals->denied;
1424 1424 /* check for mismatched ACL_MASK emulations */
1425 1425 } else if (acl->acl_mask != vals->denied) {
1426 1426 error = ENOTSUP;
1427 1427 goto out;
1428 1428 }
1429 1429 vals->mask = vals->denied;
1430 1430 }
1431 1431 vals->denied = acep->a_access_mask;
1432 1432 }
1433 1433 }
1434 1434
1435 1435 /* done collating; produce the aclent_t lists */
1436 1436 if (normacl->state != ace_unused) {
1437 1437 error = ace_list_to_aent(normacl, aclentp, aclcnt,
1438 1438 owner, group, isdir);
1439 1439 if (error != 0) {
1440 1440 goto out;
1441 1441 }
1442 1442 }
1443 1443 if (dfacl->state != ace_unused) {
1444 1444 error = ace_list_to_aent(dfacl, dfaclentp, dfaclcnt,
1445 1445 owner, group, isdir);
1446 1446 if (error != 0) {
1447 1447 goto out;
1448 1448 }
1449 1449 }
1450 1450
1451 1451 out:
1452 1452 if (normacl != NULL)
1453 1453 ace_list_free(normacl);
1454 1454 if (dfacl != NULL)
1455 1455 ace_list_free(dfacl);
1456 1456
1457 1457 return (error);
1458 1458 }
1459 1459
1460 1460 static int
1461 1461 convert_ace_to_aent(ace_t *acebufp, int acecnt, boolean_t isdir,
1462 1462 uid_t owner, gid_t group, aclent_t **retaclentp, int *retaclcnt)
1463 1463 {
1464 1464 int error = 0;
1465 1465 aclent_t *aclentp, *dfaclentp;
1466 1466 int aclcnt, dfaclcnt;
1467 1467 int aclsz, dfaclsz = 0;
1468 1468
1469 1469 error = ln_ace_to_aent(acebufp, acecnt, owner, group,
1470 1470 &aclentp, &aclcnt, &dfaclentp, &dfaclcnt, isdir);
1471 1471
1472 1472 if (error)
1473 1473 return (error);
1474 1474
1475 1475
1476 1476 if (dfaclcnt != 0) {
1477 1477 /*
1478 1478 * Slap aclentp and dfaclentp into a single array.
1479 1479 */
1480 1480 aclsz = sizeof (aclent_t) * aclcnt;
1481 1481 dfaclsz = sizeof (aclent_t) * dfaclcnt;
1482 1482 aclentp = cacl_realloc(aclentp, aclsz, aclsz + dfaclsz);
1483 1483 if (aclentp != NULL) {
1484 1484 (void) memcpy(aclentp + aclcnt, dfaclentp, dfaclsz);
1485 1485 } else {
1486 1486 error = ENOMEM;
1487 1487 }
1488 1488 }
1489 1489
1490 1490 if (aclentp) {
1491 1491 *retaclentp = aclentp;
1492 1492 *retaclcnt = aclcnt + dfaclcnt;
1493 1493 }
1494 1494
1495 1495 if (dfaclentp)
1496 1496 cacl_free(dfaclentp, dfaclsz);
1497 1497
1498 1498 return (error);
1499 1499 }
1500 1500
1501 1501
1502 1502 int
1503 1503 acl_translate(acl_t *aclp, int target_flavor, boolean_t isdir, uid_t owner,
1504 1504 gid_t group)
1505 1505 {
1506 1506 int aclcnt;
1507 1507 void *acldata;
1508 1508 int error;
1509 1509
1510 1510 /*
1511 1511 * See if we need to translate
1512 1512 */
1513 1513 if ((target_flavor == _ACL_ACE_ENABLED && aclp->acl_type == ACE_T) ||
1514 1514 (target_flavor == _ACL_ACLENT_ENABLED &&
1515 1515 aclp->acl_type == ACLENT_T))
1516 1516 return (0);
1517 1517
1518 1518 if (target_flavor == -1) {
1519 1519 error = EINVAL;
1520 1520 goto out;
1521 1521 }
1522 1522
1523 1523 if (target_flavor == _ACL_ACE_ENABLED &&
1524 1524 aclp->acl_type == ACLENT_T) {
1525 1525 error = convert_aent_to_ace(aclp->acl_aclp,
1526 1526 aclp->acl_cnt, isdir, (ace_t **)&acldata, &aclcnt);
1527 1527 if (error)
1528 1528 goto out;
1529 1529
1530 1530 } else if (target_flavor == _ACL_ACLENT_ENABLED &&
1531 1531 aclp->acl_type == ACE_T) {
1532 1532 error = convert_ace_to_aent(aclp->acl_aclp, aclp->acl_cnt,
1533 1533 isdir, owner, group, (aclent_t **)&acldata, &aclcnt);
1534 1534 if (error)
1535 1535 goto out;
1536 1536 } else {
1537 1537 error = ENOTSUP;
1538 1538 goto out;
1539 1539 }
1540 1540
1541 1541 /*
1542 1542 * replace old acl with newly translated acl
1543 1543 */
1544 1544 cacl_free(aclp->acl_aclp, aclp->acl_cnt * aclp->acl_entry_size);
1545 1545 aclp->acl_aclp = acldata;
1546 1546 aclp->acl_cnt = aclcnt;
1547 1547 if (target_flavor == _ACL_ACE_ENABLED) {
1548 1548 aclp->acl_type = ACE_T;
1549 1549 aclp->acl_entry_size = sizeof (ace_t);
1550 1550 } else {
1551 1551 aclp->acl_type = ACLENT_T;
1552 1552 aclp->acl_entry_size = sizeof (aclent_t);
1553 1553 }
1554 1554 return (0);
1555 1555
1556 1556 out:
1557 1557
1558 1558 #if defined(_KERNEL) || defined(_FAKE_KERNEL)
1559 1559 return (error);
1560 1560 #else
1561 1561 errno = error;
1562 1562 return (-1);
1563 1563 #endif
1564 1564 }
1565 1565
1566 1566 #define SET_ACE(acl, index, who, mask, type, flags) { \
1567 1567 acl[0][index].a_who = (uint32_t)who; \
1568 1568 acl[0][index].a_type = type; \
1569 1569 acl[0][index].a_flags = flags; \
1570 1570 acl[0][index++].a_access_mask = mask; \
1571 1571 }
1572 1572
1573 1573 void
1574 1574 acl_trivial_access_masks(mode_t mode, boolean_t isdir, trivial_acl_t *masks)
1575 1575 {
1576 1576 uint32_t read_mask = ACE_READ_DATA;
1577 1577 uint32_t write_mask = ACE_WRITE_DATA|ACE_APPEND_DATA;
1578 1578 uint32_t execute_mask = ACE_EXECUTE;
1579 1579
1580 1580 if (isdir)
1581 1581 write_mask |= ACE_DELETE_CHILD;
1582 1582
1583 1583 masks->deny1 = 0;
1584 1584 if (!(mode & S_IRUSR) && (mode & (S_IRGRP|S_IROTH)))
1585 1585 masks->deny1 |= read_mask;
1586 1586 if (!(mode & S_IWUSR) && (mode & (S_IWGRP|S_IWOTH)))
1587 1587 masks->deny1 |= write_mask;
1588 1588 if (!(mode & S_IXUSR) && (mode & (S_IXGRP|S_IXOTH)))
1589 1589 masks->deny1 |= execute_mask;
1590 1590
1591 1591 masks->deny2 = 0;
1592 1592 if (!(mode & S_IRGRP) && (mode & S_IROTH))
1593 1593 masks->deny2 |= read_mask;
1594 1594 if (!(mode & S_IWGRP) && (mode & S_IWOTH))
1595 1595 masks->deny2 |= write_mask;
1596 1596 if (!(mode & S_IXGRP) && (mode & S_IXOTH))
1597 1597 masks->deny2 |= execute_mask;
1598 1598
1599 1599 masks->allow0 = 0;
1600 1600 if ((mode & S_IRUSR) && (!(mode & S_IRGRP) && (mode & S_IROTH)))
1601 1601 masks->allow0 |= read_mask;
1602 1602 if ((mode & S_IWUSR) && (!(mode & S_IWGRP) && (mode & S_IWOTH)))
1603 1603 masks->allow0 |= write_mask;
1604 1604 if ((mode & S_IXUSR) && (!(mode & S_IXGRP) && (mode & S_IXOTH)))
1605 1605 masks->allow0 |= execute_mask;
1606 1606
1607 1607 masks->owner = ACE_WRITE_ATTRIBUTES|ACE_WRITE_OWNER|ACE_WRITE_ACL|
1608 1608 ACE_WRITE_NAMED_ATTRS|ACE_READ_ACL|ACE_READ_ATTRIBUTES|
1609 1609 ACE_READ_NAMED_ATTRS|ACE_SYNCHRONIZE;
1610 1610 if (mode & S_IRUSR)
1611 1611 masks->owner |= read_mask;
1612 1612 if (mode & S_IWUSR)
1613 1613 masks->owner |= write_mask;
1614 1614 if (mode & S_IXUSR)
1615 1615 masks->owner |= execute_mask;
1616 1616
1617 1617 masks->group = ACE_READ_ACL|ACE_READ_ATTRIBUTES|ACE_READ_NAMED_ATTRS|
1618 1618 ACE_SYNCHRONIZE;
1619 1619 if (mode & S_IRGRP)
1620 1620 masks->group |= read_mask;
1621 1621 if (mode & S_IWGRP)
1622 1622 masks->group |= write_mask;
1623 1623 if (mode & S_IXGRP)
1624 1624 masks->group |= execute_mask;
1625 1625
1626 1626 masks->everyone = ACE_READ_ACL|ACE_READ_ATTRIBUTES|ACE_READ_NAMED_ATTRS|
1627 1627 ACE_SYNCHRONIZE;
1628 1628 if (mode & S_IROTH)
1629 1629 masks->everyone |= read_mask;
1630 1630 if (mode & S_IWOTH)
1631 1631 masks->everyone |= write_mask;
1632 1632 if (mode & S_IXOTH)
1633 1633 masks->everyone |= execute_mask;
1634 1634 }
1635 1635
1636 1636 int
1637 1637 acl_trivial_create(mode_t mode, boolean_t isdir, ace_t **acl, int *count)
1638 1638 {
1639 1639 int index = 0;
1640 1640 int error;
1641 1641 trivial_acl_t masks;
1642 1642
1643 1643 *count = 3;
1644 1644 acl_trivial_access_masks(mode, isdir, &masks);
1645 1645
1646 1646 if (masks.allow0)
1647 1647 (*count)++;
1648 1648 if (masks.deny1)
1649 1649 (*count)++;
1650 1650 if (masks.deny2)
1651 1651 (*count)++;
1652 1652
1653 1653 if ((error = cacl_malloc((void **)acl, *count * sizeof (ace_t))) != 0)
1654 1654 return (error);
1655 1655
1656 1656 if (masks.allow0) {
1657 1657 SET_ACE(acl, index, -1, masks.allow0,
1658 1658 ACE_ACCESS_ALLOWED_ACE_TYPE, ACE_OWNER);
1659 1659 }
1660 1660 if (masks.deny1) {
1661 1661 SET_ACE(acl, index, -1, masks.deny1,
1662 1662 ACE_ACCESS_DENIED_ACE_TYPE, ACE_OWNER);
1663 1663 }
1664 1664 if (masks.deny2) {
1665 1665 SET_ACE(acl, index, -1, masks.deny2,
1666 1666 ACE_ACCESS_DENIED_ACE_TYPE, ACE_GROUP|ACE_IDENTIFIER_GROUP);
1667 1667 }
1668 1668
1669 1669 SET_ACE(acl, index, -1, masks.owner, ACE_ACCESS_ALLOWED_ACE_TYPE,
1670 1670 ACE_OWNER);
1671 1671 SET_ACE(acl, index, -1, masks.group, ACE_ACCESS_ALLOWED_ACE_TYPE,
1672 1672 ACE_IDENTIFIER_GROUP|ACE_GROUP);
1673 1673 SET_ACE(acl, index, -1, masks.everyone, ACE_ACCESS_ALLOWED_ACE_TYPE,
1674 1674 ACE_EVERYONE);
1675 1675
1676 1676 return (0);
1677 1677 }
1678 1678
1679 1679 /*
1680 1680 * ace_trivial:
1681 1681 * determine whether an ace_t acl is trivial
1682 1682 *
1683 1683 * Trivialness implies that the acl is composed of only
1684 1684 * owner, group, everyone entries. ACL can't
1685 1685 * have read_acl denied, and write_owner/write_acl/write_attributes
1686 1686 * can only be owner@ entry.
1687 1687 */
|
↓ open down ↓ |
1687 lines elided |
↑ open up ↑ |
1688 1688 int
1689 1689 ace_trivial_common(void *acep, int aclcnt,
1690 1690 uint64_t (*walk)(void *, uint64_t, int aclcnt,
1691 1691 uint16_t *, uint16_t *, uint32_t *))
1692 1692 {
1693 1693 uint16_t flags;
1694 1694 uint32_t mask;
1695 1695 uint16_t type;
1696 1696 uint64_t cookie = 0;
1697 1697
1698 - while (cookie = walk(acep, cookie, aclcnt, &flags, &type, &mask)) {
1698 + while ((cookie = walk(acep, cookie, aclcnt, &flags, &type, &mask))
1699 + != NULL) {
1699 1700 switch (flags & ACE_TYPE_FLAGS) {
1700 1701 case ACE_OWNER:
1701 1702 case ACE_GROUP|ACE_IDENTIFIER_GROUP:
1702 1703 case ACE_EVERYONE:
1703 1704 break;
1704 1705 default:
1705 1706 return (1);
1706 1707
1707 1708 }
1708 1709
1709 1710 if (flags & (ACE_FILE_INHERIT_ACE|
1710 1711 ACE_DIRECTORY_INHERIT_ACE|ACE_NO_PROPAGATE_INHERIT_ACE|
1711 1712 ACE_INHERIT_ONLY_ACE))
1712 1713 return (1);
1713 1714
1714 1715 /*
1715 1716 * Special check for some special bits
1716 1717 *
1717 1718 * Don't allow anybody to deny reading basic
1718 1719 * attributes or a files ACL.
1719 1720 */
1720 1721 if ((mask & (ACE_READ_ACL|ACE_READ_ATTRIBUTES)) &&
1721 1722 (type == ACE_ACCESS_DENIED_ACE_TYPE))
1722 1723 return (1);
1723 1724
1724 1725 /*
1725 1726 * Delete permission is never set by default
1726 1727 */
1727 1728 if (mask & ACE_DELETE)
1728 1729 return (1);
1729 1730
1730 1731 /*
1731 1732 * Child delete permission should be accompanied by write
1732 1733 */
1733 1734 if ((mask & ACE_DELETE_CHILD) && !(mask & ACE_WRITE_DATA))
1734 1735 return (1);
1735 1736
1736 1737 /*
1737 1738 * only allow owner@ to have
1738 1739 * write_acl/write_owner/write_attributes/write_xattr/
1739 1740 */
1740 1741 if (type == ACE_ACCESS_ALLOWED_ACE_TYPE &&
1741 1742 (!(flags & ACE_OWNER) && (mask &
1742 1743 (ACE_WRITE_OWNER|ACE_WRITE_ACL| ACE_WRITE_ATTRIBUTES|
1743 1744 ACE_WRITE_NAMED_ATTRS))))
1744 1745 return (1);
1745 1746
1746 1747 }
1747 1748 return (0);
1748 1749 }
1749 1750
1750 1751 uint64_t
1751 1752 ace_walk(void *datap, uint64_t cookie, int aclcnt, uint16_t *flags,
1752 1753 uint16_t *type, uint32_t *mask)
1753 1754 {
1754 1755 ace_t *acep = datap;
1755 1756
1756 1757 if (cookie >= aclcnt)
1757 1758 return (0);
1758 1759
1759 1760 *flags = acep[cookie].a_flags;
1760 1761 *type = acep[cookie].a_type;
1761 1762 *mask = acep[cookie++].a_access_mask;
1762 1763
1763 1764 return (cookie);
1764 1765 }
1765 1766
1766 1767 int
1767 1768 ace_trivial(ace_t *acep, int aclcnt)
1768 1769 {
1769 1770 return (ace_trivial_common(acep, aclcnt, ace_walk));
1770 1771 }
|
↓ open down ↓ |
62 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX