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.

192 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 2001, Microsoft Corporation
  3. Module Name:
  4. eapolpol.c
  5. Abstract:
  6. The module deals with functions related to communication group policy
  7. settings to EAPOL module
  8. Revision History:
  9. November 19 2001, Created
  10. --*/
  11. #include "precomp.h"
  12. DWORD
  13. ConvertWirelessPSDataToEAPOLData (
  14. IN WIRELESS_PS_DATA *pWirelessData,
  15. IN OUT EAPOL_POLICY_DATA *pEAPOLData
  16. )
  17. {
  18. DWORD dwRetCode = NO_ERROR;
  19. DWORD dwSSIDSize = 0;
  20. WCHAR pszTempSSID[33];
  21. BYTE pszOutSSID[33];
  22. do
  23. {
  24. if (pWirelessData->dwWirelessSSIDLen != 0)
  25. {
  26. wcsncpy(pszTempSSID, pWirelessData->pszWirelessSSID, 32);
  27. pszTempSSID[32] = L'\0';
  28. dwSSIDSize = WideCharToMultiByte (
  29. CP_ACP,
  30. 0,
  31. pszTempSSID, //pWirelessData->pszWirelessSSID,
  32. -1, // pWirelessData->dwWirelessSSIDLen+1,
  33. pszOutSSID,
  34. MAX_SSID_LEN +1 ,
  35. NULL,
  36. NULL);
  37. if (dwSSIDSize == 0)
  38. {
  39. dwRetCode = GetLastError();
  40. break;
  41. }
  42. memcpy(pEAPOLData->pbWirelessSSID, pszOutSSID, 32);
  43. }
  44. pEAPOLData->dwWirelessSSIDLen = dwSSIDSize-1;
  45. pEAPOLData->dwEnable8021x = pWirelessData->dwEnable8021x;
  46. pEAPOLData->dw8021xMode = pWirelessData->dw8021xMode;
  47. pEAPOLData->dwEAPType = pWirelessData->dwEapType;
  48. if (pWirelessData->dwEAPDataLen != 0)
  49. {
  50. pEAPOLData->pbEAPData = AllocSPDMem(pWirelessData->dwEAPDataLen);
  51. if (!pEAPOLData->pbEAPData) {
  52. dwRetCode = GetLastError();
  53. break;
  54. }
  55. }
  56. memcpy (pEAPOLData->pbEAPData, pWirelessData->pbEAPData, pWirelessData->dwEAPDataLen);
  57. pEAPOLData->dwEAPDataLen = pWirelessData->dwEAPDataLen;
  58. pEAPOLData->dwMachineAuthentication = pWirelessData->dwMachineAuthentication;
  59. pEAPOLData->dwMachineAuthenticationType = pWirelessData->dwMachineAuthenticationType;
  60. pEAPOLData->dwGuestAuthentication = pWirelessData->dwGuestAuthentication;
  61. pEAPOLData->dwIEEE8021xMaxStart = pWirelessData->dwIEEE8021xMaxStart;
  62. pEAPOLData->dwIEEE8021xStartPeriod = pWirelessData->dwIEEE8021xStartPeriod;
  63. pEAPOLData->dwIEEE8021xAuthPeriod = pWirelessData->dwIEEE8021xAuthPeriod;
  64. pEAPOLData->dwIEEE8021xHeldPeriod = pWirelessData->dwIEEE8021xHeldPeriod;
  65. }
  66. while (FALSE);
  67. return dwRetCode;
  68. }
  69. //
  70. // If Policy Engine is calling into EAPOL, pEAPOLList will be LocalFree by
  71. // PolicyEngine, after it returns from calling into EAPOL.
  72. // If Policy Engine is called by EAPOL, pEAPOLList will be LocalFree by
  73. // EAPOL
  74. //
  75. DWORD
  76. ConvertWirelessPolicyDataToEAPOLList (
  77. IN WIRELESS_POLICY_DATA *pWirelessData,
  78. OUT PEAPOL_POLICY_LIST *ppEAPOLList
  79. )
  80. {
  81. DWORD dwIndex = 0;
  82. EAPOL_POLICY_DATA *pEAPOLData = NULL;
  83. EAPOL_POLICY_LIST *pEAPOLList = NULL;
  84. DWORD dwRetCode = NO_ERROR;
  85. do
  86. {
  87. if (!pWirelessData) {
  88. pEAPOLList = AllocSPDMem(sizeof(EAPOL_POLICY_LIST));
  89. if (!pEAPOLList) {
  90. dwRetCode = GetLastError();
  91. break;
  92. }
  93. break;
  94. }
  95. pEAPOLList = AllocSPDMem(sizeof(EAPOL_POLICY_LIST)+
  96. pWirelessData->dwNumPreferredSettings*sizeof(EAPOL_POLICY_DATA));
  97. if (!pEAPOLList) {
  98. dwRetCode = GetLastError();
  99. break;
  100. }
  101. pEAPOLList->dwNumberOfItems = pWirelessData->dwNumPreferredSettings;
  102. for (dwIndex=0; dwIndex< pWirelessData->dwNumPreferredSettings; dwIndex++)
  103. {
  104. pEAPOLData = &(pEAPOLList->EAPOLPolicy[dwIndex]);
  105. dwRetCode = ConvertWirelessPSDataToEAPOLData (
  106. pWirelessData->ppWirelessPSData[dwIndex],
  107. pEAPOLData
  108. );
  109. if (dwRetCode != NO_ERROR)
  110. {
  111. break;
  112. }
  113. }
  114. }
  115. while (FALSE);
  116. if (dwRetCode) {
  117. if (pEAPOLList) {
  118. for (dwIndex = 0; dwIndex < pWirelessData->dwNumPreferredSettings; dwIndex++)
  119. {
  120. pEAPOLData = &(pEAPOLList->EAPOLPolicy[dwIndex]);
  121. if (pEAPOLData->pbEAPData)
  122. {
  123. FreeSPDMem(pEAPOLData->pbEAPData);
  124. }
  125. }
  126. FreeSPDMem(pEAPOLList);
  127. pEAPOLList = NULL;
  128. }
  129. }
  130. *ppEAPOLList = pEAPOLList;
  131. return dwRetCode;
  132. }
  133. VOID
  134. FreeEAPOLList (
  135. IN PEAPOL_POLICY_LIST pEAPOLList
  136. )
  137. {
  138. DWORD dwIndex = 0;
  139. PEAPOL_POLICY_DATA pEAPOLData = NULL;
  140. if (pEAPOLList) {
  141. for (dwIndex = 0; dwIndex < pEAPOLList->dwNumberOfItems; dwIndex++)
  142. {
  143. pEAPOLData = &(pEAPOLList->EAPOLPolicy[dwIndex]);
  144. if (pEAPOLData->pbEAPData)
  145. {
  146. FreeSPDMem(pEAPOLData->pbEAPData);
  147. }
  148. }
  149. FreeSPDMem(pEAPOLList);
  150. }
  151. return;
  152. }