1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* tests/gssapi/ccinit.c - Initialize an empty ccache */
3 /*
4 * Copyright (C) 2012 by the Massachusetts Institute of Technology.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30 * OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * This program initializes a ccache without attempting to get credentials in
35 * it. It is used to test some finer points of gss_acquire_cred behavior.
36 */
37
38 #include "k5-int.h"
39
40 static void
check(krb5_error_code code)41 check(krb5_error_code code)
42 {
43 if (code != 0) {
44 com_err("ccinit", code, NULL);
45 abort();
46 }
47 }
48
49 int
main(int argc,char ** argv)50 main(int argc, char **argv)
51 {
52 const char *ccname, *princname;
53 krb5_context context;
54 krb5_principal princ;
55 krb5_ccache ccache;
56
57 if (argc != 3) {
58 fprintf(stderr, "Usage: %s ccname princname\n", argv[0]);
59 return 1;
60 }
61 ccname = argv[1];
62 princname = argv[2];
63
64 check(krb5_init_context(&context));
65 check(krb5_parse_name(context, princname, &princ));
66 check(krb5_cc_resolve(context, ccname, &ccache));
67 check(krb5_cc_initialize(context, ccache, princ));
68 krb5_cc_close(context, ccache);
69 krb5_free_principal(context, princ);
70 krb5_free_context(context);
71 return 0;
72 }
73