remove.c revision 233294
11573Srgrimes/* 21573Srgrimes * Copyright (c) 1997-2004 Kungliga Tekniska H��gskolan 31573Srgrimes * (Royal Institute of Technology, Stockholm, Sweden). 41573Srgrimes * All rights reserved. 51573Srgrimes * 61573Srgrimes * Redistribution and use in source and binary forms, with or without 71573Srgrimes * modification, are permitted provided that the following conditions 81573Srgrimes * are met: 91573Srgrimes * 101573Srgrimes * 1. Redistributions of source code must retain the above copyright 111573Srgrimes * notice, this list of conditions and the following disclaimer. 121573Srgrimes * 13251672Semaste * 2. Redistributions in binary form must reproduce the above copyright 141573Srgrimes * notice, this list of conditions and the following disclaimer in the 151573Srgrimes * documentation and/or other materials provided with the distribution. 161573Srgrimes * 171573Srgrimes * 3. Neither the name of the Institute nor the names of its contributors 181573Srgrimes * may be used to endorse or promote products derived from this software 191573Srgrimes * without specific prior written permission. 201573Srgrimes * 211573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 221573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241573Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 251573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3123662Speter * SUCH DAMAGE. 321573Srgrimes */ 3392986Sobrien 3492986Sobrien#include "ktutil_locl.h" 351573Srgrimes 3671579SdeischenRCSID("$Id$"); 37249035Sdelphij 38249035Sdelphijint 39124738Sdaskt_remove(struct remove_options *opt, int argc, char **argv) 401573Srgrimes{ 411573Srgrimes krb5_error_code ret = 0; 4271579Sdeischen krb5_keytab_entry entry; 431573Srgrimes krb5_keytab keytab; 441573Srgrimes krb5_principal principal = NULL; 451573Srgrimes krb5_enctype enctype = 0; 461573Srgrimes 471573Srgrimes if(opt->principal_string) { 481573Srgrimes ret = krb5_parse_name(context, opt->principal_string, &principal); 491573Srgrimes if(ret) { 501573Srgrimes krb5_warn(context, ret, "%s", opt->principal_string); 511573Srgrimes return 1; 521573Srgrimes } 531573Srgrimes } 541573Srgrimes if(opt->enctype_string) { 551573Srgrimes ret = krb5_string_to_enctype(context, opt->enctype_string, &enctype); 561573Srgrimes if(ret) { 571573Srgrimes int t; 581573Srgrimes if(sscanf(opt->enctype_string, "%d", &t) == 1) 591573Srgrimes enctype = t; 60124738Sdas else { 611573Srgrimes krb5_warn(context, ret, "%s", opt->enctype_string); 621573Srgrimes if(principal) 63124738Sdas krb5_free_principal(context, principal); 641573Srgrimes return 1; 651573Srgrimes } 661573Srgrimes } 678870Srgrimes } 681573Srgrimes if (!principal && !enctype && !opt->kvno_integer) { 691573Srgrimes krb5_warnx(context, 701573Srgrimes "You must give at least one of " 711573Srgrimes "principal, enctype or kvno."); 721573Srgrimes ret = EINVAL; 731573Srgrimes goto out; 741573Srgrimes } 751573Srgrimes 761573Srgrimes if((keytab = ktutil_open_keytab()) == NULL) { 771573Srgrimes ret = 1; 781573Srgrimes goto out; 7992889Sobrien } 801573Srgrimes 811573Srgrimes entry.principal = principal; 8223662Speter entry.keyblock.keytype = enctype; 8323662Speter entry.vno = opt->kvno_integer; 8423662Speter ret = krb5_kt_remove_entry(context, keytab, &entry); 8523662Speter krb5_kt_close(context, keytab); 8623662Speter if(ret) 8723662Speter krb5_warn(context, ret, "remove"); 8823662Speter out: 8923662Speter if(principal) 9023662Speter krb5_free_principal(context, principal); 9123662Speter return ret != 0; 9223662Speter} 9323662Speter 9423662Speter