diff --git a/bin/setfacl/file.c b/bin/setfacl/file.c index 3e3c80504a6d..d2cdb9894318 100644 --- a/bin/setfacl/file.c +++ b/bin/setfacl/file.c @@ -1,74 +1,75 @@ /* * Copyright (c) 2001 Chris D. Faulhaber * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR THE VOICES IN HIS HEAD BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include -#include #include "setfacl.h" -/* read acl text from a file and return the corresponding acl */ +/* + * read acl text from a file and return the corresponding acl + */ acl_t get_acl_from_file(const char *filename) { FILE *file; char buf[BUFSIZ]; - if (!filename) - err(EX_USAGE, "(null) filename in get_acl_from_file()"); + if (filename == NULL) + err(1, "(null) filename in get_acl_from_file()"); bzero(&buf, sizeof(buf)); - if (!strcmp(filename, "-")) { - if (have_stdin) - err(EX_USAGE, "cannot specify more than one stdin"); + if (strcmp(filename, "-") == 0) { + if (have_stdin != 0) + err(1, "cannot specify more than one stdin"); file = stdin; have_stdin = 1; } else { file = fopen(filename, "r"); - if (!file) - err(EX_OSERR, "fopen() %s failed", filename); + if (file == NULL) + err(1, "fopen() %s failed", filename); } fread(buf, sizeof(buf), (size_t)1, file); - if (ferror(file)) { + if (ferror(file) != 0) { fclose(file); - err(EX_USAGE, "error reading from %s", filename); - } else if (!feof(file)) { + err(1, "error reading from %s", filename); + } else if (feof(file) == 0) { fclose(file); - errx(EX_USAGE, "line too long in %s", filename); + errx(1, "line too long in %s", filename); } fclose(file); - return acl_from_text(buf); + return (acl_from_text(buf)); } diff --git a/bin/setfacl/mask.c b/bin/setfacl/mask.c index fd4409ae096d..0851be1bff23 100644 --- a/bin/setfacl/mask.c +++ b/bin/setfacl/mask.c @@ -1,112 +1,111 @@ /* * Copyright (c) 2001 Chris D. Faulhaber * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR THE VOICES IN HIS HEAD BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include -#include #include "setfacl.h" /* set the appropriate mask the given ACL's */ int set_acl_mask(acl_t *prev_acl) { acl_entry_t entry; acl_t acl; acl_tag_t tag; int entry_id; entry = NULL; /* * ... if a mask entry is specified, then the permissions of the mask * entry in the resulting ACL shall be set to the permissions in the * specified ACL mask entry. */ if (have_mask) - return 0; + return (0); acl = acl_dup(*prev_acl); - if (!acl) - err(EX_OSERR, "acl_dup() failed"); + if (acl == NULL) + err(1, "acl_dup() failed"); - if (!n_flag) { + if (n_flag == 0) { /* * If no mask entry is specified and the -n option is not * specified, then the permissions of the resulting ACL mask * entry shall be set to the union of the permissions * associated with all entries which belong to the file group * class in the resulting ACL */ if (acl_calc_mask(&acl)) { warn("acl_calc_mask() failed"); acl_free(acl); - return -1; + return (-1); } } else { /* * If no mask entry is specified and the -n option is * specified, then the permissions of the resulting ACL * mask entry shall remain unchanged ... */ entry_id = ACL_FIRST_ENTRY; while (acl_get_entry(acl, entry_id, &entry) == 1) { entry_id = ACL_NEXT_ENTRY; if (acl_get_tag_type(entry, &tag) == -1) err(1, "acl_get_tag_type() failed"); if (tag == ACL_MASK) { acl_free(acl); - return 0; + return (0); } } /* * If no mask entry is specified, the -n option is specified, * and no ACL mask entry exists in the ACL associated with the * file, then write an error message to standard error and * continue with the next file. */ warnx("warning: no mask entry"); acl_free(acl); - return 0; + return (0); } **prev_acl = *acl; acl_free(acl); - return 0; + return (0); } diff --git a/bin/setfacl/merge.c b/bin/setfacl/merge.c index acb01f4ce6e5..b9c17b3bd80f 100644 --- a/bin/setfacl/merge.c +++ b/bin/setfacl/merge.c @@ -1,152 +1,148 @@ /* * Copyright (c) 2001 Chris D. Faulhaber * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR THE VOICES IN HIS HEAD BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include -#include #include "setfacl.h" -/* merge acl into existing file's ACL */ +/* + * merge an ACL into existing file's ACL + */ int merge_acl(acl_t acl, acl_t *prev_acl) { acl_entry_t entry, entry_new; acl_permset_t permset; acl_t acl_new; acl_tag_t tag, tag_new; int entry_id, entry_id_new, have_entry; uid_t *id, *id_new; if (acl_type == ACL_TYPE_ACCESS) acl_new = acl_dup(prev_acl[0]); else acl_new = acl_dup(prev_acl[1]); - if (!acl_new) - err(EX_OSERR, "acl_dup() failed"); + if (acl_new == NULL) + err(1, "acl_dup() failed"); entry_id = ACL_FIRST_ENTRY; while (acl_get_entry(acl, entry_id, &entry) == 1) { entry_id = ACL_NEXT_ENTRY; have_entry = 0; /* keep track of existing ACL_MASK entries */ if (acl_get_tag_type(entry, &tag) == -1) - err(EX_OSERR, - "acl_get_tag_type() failed - invalid ACL entry"); + err(1, "acl_get_tag_type() failed - invalid ACL entry"); if (tag == ACL_MASK) have_mask = 1; /* check against the existing ACL entries */ entry_id_new = ACL_FIRST_ENTRY; - while (!have_entry && + while (have_entry == 0 && acl_get_entry(acl_new, entry_id_new, &entry_new) == 1) { entry_id_new = ACL_NEXT_ENTRY; if (acl_get_tag_type(entry, &tag) == -1) - err(EX_OSERR, "acl_get_tag_type() failed"); + err(1, "acl_get_tag_type() failed"); if (acl_get_tag_type(entry_new, &tag_new) == -1) - err(EX_OSERR, "acl_get_tag_type() failed"); + err(1, "acl_get_tag_type() failed"); if (tag != tag_new) continue; switch(tag) { case ACL_USER: case ACL_GROUP: id = acl_get_qualifier(entry); if (id == NULL) - err(EX_OSERR, - "acl_get_qualifier() failed"); + err(1, "acl_get_qualifier() failed"); id_new = acl_get_qualifier(entry_new); if (id_new == NULL) - err(EX_OSERR, - "acl_get_qualifier() failed"); + err(1, "acl_get_qualifier() failed"); if (*id == *id_new) { /* any other matches */ if (acl_get_permset(entry, &permset) == -1) - err(EX_OSERR, + err(1, "acl_get_permset() failed"); if (acl_set_permset(entry_new, permset) == -1) - err(EX_OSERR, + err(1, "acl_set_permset() failed"); have_entry = 1; } acl_free(id); acl_free(id_new); - if (!have_entry) + if (have_entry == 0) break; /* FALLTHROUGH */ case ACL_USER_OBJ: case ACL_GROUP_OBJ: case ACL_OTHER: case ACL_MASK: if (acl_get_permset(entry, &permset) == -1) - err(EX_OSERR, - "acl_get_permset() failed"); + err(1, "acl_get_permset() failed"); if (acl_set_permset(entry_new, permset) == -1) - err(EX_OSERR, - "acl_set_permset() failed"); + err(1, "acl_set_permset() failed"); have_entry = 1; break; default: /* should never be here */ - errx(EX_OSERR, "Invalid tag type: %i", tag); + errx(1, "Invalid tag type: %i", tag); break; } } /* if this entry has not been found, it must be new */ - if (!have_entry) { + if (have_entry == 0) { if (acl_create_entry(&acl_new, &entry_new) == -1) { acl_free(acl_new); - return -1; + return (-1); } if (acl_copy_entry(entry_new, entry) == -1) - err(EX_OSERR, "acl_copy_entry() failed"); + err(1, "acl_copy_entry() failed"); } } if (acl_type == ACL_TYPE_ACCESS) { acl_free(prev_acl[0]); prev_acl[0] = acl_new; } else { acl_free(prev_acl[1]); prev_acl[1] = acl_new; } - return 0; + return (0); } diff --git a/bin/setfacl/remove.c b/bin/setfacl/remove.c index e987df77b96e..0911dd8b9a4b 100644 --- a/bin/setfacl/remove.c +++ b/bin/setfacl/remove.c @@ -1,174 +1,179 @@ /* * Copyright (c) 2001 Chris D. Faulhaber * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR THE VOICES IN HIS HEAD BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include -#include #include "setfacl.h" -/* remove ACL entries from an ACL */ +/* + * remove ACL entries from an ACL + */ int remove_acl(acl_t acl, acl_t *prev_acl) { acl_entry_t entry; acl_t acl_new; acl_tag_t tag; int carried_error, entry_id; carried_error = 0; if (acl_type == ACL_TYPE_ACCESS) acl_new = acl_dup(prev_acl[0]); else acl_new = acl_dup(prev_acl[1]); - if (!acl_new) - err(EX_OSERR, "acl_dup() failed"); + if (acl_new == NULL) + err(1, "acl_dup() failed"); tag = ACL_UNDEFINED_TAG; /* find and delete the entry */ entry_id = ACL_FIRST_ENTRY; while (acl_get_entry(acl, entry_id, &entry) == 1) { entry_id = ACL_NEXT_ENTRY; if (acl_get_tag_type(entry, &tag) == -1) err(1, "acl_get_tag_type() failed"); if (tag == ACL_MASK) have_mask++; if (acl_delete_entry(acl_new, entry) == -1) { carried_error++; warnx("cannot remove non-existent acl entry"); } } if (acl_type == ACL_TYPE_ACCESS) { acl_free(prev_acl[0]); prev_acl[0] = acl_new; } else { acl_free(prev_acl[1]); prev_acl[1] = acl_new; } if (carried_error) - return -1; + return (-1); - return 0; + return (0); } -/* remove default entries */ +/* + * remove default entries + */ int remove_default(acl_t *prev_acl) { if (prev_acl[1]) { acl_free(prev_acl[1]); prev_acl[1] = acl_init(ACL_MAX_ENTRIES); - if (!prev_acl[1]) + if (prev_acl[1] == NULL) err(1, "acl_init() failed"); } else { warn("cannot remove default ACL"); - return -1; + return (-1); } - return 0; + return (0); } -/* remove extended entries */ +/* + * remove extended entries + */ void remove_ext(acl_t *prev_acl) { acl_t acl_new, acl_old; acl_entry_t entry, entry_new; acl_permset_t perm; acl_tag_t tag; int entry_id, have_mask_entry; if (acl_type == ACL_TYPE_ACCESS) acl_old = acl_dup(prev_acl[0]); else acl_old = acl_dup(prev_acl[1]); - if (!acl_old) - err(EX_OSERR, "acl_dup() failed"); + if (acl_old == NULL) + err(1, "acl_dup() failed"); have_mask_entry = 0; acl_new = acl_init(ACL_MAX_ENTRIES); - if (!acl_new) - err(EX_OSERR, "%s", "acl_init() failed"); + if (acl_new == NULL) + err(1, "acl_init() failed"); tag = ACL_UNDEFINED_TAG; /* only save the default user/group/other entries */ entry_id = ACL_FIRST_ENTRY; while (acl_get_entry(acl_old, entry_id, &entry) == 1) { entry_id = ACL_NEXT_ENTRY; if (acl_get_tag_type(entry, &tag) == -1) err(1, "acl_get_tag_type() failed"); switch(tag) { case ACL_USER_OBJ: case ACL_GROUP_OBJ: case ACL_OTHER: if (acl_get_tag_type(entry, &tag) == -1) err(1, "acl_get_tag_type() failed"); if (acl_get_permset(entry, &perm) == -1) err(1, "acl_get_permset() failed"); if (acl_create_entry(&acl_new, &entry_new) == -1) err(1, "acl_create_entry() failed"); if (acl_set_tag_type(entry_new, tag) == -1) err(1, "acl_set_tag_type() failed"); if (acl_set_permset(entry_new, perm) == -1) err(1, "acl_get_permset() failed"); if (acl_copy_entry(entry_new, entry) == -1) err(1, "acl_copy_entry() failed"); break; case ACL_MASK: have_mask_entry = 1; break; default: break; } } - if (have_mask_entry && !n_flag) { + if (have_mask_entry && n_flag == 0) { if (acl_calc_mask(&acl_new) == -1) err(1, "acl_calc_mask() failed"); } else { have_mask = 1; } if (acl_type == ACL_TYPE_ACCESS) { acl_free(prev_acl[0]); prev_acl[0] = acl_new; } else { acl_free(prev_acl[1]); prev_acl[1] = acl_new; } } diff --git a/bin/setfacl/setfacl.c b/bin/setfacl/setfacl.c index 072bca876dfd..d69c7c9bcd78 100644 --- a/bin/setfacl/setfacl.c +++ b/bin/setfacl/setfacl.c @@ -1,254 +1,252 @@ /* * Copyright (c) 2001 Chris D. Faulhaber * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR THE VOICES IN HIS HEAD BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include -#include #include #include "setfacl.h" static void add_filename(const char *filename); static acl_t *get_file_acls(const char *filename); static void usage(void); static void add_filename(const char *filename) { struct sf_file *file; if (strlen(filename) > PATH_MAX - 1) { warn("illegal filename"); return; } file = zmalloc(sizeof(struct sf_file)); file->filename = filename; TAILQ_INSERT_TAIL(&filelist, file, next); } static acl_t * get_file_acls(const char *filename) { acl_t *acl; struct stat sb; if (stat(filename, &sb) == -1) { warn("stat() of %s failed", filename); - return NULL; + return (NULL); } acl = zmalloc(sizeof(acl_t) * 2); acl[0] = acl_get_file(filename, ACL_TYPE_ACCESS); - if (!acl[0]) - err(EX_OSERR, "acl_get_file() failed"); + if (acl[0] == NULL) + err(1, "acl_get_file() failed"); if (S_ISDIR(sb.st_mode)) { acl[1] = acl_get_file(filename, ACL_TYPE_DEFAULT); - if (!acl[1]) - err(EX_OSERR, "acl_get_file() failed"); + if (acl[1] == NULL) + err(1, "acl_get_file() failed"); } else acl[1] = NULL; - return acl; + return (acl); } static void usage(void) { fprintf(stderr, "usage: setfacl [-bdknv] [-m entries] [-M file1] " "[-x entries] [-X file2] [file ...]\n"); - exit(EX_USAGE); + exit(1); } int main(int argc, char *argv[]) { acl_t *acl, final_acl; char filename[PATH_MAX]; int local_error, carried_error, ch, i; struct sf_file *file; struct sf_entry *entry; acl_type = ACL_TYPE_ACCESS; carried_error = local_error = 0; have_mask = have_stdin = n_flag = need_mask = 0; TAILQ_INIT(&entrylist); TAILQ_INIT(&filelist); while ((ch = getopt(argc, argv, "M:X:bdkm:nx:")) != -1) switch(ch) { case 'M': entry = zmalloc(sizeof(struct sf_entry)); entry->acl = get_acl_from_file(optarg); - if (!entry->acl) - err(EX_OSERR, "get_acl_from_file() failed"); + if (entry->acl == NULL) + err(1, "get_acl_from_file() failed"); entry->op = OP_MERGE_ACL; TAILQ_INSERT_TAIL(&entrylist, entry, next); break; case 'X': entry = zmalloc(sizeof(struct sf_entry)); entry->acl = get_acl_from_file(optarg); entry->op = OP_REMOVE_ACL; TAILQ_INSERT_TAIL(&entrylist, entry, next); break; case 'b': entry = zmalloc(sizeof(struct sf_entry)); entry->op = OP_REMOVE_EXT; TAILQ_INSERT_TAIL(&entrylist, entry, next); break; case 'd': acl_type = ACL_TYPE_DEFAULT; break; case 'k': entry = zmalloc(sizeof(struct sf_entry)); entry->op = OP_REMOVE_DEF; TAILQ_INSERT_TAIL(&entrylist, entry, next); break; case 'm': entry = zmalloc(sizeof(struct sf_entry)); entry->acl = acl_from_text(optarg); - if (!entry->acl) - err(EX_USAGE, "acl_from_text() failed"); + if (entry->acl == NULL) + err(1, "acl_from_text() failed"); entry->op = OP_MERGE_ACL; TAILQ_INSERT_TAIL(&entrylist, entry, next); break; case 'n': n_flag++; break; case 'x': entry = zmalloc(sizeof(struct sf_entry)); entry->acl = acl_from_text(optarg); - if (!entry->acl) - err(EX_USAGE, "acl_from_text() failed"); + if (entry->acl == NULL) + err(1, "acl_from_text() failed"); entry->op = OP_REMOVE_ACL; TAILQ_INSERT_TAIL(&entrylist, entry, next); break; default: usage(); break; } argc -= optind; argv += optind; - if (!n_flag && TAILQ_EMPTY(&entrylist)) + if (n_flag == 0 && TAILQ_EMPTY(&entrylist)) usage(); /* take list of files from stdin */ - if (argc == 0 || !strcmp(argv[0], "-")) { + if (argc == 0 || strcmp(argv[0], "-") == 0) { if (have_stdin) - err(EX_USAGE, "cannot have more than one stdin"); + err(1, "cannot have more than one stdin"); have_stdin = 1; bzero(&filename, sizeof(filename)); while (fgets(filename, (int)sizeof(filename), stdin)) { /* remove the \n */ filename[strlen(filename) - 1] = '\0'; add_filename(filename); } } else for (i = 0; i < argc; i++) add_filename(argv[i]); /* cycle through each file */ TAILQ_FOREACH(file, &filelist, next) { /* get our initial access and default ACL's */ acl = get_file_acls(file->filename); - if (!acl) + if (acl == NULL) continue; if ((acl_type == ACL_TYPE_DEFAULT) && !acl[1]) { warnx("Default ACL not valid for %s", file->filename); continue; } local_error = 0; /* cycle through each option */ TAILQ_FOREACH(entry, &entrylist, next) { if (local_error) continue; switch(entry->op) { case OP_MERGE_ACL: local_error += merge_acl(entry->acl, acl); need_mask = 1; break; case OP_REMOVE_EXT: remove_ext(acl); need_mask = 0; break; case OP_REMOVE_DEF: if (acl_delete_def_file(file->filename) == -1) { warn("acl_delete_def_file() failed"); local_error++; } local_error += remove_default(acl); need_mask = 0; break; case OP_REMOVE_ACL: local_error += remove_acl(entry->acl, acl); need_mask = 1; break; - /* NOTREACHED */ } } /* don't bother setting the ACL if something is broken */ if (local_error) { carried_error++; continue; } if (acl_type == ACL_TYPE_ACCESS) final_acl = acl[0]; else final_acl = acl[1]; if (need_mask && (set_acl_mask(&final_acl) == -1)) { warnx("failed to set ACL mask on %s", file->filename); carried_error++; } else if (acl_set_file(file->filename, acl_type, final_acl) == -1) { carried_error++; warn("acl_set_file() failed for %s", file->filename); } acl_free(acl[0]); acl_free(acl[1]); free(acl); } - return carried_error; + return (carried_error); } diff --git a/bin/setfacl/util.c b/bin/setfacl/util.c index f4fef77adb47..2c1a6e273b04 100644 --- a/bin/setfacl/util.c +++ b/bin/setfacl/util.c @@ -1,45 +1,44 @@ /* * Copyright (c) 2001 Chris D. Faulhaber * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR THE VOICES IN HIS HEAD BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include -#include #include "setfacl.h" void * zmalloc(size_t size) { void *ptr; ptr = calloc(1, size); if (ptr == NULL) - err(EX_OSERR, "calloc() failed"); - return ptr; + err(1, "calloc() failed"); + return (ptr); }