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