]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bus-util: Move geteuid() check out of bus_connect_system_systemd()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 9 Oct 2024 10:10:44 +0000 (12:10 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 11 Oct 2024 09:35:02 +0000 (11:35 +0200)
Let's move this check to bus_connect_transport_systemd() so that
bus_connect_system_systemd() will only ever connect to the manager
private manager bus instance and fail otherwise.

src/shared/bus-util.c

index 44ed617da8dfbd615adfce0a1e1bb008e7be0dd8..a196ba47f647c4187503837ddb9ec1e1ad36671d 100644 (file)
@@ -229,12 +229,6 @@ int bus_connect_system_systemd(sd_bus **ret_bus) {
 
         assert(ret_bus);
 
-        if (geteuid() != 0)
-                return sd_bus_default_system(ret_bus);
-
-        /* If we are root then let's talk directly to the system
-         * instance, instead of going via the bus */
-
         r = sd_bus_new(&bus);
         if (r < 0)
                 return r;
@@ -521,8 +515,13 @@ int bus_connect_transport_systemd(
                                 /* Print a friendly message when the local system is actually not running systemd as PID 1. */
                                 return log_error_errno(SYNTHETIC_ERRNO(EHOSTDOWN),
                                                        "System has not been booted with systemd as init system (PID 1). Can't operate.");
-                        return bus_connect_system_systemd(ret_bus);
 
+                        if (geteuid() == 0)
+                                /* If we are root then let's talk directly to the system
+                                 * instance, instead of going via the bus. */
+                                return bus_connect_system_systemd(ret_bus);
+
+                        return sd_bus_default_system(ret_bus);
                 default:
                         assert_not_reached();
                 }