From 2be2a3d62c2d89e1f261d5b0e395b28ed3cbe102 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 24 Jan 2001 21:46:16 +0000 Subject: Added modification to Richard Bollinger getpw[nam|uid] cache patch. Only uses cache max 100 times. Jeremy. (This used to be commit 3712e35c5460d341ba750fe5e7bce8ef63c9f8ef) --- source3/lib/system.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/system.c b/source3/lib/system.c index 41877e51df..4481aa2689 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -612,6 +612,10 @@ static struct passwd *setup_pwret(struct passwd *pass) */ static struct passwd *sv_pw_ret; /* implicitly initialized to NULL */ +static int num_lookups; /* Counter so we don't always use cache. */ +#ifndef PW_RET_CACHE_MAX_LOOKUPS +#define PW_RET_CACHE_MAX_LOOKUPS 100 +#endif /************************************************************************** Wrapper for getpwnam(). Always returns a static that can be modified. @@ -623,9 +627,11 @@ struct passwd *sys_getpwnam(const char *name) return NULL; /* check for a cache hit first */ - if (sv_pw_ret && !strcmp(name, sv_pw_ret->pw_name)) + if (num_lookups && sv_pw_ret && !strcmp(name, sv_pw_ret->pw_name)) { DEBUG(2,("getpwnam(%s) avoided - using cached results\n",name)); + num_lookups++; + num_lookups = (num_lookups % PW_RET_CACHE_MAX_LOOKUPS); return setup_pwret(sv_pw_ret); } @@ -634,6 +640,8 @@ struct passwd *sys_getpwnam(const char *name) if (!(sv_pw_ret = getpwnam(name))) return NULL; + num_lookups = 1; + return setup_pwret(sv_pw_ret); } @@ -643,9 +651,11 @@ struct passwd *sys_getpwnam(const char *name) struct passwd *sys_getpwuid(uid_t uid) { - if (sv_pw_ret && (uid == sv_pw_ret->pw_uid)) + if (num_lookups && sv_pw_ret && (uid == sv_pw_ret->pw_uid)) { DEBUG(2,("getpwuid(%d) avoided - using cached results\n",uid)); + num_lookups++; + num_lookups = (num_lookups % PW_RET_CACHE_MAX_LOOKUPS); return setup_pwret(sv_pw_ret); } @@ -653,6 +663,8 @@ struct passwd *sys_getpwuid(uid_t uid) if (!(sv_pw_ret = getpwuid(uid))) return NULL; + num_lookups = 1; + return setup_pwret(sv_pw_ret); } -- cgit