1997-10-25 17:45:55 +04:00
|
|
|
/* $NetBSD: pcnfsd_cache.c,v 1.3 1997/10/25 13:45:57 lukem Exp $ */
|
1995-07-26 02:20:13 +04:00
|
|
|
|
1995-07-24 08:02:44 +04:00
|
|
|
/* RE_SID: @(%)/usr/dosnfs/shades_SCCS/unix/pcnfsd/v2/src/SCCS/s.pcnfsd_cache.c 1.1 91/09/03 12:45:14 SMI */
|
|
|
|
/*
|
|
|
|
**=====================================================================
|
|
|
|
** Copyright (c) 1986,1987,1988,1989,1990,1991 by Sun Microsystems, Inc.
|
|
|
|
** @(#)pcnfsd_cache.c 1.1 9/3/91
|
|
|
|
**=====================================================================
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
**=====================================================================
|
|
|
|
** I N C L U D E F I L E S E C T I O N *
|
|
|
|
** *
|
|
|
|
** If your port requires different include files, add a suitable *
|
|
|
|
** #define in the customization section, and make the inclusion or *
|
|
|
|
** exclusion of the files conditional on this. *
|
|
|
|
**=====================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
1997-10-25 17:45:55 +04:00
|
|
|
#include <pwd.h>
|
|
|
|
#include <stdio.h>
|
1995-07-24 08:02:44 +04:00
|
|
|
#include <string.h>
|
1997-10-25 17:45:55 +04:00
|
|
|
#include <unistd.h>
|
1995-07-24 08:02:44 +04:00
|
|
|
|
1997-10-25 17:45:55 +04:00
|
|
|
#include "common.h"
|
|
|
|
#include "pcnfsd.h"
|
|
|
|
#include "extern.h"
|
1995-07-24 08:02:44 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
**---------------------------------------------------------------------
|
|
|
|
** Misc. variable definitions
|
|
|
|
**---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef USER_CACHE
|
1997-10-25 17:45:55 +04:00
|
|
|
#define CACHE_SIZE 16 /* keep it small, as linear searches are done */
|
|
|
|
struct cache {
|
|
|
|
int cuid;
|
|
|
|
int cgid;
|
|
|
|
char cpw[32];
|
|
|
|
char cuname[10]; /* keep this even for machines with alignment
|
|
|
|
* problems */
|
|
|
|
} User_cache[CACHE_SIZE];
|
1995-07-24 08:02:44 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
**---------------------------------------------------------------------
|
1997-10-25 17:45:55 +04:00
|
|
|
** User cache support procedures
|
1995-07-24 08:02:44 +04:00
|
|
|
**---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
check_cache(name, pw, p_uid, p_gid)
|
1997-10-25 17:45:55 +04:00
|
|
|
char *name;
|
|
|
|
char *pw;
|
|
|
|
int *p_uid;
|
|
|
|
int *p_gid;
|
1995-07-24 08:02:44 +04:00
|
|
|
{
|
1997-10-25 17:45:55 +04:00
|
|
|
int i;
|
|
|
|
int c1, c2;
|
1995-07-24 08:02:44 +04:00
|
|
|
|
|
|
|
for (i = 0; i < CACHE_SIZE; i++) {
|
|
|
|
if (!strcmp(User_cache[i].cuname, name)) {
|
1997-10-25 17:45:55 +04:00
|
|
|
c1 = strlen(pw);
|
|
|
|
c2 = strlen(User_cache[i].cpw);
|
|
|
|
if ((!c1 && !c2) ||
|
|
|
|
!(strcmp(User_cache[i].cpw,
|
|
|
|
crypt(pw, User_cache[i].cpw)))) {
|
|
|
|
*p_uid = User_cache[i].cuid;
|
|
|
|
*p_gid = User_cache[i].cgid;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
User_cache[i].cuname[0] = '\0'; /* nuke entry */
|
|
|
|
return (0);
|
|
|
|
}
|
1995-07-24 08:02:44 +04:00
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
add_cache_entry(p)
|
1997-10-25 17:45:55 +04:00
|
|
|
struct passwd *p;
|
1995-07-24 08:02:44 +04:00
|
|
|
{
|
1997-10-25 17:45:55 +04:00
|
|
|
int i;
|
1995-07-24 08:02:44 +04:00
|
|
|
|
|
|
|
for (i = CACHE_SIZE - 1; i > 0; i--)
|
|
|
|
User_cache[i] = User_cache[i - 1];
|
|
|
|
User_cache[0].cuid = p->pw_uid;
|
|
|
|
User_cache[0].cgid = p->pw_gid;
|
1997-10-25 17:45:55 +04:00
|
|
|
(void) strcpy(User_cache[0].cpw, p->pw_passwd);
|
|
|
|
(void) strcpy(User_cache[0].cuname, p->pw_name);
|
1995-07-24 08:02:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* USER_CACHE */
|