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.

619 lines
14 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: wlx.c
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 7-15-94 RichardW Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "testgina.h"
  18. HANDLE hThread;
  19. SID_IDENTIFIER_AUTHORITY gSystemSidAuthority = SECURITY_NT_AUTHORITY;
  20. SID_IDENTIFIER_AUTHORITY gLocalSidAuthority = SECURITY_LOCAL_SID_AUTHORITY;
  21. WLX_MPR_NOTIFY_INFO GlobalMprInfo;
  22. WCHAR GlobalProviderName[128];
  23. HANDLE hToken;
  24. void
  25. LockTestGina(void)
  26. {
  27. FLAG_OFF(fTestGina, GINA_LOGGEDON_OK);
  28. FLAG_ON(fTestGina, GINA_DISPLAYLOCK_OK);
  29. FLAG_ON(fTestGina, GINA_WKSTALOCK_OK);
  30. UpdateGinaState(UPDATE_LOCK_WKSTA);
  31. UpdateMenuBar();
  32. }
  33. void
  34. UnlockTestGina(void)
  35. {
  36. FLAG_OFF(fTestGina, GINA_DISPLAYLOCK_OK);
  37. FLAG_OFF(fTestGina, GINA_WKSTALOCK_OK);
  38. FLAG_ON(fTestGina, GINA_LOGGEDON_OK);
  39. UpdateGinaState(UPDATE_UNLOCK_WKSTA);
  40. UpdateMenuBar();
  41. }
  42. LogoffUser(void)
  43. {
  44. CloseHandle(hToken);
  45. FLAG_OFF(fTestGina, GINA_LOGGEDON_OK);
  46. FLAG_OFF(fTestGina, GINA_DISPLAYLOCK_OK);
  47. FLAG_OFF(fTestGina, GINA_WKSTALOCK_OK);
  48. FLAG_ON(fTestGina, GINA_LOGGEDOUT_OK);
  49. FLAG_ON(fTestGina, GINA_DISPLAY_OK);
  50. UpdateGinaState(UPDATE_LOGOFF);
  51. UpdateMenuBar();
  52. return(0);
  53. }
  54. BOOLEAN
  55. LoadGinaDll(void)
  56. {
  57. hDllInstance = LoadLibrary(szGinaDll);
  58. if (!hDllInstance)
  59. {
  60. TestGinaError(GINAERR_LOAD_FAILED, TEXT("LoadGinaDll"));
  61. }
  62. pWlxNegotiate = (PWLX_NEGOTIATE) GetProcAddress(hDllInstance, WLX_NEGOTIATE_NAME);
  63. if (!pWlxNegotiate)
  64. {
  65. TestGinaError(GINAERR_MISSING_FUNCTION, TEXT(WLX_NEGOTIATE_NAME));
  66. }
  67. pWlxInitialize = (PWLX_INITIALIZE) GetProcAddress(hDllInstance, WLX_INITIALIZE_NAME);
  68. if (!pWlxInitialize)
  69. {
  70. TestGinaError(GINAERR_MISSING_FUNCTION, TEXT(WLX_INITIALIZE_NAME));
  71. }
  72. pWlxDisplaySASNotice = (PWLX_DISPLAYSASNOTICE) GetProcAddress(hDllInstance, WLX_DISPLAYSASNOTICE_NAME);
  73. if (!pWlxDisplaySASNotice)
  74. {
  75. TestGinaError(GINAERR_MISSING_FUNCTION, TEXT(WLX_DISPLAYSASNOTICE_NAME));
  76. }
  77. pWlxLoggedOutSAS = (PWLX_LOGGEDOUTSAS) GetProcAddress(hDllInstance, WLX_LOGGEDOUTSAS_NAME);
  78. if (!pWlxLoggedOutSAS)
  79. {
  80. TestGinaError(GINAERR_MISSING_FUNCTION, TEXT(WLX_LOGGEDOUTSAS_NAME));
  81. }
  82. pWlxActivateUserShell = (PWLX_ACTIVATEUSERSHELL) GetProcAddress(hDllInstance, WLX_ACTIVATEUSERSHELL_NAME);
  83. if (!pWlxActivateUserShell)
  84. {
  85. TestGinaError(GINAERR_MISSING_FUNCTION, TEXT(WLX_ACTIVATEUSERSHELL_NAME));
  86. }
  87. pWlxLoggedOnSAS = (PWLX_LOGGEDONSAS) GetProcAddress(hDllInstance, WLX_LOGGEDONSAS_NAME);
  88. if (!pWlxLoggedOnSAS)
  89. {
  90. TestGinaError(GINAERR_MISSING_FUNCTION, TEXT(WLX_LOGGEDONSAS_NAME));
  91. }
  92. pWlxDisplayLockedNotice = (PWLX_DISPLAYLOCKEDNOTICE) GetProcAddress(hDllInstance, WLX_DISPLAYLOCKED_NAME);
  93. if (!pWlxDisplayLockedNotice)
  94. {
  95. TestGinaError(GINAERR_MISSING_FUNCTION, TEXT(WLX_DISPLAYLOCKED_NAME));
  96. }
  97. pWlxWkstaLockedSAS = (PWLX_WKSTALOCKEDSAS) GetProcAddress(hDllInstance, WLX_WKSTALOCKEDSAS_NAME);
  98. if (!pWlxWkstaLockedSAS)
  99. {
  100. TestGinaError(GINAERR_MISSING_FUNCTION, TEXT(WLX_WKSTALOCKEDSAS_NAME));
  101. }
  102. pWlxLogoff = (PWLX_LOGOFF) GetProcAddress(hDllInstance, WLX_LOGOFF_NAME);
  103. if (!pWlxLogoff)
  104. {
  105. TestGinaError(GINAERR_MISSING_FUNCTION, TEXT(WLX_LOGOFF_NAME));
  106. }
  107. pWlxShutdown = (PWLX_SHUTDOWN) GetProcAddress(hDllInstance, WLX_SHUTDOWN_NAME);
  108. if (!pWlxShutdown)
  109. {
  110. TestGinaError(GINAERR_MISSING_FUNCTION, TEXT(WLX_SHUTDOWN_NAME));
  111. }
  112. FLAG_ON(fTestGina, GINA_NEGOTIATE_OK);
  113. UpdateMenuBar();
  114. return(TRUE);
  115. }
  116. BOOLEAN
  117. TestNegotiate(void)
  118. {
  119. BOOL ret;
  120. if (!TEST_FLAG(fTestGina, GINA_NEGOTIATE_OK) ||
  121. !TEST_FLAG(fTestGina, GINA_DLL_KNOWN))
  122. {
  123. TestGinaError(0, TEXT("TestNegotiate"));
  124. }
  125. if (TEST_FLAG(GinaBreakFlags, BREAK_NEGOTIATE))
  126. {
  127. LogEvent(0, "About to call WlxNegotiate(%d, @%#x):\n",
  128. WLX_CURRENT_VERSION, & DllVersion);
  129. if (AmIBeingDebugged())
  130. {
  131. DebugBreak();
  132. }
  133. }
  134. ret = pWlxNegotiate(WLX_CURRENT_VERSION, & DllVersion );
  135. if (TEST_FLAG(GinaBreakFlags, BREAK_NEGOTIATE))
  136. {
  137. LogEvent(0, "Back from WlxNegotiate() @%#x = %d \n",
  138. & DllVersion, DllVersion);
  139. if (AmIBeingDebugged())
  140. {
  141. DebugBreak();
  142. }
  143. }
  144. if (DllVersion > WLX_CURRENT_VERSION)
  145. {
  146. TestGinaError(GINAERR_INVALID_LEVEL, TEXT("TestNegotiate"));
  147. }
  148. FLAG_OFF(fTestGina, GINA_NEGOTIATE_OK);
  149. FLAG_ON(fTestGina, GINA_INITIALIZE_OK);
  150. UpdateMenuBar();
  151. GinaState = Winsta_Initialize;
  152. LastRetCode = WLX_SAS_ACTION_BOOL_RET;
  153. LastBoolRet = ret;
  154. UpdateStatusBar();
  155. return(TRUE);
  156. }
  157. BOOLEAN
  158. TestInitialize(void)
  159. {
  160. PVOID pContext = NULL;
  161. BOOL ret;
  162. if (!TEST_FLAG(fTestGina, GINA_INITIALIZE_OK))
  163. {
  164. TestGinaError(0, TEXT("TestInitialize"));
  165. }
  166. AssociateHandle((HANDLE) 1);
  167. UpdateGinaState(UPDATE_INITIALIZE);
  168. FLAG_OFF(fTestGina, GINA_INITIALIZE_OK);
  169. FLAG_ON(fTestGina, GINA_LOGGEDOUT_OK);
  170. FLAG_ON(fTestGina, GINA_SHUTDOWN_OK);
  171. FLAG_ON(fTestGina, GINA_DISPLAY_OK);
  172. UpdateMenuBar();
  173. if (TEST_FLAG(GinaBreakFlags, BREAK_INITIALIZE))
  174. {
  175. LogEvent(0, "About to call WlxInitialize(%ws, 1, @%#x, @%#x)\n",
  176. TEXT("winsta0"), &WlxDispatchTable, &pContext);
  177. if (AmIBeingDebugged())
  178. {
  179. DebugBreak();
  180. }
  181. }
  182. ret = pWlxInitialize( TEXT("winsta0"),
  183. (HANDLE) 1,
  184. NULL,
  185. &WlxDispatchTable,
  186. &pContext );
  187. StashContext(pContext);
  188. GinaState = Winsta_NoOne;
  189. LastRetCode = WLX_SAS_ACTION_BOOL_RET;
  190. LastBoolRet = ret;
  191. UpdateStatusBar();
  192. EnableOptions( TRUE );
  193. return(TRUE);
  194. }
  195. DWORD
  196. TestDisplaySASNoticeWorker(PVOID pvIgnored)
  197. {
  198. PVOID pContext = NULL;
  199. DWORD err;
  200. if (!TEST_FLAG(fTestGina, GINA_DISPLAY_OK))
  201. {
  202. TestGinaError(0, TEXT("TestDisplaySASNotice"));
  203. }
  204. pContext = GetContext();
  205. if (TEST_FLAG(GinaBreakFlags, BREAK_DISPLAY))
  206. {
  207. LogEvent(0, "About to call WlxDisplaySASNotice(%#x) \n", pContext);
  208. if (AmIBeingDebugged())
  209. {
  210. DebugBreak();
  211. }
  212. }
  213. pWlxDisplaySASNotice(pContext);
  214. err = GetLastError();
  215. return(err == 0 ? TRUE : FALSE);
  216. }
  217. BOOLEAN
  218. TestDisplaySASNotice(void)
  219. {
  220. DWORD tid;
  221. UpdateGinaState(UPDATE_DISPLAY_NOTICE);
  222. hThread = CreateThread( NULL, 0, TestDisplaySASNoticeWorker,
  223. NULL, 0, &tid);
  224. CloseHandle(hThread);
  225. return(TRUE);
  226. }
  227. /***************************************************************************\
  228. * CreateLogonSid
  229. *
  230. * Creates a logon sid for a new logon.
  231. *
  232. * If LogonId is non NULL, on return the LUID that is part of the logon
  233. * sid is returned here.
  234. *
  235. * History:
  236. * 12-05-91 Davidc Created
  237. \***************************************************************************/
  238. PSID
  239. CreateLogonSid(
  240. PLUID LogonId OPTIONAL
  241. )
  242. {
  243. NTSTATUS Status;
  244. ULONG Length;
  245. PSID Sid;
  246. LUID Luid;
  247. //
  248. // Generate a locally unique id to include in the logon sid
  249. //
  250. Status = NtAllocateLocallyUniqueId(&Luid);
  251. if (!NT_SUCCESS(Status)) {
  252. TestGinaError(0, TEXT("CreateLogonSid"));
  253. return(NULL);
  254. }
  255. //
  256. // Allocate space for the sid and fill it in.
  257. //
  258. Length = RtlLengthRequiredSid(SECURITY_LOGON_IDS_RID_COUNT);
  259. Sid = (PSID)LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, Length);
  260. ASSERTMSG("Winlogon failed to allocate memory for logonsid", Sid != NULL);
  261. if (Sid != NULL) {
  262. RtlInitializeSid(Sid, &gSystemSidAuthority, SECURITY_LOGON_IDS_RID_COUNT);
  263. ASSERT(SECURITY_LOGON_IDS_RID_COUNT == 3);
  264. *(RtlSubAuthoritySid(Sid, 0)) = SECURITY_LOGON_IDS_RID;
  265. *(RtlSubAuthoritySid(Sid, 1 )) = Luid.HighPart;
  266. *(RtlSubAuthoritySid(Sid, 2 )) = Luid.LowPart;
  267. }
  268. //
  269. // Return the logon LUID if required.
  270. //
  271. if (LogonId != NULL) {
  272. *LogonId = Luid;
  273. }
  274. return(Sid);
  275. }
  276. DWORD
  277. TestLoggedOutSASWorker(PVOID pvIgnored)
  278. {
  279. PVOID pContext = NULL;
  280. DWORD res;
  281. LUID LogonId;
  282. PSID pSid;
  283. WLX_MPR_NOTIFY_INFO MprInfo;
  284. PWLX_PROFILE_V2_0 pProfile;
  285. DWORD Options;
  286. if (!TEST_FLAG(fTestGina, GINA_LOGGEDOUT_OK))
  287. {
  288. TestGinaError(0, TEXT("TestLoggedOutSASWorker"));
  289. }
  290. pContext = GetContext();
  291. pSid = CreateLogonSid(NULL);
  292. if (TEST_FLAG(GinaBreakFlags, BREAK_LOGGEDOUT))
  293. {
  294. LogEvent(0, "About to call WlxLoggedOutSAS()\n");
  295. if (AmIBeingDebugged())
  296. {
  297. DebugBreak();
  298. }
  299. }
  300. res = pWlxLoggedOutSAS( pContext,
  301. (DWORD) pvIgnored,
  302. &LogonId,
  303. pSid,
  304. &Options,
  305. &hToken,
  306. &MprInfo,
  307. &pProfile );
  308. if (!ValidResponse(WLX_LOGGEDOUTSAS_API, res))
  309. {
  310. TestGinaError(GINAERR_INVALID_RETURN, TEXT("WlxLoggedOutSAS"));
  311. }
  312. if (res == WLX_SAS_ACTION_LOGON)
  313. {
  314. UpdateGinaState(UPDATE_USER_LOGON);
  315. FLAG_OFF(fTestGina, GINA_LOGGEDOUT_OK);
  316. FLAG_OFF(fTestGina, GINA_DISPLAY_OK);
  317. FLAG_ON(fTestGina, GINA_ACTIVATE_OK);
  318. UpdateMenuBar();
  319. if (MprInfo.pszUserName || MprInfo.pszDomain || MprInfo.pszPassword ||
  320. MprInfo.pszOldPassword)
  321. {
  322. // FLAG_ON(fTestGina, GINA_MPRINFO_RECV);
  323. GlobalMprInfo = MprInfo;
  324. wcscpy( GlobalProviderName, TEXT("All") );
  325. }
  326. }
  327. if (res == WLX_SAS_ACTION_NONE)
  328. {
  329. UpdateGinaState(UPDATE_SAS_COMPLETE);
  330. }
  331. return(res);
  332. }
  333. int
  334. TestLoggedOutSAS(int SasType)
  335. {
  336. DWORD tid;
  337. hThread = CreateThread( NULL, 0, TestLoggedOutSASWorker,
  338. (PVOID) SasType, 0, &tid);
  339. CloseHandle(hThread);
  340. return(TRUE);
  341. }
  342. int
  343. TestActivateUserShell(void)
  344. {
  345. PVOID pContext = NULL;
  346. PVOID pEnvironment = NULL;
  347. if (!TEST_FLAG(fTestGina, GINA_ACTIVATE_OK) )
  348. {
  349. TestGinaError(0, TEXT("TestActivateUserShell"));
  350. }
  351. pContext = GetContext();
  352. pEnvironment = GetEnvironmentStrings();
  353. pWlxActivateUserShell( pContext,
  354. TEXT("Winsta0\\Default"),
  355. NULL,
  356. pEnvironment );
  357. FLAG_OFF(fTestGina, GINA_ACTIVATE_OK);
  358. FLAG_ON(fTestGina, GINA_LOGGEDON_OK);
  359. UpdateMenuBar();
  360. return(0);
  361. }
  362. int
  363. TestLoggedOnSAS(int SasType)
  364. {
  365. PVOID pContext = NULL;
  366. WLX_MPR_NOTIFY_INFO MprInfo;
  367. DWORD Result;
  368. if (!TEST_FLAG(fTestGina, GINA_LOGGEDON_OK))
  369. {
  370. TestGinaError(0, TEXT("TestLoggedOnSAS"));
  371. }
  372. pContext = GetContext();
  373. if (TEST_FLAG(GinaBreakFlags, BREAK_LOGGEDON))
  374. {
  375. LogEvent(0, "About to call WlxLoggedOnSAS\n");
  376. if (AmIBeingDebugged())
  377. {
  378. DebugBreak();
  379. }
  380. }
  381. Result = pWlxLoggedOnSAS( pContext,
  382. SasType,
  383. &MprInfo );
  384. if (!ValidResponse(WLX_LOGGEDONSAS_API, Result))
  385. {
  386. TestGinaError(GINAERR_INVALID_RETURN, TEXT("WlxLoggedOnSAS"));
  387. }
  388. switch (Result)
  389. {
  390. case WLX_SAS_ACTION_NONE:
  391. UpdateGinaState(UPDATE_SAS_COMPLETE);
  392. break;
  393. case WLX_SAS_ACTION_TASKLIST:
  394. UpdateGinaState(UPDATE_SAS_COMPLETE);
  395. break;
  396. case WLX_SAS_ACTION_LOCK_WKSTA:
  397. LockTestGina();
  398. break;
  399. case WLX_SAS_ACTION_LOGOFF:
  400. LogoffUser();
  401. break;
  402. case WLX_SAS_ACTION_SHUTDOWN:
  403. case WLX_SAS_ACTION_SHUTDOWN_REBOOT:
  404. case WLX_SAS_ACTION_SHUTDOWN_POWER_OFF:
  405. LogoffUser();
  406. UpdateGinaState(UPDATE_SHUTDOWN);
  407. break;
  408. default:
  409. TestGinaError(0, TEXT("TestLoggedOnSAS_2"));
  410. }
  411. return(0);
  412. }
  413. DWORD
  414. TestDisplayLockedWorker(PVOID pvIgnored)
  415. {
  416. PVOID pContext = NULL;
  417. DWORD err;
  418. if (!TEST_FLAG(fTestGina, GINA_DISPLAYLOCK_OK))
  419. {
  420. TestGinaError(0, TEXT("TestDisplayLocked"));
  421. }
  422. pContext = GetContext();
  423. if (TEST_FLAG(GinaBreakFlags, BREAK_DISPLAYLOCKED))
  424. {
  425. LogEvent(0, "About to call WlxDisplayLockedNotice(%#x) \n", pContext);
  426. if (AmIBeingDebugged())
  427. {
  428. DebugBreak();
  429. }
  430. }
  431. pWlxDisplayLockedNotice(pContext);
  432. err = GetLastError();
  433. return(err == 0 ? TRUE : FALSE);
  434. }
  435. int
  436. TestDisplayLockedNotice(void)
  437. {
  438. DWORD tid;
  439. hThread = CreateThread( NULL, 0, TestDisplayLockedWorker,
  440. NULL, 0, &tid);
  441. CloseHandle(hThread);
  442. return(0);
  443. }
  444. int
  445. TestWkstaLockedSAS(int SasType)
  446. {
  447. PVOID pContext;
  448. DWORD Result;
  449. pContext = GetContext();
  450. if (!TEST_FLAG(fTestGina, GINA_WKSTALOCK_OK))
  451. {
  452. TestGinaError(0, TEXT("TestWkstaLockedSAS"));
  453. }
  454. if (TEST_FLAG(GinaBreakFlags, BREAK_WKSTALOCKED))
  455. {
  456. LogEvent(0, "About to call WlxWkstaLockedSAS\n");
  457. if (AmIBeingDebugged())
  458. {
  459. DebugBreak();
  460. }
  461. }
  462. Result = pWlxWkstaLockedSAS(pContext,
  463. SasType);
  464. if (!ValidResponse(WLX_WKSTALOCKEDSAS_API, Result))
  465. {
  466. TestGinaError(GINAERR_INVALID_RETURN, TEXT("WlxWkstaLockedSAS"));
  467. }
  468. switch (Result)
  469. {
  470. case WLX_SAS_ACTION_NONE:
  471. UpdateGinaState(UPDATE_SAS_COMPLETE);
  472. return(0);
  473. case WLX_SAS_ACTION_UNLOCK_WKSTA:
  474. UnlockTestGina();
  475. return(0);
  476. case WLX_SAS_ACTION_FORCE_LOGOFF:
  477. LogoffUser();
  478. UpdateGinaState(UPDATE_SAS_COMPLETE);
  479. return(0);
  480. default:
  481. TestGinaError(0, TEXT("TestWkstaLockedSAS_2"));
  482. }
  483. return(0);
  484. }