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.

1550 lines
46 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2001.
  5. //
  6. // File: procrule.h
  7. //
  8. // Contents: Wireless Network Policy Management - Marshall/Unmarshall/etc.
  9. //
  10. //
  11. // History: TaroonM
  12. // 10/30/01
  13. // Abhishev(2000)
  14. //----------------------------------------------------------------------------
  15. #include "precomp.h"
  16. DWORD
  17. DeepCpyRsopInfo(
  18. PRSOP_INFO pDestRsop,
  19. PRSOP_INFO pSrcRsop
  20. )
  21. {
  22. DWORD dwError = ERROR_SUCCESS;
  23. if (pSrcRsop->pszCreationtime && *pSrcRsop->pszCreationtime) {
  24. pDestRsop->pszCreationtime = AllocPolStr(
  25. pSrcRsop->pszCreationtime
  26. );
  27. if (!pDestRsop->pszCreationtime) {
  28. dwError = ERROR_OUTOFMEMORY;
  29. BAIL_ON_WIN32_ERROR(dwError);
  30. }
  31. }
  32. if (pSrcRsop->pszID && *pSrcRsop->pszID) {
  33. pDestRsop->pszID = AllocPolStr(
  34. pSrcRsop->pszID
  35. );
  36. if (!pDestRsop->pszID) {
  37. dwError = ERROR_OUTOFMEMORY;
  38. BAIL_ON_WIN32_ERROR(dwError);
  39. }
  40. }
  41. if (pSrcRsop->pszName && *pSrcRsop->pszName) {
  42. pDestRsop->pszName = AllocPolStr(
  43. pSrcRsop->pszName
  44. );
  45. }
  46. pDestRsop->uiPrecedence = pSrcRsop->uiPrecedence;
  47. if (pSrcRsop->pszGPOID && *pSrcRsop->pszGPOID) {
  48. pDestRsop->pszGPOID= AllocPolStr(
  49. pSrcRsop->pszGPOID
  50. );
  51. if (!pDestRsop->pszGPOID) {
  52. dwError = ERROR_OUTOFMEMORY;
  53. BAIL_ON_WIN32_ERROR(dwError);
  54. }
  55. }
  56. if (pSrcRsop->pszSOMID && *pSrcRsop->pszSOMID) {
  57. pDestRsop->pszSOMID = AllocPolStr(
  58. pSrcRsop->pszSOMID
  59. );
  60. if (!pDestRsop->pszSOMID) {
  61. dwError = ERROR_OUTOFMEMORY;
  62. BAIL_ON_WIN32_ERROR(dwError);
  63. }
  64. }
  65. error:
  66. return dwError;
  67. }
  68. DWORD
  69. UnmarshallWirelessPSObject(
  70. LPBYTE pMem,
  71. PWIRELESS_PS_DATA *ppWirelessPSData,
  72. LPBYTE *ppMem,
  73. LPBYTE pMemDelimitter
  74. )
  75. {
  76. DWORD dwError = 0;
  77. DWORD dwPSLen = 0;
  78. PWIRELESS_PS_DATA pWirelessPSData = NULL;
  79. WCHAR pszWirelessSSID[32];
  80. DWORD dwWirelessSSIDLen = 0;
  81. DWORD dwWepEnabled = 0;
  82. DWORD dwId = 0;
  83. DWORD dwNetworkAuthentication = 0;
  84. DWORD dwAutomaticKeyProvision = 0;
  85. DWORD dwNetworkType = 0;
  86. DWORD dwEnable8021x = 0;
  87. DWORD dw8021xMode = 0;
  88. DWORD dwEapType = 0;
  89. DWORD dwCertificateType = 0;
  90. DWORD dwValidateServerCertificate = 0;
  91. DWORD dwMachineAuthentication = 0;
  92. DWORD dwMachineAuthenticationType = 0;
  93. DWORD dwGuestAuthentication = 0;
  94. DWORD dwIEEE8021xMaxStart = 0;
  95. DWORD dwIEEE8021xStartPeriod = 0;
  96. DWORD dwIEEE802xAuthPeriod = 0;
  97. DWORD dwIEEE802xHeldPeriod = 0;
  98. DWORD dwDescriptionLen = 0;
  99. DWORD dwEAPDataLen = 0;
  100. LPBYTE pbEAPData = NULL;
  101. LPWSTR pszDescription = NULL;
  102. LPBYTE pTempMem = NULL;
  103. pTempMem = pMem;
  104. pWirelessPSData = (PWIRELESS_PS_DATA)AllocPolMem(
  105. sizeof(WIRELESS_PS_DATA)
  106. );
  107. if (!pWirelessPSData) {
  108. dwError = ERROR_OUTOFMEMORY;
  109. BAIL_ON_WIN32_ERROR(dwError);
  110. }
  111. if (pMem + sizeof(DWORD) > pMemDelimitter) {
  112. dwError = ERROR_INVALID_PARAMETER;
  113. }
  114. BAIL_ON_WIN32_ERROR(dwError);
  115. memcpy((LPBYTE)&dwPSLen, pMem, sizeof(DWORD));
  116. pMem += sizeof(DWORD);
  117. pWirelessPSData->dwPSLen = dwPSLen;
  118. if (pMem + dwPSLen -sizeof(DWORD) > pMemDelimitter) {
  119. dwError = ERROR_INVALID_PARAMETER;
  120. }
  121. BAIL_ON_WIN32_ERROR(dwError);
  122. // Now that we know the length of this PS, and it is in bounds
  123. // delimit further ; given by PSLen
  124. pMemDelimitter = pTempMem + dwPSLen;
  125. memcpy(pszWirelessSSID, pMem, 32*sizeof(WCHAR));
  126. pMem += 32*(sizeof(WCHAR));
  127. memcpy(pWirelessPSData->pszWirelessSSID, pszWirelessSSID, 32*sizeof(WCHAR));
  128. memcpy((LPBYTE)&dwWirelessSSIDLen, pMem, sizeof(DWORD));
  129. pMem += sizeof(DWORD);
  130. pWirelessPSData->dwWirelessSSIDLen = dwWirelessSSIDLen;
  131. memcpy((LPBYTE)&dwWepEnabled, pMem, sizeof(DWORD));
  132. pMem += sizeof(DWORD);
  133. pWirelessPSData->dwWepEnabled = dwWepEnabled;
  134. memcpy((LPBYTE)&dwId, pMem, sizeof(DWORD));
  135. pMem += sizeof(DWORD);
  136. pWirelessPSData->dwId = dwId;
  137. memcpy((LPBYTE)&dwNetworkAuthentication,pMem,sizeof(DWORD));
  138. pMem += sizeof(DWORD);
  139. pWirelessPSData->dwNetworkAuthentication = dwNetworkAuthentication;
  140. memcpy((LPBYTE)&dwAutomaticKeyProvision, pMem, sizeof(DWORD));
  141. pMem += sizeof(DWORD);
  142. pWirelessPSData->dwAutomaticKeyProvision = dwAutomaticKeyProvision;
  143. memcpy((LPBYTE)&dwNetworkType, pMem, sizeof(DWORD));
  144. pMem += sizeof(DWORD);
  145. pWirelessPSData->dwNetworkType = dwNetworkType;
  146. memcpy((LPBYTE)&dwEnable8021x, pMem, sizeof(DWORD));
  147. pMem += sizeof(DWORD);
  148. pWirelessPSData->dwEnable8021x = dwEnable8021x;
  149. memcpy((LPBYTE)&dw8021xMode, pMem, sizeof(DWORD));
  150. pMem += sizeof(DWORD);
  151. pWirelessPSData->dw8021xMode = dw8021xMode;
  152. memcpy((LPBYTE)&dwEapType, pMem, sizeof(DWORD));
  153. pMem += sizeof(DWORD);
  154. pWirelessPSData->dwEapType = dwEapType;
  155. memcpy((LPBYTE)&dwEAPDataLen, pMem, sizeof(DWORD));
  156. pMem += sizeof(DWORD);
  157. pWirelessPSData->dwEAPDataLen = dwEAPDataLen;
  158. if (dwEAPDataLen) {
  159. pbEAPData = (LPBYTE)AllocPolMem((dwEAPDataLen));
  160. if (!pbEAPData) {
  161. dwError = ERROR_OUTOFMEMORY;
  162. BAIL_ON_WIN32_ERROR(dwError);
  163. }
  164. memcpy(pbEAPData, pMem, dwEAPDataLen);
  165. }
  166. pWirelessPSData->pbEAPData = pbEAPData;
  167. pMem += dwEAPDataLen;
  168. memcpy((LPBYTE)&dwMachineAuthentication, pMem, sizeof(DWORD));
  169. pMem += sizeof(DWORD);
  170. pWirelessPSData->dwMachineAuthentication = dwMachineAuthentication;
  171. memcpy((LPBYTE)&dwMachineAuthenticationType, pMem, sizeof(DWORD));
  172. pMem += sizeof(DWORD);
  173. pWirelessPSData->dwMachineAuthenticationType = dwMachineAuthenticationType;
  174. memcpy((LPBYTE)&dwGuestAuthentication, pMem, sizeof(DWORD));
  175. pMem += sizeof(DWORD);
  176. pWirelessPSData->dwGuestAuthentication = dwGuestAuthentication;
  177. memcpy((LPBYTE)&dwIEEE8021xMaxStart, pMem, sizeof(DWORD));
  178. pMem += sizeof(DWORD);
  179. pWirelessPSData->dwIEEE8021xMaxStart = dwIEEE8021xMaxStart;
  180. memcpy((LPBYTE)&dwIEEE8021xStartPeriod, pMem, sizeof(DWORD));
  181. pMem += sizeof(DWORD);
  182. pWirelessPSData->dwIEEE8021xStartPeriod = dwIEEE8021xStartPeriod;
  183. memcpy((LPBYTE)&dwIEEE802xAuthPeriod, pMem, sizeof(DWORD));
  184. pMem += sizeof(DWORD);
  185. pWirelessPSData->dwIEEE8021xAuthPeriod = dwIEEE802xAuthPeriod;
  186. memcpy((LPBYTE)&dwIEEE802xHeldPeriod, pMem, sizeof(DWORD));
  187. pMem += sizeof(DWORD);
  188. pWirelessPSData->dwIEEE8021xHeldPeriod = dwIEEE802xHeldPeriod;
  189. memcpy((LPBYTE)&dwDescriptionLen, pMem, sizeof(DWORD));
  190. pMem += sizeof(DWORD);
  191. pWirelessPSData->dwDescriptionLen = dwDescriptionLen;
  192. if (dwDescriptionLen) {
  193. pszDescription = (LPWSTR)AllocPolMem((dwDescriptionLen+1)*sizeof(WCHAR));
  194. if (!pszDescription) {
  195. dwError = ERROR_OUTOFMEMORY;
  196. BAIL_ON_WIN32_ERROR(dwError);
  197. }
  198. memcpy(pszDescription, pMem, dwDescriptionLen*sizeof(WCHAR));
  199. }
  200. pWirelessPSData->pszDescription = pszDescription;
  201. pMem += dwDescriptionLen*sizeof(WCHAR);
  202. // validate here that we didnt cross the delimitter
  203. if (pMem > pMemDelimitter) {
  204. dwError = ERROR_INVALID_PARAMETER;
  205. }
  206. BAIL_ON_WIN32_ERROR(dwError);
  207. *ppWirelessPSData = pWirelessPSData;
  208. *ppMem = pTempMem + dwPSLen;
  209. return(dwError);
  210. error:
  211. if (pWirelessPSData) {
  212. FreeWirelessPSData(pWirelessPSData);
  213. }
  214. *ppWirelessPSData = NULL;
  215. return(dwError);
  216. }
  217. DWORD
  218. UnmarshallWirelessPolicyObject(
  219. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject,
  220. DWORD dwStoreType,
  221. PWIRELESS_POLICY_DATA * ppWirelessPolicyData
  222. )
  223. {
  224. LPBYTE pMem = NULL;
  225. LPBYTE pNMem = NULL;
  226. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  227. PWIRELESS_PS_DATA *ppWirelessPSDatas = NULL;
  228. PWIRELESS_PS_DATA pWirelessPSData = NULL;
  229. DWORD dwPollingInterval = 0;
  230. DWORD dwError = 0;
  231. DWORD dwSkipSize = 0;
  232. DWORD dwDisableZeroConf = 0;
  233. DWORD dwNetworkToAccess = 0;
  234. DWORD dwConnectToNonPreferredNetworks = 0;
  235. DWORD dwNumPreferredSettings = 0;
  236. DWORD dwNumAPNetworks = 0;
  237. DWORD dwFirstAdhoc = 1;
  238. DWORD i = 0;
  239. WORD wMajorVersion = 0;
  240. WORD wMinorVersion = 0;
  241. DWORD dwFound = 0;
  242. DWORD dwWirelessDataLen = 0;
  243. DWORD dwAdvance = 0;
  244. DWORD dwWlBlobLen = 0;
  245. DWORD dwFlags = 0;
  246. DWORD dwBlobAdvance = 0;
  247. LPBYTE pMemDelimitter = NULL;
  248. pWirelessPolicyData = (PWIRELESS_POLICY_DATA)AllocPolMem(
  249. sizeof(WIRELESS_POLICY_DATA)
  250. );
  251. if (!pWirelessPolicyData) {
  252. dwError = ERROR_OUTOFMEMORY;
  253. BAIL_ON_WIN32_ERROR(dwError);
  254. }
  255. if (pWirelessPolicyObject->pszWirelessName && *(pWirelessPolicyObject->pszWirelessName)) {
  256. pWirelessPolicyData->pszWirelessName = AllocPolStr(
  257. pWirelessPolicyObject->pszWirelessName
  258. );
  259. if (!pWirelessPolicyData->pszWirelessName) {
  260. dwError = ERROR_OUTOFMEMORY;
  261. BAIL_ON_WIN32_ERROR(dwError);
  262. }
  263. }
  264. pWirelessPolicyData->pszOldWirelessName = NULL;
  265. if (pWirelessPolicyObject->pszDescription &&
  266. *(pWirelessPolicyObject->pszDescription)){
  267. pWirelessPolicyData->pszDescription = AllocPolStr(
  268. pWirelessPolicyObject->pszDescription
  269. );
  270. if (!pWirelessPolicyData->pszDescription) {
  271. dwError = ERROR_OUTOFMEMORY;
  272. BAIL_ON_WIN32_ERROR(dwError);
  273. }
  274. }
  275. wGUIDFromString(pWirelessPolicyObject->pszWirelessID,
  276. &pWirelessPolicyData->PolicyIdentifier
  277. );
  278. pMem = pWirelessPolicyObject->pWirelessData;
  279. dwWirelessDataLen = pWirelessPolicyObject->dwWirelessDataLen;
  280. //
  281. // Find the start point of our version.
  282. //
  283. pMemDelimitter = pMem + dwWirelessDataLen;
  284. dwAdvance = 0;
  285. while(dwAdvance < dwWirelessDataLen) {
  286. memcpy((LPBYTE)&wMajorVersion, pMem+dwAdvance, sizeof(WORD));
  287. dwAdvance += sizeof(WORD);
  288. memcpy((LPBYTE)&wMinorVersion, pMem+dwAdvance, sizeof(WORD));
  289. dwAdvance += sizeof(WORD);
  290. if ((wMajorVersion == WL_BLOB_MAJOR_VERSION)
  291. && (wMinorVersion == WL_BLOB_MINOR_VERSION))
  292. {
  293. dwFound = 1;
  294. dwBlobAdvance = dwAdvance;
  295. }
  296. else
  297. {
  298. if (
  299. (wMajorVersion > WL_BLOB_MAJOR_VERSION)
  300. ||((wMajorVersion == WL_BLOB_MAJOR_VERSION)
  301. && (wMinorVersion > WL_BLOB_MINOR_VERSION))
  302. )
  303. {
  304. dwFlags = WLSTORE_READONLY;
  305. }
  306. }
  307. memcpy((LPBYTE)&dwWlBlobLen, pMem+dwAdvance, sizeof(DWORD));
  308. dwAdvance += sizeof(DWORD);
  309. dwAdvance += dwWlBlobLen;
  310. }
  311. if (!dwFound) {
  312. dwError = ERROR_INVALID_PARAMETER;
  313. }
  314. BAIL_ON_WIN32_ERROR(dwError);
  315. pMem += dwBlobAdvance;
  316. // read the length
  317. if (pMem + sizeof(DWORD) > pMemDelimitter) {
  318. dwError = ERROR_INVALID_PARAMETER;
  319. }
  320. BAIL_ON_WIN32_ERROR(dwError);
  321. memcpy((LPBYTE)&dwWlBlobLen, pMem, sizeof(DWORD));
  322. pMem += sizeof(DWORD);
  323. if ((pMem + dwWlBlobLen) > pMemDelimitter ) {
  324. dwError = ERROR_INVALID_PARAMETER;
  325. }
  326. BAIL_ON_WIN32_ERROR(dwError);
  327. // Now that we the know a better bound on the delimitter
  328. pMemDelimitter = pMem + dwWlBlobLen;
  329. memcpy((LPBYTE)&dwPollingInterval, pMem, sizeof(DWORD));
  330. pMem += sizeof(DWORD);
  331. memcpy((LPBYTE)&dwDisableZeroConf, pMem, sizeof(DWORD));
  332. pMem += sizeof(DWORD);
  333. memcpy((LPBYTE)&dwNetworkToAccess, pMem, sizeof(DWORD));
  334. pMem += sizeof(DWORD);
  335. memcpy((LPBYTE)&dwConnectToNonPreferredNetworks, pMem, sizeof(DWORD));
  336. pMem += sizeof(DWORD);
  337. memcpy((LPBYTE)&dwNumPreferredSettings, pMem, sizeof(DWORD));
  338. pMem += sizeof(DWORD);
  339. pWirelessPolicyData->dwWhenChanged = pWirelessPolicyObject->dwWhenChanged;
  340. pWirelessPolicyData->dwPollingInterval = dwPollingInterval;
  341. pWirelessPolicyData->dwDisableZeroConf = dwDisableZeroConf;
  342. pWirelessPolicyData->dwNetworkToAccess = dwNetworkToAccess;
  343. pWirelessPolicyData->dwConnectToNonPreferredNtwks =
  344. dwConnectToNonPreferredNetworks;
  345. pWirelessPolicyData->dwFlags = dwFlags;
  346. if (pMem > pMemDelimitter) {
  347. dwError = ERROR_INVALID_PARAMETER;
  348. }
  349. BAIL_ON_WIN32_ERROR(dwError);
  350. if(dwNumPreferredSettings) {
  351. ppWirelessPSDatas =
  352. (PWIRELESS_PS_DATA *)
  353. AllocPolMem(dwNumPreferredSettings*sizeof(PWIRELESS_PS_DATA));
  354. if(!ppWirelessPSDatas) {
  355. dwError = ERROR_OUTOFMEMORY;
  356. BAIL_ON_WIN32_ERROR(dwError);
  357. }
  358. // Read the WirelessPSData now
  359. for(i=0;i<dwNumPreferredSettings;++i) {
  360. dwError = UnmarshallWirelessPSObject(
  361. pMem,
  362. &pWirelessPSData,
  363. &pNMem,
  364. pMemDelimitter
  365. );
  366. BAIL_ON_WIN32_ERROR(dwError);
  367. *(ppWirelessPSDatas+i) = pWirelessPSData;
  368. pMem = pNMem;
  369. if(dwFirstAdhoc) {
  370. if (pWirelessPSData->dwNetworkType ==
  371. WIRELESS_NETWORK_TYPE_ADHOC)
  372. {
  373. dwNumAPNetworks = i;
  374. dwFirstAdhoc = 0;
  375. }
  376. }
  377. }
  378. }
  379. pWirelessPolicyData->ppWirelessPSData = ppWirelessPSDatas;
  380. pWirelessPolicyData->dwNumPreferredSettings =
  381. dwNumPreferredSettings;
  382. if(dwFirstAdhoc) {
  383. dwNumAPNetworks = dwNumPreferredSettings;
  384. }
  385. pWirelessPolicyData->dwNumAPNetworks =
  386. dwNumAPNetworks;
  387. /* WMI RElated */
  388. switch(dwStoreType) {
  389. case WIRELESS_WMI_PROVIDER:
  390. pWirelessPolicyData->pRsopInfo = (PRSOP_INFO)AllocPolMem(
  391. sizeof(RSOP_INFO)
  392. );
  393. if (!pWirelessPolicyData->pRsopInfo) {
  394. dwError = ERROR_OUTOFMEMORY;
  395. BAIL_ON_WIN32_ERROR(dwError);
  396. }
  397. dwError = DeepCpyRsopInfo(
  398. pWirelessPolicyData->pRsopInfo,
  399. pWirelessPolicyObject->pRsopInfo
  400. );
  401. BAIL_ON_WIN32_ERROR(dwError);
  402. // no "break"; do everything we'd do for WIRELESS_REGISTRY_PROVIDER as well.
  403. case WIRELESS_REGISTRY_PROVIDER:
  404. break;
  405. case WIRELESS_DIRECTORY_PROVIDER:
  406. break;
  407. default:
  408. dwError = ERROR_INVALID_PARAMETER;
  409. BAIL_ON_WIN32_ERROR(dwError);
  410. }
  411. *ppWirelessPolicyData = pWirelessPolicyData;
  412. return(0);
  413. error:
  414. if (pWirelessPolicyData) {
  415. FreeWirelessPolicyData(pWirelessPolicyData);
  416. }
  417. *ppWirelessPolicyData = NULL;
  418. return(dwError);
  419. }
  420. DWORD
  421. UpdateWirelessPolicyDataWithPreferredSettings(
  422. PWIRELESS_POLICY_DATA pNewWirelessPolicyData,
  423. PWIRELESS_POLICY_DATA pWirelessPolicyData
  424. )
  425. {
  426. DWORD dwError = 0;
  427. DWORD i = 0;
  428. DWORD j=0;
  429. DWORD dwNumPreferredSettings = 0;
  430. DWORD dwNumAPNetworks = 0;
  431. PWIRELESS_PS_DATA pWirelessPSData;
  432. PWIRELESS_PS_DATA pNewWirelessPSData;
  433. PWIRELESS_PS_DATA *ppNewWirelessPSData;
  434. PWIRELESS_PS_DATA *ppWirelessPSData;
  435. DWORD dwNumToFreePreferredSettings = 0;
  436. PWIRELESS_PS_DATA *ppToFreeWirelessPSData = NULL;
  437. dwNumPreferredSettings =
  438. pWirelessPolicyData->dwNumPreferredSettings;
  439. dwNumAPNetworks =
  440. pWirelessPolicyData->dwNumAPNetworks;
  441. dwNumToFreePreferredSettings =
  442. pNewWirelessPolicyData->dwNumPreferredSettings;
  443. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  444. ppToFreeWirelessPSData = pNewWirelessPolicyData->ppWirelessPSData;
  445. ppNewWirelessPSData = (PWIRELESS_PS_DATA *) AllocPolMem(
  446. dwNumPreferredSettings*sizeof(PWIRELESS_PS_DATA));
  447. if(!ppNewWirelessPSData) {
  448. dwError = ERROR_OUTOFMEMORY;
  449. BAIL_ON_WIN32_ERROR(dwError);
  450. }
  451. for(i=0; i<dwNumPreferredSettings; ++i) {
  452. pNewWirelessPSData = NULL;
  453. dwError = CopyWirelessPSData(
  454. *(ppWirelessPSData+i),
  455. &pNewWirelessPSData
  456. );
  457. BAIL_ON_WIN32_ERROR(dwError);
  458. *(ppNewWirelessPSData+i) = pNewWirelessPSData;
  459. }
  460. pNewWirelessPolicyData->ppWirelessPSData =
  461. ppNewWirelessPSData;
  462. pNewWirelessPolicyData->dwNumPreferredSettings =
  463. dwNumPreferredSettings;
  464. pNewWirelessPolicyData->dwNumAPNetworks =
  465. dwNumAPNetworks;
  466. // Free the Old PS Array now
  467. for(i=0; i < dwNumToFreePreferredSettings; ++i) {
  468. FreeWirelessPSData(ppToFreeWirelessPSData[i]);
  469. }
  470. FreePolMem(ppToFreeWirelessPSData);
  471. return (dwError);
  472. error:
  473. if (ppNewWirelessPSData) {
  474. // Need to free up any of the WirelessPSData that may have been
  475. // Allocated.
  476. for(j=0; j<i ; ++j) {
  477. FreeWirelessPSData(
  478. ppNewWirelessPSData[j]
  479. );
  480. }
  481. // Free up the last one if there.
  482. if(pNewWirelessPSData) {
  483. FreeWirelessPSData(
  484. pNewWirelessPSData
  485. );
  486. }
  487. FreePolMem(ppNewWirelessPSData);
  488. }
  489. return (dwError);
  490. }
  491. DWORD
  492. UpdateWirelessPolicyData(
  493. PWIRELESS_POLICY_DATA pNewWirelessPolicyData,
  494. PWIRELESS_POLICY_DATA pWirelessPolicyData
  495. )
  496. {
  497. DWORD dwError = 0;
  498. DWORD i = 0;
  499. DWORD dwNumPreferredSettings = 0;
  500. DWORD dwNumAPNetworks = 0;
  501. PWIRELESS_PS_DATA pWirelessPSData;
  502. PWIRELESS_PS_DATA pNewWirelessPSData;
  503. PWIRELESS_PS_DATA *ppNewWirelessPSData;
  504. PWIRELESS_PS_DATA *ppWirelessPSData;
  505. DWORD dwNumToFreePreferredSettings = 0;
  506. PWIRELESS_PS_DATA *ppToFreeWirelessPSData = NULL;
  507. pNewWirelessPolicyData->dwPollingInterval =
  508. pWirelessPolicyData->dwPollingInterval;
  509. pNewWirelessPolicyData->dwWhenChanged =
  510. pWirelessPolicyData->dwWhenChanged;
  511. pNewWirelessPolicyData->dwFlags = pWirelessPolicyData->dwFlags;
  512. memcpy(
  513. &(pNewWirelessPolicyData->PolicyIdentifier),
  514. &(pWirelessPolicyData->PolicyIdentifier),
  515. sizeof(GUID)
  516. );
  517. if (pWirelessPolicyData->pszWirelessName &&
  518. *pWirelessPolicyData->pszWirelessName) {
  519. if (pNewWirelessPolicyData->pszWirelessName) {
  520. FreePolStr(pNewWirelessPolicyData->pszWirelessName);
  521. }
  522. pNewWirelessPolicyData->pszWirelessName = AllocPolStr(
  523. pWirelessPolicyData->pszWirelessName
  524. );
  525. if (!pNewWirelessPolicyData->pszWirelessName) {
  526. dwError = ERROR_OUTOFMEMORY;
  527. BAIL_ON_WIN32_ERROR(dwError);
  528. }
  529. }
  530. if (pWirelessPolicyData->pszDescription &&
  531. *pWirelessPolicyData->pszDescription) {
  532. if (pNewWirelessPolicyData->pszDescription) {
  533. FreePolStr(pNewWirelessPolicyData->pszDescription);
  534. }
  535. pNewWirelessPolicyData->pszDescription = AllocPolStr(
  536. pWirelessPolicyData->pszDescription
  537. );
  538. if (!pNewWirelessPolicyData->pszDescription) {
  539. dwError = ERROR_OUTOFMEMORY;
  540. BAIL_ON_WIN32_ERROR(dwError);
  541. }
  542. }
  543. pNewWirelessPolicyData->dwDisableZeroConf =
  544. pWirelessPolicyData->dwDisableZeroConf;
  545. pNewWirelessPolicyData->dwNetworkToAccess =
  546. pWirelessPolicyData->dwNetworkToAccess;
  547. pNewWirelessPolicyData->dwConnectToNonPreferredNtwks =
  548. pWirelessPolicyData->dwConnectToNonPreferredNtwks;
  549. dwNumPreferredSettings =
  550. pWirelessPolicyData->dwNumPreferredSettings;
  551. dwNumAPNetworks =
  552. pWirelessPolicyData->dwNumAPNetworks;
  553. dwNumToFreePreferredSettings =
  554. pNewWirelessPolicyData->dwNumPreferredSettings;
  555. pNewWirelessPolicyData->dwNumPreferredSettings =
  556. dwNumPreferredSettings;
  557. pNewWirelessPolicyData->dwNumAPNetworks =
  558. dwNumAPNetworks;
  559. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  560. ppToFreeWirelessPSData = pNewWirelessPolicyData->ppWirelessPSData;
  561. ppNewWirelessPSData = (PWIRELESS_PS_DATA *) AllocPolMem(
  562. dwNumPreferredSettings*sizeof(PWIRELESS_PS_DATA));
  563. if(!ppNewWirelessPSData) {
  564. dwError = ERROR_OUTOFMEMORY;
  565. BAIL_ON_WIN32_ERROR(dwError);
  566. }
  567. for(i=0; i<dwNumPreferredSettings; ++i) {
  568. pNewWirelessPSData = NULL;
  569. dwError = CopyWirelessPSData(
  570. *(ppWirelessPSData+i),
  571. &pNewWirelessPSData
  572. );
  573. BAIL_ON_WIN32_ERROR(dwError);
  574. *(ppNewWirelessPSData+i) = pNewWirelessPSData;
  575. }
  576. pNewWirelessPolicyData->ppWirelessPSData =
  577. ppNewWirelessPSData;
  578. // Free the Old PS Array now
  579. for(i=0; i < dwNumToFreePreferredSettings; ++i) {
  580. FreeWirelessPSData(ppToFreeWirelessPSData[i]);
  581. }
  582. FreePolMem(ppToFreeWirelessPSData);
  583. return (dwError);
  584. error:
  585. if (ppNewWirelessPSData) {
  586. FreePolMem(ppNewWirelessPSData);
  587. }
  588. return (dwError);
  589. }
  590. DWORD
  591. ModifyWirelessPSData(
  592. PWIRELESS_PS_DATA pNewWirelessPSData,
  593. PWIRELESS_PS_DATA pWirelessPSData
  594. )
  595. {
  596. DWORD dwError = 0;
  597. DWORD dwPSLen = 0;
  598. WCHAR SSID[32];
  599. DWORD dwSize = 0;
  600. DWORD dwWepEnabled=0;
  601. DWORD dwId = 0;
  602. DWORD dwWirelessSSIDLen = 0;
  603. DWORD dwNetworkAuthentication = 0;
  604. DWORD dwAutomaticKeyProvision = 0;
  605. DWORD dwNetworkType = 0;
  606. DWORD dwEnable8021x = 0;
  607. DWORD dw8021xMode = 0;
  608. DWORD dwEapType = 0;
  609. DWORD dwCertificateType = 0;
  610. DWORD dwValidateServerCertificate = 0;
  611. DWORD dwEAPDataLen = 0;
  612. LPBYTE pbEAPData = NULL;
  613. DWORD dwMachineAuthentication = 0;
  614. DWORD dwMachineAuthenticationType = 0;
  615. DWORD dwGuestAuthentication = 0;
  616. DWORD dwIEEE8021xMaxStart = 0;
  617. DWORD dwIEEE8021xStartPeriod = 0;
  618. DWORD dwIEEE8021xAuthPeriod = 0;
  619. DWORD dwIEEE8021xHeldPeriod = 0;
  620. DWORD dwDescriptionLen = 0;
  621. LPWSTR pszDescription = NULL;
  622. if (!pNewWirelessPSData || !pWirelessPSData) {
  623. dwError = -1 ;
  624. BAIL_ON_WIN32_ERROR(dwError);
  625. }
  626. dwPSLen = pWirelessPSData->dwPSLen;
  627. pNewWirelessPSData->dwPSLen = dwPSLen;
  628. memcpy(SSID,pWirelessPSData->pszWirelessSSID,32*2);
  629. memcpy(pNewWirelessPSData->pszWirelessSSID,SSID,32*2);
  630. dwWirelessSSIDLen = pWirelessPSData->dwWirelessSSIDLen;
  631. pNewWirelessPSData->dwWirelessSSIDLen = dwWirelessSSIDLen;
  632. dwWepEnabled = pWirelessPSData->dwWepEnabled;
  633. pNewWirelessPSData->dwWepEnabled = dwWepEnabled;
  634. dwId = pWirelessPSData->dwId;
  635. pNewWirelessPSData->dwId = dwId;
  636. dwNetworkAuthentication = pWirelessPSData->dwNetworkAuthentication;
  637. pNewWirelessPSData->dwNetworkAuthentication = dwNetworkAuthentication;
  638. dwAutomaticKeyProvision = pWirelessPSData->dwAutomaticKeyProvision;
  639. pNewWirelessPSData->dwAutomaticKeyProvision = dwAutomaticKeyProvision;
  640. dwNetworkType = pWirelessPSData->dwNetworkType;
  641. pNewWirelessPSData->dwNetworkType = dwNetworkType;
  642. dwEnable8021x = pWirelessPSData->dwEnable8021x;
  643. pNewWirelessPSData->dwEnable8021x = dwEnable8021x;
  644. dw8021xMode = pWirelessPSData->dw8021xMode;
  645. pNewWirelessPSData->dw8021xMode = dw8021xMode;
  646. dwEapType = pWirelessPSData->dwEapType;
  647. pNewWirelessPSData->dwEapType = dwEapType;
  648. dwEAPDataLen = pWirelessPSData->dwEAPDataLen;
  649. pNewWirelessPSData->dwEAPDataLen = dwEAPDataLen;
  650. pbEAPData = AllocPolMem(dwEAPDataLen);
  651. if (!pbEAPData) {
  652. dwError = ERROR_OUTOFMEMORY;
  653. BAIL_ON_WIN32_ERROR(dwError);
  654. }
  655. memcpy(pbEAPData, pWirelessPSData->pbEAPData, dwEAPDataLen);
  656. FreePolMem(pNewWirelessPSData->pbEAPData);
  657. pNewWirelessPSData->pbEAPData = pbEAPData;
  658. dwMachineAuthentication = pWirelessPSData->dwMachineAuthentication;
  659. pNewWirelessPSData->dwMachineAuthentication = dwMachineAuthentication;
  660. dwMachineAuthenticationType = pWirelessPSData->dwMachineAuthenticationType;
  661. pNewWirelessPSData->dwMachineAuthenticationType =
  662. dwMachineAuthenticationType;
  663. dwGuestAuthentication = pWirelessPSData->dwGuestAuthentication;
  664. pNewWirelessPSData->dwGuestAuthentication = dwGuestAuthentication;
  665. dwIEEE8021xMaxStart = pWirelessPSData->dwIEEE8021xMaxStart;
  666. pNewWirelessPSData->dwIEEE8021xMaxStart = dwIEEE8021xMaxStart;
  667. dwIEEE8021xStartPeriod = pWirelessPSData->dwIEEE8021xStartPeriod;
  668. pNewWirelessPSData->dwIEEE8021xStartPeriod = dwIEEE8021xStartPeriod;
  669. dwIEEE8021xAuthPeriod = pWirelessPSData->dwIEEE8021xAuthPeriod;
  670. pNewWirelessPSData->dwIEEE8021xAuthPeriod = dwIEEE8021xAuthPeriod;
  671. dwIEEE8021xHeldPeriod = pWirelessPSData->dwIEEE8021xHeldPeriod;
  672. pNewWirelessPSData->dwIEEE8021xHeldPeriod = dwIEEE8021xHeldPeriod;
  673. dwDescriptionLen = pWirelessPSData->dwDescriptionLen;
  674. pNewWirelessPSData->dwDescriptionLen = dwDescriptionLen;
  675. pszDescription = AllocPolStr(pWirelessPSData->pszDescription);
  676. if (!pszDescription) {
  677. dwError = ERROR_OUTOFMEMORY;
  678. BAIL_ON_WIN32_ERROR(dwError);
  679. }
  680. FreePolMem(pNewWirelessPSData->pszDescription);
  681. pNewWirelessPSData->pszDescription = pszDescription;
  682. return(dwError);
  683. error:
  684. return(dwError);
  685. }
  686. DWORD
  687. WirelessPSMoveUp(
  688. PWIRELESS_POLICY_DATA pWirelessPolicyData,
  689. DWORD dwIndex
  690. )
  691. {
  692. PWIRELESS_PS_DATA *ppWirelessPSData = NULL;
  693. PWIRELESS_PS_DATA pUpperWirelessPSData = NULL;
  694. PWIRELESS_PS_DATA pLowerWirelessPSData = NULL;
  695. DWORD dwError = 0;
  696. DWORD dwNumPreferredSettings;
  697. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  698. if (!ppWirelessPSData) {
  699. dwError = ERROR_PS_NOT_PRESENT;
  700. BAIL_ON_WIN32_ERROR(dwError);
  701. }
  702. dwNumPreferredSettings = pWirelessPolicyData->dwNumPreferredSettings;
  703. if(dwNumPreferredSettings <= dwIndex) {
  704. dwError = ERROR_PS_NOT_PRESENT;
  705. BAIL_ON_WIN32_ERROR(dwError);
  706. }
  707. pUpperWirelessPSData = ppWirelessPSData[dwIndex];
  708. pLowerWirelessPSData = ppWirelessPSData[dwIndex-1];
  709. if(!(pUpperWirelessPSData && pLowerWirelessPSData)) {
  710. dwError = ERROR_PS_NOT_PRESENT;
  711. BAIL_ON_WIN32_ERROR(dwError);
  712. }
  713. pUpperWirelessPSData->dwId = dwIndex-1;
  714. pLowerWirelessPSData->dwId = dwIndex;
  715. ppWirelessPSData[dwIndex] = pLowerWirelessPSData;
  716. ppWirelessPSData[dwIndex-1] = pUpperWirelessPSData;
  717. return(dwError);
  718. error:
  719. return(dwError);
  720. }
  721. DWORD
  722. WirelessPSMoveDown(
  723. PWIRELESS_POLICY_DATA pWirelessPolicyData,
  724. DWORD dwIndex
  725. )
  726. {
  727. PWIRELESS_PS_DATA *ppWirelessPSData = NULL;
  728. PWIRELESS_PS_DATA pUpperWirelessPSData = NULL;
  729. PWIRELESS_PS_DATA pLowerWirelessPSData = NULL;
  730. DWORD dwError = 0;
  731. DWORD dwNumPreferredSettings;
  732. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  733. if (!ppWirelessPSData) {
  734. dwError = ERROR_PS_NOT_PRESENT;
  735. BAIL_ON_WIN32_ERROR(dwError);
  736. }
  737. dwNumPreferredSettings = pWirelessPolicyData->dwNumPreferredSettings;
  738. if(dwNumPreferredSettings <= dwIndex) {
  739. dwError = ERROR_PS_NOT_PRESENT;
  740. BAIL_ON_WIN32_ERROR(dwError);
  741. }
  742. pUpperWirelessPSData = ppWirelessPSData[dwIndex+1];
  743. pLowerWirelessPSData = ppWirelessPSData[dwIndex];
  744. if(!(pUpperWirelessPSData && pLowerWirelessPSData)) {
  745. dwError = ERROR_PS_NOT_PRESENT;
  746. BAIL_ON_WIN32_ERROR(dwError);
  747. }
  748. pUpperWirelessPSData->dwId = dwIndex;
  749. pLowerWirelessPSData->dwId = dwIndex+1;
  750. ppWirelessPSData[dwIndex] = pUpperWirelessPSData;
  751. ppWirelessPSData[dwIndex+1] = pLowerWirelessPSData;
  752. return(dwError);
  753. error:
  754. return(dwError);
  755. }
  756. DWORD
  757. WirelessSetPSDataInPolicyId(
  758. PWIRELESS_POLICY_DATA pWirelessPolicyData,
  759. PWIRELESS_PS_DATA pWirelessPSData
  760. )
  761. {
  762. DWORD dwError = 0;
  763. DWORD dwPSId;
  764. DWORD dwNumPreferredSettings = 0;
  765. PWIRELESS_PS_DATA pCurrentWirelessPSData = NULL;
  766. PWIRELESS_PS_DATA *ppWirelessPSData = NULL;
  767. PWIRELESS_PS_DATA *ppNewWirelessPSData = NULL;
  768. DWORD dwNumAPNetworks;
  769. DWORD dwNewNumAPNetworks = 0;
  770. DWORD dwNewId = 0;
  771. DWORD i = 0;
  772. if (!(pWirelessPolicyData && pWirelessPSData)) {
  773. dwError = ERROR_PS_NOT_PRESENT;
  774. BAIL_ON_WIN32_ERROR(dwError);
  775. }
  776. dwPSId = pWirelessPSData->dwId;
  777. dwNumPreferredSettings = pWirelessPolicyData->dwNumPreferredSettings;
  778. dwNumAPNetworks = pWirelessPolicyData->dwNumAPNetworks;
  779. if (dwPSId >= dwNumPreferredSettings) {
  780. dwError = ERROR_PS_NOT_PRESENT;
  781. BAIL_ON_WIN32_ERROR(dwError);
  782. }
  783. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  784. pCurrentWirelessPSData = ppWirelessPSData[dwPSId];
  785. if (pCurrentWirelessPSData->dwNetworkType != pWirelessPSData->dwNetworkType) {
  786. ppNewWirelessPSData =
  787. (PWIRELESS_PS_DATA *)
  788. AllocPolMem(sizeof(PWIRELESS_PS_DATA)*dwNumPreferredSettings);
  789. if(ppNewWirelessPSData == NULL) {
  790. dwError = ERROR_OUTOFMEMORY;
  791. BAIL_ON_WIN32_ERROR(dwError);
  792. }
  793. if (pCurrentWirelessPSData->dwNetworkType == WIRELESS_NETWORK_TYPE_AP) {
  794. //AP to Adhoc
  795. for(i=0; i < dwPSId; ++i) {
  796. ppNewWirelessPSData[i] = ppWirelessPSData[i];
  797. }
  798. for(i = dwPSId+1;i<dwNumAPNetworks;++i) {
  799. ppNewWirelessPSData[i-1] = ppWirelessPSData[i];
  800. }
  801. ppNewWirelessPSData[dwNumAPNetworks-1] = ppWirelessPSData[dwPSId];
  802. dwNewId = dwNumAPNetworks-1 ;
  803. dwNewNumAPNetworks = pWirelessPolicyData->dwNumAPNetworks-1;
  804. for(i = dwNumAPNetworks;i<dwNumPreferredSettings;++i) {
  805. ppNewWirelessPSData[i] = ppWirelessPSData[i];
  806. }
  807. } else
  808. {
  809. // Adhoc to AP
  810. for(i=0; i < dwNumAPNetworks; ++i) {
  811. ppNewWirelessPSData[i] = ppWirelessPSData[i];
  812. }
  813. ppNewWirelessPSData[dwNumAPNetworks] = ppWirelessPSData[dwPSId];
  814. dwNewId = dwNumAPNetworks;
  815. dwNewNumAPNetworks = pWirelessPolicyData->dwNumAPNetworks+1;
  816. for(i=dwNumAPNetworks; i < dwPSId; ++i) {
  817. ppNewWirelessPSData[i+1] = ppWirelessPSData[i];
  818. }
  819. for(i=dwPSId+1; i < dwNumPreferredSettings; ++i) {
  820. ppNewWirelessPSData[i] = ppWirelessPSData[i];
  821. }
  822. }
  823. dwError = ModifyWirelessPSData(
  824. ppNewWirelessPSData[dwNewId],
  825. pWirelessPSData
  826. );
  827. BAIL_ON_WIN32_ERROR(dwError);
  828. for(i=0;i<dwNumPreferredSettings;++i)
  829. {
  830. ppNewWirelessPSData[i]->dwId = i;
  831. }
  832. pWirelessPolicyData->ppWirelessPSData = ppNewWirelessPSData;
  833. pWirelessPolicyData->dwNumAPNetworks = dwNewNumAPNetworks;
  834. pWirelessPSData->dwId = dwNewId;
  835. FreePolMem(ppWirelessPSData);
  836. } else {
  837. dwError = ModifyWirelessPSData(
  838. pWirelessPolicyData->ppWirelessPSData[dwPSId],
  839. pWirelessPSData
  840. );
  841. BAIL_ON_WIN32_ERROR(dwError);
  842. }
  843. dwError = ERROR_SUCCESS;
  844. return(dwError);
  845. error:
  846. if (ppNewWirelessPSData) {
  847. FreePolMem(ppNewWirelessPSData);
  848. }
  849. return(dwError);
  850. }
  851. DWORD
  852. CopyWirelessPolicyData(
  853. PWIRELESS_POLICY_DATA pWirelessPolicyData,
  854. PWIRELESS_POLICY_DATA * ppWirelessPolicyData
  855. )
  856. {
  857. DWORD dwError = 0;
  858. PWIRELESS_POLICY_DATA pNewWirelessPolicyData = NULL;
  859. DWORD i = 0;
  860. DWORD dwNumPreferredSettings = 0;
  861. DWORD dwNumAPNetworks = 0;
  862. PWIRELESS_PS_DATA pWirelessPSData;
  863. PWIRELESS_PS_DATA pNewWirelessPSData;
  864. PWIRELESS_PS_DATA *ppNewWirelessPSData;
  865. PWIRELESS_PS_DATA *ppWirelessPSData;
  866. *ppWirelessPolicyData = NULL;
  867. pNewWirelessPolicyData = (PWIRELESS_POLICY_DATA) AllocPolMem(
  868. sizeof(WIRELESS_POLICY_DATA)
  869. );
  870. if (!pNewWirelessPolicyData) {
  871. dwError = ERROR_OUTOFMEMORY;
  872. BAIL_ON_WIN32_ERROR(dwError);
  873. }
  874. pNewWirelessPolicyData->dwPollingInterval =
  875. pWirelessPolicyData->dwPollingInterval;
  876. pNewWirelessPolicyData->dwWhenChanged =
  877. pWirelessPolicyData->dwWhenChanged;
  878. pNewWirelessPolicyData->dwFlags = pWirelessPolicyData->dwFlags;
  879. memcpy(
  880. &(pNewWirelessPolicyData->PolicyIdentifier),
  881. &(pWirelessPolicyData->PolicyIdentifier),
  882. sizeof(GUID)
  883. );
  884. if (pWirelessPolicyData->pszWirelessName &&
  885. *pWirelessPolicyData->pszWirelessName) {
  886. pNewWirelessPolicyData->pszWirelessName =
  887. AllocPolStr(
  888. pWirelessPolicyData->pszWirelessName
  889. );
  890. if (!pNewWirelessPolicyData->pszWirelessName) {
  891. dwError = ERROR_OUTOFMEMORY;
  892. BAIL_ON_WIN32_ERROR(dwError);
  893. }
  894. }
  895. if (pWirelessPolicyData->pszOldWirelessName &&
  896. *pWirelessPolicyData->pszOldWirelessName) {
  897. pNewWirelessPolicyData->pszOldWirelessName =
  898. AllocPolStr(
  899. pWirelessPolicyData->pszOldWirelessName
  900. );
  901. if (!pNewWirelessPolicyData->pszOldWirelessName) {
  902. dwError = ERROR_OUTOFMEMORY;
  903. BAIL_ON_WIN32_ERROR(dwError);
  904. }
  905. }
  906. if (pWirelessPolicyData->pszDescription &&
  907. *pWirelessPolicyData->pszDescription) {
  908. pNewWirelessPolicyData->pszDescription = AllocPolStr(
  909. pWirelessPolicyData->pszDescription
  910. );
  911. if (!pNewWirelessPolicyData->pszDescription) {
  912. dwError = ERROR_OUTOFMEMORY;
  913. BAIL_ON_WIN32_ERROR(dwError);
  914. }
  915. }
  916. pNewWirelessPolicyData->dwDisableZeroConf =
  917. pWirelessPolicyData->dwDisableZeroConf;
  918. pNewWirelessPolicyData->wMajorVersion =
  919. pWirelessPolicyData->wMajorVersion;
  920. pNewWirelessPolicyData->wMinorVersion =
  921. pWirelessPolicyData->wMinorVersion;
  922. pNewWirelessPolicyData->dwNetworkToAccess =
  923. pWirelessPolicyData->dwNetworkToAccess;
  924. pNewWirelessPolicyData->dwConnectToNonPreferredNtwks =
  925. pWirelessPolicyData->dwConnectToNonPreferredNtwks;
  926. dwNumPreferredSettings =
  927. pWirelessPolicyData->dwNumPreferredSettings;
  928. dwNumAPNetworks =
  929. pWirelessPolicyData->dwNumAPNetworks;
  930. pNewWirelessPolicyData->dwNumPreferredSettings =
  931. dwNumPreferredSettings;
  932. pNewWirelessPolicyData->dwNumAPNetworks =
  933. dwNumAPNetworks;
  934. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  935. ppNewWirelessPSData = (PWIRELESS_PS_DATA *) AllocPolMem(
  936. dwNumPreferredSettings*sizeof(PWIRELESS_PS_DATA));
  937. if(!ppNewWirelessPSData) {
  938. dwError = ERROR_OUTOFMEMORY;
  939. BAIL_ON_WIN32_ERROR(dwError);
  940. }
  941. for(i=0; i<dwNumPreferredSettings; ++i) {
  942. pNewWirelessPSData = NULL;
  943. dwError = CopyWirelessPSData(
  944. *(ppWirelessPSData+i),
  945. &pNewWirelessPSData
  946. );
  947. BAIL_ON_WIN32_ERROR(dwError);
  948. *(ppNewWirelessPSData+i) = pNewWirelessPSData;
  949. }
  950. pNewWirelessPolicyData->ppWirelessPSData =
  951. ppNewWirelessPSData;
  952. if (pWirelessPolicyData->pRsopInfo) {
  953. pNewWirelessPolicyData->pRsopInfo = (PRSOP_INFO)AllocPolMem(
  954. sizeof(RSOP_INFO)
  955. );
  956. if (!pNewWirelessPolicyData->pRsopInfo) {
  957. dwError = ERROR_OUTOFMEMORY;
  958. BAIL_ON_WIN32_ERROR(dwError);
  959. }
  960. dwError = DeepCpyRsopInfo(
  961. pNewWirelessPolicyData->pRsopInfo,
  962. pWirelessPolicyData->pRsopInfo
  963. );
  964. BAIL_ON_WIN32_ERROR(dwError);
  965. }
  966. *ppWirelessPolicyData = pNewWirelessPolicyData;
  967. return (dwError);
  968. error:
  969. if (pNewWirelessPolicyData) {
  970. FreeWirelessPolicyData(pNewWirelessPolicyData);
  971. }
  972. *ppWirelessPolicyData = NULL;
  973. return (dwError);
  974. }
  975. DWORD
  976. CopyWirelessPSData(
  977. PWIRELESS_PS_DATA pWirelessPSData,
  978. PWIRELESS_PS_DATA *ppWirelessPSData
  979. )
  980. {
  981. PWIRELESS_PS_DATA pNewWirelessPSData = NULL;
  982. DWORD dwError = 0;
  983. DWORD dwPSLen = 0;
  984. WCHAR SSID[32];
  985. DWORD dwSize = 0;
  986. DWORD dwWepEnabled=0;
  987. DWORD dwId = 0;
  988. DWORD dwWirelessSSIDLen = 0;
  989. DWORD dwNetworkAuthentication = 0;
  990. DWORD dwAutomaticKeyProvision = 0;
  991. DWORD dwNetworkType = 0;
  992. DWORD dwEnable8021x = 0;
  993. DWORD dw8021xMode = 0;
  994. DWORD dwEapType = 0;
  995. DWORD dwCertificateType = 0;
  996. DWORD dwValidateServerCertificate = 0;
  997. DWORD dwEAPDataLen = 0;
  998. LPBYTE pbEAPData = NULL;
  999. DWORD dwMachineAuthentication = 0;
  1000. DWORD dwMachineAuthenticationType = 0;
  1001. DWORD dwGuestAuthentication = 0;
  1002. DWORD dwIEEE8021xMaxStart = 0;
  1003. DWORD dwIEEE8021xStartPeriod = 0;
  1004. DWORD dwIEEE8021xAuthPeriod = 0;
  1005. DWORD dwIEEE8021xHeldPeriod = 0;
  1006. DWORD dwDescriptionLen = 0;
  1007. LPWSTR pszDescription = NULL;
  1008. pNewWirelessPSData = (PWIRELESS_PS_DATA) AllocPolMem(
  1009. sizeof(WIRELESS_PS_DATA)
  1010. );
  1011. if (!pNewWirelessPSData) {
  1012. dwError = ERROR_OUTOFMEMORY;
  1013. BAIL_ON_WIN32_ERROR(dwError);
  1014. }
  1015. dwPSLen = pWirelessPSData->dwPSLen;
  1016. pNewWirelessPSData->dwPSLen = dwPSLen;
  1017. memcpy(SSID,pWirelessPSData->pszWirelessSSID,32*2);
  1018. memcpy(pNewWirelessPSData->pszWirelessSSID,SSID,32*2);
  1019. dwWirelessSSIDLen = pWirelessPSData->dwWirelessSSIDLen;
  1020. pNewWirelessPSData->dwWirelessSSIDLen = dwWirelessSSIDLen;
  1021. dwWepEnabled = pWirelessPSData->dwWepEnabled;
  1022. pNewWirelessPSData->dwWepEnabled = dwWepEnabled;
  1023. dwId = pWirelessPSData->dwId;
  1024. pNewWirelessPSData->dwId = dwId;
  1025. dwNetworkAuthentication = pWirelessPSData->dwNetworkAuthentication;
  1026. pNewWirelessPSData->dwNetworkAuthentication = dwNetworkAuthentication;
  1027. dwAutomaticKeyProvision = pWirelessPSData->dwAutomaticKeyProvision;
  1028. pNewWirelessPSData->dwAutomaticKeyProvision = dwAutomaticKeyProvision;
  1029. dwNetworkType = pWirelessPSData->dwNetworkType;
  1030. pNewWirelessPSData->dwNetworkType = dwNetworkType;
  1031. dwEnable8021x = pWirelessPSData->dwEnable8021x;
  1032. pNewWirelessPSData->dwEnable8021x = dwEnable8021x;
  1033. dw8021xMode = pWirelessPSData->dw8021xMode;
  1034. pNewWirelessPSData->dw8021xMode = dw8021xMode;
  1035. dwEapType = pWirelessPSData->dwEapType;
  1036. pNewWirelessPSData->dwEapType = dwEapType;
  1037. dwEAPDataLen = pWirelessPSData->dwEAPDataLen;
  1038. pNewWirelessPSData->dwEAPDataLen = dwEAPDataLen;
  1039. if (dwEAPDataLen && (pWirelessPSData->pbEAPData)) {
  1040. pbEAPData = AllocPolMem(dwEAPDataLen);
  1041. if (!pbEAPData) {
  1042. dwError = ERROR_OUTOFMEMORY;
  1043. BAIL_ON_WIN32_ERROR(dwError);
  1044. }
  1045. memcpy(pbEAPData, pWirelessPSData->pbEAPData, dwEAPDataLen);
  1046. }
  1047. pNewWirelessPSData->pbEAPData = pbEAPData;
  1048. dwMachineAuthentication = pWirelessPSData->dwMachineAuthentication;
  1049. pNewWirelessPSData->dwMachineAuthentication = dwMachineAuthentication;
  1050. dwMachineAuthenticationType =
  1051. pWirelessPSData->dwMachineAuthenticationType;
  1052. pNewWirelessPSData->dwMachineAuthenticationType =
  1053. dwMachineAuthenticationType;
  1054. dwGuestAuthentication = pWirelessPSData->dwGuestAuthentication;
  1055. pNewWirelessPSData->dwGuestAuthentication = dwGuestAuthentication;
  1056. dwIEEE8021xMaxStart = pWirelessPSData->dwIEEE8021xMaxStart;
  1057. pNewWirelessPSData->dwIEEE8021xMaxStart = dwIEEE8021xMaxStart;
  1058. dwIEEE8021xStartPeriod = pWirelessPSData->dwIEEE8021xStartPeriod;
  1059. pNewWirelessPSData->dwIEEE8021xStartPeriod = dwIEEE8021xStartPeriod;
  1060. dwIEEE8021xAuthPeriod = pWirelessPSData->dwIEEE8021xAuthPeriod;
  1061. pNewWirelessPSData->dwIEEE8021xAuthPeriod = dwIEEE8021xAuthPeriod;
  1062. dwIEEE8021xHeldPeriod = pWirelessPSData->dwIEEE8021xHeldPeriod;
  1063. pNewWirelessPSData->dwIEEE8021xHeldPeriod = dwIEEE8021xHeldPeriod;
  1064. dwDescriptionLen = pWirelessPSData->dwDescriptionLen;
  1065. pNewWirelessPSData->dwDescriptionLen = dwDescriptionLen;
  1066. if ((pWirelessPSData->pszDescription) && *(pWirelessPSData->pszDescription)) {
  1067. pszDescription = AllocPolStr(pWirelessPSData->pszDescription);
  1068. if (!pszDescription) {
  1069. dwError = ERROR_OUTOFMEMORY;
  1070. BAIL_ON_WIN32_ERROR(dwError);
  1071. }
  1072. }
  1073. pNewWirelessPSData->pszDescription = pszDescription;
  1074. *ppWirelessPSData = pNewWirelessPSData;
  1075. return(dwError);
  1076. error:
  1077. FreeWirelessPSData(pNewWirelessPSData);
  1078. return(dwError);
  1079. }
  1080. void
  1081. FreeMulWirelessPolicyData(
  1082. PWIRELESS_POLICY_DATA * ppWirelessPolicyData,
  1083. DWORD dwNumPolicyObjects
  1084. )
  1085. {
  1086. DWORD i = 0;
  1087. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  1088. if (!ppWirelessPolicyData) {
  1089. return;
  1090. }
  1091. for (i = 0; i < dwNumPolicyObjects; i++) {
  1092. pWirelessPolicyData = *(ppWirelessPolicyData + i);
  1093. if (pWirelessPolicyData) {
  1094. FreeWirelessPolicyData(pWirelessPolicyData);
  1095. }
  1096. }
  1097. FreePolMem(ppWirelessPolicyData);
  1098. return;
  1099. }
  1100. void
  1101. FreeWirelessPSData(
  1102. PWIRELESS_PS_DATA pWirelessPSData
  1103. )
  1104. {
  1105. if (!pWirelessPSData)
  1106. return;
  1107. if (pWirelessPSData->pbEAPData) {
  1108. FreePolMem(pWirelessPSData->pbEAPData);
  1109. }
  1110. if (pWirelessPSData->pszDescription) {
  1111. FreePolStr(pWirelessPSData->pszDescription);
  1112. }
  1113. FreePolMem(pWirelessPSData);
  1114. return;
  1115. }
  1116. void
  1117. FreeWirelessPolicyData(
  1118. PWIRELESS_POLICY_DATA pWirelessPolicyData
  1119. )
  1120. {
  1121. DWORD i = 0;
  1122. DWORD dwNumPSCount = 0;
  1123. PWIRELESS_PS_DATA *ppWirelessPSDatas = NULL;
  1124. PWIRELESS_PS_DATA pWirelessPSData = NULL;
  1125. if (!pWirelessPolicyData)
  1126. return;
  1127. if (pWirelessPolicyData->pszWirelessName) {
  1128. FreePolStr(pWirelessPolicyData->pszWirelessName);
  1129. }
  1130. if (pWirelessPolicyData->pszOldWirelessName) {
  1131. FreePolStr(pWirelessPolicyData->pszOldWirelessName);
  1132. }
  1133. if (pWirelessPolicyData->pszDescription) {
  1134. FreePolStr(pWirelessPolicyData->pszDescription);
  1135. }
  1136. ppWirelessPSDatas = pWirelessPolicyData->ppWirelessPSData;
  1137. if (ppWirelessPSDatas) {
  1138. dwNumPSCount = pWirelessPolicyData->dwNumPreferredSettings;
  1139. for(i = 0; i < dwNumPSCount ; ++i) {
  1140. pWirelessPSData = *(ppWirelessPSDatas+i);
  1141. FreeWirelessPSData(pWirelessPSData);
  1142. }
  1143. FreePolMem(ppWirelessPSDatas);
  1144. }
  1145. if (pWirelessPolicyData->pRsopInfo) {
  1146. FreeRsopInfo(
  1147. pWirelessPolicyData->pRsopInfo
  1148. );
  1149. }
  1150. FreePolMem(pWirelessPolicyData);
  1151. return;
  1152. }
  1153. void
  1154. FreeRsopInfo(
  1155. PRSOP_INFO pRsopInfo
  1156. )
  1157. {
  1158. if (pRsopInfo) {
  1159. FreePolStr(pRsopInfo->pszCreationtime);
  1160. FreePolStr(pRsopInfo->pszID);
  1161. FreePolStr(pRsopInfo->pszName);
  1162. FreePolStr(pRsopInfo->pszGPOID);
  1163. FreePolStr(pRsopInfo->pszSOMID);
  1164. }
  1165. }