Skip to content

Commit

Permalink
Properly mirror child exit status in ksu
Browse files Browse the repository at this point in the history
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
  • Loading branch information
greghudson committed Oct 3, 2023
1 parent 036f861 commit 03c7df6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/clients/ksu/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions src/clients/ksu/t_ksu.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def remove_authz_file(fname):
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')
Expand All @@ -253,7 +253,8 @@ def remove_authz_file(fname):
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',
Expand All @@ -266,6 +267,7 @@ def remove_authz_file(fname):
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')

0 comments on commit 03c7df6

Please sign in to comment.