]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
sysdeps: Give a more useful error if unable to resolve a numeric uid
authorSimon McVittie <smcv@collabora.com>
Thu, 29 Jun 2023 16:03:51 +0000 (17:03 +0100)
committerSimon McVittie <smcv@collabora.com>
Mon, 21 Aug 2023 13:49:31 +0000 (13:49 +0000)
If we want to get the struct passwd corresponding to uid 42, but we
can't, it's much better to say

    User ID "42" unknown

rather than

    User "???" unknown

Helps: https://gitlab.freedesktop.org/dbus/dbus/-/issues/343
Signed-off-by: Simon McVittie <smcv@collabora.com>
dbus/dbus-sysdeps-unix.c

index 4dfdf549413fbc0716ba99510d914505a4f829d6..d08516ab5c797fc3c41a4206fe2229f96ddfe9c3 100644 (file)
@@ -2797,10 +2797,19 @@ fill_user_info (DBusUserInfo       *info,
       }
     else
       {
-        dbus_set_error (error, _dbus_error_from_errno (errno),
-                        "User \"%s\" unknown or no memory to allocate password entry\n",
-                        username_c ? username_c : "???");
-        _dbus_verbose ("User %s unknown\n", username_c ? username_c : "???");
+        DBusError local_error = DBUS_ERROR_INIT;
+
+        if (uid != DBUS_UID_UNSET)
+          dbus_set_error (&local_error, _dbus_error_from_errno (errno),
+                          "User ID " DBUS_UID_FORMAT " unknown or no memory to allocate password entry",
+                          uid);
+        else
+          dbus_set_error (&local_error, _dbus_error_from_errno (errno),
+                          "User \"%s\" unknown or no memory to allocate password entry\n",
+                          username_c ? username_c : "???");
+
+        _dbus_verbose ("%s", local_error.message);
+        dbus_move_error (&local_error, error);
         dbus_free (buf);
         return FALSE;
       }