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