#define ACL_SUCCESS 1
-/* Command-line options */
-static bool no_exec_mask = false;
-
-
/**
* @brief Get the mode bits from the given 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;
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;
}
*
* 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
* 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 */
}
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. */
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) {