Source code of Windows XP (NT5)
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.

415 lines
11 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. audtfail.C
  5. Abstract:
  6. functions used to set the Crash on audit Fail paramter
  7. on the current system.
  8. Author:
  9. Bob Watson (a-robw)
  10. Revision History:
  11. 23 Dec 94
  12. --*/
  13. #include <windows.h>
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <c2dll.h>
  17. #include <c2inc.h>
  18. #include <c2utils.h>
  19. #include "c2funcs.h"
  20. #include "c2funres.h"
  21. // local constants
  22. // define action codes here. They are only meaningful in the
  23. // context of this module.
  24. #define AC_AUDITFAIL_NOCHANGE 0
  25. #define AC_AUDITFAIL_SET_CRASH 1
  26. #define AC_AUDITFAIL_SET_NOCRASH 2
  27. #define SECURE C2DLL_SECURE
  28. static
  29. BOOL
  30. SetAuditFailSetting (
  31. DWORD dwNewValue
  32. )
  33. {
  34. HKEY hKeyLsa = NULL;
  35. LONG lStatus = ERROR_SUCCESS;
  36. BOOL bReturn = FALSE;
  37. SET_WAIT_CURSOR;
  38. lStatus = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  39. GetStringResource (GetDllInstance(), IDS_LSA_KEY),
  40. 0L,
  41. KEY_SET_VALUE,
  42. &hKeyLsa);
  43. if (lStatus == ERROR_SUCCESS) {
  44. // key opened OK so set value
  45. lStatus = RegSetValueEx (
  46. hKeyLsa,
  47. GetStringResource (GetDllInstance(), IDS_AUDIT_FAIL_VALUE),
  48. 0L,
  49. REG_DWORD,
  50. (CONST LPBYTE)&dwNewValue,
  51. sizeof(DWORD));
  52. if (lStatus == ERROR_SUCCESS) {
  53. bReturn = TRUE;
  54. } else {
  55. bReturn = FALSE;
  56. }
  57. RegCloseKey (hKeyLsa);
  58. } else {
  59. bReturn = FALSE;
  60. SetLastError (ERROR_BADKEY);
  61. }
  62. SET_ARROW_CURSOR;
  63. return bReturn;
  64. }
  65. static
  66. BOOL
  67. GetAuditFailSetting (
  68. )
  69. {
  70. HKEY hKeyLsa = NULL;
  71. LONG lStatus = ERROR_SUCCESS;
  72. DWORD dwType = 0;
  73. DWORD dwValue = 0;
  74. DWORD dwValueSize = sizeof(DWORD);
  75. BOOL bReturn = FALSE;
  76. SET_WAIT_CURSOR;
  77. lStatus = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  78. GetStringResource (GetDllInstance(), IDS_LSA_KEY),
  79. 0L,
  80. KEY_READ,
  81. &hKeyLsa);
  82. if (lStatus == ERROR_SUCCESS) {
  83. // key opened OK so check value
  84. lStatus = RegQueryValueEx (
  85. hKeyLsa,
  86. (LPTSTR)GetStringResource (GetDllInstance(), IDS_AUDIT_FAIL_VALUE),
  87. (LPDWORD)NULL,
  88. &dwType,
  89. (LPBYTE)&dwValue,
  90. &dwValueSize);
  91. if (lStatus == ERROR_SUCCESS) {
  92. // value read successfully so check it out
  93. if (dwType == REG_DWORD) {
  94. // check value. The "C2" value is 1, any
  95. // other value is NOT C2
  96. if (dwValue == 1) {
  97. bReturn = TRUE;
  98. } else {
  99. bReturn = FALSE;
  100. }
  101. SetLastError (ERROR_SUCCESS);
  102. } else {
  103. // wrong data type returned
  104. bReturn = FALSE;
  105. SetLastError (ERROR_CANTREAD);
  106. }
  107. } else {
  108. // no value present
  109. bReturn = FALSE;
  110. SetLastError (ERROR_CANTREAD);
  111. }
  112. RegCloseKey (hKeyLsa);
  113. } else {
  114. bReturn = FALSE;
  115. SetLastError (ERROR_BADKEY);
  116. }
  117. SET_ARROW_CURSOR;
  118. return bReturn;
  119. }
  120. BOOL CALLBACK
  121. C2AuditFailDlgProc(
  122. IN HWND hDlg, // window handle of the dialog box
  123. IN UINT message, // type of message
  124. IN WPARAM wParam,
  125. IN LPARAM lParam
  126. )
  127. /*++
  128. Routine Description:
  129. Window procedure for Audit Failure dialog box
  130. Arguments:
  131. Standard DlgProc arguments
  132. ReturnValue:
  133. TRUE the message was handled by this routine
  134. FALSE DefDialogProc should handle the message
  135. --*/
  136. {
  137. static LPDWORD lpdwNewValue;
  138. DWORD dwLogSetting = 0;
  139. switch (message) {
  140. case WM_INITDIALOG:
  141. // save the pointer to the new value
  142. lpdwNewValue = (LPDWORD)lParam;
  143. // get Audit failure settings
  144. CheckDlgButton (hDlg, IDC_HALT_WHEN_LOG_FULL,
  145. (GetAuditFailSetting() ? CHECKED : UNCHECKED));
  146. SetFocus (GetDlgItem (hDlg, IDOK)); // set focus to OK Button
  147. return FALSE; // we don't want Windows to set the focus
  148. case WM_COMMAND:
  149. switch (LOWORD(wParam)){
  150. case IDOK:
  151. if (HIWORD(wParam) == BN_CLICKED) {
  152. // exit and return button that caused exit
  153. if (IsDlgButtonChecked (hDlg, IDC_HALT_WHEN_LOG_FULL) == CHECKED) {
  154. *lpdwNewValue = TRUE;
  155. EndDialog (hDlg, (int)LOWORD(wParam));
  156. } else {
  157. *lpdwNewValue = FALSE;
  158. EndDialog (hDlg, (int)LOWORD(wParam));
  159. }
  160. return TRUE;
  161. } else {
  162. return FALSE;
  163. }
  164. case IDCANCEL:
  165. if (HIWORD(wParam) == BN_CLICKED) {
  166. // exit and return button that caused exit
  167. *lpdwNewValue = 0;
  168. EndDialog (hDlg, (int)LOWORD(wParam));
  169. return TRUE;
  170. } else {
  171. return FALSE;
  172. }
  173. case IDC_C2:
  174. if (HIWORD(wParam) == BN_CLICKED) {
  175. CheckDlgButton (hDlg, IDC_HALT_WHEN_LOG_FULL, CHECKED);
  176. return TRUE;
  177. } else {
  178. return FALSE;
  179. }
  180. case IDC_HELP:
  181. PostMessage (GetParent(hDlg), UM_SHOW_CONTEXT_HELP, 0, 0);
  182. return TRUE;
  183. default:
  184. return FALSE;
  185. }
  186. default:
  187. return (FALSE); // Didn't process the message
  188. }
  189. }
  190. LONG
  191. C2QueryCrashAuditFail (
  192. IN LPARAM lParam
  193. )
  194. /*++
  195. Routine Description:
  196. Function called to find out if the OS/2 subsystem is installed
  197. on the system. For C2 compliance, OS/2 must not be
  198. allowed on the system.
  199. Arguments:
  200. Pointer to the Dll data block passed as an LPARAM.
  201. ReturnValue:
  202. ERROR_SUCCESS if the function succeeds otherwise a
  203. WIN32 error is returned if an error occurs
  204. --*/
  205. {
  206. PC2DLL_DATA pC2Data;
  207. DWORD dwLogSetting = 0;
  208. UINT nMsgString;
  209. if (lParam != 0) {
  210. pC2Data = (PC2DLL_DATA)lParam;
  211. pC2Data->lC2Compliance = SECURE; // assume true for now
  212. if (GetAuditFailSetting()) {
  213. pC2Data->lC2Compliance = SECURE;
  214. nMsgString = IDS_AUDIT_FAIL_CRASH;
  215. } else {
  216. pC2Data->lC2Compliance = C2DLL_NOT_SECURE;
  217. nMsgString = IDS_AUDIT_FAIL_NO_CRASH;
  218. }
  219. lstrcpy (pC2Data->szStatusName,
  220. GetStringResource (GetDllInstance(), nMsgString));
  221. } else {
  222. return ERROR_BAD_ARGUMENTS;
  223. }
  224. return ERROR_SUCCESS;
  225. }
  226. LONG
  227. C2SetCrashAuditFail (
  228. IN LPARAM lParam
  229. )
  230. /*++
  231. Routine Description:
  232. Function called to change the current state of this configuration
  233. item based on an action code passed in the DLL data block. If
  234. this function successfully sets the state of the configuration
  235. item, then the C2 Compliance flag and the Status string to reflect
  236. the new value of the configuration item.
  237. Arguments:
  238. Pointer to the Dll data block passed as an LPARAM.
  239. ReturnValue:
  240. ERROR_SUCCESS if the function succeeds otherwise a
  241. WIN32 error is returned if an error occurs
  242. --*/
  243. {
  244. PC2DLL_DATA pC2Data;
  245. UINT nMsgString;
  246. if (lParam != 0) {
  247. pC2Data = (PC2DLL_DATA)lParam;
  248. // action valie = the new value of the wrap setting
  249. if (pC2Data->lActionCode != AC_AUDITFAIL_NOCHANGE) {
  250. nMsgString = 0;
  251. if (pC2Data->lActionCode == AC_AUDITFAIL_SET_CRASH) {
  252. if (SetAuditFailSetting (1)) {
  253. pC2Data->lC2Compliance = SECURE;
  254. nMsgString = IDS_AUDIT_FAIL_CRASH;
  255. } else {
  256. DisplayDllMessageBox (
  257. pC2Data->hWnd,
  258. IDS_AUDIT_ERROR_NO_SET,
  259. IDS_AUDIT_CAPTION,
  260. MBOK_EXCLAIM);
  261. }
  262. } else if (pC2Data->lActionCode == AC_AUDITFAIL_SET_NOCRASH) {
  263. if (SetAuditFailSetting (0)) {
  264. pC2Data->lC2Compliance = C2DLL_NOT_SECURE;
  265. nMsgString = IDS_AUDIT_FAIL_NO_CRASH;
  266. } else {
  267. DisplayDllMessageBox (
  268. pC2Data->hWnd,
  269. IDS_AUDIT_ERROR_NO_SET,
  270. IDS_AUDIT_CAPTION,
  271. MBOK_EXCLAIM);
  272. }
  273. }
  274. if (nMsgString != 0) {
  275. // update status string if set was successful
  276. lstrcpy (pC2Data->szStatusName,
  277. GetStringResource (GetDllInstance(), nMsgString));
  278. }
  279. }
  280. // update action values
  281. pC2Data->lActionCode = 0;
  282. pC2Data->lActionValue = 0;
  283. } else {
  284. return ERROR_BAD_ARGUMENTS;
  285. }
  286. return ERROR_SUCCESS;
  287. }
  288. LONG
  289. C2DisplayCrashAuditFail (
  290. IN LPARAM lParam
  291. )
  292. /*++
  293. Routine Description:
  294. Function called to display more information on the configuration
  295. item and provide the user with the option to change the current
  296. setting (if appropriate). If the User "OK's" out of the UI,
  297. then the action code field in the DLL data block is set to the
  298. appropriate (and configuration item-specific) action code so the
  299. "Set" function can be called to perform the desired action. If
  300. the user Cancels out of the UI, then the Action code field is
  301. set to 0 (no action) and no action is performed.
  302. Arguments:
  303. Pointer to the Dll data block passed as an LPARAM.
  304. ReturnValue:
  305. ERROR_SUCCESS if the function succeeds otherwise a
  306. WIN32 error is returned if an error occurs
  307. --*/
  308. {
  309. PC2DLL_DATA pC2Data;
  310. DWORD dwNewValue;
  311. if (lParam != 0) {
  312. pC2Data = (PC2DLL_DATA)lParam;
  313. if (DialogBoxParam (
  314. GetDllInstance(),
  315. MAKEINTRESOURCE (IDD_AUDIT_FAIL),
  316. pC2Data->hWnd,
  317. C2AuditFailDlgProc,
  318. (LPARAM)&dwNewValue) == IDOK) {
  319. pC2Data->lActionValue = 0;
  320. if (dwNewValue) {
  321. pC2Data->lActionCode = AC_AUDITFAIL_SET_CRASH;
  322. } else {
  323. pC2Data->lActionCode = AC_AUDITFAIL_SET_NOCRASH;
  324. }
  325. } else {
  326. // no action
  327. pC2Data->lActionCode = AC_AUDITFAIL_NOCHANGE;
  328. }
  329. } else {
  330. return ERROR_BAD_ARGUMENTS;
  331. }
  332. return ERROR_SUCCESS;
  333. }
  334. 
  335.