2 * Copyright (c) 2001-2002 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include "krb5_locl.h"
36 RCSID("$Id: keytab_any.c,v 1.6.4.1 2002/10/21 16:07:00 joda Exp $");
41 struct any_data *next;
45 free_list (krb5_context context, struct any_data *a)
47 struct any_data *next;
49 for (; a != NULL; a = next) {
53 krb5_kt_close(context, a->kt);
58 static krb5_error_code
59 any_resolve(krb5_context context, const char *name, krb5_keytab id)
61 struct any_data *a, *a0 = NULL, *prev = NULL;
65 while (strsep_copy(&name, ",", buf, sizeof(buf)) != -1) {
66 a = malloc(sizeof(*a));
73 a->name = strdup(buf);
74 if (a->name == NULL) {
75 krb5_set_error_string(context, "malloc: out of memory");
84 ret = krb5_kt_resolve (context, buf, &a->kt);
90 krb5_set_error_string(context, "empty ANY: keytab");
96 free_list (context, a0);
100 static krb5_error_code
101 any_get_name (krb5_context context,
106 struct any_data *a = id->data;
107 strlcpy(name, a->name, namesize);
111 static krb5_error_code
112 any_close (krb5_context context,
115 struct any_data *a = id->data;
117 free_list (context, a);
121 struct any_cursor_extra_data {
123 krb5_kt_cursor cursor;
126 static krb5_error_code
127 any_start_seq_get(krb5_context context,
131 struct any_data *a = id->data;
132 struct any_cursor_extra_data *ed;
135 c->data = malloc (sizeof(struct any_cursor_extra_data));
137 krb5_set_error_string (context, "malloc: out of memory");
140 ed = (struct any_cursor_extra_data *)c->data;
142 ret = krb5_kt_start_seq_get(context, ed->a->kt, &ed->cursor);
151 static krb5_error_code
152 any_next_entry (krb5_context context,
154 krb5_keytab_entry *entry,
155 krb5_kt_cursor *cursor)
157 krb5_error_code ret, ret2;
158 struct any_cursor_extra_data *ed;
160 ed = (struct any_cursor_extra_data *)cursor->data;
162 ret = krb5_kt_next_entry(context, ed->a->kt, entry, &ed->cursor);
165 else if (ret == KRB5_KT_END) {
166 ret2 = krb5_kt_end_seq_get (context, ed->a->kt, &ed->cursor);
169 while ((ed->a = ed->a->next) != NULL) {
170 ret2 = krb5_kt_start_seq_get(context, ed->a->kt, &ed->cursor);
175 krb5_clear_error_string (context);
180 } while (ret == KRB5_KT_END);
184 static krb5_error_code
185 any_end_seq_get(krb5_context context,
187 krb5_kt_cursor *cursor)
189 krb5_error_code ret = 0;
190 struct any_cursor_extra_data *ed;
192 ed = (struct any_cursor_extra_data *)cursor->data;
194 ret = krb5_kt_end_seq_get(context, ed->a->kt, &ed->cursor);
200 static krb5_error_code
201 any_add_entry(krb5_context context,
203 krb5_keytab_entry *entry)
205 struct any_data *a = id->data;
208 ret = krb5_kt_add_entry(context, a->kt, entry);
209 if(ret != 0 && ret != KRB5_KT_NOWRITE) {
210 krb5_set_error_string(context, "failed to add entry to %s",
219 static krb5_error_code
220 any_remove_entry(krb5_context context,
222 krb5_keytab_entry *entry)
224 struct any_data *a = id->data;
228 ret = krb5_kt_remove_entry(context, a->kt, entry);
232 if(ret != KRB5_KT_NOWRITE && ret != KRB5_KT_NOTFOUND) {
233 krb5_set_error_string(context, "failed to remove entry from %s",
241 return KRB5_KT_NOTFOUND;
245 const krb5_kt_ops krb5_any_ops = {