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.

355 lines
11 KiB

  1. #include <precomp.h>
  2. #include "eapolcfg.h"
  3. #define MALLOC(s) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (s))
  4. #define FREE(p) HeapFree(GetProcessHeap(), 0, (p))
  5. ////////////////////////////////////////////////////////////////////////
  6. // CEapolConfig related stuff
  7. //
  8. //+---------------------------------------------------------------------------
  9. // constructor
  10. CEapolConfig::CEapolConfig()
  11. {
  12. m_dwCtlFlags = 0;
  13. ZeroMemory(&m_EapolIntfParams, sizeof(EAPOL_INTF_PARAMS));
  14. m_pListEapcfgs = NULL;
  15. }
  16. //+---------------------------------------------------------------------------
  17. // destructor
  18. CEapolConfig::~CEapolConfig()
  19. {
  20. ZeroMemory(&m_EapolIntfParams, sizeof(EAPOL_INTF_PARAMS));
  21. if (m_pListEapcfgs != NULL)
  22. {
  23. DtlDestroyList (m_pListEapcfgs, DestroyEapcfgNode);
  24. m_pListEapcfgs = NULL;
  25. }
  26. }
  27. //+---------------------------------------------------------------------------
  28. DWORD CEapolConfig::CopyEapolConfig(CEapolConfig *pEapolConfig)
  29. {
  30. DTLLIST *pListEapcfgs = NULL;
  31. DTLNODE *pCopyNode = NULL, *pInNode = NULL;
  32. DWORD dwErr = ERROR_SUCCESS;
  33. if (pEapolConfig)
  34. {
  35. pListEapcfgs = ::ReadEapcfgList (EAPOL_MUTUAL_AUTH_EAP_ONLY);
  36. if (pListEapcfgs)
  37. {
  38. for (pCopyNode = DtlGetFirstNode(pListEapcfgs);
  39. pCopyNode;
  40. pCopyNode = DtlGetNextNode(pCopyNode))
  41. {
  42. EAPCFG* pCopyEapcfg = (EAPCFG* )DtlGetData(pCopyNode);
  43. for (pInNode = DtlGetFirstNode(pEapolConfig->m_pListEapcfgs);
  44. pInNode;
  45. pInNode = DtlGetNextNode(pInNode))
  46. {
  47. EAPCFG* pInEapcfg = (EAPCFG* )DtlGetData(pInNode);
  48. if (pCopyEapcfg->dwKey == pInEapcfg->dwKey)
  49. {
  50. if ((pCopyEapcfg->pData = (PBYTE) MALLOC (pInEapcfg->cbData)) == NULL)
  51. {
  52. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  53. break;
  54. }
  55. memcpy (pCopyEapcfg->pData, pInEapcfg->pData, pInEapcfg->cbData);
  56. pCopyEapcfg->cbData = pInEapcfg->cbData;
  57. break;
  58. }
  59. }
  60. if (dwErr != NO_ERROR)
  61. {
  62. goto LExit;
  63. }
  64. }
  65. }
  66. m_pListEapcfgs = pListEapcfgs;
  67. memcpy (&m_EapolIntfParams, &pEapolConfig->m_EapolIntfParams, sizeof(EAPOL_INTF_PARAMS));
  68. }
  69. else
  70. {
  71. dwErr = ERROR_INVALID_DATA;
  72. }
  73. LExit:
  74. if (dwErr != ERROR_SUCCESS && pListEapcfgs != NULL)
  75. {
  76. DtlDestroyList (pListEapcfgs, DestroyEapcfgNode);
  77. }
  78. return dwErr;
  79. }
  80. //+---------------------------------------------------------------------------
  81. DWORD CEapolConfig::LoadEapolConfig(LPWSTR wszIntfGuid, PNDIS_802_11_SSID pndSsid)
  82. {
  83. DWORD dwErr = ERROR_SUCCESS;
  84. BYTE *pbData = NULL;
  85. DWORD cbData = 0;
  86. EAPOL_INTF_PARAMS EapolIntfParams;
  87. DTLLIST *pListEapcfgs = NULL;
  88. // Initialize EAP package list
  89. // Read the EAPCFG information from the registry and find the node
  90. // selected in the entry, or the default, if none.
  91. do
  92. {
  93. DTLNODE* pNode = NULL;
  94. // Read the EAPCFG information from the registry and find the node
  95. // selected in the entry, or the default, if none.
  96. pListEapcfgs = ::ReadEapcfgList (EAPOL_MUTUAL_AUTH_EAP_ONLY);
  97. if (pListEapcfgs)
  98. {
  99. DTLNODE* pNodeEap;
  100. DWORD dwkey = 0;
  101. // Read the EAP params for this interface
  102. ZeroMemory ((BYTE *)&EapolIntfParams, sizeof(EAPOL_INTF_PARAMS));
  103. EapolIntfParams.dwEapFlags = DEFAULT_EAP_STATE;
  104. EapolIntfParams.dwEapType = DEFAULT_EAP_TYPE;
  105. if (pndSsid)
  106. {
  107. EapolIntfParams.dwSizeOfSSID = pndSsid->SsidLength;
  108. memcpy (EapolIntfParams.bSSID, pndSsid->Ssid, pndSsid->SsidLength);
  109. }
  110. else
  111. {
  112. // If NULL SSID, this will get default EAPOL values
  113. EapolIntfParams.dwSizeOfSSID = 1;
  114. }
  115. dwErr = WZCEapolGetInterfaceParams (
  116. NULL,
  117. wszIntfGuid,
  118. &EapolIntfParams);
  119. if (dwErr != ERROR_SUCCESS)
  120. break;
  121. memcpy (&m_EapolIntfParams, &EapolIntfParams, sizeof(EAPOL_INTF_PARAMS));
  122. // Read the EAP configuration info for all EAP packages
  123. for (pNodeEap = DtlGetFirstNode(pListEapcfgs);
  124. pNodeEap;
  125. pNodeEap = DtlGetNextNode(pNodeEap))
  126. {
  127. EAPCFG* pEapcfg = (EAPCFG* )DtlGetData(pNodeEap);
  128. ASSERT( pEapcfg );
  129. dwErr = ERROR_SUCCESS;
  130. pbData = NULL;
  131. cbData = 0;
  132. // Get the size of the EAP blob
  133. dwErr = WZCEapolGetCustomAuthData(
  134. NULL,
  135. wszIntfGuid,
  136. pEapcfg->dwKey,
  137. EapolIntfParams.dwSizeOfSSID,
  138. EapolIntfParams.bSSID,
  139. NULL,
  140. &cbData
  141. );
  142. if (dwErr != ERROR_SUCCESS)
  143. {
  144. if ((EapolIntfParams.dwSizeOfSSID != 0) &&
  145. (dwErr == ERROR_FILE_NOT_FOUND))
  146. {
  147. // The Last Used SSID did not have a connection
  148. // blob created. Call again for size of blob with
  149. // NULL SSID
  150. EapolIntfParams.dwSizeOfSSID = 0;
  151. // Get the size of the EAP blob
  152. dwErr = WZCEapolGetCustomAuthData (
  153. NULL,
  154. wszIntfGuid,
  155. pEapcfg->dwKey,
  156. 0,
  157. NULL,
  158. NULL,
  159. &cbData
  160. );
  161. }
  162. if (dwErr == ERROR_BUFFER_TOO_SMALL)
  163. {
  164. if (cbData <= 0)
  165. {
  166. // No EAP blob stored in the registry
  167. pbData = NULL;
  168. // Will continue processing for errors
  169. // Not exit
  170. dwErr = ERROR_SUCCESS;
  171. }
  172. else
  173. {
  174. // Allocate memory to hold the blob
  175. pbData = (PBYTE) MALLOC (cbData);
  176. if (pbData == NULL)
  177. {
  178. dwErr = ERROR_SUCCESS;
  179. continue;
  180. }
  181. ZeroMemory (pbData, cbData);
  182. dwErr = WZCEapolGetCustomAuthData (
  183. NULL,
  184. wszIntfGuid,
  185. pEapcfg->dwKey,
  186. EapolIntfParams.dwSizeOfSSID,
  187. EapolIntfParams.bSSID,
  188. pbData,
  189. &cbData
  190. );
  191. if (dwErr != ERROR_SUCCESS)
  192. {
  193. FREE ( pbData );
  194. dwErr = ERROR_SUCCESS;
  195. continue;
  196. }
  197. }
  198. }
  199. else
  200. {
  201. dwErr = ERROR_SUCCESS;
  202. continue;
  203. }
  204. }
  205. else
  206. {
  207. dwErr = ERROR_SUCCESS;
  208. }
  209. if (pEapcfg->pData != NULL)
  210. {
  211. FREE ( pEapcfg->pData );
  212. }
  213. pEapcfg->pData = (UCHAR *)pbData;
  214. pEapcfg->cbData = cbData;
  215. }
  216. m_pListEapcfgs = pListEapcfgs;
  217. }
  218. else
  219. {
  220. dwErr = ERROR_INVALID_DATA;
  221. }
  222. } while (FALSE);
  223. return dwErr;
  224. }
  225. //+---------------------------------------------------------------------------
  226. DWORD CEapolConfig::SaveEapolConfig(LPWSTR wszIntfGuid, PNDIS_802_11_SSID pndSsid)
  227. {
  228. WCHAR *pwszLastUsedSSID = NULL;
  229. DWORD dwEapFlags = 0;
  230. DWORD dwErrOverall = ERROR_SUCCESS;
  231. DWORD dwErr = ERROR_SUCCESS;
  232. // Save the EAP configuration data into the registry
  233. DTLNODE* pNodeEap = NULL;
  234. dwErr = ERROR_SUCCESS;
  235. // Save data for all EAP packages in the registry
  236. if (m_pListEapcfgs == NULL)
  237. {
  238. return ERROR_SUCCESS;
  239. }
  240. if (pndSsid)
  241. {
  242. m_EapolIntfParams.dwSizeOfSSID = pndSsid->SsidLength;
  243. memcpy (m_EapolIntfParams.bSSID, pndSsid->Ssid, pndSsid->SsidLength);
  244. }
  245. for (pNodeEap = DtlGetFirstNode(m_pListEapcfgs);
  246. pNodeEap;
  247. pNodeEap = DtlGetNextNode(pNodeEap))
  248. {
  249. EAPCFG* pcfg = (EAPCFG* )DtlGetData(pNodeEap);
  250. if (pcfg == NULL)
  251. {
  252. continue;
  253. }
  254. dwErr = ERROR_SUCCESS;
  255. // ignore error and continue with next
  256. dwErr = WZCEapolSetCustomAuthData (
  257. NULL,
  258. wszIntfGuid,
  259. pcfg->dwKey,
  260. m_EapolIntfParams.dwSizeOfSSID,
  261. m_EapolIntfParams.bSSID,
  262. pcfg->pData,
  263. pcfg->cbData);
  264. if (dwErr != ERROR_SUCCESS)
  265. {
  266. dwErrOverall = dwErr;
  267. dwErr = ERROR_SUCCESS;
  268. }
  269. }
  270. if (m_dwCtlFlags & EAPOL_CTL_LOCKED)
  271. m_EapolIntfParams.dwEapFlags &= ~EAPOL_ENABLED;
  272. dwErr = WZCEapolSetInterfaceParams (
  273. NULL,
  274. wszIntfGuid,
  275. &m_EapolIntfParams);
  276. if (dwErrOverall != ERROR_SUCCESS)
  277. {
  278. dwErr = dwErrOverall;
  279. }
  280. return dwErr;
  281. }
  282. //+---------------------------------------------------------------------------
  283. BOOL CEapolConfig::Is8021XEnabled()
  284. {
  285. return (IS_EAPOL_ENABLED(m_EapolIntfParams.dwEapFlags));
  286. }
  287. //+---------------------------------------------------------------------------
  288. VOID CEapolConfig::Set8021XState(BOOLEAN fSet)
  289. {
  290. if (fSet)
  291. m_EapolIntfParams.dwEapFlags |= EAPOL_ENABLED;
  292. else
  293. m_EapolIntfParams.dwEapFlags &= ~EAPOL_ENABLED;
  294. }