sys: move getpwnam() call to main.c

Pass uid/gid instead of user name to the root dropping function.
This commit is contained in:
Miroslav Lichvar
2015-08-10 15:53:36 +02:00
parent 236576c124
commit 6402350c83
6 changed files with 20 additions and 22 deletions

7
main.c
View File

@@ -350,6 +350,7 @@ int main
const char *conf_file = DEFAULT_CONF_FILE;
const char *progname = argv[0];
char *user = NULL;
struct passwd *pw;
int debug = 0, nofork = 0, address_family = IPADDR_UNSPEC;
int do_init_rtc = 0, restarted = 0;
int other_pid;
@@ -488,8 +489,12 @@ int main
if (!user) {
user = CNF_GetUser();
}
if (user && strcmp(user, "root")) {
SYS_DropRoot(user);
if ((pw = getpwnam(user)) == NULL)
LOG_FATAL(LOGF_Main, "Could not get %s uid/gid", user);
SYS_DropRoot(pw->pw_uid, pw->pw_gid);
}
LOG_CreateLogFileDir();