X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2Flibadacl.c;h=36812e8af3dd18a4dbfd96f7c7b769865d90298d;hb=ee4b602d26225bb5a548eaeb7bd570adaa48721a;hp=1b31938666c9aab2aab84f4bdd3087bb7561b079;hpb=fb29df3ea25b6f6a5bfdeaa8912997f73d2e4d14;p=apply-default-acl.git diff --git a/src/libadacl.c b/src/libadacl.c index 1b31938..36812e8 100644 --- a/src/libadacl.c +++ b/src/libadacl.c @@ -170,25 +170,24 @@ int safe_open(const char* pathname, int flags) { return OPEN_ERROR; } - int fd = 0; - if (strcmp(abspath, "/") == 0) { - fd = open("/", flags | O_DIRECTORY); - } - else { + bool abspath_is_root = (strcmp(abspath, "/") == 0); + int rootflags = flags | O_DIRECTORY; + if (!abspath_is_root) { /* Use O_PATH for some added safety if "/" is not our target */ - fd = open("/", flags | O_DIRECTORY | O_PATH); + rootflags |= O_PATH; } - if (fd == OPEN_ERROR) { + int rootfd = open("/", rootflags); + if (rootfd == OPEN_ERROR) { perror("safe_open (open)"); return OPEN_ERROR; } - if (strcmp(abspath, "/") == 0) { - return fd; + if (abspath_is_root) { + return rootfd; } - int result = safe_open_ex(fd, abspath+1, flags); - if (close(fd) == CLOSE_ERROR) { + int result = safe_open_ex(rootfd, abspath+1, flags); + if (close(rootfd) == CLOSE_ERROR) { perror("safe_open (close)"); return OPEN_ERROR; }