1 Adds an "ANY" keytab type which is a list of other keytab locations to search
2 when searching for a specific entry. When iterated through, it only presents
3 the contents of the first keytab.
5 diff -up /dev/null krb5-1.7/src/lib/krb5/keytab/kt_any.c
6 --- /dev/null 2009-06-04 10:34:55.169007373 -0400
7 +++ krb5-1.7/src/lib/krb5/keytab/kt_any.c 2009-06-04 13:54:36.000000000 -0400
10 + * lib/krb5/keytab/kt_any.c
12 + * Copyright 1998, 1999 by the Massachusetts Institute of Technology.
13 + * All Rights Reserved.
15 + * Export of this software from the United States of America may
16 + * require a specific license from the United States Government.
17 + * It is the responsibility of any person or organization contemplating
18 + * export to obtain such a license before exporting.
20 + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
21 + * distribute this software and its documentation for any purpose and
22 + * without fee is hereby granted, provided that the above copyright
23 + * notice appear in all copies and that both that copyright notice and
24 + * this permission notice appear in supporting documentation, and that
25 + * the name of M.I.T. not be used in advertising or publicity pertaining
26 + * to distribution of the software without specific, written prior
27 + * permission. M.I.T. makes no representations about the suitability of
28 + * this software for any purpose. It is provided "as is" without express
29 + * or implied warranty.
37 +typedef struct _krb5_ktany_data {
39 + krb5_keytab *choices;
43 +typedef struct _krb5_ktany_cursor_data {
45 + krb5_kt_cursor cursor;
46 +} krb5_ktany_cursor_data;
48 +static krb5_error_code krb5_ktany_resolve
52 +static krb5_error_code krb5_ktany_get_name
53 + (krb5_context context,
57 +static krb5_error_code krb5_ktany_close
58 + (krb5_context context,
60 +static krb5_error_code krb5_ktany_get_entry
61 + (krb5_context context,
63 + krb5_const_principal principal,
65 + krb5_enctype enctype,
66 + krb5_keytab_entry *entry);
67 +static krb5_error_code krb5_ktany_start_seq_get
68 + (krb5_context context,
70 + krb5_kt_cursor *cursorp);
71 +static krb5_error_code krb5_ktany_next_entry
72 + (krb5_context context,
74 + krb5_keytab_entry *entry,
75 + krb5_kt_cursor *cursor);
76 +static krb5_error_code krb5_ktany_end_seq_get
77 + (krb5_context context,
79 + krb5_kt_cursor *cursor);
81 + (krb5_context context,
82 + krb5_ktany_data *data,
85 +struct _krb5_kt_ops krb5_kta_ops = {
87 + "ANY", /* Prefix -- this string should not appear anywhere else! */
89 + krb5_ktany_get_name,
91 + krb5_ktany_get_entry,
92 + krb5_ktany_start_seq_get,
93 + krb5_ktany_next_entry,
94 + krb5_ktany_end_seq_get,
100 +static krb5_error_code
101 +krb5_ktany_resolve(context, name, id)
102 + krb5_context context;
108 + krb5_error_code kerror;
109 + krb5_ktany_data *data;
112 + /* Allocate space for our data and remember a copy of the name. */
113 + if ((data = (krb5_ktany_data *)malloc(sizeof(krb5_ktany_data))) == NULL)
115 + if ((data->name = (char *)malloc(strlen(name) + 1)) == NULL) {
119 + strcpy(data->name, name);
121 + /* Count the number of choices and allocate memory for them. */
122 + data->nchoices = 1;
123 + for (p = name; (q = strchr(p, ',')) != NULL; p = q + 1)
125 + if ((data->choices = (krb5_keytab *)
126 + malloc(data->nchoices * sizeof(krb5_keytab))) == NULL) {
127 + krb5_xfree(data->name);
132 + /* Resolve each of the choices. */
134 + for (p = name; (q = strchr(p, ',')) != NULL; p = q + 1) {
135 + /* Make a copy of the choice name so we can terminate it. */
136 + if ((copy = (char *)malloc(q - p + 1)) == NULL) {
137 + cleanup(context, data, i);
140 + memcpy(copy, p, q - p);
143 + /* Try resolving the choice name. */
144 + kerror = krb5_kt_resolve(context, copy, &data->choices[i]);
147 + cleanup(context, data, i);
152 + if ((kerror = krb5_kt_resolve(context, p, &data->choices[i]))) {
153 + cleanup(context, data, i);
157 + /* Allocate and fill in an ID for the caller. */
158 + if ((*id = (krb5_keytab)malloc(sizeof(**id))) == NULL) {
159 + cleanup(context, data, i);
162 + (*id)->ops = &krb5_kta_ops;
163 + (*id)->data = (krb5_pointer)data;
164 + (*id)->magic = KV5M_KEYTAB;
169 +static krb5_error_code
170 +krb5_ktany_get_name(context, id, name, len)
171 + krb5_context context;
176 + krb5_ktany_data *data = (krb5_ktany_data *)id->data;
178 + if (len < strlen(data->name) + 1)
179 + return(KRB5_KT_NAME_TOOLONG);
180 + strcpy(name, data->name);
184 +static krb5_error_code
185 +krb5_ktany_close(context, id)
186 + krb5_context context;
189 + krb5_ktany_data *data = (krb5_ktany_data *)id->data;
191 + cleanup(context, data, data->nchoices);
197 +static krb5_error_code
198 +krb5_ktany_get_entry(context, id, principal, kvno, enctype, entry)
199 + krb5_context context;
201 + krb5_const_principal principal;
203 + krb5_enctype enctype;
204 + krb5_keytab_entry *entry;
206 + krb5_ktany_data *data = (krb5_ktany_data *)id->data;
207 + krb5_error_code kerror = KRB5_KT_NOTFOUND;
210 + for (i = 0; i < data->nchoices; i++) {
211 + if ((kerror = krb5_kt_get_entry(context, data->choices[i], principal,
212 + kvno, enctype, entry)) != ENOENT)
218 +static krb5_error_code
219 +krb5_ktany_start_seq_get(context, id, cursorp)
220 + krb5_context context;
222 + krb5_kt_cursor *cursorp;
224 + krb5_ktany_data *data = (krb5_ktany_data *)id->data;
225 + krb5_ktany_cursor_data *cdata;
226 + krb5_error_code kerror = ENOENT;
229 + if ((cdata = (krb5_ktany_cursor_data *)
230 + malloc(sizeof(krb5_ktany_cursor_data))) == NULL)
233 + /* Find a choice which can handle the serialization request. */
234 + for (i = 0; i < data->nchoices; i++) {
235 + if ((kerror = krb5_kt_start_seq_get(context, data->choices[i],
236 + &cdata->cursor)) == 0)
238 + else if (kerror != ENOENT) {
244 + if (i == data->nchoices) {
245 + /* Everyone returned ENOENT, so no go. */
251 + *cursorp = (krb5_kt_cursor)cdata;
255 +static krb5_error_code
256 +krb5_ktany_next_entry(context, id, entry, cursor)
257 + krb5_context context;
259 + krb5_keytab_entry *entry;
260 + krb5_kt_cursor *cursor;
262 + krb5_ktany_data *data = (krb5_ktany_data *)id->data;
263 + krb5_ktany_cursor_data *cdata = (krb5_ktany_cursor_data *)*cursor;
264 + krb5_keytab choice_id;
266 + choice_id = data->choices[cdata->which];
267 + return(krb5_kt_next_entry(context, choice_id, entry, &cdata->cursor));
270 +static krb5_error_code
271 +krb5_ktany_end_seq_get(context, id, cursor)
272 + krb5_context context;
274 + krb5_kt_cursor *cursor;
276 + krb5_ktany_data *data = (krb5_ktany_data *)id->data;
277 + krb5_ktany_cursor_data *cdata = (krb5_ktany_cursor_data *)*cursor;
278 + krb5_keytab choice_id;
279 + krb5_error_code kerror;
281 + choice_id = data->choices[cdata->which];
282 + kerror = krb5_kt_end_seq_get(context, choice_id, &cdata->cursor);
288 +cleanup(context, data, nchoices)
289 + krb5_context context;
290 + krb5_ktany_data *data;
295 + krb5_xfree(data->name);
296 + for (i = 0; i < nchoices; i++)
297 + krb5_kt_close(context, data->choices[i]);
298 + krb5_xfree(data->choices);
301 diff -up krb5-1.7/src/lib/krb5/keytab/ktbase.c krb5-1.7/src/lib/krb5/keytab/ktbase.c
302 --- krb5-1.7/src/lib/krb5/keytab/ktbase.c 2009-02-18 13:18:56.000000000 -0500
303 +++ krb5-1.7/src/lib/krb5/keytab/ktbase.c 2009-06-04 13:54:36.000000000 -0400
304 @@ -59,14 +59,19 @@ extern const krb5_kt_ops krb5_ktf_ops;
305 extern const krb5_kt_ops krb5_ktf_writable_ops;
306 extern const krb5_kt_ops krb5_kts_ops;
307 extern const krb5_kt_ops krb5_mkt_ops;
308 +extern const krb5_kt_ops krb5_kta_ops;
310 struct krb5_kt_typelist {
311 const krb5_kt_ops *ops;
312 const struct krb5_kt_typelist *next;
314 +static struct krb5_kt_typelist krb5_kt_typelist_any = {
318 const static struct krb5_kt_typelist krb5_kt_typelist_srvtab = {
321 + &krb5_kt_typelist_any
323 const static struct krb5_kt_typelist krb5_kt_typelist_memory = {
325 diff -up krb5-1.7/src/lib/krb5/keytab/Makefile.in krb5-1.7/src/lib/krb5/keytab/Makefile.in
326 --- krb5-1.7/src/lib/krb5/keytab/Makefile.in 2009-01-05 15:27:53.000000000 -0500
327 +++ krb5-1.7/src/lib/krb5/keytab/Makefile.in 2009-06-04 13:54:36.000000000 -0400
328 @@ -19,6 +19,7 @@ STLIBOBJS= \
336 @@ -31,6 +32,7 @@ OBJS= \
337 $(OUTPRE)ktfr_entry.$(OBJEXT) \
338 $(OUTPRE)ktremove.$(OBJEXT) \
339 $(OUTPRE)ktfns.$(OBJEXT) \
340 + $(OUTPRE)kt_any.$(OBJEXT) \
341 $(OUTPRE)kt_file.$(OBJEXT) \
342 $(OUTPRE)kt_memory.$(OBJEXT) \
343 $(OUTPRE)kt_srvtab.$(OBJEXT) \
344 @@ -43,6 +45,7 @@ SRCS= \
345 $(srcdir)/ktfr_entry.c \
346 $(srcdir)/ktremove.c \
348 + $(srcdir)/kt_any.c \
349 $(srcdir)/kt_file.c \
350 $(srcdir)/kt_memory.c \
351 $(srcdir)/kt_srvtab.c \