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>
This commit is contained in:
Simon McVittie 2023-06-29 17:03:51 +01:00
parent 80b90e570e
commit 12b367daaa

View 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;
}