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.

369 lines
8.0 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. SetAlertOptions();
  58. SetRemovalOptions();
  59. // Enable ActiveX control usage
  60. AfxEnableControlContainer();
  61. // Enable 3D Contols
  62. #ifdef _AFXDLL
  63. Enable3dControls(); // Call this when using MFC in a shared DLL
  64. #else
  65. Enable3dControlsStatic(); // Call this when linking to MFC statically
  66. #endif
  67. // Load the icons
  68. m_hIconCard = LoadIcon(MAKEINTRESOURCE(IDI_SC_READERLOADED_V2));
  69. m_hIconCalaisDown = LoadIcon(MAKEINTRESOURCE(IDI_SC_READERERR));
  70. m_hIconRdrEmpty = LoadIcon(MAKEINTRESOURCE(IDI_SC_READEREMPTY_V2));
  71. m_hIconCardInfo = LoadIcon(MAKEINTRESOURCE(IDI_SC_INFO));
  72. // Create the "main" window for this app
  73. m_pMainWnd = (CWnd*)new(CNotifyWin);
  74. if (m_pMainWnd == NULL)
  75. throw (FALSE);
  76. // Get pointer to CNotifyWin class
  77. pNotifyWin = (CNotifyWin*)m_pMainWnd;
  78. if (!pNotifyWin->FinalConstruct())
  79. {
  80. delete pNotifyWin;
  81. m_pMainWnd = NULL;
  82. throw (FALSE);
  83. }
  84. // Get the window name
  85. fReturn = sWindowName.LoadString(IDS_NOTIFY_WIN_NAME);
  86. if (!fReturn)
  87. throw (fReturn);
  88. // Create the window
  89. fReturn = m_pMainWnd->CreateEx( 0,
  90. pNotifyWin->m_sClassName,
  91. sWindowName,
  92. 0,
  93. 0,0,0,0,
  94. NULL,
  95. NULL,
  96. NULL);
  97. if (!fReturn)
  98. throw (fReturn);
  99. }
  100. catch (...) {
  101. fReturn = FALSE;
  102. TRACE_CATCH_UNKNOWN(_T("CSCStatusApp::InitInstance"));
  103. }
  104. return fReturn;
  105. }
  106. /*++
  107. void SetAlertOptions:
  108. Set User's alert options according to regkey settings (or default)
  109. Arguments:
  110. Return Value:
  111. None.
  112. Author:
  113. Amanda Matlosz 5/13/99
  114. --*/
  115. void CSCStatusApp::SetAlertOptions(bool fRead)
  116. {
  117. long lSts = ERROR_SUCCESS;
  118. HKEY hKey = NULL;
  119. // Either read the AlertOptions from the registry...
  120. if (fRead)
  121. {
  122. DWORD dwOption = -1;
  123. DWORD dwSize = sizeof(DWORD);
  124. DWORD dwType = 0;
  125. lSts = RegOpenKeyEx(
  126. HKEY_CURRENT_USER,
  127. szAlertOptionsKey,
  128. 0,
  129. KEY_READ,
  130. &hKey);
  131. if (ERROR_SUCCESS == lSts)
  132. {
  133. lSts = RegQueryValueEx(
  134. hKey,
  135. szAlertOptionsValue,
  136. 0,
  137. &dwType,
  138. (PBYTE)&dwOption,
  139. &dwSize
  140. );
  141. }
  142. if (k_AlertOption_IconMsg < dwOption)
  143. {
  144. // default value is "IconSoundMessage"
  145. m_dwAlertOption = k_AlertOption_IconSoundMsg;
  146. }
  147. else
  148. {
  149. m_dwAlertOption = dwOption;
  150. }
  151. }
  152. // Or set the value of the registry "AlertOptions"
  153. else
  154. {
  155. DWORD dw = 0; // don't really care about this param
  156. lSts = RegCreateKeyEx(
  157. HKEY_CURRENT_USER,
  158. szAlertOptionsKey,
  159. 0,
  160. TEXT(""),
  161. REG_OPTION_NON_VOLATILE,
  162. KEY_WRITE,
  163. NULL,
  164. &hKey,
  165. &dw);
  166. if (ERROR_SUCCESS == lSts)
  167. {
  168. RegSetValueEx(
  169. hKey,
  170. szAlertOptionsValue,
  171. 0,
  172. REG_DWORD,
  173. (PBYTE)&m_dwAlertOption,
  174. sizeof(DWORD)
  175. );
  176. }
  177. }
  178. // cleanup
  179. if (NULL != hKey)
  180. {
  181. RegCloseKey(hKey);
  182. }
  183. }
  184. /*++
  185. void SetRemovalOptions:
  186. Determine if user has set ScremoveOption for smart card logon, and
  187. set behavior for ScAlert accordingly.
  188. Arguments:
  189. Return Value:
  190. None.
  191. Author:
  192. Amanda Matlosz 6/02/99
  193. --*/
  194. void CSCStatusApp::SetRemovalOptions()
  195. {
  196. long lSts = ERROR_SUCCESS;
  197. HKEY hKey = NULL;
  198. DWORD dwType = 0;
  199. DWORD dwSize = 2*sizeof(TCHAR);
  200. TCHAR szRemoveOption[2];
  201. lSts = RegOpenKeyEx(
  202. HKEY_LOCAL_MACHINE,
  203. szScRemoveOptionKey,
  204. 0,
  205. KEY_READ,
  206. &hKey);
  207. if (ERROR_SUCCESS == lSts)
  208. {
  209. // this value must be either '0', '1', '2', or nonexistent.
  210. lSts = RegQueryValueEx(
  211. hKey,
  212. szScRemoveOptionsValue,
  213. 0,
  214. &dwType,
  215. (PBYTE)szRemoveOption,
  216. &dwSize
  217. );
  218. }
  219. if (ERROR_SUCCESS == lSts)
  220. {
  221. // if '1' or '2' find out what reader was used for logon, if any.
  222. if('1' == *szRemoveOption)
  223. {
  224. m_strRemovalText.LoadString(IDS_SC_REMOVAL_LOCK);
  225. }
  226. else if ('2' == *szRemoveOption)
  227. {
  228. m_strRemovalText.LoadString(IDS_SC_REMOVAL_LOGOFF);
  229. }
  230. }
  231. if (!m_strRemovalText.IsEmpty())
  232. {
  233. dwSize = 0;
  234. LPTSTR szLogonReader = NULL;
  235. lSts = RegQueryValueEx(
  236. hKey,
  237. szScLogonReaderValue,
  238. 0,
  239. &dwType,
  240. NULL,
  241. &dwSize
  242. );
  243. if (ERROR_SUCCESS == lSts)
  244. {
  245. szLogonReader = m_strLogonReader.GetBuffer(dwSize);
  246. lSts = RegQueryValueEx(
  247. hKey,
  248. szScLogonReaderValue,
  249. 0,
  250. &dwType,
  251. (PBYTE)szLogonReader,
  252. &dwSize
  253. );
  254. m_strLogonReader.ReleaseBuffer();
  255. }
  256. }
  257. // cleanup
  258. if (NULL != hKey)
  259. {
  260. RegCloseKey(hKey);
  261. }
  262. }
  263. /*++
  264. void ExitInstance:
  265. Does instance uninitialization
  266. Arguments:
  267. None.
  268. Return Value:
  269. Win32 error codes. 0 indicates no error occured.
  270. Author:
  271. Chris Dudley 7/30/1997
  272. Note:
  273. --*/
  274. int CSCStatusApp::ExitInstance()
  275. {
  276. // save the alert options
  277. SetAlertOptions(false);
  278. // Release calais if required
  279. if (m_hSCardContext != NULL)
  280. {
  281. SCardReleaseContext(m_hSCardContext);
  282. }
  283. // Make sure the window is deleted
  284. if (m_pMainWnd != NULL)
  285. {
  286. delete m_pMainWnd;
  287. }
  288. return CWinApp::ExitInstance();
  289. }