remove.c revision 178825
157416Smarkm/* 257416Smarkm * Copyright (c) 1997-2004 Kungliga Tekniska H�gskolan 357416Smarkm * (Royal Institute of Technology, Stockholm, Sweden). 457416Smarkm * All rights reserved. 557416Smarkm * 657416Smarkm * Redistribution and use in source and binary forms, with or without 757416Smarkm * modification, are permitted provided that the following conditions 857416Smarkm * are met: 957416Smarkm * 1057416Smarkm * 1. Redistributions of source code must retain the above copyright 1157416Smarkm * notice, this list of conditions and the following disclaimer. 1257416Smarkm * 1357416Smarkm * 2. Redistributions in binary form must reproduce the above copyright 1457416Smarkm * notice, this list of conditions and the following disclaimer in the 1557416Smarkm * documentation and/or other materials provided with the distribution. 1657416Smarkm * 1757416Smarkm * 3. Neither the name of the Institute nor the names of its contributors 1857416Smarkm * may be used to endorse or promote products derived from this software 1957416Smarkm * without specific prior written permission. 2057416Smarkm * 2157416Smarkm * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 2257416Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2357416Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2457416Smarkm * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 2557416Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2657416Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2757416Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2857416Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2957416Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3057416Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3157416Smarkm * SUCH DAMAGE. 3257416Smarkm */ 3357416Smarkm 3457416Smarkm#include "ktutil_locl.h" 3557416Smarkm 3657416SmarkmRCSID("$Id: remove.c 17004 2006-04-07 13:06:37Z lha $"); 3757416Smarkm 3857416Smarkmint 3957416Smarkmkt_remove(struct remove_options *opt, int argc, char **argv) 4057416Smarkm{ 4157416Smarkm krb5_error_code ret = 0; 4257416Smarkm krb5_keytab_entry entry; 4357416Smarkm krb5_keytab keytab; 4457416Smarkm krb5_principal principal = NULL; 4557416Smarkm krb5_enctype enctype = 0; 4657416Smarkm 4757416Smarkm if(opt->principal_string) { 4857416Smarkm ret = krb5_parse_name(context, opt->principal_string, &principal); 4957416Smarkm if(ret) { 5057416Smarkm krb5_warn(context, ret, "%s", opt->principal_string); 5157416Smarkm return 1; 5257416Smarkm } 5357416Smarkm } 5457416Smarkm if(opt->enctype_string) { 5557416Smarkm ret = krb5_string_to_enctype(context, opt->enctype_string, &enctype); 5657416Smarkm if(ret) { 5757416Smarkm int t; 5857416Smarkm if(sscanf(opt->enctype_string, "%d", &t) == 1) 5957416Smarkm enctype = t; 6057416Smarkm else { 6157416Smarkm krb5_warn(context, ret, "%s", opt->enctype_string); 6257416Smarkm if(principal) 6357416Smarkm krb5_free_principal(context, principal); 6457416Smarkm return 1; 6557416Smarkm } 6657416Smarkm } 6757416Smarkm } 6857416Smarkm if (!principal && !enctype && !opt->kvno_integer) { 6957416Smarkm krb5_warnx(context, 7057416Smarkm "You must give at least one of " 7157416Smarkm "principal, enctype or kvno."); 7257416Smarkm ret = EINVAL; 7357416Smarkm goto out; 7457416Smarkm } 7557416Smarkm 7657416Smarkm if((keytab = ktutil_open_keytab()) == NULL) { 7757416Smarkm ret = 1; 7857416Smarkm goto out; 7957416Smarkm } 8057416Smarkm 8157416Smarkm entry.principal = principal; 8257416Smarkm entry.keyblock.keytype = enctype; 8357416Smarkm entry.vno = opt->kvno_integer; 8457416Smarkm ret = krb5_kt_remove_entry(context, keytab, &entry); 8557416Smarkm krb5_kt_close(context, keytab); 8657416Smarkm if(ret) 8757416Smarkm krb5_warn(context, ret, "remove"); 8857416Smarkm out: 8957416Smarkm if(principal) 9057416Smarkm krb5_free_principal(context, principal); 9157416Smarkm return ret != 0; 9257416Smarkm} 9357416Smarkm 9457416Smarkm