1b528cefcSMark Murray /* 2b528cefcSMark Murray * Copyright (c) 1997 - 2000 Kungliga Tekniska H�gskolan 3b528cefcSMark Murray * (Royal Institute of Technology, Stockholm, Sweden). 4b528cefcSMark Murray * All rights reserved. 5b528cefcSMark Murray * 6b528cefcSMark Murray * Redistribution and use in source and binary forms, with or without 7b528cefcSMark Murray * modification, are permitted provided that the following conditions 8b528cefcSMark Murray * are met: 9b528cefcSMark Murray * 10b528cefcSMark Murray * 1. Redistributions of source code must retain the above copyright 11b528cefcSMark Murray * notice, this list of conditions and the following disclaimer. 12b528cefcSMark Murray * 13b528cefcSMark Murray * 2. Redistributions in binary form must reproduce the above copyright 14b528cefcSMark Murray * notice, this list of conditions and the following disclaimer in the 15b528cefcSMark Murray * documentation and/or other materials provided with the distribution. 16b528cefcSMark Murray * 17b528cefcSMark Murray * 3. Neither the name of the Institute nor the names of its contributors 18b528cefcSMark Murray * may be used to endorse or promote products derived from this software 19b528cefcSMark Murray * without specific prior written permission. 20b528cefcSMark Murray * 21b528cefcSMark Murray * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22b528cefcSMark Murray * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23b528cefcSMark Murray * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24b528cefcSMark Murray * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25b528cefcSMark Murray * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26b528cefcSMark Murray * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27b528cefcSMark Murray * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28b528cefcSMark Murray * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29b528cefcSMark Murray * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30b528cefcSMark Murray * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31b528cefcSMark Murray * SUCH DAMAGE. 32b528cefcSMark Murray */ 33b528cefcSMark Murray 34b528cefcSMark Murray #include "ktutil_locl.h" 35b528cefcSMark Murray 36b528cefcSMark Murray RCSID("$Id: remove.c,v 1.1 2000/01/02 04:41:02 assar Exp $"); 37b528cefcSMark Murray 38b528cefcSMark Murray int 39b528cefcSMark Murray kt_remove(int argc, char **argv) 40b528cefcSMark Murray { 41b528cefcSMark Murray krb5_error_code ret; 42b528cefcSMark Murray krb5_keytab_entry entry; 43b528cefcSMark Murray char *principal_string = NULL; 44b528cefcSMark Murray krb5_principal principal = NULL; 45b528cefcSMark Murray int kvno = 0; 46b528cefcSMark Murray char *keytype_string = NULL; 47b528cefcSMark Murray krb5_enctype enctype = 0; 48b528cefcSMark Murray int help_flag = 0; 49b528cefcSMark Murray struct getargs args[] = { 50b528cefcSMark Murray { "principal", 'p', arg_string, NULL, "principal to remove" }, 51b528cefcSMark Murray { "kvno", 'V', arg_integer, NULL, "key version to remove" }, 52b528cefcSMark Murray { "enctype", 'e', arg_string, NULL, "enctype to remove" }, 53b528cefcSMark Murray { "help", 'h', arg_flag, NULL } 54b528cefcSMark Murray }; 55b528cefcSMark Murray int num_args = sizeof(args) / sizeof(args[0]); 56b528cefcSMark Murray int optind = 0; 57b528cefcSMark Murray int i = 0; 58b528cefcSMark Murray args[i++].value = &principal_string; 59b528cefcSMark Murray args[i++].value = &kvno; 60b528cefcSMark Murray args[i++].value = &keytype_string; 61b528cefcSMark Murray args[i++].value = &help_flag; 62b528cefcSMark Murray if(getarg(args, num_args, argc, argv, &optind)) { 63b528cefcSMark Murray arg_printusage(args, num_args, "ktutil remove", ""); 64b528cefcSMark Murray return 0; 65b528cefcSMark Murray } 66b528cefcSMark Murray if(help_flag) { 67b528cefcSMark Murray arg_printusage(args, num_args, "ktutil remove", ""); 68b528cefcSMark Murray return 0; 69b528cefcSMark Murray } 70b528cefcSMark Murray if(principal_string) { 71b528cefcSMark Murray ret = krb5_parse_name(context, principal_string, &principal); 72b528cefcSMark Murray if(ret) { 73b528cefcSMark Murray krb5_warn(context, ret, "%s", principal_string); 74b528cefcSMark Murray return 0; 75b528cefcSMark Murray } 76b528cefcSMark Murray } 77b528cefcSMark Murray if(keytype_string) { 78b528cefcSMark Murray ret = krb5_string_to_enctype(context, keytype_string, &enctype); 79b528cefcSMark Murray if(ret) { 80b528cefcSMark Murray int t; 81b528cefcSMark Murray if(sscanf(keytype_string, "%d", &t) == 1) 82b528cefcSMark Murray enctype = t; 83b528cefcSMark Murray else { 84b528cefcSMark Murray krb5_warn(context, ret, "%s", keytype_string); 85b528cefcSMark Murray if(principal) 86b528cefcSMark Murray krb5_free_principal(context, principal); 87b528cefcSMark Murray return 0; 88b528cefcSMark Murray } 89b528cefcSMark Murray } 90b528cefcSMark Murray } 91b528cefcSMark Murray if (!principal && !enctype && !kvno) { 92b528cefcSMark Murray krb5_warnx(context, 93b528cefcSMark Murray "You must give at least one of " 94b528cefcSMark Murray "principal, enctype or kvno."); 95b528cefcSMark Murray return 0; 96b528cefcSMark Murray } 97b528cefcSMark Murray entry.principal = principal; 98b528cefcSMark Murray entry.keyblock.keytype = enctype; 99b528cefcSMark Murray entry.vno = kvno; 100b528cefcSMark Murray ret = krb5_kt_remove_entry(context, keytab, &entry); 101b528cefcSMark Murray if(ret) 102b528cefcSMark Murray krb5_warn(context, ret, "remove"); 103b528cefcSMark Murray if(principal) 104b528cefcSMark Murray krb5_free_principal(context, principal); 105b528cefcSMark Murray return 0; 106b528cefcSMark Murray } 107b528cefcSMark Murray 108