From: Michael Orlitzky Date: Fri, 25 Jan 2013 04:17:45 +0000 (-0500) Subject: Replace the global no_exec_mask variable with a slightly less-awful solution. X-Git-Tag: v0.0.4~3 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=012ac3813d30a1bc3f405a2f8f33809cea607c6c;p=apply-default-acl.git Replace the global no_exec_mask variable with a slightly less-awful solution. --- diff --git a/src/apply-default-acl.c b/src/apply-default-acl.c index b279814..5fea3a3 100644 --- a/src/apply-default-acl.c +++ b/src/apply-default-acl.c @@ -33,10 +33,6 @@ #define ACL_SUCCESS 1 -/* Command-line options */ -static bool no_exec_mask = false; - - /** * @brief Get the mode bits from the given path. @@ -611,13 +607,16 @@ int wipe_acls(const char* path) { * @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) { +int apply_default_acl(const char* path, bool no_exec_mask) { if (path == NULL) { errno = ENOENT; @@ -807,7 +806,30 @@ int apply_default_acl_nftw(const char *target, int info, struct FTW *ftw) { - bool app_result = apply_default_acl(target); + bool app_result = apply_default_acl(target, false); + if (app_result) { + return FTW_CONTINUE; + } + else { + return FTW_STOP; + } +} + + + +/** + * @brief Wrapper around @c apply_default_acl() for use with @c nftw(). + * + * This is identical to @c apply_default_acl_nftw(), except it passes + * @c true to @c apply_default_acl() as its no_exec_mask argument. + * + */ +int apply_default_acl_nftw_x(const char *target, + const struct stat *s, + int info, + struct FTW *ftw) { + + bool app_result = apply_default_acl(target, true); if (app_result) { return FTW_CONTINUE; } @@ -827,6 +849,12 @@ int apply_default_acl_nftw(const char *target, * * We ignore symlinks for consistency with chmod -r. * + * @param target + * The root (path) of the recursive application. + * + * @param no_exec_mask + * The value (either true or false) of the --no-exec-mask flag. + * * @return * If @c target is not a directory, we return the result of * calling @c apply_default_acl() on @c target. Otherwise, we convert @@ -836,19 +864,24 @@ int apply_default_acl_nftw(const char *target, * If there is an error, it will be reported via @c perror, but * we still return @c false. */ -bool apply_default_acl_recursive(const char *target) { +bool apply_default_acl_recursive(const char *target, bool no_exec_mask) { if (!is_directory(target)) { - return apply_default_acl(target); + return apply_default_acl(target, no_exec_mask); } int max_levels = 256; int flags = FTW_PHYS; /* Don't follow links. */ - int nftw_result = nftw(target, - apply_default_acl_nftw, - max_levels, - flags); + /* There are two separate functions that could be passed to + nftw(). One passes no_exec_mask = true to apply_default_acl(), + and the other passes no_exec_mask = false. Since the function we + pass to nftw() cannot have parameters, we have to create separate + options and make the decision here. */ + int (*fn)(const char *, const struct stat *, int, struct FTW *) = NULL; + fn = no_exec_mask ? apply_default_acl_nftw_x : apply_default_acl_nftw; + + int nftw_result = nftw(target, fn, max_levels, flags); if (nftw_result == 0) { /* Success */ @@ -884,7 +917,7 @@ int main(int argc, char* argv[]) { } bool recursive = false; - /* bool no_exec_mask is declared static/global */ + bool no_exec_mask = false; struct option long_options[] = { /* These options set a flag. */ @@ -921,11 +954,11 @@ int main(int argc, char* argv[]) { bool reapp_result = false; if (recursive) { - reapp_result = apply_default_acl_recursive(target); + reapp_result = apply_default_acl_recursive(target, no_exec_mask); } else { /* It's either normal file, or we're not operating recursively. */ - reapp_result = apply_default_acl(target); + reapp_result = apply_default_acl(target, no_exec_mask); } if (!reapp_result) {