2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
8 * clients/kdestroy/kdestroy.c
10 * Copyright 1990 by the Massachusetts Institute of Technology.
11 * All Rights Reserved.
13 * Export of this software from the United States of America may
14 * require a specific license from the United States Government.
15 * It is the responsibility of any person or organization contemplating
16 * export to obtain such a license before exporting.
18 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
19 * distribute this software and its documentation for any purpose and
20 * without fee is hereby granted, provided that the above copyright
21 * notice appear in all copies and that both that copyright notice and
22 * this permission notice appear in supporting documentation, and that
23 * the name of M.I.T. not be used in advertising or publicity pertaining
24 * to distribution of the software without specific, written prior
25 * permission. Furthermore if you modify this software you must label
26 * your software as modified software and not distribute it in such a
27 * fashion that it might be confused with the original M.I.T. software.
28 * M.I.T. makes no representations about the suitability of
29 * this software for any purpose. It is provided "as is" without express
30 * or implied warranty.
33 * Destroy the contents of your credential cache.
44 #include <rpc/types.h>
45 #include <rpc/rpcsys.h>
46 #include <rpc/rpcsec_gss.h>
50 #ifdef KRB5_KRB4_COMPAT
51 #include <kerberosIV/krb.h>
55 #define BELL_CHAR '\a'
57 #define BELL_CHAR '\007'
64 #define GET_PROGNAME(x) (strrchr((x), '/') ? strrchr((x), '/')+1 : (x))
66 #define GET_PROGNAME(x) max(max(strrchr((x), '/'), strrchr((x), '\\')) + 1,(x))
75 #ifdef KRB5_KRB4_COMPAT
84 #define KRB_AVAIL_STRING(x) ((x)?gettext("available"):gettext("not available"))
86 fprintf(stderr
, gettext("Usage"), ": %s [-5] [-4] [-q] [-c cache_name]\n",
88 fprintf(stderr
, "\t-5 Kerberos 5 (%s)\n", KRB_AVAIL_STRING(got_k5
));
89 fprintf(stderr
, "\t-4 Kerberos 4 (%s)\n", KRB_AVAIL_STRING(got_k4
));
90 fprintf(stderr
, gettext("\t (Default is %s%s%s%s)\n"),
91 default_k5
?"Kerberos 5":"",
92 (default_k5
&& default_k4
)?gettext(" and "):"",
93 default_k4
?"Kerberos 4":"",
94 (!default_k5
&& !default_k4
)?gettext("neither"):"");
95 fprintf(stderr
, gettext("\t-q quiet mode\n"));
96 fprintf(stderr
, gettext("\t-c specify name of credentials cache\n"));
105 krb5_context kcontext
;
106 krb5_error_code retval
;
108 krb5_ccache cache
= NULL
;
109 char *cache_name
= NULL
;
110 char *client_name
= NULL
;
113 #ifdef KRB5_KRB4_COMPAT
119 struct krpc_revauth desarg
;
120 static rpc_gss_OID_desc oid
=
121 {9, "\052\206\110\206\367\022\001\002\002"};
123 static rpc_gss_OID krb5_mech_type
= &oid
;
128 progname
= GET_PROGNAME(argv
[0]);
129 /* set locale and domain for internationalization */
130 (void) setlocale(LC_ALL
, "");
132 #if !defined(TEXT_DOMAIN)
133 #define TEXT_DOMAIN "SYS_TEST"
134 #endif /* !TEXT_DOMAIN */
136 (void) textdomain(TEXT_DOMAIN
);
139 #ifdef KRB5_KRB4_COMPAT
143 while ((c
= getopt(argc
, argv
, "54qc:")) != -1) {
150 fprintf(stderr
, gettext("Only one -c option allowed\n"));
159 #ifdef KRB5_KRB4_COMPAT
160 fprintf(stderr
, "Kerberos 4 support could not be loaded\n");
162 fprintf(stderr
, gettext("This was not built with Kerberos 4 support\n"));
171 fprintf(stderr
, gettext("Kerberos 5 support could not be loaded\n"));
190 if (!use_k5
&& !use_k4
)
202 retval
= krb5_init_context(&kcontext
);
204 com_err(progname
, retval
, gettext("while initializing krb5"));
210 * Let us destroy the kernel cache first
213 desarg
.uid_1
= geteuid();
214 desarg
.rpcsec_flavor_1
= RPCSEC_GSS
;
215 desarg
.flavor_data_1
= (void *) krb5_mech_type
;
216 code
= krpc_sys(KRPC_REVAUTH
, (void *)&desarg
);
220 gettext("%s: kernel creds cache error %d \n"),
225 if (code
= krb5_cc_default(kcontext
, &cache
)) {
226 com_err(progname
, code
,
227 gettext("while getting default ccache"));
233 #ifdef KRB5_KRB4_COMPAT
234 v4
= 0; /* Don't do v4 if doing v5 and cache name given. */
236 code
= krb5_cc_resolve (kcontext
, cache_name
, &cache
);
238 com_err (progname
, code
, gettext("while resolving %s"), cache_name
);
242 code
= krb5_cc_default(kcontext
, &cache
);
244 com_err(progname
, code
, gettext("while getting default ccache"));
251 * Get client name for kwarn_del_warning.
253 code
= krb5_cc_get_principal(kcontext
, cache
, &me
);
255 fprintf(stderr
, gettext
256 ("%s: Could not obtain principal name from cache\n"), progname
);
258 if ((code
= krb5_unparse_name(kcontext
, me
, &client_name
)))
259 fprintf(stderr
, gettext
260 ("%s: Could not unparse principal name found in cache\n"), progname
);
262 code
= krb5_cc_destroy (kcontext
, cache
);
264 com_err (progname
, code
, gettext("while destroying cache"));
265 if (code
!= KRB5_FCC_NOFILE
) {
267 fprintf(stderr
, gettext("Ticket cache NOT destroyed!\n"));
269 fprintf(stderr
, gettext("Ticket cache %cNOT%c destroyed!\n"),
270 BELL_CHAR
, BELL_CHAR
);
276 #ifdef KRB5_KRB4_COMPAT
279 if (v4code
== KSUCCESS
&& code
!= 0)
280 fprintf(stderr
, "Kerberos 4 ticket cache destroyed.\n");
281 if (v4code
!= KSUCCESS
&& v4code
!= RET_TKFIL
) {
283 fprintf(stderr
, "Kerberos 4 ticket cache NOT destroyed!\n");
285 fprintf(stderr
, "Kerberos 4 ticket cache %cNOT%c destroyed!\n",
286 BELL_CHAR
, BELL_CHAR
);
292 /* Solaris Kerberos */
293 if (!errflg
&& client_name
)
294 kwarn_del_warning(client_name
);
296 fprintf(stderr
, gettext
297 ("%s: TGT expire warning NOT deleted\n"), progname
);