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.

490 lines
15 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. SecLog.C
  5. Abstract:
  6. functions used to set the Security Log size settings
  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 <tchar.h>
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <c2dll.h>
  18. #include <c2inc.h>
  19. #include <c2utils.h>
  20. #include "c2funcs.h"
  21. #include "c2funres.h"
  22. // local constants
  23. #define DAYS_NUM_LENGTH 3
  24. #define SECONDS_PER_DAY 86400
  25. // define action codes here. They are only meaningful in the
  26. // context of this module.
  27. #define AC_SECLOG_NOCHANGE 0
  28. #define AC_SECLOG_NEWVALUE 1
  29. #define SECURE C2DLL_C2
  30. static
  31. BOOL
  32. SetSecurityLogWrapSetting (
  33. DWORD dwNewValue
  34. )
  35. {
  36. HKEY hKeySecLog = NULL;
  37. LONG lStatus = ERROR_SUCCESS;
  38. BOOL bReturn = FALSE;
  39. SET_WAIT_CURSOR;
  40. lStatus = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  41. GetStringResource (GetDllInstance(), IDS_SECLOG_WRAP_KEY),
  42. 0L,
  43. KEY_SET_VALUE,
  44. &hKeySecLog);
  45. if (lStatus == ERROR_SUCCESS) {
  46. // key opened OK so set value
  47. lStatus = RegSetValueEx (
  48. hKeySecLog,
  49. GetStringResource (GetDllInstance(), IDS_SECLOG_WRAP_VALUE),
  50. 0L,
  51. REG_DWORD,
  52. (CONST LPBYTE)&dwNewValue,
  53. sizeof(DWORD));
  54. if (lStatus == ERROR_SUCCESS) {
  55. bReturn = TRUE;
  56. } else {
  57. bReturn = FALSE;
  58. }
  59. RegCloseKey (hKeySecLog);
  60. } else {
  61. bReturn = FALSE;
  62. SetLastError (ERROR_BADKEY);
  63. }
  64. SET_ARROW_CURSOR;
  65. return bReturn;
  66. }
  67. static
  68. DWORD
  69. GetSecurityLogWrapSetting (
  70. )
  71. {
  72. HKEY hKeySecLog = NULL;
  73. LONG lStatus = ERROR_SUCCESS;
  74. DWORD dwType = 0;
  75. DWORD dwValue = 0;
  76. DWORD dwValueSize = sizeof(DWORD);
  77. SET_WAIT_CURSOR;
  78. lStatus = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  79. GetStringResource (GetDllInstance(), IDS_SECLOG_WRAP_KEY),
  80. 0L,
  81. KEY_READ,
  82. &hKeySecLog);
  83. if (lStatus == ERROR_SUCCESS) {
  84. // key opened OK so check value
  85. lStatus = RegQueryValueEx (
  86. hKeySecLog,
  87. (LPTSTR)GetStringResource (GetDllInstance(), IDS_SECLOG_WRAP_VALUE),
  88. (LPDWORD)NULL,
  89. &dwType,
  90. (LPBYTE)&dwValue,
  91. &dwValueSize);
  92. if (lStatus == ERROR_SUCCESS) {
  93. // value read successfully so check it out
  94. if (dwType == REG_DWORD) {
  95. // check value. The "C2" value is 0xFFFFFFFF, any
  96. // other value is NOT C2
  97. SetLastError (ERROR_SUCCESS);
  98. } else {
  99. // wrong data type returned
  100. dwValue = 0;
  101. SetLastError (ERROR_CANTREAD);
  102. }
  103. } else {
  104. dwValue = 0;
  105. SetLastError (ERROR_CANTREAD);
  106. }
  107. RegCloseKey (hKeySecLog);
  108. } else {
  109. dwValue = 0;
  110. SetLastError (ERROR_BADKEY);
  111. }
  112. SET_ARROW_CURSOR;
  113. return dwValue;
  114. }
  115. BOOL CALLBACK
  116. C2SecLogDlgProc(
  117. IN HWND hDlg, // window handle of the dialog box
  118. IN UINT message, // type of message
  119. IN WPARAM wParam,
  120. IN LPARAM lParam
  121. )
  122. /*++
  123. Routine Description:
  124. Window procedure for Security Log dialog box
  125. Arguments:
  126. Standard DlgProc arguments
  127. ReturnValue:
  128. TRUE the message was handled by this routine
  129. FALSE DefDialogProc should handle the message
  130. --*/
  131. {
  132. static LPDWORD lpdwNewValue;
  133. DWORD dwLogSetting = 0;
  134. int nButton;
  135. DWORD dwDays;
  136. TCHAR szDays[DAYS_NUM_LENGTH+1];
  137. switch (message) {
  138. case WM_INITDIALOG:
  139. // save the pointer to the new value
  140. lpdwNewValue = (LPDWORD)lParam;
  141. // get Security Log Wrap setting
  142. dwLogSetting = GetSecurityLogWrapSetting();
  143. if (dwLogSetting == 0xFFFFFFFF) {
  144. // the log does not wrap, that is the C2 value
  145. nButton = IDC_DO_NOT_OVERWRITE;
  146. EnableWindow (GetDlgItem(hDlg, IDC_DAYS), FALSE);
  147. } else if (dwLogSetting == 0) {
  148. // the security log will overwrite events as needed
  149. nButton = IDC_OVERWRITE_AS_NEEDED;
  150. EnableWindow (GetDlgItem(hDlg, IDC_DAYS), FALSE);
  151. } else {
  152. // the security log will overwrite events older than x days
  153. nButton = IDC_OVERWRITE_OLDER;
  154. // (log setting is returned in seconds, so they must be converted
  155. // to integer days.
  156. dwDays = dwLogSetting / SECONDS_PER_DAY;
  157. _stprintf (szDays, TEXT("%3d"), dwDays);
  158. EnableWindow (GetDlgItem(hDlg, IDC_DAYS), TRUE);
  159. SetDlgItemText (hDlg, IDC_DAYS, szDays);
  160. SendDlgItemMessage (hDlg, IDC_DAYS, EM_LIMITTEXT,
  161. (WPARAM)DAYS_NUM_LENGTH, 0);
  162. }
  163. CheckRadioButton (hDlg,
  164. IDC_OVERWRITE_AS_NEEDED,
  165. IDC_DO_NOT_OVERWRITE,
  166. nButton);
  167. SendDlgItemMessage (hDlg, IDC_DAYS, EM_LIMITTEXT,
  168. (WPARAM)DAYS_NUM_LENGTH, 0);
  169. SetFocus (GetDlgItem (hDlg, IDOK)); // set focus to OK Button
  170. return FALSE; // we don't want Windows to set the focus
  171. case WM_COMMAND:
  172. switch (LOWORD(wParam)){
  173. case IDOK:
  174. if (HIWORD(wParam) == BN_CLICKED) {
  175. // exit and return button that caused exit
  176. if (IsDlgButtonChecked (hDlg, IDC_OVERWRITE_AS_NEEDED) == CHECKED) {
  177. *lpdwNewValue = 0;
  178. EndDialog (hDlg, (int)LOWORD(wParam));
  179. } else if (IsDlgButtonChecked (hDlg, IDC_DO_NOT_OVERWRITE) == CHECKED) {
  180. *lpdwNewValue = 0xFFFFFFFF;
  181. EndDialog (hDlg, (int)LOWORD(wParam));
  182. } else if (IsDlgButtonChecked (hDlg, IDC_OVERWRITE_OLDER) == CHECKED) {
  183. GetDlgItemText (hDlg, IDC_DAYS, szDays, DAYS_NUM_LENGTH);
  184. dwDays = _tcstol (szDays, NULL, 0);
  185. if (dwDays == 0) {
  186. MessageBeep (MB_ICONEXCLAMATION);
  187. DisplayDllMessageBox (
  188. hDlg,
  189. IDS_SECLOG_DAYS_ERROR,
  190. IDS_SECLOG_CAPTION,
  191. MBOK_EXCLAIM);
  192. SendDlgItemMessage (hDlg, IDC_DAYS, EM_SETSEL,
  193. (WPARAM)0, (LPARAM)-1);
  194. SetFocus (GetDlgItem (hDlg, IDC_DAYS));
  195. } else {
  196. *lpdwNewValue = dwDays * SECONDS_PER_DAY;
  197. EndDialog (hDlg, (int)LOWORD(wParam));
  198. }
  199. }
  200. return TRUE;
  201. } else {
  202. return FALSE;
  203. }
  204. case IDCANCEL:
  205. if (HIWORD(wParam) == BN_CLICKED) {
  206. // exit and return button that caused exit
  207. *lpdwNewValue = 0;
  208. EndDialog (hDlg, (int)LOWORD(wParam));
  209. return TRUE;
  210. } else {
  211. return FALSE;
  212. }
  213. case IDC_C2:
  214. if (HIWORD(wParam) == BN_CLICKED) {
  215. CheckRadioButton (hDlg,
  216. IDC_OVERWRITE_AS_NEEDED,
  217. IDC_DO_NOT_OVERWRITE,
  218. IDC_DO_NOT_OVERWRITE);
  219. return TRUE;
  220. } else {
  221. return FALSE;
  222. }
  223. case IDC_OVERWRITE_AS_NEEDED:
  224. case IDC_OVERWRITE_OLDER:
  225. case IDC_DO_NOT_OVERWRITE:
  226. CheckRadioButton (hDlg,
  227. IDC_OVERWRITE_AS_NEEDED,
  228. IDC_DO_NOT_OVERWRITE,
  229. LOWORD (wParam));
  230. if (LOWORD(wParam) == IDC_OVERWRITE_OLDER) {
  231. EnableWindow (GetDlgItem(hDlg, IDC_DAYS), TRUE);
  232. } else {
  233. EnableWindow (GetDlgItem(hDlg, IDC_DAYS), FALSE);
  234. }
  235. return TRUE;
  236. case IDC_HELP:
  237. PostMessage (GetParent(hDlg), UM_SHOW_CONTEXT_HELP, 0, 0);
  238. return TRUE;
  239. default:
  240. return FALSE;
  241. }
  242. default:
  243. return (FALSE); // Didn't process the message
  244. }
  245. }
  246. LONG
  247. C2QuerySecLogWrap (
  248. IN LPARAM lParam
  249. )
  250. /*++
  251. Routine Description:
  252. Function called to find out if the OS/2 subsystem is installed
  253. on the system. For C2 compliance, OS/2 must not be
  254. allowed on the system.
  255. Arguments:
  256. Pointer to the Dll data block passed as an LPARAM.
  257. ReturnValue:
  258. ERROR_SUCCESS if the function succeeds otherwise a
  259. WIN32 error is returned if an error occurs
  260. --*/
  261. {
  262. PC2DLL_DATA pC2Data;
  263. DWORD dwLogSetting = 0;
  264. DWORD dwDays;
  265. if (lParam != 0) {
  266. pC2Data = (PC2DLL_DATA)lParam;
  267. pC2Data->lC2Compliance = SECURE; // assume true for now
  268. // check for correct Security Log Wrap setting
  269. dwLogSetting = GetSecurityLogWrapSetting();
  270. if (dwLogSetting == 0xFFFFFFFF) {
  271. // the log does not wrap, that is the C2 value
  272. pC2Data->lC2Compliance = SECURE;
  273. lstrcpy (pC2Data->szStatusName,
  274. GetStringResource (GetDllInstance(), IDS_SECLOG_IS_C2));
  275. } else if (dwLogSetting == 0) {
  276. if (GetLastError() == ERROR_SUCCESS) {
  277. // the security log will overwrite events as needed
  278. pC2Data->lC2Compliance = C2DLL_NOT_SECURE;
  279. lstrcpy (pC2Data->szStatusName,
  280. GetStringResource (GetDllInstance(), IDS_SECLOG_WRAPS_AS_NEEDED));
  281. } else {
  282. // an error occured while reading the value
  283. pC2Data->lC2Compliance = C2DLL_NOT_SECURE;
  284. lstrcpy (pC2Data->szStatusName,
  285. GetStringResource (GetDllInstance(), IDS_UNABLE_READ));
  286. }
  287. } else {
  288. // the security log will overwrite events older than x days
  289. pC2Data->lC2Compliance = C2DLL_NOT_SECURE;
  290. // (log setting is returned in seconds, so they must be converted
  291. // to integer days.
  292. dwDays = dwLogSetting / SECONDS_PER_DAY;
  293. _stprintf (pC2Data->szStatusName,
  294. GetStringResource (GetDllInstance(), IDS_SECLOG_OVERWRITE_OLD),
  295. dwDays);
  296. }
  297. } else {
  298. return ERROR_BAD_ARGUMENTS;
  299. }
  300. return ERROR_SUCCESS;
  301. }
  302. LONG
  303. C2SetSecLogWrap (
  304. IN LPARAM lParam
  305. )
  306. /*++
  307. Routine Description:
  308. Function called to change the current state of this configuration
  309. item based on an action code passed in the DLL data block. If
  310. this function successfully sets the state of the configuration
  311. item, then the C2 Compliance flag and the Status string to reflect
  312. the new value of the configuration item.
  313. Arguments:
  314. Pointer to the Dll data block passed as an LPARAM.
  315. ReturnValue:
  316. ERROR_SUCCESS if the function succeeds otherwise a
  317. WIN32 error is returned if an error occurs
  318. --*/
  319. {
  320. PC2DLL_DATA pC2Data;
  321. DWORD dwLogSetting;
  322. DWORD dwDays;
  323. if (lParam != 0) {
  324. pC2Data = (PC2DLL_DATA)lParam;
  325. // action valie = the new value of the wrap setting
  326. if (pC2Data->lActionCode == AC_SECLOG_NEWVALUE) {
  327. if (SetSecurityLogWrapSetting((DWORD)pC2Data->lActionValue)) {
  328. // set new settings
  329. dwLogSetting = GetSecurityLogWrapSetting();
  330. if (dwLogSetting == 0xFFFFFFFF) {
  331. // the log does not wrap, that is the C2 value
  332. pC2Data->lC2Compliance = SECURE;
  333. lstrcpy (pC2Data->szStatusName,
  334. GetStringResource (GetDllInstance(), IDS_SECLOG_IS_C2));
  335. } else if (dwLogSetting == 0) {
  336. // the security log will overwrite events as needed
  337. pC2Data->lC2Compliance = C2DLL_NOT_SECURE;
  338. lstrcpy (pC2Data->szStatusName,
  339. GetStringResource (GetDllInstance(), IDS_SECLOG_WRAPS_AS_NEEDED));
  340. } else {
  341. // the security log will overwrite events older than x days
  342. pC2Data->lC2Compliance = C2DLL_NOT_SECURE;
  343. // (log setting is returned in seconds, so they must be converted
  344. // to integer days.
  345. dwDays = dwLogSetting / SECONDS_PER_DAY;
  346. _stprintf (pC2Data->szStatusName,
  347. GetStringResource (GetDllInstance(), IDS_SECLOG_OVERWRITE_OLD),
  348. dwDays);
  349. }
  350. } else {
  351. DisplayDllMessageBox (
  352. pC2Data->hWnd,
  353. IDS_SECLOG_ERROR_NO_SET,
  354. IDS_SECLOG_CAPTION,
  355. MBOK_EXCLAIM);
  356. }
  357. }
  358. // update action values
  359. pC2Data->lActionCode = 0;
  360. pC2Data->lActionValue = 0;
  361. } else {
  362. return ERROR_BAD_ARGUMENTS;
  363. }
  364. return ERROR_SUCCESS;
  365. }
  366. LONG
  367. C2DisplaySecLogWrap (
  368. IN LPARAM lParam
  369. )
  370. /*++
  371. Routine Description:
  372. Function called to display more information on the configuration
  373. item and provide the user with the option to change the current
  374. setting (if appropriate). If the User "OK's" out of the UI,
  375. then the action code field in the DLL data block is set to the
  376. appropriate (and configuration item-specific) action code so the
  377. "Set" function can be called to perform the desired action. If
  378. the user Cancels out of the UI, then the Action code field is
  379. set to 0 (no action) and no action is performed.
  380. Arguments:
  381. Pointer to the Dll data block passed as an LPARAM.
  382. ReturnValue:
  383. ERROR_SUCCESS if the function succeeds otherwise a
  384. WIN32 error is returned if an error occurs
  385. --*/
  386. {
  387. PC2DLL_DATA pC2Data;
  388. DWORD dwNewValue;
  389. if (lParam != 0) {
  390. pC2Data = (PC2DLL_DATA)lParam;
  391. if (DialogBoxParam (
  392. GetDllInstance(),
  393. MAKEINTRESOURCE (IDD_SECLOG_WRAP),
  394. pC2Data->hWnd,
  395. C2SecLogDlgProc,
  396. (LPARAM)&dwNewValue) == IDOK) {
  397. pC2Data->lActionValue = (LONG)dwNewValue;
  398. pC2Data->lActionCode = AC_SECLOG_NEWVALUE;
  399. } else {
  400. // no action
  401. pC2Data->lActionCode = AC_SECLOG_NOCHANGE;
  402. }
  403. } else {
  404. return ERROR_BAD_ARGUMENTS;
  405. }
  406. return ERROR_SUCCESS;
  407. }
  408. 
  409.