diff options
-rw-r--r-- | dbus/dbus-sysdeps-unix.c | 34 |
1 files changed, 9 insertions, 25 deletions
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 60bdc6f7..4dfdf549 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -2727,12 +2727,12 @@ fill_user_info (DBusUserInfo *info, * checks */ -#ifdef HAVE_GETPWNAM_R { struct passwd *p; + char *buf = NULL; +#ifdef HAVE_GETPWNAM_R int result; size_t buflen; - char *buf; struct passwd p_str; /* retrieve maximum needed size for buf */ @@ -2773,43 +2773,27 @@ fill_user_info (DBusUserInfo *info, break; } } - if (result == 0 && p == &p_str) - { - if (!fill_user_info_from_passwd (p, info, error)) - { - dbus_free (buf); - return FALSE; - } - dbus_free (buf); - } - 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 : "???"); - dbus_free (buf); - return FALSE; - } - } + + if (result != 0 || p != &p_str) + p = NULL; #else /* ! HAVE_GETPWNAM_R */ - { /* I guess we're screwed on thread safety here */ - struct passwd *p; - #warning getpwnam_r() not available, please report this to the dbus maintainers with details of your OS if (uid != DBUS_UID_UNSET) p = getpwuid (uid); else p = getpwnam (username_c); +#endif /* ! HAVE_GETPWNAM_R */ if (p != NULL) { if (!fill_user_info_from_passwd (p, info, error)) { + dbus_free (buf); return FALSE; } + dbus_free (buf); } else { @@ -2817,10 +2801,10 @@ fill_user_info (DBusUserInfo *info, "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 : "???"); + dbus_free (buf); return FALSE; } } -#endif /* ! HAVE_GETPWNAM_R */ /* Fill this in so we can use it to get groups */ username_c = info->username; |