]> gitweb.michael.orlitzky.com - apply-default-acl.git/blobdiff - src/libadacl.c
Bail out of apply_default_acl_ex() early if the parent has no default ACL.
[apply-default-acl.git] / src / libadacl.c
index d92432228358badf66a302e34e31ff459579b1de..0d07f2c6d0126880b59e830011fcbbefc75e797f 100644 (file)
@@ -681,6 +681,30 @@ int acl_copy_xattr(int src_fd,
 }
 
 
+/**
+ * @brief Determine if a file descriptor has a default ACL.
+ *
+ * @param fd
+ *   The file descriptor whose default ACL is in question.
+ *
+ * @return
+ *   - @c ACL_SUCCESS - If @c fd has a default ACL.
+ *   - @c ACL_FAILURE - If @c fd does not have a default ACL.
+ *   - @c ACL_ERROR - Unexpected library error.
+ */
+int has_default_acl_fd(int fd) {
+  if (fgetxattr(fd, XATTR_NAME_POSIX_ACL_DEFAULT, NULL, 0) == XATTR_ERROR) {
+    if (errno == ENODATA) {
+      return ACL_FAILURE;
+    }
+    perror("has_default_acl_fd (fgetxattr)");
+    return ACL_ERROR;
+  }
+
+  return ACL_SUCCESS;
+}
+
+
 /**
  * @brief Apply parent default ACL to a path.
  *
@@ -754,6 +778,13 @@ int apply_default_acl_ex(const char* path,
     }
   }
 
+  /* Check to make sure the parent descriptor actually has a default
+     ACL. If it doesn't, then we can "succeed" immediately. */
+  if (has_default_acl_fd(parent_fd) == ACL_FAILURE) {
+    result = ACL_SUCCESS;
+    goto cleanup;
+  }
+
   fd = safe_open(path, O_NOFOLLOW);
   if (fd == OPEN_ERROR) {
     if (errno == ELOOP || errno == ENOTDIR) {