util: switch create_dir() from chown() to lchown()

Use lchown(), the safer variant of chown() that does not follow
symlinks, when changing the ownership of a created directory (logdir,
dumpdir, ntsdumpdir, and the directory of bindcmdaddress) to the chrony
user.
This commit is contained in:
Miroslav Lichvar
2025-08-26 08:38:07 +02:00
parent 0289442998
commit 830c8bb18a

2
util.c
View File

@@ -1203,7 +1203,7 @@ create_dir(char *p, mode_t mode, uid_t uid, gid_t gid)
} }
/* Set its owner */ /* Set its owner */
if (chown(p, uid, gid) < 0) { if (lchown(p, uid, gid) < 0) {
LOG(LOGS_ERR, "Could not change ownership of %s : %s", p, strerror(errno)); LOG(LOGS_ERR, "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);