/*
 * Copyright 1994 University of Wisconsin-Madison
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of the University of Wisconsin-Madison not
 * be used in advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission.  The University of
 * Wisconsin-Madison makes no representations about the suitability of this
 * software for any purpose.  It is provided "as is" without express or
 * implied warranty.
 *
 * THE UNIVERSITY OF WISCONSIN-MADISON DISCLAIMS ALL WARRANTIES WITH REGARD TO
 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF WISCONSIN-MADISON BE LIABLE FOR
 * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 *           Tim Theisen           Associate Researcher
 * Internet: tim@cs.wisc.edu       Department of Computer Sciences
 *     UUCP: uwvax!tim             University of Wisconsin-Madison
 *    Phone: (608)262-0438         1210 West Dayton Street
 *      FAX: (608)262-9777         Madison, WI   53706-1685
 */

#include <stdio.h>
#include <kerberos/com_err.h>

#include <krb5/krb5.h>
#include <krb5/ext-proto.h>
#include <krb5/los-proto.h>

/*
 * Destroys the credential cache.
 * Returns 0 on success, otherwise an error code.
 * Prints to stderr all problems.
 */
int
#ifdef __STDC__
k5destroy(char *cache_name)
#else
k5destroy(cache_name)
    char *cache_name;		/* "FILE:/tmp/krb_pidXXXXX" for example */
				/* NULL users the default: "/tmp/krb5cc_uid" */
#endif
{
    krb5_error_code code;
    krb5_ccache ccache;

    if (cache_name) {
	if (code = krb5_cc_resolve(cache_name, &ccache)) {
	    com_err("k5destroy", code, "while getting named cache");
	    return code;
	}
    } else {
	if (code = krb5_cc_default(&ccache)) {
	    com_err("k5destroy", code, "while getting default cache");
	    return code;
	}
    }
    if ( code = krb5_cc_destroy(ccache)) {
	com_err ("k5destroy", code, "destroying the credential cache");
    }
    return code;
}
