From 762954c14910b96022d8718ee2b8e3cd2f2587c1 Mon Sep 17 00:00:00 2001 From: Narrat Date: Thu, 4 Sep 2025 12:15:20 +0200 Subject: [PATCH 1/3] _sudo: fix formatting mix of tabs and whitespaces --- tomb | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tomb b/tomb index 671f4075..7fac4a2d 100755 --- a/tomb +++ b/tomb @@ -139,29 +139,29 @@ _sudo() { esac else - if [[ "`id -u`" = "0" ]]; then + if [[ "`id -u`" = "0" ]]; then _verbose "Super user execution skipped (SUID caller)" ${@} return $? - elif _is_found sudo; then - local msg="[sudo] Enter password for user ::1 user:: to gain superuser privileges" - _is_found gettext && msg="$(gettext -s "$msg")" - msg=${(S)msg//::1*::/$USER} - [[ -n "$SUDO_ASKPASS" ]] && local sudo_askpass="--askpass" - sudo $sudo_askpass -p " + elif _is_found sudo; then + local msg="[sudo] Enter password for user ::1 user:: to gain superuser privileges" + _is_found gettext && msg="$(gettext -s "$msg")" + msg=${(S)msg//::1*::/$USER} + [[ -n "$SUDO_ASKPASS" ]] && local sudo_askpass="--askpass" + sudo $sudo_askpass -p " $msg " ${@} - return $? - elif _is_found doas; then - local msg="Enter password for user ::1 user:: to gain superuser privileges" - _is_found gettext && msg="$(gettext -s "$msg")" - msg=${(S)msg//::1*::/$USER} - doas ${@} - return $? - else - _failure "No way found to escalate privileges to super user." - fi + return $? + elif _is_found doas; then + local msg="Enter password for user ::1 user:: to gain superuser privileges" + _is_found gettext && msg="$(gettext -s "$msg")" + msg=${(S)msg//::1*::/$USER} + doas ${@} + return $? + else + _failure "No way found to escalate privileges to super user." + fi fi } From 08c1236903e06649d377bef92749e2def46a53d4 Mon Sep 17 00:00:00 2001 From: Narrat Date: Thu, 4 Sep 2025 15:06:50 +0200 Subject: [PATCH 2/3] _sudo: unify branches into a singular flow If --sudo was supplied it would behave differently than without. More verbose, different output, but in general the same behaviour as without. Additionally "--sudo sudo" wasn't working. Now this is organized in one branch instead of two. Has the benefit that instead of a direct failure when the argument of "--sudo" isn't found, it will then fallback to sudo and doas. Both tools were checked upon if --sudo wasn't used and counted as defaults. Additionally adjust the man page in that regard. --- doc/tomb.1 | 9 ++++-- tomb | 81 +++++++++++++++++++++++++++--------------------------- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/doc/tomb.1 b/doc/tomb.1 index c7703cef..7ffe5729 100644 --- a/doc/tomb.1 +++ b/doc/tomb.1 @@ -325,8 +325,8 @@ takes massively longer on regular systems. Default is 1 thread (based on the \fIargon2\fR default). .B .IP "--sudo \fI\fR" -Select a different tool than sudo for privilege escalation. -Alternatives supported so far are: pkexec, doas, sup, sud. For any +Select a different tool than sudo or doas for privilege escalation. +Alternatives supported so far are: pkexec, sup, sud. For any alternative to work the executable must be included in the current PATH. @@ -419,7 +419,8 @@ user. Tomb executes as super user only when required. To be made available on multi user systems, the superuser execution of the tomb script can be authorized for users without jeopardizing the -whole system's security: just add such a line to \fI/etc/sudoers\fR: +whole system's security: In case of sudo just add such a line to +\fI/etc/sudoers\fR: .EX username ALL=NOPASSWD: /usr/local/bin/tomb @@ -432,6 +433,8 @@ To avoid that tomb execution is logged by \fIsyslog\fR also add: Defaults!TOMB !syslog .EE +Different tools require other settings to achieve something similar. + .SH PASSWORD INPUT Password input is handled by the pinentry program: it can be text diff --git a/tomb b/tomb index 7fac4a2d..f046a073 100755 --- a/tomb +++ b/tomb @@ -118,51 +118,50 @@ export TEXTDOMAIN=tomb # Wrap sudo with a more visible message or apply user-supplied alternative to sudo _sudo() { - if option_is_set --sudo; then - pescmd=`option_value --sudo` - case `basename $pescmd` in - "doas"|"sup"|"sud"|"pkexec") - - _is_found $pescmd || _failure "::1 pesc:: executable not found" $pescmd - _verbose "Super user execution using ::1 pesc::" $pescmd - ${pescmd} ${@} - return $? - ;; - "skip"|"none") - _verbose "Super user execution skipped (SUID caller)" - ${@} - return $? - ;; - *) - _failure "Super user execution not supported: ::1 sudo::" "`option_value --sudo`" - ;; - esac + local -a pescmds pe_extras + local pescmd - else - if [[ "`id -u`" = "0" ]]; then - _verbose "Super user execution skipped (SUID caller)" - ${@} - return $? - elif _is_found sudo; then - local msg="[sudo] Enter password for user ::1 user:: to gain superuser privileges" - _is_found gettext && msg="$(gettext -s "$msg")" - msg=${(S)msg//::1*::/$USER} + [[ "`id -u`" = "0" ]] && { + _verbose "Super user execution skipped (SUID caller)" + ${@} + return $? + } + + option_is_set --sudo && { + pescmds=(`option_value --sudo`) + } + pescmds+=("sudo" "doas") + + for cmd in "${pescmds[@]}"; do + _is_found $cmd && { pescmd=$cmd; break } + done + [[ -z ${pescmd} ]] && + _failure "Couldn't find a viable privilege escalation tool." + + # Construct message for the tools that allow custom prompts + local msg="Enter password for user ::1 user:: to gain superuser privileges" + _is_found gettext && msg="$(gettext -s "$msg")" + msg=${(S)msg//::1*::/$USER} + + # Adjust call in regards of the chosen tool + case `basename $pescmd` in + "sudo") [[ -n "$SUDO_ASKPASS" ]] && local sudo_askpass="--askpass" - sudo $sudo_askpass -p " + pe_extras=("-p" " $msg +") + ;; + "doas"|"sup"|"sud"|"pkexec") + ;; + *) + _failure "Super user execution not supported: ::1 sudo::" "`option_value --sudo`" + ;; + esac -" ${@} - return $? - elif _is_found doas; then - local msg="Enter password for user ::1 user:: to gain superuser privileges" - _is_found gettext && msg="$(gettext -s "$msg")" - msg=${(S)msg//::1*::/$USER} - doas ${@} - return $? - else - _failure "No way found to escalate privileges to super user." - fi - fi + # Execute stuff + _verbose "Super user execution using ::1 pesc::" $pescmd + ${pescmd} $sudo_askpass $pe_extras ${@} + return $? } # Cleanup anything sensitive before exiting. From 667d89c07c9ae3e75dcaaa74e0f0d10cd5497565 Mon Sep 17 00:00:00 2001 From: Narrat Date: Thu, 4 Sep 2025 15:57:51 +0200 Subject: [PATCH 3/3] --sudo: Allow sudo-rs --- doc/tomb.1 | 2 +- tomb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/tomb.1 b/doc/tomb.1 index 7ffe5729..3a457076 100644 --- a/doc/tomb.1 +++ b/doc/tomb.1 @@ -326,7 +326,7 @@ Default is 1 thread (based on the \fIargon2\fR default). .B .IP "--sudo \fI\fR" Select a different tool than sudo or doas for privilege escalation. -Alternatives supported so far are: pkexec, sup, sud. For any +Alternatives supported so far are: pkexec, sup, sud, sudo-rs. For any alternative to work the executable must be included in the current PATH. diff --git a/tomb b/tomb index f046a073..a26799ee 100755 --- a/tomb +++ b/tomb @@ -151,6 +151,9 @@ _sudo() { $msg ") ;; + "sudo-rs") + pe_extras=("-p" "$msg") + ;; "doas"|"sup"|"sud"|"pkexec") ;; *)