From a7187b9c820583d75581c6fe7e26e38ed9e24f7e Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 25 Feb 2018 19:39:16 -0500 Subject: [PATCH] Simplify wipe_acls() by having it unconditionally write a new, empty ACL. --- src/apply-default-acl.c | 53 +++++++++-------------------------------- 1 file changed, 11 insertions(+), 42 deletions(-) diff --git a/src/apply-default-acl.c b/src/apply-default-acl.c index d97d67d..de4e1ac 100644 --- a/src/apply-default-acl.c +++ b/src/apply-default-acl.c @@ -622,8 +622,8 @@ int assign_default_acl(const char* path, acl_t acl) { /** - * @brief Remove @c ACL_USER, @c ACL_GROUP, and @c ACL_MASK entries - * from the given file descriptor. + * @brief Remove all @c ACL_TYPE_ACCESS entries from the given file + * descriptor, leaving the UNIX permission bits. * * @param fd * The file descriptor whose ACLs we want to wipe. @@ -634,53 +634,22 @@ int assign_default_acl(const char* path, acl_t acl) { * - @c ACL_ERROR - Unexpected library error. */ int wipe_acls(int fd) { + /* Initialize an empty ACL, and then overwrite the one on "fd" with it. */ + acl_t empty_acl = acl_init(0); - if (fd <= 0) { - errno = ENOENT; - return ACL_ERROR; - } - - acl_t acl = acl_get_fd(fd); - if (acl == (acl_t)NULL) { - perror("wipe_acls (acl_get_fd)"); + if (empty_acl == (acl_t)NULL) { + perror("wipe_acls (acl_init)"); return ACL_ERROR; } - /* Our return value. */ - int result = ACL_SUCCESS; - - acl_entry_t entry; - int ge_result = acl_get_entry(acl, ACL_FIRST_ENTRY, &entry); - - while (ge_result == ACL_SUCCESS) { - int d_result = acl_delete_entry(acl, entry); - if (d_result == ACL_ERROR) { - perror("wipe_acls (acl_delete_entry)"); - result = ACL_ERROR; - goto cleanup; - } - - ge_result = acl_get_entry(acl, ACL_NEXT_ENTRY, &entry); - } - - /* Catches the first acl_get_entry as well as the ones at the end of - the loop. */ - if (ge_result == ACL_ERROR) { - perror("wipe_acls (acl_get_entry)"); - result = ACL_ERROR; - goto cleanup; - } - - int sf_result = acl_set_fd(fd, acl); - if (sf_result == ACL_ERROR) { + if (acl_set_fd(fd, empty_acl) == ACL_ERROR) { perror("wipe_acls (acl_set_fd)"); - result = ACL_ERROR; - goto cleanup; + acl_free(empty_acl); + return ACL_ERROR; } - cleanup: - acl_free(acl); - return result; + acl_free(empty_acl); + return ACL_SUCCESS; } -- 2.44.2