[PATCH] fill_user_info: fake user info for 'root' if it can not be found

Simon McVittie simon.mcvittie at collabora.co.uk
Mon Feb 25 10:03:06 PST 2013


On 25/02/13 15:14, Tom Gundersen wrote:
> This should make make libdbus a bit more robust against bugs or configuration
> errors. In particular, it should make it work on an empty /etc or in case nss is
> broken, misconfigured or simply missing.

This doesn't seem like something that ought to be wired into every
sufficiently-low-level library and utility: if it needs to be
configurable, then it needs to be configurable, and if it doesn't,
shouldn't libc do this for you?

Alternatively, have you considered using a NSS module that "knows who
root is", analogous to nss-myhostname?

If none of the alternatives are viable, please open a bug on
bugs.freedesktop.org so this doesn't get lost.

Some quick comments on the implementation:

In this situation, don't you fail anyway, further down the function,
when you getgrouplist() and it doesn't work?

> +    //Make sure 'root' always exists, even if nss is not configured correctly

D-Bus is C89: no C++-style comments, please.

> +    if ((result != 0 || p != &p_str) && (uid == 0 || strcmp(username_c, "root") == 0))
> +      {
> +        _dbus_warn ("Failed to find 'root' user, use fallback entry.");

If this is considered to be normal, it shouldn't warn.

> +        p_str.pw_name = "root";
> +        p_str.pw_passwd = "x";

I'd prefer to populate @info directly, rather than populating a struct
passwd and then copying it into @info.

You could probably benefit from a fill_user_info_for_root() helper
shared between the HAVE_GETPWNAM_R and !HAVE_GETPWNAM_R code paths.


More information about the dbus mailing list