2000-01-09 20:58:00 +00:00
|
|
|
/*
|
2011-10-05 07:23:29 +00:00
|
|
|
* Copyright (c) 1997-2008 Kungliga Tekniska Högskolan
|
|
|
|
* (Royal Institute of Technology, Stockholm, Sweden).
|
|
|
|
* All rights reserved.
|
2000-01-09 20:58:00 +00:00
|
|
|
*
|
2011-10-05 07:23:29 +00:00
|
|
|
* Portions Copyright (c) 2009 Apple Inc. All rights reserved.
|
2000-01-09 20:58:00 +00:00
|
|
|
*
|
2011-10-05 07:23:29 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
2000-01-09 20:58:00 +00:00
|
|
|
*
|
2011-10-05 07:23:29 +00:00
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
2000-01-09 20:58:00 +00:00
|
|
|
*
|
2011-10-05 07:23:29 +00:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2000-01-09 20:58:00 +00:00
|
|
|
*
|
2011-10-05 07:23:29 +00:00
|
|
|
* 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
2000-01-09 20:58:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kuser_locl.h"
|
2001-02-13 16:46:19 +00:00
|
|
|
#include "rtbl.h"
|
2011-10-05 07:23:29 +00:00
|
|
|
#include "parse_units.h"
|
|
|
|
#include "kcc-commands.h"
|
2000-01-09 20:58:00 +00:00
|
|
|
|
|
|
|
static char*
|
2011-10-05 07:23:29 +00:00
|
|
|
printable_time_internal(time_t t, int x)
|
2000-01-09 20:58:00 +00:00
|
|
|
{
|
|
|
|
static char s[128];
|
2011-10-05 07:23:29 +00:00
|
|
|
char *p;
|
|
|
|
|
|
|
|
if ((p = ctime(&t)) == NULL)
|
|
|
|
strlcpy(s, "?", sizeof(s));
|
|
|
|
else
|
|
|
|
strlcpy(s, p + 4, sizeof(s));
|
|
|
|
s[x] = 0;
|
2000-01-09 20:58:00 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2011-10-05 07:23:29 +00:00
|
|
|
static char*
|
|
|
|
printable_time(time_t t)
|
|
|
|
{
|
|
|
|
return printable_time_internal(t, 20);
|
|
|
|
}
|
|
|
|
|
2000-01-09 20:58:00 +00:00
|
|
|
static char*
|
|
|
|
printable_time_long(time_t t)
|
|
|
|
{
|
2011-10-05 07:23:29 +00:00
|
|
|
return printable_time_internal(t, 20);
|
2000-01-09 20:58:00 +00:00
|
|
|
}
|
|
|
|
|
2011-10-05 07:23:29 +00:00
|
|
|
#define COL_ISSUED NP_(" Issued","")
|
|
|
|
#define COL_EXPIRES NP_(" Expires", "")
|
|
|
|
#define COL_FLAGS NP_("Flags", "")
|
|
|
|
#define COL_NAME NP_(" Name", "")
|
|
|
|
#define COL_PRINCIPAL NP_(" Principal", "in klist output")
|
|
|
|
#define COL_PRINCIPAL_KVNO NP_(" Principal (kvno)", "in klist output")
|
|
|
|
#define COL_CACHENAME NP_(" Cache name", "name in klist output")
|
|
|
|
#define COL_DEFCACHE NP_("", "")
|
2001-02-13 16:46:19 +00:00
|
|
|
|
2000-01-09 20:58:00 +00:00
|
|
|
static void
|
2001-02-13 16:46:19 +00:00
|
|
|
print_cred(krb5_context context, krb5_creds *cred, rtbl_t ct, int do_flags)
|
2000-01-09 20:58:00 +00:00
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
krb5_error_code ret;
|
2000-02-24 11:07:16 +00:00
|
|
|
krb5_timestamp sec;
|
2000-01-09 20:58:00 +00:00
|
|
|
|
|
|
|
krb5_timeofday (context, &sec);
|
|
|
|
|
2001-02-13 16:46:19 +00:00
|
|
|
|
2000-01-09 20:58:00 +00:00
|
|
|
if(cred->times.starttime)
|
2001-02-13 16:46:19 +00:00
|
|
|
rtbl_add_column_entry(ct, COL_ISSUED,
|
|
|
|
printable_time(cred->times.starttime));
|
2000-01-09 20:58:00 +00:00
|
|
|
else
|
2001-02-13 16:46:19 +00:00
|
|
|
rtbl_add_column_entry(ct, COL_ISSUED,
|
|
|
|
printable_time(cred->times.authtime));
|
2011-10-05 07:23:29 +00:00
|
|
|
|
2000-01-09 20:58:00 +00:00
|
|
|
if(cred->times.endtime > sec)
|
2001-02-13 16:46:19 +00:00
|
|
|
rtbl_add_column_entry(ct, COL_EXPIRES,
|
|
|
|
printable_time(cred->times.endtime));
|
2000-01-09 20:58:00 +00:00
|
|
|
else
|
2011-10-05 07:23:29 +00:00
|
|
|
rtbl_add_column_entry(ct, COL_EXPIRES, N_(">>>Expired<<<", ""));
|
2000-01-09 20:58:00 +00:00
|
|
|
ret = krb5_unparse_name (context, cred->server, &str);
|
|
|
|
if (ret)
|
|
|
|
krb5_err(context, 1, ret, "krb5_unparse_name");
|
2001-02-13 16:46:19 +00:00
|
|
|
rtbl_add_column_entry(ct, COL_PRINCIPAL, str);
|
|
|
|
if(do_flags) {
|
|
|
|
char s[16], *sp = s;
|
|
|
|
if(cred->flags.b.forwardable)
|
|
|
|
*sp++ = 'F';
|
|
|
|
if(cred->flags.b.forwarded)
|
|
|
|
*sp++ = 'f';
|
|
|
|
if(cred->flags.b.proxiable)
|
|
|
|
*sp++ = 'P';
|
|
|
|
if(cred->flags.b.proxy)
|
|
|
|
*sp++ = 'p';
|
|
|
|
if(cred->flags.b.may_postdate)
|
|
|
|
*sp++ = 'D';
|
|
|
|
if(cred->flags.b.postdated)
|
|
|
|
*sp++ = 'd';
|
|
|
|
if(cred->flags.b.renewable)
|
|
|
|
*sp++ = 'R';
|
|
|
|
if(cred->flags.b.initial)
|
|
|
|
*sp++ = 'I';
|
|
|
|
if(cred->flags.b.invalid)
|
|
|
|
*sp++ = 'i';
|
|
|
|
if(cred->flags.b.pre_authent)
|
|
|
|
*sp++ = 'A';
|
|
|
|
if(cred->flags.b.hw_authent)
|
|
|
|
*sp++ = 'H';
|
2011-10-05 07:23:29 +00:00
|
|
|
*sp = '\0';
|
2001-02-13 16:46:19 +00:00
|
|
|
rtbl_add_column_entry(ct, COL_FLAGS, s);
|
|
|
|
}
|
|
|
|
free(str);
|
2000-01-09 20:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_cred_verbose(krb5_context context, krb5_creds *cred)
|
|
|
|
{
|
2011-10-05 07:23:29 +00:00
|
|
|
size_t j;
|
2000-01-09 20:58:00 +00:00
|
|
|
char *str;
|
|
|
|
krb5_error_code ret;
|
2000-02-24 11:07:16 +00:00
|
|
|
krb5_timestamp sec;
|
2000-01-09 20:58:00 +00:00
|
|
|
|
|
|
|
krb5_timeofday (context, &sec);
|
|
|
|
|
|
|
|
ret = krb5_unparse_name(context, cred->server, &str);
|
|
|
|
if(ret)
|
|
|
|
exit(1);
|
2011-10-05 07:23:29 +00:00
|
|
|
printf(N_("Server: %s\n", ""), str);
|
2000-01-09 20:58:00 +00:00
|
|
|
free (str);
|
2008-05-07 13:39:42 +00:00
|
|
|
|
|
|
|
ret = krb5_unparse_name(context, cred->client, &str);
|
|
|
|
if(ret)
|
|
|
|
exit(1);
|
2011-10-05 07:23:29 +00:00
|
|
|
printf(N_("Client: %s\n", ""), str);
|
2008-05-07 13:39:42 +00:00
|
|
|
free (str);
|
|
|
|
|
2000-01-09 20:58:00 +00:00
|
|
|
{
|
|
|
|
Ticket t;
|
|
|
|
size_t len;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
decode_Ticket(cred->ticket.data, cred->ticket.length, &t, &len);
|
|
|
|
ret = krb5_enctype_to_string(context, t.enc_part.etype, &s);
|
2011-10-05 07:23:29 +00:00
|
|
|
printf(N_("Ticket etype: ", ""));
|
2000-01-09 20:58:00 +00:00
|
|
|
if (ret == 0) {
|
2001-02-13 16:46:19 +00:00
|
|
|
printf("%s", s);
|
2000-01-09 20:58:00 +00:00
|
|
|
free(s);
|
|
|
|
} else {
|
2011-10-05 07:23:29 +00:00
|
|
|
printf(N_("unknown-enctype(%d)", ""), t.enc_part.etype);
|
2000-01-09 20:58:00 +00:00
|
|
|
}
|
|
|
|
if(t.enc_part.kvno)
|
2011-10-05 07:23:29 +00:00
|
|
|
printf(N_(", kvno %d", ""), *t.enc_part.kvno);
|
2000-01-09 20:58:00 +00:00
|
|
|
printf("\n");
|
|
|
|
if(cred->session.keytype != t.enc_part.etype) {
|
2008-05-07 13:39:42 +00:00
|
|
|
ret = krb5_enctype_to_string(context, cred->session.keytype, &str);
|
2000-01-09 20:58:00 +00:00
|
|
|
if(ret)
|
|
|
|
krb5_warn(context, ret, "session keytype");
|
|
|
|
else {
|
2011-10-05 07:23:29 +00:00
|
|
|
printf(N_("Session key: %s\n", "enctype"), str);
|
2000-01-09 20:58:00 +00:00
|
|
|
free(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free_Ticket(&t);
|
2011-10-05 07:23:29 +00:00
|
|
|
printf(N_("Ticket length: %lu\n", ""),
|
|
|
|
(unsigned long)cred->ticket.length);
|
2000-01-09 20:58:00 +00:00
|
|
|
}
|
2011-10-05 07:23:29 +00:00
|
|
|
printf(N_("Auth time: %s\n", ""),
|
|
|
|
printable_time_long(cred->times.authtime));
|
2000-01-09 20:58:00 +00:00
|
|
|
if(cred->times.authtime != cred->times.starttime)
|
2011-10-05 07:23:29 +00:00
|
|
|
printf(N_("Start time: %s\n", ""),
|
|
|
|
printable_time_long(cred->times.starttime));
|
|
|
|
printf(N_("End time: %s", ""),
|
|
|
|
printable_time_long(cred->times.endtime));
|
2000-01-09 20:58:00 +00:00
|
|
|
if(sec > cred->times.endtime)
|
2011-10-05 07:23:29 +00:00
|
|
|
printf(N_(" (expired)", ""));
|
2000-01-09 20:58:00 +00:00
|
|
|
printf("\n");
|
|
|
|
if(cred->flags.b.renewable)
|
2011-10-05 07:23:29 +00:00
|
|
|
printf(N_("Renew till: %s\n", ""),
|
2000-01-09 20:58:00 +00:00
|
|
|
printable_time_long(cred->times.renew_till));
|
2011-10-05 07:23:29 +00:00
|
|
|
{
|
|
|
|
char flags[1024];
|
|
|
|
unparse_flags(TicketFlags2int(cred->flags.b),
|
|
|
|
asn1_TicketFlags_units(),
|
|
|
|
flags, sizeof(flags));
|
|
|
|
printf(N_("Ticket flags: %s\n", ""), flags);
|
|
|
|
}
|
|
|
|
printf(N_("Addresses: ", ""));
|
2008-05-07 13:39:42 +00:00
|
|
|
if (cred->addresses.len != 0) {
|
|
|
|
for(j = 0; j < cred->addresses.len; j++){
|
|
|
|
char buf[128];
|
|
|
|
size_t len;
|
|
|
|
if(j) printf(", ");
|
2011-10-05 07:23:29 +00:00
|
|
|
ret = krb5_print_address(&cred->addresses.val[j],
|
2008-05-07 13:39:42 +00:00
|
|
|
buf, sizeof(buf), &len);
|
2011-10-05 07:23:29 +00:00
|
|
|
|
2008-05-07 13:39:42 +00:00
|
|
|
if(ret == 0)
|
|
|
|
printf("%s", buf);
|
|
|
|
}
|
|
|
|
} else {
|
2011-10-05 07:23:29 +00:00
|
|
|
printf(N_("addressless", ""));
|
2000-01-09 20:58:00 +00:00
|
|
|
}
|
|
|
|
printf("\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print all tickets in `ccache' on stdout, verbosily iff do_verbose.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_tickets (krb5_context context,
|
|
|
|
krb5_ccache ccache,
|
|
|
|
krb5_principal principal,
|
2001-02-13 16:46:19 +00:00
|
|
|
int do_verbose,
|
2008-05-07 13:39:42 +00:00
|
|
|
int do_flags,
|
|
|
|
int do_hidden)
|
2000-01-09 20:58:00 +00:00
|
|
|
{
|
|
|
|
krb5_error_code ret;
|
2011-10-05 07:23:29 +00:00
|
|
|
char *str, *name;
|
2000-01-09 20:58:00 +00:00
|
|
|
krb5_cc_cursor cursor;
|
|
|
|
krb5_creds creds;
|
2011-10-05 07:23:29 +00:00
|
|
|
krb5_deltat sec;
|
2000-01-09 20:58:00 +00:00
|
|
|
|
2001-02-13 16:46:19 +00:00
|
|
|
rtbl_t ct = NULL;
|
|
|
|
|
2000-01-09 20:58:00 +00:00
|
|
|
ret = krb5_unparse_name (context, principal, &str);
|
|
|
|
if (ret)
|
|
|
|
krb5_err (context, 1, ret, "krb5_unparse_name");
|
|
|
|
|
2011-10-05 07:23:29 +00:00
|
|
|
printf ("%17s: %s:%s\n",
|
|
|
|
N_("Credentials cache", ""),
|
2000-01-09 20:58:00 +00:00
|
|
|
krb5_cc_get_type(context, ccache),
|
|
|
|
krb5_cc_get_name(context, ccache));
|
2011-10-05 07:23:29 +00:00
|
|
|
printf ("%17s: %s\n", N_("Principal", ""), str);
|
|
|
|
|
|
|
|
ret = krb5_cc_get_friendly_name(context, ccache, &name);
|
|
|
|
if (ret == 0) {
|
|
|
|
if (strcmp(name, str) != 0)
|
|
|
|
printf ("%17s: %s\n", N_("Friendly name", ""), name);
|
|
|
|
free(name);
|
|
|
|
}
|
2000-01-09 20:58:00 +00:00
|
|
|
free (str);
|
2011-10-05 07:23:29 +00:00
|
|
|
|
|
|
|
if(do_verbose) {
|
|
|
|
printf ("%17s: %d\n", N_("Cache version", ""),
|
2000-01-09 20:58:00 +00:00
|
|
|
krb5_cc_get_version(context, ccache));
|
2011-10-05 07:23:29 +00:00
|
|
|
} else {
|
|
|
|
krb5_cc_set_flags(context, ccache, KRB5_TC_NOTICKET);
|
|
|
|
}
|
2008-05-07 13:39:42 +00:00
|
|
|
|
2011-10-05 07:23:29 +00:00
|
|
|
ret = krb5_cc_get_kdc_offset(context, ccache, &sec);
|
|
|
|
|
|
|
|
if (ret == 0 && do_verbose && sec != 0) {
|
2000-01-09 20:58:00 +00:00
|
|
|
char buf[BUFSIZ];
|
|
|
|
int val;
|
|
|
|
int sig;
|
|
|
|
|
2008-05-07 13:39:42 +00:00
|
|
|
val = sec;
|
2000-01-09 20:58:00 +00:00
|
|
|
sig = 1;
|
|
|
|
if (val < 0) {
|
|
|
|
sig = -1;
|
|
|
|
val = -val;
|
|
|
|
}
|
2011-10-05 07:23:29 +00:00
|
|
|
|
2000-01-09 20:58:00 +00:00
|
|
|
unparse_time (val, buf, sizeof(buf));
|
|
|
|
|
2011-10-05 07:23:29 +00:00
|
|
|
printf ("%17s: %s%s\n", N_("KDC time offset", ""),
|
2000-01-09 20:58:00 +00:00
|
|
|
sig == -1 ? "-" : "", buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
ret = krb5_cc_start_seq_get (context, ccache, &cursor);
|
|
|
|
if (ret)
|
|
|
|
krb5_err(context, 1, ret, "krb5_cc_start_seq_get");
|
|
|
|
|
2001-02-13 16:46:19 +00:00
|
|
|
if(!do_verbose) {
|
|
|
|
ct = rtbl_create();
|
|
|
|
rtbl_add_column(ct, COL_ISSUED, 0);
|
|
|
|
rtbl_add_column(ct, COL_EXPIRES, 0);
|
|
|
|
if(do_flags)
|
|
|
|
rtbl_add_column(ct, COL_FLAGS, 0);
|
|
|
|
rtbl_add_column(ct, COL_PRINCIPAL, 0);
|
2008-05-07 13:39:42 +00:00
|
|
|
rtbl_set_separator(ct, " ");
|
2001-02-13 16:46:19 +00:00
|
|
|
}
|
2004-04-03 21:22:55 +00:00
|
|
|
while ((ret = krb5_cc_next_cred (context,
|
|
|
|
ccache,
|
|
|
|
&cursor,
|
|
|
|
&creds)) == 0) {
|
2011-10-05 07:23:29 +00:00
|
|
|
if (!do_hidden && krb5_is_config_principal(context, creds.server)) {
|
2008-05-07 13:39:42 +00:00
|
|
|
;
|
|
|
|
}else if(do_verbose){
|
2000-01-09 20:58:00 +00:00
|
|
|
print_cred_verbose(context, &creds);
|
|
|
|
}else{
|
2001-02-13 16:46:19 +00:00
|
|
|
print_cred(context, &creds, ct, do_flags);
|
2000-01-09 20:58:00 +00:00
|
|
|
}
|
2008-05-07 13:39:42 +00:00
|
|
|
krb5_free_cred_contents (context, &creds);
|
2000-01-09 20:58:00 +00:00
|
|
|
}
|
2004-04-03 21:22:55 +00:00
|
|
|
if(ret != KRB5_CC_END)
|
|
|
|
krb5_err(context, 1, ret, "krb5_cc_get_next");
|
2000-01-09 20:58:00 +00:00
|
|
|
ret = krb5_cc_end_seq_get (context, ccache, &cursor);
|
|
|
|
if (ret)
|
|
|
|
krb5_err (context, 1, ret, "krb5_cc_end_seq_get");
|
2001-02-13 16:46:19 +00:00
|
|
|
if(!do_verbose) {
|
|
|
|
rtbl_format(ct, stdout);
|
|
|
|
rtbl_destroy(ct);
|
|
|
|
}
|
2000-01-09 20:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if there's a tgt for the realm of `principal' and ccache and
|
|
|
|
* if so return 0, else 1
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
check_for_tgt (krb5_context context,
|
|
|
|
krb5_ccache ccache,
|
2008-05-07 13:39:42 +00:00
|
|
|
krb5_principal principal,
|
|
|
|
time_t *expiration)
|
2000-01-09 20:58:00 +00:00
|
|
|
{
|
|
|
|
krb5_error_code ret;
|
|
|
|
krb5_creds pattern;
|
|
|
|
krb5_creds creds;
|
2011-10-05 07:23:29 +00:00
|
|
|
krb5_const_realm client_realm;
|
2000-01-09 20:58:00 +00:00
|
|
|
int expired;
|
|
|
|
|
2008-05-07 13:39:42 +00:00
|
|
|
krb5_cc_clear_mcred(&pattern);
|
|
|
|
|
2011-10-05 07:23:29 +00:00
|
|
|
client_realm = krb5_principal_get_realm(context, principal);
|
2000-01-09 20:58:00 +00:00
|
|
|
|
|
|
|
ret = krb5_make_principal (context, &pattern.server,
|
2011-10-05 07:23:29 +00:00
|
|
|
client_realm, KRB5_TGS_NAME, client_realm, NULL);
|
2000-01-09 20:58:00 +00:00
|
|
|
if (ret)
|
|
|
|
krb5_err (context, 1, ret, "krb5_make_principal");
|
2008-05-07 13:39:42 +00:00
|
|
|
pattern.client = principal;
|
2000-01-09 20:58:00 +00:00
|
|
|
|
|
|
|
ret = krb5_cc_retrieve_cred (context, ccache, 0, &pattern, &creds);
|
|
|
|
krb5_free_principal (context, pattern.server);
|
|
|
|
if (ret) {
|
|
|
|
if (ret == KRB5_CC_END)
|
|
|
|
return 1;
|
|
|
|
krb5_err (context, 1, ret, "krb5_cc_retrieve_cred");
|
|
|
|
}
|
2001-02-13 16:46:19 +00:00
|
|
|
|
2008-05-07 13:39:42 +00:00
|
|
|
expired = time(NULL) > creds.times.endtime;
|
2001-02-13 16:46:19 +00:00
|
|
|
|
2008-05-07 13:39:42 +00:00
|
|
|
if (expiration)
|
|
|
|
*expiration = creds.times.endtime;
|
2001-02-13 16:46:19 +00:00
|
|
|
|
2008-05-07 13:39:42 +00:00
|
|
|
krb5_free_cred_contents (context, &creds);
|
2001-02-13 16:46:19 +00:00
|
|
|
|
2008-05-07 13:39:42 +00:00
|
|
|
return expired;
|
2001-02-13 16:46:19 +00:00
|
|
|
}
|
|
|
|
|
2000-01-09 20:58:00 +00:00
|
|
|
/*
|
|
|
|
* Print a list of all AFS tokens
|
|
|
|
*/
|
|
|
|
|
2011-10-05 07:23:29 +00:00
|
|
|
#ifndef NO_AFS
|
|
|
|
|
2000-01-09 20:58:00 +00:00
|
|
|
static void
|
|
|
|
display_tokens(int do_verbose)
|
|
|
|
{
|
2008-05-07 13:39:42 +00:00
|
|
|
uint32_t i;
|
2002-08-30 21:23:27 +00:00
|
|
|
unsigned char t[4096];
|
2000-01-09 20:58:00 +00:00
|
|
|
struct ViceIoctl parms;
|
|
|
|
|
|
|
|
parms.in = (void *)&i;
|
|
|
|
parms.in_size = sizeof(i);
|
|
|
|
parms.out = (void *)t;
|
|
|
|
parms.out_size = sizeof(t);
|
|
|
|
|
2002-08-30 21:23:27 +00:00
|
|
|
for (i = 0;; i++) {
|
2000-01-09 20:58:00 +00:00
|
|
|
int32_t size_secret_tok, size_public_tok;
|
|
|
|
unsigned char *cell;
|
|
|
|
struct ClearToken ct;
|
|
|
|
unsigned char *r = t;
|
|
|
|
struct timeval tv;
|
|
|
|
char buf1[20], buf2[20];
|
|
|
|
|
2002-08-30 21:23:27 +00:00
|
|
|
if(k_pioctl(NULL, VIOCGETTOK, &parms, 0) < 0) {
|
|
|
|
if(errno == EDOM)
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
2002-11-24 20:59:25 +00:00
|
|
|
if(parms.out_size > sizeof(t))
|
2002-08-30 21:23:27 +00:00
|
|
|
continue;
|
|
|
|
if(parms.out_size < sizeof(size_secret_tok))
|
|
|
|
continue;
|
2003-10-09 19:36:20 +00:00
|
|
|
t[min(parms.out_size,sizeof(t)-1)] = 0;
|
2000-01-09 20:58:00 +00:00
|
|
|
memcpy(&size_secret_tok, r, sizeof(size_secret_tok));
|
|
|
|
/* dont bother about the secret token */
|
|
|
|
r += size_secret_tok + sizeof(size_secret_tok);
|
2002-08-30 21:23:27 +00:00
|
|
|
if (parms.out_size < (r - t) + sizeof(size_public_tok))
|
|
|
|
continue;
|
2000-01-09 20:58:00 +00:00
|
|
|
memcpy(&size_public_tok, r, sizeof(size_public_tok));
|
|
|
|
r += sizeof(size_public_tok);
|
2002-08-30 21:23:27 +00:00
|
|
|
if (parms.out_size < (r - t) + size_public_tok + sizeof(int32_t))
|
|
|
|
continue;
|
2000-01-09 20:58:00 +00:00
|
|
|
memcpy(&ct, r, size_public_tok);
|
|
|
|
r += size_public_tok;
|
|
|
|
/* there is a int32_t with length of cellname, but we dont read it */
|
|
|
|
r += sizeof(int32_t);
|
|
|
|
cell = r;
|
|
|
|
|
|
|
|
gettimeofday (&tv, NULL);
|
|
|
|
strlcpy (buf1, printable_time(ct.BeginTimestamp),
|
2002-08-30 21:23:27 +00:00
|
|
|
sizeof(buf1));
|
2000-01-09 20:58:00 +00:00
|
|
|
if (do_verbose || tv.tv_sec < ct.EndTimestamp)
|
|
|
|
strlcpy (buf2, printable_time(ct.EndTimestamp),
|
2002-08-30 21:23:27 +00:00
|
|
|
sizeof(buf2));
|
2000-01-09 20:58:00 +00:00
|
|
|
else
|
2011-10-05 07:23:29 +00:00
|
|
|
strlcpy (buf2, N_(">>> Expired <<<", ""), sizeof(buf2));
|
2000-01-09 20:58:00 +00:00
|
|
|
|
|
|
|
printf("%s %s ", buf1, buf2);
|
|
|
|
|
|
|
|
if ((ct.EndTimestamp - ct.BeginTimestamp) & 1)
|
2011-10-05 07:23:29 +00:00
|
|
|
printf(N_("User's (AFS ID %d) tokens for %s", ""), ct.ViceId, cell);
|
2000-01-09 20:58:00 +00:00
|
|
|
else
|
2011-10-05 07:23:29 +00:00
|
|
|
printf(N_("Tokens for %s", ""), cell);
|
2000-01-09 20:58:00 +00:00
|
|
|
if (do_verbose)
|
|
|
|
printf(" (%d)", ct.AuthHandle);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
}
|
2011-10-05 07:23:29 +00:00
|
|
|
#endif
|
2001-02-13 16:46:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* display the ccache in `cred_cache'
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
2011-10-05 07:23:29 +00:00
|
|
|
display_v5_ccache (krb5_context context, krb5_ccache ccache,
|
|
|
|
int do_test, int do_verbose,
|
2008-05-07 13:39:42 +00:00
|
|
|
int do_flags, int do_hidden)
|
2001-02-13 16:46:19 +00:00
|
|
|
{
|
|
|
|
krb5_error_code ret;
|
|
|
|
krb5_principal principal;
|
|
|
|
int exit_status = 0;
|
|
|
|
|
|
|
|
|
|
|
|
ret = krb5_cc_get_principal (context, ccache, &principal);
|
|
|
|
if (ret) {
|
|
|
|
if(ret == ENOENT) {
|
|
|
|
if (!do_test)
|
2011-10-05 07:23:29 +00:00
|
|
|
krb5_warnx(context, N_("No ticket file: %s", ""),
|
2001-02-13 16:46:19 +00:00
|
|
|
krb5_cc_get_name(context, ccache));
|
|
|
|
return 1;
|
|
|
|
} else
|
|
|
|
krb5_err (context, 1, ret, "krb5_cc_get_principal");
|
|
|
|
}
|
|
|
|
if (do_test)
|
2008-05-07 13:39:42 +00:00
|
|
|
exit_status = check_for_tgt (context, ccache, principal, NULL);
|
2001-02-13 16:46:19 +00:00
|
|
|
else
|
2008-05-07 13:39:42 +00:00
|
|
|
print_tickets (context, ccache, principal, do_verbose,
|
|
|
|
do_flags, do_hidden);
|
2001-02-13 16:46:19 +00:00
|
|
|
|
|
|
|
ret = krb5_cc_close (context, ccache);
|
|
|
|
if (ret)
|
|
|
|
krb5_err (context, 1, ret, "krb5_cc_close");
|
|
|
|
|
|
|
|
krb5_free_principal (context, principal);
|
2011-10-05 07:23:29 +00:00
|
|
|
|
2001-02-13 16:46:19 +00:00
|
|
|
return exit_status;
|
|
|
|
}
|
2000-01-09 20:58:00 +00:00
|
|
|
|
2008-05-07 13:39:42 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
2011-10-05 07:23:29 +00:00
|
|
|
list_caches(krb5_context context)
|
2008-05-07 13:39:42 +00:00
|
|
|
{
|
|
|
|
krb5_cc_cache_cursor cursor;
|
2011-10-05 07:23:29 +00:00
|
|
|
const char *cdef_name;
|
|
|
|
char *def_name;
|
2008-05-07 13:39:42 +00:00
|
|
|
krb5_error_code ret;
|
|
|
|
krb5_ccache id;
|
|
|
|
rtbl_t ct;
|
2011-10-05 07:23:29 +00:00
|
|
|
|
|
|
|
cdef_name = krb5_cc_default_name(context);
|
|
|
|
if (cdef_name == NULL)
|
|
|
|
krb5_errx(context, 1, "krb5_cc_default_name");
|
|
|
|
def_name = strdup(cdef_name);
|
2008-05-07 13:39:42 +00:00
|
|
|
|
|
|
|
ret = krb5_cc_cache_get_first (context, NULL, &cursor);
|
|
|
|
if (ret == KRB5_CC_NOSUPP)
|
|
|
|
return 0;
|
|
|
|
else if (ret)
|
|
|
|
krb5_err (context, 1, ret, "krb5_cc_cache_get_first");
|
|
|
|
|
|
|
|
ct = rtbl_create();
|
2011-10-05 07:23:29 +00:00
|
|
|
rtbl_add_column(ct, COL_NAME, 0);
|
2008-05-07 13:39:42 +00:00
|
|
|
rtbl_add_column(ct, COL_CACHENAME, 0);
|
|
|
|
rtbl_add_column(ct, COL_EXPIRES, 0);
|
2011-10-05 07:23:29 +00:00
|
|
|
rtbl_add_column(ct, COL_DEFCACHE, 0);
|
2008-05-07 13:39:42 +00:00
|
|
|
rtbl_set_prefix(ct, " ");
|
2011-10-05 07:23:29 +00:00
|
|
|
rtbl_set_column_prefix(ct, COL_NAME, "");
|
2008-05-07 13:39:42 +00:00
|
|
|
|
2011-10-05 07:23:29 +00:00
|
|
|
while (krb5_cc_cache_next (context, cursor, &id) == 0) {
|
|
|
|
krb5_principal principal = NULL;
|
|
|
|
int expired = 0;
|
2008-05-07 13:39:42 +00:00
|
|
|
char *name;
|
2011-10-05 07:23:29 +00:00
|
|
|
time_t t;
|
2008-05-07 13:39:42 +00:00
|
|
|
|
|
|
|
ret = krb5_cc_get_principal(context, id, &principal);
|
2011-10-05 07:23:29 +00:00
|
|
|
if (ret)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
expired = check_for_tgt (context, id, principal, &t);
|
|
|
|
|
|
|
|
ret = krb5_cc_get_friendly_name(context, id, &name);
|
2008-05-07 13:39:42 +00:00
|
|
|
if (ret == 0) {
|
2011-10-05 07:23:29 +00:00
|
|
|
const char *str;
|
|
|
|
char *fname;
|
|
|
|
rtbl_add_column_entry(ct, COL_NAME, name);
|
|
|
|
rtbl_add_column_entry(ct, COL_CACHENAME,
|
|
|
|
krb5_cc_get_name(context, id));
|
|
|
|
if (expired)
|
|
|
|
str = N_(">>> Expired <<<", "");
|
|
|
|
else
|
|
|
|
str = printable_time(t);
|
|
|
|
rtbl_add_column_entry(ct, COL_EXPIRES, str);
|
|
|
|
free(name);
|
|
|
|
|
|
|
|
ret = krb5_cc_get_full_name(context, id, &fname);
|
|
|
|
if (ret)
|
|
|
|
krb5_err (context, 1, ret, "krb5_cc_get_full_name");
|
|
|
|
|
|
|
|
if (strcmp(fname, def_name) == 0)
|
|
|
|
rtbl_add_column_entry(ct, COL_DEFCACHE, "*");
|
|
|
|
else
|
|
|
|
rtbl_add_column_entry(ct, COL_DEFCACHE, "");
|
|
|
|
|
|
|
|
krb5_xfree(fname);
|
2008-05-07 13:39:42 +00:00
|
|
|
}
|
|
|
|
krb5_cc_close(context, id);
|
2011-10-05 07:23:29 +00:00
|
|
|
|
|
|
|
krb5_free_principal(context, principal);
|
2008-05-07 13:39:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
krb5_cc_cache_end_seq_get(context, cursor);
|
|
|
|
|
2011-10-05 07:23:29 +00:00
|
|
|
free(def_name);
|
2008-05-07 13:39:42 +00:00
|
|
|
rtbl_format(ct, stdout);
|
|
|
|
rtbl_destroy(ct);
|
2011-10-05 07:23:29 +00:00
|
|
|
|
2008-05-07 13:39:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2000-01-09 20:58:00 +00:00
|
|
|
int
|
2011-10-05 07:23:29 +00:00
|
|
|
klist(struct klist_options *opt, int argc, char **argv)
|
2000-01-09 20:58:00 +00:00
|
|
|
{
|
2011-10-05 07:23:29 +00:00
|
|
|
krb5_error_code ret;
|
2000-01-09 20:58:00 +00:00
|
|
|
int exit_status = 0;
|
|
|
|
|
2011-10-05 07:23:29 +00:00
|
|
|
int do_verbose =
|
|
|
|
opt->verbose_flag ||
|
|
|
|
opt->a_flag ||
|
|
|
|
opt->n_flag;
|
|
|
|
int do_test =
|
|
|
|
opt->test_flag ||
|
|
|
|
opt->s_flag;
|
2000-01-09 20:58:00 +00:00
|
|
|
|
2011-10-05 07:23:29 +00:00
|
|
|
if (opt->list_all_flag) {
|
|
|
|
exit_status = list_caches(kcc_context);
|
|
|
|
return exit_status;
|
2000-01-09 20:58:00 +00:00
|
|
|
}
|
|
|
|
|
2011-10-05 07:23:29 +00:00
|
|
|
if (opt->v5_flag) {
|
|
|
|
krb5_ccache id;
|
2000-01-09 20:58:00 +00:00
|
|
|
|
2011-10-05 07:23:29 +00:00
|
|
|
if (opt->all_content_flag) {
|
|
|
|
krb5_cc_cache_cursor cursor;
|
2000-01-09 20:58:00 +00:00
|
|
|
|
2011-10-05 07:23:29 +00:00
|
|
|
ret = krb5_cc_cache_get_first(kcc_context, NULL, &cursor);
|
|
|
|
if (ret)
|
|
|
|
krb5_err(kcc_context, 1, ret, "krb5_cc_cache_get_first");
|
2008-05-07 13:39:42 +00:00
|
|
|
|
2011-10-05 07:23:29 +00:00
|
|
|
|
|
|
|
while (krb5_cc_cache_next(kcc_context, cursor, &id) == 0) {
|
|
|
|
exit_status |= display_v5_ccache(kcc_context, id, do_test,
|
|
|
|
do_verbose, opt->flags_flag,
|
|
|
|
opt->hidden_flag);
|
|
|
|
printf("\n\n");
|
|
|
|
}
|
|
|
|
krb5_cc_cache_end_seq_get(kcc_context, cursor);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if(opt->cache_string) {
|
|
|
|
ret = krb5_cc_resolve(kcc_context, opt->cache_string, &id);
|
|
|
|
if (ret)
|
|
|
|
krb5_err(kcc_context, 1, ret, "%s", opt->cache_string);
|
|
|
|
} else {
|
|
|
|
ret = krb5_cc_default(kcc_context, &id);
|
|
|
|
if (ret)
|
|
|
|
krb5_err(kcc_context, 1, ret, "krb5_cc_resolve");
|
|
|
|
}
|
|
|
|
exit_status = display_v5_ccache(kcc_context, id, do_test,
|
|
|
|
do_verbose, opt->flags_flag,
|
|
|
|
opt->hidden_flag);
|
|
|
|
}
|
|
|
|
}
|
2000-01-09 20:58:00 +00:00
|
|
|
|
2001-02-13 16:46:19 +00:00
|
|
|
if (!do_test) {
|
2011-10-05 07:23:29 +00:00
|
|
|
#ifndef NO_AFS
|
|
|
|
if (opt->tokens_flag && k_hasafs()) {
|
|
|
|
if (opt->v5_flag)
|
|
|
|
printf("\n");
|
|
|
|
display_tokens(opt->verbose_flag);
|
2001-02-13 16:46:19 +00:00
|
|
|
}
|
2011-10-05 07:23:29 +00:00
|
|
|
#endif
|
2001-02-13 16:46:19 +00:00
|
|
|
}
|
2000-01-09 20:58:00 +00:00
|
|
|
|
|
|
|
return exit_status;
|
|
|
|
}
|