--- a/src/svr-auth.c +++ b/src/svr-auth.c @@ -509,9 +509,9 @@ void svr_switch_user(void) { /* We can only change uid/gid as root ... */ if (getuid() == 0) { - if ((setgid(ses.authstate.pw_gid) < 0) || + if ((ses.authstate.pw_gid != 0) && ((setgid(ses.authstate.pw_gid) < 0) || (initgroups(ses.authstate.pw_name, - ses.authstate.pw_gid) < 0)) { + ses.authstate.pw_gid) < 0))) { dropbear_exit("Error changing user group"); } @@ -533,7 +533,7 @@ void svr_switch_user(void) { } #endif - if (setuid(ses.authstate.pw_uid) < 0) { + if ((ses.authstate.pw_uid != 0) && (setuid(ses.authstate.pw_uid) < 0)) { dropbear_exit("Error changing user"); } } else {