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.

765 lines
17 KiB

  1. #include <precomp.h>
  2. BOOL
  3. WZCSvcMain(
  4. IN PVOID hmod,
  5. IN DWORD dwReason,
  6. IN PCONTEXT pctx OPTIONAL)
  7. {
  8. DBG_UNREFERENCED_PARAMETER(pctx);
  9. switch (dwReason)
  10. {
  11. case DLL_PROCESS_ATTACH:
  12. DisableThreadLibraryCalls((HMODULE) hmod);
  13. break;
  14. case DLL_PROCESS_DETACH:
  15. break;
  16. }
  17. return TRUE;
  18. }
  19. //---------------------------------------
  20. // GetSPResModule: Utility function used to return
  21. // the handle to the module having WZC UI resources
  22. // (needed for XP.QFE & XP.SP1 builds)
  23. HINSTANCE
  24. WZCGetSPResModule()
  25. {
  26. static HINSTANCE st_hModule = NULL;
  27. if (st_hModule == NULL)
  28. {
  29. WCHAR wszFullPath[_MAX_PATH];
  30. if (ExpandEnvironmentStrings(
  31. L"%systemroot%\\system32\\xpsp1res.dll",
  32. wszFullPath,
  33. _MAX_PATH) != 0)
  34. {
  35. st_hModule = LoadLibraryEx(
  36. wszFullPath,
  37. NULL,
  38. 0);
  39. }
  40. }
  41. return st_hModule;
  42. }
  43. //---------------------------------------
  44. // GetSPResModule: Utility function used to return
  45. // the handle to the module having WZC UI resources
  46. // (needed for XP.QFE & XP.SP1 builds)
  47. HINSTANCE
  48. WZCGetDlgResModule()
  49. {
  50. static HINSTANCE st_hDlgModule = NULL;
  51. if (st_hDlgModule == NULL)
  52. {
  53. WCHAR wszFullPath[_MAX_PATH];
  54. if (ExpandEnvironmentStrings(
  55. L"%systemroot%\\system32\\wzcdlg.dll",
  56. wszFullPath,
  57. _MAX_PATH) != 0)
  58. {
  59. st_hDlgModule = LoadLibraryEx(
  60. wszFullPath,
  61. NULL,
  62. 0);
  63. }
  64. }
  65. return st_hDlgModule;
  66. }
  67. //---------------------------------------
  68. // WZCDeleteIntfObj: cleans an INTF_ENTRY object that is
  69. // allocated within any RPC call.
  70. VOID
  71. WZCDeleteIntfObj(
  72. PINTF_ENTRY pIntf)
  73. {
  74. if (pIntf != NULL)
  75. {
  76. RpcFree(pIntf->wszGuid);
  77. RpcFree(pIntf->wszDescr);
  78. RpcFree(pIntf->rdSSID.pData);
  79. RpcFree(pIntf->rdBSSID.pData);
  80. RpcFree(pIntf->rdBSSIDList.pData);
  81. RpcFree(pIntf->rdStSSIDList.pData);
  82. RpcFree(pIntf->rdCtrlData.pData);
  83. }
  84. }
  85. //---------------------------------------
  86. // WZCEnumInterfaces: provides the table of key
  87. // information for all the interfaces that are managed.
  88. // For all subsequent calls the clients need to identify
  89. // the Interface it operates on by providing the respective
  90. // key info.
  91. //
  92. // Parameters:
  93. // pSrvAddr
  94. // [in] WZC Server to contact
  95. // pIntf
  96. // [out] table of key info for all interfaces
  97. // Returned value:
  98. // Win32 error code
  99. DWORD
  100. WZCEnumInterfaces(
  101. LPWSTR pSrvAddr,
  102. PINTFS_KEY_TABLE pIntfs)
  103. {
  104. DWORD rpcStatus = RPC_S_OK;
  105. RpcTryExcept
  106. {
  107. rpcStatus = RpcEnumInterfaces(pSrvAddr, pIntfs);
  108. }
  109. RpcExcept(TRUE)
  110. {
  111. rpcStatus = RpcExceptionCode();
  112. }
  113. RpcEndExcept
  114. return rpcStatus;
  115. }
  116. //---------------------------------------
  117. // WZCQueryIterface: provides detailed information for a
  118. // given interface.
  119. //
  120. // Parameters:
  121. // pSrvAddr:
  122. // [in] WZC Server to contact
  123. // dwInFlags:
  124. // [in] Fields to be queried (bitmask of INTF_*)
  125. // pIntf:
  126. // [in] Key of the interface to query
  127. // [out] Requested data from the interface.
  128. // pdwOutFlags
  129. // [out] Fields successfully retrieved (bitmask of INTF_*)
  130. //
  131. // Returned value:
  132. // Win32 error code
  133. DWORD
  134. WZCQueryInterface(
  135. LPWSTR pSrvAddr,
  136. DWORD dwInFlags,
  137. PINTF_ENTRY pIntf,
  138. LPDWORD pdwOutFlags)
  139. {
  140. DWORD rpcStatus = RPC_S_OK;
  141. if (pIntf == NULL || pIntf->wszGuid == NULL)
  142. {
  143. rpcStatus = ERROR_INVALID_PARAMETER;
  144. goto exit;
  145. }
  146. RpcTryExcept
  147. {
  148. DWORD dwOutFlags;
  149. rpcStatus = RpcQueryInterface(
  150. pSrvAddr,
  151. dwInFlags,
  152. pIntf,
  153. &dwOutFlags);
  154. if ((dwInFlags & INTF_PREFLIST) &&
  155. (dwOutFlags & INTF_PREFLIST) &&
  156. pIntf->rdStSSIDList.dwDataLen != 0)
  157. {
  158. PWZC_802_11_CONFIG_LIST pwzcPList;
  159. UINT nIdx;
  160. pwzcPList = (PWZC_802_11_CONFIG_LIST)(pIntf->rdStSSIDList.pData);
  161. for (nIdx = 0; nIdx < pwzcPList->NumberOfItems; nIdx++)
  162. {
  163. PWZC_WLAN_CONFIG pwzcConfig = &(pwzcPList->Config[nIdx]);
  164. BYTE chFakeKeyMaterial[] = {0x56, 0x09, 0x08, 0x98, 0x4D, 0x08, 0x11, 0x66, 0x42, 0x03, 0x01, 0x67, 0x66};
  165. UINT i;
  166. for (i = 0; i < WZCCTL_MAX_WEPK_MATERIAL; i++)
  167. pwzcConfig->KeyMaterial[i] ^= chFakeKeyMaterial[(7*i)%13];
  168. }
  169. }
  170. if (pdwOutFlags != NULL)
  171. *pdwOutFlags = dwOutFlags;
  172. }
  173. RpcExcept(TRUE)
  174. {
  175. rpcStatus = RpcExceptionCode();
  176. }
  177. RpcEndExcept
  178. exit:
  179. return rpcStatus;
  180. }
  181. //---------------------------------------
  182. // WZCSetIterface: sets specific information on the interface
  183. //
  184. // Parameters:
  185. // pSrvAddr:
  186. // [in] WZC Server to contact
  187. // dwInFlags:
  188. // [in] Fields to be set (bitmask of INTF_*)
  189. // pIntf:
  190. // [in] Key of the interface to query and data to be set
  191. // pdwOutFlags:
  192. // [out] Fields successfully set (bitmask of INTF_*)
  193. //
  194. // Returned value:
  195. // Win32 error code
  196. DWORD
  197. WZCSetInterface(
  198. LPWSTR pSrvAddr,
  199. DWORD dwInFlags,
  200. PINTF_ENTRY pIntf,
  201. LPDWORD pdwOutFlags)
  202. {
  203. DWORD rpcStatus = RPC_S_OK;
  204. if (pIntf == NULL)
  205. {
  206. rpcStatus = ERROR_INVALID_PARAMETER;
  207. goto exit;
  208. }
  209. RpcTryExcept
  210. {
  211. if (dwInFlags & INTF_PREFLIST &&
  212. pIntf->rdStSSIDList.dwDataLen != 0)
  213. {
  214. PWZC_802_11_CONFIG_LIST pwzcPList;
  215. UINT nIdx;
  216. pwzcPList = (PWZC_802_11_CONFIG_LIST)(pIntf->rdStSSIDList.pData);
  217. for (nIdx = 0; nIdx < pwzcPList->NumberOfItems; nIdx++)
  218. {
  219. PWZC_WLAN_CONFIG pwzcConfig = &(pwzcPList->Config[nIdx]);
  220. BYTE chFakeKeyMaterial[] = {0x56, 0x09, 0x08, 0x98, 0x4D, 0x08, 0x11, 0x66, 0x42, 0x03, 0x01, 0x67, 0x66};
  221. UINT i;
  222. for (i = 0; i < WZCCTL_MAX_WEPK_MATERIAL; i++)
  223. pwzcConfig->KeyMaterial[i] ^= chFakeKeyMaterial[(7*i)%13];
  224. }
  225. }
  226. rpcStatus = RpcSetInterface(
  227. pSrvAddr,
  228. dwInFlags,
  229. pIntf,
  230. pdwOutFlags);
  231. }
  232. RpcExcept(TRUE)
  233. {
  234. rpcStatus = RpcExceptionCode();
  235. }
  236. RpcEndExcept
  237. exit:
  238. return rpcStatus;
  239. }
  240. //---------------------------------------
  241. // WZCRefreshInterface: refreshes specific information for the interface
  242. //
  243. // Parameters:
  244. // pSrvAddr:
  245. // [in] WZC Server to contact
  246. // dwInFlags:
  247. // [in] Fields to be refreshed and specific refresh actions to be
  248. // taken (bitmask of INTF_* and INTF_RFSH_*)
  249. // pIntf:
  250. // [in] Key of the interface to be refreshed
  251. // pdwOutFlags:
  252. // [out] Fields successfully refreshed (bitmask of INTF_* and INTF_RFSH_*)
  253. //
  254. // Returned value:
  255. // Win32 error code
  256. DWORD
  257. WZCRefreshInterface(
  258. LPWSTR pSrvAddr,
  259. DWORD dwInFlags,
  260. PINTF_ENTRY pIntf,
  261. LPDWORD pdwOutFlags)
  262. {
  263. DWORD rpcStatus = RPC_S_OK;
  264. if (pIntf == NULL || pIntf->wszGuid == NULL)
  265. {
  266. rpcStatus = ERROR_INVALID_PARAMETER;
  267. goto exit;
  268. }
  269. RpcTryExcept
  270. {
  271. rpcStatus = RpcRefreshInterface(
  272. pSrvAddr,
  273. dwInFlags,
  274. pIntf,
  275. pdwOutFlags);
  276. }
  277. RpcExcept(TRUE)
  278. {
  279. rpcStatus = RpcExceptionCode();
  280. }
  281. RpcEndExcept
  282. exit:
  283. return rpcStatus;
  284. }
  285. //---------------------------------------
  286. // WZCQueryContext: retrieves the WZC service parameters
  287. //
  288. // Parameters:
  289. // pSrvAddr:
  290. // [in] WZC Server to contact
  291. // dwInFlags:
  292. // [in] Fields to be retrieved (bitmask of WZC_CONTEXT_CTL*)
  293. // pContext:
  294. // [in] Placeholder for the service parameters
  295. // pdwOutFlags:
  296. // [out] Fields successfully retrieved (bitmask of WZC_CONTEXT_CTL*)
  297. //
  298. // Returned value:
  299. // Win32 error code
  300. DWORD
  301. WZCQueryContext(
  302. LPWSTR pSrvAddr,
  303. DWORD dwInFlags,
  304. PWZC_CONTEXT pContext,
  305. LPDWORD pdwOutFlags)
  306. {
  307. DWORD rpcStatus = RPC_S_OK;
  308. RpcTryExcept
  309. {
  310. rpcStatus = RpcQueryContext(
  311. pSrvAddr,
  312. dwInFlags,
  313. pContext,
  314. pdwOutFlags);
  315. }
  316. RpcExcept(TRUE)
  317. {
  318. rpcStatus = RpcExceptionCode();
  319. }
  320. RpcEndExcept
  321. return rpcStatus;
  322. }
  323. //---------------------------------------
  324. // WZCSetContext: sets specific WZC service parameters
  325. //
  326. // Parameters:
  327. // pSrvAddr:
  328. // [in] WZC Server to contact
  329. // dwInFlags:
  330. // [in] Fields to be set (bitmask of WZC_CONTEXT_CTL*)
  331. // pContext:
  332. // [in] Context buffer containing the specific parameters to be set
  333. // pdwOutFlags:
  334. // [out] Fields successfully set (bitmask of WZC_CONTEXT_CTL*)
  335. //
  336. // Returned value:
  337. // Win32 error code
  338. DWORD
  339. WZCSetContext(
  340. LPWSTR pSrvAddr,
  341. DWORD dwInFlags,
  342. PWZC_CONTEXT pContext,
  343. LPDWORD pdwOutFlags)
  344. {
  345. DWORD rpcStatus = RPC_S_OK;
  346. RpcTryExcept
  347. {
  348. rpcStatus = RpcSetContext(
  349. pSrvAddr,
  350. dwInFlags,
  351. pContext,
  352. pdwOutFlags);
  353. }
  354. RpcExcept(TRUE)
  355. {
  356. rpcStatus = RpcExceptionCode();
  357. }
  358. RpcEndExcept
  359. return rpcStatus;
  360. }
  361. //---------------------------------------
  362. // WZCEapolGetCustomAuthData: Get EAP-specific configuration data for interface
  363. //
  364. // Parameters:
  365. // pSrvAddr:
  366. // [in] WZC Server to contact
  367. // pwszGuid:
  368. // [in] Interface GUID
  369. // dwEapTypeId:
  370. // [in] EAP type Id
  371. // SSID:
  372. // [in] SSID for which data is to be stored
  373. // pbConnInfo:
  374. // [in out] Connection EAP info
  375. // pdwInfoSize:
  376. // [in out] Size of pbConnInfo
  377. //
  378. // Returned value:
  379. // Win32 error code
  380. DWORD
  381. WZCEapolGetCustomAuthData (
  382. IN LPWSTR pSrvAddr,
  383. IN PWCHAR pwszGuid,
  384. IN DWORD dwEapTypeId,
  385. IN DWORD dwSizeOfSSID,
  386. IN BYTE *pbSSID,
  387. IN OUT PBYTE pbConnInfo,
  388. IN OUT PDWORD pdwInfoSize
  389. )
  390. {
  391. RAW_DATA rdConnInfo;
  392. RAW_DATA rdSSID;
  393. DWORD rpcStatus = RPC_S_OK;
  394. if ((pwszGuid == NULL) || (pdwInfoSize == NULL))
  395. {
  396. rpcStatus = ERROR_INVALID_PARAMETER;
  397. goto exit;
  398. }
  399. if ((*pdwInfoSize != 0) && (pbConnInfo == NULL))
  400. {
  401. rpcStatus = ERROR_INVALID_PARAMETER;
  402. goto exit;
  403. }
  404. rdConnInfo.pData = pbConnInfo;
  405. rdConnInfo.dwDataLen = *pdwInfoSize;
  406. rdSSID.pData = pbSSID;
  407. rdSSID.dwDataLen = dwSizeOfSSID;
  408. RpcTryExcept
  409. {
  410. rpcStatus = RpcEapolGetCustomAuthData (
  411. pSrvAddr,
  412. pwszGuid,
  413. dwEapTypeId,
  414. rdSSID,
  415. &rdConnInfo
  416. );
  417. *pdwInfoSize = rdConnInfo.dwDataLen;
  418. }
  419. RpcExcept(TRUE)
  420. {
  421. rpcStatus = RpcExceptionCode();
  422. }
  423. RpcEndExcept
  424. exit:
  425. return rpcStatus;
  426. }
  427. //---------------------------------------
  428. // WZCEapolSetCustomAuthData: Set EAP-specific configuration data for interface
  429. //
  430. // Parameters:
  431. // pSrvAddr:
  432. // [in] WZC Server to contact
  433. // pwszGuid:
  434. // [in] Interface GUID
  435. // dwEapTypeId:
  436. // [in] EAP type Id
  437. // SSID:
  438. // [in] SSID for which data is to be stored
  439. // pbConnInfo:
  440. // [in] Connection EAP info
  441. // pdwInfoSize:
  442. // [in] Size of pbConnInfo
  443. //
  444. // Returned value:
  445. // Win32 error code
  446. DWORD
  447. WZCEapolSetCustomAuthData (
  448. IN LPWSTR pSrvAddr,
  449. IN PWCHAR pwszGuid,
  450. IN DWORD dwEapTypeId,
  451. IN DWORD dwSizeOfSSID,
  452. IN BYTE *pbSSID,
  453. IN PBYTE pbConnInfo,
  454. IN DWORD dwInfoSize
  455. )
  456. {
  457. RAW_DATA rdConnInfo;
  458. RAW_DATA rdSSID;
  459. DWORD rpcStatus = RPC_S_OK;
  460. if (pwszGuid == NULL)
  461. {
  462. rpcStatus = ERROR_INVALID_PARAMETER;
  463. goto exit;
  464. }
  465. rdConnInfo.pData = pbConnInfo;
  466. rdConnInfo.dwDataLen = dwInfoSize;
  467. rdSSID.pData = pbSSID;
  468. rdSSID.dwDataLen = dwSizeOfSSID;
  469. RpcTryExcept
  470. {
  471. rpcStatus = RpcEapolSetCustomAuthData (
  472. pSrvAddr,
  473. pwszGuid,
  474. dwEapTypeId,
  475. rdSSID,
  476. &rdConnInfo
  477. );
  478. }
  479. RpcExcept(TRUE)
  480. {
  481. rpcStatus = RpcExceptionCode();
  482. }
  483. RpcEndExcept
  484. exit:
  485. return rpcStatus;
  486. }
  487. //---------------------------------------
  488. // WZCEapolGetInterfaceParams: Get configuration parameters for interface
  489. //
  490. // Parameters:
  491. // pSrvAddr:
  492. // [in] WZC Server to contact
  493. // pwszGuid:
  494. // [in] Interface GUID
  495. // pIntfParams:
  496. // [in out] Interface Parameters
  497. //
  498. // Returned value:
  499. // Win32 error code
  500. DWORD
  501. WZCEapolGetInterfaceParams (
  502. IN LPWSTR pSrvAddr,
  503. IN PWCHAR pwszGuid,
  504. IN OUT EAPOL_INTF_PARAMS *pIntfParams
  505. )
  506. {
  507. DWORD rpcStatus = RPC_S_OK;
  508. if ((pwszGuid == NULL) || (pIntfParams == NULL))
  509. {
  510. rpcStatus = ERROR_INVALID_PARAMETER;
  511. goto exit;
  512. }
  513. RpcTryExcept
  514. {
  515. rpcStatus = RpcEapolGetInterfaceParams (
  516. pSrvAddr,
  517. pwszGuid,
  518. pIntfParams
  519. );
  520. }
  521. RpcExcept(TRUE)
  522. {
  523. rpcStatus = RpcExceptionCode();
  524. }
  525. RpcEndExcept
  526. exit:
  527. return rpcStatus;
  528. }
  529. //---------------------------------------
  530. // WZCEapolSetInterfaceParams: Set configuration parameters for interface
  531. //
  532. // Parameters:
  533. // pSrvAddr:
  534. // [in] WZC Server to contact
  535. // pwszGuid:
  536. // [in] Interface GUID
  537. // pIntfParams:
  538. // [in] Interface Parameters
  539. //
  540. // Returned value:
  541. // Win32 error code
  542. DWORD
  543. WZCEapolSetInterfaceParams (
  544. IN LPWSTR pSrvAddr,
  545. IN PWCHAR pwszGuid,
  546. IN EAPOL_INTF_PARAMS *pIntfParams
  547. )
  548. {
  549. DWORD rpcStatus = RPC_S_OK;
  550. if ((pwszGuid == NULL) || (pIntfParams == NULL))
  551. {
  552. rpcStatus = ERROR_INVALID_PARAMETER;
  553. goto exit;
  554. }
  555. RpcTryExcept
  556. {
  557. rpcStatus = RpcEapolSetInterfaceParams (
  558. pSrvAddr,
  559. pwszGuid,
  560. pIntfParams
  561. );
  562. }
  563. RpcExcept(TRUE)
  564. {
  565. rpcStatus = RpcExceptionCode();
  566. }
  567. RpcEndExcept
  568. exit:
  569. return rpcStatus;
  570. }
  571. //---------------------------------------
  572. // WZCEapolReAuthenticate: Restart 802.1X authenticaiton on an
  573. // interface
  574. //
  575. // Parameters:
  576. // pSrvAddr:
  577. // [in] WZC Server to contact
  578. // pwszGuid:
  579. // [in] Interface GUID
  580. //
  581. // Returned value:
  582. // Win32 error code
  583. DWORD
  584. WZCEapolReAuthenticate (
  585. IN LPWSTR pSrvAddr,
  586. IN PWCHAR pwszGuid
  587. )
  588. {
  589. DWORD rpcStatus = RPC_S_OK;
  590. if (pwszGuid == NULL)
  591. {
  592. rpcStatus = ERROR_INVALID_PARAMETER;
  593. goto exit;
  594. }
  595. RpcTryExcept
  596. {
  597. rpcStatus = RpcEapolReAuthenticateInterface (
  598. pSrvAddr,
  599. pwszGuid
  600. );
  601. }
  602. RpcExcept(TRUE)
  603. {
  604. rpcStatus = RpcExceptionCode();
  605. }
  606. RpcEndExcept
  607. exit:
  608. return rpcStatus;
  609. }
  610. //---------------------------------------
  611. // WZCEapolQueryState: Query EAPOL interface state
  612. //
  613. // Parameters:
  614. // pSrvAddr:
  615. // [in] WZC Server to contact
  616. // pwszGuid:
  617. // [in] Interface GUID
  618. // pIntfState:
  619. // [in, out] EAPOL State
  620. //
  621. // Returned value:
  622. // Win32 error code
  623. DWORD
  624. WZCEapolQueryState (
  625. IN LPWSTR pSrvAddr,
  626. IN PWCHAR pwszGuid,
  627. IN OUT PEAPOL_INTF_STATE pIntfState
  628. )
  629. {
  630. DWORD rpcStatus = RPC_S_OK;
  631. if (pwszGuid == NULL)
  632. {
  633. rpcStatus = ERROR_INVALID_PARAMETER;
  634. goto exit;
  635. }
  636. RpcTryExcept
  637. {
  638. rpcStatus = RpcEapolQueryInterfaceState (
  639. pSrvAddr,
  640. pwszGuid,
  641. pIntfState
  642. );
  643. }
  644. RpcExcept(TRUE)
  645. {
  646. rpcStatus = RpcExceptionCode();
  647. }
  648. RpcEndExcept
  649. exit:
  650. return rpcStatus;
  651. }
  652. //---------------------------------------
  653. // WZCEapolUIResponse: Send Dlg response to Service
  654. //
  655. // Parameters:
  656. // pSrvAddr:
  657. // [in] WZC Server to contact
  658. // EapolUIContext:
  659. // [in] EAPOLUI Context data
  660. // EapolUI:
  661. // [in] EAPOLUI response data
  662. //
  663. // Returned value:
  664. // Win32 error code
  665. DWORD
  666. WZCEapolUIResponse (
  667. LPWSTR pSrvAddr,
  668. EAPOL_EAP_UI_CONTEXT EapolUIContext,
  669. EAPOLUI_RESP EapolUIResp
  670. )
  671. {
  672. DWORD rpcStatus = RPC_S_OK;
  673. RpcTryExcept
  674. {
  675. rpcStatus = RpcEapolUIResponse (
  676. pSrvAddr,
  677. EapolUIContext,
  678. EapolUIResp
  679. );
  680. }
  681. RpcExcept(TRUE)
  682. {
  683. rpcStatus = RpcExceptionCode();
  684. }
  685. RpcEndExcept
  686. return rpcStatus;
  687. }