Print this page
3742 zfs comments need cleaner, more consistent style
Submitted by: Will Andrews <willa@spectralogic.com>
Submitted by: Alan Somers <alans@spectralogic.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Eric Schrock <eric.schrock@delphix.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/zfs/zfs_acl.c
+++ new/usr/src/uts/common/fs/zfs/zfs_acl.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 2011 Nexenta Systems, Inc. All rights reserved.
24 24 * Copyright (c) 2013 by Delphix. All rights reserved.
25 25 */
26 26
27 27 #include <sys/types.h>
28 28 #include <sys/param.h>
29 29 #include <sys/time.h>
30 30 #include <sys/systm.h>
31 31 #include <sys/sysmacros.h>
32 32 #include <sys/resource.h>
33 33 #include <sys/vfs.h>
34 34 #include <sys/vnode.h>
35 35 #include <sys/sid.h>
36 36 #include <sys/file.h>
37 37 #include <sys/stat.h>
38 38 #include <sys/kmem.h>
39 39 #include <sys/cmn_err.h>
40 40 #include <sys/errno.h>
41 41 #include <sys/unistd.h>
42 42 #include <sys/sdt.h>
43 43 #include <sys/fs/zfs.h>
44 44 #include <sys/mode.h>
45 45 #include <sys/policy.h>
46 46 #include <sys/zfs_znode.h>
47 47 #include <sys/zfs_fuid.h>
48 48 #include <sys/zfs_acl.h>
49 49 #include <sys/zfs_dir.h>
50 50 #include <sys/zfs_vfsops.h>
51 51 #include <sys/dmu.h>
52 52 #include <sys/dnode.h>
53 53 #include <sys/zap.h>
54 54 #include <sys/sa.h>
55 55 #include "fs/fs_subr.h"
56 56 #include <acl/acl_common.h>
57 57
58 58 #define ALLOW ACE_ACCESS_ALLOWED_ACE_TYPE
59 59 #define DENY ACE_ACCESS_DENIED_ACE_TYPE
60 60 #define MAX_ACE_TYPE ACE_SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE
61 61 #define MIN_ACE_TYPE ALLOW
62 62
63 63 #define OWNING_GROUP (ACE_GROUP|ACE_IDENTIFIER_GROUP)
64 64 #define EVERYONE_ALLOW_MASK (ACE_READ_ACL|ACE_READ_ATTRIBUTES | \
65 65 ACE_READ_NAMED_ATTRS|ACE_SYNCHRONIZE)
66 66 #define EVERYONE_DENY_MASK (ACE_WRITE_ACL|ACE_WRITE_OWNER | \
67 67 ACE_WRITE_ATTRIBUTES|ACE_WRITE_NAMED_ATTRS)
68 68 #define OWNER_ALLOW_MASK (ACE_WRITE_ACL | ACE_WRITE_OWNER | \
69 69 ACE_WRITE_ATTRIBUTES|ACE_WRITE_NAMED_ATTRS)
70 70
71 71 #define ZFS_CHECKED_MASKS (ACE_READ_ACL|ACE_READ_ATTRIBUTES|ACE_READ_DATA| \
72 72 ACE_READ_NAMED_ATTRS|ACE_WRITE_DATA|ACE_WRITE_ATTRIBUTES| \
73 73 ACE_WRITE_NAMED_ATTRS|ACE_APPEND_DATA|ACE_EXECUTE|ACE_WRITE_OWNER| \
74 74 ACE_WRITE_ACL|ACE_DELETE|ACE_DELETE_CHILD|ACE_SYNCHRONIZE)
75 75
76 76 #define WRITE_MASK_DATA (ACE_WRITE_DATA|ACE_APPEND_DATA|ACE_WRITE_NAMED_ATTRS)
77 77 #define WRITE_MASK_ATTRS (ACE_WRITE_ACL|ACE_WRITE_OWNER|ACE_WRITE_ATTRIBUTES| \
78 78 ACE_DELETE|ACE_DELETE_CHILD)
79 79 #define WRITE_MASK (WRITE_MASK_DATA|WRITE_MASK_ATTRS)
80 80
81 81 #define OGE_CLEAR (ACE_READ_DATA|ACE_LIST_DIRECTORY|ACE_WRITE_DATA| \
82 82 ACE_ADD_FILE|ACE_APPEND_DATA|ACE_ADD_SUBDIRECTORY|ACE_EXECUTE)
83 83
84 84 #define OKAY_MASK_BITS (ACE_READ_DATA|ACE_LIST_DIRECTORY|ACE_WRITE_DATA| \
85 85 ACE_ADD_FILE|ACE_APPEND_DATA|ACE_ADD_SUBDIRECTORY|ACE_EXECUTE)
86 86
87 87 #define ALL_INHERIT (ACE_FILE_INHERIT_ACE|ACE_DIRECTORY_INHERIT_ACE | \
88 88 ACE_NO_PROPAGATE_INHERIT_ACE|ACE_INHERIT_ONLY_ACE|ACE_INHERITED_ACE)
89 89
90 90 #define RESTRICTED_CLEAR (ACE_WRITE_ACL|ACE_WRITE_OWNER)
91 91
92 92 #define V4_ACL_WIDE_FLAGS (ZFS_ACL_AUTO_INHERIT|ZFS_ACL_DEFAULTED|\
93 93 ZFS_ACL_PROTECTED)
94 94
95 95 #define ZFS_ACL_WIDE_FLAGS (V4_ACL_WIDE_FLAGS|ZFS_ACL_TRIVIAL|ZFS_INHERIT_ACE|\
96 96 ZFS_ACL_OBJ_ACE)
97 97
98 98 #define ALL_MODE_EXECS (S_IXUSR | S_IXGRP | S_IXOTH)
99 99
100 100 static uint16_t
101 101 zfs_ace_v0_get_type(void *acep)
102 102 {
103 103 return (((zfs_oldace_t *)acep)->z_type);
104 104 }
105 105
106 106 static uint16_t
107 107 zfs_ace_v0_get_flags(void *acep)
108 108 {
109 109 return (((zfs_oldace_t *)acep)->z_flags);
110 110 }
111 111
112 112 static uint32_t
113 113 zfs_ace_v0_get_mask(void *acep)
114 114 {
115 115 return (((zfs_oldace_t *)acep)->z_access_mask);
116 116 }
117 117
118 118 static uint64_t
119 119 zfs_ace_v0_get_who(void *acep)
120 120 {
121 121 return (((zfs_oldace_t *)acep)->z_fuid);
122 122 }
123 123
124 124 static void
125 125 zfs_ace_v0_set_type(void *acep, uint16_t type)
126 126 {
127 127 ((zfs_oldace_t *)acep)->z_type = type;
128 128 }
129 129
130 130 static void
131 131 zfs_ace_v0_set_flags(void *acep, uint16_t flags)
132 132 {
133 133 ((zfs_oldace_t *)acep)->z_flags = flags;
134 134 }
135 135
136 136 static void
137 137 zfs_ace_v0_set_mask(void *acep, uint32_t mask)
138 138 {
139 139 ((zfs_oldace_t *)acep)->z_access_mask = mask;
140 140 }
141 141
142 142 static void
143 143 zfs_ace_v0_set_who(void *acep, uint64_t who)
144 144 {
145 145 ((zfs_oldace_t *)acep)->z_fuid = who;
146 146 }
147 147
148 148 /*ARGSUSED*/
149 149 static size_t
150 150 zfs_ace_v0_size(void *acep)
151 151 {
152 152 return (sizeof (zfs_oldace_t));
153 153 }
154 154
155 155 static size_t
156 156 zfs_ace_v0_abstract_size(void)
157 157 {
158 158 return (sizeof (zfs_oldace_t));
159 159 }
160 160
161 161 static int
162 162 zfs_ace_v0_mask_off(void)
163 163 {
164 164 return (offsetof(zfs_oldace_t, z_access_mask));
165 165 }
166 166
167 167 /*ARGSUSED*/
168 168 static int
169 169 zfs_ace_v0_data(void *acep, void **datap)
170 170 {
171 171 *datap = NULL;
172 172 return (0);
173 173 }
174 174
175 175 static acl_ops_t zfs_acl_v0_ops = {
176 176 zfs_ace_v0_get_mask,
177 177 zfs_ace_v0_set_mask,
178 178 zfs_ace_v0_get_flags,
179 179 zfs_ace_v0_set_flags,
180 180 zfs_ace_v0_get_type,
181 181 zfs_ace_v0_set_type,
182 182 zfs_ace_v0_get_who,
183 183 zfs_ace_v0_set_who,
184 184 zfs_ace_v0_size,
185 185 zfs_ace_v0_abstract_size,
186 186 zfs_ace_v0_mask_off,
187 187 zfs_ace_v0_data
188 188 };
189 189
190 190 static uint16_t
191 191 zfs_ace_fuid_get_type(void *acep)
192 192 {
193 193 return (((zfs_ace_hdr_t *)acep)->z_type);
194 194 }
195 195
196 196 static uint16_t
197 197 zfs_ace_fuid_get_flags(void *acep)
198 198 {
199 199 return (((zfs_ace_hdr_t *)acep)->z_flags);
200 200 }
201 201
202 202 static uint32_t
203 203 zfs_ace_fuid_get_mask(void *acep)
204 204 {
205 205 return (((zfs_ace_hdr_t *)acep)->z_access_mask);
206 206 }
207 207
208 208 static uint64_t
209 209 zfs_ace_fuid_get_who(void *args)
210 210 {
211 211 uint16_t entry_type;
212 212 zfs_ace_t *acep = args;
213 213
214 214 entry_type = acep->z_hdr.z_flags & ACE_TYPE_FLAGS;
215 215
216 216 if (entry_type == ACE_OWNER || entry_type == OWNING_GROUP ||
217 217 entry_type == ACE_EVERYONE)
218 218 return (-1);
219 219 return (((zfs_ace_t *)acep)->z_fuid);
220 220 }
221 221
222 222 static void
223 223 zfs_ace_fuid_set_type(void *acep, uint16_t type)
224 224 {
225 225 ((zfs_ace_hdr_t *)acep)->z_type = type;
226 226 }
227 227
228 228 static void
229 229 zfs_ace_fuid_set_flags(void *acep, uint16_t flags)
230 230 {
231 231 ((zfs_ace_hdr_t *)acep)->z_flags = flags;
232 232 }
233 233
234 234 static void
235 235 zfs_ace_fuid_set_mask(void *acep, uint32_t mask)
236 236 {
237 237 ((zfs_ace_hdr_t *)acep)->z_access_mask = mask;
238 238 }
239 239
240 240 static void
241 241 zfs_ace_fuid_set_who(void *arg, uint64_t who)
242 242 {
243 243 zfs_ace_t *acep = arg;
244 244
245 245 uint16_t entry_type = acep->z_hdr.z_flags & ACE_TYPE_FLAGS;
246 246
247 247 if (entry_type == ACE_OWNER || entry_type == OWNING_GROUP ||
248 248 entry_type == ACE_EVERYONE)
249 249 return;
250 250 acep->z_fuid = who;
251 251 }
252 252
253 253 static size_t
254 254 zfs_ace_fuid_size(void *acep)
255 255 {
256 256 zfs_ace_hdr_t *zacep = acep;
257 257 uint16_t entry_type;
258 258
259 259 switch (zacep->z_type) {
260 260 case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
261 261 case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
262 262 case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
263 263 case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
264 264 return (sizeof (zfs_object_ace_t));
265 265 case ALLOW:
266 266 case DENY:
267 267 entry_type =
268 268 (((zfs_ace_hdr_t *)acep)->z_flags & ACE_TYPE_FLAGS);
269 269 if (entry_type == ACE_OWNER ||
270 270 entry_type == OWNING_GROUP ||
271 271 entry_type == ACE_EVERYONE)
272 272 return (sizeof (zfs_ace_hdr_t));
273 273 /*FALLTHROUGH*/
274 274 default:
275 275 return (sizeof (zfs_ace_t));
276 276 }
277 277 }
278 278
279 279 static size_t
280 280 zfs_ace_fuid_abstract_size(void)
281 281 {
282 282 return (sizeof (zfs_ace_hdr_t));
283 283 }
284 284
285 285 static int
286 286 zfs_ace_fuid_mask_off(void)
287 287 {
288 288 return (offsetof(zfs_ace_hdr_t, z_access_mask));
289 289 }
290 290
291 291 static int
292 292 zfs_ace_fuid_data(void *acep, void **datap)
293 293 {
294 294 zfs_ace_t *zacep = acep;
295 295 zfs_object_ace_t *zobjp;
296 296
297 297 switch (zacep->z_hdr.z_type) {
298 298 case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
299 299 case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
300 300 case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
301 301 case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
302 302 zobjp = acep;
303 303 *datap = (caddr_t)zobjp + sizeof (zfs_ace_t);
304 304 return (sizeof (zfs_object_ace_t) - sizeof (zfs_ace_t));
305 305 default:
306 306 *datap = NULL;
307 307 return (0);
308 308 }
309 309 }
310 310
311 311 static acl_ops_t zfs_acl_fuid_ops = {
312 312 zfs_ace_fuid_get_mask,
313 313 zfs_ace_fuid_set_mask,
314 314 zfs_ace_fuid_get_flags,
315 315 zfs_ace_fuid_set_flags,
316 316 zfs_ace_fuid_get_type,
317 317 zfs_ace_fuid_set_type,
318 318 zfs_ace_fuid_get_who,
319 319 zfs_ace_fuid_set_who,
320 320 zfs_ace_fuid_size,
321 321 zfs_ace_fuid_abstract_size,
322 322 zfs_ace_fuid_mask_off,
323 323 zfs_ace_fuid_data
324 324 };
325 325
326 326 /*
327 327 * The following three functions are provided for compatibility with
328 328 * older ZPL version in order to determine if the file use to have
329 329 * an external ACL and what version of ACL previously existed on the
330 330 * file. Would really be nice to not need this, sigh.
331 331 */
332 332 uint64_t
333 333 zfs_external_acl(znode_t *zp)
334 334 {
335 335 zfs_acl_phys_t acl_phys;
336 336 int error;
337 337
338 338 if (zp->z_is_sa)
339 339 return (0);
340 340
341 341 /*
342 342 * Need to deal with a potential
343 343 * race where zfs_sa_upgrade could cause
344 344 * z_isa_sa to change.
345 345 *
346 346 * If the lookup fails then the state of z_is_sa should have
347 347 * changed.
348 348 */
349 349
350 350 if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zp->z_zfsvfs),
351 351 &acl_phys, sizeof (acl_phys))) == 0)
352 352 return (acl_phys.z_acl_extern_obj);
353 353 else {
354 354 /*
355 355 * after upgrade the SA_ZPL_ZNODE_ACL should have been
356 356 * removed
357 357 */
358 358 VERIFY(zp->z_is_sa && error == ENOENT);
359 359 return (0);
360 360 }
361 361 }
362 362
363 363 /*
364 364 * Determine size of ACL in bytes
365 365 *
366 366 * This is more complicated than it should be since we have to deal
367 367 * with old external ACLs.
368 368 */
369 369 static int
370 370 zfs_acl_znode_info(znode_t *zp, int *aclsize, int *aclcount,
371 371 zfs_acl_phys_t *aclphys)
372 372 {
373 373 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
374 374 uint64_t acl_count;
375 375 int size;
376 376 int error;
377 377
378 378 ASSERT(MUTEX_HELD(&zp->z_acl_lock));
379 379 if (zp->z_is_sa) {
380 380 if ((error = sa_size(zp->z_sa_hdl, SA_ZPL_DACL_ACES(zfsvfs),
381 381 &size)) != 0)
382 382 return (error);
383 383 *aclsize = size;
384 384 if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_DACL_COUNT(zfsvfs),
385 385 &acl_count, sizeof (acl_count))) != 0)
386 386 return (error);
387 387 *aclcount = acl_count;
388 388 } else {
389 389 if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zfsvfs),
390 390 aclphys, sizeof (*aclphys))) != 0)
391 391 return (error);
392 392
393 393 if (aclphys->z_acl_version == ZFS_ACL_VERSION_INITIAL) {
394 394 *aclsize = ZFS_ACL_SIZE(aclphys->z_acl_size);
395 395 *aclcount = aclphys->z_acl_size;
396 396 } else {
397 397 *aclsize = aclphys->z_acl_size;
398 398 *aclcount = aclphys->z_acl_count;
399 399 }
400 400 }
401 401 return (0);
402 402 }
403 403
404 404 int
405 405 zfs_znode_acl_version(znode_t *zp)
406 406 {
407 407 zfs_acl_phys_t acl_phys;
408 408
409 409 if (zp->z_is_sa)
410 410 return (ZFS_ACL_VERSION_FUID);
411 411 else {
412 412 int error;
413 413
414 414 /*
415 415 * Need to deal with a potential
416 416 * race where zfs_sa_upgrade could cause
417 417 * z_isa_sa to change.
418 418 *
419 419 * If the lookup fails then the state of z_is_sa should have
420 420 * changed.
421 421 */
422 422 if ((error = sa_lookup(zp->z_sa_hdl,
423 423 SA_ZPL_ZNODE_ACL(zp->z_zfsvfs),
424 424 &acl_phys, sizeof (acl_phys))) == 0)
425 425 return (acl_phys.z_acl_version);
426 426 else {
427 427 /*
428 428 * After upgrade SA_ZPL_ZNODE_ACL should have
429 429 * been removed.
430 430 */
431 431 VERIFY(zp->z_is_sa && error == ENOENT);
432 432 return (ZFS_ACL_VERSION_FUID);
433 433 }
434 434 }
435 435 }
436 436
437 437 static int
438 438 zfs_acl_version(int version)
439 439 {
440 440 if (version < ZPL_VERSION_FUID)
441 441 return (ZFS_ACL_VERSION_INITIAL);
442 442 else
443 443 return (ZFS_ACL_VERSION_FUID);
444 444 }
445 445
446 446 static int
447 447 zfs_acl_version_zp(znode_t *zp)
448 448 {
449 449 return (zfs_acl_version(zp->z_zfsvfs->z_version));
450 450 }
451 451
452 452 zfs_acl_t *
453 453 zfs_acl_alloc(int vers)
454 454 {
455 455 zfs_acl_t *aclp;
456 456
457 457 aclp = kmem_zalloc(sizeof (zfs_acl_t), KM_SLEEP);
458 458 list_create(&aclp->z_acl, sizeof (zfs_acl_node_t),
459 459 offsetof(zfs_acl_node_t, z_next));
460 460 aclp->z_version = vers;
461 461 if (vers == ZFS_ACL_VERSION_FUID)
462 462 aclp->z_ops = zfs_acl_fuid_ops;
463 463 else
464 464 aclp->z_ops = zfs_acl_v0_ops;
465 465 return (aclp);
466 466 }
467 467
468 468 zfs_acl_node_t *
469 469 zfs_acl_node_alloc(size_t bytes)
470 470 {
471 471 zfs_acl_node_t *aclnode;
472 472
473 473 aclnode = kmem_zalloc(sizeof (zfs_acl_node_t), KM_SLEEP);
474 474 if (bytes) {
475 475 aclnode->z_acldata = kmem_alloc(bytes, KM_SLEEP);
476 476 aclnode->z_allocdata = aclnode->z_acldata;
477 477 aclnode->z_allocsize = bytes;
478 478 aclnode->z_size = bytes;
479 479 }
480 480
481 481 return (aclnode);
482 482 }
483 483
484 484 static void
485 485 zfs_acl_node_free(zfs_acl_node_t *aclnode)
486 486 {
487 487 if (aclnode->z_allocsize)
488 488 kmem_free(aclnode->z_allocdata, aclnode->z_allocsize);
489 489 kmem_free(aclnode, sizeof (zfs_acl_node_t));
490 490 }
491 491
492 492 static void
493 493 zfs_acl_release_nodes(zfs_acl_t *aclp)
494 494 {
495 495 zfs_acl_node_t *aclnode;
496 496
497 497 while (aclnode = list_head(&aclp->z_acl)) {
498 498 list_remove(&aclp->z_acl, aclnode);
499 499 zfs_acl_node_free(aclnode);
500 500 }
501 501 aclp->z_acl_count = 0;
502 502 aclp->z_acl_bytes = 0;
503 503 }
504 504
505 505 void
506 506 zfs_acl_free(zfs_acl_t *aclp)
507 507 {
508 508 zfs_acl_release_nodes(aclp);
509 509 list_destroy(&aclp->z_acl);
510 510 kmem_free(aclp, sizeof (zfs_acl_t));
511 511 }
512 512
513 513 static boolean_t
514 514 zfs_acl_valid_ace_type(uint_t type, uint_t flags)
515 515 {
516 516 uint16_t entry_type;
517 517
518 518 switch (type) {
519 519 case ALLOW:
520 520 case DENY:
521 521 case ACE_SYSTEM_AUDIT_ACE_TYPE:
522 522 case ACE_SYSTEM_ALARM_ACE_TYPE:
523 523 entry_type = flags & ACE_TYPE_FLAGS;
524 524 return (entry_type == ACE_OWNER ||
525 525 entry_type == OWNING_GROUP ||
526 526 entry_type == ACE_EVERYONE || entry_type == 0 ||
527 527 entry_type == ACE_IDENTIFIER_GROUP);
528 528 default:
529 529 if (type >= MIN_ACE_TYPE && type <= MAX_ACE_TYPE)
530 530 return (B_TRUE);
531 531 }
532 532 return (B_FALSE);
533 533 }
534 534
535 535 static boolean_t
536 536 zfs_ace_valid(vtype_t obj_type, zfs_acl_t *aclp, uint16_t type, uint16_t iflags)
537 537 {
538 538 /*
539 539 * first check type of entry
540 540 */
541 541
542 542 if (!zfs_acl_valid_ace_type(type, iflags))
543 543 return (B_FALSE);
544 544
545 545 switch (type) {
546 546 case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
547 547 case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
548 548 case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
549 549 case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
550 550 if (aclp->z_version < ZFS_ACL_VERSION_FUID)
551 551 return (B_FALSE);
552 552 aclp->z_hints |= ZFS_ACL_OBJ_ACE;
553 553 }
554 554
555 555 /*
556 556 * next check inheritance level flags
557 557 */
558 558
559 559 if (obj_type == VDIR &&
560 560 (iflags & (ACE_FILE_INHERIT_ACE|ACE_DIRECTORY_INHERIT_ACE)))
561 561 aclp->z_hints |= ZFS_INHERIT_ACE;
562 562
563 563 if (iflags & (ACE_INHERIT_ONLY_ACE|ACE_NO_PROPAGATE_INHERIT_ACE)) {
564 564 if ((iflags & (ACE_FILE_INHERIT_ACE|
565 565 ACE_DIRECTORY_INHERIT_ACE)) == 0) {
566 566 return (B_FALSE);
567 567 }
568 568 }
569 569
570 570 return (B_TRUE);
571 571 }
572 572
573 573 static void *
574 574 zfs_acl_next_ace(zfs_acl_t *aclp, void *start, uint64_t *who,
575 575 uint32_t *access_mask, uint16_t *iflags, uint16_t *type)
576 576 {
577 577 zfs_acl_node_t *aclnode;
578 578
579 579 ASSERT(aclp);
580 580
581 581 if (start == NULL) {
582 582 aclnode = list_head(&aclp->z_acl);
583 583 if (aclnode == NULL)
584 584 return (NULL);
585 585
586 586 aclp->z_next_ace = aclnode->z_acldata;
587 587 aclp->z_curr_node = aclnode;
588 588 aclnode->z_ace_idx = 0;
589 589 }
590 590
591 591 aclnode = aclp->z_curr_node;
592 592
593 593 if (aclnode == NULL)
594 594 return (NULL);
595 595
596 596 if (aclnode->z_ace_idx >= aclnode->z_ace_count) {
597 597 aclnode = list_next(&aclp->z_acl, aclnode);
598 598 if (aclnode == NULL)
599 599 return (NULL);
600 600 else {
601 601 aclp->z_curr_node = aclnode;
602 602 aclnode->z_ace_idx = 0;
603 603 aclp->z_next_ace = aclnode->z_acldata;
604 604 }
605 605 }
606 606
607 607 if (aclnode->z_ace_idx < aclnode->z_ace_count) {
608 608 void *acep = aclp->z_next_ace;
609 609 size_t ace_size;
610 610
611 611 /*
612 612 * Make sure we don't overstep our bounds
613 613 */
614 614 ace_size = aclp->z_ops.ace_size(acep);
615 615
616 616 if (((caddr_t)acep + ace_size) >
617 617 ((caddr_t)aclnode->z_acldata + aclnode->z_size)) {
618 618 return (NULL);
619 619 }
620 620
621 621 *iflags = aclp->z_ops.ace_flags_get(acep);
622 622 *type = aclp->z_ops.ace_type_get(acep);
623 623 *access_mask = aclp->z_ops.ace_mask_get(acep);
624 624 *who = aclp->z_ops.ace_who_get(acep);
625 625 aclp->z_next_ace = (caddr_t)aclp->z_next_ace + ace_size;
626 626 aclnode->z_ace_idx++;
627 627
628 628 return ((void *)acep);
629 629 }
630 630 return (NULL);
631 631 }
632 632
633 633 /*ARGSUSED*/
634 634 static uint64_t
635 635 zfs_ace_walk(void *datap, uint64_t cookie, int aclcnt,
636 636 uint16_t *flags, uint16_t *type, uint32_t *mask)
637 637 {
638 638 zfs_acl_t *aclp = datap;
639 639 zfs_ace_hdr_t *acep = (zfs_ace_hdr_t *)(uintptr_t)cookie;
640 640 uint64_t who;
641 641
642 642 acep = zfs_acl_next_ace(aclp, acep, &who, mask,
643 643 flags, type);
644 644 return ((uint64_t)(uintptr_t)acep);
645 645 }
646 646
647 647 static zfs_acl_node_t *
648 648 zfs_acl_curr_node(zfs_acl_t *aclp)
649 649 {
650 650 ASSERT(aclp->z_curr_node);
651 651 return (aclp->z_curr_node);
652 652 }
653 653
654 654 /*
655 655 * Copy ACE to internal ZFS format.
656 656 * While processing the ACL each ACE will be validated for correctness.
657 657 * ACE FUIDs will be created later.
658 658 */
659 659 int
660 660 zfs_copy_ace_2_fuid(zfsvfs_t *zfsvfs, vtype_t obj_type, zfs_acl_t *aclp,
661 661 void *datap, zfs_ace_t *z_acl, uint64_t aclcnt, size_t *size,
662 662 zfs_fuid_info_t **fuidp, cred_t *cr)
663 663 {
664 664 int i;
665 665 uint16_t entry_type;
666 666 zfs_ace_t *aceptr = z_acl;
667 667 ace_t *acep = datap;
668 668 zfs_object_ace_t *zobjacep;
669 669 ace_object_t *aceobjp;
670 670
671 671 for (i = 0; i != aclcnt; i++) {
672 672 aceptr->z_hdr.z_access_mask = acep->a_access_mask;
673 673 aceptr->z_hdr.z_flags = acep->a_flags;
674 674 aceptr->z_hdr.z_type = acep->a_type;
675 675 entry_type = aceptr->z_hdr.z_flags & ACE_TYPE_FLAGS;
676 676 if (entry_type != ACE_OWNER && entry_type != OWNING_GROUP &&
677 677 entry_type != ACE_EVERYONE) {
678 678 aceptr->z_fuid = zfs_fuid_create(zfsvfs, acep->a_who,
679 679 cr, (entry_type == 0) ?
680 680 ZFS_ACE_USER : ZFS_ACE_GROUP, fuidp);
681 681 }
682 682
683 683 /*
684 684 * Make sure ACE is valid
685 685 */
686 686 if (zfs_ace_valid(obj_type, aclp, aceptr->z_hdr.z_type,
687 687 aceptr->z_hdr.z_flags) != B_TRUE)
688 688 return (SET_ERROR(EINVAL));
689 689
690 690 switch (acep->a_type) {
691 691 case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
692 692 case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
693 693 case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
694 694 case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
695 695 zobjacep = (zfs_object_ace_t *)aceptr;
696 696 aceobjp = (ace_object_t *)acep;
697 697
698 698 bcopy(aceobjp->a_obj_type, zobjacep->z_object_type,
699 699 sizeof (aceobjp->a_obj_type));
700 700 bcopy(aceobjp->a_inherit_obj_type,
701 701 zobjacep->z_inherit_type,
702 702 sizeof (aceobjp->a_inherit_obj_type));
703 703 acep = (ace_t *)((caddr_t)acep + sizeof (ace_object_t));
704 704 break;
705 705 default:
706 706 acep = (ace_t *)((caddr_t)acep + sizeof (ace_t));
707 707 }
708 708
709 709 aceptr = (zfs_ace_t *)((caddr_t)aceptr +
710 710 aclp->z_ops.ace_size(aceptr));
711 711 }
712 712
713 713 *size = (caddr_t)aceptr - (caddr_t)z_acl;
714 714
715 715 return (0);
716 716 }
717 717
718 718 /*
719 719 * Copy ZFS ACEs to fixed size ace_t layout
720 720 */
721 721 static void
722 722 zfs_copy_fuid_2_ace(zfsvfs_t *zfsvfs, zfs_acl_t *aclp, cred_t *cr,
723 723 void *datap, int filter)
724 724 {
725 725 uint64_t who;
726 726 uint32_t access_mask;
727 727 uint16_t iflags, type;
728 728 zfs_ace_hdr_t *zacep = NULL;
729 729 ace_t *acep = datap;
730 730 ace_object_t *objacep;
731 731 zfs_object_ace_t *zobjacep;
732 732 size_t ace_size;
733 733 uint16_t entry_type;
734 734
735 735 while (zacep = zfs_acl_next_ace(aclp, zacep,
736 736 &who, &access_mask, &iflags, &type)) {
737 737
738 738 switch (type) {
739 739 case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
740 740 case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
741 741 case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
742 742 case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
743 743 if (filter) {
744 744 continue;
745 745 }
746 746 zobjacep = (zfs_object_ace_t *)zacep;
747 747 objacep = (ace_object_t *)acep;
748 748 bcopy(zobjacep->z_object_type,
749 749 objacep->a_obj_type,
750 750 sizeof (zobjacep->z_object_type));
751 751 bcopy(zobjacep->z_inherit_type,
752 752 objacep->a_inherit_obj_type,
753 753 sizeof (zobjacep->z_inherit_type));
754 754 ace_size = sizeof (ace_object_t);
755 755 break;
756 756 default:
757 757 ace_size = sizeof (ace_t);
758 758 break;
759 759 }
760 760
761 761 entry_type = (iflags & ACE_TYPE_FLAGS);
762 762 if ((entry_type != ACE_OWNER &&
763 763 entry_type != OWNING_GROUP &&
764 764 entry_type != ACE_EVERYONE)) {
765 765 acep->a_who = zfs_fuid_map_id(zfsvfs, who,
766 766 cr, (entry_type & ACE_IDENTIFIER_GROUP) ?
767 767 ZFS_ACE_GROUP : ZFS_ACE_USER);
768 768 } else {
769 769 acep->a_who = (uid_t)(int64_t)who;
770 770 }
771 771 acep->a_access_mask = access_mask;
772 772 acep->a_flags = iflags;
773 773 acep->a_type = type;
774 774 acep = (ace_t *)((caddr_t)acep + ace_size);
775 775 }
776 776 }
777 777
778 778 static int
779 779 zfs_copy_ace_2_oldace(vtype_t obj_type, zfs_acl_t *aclp, ace_t *acep,
780 780 zfs_oldace_t *z_acl, int aclcnt, size_t *size)
781 781 {
782 782 int i;
783 783 zfs_oldace_t *aceptr = z_acl;
784 784
785 785 for (i = 0; i != aclcnt; i++, aceptr++) {
786 786 aceptr->z_access_mask = acep[i].a_access_mask;
787 787 aceptr->z_type = acep[i].a_type;
788 788 aceptr->z_flags = acep[i].a_flags;
789 789 aceptr->z_fuid = acep[i].a_who;
790 790 /*
791 791 * Make sure ACE is valid
792 792 */
793 793 if (zfs_ace_valid(obj_type, aclp, aceptr->z_type,
794 794 aceptr->z_flags) != B_TRUE)
795 795 return (SET_ERROR(EINVAL));
796 796 }
797 797 *size = (caddr_t)aceptr - (caddr_t)z_acl;
798 798 return (0);
799 799 }
800 800
801 801 /*
802 802 * convert old ACL format to new
803 803 */
804 804 void
805 805 zfs_acl_xform(znode_t *zp, zfs_acl_t *aclp, cred_t *cr)
806 806 {
807 807 zfs_oldace_t *oldaclp;
808 808 int i;
809 809 uint16_t type, iflags;
810 810 uint32_t access_mask;
811 811 uint64_t who;
812 812 void *cookie = NULL;
813 813 zfs_acl_node_t *newaclnode;
814 814
815 815 ASSERT(aclp->z_version == ZFS_ACL_VERSION_INITIAL);
816 816 /*
817 817 * First create the ACE in a contiguous piece of memory
818 818 * for zfs_copy_ace_2_fuid().
819 819 *
820 820 * We only convert an ACL once, so this won't happen
821 821 * everytime.
822 822 */
823 823 oldaclp = kmem_alloc(sizeof (zfs_oldace_t) * aclp->z_acl_count,
824 824 KM_SLEEP);
825 825 i = 0;
826 826 while (cookie = zfs_acl_next_ace(aclp, cookie, &who,
827 827 &access_mask, &iflags, &type)) {
828 828 oldaclp[i].z_flags = iflags;
829 829 oldaclp[i].z_type = type;
830 830 oldaclp[i].z_fuid = who;
831 831 oldaclp[i++].z_access_mask = access_mask;
832 832 }
833 833
834 834 newaclnode = zfs_acl_node_alloc(aclp->z_acl_count *
835 835 sizeof (zfs_object_ace_t));
836 836 aclp->z_ops = zfs_acl_fuid_ops;
837 837 VERIFY(zfs_copy_ace_2_fuid(zp->z_zfsvfs, ZTOV(zp)->v_type, aclp,
838 838 oldaclp, newaclnode->z_acldata, aclp->z_acl_count,
839 839 &newaclnode->z_size, NULL, cr) == 0);
840 840 newaclnode->z_ace_count = aclp->z_acl_count;
841 841 aclp->z_version = ZFS_ACL_VERSION;
842 842 kmem_free(oldaclp, aclp->z_acl_count * sizeof (zfs_oldace_t));
843 843
844 844 /*
845 845 * Release all previous ACL nodes
846 846 */
847 847
848 848 zfs_acl_release_nodes(aclp);
849 849
850 850 list_insert_head(&aclp->z_acl, newaclnode);
851 851
852 852 aclp->z_acl_bytes = newaclnode->z_size;
853 853 aclp->z_acl_count = newaclnode->z_ace_count;
854 854
855 855 }
856 856
857 857 /*
858 858 * Convert unix access mask to v4 access mask
859 859 */
860 860 static uint32_t
861 861 zfs_unix_to_v4(uint32_t access_mask)
862 862 {
863 863 uint32_t new_mask = 0;
864 864
865 865 if (access_mask & S_IXOTH)
866 866 new_mask |= ACE_EXECUTE;
867 867 if (access_mask & S_IWOTH)
868 868 new_mask |= ACE_WRITE_DATA;
869 869 if (access_mask & S_IROTH)
870 870 new_mask |= ACE_READ_DATA;
871 871 return (new_mask);
872 872 }
873 873
874 874 static void
875 875 zfs_set_ace(zfs_acl_t *aclp, void *acep, uint32_t access_mask,
876 876 uint16_t access_type, uint64_t fuid, uint16_t entry_type)
877 877 {
878 878 uint16_t type = entry_type & ACE_TYPE_FLAGS;
879 879
880 880 aclp->z_ops.ace_mask_set(acep, access_mask);
881 881 aclp->z_ops.ace_type_set(acep, access_type);
882 882 aclp->z_ops.ace_flags_set(acep, entry_type);
883 883 if ((type != ACE_OWNER && type != OWNING_GROUP &&
884 884 type != ACE_EVERYONE))
885 885 aclp->z_ops.ace_who_set(acep, fuid);
886 886 }
887 887
888 888 /*
889 889 * Determine mode of file based on ACL.
890 890 * Also, create FUIDs for any User/Group ACEs
891 891 */
892 892 uint64_t
893 893 zfs_mode_compute(uint64_t fmode, zfs_acl_t *aclp,
894 894 uint64_t *pflags, uint64_t fuid, uint64_t fgid)
895 895 {
896 896 int entry_type;
897 897 mode_t mode;
898 898 mode_t seen = 0;
899 899 zfs_ace_hdr_t *acep = NULL;
900 900 uint64_t who;
901 901 uint16_t iflags, type;
902 902 uint32_t access_mask;
903 903 boolean_t an_exec_denied = B_FALSE;
904 904
905 905 mode = (fmode & (S_IFMT | S_ISUID | S_ISGID | S_ISVTX));
906 906
907 907 while (acep = zfs_acl_next_ace(aclp, acep, &who,
908 908 &access_mask, &iflags, &type)) {
909 909
910 910 if (!zfs_acl_valid_ace_type(type, iflags))
911 911 continue;
912 912
913 913 entry_type = (iflags & ACE_TYPE_FLAGS);
914 914
915 915 /*
916 916 * Skip over owner@, group@ or everyone@ inherit only ACEs
917 917 */
918 918 if ((iflags & ACE_INHERIT_ONLY_ACE) &&
919 919 (entry_type == ACE_OWNER || entry_type == ACE_EVERYONE ||
920 920 entry_type == OWNING_GROUP))
921 921 continue;
922 922
923 923 if (entry_type == ACE_OWNER || (entry_type == 0 &&
924 924 who == fuid)) {
925 925 if ((access_mask & ACE_READ_DATA) &&
926 926 (!(seen & S_IRUSR))) {
927 927 seen |= S_IRUSR;
928 928 if (type == ALLOW) {
929 929 mode |= S_IRUSR;
930 930 }
931 931 }
932 932 if ((access_mask & ACE_WRITE_DATA) &&
933 933 (!(seen & S_IWUSR))) {
934 934 seen |= S_IWUSR;
935 935 if (type == ALLOW) {
936 936 mode |= S_IWUSR;
937 937 }
938 938 }
939 939 if ((access_mask & ACE_EXECUTE) &&
940 940 (!(seen & S_IXUSR))) {
941 941 seen |= S_IXUSR;
942 942 if (type == ALLOW) {
943 943 mode |= S_IXUSR;
944 944 }
945 945 }
946 946 } else if (entry_type == OWNING_GROUP ||
947 947 (entry_type == ACE_IDENTIFIER_GROUP && who == fgid)) {
948 948 if ((access_mask & ACE_READ_DATA) &&
949 949 (!(seen & S_IRGRP))) {
950 950 seen |= S_IRGRP;
951 951 if (type == ALLOW) {
952 952 mode |= S_IRGRP;
953 953 }
954 954 }
955 955 if ((access_mask & ACE_WRITE_DATA) &&
956 956 (!(seen & S_IWGRP))) {
957 957 seen |= S_IWGRP;
958 958 if (type == ALLOW) {
959 959 mode |= S_IWGRP;
960 960 }
961 961 }
962 962 if ((access_mask & ACE_EXECUTE) &&
963 963 (!(seen & S_IXGRP))) {
964 964 seen |= S_IXGRP;
965 965 if (type == ALLOW) {
966 966 mode |= S_IXGRP;
967 967 }
968 968 }
969 969 } else if (entry_type == ACE_EVERYONE) {
970 970 if ((access_mask & ACE_READ_DATA)) {
971 971 if (!(seen & S_IRUSR)) {
972 972 seen |= S_IRUSR;
973 973 if (type == ALLOW) {
974 974 mode |= S_IRUSR;
975 975 }
976 976 }
977 977 if (!(seen & S_IRGRP)) {
978 978 seen |= S_IRGRP;
979 979 if (type == ALLOW) {
980 980 mode |= S_IRGRP;
981 981 }
982 982 }
983 983 if (!(seen & S_IROTH)) {
984 984 seen |= S_IROTH;
985 985 if (type == ALLOW) {
986 986 mode |= S_IROTH;
987 987 }
988 988 }
989 989 }
990 990 if ((access_mask & ACE_WRITE_DATA)) {
991 991 if (!(seen & S_IWUSR)) {
992 992 seen |= S_IWUSR;
993 993 if (type == ALLOW) {
994 994 mode |= S_IWUSR;
995 995 }
996 996 }
997 997 if (!(seen & S_IWGRP)) {
998 998 seen |= S_IWGRP;
999 999 if (type == ALLOW) {
1000 1000 mode |= S_IWGRP;
1001 1001 }
1002 1002 }
1003 1003 if (!(seen & S_IWOTH)) {
1004 1004 seen |= S_IWOTH;
1005 1005 if (type == ALLOW) {
1006 1006 mode |= S_IWOTH;
1007 1007 }
1008 1008 }
1009 1009 }
1010 1010 if ((access_mask & ACE_EXECUTE)) {
1011 1011 if (!(seen & S_IXUSR)) {
1012 1012 seen |= S_IXUSR;
1013 1013 if (type == ALLOW) {
1014 1014 mode |= S_IXUSR;
1015 1015 }
1016 1016 }
1017 1017 if (!(seen & S_IXGRP)) {
1018 1018 seen |= S_IXGRP;
1019 1019 if (type == ALLOW) {
1020 1020 mode |= S_IXGRP;
1021 1021 }
1022 1022 }
1023 1023 if (!(seen & S_IXOTH)) {
1024 1024 seen |= S_IXOTH;
1025 1025 if (type == ALLOW) {
1026 1026 mode |= S_IXOTH;
1027 1027 }
1028 1028 }
1029 1029 }
1030 1030 } else {
1031 1031 /*
1032 1032 * Only care if this IDENTIFIER_GROUP or
1033 1033 * USER ACE denies execute access to someone,
1034 1034 * mode is not affected
1035 1035 */
1036 1036 if ((access_mask & ACE_EXECUTE) && type == DENY)
1037 1037 an_exec_denied = B_TRUE;
1038 1038 }
1039 1039 }
1040 1040
1041 1041 /*
1042 1042 * Failure to allow is effectively a deny, so execute permission
1043 1043 * is denied if it was never mentioned or if we explicitly
1044 1044 * weren't allowed it.
1045 1045 */
1046 1046 if (!an_exec_denied &&
1047 1047 ((seen & ALL_MODE_EXECS) != ALL_MODE_EXECS ||
1048 1048 (mode & ALL_MODE_EXECS) != ALL_MODE_EXECS))
1049 1049 an_exec_denied = B_TRUE;
1050 1050
1051 1051 if (an_exec_denied)
1052 1052 *pflags &= ~ZFS_NO_EXECS_DENIED;
1053 1053 else
1054 1054 *pflags |= ZFS_NO_EXECS_DENIED;
1055 1055
1056 1056 return (mode);
1057 1057 }
1058 1058
1059 1059 /*
1060 1060 * Read an external acl object. If the intent is to modify, always
1061 1061 * create a new acl and leave any cached acl in place.
1062 1062 */
1063 1063 static int
1064 1064 zfs_acl_node_read(znode_t *zp, boolean_t have_lock, zfs_acl_t **aclpp,
1065 1065 boolean_t will_modify)
1066 1066 {
1067 1067 zfs_acl_t *aclp;
1068 1068 int aclsize;
1069 1069 int acl_count;
1070 1070 zfs_acl_node_t *aclnode;
1071 1071 zfs_acl_phys_t znode_acl;
1072 1072 int version;
1073 1073 int error;
1074 1074 boolean_t drop_lock = B_FALSE;
1075 1075
1076 1076 ASSERT(MUTEX_HELD(&zp->z_acl_lock));
1077 1077
1078 1078 if (zp->z_acl_cached && !will_modify) {
1079 1079 *aclpp = zp->z_acl_cached;
1080 1080 return (0);
1081 1081 }
1082 1082
1083 1083 /*
1084 1084 * close race where znode could be upgrade while trying to
1085 1085 * read the znode attributes.
1086 1086 *
1087 1087 * But this could only happen if the file isn't already an SA
1088 1088 * znode
1089 1089 */
1090 1090 if (!zp->z_is_sa && !have_lock) {
1091 1091 mutex_enter(&zp->z_lock);
1092 1092 drop_lock = B_TRUE;
1093 1093 }
1094 1094 version = zfs_znode_acl_version(zp);
1095 1095
1096 1096 if ((error = zfs_acl_znode_info(zp, &aclsize,
1097 1097 &acl_count, &znode_acl)) != 0) {
1098 1098 goto done;
1099 1099 }
1100 1100
1101 1101 aclp = zfs_acl_alloc(version);
1102 1102
1103 1103 aclp->z_acl_count = acl_count;
1104 1104 aclp->z_acl_bytes = aclsize;
1105 1105
1106 1106 aclnode = zfs_acl_node_alloc(aclsize);
1107 1107 aclnode->z_ace_count = aclp->z_acl_count;
1108 1108 aclnode->z_size = aclsize;
1109 1109
1110 1110 if (!zp->z_is_sa) {
1111 1111 if (znode_acl.z_acl_extern_obj) {
1112 1112 error = dmu_read(zp->z_zfsvfs->z_os,
1113 1113 znode_acl.z_acl_extern_obj, 0, aclnode->z_size,
1114 1114 aclnode->z_acldata, DMU_READ_PREFETCH);
1115 1115 } else {
1116 1116 bcopy(znode_acl.z_ace_data, aclnode->z_acldata,
1117 1117 aclnode->z_size);
1118 1118 }
1119 1119 } else {
1120 1120 error = sa_lookup(zp->z_sa_hdl, SA_ZPL_DACL_ACES(zp->z_zfsvfs),
1121 1121 aclnode->z_acldata, aclnode->z_size);
1122 1122 }
1123 1123
1124 1124 if (error != 0) {
1125 1125 zfs_acl_free(aclp);
1126 1126 zfs_acl_node_free(aclnode);
1127 1127 /* convert checksum errors into IO errors */
1128 1128 if (error == ECKSUM)
1129 1129 error = SET_ERROR(EIO);
1130 1130 goto done;
1131 1131 }
1132 1132
1133 1133 list_insert_head(&aclp->z_acl, aclnode);
1134 1134
1135 1135 *aclpp = aclp;
1136 1136 if (!will_modify)
1137 1137 zp->z_acl_cached = aclp;
1138 1138 done:
1139 1139 if (drop_lock)
1140 1140 mutex_exit(&zp->z_lock);
1141 1141 return (error);
1142 1142 }
1143 1143
1144 1144 /*ARGSUSED*/
1145 1145 void
1146 1146 zfs_acl_data_locator(void **dataptr, uint32_t *length, uint32_t buflen,
1147 1147 boolean_t start, void *userdata)
1148 1148 {
1149 1149 zfs_acl_locator_cb_t *cb = (zfs_acl_locator_cb_t *)userdata;
1150 1150
1151 1151 if (start) {
1152 1152 cb->cb_acl_node = list_head(&cb->cb_aclp->z_acl);
1153 1153 } else {
1154 1154 cb->cb_acl_node = list_next(&cb->cb_aclp->z_acl,
1155 1155 cb->cb_acl_node);
1156 1156 }
1157 1157 *dataptr = cb->cb_acl_node->z_acldata;
1158 1158 *length = cb->cb_acl_node->z_size;
1159 1159 }
1160 1160
1161 1161 int
1162 1162 zfs_acl_chown_setattr(znode_t *zp)
1163 1163 {
1164 1164 int error;
1165 1165 zfs_acl_t *aclp;
1166 1166
1167 1167 ASSERT(MUTEX_HELD(&zp->z_lock));
1168 1168 ASSERT(MUTEX_HELD(&zp->z_acl_lock));
1169 1169
1170 1170 if ((error = zfs_acl_node_read(zp, B_TRUE, &aclp, B_FALSE)) == 0)
1171 1171 zp->z_mode = zfs_mode_compute(zp->z_mode, aclp,
1172 1172 &zp->z_pflags, zp->z_uid, zp->z_gid);
1173 1173 return (error);
1174 1174 }
1175 1175
1176 1176 /*
1177 1177 * common code for setting ACLs.
1178 1178 *
1179 1179 * This function is called from zfs_mode_update, zfs_perm_init, and zfs_setacl.
1180 1180 * zfs_setacl passes a non-NULL inherit pointer (ihp) to indicate that it's
1181 1181 * already checked the acl and knows whether to inherit.
1182 1182 */
1183 1183 int
1184 1184 zfs_aclset_common(znode_t *zp, zfs_acl_t *aclp, cred_t *cr, dmu_tx_t *tx)
1185 1185 {
1186 1186 int error;
1187 1187 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1188 1188 dmu_object_type_t otype;
1189 1189 zfs_acl_locator_cb_t locate = { 0 };
1190 1190 uint64_t mode;
1191 1191 sa_bulk_attr_t bulk[5];
1192 1192 uint64_t ctime[2];
1193 1193 int count = 0;
1194 1194
1195 1195 mode = zp->z_mode;
1196 1196
1197 1197 mode = zfs_mode_compute(mode, aclp, &zp->z_pflags,
1198 1198 zp->z_uid, zp->z_gid);
1199 1199
1200 1200 zp->z_mode = mode;
1201 1201 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs), NULL,
1202 1202 &mode, sizeof (mode));
1203 1203 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
1204 1204 &zp->z_pflags, sizeof (zp->z_pflags));
1205 1205 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL,
1206 1206 &ctime, sizeof (ctime));
1207 1207
1208 1208 if (zp->z_acl_cached) {
1209 1209 zfs_acl_free(zp->z_acl_cached);
1210 1210 zp->z_acl_cached = NULL;
1211 1211 }
1212 1212
1213 1213 /*
1214 1214 * Upgrade needed?
1215 1215 */
1216 1216 if (!zfsvfs->z_use_fuids) {
1217 1217 otype = DMU_OT_OLDACL;
1218 1218 } else {
1219 1219 if ((aclp->z_version == ZFS_ACL_VERSION_INITIAL) &&
1220 1220 (zfsvfs->z_version >= ZPL_VERSION_FUID))
1221 1221 zfs_acl_xform(zp, aclp, cr);
1222 1222 ASSERT(aclp->z_version >= ZFS_ACL_VERSION_FUID);
1223 1223 otype = DMU_OT_ACL;
1224 1224 }
1225 1225
1226 1226 /*
1227 1227 * Arrgh, we have to handle old on disk format
1228 1228 * as well as newer (preferred) SA format.
1229 1229 */
1230 1230
1231 1231 if (zp->z_is_sa) { /* the easy case, just update the ACL attribute */
1232 1232 locate.cb_aclp = aclp;
1233 1233 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_DACL_ACES(zfsvfs),
1234 1234 zfs_acl_data_locator, &locate, aclp->z_acl_bytes);
1235 1235 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_DACL_COUNT(zfsvfs),
1236 1236 NULL, &aclp->z_acl_count, sizeof (uint64_t));
1237 1237 } else { /* Painful legacy way */
1238 1238 zfs_acl_node_t *aclnode;
1239 1239 uint64_t off = 0;
1240 1240 zfs_acl_phys_t acl_phys;
1241 1241 uint64_t aoid;
1242 1242
1243 1243 if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_ZNODE_ACL(zfsvfs),
1244 1244 &acl_phys, sizeof (acl_phys))) != 0)
1245 1245 return (error);
1246 1246
1247 1247 aoid = acl_phys.z_acl_extern_obj;
1248 1248
1249 1249 if (aclp->z_acl_bytes > ZFS_ACE_SPACE) {
1250 1250 /*
1251 1251 * If ACL was previously external and we are now
1252 1252 * converting to new ACL format then release old
1253 1253 * ACL object and create a new one.
1254 1254 */
1255 1255 if (aoid &&
1256 1256 aclp->z_version != acl_phys.z_acl_version) {
1257 1257 error = dmu_object_free(zfsvfs->z_os, aoid, tx);
1258 1258 if (error)
1259 1259 return (error);
1260 1260 aoid = 0;
1261 1261 }
1262 1262 if (aoid == 0) {
1263 1263 aoid = dmu_object_alloc(zfsvfs->z_os,
1264 1264 otype, aclp->z_acl_bytes,
1265 1265 otype == DMU_OT_ACL ?
1266 1266 DMU_OT_SYSACL : DMU_OT_NONE,
1267 1267 otype == DMU_OT_ACL ?
1268 1268 DN_MAX_BONUSLEN : 0, tx);
1269 1269 } else {
1270 1270 (void) dmu_object_set_blocksize(zfsvfs->z_os,
1271 1271 aoid, aclp->z_acl_bytes, 0, tx);
1272 1272 }
1273 1273 acl_phys.z_acl_extern_obj = aoid;
1274 1274 for (aclnode = list_head(&aclp->z_acl); aclnode;
1275 1275 aclnode = list_next(&aclp->z_acl, aclnode)) {
1276 1276 if (aclnode->z_ace_count == 0)
1277 1277 continue;
1278 1278 dmu_write(zfsvfs->z_os, aoid, off,
1279 1279 aclnode->z_size, aclnode->z_acldata, tx);
1280 1280 off += aclnode->z_size;
1281 1281 }
1282 1282 } else {
1283 1283 void *start = acl_phys.z_ace_data;
1284 1284 /*
1285 1285 * Migrating back embedded?
1286 1286 */
1287 1287 if (acl_phys.z_acl_extern_obj) {
1288 1288 error = dmu_object_free(zfsvfs->z_os,
1289 1289 acl_phys.z_acl_extern_obj, tx);
1290 1290 if (error)
1291 1291 return (error);
1292 1292 acl_phys.z_acl_extern_obj = 0;
1293 1293 }
1294 1294
1295 1295 for (aclnode = list_head(&aclp->z_acl); aclnode;
1296 1296 aclnode = list_next(&aclp->z_acl, aclnode)) {
1297 1297 if (aclnode->z_ace_count == 0)
1298 1298 continue;
1299 1299 bcopy(aclnode->z_acldata, start,
1300 1300 aclnode->z_size);
1301 1301 start = (caddr_t)start + aclnode->z_size;
1302 1302 }
1303 1303 }
1304 1304 /*
1305 1305 * If Old version then swap count/bytes to match old
1306 1306 * layout of znode_acl_phys_t.
1307 1307 */
1308 1308 if (aclp->z_version == ZFS_ACL_VERSION_INITIAL) {
1309 1309 acl_phys.z_acl_size = aclp->z_acl_count;
1310 1310 acl_phys.z_acl_count = aclp->z_acl_bytes;
1311 1311 } else {
1312 1312 acl_phys.z_acl_size = aclp->z_acl_bytes;
1313 1313 acl_phys.z_acl_count = aclp->z_acl_count;
1314 1314 }
1315 1315 acl_phys.z_acl_version = aclp->z_version;
1316 1316
1317 1317 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ZNODE_ACL(zfsvfs), NULL,
1318 1318 &acl_phys, sizeof (acl_phys));
1319 1319 }
1320 1320
1321 1321 /*
1322 1322 * Replace ACL wide bits, but first clear them.
1323 1323 */
1324 1324 zp->z_pflags &= ~ZFS_ACL_WIDE_FLAGS;
1325 1325
1326 1326 zp->z_pflags |= aclp->z_hints;
1327 1327
1328 1328 if (ace_trivial_common(aclp, 0, zfs_ace_walk) == 0)
1329 1329 zp->z_pflags |= ZFS_ACL_TRIVIAL;
1330 1330
1331 1331 zfs_tstamp_update_setup(zp, STATE_CHANGED, NULL, ctime, B_TRUE);
1332 1332 return (sa_bulk_update(zp->z_sa_hdl, bulk, count, tx));
1333 1333 }
1334 1334
1335 1335 static void
1336 1336 zfs_acl_chmod(vtype_t vtype, uint64_t mode, boolean_t trim, zfs_acl_t *aclp)
1337 1337 {
1338 1338 void *acep = NULL;
1339 1339 uint64_t who;
1340 1340 int new_count, new_bytes;
1341 1341 int ace_size;
1342 1342 int entry_type;
1343 1343 uint16_t iflags, type;
1344 1344 uint32_t access_mask;
1345 1345 zfs_acl_node_t *newnode;
1346 1346 size_t abstract_size = aclp->z_ops.ace_abstract_size();
1347 1347 void *zacep;
1348 1348 boolean_t isdir;
1349 1349 trivial_acl_t masks;
1350 1350
1351 1351 new_count = new_bytes = 0;
1352 1352
1353 1353 isdir = (vtype == VDIR);
1354 1354
↓ open down ↓ |
1354 lines elided |
↑ open up ↑ |
1355 1355 acl_trivial_access_masks((mode_t)mode, isdir, &masks);
1356 1356
1357 1357 newnode = zfs_acl_node_alloc((abstract_size * 6) + aclp->z_acl_bytes);
1358 1358
1359 1359 zacep = newnode->z_acldata;
1360 1360 if (masks.allow0) {
1361 1361 zfs_set_ace(aclp, zacep, masks.allow0, ALLOW, -1, ACE_OWNER);
1362 1362 zacep = (void *)((uintptr_t)zacep + abstract_size);
1363 1363 new_count++;
1364 1364 new_bytes += abstract_size;
1365 - } if (masks.deny1) {
1365 + }
1366 + if (masks.deny1) {
1366 1367 zfs_set_ace(aclp, zacep, masks.deny1, DENY, -1, ACE_OWNER);
1367 1368 zacep = (void *)((uintptr_t)zacep + abstract_size);
1368 1369 new_count++;
1369 1370 new_bytes += abstract_size;
1370 1371 }
1371 1372 if (masks.deny2) {
1372 1373 zfs_set_ace(aclp, zacep, masks.deny2, DENY, -1, OWNING_GROUP);
1373 1374 zacep = (void *)((uintptr_t)zacep + abstract_size);
1374 1375 new_count++;
1375 1376 new_bytes += abstract_size;
1376 1377 }
1377 1378
1378 1379 while (acep = zfs_acl_next_ace(aclp, acep, &who, &access_mask,
1379 1380 &iflags, &type)) {
1380 1381 uint16_t inherit_flags;
1381 1382
1382 1383 entry_type = (iflags & ACE_TYPE_FLAGS);
1383 1384 inherit_flags = (iflags & ALL_INHERIT);
1384 1385
1385 1386 if ((entry_type == ACE_OWNER || entry_type == ACE_EVERYONE ||
1386 1387 (entry_type == OWNING_GROUP)) &&
1387 1388 ((inherit_flags & ACE_INHERIT_ONLY_ACE) == 0)) {
1388 1389 continue;
1389 1390 }
1390 1391
1391 1392 /*
1392 1393 * If this ACL has any inheritable ACEs, mark that in
1393 1394 * the hints (which are later masked into the pflags)
1394 1395 * so create knows to do inheritance.
1395 1396 */
1396 1397 if (isdir && (inherit_flags &
1397 1398 (ACE_FILE_INHERIT_ACE|ACE_DIRECTORY_INHERIT_ACE)))
1398 1399 aclp->z_hints |= ZFS_INHERIT_ACE;
1399 1400
1400 1401 if ((type != ALLOW && type != DENY) ||
1401 1402 (inherit_flags & ACE_INHERIT_ONLY_ACE)) {
1402 1403 switch (type) {
1403 1404 case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
1404 1405 case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
1405 1406 case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
1406 1407 case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
1407 1408 aclp->z_hints |= ZFS_ACL_OBJ_ACE;
1408 1409 break;
1409 1410 }
1410 1411 } else {
1411 1412
1412 1413 /*
1413 1414 * Limit permissions to be no greater than
1414 1415 * group permissions.
1415 1416 * The "aclinherit" and "aclmode" properties
1416 1417 * affect policy for create and chmod(2),
1417 1418 * respectively.
1418 1419 */
1419 1420 if ((type == ALLOW) && trim)
1420 1421 access_mask &= masks.group;
1421 1422 }
1422 1423 zfs_set_ace(aclp, zacep, access_mask, type, who, iflags);
1423 1424 ace_size = aclp->z_ops.ace_size(acep);
1424 1425 zacep = (void *)((uintptr_t)zacep + ace_size);
1425 1426 new_count++;
1426 1427 new_bytes += ace_size;
1427 1428 }
1428 1429 zfs_set_ace(aclp, zacep, masks.owner, 0, -1, ACE_OWNER);
1429 1430 zacep = (void *)((uintptr_t)zacep + abstract_size);
1430 1431 zfs_set_ace(aclp, zacep, masks.group, 0, -1, OWNING_GROUP);
1431 1432 zacep = (void *)((uintptr_t)zacep + abstract_size);
1432 1433 zfs_set_ace(aclp, zacep, masks.everyone, 0, -1, ACE_EVERYONE);
1433 1434
1434 1435 new_count += 3;
1435 1436 new_bytes += abstract_size * 3;
1436 1437 zfs_acl_release_nodes(aclp);
1437 1438 aclp->z_acl_count = new_count;
1438 1439 aclp->z_acl_bytes = new_bytes;
1439 1440 newnode->z_ace_count = new_count;
1440 1441 newnode->z_size = new_bytes;
1441 1442 list_insert_tail(&aclp->z_acl, newnode);
1442 1443 }
1443 1444
1444 1445 int
1445 1446 zfs_acl_chmod_setattr(znode_t *zp, zfs_acl_t **aclp, uint64_t mode)
1446 1447 {
1447 1448 int error = 0;
1448 1449
1449 1450 mutex_enter(&zp->z_acl_lock);
1450 1451 mutex_enter(&zp->z_lock);
1451 1452 if (zp->z_zfsvfs->z_acl_mode == ZFS_ACL_DISCARD)
1452 1453 *aclp = zfs_acl_alloc(zfs_acl_version_zp(zp));
1453 1454 else
1454 1455 error = zfs_acl_node_read(zp, B_TRUE, aclp, B_TRUE);
1455 1456
1456 1457 if (error == 0) {
1457 1458 (*aclp)->z_hints = zp->z_pflags & V4_ACL_WIDE_FLAGS;
1458 1459 zfs_acl_chmod(ZTOV(zp)->v_type, mode,
1459 1460 (zp->z_zfsvfs->z_acl_mode == ZFS_ACL_GROUPMASK), *aclp);
1460 1461 }
1461 1462 mutex_exit(&zp->z_lock);
1462 1463 mutex_exit(&zp->z_acl_lock);
1463 1464
1464 1465 return (error);
1465 1466 }
1466 1467
1467 1468 /*
1468 1469 * strip off write_owner and write_acl
1469 1470 */
1470 1471 static void
1471 1472 zfs_restricted_update(zfsvfs_t *zfsvfs, zfs_acl_t *aclp, void *acep)
1472 1473 {
1473 1474 uint32_t mask = aclp->z_ops.ace_mask_get(acep);
1474 1475
1475 1476 if ((zfsvfs->z_acl_inherit == ZFS_ACL_RESTRICTED) &&
1476 1477 (aclp->z_ops.ace_type_get(acep) == ALLOW)) {
1477 1478 mask &= ~RESTRICTED_CLEAR;
1478 1479 aclp->z_ops.ace_mask_set(acep, mask);
1479 1480 }
1480 1481 }
1481 1482
1482 1483 /*
1483 1484 * Should ACE be inherited?
1484 1485 */
1485 1486 static int
1486 1487 zfs_ace_can_use(vtype_t vtype, uint16_t acep_flags)
1487 1488 {
1488 1489 int iflags = (acep_flags & 0xf);
1489 1490
1490 1491 if ((vtype == VDIR) && (iflags & ACE_DIRECTORY_INHERIT_ACE))
1491 1492 return (1);
1492 1493 else if (iflags & ACE_FILE_INHERIT_ACE)
1493 1494 return (!((vtype == VDIR) &&
1494 1495 (iflags & ACE_NO_PROPAGATE_INHERIT_ACE)));
1495 1496 return (0);
1496 1497 }
1497 1498
1498 1499 /*
1499 1500 * inherit inheritable ACEs from parent
1500 1501 */
1501 1502 static zfs_acl_t *
1502 1503 zfs_acl_inherit(zfsvfs_t *zfsvfs, vtype_t vtype, zfs_acl_t *paclp,
1503 1504 uint64_t mode, boolean_t *need_chmod)
1504 1505 {
1505 1506 void *pacep;
1506 1507 void *acep;
1507 1508 zfs_acl_node_t *aclnode;
1508 1509 zfs_acl_t *aclp = NULL;
1509 1510 uint64_t who;
1510 1511 uint32_t access_mask;
1511 1512 uint16_t iflags, newflags, type;
1512 1513 size_t ace_size;
1513 1514 void *data1, *data2;
1514 1515 size_t data1sz, data2sz;
1515 1516 boolean_t vdir = vtype == VDIR;
1516 1517 boolean_t vreg = vtype == VREG;
1517 1518 boolean_t passthrough, passthrough_x, noallow;
1518 1519
1519 1520 passthrough_x =
1520 1521 zfsvfs->z_acl_inherit == ZFS_ACL_PASSTHROUGH_X;
1521 1522 passthrough = passthrough_x ||
1522 1523 zfsvfs->z_acl_inherit == ZFS_ACL_PASSTHROUGH;
1523 1524 noallow =
1524 1525 zfsvfs->z_acl_inherit == ZFS_ACL_NOALLOW;
1525 1526
1526 1527 *need_chmod = B_TRUE;
1527 1528 pacep = NULL;
1528 1529 aclp = zfs_acl_alloc(paclp->z_version);
1529 1530 if (zfsvfs->z_acl_inherit == ZFS_ACL_DISCARD || vtype == VLNK)
1530 1531 return (aclp);
1531 1532 while (pacep = zfs_acl_next_ace(paclp, pacep, &who,
1532 1533 &access_mask, &iflags, &type)) {
1533 1534
1534 1535 /*
1535 1536 * don't inherit bogus ACEs
1536 1537 */
1537 1538 if (!zfs_acl_valid_ace_type(type, iflags))
1538 1539 continue;
1539 1540
1540 1541 if (noallow && type == ALLOW)
1541 1542 continue;
1542 1543
1543 1544 ace_size = aclp->z_ops.ace_size(pacep);
1544 1545
1545 1546 if (!zfs_ace_can_use(vtype, iflags))
1546 1547 continue;
1547 1548
1548 1549 /*
1549 1550 * If owner@, group@, or everyone@ inheritable
1550 1551 * then zfs_acl_chmod() isn't needed.
1551 1552 */
1552 1553 if (passthrough &&
1553 1554 ((iflags & (ACE_OWNER|ACE_EVERYONE)) ||
1554 1555 ((iflags & OWNING_GROUP) ==
1555 1556 OWNING_GROUP)) && (vreg || (vdir && (iflags &
1556 1557 ACE_DIRECTORY_INHERIT_ACE)))) {
1557 1558 *need_chmod = B_FALSE;
1558 1559 }
1559 1560
1560 1561 if (!vdir && passthrough_x &&
1561 1562 ((mode & (S_IXUSR | S_IXGRP | S_IXOTH)) == 0)) {
1562 1563 access_mask &= ~ACE_EXECUTE;
1563 1564 }
1564 1565
1565 1566 aclnode = zfs_acl_node_alloc(ace_size);
1566 1567 list_insert_tail(&aclp->z_acl, aclnode);
1567 1568 acep = aclnode->z_acldata;
1568 1569
1569 1570 zfs_set_ace(aclp, acep, access_mask, type,
1570 1571 who, iflags|ACE_INHERITED_ACE);
1571 1572
1572 1573 /*
1573 1574 * Copy special opaque data if any
1574 1575 */
1575 1576 if ((data1sz = paclp->z_ops.ace_data(pacep, &data1)) != 0) {
1576 1577 VERIFY((data2sz = aclp->z_ops.ace_data(acep,
1577 1578 &data2)) == data1sz);
1578 1579 bcopy(data1, data2, data2sz);
1579 1580 }
1580 1581
1581 1582 aclp->z_acl_count++;
1582 1583 aclnode->z_ace_count++;
1583 1584 aclp->z_acl_bytes += aclnode->z_size;
1584 1585 newflags = aclp->z_ops.ace_flags_get(acep);
1585 1586
1586 1587 if (vdir)
1587 1588 aclp->z_hints |= ZFS_INHERIT_ACE;
1588 1589
1589 1590 if ((iflags & ACE_NO_PROPAGATE_INHERIT_ACE) || !vdir) {
1590 1591 newflags &= ~ALL_INHERIT;
1591 1592 aclp->z_ops.ace_flags_set(acep,
1592 1593 newflags|ACE_INHERITED_ACE);
1593 1594 zfs_restricted_update(zfsvfs, aclp, acep);
1594 1595 continue;
1595 1596 }
1596 1597
1597 1598 ASSERT(vdir);
1598 1599
1599 1600 /*
1600 1601 * If only FILE_INHERIT is set then turn on
1601 1602 * inherit_only
1602 1603 */
1603 1604 if ((iflags & (ACE_FILE_INHERIT_ACE |
1604 1605 ACE_DIRECTORY_INHERIT_ACE)) == ACE_FILE_INHERIT_ACE) {
1605 1606 newflags |= ACE_INHERIT_ONLY_ACE;
1606 1607 aclp->z_ops.ace_flags_set(acep,
1607 1608 newflags|ACE_INHERITED_ACE);
1608 1609 } else {
1609 1610 newflags &= ~ACE_INHERIT_ONLY_ACE;
1610 1611 aclp->z_ops.ace_flags_set(acep,
1611 1612 newflags|ACE_INHERITED_ACE);
1612 1613 }
1613 1614 }
1614 1615 return (aclp);
1615 1616 }
1616 1617
1617 1618 /*
1618 1619 * Create file system object initial permissions
1619 1620 * including inheritable ACEs.
1620 1621 */
1621 1622 int
1622 1623 zfs_acl_ids_create(znode_t *dzp, int flag, vattr_t *vap, cred_t *cr,
1623 1624 vsecattr_t *vsecp, zfs_acl_ids_t *acl_ids)
1624 1625 {
1625 1626 int error;
1626 1627 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
1627 1628 zfs_acl_t *paclp;
1628 1629 gid_t gid;
1629 1630 boolean_t need_chmod = B_TRUE;
1630 1631 boolean_t inherited = B_FALSE;
1631 1632
1632 1633 bzero(acl_ids, sizeof (zfs_acl_ids_t));
1633 1634 acl_ids->z_mode = MAKEIMODE(vap->va_type, vap->va_mode);
1634 1635
1635 1636 if (vsecp)
1636 1637 if ((error = zfs_vsec_2_aclp(zfsvfs, vap->va_type, vsecp, cr,
1637 1638 &acl_ids->z_fuidp, &acl_ids->z_aclp)) != 0)
1638 1639 return (error);
1639 1640 /*
1640 1641 * Determine uid and gid.
1641 1642 */
1642 1643 if ((flag & IS_ROOT_NODE) || zfsvfs->z_replay ||
1643 1644 ((flag & IS_XATTR) && (vap->va_type == VDIR))) {
1644 1645 acl_ids->z_fuid = zfs_fuid_create(zfsvfs,
1645 1646 (uint64_t)vap->va_uid, cr,
1646 1647 ZFS_OWNER, &acl_ids->z_fuidp);
1647 1648 acl_ids->z_fgid = zfs_fuid_create(zfsvfs,
1648 1649 (uint64_t)vap->va_gid, cr,
1649 1650 ZFS_GROUP, &acl_ids->z_fuidp);
1650 1651 gid = vap->va_gid;
1651 1652 } else {
1652 1653 acl_ids->z_fuid = zfs_fuid_create_cred(zfsvfs, ZFS_OWNER,
1653 1654 cr, &acl_ids->z_fuidp);
1654 1655 acl_ids->z_fgid = 0;
1655 1656 if (vap->va_mask & AT_GID) {
1656 1657 acl_ids->z_fgid = zfs_fuid_create(zfsvfs,
1657 1658 (uint64_t)vap->va_gid,
1658 1659 cr, ZFS_GROUP, &acl_ids->z_fuidp);
1659 1660 gid = vap->va_gid;
1660 1661 if (acl_ids->z_fgid != dzp->z_gid &&
1661 1662 !groupmember(vap->va_gid, cr) &&
1662 1663 secpolicy_vnode_create_gid(cr) != 0)
1663 1664 acl_ids->z_fgid = 0;
1664 1665 }
1665 1666 if (acl_ids->z_fgid == 0) {
1666 1667 if (dzp->z_mode & S_ISGID) {
1667 1668 char *domain;
1668 1669 uint32_t rid;
1669 1670
1670 1671 acl_ids->z_fgid = dzp->z_gid;
1671 1672 gid = zfs_fuid_map_id(zfsvfs, acl_ids->z_fgid,
1672 1673 cr, ZFS_GROUP);
1673 1674
1674 1675 if (zfsvfs->z_use_fuids &&
1675 1676 IS_EPHEMERAL(acl_ids->z_fgid)) {
1676 1677 domain = zfs_fuid_idx_domain(
1677 1678 &zfsvfs->z_fuid_idx,
1678 1679 FUID_INDEX(acl_ids->z_fgid));
1679 1680 rid = FUID_RID(acl_ids->z_fgid);
1680 1681 zfs_fuid_node_add(&acl_ids->z_fuidp,
1681 1682 domain, rid,
1682 1683 FUID_INDEX(acl_ids->z_fgid),
1683 1684 acl_ids->z_fgid, ZFS_GROUP);
1684 1685 }
1685 1686 } else {
1686 1687 acl_ids->z_fgid = zfs_fuid_create_cred(zfsvfs,
1687 1688 ZFS_GROUP, cr, &acl_ids->z_fuidp);
1688 1689 gid = crgetgid(cr);
1689 1690 }
1690 1691 }
1691 1692 }
1692 1693
1693 1694 /*
1694 1695 * If we're creating a directory, and the parent directory has the
1695 1696 * set-GID bit set, set in on the new directory.
1696 1697 * Otherwise, if the user is neither privileged nor a member of the
1697 1698 * file's new group, clear the file's set-GID bit.
1698 1699 */
1699 1700
1700 1701 if (!(flag & IS_ROOT_NODE) && (dzp->z_mode & S_ISGID) &&
1701 1702 (vap->va_type == VDIR)) {
1702 1703 acl_ids->z_mode |= S_ISGID;
1703 1704 } else {
1704 1705 if ((acl_ids->z_mode & S_ISGID) &&
1705 1706 secpolicy_vnode_setids_setgids(cr, gid) != 0)
1706 1707 acl_ids->z_mode &= ~S_ISGID;
1707 1708 }
1708 1709
1709 1710 if (acl_ids->z_aclp == NULL) {
1710 1711 mutex_enter(&dzp->z_acl_lock);
1711 1712 mutex_enter(&dzp->z_lock);
1712 1713 if (!(flag & IS_ROOT_NODE) &&
1713 1714 (dzp->z_pflags & ZFS_INHERIT_ACE) &&
1714 1715 !(dzp->z_pflags & ZFS_XATTR)) {
1715 1716 VERIFY(0 == zfs_acl_node_read(dzp, B_TRUE,
1716 1717 &paclp, B_FALSE));
1717 1718 acl_ids->z_aclp = zfs_acl_inherit(zfsvfs,
1718 1719 vap->va_type, paclp, acl_ids->z_mode, &need_chmod);
1719 1720 inherited = B_TRUE;
1720 1721 } else {
1721 1722 acl_ids->z_aclp =
1722 1723 zfs_acl_alloc(zfs_acl_version_zp(dzp));
1723 1724 acl_ids->z_aclp->z_hints |= ZFS_ACL_TRIVIAL;
1724 1725 }
1725 1726 mutex_exit(&dzp->z_lock);
1726 1727 mutex_exit(&dzp->z_acl_lock);
1727 1728 if (need_chmod) {
1728 1729 acl_ids->z_aclp->z_hints |= (vap->va_type == VDIR) ?
1729 1730 ZFS_ACL_AUTO_INHERIT : 0;
1730 1731 zfs_acl_chmod(vap->va_type, acl_ids->z_mode,
1731 1732 (zfsvfs->z_acl_inherit == ZFS_ACL_RESTRICTED),
1732 1733 acl_ids->z_aclp);
1733 1734 }
1734 1735 }
1735 1736
1736 1737 if (inherited || vsecp) {
1737 1738 acl_ids->z_mode = zfs_mode_compute(acl_ids->z_mode,
1738 1739 acl_ids->z_aclp, &acl_ids->z_aclp->z_hints,
1739 1740 acl_ids->z_fuid, acl_ids->z_fgid);
1740 1741 if (ace_trivial_common(acl_ids->z_aclp, 0, zfs_ace_walk) == 0)
1741 1742 acl_ids->z_aclp->z_hints |= ZFS_ACL_TRIVIAL;
1742 1743 }
1743 1744
1744 1745 return (0);
1745 1746 }
1746 1747
1747 1748 /*
1748 1749 * Free ACL and fuid_infop, but not the acl_ids structure
1749 1750 */
1750 1751 void
1751 1752 zfs_acl_ids_free(zfs_acl_ids_t *acl_ids)
1752 1753 {
1753 1754 if (acl_ids->z_aclp)
1754 1755 zfs_acl_free(acl_ids->z_aclp);
1755 1756 if (acl_ids->z_fuidp)
1756 1757 zfs_fuid_info_free(acl_ids->z_fuidp);
1757 1758 acl_ids->z_aclp = NULL;
1758 1759 acl_ids->z_fuidp = NULL;
↓ open down ↓ |
383 lines elided |
↑ open up ↑ |
1759 1760 }
1760 1761
1761 1762 boolean_t
1762 1763 zfs_acl_ids_overquota(zfsvfs_t *zfsvfs, zfs_acl_ids_t *acl_ids)
1763 1764 {
1764 1765 return (zfs_fuid_overquota(zfsvfs, B_FALSE, acl_ids->z_fuid) ||
1765 1766 zfs_fuid_overquota(zfsvfs, B_TRUE, acl_ids->z_fgid));
1766 1767 }
1767 1768
1768 1769 /*
1769 - * Retrieve a files ACL
1770 + * Retrieve a file's ACL
1770 1771 */
1771 1772 int
1772 1773 zfs_getacl(znode_t *zp, vsecattr_t *vsecp, boolean_t skipaclchk, cred_t *cr)
1773 1774 {
1774 1775 zfs_acl_t *aclp;
1775 1776 ulong_t mask;
1776 1777 int error;
1777 1778 int count = 0;
1778 1779 int largeace = 0;
1779 1780
1780 1781 mask = vsecp->vsa_mask & (VSA_ACE | VSA_ACECNT |
1781 1782 VSA_ACE_ACLFLAGS | VSA_ACE_ALLTYPES);
1782 1783
1783 1784 if (mask == 0)
1784 1785 return (SET_ERROR(ENOSYS));
1785 1786
1786 1787 if (error = zfs_zaccess(zp, ACE_READ_ACL, 0, skipaclchk, cr))
1787 1788 return (error);
1788 1789
1789 1790 mutex_enter(&zp->z_acl_lock);
1790 1791
1791 1792 error = zfs_acl_node_read(zp, B_FALSE, &aclp, B_FALSE);
1792 1793 if (error != 0) {
1793 1794 mutex_exit(&zp->z_acl_lock);
1794 1795 return (error);
1795 1796 }
1796 1797
1797 1798 /*
1798 1799 * Scan ACL to determine number of ACEs
1799 1800 */
1800 1801 if ((zp->z_pflags & ZFS_ACL_OBJ_ACE) && !(mask & VSA_ACE_ALLTYPES)) {
1801 1802 void *zacep = NULL;
1802 1803 uint64_t who;
1803 1804 uint32_t access_mask;
1804 1805 uint16_t type, iflags;
1805 1806
1806 1807 while (zacep = zfs_acl_next_ace(aclp, zacep,
1807 1808 &who, &access_mask, &iflags, &type)) {
1808 1809 switch (type) {
1809 1810 case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
1810 1811 case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
1811 1812 case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
1812 1813 case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
1813 1814 largeace++;
1814 1815 continue;
1815 1816 default:
1816 1817 count++;
1817 1818 }
1818 1819 }
1819 1820 vsecp->vsa_aclcnt = count;
1820 1821 } else
1821 1822 count = (int)aclp->z_acl_count;
1822 1823
1823 1824 if (mask & VSA_ACECNT) {
1824 1825 vsecp->vsa_aclcnt = count;
1825 1826 }
1826 1827
1827 1828 if (mask & VSA_ACE) {
1828 1829 size_t aclsz;
1829 1830
1830 1831 aclsz = count * sizeof (ace_t) +
1831 1832 sizeof (ace_object_t) * largeace;
1832 1833
1833 1834 vsecp->vsa_aclentp = kmem_alloc(aclsz, KM_SLEEP);
1834 1835 vsecp->vsa_aclentsz = aclsz;
1835 1836
1836 1837 if (aclp->z_version == ZFS_ACL_VERSION_FUID)
1837 1838 zfs_copy_fuid_2_ace(zp->z_zfsvfs, aclp, cr,
1838 1839 vsecp->vsa_aclentp, !(mask & VSA_ACE_ALLTYPES));
1839 1840 else {
1840 1841 zfs_acl_node_t *aclnode;
1841 1842 void *start = vsecp->vsa_aclentp;
1842 1843
1843 1844 for (aclnode = list_head(&aclp->z_acl); aclnode;
1844 1845 aclnode = list_next(&aclp->z_acl, aclnode)) {
1845 1846 bcopy(aclnode->z_acldata, start,
1846 1847 aclnode->z_size);
1847 1848 start = (caddr_t)start + aclnode->z_size;
1848 1849 }
1849 1850 ASSERT((caddr_t)start - (caddr_t)vsecp->vsa_aclentp ==
1850 1851 aclp->z_acl_bytes);
1851 1852 }
1852 1853 }
1853 1854 if (mask & VSA_ACE_ACLFLAGS) {
1854 1855 vsecp->vsa_aclflags = 0;
1855 1856 if (zp->z_pflags & ZFS_ACL_DEFAULTED)
1856 1857 vsecp->vsa_aclflags |= ACL_DEFAULTED;
1857 1858 if (zp->z_pflags & ZFS_ACL_PROTECTED)
1858 1859 vsecp->vsa_aclflags |= ACL_PROTECTED;
1859 1860 if (zp->z_pflags & ZFS_ACL_AUTO_INHERIT)
1860 1861 vsecp->vsa_aclflags |= ACL_AUTO_INHERIT;
1861 1862 }
1862 1863
1863 1864 mutex_exit(&zp->z_acl_lock);
1864 1865
1865 1866 return (0);
1866 1867 }
1867 1868
1868 1869 int
1869 1870 zfs_vsec_2_aclp(zfsvfs_t *zfsvfs, vtype_t obj_type,
1870 1871 vsecattr_t *vsecp, cred_t *cr, zfs_fuid_info_t **fuidp, zfs_acl_t **zaclp)
1871 1872 {
1872 1873 zfs_acl_t *aclp;
1873 1874 zfs_acl_node_t *aclnode;
1874 1875 int aclcnt = vsecp->vsa_aclcnt;
1875 1876 int error;
1876 1877
1877 1878 if (vsecp->vsa_aclcnt > MAX_ACL_ENTRIES || vsecp->vsa_aclcnt <= 0)
1878 1879 return (SET_ERROR(EINVAL));
1879 1880
1880 1881 aclp = zfs_acl_alloc(zfs_acl_version(zfsvfs->z_version));
1881 1882
1882 1883 aclp->z_hints = 0;
1883 1884 aclnode = zfs_acl_node_alloc(aclcnt * sizeof (zfs_object_ace_t));
1884 1885 if (aclp->z_version == ZFS_ACL_VERSION_INITIAL) {
1885 1886 if ((error = zfs_copy_ace_2_oldace(obj_type, aclp,
1886 1887 (ace_t *)vsecp->vsa_aclentp, aclnode->z_acldata,
1887 1888 aclcnt, &aclnode->z_size)) != 0) {
1888 1889 zfs_acl_free(aclp);
1889 1890 zfs_acl_node_free(aclnode);
1890 1891 return (error);
1891 1892 }
1892 1893 } else {
1893 1894 if ((error = zfs_copy_ace_2_fuid(zfsvfs, obj_type, aclp,
1894 1895 vsecp->vsa_aclentp, aclnode->z_acldata, aclcnt,
1895 1896 &aclnode->z_size, fuidp, cr)) != 0) {
1896 1897 zfs_acl_free(aclp);
1897 1898 zfs_acl_node_free(aclnode);
1898 1899 return (error);
1899 1900 }
1900 1901 }
1901 1902 aclp->z_acl_bytes = aclnode->z_size;
1902 1903 aclnode->z_ace_count = aclcnt;
1903 1904 aclp->z_acl_count = aclcnt;
1904 1905 list_insert_head(&aclp->z_acl, aclnode);
1905 1906
1906 1907 /*
1907 1908 * If flags are being set then add them to z_hints
1908 1909 */
1909 1910 if (vsecp->vsa_mask & VSA_ACE_ACLFLAGS) {
1910 1911 if (vsecp->vsa_aclflags & ACL_PROTECTED)
1911 1912 aclp->z_hints |= ZFS_ACL_PROTECTED;
1912 1913 if (vsecp->vsa_aclflags & ACL_DEFAULTED)
1913 1914 aclp->z_hints |= ZFS_ACL_DEFAULTED;
↓ open down ↓ |
134 lines elided |
↑ open up ↑ |
1914 1915 if (vsecp->vsa_aclflags & ACL_AUTO_INHERIT)
1915 1916 aclp->z_hints |= ZFS_ACL_AUTO_INHERIT;
1916 1917 }
1917 1918
1918 1919 *zaclp = aclp;
1919 1920
1920 1921 return (0);
1921 1922 }
1922 1923
1923 1924 /*
1924 - * Set a files ACL
1925 + * Set a file's ACL
1925 1926 */
1926 1927 int
1927 1928 zfs_setacl(znode_t *zp, vsecattr_t *vsecp, boolean_t skipaclchk, cred_t *cr)
1928 1929 {
1929 1930 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
1930 1931 zilog_t *zilog = zfsvfs->z_log;
1931 1932 ulong_t mask = vsecp->vsa_mask & (VSA_ACE | VSA_ACECNT);
1932 1933 dmu_tx_t *tx;
1933 1934 int error;
1934 1935 zfs_acl_t *aclp;
1935 1936 zfs_fuid_info_t *fuidp = NULL;
1936 1937 boolean_t fuid_dirtied;
1937 1938 uint64_t acl_obj;
1938 1939
1939 1940 if (mask == 0)
1940 1941 return (SET_ERROR(ENOSYS));
1941 1942
1942 1943 if (zp->z_pflags & ZFS_IMMUTABLE)
1943 1944 return (SET_ERROR(EPERM));
1944 1945
1945 1946 if (error = zfs_zaccess(zp, ACE_WRITE_ACL, 0, skipaclchk, cr))
1946 1947 return (error);
1947 1948
1948 1949 error = zfs_vsec_2_aclp(zfsvfs, ZTOV(zp)->v_type, vsecp, cr, &fuidp,
1949 1950 &aclp);
1950 1951 if (error)
1951 1952 return (error);
1952 1953
1953 1954 /*
1954 1955 * If ACL wide flags aren't being set then preserve any
1955 1956 * existing flags.
1956 1957 */
1957 1958 if (!(vsecp->vsa_mask & VSA_ACE_ACLFLAGS)) {
1958 1959 aclp->z_hints |=
1959 1960 (zp->z_pflags & V4_ACL_WIDE_FLAGS);
1960 1961 }
1961 1962 top:
1962 1963 mutex_enter(&zp->z_acl_lock);
1963 1964 mutex_enter(&zp->z_lock);
1964 1965
1965 1966 tx = dmu_tx_create(zfsvfs->z_os);
1966 1967
1967 1968 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE);
1968 1969
1969 1970 fuid_dirtied = zfsvfs->z_fuid_dirty;
1970 1971 if (fuid_dirtied)
1971 1972 zfs_fuid_txhold(zfsvfs, tx);
1972 1973
1973 1974 /*
1974 1975 * If old version and ACL won't fit in bonus and we aren't
1975 1976 * upgrading then take out necessary DMU holds
1976 1977 */
1977 1978
1978 1979 if ((acl_obj = zfs_external_acl(zp)) != 0) {
1979 1980 if (zfsvfs->z_version >= ZPL_VERSION_FUID &&
1980 1981 zfs_znode_acl_version(zp) <= ZFS_ACL_VERSION_INITIAL) {
1981 1982 dmu_tx_hold_free(tx, acl_obj, 0,
1982 1983 DMU_OBJECT_END);
1983 1984 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0,
1984 1985 aclp->z_acl_bytes);
1985 1986 } else {
1986 1987 dmu_tx_hold_write(tx, acl_obj, 0, aclp->z_acl_bytes);
1987 1988 }
1988 1989 } else if (!zp->z_is_sa && aclp->z_acl_bytes > ZFS_ACE_SPACE) {
1989 1990 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, aclp->z_acl_bytes);
1990 1991 }
1991 1992
1992 1993 zfs_sa_upgrade_txholds(tx, zp);
1993 1994 error = dmu_tx_assign(tx, TXG_NOWAIT);
1994 1995 if (error) {
1995 1996 mutex_exit(&zp->z_acl_lock);
1996 1997 mutex_exit(&zp->z_lock);
1997 1998
1998 1999 if (error == ERESTART) {
1999 2000 dmu_tx_wait(tx);
2000 2001 dmu_tx_abort(tx);
2001 2002 goto top;
2002 2003 }
2003 2004 dmu_tx_abort(tx);
2004 2005 zfs_acl_free(aclp);
2005 2006 return (error);
2006 2007 }
2007 2008
2008 2009 error = zfs_aclset_common(zp, aclp, cr, tx);
2009 2010 ASSERT(error == 0);
2010 2011 ASSERT(zp->z_acl_cached == NULL);
2011 2012 zp->z_acl_cached = aclp;
2012 2013
2013 2014 if (fuid_dirtied)
2014 2015 zfs_fuid_sync(zfsvfs, tx);
2015 2016
2016 2017 zfs_log_acl(zilog, tx, zp, vsecp, fuidp);
2017 2018
2018 2019 if (fuidp)
2019 2020 zfs_fuid_info_free(fuidp);
2020 2021 dmu_tx_commit(tx);
2021 2022 done:
2022 2023 mutex_exit(&zp->z_lock);
2023 2024 mutex_exit(&zp->z_acl_lock);
2024 2025
2025 2026 return (error);
2026 2027 }
2027 2028
2028 2029 /*
2029 2030 * Check accesses of interest (AoI) against attributes of the dataset
2030 2031 * such as read-only. Returns zero if no AoI conflict with dataset
2031 2032 * attributes, otherwise an appropriate errno is returned.
2032 2033 */
2033 2034 static int
2034 2035 zfs_zaccess_dataset_check(znode_t *zp, uint32_t v4_mode)
2035 2036 {
2036 2037 if ((v4_mode & WRITE_MASK) &&
2037 2038 (zp->z_zfsvfs->z_vfs->vfs_flag & VFS_RDONLY) &&
2038 2039 (!IS_DEVVP(ZTOV(zp)) ||
2039 2040 (IS_DEVVP(ZTOV(zp)) && (v4_mode & WRITE_MASK_ATTRS)))) {
2040 2041 return (SET_ERROR(EROFS));
2041 2042 }
2042 2043
2043 2044 /*
2044 2045 * Only check for READONLY on non-directories.
2045 2046 */
2046 2047 if ((v4_mode & WRITE_MASK_DATA) &&
2047 2048 (((ZTOV(zp)->v_type != VDIR) &&
2048 2049 (zp->z_pflags & (ZFS_READONLY | ZFS_IMMUTABLE))) ||
2049 2050 (ZTOV(zp)->v_type == VDIR &&
2050 2051 (zp->z_pflags & ZFS_IMMUTABLE)))) {
2051 2052 return (SET_ERROR(EPERM));
2052 2053 }
2053 2054
2054 2055 if ((v4_mode & (ACE_DELETE | ACE_DELETE_CHILD)) &&
2055 2056 (zp->z_pflags & ZFS_NOUNLINK)) {
2056 2057 return (SET_ERROR(EPERM));
2057 2058 }
2058 2059
2059 2060 if (((v4_mode & (ACE_READ_DATA|ACE_EXECUTE)) &&
2060 2061 (zp->z_pflags & ZFS_AV_QUARANTINED))) {
2061 2062 return (SET_ERROR(EACCES));
2062 2063 }
2063 2064
2064 2065 return (0);
2065 2066 }
2066 2067
2067 2068 /*
2068 2069 * The primary usage of this function is to loop through all of the
2069 2070 * ACEs in the znode, determining what accesses of interest (AoI) to
2070 2071 * the caller are allowed or denied. The AoI are expressed as bits in
2071 2072 * the working_mode parameter. As each ACE is processed, bits covered
2072 2073 * by that ACE are removed from the working_mode. This removal
2073 2074 * facilitates two things. The first is that when the working mode is
2074 2075 * empty (= 0), we know we've looked at all the AoI. The second is
2075 2076 * that the ACE interpretation rules don't allow a later ACE to undo
2076 2077 * something granted or denied by an earlier ACE. Removing the
2077 2078 * discovered access or denial enforces this rule. At the end of
2078 2079 * processing the ACEs, all AoI that were found to be denied are
2079 2080 * placed into the working_mode, giving the caller a mask of denied
2080 2081 * accesses. Returns:
2081 2082 * 0 if all AoI granted
2082 2083 * EACCESS if the denied mask is non-zero
2083 2084 * other error if abnormal failure (e.g., IO error)
2084 2085 *
2085 2086 * A secondary usage of the function is to determine if any of the
2086 2087 * AoI are granted. If an ACE grants any access in
2087 2088 * the working_mode, we immediately short circuit out of the function.
2088 2089 * This mode is chosen by setting anyaccess to B_TRUE. The
2089 2090 * working_mode is not a denied access mask upon exit if the function
2090 2091 * is used in this manner.
2091 2092 */
2092 2093 static int
2093 2094 zfs_zaccess_aces_check(znode_t *zp, uint32_t *working_mode,
2094 2095 boolean_t anyaccess, cred_t *cr)
2095 2096 {
2096 2097 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2097 2098 zfs_acl_t *aclp;
2098 2099 int error;
2099 2100 uid_t uid = crgetuid(cr);
2100 2101 uint64_t who;
2101 2102 uint16_t type, iflags;
2102 2103 uint16_t entry_type;
2103 2104 uint32_t access_mask;
2104 2105 uint32_t deny_mask = 0;
2105 2106 zfs_ace_hdr_t *acep = NULL;
2106 2107 boolean_t checkit;
2107 2108 uid_t gowner;
2108 2109 uid_t fowner;
2109 2110
2110 2111 zfs_fuid_map_ids(zp, cr, &fowner, &gowner);
2111 2112
2112 2113 mutex_enter(&zp->z_acl_lock);
2113 2114
2114 2115 error = zfs_acl_node_read(zp, B_FALSE, &aclp, B_FALSE);
2115 2116 if (error != 0) {
2116 2117 mutex_exit(&zp->z_acl_lock);
2117 2118 return (error);
2118 2119 }
2119 2120
2120 2121 ASSERT(zp->z_acl_cached);
2121 2122
2122 2123 while (acep = zfs_acl_next_ace(aclp, acep, &who, &access_mask,
2123 2124 &iflags, &type)) {
2124 2125 uint32_t mask_matched;
2125 2126
2126 2127 if (!zfs_acl_valid_ace_type(type, iflags))
2127 2128 continue;
2128 2129
2129 2130 if (ZTOV(zp)->v_type == VDIR && (iflags & ACE_INHERIT_ONLY_ACE))
2130 2131 continue;
2131 2132
2132 2133 /* Skip ACE if it does not affect any AoI */
2133 2134 mask_matched = (access_mask & *working_mode);
2134 2135 if (!mask_matched)
2135 2136 continue;
2136 2137
2137 2138 entry_type = (iflags & ACE_TYPE_FLAGS);
2138 2139
2139 2140 checkit = B_FALSE;
2140 2141
2141 2142 switch (entry_type) {
2142 2143 case ACE_OWNER:
2143 2144 if (uid == fowner)
2144 2145 checkit = B_TRUE;
2145 2146 break;
2146 2147 case OWNING_GROUP:
2147 2148 who = gowner;
2148 2149 /*FALLTHROUGH*/
2149 2150 case ACE_IDENTIFIER_GROUP:
2150 2151 checkit = zfs_groupmember(zfsvfs, who, cr);
2151 2152 break;
2152 2153 case ACE_EVERYONE:
2153 2154 checkit = B_TRUE;
2154 2155 break;
2155 2156
2156 2157 /* USER Entry */
2157 2158 default:
2158 2159 if (entry_type == 0) {
2159 2160 uid_t newid;
2160 2161
2161 2162 newid = zfs_fuid_map_id(zfsvfs, who, cr,
2162 2163 ZFS_ACE_USER);
2163 2164 if (newid != IDMAP_WK_CREATOR_OWNER_UID &&
2164 2165 uid == newid)
2165 2166 checkit = B_TRUE;
2166 2167 break;
2167 2168 } else {
2168 2169 mutex_exit(&zp->z_acl_lock);
2169 2170 return (SET_ERROR(EIO));
2170 2171 }
2171 2172 }
2172 2173
2173 2174 if (checkit) {
2174 2175 if (type == DENY) {
2175 2176 DTRACE_PROBE3(zfs__ace__denies,
2176 2177 znode_t *, zp,
2177 2178 zfs_ace_hdr_t *, acep,
2178 2179 uint32_t, mask_matched);
2179 2180 deny_mask |= mask_matched;
2180 2181 } else {
2181 2182 DTRACE_PROBE3(zfs__ace__allows,
2182 2183 znode_t *, zp,
2183 2184 zfs_ace_hdr_t *, acep,
2184 2185 uint32_t, mask_matched);
2185 2186 if (anyaccess) {
2186 2187 mutex_exit(&zp->z_acl_lock);
2187 2188 return (0);
2188 2189 }
2189 2190 }
2190 2191 *working_mode &= ~mask_matched;
2191 2192 }
2192 2193
2193 2194 /* Are we done? */
2194 2195 if (*working_mode == 0)
2195 2196 break;
2196 2197 }
2197 2198
2198 2199 mutex_exit(&zp->z_acl_lock);
2199 2200
2200 2201 /* Put the found 'denies' back on the working mode */
2201 2202 if (deny_mask) {
2202 2203 *working_mode |= deny_mask;
2203 2204 return (SET_ERROR(EACCES));
2204 2205 } else if (*working_mode) {
2205 2206 return (-1);
2206 2207 }
2207 2208
2208 2209 return (0);
2209 2210 }
2210 2211
2211 2212 /*
2212 2213 * Return true if any access whatsoever granted, we don't actually
2213 2214 * care what access is granted.
2214 2215 */
2215 2216 boolean_t
2216 2217 zfs_has_access(znode_t *zp, cred_t *cr)
2217 2218 {
2218 2219 uint32_t have = ACE_ALL_PERMS;
2219 2220
2220 2221 if (zfs_zaccess_aces_check(zp, &have, B_TRUE, cr) != 0) {
2221 2222 uid_t owner;
2222 2223
2223 2224 owner = zfs_fuid_map_id(zp->z_zfsvfs, zp->z_uid, cr, ZFS_OWNER);
2224 2225 return (secpolicy_vnode_any_access(cr, ZTOV(zp), owner) == 0);
2225 2226 }
2226 2227 return (B_TRUE);
2227 2228 }
2228 2229
2229 2230 static int
2230 2231 zfs_zaccess_common(znode_t *zp, uint32_t v4_mode, uint32_t *working_mode,
2231 2232 boolean_t *check_privs, boolean_t skipaclchk, cred_t *cr)
2232 2233 {
2233 2234 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2234 2235 int err;
2235 2236
2236 2237 *working_mode = v4_mode;
2237 2238 *check_privs = B_TRUE;
2238 2239
2239 2240 /*
2240 2241 * Short circuit empty requests
2241 2242 */
2242 2243 if (v4_mode == 0 || zfsvfs->z_replay) {
2243 2244 *working_mode = 0;
2244 2245 return (0);
2245 2246 }
2246 2247
2247 2248 if ((err = zfs_zaccess_dataset_check(zp, v4_mode)) != 0) {
2248 2249 *check_privs = B_FALSE;
2249 2250 return (err);
2250 2251 }
2251 2252
2252 2253 /*
2253 2254 * The caller requested that the ACL check be skipped. This
2254 2255 * would only happen if the caller checked VOP_ACCESS() with a
2255 2256 * 32 bit ACE mask and already had the appropriate permissions.
2256 2257 */
2257 2258 if (skipaclchk) {
2258 2259 *working_mode = 0;
2259 2260 return (0);
2260 2261 }
2261 2262
2262 2263 return (zfs_zaccess_aces_check(zp, working_mode, B_FALSE, cr));
2263 2264 }
2264 2265
2265 2266 static int
2266 2267 zfs_zaccess_append(znode_t *zp, uint32_t *working_mode, boolean_t *check_privs,
2267 2268 cred_t *cr)
2268 2269 {
2269 2270 if (*working_mode != ACE_WRITE_DATA)
2270 2271 return (SET_ERROR(EACCES));
2271 2272
2272 2273 return (zfs_zaccess_common(zp, ACE_APPEND_DATA, working_mode,
2273 2274 check_privs, B_FALSE, cr));
2274 2275 }
2275 2276
2276 2277 int
2277 2278 zfs_fastaccesschk_execute(znode_t *zdp, cred_t *cr)
2278 2279 {
2279 2280 boolean_t owner = B_FALSE;
2280 2281 boolean_t groupmbr = B_FALSE;
2281 2282 boolean_t is_attr;
2282 2283 uid_t uid = crgetuid(cr);
2283 2284 int error;
2284 2285
2285 2286 if (zdp->z_pflags & ZFS_AV_QUARANTINED)
2286 2287 return (SET_ERROR(EACCES));
2287 2288
2288 2289 is_attr = ((zdp->z_pflags & ZFS_XATTR) &&
2289 2290 (ZTOV(zdp)->v_type == VDIR));
2290 2291 if (is_attr)
2291 2292 goto slow;
2292 2293
2293 2294
2294 2295 mutex_enter(&zdp->z_acl_lock);
2295 2296
2296 2297 if (zdp->z_pflags & ZFS_NO_EXECS_DENIED) {
2297 2298 mutex_exit(&zdp->z_acl_lock);
2298 2299 return (0);
2299 2300 }
2300 2301
2301 2302 if (FUID_INDEX(zdp->z_uid) != 0 || FUID_INDEX(zdp->z_gid) != 0) {
2302 2303 mutex_exit(&zdp->z_acl_lock);
2303 2304 goto slow;
2304 2305 }
2305 2306
2306 2307 if (uid == zdp->z_uid) {
2307 2308 owner = B_TRUE;
2308 2309 if (zdp->z_mode & S_IXUSR) {
2309 2310 mutex_exit(&zdp->z_acl_lock);
2310 2311 return (0);
2311 2312 } else {
2312 2313 mutex_exit(&zdp->z_acl_lock);
2313 2314 goto slow;
2314 2315 }
2315 2316 }
2316 2317 if (groupmember(zdp->z_gid, cr)) {
2317 2318 groupmbr = B_TRUE;
2318 2319 if (zdp->z_mode & S_IXGRP) {
2319 2320 mutex_exit(&zdp->z_acl_lock);
2320 2321 return (0);
2321 2322 } else {
2322 2323 mutex_exit(&zdp->z_acl_lock);
2323 2324 goto slow;
2324 2325 }
2325 2326 }
2326 2327 if (!owner && !groupmbr) {
2327 2328 if (zdp->z_mode & S_IXOTH) {
2328 2329 mutex_exit(&zdp->z_acl_lock);
2329 2330 return (0);
2330 2331 }
2331 2332 }
2332 2333
2333 2334 mutex_exit(&zdp->z_acl_lock);
2334 2335
↓ open down ↓ |
400 lines elided |
↑ open up ↑ |
2335 2336 slow:
2336 2337 DTRACE_PROBE(zfs__fastpath__execute__access__miss);
2337 2338 ZFS_ENTER(zdp->z_zfsvfs);
2338 2339 error = zfs_zaccess(zdp, ACE_EXECUTE, 0, B_FALSE, cr);
2339 2340 ZFS_EXIT(zdp->z_zfsvfs);
2340 2341 return (error);
2341 2342 }
2342 2343
2343 2344 /*
2344 2345 * Determine whether Access should be granted/denied.
2346 + *
2345 2347 * The least priv subsytem is always consulted as a basic privilege
2346 2348 * can define any form of access.
2347 2349 */
2348 2350 int
2349 2351 zfs_zaccess(znode_t *zp, int mode, int flags, boolean_t skipaclchk, cred_t *cr)
2350 2352 {
2351 2353 uint32_t working_mode;
2352 2354 int error;
2353 2355 int is_attr;
2354 2356 boolean_t check_privs;
2355 2357 znode_t *xzp;
2356 2358 znode_t *check_zp = zp;
2357 2359 mode_t needed_bits;
2358 2360 uid_t owner;
2359 2361
2360 2362 is_attr = ((zp->z_pflags & ZFS_XATTR) && (ZTOV(zp)->v_type == VDIR));
2361 2363
2362 2364 /*
2363 2365 * If attribute then validate against base file
2364 2366 */
2365 2367 if (is_attr) {
2366 2368 uint64_t parent;
2367 2369
2368 2370 if ((error = sa_lookup(zp->z_sa_hdl,
2369 2371 SA_ZPL_PARENT(zp->z_zfsvfs), &parent,
2370 2372 sizeof (parent))) != 0)
2371 2373 return (error);
2372 2374
2373 2375 if ((error = zfs_zget(zp->z_zfsvfs,
2374 2376 parent, &xzp)) != 0) {
2375 2377 return (error);
2376 2378 }
2377 2379
2378 2380 check_zp = xzp;
2379 2381
2380 2382 /*
2381 2383 * fixup mode to map to xattr perms
2382 2384 */
2383 2385
2384 2386 if (mode & (ACE_WRITE_DATA|ACE_APPEND_DATA)) {
2385 2387 mode &= ~(ACE_WRITE_DATA|ACE_APPEND_DATA);
2386 2388 mode |= ACE_WRITE_NAMED_ATTRS;
2387 2389 }
2388 2390
2389 2391 if (mode & (ACE_READ_DATA|ACE_EXECUTE)) {
2390 2392 mode &= ~(ACE_READ_DATA|ACE_EXECUTE);
2391 2393 mode |= ACE_READ_NAMED_ATTRS;
2392 2394 }
2393 2395 }
2394 2396
2395 2397 owner = zfs_fuid_map_id(zp->z_zfsvfs, zp->z_uid, cr, ZFS_OWNER);
2396 2398 /*
2397 2399 * Map the bits required to the standard vnode flags VREAD|VWRITE|VEXEC
2398 2400 * in needed_bits. Map the bits mapped by working_mode (currently
2399 2401 * missing) in missing_bits.
2400 2402 * Call secpolicy_vnode_access2() with (needed_bits & ~checkmode),
2401 2403 * needed_bits.
2402 2404 */
2403 2405 needed_bits = 0;
2404 2406
2405 2407 working_mode = mode;
2406 2408 if ((working_mode & (ACE_READ_ACL|ACE_READ_ATTRIBUTES)) &&
2407 2409 owner == crgetuid(cr))
2408 2410 working_mode &= ~(ACE_READ_ACL|ACE_READ_ATTRIBUTES);
2409 2411
2410 2412 if (working_mode & (ACE_READ_DATA|ACE_READ_NAMED_ATTRS|
2411 2413 ACE_READ_ACL|ACE_READ_ATTRIBUTES|ACE_SYNCHRONIZE))
2412 2414 needed_bits |= VREAD;
2413 2415 if (working_mode & (ACE_WRITE_DATA|ACE_WRITE_NAMED_ATTRS|
2414 2416 ACE_APPEND_DATA|ACE_WRITE_ATTRIBUTES|ACE_SYNCHRONIZE))
2415 2417 needed_bits |= VWRITE;
2416 2418 if (working_mode & ACE_EXECUTE)
2417 2419 needed_bits |= VEXEC;
2418 2420
2419 2421 if ((error = zfs_zaccess_common(check_zp, mode, &working_mode,
2420 2422 &check_privs, skipaclchk, cr)) == 0) {
2421 2423 if (is_attr)
2422 2424 VN_RELE(ZTOV(xzp));
2423 2425 return (secpolicy_vnode_access2(cr, ZTOV(zp), owner,
2424 2426 needed_bits, needed_bits));
2425 2427 }
2426 2428
2427 2429 if (error && !check_privs) {
2428 2430 if (is_attr)
2429 2431 VN_RELE(ZTOV(xzp));
2430 2432 return (error);
2431 2433 }
2432 2434
2433 2435 if (error && (flags & V_APPEND)) {
2434 2436 error = zfs_zaccess_append(zp, &working_mode, &check_privs, cr);
2435 2437 }
2436 2438
2437 2439 if (error && check_privs) {
2438 2440 mode_t checkmode = 0;
2439 2441
2440 2442 /*
2441 2443 * First check for implicit owner permission on
2442 2444 * read_acl/read_attributes
2443 2445 */
2444 2446
2445 2447 error = 0;
2446 2448 ASSERT(working_mode != 0);
2447 2449
2448 2450 if ((working_mode & (ACE_READ_ACL|ACE_READ_ATTRIBUTES) &&
2449 2451 owner == crgetuid(cr)))
2450 2452 working_mode &= ~(ACE_READ_ACL|ACE_READ_ATTRIBUTES);
2451 2453
2452 2454 if (working_mode & (ACE_READ_DATA|ACE_READ_NAMED_ATTRS|
2453 2455 ACE_READ_ACL|ACE_READ_ATTRIBUTES|ACE_SYNCHRONIZE))
2454 2456 checkmode |= VREAD;
2455 2457 if (working_mode & (ACE_WRITE_DATA|ACE_WRITE_NAMED_ATTRS|
2456 2458 ACE_APPEND_DATA|ACE_WRITE_ATTRIBUTES|ACE_SYNCHRONIZE))
2457 2459 checkmode |= VWRITE;
2458 2460 if (working_mode & ACE_EXECUTE)
2459 2461 checkmode |= VEXEC;
2460 2462
2461 2463 error = secpolicy_vnode_access2(cr, ZTOV(check_zp), owner,
2462 2464 needed_bits & ~checkmode, needed_bits);
2463 2465
2464 2466 if (error == 0 && (working_mode & ACE_WRITE_OWNER))
2465 2467 error = secpolicy_vnode_chown(cr, owner);
2466 2468 if (error == 0 && (working_mode & ACE_WRITE_ACL))
2467 2469 error = secpolicy_vnode_setdac(cr, owner);
2468 2470
2469 2471 if (error == 0 && (working_mode &
2470 2472 (ACE_DELETE|ACE_DELETE_CHILD)))
2471 2473 error = secpolicy_vnode_remove(cr);
2472 2474
2473 2475 if (error == 0 && (working_mode & ACE_SYNCHRONIZE)) {
2474 2476 error = secpolicy_vnode_chown(cr, owner);
2475 2477 }
2476 2478 if (error == 0) {
2477 2479 /*
2478 2480 * See if any bits other than those already checked
2479 2481 * for are still present. If so then return EACCES
2480 2482 */
2481 2483 if (working_mode & ~(ZFS_CHECKED_MASKS)) {
2482 2484 error = SET_ERROR(EACCES);
2483 2485 }
2484 2486 }
2485 2487 } else if (error == 0) {
2486 2488 error = secpolicy_vnode_access2(cr, ZTOV(zp), owner,
2487 2489 needed_bits, needed_bits);
2488 2490 }
2489 2491
2490 2492
2491 2493 if (is_attr)
2492 2494 VN_RELE(ZTOV(xzp));
2493 2495
2494 2496 return (error);
2495 2497 }
2496 2498
2497 2499 /*
2498 2500 * Translate traditional unix VREAD/VWRITE/VEXEC mode into
2499 2501 * native ACL format and call zfs_zaccess()
2500 2502 */
2501 2503 int
2502 2504 zfs_zaccess_rwx(znode_t *zp, mode_t mode, int flags, cred_t *cr)
2503 2505 {
2504 2506 return (zfs_zaccess(zp, zfs_unix_to_v4(mode >> 6), flags, B_FALSE, cr));
2505 2507 }
2506 2508
2507 2509 /*
2508 2510 * Access function for secpolicy_vnode_setattr
2509 2511 */
2510 2512 int
2511 2513 zfs_zaccess_unix(znode_t *zp, mode_t mode, cred_t *cr)
2512 2514 {
2513 2515 int v4_mode = zfs_unix_to_v4(mode >> 6);
2514 2516
2515 2517 return (zfs_zaccess(zp, v4_mode, 0, B_FALSE, cr));
2516 2518 }
2517 2519
2518 2520 static int
2519 2521 zfs_delete_final_check(znode_t *zp, znode_t *dzp,
2520 2522 mode_t available_perms, cred_t *cr)
2521 2523 {
2522 2524 int error;
2523 2525 uid_t downer;
2524 2526
2525 2527 downer = zfs_fuid_map_id(dzp->z_zfsvfs, dzp->z_uid, cr, ZFS_OWNER);
2526 2528
2527 2529 error = secpolicy_vnode_access2(cr, ZTOV(dzp),
2528 2530 downer, available_perms, VWRITE|VEXEC);
2529 2531
↓ open down ↓ |
175 lines elided |
↑ open up ↑ |
2530 2532 if (error == 0)
2531 2533 error = zfs_sticky_remove_access(dzp, zp, cr);
2532 2534
2533 2535 return (error);
2534 2536 }
2535 2537
2536 2538 /*
2537 2539 * Determine whether Access should be granted/deny, without
2538 2540 * consulting least priv subsystem.
2539 2541 *
2540 - *
2541 2542 * The following chart is the recommended NFSv4 enforcement for
2542 2543 * ability to delete an object.
2543 2544 *
2544 2545 * -------------------------------------------------------
2545 2546 * | Parent Dir | Target Object Permissions |
2546 2547 * | permissions | |
2547 2548 * -------------------------------------------------------
2548 2549 * | | ACL Allows | ACL Denies| Delete |
2549 2550 * | | Delete | Delete | unspecified|
2550 2551 * -------------------------------------------------------
2551 2552 * | ACL Allows | Permit | Permit | Permit |
2552 2553 * | DELETE_CHILD | |
2553 2554 * -------------------------------------------------------
2554 2555 * | ACL Denies | Permit | Deny | Deny |
2555 2556 * | DELETE_CHILD | | | |
2556 2557 * -------------------------------------------------------
2557 2558 * | ACL specifies | | | |
2558 2559 * | only allow | Permit | Permit | Permit |
2559 2560 * | write and | | | |
2560 2561 * | execute | | | |
2561 2562 * -------------------------------------------------------
2562 2563 * | ACL denies | | | |
2563 2564 * | write and | Permit | Deny | Deny |
2564 2565 * | execute | | | |
2565 2566 * -------------------------------------------------------
2566 2567 * ^
2567 2568 * |
2568 2569 * No search privilege, can't even look up file?
2569 2570 *
2570 2571 */
2571 2572 int
2572 2573 zfs_zaccess_delete(znode_t *dzp, znode_t *zp, cred_t *cr)
2573 2574 {
2574 2575 uint32_t dzp_working_mode = 0;
2575 2576 uint32_t zp_working_mode = 0;
2576 2577 int dzp_error, zp_error;
2577 2578 mode_t available_perms;
2578 2579 boolean_t dzpcheck_privs = B_TRUE;
2579 2580 boolean_t zpcheck_privs = B_TRUE;
2580 2581
2581 2582 /*
2582 2583 * We want specific DELETE permissions to
2583 2584 * take precedence over WRITE/EXECUTE. We don't
2584 2585 * want an ACL such as this to mess us up.
2585 2586 * user:joe:write_data:deny,user:joe:delete:allow
2586 2587 *
2587 2588 * However, deny permissions may ultimately be overridden
2588 2589 * by secpolicy_vnode_access().
2589 2590 *
2590 2591 * We will ask for all of the necessary permissions and then
2591 2592 * look at the working modes from the directory and target object
2592 2593 * to determine what was found.
2593 2594 */
2594 2595
2595 2596 if (zp->z_pflags & (ZFS_IMMUTABLE | ZFS_NOUNLINK))
2596 2597 return (SET_ERROR(EPERM));
2597 2598
2598 2599 /*
2599 2600 * First row
2600 2601 * If the directory permissions allow the delete, we are done.
2601 2602 */
2602 2603 if ((dzp_error = zfs_zaccess_common(dzp, ACE_DELETE_CHILD,
2603 2604 &dzp_working_mode, &dzpcheck_privs, B_FALSE, cr)) == 0)
2604 2605 return (0);
2605 2606
2606 2607 /*
2607 2608 * If target object has delete permission then we are done
2608 2609 */
2609 2610 if ((zp_error = zfs_zaccess_common(zp, ACE_DELETE, &zp_working_mode,
2610 2611 &zpcheck_privs, B_FALSE, cr)) == 0)
2611 2612 return (0);
2612 2613
2613 2614 ASSERT(dzp_error && zp_error);
2614 2615
2615 2616 if (!dzpcheck_privs)
2616 2617 return (dzp_error);
2617 2618 if (!zpcheck_privs)
2618 2619 return (zp_error);
2619 2620
2620 2621 /*
2621 2622 * Second row
2622 2623 *
2623 2624 * If directory returns EACCES then delete_child was denied
2624 2625 * due to deny delete_child. In this case send the request through
2625 2626 * secpolicy_vnode_remove(). We don't use zfs_delete_final_check()
2626 2627 * since that *could* allow the delete based on write/execute permission
2627 2628 * and we want delete permissions to override write/execute.
2628 2629 */
2629 2630
2630 2631 if (dzp_error == EACCES)
2631 2632 return (secpolicy_vnode_remove(cr));
2632 2633
2633 2634 /*
2634 2635 * Third Row
2635 2636 * only need to see if we have write/execute on directory.
2636 2637 */
2637 2638
2638 2639 dzp_error = zfs_zaccess_common(dzp, ACE_EXECUTE|ACE_WRITE_DATA,
2639 2640 &dzp_working_mode, &dzpcheck_privs, B_FALSE, cr);
2640 2641
2641 2642 if (dzp_error != 0 && !dzpcheck_privs)
2642 2643 return (dzp_error);
2643 2644
2644 2645 /*
2645 2646 * Fourth row
2646 2647 */
2647 2648
2648 2649 available_perms = (dzp_working_mode & ACE_WRITE_DATA) ? 0 : VWRITE;
2649 2650 available_perms |= (dzp_working_mode & ACE_EXECUTE) ? 0 : VEXEC;
2650 2651
2651 2652 return (zfs_delete_final_check(zp, dzp, available_perms, cr));
2652 2653
2653 2654 }
2654 2655
2655 2656 int
2656 2657 zfs_zaccess_rename(znode_t *sdzp, znode_t *szp, znode_t *tdzp,
2657 2658 znode_t *tzp, cred_t *cr)
2658 2659 {
2659 2660 int add_perm;
2660 2661 int error;
2661 2662
2662 2663 if (szp->z_pflags & ZFS_AV_QUARANTINED)
2663 2664 return (SET_ERROR(EACCES));
2664 2665
2665 2666 add_perm = (ZTOV(szp)->v_type == VDIR) ?
2666 2667 ACE_ADD_SUBDIRECTORY : ACE_ADD_FILE;
2667 2668
2668 2669 /*
2669 2670 * Rename permissions are combination of delete permission +
2670 2671 * add file/subdir permission.
2671 2672 */
2672 2673
2673 2674 /*
2674 2675 * first make sure we do the delete portion.
2675 2676 *
2676 2677 * If that succeeds then check for add_file/add_subdir permissions
2677 2678 */
2678 2679
2679 2680 if (error = zfs_zaccess_delete(sdzp, szp, cr))
2680 2681 return (error);
2681 2682
2682 2683 /*
2683 2684 * If we have a tzp, see if we can delete it?
2684 2685 */
2685 2686 if (tzp) {
2686 2687 if (error = zfs_zaccess_delete(tdzp, tzp, cr))
2687 2688 return (error);
2688 2689 }
2689 2690
2690 2691 /*
2691 2692 * Now check for add permissions
2692 2693 */
2693 2694 error = zfs_zaccess(tdzp, add_perm, 0, B_FALSE, cr);
2694 2695
2695 2696 return (error);
2696 2697 }
↓ open down ↓ |
146 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX