]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
util: set uid/gid of created directory even when zero
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 13 Aug 2015 15:04:10 +0000 (17:04 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 13 Aug 2015 15:15:50 +0000 (17:15 +0200)
Call chown() in create_dir() even when the specified uid/gid is zero.
This is needed on BSD systems, where directories are created with gid
of the parent directory.

util.c
util.h

diff --git a/util.c b/util.c
index f03ebaf05f3b89698877cc4b51d131a38587ae0c..d3db6509cc5dfce432bbafa8d88167b058bfdc0d 100644 (file)
--- a/util.c
+++ b/util.c
@@ -945,8 +945,8 @@ create_dir(char *p, mode_t mode, uid_t uid, gid_t gid)
     return 0;
   }
 
-  /* Change its ownership if requested */
-  if ((uid || gid) && chown(p, uid, gid) < 0) {
+  /* Set its owner */
+  if (chown(p, uid, gid) < 0) {
     LOG(LOGS_ERR, LOGF_Util, "Could not change ownership of %s : %s", p, strerror(errno));
     /* Don't leave it there with incorrect ownership */
     rmdir(p);
diff --git a/util.h b/util.h
index 360fced2825bf6989c8a6d8294dbd25ea5c7d3cc..f93d794a6f3601c5bfe175b07a48675a0d85de30 100644 (file)
--- a/util.h
+++ b/util.h
@@ -133,9 +133,9 @@ extern int UTI_SetQuitSignalsHandler(void (*handler)(int));
 /* Get directory (as an allocated string) for a path */
 extern char *UTI_PathToDir(const char *path);
 
-/* Create a directory with a specified mode (umasked) and set its uid/gid
-   (if not 0).  Create also any parent directories that don't exist with mode
-   755 and default uid/gid.  Returns 1 if created or already exists (even with
+/* Create a directory with a specified mode (umasked) and set its uid/gid.
+   Create also any parent directories that don't exist with mode 755 and
+   default uid/gid.  Returns 1 if created or already exists (even with
    different mode/uid/gid), 0 otherwise. */
 extern int UTI_CreateDirAndParents(const char *path, mode_t mode, uid_t uid, gid_t gid);