@@ -420,7 +420,9 @@ void base_process_service::run_child_proc(run_proc_params params) noexcept
420420 if (uid != uid_t (-1 )) {
421421 err.stage = exec_stage::SET_UIDGID;
422422 // We must set group first (i.e. before we drop privileges)
423- #if USE_INITGROUPS
423+
424+ #if USE_INITGROUPS
425+
424426 // Initialize supplementary groups unless disabled; non-POSIX API
425427 if (gid != gid_t (-1 )) {
426428 // Specific group; use that, with no supplementary groups.
@@ -444,20 +446,28 @@ void base_process_service::run_child_proc(run_proc_params params) noexcept
444446 goto failure_out;
445447 }
446448 }
447- #else
449+
450+ #else /* ! USE_INITGROUPS */
451+
448452 // No support for supplementary groups; just set the specified group.
449453 if (gid != gid_t (-1 )) {
450454 if (setregid (gid, gid) != 0 ) goto failure_out;
451455 }
452- #endif
453- #if SUPPORT_CAPABILITIES
454- if (cap_setuid (uid) != 0 ) goto failure_out;
455- #else
456- if (setreuid (uid, uid) != 0 ) goto failure_out;
457- #endif
456+
457+ #endif /* USE_INITGROUPS */
458+
459+ #if SUPPORT_CAPABILITIES
460+ {
461+ if (cap_setuid (uid) != 0 ) goto failure_out;
462+ }
463+ #else
464+ {
465+ if (setreuid (uid, uid) != 0 ) goto failure_out;
466+ }
467+ #endif
458468 }
459469
460- #if SUPPORT_CAPABILITIES
470+ #if SUPPORT_CAPABILITIES
461471 if (cap_iab) {
462472 err.stage = exec_stage::SET_CAPS;
463473 if (cap_iab_set_proc (cap_iab) != 0 ) goto failure_out;
@@ -470,7 +480,7 @@ void base_process_service::run_child_proc(run_proc_params params) noexcept
470480 err.stage = exec_stage::SET_CAPS;
471481 if (prctl (PR_SET_NO_NEW_PRIVS, 1 , 0 , 0 , 0 ) < 0 ) goto failure_out;
472482 }
473- #endif
483+ #endif
474484
475485 // Restore signal mask. If running on the console, we'll keep various control signals that can
476486 // be invoked from the terminal masked, with the exception of SIGHUP and possibly SIGINT.
0 commit comments