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> /* 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,
39 * @brief Get the mode bits from the given path.
42 * The path (file or directory) whose mode we want.
44 * @return A mode_t (st_mode) structure containing the mode bits.
45 * See sys/stat.h for details.
47 mode_t
get_mode(const char* path
) {
54 int result
= lstat(path
, &s
);
60 /* errno will be set already by lstat() */
68 * @brief Determine if the given path might refer to an (unsafe) hard link.
73 * @return true if we are certain that @c path does not refer to a hard
74 * link, and false otherwise. In case of error, false is returned,
75 * because we are not sure that @c path is not a hard link.
77 bool is_hardlink_safe(const char* path
) {
82 int result
= lstat(path
, &s
);
84 return (s
.st_nlink
== 1 || S_ISDIR(s
.st_mode
));
93 * @brief Determine whether or not the given path is a regular file.
98 * @return true if @c path is a regular file, false otherwise.
100 bool is_regular_file(const char* path
) {
106 int result
= lstat(path
, &s
);
108 return S_ISREG(s
.st_mode
);
118 * @brief Determine whether or not the given path is accessible.
123 * @return true if @c path is accessible to the current effective
124 * user/group, false otherwise.
126 bool path_accessible(const char* path
) {
131 /* Test for access using the effective user and group rather than
133 int flags
= AT_EACCESS
;
135 /* Don't follow symlinks when checking for a path's existence,
136 since we won't follow them to set its ACLs either. */
137 flags
|= AT_SYMLINK_NOFOLLOW
;
139 /* If the path is relative, interpret it relative to the current
140 working directory (just like the access() system call). */
141 int result
= faccessat(AT_FDCWD
, path
, F_OK
, flags
);
154 * @brief Determine whether or not the given path is a directory.
159 * @return true if @c path is a directory, false otherwise.
161 bool is_path_directory(const char* path
) {
167 int result
= lstat(path
, &s
);
169 return S_ISDIR(s
.st_mode
);
179 * @brief Update (or create) an entry in an @b minimal ACL.
181 * This function will not work if @c aclp contains extended
182 * entries. This is fine for our purposes, since we call @c wipe_acls
183 * on each path before applying the default to it.
185 * The assumption that there are no extended entries makes things much
186 * simpler. For example, we only have to update the @c ACL_USER_OBJ,
187 * @c ACL_GROUP_OBJ, and @c ACL_OTHER entries -- all others can simply
188 * be created anew. This means we don't have to fool around comparing
189 * named-user/group entries.
192 * A pointer to the acl_t structure whose entry we want to modify.
195 * The new entry. If @c entry contains a user/group/other entry, we
196 * update the existing one. Otherwise we create a new entry.
198 * @return If there is an unexpected library error, @c ACL_ERROR is
199 * returned. Otherwise, @c ACL_SUCCESS.
202 int acl_set_entry(acl_t
* aclp
,
206 int gt_result
= acl_get_tag_type(entry
, &entry_tag
);
207 if (gt_result
== ACL_ERROR
) {
208 perror("acl_set_entry (acl_get_tag_type)");
212 acl_permset_t entry_permset
;
213 int ps_result
= acl_get_permset(entry
, &entry_permset
);
214 if (ps_result
== ACL_ERROR
) {
215 perror("acl_set_entry (acl_get_permset)");
219 acl_entry_t existing_entry
;
220 /* Loop through the given ACL looking for matching entries. */
221 int result
= acl_get_entry(*aclp
, ACL_FIRST_ENTRY
, &existing_entry
);
223 while (result
== ACL_SUCCESS
) {
224 acl_tag_t existing_tag
= ACL_UNDEFINED_TAG
;
225 int tag_result
= acl_get_tag_type(existing_entry
, &existing_tag
);
227 if (tag_result
== ACL_ERROR
) {
228 perror("set_acl_tag_permset (acl_get_tag_type)");
232 if (existing_tag
== entry_tag
) {
233 if (entry_tag
== ACL_USER_OBJ
||
234 entry_tag
== ACL_GROUP_OBJ
||
235 entry_tag
== ACL_OTHER
) {
236 /* Only update for these three since all other tags will have
237 been wiped. These three are guaranteed to exist, so if we
238 match one of them, we're allowed to return ACL_SUCCESS
239 below and bypass the rest of the function. */
240 acl_permset_t existing_permset
;
241 int gep_result
= acl_get_permset(existing_entry
, &existing_permset
);
242 if (gep_result
== ACL_ERROR
) {
243 perror("acl_set_entry (acl_get_permset)");
247 int s_result
= acl_set_permset(existing_entry
, entry_permset
);
248 if (s_result
== ACL_ERROR
) {
249 perror("acl_set_entry (acl_set_permset)");
258 result
= acl_get_entry(*aclp
, ACL_NEXT_ENTRY
, &existing_entry
);
261 /* This catches both the initial acl_get_entry and the ones at the
263 if (result
== ACL_ERROR
) {
264 perror("acl_set_entry (acl_get_entry)");
268 /* If we've made it this far, we need to add a new entry to the
270 acl_entry_t new_entry
;
272 /* The acl_create_entry() function can allocate new memory and/or
273 * change the location of the ACL structure entirely. When that
274 * happens, the value pointed to by aclp is updated, which means
275 * that a new acl_t gets "passed out" to our caller, eventually to
276 * be fed to acl_free(). In other words, we should still be freeing
277 * the right thing, even if the value pointed to by aclp changes.
279 int c_result
= acl_create_entry(aclp
, &new_entry
);
280 if (c_result
== ACL_ERROR
) {
281 perror("acl_set_entry (acl_create_entry)");
285 int st_result
= acl_set_tag_type(new_entry
, entry_tag
);
286 if (st_result
== ACL_ERROR
) {
287 perror("acl_set_entry (acl_set_tag_type)");
291 int s_result
= acl_set_permset(new_entry
, entry_permset
);
292 if (s_result
== ACL_ERROR
) {
293 perror("acl_set_entry (acl_set_permset)");
297 if (entry_tag
== ACL_USER
|| entry_tag
== ACL_GROUP
) {
298 /* We need to set the qualifier too. */
299 void* entry_qual
= acl_get_qualifier(entry
);
300 if (entry_qual
== (void*)NULL
) {
301 perror("acl_set_entry (acl_get_qualifier)");
305 int sq_result
= acl_set_qualifier(new_entry
, entry_qual
);
306 if (sq_result
== ACL_ERROR
) {
307 perror("acl_set_entry (acl_set_qualifier)");
318 * @brief Determine the number of entries in the given ACL.
321 * The ACL to inspect.
323 * @return Either the non-negative number of entries in @c acl, or
324 * @c ACL_ERROR on error.
326 int acl_entry_count(acl_t acl
) {
330 int result
= acl_get_entry(acl
, ACL_FIRST_ENTRY
, &entry
);
332 while (result
== ACL_SUCCESS
) {
334 result
= acl_get_entry(acl
, ACL_NEXT_ENTRY
, &entry
);
337 if (result
== ACL_ERROR
) {
338 perror("acl_entry_count (acl_get_entry)");
348 * @brief Determine whether or not the given ACL is minimal.
350 * An ACL is minimal if it has fewer than four entries.
353 * The ACL whose minimality is in question.
356 * - @c ACL_SUCCESS - @c acl is minimal
357 * - @c ACL_FAILURE - @c acl is not minimal
358 * - @c ACL_ERROR - Unexpected library error
360 int acl_is_minimal(acl_t acl
) {
362 int ec
= acl_entry_count(acl
);
364 if (ec
== ACL_ERROR
) {
365 perror("acl_is_minimal (acl_entry_count)");
380 * @brief Determine whether the given ACL's mask denies execute.
383 * The ACL whose mask we want to check.
386 * - @c ACL_SUCCESS - The @c acl has a mask which denies execute.
387 * - @c ACL_FAILURE - The @c acl has a mask which does not deny execute.
388 * - @c ACL_ERROR - Unexpected library error.
390 int acl_execute_masked(acl_t acl
) {
393 int ge_result
= acl_get_entry(acl
, ACL_FIRST_ENTRY
, &entry
);
395 while (ge_result
== ACL_SUCCESS
) {
396 acl_tag_t tag
= ACL_UNDEFINED_TAG
;
397 int tag_result
= acl_get_tag_type(entry
, &tag
);
399 if (tag_result
== ACL_ERROR
) {
400 perror("acl_execute_masked (acl_get_tag_type)");
404 if (tag
== ACL_MASK
) {
405 /* This is the mask entry, get its permissions, and see if
406 execute is specified. */
407 acl_permset_t permset
;
409 int ps_result
= acl_get_permset(entry
, &permset
);
410 if (ps_result
== ACL_ERROR
) {
411 perror("acl_execute_masked (acl_get_permset)");
415 int gp_result
= acl_get_perm(permset
, ACL_EXECUTE
);
416 if (gp_result
== ACL_ERROR
) {
417 perror("acl_execute_masked (acl_get_perm)");
421 if (gp_result
== ACL_FAILURE
) {
422 /* No execute bit set in the mask; execute not allowed. */
427 ge_result
= acl_get_entry(acl
, ACL_NEXT_ENTRY
, &entry
);
436 * @brief Determine whether @c path is executable (by anyone) or a
439 * This is used as part of the heuristic to determine whether or not
440 * we should mask the execute bit when inheriting an ACL. If @c path
441 * is a directory, the answer is a clear-cut yes. This behavior is
442 * modeled after the capital 'X' perms of setfacl.
444 * If @c path is a file, we check the @a effective permissions,
445 * contrary to what setfacl does.
451 * - @c ACL_SUCCESS - @c path is a directory, or someone has effective
453 * - @c ACL_FAILURE - @c path is a regular file and nobody can execute
455 * - @c ACL_ERROR - Unexpected library error.
457 int any_can_execute_or_dir(const char* path
) {
459 if (is_path_directory(path
)) {
460 /* That was easy... */
464 acl_t acl
= acl_get_file(path
, ACL_TYPE_ACCESS
);
466 if (acl
== (acl_t
)NULL
) {
467 perror("any_can_execute_or_dir (acl_get_file)");
471 /* Our return value. */
472 int result
= ACL_FAILURE
;
474 if (acl_is_minimal(acl
)) {
475 mode_t mode
= get_mode(path
);
476 if (mode
& (S_IXUSR
| S_IXOTH
| S_IXGRP
)) {
477 result
= ACL_SUCCESS
;
481 result
= ACL_FAILURE
;
487 int ge_result
= acl_get_entry(acl
, ACL_FIRST_ENTRY
, &entry
);
489 while (ge_result
== ACL_SUCCESS
) {
490 /* The first thing we do is check to see if this is a mask
491 entry. If it is, we skip it entirely. */
492 acl_tag_t tag
= ACL_UNDEFINED_TAG
;
493 int tag_result
= acl_get_tag_type(entry
, &tag
);
495 if (tag_result
== ACL_ERROR
) {
496 perror("any_can_execute_or_dir (acl_get_tag_type)");
501 if (tag
== ACL_MASK
) {
502 ge_result
= acl_get_entry(acl
, ACL_NEXT_ENTRY
, &entry
);
506 /* Ok, so it's not a mask entry. Check the execute perms. */
507 acl_permset_t permset
;
509 int ps_result
= acl_get_permset(entry
, &permset
);
510 if (ps_result
== ACL_ERROR
) {
511 perror("any_can_execute_or_dir (acl_get_permset)");
516 int gp_result
= acl_get_perm(permset
, ACL_EXECUTE
);
517 if (gp_result
== ACL_ERROR
) {
518 perror("any_can_execute_or_dir (acl_get_perm)");
523 if (gp_result
== ACL_SUCCESS
) {
524 /* Only return ACL_SUCCESS if this execute bit is not masked. */
525 if (acl_execute_masked(acl
) != ACL_SUCCESS
) {
526 result
= ACL_SUCCESS
;
531 ge_result
= acl_get_entry(acl
, ACL_NEXT_ENTRY
, &entry
);
534 if (ge_result
== ACL_ERROR
) {
535 perror("any_can_execute_or_dir (acl_get_entry)");
548 * @brief Set @c acl as the default ACL on @c path if it's a directory.
550 * This overwrites any existing default ACL on @c path. If no default
551 * ACL exists, then one is created. If @c path is not a directory, we
552 * return ACL_FAILURE but no error is raised.
555 * The target directory whose ACL we wish to replace or create.
558 * The ACL to set as default on @c path.
561 * - @c ACL_SUCCESS - The default ACL was assigned successfully.
562 * - @c ACL_FAILURE - If @c path is not a directory.
563 * - @c ACL_ERROR - Unexpected library error.
565 int assign_default_acl(const char* path
, acl_t acl
) {
572 if (!is_path_directory(path
)) {
576 /* Our return value; success unless something bad happens. */
577 int result
= ACL_SUCCESS
;
578 acl_t path_acl
= acl_dup(acl
);
580 if (path_acl
== (acl_t
)NULL
) {
581 perror("inherit_default_acl (acl_dup)");
582 return ACL_ERROR
; /* Nothing to clean up in this case. */
585 int sf_result
= acl_set_file(path
, ACL_TYPE_DEFAULT
, path_acl
);
586 if (sf_result
== -1) {
587 perror("inherit_default_acl (acl_set_file)");
598 * @brief Remove @c ACL_USER, @c ACL_GROUP, and @c ACL_MASK entries
599 * from the given path.
602 * The path whose ACLs we want to wipe.
605 * - @c ACL_SUCCESS - The ACLs were wiped successfully, or none
606 * existed in the first place.
607 * - @c ACL_ERROR - Unexpected library error.
609 int wipe_acls(const char* path
) {
616 acl_t acl
= acl_get_file(path
, ACL_TYPE_ACCESS
);
617 if (acl
== (acl_t
)NULL
) {
618 perror("wipe_acls (acl_get_file)");
622 /* Our return value. */
623 int result
= ACL_SUCCESS
;
626 int ge_result
= acl_get_entry(acl
, ACL_FIRST_ENTRY
, &entry
);
628 while (ge_result
== ACL_SUCCESS
) {
629 int d_result
= acl_delete_entry(acl
, entry
);
630 if (d_result
== ACL_ERROR
) {
631 perror("wipe_acls (acl_delete_entry)");
636 ge_result
= acl_get_entry(acl
, ACL_NEXT_ENTRY
, &entry
);
639 /* Catches the first acl_get_entry as well as the ones at the end of
641 if (ge_result
== ACL_ERROR
) {
642 perror("wipe_acls (acl_get_entry)");
647 int sf_result
= acl_set_file(path
, ACL_TYPE_ACCESS
, acl
);
648 if (sf_result
== ACL_ERROR
) {
649 perror("wipe_acls (acl_set_file)");
662 * @brief Apply parent default ACL to a path.
664 * This overwrites any existing ACLs on @c path.
667 * The path whose ACL we would like to reset to its default.
669 * @param no_exec_mask
670 * The value (either true or false) of the --no-exec-mask flag.
673 * - @c ACL_SUCCESS - The parent default ACL was inherited successfully.
674 * - @c ACL_FAILURE - The target path is not a regular file/directory,
675 * or the parent of @c path is not a directory.
676 * - @c ACL_ERROR - Unexpected library error.
678 int apply_default_acl(const char* path
, bool no_exec_mask
) {
685 /* Refuse to operate on hard links, which can be abused by an
686 * attacker to trick us into changing the ACL on a file we didn't
687 * intend to; namely the "target" of the hard link. To truly prevent
688 * that sort of mischief, we should be using file descriptors for
689 * the target and its parent directory. Then modulo a tiny race
690 * condition, we would be sure that "path" and "parent" don't change
691 * their nature between the time that we test them and when we
692 * utilize them. For contrast, the same attacker is free to replace
693 * "path" with a hard link after is_hardlink_safe() has returned
696 * Unfortunately, our API is lacking in this area. For example,
697 * acl_set_fd() is only capable of setting the ACL_TYPE_ACCESS list,
698 * and not the ACL_TYPE_DEFAULT. Apparently the only way to operate
699 * on default ACLs is through the path name, which is inherently
700 * unreliable since the acl_*_file() calls themselves might follow
701 * links (both hard and symbolic).
703 * Some improvement could still be made by using descriptors where
704 * possible -- this would shrink the exploit window -- but for now
705 * we use a naive implementation that only keeps honest men honest.
707 if (!is_hardlink_safe(path
)) {
711 if (!is_regular_file(path
) && !is_path_directory(path
)) {
715 /* dirname mangles its argument */
716 char path_copy
[PATH_MAX
];
717 strncpy(path_copy
, path
, PATH_MAX
-1);
718 path_copy
[PATH_MAX
-1] = 0;
720 char* parent
= dirname(path_copy
);
721 if (!is_path_directory(parent
)) {
722 /* Make sure dirname() did what we think it did. */
726 /* Default to not masking the exec bit; i.e. applying the default
727 ACL literally. If --no-exec-mask was not specified, then we try
728 to "guess" whether or not to mask the exec bit. */
729 bool allow_exec
= true;
732 int ace_result
= any_can_execute_or_dir(path
);
734 if (ace_result
== ACL_ERROR
) {
735 perror("apply_default_acl (any_can_execute_or_dir)");
739 allow_exec
= (bool)ace_result
;
742 acl_t defacl
= acl_get_file(parent
, ACL_TYPE_DEFAULT
);
744 if (defacl
== (acl_t
)NULL
) {
745 perror("apply_default_acl (acl_get_file)");
749 /* Our return value. */
750 int result
= ACL_SUCCESS
;
752 int wipe_result
= wipe_acls(path
);
753 if (wipe_result
== ACL_ERROR
) {
754 perror("apply_default_acl (wipe_acls)");
759 /* Do this after wipe_acls(), otherwise we'll overwrite the wiped
760 ACL with this one. */
761 acl_t acl
= acl_get_file(path
, ACL_TYPE_ACCESS
);
762 if (acl
== (acl_t
)NULL
) {
763 perror("apply_default_acl (acl_get_file)");
768 /* If it's a directory, inherit the parent's default. */
769 int inherit_result
= assign_default_acl(path
, defacl
);
770 if (inherit_result
== ACL_ERROR
) {
771 perror("apply_default_acl (inherit_acls)");
777 int ge_result
= acl_get_entry(defacl
, ACL_FIRST_ENTRY
, &entry
);
779 while (ge_result
== ACL_SUCCESS
) {
780 acl_tag_t tag
= ACL_UNDEFINED_TAG
;
781 int tag_result
= acl_get_tag_type(entry
, &tag
);
783 if (tag_result
== ACL_ERROR
) {
784 perror("apply_default_acl (acl_get_tag_type)");
790 /* We've got an entry/tag from the default ACL. Get its permset. */
791 acl_permset_t permset
;
792 int ps_result
= acl_get_permset(entry
, &permset
);
793 if (ps_result
== ACL_ERROR
) {
794 perror("apply_default_acl (acl_get_permset)");
799 /* If this is a default mask, fix it up. */
800 if (tag
== ACL_MASK
||
801 tag
== ACL_USER_OBJ
||
802 tag
== ACL_GROUP_OBJ
||
806 /* The mask doesn't affect acl_user_obj, acl_group_obj (in
807 minimal ACLs) or acl_other entries, so if execute should be
808 masked, we have to do it manually. */
809 int d_result
= acl_delete_perm(permset
, ACL_EXECUTE
);
810 if (d_result
== ACL_ERROR
) {
811 perror("apply_default_acl (acl_delete_perm)");
816 int sp_result
= acl_set_permset(entry
, permset
);
817 if (sp_result
== ACL_ERROR
) {
818 perror("apply_default_acl (acl_set_permset)");
825 /* Finally, add the permset to the access ACL. It's actually
826 * important that we pass in the address of "acl" here, and not
827 * "acl" itself. Why? The call to acl_create_entry() within
828 * acl_set_entry() can allocate new memory for the entry.
829 * Sometimes that can be done in-place, in which case everything
830 * is cool and the new memory gets released when we call
833 * But occasionally, the whole ACL structure will have to be moved
834 * in order to allocate the extra space. When that happens,
835 * acl_create_entry() modifies the pointer it was passed (in this
836 * case, &acl) to point to the new location. We want to call
837 * acl_free() on the new location, and since acl_free() gets
838 * called right here, we need acl_create_entry() to update the
839 * value of "acl". To do that, it needs the address of "acl".
841 int set_result
= acl_set_entry(&acl
, entry
);
842 if (set_result
== ACL_ERROR
) {
843 perror("apply_default_acl (acl_set_entry)");
848 ge_result
= acl_get_entry(defacl
, ACL_NEXT_ENTRY
, &entry
);
851 /* Catches the first acl_get_entry as well as the ones at the end of
853 if (ge_result
== ACL_ERROR
) {
854 perror("apply_default_acl (acl_get_entry)");
859 int sf_result
= acl_set_file(path
, ACL_TYPE_ACCESS
, acl
);
860 if (sf_result
== ACL_ERROR
) {
861 perror("apply_default_acl (acl_set_file)");
874 * @brief Display program usage information.
876 * @param program_name
877 * The program name to use in the output.
880 void usage(const char* program_name
) {
881 printf("Apply any applicable default ACLs to the given files or "
883 printf("Usage: %s [flags] <target1> [<target2> [ <target3>...]]\n\n",
886 printf(" -h, --help Print this help message\n");
887 printf(" -r, --recursive Act on any given directories recursively\n");
888 printf(" -x, --no-exec-mask Apply execute permissions unconditionally\n");
895 * @brief Wrapper around @c apply_default_acl() for use with @c nftw().
897 * For parameter information, see the @c nftw man page.
899 * @return If the ACL was applied to @c target successfully, we return
900 * @c FTW_CONTINUE to signal to @ nftw() that we should proceed onto
901 * the next file or directory. Otherwise, we return @c FTW_STOP to
905 int apply_default_acl_nftw(const char *target
,
906 const struct stat
*s
,
910 bool app_result
= apply_default_acl(target
, false);
922 * @brief Wrapper around @c apply_default_acl() for use with @c nftw().
924 * This is identical to @c apply_default_acl_nftw(), except it passes
925 * @c true to @c apply_default_acl() as its no_exec_mask argument.
928 int apply_default_acl_nftw_x(const char *target
,
929 const struct stat
*s
,
933 bool app_result
= apply_default_acl(target
, true);
945 * @brief Recursive version of @c apply_default_acl().
947 * If @c target is a directory, we use @c nftw() to call @c
948 * apply_default_acl() recursively on all of its children. Otherwise,
949 * we just delegate to @c apply_default_acl().
951 * We ignore symlinks for consistency with chmod -r.
954 * The root (path) of the recursive application.
956 * @param no_exec_mask
957 * The value (either true or false) of the --no-exec-mask flag.
960 * If @c target is not a directory, we return the result of
961 * calling @c apply_default_acl() on @c target. Otherwise, we convert
962 * the return value of @c nftw(). If @c nftw() succeeds (returns 0),
963 * then we return @c true. Otherwise, we return @c false.
965 * If there is an error, it will be reported via @c perror, but
966 * we still return @c false.
968 bool apply_default_acl_recursive(const char *target
, bool no_exec_mask
) {
970 if (!is_path_directory(target
)) {
971 return apply_default_acl(target
, no_exec_mask
);
974 int max_levels
= 256;
975 int flags
= FTW_PHYS
; /* Don't follow links. */
977 /* There are two separate functions that could be passed to
978 nftw(). One passes no_exec_mask = true to apply_default_acl(),
979 and the other passes no_exec_mask = false. Since the function we
980 pass to nftw() cannot have parameters, we have to create separate
981 options and make the decision here. */
982 int (*fn
)(const char *, const struct stat
*, int, struct FTW
*) = NULL
;
983 fn
= no_exec_mask
? apply_default_acl_nftw_x
: apply_default_acl_nftw
;
985 int nftw_result
= nftw(target
, fn
, max_levels
, flags
);
987 if (nftw_result
== 0) {
992 /* nftw will return -1 on error, or if the supplied function
993 * (apply_default_acl_nftw) returns a non-zero result, nftw will
996 if (nftw_result
== -1) {
997 perror("apply_default_acl_recursive (nftw)");
1006 * @brief Call apply_default_acl (possibly recursively) on each
1007 * command-line argument.
1009 * @return Either @c EXIT_FAILURE or @c EXIT_SUCCESS. If everything
1010 * goes as expected, we return @c EXIT_SUCCESS. Otherwise, we return
1013 int main(int argc
, char* argv
[]) {
1017 return EXIT_FAILURE
;
1020 bool recursive
= false;
1021 bool no_exec_mask
= false;
1023 struct option long_options
[] = {
1024 /* These options set a flag. */
1025 {"help", no_argument
, NULL
, 'h'},
1026 {"recursive", no_argument
, NULL
, 'r'},
1027 {"no-exec-mask", no_argument
, NULL
, 'x'},
1033 while ((opt
= getopt_long(argc
, argv
, "hrx", long_options
, NULL
)) != -1) {
1037 return EXIT_SUCCESS
;
1042 no_exec_mask
= true;
1046 return EXIT_FAILURE
;
1050 int result
= EXIT_SUCCESS
;
1053 for (arg_index
= optind
; arg_index
< argc
; arg_index
++) {
1054 const char* target
= argv
[arg_index
];
1055 bool reapp_result
= false;
1057 /* Make sure we can access the given path before we go out of our
1058 * way to please it. Doing this check outside of
1059 * apply_default_acl() lets us spit out a better error message for
1062 if (!path_accessible(target
)) {
1063 fprintf(stderr
, "%s: %s: No such file or directory\n", argv
[0], target
);
1064 result
= EXIT_FAILURE
;
1069 reapp_result
= apply_default_acl_recursive(target
, no_exec_mask
);
1072 /* It's either a normal file, or we're not operating recursively. */
1073 reapp_result
= apply_default_acl(target
, no_exec_mask
);
1076 if (!reapp_result
) {
1077 result
= EXIT_FAILURE
;