src/server/daemon/webserver.c

changeset 75
6195c92262a2
parent 73
79fa26ecd135
child 85
b62e77d8e80c
equal deleted inserted replaced
74:5bc6d078fb2c 75:6195c92262a2
95 free(pid_file_path); 95 free(pid_file_path);
96 96
97 // set global vars 97 // set global vars
98 conf_global_vars_s *vars = conf_getglobals(); 98 conf_global_vars_s *vars = conf_getglobals();
99 99
100 uid_t ws_uid = geteuid();
100 setpwent(); 101 setpwent();
102 char *pwbuf = malloc(DEF_PWBUF);
103 vars->Vuserpw = malloc(sizeof(struct passwd));
104 if(cfg->user.ptr) {
105 if(!util_getpwnam(cfg->user.ptr, vars->Vuserpw, pwbuf, DEF_PWBUF)) {
106 log_ereport(
107 LOG_MISCONFIG,
108 "user %s does not exist!",
109 cfg->user.ptr);
110 free(vars->Vuserpw);
111 vars->Vuserpw = NULL;
112 }
113 } else {
114 if(!util_getpwuid(ws_uid, vars->Vuserpw, pwbuf, DEF_PWBUF)) {
115 log_ereport(LOG_FAILURE, "webserver_init: cannot get passwd data");
116 free(vars->Vuserpw);
117 vars->Vuserpw = NULL;
118 }
119 }
120 free(pwbuf);
121 if(!vars->Vuserpw) {
122 log_ereport(LOG_WARN, "globalvars->Vuserpw is null");
123 }
124
101 if(cfg->user.ptr) { 125 if(cfg->user.ptr) {
102 char *pwbuf = malloc(DEF_PWBUF); 126 char *pwbuf = malloc(DEF_PWBUF);
103 vars->Vuserpw = malloc(sizeof(struct passwd)); 127 vars->Vuserpw = malloc(sizeof(struct passwd));
104 // open user database 128 // open user database
105 //setpwent(); 129 //setpwent();
114 free(pwbuf); 138 free(pwbuf);
115 //endpwent(); // TODO: close or not? 139 //endpwent(); // TODO: close or not?
116 } 140 }
117 141
118 // change uid 142 // change uid
119 if(vars->Vuserpw && geteuid() == 0) { 143 if(vars->Vuserpw && ws_uid == 0) {
120 // a webserver user is set and we are root 144 // a webserver user is set and we are root
121 145
122 if(setgid(vars->Vuserpw->pw_gid) != 0) { 146 if(setgid(vars->Vuserpw->pw_gid) != 0) {
123 log_ereport( 147 log_ereport(
124 LOG_FAILURE, 148 LOG_FAILURE,

mercurial