remove.c (74465) | remove.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/bin/setfacl/remove.c 74465 2001-03-19 18:09:25Z rwatson $ | 26 * $FreeBSD: head/bin/setfacl/remove.c 75928 2001-04-24 22:45:41Z jedgar $ |
27 */ 28 29#include <sys/types.h> 30#include <sys/acl.h> 31#include <sys/stat.h> 32 33#include <err.h> 34#include <stdio.h> 35#include <string.h> 36#include <sysexits.h> 37 38#include "setfacl.h" 39 40/* remove ACL entries from an ACL */ 41int 42remove_acl(acl_t acl, acl_t *prev_acl) 43{ | 27 */ 28 29#include <sys/types.h> 30#include <sys/acl.h> 31#include <sys/stat.h> 32 33#include <err.h> 34#include <stdio.h> 35#include <string.h> 36#include <sysexits.h> 37 38#include "setfacl.h" 39 40/* remove ACL entries from an ACL */ 41int 42remove_acl(acl_t acl, acl_t *prev_acl) 43{ |
44 acl_t acl_new; 45 int carried_error, i; | 44 acl_entry_t entry; 45 acl_t acl_new; 46 acl_tag_t tag; 47 int carried_error, entry_id; |
46 47 carried_error = 0; 48 49 if (acl_type == ACL_TYPE_ACCESS) 50 acl_new = acl_dup(prev_acl[0]); 51 else 52 acl_new = acl_dup(prev_acl[1]); 53 if (!acl_new) 54 err(EX_OSERR, "acl_dup() failed"); 55 | 48 49 carried_error = 0; 50 51 if (acl_type == ACL_TYPE_ACCESS) 52 acl_new = acl_dup(prev_acl[0]); 53 else 54 acl_new = acl_dup(prev_acl[1]); 55 if (!acl_new) 56 err(EX_OSERR, "acl_dup() failed"); 57 |
58 tag = ACL_UNDEFINED_TAG; 59 |
|
56 /* find and delete the entry */ | 60 /* find and delete the entry */ |
57 for (i = 0; i < acl->acl_cnt; i++) { 58 if (acl->acl_entry[i].ae_tag == ACL_MASK) | 61 entry_id = ACL_FIRST_ENTRY; 62 while (acl_get_entry(acl, entry_id, &entry) == 1) { 63 entry_id = ACL_NEXT_ENTRY; 64 if (acl_get_tag_type(entry, &tag) == -1) 65 err(1, "acl_get_tag_type() failed"); 66 if (tag == ACL_MASK) |
59 have_mask++; | 67 have_mask++; |
60 if (acl_delete_entry(acl_new, &acl->acl_entry[i]) == -1) { | 68 if (acl_delete_entry(acl_new, entry) == -1) { |
61 carried_error++; 62 warnx("cannot remove non-existent acl entry"); 63 } 64 } 65 66 if (acl_type == ACL_TYPE_ACCESS) { 67 acl_free(prev_acl[0]); 68 prev_acl[0] = acl_new; --- 9 unchanged lines hidden (view full) --- 78} 79 80/* remove default entries */ 81int 82remove_default(acl_t *prev_acl) 83{ 84 85 if (prev_acl[1]) { | 69 carried_error++; 70 warnx("cannot remove non-existent acl entry"); 71 } 72 } 73 74 if (acl_type == ACL_TYPE_ACCESS) { 75 acl_free(prev_acl[0]); 76 prev_acl[0] = acl_new; --- 9 unchanged lines hidden (view full) --- 86} 87 88/* remove default entries */ 89int 90remove_default(acl_t *prev_acl) 91{ 92 93 if (prev_acl[1]) { |
86 bzero(prev_acl[1], sizeof(struct acl)); 87 prev_acl[1]->acl_cnt = 0; | 94 acl_free(prev_acl[1]); 95 prev_acl[1] = acl_init(ACL_MAX_ENTRIES); 96 if (!prev_acl[1]) 97 err(1, "acl_init() failed"); |
88 } else { 89 warn("cannot remove default ACL"); 90 return -1; 91 } 92 return 0; 93} 94 95/* remove extended entries */ 96void 97remove_ext(acl_t *prev_acl) 98{ 99 acl_t acl_new, acl_old; | 98 } else { 99 warn("cannot remove default ACL"); 100 return -1; 101 } 102 return 0; 103} 104 105/* remove extended entries */ 106void 107remove_ext(acl_t *prev_acl) 108{ 109 acl_t acl_new, acl_old; |
100 acl_perm_t group_perm, mask_perm; 101 int have_mask_entry, i; | 110 acl_entry_t entry, entry_new; 111 acl_permset_t perm; 112 acl_tag_t tag; 113 int entry_id, have_mask_entry; |
102 103 if (acl_type == ACL_TYPE_ACCESS) 104 acl_old = acl_dup(prev_acl[0]); 105 else 106 acl_old = acl_dup(prev_acl[1]); 107 if (!acl_old) 108 err(EX_OSERR, "acl_dup() failed"); 109 | 114 115 if (acl_type == ACL_TYPE_ACCESS) 116 acl_old = acl_dup(prev_acl[0]); 117 else 118 acl_old = acl_dup(prev_acl[1]); 119 if (!acl_old) 120 err(EX_OSERR, "acl_dup() failed"); 121 |
110 group_perm = mask_perm = 0; | |
111 have_mask_entry = 0; 112 acl_new = acl_init(ACL_MAX_ENTRIES); 113 if (!acl_new) 114 err(EX_OSERR, "%s", "acl_init() failed"); | 122 have_mask_entry = 0; 123 acl_new = acl_init(ACL_MAX_ENTRIES); 124 if (!acl_new) 125 err(EX_OSERR, "%s", "acl_init() failed"); |
126 tag = ACL_UNDEFINED_TAG; |
|
115 116 /* only save the default user/group/other entries */ | 127 128 /* only save the default user/group/other entries */ |
117 for (i = 0; i < acl_old->acl_cnt; i++) 118 switch(acl_old->acl_entry[i].ae_tag) { | 129 entry_id = ACL_FIRST_ENTRY; 130 while (acl_get_entry(acl_old, entry_id, &entry) == 1) { 131 entry_id = ACL_NEXT_ENTRY; 132 133 if (acl_get_tag_type(entry, &tag) == -1) 134 err(1, "acl_get_tag_type() failed"); 135 136 switch(tag) { |
119 case ACL_USER_OBJ: | 137 case ACL_USER_OBJ: |
120 acl_new->acl_entry[0] = acl_old->acl_entry[i]; 121 break; | |
122 case ACL_GROUP_OBJ: | 138 case ACL_GROUP_OBJ: |
123 acl_new->acl_entry[1] = acl_old->acl_entry[i]; 124 group_perm = acl_old->acl_entry[i].ae_perm; | 139 case ACL_OTHER: 140 if (acl_get_tag_type(entry, &tag) == -1) 141 err(1, "acl_get_tag_type() failed"); 142 if (acl_get_permset(entry, &perm) == -1) 143 err(1, "acl_get_permset() failed"); 144 if (acl_create_entry(&acl_new, &entry_new) == -1) 145 err(1, "acl_create_entry() failed"); 146 if (acl_set_tag_type(entry_new, tag) == -1) 147 err(1, "acl_set_tag_type() failed"); 148 if (acl_set_permset(entry_new, perm) == -1) 149 err(1, "acl_get_permset() failed"); 150 if (acl_copy_entry(entry_new, entry) == -1) 151 err(1, "acl_copy_entry() failed"); |
125 break; | 152 break; |
126 case ACL_OTHER_OBJ: 127 acl_new->acl_entry[2] = acl_old->acl_entry[i]; 128 break; | |
129 case ACL_MASK: | 153 case ACL_MASK: |
130 mask_perm = acl_old->acl_entry[i].ae_perm; | |
131 have_mask_entry = 1; 132 break; 133 default: 134 break; 135 } | 154 have_mask_entry = 1; 155 break; 156 default: 157 break; 158 } |
136 /* 137 * If the ACL contains a mask entry, then the permissions associated 138 * with the owning group entry in the resulting ACL shall be set to 139 * only those permissions associated with both the owning group entry 140 * and the mask entry of the current ACL. 141 */ 142 if (have_mask_entry) 143 acl_new->acl_entry[1].ae_perm = group_perm & mask_perm; 144 acl_new->acl_cnt = 3; | 159 } 160 if (have_mask_entry && !n_flag) { 161 if (acl_calc_mask(&acl_new) == -1) 162 err(1, "acl_calc_mask() failed"); 163 } else { 164 have_mask = 1; 165 } |
145 146 if (acl_type == ACL_TYPE_ACCESS) { 147 acl_free(prev_acl[0]); 148 prev_acl[0] = acl_new; 149 } else { 150 acl_free(prev_acl[1]); 151 prev_acl[1] = acl_new; 152 } | 166 167 if (acl_type == ACL_TYPE_ACCESS) { 168 acl_free(prev_acl[0]); 169 prev_acl[0] = acl_new; 170 } else { 171 acl_free(prev_acl[1]); 172 prev_acl[1] = acl_new; 173 } |
153 154 have_mask = 0; | |
155} | 174} |