From owner-p4-projects@FreeBSD.ORG Fri Jul 7 17:09:26 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 8FEA116A4DF; Fri, 7 Jul 2006 17:09:26 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 52CD316A4DA for ; Fri, 7 Jul 2006 17:09:26 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id E909243D49 for ; Fri, 7 Jul 2006 17:09:25 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k67H9P1e052314 for ; Fri, 7 Jul 2006 17:09:25 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k67H9P2P052310 for perforce@freebsd.org; Fri, 7 Jul 2006 17:09:25 GMT (envelope-from jhb@freebsd.org) Date: Fri, 7 Jul 2006 17:09:25 GMT Message-Id: <200607071709.k67H9P2P052310@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Cc: Subject: PERFORCE change 100903 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Jul 2006 17:09:26 -0000 http://perforce.freebsd.org/chv.cgi?CH=100903 Change 100903 by jhb@jhb_mutex on 2006/07/07 17:08:42 IFC @100899. Affected files ... .. //depot/projects/smpng/sys/conf/files#179 integrate .. //depot/projects/smpng/sys/geom/raid3/g_raid3_ctl.c#13 integrate .. //depot/projects/smpng/sys/kern/kern_acl.c#26 integrate .. //depot/projects/smpng/sys/kern/subr_acl_posix1e.c#2 integrate Differences ... ==== //depot/projects/smpng/sys/conf/files#179 (text+ko) ==== @@ -1,4 +1,4 @@ -# $FreeBSD: src/sys/conf/files,v 1.1127 2006/06/27 12:45:27 glebius Exp $ +# $FreeBSD: src/sys/conf/files,v 1.1128 2006/07/06 23:37:39 rwatson Exp $ # # The long compile-with and dependency lines are required because of # limitations in config: backslash-newline doesn't work in strings, and @@ -1329,6 +1329,7 @@ kern/sched_core.c optional sched_core kern/sched_ule.c optional sched_ule kern/serdev_if.m optional puc | scc +kern/subr_acl_posix1e.c standard kern/subr_autoconf.c standard kern/subr_blist.c standard kern/subr_bus.c standard ==== //depot/projects/smpng/sys/geom/raid3/g_raid3_ctl.c#13 (text+ko) ==== @@ -25,7 +25,7 @@ */ #include -__FBSDID("$FreeBSD: src/sys/geom/raid3/g_raid3_ctl.c,v 1.16 2006/04/10 10:32:22 pjd Exp $"); +__FBSDID("$FreeBSD: src/sys/geom/raid3/g_raid3_ctl.c,v 1.17 2006/07/07 14:32:27 pjd Exp $"); #include #include @@ -102,7 +102,6 @@ int *verify, *noverify; u_int n; - g_topology_assert(); nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); if (nargs == NULL) { gctl_error(req, "No '%s' argument.", "nargs"); ==== //depot/projects/smpng/sys/kern/kern_acl.c#26 (text+ko) ==== @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1999-2003 Robert N. M. Watson + * Copyright (c) 1999-2006 Robert N. M. Watson * All rights reserved. * * This software was developed by Robert Watson for the TrustedBSD Project. @@ -27,11 +27,13 @@ */ /* * Developed by the TrustedBSD Project. - * Support for POSIX.1e access control lists. + * + * ACL system calls and other functions common across different ACL types. + * Type-specific routines go into subr_acl_.c. */ #include -__FBSDID("$FreeBSD: src/sys/kern/kern_acl.c,v 1.47 2005/09/17 22:01:14 csjp Exp $"); +__FBSDID("$FreeBSD: src/sys/kern/kern_acl.c,v 1.48 2006/07/06 23:37:38 rwatson Exp $"); #include "opt_mac.h" @@ -50,8 +52,6 @@ #include #include #include -#include -#include #include #include @@ -65,586 +65,6 @@ acl_type_t type, struct acl *aclp); /* - * Implement a version of vaccess() that understands POSIX.1e ACL semantics. - * Return 0 on success, else an errno value. Should be merged into - * vaccess() eventually. - */ -int -vaccess_acl_posix1e(enum vtype type, uid_t file_uid, gid_t file_gid, - struct acl *acl, mode_t acc_mode, struct ucred *cred, int *privused) -{ - struct acl_entry *acl_other, *acl_mask; - mode_t dac_granted; - mode_t cap_granted; - mode_t acl_mask_granted; - int group_matched, i; - - /* - * Look for a normal, non-privileged way to access the file/directory - * as requested. If it exists, go with that. Otherwise, attempt - * to use privileges granted via cap_granted. In some cases, - * which privileges to use may be ambiguous due to "best match", - * in which case fall back on first match for the time being. - */ - if (privused != NULL) - *privused = 0; - - /* - * Determine privileges now, but don't apply until we've found - * a DAC entry that matches but has failed to allow access. - */ -#ifndef CAPABILITIES - if (suser_cred(cred, SUSER_ALLOWJAIL) == 0) - cap_granted = VALLPERM; - else - cap_granted = 0; -#else - cap_granted = 0; - - if (type == VDIR) { - if ((acc_mode & VEXEC) && !cap_check(cred, NULL, - CAP_DAC_READ_SEARCH, SUSER_ALLOWJAIL)) - cap_granted |= VEXEC; - } else { - if ((acc_mode & VEXEC) && !cap_check(cred, NULL, - CAP_DAC_EXECUTE, SUSER_ALLOWJAIL)) - cap_granted |= VEXEC; - } - - if ((acc_mode & VREAD) && !cap_check(cred, NULL, CAP_DAC_READ_SEARCH, - SUSER_ALLOWJAIL)) - cap_granted |= VREAD; - - if (((acc_mode & VWRITE) || (acc_mode & VAPPEND)) && - !cap_check(cred, NULL, CAP_DAC_WRITE, SUSER_ALLOWJAIL)) - cap_granted |= (VWRITE | VAPPEND); - - if ((acc_mode & VADMIN) && !cap_check(cred, NULL, CAP_FOWNER, - SUSER_ALLOWJAIL)) - cap_granted |= VADMIN; -#endif /* CAPABILITIES */ - - /* - * The owner matches if the effective uid associated with the - * credential matches that of the ACL_USER_OBJ entry. While we're - * doing the first scan, also cache the location of the ACL_MASK - * and ACL_OTHER entries, preventing some future iterations. - */ - acl_mask = acl_other = NULL; - for (i = 0; i < acl->acl_cnt; i++) { - switch (acl->acl_entry[i].ae_tag) { - case ACL_USER_OBJ: - if (file_uid != cred->cr_uid) - break; - dac_granted = 0; - dac_granted |= VADMIN; - if (acl->acl_entry[i].ae_perm & ACL_EXECUTE) - dac_granted |= VEXEC; - if (acl->acl_entry[i].ae_perm & ACL_READ) - dac_granted |= VREAD; - if (acl->acl_entry[i].ae_perm & ACL_WRITE) - dac_granted |= (VWRITE | VAPPEND); - if ((acc_mode & dac_granted) == acc_mode) - return (0); - if ((acc_mode & (dac_granted | cap_granted)) == - acc_mode) { - if (privused != NULL) - *privused = 1; - return (0); - } - goto error; - - case ACL_MASK: - acl_mask = &acl->acl_entry[i]; - break; - - case ACL_OTHER: - acl_other = &acl->acl_entry[i]; - break; - - default: - break; - } - } - - /* - * An ACL_OTHER entry should always exist in a valid access - * ACL. If it doesn't, then generate a serious failure. For now, - * this means a debugging message and EPERM, but in the future - * should probably be a panic. - */ - if (acl_other == NULL) { - /* - * XXX This should never happen - */ - printf("vaccess_acl_posix1e: ACL_OTHER missing\n"); - return (EPERM); - } - - /* - * Checks against ACL_USER, ACL_GROUP_OBJ, and ACL_GROUP fields - * are masked by an ACL_MASK entry, if any. As such, first identify - * the ACL_MASK field, then iterate through identifying potential - * user matches, then group matches. If there is no ACL_MASK, - * assume that the mask allows all requests to succeed. - */ - if (acl_mask != NULL) { - acl_mask_granted = 0; - if (acl_mask->ae_perm & ACL_EXECUTE) - acl_mask_granted |= VEXEC; - if (acl_mask->ae_perm & ACL_READ) - acl_mask_granted |= VREAD; - if (acl_mask->ae_perm & ACL_WRITE) - acl_mask_granted |= (VWRITE | VAPPEND); - } else - acl_mask_granted = VEXEC | VREAD | VWRITE | VAPPEND; - - /* - * Iterate through user ACL entries. Do checks twice, first - * without privilege, and then if a match is found but failed, - * a second time with privilege. - */ - - /* - * Check ACL_USER ACL entries. - */ - for (i = 0; i < acl->acl_cnt; i++) { - switch (acl->acl_entry[i].ae_tag) { - case ACL_USER: - if (acl->acl_entry[i].ae_id != cred->cr_uid) - break; - dac_granted = 0; - if (acl->acl_entry[i].ae_perm & ACL_EXECUTE) - dac_granted |= VEXEC; - if (acl->acl_entry[i].ae_perm & ACL_READ) - dac_granted |= VREAD; - if (acl->acl_entry[i].ae_perm & ACL_WRITE) - dac_granted |= (VWRITE | VAPPEND); - dac_granted &= acl_mask_granted; - if ((acc_mode & dac_granted) == acc_mode) - return (0); - if ((acc_mode & (dac_granted | cap_granted)) != - acc_mode) - goto error; - - if (privused != NULL) - *privused = 1; - return (0); - } - } - - /* - * Group match is best-match, not first-match, so find a - * "best" match. Iterate across, testing each potential group - * match. Make sure we keep track of whether we found a match - * or not, so that we know if we should try again with any - * available privilege, or if we should move on to ACL_OTHER. - */ - group_matched = 0; - for (i = 0; i < acl->acl_cnt; i++) { - switch (acl->acl_entry[i].ae_tag) { - case ACL_GROUP_OBJ: - if (!groupmember(file_gid, cred)) - break; - dac_granted = 0; - if (acl->acl_entry[i].ae_perm & ACL_EXECUTE) - dac_granted |= VEXEC; - if (acl->acl_entry[i].ae_perm & ACL_READ) - dac_granted |= VREAD; - if (acl->acl_entry[i].ae_perm & ACL_WRITE) - dac_granted |= (VWRITE | VAPPEND); - dac_granted &= acl_mask_granted; - - if ((acc_mode & dac_granted) == acc_mode) - return (0); - - group_matched = 1; - break; - - case ACL_GROUP: - if (!groupmember(acl->acl_entry[i].ae_id, cred)) - break; - dac_granted = 0; - if (acl->acl_entry[i].ae_perm & ACL_EXECUTE) - dac_granted |= VEXEC; - if (acl->acl_entry[i].ae_perm & ACL_READ) - dac_granted |= VREAD; - if (acl->acl_entry[i].ae_perm & ACL_WRITE) - dac_granted |= (VWRITE | VAPPEND); - dac_granted &= acl_mask_granted; - - if ((acc_mode & dac_granted) == acc_mode) - return (0); - - group_matched = 1; - break; - - default: - break; - } - } - - if (group_matched == 1) { - /* - * There was a match, but it did not grant rights via - * pure DAC. Try again, this time with privilege. - */ - for (i = 0; i < acl->acl_cnt; i++) { - switch (acl->acl_entry[i].ae_tag) { - case ACL_GROUP_OBJ: - if (!groupmember(file_gid, cred)) - break; - dac_granted = 0; - if (acl->acl_entry[i].ae_perm & ACL_EXECUTE) - dac_granted |= VEXEC; - if (acl->acl_entry[i].ae_perm & ACL_READ) - dac_granted |= VREAD; - if (acl->acl_entry[i].ae_perm & ACL_WRITE) - dac_granted |= (VWRITE | VAPPEND); - dac_granted &= acl_mask_granted; - - if ((acc_mode & (dac_granted | cap_granted)) != - acc_mode) - break; - - if (privused != NULL) - *privused = 1; - return (0); - - case ACL_GROUP: - if (!groupmember(acl->acl_entry[i].ae_id, - cred)) - break; - dac_granted = 0; - if (acl->acl_entry[i].ae_perm & ACL_EXECUTE) - dac_granted |= VEXEC; - if (acl->acl_entry[i].ae_perm & ACL_READ) - dac_granted |= VREAD; - if (acl->acl_entry[i].ae_perm & ACL_WRITE) - dac_granted |= (VWRITE | VAPPEND); - dac_granted &= acl_mask_granted; - - if ((acc_mode & (dac_granted | cap_granted)) != - acc_mode) - break; - - if (privused != NULL) - *privused = 1; - return (0); - - default: - break; - } - } - /* - * Even with privilege, group membership was not sufficient. - * Return failure. - */ - goto error; - } - - /* - * Fall back on ACL_OTHER. ACL_MASK is not applied to ACL_OTHER. - */ - dac_granted = 0; - if (acl_other->ae_perm & ACL_EXECUTE) - dac_granted |= VEXEC; - if (acl_other->ae_perm & ACL_READ) - dac_granted |= VREAD; - if (acl_other->ae_perm & ACL_WRITE) - dac_granted |= (VWRITE | VAPPEND); - - if ((acc_mode & dac_granted) == acc_mode) - return (0); - if ((acc_mode & (dac_granted | cap_granted)) == acc_mode) { - if (privused != NULL) - *privused = 1; - return (0); - } - -error: - return ((acc_mode & VADMIN) ? EPERM : EACCES); -} - -/* - * For the purposes of filesystems maintaining the _OBJ entries in an - * inode with a mode_t field, this routine converts a mode_t entry - * to an acl_perm_t. - */ -acl_perm_t -acl_posix1e_mode_to_perm(acl_tag_t tag, mode_t mode) -{ - acl_perm_t perm = 0; - - switch(tag) { - case ACL_USER_OBJ: - if (mode & S_IXUSR) - perm |= ACL_EXECUTE; - if (mode & S_IRUSR) - perm |= ACL_READ; - if (mode & S_IWUSR) - perm |= ACL_WRITE; - return (perm); - - case ACL_GROUP_OBJ: - if (mode & S_IXGRP) - perm |= ACL_EXECUTE; - if (mode & S_IRGRP) - perm |= ACL_READ; - if (mode & S_IWGRP) - perm |= ACL_WRITE; - return (perm); - - case ACL_OTHER: - if (mode & S_IXOTH) - perm |= ACL_EXECUTE; - if (mode & S_IROTH) - perm |= ACL_READ; - if (mode & S_IWOTH) - perm |= ACL_WRITE; - return (perm); - - default: - printf("acl_posix1e_mode_to_perm: invalid tag (%d)\n", tag); - return (0); - } -} - -/* - * Given inode information (uid, gid, mode), return an acl entry of the - * appropriate type. - */ -struct acl_entry -acl_posix1e_mode_to_entry(acl_tag_t tag, uid_t uid, gid_t gid, mode_t mode) -{ - struct acl_entry acl_entry; - - acl_entry.ae_tag = tag; - acl_entry.ae_perm = acl_posix1e_mode_to_perm(tag, mode); - switch(tag) { - case ACL_USER_OBJ: - acl_entry.ae_id = uid; - break; - - case ACL_GROUP_OBJ: - acl_entry.ae_id = gid; - break; - - case ACL_OTHER: - acl_entry.ae_id = ACL_UNDEFINED_ID; - break; - - default: - acl_entry.ae_id = ACL_UNDEFINED_ID; - printf("acl_posix1e_mode_to_entry: invalid tag (%d)\n", tag); - } - - return (acl_entry); -} - -/* - * Utility function to generate a file mode given appropriate ACL entries. - */ -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) -{ - mode_t mode; - - mode = 0; - if (acl_user_obj_entry->ae_perm & ACL_EXECUTE) - mode |= S_IXUSR; - if (acl_user_obj_entry->ae_perm & ACL_READ) - mode |= S_IRUSR; - if (acl_user_obj_entry->ae_perm & ACL_WRITE) - mode |= S_IWUSR; - if (acl_group_obj_entry->ae_perm & ACL_EXECUTE) - mode |= S_IXGRP; - if (acl_group_obj_entry->ae_perm & ACL_READ) - mode |= S_IRGRP; - if (acl_group_obj_entry->ae_perm & ACL_WRITE) - mode |= S_IWGRP; - if (acl_other_entry->ae_perm & ACL_EXECUTE) - mode |= S_IXOTH; - if (acl_other_entry->ae_perm & ACL_READ) - mode |= S_IROTH; - if (acl_other_entry->ae_perm & ACL_WRITE) - mode |= S_IWOTH; - - return (mode); -} - -/* - * Utility function to generate a file mode given a complete POSIX.1e - * access ACL. Note that if the ACL is improperly formed, this may - * result in a panic. - */ -mode_t -acl_posix1e_acl_to_mode(struct acl *acl) -{ - struct acl_entry *acl_mask, *acl_user_obj, *acl_group_obj, *acl_other; - int i; - - /* - * Find the ACL entries relevant to a POSIX permission mode. - */ - acl_user_obj = acl_group_obj = acl_other = acl_mask = NULL; - for (i = 0; i < acl->acl_cnt; i++) { - switch (acl->acl_entry[i].ae_tag) { - case ACL_USER_OBJ: - acl_user_obj = &acl->acl_entry[i]; - break; - - case ACL_GROUP_OBJ: - acl_group_obj = &acl->acl_entry[i]; - break; - - case ACL_OTHER: - acl_other = &acl->acl_entry[i]; - break; - - case ACL_MASK: - acl_mask = &acl->acl_entry[i]; - break; - - case ACL_USER: - case ACL_GROUP: - break; - - default: - panic("acl_posix1e_acl_to_mode: bad ae_tag"); - } - } - - if (acl_user_obj == NULL || acl_group_obj == NULL || acl_other == NULL) - panic("acl_posix1e_acl_to_mode: missing base ae_tags"); - - /* - * POSIX.1e specifies that if there is an ACL_MASK entry, we replace - * the mode "group" bits with its permissions. If there isn't, we - * use the ACL_GROUP_OBJ permissions. - */ - if (acl_mask != NULL) - return (acl_posix1e_perms_to_mode(acl_user_obj, acl_mask, - acl_other)); - else - return (acl_posix1e_perms_to_mode(acl_user_obj, acl_group_obj, - acl_other)); -} - -/* - * Perform a syntactic check of the ACL, sufficient to allow an - * implementing filesystem to determine if it should accept this and - * rely on the POSIX.1e ACL properties. - */ -int -acl_posix1e_check(struct acl *acl) -{ - int num_acl_user_obj, num_acl_user, num_acl_group_obj, num_acl_group; - int num_acl_mask, num_acl_other, i; - - /* - * Verify that the number of entries does not exceed the maximum - * defined for acl_t. - * Verify that the correct number of various sorts of ae_tags are - * present: - * Exactly one ACL_USER_OBJ - * Exactly one ACL_GROUP_OBJ - * Exactly one ACL_OTHER - * If any ACL_USER or ACL_GROUP entries appear, then exactly one - * ACL_MASK entry must also appear. - * Verify that all ae_perm entries are in ACL_PERM_BITS. - * Verify all ae_tag entries are understood by this implementation. - * Note: Does not check for uniqueness of qualifier (ae_id) field. - */ - num_acl_user_obj = num_acl_user = num_acl_group_obj = num_acl_group = - num_acl_mask = num_acl_other = 0; - if (acl->acl_cnt > ACL_MAX_ENTRIES || acl->acl_cnt < 0) - return (EINVAL); - for (i = 0; i < acl->acl_cnt; i++) { - /* - * Check for a valid tag. - */ - switch(acl->acl_entry[i].ae_tag) { - case ACL_USER_OBJ: - acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID; /* XXX */ - if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID) - return (EINVAL); - num_acl_user_obj++; - break; - case ACL_GROUP_OBJ: - acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID; /* XXX */ - if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID) - return (EINVAL); - num_acl_group_obj++; - break; - case ACL_USER: - if (acl->acl_entry[i].ae_id == ACL_UNDEFINED_ID) - return (EINVAL); - num_acl_user++; - break; - case ACL_GROUP: - if (acl->acl_entry[i].ae_id == ACL_UNDEFINED_ID) - return (EINVAL); - num_acl_group++; - break; - case ACL_OTHER: - acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID; /* XXX */ - if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID) - return (EINVAL); - num_acl_other++; - break; - case ACL_MASK: - acl->acl_entry[i].ae_id = ACL_UNDEFINED_ID; /* XXX */ - if (acl->acl_entry[i].ae_id != ACL_UNDEFINED_ID) - return (EINVAL); - num_acl_mask++; - break; - default: - return (EINVAL); - } - /* - * Check for valid perm entries. - */ - if ((acl->acl_entry[i].ae_perm | ACL_PERM_BITS) != - ACL_PERM_BITS) - return (EINVAL); - } - if ((num_acl_user_obj != 1) || (num_acl_group_obj != 1) || - (num_acl_other != 1) || (num_acl_mask != 0 && num_acl_mask != 1)) - return (EINVAL); - if (((num_acl_group != 0) || (num_acl_user != 0)) && - (num_acl_mask != 1)) - return (EINVAL); - return (0); -} - -/* - * Given a requested mode for a new object, and a default ACL, combine - * the two to produce a new mode. Be careful not to clear any bits that - * aren't intended to be affected by the POSIX.1e ACL. Eventually, - * this might also take the cmask as an argument, if we push that down - * into per-filesystem-code. - */ -mode_t -acl_posix1e_newfilemode(mode_t cmode, struct acl *dacl) -{ - mode_t mode; - - mode = cmode; - /* - * The current composition policy is that a permission bit must - * be set in *both* the ACL and the requested creation mode for - * it to appear in the resulting mode/ACL. First clear any - * possibly effected bits, then reconstruct. - */ - mode &= ACL_PRESERVE_MASK; - mode |= (ACL_OVERRIDE_MASK & cmode & acl_posix1e_acl_to_mode(dacl)); - - return (mode); -} - -/* * These calls wrap the real vnode operations, and are called by the * syscall code once the syscall has converted the path or file * descriptor to a vnode (unlocked). The aclp pointer is assumed ==== //depot/projects/smpng/sys/kern/subr_acl_posix1e.c#2 (text+ko) ==== @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1999-2003 Robert N. M. Watson + * Copyright (c) 1999-2006 Robert N. M. Watson * All rights reserved. * * This software was developed by Robert Watson for the TrustedBSD Project. @@ -27,43 +27,23 @@ */ /* * Developed by the TrustedBSD Project. - * Support for POSIX.1e access control lists. + * + * ACL support routines specific to POSIX.1e access control lists. These are + * utility routines for code common across file systems implementing POSIX.1e + * ACLs. */ #include -__FBSDID("$FreeBSD: src/sys/kern/subr_acl_posix1e.c,v 1.47 2005/09/17 22:01:14 csjp Exp $"); - -#include "opt_mac.h" +__FBSDID("$FreeBSD: src/sys/kern/subr_acl_posix1e.c,v 1.49 2006/07/06 23:37:38 rwatson Exp $"); #include #include -#include -#include -#include -#include #include #include -#include -#include -#include -#include -#include -#include -#include #include #include #include -#include - -uma_zone_t acl_zone; -static int vacl_set_acl(struct thread *td, struct vnode *vp, - acl_type_t type, struct acl *aclp); -static int vacl_get_acl(struct thread *td, struct vnode *vp, - acl_type_t type, struct acl *aclp); -static int vacl_aclcheck(struct thread *td, struct vnode *vp, - acl_type_t type, struct acl *aclp); - /* * Implement a version of vaccess() that understands POSIX.1e ACL semantics. * Return 0 on success, else an errno value. Should be merged into @@ -643,394 +623,3 @@ return (mode); } - -/* - * These calls wrap the real vnode operations, and are called by the - * syscall code once the syscall has converted the path or file - * descriptor to a vnode (unlocked). The aclp pointer is assumed - * still to point to userland, so this should not be consumed within - * the kernel except by syscall code. Other code should directly - * invoke VOP_{SET,GET}ACL. - */ - -/* - * Given a vnode, set its ACL. - */ -static int -vacl_set_acl(struct thread *td, struct vnode *vp, acl_type_t type, - struct acl *aclp) -{ - struct acl inkernacl; - struct mount *mp; - int error; - - error = copyin(aclp, &inkernacl, sizeof(struct acl)); - if (error) - return(error); - error = vn_start_write(vp, &mp, V_WAIT | PCATCH); - if (error != 0) - return (error); - VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE); - vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); -#ifdef MAC - error = mac_check_vnode_setacl(td->td_ucred, vp, type, &inkernacl); - if (error != 0) - goto out; -#endif - error = VOP_SETACL(vp, type, &inkernacl, td->td_ucred, td); -#ifdef MAC -out: -#endif - VOP_UNLOCK(vp, 0, td); - vn_finished_write(mp); - return(error); -} - -/* - * Given a vnode, get its ACL. - */ -static int -vacl_get_acl(struct thread *td, struct vnode *vp, acl_type_t type, - struct acl *aclp) -{ - struct acl inkernelacl; - int error; - - VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE); - vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); -#ifdef MAC - error = mac_check_vnode_getacl(td->td_ucred, vp, type); - if (error != 0) - goto out; -#endif - error = VOP_GETACL(vp, type, &inkernelacl, td->td_ucred, td); -#ifdef MAC -out: -#endif - VOP_UNLOCK(vp, 0, td); - if (error == 0) - error = copyout(&inkernelacl, aclp, sizeof(struct acl)); - return (error); -} - -/* - * Given a vnode, delete its ACL. - */ -static int -vacl_delete(struct thread *td, struct vnode *vp, acl_type_t type) -{ - struct mount *mp; - int error; - - error = vn_start_write(vp, &mp, V_WAIT | PCATCH); - if (error) - return (error); - VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE); - vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); -#ifdef MAC - error = mac_check_vnode_deleteacl(td->td_ucred, vp, type); - if (error) - goto out; -#endif - error = VOP_SETACL(vp, type, 0, td->td_ucred, td); -#ifdef MAC -out: -#endif - VOP_UNLOCK(vp, 0, td); - vn_finished_write(mp); - return (error); -} - -/* - * Given a vnode, check whether an ACL is appropriate for it - */ -static int -vacl_aclcheck(struct thread *td, struct vnode *vp, acl_type_t type, - struct acl *aclp) -{ - struct acl inkernelacl; - int error; - - error = copyin(aclp, &inkernelacl, sizeof(struct acl)); - if (error) - return(error); - error = VOP_ACLCHECK(vp, type, &inkernelacl, td->td_ucred, td); - return (error); -} - -/* - * syscalls -- convert the path/fd to a vnode, and call vacl_whatever. - * Don't need to lock, as the vacl_ code will get/release any locks - * required. - */ - -/* - * Given a file path, get an ACL for it - * - * MPSAFE - */ -int -__acl_get_file(struct thread *td, struct __acl_get_file_args *uap) -{ - struct nameidata nd; - int vfslocked, error; - - NDINIT(&nd, LOOKUP, MPSAFE|FOLLOW, UIO_USERSPACE, uap->path, td); - error = namei(&nd); - vfslocked = NDHASGIANT(&nd); - if (error == 0) { - error = vacl_get_acl(td, nd.ni_vp, uap->type, uap->aclp); - NDFREE(&nd, 0); - } - VFS_UNLOCK_GIANT(vfslocked); - return (error); -} - -/* - * Given a file path, get an ACL for it; don't follow links. - * - * MPSAFE - */ -int -__acl_get_link(struct thread *td, struct __acl_get_link_args *uap) -{ - struct nameidata nd; - int vfslocked, error; - - NDINIT(&nd, LOOKUP, MPSAFE|NOFOLLOW, UIO_USERSPACE, uap->path, td); - error = namei(&nd); - vfslocked = NDHASGIANT(&nd); - if (error == 0) { - error = vacl_get_acl(td, nd.ni_vp, uap->type, uap->aclp); - NDFREE(&nd, 0); - } - VFS_UNLOCK_GIANT(vfslocked); - return (error); -} - -/* - * Given a file path, set an ACL for it - * - * MPSAFE - */ -int -__acl_set_file(struct thread *td, struct __acl_set_file_args *uap) -{ - struct nameidata nd; - int vfslocked, error; - - NDINIT(&nd, LOOKUP, MPSAFE|FOLLOW, UIO_USERSPACE, uap->path, td); - error = namei(&nd); - vfslocked = NDHASGIANT(&nd); - if (error == 0) { - error = vacl_set_acl(td, nd.ni_vp, uap->type, uap->aclp); - NDFREE(&nd, 0); - } - VFS_UNLOCK_GIANT(vfslocked); - return (error); -} - -/* - * Given a file path, set an ACL for it; don't follow links. - * - * MPSAFE - */ -int -__acl_set_link(struct thread *td, struct __acl_set_link_args *uap) -{ - struct nameidata nd; - int vfslocked, error; - - NDINIT(&nd, LOOKUP, MPSAFE|NOFOLLOW, UIO_USERSPACE, uap->path, td); - error = namei(&nd); - vfslocked = NDHASGIANT(&nd); - if (error == 0) { - error = vacl_set_acl(td, nd.ni_vp, uap->type, uap->aclp); - NDFREE(&nd, 0); - } - VFS_UNLOCK_GIANT(vfslocked); - return (error); -} - -/* - * Given a file descriptor, get an ACL for it - * - * MPSAFE - */ -int -__acl_get_fd(struct thread *td, struct __acl_get_fd_args *uap) -{ - struct file *fp; - int vfslocked, error; - - error = getvnode(td->td_proc->p_fd, uap->filedes, &fp); - if (error == 0) { - vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount); - error = vacl_get_acl(td, fp->f_vnode, uap->type, uap->aclp); - fdrop(fp, td); - VFS_UNLOCK_GIANT(vfslocked); - } - return (error); -} - -/* - * Given a file descriptor, set an ACL for it - * - * MPSAFE - */ -int -__acl_set_fd(struct thread *td, struct __acl_set_fd_args *uap) -{ - struct file *fp; - int vfslocked, error; - - error = getvnode(td->td_proc->p_fd, uap->filedes, &fp); - if (error == 0) { - vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount); - error = vacl_set_acl(td, fp->f_vnode, uap->type, uap->aclp); - fdrop(fp, td); - VFS_UNLOCK_GIANT(vfslocked); - } - return (error); -} - -/* - * Given a file path, delete an ACL from it. - * - * MPSAFE - */ -int -__acl_delete_file(struct thread *td, struct __acl_delete_file_args *uap) -{ - struct nameidata nd; - int vfslocked, error; - - NDINIT(&nd, LOOKUP, MPSAFE|FOLLOW, UIO_USERSPACE, uap->path, td); - error = namei(&nd); - vfslocked = NDHASGIANT(&nd); - if (error == 0) { >>> TRUNCATED FOR MAIL (1000 lines) <<<