X-Git-Url: http://gitweb.michael.orlitzky.com/?p=apply-default-acl.git;a=blobdiff_plain;f=src%2Flibadacl.c;h=0d07f2c6d0126880b59e830011fcbbefc75e797f;hp=d92432228358badf66a302e34e31ff459579b1de;hb=6727b9e8ed3807cd565127f87fa6faa33c4b5ee4;hpb=c5fdaba07b5f965edca0a57d9c3cd8f8bbabc155 diff --git a/src/libadacl.c b/src/libadacl.c index d924322..0d07f2c 100644 --- a/src/libadacl.c +++ b/src/libadacl.c @@ -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) {