main: always call getpwnam()

Don't hardcode root as the user with zero uid/gid.
This commit is contained in:
Miroslav Lichvar
2015-08-10 16:24:45 +02:00
parent 6402350c83
commit e7100e106d
3 changed files with 18 additions and 14 deletions

8
main.c
View File

@@ -490,12 +490,12 @@ int main
user = CNF_GetUser();
}
if (user && strcmp(user, "root")) {
if ((pw = getpwnam(user)) == NULL)
LOG_FATAL(LOGF_Main, "Could not get %s uid/gid", user);
if ((pw = getpwnam(user)) == NULL)
LOG_FATAL(LOGF_Main, "Could not get %s uid/gid", user);
/* Drop root privileges if the user has non-zero uid or gid */
if (pw->pw_uid || pw->pw_gid)
SYS_DropRoot(pw->pw_uid, pw->pw_gid);
}
LOG_CreateLogFileDir();