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.

445 lines
12 KiB

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