]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run: chop off username from --machine= argument before calling OpenMachinePTY()
authorLennart Poettering <lennart@poettering.net>
Wed, 4 Jun 2025 16:28:35 +0000 (18:28 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 5 Jun 2025 10:45:37 +0000 (12:45 +0200)
Let's be compatible with sd-bus' logic to talk to machine, and support
the usual user@host syntax. We only want the host part, hence chop if
off before passing it to OpenMachinePTY().

Fixes: #32997
src/run/run.c

index 5a9476f13f6995c162fdaa6cb267201f637d2ae6..27e09cd2db6d2993ddf479bd25fabf10d6ca0a49 100644 (file)
@@ -36,6 +36,7 @@
 #include "format-table.h"
 #include "format-util.h"
 #include "fs-util.h"
+#include "hostname-util.h"
 #include "log.h"
 #include "main-func.h"
 #include "osc-context.h"
@@ -2358,12 +2359,20 @@ static int start_transient_service(sd_bus *bus) {
 
                         (void) sd_bus_set_allow_interactive_authorization(system_bus, arg_ask_password);
 
-                        r = bus_call_method(system_bus,
-                                            bus_machine_mgr,
-                                            "OpenMachinePTY",
-                                            &error,
-                                            &pty_reply,
-                                            "s", arg_host);
+                        /* Chop off a username prefix. We allow this for sd-bus machine connections, hence
+                         * support that here too. */
+                        _cleanup_free_ char *h = NULL;
+                        r = split_user_at_host(arg_host, /* ret_user= */ NULL, &h);
+                        if (r < 0)
+                                return log_error_errno(r, "Failed to split host specification '%s': %m", arg_host);
+
+                        r = bus_call_method(
+                                        system_bus,
+                                        bus_machine_mgr,
+                                        "OpenMachinePTY",
+                                        &error,
+                                        &pty_reply,
+                                        "s", h ?: ".host");
                         if (r < 0)
                                 return log_error_errno(r, "Failed to get machine PTY: %s", bus_error_message(&error, r));