Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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