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.

278 lines
8.3 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000.
  5. //
  6. // File: policy-r.c
  7. //
  8. // Contents: Policy management for registry.
  9. //
  10. //
  11. // History: KrishnaG.
  12. // AbhisheV.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "precomp.h"
  16. DWORD
  17. MarshallWirelessPSBuffer(
  18. PWIRELESS_PS_DATA pWirelessPSData,
  19. LPBYTE pBuffer,
  20. DWORD * pdwBufferLen
  21. )
  22. {
  23. DWORD dwSize = 0;
  24. DWORD dwError = 0;
  25. LPBYTE pCurrentPos = NULL;
  26. DWORD dwPSSize = 0;
  27. LPWSTR SSID = NULL;
  28. DWORD dwWepEnabled = 0;
  29. DWORD dwId = 0;
  30. DWORD dwNetworkAuthentication = 0;
  31. DWORD dwAutomaticKeyProvision = 0;
  32. DWORD dwNetworkType = 0;
  33. DWORD dwEnable8021x = 0;
  34. DWORD dw8021xMode = 0;
  35. DWORD dwEAPType = 0;
  36. DWORD dwCertificateType = 0;
  37. DWORD dwValidateServerCertificate = 0;
  38. DWORD dwMachineAuthentication = 0;
  39. DWORD dwMachineAuthenticationType = 0;
  40. DWORD dwGuestAuthentication = 0;
  41. DWORD dwIEEE8021xMaxStart = 0;
  42. DWORD dwIEEE8021xStartPeriod = 0;
  43. DWORD dwIEEE8021xAuthPeriod = 0;
  44. DWORD dwIEEE8021xHeldPeriod = 0;
  45. DWORD dwDescriptionLen = 0;
  46. DWORD dwEAPDataLen = 0;
  47. DWORD dwSSIDLen = 0;
  48. pCurrentPos = pBuffer;
  49. dwPSSize = pWirelessPSData->dwPSLen;
  50. memcpy(pCurrentPos, &dwPSSize, sizeof(DWORD));
  51. pCurrentPos += sizeof(DWORD);
  52. SSID = pWirelessPSData->pszWirelessSSID;
  53. memcpy(pCurrentPos, SSID, 32*2);
  54. pCurrentPos += 32*2;
  55. dwSSIDLen = pWirelessPSData->dwWirelessSSIDLen;
  56. memcpy(pCurrentPos, &dwSSIDLen, sizeof(DWORD));
  57. pCurrentPos += sizeof(DWORD);
  58. dwWepEnabled = pWirelessPSData->dwWepEnabled;
  59. memcpy(pCurrentPos, &dwWepEnabled, sizeof(DWORD));
  60. pCurrentPos += sizeof(DWORD);
  61. dwId = pWirelessPSData->dwId;
  62. memcpy(pCurrentPos, &dwId, sizeof(DWORD));
  63. pCurrentPos += sizeof(DWORD);
  64. dwNetworkAuthentication = pWirelessPSData->dwNetworkAuthentication;
  65. memcpy(pCurrentPos, &dwNetworkAuthentication, sizeof(DWORD));
  66. pCurrentPos += sizeof(DWORD);
  67. dwAutomaticKeyProvision = pWirelessPSData->dwAutomaticKeyProvision;
  68. memcpy(pCurrentPos, &dwAutomaticKeyProvision, sizeof(DWORD));
  69. pCurrentPos += sizeof(DWORD);
  70. dwNetworkType = pWirelessPSData->dwNetworkType;
  71. memcpy(pCurrentPos, &dwNetworkType, sizeof(DWORD));
  72. pCurrentPos += sizeof(DWORD);
  73. dwEnable8021x = pWirelessPSData->dwEnable8021x;
  74. memcpy(pCurrentPos, &dwEnable8021x, sizeof(DWORD));
  75. pCurrentPos += sizeof(DWORD);
  76. dw8021xMode = pWirelessPSData->dw8021xMode;
  77. memcpy(pCurrentPos, &dw8021xMode, sizeof(DWORD));
  78. pCurrentPos += sizeof(DWORD);
  79. dwEAPType = pWirelessPSData->dwEapType;
  80. memcpy(pCurrentPos, &dwEAPType, sizeof(DWORD));
  81. pCurrentPos += sizeof(DWORD);
  82. dwEAPDataLen = pWirelessPSData->dwEAPDataLen;
  83. memcpy(pCurrentPos, &dwEAPDataLen, sizeof(DWORD));
  84. pCurrentPos += sizeof(DWORD);
  85. memcpy(pCurrentPos,
  86. pWirelessPSData->pbEAPData,
  87. dwEAPDataLen);
  88. pCurrentPos += dwEAPDataLen;
  89. dwMachineAuthentication = pWirelessPSData->dwMachineAuthentication;
  90. memcpy(pCurrentPos, &dwMachineAuthentication, sizeof(DWORD));
  91. pCurrentPos += sizeof(DWORD);
  92. dwMachineAuthenticationType = pWirelessPSData->dwMachineAuthenticationType;
  93. memcpy(pCurrentPos, &dwMachineAuthenticationType, sizeof(DWORD));
  94. pCurrentPos += sizeof(DWORD);
  95. dwGuestAuthentication = pWirelessPSData->dwGuestAuthentication;
  96. memcpy(pCurrentPos, &dwGuestAuthentication, sizeof(DWORD));
  97. pCurrentPos += sizeof(DWORD);
  98. dwIEEE8021xMaxStart = pWirelessPSData->dwIEEE8021xMaxStart;
  99. memcpy(pCurrentPos, &dwIEEE8021xMaxStart, sizeof(DWORD));
  100. pCurrentPos += sizeof(DWORD);
  101. dwIEEE8021xStartPeriod = pWirelessPSData->dwIEEE8021xStartPeriod;
  102. memcpy(pCurrentPos, &dwIEEE8021xStartPeriod, sizeof(DWORD));
  103. pCurrentPos += sizeof(DWORD);
  104. dwIEEE8021xAuthPeriod = pWirelessPSData->dwIEEE8021xAuthPeriod;
  105. memcpy(pCurrentPos, &dwIEEE8021xAuthPeriod, sizeof(DWORD));
  106. pCurrentPos += sizeof(DWORD);
  107. dwIEEE8021xHeldPeriod = pWirelessPSData->dwIEEE8021xHeldPeriod;
  108. memcpy(pCurrentPos, &dwIEEE8021xHeldPeriod, sizeof(DWORD));
  109. pCurrentPos += sizeof(DWORD);
  110. dwDescriptionLen = pWirelessPSData->dwDescriptionLen;
  111. memcpy(pCurrentPos, &dwDescriptionLen, sizeof(DWORD));
  112. pCurrentPos += sizeof(DWORD);
  113. memcpy(pCurrentPos,
  114. pWirelessPSData->pszDescription,
  115. dwDescriptionLen*2);
  116. *pdwBufferLen = dwPSSize;
  117. return(dwError);
  118. }
  119. DWORD
  120. MarshallWirelessPolicyBuffer(
  121. PWIRELESS_POLICY_DATA pWirelessPolicyData,
  122. LPBYTE * ppBuffer,
  123. DWORD * pdwBufferLen
  124. )
  125. {
  126. LPBYTE pBuffer = NULL;
  127. DWORD dwSize = 0;
  128. DWORD dwError = 0;
  129. DWORD dwPollingInterval = 0;
  130. LPBYTE pCurrentPos = NULL;
  131. DWORD dwEffectiveSize = 0;
  132. PWIRELESS_PS_DATA *ppWirelessPSData = NULL;
  133. DWORD dwNumPreferredSettings = 0;
  134. DWORD dwPSSize = 0;
  135. DWORD i = 0;
  136. DWORD dwDisableZeroConf = 0;
  137. DWORD dwNetworkToAccess = 0;
  138. DWORD dwConnectToNonPreferredNtwks = 0;
  139. DWORD dwWlBlobLen = 0;
  140. WORD wMajorVersion = 0;
  141. WORD wMinorVersion = 0;
  142. wMajorVersion = WL_BLOB_MAJOR_VERSION;
  143. wMinorVersion = WL_BLOB_MINOR_VERSION;
  144. // first estimate the total size
  145. dwSize += sizeof(WORD); // Major Version
  146. dwSize += sizeof(WORD); // Minor Version
  147. dwSize += sizeof(DWORD); // Length of the Wl_Blob
  148. dwWlBlobLen += sizeof(DWORD); // dwPollingInterval
  149. dwWlBlobLen += sizeof(DWORD); // dwDisableZeroConf
  150. dwWlBlobLen += sizeof(DWORD); // dwNetworkToAccess
  151. dwWlBlobLen += sizeof(DWORD); // dwConnectToNonPreferredNetworks
  152. dwWlBlobLen += sizeof(DWORD); // dwNumPreferredSettings
  153. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  154. dwNumPreferredSettings =
  155. pWirelessPolicyData->dwNumPreferredSettings;
  156. for (i=0; i<dwNumPreferredSettings;++i) {
  157. dwWlBlobLen += (*ppWirelessPSData)->dwPSLen;
  158. ppWirelessPSData++;
  159. }
  160. //dwSize++; //Taroon Dont know why this for.
  161. dwSize += dwWlBlobLen;
  162. pBuffer = AllocPolMem(dwSize);
  163. if (!pBuffer) {
  164. dwError = ERROR_OUTOFMEMORY;
  165. BAIL_ON_WIN32_ERROR(dwError);
  166. }
  167. pCurrentPos = pBuffer;
  168. memcpy(pCurrentPos, &wMajorVersion, sizeof(WORD));
  169. pCurrentPos += sizeof(WORD);
  170. memcpy(pCurrentPos, &wMinorVersion, sizeof(WORD));
  171. pCurrentPos += sizeof(WORD);
  172. memcpy(pCurrentPos, &dwWlBlobLen, sizeof(DWORD));
  173. pCurrentPos += sizeof(DWORD);
  174. dwPollingInterval = pWirelessPolicyData->dwPollingInterval;
  175. memcpy(pCurrentPos, &dwPollingInterval, sizeof(DWORD));
  176. pCurrentPos += sizeof(DWORD);
  177. dwDisableZeroConf = pWirelessPolicyData->dwDisableZeroConf;
  178. memcpy(pCurrentPos, &dwDisableZeroConf, sizeof(DWORD));
  179. pCurrentPos += sizeof(DWORD);
  180. dwNetworkToAccess = pWirelessPolicyData->dwNetworkToAccess;
  181. memcpy(pCurrentPos, &dwNetworkToAccess, sizeof(DWORD));
  182. pCurrentPos += sizeof(DWORD);
  183. dwConnectToNonPreferredNtwks = pWirelessPolicyData->dwConnectToNonPreferredNtwks;
  184. memcpy(pCurrentPos, &dwConnectToNonPreferredNtwks, sizeof(DWORD));
  185. pCurrentPos += sizeof(DWORD);
  186. dwNumPreferredSettings = pWirelessPolicyData->dwNumPreferredSettings;
  187. memcpy(pCurrentPos, &dwNumPreferredSettings, sizeof(DWORD));
  188. pCurrentPos += sizeof(DWORD);
  189. // Write each Preferred Setting data here
  190. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  191. for(i=0; i<dwNumPreferredSettings;++i) {
  192. dwError = MarshallWirelessPSBuffer(
  193. *(ppWirelessPSData+i),
  194. pCurrentPos,
  195. &dwPSSize);
  196. BAIL_ON_WIN32_ERROR(dwError);
  197. pCurrentPos += dwPSSize;
  198. }
  199. *ppBuffer = pBuffer;
  200. *pdwBufferLen = dwSize;
  201. return(dwError);
  202. error:
  203. if (pBuffer) {
  204. FreePolMem(pBuffer);
  205. }
  206. *ppBuffer = NULL;
  207. *pdwBufferLen = 0;
  208. return(dwError);
  209. }