Skip to content

Commit

Permalink
Fix drop-after options so they work
Browse files Browse the repository at this point in the history
Moved all calls to `uwsgi_as_root` into `uwsgi.c` so that all handling
of privilege dropping is in the same file. Added extra checks to ensure
that privileges are properly dropped when the user requests them to be
dropped.

This closes #1519
  • Loading branch information
RobertDeRose committed May 3, 2017
1 parent d241561 commit bc043d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
7 changes: 0 additions & 7 deletions core/socket.c
Expand Up @@ -1846,13 +1846,6 @@ void uwsgi_bind_sockets() {

stdin_done:

if (uwsgi.chown_socket) {
if (!uwsgi.master_as_root) {
uwsgi_as_root();
}
}


// check for auto_port socket
uwsgi_sock = uwsgi.sockets;
while (uwsgi_sock) {
Expand Down
13 changes: 11 additions & 2 deletions core/uwsgi.c
Expand Up @@ -2695,6 +2695,7 @@ int uwsgi_start(void *v_argv) {
uwsgi_file_write_do(uwsgi.file_write_list);

if (!uwsgi.master_as_root && !uwsgi.chown_socket && !uwsgi.drop_after_init && !uwsgi.drop_after_apps) {
uwsgi_log("dropping root privileges as early as possible\n");
uwsgi_as_root();
}

Expand Down Expand Up @@ -2937,6 +2938,11 @@ int uwsgi_start(void *v_argv) {
//now bind all the unbound sockets
uwsgi_bind_sockets();

if (!uwsgi.master_as_root && !uwsgi.drop_after_init && !uwsgi.drop_after_apps) {
uwsgi_log("dropping root privileges after socket binding\n");
uwsgi_as_root();
}

// put listening socket in non-blocking state and set the protocol
uwsgi_set_sockets_protocols();

Expand All @@ -2952,7 +2958,8 @@ int uwsgi_start(void *v_argv) {
}
}

if (uwsgi.drop_after_init) {
if (!uwsgi.master_as_root && !uwsgi.drop_after_apps) {
uwsgi_log("dropping root privileges after plugin initialization\n");
uwsgi_as_root();
}

Expand Down Expand Up @@ -3220,7 +3227,8 @@ int uwsgi_start(void *v_argv) {
uwsgi_init_all_apps();
}

if (uwsgi.drop_after_apps) {
if (!uwsgi.master_as_root) {
uwsgi_log("dropping root privileges after application loading\n");
uwsgi_as_root();
}

Expand Down Expand Up @@ -3475,6 +3483,7 @@ int uwsgi_run() {
}

if (uwsgi.master_as_root) {
uwsgi_log("dropping root privileges after master thread creation\n");
uwsgi_as_root();
}

Expand Down

0 comments on commit bc043d5

Please sign in to comment.