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 37#include "mit-KerberosLogin.h" 38#include <stdio.h> 39#include <stdlib.h> 40#include <string.h> 41#include <err.h> 42 43int 44main(int argc, char **argv) 45{ 46 KLLoginOptions options; 47 KLPrincipal princ; 48 KLStatus ret; 49 KLBoolean foundV5; 50 char *user; 51 char *password; 52 char *buffer; 53 54 if (argc != 3) 55 errx(1, "argc != 2"); 56 57 user = argv[1]; 58 password = strdup(argv[2]); 59 60 printf("test NULL argument\n"); 61 ret = KLCreatePrincipalFromString(NULL, kerberosVersion_V5, &princ); 62 if (ret == 0) 63 errx(1, "KLCreatePrincipalFromString: %d", ret); 64 65 printf("create principal\n"); 66 ret = KLCreatePrincipalFromString(user, 67 kerberosVersion_V5, &princ); 68 if (ret) 69 errx(1, "KLCreatePrincipalFromString: %d", ret); 70 71 printf("acquire cred\n"); 72 ret = KLAcquireNewInitialTicketsWithPassword(princ, NULL, password, NULL); 73 if (ret) 74 errx(1, "KLAcquireTicketsWithPassword1: %d", ret); 75 76 printf("get valid tickets\n"); 77 ret = KLCacheHasValidTickets(princ, kerberosVersion_V5, &foundV5, NULL, NULL); 78 if (ret) 79 errx(1, "KLCacheHasValidTickets failed1"); 80 else if (!foundV5) 81 errx(1, "found no valid tickets"); 82 83#if 0 84 ret = KLAcquireNewInitialTickets(princ, NULL, NULL, NULL); 85 if (ret) 86 errx(1, "KLAcquireTickets: %d", ret); 87 88 KLDestroyTickets(princ); 89 90 printf("get valid tickets\n"); 91 ret = KLCacheHasValidTickets(princ, kerberosVersion_V5, &foundV5, NULL, NULL); 92 if (ret) 93 errx(1, "KLCacheHasValidTickets failed1 dead"); 94 else if (foundV5) 95 errx(1, "found valid tickets!"); 96#endif 97 98 KLCreateLoginOptions(&options); 99 KLLoginOptionsSetRenewableLifetime(options, 3600 * 24 * 7); 100 101 ret = KLAcquireNewInitialTicketsWithPassword(princ, options, password, NULL); 102 if (ret) 103 errx(1, "KLAcquireTicketsWithPassword2: %d", ret); 104 105 KLDisposeLoginOptions(options); 106 107 printf("get valid tickets\n"); 108 ret = KLCacheHasValidTickets(princ, kerberosVersion_V5, &foundV5, NULL, NULL); 109 if (ret) 110 errx(1, "KLCacheHasValidTickets failed"); 111 else if (!foundV5) 112 errx(1, "found no valid tickets"); 113 114 printf("renew tickets\n"); 115 ret = KLRenewInitialTickets(princ, NULL, NULL, NULL); 116 if (ret) 117 errx(1, "KLRenewInitialTickets: %d", ret); 118 119 printf("display string from princ\n"); 120 ret = KLGetDisplayStringFromPrincipal(princ, kerberosVersion_V5, &buffer); 121 if (ret) 122 errx(1, "KLGetDisplayStringFromPrincipal: %d", ret); 123 free(buffer); 124 125 printf("string from princ\n"); 126 ret = KLGetStringFromPrincipal(princ, kerberosVersion_V5, &buffer); 127 if (ret) 128 errx(1, "KLGetStringFromPrincipal: %d", ret); 129 free(buffer); 130 131 { 132 char *name; 133 char *inst; 134 char *realm; 135 printf("triplet from princ\n"); 136 ret = KLGetTripletFromPrincipal(princ, &name, &inst, &realm); 137 if (ret) 138 errx(1, "KLCancelAllDialogs: %d", ret); 139 free(name); 140 free(inst); 141 free(realm); 142 } 143 144 145 printf("cancel dialogs\n"); 146 ret = KLCancelAllDialogs(); 147 if (ret) 148 errx(1, "KLCancelAllDialogs: %d", ret); 149 150 printf("dispose string\n"); 151 ret = KLDisposeString(password); 152 if (ret) 153 errx(1, "KLDisposeString: %d", ret); 154 155 KLDestroyTickets(princ); 156 KLDisposePrincipal(princ); 157 158 return 0; 159} 160