-/**
- * @brief Wrapper around @c apply_default_acl() for use with @c nftw().
- *
- * For parameter information, see the @c nftw man page.
- *
- * @return If the ACL was applied to @c target successfully, we return
- * @c FTW_CONTINUE to signal to @ nftw() that we should proceed onto
- * the next file or directory. Otherwise, we return @c FTW_STOP to
- * signal failure.
- *
- */
-int apply_default_acl_nftw(const char *target,
- const struct stat *sp,
- int info,
- struct FTW *ftw) {
-
- if (apply_default_acl(target, sp, false)) {
- 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 *sp,
- int info,
- struct FTW *ftw) {
-
- if (apply_default_acl(target, sp, true)) {
- return FTW_CONTINUE;
- }
- else {
- return FTW_STOP;
- }
-}
-
-
-
-/**
- * @brief Recursive version of @c apply_default_acl().
- *
- * If @c target is a directory, we use @c nftw() to call @c
- * apply_default_acl() recursively on all of its children. Otherwise,
- * we just delegate to @c apply_default_acl().
- *
- * 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
- * the return value of @c nftw(). If @c nftw() succeeds (returns 0),
- * then we return @c true. Otherwise, we return @c false.
- * \n\n
- * 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 no_exec_mask) {
- int max_levels = 256;
- int flags = FTW_PHYS; /* Don't follow links. */
-
- /* 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 */
- return true;
- }
-
- /* nftw will return NFTW_ERROR on error, or if the supplied function
- * (apply_default_acl_nftw) returns a non-zero result, nftw will
- * return that.
- */
- if (nftw_result == NFTW_ERROR) {
- perror("apply_default_acl_recursive (nftw)");
- }
-
- return false;
-}
-