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