/*1* Copyright (c) 1997 - 2005, 2007 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* 3. Neither the name of the Institute nor the names of its contributors17* may be used to endorse or promote products derived from this software18* without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND21* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE24* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT28* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY29* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF30* SUCH DAMAGE.31*/3233#include "kuser_locl.h"3435static int help_flag = 0;36static int version_flag = 0;3738static struct getargs args[] = {39{ "version", 0, arg_flag, &version_flag },40{ "help", 0, arg_flag, &help_flag }41};4243static void44usage (int ret)45{46arg_printusage (args,47sizeof(args)/sizeof(*args),48NULL,49"[principal]");50exit (ret);51}5253int54main(int argc, char **argv)55{56krb5_context context;57krb5_error_code ret;58krb5_creds cred;59krb5_preauthtype pre_auth_types[] = {KRB5_PADATA_ENC_TIMESTAMP};60krb5_get_init_creds_opt *get_options;61krb5_verify_init_creds_opt verify_options;62krb5_principal principal = NULL;63int optidx = 0;6465setprogname (argv[0]);6667if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx))68usage(1);6970if (help_flag)71usage (0);7273if(version_flag) {74print_version(NULL);75exit(0);76}7778argc -= optidx;79argv += optidx;8081ret = krb5_init_context(&context);82if (ret)83errx (1, "krb5_init_context failed: %d", ret);8485ret = krb5_get_init_creds_opt_alloc (context, &get_options);86if (ret)87krb5_err(context, 1, ret, "krb5_get_init_creds_opt_alloc");8889krb5_get_init_creds_opt_set_preauth_list (get_options,90pre_auth_types,911);9293krb5_verify_init_creds_opt_init (&verify_options);9495if (argc) {96ret = krb5_parse_name(context, argv[0], &principal);97if (ret)98krb5_err(context, 1, ret, "krb5_parse_name: %s", argv[0]);99} else {100ret = krb5_get_default_principal(context, &principal);101if (ret)102krb5_err(context, 1, ret, "krb5_get_default_principal");103104}105106ret = krb5_get_init_creds_password (context,107&cred,108principal,109NULL,110krb5_prompter_posix,111NULL,1120,113NULL,114get_options);115if (ret)116krb5_err(context, 1, ret, "krb5_get_init_creds");117118ret = krb5_verify_init_creds (context,119&cred,120NULL,121NULL,122NULL,123&verify_options);124if (ret)125krb5_err(context, 1, ret, "krb5_verify_init_creds");126krb5_free_cred_contents (context, &cred);127krb5_free_context (context);128return 0;129}130131132