X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2Flibadacl.c;h=21b8141cbbc0158a3c6cfce3e985838bed1e20ce;hb=aaf323d45b5c2043acd64b7e6b8b1fea1664dd0b;hp=08b13b82395941b90956129499de8a3450177ace;hpb=a662358647653b8d7f4f2dbfc5ca2802f38c60c8;p=apply-default-acl.git diff --git a/src/libadacl.c b/src/libadacl.c index 08b13b8..21b8141 100644 --- a/src/libadacl.c +++ b/src/libadacl.c @@ -26,6 +26,15 @@ #include "libadacl.h" +/* Even though most other library functions reliably return -1 for + * error, it feels a little wrong to re-use the ACL_ERROR constant. + */ +#define CLOSE_ERROR -1 +#define OPEN_ERROR -1 +#define SNPRINTF_ERROR -1 +#define STAT_ERROR -1 + + /** * @brief The recursive portion of the @c safe_open function, used to * open a file descriptor in a symlink-safe way when combined with @@ -37,6 +46,9 @@ * @param pathname * The path to the file/directory/whatever whose descriptor you want. * + * @param flags + * File status flags to be passed to @c openat. + * * @return a file descriptor for @c pathname if everything goes well, * and @c OPEN_ERROR if not. */ @@ -97,6 +109,9 @@ int safe_open_ex(int at_fd, char* pathname, int flags) { * @param pathname * The path to the file/directory/whatever whose descriptor you want. * + * @param flags + * File status flags to be passed to @c openat. + * * @return a file descriptor for @c pathname if everything goes well, * and @c OPEN_ERROR if not. */ @@ -145,6 +160,11 @@ int safe_open(const char* pathname, int flags) { } int fd = open("/", flags); + if (fd == OPEN_ERROR) { + perror("safe_open (open)"); + return OPEN_ERROR; + } + if (strcmp(abspath, "/") == 0) { return fd; } @@ -600,8 +620,7 @@ int wipe_acls(int fd) { * * @return * - @c ACL_SUCCESS - The parent default ACL was inherited successfully. - * - @c ACL_FAILURE - The target path is not a regular file/directory, - * or the parent of @c path is not a directory. + * - @c ACL_FAILURE - If symlinks or hard links are encountered. * - @c ACL_ERROR - Unexpected library error. */ int apply_default_acl_ex(const char* path, @@ -851,7 +870,7 @@ int apply_default_acl_ex(const char* path, * * @return * - @c ACL_SUCCESS - The parent default ACL was inherited successfully. - * - @c ACL_FAILURE - The target path is not a regular file/directory, + * - @c ACL_FAILURE - If symlinks or hard links are encountered. * or the parent of @c path is not a directory. * - @c ACL_ERROR - Unexpected library error. */