Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.sbin / rpc.pcnfsd / pcnfsd_cache.c
blob846d2a109f12fa1dc017ea2333f612ec05937c53
1 /* $NetBSD: pcnfsd_cache.c,v 1.3 1997/10/25 13:45:57 lukem Exp $ */
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 */
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 **=====================================================================
20 #include <errno.h>
21 #include <pwd.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <unistd.h>
26 #include "common.h"
27 #include "pcnfsd.h"
28 #include "extern.h"
31 **---------------------------------------------------------------------
32 ** Misc. variable definitions
33 **---------------------------------------------------------------------
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];
48 **---------------------------------------------------------------------
49 ** User cache support procedures
50 **---------------------------------------------------------------------
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;
61 int i;
62 int c1, c2;
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);
75 User_cache[i].cuname[0] = '\0'; /* nuke entry */
76 return (0);
79 return (0);
82 void
83 add_cache_entry(p)
84 struct passwd *p;
86 int i;
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) strlcpy(User_cache[0].cpw, p->pw_passwd,
93 sizeof(User_cache[0].cpw));
94 (void) strlcpy(User_cache[0].cuname, p->pw_name,
95 sizeof(User_cache[0].cuname));
98 #endif /* USER_CACHE */