Leaked source code of windows server 2003
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.

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