2019-10-21 05:46:49 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-05-10 23:18:36 -04:00
|
|
|
## Copyright (C) 2019 - 2024 ENCRYPTED SUPPORT LP <adrelanos@whonix.org>
|
2019-10-21 05:46:49 -04:00
|
|
|
## See the file COPYING for copying conditions.
|
|
|
|
|
|
|
|
## Redirect calls for pkexec to lxqt-sudo because pkexec is incompatible with
|
|
|
|
## hidepid.
|
|
|
|
## * https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=860040
|
|
|
|
## * https://forums.whonix.org/t/cannot-use-pkexec/8129
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2020-01-15 02:42:10 -05:00
|
|
|
my_real_path="$(realpath "$0")" || true
|
|
|
|
identifier="$my_real_path wrapper"
|
|
|
|
exec > >(systemd-cat --identifier="$identifier output by program:") 2>&1
|
|
|
|
|
|
|
|
log_to_journal() {
|
|
|
|
echo "$@" | systemd-cat --identifier="$identifier output by wrapper:" || true
|
|
|
|
}
|
|
|
|
|
|
|
|
log_to_journal "$0 $@"
|
|
|
|
log_to_journal "DISPLAY: '$DISPLAY'"
|
2020-01-14 15:04:58 -05:00
|
|
|
my_pstree="$(pstree -p $$)" || true
|
2020-01-15 02:42:10 -05:00
|
|
|
log_to_journal "my_pstree: '$my_pstree'"
|
2020-01-14 15:04:58 -05:00
|
|
|
|
2019-10-21 05:46:49 -04:00
|
|
|
## If hidepid is not in use, just use pkexec normally.
|
2019-10-22 08:54:48 -04:00
|
|
|
if ! mount | grep "/proc" | grep "hidepid=2" &>/dev/null ; then
|
2019-10-21 05:46:49 -04:00
|
|
|
pkexec.security-misc-orig "$@"
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
|
2020-01-15 02:42:10 -05:00
|
|
|
switch_user=false
|
2019-10-21 05:46:49 -04:00
|
|
|
|
|
|
|
original_args="$@"
|
|
|
|
|
|
|
|
## Thanks to:
|
2024-07-17 09:44:37 -04:00
|
|
|
## https://mywiki.wooledge.org/BashFAQ/035
|
2019-10-21 05:46:49 -04:00
|
|
|
|
|
|
|
while :
|
|
|
|
do
|
|
|
|
case $1 in
|
|
|
|
## Should show 'pkexec --version' or fail?
|
|
|
|
--version)
|
|
|
|
shift
|
|
|
|
pkexec.security-misc-orig "$original_args"
|
|
|
|
exit $?
|
|
|
|
;;
|
|
|
|
## Should show 'pkexec --help' or fail?
|
|
|
|
--help)
|
|
|
|
shift
|
|
|
|
pkexec.security-misc-orig "$original_args"
|
|
|
|
exit $?
|
|
|
|
;;
|
|
|
|
## Drop --disable-internal-agent as not needed and breaking both,
|
|
|
|
## lxqt-sudo and sudo.
|
|
|
|
--disable-internal-agent)
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--user)
|
|
|
|
## lxqt-sudo does not support "--user".
|
|
|
|
## We should not make this wrapper run something as root which
|
|
|
|
## is supposed to run under a different user. Try using
|
|
|
|
## "sudo -A --user user --set-home" instead.
|
|
|
|
user_pkexec_wrapper="$2"
|
|
|
|
if [ "$user_pkexec_wrapper" = "" ]; then
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
shift 2
|
|
|
|
fi
|
2020-01-15 02:42:10 -05:00
|
|
|
switch_user=true
|
|
|
|
maybe_switch_to_user="--user $user_pkexec_wrapper"
|
2019-10-21 05:46:49 -04:00
|
|
|
;;
|
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
## If there are input files (for example) that follow the options, they
|
|
|
|
## will remain in the "$@" positional parameters.
|
|
|
|
|
2020-01-15 02:42:10 -05:00
|
|
|
if [ "$PKEXEC_UID" = "" ]; then
|
|
|
|
if [ ! "$user_pkexec_wrapper" = "" ]; then
|
|
|
|
PKEXEC_UID="$user_pkexec_wrapper"
|
|
|
|
elif [ ! "$SUDO_USER" = "" ]; then
|
|
|
|
PKEXEC_UID="$SUDO_USER"
|
|
|
|
else
|
|
|
|
PKEXEC_UID="$(whoami)"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
export PKEXEC_UID
|
|
|
|
|
2019-10-21 05:46:49 -04:00
|
|
|
if [[ "$@" = "" ]]; then
|
|
|
|
## Call original pkexec in case there are no arguments.
|
2019-10-22 09:22:29 -04:00
|
|
|
pkexec.security-misc-orig $original_args
|
2019-10-21 05:46:49 -04:00
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
|
2020-01-14 15:04:58 -05:00
|
|
|
exit_code=0
|
2020-01-15 02:42:10 -05:00
|
|
|
|
|
|
|
## lxqt-sudo does not check /etc/sudoers / /etc/sudoers.d exceptions.
|
|
|
|
## Therefore use 'sudo -l' to see if there is any already existing sudoers exception.
|
2020-02-29 04:59:56 -05:00
|
|
|
## Did not work. 'sudo -l' will always exit with exit code '0'.
|
|
|
|
# if sudo -l --non-interactive $maybe_switch_to_user --set-home PKEXEC_UID="$PKEXEC_UID" "$@" ; then
|
|
|
|
# log_to_journal "sudoers exception: yes"
|
|
|
|
# sudo --non-interactive $maybe_switch_to_user --set-home PKEXEC_UID="$PKEXEC_UID" "$@" || { exit_code=$? ; true; };
|
|
|
|
# log_to_journal "sudo --user | exit_code: '$exit_code'"
|
|
|
|
# exit "$exit_code"
|
|
|
|
# fi
|
|
|
|
#
|
|
|
|
# log_to_journal "sudoers exception: no"
|
2020-01-15 02:42:10 -05:00
|
|
|
|
|
|
|
if [ "$switch_user" = "true" ]; then
|
|
|
|
## 'sudo --user user' clears environment variables such as PATH.
|
|
|
|
lxqt-sudo sudo $maybe_switch_to_user --set-home PKEXEC_UID="$PKEXEC_UID" "$@" || { exit_code=$? ; true; };
|
2019-10-21 05:46:49 -04:00
|
|
|
else
|
2020-01-14 15:12:13 -05:00
|
|
|
## set PATH same as root
|
|
|
|
## This is required for gdebi.
|
|
|
|
## REVIEW: is it ok that users can find out the PATH setting of root?
|
2020-01-15 02:42:10 -05:00
|
|
|
## lxqt-sudo does not clear environment variable PATH.
|
2021-08-03 12:56:31 -04:00
|
|
|
PATH="$(sudo --non-interactive /usr/libexec/security-misc/echo-path)"
|
2020-01-14 15:12:13 -05:00
|
|
|
export PATH
|
2020-01-14 15:04:58 -05:00
|
|
|
lxqt-sudo "$@" || { exit_code=$? ; true; };
|
2019-10-21 05:46:49 -04:00
|
|
|
fi
|
2020-01-14 15:04:58 -05:00
|
|
|
|
2020-01-15 02:42:10 -05:00
|
|
|
log_to_journal "exit_code: '$exit_code'"
|
2020-01-14 15:04:58 -05:00
|
|
|
|
|
|
|
exit "$exit_code"
|