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.

428 lines
9.6 KiB

  1. /*
  2. Copyright (c) 1997, Microsoft Corporation, all rights reserved
  3. Description:
  4. History:
  5. */
  6. #include <nt.h> // Required by windows.h
  7. #include <ntrtl.h> // Required by windows.h
  8. #include <nturtl.h> // Required by windows.h
  9. #include <windows.h> // Win32 base API's
  10. #include <schannel.h>
  11. #define SECURITY_WIN32
  12. #include <sspi.h> // For CredHandle
  13. #include <wincrypt.h> // Required by sclogon.h
  14. #include <eaptypeid.h>
  15. #include <rasauth.h> // Required by raseapif.h
  16. #include <eaptypeid.h>
  17. #include <raseapif.h>
  18. #include <rasman.h> // For EAPLOGONINFO
  19. #include "eaptls.h"
  20. #include "ceapcfg.h"
  21. extern "C"
  22. DWORD
  23. InvokeServerConfigUI(
  24. IN HWND hWnd,
  25. IN WCHAR* pwszMachineName
  26. );
  27. extern "C"
  28. DWORD
  29. WINAPI PeapInvokeServerConfigUI ( IN HWND hWnd,
  30. IN WCHAR * pwszMachineName
  31. );
  32. extern "C"
  33. DWORD
  34. EapTlsInvokeIdentityUI(
  35. IN BOOL fServer,
  36. IN BOOL fRouterConfig,
  37. IN DWORD dwFlags,
  38. IN WCHAR* pszStoreName,
  39. IN const WCHAR* pwszPhonebook,
  40. IN const WCHAR* pwszEntry,
  41. IN HWND hwndParent,
  42. IN BYTE* pConnectionDataIn,
  43. IN DWORD dwSizeOfConnectionDataIn,
  44. IN BYTE* pUserDataIn,
  45. IN DWORD dwSizeOfUserDataIn,
  46. OUT BYTE** ppUserDataOut,
  47. OUT DWORD* pdwSizeOfUserDataOut,
  48. OUT WCHAR** ppwszIdentity
  49. );
  50. extern "C"
  51. DWORD
  52. RasEapInvokeConfigUI(
  53. IN DWORD dwEapTypeId,
  54. IN HWND hwndParent,
  55. IN DWORD dwFlags,
  56. IN BYTE* pConnectionDataIn,
  57. IN DWORD dwSizeOfConnectionDataIn,
  58. OUT BYTE** ppConnectionDataOut,
  59. OUT DWORD* pdwSizeOfConnectionDataOut
  60. );
  61. extern "C"
  62. DWORD
  63. RasEapFreeMemory(
  64. IN BYTE* pMemory
  65. );
  66. /*
  67. Returns:
  68. Notes:
  69. Implementation of IEAPProviderConfig::Initialize
  70. */
  71. STDMETHODIMP
  72. CEapCfg::Initialize(
  73. LPCOLESTR pwszMachineName,
  74. DWORD dwEapTypeId,
  75. ULONG_PTR* puConnectionParam
  76. )
  77. {
  78. size_t size;
  79. WCHAR* pwsz = NULL;
  80. DWORD dwErr = NO_ERROR;
  81. *puConnectionParam = NULL;
  82. if (dwEapTypeId != PPP_EAP_TLS && dwEapTypeId != PPP_EAP_PEAP)
  83. {
  84. dwErr = ERROR_NOT_SUPPORTED;
  85. goto LDone;
  86. }
  87. size = wcslen(pwszMachineName);
  88. pwsz = (WCHAR*) LocalAlloc(LPTR, (size + 1)*sizeof(WCHAR));
  89. if (NULL == pwsz)
  90. {
  91. dwErr = GetLastError();
  92. goto LDone;
  93. }
  94. CopyMemory(pwsz, pwszMachineName, (size + 1)*sizeof(WCHAR));
  95. *puConnectionParam = (ULONG_PTR)pwsz;
  96. pwsz = NULL;
  97. LDone:
  98. LocalFree(pwsz);
  99. return(HRESULT_FROM_WIN32(dwErr));
  100. }
  101. /*
  102. Returns:
  103. Notes:
  104. Implementation of IEAPProviderConfig::Uninitialize
  105. */
  106. STDMETHODIMP
  107. CEapCfg::Uninitialize(
  108. DWORD dwEapTypeId,
  109. ULONG_PTR uConnectionParam
  110. )
  111. {
  112. LocalFree((VOID*)uConnectionParam);
  113. return(HRESULT_FROM_WIN32(NO_ERROR));
  114. }
  115. /*
  116. Returns:
  117. Notes:
  118. Implementation of IEAPProviderConfig::ServerInvokeConfigUI
  119. hWnd - handle to the parent window
  120. dwRes1 - reserved parameter (ignore)
  121. dwRes2 - reserved parameter (ignore)
  122. */
  123. STDMETHODIMP
  124. CEapCfg::ServerInvokeConfigUI(
  125. DWORD dwEapTypeId,
  126. ULONG_PTR uConnectionParam,
  127. HWND hWnd,
  128. DWORD_PTR dwRes1,
  129. DWORD_PTR dwRes2
  130. )
  131. {
  132. WCHAR* pwszMachineName;
  133. HRESULT hr;
  134. DWORD dwErr;
  135. if (dwEapTypeId != PPP_EAP_TLS
  136. #ifdef IMPL_PEAP
  137. && dwEapTypeId != PPP_EAP_PEAP
  138. #endif
  139. )
  140. {
  141. dwErr = ERROR_NOT_SUPPORTED;
  142. goto LDone;
  143. }
  144. pwszMachineName = (WCHAR*)uConnectionParam;
  145. if (NULL == pwszMachineName)
  146. {
  147. dwErr = E_FAIL;
  148. }
  149. else
  150. {
  151. if ( dwEapTypeId == PPP_EAP_TLS )
  152. {
  153. dwErr = InvokeServerConfigUI(hWnd, pwszMachineName);
  154. }
  155. #ifdef IMPL_PEAP
  156. else
  157. {
  158. dwErr = PeapInvokeServerConfigUI(hWnd, pwszMachineName);
  159. }
  160. #endif
  161. }
  162. LDone:
  163. hr = HRESULT_FROM_WIN32(dwErr);
  164. return(hr);
  165. }
  166. /*
  167. Returns:
  168. Notes:
  169. Implementation of IEAPProviderConfig::RouterInvokeConfigUI
  170. */
  171. STDMETHODIMP
  172. CEapCfg::RouterInvokeConfigUI(
  173. DWORD dwEapTypeId,
  174. ULONG_PTR uConnectionParam,
  175. HWND hwndParent,
  176. DWORD dwFlags,
  177. BYTE* pConnectionDataIn,
  178. DWORD dwSizeOfConnectionDataIn,
  179. BYTE** ppConnectionDataOut,
  180. DWORD* pdwSizeOfConnectionDataOut
  181. )
  182. {
  183. DWORD dwErr = NO_ERROR;
  184. BYTE* pConnectionDataOut = NULL;
  185. DWORD dwSizeOfConnectionDataOut = 0;
  186. *ppConnectionDataOut = NULL;
  187. *pdwSizeOfConnectionDataOut = 0;
  188. if (dwEapTypeId != PPP_EAP_TLS )
  189. {
  190. dwErr = ERROR_NOT_SUPPORTED;
  191. goto LDone;
  192. }
  193. dwErr = RasEapInvokeConfigUI(
  194. dwEapTypeId,
  195. hwndParent,
  196. dwFlags,
  197. pConnectionDataIn,
  198. dwSizeOfConnectionDataIn,
  199. &pConnectionDataOut,
  200. &dwSizeOfConnectionDataOut);
  201. if ( (NO_ERROR == dwErr)
  202. && (0 != dwSizeOfConnectionDataOut))
  203. {
  204. *ppConnectionDataOut = (BYTE*)CoTaskMemAlloc(dwSizeOfConnectionDataOut);
  205. if (NULL == *ppConnectionDataOut)
  206. {
  207. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  208. goto LDone;
  209. }
  210. CopyMemory(*ppConnectionDataOut, pConnectionDataOut,
  211. dwSizeOfConnectionDataOut);
  212. *pdwSizeOfConnectionDataOut = dwSizeOfConnectionDataOut;
  213. }
  214. LDone:
  215. RasEapFreeMemory(pConnectionDataOut);
  216. return(HRESULT_FROM_WIN32(dwErr));
  217. }
  218. /*
  219. Returns:
  220. Notes:
  221. Implementation of IEAPProviderConfig::RouterInvokeCredentialsUI
  222. */
  223. STDMETHODIMP
  224. CEapCfg::RouterInvokeCredentialsUI(
  225. DWORD dwEapTypeId,
  226. ULONG_PTR uConnectionParam,
  227. HWND hwndParent,
  228. DWORD dwFlags,
  229. BYTE* pConnectionDataIn,
  230. DWORD dwSizeOfConnectionDataIn,
  231. BYTE* pUserDataIn,
  232. DWORD dwSizeOfUserDataIn,
  233. BYTE** ppUserDataOut,
  234. DWORD* pdwSizeOfUserDataOut
  235. )
  236. {
  237. #define MAX_STORE_NAME_LENGTH MAX_COMPUTERNAME_LENGTH + 20
  238. WCHAR awszStoreName[MAX_STORE_NAME_LENGTH + 1];
  239. DWORD dwErr;
  240. DWORD dwSizeOfUserDataOut;
  241. BYTE* pUserDataOut = NULL;
  242. WCHAR* pwszIdentityOut = NULL;
  243. WCHAR* pwszMachineName;
  244. BOOL fLocal = FALSE;
  245. *ppUserDataOut = NULL;
  246. *pdwSizeOfUserDataOut = 0;
  247. if (dwEapTypeId != PPP_EAP_TLS )
  248. {
  249. dwErr = ERROR_NOT_SUPPORTED;
  250. goto LDone;
  251. }
  252. pwszMachineName = (WCHAR*)uConnectionParam;
  253. if (0 == *pwszMachineName)
  254. {
  255. fLocal = TRUE;
  256. }
  257. wcscpy(awszStoreName, L"\\\\");
  258. wcsncat(awszStoreName, pwszMachineName, MAX_COMPUTERNAME_LENGTH);
  259. wcsncat(awszStoreName, L"\\MY", wcslen(L"\\MY"));
  260. if ( dwEapTypeId == PPP_EAP_TLS )
  261. {
  262. dwErr = EapTlsInvokeIdentityUI(
  263. FALSE /* fServer */,
  264. TRUE /* fRouterConfig */,
  265. dwFlags,
  266. fLocal ? L"MY" : awszStoreName,
  267. L"",
  268. L"",
  269. hwndParent,
  270. pConnectionDataIn,
  271. dwSizeOfConnectionDataIn,
  272. pUserDataIn,
  273. dwSizeOfUserDataIn,
  274. &pUserDataOut,
  275. &dwSizeOfUserDataOut,
  276. &pwszIdentityOut);
  277. if ( (NO_ERROR == dwErr)
  278. && (0 != dwSizeOfUserDataOut))
  279. {
  280. *ppUserDataOut = (BYTE*)CoTaskMemAlloc(dwSizeOfUserDataOut);
  281. if (NULL == *ppUserDataOut)
  282. {
  283. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  284. goto LDone;
  285. }
  286. CopyMemory(*ppUserDataOut, pUserDataOut, dwSizeOfUserDataOut);
  287. *pdwSizeOfUserDataOut = dwSizeOfUserDataOut;
  288. }
  289. }
  290. else
  291. {
  292. //Show PEAP dialog to get identity for router...
  293. }
  294. LDone:
  295. RasEapFreeMemory(pUserDataOut);
  296. RasEapFreeMemory((BYTE*)pwszIdentityOut);
  297. return(HRESULT_FROM_WIN32(dwErr));
  298. }
  299. extern "C"
  300. {
  301. //utility function kept here so that we dont have to get the COM junk in other files
  302. DWORD PeapEapInfoInvokeServerConfigUI ( HWND hWndParent,
  303. LPWSTR lpwszMachineName,
  304. PPEAP_EAP_INFO pEapInfo
  305. )
  306. {
  307. DWORD dwRetCode = NO_ERROR;
  308. GUID guid;
  309. HRESULT hr = S_OK;
  310. ULONG_PTR uConnection = 0;
  311. CComPtr<IEAPProviderConfig> spEAPConfig;
  312. hr = CLSIDFromString(pEapInfo->lpwszConfigClsId, &guid);
  313. if (FAILED(hr)) goto L_ERR;
  314. // Create the EAP provider object
  315. // ----------------------------------------------------------------
  316. hr = CoCreateInstance( guid,
  317. NULL,
  318. CLSCTX_INPROC_SERVER,
  319. __uuidof(IEAPProviderConfig),
  320. (LPVOID *) &spEAPConfig);
  321. if (FAILED(hr )) goto L_ERR;
  322. // Configure this EAP provider
  323. // ----------------------------------------------------------------
  324. // EAP configure displays its own error message, so no hr is kept
  325. if ( !FAILED(spEAPConfig->Initialize(lpwszMachineName, pEapInfo->dwTypeId, &uConnection)) )
  326. {
  327. spEAPConfig->ServerInvokeConfigUI(pEapInfo->dwTypeId, uConnection, hWndParent, 0, 0);
  328. spEAPConfig->Uninitialize(pEapInfo->dwTypeId, uConnection);
  329. }
  330. if ( hr == E_NOTIMPL )
  331. hr = S_OK;
  332. L_ERR:
  333. if ( FAILED(hr) )
  334. {
  335. dwRetCode = hr;
  336. }
  337. return dwRetCode;
  338. }
  339. }