diff -r 26d5351649ac configure.in --- a/configure.in Wed Mar 16 19:49:27 2011 +0200 +++ b/configure.in Thu Mar 17 13:54:55 2011 +0100 @@ -379,7 +379,8 @@ setrlimit setproctitle seteuid setreuid setegid setresgid \ strtoull strtoll strtouq strtoq \ setpriority quotactl getmntent kqueue kevent backtrace_symbols \ - walkcontext dirfd clearenv malloc_usable_size glob fallocate) + walkcontext dirfd clearenv malloc_usable_size glob fallocate \ + getpwnam_r) AC_CHECK_LIB(rt, clock_gettime, [ AC_DEFINE(HAVE_CLOCK_GETTIME,, Define if you have the clock_gettime function) diff -r 26d5351649ac src/auth/userdb-passwd.c --- a/src/auth/userdb-passwd.c Wed Mar 16 19:49:27 2011 +0200 +++ b/src/auth/userdb-passwd.c Thu Mar 17 13:54:55 2011 +0100 @@ -9,12 +9,18 @@ #include "userdb-static.h" #include +#include #define USER_CACHE_KEY "%u" struct passwd_userdb_module { struct userdb_module module; struct userdb_static_template *tmpl; + +#ifdef HAVE_GETPWNAM_R + char *buf; + size_t bufsize; +#endif }; struct passwd_userdb_iterate_context { @@ -33,15 +39,35 @@ struct passwd_userdb_module *module = (struct passwd_userdb_module *)_module; struct passwd *pw; +#ifdef HAVE_GETPWNAM_R + struct passwd pw_data; + int err; +#endif auth_request_log_debug(auth_request, "passwd", "lookup"); +#ifdef HAVE_GETPWNAM_R + err = getpwnam_r(auth_request->user, &pw_data, + module->buf, module->bufsize, &pw); + if (pw == NULL) { + if (err) { + auth_request_log_error(auth_request, "passwd", "%s", + strerror(err)); + callback(USERDB_RESULT_INTERNAL_FAILURE, auth_request); + return; + } + auth_request_log_info(auth_request, "passwd", "unknown user"); + callback(USERDB_RESULT_USER_UNKNOWN, auth_request); + return; + } +#else pw = getpwnam(auth_request->user); if (pw == NULL) { auth_request_log_info(auth_request, "passwd", "unknown user"); callback(USERDB_RESULT_USER_UNKNOWN, auth_request); return; } +#endif auth_request_set_field(auth_request, "user", pw->pw_name, NULL); @@ -151,6 +177,13 @@ module->module.cache_key = USER_CACHE_KEY; module->tmpl = userdb_static_template_build(pool, "passwd", args); +#ifdef HAVE_GETPWNAM_R + module->bufsize = sysconf(_SC_GETPW_R_SIZE_MAX); + if (module->bufsize == (size_t)-1) + module->bufsize = 16384; + module->buf = p_malloc(pool, module->bufsize); +#endif + if (userdb_static_template_remove(module->tmpl, "blocking", &value)) { module->module.blocking = value == NULL ||