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.

267 lines
8.0 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "CWANPPPConnectionService.h"
  4. #include "ndispnp.h"
  5. #include "ras.h"
  6. #include "rasuip.h"
  7. #include "util.h"
  8. #include "raserror.h"
  9. #include "rasdlg.h"
  10. CWANPPPConnectionService::CWANPPPConnectionService()
  11. {
  12. m_dwLastConnectionError = 0;
  13. }
  14. HRESULT CWANPPPConnectionService::get_LastConnectionError(BSTR *pLastConnectionError)
  15. {
  16. HRESULT hr = S_OK;
  17. LPOLESTR pszError = NULL;
  18. switch(m_dwLastConnectionError)
  19. {
  20. case 0:
  21. pszError = L"ERROR_NONE";
  22. break;
  23. case ERROR_PPP_TIMEOUT:
  24. case ERROR_REQUEST_TIMEOUT:
  25. pszError = L"ERROR_ISP_TIME_OUT";
  26. break;
  27. // case : // no mapping
  28. // pszError = L"ERROR_COMMAND_ABORTED";
  29. // break;
  30. // case : // no mapping
  31. // pszError = L"ERROR_NOT_ENABLED_FOR_INTERNET";
  32. // break;
  33. case ERROR_BAD_PHONE_NUMBER:
  34. pszError = L"ERROR_BAD_PHONE_NUMBER";
  35. break;
  36. case ERROR_USER_DISCONNECTION:
  37. pszError = L"ERROR_USER_DISCONNECT";
  38. break;
  39. case ERROR_REMOTE_DISCONNECTION:
  40. pszError = L"ERROR_ISP_DISCONNECT";
  41. break;
  42. // case : // no mapping
  43. // pszError = L"ERROR_IDLE_DISCONNECT";
  44. // break;
  45. // case : // no mapping
  46. // pszError = L"ERROR_FORCED_DISCONNECT";
  47. // break;
  48. case ERROR_SERVER_OUT_OF_RESOURCES:
  49. pszError = L"ERROR_SERVER_OUT_OF_RESOURCES";
  50. break;
  51. case ERROR_RESTRICTED_LOGON_HOURS:
  52. pszError = L"ERROR_RESTRICTED_LOGON_HOURS";
  53. break;
  54. case ERROR_ACCT_DISABLED:
  55. pszError = L"ERROR_ACCOUNT_DISABLED";
  56. break;
  57. case ERROR_ACCT_EXPIRED:
  58. pszError = L"ERROR_ACCOUNT_EXPIRED";
  59. break;
  60. case ERROR_PASSWD_EXPIRED:
  61. pszError = L"ERROR_PASSWORD_EXPIRED";
  62. break;
  63. case ERROR_AUTHENTICATION_FAILURE:
  64. pszError = L"ERROR_AUTHENTICATION_FAILURE";
  65. break;
  66. case ERROR_NO_DIALTONE:
  67. pszError = L"ERROR_NO_DIALTONE";
  68. break;
  69. case ERROR_NO_CARRIER:
  70. pszError = L"ERROR_NO_CARRIER";
  71. break;
  72. case ERROR_NO_ANSWER:
  73. pszError = L"ERROR_NO_ANSWER";
  74. break;
  75. case ERROR_LINE_BUSY:
  76. pszError = L"ERROR_LINE_BUSY";
  77. break;
  78. case ERROR_UNSUPPORTED_BPS:
  79. pszError = L"ERROR_UNSUPPORTED_BITSPERSECOND";
  80. break;
  81. case ERROR_TOO_MANY_LINE_ERRORS:
  82. pszError = L"ERROR_TOO_MANY_LINE_ERRORS";
  83. break;
  84. case ERROR_IP_CONFIGURATION:
  85. pszError = L"ERROR_IP_CONFIGURATION";
  86. break;
  87. default:
  88. pszError = L"ERROR_UNKNOWN";
  89. break;
  90. }
  91. *pLastConnectionError = SysAllocString(pszError);
  92. if(NULL == *pLastConnectionError)
  93. {
  94. hr = E_OUTOFMEMORY;
  95. }
  96. return hr;
  97. }
  98. HRESULT CWANPPPConnectionService::RequestConnection(void)
  99. {
  100. HRESULT hr = S_OK;
  101. m_dwLastConnectionError = 0;
  102. hr = ControlEnabled();
  103. if(SUCCEEDED(hr))
  104. {
  105. DWORD dwErr;
  106. RASSHARECONN rsc;
  107. dwErr = RasQuerySharedConnection(&rsc);
  108. if(NO_ERROR == dwErr)
  109. {
  110. RASCREDENTIALSW rc;
  111. rc.dwSize = sizeof(rc);
  112. rc.dwMask = RASCM_UserName | RASCM_Password | RASCM_Domain | RASCM_DefaultCreds;
  113. dwErr = RasGetCredentials(rsc.name.szPhonebookPath, rsc.name.szEntryName, &rc);
  114. if (NO_ERROR == dwErr)
  115. {
  116. RASDIALEXTENSIONS rde;
  117. RASDIALPARAMSW rdp;
  118. ZeroMemory(&rde, sizeof(rde));
  119. rde.dwSize = sizeof(rde);
  120. rde.dwfOptions = RDEOPT_NoUser;
  121. ZeroMemory(&rdp, sizeof(rdp));
  122. rdp.dwSize = sizeof(rdp);
  123. lstrcpyW(rdp.szEntryName, rsc.name.szEntryName);
  124. lstrcpyW(rdp.szUserName, rc.szUserName);
  125. lstrcpyW(rdp.szDomain, rc.szDomain);
  126. lstrcpyW(rdp.szPassword, rc.szPassword);
  127. ZeroMemory(&rc, sizeof(rc)); // zero crendentials
  128. HRASCONN hrasconn = NULL;
  129. dwErr = RasDial(&rde, rsc.name.szPhonebookPath, &rdp, 0, NULL, &hrasconn);
  130. ZeroMemory(&rdp, sizeof(rdp)); // zero credentials
  131. if (E_NOTIMPL == dwErr)
  132. {
  133. //
  134. // This is possibly a Connection Manager connection since it's returning E_NOTIMPL,
  135. // we should check the phonebook entry for the type and then call the RasDialDlg
  136. // with the RASDDFLAG_NoPrompt flag.
  137. //
  138. RASDIALDLG info;
  139. BOOL fRetVal = FALSE;
  140. RASENTRY re;
  141. DWORD dwRasEntrySize;
  142. DWORD dwIgnore;
  143. HINSTANCE hRasDlgDll = NULL;
  144. FARPROC lpfnRasDialDlg = NULL;
  145. typedef BOOL (*lpfnRasDialDlgFunc)(LPWSTR, LPWSTR, LPWSTR, LPRASDIALDLG);
  146. ZeroMemory(&info, sizeof(info));
  147. info.dwSize = sizeof(info);
  148. ZeroMemory(&re, sizeof(re));
  149. dwRasEntrySize = sizeof(re);
  150. re.dwSize = dwRasEntrySize;
  151. dwErr = RasGetEntryProperties(
  152. rsc.name.szPhonebookPath,
  153. rsc.name.szEntryName,
  154. &re,
  155. &dwRasEntrySize,
  156. NULL,
  157. &dwIgnore);
  158. if (ERROR_SUCCESS == dwErr)
  159. {
  160. dwErr = ERROR_NOT_SUPPORTED;
  161. //
  162. // Check if this is a Connection Manager entry
  163. //
  164. if (RASET_Internet == re.dwType)
  165. {
  166. //
  167. // Prevent the DialerDialog
  168. //
  169. info.dwFlags |= RASDDFLAG_NoPrompt;
  170. hRasDlgDll = LoadLibrary(L"RASDLG.DLL");
  171. if (hRasDlgDll)
  172. {
  173. lpfnRasDialDlgFunc lpfnRasDialDlg = (lpfnRasDialDlgFunc)GetProcAddress(hRasDlgDll, "RasDialDlgW");
  174. if (lpfnRasDialDlg)
  175. {
  176. fRetVal = (BOOL)(lpfnRasDialDlg)(rsc.name.szPhonebookPath, rsc.name.szEntryName, NULL, &info );
  177. if (fRetVal)
  178. {
  179. dwErr = NO_ERROR;
  180. }
  181. }
  182. FreeLibrary(hRasDlgDll);
  183. hRasDlgDll = NULL;
  184. }
  185. }
  186. }
  187. }
  188. m_dwLastConnectionError = dwErr;
  189. if(NO_ERROR != dwErr)
  190. {
  191. hr = E_FAIL;
  192. if(NULL != hrasconn)
  193. {
  194. RasHangUp(hrasconn);
  195. }
  196. }
  197. }
  198. else
  199. {
  200. hr = E_FAIL;
  201. }
  202. }
  203. else
  204. {
  205. hr = E_FAIL;
  206. }
  207. if(FAILED(hr))
  208. {
  209. SetUPnPError(DCP_ERROR_CONNECTIONSETUPFAILED);
  210. }
  211. }
  212. else
  213. {
  214. SetUPnPError(DCP_CUSTOM_ERROR_ACCESSDENIED);
  215. }
  216. return hr;
  217. }
  218. HRESULT CWANPPPConnectionService::ForceTermination(void)
  219. {
  220. HRESULT hr = S_OK;
  221. hr = ControlEnabled();
  222. if(SUCCEEDED(hr))
  223. {
  224. INetConnection* pNetConnection;
  225. hr = m_pHomenetConnection->GetINetConnection(&pNetConnection);
  226. if(SUCCEEDED(hr))
  227. {
  228. hr = pNetConnection->Disconnect();
  229. pNetConnection->Release();
  230. }
  231. }
  232. else
  233. {
  234. SetUPnPError(DCP_CUSTOM_ERROR_ACCESSDENIED);
  235. }
  236. return hr;
  237. }