Change export warning notice from "is assumed to require an export license"
[krb5.git] / src / lib / krb5 / keytab / ktbase.c
1 /*
2  * $Source$
3  * $Author$
4  *
5  * Copyright 1990 by the Massachusetts Institute of Technology.
6  * All Rights Reserved.
7  *
8  * Export of this software from the United States of America may
9  *   require a specific license from the United States Government.
10  *   It is the responsibility of any person or organization contemplating
11  *   export to obtain such a license before exporting.
12  * 
13  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
14  * distribute this software and its documentation for any purpose and
15  * without fee is hereby granted, provided that the above copyright
16  * notice appear in all copies and that both that copyright notice and
17  * this permission notice appear in supporting documentation, and that
18  * the name of M.I.T. not be used in advertising or publicity pertaining
19  * to distribution of the software without specific, written prior
20  * permission.  M.I.T. makes no representations about the suitability of
21  * this software for any purpose.  It is provided "as is" without express
22  * or implied warranty.
23  * 
24  *
25  * Registration functions for keytab.
26  */
27
28 #if !defined(lint) && !defined(SABER)
29 static char rcsid_ktbase_c[] =
30 "$Id$";
31 #endif  /* !lint & !SABER */
32
33 #include <krb5/krb5.h>
34 #include <krb5/ext-proto.h>
35
36 struct krb5_kt_typelist
37  {
38   krb5_kt_ops *ops;
39   struct krb5_kt_typelist *next;
40  };
41 static struct krb5_kt_typelist krb5_kt_typelist_dfl = { &krb5_kt_dfl_ops, 0 };
42 static struct krb5_kt_typelist *kt_typehead = &krb5_kt_typelist_dfl;
43
44 /*
45  * Register a new key table type
46  * don't replace if it already exists; return an error instead.
47  */
48
49 krb5_error_code
50 krb5_kt_register(ops)
51 krb5_kt_ops *ops;
52 {
53     struct krb5_kt_typelist *t;
54     for (t = kt_typehead;t && strcmp(t->ops->prefix,ops->prefix);t = t->next)
55         ;
56     if (t) {
57         return KRB5_KT_TYPE_EXISTS;
58     }
59     if (!(t = (struct krb5_kt_typelist *) malloc(sizeof(*t))))
60         return ENOMEM;
61     t->next = kt_typehead;
62     t->ops = ops;
63     kt_typehead = t;
64     return 0;
65 }
66
67 /*
68  * Resolve a key table name into a keytab object.
69  *
70  * The name is currently constrained to be of the form "type:residual";
71  *
72  * The "type" portion corresponds to one of the registered key table
73  * types, while the "residual" portion is specific to the
74  * particular keytab type.
75  */
76
77 krb5_error_code krb5_kt_resolve (name, ktid)
78     const char *name;
79     krb5_keytab *ktid;
80 {
81     struct krb5_kt_typelist *tlist;
82     char *pfx, *resid, *cp;
83     int pfxlen;
84     
85     cp = strchr (name, ':');
86     if (!cp)
87         return KRB5_KT_BADNAME;
88
89     pfxlen = cp - (char *)name;
90     resid = (char *)name + pfxlen + 1;
91         
92     pfx = malloc (pfxlen+1);
93     if (!pfx)
94         return ENOMEM;
95
96     memcpy (pfx, name, pfxlen);
97     pfx[pfxlen] = '\0';
98
99     *ktid = (krb5_keytab) 0;
100
101     for (tlist = kt_typehead; tlist; tlist = tlist->next) {
102         if (strcmp (tlist->ops->prefix, pfx) == 0) {
103             free(pfx);
104             return (*tlist->ops->resolve)(resid, ktid);
105         }
106     }
107     free(pfx);
108     return KRB5_KT_UNKNOWN_TYPE;
109 }