exit when running as a nonexistent user and warn when running as root (#948)

This commit is contained in:
Max Lv
2016-11-14 21:06:04 -06:00
committed by GitHub
5 changed files with 26 additions and 11 deletions
+5 -2
View File
@@ -1440,8 +1440,11 @@ main(int argc, char **argv)
LOGI("listening at %s:%s", local_addr, local_port);
// setuid
if (user != NULL) {
run_as(user);
if (user != NULL && ! run_as(user)) {
FATAL("failed to switch user");
}
if (geteuid() == 0){
LOGI("You are running this process as the root user!");
}
// Init connections
+6 -3
View File
@@ -845,11 +845,14 @@ main(int argc, char **argv)
struct ev_loop *loop = EV_DEFAULT;
// setuid
if (user != NULL) {
run_as(user);
if (user != NULL && ! run_as(user)) {
FATAL("failed to switch user");
}
if (geteuid() == 0){
LOGI("You are running this process as the root user!");
}
struct passwd *pw = getpwuid(getuid());
struct passwd *pw = getpwuid(geteuid());
const char *homedir = pw->pw_dir;
working_dir_size = strlen(homedir) + 15;
working_dir = malloc(working_dir_size);
+5 -2
View File
@@ -1021,8 +1021,11 @@ main(int argc, char **argv)
LOGI("listening at %s:%s", local_addr, local_port);
// setuid
if (user != NULL) {
run_as(user);
if (user != NULL && ! run_as(user)) {
FATAL("failed to switch user");
}
if (geteuid() == 0){
LOGI("You are running this process as the root user!");
}
ev_run(loop, 0);
+5 -2
View File
@@ -1871,8 +1871,11 @@ main(int argc, char **argv)
ev_timer_start(EV_DEFAULT, &block_list_watcher);
// setuid
if (user != NULL) {
run_as(user);
if (user != NULL && ! run_as(user)) {
FATAL("failed to switch user");
}
if (geteuid() == 0){
LOGI("You are running this process as the root user!");
}
// init block list
+5 -2
View File
@@ -1028,8 +1028,11 @@ main(int argc, char **argv)
LOGI("listening at %s:%s", local_addr, local_port);
// setuid
if (user != NULL) {
run_as(user);
if (user != NULL && ! run_as(user)) {
FATAL("failed to switch user");
}
if (geteuid() == 0){
LOGI("You are running this process as the root user!");
}
ev_run(loop, 0);