acl_calc_mask.c (75928) | acl_calc_mask.c (90781) |
---|---|
1/* | 1/* |
2 * Copyright (c) 2001 Chris D. Faulhaber | 2 * Copyright (c) 2001-2002 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 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright --- 7 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 * | 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 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright --- 7 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 75928 2001-04-24 22:45:41Z jedgar $ | 26 * $FreeBSD: head/lib/libc/posix1e/acl_calc_mask.c 90781 2002-02-17 20:05:20Z 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> --- 14 unchanged lines hidden (view full) --- 49 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 */ | 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> --- 14 unchanged lines hidden (view full) --- 49 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) { | 57 if (acl_p == NULL || *acl_p == NULL) { |
58 errno = EINVAL; | 58 errno = EINVAL; |
59 return -1; | 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; | 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; | 64 return (-1); |
65 } 66 67 acl_new = acl_dup(*acl_p); | 65 } 66 67 acl_new = acl_dup(*acl_p); |
68 if (!acl_new) 69 return -1; | 68 if (acl_new == NULL) 69 return (-1); |
70 acl_int_new = &acl_new->ats_acl; 71 72 mask_mode = 0; 73 mask_num = -1; 74 75 /* gather permissions and find a mask entry */ 76 for (i = 0; i < acl_int_new->acl_cnt; i++) { 77 switch(acl_int_new->acl_entry[i].ae_tag) { --- 11 unchanged lines hidden (view full) --- 89 90 /* if a mask entry already exists, overwrite the perms */ 91 if (mask_num != -1) 92 acl_int_new->acl_entry[mask_num].ae_perm = mask_mode; 93 else { 94 /* if no mask exists, check acl_cnt... */ 95 if (acl_int_new->acl_cnt == ACL_MAX_ENTRIES) { 96 errno = ENOMEM; | 70 acl_int_new = &acl_new->ats_acl; 71 72 mask_mode = 0; 73 mask_num = -1; 74 75 /* gather permissions and find a mask entry */ 76 for (i = 0; i < acl_int_new->acl_cnt; i++) { 77 switch(acl_int_new->acl_entry[i].ae_tag) { --- 11 unchanged lines hidden (view full) --- 89 90 /* if a mask entry already exists, overwrite the perms */ 91 if (mask_num != -1) 92 acl_int_new->acl_entry[mask_num].ae_perm = mask_mode; 93 else { 94 /* if no mask exists, check acl_cnt... */ 95 if (acl_int_new->acl_cnt == ACL_MAX_ENTRIES) { 96 errno = ENOMEM; |
97 return -1; | 97 return (-1); |
98 } 99 /* ...and add the mask entry */ 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++; 106 } 107 108 if (acl_valid(acl_new) == -1) { 109 errno = EINVAL; 110 acl_free(acl_new); | 98 } 99 /* ...and add the mask entry */ 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++; 106 } 107 108 if (acl_valid(acl_new) == -1) { 109 errno = EINVAL; 110 acl_free(acl_new); |
111 return -1; | 111 return (-1); |
112 } 113 114 **acl_p = *acl_new; 115 acl_free(acl_new); 116 | 112 } 113 114 **acl_p = *acl_new; 115 acl_free(acl_new); 116 |
117 return 0; | 117 return (0); |
118} | 118} |