2
2
* lib/krb5/keytab/ktbase.c
4
* Copyright 1990 by the Massachusetts Institute of Technology.
4
* Copyright 1990,2008 by the Massachusetts Institute of Technology.
5
5
* All Rights Reserved.
7
7
* Export of this software from the United States of America may
24
24
* or implied warranty.
27
* Copyright 2007 by Secure Endpoints Inc.
29
* Permission is hereby granted, free of charge, to any person
30
* obtaining a copy of this software and associated documentation files
31
* (the "Software"), to deal in the Software without restriction,
32
* including without limitation the rights to use, copy, modify, merge,
33
* publish, distribute, sublicense, and/or sell copies of the Software,
34
* and to permit persons to whom the Software is furnished to do so,
35
* subject to the following conditions:
37
* The above copyright notice and this permission notice shall be
38
* included in all copies or substantial portions of the Software.
40
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
41
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
42
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
43
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
44
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
45
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
46
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
49
* Registration functions for keytab.
31
53
#include "k5-thread.h"
32
54
#include "kt-int.h"
34
58
extern const krb5_kt_ops krb5_ktf_ops;
35
59
extern const krb5_kt_ops krb5_ktf_writable_ops;
36
60
extern const krb5_kt_ops krb5_kts_ops;
61
extern const krb5_kt_ops krb5_mkt_ops;
38
63
struct krb5_kt_typelist {
39
64
const krb5_kt_ops *ops;
40
65
const struct krb5_kt_typelist *next;
67
const static struct krb5_kt_typelist krb5_kt_typelist_srvtab = {
71
const static struct krb5_kt_typelist krb5_kt_typelist_memory = {
73
&krb5_kt_typelist_srvtab
42
75
const static struct krb5_kt_typelist krb5_kt_typelist_wrfile = {
43
76
&krb5_ktf_writable_ops,
77
&krb5_kt_typelist_memory
46
79
const static struct krb5_kt_typelist krb5_kt_typelist_file = {
48
81
&krb5_kt_typelist_wrfile
50
const static struct krb5_kt_typelist krb5_kt_typelist_srvtab = {
52
&krb5_kt_typelist_file
54
static const struct krb5_kt_typelist *kt_typehead = &krb5_kt_typelist_srvtab;
84
static const struct krb5_kt_typelist *kt_typehead = &krb5_kt_typelist_file;
55
85
/* Lock for protecting the type list. */
56
86
static k5_mutex_t kt_typehead_lock = K5_MUTEX_PARTIAL_INITIALIZER;
58
88
int krb5int_kt_initialize(void)
60
return k5_mutex_finish_init(&kt_typehead_lock);
92
err = k5_mutex_finish_init(&kt_typehead_lock);
95
err = krb5int_mkt_initialize();
64
104
krb5int_kt_finalize(void)
66
struct krb5_kt_typelist *t, *t_next;
106
const struct krb5_kt_typelist *t, *t_next;
67
108
k5_mutex_destroy(&kt_typehead_lock);
68
for (t = kt_typehead; t != &krb5_kt_typelist_srvtab; t = t_next) {
109
for (t = kt_typehead; t != &krb5_kt_typelist_file; t = t_next) {
111
free((struct krb5_kt_typelist *)t);
114
krb5int_mkt_finalize();
161
209
k5_mutex_unlock(&kt_typehead_lock);
162
210
for (; tlist; tlist = tlist->next) {
163
211
if (strcmp (tlist->ops->prefix, pfx) == 0) {
165
return (*tlist->ops->resolve)(context, resid, ktid);
212
err = (*tlist->ops->resolve)(context, resid, ktid);
216
err = KRB5_KT_UNKNOWN_TYPE;
169
return KRB5_KT_UNKNOWN_TYPE;