setfacl.c (74465) | setfacl.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/setfacl.c 74465 2001-03-19 18:09:25Z rwatson $ | 26 * $FreeBSD: head/bin/setfacl/setfacl.c 75928 2001-04-24 22:45:41Z jedgar $ |
27 */ 28 29#include <sys/types.h> 30#include <sys/param.h> 31#include <sys/stat.h> 32#include <sys/acl.h> 33#include <sys/queue.h> 34 --- 16 unchanged lines hidden (view full) --- 51 struct sf_file *file; 52 53 if (strlen(filename) > PATH_MAX - 1) { 54 warn("illegal filename"); 55 return; 56 } 57 file = zmalloc(sizeof(struct sf_file)); 58 file->filename = filename; | 27 */ 28 29#include <sys/types.h> 30#include <sys/param.h> 31#include <sys/stat.h> 32#include <sys/acl.h> 33#include <sys/queue.h> 34 --- 16 unchanged lines hidden (view full) --- 51 struct sf_file *file; 52 53 if (strlen(filename) > PATH_MAX - 1) { 54 warn("illegal filename"); 55 return; 56 } 57 file = zmalloc(sizeof(struct sf_file)); 58 file->filename = filename; |
59 STAILQ_INSERT_TAIL(&filelist, file, next); | 59 TAILQ_INSERT_TAIL(&filelist, file, next); |
60} 61 62static acl_t * 63get_file_acls(const char *filename) 64{ 65 acl_t *acl; 66 struct stat sb; 67 --- 33 unchanged lines hidden (view full) --- 101 int local_error, carried_error, ch, i; 102 struct sf_file *file; 103 struct sf_entry *entry; 104 105 acl_type = ACL_TYPE_ACCESS; 106 carried_error = local_error = 0; 107 have_mask = have_stdin = n_flag = need_mask = 0; 108 | 60} 61 62static acl_t * 63get_file_acls(const char *filename) 64{ 65 acl_t *acl; 66 struct stat sb; 67 --- 33 unchanged lines hidden (view full) --- 101 int local_error, carried_error, ch, i; 102 struct sf_file *file; 103 struct sf_entry *entry; 104 105 acl_type = ACL_TYPE_ACCESS; 106 carried_error = local_error = 0; 107 have_mask = have_stdin = n_flag = need_mask = 0; 108 |
109 STAILQ_INIT(&entrylist); 110 STAILQ_INIT(&filelist); | 109 TAILQ_INIT(&entrylist); 110 TAILQ_INIT(&filelist); |
111 112 while ((ch = getopt(argc, argv, "M:X:bdkm:nx:")) != -1) 113 switch(ch) { 114 case 'M': 115 entry = zmalloc(sizeof(struct sf_entry)); 116 entry->acl = get_acl_from_file(optarg); 117 if (!entry->acl) 118 err(EX_OSERR, "get_acl_from_file() failed"); 119 entry->op = OP_MERGE_ACL; | 111 112 while ((ch = getopt(argc, argv, "M:X:bdkm:nx:")) != -1) 113 switch(ch) { 114 case 'M': 115 entry = zmalloc(sizeof(struct sf_entry)); 116 entry->acl = get_acl_from_file(optarg); 117 if (!entry->acl) 118 err(EX_OSERR, "get_acl_from_file() failed"); 119 entry->op = OP_MERGE_ACL; |
120 STAILQ_INSERT_TAIL(&entrylist, entry, next); | 120 TAILQ_INSERT_TAIL(&entrylist, entry, next); |
121 break; 122 case 'X': 123 entry = zmalloc(sizeof(struct sf_entry)); 124 entry->acl = get_acl_from_file(optarg); 125 entry->op = OP_REMOVE_ACL; | 121 break; 122 case 'X': 123 entry = zmalloc(sizeof(struct sf_entry)); 124 entry->acl = get_acl_from_file(optarg); 125 entry->op = OP_REMOVE_ACL; |
126 STAILQ_INSERT_TAIL(&entrylist, entry, next); | 126 TAILQ_INSERT_TAIL(&entrylist, entry, next); |
127 break; 128 case 'b': 129 entry = zmalloc(sizeof(struct sf_entry)); 130 entry->op = OP_REMOVE_EXT; | 127 break; 128 case 'b': 129 entry = zmalloc(sizeof(struct sf_entry)); 130 entry->op = OP_REMOVE_EXT; |
131 STAILQ_INSERT_TAIL(&entrylist, entry, next); | 131 TAILQ_INSERT_TAIL(&entrylist, entry, next); |
132 break; 133 case 'd': 134 acl_type = ACL_TYPE_DEFAULT; 135 break; 136 case 'k': 137 entry = zmalloc(sizeof(struct sf_entry)); 138 entry->op = OP_REMOVE_DEF; | 132 break; 133 case 'd': 134 acl_type = ACL_TYPE_DEFAULT; 135 break; 136 case 'k': 137 entry = zmalloc(sizeof(struct sf_entry)); 138 entry->op = OP_REMOVE_DEF; |
139 STAILQ_INSERT_TAIL(&entrylist, entry, next); | 139 TAILQ_INSERT_TAIL(&entrylist, entry, next); |
140 break; 141 case 'm': 142 entry = zmalloc(sizeof(struct sf_entry)); 143 entry->acl = acl_from_text(optarg); 144 if (!entry->acl) 145 err(EX_USAGE, "acl_from_text() failed"); 146 entry->op = OP_MERGE_ACL; | 140 break; 141 case 'm': 142 entry = zmalloc(sizeof(struct sf_entry)); 143 entry->acl = acl_from_text(optarg); 144 if (!entry->acl) 145 err(EX_USAGE, "acl_from_text() failed"); 146 entry->op = OP_MERGE_ACL; |
147 STAILQ_INSERT_TAIL(&entrylist, entry, next); | 147 TAILQ_INSERT_TAIL(&entrylist, entry, next); |
148 break; 149 case 'n': 150 n_flag++; 151 break; 152 case 'x': 153 entry = zmalloc(sizeof(struct sf_entry)); 154 entry->acl = acl_from_text(optarg); 155 if (!entry->acl) 156 err(EX_USAGE, "acl_from_text() failed"); 157 entry->op = OP_REMOVE_ACL; | 148 break; 149 case 'n': 150 n_flag++; 151 break; 152 case 'x': 153 entry = zmalloc(sizeof(struct sf_entry)); 154 entry->acl = acl_from_text(optarg); 155 if (!entry->acl) 156 err(EX_USAGE, "acl_from_text() failed"); 157 entry->op = OP_REMOVE_ACL; |
158 STAILQ_INSERT_TAIL(&entrylist, entry, next); | 158 TAILQ_INSERT_TAIL(&entrylist, entry, next); |
159 break; 160 default: 161 usage(); 162 break; 163 } 164 argc -= optind; 165 argv += optind; 166 | 159 break; 160 default: 161 usage(); 162 break; 163 } 164 argc -= optind; 165 argv += optind; 166 |
167 if (STAILQ_EMPTY(&entrylist)) | 167 if (!n_flag && TAILQ_EMPTY(&entrylist)) |
168 usage(); 169 170 /* take list of files from stdin */ 171 if (argc == 0 || !strcmp(argv[0], "-")) { 172 if (have_stdin) 173 err(EX_USAGE, "cannot have more than one stdin"); 174 have_stdin = 1; 175 bzero(&filename, sizeof(filename)); 176 while (fgets(filename, sizeof(filename), stdin)) { 177 /* remove the \n */ 178 filename[strlen(filename) - 1] = '\0'; 179 add_filename(filename); 180 } 181 } else 182 for (i = 0; i < argc; i++) 183 add_filename(argv[i]); 184 185 /* cycle through each file */ | 168 usage(); 169 170 /* take list of files from stdin */ 171 if (argc == 0 || !strcmp(argv[0], "-")) { 172 if (have_stdin) 173 err(EX_USAGE, "cannot have more than one stdin"); 174 have_stdin = 1; 175 bzero(&filename, sizeof(filename)); 176 while (fgets(filename, sizeof(filename), stdin)) { 177 /* remove the \n */ 178 filename[strlen(filename) - 1] = '\0'; 179 add_filename(filename); 180 } 181 } else 182 for (i = 0; i < argc; i++) 183 add_filename(argv[i]); 184 185 /* cycle through each file */ |
186 STAILQ_FOREACH(file, &filelist, next) { | 186 TAILQ_FOREACH(file, &filelist, next) { |
187 /* get our initial access and default ACL's */ 188 acl = get_file_acls(file->filename); 189 if (!acl) 190 continue; 191 if ((acl_type == ACL_TYPE_DEFAULT) && !acl[1]) { 192 warnx("Default ACL not valid for %s", file->filename); 193 continue; 194 } 195 196 local_error = 0; 197 198 /* cycle through each option */ | 187 /* get our initial access and default ACL's */ 188 acl = get_file_acls(file->filename); 189 if (!acl) 190 continue; 191 if ((acl_type == ACL_TYPE_DEFAULT) && !acl[1]) { 192 warnx("Default ACL not valid for %s", file->filename); 193 continue; 194 } 195 196 local_error = 0; 197 198 /* cycle through each option */ |
199 STAILQ_FOREACH(entry, &entrylist, next) { | 199 TAILQ_FOREACH(entry, &entrylist, next) { |
200 if (local_error) 201 continue; 202 203 switch(entry->op) { 204 case OP_MERGE_ACL: 205 local_error += merge_acl(entry->acl, acl); 206 need_mask = 1; 207 break; --- 23 unchanged lines hidden (view full) --- 231 continue; 232 } 233 234 if (acl_type == ACL_TYPE_ACCESS) 235 final_acl = acl[0]; 236 else 237 final_acl = acl[1]; 238 | 200 if (local_error) 201 continue; 202 203 switch(entry->op) { 204 case OP_MERGE_ACL: 205 local_error += merge_acl(entry->acl, acl); 206 need_mask = 1; 207 break; --- 23 unchanged lines hidden (view full) --- 231 continue; 232 } 233 234 if (acl_type == ACL_TYPE_ACCESS) 235 final_acl = acl[0]; 236 else 237 final_acl = acl[1]; 238 |
239 if (need_mask && (set_acl_mask(final_acl) == -1)) { | 239 if (need_mask && (set_acl_mask(&final_acl) == -1)) { |
240 warnx("failed to set ACL mask on %s", file->filename); 241 carried_error++; 242 } else if (acl_set_file(file->filename, acl_type, 243 final_acl) == -1) { 244 carried_error++; 245 warn("acl_set_file() failed for %s", file->filename); 246 } 247 248 acl_free(acl[0]); 249 acl_free(acl[1]); 250 free(acl); 251 } 252 253 return carried_error; 254} | 240 warnx("failed to set ACL mask on %s", file->filename); 241 carried_error++; 242 } else if (acl_set_file(file->filename, acl_type, 243 final_acl) == -1) { 244 carried_error++; 245 warn("acl_set_file() failed for %s", file->filename); 246 } 247 248 acl_free(acl[0]); 249 acl_free(acl[1]); 250 free(acl); 251 } 252 253 return carried_error; 254} |