[systemd-devel] [PATCH 1/2] bus-util: add ssh and polkit connection methods
Simon Peeters
peeters.simon at gmail.com
Wed Oct 30 06:55:30 CET 2013
bus_connect_system_ssh is shamelessly copied from Tom Gundersen's wip
patches
---
src/libsystemd-bus/bus-util.c | 61 +++++++++++++++++++++++++++++++++++++++++++
src/libsystemd-bus/bus-util.h | 2 ++
2 files changed, 63 insertions(+)
diff --git a/src/libsystemd-bus/bus-util.c b/src/libsystemd-bus/bus-util.c
index 42374fe..464e5fb 100644
--- a/src/libsystemd-bus/bus-util.c
+++ b/src/libsystemd-bus/bus-util.c
@@ -450,3 +450,64 @@ int bus_connect_system(sd_bus **_bus) {
*_bus = bus;
return 0;
}
+
+int bus_connect_system_ssh(const char *host, sd_bus **_bus) {
+ sd_bus *bus;
+ char *p = NULL;
+ int r;
+
+ assert(_bus);
+ assert(host);
+
+ asprintf(&p, "unixexec:path=ssh,argv1=-xT,argv2=%s,argv3=systemd-stdio-bridge", host);
+ if (!p)
+ return -ENOMEM;
+
+ r = sd_bus_new(&bus);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_set_address(bus, p);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_set_bus_client(bus, true);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_start(bus);
+ if (r < 0)
+ return r;
+
+ *_bus = bus;
+ return 0;
+}
+
+int bus_connect_system_polkit(sd_bus **_bus) {
+ sd_bus *bus;
+ int r;
+
+ assert(_bus);
+
+ if (geteuid() == 0)
+ return sd_bus_open_system(_bus);
+
+ r = sd_bus_new(&bus);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_set_address(bus, "unixexec:path=pkexec,argv1=" SYSTEMD_STDIO_BRIDGE_BINARY_PATH);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_set_bus_client(bus, true);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_start(bus);
+ if (r < 0)
+ return r;
+
+ *_bus = bus;
+ return 0;
+}
diff --git a/src/libsystemd-bus/bus-util.h b/src/libsystemd-bus/bus-util.h
index cf00436..92df3c2 100644
--- a/src/libsystemd-bus/bus-util.h
+++ b/src/libsystemd-bus/bus-util.h
@@ -38,6 +38,8 @@ int bus_verify_polkit_async(sd_bus *bus, Hashmap **registry, sd_bus_message *m,
void bus_verify_polkit_async_registry_free(sd_bus *bus, Hashmap *registry);
int bus_connect_system(sd_bus **_bus);
+int bus_connect_system_ssh(const char *host, sd_bus **_bus);
+int bus_connect_system_polkit(sd_bus **_bus);
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus*, sd_bus_unref);
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_message*, sd_bus_message_unref);
--
1.8.4.2
More information about the systemd-devel
mailing list