add: drop privileges

This commit is contained in:
Tobias Reisinger 2020-06-19 00:26:49 +02:00
parent 486b45c680
commit 1d8408581a
6 changed files with 118 additions and 7 deletions

View file

@ -49,6 +49,9 @@ main(int argc, const char** argv)
/******************** LOAD CONFIG ********************/
global_config.file = "core.ini";
strcpy(global_config.user, "");
strcpy(global_config.group, "");
strcpy(global_config.not_found_file, "404.html");
strcpy(global_config.not_found_file_type, "text/html");
strcpy(global_config.not_found_content, "404 - NOT FOUND");
@ -77,6 +80,24 @@ main(int argc, const char** argv)
global_config.http_server_opts.extra_headers = "Access-Control-Allow-Origin: *\r\nAccess-Control-Allow-Headers: *\r\nAccess-Control-Allow-Methods: *";
/******************** SETUP CONNECTION ********************/
struct mg_connection *c;
mg_mgr_init(&mgr, NULL);
c = mg_bind(&mgr, global_config.server_port, handler_connection);
if(c == NULL)
{
LOG_FATAL("failed to bind to port %s\n", global_config.server_port);
exit(1);
}
mg_set_protocol_http_websocket(c);
helper_drop_privileges();
/******************** SETUP DATABASE ********************/
int rc = sqlite3_open(global_config.database, &global_database);
@ -102,12 +123,6 @@ main(int argc, const char** argv)
/******************** START MAIN LOOP ********************/
struct mg_connection *c;
mg_mgr_init(&mgr, NULL);
c = mg_bind(&mgr, global_config.server_port, handler_connection);
mg_set_protocol_http_websocket(c);
for (;;)
{
mg_mgr_poll(&mgr, 1000);