]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd_bus_open_user_machine(): Don't shortcut without necessary env
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 17 Mar 2025 11:28:37 +0000 (12:28 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 8 Apr 2025 19:52:11 +0000 (20:52 +0100)
Don't shortcut if we don't have the necessary environment variables
set in sd_bus_open_user_machine().

(cherry picked from commit 9e34c34b7b027da24b084a58246c1d88bdbcc817)
(cherry picked from commit bd06aa555603f877774942dcda4664e8e44f21fd)

src/libsystemd/sd-bus/sd-bus.c

index 1a642cb19783104c71ddc61b72f796a4ce4a17af..31be9f3ccb662fb50eb6ca8be23564b3c95b3250 100644 (file)
@@ -1760,8 +1760,10 @@ _public_ int sd_bus_open_user_machine(sd_bus **ret, const char *user_and_machine
         assert_return(user_and_machine, -EINVAL);
         assert_return(ret, -EINVAL);
 
-        /* Shortcut things if we'd end up on this host and as the same user.  */
-        if (user_and_machine_equivalent(user_and_machine))
+        /* Shortcut things if we'd end up on this host and as the same user and have one of the necessary
+         * environment variables set already.  */
+        if (user_and_machine_equivalent(user_and_machine) &&
+            (secure_getenv("DBUS_SESSION_BUS_ADDRESS") || secure_getenv("XDG_RUNTIME_DIR")))
                 return sd_bus_open_user(ret);
 
         r = user_and_machine_valid(user_and_machine);