2 * lib/krb5/keytab/ktbase.c
4 * Copyright 1990 by the Massachusetts Institute of Technology.
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. Furthermore if you modify this software you must label
20 * your software as modified software and not distribute it in such a
21 * fashion that it might be confused with the original M.I.T. software.
22 * M.I.T. makes no representations about the suitability of
23 * this software for any purpose. It is provided "as is" without express
24 * or implied warranty.
27 * Registration functions for keytab.
32 extern krb5_kt_ops krb5_ktf_ops;
33 extern krb5_kt_ops krb5_kts_ops;
35 struct krb5_kt_typelist {
37 struct krb5_kt_typelist *next;
39 static struct krb5_kt_typelist krb5_kt_typelist_file = {
43 static struct krb5_kt_typelist krb5_kt_typelist_srvtab = {
45 &krb5_kt_typelist_file
47 static struct krb5_kt_typelist *kt_typehead = &krb5_kt_typelist_srvtab;
51 * Register a new key table type
52 * don't replace if it already exists; return an error instead.
55 krb5_error_code KRB5_CALLCONV
56 krb5_kt_register(context, ops)
60 struct krb5_kt_typelist *t;
61 for (t = kt_typehead;t && strcmp(t->ops->prefix,ops->prefix);t = t->next)
64 return KRB5_KT_TYPE_EXISTS;
66 if (!(t = (struct krb5_kt_typelist *) malloc(sizeof(*t))))
68 t->next = kt_typehead;
75 * Resolve a key table name into a keytab object.
77 * The name is currently constrained to be of the form "type:residual";
79 * The "type" portion corresponds to one of the registered key table
80 * types, while the "residual" portion is specific to the
81 * particular keytab type.
84 krb5_error_code KRB5_CALLCONV
85 krb5_kt_resolve (context, name, ktid)
87 krb5_const char FAR *name;
88 krb5_keytab FAR *ktid;
90 struct krb5_kt_typelist *tlist;
93 const char *cp, *resid;
95 cp = strchr (name, ':');
97 return (*krb5_kt_dfl_ops.resolve)(context, name, ktid);
101 resid = name + pfxlen + 1;
103 pfx = malloc (pfxlen+1);
107 memcpy (pfx, name, pfxlen);
110 *ktid = (krb5_keytab) 0;
112 for (tlist = kt_typehead; tlist; tlist = tlist->next) {
113 if (strcmp (tlist->ops->prefix, pfx) == 0) {
115 return (*tlist->ops->resolve)(context, resid, ktid);
119 return KRB5_KT_UNKNOWN_TYPE;
123 * Routines to deal with externalizingt krb5_keytab.
124 * krb5_keytab_size();
125 * krb5_keytab_externalize();
126 * krb5_keytab_internalize();
128 static krb5_error_code krb5_keytab_size
129 KRB5_PROTOTYPE((krb5_context, krb5_pointer, size_t *));
130 static krb5_error_code krb5_keytab_externalize
131 KRB5_PROTOTYPE((krb5_context, krb5_pointer, krb5_octet **, size_t *));
132 static krb5_error_code krb5_keytab_internalize
133 KRB5_PROTOTYPE((krb5_context,krb5_pointer *, krb5_octet **, size_t *));
136 * Serialization entry for this type.
138 static const krb5_ser_entry krb5_keytab_ser_entry = {
139 KV5M_KEYTAB, /* Type */
140 krb5_keytab_size, /* Sizer routine */
141 krb5_keytab_externalize, /* Externalize routine */
142 krb5_keytab_internalize /* Internalize routine */
145 static krb5_error_code
146 krb5_keytab_size(kcontext, arg, sizep)
147 krb5_context kcontext;
151 krb5_error_code kret;
153 krb5_ser_handle shandle;
156 if ((keytab = (krb5_keytab) arg) &&
158 (shandle = (krb5_ser_handle) keytab->ops->serializer) &&
160 kret = (*shandle->sizer)(kcontext, arg, sizep);
164 static krb5_error_code
165 krb5_keytab_externalize(kcontext, arg, buffer, lenremain)
166 krb5_context kcontext;
171 krb5_error_code kret;
173 krb5_ser_handle shandle;
176 if ((keytab = (krb5_keytab) arg) &&
178 (shandle = (krb5_ser_handle) keytab->ops->serializer) &&
179 shandle->externalizer)
180 kret = (*shandle->externalizer)(kcontext, arg, buffer, lenremain);
184 static krb5_error_code
185 krb5_keytab_internalize(kcontext, argp, buffer, lenremain)
186 krb5_context kcontext;
191 krb5_error_code kret;
192 krb5_ser_handle shandle;
195 if ((shandle = (krb5_ser_handle) krb5_kt_dfl_ops.serializer) &&
196 shandle->internalizer)
197 kret = (*shandle->internalizer)(kcontext, argp, buffer, lenremain);
201 krb5_error_code KRB5_CALLCONV
202 krb5_ser_keytab_init(kcontext)
203 krb5_context kcontext;
205 return(krb5_register_serializer(kcontext, &krb5_keytab_ser_entry));