]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
Handle missing user when installing setuid in meson_post_install.py
authorJordan Williams <jordan@jwillikers.com>
Wed, 6 Mar 2024 14:32:34 +0000 (08:32 -0600)
committerSimon McVittie <smcv@collabora.com>
Tue, 1 Oct 2024 16:23:02 +0000 (16:23 +0000)
The logic that sets the dbus-daemon-launcher-helper setuid does not
handle the case where the group named the same as the dbus_user does not
exist.
This makes the assumption that the primary group of the dbus_user
has the same name as the dbus_user.
This may not be the case.

To remedy these issues, obtain the group id for dbus_user instead of
attempting to retrieve the group id by name.
To avoid a failure when the user does not exist, handle the KeyError
exception from the pwd.getpwnam function by printing a warning and
skipping the logic to set the binary setuid.
Perform an additional check to ensure that the dbus_user's primary group
 has only a single member.
Fail similarly if it has more than one member.

Resolves: #492
Signed-off-by: Simon McVittie <smcv@collabora.com>
meson_post_install.py

index cfc03b2219ff71af685798613133c510cd57b1a7..fe0633458c4f194b59d4e8a8c43079626a3ea503 100755 (executable)
@@ -88,11 +88,35 @@ def post_install_exe():
     daemon_launch_helper = get_target('dbus-daemon-launch-helper')
     if daemon_launch_helper:
         import grp
+        import pwd
         exe_name = os.path.basename(daemon_launch_helper['install_filename'][0])
         exe_path = abs_libexecdir / exe_name
         dbus_user = get_option('dbus_user')
         if os.getuid() == 0:
-            os.chown(exe_path, 0, grp.getgrnam(dbus_user).gr_gid)
+            dbus_user_data = None
+            try:
+                dbus_user_data = pwd.getpwnam(dbus_user)
+            except KeyError:
+                print('Not installing {0} binary setuid!'.format(exe_path))
+                print('The dbus_user {0} does not exist!'.format(dbus_user))
+                return
+
+            dbus_group_data = None
+            try:
+                dbus_group_data = grp.getgrgid(dbus_user_data.pw_gid)
+            except KeyError:
+                print('Not installing {0} binary setuid!'.format(exe_path))
+                print('The dbus_user\'s primary group {0} does not exist!'.format(dbus_user))
+                return
+
+            if len(dbus_group_data.gr_mem) > 1:
+                print('Not installing {0} binary setuid!'.format(exe_path))
+                print('The dbus_user\'s primary group {0} contains {1} members when it '
+                      'should only contain one!'
+                      .format(dbus_user, len(dbus_group_data.gr_mem)))
+                return
+            
+            os.chown(exe_path, 0, dbus_user_data.pw_gid)
             os.chmod(exe_path, stat.S_ISUID | stat.S_IXUSR | stat.S_IXGRP)
         else:
             print('Not installing {0} binary setuid!'.format(exe_path))