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
);
56 /* Don't output anything if we ignore a symlink */
57 perror("safe_open_ex (safe_open_ex)");
62 /* The ++ is safe because there needs to be at least a null byte
63 after the first slash, even if it's the last real character in
65 int result
= safe_open_ex(fd
, firstslash
+1, flags
);
66 if (close(fd
) == -1) {
67 perror("safe_open_ex (close)");
74 int safe_open(const char* pathname
, int flags
) {
75 if (pathname
== NULL
|| strlen(pathname
) == 0 || pathname
[0] == '\0') {
80 char abspath
[PATH_MAX
];
81 int snprintf_result
= 0;
82 if (strchr(pathname
, '/') == pathname
) {
83 /* pathname is already absolute; just copy it. */
84 snprintf_result
= snprintf(abspath
, PATH_MAX
, "%s", pathname
);
87 /* Concatenate the current working directory and pathname into an
88 * absolute path. We use realpath() ONLY on the cwd part, and not
89 * on the pathname part, because realpath() resolves symlinks. And
90 * the whole point of all this crap is to avoid following symlinks
93 * Using realpath() on the cwd lets us operate on relative paths
94 * while we're sitting in a directory that happens to have a
95 * symlink in it; for example: cd /var/run && apply-default-acl foo.
97 char* cwd
= get_current_dir_name();
99 perror("safe_open (get_current_dir_name)");
103 char abs_cwd
[PATH_MAX
];
104 if (realpath(cwd
, abs_cwd
) == NULL
) {
105 perror("safe_open (realpath)");
109 snprintf_result
= snprintf(abspath
, PATH_MAX
, "%s/%s", abs_cwd
, pathname
);
112 if (snprintf_result
== -1 || snprintf_result
> PATH_MAX
) {
113 perror("safe_open (snprintf)");
117 int fd
= open("/", flags
);
118 if (strcmp(abspath
, "/") == 0) {
122 int result
= safe_open_ex(fd
, abspath
+1, flags
);
123 if (close(fd
) == -1) {
124 perror("safe_open (close)");
133 * @brief Determine whether or not the given path is accessible.
138 * @return true if @c path is accessible to the current effective
139 * user/group, false otherwise.
141 bool path_accessible(const char* path
) {
146 /* Test for access using the effective user and group rather than
148 int flags
= AT_EACCESS
;
150 /* Don't follow symlinks when checking for a path's existence,
151 since we won't follow them to set its ACLs either. */
152 flags
|= AT_SYMLINK_NOFOLLOW
;
154 /* If the path is relative, interpret it relative to the current
155 working directory (just like the access() system call). */
156 if (faccessat(AT_FDCWD
, path
, F_OK
, flags
) == 0) {
167 * @brief Update (or create) an entry in an @b minimal ACL.
169 * This function will not work if @c aclp contains extended
170 * entries. This is fine for our purposes, since we call @c wipe_acls
171 * on each path before applying the default to it.
173 * The assumption that there are no extended entries makes things much
174 * simpler. For example, we only have to update the @c ACL_USER_OBJ,
175 * @c ACL_GROUP_OBJ, and @c ACL_OTHER entries -- all others can simply
176 * be created anew. This means we don't have to fool around comparing
177 * named-user/group entries.
180 * A pointer to the acl_t structure whose entry we want to modify.
183 * The new entry. If @c entry contains a user/group/other entry, we
184 * update the existing one. Otherwise we create a new entry.
186 * @return If there is an unexpected library error, @c ACL_ERROR is
187 * returned. Otherwise, @c ACL_SUCCESS.
190 int acl_set_entry(acl_t
* aclp
, acl_entry_t entry
) {
193 if (acl_get_tag_type(entry
, &entry_tag
) == ACL_ERROR
) {
194 perror("acl_set_entry (acl_get_tag_type)");
198 acl_permset_t entry_permset
;
199 if (acl_get_permset(entry
, &entry_permset
) == ACL_ERROR
) {
200 perror("acl_set_entry (acl_get_permset)");
204 acl_entry_t existing_entry
;
205 /* Loop through the given ACL looking for matching entries. */
206 int result
= acl_get_entry(*aclp
, ACL_FIRST_ENTRY
, &existing_entry
);
208 while (result
== ACL_SUCCESS
) {
209 acl_tag_t existing_tag
= ACL_UNDEFINED_TAG
;
211 if (acl_get_tag_type(existing_entry
, &existing_tag
) == ACL_ERROR
) {
212 perror("set_acl_tag_permset (acl_get_tag_type)");
216 if (existing_tag
== entry_tag
) {
217 if (entry_tag
== ACL_USER_OBJ
||
218 entry_tag
== ACL_GROUP_OBJ
||
219 entry_tag
== ACL_OTHER
) {
220 /* Only update for these three since all other tags will have
221 been wiped. These three are guaranteed to exist, so if we
222 match one of them, we're allowed to return ACL_SUCCESS
223 below and bypass the rest of the function. */
224 acl_permset_t existing_permset
;
225 if (acl_get_permset(existing_entry
, &existing_permset
) == ACL_ERROR
) {
226 perror("acl_set_entry (acl_get_permset)");
230 if (acl_set_permset(existing_entry
, entry_permset
) == ACL_ERROR
) {
231 perror("acl_set_entry (acl_set_permset)");
240 result
= acl_get_entry(*aclp
, ACL_NEXT_ENTRY
, &existing_entry
);
243 /* This catches both the initial acl_get_entry and the ones at the
245 if (result
== ACL_ERROR
) {
246 perror("acl_set_entry (acl_get_entry)");
250 /* If we've made it this far, we need to add a new entry to the
252 acl_entry_t new_entry
;
254 /* The acl_create_entry() function can allocate new memory and/or
255 * change the location of the ACL structure entirely. When that
256 * happens, the value pointed to by aclp is updated, which means
257 * that a new acl_t gets "passed out" to our caller, eventually to
258 * be fed to acl_free(). In other words, we should still be freeing
259 * the right thing, even if the value pointed to by aclp changes.
261 if (acl_create_entry(aclp
, &new_entry
) == ACL_ERROR
) {
262 perror("acl_set_entry (acl_create_entry)");
266 if (acl_set_tag_type(new_entry
, entry_tag
) == ACL_ERROR
) {
267 perror("acl_set_entry (acl_set_tag_type)");
271 if (acl_set_permset(new_entry
, entry_permset
) == ACL_ERROR
) {
272 perror("acl_set_entry (acl_set_permset)");
276 if (entry_tag
== ACL_USER
|| entry_tag
== ACL_GROUP
) {
277 /* We need to set the qualifier too. */
278 void* entry_qual
= acl_get_qualifier(entry
);
279 if (entry_qual
== (void*)NULL
) {
280 perror("acl_set_entry (acl_get_qualifier)");
284 if (acl_set_qualifier(new_entry
, entry_qual
) == ACL_ERROR
) {
285 perror("acl_set_entry (acl_set_qualifier)");
296 * @brief Determine the number of entries in the given ACL.
299 * The ACL to inspect.
301 * @return Either the non-negative number of entries in @c acl, or
302 * @c ACL_ERROR on error.
304 int acl_entry_count(acl_t acl
) {
308 int result
= acl_get_entry(acl
, ACL_FIRST_ENTRY
, &entry
);
310 while (result
== ACL_SUCCESS
) {
312 result
= acl_get_entry(acl
, ACL_NEXT_ENTRY
, &entry
);
315 if (result
== ACL_ERROR
) {
316 perror("acl_entry_count (acl_get_entry)");
326 * @brief Determine whether or not the given ACL is minimal.
328 * An ACL is minimal if it has fewer than four entries.
331 * The ACL whose minimality is in question.
334 * - @c ACL_SUCCESS - @c acl is minimal
335 * - @c ACL_FAILURE - @c acl is not minimal
336 * - @c ACL_ERROR - Unexpected library error
338 int acl_is_minimal(acl_t acl
) {
340 int ec
= acl_entry_count(acl
);
342 if (ec
== ACL_ERROR
) {
343 perror("acl_is_minimal (acl_entry_count)");
358 * @brief Determine whether the given ACL's mask denies execute.
361 * The ACL whose mask we want to check.
364 * - @c ACL_SUCCESS - The @c acl has a mask which denies execute.
365 * - @c ACL_FAILURE - The @c acl has a mask which does not deny execute.
366 * - @c ACL_ERROR - Unexpected library error.
368 int acl_execute_masked(acl_t acl
) {
371 int ge_result
= acl_get_entry(acl
, ACL_FIRST_ENTRY
, &entry
);
373 while (ge_result
== ACL_SUCCESS
) {
374 acl_tag_t tag
= ACL_UNDEFINED_TAG
;
376 if (acl_get_tag_type(entry
, &tag
) == ACL_ERROR
) {
377 perror("acl_execute_masked (acl_get_tag_type)");
381 if (tag
== ACL_MASK
) {
382 /* This is the mask entry, get its permissions, and see if
383 execute is specified. */
384 acl_permset_t permset
;
386 if (acl_get_permset(entry
, &permset
) == ACL_ERROR
) {
387 perror("acl_execute_masked (acl_get_permset)");
391 int gp_result
= acl_get_perm(permset
, ACL_EXECUTE
);
392 if (gp_result
== ACL_ERROR
) {
393 perror("acl_execute_masked (acl_get_perm)");
397 if (gp_result
== ACL_FAILURE
) {
398 /* No execute bit set in the mask; execute not allowed. */
403 ge_result
= acl_get_entry(acl
, ACL_NEXT_ENTRY
, &entry
);
412 * @brief Determine whether @c fd is executable by anyone.
415 * This is used as part of the heuristic to determine whether or not
416 * we should mask the execute bit when inheriting an ACL. If @c fd
417 * describes a file, we check the @a effective permissions, contrary
418 * to what setfacl does.
421 * The file descriptor to check.
424 * A pointer to a stat structure for @c fd.
427 * - @c ACL_SUCCESS - Someone has effective execute permissions on @c fd.
428 * - @c ACL_FAILURE - Nobody can execute @c fd.
429 * - @c ACL_ERROR - Unexpected library error.
431 int any_can_execute(int fd
, const struct stat
* sp
) {
432 acl_t acl
= acl_get_fd(fd
);
434 if (acl
== (acl_t
)NULL
) {
435 perror("any_can_execute (acl_get_file)");
439 /* Our return value. */
440 int result
= ACL_FAILURE
;
442 if (acl_is_minimal(acl
)) {
443 if (sp
->st_mode
& (S_IXUSR
| S_IXOTH
| S_IXGRP
)) {
444 result
= ACL_SUCCESS
;
448 result
= ACL_FAILURE
;
454 int ge_result
= acl_get_entry(acl
, ACL_FIRST_ENTRY
, &entry
);
456 while (ge_result
== ACL_SUCCESS
) {
457 /* The first thing we do is check to see if this is a mask
458 entry. If it is, we skip it entirely. */
459 acl_tag_t tag
= ACL_UNDEFINED_TAG
;
461 if (acl_get_tag_type(entry
, &tag
) == ACL_ERROR
) {
462 perror("any_can_execute_or (acl_get_tag_type)");
467 if (tag
== ACL_MASK
) {
468 ge_result
= acl_get_entry(acl
, ACL_NEXT_ENTRY
, &entry
);
472 /* Ok, so it's not a mask entry. Check the execute perms. */
473 acl_permset_t permset
;
475 if (acl_get_permset(entry
, &permset
) == ACL_ERROR
) {
476 perror("any_can_execute_or (acl_get_permset)");
481 int gp_result
= acl_get_perm(permset
, ACL_EXECUTE
);
482 if (gp_result
== ACL_ERROR
) {
483 perror("any_can_execute (acl_get_perm)");
488 if (gp_result
== ACL_SUCCESS
) {
489 /* Only return ACL_SUCCESS if this execute bit is not masked. */
490 if (acl_execute_masked(acl
) != ACL_SUCCESS
) {
491 result
= ACL_SUCCESS
;
496 ge_result
= acl_get_entry(acl
, ACL_NEXT_ENTRY
, &entry
);
499 if (ge_result
== ACL_ERROR
) {
500 perror("any_can_execute (acl_get_entry)");
513 * @brief Set @c acl as the default ACL on @c path.
515 * This overwrites any existing default ACL on @c path. If @c path is
516 * not a directory, we return ACL_ERROR and @c errno is set.
519 * The target directory whose ACL we wish to replace or create.
522 * The ACL to set as default on @c path.
525 * - @c ACL_SUCCESS - The default ACL was assigned successfully.
526 * - @c ACL_ERROR - Unexpected library error.
528 int assign_default_acl(const char* path
, acl_t acl
) {
532 perror("assign_default_acl (args)");
536 /* Our return value; success unless something bad happens. */
537 int result
= ACL_SUCCESS
;
538 acl_t path_acl
= acl_dup(acl
);
540 if (path_acl
== (acl_t
)NULL
) {
541 perror("assign_default_acl (acl_dup)");
542 return ACL_ERROR
; /* Nothing to clean up in this case. */
545 if (acl_set_file(path
, ACL_TYPE_DEFAULT
, path_acl
) == ACL_ERROR
) {
546 perror("assign_default_acl (acl_set_file)");
557 * @brief Remove all @c ACL_TYPE_ACCESS entries from the given file
558 * descriptor, leaving the UNIX permission bits.
561 * The file descriptor whose ACLs we want to wipe.
564 * - @c ACL_SUCCESS - The ACLs were wiped successfully, or none
565 * existed in the first place.
566 * - @c ACL_ERROR - Unexpected library error.
568 int wipe_acls(int fd
) {
569 /* Initialize an empty ACL, and then overwrite the one on "fd" with it. */
570 acl_t empty_acl
= acl_init(0);
572 if (empty_acl
== (acl_t
)NULL
) {
573 perror("wipe_acls (acl_init)");
577 if (acl_set_fd(fd
, empty_acl
) == ACL_ERROR
) {
578 perror("wipe_acls (acl_set_fd)");
590 * @brief Apply parent default ACL to a path.
592 * This overwrites any existing ACLs on @c path.
595 * The path whose ACL we would like to reset to its default.
598 * A pointer to a stat structure for @c path, or @c NULL if you don't
601 * @param no_exec_mask
602 * The value (either true or false) of the --no-exec-mask flag.
605 * - @c ACL_SUCCESS - The parent default ACL was inherited successfully.
606 * - @c ACL_FAILURE - The target path is not a regular file/directory,
607 * or the parent of @c path is not a directory.
608 * - @c ACL_ERROR - Unexpected library error.
610 int apply_default_acl(const char* path
,
611 const struct stat
* sp
,
616 perror("apply_default_acl (args)");
620 /* Define these next three variables here because we may have to
621 * jump to the cleanup routine which expects them to exist.
624 /* Our return value. */
625 int result
= ACL_SUCCESS
;
627 /* The default ACL on path's parent directory */
628 acl_t defacl
= (acl_t
)NULL
;
630 /* The file descriptor corresponding to "path" */
633 /* Get the parent directory of "path" with dirname(), which happens
634 * to murder its argument and necessitates a path_copy.
636 char* path_copy
= strdup(path
);
637 if (path_copy
== NULL
) {
638 perror("apply_default_acl (strdup)");
641 char* parent
= dirname(path_copy
);
643 fd
= safe_open(path
, O_NOFOLLOW
);
645 if (errno
== ELOOP
) {
646 result
= ACL_FAILURE
; /* hit a symlink */
650 perror("apply_default_acl (open fd)");
657 /* Refuse to operate on hard links, which can be abused by an
658 * attacker to trick us into changing the ACL on a file we didn't
659 * intend to; namely the "target" of the hard link. There is TOCTOU
660 * race condition here, but the window is as small as possible
661 * between when we open the file descriptor (look above) and when we
664 * Note: we only need to call fstat ourselves if we weren't passed a
665 * valid pointer to a stat structure (nftw does that).
669 if (fstat(fd
, &s
) == -1) {
670 perror("apply_default_acl (fstat)");
677 if (!S_ISDIR(sp
->st_mode
)) {
678 /* If it's not a directory, make sure it's a regular,
679 non-hard-linked file. */
680 if (!S_ISREG(sp
->st_mode
) || sp
->st_nlink
!= 1) {
681 result
= ACL_FAILURE
;
687 /* Default to not masking the exec bit; i.e. applying the default
688 ACL literally. If --no-exec-mask was not specified, then we try
689 to "guess" whether or not to mask the exec bit. This behavior
690 is modeled after the capital 'X' perms of setfacl. */
691 bool allow_exec
= true;
694 /* Never mask the execute bit on directories. */
695 int ace_result
= any_can_execute(fd
,sp
) || S_ISDIR(sp
->st_mode
);
697 if (ace_result
== ACL_ERROR
) {
698 perror("apply_default_acl (any_can_execute)");
703 allow_exec
= (bool)ace_result
;
706 defacl
= acl_get_file(parent
, ACL_TYPE_DEFAULT
);
708 if (defacl
== (acl_t
)NULL
) {
709 perror("apply_default_acl (acl_get_file)");
714 if (wipe_acls(fd
) == ACL_ERROR
) {
715 perror("apply_default_acl (wipe_acls)");
720 /* Do this after wipe_acls(), otherwise we'll overwrite the wiped
721 ACL with this one. */
722 acl_t acl
= acl_get_fd(fd
);
723 if (acl
== (acl_t
)NULL
) {
724 perror("apply_default_acl (acl_get_fd)");
729 /* If it's a directory, inherit the parent's default. We sure hope
730 * that "path" still points to the same thing that "fd" and this
731 * "sp" describe. If not, we may wind up trying to set a default ACL
732 * on a file, and this will throw an error. I guess that's what we
735 if (S_ISDIR(sp
->st_mode
) && assign_default_acl(path
, defacl
) == ACL_ERROR
) {
736 perror("apply_default_acl (assign_default_acl)");
742 int ge_result
= acl_get_entry(defacl
, ACL_FIRST_ENTRY
, &entry
);
744 while (ge_result
== ACL_SUCCESS
) {
745 acl_tag_t tag
= ACL_UNDEFINED_TAG
;
747 if (acl_get_tag_type(entry
, &tag
) == ACL_ERROR
) {
748 perror("apply_default_acl (acl_get_tag_type)");
754 /* We've got an entry/tag from the default ACL. Get its permset. */
755 acl_permset_t permset
;
756 if (acl_get_permset(entry
, &permset
) == ACL_ERROR
) {
757 perror("apply_default_acl (acl_get_permset)");
762 /* If this is a default mask, fix it up. */
763 if (tag
== ACL_MASK
||
764 tag
== ACL_USER_OBJ
||
765 tag
== ACL_GROUP_OBJ
||
769 /* The mask doesn't affect acl_user_obj, acl_group_obj (in
770 minimal ACLs) or acl_other entries, so if execute should be
771 masked, we have to do it manually. */
772 if (acl_delete_perm(permset
, ACL_EXECUTE
) == ACL_ERROR
) {
773 perror("apply_default_acl (acl_delete_perm)");
778 if (acl_set_permset(entry
, permset
) == ACL_ERROR
) {
779 perror("apply_default_acl (acl_set_permset)");
786 /* Finally, add the permset to the access ACL. It's actually
787 * important that we pass in the address of "acl" here, and not
788 * "acl" itself. Why? The call to acl_create_entry() within
789 * acl_set_entry() can allocate new memory for the entry.
790 * Sometimes that can be done in-place, in which case everything
791 * is cool and the new memory gets released when we call
794 * But occasionally, the whole ACL structure will have to be moved
795 * in order to allocate the extra space. When that happens,
796 * acl_create_entry() modifies the pointer it was passed (in this
797 * case, &acl) to point to the new location. We want to call
798 * acl_free() on the new location, and since acl_free() gets
799 * called right here, we need acl_create_entry() to update the
800 * value of "acl". To do that, it needs the address of "acl".
802 if (acl_set_entry(&acl
, entry
) == ACL_ERROR
) {
803 perror("apply_default_acl (acl_set_entry)");
808 ge_result
= acl_get_entry(defacl
, ACL_NEXT_ENTRY
, &entry
);
811 /* Catches the first acl_get_entry as well as the ones at the end of
813 if (ge_result
== ACL_ERROR
) {
814 perror("apply_default_acl (acl_get_entry)");
819 if (acl_set_fd(fd
, acl
) == ACL_ERROR
) {
820 perror("apply_default_acl (acl_set_fd)");
827 if (defacl
!= (acl_t
)NULL
) {
830 if (fd
>= 0 && close(fd
) == -1) {
831 perror("apply_default_acl (close)");
840 * @brief Display program usage information.
842 * @param program_name
843 * The program name to use in the output.
846 void usage(const char* program_name
) {
847 printf("Apply any applicable default ACLs to the given files or "
849 printf("Usage: %s [flags] <target1> [<target2> [ <target3>...]]\n\n",
852 printf(" -h, --help Print this help message\n");
853 printf(" -r, --recursive Act on any given directories recursively\n");
854 printf(" -x, --no-exec-mask Apply execute permissions unconditionally\n");
861 * @brief Wrapper around @c apply_default_acl() for use with @c nftw().
863 * For parameter information, see the @c nftw man page.
865 * @return If the ACL was applied to @c target successfully, we return
866 * @c FTW_CONTINUE to signal to @ nftw() that we should proceed onto
867 * the next file or directory. Otherwise, we return @c FTW_STOP to
871 int apply_default_acl_nftw(const char *target
,
872 const struct stat
*sp
,
876 if (apply_default_acl(target
, sp
, false)) {
887 * @brief Wrapper around @c apply_default_acl() for use with @c nftw().
889 * This is identical to @c apply_default_acl_nftw(), except it passes
890 * @c true to @c apply_default_acl() as its no_exec_mask argument.
893 int apply_default_acl_nftw_x(const char *target
,
894 const struct stat
*sp
,
898 if (apply_default_acl(target
, sp
, true)) {
909 * @brief Recursive version of @c apply_default_acl().
911 * If @c target is a directory, we use @c nftw() to call @c
912 * apply_default_acl() recursively on all of its children. Otherwise,
913 * we just delegate to @c apply_default_acl().
915 * We ignore symlinks for consistency with chmod -r.
918 * The root (path) of the recursive application.
920 * @param no_exec_mask
921 * The value (either true or false) of the --no-exec-mask flag.
924 * If @c target is not a directory, we return the result of
925 * calling @c apply_default_acl() on @c target. Otherwise, we convert
926 * the return value of @c nftw(). If @c nftw() succeeds (returns 0),
927 * then we return @c true. Otherwise, we return @c false.
929 * If there is an error, it will be reported via @c perror, but
930 * we still return @c false.
932 bool apply_default_acl_recursive(const char *target
, bool no_exec_mask
) {
933 int max_levels
= 256;
934 int flags
= FTW_PHYS
; /* Don't follow links. */
936 /* There are two separate functions that could be passed to
937 nftw(). One passes no_exec_mask = true to apply_default_acl(),
938 and the other passes no_exec_mask = false. Since the function we
939 pass to nftw() cannot have parameters, we have to create separate
940 options and make the decision here. */
941 int (*fn
)(const char *, const struct stat
*, int, struct FTW
*) = NULL
;
942 fn
= no_exec_mask
? apply_default_acl_nftw_x
: apply_default_acl_nftw
;
944 int nftw_result
= nftw(target
, fn
, max_levels
, flags
);
946 if (nftw_result
== 0) {
951 /* nftw will return -1 on error, or if the supplied function
952 * (apply_default_acl_nftw) returns a non-zero result, nftw will
955 if (nftw_result
== -1) {
956 perror("apply_default_acl_recursive (nftw)");
965 * @brief Call apply_default_acl (possibly recursively) on each
966 * command-line argument.
968 * @return Either @c EXIT_FAILURE or @c EXIT_SUCCESS. If everything
969 * goes as expected, we return @c EXIT_SUCCESS. Otherwise, we return
972 int main(int argc
, char* argv
[]) {
979 bool recursive
= false;
980 bool no_exec_mask
= false;
982 struct option long_options
[] = {
983 /* These options set a flag. */
984 {"help", no_argument
, NULL
, 'h'},
985 {"recursive", no_argument
, NULL
, 'r'},
986 {"no-exec-mask", no_argument
, NULL
, 'x'},
992 while ((opt
= getopt_long(argc
, argv
, "hrx", long_options
, NULL
)) != -1) {
1001 no_exec_mask
= true;
1005 return EXIT_FAILURE
;
1009 int result
= EXIT_SUCCESS
;
1012 for (arg_index
= optind
; arg_index
< argc
; arg_index
++) {
1013 const char* target
= argv
[arg_index
];
1014 bool reapp_result
= false;
1016 /* Make sure we can access the given path before we go out of our
1017 * way to please it. Doing this check outside of
1018 * apply_default_acl() lets us spit out a better error message for
1021 if (!path_accessible(target
)) {
1022 fprintf(stderr
, "%s: %s: No such file or directory\n", argv
[0], target
);
1023 result
= EXIT_FAILURE
;
1028 reapp_result
= apply_default_acl_recursive(target
, no_exec_mask
);
1031 /* It's either a normal file, or we're not operating recursively. */
1032 reapp_result
= apply_default_acl(target
, NULL
, no_exec_mask
);
1035 if (!reapp_result
) {
1036 result
= EXIT_FAILURE
;