Elevate blob-network-dns from its own path

This commit is contained in:
SirBlob committed 2026-11-01 19:40:39 -05:00
1 parent 6a3608e7bc
commit 8ef25d0d31
1 file changed
+4 -21
+4 -21
View File
@@ -40,32 +40,15 @@ provider_from_arg() {
esac
}
# The path etc/sudoers.d/blob-network-dns names. The privileged half always runs from
# there rather than from whichever copy was invoked, so the rule matches even
# where $BLOB_PATH points at a checkout.
PACKAGED_PATH=/usr/bin/blob-network-dns
# True when sudo would run this exact command without stopping for a password.
# `sudo -l` on its own reports whether a command is permitted, which the blanket
# %wheel rule answers yes to for everything; the long listing prints the matched
# entry's tags, so !authenticate is the grant in etc/sudoers.d/blob-network-dns and
# nothing else. Listing runs nothing and, under -n, prompts for nothing, so a
# machine whose blob-settings predates that file falls through to polkit
# instead of dying on a password prompt it has no terminal to show.
sudo_grants_passwordless() {
sudo -n -l -l "$PACKAGED_PATH" "$@" 2>/dev/null | grep -q '!authenticate'
}
script_path=$(readlink -f "${BASH_SOURCE[0]}")
require_root() {
if (( EUID == 0 )); then
return
elif [[ -t 0 ]] || sudo_grants_passwordless "$@"; then
# A terminal can carry sudo's own password prompt. Without one, sudo is
# right only where the grant reaches; polkit can at least put a prompt on
# screen, and offer to authenticate as someone else.
exec sudo "$PACKAGED_PATH" "$@"
elif [[ -t 0 ]]; then
exec sudo "$script_path" "$@"
else
exec pkexec "$PACKAGED_PATH" "$@"
exec pkexec "$script_path" "$@"
fi
}