run0: implement -k/-K to revoke temporary auth

This is meant to mirror sudo's -k/--reset-timestamp and
-K/--remove-timestamp options, which revoke the temporary authorization
provided by the timestamp files in /var/run/sudo/ts.

To achieve the same effect in run0, we ask polkit to revoke our
temporary authorization. If used with a command, run0 will revoke the
temporary auth and then immediately authorize the user again, just like
sudo -k. All the bus calls are completed synchronously, as they need to
complete before authorizing the user anyway.

Like sudo, the effect of -k/--reset-timestamp is to revoke only the
tmpauthz that polkit would have used to authorize the command, if
available. The -K/--remove-timestamp option will revoke all temporary
authorizations across all ttys.
This commit is contained in:
Ronan Pigott
2026-06-03 17:36:25 -07:00
committed by Luca Boccassi
parent 075036f205
commit 78b53d0132
4 changed files with 340 additions and 1 deletions

View File

@@ -38,6 +38,7 @@ _run0() {
--setenv --background
)
local OPTS="${opts_with_values[*]} -h --help -V --version --no-ask-password --slice-inherit --empower"
OPTS="$OPTS -k --reset-timestamp -K --remove-timestamp"
local i
for (( i=1; i <= COMP_CWORD; i++ )); do

View File

@@ -47,6 +47,8 @@ local -a args=(
'(--group -g)'{--group=,-g+}'[Switch to the specified group]:group:_groups'
'--nice=[Run with specified nice level]:nice value'
'(--chdir -D -i --same-root-dir)'{--chdir=,-D+}'[Run within the specified working directory]:directory:_files -/'
'(-k --reset-timestamp)'{-k,--reset-timestamp}'[Revoke temporary authorization for this terminal]'
'(-K --remove-timestamp)'{-K,--remove-timestamp}'[Revoke temporary authorizations for this user session]'
'(-i)'--via-shell"[Invoke command via target user's login shell]"
'(--via-shell --chdir -D --same-root-dir)'-i"[Shortcut for --via-shell --chdir='~']"
'*--setenv=[Set the specified environment variable in the session]:environment variable:_parameters -g "*export*" -S = -q'