kdestroy.c revision 72445
155682Smarkm/*
272445Sassar * Copyright (c) 1997 - 2000 Kungliga Tekniska H�gskolan
355682Smarkm * (Royal Institute of Technology, Stockholm, Sweden).
455682Smarkm * All rights reserved.
555682Smarkm *
655682Smarkm * Redistribution and use in source and binary forms, with or without
755682Smarkm * modification, are permitted provided that the following conditions
855682Smarkm * are met:
955682Smarkm *
1055682Smarkm * 1. Redistributions of source code must retain the above copyright
1155682Smarkm *    notice, this list of conditions and the following disclaimer.
1255682Smarkm *
1355682Smarkm * 2. Redistributions in binary form must reproduce the above copyright
1455682Smarkm *    notice, this list of conditions and the following disclaimer in the
1555682Smarkm *    documentation and/or other materials provided with the distribution.
1655682Smarkm *
1755682Smarkm * 3. Neither the name of the Institute nor the names of its contributors
1855682Smarkm *    may be used to endorse or promote products derived from this software
1955682Smarkm *    without specific prior written permission.
2055682Smarkm *
2155682Smarkm * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
2255682Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2355682Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2455682Smarkm * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
2555682Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2655682Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2755682Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2855682Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2955682Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3055682Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3155682Smarkm * SUCH DAMAGE.
3255682Smarkm */
3355682Smarkm
3455682Smarkm#include "kuser_locl.h"
3572445SassarRCSID("$Id: kdestroy.c,v 1.12 2000/12/31 07:51:09 assar Exp $");
3655682Smarkm
3755682Smarkmstatic const char *cache;
3855682Smarkmstatic int help_flag;
3955682Smarkmstatic int version_flag;
4055682Smarkmstatic int unlog_flag = 1;
4155682Smarkmstatic int dest_tkt_flag = 1;
4255682Smarkm
4355682Smarkmstruct getargs args[] = {
4455682Smarkm    { "cache",		'c', arg_string, &cache, "cache to destroy", "cache" },
4555682Smarkm    { "unlog",		0,   arg_negative_flag, &unlog_flag,
4655682Smarkm      "do not destroy tokens", NULL },
4755682Smarkm    { "delete-v4",	0,   arg_negative_flag, &dest_tkt_flag,
4855682Smarkm      "do not destroy v4 tickets", NULL },
4955682Smarkm    { "version", 	0,   arg_flag, &version_flag, NULL, NULL },
5055682Smarkm    { "help",		'h', arg_flag, &help_flag, NULL, NULL}
5155682Smarkm};
5255682Smarkm
5355682Smarkmint num_args = sizeof(args) / sizeof(args[0]);
5455682Smarkm
5555682Smarkmstatic void
5655682Smarkmusage (int status)
5755682Smarkm{
5855682Smarkm    arg_printusage (args, num_args, NULL, "");
5955682Smarkm    exit (status);
6055682Smarkm}
6155682Smarkm
6255682Smarkmint
6355682Smarkmmain (int argc, char **argv)
6455682Smarkm{
6555682Smarkm    krb5_error_code ret;
6655682Smarkm    krb5_context context;
6755682Smarkm    krb5_ccache  ccache;
6855682Smarkm    int optind = 0;
6955682Smarkm    int exit_val = 0;
7055682Smarkm
7155682Smarkm    set_progname (argv[0]);
7255682Smarkm
7355682Smarkm    if(getarg(args, num_args, argc, argv, &optind))
7455682Smarkm	usage(1);
7555682Smarkm
7655682Smarkm    if (help_flag)
7755682Smarkm	usage (0);
7855682Smarkm
7955682Smarkm    if(version_flag){
8055682Smarkm	print_version(NULL);
8155682Smarkm	exit(0);
8255682Smarkm    }
8355682Smarkm
8455682Smarkm    argc -= optind;
8555682Smarkm    argv += optind;
8655682Smarkm
8755682Smarkm    if (argc != 0)
8855682Smarkm	usage (1);
8955682Smarkm
9055682Smarkm    ret = krb5_init_context (&context);
9155682Smarkm    if (ret)
9272445Sassar	errx (1, "krb5_init_context failed: %d", ret);
9355682Smarkm
9455682Smarkm    if(cache == NULL)
9555682Smarkm	cache = krb5_cc_default_name(context);
9655682Smarkm
9755682Smarkm    ret =  krb5_cc_resolve(context,
9855682Smarkm			   cache,
9955682Smarkm			   &ccache);
10055682Smarkm
10155682Smarkm    if (ret == 0) {
10255682Smarkm	ret = krb5_cc_destroy (context, ccache);
10355682Smarkm	if (ret) {
10455682Smarkm	    warnx ("krb5_cc_destroy: %s", krb5_get_err_text(context, ret));
10555682Smarkm	    exit_val = 1;
10655682Smarkm	}
10755682Smarkm    } else {
10855682Smarkm	warnx ("krb5_cc_resolve(%s): %s", cache,
10955682Smarkm	       krb5_get_err_text(context, ret));
11055682Smarkm	exit_val = 1;
11155682Smarkm    }
11255682Smarkm
11355682Smarkm    krb5_free_context (context);
11455682Smarkm
11555682Smarkm#if KRB4
11655682Smarkm    if(dest_tkt_flag && dest_tkt ())
11755682Smarkm	exit_val = 1;
11855682Smarkm    if (unlog_flag && k_hasafs ()) {
11955682Smarkm	if (k_unlog ())
12055682Smarkm	    exit_val = 1;
12155682Smarkm    }
12255682Smarkm#endif
12355682Smarkm
12455682Smarkm    return exit_val;
12555682Smarkm}
126