* @param path
* The path whose ACL we would like to reset to its default.
*
+ * @param sp
+ * A pointer to a stat structure for @c path, or @c NULL if you don't
+ * have one handy.
+ *
* @param no_exec_mask
* The value (either true or false) of the --no-exec-mask flag.
*
* or the parent of @c path is not a directory.
* - @c ACL_ERROR - Unexpected library error.
*/
-int apply_default_acl(const char* path, bool no_exec_mask) {
+int apply_default_acl(const char* path,
+ const struct stat* sp,
+ bool no_exec_mask) {
if (path == NULL) {
errno = EINVAL;
* race condition here, but the window is as small as possible
* between when we open the file descriptor (look above) and when we
* fstat it.
+ *
+ * Note: we only need to call fstat ourselves if we weren't passed a
+ * valid pointer to a stat structure (nftw does that).
*/
- struct stat s;
- if (fstat(fd, &s) == -1) {
- perror("apply_default_acl (fstat)");
- goto cleanup;
+ if (sp == NULL) {
+ struct stat s;
+ if (fstat(fd, &s) == -1) {
+ perror("apply_default_acl (fstat)");
+ goto cleanup;
+ }
+
+ sp = &s;
}
- if (!S_ISDIR(s.st_mode)) {
+
+ if (!S_ISDIR(sp->st_mode)) {
/* If it's not a directory, make sure it's a regular,
non-hard-linked file. */
- if (!S_ISREG(s.st_mode) || s.st_nlink != 1) {
+ if (!S_ISREG(sp->st_mode) || sp->st_nlink != 1) {
result = ACL_FAILURE;
goto cleanup;
}
if (!no_exec_mask) {
/* Never mask the execute bit on directories. */
- int ace_result = any_can_execute(fd) || S_ISDIR(s.st_mode);
+ int ace_result = any_can_execute(fd) || S_ISDIR(sp->st_mode);
if (ace_result == ACL_ERROR) {
perror("apply_default_acl (any_can_execute)");
*
*/
int apply_default_acl_nftw(const char *target,
- const struct stat *s,
+ const struct stat *sp,
int info,
struct FTW *ftw) {
- if (apply_default_acl(target, false)) {
+ if (apply_default_acl(target, sp, false)) {
return FTW_CONTINUE;
}
else {
*
*/
int apply_default_acl_nftw_x(const char *target,
- const struct stat *s,
+ const struct stat *sp,
int info,
struct FTW *ftw) {
- if (apply_default_acl(target, true)) {
+ if (apply_default_acl(target, sp, true)) {
return FTW_CONTINUE;
}
else {
bool apply_default_acl_recursive(const char *target, bool no_exec_mask) {
if (!is_path_directory(target)) {
- return apply_default_acl(target, no_exec_mask);
+ return apply_default_acl(target, NULL, no_exec_mask);
}
int max_levels = 256;
}
else {
/* It's either a normal file, or we're not operating recursively. */
- reapp_result = apply_default_acl(target, no_exec_mask);
+ reapp_result = apply_default_acl(target, NULL, no_exec_mask);
}
if (!reapp_result) {