acl_calc_mask.c (75185) | acl_calc_mask.c (75928) |
---|---|
1/* 2 * Copyright (c) 2001 Chris D. Faulhaber 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 * POSSIBILITY OF SUCH DAMAGE. 25 * | 1/* 2 * Copyright (c) 2001 Chris D. Faulhaber 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 * POSSIBILITY OF SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/lib/libc/posix1e/acl_calc_mask.c 75185 2001-04-04 18:00:52Z tmm $ | 26 * $FreeBSD: head/lib/libc/posix1e/acl_calc_mask.c 75928 2001-04-24 22:45:41Z jedgar $ |
27 */ 28 29#include <sys/types.h> 30#include "namespace.h" 31#include <sys/acl.h> 32#include "un-namespace.h" 33 34#include <errno.h> | 27 */ 28 29#include <sys/types.h> 30#include "namespace.h" 31#include <sys/acl.h> 32#include "un-namespace.h" 33 34#include <errno.h> |
35#include <stdio.h> |
|
35 36/* | 36 37/* |
37 * acl_calc_mask() calculates and set the permissions associated 38 * with the ACL_MASK ACL entry. If the ACL already contains an 39 * ACL_MASK entry, its permissions shall be overwritten; if not, 40 * one shall be added. | 38 * acl_calc_mask() (23.4.2): calculate and set the permissions 39 * associated with the ACL_MASK ACL entry. If the ACL already 40 * contains an ACL_MASK entry, its permissions shall be 41 * overwritten; if not, one shall be added. |
41 */ 42int 43acl_calc_mask(acl_t *acl_p) 44{ | 42 */ 43int 44acl_calc_mask(acl_t *acl_p) 45{ |
45 acl_t acl_new; 46 int group_obj, i, mask_mode, mask_num, other_obj, user_obj; | 46 struct acl *acl_int, *acl_int_new; 47 acl_t acl_new; 48 int i, mask_mode, mask_num; |
47 | 49 |
48 /* check args */ 49 if (!acl_p || !*acl_p || ((*acl_p)->acl_cnt < 3) || 50 ((*acl_p)->acl_cnt > ACL_MAX_ENTRIES)) { | 50 /* 51 * (23.4.2.4) requires acl_p to point to a pointer to a valid ACL. 52 * Since one of the primary reasons to use this function would be 53 * to calculate the appropriate mask to obtain a valid ACL, we only 54 * perform sanity checks here and validate the ACL prior to 55 * returning. 56 */ 57 if (!acl_p || !*acl_p) { |
51 errno = EINVAL; 52 return -1; 53 } | 58 errno = EINVAL; 59 return -1; 60 } |
61 acl_int = &(*acl_p)->ats_acl; 62 if ((acl_int->acl_cnt < 3) || (acl_int->acl_cnt > ACL_MAX_ENTRIES)) { 63 errno = EINVAL; 64 return -1; 65 } |
|
54 55 acl_new = acl_dup(*acl_p); 56 if (!acl_new) 57 return -1; | 66 67 acl_new = acl_dup(*acl_p); 68 if (!acl_new) 69 return -1; |
70 acl_int_new = &acl_new->ats_acl; |
|
58 | 71 |
59 user_obj = group_obj = other_obj = mask_mode = 0; | 72 mask_mode = 0; |
60 mask_num = -1; 61 62 /* gather permissions and find a mask entry */ | 73 mask_num = -1; 74 75 /* gather permissions and find a mask entry */ |
63 for (i = 0; i < acl_new->acl_cnt; i++) { 64 switch(acl_new->acl_entry[i].ae_tag) { 65 case ACL_USER_OBJ: 66 user_obj++; 67 break; 68 case ACL_OTHER: 69 other_obj++; 70 break; 71 case ACL_GROUP_OBJ: 72 group_obj++; 73 /* FALLTHROUGH */ 74 case ACL_GROUP: | 76 for (i = 0; i < acl_int_new->acl_cnt; i++) { 77 switch(acl_int_new->acl_entry[i].ae_tag) { |
75 case ACL_USER: | 78 case ACL_USER: |
79 case ACL_GROUP: 80 case ACL_GROUP_OBJ: |
|
76 mask_mode |= | 81 mask_mode |= |
77 acl_new->acl_entry[i].ae_perm & ACL_PERM_BITS; | 82 acl_int_new->acl_entry[i].ae_perm & ACL_PERM_BITS; |
78 break; 79 case ACL_MASK: 80 mask_num = i; 81 break; | 83 break; 84 case ACL_MASK: 85 mask_num = i; 86 break; |
82 default: 83 errno = EINVAL; 84 acl_free(acl_new); 85 return -1; 86 /* NOTREACHED */ | |
87 } 88 } | 87 } 88 } |
89 if ((user_obj != 1) || (group_obj != 1) || (other_obj != 1)) { 90 errno = EINVAL; 91 acl_free(acl_new); 92 return -1; 93 } | 89 |
94 /* if a mask entry already exists, overwrite the perms */ | 90 /* if a mask entry already exists, overwrite the perms */ |
95 if (mask_num != -1) { 96 acl_new->acl_entry[mask_num].ae_perm = mask_mode; 97 } else { | 91 if (mask_num != -1) 92 acl_int_new->acl_entry[mask_num].ae_perm = mask_mode; 93 else { |
98 /* if no mask exists, check acl_cnt... */ | 94 /* if no mask exists, check acl_cnt... */ |
99 if (acl_new->acl_cnt == ACL_MAX_ENTRIES) { 100 errno = EINVAL; 101 acl_free(acl_new); | 95 if (acl_int_new->acl_cnt == ACL_MAX_ENTRIES) { 96 errno = ENOMEM; |
102 return -1; 103 } 104 /* ...and add the mask entry */ | 97 return -1; 98 } 99 /* ...and add the mask entry */ |
105 acl_new->acl_entry[acl_new->acl_cnt].ae_tag = ACL_MASK; 106 acl_new->acl_entry[acl_new->acl_cnt].ae_id = 0; 107 acl_new->acl_entry[acl_new->acl_cnt].ae_perm = mask_mode; 108 acl_new->acl_cnt++; | 100 acl_int_new->acl_entry[acl_int_new->acl_cnt].ae_tag = ACL_MASK; 101 acl_int_new->acl_entry[acl_int_new->acl_cnt].ae_id = 102 ACL_UNDEFINED_ID; 103 acl_int_new->acl_entry[acl_int_new->acl_cnt].ae_perm = 104 mask_mode; 105 acl_int_new->acl_cnt++; |
109 } 110 111 if (acl_valid(acl_new) == -1) { 112 errno = EINVAL; 113 acl_free(acl_new); 114 return -1; 115 } 116 117 **acl_p = *acl_new; 118 acl_free(acl_new); 119 120 return 0; 121} | 106 } 107 108 if (acl_valid(acl_new) == -1) { 109 errno = EINVAL; 110 acl_free(acl_new); 111 return -1; 112 } 113 114 **acl_p = *acl_new; 115 acl_free(acl_new); 116 117 return 0; 118} |