Home | History | Annotate | Line # | Download | only in rpc.pcnfsd
pcnfsd_cache.c revision 1.3
      1  1.3  lukem /*	$NetBSD: pcnfsd_cache.c,v 1.3 1997/10/25 13:45:57 lukem Exp $	*/
      2  1.2    gwr 
      3  1.1    jtc /* RE_SID: @(%)/usr/dosnfs/shades_SCCS/unix/pcnfsd/v2/src/SCCS/s.pcnfsd_cache.c 1.1 91/09/03 12:45:14 SMI */
      4  1.1    jtc /*
      5  1.1    jtc **=====================================================================
      6  1.1    jtc ** Copyright (c) 1986,1987,1988,1989,1990,1991 by Sun Microsystems, Inc.
      7  1.1    jtc **	@(#)pcnfsd_cache.c	1.1	9/3/91
      8  1.1    jtc **=====================================================================
      9  1.1    jtc */
     10  1.1    jtc /*
     11  1.1    jtc **=====================================================================
     12  1.1    jtc **             I N C L U D E   F I L E   S E C T I O N                *
     13  1.1    jtc **                                                                    *
     14  1.1    jtc ** If your port requires different include files, add a suitable      *
     15  1.1    jtc ** #define in the customization section, and make the inclusion or    *
     16  1.1    jtc ** exclusion of the files conditional on this.                        *
     17  1.1    jtc **=====================================================================
     18  1.1    jtc */
     19  1.1    jtc 
     20  1.3  lukem #include <errno.h>
     21  1.3  lukem #include <pwd.h>
     22  1.1    jtc #include <stdio.h>
     23  1.1    jtc #include <string.h>
     24  1.3  lukem #include <unistd.h>
     25  1.1    jtc 
     26  1.3  lukem #include "common.h"
     27  1.3  lukem #include "pcnfsd.h"
     28  1.3  lukem #include "extern.h"
     29  1.1    jtc 
     30  1.1    jtc /*
     31  1.1    jtc **---------------------------------------------------------------------
     32  1.1    jtc **                       Misc. variable definitions
     33  1.1    jtc **---------------------------------------------------------------------
     34  1.1    jtc */
     35  1.1    jtc 
     36  1.1    jtc #ifdef USER_CACHE
     37  1.3  lukem #define CACHE_SIZE 16		/* keep it small, as linear searches are done */
     38  1.3  lukem struct cache {
     39  1.3  lukem 	int     cuid;
     40  1.3  lukem 	int     cgid;
     41  1.3  lukem 	char    cpw[32];
     42  1.3  lukem 	char    cuname[10];	/* keep this even for machines with alignment
     43  1.3  lukem 				 * problems */
     44  1.3  lukem }       User_cache[CACHE_SIZE];
     45  1.1    jtc 
     46  1.1    jtc 
     47  1.1    jtc /*
     48  1.1    jtc **---------------------------------------------------------------------
     49  1.3  lukem **                 User cache support procedures
     50  1.1    jtc **---------------------------------------------------------------------
     51  1.1    jtc */
     52  1.1    jtc 
     53  1.1    jtc 
     54  1.1    jtc int
     55  1.1    jtc check_cache(name, pw, p_uid, p_gid)
     56  1.3  lukem 	char   *name;
     57  1.3  lukem 	char   *pw;
     58  1.3  lukem 	int    *p_uid;
     59  1.3  lukem 	int    *p_gid;
     60  1.1    jtc {
     61  1.3  lukem 	int     i;
     62  1.3  lukem 	int     c1, c2;
     63  1.1    jtc 
     64  1.1    jtc 	for (i = 0; i < CACHE_SIZE; i++) {
     65  1.1    jtc 		if (!strcmp(User_cache[i].cuname, name)) {
     66  1.3  lukem 			c1 = strlen(pw);
     67  1.3  lukem 			c2 = strlen(User_cache[i].cpw);
     68  1.3  lukem 			if ((!c1 && !c2) ||
     69  1.3  lukem 			    !(strcmp(User_cache[i].cpw,
     70  1.3  lukem 				    crypt(pw, User_cache[i].cpw)))) {
     71  1.3  lukem 				*p_uid = User_cache[i].cuid;
     72  1.3  lukem 				*p_gid = User_cache[i].cgid;
     73  1.3  lukem 				return (1);
     74  1.3  lukem 			}
     75  1.3  lukem 			User_cache[i].cuname[0] = '\0';	/* nuke entry */
     76  1.3  lukem 			return (0);
     77  1.3  lukem 		}
     78  1.1    jtc 	}
     79  1.1    jtc 	return (0);
     80  1.1    jtc }
     81  1.1    jtc 
     82  1.1    jtc void
     83  1.1    jtc add_cache_entry(p)
     84  1.3  lukem 	struct passwd *p;
     85  1.1    jtc {
     86  1.3  lukem 	int     i;
     87  1.1    jtc 
     88  1.1    jtc 	for (i = CACHE_SIZE - 1; i > 0; i--)
     89  1.1    jtc 		User_cache[i] = User_cache[i - 1];
     90  1.1    jtc 	User_cache[0].cuid = p->pw_uid;
     91  1.1    jtc 	User_cache[0].cgid = p->pw_gid;
     92  1.3  lukem 	(void) strcpy(User_cache[0].cpw, p->pw_passwd);
     93  1.3  lukem 	(void) strcpy(User_cache[0].cuname, p->pw_name);
     94  1.1    jtc }
     95  1.1    jtc 
     96  1.1    jtc #endif				/* USER_CACHE */
     97