2 * @file apply-default-acl.c
4 * @brief The entire implementation.
8 /* On Linux, ftw.h needs this special voodoo to work. */
9 #define _XOPEN_SOURCE 500
13 #include <fcntl.h> /* AT_FOO constants */
14 #include <ftw.h> /* nftw() et al. */
16 #include <libgen.h> /* basename(), dirname() */
17 #include <limits.h> /* PATH_MAX */
26 #include <acl/libacl.h> /* acl_get_perm, not portable */
27 #include <sys/types.h>
30 /* Most of the libacl functions return 1 for success, 0 for failure,
37 int safe_open_ex(int at_fd
, char* pathname
, int flags
) {
38 if (pathname
!= NULL
&& strlen(pathname
) == 0) {
39 /* Oops, went one level to deep with nothing to do. */
43 char* firstslash
= strchr(pathname
, '/');
44 if (firstslash
== NULL
) {
45 /* No more slashes, this is the base case. */
46 int r
= openat(at_fd
, pathname
, flags
);
50 /* Temporarily disable the slash, so that the subsequent call to
51 openat() opens only the next directory (and doesn't recurse). */
53 int fd
= safe_open_ex(at_fd
, pathname
, flags
);
55 /* The ++ is safe because there needs to be at least a null byte
56 after the first slash, even if it's the last real character in
58 int result
= safe_open_ex(fd
, firstslash
+1, flags
);
59 if (close(fd
) == -1) {
60 perror("safe_open_ex (close)");
67 int safe_open(const char* pathname
, int flags
) {
68 if (pathname
== NULL
|| strlen(pathname
) == 0 || pathname
[0] == '\0') {
73 char abspath
[PATH_MAX
];
74 int snprintf_result
= 0;
75 if (strchr(pathname
, '/') == pathname
) {
76 /* pathname is already absolute; just copy it. */
77 snprintf_result
= snprintf(abspath
, PATH_MAX
, "%s", pathname
);
80 /* Concatenate the current working directory and pathname into an
81 * absolute path. We use realpath() ONLY on the cwd part, and not
82 * on the pathname part, because realpath() resolves symlinks. And
83 * the whole point of all this crap is to avoid following symlinks
86 * Using realpath() on the cwd lets us operate on relative paths
87 * while we're sitting in a directory that happens to have a
88 * symlink in it; for example: cd /var/run && apply-default-acl foo.
90 char* cwd
= get_current_dir_name();
92 perror("safe_open (get_current_dir_name)");
96 char abs_cwd
[PATH_MAX
];
97 if (realpath(cwd
, abs_cwd
) == NULL
) {
98 perror("safe_open (realpath)");
102 snprintf_result
= snprintf(abspath
, PATH_MAX
, "%s/%s", abs_cwd
, pathname
);
105 if (snprintf_result
== -1 || snprintf_result
> PATH_MAX
) {
106 perror("safe_open (snprintf)");
110 int fd
= open("/", flags
);
111 if (strcmp(abspath
, "/") == 0) {
115 int result
= safe_open_ex(fd
, abspath
+1, flags
);
116 if (close(fd
) == -1) {
117 perror("safe_open (close)");
126 * @brief Determine whether or not the given path is accessible.
131 * @return true if @c path is accessible to the current effective
132 * user/group, false otherwise.
134 bool path_accessible(const char* path
) {
139 /* Test for access using the effective user and group rather than
141 int flags
= AT_EACCESS
;
143 /* Don't follow symlinks when checking for a path's existence,
144 since we won't follow them to set its ACLs either. */
145 flags
|= AT_SYMLINK_NOFOLLOW
;
147 /* If the path is relative, interpret it relative to the current
148 working directory (just like the access() system call). */
149 if (faccessat(AT_FDCWD
, path
, F_OK
, flags
) == 0) {
160 * @brief Update (or create) an entry in an @b minimal ACL.
162 * This function will not work if @c aclp contains extended
163 * entries. This is fine for our purposes, since we call @c wipe_acls
164 * on each path before applying the default to it.
166 * The assumption that there are no extended entries makes things much
167 * simpler. For example, we only have to update the @c ACL_USER_OBJ,
168 * @c ACL_GROUP_OBJ, and @c ACL_OTHER entries -- all others can simply
169 * be created anew. This means we don't have to fool around comparing
170 * named-user/group entries.
173 * A pointer to the acl_t structure whose entry we want to modify.
176 * The new entry. If @c entry contains a user/group/other entry, we
177 * update the existing one. Otherwise we create a new entry.
179 * @return If there is an unexpected library error, @c ACL_ERROR is
180 * returned. Otherwise, @c ACL_SUCCESS.
183 int acl_set_entry(acl_t
* aclp
, acl_entry_t entry
) {
186 if (acl_get_tag_type(entry
, &entry_tag
) == ACL_ERROR
) {
187 perror("acl_set_entry (acl_get_tag_type)");
191 acl_permset_t entry_permset
;
192 if (acl_get_permset(entry
, &entry_permset
) == ACL_ERROR
) {
193 perror("acl_set_entry (acl_get_permset)");
197 acl_entry_t existing_entry
;
198 /* Loop through the given ACL looking for matching entries. */
199 int result
= acl_get_entry(*aclp
, ACL_FIRST_ENTRY
, &existing_entry
);
201 while (result
== ACL_SUCCESS
) {
202 acl_tag_t existing_tag
= ACL_UNDEFINED_TAG
;
204 if (acl_get_tag_type(existing_entry
, &existing_tag
) == ACL_ERROR
) {
205 perror("set_acl_tag_permset (acl_get_tag_type)");
209 if (existing_tag
== entry_tag
) {
210 if (entry_tag
== ACL_USER_OBJ
||
211 entry_tag
== ACL_GROUP_OBJ
||
212 entry_tag
== ACL_OTHER
) {
213 /* Only update for these three since all other tags will have
214 been wiped. These three are guaranteed to exist, so if we
215 match one of them, we're allowed to return ACL_SUCCESS
216 below and bypass the rest of the function. */
217 acl_permset_t existing_permset
;
218 if (acl_get_permset(existing_entry
, &existing_permset
) == ACL_ERROR
) {
219 perror("acl_set_entry (acl_get_permset)");
223 if (acl_set_permset(existing_entry
, entry_permset
) == ACL_ERROR
) {
224 perror("acl_set_entry (acl_set_permset)");
233 result
= acl_get_entry(*aclp
, ACL_NEXT_ENTRY
, &existing_entry
);
236 /* This catches both the initial acl_get_entry and the ones at the
238 if (result
== ACL_ERROR
) {
239 perror("acl_set_entry (acl_get_entry)");
243 /* If we've made it this far, we need to add a new entry to the
245 acl_entry_t new_entry
;
247 /* The acl_create_entry() function can allocate new memory and/or
248 * change the location of the ACL structure entirely. When that
249 * happens, the value pointed to by aclp is updated, which means
250 * that a new acl_t gets "passed out" to our caller, eventually to
251 * be fed to acl_free(). In other words, we should still be freeing
252 * the right thing, even if the value pointed to by aclp changes.
254 if (acl_create_entry(aclp
, &new_entry
) == ACL_ERROR
) {
255 perror("acl_set_entry (acl_create_entry)");
259 if (acl_set_tag_type(new_entry
, entry_tag
) == ACL_ERROR
) {
260 perror("acl_set_entry (acl_set_tag_type)");
264 if (acl_set_permset(new_entry
, entry_permset
) == ACL_ERROR
) {
265 perror("acl_set_entry (acl_set_permset)");
269 if (entry_tag
== ACL_USER
|| entry_tag
== ACL_GROUP
) {
270 /* We need to set the qualifier too. */
271 void* entry_qual
= acl_get_qualifier(entry
);
272 if (entry_qual
== (void*)NULL
) {
273 perror("acl_set_entry (acl_get_qualifier)");
277 if (acl_set_qualifier(new_entry
, entry_qual
) == ACL_ERROR
) {
278 perror("acl_set_entry (acl_set_qualifier)");
289 * @brief Determine the number of entries in the given ACL.
292 * The ACL to inspect.
294 * @return Either the non-negative number of entries in @c acl, or
295 * @c ACL_ERROR on error.
297 int acl_entry_count(acl_t acl
) {
301 int result
= acl_get_entry(acl
, ACL_FIRST_ENTRY
, &entry
);
303 while (result
== ACL_SUCCESS
) {
305 result
= acl_get_entry(acl
, ACL_NEXT_ENTRY
, &entry
);
308 if (result
== ACL_ERROR
) {
309 perror("acl_entry_count (acl_get_entry)");
319 * @brief Determine whether or not the given ACL is minimal.
321 * An ACL is minimal if it has fewer than four entries.
324 * The ACL whose minimality is in question.
327 * - @c ACL_SUCCESS - @c acl is minimal
328 * - @c ACL_FAILURE - @c acl is not minimal
329 * - @c ACL_ERROR - Unexpected library error
331 int acl_is_minimal(acl_t acl
) {
333 int ec
= acl_entry_count(acl
);
335 if (ec
== ACL_ERROR
) {
336 perror("acl_is_minimal (acl_entry_count)");
351 * @brief Determine whether the given ACL's mask denies execute.
354 * The ACL whose mask we want to check.
357 * - @c ACL_SUCCESS - The @c acl has a mask which denies execute.
358 * - @c ACL_FAILURE - The @c acl has a mask which does not deny execute.
359 * - @c ACL_ERROR - Unexpected library error.
361 int acl_execute_masked(acl_t acl
) {
364 int ge_result
= acl_get_entry(acl
, ACL_FIRST_ENTRY
, &entry
);
366 while (ge_result
== ACL_SUCCESS
) {
367 acl_tag_t tag
= ACL_UNDEFINED_TAG
;
369 if (acl_get_tag_type(entry
, &tag
) == ACL_ERROR
) {
370 perror("acl_execute_masked (acl_get_tag_type)");
374 if (tag
== ACL_MASK
) {
375 /* This is the mask entry, get its permissions, and see if
376 execute is specified. */
377 acl_permset_t permset
;
379 if (acl_get_permset(entry
, &permset
) == ACL_ERROR
) {
380 perror("acl_execute_masked (acl_get_permset)");
384 int gp_result
= acl_get_perm(permset
, ACL_EXECUTE
);
385 if (gp_result
== ACL_ERROR
) {
386 perror("acl_execute_masked (acl_get_perm)");
390 if (gp_result
== ACL_FAILURE
) {
391 /* No execute bit set in the mask; execute not allowed. */
396 ge_result
= acl_get_entry(acl
, ACL_NEXT_ENTRY
, &entry
);
405 * @brief Determine whether @c fd is executable by anyone.
408 * This is used as part of the heuristic to determine whether or not
409 * we should mask the execute bit when inheriting an ACL. If @c fd
410 * describes a file, we check the @a effective permissions, contrary
411 * to what setfacl does.
414 * The file descriptor to check.
417 * A pointer to a stat structure for @c fd.
420 * - @c ACL_SUCCESS - Someone has effective execute permissions on @c fd.
421 * - @c ACL_FAILURE - Nobody can execute @c fd.
422 * - @c ACL_ERROR - Unexpected library error.
424 int any_can_execute(int fd
, const struct stat
* sp
) {
425 acl_t acl
= acl_get_fd(fd
);
427 if (acl
== (acl_t
)NULL
) {
428 perror("any_can_execute (acl_get_file)");
432 /* Our return value. */
433 int result
= ACL_FAILURE
;
435 if (acl_is_minimal(acl
)) {
436 if (sp
->st_mode
& (S_IXUSR
| S_IXOTH
| S_IXGRP
)) {
437 result
= ACL_SUCCESS
;
441 result
= ACL_FAILURE
;
447 int ge_result
= acl_get_entry(acl
, ACL_FIRST_ENTRY
, &entry
);
449 while (ge_result
== ACL_SUCCESS
) {
450 /* The first thing we do is check to see if this is a mask
451 entry. If it is, we skip it entirely. */
452 acl_tag_t tag
= ACL_UNDEFINED_TAG
;
454 if (acl_get_tag_type(entry
, &tag
) == ACL_ERROR
) {
455 perror("any_can_execute_or (acl_get_tag_type)");
460 if (tag
== ACL_MASK
) {
461 ge_result
= acl_get_entry(acl
, ACL_NEXT_ENTRY
, &entry
);
465 /* Ok, so it's not a mask entry. Check the execute perms. */
466 acl_permset_t permset
;
468 if (acl_get_permset(entry
, &permset
) == ACL_ERROR
) {
469 perror("any_can_execute_or (acl_get_permset)");
474 int gp_result
= acl_get_perm(permset
, ACL_EXECUTE
);
475 if (gp_result
== ACL_ERROR
) {
476 perror("any_can_execute (acl_get_perm)");
481 if (gp_result
== ACL_SUCCESS
) {
482 /* Only return ACL_SUCCESS if this execute bit is not masked. */
483 if (acl_execute_masked(acl
) != ACL_SUCCESS
) {
484 result
= ACL_SUCCESS
;
489 ge_result
= acl_get_entry(acl
, ACL_NEXT_ENTRY
, &entry
);
492 if (ge_result
== ACL_ERROR
) {
493 perror("any_can_execute (acl_get_entry)");
506 * @brief Set @c acl as the default ACL on @c path.
508 * This overwrites any existing default ACL on @c path. If @c path is
509 * not a directory, we return ACL_ERROR and @c errno is set.
512 * The target directory whose ACL we wish to replace or create.
515 * The ACL to set as default on @c path.
518 * - @c ACL_SUCCESS - The default ACL was assigned successfully.
519 * - @c ACL_ERROR - Unexpected library error.
521 int assign_default_acl(const char* path
, acl_t acl
) {
525 perror("assign_default_acl (args)");
529 /* Our return value; success unless something bad happens. */
530 int result
= ACL_SUCCESS
;
531 acl_t path_acl
= acl_dup(acl
);
533 if (path_acl
== (acl_t
)NULL
) {
534 perror("assign_default_acl (acl_dup)");
535 return ACL_ERROR
; /* Nothing to clean up in this case. */
538 if (acl_set_file(path
, ACL_TYPE_DEFAULT
, path_acl
) == ACL_ERROR
) {
539 perror("assign_default_acl (acl_set_file)");
550 * @brief Remove all @c ACL_TYPE_ACCESS entries from the given file
551 * descriptor, leaving the UNIX permission bits.
554 * The file descriptor whose ACLs we want to wipe.
557 * - @c ACL_SUCCESS - The ACLs were wiped successfully, or none
558 * existed in the first place.
559 * - @c ACL_ERROR - Unexpected library error.
561 int wipe_acls(int fd
) {
562 /* Initialize an empty ACL, and then overwrite the one on "fd" with it. */
563 acl_t empty_acl
= acl_init(0);
565 if (empty_acl
== (acl_t
)NULL
) {
566 perror("wipe_acls (acl_init)");
570 if (acl_set_fd(fd
, empty_acl
) == ACL_ERROR
) {
571 perror("wipe_acls (acl_set_fd)");
583 * @brief Apply parent default ACL to a path.
585 * This overwrites any existing ACLs on @c path.
588 * The path whose ACL we would like to reset to its default.
591 * A pointer to a stat structure for @c path, or @c NULL if you don't
594 * @param no_exec_mask
595 * The value (either true or false) of the --no-exec-mask flag.
598 * - @c ACL_SUCCESS - The parent default ACL was inherited successfully.
599 * - @c ACL_FAILURE - The target path is not a regular file/directory,
600 * or the parent of @c path is not a directory.
601 * - @c ACL_ERROR - Unexpected library error.
603 int apply_default_acl(const char* path
,
604 const struct stat
* sp
,
609 perror("apply_default_acl (args)");
613 /* Define these next three variables here because we may have to
614 * jump to the cleanup routine which expects them to exist.
617 /* Our return value. */
618 int result
= ACL_SUCCESS
;
620 /* The default ACL on path's parent directory */
621 acl_t defacl
= (acl_t
)NULL
;
623 /* The file descriptor corresponding to "path" */
626 /* Get the parent directory of "path" with dirname(), which happens
627 * to murder its argument and necessitates a path_copy.
629 char* path_copy
= strdup(path
);
630 if (path_copy
== NULL
) {
631 perror("apply_default_acl (strdup)");
634 char* parent
= dirname(path_copy
);
636 fd
= safe_open(path
, O_NOFOLLOW
);
638 if (errno
== ELOOP
) {
639 result
= ACL_FAILURE
; /* hit a symlink */
643 perror("apply_default_acl (open fd)");
650 /* Refuse to operate on hard links, which can be abused by an
651 * attacker to trick us into changing the ACL on a file we didn't
652 * intend to; namely the "target" of the hard link. There is TOCTOU
653 * race condition here, but the window is as small as possible
654 * between when we open the file descriptor (look above) and when we
657 * Note: we only need to call fstat ourselves if we weren't passed a
658 * valid pointer to a stat structure (nftw does that).
662 if (fstat(fd
, &s
) == -1) {
663 perror("apply_default_acl (fstat)");
670 if (!S_ISDIR(sp
->st_mode
)) {
671 /* If it's not a directory, make sure it's a regular,
672 non-hard-linked file. */
673 if (!S_ISREG(sp
->st_mode
) || sp
->st_nlink
!= 1) {
674 result
= ACL_FAILURE
;
680 /* Default to not masking the exec bit; i.e. applying the default
681 ACL literally. If --no-exec-mask was not specified, then we try
682 to "guess" whether or not to mask the exec bit. This behavior
683 is modeled after the capital 'X' perms of setfacl. */
684 bool allow_exec
= true;
687 /* Never mask the execute bit on directories. */
688 int ace_result
= any_can_execute(fd
,sp
) || S_ISDIR(sp
->st_mode
);
690 if (ace_result
== ACL_ERROR
) {
691 perror("apply_default_acl (any_can_execute)");
696 allow_exec
= (bool)ace_result
;
699 defacl
= acl_get_file(parent
, ACL_TYPE_DEFAULT
);
701 if (defacl
== (acl_t
)NULL
) {
702 perror("apply_default_acl (acl_get_file)");
707 if (wipe_acls(fd
) == ACL_ERROR
) {
708 perror("apply_default_acl (wipe_acls)");
713 /* Do this after wipe_acls(), otherwise we'll overwrite the wiped
714 ACL with this one. */
715 acl_t acl
= acl_get_fd(fd
);
716 if (acl
== (acl_t
)NULL
) {
717 perror("apply_default_acl (acl_get_fd)");
722 /* If it's a directory, inherit the parent's default. We sure hope
723 * that "path" still points to the same thing that "fd" and this
724 * "sp" describe. If not, we may wind up trying to set a default ACL
725 * on a file, and this will throw an error. I guess that's what we
728 if (S_ISDIR(sp
->st_mode
) && assign_default_acl(path
, defacl
) == ACL_ERROR
) {
729 perror("apply_default_acl (assign_default_acl)");
735 int ge_result
= acl_get_entry(defacl
, ACL_FIRST_ENTRY
, &entry
);
737 while (ge_result
== ACL_SUCCESS
) {
738 acl_tag_t tag
= ACL_UNDEFINED_TAG
;
740 if (acl_get_tag_type(entry
, &tag
) == ACL_ERROR
) {
741 perror("apply_default_acl (acl_get_tag_type)");
747 /* We've got an entry/tag from the default ACL. Get its permset. */
748 acl_permset_t permset
;
749 if (acl_get_permset(entry
, &permset
) == ACL_ERROR
) {
750 perror("apply_default_acl (acl_get_permset)");
755 /* If this is a default mask, fix it up. */
756 if (tag
== ACL_MASK
||
757 tag
== ACL_USER_OBJ
||
758 tag
== ACL_GROUP_OBJ
||
762 /* The mask doesn't affect acl_user_obj, acl_group_obj (in
763 minimal ACLs) or acl_other entries, so if execute should be
764 masked, we have to do it manually. */
765 if (acl_delete_perm(permset
, ACL_EXECUTE
) == ACL_ERROR
) {
766 perror("apply_default_acl (acl_delete_perm)");
771 if (acl_set_permset(entry
, permset
) == ACL_ERROR
) {
772 perror("apply_default_acl (acl_set_permset)");
779 /* Finally, add the permset to the access ACL. It's actually
780 * important that we pass in the address of "acl" here, and not
781 * "acl" itself. Why? The call to acl_create_entry() within
782 * acl_set_entry() can allocate new memory for the entry.
783 * Sometimes that can be done in-place, in which case everything
784 * is cool and the new memory gets released when we call
787 * But occasionally, the whole ACL structure will have to be moved
788 * in order to allocate the extra space. When that happens,
789 * acl_create_entry() modifies the pointer it was passed (in this
790 * case, &acl) to point to the new location. We want to call
791 * acl_free() on the new location, and since acl_free() gets
792 * called right here, we need acl_create_entry() to update the
793 * value of "acl". To do that, it needs the address of "acl".
795 if (acl_set_entry(&acl
, entry
) == ACL_ERROR
) {
796 perror("apply_default_acl (acl_set_entry)");
801 ge_result
= acl_get_entry(defacl
, ACL_NEXT_ENTRY
, &entry
);
804 /* Catches the first acl_get_entry as well as the ones at the end of
806 if (ge_result
== ACL_ERROR
) {
807 perror("apply_default_acl (acl_get_entry)");
812 if (acl_set_fd(fd
, acl
) == ACL_ERROR
) {
813 perror("apply_default_acl (acl_set_fd)");
820 if (defacl
!= (acl_t
)NULL
) {
823 if (fd
>= 0 && close(fd
) == -1) {
824 perror("apply_default_acl (close)");
833 * @brief Display program usage information.
835 * @param program_name
836 * The program name to use in the output.
839 void usage(const char* program_name
) {
840 printf("Apply any applicable default ACLs to the given files or "
842 printf("Usage: %s [flags] <target1> [<target2> [ <target3>...]]\n\n",
845 printf(" -h, --help Print this help message\n");
846 printf(" -r, --recursive Act on any given directories recursively\n");
847 printf(" -x, --no-exec-mask Apply execute permissions unconditionally\n");
854 * @brief Wrapper around @c apply_default_acl() for use with @c nftw().
856 * For parameter information, see the @c nftw man page.
858 * @return If the ACL was applied to @c target successfully, we return
859 * @c FTW_CONTINUE to signal to @ nftw() that we should proceed onto
860 * the next file or directory. Otherwise, we return @c FTW_STOP to
864 int apply_default_acl_nftw(const char *target
,
865 const struct stat
*sp
,
869 if (apply_default_acl(target
, sp
, false)) {
880 * @brief Wrapper around @c apply_default_acl() for use with @c nftw().
882 * This is identical to @c apply_default_acl_nftw(), except it passes
883 * @c true to @c apply_default_acl() as its no_exec_mask argument.
886 int apply_default_acl_nftw_x(const char *target
,
887 const struct stat
*sp
,
891 if (apply_default_acl(target
, sp
, true)) {
902 * @brief Recursive version of @c apply_default_acl().
904 * If @c target is a directory, we use @c nftw() to call @c
905 * apply_default_acl() recursively on all of its children. Otherwise,
906 * we just delegate to @c apply_default_acl().
908 * We ignore symlinks for consistency with chmod -r.
911 * The root (path) of the recursive application.
913 * @param no_exec_mask
914 * The value (either true or false) of the --no-exec-mask flag.
917 * If @c target is not a directory, we return the result of
918 * calling @c apply_default_acl() on @c target. Otherwise, we convert
919 * the return value of @c nftw(). If @c nftw() succeeds (returns 0),
920 * then we return @c true. Otherwise, we return @c false.
922 * If there is an error, it will be reported via @c perror, but
923 * we still return @c false.
925 bool apply_default_acl_recursive(const char *target
, bool no_exec_mask
) {
926 int max_levels
= 256;
927 int flags
= FTW_PHYS
; /* Don't follow links. */
929 /* There are two separate functions that could be passed to
930 nftw(). One passes no_exec_mask = true to apply_default_acl(),
931 and the other passes no_exec_mask = false. Since the function we
932 pass to nftw() cannot have parameters, we have to create separate
933 options and make the decision here. */
934 int (*fn
)(const char *, const struct stat
*, int, struct FTW
*) = NULL
;
935 fn
= no_exec_mask
? apply_default_acl_nftw_x
: apply_default_acl_nftw
;
937 int nftw_result
= nftw(target
, fn
, max_levels
, flags
);
939 if (nftw_result
== 0) {
944 /* nftw will return -1 on error, or if the supplied function
945 * (apply_default_acl_nftw) returns a non-zero result, nftw will
948 if (nftw_result
== -1) {
949 perror("apply_default_acl_recursive (nftw)");
958 * @brief Call apply_default_acl (possibly recursively) on each
959 * command-line argument.
961 * @return Either @c EXIT_FAILURE or @c EXIT_SUCCESS. If everything
962 * goes as expected, we return @c EXIT_SUCCESS. Otherwise, we return
965 int main(int argc
, char* argv
[]) {
972 bool recursive
= false;
973 bool no_exec_mask
= false;
975 struct option long_options
[] = {
976 /* These options set a flag. */
977 {"help", no_argument
, NULL
, 'h'},
978 {"recursive", no_argument
, NULL
, 'r'},
979 {"no-exec-mask", no_argument
, NULL
, 'x'},
985 while ((opt
= getopt_long(argc
, argv
, "hrx", long_options
, NULL
)) != -1) {
1002 int result
= EXIT_SUCCESS
;
1005 for (arg_index
= optind
; arg_index
< argc
; arg_index
++) {
1006 const char* target
= argv
[arg_index
];
1007 bool reapp_result
= false;
1009 /* Make sure we can access the given path before we go out of our
1010 * way to please it. Doing this check outside of
1011 * apply_default_acl() lets us spit out a better error message for
1014 if (!path_accessible(target
)) {
1015 fprintf(stderr
, "%s: %s: No such file or directory\n", argv
[0], target
);
1016 result
= EXIT_FAILURE
;
1021 reapp_result
= apply_default_acl_recursive(target
, no_exec_mask
);
1024 /* It's either a normal file, or we're not operating recursively. */
1025 reapp_result
= apply_default_acl(target
, NULL
, no_exec_mask
);
1028 if (!reapp_result
) {
1029 result
= EXIT_FAILURE
;