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.

1450 lines
42 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. UpdateWirelessPolicyData(
  422. PWIRELESS_POLICY_DATA pNewWirelessPolicyData,
  423. PWIRELESS_POLICY_DATA pWirelessPolicyData
  424. )
  425. {
  426. DWORD dwError = 0;
  427. DWORD i = 0;
  428. DWORD dwNumPreferredSettings = 0;
  429. DWORD dwNumAPNetworks = 0;
  430. PWIRELESS_PS_DATA pWirelessPSData;
  431. PWIRELESS_PS_DATA pNewWirelessPSData;
  432. PWIRELESS_PS_DATA *ppNewWirelessPSData;
  433. PWIRELESS_PS_DATA *ppWirelessPSData;
  434. DWORD dwNumToFreePreferredSettings = 0;
  435. PWIRELESS_PS_DATA *ppToFreeWirelessPSData = NULL;
  436. pNewWirelessPolicyData->dwPollingInterval =
  437. pWirelessPolicyData->dwPollingInterval;
  438. pNewWirelessPolicyData->dwWhenChanged =
  439. pWirelessPolicyData->dwWhenChanged;
  440. pNewWirelessPolicyData->dwFlags = pWirelessPolicyData->dwFlags;
  441. memcpy(
  442. &(pNewWirelessPolicyData->PolicyIdentifier),
  443. &(pWirelessPolicyData->PolicyIdentifier),
  444. sizeof(GUID)
  445. );
  446. if (pWirelessPolicyData->pszWirelessName &&
  447. *pWirelessPolicyData->pszWirelessName) {
  448. if (pNewWirelessPolicyData->pszWirelessName) {
  449. FreePolStr(pNewWirelessPolicyData->pszWirelessName);
  450. }
  451. pNewWirelessPolicyData->pszWirelessName = AllocPolStr(
  452. pWirelessPolicyData->pszWirelessName
  453. );
  454. if (!pNewWirelessPolicyData->pszWirelessName) {
  455. dwError = ERROR_OUTOFMEMORY;
  456. BAIL_ON_WIN32_ERROR(dwError);
  457. }
  458. }
  459. if (pWirelessPolicyData->pszDescription &&
  460. *pWirelessPolicyData->pszDescription) {
  461. if (pNewWirelessPolicyData->pszDescription) {
  462. FreePolStr(pNewWirelessPolicyData->pszDescription);
  463. }
  464. pNewWirelessPolicyData->pszDescription = AllocPolStr(
  465. pWirelessPolicyData->pszDescription
  466. );
  467. if (!pNewWirelessPolicyData->pszDescription) {
  468. dwError = ERROR_OUTOFMEMORY;
  469. BAIL_ON_WIN32_ERROR(dwError);
  470. }
  471. }
  472. pNewWirelessPolicyData->dwDisableZeroConf =
  473. pWirelessPolicyData->dwDisableZeroConf;
  474. pNewWirelessPolicyData->dwNetworkToAccess =
  475. pWirelessPolicyData->dwNetworkToAccess;
  476. pNewWirelessPolicyData->dwConnectToNonPreferredNtwks =
  477. pWirelessPolicyData->dwConnectToNonPreferredNtwks;
  478. dwNumPreferredSettings =
  479. pWirelessPolicyData->dwNumPreferredSettings;
  480. dwNumAPNetworks =
  481. pWirelessPolicyData->dwNumAPNetworks;
  482. dwNumToFreePreferredSettings =
  483. pNewWirelessPolicyData->dwNumPreferredSettings;
  484. pNewWirelessPolicyData->dwNumPreferredSettings =
  485. dwNumPreferredSettings;
  486. pNewWirelessPolicyData->dwNumAPNetworks =
  487. dwNumAPNetworks;
  488. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  489. ppToFreeWirelessPSData = pNewWirelessPolicyData->ppWirelessPSData;
  490. ppNewWirelessPSData = (PWIRELESS_PS_DATA *) AllocPolMem(
  491. dwNumPreferredSettings*sizeof(PWIRELESS_PS_DATA));
  492. if(!ppNewWirelessPSData) {
  493. dwError = ERROR_OUTOFMEMORY;
  494. BAIL_ON_WIN32_ERROR(dwError);
  495. }
  496. for(i=0; i<dwNumPreferredSettings; ++i) {
  497. pNewWirelessPSData = NULL;
  498. dwError = CopyWirelessPSData(
  499. *(ppWirelessPSData+i),
  500. &pNewWirelessPSData
  501. );
  502. BAIL_ON_WIN32_ERROR(dwError);
  503. *(ppNewWirelessPSData+i) = pNewWirelessPSData;
  504. }
  505. pNewWirelessPolicyData->ppWirelessPSData =
  506. ppNewWirelessPSData;
  507. // Free the Old PS Array now
  508. for(i=0; i < dwNumToFreePreferredSettings; ++i) {
  509. FreeWirelessPSData(ppToFreeWirelessPSData[i]);
  510. }
  511. FreePolMem(ppToFreeWirelessPSData);
  512. return (dwError);
  513. error:
  514. if (ppNewWirelessPSData) {
  515. FreePolMem(ppNewWirelessPSData);
  516. }
  517. return (dwError);
  518. }
  519. DWORD
  520. ModifyWirelessPSData(
  521. PWIRELESS_PS_DATA pNewWirelessPSData,
  522. PWIRELESS_PS_DATA pWirelessPSData
  523. )
  524. {
  525. DWORD dwError = 0;
  526. DWORD dwPSLen = 0;
  527. WCHAR SSID[32];
  528. DWORD dwSize = 0;
  529. DWORD dwWepEnabled=0;
  530. DWORD dwId = 0;
  531. DWORD dwWirelessSSIDLen = 0;
  532. DWORD dwNetworkAuthentication = 0;
  533. DWORD dwAutomaticKeyProvision = 0;
  534. DWORD dwNetworkType = 0;
  535. DWORD dwEnable8021x = 0;
  536. DWORD dw8021xMode = 0;
  537. DWORD dwEapType = 0;
  538. DWORD dwCertificateType = 0;
  539. DWORD dwValidateServerCertificate = 0;
  540. DWORD dwEAPDataLen = 0;
  541. LPBYTE pbEAPData = NULL;
  542. DWORD dwMachineAuthentication = 0;
  543. DWORD dwMachineAuthenticationType = 0;
  544. DWORD dwGuestAuthentication = 0;
  545. DWORD dwIEEE8021xMaxStart = 0;
  546. DWORD dwIEEE8021xStartPeriod = 0;
  547. DWORD dwIEEE8021xAuthPeriod = 0;
  548. DWORD dwIEEE8021xHeldPeriod = 0;
  549. DWORD dwDescriptionLen = 0;
  550. LPWSTR pszDescription = NULL;
  551. if (!pNewWirelessPSData || !pWirelessPSData) {
  552. dwError = -1 ;
  553. BAIL_ON_WIN32_ERROR(dwError);
  554. }
  555. dwPSLen = pWirelessPSData->dwPSLen;
  556. pNewWirelessPSData->dwPSLen = dwPSLen;
  557. memcpy(SSID,pWirelessPSData->pszWirelessSSID,32*2);
  558. memcpy(pNewWirelessPSData->pszWirelessSSID,SSID,32*2);
  559. dwWirelessSSIDLen = pWirelessPSData->dwWirelessSSIDLen;
  560. pNewWirelessPSData->dwWirelessSSIDLen = dwWirelessSSIDLen;
  561. dwWepEnabled = pWirelessPSData->dwWepEnabled;
  562. pNewWirelessPSData->dwWepEnabled = dwWepEnabled;
  563. dwId = pWirelessPSData->dwId;
  564. pNewWirelessPSData->dwId = dwId;
  565. dwNetworkAuthentication = pWirelessPSData->dwNetworkAuthentication;
  566. pNewWirelessPSData->dwNetworkAuthentication = dwNetworkAuthentication;
  567. dwAutomaticKeyProvision = pWirelessPSData->dwAutomaticKeyProvision;
  568. pNewWirelessPSData->dwAutomaticKeyProvision = dwAutomaticKeyProvision;
  569. dwNetworkType = pWirelessPSData->dwNetworkType;
  570. pNewWirelessPSData->dwNetworkType = dwNetworkType;
  571. dwEnable8021x = pWirelessPSData->dwEnable8021x;
  572. pNewWirelessPSData->dwEnable8021x = dwEnable8021x;
  573. dw8021xMode = pWirelessPSData->dw8021xMode;
  574. pNewWirelessPSData->dw8021xMode = dw8021xMode;
  575. dwEapType = pWirelessPSData->dwEapType;
  576. pNewWirelessPSData->dwEapType = dwEapType;
  577. dwEAPDataLen = pWirelessPSData->dwEAPDataLen;
  578. pNewWirelessPSData->dwEAPDataLen = dwEAPDataLen;
  579. pbEAPData = AllocPolMem(dwEAPDataLen);
  580. if (!pbEAPData) {
  581. dwError = ERROR_OUTOFMEMORY;
  582. BAIL_ON_WIN32_ERROR(dwError);
  583. }
  584. memcpy(pbEAPData, pWirelessPSData->pbEAPData, dwEAPDataLen);
  585. FreePolMem(pNewWirelessPSData->pbEAPData);
  586. pNewWirelessPSData->pbEAPData = pbEAPData;
  587. dwMachineAuthentication = pWirelessPSData->dwMachineAuthentication;
  588. pNewWirelessPSData->dwMachineAuthentication = dwMachineAuthentication;
  589. dwMachineAuthenticationType = pWirelessPSData->dwMachineAuthenticationType;
  590. pNewWirelessPSData->dwMachineAuthenticationType =
  591. dwMachineAuthenticationType;
  592. dwGuestAuthentication = pWirelessPSData->dwGuestAuthentication;
  593. pNewWirelessPSData->dwGuestAuthentication = dwGuestAuthentication;
  594. dwIEEE8021xMaxStart = pWirelessPSData->dwIEEE8021xMaxStart;
  595. pNewWirelessPSData->dwIEEE8021xMaxStart = dwIEEE8021xMaxStart;
  596. dwIEEE8021xStartPeriod = pWirelessPSData->dwIEEE8021xStartPeriod;
  597. pNewWirelessPSData->dwIEEE8021xStartPeriod = dwIEEE8021xStartPeriod;
  598. dwIEEE8021xAuthPeriod = pWirelessPSData->dwIEEE8021xAuthPeriod;
  599. pNewWirelessPSData->dwIEEE8021xAuthPeriod = dwIEEE8021xAuthPeriod;
  600. dwIEEE8021xHeldPeriod = pWirelessPSData->dwIEEE8021xHeldPeriod;
  601. pNewWirelessPSData->dwIEEE8021xHeldPeriod = dwIEEE8021xHeldPeriod;
  602. dwDescriptionLen = pWirelessPSData->dwDescriptionLen;
  603. pNewWirelessPSData->dwDescriptionLen = dwDescriptionLen;
  604. pszDescription = AllocPolStr(pWirelessPSData->pszDescription);
  605. if (!pszDescription) {
  606. dwError = ERROR_OUTOFMEMORY;
  607. BAIL_ON_WIN32_ERROR(dwError);
  608. }
  609. FreePolMem(pNewWirelessPSData->pszDescription);
  610. pNewWirelessPSData->pszDescription = pszDescription;
  611. return(dwError);
  612. error:
  613. return(dwError);
  614. }
  615. DWORD
  616. WirelessPSMoveUp(
  617. PWIRELESS_POLICY_DATA pWirelessPolicyData,
  618. DWORD dwIndex
  619. )
  620. {
  621. PWIRELESS_PS_DATA *ppWirelessPSData = NULL;
  622. PWIRELESS_PS_DATA pUpperWirelessPSData = NULL;
  623. PWIRELESS_PS_DATA pLowerWirelessPSData = NULL;
  624. DWORD dwError = 0;
  625. DWORD dwNumPreferredSettings;
  626. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  627. if (!ppWirelessPSData) {
  628. dwError = ERROR_PS_NOT_PRESENT;
  629. BAIL_ON_WIN32_ERROR(dwError);
  630. }
  631. dwNumPreferredSettings = pWirelessPolicyData->dwNumPreferredSettings;
  632. if(dwNumPreferredSettings <= dwIndex) {
  633. dwError = ERROR_PS_NOT_PRESENT;
  634. BAIL_ON_WIN32_ERROR(dwError);
  635. }
  636. pUpperWirelessPSData = ppWirelessPSData[dwIndex];
  637. pLowerWirelessPSData = ppWirelessPSData[dwIndex-1];
  638. if(!(pUpperWirelessPSData && pLowerWirelessPSData)) {
  639. dwError = ERROR_PS_NOT_PRESENT;
  640. BAIL_ON_WIN32_ERROR(dwError);
  641. }
  642. pUpperWirelessPSData->dwId = dwIndex-1;
  643. pLowerWirelessPSData->dwId = dwIndex;
  644. ppWirelessPSData[dwIndex] = pLowerWirelessPSData;
  645. ppWirelessPSData[dwIndex-1] = pUpperWirelessPSData;
  646. return(dwError);
  647. error:
  648. return(dwError);
  649. }
  650. DWORD
  651. WirelessPSMoveDown(
  652. PWIRELESS_POLICY_DATA pWirelessPolicyData,
  653. DWORD dwIndex
  654. )
  655. {
  656. PWIRELESS_PS_DATA *ppWirelessPSData = NULL;
  657. PWIRELESS_PS_DATA pUpperWirelessPSData = NULL;
  658. PWIRELESS_PS_DATA pLowerWirelessPSData = NULL;
  659. DWORD dwError = 0;
  660. DWORD dwNumPreferredSettings;
  661. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  662. if (!ppWirelessPSData) {
  663. dwError = ERROR_PS_NOT_PRESENT;
  664. BAIL_ON_WIN32_ERROR(dwError);
  665. }
  666. dwNumPreferredSettings = pWirelessPolicyData->dwNumPreferredSettings;
  667. if(dwNumPreferredSettings <= dwIndex) {
  668. dwError = ERROR_PS_NOT_PRESENT;
  669. BAIL_ON_WIN32_ERROR(dwError);
  670. }
  671. pUpperWirelessPSData = ppWirelessPSData[dwIndex+1];
  672. pLowerWirelessPSData = ppWirelessPSData[dwIndex];
  673. if(!(pUpperWirelessPSData && pLowerWirelessPSData)) {
  674. dwError = ERROR_PS_NOT_PRESENT;
  675. BAIL_ON_WIN32_ERROR(dwError);
  676. }
  677. pUpperWirelessPSData->dwId = dwIndex;
  678. pLowerWirelessPSData->dwId = dwIndex+1;
  679. ppWirelessPSData[dwIndex] = pUpperWirelessPSData;
  680. ppWirelessPSData[dwIndex+1] = pLowerWirelessPSData;
  681. return(dwError);
  682. error:
  683. return(dwError);
  684. }
  685. DWORD
  686. WirelessSetPSDataInPolicyId(
  687. PWIRELESS_POLICY_DATA pWirelessPolicyData,
  688. PWIRELESS_PS_DATA pWirelessPSData
  689. )
  690. {
  691. DWORD dwError = 0;
  692. DWORD dwPSId;
  693. DWORD dwNumPreferredSettings = 0;
  694. PWIRELESS_PS_DATA pCurrentWirelessPSData = NULL;
  695. PWIRELESS_PS_DATA *ppWirelessPSData = NULL;
  696. PWIRELESS_PS_DATA *ppNewWirelessPSData = NULL;
  697. DWORD dwNumAPNetworks;
  698. DWORD dwNewNumAPNetworks = 0;
  699. DWORD dwNewId = 0;
  700. DWORD i = 0;
  701. if (!(pWirelessPolicyData && pWirelessPSData)) {
  702. dwError = ERROR_PS_NOT_PRESENT;
  703. BAIL_ON_WIN32_ERROR(dwError);
  704. }
  705. dwPSId = pWirelessPSData->dwId;
  706. dwNumPreferredSettings = pWirelessPolicyData->dwNumPreferredSettings;
  707. dwNumAPNetworks = pWirelessPolicyData->dwNumAPNetworks;
  708. if (dwPSId >= dwNumPreferredSettings) {
  709. dwError = ERROR_PS_NOT_PRESENT;
  710. BAIL_ON_WIN32_ERROR(dwError);
  711. }
  712. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  713. pCurrentWirelessPSData = ppWirelessPSData[dwPSId];
  714. if (pCurrentWirelessPSData->dwNetworkType != pWirelessPSData->dwNetworkType) {
  715. ppNewWirelessPSData =
  716. (PWIRELESS_PS_DATA *)
  717. AllocPolMem(sizeof(PWIRELESS_PS_DATA)*dwNumPreferredSettings);
  718. if(ppNewWirelessPSData == NULL) {
  719. dwError = ERROR_OUTOFMEMORY;
  720. BAIL_ON_WIN32_ERROR(dwError);
  721. }
  722. if (pCurrentWirelessPSData->dwNetworkType == WIRELESS_NETWORK_TYPE_AP) {
  723. //AP to Adhoc
  724. for(i=0; i < dwPSId; ++i) {
  725. ppNewWirelessPSData[i] = ppWirelessPSData[i];
  726. }
  727. for(i = dwPSId+1;i<dwNumAPNetworks;++i) {
  728. ppNewWirelessPSData[i-1] = ppWirelessPSData[i];
  729. }
  730. ppNewWirelessPSData[dwNumAPNetworks-1] = ppWirelessPSData[dwPSId];
  731. dwNewId = dwNumAPNetworks-1 ;
  732. dwNewNumAPNetworks = pWirelessPolicyData->dwNumAPNetworks-1;
  733. for(i = dwNumAPNetworks;i<dwNumPreferredSettings;++i) {
  734. ppNewWirelessPSData[i] = ppWirelessPSData[i];
  735. }
  736. } else
  737. {
  738. // Adhoc to AP
  739. for(i=0; i < dwNumAPNetworks; ++i) {
  740. ppNewWirelessPSData[i] = ppWirelessPSData[i];
  741. }
  742. ppNewWirelessPSData[dwNumAPNetworks] = ppWirelessPSData[dwPSId];
  743. dwNewId = dwNumAPNetworks;
  744. dwNewNumAPNetworks = pWirelessPolicyData->dwNumAPNetworks+1;
  745. for(i=dwNumAPNetworks; i < dwPSId; ++i) {
  746. ppNewWirelessPSData[i+1] = ppWirelessPSData[i];
  747. }
  748. for(i=dwPSId+1; i < dwNumPreferredSettings; ++i) {
  749. ppNewWirelessPSData[i] = ppWirelessPSData[i];
  750. }
  751. }
  752. dwError = ModifyWirelessPSData(
  753. ppNewWirelessPSData[dwNewId],
  754. pWirelessPSData
  755. );
  756. BAIL_ON_WIN32_ERROR(dwError);
  757. for(i=0;i<dwNumPreferredSettings;++i)
  758. {
  759. ppNewWirelessPSData[i]->dwId = i;
  760. }
  761. pWirelessPolicyData->ppWirelessPSData = ppNewWirelessPSData;
  762. pWirelessPolicyData->dwNumAPNetworks = dwNewNumAPNetworks;
  763. pWirelessPSData->dwId = dwNewId;
  764. FreePolMem(ppWirelessPSData);
  765. } else {
  766. dwError = ModifyWirelessPSData(
  767. pWirelessPolicyData->ppWirelessPSData[dwPSId],
  768. pWirelessPSData
  769. );
  770. BAIL_ON_WIN32_ERROR(dwError);
  771. }
  772. dwError = ERROR_SUCCESS;
  773. return(dwError);
  774. error:
  775. if (ppNewWirelessPSData) {
  776. FreePolMem(ppNewWirelessPSData);
  777. }
  778. return(dwError);
  779. }
  780. DWORD
  781. CopyWirelessPolicyData(
  782. PWIRELESS_POLICY_DATA pWirelessPolicyData,
  783. PWIRELESS_POLICY_DATA * ppWirelessPolicyData
  784. )
  785. {
  786. DWORD dwError = 0;
  787. PWIRELESS_POLICY_DATA pNewWirelessPolicyData = NULL;
  788. DWORD i = 0;
  789. DWORD dwNumPreferredSettings = 0;
  790. DWORD dwNumAPNetworks = 0;
  791. PWIRELESS_PS_DATA pWirelessPSData;
  792. PWIRELESS_PS_DATA pNewWirelessPSData;
  793. PWIRELESS_PS_DATA *ppNewWirelessPSData;
  794. PWIRELESS_PS_DATA *ppWirelessPSData;
  795. *ppWirelessPolicyData = NULL;
  796. pNewWirelessPolicyData = (PWIRELESS_POLICY_DATA) AllocPolMem(
  797. sizeof(WIRELESS_POLICY_DATA)
  798. );
  799. if (!pNewWirelessPolicyData) {
  800. dwError = ERROR_OUTOFMEMORY;
  801. BAIL_ON_WIN32_ERROR(dwError);
  802. }
  803. pNewWirelessPolicyData->dwPollingInterval =
  804. pWirelessPolicyData->dwPollingInterval;
  805. pNewWirelessPolicyData->dwWhenChanged =
  806. pWirelessPolicyData->dwWhenChanged;
  807. pNewWirelessPolicyData->dwFlags = pWirelessPolicyData->dwFlags;
  808. memcpy(
  809. &(pNewWirelessPolicyData->PolicyIdentifier),
  810. &(pWirelessPolicyData->PolicyIdentifier),
  811. sizeof(GUID)
  812. );
  813. if (pWirelessPolicyData->pszWirelessName &&
  814. *pWirelessPolicyData->pszWirelessName) {
  815. pNewWirelessPolicyData->pszWirelessName =
  816. AllocPolStr(
  817. pWirelessPolicyData->pszWirelessName
  818. );
  819. if (!pNewWirelessPolicyData->pszWirelessName) {
  820. dwError = ERROR_OUTOFMEMORY;
  821. BAIL_ON_WIN32_ERROR(dwError);
  822. }
  823. }
  824. if (pWirelessPolicyData->pszOldWirelessName &&
  825. *pWirelessPolicyData->pszOldWirelessName) {
  826. pNewWirelessPolicyData->pszOldWirelessName =
  827. AllocPolStr(
  828. pWirelessPolicyData->pszOldWirelessName
  829. );
  830. if (!pNewWirelessPolicyData->pszOldWirelessName) {
  831. dwError = ERROR_OUTOFMEMORY;
  832. BAIL_ON_WIN32_ERROR(dwError);
  833. }
  834. }
  835. if (pWirelessPolicyData->pszDescription &&
  836. *pWirelessPolicyData->pszDescription) {
  837. pNewWirelessPolicyData->pszDescription = AllocPolStr(
  838. pWirelessPolicyData->pszDescription
  839. );
  840. if (!pNewWirelessPolicyData->pszDescription) {
  841. dwError = ERROR_OUTOFMEMORY;
  842. BAIL_ON_WIN32_ERROR(dwError);
  843. }
  844. }
  845. pNewWirelessPolicyData->dwDisableZeroConf =
  846. pWirelessPolicyData->dwDisableZeroConf;
  847. pNewWirelessPolicyData->wMajorVersion =
  848. pWirelessPolicyData->wMajorVersion;
  849. pNewWirelessPolicyData->wMinorVersion =
  850. pWirelessPolicyData->wMinorVersion;
  851. pNewWirelessPolicyData->dwNetworkToAccess =
  852. pWirelessPolicyData->dwNetworkToAccess;
  853. pNewWirelessPolicyData->dwConnectToNonPreferredNtwks =
  854. pWirelessPolicyData->dwConnectToNonPreferredNtwks;
  855. dwNumPreferredSettings =
  856. pWirelessPolicyData->dwNumPreferredSettings;
  857. dwNumAPNetworks =
  858. pWirelessPolicyData->dwNumAPNetworks;
  859. pNewWirelessPolicyData->dwNumPreferredSettings =
  860. dwNumPreferredSettings;
  861. pNewWirelessPolicyData->dwNumAPNetworks =
  862. dwNumAPNetworks;
  863. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  864. ppNewWirelessPSData = (PWIRELESS_PS_DATA *) AllocPolMem(
  865. dwNumPreferredSettings*sizeof(PWIRELESS_PS_DATA));
  866. if(!ppNewWirelessPSData) {
  867. dwError = ERROR_OUTOFMEMORY;
  868. BAIL_ON_WIN32_ERROR(dwError);
  869. }
  870. for(i=0; i<dwNumPreferredSettings; ++i) {
  871. pNewWirelessPSData = NULL;
  872. dwError = CopyWirelessPSData(
  873. *(ppWirelessPSData+i),
  874. &pNewWirelessPSData
  875. );
  876. BAIL_ON_WIN32_ERROR(dwError);
  877. *(ppNewWirelessPSData+i) = pNewWirelessPSData;
  878. }
  879. pNewWirelessPolicyData->ppWirelessPSData =
  880. ppNewWirelessPSData;
  881. if (pWirelessPolicyData->pRsopInfo) {
  882. pNewWirelessPolicyData->pRsopInfo = (PRSOP_INFO)AllocPolMem(
  883. sizeof(RSOP_INFO)
  884. );
  885. if (!pNewWirelessPolicyData->pRsopInfo) {
  886. dwError = ERROR_OUTOFMEMORY;
  887. BAIL_ON_WIN32_ERROR(dwError);
  888. }
  889. dwError = DeepCpyRsopInfo(
  890. pNewWirelessPolicyData->pRsopInfo,
  891. pWirelessPolicyData->pRsopInfo
  892. );
  893. BAIL_ON_WIN32_ERROR(dwError);
  894. }
  895. *ppWirelessPolicyData = pNewWirelessPolicyData;
  896. return (dwError);
  897. error:
  898. if (pNewWirelessPolicyData) {
  899. FreeWirelessPolicyData(pNewWirelessPolicyData);
  900. }
  901. *ppWirelessPolicyData = NULL;
  902. return (dwError);
  903. }
  904. DWORD
  905. CopyWirelessPSData(
  906. PWIRELESS_PS_DATA pWirelessPSData,
  907. PWIRELESS_PS_DATA *ppWirelessPSData
  908. )
  909. {
  910. PWIRELESS_PS_DATA pNewWirelessPSData = NULL;
  911. DWORD dwError = 0;
  912. DWORD dwPSLen = 0;
  913. WCHAR SSID[32];
  914. DWORD dwSize = 0;
  915. DWORD dwWepEnabled=0;
  916. DWORD dwId = 0;
  917. DWORD dwWirelessSSIDLen = 0;
  918. DWORD dwNetworkAuthentication = 0;
  919. DWORD dwAutomaticKeyProvision = 0;
  920. DWORD dwNetworkType = 0;
  921. DWORD dwEnable8021x = 0;
  922. DWORD dw8021xMode = 0;
  923. DWORD dwEapType = 0;
  924. DWORD dwCertificateType = 0;
  925. DWORD dwValidateServerCertificate = 0;
  926. DWORD dwEAPDataLen = 0;
  927. LPBYTE pbEAPData = NULL;
  928. DWORD dwMachineAuthentication = 0;
  929. DWORD dwMachineAuthenticationType = 0;
  930. DWORD dwGuestAuthentication = 0;
  931. DWORD dwIEEE8021xMaxStart = 0;
  932. DWORD dwIEEE8021xStartPeriod = 0;
  933. DWORD dwIEEE8021xAuthPeriod = 0;
  934. DWORD dwIEEE8021xHeldPeriod = 0;
  935. DWORD dwDescriptionLen = 0;
  936. LPWSTR pszDescription = NULL;
  937. pNewWirelessPSData = (PWIRELESS_PS_DATA) AllocPolMem(
  938. sizeof(WIRELESS_PS_DATA)
  939. );
  940. if (!pNewWirelessPSData) {
  941. dwError = ERROR_OUTOFMEMORY;
  942. BAIL_ON_WIN32_ERROR(dwError);
  943. }
  944. dwPSLen = pWirelessPSData->dwPSLen;
  945. pNewWirelessPSData->dwPSLen = dwPSLen;
  946. memcpy(SSID,pWirelessPSData->pszWirelessSSID,32*2);
  947. memcpy(pNewWirelessPSData->pszWirelessSSID,SSID,32*2);
  948. dwWirelessSSIDLen = pWirelessPSData->dwWirelessSSIDLen;
  949. pNewWirelessPSData->dwWirelessSSIDLen = dwWirelessSSIDLen;
  950. dwWepEnabled = pWirelessPSData->dwWepEnabled;
  951. pNewWirelessPSData->dwWepEnabled = dwWepEnabled;
  952. dwId = pWirelessPSData->dwId;
  953. pNewWirelessPSData->dwId = dwId;
  954. dwNetworkAuthentication = pWirelessPSData->dwNetworkAuthentication;
  955. pNewWirelessPSData->dwNetworkAuthentication = dwNetworkAuthentication;
  956. dwAutomaticKeyProvision = pWirelessPSData->dwAutomaticKeyProvision;
  957. pNewWirelessPSData->dwAutomaticKeyProvision = dwAutomaticKeyProvision;
  958. dwNetworkType = pWirelessPSData->dwNetworkType;
  959. pNewWirelessPSData->dwNetworkType = dwNetworkType;
  960. dwEnable8021x = pWirelessPSData->dwEnable8021x;
  961. pNewWirelessPSData->dwEnable8021x = dwEnable8021x;
  962. dw8021xMode = pWirelessPSData->dw8021xMode;
  963. pNewWirelessPSData->dw8021xMode = dw8021xMode;
  964. dwEapType = pWirelessPSData->dwEapType;
  965. pNewWirelessPSData->dwEapType = dwEapType;
  966. dwEAPDataLen = pWirelessPSData->dwEAPDataLen;
  967. pNewWirelessPSData->dwEAPDataLen = dwEAPDataLen;
  968. if (dwEAPDataLen && (pWirelessPSData->pbEAPData)) {
  969. pbEAPData = AllocPolMem(dwEAPDataLen);
  970. if (!pbEAPData) {
  971. dwError = ERROR_OUTOFMEMORY;
  972. BAIL_ON_WIN32_ERROR(dwError);
  973. }
  974. memcpy(pbEAPData, pWirelessPSData->pbEAPData, dwEAPDataLen);
  975. }
  976. pNewWirelessPSData->pbEAPData = pbEAPData;
  977. dwMachineAuthentication = pWirelessPSData->dwMachineAuthentication;
  978. pNewWirelessPSData->dwMachineAuthentication = dwMachineAuthentication;
  979. dwMachineAuthenticationType =
  980. pWirelessPSData->dwMachineAuthenticationType;
  981. pNewWirelessPSData->dwMachineAuthenticationType =
  982. dwMachineAuthenticationType;
  983. dwGuestAuthentication = pWirelessPSData->dwGuestAuthentication;
  984. pNewWirelessPSData->dwGuestAuthentication = dwGuestAuthentication;
  985. dwIEEE8021xMaxStart = pWirelessPSData->dwIEEE8021xMaxStart;
  986. pNewWirelessPSData->dwIEEE8021xMaxStart = dwIEEE8021xMaxStart;
  987. dwIEEE8021xStartPeriod = pWirelessPSData->dwIEEE8021xStartPeriod;
  988. pNewWirelessPSData->dwIEEE8021xStartPeriod = dwIEEE8021xStartPeriod;
  989. dwIEEE8021xAuthPeriod = pWirelessPSData->dwIEEE8021xAuthPeriod;
  990. pNewWirelessPSData->dwIEEE8021xAuthPeriod = dwIEEE8021xAuthPeriod;
  991. dwIEEE8021xHeldPeriod = pWirelessPSData->dwIEEE8021xHeldPeriod;
  992. pNewWirelessPSData->dwIEEE8021xHeldPeriod = dwIEEE8021xHeldPeriod;
  993. dwDescriptionLen = pWirelessPSData->dwDescriptionLen;
  994. pNewWirelessPSData->dwDescriptionLen = dwDescriptionLen;
  995. if ((pWirelessPSData->pszDescription) && *(pWirelessPSData->pszDescription)) {
  996. pszDescription = AllocPolStr(pWirelessPSData->pszDescription);
  997. if (!pszDescription) {
  998. dwError = ERROR_OUTOFMEMORY;
  999. BAIL_ON_WIN32_ERROR(dwError);
  1000. }
  1001. }
  1002. pNewWirelessPSData->pszDescription = pszDescription;
  1003. *ppWirelessPSData = pNewWirelessPSData;
  1004. return(dwError);
  1005. error:
  1006. FreeWirelessPSData(pNewWirelessPSData);
  1007. return(dwError);
  1008. }
  1009. void
  1010. FreeMulWirelessPolicyData(
  1011. PWIRELESS_POLICY_DATA * ppWirelessPolicyData,
  1012. DWORD dwNumPolicyObjects
  1013. )
  1014. {
  1015. DWORD i = 0;
  1016. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  1017. if (!ppWirelessPolicyData) {
  1018. return;
  1019. }
  1020. for (i = 0; i < dwNumPolicyObjects; i++) {
  1021. pWirelessPolicyData = *(ppWirelessPolicyData + i);
  1022. if (pWirelessPolicyData) {
  1023. FreeWirelessPolicyData(pWirelessPolicyData);
  1024. }
  1025. }
  1026. FreePolMem(ppWirelessPolicyData);
  1027. return;
  1028. }
  1029. void
  1030. FreeWirelessPSData(
  1031. PWIRELESS_PS_DATA pWirelessPSData
  1032. )
  1033. {
  1034. if (!pWirelessPSData)
  1035. return;
  1036. if (pWirelessPSData->pbEAPData) {
  1037. FreePolMem(pWirelessPSData->pbEAPData);
  1038. }
  1039. if (pWirelessPSData->pszDescription) {
  1040. FreePolStr(pWirelessPSData->pszDescription);
  1041. }
  1042. FreePolMem(pWirelessPSData);
  1043. return;
  1044. }
  1045. void
  1046. FreeWirelessPolicyData(
  1047. PWIRELESS_POLICY_DATA pWirelessPolicyData
  1048. )
  1049. {
  1050. DWORD i = 0;
  1051. DWORD dwNumPSCount = 0;
  1052. PWIRELESS_PS_DATA *ppWirelessPSDatas = NULL;
  1053. PWIRELESS_PS_DATA pWirelessPSData = NULL;
  1054. if (!pWirelessPolicyData)
  1055. return;
  1056. if (pWirelessPolicyData->pszWirelessName) {
  1057. FreePolStr(pWirelessPolicyData->pszWirelessName);
  1058. }
  1059. if (pWirelessPolicyData->pszOldWirelessName) {
  1060. FreePolStr(pWirelessPolicyData->pszOldWirelessName);
  1061. }
  1062. if (pWirelessPolicyData->pszDescription) {
  1063. FreePolStr(pWirelessPolicyData->pszDescription);
  1064. }
  1065. ppWirelessPSDatas = pWirelessPolicyData->ppWirelessPSData;
  1066. if (ppWirelessPSDatas) {
  1067. dwNumPSCount = pWirelessPolicyData->dwNumPreferredSettings;
  1068. for(i = 0; i < dwNumPSCount ; ++i) {
  1069. pWirelessPSData = *(ppWirelessPSDatas+i);
  1070. FreeWirelessPSData(pWirelessPSData);
  1071. }
  1072. FreePolMem(ppWirelessPSDatas);
  1073. }
  1074. if (pWirelessPolicyData->pRsopInfo) {
  1075. FreeRsopInfo(
  1076. pWirelessPolicyData->pRsopInfo
  1077. );
  1078. }
  1079. FreePolMem(pWirelessPolicyData);
  1080. return;
  1081. }
  1082. void
  1083. FreeRsopInfo(
  1084. PRSOP_INFO pRsopInfo
  1085. )
  1086. {
  1087. if (pRsopInfo) {
  1088. FreePolStr(pRsopInfo->pszCreationtime);
  1089. FreePolStr(pRsopInfo->pszID);
  1090. FreePolStr(pRsopInfo->pszName);
  1091. FreePolStr(pRsopInfo->pszGPOID);
  1092. FreePolStr(pRsopInfo->pszSOMID);
  1093. }
  1094. }