36 #include <sys/cdefs.h>
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/mount.h>
43 #include <sys/vnode.h>
44 #include <sys/errno.h>
56 struct acl *acl, accmode_t
accmode,
struct ucred *cred,
int *privused)
58 struct acl_entry *acl_other, *acl_mask;
59 accmode_t dac_granted;
60 accmode_t priv_granted;
61 accmode_t acl_mask_granted;
64 KASSERT((accmode & ~(VEXEC | VWRITE | VREAD | VADMIN | VAPPEND)) == 0,
65 (
"invalid bit in accmode"));
66 KASSERT((accmode & VAPPEND) == 0 || (accmode & VWRITE),
67 (
"VAPPEND without VWRITE"));
91 priv_granted |= VEXEC;
99 (S_IXUSR | S_IXGRP | S_IXOTH)) != 0 &&
101 priv_granted |= VEXEC;
105 priv_granted |= VREAD;
107 if (((accmode & VWRITE) || (accmode & VAPPEND)) &&
109 priv_granted |= (VWRITE | VAPPEND);
112 priv_granted |= VADMIN;
120 acl_mask = acl_other = NULL;
121 for (i = 0; i < acl->acl_cnt; i++) {
122 switch (acl->acl_entry[i].ae_tag) {
124 if (file_uid != cred->cr_uid)
127 dac_granted |= VADMIN;
128 if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
129 dac_granted |= VEXEC;
130 if (acl->acl_entry[i].ae_perm & ACL_READ)
131 dac_granted |= VREAD;
132 if (acl->acl_entry[i].ae_perm & ACL_WRITE)
133 dac_granted |= (VWRITE | VAPPEND);
134 if ((accmode & dac_granted) ==
accmode)
140 if ((accmode & (dac_granted | priv_granted)) ==
142 if (privused != NULL)
149 acl_mask = &acl->acl_entry[i];
153 acl_other = &acl->acl_entry[i];
167 if (acl_other == NULL) {
171 printf(
"vaccess_acl_posix1e: ACL_OTHER missing\n");
182 if (acl_mask != NULL) {
183 acl_mask_granted = 0;
184 if (acl_mask->ae_perm & ACL_EXECUTE)
185 acl_mask_granted |= VEXEC;
186 if (acl_mask->ae_perm & ACL_READ)
187 acl_mask_granted |= VREAD;
188 if (acl_mask->ae_perm & ACL_WRITE)
189 acl_mask_granted |= (VWRITE | VAPPEND);
191 acl_mask_granted = VEXEC | VREAD | VWRITE | VAPPEND;
198 for (i = 0; i < acl->acl_cnt; i++) {
199 switch (acl->acl_entry[i].ae_tag) {
201 if (acl->acl_entry[i].ae_id != cred->cr_uid)
204 if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
205 dac_granted |= VEXEC;
206 if (acl->acl_entry[i].ae_perm & ACL_READ)
207 dac_granted |= VREAD;
208 if (acl->acl_entry[i].ae_perm & ACL_WRITE)
209 dac_granted |= (VWRITE | VAPPEND);
210 dac_granted &= acl_mask_granted;
211 if ((accmode & dac_granted) ==
accmode)
216 if ((accmode & (dac_granted | priv_granted)) !=
220 if (privused != NULL)
234 for (i = 0; i < acl->acl_cnt; i++) {
235 switch (acl->acl_entry[i].ae_tag) {
240 if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
241 dac_granted |= VEXEC;
242 if (acl->acl_entry[i].ae_perm & ACL_READ)
243 dac_granted |= VREAD;
244 if (acl->acl_entry[i].ae_perm & ACL_WRITE)
245 dac_granted |= (VWRITE | VAPPEND);
246 dac_granted &= acl_mask_granted;
248 if ((accmode & dac_granted) ==
accmode)
258 if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
259 dac_granted |= VEXEC;
260 if (acl->acl_entry[i].ae_perm & ACL_READ)
261 dac_granted |= VREAD;
262 if (acl->acl_entry[i].ae_perm & ACL_WRITE)
263 dac_granted |= (VWRITE | VAPPEND);
264 dac_granted &= acl_mask_granted;
266 if ((accmode & dac_granted) ==
accmode)
277 if (group_matched == 1) {
282 for (i = 0; i < acl->acl_cnt; i++) {
283 switch (acl->acl_entry[i].ae_tag) {
288 if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
289 dac_granted |= VEXEC;
290 if (acl->acl_entry[i].ae_perm & ACL_READ)
291 dac_granted |= VREAD;
292 if (acl->acl_entry[i].ae_perm & ACL_WRITE)
293 dac_granted |= (VWRITE | VAPPEND);
294 dac_granted &= acl_mask_granted;
299 if ((accmode & (dac_granted | priv_granted))
303 if (privused != NULL)
312 if (acl->acl_entry[i].ae_perm & ACL_EXECUTE)
313 dac_granted |= VEXEC;
314 if (acl->acl_entry[i].ae_perm & ACL_READ)
315 dac_granted |= VREAD;
316 if (acl->acl_entry[i].ae_perm & ACL_WRITE)
317 dac_granted |= (VWRITE | VAPPEND);
318 dac_granted &= acl_mask_granted;
323 if ((accmode & (dac_granted | priv_granted))
327 if (privused != NULL)
346 if (acl_other->ae_perm & ACL_EXECUTE)
347 dac_granted |= VEXEC;
348 if (acl_other->ae_perm & ACL_READ)
349 dac_granted |= VREAD;
350 if (acl_other->ae_perm & ACL_WRITE)
351 dac_granted |= (VWRITE | VAPPEND);
353 if ((accmode & dac_granted) ==
accmode)
358 if ((accmode & (dac_granted | priv_granted)) == accmode) {
359 if (privused != NULL)
365 return ((accmode & VADMIN) ? EPERM : EACCES);
407 printf(
"acl_posix1e_mode_to_perm: invalid tag (%d)\n", tag);
419 struct acl_entry acl_entry;
421 acl_entry.ae_tag = tag;
423 acl_entry.ae_entry_type = 0;
424 acl_entry.ae_flags = 0;
427 acl_entry.ae_id = uid;
431 acl_entry.ae_id = gid;
435 acl_entry.ae_id = ACL_UNDEFINED_ID;
439 acl_entry.ae_id = ACL_UNDEFINED_ID;
440 printf(
"acl_posix1e_mode_to_entry: invalid tag (%d)\n", tag);
451 struct acl_entry *acl_group_obj_entry,
struct acl_entry *acl_other_entry)
456 if (acl_user_obj_entry->ae_perm & ACL_EXECUTE)
458 if (acl_user_obj_entry->ae_perm & ACL_READ)
460 if (acl_user_obj_entry->ae_perm & ACL_WRITE)
462 if (acl_group_obj_entry->ae_perm & ACL_EXECUTE)
464 if (acl_group_obj_entry->ae_perm & ACL_READ)
466 if (acl_group_obj_entry->ae_perm & ACL_WRITE)
468 if (acl_other_entry->ae_perm & ACL_EXECUTE)
470 if (acl_other_entry->ae_perm & ACL_READ)
472 if (acl_other_entry->ae_perm & ACL_WRITE)
486 struct acl_entry *acl_mask, *acl_user_obj, *acl_group_obj, *acl_other;
492 acl_user_obj = acl_group_obj = acl_other = acl_mask = NULL;
493 for (i = 0; i < acl->acl_cnt; i++) {
494 switch (acl->acl_entry[i].ae_tag) {
496 acl_user_obj = &acl->acl_entry[i];
500 acl_group_obj = &acl->acl_entry[i];
504 acl_other = &acl->acl_entry[i];
508 acl_mask = &acl->acl_entry[i];
516 panic(
"acl_posix1e_acl_to_mode: bad ae_tag");
520 if (acl_user_obj == NULL || acl_group_obj == NULL || acl_other == NULL)
521 panic(
"acl_posix1e_acl_to_mode: missing base ae_tags");
528 if (acl_mask != NULL)
544 int num_acl_user_obj, num_acl_user, num_acl_group_obj, num_acl_group;
545 int num_acl_mask, num_acl_other, i;
565 num_acl_user_obj = num_acl_user = num_acl_group_obj = num_acl_group =
566 num_acl_mask = num_acl_other = 0;
567 if (acl->acl_cnt > ACL_MAX_ENTRIES)
569 for (i = 0; i < acl->acl_cnt; i++) {
573 switch(acl->acl_entry[i].ae_tag) {
575 acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID;
576 if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID)
581 acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID;
582 if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID)
587 if (acl->acl_entry[i].ae_id == ACL_UNDEFINED_ID)
592 if (acl->acl_entry[i].ae_id == ACL_UNDEFINED_ID)
597 acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID;
598 if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID)
603 acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID;
604 if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID)
614 if ((acl->acl_entry[i].ae_perm | ACL_PERM_BITS) !=
618 if ((num_acl_user_obj != 1) || (num_acl_group_obj != 1) ||
619 (num_acl_other != 1) || (num_acl_mask != 0 && num_acl_mask != 1))
621 if (((num_acl_group != 0) || (num_acl_user != 0)) &&
646 mode &= ACL_PRESERVE_MASK;
int priv_check_cred(struct ucred *cred, int priv, int flags)
int vaccess_acl_posix1e(enum vtype type, uid_t file_uid, gid_t file_gid, struct acl *acl, accmode_t accmode, struct ucred *cred, int *privused)
mode_t acl_posix1e_acl_to_mode(struct acl *acl)
void panic(const char *fmt,...)
int acl_posix1e_check(struct acl *acl)
struct acl_entry acl_posix1e_mode_to_entry(acl_tag_t tag, uid_t uid, gid_t gid, mode_t mode)
mode_t acl_posix1e_perms_to_mode(struct acl_entry *acl_user_obj_entry, struct acl_entry *acl_group_obj_entry, struct acl_entry *acl_other_entry)
int groupmember(gid_t gid, struct ucred *cred)
int printf(const char *fmt,...)
acl_perm_t acl_posix1e_mode_to_perm(acl_tag_t tag, mode_t mode)
mode_t acl_posix1e_newfilemode(mode_t cmode, struct acl *dacl)