Browse Source

exit when running as a nonexistent user and warn when running as root

pull/948/head
Rayson Zhu 8 years ago
committed by Rayson zhu
parent
commit
07d2b1a005
5 changed files with 26 additions and 11 deletions
  1. 7
      src/local.c
  2. 9
      src/manager.c
  3. 7
      src/redir.c
  4. 7
      src/server.c
  5. 7
      src/tunnel.c

7
src/local.c

@ -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

9
src/manager.c

@ -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);

7
src/redir.c

@ -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);

7
src/server.c

@ -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

7
src/tunnel.c

@ -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);

Loading…
Cancel
Save