From c34ec6180a011f23de16cc5e19902470dc7feb6f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 12 Nov 2004 15:01:40 +0000 Subject: r3702: This is a getpwnam-cache. It is mainly to speed up Samba with slow nss backends such as nss_ldap. Volker (This used to be commit a8bd0b75042f73b753fc1cb8a52e6e90372fd1fe) --- source3/lib/util_pw.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/source3/lib/util_pw.c b/source3/lib/util_pw.c index 9d075a05e8..e102f2ef81 100644 --- a/source3/lib/util_pw.c +++ b/source3/lib/util_pw.c @@ -52,10 +52,40 @@ void passwd_free (struct passwd **buf) SAFE_FREE(*buf); } +#define PWNAMCACHE_SIZE 4 +static struct passwd *pwnam_cache[PWNAMCACHE_SIZE]; +static BOOL pwnam_cache_initialized = False; + +static void init_pwnam_cache(void) +{ + int i; + + if (pwnam_cache_initialized) + return; + + for (i=0; ipw_name) == 0)) { + DEBUG(10, ("Got %s from pwnam_cache\n", name)); + return alloc_copy_passwd(pwnam_cache[i]); + } + } + temp = sys_getpwnam(name); if (!temp) { @@ -67,6 +97,19 @@ struct passwd *getpwnam_alloc(const char *name) return NULL; } + for (i=0; i