#include "util.h"
#include "macro.h"
#include "pager.h"
+#include "spawn-polkit-agent.h"
#include "bus-util.h"
#include "bus-error.h"
#include "build.h"
static bool arg_read_only = false;
static bool arg_mkdir = false;
static bool arg_quiet = false;
+static bool arg_ask_password = true;
static unsigned arg_lines = 10;
static OutputMode arg_output = OUTPUT_SHORT;
pager_open(false);
}
+static void polkit_agent_open_if_enabled(void) {
+
+ /* Open the polkit agent as a child process if necessary */
+
+ if (!arg_ask_password)
+ return;
+
+ if (arg_transport != BUS_TRANSPORT_LOCAL)
+ return;
+
+ polkit_agent_open();
+}
+
static OutputFlags get_output_flags(void) {
return
arg_all * OUTPUT_SHOW_ALL |
assert(bus);
+ polkit_agent_open_if_enabled();
+
if (!arg_kill_who)
arg_kill_who = "all";
assert(bus);
+ polkit_agent_open_if_enabled();
+
for (i = 1; i < argc; i++) {
int r;
return -ENOTSUP;
}
+ polkit_agent_open_if_enabled();
+
r = sd_event_default(&event);
if (r < 0)
return log_error_errno(r, "Failed to get event loop: %m");
if (r < 0)
return bus_log_create_error(r);
- r = sd_bus_message_set_allow_interactive_authorization(m, true);
+ r = sd_bus_message_set_allow_interactive_authorization(m, arg_ask_password);
if (r < 0)
return bus_log_create_error(r);
assert(bus);
+ polkit_agent_open_if_enabled();
+
for (i = 1; i < argc; i++) {
r = sd_bus_call_method(
bus,
sd_bus *bus = userdata;
int r;
+ polkit_agent_open_if_enabled();
+
r = sd_bus_call_method(
bus,
"org.freedesktop.machine1",
sd_bus *bus = userdata;
int r;
+ polkit_agent_open_if_enabled();
+
r = sd_bus_call_method(
bus,
"org.freedesktop.machine1",
}
}
+ polkit_agent_open_if_enabled();
+
r = sd_bus_call_method(
bus,
"org.freedesktop.machine1",
assert(bus);
+ polkit_agent_open_if_enabled();
+
r = bus_wait_for_jobs_new(bus, &w);
if (r < 0)
return log_oom();
if (r < 0)
return bus_log_create_error(r);
- r = sd_bus_message_set_allow_interactive_authorization(m, true);
+ r = sd_bus_message_set_allow_interactive_authorization(m, arg_ask_password);
if (r < 0)
return bus_log_create_error(r);
assert(bus);
+ polkit_agent_open_if_enabled();
+
method = streq(argv[0], "enable") ? "EnableUnitFiles" : "DisableUnitFiles";
r = sd_bus_message_new_method_call(
if (r < 0)
return bus_log_create_error(r);
- r = sd_bus_message_set_allow_interactive_authorization(m, true);
+ r = sd_bus_message_set_allow_interactive_authorization(m, arg_ask_password);
if (r < 0)
return bus_log_create_error(r);
if (r < 0)
return bus_log_create_error(r);
- r = sd_bus_message_set_allow_interactive_authorization(m, true);
+ r = sd_bus_message_set_allow_interactive_authorization(m, arg_ask_password);
if (r < 0)
return bus_log_create_error(r);
" --version Show package version\n"
" --no-pager Do not pipe output into a pager\n"
" --no-legend Do not show the headers and footers\n"
+ " --no-ask-password Do not ask for system passwords\n"
" -H --host=[USER@]HOST Operate on remote host\n"
" -M --machine=CONTAINER Operate on local container\n"
" -p --property=NAME Show only properties by this name\n"
ARG_KILL_WHO,
ARG_READ_ONLY,
ARG_MKDIR,
+ ARG_NO_ASK_PASSWORD,
};
static const struct option options[] = {
{ "quiet", no_argument, NULL, 'q' },
{ "lines", required_argument, NULL, 'n' },
{ "output", required_argument, NULL, 'o' },
+ { "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD },
{}
};
}
break;
+ case ARG_NO_ASK_PASSWORD:
+ arg_ask_password = false;
+ break;
+
case 'H':
arg_transport = BUS_TRANSPORT_REMOTE;
arg_host = optarg;
finish:
pager_close();
+ polkit_agent_close();
strv_free(arg_property);