[267] in Kerberos-V5-bugs
bugfix and new feature for V5 klist
daemon@ATHENA.MIT.EDU (Barry Jaspan)
Wed Dec 16 12:14:07 1992
Date: Wed, 16 Dec 92 11:53:05 -0500
From: "Barry Jaspan" <bjaspan@Athena.MIT.EDU>
To: kerberos@Athena.MIT.EDU, krb5-bugs@Athena.MIT.EDU
This patch makes two changes in V5 klist:
1. Usage of the Unix function time() is replaced with
krb5_timeofday().
2. The -s option sets the exit status to zero if a non-expired tgt
for the cache's principal's realm exists, one otherwise. This is
similar to V4 klist's -t option. Note that the renew_until time does
not affect the exit status; I'm not sure how renewable tickets
should affect the semantics of -s.
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 16:38:57
***************
*** 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,82 ****
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;
--- 69,86 ----
int argc;
char **argv;
{
! int mode, code;
char *name;
krb5_init_ets();
progname = (strrchr(*argv, '/') ? strrchr(*argv, '/')+1 : argv[0]);
+ if (code = krb5_timeofday(&now)) {
+ com_err(progname, code, "while getting time of day.");
+ exit(1);
+ }
+
argv++;
name = NULL;
mode = DEFAULT;
***************
*** 91,96 ****
--- 95,103 ----
case 't':
show_time = 1;
break;
+ case 's':
+ status_only = 1;
+ break;
case 'c':
if (mode != DEFAULT) usage();
mode = CCACHE;
***************
*** 188,195 ****
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");
--- 195,208 ----
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)) {
com_err(progname, code, "while getting default ccache");
***************
*** 222,237 ****
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");
--- 235,267 ----
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)) {
! 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)) {
com_err(progname, code, "while finishing ticket retrieval");
***************
*** 242,248 ****
com_err(progname, code, "while closing ccache");
exit(1);
}
! exit(0);
} else {
com_err(progname, code, "while retrieving a ticket");
exit(1);
--- 272,278 ----
com_err(progname, code, "while closing ccache");
exit(1);
}
! exit(exit_status);
} else {
com_err(progname, code, "while retrieving a ticket");
exit(1);