FILE *f;
sigset_t sigs;
int num;
- int is_child_of_nonroot = 0;
+ int isroot = 1;
char *buf;
char *runuser = NULL, *rungroup = NULL;
_argv[x] = argv[x];
_argv[x] = NULL;
+ if (geteuid() != 0)
+ isroot = 0;
+
/* if the progname is rasterisk consider it a remote console */
if (argv[0] && (strstr(argv[0], "rasterisk")) != NULL) {
ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE);
ast_builtins_init();
ast_utils_init();
tdd_init();
- /* When Asterisk restarts after it has dropped the root privileges,
- * it can't issue setuid(), setgid(), setgroups() or set_priority()
- */
- if (getenv("ASTERISK_ALREADY_NONROOT"))
- is_child_of_nonroot=1;
+
if (getenv("HOME"))
snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
/* Check for options */
#ifndef __CYGWIN__
- if (!is_child_of_nonroot)
+ if (isroot)
ast_set_priority(ast_opt_high_priority);
- if (!is_child_of_nonroot && rungroup) {
+ if (isroot && rungroup) {
struct group *gr;
gr = getgrnam(rungroup);
if (!gr) {
ast_verbose("Running as group '%s'\n", rungroup);
}
- if (!is_child_of_nonroot && runuser) {
+ if (runuser && !ast_test_flag(&ast_options, AST_OPT_FLAG_REMOTE)) {
#ifdef HAVE_CAP
int has_cap = 1;
#endif /* HAVE_CAP */
has_cap = 0;
}
#endif /* HAVE_CAP */
+ if (!isroot && pw->pw_uid != geteuid()) {
+ ast_log(LOG_ERROR, "Asterisk started as nonroot, but runuser '%s' requested.\n", runuser);
+ exit(1);
+ }
if (!rungroup) {
if (setgid(pw->pw_gid)) {
ast_log(LOG_WARNING, "Unable to setgid to %d!\n", (int)pw->pw_gid);
ast_log(LOG_WARNING, "Unable to setuid to %d (%s)\n", (int)pw->pw_uid, runuser);
exit(1);
}
- setenv("ASTERISK_ALREADY_NONROOT", "yes", 1);
if (option_verbose)
ast_verbose("Running as user '%s'\n", runuser);
#ifdef HAVE_CAP