From 03c7df6fc683c68975db46c7afaa24f1a9a05fae Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Fri, 28 Jul 2023 18:07:34 -0400 Subject: [PATCH] Properly mirror child exit status in ksu ksu attempts to exit with the same status as its child process, but does not do so correctly. Use WEXITSTATUS() to extract the exit code. Reported by Todd Lubin. ticket: 8618 --- src/clients/ksu/main.c | 2 +- src/clients/ksu/t_ksu.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/clients/ksu/main.c b/src/clients/ksu/main.c index 7298436585..80a9c07db7 100644 --- a/src/clients/ksu/main.c +++ b/src/clients/ksu/main.c @@ -780,7 +780,7 @@ main(int argc, char ** argv) com_err(prog_name, errno, _("while calling waitpid")); } sweep_up(ksu_context, cc_target); - exit (statusp); + exit (WIFEXITED(statusp) ? WEXITSTATUS(statusp) : 1); case -1: com_err(prog_name, errno, _("while trying to fork.")); sweep_up(ksu_context, cc_target); diff --git a/src/clients/ksu/t_ksu.py b/src/clients/ksu/t_ksu.py index 9740972ba5..ab52b4b2dc 100644 --- a/src/clients/ksu/t_ksu.py +++ b/src/clients/ksu/t_ksu.py @@ -244,7 +244,7 @@ mark('principal heuristic (no authorization)') realm.run([ksu, '.', '-e', klist], expected_msg='Default principal: alice@KRBTEST.COM') be_root() -realm.run([ksu, 'ksutest', '-e', klist], +realm.run([ksu, 'ksutest', '-e', klist], expected_code=1, expected_msg='No credentials cache found') be_caller() realm.kinit('ksutest', 'pwksutest') @@ -253,7 +253,8 @@ realm.run([ksu, 'ksutest', '-e', klist], expected_msg='Default principal: ksutest@KRBTEST.COM') be_caller() realm.run([kdestroy]) -realm.run([ksu, '.', '-e', klist], expected_msg='No credentials cache found') +realm.run([ksu, '.', '-e', klist], expected_code=1, + expected_msg='No credentials cache found') mark('authentication without authorization') realm.run([ksu, '.', '-n', 'ksutest', '-e', klist], input='pwksutest\n', @@ -266,6 +267,7 @@ realm.kinit(caller_username, 'pwcaller') realm.run([ksu, '.', '-z', '-e', klist], expected_msg='Default principal: ' + caller_username) -realm.run([ksu, '.', '-Z', '-e', klist]) +realm.run([ksu, '.', '-Z', '-e', klist], expected_code=1, + expected_msg='No credentials cache found') success('ksu tests') -- 2.47.2