Skip to content

sysdeps: Improve error reporting for looking up a user

Simon McVittie requested to merge smcv/dbus:issue343-3 into master

Requires !417 (merged), please review that first.

  • sysdeps-unix: Deduplicate error handling for getpwnam and getpwnam_r

    The only difference between these was that we only needed to allocate and free buf in the getpwnam_r case. We expect that all reasonable Unix platforms will have getpwnam_r (it's in POSIX) so adding a no-op dbus_free(NULL) to the getpwnam code path seems harmless.

    This will be helpful when we make the error handling better, in a subsequent commit.

    Helps: #343 (closed)

  • 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: #343 (closed)

  • sysdeps: Improve error reporting for looking up a user

    Our implementation always assumed that both code paths set errno, but according to their API documentation, getpwnam_r and getpwuid_r actually don't: they return a code from the same pseudo-enum as errno. They also return 0 (but with a NULL struct passwd) if the user is not found, which these APIs don't count as an error (but we do).

    Similarly, in the legacy getpwnam/getpwuid code path, it is unspecified whether looking up a nonexistent user will set errno or not.

    Having retrieved an errno-like error code, we might as well use it in the human-readable message and not just the machine-readable code, because the human-readable message is what ends up in the system log.

    Helps: #343 (closed)

  • userdb: Use "goto out" pattern for _dbus_groups_from_uid()

    This makes it easier to verify that _dbus_user_database_unlock_system() is called on all exit paths. The only early-return is when locking the userdb failed.


I'm probably not going to backport this to 1.14.x unless someone thinks it's important to do so. Definitely not 1.12.x material.

Edited by Simon McVittie

Merge request reports