Elevate blob-network-dns from its own path
This commit is contained in:
1 parent
6a3608e7bc
commit
8ef25d0d31
1 file changed
+4
-21
+4
-21
@@ -40,32 +40,15 @@ provider_from_arg() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# The path etc/sudoers.d/blob-network-dns names. The privileged half always runs from
|
script_path=$(readlink -f "${BASH_SOURCE[0]}")
|
||||||
# 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'
|
|
||||||
}
|
|
||||||
|
|
||||||
require_root() {
|
require_root() {
|
||||||
if (( EUID == 0 )); then
|
if (( EUID == 0 )); then
|
||||||
return
|
return
|
||||||
elif [[ -t 0 ]] || sudo_grants_passwordless "$@"; then
|
elif [[ -t 0 ]]; then
|
||||||
# A terminal can carry sudo's own password prompt. Without one, sudo is
|
exec sudo "$script_path" "$@"
|
||||||
# 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" "$@"
|
|
||||||
else
|
else
|
||||||
exec pkexec "$PACKAGED_PATH" "$@"
|
exec pkexec "$script_path" "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user