From: Michael Orlitzky Date: Fri, 2 Mar 2018 14:11:40 +0000 (-0500) Subject: Eliminate the apply_default_acl_ex() function. X-Git-Tag: v0.2.0~1 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=380d77fc4acfd5e6cb2317e63c96567209902eda;p=apply-default-acl.git Eliminate the apply_default_acl_ex() function. The apply_default_acl_ex() function was an "extended" version of the apply_default_acl() function that, in addition, took a stat structure pointer to the target path. The extended function was used by nftw(), which usually has such a stat structure handy. However, the provenance of that stat structure is not clear: does nftw() obtain it in a safe way? Since I don't know the answer to that question, I would rather stat() the descriptor that I know was obtained safely. Thus there's no reason to take the pointer as an argument, and then no reason to keep the extended function around at all. --- diff --git a/src/apply-default-acl.c b/src/apply-default-acl.c index a520aa9..d83e428 100644 --- a/src/apply-default-acl.c +++ b/src/apply-default-acl.c @@ -109,7 +109,10 @@ int apply_default_acl_nftw(const char *target, } - if (apply_default_acl_ex(target, sp, false) == ACL_ERROR) { + /* The apply_default_acl() function could make use of the stat + struct pointer sp, but for safety we choose to stat the result of + safe_open() ourselves. */ + if (apply_default_acl(target, false) == ACL_ERROR) { /* I guess we do want to bail out for serious/unexpected errors? */ return ACL_ERROR; } @@ -138,7 +141,10 @@ int apply_default_acl_nftw_x(const char *target, return ACL_ERROR; } - if (apply_default_acl_ex(target, sp, true) == ACL_ERROR) { + /* The apply_default_acl() function could make use of the stat + struct pointer sp, but for safety we choose to stat the result of + safe_open() ourselves. */ + if (apply_default_acl(target, true) == ACL_ERROR) { /* I guess we do want to bail out for serious/unexpected errors? */ return ACL_ERROR; } diff --git a/src/libadacl.c b/src/libadacl.c index b8f6099..2c28945 100644 --- a/src/libadacl.c +++ b/src/libadacl.c @@ -630,10 +630,6 @@ int has_default_acl_fd(int fd) { * @param path * The path whose ACL we would like to reset to its default. * - * @param sp - * A pointer to a stat structure for @c path, or @c NULL if you don't - * have one handy. - * * @param no_exec_mask * The value (either true or false) of the --no-exec-mask flag. * @@ -642,13 +638,11 @@ int has_default_acl_fd(int fd) { * - @c ACL_FAILURE - If symlinks or hard links are encountered. * - @c ACL_ERROR - Unexpected library error. */ -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) { if (path == NULL) { errno = EINVAL; - perror("apply_default_acl_ex (args)"); + perror("apply_default_acl (args)"); return ACL_ERROR; } @@ -681,7 +675,7 @@ int apply_default_acl_ex(const char* path, * to murder its argument and necessitates a path_copy. */ dirname_path_copy = strdup(path); if (dirname_path_copy == NULL) { - perror("apply_default_acl_ex (strdup)"); + perror("apply_default_acl (strdup)"); return ACL_ERROR; } char* parent = dirname(dirname_path_copy); @@ -694,7 +688,7 @@ int apply_default_acl_ex(const char* path, goto cleanup; } else { - perror("apply_default_acl_ex (open parent fd)"); + perror("apply_default_acl (open parent fd)"); result = ACL_ERROR; goto cleanup; } @@ -713,7 +707,7 @@ int apply_default_acl_ex(const char* path, another safe_open(). */ basename_path_copy = strdup(path); if (basename_path_copy == NULL) { - perror("apply_default_acl_ex (strdup)"); + perror("apply_default_acl (strdup)"); return ACL_ERROR; } fd = openat(parent_fd, basename(basename_path_copy), O_NOFOLLOW); @@ -725,7 +719,7 @@ int apply_default_acl_ex(const char* path, goto cleanup; } else { - perror("apply_default_acl_ex (open fd)"); + perror("apply_default_acl (open fd)"); result = ACL_ERROR; goto cleanup; } @@ -741,20 +735,16 @@ int apply_default_acl_ex(const char* path, * Note: we only need to call fstat ourselves if we weren't passed a * valid pointer to a stat structure (nftw does that). */ - if (sp == NULL) { - struct stat s; - if (fstat(fd, &s) == STAT_ERROR) { - perror("apply_default_acl_ex (fstat)"); - goto cleanup; - } - - sp = &s; + struct stat s; + if (fstat(fd, &s) == STAT_ERROR) { + perror("apply_default_acl (fstat)"); + goto cleanup; } - if (!S_ISDIR(sp->st_mode)) { + if (!S_ISDIR(s.st_mode)) { /* If it's not a directory, make sure it's a regular, non-hard-linked file. */ - if (!S_ISREG(sp->st_mode) || sp->st_nlink != 1) { + if (!S_ISREG(s.st_mode) || s.st_nlink != 1) { result = ACL_FAILURE; goto cleanup; } @@ -769,10 +759,10 @@ int apply_default_acl_ex(const char* path, if (!no_exec_mask) { /* Never mask the execute bit on directories. */ - int ace_result = any_can_execute(fd,sp) || S_ISDIR(sp->st_mode); + int ace_result = any_can_execute(fd,&s) || S_ISDIR(s.st_mode); if (ace_result == ACL_ERROR) { - perror("apply_default_acl_ex (any_can_execute)"); + perror("apply_default_acl (any_can_execute)"); result = ACL_ERROR; goto cleanup; } @@ -781,12 +771,12 @@ int apply_default_acl_ex(const char* path, } /* If it's a directory, inherit the parent's default. */ - if (S_ISDIR(sp->st_mode)) { + if (S_ISDIR(s.st_mode)) { if (acl_copy_xattr(parent_fd, ACL_TYPE_DEFAULT, fd, ACL_TYPE_DEFAULT) == ACL_ERROR) { - perror("apply_default_acl_ex (acl_copy_xattr default)"); + perror("apply_default_acl (acl_copy_xattr default)"); result = ACL_ERROR; goto cleanup; } @@ -797,7 +787,7 @@ int apply_default_acl_ex(const char* path, ACL_TYPE_DEFAULT, fd, ACL_TYPE_ACCESS) == ACL_ERROR) { - perror("apply_default_acl_ex (acl_copy_xattr access)"); + perror("apply_default_acl (acl_copy_xattr access)"); result = ACL_ERROR; goto cleanup; } @@ -823,7 +813,7 @@ int apply_default_acl_ex(const char* path, current ACL... */ new_acl = acl_get_fd(fd); if (new_acl == (acl_t)NULL) { - perror("apply_default_acl_ex (acl_get_fd)"); + perror("apply_default_acl (acl_get_fd)"); result = ACL_ERROR; goto cleanup; } @@ -833,7 +823,7 @@ int apply_default_acl_ex(const char* path, looping over it no worky). */ new_acl_unmasked = acl_dup(new_acl); if (new_acl_unmasked == (acl_t)NULL) { - perror("apply_default_acl_ex (acl_dup)"); + perror("apply_default_acl (acl_dup)"); result = ACL_ERROR; goto cleanup; } @@ -845,7 +835,7 @@ int apply_default_acl_ex(const char* path, acl_tag_t tag = ACL_UNDEFINED_TAG; if (acl_get_tag_type(entry, &tag) == ACL_ERROR) { - perror("apply_default_acl_ex (acl_get_tag_type)"); + perror("apply_default_acl (acl_get_tag_type)"); result = ACL_ERROR; goto cleanup; } @@ -854,7 +844,7 @@ int apply_default_acl_ex(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_ex (acl_get_permset)"); + perror("apply_default_acl (acl_get_permset)"); result = ACL_ERROR; goto cleanup; } @@ -868,20 +858,20 @@ int apply_default_acl_ex(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_ex (acl_delete_perm)"); + perror("apply_default_acl (acl_delete_perm)"); result = ACL_ERROR; goto cleanup; } if (acl_set_permset(entry, permset) == ACL_ERROR) { - perror("apply_default_acl_ex (acl_set_permset)"); + perror("apply_default_acl (acl_set_permset)"); result = ACL_ERROR; goto cleanup; } } if (acl_update_entry(new_acl, entry) == ACL_ERROR) { - perror("apply_default_acl_ex (acl_update_entry)"); + perror("apply_default_acl (acl_update_entry)"); result = ACL_ERROR; goto cleanup; } @@ -892,13 +882,13 @@ int apply_default_acl_ex(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_ex (acl_get_entry)"); + perror("apply_default_acl (acl_get_entry)"); result = ACL_ERROR; goto cleanup; } if (acl_set_fd(fd, new_acl) == ACL_ERROR) { - perror("apply_default_acl_ex (acl_set_fd)"); + perror("apply_default_acl (acl_set_fd)"); result = ACL_ERROR; goto cleanup; } @@ -910,40 +900,12 @@ int apply_default_acl_ex(const char* path, acl_free(new_acl_unmasked); if (fd > 0 && close(fd) == CLOSE_ERROR) { - perror("apply_default_acl_ex (close fd)"); + perror("apply_default_acl (close fd)"); result = ACL_ERROR; } if (parent_fd > 0 && close(parent_fd) == CLOSE_ERROR) { - perror("apply_default_acl_ex (close parent_fd)"); + perror("apply_default_acl (close parent_fd)"); 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 - If symlinks or hard links are encountered. - * 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 be9d50e..1a7f802 100644 --- a/src/libadacl.h +++ b/src/libadacl.h @@ -15,8 +15,4 @@ #define ACL_FAILURE 0 #define ACL_SUCCESS 1 -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);