diff options
author | Jeremy Allison <jra@samba.org> | 2001-01-24 22:31:43 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2001-01-24 22:31:43 +0000 |
commit | 16dd4b9988853c27034ad00e39bc06cb52b48cb7 (patch) | |
tree | 24886750ccca419bd4e6ad48f4f4d89be99527e0 /source3/lib | |
parent | b15e9adea1bd09cfe78f32be9a007a9731bcb3e4 (diff) | |
download | samba-16dd4b9988853c27034ad00e39bc06cb52b48cb7.tar.gz samba-16dd4b9988853c27034ad00e39bc06cb52b48cb7.tar.bz2 samba-16dd4b9988853c27034ad00e39bc06cb52b48cb7.zip |
Fix insure problems with passwd caching code.
Jeremy.
(This used to be commit 2bd4f163890be58456a7e49b1adbed3f5834ff9e)
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/system.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/source3/lib/system.c b/source3/lib/system.c index 4481aa2689..a2b9a7dbf7 100644 --- a/source3/lib/system.c +++ b/source3/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)); } /************************************************************************** |