char* exec = NULL;
char* stop = NULL;
char* pidfile = NULL;
+ uid_t uid = 0;
+ gid_t gid = 0;
+ bool bad = false;
for(i = 0;; i++){
if(buffer[i] == '\n' || buffer[i] == 0){
}else if(strcmp(key, "stop") == 0){
if(stop != NULL) free(stop);
stop = mk_strdup(value);
+ }else if(strcmp(key, "user") == 0){
+ struct passwd* p = getpwnam(value);
+ if(p != NULL){
+ uid = p->pw_uid;
+ gid = p->pw_gid;
+ }else{
+ mk_log("Could not find the specified user");
+ bad = true;
+ }
}
break;
}
fclose(f);
- bool bad = false;
if(exec == NULL){
char* log = mk_strcat(desc == NULL ? path : desc, ": Missing exec");
mk_log(log);
serv->stop = stop != NULL ? mk_strdup(stop) : NULL;
serv->exec = mk_strdup(exec);
serv->pidfile = mk_strdup(pidfile);
+ serv->uid = uid;
+ serv->gid = gid;
serv->stopped = false;
struct mk_service** oldsrvs = services;
int n = open("/dev/null", O_RDWR);
dup2(n, 1);
dup2(n, 2);
+ setgid(srv->gid);
+ setegid(srv->gid);
+ setuid(srv->uid);
+ seteuid(srv->uid);
execvp(pargv[0], pargv);
_exit(-1);
}else{
int n = open("/dev/null", O_RDWR);
dup2(n, 1);
dup2(n, 2);
+ setgid(srv->gid);
+ setegid(srv->gid);
+ setuid(srv->uid);
+ seteuid(srv->uid);
execvp(pargv[0], pargv);
_exit(-1);
}else{