mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 21:45:07 -05:00
util: set uid/gid of created directory even when zero
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.
This commit is contained in:
4
util.c
4
util.c
@@ -945,8 +945,8 @@ create_dir(char *p, mode_t mode, uid_t uid, gid_t gid)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Change its ownership if requested */
|
/* Set its owner */
|
||||||
if ((uid || gid) && chown(p, uid, gid) < 0) {
|
if (chown(p, uid, gid) < 0) {
|
||||||
LOG(LOGS_ERR, LOGF_Util, "Could not change ownership of %s : %s", p, strerror(errno));
|
LOG(LOGS_ERR, LOGF_Util, "Could not change ownership of %s : %s", p, strerror(errno));
|
||||||
/* Don't leave it there with incorrect ownership */
|
/* Don't leave it there with incorrect ownership */
|
||||||
rmdir(p);
|
rmdir(p);
|
||||||
|
|||||||
6
util.h
6
util.h
@@ -133,9 +133,9 @@ extern int UTI_SetQuitSignalsHandler(void (*handler)(int));
|
|||||||
/* Get directory (as an allocated string) for a path */
|
/* Get directory (as an allocated string) for a path */
|
||||||
extern char *UTI_PathToDir(const char *path);
|
extern char *UTI_PathToDir(const char *path);
|
||||||
|
|
||||||
/* Create a directory with a specified mode (umasked) and set its uid/gid
|
/* 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
|
Create also any parent directories that don't exist with mode 755 and
|
||||||
755 and default uid/gid. Returns 1 if created or already exists (even with
|
default uid/gid. Returns 1 if created or already exists (even with
|
||||||
different mode/uid/gid), 0 otherwise. */
|
different mode/uid/gid), 0 otherwise. */
|
||||||
extern int UTI_CreateDirAndParents(const char *path, mode_t mode, uid_t uid, gid_t gid);
|
extern int UTI_CreateDirAndParents(const char *path, mode_t mode, uid_t uid, gid_t gid);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user