# HG changeset patch # User Olaf Wintermann # Date 1484389675 -3600 # Node ID a9591a91c004b976bcd29db49fc3bb83d85bb9bf # Parent 1c93281ca4bf019c1700c65d63115f2f7312bb3a fixes server user init diff -r 1c93281ca4bf -r a9591a91c004 make/clang.mk --- a/make/clang.mk Fri Jan 13 09:53:55 2017 +0100 +++ b/make/clang.mk Sat Jan 14 11:27:55 2017 +0100 @@ -27,7 +27,7 @@ # CFLAGS = -g -LDFLAGS = -Wl,-R,'$$ORIGIN/../lib' +LDFLAGS = -rdynamic -Wl,-R,'$$ORIGIN/../lib' CC = clang CXX = clang++ diff -r 1c93281ca4bf -r a9591a91c004 make/gcc.mk --- a/make/gcc.mk Fri Jan 13 09:53:55 2017 +0100 +++ b/make/gcc.mk Sat Jan 14 11:27:55 2017 +0100 @@ -27,7 +27,7 @@ # CFLAGS = -std=gnu99 -g -LDFLAGS = -Wl,-R,'$$ORIGIN/../lib' +LDFLAGS = -rdynamic -Wl,-R,'$$ORIGIN/../lib' CC = gcc CXX = g++ diff -r 1c93281ca4bf -r a9591a91c004 src/server/daemon/main.c --- a/src/server/daemon/main.c Fri Jan 13 09:53:55 2017 +0100 +++ b/src/server/daemon/main.c Sat Jan 14 11:27:55 2017 +0100 @@ -154,6 +154,7 @@ signal(SIGINT, sig_term); struct sigaction act; + ZERO(&act, sizeof(struct sigaction)); act.sa_handler = SIG_IGN; sigaction(SIGPIPE, &act, NULL); diff -r 1c93281ca4bf -r a9591a91c004 src/server/daemon/webserver.c --- a/src/server/daemon/webserver.c Fri Jan 13 09:53:55 2017 +0100 +++ b/src/server/daemon/webserver.c Sat Jan 14 11:27:55 2017 +0100 @@ -97,7 +97,7 @@ char *pid_file_path = NULL; asprintf(&pid_file_path, "%s/pid", cfg->tmp.ptr); - FILE *pidfile = fopen(pid_file_path, "w"); + FILE *pidfile = fopen(pid_file_path, "w"); // TODO: check error pid_t pid = getpid(); fprintf(pidfile, "%d", pid); fclose(pidfile); @@ -106,6 +106,7 @@ // set global vars conf_global_vars_s *vars = conf_getglobals(); + WSBool changeuid = FALSE; uid_t ws_uid = geteuid(); setpwent(); char *pwbuf = malloc(DEF_PWBUF); @@ -118,6 +119,8 @@ cfg->user.ptr); free(vars->Vuserpw); vars->Vuserpw = NULL; + } else { + changeuid = TRUE; } } else { if(!util_getpwuid(ws_uid, vars->Vuserpw, pwbuf, DEF_PWBUF)) { @@ -129,25 +132,9 @@ if(!vars->Vuserpw) { log_ereport(LOG_WARN, "globalvars->Vuserpw is null"); } - - if(cfg->user.ptr) { - vars->Vuserpw = malloc(sizeof(struct passwd)); - // open user database - //setpwent(); - if(!util_getpwnam(cfg->user.ptr, vars->Vuserpw, pwbuf, DEF_PWBUF)) { - log_ereport( - LOG_MISCONFIG, - "user %s does not exist!", - cfg->user.ptr); - free(vars->Vuserpw); - vars->Vuserpw = NULL; - } - //endpwent(); // TODO: close or not? - } - free(pwbuf); // change uid - if(vars->Vuserpw && ws_uid == 0) { + if(changeuid && ws_uid == 0) { // a webserver user is set and we are root if(setgid(vars->Vuserpw->pw_gid) != 0) { @@ -176,6 +163,9 @@ "server must be started as root to change uid"); } + //endpwent(); // TODO: close or not? + //free(pwbuf); // TODO: ? + return 0; }