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.

205 lines
6.0 KiB

  1. #include <precomp.h>
  2. #include "utils.h"
  3. // global storing the OS version#
  4. OSVERSIONINFOEX g_verInfoEx = {0};
  5. //------------------------------------
  6. // Allocates general usage memory from the process heap
  7. PVOID
  8. Process_user_allocate(IN size_t NumBytes)
  9. {
  10. PVOID pMem;
  11. pMem = (NumBytes > 0) ? HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, NumBytes) : NULL;
  12. return pMem;
  13. }
  14. //------------------------------------
  15. // Frees general usage memory
  16. VOID
  17. Process_user_free(IN LPVOID pMem)
  18. {
  19. if (pMem != NULL)
  20. HeapFree(GetProcessHeap(), 0, (pMem));
  21. }
  22. BOOL IsXPRTM()
  23. {
  24. return (g_verInfoEx.dwBuildNumber == 2600) && (g_verInfoEx.wServicePackMajor == 0);
  25. }
  26. // Translates current WZC control flags to values from legacy OS versions
  27. // Returns the Os dependant flag value
  28. DWORD _Os(DWORD dwApiCtl)
  29. {
  30. // the only translation should happen for XP RTM
  31. if (IsXPRTM())
  32. {
  33. DWORD dwRTMApiCtl = 0;
  34. if (dwApiCtl & INTF_BSSIDLIST)
  35. dwRTMApiCtl |= 0x00004000;
  36. if (dwApiCtl & INTF_PREFLIST)
  37. dwRTMApiCtl |= 0x00000020;
  38. if (dwApiCtl & INTF_CM_MASK)
  39. dwRTMApiCtl |= 0x00000010;
  40. if (dwApiCtl & INTF_ENABLED)
  41. dwRTMApiCtl |= 0x00000010;
  42. if (dwApiCtl & INTF_SSID)
  43. dwRTMApiCtl |= 0x00001000;
  44. if (dwApiCtl & INTF_INFRAMODE)
  45. dwRTMApiCtl |= 0x00000200;
  46. if (dwApiCtl & INTF_AUTHMODE)
  47. dwRTMApiCtl |= 0x00000400;
  48. if (dwApiCtl & INTF_WEPSTATUS)
  49. dwRTMApiCtl |= 0x00000800;
  50. if (dwApiCtl & INTF_BSSID)
  51. dwRTMApiCtl |= 0x00002000;
  52. if (dwApiCtl & INTF_LIST_SCAN)
  53. dwRTMApiCtl |= 0x00008000;
  54. dwApiCtl = dwRTMApiCtl;
  55. }
  56. return dwApiCtl;
  57. }
  58. //-----------------------------------------------------------
  59. // WzcConfigHit: tells weather the WZC_WLAN_CONFIG matches the criteria in pPDData
  60. BOOL
  61. WzcConfigHit(
  62. PPARAM_DESCR_DATA pPDData,
  63. PWZC_WLAN_CONFIG pwzcConfig)
  64. {
  65. BOOL bRet = TRUE;
  66. if (bRet && (pPDData->dwArgumentedParams & PRM_IM))
  67. {
  68. bRet = (pwzcConfig->InfrastructureMode == pPDData->wzcIntfEntry.nInfraMode);
  69. }
  70. if (bRet && (pPDData->dwArgumentedParams & PRM_AM))
  71. {
  72. bRet = (pwzcConfig->AuthenticationMode == pPDData->wzcIntfEntry.nAuthMode);
  73. }
  74. if (bRet && (pPDData->dwArgumentedParams & PRM_PRIV))
  75. {
  76. bRet = (pwzcConfig->Privacy == pPDData->wzcIntfEntry.nWepStatus);
  77. }
  78. if (bRet && (pPDData->dwArgumentedParams & PRM_BSSID))
  79. {
  80. bRet = (memcmp(
  81. &(pwzcConfig->MacAddress),
  82. pPDData->wzcIntfEntry.rdBSSID.pData,
  83. sizeof(NDIS_802_11_MAC_ADDRESS))
  84. == 0);
  85. }
  86. if (bRet && (pPDData->dwArgumentedParams & PRM_SSID))
  87. {
  88. bRet = (pwzcConfig->Ssid.SsidLength == pPDData->wzcIntfEntry.rdSSID.dwDataLen);
  89. bRet = bRet &&
  90. (memcmp(
  91. &(pwzcConfig->Ssid.Ssid),
  92. pPDData->wzcIntfEntry.rdSSID.pData,
  93. pwzcConfig->Ssid.SsidLength)
  94. == 0);
  95. }
  96. return bRet;
  97. }
  98. //-----------------------------------------------------------
  99. // WzcFilterList: Filter the wzc list according to the settings in pPDData
  100. DWORD
  101. WzcFilterList(
  102. BOOL bInclude,
  103. PPARAM_DESCR_DATA pPDData,
  104. PWZC_802_11_CONFIG_LIST pwzcList)
  105. {
  106. DWORD dwErr = ERROR_SUCCESS;
  107. UINT i;
  108. if (pwzcList == NULL)
  109. dwErr = ERROR_GEN_FAILURE;
  110. else
  111. {
  112. for (i = 0; i < pwzcList->NumberOfItems; i++)
  113. {
  114. PWZC_WLAN_CONFIG pwzcConfig = &pwzcList->Config[i];
  115. if (bInclude != WzcConfigHit(pPDData, pwzcConfig))
  116. {
  117. if (i < pwzcList->NumberOfItems - 1)
  118. {
  119. memmove(
  120. &pwzcList->Config[i],
  121. &pwzcList->Config[i+1],
  122. (pwzcList->NumberOfItems - i - 1) * sizeof(WZC_WLAN_CONFIG));
  123. }
  124. i--;
  125. pwzcList->NumberOfItems--;
  126. }
  127. }
  128. }
  129. SetLastError(dwErr);
  130. return dwErr;
  131. }
  132. //-----------------------------------------------------------
  133. // WzcDisableOneX: Make sure 802.1x is disabled for the SSID in pPDData
  134. DWORD
  135. WzcSetOneX(
  136. PPARAM_DESCR_DATA pPDData,
  137. BOOL bEnableOneX)
  138. {
  139. DWORD dwErr = ERROR_SUCCESS;
  140. EAPOL_INTF_PARAMS eapolParams = {0};
  141. if (pPDData == NULL ||
  142. (pPDData->dwArgumentedParams & PRM_SSID) == 0 ||
  143. (pPDData->wzcIntfEntry.rdSSID.dwDataLen > MAX_SSID_LEN))
  144. {
  145. dwErr = ERROR_INVALID_PARAMETER;
  146. }
  147. else
  148. {
  149. memcpy(eapolParams.bSSID,
  150. pPDData->wzcIntfEntry.rdSSID.pData,
  151. pPDData->wzcIntfEntry.rdSSID.dwDataLen);
  152. eapolParams.dwSizeOfSSID = pPDData->wzcIntfEntry.rdSSID.dwDataLen;
  153. }
  154. if (dwErr == ERROR_SUCCESS)
  155. {
  156. dwErr = WZCEapolGetInterfaceParams (
  157. NULL,
  158. pPDData->wzcIntfEntry.wszGuid,
  159. &eapolParams);
  160. }
  161. if (IsXPRTM() && dwErr != ERROR_SUCCESS)
  162. {
  163. eapolParams.dwEapFlags = DEFAULT_MACHINE_AUTH_STATE | DEFAULT_GUEST_AUTH_STATE;
  164. eapolParams.dwEapType = DEFAULT_EAP_TYPE;
  165. memcpy(eapolParams.bSSID,
  166. pPDData->wzcIntfEntry.rdSSID.pData,
  167. pPDData->wzcIntfEntry.rdSSID.dwDataLen);
  168. eapolParams.dwSizeOfSSID = pPDData->wzcIntfEntry.rdSSID.dwDataLen;
  169. dwErr = ERROR_SUCCESS;
  170. }
  171. if (dwErr == ERROR_SUCCESS)
  172. {
  173. if (bEnableOneX)
  174. eapolParams.dwEapFlags |= EAPOL_ENABLED;
  175. else
  176. eapolParams.dwEapFlags &= ~EAPOL_ENABLED;
  177. dwErr = WZCEapolSetInterfaceParams (
  178. NULL,
  179. pPDData->wzcIntfEntry.wszGuid,
  180. &eapolParams);
  181. }
  182. SetLastError(dwErr);
  183. return dwErr;
  184. }