* $Source: /usr/src/kerberosIV/klist/RCS/klist.c,v $
* Copyright 1987, 1988 by the Massachusetts Institute of Technology.
* For copying and distribution information, please see the file
* Lists your current Kerberos tickets.
* Written by Bill Sommerfeld, MIT Project Athena.
static char rcsid_klist_c
[] =
"$Header: /usr/src/kerberosIV/klist/RCS/klist.c,v 4.16 90/06/25 21:01:52 kfall Exp $";
#include <mit-copyright.h>
char *whoami
; /* What was I invoked as?? */
extern char *krb_err_txt
[];
whoami
= (cp
= rindex(*argv
, '/')) ? cp
+ 1 : *argv
;
if (!strcmp(*argv
, "-s")) {
if (!strcmp(*argv
, "-t")) {
if (!strcmp(*argv
, "-l")) { /* now default */
if (!strcmp(*argv
, "-file")) {
if (!strcmp(*argv
, "-srvtab")) {
if (tkt_file
== NULL
) /* if no other file spec'ed,
set file to default srvtab */
display_srvtab(tkt_file
);
display_tktfile(tkt_file
, tgt_test
, long_form
);
display_tktfile(file
, tgt_test
, long_form
)
if ((file
== NULL
) && ((file
= getenv("KRBTKFILE")) == NULL
))
printf("Ticket file: %s\n", file
);
* Since krb_get_tf_realm will return a ticket_file error,
* we will call tf_init and tf_close first to filter out
* things like no ticket file. Otherwise, the error that
* the user would see would be
* klist: can't find realm of ticket file: No ticket file (tf_util)
* klist: No ticket file (tf_util)
if (k_errno
= tf_init(file
, R_TKT_FIL
)) {
fprintf(stderr
, "%s: %s\n", whoami
, krb_err_txt
[k_errno
]);
* We must find the realm of the ticket file here before calling
* tf_init because since the realm of the ticket file is not
* really stored in the principal section of the file, the
* routine we use must itself call tf_init and tf_close.
if ((k_errno
= krb_get_tf_realm(file
, prealm
)) != KSUCCESS
) {
fprintf(stderr
, "%s: can't find realm of ticket file: %s\n",
whoami
, krb_err_txt
[k_errno
]);
if (k_errno
= tf_init(file
, R_TKT_FIL
)) {
fprintf(stderr
, "%s: %s\n", whoami
, krb_err_txt
[k_errno
]);
/* Get principal name and instance */
if ((k_errno
= tf_get_pname(pname
)) ||
(k_errno
= tf_get_pinst(pinst
))) {
fprintf(stderr
, "%s: %s\n", whoami
, krb_err_txt
[k_errno
]);
* You may think that this is the obvious place to get the
* realm of the ticket file, but it can't be done here as the
* routine to do this must open the ticket file. This is why
* it was done before tf_init.
if (!tgt_test
&& long_form
)
printf("Principal:\t%s%s%s%s%s\n\n", pname
,
(pinst
[0] ? "." : ""), pinst
,
(prealm
[0] ? "@" : ""), prealm
);
while ((k_errno
= tf_get_cred(&c
)) == KSUCCESS
) {
if (!tgt_test
&& long_form
&& header
) {
printf("%-15s %-15s %s\n",
" Issued", " Expires", " Principal");
c
.issue_date
+= ((unsigned char) c
.lifetime
) * 5 * 60;
if (!strcmp(c
.service
, TICKET_GRANTING_TICKET
) &&
!strcmp(c
.instance
, prealm
)) {
if (time(0) < c
.issue_date
)
exit(0); /* tgt hasn't expired */
exit(1); /* has expired */
continue; /* not a tgt */
(void) strcpy(buf1
, short_date(&c
.issue_date
));
c
.issue_date
+= ((unsigned char) c
.lifetime
) * 5 * 60;
(void) strcpy(buf2
, short_date(&c
.issue_date
));
printf("%s %s ", buf1
, buf2
);
c
.service
, (c
.instance
[0] ? "." : ""), c
.instance
,
(c
.realm
[0] ? "@" : ""), c
.realm
);
exit(1); /* no tgt found */
if (header
&& long_form
&& k_errno
== EOF
) {
printf("No tickets in file.\n");
"Usage: %s [ -s | -t ] [ -file filename ] [ -srvtab ]\n", whoami
);
printf("Server key file: %s\n", file
);
if ((stab
= open(file
, O_RDONLY
, 0400)) < 0) {
printf("%-15s %-15s %-10s %s\n","Service","Instance","Realm",
printf("------------------------------------------------------\n");
/* argh. getst doesn't return error codes, it silently fails */
while (((count
= ok_getst(stab
, serv
, SNAME_SZ
)) > 0)
&& ((count
= ok_getst(stab
, inst
, INST_SZ
)) > 0)
&& ((count
= ok_getst(stab
, rlm
, REALM_SZ
)) > 0)) {
if (((count
= read(stab
,(char *) &vno
,1)) != 1) ||
((count
= read(stab
,(char *) key
,8)) != 8)) {
perror("reading from key file");
fprintf(stderr
, "key file truncated\n");
printf("%-15s %-15s %-15s %d\n",serv
,inst
,rlm
,vno
);
/* adapted from getst() in librkb */
* ok_getst() takes a file descriptor, a string and a count. It reads
* from the file until either it has read "count" characters, or until
* it reads a null byte. When finished, what has been read exists in
* the given string "s". If "count" characters were actually read, the
* last is changed to a null, so the returned string is always null-
* terminated. ok_getst() returns the number of characters read, including
* If there is a read error, it returns -1 (like the read(2) system call)
while ((err
= read(fd
, s
, 1)) > 0 && --count
)