1 /* $NetBSD: kdestroy.c,v 1.1.1.2 2014/04/24 12:45:28 pettai Exp $ */
4 * Copyright (c) 1997 - 2000, 2003 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include "kuser_locl.h"
38 static const char *cache
;
39 static const char *credential
;
41 static int version_flag
;
43 static int unlog_flag
= 1;
45 static int dest_tkt_flag
= 1;
46 static int all_flag
= 0;
48 struct getargs args
[] = {
49 { "credential", 0, arg_string
, rk_UNCONST(&credential
),
50 "remove one credential", "principal" },
51 { "cache", 'c', arg_string
, rk_UNCONST(&cache
), "cache to destroy", "cache" },
52 { "all", 'A', arg_flag
, &all_flag
, "destroy all caches", NULL
},
54 { "unlog", 0, arg_negative_flag
, &unlog_flag
,
55 "do not destroy tokens", NULL
},
57 { "delete-v4", 0, arg_negative_flag
, &dest_tkt_flag
,
58 "do not destroy v4 tickets", NULL
},
59 { "version", 0, arg_flag
, &version_flag
, NULL
, NULL
},
60 { "help", 'h', arg_flag
, &help_flag
, NULL
, NULL
}
63 int num_args
= sizeof(args
) / sizeof(args
[0]);
68 arg_printusage (args
, num_args
, NULL
, "");
73 main (int argc
, char **argv
)
81 setprogname (argv
[0]);
83 if(getarg(args
, num_args
, argc
, argv
, &optidx
))
100 ret
= krb5_init_context (&context
);
102 errx (1, "krb5_init_context failed: %d", ret
);
105 krb5_cccol_cursor cursor
;
107 ret
= krb5_cccol_cursor_new (context
, &cursor
);
109 krb5_err(context
, 1, ret
, "krb5_cccol_cursor_new");
111 while (krb5_cccol_cursor_next (context
, cursor
, &ccache
) == 0 && ccache
!= NULL
) {
113 ret
= krb5_cc_destroy (context
, ccache
);
115 krb5_warn(context
, ret
, "krb5_cc_destroy");
119 krb5_cccol_cursor_free(context
, &cursor
);
123 ret
= krb5_cc_default(context
, &ccache
);
125 krb5_err(context
, 1, ret
, "krb5_cc_default");
127 ret
= krb5_cc_resolve(context
,
131 krb5_err(context
, 1, ret
, "krb5_cc_resolve");
138 krb5_cc_clear_mcred(&mcred
);
140 ret
= krb5_parse_name(context
, credential
, &mcred
.server
);
142 krb5_err(context
, 1, ret
,
143 "Can't parse principal %s", credential
);
145 ret
= krb5_cc_remove_cred(context
, ccache
, 0, &mcred
);
147 krb5_err(context
, 1, ret
,
148 "Failed to remove principal %s", credential
);
150 krb5_cc_close(context
, ccache
);
151 krb5_free_principal(context
, mcred
.server
);
152 krb5_free_context(context
);
156 ret
= krb5_cc_destroy (context
, ccache
);
158 krb5_warn(context
, ret
, "krb5_cc_destroy");
164 krb5_free_context (context
);
167 if (unlog_flag
&& k_hasafs ()) {