Commit 9414de16 authored by Michael Smith's avatar Michael Smith

Fix potential problem which would occur if <changeuser> was set, but had

no <user> or no <group> element within it.

svn path=/trunk/icecast/; revision=3315
parent 86c78a6b
...@@ -92,11 +92,18 @@ static int _start_logging(void) ...@@ -92,11 +92,18 @@ static int _start_logging(void)
char fn_access[FILENAME_MAX]; char fn_access[FILENAME_MAX];
ice_config_t *config = config_get_config(); ice_config_t *config = config_get_config();
snprintf(fn_error, FILENAME_MAX, "%s%s%s", config->log_dir, PATH_SEPARATOR, config->error_log); if(strcmp(config->error_log, "-")) {
snprintf(fn_access, FILENAME_MAX, "%s%s%s", config->log_dir, PATH_SEPARATOR, config->access_log); snprintf(fn_error, FILENAME_MAX, "%s%s%s", config->log_dir, PATH_SEPARATOR, config->error_log);
errorlog = log_open(fn_error);
errorlog = log_open(fn_error); } else {
accesslog = log_open(fn_access); errorlog = log_open_file(stderr);
}
if(strcmp(config->access_log, "-")) {
snprintf(fn_access, FILENAME_MAX, "%s%s%s", config->log_dir, PATH_SEPARATOR, config->access_log);
accesslog = log_open(fn_access);
} else {
accesslog = log_open_file(stderr);
}
log_set_level(errorlog, 4); log_set_level(errorlog, 4);
log_set_level(accesslog, 4); log_set_level(accesslog, 4);
...@@ -176,17 +183,21 @@ static void _ch_root_uid__setup(void) ...@@ -176,17 +183,21 @@ static void _ch_root_uid__setup(void)
if(conf->chuid) if(conf->chuid)
{ {
user = getpwnam(conf->user); if(conf->user) {
group = getgrnam(conf->group); user = getpwnam(conf->user);
if(user)
uid = user->pw_uid;
else
fprintf(stderr, "Couldn't find user \"%s\" in password file\n", conf->user);
}
if(conf->group) {
group = getgrnam(conf->group);
if(user) if(group)
uid = user->pw_uid; gid = group->gr_gid;
else else
fprintf(stderr, "Couldn't find user \"%s\" in password file\n", conf->user); fprintf(stderr, "Couldn't find group \"%s\" in groups file\n", conf->group);
if(group) }
gid = group->gr_gid;
else
fprintf(stderr, "Couldn't find group \"%s\" in groups file\n", conf->group);
} }
#endif #endif
...@@ -220,14 +231,14 @@ static void _ch_root_uid__setup(void) ...@@ -220,14 +231,14 @@ static void _ch_root_uid__setup(void)
if(gid != -1) { if(gid != -1) {
if(!setgid(gid)) if(!setgid(gid))
fprintf(stdout, "Changed groupid to %i.\n", group->gr_gid); fprintf(stdout, "Changed groupid to %i.\n", gid);
else else
fprintf(stdout, "Error changing groupid: %s.\n", strerror(errno)); fprintf(stdout, "Error changing groupid: %s.\n", strerror(errno));
} }
if(uid != -1) { if(uid != -1) {
if(!setuid(uid)) if(!setuid(uid))
fprintf(stdout, "Changed userid to %i.\n", user->pw_uid); fprintf(stdout, "Changed userid to %i.\n", uid);
else else
fprintf(stdout, "Error changing userid: %s.\n", strerror(errno)); fprintf(stdout, "Error changing userid: %s.\n", strerror(errno));
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment