diff options
author | Jeremy Allison <jra@samba.org> | 2001-01-24 22:31:16 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2001-01-24 22:31:16 +0000 |
commit | b970656ddfa3761b7b5022b190f1e647ec1253ac (patch) | |
tree | 88e4b7ca5dc492b96e2c64487b16f561c6a71699 /source/lib/system.c | |
parent | 955f1e0f5d6c079c00da110a249b127a9dcaa953 (diff) | |
download | samba-b970656ddfa3761b7b5022b190f1e647ec1253ac.tar.gz samba-b970656ddfa3761b7b5022b190f1e647ec1253ac.tar.xz samba-b970656ddfa3761b7b5022b190f1e647ec1253ac.zip |
Fix insure problems with passwd caching code...
Jeremy.
Diffstat (limited to 'source/lib/system.c')
-rw-r--r-- | source/lib/system.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/source/lib/system.c b/source/lib/system.c index 85ccee03221..a2b9a7dbf73 100644 --- a/source/lib/system.c +++ b/source/lib/system.c @@ -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,13 @@ 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" +/* 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 */ static int num_lookups; /* Counter so we don't always use cache. */ -#ifndef PW_RET_CACHE_MAX_LOOKUPS +#ifndef PW_RET_CACHE_MAX_LOOKUPS #define PW_RET_CACHE_MAX_LOOKUPS 100 #endif @@ -624,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; @@ -633,18 +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)); } /************************************************************************** @@ -653,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)); } /************************************************************************** |