xref: /freebsd/crypto/krb5/src/windows/leash/LeashView.cpp (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubert //*****************************************************************************
2*7f2fe78bSCy Schubert // File:	LeashView.cpp
3*7f2fe78bSCy Schubert // By:		Arthur David Leather
4*7f2fe78bSCy Schubert // Created:	12/02/98
5*7f2fe78bSCy Schubert // Copyright	@1998 Massachusetts Institute of Technology - All rights reserved.
6*7f2fe78bSCy Schubert // Description:	CPP file for LeashView.h. Contains variables and functions
7*7f2fe78bSCy Schubert //		for the Leash FormView
8*7f2fe78bSCy Schubert //
9*7f2fe78bSCy Schubert // History:
10*7f2fe78bSCy Schubert //
11*7f2fe78bSCy Schubert // MM/DD/YY	Inits	Description of Change
12*7f2fe78bSCy Schubert // 12/02/98	ADL		Original
13*7f2fe78bSCy Schubert // 20030508     JEA     Added
14*7f2fe78bSCy Schubert //*****************************************************************************
15*7f2fe78bSCy Schubert 
16*7f2fe78bSCy Schubert #include "stdafx.h"
17*7f2fe78bSCy Schubert #include <afxpriv.h>
18*7f2fe78bSCy Schubert #include "Leash.h"
19*7f2fe78bSCy Schubert #include "LeashDoc.h"
20*7f2fe78bSCy Schubert #include "LeashView.h"
21*7f2fe78bSCy Schubert #include "MainFrm.h"
22*7f2fe78bSCy Schubert #include "reminder.h"
23*7f2fe78bSCy Schubert #include "lglobals.h"
24*7f2fe78bSCy Schubert #include "LeashDebugWindow.h"
25*7f2fe78bSCy Schubert #include "LeashMessageBox.h"
26*7f2fe78bSCy Schubert #include "LeashAboutBox.h"
27*7f2fe78bSCy Schubert #include <krb5.h>
28*7f2fe78bSCy Schubert 
29*7f2fe78bSCy Schubert #ifdef _DEBUG
30*7f2fe78bSCy Schubert #define new DEBUG_NEW
31*7f2fe78bSCy Schubert #undef THIS_FILE
32*7f2fe78bSCy Schubert static CHAR THIS_FILE[] = __FILE__;
33*7f2fe78bSCy Schubert #endif
34*7f2fe78bSCy Schubert 
35*7f2fe78bSCy Schubert #pragma comment(lib, "uxtheme")
36*7f2fe78bSCy Schubert /////////////////////////////////////////////////////////////////////////////
37*7f2fe78bSCy Schubert // CLeashView
38*7f2fe78bSCy Schubert 
39*7f2fe78bSCy Schubert IMPLEMENT_DYNCREATE(CLeashView, CListView)
40*7f2fe78bSCy Schubert 
41*7f2fe78bSCy Schubert BEGIN_MESSAGE_MAP(CLeashView, CListView)
42*7f2fe78bSCy Schubert 	//{{AFX_MSG_MAP(CLeashView)
43*7f2fe78bSCy Schubert     ON_MESSAGE(WM_WARNINGPOPUP, OnWarningPopup)
44*7f2fe78bSCy Schubert 	ON_MESSAGE(WM_GOODBYE, OnGoodbye)
45*7f2fe78bSCy Schubert     ON_MESSAGE(WM_TRAYICON, OnTrayIcon)
46*7f2fe78bSCy Schubert     ON_NOTIFY(TVN_ITEMEXPANDED, IDC_TREEVIEW, OnItemexpandedTreeview)
47*7f2fe78bSCy Schubert 	ON_WM_CREATE()
48*7f2fe78bSCy Schubert 	ON_WM_SHOWWINDOW()
49*7f2fe78bSCy Schubert 	ON_COMMAND(ID_INIT_TICKET, OnInitTicket)
50*7f2fe78bSCy Schubert 	ON_COMMAND(ID_RENEW_TICKET, OnRenewTicket)
51*7f2fe78bSCy Schubert 	ON_COMMAND(ID_DESTROY_TICKET, OnDestroyTicket)
52*7f2fe78bSCy Schubert 	ON_COMMAND(ID_CHANGE_PASSWORD, OnChangePassword)
53*7f2fe78bSCy Schubert 	ON_COMMAND(ID_MAKE_DEFAULT, OnMakeDefault)
54*7f2fe78bSCy Schubert 	ON_COMMAND(ID_UPDATE_DISPLAY, OnUpdateDisplay)
55*7f2fe78bSCy Schubert 	ON_COMMAND(ID_SYN_TIME, OnSynTime)
56*7f2fe78bSCy Schubert 	ON_COMMAND(ID_DEBUG_MODE, OnDebugMode)
57*7f2fe78bSCy Schubert 	ON_COMMAND(ID_LARGE_ICONS, OnLargeIcons)
58*7f2fe78bSCy Schubert 	ON_COMMAND(ID_TIME_ISSUED, OnTimeIssued)
59*7f2fe78bSCy Schubert 	ON_COMMAND(ID_VALID_UNTIL, OnValidUntil)
60*7f2fe78bSCy Schubert 	ON_COMMAND(ID_RENEWABLE_UNTIL, OnRenewableUntil)
61*7f2fe78bSCy Schubert 	ON_COMMAND(ID_SHOW_TICKET_FLAGS, OnShowTicketFlags)
62*7f2fe78bSCy Schubert 	ON_COMMAND(ID_ENCRYPTION_TYPE, OnEncryptionType)
63*7f2fe78bSCy Schubert 	ON_COMMAND(ID_CCACHE_NAME, OnCcacheName)
64*7f2fe78bSCy Schubert 	ON_UPDATE_COMMAND_UI(ID_TIME_ISSUED, OnUpdateTimeIssued)
65*7f2fe78bSCy Schubert 	ON_UPDATE_COMMAND_UI(ID_VALID_UNTIL, OnUpdateValidUntil)
66*7f2fe78bSCy Schubert 	ON_UPDATE_COMMAND_UI(ID_RENEWABLE_UNTIL, OnUpdateRenewableUntil)
67*7f2fe78bSCy Schubert 	ON_UPDATE_COMMAND_UI(ID_SHOW_TICKET_FLAGS, OnUpdateShowTicketFlags)
68*7f2fe78bSCy Schubert 	ON_UPDATE_COMMAND_UI(ID_ENCRYPTION_TYPE, OnUpdateEncryptionType)
69*7f2fe78bSCy Schubert 	ON_UPDATE_COMMAND_UI(ID_CCACHE_NAME, OnUpdateCcacheName)
70*7f2fe78bSCy Schubert 	ON_COMMAND(ID_UPPERCASE_REALM, OnUppercaseRealm)
71*7f2fe78bSCy Schubert 	ON_COMMAND(ID_KILL_TIX_ONEXIT, OnKillTixOnExit)
72*7f2fe78bSCy Schubert 	ON_UPDATE_COMMAND_UI(ID_UPPERCASE_REALM, OnUpdateUppercaseRealm)
73*7f2fe78bSCy Schubert 	ON_UPDATE_COMMAND_UI(ID_KILL_TIX_ONEXIT, OnUpdateKillTixOnExit)
74*7f2fe78bSCy Schubert 	ON_WM_DESTROY()
75*7f2fe78bSCy Schubert 	ON_UPDATE_COMMAND_UI(ID_DESTROY_TICKET, OnUpdateDestroyTicket)
76*7f2fe78bSCy Schubert 	ON_UPDATE_COMMAND_UI(ID_INIT_TICKET, OnUpdateInitTicket)
77*7f2fe78bSCy Schubert 	ON_UPDATE_COMMAND_UI(ID_RENEW_TICKET, OnUpdateRenewTicket)
78*7f2fe78bSCy Schubert 	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
79*7f2fe78bSCy Schubert 	ON_UPDATE_COMMAND_UI(ID_DEBUG_MODE, OnUpdateDebugMode)
80*7f2fe78bSCy Schubert 	ON_UPDATE_COMMAND_UI(ID_CFG_FILES, OnUpdateCfgFiles)
81*7f2fe78bSCy Schubert     ON_COMMAND(ID_LEASH_RESTORE, OnLeashRestore)
82*7f2fe78bSCy Schubert     ON_COMMAND(ID_LEASH_MINIMIZE, OnLeashMinimize)
83*7f2fe78bSCy Schubert 	ON_COMMAND(ID_LOW_TICKET_ALARM, OnLowTicketAlarm)
84*7f2fe78bSCy Schubert 	ON_COMMAND(ID_AUTO_RENEW, OnAutoRenew)
85*7f2fe78bSCy Schubert 	ON_UPDATE_COMMAND_UI(ID_LOW_TICKET_ALARM, OnUpdateLowTicketAlarm)
86*7f2fe78bSCy Schubert 	ON_UPDATE_COMMAND_UI(ID_AUTO_RENEW, OnUpdateAutoRenew)
87*7f2fe78bSCy Schubert 	ON_UPDATE_COMMAND_UI(ID_MAKE_DEFAULT, OnUpdateMakeDefault)
88*7f2fe78bSCy Schubert 	ON_UPDATE_COMMAND_UI(ID_PROPERTIES, OnUpdateProperties)
89*7f2fe78bSCy Schubert 	ON_COMMAND(ID_HELP_KERBEROS_, OnHelpKerberos)
90*7f2fe78bSCy Schubert 	ON_COMMAND(ID_HELP_LEASH32, OnHelpLeash32)
91*7f2fe78bSCy Schubert 	ON_COMMAND(ID_HELP_WHYUSELEASH32, OnHelpWhyuseleash32)
92*7f2fe78bSCy Schubert 	ON_WM_SIZE()
93*7f2fe78bSCy Schubert 	ON_WM_LBUTTONDOWN()
94*7f2fe78bSCy Schubert 	ON_WM_CLOSE()
95*7f2fe78bSCy Schubert 	ON_WM_HSCROLL()
96*7f2fe78bSCy Schubert 	ON_WM_VSCROLL()
97*7f2fe78bSCy Schubert     ON_WM_SYSCOLORCHANGE()
98*7f2fe78bSCy Schubert     ON_MESSAGE(ID_OBTAIN_TGT_WITH_LPARAM, OnObtainTGTWithParam)
99*7f2fe78bSCy Schubert     ON_NOTIFY(HDN_ITEMCHANGED, 0, OnItemChanged)
100*7f2fe78bSCy Schubert 	//}}AFX_MSG_MAP
101*7f2fe78bSCy Schubert 
102*7f2fe78bSCy Schubert     ON_NOTIFY_REFLECT(LVN_ITEMCHANGING, &CLeashView::OnLvnItemchanging)
103*7f2fe78bSCy Schubert     ON_NOTIFY_REFLECT(LVN_ITEMACTIVATE, &CLeashView::OnLvnItemActivate)
104*7f2fe78bSCy Schubert     ON_NOTIFY_REFLECT(LVN_KEYDOWN, &CLeashView::OnLvnKeydown)
105*7f2fe78bSCy Schubert     ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, &CLeashView::OnNMCustomdraw)
106*7f2fe78bSCy Schubert END_MESSAGE_MAP()
107*7f2fe78bSCy Schubert 
108*7f2fe78bSCy Schubert 
109*7f2fe78bSCy Schubert time_t CLeashView::m_ticketTimeLeft = 0;  // # of seconds left before tickets expire
110*7f2fe78bSCy Schubert INT  CLeashView::m_ticketStatusKrb5 = 0; // Defense Condition: are we low on tickets?
111*7f2fe78bSCy Schubert INT  CLeashView::m_warningOfTicketTimeLeftKrb5 = 0; // Prevents warning box from coming up repeatively
112*7f2fe78bSCy Schubert INT  CLeashView::m_warningOfTicketTimeLeftLockKrb5 = 0;
113*7f2fe78bSCy Schubert INT  CLeashView::m_updateDisplayCount;
114*7f2fe78bSCy Schubert INT  CLeashView::m_alreadyPlayedDisplayCount;
115*7f2fe78bSCy Schubert INT  CLeashView::m_autoRenewTickets = 0;
116*7f2fe78bSCy Schubert BOOL CLeashView::m_lowTicketAlarmSound;
117*7f2fe78bSCy Schubert INT  CLeashView::m_autoRenewalAttempted = 0;
118*7f2fe78bSCy Schubert LONG CLeashView::m_timerMsgNotInProgress = 1;
119*7f2fe78bSCy Schubert ViewColumnInfo CLeashView::sm_viewColumns[] =
120*7f2fe78bSCy Schubert {
121*7f2fe78bSCy Schubert     {"Principal", true, -1, 200},                        // PRINCIPAL
122*7f2fe78bSCy Schubert     {"Issued", false, ID_TIME_ISSUED, 100},              // TIME_ISSUED
123*7f2fe78bSCy Schubert     {"Renewable Until", false, ID_RENEWABLE_UNTIL, 100}, // RENEWABLE_UNTIL
124*7f2fe78bSCy Schubert     {"Valid Until", true, ID_VALID_UNTIL, 100},          // VALID_UNTIL
125*7f2fe78bSCy Schubert     {"Encryption Type", false, ID_ENCRYPTION_TYPE, 100}, // ENCRYPTION_TYPE
126*7f2fe78bSCy Schubert     {"Flags", false, ID_SHOW_TICKET_FLAGS, 100},         // TICKET_FLAGS
127*7f2fe78bSCy Schubert     {"Credential Cache", false, ID_CCACHE_NAME, 105},    // CACHE_NAME
128*7f2fe78bSCy Schubert };
129*7f2fe78bSCy Schubert 
130*7f2fe78bSCy Schubert static struct TicketFlag {
131*7f2fe78bSCy Schubert     unsigned long m_flag;
132*7f2fe78bSCy Schubert     const LPTSTR m_description;
133*7f2fe78bSCy Schubert } sm_TicketFlags[] =
134*7f2fe78bSCy Schubert {
135*7f2fe78bSCy Schubert     {TKT_FLG_FORWARDABLE, _T("Forwardable")},
136*7f2fe78bSCy Schubert     {TKT_FLG_FORWARDED, _T("Forwarded")},
137*7f2fe78bSCy Schubert     {TKT_FLG_PROXIABLE, _T("Proxiable")},
138*7f2fe78bSCy Schubert     {TKT_FLG_PROXY, _T("Proxy")},
139*7f2fe78bSCy Schubert     {TKT_FLG_RENEWABLE, _T("Renewable")},
140*7f2fe78bSCy Schubert };
141*7f2fe78bSCy Schubert 
krb5TicketFlagsToString(unsigned long flags,LPTSTR * outStr)142*7f2fe78bSCy Schubert static void krb5TicketFlagsToString(unsigned long flags, LPTSTR *outStr)
143*7f2fe78bSCy Schubert {
144*7f2fe78bSCy Schubert     const int numFlags = sizeof(sm_TicketFlags) / sizeof(sm_TicketFlags[0]);
145*7f2fe78bSCy Schubert     int strSize = 1;
146*7f2fe78bSCy Schubert     LPTSTR str;
147*7f2fe78bSCy Schubert     // pass 1: compute size
148*7f2fe78bSCy Schubert     for (int i = 0; i < numFlags; i++) {
149*7f2fe78bSCy Schubert         if (flags & sm_TicketFlags[i].m_flag) {
150*7f2fe78bSCy Schubert             if (strSize > 1)
151*7f2fe78bSCy Schubert                 strSize += 2;
152*7f2fe78bSCy Schubert             strSize += strlen(sm_TicketFlags[i].m_description);
153*7f2fe78bSCy Schubert         }
154*7f2fe78bSCy Schubert     }
155*7f2fe78bSCy Schubert     // allocate
156*7f2fe78bSCy Schubert     str = (LPSTR)malloc(strSize);
157*7f2fe78bSCy Schubert     if (str != NULL) {
158*7f2fe78bSCy Schubert         *str = 0;
159*7f2fe78bSCy Schubert         // pass 2: construct string
160*7f2fe78bSCy Schubert         for (int i = 0; i < numFlags; i++) {
161*7f2fe78bSCy Schubert             if (flags & sm_TicketFlags[i].m_flag) {
162*7f2fe78bSCy Schubert                 if (str[0])
163*7f2fe78bSCy Schubert                     _tcscat_s(str, strSize, _T(", "));
164*7f2fe78bSCy Schubert                 _tcscat_s(str, strSize, sm_TicketFlags[i].m_description);
165*7f2fe78bSCy Schubert             }
166*7f2fe78bSCy Schubert         }
167*7f2fe78bSCy Schubert     }
168*7f2fe78bSCy Schubert     *outStr = str;
169*7f2fe78bSCy Schubert }
170*7f2fe78bSCy Schubert 
171*7f2fe78bSCy Schubert 
CreateBoldFont(HFONT font)172*7f2fe78bSCy Schubert static HFONT CreateBoldFont(HFONT font)
173*7f2fe78bSCy Schubert {
174*7f2fe78bSCy Schubert     // @TODO: Should probably enumerate fonts here instead since this
175*7f2fe78bSCy Schubert     // does not actually seem to guarantee returning a new font
176*7f2fe78bSCy Schubert     // distinguishable from the original.
177*7f2fe78bSCy Schubert     LOGFONT fontAttributes = { 0 };
178*7f2fe78bSCy Schubert     ::GetObject(font, sizeof(fontAttributes), &fontAttributes);
179*7f2fe78bSCy Schubert     fontAttributes.lfWeight = FW_BOLD;
180*7f2fe78bSCy Schubert     HFONT boldFont = ::CreateFontIndirect(&fontAttributes);
181*7f2fe78bSCy Schubert     return boldFont;
182*7f2fe78bSCy Schubert }
183*7f2fe78bSCy Schubert 
CreateItalicFont(HFONT font)184*7f2fe78bSCy Schubert static HFONT CreateItalicFont(HFONT font)
185*7f2fe78bSCy Schubert {
186*7f2fe78bSCy Schubert     LOGFONT fontAttributes = { 0 };
187*7f2fe78bSCy Schubert     ::GetObject(font, sizeof(fontAttributes), &fontAttributes);
188*7f2fe78bSCy Schubert     fontAttributes.lfItalic = TRUE;
189*7f2fe78bSCy Schubert     HFONT italicFont = ::CreateFontIndirect(&fontAttributes);
190*7f2fe78bSCy Schubert     return italicFont;
191*7f2fe78bSCy Schubert }
192*7f2fe78bSCy Schubert 
CreateBoldItalicFont(HFONT font)193*7f2fe78bSCy Schubert static HFONT CreateBoldItalicFont(HFONT font)
194*7f2fe78bSCy Schubert {
195*7f2fe78bSCy Schubert     LOGFONT fontAttributes = { 0 };
196*7f2fe78bSCy Schubert     ::GetObject(font, sizeof(fontAttributes), &fontAttributes);
197*7f2fe78bSCy Schubert     fontAttributes.lfWeight = FW_BOLD;
198*7f2fe78bSCy Schubert     fontAttributes.lfItalic = TRUE;
199*7f2fe78bSCy Schubert     HFONT boldItalicFont = ::CreateFontIndirect(&fontAttributes);
200*7f2fe78bSCy Schubert     return boldItalicFont;
201*7f2fe78bSCy Schubert }
202*7f2fe78bSCy Schubert 
203*7f2fe78bSCy Schubert bool change_icon_size = true;
204*7f2fe78bSCy Schubert 
TimestampToFileTime(time_t t,LPFILETIME pft)205*7f2fe78bSCy Schubert void TimestampToFileTime(time_t t, LPFILETIME pft)
206*7f2fe78bSCy Schubert {
207*7f2fe78bSCy Schubert     // Note that LONGLONG is a 64-bit value
208*7f2fe78bSCy Schubert     ULONGLONG ll;
209*7f2fe78bSCy Schubert 
210*7f2fe78bSCy Schubert     ll = UInt32x32To64((DWORD)t, 10000000) + 116444736000000000;
211*7f2fe78bSCy Schubert     pft->dwLowDateTime = (DWORD)ll;
212*7f2fe78bSCy Schubert     pft->dwHighDateTime = ll >> 32;
213*7f2fe78bSCy Schubert }
214*7f2fe78bSCy Schubert 
215*7f2fe78bSCy Schubert // allocate outstr
TimestampToLocalizedString(time_t t,LPTSTR * outStr)216*7f2fe78bSCy Schubert void TimestampToLocalizedString(time_t t, LPTSTR *outStr)
217*7f2fe78bSCy Schubert {
218*7f2fe78bSCy Schubert     FILETIME ft, lft;
219*7f2fe78bSCy Schubert     SYSTEMTIME st;
220*7f2fe78bSCy Schubert     TimestampToFileTime(t, &ft);
221*7f2fe78bSCy Schubert     FileTimeToLocalFileTime(&ft, &lft);
222*7f2fe78bSCy Schubert     FileTimeToSystemTime(&lft, &st);
223*7f2fe78bSCy Schubert     TCHAR timeFormat[80]; // 80 is max required for LOCALE_STIMEFORMAT
224*7f2fe78bSCy Schubert     GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,
225*7f2fe78bSCy Schubert                   LOCALE_STIMEFORMAT,
226*7f2fe78bSCy Schubert                   timeFormat,
227*7f2fe78bSCy Schubert                   sizeof(timeFormat) / sizeof(timeFormat[0]));
228*7f2fe78bSCy Schubert 
229*7f2fe78bSCy Schubert     int timeSize = GetTimeFormat(LOCALE_SYSTEM_DEFAULT,
230*7f2fe78bSCy Schubert                                  TIME_NOSECONDS,
231*7f2fe78bSCy Schubert                                  &st,
232*7f2fe78bSCy Schubert                                  timeFormat,
233*7f2fe78bSCy Schubert                                  NULL,
234*7f2fe78bSCy Schubert                                  0);
235*7f2fe78bSCy Schubert     // Using dateFormat prevents localization of Month/day order,
236*7f2fe78bSCy Schubert     // but there is no other way AFAICT to suppress the year
237*7f2fe78bSCy Schubert     TCHAR * dateFormat = "MMM dd'  '";
238*7f2fe78bSCy Schubert     int dateSize = GetDateFormat(LOCALE_SYSTEM_DEFAULT,
239*7f2fe78bSCy Schubert         0, // flags
240*7f2fe78bSCy Schubert         &st,
241*7f2fe78bSCy Schubert         dateFormat, // format
242*7f2fe78bSCy Schubert         NULL, // date string
243*7f2fe78bSCy Schubert         0);
244*7f2fe78bSCy Schubert 
245*7f2fe78bSCy Schubert     if (*outStr)
246*7f2fe78bSCy Schubert         free(*outStr);
247*7f2fe78bSCy Schubert 
248*7f2fe78bSCy Schubert     // Allocate string for combined date and time,
249*7f2fe78bSCy Schubert     // but only need one terminating NULL
250*7f2fe78bSCy Schubert     LPTSTR str = (LPSTR)malloc((dateSize + timeSize - 1) * sizeof(TCHAR));
251*7f2fe78bSCy Schubert     if (!str) {
252*7f2fe78bSCy Schubert         // LeashWarn allocation failure
253*7f2fe78bSCy Schubert         *outStr = NULL;
254*7f2fe78bSCy Schubert         return;
255*7f2fe78bSCy Schubert     }
256*7f2fe78bSCy Schubert     GetDateFormat(LOCALE_SYSTEM_DEFAULT,
257*7f2fe78bSCy Schubert         0, // flags
258*7f2fe78bSCy Schubert         &st,
259*7f2fe78bSCy Schubert         dateFormat, // format
260*7f2fe78bSCy Schubert         &str[0],
261*7f2fe78bSCy Schubert         dateSize);
262*7f2fe78bSCy Schubert 
263*7f2fe78bSCy Schubert     GetTimeFormat(LOCALE_SYSTEM_DEFAULT,
264*7f2fe78bSCy Schubert                     TIME_NOSECONDS,
265*7f2fe78bSCy Schubert                     &st,
266*7f2fe78bSCy Schubert                     timeFormat,
267*7f2fe78bSCy Schubert                     &str[dateSize - 1],
268*7f2fe78bSCy Schubert                     timeSize);
269*7f2fe78bSCy Schubert     *outStr = str;
270*7f2fe78bSCy Schubert }
271*7f2fe78bSCy Schubert 
272*7f2fe78bSCy Schubert #define SECONDS_PER_MINUTE (60)
273*7f2fe78bSCy Schubert #define SECONDS_PER_HOUR (60 * SECONDS_PER_MINUTE)
274*7f2fe78bSCy Schubert #define SECONDS_PER_DAY (24 * SECONDS_PER_HOUR)
275*7f2fe78bSCy Schubert #define MAX_DURATION_STR 255
276*7f2fe78bSCy Schubert // convert time in seconds to string
DurationToString(long delta,LPTSTR * outStr)277*7f2fe78bSCy Schubert void DurationToString(long delta, LPTSTR *outStr)
278*7f2fe78bSCy Schubert {
279*7f2fe78bSCy Schubert     int days;
280*7f2fe78bSCy Schubert     int hours;
281*7f2fe78bSCy Schubert     int minutes;
282*7f2fe78bSCy Schubert     TCHAR minutesStr[MAX_DURATION_STR+1];
283*7f2fe78bSCy Schubert     TCHAR hoursStr[MAX_DURATION_STR+1];
284*7f2fe78bSCy Schubert 
285*7f2fe78bSCy Schubert     if (*outStr)
286*7f2fe78bSCy Schubert         free(*outStr);
287*7f2fe78bSCy Schubert     *outStr = (LPSTR)malloc((MAX_DURATION_STR + 1)* sizeof(TCHAR));
288*7f2fe78bSCy Schubert     if (!(*outStr))
289*7f2fe78bSCy Schubert         return;
290*7f2fe78bSCy Schubert 
291*7f2fe78bSCy Schubert     days = delta / SECONDS_PER_DAY;
292*7f2fe78bSCy Schubert     delta -= days * SECONDS_PER_DAY;
293*7f2fe78bSCy Schubert     hours = delta / SECONDS_PER_HOUR;
294*7f2fe78bSCy Schubert     delta -= hours * SECONDS_PER_HOUR;
295*7f2fe78bSCy Schubert     minutes = delta / SECONDS_PER_MINUTE;
296*7f2fe78bSCy Schubert 
297*7f2fe78bSCy Schubert     _snprintf(minutesStr, MAX_DURATION_STR, "%d m", minutes);
298*7f2fe78bSCy Schubert     minutesStr[MAX_DURATION_STR] = 0;
299*7f2fe78bSCy Schubert 
300*7f2fe78bSCy Schubert     _snprintf(hoursStr, MAX_DURATION_STR, "%d h", hours);
301*7f2fe78bSCy Schubert     hoursStr[MAX_DURATION_STR] = 0;
302*7f2fe78bSCy Schubert 
303*7f2fe78bSCy Schubert     if (days > 0) {
304*7f2fe78bSCy Schubert         _snprintf(*outStr, MAX_DURATION_STR, "(%d d, %s remaining)", days,
305*7f2fe78bSCy Schubert                   hoursStr);
306*7f2fe78bSCy Schubert     } else if (hours > 0) {
307*7f2fe78bSCy Schubert         _snprintf(*outStr, MAX_DURATION_STR, "(%s, %s remaining)", hoursStr,
308*7f2fe78bSCy Schubert                   minutesStr);
309*7f2fe78bSCy Schubert     } else {
310*7f2fe78bSCy Schubert         _snprintf(*outStr, MAX_DURATION_STR, "(%s remaining)", minutesStr);
311*7f2fe78bSCy Schubert     }
312*7f2fe78bSCy Schubert     (*outStr)[MAX_DURATION_STR] = 0;
313*7f2fe78bSCy Schubert }
314*7f2fe78bSCy Schubert 
315*7f2fe78bSCy Schubert /////////////////////////////////////////////////////////////////////////////
316*7f2fe78bSCy Schubert // CLeashView construction/destruction
317*7f2fe78bSCy Schubert 
CLeashView()318*7f2fe78bSCy Schubert CLeashView::CLeashView()
319*7f2fe78bSCy Schubert {
320*7f2fe78bSCy Schubert ////@#+Need removing as well!
321*7f2fe78bSCy Schubert     m_startup = TRUE;
322*7f2fe78bSCy Schubert     m_warningOfTicketTimeLeftKrb5 = 0;
323*7f2fe78bSCy Schubert     m_warningOfTicketTimeLeftLockKrb5 = 0;
324*7f2fe78bSCy Schubert     m_largeIcons = 0;
325*7f2fe78bSCy Schubert     m_destroyTicketsOnExit = 0;
326*7f2fe78bSCy Schubert     m_debugWindow = 0;
327*7f2fe78bSCy Schubert     m_upperCaseRealm = 0;
328*7f2fe78bSCy Schubert     m_lowTicketAlarm = 0;
329*7f2fe78bSCy Schubert 
330*7f2fe78bSCy Schubert     m_pDebugWindow = NULL;
331*7f2fe78bSCy Schubert     m_pDebugWindow = new CLeashDebugWindow(this);
332*7f2fe78bSCy Schubert     if (!m_pDebugWindow)
333*7f2fe78bSCy Schubert     {
334*7f2fe78bSCy Schubert         AfxMessageBox("There is a problem with the Leash Debug Window!",
335*7f2fe78bSCy Schubert                    MB_OK|MB_ICONSTOP);
336*7f2fe78bSCy Schubert     }
337*7f2fe78bSCy Schubert 
338*7f2fe78bSCy Schubert     m_debugStartUp = TRUE;
339*7f2fe78bSCy Schubert     m_isMinimum = FALSE;
340*7f2fe78bSCy Schubert     m_lowTicketAlarmSound = FALSE;
341*7f2fe78bSCy Schubert     m_alreadyPlayed = FALSE;
342*7f2fe78bSCy Schubert     ResetTreeNodes();
343*7f2fe78bSCy Schubert     m_hMenu = NULL;
344*7f2fe78bSCy Schubert     m_pApp = NULL;
345*7f2fe78bSCy Schubert     m_ccacheDisplay = NULL;
346*7f2fe78bSCy Schubert     m_autoRenewTickets = 0;
347*7f2fe78bSCy Schubert     m_autoRenewalAttempted = 0;
348*7f2fe78bSCy Schubert     m_pWarningMessage = NULL;
349*7f2fe78bSCy Schubert     m_bIconAdded = FALSE;
350*7f2fe78bSCy Schubert     m_bIconDeleted = FALSE;
351*7f2fe78bSCy Schubert     m_BaseFont = NULL;
352*7f2fe78bSCy Schubert     m_BoldFont = NULL;
353*7f2fe78bSCy Schubert     m_ItalicFont = NULL;
354*7f2fe78bSCy Schubert     m_aListItemInfo = NULL;
355*7f2fe78bSCy Schubert }
356*7f2fe78bSCy Schubert 
357*7f2fe78bSCy Schubert 
~CLeashView()358*7f2fe78bSCy Schubert CLeashView::~CLeashView()
359*7f2fe78bSCy Schubert {
360*7f2fe78bSCy Schubert     CCacheDisplayData *elem = m_ccacheDisplay;
361*7f2fe78bSCy Schubert     while (elem) {
362*7f2fe78bSCy Schubert         CCacheDisplayData *next = elem->m_next;
363*7f2fe78bSCy Schubert         delete elem;
364*7f2fe78bSCy Schubert         elem = next;
365*7f2fe78bSCy Schubert     }
366*7f2fe78bSCy Schubert     m_ccacheDisplay = NULL;
367*7f2fe78bSCy Schubert     // destroys window if not already destroyed
368*7f2fe78bSCy Schubert     if (m_pDebugWindow)
369*7f2fe78bSCy Schubert         delete m_pDebugWindow;
370*7f2fe78bSCy Schubert     if (m_BoldFont)
371*7f2fe78bSCy Schubert         DeleteObject(m_BoldFont);
372*7f2fe78bSCy Schubert     if (m_ItalicFont)
373*7f2fe78bSCy Schubert         DeleteObject(m_ItalicFont);
374*7f2fe78bSCy Schubert     if (m_aListItemInfo)
375*7f2fe78bSCy Schubert         delete[] m_aListItemInfo;
376*7f2fe78bSCy Schubert }
377*7f2fe78bSCy Schubert 
OnItemChanged(NMHDR * pNmHdr,LRESULT * pResult)378*7f2fe78bSCy Schubert void CLeashView::OnItemChanged(NMHDR* pNmHdr, LRESULT* pResult)
379*7f2fe78bSCy Schubert {
380*7f2fe78bSCy Schubert     NMHEADER* pHdr = (NMHEADER*)pNmHdr;
381*7f2fe78bSCy Schubert     if (!pHdr->pitem)
382*7f2fe78bSCy Schubert         return;
383*7f2fe78bSCy Schubert     if (!pHdr->pitem->mask & HDI_WIDTH)
384*7f2fe78bSCy Schubert         return;
385*7f2fe78bSCy Schubert 
386*7f2fe78bSCy Schubert     // Sync column width and save to registry
387*7f2fe78bSCy Schubert     for (int i = 0, columnIndex = 0; i < NUM_VIEW_COLUMNS; i++) {
388*7f2fe78bSCy Schubert         ViewColumnInfo &info = sm_viewColumns[i];
389*7f2fe78bSCy Schubert         if ((info.m_enabled) && (columnIndex++ == pHdr->iItem)) {
390*7f2fe78bSCy Schubert             info.m_columnWidth = pHdr->pitem->cxy;
391*7f2fe78bSCy Schubert             if (m_pApp)
392*7f2fe78bSCy Schubert                 m_pApp->WriteProfileInt("ColumnWidths", info.m_name, info.m_columnWidth);
393*7f2fe78bSCy Schubert             break;
394*7f2fe78bSCy Schubert         }
395*7f2fe78bSCy Schubert     }
396*7f2fe78bSCy Schubert }
397*7f2fe78bSCy Schubert 
PreCreateWindow(CREATESTRUCT & cs)398*7f2fe78bSCy Schubert BOOL CLeashView::PreCreateWindow(CREATESTRUCT& cs)
399*7f2fe78bSCy Schubert {
400*7f2fe78bSCy Schubert     // TODO: Modify the Window class or styles here by modifying
401*7f2fe78bSCy Schubert     //  the CREATESTRUCT cs
402*7f2fe78bSCy Schubert 
403*7f2fe78bSCy Schubert     return CListView::PreCreateWindow(cs);
404*7f2fe78bSCy Schubert }
405*7f2fe78bSCy Schubert 
406*7f2fe78bSCy Schubert /////////////////////////////////////////////////////////////////////////////
407*7f2fe78bSCy Schubert // CLeashView diagnostics
408*7f2fe78bSCy Schubert 
409*7f2fe78bSCy Schubert #ifdef _DEBUG
AssertValid() const410*7f2fe78bSCy Schubert VOID CLeashView::AssertValid() const
411*7f2fe78bSCy Schubert {
412*7f2fe78bSCy Schubert     CListView::AssertValid();
413*7f2fe78bSCy Schubert }
414*7f2fe78bSCy Schubert 
Dump(CDumpContext & dc) const415*7f2fe78bSCy Schubert VOID CLeashView::Dump(CDumpContext& dc) const
416*7f2fe78bSCy Schubert {
417*7f2fe78bSCy Schubert     CListView::Dump(dc);
418*7f2fe78bSCy Schubert }
419*7f2fe78bSCy Schubert 
420*7f2fe78bSCy Schubert /*
421*7f2fe78bSCy Schubert LeashDoc* CLeashView::GetDocument() // non-debug version is inline
422*7f2fe78bSCy Schubert {
423*7f2fe78bSCy Schubert     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(LeashDoc)));
424*7f2fe78bSCy Schubert     return (LeashDoc*)m_pDocument;
425*7f2fe78bSCy Schubert }
426*7f2fe78bSCy Schubert */
427*7f2fe78bSCy Schubert #endif //_DEBUG
428*7f2fe78bSCy Schubert 
429*7f2fe78bSCy Schubert /////////////////////////////////////////////////////////////////////////////
430*7f2fe78bSCy Schubert // CLeashView message handlers
431*7f2fe78bSCy Schubert 
Create(LPCTSTR lpszClassName,LPCTSTR lpszWindowName,DWORD dwStyle,const RECT & rect,CWnd * pParentWnd,UINT nID,CCreateContext * pContext)432*7f2fe78bSCy Schubert BOOL CLeashView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName,
433*7f2fe78bSCy Schubert                         DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
434*7f2fe78bSCy Schubert                         UINT nID, CCreateContext* pContext)
435*7f2fe78bSCy Schubert {
436*7f2fe78bSCy Schubert     return CListView::Create(lpszClassName, lpszWindowName, dwStyle, rect,
437*7f2fe78bSCy Schubert                              pParentWnd, nID, pContext);
438*7f2fe78bSCy Schubert }
439*7f2fe78bSCy Schubert 
OnCreate(LPCREATESTRUCT lpCreateStruct)440*7f2fe78bSCy Schubert INT CLeashView::OnCreate(LPCREATESTRUCT lpCreateStruct)
441*7f2fe78bSCy Schubert {
442*7f2fe78bSCy Schubert     if (CListView::OnCreate(lpCreateStruct) == -1)
443*7f2fe78bSCy Schubert         return -1;
444*7f2fe78bSCy Schubert     return 0;
445*7f2fe78bSCy Schubert }
446*7f2fe78bSCy Schubert 
OnClose(void)447*7f2fe78bSCy Schubert VOID CLeashView::OnClose(void)
448*7f2fe78bSCy Schubert {
449*7f2fe78bSCy Schubert     printf("OnClose\n");
450*7f2fe78bSCy Schubert }
451*7f2fe78bSCy Schubert 
LeashTime()452*7f2fe78bSCy Schubert time_t CLeashView::LeashTime()
453*7f2fe78bSCy Schubert {
454*7f2fe78bSCy Schubert     _tzset();
455*7f2fe78bSCy Schubert     return time(0);
456*7f2fe78bSCy Schubert }
457*7f2fe78bSCy Schubert 
458*7f2fe78bSCy Schubert // Call while possessing a lock to ticketinfo.lockObj
GetLowTicketStatus(int ver)459*7f2fe78bSCy Schubert INT CLeashView::GetLowTicketStatus(int ver)
460*7f2fe78bSCy Schubert {
461*7f2fe78bSCy Schubert     BOOL b_notix = (ver == 5 && !ticketinfo.Krb5.btickets);
462*7f2fe78bSCy Schubert 
463*7f2fe78bSCy Schubert     if (b_notix)
464*7f2fe78bSCy Schubert         return NO_TICKETS;
465*7f2fe78bSCy Schubert 
466*7f2fe78bSCy Schubert     if (m_ticketTimeLeft <= 0L)
467*7f2fe78bSCy Schubert         return ZERO_MINUTES_LEFT;
468*7f2fe78bSCy Schubert 
469*7f2fe78bSCy Schubert     if (m_ticketTimeLeft <= 20 * 60)
470*7f2fe78bSCy Schubert         return (INT)(m_ticketTimeLeft / 5 / 60) + 2 -
471*7f2fe78bSCy Schubert             (m_ticketTimeLeft % (5 * 60) == 0 ? 1 : 0);
472*7f2fe78bSCy Schubert 
473*7f2fe78bSCy Schubert     return PLENTY_OF_TIME;
474*7f2fe78bSCy Schubert }
475*7f2fe78bSCy Schubert 
UpdateTicketTime(TICKETINFO & ti)476*7f2fe78bSCy Schubert VOID CLeashView::UpdateTicketTime(TICKETINFO& ti)
477*7f2fe78bSCy Schubert {
478*7f2fe78bSCy Schubert     if (!ti.btickets) {
479*7f2fe78bSCy Schubert         m_ticketTimeLeft = 0L;
480*7f2fe78bSCy Schubert         return;
481*7f2fe78bSCy Schubert     }
482*7f2fe78bSCy Schubert 
483*7f2fe78bSCy Schubert     m_ticketTimeLeft = ti.valid_until - LeashTime();
484*7f2fe78bSCy Schubert 
485*7f2fe78bSCy Schubert     if (m_ticketTimeLeft <= 0L)
486*7f2fe78bSCy Schubert         ti.btickets = EXPIRED_TICKETS;
487*7f2fe78bSCy Schubert }
488*7f2fe78bSCy Schubert 
489*7f2fe78bSCy Schubert 
TimerProc(HWND hWnd,UINT nMsg,UINT_PTR nIDEvent,DWORD dwTime)490*7f2fe78bSCy Schubert VOID CALLBACK EXPORT CLeashView::TimerProc(HWND hWnd, UINT nMsg,
491*7f2fe78bSCy Schubert                                            UINT_PTR nIDEvent, DWORD dwTime)
492*7f2fe78bSCy Schubert {
493*7f2fe78bSCy Schubert     // All of the work is being done in the PreTranslateMessage method
494*7f2fe78bSCy Schubert     // in order to have access to the object
495*7f2fe78bSCy Schubert }
496*7f2fe78bSCy Schubert 
ApplicationInfoMissingMsg()497*7f2fe78bSCy Schubert VOID  CLeashView::ApplicationInfoMissingMsg()
498*7f2fe78bSCy Schubert {
499*7f2fe78bSCy Schubert     AfxMessageBox("There is a problem finding Leash application information!",
500*7f2fe78bSCy Schubert                MB_OK|MB_ICONSTOP);
501*7f2fe78bSCy Schubert }
502*7f2fe78bSCy Schubert 
OnShowWindow(BOOL bShow,UINT nStatus)503*7f2fe78bSCy Schubert VOID CLeashView::OnShowWindow(BOOL bShow, UINT nStatus)
504*7f2fe78bSCy Schubert {
505*7f2fe78bSCy Schubert     CListView::OnShowWindow(bShow, nStatus);
506*7f2fe78bSCy Schubert 
507*7f2fe78bSCy Schubert     // Get State of Icons Size
508*7f2fe78bSCy Schubert     m_pApp = AfxGetApp();
509*7f2fe78bSCy Schubert     if (!m_pApp)
510*7f2fe78bSCy Schubert     {
511*7f2fe78bSCy Schubert         ApplicationInfoMissingMsg();
512*7f2fe78bSCy Schubert     }
513*7f2fe78bSCy Schubert     else
514*7f2fe78bSCy Schubert     {
515*7f2fe78bSCy Schubert         m_largeIcons = m_pApp->GetProfileInt("Settings", "LargeIcons", ON);
516*7f2fe78bSCy Schubert 
517*7f2fe78bSCy Schubert         // Get State of Destroy Tickets On Exit
518*7f2fe78bSCy Schubert         m_destroyTicketsOnExit = m_pApp->GetProfileInt("Settings", "DestroyTicketsOnExit", OFF);
519*7f2fe78bSCy Schubert 
520*7f2fe78bSCy Schubert         // Get State of Low Ticket Alarm
521*7f2fe78bSCy Schubert         m_lowTicketAlarm = m_pApp->GetProfileInt("Settings", "LowTicketAlarm", ON);
522*7f2fe78bSCy Schubert 
523*7f2fe78bSCy Schubert         // Get State of Auto Renew Tickets
524*7f2fe78bSCy Schubert         m_autoRenewTickets = m_pApp->GetProfileInt("Settings", "AutoRenewTickets", ON);
525*7f2fe78bSCy Schubert 
526*7f2fe78bSCy Schubert         // Get State of Upper Case Realm
527*7f2fe78bSCy Schubert         m_upperCaseRealm = pLeash_get_default_uppercaserealm();
528*7f2fe78bSCy Schubert 
529*7f2fe78bSCy Schubert         // UI main display column widths
530*7f2fe78bSCy Schubert         for (int i=0; i<NUM_VIEW_COLUMNS; i++) {
531*7f2fe78bSCy Schubert             ViewColumnInfo &info = sm_viewColumns[i];
532*7f2fe78bSCy Schubert             info.m_enabled = m_pApp->GetProfileInt("Settings",
533*7f2fe78bSCy Schubert                                                    info.m_name,
534*7f2fe78bSCy Schubert                                                    info.m_enabled);
535*7f2fe78bSCy Schubert             info.m_columnWidth = m_pApp->GetProfileInt("ColumnWidths",
536*7f2fe78bSCy Schubert                                                    info.m_name,
537*7f2fe78bSCy Schubert                                                    info.m_columnWidth);
538*7f2fe78bSCy Schubert         }
539*7f2fe78bSCy Schubert 
540*7f2fe78bSCy Schubert         OnLargeIcons();
541*7f2fe78bSCy Schubert     }
542*7f2fe78bSCy Schubert 
543*7f2fe78bSCy Schubert     SetTimer(1, ONE_SECOND, TimerProc);
544*7f2fe78bSCy Schubert 
545*7f2fe78bSCy Schubert     if (!CLeashApp::m_hKrb5DLL)
546*7f2fe78bSCy Schubert     {
547*7f2fe78bSCy Schubert ////Update not to mention K4
548*7f2fe78bSCy Schubert         AfxMessageBox("Kerberos Five is not loaded!!!"
549*7f2fe78bSCy Schubert                    "\r\nYou will not be able to retrieve tickets and/or "
550*7f2fe78bSCy Schubert                    "tokens.",
551*7f2fe78bSCy Schubert                    MB_OK|MB_ICONWARNING);
552*7f2fe78bSCy Schubert     }
553*7f2fe78bSCy Schubert 
554*7f2fe78bSCy Schubert     SetDlgItemText(IDC_LABEL_KERB_TICKETS,
555*7f2fe78bSCy Schubert 		   "Your Kerberos Tickets (Issued/Expires/[Renew]/Principal)");
556*7f2fe78bSCy Schubert 
557*7f2fe78bSCy Schubert     // CLeashApp::m_krbv5_context = NULL;
558*7f2fe78bSCy Schubert }
559*7f2fe78bSCy Schubert 
OnInitTicket()560*7f2fe78bSCy Schubert VOID CLeashView::OnInitTicket()
561*7f2fe78bSCy Schubert {
562*7f2fe78bSCy Schubert     try {
563*7f2fe78bSCy Schubert         InitTicket(m_hWnd);
564*7f2fe78bSCy Schubert     }
565*7f2fe78bSCy Schubert     catch(...) {
566*7f2fe78bSCy Schubert         AfxMessageBox("Ticket Getting operation already in progress", MB_OK, 0);
567*7f2fe78bSCy Schubert     }
568*7f2fe78bSCy Schubert }
569*7f2fe78bSCy Schubert 
InitTicket(void * hWnd)570*7f2fe78bSCy Schubert UINT CLeashView::InitTicket(void * hWnd)
571*7f2fe78bSCy Schubert {
572*7f2fe78bSCy Schubert     LSH_DLGINFO_EX ldi;
573*7f2fe78bSCy Schubert     char username[64];
574*7f2fe78bSCy Schubert     char realm[192];
575*7f2fe78bSCy Schubert     int i=0, j=0;
576*7f2fe78bSCy Schubert     if (WaitForSingleObject( ticketinfo.lockObj, INFINITE ) != WAIT_OBJECT_0) {
577*7f2fe78bSCy Schubert         throw("Unable to lock ticketinfo");
578*7f2fe78bSCy Schubert     }
579*7f2fe78bSCy Schubert     LeashKRB5ListDefaultTickets(&ticketinfo.Krb5);
580*7f2fe78bSCy Schubert     char * principal = ticketinfo.Krb5.principal;
581*7f2fe78bSCy Schubert     if (principal)
582*7f2fe78bSCy Schubert         for (; principal[i] && principal[i] != '@'; i++)
583*7f2fe78bSCy Schubert             username[i] = principal[i];
584*7f2fe78bSCy Schubert     username[i] = '\0';
585*7f2fe78bSCy Schubert     if (principal && principal[i]) {
586*7f2fe78bSCy Schubert         for (i++ ; principal[i] ; i++, j++)
587*7f2fe78bSCy Schubert         {
588*7f2fe78bSCy Schubert             realm[j] = principal[i];
589*7f2fe78bSCy Schubert         }
590*7f2fe78bSCy Schubert     }
591*7f2fe78bSCy Schubert     realm[j] = '\0';
592*7f2fe78bSCy Schubert     LeashKRB5FreeTicketInfo(&ticketinfo.Krb5);
593*7f2fe78bSCy Schubert     ReleaseMutex(ticketinfo.lockObj);
594*7f2fe78bSCy Schubert 
595*7f2fe78bSCy Schubert     ldi.size = sizeof(ldi);
596*7f2fe78bSCy Schubert     ldi.dlgtype = DLGTYPE_PASSWD;
597*7f2fe78bSCy Schubert     ldi.title = ldi.in.title;
598*7f2fe78bSCy Schubert     strcpy_s(ldi.in.title,"MIT Kerberos: Get Ticket");
599*7f2fe78bSCy Schubert     ldi.username = ldi.in.username;
600*7f2fe78bSCy Schubert     strcpy(ldi.in.username,username);
601*7f2fe78bSCy Schubert     ldi.realm = ldi.in.realm;
602*7f2fe78bSCy Schubert     strcpy(ldi.in.realm,realm);
603*7f2fe78bSCy Schubert     ldi.dlgtype = DLGTYPE_PASSWD;
604*7f2fe78bSCy Schubert     ldi.use_defaults = 1;
605*7f2fe78bSCy Schubert 
606*7f2fe78bSCy Schubert     if (!hWnd)
607*7f2fe78bSCy Schubert     {
608*7f2fe78bSCy Schubert         AfxMessageBox("There is a problem finding the Leash Window!",
609*7f2fe78bSCy Schubert                    MB_OK|MB_ICONSTOP);
610*7f2fe78bSCy Schubert         return 0;
611*7f2fe78bSCy Schubert     }
612*7f2fe78bSCy Schubert 
613*7f2fe78bSCy Schubert     int result = pLeash_kinit_dlg_ex((HWND)hWnd, &ldi);
614*7f2fe78bSCy Schubert 
615*7f2fe78bSCy Schubert     if (-1 == result)
616*7f2fe78bSCy Schubert     {
617*7f2fe78bSCy Schubert         AfxMessageBox("There is a problem getting tickets!",
618*7f2fe78bSCy Schubert                    MB_OK|MB_ICONSTOP);
619*7f2fe78bSCy Schubert     }
620*7f2fe78bSCy Schubert     else if ( result )
621*7f2fe78bSCy Schubert     {
622*7f2fe78bSCy Schubert         if (WaitForSingleObject( ticketinfo.lockObj, INFINITE ) != WAIT_OBJECT_0) {
623*7f2fe78bSCy Schubert             throw("Unable to lock ticketinfo");
624*7f2fe78bSCy Schubert         }
625*7f2fe78bSCy Schubert         m_warningOfTicketTimeLeftKrb5 = 0;
626*7f2fe78bSCy Schubert         m_ticketStatusKrb5 = 0;
627*7f2fe78bSCy Schubert         ReleaseMutex(ticketinfo.lockObj);
628*7f2fe78bSCy Schubert         m_autoRenewalAttempted = 0;
629*7f2fe78bSCy Schubert         ::SendMessage((HWND)hWnd, WM_COMMAND, ID_UPDATE_DISPLAY, 0);
630*7f2fe78bSCy Schubert     }
631*7f2fe78bSCy Schubert     return 0;
632*7f2fe78bSCy Schubert }
633*7f2fe78bSCy Schubert 
krenew(void * param)634*7f2fe78bSCy Schubert static UINT krenew(void *param)
635*7f2fe78bSCy Schubert {
636*7f2fe78bSCy Schubert     char *ccache_name = (char *)param;
637*7f2fe78bSCy Schubert     krb5_context ctx = 0;
638*7f2fe78bSCy Schubert     krb5_ccache ccache = NULL;
639*7f2fe78bSCy Schubert     krb5_principal me = 0;
640*7f2fe78bSCy Schubert     krb5_principal server = 0;
641*7f2fe78bSCy Schubert     krb5_creds my_creds;
642*7f2fe78bSCy Schubert     krb5_data *realm = 0;
643*7f2fe78bSCy Schubert 
644*7f2fe78bSCy Schubert     memset(&my_creds, 0, sizeof(krb5_creds));
645*7f2fe78bSCy Schubert     if (ccache_name == NULL)
646*7f2fe78bSCy Schubert         // Bad param
647*7f2fe78bSCy Schubert         goto cleanup;
648*7f2fe78bSCy Schubert 
649*7f2fe78bSCy Schubert     krb5_error_code code = pkrb5_init_context(&ctx);
650*7f2fe78bSCy Schubert     if (code) {
651*7f2fe78bSCy Schubert         // TODO: spew error
652*7f2fe78bSCy Schubert         goto cleanup;
653*7f2fe78bSCy Schubert     }
654*7f2fe78bSCy Schubert     code = pkrb5_cc_resolve(ctx, ccache_name, &ccache);
655*7f2fe78bSCy Schubert     if (code) {
656*7f2fe78bSCy Schubert         // TODO: spew error
657*7f2fe78bSCy Schubert         goto cleanup;
658*7f2fe78bSCy Schubert     }
659*7f2fe78bSCy Schubert 
660*7f2fe78bSCy Schubert     code = pkrb5_cc_get_principal(ctx, ccache, &me);
661*7f2fe78bSCy Schubert     if (code)
662*7f2fe78bSCy Schubert         goto cleanup;
663*7f2fe78bSCy Schubert 
664*7f2fe78bSCy Schubert     realm = krb5_princ_realm(ctx, me);
665*7f2fe78bSCy Schubert 
666*7f2fe78bSCy Schubert     code = pkrb5_build_principal_ext(ctx, &server,
667*7f2fe78bSCy Schubert                                     realm->length, realm->data,
668*7f2fe78bSCy Schubert                                     KRB5_TGS_NAME_SIZE, KRB5_TGS_NAME,
669*7f2fe78bSCy Schubert                                     realm->length, realm->data,
670*7f2fe78bSCy Schubert                                     0);
671*7f2fe78bSCy Schubert     if (code)
672*7f2fe78bSCy Schubert         goto cleanup;
673*7f2fe78bSCy Schubert 
674*7f2fe78bSCy Schubert     my_creds.client = me;
675*7f2fe78bSCy Schubert     my_creds.server = server;
676*7f2fe78bSCy Schubert 
677*7f2fe78bSCy Schubert #ifdef KRB5_TC_NOTICKET
678*7f2fe78bSCy Schubert     pkrb5_cc_set_flags(ctx, ccache, 0);
679*7f2fe78bSCy Schubert #endif
680*7f2fe78bSCy Schubert     code = pkrb5_get_renewed_creds(ctx, &my_creds, me, ccache, NULL);
681*7f2fe78bSCy Schubert #ifdef KRB5_TC_NOTICKET
682*7f2fe78bSCy Schubert     pkrb5_cc_set_flags(ctx, ccache, KRB5_TC_NOTICKET);
683*7f2fe78bSCy Schubert #endif
684*7f2fe78bSCy Schubert     if (code) {
685*7f2fe78bSCy Schubert /* TODO
686*7f2fe78bSCy Schubert         if (code != KRB5KDC_ERR_ETYPE_NOSUPP || code != KRB5_KDC_UNREACH)
687*7f2fe78bSCy Schubert             Leash_krb5_error(code, "krb5_get_renewed_creds()", 0, &ctx,
688*7f2fe78bSCy Schubert                              &ccache);
689*7f2fe78bSCy Schubert */
690*7f2fe78bSCy Schubert         goto cleanup;
691*7f2fe78bSCy Schubert     }
692*7f2fe78bSCy Schubert 
693*7f2fe78bSCy Schubert     code = pkrb5_cc_initialize(ctx, ccache, me);
694*7f2fe78bSCy Schubert     if (code)
695*7f2fe78bSCy Schubert         goto cleanup;
696*7f2fe78bSCy Schubert 
697*7f2fe78bSCy Schubert     code = pkrb5_cc_store_cred(ctx, ccache, &my_creds);
698*7f2fe78bSCy Schubert     if (code)
699*7f2fe78bSCy Schubert         goto cleanup;
700*7f2fe78bSCy Schubert 
701*7f2fe78bSCy Schubert cleanup:
702*7f2fe78bSCy Schubert     if (my_creds.client == me)
703*7f2fe78bSCy Schubert         my_creds.client = 0;
704*7f2fe78bSCy Schubert     if (my_creds.server == server)
705*7f2fe78bSCy Schubert         my_creds.server = 0;
706*7f2fe78bSCy Schubert     pkrb5_free_cred_contents(ctx, &my_creds);
707*7f2fe78bSCy Schubert     if (me != NULL)
708*7f2fe78bSCy Schubert         pkrb5_free_principal(ctx, me);
709*7f2fe78bSCy Schubert     if (server != NULL)
710*7f2fe78bSCy Schubert         pkrb5_free_principal(ctx, server);
711*7f2fe78bSCy Schubert     if (ccache != NULL)
712*7f2fe78bSCy Schubert         pkrb5_cc_close(ctx, ccache);
713*7f2fe78bSCy Schubert     if (ctx != NULL)
714*7f2fe78bSCy Schubert         pkrb5_free_context(ctx);
715*7f2fe78bSCy Schubert     if (ccache_name != NULL)
716*7f2fe78bSCy Schubert         free(ccache_name);
717*7f2fe78bSCy Schubert 
718*7f2fe78bSCy Schubert     CLeashApp::m_bUpdateDisplay = TRUE;
719*7f2fe78bSCy Schubert     return 0;
720*7f2fe78bSCy Schubert }
721*7f2fe78bSCy Schubert 
OnRenewTicket()722*7f2fe78bSCy Schubert VOID CLeashView::OnRenewTicket()
723*7f2fe78bSCy Schubert {
724*7f2fe78bSCy Schubert     if ( !CLeashApp::m_hKrb5DLL )
725*7f2fe78bSCy Schubert         return;
726*7f2fe78bSCy Schubert 
727*7f2fe78bSCy Schubert     // @TODO: grab list mutex
728*7f2fe78bSCy Schubert     CCacheDisplayData *elem = m_ccacheDisplay;
729*7f2fe78bSCy Schubert     while (elem != NULL) {
730*7f2fe78bSCy Schubert         if (elem->m_selected) {
731*7f2fe78bSCy Schubert             char *ccache_name = strdup(elem->m_ccacheName);
732*7f2fe78bSCy Schubert             if (ccache_name)
733*7f2fe78bSCy Schubert                 AfxBeginThread(krenew, (void *)ccache_name);
734*7f2fe78bSCy Schubert         }
735*7f2fe78bSCy Schubert         elem = elem->m_next;
736*7f2fe78bSCy Schubert     }
737*7f2fe78bSCy Schubert     // release list mutex
738*7f2fe78bSCy Schubert }
739*7f2fe78bSCy Schubert 
RenewTicket(void * hWnd)740*7f2fe78bSCy Schubert UINT CLeashView::RenewTicket(void * hWnd)
741*7f2fe78bSCy Schubert {
742*7f2fe78bSCy Schubert     if ( !CLeashApp::m_hKrb5DLL )
743*7f2fe78bSCy Schubert         return 0;
744*7f2fe78bSCy Schubert 
745*7f2fe78bSCy Schubert     // Try to renew
746*7f2fe78bSCy Schubert     BOOL b_renewed = pLeash_renew();
747*7f2fe78bSCy Schubert     if ( b_renewed ) {
748*7f2fe78bSCy Schubert         m_warningOfTicketTimeLeftKrb5 = 0;
749*7f2fe78bSCy Schubert         m_ticketStatusKrb5 = 0;
750*7f2fe78bSCy Schubert         m_autoRenewalAttempted = 0;
751*7f2fe78bSCy Schubert         ReleaseMutex(ticketinfo.lockObj);
752*7f2fe78bSCy Schubert         ::SendMessage((HWND)hWnd, WM_COMMAND, ID_UPDATE_DISPLAY, 0);
753*7f2fe78bSCy Schubert         return 0;
754*7f2fe78bSCy Schubert     }
755*7f2fe78bSCy Schubert 
756*7f2fe78bSCy Schubert     AfxBeginThread(InitTicket,hWnd);
757*7f2fe78bSCy Schubert 
758*7f2fe78bSCy Schubert     return 0;
759*7f2fe78bSCy Schubert }
760*7f2fe78bSCy Schubert 
kdestroy(const char * ccache_name)761*7f2fe78bSCy Schubert static void kdestroy(const char *ccache_name)
762*7f2fe78bSCy Schubert {
763*7f2fe78bSCy Schubert     krb5_context ctx;
764*7f2fe78bSCy Schubert     krb5_ccache ccache=NULL;
765*7f2fe78bSCy Schubert     int code = pkrb5_init_context(&ctx);
766*7f2fe78bSCy Schubert     if (code) {
767*7f2fe78bSCy Schubert         // TODO: spew error
768*7f2fe78bSCy Schubert         goto cleanup;
769*7f2fe78bSCy Schubert     }
770*7f2fe78bSCy Schubert     code = pkrb5_cc_resolve(ctx, ccache_name, &ccache);
771*7f2fe78bSCy Schubert     if (code) {
772*7f2fe78bSCy Schubert         // TODO: spew error
773*7f2fe78bSCy Schubert         goto cleanup;
774*7f2fe78bSCy Schubert     }
775*7f2fe78bSCy Schubert     code = pkrb5_cc_destroy(ctx, ccache);
776*7f2fe78bSCy Schubert     if (code) {
777*7f2fe78bSCy Schubert         goto cleanup;
778*7f2fe78bSCy Schubert     }
779*7f2fe78bSCy Schubert cleanup:
780*7f2fe78bSCy Schubert     if (ctx)
781*7f2fe78bSCy Schubert         pkrb5_free_context(ctx);
782*7f2fe78bSCy Schubert }
783*7f2fe78bSCy Schubert 
784*7f2fe78bSCy Schubert 
OnDestroyTicket()785*7f2fe78bSCy Schubert VOID CLeashView::OnDestroyTicket()
786*7f2fe78bSCy Schubert {
787*7f2fe78bSCy Schubert     // @TODO: grab mutex
788*7f2fe78bSCy Schubert     BOOL destroy = FALSE;
789*7f2fe78bSCy Schubert     CCacheDisplayData *elem = m_ccacheDisplay;
790*7f2fe78bSCy Schubert     while (elem) {
791*7f2fe78bSCy Schubert         if (elem->m_selected) {
792*7f2fe78bSCy Schubert             // @TODO add princ to msg text
793*7f2fe78bSCy Schubert             destroy = TRUE;
794*7f2fe78bSCy Schubert         }
795*7f2fe78bSCy Schubert         elem = elem->m_next;
796*7f2fe78bSCy Schubert     }
797*7f2fe78bSCy Schubert     // release mutex
798*7f2fe78bSCy Schubert 
799*7f2fe78bSCy Schubert     if (destroy)
800*7f2fe78bSCy Schubert     {
801*7f2fe78bSCy Schubert         INT whatToDo;
802*7f2fe78bSCy Schubert 
803*7f2fe78bSCy Schubert         whatToDo = AfxMessageBox("Are you sure you want to destroy these tickets?",
804*7f2fe78bSCy Schubert                                     MB_ICONEXCLAMATION|MB_YESNO, 0);
805*7f2fe78bSCy Schubert 
806*7f2fe78bSCy Schubert         if (whatToDo == IDYES)
807*7f2fe78bSCy Schubert         {
808*7f2fe78bSCy Schubert             // grab list mutex
809*7f2fe78bSCy Schubert             elem = m_ccacheDisplay;
810*7f2fe78bSCy Schubert             while (elem) {
811*7f2fe78bSCy Schubert                 if (elem->m_selected)
812*7f2fe78bSCy Schubert                     kdestroy(elem->m_ccacheName);
813*7f2fe78bSCy Schubert                 elem = elem->m_next;
814*7f2fe78bSCy Schubert             }
815*7f2fe78bSCy Schubert             // release list mutex
816*7f2fe78bSCy Schubert             SendMessage(WM_COMMAND, ID_UPDATE_DISPLAY, 0);
817*7f2fe78bSCy Schubert         }
818*7f2fe78bSCy Schubert     }
819*7f2fe78bSCy Schubert     m_autoRenewalAttempted = 0;
820*7f2fe78bSCy Schubert }
821*7f2fe78bSCy Schubert 
OnMakeDefault()822*7f2fe78bSCy Schubert VOID CLeashView::OnMakeDefault()
823*7f2fe78bSCy Schubert {
824*7f2fe78bSCy Schubert     CCacheDisplayData *elem = m_ccacheDisplay;
825*7f2fe78bSCy Schubert     int code = 0;
826*7f2fe78bSCy Schubert     krb5_context ctx;
827*7f2fe78bSCy Schubert     krb5_ccache cc;
828*7f2fe78bSCy Schubert     while (elem) {
829*7f2fe78bSCy Schubert         if (elem->m_selected) {
830*7f2fe78bSCy Schubert             pkrb5_init_context(&ctx);
831*7f2fe78bSCy Schubert             code = pkrb5_cc_resolve(ctx, elem->m_ccacheName, &cc);
832*7f2fe78bSCy Schubert             if (!code)
833*7f2fe78bSCy Schubert                 code = pkrb5_cc_switch(ctx, cc);
834*7f2fe78bSCy Schubert             if (!code) {
835*7f2fe78bSCy Schubert                 const char *cctype = pkrb5_cc_get_type(ctx, cc);
836*7f2fe78bSCy Schubert                 if (cctype != NULL) {
837*7f2fe78bSCy Schubert                     char defname[20];
838*7f2fe78bSCy Schubert                     sprintf_s(defname, "%s:", cctype);
839*7f2fe78bSCy Schubert                     code = pkrb5int_cc_user_set_default_name(ctx, defname);
840*7f2fe78bSCy Schubert                 }
841*7f2fe78bSCy Schubert             }
842*7f2fe78bSCy Schubert             pkrb5_free_context(ctx);
843*7f2fe78bSCy Schubert             CLeashApp::m_bUpdateDisplay = TRUE;
844*7f2fe78bSCy Schubert             break;
845*7f2fe78bSCy Schubert         }
846*7f2fe78bSCy Schubert         elem = elem->m_next;
847*7f2fe78bSCy Schubert     }
848*7f2fe78bSCy Schubert }
849*7f2fe78bSCy Schubert 
OnChangePassword()850*7f2fe78bSCy Schubert VOID CLeashView::OnChangePassword()
851*7f2fe78bSCy Schubert {
852*7f2fe78bSCy Schubert     krb5_context ctx = 0;
853*7f2fe78bSCy Schubert     krb5_ccache ccache = 0;
854*7f2fe78bSCy Schubert     krb5_principal princ = 0;
855*7f2fe78bSCy Schubert     char *pname = NULL;
856*7f2fe78bSCy Schubert     char *username = NULL;
857*7f2fe78bSCy Schubert     char *realm = NULL;
858*7f2fe78bSCy Schubert     int code = 0;
859*7f2fe78bSCy Schubert 
860*7f2fe78bSCy Schubert     CCacheDisplayData *elem = m_ccacheDisplay;
861*7f2fe78bSCy Schubert     while (elem != NULL) {
862*7f2fe78bSCy Schubert         if (elem->m_selected) {
863*7f2fe78bSCy Schubert             if (elem->m_ccacheName)
864*7f2fe78bSCy Schubert                 break;
865*7f2fe78bSCy Schubert         }
866*7f2fe78bSCy Schubert         elem = elem->m_next;
867*7f2fe78bSCy Schubert     }
868*7f2fe78bSCy Schubert     if (elem != NULL) {
869*7f2fe78bSCy Schubert         code = pkrb5_init_context(&ctx);
870*7f2fe78bSCy Schubert         if (code) {
871*7f2fe78bSCy Schubert             // TODO: spew error
872*7f2fe78bSCy Schubert             goto cleanup;
873*7f2fe78bSCy Schubert         }
874*7f2fe78bSCy Schubert         code = pkrb5_cc_resolve(ctx, elem->m_ccacheName, &ccache);
875*7f2fe78bSCy Schubert         if (code) {
876*7f2fe78bSCy Schubert             // TODO: spew error
877*7f2fe78bSCy Schubert             goto cleanup;
878*7f2fe78bSCy Schubert         }
879*7f2fe78bSCy Schubert         code = pkrb5_cc_get_principal(ctx, ccache, &princ);
880*7f2fe78bSCy Schubert         if (code) {
881*7f2fe78bSCy Schubert             goto cleanup;
882*7f2fe78bSCy Schubert         }
883*7f2fe78bSCy Schubert         code = pkrb5_unparse_name(ctx, princ, &pname);
884*7f2fe78bSCy Schubert         if (code) {
885*7f2fe78bSCy Schubert             goto cleanup;
886*7f2fe78bSCy Schubert         }
887*7f2fe78bSCy Schubert     }
888*7f2fe78bSCy Schubert 
889*7f2fe78bSCy Schubert     LSH_DLGINFO_EX ldi;
890*7f2fe78bSCy Schubert     if (pname != NULL) {
891*7f2fe78bSCy Schubert         username = pname;
892*7f2fe78bSCy Schubert         realm = strchr(pname, '@');
893*7f2fe78bSCy Schubert         if (realm != NULL)
894*7f2fe78bSCy Schubert             *realm++ = '\0';
895*7f2fe78bSCy Schubert     }
896*7f2fe78bSCy Schubert     ldi.size = sizeof(ldi);
897*7f2fe78bSCy Schubert     ldi.dlgtype = DLGTYPE_CHPASSWD;
898*7f2fe78bSCy Schubert     ldi.title = ldi.in.title;
899*7f2fe78bSCy Schubert     strcpy_s(ldi.in.title, "MIT Kerberos: Change Password");
900*7f2fe78bSCy Schubert     ldi.username = ldi.in.username;
901*7f2fe78bSCy Schubert     strcpy_s(ldi.in.username, username ? username : "");
902*7f2fe78bSCy Schubert     ldi.realm = ldi.in.realm;
903*7f2fe78bSCy Schubert     strcpy_s(ldi.in.realm, realm ? realm : "");
904*7f2fe78bSCy Schubert     ldi.use_defaults = 1;
905*7f2fe78bSCy Schubert 
906*7f2fe78bSCy Schubert     int result = pLeash_changepwd_dlg_ex(m_hWnd, &ldi);
907*7f2fe78bSCy Schubert     if (-1 == result) {
908*7f2fe78bSCy Schubert         AfxMessageBox("There is a problem changing password!",
909*7f2fe78bSCy Schubert                    MB_OK|MB_ICONSTOP);
910*7f2fe78bSCy Schubert     }
911*7f2fe78bSCy Schubert cleanup:
912*7f2fe78bSCy Schubert     if (pname != NULL)
913*7f2fe78bSCy Schubert         pkrb5_free_unparsed_name(ctx, pname);
914*7f2fe78bSCy Schubert     if (princ != NULL)
915*7f2fe78bSCy Schubert         pkrb5_free_principal(ctx, princ);
916*7f2fe78bSCy Schubert     if (ccache != NULL)
917*7f2fe78bSCy Schubert         pkrb5_cc_close(ctx, ccache);
918*7f2fe78bSCy Schubert     if (ctx != NULL)
919*7f2fe78bSCy Schubert         pkrb5_free_context(ctx);
920*7f2fe78bSCy Schubert }
921*7f2fe78bSCy Schubert 
922*7f2fe78bSCy Schubert static CCacheDisplayData **
FindCCacheDisplayData(const char * ccacheName,CCacheDisplayData ** pList)923*7f2fe78bSCy Schubert FindCCacheDisplayData(const char * ccacheName, CCacheDisplayData **pList)
924*7f2fe78bSCy Schubert {
925*7f2fe78bSCy Schubert     CCacheDisplayData *elem;
926*7f2fe78bSCy Schubert     while ((elem = *pList)) {
927*7f2fe78bSCy Schubert         if (strcmp(ccacheName, elem->m_ccacheName)==0)
928*7f2fe78bSCy Schubert             return pList;
929*7f2fe78bSCy Schubert         pList = &elem->m_next;
930*7f2fe78bSCy Schubert     }
931*7f2fe78bSCy Schubert     return NULL;
932*7f2fe78bSCy Schubert }
933*7f2fe78bSCy Schubert 
AddDisplayItem(CListCtrl & list,CCacheDisplayData * elem,int iItem,char * principal,time_t issued,time_t valid_until,time_t renew_until,char * encTypes,unsigned long flags,char * ccache_name)934*7f2fe78bSCy Schubert void CLeashView::AddDisplayItem(CListCtrl &list,
935*7f2fe78bSCy Schubert                                 CCacheDisplayData *elem,
936*7f2fe78bSCy Schubert                                 int iItem,
937*7f2fe78bSCy Schubert                                 char *principal,
938*7f2fe78bSCy Schubert                                 time_t issued,
939*7f2fe78bSCy Schubert                                 time_t valid_until,
940*7f2fe78bSCy Schubert                                 time_t renew_until,
941*7f2fe78bSCy Schubert                                 char *encTypes,
942*7f2fe78bSCy Schubert                                 unsigned long flags,
943*7f2fe78bSCy Schubert                                 char *ccache_name)
944*7f2fe78bSCy Schubert {
945*7f2fe78bSCy Schubert     TCHAR* localTimeStr=NULL;
946*7f2fe78bSCy Schubert     TCHAR* durationStr=NULL;
947*7f2fe78bSCy Schubert     TCHAR* flagsStr=NULL;
948*7f2fe78bSCy Schubert     TCHAR tempStr[MAX_DURATION_STR+1];
949*7f2fe78bSCy Schubert     time_t now = LeashTime();
950*7f2fe78bSCy Schubert 
951*7f2fe78bSCy Schubert     list.InsertItem(iItem, principal, -1);
952*7f2fe78bSCy Schubert 
953*7f2fe78bSCy Schubert     int iSubItem = 1;
954*7f2fe78bSCy Schubert     if (sm_viewColumns[TIME_ISSUED].m_enabled) {
955*7f2fe78bSCy Schubert         if (issued == 0) {
956*7f2fe78bSCy Schubert             list.SetItemText(iItem, iSubItem++, "Unknown");
957*7f2fe78bSCy Schubert         } else {
958*7f2fe78bSCy Schubert             TimestampToLocalizedString(issued, &localTimeStr);
959*7f2fe78bSCy Schubert             list.SetItemText(iItem, iSubItem++, localTimeStr);
960*7f2fe78bSCy Schubert         }
961*7f2fe78bSCy Schubert     }
962*7f2fe78bSCy Schubert     if (sm_viewColumns[RENEWABLE_UNTIL].m_enabled) {
963*7f2fe78bSCy Schubert         if (valid_until == 0) {
964*7f2fe78bSCy Schubert             list.SetItemText(iItem, iSubItem++, "Unknown");
965*7f2fe78bSCy Schubert         } else if (valid_until < now) {
966*7f2fe78bSCy Schubert             list.SetItemText(iItem, iSubItem++, "Expired");
967*7f2fe78bSCy Schubert         } else if (renew_until) {
968*7f2fe78bSCy Schubert             TimestampToLocalizedString(renew_until, &localTimeStr);
969*7f2fe78bSCy Schubert             DurationToString(renew_until - now, &durationStr);
970*7f2fe78bSCy Schubert             if (localTimeStr && durationStr) {
971*7f2fe78bSCy Schubert                 _snprintf(tempStr, MAX_DURATION_STR, "%s %s", localTimeStr, durationStr);
972*7f2fe78bSCy Schubert                 tempStr[MAX_DURATION_STR] = 0;
973*7f2fe78bSCy Schubert                 list.SetItemText(iItem, iSubItem++, tempStr);
974*7f2fe78bSCy Schubert             }
975*7f2fe78bSCy Schubert         } else {
976*7f2fe78bSCy Schubert             list.SetItemText(iItem, iSubItem++, "Not renewable");
977*7f2fe78bSCy Schubert         }
978*7f2fe78bSCy Schubert     }
979*7f2fe78bSCy Schubert     if (sm_viewColumns[VALID_UNTIL].m_enabled) {
980*7f2fe78bSCy Schubert         if (valid_until == 0) {
981*7f2fe78bSCy Schubert             list.SetItemText(iItem, iSubItem++, "Unknown");
982*7f2fe78bSCy Schubert         } else if (valid_until < now) {
983*7f2fe78bSCy Schubert             list.SetItemText(iItem, iSubItem++, "Expired");
984*7f2fe78bSCy Schubert         } else {
985*7f2fe78bSCy Schubert             TimestampToLocalizedString(valid_until, &localTimeStr);
986*7f2fe78bSCy Schubert             DurationToString(valid_until - now, &durationStr);
987*7f2fe78bSCy Schubert             if (localTimeStr && durationStr) {
988*7f2fe78bSCy Schubert                 _snprintf(tempStr, MAX_DURATION_STR, "%s %s", localTimeStr, durationStr);
989*7f2fe78bSCy Schubert                 tempStr[MAX_DURATION_STR] = 0;
990*7f2fe78bSCy Schubert                 list.SetItemText(iItem, iSubItem++, tempStr);
991*7f2fe78bSCy Schubert             }
992*7f2fe78bSCy Schubert         }
993*7f2fe78bSCy Schubert     }
994*7f2fe78bSCy Schubert 
995*7f2fe78bSCy Schubert     if (sm_viewColumns[ENCRYPTION_TYPE].m_enabled) {
996*7f2fe78bSCy Schubert         list.SetItemText(iItem, iSubItem++, encTypes);
997*7f2fe78bSCy Schubert     }
998*7f2fe78bSCy Schubert     if (sm_viewColumns[TICKET_FLAGS].m_enabled) {
999*7f2fe78bSCy Schubert         krb5TicketFlagsToString(flags, &flagsStr);
1000*7f2fe78bSCy Schubert         list.SetItemText(iItem, iSubItem++, flagsStr);
1001*7f2fe78bSCy Schubert     }
1002*7f2fe78bSCy Schubert     if (sm_viewColumns[CACHE_NAME].m_enabled) {
1003*7f2fe78bSCy Schubert         list.SetItemText(iItem, iSubItem++, ccache_name);
1004*7f2fe78bSCy Schubert     }
1005*7f2fe78bSCy Schubert     if (flagsStr)
1006*7f2fe78bSCy Schubert         free(flagsStr);
1007*7f2fe78bSCy Schubert     if (localTimeStr)
1008*7f2fe78bSCy Schubert         free(localTimeStr);
1009*7f2fe78bSCy Schubert     if (durationStr)
1010*7f2fe78bSCy Schubert         free(durationStr);
1011*7f2fe78bSCy Schubert }
1012*7f2fe78bSCy Schubert 
IsExpanded(TICKETINFO * info)1013*7f2fe78bSCy Schubert BOOL CLeashView::IsExpanded(TICKETINFO *info)
1014*7f2fe78bSCy Schubert {
1015*7f2fe78bSCy Schubert     CCacheDisplayData **pElem = FindCCacheDisplayData(info->ccache_name,
1016*7f2fe78bSCy Schubert                                                       &m_ccacheDisplay);
1017*7f2fe78bSCy Schubert     return (pElem && (*pElem)->m_expanded) ? TRUE : FALSE;
1018*7f2fe78bSCy Schubert }
1019*7f2fe78bSCy Schubert 
IsExpired(TICKETINFO * info)1020*7f2fe78bSCy Schubert BOOL CLeashView::IsExpired(TICKETINFO *info)
1021*7f2fe78bSCy Schubert {
1022*7f2fe78bSCy Schubert     return LeashTime() > info->valid_until ? TRUE : FALSE;
1023*7f2fe78bSCy Schubert }
1024*7f2fe78bSCy Schubert 
IsExpired(TicketList * ticket)1025*7f2fe78bSCy Schubert BOOL CLeashView::IsExpired(TicketList *ticket)
1026*7f2fe78bSCy Schubert {
1027*7f2fe78bSCy Schubert     return LeashTime() > ticket->valid_until ? TRUE : FALSE;
1028*7f2fe78bSCy Schubert }
1029*7f2fe78bSCy Schubert 
1030*7f2fe78bSCy Schubert CCacheDisplayData *
FindCCacheDisplayElem(CCacheDisplayData * pElem,int itemIndex)1031*7f2fe78bSCy Schubert FindCCacheDisplayElem(CCacheDisplayData *pElem, int itemIndex)
1032*7f2fe78bSCy Schubert {
1033*7f2fe78bSCy Schubert     while (pElem != NULL) {
1034*7f2fe78bSCy Schubert         if (pElem->m_index == itemIndex)
1035*7f2fe78bSCy Schubert             return pElem;
1036*7f2fe78bSCy Schubert         pElem = pElem->m_next;
1037*7f2fe78bSCy Schubert     }
1038*7f2fe78bSCy Schubert     return NULL;
1039*7f2fe78bSCy Schubert }
1040*7f2fe78bSCy Schubert 
OnUpdateDisplay()1041*7f2fe78bSCy Schubert VOID CLeashView::OnUpdateDisplay()
1042*7f2fe78bSCy Schubert {
1043*7f2fe78bSCy Schubert     CListCtrl& list = GetListCtrl();
1044*7f2fe78bSCy Schubert     // @TODO: there is probably a more sensible place to initialize these...
1045*7f2fe78bSCy Schubert     if ((m_BaseFont == NULL) && (list.GetFont())) {
1046*7f2fe78bSCy Schubert         m_BaseFont = *list.GetFont();
1047*7f2fe78bSCy Schubert         m_BoldFont = CreateBoldFont(m_BaseFont);
1048*7f2fe78bSCy Schubert         m_ItalicFont = CreateItalicFont(m_BaseFont);
1049*7f2fe78bSCy Schubert         m_BoldItalicFont = CreateBoldItalicFont(m_BaseFont);
1050*7f2fe78bSCy Schubert     }
1051*7f2fe78bSCy Schubert     // Determine currently focused item
1052*7f2fe78bSCy Schubert     int focusItem = list.GetNextItem(-1, LVNI_FOCUSED);
1053*7f2fe78bSCy Schubert     CCacheDisplayData *elem = m_ccacheDisplay;
1054*7f2fe78bSCy Schubert     while (elem) {
1055*7f2fe78bSCy Schubert         if (focusItem >= elem->m_index) {
1056*7f2fe78bSCy Schubert             elem->m_focus = focusItem - elem->m_index;
1057*7f2fe78bSCy Schubert             focusItem = -1;
1058*7f2fe78bSCy Schubert         } else {
1059*7f2fe78bSCy Schubert             elem->m_focus = -1;
1060*7f2fe78bSCy Schubert         }
1061*7f2fe78bSCy Schubert         elem = elem->m_next;
1062*7f2fe78bSCy Schubert     }
1063*7f2fe78bSCy Schubert 
1064*7f2fe78bSCy Schubert     list.DeleteAllItems();
1065*7f2fe78bSCy Schubert     ModifyStyle(LVS_TYPEMASK, LVS_REPORT);
1066*7f2fe78bSCy Schubert 	UpdateWindow();
1067*7f2fe78bSCy Schubert     // Delete all of the columns.
1068*7f2fe78bSCy Schubert     while (list.DeleteColumn(0));
1069*7f2fe78bSCy Schubert 
1070*7f2fe78bSCy Schubert     list.SetImageList(&m_imageList, LVSIL_SMALL);
1071*7f2fe78bSCy Schubert 
1072*7f2fe78bSCy Schubert     // Reconstruct based on current options
1073*7f2fe78bSCy Schubert     int columnIndex = 0;
1074*7f2fe78bSCy Schubert     int itemIndex = 0;
1075*7f2fe78bSCy Schubert     for (int i = 0; i < NUM_VIEW_COLUMNS; i++) {
1076*7f2fe78bSCy Schubert         ViewColumnInfo &info = sm_viewColumns[i];
1077*7f2fe78bSCy Schubert         if (info.m_enabled) {
1078*7f2fe78bSCy Schubert             list.InsertColumn(columnIndex++,
1079*7f2fe78bSCy Schubert                 (info.m_name), // @LOCALIZEME!
1080*7f2fe78bSCy Schubert                 LVCFMT_LEFT,
1081*7f2fe78bSCy Schubert                 info.m_columnWidth,
1082*7f2fe78bSCy Schubert                 itemIndex++);
1083*7f2fe78bSCy Schubert         }
1084*7f2fe78bSCy Schubert     }
1085*7f2fe78bSCy Schubert 
1086*7f2fe78bSCy Schubert     INT ticketIconStatusKrb5;
1087*7f2fe78bSCy Schubert     INT ticketIconStatus_SelectedKrb5;
1088*7f2fe78bSCy Schubert     INT iconStatusKrb5;
1089*7f2fe78bSCy Schubert 
1090*7f2fe78bSCy Schubert     if (WaitForSingleObject( ticketinfo.lockObj, 100 ) != WAIT_OBJECT_0)
1091*7f2fe78bSCy Schubert         throw("Unable to lock ticketinfo");
1092*7f2fe78bSCy Schubert 
1093*7f2fe78bSCy Schubert     // Get Kerb 5 tickets in list
1094*7f2fe78bSCy Schubert     LeashKRB5ListDefaultTickets(&ticketinfo.Krb5);
1095*7f2fe78bSCy Schubert     if (CLeashApp::m_hKrb5DLL && !CLeashApp::m_krbv5_profile)
1096*7f2fe78bSCy Schubert     {
1097*7f2fe78bSCy Schubert         CHAR confname[MAX_PATH];
1098*7f2fe78bSCy Schubert         if (CLeashApp::GetProfileFile(confname, sizeof(confname)))
1099*7f2fe78bSCy Schubert         {
1100*7f2fe78bSCy Schubert             AfxMessageBox("Can't locate Kerberos Five Config. file!",
1101*7f2fe78bSCy Schubert                         MB_OK|MB_ICONSTOP);
1102*7f2fe78bSCy Schubert         }
1103*7f2fe78bSCy Schubert 
1104*7f2fe78bSCy Schubert         const char *filenames[2];
1105*7f2fe78bSCy Schubert         filenames[0] = confname;
1106*7f2fe78bSCy Schubert         filenames[1] = NULL;
1107*7f2fe78bSCy Schubert         pprofile_init(filenames, &CLeashApp::m_krbv5_profile);
1108*7f2fe78bSCy Schubert     }
1109*7f2fe78bSCy Schubert 
1110*7f2fe78bSCy Schubert     /*
1111*7f2fe78bSCy Schubert      * Update Ticket Status for Krb5 so that we may use their state
1112*7f2fe78bSCy Schubert      * to select the appropriate Icon for the Parent Node
1113*7f2fe78bSCy Schubert      */
1114*7f2fe78bSCy Schubert 
1115*7f2fe78bSCy Schubert     /* Krb5 */
1116*7f2fe78bSCy Schubert     UpdateTicketTime(ticketinfo.Krb5);
1117*7f2fe78bSCy Schubert     m_ticketStatusKrb5 = GetLowTicketStatus(5);
1118*7f2fe78bSCy Schubert     if ((!ticketinfo.Krb5.btickets) ||
1119*7f2fe78bSCy Schubert         EXPIRED_TICKETS == ticketinfo.Krb5.btickets ||
1120*7f2fe78bSCy Schubert         m_ticketStatusKrb5 == ZERO_MINUTES_LEFT)
1121*7f2fe78bSCy Schubert     {
1122*7f2fe78bSCy Schubert         ticketIconStatusKrb5 = EXPIRED_CLOCK;
1123*7f2fe78bSCy Schubert         ticketIconStatus_SelectedKrb5 = EXPIRED_CLOCK;
1124*7f2fe78bSCy Schubert         iconStatusKrb5 = EXPIRED_TICKET;
1125*7f2fe78bSCy Schubert     }
1126*7f2fe78bSCy Schubert     else if (TICKETS_LOW == ticketinfo.Krb5.btickets ||
1127*7f2fe78bSCy Schubert              m_ticketStatusKrb5 == FIVE_MINUTES_LEFT ||
1128*7f2fe78bSCy Schubert              m_ticketStatusKrb5 == TEN_MINUTES_LEFT ||
1129*7f2fe78bSCy Schubert              m_ticketStatusKrb5 == FIFTEEN_MINUTES_LEFT)
1130*7f2fe78bSCy Schubert     {
1131*7f2fe78bSCy Schubert         ticketIconStatusKrb5 = LOW_CLOCK;
1132*7f2fe78bSCy Schubert         ticketIconStatus_SelectedKrb5 = LOW_CLOCK;
1133*7f2fe78bSCy Schubert         iconStatusKrb5 = LOW_TICKET;
1134*7f2fe78bSCy Schubert     }
1135*7f2fe78bSCy Schubert     else if ( CLeashApp::m_hKrb5DLL )
1136*7f2fe78bSCy Schubert     {
1137*7f2fe78bSCy Schubert         ticketIconStatusKrb5 = ACTIVE_CLOCK;
1138*7f2fe78bSCy Schubert         ticketIconStatus_SelectedKrb5 = ACTIVE_CLOCK;
1139*7f2fe78bSCy Schubert         iconStatusKrb5 = ACTIVE_TICKET;
1140*7f2fe78bSCy Schubert     } else
1141*7f2fe78bSCy Schubert     {
1142*7f2fe78bSCy Schubert         ticketIconStatusKrb5 = EXPIRED_CLOCK;
1143*7f2fe78bSCy Schubert         ticketIconStatus_SelectedKrb5 = EXPIRED_CLOCK;
1144*7f2fe78bSCy Schubert         iconStatusKrb5 = TICKET_NOT_INSTALLED;
1145*7f2fe78bSCy Schubert     }
1146*7f2fe78bSCy Schubert 
1147*7f2fe78bSCy Schubert     int trayIcon = NONE_PARENT_NODE;
1148*7f2fe78bSCy Schubert     if (CLeashApp::m_hKrb5DLL && ticketinfo.Krb5.btickets) {
1149*7f2fe78bSCy Schubert         switch ( iconStatusKrb5 ) {
1150*7f2fe78bSCy Schubert         case ACTIVE_TICKET:
1151*7f2fe78bSCy Schubert             trayIcon = ACTIVE_PARENT_NODE;
1152*7f2fe78bSCy Schubert             break;
1153*7f2fe78bSCy Schubert         case LOW_TICKET:
1154*7f2fe78bSCy Schubert             trayIcon = LOW_PARENT_NODE;
1155*7f2fe78bSCy Schubert             break;
1156*7f2fe78bSCy Schubert         case EXPIRED_TICKET:
1157*7f2fe78bSCy Schubert             trayIcon = EXPIRED_PARENT_NODE;
1158*7f2fe78bSCy Schubert             break;
1159*7f2fe78bSCy Schubert         }
1160*7f2fe78bSCy Schubert     }
1161*7f2fe78bSCy Schubert     SetTrayIcon(NIM_MODIFY, trayIcon);
1162*7f2fe78bSCy Schubert 
1163*7f2fe78bSCy Schubert     CCacheDisplayData* prevCCacheDisplay = m_ccacheDisplay;
1164*7f2fe78bSCy Schubert     m_ccacheDisplay = NULL;
1165*7f2fe78bSCy Schubert 
1166*7f2fe78bSCy Schubert     const char *def_ccache_name = ticketinfo.Krb5.ccache_name;
1167*7f2fe78bSCy Schubert     TICKETINFO *principallist = NULL;
1168*7f2fe78bSCy Schubert     LeashKRB5ListAllTickets(&principallist);
1169*7f2fe78bSCy Schubert     int iItem = 0;
1170*7f2fe78bSCy Schubert     TicketList* tempList;
1171*7f2fe78bSCy Schubert     TICKETINFO *principal = principallist;
1172*7f2fe78bSCy Schubert     while (principal != NULL) {
1173*7f2fe78bSCy Schubert         CCacheDisplayData **pOldElem;
1174*7f2fe78bSCy Schubert         pOldElem = FindCCacheDisplayData(principal->ccache_name,
1175*7f2fe78bSCy Schubert                                          &prevCCacheDisplay);
1176*7f2fe78bSCy Schubert         if (pOldElem) {
1177*7f2fe78bSCy Schubert             // remove from old list
1178*7f2fe78bSCy Schubert             elem = *pOldElem;
1179*7f2fe78bSCy Schubert             *pOldElem = elem->m_next;
1180*7f2fe78bSCy Schubert             elem->m_next = NULL;
1181*7f2fe78bSCy Schubert         } else {
1182*7f2fe78bSCy Schubert             elem = new CCacheDisplayData(principal->ccache_name);
1183*7f2fe78bSCy Schubert         }
1184*7f2fe78bSCy Schubert         elem->m_isDefault = def_ccache_name &&
1185*7f2fe78bSCy Schubert                             (strcmp(def_ccache_name, elem->m_ccacheName) == 0);
1186*7f2fe78bSCy Schubert         elem->m_isRenewable = principal->renew_until != 0;
1187*7f2fe78bSCy Schubert 
1188*7f2fe78bSCy Schubert         elem->m_next = m_ccacheDisplay;
1189*7f2fe78bSCy Schubert         m_ccacheDisplay = elem;
1190*7f2fe78bSCy Schubert         elem->m_index = iItem;
1191*7f2fe78bSCy Schubert 
1192*7f2fe78bSCy Schubert         AddDisplayItem(list,
1193*7f2fe78bSCy Schubert                        elem,
1194*7f2fe78bSCy Schubert                        iItem++,
1195*7f2fe78bSCy Schubert                        principal->principal,
1196*7f2fe78bSCy Schubert                        principal->issued,
1197*7f2fe78bSCy Schubert                        principal->valid_until,
1198*7f2fe78bSCy Schubert                        principal->renew_until,
1199*7f2fe78bSCy Schubert                        "",
1200*7f2fe78bSCy Schubert                        principal->flags,
1201*7f2fe78bSCy Schubert                        principal->ccache_name);
1202*7f2fe78bSCy Schubert         if (elem->m_expanded) {
1203*7f2fe78bSCy Schubert             for (tempList = principal->ticket_list;
1204*7f2fe78bSCy Schubert                  tempList != NULL;
1205*7f2fe78bSCy Schubert                  tempList = tempList->next) {
1206*7f2fe78bSCy Schubert                 AddDisplayItem(list,
1207*7f2fe78bSCy Schubert                                elem,
1208*7f2fe78bSCy Schubert                                iItem++,
1209*7f2fe78bSCy Schubert                                tempList->service,
1210*7f2fe78bSCy Schubert                                tempList->issued,
1211*7f2fe78bSCy Schubert                                tempList->valid_until,
1212*7f2fe78bSCy Schubert                                tempList->renew_until,
1213*7f2fe78bSCy Schubert                                tempList->encTypes,
1214*7f2fe78bSCy Schubert                                tempList->flags,
1215*7f2fe78bSCy Schubert                                principal->ccache_name);
1216*7f2fe78bSCy Schubert             }
1217*7f2fe78bSCy Schubert         }
1218*7f2fe78bSCy Schubert         if ((elem->m_focus >= 0) &&
1219*7f2fe78bSCy Schubert             (iItem > elem->m_index + elem->m_focus)) {
1220*7f2fe78bSCy Schubert             list.SetItemState(elem->m_index + elem->m_focus, LVIS_FOCUSED,
1221*7f2fe78bSCy Schubert                               LVIS_FOCUSED);
1222*7f2fe78bSCy Schubert         }
1223*7f2fe78bSCy Schubert         if (elem->m_selected)
1224*7f2fe78bSCy Schubert             list.SetItemState(elem->m_index, LVIS_SELECTED, LVIS_SELECTED);
1225*7f2fe78bSCy Schubert 
1226*7f2fe78bSCy Schubert         principal = principal->next;
1227*7f2fe78bSCy Schubert     }
1228*7f2fe78bSCy Schubert 
1229*7f2fe78bSCy Schubert     // create list item font data array
1230*7f2fe78bSCy Schubert     if (m_aListItemInfo != NULL)
1231*7f2fe78bSCy Schubert         delete[] m_aListItemInfo;
1232*7f2fe78bSCy Schubert     m_aListItemInfo = new ListItemInfo[iItem];
1233*7f2fe78bSCy Schubert     iItem = 0;
1234*7f2fe78bSCy Schubert     for (principal = principallist; principal != NULL;
1235*7f2fe78bSCy Schubert          principal = principal->next) {
1236*7f2fe78bSCy Schubert         //
1237*7f2fe78bSCy Schubert         HFONT font, durationFont;
1238*7f2fe78bSCy Schubert         elem = FindCCacheDisplayElem(m_ccacheDisplay, iItem);
1239*7f2fe78bSCy Schubert         if (elem != NULL && elem->m_isDefault) {
1240*7f2fe78bSCy Schubert             font = m_BoldFont;
1241*7f2fe78bSCy Schubert             durationFont = IsExpired(principal) ? m_BoldItalicFont : m_BoldFont;
1242*7f2fe78bSCy Schubert         } else {
1243*7f2fe78bSCy Schubert             font = m_BaseFont;
1244*7f2fe78bSCy Schubert             durationFont = IsExpired(principal) ? m_ItalicFont : m_BaseFont;
1245*7f2fe78bSCy Schubert         }
1246*7f2fe78bSCy Schubert         m_aListItemInfo[iItem].m_font = font;
1247*7f2fe78bSCy Schubert         m_aListItemInfo[iItem++].m_durationFont = durationFont;
1248*7f2fe78bSCy Schubert 
1249*7f2fe78bSCy Schubert         if (IsExpanded(principal)) {
1250*7f2fe78bSCy Schubert             for (TicketList *ticket = principal->ticket_list;
1251*7f2fe78bSCy Schubert                  ticket != NULL; ticket = ticket->next) {
1252*7f2fe78bSCy Schubert                 font = m_BaseFont;
1253*7f2fe78bSCy Schubert                 durationFont = IsExpired(ticket) ? m_ItalicFont : m_BaseFont;
1254*7f2fe78bSCy Schubert                 m_aListItemInfo[iItem].m_font = font;
1255*7f2fe78bSCy Schubert                 m_aListItemInfo[iItem++].m_durationFont = durationFont;
1256*7f2fe78bSCy Schubert             }
1257*7f2fe78bSCy Schubert         }
1258*7f2fe78bSCy Schubert     }
1259*7f2fe78bSCy Schubert 
1260*7f2fe78bSCy Schubert     // delete ccache items that no longer exist
1261*7f2fe78bSCy Schubert     while (prevCCacheDisplay != NULL) {
1262*7f2fe78bSCy Schubert         CCacheDisplayData *next = prevCCacheDisplay->m_next;
1263*7f2fe78bSCy Schubert         delete prevCCacheDisplay;
1264*7f2fe78bSCy Schubert         prevCCacheDisplay = next;
1265*7f2fe78bSCy Schubert     }
1266*7f2fe78bSCy Schubert 
1267*7f2fe78bSCy Schubert     LeashKRB5FreeTicketInfo(&ticketinfo.Krb5);
1268*7f2fe78bSCy Schubert     LeashKRB5FreeTickets(&principallist);
1269*7f2fe78bSCy Schubert 
1270*7f2fe78bSCy Schubert     ReleaseMutex(ticketinfo.lockObj);
1271*7f2fe78bSCy Schubert }
1272*7f2fe78bSCy Schubert 
OnSynTime()1273*7f2fe78bSCy Schubert VOID CLeashView::OnSynTime()
1274*7f2fe78bSCy Schubert {
1275*7f2fe78bSCy Schubert     LONG returnValue;
1276*7f2fe78bSCy Schubert     returnValue = pLeash_timesync(1);
1277*7f2fe78bSCy Schubert }
1278*7f2fe78bSCy Schubert 
OnActivateView(BOOL bActivate,CView * pActivateView,CView * pDeactiveView)1279*7f2fe78bSCy Schubert VOID CLeashView::OnActivateView(BOOL bActivate, CView* pActivateView,
1280*7f2fe78bSCy Schubert                                 CView* pDeactiveView)
1281*7f2fe78bSCy Schubert {
1282*7f2fe78bSCy Schubert     UINT check = NULL;
1283*7f2fe78bSCy Schubert 
1284*7f2fe78bSCy Schubert     if (m_alreadyPlayed)
1285*7f2fe78bSCy Schubert     {
1286*7f2fe78bSCy Schubert         CListView::OnActivateView(bActivate, pActivateView, pDeactiveView);
1287*7f2fe78bSCy Schubert         return;
1288*7f2fe78bSCy Schubert     }
1289*7f2fe78bSCy Schubert 
1290*7f2fe78bSCy Schubert     // The following code has put here because at the time
1291*7f2fe78bSCy Schubert     // 'checking and unchecking' a menuitem with the
1292*7f2fe78bSCy Schubert     // 'OnUpdate.....(CCmdUI* pCmdUI) functions' were unreliable
1293*7f2fe78bSCy Schubert     // in CLeashView -->> Better done in CMainFrame
1294*7f2fe78bSCy Schubert     if( CLeashApp::m_hProgram != 0 )
1295*7f2fe78bSCy Schubert     {
1296*7f2fe78bSCy Schubert         m_hMenu = ::GetMenu(CLeashApp::m_hProgram);
1297*7f2fe78bSCy Schubert     } else {
1298*7f2fe78bSCy Schubert         return;
1299*7f2fe78bSCy Schubert     }
1300*7f2fe78bSCy Schubert 
1301*7f2fe78bSCy Schubert     if (m_hMenu) {
1302*7f2fe78bSCy Schubert         if (!m_largeIcons)
1303*7f2fe78bSCy Schubert             check = CheckMenuItem(m_hMenu, ID_LARGE_ICONS, MF_CHECKED);
1304*7f2fe78bSCy Schubert         else
1305*7f2fe78bSCy Schubert             check = CheckMenuItem(m_hMenu, ID_LARGE_ICONS, MF_UNCHECKED);
1306*7f2fe78bSCy Schubert 
1307*7f2fe78bSCy Schubert         if( check != MF_CHECKED || check != MF_UNCHECKED )
1308*7f2fe78bSCy Schubert         {
1309*7f2fe78bSCy Schubert             m_debugStartUp = 1;
1310*7f2fe78bSCy Schubert         }
1311*7f2fe78bSCy Schubert 
1312*7f2fe78bSCy Schubert         if (!m_destroyTicketsOnExit)
1313*7f2fe78bSCy Schubert             check = CheckMenuItem(m_hMenu, ID_KILL_TIX_ONEXIT, MF_UNCHECKED);
1314*7f2fe78bSCy Schubert         else
1315*7f2fe78bSCy Schubert             check = CheckMenuItem(m_hMenu, ID_KILL_TIX_ONEXIT, MF_CHECKED);
1316*7f2fe78bSCy Schubert 
1317*7f2fe78bSCy Schubert         if (!m_upperCaseRealm)
1318*7f2fe78bSCy Schubert             check = CheckMenuItem(m_hMenu, ID_UPPERCASE_REALM, MF_UNCHECKED);
1319*7f2fe78bSCy Schubert         else
1320*7f2fe78bSCy Schubert             check = CheckMenuItem(m_hMenu, ID_UPPERCASE_REALM, MF_CHECKED);
1321*7f2fe78bSCy Schubert 
1322*7f2fe78bSCy Schubert         for (int i=0; i<NUM_VIEW_COLUMNS; i++) {
1323*7f2fe78bSCy Schubert             ViewColumnInfo &info = sm_viewColumns[i];
1324*7f2fe78bSCy Schubert             if (info.m_id >= 0)
1325*7f2fe78bSCy Schubert                 CheckMenuItem(m_hMenu, info.m_id,
1326*7f2fe78bSCy Schubert                               info.m_enabled ? MF_CHECKED : MF_UNCHECKED);
1327*7f2fe78bSCy Schubert         }
1328*7f2fe78bSCy Schubert 
1329*7f2fe78bSCy Schubert         if (!m_lowTicketAlarm)
1330*7f2fe78bSCy Schubert             CheckMenuItem(m_hMenu, ID_LOW_TICKET_ALARM, MF_UNCHECKED);
1331*7f2fe78bSCy Schubert         else
1332*7f2fe78bSCy Schubert             CheckMenuItem(m_hMenu, ID_LOW_TICKET_ALARM, MF_CHECKED);
1333*7f2fe78bSCy Schubert 
1334*7f2fe78bSCy Schubert         if (!m_autoRenewTickets)
1335*7f2fe78bSCy Schubert             CheckMenuItem(m_hMenu, ID_AUTO_RENEW, MF_UNCHECKED);
1336*7f2fe78bSCy Schubert         else
1337*7f2fe78bSCy Schubert             CheckMenuItem(m_hMenu, ID_AUTO_RENEW, MF_CHECKED);
1338*7f2fe78bSCy Schubert 
1339*7f2fe78bSCy Schubert         m_debugWindow = m_pApp->GetProfileInt("Settings", "DebugWindow", 0);
1340*7f2fe78bSCy Schubert         if (!m_debugWindow)
1341*7f2fe78bSCy Schubert             check = CheckMenuItem(m_hMenu, ID_DEBUG_MODE, MF_UNCHECKED);
1342*7f2fe78bSCy Schubert         else
1343*7f2fe78bSCy Schubert             check = CheckMenuItem(m_hMenu, ID_DEBUG_MODE, MF_CHECKED);
1344*7f2fe78bSCy Schubert     }
1345*7f2fe78bSCy Schubert     m_lowTicketAlarmSound = !!m_lowTicketAlarm;
1346*7f2fe78bSCy Schubert     m_alreadyPlayed = TRUE;
1347*7f2fe78bSCy Schubert     if (m_pApp)
1348*7f2fe78bSCy Schubert     {
1349*7f2fe78bSCy Schubert         m_debugWindow = m_pApp->GetProfileInt("Settings", "DebugWindow", 0);
1350*7f2fe78bSCy Schubert 
1351*7f2fe78bSCy Schubert         if (m_hMenu)
1352*7f2fe78bSCy Schubert         {
1353*7f2fe78bSCy Schubert             if (!m_debugWindow)
1354*7f2fe78bSCy Schubert             {
1355*7f2fe78bSCy Schubert                 CheckMenuItem(m_hMenu, ID_DEBUG_MODE, MF_UNCHECKED);
1356*7f2fe78bSCy Schubert             }
1357*7f2fe78bSCy Schubert             else
1358*7f2fe78bSCy Schubert             {
1359*7f2fe78bSCy Schubert                 CheckMenuItem(m_hMenu, ID_DEBUG_MODE, MF_CHECKED);
1360*7f2fe78bSCy Schubert             }
1361*7f2fe78bSCy Schubert         }
1362*7f2fe78bSCy Schubert     }
1363*7f2fe78bSCy Schubert     else
1364*7f2fe78bSCy Schubert     {
1365*7f2fe78bSCy Schubert         ApplicationInfoMissingMsg();
1366*7f2fe78bSCy Schubert     }
1367*7f2fe78bSCy Schubert 
1368*7f2fe78bSCy Schubert     m_alreadyPlayed = TRUE;
1369*7f2fe78bSCy Schubert 
1370*7f2fe78bSCy Schubert     if (m_debugStartUp)
1371*7f2fe78bSCy Schubert     {
1372*7f2fe78bSCy Schubert         OnDebugMode();
1373*7f2fe78bSCy Schubert     }
1374*7f2fe78bSCy Schubert 
1375*7f2fe78bSCy Schubert     m_debugStartUp = FALSE;
1376*7f2fe78bSCy Schubert 
1377*7f2fe78bSCy Schubert     CListView::OnActivateView(bActivate, pActivateView, pDeactiveView);
1378*7f2fe78bSCy Schubert }
1379*7f2fe78bSCy Schubert 
1380*7f2fe78bSCy Schubert ////@#+Is this KRB4 only?
OnDebugMode()1381*7f2fe78bSCy Schubert VOID CLeashView::OnDebugMode()
1382*7f2fe78bSCy Schubert {
1383*7f2fe78bSCy Schubert     if (!m_pDebugWindow)
1384*7f2fe78bSCy Schubert     {
1385*7f2fe78bSCy Schubert         AfxMessageBox("There is a problem with the Leash Debug Window!",
1386*7f2fe78bSCy Schubert                    MB_OK|MB_ICONSTOP);
1387*7f2fe78bSCy Schubert         return;
1388*7f2fe78bSCy Schubert     }
1389*7f2fe78bSCy Schubert 
1390*7f2fe78bSCy Schubert 
1391*7f2fe78bSCy Schubert     // Check all possible 'KRB' system variables, then delete debug file
1392*7f2fe78bSCy Schubert     CHAR*  Env[] = {"TEMP", "TMP", "HOME", NULL};
1393*7f2fe78bSCy Schubert     CHAR** pEnv = Env;
1394*7f2fe78bSCy Schubert     CHAR debugFilePath[MAX_PATH];
1395*7f2fe78bSCy Schubert     *debugFilePath = 0;
1396*7f2fe78bSCy Schubert 
1397*7f2fe78bSCy Schubert     while (*pEnv)
1398*7f2fe78bSCy Schubert     {
1399*7f2fe78bSCy Schubert         CHAR* ptestenv = getenv(*pEnv);
1400*7f2fe78bSCy Schubert         if (ptestenv)
1401*7f2fe78bSCy Schubert         {
1402*7f2fe78bSCy Schubert             // reset debug file
1403*7f2fe78bSCy Schubert             strcpy(debugFilePath, ptestenv);
1404*7f2fe78bSCy Schubert             strcat(debugFilePath, "\\LshDebug.log");
1405*7f2fe78bSCy Schubert             remove(debugFilePath);
1406*7f2fe78bSCy Schubert             break;
1407*7f2fe78bSCy Schubert         }
1408*7f2fe78bSCy Schubert 
1409*7f2fe78bSCy Schubert         pEnv++;
1410*7f2fe78bSCy Schubert     }
1411*7f2fe78bSCy Schubert 
1412*7f2fe78bSCy Schubert     if (!m_debugStartUp)
1413*7f2fe78bSCy Schubert     {
1414*7f2fe78bSCy Schubert         if (m_debugWindow%2 == 0)
1415*7f2fe78bSCy Schubert             m_debugWindow = ON;
1416*7f2fe78bSCy Schubert         else
1417*7f2fe78bSCy Schubert             m_debugWindow = OFF;
1418*7f2fe78bSCy Schubert     }
1419*7f2fe78bSCy Schubert 
1420*7f2fe78bSCy Schubert     if (!m_pApp)
1421*7f2fe78bSCy Schubert     {
1422*7f2fe78bSCy Schubert         ApplicationInfoMissingMsg();
1423*7f2fe78bSCy Schubert     }
1424*7f2fe78bSCy Schubert     else if (!m_debugWindow)
1425*7f2fe78bSCy Schubert     {
1426*7f2fe78bSCy Schubert         if (m_hMenu)
1427*7f2fe78bSCy Schubert             CheckMenuItem(m_hMenu, ID_DEBUG_MODE, MF_UNCHECKED);
1428*7f2fe78bSCy Schubert 
1429*7f2fe78bSCy Schubert         m_pApp->WriteProfileInt("Settings", "DebugWindow", FALSE_FLAG);
1430*7f2fe78bSCy Schubert         m_pDebugWindow->DestroyWindow();
1431*7f2fe78bSCy Schubert         return;
1432*7f2fe78bSCy Schubert     }
1433*7f2fe78bSCy Schubert     else
1434*7f2fe78bSCy Schubert     {
1435*7f2fe78bSCy Schubert         if (m_hMenu)
1436*7f2fe78bSCy Schubert             CheckMenuItem(m_hMenu, ID_DEBUG_MODE, MF_CHECKED);
1437*7f2fe78bSCy Schubert 
1438*7f2fe78bSCy Schubert         m_pApp->WriteProfileInt("Settings", "DebugWindow", TRUE_FLAG);
1439*7f2fe78bSCy Schubert     }
1440*7f2fe78bSCy Schubert 
1441*7f2fe78bSCy Schubert     // Creates the Debug dialog if not created already
1442*7f2fe78bSCy Schubert     if (m_pDebugWindow->GetSafeHwnd() == 0)
1443*7f2fe78bSCy Schubert     { // displays the Debug Window
1444*7f2fe78bSCy Schubert         m_pDebugWindow->Create(debugFilePath);
1445*7f2fe78bSCy Schubert     }
1446*7f2fe78bSCy Schubert }
1447*7f2fe78bSCy Schubert 
ToggleViewColumn(eViewColumn viewOption)1448*7f2fe78bSCy Schubert void CLeashView::ToggleViewColumn(eViewColumn viewOption)
1449*7f2fe78bSCy Schubert {
1450*7f2fe78bSCy Schubert     if ((viewOption < 0) || (viewOption >= NUM_VIEW_COLUMNS)) {
1451*7f2fe78bSCy Schubert         //LeashWarn("ToggleViewColumn(): invalid view option index %i", viewOption);
1452*7f2fe78bSCy Schubert         return;
1453*7f2fe78bSCy Schubert     }
1454*7f2fe78bSCy Schubert     ViewColumnInfo &info = sm_viewColumns[viewOption];
1455*7f2fe78bSCy Schubert     info.m_enabled = !info.m_enabled;
1456*7f2fe78bSCy Schubert     if (m_pApp)
1457*7f2fe78bSCy Schubert         m_pApp->WriteProfileInt("Settings", info.m_name, info.m_enabled);
1458*7f2fe78bSCy Schubert     // Don't update display immediately; wait for next idle so our
1459*7f2fe78bSCy Schubert     // checkbox controls will be more responsive
1460*7f2fe78bSCy Schubert     CLeashApp::m_bUpdateDisplay = TRUE;
1461*7f2fe78bSCy Schubert }
1462*7f2fe78bSCy Schubert 
OnRenewableUntil()1463*7f2fe78bSCy Schubert VOID CLeashView::OnRenewableUntil()
1464*7f2fe78bSCy Schubert {
1465*7f2fe78bSCy Schubert     ToggleViewColumn(RENEWABLE_UNTIL);
1466*7f2fe78bSCy Schubert }
1467*7f2fe78bSCy Schubert 
OnUpdateRenewableUntil(CCmdUI * pCmdUI)1468*7f2fe78bSCy Schubert VOID CLeashView::OnUpdateRenewableUntil(CCmdUI *pCmdUI)
1469*7f2fe78bSCy Schubert {
1470*7f2fe78bSCy Schubert     pCmdUI->SetCheck(sm_viewColumns[RENEWABLE_UNTIL].m_enabled);
1471*7f2fe78bSCy Schubert }
1472*7f2fe78bSCy Schubert 
OnShowTicketFlags()1473*7f2fe78bSCy Schubert VOID CLeashView::OnShowTicketFlags()
1474*7f2fe78bSCy Schubert {
1475*7f2fe78bSCy Schubert     ToggleViewColumn(TICKET_FLAGS);
1476*7f2fe78bSCy Schubert }
1477*7f2fe78bSCy Schubert 
OnUpdateShowTicketFlags(CCmdUI * pCmdUI)1478*7f2fe78bSCy Schubert VOID CLeashView::OnUpdateShowTicketFlags(CCmdUI *pCmdUI)
1479*7f2fe78bSCy Schubert {
1480*7f2fe78bSCy Schubert     pCmdUI->SetCheck(sm_viewColumns[TICKET_FLAGS].m_enabled);
1481*7f2fe78bSCy Schubert }
1482*7f2fe78bSCy Schubert 
OnTimeIssued()1483*7f2fe78bSCy Schubert VOID CLeashView::OnTimeIssued()
1484*7f2fe78bSCy Schubert {
1485*7f2fe78bSCy Schubert     ToggleViewColumn(TIME_ISSUED);
1486*7f2fe78bSCy Schubert }
1487*7f2fe78bSCy Schubert 
OnUpdateTimeIssued(CCmdUI * pCmdUI)1488*7f2fe78bSCy Schubert VOID CLeashView::OnUpdateTimeIssued(CCmdUI *pCmdUI)
1489*7f2fe78bSCy Schubert {
1490*7f2fe78bSCy Schubert     pCmdUI->SetCheck(sm_viewColumns[TIME_ISSUED].m_enabled);
1491*7f2fe78bSCy Schubert }
1492*7f2fe78bSCy Schubert 
OnValidUntil()1493*7f2fe78bSCy Schubert VOID CLeashView::OnValidUntil()
1494*7f2fe78bSCy Schubert {
1495*7f2fe78bSCy Schubert     ToggleViewColumn(VALID_UNTIL);
1496*7f2fe78bSCy Schubert }
1497*7f2fe78bSCy Schubert 
OnUpdateValidUntil(CCmdUI * pCmdUI)1498*7f2fe78bSCy Schubert VOID CLeashView::OnUpdateValidUntil(CCmdUI *pCmdUI)
1499*7f2fe78bSCy Schubert {
1500*7f2fe78bSCy Schubert     pCmdUI->SetCheck(sm_viewColumns[VALID_UNTIL].m_enabled);
1501*7f2fe78bSCy Schubert }
1502*7f2fe78bSCy Schubert 
OnEncryptionType()1503*7f2fe78bSCy Schubert VOID CLeashView::OnEncryptionType()
1504*7f2fe78bSCy Schubert {
1505*7f2fe78bSCy Schubert     ToggleViewColumn(ENCRYPTION_TYPE);
1506*7f2fe78bSCy Schubert }
1507*7f2fe78bSCy Schubert 
OnUpdateEncryptionType(CCmdUI * pCmdUI)1508*7f2fe78bSCy Schubert VOID CLeashView::OnUpdateEncryptionType(CCmdUI *pCmdUI)
1509*7f2fe78bSCy Schubert {
1510*7f2fe78bSCy Schubert     pCmdUI->SetCheck(sm_viewColumns[ENCRYPTION_TYPE].m_enabled);
1511*7f2fe78bSCy Schubert }
1512*7f2fe78bSCy Schubert 
OnCcacheName()1513*7f2fe78bSCy Schubert VOID CLeashView::OnCcacheName()
1514*7f2fe78bSCy Schubert {
1515*7f2fe78bSCy Schubert     ToggleViewColumn(CACHE_NAME);
1516*7f2fe78bSCy Schubert }
1517*7f2fe78bSCy Schubert 
OnUpdateCcacheName(CCmdUI * pCmdUI)1518*7f2fe78bSCy Schubert VOID CLeashView::OnUpdateCcacheName(CCmdUI *pCmdUI)
1519*7f2fe78bSCy Schubert {
1520*7f2fe78bSCy Schubert     pCmdUI->SetCheck(sm_viewColumns[CACHE_NAME].m_enabled);
1521*7f2fe78bSCy Schubert }
1522*7f2fe78bSCy Schubert 
OnLargeIcons()1523*7f2fe78bSCy Schubert VOID CLeashView::OnLargeIcons()
1524*7f2fe78bSCy Schubert {
1525*7f2fe78bSCy Schubert     INT x, y, n;
1526*7f2fe78bSCy Schubert 
1527*7f2fe78bSCy Schubert     if (change_icon_size)
1528*7f2fe78bSCy Schubert     {
1529*7f2fe78bSCy Schubert         if (m_largeIcons%2 == 0)
1530*7f2fe78bSCy Schubert             m_largeIcons = ON;
1531*7f2fe78bSCy Schubert         else
1532*7f2fe78bSCy Schubert             m_largeIcons = OFF;
1533*7f2fe78bSCy Schubert     }
1534*7f2fe78bSCy Schubert     else
1535*7f2fe78bSCy Schubert     {
1536*7f2fe78bSCy Schubert         if (m_largeIcons%2 == 0)
1537*7f2fe78bSCy Schubert             m_largeIcons = OFF;
1538*7f2fe78bSCy Schubert         else
1539*7f2fe78bSCy Schubert             m_largeIcons = ON;
1540*7f2fe78bSCy Schubert     }
1541*7f2fe78bSCy Schubert 
1542*7f2fe78bSCy Schubert     x = y = SMALL_ICONS;
1543*7f2fe78bSCy Schubert 
1544*7f2fe78bSCy Schubert     if (!m_pApp)
1545*7f2fe78bSCy Schubert         ApplicationInfoMissingMsg();
1546*7f2fe78bSCy Schubert     else
1547*7f2fe78bSCy Schubert     {
1548*7f2fe78bSCy Schubert         if (!m_largeIcons)
1549*7f2fe78bSCy Schubert         {
1550*7f2fe78bSCy Schubert             if (m_hMenu)
1551*7f2fe78bSCy Schubert                 CheckMenuItem(m_hMenu, ID_LARGE_ICONS, MF_CHECKED);
1552*7f2fe78bSCy Schubert 
1553*7f2fe78bSCy Schubert             x = y = LARGE_ICONS;
1554*7f2fe78bSCy Schubert 
1555*7f2fe78bSCy Schubert 	    if (!m_startup)
1556*7f2fe78bSCy Schubert 	    {
1557*7f2fe78bSCy Schubert                 m_pApp->WriteProfileInt("Settings", "LargeIcons", TRUE_FLAG);
1558*7f2fe78bSCy Schubert 	    }
1559*7f2fe78bSCy Schubert         }
1560*7f2fe78bSCy Schubert         else
1561*7f2fe78bSCy Schubert         {
1562*7f2fe78bSCy Schubert             if (m_hMenu)
1563*7f2fe78bSCy Schubert                 CheckMenuItem(m_hMenu, ID_LARGE_ICONS, MF_UNCHECKED);
1564*7f2fe78bSCy Schubert 
1565*7f2fe78bSCy Schubert             x = y = SMALL_ICONS;
1566*7f2fe78bSCy Schubert 
1567*7f2fe78bSCy Schubert             if (!m_startup)
1568*7f2fe78bSCy Schubert             {
1569*7f2fe78bSCy Schubert                 m_pApp->WriteProfileInt("Settings", "LargeIcons", FALSE_FLAG);
1570*7f2fe78bSCy Schubert             }
1571*7f2fe78bSCy Schubert         }
1572*7f2fe78bSCy Schubert     }
1573*7f2fe78bSCy Schubert 
1574*7f2fe78bSCy Schubert     HICON hIcon[IMAGE_COUNT];
1575*7f2fe78bSCy Schubert     for (n = 0; n < IMAGE_COUNT; n++)
1576*7f2fe78bSCy Schubert     {
1577*7f2fe78bSCy Schubert         hIcon[n] = NULL;
1578*7f2fe78bSCy Schubert     }
1579*7f2fe78bSCy Schubert 
1580*7f2fe78bSCy Schubert     m_imageList.DeleteImageList( );
1581*7f2fe78bSCy Schubert 
1582*7f2fe78bSCy Schubert     UINT bitsPerPixel = GetDeviceCaps( ::GetDC(::GetDesktopWindow()), BITSPIXEL);
1583*7f2fe78bSCy Schubert     UINT ilcColor;
1584*7f2fe78bSCy Schubert     if ( bitsPerPixel >= 32 )
1585*7f2fe78bSCy Schubert         ilcColor = ILC_COLOR32;
1586*7f2fe78bSCy Schubert     else if ( bitsPerPixel >= 24 )
1587*7f2fe78bSCy Schubert         ilcColor = ILC_COLOR24;
1588*7f2fe78bSCy Schubert     else if ( bitsPerPixel >= 16 )
1589*7f2fe78bSCy Schubert         ilcColor = ILC_COLOR16;
1590*7f2fe78bSCy Schubert     else if ( bitsPerPixel >= 8 )
1591*7f2fe78bSCy Schubert         ilcColor = ILC_COLOR8;
1592*7f2fe78bSCy Schubert     else
1593*7f2fe78bSCy Schubert         ilcColor = ILC_COLOR;
1594*7f2fe78bSCy Schubert     m_imageList.Create(x, y, ilcColor | ILC_MASK, IMAGE_COUNT, 1);
1595*7f2fe78bSCy Schubert     m_imageList.SetBkColor(GetSysColor(COLOR_WINDOW));
1596*7f2fe78bSCy Schubert 
1597*7f2fe78bSCy Schubert     hIcon[ACTIVE_TRAY_ICON] = AfxGetApp()->LoadIcon(IDI_LEASH_TRAY_GOOD);
1598*7f2fe78bSCy Schubert     hIcon[LOW_TRAY_ICON] = AfxGetApp()->LoadIcon(IDI_LEASH_TRAY_LOW);
1599*7f2fe78bSCy Schubert     hIcon[EXPIRED_TRAY_ICON] = AfxGetApp()->LoadIcon(IDI_LEASH_TRAY_EXPIRED);
1600*7f2fe78bSCy Schubert     hIcon[NONE_TRAY_ICON]  = AfxGetApp()->LoadIcon(IDI_LEASH_TRAY_NONE);
1601*7f2fe78bSCy Schubert     hIcon[ACTIVE_PARENT_NODE] = AfxGetApp()->LoadIcon(IDI_LEASH_PRINCIPAL_GOOD);
1602*7f2fe78bSCy Schubert     hIcon[LOW_PARENT_NODE] = AfxGetApp()->LoadIcon(IDI_LEASH_PRINCIPAL_LOW);
1603*7f2fe78bSCy Schubert     hIcon[EXPIRED_PARENT_NODE] = AfxGetApp()->LoadIcon(IDI_LEASH_PRINCIPAL_EXPIRED);
1604*7f2fe78bSCy Schubert     hIcon[NONE_PARENT_NODE]  = AfxGetApp()->LoadIcon(IDI_LEASH_PRINCIPAL_NONE);
1605*7f2fe78bSCy Schubert     hIcon[ACTIVE_TICKET] = AfxGetApp()->LoadIcon(IDI_TICKETTYPE_GOOD);
1606*7f2fe78bSCy Schubert     hIcon[LOW_TICKET] = AfxGetApp()->LoadIcon(IDI_TICKETTYPE_LOW);
1607*7f2fe78bSCy Schubert     hIcon[EXPIRED_TICKET] = AfxGetApp()->LoadIcon(IDI_TICKETTYPE_EXPIRED);
1608*7f2fe78bSCy Schubert     hIcon[TICKET_NOT_INSTALLED] = AfxGetApp()->LoadIcon(IDI_TICKETTYPE_NOTINSTALLED);
1609*7f2fe78bSCy Schubert     hIcon[ACTIVE_CLOCK] = AfxGetApp()->LoadIcon(IDI_TICKET_GOOD);
1610*7f2fe78bSCy Schubert     hIcon[LOW_CLOCK] = AfxGetApp()->LoadIcon(IDI_TICKET_LOW);
1611*7f2fe78bSCy Schubert     hIcon[EXPIRED_CLOCK] = AfxGetApp()->LoadIcon(IDI_TICKET_EXPIRED);
1612*7f2fe78bSCy Schubert     hIcon[TKT_ADDRESS] = AfxGetApp()->LoadIcon(IDI_LEASH_TICKET_ADDRESS);
1613*7f2fe78bSCy Schubert     hIcon[TKT_SESSION] = AfxGetApp()->LoadIcon(IDI_LEASH_TICKET_SESSION);
1614*7f2fe78bSCy Schubert     hIcon[TKT_ENCRYPTION] = AfxGetApp()->LoadIcon(IDI_LEASH_TICKET_ENCRYPTION);
1615*7f2fe78bSCy Schubert 
1616*7f2fe78bSCy Schubert     for (n = 0; n < IMAGE_COUNT; n++)
1617*7f2fe78bSCy Schubert     {
1618*7f2fe78bSCy Schubert         if ( !hIcon[n] ) {
1619*7f2fe78bSCy Schubert             AfxMessageBox("Can't find one or more images in the Leash Ticket Tree!",
1620*7f2fe78bSCy Schubert                         MB_OK|MB_ICONSTOP);
1621*7f2fe78bSCy Schubert             return;
1622*7f2fe78bSCy Schubert         }
1623*7f2fe78bSCy Schubert         m_imageList.Add(hIcon[n]);
1624*7f2fe78bSCy Schubert     }
1625*7f2fe78bSCy Schubert 
1626*7f2fe78bSCy Schubert     if (!m_startup)
1627*7f2fe78bSCy Schubert         SendMessage(WM_COMMAND, ID_UPDATE_DISPLAY, 0);
1628*7f2fe78bSCy Schubert }
1629*7f2fe78bSCy Schubert 
OnKillTixOnExit()1630*7f2fe78bSCy Schubert VOID CLeashView::OnKillTixOnExit()
1631*7f2fe78bSCy Schubert {
1632*7f2fe78bSCy Schubert     m_destroyTicketsOnExit = !m_destroyTicketsOnExit;
1633*7f2fe78bSCy Schubert 
1634*7f2fe78bSCy Schubert     if (m_pApp)
1635*7f2fe78bSCy Schubert         m_pApp->WriteProfileInt("Settings", "DestroyTicketsOnExit",
1636*7f2fe78bSCy Schubert                                 m_destroyTicketsOnExit);
1637*7f2fe78bSCy Schubert }
1638*7f2fe78bSCy Schubert 
OnUpdateKillTixOnExit(CCmdUI * pCmdUI)1639*7f2fe78bSCy Schubert VOID CLeashView::OnUpdateKillTixOnExit(CCmdUI *pCmdUI)
1640*7f2fe78bSCy Schubert {
1641*7f2fe78bSCy Schubert     pCmdUI->SetCheck(m_destroyTicketsOnExit);
1642*7f2fe78bSCy Schubert }
1643*7f2fe78bSCy Schubert 
OnUppercaseRealm()1644*7f2fe78bSCy Schubert VOID CLeashView::OnUppercaseRealm()
1645*7f2fe78bSCy Schubert {
1646*7f2fe78bSCy Schubert     m_upperCaseRealm = !m_upperCaseRealm;
1647*7f2fe78bSCy Schubert 
1648*7f2fe78bSCy Schubert     pLeash_set_default_uppercaserealm(m_upperCaseRealm);
1649*7f2fe78bSCy Schubert }
1650*7f2fe78bSCy Schubert 
OnUpdateUppercaseRealm(CCmdUI * pCmdUI)1651*7f2fe78bSCy Schubert VOID CLeashView::OnUpdateUppercaseRealm(CCmdUI *pCmdUI)
1652*7f2fe78bSCy Schubert {
1653*7f2fe78bSCy Schubert     // description is now 'allow mixed case', so reverse logic
1654*7f2fe78bSCy Schubert     pCmdUI->SetCheck(!m_upperCaseRealm);
1655*7f2fe78bSCy Schubert }
1656*7f2fe78bSCy Schubert 
ResetTreeNodes()1657*7f2fe78bSCy Schubert VOID CLeashView::ResetTreeNodes()
1658*7f2fe78bSCy Schubert {
1659*7f2fe78bSCy Schubert     m_hPrincipalState = 0;
1660*7f2fe78bSCy Schubert     m_hKerb5State = 0;
1661*7f2fe78bSCy Schubert }
1662*7f2fe78bSCy Schubert 
OnDestroy()1663*7f2fe78bSCy Schubert VOID CLeashView::OnDestroy()
1664*7f2fe78bSCy Schubert {
1665*7f2fe78bSCy Schubert     CCacheDisplayData *elem;
1666*7f2fe78bSCy Schubert     SetTrayIcon(NIM_DELETE);
1667*7f2fe78bSCy Schubert 
1668*7f2fe78bSCy Schubert     if (m_destroyTicketsOnExit) {
1669*7f2fe78bSCy Schubert         elem = m_ccacheDisplay;
1670*7f2fe78bSCy Schubert         while (elem != NULL) {
1671*7f2fe78bSCy Schubert             kdestroy(elem->m_ccacheName);
1672*7f2fe78bSCy Schubert             elem = elem->m_next;
1673*7f2fe78bSCy Schubert         }
1674*7f2fe78bSCy Schubert     }
1675*7f2fe78bSCy Schubert     CListView::OnDestroy();
1676*7f2fe78bSCy Schubert }
1677*7f2fe78bSCy Schubert 
OnUpdateDestroyTicket(CCmdUI * pCmdUI)1678*7f2fe78bSCy Schubert VOID CLeashView::OnUpdateDestroyTicket(CCmdUI* pCmdUI)
1679*7f2fe78bSCy Schubert {
1680*7f2fe78bSCy Schubert     // @TODO: mutex
1681*7f2fe78bSCy Schubert     BOOL enable = FALSE;
1682*7f2fe78bSCy Schubert     CCacheDisplayData *elem = m_ccacheDisplay;
1683*7f2fe78bSCy Schubert     while (elem != NULL) {
1684*7f2fe78bSCy Schubert         if (elem->m_selected) {
1685*7f2fe78bSCy Schubert             enable = TRUE;
1686*7f2fe78bSCy Schubert             break;
1687*7f2fe78bSCy Schubert         }
1688*7f2fe78bSCy Schubert         elem = elem->m_next;
1689*7f2fe78bSCy Schubert     }
1690*7f2fe78bSCy Schubert 
1691*7f2fe78bSCy Schubert     pCmdUI->Enable(enable);
1692*7f2fe78bSCy Schubert }
1693*7f2fe78bSCy Schubert 
OnUpdateInitTicket(CCmdUI * pCmdUI)1694*7f2fe78bSCy Schubert VOID CLeashView::OnUpdateInitTicket(CCmdUI* pCmdUI)
1695*7f2fe78bSCy Schubert {
1696*7f2fe78bSCy Schubert   if (!CLeashApp::m_hKrb5DLL)
1697*7f2fe78bSCy Schubert         pCmdUI->Enable(FALSE);
1698*7f2fe78bSCy Schubert     else
1699*7f2fe78bSCy Schubert         pCmdUI->Enable(TRUE);
1700*7f2fe78bSCy Schubert }
1701*7f2fe78bSCy Schubert 
OnUpdateRenewTicket(CCmdUI * pCmdUI)1702*7f2fe78bSCy Schubert VOID CLeashView::OnUpdateRenewTicket(CCmdUI* pCmdUI)
1703*7f2fe78bSCy Schubert {
1704*7f2fe78bSCy Schubert     // @TODO: mutex
1705*7f2fe78bSCy Schubert     BOOL enable = FALSE;
1706*7f2fe78bSCy Schubert     CCacheDisplayData *elem = m_ccacheDisplay;
1707*7f2fe78bSCy Schubert     while (elem != NULL) {
1708*7f2fe78bSCy Schubert         if (elem->m_selected) { // @TODO: && elem->m_renewable
1709*7f2fe78bSCy Schubert             enable = TRUE;
1710*7f2fe78bSCy Schubert             break;
1711*7f2fe78bSCy Schubert         }
1712*7f2fe78bSCy Schubert         elem = elem->m_next;
1713*7f2fe78bSCy Schubert     }
1714*7f2fe78bSCy Schubert 
1715*7f2fe78bSCy Schubert     pCmdUI->Enable(enable);
1716*7f2fe78bSCy Schubert }
1717*7f2fe78bSCy Schubert 
OnGoodbye(WPARAM wParam,LPARAM lParam)1718*7f2fe78bSCy Schubert LRESULT CLeashView::OnGoodbye(WPARAM wParam, LPARAM lParam)
1719*7f2fe78bSCy Schubert {
1720*7f2fe78bSCy Schubert     m_pDebugWindow->DestroyWindow();
1721*7f2fe78bSCy Schubert     return 0L;
1722*7f2fe78bSCy Schubert }
1723*7f2fe78bSCy Schubert 
OnLeashRestore()1724*7f2fe78bSCy Schubert VOID CLeashView::OnLeashRestore()
1725*7f2fe78bSCy Schubert {
1726*7f2fe78bSCy Schubert     if ( CMainFrame::m_isMinimum ) {
1727*7f2fe78bSCy Schubert         CMainFrame * frame = (CMainFrame *)GetParentFrame();
1728*7f2fe78bSCy Schubert         frame->ShowTaskBarButton(TRUE);
1729*7f2fe78bSCy Schubert         frame->ShowWindow(SW_SHOWNORMAL);
1730*7f2fe78bSCy Schubert     }
1731*7f2fe78bSCy Schubert }
1732*7f2fe78bSCy Schubert 
OnLeashMinimize()1733*7f2fe78bSCy Schubert VOID CLeashView::OnLeashMinimize()
1734*7f2fe78bSCy Schubert {
1735*7f2fe78bSCy Schubert     if ( !CMainFrame::m_isMinimum ) {
1736*7f2fe78bSCy Schubert         CMainFrame * frame = (CMainFrame *)GetParentFrame();
1737*7f2fe78bSCy Schubert         // frame->ShowTaskBarButton(FALSE);
1738*7f2fe78bSCy Schubert         frame->ShowWindow(SW_HIDE);
1739*7f2fe78bSCy Schubert         frame->ShowWindow(SW_MINIMIZE);
1740*7f2fe78bSCy Schubert     }
1741*7f2fe78bSCy Schubert }
1742*7f2fe78bSCy Schubert 
OnTrayIcon(WPARAM wParam,LPARAM lParam)1743*7f2fe78bSCy Schubert LRESULT CLeashView::OnTrayIcon(WPARAM wParam, LPARAM lParam)
1744*7f2fe78bSCy Schubert {
1745*7f2fe78bSCy Schubert     switch ( lParam ) {
1746*7f2fe78bSCy Schubert     case WM_LBUTTONDOWN:
1747*7f2fe78bSCy Schubert         if ( CMainFrame::m_isMinimum )
1748*7f2fe78bSCy Schubert             OnLeashRestore();
1749*7f2fe78bSCy Schubert         else
1750*7f2fe78bSCy Schubert             OnLeashMinimize();
1751*7f2fe78bSCy Schubert         break;
1752*7f2fe78bSCy Schubert     case WM_RBUTTONDOWN:
1753*7f2fe78bSCy Schubert         {
1754*7f2fe78bSCy Schubert             int nFlags;
1755*7f2fe78bSCy Schubert             CMenu * menu = new CMenu();
1756*7f2fe78bSCy Schubert             menu->CreatePopupMenu();
1757*7f2fe78bSCy Schubert             if ( !CMainFrame::m_isMinimum )
1758*7f2fe78bSCy Schubert                 menu->AppendMenu(MF_STRING, ID_LEASH_MINIMIZE, "&Close MIT Kerberos Window");
1759*7f2fe78bSCy Schubert             else
1760*7f2fe78bSCy Schubert                 menu->AppendMenu(MF_STRING, ID_LEASH_RESTORE, "&Open MIT Kerberos Window");
1761*7f2fe78bSCy Schubert             menu->AppendMenu(MF_SEPARATOR);
1762*7f2fe78bSCy Schubert             menu->AppendMenu(MF_STRING, ID_INIT_TICKET, "&Get Tickets");
1763*7f2fe78bSCy Schubert             if (WaitForSingleObject( ticketinfo.lockObj, INFINITE ) != WAIT_OBJECT_0)
1764*7f2fe78bSCy Schubert                 throw("Unable to lock ticketinfo");
1765*7f2fe78bSCy Schubert             if (!ticketinfo.Krb5.btickets ||
1766*7f2fe78bSCy Schubert 		!CLeashApp::m_hKrb5DLL)
1767*7f2fe78bSCy Schubert                 nFlags = MF_STRING | MF_GRAYED;
1768*7f2fe78bSCy Schubert             else
1769*7f2fe78bSCy Schubert                 nFlags = MF_STRING;
1770*7f2fe78bSCy Schubert             menu->AppendMenu(nFlags, ID_RENEW_TICKET, "&Renew Tickets");
1771*7f2fe78bSCy Schubert             if (!ticketinfo.Krb5.btickets)
1772*7f2fe78bSCy Schubert                 nFlags = MF_STRING | MF_GRAYED;
1773*7f2fe78bSCy Schubert             else
1774*7f2fe78bSCy Schubert                 nFlags = MF_STRING;
1775*7f2fe78bSCy Schubert             ReleaseMutex(ticketinfo.lockObj);
1776*7f2fe78bSCy Schubert             menu->AppendMenu(MF_STRING, ID_DESTROY_TICKET, "&Destroy Tickets");
1777*7f2fe78bSCy Schubert             menu->AppendMenu(MF_STRING, ID_CHANGE_PASSWORD, "&Change Password");
1778*7f2fe78bSCy Schubert 
1779*7f2fe78bSCy Schubert             menu->AppendMenu(MF_SEPARATOR);
1780*7f2fe78bSCy Schubert             if ( m_autoRenewTickets )
1781*7f2fe78bSCy Schubert                 nFlags = MF_STRING | MF_CHECKED;
1782*7f2fe78bSCy Schubert             else
1783*7f2fe78bSCy Schubert                 nFlags = MF_STRING | MF_UNCHECKED;
1784*7f2fe78bSCy Schubert             menu->AppendMenu(nFlags, ID_AUTO_RENEW, "&Automatic Ticket Renewal");
1785*7f2fe78bSCy Schubert             if ( m_lowTicketAlarm )
1786*7f2fe78bSCy Schubert                 nFlags = MF_STRING | MF_CHECKED;
1787*7f2fe78bSCy Schubert             else
1788*7f2fe78bSCy Schubert                 nFlags = MF_STRING | MF_UNCHECKED;
1789*7f2fe78bSCy Schubert             menu->AppendMenu(nFlags, ID_LOW_TICKET_ALARM, "&Expiration Alarm");
1790*7f2fe78bSCy Schubert             menu->AppendMenu(MF_SEPARATOR);
1791*7f2fe78bSCy Schubert             menu->AppendMenu(MF_STRING, ID_APP_EXIT, "E&xit");
1792*7f2fe78bSCy Schubert             menu->SetDefaultItem(ID_LEASH_RESTORE);
1793*7f2fe78bSCy Schubert 
1794*7f2fe78bSCy Schubert             POINT pt;
1795*7f2fe78bSCy Schubert             GetCursorPos(&pt);
1796*7f2fe78bSCy Schubert 
1797*7f2fe78bSCy Schubert 	    SetForegroundWindow();
1798*7f2fe78bSCy Schubert             menu->TrackPopupMenu(TPM_RIGHTALIGN | TPM_RIGHTBUTTON,
1799*7f2fe78bSCy Schubert                                 pt.x, pt.y, GetParentFrame());
1800*7f2fe78bSCy Schubert 	    PostMessage(WM_NULL, 0, 0);
1801*7f2fe78bSCy Schubert             menu->DestroyMenu();
1802*7f2fe78bSCy Schubert             delete menu;
1803*7f2fe78bSCy Schubert         }
1804*7f2fe78bSCy Schubert         break;
1805*7f2fe78bSCy Schubert     case WM_MOUSEMOVE:
1806*7f2fe78bSCy Schubert         // SendMessage(WM_COMMAND, ID_UPDATE_DISPLAY, 0);
1807*7f2fe78bSCy Schubert         break;
1808*7f2fe78bSCy Schubert     }
1809*7f2fe78bSCy Schubert     return 0L;
1810*7f2fe78bSCy Schubert }
1811*7f2fe78bSCy Schubert 
OnAppAbout()1812*7f2fe78bSCy Schubert VOID CLeashView::OnAppAbout()
1813*7f2fe78bSCy Schubert {
1814*7f2fe78bSCy Schubert     CLeashAboutBox leashAboutBox;
1815*7f2fe78bSCy Schubert     // To debug loaded dlls:
1816*7f2fe78bSCy Schubert     // leashAboutBox.m_bListModules = TRUE;
1817*7f2fe78bSCy Schubert     leashAboutBox.DoModal();
1818*7f2fe78bSCy Schubert }
1819*7f2fe78bSCy Schubert 
1820*7f2fe78bSCy Schubert 
OnInitialUpdate()1821*7f2fe78bSCy Schubert VOID CLeashView::OnInitialUpdate()
1822*7f2fe78bSCy Schubert {
1823*7f2fe78bSCy Schubert     CListView::OnInitialUpdate();
1824*7f2fe78bSCy Schubert     CLeashApp::m_hProgram = ::FindWindow(_T("LEASH.0WNDCLASS"), NULL);
1825*7f2fe78bSCy Schubert     EnableToolTips();
1826*7f2fe78bSCy Schubert }
1827*7f2fe78bSCy Schubert 
OnItemexpandedTreeview(NMHDR * pNMHDR,LRESULT * pResult)1828*7f2fe78bSCy Schubert VOID CLeashView::OnItemexpandedTreeview(NMHDR* pNMHDR, LRESULT* pResult)
1829*7f2fe78bSCy Schubert {
1830*7f2fe78bSCy Schubert     NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
1831*7f2fe78bSCy Schubert 
1832*7f2fe78bSCy Schubert     if (m_hPrincipal == pNMTreeView->itemNew.hItem)
1833*7f2fe78bSCy Schubert         m_hPrincipalState = pNMTreeView->action;
1834*7f2fe78bSCy Schubert     else if (m_hKerb5 == pNMTreeView->itemNew.hItem)
1835*7f2fe78bSCy Schubert         m_hKerb5State = pNMTreeView->action;
1836*7f2fe78bSCy Schubert 
1837*7f2fe78bSCy Schubert     CMainFrame::m_isBeingResized = TRUE;
1838*7f2fe78bSCy Schubert     *pResult = 0;
1839*7f2fe78bSCy Schubert }
1840*7f2fe78bSCy Schubert 
OnUpdateDebugMode(CCmdUI * pCmdUI)1841*7f2fe78bSCy Schubert VOID CLeashView::OnUpdateDebugMode(CCmdUI* pCmdUI)
1842*7f2fe78bSCy Schubert {
1843*7f2fe78bSCy Schubert         pCmdUI->Enable(FALSE);
1844*7f2fe78bSCy Schubert }
1845*7f2fe78bSCy Schubert 
OnUpdateCfgFiles(CCmdUI * pCmdUI)1846*7f2fe78bSCy Schubert VOID CLeashView::OnUpdateCfgFiles(CCmdUI* pCmdUI)
1847*7f2fe78bSCy Schubert {
1848*7f2fe78bSCy Schubert         pCmdUI->Enable(FALSE);
1849*7f2fe78bSCy Schubert }
1850*7f2fe78bSCy Schubert 
1851*7f2fe78bSCy Schubert /*
1852*7f2fe78bSCy Schubert void CLeashView::GetRowWidthHeight(CDC* pDC, LPCSTR theString, int& nRowWidth,
1853*7f2fe78bSCy Schubert                                    int& nRowHeight, int& nCharWidth)
1854*7f2fe78bSCy Schubert {
1855*7f2fe78bSCy Schubert     TEXTMETRIC tm;
1856*7f2fe78bSCy Schubert 
1857*7f2fe78bSCy Schubert     //CEx29aDoc* pDoc = GetDocument();
1858*7f2fe78bSCy Schubert 	pDC->GetTextMetrics(&tm);
1859*7f2fe78bSCy Schubert     nCharWidth = tm.tmAveCharWidth + 1;
1860*7f2fe78bSCy Schubert     nRowWidth = strlen(theString);
1861*7f2fe78bSCy Schubert 
1862*7f2fe78bSCy Schubert     //int nFields = theString.GetLength();
1863*7f2fe78bSCy Schubert 
1864*7f2fe78bSCy Schubert     //for(int i = 0; i < nFields; i++)
1865*7f2fe78bSCy Schubert     //{
1866*7f2fe78bSCy Schubert 	//    nRowWidth += nCharWidth;
1867*7f2fe78bSCy Schubert 	//}
1868*7f2fe78bSCy Schubert 
1869*7f2fe78bSCy Schubert     nRowWidth *= nCharWidth;
1870*7f2fe78bSCy Schubert     nRowHeight = tm.tmHeight;
1871*7f2fe78bSCy Schubert }
1872*7f2fe78bSCy Schubert */
1873*7f2fe78bSCy Schubert 
SetTrayText(int nim,CString tip)1874*7f2fe78bSCy Schubert void CLeashView::SetTrayText(int nim, CString tip)
1875*7f2fe78bSCy Schubert {
1876*7f2fe78bSCy Schubert     if ( (nim == NIM_MODIFY) && (m_bIconDeleted) )
1877*7f2fe78bSCy Schubert         return;
1878*7f2fe78bSCy Schubert     if ( (nim == NIM_MODIFY) && (!m_bIconAdded) )
1879*7f2fe78bSCy Schubert         nim = NIM_ADD;
1880*7f2fe78bSCy Schubert 
1881*7f2fe78bSCy Schubert     if ( (nim != NIM_DELETE) || IsWindow(m_hWnd) )
1882*7f2fe78bSCy Schubert     {
1883*7f2fe78bSCy Schubert         NOTIFYICONDATA nid;
1884*7f2fe78bSCy Schubert         memset (&nid, 0x00, sizeof(NOTIFYICONDATA));
1885*7f2fe78bSCy Schubert         nid.cbSize = sizeof(NOTIFYICONDATA);
1886*7f2fe78bSCy Schubert         nid.hWnd = m_hWnd;
1887*7f2fe78bSCy Schubert         nid.uID = 0;
1888*7f2fe78bSCy Schubert         nid.uFlags = NIF_MESSAGE | NIF_TIP;
1889*7f2fe78bSCy Schubert         nid.uCallbackMessage = WM_TRAYICON;
1890*7f2fe78bSCy Schubert         strncpy(nid.szTip, (LPCTSTR) tip, sizeof(nid.szTip));
1891*7f2fe78bSCy Schubert         nid.szTip[sizeof(nid.szTip)-1] = '\0';
1892*7f2fe78bSCy Schubert         Shell_NotifyIcon (nim, &nid);
1893*7f2fe78bSCy Schubert     }
1894*7f2fe78bSCy Schubert 
1895*7f2fe78bSCy Schubert     if ( nim == NIM_ADD )
1896*7f2fe78bSCy Schubert         m_bIconAdded = TRUE;
1897*7f2fe78bSCy Schubert     if ( nim == NIM_DELETE )
1898*7f2fe78bSCy Schubert         m_bIconDeleted = TRUE;
1899*7f2fe78bSCy Schubert }
1900*7f2fe78bSCy Schubert 
SetTrayIcon(int nim,int state)1901*7f2fe78bSCy Schubert void CLeashView::SetTrayIcon(int nim, int state)
1902*7f2fe78bSCy Schubert {
1903*7f2fe78bSCy Schubert     static HICON hIcon[IMAGE_COUNT];
1904*7f2fe78bSCy Schubert     static BOOL bIconInit = FALSE;
1905*7f2fe78bSCy Schubert 
1906*7f2fe78bSCy Schubert     if ( (nim == NIM_MODIFY) && (m_bIconDeleted) )
1907*7f2fe78bSCy Schubert         return;
1908*7f2fe78bSCy Schubert     if ( (nim == NIM_MODIFY) && (!m_bIconAdded) )
1909*7f2fe78bSCy Schubert         nim = NIM_ADD;
1910*7f2fe78bSCy Schubert 
1911*7f2fe78bSCy Schubert     if ( (nim != NIM_DELETE) || IsWindow(m_hWnd) )
1912*7f2fe78bSCy Schubert     {
1913*7f2fe78bSCy Schubert         if ( !bIconInit ) {
1914*7f2fe78bSCy Schubert             // The state is reported as the parent node value although
1915*7f2fe78bSCy Schubert             // we want to use the Tray Version of the icons
1916*7f2fe78bSCy Schubert             hIcon[ACTIVE_PARENT_NODE] = AfxGetApp()->LoadIcon(IDI_LEASH_TRAY_GOOD);
1917*7f2fe78bSCy Schubert             hIcon[LOW_PARENT_NODE] = AfxGetApp()->LoadIcon(IDI_LEASH_TRAY_LOW);
1918*7f2fe78bSCy Schubert             hIcon[EXPIRED_PARENT_NODE] = AfxGetApp()->LoadIcon(IDI_LEASH_TRAY_EXPIRED);
1919*7f2fe78bSCy Schubert             hIcon[NONE_PARENT_NODE]  = AfxGetApp()->LoadIcon(IDI_LEASH_TRAY_NONE);
1920*7f2fe78bSCy Schubert             bIconInit = TRUE;
1921*7f2fe78bSCy Schubert         }
1922*7f2fe78bSCy Schubert 
1923*7f2fe78bSCy Schubert         NOTIFYICONDATA nid;
1924*7f2fe78bSCy Schubert         memset (&nid, 0x00, sizeof(NOTIFYICONDATA));
1925*7f2fe78bSCy Schubert         nid.cbSize = sizeof(NOTIFYICONDATA);
1926*7f2fe78bSCy Schubert         nid.hWnd = m_hWnd;
1927*7f2fe78bSCy Schubert         nid.uID = 0;
1928*7f2fe78bSCy Schubert         nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
1929*7f2fe78bSCy Schubert         nid.uCallbackMessage = WM_TRAYICON;
1930*7f2fe78bSCy Schubert         nid.hIcon = hIcon[state];
1931*7f2fe78bSCy Schubert         Shell_NotifyIcon (nim, &nid);
1932*7f2fe78bSCy Schubert     }
1933*7f2fe78bSCy Schubert 
1934*7f2fe78bSCy Schubert     if ( nim == NIM_ADD )
1935*7f2fe78bSCy Schubert         m_bIconAdded = TRUE;
1936*7f2fe78bSCy Schubert     if ( nim == NIM_DELETE )
1937*7f2fe78bSCy Schubert         m_bIconDeleted = TRUE;
1938*7f2fe78bSCy Schubert }
1939*7f2fe78bSCy Schubert 
PostWarningMessage(const CString & message)1940*7f2fe78bSCy Schubert BOOL CLeashView::PostWarningMessage(const CString& message)
1941*7f2fe78bSCy Schubert {
1942*7f2fe78bSCy Schubert     if (m_pWarningMessage)
1943*7f2fe78bSCy Schubert     {
1944*7f2fe78bSCy Schubert         return FALSE; // can't post more than one warning at a time
1945*7f2fe78bSCy Schubert     }
1946*7f2fe78bSCy Schubert     m_pWarningMessage = new CString(message);
1947*7f2fe78bSCy Schubert     PostMessage(WM_WARNINGPOPUP);
1948*7f2fe78bSCy Schubert     return TRUE;
1949*7f2fe78bSCy Schubert }
1950*7f2fe78bSCy Schubert 
OnWarningPopup(WPARAM wParam,LPARAM lParam)1951*7f2fe78bSCy Schubert LRESULT CLeashView::OnWarningPopup(WPARAM wParam, LPARAM lParam)
1952*7f2fe78bSCy Schubert {
1953*7f2fe78bSCy Schubert     CLeashMessageBox leashMessageBox(CMainFrame::m_isMinimum ? GetDesktopWindow() : NULL,
1954*7f2fe78bSCy Schubert                                         *m_pWarningMessage, 100000);
1955*7f2fe78bSCy Schubert     leashMessageBox.DoModal();
1956*7f2fe78bSCy Schubert     delete m_pWarningMessage;
1957*7f2fe78bSCy Schubert     m_pWarningMessage = NULL;
1958*7f2fe78bSCy Schubert     return 0L;
1959*7f2fe78bSCy Schubert }
1960*7f2fe78bSCy Schubert 
PreTranslateMessage(MSG * pMsg)1961*7f2fe78bSCy Schubert BOOL CLeashView::PreTranslateMessage(MSG* pMsg)
1962*7f2fe78bSCy Schubert {
1963*7f2fe78bSCy Schubert 	if ( pMsg->message == ID_OBTAIN_TGT_WITH_LPARAM )
1964*7f2fe78bSCy Schubert 	{
1965*7f2fe78bSCy Schubert 		OutputDebugString("Obtain TGT with LParam\n");
1966*7f2fe78bSCy Schubert 	}
1967*7f2fe78bSCy Schubert 
1968*7f2fe78bSCy Schubert     if ( pMsg->message == WM_TIMER ) {
1969*7f2fe78bSCy Schubert         try {
1970*7f2fe78bSCy Schubert         if (InterlockedDecrement(&m_timerMsgNotInProgress) == 0) {
1971*7f2fe78bSCy Schubert 
1972*7f2fe78bSCy Schubert             CString ticketStatusKrb5 = TCHAR(NOT_INSTALLED);
1973*7f2fe78bSCy Schubert             CString strTimeDate;
1974*7f2fe78bSCy Schubert             CString lowTicketWarningKrb5;
1975*7f2fe78bSCy Schubert 
1976*7f2fe78bSCy Schubert           timer_start:
1977*7f2fe78bSCy Schubert             if (WaitForSingleObject( ticketinfo.lockObj, 100 ) != WAIT_OBJECT_0)
1978*7f2fe78bSCy Schubert                 throw("Unable to lock ticketinfo");
1979*7f2fe78bSCy Schubert             if (CLeashApp::m_hKrb5DLL)
1980*7f2fe78bSCy Schubert             {
1981*7f2fe78bSCy Schubert                 // KRB5
1982*7f2fe78bSCy Schubert                 UpdateTicketTime(ticketinfo.Krb5);
1983*7f2fe78bSCy Schubert 
1984*7f2fe78bSCy Schubert                 if (!ticketinfo.Krb5.btickets)
1985*7f2fe78bSCy Schubert                 {
1986*7f2fe78bSCy Schubert                     ticketStatusKrb5 = "Kerb-5: No Tickets";
1987*7f2fe78bSCy Schubert                 }
1988*7f2fe78bSCy Schubert                 else if (EXPIRED_TICKETS == ticketinfo.Krb5.btickets)
1989*7f2fe78bSCy Schubert                 {
1990*7f2fe78bSCy Schubert                     ticketStatusKrb5 = "Kerb-5: Expired Ticket(s)";
1991*7f2fe78bSCy Schubert                     m_ticketTimeLeft = 0;
1992*7f2fe78bSCy Schubert                     lowTicketWarningKrb5 = "Your Kerberos Five ticket(s) have expired";
1993*7f2fe78bSCy Schubert                     if (!m_warningOfTicketTimeLeftLockKrb5)
1994*7f2fe78bSCy Schubert                         m_warningOfTicketTimeLeftKrb5 = 0;
1995*7f2fe78bSCy Schubert                     m_warningOfTicketTimeLeftLockKrb5 = ZERO_MINUTES_LEFT;
1996*7f2fe78bSCy Schubert                 }
1997*7f2fe78bSCy Schubert                 else
1998*7f2fe78bSCy Schubert                 {
1999*7f2fe78bSCy Schubert                     m_ticketStatusKrb5 = GetLowTicketStatus(5);
2000*7f2fe78bSCy Schubert                     switch (m_ticketStatusKrb5)
2001*7f2fe78bSCy Schubert                     {
2002*7f2fe78bSCy Schubert                     case TWENTY_MINUTES_LEFT:
2003*7f2fe78bSCy Schubert                         break;
2004*7f2fe78bSCy Schubert                     case FIFTEEN_MINUTES_LEFT:
2005*7f2fe78bSCy Schubert                         ticketinfo.Krb5.btickets = TICKETS_LOW;
2006*7f2fe78bSCy Schubert                         lowTicketWarningKrb5 = "Less then 15 minutes left on your Kerberos Five ticket(s)";
2007*7f2fe78bSCy Schubert                         break;
2008*7f2fe78bSCy Schubert                     case TEN_MINUTES_LEFT:
2009*7f2fe78bSCy Schubert                         ticketinfo.Krb5.btickets = TICKETS_LOW;
2010*7f2fe78bSCy Schubert                         lowTicketWarningKrb5 = "Less then 10 minutes left on your Kerberos Five ticket(s)";
2011*7f2fe78bSCy Schubert                         if (!m_warningOfTicketTimeLeftLockKrb5)
2012*7f2fe78bSCy Schubert                             m_warningOfTicketTimeLeftKrb5 = 0;
2013*7f2fe78bSCy Schubert                         m_warningOfTicketTimeLeftLockKrb5 = TEN_MINUTES_LEFT;
2014*7f2fe78bSCy Schubert                         break;
2015*7f2fe78bSCy Schubert                     case FIVE_MINUTES_LEFT:
2016*7f2fe78bSCy Schubert                         ticketinfo.Krb5.btickets = TICKETS_LOW;
2017*7f2fe78bSCy Schubert                         if (m_warningOfTicketTimeLeftLockKrb5 == TEN_MINUTES_LEFT)
2018*7f2fe78bSCy Schubert                             m_warningOfTicketTimeLeftKrb5 = 0;
2019*7f2fe78bSCy Schubert                         m_warningOfTicketTimeLeftLockKrb5 = FIVE_MINUTES_LEFT;
2020*7f2fe78bSCy Schubert                         lowTicketWarningKrb5 = "Less then 5 minutes left on your Kerberos Five ticket(s)";
2021*7f2fe78bSCy Schubert                         break;
2022*7f2fe78bSCy Schubert                     default:
2023*7f2fe78bSCy Schubert                         m_ticketStatusKrb5 = 0;
2024*7f2fe78bSCy Schubert                         break;
2025*7f2fe78bSCy Schubert                     }
2026*7f2fe78bSCy Schubert                 }
2027*7f2fe78bSCy Schubert 
2028*7f2fe78bSCy Schubert                 if (CMainFrame::m_isMinimum)
2029*7f2fe78bSCy Schubert                 {
2030*7f2fe78bSCy Schubert                     // minimized display
2031*7f2fe78bSCy Schubert                     ticketStatusKrb5.Format("Kerb-5: %02d:%02d Left",
2032*7f2fe78bSCy Schubert                                              (m_ticketTimeLeft / 60L / 60L),
2033*7f2fe78bSCy Schubert                                              (m_ticketTimeLeft / 60L % 60L));
2034*7f2fe78bSCy Schubert                 }
2035*7f2fe78bSCy Schubert                 else
2036*7f2fe78bSCy Schubert                 {
2037*7f2fe78bSCy Schubert                     // normal display
2038*7f2fe78bSCy Schubert                     if (GOOD_TICKETS == ticketinfo.Krb5.btickets || TICKETS_LOW == ticketinfo.Krb5.btickets)
2039*7f2fe78bSCy Schubert                     {
2040*7f2fe78bSCy Schubert                         if ( m_ticketTimeLeft >= 60 ) {
2041*7f2fe78bSCy Schubert                             ticketStatusKrb5.Format("Kerb-5 Ticket Life: %02d:%02d",
2042*7f2fe78bSCy Schubert                                                      (m_ticketTimeLeft / 60L / 60L),
2043*7f2fe78bSCy Schubert                                                      (m_ticketTimeLeft / 60L % 60L));
2044*7f2fe78bSCy Schubert                         } else {
2045*7f2fe78bSCy Schubert                             ticketStatusKrb5.Format("Kerb-5 Ticket Life: < 1 min");
2046*7f2fe78bSCy Schubert                         }
2047*7f2fe78bSCy Schubert                     }
2048*7f2fe78bSCy Schubert #ifndef NO_STATUS_BAR
2049*7f2fe78bSCy Schubert                     if (CMainFrame::m_wndStatusBar)
2050*7f2fe78bSCy Schubert                     {
2051*7f2fe78bSCy Schubert                         CMainFrame::m_wndStatusBar.SetPaneInfo(1, 111112, SBPS_NORMAL, 130);
2052*7f2fe78bSCy Schubert                         CMainFrame::m_wndStatusBar.SetPaneText(1, ticketStatusKrb5, SBT_POPOUT);
2053*7f2fe78bSCy Schubert                     }
2054*7f2fe78bSCy Schubert #endif
2055*7f2fe78bSCy Schubert                 }
2056*7f2fe78bSCy Schubert             }
2057*7f2fe78bSCy Schubert             else
2058*7f2fe78bSCy Schubert             {
2059*7f2fe78bSCy Schubert                 // not installed
2060*7f2fe78bSCy Schubert                 ticketStatusKrb5.Format("Kerb-5: Not Available");
2061*7f2fe78bSCy Schubert #ifndef NO_STATUS_BAR
2062*7f2fe78bSCy Schubert                 if (CMainFrame::m_wndStatusBar)
2063*7f2fe78bSCy Schubert                 {
2064*7f2fe78bSCy Schubert                     CMainFrame::m_wndStatusBar.SetPaneInfo(1, 111112, SBPS_NORMAL, 130);
2065*7f2fe78bSCy Schubert                     CMainFrame::m_wndStatusBar.SetPaneText(1, ticketStatusKrb5, SBT_POPOUT);
2066*7f2fe78bSCy Schubert                 }
2067*7f2fe78bSCy Schubert #endif
2068*7f2fe78bSCy Schubert             }
2069*7f2fe78bSCy Schubert             //KRB5
2070*7f2fe78bSCy Schubert 
2071*7f2fe78bSCy Schubert             if ( m_ticketStatusKrb5 == TWENTY_MINUTES_LEFT &&
2072*7f2fe78bSCy Schubert                  m_autoRenewTickets && !m_autoRenewalAttempted && ticketinfo.Krb5.renew_until &&
2073*7f2fe78bSCy Schubert                  (ticketinfo.Krb5.renew_until - LeashTime() > 20 * 60))
2074*7f2fe78bSCy Schubert             {
2075*7f2fe78bSCy Schubert                 m_autoRenewalAttempted = 1;
2076*7f2fe78bSCy Schubert                 ReleaseMutex(ticketinfo.lockObj);
2077*7f2fe78bSCy Schubert                 AfxBeginThread(RenewTicket,m_hWnd);
2078*7f2fe78bSCy Schubert                 goto timer_start;
2079*7f2fe78bSCy Schubert             }
2080*7f2fe78bSCy Schubert 
2081*7f2fe78bSCy Schubert             BOOL warningKrb5 = m_ticketStatusKrb5 > NO_TICKETS &&
2082*7f2fe78bSCy Schubert                 m_ticketStatusKrb5 < TWENTY_MINUTES_LEFT &&
2083*7f2fe78bSCy Schubert                     !m_warningOfTicketTimeLeftKrb5;
2084*7f2fe78bSCy Schubert 
2085*7f2fe78bSCy Schubert             // Play warning message only once per each case statement above
2086*7f2fe78bSCy Schubert             if (warningKrb5)
2087*7f2fe78bSCy Schubert             {
2088*7f2fe78bSCy Schubert 
2089*7f2fe78bSCy Schubert                 CString lowTicketWarning = "";
2090*7f2fe78bSCy Schubert                 int warnings = 0;
2091*7f2fe78bSCy Schubert 
2092*7f2fe78bSCy Schubert                 if (warningKrb5) {
2093*7f2fe78bSCy Schubert                     lowTicketWarning += lowTicketWarningKrb5;
2094*7f2fe78bSCy Schubert                     m_warningOfTicketTimeLeftKrb5 = ON;
2095*7f2fe78bSCy Schubert                     warnings++;
2096*7f2fe78bSCy Schubert                 }
2097*7f2fe78bSCy Schubert 
2098*7f2fe78bSCy Schubert                 ReleaseMutex(ticketinfo.lockObj);
2099*7f2fe78bSCy Schubert                 AlarmBeep();
2100*7f2fe78bSCy Schubert                 PostWarningMessage(lowTicketWarning);
2101*7f2fe78bSCy Schubert                 if (WaitForSingleObject( ticketinfo.lockObj, 100 ) != WAIT_OBJECT_0)
2102*7f2fe78bSCy Schubert                     throw("Unable to lock ticketinfo");
2103*7f2fe78bSCy Schubert             }
2104*7f2fe78bSCy Schubert 
2105*7f2fe78bSCy Schubert             CTime tTimeDate = CTime::GetCurrentTime();
2106*7f2fe78bSCy Schubert 
2107*7f2fe78bSCy Schubert             if (CMainFrame::m_isMinimum)
2108*7f2fe78bSCy Schubert             {
2109*7f2fe78bSCy Schubert 	      strTimeDate = ( "MIT Kerberos - "
2110*7f2fe78bSCy Schubert 			      "[" + ticketStatusKrb5 + "] - " +
2111*7f2fe78bSCy Schubert 			      "[" + ticketinfo.Krb5.principal + "]" + " - " +
2112*7f2fe78bSCy Schubert 			      tTimeDate.Format("%A, %B %d, %Y  %H:%M "));
2113*7f2fe78bSCy Schubert             }
2114*7f2fe78bSCy Schubert             else
2115*7f2fe78bSCy Schubert             {
2116*7f2fe78bSCy Schubert                 strTimeDate = ("MIT Kerberos - " +
2117*7f2fe78bSCy Schubert                                 tTimeDate.Format("%A, %B %d, %Y  %H:%M ")
2118*7f2fe78bSCy Schubert                                 //timeDate.Format("%d %b %y %H:%M:%S - ")
2119*7f2fe78bSCy Schubert                                 );
2120*7f2fe78bSCy Schubert             }
2121*7f2fe78bSCy Schubert             ::SetWindowText(CLeashApp::m_hProgram, strTimeDate);
2122*7f2fe78bSCy Schubert 
2123*7f2fe78bSCy Schubert             if (CLeashApp::m_hKrb5DLL) {
2124*7f2fe78bSCy Schubert                 if ( ticketinfo.Krb5.btickets )
2125*7f2fe78bSCy Schubert                     strTimeDate = ( "MIT Kerberos: "
2126*7f2fe78bSCy Schubert                                     "[" + ticketStatusKrb5 + "]" +
2127*7f2fe78bSCy Schubert                                     " - [" + ticketinfo.Krb5.principal + "]");
2128*7f2fe78bSCy Schubert                 else
2129*7f2fe78bSCy Schubert                     strTimeDate = "MIT Kerberos: No Tickets";
2130*7f2fe78bSCy Schubert             }
2131*7f2fe78bSCy Schubert             ReleaseMutex(ticketinfo.lockObj);
2132*7f2fe78bSCy Schubert 
2133*7f2fe78bSCy Schubert             SetTrayText(NIM_MODIFY, strTimeDate);
2134*7f2fe78bSCy Schubert 
2135*7f2fe78bSCy Schubert             m_updateDisplayCount++;
2136*7f2fe78bSCy Schubert             m_alreadyPlayedDisplayCount++;
2137*7f2fe78bSCy Schubert         }
2138*7f2fe78bSCy Schubert         } catch (...) {
2139*7f2fe78bSCy Schubert         }
2140*7f2fe78bSCy Schubert         InterlockedIncrement(&m_timerMsgNotInProgress);
2141*7f2fe78bSCy Schubert     }  // WM_TIMER
2142*7f2fe78bSCy Schubert 
2143*7f2fe78bSCy Schubert 
2144*7f2fe78bSCy Schubert     if (UPDATE_DISPLAY_TIME == m_updateDisplayCount)
2145*7f2fe78bSCy Schubert     {
2146*7f2fe78bSCy Schubert         m_updateDisplayCount = 0;
2147*7f2fe78bSCy Schubert         SendMessage(WM_COMMAND, ID_UPDATE_DISPLAY, 0);
2148*7f2fe78bSCy Schubert     }
2149*7f2fe78bSCy Schubert 
2150*7f2fe78bSCy Schubert     if (m_alreadyPlayedDisplayCount > 2)
2151*7f2fe78bSCy Schubert     {
2152*7f2fe78bSCy Schubert         m_alreadyPlayedDisplayCount = 0;
2153*7f2fe78bSCy Schubert         m_alreadyPlayed = FALSE;
2154*7f2fe78bSCy Schubert     }
2155*7f2fe78bSCy Schubert 
2156*7f2fe78bSCy Schubert     if (CMainFrame::m_isBeingResized)
2157*7f2fe78bSCy Schubert     {
2158*7f2fe78bSCy Schubert         m_startup = FALSE;
2159*7f2fe78bSCy Schubert 
2160*7f2fe78bSCy Schubert         UpdateWindow();
2161*7f2fe78bSCy Schubert 
2162*7f2fe78bSCy Schubert         CMainFrame::m_isBeingResized = FALSE;
2163*7f2fe78bSCy Schubert     }
2164*7f2fe78bSCy Schubert 
2165*7f2fe78bSCy Schubert 	if (::IsWindow(pMsg->hwnd))
2166*7f2fe78bSCy Schubert 		return CListView::PreTranslateMessage(pMsg);
2167*7f2fe78bSCy Schubert 	else
2168*7f2fe78bSCy Schubert 		return FALSE;
2169*7f2fe78bSCy Schubert }
2170*7f2fe78bSCy Schubert 
OnLowTicketAlarm()2171*7f2fe78bSCy Schubert VOID CLeashView::OnLowTicketAlarm()
2172*7f2fe78bSCy Schubert {
2173*7f2fe78bSCy Schubert     m_lowTicketAlarm = !m_lowTicketAlarm;
2174*7f2fe78bSCy Schubert 
2175*7f2fe78bSCy Schubert     if (m_pApp)
2176*7f2fe78bSCy Schubert         m_pApp->WriteProfileInt("Settings", "LowTicketAlarm", m_lowTicketAlarm);
2177*7f2fe78bSCy Schubert }
2178*7f2fe78bSCy Schubert 
OnUpdateLowTicketAlarm(CCmdUI * pCmdUI)2179*7f2fe78bSCy Schubert VOID CLeashView::OnUpdateLowTicketAlarm(CCmdUI* pCmdUI)
2180*7f2fe78bSCy Schubert {
2181*7f2fe78bSCy Schubert     pCmdUI->SetCheck(m_lowTicketAlarm);
2182*7f2fe78bSCy Schubert }
2183*7f2fe78bSCy Schubert 
OnAutoRenew()2184*7f2fe78bSCy Schubert VOID CLeashView::OnAutoRenew()
2185*7f2fe78bSCy Schubert {
2186*7f2fe78bSCy Schubert     m_autoRenewTickets = !m_autoRenewTickets;
2187*7f2fe78bSCy Schubert 
2188*7f2fe78bSCy Schubert     if (m_pApp)
2189*7f2fe78bSCy Schubert         m_pApp->WriteProfileInt("Settings", "AutoRenewTickets", m_autoRenewTickets);
2190*7f2fe78bSCy Schubert 
2191*7f2fe78bSCy Schubert     m_autoRenewalAttempted = 0;
2192*7f2fe78bSCy Schubert }
2193*7f2fe78bSCy Schubert 
OnUpdateAutoRenew(CCmdUI * pCmdUI)2194*7f2fe78bSCy Schubert VOID CLeashView::OnUpdateAutoRenew(CCmdUI* pCmdUI)
2195*7f2fe78bSCy Schubert {
2196*7f2fe78bSCy Schubert     pCmdUI->SetCheck(m_autoRenewTickets);
2197*7f2fe78bSCy Schubert }
2198*7f2fe78bSCy Schubert 
OnUpdateMakeDefault(CCmdUI * pCmdUI)2199*7f2fe78bSCy Schubert VOID CLeashView::OnUpdateMakeDefault(CCmdUI* pCmdUI)
2200*7f2fe78bSCy Schubert {
2201*7f2fe78bSCy Schubert     // enable if exactly one principal is selected and that principal is not
2202*7f2fe78bSCy Schubert     // the default principal
2203*7f2fe78bSCy Schubert     BOOL enable = FALSE;
2204*7f2fe78bSCy Schubert     CCacheDisplayData *elem = m_ccacheDisplay;
2205*7f2fe78bSCy Schubert     while (elem != NULL) {
2206*7f2fe78bSCy Schubert         if (elem->m_selected) {
2207*7f2fe78bSCy Schubert             if (enable) {
2208*7f2fe78bSCy Schubert                 // multiple selection; disable button
2209*7f2fe78bSCy Schubert                 enable = FALSE;
2210*7f2fe78bSCy Schubert                 break;
2211*7f2fe78bSCy Schubert             }
2212*7f2fe78bSCy Schubert             if (elem->m_isDefault)
2213*7f2fe78bSCy Schubert                 break;
2214*7f2fe78bSCy Schubert 
2215*7f2fe78bSCy Schubert             enable = TRUE;
2216*7f2fe78bSCy Schubert         }
2217*7f2fe78bSCy Schubert         elem = elem->m_next;
2218*7f2fe78bSCy Schubert     }
2219*7f2fe78bSCy Schubert     pCmdUI->Enable(enable);
2220*7f2fe78bSCy Schubert }
2221*7f2fe78bSCy Schubert 
AlarmBeep()2222*7f2fe78bSCy Schubert VOID CLeashView::AlarmBeep()
2223*7f2fe78bSCy Schubert {
2224*7f2fe78bSCy Schubert 	if (m_lowTicketAlarmSound)
2225*7f2fe78bSCy Schubert 	{
2226*7f2fe78bSCy Schubert 		::Beep(2000, 200);
2227*7f2fe78bSCy Schubert 		::Beep(200, 200);
2228*7f2fe78bSCy Schubert 		::Beep(700, 200);
2229*7f2fe78bSCy Schubert 	}
2230*7f2fe78bSCy Schubert }
2231*7f2fe78bSCy Schubert 
OnUpdateProperties(CCmdUI * pCmdUI)2232*7f2fe78bSCy Schubert VOID CLeashView::OnUpdateProperties(CCmdUI* pCmdUI)
2233*7f2fe78bSCy Schubert {
2234*7f2fe78bSCy Schubert     if (CLeashApp::m_hKrb5DLL)
2235*7f2fe78bSCy Schubert         pCmdUI->Enable();
2236*7f2fe78bSCy Schubert     else
2237*7f2fe78bSCy Schubert         pCmdUI->Enable(FALSE);
2238*7f2fe78bSCy Schubert }
2239*7f2fe78bSCy Schubert 
OnHelpLeash32()2240*7f2fe78bSCy Schubert void CLeashView::OnHelpLeash32()
2241*7f2fe78bSCy Schubert {
2242*7f2fe78bSCy Schubert #ifdef CALL_HTMLHELP
2243*7f2fe78bSCy Schubert 	AfxGetApp()->HtmlHelp(HID_LEASH_PROGRAM);
2244*7f2fe78bSCy Schubert #else
2245*7f2fe78bSCy Schubert     AfxGetApp()->WinHelp(HID_LEASH_PROGRAM);
2246*7f2fe78bSCy Schubert #endif
2247*7f2fe78bSCy Schubert }
2248*7f2fe78bSCy Schubert 
OnHelpKerberos()2249*7f2fe78bSCy Schubert void CLeashView::OnHelpKerberos()
2250*7f2fe78bSCy Schubert {
2251*7f2fe78bSCy Schubert #ifdef CALL_HTMLHELP
2252*7f2fe78bSCy Schubert     AfxGetApp()->HtmlHelp(HID_ABOUT_KERBEROS);
2253*7f2fe78bSCy Schubert #else
2254*7f2fe78bSCy Schubert     AfxGetApp()->WinHelp(HID_ABOUT_KERBEROS);
2255*7f2fe78bSCy Schubert #endif
2256*7f2fe78bSCy Schubert }
2257*7f2fe78bSCy Schubert 
OnHelpWhyuseleash32()2258*7f2fe78bSCy Schubert void CLeashView::OnHelpWhyuseleash32()
2259*7f2fe78bSCy Schubert {
2260*7f2fe78bSCy Schubert #ifdef CALL_HTMLHELP
2261*7f2fe78bSCy Schubert     AfxGetApp()->HtmlHelp(HID_WHY_USE_LEASH32);
2262*7f2fe78bSCy Schubert #else
2263*7f2fe78bSCy Schubert     AfxGetApp()->WinHelp(HID_WHY_USE_LEASH32);
2264*7f2fe78bSCy Schubert #endif
2265*7f2fe78bSCy Schubert }
2266*7f2fe78bSCy Schubert 
OnSysColorChange()2267*7f2fe78bSCy Schubert void CLeashView::OnSysColorChange()
2268*7f2fe78bSCy Schubert {
2269*7f2fe78bSCy Schubert     change_icon_size = FALSE;
2270*7f2fe78bSCy Schubert     CWnd::OnSysColorChange();
2271*7f2fe78bSCy Schubert     OnLargeIcons();
2272*7f2fe78bSCy Schubert     m_imageList.SetBkColor(GetSysColor(COLOR_WINDOW));
2273*7f2fe78bSCy Schubert     change_icon_size = TRUE;
2274*7f2fe78bSCy Schubert }
2275*7f2fe78bSCy Schubert 
2276*7f2fe78bSCy Schubert 
2277*7f2fe78bSCy Schubert LRESULT
OnObtainTGTWithParam(WPARAM wParam,LPARAM lParam)2278*7f2fe78bSCy Schubert CLeashView::OnObtainTGTWithParam(WPARAM wParam, LPARAM lParam)
2279*7f2fe78bSCy Schubert {
2280*7f2fe78bSCy Schubert     LRESULT res = 0;
2281*7f2fe78bSCy Schubert     char *param = 0;
2282*7f2fe78bSCy Schubert     LSH_DLGINFO_EX ldi;
2283*7f2fe78bSCy Schubert     ldi.size = sizeof(ldi);
2284*7f2fe78bSCy Schubert     ldi.dlgtype = DLGTYPE_PASSWD;
2285*7f2fe78bSCy Schubert     ldi.use_defaults = 1;
2286*7f2fe78bSCy Schubert     ldi.title = ldi.in.title;
2287*7f2fe78bSCy Schubert     ldi.username = ldi.in.username;
2288*7f2fe78bSCy Schubert     ldi.realm = ldi.in.realm;
2289*7f2fe78bSCy Schubert 
2290*7f2fe78bSCy Schubert     if (lParam)
2291*7f2fe78bSCy Schubert         param = (char *) MapViewOfFile((HANDLE)lParam,
2292*7f2fe78bSCy Schubert                                        FILE_MAP_ALL_ACCESS,
2293*7f2fe78bSCy Schubert                                        0,
2294*7f2fe78bSCy Schubert                                        0,
2295*7f2fe78bSCy Schubert                                        4096);
2296*7f2fe78bSCy Schubert 
2297*7f2fe78bSCy Schubert     if ( param ) {
2298*7f2fe78bSCy Schubert         if ( *param )
2299*7f2fe78bSCy Schubert             strcpy_s(ldi.in.title,param);
2300*7f2fe78bSCy Schubert         param += strlen(param) + 1;
2301*7f2fe78bSCy Schubert         if ( *param )
2302*7f2fe78bSCy Schubert             strcpy_s(ldi.in.username,param);
2303*7f2fe78bSCy Schubert         param += strlen(param) + 1;
2304*7f2fe78bSCy Schubert         if ( *param )
2305*7f2fe78bSCy Schubert             strcpy_s(ldi.in.realm,param);
2306*7f2fe78bSCy Schubert         param += strlen(param) + 1;
2307*7f2fe78bSCy Schubert 	if ( *param )
2308*7f2fe78bSCy Schubert 	    strcpy_s(ldi.in.ccache,param);
2309*7f2fe78bSCy Schubert     } else {
2310*7f2fe78bSCy Schubert         strcpy_s(ldi.in.title, "MIT Kerberos: Get Ticket");
2311*7f2fe78bSCy Schubert     }
2312*7f2fe78bSCy Schubert 
2313*7f2fe78bSCy Schubert     if (strlen(ldi.username) > 0 && strlen(ldi.realm) > 0)
2314*7f2fe78bSCy Schubert         ldi.dlgtype |= DLGFLAG_READONLYPRINC;
2315*7f2fe78bSCy Schubert 
2316*7f2fe78bSCy Schubert     res = pLeash_kinit_dlg_ex(m_hWnd, &ldi);
2317*7f2fe78bSCy Schubert     if (param)
2318*7f2fe78bSCy Schubert         UnmapViewOfFile(param);
2319*7f2fe78bSCy Schubert     if (lParam)
2320*7f2fe78bSCy Schubert         CloseHandle((HANDLE )lParam);
2321*7f2fe78bSCy Schubert     ::SendMessage(m_hWnd, WM_COMMAND, ID_UPDATE_DISPLAY, 0);
2322*7f2fe78bSCy Schubert     return res;
2323*7f2fe78bSCy Schubert }
2324*7f2fe78bSCy Schubert 
2325*7f2fe78bSCy Schubert 
2326*7f2fe78bSCy Schubert // Find the CCacheDisplayData corresponding to the specified item, if it exists
2327*7f2fe78bSCy Schubert static CCacheDisplayData *
FindCCacheDisplayData(int item,CCacheDisplayData * elem)2328*7f2fe78bSCy Schubert FindCCacheDisplayData(int item, CCacheDisplayData *elem)
2329*7f2fe78bSCy Schubert {
2330*7f2fe78bSCy Schubert     while (elem != NULL) {
2331*7f2fe78bSCy Schubert         if (elem->m_index == item)
2332*7f2fe78bSCy Schubert             break;
2333*7f2fe78bSCy Schubert         elem = elem->m_next;
2334*7f2fe78bSCy Schubert     }
2335*7f2fe78bSCy Schubert     return elem;
2336*7f2fe78bSCy Schubert }
2337*7f2fe78bSCy Schubert 
2338*7f2fe78bSCy Schubert 
OnLvnItemActivate(NMHDR * pNMHDR,LRESULT * pResult)2339*7f2fe78bSCy Schubert void CLeashView::OnLvnItemActivate(NMHDR *pNMHDR, LRESULT *pResult)
2340*7f2fe78bSCy Schubert {
2341*7f2fe78bSCy Schubert     LPNMITEMACTIVATE pNMIA = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
2342*7f2fe78bSCy Schubert     // TODO: Add your control notification handler code here
2343*7f2fe78bSCy Schubert     CCacheDisplayData *elem = FindCCacheDisplayData(pNMIA->iItem,
2344*7f2fe78bSCy Schubert                                                     m_ccacheDisplay);
2345*7f2fe78bSCy Schubert     if (elem != NULL) {
2346*7f2fe78bSCy Schubert         elem->m_expanded = !elem->m_expanded;
2347*7f2fe78bSCy Schubert         OnUpdateDisplay();
2348*7f2fe78bSCy Schubert     }
2349*7f2fe78bSCy Schubert     *pResult = 0;
2350*7f2fe78bSCy Schubert }
2351*7f2fe78bSCy Schubert 
2352*7f2fe78bSCy Schubert 
OnLvnKeydown(NMHDR * pNMHDR,LRESULT * pResult)2353*7f2fe78bSCy Schubert void CLeashView::OnLvnKeydown(NMHDR *pNMHDR, LRESULT *pResult)
2354*7f2fe78bSCy Schubert {
2355*7f2fe78bSCy Schubert     LPNMLVKEYDOWN pLVKeyDow = reinterpret_cast<LPNMLVKEYDOWN>(pNMHDR);
2356*7f2fe78bSCy Schubert     int expand = -1; // -1 = unchanged; 0 = collapse; 1 = expand
2357*7f2fe78bSCy Schubert     switch (pLVKeyDow->wVKey) {
2358*7f2fe78bSCy Schubert     case VK_RIGHT:
2359*7f2fe78bSCy Schubert         // expand focus item
2360*7f2fe78bSCy Schubert         expand = 1;
2361*7f2fe78bSCy Schubert         break;
2362*7f2fe78bSCy Schubert     case VK_LEFT:
2363*7f2fe78bSCy Schubert         // collapse focus item
2364*7f2fe78bSCy Schubert         expand = 0;
2365*7f2fe78bSCy Schubert         break;
2366*7f2fe78bSCy Schubert     default:
2367*7f2fe78bSCy Schubert         break;
2368*7f2fe78bSCy Schubert     }
2369*7f2fe78bSCy Schubert     if (expand >= 0) {
2370*7f2fe78bSCy Schubert         int focusedItem = GetListCtrl().GetNextItem(-1, LVNI_FOCUSED);
2371*7f2fe78bSCy Schubert         if (focusedItem >= 0) {
2372*7f2fe78bSCy Schubert             CCacheDisplayData *elem = FindCCacheDisplayData(focusedItem,
2373*7f2fe78bSCy Schubert                                                             m_ccacheDisplay);
2374*7f2fe78bSCy Schubert             if (elem != NULL) {
2375*7f2fe78bSCy Schubert                 if (elem->m_expanded != expand) {
2376*7f2fe78bSCy Schubert                     elem->m_expanded = expand;
2377*7f2fe78bSCy Schubert                     OnUpdateDisplay();
2378*7f2fe78bSCy Schubert                 }
2379*7f2fe78bSCy Schubert             }
2380*7f2fe78bSCy Schubert         }
2381*7f2fe78bSCy Schubert     }
2382*7f2fe78bSCy Schubert     *pResult = 0;
2383*7f2fe78bSCy Schubert }
2384*7f2fe78bSCy Schubert 
OnLvnItemchanging(NMHDR * pNMHDR,LRESULT * pResult)2385*7f2fe78bSCy Schubert void CLeashView::OnLvnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
2386*7f2fe78bSCy Schubert {
2387*7f2fe78bSCy Schubert     CCacheDisplayData *elem;
2388*7f2fe78bSCy Schubert     LRESULT result = 0;
2389*7f2fe78bSCy Schubert     LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2390*7f2fe78bSCy Schubert     // TODO: Add your control notification handler code here
2391*7f2fe78bSCy Schubert     if ((pNMLV->uNewState ^ pNMLV->uOldState) & LVIS_SELECTED) {
2392*7f2fe78bSCy Schubert         // selection state changing
2393*7f2fe78bSCy Schubert         elem = FindCCacheDisplayData(pNMLV->iItem, m_ccacheDisplay);
2394*7f2fe78bSCy Schubert         if (elem == NULL) {
2395*7f2fe78bSCy Schubert             // this is an individual ticket, not a cache, so prevent selection
2396*7f2fe78bSCy Schubert             if (pNMLV->uNewState & LVIS_SELECTED) {
2397*7f2fe78bSCy Schubert                 unsigned int newState =  pNMLV->uNewState & ~LVIS_SELECTED;
2398*7f2fe78bSCy Schubert                 result = 1; // suppress changes
2399*7f2fe78bSCy Schubert                 if (newState != pNMLV->uOldState) {
2400*7f2fe78bSCy Schubert                     // but need to make other remaining changes still
2401*7f2fe78bSCy Schubert                     GetListCtrl().SetItemState(pNMLV->iItem, newState,
2402*7f2fe78bSCy Schubert                                                newState ^ pNMLV->uOldState);
2403*7f2fe78bSCy Schubert                 }
2404*7f2fe78bSCy Schubert             }
2405*7f2fe78bSCy Schubert         } else {
2406*7f2fe78bSCy Schubert             elem->m_selected = (pNMLV->uNewState & LVIS_SELECTED) ? 1 : 0;
2407*7f2fe78bSCy Schubert         }
2408*7f2fe78bSCy Schubert     }
2409*7f2fe78bSCy Schubert     *pResult = result;
2410*7f2fe78bSCy Schubert }
2411*7f2fe78bSCy Schubert 
GetSubItemFont(int iItem,int iSubItem)2412*7f2fe78bSCy Schubert HFONT CLeashView::GetSubItemFont(int iItem, int iSubItem)
2413*7f2fe78bSCy Schubert {
2414*7f2fe78bSCy Schubert     HFONT retval = m_BaseFont;
2415*7f2fe78bSCy Schubert     int iColumn, columnSubItem = 0;
2416*7f2fe78bSCy Schubert 
2417*7f2fe78bSCy Schubert     // Translate subitem to column index
2418*7f2fe78bSCy Schubert     for (iColumn = 0; iColumn < NUM_VIEW_COLUMNS; iColumn++) {
2419*7f2fe78bSCy Schubert         if (sm_viewColumns[iColumn].m_enabled) {
2420*7f2fe78bSCy Schubert             if (columnSubItem == iSubItem)
2421*7f2fe78bSCy Schubert                 break;
2422*7f2fe78bSCy Schubert             else
2423*7f2fe78bSCy Schubert                 columnSubItem++;
2424*7f2fe78bSCy Schubert         }
2425*7f2fe78bSCy Schubert     }
2426*7f2fe78bSCy Schubert     switch (iColumn) {
2427*7f2fe78bSCy Schubert     case RENEWABLE_UNTIL:
2428*7f2fe78bSCy Schubert     case VALID_UNTIL:
2429*7f2fe78bSCy Schubert         retval = m_aListItemInfo[iItem].m_durationFont;
2430*7f2fe78bSCy Schubert         break;
2431*7f2fe78bSCy Schubert     default:
2432*7f2fe78bSCy Schubert         retval = m_aListItemInfo[iItem].m_font;
2433*7f2fe78bSCy Schubert         break;
2434*7f2fe78bSCy Schubert     }
2435*7f2fe78bSCy Schubert     return retval;
2436*7f2fe78bSCy Schubert }
2437*7f2fe78bSCy Schubert 
OnNMCustomdraw(NMHDR * pNMHDR,LRESULT * pResult)2438*7f2fe78bSCy Schubert void CLeashView::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
2439*7f2fe78bSCy Schubert {
2440*7f2fe78bSCy Schubert     HFONT font;
2441*7f2fe78bSCy Schubert     CCacheDisplayData *pElem;
2442*7f2fe78bSCy Schubert     *pResult = CDRF_DODEFAULT;
2443*7f2fe78bSCy Schubert     int iItem;
2444*7f2fe78bSCy Schubert 
2445*7f2fe78bSCy Schubert     LPNMLVCUSTOMDRAW pNMLVCD = reinterpret_cast<LPNMLVCUSTOMDRAW>(pNMHDR);
2446*7f2fe78bSCy Schubert     switch (pNMLVCD->nmcd.dwDrawStage) {
2447*7f2fe78bSCy Schubert     case CDDS_PREPAINT:
2448*7f2fe78bSCy Schubert         *pResult = CDRF_NOTIFYITEMDRAW;
2449*7f2fe78bSCy Schubert         break;
2450*7f2fe78bSCy Schubert     case CDDS_ITEMPREPAINT:
2451*7f2fe78bSCy Schubert         *pResult = CDRF_NOTIFYSUBITEMDRAW;
2452*7f2fe78bSCy Schubert         break;
2453*7f2fe78bSCy Schubert     case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
2454*7f2fe78bSCy Schubert         iItem = pNMLVCD->nmcd.dwItemSpec;
2455*7f2fe78bSCy Schubert         pElem = FindCCacheDisplayElem(m_ccacheDisplay, iItem);
2456*7f2fe78bSCy Schubert         font = GetSubItemFont(iItem, pNMLVCD->iSubItem);
2457*7f2fe78bSCy Schubert         SelectObject(pNMLVCD->nmcd.hdc, font);
2458*7f2fe78bSCy Schubert         if (pElem != NULL && pNMLVCD->iSubItem == 0) {
2459*7f2fe78bSCy Schubert             CListCtrl &list = GetListCtrl();
2460*7f2fe78bSCy Schubert             CRect drawRect, nextRect;
2461*7f2fe78bSCy Schubert             if (list.GetSubItemRect(iItem, 0, LVIR_BOUNDS, drawRect)) {
2462*7f2fe78bSCy Schubert                 HTHEME hTheme = OpenThemeData(pNMLVCD->nmcd.hdr.hwndFrom,
2463*7f2fe78bSCy Schubert                                               L"Explorer::TreeView");
2464*7f2fe78bSCy Schubert                 drawRect.right = drawRect.left +
2465*7f2fe78bSCy Schubert                                  (drawRect.bottom - drawRect.top);
2466*7f2fe78bSCy Schubert                 // @TODO: need hot states, too: TVP_HOTGLYPH, HGLPS_OPENED,
2467*7f2fe78bSCy Schubert                 //        HGLPS_CLOSED
2468*7f2fe78bSCy Schubert                 int state = pElem->m_expanded ? GLPS_OPENED : GLPS_CLOSED;
2469*7f2fe78bSCy Schubert                 DrawThemeBackground(hTheme,
2470*7f2fe78bSCy Schubert                                     pNMLVCD->nmcd.hdc,
2471*7f2fe78bSCy Schubert                                     TVP_GLYPH, state,
2472*7f2fe78bSCy Schubert                                     &drawRect, NULL);
2473*7f2fe78bSCy Schubert             }
2474*7f2fe78bSCy Schubert         }
2475*7f2fe78bSCy Schubert         *pResult = CDRF_NEWFONT;
2476*7f2fe78bSCy Schubert         break;
2477*7f2fe78bSCy Schubert     default:
2478*7f2fe78bSCy Schubert         break;
2479*7f2fe78bSCy Schubert     }
2480*7f2fe78bSCy Schubert }
2481