summaryrefslogtreecommitdiff
path: root/source3/lib/system.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2002-05-22 12:44:45 +0000
committerAndrew Bartlett <abartlet@samba.org>2002-05-22 12:44:45 +0000
commitb87eee983612c0d21b0c6f1346ba15ace797fe9e (patch)
tree24e2b36dfad85d014754e1ed08cb3d3b74704f24 /source3/lib/system.c
parentdaec6cbbeee8401ef1aa0a3424ee05a3148d7ec8 (diff)
downloadsamba-b87eee983612c0d21b0c6f1346ba15ace797fe9e.tar.gz
samba-b87eee983612c0d21b0c6f1346ba15ace797fe9e.tar.bz2
samba-b87eee983612c0d21b0c6f1346ba15ace797fe9e.zip
Add a bit more const, and kill of (finally!) sys_getpwnam and sys_getpwuid.
These might be reimplmented as simple pass-through functions, but all users really should be doing 'getpwnam_alloc' or 'getpwuid_alloc' to ensure that there are not shared static buffers. I don't beleive we actually need a getpw*() cache inside samba - if we do then I think we should look at our code design first. (some of these changes are for platforms I don't have access to, but they look sane) Andrew Bartlett (This used to be commit 9d8431b04f41dceffe4c45cc969472ee59f7282f)
Diffstat (limited to 'source3/lib/system.c')
-rw-r--r--source3/lib/system.c110
1 files changed, 1 insertions, 109 deletions
diff --git a/source3/lib/system.c b/source3/lib/system.c
index 9953df7058..3bf0994621 100644
--- a/source3/lib/system.c
+++ b/source3/lib/system.c
@@ -744,133 +744,25 @@ int sys_setgroups(int setlen, gid_t *gidset)
#endif /* HAVE_SETGROUPS */
-/*
- * We only wrap pw_name and pw_passwd for now as these
- * are the only potentially modified fields.
- */
-
-/**************************************************************************
- Helper function for getpwnam/getpwuid wrappers.
-****************************************************************************/
-
-struct saved_pw {
- fstring pw_name;
- fstring pw_passwd;
- fstring pw_gecos;
- pstring pw_dir;
- pstring pw_shell;
- struct passwd pass;
-};
-
-static struct saved_pw pw_mod; /* This is the structure returned - can be modified. */
-static struct saved_pw pw_cache; /* This is the structure saved - used to check cache. */
-
-static int num_lookups; /* Counter so we don't always use cache. */
-#ifndef PW_RET_CACHE_MAX_LOOKUPS
-#define PW_RET_CACHE_MAX_LOOKUPS 100
-#endif
-
-static void copy_pwent(struct saved_pw *dst, struct passwd *pass)
-{
- memcpy((char *)&dst->pass, pass, sizeof(struct passwd));
-
- fstrcpy(dst->pw_name, pass->pw_name);
- dst->pass.pw_name = dst->pw_name;
-
- fstrcpy(dst->pw_passwd, pass->pw_passwd);
- dst->pass.pw_passwd = dst->pw_passwd;
-
- fstrcpy(dst->pw_gecos, pass->pw_gecos);
- dst->pass.pw_gecos = dst->pw_gecos;
-
- pstrcpy(dst->pw_dir, pass->pw_dir);
- dst->pass.pw_dir = dst->pw_dir;
-
- pstrcpy(dst->pw_shell, pass->pw_shell);
- dst->pass.pw_shell = dst->pw_shell;
-}
-
-static struct passwd *setup_pwret(struct passwd *pass)
-{
- if (pass == NULL) {
- /* Clear the caches. */
- memset(&pw_cache, '\0', sizeof(struct saved_pw));
- memset(&pw_mod, '\0', sizeof(struct saved_pw));
- num_lookups = 0;
- return NULL;
- }
-
- copy_pwent( &pw_mod, pass);
-
- if (pass != &pw_cache.pass) {
-
- /* If it's a cache miss we must also refill the cache. */
-
- copy_pwent( &pw_cache, pass);
- num_lookups = 1;
-
- } else {
-
- /* Cache hit. */
-
- num_lookups++;
- num_lookups = (num_lookups % PW_RET_CACHE_MAX_LOOKUPS);
- }
-
- return &pw_mod.pass;
-}
-
/**************************************************************************
Wrappers for setpwent(), getpwent() and endpwent()
****************************************************************************/
void sys_setpwent(void)
{
- setup_pwret(NULL); /* Clear cache. */
setpwent();
}
struct passwd *sys_getpwent(void)
{
- return setup_pwret(getpwent());
+ return getpwent();
}
void sys_endpwent(void)
{
- setup_pwret(NULL); /* Clear cache. */
endpwent();
}
-/**************************************************************************
- Wrapper for getpwnam(). Always returns a static that can be modified.
-****************************************************************************/
-
-struct passwd *sys_getpwnam(const char *name)
-{
- if (!name || !name[0])
- return NULL;
-
- /* check for a cache hit first */
- if (num_lookups && pw_cache.pass.pw_name && !strcmp(name, pw_cache.pass.pw_name)) {
- return setup_pwret(&pw_cache.pass);
- }
-
- return setup_pwret(getpwnam(name));
-}
-
-/**************************************************************************
- Wrapper for getpwuid(). Always returns a static that can be modified.
-****************************************************************************/
-
-struct passwd *sys_getpwuid(uid_t uid)
-{
- if (num_lookups && pw_cache.pass.pw_name && (uid == pw_cache.pass.pw_uid)) {
- return setup_pwret(&pw_cache.pass);
- }
-
- return setup_pwret(getpwuid(uid));
-}
-
#if 0 /* NOT CURRENTLY USED - JRA */
/**************************************************************************
The following are the UNICODE versions of *all* system interface functions