Complete command-scoped authentication across update phases
This commit is contained in:
1 parent
7f9a401bb1
commit
35b318ed09
16 files changed
+583
-1643
No files matched your search
@@ -81,46 +81,55 @@ stop() {
|
||||
}
|
||||
|
||||
start() {
|
||||
local inhibit_pid=""
|
||||
local inhibit_start_time=""
|
||||
local inhibit_runner=()
|
||||
local idle_owner="$$:$RANDOM:$RANDOM"
|
||||
|
||||
stop
|
||||
mkdir -p "$state_dir"
|
||||
|
||||
if omarchy-cmd-present systemd-inhibit; then
|
||||
if (( EUID != 0 )); then
|
||||
if [[ -t 0 ]]; then
|
||||
sudo -v
|
||||
inhibit_runner=(sudo)
|
||||
else
|
||||
inhibit_runner=(pkexec)
|
||||
fi
|
||||
fi
|
||||
# sudo authenticates in the foreground, then backgrounds the inhibitor.
|
||||
# The held command drops back to this user before publishing its PID, so stop
|
||||
# can release the inhibitor without another privileged operation or ticket.
|
||||
local hold_command=(
|
||||
/usr/bin/systemd-inhibit --what=sleep:idle --who=omarchy-update
|
||||
--why="Omarchy update in progress" --mode=block
|
||||
/usr/bin/setpriv --reuid "$UID" --regid "$(id -g)" --clear-groups
|
||||
/usr/bin/bash -p -c '
|
||||
read -r process_stat <"/proc/$$/stat"
|
||||
process_stat=${process_stat##*) }
|
||||
read -r -a fields <<< "$process_stat"
|
||||
printf "%s %s\n" "$$" "${fields[19]}" >"$1"
|
||||
exec /usr/bin/sleep infinity
|
||||
' omarchy-update-inhibitor "$inhibit_pid_file"
|
||||
)
|
||||
|
||||
if [[ -n ${OMARCHY_UPDATE_LOCK_FD:-} ]]; then
|
||||
"${inhibit_runner[@]}" systemd-inhibit \
|
||||
--what=sleep:idle \
|
||||
--who=omarchy-update \
|
||||
--why="Omarchy update in progress" \
|
||||
--mode=block \
|
||||
sleep infinity >/dev/null 2>&1 {OMARCHY_UPDATE_LOCK_FD}>&- &
|
||||
else
|
||||
"${inhibit_runner[@]}" systemd-inhibit \
|
||||
--what=sleep:idle \
|
||||
--who=omarchy-update \
|
||||
--why="Omarchy update in progress" \
|
||||
--mode=block \
|
||||
sleep infinity >/dev/null 2>&1 &
|
||||
fi
|
||||
inhibit_pid=$!
|
||||
inhibit_start_time=$(process_start_time "$inhibit_pid" 2>/dev/null || true)
|
||||
if [[ -n $inhibit_start_time ]]; then
|
||||
printf '%s %s\n' "$inhibit_pid" "$inhibit_start_time" >"$inhibit_pid_file"
|
||||
fi
|
||||
if (( EUID == 0 )); then
|
||||
( [[ -z ${OMARCHY_UPDATE_LOCK_FD:-} ]] || exec {OMARCHY_UPDATE_LOCK_FD}>&-
|
||||
exec "${hold_command[@]}" ) &
|
||||
elif [[ -t 0 ]]; then
|
||||
sudo -N -b -- "${hold_command[@]}"
|
||||
else
|
||||
( [[ -z ${OMARCHY_UPDATE_LOCK_FD:-} ]] || exec {OMARCHY_UPDATE_LOCK_FD}>&-
|
||||
exec pkexec "${hold_command[@]}" ) &
|
||||
fi
|
||||
|
||||
# For graphical authentication the launcher may wait for a password. Wait for
|
||||
# either the user-owned held command to become ready or the launcher to fail.
|
||||
local launcher_pid=${!:-}
|
||||
local readiness_attempts=0
|
||||
while [[ ! -s $inhibit_pid_file ]]; do
|
||||
if [[ -n $launcher_pid ]] && ! kill -0 "$launcher_pid" 2>/dev/null; then
|
||||
wait "$launcher_pid" || return 1
|
||||
echo "The update sleep inhibitor did not start." >&2
|
||||
return 1
|
||||
fi
|
||||
readiness_attempts=$((readiness_attempts + 1))
|
||||
if [[ -t 0 ]] && (( EUID != 0 && readiness_attempts >= 100 )); then
|
||||
echo "The update sleep inhibitor did not become ready." >&2
|
||||
return 1
|
||||
fi
|
||||
sleep 0.05
|
||||
done
|
||||
|
||||
if [[ ! -f $stay_awake_state ]]; then
|
||||
printf '%s\n' "$idle_owner" >"$idle_owner_file"
|
||||
mkdir -p "$(dirname "$stay_awake_state")"
|
||||
|
||||
Reference in new issue
Block a user