2 * Copyright (c) 1997 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Kungliga Tekniska
20 * Högskolan and its contributors.
22 * 4. Neither the name of the Institute nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include "kuser_locl.h"
44 printable_time(time_t t
)
47 strcpy(s
, ctime(&t
)+ 4);
53 printable_time_long(time_t t
)
56 strcpy(s
, ctime(&t
)+ 4);
62 print_cred(krb5_context context
, krb5_creds
*cred
)
68 krb5_timeofday (context
, &sec
);
70 if(cred
->times
.starttime
)
71 printf ("%s ", printable_time(cred
->times
.starttime
));
73 printf ("%s ", printable_time(cred
->times
.authtime
));
75 if(cred
->times
.endtime
> sec
)
76 printf ("%s ", printable_time(cred
->times
.endtime
));
78 printf ("%-15s ", ">>>Expired<<<");
79 ret
= krb5_unparse_name (context
, cred
->server
, &str
);
81 krb5_err(context
, 1, ret
, "krb5_unparse_name");
87 print_cred_verbose(krb5_context context
, krb5_creds
*cred
)
95 krb5_timeofday (context
, &sec
);
97 ret
= krb5_unparse_name(context
, cred
->server
, &str
);
100 printf("Server: %s\n", str
);
106 decode_Ticket(cred
->ticket
.data
, cred
->ticket
.length
, &t
, &len
);
107 krb5_etype_to_string(context
, t
.enc_part
.etype
, &s
);
108 printf("Ticket etype: %s", s
);
111 printf(", kvno %d", *t
.enc_part
.kvno
);
115 krb5_keytype_to_string(context
, cred
->session
.keytype
, &str
);
116 printf("Session key: %s\n", str
);
118 printf("Auth time: %s\n", printable_time_long(cred
->times
.authtime
));
119 if(cred
->times
.authtime
!= cred
->times
.starttime
)
120 printf("Start time: %s\n", printable_time_long(cred
->times
.starttime
));
121 printf("End time: %s", printable_time_long(cred
->times
.endtime
));
122 if(sec
> cred
->times
.endtime
)
123 printf(" (expired)");
125 if(cred
->flags
.b
.renewable
)
126 printf("Renew till: %s\n",
127 printable_time_long(cred
->times
.renew_till
));
128 printf("Ticket flags: ");
129 #define PRINT_FLAG2(f, s) if(cred->flags.b.f) { if(!first_flag) printf(", "); printf("%s", #s); first_flag = 0; }
130 #define PRINT_FLAG(f) PRINT_FLAG2(f, f)
132 PRINT_FLAG(forwardable
);
133 PRINT_FLAG(forwarded
);
134 PRINT_FLAG(proxiable
);
136 PRINT_FLAG2(may_postdate
, may
-postdate
);
137 PRINT_FLAG(postdated
);
139 PRINT_FLAG(renewable
);
141 PRINT_FLAG2(pre_authent
, pre
-authenticated
);
142 PRINT_FLAG2(hw_authent
, hw
-authenticated
);
143 PRINT_FLAG2(transited_policy_checked
, transited
-policy
-checked
);
144 PRINT_FLAG2(ok_as_delegate
, ok
-as
-delegate
);
145 PRINT_FLAG(anonymous
);
147 printf("Addresses: ");
148 for(j
= 0; j
< cred
->addresses
.len
; j
++){
150 switch(cred
->addresses
.val
[j
].addr_type
){
151 case KRB5_ADDRESS_INET
:
152 printf("IPv4: %s", inet_ntoa(*(struct in_addr
*)cred
->addresses
.val
[j
].address
.data
));
154 #if defined(AF_INET6) && defined(HAVE_INET_NTOP) && defined(INET6_ADDRSTRLEN)
155 case KRB5_ADDRESS_INET6
: {
156 char foo
[INET6_ADDRSTRLEN
];
158 printf("IPv6: %s", inet_ntop(AF_INET6
,
159 cred
->addresses
.val
[j
].address
.data
,
167 krb5_address
*a
= &cred
->addresses
.val
[j
];
168 s
= malloc(a
->address
.length
* 2 + 1);
169 for(i
= 0; i
< a
->address
.length
; i
++)
170 sprintf(s
+ 2*i
, "%02x", ((char*)a
->address
.data
)[i
]);
171 printf("%d/%s", cred
->addresses
.val
[j
].addr_type
, s
);
179 static int version_flag
= 0;
180 static int help_flag
= 0;
181 static int do_verbose
= 0;
183 static struct getargs args
[] = {
184 { "verbose", 'v', arg_flag
, &do_verbose
,
185 "Verbose output", NULL
},
186 { "version", 0, arg_flag
, &version_flag
,
187 "print version", NULL
},
188 { "help", 0, arg_flag
, &help_flag
,
195 arg_printusage (args
,
196 sizeof(args
)/sizeof(*args
),
202 main (int argc
, char **argv
)
205 krb5_context context
;
207 krb5_principal principal
;
208 krb5_cc_cursor cursor
;
213 set_progname (argv
[0]);
215 if(getarg(args
, sizeof(args
) / sizeof(args
[0]), argc
, argv
, &optind
))
222 printf("%s (%s-%s)\n", __progname
, PACKAGE
, VERSION
);
232 ret
= krb5_init_context (&context
);
234 krb5_err(context
, 1, ret
, "krb5_init_context");
236 ret
= krb5_cc_default (context
, &ccache
);
238 krb5_err (context
, 1, ret
, "krb5_cc_default");
240 ret
= krb5_cc_get_principal (context
, ccache
, &principal
);
242 krb5_errx(context
, 1, "No ticket file: %s",
243 krb5_cc_get_name(context
, ccache
));
245 krb5_err (context
, 1, ret
, "krb5_cc_get_principal");
247 ret
= krb5_unparse_name (context
, principal
, &str
);
249 krb5_err (context
, 1, ret
, "krb5_unparse_name");
251 printf ("Credentials cache: %s\n", krb5_cc_get_name(context
, ccache
));
252 printf ("\tPrincipal: %s\n\n", str
);
255 if (do_verbose
&& context
->kdc_sec_offset
) {
260 val
= context
->kdc_sec_offset
;
267 unparse_time (val
, buf
, sizeof(buf
));
269 printf ("\tKDC time offset: %s%s\n",
270 sig
== -1 ? "-" : "", buf
);
273 ret
= krb5_cc_start_seq_get (context
, ccache
, &cursor
);
275 krb5_err(context
, 1, ret
, "krb5_cc_start_seq_get");
278 printf(" %-15s %-15s %s\n", "Issued", "Expires", "Principal");
280 while (krb5_cc_next_cred (context
,
285 print_cred_verbose(context
, &creds
);
287 print_cred(context
, &creds
);
289 krb5_free_creds_contents (context
, &creds
);
291 ret
= krb5_cc_end_seq_get (context
, ccache
, &cursor
);
293 krb5_err (context
, 1, ret
, "krb5_cc_end_seq_get");
295 ret
= krb5_cc_close (context
, ccache
);
297 krb5_err (context
, 1, ret
, "krb5_cc_close");
299 krb5_free_principal (context
, principal
);
300 krb5_free_context (context
);