2 * lib/krb5/rcache/rc_base.c
4 * This file of the Kerberos V5 software is derived from public-domain code
5 * contributed by Daniel J. Bernstein, <brnstnd@acf10.nyu.edu>.
11 * Base "glue" functions for the replay cache.
15 #include <semaphore.h>
19 #define FREE(x) ((void) free((char *) (x)))
21 struct krb5_rc_typelist
24 struct krb5_rc_typelist *next;
26 static struct krb5_rc_typelist krb5_rc_typelist_dfl = { &krb5_rc_dfl_ops, 0 };
27 static struct krb5_rc_typelist *typehead = &krb5_rc_typelist_dfl;
30 semaphore ex_typelist = 1;
33 krb5_error_code INTERFACE krb5_rc_register_type(context, ops)
37 struct krb5_rc_typelist *t;
41 for (t = typehead;t && strcmp(t->ops->type,ops->type);t = t->next)
47 return KRB5_RC_TYPE_EXISTS;
48 if (!(t = (struct krb5_rc_typelist *) malloc(sizeof(struct krb5_rc_typelist))))
49 return KRB5_RC_MALLOC;
62 krb5_error_code INTERFACE krb5_rc_resolve_type(context, id, type)
67 struct krb5_rc_typelist *t;
71 for (t = typehead;t && strcmp(t->ops->type,type);t = t->next)
77 return KRB5_RC_TYPE_NOTFOUND;
78 /* allocate *id? nah */
83 char * INTERFACE krb5_rc_get_type(context, id)
90 char * INTERFACE krb5_rc_default_type(context)
94 if (s = getenv("KRB5RCACHETYPE"))
100 char * INTERFACE krb5_rc_default_name(context)
101 krb5_context context;
104 if (s = getenv("KRB5RCACHENAME"))
110 krb5_error_code INTERFACE
111 krb5_rc_default(context, id)
112 krb5_context context;
115 krb5_error_code retval;
117 if (!(*id = (krb5_rcache )malloc(sizeof(**id))))
118 return KRB5_RC_MALLOC;
120 if (retval = krb5_rc_resolve_type(context, id,
121 krb5_rc_default_type(context))) {
125 if (retval = krb5_rc_resolve(context, *id,
126 krb5_rc_default_name(context)))
132 krb5_error_code INTERFACE krb5_rc_resolve_full(context, id, string_name)
133 krb5_context context;
139 krb5_error_code retval;
141 if (!(residual = strchr(string_name,':')))
142 return KRB5_RC_PARSE;
144 if (!(type = malloc(residual - string_name + 1)))
145 return KRB5_RC_MALLOC;
146 (void) strncpy(type,string_name,residual - string_name);
147 type[residual - string_name] = '\0';
149 if (!(*id = (krb5_rcache) malloc(sizeof(**id)))) {
151 return KRB5_RC_MALLOC;
154 if (retval = krb5_rc_resolve_type(context, id,type)) {
160 if (retval = krb5_rc_resolve(context, *id,residual + 1))