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.

324 lines
7.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: cncting.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // cncting.cpp : implementation file
  11. //
  12. #include "stdafx.h"
  13. #include "cncting.h"
  14. #include "rtrutilp.h"
  15. #include "rtrstr.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. // Windows NT Bugs : 82409
  22. // Something is sending a WM_USER message through when we click on the
  23. // edit control. To avoid that conflict, renumber the request complete
  24. // message.
  25. #define WM_RTR_REQUEST_COMPLETED (WM_USER+0x0100)
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CConnectRequest
  28. UINT ConnectThread(LPVOID pParam)
  29. {
  30. CConnectData *pData = (CConnectData*)pParam;
  31. pData->m_pfnConnect(pData);
  32. if (!::IsWindow(pData->m_hwndMsg))
  33. {
  34. delete pData;
  35. }
  36. else
  37. {
  38. ::PostMessage(pData->m_hwndMsg, WM_RTR_REQUEST_COMPLETED, (WPARAM)pData, NULL);
  39. }
  40. return 0;
  41. }
  42. void ConnectToMachine(CConnectData* pParam)
  43. {
  44. pParam->m_dwr = ValidateUserPermissions(pParam->m_sName,
  45. &pParam->m_routerVersion,
  46. &pParam->m_hkMachine);
  47. }
  48. void ConnectToDomain(CConnectData* pParam)
  49. {
  50. DWORD dwTotal;
  51. PWSTR pszDomain;
  52. ASSERT(!pParam->m_sName.IsEmpty());
  53. // Although the API excepts TCHAR it is exclusively UNICODE
  54. pszDomain = new WCHAR[pParam->m_sName.GetLength() + 1];
  55. wcscpy(pszDomain, pParam->m_sName);
  56. pParam->m_pSvInfo100 = NULL;
  57. pParam->m_dwr = (DWORD)::NetServerEnum(NULL, 100,
  58. (LPBYTE*)&pParam->m_pSvInfo100, 0xffffffff,
  59. &pParam->m_dwSvInfoRead, &dwTotal, SV_TYPE_DIALIN_SERVER,
  60. (PTSTR)pszDomain, NULL);
  61. delete [] pszDomain;
  62. }
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CConnectingDlg dialog
  65. CConnectingDlg::CConnectingDlg(CWnd* pParent /*=NULL*/)
  66. : CDialog(CConnectingDlg::IDD, pParent)
  67. {
  68. m_bRouter = TRUE;
  69. //{{AFX_DATA_INIT(CConnectingDlg)
  70. m_sName = _T("");
  71. //}}AFX_DATA_INIT
  72. }
  73. void CConnectingDlg::DoDataExchange(CDataExchange* pDX)
  74. {
  75. CDialog::DoDataExchange(pDX);
  76. //{{AFX_DATA_MAP(CConnectingDlg)
  77. DDX_Text(pDX, IDC_EDIT_MACHINENAME, m_sName);
  78. //}}AFX_DATA_MAP
  79. }
  80. BEGIN_MESSAGE_MAP(CConnectingDlg, CDialog)
  81. //{{AFX_MSG_MAP(CConnectingDlg)
  82. //}}AFX_MSG_MAP
  83. ON_MESSAGE(WM_RTR_REQUEST_COMPLETED, OnRequestComplete)
  84. END_MESSAGE_MAP()
  85. /////////////////////////////////////////////////////////////////////////////
  86. // CConnectingDlg message handlers
  87. BOOL CConnectingDlg::OnInitDialog()
  88. {
  89. CDialog::OnInitDialog();
  90. CConnectData *pData = new CConnectData;
  91. pData->m_sName = m_sName;
  92. pData->m_hwndMsg = m_hWnd;
  93. if (m_bRouter)
  94. {
  95. pData->m_pfnConnect = ConnectToMachine;
  96. }
  97. else
  98. {
  99. pData->m_pfnConnect = ConnectToDomain;
  100. }
  101. m_pThread = AfxBeginThread((AFX_THREADPROC)ConnectThread, (LPVOID)pData);
  102. if (!m_pThread) EndDialog(IDCANCEL);
  103. return TRUE;
  104. }
  105. LRESULT CConnectingDlg::OnRequestComplete(WPARAM wParam, LPARAM lParam)
  106. {
  107. CConnectData *pData = (CConnectData*)wParam;
  108. if (!pData) { EndDialog(IDCANCEL); return 0; }
  109. m_dwr = pData->m_dwr;
  110. if (m_dwr != ERROR_SUCCESS)
  111. {
  112. EndDialog(m_dwr);
  113. delete pData;
  114. return 0L;
  115. }
  116. if (m_bRouter)
  117. m_hkMachine = pData->m_hkMachine;
  118. else
  119. {
  120. m_pSvInfo100 = pData->m_pSvInfo100;
  121. m_dwSvInfoRead = pData->m_dwSvInfoRead;
  122. }
  123. delete pData;
  124. EndDialog(IDOK);
  125. return 0L;
  126. }
  127. BOOL CConnectingDlg::Connect()
  128. {
  129. CConnectData Data;
  130. Data.m_sName = m_sName;
  131. Data.m_hwndMsg = m_hWnd;
  132. if (m_bRouter)
  133. {
  134. Data.m_pfnConnect = ConnectToMachine;
  135. }
  136. else
  137. {
  138. Data.m_pfnConnect = ConnectToDomain;
  139. }
  140. CWaitCursor wc;
  141. Data.m_pfnConnect(&Data);
  142. // setup all of the data from the connection
  143. m_dwr = Data.m_dwr;
  144. if (m_dwr != ERROR_SUCCESS)
  145. {
  146. return FALSE;
  147. }
  148. if (m_bRouter)
  149. m_hkMachine = Data.m_hkMachine;
  150. else
  151. {
  152. m_pSvInfo100 = Data.m_pSvInfo100;
  153. m_dwSvInfoRead = Data.m_dwSvInfoRead;
  154. }
  155. return TRUE;
  156. }
  157. /*!--------------------------------------------------------------------------
  158. ValidateUserPermissions
  159. Check to see if we can access the places we need to access
  160. Returns HRESULT_OK if the user has the proper access.
  161. Returns E_ACCESSDENIED if the user does not have proper access.
  162. Returns error otherwise.
  163. Author: KennT
  164. ---------------------------------------------------------------------------*/
  165. DWORD ValidateUserPermissions(LPCTSTR pszServer,
  166. RouterVersionInfo *pVersion,
  167. HKEY *phkeyMachine)
  168. {
  169. HKEY hkMachine = NULL;
  170. RegKey regkey;
  171. RouterVersionInfo routerVersion;
  172. HRESULT hr = hrOK;
  173. DWORD dwErr = ERROR_SUCCESS;
  174. dwErr = ValidateMachine(pszServer);
  175. if (dwErr != ERROR_SUCCESS)
  176. goto Error;
  177. // connect to the machine's registry
  178. dwErr = ConnectRegistry((LPTSTR) pszServer,
  179. &hkMachine);
  180. if(dwErr != ERROR_SUCCESS)
  181. goto Error;
  182. // There are three cases to consider here:
  183. // (1) NT4 RAS server (no router keys)
  184. // (2) NT4 RRAS (NT4+Steelhead)
  185. // (3) NT5
  186. // ----------------------------------------------------------------
  187. // Get the version information
  188. // ----------------------------------------------------------------
  189. hr = QueryRouterVersionInfo(hkMachine, &routerVersion);
  190. if (!FHrOK(hr))
  191. {
  192. dwErr = (hr & 0x0000FFFF);
  193. goto Error;
  194. }
  195. // Copy the version info over.
  196. // ----------------------------------------------------------------
  197. if (pVersion)
  198. *pVersion = routerVersion;
  199. else
  200. pVersion = &routerVersion;
  201. // This test is intended for the RAS server case.
  202. // ----------------------------------------------------------------
  203. if (routerVersion.dwOsMajorVersion <= 4)
  204. {
  205. // If we can't find the router key, we can skip the rest of the
  206. // tests. We do assume that everything succeeded however.
  207. // ----------------------------------------------------------------
  208. dwErr = regkey.Open(hkMachine, c_szRegKeyRouter, KEY_READ);
  209. if (dwErr == ERROR_FILE_NOT_FOUND)
  210. {
  211. // Could not find the router key, however this may
  212. // be a NT4 RAS server (no Steelhead), so return success
  213. // --------------------------------------------------------
  214. goto Done;
  215. }
  216. else if (dwErr != ERROR_SUCCESS)
  217. goto Error;
  218. // If we could find the router key, then we can continue with
  219. // the other registry tests.
  220. // ------------------------------------------------------------
  221. regkey.Close();
  222. }
  223. // open HKLM\Software\Microsoft\Router\CurrentVersion\RouterManagers
  224. // ----------------------------------------------------------------
  225. dwErr = regkey.Open(hkMachine, c_szRouterManagersKey, KEY_ALL_ACCESS);
  226. if(dwErr != ERROR_SUCCESS)
  227. goto Error;
  228. regkey.Close();
  229. // open c_szSystemCCSServices HKLM\System\\CurrentControlSet\\Services
  230. // ----------------------------------------------------------------
  231. {
  232. RegKey regFolder;
  233. dwErr = regFolder.Open(hkMachine, c_szSystemCCSServices, KEY_READ);
  234. if(dwErr != ERROR_SUCCESS)
  235. goto Error;
  236. // sub keys under Services -- remoteAccess, RW
  237. dwErr = regkey.Open(regFolder, c_szRemoteAccess, KEY_ALL_ACCESS);
  238. if(dwErr != ERROR_SUCCESS)
  239. goto Error;
  240. regkey.Close();
  241. // sub keys under Services -- rasman, RW
  242. dwErr = regkey.Open(regFolder, c_szSvcRasMan, KEY_ALL_ACCESS);
  243. if(dwErr != ERROR_SUCCESS)
  244. goto Error;
  245. regkey.Close();
  246. // sub keys under Services -- TcpIp, RW
  247. dwErr = regkey.Open(regFolder, c_szTcpip, KEY_ALL_ACCESS);
  248. if(dwErr != ERROR_SUCCESS)
  249. goto Error;
  250. regkey.Close();
  251. regFolder.Close();
  252. }
  253. Done:
  254. if (phkeyMachine)
  255. {
  256. *phkeyMachine = hkMachine;
  257. hkMachine = NULL;
  258. }
  259. Error:
  260. if(hkMachine != NULL)
  261. DisconnectRegistry( hkMachine );
  262. return dwErr;
  263. }