2 * Copyright (c) 1995 - 2005 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. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include "ftpd_locl.h"
39 print_cred(krb5_context context
, krb5_creds
*cred
)
41 char t1
[128], t2
[128], *str
;
45 krb5_timeofday (context
, &sec
);
47 if(cred
->times
.starttime
)
48 krb5_format_time(context
, cred
->times
.starttime
, t1
, sizeof(t1
), 1);
50 krb5_format_time(context
, cred
->times
.authtime
, t1
, sizeof(t1
), 1);
52 if(cred
->times
.endtime
> sec
)
53 krb5_format_time(context
, cred
->times
.endtime
, t2
, sizeof(t2
), 1);
55 strlcpy(t2
, ">>>Expired<<<", sizeof(t2
));
57 ret
= krb5_unparse_name (context
, cred
->server
, &str
);
59 lreply(500, "krb5_unparse_name: %d", ret
);
63 lreply(200, "%-20s %-20s %s", t1
, t2
, str
);
69 print_tickets (krb5_context context
,
71 krb5_principal principal
)
74 krb5_cc_cursor cursor
;
78 ret
= krb5_unparse_name (context
, principal
, &str
);
80 lreply(500, "krb5_unparse_name: %d", ret
);
84 lreply(200, "%17s: %s:%s",
86 krb5_cc_get_type(context
, ccache
),
87 krb5_cc_get_name(context
, ccache
));
88 lreply(200, "%17s: %s", "Principal", str
);
91 ret
= krb5_cc_start_seq_get (context
, ccache
, &cursor
);
93 lreply(500, "krb5_cc_start_seq_get: %d", ret
);
97 lreply(200, " Issued Expires Principal");
99 while ((ret
= krb5_cc_next_cred (context
,
103 if (print_cred(context
, &cred
))
105 krb5_free_cred_contents (context
, &cred
);
107 if (ret
!= KRB5_CC_END
) {
108 lreply(500, "krb5_cc_get_next: %d", ret
);
111 ret
= krb5_cc_end_seq_get (context
, ccache
, &cursor
);
113 lreply(500, "krb5_cc_end_seq_get: %d", ret
);
124 krb5_context context
;
126 krb5_principal principal
;
127 int exit_status
= 200;
129 ret
= krb5_init_context (&context
);
131 lreply(500, "krb5_init_context failed: %d", ret
);
136 ret
= krb5_cc_resolve(context
, k5ccname
, &ccache
);
138 ret
= krb5_cc_default (context
, &ccache
);
140 lreply(500, "krb5_cc_default: %d", ret
);
144 ret
= krb5_cc_get_principal (context
, ccache
, &principal
);
147 lreply(500, "No ticket file: %s",
148 krb5_cc_get_name(context
, ccache
));
150 lreply(500, "krb5_cc_get_principal: %d", ret
);
154 exit_status
= print_tickets (context
, ccache
, principal
);
156 ret
= krb5_cc_close (context
, ccache
);
158 lreply(500, "krb5_cc_close: %d", ret
);
162 krb5_free_principal (context
, principal
);
163 krb5_free_context (context
);
175 reply(500, "Command not implemented.");