1*7f2fe78bSCy Schubert #include "stdafx.h"
2*7f2fe78bSCy Schubert #include "lglobals.h"
3*7f2fe78bSCy Schubert #include "krb5.h"
4*7f2fe78bSCy Schubert
5*7f2fe78bSCy Schubert static void
FreeTicketList(TicketList ** ticketList)6*7f2fe78bSCy Schubert FreeTicketList(TicketList** ticketList)
7*7f2fe78bSCy Schubert {
8*7f2fe78bSCy Schubert TicketList* tempList = *ticketList, *killList;
9*7f2fe78bSCy Schubert
10*7f2fe78bSCy Schubert while (tempList) {
11*7f2fe78bSCy Schubert killList = tempList;
12*7f2fe78bSCy Schubert tempList = tempList->next;
13*7f2fe78bSCy Schubert free(killList->service);
14*7f2fe78bSCy Schubert if (killList->encTypes)
15*7f2fe78bSCy Schubert free(killList->encTypes);
16*7f2fe78bSCy Schubert free(killList);
17*7f2fe78bSCy Schubert }
18*7f2fe78bSCy Schubert
19*7f2fe78bSCy Schubert *ticketList = NULL;
20*7f2fe78bSCy Schubert }
21*7f2fe78bSCy Schubert
22*7f2fe78bSCy Schubert void
LeashKRB5FreeTicketInfo(TICKETINFO * ticketinfo)23*7f2fe78bSCy Schubert LeashKRB5FreeTicketInfo(TICKETINFO *ticketinfo)
24*7f2fe78bSCy Schubert {
25*7f2fe78bSCy Schubert if (ticketinfo->principal) {
26*7f2fe78bSCy Schubert free(ticketinfo->principal);
27*7f2fe78bSCy Schubert ticketinfo->principal = NULL;
28*7f2fe78bSCy Schubert }
29*7f2fe78bSCy Schubert if (ticketinfo->ccache_name) {
30*7f2fe78bSCy Schubert pkrb5_free_string(NULL, ticketinfo->ccache_name);
31*7f2fe78bSCy Schubert ticketinfo->ccache_name = NULL;
32*7f2fe78bSCy Schubert }
33*7f2fe78bSCy Schubert if (ticketinfo->ticket_list)
34*7f2fe78bSCy Schubert FreeTicketList(&ticketinfo->ticket_list);
35*7f2fe78bSCy Schubert }
36*7f2fe78bSCy Schubert
37*7f2fe78bSCy Schubert void
LeashKRB5FreeTickets(TICKETINFO ** ticketinfolist)38*7f2fe78bSCy Schubert LeashKRB5FreeTickets(TICKETINFO **ticketinfolist)
39*7f2fe78bSCy Schubert {
40*7f2fe78bSCy Schubert TICKETINFO *ticketinfo = *ticketinfolist, *next;
41*7f2fe78bSCy Schubert while (ticketinfo) {
42*7f2fe78bSCy Schubert next = ticketinfo->next;
43*7f2fe78bSCy Schubert LeashKRB5FreeTicketInfo(ticketinfo);
44*7f2fe78bSCy Schubert free(ticketinfo);
45*7f2fe78bSCy Schubert ticketinfo = next;
46*7f2fe78bSCy Schubert }
47*7f2fe78bSCy Schubert *ticketinfolist = NULL;
48*7f2fe78bSCy Schubert }
49*7f2fe78bSCy Schubert
50*7f2fe78bSCy Schubert /*
51*7f2fe78bSCy Schubert * LeashKRB5Error()
52*7f2fe78bSCy Schubert */
53*7f2fe78bSCy Schubert int
LeashKRB5Error(krb5_error_code rc,LPCSTR FailedFunctionName)54*7f2fe78bSCy Schubert LeashKRB5Error(krb5_error_code rc, LPCSTR FailedFunctionName)
55*7f2fe78bSCy Schubert {
56*7f2fe78bSCy Schubert #ifdef USE_MESSAGE_BOX
57*7f2fe78bSCy Schubert char message[256];
58*7f2fe78bSCy Schubert const char *errText;
59*7f2fe78bSCy Schubert
60*7f2fe78bSCy Schubert errText = perror_message(rc);
61*7f2fe78bSCy Schubert _snprintf(message, sizeof(message),
62*7f2fe78bSCy Schubert "%s\n(Kerberos error %ld)\n\n%s failed",
63*7f2fe78bSCy Schubert errText,
64*7f2fe78bSCy Schubert rc,
65*7f2fe78bSCy Schubert FailedFunctionName);
66*7f2fe78bSCy Schubert message[sizeof(message)-1] = 0;
67*7f2fe78bSCy Schubert
68*7f2fe78bSCy Schubert MessageBox(NULL, message, "Kerberos Five", MB_OK | MB_ICONERROR |
69*7f2fe78bSCy Schubert MB_TASKMODAL |
70*7f2fe78bSCy Schubert MB_SETFOREGROUND);
71*7f2fe78bSCy Schubert #endif /* USE_MESSAGE_BOX */
72*7f2fe78bSCy Schubert return rc;
73*7f2fe78bSCy Schubert }
74*7f2fe78bSCy Schubert
75*7f2fe78bSCy Schubert
76*7f2fe78bSCy Schubert static void
etype_string(krb5_enctype enctype,char * buf,size_t buflen)77*7f2fe78bSCy Schubert etype_string(krb5_enctype enctype, char *buf, size_t buflen)
78*7f2fe78bSCy Schubert {
79*7f2fe78bSCy Schubert krb5_error_code retval;
80*7f2fe78bSCy Schubert
81*7f2fe78bSCy Schubert if ((retval = pkrb5_enctype_to_name(enctype, FALSE, buf, buflen))) {
82*7f2fe78bSCy Schubert /* XXX if there's an error != EINVAL, I should probably report it */
83*7f2fe78bSCy Schubert sprintf_s(buf, buflen, "etype %d", enctype);
84*7f2fe78bSCy Schubert }
85*7f2fe78bSCy Schubert }
86*7f2fe78bSCy Schubert
87*7f2fe78bSCy Schubert
88*7f2fe78bSCy Schubert static void
CredToTicketInfo(krb5_creds KRBv5Credentials,TICKETINFO * ticketinfo)89*7f2fe78bSCy Schubert CredToTicketInfo(krb5_creds KRBv5Credentials, TICKETINFO *ticketinfo)
90*7f2fe78bSCy Schubert {
91*7f2fe78bSCy Schubert ticketinfo->issued = (DWORD)KRBv5Credentials.times.starttime;
92*7f2fe78bSCy Schubert ticketinfo->valid_until = (DWORD)KRBv5Credentials.times.endtime;
93*7f2fe78bSCy Schubert ticketinfo->renew_until = KRBv5Credentials.ticket_flags & TKT_FLG_RENEWABLE ?
94*7f2fe78bSCy Schubert (DWORD)KRBv5Credentials.times.renew_till : (DWORD)0;
95*7f2fe78bSCy Schubert _tzset();
96*7f2fe78bSCy Schubert if ( ticketinfo->valid_until - time(0) <= 0L )
97*7f2fe78bSCy Schubert ticketinfo->btickets = EXPD_TICKETS;
98*7f2fe78bSCy Schubert else
99*7f2fe78bSCy Schubert ticketinfo->btickets = GOOD_TICKETS;
100*7f2fe78bSCy Schubert }
101*7f2fe78bSCy Schubert
102*7f2fe78bSCy Schubert static int
CredToTicketList(krb5_context ctx,krb5_creds KRBv5Credentials,char * PrincipalName,TicketList *** ticketListTail)103*7f2fe78bSCy Schubert CredToTicketList(krb5_context ctx, krb5_creds KRBv5Credentials,
104*7f2fe78bSCy Schubert char *PrincipalName, TicketList ***ticketListTail)
105*7f2fe78bSCy Schubert {
106*7f2fe78bSCy Schubert krb5_error_code code = 0;
107*7f2fe78bSCy Schubert krb5_ticket *tkt=NULL;
108*7f2fe78bSCy Schubert char *sServerName = NULL;
109*7f2fe78bSCy Schubert char Buffer[256], sestype[100], tkttype[100];
110*7f2fe78bSCy Schubert char *functionName = NULL;
111*7f2fe78bSCy Schubert TicketList *list = NULL;
112*7f2fe78bSCy Schubert
113*7f2fe78bSCy Schubert functionName = "krb5_unparse_name()";
114*7f2fe78bSCy Schubert code = (*pkrb5_unparse_name)(ctx, KRBv5Credentials.server, &sServerName);
115*7f2fe78bSCy Schubert if (code)
116*7f2fe78bSCy Schubert goto cleanup;
117*7f2fe78bSCy Schubert
118*7f2fe78bSCy Schubert if (!KRBv5Credentials.times.starttime)
119*7f2fe78bSCy Schubert KRBv5Credentials.times.starttime = KRBv5Credentials.times.authtime;
120*7f2fe78bSCy Schubert
121*7f2fe78bSCy Schubert memset(Buffer, '\0', sizeof(Buffer));
122*7f2fe78bSCy Schubert
123*7f2fe78bSCy Schubert // @fixme: calloc for ptr init
124*7f2fe78bSCy Schubert list = (TicketList *)calloc(1, sizeof(TicketList));
125*7f2fe78bSCy Schubert if (!list) {
126*7f2fe78bSCy Schubert code = ENOMEM;
127*7f2fe78bSCy Schubert functionName = "calloc()";
128*7f2fe78bSCy Schubert goto cleanup;
129*7f2fe78bSCy Schubert }
130*7f2fe78bSCy Schubert list->service = strdup(sServerName);
131*7f2fe78bSCy Schubert if (!list->service) {
132*7f2fe78bSCy Schubert code = ENOMEM;
133*7f2fe78bSCy Schubert functionName = "calloc()";
134*7f2fe78bSCy Schubert goto cleanup;
135*7f2fe78bSCy Schubert }
136*7f2fe78bSCy Schubert list->issued = (DWORD)KRBv5Credentials.times.starttime;
137*7f2fe78bSCy Schubert list->valid_until = (DWORD)KRBv5Credentials.times.endtime;
138*7f2fe78bSCy Schubert if (KRBv5Credentials.ticket_flags & TKT_FLG_RENEWABLE)
139*7f2fe78bSCy Schubert list->renew_until = (DWORD)KRBv5Credentials.times.renew_till;
140*7f2fe78bSCy Schubert else
141*7f2fe78bSCy Schubert list->renew_until = 0;
142*7f2fe78bSCy Schubert
143*7f2fe78bSCy Schubert etype_string(KRBv5Credentials.keyblock.enctype, sestype, sizeof(sestype));
144*7f2fe78bSCy Schubert if (!pkrb5_decode_ticket(&KRBv5Credentials.ticket, &tkt)) {
145*7f2fe78bSCy Schubert etype_string(tkt->enc_part.enctype, tkttype, sizeof(tkttype));
146*7f2fe78bSCy Schubert wsprintf(Buffer, "Session Key: %s Ticket: %s", sestype, tkttype);
147*7f2fe78bSCy Schubert pkrb5_free_ticket(ctx, tkt);
148*7f2fe78bSCy Schubert tkt = NULL;
149*7f2fe78bSCy Schubert } else {
150*7f2fe78bSCy Schubert wsprintf(Buffer, "Session Key: %s", sestype);
151*7f2fe78bSCy Schubert }
152*7f2fe78bSCy Schubert
153*7f2fe78bSCy Schubert list->encTypes = (char *)calloc(1, strlen(Buffer)+1);
154*7f2fe78bSCy Schubert if (!list->encTypes) {
155*7f2fe78bSCy Schubert functionName = "calloc()";
156*7f2fe78bSCy Schubert code = ENOMEM;
157*7f2fe78bSCy Schubert goto cleanup;
158*7f2fe78bSCy Schubert }
159*7f2fe78bSCy Schubert strcpy(list->encTypes, Buffer);
160*7f2fe78bSCy Schubert
161*7f2fe78bSCy Schubert list->flags = KRBv5Credentials.ticket_flags;
162*7f2fe78bSCy Schubert cleanup:
163*7f2fe78bSCy Schubert if (code) {
164*7f2fe78bSCy Schubert LeashKRB5Error(code, functionName);
165*7f2fe78bSCy Schubert if (list)
166*7f2fe78bSCy Schubert FreeTicketList(&list);
167*7f2fe78bSCy Schubert } else {
168*7f2fe78bSCy Schubert **ticketListTail = list;
169*7f2fe78bSCy Schubert *ticketListTail = &list->next;
170*7f2fe78bSCy Schubert }
171*7f2fe78bSCy Schubert
172*7f2fe78bSCy Schubert if (sServerName != NULL)
173*7f2fe78bSCy Schubert (*pkrb5_free_unparsed_name)(ctx, sServerName);
174*7f2fe78bSCy Schubert
175*7f2fe78bSCy Schubert return code;
176*7f2fe78bSCy Schubert }
177*7f2fe78bSCy Schubert
178*7f2fe78bSCy Schubert // return 0 if ticketinfo was successfully appended to list, 1 otherwise
179*7f2fe78bSCy Schubert int
do_ccache(krb5_context ctx,krb5_ccache cache,TICKETINFO ** ticketInfoTail)180*7f2fe78bSCy Schubert do_ccache(krb5_context ctx,
181*7f2fe78bSCy Schubert krb5_ccache cache,
182*7f2fe78bSCy Schubert TICKETINFO **ticketInfoTail)
183*7f2fe78bSCy Schubert {
184*7f2fe78bSCy Schubert krb5_cc_cursor cur;
185*7f2fe78bSCy Schubert krb5_creds creds;
186*7f2fe78bSCy Schubert krb5_principal princ = NULL;
187*7f2fe78bSCy Schubert krb5_flags flags;
188*7f2fe78bSCy Schubert krb5_error_code code;
189*7f2fe78bSCy Schubert char *defname = NULL;
190*7f2fe78bSCy Schubert char *functionName = NULL;
191*7f2fe78bSCy Schubert TicketList **ticketListTail;
192*7f2fe78bSCy Schubert TICKETINFO *ticketinfo = NULL;
193*7f2fe78bSCy Schubert int retval = 1;
194*7f2fe78bSCy Schubert
195*7f2fe78bSCy Schubert // Don't need the actual ticket.
196*7f2fe78bSCy Schubert flags = KRB5_TC_NOTICKET;
197*7f2fe78bSCy Schubert code = pkrb5_cc_set_flags(ctx, cache, flags);
198*7f2fe78bSCy Schubert if (code) {
199*7f2fe78bSCy Schubert if (code == KRB5_FCC_NOFILE || code == KRB5_CC_NOTFOUND) {
200*7f2fe78bSCy Schubert // Normal behavior; skip cache but suppress error message box
201*7f2fe78bSCy Schubert code = 0;
202*7f2fe78bSCy Schubert } else {
203*7f2fe78bSCy Schubert functionName = "krb5_cc_set_flags";
204*7f2fe78bSCy Schubert }
205*7f2fe78bSCy Schubert goto cleanup;
206*7f2fe78bSCy Schubert }
207*7f2fe78bSCy Schubert code = pkrb5_cc_get_principal(ctx, cache, &princ);
208*7f2fe78bSCy Schubert if (code) {
209*7f2fe78bSCy Schubert // Normal behavior; skip cache but suppress error message box
210*7f2fe78bSCy Schubert code = 0;
211*7f2fe78bSCy Schubert goto cleanup;
212*7f2fe78bSCy Schubert }
213*7f2fe78bSCy Schubert code = pkrb5_unparse_name(ctx, princ, &defname);
214*7f2fe78bSCy Schubert if (code) {
215*7f2fe78bSCy Schubert functionName = "krb5_unparse_name";
216*7f2fe78bSCy Schubert goto cleanup;
217*7f2fe78bSCy Schubert }
218*7f2fe78bSCy Schubert code = pkrb5_cc_start_seq_get(ctx, cache, &cur);
219*7f2fe78bSCy Schubert if (code) {
220*7f2fe78bSCy Schubert // MSLSA errors here if no TGT is found; suppress error message box
221*7f2fe78bSCy Schubert code = 0;
222*7f2fe78bSCy Schubert goto cleanup;
223*7f2fe78bSCy Schubert }
224*7f2fe78bSCy Schubert if (*ticketInfoTail)
225*7f2fe78bSCy Schubert ticketinfo = *ticketInfoTail;
226*7f2fe78bSCy Schubert else
227*7f2fe78bSCy Schubert // @fixme: calloc to init pointers
228*7f2fe78bSCy Schubert ticketinfo = (TICKETINFO *)calloc(1, sizeof(TICKETINFO));
229*7f2fe78bSCy Schubert
230*7f2fe78bSCy Schubert if (ticketinfo == NULL) {
231*7f2fe78bSCy Schubert functionName = "calloc";
232*7f2fe78bSCy Schubert code = ENOMEM;
233*7f2fe78bSCy Schubert goto cleanup;
234*7f2fe78bSCy Schubert }
235*7f2fe78bSCy Schubert ticketinfo->next = NULL;
236*7f2fe78bSCy Schubert ticketinfo->ticket_list = NULL;
237*7f2fe78bSCy Schubert ticketinfo->principal = strdup(defname);
238*7f2fe78bSCy Schubert if (ticketinfo->principal == NULL) {
239*7f2fe78bSCy Schubert functionName = "strdup";
240*7f2fe78bSCy Schubert code = ENOMEM;
241*7f2fe78bSCy Schubert goto cleanup;
242*7f2fe78bSCy Schubert }
243*7f2fe78bSCy Schubert code = pkrb5_cc_get_full_name(ctx, cache, &ticketinfo->ccache_name);
244*7f2fe78bSCy Schubert if (code) {
245*7f2fe78bSCy Schubert functionName = "krb5_cc_get_full_name";
246*7f2fe78bSCy Schubert goto cleanup;
247*7f2fe78bSCy Schubert }
248*7f2fe78bSCy Schubert *ticketInfoTail = ticketinfo;
249*7f2fe78bSCy Schubert ticketListTail = &ticketinfo->ticket_list;
250*7f2fe78bSCy Schubert while (!(code = pkrb5_cc_next_cred(ctx, cache, &cur, &creds))) {
251*7f2fe78bSCy Schubert if (!pkrb5_is_config_principal(ctx, creds.server)) {
252*7f2fe78bSCy Schubert CredToTicketList(ctx, creds, defname, &ticketListTail);
253*7f2fe78bSCy Schubert CredToTicketInfo(creds, ticketinfo);
254*7f2fe78bSCy Schubert }
255*7f2fe78bSCy Schubert pkrb5_free_cred_contents(ctx, &creds);
256*7f2fe78bSCy Schubert }
257*7f2fe78bSCy Schubert if (code == KRB5_CC_END) {
258*7f2fe78bSCy Schubert code = pkrb5_cc_end_seq_get(ctx, cache, &cur);
259*7f2fe78bSCy Schubert if (code) {
260*7f2fe78bSCy Schubert functionName = "krb5_cc_end_seq_get";
261*7f2fe78bSCy Schubert goto cleanup;
262*7f2fe78bSCy Schubert }
263*7f2fe78bSCy Schubert flags = 0;
264*7f2fe78bSCy Schubert code = pkrb5_cc_set_flags(ctx, cache, flags);
265*7f2fe78bSCy Schubert if (code) {
266*7f2fe78bSCy Schubert functionName = "krb5_cc_set_flags";
267*7f2fe78bSCy Schubert goto cleanup;
268*7f2fe78bSCy Schubert }
269*7f2fe78bSCy Schubert } else {
270*7f2fe78bSCy Schubert functionName = "krb5_cc_next_cred";
271*7f2fe78bSCy Schubert goto cleanup;
272*7f2fe78bSCy Schubert }
273*7f2fe78bSCy Schubert cleanup:
274*7f2fe78bSCy Schubert if (code)
275*7f2fe78bSCy Schubert LeashKRB5Error(code, functionName);
276*7f2fe78bSCy Schubert if (ticketinfo) {
277*7f2fe78bSCy Schubert if (ticketinfo == *ticketInfoTail)
278*7f2fe78bSCy Schubert retval = 0;
279*7f2fe78bSCy Schubert else
280*7f2fe78bSCy Schubert LeashKRB5FreeTickets(&ticketinfo);
281*7f2fe78bSCy Schubert }
282*7f2fe78bSCy Schubert if (defname)
283*7f2fe78bSCy Schubert pkrb5_free_unparsed_name(ctx, defname);
284*7f2fe78bSCy Schubert if (princ)
285*7f2fe78bSCy Schubert pkrb5_free_principal(ctx, princ);
286*7f2fe78bSCy Schubert return retval;
287*7f2fe78bSCy Schubert }
288*7f2fe78bSCy Schubert
289*7f2fe78bSCy Schubert
290*7f2fe78bSCy Schubert //
291*7f2fe78bSCy Schubert // Returns 0 for success, 1 for failure
292*7f2fe78bSCy Schubert //
293*7f2fe78bSCy Schubert int
do_all_ccaches(krb5_context ctx,TICKETINFO ** ticketinfotail)294*7f2fe78bSCy Schubert do_all_ccaches(krb5_context ctx, TICKETINFO **ticketinfotail)
295*7f2fe78bSCy Schubert {
296*7f2fe78bSCy Schubert krb5_error_code code;
297*7f2fe78bSCy Schubert krb5_ccache cache;
298*7f2fe78bSCy Schubert krb5_cccol_cursor cursor;
299*7f2fe78bSCy Schubert int retval = 1;
300*7f2fe78bSCy Schubert char *functionName = NULL;
301*7f2fe78bSCy Schubert
302*7f2fe78bSCy Schubert code = pkrb5_cccol_cursor_new(ctx, &cursor);
303*7f2fe78bSCy Schubert if (code) {
304*7f2fe78bSCy Schubert functionName = "krb5_cccol_cursor_new";
305*7f2fe78bSCy Schubert goto cleanup;
306*7f2fe78bSCy Schubert }
307*7f2fe78bSCy Schubert retval = 0;
308*7f2fe78bSCy Schubert while (!(code = pkrb5_cccol_cursor_next(ctx, cursor, &cache)) &&
309*7f2fe78bSCy Schubert cache != NULL) {
310*7f2fe78bSCy Schubert // Note that ticketinfotail will be updated here to point to the tail
311*7f2fe78bSCy Schubert // of the list but the caller of this function will remain with a
312*7f2fe78bSCy Schubert // pointer to the head.
313*7f2fe78bSCy Schubert if (do_ccache(ctx, cache, ticketinfotail) == 0)
314*7f2fe78bSCy Schubert ticketinfotail = &((*ticketinfotail)->next);
315*7f2fe78bSCy Schubert pkrb5_cc_close(ctx, cache);
316*7f2fe78bSCy Schubert }
317*7f2fe78bSCy Schubert if (code)
318*7f2fe78bSCy Schubert functionName = "krb5_cccol_cursor_next";
319*7f2fe78bSCy Schubert pkrb5_cccol_cursor_free(ctx, &cursor);
320*7f2fe78bSCy Schubert cleanup:
321*7f2fe78bSCy Schubert if (code)
322*7f2fe78bSCy Schubert LeashKRB5Error(code, functionName);
323*7f2fe78bSCy Schubert return retval;
324*7f2fe78bSCy Schubert }
325*7f2fe78bSCy Schubert
326*7f2fe78bSCy Schubert void
LeashKRB5ListDefaultTickets(TICKETINFO * ticketinfo)327*7f2fe78bSCy Schubert LeashKRB5ListDefaultTickets(TICKETINFO *ticketinfo)
328*7f2fe78bSCy Schubert {
329*7f2fe78bSCy Schubert krb5_error_code code;
330*7f2fe78bSCy Schubert krb5_context ctx = 0;
331*7f2fe78bSCy Schubert krb5_ccache cache = 0;
332*7f2fe78bSCy Schubert char *functionName = NULL;
333*7f2fe78bSCy Schubert
334*7f2fe78bSCy Schubert ticketinfo->btickets = NO_TICKETS;
335*7f2fe78bSCy Schubert ticketinfo->principal = NULL;
336*7f2fe78bSCy Schubert ticketinfo->ccache_name = NULL;
337*7f2fe78bSCy Schubert ticketinfo->next = NULL;
338*7f2fe78bSCy Schubert ticketinfo->ticket_list = NULL;
339*7f2fe78bSCy Schubert ticketinfo->renew_until = 0;
340*7f2fe78bSCy Schubert ticketinfo->valid_until = 0;
341*7f2fe78bSCy Schubert ticketinfo->issued = 0;
342*7f2fe78bSCy Schubert
343*7f2fe78bSCy Schubert code = pkrb5_init_context(&ctx);
344*7f2fe78bSCy Schubert if (code) {
345*7f2fe78bSCy Schubert functionName = "krb5_init_context";
346*7f2fe78bSCy Schubert goto cleanup;
347*7f2fe78bSCy Schubert }
348*7f2fe78bSCy Schubert
349*7f2fe78bSCy Schubert code = pkrb5_cc_default(ctx, &cache);
350*7f2fe78bSCy Schubert if (code) {
351*7f2fe78bSCy Schubert functionName = "krb5_cc_default";
352*7f2fe78bSCy Schubert goto cleanup;
353*7f2fe78bSCy Schubert }
354*7f2fe78bSCy Schubert if (cache != NULL)
355*7f2fe78bSCy Schubert do_ccache(ctx, cache, &ticketinfo);
356*7f2fe78bSCy Schubert cleanup:
357*7f2fe78bSCy Schubert if (code)
358*7f2fe78bSCy Schubert LeashKRB5Error(code, functionName);
359*7f2fe78bSCy Schubert if (cache)
360*7f2fe78bSCy Schubert pkrb5_cc_close(ctx, cache);
361*7f2fe78bSCy Schubert if (ctx)
362*7f2fe78bSCy Schubert pkrb5_free_context(ctx);
363*7f2fe78bSCy Schubert }
364*7f2fe78bSCy Schubert
365*7f2fe78bSCy Schubert
366*7f2fe78bSCy Schubert /*
367*7f2fe78bSCy Schubert * LeashKRB5ListAllTickets()
368*7f2fe78bSCy Schubert */
369*7f2fe78bSCy Schubert
370*7f2fe78bSCy Schubert void
LeashKRB5ListAllTickets(TICKETINFO ** ticketinfo)371*7f2fe78bSCy Schubert LeashKRB5ListAllTickets(TICKETINFO **ticketinfo)
372*7f2fe78bSCy Schubert {
373*7f2fe78bSCy Schubert krb5_error_code code;
374*7f2fe78bSCy Schubert krb5_context ctx = 0;
375*7f2fe78bSCy Schubert char *functionName = NULL;
376*7f2fe78bSCy Schubert
377*7f2fe78bSCy Schubert code = pkrb5_init_context(&ctx);
378*7f2fe78bSCy Schubert if (code) {
379*7f2fe78bSCy Schubert functionName = "krb5_init_context";
380*7f2fe78bSCy Schubert goto cleanup;
381*7f2fe78bSCy Schubert }
382*7f2fe78bSCy Schubert
383*7f2fe78bSCy Schubert do_all_ccaches(ctx, ticketinfo);
384*7f2fe78bSCy Schubert cleanup:
385*7f2fe78bSCy Schubert if (code)
386*7f2fe78bSCy Schubert LeashKRB5Error(code, functionName);
387*7f2fe78bSCy Schubert if (ctx)
388*7f2fe78bSCy Schubert pkrb5_free_context(ctx);
389*7f2fe78bSCy Schubert }
390