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