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.

865 lines
20 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2001.
  5. //
  6. // File: api.c
  7. //
  8. // Contents: APIs exported to snapin to manage WIFI policy objects on AD
  9. //
  10. //
  11. // History: TaroonM
  12. // 10/30/01
  13. //
  14. // Remarks: Wireless Network Policy Management Currently doesnt support Registry based(local) policies. However we are
  15. // keeping the Registry based code, for possible use later.
  16. //----------------------------------------------------------------------------
  17. #include "precomp.h"
  18. DWORD
  19. WirelessEnumPolicyData(
  20. HANDLE hPolicyStore,
  21. PWIRELESS_POLICY_DATA ** pppWirelessPolicyData,
  22. PDWORD pdwNumPolicyObjects
  23. )
  24. {
  25. DWORD dwError = 0;
  26. DWORD dwProvider = 0;
  27. PWIRELESS_POLICY_STORE pPolicyStore = NULL;
  28. IWbemServices *pWbemServices = NULL;
  29. pPolicyStore = (PWIRELESS_POLICY_STORE)hPolicyStore;
  30. switch (pPolicyStore->dwProvider) {
  31. case WIRELESS_REGISTRY_PROVIDER:
  32. break;
  33. case WIRELESS_DIRECTORY_PROVIDER:
  34. dwError = DirEnumWirelessPolicyData(
  35. (pPolicyStore->hLdapBindHandle),
  36. pPolicyStore->pszWirelessRootContainer,
  37. pppWirelessPolicyData,
  38. pdwNumPolicyObjects
  39. );
  40. break;
  41. case WIRELESS_WMI_PROVIDER:
  42. dwError = CreateIWbemServices(
  43. pPolicyStore->pszLocationName,
  44. &pWbemServices
  45. );
  46. if(dwError == ERROR_SUCCESS) {
  47. dwError = WMIEnumPolicyDataEx(
  48. pWbemServices,
  49. pppWirelessPolicyData,
  50. pdwNumPolicyObjects
  51. );
  52. IWbemServices_Release(pWbemServices);
  53. }
  54. break;
  55. default:
  56. dwError = ERROR_INVALID_PARAMETER;
  57. break;
  58. }
  59. return(dwError);
  60. }
  61. DWORD
  62. WirelessSetPolicyData(
  63. HANDLE hPolicyStore,
  64. PWIRELESS_POLICY_DATA pWirelessPolicyData
  65. )
  66. {
  67. DWORD dwError = 0;
  68. DWORD dwProvider = 0;
  69. PWIRELESS_POLICY_STORE pPolicyStore = NULL;
  70. dwError = ValidateWirelessPolicyData(
  71. pWirelessPolicyData
  72. );
  73. BAIL_ON_WIN32_ERROR(dwError);
  74. pPolicyStore = (PWIRELESS_POLICY_STORE)hPolicyStore;
  75. switch (pPolicyStore->dwProvider) {
  76. case WIRELESS_REGISTRY_PROVIDER:
  77. break;
  78. case WIRELESS_DIRECTORY_PROVIDER:
  79. dwError = DirSetWirelessPolicyData(
  80. (pPolicyStore->hLdapBindHandle),
  81. pPolicyStore->pszWirelessRootContainer,
  82. pWirelessPolicyData
  83. );
  84. break;
  85. case WIRELESS_WMI_PROVIDER:
  86. dwError = ERROR_NOT_SUPPORTED;
  87. break;
  88. default:
  89. dwError = ERROR_INVALID_PARAMETER;
  90. break;
  91. }
  92. error:
  93. return(dwError);
  94. }
  95. DWORD
  96. WirelessCreatePolicyData(
  97. HANDLE hPolicyStore,
  98. PWIRELESS_POLICY_DATA pWirelessPolicyData
  99. )
  100. {
  101. DWORD dwError = 0;
  102. DWORD dwProvider = 0;
  103. PWIRELESS_POLICY_STORE pPolicyStore = NULL;
  104. dwError = ValidateWirelessPolicyData(
  105. pWirelessPolicyData
  106. );
  107. BAIL_ON_WIN32_ERROR(dwError);
  108. pPolicyStore = (PWIRELESS_POLICY_STORE)hPolicyStore;
  109. switch (pPolicyStore->dwProvider) {
  110. case WIRELESS_REGISTRY_PROVIDER:
  111. /*
  112. dwError = RegCreatePolicyData(
  113. (pPolicyStore->hRegistryKey),
  114. pPolicyStore->pszWirelessRootContainer,
  115. pWirelessPolicyData
  116. );
  117. */
  118. break;
  119. case WIRELESS_DIRECTORY_PROVIDER:
  120. dwError = DirCreateWirelessPolicyData(
  121. (pPolicyStore->hLdapBindHandle),
  122. pPolicyStore->pszWirelessRootContainer,
  123. pWirelessPolicyData
  124. );
  125. break;
  126. case WIRELESS_WMI_PROVIDER:
  127. dwError = ERROR_NOT_SUPPORTED;
  128. break;
  129. default:
  130. dwError = ERROR_INVALID_PARAMETER;
  131. break;
  132. }
  133. error:
  134. return(dwError);
  135. }
  136. DWORD
  137. WirelessDeletePolicyData(
  138. HANDLE hPolicyStore,
  139. PWIRELESS_POLICY_DATA pWirelessPolicyData
  140. )
  141. {
  142. DWORD dwError = 0;
  143. DWORD dwProvider = 0;
  144. PWIRELESS_POLICY_STORE pPolicyStore = NULL;
  145. pPolicyStore = (PWIRELESS_POLICY_STORE)hPolicyStore;
  146. switch (pPolicyStore->dwProvider) {
  147. case WIRELESS_REGISTRY_PROVIDER:
  148. break;
  149. case WIRELESS_DIRECTORY_PROVIDER:
  150. dwError = DirDeleteWirelessPolicyData(
  151. (pPolicyStore->hLdapBindHandle),
  152. pPolicyStore->pszWirelessRootContainer,
  153. pWirelessPolicyData
  154. );
  155. break;
  156. case WIRELESS_WMI_PROVIDER:
  157. dwError = ERROR_NOT_SUPPORTED;
  158. break;
  159. default:
  160. dwError = ERROR_INVALID_PARAMETER;
  161. break;
  162. }
  163. return(dwError);
  164. }
  165. /*
  166. pszGPO name contains the LDAP path of the GPO whose extesnion
  167. snapin is making this call.
  168. */
  169. DWORD
  170. WirelessGPOOpenPolicyStore(
  171. LPWSTR pszMachineName,
  172. DWORD dwTypeOfStore,
  173. LPWSTR pszGPOName,
  174. LPWSTR pszFileName,
  175. HANDLE * phPolicyStore
  176. )
  177. {
  178. DWORD dwError = 0;
  179. switch (dwTypeOfStore) {
  180. case WIRELESS_REGISTRY_PROVIDER:
  181. break;
  182. case WIRELESS_DIRECTORY_PROVIDER:
  183. dwError = DirGPOOpenPolicyStore(
  184. pszMachineName,
  185. pszGPOName,
  186. phPolicyStore
  187. );
  188. break;
  189. case WIRELESS_FILE_PROVIDER:
  190. break;
  191. case WIRELESS_WMI_PROVIDER:
  192. dwError = WMIOpenPolicyStore(
  193. pszMachineName,
  194. phPolicyStore
  195. );
  196. break;
  197. default:
  198. dwError = ERROR_INVALID_PARAMETER;
  199. break;
  200. }
  201. return (dwError);
  202. }
  203. DWORD
  204. DirGPOOpenPolicyStore(
  205. LPWSTR pszMachineName,
  206. LPWSTR pszGPOName,
  207. HANDLE * phPolicyStore
  208. )
  209. {
  210. PWIRELESS_POLICY_STORE pPolicyStore = NULL;
  211. DWORD dwError = 0;
  212. LPWSTR pszWirelessRootContainer = NULL;
  213. HLDAP hLdapBindHandle = NULL;
  214. LPWSTR pszDefaultDirectory = NULL;
  215. if (!pszMachineName || !*pszMachineName) {
  216. dwError = ComputeDefaultDirectory(
  217. &pszDefaultDirectory
  218. );
  219. BAIL_ON_WIN32_ERROR(dwError);
  220. dwError = OpenDirectoryServerHandle(
  221. pszDefaultDirectory,
  222. 389,
  223. &hLdapBindHandle
  224. );
  225. BAIL_ON_WIN32_ERROR(dwError);
  226. dwError = ComputeGPODirLocationName(
  227. pszGPOName,
  228. &pszWirelessRootContainer
  229. );
  230. BAIL_ON_WIN32_ERROR(dwError);
  231. }
  232. else {
  233. dwError = OpenDirectoryServerHandle(
  234. pszMachineName,
  235. 389,
  236. &hLdapBindHandle
  237. );
  238. BAIL_ON_WIN32_ERROR(dwError);
  239. dwError = ComputeGPODirLocationName(
  240. pszGPOName,
  241. &pszWirelessRootContainer
  242. );
  243. BAIL_ON_WIN32_ERROR(dwError);
  244. }
  245. pPolicyStore = (PWIRELESS_POLICY_STORE)AllocPolMem(
  246. sizeof(WIRELESS_POLICY_STORE)
  247. );
  248. if (!pPolicyStore) {
  249. dwError = ERROR_OUTOFMEMORY;
  250. BAIL_ON_WIN32_ERROR(dwError);
  251. }
  252. pPolicyStore->dwProvider = WIRELESS_DIRECTORY_PROVIDER;
  253. pPolicyStore->hParentRegistryKey = NULL;
  254. pPolicyStore->hRegistryKey = NULL;
  255. pPolicyStore->pszLocationName = NULL;
  256. pPolicyStore->hLdapBindHandle = hLdapBindHandle;
  257. pPolicyStore->pszWirelessRootContainer = pszWirelessRootContainer;
  258. pPolicyStore->pszFileName = NULL;
  259. *phPolicyStore = pPolicyStore;
  260. cleanup:
  261. if (pszDefaultDirectory) {
  262. FreePolStr(pszDefaultDirectory);
  263. }
  264. return(dwError);
  265. error:
  266. if (hLdapBindHandle) {
  267. CloseDirectoryServerHandle(hLdapBindHandle);
  268. }
  269. if (pszWirelessRootContainer) {
  270. FreePolStr(pszWirelessRootContainer);
  271. }
  272. if (pPolicyStore) {
  273. FreePolMem(pPolicyStore);
  274. }
  275. *phPolicyStore = NULL;
  276. goto cleanup;
  277. }
  278. DWORD
  279. WirelessClosePolicyStore(
  280. HANDLE hPolicyStore
  281. )
  282. {
  283. DWORD dwError = 0;
  284. PWIRELESS_POLICY_STORE pPolicyStore = NULL;
  285. pPolicyStore = (PWIRELESS_POLICY_STORE)hPolicyStore;
  286. switch (pPolicyStore->dwProvider) {
  287. case WIRELESS_REGISTRY_PROVIDER:
  288. break;
  289. case WIRELESS_DIRECTORY_PROVIDER:
  290. if (pPolicyStore->hLdapBindHandle) {
  291. CloseDirectoryServerHandle(
  292. pPolicyStore->hLdapBindHandle
  293. );
  294. }
  295. if (pPolicyStore->pszWirelessRootContainer) {
  296. FreePolStr(pPolicyStore->pszWirelessRootContainer);
  297. }
  298. break;
  299. case WIRELESS_FILE_PROVIDER:
  300. break;
  301. default:
  302. dwError = ERROR_INVALID_PARAMETER;
  303. BAIL_ON_WIN32_ERROR(dwError);
  304. break;
  305. }
  306. if (pPolicyStore) {
  307. FreePolMem(pPolicyStore);
  308. }
  309. error:
  310. return(dwError);
  311. }
  312. DWORD
  313. ComputeGPODirLocationName(
  314. LPWSTR pszDirDomainName,
  315. LPWSTR * ppszDirFQPathName
  316. )
  317. {
  318. DWORD dwError = 0;
  319. WCHAR szName[MAX_PATH];
  320. LPWSTR pszDirFQPathName = NULL;
  321. DWORD dwDirDomainNameLen = 0;
  322. DWORD dwDirLocationNameLen = 0;
  323. DWORD dwTotalLen = 0;
  324. szName[0] = L'\0';
  325. wcscpy(szName, L"CN=Wireless, CN=Windows,CN=Microsoft,");
  326. dwDirDomainNameLen = wcslen(pszDirDomainName);
  327. dwDirLocationNameLen = wcslen(szName);
  328. dwTotalLen = dwDirDomainNameLen+dwDirLocationNameLen;
  329. pszDirFQPathName = AllocPolMem((dwTotalLen+1) * sizeof(WCHAR));
  330. if (!pszDirFQPathName) {
  331. dwError = ERROR_OUTOFMEMORY;
  332. BAIL_ON_WIN32_ERROR(dwError);
  333. }
  334. wcsncpy(pszDirFQPathName, szName, dwDirLocationNameLen);
  335. wcsncat(pszDirFQPathName, pszDirDomainName, dwDirDomainNameLen);
  336. pszDirFQPathName[dwTotalLen] = L'\0';
  337. *ppszDirFQPathName = pszDirFQPathName;
  338. return (dwError);
  339. error:
  340. *ppszDirFQPathName = NULL;
  341. return(dwError);
  342. }
  343. /*
  344. Helper Function: Set PS in a Policy Structure
  345. */
  346. DWORD
  347. WirelessSetPSDataInPolicy(
  348. PWIRELESS_POLICY_DATA pWirelessPolicyData,
  349. PWIRELESS_PS_DATA pWirelessPSData
  350. )
  351. {
  352. DWORD dwError = 0;
  353. DWORD dwPSId = -1;
  354. WirelessPolicyPSId(pWirelessPolicyData,
  355. pWirelessPSData->pszWirelessSSID,
  356. &dwPSId
  357. );
  358. if (dwPSId == -1) {
  359. dwError = ERROR_PS_NOT_PRESENT;
  360. BAIL_ON_WIN32_ERROR(dwError);
  361. }
  362. dwError = ModifyWirelessPSData(
  363. pWirelessPolicyData->ppWirelessPSData[dwPSId],
  364. pWirelessPSData
  365. );
  366. BAIL_ON_WIN32_ERROR(dwError);
  367. dwError = ERROR_SUCCESS;
  368. return(dwError);
  369. error:
  370. return(dwError);
  371. }
  372. DWORD
  373. WirelessAddPSToPolicy(
  374. PWIRELESS_POLICY_DATA pWirelessPolicyData,
  375. PWIRELESS_PS_DATA pWirelessPSData
  376. )
  377. {
  378. DWORD dwNumPreferredSettings = 0;
  379. DWORD dwError = 0;
  380. PWIRELESS_PS_DATA *ppWirelessPSData=NULL;
  381. PWIRELESS_PS_DATA *ppNewWirelessPSData=NULL;
  382. DWORD i = 0;
  383. DWORD dwInsertIndex = 0;
  384. DWORD dwNumAPNetworks = 0;
  385. dwNumPreferredSettings = pWirelessPolicyData->dwNumPreferredSettings;
  386. dwNumAPNetworks = pWirelessPolicyData->dwNumAPNetworks;
  387. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  388. ppNewWirelessPSData = (PWIRELESS_PS_DATA *)
  389. AllocPolMem(sizeof(PWIRELESS_PS_DATA)*(dwNumPreferredSettings+1));
  390. if(!ppNewWirelessPSData) {
  391. dwError = ERROR_OUTOFMEMORY;
  392. BAIL_ON_WIN32_ERROR(dwError);
  393. }
  394. if(pWirelessPSData->dwNetworkType == WIRELESS_NETWORK_TYPE_ADHOC) {
  395. dwInsertIndex = dwNumPreferredSettings;
  396. } else
  397. {
  398. dwInsertIndex = dwNumAPNetworks;
  399. pWirelessPolicyData->dwNumAPNetworks = dwNumAPNetworks+1;
  400. }
  401. for (i = 0; i < dwInsertIndex; ++i)
  402. {
  403. ppNewWirelessPSData[i] = ppWirelessPSData[i];
  404. }
  405. ppNewWirelessPSData[dwInsertIndex] = pWirelessPSData;
  406. pWirelessPSData->dwId = dwInsertIndex;
  407. for (i = dwInsertIndex; i < dwNumPreferredSettings; ++i) {
  408. ppNewWirelessPSData[i+1] = ppWirelessPSData[i];
  409. ppNewWirelessPSData[i+1]->dwId = i+1;
  410. }
  411. pWirelessPolicyData->dwNumPreferredSettings = dwNumPreferredSettings+1;
  412. pWirelessPolicyData->ppWirelessPSData = ppNewWirelessPSData;
  413. FreePolMem(ppWirelessPSData);
  414. return(0);
  415. error:
  416. return(dwError);
  417. }
  418. DWORD
  419. WirelessRemovePSFromPolicy(
  420. PWIRELESS_POLICY_DATA pWirelessPolicyData,
  421. LPCWSTR pszSSID
  422. )
  423. {
  424. DWORD dwNumPreferredSettings = 0;
  425. DWORD dwError = 0;
  426. PWIRELESS_PS_DATA *ppWirelessPSData;
  427. PWIRELESS_PS_DATA *ppNewWirelessPSData;
  428. DWORD i = 0;
  429. DWORD dwPSId;
  430. dwNumPreferredSettings = pWirelessPolicyData->dwNumPreferredSettings;
  431. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  432. WirelessPolicyPSId(pWirelessPolicyData,pszSSID,&dwPSId);
  433. if(dwPSId == -1)
  434. {
  435. dwError = ERROR_PS_NOT_PRESENT;
  436. BAIL_ON_WIN32_ERROR(dwError);
  437. }
  438. ppNewWirelessPSData = (PWIRELESS_PS_DATA *)
  439. AllocPolMem(sizeof(PWIRELESS_PS_DATA)*(dwNumPreferredSettings-1));
  440. if(!ppNewWirelessPSData) {
  441. dwError = ERROR_OUTOFMEMORY;
  442. BAIL_ON_WIN32_ERROR(dwError);
  443. }
  444. for(i = 0; i < dwPSId; ++i)
  445. {
  446. ppNewWirelessPSData[i] = ppWirelessPSData[i];
  447. }
  448. for(i = dwPSId; i < dwNumPreferredSettings-1; ++i)
  449. {
  450. ppNewWirelessPSData[i] = ppWirelessPSData[i+1];
  451. }
  452. pWirelessPolicyData->dwNumPreferredSettings = dwNumPreferredSettings-1;
  453. pWirelessPolicyData->ppWirelessPSData = ppNewWirelessPSData;
  454. FreePolMem(ppWirelessPSData);
  455. return(0);
  456. error:
  457. return(dwError);
  458. }
  459. DWORD
  460. WirelessRemovePSFromPolicyId(
  461. PWIRELESS_POLICY_DATA pWirelessPolicyData,
  462. DWORD dwId
  463. )
  464. {
  465. DWORD dwNumPreferredSettings = 0;
  466. DWORD dwError = 0;
  467. PWIRELESS_PS_DATA *ppWirelessPSData;
  468. PWIRELESS_PS_DATA *ppNewWirelessPSData;
  469. DWORD i = 0;
  470. DWORD dwPSId;
  471. dwNumPreferredSettings = pWirelessPolicyData->dwNumPreferredSettings;
  472. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  473. if(dwId >= dwNumPreferredSettings )
  474. {
  475. dwError = ERROR_PS_NOT_PRESENT;
  476. BAIL_ON_WIN32_ERROR(dwError);
  477. }
  478. ppNewWirelessPSData = (PWIRELESS_PS_DATA *)
  479. AllocPolMem(sizeof(PWIRELESS_PS_DATA)*(dwNumPreferredSettings-1));
  480. if(!ppNewWirelessPSData) {
  481. dwError = ERROR_OUTOFMEMORY;
  482. BAIL_ON_WIN32_ERROR(dwError);
  483. }
  484. for(i = 0; i < dwId; ++i)
  485. {
  486. ppNewWirelessPSData[i] = ppWirelessPSData[i];
  487. }
  488. if (ppWirelessPSData[dwId]->dwNetworkType == WIRELESS_NETWORK_TYPE_AP) {
  489. pWirelessPolicyData->dwNumAPNetworks--;
  490. }
  491. for(i = dwId; i < dwNumPreferredSettings-1; ++i)
  492. {
  493. ppNewWirelessPSData[i] = ppWirelessPSData[i+1];
  494. ppNewWirelessPSData[i]->dwId = i;
  495. }
  496. pWirelessPolicyData->dwNumPreferredSettings = dwNumPreferredSettings-1;
  497. pWirelessPolicyData->ppWirelessPSData = ppNewWirelessPSData;
  498. FreePolMem(ppWirelessPSData);
  499. return(0);
  500. error:
  501. return(dwError);
  502. }
  503. void
  504. WirelessPolicyPSId(PWIRELESS_POLICY_DATA pWirelessPolicyData, LPCWSTR pszSSID, DWORD *dwId)
  505. {
  506. DWORD dwError=0;
  507. DWORD dwNumPreferredSettings;
  508. DWORD dwSSIDLen = 0;
  509. DWORD i = 0;
  510. DWORD dwCompare = 1;
  511. DWORD dwPId = -1;
  512. PWIRELESS_PS_DATA *ppWirelessPSData;
  513. PWIRELESS_PS_DATA pWirelessPSData;
  514. dwSSIDLen = lstrlenW(pszSSID);
  515. dwNumPreferredSettings = pWirelessPolicyData->dwNumPreferredSettings;
  516. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  517. for(i = 0; i < dwNumPreferredSettings; ++i) {
  518. pWirelessPSData = ppWirelessPSData[i];
  519. if(pWirelessPSData->dwWirelessSSIDLen == dwSSIDLen)
  520. {
  521. dwCompare = memcmp(pWirelessPSData->pszWirelessSSID,pszSSID,dwSSIDLen*2);
  522. }
  523. if (dwCompare == 0) {
  524. dwPId = i;
  525. break;
  526. }
  527. }
  528. *dwId = dwPId;
  529. return;
  530. }
  531. void
  532. UpdateWirelessPSData(
  533. PWIRELESS_PS_DATA pWirelessPSData
  534. )
  535. {
  536. DWORD dwDescriptionLen = 0;
  537. DWORD dwEAPDataLen = 0;
  538. DWORD dwWirelessSSIDLen = 0;
  539. DWORD dwPSLen = 0;
  540. // may be replace it with actual counting.
  541. dwWirelessSSIDLen = lstrlenW(pWirelessPSData->pszWirelessSSID);
  542. dwDescriptionLen = lstrlenW(pWirelessPSData->pszDescription);
  543. //dwPSLen = 20 * sizeof(DWORD) + 32*2 + 2 * dwDescriptionLen;
  544. dwEAPDataLen = pWirelessPSData->dwEAPDataLen;
  545. dwPSLen = (sizeof(WIRELESS_PS_DATA) - sizeof(DWORD) - sizeof(LPWSTR)) + sizeof(WCHAR) * dwDescriptionLen
  546. - sizeof(LPBYTE) + dwEAPDataLen;
  547. pWirelessPSData->dwPSLen = dwPSLen;
  548. pWirelessPSData->dwWirelessSSIDLen =
  549. (dwWirelessSSIDLen < 32) ? dwWirelessSSIDLen : 32;
  550. pWirelessPSData->dwDescriptionLen = dwDescriptionLen;
  551. }
  552. DWORD
  553. WMIOpenPolicyStore(
  554. LPWSTR pszMachineName,
  555. HANDLE * phPolicyStore
  556. )
  557. {
  558. PWIRELESS_POLICY_STORE pPolicyStore = NULL;
  559. DWORD dwError = 0;
  560. pPolicyStore = (PWIRELESS_POLICY_STORE)AllocPolMem(
  561. sizeof(WIRELESS_POLICY_STORE)
  562. );
  563. if (!pPolicyStore) {
  564. dwError = ERROR_OUTOFMEMORY;
  565. BAIL_ON_WIN32_ERROR(dwError);
  566. }
  567. pPolicyStore->dwProvider = WIRELESS_WMI_PROVIDER;
  568. pPolicyStore->hParentRegistryKey = NULL;
  569. pPolicyStore->hRegistryKey = NULL;
  570. pPolicyStore->pszLocationName = pszMachineName;
  571. pPolicyStore->hLdapBindHandle = NULL;
  572. pPolicyStore->pszWirelessRootContainer = NULL;
  573. pPolicyStore->pszFileName = NULL;
  574. *phPolicyStore = pPolicyStore;
  575. cleanup:
  576. return(dwError);
  577. error:
  578. if (pPolicyStore) {
  579. FreePolMem(pPolicyStore);
  580. }
  581. *phPolicyStore = NULL;
  582. goto cleanup;
  583. }
  584. HRESULT
  585. WirelessWriteDirectoryPolicyToWMI(
  586. LPWSTR pszMachineName,
  587. LPWSTR pszPolicyDN,
  588. PGPO_INFO pGPOInfo,
  589. IWbemServices *pWbemServices
  590. )
  591. {
  592. DWORD dwError = 0;
  593. HRESULT hr = S_OK;
  594. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject = NULL;
  595. BOOL bDeepRead = FALSE;
  596. if (!pWbemServices
  597. || !pszPolicyDN
  598. || !pGPOInfo
  599. )
  600. {
  601. hr = E_INVALIDARG;
  602. BAIL_ON_HRESULT_ERROR(hr);
  603. }
  604. bDeepRead = (pGPOInfo->uiPrecedence == 1);
  605. hr = ReadPolicyObjectFromDirectoryEx(
  606. pszMachineName,
  607. pszPolicyDN,
  608. bDeepRead,
  609. &pWirelessPolicyObject
  610. );
  611. BAIL_ON_HRESULT_ERROR(hr);
  612. hr = WritePolicyObjectDirectoryToWMI(
  613. pWbemServices,
  614. pWirelessPolicyObject,
  615. pGPOInfo
  616. );
  617. BAIL_ON_HRESULT_ERROR(hr);
  618. error:
  619. if (pWirelessPolicyObject) {
  620. FreeWirelessPolicyObject(pWirelessPolicyObject);
  621. }
  622. return(hr);
  623. }
  624. HRESULT
  625. WirelessClearWMIStore(
  626. IWbemServices *pWbemServices
  627. )
  628. {
  629. HRESULT hr = S_OK;
  630. if (!pWbemServices) {
  631. hr = E_INVALIDARG;
  632. BAIL_ON_HRESULT_ERROR(hr);
  633. }
  634. hr = DeleteWMIClassObject(
  635. pWbemServices,
  636. WIRELESS_RSOP_CLASSNAME
  637. );
  638. BAIL_ON_HRESULT_ERROR(hr);
  639. error:
  640. return(hr);
  641. }