mirror of
https://github.com/samba-team/samba.git
synced 2025-01-12 09:18:10 +03:00
getpw[nam|uid] caching patch from "Richard Bollinger"
<rabollinger@home.com> jerry
This commit is contained in:
parent
a28d384e4d
commit
158430ba6a
@ -582,15 +582,14 @@ int sys_setgroups(int setlen, gid_t *gidset)
|
||||
|
||||
static struct passwd *setup_pwret(struct passwd *pass)
|
||||
{
|
||||
static pstring pw_name;
|
||||
static pstring pw_passwd;
|
||||
static fstring pw_name;
|
||||
static fstring pw_passwd;
|
||||
static struct passwd pw_ret;
|
||||
|
||||
|
||||
if (pass == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* this gets the uid, gid and null pointers */
|
||||
memcpy((char *)&pw_ret, pass, sizeof(struct passwd));
|
||||
|
||||
if (pass->pw_name)
|
||||
@ -608,13 +607,34 @@ static struct passwd *setup_pwret(struct passwd *pass)
|
||||
return &pw_ret;
|
||||
}
|
||||
|
||||
/* static pointer to be used for caching the last
|
||||
getpw[nam|uid]() call. Patch by "Richard Bollinger"
|
||||
<rabollinger@home.com> */
|
||||
|
||||
static struct passwd *sv_pw_ret; /* implicitly initialized to NULL */
|
||||
|
||||
/**************************************************************************
|
||||
Wrapper for getpwnam(). Always returns a static that can be modified.
|
||||
****************************************************************************/
|
||||
|
||||
struct passwd *sys_getpwnam(const char *name)
|
||||
{
|
||||
return setup_pwret(getpwnam(name));
|
||||
if (!name || !name[0])
|
||||
return NULL;
|
||||
|
||||
/* check for a cache hit first */
|
||||
if (sv_pw_ret && !strcmp(name, sv_pw_ret->pw_name))
|
||||
{
|
||||
DEBUG(2,("getpwnam(%s) avoided - using cached results\n",name));
|
||||
return setup_pwret(sv_pw_ret);
|
||||
}
|
||||
|
||||
/* no cache hit--use old lookup instead */
|
||||
DEBUG(2,("getpwnam(%s) called\n",name));
|
||||
if (!(sv_pw_ret = getpwnam(name)))
|
||||
return NULL;
|
||||
|
||||
return setup_pwret(sv_pw_ret);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
@ -623,7 +643,17 @@ struct passwd *sys_getpwnam(const char *name)
|
||||
|
||||
struct passwd *sys_getpwuid(uid_t uid)
|
||||
{
|
||||
return setup_pwret(getpwuid(uid));
|
||||
if (sv_pw_ret && (uid == sv_pw_ret->pw_uid))
|
||||
{
|
||||
DEBUG(2,("getpwuid(%d) avoided - using cached results\n",uid));
|
||||
return setup_pwret(sv_pw_ret);
|
||||
}
|
||||
|
||||
DEBUG(2,("getpwuid(%d) called\n",uid));
|
||||
if (!(sv_pw_ret = getpwuid(uid)))
|
||||
return NULL;
|
||||
|
||||
return setup_pwret(sv_pw_ret);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
|
Loading…
Reference in New Issue
Block a user