[268] in Kerberos-V5-bugs
CORRECTION: bugfix and new feature for V5 klist
daemon@ATHENA.MIT.EDU (Barry Jaspan)
Wed Dec 16 12:42:31 1992
Date: Wed, 16 Dec 92 12:21:02 -0500
From: "Barry Jaspan" <bjaspan@Athena.MIT.EDU>
To: bjaspan@Athena.MIT.EDU
Cc: kerberos@Athena.MIT.EDU, krb5-bugs@Athena.MIT.EDU
In-Reply-To: "Barry Jaspan"'s message of Wed, 16 Dec 92 11:53:05 -0500 <9212161653.AA18485@marinara>
Oops.
My previous patch does not disable the display of error messages when
-s is specified. This one does. DISREGARD THE PREVIOUS PATCH, and
USE THIS ONE INSTEAD.
Barry Jaspan
Aktis, Inc.
===================================================================
RCS file: RCS/klist.c,v
retrieving revision 5.17
diff -c -r5.17 klist.c
*** 5.17 1992/12/03 23:23:55
--- klist.c 1992/12/16 17:04:11
***************
*** 27,33 ****
#if !defined(lint) && !defined(SABER)
static char rcsid_klist_c [] =
! "$Id: klist.c,v 5.17 1992/12/03 23:23:55 bjaspan Exp $";
#endif /* !lint & !SABER */
#include <stdio.h>
--- 27,33 ----
#if !defined(lint) && !defined(SABER)
static char rcsid_klist_c [] =
! "$Id: klist.c,v 5.18 1992/12/16 16:55:25 bjaspan Exp bjaspan $";
#endif /* !lint & !SABER */
#include <stdio.h>
***************
*** 39,45 ****
extern int optind;
extern char *optarg;
! int show_flags = 0, show_time = 0;
char *progname;
char *defname;
time_t now;
--- 39,45 ----
extern int optind;
extern char *optarg;
! int show_flags = 0, show_time = 0, status_only = 0;
char *progname;
char *defname;
time_t now;
***************
*** 55,65 ****
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);
}
--- 55,66 ----
void usage()
{
! fprintf(stderr, "Usage: %s [-f] [-t] [-s] [-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");
+ fprintf(stderr, "\t-s sets exit status based on valid tgt existence\n");
exit(1);
}
***************
*** 68,80 ****
int argc;
char **argv;
{
! int mode;
char *name;
krb5_init_ets();
- time(&now);
-
progname = (strrchr(*argv, '/') ? strrchr(*argv, '/')+1 : argv[0]);
argv++;
--- 69,79 ----
int argc;
char **argv;
{
! int mode, code;
char *name;
krb5_init_ets();
progname = (strrchr(*argv, '/') ? strrchr(*argv, '/')+1 : argv[0]);
argv++;
***************
*** 91,96 ****
--- 90,98 ----
case 't':
show_time = 1;
break;
+ case 's':
+ status_only = 1;
+ break;
case 'c':
if (mode != DEFAULT) usage();
mode = CCACHE;
***************
*** 107,112 ****
--- 109,120 ----
argv++;
}
+ if (code = krb5_timeofday(&now)) {
+ if (!status_only)
+ com_err(progname, code, "while getting time of day.");
+ exit(1);
+ }
+
if (mode == DEFAULT || mode == CCACHE)
do_ccache(name);
else
***************
*** 188,204 ****
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);
}
}
--- 196,220 ----
krb5_creds creds;
krb5_principal princ;
krb5_flags flags;
! int code, exit_status;
+ if (status_only)
+ /* exit_status is set back to 0 if a valid tgt is found */
+ exit_status = 1;
+ else
+ exit_status = 0;
+
if (name == NULL) {
if (code = krb5_cc_default(&cache)) {
! if (!status_only)
! com_err(progname, code, "while getting default ccache");
exit(1);
}
} else {
if (code = krb5_cc_resolve(name, &cache)) {
! if (!status_only)
! com_err(progname, code, "while resolving ccache %s",
! name);
exit(1);
}
}
***************
*** 206,251 ****
flags = 0; /* turns off OPENCLOSE mode */
if (code = krb5_cc_set_flags(cache, flags)) {
if (code == ENOENT) {
! com_err(progname, code, "(ticket cache %s)",
! krb5_cc_get_name(cache));
} else
! 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(progname, code, "while retrieving principal name");
! exit(1);
}
if (code = krb5_unparse_name(princ, &defname)) {
! com_err(progname, code, "while unparsing principal name");
! exit(1);
}
! printf("Ticket cache: %s\nDefault principal: %s\n\n",
! krb5_cc_get_name(cache), defname);
if (code = krb5_cc_start_seq_get(cache, &cur)) {
! com_err(progname, code, "while starting to retrieve tickets");
! exit(1);
}
! fputs(" Valid starting Expires Service principal\n",
! stdout);
! 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(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(progname, code, "while closing ccache");
! exit(1);
}
! exit(0);
} else {
! com_err(progname, code, "while retrieving a ticket");
! exit(1);
}
}
--- 222,292 ----
flags = 0; /* turns off OPENCLOSE mode */
if (code = krb5_cc_set_flags(cache, flags)) {
if (code == ENOENT) {
! if (!status_only)
! com_err(progname, code, "(ticket cache %s)",
! krb5_cc_get_name(cache));
} else
! if (!status_only)
! 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)) {
! if (!status_only)
! com_err(progname, code, "while retrieving principal name");
! exit(1);
}
if (code = krb5_unparse_name(princ, &defname)) {
! if (!status_only)
! com_err(progname, code, "while unparsing principal name");
! exit(1);
! }
!
! if (!status_only) {
! printf("Ticket cache: %s\nDefault principal: %s\n\n",
! krb5_cc_get_name(cache), defname);
! fputs(" Valid starting Expires Service principal\n",
! stdout);
}
!
if (code = krb5_cc_start_seq_get(cache, &cur)) {
! if (!status_only)
! com_err(progname, code, "while starting to retrieve tickets");
! exit(1);
! }
!
! while (!(code = krb5_cc_next_cred(cache, &cur, &creds))) {
! if (status_only && exit_status) {
! if (creds.server->length == 2 &&
! strcmp(creds.server->realm.data, princ->realm.data) == 0 &&
! strcmp((char *)creds.server->data[0].data, "krbtgt") == 0 &&
! strcmp((char *)creds.server->data[1].data,
! princ->realm.data) == 0 &&
! creds.times.endtime > now)
! exit_status = 0;
! } else {
! show_credential(&creds);
! }
}
!
if (code == KRB5_CC_END) {
if (code = krb5_cc_end_seq_get(cache, &cur)) {
! if (!status_only)
! 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)) {
! if (!status_only)
! com_err(progname, code, "while closing ccache");
! exit(1);
}
! exit(exit_status);
} else {
! if (!status_only)
! com_err(progname, code, "while retrieving a ticket");
! exit(1);
}
}