66 |
66 |
67 extern struct FuncStruct webserver_funcs[]; |
67 extern struct FuncStruct webserver_funcs[]; |
68 |
68 |
69 static RestartCallback *atrestart; |
69 static RestartCallback *atrestart; |
70 |
70 |
|
71 static char *pwbuf; |
|
72 |
71 int webserver_init() { |
73 int webserver_init() { |
72 // init NSPR |
74 // init NSPR |
73 systhread_init("webserver"); |
75 systhread_init("webserver"); |
74 |
76 |
75 log_ereport(LOG_VERBOSE, "webserver_init"); |
77 log_ereport(LOG_VERBOSE, "webserver_init"); |
124 conf_global_vars_s *vars = conf_getglobals(); |
126 conf_global_vars_s *vars = conf_getglobals(); |
125 |
127 |
126 WSBool changeuid = FALSE; |
128 WSBool changeuid = FALSE; |
127 uid_t ws_uid = geteuid(); |
129 uid_t ws_uid = geteuid(); |
128 setpwent(); |
130 setpwent(); |
129 char *pwbuf = malloc(DEF_PWBUF); |
131 pwbuf = malloc(DEF_PWBUF); |
130 vars->Vuserpw = malloc(sizeof(struct passwd)); |
132 vars->Vuserpw = malloc(sizeof(struct passwd)); |
131 if(cfg->user.ptr) { |
133 if(cfg->user.ptr) { |
132 if(!util_getpwnam(cfg->user.ptr, vars->Vuserpw, pwbuf, DEF_PWBUF)) { |
134 if(!util_getpwnam(cfg->user.ptr, vars->Vuserpw, pwbuf, DEF_PWBUF)) { |
133 log_ereport( |
135 log_ereport( |
134 LOG_MISCONFIG, |
136 LOG_MISCONFIG, |
147 } |
149 } |
148 } |
150 } |
149 if(!vars->Vuserpw) { |
151 if(!vars->Vuserpw) { |
150 log_ereport(LOG_VERBOSE, "globalvars->Vuserpw is null"); |
152 log_ereport(LOG_VERBOSE, "globalvars->Vuserpw is null"); |
151 } |
153 } |
|
154 endpwent(); |
152 |
155 |
153 // change uid |
156 // change uid |
154 if(changeuid && ws_uid == 0) { |
157 if(changeuid && ws_uid == 0) { |
155 // a webserver user is set and we are root |
158 // a webserver user is set and we are root |
156 log_ereport(LOG_VERBOSE, "setgid(%d)", vars->Vuserpw->pw_gid); |
159 log_ereport(LOG_VERBOSE, "setgid(%d)", vars->Vuserpw->pw_gid); |
348 |
351 |
349 resource_pool_cleanup(); |
352 resource_pool_cleanup(); |
350 func_cleanup(); |
353 func_cleanup(); |
351 |
354 |
352 ServerConfiguration *scfg = cfgmgr_get_server_config(); |
355 ServerConfiguration *scfg = cfgmgr_get_server_config(); |
|
356 CxIterator i = cxListIterator(scfg->logfiles); |
|
357 cx_foreach(AccessLog *, logfile, i) { |
|
358 fclose(logfile->log->file); |
|
359 } |
353 pool_destroy(scfg->pool); |
360 pool_destroy(scfg->pool); |
|
361 |
|
362 free(pwbuf); |
354 } |
363 } |
355 |
364 |
356 int nsapi_runtime_version() { |
365 int nsapi_runtime_version() { |
357 return 303; |
366 return 303; |
358 } |
367 } |