From 994a42a0967e2f7624462cbb895e71a418bc277b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 4 Jun 2025 18:28:35 +0200 Subject: [PATCH] run: chop off username from --machine= argument before calling OpenMachinePTY() 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 | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/run/run.c b/src/run/run.c index 5a9476f13f6..27e09cd2db6 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -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)); -- 2.47.3