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.

414 lines
11 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. drvsnprt.C
  5. Abstract:
  6. functions used to set the Drive Letter and Printer Assignment
  7. on the current system.
  8. Author:
  9. Bob Watson (a-robw)
  10. Revision History:
  11. 3 Jul 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_DRIVES_AND_PRINTER_NOCHANGE 0
  25. #define AC_DRIVES_AND_PRINTER_SET_ADMIN 1
  26. #define AC_DRIVES_AND_PRINTER_SET_ANYONE 2
  27. #define SECURE C2DLL_SECURE
  28. static
  29. BOOL
  30. SetDrivesAndPrinterSetting (
  31. DWORD dwNewValue
  32. )
  33. {
  34. HKEY hKeySM = NULL;
  35. LONG lStatus = ERROR_SUCCESS;
  36. BOOL bReturn = FALSE;
  37. SET_WAIT_CURSOR;
  38. lStatus = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  39. GetStringResource (GetDllInstance(), IDS_SESSION_MANAGER_KEY),
  40. 0L,
  41. KEY_SET_VALUE,
  42. &hKeySM);
  43. if (lStatus == ERROR_SUCCESS) {
  44. // key opened OK so set value
  45. lStatus = RegSetValueEx (
  46. hKeySM,
  47. GetStringResource (GetDllInstance(), IDS_PROTECTION_MODE_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 (hKeySM);
  58. } else {
  59. bReturn = FALSE;
  60. SetLastError (ERROR_BADKEY);
  61. }
  62. SET_ARROW_CURSOR;
  63. return bReturn;
  64. }
  65. static
  66. BOOL
  67. GetDrivesAndPrinterSetting (
  68. )
  69. {
  70. HKEY hKeySM = 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_SESSION_MANAGER_KEY),
  79. 0L,
  80. KEY_READ,
  81. &hKeySM);
  82. if (lStatus == ERROR_SUCCESS) {
  83. // key opened OK so check value
  84. lStatus = RegQueryValueEx (
  85. hKeySM,
  86. (LPTSTR)GetStringResource (GetDllInstance(), IDS_PROTECTION_MODE_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 (hKeySM);
  113. } else {
  114. bReturn = FALSE;
  115. SetLastError (ERROR_BADKEY);
  116. }
  117. SET_ARROW_CURSOR;
  118. return bReturn;
  119. }
  120. BOOL CALLBACK
  121. C2DrivesAndPrinterDlgProc(
  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 Drives and Printer assignment 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_ADMIN_ASSIGN_DRIVES,
  145. (GetDrivesAndPrinterSetting() ? 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_ADMIN_ASSIGN_DRIVES) == 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_ADMIN_ASSIGN_DRIVES, 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. C2QueryAssignDrivesAndPrinter (
  192. IN LPARAM lParam
  193. )
  194. /*++
  195. Routine Description:
  196. Function called to find out if only the Admin can assign drives and printer
  197. on the system. For C2 compliance,
  198. Arguments:
  199. Pointer to the Dll data block passed as an LPARAM.
  200. ReturnValue:
  201. ERROR_SUCCESS if the function succeeds otherwise a
  202. WIN32 error is returned if an error occurs
  203. --*/
  204. {
  205. PC2DLL_DATA pC2Data;
  206. DWORD dwLogSetting = 0;
  207. UINT nMsgString;
  208. if (lParam != 0) {
  209. pC2Data = (PC2DLL_DATA)lParam;
  210. pC2Data->lC2Compliance = SECURE; // assume true for now
  211. if (GetDrivesAndPrinterSetting()) {
  212. pC2Data->lC2Compliance = SECURE;
  213. nMsgString = IDS_ONLY_ADMINS_ASSIGN_DRIVE;
  214. } else {
  215. pC2Data->lC2Compliance = C2DLL_NOT_SECURE;
  216. nMsgString = IDS_ANYONE_CAN_ASSIGN_DRIVE;
  217. }
  218. lstrcpy (pC2Data->szStatusName,
  219. GetStringResource (GetDllInstance(), nMsgString));
  220. } else {
  221. return ERROR_BAD_ARGUMENTS;
  222. }
  223. return ERROR_SUCCESS;
  224. }
  225. LONG
  226. C2SetAssignDrivesAndPrinter (
  227. IN LPARAM lParam
  228. )
  229. /*++
  230. Routine Description:
  231. Function called to change the current state of this configuration
  232. item based on an action code passed in the DLL data block. If
  233. this function successfully sets the state of the configuration
  234. item, then the C2 Compliance flag and the Status string to reflect
  235. the new value of the configuration item.
  236. Arguments:
  237. Pointer to the Dll data block passed as an LPARAM.
  238. ReturnValue:
  239. ERROR_SUCCESS if the function succeeds otherwise a
  240. WIN32 error is returned if an error occurs
  241. --*/
  242. {
  243. PC2DLL_DATA pC2Data;
  244. UINT nMsgString;
  245. if (lParam != 0) {
  246. pC2Data = (PC2DLL_DATA)lParam;
  247. // action valie = the new value of the wrap setting
  248. if (pC2Data->lActionCode != AC_DRIVES_AND_PRINTER_NOCHANGE) {
  249. nMsgString = 0;
  250. if (pC2Data->lActionCode == AC_DRIVES_AND_PRINTER_SET_ADMIN) {
  251. if (SetDrivesAndPrinterSetting (1)) {
  252. pC2Data->lC2Compliance = SECURE;
  253. nMsgString = IDS_ONLY_ADMINS_ASSIGN_DRIVE;
  254. } else {
  255. DisplayDllMessageBox (
  256. pC2Data->hWnd,
  257. IDS_AUDIT_ERROR_NO_SET,
  258. IDS_AUDIT_CAPTION,
  259. MBOK_EXCLAIM);
  260. }
  261. } else if (pC2Data->lActionCode == AC_DRIVES_AND_PRINTER_SET_ANYONE) {
  262. if (SetDrivesAndPrinterSetting (0)) {
  263. pC2Data->lC2Compliance = C2DLL_NOT_SECURE;
  264. nMsgString = IDS_ANYONE_CAN_ASSIGN_DRIVE;
  265. } else {
  266. DisplayDllMessageBox (
  267. pC2Data->hWnd,
  268. IDS_AUDIT_ERROR_NO_SET,
  269. IDS_AUDIT_CAPTION,
  270. MBOK_EXCLAIM);
  271. }
  272. }
  273. if (nMsgString != 0) {
  274. // update status string if set was successful
  275. lstrcpy (pC2Data->szStatusName,
  276. GetStringResource (GetDllInstance(), nMsgString));
  277. }
  278. }
  279. // update action values
  280. pC2Data->lActionCode = 0;
  281. pC2Data->lActionValue = 0;
  282. } else {
  283. return ERROR_BAD_ARGUMENTS;
  284. }
  285. return ERROR_SUCCESS;
  286. }
  287. LONG
  288. C2DisplayAssignDrivesAndPrinter (
  289. IN LPARAM lParam
  290. )
  291. /*++
  292. Routine Description:
  293. Function called to display more information on the configuration
  294. item and provide the user with the option to change the current
  295. setting (if appropriate). If the User "OK's" out of the UI,
  296. then the action code field in the DLL data block is set to the
  297. appropriate (and configuration item-specific) action code so the
  298. "Set" function can be called to perform the desired action. If
  299. the user Cancels out of the UI, then the Action code field is
  300. set to 0 (no action) and no action is performed.
  301. Arguments:
  302. Pointer to the Dll data block passed as an LPARAM.
  303. ReturnValue:
  304. ERROR_SUCCESS if the function succeeds otherwise a
  305. WIN32 error is returned if an error occurs
  306. --*/
  307. {
  308. PC2DLL_DATA pC2Data;
  309. DWORD dwNewValue;
  310. if (lParam != 0) {
  311. pC2Data = (PC2DLL_DATA)lParam;
  312. if (DialogBoxParam (
  313. GetDllInstance(),
  314. MAKEINTRESOURCE (IDD_DRIVES_AND_PRINTERS),
  315. pC2Data->hWnd,
  316. C2DrivesAndPrinterDlgProc,
  317. (LPARAM)&dwNewValue) == IDOK) {
  318. pC2Data->lActionValue = 0;
  319. if (dwNewValue) {
  320. pC2Data->lActionCode = AC_DRIVES_AND_PRINTER_SET_ADMIN;
  321. } else {
  322. pC2Data->lActionCode = AC_DRIVES_AND_PRINTER_SET_ANYONE;
  323. }
  324. } else {
  325. // no action
  326. pC2Data->lActionCode = AC_DRIVES_AND_PRINTER_NOCHANGE;
  327. }
  328. } else {
  329. return ERROR_BAD_ARGUMENTS;
  330. }
  331. return ERROR_SUCCESS;
  332. }
  333. 
  334.