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.

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