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.

1694 lines
40 KiB

  1. #include "precomp.h"
  2. VOID
  3. InitializePolicyStateBlock(
  4. PWIRELESS_POLICY_STATE pWirelessPolicyState
  5. )
  6. {
  7. memset(pWirelessPolicyState, 0, sizeof(WIRELESS_POLICY_STATE));
  8. pWirelessPolicyState->DefaultPollingInterval = gDefaultPollingInterval;
  9. }
  10. DWORD
  11. StartStatePollingManager(
  12. PWIRELESS_POLICY_STATE pWirelessPolicyState
  13. )
  14. {
  15. DWORD dwError = 0;
  16. dwError = PlumbDirectoryPolicy(
  17. pWirelessPolicyState
  18. );
  19. if (dwError) {
  20. dwError = PlumbCachePolicy(
  21. pWirelessPolicyState
  22. );
  23. BAIL_ON_WIN32_ERROR(dwError);
  24. }
  25. //
  26. // The new polling interval has been set by either the
  27. // registry code or the DS code.
  28. //
  29. gCurrentPollingInterval = pWirelessPolicyState->CurrentPollingInterval;
  30. return (dwError);
  31. error:
  32. //
  33. // On error, set the state to INITIAL.
  34. //
  35. pWirelessPolicyState->dwCurrentState = POLL_STATE_INITIAL;
  36. _WirelessDbg(TRC_STATE, "Policy State :: Initial State ");
  37. gCurrentPollingInterval = pWirelessPolicyState->DefaultPollingInterval;
  38. return (dwError);
  39. }
  40. DWORD
  41. PlumbDirectoryPolicy(
  42. PWIRELESS_POLICY_STATE pWirelessPolicyState
  43. )
  44. {
  45. DWORD dwError = 0;
  46. LPWSTR pszDirectoryPolicyDN = NULL;
  47. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject = NULL;
  48. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  49. DWORD dwStoreType = WIRELESS_DIRECTORY_PROVIDER;
  50. DWORD dwSlientErrorCode = 0;
  51. BOOL bIsActivePolicy = FALSE;
  52. LPVOID lpMsgBuf;
  53. DWORD len = 0;
  54. DWORD i = 0;
  55. _WirelessDbg(TRC_NOTIF, "DBASE: Wireless Policy - Checking for Current Policy on DC ");
  56. dwError = GetDirectoryPolicyDN(
  57. &pszDirectoryPolicyDN
  58. );
  59. BAIL_ON_WIN32_ERROR(dwError);
  60. bIsActivePolicy = TRUE;
  61. dwError = LoadDirectoryPolicy(
  62. pszDirectoryPolicyDN,
  63. &pWirelessPolicyObject
  64. );
  65. BAIL_ON_WIN32_ERROR(dwError);
  66. // Taroon:: For some reason, the dwChanged Field is written by ProcessNFA Routine.
  67. // Ideally it should be written here first. May be, the when changed field is decided
  68. // based on if the NFA policy too has changed etc etc.
  69. // Unmarshalling of IPSEC happens in ProcessNFA. We get rid of that and call it right here.
  70. __try {
  71. dwError = UnmarshallWirelessPolicyObject(
  72. pWirelessPolicyObject,
  73. dwStoreType,
  74. &pWirelessPolicyData
  75. );
  76. } __except(EXCEPTION_EXECUTE_HANDLER) {
  77. dwError = ERROR_INVALID_DATA;
  78. _WirelessDbg(TRC_ERR, "Got Invalid Data ");
  79. }
  80. BAIL_ON_WIN32_ERROR(dwError);
  81. dwError = AddPolicyInformation(
  82. pWirelessPolicyData
  83. );
  84. if (pWirelessPolicyState->pWirelessPolicyObject) {
  85. FreeWirelessPolicyObject(pWirelessPolicyState->pWirelessPolicyObject);
  86. }
  87. if (pWirelessPolicyState->pWirelessPolicyData) {
  88. FreeWirelessPolicyData(pWirelessPolicyState->pWirelessPolicyData);
  89. }
  90. if (pWirelessPolicyState->pszDirectoryPolicyDN) {
  91. FreeSPDStr(pWirelessPolicyState->pszDirectoryPolicyDN);
  92. }
  93. //
  94. // Delete the old cache and write the new one in.
  95. //
  96. DeleteRegistryCache();
  97. CacheDirectorytoRegistry(pWirelessPolicyObject);
  98. pWirelessPolicyState->pWirelessPolicyObject = pWirelessPolicyObject;
  99. pWirelessPolicyState->pWirelessPolicyData = pWirelessPolicyData;
  100. pWirelessPolicyState->pszDirectoryPolicyDN = pszDirectoryPolicyDN;
  101. //
  102. // Set the state to DS_DOWNLOADED.
  103. //
  104. pWirelessPolicyState->dwCurrentState = POLL_STATE_DS_DOWNLOADED;
  105. _WirelessDbg(TRC_STATE, "Policy State is DS Downloaded ");
  106. //
  107. // Compute the new polling interval.
  108. //
  109. pWirelessPolicyState->CurrentPollingInterval = pWirelessPolicyData->dwPollingInterval;
  110. pWirelessPolicyState->DSIncarnationNumber = pWirelessPolicyData->dwWhenChanged;
  111. pWirelessPolicyState->RegIncarnationNumber = 0;
  112. gCurrentPollingInterval = pWirelessPolicyState->CurrentPollingInterval;
  113. dwError = ERROR_SUCCESS;
  114. return (dwError);
  115. error:
  116. //
  117. // Check pszDirectoryPolicyDN for non-NULL.
  118. //
  119. if (pszDirectoryPolicyDN) {
  120. FreeSPDStr(pszDirectoryPolicyDN);
  121. }
  122. if (pWirelessPolicyObject) {
  123. FreeWirelessPolicyObject(pWirelessPolicyObject);
  124. }
  125. if (pWirelessPolicyData) {
  126. FreeWirelessPolicyData(pWirelessPolicyData);
  127. }
  128. return (dwError);
  129. }
  130. // This Pre-requisite for this function is that Policy state is either CACHE or DS
  131. DWORD
  132. CheckDeleteOldPolicy(
  133. DWORD *dwDelete
  134. )
  135. {
  136. DWORD dwError = 0;
  137. HKEY hPolicyKey = NULL;
  138. DWORD dwSize = 0;
  139. DWORD dwSizeID = 0;
  140. DWORD dwSizeName = 0;
  141. DWORD dwToDelete = 1;
  142. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  143. LPWSTR pszWirelessPolicyID = NULL;
  144. LPWSTR pszPolicyID = NULL;
  145. LPWSTR pszStringUuid = NULL;
  146. LPWSTR pszWirelessPolicyName = NULL;
  147. dwError = RegOpenKeyExW(
  148. HKEY_LOCAL_MACHINE,
  149. gpszWirelessDSPolicyKey,
  150. 0,
  151. KEY_ALL_ACCESS,
  152. &hPolicyKey
  153. );
  154. BAIL_ON_WIN32_ERROR(dwError);
  155. dwError = RegstoreQueryValue(
  156. hPolicyKey,
  157. L"WirelessID",
  158. REG_SZ,
  159. (LPBYTE *)&pszWirelessPolicyID,
  160. &dwSize
  161. );
  162. BAIL_ON_WIN32_ERROR(dwError);
  163. dwError = RegstoreQueryValue(
  164. hPolicyKey,
  165. L"DSWirelessPolicyName",
  166. REG_SZ,
  167. (LPBYTE *)&pszWirelessPolicyName,
  168. &dwSize
  169. );
  170. BAIL_ON_WIN32_ERROR(dwError);
  171. // account for the first {
  172. pszPolicyID = pszWirelessPolicyID+ wcslen(L"{");
  173. pWirelessPolicyData = gpWirelessPolicyState->pWirelessPolicyData;
  174. dwError = UuidToString(
  175. &pWirelessPolicyData->PolicyIdentifier,
  176. &pszStringUuid
  177. );
  178. BAIL_ON_WIN32_ERROR(dwError);
  179. dwSizeID = wcslen(pszStringUuid) * sizeof(WCHAR);
  180. dwSizeName = wcslen(pszWirelessPolicyName) * sizeof(WCHAR);
  181. if (!memcmp(pszPolicyID, pszStringUuid, dwSizeID) &&
  182. (!memcmp(pszWirelessPolicyName, pWirelessPolicyData->pszWirelessName, dwSizeName)))
  183. {
  184. dwToDelete = 0;
  185. }
  186. error:
  187. *dwDelete = dwToDelete;
  188. if (pszStringUuid) {
  189. RpcStringFree(&pszStringUuid);
  190. }
  191. if (pszWirelessPolicyID) {
  192. FreePolMem(pszWirelessPolicyID);
  193. }
  194. if (pszWirelessPolicyName) {
  195. FreePolMem(pszWirelessPolicyName);
  196. }
  197. if (hPolicyKey) {
  198. CloseHandle(hPolicyKey);
  199. }
  200. return (dwError);
  201. }
  202. DWORD
  203. GetDirectoryPolicyDN(
  204. LPWSTR * ppszDirectoryPolicyDN
  205. )
  206. {
  207. DWORD dwError = 0;
  208. HKEY hPolicyKey = NULL;
  209. LPWSTR pszWirelessPolicyName = NULL;
  210. DWORD dwSize = 0;
  211. LPWSTR pszPolicyDN = NULL;
  212. LPWSTR pszDirectoryPolicyDN = NULL;
  213. *ppszDirectoryPolicyDN = NULL;
  214. dwError = RegOpenKeyExW(
  215. HKEY_LOCAL_MACHINE,
  216. gpszWirelessDSPolicyKey,
  217. 0,
  218. KEY_ALL_ACCESS,
  219. &hPolicyKey
  220. );
  221. BAIL_ON_WIN32_ERROR(dwError);
  222. dwError = RegstoreQueryValue(
  223. hPolicyKey,
  224. L"DSWirelessPolicyPath",
  225. REG_SZ,
  226. (LPBYTE *)&pszWirelessPolicyName,
  227. &dwSize
  228. );
  229. BAIL_ON_WIN32_ERROR(dwError);
  230. //
  231. // Move by LDAP:// to get the real DN and allocate
  232. // this string.
  233. // Fix this by fixing the gpo extension.
  234. //
  235. pszPolicyDN = pszWirelessPolicyName + wcslen(L"LDAP://");
  236. pszDirectoryPolicyDN = AllocSPDStr(pszPolicyDN);
  237. if (!pszDirectoryPolicyDN) {
  238. dwError = ERROR_OUTOFMEMORY;
  239. BAIL_ON_WIN32_ERROR(dwError);
  240. }
  241. *ppszDirectoryPolicyDN = pszDirectoryPolicyDN;
  242. error:
  243. if (pszWirelessPolicyName) {
  244. FreeSPDStr(pszWirelessPolicyName);
  245. }
  246. if (hPolicyKey) {
  247. CloseHandle(hPolicyKey);
  248. }
  249. return (dwError);
  250. }
  251. DWORD
  252. LoadDirectoryPolicy(
  253. LPWSTR pszDirectoryPolicyDN,
  254. PWIRELESS_POLICY_OBJECT * ppWirelessPolicyObject
  255. )
  256. {
  257. DWORD dwError = 0;
  258. LPWSTR pszDefaultDirectory = NULL;
  259. HLDAP hLdapBindHandle = NULL;
  260. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject = NULL;
  261. dwError = ComputeDefaultDirectory(
  262. &pszDefaultDirectory
  263. );
  264. BAIL_ON_WIN32_ERROR(dwError);
  265. dwError = OpenDirectoryServerHandle(
  266. pszDefaultDirectory,
  267. 389,
  268. &hLdapBindHandle
  269. );
  270. BAIL_ON_WIN32_ERROR(dwError);
  271. dwError = ReadPolicyObjectFromDirectory(
  272. hLdapBindHandle,
  273. pszDirectoryPolicyDN,
  274. &pWirelessPolicyObject
  275. );
  276. BAIL_ON_WIN32_ERROR(dwError);
  277. *ppWirelessPolicyObject = pWirelessPolicyObject;
  278. cleanup:
  279. if (pszDefaultDirectory) {
  280. FreeSPDStr(pszDefaultDirectory);
  281. }
  282. if (hLdapBindHandle) {
  283. CloseDirectoryServerHandle(hLdapBindHandle);
  284. }
  285. return (dwError);
  286. error:
  287. *ppWirelessPolicyObject = NULL;
  288. goto cleanup;
  289. }
  290. DWORD
  291. PlumbCachePolicy(
  292. PWIRELESS_POLICY_STATE pWirelessPolicyState
  293. )
  294. {
  295. DWORD dwError = 0;
  296. LPWSTR pszCachePolicyDN = NULL;
  297. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject = NULL;
  298. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  299. DWORD dwStoreType = WIRELESS_REGISTRY_PROVIDER;
  300. DWORD dwSlientErrorCode = 0;
  301. BOOL bIsActivePolicy = FALSE;
  302. _WirelessDbg(TRC_NOTIF, "DBASE: Wireless Policy - Checking for Current Cached Policy ");
  303. dwError = GetCachePolicyDN(
  304. &pszCachePolicyDN
  305. );
  306. BAIL_ON_WIN32_ERROR(dwError);
  307. bIsActivePolicy = TRUE;
  308. dwError = LoadCachePolicy(
  309. pszCachePolicyDN,
  310. &pWirelessPolicyObject
  311. );
  312. BAIL_ON_WIN32_ERROR(dwError);
  313. __try {
  314. dwError = UnmarshallWirelessPolicyObject(
  315. pWirelessPolicyObject,
  316. dwStoreType,
  317. &pWirelessPolicyData
  318. );
  319. } __except(EXCEPTION_EXECUTE_HANDLER) {
  320. dwError = ERROR_INVALID_DATA;
  321. }
  322. BAIL_ON_WIN32_ERROR(dwError);
  323. dwError = AddPolicyInformation(
  324. pWirelessPolicyData
  325. );
  326. if (pWirelessPolicyState->pWirelessPolicyObject) {
  327. FreeWirelessPolicyObject(pWirelessPolicyState->pWirelessPolicyObject);
  328. }
  329. if (pWirelessPolicyState->pWirelessPolicyData) {
  330. FreeWirelessPolicyData(pWirelessPolicyState->pWirelessPolicyData);
  331. }
  332. if (pWirelessPolicyState->pszCachePolicyDN) {
  333. FreeSPDStr(pWirelessPolicyState->pszCachePolicyDN);
  334. }
  335. pWirelessPolicyState->pWirelessPolicyObject = pWirelessPolicyObject;
  336. pWirelessPolicyState->pWirelessPolicyData = pWirelessPolicyData;
  337. pWirelessPolicyState->pszCachePolicyDN = pszCachePolicyDN;
  338. //
  339. // Set the state to CACHE_DOWNLOADED.
  340. //
  341. //
  342. pWirelessPolicyState->dwCurrentState = POLL_STATE_CACHE_DOWNLOADED;
  343. _WirelessDbg(TRC_STATE, "Policy State :: Cache Downloaded ");
  344. //
  345. // Compute the new polling interval.
  346. //
  347. pWirelessPolicyState->CurrentPollingInterval = pWirelessPolicyData->dwPollingInterval;
  348. pWirelessPolicyState->DSIncarnationNumber = 0;
  349. pWirelessPolicyState->RegIncarnationNumber = pWirelessPolicyData->dwWhenChanged;
  350. gCurrentPollingInterval = pWirelessPolicyState->CurrentPollingInterval;
  351. dwError = ERROR_SUCCESS;
  352. return (dwError);
  353. error:
  354. //
  355. // Check pszCachePolicyDN for non-NULL.
  356. //
  357. if (pszCachePolicyDN) {
  358. FreeSPDStr(pszCachePolicyDN);
  359. }
  360. if (pWirelessPolicyObject) {
  361. FreeWirelessPolicyObject(pWirelessPolicyObject);
  362. }
  363. if (pWirelessPolicyData) {
  364. FreeWirelessPolicyData(pWirelessPolicyData);
  365. }
  366. return (dwError);
  367. }
  368. DWORD
  369. GetCachePolicyDN(
  370. LPWSTR * ppszCachePolicyDN
  371. )
  372. {
  373. DWORD dwError = 0;
  374. LPWSTR pszDirectoryPolicyDN = NULL;
  375. LPWSTR pszCachePolicyDN = NULL;
  376. *ppszCachePolicyDN = NULL;
  377. dwError = GetDirectoryPolicyDN(
  378. &pszDirectoryPolicyDN
  379. );
  380. BAIL_ON_WIN32_ERROR(dwError);
  381. dwError = CopyPolicyDSToFQRegString(
  382. pszDirectoryPolicyDN,
  383. &pszCachePolicyDN
  384. );
  385. BAIL_ON_WIN32_ERROR(dwError);
  386. *ppszCachePolicyDN = pszCachePolicyDN;
  387. error:
  388. if (pszDirectoryPolicyDN) {
  389. FreeSPDStr(pszDirectoryPolicyDN);
  390. }
  391. return (dwError);
  392. }
  393. DWORD
  394. LoadCachePolicy(
  395. LPWSTR pszCachePolicyDN,
  396. PWIRELESS_POLICY_OBJECT * ppWirelessPolicyObject
  397. )
  398. {
  399. DWORD dwError = 0;
  400. HKEY hRegistryKey = NULL;
  401. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject = NULL;
  402. dwError = OpenRegistryWIRELESSRootKey(
  403. NULL,
  404. gpszWirelessCachePolicyKey,
  405. &hRegistryKey
  406. );
  407. BAIL_ON_WIN32_ERROR(dwError);
  408. dwError = ReadPolicyObjectFromRegistry(
  409. hRegistryKey,
  410. pszCachePolicyDN,
  411. gpszWirelessCachePolicyKey,
  412. &pWirelessPolicyObject
  413. );
  414. BAIL_ON_WIN32_ERROR(dwError);
  415. *ppWirelessPolicyObject = pWirelessPolicyObject;
  416. cleanup:
  417. if (hRegistryKey) {
  418. CloseHandle(hRegistryKey);
  419. }
  420. return (dwError);
  421. error:
  422. *ppWirelessPolicyObject = NULL;
  423. goto cleanup;
  424. }
  425. DWORD
  426. OnPolicyChanged(
  427. PWIRELESS_POLICY_STATE pWirelessPolicyState
  428. )
  429. {
  430. DWORD dwError = 0;
  431. DWORD dwDelete = 1;
  432. // If Initial Start - Start afresh
  433. if (pWirelessPolicyState->dwCurrentState == POLL_STATE_INITIAL) {
  434. StartStatePollingManager(pWirelessPolicyState);
  435. return(dwError);
  436. }
  437. //
  438. // Check if the existing Policy Object has been changed.. Only in that case, delete the policy.
  439. //
  440. CheckDeleteOldPolicy(&dwDelete);
  441. if (dwDelete)
  442. {
  443. //
  444. // Remove all the old policy that was plumbed.
  445. //
  446. dwError = DeletePolicyInformation(
  447. pWirelessPolicyState->pWirelessPolicyData
  448. );
  449. ClearPolicyStateBlock(
  450. pWirelessPolicyState
  451. );
  452. //
  453. // Calling the Initializer again.
  454. //
  455. dwError = StartStatePollingManager(
  456. pWirelessPolicyState
  457. );
  458. return (dwError);
  459. }
  460. // Policy Object is the same. Might be Modified Though. Call the On Policy Poll
  461. _WirelessDbg(TRC_TRACK, "Policy Not New: Changing to Poll Function ");
  462. dwError = OnPolicyPoll(pWirelessPolicyState);
  463. return(dwError);
  464. }
  465. DWORD
  466. OnPolicyChangedEx(
  467. PWIRELESS_POLICY_STATE pWirelessPolicyState
  468. )
  469. {
  470. DWORD dwError = 0;
  471. // If Initial Start - Start afresh
  472. if (pWirelessPolicyState->dwCurrentState == POLL_STATE_INITIAL) {
  473. StartStatePollingManager(pWirelessPolicyState);
  474. return(dwError);
  475. }
  476. //
  477. // Remove all the old policy that was plumbed.
  478. //
  479. _WirelessDbg(TRC_TRACK, "OnPolicyChangeEx called ");
  480. dwError = DeletePolicyInformation(
  481. pWirelessPolicyState->pWirelessPolicyData
  482. );
  483. ClearPolicyStateBlock(
  484. pWirelessPolicyState
  485. );
  486. //
  487. // Calling the Initializer again.
  488. //
  489. dwError = StartStatePollingManager(
  490. pWirelessPolicyState
  491. );
  492. return (dwError);
  493. }
  494. DWORD
  495. DeletePolicyInformation(
  496. PWIRELESS_POLICY_DATA pWirelessPolicyData
  497. )
  498. {
  499. DWORD dwError = 0;
  500. if (!pWirelessPolicyData) {
  501. dwError = ERROR_SUCCESS;
  502. return (dwError);
  503. }
  504. _WirelessDbg(TRC_NOTIF, "DBASE: Wireless Policy - Deleting Existing Policy for Zero Conf / 802.1x ");
  505. _WirelessDbg(TRC_TRACK, "Deleting Policy Information");
  506. _WirelessDbg(TRC_TRACK, "Deleted Policy is ");
  507. printPolicy(pWirelessPolicyData);
  508. dwError = AddWZCPolicy(NULL);
  509. if (dwError) {
  510. _WirelessDbg(TRC_ERR, "Error in Deleting ZeroConfig Policy Error %d ", dwError);
  511. dwError = ERROR_SUCCESS;
  512. } else
  513. {
  514. _WirelessDbg(TRC_TRACK, "ZeroConf Policy Deletion Succesful ");
  515. }
  516. dwError = AddEapolPolicy(NULL);
  517. if (dwError) {
  518. _WirelessDbg(TRC_ERR, "Error in Deleting EAPOL Policy with Error No. %d ", dwError);
  519. dwError = ERROR_SUCCESS;
  520. } else
  521. {
  522. _WirelessDbg(TRC_TRACK, "EAPOL Policy Deletion Succesful ");
  523. }
  524. return (dwError);
  525. }
  526. VOID
  527. ClearPolicyStateBlock(
  528. PWIRELESS_POLICY_STATE pWirelessPolicyState
  529. )
  530. {
  531. if (pWirelessPolicyState->pWirelessPolicyObject) {
  532. FreeWirelessPolicyObject(
  533. pWirelessPolicyState->pWirelessPolicyObject
  534. );
  535. pWirelessPolicyState->pWirelessPolicyObject = NULL;
  536. }
  537. if (pWirelessPolicyState->pWirelessPolicyData) {
  538. FreeWirelessPolicyData(
  539. pWirelessPolicyState->pWirelessPolicyData
  540. );
  541. pWirelessPolicyState->pWirelessPolicyData = NULL;
  542. }
  543. if (pWirelessPolicyState->pszDirectoryPolicyDN) {
  544. FreeSPDStr(pWirelessPolicyState->pszDirectoryPolicyDN);
  545. pWirelessPolicyState->pszDirectoryPolicyDN = NULL;
  546. }
  547. pWirelessPolicyState->CurrentPollingInterval = gDefaultPollingInterval;
  548. pWirelessPolicyState->DefaultPollingInterval = gDefaultPollingInterval;
  549. pWirelessPolicyState->DSIncarnationNumber = 0;
  550. pWirelessPolicyState->RegIncarnationNumber = 0;
  551. pWirelessPolicyState->dwCurrentState = POLL_STATE_INITIAL;
  552. _WirelessDbg(TRC_STATE, "Policy State :: Initial State ");
  553. }
  554. DWORD
  555. OnPolicyPoll(
  556. PWIRELESS_POLICY_STATE pWirelessPolicyState
  557. )
  558. {
  559. DWORD dwError = 0;
  560. _WirelessDbg(TRC_NOTIF, "DBASE: Wireless Policy - Polling for Policy Changes ");
  561. switch (pWirelessPolicyState->dwCurrentState) {
  562. case POLL_STATE_DS_DOWNLOADED:
  563. dwError = ProcessDirectoryPolicyPollState(pWirelessPolicyState);
  564. BAIL_ON_WIN32_ERROR(dwError);
  565. break;
  566. case POLL_STATE_CACHE_DOWNLOADED:
  567. dwError = ProcessCachePolicyPollState(pWirelessPolicyState);
  568. BAIL_ON_WIN32_ERROR(dwError);
  569. break;
  570. case POLL_STATE_INITIAL:
  571. dwError = OnPolicyChangedEx(pWirelessPolicyState);
  572. BAIL_ON_WIN32_ERROR(dwError);
  573. break;
  574. }
  575. //
  576. // Set the new polling interval.
  577. //
  578. gCurrentPollingInterval = pWirelessPolicyState->CurrentPollingInterval;
  579. return (dwError);
  580. error:
  581. //
  582. // If in any of the three states other than the initial state,
  583. // then there was an error in pulling down the incarnation number
  584. // or the Wireless Policy from either the directory or the registry
  585. // or there might not no longer be any Wireless policy assigned to
  586. // this machine. So the polling state must reset back to the
  587. // start state through a forced policy change. This is also
  588. // necessary if the polling state is already in the initial state.
  589. //
  590. dwError = OnPolicyChangedEx(
  591. pWirelessPolicyState
  592. );
  593. return (dwError);
  594. }
  595. DWORD
  596. ProcessDirectoryPolicyPollState(
  597. PWIRELESS_POLICY_STATE pWirelessPolicyState
  598. )
  599. {
  600. DWORD dwError = 0;
  601. DWORD dwIncarnationNumber = 0;
  602. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject = NULL;
  603. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  604. DWORD dwStoreType = WIRELESS_DIRECTORY_PROVIDER;
  605. DWORD dwSlientErrorCode = 0;
  606. //
  607. // The directory policy DN has to be the same, otherwise the
  608. // Wireless extension in Winlogon would have already notified
  609. // PA Store of the DS policy change.
  610. //
  611. dwError = GetDirectoryIncarnationNumber(
  612. pWirelessPolicyState->pszDirectoryPolicyDN,
  613. &dwIncarnationNumber
  614. );
  615. if (dwError) {
  616. dwError = MigrateFromDSToCache(pWirelessPolicyState);
  617. BAIL_ON_WIN32_ERROR(dwError);
  618. return (ERROR_SUCCESS);
  619. }
  620. if (dwIncarnationNumber == pWirelessPolicyState->DSIncarnationNumber) {
  621. //
  622. // The policy has not changed at all.
  623. //
  624. _WirelessDbg(TRC_NOTIF, "DBASE: Wireless Policy - Policy on DS has Not Changed ");
  625. return (ERROR_SUCCESS);
  626. }
  627. //
  628. // The incarnation number is different, so there's a need to
  629. // update the policy.
  630. //
  631. dwError = LoadDirectoryPolicy(
  632. pWirelessPolicyState->pszDirectoryPolicyDN,
  633. &pWirelessPolicyObject
  634. );
  635. if (dwError) {
  636. dwError = MigrateFromDSToCache(pWirelessPolicyState);
  637. BAIL_ON_WIN32_ERROR(dwError);
  638. return (ERROR_SUCCESS);
  639. }
  640. __try {
  641. dwError = UnmarshallWirelessPolicyObject(
  642. pWirelessPolicyObject,
  643. dwStoreType,
  644. &pWirelessPolicyData
  645. );
  646. } __except(EXCEPTION_EXECUTE_HANDLER) {
  647. dwError = ERROR_INVALID_DATA;
  648. }
  649. if (dwError) {
  650. dwError = MigrateFromDSToCache(pWirelessPolicyState);
  651. BAIL_ON_WIN32_ERROR(dwError);
  652. if (pWirelessPolicyObject) {
  653. FreeWirelessPolicyObject(pWirelessPolicyObject);
  654. }
  655. return (ERROR_SUCCESS);
  656. }
  657. dwError = UpdatePolicyInformation(
  658. pWirelessPolicyState->pWirelessPolicyData,
  659. pWirelessPolicyData
  660. );
  661. if (pWirelessPolicyState->pWirelessPolicyObject) {
  662. FreeWirelessPolicyObject(pWirelessPolicyState->pWirelessPolicyObject);
  663. }
  664. if (pWirelessPolicyState->pWirelessPolicyData) {
  665. FreeWirelessPolicyData(pWirelessPolicyState->pWirelessPolicyData);
  666. }
  667. //
  668. // Now delete the old cache and write the new one in.
  669. //
  670. DeleteRegistryCache();
  671. CacheDirectorytoRegistry(pWirelessPolicyObject);
  672. pWirelessPolicyState->pWirelessPolicyObject = pWirelessPolicyObject;
  673. pWirelessPolicyState->pWirelessPolicyData = pWirelessPolicyData;
  674. pWirelessPolicyState->CurrentPollingInterval = pWirelessPolicyData->dwPollingInterval;
  675. pWirelessPolicyState->DSIncarnationNumber = dwIncarnationNumber;
  676. //NotifyWirelessPolicyChange();
  677. dwError = ERROR_SUCCESS;
  678. return (dwError);
  679. error:
  680. if (pWirelessPolicyObject) {
  681. FreeWirelessPolicyObject(pWirelessPolicyObject);
  682. }
  683. if (pWirelessPolicyData) {
  684. FreeWirelessPolicyData(pWirelessPolicyData);
  685. }
  686. return (dwError);
  687. }
  688. DWORD
  689. GetDirectoryIncarnationNumber(
  690. LPWSTR pszWirelessPolicyDN,
  691. DWORD * pdwIncarnationNumber
  692. )
  693. {
  694. DWORD dwError = 0;
  695. LPWSTR pszDefaultDirectory = NULL;
  696. HLDAP hLdapBindHandle = NULL;
  697. LPWSTR Attributes[] = {L"whenChanged", NULL};
  698. LDAPMessage *res = NULL;
  699. LDAPMessage *e = NULL;
  700. WCHAR **strvalues = NULL;
  701. DWORD dwCount = 0;
  702. DWORD dwWhenChanged = 0;
  703. *pdwIncarnationNumber = 0;
  704. //
  705. // Open the directory store.
  706. //
  707. dwError = ComputeDefaultDirectory(
  708. &pszDefaultDirectory
  709. );
  710. BAIL_ON_WIN32_ERROR(dwError);
  711. dwError = OpenDirectoryServerHandle(
  712. pszDefaultDirectory,
  713. 389,
  714. &hLdapBindHandle
  715. );
  716. BAIL_ON_WIN32_ERROR(dwError);
  717. dwError = LdapSearchST(
  718. hLdapBindHandle,
  719. pszWirelessPolicyDN,
  720. LDAP_SCOPE_BASE,
  721. L"(objectClass=*)",
  722. Attributes,
  723. 0,
  724. NULL,
  725. &res
  726. );
  727. BAIL_ON_WIN32_ERROR(dwError);
  728. dwError = LdapFirstEntry(
  729. hLdapBindHandle,
  730. res,
  731. &e
  732. );
  733. BAIL_ON_WIN32_ERROR(dwError);
  734. dwError = LdapGetValues(
  735. hLdapBindHandle,
  736. e,
  737. L"whenChanged",
  738. (WCHAR ***)&strvalues,
  739. (int *)&dwCount
  740. );
  741. BAIL_ON_WIN32_ERROR(dwError);
  742. dwWhenChanged = _wtol(LDAPOBJECT_STRING((PLDAPOBJECT)strvalues));
  743. *pdwIncarnationNumber = dwWhenChanged;
  744. error:
  745. if (pszDefaultDirectory) {
  746. FreeSPDStr(pszDefaultDirectory);
  747. }
  748. if (hLdapBindHandle) {
  749. CloseDirectoryServerHandle(hLdapBindHandle);
  750. }
  751. if (res) {
  752. LdapMsgFree(res);
  753. }
  754. if (strvalues) {
  755. LdapValueFree(strvalues);
  756. }
  757. return (dwError);
  758. }
  759. DWORD
  760. MigrateFromDSToCache(
  761. PWIRELESS_POLICY_STATE pWirelessPolicyState
  762. )
  763. {
  764. DWORD dwError = 0;
  765. LPWSTR pszCachePolicyDN = NULL;
  766. dwError = GetCachePolicyDN(
  767. &pszCachePolicyDN
  768. );
  769. BAIL_ON_WIN32_ERROR(dwError);
  770. if (pWirelessPolicyState->pszDirectoryPolicyDN) {
  771. FreeSPDStr(pWirelessPolicyState->pszDirectoryPolicyDN);
  772. pWirelessPolicyState->pszDirectoryPolicyDN = NULL;
  773. }
  774. pWirelessPolicyState->pszCachePolicyDN = pszCachePolicyDN;
  775. //
  776. // Keep pWirelessPolicyState->pWirelessPolicyData.
  777. // Keep pWirelessPolicyState->pWirelessPolicyObject.
  778. // Change the incarnation numbers.
  779. //
  780. pWirelessPolicyState->RegIncarnationNumber = pWirelessPolicyState->DSIncarnationNumber;
  781. pWirelessPolicyState->DSIncarnationNumber = 0;
  782. pWirelessPolicyState->dwCurrentState = POLL_STATE_CACHE_DOWNLOADED;
  783. _WirelessDbg(TRC_STATE, "Policy State :: Cache Downloaded ");
  784. _WirelessDbg(TRC_NOTIF, "DBASE: Wireless Policy - Error Syncing Policy with DC, Using Cached Policy ");
  785. //
  786. // Keep pWirelessPolicyState->CurrentPollingInterval.
  787. // Keep pWirelessPolicyState->DefaultPollingInterval.
  788. //
  789. gCurrentPollingInterval = pWirelessPolicyState->CurrentPollingInterval;
  790. error:
  791. return (dwError);
  792. }
  793. DWORD
  794. ProcessCachePolicyPollState(
  795. PWIRELESS_POLICY_STATE pWirelessPolicyState
  796. )
  797. {
  798. DWORD dwError = 0;
  799. LPWSTR pszDirectoryPolicyDN = NULL;
  800. DWORD dwIncarnationNumber = 0;
  801. LPWSTR pszCachePolicyDN = NULL;
  802. dwError = GetDirectoryPolicyDN(
  803. &pszDirectoryPolicyDN
  804. );
  805. if (!dwError) {
  806. dwError = GetDirectoryIncarnationNumber(
  807. pszDirectoryPolicyDN,
  808. &dwIncarnationNumber
  809. );
  810. if (!dwError) {
  811. dwError = CopyPolicyDSToFQRegString(
  812. pszDirectoryPolicyDN,
  813. &pszCachePolicyDN
  814. );
  815. if (!dwError) {
  816. if (!_wcsicmp(pWirelessPolicyState->pszCachePolicyDN, pszCachePolicyDN)) {
  817. if (pWirelessPolicyState->RegIncarnationNumber == dwIncarnationNumber) {
  818. dwError = MigrateFromCacheToDS(pWirelessPolicyState);
  819. }
  820. else {
  821. dwError = UpdateFromCacheToDS(pWirelessPolicyState);
  822. }
  823. if (dwError) {
  824. dwError = OnPolicyChangedEx(pWirelessPolicyState);
  825. }
  826. }
  827. else {
  828. dwError = OnPolicyChangedEx(pWirelessPolicyState);
  829. }
  830. }
  831. }
  832. }
  833. if (pszDirectoryPolicyDN) {
  834. FreeSPDStr(pszDirectoryPolicyDN);
  835. }
  836. if (pszCachePolicyDN) {
  837. FreeSPDStr(pszCachePolicyDN);
  838. }
  839. return (ERROR_SUCCESS);
  840. }
  841. DWORD
  842. MigrateFromCacheToDS(
  843. PWIRELESS_POLICY_STATE pWirelessPolicyState
  844. )
  845. {
  846. DWORD dwError = 0;
  847. LPWSTR pszDirectoryPolicyDN = NULL;
  848. dwError = GetDirectoryPolicyDN(
  849. &pszDirectoryPolicyDN
  850. );
  851. BAIL_ON_WIN32_ERROR(dwError);
  852. if (pWirelessPolicyState->pszCachePolicyDN) {
  853. FreeSPDStr(pWirelessPolicyState->pszCachePolicyDN);
  854. pWirelessPolicyState->pszCachePolicyDN = NULL;
  855. }
  856. pWirelessPolicyState->pszDirectoryPolicyDN = pszDirectoryPolicyDN;
  857. //
  858. // Keep pWirelessPolicyState->pWirelessPolicyData.
  859. // Keep pWirelessPolicyState->pWirelessPolicyObject.
  860. // Change the incarnation numbers.
  861. //
  862. pWirelessPolicyState->DSIncarnationNumber = pWirelessPolicyState->RegIncarnationNumber;
  863. pWirelessPolicyState->RegIncarnationNumber = 0;
  864. pWirelessPolicyState->dwCurrentState = POLL_STATE_DS_DOWNLOADED;
  865. _WirelessDbg(TRC_NOTIF, "DBASE: Wireless Policy - Policy in sync with DC ");
  866. _WirelessDbg(TRC_STATE, "Policy State :: DS Downloaded ");
  867. //
  868. // Keep pWirelessPolicyState->CurrentPollingInterval.
  869. // Keep pWirelessPolicyState->DefaultPollingInterval.
  870. //
  871. gCurrentPollingInterval = pWirelessPolicyState->CurrentPollingInterval;
  872. error:
  873. return (dwError);
  874. }
  875. DWORD
  876. UpdateFromCacheToDS(
  877. PWIRELESS_POLICY_STATE pWirelessPolicyState
  878. )
  879. {
  880. DWORD dwError = 0;
  881. LPWSTR pszDirectoryPolicyDN = NULL;
  882. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject = NULL;
  883. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  884. DWORD dwStoreType = WIRELESS_DIRECTORY_PROVIDER;
  885. DWORD dwSlientErrorCode = 0;
  886. dwError = GetDirectoryPolicyDN(
  887. &pszDirectoryPolicyDN
  888. );
  889. BAIL_ON_WIN32_ERROR(dwError);
  890. dwError = LoadDirectoryPolicy(
  891. pszDirectoryPolicyDN,
  892. &pWirelessPolicyObject
  893. );
  894. BAIL_ON_WIN32_ERROR(dwError);
  895. __try {
  896. dwError = UnmarshallWirelessPolicyObject(
  897. pWirelessPolicyObject,
  898. dwStoreType,
  899. &pWirelessPolicyData
  900. );
  901. } __except(EXCEPTION_EXECUTE_HANDLER) {
  902. dwError = ERROR_INVALID_DATA;
  903. }
  904. BAIL_ON_WIN32_ERROR(dwError);
  905. _WirelessDbg(TRC_NOTIF, "DBASE: Wireless Policy - Policy in Sync with DC ");
  906. dwError = UpdatePolicyInformation(
  907. pWirelessPolicyState->pWirelessPolicyData,
  908. pWirelessPolicyData
  909. );
  910. if (pWirelessPolicyState->pWirelessPolicyObject) {
  911. FreeWirelessPolicyObject(pWirelessPolicyState->pWirelessPolicyObject);
  912. }
  913. if (pWirelessPolicyState->pWirelessPolicyData) {
  914. FreeWirelessPolicyData(pWirelessPolicyState->pWirelessPolicyData);
  915. }
  916. if (pWirelessPolicyState->pszCachePolicyDN) {
  917. FreeSPDStr(pWirelessPolicyState->pszCachePolicyDN);
  918. }
  919. //
  920. // Now delete the old cache and write the new one in.
  921. //
  922. DeleteRegistryCache();
  923. CacheDirectorytoRegistry(pWirelessPolicyObject);
  924. pWirelessPolicyState->pWirelessPolicyObject = pWirelessPolicyObject;
  925. pWirelessPolicyState->pWirelessPolicyData = pWirelessPolicyData;
  926. pWirelessPolicyState->pszDirectoryPolicyDN = pszDirectoryPolicyDN;
  927. //
  928. // Set the state to DS-DOWNLOADED.
  929. //
  930. pWirelessPolicyState->dwCurrentState = POLL_STATE_DS_DOWNLOADED;
  931. _WirelessDbg(TRC_STATE, "Policy State :: DS Downloaded ");
  932. _WirelessDbg(TRC_NOTIF, "DBASE: Wireless Policy Synced with DS ");
  933. //
  934. // Compute the new polling interval.
  935. //
  936. pWirelessPolicyState->CurrentPollingInterval = pWirelessPolicyData->dwPollingInterval;
  937. pWirelessPolicyState->DSIncarnationNumber = pWirelessPolicyData->dwWhenChanged;
  938. pWirelessPolicyState->RegIncarnationNumber = 0;
  939. gCurrentPollingInterval = pWirelessPolicyState->CurrentPollingInterval;
  940. //NotifyWirelessPolicyChange();
  941. dwError = ERROR_SUCCESS;
  942. return (dwError);
  943. error:
  944. if (pszDirectoryPolicyDN) {
  945. FreeSPDStr(pszDirectoryPolicyDN);
  946. }
  947. if (pWirelessPolicyObject) {
  948. FreeWirelessPolicyObject(pWirelessPolicyObject);
  949. }
  950. if (pWirelessPolicyData) {
  951. FreeWirelessPolicyData(pWirelessPolicyData);
  952. }
  953. return (dwError);
  954. }
  955. DWORD
  956. GetRegistryIncarnationNumber(
  957. LPWSTR pszWirelessPolicyDN,
  958. DWORD * pdwIncarnationNumber
  959. )
  960. {
  961. DWORD dwError = 0;
  962. HKEY hRegKey = NULL;
  963. DWORD dwType = REG_DWORD;
  964. DWORD dwWhenChanged = 0;
  965. DWORD dwSize = sizeof(DWORD);
  966. *pdwIncarnationNumber = 0;
  967. dwError = RegOpenKeyExW(
  968. HKEY_LOCAL_MACHINE,
  969. pszWirelessPolicyDN,
  970. 0,
  971. KEY_ALL_ACCESS,
  972. &hRegKey
  973. );
  974. BAIL_ON_WIN32_ERROR(dwError);
  975. dwError = RegQueryValueExW(
  976. hRegKey,
  977. L"whenChanged",
  978. NULL,
  979. &dwType,
  980. (LPBYTE)&dwWhenChanged,
  981. &dwSize
  982. );
  983. BAIL_ON_WIN32_ERROR(dwError);
  984. *pdwIncarnationNumber = dwWhenChanged;
  985. error:
  986. if (hRegKey) {
  987. CloseHandle(hRegKey);
  988. }
  989. return(dwError);
  990. }
  991. DWORD
  992. UpdatePolicyInformation(
  993. PWIRELESS_POLICY_DATA pOldWirelessPolicyData,
  994. PWIRELESS_POLICY_DATA pNewWirelessPolicyData
  995. )
  996. {
  997. DWORD dwError = 0;
  998. _WirelessDbg(TRC_TRACK, "Updating Policy Information");
  999. _WirelessDbg(TRC_TRACK, "Old Policy is ");
  1000. printPolicy(pOldWirelessPolicyData);
  1001. _WirelessDbg(TRC_TRACK, "New Policy is ");
  1002. printPolicy(pNewWirelessPolicyData);
  1003. _WirelessDbg(TRC_NOTIF, "DBASE: Wireless Policy - Updating Policy for Zero Conf / 802.1x ");
  1004. dwError = AddWZCPolicy(pNewWirelessPolicyData);
  1005. if (dwError) {
  1006. _WirelessDbg(TRC_ERR, "Error in Updating the Zero Conf Policy Error Code %d ", dwError);
  1007. dwError = ERROR_SUCCESS;
  1008. } else
  1009. {
  1010. _WirelessDbg(TRC_TRACK, "Policy Update for Zero Conf Successful ");
  1011. }
  1012. dwError = AddEapolPolicy(pNewWirelessPolicyData);
  1013. if (dwError) {
  1014. _WirelessDbg(TRC_ERR, "Error in Applying EAPOL Policy Error Code %d ", dwError);
  1015. dwError = ERROR_SUCCESS;
  1016. } else
  1017. {
  1018. _WirelessDbg(TRC_TRACK, "Policy Update for EAPOL Successful ");
  1019. }
  1020. return (dwError);
  1021. }
  1022. DWORD
  1023. AddPolicyInformation(
  1024. PWIRELESS_POLICY_DATA pWirelessPolicyData
  1025. )
  1026. {
  1027. DWORD dwError = 0;
  1028. _WirelessDbg(TRC_TRACK, "Adding Policy ");
  1029. _WirelessDbg(TRC_NOTIF, "DBASE: Wireless Policy - Adding Policy for Zero Conf / 802.1x ");
  1030. // Find the diff here.
  1031. // Compare that Guids are same and the dwChanged are same..
  1032. // Then look for other differences
  1033. dwError = AddWZCPolicy(pWirelessPolicyData);
  1034. if (dwError) {
  1035. _WirelessDbg(TRC_ERR, "Error in ADDing Zero Conf the Policy Error Code %d ", dwError);
  1036. dwError = ERROR_SUCCESS;
  1037. } else
  1038. {
  1039. _WirelessDbg(TRC_TRACK, "ZeroConf Policy Addition Succesful ");
  1040. }
  1041. dwError = AddEapolPolicy(pWirelessPolicyData);
  1042. if (dwError) {
  1043. _WirelessDbg(TRC_ERR, "Error in Adding EAPOL Policy Error Code %d ", dwError);
  1044. dwError = ERROR_SUCCESS;
  1045. } else
  1046. {
  1047. _WirelessDbg(TRC_TRACK, "EAPOL Policy Addition Succesful ");
  1048. }
  1049. return (dwError);
  1050. }
  1051. DWORD
  1052. AddWZCPolicy(PWIRELESS_POLICY_DATA pWirelessPolicyData)
  1053. {
  1054. DWORD dwError = 0;
  1055. DWORD i=0;
  1056. DWORD dwNumPSSettings = 0;
  1057. DWORD dwCtlFlags = 0;
  1058. PINTF_ENTRY pIntfEntry = NULL;
  1059. PWZC_802_11_CONFIG_LIST pWZCConfigList = NULL;
  1060. DWORD dwWZCConfigListSize = 0;
  1061. PWZC_WLAN_CONFIG pWZCConfig = NULL;
  1062. PWIRELESS_PS_DATA *ppWirelessPSData = NULL;
  1063. DWORD dwInFlags = 0;
  1064. DWORD dwOutFlags = 0;
  1065. DWORD dwSSIDSize = 0;
  1066. WCHAR pszTempSSID[33];
  1067. BYTE pszOutSSID[33];
  1068. _WirelessDbg(TRC_TRACK, "Adding Wireless Zero Config Informaiton ");
  1069. printPolicy(pWirelessPolicyData);
  1070. pIntfEntry = (PINTF_ENTRY) AllocSPDMem(sizeof(INTF_ENTRY));
  1071. if (!pIntfEntry) {
  1072. dwError = GetLastError();
  1073. }
  1074. if (!pWirelessPolicyData) {
  1075. dwInFlags |= INTF_ALL_FLAGS;
  1076. dwInFlags |= INTF_PREFLIST;
  1077. pIntfEntry->rdStSSIDList.dwDataLen = 0;
  1078. pIntfEntry->rdStSSIDList.pData = NULL;
  1079. dwError = LstSetInterface(dwInFlags, pIntfEntry, &dwOutFlags);
  1080. return (dwError);
  1081. }
  1082. if (pWirelessPolicyData->dwDisableZeroConf == 0) {
  1083. dwCtlFlags |= INTFCTL_ENABLED;
  1084. }
  1085. if (pWirelessPolicyData->dwConnectToNonPreferredNtwks) {
  1086. dwCtlFlags |= INTFCTL_FALLBACK;
  1087. }
  1088. switch (pWirelessPolicyData->dwNetworkToAccess) {
  1089. case WIRELESS_ACCESS_NETWORK_ANY :
  1090. dwCtlFlags |= INTFCTL_CM_MASK & Ndis802_11AutoUnknown;
  1091. break;
  1092. case WIRELESS_ACCESS_NETWORK_AP :
  1093. dwCtlFlags |= INTFCTL_CM_MASK & Ndis802_11Infrastructure;
  1094. break;
  1095. case WIRELESS_ACCESS_NETWORK_ADHOC:
  1096. dwCtlFlags |= INTFCTL_CM_MASK & Ndis802_11IBSS;
  1097. break;
  1098. default:
  1099. dwCtlFlags |= INTFCTL_CM_MASK & Ndis802_11AutoUnknown;
  1100. break;
  1101. }
  1102. dwCtlFlags |= INTFCTL_POLICY;
  1103. dwCtlFlags |= INTFCTL_VOLATILE;
  1104. dwNumPSSettings = pWirelessPolicyData->dwNumPreferredSettings;
  1105. if (dwNumPSSettings != 0) {
  1106. dwWZCConfigListSize = (dwNumPSSettings-1) * sizeof(WZC_WLAN_CONFIG) + sizeof(WZC_802_11_CONFIG_LIST);
  1107. } else
  1108. {
  1109. dwWZCConfigListSize = sizeof(WZC_802_11_CONFIG_LIST);
  1110. }
  1111. pWZCConfigList = (PWZC_802_11_CONFIG_LIST) AllocSPDMem(dwWZCConfigListSize);
  1112. if (!pWZCConfigList) {
  1113. dwError = GetLastError();
  1114. BAIL_ON_WIN32_ERROR(dwError);
  1115. }
  1116. pWZCConfig = (PWZC_WLAN_CONFIG) &(pWZCConfigList->Config);
  1117. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  1118. for (i = 0; i < dwNumPSSettings; ++i) {
  1119. // If the SSID is 32 bit in length, we need to null terminate it so that the following call succeeds.
  1120. // SSid cannont take more than 32 bytes.. it becomes an issue with 32 byte SSID ..as it cannot null
  1121. // terminate it. So copy to a temp variable and then copy 32 bytes.
  1122. wcsncpy(pszTempSSID, ppWirelessPSData[i]->pszWirelessSSID, 32);
  1123. pszTempSSID[32] = L'\0';
  1124. dwSSIDSize = WideCharToMultiByte (
  1125. CP_ACP,
  1126. 0,
  1127. pszTempSSID, //ppWirelessPSData[i]->pszWirelessSSID,
  1128. -1,
  1129. pszOutSSID,
  1130. MAX_SSID_LEN +1 ,
  1131. NULL,
  1132. NULL);
  1133. if (dwSSIDSize == 0)
  1134. {
  1135. dwError = GetLastError();
  1136. }
  1137. BAIL_ON_WIN32_ERROR(dwError);
  1138. memcpy(pWZCConfig[i].Ssid.Ssid, pszOutSSID, 32);
  1139. pWZCConfig[i].Ssid.SsidLength = dwSSIDSize -1;
  1140. if (ppWirelessPSData[i]->dwNetworkType == WIRELESS_NETWORK_TYPE_ADHOC)
  1141. {
  1142. pWZCConfig[i].InfrastructureMode = Ndis802_11IBSS;
  1143. } else {
  1144. pWZCConfig[i].InfrastructureMode = Ndis802_11Infrastructure;
  1145. }
  1146. if (ppWirelessPSData[i]->dwNetworkAuthentication) {
  1147. pWZCConfig[i].AuthenticationMode = Ndis802_11AuthModeShared;
  1148. } else {
  1149. pWZCConfig[i].AuthenticationMode = Ndis802_11AuthModeOpen;
  1150. }
  1151. if (ppWirelessPSData[i]->dwWepEnabled) {
  1152. pWZCConfig[i].Privacy = 1;
  1153. } else {
  1154. pWZCConfig[i].Privacy = 0;
  1155. }
  1156. pWZCConfig[i].dwCtlFlags = 0;
  1157. if (ppWirelessPSData[i]->dwAutomaticKeyProvision) {
  1158. pWZCConfig[i].dwCtlFlags &= ~WZCCTL_WEPK_PRESENT;
  1159. pWZCConfig[i].KeyLength = 0;
  1160. } else {
  1161. pWZCConfig[i].dwCtlFlags |= WZCCTL_WEPK_PRESENT;
  1162. pWZCConfig[i].KeyLength = 5;
  1163. }
  1164. pWZCConfig[i].dwCtlFlags |= WZCCTL_VOLATILE;
  1165. pWZCConfig[i].dwCtlFlags |= WZCCTL_POLICY;
  1166. pWZCConfig[i].Length = sizeof(WZC_WLAN_CONFIG);
  1167. }
  1168. pWZCConfigList->NumberOfItems = dwNumPSSettings;
  1169. pWZCConfigList->Index = dwNumPSSettings;
  1170. pIntfEntry->dwCtlFlags = dwCtlFlags;
  1171. pIntfEntry->rdStSSIDList.dwDataLen = dwWZCConfigListSize;
  1172. pIntfEntry->rdStSSIDList.pData = (LPBYTE) pWZCConfigList;
  1173. dwInFlags |= INTF_ALL_FLAGS;
  1174. dwInFlags |= INTF_PREFLIST;
  1175. dwError = LstSetInterface(dwInFlags, pIntfEntry, &dwOutFlags);
  1176. error:
  1177. if (pWZCConfigList)
  1178. FreeSPDMem(pWZCConfigList);
  1179. if (pIntfEntry)
  1180. FreeSPDMem(pIntfEntry);
  1181. return (dwError);
  1182. }
  1183. DWORD
  1184. AddEapolPolicy(PWIRELESS_POLICY_DATA pWirelessPolicyData)
  1185. {
  1186. DWORD dwError = 0;
  1187. PEAPOL_POLICY_LIST pEapolPolicyList = NULL;
  1188. dwError = ConvertWirelessPolicyDataToEAPOLList(
  1189. pWirelessPolicyData,
  1190. &pEapolPolicyList
  1191. );
  1192. BAIL_ON_WIN32_ERROR(dwError);
  1193. _WirelessDbg(TRC_TRACK, "Calling into EAPOL API ");
  1194. dwError = ElPolicyChange(pEapolPolicyList);
  1195. _WirelessDbg(TRC_TRACK, "Call to EAPOL API returned with code %d ", dwError);
  1196. if (pEapolPolicyList) {
  1197. FreeEAPOLList(pEapolPolicyList);
  1198. }
  1199. error:
  1200. return(dwError);
  1201. }