1 //	**************************************************************************************
2 //	File:			LeashView.h
3 //	By:				Arthur David Leather
4 //	Created:		12/02/98
5 //	Copyright		@1998 Massachusetts Institute of Technology - All rights reserved.
6 //	Description:	H file for LeashView.cpp. Contains variables and functions
7 //					for the Leash FormView
8 //
9 //	History:
10 //
11 //	MM/DD/YY	Inits	Description of Change
12 //	12/02/98	ADL		Original
13 //	**************************************************************************************
14 
15 
16 #if !defined(AFX_LeashVIEW_H__6F45AD99_561B_11D0_8FCF_00C04FC2A0C2__INCLUDED_)
17 #define AFX_LeashVIEW_H__6F45AD99_561B_11D0_8FCF_00C04FC2A0C2__INCLUDED_
18 
19 #if _MSC_VER >= 1000
20 #pragma once
21 #endif // _MSC_VER >= 1000
22 
23 #define GOOD_TICKETS	1  // Don't change this value
24 #define EXPIRED_TICKETS 2  // Don't change this value
25 #define TICKETS_LOW		3
26 #define ONE_SECOND		1000
27 #define SMALL_ICONS     16
28 #define LARGE_ICONS     32
29 
30 #define UPDATE_DISPLAY_TIME 60  //seconds
31 
32 #define ACTIVE_CLOCK          0
33 #define LOW_CLOCK             1
34 #define EXPIRED_CLOCK         2
35 #define ACTIVE_TICKET         3
36 #define LOW_TICKET            4
37 #define EXPIRED_TICKET        5
38 #define TICKET_NOT_INSTALLED  6
39 #define ACTIVE_PARENT_NODE    7
40 #define LOW_PARENT_NODE       8
41 #define EXPIRED_PARENT_NODE   9
42 #define NONE_PARENT_NODE      10
43 #define LOW_TRAY_ICON         11
44 #define EXPIRED_TRAY_ICON     12
45 #define ACTIVE_TRAY_ICON      13
46 #define NONE_TRAY_ICON        14
47 #define TKT_ADDRESS           15
48 #define TKT_SESSION           16
49 #define TKT_ENCRYPTION        17
50 #define IMAGE_COUNT           18
51 
52 #define NODE_IS_EXPANDED 2
53 
54 #define CX_BORDER   1
55 #define CY_BORDER   1
56 
57 #ifdef NO_TICKETS
58 #undef NO_TICKETS // XXX - this is evil but necessary thanks to silliness...
59 #endif
60 
61 #define WM_TRAYICON (WM_USER+100)
62 #define WM_WARNINGPOPUP (WM_USER+101)
63 
64 enum ticketTimeLeft{NO_TICKETS, ZERO_MINUTES_LEFT, FIVE_MINUTES_LEFT, TEN_MINUTES_LEFT,
65 					FIFTEEN_MINUTES_LEFT, TWENTY_MINUTES_LEFT, PLENTY_OF_TIME,
66                     NOT_INSTALLED};
67 // Don't change 'NO_TICKET's' value
68 
69 class CLeashDebugWindow;
70 class ViewColumnInfo
71 {
72 public:
73     const char * m_name;
74     int m_enabled;
75     int m_id;
76     int m_columnWidth;
77 };
78 
79 enum eViewColumn {
80     PRINCIPAL,
81     TIME_ISSUED,
82     RENEWABLE_UNTIL,
83     VALID_UNTIL,
84     ENCRYPTION_TYPE,
85     TICKET_FLAGS,
86     CACHE_NAME,
87     NUM_VIEW_COLUMNS
88 };
89 
90 class CCacheDisplayData
91 {
92 public:
CCacheDisplayData(const char * ccache_name)93     CCacheDisplayData(const char *ccache_name) :
94       m_next(NULL),
95       m_ccacheName(strdup(ccache_name)),
96       m_index(-1),
97       m_focus(-1),
98       m_expanded(0),
99       m_selected(0),
100       m_isRenewable(0),
101       m_isDefault(0)
102     {
103     }
104 
~CCacheDisplayData()105     ~CCacheDisplayData()
106     {
107         if (m_ccacheName)
108             free(m_ccacheName);
109     }
110 
111     CCacheDisplayData *m_next;
112     char *m_ccacheName;
113     int m_index;               // item index in list view
114     int m_focus;               // sub-item with focus
115     unsigned int m_expanded;   // true when each individual ticket is displayed
116     unsigned int m_selected;   // true when this ccache is selected
117     unsigned int m_isRenewable; // true when tgt is renewable
118     unsigned int m_isDefault;  // true when this is the default ccache
119 };
120 
121 struct ListItemInfo
122 {
ListItemInfoListItemInfo123     ListItemInfo() : m_font(NULL), m_durationFont(NULL) {}
124     HFONT m_durationFont; // For renewable/valid until; italic when expired
125     HFONT m_font;         // For all other items
126 };
127 
128 class CLeashView : public CListView
129 {
130 private:
131 ////@#+Remove
132     CLeashDebugWindow*	m_pDebugWindow;
133     CCacheDisplayData*  m_ccacheDisplay;
134 	CImageList			m_imageList;
135 	CWinApp*			m_pApp;
136 	HTREEITEM			m_hPrincipal;
137 	HTREEITEM			m_hKerb5;
138     HTREEITEM           m_hk5tkt;
139 	TV_INSERTSTRUCT		m_tvinsert;
140 	HMENU				m_hMenu;
141     BOOL				m_startup;
142 	BOOL				m_isMinimum;
143 	BOOL				m_debugStartUp;
144 	BOOL				m_alreadyPlayed;
145     INT					m_upperCaseRealm;
146 	INT					m_destroyTicketsOnExit;
147 	INT					m_debugWindow;
148 	INT					m_largeIcons;
149 	INT					m_lowTicketAlarm;
150 	INT					m_hPrincipalState;
151 	INT					m_hKerb5State;
152     CString*            m_pWarningMessage;
153     BOOL                m_bIconAdded;
154     BOOL                m_bIconDeleted;
155     HFONT               m_BaseFont;
156     HFONT               m_BoldFont;
157     HFONT               m_ItalicFont;
158     HFONT               m_BoldItalicFont;
159     ListItemInfo*       m_aListItemInfo;
160 
161     static ViewColumnInfo sm_viewColumns[NUM_VIEW_COLUMNS];
162 
163     static INT		   	m_autoRenewTickets;
164     static INT          m_ticketStatusKrb5;
165     static INT          m_autoRenewalAttempted;
166 	static INT			m_warningOfTicketTimeLeftKrb5;
167     static INT			m_warningOfTicketTimeLeftLockKrb5;
168     static INT			m_updateDisplayCount;
169     static INT	        m_alreadyPlayedDisplayCount;
170     static time_t		m_ticketTimeLeft;
171     static BOOL			m_lowTicketAlarmSound;
172     static LONG         m_timerMsgNotInProgress;
173 
174     void ToggleViewColumn(eViewColumn viewOption);
175 	VOID ResetTreeNodes();
176     VOID ApplicationInfoMissingMsg();
177     VOID GetScrollBarState(CSize sizeClient, CSize& needSb,
178 	                       CSize& sizeRange, CPoint& ptMove,
179                            BOOL bInsideClient);
180     VOID UpdateBars();
181     VOID GetScrollBarSizes(CSize& sizeSb);
182     BOOL GetTrueClientSize(CSize& size, CSize& sizeSb);
183     HFONT GetSubItemFont(int iItem, int iSubItem);
184 
185     //void   GetRowWidthHeight(CDC* pDC, LPCSTR theString, int& nRowWidth,
186     //                         int& nRowHeight, int& nCharWidth);
187     static VOID	AlarmBeep();
188     static VOID	CALLBACK EXPORT TimerProc(HWND hWnd, UINT nMsg, UINT_PTR nIDEvent,
189 					  DWORD dwTime);
190     static VOID	UpdateTicketTime(TICKETINFO& ticketinfo);
191     static INT	GetLowTicketStatus(int);
192     static time_t	LeashTime();
193     static BOOL IsExpired(TicketList *ticket);
194     static BOOL IsExpired(TICKETINFO *info);
195     static VOID AddDisplayItem(CListCtrl &list,
196                                CCacheDisplayData *elem,
197                                int iItem,
198                                char *principal,
199                                time_t issued,
200                                time_t valid_until,
201                                time_t renew_until,
202                                char *encTypes,
203                                unsigned long flags,
204                                char *cache_name);
205 
206     void   SetTrayIcon(int nim, int state=0);
207     void   SetTrayText(int nim, CString tip);
208 
209     BOOL   UpdateDisplay();
210     static UINT InitTicket(void *);
211     static UINT RenewTicket(void *);
212     static UINT ImportTicket(void *);
213     // Queue a warning popup message.
214     // This is a workaround to the MFC deficiency that you cannot safely create
215     // a modal dialog while processing messages within AfxPreTranslateMessage()
216     // returns TRUE if message is queued successfully.
217     BOOL PostWarningMessage(const CString& message);
218     afx_msg LRESULT OnWarningPopup(WPARAM wParam, LPARAM lParam);
219 
220     BOOL    IsExpanded(TICKETINFO *);
221 
222 protected: // create from serialization only
223 	DECLARE_DYNCREATE(CLeashView)
224 
225 // Attributes
226 public:
227     CLeashView();
228 	//LeashDoc* GetDocument();
229 
230 	//{{AFX_DATA(CLeashView)
231 	enum { IDD = IDD_DIALOG1 };
232 		// NOTE: the ClassWizard will add data members here
233 	//}}AFX_DATA
234 
235 // Operations
236 public:
237 
238 // Overrides
239 	// ClassWizard generated virtual function overrides
240 	//{{AFX_VIRTUAL(CLeashView)
241 	public:
242 	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
243 	virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
244 	virtual VOID OnInitialUpdate();
245 	virtual BOOL PreTranslateMessage(MSG* pMsg);
246 	protected:
247 	virtual VOID OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
248 	//}}AFX_VIRTUAL
249 
250 // Implementation
251 public:
252 	virtual ~CLeashView();
253 
254 #ifdef _DEBUG
255 	virtual VOID AssertValid() const;
256 	virtual VOID Dump(CDumpContext& dc) const;
257 #endif
258 
259 // Generated message map functions
260 protected:
261 	//{{AFX_MSG(CLeashView)
262     afx_msg VOID OnItemexpandedTreeview(NMHDR* pNMHDR, LRESULT* pResult);
263 	afx_msg INT OnCreate(LPCREATESTRUCT lpCreateStruct);
264 	afx_msg VOID OnShowWindow(BOOL bShow, UINT nStatus);
265     afx_msg VOID OnClose(void);
266 	afx_msg VOID OnInitTicket();
267 	afx_msg VOID OnRenewTicket();
268 	afx_msg VOID OnDestroyTicket();
269 	afx_msg VOID OnMakeDefault();
270 	afx_msg VOID OnChangePassword();
271 	afx_msg VOID OnUpdateDisplay();
272 	afx_msg VOID OnSynTime();
273 	afx_msg VOID OnDebugMode();
274 	afx_msg VOID OnLargeIcons();
275 	afx_msg VOID OnTimeIssued();
276 	afx_msg VOID OnValidUntil();
277 	afx_msg VOID OnRenewableUntil();
278 	afx_msg VOID OnShowTicketFlags();
279 	afx_msg VOID OnEncryptionType();
280 	afx_msg VOID OnCcacheName();
281 	afx_msg VOID OnUppercaseRealm();
282 	afx_msg VOID OnKillTixOnExit();
283 	afx_msg VOID OnDestroy();
284 	afx_msg VOID OnUpdateDestroyTicket(CCmdUI* pCmdUI);
285 	afx_msg VOID OnUpdateInitTicket(CCmdUI* pCmdUI);
286 	afx_msg VOID OnUpdateRenewTicket(CCmdUI* pCmdUI);
287 	afx_msg VOID OnUpdateTimeIssued(CCmdUI* pCmdUI);
288 	afx_msg VOID OnUpdateValidUntil(CCmdUI* pCmdUI);
289 	afx_msg VOID OnUpdateRenewableUntil(CCmdUI* pCmdUI);
290 	afx_msg VOID OnUpdateShowTicketFlags(CCmdUI* pCmdUI);
291 	afx_msg VOID OnUpdateEncryptionType(CCmdUI* pCmdUI);
292 	afx_msg VOID OnUpdateCcacheName(CCmdUI* pCmdUI);
293 	afx_msg VOID OnUpdateUppercaseRealm(CCmdUI* pCmdUI);
294 	afx_msg VOID OnUpdateKillTixOnExit(CCmdUI* pCmdUI);
295 	afx_msg VOID OnUpdateLowTicketAlarm(CCmdUI* pCmdUI);
296 	afx_msg VOID OnUpdateAutoRenew(CCmdUI* pCmdUI);
297 	afx_msg VOID OnUpdateMakeDefault(CCmdUI* pCmdUI);
298 	afx_msg VOID OnAppAbout();
299 	afx_msg VOID OnUpdateDebugMode(CCmdUI* pCmdUI);
300 	afx_msg VOID OnUpdateCfgFiles(CCmdUI* pCmdUI);
301 	afx_msg VOID OnKrb5Properties();
302 	afx_msg void OnLeashProperties();
303 	afx_msg void OnLeashRestore();
304 	afx_msg void OnLeashMinimize();
305 	afx_msg void OnLowTicketAlarm();
306 	afx_msg void OnUpdateKrb5Properties(CCmdUI* pCmdUI);
307     afx_msg void OnKrbProperties();
308 	afx_msg void OnUpdateProperties(CCmdUI* pCmdUI);
309 	afx_msg void OnHelpKerberos();
310 	afx_msg void OnHelpLeash32();
311 	afx_msg void OnHelpWhyuseleash32();
312     afx_msg void OnSysColorChange();
313     afx_msg void OnAutoRenew();
314 	afx_msg LRESULT OnGoodbye(WPARAM wParam, LPARAM lParam);
315 	afx_msg LRESULT OnTrayIcon(WPARAM wParam, LPARAM lParam);
316     afx_msg LRESULT OnObtainTGTWithParam(WPARAM wParam, LPARAM lParam);
317     afx_msg void OnItemChanged(NMHDR* pNmHdr, LRESULT* pResult);
318     //}}AFX_MSG
319 	DECLARE_MESSAGE_MAP()
320 public:
321     afx_msg void OnLvnItemchanging(NMHDR *pNMHDR, LRESULT *pResult);
322     afx_msg void OnLvnItemActivate(NMHDR *pNMHDR, LRESULT *pResult);
323     afx_msg void OnLvnKeydown(NMHDR *pNMHDR, LRESULT *pResult);
324     afx_msg void OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult);
325 };
326 
327 /*
328 #ifndef _DEBUG  // debug version in CLeashView.cpp
329 inline LeashDoc* CLeashView::GetDocument()
330    { return (LeashDoc*)m_pDocument; }
331 #endif
332 */
333 
334 /////////////////////////////////////////////////////////////////////////////
335 
336 //{{AFX_INSERT_LOCATION}}
337 // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
338 
339 #endif // !defined(AFX_LeashVIEW_H__6F45AD99_561B_11D0_8FCF_00C04FC2A0C2__INCLUDED_)
340