/*1* Copyright (c) 2010 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"34#include <sl.h>35#include "kcc-commands.h"3637krb5_context kcc_context;38static int version_flag;39static int help_flag;4041static struct getargs args[] = {42{ "version", 0, arg_flag, &version_flag, NULL, NULL },43{ "help", 0, arg_flag, &help_flag, NULL, NULL }44};4546static void47usage(int ret)48{49arg_printusage_i18n(args,50sizeof(args)/sizeof(*args),51N_("Usage: ", ""),52NULL,53"command ..",54getarg_i18n);55exit (ret);56}5758int59help(void *opt, int argc, char **argv)60{61sl_slc_help(commands, argc, argv);62return 0;63}6465int66kgetcred(struct kgetcred_options *opt, int argc, char **argv)67{68return 0;69}7071/*72* Wrapper for command line compatiblity73*/7475int76kvno(struct kvno_options *opt, int argc, char **argv)77{78struct kgetcred_options k;79memset(&k, 0, sizeof(k));8081k.cache_string = opt->cache_string;82k.enctype_string = opt->enctype_string;8384return kgetcred(&k, argc, argv);85}8687static int88command_alias(const char *name)89{90const char *aliases[] = {91"kinit", "klist", "kswitch", "kgetcred", "kvno", "kdeltkt",92"kdestroy", "kcpytkt", NULL93}, **p = aliases;9495while (*p && strcmp(name, *p) != 0)96p++;97return *p != NULL;98}99100101int102main(int argc, char **argv)103{104krb5_error_code ret;105int optidx = 0;106int exit_status = 0;107108setprogname (argv[0]);109110setlocale (LC_ALL, "");111bindtextdomain ("heimdal_kuser", HEIMDAL_LOCALEDIR);112textdomain("heimdal_kuser");113114ret = krb5_init_context(&kcc_context);115if (ret == KRB5_CONFIG_BADFORMAT)116errx (1, "krb5_init_context failed to parse configuration file");117else if (ret)118errx(1, "krb5_init_context failed: %d", ret);119120/*121* Support linking of kcc to commands122*/123124if (!command_alias(getprogname())) {125126if (argc == 1) {127sl_slc_help(commands, 0, NULL);128return 1;129}130131if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx))132usage(1);133134if (help_flag)135usage (0);136137if(version_flag) {138print_version(NULL);139exit(0);140}141142} else {143argv[0] = rk_UNCONST(getprogname());144}145146argc -= optidx;147argv += optidx;148149if (argc != 0) {150ret = sl_command(commands, argc, argv);151if(ret == -1)152krb5_warnx(kcc_context, "unrecognized command: %s", argv[0]);153else if (ret == -2)154ret = 0;155if(ret != 0)156exit_status = 1;157} else {158sl_slc_help(commands, argc, argv);159exit_status = 1;160}161162krb5_free_context(kcc_context);163return exit_status;164}165166167