From a662358647653b8d7f4f2dbfc5ca2802f38c60c8 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Mon, 26 Feb 2018 13:27:18 -0500 Subject: [PATCH] Rename apply_default_acl() to apply_default_acl_ex() and add a wrapper. The old apply_default_acl() function has a weird second argument that will usually be NULL for other users of the library. Instead of making them deal with that design choice, the old apply_default_acl() function was renamed t apply_default_acl_ex(), and a new apply_default_acl() was added with no second argument to wrap the former. --- src/apply-default-acl.c | 6 ++-- src/libadacl.c | 68 +++++++++++++++++++++++++++++------------ src/libadacl.h | 8 +++-- 3 files changed, 56 insertions(+), 26 deletions(-) diff --git a/src/apply-default-acl.c b/src/apply-default-acl.c index f8ae4cd..e5b989a 100644 --- a/src/apply-default-acl.c +++ b/src/apply-default-acl.c @@ -91,7 +91,7 @@ int apply_default_acl_nftw(const char *target, int info, struct FTW *ftw) { - if (apply_default_acl(target, sp, false)) { + if (apply_default_acl_ex(target, sp, false)) { return FTW_CONTINUE; } else { @@ -113,7 +113,7 @@ int apply_default_acl_nftw_x(const char *target, int info, struct FTW *ftw) { - if (apply_default_acl(target, sp, true)) { + if (apply_default_acl_ex(target, sp, true)) { return FTW_CONTINUE; } else { @@ -247,7 +247,7 @@ int main(int argc, char* argv[]) { } else { /* It's either a normal file, or we're not operating recursively. */ - reapp_result = apply_default_acl(target, NULL, no_exec_mask); + reapp_result = apply_default_acl(target, no_exec_mask); } if (!reapp_result) { diff --git a/src/libadacl.c b/src/libadacl.c index 1fb54a8..08b13b8 100644 --- a/src/libadacl.c +++ b/src/libadacl.c @@ -604,13 +604,13 @@ int wipe_acls(int fd) { * or the parent of @c path is not a directory. * - @c ACL_ERROR - Unexpected library error. */ -int apply_default_acl(const char* path, - const struct stat* sp, - bool no_exec_mask) { +int apply_default_acl_ex(const char* path, + const struct stat* sp, + bool no_exec_mask) { if (path == NULL) { errno = EINVAL; - perror("apply_default_acl (args)"); + perror("apply_default_acl_ex (args)"); return ACL_ERROR; } @@ -632,7 +632,7 @@ int apply_default_acl(const char* path, */ char* path_copy = strdup(path); if (path_copy == NULL) { - perror("apply_default_acl (strdup)"); + perror("apply_default_acl_ex (strdup)"); return ACL_ERROR; } char* parent = dirname(path_copy); @@ -644,7 +644,7 @@ int apply_default_acl(const char* path, goto cleanup; } else { - perror("apply_default_acl (open fd)"); + perror("apply_default_acl_ex (open fd)"); result = ACL_ERROR; goto cleanup; } @@ -664,7 +664,7 @@ int apply_default_acl(const char* path, if (sp == NULL) { struct stat s; if (fstat(fd, &s) == STAT_ERROR) { - perror("apply_default_acl (fstat)"); + perror("apply_default_acl_ex (fstat)"); goto cleanup; } @@ -692,7 +692,7 @@ int apply_default_acl(const char* path, int ace_result = any_can_execute(fd,sp) || S_ISDIR(sp->st_mode); if (ace_result == ACL_ERROR) { - perror("apply_default_acl (any_can_execute)"); + perror("apply_default_acl_ex (any_can_execute)"); result = ACL_ERROR; goto cleanup; } @@ -703,13 +703,13 @@ int apply_default_acl(const char* path, defacl = acl_get_file(parent, ACL_TYPE_DEFAULT); if (defacl == (acl_t)NULL) { - perror("apply_default_acl (acl_get_file)"); + perror("apply_default_acl_ex (acl_get_file)"); result = ACL_ERROR; goto cleanup; } if (wipe_acls(fd) == ACL_ERROR) { - perror("apply_default_acl (wipe_acls)"); + perror("apply_default_acl_ex (wipe_acls)"); result = ACL_ERROR; goto cleanup; } @@ -718,7 +718,7 @@ int apply_default_acl(const char* path, ACL with this one. */ acl_t acl = acl_get_fd(fd); if (acl == (acl_t)NULL) { - perror("apply_default_acl (acl_get_fd)"); + perror("apply_default_acl_ex (acl_get_fd)"); result = ACL_ERROR; goto cleanup; } @@ -730,7 +730,7 @@ int apply_default_acl(const char* path, * want to do? */ if (S_ISDIR(sp->st_mode) && assign_default_acl(path, defacl) == ACL_ERROR) { - perror("apply_default_acl (assign_default_acl)"); + perror("apply_default_acl_ex (assign_default_acl)"); result = ACL_ERROR; goto cleanup; } @@ -742,7 +742,7 @@ int apply_default_acl(const char* path, acl_tag_t tag = ACL_UNDEFINED_TAG; if (acl_get_tag_type(entry, &tag) == ACL_ERROR) { - perror("apply_default_acl (acl_get_tag_type)"); + perror("apply_default_acl_ex (acl_get_tag_type)"); result = ACL_ERROR; goto cleanup; } @@ -751,7 +751,7 @@ int apply_default_acl(const char* path, /* We've got an entry/tag from the default ACL. Get its permset. */ acl_permset_t permset; if (acl_get_permset(entry, &permset) == ACL_ERROR) { - perror("apply_default_acl (acl_get_permset)"); + perror("apply_default_acl_ex (acl_get_permset)"); result = ACL_ERROR; goto cleanup; } @@ -767,13 +767,13 @@ int apply_default_acl(const char* path, minimal ACLs) or acl_other entries, so if execute should be masked, we have to do it manually. */ if (acl_delete_perm(permset, ACL_EXECUTE) == ACL_ERROR) { - perror("apply_default_acl (acl_delete_perm)"); + perror("apply_default_acl_ex (acl_delete_perm)"); result = ACL_ERROR; goto cleanup; } if (acl_set_permset(entry, permset) == ACL_ERROR) { - perror("apply_default_acl (acl_set_permset)"); + perror("apply_default_acl_ex (acl_set_permset)"); result = ACL_ERROR; goto cleanup; } @@ -797,7 +797,7 @@ int apply_default_acl(const char* path, * value of "acl". To do that, it needs the address of "acl". */ if (acl_set_entry(&acl, entry) == ACL_ERROR) { - perror("apply_default_acl (acl_set_entry)"); + perror("apply_default_acl_ex (acl_set_entry)"); result = ACL_ERROR; goto cleanup; } @@ -808,13 +808,13 @@ int apply_default_acl(const char* path, /* Catches the first acl_get_entry as well as the ones at the end of the loop. */ if (ge_result == ACL_ERROR) { - perror("apply_default_acl (acl_get_entry)"); + perror("apply_default_acl_ex (acl_get_entry)"); result = ACL_ERROR; goto cleanup; } if (acl_set_fd(fd, acl) == ACL_ERROR) { - perror("apply_default_acl (acl_set_fd)"); + perror("apply_default_acl_ex (acl_set_fd)"); result = ACL_ERROR; goto cleanup; } @@ -825,8 +825,36 @@ int apply_default_acl(const char* path, acl_free(defacl); } if (fd >= 0 && close(fd) == CLOSE_ERROR) { - perror("apply_default_acl (close)"); + perror("apply_default_acl_ex (close)"); result = ACL_ERROR; } return result; } + + + +/** + * @brief The friendly interface to @c apply_default_acl_ex. + * + * The @c apply_default_acl_ex function holds the real implementation + * of this function, but it takes a weird second argument that most + * people won't care about (a stat structure). But, we use that + * argument for the recursive mode of the CLI, so it's there. + * + * If you don't have a stat structure for your @c path, use this instead. + * + * @param path + * The path whose ACL we would like to reset to its default. + * + * @param no_exec_mask + * The value (either true or false) of the --no-exec-mask flag. + * + * @return + * - @c ACL_SUCCESS - The parent default ACL was inherited successfully. + * - @c ACL_FAILURE - The target path is not a regular file/directory, + * or the parent of @c path is not a directory. + * - @c ACL_ERROR - Unexpected library error. + */ +int apply_default_acl(const char* path, bool no_exec_mask) { + return apply_default_acl_ex(path, NULL, no_exec_mask); +} diff --git a/src/libadacl.h b/src/libadacl.h index d2c9785..a846c88 100644 --- a/src/libadacl.h +++ b/src/libadacl.h @@ -20,6 +20,8 @@ #define SNPRINTF_ERROR -1 #define STAT_ERROR -1 -int apply_default_acl(const char* path, - const struct stat* sp, - bool no_exec_mask); +int apply_default_acl_ex(const char* path, + const struct stat* sp, + bool no_exec_mask); + +int apply_default_acl(const char* path, bool no_exec_mask); -- 2.43.2