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.

2206 lines
66 KiB

  1. /*++
  2. Copyright (c) 2000, Microsoft Corporation
  3. Module Name:
  4. eluser.c
  5. Abstract:
  6. The module deals with functions related to user interaction, user logon
  7. Revision History:
  8. sachins, Apr 23 2000, Created
  9. --*/
  10. #include "pcheapol.h"
  11. #pragma hdrstop
  12. #define cszEapKeyRas TEXT("Software\\Microsoft\\RAS EAP\\UserEapInfo")
  13. #define cszEapValue TEXT("EapInfo")
  14. #ifndef EAPOL_SERVICE
  15. #define cszModuleName TEXT("wzcsvc.dll")
  16. #else
  17. #define cszModuleName TEXT("eapol.exe")
  18. #endif
  19. //
  20. // ElSessionChangeHandler
  21. //
  22. // Description:
  23. //
  24. // Function called to handle user session login/logoff/user-switching
  25. //
  26. // Arguments:
  27. // pEventData - SCM event data
  28. // dwEventType - SCM event type
  29. //
  30. VOID
  31. ElSessionChangeHandler (
  32. PVOID pEventData,
  33. DWORD dwEventType
  34. )
  35. {
  36. DWORD dwEventStatus = 0;
  37. BOOLEAN fDecrWorkerThreadCount = FALSE;
  38. LPTHREAD_START_ROUTINE pUserRoutine = NULL;
  39. PVOID pvBuffer = NULL;
  40. EAPOL_ZC_INTF ZCData;
  41. DWORD dwRetCode = NO_ERROR;
  42. do
  43. {
  44. if (g_hEventTerminateEAPOL == NULL)
  45. {
  46. dwRetCode = NO_ERROR;
  47. break;
  48. }
  49. if (( dwEventStatus = WaitForSingleObject (
  50. g_hEventTerminateEAPOL,
  51. 0)) == WAIT_FAILED)
  52. {
  53. dwRetCode = GetLastError ();
  54. break;
  55. }
  56. if (dwEventStatus == WAIT_OBJECT_0)
  57. {
  58. dwRetCode = NO_ERROR;
  59. break;
  60. }
  61. if (!(g_dwModulesStarted & LOGON_MODULE_STARTED))
  62. {
  63. break;
  64. }
  65. InterlockedIncrement (&g_lWorkerThreads);
  66. fDecrWorkerThreadCount = TRUE;
  67. if (pEventData)
  68. {
  69. WTSSESSION_NOTIFICATION* pswtsi = (WTSSESSION_NOTIFICATION*)pEventData;
  70. DWORD dwSessionId = pswtsi->dwSessionId;
  71. switch (dwEventType)
  72. {
  73. case WTS_CONSOLE_CONNECT:
  74. case WTS_REMOTE_CONNECT:
  75. {
  76. TRACE1 (USER,"ElSessionChangeHandler: CONNECT for session = (%ld)\n",
  77. dwSessionId);
  78. pUserRoutine = ElUserLogonCallback;
  79. break;
  80. }
  81. case WTS_CONSOLE_DISCONNECT:
  82. case WTS_REMOTE_DISCONNECT:
  83. {
  84. TRACE1 (USER,"ElSessionChangeHandler: DISCONNECT for session = (%ld)\n",
  85. dwSessionId);
  86. pUserRoutine = ElUserLogoffCallback;
  87. break;
  88. }
  89. case WTS_SESSION_LOGON:
  90. {
  91. TRACE1 (USER,"ElSessionChangeHandler: LOGON for session = (%ld)",
  92. dwSessionId);
  93. pUserRoutine = ElUserLogonCallback;
  94. break;
  95. }
  96. case WTS_SESSION_LOGOFF:
  97. {
  98. TRACE1 (USER,"ElSessionChangeHandler: LOGOFF for session=(%ld)",
  99. dwSessionId);
  100. pUserRoutine = ElUserLogoffCallback;
  101. break;
  102. }
  103. default:
  104. break;
  105. }
  106. if (pUserRoutine == NULL)
  107. {
  108. break;
  109. }
  110. if ((pvBuffer = MALLOC (sizeof(DWORD))) == NULL)
  111. {
  112. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  113. break;
  114. }
  115. *((DWORD *)pvBuffer) = dwSessionId;
  116. if (!QueueUserWorkItem (
  117. (LPTHREAD_START_ROUTINE)pUserRoutine,
  118. pvBuffer,
  119. WT_EXECUTELONGFUNCTION))
  120. {
  121. dwRetCode = GetLastError();
  122. TRACE1 (DEVICE, "ElSessionChangeHandler: QueueUserWorkItem failed with error %ld",
  123. dwRetCode);
  124. break;
  125. }
  126. else
  127. {
  128. fDecrWorkerThreadCount = FALSE;
  129. }
  130. }
  131. }
  132. while (FALSE);
  133. if (fDecrWorkerThreadCount)
  134. {
  135. InterlockedDecrement (&g_lWorkerThreads);
  136. }
  137. if (dwRetCode != NO_ERROR)
  138. {
  139. if (pvBuffer != NULL)
  140. {
  141. FREE (pvBuffer);
  142. }
  143. }
  144. }
  145. //
  146. // ElUserLogonCallback
  147. //
  148. // Description:
  149. //
  150. // Callback function invoked whenever a user logs in
  151. // Will initiate authentication process on all ports of LAN class
  152. // Credentials for the user in case of EAP-TLS can be obtained by
  153. // acquiring user token
  154. // For EAP-CHAP, WinLogon cerdentials will need to be supplied
  155. //
  156. // Arguments:
  157. // None.
  158. //
  159. DWORD
  160. WINAPI
  161. ElUserLogonCallback (
  162. IN PVOID pvContext
  163. )
  164. {
  165. DWORD dwIndex = 0;
  166. EAPOL_PCB *pPCB = NULL;
  167. BOOL fSetCONNECTINGState = FALSE;
  168. EAPOL_ZC_INTF ZCData;
  169. DWORD dwRetCode = NO_ERROR;
  170. TRACE1 (USER, "ElUserLogonCallback: UserloggedOn = %ld",
  171. g_fUserLoggedOn);
  172. do
  173. {
  174. if (g_fUserLoggedOn)
  175. {
  176. TRACE0 (USER, "ElUserLogonCallback: User logon already detected, returning without processing");
  177. break;
  178. }
  179. if (pvContext == NULL)
  180. {
  181. break;
  182. }
  183. if (*((DWORD *)pvContext) != USER_SHARED_DATA->ActiveConsoleId)
  184. {
  185. TRACE1 (USER, "ElUserLogonCallback: Not active console id (%ld)",
  186. *((DWORD *)pvContext));
  187. break;
  188. }
  189. // Check if UserModule is ready for notifications
  190. if (!g_fTrayIconReady)
  191. {
  192. if ((dwRetCode = ElCheckUserModuleReady ()) != NO_ERROR)
  193. {
  194. TRACE1 (USER, "ElUserLogonCallback: ElCheckUserModuleReady failed with error %ld",
  195. dwRetCode);
  196. if (dwRetCode == ERROR_BAD_IMPERSONATION_LEVEL)
  197. {
  198. break;
  199. }
  200. }
  201. }
  202. // Set global flag to indicate the user logged on
  203. g_fUserLoggedOn = TRUE;
  204. g_dwCurrentSessionId = *((DWORD *)pvContext);
  205. ACQUIRE_WRITE_LOCK (&(g_PCBLock));
  206. for (dwIndex = 0; dwIndex < PORT_TABLE_BUCKETS; dwIndex++)
  207. {
  208. for (pPCB = g_PCBTable.pPCBBuckets[dwIndex].pPorts;
  209. pPCB != NULL;
  210. pPCB = pPCB->pNext)
  211. {
  212. fSetCONNECTINGState = FALSE;
  213. ACQUIRE_WRITE_LOCK (&(pPCB->rwLock));
  214. switch (pPCB->dwEAPOLAuthMode)
  215. {
  216. case EAPOL_AUTH_MODE_0:
  217. if (pPCB->State == EAPOLSTATE_AUTHENTICATED)
  218. {
  219. if (pPCB->PreviousAuthenticationType ==
  220. EAPOL_UNAUTHENTICATED_ACCESS)
  221. {
  222. fSetCONNECTINGState = TRUE;
  223. }
  224. }
  225. else
  226. {
  227. (VOID) ElEapEnd (pPCB);
  228. fSetCONNECTINGState = TRUE;
  229. }
  230. break;
  231. case EAPOL_AUTH_MODE_1:
  232. (VOID) ElEapEnd (pPCB);
  233. fSetCONNECTINGState = TRUE;
  234. break;
  235. case EAPOL_AUTH_MODE_2:
  236. // Do nothing
  237. break;
  238. }
  239. if (!EAPOL_PORT_ACTIVE(pPCB))
  240. {
  241. TRACE1 (USER, "ElUserLogonCallback: Port %ws not active",
  242. pPCB->pwszDeviceGUID);
  243. fSetCONNECTINGState = FALSE;
  244. }
  245. // Set port to EAPOLSTATE_CONNECTING
  246. if (fSetCONNECTINGState)
  247. {
  248. DbLogPCBEvent (DBLOG_CATEG_INFO, pPCB, EAPOL_USER_LOGON, pPCB->pwszFriendlyName);
  249. // First send out EAPOL_Logoff message
  250. if ((dwRetCode = FSMLogoff (pPCB, NULL))
  251. != NO_ERROR)
  252. {
  253. TRACE1 (USER, "ElUserLogonCallback: Error in FSMLogoff = %ld",
  254. dwRetCode);
  255. dwRetCode = NO_ERROR;
  256. }
  257. pPCB->dwAuthFailCount = 0;
  258. // With unauthenticated access flag set, port will always
  259. // reauthenticate for logged on user
  260. pPCB->PreviousAuthenticationType =
  261. EAPOL_UNAUTHENTICATED_ACCESS;
  262. RELEASE_WRITE_LOCK (&(pPCB->rwLock));
  263. // Restart authentication on the port
  264. if ((dwRetCode = ElReStartPort (pPCB, 0, NULL)) != NO_ERROR)
  265. {
  266. TRACE1 (USER, "ElUserLogonCallback: MachineAuth: Error in ElReStartPort = %ld",
  267. dwRetCode);
  268. continue;
  269. }
  270. }
  271. else
  272. {
  273. RELEASE_WRITE_LOCK (&(pPCB->rwLock));
  274. continue;
  275. }
  276. }
  277. }
  278. RELEASE_WRITE_LOCK (&(g_PCBLock));
  279. if (dwRetCode != NO_ERROR)
  280. {
  281. break;
  282. }
  283. } while (FALSE);
  284. TRACE1 (USER, "ElUserLogonCallback: completed with error %ld", dwRetCode);
  285. if (pvContext != NULL)
  286. {
  287. FREE (pvContext);
  288. }
  289. InterlockedDecrement (&g_lWorkerThreads);
  290. return 0;
  291. }
  292. //
  293. // ElUserLogoffCallback
  294. //
  295. // Description:
  296. //
  297. // Callback function invoked whenever a user logs off
  298. // Will logoff from all ports which have authentication enabled
  299. //
  300. // Arguments:
  301. // None.
  302. //
  303. DWORD
  304. WINAPI
  305. ElUserLogoffCallback (
  306. IN PVOID pvContext
  307. )
  308. {
  309. DWORD dwIndex = 0;
  310. EAPOL_PCB *pPCB = NULL;
  311. BOOL fSetCONNECTINGState = FALSE;
  312. EAPOL_ZC_INTF ZCData;
  313. DWORD dwRetCode = NO_ERROR;
  314. do
  315. {
  316. if (!g_fUserLoggedOn)
  317. {
  318. TRACE0 (USER, "ElUserLogoffCallback: User logoff already called, returning without processing");
  319. break;
  320. }
  321. if (pvContext == NULL)
  322. {
  323. break;
  324. }
  325. if (g_dwCurrentSessionId != *((DWORD *)pvContext))
  326. {
  327. TRACE1 (USER, "ElUserLogoffCallback: Not active console id (%ld)",
  328. *((DWORD *)pvContext));
  329. break;
  330. }
  331. // Reset global flag to indicate the user logged off
  332. g_fUserLoggedOn = FALSE;
  333. g_dwCurrentSessionId = 0xffffffff;
  334. // Reset User Module ready flag
  335. g_fTrayIconReady = FALSE;
  336. TRACE1 (USER, "ElUserLogoffCallback: UserloggedOff = %ld",
  337. g_fUserLoggedOn);
  338. ACQUIRE_WRITE_LOCK (&(g_PCBLock));
  339. for (dwIndex = 0; dwIndex < PORT_TABLE_BUCKETS; dwIndex++)
  340. {
  341. for (pPCB = g_PCBTable.pPCBBuckets[dwIndex].pPorts;
  342. pPCB != NULL;
  343. pPCB = pPCB->pNext)
  344. {
  345. fSetCONNECTINGState = FALSE;
  346. ACQUIRE_WRITE_LOCK (&(pPCB->rwLock));
  347. switch (pPCB->dwEAPOLAuthMode)
  348. {
  349. case EAPOL_AUTH_MODE_0:
  350. if (pPCB->State == EAPOLSTATE_AUTHENTICATED)
  351. {
  352. if (pPCB->PreviousAuthenticationType !=
  353. EAPOL_MACHINE_AUTHENTICATION)
  354. {
  355. fSetCONNECTINGState = TRUE;
  356. }
  357. }
  358. else
  359. {
  360. (VOID) ElEapEnd (pPCB);
  361. fSetCONNECTINGState = TRUE;
  362. }
  363. break;
  364. case EAPOL_AUTH_MODE_1:
  365. (VOID) ElEapEnd (pPCB);
  366. fSetCONNECTINGState = TRUE;
  367. break;
  368. case EAPOL_AUTH_MODE_2:
  369. // Do nothing
  370. break;
  371. }
  372. if (!EAPOL_PORT_ACTIVE(pPCB))
  373. {
  374. TRACE1 (USER, "ElUserLogoffCallback: Port %ws not active",
  375. pPCB->pwszDeviceGUID);
  376. fSetCONNECTINGState = FALSE;
  377. }
  378. // Set port to EAPOLSTATE_CONNECTING
  379. if (fSetCONNECTINGState)
  380. {
  381. DbLogPCBEvent (DBLOG_CATEG_INFO, pPCB,
  382. EAPOL_USER_LOGOFF, pPCB->pwszFriendlyName);
  383. // First send out EAPOL_Logoff message
  384. if ((dwRetCode = FSMLogoff (pPCB, NULL))
  385. != NO_ERROR)
  386. {
  387. TRACE1 (USER, "ElUserLogoffCallback: Error in FSMLogoff = %ld",
  388. dwRetCode);
  389. dwRetCode = NO_ERROR;
  390. }
  391. pPCB->dwAuthFailCount = 0;
  392. // With Unauthenticated_access, port will always
  393. // reauthenticate
  394. pPCB->PreviousAuthenticationType =
  395. EAPOL_UNAUTHENTICATED_ACCESS;
  396. RELEASE_WRITE_LOCK (&(pPCB->rwLock));
  397. // Restart authentication on the port
  398. if ((dwRetCode = ElReStartPort (pPCB, 0, NULL))
  399. != NO_ERROR)
  400. {
  401. TRACE1 (USER, "ElUserLogoffCallback: Error in ElReStartPort = %ld",
  402. dwRetCode);
  403. continue;
  404. }
  405. }
  406. else
  407. {
  408. RELEASE_WRITE_LOCK (&(pPCB->rwLock));
  409. continue;
  410. }
  411. }
  412. }
  413. RELEASE_WRITE_LOCK (&(g_PCBLock));
  414. }
  415. while (FALSE);
  416. TRACE0 (USER, "ElUserLogoffCallback: completed");
  417. if (pvContext != NULL)
  418. {
  419. FREE (pvContext);
  420. }
  421. InterlockedDecrement (&g_lWorkerThreads);
  422. return 0;
  423. }
  424. //
  425. // ElGetUserIdentity
  426. //
  427. // Description:
  428. //
  429. // Function called to initiate and get user identity on a particular
  430. // interface. The RasEapGetIdentity in the appropriate DLL is called
  431. // with the necessary arguments.
  432. //
  433. // Arguments:
  434. // pPCB - Pointer to PCB for the specific port/interface
  435. //
  436. // Return values:
  437. // NO_ERROR - success
  438. // non-zero - error
  439. //
  440. DWORD
  441. ElGetUserIdentity (
  442. IN EAPOL_PCB *pPCB
  443. )
  444. {
  445. HANDLE hLib = NULL;
  446. RASEAPFREE pFreeFunc = NULL;
  447. RASEAPGETIDENTITY pIdenFunc = NULL;
  448. DWORD dwIndex = -1;
  449. DWORD cbData = 0;
  450. PBYTE pbAuthData = NULL;
  451. PBYTE pbUserIn = NULL;
  452. DWORD dwInSize = 0;
  453. BYTE *pUserDataOut;
  454. DWORD dwSizeOfUserDataOut;
  455. LPWSTR lpwszIdentity = NULL;
  456. CHAR *pszIdentity = NULL;
  457. HWND hwndOwner = NULL;
  458. DWORD dwFlags = 0;
  459. BYTE *pbSSID = NULL;
  460. DWORD dwSizeOfSSID = 0;
  461. EAPOL_STATE TmpEAPOLState;
  462. EAPOL_EAP_UI_CONTEXT *pEAPUIContext = NULL;
  463. DWORD dwRetCode = NO_ERROR;
  464. do
  465. {
  466. TRACE0 (USER, "ElGetUserIdentity entered");
  467. if (!EAPOL_PORT_ACTIVE(pPCB))
  468. {
  469. TRACE1 (PORT, "ElGetUserIdentity: Port %ws not active",
  470. pPCB->pwszDeviceGUID);
  471. // Port is not active, cannot do further processing on this port
  472. break;
  473. }
  474. if (pPCB->PreviousAuthenticationType != EAPOL_MACHINE_AUTHENTICATION)
  475. {
  476. // Get Access Token for user logged on interactively
  477. if (pPCB->hUserToken != NULL)
  478. {
  479. if (!CloseHandle (pPCB->hUserToken))
  480. {
  481. dwRetCode = GetLastError ();
  482. TRACE1 (USER, "ElGetUserIdentity: CloseHandle failed with error %ld",
  483. dwRetCode);
  484. break;
  485. }
  486. }
  487. pPCB->hUserToken = NULL;
  488. if ((dwRetCode = ElGetWinStationUserToken (g_dwCurrentSessionId, &pPCB->hUserToken)) != NO_ERROR)
  489. {
  490. TRACE1 (USER, "ElGetUserIdentity: ElGetWinStationUserToken failed with error (%ld)",
  491. dwRetCode);
  492. dwRetCode = ERROR_NO_TOKEN;
  493. break;
  494. }
  495. //
  496. // Try to fetch user identity without sending request to
  497. // user module. If not possible, send request to user module
  498. //
  499. if ((dwRetCode = ElGetUserIdentityOptimized (pPCB))
  500. != ERROR_REQUIRES_INTERACTIVE_WINDOWSTATION)
  501. {
  502. TRACE0 (USER, "ElGetUserIdentity: ElGetUserIdentityOptimized got identity without user module intervention");
  503. break;
  504. }
  505. if (!g_fTrayIconReady)
  506. {
  507. if ((dwRetCode = ElCheckUserModuleReady ()) != NO_ERROR)
  508. {
  509. TRACE1 (USER, "ElGetUserIdentity: ElCheckUserModuleReady failed with error %ld",
  510. dwRetCode);
  511. break;
  512. }
  513. }
  514. if (!g_fTrayIconReady)
  515. {
  516. DbLogPCBEvent (DBLOG_CATEG_WARN, pPCB, EAPOL_WAITING_FOR_DESKTOP_LOAD);
  517. dwRetCode = ERROR_IO_PENDING;
  518. TRACE0 (USER, "ElGetUserIdentity: TrayIcon NOT ready");
  519. break;
  520. }
  521. //
  522. // Call GetUserIdentityDlgWorker
  523. //
  524. pEAPUIContext = MALLOC (sizeof(EAPOL_EAP_UI_CONTEXT));
  525. if (pEAPUIContext == NULL)
  526. {
  527. TRACE0 (USER, "ElGetUserIdentity: MALLOC failed for pEAPUIContext");
  528. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  529. break;
  530. }
  531. pEAPUIContext->dwEAPOLUIMsgType = EAPOLUI_GET_USERIDENTITY;
  532. wcscpy (pEAPUIContext->wszGUID, pPCB->pwszDeviceGUID);
  533. pPCB->dwUIInvocationId =
  534. InterlockedIncrement(&(g_dwEAPUIInvocationId));
  535. pEAPUIContext->dwSessionId = g_dwCurrentSessionId;
  536. pEAPUIContext->dwContextId = pPCB->dwUIInvocationId;
  537. pEAPUIContext->dwEapId = pPCB->bCurrentEAPId;
  538. pEAPUIContext->dwEapTypeId = pPCB->dwEapTypeToBeUsed;
  539. pEAPUIContext->dwEapFlags = pPCB->dwEapFlags;
  540. if (pPCB->pwszSSID)
  541. {
  542. wcscpy (pEAPUIContext->wszSSID, pPCB->pwszSSID);
  543. }
  544. if (pPCB->pSSID)
  545. {
  546. pEAPUIContext->dwSizeOfSSID = pPCB->pSSID->SsidLength;
  547. memcpy ((BYTE *)pEAPUIContext->bSSID, (BYTE *)pPCB->pSSID->Ssid,
  548. NDIS_802_11_SSID_LEN-sizeof(ULONG));
  549. }
  550. // Have to notify state change before we post balloon
  551. TmpEAPOLState = pPCB->State;
  552. pPCB->State = EAPOLSTATE_ACQUIRED;
  553. ElNetmanNotify (pPCB, EAPOL_NCS_CRED_REQUIRED, NULL);
  554. // State is changed only in FSMAcquired
  555. // Revert to original
  556. pPCB->State = TmpEAPOLState;
  557. // Post the message to netman
  558. if ((dwRetCode = ElPostShowBalloonMessage (
  559. pPCB,
  560. sizeof(EAPOL_EAP_UI_CONTEXT),
  561. (BYTE *)pEAPUIContext,
  562. 0,
  563. NULL
  564. )) != NO_ERROR)
  565. {
  566. TRACE1 (USER, "ElGetUserIdentity: ElPostShowBalloonMessage failed with error %ld",
  567. dwRetCode);
  568. break;
  569. }
  570. // Restart PCB timer since UI may take longer time than required
  571. RESTART_TIMER (pPCB->hTimer,
  572. INFINITE_SECONDS,
  573. "PCB",
  574. &dwRetCode);
  575. if (dwRetCode != NO_ERROR)
  576. {
  577. break;
  578. }
  579. pPCB->EapUIState = EAPUISTATE_WAITING_FOR_IDENTITY;
  580. DbLogPCBEvent (DBLOG_CATEG_INFO, pPCB, EAPOL_WAITING_FOR_DESKTOP_IDENTITY);
  581. // Return error code as pending, since credentials have still not
  582. // been acquired
  583. dwRetCode = ERROR_IO_PENDING;
  584. }
  585. else // MACHINE_AUTHENTICATION
  586. {
  587. pPCB->hUserToken = NULL;
  588. // The EAP dll will have already been loaded by the state machine
  589. // Retrieve the handle to the dll from the global EAP table
  590. if ((dwIndex = ElGetEapTypeIndex (pPCB->dwEapTypeToBeUsed)) == -1)
  591. {
  592. TRACE1 (USER, "ElGetUserIdentity: ElGetEapTypeIndex finds no dll for EAP index %ld",
  593. pPCB->dwEapTypeToBeUsed);
  594. dwRetCode = ERROR_CAN_NOT_COMPLETE;
  595. break;
  596. }
  597. hLib = g_pEapTable[dwIndex].hInstance;
  598. pIdenFunc = (RASEAPGETIDENTITY)GetProcAddress(hLib,
  599. "RasEapGetIdentity");
  600. pFreeFunc = (RASEAPFREE)GetProcAddress(hLib, "RasEapFreeMemory");
  601. if ((pFreeFunc == NULL) || (pIdenFunc == NULL))
  602. {
  603. TRACE0 (USER, "ElGetUserIdentity: pIdenFunc or pFreeFunc does not exist in the EAP implementation");
  604. dwRetCode = ERROR_CAN_NOT_COMPLETE;
  605. break;
  606. }
  607. if (pPCB->pSSID)
  608. {
  609. pbSSID = pPCB->pSSID->Ssid;
  610. dwSizeOfSSID = pPCB->pSSID->SsidLength;
  611. }
  612. // Get the size of the EAP blob
  613. if ((dwRetCode = ElGetCustomAuthData (
  614. pPCB->pwszDeviceGUID,
  615. pPCB->dwEapTypeToBeUsed,
  616. dwSizeOfSSID,
  617. pbSSID,
  618. NULL,
  619. &cbData
  620. )) != NO_ERROR)
  621. {
  622. if (dwRetCode == ERROR_BUFFER_TOO_SMALL)
  623. {
  624. if (cbData <= 0)
  625. {
  626. // No EAP blob stored in the registry
  627. TRACE0 (USER, "ElGetUserIdentity: NULL sized EAP blob: continue");
  628. pbAuthData = NULL;
  629. // Every port should have connection data !!!
  630. dwRetCode = NO_ERROR;
  631. }
  632. else
  633. {
  634. // Allocate memory to hold the blob
  635. pbAuthData = MALLOC (cbData);
  636. if (pbAuthData == NULL)
  637. {
  638. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  639. TRACE0 (USER, "ElGetUserIdentity: Error in memory allocation for EAP blob");
  640. break;
  641. }
  642. if ((dwRetCode = ElGetCustomAuthData (
  643. pPCB->pwszDeviceGUID,
  644. pPCB->dwEapTypeToBeUsed,
  645. dwSizeOfSSID,
  646. pbSSID,
  647. pbAuthData,
  648. &cbData
  649. )) != NO_ERROR)
  650. {
  651. TRACE1 (USER, "ElGetUserIdentity: ElGetCustomAuthData failed with %ld",
  652. dwRetCode);
  653. break;
  654. }
  655. }
  656. }
  657. else
  658. {
  659. // CustomAuthData for "Default" is always created for an
  660. // interface when EAPOL starts up
  661. TRACE1 (USER, "ElGetUserIdentity: ElGetCustomAuthData size estimation failed with error %ld",
  662. dwRetCode);
  663. break;
  664. }
  665. }
  666. if (pIdenFunc)
  667. if ((dwRetCode = (*(pIdenFunc))(
  668. pPCB->dwEapTypeToBeUsed,
  669. hwndOwner, // hwndOwner
  670. RAS_EAP_FLAG_MACHINE_AUTH, // dwFlags
  671. NULL, // lpszPhonebook
  672. pPCB->pwszFriendlyName, // lpszEntry
  673. pbAuthData, // Connection data
  674. cbData, // Count of pbAuthData
  675. pbUserIn, // User data for port
  676. dwInSize, // Size of user data
  677. &pUserDataOut,
  678. &dwSizeOfUserDataOut,
  679. &lpwszIdentity
  680. )) != NO_ERROR)
  681. {
  682. if (dwRetCode == ERROR_NO_EAPTLS_CERTIFICATE)
  683. {
  684. DbLogPCBEvent (DBLOG_CATEG_ERR, pPCB, EAPOL_NO_CERTIFICATE_MACHINE);
  685. }
  686. else
  687. {
  688. DbLogPCBEvent (DBLOG_CATEG_ERR, pPCB, EAPOL_ERROR_GET_IDENTITY, EAPOLAuthTypes[EAPOL_MACHINE_AUTHENTICATION], dwRetCode);
  689. }
  690. TRACE1 (USER, "ElGetUserIdentity: Error in calling GetIdentity = %ld",
  691. dwRetCode);
  692. break;
  693. }
  694. // Fill in the returned information into the PCB fields for
  695. // later authentication
  696. if (pPCB->pCustomAuthUserData != NULL)
  697. {
  698. FREE (pPCB->pCustomAuthUserData);
  699. pPCB->pCustomAuthUserData = NULL;
  700. }
  701. pPCB->pCustomAuthUserData = MALLOC (dwSizeOfUserDataOut + sizeof (DWORD));
  702. if (pPCB->pCustomAuthUserData == NULL)
  703. {
  704. TRACE1 (USER, "ElGetUserIdentity: Error in allocating memory for UserInfo = %ld",
  705. dwRetCode);
  706. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  707. break;
  708. }
  709. pPCB->pCustomAuthUserData->dwSizeOfCustomAuthData = dwSizeOfUserDataOut;
  710. if ((dwSizeOfUserDataOut != 0) && (pUserDataOut != NULL))
  711. {
  712. memcpy ((BYTE *)pPCB->pCustomAuthUserData->pbCustomAuthData,
  713. (BYTE *)pUserDataOut,
  714. dwSizeOfUserDataOut);
  715. }
  716. if (lpwszIdentity != NULL)
  717. {
  718. pszIdentity = MALLOC (wcslen(lpwszIdentity)*sizeof(CHAR) + sizeof(CHAR));
  719. if (pszIdentity == NULL)
  720. {
  721. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  722. TRACE0 (USER, "ElGetUserIdentity: MALLOC failed for pszIdentity");
  723. break;
  724. }
  725. if (0 == WideCharToMultiByte (
  726. CP_ACP,
  727. 0,
  728. lpwszIdentity,
  729. -1,
  730. pszIdentity,
  731. wcslen(lpwszIdentity)*sizeof(CHAR)+sizeof(CHAR),
  732. NULL,
  733. NULL ))
  734. {
  735. dwRetCode = GetLastError();
  736. TRACE2 (USER, "ElGetUserIdentity: WideCharToMultiByte (%ws) failed: %ld",
  737. lpwszIdentity, dwRetCode);
  738. break;
  739. }
  740. TRACE1 (USER, "ElGetUserIdentity: Got identity = %s",
  741. pszIdentity);
  742. if (pPCB->pszIdentity != NULL)
  743. {
  744. FREE (pPCB->pszIdentity);
  745. pPCB->pszIdentity = NULL;
  746. }
  747. pPCB->pszIdentity = MALLOC (strlen(pszIdentity) + sizeof(CHAR));
  748. if (pPCB->pszIdentity == NULL)
  749. {
  750. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  751. TRACE0 (USER, "ElGetUserIdentity: MALLOC failed for pPCB->pszIdentity");
  752. break;
  753. }
  754. memcpy (pPCB->pszIdentity, pszIdentity, strlen (pszIdentity));
  755. pPCB->pszIdentity[strlen(pszIdentity)] = '\0';
  756. }
  757. if (pPCB->pCustomAuthConnData != NULL)
  758. {
  759. FREE (pPCB->pCustomAuthConnData);
  760. pPCB->pCustomAuthConnData = NULL;
  761. }
  762. pPCB->pCustomAuthConnData = MALLOC (cbData + sizeof (DWORD));
  763. if (pPCB->pCustomAuthConnData == NULL)
  764. {
  765. TRACE1 (USER, "ElGetUserIdentity: Error in allocating memory for AuthInfo = %ld",
  766. dwRetCode);
  767. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  768. break;
  769. }
  770. pPCB->pCustomAuthConnData->dwSizeOfCustomAuthData = cbData;
  771. if ((cbData != 0) && (pbAuthData != NULL))
  772. {
  773. memcpy ((BYTE *)pPCB->pCustomAuthConnData->pbCustomAuthData,
  774. (BYTE *)pbAuthData,
  775. cbData);
  776. }
  777. // Mark the identity has been obtained for this PCB
  778. pPCB->fGotUserIdentity = TRUE;
  779. }
  780. } while (FALSE);
  781. // Cleanup
  782. if ((dwRetCode != NO_ERROR) && (dwRetCode != ERROR_IO_PENDING))
  783. {
  784. if (pPCB->pCustomAuthUserData != NULL)
  785. {
  786. FREE (pPCB->pCustomAuthUserData);
  787. pPCB->pCustomAuthUserData = NULL;
  788. }
  789. if (pPCB->pszIdentity != NULL)
  790. {
  791. FREE (pPCB->pszIdentity);
  792. pPCB->pszIdentity = NULL;
  793. }
  794. }
  795. if (pEAPUIContext != NULL)
  796. {
  797. FREE (pEAPUIContext);
  798. }
  799. if (pbUserIn != NULL)
  800. {
  801. FREE (pbUserIn);
  802. }
  803. if (pbAuthData != NULL)
  804. {
  805. FREE (pbAuthData);
  806. }
  807. if (pFreeFunc != NULL)
  808. {
  809. if (lpwszIdentity != NULL)
  810. {
  811. if (( dwRetCode = (*(pFreeFunc)) ((BYTE *)lpwszIdentity)) != NO_ERROR)
  812. {
  813. TRACE1 (USER, "ElGetUserIdentity: Error in pFreeFunc = %ld",
  814. dwRetCode);
  815. }
  816. }
  817. if (pUserDataOut != NULL)
  818. {
  819. if (( dwRetCode = (*(pFreeFunc)) ((BYTE *)pUserDataOut)) != NO_ERROR)
  820. {
  821. TRACE1 (USER, "ElGetUserIdentity: Error in pFreeFunc = %ld",
  822. dwRetCode);
  823. }
  824. }
  825. }
  826. TRACE1 (USER, "ElGetUserIdentity completed with error %ld", dwRetCode);
  827. return dwRetCode;
  828. }
  829. //
  830. // ElProcessUserIdentityResponse
  831. //
  832. // Description:
  833. //
  834. // Function to handle UI response for ElGetUserIdentityResponse
  835. //
  836. // Arguments:
  837. //
  838. // Return values:
  839. //
  840. //
  841. DWORD
  842. ElProcessUserIdentityResponse (
  843. IN EAPOL_EAP_UI_CONTEXT EapolUIContext,
  844. IN EAPOLUI_RESP EapolUIResp
  845. )
  846. {
  847. DWORD dwSizeOfIdentity = 0;
  848. BYTE *pbIdentity = NULL;
  849. DWORD dwSizeOfUserData = 0;
  850. BYTE *pbUserData = NULL;
  851. DWORD dwSizeofConnData = 0;
  852. BYTE *pbConnData = NULL;
  853. EAPOL_PCB *pPCB = NULL;
  854. EAPOL_EAP_UI_CONTEXT *pEAPUIContext = NULL;
  855. BOOLEAN fPortReferenced = FALSE;
  856. BOOLEAN fPCBLocked = FALSE;
  857. BOOLEAN fBlobCopyIncomplete = FALSE;
  858. DWORD dwRetCode = NO_ERROR;
  859. do
  860. {
  861. pEAPUIContext = (EAPOL_EAP_UI_CONTEXT *)&EapolUIContext;
  862. ACQUIRE_WRITE_LOCK (&g_PCBLock);
  863. if ((pPCB = ElGetPCBPointerFromPortGUID (pEAPUIContext->wszGUID)) != NULL)
  864. {
  865. if (EAPOL_REFERENCE_PORT (pPCB))
  866. {
  867. fPortReferenced = TRUE;
  868. }
  869. else
  870. {
  871. pPCB = NULL;
  872. }
  873. }
  874. RELEASE_WRITE_LOCK (&g_PCBLock);
  875. if (pPCB == NULL)
  876. {
  877. break;
  878. }
  879. ACQUIRE_WRITE_LOCK (&(pPCB->rwLock));
  880. fPCBLocked = TRUE;
  881. if (!EAPOL_PORT_ACTIVE(pPCB))
  882. {
  883. TRACE1 (USER, "ElProcessUserIdentityResponse: Port %ws not active",
  884. pPCB->pwszDeviceGUID);
  885. // Port is not active, cannot do further processing on this port
  886. break;
  887. }
  888. if (pEAPUIContext->dwRetCode != NO_ERROR)
  889. {
  890. DbLogPCBEvent (DBLOG_CATEG_ERR, pPCB,
  891. EAPOL_ERROR_DESKTOP_IDENTITY, dwRetCode);
  892. TRACE1 (USER, "ElProcessUserIdentityResponse: Error in Dialog function (%ld)",
  893. pEAPUIContext->dwRetCode);
  894. break;
  895. }
  896. if (pPCB->EapUIState != EAPUISTATE_WAITING_FOR_IDENTITY)
  897. {
  898. TRACE2 (USER, "ElProcessUserIdentityResponse: PCB EapUIState has changed to (%ld), expected = (%ld)",
  899. pPCB->EapUIState, EAPUISTATE_WAITING_FOR_IDENTITY);
  900. break;
  901. }
  902. if (pPCB->dwUIInvocationId != pEAPUIContext->dwContextId)
  903. {
  904. TRACE2 (USER, "ElProcessUserIdentityResponse: PCB UI Id has changed to (%ld), expected = (%ld)",
  905. pPCB->dwUIInvocationId, pEAPUIContext->dwContextId);
  906. // break;
  907. }
  908. if (pPCB->bCurrentEAPId != pEAPUIContext->dwEapId)
  909. {
  910. TRACE2 (USER, "ElProcessUserIdentityResponse: PCB EAP Id has changed to (%ld), expected = (%ld)",
  911. pPCB->bCurrentEAPId, pEAPUIContext->dwEapId);
  912. // break;
  913. }
  914. // Since the PCB context is right, restart PCB timer to timeout
  915. // in authPeriod seconds
  916. RESTART_TIMER (pPCB->hTimer,
  917. pPCB->EapolConfig.dwauthPeriod,
  918. "PCB",
  919. &dwRetCode);
  920. if (dwRetCode != NO_ERROR)
  921. {
  922. TRACE1 (USER, "ElProcessUserIdentityResponse: Error in RESTART_TIMER %ld",
  923. dwRetCode);
  924. break;
  925. }
  926. DbLogPCBEvent (DBLOG_CATEG_INFO, pPCB, EAPOL_PROCESSING_DESKTOP_RESPONSE);
  927. if ((EapolUIResp.rdData0.dwDataLen != 0) && (EapolUIResp.rdData0.pData != NULL))
  928. {
  929. dwSizeOfIdentity = EapolUIResp.rdData0.dwDataLen;
  930. pbIdentity = EapolUIResp.rdData0.pData;
  931. }
  932. if ((EapolUIResp.rdData1.dwDataLen != 0) && (EapolUIResp.rdData1.pData != NULL))
  933. {
  934. dwSizeOfUserData = EapolUIResp.rdData1.dwDataLen;
  935. pbUserData = EapolUIResp.rdData1.pData;
  936. }
  937. if ((EapolUIResp.rdData2.dwDataLen != 0) && (EapolUIResp.rdData2.pData != NULL))
  938. {
  939. dwSizeofConnData = EapolUIResp.rdData2.dwDataLen;
  940. pbConnData = EapolUIResp.rdData2.pData;
  941. }
  942. fBlobCopyIncomplete = TRUE;
  943. if (pPCB->pszIdentity != NULL)
  944. {
  945. FREE (pPCB->pszIdentity);
  946. pPCB->pszIdentity = NULL;
  947. }
  948. if (pbIdentity != NULL)
  949. {
  950. pPCB->pszIdentity = MALLOC (dwSizeOfIdentity + sizeof(CHAR));
  951. if (pPCB->pszIdentity == NULL)
  952. {
  953. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  954. TRACE0 (USER, "ElProcessUserIdentityResponse: MALLOC failed for pPCB->pszIdentity");
  955. break;
  956. }
  957. memcpy (pPCB->pszIdentity, pbIdentity, dwSizeOfIdentity);
  958. pPCB->pszIdentity[dwSizeOfIdentity] = '\0';
  959. TRACE1 (USER, "ElProcessUserIdentityResponse: Got username = %s",
  960. pPCB->pszIdentity);
  961. }
  962. if (pPCB->pCustomAuthUserData != NULL)
  963. {
  964. FREE (pPCB->pCustomAuthUserData);
  965. pPCB->pCustomAuthUserData = NULL;
  966. }
  967. pPCB->pCustomAuthUserData = MALLOC (dwSizeOfUserData + sizeof (DWORD));
  968. if (pPCB->pCustomAuthUserData == NULL)
  969. {
  970. TRACE1 (USER, "ElProcessUserIdentityResponse: Error in allocating memory for UserInfo = %ld",
  971. dwRetCode);
  972. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  973. break;
  974. }
  975. pPCB->pCustomAuthUserData->dwSizeOfCustomAuthData = dwSizeOfUserData;
  976. if ((dwSizeOfUserData != 0) && (pbUserData != NULL))
  977. {
  978. memcpy ((BYTE *)pPCB->pCustomAuthUserData->pbCustomAuthData,
  979. (BYTE *)pbUserData,
  980. dwSizeOfUserData);
  981. }
  982. if (pPCB->pCustomAuthConnData != NULL)
  983. {
  984. FREE (pPCB->pCustomAuthConnData);
  985. pPCB->pCustomAuthConnData = NULL;
  986. }
  987. pPCB->pCustomAuthConnData = MALLOC (dwSizeofConnData + sizeof (DWORD));
  988. if (pPCB->pCustomAuthConnData == NULL)
  989. {
  990. TRACE1 (USER, "ElProcessUserIdentityResponse: Error in allocating memory for AuthInfo = %ld",
  991. dwRetCode);
  992. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  993. break;
  994. }
  995. pPCB->pCustomAuthConnData->dwSizeOfCustomAuthData = dwSizeofConnData;
  996. if ((dwSizeofConnData != 0) && (pbConnData != NULL))
  997. {
  998. memcpy ((BYTE *)pPCB->pCustomAuthConnData->pbCustomAuthData,
  999. (BYTE *)pbConnData,
  1000. dwSizeofConnData);
  1001. }
  1002. fBlobCopyIncomplete = FALSE;
  1003. if ((dwRetCode = ElCreateAndSendIdentityResponse (
  1004. pPCB, pEAPUIContext)) != NO_ERROR)
  1005. {
  1006. TRACE1 (USER, "ElProcessUserIdentityResponse: ElCreateAndSendIdentityResponse failed with error %ld",
  1007. dwRetCode);
  1008. break;
  1009. }
  1010. // Mark the identity has been obtained for this PCB
  1011. pPCB->fGotUserIdentity = TRUE;
  1012. // Reset the state if identity was obtained, else port will
  1013. // recover by itself
  1014. pPCB->EapUIState &= ~EAPUISTATE_WAITING_FOR_IDENTITY;
  1015. }
  1016. while (FALSE);
  1017. // Cleanup
  1018. if (dwRetCode != NO_ERROR)
  1019. {
  1020. if (fPCBLocked && fBlobCopyIncomplete)
  1021. {
  1022. if (pPCB->pCustomAuthUserData != NULL)
  1023. {
  1024. FREE (pPCB->pCustomAuthUserData);
  1025. pPCB->pCustomAuthUserData = NULL;
  1026. }
  1027. if (pPCB->pszIdentity != NULL)
  1028. {
  1029. FREE (pPCB->pszIdentity);
  1030. pPCB->pszIdentity = NULL;
  1031. }
  1032. }
  1033. }
  1034. if (fPCBLocked)
  1035. {
  1036. RELEASE_WRITE_LOCK (&(pPCB->rwLock));
  1037. }
  1038. if (fPortReferenced)
  1039. {
  1040. EAPOL_DEREFERENCE_PORT (pPCB);
  1041. }
  1042. return dwRetCode;
  1043. }
  1044. //
  1045. // ElGetUserNamePassword
  1046. //
  1047. // Description:
  1048. //
  1049. // Function called to get username, domain (if any) and password using
  1050. // an interactive dialog. Called if EAP-type is MD5
  1051. //
  1052. // Arguments:
  1053. // pPCB - Pointer to PCB for the port/interface on which credentials
  1054. // are to be obtained
  1055. //
  1056. // Return values:
  1057. // NO_ERROR - success
  1058. // non-zero - error
  1059. //
  1060. DWORD
  1061. ElGetUserNamePassword (
  1062. IN EAPOL_PCB *pPCB
  1063. )
  1064. {
  1065. EAPOL_EAP_UI_CONTEXT *pEAPUIContext = NULL;
  1066. DWORD dwRetCode = NO_ERROR;
  1067. do
  1068. {
  1069. TRACE0 (USER, "ElGetUserNamePassword entered");
  1070. if (!EAPOL_PORT_ACTIVE(pPCB))
  1071. {
  1072. TRACE1 (PORT, "ElGetUserNamePassword: Port %ws not active",
  1073. pPCB->pwszDeviceGUID);
  1074. // Port is not active, cannot do further processing on this port
  1075. break;
  1076. }
  1077. // Get Access Token for user logged on interactively
  1078. if (pPCB->hUserToken != NULL)
  1079. {
  1080. if (!CloseHandle (pPCB->hUserToken))
  1081. {
  1082. dwRetCode = GetLastError ();
  1083. TRACE1 (USER, "ElGetUserNamePassword: CloseHandle failed with error %ld",
  1084. dwRetCode);
  1085. break;
  1086. }
  1087. }
  1088. pPCB->hUserToken = NULL;
  1089. if ((dwRetCode = ElGetWinStationUserToken (g_dwCurrentSessionId, &pPCB->hUserToken)) != NO_ERROR)
  1090. {
  1091. TRACE1 (USER, "ElGetUserNamePassword: ElGetWinStationUserToken failed with error (%ld)",
  1092. dwRetCode);
  1093. dwRetCode = ERROR_NO_TOKEN;
  1094. break;
  1095. }
  1096. if (!g_fTrayIconReady)
  1097. {
  1098. if ((dwRetCode = ElCheckUserModuleReady ()) != NO_ERROR)
  1099. {
  1100. TRACE1 (USER, "ElGetUserNamePassword: ElCheckUserModuleReady failed with error %ld",
  1101. dwRetCode);
  1102. break;
  1103. }
  1104. }
  1105. if (!g_fTrayIconReady)
  1106. {
  1107. DbLogPCBEvent (DBLOG_CATEG_WARN, pPCB, EAPOL_WAITING_FOR_DESKTOP_LOAD);
  1108. dwRetCode = ERROR_IO_PENDING;
  1109. TRACE0 (USER, "ElGetUserNamePassword: TrayIcon NOT ready");
  1110. break;
  1111. }
  1112. //
  1113. // Call ElGetUserNamePasswordDlgWorker
  1114. //
  1115. pEAPUIContext = MALLOC (sizeof(EAPOL_EAP_UI_CONTEXT));
  1116. if (pEAPUIContext == NULL)
  1117. {
  1118. TRACE0 (USER, "ElGetUserNamePassword: MALLOC failed for pEAPUIContext");
  1119. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  1120. break;
  1121. }
  1122. pEAPUIContext->dwEAPOLUIMsgType = EAPOLUI_GET_USERNAMEPASSWORD;
  1123. wcscpy (pEAPUIContext->wszGUID, pPCB->pwszDeviceGUID);
  1124. pPCB->dwUIInvocationId =
  1125. InterlockedIncrement(&(g_dwEAPUIInvocationId));
  1126. pEAPUIContext->dwSessionId = g_dwCurrentSessionId;
  1127. pEAPUIContext->dwContextId = pPCB->dwUIInvocationId;
  1128. pEAPUIContext->dwEapId = pPCB->bCurrentEAPId;
  1129. pEAPUIContext->dwEapTypeId = pPCB->dwEapTypeToBeUsed;
  1130. pEAPUIContext->dwEapFlags = pPCB->dwEapFlags;
  1131. if (pPCB->pSSID)
  1132. {
  1133. memcpy ((BYTE *)pEAPUIContext->bSSID, (BYTE *)pPCB->pSSID->Ssid,
  1134. NDIS_802_11_SSID_LEN-sizeof(ULONG));
  1135. pEAPUIContext->dwSizeOfSSID = pPCB->pSSID->SsidLength;
  1136. }
  1137. if (pPCB->pwszSSID)
  1138. {
  1139. wcscpy (pEAPUIContext->wszSSID, pPCB->pwszSSID);
  1140. }
  1141. // Post the message to netman
  1142. if ((dwRetCode = ElPostShowBalloonMessage (
  1143. pPCB,
  1144. sizeof(EAPOL_EAP_UI_CONTEXT),
  1145. (BYTE *)pEAPUIContext,
  1146. 0,
  1147. NULL
  1148. )) != NO_ERROR)
  1149. {
  1150. TRACE1 (USER, "ElGetUserNamePassword: ElPostShowBalloonMessage failed with error %ld",
  1151. dwRetCode);
  1152. break;
  1153. }
  1154. // Restart PCB timer since UI may take longer time than required
  1155. RESTART_TIMER (pPCB->hTimer,
  1156. INFINITE_SECONDS,
  1157. "PCB",
  1158. &dwRetCode);
  1159. if (dwRetCode != NO_ERROR)
  1160. {
  1161. break;
  1162. }
  1163. pPCB->EapUIState = EAPUISTATE_WAITING_FOR_IDENTITY;
  1164. DbLogPCBEvent (DBLOG_CATEG_INFO, pPCB, EAPOL_WAITING_FOR_DESKTOP_IDENTITY);
  1165. // Return error code as pending, since credentials have still not
  1166. // been acquired
  1167. dwRetCode = ERROR_IO_PENDING;
  1168. } while (FALSE);
  1169. if ((dwRetCode != NO_ERROR) && (dwRetCode != ERROR_IO_PENDING))
  1170. {
  1171. }
  1172. if (pEAPUIContext)
  1173. {
  1174. FREE (pEAPUIContext);
  1175. }
  1176. TRACE1 (USER, "ElGetUserNamePassword completed with error %ld", dwRetCode);
  1177. return dwRetCode;
  1178. }
  1179. //
  1180. // ElProcessUserNamePasswordResponse
  1181. //
  1182. // Description:
  1183. //
  1184. // UI Response handler function for ElGetUserNamePassword
  1185. //
  1186. // Arguments:
  1187. //
  1188. // Return values:
  1189. // NO_ERROR - success
  1190. // non-zero - error
  1191. //
  1192. DWORD
  1193. ElProcessUserNamePasswordResponse (
  1194. IN EAPOL_EAP_UI_CONTEXT EapolUIContext,
  1195. IN EAPOLUI_RESP EapolUIResp
  1196. )
  1197. {
  1198. DWORD dwSizeOfIdentity = 0;
  1199. BYTE *pbIdentity = NULL;
  1200. DWORD dwSizeOfPassword = 0;
  1201. BYTE *pbPassword = NULL;
  1202. HWND hwndOwner = NULL;
  1203. BOOLEAN fPCBLocked = FALSE;
  1204. BOOLEAN fPortReferenced = FALSE;
  1205. BOOLEAN fBlobCopyIncomplete = FALSE;
  1206. EAPOL_PCB *pPCB = NULL;
  1207. EAPOL_EAP_UI_CONTEXT *pEAPUIContext = NULL;
  1208. DWORD dwRetCode = NO_ERROR;
  1209. do
  1210. {
  1211. TRACE0 (USER, "ElProcessUserNamePasswordResponse entered");
  1212. pEAPUIContext = (EAPOL_EAP_UI_CONTEXT *)&EapolUIContext;
  1213. ACQUIRE_WRITE_LOCK (&g_PCBLock);
  1214. if ((pPCB = ElGetPCBPointerFromPortGUID (pEAPUIContext->wszGUID)) != NULL)
  1215. {
  1216. if (EAPOL_REFERENCE_PORT (pPCB))
  1217. {
  1218. fPortReferenced = TRUE;
  1219. }
  1220. else
  1221. {
  1222. pPCB = NULL;
  1223. }
  1224. }
  1225. RELEASE_WRITE_LOCK (&g_PCBLock);
  1226. if (pPCB == NULL)
  1227. {
  1228. break;
  1229. }
  1230. ACQUIRE_WRITE_LOCK (&(pPCB->rwLock));
  1231. fPCBLocked = TRUE;
  1232. if (!EAPOL_PORT_ACTIVE(pPCB))
  1233. {
  1234. TRACE1 (PORT, "ElProcessUserNamePasswordResponse: Port %ws not active",
  1235. pPCB->pwszDeviceGUID);
  1236. // Port is not active, cannot do further processing on this port
  1237. break;
  1238. }
  1239. if (pEAPUIContext->dwRetCode != NO_ERROR)
  1240. {
  1241. DbLogPCBEvent (DBLOG_CATEG_ERR, pPCB,
  1242. EAPOL_ERROR_DESKTOP_IDENTITY, dwRetCode);
  1243. TRACE1 (USER, "ElProcessUserNamePasswordResponse: Error in Dialog function (%ld)",
  1244. pEAPUIContext->dwRetCode);
  1245. break;
  1246. }
  1247. if (pPCB->EapUIState != EAPUISTATE_WAITING_FOR_IDENTITY)
  1248. {
  1249. TRACE2 (USER, "ElProcessUserNamePasswordResponse: PCB EapUIState has changed to (%ld), expected = (%ld)",
  1250. pPCB->EapUIState, EAPUISTATE_WAITING_FOR_IDENTITY);
  1251. break;
  1252. }
  1253. if (pPCB->dwUIInvocationId != pEAPUIContext->dwContextId)
  1254. {
  1255. TRACE2 (USER, "ElProcessUserNamePasswordResponse: PCB UI Id has changed to (%ld), expected = (%ld)",
  1256. pPCB->dwUIInvocationId, pEAPUIContext->dwContextId);
  1257. // break;
  1258. }
  1259. if (pPCB->bCurrentEAPId != pEAPUIContext->dwEapId)
  1260. {
  1261. TRACE2 (USER, "ElProcessUserNamePasswordResponse: PCB EAP Id has changed to (%ld), expected = (%ld)",
  1262. pPCB->bCurrentEAPId, pEAPUIContext->dwEapId);
  1263. // break;
  1264. }
  1265. // Since the PCB context is right, restart PCB timer to timeout
  1266. // in authPeriod seconds
  1267. RESTART_TIMER (pPCB->hTimer,
  1268. pPCB->EapolConfig.dwauthPeriod,
  1269. "PCB",
  1270. &dwRetCode);
  1271. if (dwRetCode != NO_ERROR)
  1272. {
  1273. TRACE1 (USER, "ElProcessUserNamePasswordResponse: Error in RESTART_TIMER %ld",
  1274. dwRetCode);
  1275. break;
  1276. }
  1277. DbLogPCBEvent (DBLOG_CATEG_INFO, pPCB, EAPOL_PROCESSING_DESKTOP_RESPONSE);
  1278. if ((EapolUIResp.rdData0.dwDataLen != 0) && (EapolUIResp.rdData0.pData != NULL))
  1279. {
  1280. dwSizeOfIdentity = EapolUIResp.rdData0.dwDataLen;
  1281. pbIdentity = EapolUIResp.rdData0.pData;
  1282. }
  1283. if ((EapolUIResp.rdData1.dwDataLen != 0) && (EapolUIResp.rdData1.pData != NULL))
  1284. {
  1285. dwSizeOfPassword = EapolUIResp.rdData1.dwDataLen;
  1286. pbPassword = EapolUIResp.rdData1.pData;
  1287. }
  1288. fBlobCopyIncomplete = TRUE;
  1289. if (pPCB->pszIdentity != NULL)
  1290. {
  1291. FREE (pPCB->pszIdentity);
  1292. pPCB->pszIdentity = NULL;
  1293. }
  1294. if (pPCB->PasswordBlob.pbData != NULL)
  1295. {
  1296. FREE (pPCB->PasswordBlob.pbData);
  1297. pPCB->PasswordBlob.pbData = NULL;
  1298. pPCB->PasswordBlob.cbData = 0;
  1299. }
  1300. if (pbIdentity != NULL)
  1301. {
  1302. pPCB->pszIdentity = MALLOC (dwSizeOfIdentity + sizeof(CHAR));
  1303. if (pPCB->pszIdentity == NULL)
  1304. {
  1305. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  1306. TRACE0 (USER, "ElProcessUserNamePasswordResponse: MALLOC failed for pPCB->pszIdentity");
  1307. break;
  1308. }
  1309. memcpy (pPCB->pszIdentity, pbIdentity, dwSizeOfIdentity);
  1310. pPCB->pszIdentity[dwSizeOfIdentity] = '\0';
  1311. TRACE1 (USER, "ElProcessUserNamePasswordResponse: Got username = %s",
  1312. pPCB->pszIdentity);
  1313. }
  1314. if (pbPassword != 0)
  1315. {
  1316. if ((pPCB->PasswordBlob.pbData =
  1317. MALLOC (dwSizeOfPassword)) == NULL)
  1318. {
  1319. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  1320. break;
  1321. }
  1322. memcpy (pPCB->PasswordBlob.pbData, pbPassword, dwSizeOfPassword);
  1323. pPCB->PasswordBlob.cbData = dwSizeOfPassword;
  1324. }
  1325. fBlobCopyIncomplete = FALSE;
  1326. if ((dwRetCode = ElCreateAndSendIdentityResponse (
  1327. pPCB, pEAPUIContext)) != NO_ERROR)
  1328. {
  1329. TRACE1 (USER, "ElProcessUserNamePasswordResponse: ElCreateAndSendIdentityResponse failed with error %ld",
  1330. dwRetCode);
  1331. break;
  1332. }
  1333. // Mark the identity has been obtained for this PCB
  1334. pPCB->fGotUserIdentity = TRUE;
  1335. // Reset the state if identity was obtained, else the port will recover
  1336. // by itself
  1337. pPCB->EapUIState &= ~EAPUISTATE_WAITING_FOR_IDENTITY;
  1338. } while (FALSE);
  1339. if (dwRetCode != NO_ERROR)
  1340. {
  1341. if (fPCBLocked && fBlobCopyIncomplete)
  1342. {
  1343. if (pPCB->pszIdentity)
  1344. {
  1345. FREE (pPCB->pszIdentity);
  1346. pPCB->pszIdentity = NULL;
  1347. }
  1348. if (pPCB->PasswordBlob.pbData)
  1349. {
  1350. FREE (pPCB->PasswordBlob.pbData);
  1351. pPCB->PasswordBlob.pbData = NULL;
  1352. pPCB->PasswordBlob.cbData = 0;
  1353. }
  1354. }
  1355. }
  1356. if (fPCBLocked)
  1357. {
  1358. RELEASE_WRITE_LOCK (&(pPCB->rwLock));
  1359. }
  1360. if (fPortReferenced)
  1361. {
  1362. EAPOL_DEREFERENCE_PORT (pPCB);
  1363. }
  1364. TRACE1 (USER, "ElProcessUserNamePasswordResponse completed with error %ld", dwRetCode);
  1365. return dwRetCode;
  1366. }
  1367. //
  1368. // ElInvokeInteractiveUI
  1369. //
  1370. // Description:
  1371. //
  1372. // Function called to invoke RasEapInvokeInteractiveUI for an EAP on a
  1373. // particular interface
  1374. //
  1375. // Arguments:
  1376. // pPCB - Pointer to PCB for the specific interface
  1377. // pInvokeEapUIIn - Data to be supplied to the InvokeInteractiveUI entrypoint
  1378. // provided by the EAP dll through PPP_EAP_OUTPUT structure
  1379. //
  1380. DWORD
  1381. ElInvokeInteractiveUI (
  1382. IN EAPOL_PCB *pPCB,
  1383. IN ELEAP_INVOKE_EAP_UI *pInvokeEapUIIn
  1384. )
  1385. {
  1386. EAPOL_EAP_UI_CONTEXT *pEAPUIContext = NULL;
  1387. DWORD dwRetCode = NO_ERROR;
  1388. do
  1389. {
  1390. if (pInvokeEapUIIn == NULL)
  1391. {
  1392. dwRetCode = ERROR_INVALID_PARAMETER;
  1393. return dwRetCode;
  1394. }
  1395. if (pPCB->PreviousAuthenticationType == EAPOL_MACHINE_AUTHENTICATION)
  1396. {
  1397. TRACE0 (USER, "ElInvokeInteractiveUI: Cannot popup UI during machine authentication");
  1398. DbLogPCBEvent (DBLOG_CATEG_ERR, pPCB, EAPOL_CANNOT_DESKTOP_MACHINE_AUTH);
  1399. dwRetCode = ERROR_CAN_NOT_COMPLETE;
  1400. break;
  1401. }
  1402. if (!g_fTrayIconReady)
  1403. {
  1404. if ((dwRetCode = ElCheckUserModuleReady ()) != NO_ERROR)
  1405. {
  1406. TRACE1 (USER, "ElInvokeInteractiveUI: ElCheckUserModuleReady failed with error %ld",
  1407. dwRetCode);
  1408. break;
  1409. }
  1410. }
  1411. if (!g_fTrayIconReady)
  1412. {
  1413. DbLogPCBEvent (DBLOG_CATEG_WARN, pPCB, EAPOL_WAITING_FOR_DESKTOP_LOAD);
  1414. dwRetCode = ERROR_IO_PENDING;
  1415. TRACE0 (USER, "ElInvokeInteractiveUI: TrayIcon NOT ready");
  1416. break;
  1417. }
  1418. TRACE0 (USER, "ElInvokeInteractiveUI entered");
  1419. //
  1420. // Call ElInvokeInteractiveUIDlgWorker
  1421. //
  1422. pEAPUIContext = MALLOC (sizeof(EAPOL_EAP_UI_CONTEXT) +
  1423. pInvokeEapUIIn->dwSizeOfUIContextData);
  1424. if (pEAPUIContext == NULL)
  1425. {
  1426. TRACE0 (USER, "ElInvokeInteractiveUI: MALLOC failed for pEAPUIContext");
  1427. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  1428. break;
  1429. }
  1430. pEAPUIContext->dwEAPOLUIMsgType = EAPOLUI_INVOKEINTERACTIVEUI;
  1431. wcscpy (pEAPUIContext->wszGUID, pPCB->pwszDeviceGUID);
  1432. pPCB->dwUIInvocationId =
  1433. InterlockedIncrement(&(g_dwEAPUIInvocationId));
  1434. pEAPUIContext->dwSessionId = g_dwCurrentSessionId;
  1435. pEAPUIContext->dwContextId = pPCB->dwUIInvocationId;
  1436. pEAPUIContext->dwEapId = pPCB->bCurrentEAPId;
  1437. pEAPUIContext->dwEapTypeId = pPCB->dwEapTypeToBeUsed;
  1438. pEAPUIContext->dwEapFlags = pPCB->dwEapFlags;
  1439. if (pPCB->pSSID)
  1440. {
  1441. pEAPUIContext->dwSizeOfSSID = pPCB->pSSID->SsidLength;
  1442. memcpy ((BYTE *)pEAPUIContext->bSSID, (BYTE *)pPCB->pSSID->Ssid,
  1443. NDIS_802_11_SSID_LEN-sizeof(ULONG));
  1444. }
  1445. if (pPCB->pwszSSID)
  1446. {
  1447. wcscpy (pEAPUIContext->wszSSID, pPCB->pwszSSID);
  1448. }
  1449. pEAPUIContext->dwSizeOfEapUIData =
  1450. pInvokeEapUIIn->dwSizeOfUIContextData;
  1451. memcpy (pEAPUIContext->bEapUIData, pInvokeEapUIIn->pbUIContextData,
  1452. pInvokeEapUIIn->dwSizeOfUIContextData);
  1453. // Post the message to netman
  1454. if ((dwRetCode = ElPostShowBalloonMessage (
  1455. pPCB,
  1456. sizeof(EAPOL_EAP_UI_CONTEXT)+pInvokeEapUIIn->dwSizeOfUIContextData,
  1457. (BYTE *)pEAPUIContext,
  1458. 0,
  1459. NULL
  1460. )) != NO_ERROR)
  1461. {
  1462. TRACE1 (USER, "ElInvokeInteractiveUI: ElPostShowBalloonMessage failed with error %ld",
  1463. dwRetCode);
  1464. break;
  1465. }
  1466. // Restart PCB timer since UI may take longer time than required
  1467. RESTART_TIMER (pPCB->hTimer,
  1468. INFINITE_SECONDS,
  1469. "PCB",
  1470. &dwRetCode);
  1471. if (dwRetCode != NO_ERROR)
  1472. {
  1473. break;
  1474. }
  1475. pPCB->EapUIState = EAPUISTATE_WAITING_FOR_UI_RESPONSE;
  1476. DbLogPCBEvent (DBLOG_CATEG_INFO, pPCB, EAPOL_WAITING_FOR_DESKTOP_LOGON);
  1477. TRACE0 (USER, "ElInvokeInteractiveUI: ElEapWork completed successfully");
  1478. } while (FALSE);
  1479. if (pInvokeEapUIIn->pbUIContextData != NULL)
  1480. {
  1481. FREE (pInvokeEapUIIn->pbUIContextData);
  1482. pInvokeEapUIIn->pbUIContextData = NULL;
  1483. pInvokeEapUIIn->dwSizeOfUIContextData = 0;
  1484. }
  1485. if (pEAPUIContext != NULL)
  1486. {
  1487. FREE (pEAPUIContext);
  1488. }
  1489. TRACE1 (USER, "ElInvokeInteractiveUI completed with error %ld", dwRetCode);
  1490. return dwRetCode;
  1491. }
  1492. //
  1493. // ElProcessInvokeInteractiveUIResponse
  1494. //
  1495. // Description:
  1496. //
  1497. // Worker function for ElInvokeInteractiveUI
  1498. //
  1499. // Arguments:
  1500. //
  1501. DWORD
  1502. ElProcessInvokeInteractiveUIResponse (
  1503. IN EAPOL_EAP_UI_CONTEXT EapolUIContext,
  1504. IN EAPOLUI_RESP EapolUIResp
  1505. )
  1506. {
  1507. BYTE *pbUIData = NULL;
  1508. DWORD dwSizeOfUIData = 0;
  1509. EAPOL_PCB *pPCB = NULL;
  1510. EAPOL_EAP_UI_CONTEXT *pEAPUIContext = NULL;
  1511. BOOLEAN fPortReferenced = FALSE;
  1512. BOOLEAN fPCBLocked = FALSE;
  1513. DWORD dwRetCode = NO_ERROR;
  1514. do
  1515. {
  1516. TRACE0 (USER, "ElProcessInvokeInteractiveUIResponse entered");
  1517. pEAPUIContext = (EAPOL_EAP_UI_CONTEXT *)&EapolUIContext;
  1518. ACQUIRE_WRITE_LOCK (&g_PCBLock);
  1519. if ((pPCB = ElGetPCBPointerFromPortGUID (pEAPUIContext->wszGUID)) != NULL)
  1520. {
  1521. if (EAPOL_REFERENCE_PORT (pPCB))
  1522. {
  1523. fPortReferenced = TRUE;
  1524. }
  1525. else
  1526. {
  1527. pPCB = NULL;
  1528. }
  1529. }
  1530. RELEASE_WRITE_LOCK (&g_PCBLock);
  1531. if (pPCB == NULL)
  1532. {
  1533. break;
  1534. }
  1535. ACQUIRE_WRITE_LOCK (&(pPCB->rwLock));
  1536. fPCBLocked = TRUE;
  1537. if (!EAPOL_PORT_ACTIVE(pPCB))
  1538. {
  1539. TRACE1 (PORT, "ElProcessInvokeInteractiveUIResponse: Port %ws not active",
  1540. pPCB->pwszDeviceGUID);
  1541. break;
  1542. }
  1543. if (pEAPUIContext->dwRetCode != NO_ERROR)
  1544. {
  1545. DbLogPCBEvent (DBLOG_CATEG_ERR, pPCB, EAPOL_ERROR_DESKTOP_LOGON, dwRetCode);
  1546. TRACE1 (USER, "ElProcessInvokeInteractiveUIResponse: Error in Dialog function (%ld)",
  1547. pEAPUIContext->dwRetCode);
  1548. break;
  1549. }
  1550. if (pPCB->EapUIState != EAPUISTATE_WAITING_FOR_UI_RESPONSE)
  1551. {
  1552. TRACE2 (USER, "ElProcessInvokeInteractiveUIResponse: PCB EapUIState has changed to (%ld), expected = (%ld)",
  1553. pPCB->EapUIState, EAPUISTATE_WAITING_FOR_UI_RESPONSE);
  1554. break;
  1555. }
  1556. if (pPCB->dwUIInvocationId != pEAPUIContext->dwContextId)
  1557. {
  1558. TRACE2 (USER, "ElProcessInvokeInteractiveUIResponse: PCB UI Id has changed to (%ld), expected = (%ld)",
  1559. pPCB->dwUIInvocationId, pEAPUIContext->dwContextId);
  1560. // break;
  1561. }
  1562. if (pPCB->bCurrentEAPId != pEAPUIContext->dwEapId)
  1563. {
  1564. TRACE2 (USER, "ElProcessInvokeInteractiveUIResponse: PCB EAP Id has changed to (%ld), expected = (%ld)",
  1565. pPCB->bCurrentEAPId, pEAPUIContext->dwEapId);
  1566. // break;
  1567. }
  1568. // Since the PCB context is right, restart PCB timer to timeout
  1569. // in authPeriod seconds
  1570. RESTART_TIMER (pPCB->hTimer,
  1571. pPCB->EapolConfig.dwauthPeriod,
  1572. "PCB",
  1573. &dwRetCode);
  1574. if (dwRetCode != NO_ERROR)
  1575. {
  1576. TRACE1 (USER, "ElProcessInvokeInteractiveUIResponse: Error in RESTART_TIMER %ld",
  1577. dwRetCode);
  1578. break;
  1579. }
  1580. DbLogPCBEvent (DBLOG_CATEG_INFO, pPCB, EAPOL_PROCESSING_DESKTOP_RESPONSE);
  1581. if ((EapolUIResp.rdData0.dwDataLen != 0) && (EapolUIResp.rdData0.pData != NULL))
  1582. {
  1583. dwSizeOfUIData = EapolUIResp.rdData0.dwDataLen;
  1584. pbUIData = EapolUIResp.rdData0.pData;
  1585. }
  1586. if (pPCB->EapUIData.pEapUIData != NULL)
  1587. {
  1588. FREE (pPCB->EapUIData.pEapUIData);
  1589. pPCB->EapUIData.pEapUIData = NULL;
  1590. pPCB->EapUIData.dwSizeOfEapUIData = 0;
  1591. }
  1592. pPCB->EapUIData.pEapUIData = MALLOC (dwSizeOfUIData);
  1593. if (pPCB->EapUIData.pEapUIData == NULL)
  1594. {
  1595. TRACE1 (USER, "ElProcessInvokeInteractiveUIResponse: Error in allocating memory for UIData = %ld",
  1596. dwRetCode);
  1597. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  1598. break;
  1599. }
  1600. pPCB->EapUIData.dwSizeOfEapUIData = dwSizeOfUIData;
  1601. if ((dwSizeOfUIData != 0) && (pbUIData != NULL))
  1602. {
  1603. memcpy ((BYTE *)pPCB->EapUIData.pEapUIData,
  1604. (BYTE *)pbUIData,
  1605. dwSizeOfUIData);
  1606. }
  1607. pPCB->EapUIData.dwContextId = pPCB->dwUIInvocationId;
  1608. pPCB->fEapUIDataReceived = TRUE;
  1609. TRACE0 (USER, "ElProcessInvokeInteractiveUIResponse: Calling ElEapWork");
  1610. // Provide UI data to EAP Dll for processing
  1611. // EAP will send out response if required
  1612. if ((dwRetCode = ElEapWork (
  1613. pPCB,
  1614. NULL)) != NO_ERROR)
  1615. {
  1616. TRACE1 (USER, "ElProcessInvokeInteractiveUIResponse: ElEapWork failed with error = %ld",
  1617. dwRetCode);
  1618. break;
  1619. }
  1620. // Reset the state
  1621. pPCB->EapUIState &= ~EAPUISTATE_WAITING_FOR_UI_RESPONSE;
  1622. TRACE0 (USER, "ElProcessInvokeInteractiveUIResponse: ElEapWork completed successfully");
  1623. } while (FALSE);
  1624. // Cleanup
  1625. if (dwRetCode != NO_ERROR)
  1626. {
  1627. if (pPCB->EapUIData.pEapUIData != NULL)
  1628. {
  1629. FREE (pPCB->EapUIData.pEapUIData);
  1630. pPCB->EapUIData.pEapUIData = NULL;
  1631. pPCB->EapUIData.dwSizeOfEapUIData = 0;
  1632. }
  1633. }
  1634. if (fPCBLocked)
  1635. {
  1636. RELEASE_WRITE_LOCK (&(pPCB->rwLock));
  1637. }
  1638. if (fPortReferenced)
  1639. {
  1640. EAPOL_DEREFERENCE_PORT (pPCB);
  1641. }
  1642. TRACE1 (USER, "ElProcessInvokeInteractiveUIResponse completed with error %ld",
  1643. dwRetCode);
  1644. return dwRetCode;
  1645. }
  1646. //
  1647. // ElCreateAndSendIdentityResponse
  1648. //
  1649. // Description:
  1650. //
  1651. // Function called send out Identity Response packet
  1652. //
  1653. // Arguments:
  1654. // pPCB - Port Control Block for appropriate interface
  1655. // pEAPUIContext - UI context blob
  1656. //
  1657. // Return values:
  1658. // NO_ERROR - success
  1659. // !NO_ERROR - error
  1660. //
  1661. //
  1662. DWORD
  1663. ElCreateAndSendIdentityResponse (
  1664. IN EAPOL_PCB *pPCB,
  1665. IN EAPOL_EAP_UI_CONTEXT *pEAPUIContext
  1666. )
  1667. {
  1668. PPP_EAP_PACKET *pSendBuf = NULL;
  1669. EAPOL_PACKET *pEapolPkt = NULL;
  1670. WORD wSizeOfEapPkt = 0;
  1671. DWORD dwIdentityLength = 0;
  1672. DWORD dwRetCode = NO_ERROR;
  1673. do
  1674. {
  1675. // Create buffer for EAPOL + EAP and pass pointer to EAP header
  1676. pEapolPkt = (EAPOL_PACKET *) MALLOC (MAX_EAPOL_BUFFER_SIZE);
  1677. TRACE1 (EAPOL, "ElCreateAndSendIdResp: EapolPkt created at %p", pEapolPkt);
  1678. if (pEapolPkt == NULL)
  1679. {
  1680. TRACE0 (EAPOL, "ElCreateAndSendIdResp: Error allocating EAP buffer");
  1681. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  1682. break;
  1683. }
  1684. // Point to EAP header
  1685. pSendBuf = (PPP_EAP_PACKET *)((PBYTE)pEapolPkt + sizeof (EAPOL_PACKET) - 1);
  1686. pSendBuf->Code = EAPCODE_Response;
  1687. pSendBuf->Id = (BYTE)pPCB->bCurrentEAPId;
  1688. if (pPCB->pszIdentity != NULL)
  1689. {
  1690. dwIdentityLength = strlen (pPCB->pszIdentity);
  1691. }
  1692. else
  1693. {
  1694. dwIdentityLength = 0;
  1695. }
  1696. HostToWireFormat16 (
  1697. (WORD)(PPP_EAP_PACKET_HDR_LEN+1+dwIdentityLength),
  1698. pSendBuf->Length );
  1699. strncpy ((CHAR *)pSendBuf->Data+1, (CHAR *)pPCB->pszIdentity,
  1700. dwIdentityLength);
  1701. TRACE1 (EAPOL, "ElCreateAndSendIdResp: Identity sent out = %s",
  1702. pPCB->pszIdentity);
  1703. pSendBuf->Data[0] = EAPTYPE_Identity;
  1704. // Indicate to EAPOL what is length of the EAP packet
  1705. wSizeOfEapPkt = (WORD)(PPP_EAP_PACKET_HDR_LEN+
  1706. 1+dwIdentityLength);
  1707. // Send out EAPOL packet
  1708. memcpy ((BYTE *)pEapolPkt->EthernetType,
  1709. (BYTE *)pPCB->bEtherType,
  1710. SIZE_ETHERNET_TYPE);
  1711. pEapolPkt->ProtocolVersion = pPCB->bProtocolVersion;
  1712. pEapolPkt->PacketType = EAP_Packet;
  1713. HostToWireFormat16 ((WORD) wSizeOfEapPkt,
  1714. (BYTE *)pEapolPkt->PacketBodyLength);
  1715. // Make a copy of the EAPOL packet in the PCB
  1716. // Will be used during retransmission
  1717. if (pPCB->pbPreviousEAPOLPkt != NULL)
  1718. {
  1719. FREE (pPCB->pbPreviousEAPOLPkt);
  1720. }
  1721. pPCB->pbPreviousEAPOLPkt =
  1722. MALLOC (sizeof (EAPOL_PACKET)+wSizeOfEapPkt-1);
  1723. if (pPCB->pbPreviousEAPOLPkt == NULL)
  1724. {
  1725. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  1726. break;
  1727. }
  1728. memcpy (pPCB->pbPreviousEAPOLPkt, pEapolPkt,
  1729. sizeof (EAPOL_PACKET)+wSizeOfEapPkt-1);
  1730. pPCB->dwSizeOfPreviousEAPOLPkt =
  1731. sizeof (EAPOL_PACKET)+wSizeOfEapPkt-1;
  1732. pPCB->dwPreviousId = pPCB->bCurrentEAPId;
  1733. // Send packet out on the port
  1734. dwRetCode = ElWriteToPort (pPCB,
  1735. (CHAR *)pEapolPkt,
  1736. sizeof (EAPOL_PACKET)+wSizeOfEapPkt-1);
  1737. if (dwRetCode != NO_ERROR)
  1738. {
  1739. TRACE1 (EAPOL, "ElCreateAndSendIdResp: Error in writing EAP_Packet to port %ld",
  1740. dwRetCode);
  1741. break;
  1742. }
  1743. }
  1744. while (FALSE);
  1745. if (pEapolPkt != NULL)
  1746. {
  1747. FREE (pEapolPkt);
  1748. }
  1749. return dwRetCode;
  1750. }
  1751. //
  1752. // ElSendGuestIdentityResponse
  1753. //
  1754. // Description:
  1755. //
  1756. // Function called send out Guest Identity Response packet
  1757. //
  1758. // Arguments:
  1759. // pEAPUIContext - UI context blob
  1760. //
  1761. // Return values:
  1762. // NO_ERROR - success
  1763. // !NO_ERROR - failure
  1764. //
  1765. DWORD
  1766. ElSendGuestIdentityResponse (
  1767. IN EAPOL_EAP_UI_CONTEXT *pEAPUIContext
  1768. )
  1769. {
  1770. EAPOL_PCB *pPCB = NULL;
  1771. BOOLEAN fPortReferenced = FALSE;
  1772. BOOLEAN fPCBLocked = FALSE;
  1773. DWORD dwRetCode = NO_ERROR;
  1774. do
  1775. {
  1776. ACQUIRE_WRITE_LOCK (&g_PCBLock);
  1777. if ((pPCB = ElGetPCBPointerFromPortGUID (pEAPUIContext->wszGUID)) != NULL)
  1778. {
  1779. if (EAPOL_REFERENCE_PORT (pPCB))
  1780. {
  1781. fPortReferenced = TRUE;
  1782. }
  1783. else
  1784. {
  1785. pPCB = NULL;
  1786. }
  1787. }
  1788. RELEASE_WRITE_LOCK (&g_PCBLock);
  1789. if (pPCB == NULL)
  1790. {
  1791. break;
  1792. }
  1793. ACQUIRE_WRITE_LOCK (&(pPCB->rwLock));
  1794. fPCBLocked = TRUE;
  1795. // Send the identity out as a EAP-Response packet
  1796. if (pPCB->EapUIState != EAPUISTATE_WAITING_FOR_IDENTITY)
  1797. {
  1798. TRACE2 (USER, "ElSendGuestIdentityResponse: PCB EapUIState has changed to (%ld), expected = (%ld)",
  1799. pPCB->EapUIState, EAPUISTATE_WAITING_FOR_IDENTITY);
  1800. dwRetCode = ERROR_CAN_NOT_COMPLETE;
  1801. break;
  1802. }
  1803. if (pPCB->dwUIInvocationId != pEAPUIContext->dwContextId)
  1804. {
  1805. TRACE2 (USER, "ElSendGuestIdentityResponse: PCB UI Id has changed to (%ld), expected = (%ld)",
  1806. pPCB->dwUIInvocationId, pEAPUIContext->dwContextId);
  1807. dwRetCode = ERROR_CAN_NOT_COMPLETE;
  1808. break;
  1809. }
  1810. if (pPCB->bCurrentEAPId != pEAPUIContext->dwEapId)
  1811. {
  1812. TRACE2 (USER, "ElSendGuestIdentityResponse: PCB EAP Id has changed to (%ld), expected = (%ld)",
  1813. pPCB->bCurrentEAPId, pEAPUIContext->dwEapId);
  1814. dwRetCode = ERROR_CAN_NOT_COMPLETE;
  1815. break;
  1816. }
  1817. if (pPCB->pszIdentity != NULL)
  1818. {
  1819. FREE (pPCB->pszIdentity);
  1820. pPCB->pszIdentity = NULL;
  1821. }
  1822. // Do not flag that identity was received
  1823. // Reset the UI state though for state machine to proceed
  1824. pPCB->EapUIState &= ~EAPUISTATE_WAITING_FOR_IDENTITY;
  1825. pPCB->PreviousAuthenticationType = EAPOL_UNAUTHENTICATED_ACCESS;
  1826. if ((dwRetCode = ElCreateAndSendIdentityResponse (
  1827. pPCB, pEAPUIContext)) != NO_ERROR)
  1828. {
  1829. TRACE1 (USER, "ElSendGuestIdentityResponse: ElCreateAndSendIdentityResponse failed with error %ld",
  1830. dwRetCode);
  1831. break;
  1832. }
  1833. }
  1834. while (FALSE);
  1835. if (fPCBLocked)
  1836. {
  1837. RELEASE_WRITE_LOCK (&(pPCB->rwLock));
  1838. }
  1839. if (fPortReferenced)
  1840. {
  1841. EAPOL_DEREFERENCE_PORT (pPCB);
  1842. }
  1843. return dwRetCode;
  1844. }