1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* clients/kdestroy/kdestroy.c - Destroy contents of credential cache */
4 * Copyright 1990 by the Massachusetts Institute of Technology.
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. Furthermore if you modify this software you must label
20 * your software as modified software and not distribute it in such a
21 * fashion that it might be confused with the original M.I.T. software.
22 * M.I.T. makes no representations about the suitability of
23 * this software for any purpose. It is provided "as is" without express
24 * or implied warranty.
27 #include "k5-platform.h"
35 #define BELL_CHAR '\a'
37 #define BELL_CHAR '\007'
44 #define GET_PROGNAME(x) (strrchr((x), '/') ? strrchr((x), '/')+1 : (x))
46 #define GET_PROGNAME(x) max(max(strrchr((x), '/'), strrchr((x), '\\')) + 1,(x))
54 #define KRB_AVAIL_STRING(x) ((x)?"available":"not available")
56 fprintf(stderr, _("Usage: %s [-A] [-q] [-c cache_name]\n"), progname);
57 fprintf(stderr, _("\t-A destroy all credential caches in collection\n"));
58 fprintf(stderr, _("\t-q quiet mode\n"));
59 fprintf(stderr, _("\t-c specify name of credentials cache\n"));
63 /* Print a warning if there are still un-destroyed caches in the collection. */
65 print_remaining_cc_warning(krb5_context context)
67 krb5_error_code retval;
69 krb5_cccol_cursor cursor;
71 retval = krb5_cccol_cursor_new(context, &cursor);
73 com_err(progname, retval, _("while listing credential caches"));
77 retval = krb5_cccol_cursor_next(context, cursor, &cache);
78 if (retval == 0 && cache != NULL) {
80 _("Other credential caches present, use -A to destroy all\n"));
81 krb5_cc_close(context, cache);
84 krb5_cccol_cursor_free(context, &cursor);
92 krb5_context kcontext;
93 krb5_error_code retval;
95 krb5_ccache cache = NULL;
96 krb5_cccol_cursor cursor;
97 char *cache_name = NULL;
103 setlocale(LC_ALL, "");
104 progname = GET_PROGNAME(argv[0]);
106 while ((c = getopt(argc, argv, "54Aqc:")) != -1) {
116 fprintf(stderr, _("Only one -c option allowed\n"));
123 fprintf(stderr, _("Kerberos 4 is no longer supported\n"));
142 retval = krb5_init_context(&kcontext);
144 com_err(progname, retval, _("while initializing krb5"));
149 code = krb5_cccol_cursor_new(kcontext, &cursor);
151 com_err(progname, code, _("while listing credential caches"));
154 while ((code = krb5_cccol_cursor_next(kcontext, cursor,
155 &cache)) == 0 && cache != NULL) {
156 code = krb5_cc_get_full_name(kcontext, cache, &cache_name);
158 com_err(progname, code, _("composing ccache name"));
161 code = krb5_cc_destroy(kcontext, cache);
162 if (code && code != KRB5_FCC_NOFILE) {
163 com_err(progname, code, _("while destroying cache %s"),
166 krb5_free_string(kcontext, cache_name);
168 krb5_cccol_cursor_free(kcontext, &cursor);
169 krb5_free_context(kcontext);
174 code = krb5_cc_resolve (kcontext, cache_name, &cache);
176 com_err(progname, code, _("while resolving %s"), cache_name);
180 code = krb5_cc_default(kcontext, &cache);
182 com_err(progname, code, _("while getting default ccache"));
187 code = krb5_cc_destroy (kcontext, cache);
189 com_err (progname, code, _("while destroying cache"));
190 if (code != KRB5_FCC_NOFILE) {
192 fprintf(stderr, _("Ticket cache NOT destroyed!\n"));
194 fprintf(stderr, _("Ticket cache %cNOT%c destroyed!\n"),
195 BELL_CHAR, BELL_CHAR);
201 if (!quiet && !errflg)
202 print_remaining_cc_warning(kcontext);
204 krb5_free_context(kcontext);