4 * Handle all actions of the Kerberos ticket list.
6 * Copyright 1994 by the Massachusetts Institute of Technology.
8 * For copying and distribution information, please see the file
12 #if !defined(KRB5) && !defined(KRB4)
24 #include "mit-copyright.h"
34 #define DEFAULT_TKT_LIFE 120
39 #define MAX_KPW_LEN 128
40 /* include space for '.' and '@' */
41 #define MAX_K_NAME_SZ (ANAME_SZ + INST_SZ + REALM_SZ + 2)
42 #define ORGANIZATION "Cygnus Support"
49 * Ticket information for a list line
52 BOOL ticket; /* TRUE if this is a real ticket */
53 time_t issue_time; /* time_t of issue */
54 long lifetime; /* Lifetime for ticket in 5 minute intervals */
55 char buf[0]; /* String to display */
56 } TICKETINFO, *LPTICKETINFO;
59 * Function: Returns a standard ctime date with day of week and year
63 * t - time_t date to convert
65 * Returns: A pointer to the adjusted time value.
69 static char buf[26 - 4];
84 * Function: Initializes and populates the ticket list with all existing
88 * hwnd - the window handle of the ticket window.
90 * Returns: Number of elements in the list or -1 on error
100 char buf[26+2 + 26+2 + ANAME_SZ+1 + INST_SZ+1 + REALM_SZ + 22];
104 char service[ANAME_SZ];
105 char instance[INST_SZ];
106 char realm[REALM_SZ];
110 krb5_cc_cursor cursor;
111 krb5_error_code code;
114 char *sname; /* Name of the service */
115 char *flags_string(krb5_creds *cred);
118 SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
120 rc = SendMessage(hwnd, LB_GETCOUNT, 0, 0);
121 assert(rc != LB_ERR);
124 ticket_destroy(hwnd);
127 SendMessage(hwnd, LB_DELETESTRING, (WPARAM) rc, 0);
131 ncred = krb_get_num_cred();
132 for (i = 1; i <= ncred; i++) {
133 krb_get_nth_cred(service, instance, realm, i);
134 krb_get_cred(service, instance, realm, &c);
136 strcat(buf, short_date(c.issue_date - kwin_get_epoch()));
137 expiration = c.issue_date - kwin_get_epoch() + (long) c.lifetime * 5L * 60L;
139 strcat(buf, short_date(expiration));
141 sprintf(&buf[l], " %s%s%s%s%s (%d)",
142 c.service, (c.instance[0] ? "." : ""), c.instance,
143 (c.realm[0] ? "@" : ""), c.realm, c.kvno);
146 lpinfo = (LPTICKETINFO) malloc(sizeof(TICKETINFO) + l + 1);
147 assert(lpinfo != NULL);
152 lpinfo->ticket = TRUE;
153 lpinfo->issue_time = c.issue_date - kwin_get_epoch(); /* back to system time */
154 lpinfo->lifetime = (long) c.lifetime * 5L * 60L;
155 strcpy(lpinfo->buf, buf);
157 rc = SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM) lpinfo);
170 if (code = krb5_cc_set_flags(k5_context, k5_ccache, flags)) {
171 if (code != KRB5_FCC_NOFILE) {
172 //com_err (NULL, code,
173 // "while setting cache flags (ticket cache %s)",
174 // krb5_cc_get_name(k5_context, k5_ccache));
178 if (code = krb5_cc_start_seq_get(k5_context, k5_ccache, &cursor)) {
179 //com_err (NULL, code, "while starting to retrieve tickets");
184 code = krb5_cc_next_cred(k5_context, k5_ccache, &cursor, &c);
190 strcat (buf, short_date (c.times.starttime - kwin_get_epoch()));
192 strcat (buf, short_date (c.times.endtime - kwin_get_epoch()));
195 /* Add ticket service name and realm */
196 code = krb5_unparse_name (k5_context, c.server, &sname);
198 com_err (NULL, code, "while unparsing server name");
203 strcat (buf, flags_string (&c)); /* Add flag info */
206 lpinfo = (LPTICKETINFO) malloc(sizeof(TICKETINFO) + l + 1);
207 assert(lpinfo != NULL);
212 lpinfo->ticket = TRUE;
213 lpinfo->issue_time = c.times.starttime - kwin_get_epoch();
214 lpinfo->lifetime = c.times.endtime - c.times.starttime;
215 strcpy(lpinfo->buf, buf);
217 rc = SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM) lpinfo);
224 if (code == KRB5_CC_END) { /* End of ccache */
225 if (code = krb5_cc_end_seq_get(k5_context, k5_ccache, &cursor)) {
226 //com_err(NULL, code, "while finishing ticket retrieval");
229 flags = KRB5_TC_OPENCLOSE; /* turns on OPENCLOSE mode */
230 if (code = krb5_cc_set_flags(k5_context, k5_ccache, flags)) {
231 //com_err(NULL, code, "while closing ccache");
235 //com_err(NULL, code, "while retrieving a ticket");
242 strcpy(buf, " No Tickets");
243 lpinfo = (LPTICKETINFO) malloc(sizeof(TICKETINFO) + strlen(buf) + 1);
244 assert(lpinfo != NULL);
249 lpinfo->ticket = FALSE;
250 strcpy (lpinfo->buf, buf);
251 rc = SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM) lpinfo);
255 SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
259 } /* ticket_init_list */
263 * Function: Destroy the ticket list. Make sure to delete all
264 * ticket entries created during ticket initialization.
267 * hwnd - the window handle of the ticket window.
277 n = (int) SendMessage(hwnd, LB_GETCOUNT, 0, 0);
279 for (i = 0; i < n; i++) {
280 rc = SendMessage(hwnd, LB_GETITEMDATA, i, 0);
281 assert(rc != LB_ERR);
287 } /* ticket_destroy */
291 * Function: Respond to the WM_MEASUREITEM message for the ticket list
292 * by setting each list item up at 1/4" hight.
295 * hwnd - the window handle of the ticket window.
297 * wparam - control id of the ticket list.
299 * lparam - pointer to the MEASUREITEMSTRUCT.
301 * Returns: TRUE if message process, FALSE otherwise.
310 LPMEASUREITEMSTRUCT lpmi;
313 lpmi = (LPMEASUREITEMSTRUCT) lparam;
314 hdc = GetDC(HWND_DESKTOP);
315 logpixelsy = GetDeviceCaps(hdc, LOGPIXELSY);
316 ReleaseDC(HWND_DESKTOP, hdc);
317 lpmi->itemHeight = logpixelsy / 4; /* 1/4 inch */
321 } /* ticket_measureitem */
325 * Function: Respond to the WM_DRAWITEM message for the ticket list
326 * by displaying a single list item.
329 * hwnd - the window handle of the ticket window.
331 * wparam - control id of the ticket list.
333 * lparam - pointer to the DRAWITEMSTRUCT.
335 * Returns: TRUE if message process, FALSE otherwise.
337 LONG ticket_drawitem(
342 LPDRAWITEMSTRUCT lpdi;
355 COLORREF orgtextcolor;
358 lpdi = (LPDRAWITEMSTRUCT) lparam;
359 lpinfo = (LPTICKETINFO) lpdi->itemData;
361 if (lpdi->itemAction == ODA_FOCUS)
365 if (lpdi->itemState & ODS_SELECTED) {
366 textcolor = GetSysColor(COLOR_HIGHLIGHTTEXT);
367 bkcolor = GetSysColor(COLOR_HIGHLIGHT);
369 orgtextcolor = SetTextColor(lpdi->hDC, textcolor);
370 assert(textcolor != 0x80000000);
372 orgbkcolor = SetBkColor(lpdi->hDC, bkcolor);
373 assert(bkcolor != 0x80000000);
378 bkcolor = GetBkColor(lpdi->hDC);
379 hbrush = CreateSolidBrush(bkcolor);
380 assert(hbrush != NULL);
382 FillRect(lpdi->hDC, &(lpdi->rcItem), hbrush);
383 DeleteObject(hbrush);
386 * Display the appropriate icon
388 if (lpinfo->ticket) {
389 hicon = kwin_get_icon(lpinfo->issue_time + lpinfo->lifetime);
390 left = lpdi->rcItem.left - (32 - ICON_WIDTH) / 2;
391 top = lpdi->rcItem.top;
392 top += (lpdi->rcItem.bottom - lpdi->rcItem.top - 32) / 2;
394 b = DrawIcon(lpdi->hDC, left, top, hicon);
399 * Display centered string
401 textheight = HIWORD(GetTextExtent(lpdi->hDC, "X", 1));
402 alignment = SetTextAlign(lpdi->hDC, TA_TOP | TA_LEFT);
405 left = lpdi->rcItem.left + ICON_WIDTH;
407 left = lpdi->rcItem.left;
409 top = lpdi->rcItem.top;
410 top += (lpdi->rcItem.bottom - lpdi->rcItem.top - textheight) / 2;
411 rc = TextOut(lpdi->hDC, left, top, (LPSTR) lpinfo->buf,
412 strlen((LPSTR) lpinfo->buf));
415 alignment = SetTextAlign(lpdi->hDC, alignment);
418 if (lpdi->itemState & ODS_SELECTED) {
419 textcolor = SetTextColor(lpdi->hDC, orgtextcolor);
420 assert(textcolor != 0x80000000);
422 bkcolor = SetBkColor(lpdi->hDC, orgbkcolor);
423 assert(bkcolor != 0x80000000);
430 } /* ticket_drawitem */
439 * Return buffer with the current flags for the credential
443 flags_string(krb5_creds *cred) {
449 if (cred->ticket_flags & TKT_FLG_FORWARDABLE)
451 if (cred->ticket_flags & TKT_FLG_FORWARDED)
453 if (cred->ticket_flags & TKT_FLG_PROXIABLE)
455 if (cred->ticket_flags & TKT_FLG_PROXY)
457 if (cred->ticket_flags & TKT_FLG_MAY_POSTDATE)
459 if (cred->ticket_flags & TKT_FLG_POSTDATED)
461 if (cred->ticket_flags & TKT_FLG_INVALID)
463 if (cred->ticket_flags & TKT_FLG_RENEWABLE)
465 if (cred->ticket_flags & TKT_FLG_INITIAL)
467 if (cred->ticket_flags & TKT_FLG_HW_AUTH)
469 if (cred->ticket_flags & TKT_FLG_PRE_AUTH)