diff options
author | Jeremy Allison <jra@samba.org> | 2001-01-24 21:46:16 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2001-01-24 21:46:16 +0000 |
commit | 2be2a3d62c2d89e1f261d5b0e395b28ed3cbe102 (patch) | |
tree | a44a9acdd275b7bf8ee6e8eb7ecc756ad36163cf /source3/lib | |
parent | 24f8e973b210bbf5b79ac27f0a0e519c7dfe9354 (diff) | |
download | samba-2be2a3d62c2d89e1f261d5b0e395b28ed3cbe102.tar.gz samba-2be2a3d62c2d89e1f261d5b0e395b28ed3cbe102.tar.bz2 samba-2be2a3d62c2d89e1f261d5b0e395b28ed3cbe102.zip |
Added modification to Richard Bollinger getpw[nam|uid] cache patch. Only
uses cache max 100 times.
Jeremy.
(This used to be commit 3712e35c5460d341ba750fe5e7bce8ef63c9f8ef)
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/system.c | 16 |
1 files changed, 14 insertions, 2 deletions
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) <rabollinger@home.com> */ 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); } |