summaryrefslogtreecommitdiffstats
path: root/src/clients/kdestroy
diff options
context:
space:
mode:
authorDanilo Almeida <dalmeida@mit.edu>2000-02-04 21:23:59 +0000
committerDanilo Almeida <dalmeida@mit.edu>2000-02-04 21:23:59 +0000
commite2b7b0d4b9e4ee2faae9dc219563aeb6a5e300bc (patch)
tree708a265b3731cd5f3926839e92c69b6cf793230a /src/clients/kdestroy
parent9dd256d9113af69545873d9f2b429e2c52e3c931 (diff)
downloadkrb5-e2b7b0d4b9e4ee2faae9dc219563aeb6a5e300bc.tar.gz
krb5-e2b7b0d4b9e4ee2faae9dc219563aeb6a5e300bc.tar.xz
krb5-e2b7b0d4b9e4ee2faae9dc219563aeb6a5e300bc.zip
* kdestroy.c: Major revamp to support Kerberos 4 compatibility. Code
restructured to allow changes to support Kerberos 4 or Kerberos 5 only operation depending on whether dynamic libraries are avialable. Explicit documentation and support files to make it easy to do this will be forthcoming. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11991 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/clients/kdestroy')
-rw-r--r--src/clients/kdestroy/ChangeLog8
-rw-r--r--src/clients/kdestroy/kdestroy.c152
2 files changed, 119 insertions, 41 deletions
diff --git a/src/clients/kdestroy/ChangeLog b/src/clients/kdestroy/ChangeLog
index 41d694f735..509b26b389 100644
--- a/src/clients/kdestroy/ChangeLog
+++ b/src/clients/kdestroy/ChangeLog
@@ -1,3 +1,11 @@
+2000-02-04 Danilo Almeida <dalmeida@mit.edu>
+
+ * kdestroy.c: Major revamp to support Kerberos 4 compatibility. Code
+ restructured to allow changes to support Kerberos 4 or Kerberos 5
+ only operation depending on whether dynamic libraries are
+ avialable. Explicit documentation and support files to make it
+ easy to do this will be forthcoming.
+
1999-12-03 Danilo Almeida <dalmeida@mit.edu>
* Makefile.in: Windows fix for 10/26/99 cleanup.
diff --git a/src/clients/kdestroy/kdestroy.c b/src/clients/kdestroy/kdestroy.c
index 6fdbc652a5..ccc6ecf709 100644
--- a/src/clients/kdestroy/kdestroy.c
+++ b/src/clients/kdestroy/kdestroy.c
@@ -27,14 +27,35 @@
* Destroy the contents of your credential cache.
*/
-#include "krb5.h"
-#include "com_err.h"
+#include <krb5.h>
+#include <com_err.h>
#include <string.h>
#include <stdio.h>
+#ifdef KRB5_KRB4_COMPAT
+#include <kerberosIV/krb.h>
+#define K54_OPT_STRING "45"
+#define K54_USAGE_STRING "[-4] [-5] "
+#else
+#define K54_OPT_STRING ""
+#define K54_USAGE_STRING ""
+#endif
+
+#ifdef __STDC__
+#define BELL_CHAR '\a'
+#else
+#define BELL_CHAR '\007'
+#endif
+
extern int optind;
extern char *optarg;
+#ifndef _WIN32
+#define GET_PROGNAME(x) (strrchr((x), '/') ? strrchr((x), '/')+1 : (x))
+#else
+#define GET_PROGNAME(x) (max(strrchr((x), '/'), strrchr((x), '\\')) + 1, (x))
+#endif
+
int
main(argc, argv)
int argc;
@@ -45,38 +66,46 @@ main(argc, argv)
int c;
krb5_ccache cache = NULL;
char *cache_name = NULL;
- int code;
- int errflg=0;
- int quiet = 0;
-
- retval = krb5_init_context(&kcontext);
- if (retval) {
- com_err(argv[0], retval, "while initializing krb5");
- exit(1);
- }
+ int code = 0;
+ int v4code = 0;
+ int errflg = 0;
+ int quiet = 0;
+ int v4 = 1;
+
+ int got_k4 = 0;
+ int got_k5 = 0;
+
+ int use_k4_only = 0;
+ int use_k5_only = 0;
- if (strrchr(argv[0], '/'))
- argv[0] = strrchr(argv[0], '/')+1;
+ char * progname = GET_PROGNAME(argv[0]);
- while ((c = getopt(argc, argv, "qc:")) != -1) {
+ got_k5 = 1;
+#ifdef KRB5_KRB4_COMPAT
+ got_k4 = 1;
+#endif
+
+ while ((c = getopt(argc, argv, K54_OPT_STRING "qc:")) != -1) {
switch (c) {
case 'q':
quiet = 1;
break;
case 'c':
- if (cache == NULL) {
- cache_name = optarg;
-
- code = krb5_cc_resolve (kcontext, cache_name, &cache);
- if (code != 0) {
- com_err (argv[0], code, "while resolving %s", cache_name);
- errflg++;
- }
- } else {
+ if (cache_name) {
fprintf(stderr, "Only one -c option allowed\n");
errflg++;
+ } else {
+ cache_name = optarg;
}
break;
+#ifdef KRB5_KRB4_COMPAT
+ case '4':
+ use_k4_only = 1;
+ break;
+ case '5':
+ use_k5_only = 1;
+ break;
+#endif
case '?':
default:
errflg++;
@@ -84,34 +113,75 @@ main(argc, argv)
}
}
+ if (use_k4_only && use_k5_only)
+ {
+ fprintf(stderr, "Only one of -4 and -5 allowed\n");
+ errflg++;
+ }
+
if (optind != argc)
errflg++;
if (errflg) {
- fprintf(stderr, "Usage: %s [-q] [ -c cache-name ]\n", argv[0]);
+ fprintf(stderr, "Usage: %s " K54_USAGE_STRING
+ "[-q] [ -c cache-name ]\n", progname);
exit(2);
}
- if (cache == NULL) {
- if (code = krb5_cc_default(kcontext, &cache)) {
- com_err(argv[0], code, "while getting default ccache");
+ if (use_k4_only)
+ got_k5 = 0;
+ if (use_k5_only)
+ got_k4 = 0;
+
+ if (got_k5) {
+ retval = krb5_init_context(&kcontext);
+ if (retval) {
+ com_err(progname, retval, "while initializing krb5");
exit(1);
}
- }
- code = krb5_cc_destroy (kcontext, cache);
- if (code != 0) {
- com_err (argv[0], code, "while destroying cache");
- if (quiet)
- fprintf(stderr, "Ticket cache NOT destroyed!\n");
- else {
-#ifdef __STDC__
- fprintf(stderr, "Ticket cache \aNOT\a destroyed!\n");
-#else
- fprintf(stderr, "Ticket cache \007NOT\007 destroyed!\n");
-#endif
+ if (cache_name) {
+ v4 = 0; /* Don't do v4 if doing v5 and cache name given. */
+ code = krb5_cc_resolve (kcontext, cache_name, &cache);
+ if (code != 0) {
+ com_err (progname, code, "while resolving %s", cache_name);
+ exit(1);
+ }
+ } else {
+ if (code = krb5_cc_default(kcontext, &cache)) {
+ com_err(progname, code, "while getting default ccache");
+ exit(1);
+ }
+ }
+
+ code = krb5_cc_destroy (kcontext, cache);
+ if (code != 0) {
+ com_err (progname, code, "while destroying cache");
+ if (code != KRB5_FCC_NOFILE) {
+ if (quiet)
+ fprintf(stderr, "Ticket cache NOT destroyed!\n");
+ else {
+ fprintf(stderr, "Ticket cache %cNOT%c destroyed!\n",
+ BELL_CHAR, BELL_CHAR);
+ }
+ errflg = 1;
+ }
+ }
+ }
+#ifdef KRB5_KRB4_COMPAT
+ if (got_k4 && v4) {
+ v4code = dest_tkt();
+ if (v4code == KSUCCESS && code != 0)
+ fprintf(stderr, "Kerberos 4 ticket cache destroyed.\n");
+ if (v4code != KSUCCESS && v4code != RET_TKFIL) {
+ if (quiet)
+ fprintf(stderr, "Kerberos 4 ticket cache NOT destroyed!\n");
+ else
+ fprintf(stderr, "Kerberos 4 ticket cache %cNOT%c destroyed!\n",
+ BELL_CHAR, BELL_CHAR);
+ errflg = 1;
}
- exit (1);
}
- exit (0);
+#endif
+ return errflg;
}