From 839912ae1c4bb5e6a97055fb775bfb2bdb14b338 Mon Sep 17 00:00:00 2001 From: John Kohl Date: Mon, 29 Apr 1991 14:18:51 +0000 Subject: [PATCH] add code to print times & flags git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2050 dc483132-0cff-0310-8789-dd5450dbe970 --- src/clients/klist/klist.c | 160 +++++++++++++++++++++++++++++--------- 1 file changed, 125 insertions(+), 35 deletions(-) diff --git a/src/clients/klist/klist.c b/src/clients/klist/klist.c index bc5edf402..a608492fd 100644 --- a/src/clients/klist/klist.c +++ b/src/clients/klist/klist.c @@ -21,9 +21,15 @@ static char rcsid_klist_c [] = #include #include #include +#include extern int optind; extern char *optarg; +int show_flags = 0; +char *progname; + +void +show_credential PROTOTYPE((krb5_creds *)); void main(argc, argv) @@ -32,7 +38,6 @@ main(argc, argv) { int c; int errflg = 0; - int show_flags = 0; int code; krb5_ccache cache = NULL; krb5_cc_cursor cur; @@ -42,12 +47,12 @@ main(argc, argv) char *name, *sname; krb5_flags flags; - initialize_krb5_error_table(); - initialize_isod_error_table(); - + krb5_init_ets(); if (strrchr(argv[0], '/')) - argv[0] = strrchr(argv[0], '/')+1; + progname = strrchr(argv[0], '/')+1; + else + progname = argv[0]; while ((c = getopt(argc, argv, "fc:")) != EOF) { switch (c) { @@ -60,7 +65,7 @@ main(argc, argv) code = krb5_cc_resolve (cache_name, &cache); if (code != 0) { - com_err(argv[0], code, "while resolving %s", cache_name); + com_err(progname, code, "while resolving %s", cache_name); errflg++; } } else { @@ -79,12 +84,12 @@ main(argc, argv) errflg++; if (errflg) { - fprintf(stderr, "Usage: %s [ -c cache ]\n", argv[0]); + fprintf(stderr, "Usage: %s [ -c cache ]\n", progname); exit(2); } if (cache == NULL) { if (code = krb5_cc_default(&cache)) { - com_err(argv[0], code, "while getting default ccache"); + com_err(progname, code, "while getting default ccache"); exit(1); } } @@ -92,61 +97,146 @@ main(argc, argv) flags = 0; /* turns off OPENCLOSE mode */ if (code = krb5_cc_set_flags(cache, flags)) { if (code == ENOENT) { - com_err(argv[0], code, "(ticket cache %s)", + com_err(progname, code, "(ticket cache %s)", krb5_cc_get_name(cache)); } else - com_err(argv[0], code, + com_err(progname, code, "while setting cache flags (ticket cache %s)", krb5_cc_get_name(cache)); exit(1); } if (code = krb5_cc_get_principal(cache, &princ)) { - com_err(argv[0], code, "while retrieving principal name"); + com_err(progname, code, "while retrieving principal name"); exit(1); } if (code = krb5_unparse_name(princ, &name)) { - com_err(argv[0], code, "while unparsing principal name"); + com_err(progname, code, "while unparsing principal name"); exit(1); } printf("Ticket cache: %s\nDefault principal: %s\n", krb5_cc_get_name(cache), name); free(name); if (code = krb5_cc_start_seq_get(cache, &cur)) { - com_err(argv[0], code, "while starting to retrieve tickets"); + com_err(progname, code, "while starting to retrieve tickets"); exit(1); } - while (!(code = krb5_cc_next_cred(cache, &cur, &creds))) { - code = krb5_unparse_name(creds.client, &name); - if (code) { - com_err(argv[0], code, "while unparsing client name"); - continue; - } - code = krb5_unparse_name(creds.server, &sname); - if (code) { - com_err(argv[0], code, "while unparsing server name"); - free(name); - continue; - } - if (show_flags) - printf("C: %s\tS: %s\tF: %d\n", name, sname, creds.ticket_flags); - else - printf("C: %s\tS: %s\n", name, sname); - free(name); - free(sname); - } + while (!(code = krb5_cc_next_cred(cache, &cur, &creds))) + show_credential(&creds); if (code == KRB5_CC_END) { if (code = krb5_cc_end_seq_get(cache, &cur)) { - com_err(argv[0], code, "while finishing ticket retrieval"); + com_err(progname, code, "while finishing ticket retrieval"); exit(1); } flags = KRB5_TC_OPENCLOSE; /* turns on OPENCLOSE mode */ if (code = krb5_cc_set_flags(cache, flags)) { - com_err(argv[0], code, "while closing ccache"); + com_err(progname, code, "while closing ccache"); exit(1); } exit(0); } else { - com_err(argv[0], code, "while retrieving a ticket"); + com_err(progname, code, "while retrieving a ticket"); exit(1); } } + +void +print_flags(cred) +register krb5_creds *cred; +{ + printf("F: %X (", cred->ticket_flags); + if (cred->ticket_flags & TKT_FLG_FORWARDABLE) + putchar('F'); + else + putchar(' '); + if (cred->ticket_flags & TKT_FLG_FORWARDED) + putchar('f'); + else + putchar(' '); + if (cred->ticket_flags & TKT_FLG_PROXIABLE) + putchar('P'); + else + putchar(' '); + if (cred->ticket_flags & TKT_FLG_PROXY) + putchar('p'); + else + putchar(' '); + if (cred->ticket_flags & TKT_FLG_MAY_POSTDATE) + putchar('D'); + else + putchar(' '); + if (cred->ticket_flags & TKT_FLG_POSTDATED) + putchar('d'); + else + putchar(' '); + if (cred->ticket_flags & TKT_FLG_INVALID) + putchar('i'); + else + putchar(' '); + if (cred->ticket_flags & TKT_FLG_RENEWABLE) + putchar('R'); + else + putchar(' '); + if (cred->ticket_flags & TKT_FLG_INITIAL) + putchar('I'); + else + putchar(' '); + putchar(')'); +} + +void +show_credential(cred) +register krb5_creds *cred; +{ + krb5_error_code retval; + char *name, *sname; + struct tm *stime; + + retval = krb5_unparse_name(cred->client, &name); + if (retval) { + com_err(progname, retval, "while unparsing client name"); + return; + } + retval = krb5_unparse_name(cred->server, &sname); + if (retval) { + com_err(progname, retval, "while unparsing server name"); + free(name); + return; + } + printf("C: %s\tS: %s\n\t", name, sname); + + if (!cred->times.starttime) + cred->times.starttime = cred->times.authtime; + stime = localtime(&cred->times.starttime); + printf("valid %02d/%02d/%02d:%02d:%02d:%02d to ", + stime->tm_year, + stime->tm_mon + 1, + stime->tm_mday, + stime->tm_hour, + stime->tm_min, + stime->tm_sec); + stime = localtime(&cred->times.endtime); + printf("%02d/%02d/%02d:%02d:%02d:%02d", + stime->tm_year, + stime->tm_mon + 1, + stime->tm_mday, + stime->tm_hour, + stime->tm_min, + stime->tm_sec); + if (cred->times.renew_till) { + stime = localtime(&cred->times.renew_till); + printf("\n\trenew until %02d/%02d/%02d:%02d:%02d:%02d", + stime->tm_year, + stime->tm_mon + 1, + stime->tm_mday, + stime->tm_hour, + stime->tm_min, + stime->tm_sec); + } + if (show_flags) { + fputs("\n\t",stdout); + print_flags(cred); + } + putchar('\n'); + free(name); + free(sname); +} -- 2.26.2