summaryrefslogtreecommitdiff
path: root/kerberosIV/kdb/krb_cache.c
blob: 0deb618b83fc8f88328e8d22f5846792dd3ee676 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*	$OpenBSD: krb_cache.c,v 1.5 1998/05/15 06:10:47 art Exp $	*/
/*	$KTH: krb_cache.c,v 1.6 1997/05/02 10:27:53 joda Exp $	*/

/*
 * This source code is no longer held under any constraint of USA
 * `cryptographic laws' since it was exported legally.  The cryptographic
 * functions were removed from the code and a "Bones" distribution was
 * made.  A Commodity Jurisdiction Request #012-94 was filed with the
 * USA State Department, who handed it to the Commerce department.  The
 * code was determined to fall under General License GTDA under ECCN 5D96G,
 * and hence exportable.  The cryptographic interfaces were re-added by Eric
 * Young, and then KTH proceeded to maintain the code in the free world.
 *
 */

/* 
 *  Copyright (C) 1989 by the Massachusetts Institute of Technology
 *
 *  Export of this software from the United States of America is assumed
 *  to require a specific license from the United States Government.
 *  It is the responsibility of any person or organization contemplating
 *  export to obtain such a license before exporting.
 *
 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
 * distribute this software and its documentation for any purpose and
 * without fee is hereby granted, provided that the above copyright
 * notice appear in all copies and that both that copyright notice and
 * this permission notice appear in supporting documentation, and that
 * the name of M.I.T. not be used in advertising or publicity pertaining
 * to distribution of the software without specific, written prior
 * permission.  M.I.T. makes no representations about the suitability of
 * this software for any purpose.  It is provided "as is" without express
 * or implied warranty.
 *
 */

/*
 * This is where a cache would be implemented, if it were necessary.
 */

#include "kdb_locl.h"

#ifdef DEBUG
extern int debug;
extern long kerb_debug;
#endif
static int init = 0;

/*
 * initialization routine for cache 
 */

int
kerb_cache_init(void)
{
    init = 1;
    return (0);
}

/*
 * look up a principal in the cache returns number of principals found 
 */

int
kerb_cache_get_principal(char *serv, char *inst, Principal *principal, unsigned int max)
                 		/* could have wild card */
                 		/* could have wild card */
                         
                     		/* max number of name structs to return */

{
    int found = 0;

    if (!init)
	kerb_cache_init();
#ifdef DEBUG
    if (kerb_debug & 2)
	fprintf(stderr, "cache_get_principal for %s %s max = %d\n",
		serv, inst, max);
#endif /* DEBUG */
    
#ifdef DEBUG
    if (kerb_debug & 2) {
	if (found) {
	    fprintf(stderr, "cache get %s %s found %s %s sid = %d\n",
		    serv, inst, principal->name, principal->instance);
	} else {
	    fprintf(stderr, "cache %s %s not found\n", serv,
		    inst);
	}
    }
#endif
    return found;
}

/*
 * insert/replace a principal in the cache returns number of principals
 * inserted 
 */

int
kerb_cache_put_principal(Principal *principal, unsigned int max)
                         
                     		/* max number of principal structs to
				 * insert */

{
    u_long i;
    int count = 0;

    if (!init)
	kerb_cache_init();

#ifdef DEBUG
    if (kerb_debug & 2) {
	fprintf(stderr, "kerb_cache_put_principal  max = %d",
	    max);
    }
#endif
    
    for (i = 0; i < max; i++) {
#ifdef DEBUG
	if (kerb_debug & 2)
	    fprintf(stderr, "\n %s %s",
		    principal->name, principal->instance);
#endif	
	/* DO IT */
	count++;
	principal++;
    }
    return count;
}

/*
 * look up a dba in the cache returns number of dbas found 
 */

int
kerb_cache_get_dba(char *serv, char *inst, Dba *dba, unsigned int max)
                 		/* could have wild card */
                 		/* could have wild card */
                
                     		/* max number of name structs to return */

{
    int found = 0;

    if (!init)
	kerb_cache_init();

#ifdef DEBUG
    if (kerb_debug & 2)
	fprintf(stderr, "cache_get_dba for %s %s max = %d\n",
		serv, inst, max);
#endif

#ifdef DEBUG
    if (kerb_debug & 2) {
	if (found) {
	    fprintf(stderr, "cache get %s %s found %s %s sid = %d\n",
		    serv, inst, dba->name, dba->instance);
	} else {
	    fprintf(stderr, "cache %s %s not found\n", serv, inst);
	}
    }
#endif
    return found;
}

/*
 * insert/replace a dba in the cache returns number of dbas inserted 
 */

int
kerb_cache_put_dba(Dba *dba, unsigned int max)
                
                     		/* max number of dba structs to insert */

{
    u_long  i;
    int     count = 0;

    if (!init)
	kerb_cache_init();
#ifdef DEBUG
    if (kerb_debug & 2) {
	fprintf(stderr, "kerb_cache_put_dba  max = %d", max);
    }
#endif
    for (i = 0; i < max; i++) {
#ifdef DEBUG
	if (kerb_debug & 2)
	    fprintf(stderr, "\n %s %s",
		    dba->name, dba->instance);
#endif	
	/* DO IT */
	count++;
	dba++;
    }
    return count;
}