Initial import from FreeBSD RELENG_4:
[dragonfly.git] / crypto / kerberosIV / lib / kdb / krb_cache.c
1 /* 
2   Copyright (C) 1989 by the Massachusetts Institute of Technology
3
4    Export of this software from the United States of America is assumed
5    to require a specific license from the United States Government.
6    It is the responsibility of any person or organization contemplating
7    export to obtain such a license before exporting.
8
9 WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
10 distribute this software and its documentation for any purpose and
11 without fee is hereby granted, provided that the above copyright
12 notice appear in all copies and that both that copyright notice and
13 this permission notice appear in supporting documentation, and that
14 the name of M.I.T. not be used in advertising or publicity pertaining
15 to distribution of the software without specific, written prior
16 permission.  M.I.T. makes no representations about the suitability of
17 this software for any purpose.  It is provided "as is" without express
18 or implied warranty.
19
20   */
21
22 /*
23  * This is where a cache would be implemented, if it were necessary.
24  */
25
26 #include "kdb_locl.h"
27
28 RCSID("$Id: krb_cache.c,v 1.7 1998/06/09 19:25:14 joda Exp $");
29
30 #ifdef DEBUG
31 extern int debug;
32 extern long kerb_debug;
33 #endif
34 static int init = 0;
35
36 /*
37  * initialization routine for cache 
38  */
39
40 int
41 kerb_cache_init(void)
42 {
43     init = 1;
44     return (0);
45 }
46
47 /*
48  * look up a principal in the cache returns number of principals found 
49  */
50
51 int
52 kerb_cache_get_principal(char *serv, /* could have wild card */
53                          char *inst, /* could have wild card */
54                          Principal *principal,
55                          unsigned int max) /* max number of name structs to return */
56 {
57     int     found = 0;
58
59     if (!init)
60         kerb_cache_init();
61 #ifdef DEBUG
62     if (kerb_debug & 2)
63         fprintf(stderr, "cache_get_principal for %s %s max = %d\n",
64             serv, inst, max);
65 #endif /* DEBUG */
66     
67 #ifdef DEBUG
68     if (kerb_debug & 2) {
69         if (found) {
70             fprintf(stderr, "cache get %s %s found %s %s sid = %d\n",
71                 serv, inst, principal->name, principal->instance);
72         } else {
73             fprintf(stderr, "cache %s %s not found\n", serv,
74                 inst);
75         }
76     }
77 #endif
78     return (found);
79 }
80
81 /*
82  * insert/replace a principal in the cache returns number of principals
83  * inserted 
84  */
85
86 int
87 kerb_cache_put_principal(Principal *principal,
88                          unsigned int max)
89                                 /* max number of principal structs to
90                                  * insert */
91 {
92     u_long  i;
93     int     count = 0;
94
95     if (!init)
96         kerb_cache_init();
97
98 #ifdef DEBUG
99     if (kerb_debug & 2) {
100         fprintf(stderr, "kerb_cache_put_principal  max = %d",
101             max);
102     }
103 #endif
104     
105     for (i = 0; i < max; i++) {
106 #ifdef DEBUG
107         if (kerb_debug & 2)
108             fprintf(stderr, "\n %s %s",
109                     principal->name, principal->instance);
110 #endif  
111         /* DO IT */
112         count++;
113         principal++;
114     }
115     return count;
116 }
117
118 /*
119  * look up a dba in the cache returns number of dbas found 
120  */
121
122 int
123 kerb_cache_get_dba(char *serv,  /* could have wild card */
124                    char *inst,  /* could have wild card */
125                    Dba *dba,
126                    unsigned int max) /* max number of name structs to return */
127 {
128     int     found = 0;
129
130     if (!init)
131         kerb_cache_init();
132
133 #ifdef DEBUG
134     if (kerb_debug & 2)
135         fprintf(stderr, "cache_get_dba for %s %s max = %d\n",
136             serv, inst, max);
137 #endif
138
139 #ifdef DEBUG
140     if (kerb_debug & 2) {
141         if (found) {
142             fprintf(stderr, "cache get %s %s found %s %s sid = %d\n",
143                 serv, inst, dba->name, dba->instance);
144         } else {
145             fprintf(stderr, "cache %s %s not found\n", serv, inst);
146         }
147     }
148 #endif
149     return (found);
150 }
151
152 /*
153  * insert/replace a dba in the cache returns number of dbas inserted 
154  */
155
156 int
157 kerb_cache_put_dba(Dba *dba,
158                    unsigned int max)
159                                 /* max number of dba structs to insert */
160 {
161     u_long  i;
162     int     count = 0;
163
164     if (!init)
165         kerb_cache_init();
166 #ifdef DEBUG
167     if (kerb_debug & 2) {
168         fprintf(stderr, "kerb_cache_put_dba  max = %d", max);
169     }
170 #endif
171     for (i = 0; i < max; i++) {
172 #ifdef DEBUG
173         if (kerb_debug & 2)
174             fprintf(stderr, "\n %s %s",
175                     dba->name, dba->instance);
176 #endif  
177         /* DO IT */
178         count++;
179         dba++;
180     }
181     return count;
182 }
183