</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-v</option></term>
+ <term><option>--validate</option></term>
+
+ <listitem><para>Request authorization from polkit. Can be used to create a temporary authorization
+ without running a command.</para>
+
+ <xi:include href="version-info.xml" xpointer="v262"/>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>--via-shell</option></term>
'(--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]'
+ '(-v --validate)'{-v,--validate}'[Request authorization from polkit]'
'(-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'
static bool arg_default_command = false;
static bool arg_remove_timestamp = false;
static bool arg_reset_timestamp = false;
+static bool arg_validate = false;
static const char *arg_unit = NULL;
static char *arg_description = NULL;
static char *arg_slice = NULL;
arg_remove_timestamp = true;
break;
+ OPTION('v', "validate", NULL, "Request temporary authorization from polkit"):
+ arg_validate = true;
+ break;
+
OPTION('u', "user", "USER", "Run as system user"):
r = free_and_strdup_warn(&arg_exec_user, opts.arg);
if (r < 0)
_cleanup_strv_free_ char **l = NULL;
char **args = option_parser_get_args(&opts);
if (!strv_isempty(args)) {
+ if (arg_validate)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Option '--validate' cannot be used with a command");
l = strv_copy(args);
if (!l)
return log_oom();
return 0;
}
+static int polkit_validate(sd_bus *bus) {
+ PolkitFlags flags = POLKIT_ALWAYS_QUERY;
+ int r;
+
+ if (arg_ask_password)
+ flags |= POLKIT_ALLOW_INTERACTIVE;
+
+ (void) polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
+ r = polkit_check_authorization(bus, (uint32_t) (flags & _POLKIT_MASK_PUBLIC), NULL);
+ if (r < 0)
+ return r;
+ if (r == 0) /* not authorized */
+ return 1;
+
+ return 0;
+}
+
static int run(int argc, char* argv[]) {
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int r;
return 0;
}
+ if (arg_validate)
+ return polkit_validate(bus);
if (arg_scope)
return start_transient_scope(bus);
if (arg_path_property)