summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2001-01-24 22:31:43 +0000
committerJeremy Allison <jra@samba.org>2001-01-24 22:31:43 +0000
commit2bd4f163890be58456a7e49b1adbed3f5834ff9e (patch)
tree652a59cf5692e9941172357752a9afb25e9c7237
parente0431672cc54ed09d6c5cf083054db12ccd9dcf6 (diff)
downloadsamba-2bd4f163890be58456a7e49b1adbed3f5834ff9e.tar.gz
samba-2bd4f163890be58456a7e49b1adbed3f5834ff9e.tar.xz
samba-2bd4f163890be58456a7e49b1adbed3f5834ff9e.zip
Fix insure problems with passwd caching code.
Jeremy.
-rw-r--r--source/lib/system.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/source/lib/system.c b/source/lib/system.c
index 4481aa2689f..a2b9a7dbf73 100644
--- a/source/lib/system.c
+++ b/source/lib/system.c
@@ -623,6 +623,8 @@ static int num_lookups; /* Counter so we don't always use cache. */
struct passwd *sys_getpwnam(const char *name)
{
+ struct passwd *pw_ret;
+
if (!name || !name[0])
return NULL;
@@ -632,17 +634,17 @@ struct passwd *sys_getpwnam(const char *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);
+ return sv_pw_ret;
}
/* no cache hit--use old lookup instead */
DEBUG(2,("getpwnam(%s) called\n",name));
- if (!(sv_pw_ret = getpwnam(name)))
+ if (!(pw_ret = getpwnam(name)))
return NULL;
num_lookups = 1;
- return setup_pwret(sv_pw_ret);
+ return (sv_pw_ret = setup_pwret(pw_ret));
}
/**************************************************************************
@@ -651,21 +653,23 @@ struct passwd *sys_getpwnam(const char *name)
struct passwd *sys_getpwuid(uid_t uid)
{
+ struct passwd *pw_ret;
+
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);
+ return sv_pw_ret;
}
DEBUG(2,("getpwuid(%d) called\n",uid));
- if (!(sv_pw_ret = getpwuid(uid)))
+ if (!(pw_ret = getpwuid(uid)))
return NULL;
num_lookups = 1;
- return setup_pwret(sv_pw_ret);
+ return (sv_pw_ret = setup_pwret(pw_ret));
}
/**************************************************************************