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.

396 lines
13 KiB

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