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.

3069 lines
96 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. machine.pp
  7. FILE HISTORY:
  8. Wei Jiang : 5/7/98 --- SECURE_ROUTERINFO
  9. Postpone the loading of router info
  10. Added function calls SecureRouterInfo before each usage of
  11. router info to make sure router info is loaded.
  12. Wei Jiang : 10/26/98 --- Move Auto Refresh from "Router Interfaces" node to machine node.
  13. Wei Jiang : 10/27/98 --- Move Auto Refresh from "Machine" node to Root node, multiple machine shares
  14. the same auto refresh settings.
  15. */
  16. #include "stdafx.h"
  17. #include "root.h"
  18. #include "machine.h"
  19. #include "ifadmin.h"
  20. #include "dialin.h"
  21. #include "ports.h"
  22. #include "rtrutilp.h" // InitiateServerConnection
  23. #include "rtrcfg.h"
  24. #include "rtrwiz.h"
  25. #include "cservice.h"
  26. #include <htmlhelp.h>
  27. #include "rrasqry.h"
  28. #include "rtrres.h"
  29. #include "dumbprop.h" // dummy property page
  30. #include "refresh.h"
  31. #include "refrate.h"
  32. #include "cncting.h"
  33. #include "dvsview.h"
  34. #include "rrasutil.h"
  35. #include "rtrcomn.h"
  36. #include "routprot.h" // MS_IP_XXX
  37. #include "raputil.h"
  38. // result message view stuff
  39. #define MACHINE_MESSAGE_MAX_STRING 5
  40. typedef enum _MACHINE_MESSAGES
  41. {
  42. MACHINE_MESSAGE_NOT_CONFIGURED,
  43. MACHINE_MESSAGE_MAX
  44. };
  45. UINT g_uMachineMessages[MACHINE_MESSAGE_MAX][MACHINE_MESSAGE_MAX_STRING] =
  46. {
  47. {IDS_MACHINE_MESSAGE_TITLE, Icon_Information, IDS_MACHINE_MESSAGE_BODY1, IDS_MACHINE_MESSAGE_BODY2, 0},
  48. };
  49. extern "C"
  50. {
  51. typedef struct _RAS_SERVER_0
  52. {
  53. WORD TotalPorts; // Total ports configured on the server
  54. WORD PortsInUse; // Ports currently in use by remote clients
  55. DWORD RasVersion; // version of RAS server
  56. } RAS_SERVER_0, *PRAS_SERVER_0;
  57. DWORD APIENTRY RasAdminServerGetInfo(
  58. IN const WCHAR * lpszServer,
  59. OUT PRAS_SERVER_0 pRasServer0
  60. );
  61. };
  62. // if you want to test Qry
  63. // #define __RRAS_QRY_TEST // to test the component
  64. //
  65. #ifdef __RRAS_QRY_TEST
  66. #include "dlgtestdlg.h"
  67. #endif
  68. static CString c_stStatUnavail;
  69. static CString c_stStatNotConfig;
  70. static CString c_stStatAccessDenied;
  71. static CString c_stServiceStopped;
  72. static CString c_stServiceStartPending;
  73. static CString c_stServiceStopPending;
  74. static CString c_stServiceRunning;
  75. static CString c_stServiceContinuePending;
  76. static CString c_stServicePausePending;
  77. static CString c_stServicePaused;
  78. static CString c_stServiceStateUnknown;
  79. const CStringMapEntry ServiceStateMap[] =
  80. {
  81. { SERVICE_STOPPED, &c_stServiceStopped, IDS_SERVICE_STOPPED },
  82. { SERVICE_START_PENDING, &c_stServiceStartPending, IDS_SERVICE_START_PENDING },
  83. { SERVICE_STOP_PENDING, &c_stServiceStopPending, IDS_SERVICE_STOP_PENDING },
  84. { SERVICE_RUNNING, &c_stServiceRunning, IDS_SERVICE_RUNNING },
  85. { SERVICE_CONTINUE_PENDING, &c_stServiceContinuePending, IDS_SERVICE_CONTINUE_PENDING },
  86. { SERVICE_PAUSE_PENDING, &c_stServicePausePending, IDS_SERVICE_PAUSE_PENDING },
  87. { SERVICE_PAUSED, &c_stServicePaused, IDS_SERVICE_PAUSED },
  88. { -1, &c_stServiceStateUnknown, IDS_SERVICE_UNKNOWN }
  89. };
  90. CString& ServiceStateToCString(DWORD dwState)
  91. {
  92. return MapDWORDToCString(dwState, ServiceStateMap);
  93. }
  94. DEBUG_DECLARE_INSTANCE_COUNTER(MachineNodeData);
  95. MachineNodeData::MachineNodeData()
  96. {
  97. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  98. m_cRef = 1;
  99. IfDebug(StrCpyA(m_szDebug, "MachineNodeData"));
  100. m_fLocalMachine = TRUE;
  101. m_fAddedAsLocal = TRUE;
  102. m_stMachineName.Empty();
  103. m_fExtension = FALSE;
  104. m_machineState = machine_not_connected;
  105. m_dataState = data_not_loaded;
  106. m_stState.Empty();
  107. m_stServerType.Empty();
  108. m_stBuildNo.Empty();
  109. m_dwPortsInUse = 0;
  110. m_dwPortsTotal = 0;
  111. m_dwUpTime = 0;
  112. m_fStatsRetrieved = FALSE;
  113. m_fIsServer = TRUE;
  114. m_dwServerHandle = 0;
  115. m_hRasAdmin = INVALID_HANDLE_VALUE;
  116. m_routerType = ServerType_Unknown;
  117. m_ulRefreshConnId = 0;
  118. if (c_stStatUnavail.IsEmpty())
  119. c_stStatUnavail.LoadString(IDS_DVS_STATUS_UNAVAILABLE);
  120. if (c_stStatNotConfig.IsEmpty())
  121. c_stStatNotConfig.LoadString(IDS_DVS_STATUS_NOTCONFIG);
  122. if (c_stStatAccessDenied.IsEmpty())
  123. c_stStatAccessDenied.LoadString(IDS_DVS_STATUS_ACCESSDENIED);
  124. DEBUG_INCREMENT_INSTANCE_COUNTER(MachineNodeData);
  125. }
  126. MachineNodeData::~MachineNodeData()
  127. {
  128. if (m_hRasAdmin != INVALID_HANDLE_VALUE)
  129. ::CloseHandle(m_hRasAdmin);
  130. m_hRasAdmin = INVALID_HANDLE_VALUE;
  131. DEBUG_DECREMENT_INSTANCE_COUNTER(MachineNodeData);
  132. }
  133. ULONG MachineNodeData::AddRef()
  134. {
  135. return InterlockedIncrement(&m_cRef);
  136. }
  137. ULONG MachineNodeData::Release()
  138. {
  139. Assert(m_cRef > 0);
  140. if (InterlockedDecrement(&m_cRef) == 0)
  141. {
  142. delete this;
  143. return 0;
  144. }
  145. return m_cRef;
  146. }
  147. HRESULT MachineNodeData::Init(LPCTSTR pszMachineName)
  148. {
  149. HRESULT hr = hrOK;
  150. m_stMachineName = pszMachineName;
  151. m_fAddedAsLocal = m_stMachineName.IsEmpty();
  152. m_fLocalMachine = IsLocalMachine(pszMachineName);
  153. return hr;
  154. }
  155. HRESULT MachineNodeData::Merge(const MachineNodeData& data)
  156. {
  157. m_machineState = data.m_machineState;
  158. m_serviceState = data.m_serviceState;
  159. m_dataState = data.m_dataState;
  160. m_stState = data.m_stState; // "started", "stopped", ...
  161. m_stServerType = data.m_stServerType; // Actually the router version
  162. m_stBuildNo = data.m_stBuildNo; // OS Build no.
  163. m_dwPortsInUse = data.m_dwPortsInUse;
  164. m_dwPortsTotal = data.m_dwPortsTotal;
  165. m_dwUpTime = data.m_dwUpTime;
  166. m_fStatsRetrieved = data.m_fStatsRetrieved;
  167. m_routerType = data.m_routerType;
  168. m_MachineConfig = data.m_MachineConfig;
  169. m_routerVersion = data.m_routerVersion;
  170. return S_OK;
  171. }
  172. HRESULT MachineNodeData::SetDefault()
  173. {
  174. // m_fLocalMachine = TRUE;
  175. // m_stMachineName.Empty();
  176. // m_fExtension = FALSE;
  177. m_machineState = machine_not_connected;
  178. m_dataState = data_not_loaded;
  179. m_serviceState = service_unknown;
  180. m_stState.Empty();
  181. m_stServerType.Empty();
  182. m_stBuildNo.Empty();
  183. m_dwPortsInUse = 0;
  184. m_dwPortsTotal = 0;
  185. m_dwUpTime = 0;
  186. m_fStatsRetrieved = FALSE;
  187. // This data is reserved for setting/clearing by the
  188. // MachineHandler().
  189. // m_dwServerHandle = 0;
  190. // m_ulRefreshConnId = 0;
  191. m_routerType = ServerType_Unknown;
  192. return hrOK;
  193. }
  194. /*!--------------------------------------------------------------------------
  195. MachineNodeData::Load
  196. -
  197. Author: KennT
  198. ---------------------------------------------------------------------------*/
  199. HRESULT MachineNodeData::Load()
  200. {
  201. CString szState;
  202. HRESULT hr = hrOK;
  203. DWORD dwErr;
  204. CWaitCursor wait;
  205. // HKEY hkeyMachine;
  206. // RegKey rkeyMachine;
  207. MIB_SERVER_HANDLE handle = INVALID_HANDLE_VALUE;
  208. MPR_SERVER_0* pserver0 = NULL;
  209. // set the defaults
  210. // ----------------------------------------------------------------
  211. SetDefault();
  212. // Ok, we're no longer in the machine_not_connected (haven't tried yet)
  213. // state.
  214. // ----------------------------------------------------------------
  215. m_machineState = machine_connecting;
  216. // First, try to connect with the registry calls
  217. // ----------------------------------------------------------------
  218. dwErr = ValidateUserPermissions((LPCTSTR) m_stMachineName,
  219. &m_routerVersion,
  220. NULL);
  221. // If this succeeded, then we have access to the right
  222. // areas. We can continue on. This does NOT tell us about
  223. // the service state.
  224. // ----------------------------------------------------------------
  225. if (dwErr == ERROR_ACCESS_DENIED)
  226. {
  227. // An access denied at this stage means that we can't
  228. // do any machine configuration, so this value should
  229. // not get changed by anything below.
  230. // ------------------------------------------------------------
  231. m_machineState = machine_access_denied;
  232. }
  233. else if (dwErr == ERROR_BAD_NETPATH)
  234. {
  235. m_machineState = machine_bad_net_path;
  236. // If we get a bad net path, we can stop right now, since
  237. // everything else will fail also.
  238. // ------------------------------------------------------------
  239. m_stState.LoadString(IDS_MACHINE_NAME_NOT_FOUND);
  240. m_serviceState = service_bad_net_path;
  241. m_dataState = data_unable_to_load;
  242. goto Error;
  243. }
  244. else if (dwErr != ERROR_SUCCESS)
  245. {
  246. // I don't know why we can't connect
  247. // ------------------------------------------------------------
  248. m_machineState = machine_unable_to_connect;
  249. }
  250. // Try to connect to the mpradmin service, to get statistics
  251. // and such.
  252. // ----------------------------------------------------------------
  253. if (m_machineState != machine_access_denied)
  254. {
  255. dwErr = ::MprAdminServerConnect((LPWSTR) (LPCTSTR) m_stMachineName, &handle);
  256. if (dwErr == ERROR_SUCCESS)
  257. dwErr = ::MprAdminServerGetInfo(handle, 0, (LPBYTE *) &pserver0);
  258. if (dwErr == ERROR_SUCCESS)
  259. {
  260. // successful mpradmin fetch
  261. m_dwPortsInUse = pserver0->dwPortsInUse;
  262. m_dwPortsTotal = pserver0->dwTotalPorts;
  263. m_dwUpTime = pserver0->dwUpTime;
  264. m_fStatsRetrieved = TRUE;
  265. }
  266. else
  267. {
  268. if (dwErr == RPC_S_SERVER_UNAVAILABLE)
  269. {
  270. RAS_SERVER_0 ras0;
  271. CString stServer;
  272. stServer = _T("\\\\");
  273. stServer += m_stMachineName;
  274. // Ok, it may be that this is a non-steelhead
  275. // machine, try the RasAdmin APIs
  276. dwErr = RasAdminServerGetInfo(stServer,
  277. &ras0);
  278. if (dwErr == ERROR_SUCCESS)
  279. {
  280. m_dwPortsInUse = ras0.PortsInUse;
  281. m_dwPortsTotal = ras0.TotalPorts;
  282. m_dwUpTime = 0;
  283. m_fStatsRetrieved = TRUE;
  284. }
  285. else
  286. {
  287. // Ok, that call failed, try the registry.
  288. // If we can find the RemoteAccess key, then
  289. // we can assume that this is a Ras server.
  290. }
  291. }
  292. }
  293. }
  294. hr = LoadServerVersion();
  295. if (!FHrOK(hr))
  296. {
  297. // We've failed to get the version information.
  298. // This is pretty bad. Assume that we are unable to
  299. // connect.
  300. // ------------------------------------------------------------
  301. if (m_machineState == machine_connecting)
  302. m_machineState = machine_unable_to_connect;
  303. }
  304. // If this is not a server, we need to adjust the states
  305. // so that we don't show the state.
  306. // ----------------------------------------------------------------
  307. if (!m_fIsServer)
  308. {
  309. m_serviceState = service_not_a_server;
  310. m_machineState = machine_unable_to_connect;
  311. m_stState.LoadString(IDS_ERR_IS_A_WKS);
  312. }
  313. else
  314. {
  315. // This will set the service state (started, stopped, etc..)
  316. // ------------------------------------------------------------
  317. FetchServerState( szState );
  318. m_stState = szState;
  319. }
  320. // If we have reached this point, then all is well!
  321. // ----------------------------------------------------------------
  322. if (m_machineState == machine_connecting)
  323. m_machineState = machine_connected;
  324. // load machine config info as well
  325. hr = m_MachineConfig.GetMachineConfig(this);
  326. Error:
  327. if (pserver0) ::MprAdminBufferFree(pserver0);
  328. if (handle != INVALID_HANDLE_VALUE) ::MprAdminServerDisconnect(handle);
  329. return hr;
  330. }
  331. /*!--------------------------------------------------------------------------
  332. MachineNodeData::Unload
  333. -
  334. Author: KennT
  335. ---------------------------------------------------------------------------*/
  336. HRESULT MachineNodeData::Unload()
  337. {
  338. // Unload the data (i.e. NULL it out).
  339. SetDefault();
  340. return 0;
  341. }
  342. /*!--------------------------------------------------------------------------
  343. MachineNodeData::LoadServerVersion
  344. -
  345. Author: KennT
  346. ---------------------------------------------------------------------------*/
  347. HRESULT MachineNodeData::LoadServerVersion()
  348. {
  349. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  350. HRESULT hr = hrOK;
  351. HKEY hkMachine = 0;
  352. CString skey, stVersion;
  353. CString stServerType;
  354. CString stBuildNo;
  355. CString stProductType;
  356. CString stProductName;
  357. TCHAR szCurrentVersion[256];
  358. TCHAR szCSDVersion[256];
  359. TCHAR szBuffer[256];
  360. DWORD dwErr;
  361. RegKey regkeyWindows;
  362. RegKey regkeyProduct;
  363. int iProductType;
  364. // Windows NT Bug: 274198
  365. // If we couldn't find the path to the machine, just punt
  366. // ----------------------------------------------------------------
  367. if (m_machineState == machine_bad_net_path)
  368. {
  369. m_stState.LoadString(IDS_MACHINE_NAME_NOT_FOUND);
  370. return HResultFromWin32(ERROR_BAD_NETPATH);
  371. }
  372. // Everything we do here uses read-only permissions. So
  373. // we may able to do things even if our machine state is
  374. // machine_access_denied.
  375. // ----------------------------------------------------------------
  376. COM_PROTECT_TRY
  377. {
  378. // This is the default (unknown)
  379. m_stServerType.LoadString(IDS_UNKNOWN);
  380. m_stBuildNo = m_stServerType;
  381. CWRg( ConnectRegistry(m_stMachineName, &hkMachine) );
  382. skey = c_szSoftware;
  383. skey += TEXT('\\');
  384. skey += c_szMicrosoft;
  385. skey += TEXT('\\');
  386. skey += c_szWindowsNT;
  387. skey += TEXT('\\');
  388. skey += c_szCurrentVersion;
  389. CWRg( regkeyWindows.Open(hkMachine, (LPCTSTR) skey, KEY_READ) );
  390. // Ok, now try to get the current version value
  391. CWRg( regkeyWindows.QueryValue( c_szCurrentVersion, szCurrentVersion,
  392. sizeof(szCurrentVersion),
  393. FALSE) );
  394. // Now get the SP version
  395. // ----------------------------------------------------------------
  396. szCSDVersion[0] = 0;
  397. // We don't care if we get an error here
  398. regkeyWindows.QueryValue( c_szCSDVersion, szCSDVersion,
  399. sizeof(szCSDVersion),
  400. FALSE);
  401. if (szCSDVersion[0] == 0)
  402. {
  403. // Set this to a space (to make the print easier)
  404. StrCpy(szCSDVersion, _T(" "));
  405. }
  406. // Determine the product type
  407. // setup the default product type (NTS)
  408. if (_ttoi(szCurrentVersion) >= 5)
  409. {
  410. // For NT5 and up, we can use the
  411. // HKLM \ Software \ Microsoft \ Windows NT \ CurrentVersion
  412. // ProductName : REG_SZ
  413. // --------------------------------------------------------
  414. iProductType = IDS_ROUTER_TYPE_WIN2000_SERVER;
  415. dwErr = regkeyWindows.QueryValue( c_szRegValProductName, stProductName );
  416. if (dwErr != ERROR_SUCCESS)
  417. stProductName.LoadString(IDS_WIN2000);
  418. }
  419. else
  420. iProductType = IDS_ROUTER_TYPE_NTS;
  421. // Now that we've determine the version id, we
  422. // need to determine the product type (wks or svr)
  423. // ------------------------------------------------------------
  424. dwErr = regkeyProduct.Open(hkMachine, c_szRegKeyProductOptions, KEY_READ);
  425. if (dwErr == ERROR_SUCCESS)
  426. {
  427. // Ok, now get the product info
  428. // The product type is used to determine if server or not.
  429. regkeyProduct.QueryValue(c_szRegValProductType, stProductType);
  430. if (stProductType.CompareNoCase(c_szWinNT) == 0)
  431. {
  432. if (_ttoi(szCurrentVersion) >= 5)
  433. iProductType = IDS_ROUTER_TYPE_WIN2000_PRO;
  434. else
  435. iProductType = IDS_ROUTER_TYPE_NTW;
  436. m_fIsServer = FALSE;
  437. }
  438. }
  439. // If this is a Win2000 machine, show
  440. // Win2000 (CSD)
  441. // else
  442. // NT 4.X (CSD)
  443. // ------------------------------------------------------------
  444. if ((iProductType == IDS_ROUTER_TYPE_WIN2000_SERVER) ||
  445. (iProductType == IDS_ROUTER_TYPE_WIN2000_PRO))
  446. AfxFormatString2(stVersion, iProductType,
  447. stProductName, szCSDVersion);
  448. else
  449. AfxFormatString2(stVersion, iProductType,
  450. szCurrentVersion, szCSDVersion);
  451. // Now that we know that it is a workstation or server, adjust
  452. // for RRAS
  453. // If this is a workstation, then routertype is none.
  454. // If this is NT5 or up, then this is a RRAS machine.
  455. // If NT4, if the HKLM\Software\Microsoft\Router exists, this is RRAS
  456. // Else if HKLM\System\CurrentControlSet\Services\RemoteAccess, RAS
  457. // Else nothing is installed.
  458. if (m_fIsServer == FALSE)
  459. {
  460. m_routerType = ServerType_Workstation;
  461. }
  462. else if (_ttoi(szCurrentVersion) >= 5)
  463. {
  464. DWORD dwConfigured;
  465. // Check the configuration flags key.
  466. if (FHrSucceeded(ReadRouterConfiguredReg(m_stMachineName, &dwConfigured)))
  467. {
  468. if (dwConfigured)
  469. m_routerType = ServerType_Rras;
  470. else
  471. m_routerType = ServerType_RrasUninstalled;
  472. }
  473. else
  474. m_routerType = ServerType_Unknown;
  475. }
  476. else
  477. {
  478. RegKey regkeyT;
  479. // Now check for the Router key
  480. dwErr = regkeyT.Open(hkMachine, c_szRegKeyRouter, KEY_READ);
  481. if (dwErr == ERROR_SUCCESS)
  482. m_routerType = ServerType_Rras;
  483. else
  484. {
  485. dwErr = regkeyT.Open(hkMachine, c_szRemoteAccessKey, KEY_READ);
  486. if (dwErr == ERROR_SUCCESS)
  487. m_routerType = ServerType_Ras;
  488. else
  489. m_routerType = ServerType_Uninstalled;
  490. }
  491. regkeyT.Close();
  492. // If the error code is anything other than ERROR_FILE_NOT_FOUND
  493. // then we set the router type to be unknown.
  494. if ((dwErr != ERROR_SUCCESS) &&
  495. (dwErr != ERROR_FILE_NOT_FOUND))
  496. {
  497. m_routerType = ServerType_Unknown;
  498. }
  499. dwErr = ERROR_SUCCESS;
  500. }
  501. // Setup the default string
  502. stServerType = stVersion;
  503. if (_ttoi(szCurrentVersion) == 4)
  504. {
  505. UINT ids = 0;
  506. if (m_routerType == ServerType_Rras)
  507. ids = IDS_RRAS;
  508. else if (m_routerType == ServerType_Ras)
  509. ids = IDS_RAS;
  510. if (ids)
  511. {
  512. CString stRras;
  513. stRras.LoadString(ids);
  514. AfxFormatString2(stServerType, IDS_ROUTER_TYPE_NTsteelhead,
  515. stVersion, stRras);
  516. }
  517. }
  518. m_stServerType = stServerType;
  519. szBuffer[0] = 0;
  520. regkeyWindows.QueryValue( c_szCurrentBuildNumber, szBuffer,
  521. sizeof(szBuffer), FALSE);
  522. m_stBuildNo = szBuffer;
  523. COM_PROTECT_ERROR_LABEL;
  524. }
  525. COM_PROTECT_CATCH;
  526. if (hkMachine)
  527. DisconnectRegistry( hkMachine );
  528. return hr;
  529. }
  530. /*!--------------------------------------------------------------------------
  531. MachineNodeData::FetchServerState
  532. -
  533. Author: KennT
  534. ---------------------------------------------------------------------------*/
  535. HRESULT MachineNodeData::FetchServerState(CString& szState)
  536. {
  537. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  538. HRESULT hr = hrOK;
  539. DWORD dwStatus, dwErrorCode;
  540. // Windows NT Bug: 274198
  541. // If we couldn't find the path to the machine, just punt
  542. // ----------------------------------------------------------------
  543. if (m_machineState == machine_bad_net_path)
  544. {
  545. szState.LoadString(IDS_MACHINE_NAME_NOT_FOUND);
  546. return HResultFromWin32(ERROR_BAD_NETPATH);
  547. }
  548. // Note: We could be in machine_access_denied but still
  549. // be able to access the service status.
  550. // ----------------------------------------------------------------
  551. hr = GetRouterServiceStatus((LPCTSTR) m_stMachineName,
  552. &dwStatus,
  553. &dwErrorCode);
  554. if (FHrSucceeded(hr))
  555. {
  556. m_MachineConfig.m_dwServiceStatus = dwStatus;
  557. if (dwStatus == SERVICE_RUNNING)
  558. m_serviceState = service_started;
  559. else
  560. m_serviceState = service_stopped;
  561. szState = ServiceStateToCString(dwStatus);
  562. if (m_routerType == ServerType_RrasUninstalled)
  563. {
  564. CString stTemp;
  565. stTemp.Format(IDS_ROUTER_UNINSTALLED,
  566. (LPCTSTR) szState);
  567. szState = stTemp;
  568. }
  569. }
  570. else
  571. {
  572. m_MachineConfig.m_dwServiceStatus = 0;
  573. if (hr == HResultFromWin32(ERROR_ACCESS_DENIED))
  574. {
  575. szState = c_stStatAccessDenied;
  576. m_serviceState = service_access_denied;
  577. }
  578. else
  579. {
  580. szState = c_stStatUnavail;
  581. m_serviceState = service_unknown;
  582. }
  583. }
  584. return hr;
  585. }
  586. typedef struct
  587. {
  588. SERVICE_STATES m_serviceState;
  589. LPARAM m_imageIndex;
  590. } ServiceStateImageMapEntry;
  591. static ServiceStateImageMapEntry s_rgImageMap[] =
  592. {
  593. { service_unknown, IMAGE_IDX_MACHINE },
  594. { service_not_a_server, IMAGE_IDX_MACHINE_ERROR },
  595. { service_access_denied, IMAGE_IDX_MACHINE_ACCESS_DENIED },
  596. { service_bad_net_path, IMAGE_IDX_MACHINE_ERROR },
  597. { service_started, IMAGE_IDX_MACHINE_STARTED },
  598. { service_stopped, IMAGE_IDX_MACHINE_STOPPED },
  599. { service_rasadmin, IMAGE_IDX_MACHINE_STARTED },
  600. { service_enum_end, IMAGE_IDX_MACHINE },
  601. };
  602. LPARAM MachineNodeData::GetServiceImageIndex()
  603. {
  604. ServiceStateImageMapEntry * pEntry;
  605. for (pEntry = s_rgImageMap; pEntry->m_serviceState != service_enum_end; pEntry++)
  606. {
  607. if (pEntry->m_serviceState == m_serviceState)
  608. break;
  609. }
  610. return pEntry->m_imageIndex;
  611. }
  612. /*---------------------------------------------------------------------------
  613. MachineHandler implementation
  614. ---------------------------------------------------------------------------*/
  615. DEBUG_DECLARE_INSTANCE_COUNTER(MachineHandler)
  616. MachineHandler::MachineHandler(ITFSComponentData *pCompData)
  617. : BaseRouterHandler(pCompData),
  618. m_bExpanded(FALSE),
  619. m_pConfigStream(NULL),
  620. m_bRouterInfoAddedToAutoRefresh(FALSE),
  621. m_bMergeRequired(FALSE),
  622. m_fTryToConnect(TRUE)
  623. {
  624. m_rgButtonState[MMC_VERB_PROPERTIES_INDEX] = ENABLED;
  625. m_bState[MMC_VERB_PROPERTIES_INDEX] = TRUE;
  626. m_rgButtonState[MMC_VERB_REFRESH_INDEX] = ENABLED;
  627. m_bState[MMC_VERB_REFRESH_INDEX] = TRUE;
  628. m_pSumNodeHandler = NULL;
  629. m_pSumNode=NULL;
  630. m_fCreateNewDataObj = FALSE;
  631. m_fNoConnectingUI = FALSE;
  632. m_EventId = -1;
  633. DEBUG_INCREMENT_INSTANCE_COUNTER(MachineHandler);
  634. };
  635. /*!--------------------------------------------------------------------------
  636. MachineHandler::QueryInterface
  637. -
  638. Author: KennT
  639. ---------------------------------------------------------------------------*/
  640. STDMETHODIMP MachineHandler::QueryInterface(REFIID riid, LPVOID *ppv)
  641. {
  642. // Is the pointer bad?
  643. if (ppv == NULL)
  644. return E_INVALIDARG;
  645. // Place NULL in *ppv in case of failure
  646. *ppv = NULL;
  647. // This is the non-delegating IUnknown implementation
  648. if (riid == IID_IUnknown)
  649. *ppv = (LPVOID) this;
  650. else if (riid == IID_IRtrAdviseSink)
  651. *ppv = &m_IRtrAdviseSink;
  652. else
  653. return BaseRouterHandler::QueryInterface(riid, ppv);
  654. // If we're going to return an interface, AddRef it first
  655. if (*ppv)
  656. {
  657. ((LPUNKNOWN) *ppv)->AddRef();
  658. return hrOK;
  659. }
  660. else
  661. return E_NOINTERFACE;
  662. }
  663. /*!--------------------------------------------------------------------------
  664. MachineHandler::Init
  665. -
  666. Author: KennT
  667. ---------------------------------------------------------------------------*/
  668. HRESULT MachineHandler::Init(LPCTSTR pszMachine,
  669. RouterAdminConfigStream *pConfigStream,
  670. ITFSNodeHandler* pSumNodeHandler /*=NULL*/,
  671. ITFSNode* pSumNode /*=NULL*/)
  672. {
  673. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  674. HRESULT hr = hrOK;
  675. m_pConfigStream = pConfigStream;
  676. m_pSumNodeHandler = pSumNodeHandler;
  677. m_pSumNode = pSumNode;
  678. Assert(m_spRouterInfo == NULL);
  679. CORg( CreateRouterInfo(&m_spRouterInfo, m_spTFSCompData->GetHiddenWnd(), pszMachine) );
  680. Assert(m_spRouterInfo != NULL);
  681. // Windows NT Bug : 330939
  682. // Add the delete button to the machine node
  683. // -----------------------------------------------------------------
  684. m_rgButtonState[MMC_VERB_DELETE_INDEX] = ENABLED;
  685. m_bState[MMC_VERB_DELETE_INDEX] = TRUE;
  686. Error:
  687. return hr;
  688. }
  689. /*!--------------------------------------------------------------------------
  690. MachineHandler::GetString
  691. Implementation of ITFSNodeHandler::GetString
  692. Author: KennT
  693. ---------------------------------------------------------------------------*/
  694. STDMETHODIMP_(LPCTSTR) MachineHandler::GetString(ITFSNode *pNode, int nCol)
  695. {
  696. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  697. MachineNodeData * pData = GET_MACHINENODEDATA(pNode);
  698. int nFormat;
  699. Assert(pData);
  700. if (m_stNodeTitle.IsEmpty())
  701. {
  702. if (pData->m_fExtension)
  703. nFormat = IDS_RRAS_SERVICE_DESC;
  704. else if (pData->m_fAddedAsLocal)
  705. nFormat = IDS_RRAS_LOCAL_TITLE;
  706. else
  707. nFormat = IDS_RRAS_TITLE;
  708. m_stNodeTitle.Format(nFormat, (LPCTSTR) pData->m_stMachineName);
  709. }
  710. return (LPCTSTR) m_stNodeTitle;
  711. }
  712. /*!--------------------------------------------------------------------------
  713. IfAdminNodeHandler::CreatePropertyPages
  714. -
  715. Author: KennT
  716. ---------------------------------------------------------------------------*/
  717. STDMETHODIMP
  718. MachineHandler::CreatePropertyPages
  719. (
  720. ITFSNode * pNode,
  721. LPPROPERTYSHEETCALLBACK lpProvider,
  722. LPDATAOBJECT pDataObject,
  723. LONG_PTR handle,
  724. DWORD dwType
  725. )
  726. {
  727. // Check to see if this router has been initialized
  728. // if not, do the dummy page thing
  729. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  730. HRESULT hr = hrOK;
  731. SMenuData sData;
  732. SRouterNodeMenu sRouterData;
  733. RtrCfgSheet* pPropSheet = NULL;
  734. SPIComponentData spComponentData;
  735. CString stTitle;
  736. CDummyProperties * pProp;
  737. ULONG ulFlags;
  738. int idsErr;
  739. // Windows NT Bug : 177400
  740. // If the machine is not configured, do not allow the properties
  741. // page to be brought up
  742. // ----------------------------------------------------------------
  743. MachineNodeData * pData = GET_MACHINENODEDATA(pNode);
  744. ::ZeroMemory(&sRouterData, sizeof(sRouterData));
  745. sRouterData.m_sidMenu = IDS_MENU_RTRWIZ;
  746. sData.m_spNode.Set(pNode);
  747. sData.m_pMachineConfig = &(pData->m_MachineConfig);
  748. sData.m_spRouterInfo.Set(m_spRouterInfo);
  749. CORg( m_spNodeMgr->GetComponentData(&spComponentData) );
  750. ulFlags = MachineRtrConfWizFlags(&sRouterData,
  751. reinterpret_cast<INT_PTR>(&sData));
  752. if ((ulFlags == MF_ENABLED) ||
  753. (ulFlags == 0xFFFFFFFF) ||
  754. (pData->m_machineState < machine_connected))
  755. {
  756. // We are unable to connect.
  757. if (pData->m_machineState == machine_bad_net_path)
  758. idsErr = IDS_ERR_MACHINE_NAME_NOT_FOUND;
  759. if (pData->m_machineState < machine_connected)
  760. idsErr = IDS_ERR_NONADMIN_CANNOT_SEE_PROPERTIES;
  761. // If this is an NT4 machine, we don't show the properties
  762. else if (sData.m_pMachineConfig->m_fNt4)
  763. idsErr = IDS_ERR_CANNOT_SHOW_NT4_PROPERTIES;
  764. // This case means that the install menu should be shown
  765. // and the properties menu hidden
  766. else
  767. idsErr = IDS_ERR_MUST_INSTALL_BEFORE_PROPERTIES;
  768. AfxMessageBox(idsErr);
  769. pProp = new CDummyProperties(pNode, spComponentData, NULL);
  770. hr = pProp->CreateModelessSheet(lpProvider, handle);
  771. }
  772. else
  773. {
  774. pPropSheet = new RtrCfgSheet(pNode, m_spRouterInfo, spComponentData,
  775. m_spTFSCompData, stTitle);
  776. // added by WeiJiang 5/7/98, to postpone the Load of RouterInfo
  777. CORg(SecureRouterInfo(pNode, !m_fNoConnectingUI));
  778. pPropSheet->Init(m_spRouterInfo->GetMachineName());
  779. if (lpProvider)
  780. hr = pPropSheet->CreateModelessSheet(lpProvider, handle);
  781. else
  782. hr = pPropSheet->DoModelessSheet();
  783. }
  784. Error:
  785. return hr;
  786. }
  787. /*!--------------------------------------------------------------------------
  788. MachineHandler::HasPropertyPages
  789. Author: KennT
  790. ---------------------------------------------------------------------------*/
  791. STDMETHODIMP
  792. MachineHandler::HasPropertyPages
  793. (
  794. ITFSNode * pNode,
  795. LPDATAOBJECT pDataObject,
  796. DATA_OBJECT_TYPES type,
  797. DWORD dwType
  798. )
  799. {
  800. return hrOK;
  801. }
  802. // this is the set of menus for NT4 RRAS
  803. static const SRouterNodeMenu s_rgIfNodeMenuNT4[] =
  804. {
  805. // Add items that go on the top menu here
  806. { IDS_DMV_MENU_START, MachineHandler::QueryService,
  807. CCM_INSERTIONPOINTID_PRIMARY_TASK },
  808. { IDS_DMV_MENU_STOP, MachineHandler::QueryService,
  809. CCM_INSERTIONPOINTID_PRIMARY_TASK },
  810. { IDS_MENU_PAUSE_SERVICE, MachineHandler::GetPauseFlags,
  811. CCM_INSERTIONPOINTID_PRIMARY_TASK },
  812. { IDS_MENU_RESUME_SERVICE, MachineHandler::GetPauseFlags,
  813. CCM_INSERTIONPOINTID_PRIMARY_TASK }
  814. };
  815. // this is the set of menus for NT5
  816. static const SRouterNodeMenu s_rgIfNodeMenu[] =
  817. {
  818. #ifdef kennt
  819. // Add items that go on the top menu here
  820. { IDS_MENU_NEW_WIZARD_TEST, NULL,
  821. CCM_INSERTIONPOINTID_PRIMARY_TOP },
  822. #endif
  823. { IDS_MENU_RTRWIZ, MachineHandler::MachineRtrConfWizFlags,
  824. CCM_INSERTIONPOINTID_PRIMARY_TOP, _T("_CONFIGURE_RRAS_WIZARD_") },
  825. { IDS_DMV_MENU_REMOVESERVICE, MachineHandler::QueryService,
  826. CCM_INSERTIONPOINTID_PRIMARY_TOP },
  827. { IDS_DMV_MENU_START, MachineHandler::QueryService,
  828. CCM_INSERTIONPOINTID_PRIMARY_TASK },
  829. { IDS_DMV_MENU_STOP, MachineHandler::QueryService,
  830. CCM_INSERTIONPOINTID_PRIMARY_TASK },
  831. { IDS_MENU_PAUSE_SERVICE, MachineHandler::GetPauseFlags,
  832. CCM_INSERTIONPOINTID_PRIMARY_TASK },
  833. { IDS_MENU_RESUME_SERVICE, MachineHandler::GetPauseFlags,
  834. CCM_INSERTIONPOINTID_PRIMARY_TASK },
  835. { IDS_MENU_RESTART_SERVICE, MachineHandler::QueryService,
  836. CCM_INSERTIONPOINTID_PRIMARY_TASK }
  837. };
  838. static const SRouterNodeMenu s_rgIfNodeMenu_ExtensionOnly[] =
  839. {
  840. { IDS_MENU_SEPARATOR, 0,
  841. CCM_INSERTIONPOINTID_PRIMARY_TOP },
  842. { IDS_MENU_AUTO_REFRESH, MachineHandler::GetAutoRefreshFlags,
  843. CCM_INSERTIONPOINTID_PRIMARY_TOP },
  844. { IDS_MENU_REFRESH_RATE, MachineHandler::GetAutoRefreshFlags,
  845. CCM_INSERTIONPOINTID_PRIMARY_TOP },
  846. };
  847. ULONG MachineHandler::MachineRtrConfWizFlags(const SRouterNodeMenu *pMenuData,
  848. INT_PTR pData)
  849. {
  850. return GetServiceFlags(pMenuData, pData);
  851. }
  852. ULONG MachineHandler::GetServiceFlags(const SRouterNodeMenu *pMenuData,
  853. INT_PTR pUserData)
  854. {
  855. Assert(pUserData);
  856. ULONG uStatus = MF_GRAYED;
  857. SMenuData *pData = reinterpret_cast<SMenuData *>(pUserData);
  858. ULONG ulMenuId = pMenuData->m_sidMenu;
  859. BOOL fStarted = (pData->m_pMachineConfig->m_dwServiceStatus != SERVICE_STOPPED);
  860. if ( ulMenuId == IDS_DMV_MENU_START )
  861. {
  862. // If this is an NT5 machine (or up), then the start menu
  863. // will appear grayed if the machine has not been configured.
  864. if ((pData->m_pMachineConfig->m_fNt4) || (pData->m_pMachineConfig->m_fConfigured))
  865. uStatus = ( fStarted ? MF_GRAYED : MF_ENABLED);
  866. else
  867. {
  868. // If this is an NT5 machine and if the machine is not configured
  869. uStatus = MF_GRAYED;
  870. }
  871. }
  872. else if (( ulMenuId == IDS_DMV_MENU_STOP ) ||
  873. ( ulMenuId == IDS_MENU_RESTART_SERVICE) )
  874. {
  875. uStatus = ( fStarted ? MF_ENABLED : MF_GRAYED);
  876. }
  877. else if ( (ulMenuId == IDS_MENU_RTRWIZ) ||
  878. (ulMenuId == IDS_DMV_MENU_REMOVESERVICE))
  879. {
  880. if ( pData->m_pMachineConfig->m_fReachable )
  881. {
  882. if ( pData->m_pMachineConfig->m_fNt4 )
  883. {
  884. // This is an NT4 machine, we can't bring
  885. // this menu option up.
  886. uStatus = 0xFFFFFFFF;
  887. }
  888. else
  889. {
  890. if (ulMenuId == IDS_MENU_RTRWIZ)
  891. uStatus = (pData->m_pMachineConfig->m_fConfigured ? MF_GRAYED : MF_ENABLED);
  892. else
  893. uStatus = (pData->m_pMachineConfig->m_fConfigured ? MF_ENABLED : MF_GRAYED);
  894. }
  895. }
  896. }
  897. return uStatus;
  898. }
  899. /*!--------------------------------------------------------------------------
  900. MachineHandler::GetPauseFlags
  901. -
  902. Author: KennT
  903. ---------------------------------------------------------------------------*/
  904. ULONG MachineHandler::GetPauseFlags(const SRouterNodeMenu *pMenuData,
  905. INT_PTR pUserData)
  906. {
  907. ULONG ulReturn = MF_GRAYED;
  908. SMenuData *pData = reinterpret_cast<SMenuData *>(pUserData);
  909. ULONG ulMenuId = pMenuData->m_sidMenu;
  910. // We can only pause when the service is started
  911. if ((pData->m_pMachineConfig->m_dwServiceStatus == SERVICE_RUNNING) &&
  912. (ulMenuId == IDS_MENU_PAUSE_SERVICE))
  913. ulReturn = 0;
  914. // We can only resume when the service is paused
  915. if ((pData->m_pMachineConfig->m_dwServiceStatus == SERVICE_PAUSED) &&
  916. (ulMenuId == IDS_MENU_RESUME_SERVICE))
  917. ulReturn = 0;
  918. return ulReturn;
  919. }
  920. /*!--------------------------------------------------------------------------
  921. MachineHandler::GetAutoRefreshFlags
  922. -
  923. Author: KennT
  924. ---------------------------------------------------------------------------*/
  925. ULONG MachineHandler::GetAutoRefreshFlags(const SRouterNodeMenu *pMenuData,
  926. INT_PTR pUserData)
  927. {
  928. ULONG uStatus = MF_GRAYED;
  929. SMenuData * pData = reinterpret_cast<SMenuData *>(pUserData);
  930. Assert(pData);
  931. while( pData->m_pMachineConfig->m_fReachable ) // Pseudo loop
  932. {
  933. SPIRouterRefresh spRefresh;
  934. if(!pData->m_spRouterInfo)
  935. break;
  936. pData->m_spRouterInfo->GetRefreshObject(&spRefresh);
  937. if (!spRefresh)
  938. break;
  939. uStatus = MF_ENABLED;
  940. if (pMenuData->m_sidMenu == IDS_MENU_AUTO_REFRESH && (spRefresh->IsRefreshStarted() == hrOK))
  941. {
  942. uStatus |= MF_CHECKED;
  943. }
  944. break;
  945. }
  946. return uStatus;
  947. }
  948. HRESULT MachineHandler::SetExternalRefreshObject(IRouterRefresh *pRefresh)
  949. {
  950. Assert((IRouterInfo*)m_spRouterInfo);
  951. return m_spRouterInfo->SetExternalRefreshObject(pRefresh);
  952. }
  953. ULONG MachineHandler::QueryService(const SRouterNodeMenu *pMenuData, INT_PTR pData)
  954. {
  955. return GetServiceFlags(pMenuData, pData);
  956. }
  957. STDMETHODIMP MachineHandler::OnAddMenuItems(
  958. ITFSNode *pNode,
  959. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  960. LPDATAOBJECT lpDataObject,
  961. DATA_OBJECT_TYPES type,
  962. DWORD dwType,
  963. long *pInsertionAllowed)
  964. {
  965. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  966. MachineNodeData * pData = GET_MACHINENODEDATA(pNode);
  967. BOOL bExtension = pData->m_fExtension;
  968. UINT cMenu;
  969. const SRouterNodeMenu *pMenu;
  970. SMenuData menuData;
  971. HRESULT hr = S_OK;
  972. COM_PROTECT_TRY
  973. {
  974. // Windows NT Bug : 281492
  975. // If we have not connected, attempt to connect
  976. if (pData->m_machineState == machine_not_connected)
  977. {
  978. pData->Unload();
  979. pData->Load();
  980. }
  981. // For down-level servers, we can't do anything with it.
  982. if ((pData->m_routerType == ServerType_Rras) ||
  983. (pData->m_routerType == ServerType_RrasUninstalled))
  984. {
  985. // Get some initial state data.
  986. MachineNodeData * pData = GET_MACHINENODEDATA(pNode);
  987. menuData.m_pMachineConfig = &(pData->m_MachineConfig);
  988. // Now go through and add our menu items
  989. menuData.m_spNode.Set(pNode);
  990. menuData.m_spRouterInfo.Set(m_spRouterInfo);
  991. // NT4 and NT5 have different menus
  992. if (pData->m_MachineConfig.m_fNt4)
  993. {
  994. pMenu = s_rgIfNodeMenuNT4;
  995. cMenu = DimensionOf(s_rgIfNodeMenuNT4);
  996. }
  997. else
  998. {
  999. pMenu = s_rgIfNodeMenu;
  1000. cMenu = DimensionOf(s_rgIfNodeMenu);
  1001. }
  1002. hr = AddArrayOfMenuItems(pNode,
  1003. pMenu,
  1004. cMenu,
  1005. pContextMenuCallback,
  1006. *pInsertionAllowed,
  1007. (INT_PTR) &menuData);
  1008. if(bExtension)
  1009. hr = AddArrayOfMenuItems(pNode, s_rgIfNodeMenu_ExtensionOnly,
  1010. DimensionOf(s_rgIfNodeMenu_ExtensionOnly),
  1011. pContextMenuCallback,
  1012. *pInsertionAllowed,
  1013. (INT_PTR) &menuData);
  1014. }
  1015. }
  1016. COM_PROTECT_CATCH;
  1017. return hr;
  1018. }
  1019. struct STimerParam
  1020. {
  1021. MachineHandler * pHandler;
  1022. ITFSNode * pNode;
  1023. };
  1024. extern CTimerMgr g_timerMgr;
  1025. void ExpandTimerProc(LPARAM lParam, DWORD dwTime)
  1026. {
  1027. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1028. STimerParam * pParam = (STimerParam * )lParam;
  1029. pParam->pHandler->ExpandNode(pParam->pNode, TRUE);
  1030. }
  1031. void MachineHandler::ExpandNode
  1032. (
  1033. ITFSNode * pNode,
  1034. BOOL fExpand
  1035. )
  1036. {
  1037. SPIComponentData spCompData;
  1038. SPIDataObject spDataObject;
  1039. LPDATAOBJECT pDataObject;
  1040. SPIConsole spConsole;
  1041. HRESULT hr = hrOK;
  1042. RegKey regkey;
  1043. BOOL bFound = FALSE;
  1044. // don't expand the node if we are handling the EXPAND_SYNC message,
  1045. // this screws up the insertion of item, getting duplicates.
  1046. m_spNodeMgr->GetComponentData(&spCompData);
  1047. CORg ( spCompData->QueryDataObject((MMC_COOKIE) pNode, CCT_SCOPE, &pDataObject) );
  1048. spDataObject = pDataObject;
  1049. CORg ( m_spNodeMgr->GetConsole(&spConsole) );
  1050. CORg ( spConsole->UpdateAllViews(pDataObject, TRUE, RESULT_PANE_EXPAND) );
  1051. //set the regkey
  1052. if (ERROR_SUCCESS == regkey.Open ( HKEY_LOCAL_MACHINE,
  1053. c_szRemoteAccessKey,
  1054. KEY_ALL_ACCESS,
  1055. m_spRouterInfo->GetMachineName()
  1056. )
  1057. )
  1058. {
  1059. DWORD dwSet = 0;
  1060. CWRg(regkey.SetValue( c_szRegValOpenMPRSnap, dwSet));
  1061. dwSet = 1;
  1062. CWRg(regkey.SetValue( c_szRegValOpenIPSnap, dwSet));
  1063. }
  1064. Error:
  1065. if ( m_EventId != -1 )
  1066. {
  1067. g_timerMgr.FreeTimer(m_EventId);
  1068. m_EventId = -1;
  1069. }
  1070. return;
  1071. }
  1072. /*!--------------------------------------------------------------------------
  1073. MachineHandler::OnCommand
  1074. Implementation of ITFSNodeHandler::OnCommand
  1075. Author: KennT
  1076. ---------------------------------------------------------------------------*/
  1077. STDMETHODIMP MachineHandler::OnCommand(ITFSNode *pNode, long nCommandId,
  1078. DATA_OBJECT_TYPES type,
  1079. LPDATAOBJECT pDataObject,
  1080. DWORD dwType)
  1081. {
  1082. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1083. HRESULT hr = S_OK;
  1084. ClearTFSErrorInfo(0);
  1085. COM_PROTECT_TRY
  1086. {
  1087. switch (nCommandId)
  1088. {
  1089. case IDS_MENU_NEW_WIZARD_TEST:
  1090. {
  1091. hr = OnNewRtrRASConfigWiz(pNode, TRUE);
  1092. }
  1093. break;
  1094. case IDS_MENU_RTRWIZ:
  1095. hr = OnNewRtrRASConfigWiz(pNode, FALSE);
  1096. //hr = OnRtrRASConfigWiz(pNode);
  1097. // when summary node is not yet created, then refresh icon
  1098. // from machine node is needed
  1099. if (!m_pSumNodeHandler &&
  1100. (*pNode->GetNodeType()) == GUID_RouterMachineNodeType)
  1101. {
  1102. MachineNodeData* pData = GET_MACHINENODEDATA(pNode);
  1103. Assert(pData);
  1104. // Ignore the return value, if the load fails
  1105. // we still need to update the icon
  1106. // ------------------------------------------------
  1107. pData->Load();
  1108. hr = SynchronizeIcon(pNode);
  1109. //HACK Alert! This is the most
  1110. //hacky stuff I have seen around
  1111. //but cannot help it at all...
  1112. {
  1113. STimerParam * pParam = new STimerParam;
  1114. pParam ->pHandler = this;
  1115. pParam->pNode = pNode;
  1116. RegKey regkey;
  1117. //set the regkey
  1118. if (ERROR_SUCCESS == regkey.Open ( HKEY_LOCAL_MACHINE,
  1119. c_szRemoteAccessKey,
  1120. KEY_ALL_ACCESS,
  1121. m_spRouterInfo->GetMachineName()
  1122. )
  1123. )
  1124. {
  1125. DWORD dwSet = 1;
  1126. regkey.SetValue( c_szRegValOpenMPRSnap, dwSet);
  1127. }
  1128. //Give MMC enough time to settle down...
  1129. m_EventId = g_timerMgr.AllocateTimer ( ExpandTimerProc,
  1130. (LPARAM)pParam,
  1131. 10000
  1132. );
  1133. }
  1134. }
  1135. break;
  1136. case IDS_DMV_MENU_START:
  1137. case IDS_DMV_MENU_STOP:
  1138. case IDS_DMV_MENU_REMOVESERVICE:
  1139. case IDS_MENU_PAUSE_SERVICE:
  1140. case IDS_MENU_RESUME_SERVICE:
  1141. case IDS_MENU_RESTART_SERVICE:
  1142. {
  1143. // Windows NT Bug : 285537
  1144. // First, ask the user if they really wish
  1145. // to disable the router.
  1146. if ((nCommandId != IDS_DMV_MENU_REMOVESERVICE) ||
  1147. (IDYES == AfxMessageBox(IDS_WRN_DISABLE_ROUTER, MB_YESNO)))
  1148. {
  1149. MachineNodeData * pData = GET_MACHINENODEDATA(pNode);
  1150. hr = ChgService(pNode,
  1151. pData->m_stMachineName,
  1152. nCommandId);
  1153. }
  1154. SynchronizeIcon(pNode);
  1155. }
  1156. case IDS_DMV_MENU_REFRESH:
  1157. {
  1158. SPITFSNode spRoutingNode;
  1159. SPITFSNodeEnum spMachineEnum;
  1160. SPITFSNode spMachineNode;
  1161. // when summary node is not yet created, then refresh icon from machine node is needed
  1162. if (!m_pSumNodeHandler && (*pNode->GetNodeType()) == GUID_RouterMachineNodeType)
  1163. {
  1164. MachineNodeData* pData = GET_MACHINENODEDATA(pNode);
  1165. Assert(pData);
  1166. // Ignore the return value, if the load fails
  1167. // we still need to update the icon
  1168. // --------------------------------------------
  1169. pData->Load();
  1170. hr = SynchronizeIcon(pNode);
  1171. }
  1172. }
  1173. break;
  1174. case IDS_MENU_REFRESH_RATE:
  1175. {
  1176. CRefRateDlg refrate;
  1177. SPIRouterRefresh spRefresh;
  1178. m_spRouterInfo->GetRefreshObject(&spRefresh);
  1179. if (spRefresh)
  1180. {
  1181. DWORD rate;
  1182. spRefresh->GetRefreshInterval(&rate);
  1183. refrate.m_cRefRate = rate;
  1184. if (refrate.DoModal() == IDOK)
  1185. {
  1186. spRefresh->SetRefreshInterval(refrate.m_cRefRate);
  1187. }
  1188. }
  1189. }
  1190. break;
  1191. case IDS_MENU_AUTO_REFRESH:
  1192. {
  1193. SPIRouterRefresh spRefresh;
  1194. m_spRouterInfo->GetRefreshObject(&spRefresh);
  1195. if(!spRefresh)
  1196. break;
  1197. if (spRefresh->IsRefreshStarted() == hrOK)
  1198. spRefresh->Stop();
  1199. else
  1200. {
  1201. DWORD rate;
  1202. spRefresh->GetRefreshInterval(&rate);
  1203. spRefresh->Start(rate);
  1204. }
  1205. }
  1206. break;
  1207. default:
  1208. break;
  1209. }
  1210. }
  1211. COM_PROTECT_CATCH;
  1212. if (!FHrSucceeded(hr))
  1213. {
  1214. DisplayTFSErrorMessage(NULL);
  1215. }
  1216. ForceGlobalRefresh(m_spRouterInfo);
  1217. return hrOK;
  1218. }
  1219. /*!--------------------------------------------------------------------------
  1220. MachineHandler::SynchronizeIcon
  1221. -
  1222. Author: FlorinT
  1223. ---------------------------------------------------------------------------*/
  1224. HRESULT MachineHandler::SynchronizeIcon(ITFSNode *pNode)
  1225. {
  1226. HRESULT hr = hrOK;
  1227. MachineNodeData *pMachineData;
  1228. LPARAM imageIndex;
  1229. pMachineData = GET_MACHINENODEDATA(pNode);
  1230. Assert(pMachineData);
  1231. CString str;
  1232. pMachineData->FetchServerState(str);
  1233. imageIndex = pMachineData->GetServiceImageIndex();
  1234. pNode->SetData(TFS_DATA_IMAGEINDEX, imageIndex);
  1235. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, imageIndex);
  1236. pNode->ChangeNode(SCOPE_PANE_CHANGE_ITEM_ICON);
  1237. if (m_bExpanded)
  1238. UpdateResultMessage(pNode);
  1239. return hr;
  1240. }
  1241. /*!--------------------------------------------------------------------------
  1242. MachineHandler::ChgService
  1243. -
  1244. Author: KennT
  1245. ---------------------------------------------------------------------------*/
  1246. HRESULT MachineHandler::ChgService(ITFSNode *pNode, const CString& szServer, ULONG menuId)
  1247. {
  1248. CServiceManager sm;
  1249. DWORD dw;
  1250. ULONG ret;
  1251. HRESULT hr=S_OK;
  1252. CWaitCursor wait;
  1253. DWORD dwStartType = 0;
  1254. if (menuId == IDS_DMV_MENU_START)
  1255. {
  1256. // Windows NT Bug : 310919
  1257. // Check service state before starting service.
  1258. // ------------------------------------------------------------
  1259. hr = GetRouterServiceStartType(szServer, &dwStartType);
  1260. if (FHrSucceeded(hr))
  1261. {
  1262. if (dwStartType == SERVICE_DISABLED)
  1263. {
  1264. if (AfxMessageBox(IDS_PROMPT_START_DISABLED_SERVICE, MB_YESNO) == IDNO)
  1265. goto Error;
  1266. SetRouterServiceStartType(szServer, SERVICE_AUTO_START);
  1267. }
  1268. }
  1269. hr = StartRouterService(szServer);
  1270. if (!FHrSucceeded(hr))
  1271. {
  1272. AddHighLevelErrorStringId(IDS_ERR_COULD_NOT_START_ROUTER);
  1273. CORg(hr);
  1274. }
  1275. }
  1276. else if (menuId == IDS_DMV_MENU_STOP)
  1277. {
  1278. hr = StopRouterService(szServer);
  1279. if (!FHrSucceeded(hr))
  1280. {
  1281. AddHighLevelErrorStringId(IDS_ERR_COULD_NOT_STOP_ROUTER);
  1282. CORg(hr);
  1283. }
  1284. }
  1285. else if (menuId == IDS_DMV_MENU_REMOVESERVICE)
  1286. {
  1287. MachineNodeData * pData = GET_MACHINENODEDATA(pNode);
  1288. GUID guidConfig = GUID_RouterNull;
  1289. SPIRouterProtocolConfig spRouterConfig;
  1290. SPIRtrMgrProtocolInfo spRmProt;
  1291. RtrMgrProtocolCB RmProtCB;
  1292. // Stop the router service
  1293. hr = StopRouterService((LPCTSTR) szServer);
  1294. if (!FHrSucceeded(hr))
  1295. {
  1296. AddHighLevelErrorStringId(IDS_ERR_COULD_NOT_REMOVE_ROUTER);
  1297. CORg(hr);
  1298. }
  1299. // remove router id object from DS if the it's an NT5 server
  1300. Assert(m_spRouterInfo);
  1301. if(FHrSucceeded( hr = SecureRouterInfo(pNode, !m_fNoConnectingUI)))
  1302. {
  1303. RouterVersionInfo RVI;
  1304. USES_CONVERSION;
  1305. if(S_OK == m_spRouterInfo->GetRouterVersionInfo(&RVI) && RVI.dwRouterVersion >= 5)
  1306. {
  1307. hr = RRASDelRouterIdObj(T2W((LPTSTR)(LPCTSTR)szServer));
  1308. Assert(hr == S_OK);
  1309. }
  1310. }
  1311. // Windows NT Bug : 389469
  1312. // This is hardcoded for NAT (I do not want to change too much).
  1313. // Find the config GUID for NAT, and then remove the protocol.
  1314. hr = LookupRtrMgrProtocol(m_spRouterInfo,
  1315. PID_IP,
  1316. MS_IP_NAT,
  1317. &spRmProt);
  1318. // If the lookup returns S_FALSE, then it couldn't find the
  1319. // protocol.
  1320. if (FHrOK(hr))
  1321. {
  1322. spRmProt->CopyCB(&RmProtCB);
  1323. CORg( CoCreateProtocolConfig(RmProtCB.guidConfig,
  1324. m_spRouterInfo,
  1325. PID_IP,
  1326. MS_IP_NAT,
  1327. &spRouterConfig) );
  1328. if (spRouterConfig)
  1329. hr = spRouterConfig->RemoveProtocol(m_spRouterInfo->GetMachineName(),
  1330. PID_IP,
  1331. MS_IP_NAT,
  1332. NULL,
  1333. 0,
  1334. m_spRouterInfo,
  1335. 0);
  1336. }
  1337. // Perform any removal/cleanup action
  1338. UninstallGlobalSettings(szServer,
  1339. m_spRouterInfo,
  1340. pData->m_MachineConfig.m_fNt4,
  1341. TRUE);
  1342. // Remove the router from the domain
  1343. if (m_spRouterInfo->GetRouterType() != ROUTER_TYPE_LAN)
  1344. RegisterRouterInDomain(szServer, FALSE);
  1345. // Disable the service
  1346. SetRouterServiceStartType((LPCTSTR) szServer,
  1347. SERVICE_DISABLED);
  1348. //Now update the default policy
  1349. CORg( UpdateDefaultPolicy((LPTSTR)(LPCTSTR)szServer,
  1350. FALSE,
  1351. FALSE,
  1352. 0
  1353. ) );
  1354. }
  1355. else if (menuId == IDS_MENU_PAUSE_SERVICE)
  1356. {
  1357. hr = PauseRouterService(szServer);
  1358. if (!FHrSucceeded(hr))
  1359. {
  1360. AddHighLevelErrorStringId(IDS_ERR_COULD_NOT_PAUSE_ROUTER);
  1361. CORg(hr);
  1362. }
  1363. }
  1364. else if (menuId == IDS_MENU_RESUME_SERVICE)
  1365. {
  1366. hr = ResumeRouterService(szServer);
  1367. if (!FHrSucceeded(hr))
  1368. {
  1369. AddHighLevelErrorStringId(IDS_ERR_COULD_NOT_RESUME_ROUTER);
  1370. CORg(hr);
  1371. }
  1372. }
  1373. else if (menuId == IDS_MENU_RESTART_SERVICE)
  1374. {
  1375. // Do a stop and then a start
  1376. //CORg( ChgService(pNode, szServer, IDS_DMV_MENU_STOP) );
  1377. //CORg( ChgService(pNode, szServer, IDS_DMV_MENU_START) );
  1378. COSERVERINFO csi;
  1379. COAUTHINFO cai;
  1380. COAUTHIDENTITY caid;
  1381. SPIRemoteRouterRestart spRestart;
  1382. IUnknown * punk = NULL;
  1383. ZeroMemory(&csi, sizeof(csi));
  1384. ZeroMemory(&cai, sizeof(cai));
  1385. ZeroMemory(&caid, sizeof(caid));
  1386. csi.pAuthInfo = &cai;
  1387. cai.pAuthIdentityData = &caid;
  1388. CORg( CoCreateRouterConfig(szServer,
  1389. m_spRouterInfo,
  1390. &csi,
  1391. IID_IRemoteRouterRestart,
  1392. &punk) );
  1393. spRestart = (IRemoteRouterRestart *) punk;
  1394. spRestart->RestartRouter(0);
  1395. //Get the current time before we begin restart the router
  1396. CTime timeStart = CTime::GetCurrentTime();
  1397. spRestart.Release();
  1398. // Put up the dialog with the funky spinning thing to
  1399. // let the user know that something is happening
  1400. CString stTitle;
  1401. CString stDescrption;
  1402. stTitle.LoadString(IDS_PROMPT_SERVICE_RESTART_TITLE);
  1403. stDescrption.Format(IDS_PROMPT_SERVICE_RESTART_DESC, szServer);
  1404. CRestartRouterDlg dlgRestartRouter(szServer, (LPCTSTR)stDescrption,
  1405. (LPCTSTR)stTitle, &timeStart);
  1406. dlgRestartRouter.DoModal();
  1407. if (NO_ERROR != dlgRestartRouter.m_dwError)
  1408. {
  1409. AddHighLevelErrorStringId(IDS_ERR_RESTART_SERVICE);
  1410. hr = HRESULT_FROM_WIN32(dlgRestartRouter.m_dwError);
  1411. }
  1412. else if (dlgRestartRouter.m_fTimeOut)
  1413. {
  1414. CString stErrMsg;
  1415. stErrMsg.Format(IDS_ERR_RESTART_TIMEOUT, szServer);
  1416. ::AfxMessageBox((LPCTSTR)stErrMsg);
  1417. }
  1418. if (csi.pAuthInfo)
  1419. delete csi.pAuthInfo->pAuthIdentityData->Password;
  1420. }
  1421. Error:
  1422. if (!FHrSucceeded(hr))
  1423. {
  1424. AddSystemErrorMessage(hr);
  1425. TRACE0("MachineHandler::ChgService, unable to start/stop service");
  1426. }
  1427. return hr;
  1428. }
  1429. /*!--------------------------------------------------------------------------
  1430. MachineHandler::OnCreateDataObject
  1431. -
  1432. Author: KennT
  1433. ---------------------------------------------------------------------------*/
  1434. STDMETHODIMP MachineHandler::OnCreateDataObject(MMC_COOKIE cookie,
  1435. DATA_OBJECT_TYPES type,
  1436. IDataObject **ppDataObject)
  1437. {
  1438. Assert(ppDataObject);
  1439. HRESULT hr = hrOK;
  1440. MachineNodeData * pData;
  1441. SPITFSNode spNode;
  1442. m_spNodeMgr->FindNode(cookie, &spNode);
  1443. pData = GET_MACHINENODEDATA(spNode);
  1444. COM_PROTECT_TRY
  1445. {
  1446. if (m_spDataObject)
  1447. {
  1448. // If our cached data object does not have the correct
  1449. // type, release it and create a new one.
  1450. // or if it doesn't have a RouterInfo object and one is now
  1451. // available, recreate
  1452. SPINTERNAL spInternal = ExtractInternalFormat(m_spDataObject);
  1453. SPIRouterInfo spRouterInfo;
  1454. if ( (spInternal != NULL && (spInternal->m_type != type)) ||
  1455. (FAILED(spRouterInfo.HrQuery(m_spDataObject)) && m_spRouterInfo) )
  1456. m_spDataObject.Set(NULL);
  1457. }
  1458. if (!m_spDataObject)
  1459. {
  1460. //if (FAILED(SecureRouterInfo(spNode)))
  1461. //{
  1462. // Trace0("SecureRouterInfo failed! Creating data object without RouterInfo\n");
  1463. //}
  1464. if (m_spRouterInfo)
  1465. {
  1466. CORg( CreateDataObjectFromRouterInfo(m_spRouterInfo,
  1467. pData->m_stMachineName,
  1468. type, cookie, m_spTFSCompData,
  1469. &m_spDataObject, &m_dynExtensions,
  1470. pData->m_fAddedAsLocal
  1471. ) );
  1472. }
  1473. else
  1474. {
  1475. CORg( CreateRouterDataObject(pData->m_stMachineName,
  1476. type, cookie, m_spTFSCompData,
  1477. &m_spDataObject, &m_dynExtensions,
  1478. pData->m_fAddedAsLocal) );
  1479. }
  1480. Assert(m_spDataObject);
  1481. }
  1482. *ppDataObject = m_spDataObject;
  1483. (*ppDataObject)->AddRef();
  1484. COM_PROTECT_ERROR_LABEL;
  1485. }
  1486. COM_PROTECT_CATCH;
  1487. return hr;
  1488. }
  1489. /*!--------------------------------------------------------------------------
  1490. MachineHandler::ConstructNode
  1491. Initializes the node for a machine.
  1492. Author: KennT
  1493. ---------------------------------------------------------------------------*/
  1494. HRESULT MachineHandler::ConstructNode(ITFSNode *pNode, LPCTSTR szMachine, MachineNodeData *pMachineData)
  1495. {
  1496. DWORD dwErr;
  1497. const GUID * pguid;
  1498. HRESULT hr = hrOK;
  1499. int i;
  1500. Assert(pMachineData);
  1501. pNode->SetData(TFS_DATA_IMAGEINDEX, IMAGE_IDX_MACHINE);
  1502. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, IMAGE_IDX_MACHINE);
  1503. pNode->SetNodeType(&GUID_RouterMachineErrorNodeType);
  1504. // Save the machine type for this particular data type
  1505. pNode->SetData(TFS_DATA_TYPE, ROUTER_NODE_MACHINE);
  1506. // Assume that there's nothing in the node at this point
  1507. Assert(pNode->GetData(TFS_DATA_USER) == 0);
  1508. // If szMachine == NULL, then this is the local machine and
  1509. // we have to get the name of the local machine
  1510. // added the first condition m_fLocalMachine, to fix bug 223062
  1511. pMachineData->m_fAddedAsLocal = FALSE;
  1512. if (pMachineData->m_fLocalMachine || szMachine == NULL || *szMachine == 0)
  1513. {
  1514. pMachineData->m_stMachineName = GetLocalMachineName();
  1515. pMachineData->m_fLocalMachine = TRUE;
  1516. if(szMachine == NULL || *szMachine == 0)
  1517. {
  1518. pMachineData->m_fAddedAsLocal = TRUE;
  1519. // set flag in routeInfo, so other component will get this piece
  1520. Assert(m_spRouterInfo); // should have been initialized at this point
  1521. // append add as local flag
  1522. m_spRouterInfo->SetFlags(m_spRouterInfo->GetFlags() | RouterInfo_AddedAsLocal);
  1523. }
  1524. }
  1525. else
  1526. {
  1527. // Strip out the "\\" if there are any
  1528. if ((szMachine[0] == _T('\\')) && (szMachine[1] == _T('\\')))
  1529. pMachineData->m_stMachineName = szMachine + 2;
  1530. else
  1531. pMachineData->m_stMachineName = szMachine;
  1532. pMachineData->m_fLocalMachine = FALSE;
  1533. }
  1534. pMachineData->m_cookie = (MMC_COOKIE) pNode->GetData(TFS_DATA_COOKIE);
  1535. // Save the machine data back to the node
  1536. pMachineData->AddRef();
  1537. SET_MACHINENODEDATA(pNode, pMachineData);
  1538. /*-----------------------------------------------------------------------
  1539. * ALL data for the node that holds true, even if we can't get to
  1540. * the machine, must be set before the call to QueryRouterType()!
  1541. ------------------------------------------------------------------------*/
  1542. pNode->SetNodeType(&GUID_RouterMachineNodeType);
  1543. SynchronizeIcon(pNode);
  1544. EnumDynamicExtensions(pNode);
  1545. return hr;
  1546. }
  1547. /*!--------------------------------------------------------------------------
  1548. MachineHandler::DestroyHandler
  1549. -
  1550. Author: KennT
  1551. ---------------------------------------------------------------------------*/
  1552. STDMETHODIMP MachineHandler::DestroyHandler(ITFSNode *pNode)
  1553. {
  1554. MachineNodeData * pData = GET_MACHINENODEDATA(pNode);
  1555. // Release the refresh advise sinks
  1556. // ----------------------------------------------------------------
  1557. if ( m_spRouterInfo )
  1558. {
  1559. SPIRouterRefresh spRefresh;
  1560. SPIRouterRefreshModify spModify;
  1561. m_spRouterInfo->GetRefreshObject(&spRefresh);
  1562. if(spRefresh && m_bRouterInfoAddedToAutoRefresh)
  1563. {
  1564. spModify.HrQuery(spRefresh);
  1565. if (spModify)
  1566. spModify->RemoveRouterObject(IID_IRouterInfo, m_spRouterInfo);
  1567. }
  1568. if (spRefresh && pData->m_ulRefreshConnId )
  1569. spRefresh->UnadviseRefresh(pData->m_ulRefreshConnId);
  1570. }
  1571. pData->Release();
  1572. SET_MACHINENODEDATA(pNode, NULL);
  1573. m_spDataObject.Release();
  1574. m_spRouterInfo.Release();
  1575. return hrOK;
  1576. }
  1577. /*!--------------------------------------------------------------------------
  1578. MachineHandler::SetExtensionStatus
  1579. Sets whether this node is operating as an extension (network console).
  1580. Author: EricDav
  1581. ---------------------------------------------------------------------------*/
  1582. HRESULT MachineHandler::SetExtensionStatus(ITFSNode * pNode, BOOL bExtension)
  1583. {
  1584. MachineNodeData * pData = GET_MACHINENODEDATA(pNode);
  1585. pData->m_fExtension = bExtension;
  1586. return hrOK;
  1587. }
  1588. /*!--------------------------------------------------------------------------
  1589. MachineHandler::SecureRouterInfo
  1590. to postpone the loading of RouterInfo from Init, till it's used
  1591. function SecureRouterInfo is introduced to make sure RouterInfo is Loaded
  1592. Author: KennT
  1593. ---------------------------------------------------------------------------*/
  1594. HRESULT MachineHandler::SecureRouterInfo(ITFSNode *pNode, BOOL fShowUI)
  1595. {
  1596. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1597. MachineNodeData * pData = GET_MACHINENODEDATA(pNode);
  1598. HRESULT hr = S_OK;
  1599. Assert(m_spRouterInfo);
  1600. // If the name is invalid, skip this attempt.
  1601. // ----------------------------------------------------------------
  1602. // if (pData->m_machineState == machine_bad_net_path)
  1603. // {
  1604. // pData->m_dataState = data_unable_to_load;
  1605. // return hr;
  1606. // }
  1607. // If this is an NT4 RAS server, we don't need to do this
  1608. // ----------------------------------------------------------------
  1609. if (pData->m_routerType == ServerType_Ras)
  1610. {
  1611. pData->m_dataState = data_unable_to_load;
  1612. SynchronizeIcon(pNode);
  1613. return hr;
  1614. }
  1615. // If this is a workstation, we don't need to connect
  1616. // ----------------------------------------------------------------
  1617. if (pData->m_fIsServer == FALSE)
  1618. {
  1619. pData->m_dataState = data_unable_to_load;
  1620. SynchronizeIcon(pNode);
  1621. return hr;
  1622. }
  1623. // This function should try to connect
  1624. // (or reconnect).
  1625. if ((pData->m_dataState == data_not_loaded) ||
  1626. (pData->m_dataState == data_unable_to_load) ||
  1627. (pData->m_machineState == machine_access_denied))
  1628. {
  1629. pData->m_dataState = data_loading;
  1630. CORg(InitiateServerConnection(pData->m_stMachineName,
  1631. NULL,
  1632. !fShowUI,
  1633. m_spRouterInfo));
  1634. if (!FHrOK(hr))
  1635. {
  1636. // though this case when user chooses cancel on user/password dlg,
  1637. // this is considered as FAIL to connect
  1638. if (hr == S_FALSE)
  1639. hr = HResultFromWin32(ERROR_CANCELLED);
  1640. goto Error;
  1641. }
  1642. {
  1643. CWaitCursor wc;
  1644. if (m_bMergeRequired)
  1645. {
  1646. SPIRouterInfo spNewRouter;
  1647. CORg( CreateRouterInfo(&spNewRouter, NULL , (LPCTSTR) pData->m_stMachineName));
  1648. TransferCredentials ( m_spRouterInfo,
  1649. spNewRouter
  1650. );
  1651. CORg( spNewRouter->Load(T2COLE((LPTSTR) (LPCTSTR) pData->m_stMachineName),
  1652. NULL) );
  1653. m_spRouterInfo->Merge(spNewRouter);
  1654. }
  1655. else
  1656. {
  1657. CORg( m_spRouterInfo->Load(T2COLE((LPTSTR) (LPCTSTR) pData->m_stMachineName),
  1658. NULL) );
  1659. m_bMergeRequired = TRUE;
  1660. }
  1661. pData->Load();
  1662. }
  1663. pData->m_dataState = data_loaded;
  1664. }
  1665. Error:
  1666. if (FAILED(hr))
  1667. {
  1668. pData->m_dataState = data_unable_to_load;
  1669. if (hr == HResultFromWin32(ERROR_BAD_NETPATH))
  1670. {
  1671. pData->m_machineState = machine_bad_net_path;
  1672. pData->m_stState.LoadString(IDS_MACHINE_NAME_NOT_FOUND);
  1673. pData->m_serviceState = service_bad_net_path;
  1674. }
  1675. else if (hr == HResultFromWin32(ERROR_CANCELLED))
  1676. {
  1677. pData->m_machineState = machine_access_denied;
  1678. pData->m_stState = c_stStatAccessDenied;
  1679. pData->m_serviceState = service_access_denied;
  1680. }
  1681. }
  1682. // No matter what, try to synchronize the icon
  1683. // ----------------------------------------------------------------
  1684. SynchronizeIcon(pNode);
  1685. return hr;
  1686. };
  1687. /*!--------------------------------------------------------------------------
  1688. MachineHandler::OnExpandSync
  1689. If this gets called, then MMC is initalizing and we don't want to
  1690. put up UI which can cause messages to start flying around....
  1691. Author: KennT
  1692. ---------------------------------------------------------------------------*/
  1693. HRESULT MachineHandler::OnExpandSync(ITFSNode *pNode,
  1694. LPDATAOBJECT pDataObject,
  1695. LPARAM arg,
  1696. LPARAM lParam)
  1697. {
  1698. m_fNoConnectingUI = TRUE;
  1699. return hrOK;
  1700. }
  1701. /*!--------------------------------------------------------------------------
  1702. MachineHandler::OnExpand
  1703. -
  1704. Author: KennT
  1705. ---------------------------------------------------------------------------*/
  1706. HRESULT MachineHandler::OnExpand(ITFSNode *pNode,
  1707. LPDATAOBJECT pDataObject,
  1708. DWORD dwType,
  1709. LPARAM arg,
  1710. LPARAM lParam)
  1711. {
  1712. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1713. HRESULT hr = hrOK;
  1714. SPITFSNode spNode;
  1715. SPITFSNodeHandler spHandler;
  1716. IfAdminNodeHandler * pHandler = NULL;
  1717. DialInNodeHandler * pDialInHandler = NULL;
  1718. PortsNodeHandler * pPortsHandler = NULL;
  1719. RouterVersionInfo versionInfo;
  1720. DWORD dwRouterFlags = 0;
  1721. DWORD dwRouterType = 0;
  1722. MachineNodeData * pData = NULL;
  1723. if (m_bExpanded)
  1724. return hr;
  1725. CComPtr<IConsole2> spConsole;
  1726. m_spTFSCompData->GetConsole(&spConsole);
  1727. if(spConsole != NULL)
  1728. {
  1729. HWND hMainWnd = NULL;
  1730. spConsole->GetMainWindow(&hMainWnd);
  1731. if (hMainWnd)
  1732. SetForegroundWindow(hMainWnd);
  1733. }
  1734. // If this is an error node, don't show the child nodes
  1735. // ----------------------------------------------------------------
  1736. if (*(pNode->GetNodeType()) == GUID_RouterMachineErrorNodeType)
  1737. return hrOK;
  1738. Assert(m_spRouterInfo);
  1739. // We need the machine node data, that is where the connection id
  1740. // is stored.
  1741. // ----------------------------------------------------------------
  1742. pData = GET_MACHINENODEDATA(pNode);
  1743. // Load the data if we need to:
  1744. // ----------------------------------------------------------------
  1745. if (pData->m_machineState == machine_not_connected)
  1746. pData->Load();
  1747. SynchronizeIcon(pNode);
  1748. // Windows Nt Bug : 302430
  1749. // If this is an NT4 machine, we don't need to do the rest
  1750. // ----------------------------------------------------------------
  1751. if (pData->m_routerType == ServerType_Ras)
  1752. goto Error;
  1753. // Connect to the target router
  1754. // ----------------------------------------------------------------
  1755. CORg( SecureRouterInfo(pNode, m_fNoConnectingUI) );
  1756. // Windows NT Bug : ?
  1757. // Need to check the machine state.
  1758. // ----------------------------------------------------------------
  1759. if (pData->m_dataState < data_loaded)
  1760. return hrOK;
  1761. {
  1762. CWaitCursor wc;
  1763. // Setup the refresh advise sinks
  1764. // ----------------------------------------------------------------
  1765. if ( m_spRouterInfo )
  1766. {
  1767. SPIRouterRefresh spRefresh;
  1768. SPIRouterRefreshModify spModify;
  1769. m_spRouterInfo->GetRefreshObject(&spRefresh);
  1770. if(spRefresh)
  1771. {
  1772. spModify.HrQuery(spRefresh);
  1773. if (spModify)
  1774. spModify->AddRouterObject(IID_IRouterInfo, m_spRouterInfo);
  1775. m_bRouterInfoAddedToAutoRefresh = TRUE;
  1776. // The lUserParam for this refresh connection, must be the
  1777. // cookie.
  1778. // ------------------------------------------------------------
  1779. if ( pData->m_ulRefreshConnId == 0 )
  1780. spRefresh->AdviseRefresh(&m_IRtrAdviseSink,
  1781. &(pData->m_ulRefreshConnId),
  1782. pNode->GetData(TFS_DATA_COOKIE));
  1783. }
  1784. }
  1785. dwRouterType = m_spRouterInfo->GetRouterType();
  1786. m_spRouterInfo->GetRouterVersionInfo(&versionInfo);
  1787. dwRouterFlags = versionInfo.dwRouterFlags;
  1788. // Routing interfaces is enabled only if NOT a RAS-only router
  1789. AddRemoveRoutingInterfacesNode(pNode, dwRouterType, dwRouterFlags);
  1790. AddRemoveDialinNode(pNode, dwRouterType, dwRouterFlags);
  1791. AddRemovePortsNode(pNode, dwRouterType, dwRouterFlags);
  1792. // update status node, and Icon
  1793. if (m_pSumNodeHandler && m_pSumNode)
  1794. m_pSumNodeHandler->OnCommand(m_pSumNode,IDS_MENU_REFRESH,CCT_RESULT, NULL, 0);
  1795. m_bExpanded = TRUE;
  1796. CORg(AddDynamicNamespaceExtensions(pNode));
  1797. }
  1798. Error:
  1799. // Windows NT Bug : 274198
  1800. // If we have an error and if the error is not "ERROR_BAD_NETPATH"
  1801. // then we continue to load the info
  1802. // ----------------------------------------------------------------
  1803. // Setup the machine state at this point
  1804. // ----------------------------------------------------------------
  1805. if (!FHrSucceeded(hr))
  1806. {
  1807. if (hr == HResultFromWin32(ERROR_BAD_NETPATH))
  1808. {
  1809. pData->m_machineState = machine_bad_net_path;
  1810. pData->m_serviceState = service_bad_net_path;
  1811. pData->m_stState.LoadString(IDS_MACHINE_NAME_NOT_FOUND);
  1812. }
  1813. else
  1814. {
  1815. // Try to load up the data if we can
  1816. if ((pData->m_machineState == machine_unable_to_connect) ||
  1817. (pData->m_machineState == machine_not_connected))
  1818. pData->Load();
  1819. if (pData->m_routerType == ServerType_Ras)
  1820. hr = StartRasAdminExe(pData);
  1821. else if (hr != HResultFromWin32(ERROR_CANCELLED))
  1822. DisplayErrorMessage(NULL, hr);
  1823. }
  1824. m_fTryToConnect = FALSE;
  1825. // snapin relies on registry service, check if it's running.
  1826. // check if Remote Registry Service is not running
  1827. CServiceManager csm;
  1828. CService svr;
  1829. DWORD dwState = 0;
  1830. BOOL RRWrong = TRUE; // if any problem with RemoteRegistry Service
  1831. if (!IsLocalMachine(m_spRouterInfo->GetMachineName()) && SUCCEEDED( csm.HrOpen(SC_MANAGER_CONNECT, m_spRouterInfo->GetMachineName(), NULL)))
  1832. {
  1833. if (SUCCEEDED(csm.HrOpenService(&svr, L"RemoteRegistry", SERVICE_QUERY_STATUS)))
  1834. {
  1835. if (SUCCEEDED(svr.HrQueryState(&dwState)))
  1836. {
  1837. if(dwState == SERVICE_RUNNING)
  1838. RRWrong = FALSE;
  1839. }
  1840. }
  1841. if (RRWrong)
  1842. {
  1843. CString str1;
  1844. str1.LoadString(IDS_ERR_RR_SERVICE_NOT_RUNNING);
  1845. CString str;
  1846. str.Format(str1, m_spRouterInfo->GetMachineName());
  1847. ::AfxMessageBox(str);
  1848. }
  1849. }
  1850. // end of remote registry service checking
  1851. }
  1852. return hr;
  1853. }
  1854. HRESULT MachineHandler::OnResultRefresh(ITFSComponent * pComponent,
  1855. LPDATAOBJECT pDataObject,
  1856. MMC_COOKIE cookie,
  1857. LPARAM arg,
  1858. LPARAM lParam)
  1859. {
  1860. HRESULT hr = hrOK;
  1861. SPITFSNode spNode;
  1862. m_spResultNodeMgr->FindNode(cookie, &spNode);
  1863. MachineNodeData * pData = GET_MACHINENODEDATA(spNode);
  1864. int nOldState = pData->m_dataState;
  1865. if (pData->m_dataState != data_loaded)
  1866. {
  1867. SPIDataObject spDataObject;
  1868. // change state to not connected here
  1869. pData->m_dataState = data_not_loaded;
  1870. hr = SecureRouterInfo(spNode, m_fNoConnectingUI);
  1871. }
  1872. // force an update if the machine was able to load
  1873. // or the state has changed
  1874. if (hr == S_OK &&
  1875. m_spRouterInfo &&
  1876. ( (pData->m_dataState >= data_loaded) ||
  1877. (nOldState != pData->m_dataState) ) )
  1878. {
  1879. ForceGlobalRefresh(m_spRouterInfo);
  1880. hr = OnCommand(spNode, IDS_DMV_MENU_REFRESH, CCT_RESULT, NULL, 0);
  1881. }
  1882. return hr;
  1883. }
  1884. /*!--------------------------------------------------------------------------
  1885. MachineHandler::AddMenuItems
  1886. Over-ride this to add our view menu item
  1887. Author: EricDav
  1888. ---------------------------------------------------------------------------*/
  1889. STDMETHODIMP
  1890. MachineHandler::AddMenuItems
  1891. (
  1892. ITFSComponent * pComponent,
  1893. MMC_COOKIE cookie,
  1894. LPDATAOBJECT pDataObject,
  1895. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  1896. long * pInsertionAllowed
  1897. )
  1898. {
  1899. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  1900. HRESULT hr = S_OK;
  1901. return hr;
  1902. }
  1903. /*!--------------------------------------------------------------------------
  1904. MachineHandler::Command
  1905. Handles commands for the current view
  1906. Author: EricDav
  1907. ---------------------------------------------------------------------------*/
  1908. STDMETHODIMP
  1909. MachineHandler::Command
  1910. (
  1911. ITFSComponent * pComponent,
  1912. MMC_COOKIE cookie,
  1913. int nCommandID,
  1914. LPDATAOBJECT pDataObject
  1915. )
  1916. {
  1917. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1918. HRESULT hr = S_OK;
  1919. switch (nCommandID)
  1920. {
  1921. case MMCC_STANDARD_VIEW_SELECT:
  1922. break;
  1923. }
  1924. return hr;
  1925. }
  1926. /*---------------------------------------------------------------------------
  1927. MachineHandler::OnGetResultViewType
  1928. Return the result view that this node is going to support
  1929. Author: EricDav
  1930. ---------------------------------------------------------------------------*/
  1931. HRESULT
  1932. MachineHandler::OnGetResultViewType
  1933. (
  1934. ITFSComponent * pComponent,
  1935. MMC_COOKIE cookie,
  1936. LPOLESTR * ppViewType,
  1937. long * pViewOptions
  1938. )
  1939. {
  1940. WCHAR wszURL[MAX_PATH+1] = {0};
  1941. WCHAR wszSystemDirectory[MAX_PATH+1] = {0};
  1942. GetSystemDirectoryW ( wszSystemDirectory, MAX_PATH);
  1943. wsprintf( wszURL, L"res://%s\\mprsnap.dll/configure.htm", wszSystemDirectory );
  1944. //Send the URL back and see what happens
  1945. *pViewOptions = MMC_VIEW_OPTIONS_NOLISTVIEWS;
  1946. *ppViewType = SysAllocString(wszURL);
  1947. return S_OK;
  1948. //return BaseRouterHandler::OnGetResultViewType(pComponent, cookie, ppViewType, pViewOptions);
  1949. }
  1950. /*!--------------------------------------------------------------------------
  1951. MachineHandler::OnResultSelect
  1952. Update the result pane
  1953. Author: EricDav
  1954. ---------------------------------------------------------------------------*/
  1955. HRESULT MachineHandler::OnResultSelect(ITFSComponent *pComponent,
  1956. LPDATAOBJECT pDataObject,
  1957. MMC_COOKIE cookie,
  1958. LPARAM arg,
  1959. LPARAM lParam)
  1960. {
  1961. HRESULT hr = hrOK;
  1962. SPITFSNode spNode;
  1963. CORg(BaseRouterHandler::OnResultSelect(pComponent, pDataObject, cookie, arg, lParam));
  1964. m_spNodeMgr->FindNode(cookie, &spNode);
  1965. UpdateResultMessage(spNode);
  1966. Error:
  1967. return hr;
  1968. }
  1969. /*!--------------------------------------------------------------------------
  1970. MachineHandler::UpdateResultMessage
  1971. Determines what (if anything) to put in the result pane message
  1972. Author: EricDav
  1973. ---------------------------------------------------------------------------*/
  1974. void MachineHandler::UpdateResultMessage(ITFSNode * pNode)
  1975. {
  1976. HRESULT hr = hrOK;
  1977. int nMessage = -1; // default none
  1978. int i;
  1979. CString strTitle, strBody, strTemp;
  1980. // Only do this if the node we are looking at is a
  1981. // machine node.
  1982. if ((pNode == NULL) ||
  1983. (*(pNode->GetNodeType()) != GUID_RouterMachineNodeType))
  1984. return;
  1985. MachineNodeData * pData = GET_MACHINENODEDATA(pNode);
  1986. if (pData == NULL)
  1987. return;
  1988. if (pData->m_routerType == ServerType_RrasUninstalled)
  1989. {
  1990. nMessage = MACHINE_MESSAGE_NOT_CONFIGURED;
  1991. // now build the text strings
  1992. // first entry is the title
  1993. strTitle.LoadString(g_uMachineMessages[nMessage][0]);
  1994. // second entry is the icon
  1995. // third ... n entries are the body strings
  1996. for (i = 2; g_uMachineMessages[nMessage][i] != 0; i++)
  1997. {
  1998. strTemp.LoadString(g_uMachineMessages[nMessage][i]);
  1999. strBody += strTemp;
  2000. }
  2001. }
  2002. if (nMessage == -1)
  2003. {
  2004. ClearMessage(pNode);
  2005. }
  2006. else
  2007. {
  2008. ShowMessage(pNode, strTitle, strBody, (IconIdentifier) g_uMachineMessages[nMessage][1]);
  2009. }
  2010. }
  2011. /*!--------------------------------------------------------------------------
  2012. MachineHandler::UserResultNotify
  2013. -
  2014. Author: KennT
  2015. ---------------------------------------------------------------------------*/
  2016. HRESULT MachineHandler::UserResultNotify(ITFSNode *pNode,
  2017. LPARAM lParam1,
  2018. LPARAM lParam2)
  2019. {
  2020. HRESULT hr = hrOK;
  2021. COM_PROTECT_TRY
  2022. {
  2023. // Do not handle RRAS_ON_SAVE, since there isn't any column
  2024. // information for us to save.
  2025. // ------------------------------------------------------------
  2026. if (lParam1 != RRAS_ON_SAVE)
  2027. {
  2028. hr = BaseRouterHandler::UserResultNotify(pNode, lParam1, lParam2);
  2029. }
  2030. }
  2031. COM_PROTECT_CATCH;
  2032. return hr;
  2033. }
  2034. /*---------------------------------------------------------------------------
  2035. Embedded IRtrAdviseSink
  2036. ---------------------------------------------------------------------------*/
  2037. ImplementEmbeddedUnknown(MachineHandler, IRtrAdviseSink)
  2038. /*!--------------------------------------------------------------------------
  2039. MachineHandler::EIRtrAdviseSink::OnChange
  2040. -
  2041. Author: KennT
  2042. ---------------------------------------------------------------------------*/
  2043. STDMETHODIMP MachineHandler::EIRtrAdviseSink::OnChange(LONG_PTR ulConn,
  2044. DWORD dwChangeType, DWORD dwObjectType, LPARAM lUserParam, LPARAM lParam)
  2045. {
  2046. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  2047. InitPThis(MachineHandler, IRtrAdviseSink);
  2048. SPITFSNode spThisNode;
  2049. HRESULT hr = hrOK;
  2050. COM_PROTECT_TRY
  2051. {
  2052. //$ TODO : this is bogus, this is tied to the cookie
  2053. // for this handler. What we need is a mapping between
  2054. // the connection ids (for this handler) and the appropriate
  2055. // nodes.
  2056. // ------------------------------------------------------------
  2057. // The lUserParam passed into the refresh is the cookie for
  2058. // this machine node.
  2059. // ------------------------------------------------------------
  2060. pThis->m_spNodeMgr->FindNode(lUserParam, &spThisNode);
  2061. if(spThisNode)
  2062. pThis->SynchronizeIcon(spThisNode);
  2063. if (dwChangeType == ROUTER_REFRESH)
  2064. {
  2065. DWORD dwNewRouterType, dwNewRouterFlags;
  2066. RouterVersionInfo versionInfo;
  2067. dwNewRouterType = pThis->m_spRouterInfo->GetRouterType();
  2068. pThis->m_spRouterInfo->GetRouterVersionInfo(&versionInfo);
  2069. dwNewRouterFlags = versionInfo.dwRouterFlags;
  2070. // Ok, we have to take a look see and what nodes
  2071. // we can add/remove
  2072. // ----------------------------------------------------
  2073. // Look to see if we need the Routing Interfaces node
  2074. // ----------------------------------------------------
  2075. pThis->AddRemoveRoutingInterfacesNode(spThisNode, dwNewRouterType,
  2076. dwNewRouterFlags);
  2077. // Look to see if we need the ports node
  2078. // ----------------------------------------------------
  2079. pThis->AddRemovePortsNode(spThisNode, dwNewRouterType,
  2080. dwNewRouterFlags);
  2081. // Look to see if we need the Dial-In Clients node
  2082. // ----------------------------------------------------
  2083. pThis->AddRemoveDialinNode(spThisNode, dwNewRouterType,
  2084. dwNewRouterFlags);
  2085. }
  2086. }
  2087. COM_PROTECT_CATCH;
  2088. return hr;
  2089. }
  2090. /*!--------------------------------------------------------------------------
  2091. MachineHandler::AddRemoveRoutingInterfacesNode
  2092. -
  2093. Author: KennT
  2094. ---------------------------------------------------------------------------*/
  2095. HRESULT MachineHandler::AddRemoveRoutingInterfacesNode(ITFSNode *pNode, DWORD dwRouterType, DWORD dwRouterFlags)
  2096. {
  2097. HRESULT hr = hrOK;
  2098. SPITFSNodeHandler spHandler;
  2099. IfAdminNodeHandler * pHandler = NULL;
  2100. SPITFSNode spChild;
  2101. // Search for an already existing node
  2102. // ----------------------------------------------------------------
  2103. SearchChildNodesForGuid(pNode, &GUID_RouterIfAdminNodeType, &spChild);
  2104. if ((dwRouterType & (ROUTER_TYPE_WAN | ROUTER_TYPE_LAN)) &&
  2105. (dwRouterFlags & RouterSnapin_IsConfigured))
  2106. {
  2107. // Create the new node if we don't already have one
  2108. // ------------------------------------------------------------
  2109. if (spChild == NULL)
  2110. {
  2111. // as a default, add the routing interfaces node
  2112. // --------------------------------------------------------
  2113. pHandler = new IfAdminNodeHandler(m_spTFSCompData);
  2114. CORg( pHandler->Init(m_spRouterInfo, m_pConfigStream) );
  2115. spHandler = pHandler;
  2116. CreateContainerTFSNode(&spChild,
  2117. &GUID_RouterIfAdminNodeType,
  2118. static_cast<ITFSNodeHandler *>(pHandler),
  2119. static_cast<ITFSResultHandler *>(pHandler),
  2120. m_spNodeMgr);
  2121. // Call to the node handler to init the node data
  2122. // --------------------------------------------------------
  2123. pHandler->ConstructNode(spChild);
  2124. // Make the node immediately visible
  2125. // --------------------------------------------------------
  2126. spChild->SetVisibilityState(TFS_VIS_SHOW);
  2127. //$ TODO : We should add this in the right place (where is that?)
  2128. // --------------------------------------------------------
  2129. pNode->AddChild(spChild);
  2130. }
  2131. }
  2132. else
  2133. {
  2134. if (spChild)
  2135. {
  2136. // Remove this node
  2137. // --------------------------------------------------------
  2138. pNode->RemoveChild(spChild);
  2139. spChild->Destroy();
  2140. spChild.Release();
  2141. }
  2142. }
  2143. Error:
  2144. return hr;
  2145. }
  2146. /*!--------------------------------------------------------------------------
  2147. MachineHandler::AddRemovePortsNode
  2148. -
  2149. Author: KennT
  2150. ---------------------------------------------------------------------------*/
  2151. HRESULT MachineHandler::AddRemovePortsNode(ITFSNode *pNode, DWORD dwRouterType,
  2152. DWORD dwRouterFlags)
  2153. {
  2154. HRESULT hr = hrOK;
  2155. SPITFSNodeHandler spHandler;
  2156. PortsNodeHandler * pPortsHandler = NULL;
  2157. SPITFSNode spChild;
  2158. // Search for an already existing node
  2159. // ----------------------------------------------------------------
  2160. SearchChildNodesForGuid(pNode, &GUID_RouterPortsNodeType, &spChild);
  2161. if ( (dwRouterType & (ROUTER_TYPE_RAS | ROUTER_TYPE_WAN) ) &&
  2162. (dwRouterFlags & RouterSnapin_IsConfigured))
  2163. {
  2164. // Create the new node if we don't already have one
  2165. // ------------------------------------------------------------
  2166. if (spChild == NULL)
  2167. {
  2168. // as a default, add the routing interfaces node
  2169. // --------------------------------------------------------
  2170. pPortsHandler = new PortsNodeHandler(m_spTFSCompData);
  2171. CORg( pPortsHandler->Init(m_spRouterInfo, m_pConfigStream) );
  2172. spHandler = pPortsHandler;
  2173. CreateContainerTFSNode(&spChild,
  2174. &GUID_RouterPortsNodeType,
  2175. static_cast<ITFSNodeHandler *>(pPortsHandler),
  2176. static_cast<ITFSResultHandler *>(pPortsHandler),
  2177. m_spNodeMgr);
  2178. // Call to the node handler to init the node data
  2179. // --------------------------------------------------------
  2180. pPortsHandler->ConstructNode(spChild);
  2181. // Make the node immediately visible
  2182. // --------------------------------------------------------
  2183. spChild->SetVisibilityState(TFS_VIS_SHOW);
  2184. //$ TODO : We should add this in the right place (where is that?)
  2185. // --------------------------------------------------------
  2186. pNode->AddChild(spChild);
  2187. }
  2188. }
  2189. else
  2190. {
  2191. if (spChild)
  2192. {
  2193. // Remove this node
  2194. // --------------------------------------------------------
  2195. pNode->RemoveChild(spChild);
  2196. spChild->Destroy();
  2197. spChild.Release();
  2198. }
  2199. }
  2200. Error:
  2201. return hr;
  2202. }
  2203. /*!--------------------------------------------------------------------------
  2204. MachineHandler::AddRemoveDialinNode
  2205. -
  2206. Author: KennT
  2207. ---------------------------------------------------------------------------*/
  2208. HRESULT MachineHandler::AddRemoveDialinNode(ITFSNode *pNode, DWORD dwRouterType,
  2209. DWORD dwRouterFlags)
  2210. {
  2211. HRESULT hr = hrOK;
  2212. SPITFSNodeHandler spHandler;
  2213. DialInNodeHandler * pDialInHandler = NULL;
  2214. SPITFSNode spChild;
  2215. // Search for an already existing node
  2216. // ----------------------------------------------------------------
  2217. SearchChildNodesForGuid(pNode, &GUID_RouterDialInNodeType, &spChild);
  2218. if ((dwRouterType & ROUTER_TYPE_RAS ) &&
  2219. (dwRouterFlags & RouterSnapin_IsConfigured))
  2220. {
  2221. // Create the new node if we don't already have one
  2222. // ------------------------------------------------------------
  2223. if (spChild == NULL)
  2224. {
  2225. // as a default, add the dial in node
  2226. pDialInHandler = new DialInNodeHandler(m_spTFSCompData);
  2227. CORg( pDialInHandler->Init(m_spRouterInfo, m_pConfigStream) );
  2228. spHandler = pDialInHandler;
  2229. CreateContainerTFSNode(&spChild,
  2230. &GUID_RouterDialInNodeType,
  2231. static_cast<ITFSNodeHandler *>(pDialInHandler),
  2232. static_cast<ITFSResultHandler *>(pDialInHandler),
  2233. m_spNodeMgr);
  2234. // Call to the node handler to init the node data
  2235. pDialInHandler->ConstructNode(spChild);
  2236. // Make the node immediately visible
  2237. spChild->SetVisibilityState(TFS_VIS_SHOW);
  2238. //$ TODO : We should add this in the right place (where is that?)
  2239. // --------------------------------------------------------
  2240. pNode->AddChild(spChild);
  2241. }
  2242. }
  2243. else
  2244. {
  2245. if (spChild)
  2246. {
  2247. // Remove this node
  2248. // --------------------------------------------------------
  2249. pNode->RemoveChild(spChild);
  2250. spChild->Destroy();
  2251. spChild.Release();
  2252. }
  2253. }
  2254. Error:
  2255. return hr;
  2256. }
  2257. /*!--------------------------------------------------------------------------
  2258. MachineConfig::GetMachineConfig
  2259. -
  2260. Author: KennT
  2261. ---------------------------------------------------------------------------*/
  2262. HRESULT MachineConfig::GetMachineConfig(MachineNodeData *pData)
  2263. {
  2264. // m_fReachable
  2265. m_fReachable = (pData->m_machineState == machine_connected);
  2266. // m_fNt4
  2267. m_fNt4 = (pData->m_routerVersion.dwRouterVersion <= 4);
  2268. // m_fConfigured
  2269. m_fConfigured = (pData->m_routerType != ServerType_RrasUninstalled);
  2270. // m_dwServiceStatus
  2271. // Set in FetchServerState();
  2272. // m_fLocalMachine
  2273. m_fLocalMachine = IsLocalMachine((LPCTSTR) pData->m_stMachineName);
  2274. return hrOK;
  2275. }
  2276. /*!--------------------------------------------------------------------------
  2277. MachineHandler::StartRasAdminExe
  2278. -
  2279. Author: MikeG (a-migall)
  2280. ---------------------------------------------------------------------------*/
  2281. HRESULT MachineHandler::StartRasAdminExe(MachineNodeData *pData)
  2282. {
  2283. // Locals.
  2284. CString sRasAdminExePath;
  2285. CString stCommandLine;
  2286. LPTSTR pszRasAdminExe = NULL;
  2287. STARTUPINFO si;
  2288. PROCESS_INFORMATION pi;
  2289. HRESULT hr = S_OK;
  2290. UINT nCnt = 0;
  2291. DWORD cbAppCnt = 0;
  2292. // Check the handle to see if rasadmin is running
  2293. if (pData->m_hRasAdmin != INVALID_HANDLE_VALUE)
  2294. {
  2295. DWORD dwReturn = 0;
  2296. // If the state is not signalled, then the process has
  2297. // not exited (or some other occurred).
  2298. dwReturn = WaitForSingleObject(pData->m_hRasAdmin, 0);
  2299. if (dwReturn == WAIT_TIMEOUT)
  2300. {
  2301. // The process has not signalled (it's still running);
  2302. return hrOK;
  2303. }
  2304. else
  2305. {
  2306. // the process has signalled or the call failed, close the handle
  2307. // and call up RasAdmin
  2308. ::CloseHandle(pData->m_hRasAdmin);
  2309. pData->m_hRasAdmin = INVALID_HANDLE_VALUE;
  2310. }
  2311. }
  2312. try
  2313. {
  2314. // Looks like the RasAdmin.Exe is not running on this
  2315. // workstation's desktop; so, start it!
  2316. // Figure out where the \\WinNt\System32 directory is.
  2317. pszRasAdminExe = sRasAdminExePath.GetBuffer((MAX_PATH*sizeof(TCHAR)));
  2318. nCnt = ::GetSystemDirectory(pszRasAdminExe,
  2319. (MAX_PATH*sizeof(TCHAR)));
  2320. sRasAdminExePath.ReleaseBuffer();
  2321. if (nCnt == 0)
  2322. throw (HRESULT_FROM_WIN32(::GetLastError()));
  2323. // Complete the construction of the executable's name.
  2324. sRasAdminExePath += _T("\\rasadmin.exe");
  2325. Assert(!::IsBadStringPtr((LPCTSTR)sRasAdminExePath,
  2326. sRasAdminExePath.GetLength()));
  2327. // Build command line string
  2328. stCommandLine.Format(_T("%s \\\\%s"),
  2329. (LPCTSTR) sRasAdminExePath,
  2330. (LPCTSTR) pData->m_stMachineName);
  2331. // Start RasAdmin.Exe.
  2332. ::ZeroMemory(&si, sizeof(STARTUPINFO));
  2333. si.cb = sizeof(STARTUPINFO);
  2334. si.dwX = si.dwY = si.dwXSize = si.dwYSize = 0L;
  2335. si.wShowWindow = SW_SHOW;
  2336. ::ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
  2337. if (!::CreateProcess(NULL, // pointer to name of executable module
  2338. (LPTSTR) (LPCTSTR) stCommandLine, // pointer to command line string
  2339. NULL, // process security attributes
  2340. NULL, // thread security attributes
  2341. FALSE, // handle inheritance flag
  2342. CREATE_NEW_CONSOLE, // creation flags
  2343. NULL, // pointer to new environment block
  2344. NULL, // pointer to current directory name
  2345. &si, // pointer to STARTUPINFO
  2346. &pi)) // pointer to PROCESS_INFORMATION
  2347. {
  2348. hr = HRESULT_FROM_WIN32(::GetLastError());
  2349. ::CloseHandle(pi.hProcess);
  2350. }
  2351. else
  2352. {
  2353. Assert(pData->m_hRasAdmin == INVALID_HANDLE_VALUE);
  2354. pData->m_hRasAdmin = pi.hProcess;
  2355. }
  2356. ::CloseHandle(pi.hThread);
  2357. //
  2358. // OPT: Maybe we should have used the ShellExecute() API rather than
  2359. // the CreateProcess() API. Why? The ShellExecute() API will
  2360. // give the shell the opportunity to check the current user's
  2361. // system policy settings before allowing the executable to execute.
  2362. //
  2363. }
  2364. catch (CException * e)
  2365. {
  2366. hr = E_OUTOFMEMORY;
  2367. }
  2368. catch (HRESULT hrr)
  2369. {
  2370. hr = hrr;
  2371. }
  2372. catch (...)
  2373. {
  2374. hr = E_UNEXPECTED;
  2375. }
  2376. //Assert(SUCCEEDED(hr));
  2377. return hr;
  2378. }
  2379. /*!--------------------------------------------------------------------------
  2380. MachineHandler::OnResultShow
  2381. -
  2382. Author: MikeG (a-migall)
  2383. ---------------------------------------------------------------------------*/
  2384. HRESULT MachineHandler::OnResultShow(ITFSComponent *pComponent,
  2385. MMC_COOKIE cookie,
  2386. LPARAM arg,
  2387. LPARAM lParam)
  2388. {
  2389. BOOL bSelect = static_cast<BOOL>(arg);
  2390. HRESULT hr = hrOK;
  2391. SPITFSNode spNode;
  2392. MachineNodeData * pData = NULL;
  2393. hr = BaseRouterHandler::OnResultShow(pComponent, cookie, arg, lParam);
  2394. if (bSelect)
  2395. {
  2396. m_spNodeMgr->FindNode(cookie, &spNode);
  2397. // We need the machine node data.
  2398. // ------------------------------------------------------------
  2399. pData = GET_MACHINENODEDATA(spNode);
  2400. if (pData->m_routerType == ServerType_Ras)
  2401. hr = StartRasAdminExe(pData);
  2402. else if ((pData->m_machineState == machine_access_denied) ||
  2403. (pData->m_machineState == machine_bad_net_path))
  2404. {
  2405. // Try to connect again
  2406. // --------------------------------------------------------
  2407. if (m_fTryToConnect)
  2408. OnExpand(spNode, NULL, 0, 0, 0);
  2409. // If we have failed, keep on trucking!
  2410. // --------------------------------------------------------
  2411. m_fTryToConnect = TRUE;
  2412. }
  2413. }
  2414. return hr;
  2415. }
  2416. /*!--------------------------------------------------------------------------
  2417. MachineHandler::OnDelete
  2418. -
  2419. Author: KennT
  2420. ---------------------------------------------------------------------------*/
  2421. HRESULT MachineHandler::OnDelete(ITFSNode *pNode,
  2422. LPARAM arg,
  2423. LPARAM param)
  2424. {
  2425. SPITFSNode spNode;
  2426. SPITFSNode spStatusNode;
  2427. SPITFSNodeHandler spHoldHandler;
  2428. SPITFSNode spParent;
  2429. SPITFSNode spGrandParent;
  2430. SPITFSNode spthis;
  2431. SPITFSNode spMachineNode;
  2432. DMVNodeData* pData;
  2433. MachineNodeData * pMachineData = NULL;
  2434. MachineNodeData * pNodeData = NULL;
  2435. SPITFSNodeEnum spNodeEnum;
  2436. SPITFSNode spResultNode;
  2437. MMC_COOKIE cookie;
  2438. // This will be the machine node, in the scope pane, that
  2439. // we wish to delete.
  2440. Assert(pNode);
  2441. cookie = pNode->GetData(TFS_DATA_COOKIE);
  2442. // Addref this node so that it won't get deleted before we're out
  2443. // of this function
  2444. spHoldHandler.Set( this );
  2445. spthis.Set( pNode );
  2446. pNode->GetParent( &spParent );
  2447. Assert( spParent );
  2448. // Given this node, find the node in the result pane that
  2449. // corresponds to this scope node.
  2450. // Iterate through the nodes of our parent node to find the
  2451. // server status node.
  2452. // ----------------------------------------------------------------
  2453. spParent->GetEnum(&spNodeEnum);
  2454. while (spNodeEnum->Next(1, &spStatusNode, NULL) == hrOK)
  2455. {
  2456. if ((*spStatusNode->GetNodeType()) == GUID_DomainStatusNodeType)
  2457. break;
  2458. spStatusNode.Release();
  2459. }
  2460. Assert(spStatusNode != NULL);
  2461. // Now iterate through the status node to find the appropriate
  2462. // machine.
  2463. // ----------------------------------------------------------------
  2464. spNodeEnum.Release();
  2465. spStatusNode->GetEnum(&spNodeEnum);
  2466. while (spNodeEnum->Next(1, &spResultNode, NULL) == hrOK)
  2467. {
  2468. pData = GET_DMVNODEDATA( spResultNode );
  2469. Assert( pData );
  2470. pMachineData = pData->m_spMachineData;
  2471. if (pMachineData->m_cookie == cookie)
  2472. break;
  2473. spResultNode.Release();
  2474. }
  2475. // Note: if the server status node has not been expanded yet
  2476. // we could hit this case.
  2477. // ----------------------------------------------------------------
  2478. if (pMachineData && (pMachineData->m_cookie == cookie))
  2479. {
  2480. // fetch & delete server node (the node in the result pane)
  2481. spStatusNode->RemoveChild( spResultNode );
  2482. spResultNode.Release();
  2483. }
  2484. else
  2485. {
  2486. // If this is the case, we need to remove the server from
  2487. // the list before it is expanded.
  2488. // ------------------------------------------------------------
  2489. SPITFSNodeHandler spHandler;
  2490. spParent->GetHandler(&spHandler);
  2491. // Get the node data (for this specific machine node)
  2492. // ------------------------------------------------------------
  2493. pNodeData = GET_MACHINENODEDATA(pNode);
  2494. spHandler->UserNotify(spParent,
  2495. DMV_DELETE_SERVER_ENTRY,
  2496. (LPARAM) (LPCTSTR) pNodeData->m_stMachineName
  2497. );
  2498. }
  2499. // delete the machine node (the node in the scope pane)
  2500. spParent->RemoveChild( pNode );
  2501. return hrOK;
  2502. }
  2503. STDMETHODIMP MachineHandler::UserNotify(ITFSNode *pNode, LPARAM lParam, LPARAM lParam2)
  2504. {
  2505. HRESULT hr = hrOK;
  2506. COM_PROTECT_TRY
  2507. {
  2508. switch (lParam)
  2509. {
  2510. case MACHINE_SYNCHRONIZE_ICON:
  2511. {
  2512. SynchronizeIcon(pNode);
  2513. }
  2514. break;
  2515. default:
  2516. hr = BaseRouterHandler::UserNotify(pNode, lParam, lParam2);
  2517. break;
  2518. }
  2519. }
  2520. COM_PROTECT_CATCH;
  2521. return hr;
  2522. }