ktutil.c revision 57416
1138568Ssam/* 2170360Ssam * Copyright (c) 1997 - 2000 Kungliga Tekniska H�gskolan 3138568Ssam * (Royal Institute of Technology, Stockholm, Sweden). 4138568Ssam * All rights reserved. 5138568Ssam * 6138568Ssam * Redistribution and use in source and binary forms, with or without 7138568Ssam * modification, are permitted provided that the following conditions 8138568Ssam * are met: 9138568Ssam * 10138568Ssam * 1. Redistributions of source code must retain the above copyright 11138568Ssam * notice, this list of conditions and the following disclaimer. 12138568Ssam * 13138568Ssam * 2. Redistributions in binary form must reproduce the above copyright 14138568Ssam * notice, this list of conditions and the following disclaimer in the 15138568Ssam * documentation and/or other materials provided with the distribution. 16138568Ssam * 17138568Ssam * 3. Neither the name of the Institute nor the names of its contributors 18138568Ssam * may be used to endorse or promote products derived from this software 19138568Ssam * without specific prior written permission. 20138568Ssam * 21138568Ssam * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22138568Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23138568Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24138568Ssam * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25138568Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26138568Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27138568Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28138568Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29138568Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30138568Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31138568Ssam * SUCH DAMAGE. 32138568Ssam */ 33138568Ssam 34138568Ssam#include "ktutil_locl.h" 35138568Ssam 36138568SsamRCSID("$Id: ktutil.c,v 1.26 2000/02/07 04:29:25 assar Exp $"); 37138568Ssam 38138568Ssamstatic int help_flag; 39138568Ssamstatic int version_flag; 40138568Ssamint verbose_flag; 41138568Ssamchar *keytab_string; 42138568Ssam 43138568Ssamstatic int help(int argc, char **argv); 44138568Ssam 45138568Ssamstatic SL_cmd cmds[] = { 46138568Ssam { "add", kt_add, "add", 47138568Ssam "adds key to keytab" }, 48138568Ssam { "change", kt_change, "change [principal...]", 49138568Ssam "get new key for principals (all)" }, 50138568Ssam { "copy", kt_copy, "copy src dst", 51138568Ssam "copy one keytab to another" }, 52138568Ssam { "get", kt_get, "get [principal...]", 53138568Ssam "create key in database and add to keytab" }, 54138568Ssam { "list", kt_list, "list", 55138568Ssam "shows contents of a keytab" }, 56138568Ssam { "purge", kt_purge, "purge", 57138568Ssam "remove old and superceeded entries" }, 58138568Ssam { "remove", kt_remove, "remove", 59138568Ssam "remove key from keytab" }, 60138568Ssam { "srvconvert", srvconv, "srvconvert [flags]", 61138568Ssam "convert v4 srvtab to keytab" }, 62138568Ssam { "srv2keytab" }, 63138568Ssam { "srvcreate", srvcreate, "srvcreate [flags]", 64138568Ssam "convert keytab to v4 srvtab" }, 65138568Ssam { "key2srvtab" }, 66138568Ssam { "help", help, "help", "" }, 67138568Ssam { NULL, NULL, NULL, NULL } 68138568Ssam}; 69138568Ssam 70138568Ssamstatic struct getargs args[] = { 71138568Ssam { 72138568Ssam "version", 73138568Ssam 0, 74138568Ssam arg_flag, 75138568Ssam &version_flag, 76138568Ssam NULL, 77138568Ssam NULL 78138568Ssam }, 79138568Ssam { 80138568Ssam "help", 81138568Ssam 'h', 82138568Ssam arg_flag, 83138568Ssam &help_flag, 84138568Ssam NULL, 85138568Ssam NULL 86138568Ssam }, 87138568Ssam { 88138568Ssam "keytab", 89138568Ssam 'k', 90138568Ssam arg_string, 91138568Ssam &keytab_string, 92138568Ssam "keytab", 93138568Ssam "keytab to operate on" 94138568Ssam }, 95138568Ssam { 96138568Ssam "verbose", 97138568Ssam 'v', 98138568Ssam arg_flag, 99138568Ssam &verbose_flag, 100138568Ssam "verbose", 101138568Ssam "run verbosely" 102138568Ssam } 103138568Ssam}; 104138568Ssam 105138568Ssamstatic int num_args = sizeof(args) / sizeof(args[0]); 106138568Ssam 107138568Ssamkrb5_context context; 108138568Ssamkrb5_keytab keytab; 109140633Ssam 110138568Ssamstatic int 111138568Ssamhelp(int argc, char **argv) 112138568Ssam{ 113138568Ssam sl_help(cmds, argc, argv); 114138568Ssam return 0; 115138568Ssam} 116138568Ssam 117138568Ssamstatic void 118138568Ssamusage(int status) 119138568Ssam{ 120138568Ssam arg_printusage(args, num_args, NULL, "command"); 121138568Ssam exit(status); 122138568Ssam} 123138568Ssam 124139512Ssamint 125139512Ssammain(int argc, char **argv) 126139512Ssam{ 127153349Ssam int optind = 0; 128153349Ssam krb5_error_code ret; 129153349Ssam set_progname(argv[0]); 130138568Ssam krb5_init_context(&context); 131138568Ssam if(getarg(args, num_args, argc, argv, &optind)) 132138568Ssam usage(1); 133138568Ssam if(help_flag) 134138568Ssam usage(0); 135138568Ssam if(version_flag) { 136138568Ssam print_version(NULL); 137138568Ssam exit(0); 138138568Ssam } 139138568Ssam argc -= optind; 140138568Ssam argv += optind; 141138568Ssam if(argc == 0) 142138568Ssam usage(1); 143138568Ssam if(keytab_string) { 144138568Ssam ret = krb5_kt_resolve(context, keytab_string, &keytab); 145138568Ssam } else { 146138568Ssam ret = krb5_kt_default(context, &keytab); 147138568Ssam } 148138568Ssam if(ret) 149138568Ssam krb5_err(context, 1, ret, "resolving keytab"); 150138568Ssam ret = sl_command(cmds, argc, argv); 151165894Ssam if(ret == -1) 152165894Ssam krb5_warnx (context, "unrecognized command: %s", argv[0]); 153165894Ssam krb5_kt_close(context, keytab); 154165894Ssam return ret; 155165894Ssam} 156165894Ssam