diff options
author | Simon McVittie <smcv@collabora.com> | 2023-06-29 17:03:51 +0100 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2023-08-21 13:49:31 +0000 |
commit | 12b367daaaabab838537bfbe8164f095a6294ec3 (patch) | |
tree | d30627a19953be32a1a181d0879d1da7696c4407 | |
parent | 80b90e570e0cc950491aaeacb008b101922d8a57 (diff) |
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 <smcv@collabora.com>
-rw-r--r-- | dbus/dbus-sysdeps-unix.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 4dfdf549..d08516ab 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; } |