Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

376 lines
8.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: scalert.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // SCAlert.cpp : Defines the class behaviors for the application.
  11. //
  12. #include "stdafx.h"
  13. #include "SCAlert.h"
  14. #include "miscdef.h"
  15. #include "cmnstat.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. LPTSTR szAlertOptionsValue = TEXT("AlertOptions");
  22. LPTSTR szScRemoveOptionsValue = TEXT("ScRemoveOption");
  23. LPTSTR szScLogonReaderValue = TEXT("ScLogonReader");
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CSCStatusApp
  26. BEGIN_MESSAGE_MAP(CSCStatusApp, CWinApp)
  27. //{{AFX_MSG_MAP(CSCStatusApp)
  28. // NOTE - the ClassWizard will add and remove mapping macros here.
  29. // DO NOT EDIT what you see in these blocks of generated code!
  30. //}}AFX_MSG
  31. END_MESSAGE_MAP()
  32. /////////////////////////////////////////////////////////////////////////////
  33. // The one and only CSCStatusApp object
  34. CSCStatusApp theApp;
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CSCStatusApp construction
  37. CSCStatusApp::CSCStatusApp()
  38. {
  39. m_strLogonReader.Empty();
  40. m_strRemovalText.Empty();
  41. }
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CSCStatusApp initialization
  44. BOOL CSCStatusApp::InitInstance()
  45. {
  46. // Locals
  47. BOOL fReturn = TRUE;
  48. DWORD dwStatus = 0;
  49. CNotifyWin* pNotifyWin = NULL;
  50. CString sWindowName;
  51. try
  52. {
  53. // set params
  54. m_hSCardContext = NULL;
  55. m_pMainWnd = NULL;
  56. m_dwState = k_State_Unknown;
  57. #ifdef ISOLATION_AWARE_ENABLED
  58. SHFusionInitializeFromModuleID (m_hInstance, 2);
  59. #endif
  60. SetAlertOptions();
  61. SetRemovalOptions();
  62. // Enable ActiveX control usage
  63. AfxEnableControlContainer();
  64. // Enable 3D Contols
  65. #ifdef _AFXDLL
  66. Enable3dControls(); // Call this when using MFC in a shared DLL
  67. #else
  68. Enable3dControlsStatic(); // Call this when linking to MFC statically
  69. #endif
  70. // Load the icons
  71. m_hIconCard = LoadIcon(MAKEINTRESOURCE(IDI_SC_READERLOADED_V2));
  72. m_hIconCalaisDown = LoadIcon(MAKEINTRESOURCE(IDI_SC_READERERR));
  73. m_hIconRdrEmpty = LoadIcon(MAKEINTRESOURCE(IDI_SC_READEREMPTY_V2));
  74. m_hIconCardInfo = LoadIcon(MAKEINTRESOURCE(IDI_SC_INFO));
  75. // Create the "main" window for this app
  76. m_pMainWnd = (CWnd*)new(CNotifyWin);
  77. if (m_pMainWnd == NULL)
  78. throw (FALSE);
  79. // Get pointer to CNotifyWin class
  80. pNotifyWin = (CNotifyWin*)m_pMainWnd;
  81. if (!pNotifyWin->FinalConstruct())
  82. {
  83. delete pNotifyWin;
  84. m_pMainWnd = NULL;
  85. throw (FALSE);
  86. }
  87. // Get the window name
  88. fReturn = sWindowName.LoadString(IDS_NOTIFY_WIN_NAME);
  89. if (!fReturn)
  90. throw (fReturn);
  91. // Create the window
  92. fReturn = m_pMainWnd->CreateEx( 0,
  93. pNotifyWin->m_sClassName,
  94. sWindowName,
  95. 0,
  96. 0,0,0,0,
  97. NULL,
  98. NULL,
  99. NULL);
  100. if (!fReturn)
  101. throw (fReturn);
  102. }
  103. catch (...) {
  104. fReturn = FALSE;
  105. TRACE_CATCH_UNKNOWN(_T("CSCStatusApp::InitInstance"));
  106. }
  107. return fReturn;
  108. }
  109. /*++
  110. void SetAlertOptions:
  111. Set User's alert options according to regkey settings (or default)
  112. Arguments:
  113. Return Value:
  114. None.
  115. Author:
  116. Amanda Matlosz 5/13/99
  117. --*/
  118. void CSCStatusApp::SetAlertOptions(bool fRead)
  119. {
  120. long lSts = ERROR_SUCCESS;
  121. HKEY hKey = NULL;
  122. // Either read the AlertOptions from the registry...
  123. if (fRead)
  124. {
  125. DWORD dwOption = -1;
  126. DWORD dwSize = sizeof(DWORD);
  127. DWORD dwType = 0;
  128. lSts = RegOpenKeyEx(
  129. HKEY_CURRENT_USER,
  130. szAlertOptionsKey,
  131. 0,
  132. KEY_READ,
  133. &hKey);
  134. if (ERROR_SUCCESS == lSts)
  135. {
  136. lSts = RegQueryValueEx(
  137. hKey,
  138. szAlertOptionsValue,
  139. 0,
  140. &dwType,
  141. (PBYTE)&dwOption,
  142. &dwSize
  143. );
  144. }
  145. if (k_AlertOption_IconMsg < dwOption)
  146. {
  147. // default value is "IconSoundMessage"
  148. m_dwAlertOption = k_AlertOption_IconSoundMsg;
  149. }
  150. else
  151. {
  152. m_dwAlertOption = dwOption;
  153. }
  154. }
  155. // Or set the value of the registry "AlertOptions"
  156. else
  157. {
  158. DWORD dw = 0; // don't really care about this param
  159. lSts = RegCreateKeyEx(
  160. HKEY_CURRENT_USER,
  161. szAlertOptionsKey,
  162. 0,
  163. TEXT(""),
  164. REG_OPTION_NON_VOLATILE,
  165. KEY_WRITE,
  166. NULL,
  167. &hKey,
  168. &dw);
  169. if (ERROR_SUCCESS == lSts)
  170. {
  171. RegSetValueEx(
  172. hKey,
  173. szAlertOptionsValue,
  174. 0,
  175. REG_DWORD,
  176. (PBYTE)&m_dwAlertOption,
  177. sizeof(DWORD)
  178. );
  179. }
  180. }
  181. // cleanup
  182. if (NULL != hKey)
  183. {
  184. RegCloseKey(hKey);
  185. }
  186. }
  187. /*++
  188. void SetRemovalOptions:
  189. Determine if user has set ScremoveOption for smart card logon, and
  190. set behavior for ScAlert accordingly.
  191. Arguments:
  192. Return Value:
  193. None.
  194. Author:
  195. Amanda Matlosz 6/02/99
  196. --*/
  197. void CSCStatusApp::SetRemovalOptions()
  198. {
  199. long lSts = ERROR_SUCCESS;
  200. HKEY hKey = NULL;
  201. DWORD dwType = 0;
  202. DWORD dwSize = 2*sizeof(TCHAR);
  203. TCHAR szRemoveOption[2];
  204. lSts = RegOpenKeyEx(
  205. HKEY_LOCAL_MACHINE,
  206. szScRemoveOptionKey,
  207. 0,
  208. KEY_READ,
  209. &hKey);
  210. if (ERROR_SUCCESS == lSts)
  211. {
  212. // this value must be either '0', '1', '2', or nonexistent.
  213. lSts = RegQueryValueEx(
  214. hKey,
  215. szScRemoveOptionsValue,
  216. 0,
  217. &dwType,
  218. (PBYTE)szRemoveOption,
  219. &dwSize
  220. );
  221. }
  222. if (ERROR_SUCCESS == lSts)
  223. {
  224. // if '1' or '2' find out what reader was used for logon, if any.
  225. if('1' == *szRemoveOption)
  226. {
  227. m_strRemovalText.LoadString(IDS_SC_REMOVAL_LOCK);
  228. }
  229. else if ('2' == *szRemoveOption)
  230. {
  231. m_strRemovalText.LoadString(IDS_SC_REMOVAL_LOGOFF);
  232. }
  233. }
  234. if (!m_strRemovalText.IsEmpty())
  235. {
  236. dwSize = 0;
  237. LPTSTR szLogonReader = NULL;
  238. lSts = RegQueryValueEx(
  239. hKey,
  240. szScLogonReaderValue,
  241. 0,
  242. &dwType,
  243. NULL,
  244. &dwSize
  245. );
  246. if (ERROR_SUCCESS == lSts)
  247. {
  248. szLogonReader = m_strLogonReader.GetBuffer(dwSize);
  249. lSts = RegQueryValueEx(
  250. hKey,
  251. szScLogonReaderValue,
  252. 0,
  253. &dwType,
  254. (PBYTE)szLogonReader,
  255. &dwSize
  256. );
  257. m_strLogonReader.ReleaseBuffer();
  258. }
  259. }
  260. // cleanup
  261. if (NULL != hKey)
  262. {
  263. RegCloseKey(hKey);
  264. }
  265. }
  266. /*++
  267. void ExitInstance:
  268. Does instance uninitialization
  269. Arguments:
  270. None.
  271. Return Value:
  272. Win32 error codes. 0 indicates no error occured.
  273. Author:
  274. Chris Dudley 7/30/1997
  275. Note:
  276. --*/
  277. int CSCStatusApp::ExitInstance()
  278. {
  279. // save the alert options
  280. SetAlertOptions(false);
  281. // Release calais if required
  282. if (m_hSCardContext != NULL)
  283. {
  284. SCardReleaseContext(m_hSCardContext);
  285. }
  286. // Make sure the window is deleted
  287. if (m_pMainWnd != NULL)
  288. {
  289. delete m_pMainWnd;
  290. }
  291. #ifdef ISOLATION_AWARE_ENABLED
  292. SHFusionUninitialize();
  293. #endif
  294. return CWinApp::ExitInstance();
  295. }