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"
39 struct any_data
*next
;
43 free_list (krb5_context context
, struct any_data
*a
)
45 struct any_data
*next
;
47 for (; a
!= NULL
; a
= next
) {
51 krb5_kt_close(context
, a
->kt
);
56 static krb5_error_code KRB5_CALLCONV
57 any_resolve(krb5_context context
, const char *name
, krb5_keytab id
)
59 struct any_data
*a
, *a0
= NULL
, *prev
= NULL
;
63 while (strsep_copy(&name
, ",", buf
, sizeof(buf
)) != -1) {
64 a
= calloc(1, sizeof(*a
));
66 ret
= krb5_enomem(context
);
71 a
->name
= strdup(buf
);
72 if (a
->name
== NULL
) {
73 ret
= krb5_enomem(context
);
81 ret
= krb5_kt_resolve (context
, buf
, &a
->kt
);
87 krb5_set_error_message(context
, ENOENT
, N_("empty ANY: keytab", ""));
93 free_list (context
, a0
);
97 static krb5_error_code KRB5_CALLCONV
98 any_get_name (krb5_context context
,
103 struct any_data
*a
= id
->data
;
104 strlcpy(name
, a
->name
, namesize
);
108 static krb5_error_code KRB5_CALLCONV
109 any_close (krb5_context context
,
112 struct any_data
*a
= id
->data
;
114 free_list (context
, a
);
118 struct any_cursor_extra_data
{
120 krb5_kt_cursor cursor
;
123 static krb5_error_code KRB5_CALLCONV
124 any_start_seq_get(krb5_context context
,
128 struct any_data
*a
= id
->data
;
129 struct any_cursor_extra_data
*ed
;
132 c
->data
= malloc (sizeof(struct any_cursor_extra_data
));
134 return krb5_enomem(context
);
135 ed
= (struct any_cursor_extra_data
*)c
->data
;
136 for (ed
->a
= a
; ed
->a
!= NULL
; ed
->a
= ed
->a
->next
) {
137 ret
= krb5_kt_start_seq_get(context
, ed
->a
->kt
, &ed
->cursor
);
144 krb5_clear_error_message (context
);
150 static krb5_error_code KRB5_CALLCONV
151 any_next_entry (krb5_context context
,
153 krb5_keytab_entry
*entry
,
154 krb5_kt_cursor
*cursor
)
156 krb5_error_code ret
, ret2
;
157 struct any_cursor_extra_data
*ed
;
159 ed
= (struct any_cursor_extra_data
*)cursor
->data
;
161 ret
= krb5_kt_next_entry(context
, ed
->a
->kt
, entry
, &ed
->cursor
);
164 else if (ret
!= KRB5_KT_END
)
167 ret2
= krb5_kt_end_seq_get (context
, ed
->a
->kt
, &ed
->cursor
);
170 while ((ed
->a
= ed
->a
->next
) != NULL
) {
171 ret2
= krb5_kt_start_seq_get(context
, ed
->a
->kt
, &ed
->cursor
);
176 krb5_clear_error_message (context
);
182 static krb5_error_code KRB5_CALLCONV
183 any_end_seq_get(krb5_context context
,
185 krb5_kt_cursor
*cursor
)
187 krb5_error_code ret
= 0;
188 struct any_cursor_extra_data
*ed
;
190 ed
= (struct any_cursor_extra_data
*)cursor
->data
;
192 ret
= krb5_kt_end_seq_get(context
, ed
->a
->kt
, &ed
->cursor
);
198 static krb5_error_code KRB5_CALLCONV
199 any_add_entry(krb5_context context
,
201 krb5_keytab_entry
*entry
)
203 struct any_data
*a
= id
->data
;
206 ret
= krb5_kt_add_entry(context
, a
->kt
, entry
);
207 if(ret
!= 0 && ret
!= KRB5_KT_NOWRITE
) {
208 krb5_set_error_message(context
, ret
,
209 N_("failed to add entry to %s", ""),
218 static krb5_error_code KRB5_CALLCONV
219 any_remove_entry(krb5_context context
,
221 krb5_keytab_entry
*entry
)
223 struct any_data
*a
= id
->data
;
225 krb5_boolean found
= FALSE
;
227 ret
= krb5_kt_remove_entry(context
, a
->kt
, entry
);
231 if(ret
!= KRB5_KT_NOWRITE
&& ret
!= KRB5_KT_NOTFOUND
) {
232 krb5_set_error_message(context
, ret
,
233 N_("Failed to remove keytab "
234 "entry from %s", "keytab name"),
242 return KRB5_KT_NOTFOUND
;
246 const krb5_kt_ops krb5_any_ops
= {