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. lastuser.C
  5. Abstract:
  6. functions used to set the last username display function
  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_LASTUSER_NOCHANGE 0
  25. #define AC_LASTUSER_UPDATE 1
  26. #define SECURE C2DLL_SECURE
  27. static
  28. BOOL
  29. SetLastUserDisplay (
  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_LAST_USER_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. SetLastError (lStatus);
  62. } else {
  63. bReturn = FALSE;
  64. SetLastError (ERROR_BADKEY);
  65. }
  66. SET_ARROW_CURSOR;
  67. return bReturn;
  68. }
  69. static
  70. BOOL
  71. GetLastUserDisplay (
  72. )
  73. {
  74. HKEY hKeyWinlogon = NULL;
  75. LONG lStatus = ERROR_SUCCESS;
  76. DWORD dwType = 0;
  77. BOOL bReturn = FALSE;
  78. TCHAR szValue[MAX_PATH];
  79. DWORD dwValueSize = MAX_PATH * sizeof(TCHAR);
  80. SET_WAIT_CURSOR;
  81. lStatus = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  82. GetStringResource (GetDllInstance(), IDS_WINLOGON_KEY),
  83. 0L,
  84. KEY_READ,
  85. &hKeyWinlogon);
  86. if (lStatus == ERROR_SUCCESS) {
  87. // key opened OK so check value
  88. lStatus = RegQueryValueEx (
  89. hKeyWinlogon,
  90. (LPTSTR)GetStringResource (GetDllInstance(), IDS_LAST_USER_VALUE),
  91. (LPDWORD)NULL,
  92. &dwType,
  93. (LPBYTE)szValue,
  94. &dwValueSize);
  95. if (lStatus == ERROR_SUCCESS) {
  96. // value read successfully so check it out
  97. if (dwType == REG_SZ) {
  98. // check value. The "C2" value is "1", any
  99. // other value is NOT C2
  100. if (lstrcmp(szValue, GetStringResource(GetDllInstance(), IDS_1)) == 0) {
  101. bReturn = TRUE;
  102. } else {
  103. bReturn = FALSE;
  104. }
  105. SetLastError (ERROR_SUCCESS);
  106. } else {
  107. // wrong data type returned
  108. bReturn = FALSE;
  109. SetLastError (ERROR_CANTREAD);
  110. }
  111. } else {
  112. // no value present
  113. bReturn = FALSE;
  114. SetLastError (ERROR_CANTREAD);
  115. }
  116. RegCloseKey (hKeyWinlogon);
  117. } else {
  118. bReturn = FALSE;
  119. SetLastError (ERROR_BADKEY);
  120. }
  121. SET_ARROW_CURSOR;
  122. return bReturn;
  123. }
  124. BOOL CALLBACK
  125. C2LastUserDlgProc(
  126. IN HWND hDlg, // window handle of the dialog box
  127. IN UINT message, // type of message
  128. IN WPARAM wParam,
  129. IN LPARAM lParam
  130. )
  131. /*++
  132. Routine Description:
  133. Window procedure for Last User Display dialog box
  134. Arguments:
  135. Standard DlgProc arguments
  136. ReturnValue:
  137. TRUE the message was handled by this routine
  138. FALSE DefDialogProc should handle the message
  139. --*/
  140. {
  141. static LPDWORD lpdwNewValue;
  142. DWORD dwLogSetting = 0;
  143. switch (message) {
  144. case WM_INITDIALOG:
  145. // save the pointer to the new value
  146. lpdwNewValue = (LPDWORD)lParam;
  147. // get Audit failure settings
  148. CheckDlgButton (hDlg, IDC_HIDE_LAST_USER,
  149. (GetLastUserDisplay() ? CHECKED : UNCHECKED));
  150. SetFocus (GetDlgItem (hDlg, IDOK)); // set focus to OK Button
  151. return FALSE; // we don't want Windows to set the focus
  152. case WM_COMMAND:
  153. switch (LOWORD(wParam)){
  154. case IDOK:
  155. if (HIWORD(wParam) == BN_CLICKED) {
  156. // exit and return button that caused exit
  157. if (IsDlgButtonChecked (hDlg, IDC_HIDE_LAST_USER) == CHECKED) {
  158. *lpdwNewValue = TRUE;
  159. EndDialog (hDlg, (int)LOWORD(wParam));
  160. } else {
  161. *lpdwNewValue = FALSE;
  162. EndDialog (hDlg, (int)LOWORD(wParam));
  163. }
  164. return TRUE;
  165. } else {
  166. return FALSE;
  167. }
  168. case IDCANCEL:
  169. if (HIWORD(wParam) == BN_CLICKED) {
  170. // exit and return button that caused exit
  171. *lpdwNewValue = 0;
  172. EndDialog (hDlg, (int)LOWORD(wParam));
  173. return TRUE;
  174. } else {
  175. return FALSE;
  176. }
  177. case IDC_C2:
  178. if (HIWORD(wParam) == BN_CLICKED) {
  179. CheckDlgButton (hDlg, IDC_HIDE_LAST_USER, CHECKED);
  180. return TRUE;
  181. } else {
  182. return FALSE;
  183. }
  184. case IDC_HELP:
  185. PostMessage (GetParent(hDlg), UM_SHOW_CONTEXT_HELP, 0, 0);
  186. return TRUE;
  187. default:
  188. return FALSE;
  189. }
  190. default:
  191. return (FALSE); // Didn't process the message
  192. }
  193. }
  194. LONG
  195. C2QueryLastUser (
  196. IN LPARAM lParam
  197. )
  198. /*++
  199. Routine Description:
  200. Function called to find out if the OS/2 subsystem is installed
  201. on the system. For C2 compliance, OS/2 must not be
  202. allowed on the system.
  203. Arguments:
  204. Pointer to the Dll data block passed as an LPARAM.
  205. ReturnValue:
  206. ERROR_SUCCESS if the function succeeds otherwise a
  207. WIN32 error is returned if an error occurs
  208. --*/
  209. {
  210. PC2DLL_DATA pC2Data;
  211. DWORD dwLogSetting = 0;
  212. UINT nMsgString;
  213. if (lParam != 0) {
  214. pC2Data = (PC2DLL_DATA)lParam;
  215. pC2Data->lC2Compliance = SECURE; // assume true for now
  216. if (GetLastUserDisplay()) {
  217. pC2Data->lC2Compliance = SECURE;
  218. nMsgString = IDS_LAST_USER_HIDDEN;
  219. } else {
  220. pC2Data->lC2Compliance = C2DLL_NOT_SECURE;
  221. nMsgString = IDS_LAST_USER_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. C2SetLastUser (
  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_LASTUSER_NOCHANGE) {
  254. nMsgString = 0;
  255. if (pC2Data->lActionCode == AC_LASTUSER_UPDATE) {
  256. if (pC2Data->lActionValue) {
  257. if (SetLastUserDisplay (TRUE)) {
  258. pC2Data->lC2Compliance = SECURE;
  259. nMsgString = IDS_LAST_USER_HIDDEN;
  260. } else {
  261. DisplayDllMessageBox (
  262. pC2Data->hWnd,
  263. IDS_LAST_USER_ERROR_NO_SET,
  264. IDS_LAST_USER_CAPTION,
  265. MBOK_EXCLAIM);
  266. }
  267. } else {
  268. if (SetLastUserDisplay (FALSE)) {
  269. pC2Data->lC2Compliance = C2DLL_NOT_SECURE;
  270. nMsgString = IDS_LAST_USER_DISPLAYED;
  271. } else {
  272. DisplayDllMessageBox (
  273. pC2Data->hWnd,
  274. IDS_LAST_USER_ERROR_NO_SET,
  275. IDS_LAST_USER_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. C2DisplayLastUser (
  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_LAST_USER),
  322. pC2Data->hWnd,
  323. C2LastUserDlgProc,
  324. (LPARAM)&dwNewValue) == IDOK) {
  325. pC2Data->lActionValue = dwNewValue;
  326. pC2Data->lActionCode = AC_LASTUSER_UPDATE;
  327. } else {
  328. // no action
  329. pC2Data->lActionCode = AC_LASTUSER_NOCHANGE;
  330. }
  331. } else {
  332. return ERROR_BAD_ARGUMENTS;
  333. }
  334. return ERROR_SUCCESS;
  335. }
  336. 
  337.