]> 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)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 19 Mar 2025 09:01:19 +0000 (10:01 +0100)
Don't shortcut if we don't have the necessary environment variables
set in sd_bus_open_user_machine().

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

index 7c6183d1bbd157645135f1766d56016b3e9b7989..6429267843c95047114aee2ca4b01c57a700d59d 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);