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. M.I.T. makes no representations about the suitability of
20 * this software for any purpose. It is provided "as is" without express
21 * or implied warranty.
24 * Registration functions for keytab.
28 #include <krb5/krb5.h>
29 #include <krb5/ext-proto.h>
31 struct krb5_kt_typelist
34 struct krb5_kt_typelist *next;
36 static struct krb5_kt_typelist krb5_kt_typelist_dfl = { &krb5_kt_dfl_ops, 0 };
37 static struct krb5_kt_typelist *kt_typehead = &krb5_kt_typelist_dfl;
40 * Register a new key table type
41 * don't replace if it already exists; return an error instead.
48 struct krb5_kt_typelist *t;
49 for (t = kt_typehead;t && strcmp(t->ops->prefix,ops->prefix);t = t->next)
52 return KRB5_KT_TYPE_EXISTS;
54 if (!(t = (struct krb5_kt_typelist *) malloc(sizeof(*t))))
56 t->next = kt_typehead;
63 * Resolve a key table name into a keytab object.
65 * The name is currently constrained to be of the form "type:residual";
67 * The "type" portion corresponds to one of the registered key table
68 * types, while the "residual" portion is specific to the
69 * particular keytab type.
72 krb5_error_code krb5_kt_resolve (name, ktid)
76 struct krb5_kt_typelist *tlist;
77 char *pfx, *resid, *cp;
80 cp = strchr (name, ':');
82 return (*krb5_kt_dfl_ops.resolve)(name, ktid);
85 pfxlen = cp - (char *)name;
86 resid = (char *)name + pfxlen + 1;
88 pfx = malloc (pfxlen+1);
92 memcpy (pfx, name, pfxlen);
95 *ktid = (krb5_keytab) 0;
97 for (tlist = kt_typehead; tlist; tlist = tlist->next) {
98 if (strcmp (tlist->ops->prefix, pfx) == 0) {
100 return (*tlist->ops->resolve)(resid, ktid);
104 return KRB5_KT_UNKNOWN_TYPE;