mirror of
https://github.com/samba-team/samba.git
synced 2024-12-24 21:34:56 +03:00
Added modification to Richard Bollinger getpw[nam|uid] cache patch. Only
uses cache max 100 times. Jeremy.
This commit is contained in:
parent
a72d12e992
commit
3712e35c54
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user