[256] in Kerberos-V5-bugs
keytab printing capability for klist
daemon@ATHENA.MIT.EDU (Barry Jaspan)
Fri Nov 20 16:25:51 1992
Date: Fri, 20 Nov 92 15:50:51 -0500
From: "Barry Jaspan" <bjaspan@Athena.MIT.EDU>
To: kerberos@Athena.MIT.EDU, krb5-bugs@Athena.MIT.EDU
The v4 klist hads an option (-srvtab) to interpret the given file as a
srvtab and print it. As far as I can tell, v5 currently lacks that
ability. The following patch adds it to v5 klist. For example,
# klist -k -t
Keytab name: /usr/local/krb5/v5srvtab
KVNO Timestamp Principal
---- ------------------ -------------------------------------------------------
1 16-Nov-92 14:52:47 discuss/pad-thai.aktis.com@AKTIS.COM
1 16-Nov-92 14:52:47 host/pad-thai.aktis.com@AKTIS.COM
1 16-Nov-92 14:52:47 pop/pad-thai.aktis.com@AKTIS.COM
I've changed the semantics of the -c argument slightly, but done so in
a way that is backward compatible with the previous interface in that
all combinations of arguments work in the same way. (Thanks to Marc
Horowitz for the idea.)
Barry Jaspan
Aktis, Inc.
--- snip snip ---
===================================================================
RCS file: RCS/klist.c,v
retrieving revision 5.15
diff -c -r5.15 klist.c
*** 5.15 1992/11/11 19:10:14
--- klist.c 1992/11/20 20:24:48
***************
*** 22,33 ****
* or implied warranty.
*
*
! * List out the contents of your credential cache.
*/
#if !defined(lint) && !defined(SABER)
static char rcsid_klist_c [] =
! "$Id: klist.c,v 5.15 1992/11/11 19:10:14 bjaspan Exp $";
#endif /* !lint & !SABER */
#include <stdio.h>
--- 22,33 ----
* or implied warranty.
*
*
! * List out the contents of your credential cache or keytab.
*/
#if !defined(lint) && !defined(SABER)
static char rcsid_klist_c [] =
! "$Id: klist.c,v 5.16 1992/11/20 20:26:24 bjaspan Exp $";
#endif /* !lint & !SABER */
#include <stdio.h>
***************
*** 39,51 ****
extern int optind;
extern char *optarg;
! int show_flags = 0;
char *progname;
char *defname;
time_t now;
! void
! show_credential PROTOTYPE((krb5_creds *));
void
main(argc, argv)
--- 39,67 ----
extern int optind;
extern char *optarg;
! int show_flags = 0, show_time = 0;
char *progname;
char *defname;
time_t now;
! void show_credential PROTOTYPE((krb5_creds *)),
! do_ccache PROTOTYPE((char *)),
! do_keytab PROTOTYPE((char *)),
! printtime PROTOTYPE((time_t));
!
! #define DEFAULT 0
! #define CCACHE 1
! #define KEYTAB 2
!
! void usage()
! {
! fprintf(stderr, "Usage: %s [-f] [-c|-k] [name]\n", progname);
! fprintf(stderr, "\t-c specifies credentials cache, -k specifies keytab");
! fprintf(stderr, ", -c is default\n");
! fprintf(stderr, "\t-f shows credentials flags\n");
! fprintf(stderr, "\t-t shows keytab entry timestamps\n");
! exit(1);
! }
void
main(argc, argv)
***************
*** 52,114 ****
int argc;
char **argv;
{
! int c;
! int errflg = 0;
! int code;
! krb5_ccache cache = NULL;
! krb5_cc_cursor cur;
! krb5_creds creds;
! char *cache_name;
! krb5_principal princ;
! krb5_flags flags;
krb5_init_ets();
time(&now);
-
- if (strrchr(argv[0], '/'))
- progname = strrchr(argv[0], '/')+1;
- else
- progname = argv[0];
! while ((c = getopt(argc, argv, "fc:")) != EOF) {
! switch (c) {
! case 'f':
! show_flags = 1;
! break;
! case 'c':
! if (cache == NULL) {
! cache_name = optarg;
!
! code = krb5_cc_resolve (cache_name, &cache);
! if (code != 0) {
! com_err(progname, code, "while resolving %s", cache_name);
! errflg++;
! }
! } else {
! fprintf(stderr, "Only one -c option allowed\n");
! errflg++;
! }
! break;
! case '?':
! default:
! errflg++;
! break;
! }
! }
! if (optind != argc)
! errflg++;
!
! if (errflg) {
! fprintf(stderr, "Usage: %s [ -f ] [ -c cache ]\n", progname);
! exit(2);
}
! if (cache == NULL) {
! if (code = krb5_cc_default(&cache)) {
! com_err(progname, code, "while getting default ccache");
! exit(1);
! }
}
flags = 0; /* turns off OPENCLOSE mode */
--- 68,206 ----
int argc;
char **argv;
{
! int mode;
! char *name;
krb5_init_ets();
time(&now);
! progname = (strrchr(*argv, '/') ? strrchr(*argv, '/')+1 : argv[0]);
! argv++;
! name = NULL;
! mode = DEFAULT;
! while (*argv) {
! if ((*argv)[0] != '-') {
! if (name) usage();
! name = *argv;
! } else switch ((*argv)[1]) {
! case 'f':
! show_flags = 1;
! break;
! case 't':
! show_time = 1;
! break;
! case 'c':
! if (mode != DEFAULT) usage();
! mode = CCACHE;
! break;
! case 'k':
! if (mode != DEFAULT) usage();
! mode = KEYTAB;
! break;
! default:
! usage();
! break;
! }
!
! argv++;
}
!
! if (mode == DEFAULT || mode == CCACHE)
! do_ccache(name);
! else
! do_keytab(name);
! }
!
! void do_keytab(name)
! char *name;
! {
! krb5_keytab kt;
! krb5_keytab_entry entry;
! krb5_kt_cursor cursor;
! char buf[BUFSIZ]; /* hopefully large enough for any type */
! char *pname, *tstring;
! int code;
!
! if (name == NULL) {
! if (code = krb5_kt_default(&kt)) {
! com_err(progname, code, "while getting default keytab");
! exit(1);
! }
! } else {
! if (code = krb5_kt_resolve(name, &kt)) {
! com_err(progname, code, "while resolving keytab %s",
! name);
! exit(1);
! }
! }
!
! if (code = krb5_kt_get_name(kt, buf, BUFSIZ)) {
! com_err(progname, code, "while getting keytab name");
! exit(1);
! }
!
! printf("Keytab name: %s\n", buf);
!
! if (code = krb5_kt_start_seq_get(kt, &cursor)) {
! com_err(progname, code, "while starting keytab scan");
! exit(1);
! }
!
! if (show_time) {
! printf("KVNO Timestamp Principal\n");
! printf("---- ------------------ -------------------------------------------------------\n");
! } else {
! printf("KVNO Principal\n");
! printf("---- --------------------------------------------------------------------------\n");
! }
!
! while ((code = krb5_kt_next_entry(kt, &entry, cursor)) == 0) {
! if (code = krb5_unparse_name(entry.principal, &pname)) {
! com_err(progname, code, "while unparsing principal name");
! exit(1);
! }
! printf("%4d ", entry.vno);
! if (show_time) {
! printtime(entry.timestamp);
! printf(" ");
! }
! printf("%s\n", pname);
! free(pname);
! }
! if (code && code != KRB5_KT_END) {
! com_err(progname, code, "while scanning keytab");
! exit(1);
! }
! if (code = krb5_kt_end_seq_get(kt, cursor)) {
! com_err(progname, code, "while ending keytab scan");
! exit(1);
! }
! exit(0);
! }
!
! void do_ccache(name)
! char *name;
! {
! krb5_ccache cache = NULL;
! krb5_cc_cursor cur;
! krb5_creds creds;
! krb5_principal princ;
! krb5_flags flags;
! int code;
!
! if (name == NULL) {
! if (code = krb5_cc_default(&cache)) {
! com_err(progname, code, "while getting default ccache");
! exit(1);
! }
! } else {
! if (code = krb5_cc_resolve(name, &cache)) {
! com_err(progname, code, "while resolving ccache %s",
! name);
! exit(1);
! }
}
flags = 0; /* turns off OPENCLOSE mode */