11573Srgrimes/* $NetBSD: test_gic.c,v 1.2 2017/01/28 21:31:49 christos Exp $ */ 21573Srgrimes 31573Srgrimes/* 41573Srgrimes * Copyright (c) 2009 Kungliga Tekniska H�gskolan 51573Srgrimes * (Royal Institute of Technology, Stockholm, Sweden). 61573Srgrimes * All rights reserved. 71573Srgrimes * 81573Srgrimes * Redistribution and use in source and binary forms, with or without 91573Srgrimes * modification, are permitted provided that the following conditions 101573Srgrimes * are met: 111573Srgrimes * 121573Srgrimes * 1. Redistributions of source code must retain the above copyright 131573Srgrimes * notice, this list of conditions and the following disclaimer. 141573Srgrimes * 151573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 161573Srgrimes * notice, this list of conditions and the following disclaimer in the 171573Srgrimes * documentation and/or other materials provided with the distribution. 181573Srgrimes * 191573Srgrimes * 3. Neither the name of KTH nor the names of its contributors may be 201573Srgrimes * used to endorse or promote products derived from this software without 211573Srgrimes * specific prior written permission. 221573Srgrimes * 231573Srgrimes * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY 241573Srgrimes * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 251573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 261573Srgrimes * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE 271573Srgrimes * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 281573Srgrimes * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 291573Srgrimes * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 301573Srgrimes * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 311573Srgrimes * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 321573Srgrimes * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 331573Srgrimes * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 341573Srgrimes 3555127Speter#include "krb5_locl.h" 361573Srgrimes#include <err.h> 3755127Speter#include <krb5/getarg.h> 3855127Speter 3955127Speterstatic char *password_str; 4055127Speter 411573Srgrimesstatic krb5_error_code 421573Srgrimeslr_proc(krb5_context context, krb5_last_req_entry **e, void *ctx) 431573Srgrimes{ 448870Srgrimes while (e && *e) { 451573Srgrimes printf("e type: %d value: %d\n", (*e)->lr_type, (int)(*e)->value); 461573Srgrimes e++; 471573Srgrimes } 481573Srgrimes return 0; 491573Srgrimes} 501573Srgrimes 511573Srgrimesstatic void 521573Srgrimestest_get_init_creds(krb5_context context, 5355206Speter krb5_principal client) 541573Srgrimes{ 5555206Speter krb5_error_code ret; 561573Srgrimes krb5_get_init_creds_opt *opt; 571573Srgrimes krb5_creds cred; 581573Srgrimes 591573Srgrimes ret = krb5_get_init_creds_opt_alloc(context, &opt); 601573Srgrimes if (ret) 611573Srgrimes krb5_err(context, 1, ret, "krb5_get_init_creds_opt_alloc"); 621573Srgrimes 631573Srgrimes 641573Srgrimes ret = krb5_get_init_creds_opt_set_process_last_req(context, 651573Srgrimes opt, 661573Srgrimes lr_proc, 671573Srgrimes NULL); 681573Srgrimes if (ret) 691573Srgrimes krb5_err(context, 1, ret, 701573Srgrimes "krb5_get_init_creds_opt_set_process_last_req"); 711573Srgrimes 721573Srgrimes ret = krb5_get_init_creds_password(context, 731573Srgrimes &cred, 741573Srgrimes client, 751573Srgrimes password_str, 761573Srgrimes krb5_prompter_posix, 771573Srgrimes NULL, 781573Srgrimes 0, 7917141Sjkh NULL, 801573Srgrimes opt); 811573Srgrimes if (ret) 821573Srgrimes krb5_err(context, 1, ret, "krb5_get_init_creds_password"); 831573Srgrimes 841573Srgrimes krb5_get_init_creds_opt_free(context, opt); 856683Sphk} 8614523Shsu 871573Srgrimesstatic char *client_str = NULL; 8814523Shsustatic int debug_flag = 0; 891573Srgrimesstatic int version_flag = 0; 901573Srgrimesstatic int help_flag = 0; 911573Srgrimes 921573Srgrimesstatic struct getargs args[] = { 931573Srgrimes {"client", 0, arg_string, &client_str, 941573Srgrimes "client principal to use", NULL }, 951573Srgrimes {"password",0, arg_string, &password_str, 961573Srgrimes "password", NULL }, 971573Srgrimes {"debug", 'd', arg_flag, &debug_flag, 981573Srgrimes "turn on debuggin", NULL }, 991573Srgrimes {"version", 0, arg_flag, &version_flag, 10014523Shsu "print version", NULL }, 1011573Srgrimes {"help", 0, arg_flag, &help_flag, 1021573Srgrimes NULL, NULL } 1031573Srgrimes}; 1041573Srgrimes 10514523Shsustatic void 1061573Srgrimesusage (int ret) 1071573Srgrimes{ 1081573Srgrimes arg_printusage (args, sizeof(args)/sizeof(*args), NULL, "hostname ..."); 1091573Srgrimes exit (ret); 1101573Srgrimes} 1111573Srgrimes 1121573Srgrimes 1131573Srgrimesint 1141573Srgrimesmain(int argc, char **argv) 1151573Srgrimes{ 1161573Srgrimes krb5_context context; 1171573Srgrimes krb5_error_code ret; 1181573Srgrimes int optidx = 0, errors = 0; 1191573Srgrimes krb5_principal client; 1201573Srgrimes 1211573Srgrimes setprogname(argv[0]); 1221573Srgrimes 1231573Srgrimes if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx)) 1241573Srgrimes usage(1); 1251573Srgrimes 1261573Srgrimes if (help_flag) 1271573Srgrimes usage (0); 1281573Srgrimes 1291573Srgrimes if(version_flag){ 13038534Sdfr print_version(NULL); 13138534Sdfr exit(0); 13214523Shsu } 13314523Shsu 1341573Srgrimes if(client_str == NULL) 1351573Srgrimes errx(1, "client is not set"); 1361573Srgrimes 1371573Srgrimes ret = krb5_init_context(&context); 1381573Srgrimes if (ret) 1391573Srgrimes errx (1, "krb5_init_context failed: %d", ret); 1401573Srgrimes 14157321Speter ret = krb5_parse_name(context, client_str, &client); 1421573Srgrimes if (ret) 1431573Srgrimes krb5_err(context, 1, ret, "krb5_parse_name: %d", ret); 1441573Srgrimes 1451573Srgrimes test_get_init_creds(context, client); 1461573Srgrimes 1471573Srgrimes krb5_free_context(context); 1481573Srgrimes 1491573Srgrimes return errors; 1501573Srgrimes} 1511573Srgrimes