From 916555623ea3c0cd8976718f0b989280df9260ce Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Mon, 5 Sep 2011 16:26:48 +0000 Subject: Add ccache collection support to tools * "kdestroy -A" destroys all caches in collection. * "kinit princ" searches the collection for a matching cache and overwrites it, or creates a new cache in the collection, if the type of the default cache is collection-enabled. The chosen cache also becomes the primary cache for the collection. * "klist -l" lists (in summary form) the caches in the collection. * "klist -A" lists the content of all of the caches in the collection. * "kswitch -c cache" (new command) makes cache the primary cache. * "kswitch -p princ" makes the cache for princ the primary cache. ticket: 6956 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25157 dc483132-0cff-0310-8789-dd5450dbe970 --- src/clients/kdestroy/kdestroy.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'src/clients/kdestroy/kdestroy.c') diff --git a/src/clients/kdestroy/kdestroy.c b/src/clients/kdestroy/kdestroy.c index 73ce04459b..abe49533d4 100644 --- a/src/clients/kdestroy/kdestroy.c +++ b/src/clients/kdestroy/kdestroy.c @@ -55,7 +55,8 @@ static void usage() { #define KRB_AVAIL_STRING(x) ((x)?"available":"not available") - fprintf(stderr, _("Usage: %s [-q] [-c cache_name]\n"), progname); + fprintf(stderr, _("Usage: %s [-A] [-q] [-c cache_name]\n"), progname); + fprintf(stderr, _("\t-A destroy all credential caches in collection\n")); fprintf(stderr, _("\t-q quiet mode\n")); fprintf(stderr, _("\t-c specify name of credentials cache\n")); exit(2); @@ -70,16 +71,21 @@ main(argc, argv) krb5_error_code retval; int c; krb5_ccache cache = NULL; + krb5_cccol_cursor cursor; char *cache_name = NULL; int code = 0; int errflg = 0; int quiet = 0; + int all = 0; setlocale(LC_MESSAGES, ""); progname = GET_PROGNAME(argv[0]); - while ((c = getopt(argc, argv, "54qc:")) != -1) { + while ((c = getopt(argc, argv, "54Aqc:")) != -1) { switch (c) { + case 'A': + all = 1; + break; case 'q': quiet = 1; break; @@ -117,6 +123,30 @@ main(argc, argv) exit(1); } + if (all) { + code = krb5_cccol_cursor_new(kcontext, &cursor); + if (code) { + com_err(progname, code, _("while listing credential caches")); + exit(1); + } + while ((code = krb5_cccol_cursor_next(kcontext, cursor, + &cache)) == 0 && cache != NULL) { + code = krb5_cc_get_full_name(kcontext, cache, &cache_name); + if (code) { + com_err(progname, code, _("composing ccache name")); + exit(1); + } + code = krb5_cc_destroy(kcontext, cache); + if (code && code != KRB5_FCC_NOFILE) { + com_err(progname, code, _("while destroying cache %s"), + cache_name); + } + krb5_free_string(kcontext, cache_name); + } + krb5_cccol_cursor_free(kcontext, &cursor); + return 0; + } + if (cache_name) { code = krb5_cc_resolve (kcontext, cache_name, &cache); if (code != 0) { -- cgit