From: Simon McVittie Date: Thu, 29 Jun 2023 16:03:51 +0000 (+0100) Subject: sysdeps: Give a more useful error if unable to resolve a numeric uid X-Git-Tag: dbus-1.15.8~3^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=12b367daaaabab838537bfbe8164f095a6294ec3;p=thirdparty%2Fdbus.git sysdeps: Give a more useful error if unable to resolve a numeric uid 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 --- diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 4dfdf5494..d08516ab5 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -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; }