1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-11-26 14:57:17 +00:00

drop privliges after port binding, fixes #12

This commit is contained in:
Andrew Karpow 2014-04-23 12:17:55 +02:00
parent fd140e210e
commit 25d54f68d6

View File

@ -56,6 +56,7 @@ int main(int argc, char **argv)
int n, option_index = 0; int n, option_index = 0;
struct mg_server *server = mg_create_server(NULL); struct mg_server *server = mg_create_server(NULL);
unsigned int current_timer = 0, last_timer = 0; unsigned int current_timer = 0, last_timer = 0;
char *run_as_user = NULL;
atexit(bye); atexit(bye);
mg_set_option(server, "listening_port", "8080"); mg_set_option(server, "listening_port", "8080");
@ -84,7 +85,7 @@ int main(int argc, char **argv)
mg_set_option(server, "listening_port", optarg); mg_set_option(server, "listening_port", optarg);
break; break;
case 'u': case 'u':
mg_set_option(server, "run_as_user", optarg); run_as_user = strdup(optarg);
break; break;
case 'v': case 'v':
fprintf(stdout, "ympd %d.%d.%d\n" fprintf(stdout, "ympd %d.%d.%d\n"
@ -106,6 +107,13 @@ int main(int argc, char **argv)
} }
} }
/* drop privilges at last to ensure proper port binding */
if(run_as_user != NULL)
{
mg_set_option(server, "run_as_user", run_as_user);
free(run_as_user);
}
mg_set_http_close_handler(server, mpd_close_handler); mg_set_http_close_handler(server, mpd_close_handler);
mg_set_request_handler(server, server_callback); mg_set_request_handler(server, server_callback);
while (!force_exit) { while (!force_exit) {