From 993f5df62825d513b93cb1799887b442abf50bc6 Mon Sep 17 00:00:00 2001 From: "Chris D. Faulhaber" Date: Mon, 3 Dec 2001 01:20:52 +0000 Subject: [PATCH] Add defines for access and default ACLs (ACCESS_ACL/DEFAULT_ACL) to enhance readability. Obtained from: TrustedBSD Project --- bin/setfacl/merge.c | 12 ++++++------ bin/setfacl/remove.c | 24 ++++++++++++------------ bin/setfacl/setfacl.c | 18 +++++++++--------- bin/setfacl/setfacl.h | 4 ++++ 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/bin/setfacl/merge.c b/bin/setfacl/merge.c index b9c17b3bd80f..7c26e69c5ff0 100644 --- a/bin/setfacl/merge.c +++ b/bin/setfacl/merge.c @@ -49,9 +49,9 @@ merge_acl(acl_t acl, acl_t *prev_acl) uid_t *id, *id_new; if (acl_type == ACL_TYPE_ACCESS) - acl_new = acl_dup(prev_acl[0]); + acl_new = acl_dup(prev_acl[ACCESS_ACL]); else - acl_new = acl_dup(prev_acl[1]); + acl_new = acl_dup(prev_acl[DEFAULT_ACL]); if (acl_new == NULL) err(1, "acl_dup() failed"); @@ -136,11 +136,11 @@ merge_acl(acl_t acl, acl_t *prev_acl) if (acl_type == ACL_TYPE_ACCESS) { - acl_free(prev_acl[0]); - prev_acl[0] = acl_new; + acl_free(prev_acl[ACCESS_ACL]); + prev_acl[ACCESS_ACL] = acl_new; } else { - acl_free(prev_acl[1]); - prev_acl[1] = acl_new; + acl_free(prev_acl[DEFAULT_ACL]); + prev_acl[DEFAULT_ACL] = acl_new; } diff --git a/bin/setfacl/remove.c b/bin/setfacl/remove.c index 0911dd8b9a4b..e4f2f3536fac 100644 --- a/bin/setfacl/remove.c +++ b/bin/setfacl/remove.c @@ -50,9 +50,9 @@ remove_acl(acl_t acl, acl_t *prev_acl) carried_error = 0; if (acl_type == ACL_TYPE_ACCESS) - acl_new = acl_dup(prev_acl[0]); + acl_new = acl_dup(prev_acl[ACCESS_ACL]); else - acl_new = acl_dup(prev_acl[1]); + acl_new = acl_dup(prev_acl[DEFAULT_ACL]); if (acl_new == NULL) err(1, "acl_dup() failed"); @@ -73,11 +73,11 @@ remove_acl(acl_t acl, acl_t *prev_acl) } if (acl_type == ACL_TYPE_ACCESS) { - acl_free(prev_acl[0]); - prev_acl[0] = acl_new; + acl_free(prev_acl[ACCESS_ACL]); + prev_acl[ACCESS_ACL] = acl_new; } else { - acl_free(prev_acl[1]); - prev_acl[1] = acl_new; + acl_free(prev_acl[DEFAULT_ACL]); + prev_acl[DEFAULT_ACL] = acl_new; } if (carried_error) @@ -118,9 +118,9 @@ remove_ext(acl_t *prev_acl) int entry_id, have_mask_entry; if (acl_type == ACL_TYPE_ACCESS) - acl_old = acl_dup(prev_acl[0]); + acl_old = acl_dup(prev_acl[ACCESS_ACL]); else - acl_old = acl_dup(prev_acl[1]); + acl_old = acl_dup(prev_acl[DEFAULT_ACL]); if (acl_old == NULL) err(1, "acl_dup() failed"); @@ -170,10 +170,10 @@ remove_ext(acl_t *prev_acl) } if (acl_type == ACL_TYPE_ACCESS) { - acl_free(prev_acl[0]); - prev_acl[0] = acl_new; + acl_free(prev_acl[ACCESS_ACL]); + prev_acl[ACCESS_ACL] = acl_new; } else { - acl_free(prev_acl[1]); - prev_acl[1] = acl_new; + acl_free(prev_acl[DEFAULT_ACL]); + prev_acl[DEFAULT_ACL] = acl_new; } } diff --git a/bin/setfacl/setfacl.c b/bin/setfacl/setfacl.c index d69c7c9bcd78..b008e1db9924 100644 --- a/bin/setfacl/setfacl.c +++ b/bin/setfacl/setfacl.c @@ -70,15 +70,15 @@ get_file_acls(const char *filename) } acl = zmalloc(sizeof(acl_t) * 2); - acl[0] = acl_get_file(filename, ACL_TYPE_ACCESS); - if (acl[0] == NULL) + acl[ACCESS_ACL] = acl_get_file(filename, ACL_TYPE_ACCESS); + if (acl[ACCESS_ACL] == 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] == NULL) + acl[DEFAULT_ACL] = acl_get_file(filename, ACL_TYPE_DEFAULT); + if (acl[DEFAULT_ACL] == NULL) err(1, "acl_get_file() failed"); } else - acl[1] = NULL; + acl[DEFAULT_ACL] = NULL; return (acl); } @@ -230,9 +230,9 @@ main(int argc, char *argv[]) } if (acl_type == ACL_TYPE_ACCESS) - final_acl = acl[0]; + final_acl = acl[ACCESS_ACL]; else - final_acl = acl[1]; + final_acl = acl[DEFAULT_ACL]; if (need_mask && (set_acl_mask(&final_acl) == -1)) { warnx("failed to set ACL mask on %s", file->filename); @@ -243,8 +243,8 @@ main(int argc, char *argv[]) warn("acl_set_file() failed for %s", file->filename); } - acl_free(acl[0]); - acl_free(acl[1]); + acl_free(acl[ACCESS_ACL]); + acl_free(acl[DEFAULT_ACL]); free(acl); } diff --git a/bin/setfacl/setfacl.h b/bin/setfacl/setfacl.h index d3c79230a92f..022a4a34ef46 100644 --- a/bin/setfacl/setfacl.h +++ b/bin/setfacl/setfacl.h @@ -39,6 +39,10 @@ #define OP_REMOVE_EXT 0x02 /* remove extended acl's (-b) */ #define OP_REMOVE_ACL 0x03 /* remove acl's (-xX) */ +/* ACL types for the acl array */ +#define ACCESS_ACL 0 +#define DEFAULT_ACL 1 + /* TAILQ entry for acl operations */ struct sf_entry { uint op;