xref: /freebsd/crypto/heimdal/lib/krb5/test_cc.c (revision eb69d1f144a6fcc765d1b9d44a5ae8082353e70b)
1 /*
2  * Copyright (c) 2003 - 2007 Kungliga Tekniska Högskolan
3  * (Royal Institute of Technology, Stockholm, Sweden).
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *
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.
16  *
17  * 3. Neither the name of KTH nor the names of its contributors may be
18  *    used to endorse or promote products derived from this software without
19  *    specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
22  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
32 
33 #include "krb5_locl.h"
34 #include <getarg.h>
35 #include <err.h>
36 
37 static int debug_flag	= 0;
38 static int version_flag = 0;
39 static int help_flag	= 0;
40 
41 #ifdef KRB5_USE_PATH_TOKENS
42 #define TEST_CC_NAME "%{TEMP}/krb5-cc-test-foo"
43 #else
44 #define TEST_CC_NAME "/tmp/krb5-cc-test-foo"
45 #endif
46 
47 static void
48 test_default_name(krb5_context context)
49 {
50     krb5_error_code ret;
51     const char *p, *test_cc_name = TEST_CC_NAME;
52     char *p1, *p2, *p3;
53 
54     p = krb5_cc_default_name(context);
55     if (p == NULL)
56 	krb5_errx (context, 1, "krb5_cc_default_name 1 failed");
57     p1 = estrdup(p);
58 
59     ret = krb5_cc_set_default_name(context, NULL);
60     if (p == NULL)
61 	krb5_errx (context, 1, "krb5_cc_set_default_name failed");
62 
63     p = krb5_cc_default_name(context);
64     if (p == NULL)
65 	krb5_errx (context, 1, "krb5_cc_default_name 2 failed");
66     p2 = estrdup(p);
67 
68     if (strcmp(p1, p2) != 0)
69 	krb5_errx (context, 1, "krb5_cc_default_name no longer same");
70 
71     ret = krb5_cc_set_default_name(context, test_cc_name);
72     if (p == NULL)
73 	krb5_errx (context, 1, "krb5_cc_set_default_name 1 failed");
74 
75     p = krb5_cc_default_name(context);
76     if (p == NULL)
77 	krb5_errx (context, 1, "krb5_cc_default_name 2 failed");
78     p3 = estrdup(p);
79 
80 #ifndef KRB5_USE_PATH_TOKENS
81     /* If we are using path tokens, we don't expect the p3 and
82        test_cc_name to match since p3 is going to have expanded
83        tokens. */
84     if (strcmp(p3, test_cc_name) != 0)
85 	krb5_errx (context, 1, "krb5_cc_set_default_name 1 failed");
86 #endif
87 
88     free(p1);
89     free(p2);
90     free(p3);
91 }
92 
93 /*
94  * Check that a closed cc still keeps it data and that it's no longer
95  * there when it's destroyed.
96  */
97 
98 static void
99 test_mcache(krb5_context context)
100 {
101     krb5_error_code ret;
102     krb5_ccache id, id2;
103     const char *nc, *tc;
104     char *c;
105     krb5_principal p, p2;
106 
107     ret = krb5_parse_name(context, "lha@SU.SE", &p);
108     if (ret)
109 	krb5_err(context, 1, ret, "krb5_parse_name");
110 
111     ret = krb5_cc_new_unique(context, krb5_cc_type_memory, NULL, &id);
112     if (ret)
113 	krb5_err(context, 1, ret, "krb5_cc_new_unique");
114 
115     ret = krb5_cc_initialize(context, id, p);
116     if (ret)
117 	krb5_err(context, 1, ret, "krb5_cc_initialize");
118 
119     nc = krb5_cc_get_name(context, id);
120     if (nc == NULL)
121 	krb5_errx(context, 1, "krb5_cc_get_name");
122 
123     tc = krb5_cc_get_type(context, id);
124     if (tc == NULL)
125 	krb5_errx(context, 1, "krb5_cc_get_name");
126 
127     if (asprintf(&c, "%s:%s", tc, nc) < 0 || c == NULL)
128 	errx(1, "malloc");
129 
130     krb5_cc_close(context, id);
131 
132     ret = krb5_cc_resolve(context, c, &id2);
133     if (ret)
134 	krb5_err(context, 1, ret, "krb5_cc_resolve");
135 
136     ret = krb5_cc_get_principal(context, id2, &p2);
137     if (ret)
138 	krb5_err(context, 1, ret, "krb5_cc_get_principal");
139 
140     if (krb5_principal_compare(context, p, p2) == FALSE)
141 	krb5_errx(context, 1, "p != p2");
142 
143     krb5_cc_destroy(context, id2);
144     krb5_free_principal(context, p);
145     krb5_free_principal(context, p2);
146 
147     ret = krb5_cc_resolve(context, c, &id2);
148     if (ret)
149 	krb5_err(context, 1, ret, "krb5_cc_resolve");
150 
151     ret = krb5_cc_get_principal(context, id2, &p2);
152     if (ret == 0)
153 	krb5_errx(context, 1, "krb5_cc_get_principal");
154 
155     krb5_cc_destroy(context, id2);
156     free(c);
157 }
158 
159 /*
160  * Test that init works on a destroyed cc.
161  */
162 
163 static void
164 test_init_vs_destroy(krb5_context context, const char *type)
165 {
166     krb5_error_code ret;
167     krb5_ccache id, id2;
168     krb5_principal p, p2;
169     char *n = NULL;
170 
171     ret = krb5_parse_name(context, "lha@SU.SE", &p);
172     if (ret)
173 	krb5_err(context, 1, ret, "krb5_parse_name");
174 
175     ret = krb5_cc_new_unique(context, type, NULL, &id);
176     if (ret)
177 	krb5_err(context, 1, ret, "krb5_cc_new_unique: %s", type);
178 
179     if (asprintf(&n, "%s:%s",
180 		 krb5_cc_get_type(context, id),
181 		 krb5_cc_get_name(context, id)) < 0 || n == NULL)
182 	errx(1, "malloc");
183 
184 
185     ret = krb5_cc_resolve(context, n, &id2);
186     free(n);
187     if (ret)
188 	krb5_err(context, 1, ret, "krb5_cc_resolve");
189 
190     krb5_cc_destroy(context, id);
191 
192     ret = krb5_cc_initialize(context, id2, p);
193     if (ret)
194 	krb5_err(context, 1, ret, "krb5_cc_initialize");
195 
196     ret = krb5_cc_get_principal(context, id2, &p2);
197     if (ret)
198 	krb5_err(context, 1, ret, "krb5_cc_get_principal");
199 
200     krb5_cc_destroy(context, id2);
201     krb5_free_principal(context, p);
202     krb5_free_principal(context, p2);
203 }
204 
205 static void
206 test_cache_remove(krb5_context context, const char *type)
207 {
208     krb5_error_code ret;
209     krb5_ccache id;
210     krb5_principal p;
211     krb5_creds cred;
212 
213     ret = krb5_parse_name(context, "lha@SU.SE", &p);
214     if (ret)
215 	krb5_err(context, 1, ret, "krb5_parse_name");
216 
217     ret = krb5_cc_new_unique(context, type, NULL, &id);
218     if (ret)
219 	krb5_err(context, 1, ret, "krb5_cc_gen_new: %s", type);
220 
221     ret = krb5_cc_initialize(context, id, p);
222     if (ret)
223 	krb5_err(context, 1, ret, "krb5_cc_initialize");
224 
225     /* */
226     memset(&cred, 0, sizeof(cred));
227     ret = krb5_parse_name(context, "krbtgt/SU.SE@SU.SE", &cred.server);
228     if (ret)
229 	krb5_err(context, 1, ret, "krb5_parse_name");
230     ret = krb5_parse_name(context, "lha@SU.SE", &cred.client);
231     if (ret)
232 	krb5_err(context, 1, ret, "krb5_parse_name");
233 
234     ret = krb5_cc_store_cred(context, id, &cred);
235     if (ret)
236 	krb5_err(context, 1, ret, "krb5_cc_store_cred");
237 
238     ret = krb5_cc_remove_cred(context, id, 0, &cred);
239     if (ret)
240 	krb5_err(context, 1, ret, "krb5_cc_remove_cred");
241 
242     ret = krb5_cc_destroy(context, id);
243     if (ret)
244 	krb5_err(context, 1, ret, "krb5_cc_destroy");
245 
246     krb5_free_principal(context, p);
247     krb5_free_principal(context, cred.server);
248     krb5_free_principal(context, cred.client);
249 }
250 
251 static void
252 test_mcc_default(void)
253 {
254     krb5_context context;
255     krb5_error_code ret;
256     krb5_ccache id, id2;
257     int i;
258 
259     for (i = 0; i < 10; i++) {
260 
261 	ret = krb5_init_context(&context);
262 	if (ret)
263 	    krb5_err(context, 1, ret, "krb5_init_context");
264 
265 	ret = krb5_cc_set_default_name(context, "MEMORY:foo");
266 	if (ret)
267 	    krb5_err(context, 1, ret, "krb5_cc_set_default_name");
268 
269 	ret = krb5_cc_default(context, &id);
270 	if (ret)
271 	    krb5_err(context, 1, ret, "krb5_cc_default");
272 
273 	ret = krb5_cc_default(context, &id2);
274 	if (ret)
275 	    krb5_err(context, 1, ret, "krb5_cc_default");
276 
277 	ret = krb5_cc_close(context, id);
278 	if (ret)
279 	    krb5_err(context, 1, ret, "krb5_cc_close");
280 
281 	ret = krb5_cc_close(context, id2);
282 	if (ret)
283 	    krb5_err(context, 1, ret, "krb5_cc_close");
284 
285 	krb5_free_context(context);
286     }
287 }
288 
289 struct {
290     char *str;
291     int fail;
292     char *res;
293 } cc_names[] = {
294     { "foo", 0, "foo" },
295     { "foo%}", 0, "foo%}" },
296     { "%{uid}", 0 },
297     { "foo%{null}", 0, "foo" },
298     { "foo%{null}bar", 0, "foobar" },
299     { "%{", 1 },
300     { "%{foo %{", 1 },
301     { "%{{", 1 },
302     { "%{{}", 1 },
303     { "%{nulll}", 1 },
304     { "%{does not exist}", 1 },
305     { "%{}", 1 },
306 #ifdef KRB5_USE_PATH_TOKENS
307     { "%{APPDATA}", 0 },
308     { "%{COMMON_APPDATA}", 0},
309     { "%{LOCAL_APPDATA}", 0},
310     { "%{SYSTEM}", 0},
311     { "%{WINDOWS}", 0},
312     { "%{TEMP}", 0},
313     { "%{USERID}", 0},
314     { "%{uid}", 0},
315     { "%{USERCONFIG}", 0},
316     { "%{COMMONCONFIG}", 0},
317     { "%{LIBDIR}", 0},
318     { "%{BINDIR}", 0},
319     { "%{LIBEXEC}", 0},
320     { "%{SBINDIR}", 0},
321 #endif
322 };
323 
324 static void
325 test_def_cc_name(krb5_context context)
326 {
327     krb5_error_code ret;
328     char *str;
329     int i;
330 
331     for (i = 0; i < sizeof(cc_names)/sizeof(cc_names[0]); i++) {
332 	ret = _krb5_expand_default_cc_name(context, cc_names[i].str, &str);
333 	if (ret) {
334 	    if (cc_names[i].fail == 0)
335 		krb5_errx(context, 1, "test %d \"%s\" failed",
336 			  i, cc_names[i].str);
337 	} else {
338 	    if (cc_names[i].fail)
339 		krb5_errx(context, 1, "test %d \"%s\" was successful",
340 			  i, cc_names[i].str);
341 	    if (cc_names[i].res && strcmp(cc_names[i].res, str) != 0)
342 		krb5_errx(context, 1, "test %d %s != %s",
343 			  i, cc_names[i].res, str);
344 	    if (debug_flag)
345 		printf("%s => %s\n", cc_names[i].str, str);
346 	    free(str);
347 	}
348     }
349 }
350 
351 static void
352 test_cache_find(krb5_context context, const char *principal, int find)
353 {
354     krb5_principal client;
355     krb5_error_code ret;
356     krb5_ccache id = NULL;
357 
358     ret = krb5_parse_name(context, principal, &client);
359     if (ret)
360 	krb5_err(context, 1, ret, "parse_name for %s failed", principal);
361 
362     ret = krb5_cc_cache_match(context, client, &id);
363     if (ret && find)
364 	krb5_err(context, 1, ret, "cc_cache_match for %s failed", principal);
365     if (ret == 0 && !find)
366 	krb5_err(context, 1, ret, "cc_cache_match for %s found", principal);
367 
368     if (id)
369 	krb5_cc_close(context, id);
370     krb5_free_principal(context, client);
371 }
372 
373 
374 static void
375 test_cache_iter(krb5_context context, const char *type, int destroy)
376 {
377     krb5_cc_cache_cursor cursor;
378     krb5_error_code ret;
379     krb5_ccache id;
380 
381     ret = krb5_cc_cache_get_first (context, type, &cursor);
382     if (ret == KRB5_CC_NOSUPP)
383 	return;
384     else if (ret)
385 	krb5_err(context, 1, ret, "krb5_cc_cache_get_first(%s)", type);
386 
387 
388     while ((ret = krb5_cc_cache_next (context, cursor, &id)) == 0) {
389 	krb5_principal principal;
390 	char *name;
391 
392 	if (debug_flag)
393 	    printf("name: %s\n", krb5_cc_get_name(context, id));
394 	ret = krb5_cc_get_principal(context, id, &principal);
395 	if (ret == 0) {
396 	    ret = krb5_unparse_name(context, principal, &name);
397 	    if (ret == 0) {
398 		if (debug_flag)
399 		    printf("\tprincipal: %s\n", name);
400 		free(name);
401 	    }
402 	    krb5_free_principal(context, principal);
403 	}
404 	if (destroy)
405 	    krb5_cc_destroy(context, id);
406 	else
407 	    krb5_cc_close(context, id);
408     }
409 
410     krb5_cc_cache_end_seq_get(context, cursor);
411 }
412 
413 static void
414 test_cache_iter_all(krb5_context context)
415 {
416     krb5_cccol_cursor cursor;
417     krb5_error_code ret;
418     krb5_ccache id;
419 
420     ret = krb5_cccol_cursor_new (context, &cursor);
421     if (ret)
422 	krb5_err(context, 1, ret, "krb5_cccol_cursor_new");
423 
424 
425     while ((ret = krb5_cccol_cursor_next (context, cursor, &id)) == 0 && id != NULL) {
426 	krb5_principal principal;
427 	char *name;
428 
429 	if (debug_flag)
430 	    printf("name: %s\n", krb5_cc_get_name(context, id));
431 	ret = krb5_cc_get_principal(context, id, &principal);
432 	if (ret == 0) {
433 	    ret = krb5_unparse_name(context, principal, &name);
434 	    if (ret == 0) {
435 		if (debug_flag)
436 		    printf("\tprincipal: %s\n", name);
437 		free(name);
438 	    }
439 	    krb5_free_principal(context, principal);
440 	}
441 	krb5_cc_close(context, id);
442     }
443 
444     krb5_cccol_cursor_free(context, &cursor);
445 }
446 
447 
448 static void
449 test_copy(krb5_context context, const char *from, const char *to)
450 {
451     krb5_ccache fromid, toid;
452     krb5_error_code ret;
453     krb5_principal p, p2;
454 
455     ret = krb5_parse_name(context, "lha@SU.SE", &p);
456     if (ret)
457 	krb5_err(context, 1, ret, "krb5_parse_name");
458 
459     ret = krb5_cc_new_unique(context, from, NULL, &fromid);
460     if (ret)
461 	krb5_err(context, 1, ret, "krb5_cc_new_unique: %s", from);
462 
463     ret = krb5_cc_initialize(context, fromid, p);
464     if (ret)
465 	krb5_err(context, 1, ret, "krb5_cc_initialize");
466 
467     ret = krb5_cc_new_unique(context, to, NULL, &toid);
468     if (ret)
469 	krb5_err(context, 1, ret, "krb5_cc_gen_new: %s", to);
470 
471     ret = krb5_cc_copy_cache(context, fromid, toid);
472     if (ret)
473 	krb5_err(context, 1, ret, "krb5_cc_copy_cache");
474 
475     ret = krb5_cc_get_principal(context, toid, &p2);
476     if (ret)
477 	krb5_err(context, 1, ret, "krb5_cc_get_principal");
478 
479     if (krb5_principal_compare(context, p, p2) == FALSE)
480 	krb5_errx(context, 1, "p != p2");
481 
482     krb5_free_principal(context, p);
483     krb5_free_principal(context, p2);
484 
485     krb5_cc_destroy(context, fromid);
486     krb5_cc_destroy(context, toid);
487 }
488 
489 static void
490 test_move(krb5_context context, const char *type)
491 {
492     const krb5_cc_ops *ops;
493     krb5_ccache fromid, toid;
494     krb5_error_code ret;
495     krb5_principal p, p2;
496 
497     ops = krb5_cc_get_prefix_ops(context, type);
498     if (ops == NULL)
499 	return;
500 
501     ret = krb5_cc_new_unique(context, type, NULL, &fromid);
502     if (ret == KRB5_CC_NOSUPP)
503 	return;
504     else if (ret)
505 	krb5_err(context, 1, ret, "krb5_cc_new_unique: %s", type);
506 
507     ret = krb5_parse_name(context, "lha@SU.SE", &p);
508     if (ret)
509 	krb5_err(context, 1, ret, "krb5_parse_name");
510 
511     ret = krb5_cc_initialize(context, fromid, p);
512     if (ret)
513 	krb5_err(context, 1, ret, "krb5_cc_initialize");
514 
515     ret = krb5_cc_new_unique(context, type, NULL, &toid);
516     if (ret)
517 	krb5_err(context, 1, ret, "krb5_cc_new_unique");
518 
519     ret = krb5_cc_initialize(context, toid, p);
520     if (ret)
521 	krb5_err(context, 1, ret, "krb5_cc_initialize");
522 
523     ret = krb5_cc_get_principal(context, toid, &p2);
524     if (ret)
525 	krb5_err(context, 1, ret, "krb5_cc_get_principal");
526 
527     if (krb5_principal_compare(context, p, p2) == FALSE)
528 	krb5_errx(context, 1, "p != p2");
529 
530     krb5_free_principal(context, p);
531     krb5_free_principal(context, p2);
532 
533     krb5_cc_destroy(context, toid);
534     krb5_cc_destroy(context, fromid);
535 }
536 
537 
538 static void
539 test_prefix_ops(krb5_context context, const char *name, const krb5_cc_ops *ops)
540 {
541     const krb5_cc_ops *o;
542 
543     o = krb5_cc_get_prefix_ops(context, name);
544     if (o == NULL)
545 	krb5_errx(context, 1, "found no match for prefix '%s'", name);
546     if (strcmp(o->prefix, ops->prefix) != 0)
547 	krb5_errx(context, 1, "ops for prefix '%s' is not "
548 		  "the expected %s != %s", name, o->prefix, ops->prefix);
549 }
550 
551 static void
552 test_cc_config(krb5_context context)
553 {
554     krb5_error_code ret;
555     krb5_principal p;
556     krb5_ccache id;
557     unsigned int i;
558 
559     ret = krb5_cc_new_unique(context, "MEMORY", "bar", &id);
560     if (ret)
561 	krb5_err(context, 1, ret, "krb5_cc_new_unique");
562 
563     ret = krb5_parse_name(context, "lha@SU.SE", &p);
564     if (ret)
565 	krb5_err(context, 1, ret, "krb5_parse_name");
566 
567     ret = krb5_cc_initialize(context, id, p);
568     if (ret)
569 	krb5_err(context, 1, ret, "krb5_cc_initialize");
570 
571     for (i = 0; i < 1000; i++) {
572 	krb5_data data, data2;
573 	const char *name = "foo";
574 	krb5_principal p1 = NULL;
575 
576 	if (i & 1)
577 	    p1 = p;
578 
579 	data.data = rk_UNCONST(name);
580 	data.length = strlen(name);
581 
582 	ret = krb5_cc_set_config(context, id, p1, "FriendlyName", &data);
583 	if (ret)
584 	    krb5_errx(context, 1, "krb5_cc_set_config: add");
585 
586 	ret = krb5_cc_get_config(context, id, p1, "FriendlyName", &data2);
587 	if (ret)
588 	    krb5_errx(context, 1, "krb5_cc_get_config: first");
589 	krb5_data_free(&data2);
590 
591 	ret = krb5_cc_set_config(context, id, p1, "FriendlyName", &data);
592 	if (ret)
593 	    krb5_errx(context, 1, "krb5_cc_set_config: add -second");
594 
595 	ret = krb5_cc_get_config(context, id, p1, "FriendlyName", &data2);
596 	if (ret)
597 	    krb5_errx(context, 1, "krb5_cc_get_config: second");
598 	krb5_data_free(&data2);
599 
600 	ret = krb5_cc_set_config(context, id, p1, "FriendlyName", NULL);
601 	if (ret)
602 	    krb5_errx(context, 1, "krb5_cc_set_config: delete");
603 
604 	ret = krb5_cc_get_config(context, id, p1, "FriendlyName", &data2);
605 	if (ret == 0)
606 	    krb5_errx(context, 1, "krb5_cc_get_config: non-existant");
607     }
608 
609     krb5_cc_destroy(context, id);
610     krb5_free_principal(context, p);
611 }
612 
613 
614 static struct getargs args[] = {
615     {"debug",	'd',	arg_flag,	&debug_flag,
616      "turn on debuggin", NULL },
617     {"version",	0,	arg_flag,	&version_flag,
618      "print version", NULL },
619     {"help",	0,	arg_flag,	&help_flag,
620      NULL, NULL }
621 };
622 
623 static void
624 usage (int ret)
625 {
626     arg_printusage (args, sizeof(args)/sizeof(*args), NULL, "hostname ...");
627     exit (ret);
628 }
629 
630 int
631 main(int argc, char **argv)
632 {
633     krb5_context context;
634     krb5_error_code ret;
635     int optidx = 0;
636     krb5_ccache id1, id2;
637 
638     setprogname(argv[0]);
639 
640     if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx))
641 	usage(1);
642 
643     if (help_flag)
644 	usage (0);
645 
646     if(version_flag){
647 	print_version(NULL);
648 	exit(0);
649     }
650 
651     argc -= optidx;
652     argv += optidx;
653 
654     ret = krb5_init_context(&context);
655     if (ret)
656 	errx (1, "krb5_init_context failed: %d", ret);
657 
658     test_cache_remove(context, krb5_cc_type_file);
659     test_cache_remove(context, krb5_cc_type_memory);
660 #ifdef USE_SQLITE
661     test_cache_remove(context, krb5_cc_type_scc);
662 #endif
663 
664     test_default_name(context);
665     test_mcache(context);
666     test_init_vs_destroy(context, krb5_cc_type_memory);
667     test_init_vs_destroy(context, krb5_cc_type_file);
668 #if 0
669     test_init_vs_destroy(context, krb5_cc_type_api);
670 #endif
671     test_init_vs_destroy(context, krb5_cc_type_scc);
672     test_mcc_default();
673     test_def_cc_name(context);
674 
675     test_cache_iter_all(context);
676 
677     test_cache_iter(context, krb5_cc_type_memory, 0);
678     {
679 	krb5_principal p;
680 	krb5_cc_new_unique(context, krb5_cc_type_memory, "bar", &id1);
681 	krb5_cc_new_unique(context, krb5_cc_type_memory, "baz", &id2);
682 	krb5_parse_name(context, "lha@SU.SE", &p);
683 	krb5_cc_initialize(context, id1, p);
684 	krb5_free_principal(context, p);
685     }
686 
687     test_cache_find(context, "lha@SU.SE", 1);
688     test_cache_find(context, "hulabundulahotentot@SU.SE", 0);
689 
690     test_cache_iter(context, krb5_cc_type_memory, 0);
691     test_cache_iter(context, krb5_cc_type_memory, 1);
692     test_cache_iter(context, krb5_cc_type_memory, 0);
693     test_cache_iter(context, krb5_cc_type_file, 0);
694     test_cache_iter(context, krb5_cc_type_api, 0);
695     test_cache_iter(context, krb5_cc_type_scc, 0);
696     test_cache_iter(context, krb5_cc_type_scc, 1);
697 
698     test_copy(context, krb5_cc_type_file, krb5_cc_type_file);
699     test_copy(context, krb5_cc_type_memory, krb5_cc_type_memory);
700     test_copy(context, krb5_cc_type_file, krb5_cc_type_memory);
701     test_copy(context, krb5_cc_type_memory, krb5_cc_type_file);
702     test_copy(context, krb5_cc_type_scc, krb5_cc_type_file);
703     test_copy(context, krb5_cc_type_file, krb5_cc_type_scc);
704     test_copy(context, krb5_cc_type_scc, krb5_cc_type_memory);
705     test_copy(context, krb5_cc_type_memory, krb5_cc_type_scc);
706 
707     test_move(context, krb5_cc_type_file);
708     test_move(context, krb5_cc_type_memory);
709 #ifdef HAVE_KCM
710     test_move(context, krb5_cc_type_kcm);
711 #endif
712     test_move(context, krb5_cc_type_scc);
713 
714     test_prefix_ops(context, "FILE:/tmp/foo", &krb5_fcc_ops);
715     test_prefix_ops(context, "FILE", &krb5_fcc_ops);
716     test_prefix_ops(context, "MEMORY", &krb5_mcc_ops);
717     test_prefix_ops(context, "MEMORY:foo", &krb5_mcc_ops);
718     test_prefix_ops(context, "/tmp/kaka", &krb5_fcc_ops);
719 #ifdef HAVE_SCC
720     test_prefix_ops(context, "SCC:", &krb5_scc_ops);
721     test_prefix_ops(context, "SCC:foo", &krb5_scc_ops);
722 #endif
723 
724     krb5_cc_destroy(context, id1);
725     krb5_cc_destroy(context, id2);
726 
727     test_cc_config(context);
728 
729     krb5_free_context(context);
730 
731 #if 0
732     sleep(60);
733 #endif
734 
735     return 0;
736 }
737