Skip to content

Commit

Permalink
drop privliges after port binding, fixes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
notandy committed Apr 23, 2014
1 parent fd140e2 commit 25d54f6
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/ympd.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ int main(int argc, char **argv)
int n, option_index = 0;
struct mg_server *server = mg_create_server(NULL);
unsigned int current_timer = 0, last_timer = 0;
char *run_as_user = NULL;

atexit(bye);
mg_set_option(server, "listening_port", "8080");
Expand Down Expand Up @@ -84,7 +85,7 @@ int main(int argc, char **argv)
mg_set_option(server, "listening_port", optarg);
break;
case 'u':
mg_set_option(server, "run_as_user", optarg);
run_as_user = strdup(optarg);
break;
case 'v':
fprintf(stdout, "ympd %d.%d.%d\n"
Expand All @@ -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_request_handler(server, server_callback);
while (!force_exit) {
Expand Down

0 comments on commit 25d54f6

Please sign in to comment.