Blame SOURCES/0195-sd-bus-allow-connecting-to-the-pseudo-container-.hos.patch

a3e2b5
From 6bf178a9a6e3fd6544d8e37a0082febf81c0ad2d Mon Sep 17 00:00:00 2001
a3e2b5
From: Lennart Poettering <lennart@poettering.net>
a3e2b5
Date: Tue, 17 Jul 2018 12:23:26 +0200
a3e2b5
Subject: [PATCH] sd-bus: allow connecting to the pseudo-container ".host"
a3e2b5
a3e2b5
machined exposes the pseudo-container ".host" as a reference to the host
a3e2b5
system, and this means "machinectl login .host" and "machinectl shell
a3e2b5
.host" get your a login/shell on the host. systemd-run currently doesn't
a3e2b5
allow that. Let's fix that, and make sd-bus understand ".host" as an
a3e2b5
alias for connecting to the host system.
a3e2b5
a3e2b5
(cherry picked from commit 1e5057b904473696ae0d591d7555233adcb51fa4)
a3e2b5
a3e2b5
Resolves: #1683334
a3e2b5
---
a3e2b5
 src/basic/util.c               | 5 +++++
a3e2b5
 src/libsystemd/sd-bus/sd-bus.c | 4 ++--
a3e2b5
 2 files changed, 7 insertions(+), 2 deletions(-)
a3e2b5
a3e2b5
diff --git a/src/basic/util.c b/src/basic/util.c
a3e2b5
index 8f2d6061da..82cb937314 100644
a3e2b5
--- a/src/basic/util.c
a3e2b5
+++ b/src/basic/util.c
a3e2b5
@@ -255,6 +255,11 @@ int container_get_leader(const char *machine, pid_t *pid) {
a3e2b5
         assert(machine);
a3e2b5
         assert(pid);
a3e2b5
 
a3e2b5
+        if (streq(machine, ".host")) {
a3e2b5
+                *pid = 1;
a3e2b5
+                return 0;
a3e2b5
+        }
a3e2b5
+
a3e2b5
         if (!machine_name_is_valid(machine))
a3e2b5
                 return -EINVAL;
a3e2b5
 
a3e2b5
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
a3e2b5
index 7f03528b89..f53a98d6bf 100644
a3e2b5
--- a/src/libsystemd/sd-bus/sd-bus.c
a3e2b5
+++ b/src/libsystemd/sd-bus/sd-bus.c
a3e2b5
@@ -952,7 +952,7 @@ static int parse_container_unix_address(sd_bus *b, const char **p, char **guid)
a3e2b5
                 return -EINVAL;
a3e2b5
 
a3e2b5
         if (machine) {
a3e2b5
-                if (!machine_name_is_valid(machine))
a3e2b5
+                if (!streq(machine, ".host") && !machine_name_is_valid(machine))
a3e2b5
                         return -EINVAL;
a3e2b5
 
a3e2b5
                 free_and_replace(b->machine, machine);
a3e2b5
@@ -1450,7 +1450,7 @@ _public_ int sd_bus_open_system_machine(sd_bus **ret, const char *machine) {
a3e2b5
 
a3e2b5
         assert_return(machine, -EINVAL);
a3e2b5
         assert_return(ret, -EINVAL);
a3e2b5
-        assert_return(machine_name_is_valid(machine), -EINVAL);
a3e2b5
+        assert_return(streq(machine, ".host") || machine_name_is_valid(machine), -EINVAL);
a3e2b5
 
a3e2b5
         r = sd_bus_new(&b);
a3e2b5
         if (r < 0)