summaryrefslogtreecommitdiffstats
path: root/source/lib/system.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/lib/system.c')
-rw-r--r--source/lib/system.c34
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));
}
/**************************************************************************