~ubuntu-branches/ubuntu/maverick/krb5/maverick

« back to all changes in this revision

Viewing changes to src/lib/krb5/keytab/ktbase.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hartman
  • Date: 2009-05-07 16:16:34 UTC
  • mfrom: (13.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20090507161634-xqyk0s9na0le4flj
Tags: 1.7dfsg~beta1-4
When  decrypting the TGS response fails with the subkey, try with the
session key to work around Heimdal bug, Closes: #527353 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * lib/krb5/keytab/ktbase.c
3
3
 *
4
 
 * Copyright 1990 by the Massachusetts Institute of Technology.
 
4
 * Copyright 1990,2008 by the Massachusetts Institute of Technology.
5
5
 * All Rights Reserved.
6
6
 *
7
7
 * Export of this software from the United States of America may
24
24
 * or implied warranty.
25
25
 * 
26
26
 *
 
27
 * Copyright 2007 by Secure Endpoints Inc.
 
28
 *
 
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:
 
36
 *
 
37
 * The above copyright notice and this permission notice shall be
 
38
 * included in all copies or substantial portions of the Software.
 
39
 *
 
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
 
47
 * SOFTWARE.
 
48
 *
27
49
 * Registration functions for keytab.
28
50
 */
29
51
 
31
53
#include "k5-thread.h"
32
54
#include "kt-int.h"
33
55
 
 
56
#ifndef LEAN_CLIENT
 
57
 
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;
37
62
 
38
63
struct krb5_kt_typelist {
39
64
    const krb5_kt_ops *ops;
40
65
    const struct krb5_kt_typelist *next;
41
66
};
 
67
const static struct krb5_kt_typelist krb5_kt_typelist_srvtab = {
 
68
    &krb5_kts_ops,
 
69
    NULL
 
70
};
 
71
const static struct krb5_kt_typelist krb5_kt_typelist_memory = {
 
72
    &krb5_mkt_ops,
 
73
    &krb5_kt_typelist_srvtab
 
74
};
42
75
const static struct krb5_kt_typelist krb5_kt_typelist_wrfile  = {
43
76
    &krb5_ktf_writable_ops,
44
 
    0
 
77
    &krb5_kt_typelist_memory
45
78
};
46
79
const static struct krb5_kt_typelist krb5_kt_typelist_file  = {
47
80
    &krb5_ktf_ops,
48
81
    &krb5_kt_typelist_wrfile
49
82
};
50
 
const static struct krb5_kt_typelist krb5_kt_typelist_srvtab = {
51
 
    &krb5_kts_ops,
52
 
    &krb5_kt_typelist_file
53
 
};
54
 
static const struct krb5_kt_typelist *kt_typehead = &krb5_kt_typelist_srvtab;
 
83
 
 
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;
57
87
 
58
88
int krb5int_kt_initialize(void)
59
89
{
60
 
    return k5_mutex_finish_init(&kt_typehead_lock);
 
90
    int err;
 
91
 
 
92
    err = k5_mutex_finish_init(&kt_typehead_lock);
 
93
    if (err)
 
94
        goto done;
 
95
    err = krb5int_mkt_initialize();
 
96
    if (err)
 
97
        goto done;
 
98
 
 
99
  done:
 
100
    return(err);
61
101
}
62
102
 
63
103
void
64
104
krb5int_kt_finalize(void)
65
105
{
66
 
    struct krb5_kt_typelist *t, *t_next;
 
106
    const struct krb5_kt_typelist *t, *t_next;
 
107
 
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) {
69
110
        t_next = t->next;
70
 
        free(t);
 
111
        free((struct krb5_kt_typelist *)t);
71
112
    }
 
113
 
 
114
    krb5int_mkt_finalize();
72
115
}
73
116
 
74
117
 
119
162
krb5_kt_resolve (krb5_context context, const char *name, krb5_keytab *ktid)
120
163
{
121
164
    const struct krb5_kt_typelist *tlist;
122
 
    char *pfx;
 
165
    char *pfx = NULL;
123
166
    unsigned int pfxlen;
124
167
    const char *cp, *resid;
125
 
    krb5_error_code err;
 
168
    krb5_error_code err = 0;
126
169
    
127
170
    cp = strchr (name, ':');
128
171
    if (!cp) {
138
181
            return ENOMEM;
139
182
 
140
183
        resid = name;
 
184
    } else if (name[0] == '/') {
 
185
        pfx = strdup("FILE");
 
186
        if (!pfx)
 
187
            return ENOMEM;
 
188
        resid = name;
141
189
    } else {
142
190
        resid = name + pfxlen + 1;
143
191
        
153
201
 
154
202
    err = k5_mutex_lock(&kt_typehead_lock);
155
203
    if (err)
156
 
        return err;
 
204
        goto cleanup;
157
205
    tlist = kt_typehead;
158
206
    /* Don't need to hold the lock, since entries are never modified
159
207
       or removed once they're in the list.  Just need to protect
161
209
    k5_mutex_unlock(&kt_typehead_lock);
162
210
    for (; tlist; tlist = tlist->next) {
163
211
        if (strcmp (tlist->ops->prefix, pfx) == 0) {
164
 
            free(pfx);
165
 
            return (*tlist->ops->resolve)(context, resid, ktid);
 
212
            err = (*tlist->ops->resolve)(context, resid, ktid);
 
213
            goto cleanup;
166
214
        }
167
215
    }
 
216
    err = KRB5_KT_UNKNOWN_TYPE;
 
217
 
 
218
cleanup:
168
219
    free(pfx);
169
 
    return KRB5_KT_UNKNOWN_TYPE;
 
220
    return err;
170
221
}
171
222
 
172
223
/*
242
293
{
243
294
    return(krb5_register_serializer(kcontext, &krb5_keytab_ser_entry));
244
295
}
 
296
#endif /* LEAN_CLIENT */
 
297