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.

418 lines
11 KiB

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