2 Copyright (C) 1989 by the Massachusetts Institute of Technology
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.
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
24 RCSID("$Id: krb_lib.c,v 1.13 1998/11/22 09:41:43 assar Exp $");
28 extern char *progname;
35 * initialization routine for data base
43 char *dbg = getenv("KERB_DBG");
45 sscanf(dbg, "%d", &kerb_debug);
55 /* successful init, return 0, else errcode */
60 * finalization routine for database -- NOTE: MUST be called by any
61 * program using kerb_init. ALSO will have to be modified to finalize
62 * caches, if they're ever really implemented.
73 kerb_delete_principal(char *name, char *inst)
80 ret = kerb_db_delete_principal(name, inst);
83 kerb_cache_delete_principal(name, inst);
91 * look up a principal in the cache or data base returns number of
96 kerb_get_principal(char *name, /* could have wild card */
97 char *inst, /* could have wild card */
99 unsigned int max, /* max number of name structs to return */
100 int *more) /* more tuples than room for */
111 fprintf(stderr, "\n%s: kerb_get_principal for %s %s max = %d\n",
112 progname, name, inst, max);
116 * if this is a request including a wild card, have to go to db
117 * since the cache may not be exhaustive.
120 /* clear the principal area */
121 memset(principal, 0, max * sizeof(Principal));
125 * so check to see if the name contains a wildcard "*" or "?", not
126 * preceeded by a backslash.
129 if (index(name, '*') || index(name, '?') ||
130 index(inst, '*') || index(inst, '?'))
134 /* try the cache first */
135 found = kerb_cache_get_principal(name, inst, principal, max, more);
140 /* If we didn't try cache, or it wasn't there, try db */
141 found = kerb_db_get_principal(name, inst, principal, max, more);
142 /* try to insert principal(s) into cache if it was found */
145 kerb_cache_put_principal(principal, found);
153 kerb_put_principal(Principal *principal,
155 /* number of principal structs to write */
158 principal->mod_date = time((time_t *)0);
159 /* and mod date string */
161 strftime(principal->mod_date_txt,
162 sizeof(principal->mod_date_txt),
163 "%Y-%m-%d", k_localtime(&principal->mod_date));
164 strftime(principal->exp_date_txt,
165 sizeof(principal->exp_date_txt),
166 "%Y-%m-%d", k_localtime(&principal->exp_date));
168 if (kerb_debug & 1) {
170 fprintf(stderr, "\nkerb_put_principal...");
171 for (i = 0; i < n; i++) {
172 krb_print_principal(&principal[i]);
177 if (kerb_db_put_principal(principal, n) < 0) {
180 fprintf(stderr, "\n%s: kerb_db_put_principal err", progname);
181 /* watch out for cache */
187 if (!kerb_cache_put_principal(principal, n)) {
190 fprintf(stderr, "\n%s: kerb_cache_put_principal err", progname);
199 kerb_get_dba(char *name, /* could have wild card */
200 char *inst, /* could have wild card */
202 unsigned int max, /* max number of name structs to return */
203 int *more) /* more tuples than room for */
214 fprintf(stderr, "\n%s: kerb_get_dba for %s %s max = %d\n",
215 progname, name, inst, max);
218 * if this is a request including a wild card, have to go to db
219 * since the cache may not be exhaustive.
222 /* clear the dba area */
223 memset(dba, 0, max * sizeof(Dba));
227 * so check to see if the name contains a wildcard "*" or "?", not
228 * preceeded by a backslash.
232 if (index(name, '*') || index(name, '?') ||
233 index(inst, '*') || index(inst, '?'))
237 /* try the cache first */
238 found = kerb_cache_get_dba(name, inst, dba, max, more);
243 /* If we didn't try cache, or it wasn't there, try db */
244 found = kerb_db_get_dba(name, inst, dba, max, more);
246 /* try to insert dba(s) into cache if it was found */
248 kerb_cache_put_dba(dba, found);