1/*
2 * Copyright (c) 2008-2010 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Portions Copyright (c) 2008-2010 Apple Inc. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * 3. Neither the name of the Institute nor the names of its contributors
20 *    may be used to endorse or promote products derived from this software
21 *    without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36#include "mit-KerberosLogin.h"
37#include <stdio.h>
38#include <err.h>
39
40int
41main(int argc, char **argv)
42{
43    KLLoginOptions options;
44    KLPrincipal princ;
45    KLStatus ret;
46    KLBoolean foundV5;
47    KLIdleCallback idlecall;
48    KLRefCon refcon;
49
50    if (argc != 2)
51	errx(1, "argc != 2");
52
53    printf("test NULL argument\n");
54    ret = KLCreatePrincipalFromString(NULL, kerberosVersion_V5, &princ);
55    if (ret == 0)
56	errx(1, "KLCreatePrincipalFromString: %d", ret);
57
58    printf("create principal\n");
59    ret = KLCreatePrincipalFromString(argv[1],
60				      kerberosVersion_V5, &princ);
61    if (ret)
62	errx(1, "KLCreatePrincipalFromString: %d", ret);
63
64    printf("acquire cred\n");
65
66    KLCreateLoginOptions(&options);
67    KLLoginOptionsSetRenewableLifetime(options, 3600 * 24 * 7);
68
69    ret = KLAcquireInitialTickets(princ, options, NULL, NULL);
70    if (ret)
71	errx(1, "KLAcquireTicketsWithPassword: %d", ret);
72
73    KLDisposeLoginOptions(options);
74
75    printf("get valid tickets\n");
76    ret = KLCacheHasValidTickets(princ, kerberosVersion_V5, &foundV5, NULL, NULL);
77    if (ret)
78	errx(1, "KLCacheHasValidTickets failed");
79    else if (!foundV5)
80	errx(1, "found no valid tickets");
81
82    printf("renew tickets\n");
83    ret = KLRenewInitialTickets(princ, NULL, NULL, NULL);
84    if (ret)
85	errx(1, "KLRenewInitialTickets: %d", ret);
86    KLDisposePrincipal(princ);
87
88    printf("test callbacks\n");
89    ret = KLGetIdleCallback(&idlecall, &refcon);
90    if (ret != klNoErr)
91	errx(1, "KLGetIdleCallback: %d", ret);
92
93    ret = KLSetIdleCallback(NULL, refcon);
94    if (ret != klNoErr)
95	errx(1, "KLSetIdleCallback: %d", ret);
96
97
98    return 0;
99}
100