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.

1733 lines
56 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. IFadmin
  7. Interface node information
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "ifadmin.h"
  12. #include "iface.h" // to get InterfaceNodeHandler class
  13. #include "rtrstrm.h" // for RouterAdminConfigStream
  14. #include "rtrlib.h" // ContainerColumnInfo
  15. #include "coldlg.h" // ColumnDlg
  16. #include "column.h" // ComponentConfigStream
  17. #include "refresh.h" // IRouterRefresh
  18. #include "refrate.h" // CRefRate dialog
  19. #include "machine.h"
  20. #include "dmvcomp.h"
  21. #include "rtrerr.h" // FormatRasError
  22. #include "ports.h" // for PortsDataEntry
  23. extern "C" {
  24. #define _NOUIUTIL_H_
  25. #include "dtl.h"
  26. #include "pbuser.h"
  27. };
  28. /*!--------------------------------------------------------------------------
  29. AddStaticRoute -- Collapse this later into common module
  30. This function ASSUMES that the route is NOT in the block.
  31. Author: KennT
  32. ---------------------------------------------------------------------------*/
  33. HRESULT AddStaticRoute(MIB_IPFORWARDROW * pNewForwardRow,
  34. IInfoBase *pInfoBase,
  35. InfoBlock *pBlock,
  36. DWORD dwCount)
  37. {
  38. MIB_IPFORWARDROW IPRow;
  39. HRESULT hr = hrOK;
  40. if (pBlock == NULL)
  41. {
  42. //
  43. // No IP_ROUTE_INFO block was found; we create a new block
  44. // with the new route, and add that block to the interface-info
  45. //
  46. CORg( pInfoBase->AddBlock(IP_ROUTE_INFO, sizeof(MIB_IPFORWARDROW),
  47. (LPBYTE) pNewForwardRow, dwCount, 0) );
  48. }
  49. else
  50. {
  51. // Either the route is completely new, or it is a route
  52. // which was moved from one interface to another.
  53. // Set a new block as the IP_ROUTE_INFO,
  54. // and include the re-configured route in the new block.
  55. MIB_IPFORWARDROW* prdTable;
  56. prdTable = new MIB_IPFORWARDROW[pBlock->dwCount + 1];
  57. Assert(prdTable);
  58. // Copy the original table of routes
  59. ::memcpy(prdTable, pBlock->pData,
  60. pBlock->dwCount * sizeof(MIB_IPFORWARDROW));
  61. // Append the new route
  62. prdTable[pBlock->dwCount] = *pNewForwardRow;
  63. // Replace the old route-table with the new one
  64. CORg( pInfoBase->SetData(IP_ROUTE_INFO, sizeof(MIB_IPFORWARDROW),
  65. (LPBYTE) prdTable, pBlock->dwCount + 1, 0) );
  66. }
  67. Error:
  68. return hr;
  69. }
  70. IfAdminNodeData::IfAdminNodeData()
  71. {
  72. #ifdef DEBUG
  73. StrCpyA(m_szDebug, "IfAdminNodeData");
  74. #endif
  75. }
  76. IfAdminNodeData::~IfAdminNodeData()
  77. {
  78. }
  79. /*!--------------------------------------------------------------------------
  80. IfAdminNodeData::InitAdminNodeData
  81. -
  82. Author: KennT
  83. ---------------------------------------------------------------------------*/
  84. HRESULT IfAdminNodeData::InitAdminNodeData(ITFSNode *pNode, RouterAdminConfigStream *pConfigStream)
  85. {
  86. HRESULT hr = hrOK;
  87. IfAdminNodeData * pData = NULL;
  88. pData = new IfAdminNodeData;
  89. SET_IFADMINNODEDATA(pNode, pData);
  90. return hr;
  91. }
  92. /*!--------------------------------------------------------------------------
  93. IfAdminNodeData::FreeAdminNodeData
  94. -
  95. Author: KennT
  96. ---------------------------------------------------------------------------*/
  97. HRESULT IfAdminNodeData::FreeAdminNodeData(ITFSNode *pNode)
  98. {
  99. IfAdminNodeData * pData = GET_IFADMINNODEDATA(pNode);
  100. delete pData;
  101. SET_IFADMINNODEDATA(pNode, NULL);
  102. return hrOK;
  103. }
  104. STDMETHODIMP IfAdminNodeHandler::QueryInterface(REFIID riid, LPVOID *ppv)
  105. {
  106. // Is the pointer bad?
  107. if (ppv == NULL)
  108. return E_INVALIDARG;
  109. // Place NULL in *ppv in case of failure
  110. *ppv = NULL;
  111. // This is the non-delegating IUnknown implementation
  112. if (riid == IID_IUnknown)
  113. *ppv = (LPVOID) this;
  114. else if (riid == IID_IRtrAdviseSink)
  115. *ppv = &m_IRtrAdviseSink;
  116. else
  117. return CHandler::QueryInterface(riid, ppv);
  118. // If we're going to return an interface, AddRef it first
  119. if (*ppv)
  120. {
  121. ((LPUNKNOWN) *ppv)->AddRef();
  122. return hrOK;
  123. }
  124. else
  125. return E_NOINTERFACE;
  126. }
  127. /*---------------------------------------------------------------------------
  128. NodeHandler implementation
  129. ---------------------------------------------------------------------------*/
  130. extern const ContainerColumnInfo s_rgIfAdminColumnInfo[];
  131. const ContainerColumnInfo s_rgIfAdminColumnInfo[] =
  132. {
  133. { IDS_COL_INTERFACES, CON_SORT_BY_STRING, TRUE, COL_IF_NAME },
  134. { IDS_COL_TYPE, CON_SORT_BY_STRING, TRUE, COL_STRING },
  135. { IDS_COL_STATUS, CON_SORT_BY_STRING, TRUE, COL_STATUS },
  136. { IDS_COL_CONNECTION_STATE, CON_SORT_BY_STRING, TRUE, COL_STRING},
  137. { IDS_COL_DEVICE_NAME, CON_SORT_BY_STRING, TRUE, COL_IF_DEVICE},
  138. };
  139. IfAdminNodeHandler::IfAdminNodeHandler(ITFSComponentData *pCompData)
  140. : BaseContainerHandler(pCompData, DM_COLUMNS_IFADMIN, s_rgIfAdminColumnInfo),
  141. m_bExpanded(FALSE),
  142. m_hInstRasDlg(NULL),
  143. m_pfnRouterEntryDlg(NULL),
  144. m_pConfigStream(NULL),
  145. m_ulConnId(0),
  146. m_ulRefreshConnId(0)
  147. {
  148. // Setup the verb states for this node
  149. m_rgButtonState[MMC_VERB_REFRESH_INDEX] = ENABLED;
  150. m_bState[MMC_VERB_REFRESH_INDEX] = TRUE;
  151. }
  152. /*!--------------------------------------------------------------------------
  153. IfAdminNodeHandler::Init
  154. -
  155. Author: KennT
  156. ---------------------------------------------------------------------------*/
  157. HRESULT IfAdminNodeHandler::Init(IRouterInfo *pRouterInfo, RouterAdminConfigStream *pConfigStream)
  158. {
  159. HRESULT hr = hrOK;
  160. HKEY hkeyMachine;
  161. DWORD dwErr;
  162. // If we don't have a router info then we probably failed to load
  163. // or failed to connect. Bail out of this.
  164. if (!pRouterInfo)
  165. CORg( E_FAIL );
  166. m_spRouterInfo.Set(pRouterInfo);
  167. // Also need to register for change notifications
  168. m_spRouterInfo->RtrAdvise(&m_IRtrAdviseSink, &m_ulConnId, 0);
  169. if (m_hInstRasDlg == NULL)
  170. m_hInstRasDlg = LoadLibrary(_T("rasdlg.dll"));
  171. if (m_hInstRasDlg)
  172. {
  173. m_pfnRouterEntryDlg= (PROUTERENTRYDLG)::GetProcAddress(m_hInstRasDlg,
  174. SZROUTERENTRYDLG);
  175. if (m_pfnRouterEntryDlg == NULL)
  176. {
  177. Trace0("MPRSNAP - Could not find function: RouterEntryDlg\n");
  178. }
  179. }
  180. else
  181. {
  182. dwErr = GetLastError();
  183. Trace0("MPRSNAP - failed to load rasdlg.dll\n");
  184. }
  185. m_pConfigStream = pConfigStream;
  186. Error:
  187. return hrOK;
  188. }
  189. /*!--------------------------------------------------------------------------
  190. IfAdminNodeHandler::DestroyHandler
  191. Implementation of ITFSNodeHandler::DestroyHandler
  192. Author: KennT
  193. ---------------------------------------------------------------------------*/
  194. STDMETHODIMP IfAdminNodeHandler::DestroyHandler(ITFSNode *pNode)
  195. {
  196. IfAdminNodeData::FreeAdminNodeData(pNode);
  197. m_spDataObject.Release();
  198. if (m_hInstRasDlg)
  199. {
  200. FreeLibrary(m_hInstRasDlg);
  201. m_hInstRasDlg = NULL;
  202. }
  203. if (m_ulRefreshConnId)
  204. {
  205. SPIRouterRefresh spRefresh;
  206. if (m_spRouterInfo)
  207. m_spRouterInfo->GetRefreshObject(&spRefresh);
  208. if (spRefresh)
  209. spRefresh->UnadviseRefresh(m_ulRefreshConnId);
  210. }
  211. m_ulRefreshConnId = 0;
  212. if (m_spRouterInfo)
  213. {
  214. m_spRouterInfo->RtrUnadvise(m_ulConnId);
  215. m_spRouterInfo.Release();
  216. }
  217. return hrOK;
  218. }
  219. /*!--------------------------------------------------------------------------
  220. IfAdminNodeHandler::HasPropertyPages
  221. Implementation of ITFSNodeHandler::HasPropertyPages
  222. Author: KennT
  223. ---------------------------------------------------------------------------*/
  224. STDMETHODIMP
  225. IfAdminNodeHandler::HasPropertyPages
  226. (
  227. ITFSNode * pNode,
  228. LPDATAOBJECT pDataObject,
  229. DATA_OBJECT_TYPES type,
  230. DWORD dwType
  231. )
  232. {
  233. return hrOK;
  234. }
  235. /*!--------------------------------------------------------------------------
  236. IfAdminNodeHandler::OnAddMenuItems
  237. Implementation of ITFSNodeHandler::OnAddMenuItems
  238. Author: KennT
  239. ---------------------------------------------------------------------------*/
  240. STDMETHODIMP IfAdminNodeHandler::OnAddMenuItems(
  241. ITFSNode *pNode,
  242. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  243. LPDATAOBJECT lpDataObject,
  244. DATA_OBJECT_TYPES type,
  245. DWORD dwType,
  246. long *pInsertionAllowed)
  247. {
  248. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  249. HRESULT hr = S_OK;
  250. CString stMenuItem;
  251. DWORD dwWiz;
  252. ULONG ulFlags;
  253. SPIRouterRefresh spRefresh;
  254. RouterVersionInfo routerVer;
  255. BOOL fNt4;
  256. COM_PROTECT_TRY
  257. {
  258. m_spRouterInfo->GetRouterVersionInfo(&routerVer);
  259. fNt4 = (routerVer.dwRouterVersion == 4);
  260. if ((type == CCT_SCOPE) || (dwType == TFS_COMPDATA_CHILD_CONTEXTMENU))
  261. {
  262. long lMenuText;
  263. //
  264. // If any more menus are added to this section, then the
  265. // code for the InterfaceNodeHandler needs to be updated also.
  266. //
  267. // Add these menus at the top of the context menu
  268. if (!fNt4)
  269. {
  270. if (*pInsertionAllowed & CCM_INSERTIONALLOWED_TOP)
  271. {
  272. lMenuText = IDS_MENU_NEW_DEMAND_DIAL_INTERFACE;
  273. stMenuItem.LoadString( lMenuText );
  274. hr = LoadAndAddMenuItem( pContextMenuCallback,
  275. stMenuItem,
  276. lMenuText,
  277. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  278. EnableAddInterface() ? 0 : MF_GRAYED);
  279. #ifdef KSL_IPINIP
  280. lMenuText = IDS_MENU_ADD_TUNNEL;
  281. stMenuItem.LoadString( lMenuText );
  282. hr = LoadAndAddMenuItem( pContextMenuCallback,
  283. stMenuItem,
  284. lMenuText,
  285. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  286. EnableAddInterface() ? 0 : MF_GRAYED);
  287. #endif //KSL_IPINIP
  288. }
  289. }
  290. // For NT4, we add the option to disable the wizard
  291. // interface.
  292. // --------------------------------------------------------
  293. if (fNt4)
  294. {
  295. if (*pInsertionAllowed & CCM_INSERTIONALLOWED_TOP)
  296. {
  297. lMenuText = IDS_MENU_ADD_INTERFACE;
  298. stMenuItem.LoadString(lMenuText);
  299. hr = LoadAndAddMenuItem( pContextMenuCallback,
  300. stMenuItem,
  301. lMenuText,
  302. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  303. EnableAddInterface() ? 0 : MF_GRAYED);
  304. }
  305. hr = GetDemandDialWizardRegKey(OLE2CT(m_spRouterInfo->GetMachineName()),
  306. &dwWiz);
  307. if (!FHrSucceeded(hr))
  308. dwWiz = TRUE;
  309. ulFlags = dwWiz ? MF_CHECKED : MF_UNCHECKED;
  310. if (!FHrSucceeded(hr))
  311. ulFlags |= MF_GRAYED;
  312. if (*pInsertionAllowed & CCM_INSERTIONALLOWED_TOP)
  313. {
  314. lMenuText = IDS_MENU_USE_DEMANDDIALWIZARD;
  315. stMenuItem.LoadString(lMenuText);
  316. hr = LoadAndAddMenuItem( pContextMenuCallback,
  317. stMenuItem,
  318. lMenuText,
  319. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  320. ulFlags );
  321. ASSERT( SUCCEEDED(hr) );
  322. }
  323. }
  324. }
  325. }
  326. COM_PROTECT_CATCH;
  327. return hr;
  328. }
  329. /*!--------------------------------------------------------------------------
  330. IfAdminNodeHandler::OnCommand
  331. Implementation of ITFSNodeHandler::OnCommand
  332. Author: KennT
  333. ---------------------------------------------------------------------------*/
  334. STDMETHODIMP IfAdminNodeHandler::OnCommand(ITFSNode *pNode, long nCommandId,
  335. DATA_OBJECT_TYPES type,
  336. LPDATAOBJECT pDataObject,
  337. DWORD dwType)
  338. {
  339. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  340. HRESULT hr = S_OK;
  341. COM_PROTECT_TRY
  342. {
  343. switch (nCommandId)
  344. {
  345. case IDS_MENU_NEW_DEMAND_DIAL_INTERFACE:
  346. case IDS_MENU_ADD_INTERFACE:
  347. OnAddInterface();
  348. break;
  349. #ifdef KSL_IPINIP
  350. case IDS_MENU_ADD_TUNNEL:
  351. OnNewTunnel();
  352. break;
  353. #endif //KSL_IPINIP
  354. case IDS_MENU_USE_DEMANDDIALWIZARD:
  355. OnUseDemandDialWizard();
  356. break;
  357. case IDS_MENU_REFRESH:
  358. SynchronizeNodeData(pNode);
  359. break;
  360. default:
  361. break;
  362. }
  363. }
  364. COM_PROTECT_CATCH;
  365. return hr;
  366. }
  367. /*!--------------------------------------------------------------------------
  368. IfAdminNodeHandler::GetString
  369. Implementation of ITFSNodeHandler::GetString
  370. Author: KennT
  371. ---------------------------------------------------------------------------*/
  372. STDMETHODIMP_(LPCTSTR) IfAdminNodeHandler::GetString(ITFSNode *pNode, int nCol)
  373. {
  374. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  375. HRESULT hr = hrOK;
  376. COM_PROTECT_TRY
  377. {
  378. if (m_stTitle.IsEmpty())
  379. m_stTitle.LoadString(IDS_ROUTING_INTERFACES);
  380. }
  381. COM_PROTECT_CATCH;
  382. return m_stTitle;
  383. }
  384. /*!--------------------------------------------------------------------------
  385. IfAdminNodeHandler::OnCreateDataObject
  386. Implementation of ITFSNodeHandler::OnCreateDataObject
  387. Author: KennT
  388. ---------------------------------------------------------------------------*/
  389. STDMETHODIMP IfAdminNodeHandler::OnCreateDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, IDataObject **ppDataObject)
  390. {
  391. HRESULT hr = hrOK;
  392. COM_PROTECT_TRY
  393. {
  394. if (!m_spDataObject)
  395. {
  396. CORg( CreateDataObjectFromRouterInfo(m_spRouterInfo,
  397. m_spRouterInfo->GetMachineName(),
  398. type, cookie, m_spTFSCompData,
  399. &m_spDataObject, NULL, FALSE) );
  400. Assert(m_spDataObject);
  401. }
  402. *ppDataObject = m_spDataObject;
  403. (*ppDataObject)->AddRef();
  404. COM_PROTECT_ERROR_LABEL;
  405. }
  406. COM_PROTECT_CATCH;
  407. return hr;
  408. }
  409. /*!--------------------------------------------------------------------------
  410. IfAdminNodeHandler::OnExpand
  411. -
  412. Author: KennT
  413. ---------------------------------------------------------------------------*/
  414. HRESULT IfAdminNodeHandler::OnExpand(ITFSNode *pNode,
  415. LPDATAOBJECT pDataObject,
  416. DWORD dwType,
  417. LPARAM arg,
  418. LPARAM lParam)
  419. {
  420. HRESULT hr = hrOK;
  421. SPIEnumInterfaceInfo spEnumIf;
  422. SPIInterfaceInfo spIf;
  423. // If we don't have a router object, then we don't have any info, don't
  424. // try to expand.
  425. if (!m_spRouterInfo)
  426. return hrOK;
  427. // Windows NT Bug: 288427
  428. // This flag may also get set inside of the OnChange() call.
  429. // The OnChange() will enumerate and all interfaces.
  430. // They may have been added as the result of an OnChange()
  431. // because they were added before the OnExpand() was called.
  432. //
  433. // WARNING! Be careful about adding anything to this function,
  434. // since the m_bExpanded can be set in another function.
  435. // ----------------------------------------------------------------
  436. if (m_bExpanded)
  437. {
  438. return hrOK;
  439. }
  440. COM_PROTECT_TRY
  441. {
  442. CORg( m_spRouterInfo->EnumInterface(&spEnumIf) );
  443. while (spEnumIf->Next(1, &spIf, NULL) == hrOK)
  444. {
  445. AddInterfaceNode(pNode, spIf);
  446. spIf.Release();
  447. }
  448. m_bExpanded = TRUE;
  449. // Now that we have all of the nodes, update the data for
  450. // all of the nodes
  451. SynchronizeNodeData(pNode);
  452. COM_PROTECT_ERROR_LABEL;
  453. }
  454. COM_PROTECT_CATCH;
  455. return hr;
  456. }
  457. /*!--------------------------------------------------------------------------
  458. IfAdminNodeHandler::OnResultShow
  459. -
  460. Author: KennT
  461. ---------------------------------------------------------------------------*/
  462. HRESULT IfAdminNodeHandler::OnResultShow(ITFSComponent *pTFSComponent,
  463. MMC_COOKIE cookie,
  464. LPARAM arg,
  465. LPARAM lParam)
  466. {
  467. BOOL bSelect = (BOOL) arg;
  468. HRESULT hr = hrOK;
  469. SPIRouterRefresh spRefresh;
  470. SPITFSNode spNode;
  471. BaseContainerHandler::OnResultShow(pTFSComponent, cookie, arg, lParam);
  472. if (bSelect)
  473. {
  474. // Call synchronize on this node
  475. m_spNodeMgr->FindNode(cookie, &spNode);
  476. if (spNode)
  477. SynchronizeNodeData(spNode);
  478. }
  479. // Un/Register for refresh advises
  480. if (m_spRouterInfo)
  481. m_spRouterInfo->GetRefreshObject(&spRefresh);
  482. if (spRefresh)
  483. {
  484. if (bSelect)
  485. {
  486. if (m_ulRefreshConnId == 0)
  487. spRefresh->AdviseRefresh(&m_IRtrAdviseSink, &m_ulRefreshConnId, 0);
  488. }
  489. else
  490. {
  491. if (m_ulRefreshConnId)
  492. spRefresh->UnadviseRefresh(m_ulRefreshConnId);
  493. m_ulRefreshConnId = 0;
  494. }
  495. }
  496. return hr;
  497. }
  498. /*!--------------------------------------------------------------------------
  499. IfAdminNodeHandler::ConstructNode
  500. Initializes the Domain node (sets it up).
  501. Author: KennT
  502. ---------------------------------------------------------------------------*/
  503. HRESULT IfAdminNodeHandler::ConstructNode(ITFSNode *pNode)
  504. {
  505. HRESULT hr = hrOK;
  506. IfAdminNodeData * pNodeData;
  507. if (pNode == NULL)
  508. return hrOK;
  509. COM_PROTECT_TRY
  510. {
  511. // Need to initialize the data for the Domain node
  512. pNode->SetData(TFS_DATA_IMAGEINDEX, IMAGE_IDX_INTERFACES);
  513. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, IMAGE_IDX_INTERFACES);
  514. pNode->SetData(TFS_DATA_SCOPEID, 0);
  515. // This is a leaf node in the scope pane
  516. pNode->SetData(TFS_DATA_SCOPE_LEAF_NODE, TRUE);
  517. m_cookie = reinterpret_cast<LONG_PTR>(pNode);
  518. pNode->SetData(TFS_DATA_COOKIE, m_cookie);
  519. pNode->SetNodeType(&GUID_RouterIfAdminNodeType);
  520. IfAdminNodeData::InitAdminNodeData(pNode, m_pConfigStream);
  521. pNodeData = GET_IFADMINNODEDATA(pNode);
  522. Assert(pNodeData);
  523. // Copy over this data so that the Interface node can access
  524. // this and use this to configure its interface.
  525. pNodeData->m_hInstRasDlg = m_hInstRasDlg;
  526. pNodeData->m_pfnRouterEntryDlg = m_pfnRouterEntryDlg;
  527. }
  528. COM_PROTECT_CATCH
  529. return hr;
  530. }
  531. /*!--------------------------------------------------------------------------
  532. IfAdminNodeHandler::OnAddInterface
  533. -
  534. Author: KennT
  535. ---------------------------------------------------------------------------*/
  536. HRESULT IfAdminNodeHandler::OnAddInterface()
  537. {
  538. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  539. HRESULT hr = hrOK;
  540. CString stPhoneBook;
  541. CString stRouter;
  542. DWORD dwErr = NO_ERROR;
  543. SPIConsole spConsole;
  544. SPIInterfaceInfo spIfInfo;
  545. BOOL bStatus;
  546. MachineNodeData *pData;
  547. SPITFSNode spNode, spParent;
  548. DWORD dwRouterType;
  549. CString stServiceDesc;
  550. RouterVersionInfo routerVersion;
  551. if (!EnableAddInterface())
  552. {
  553. AddHighLevelErrorStringId(IDS_ERR_TEMPNOADD);
  554. CORg( E_FAIL );
  555. }
  556. m_spNodeMgr->FindNode(m_cookie, &spNode);
  557. spNode->GetParent(&spParent);
  558. pData = GET_MACHINENODEDATA(spParent);
  559. // Get the router type, if WAN routing is not-enabled
  560. // then we don't need to create demand-dial interfaces.
  561. // ----------------------------------------------------------------
  562. Assert(m_spRouterInfo);
  563. dwRouterType = m_spRouterInfo->GetRouterType();
  564. Trace1("Routertype is %d\n", dwRouterType);
  565. if ((dwRouterType & ROUTER_TYPE_WAN) == 0)
  566. {
  567. //
  568. //Show warning message box. This is not an error anymore
  569. //
  570. AfxMessageBox ( IDS_ERR_NEEDS_WAN, MB_OK|MB_ICONINFORMATION );
  571. hr = E_FAIL;
  572. return hr;
  573. /*
  574. AddHighLevelErrorStringId(IDS_ERR_NEEDS_WAN);
  575. CORg( E_FAIL );
  576. */
  577. }
  578. // Get the version info. Needed later on.
  579. // ----------------------------------------------------------------
  580. m_spRouterInfo->GetRouterVersionInfo(&routerVersion);
  581. // Check to see if the router service is running, before
  582. // continuing on.
  583. // ----------------------------------------------------------------
  584. hr = IsRouterServiceRunning(m_spRouterInfo->GetMachineName(), NULL);
  585. if (hr == hrFalse)
  586. {
  587. // Ask the user if they want to start the service
  588. // ------------------------------------------------------------
  589. if (AfxMessageBox(IDS_PROMPT_SERVICESTART, MB_YESNO) != IDYES)
  590. CWRg( ERROR_CANCELLED );
  591. // Else start the service
  592. // ------------------------------------------------------------
  593. stServiceDesc.LoadString(IDS_RRAS_SERVICE_DESC);
  594. dwErr = TFSStartService(m_spRouterInfo->GetMachineName(), c_szRemoteAccess, stServiceDesc);
  595. if (dwErr != NO_ERROR)
  596. {
  597. AddHighLevelErrorStringId(IDS_ERR_IFASERVICESTOPPED);
  598. CWRg( dwErr );
  599. }
  600. //$todo: what to do about forcing a refresh through?
  601. // ForceGlobalRefresh();
  602. }
  603. // Now we need to check to see if there are any routing-enabled ports
  604. // (Here we can assume that rasman is running). We can make this
  605. // check only for >= NT5, since this is when we got Rao's API.
  606. // ----------------------------------------------------------------
  607. if ((routerVersion.dwRouterVersion >= 5) &&
  608. !FLookForRoutingEnabledPorts(m_spRouterInfo->GetMachineName()))
  609. {
  610. AfxMessageBox(IDS_ERR_NO_ROUTING_ENABLED_PORTS);
  611. CWRg( ERROR_CANCELLED );
  612. }
  613. m_spTFSCompData->GetConsole(&spConsole);
  614. // First create the phone book entry.
  615. RASENTRYDLG info;
  616. HWND hwnd;
  617. ZeroMemory( &info, sizeof(info) );
  618. info.dwSize = sizeof(info);
  619. hwnd = NULL;
  620. spConsole->GetMainWindow(&hwnd);
  621. info.hwndOwner = hwnd;
  622. //info.hwndOwner = IFGetApp()->m_hWndHost;
  623. info.dwFlags |= RASEDFLAG_NewEntry;
  624. TRACE0("RouterEntryDlg\n");
  625. ASSERT(m_pfnRouterEntryDlg);
  626. stRouter = m_spRouterInfo->GetMachineName();
  627. GetPhoneBookPath(stRouter, &stPhoneBook);
  628. if (stRouter.GetLength() == 0)
  629. {
  630. stRouter = CString(_T("\\\\")) + GetLocalMachineName();
  631. }
  632. bStatus = m_pfnRouterEntryDlg(
  633. (LPTSTR)(LPCTSTR)stRouter, (LPTSTR)(LPCTSTR)stPhoneBook, NULL, &info);
  634. Trace2("RouterEntryDlg=%f,e=%d\n", bStatus, info.dwError);
  635. if (!bStatus)
  636. {
  637. if (info.dwError != NO_ERROR)
  638. {
  639. AddHighLevelErrorStringId(IDS_ERR_UNABLETOCONFIGPBK);
  640. CWRg( info.dwError );
  641. }
  642. CWRg( ERROR_CANCELLED );
  643. }
  644. //
  645. CORg( CreateInterfaceInfo(&spIfInfo,
  646. info.szEntry,
  647. ROUTER_IF_TYPE_FULL_ROUTER) );
  648. CORg( spIfInfo->SetTitle(spIfInfo->GetId()) );
  649. CORg( spIfInfo->SetMachineName(m_spRouterInfo->GetMachineName()) );
  650. CORg( m_spRouterInfo->AddInterface(spIfInfo) );
  651. // Ok, we've added the interfaces, we now need to add in
  652. // the appropriate defaults for the router managers
  653. if (info.reserved2 & RASNP_Ip)
  654. {
  655. CORg( AddRouterManagerToInterface(spIfInfo,
  656. m_spRouterInfo,
  657. PID_IP) );
  658. }
  659. if (info.reserved2 & RASNP_Ipx)
  660. {
  661. CORg( AddRouterManagerToInterface(spIfInfo,
  662. m_spRouterInfo,
  663. PID_IPX) );
  664. }
  665. HANDLE hMachine = INVALID_HANDLE_VALUE;
  666. dwErr = ::MprConfigServerConnect((LPWSTR)m_spRouterInfo->GetMachineName(), &hMachine);
  667. if(dwErr != NOERROR || hMachine == INVALID_HANDLE_VALUE)
  668. goto Error;
  669. //
  670. //Add static routes here if any
  671. //
  672. SROUTEINFOLIST * pSRouteList = (SROUTEINFOLIST * )info.reserved;
  673. while ( pSRouteList )
  674. {
  675. MIB_IPFORWARDROW route;
  676. SPIInfoBase spInfoBase;
  677. SPIRtrMgrInterfaceInfo spRmIf;
  678. InfoBlock * pBlock;
  679. SROUTEINFOLIST * pTemp;
  680. ZeroMemory(&route, sizeof(route) );
  681. route.dwForwardDest = INET_ADDR(pSRouteList->RouteInfo.pszDestIP);
  682. route.dwForwardMask = INET_ADDR(pSRouteList->RouteInfo.pszNetworkMask);
  683. route.dwForwardMetric1 = _ttol(pSRouteList->RouteInfo.pszMetric );
  684. route.dwForwardMetric5 = RTM_VIEW_MASK_UCAST | RTM_VIEW_MASK_MCAST;
  685. route.dwForwardNextHop = 0;
  686. if (routerVersion.dwRouterVersion < 5)
  687. route.dwForwardProto = PROTO_IP_LOCAL;
  688. else
  689. route.dwForwardProto = PROTO_IP_NT_STATIC;
  690. CORg( spIfInfo->FindRtrMgrInterface(PID_IP, &spRmIf) );
  691. CORg( spRmIf->GetInfoBase( hMachine,
  692. NULL,
  693. NULL,
  694. &spInfoBase));
  695. // Ok, go ahead and add the route
  696. // Get the IP_ROUTE_INFO block from the interface
  697. spInfoBase->GetBlock(IP_ROUTE_INFO, &pBlock, 0);
  698. CORg( AddStaticRoute(&route, spInfoBase, pBlock, 1) );
  699. // Update the interface information
  700. CORg( spRmIf->Save(m_spRouterInfo->GetMachineName(),
  701. hMachine,
  702. NULL,
  703. NULL,
  704. spInfoBase,
  705. 0));
  706. //Free all the entry items
  707. pTemp = pSRouteList->pNext;
  708. GlobalFree(pSRouteList->RouteInfo.pszDestIP);
  709. GlobalFree(pSRouteList->RouteInfo.pszNetworkMask);
  710. GlobalFree(pSRouteList->RouteInfo.pszMetric);
  711. GlobalFree(pSRouteList);
  712. pSRouteList = pTemp;
  713. }
  714. // disconnect it
  715. if(hMachine != INVALID_HANDLE_VALUE)
  716. {
  717. ::MprAdminServerDisconnect(hMachine);
  718. }
  719. Error:
  720. if (!FHrSucceeded(hr) && (hr != HRESULT_FROM_WIN32(ERROR_CANCELLED)))
  721. {
  722. TCHAR szErr[2048] = _T(" ");
  723. if (hr != E_FAIL) // E_FAIL doesn't give user any information
  724. {
  725. FormatRasError(hr, szErr, DimensionOf(szErr));
  726. }
  727. AddLowLevelErrorString(szErr);
  728. // If there is no high level error string, add a
  729. // generic error string. This will be used if no other
  730. // high level error string is set.
  731. SetDefaultHighLevelErrorStringId(IDS_ERR_GENERIC_ERROR);
  732. DisplayTFSErrorMessage(NULL);
  733. }
  734. return hr;
  735. }
  736. #ifdef KSL_IPINIP
  737. /*!--------------------------------------------------------------------------
  738. IfAdminNodeHandler::OnNewTunnel
  739. -
  740. Author: KennT
  741. ---------------------------------------------------------------------------*/
  742. HRESULT IfAdminNodeHandler::OnNewTunnel()
  743. {
  744. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  745. HRESULT hr = hrOK;
  746. SPIConsole spConsole;
  747. SPIInterfaceInfo spIfInfo;
  748. int idsErr = 0;
  749. RouterVersionInfo routerVersion;
  750. TunnelDialog tunnel;
  751. GUID guidNew;
  752. TCHAR szGuid[128];
  753. if (!EnableAddInterface())
  754. {
  755. idsErr = IDS_ERR_TEMPNOADD;
  756. CORg( E_FAIL );
  757. }
  758. // Get the version info. Needed later on.
  759. // ----------------------------------------------------------------
  760. m_spRouterInfo->GetRouterVersionInfo(&routerVersion);
  761. m_spTFSCompData->GetConsole(&spConsole);
  762. // For now, popup a dialog asking for the tunnel information
  763. // ----------------------------------------------------------------
  764. if (tunnel.DoModal() == IDOK)
  765. {
  766. // We need to create a GUID for this tunnel.
  767. // ------------------------------------------------------------
  768. CORg( CoCreateGuid(&guidNew) );
  769. // Convert the GUID into a string
  770. // ------------------------------------------------------------
  771. Verify( StringFromGUID2(guidNew, szGuid, DimensionOf(szGuid)) );
  772. CORg( CreateInterfaceInfo(&spIfInfo,
  773. szGuid,
  774. ROUTER_IF_TYPE_TUNNEL1) );
  775. CORg( spIfInfo->SetTitle(tunnel.m_stName) );
  776. CORg( spIfInfo->SetMachineName(m_spRouterInfo->GetMachineName()) );
  777. CORg( m_spRouterInfo->AddInterface(spIfInfo) );
  778. // Need to add the IP Specific data
  779. ForceGlobalRefresh(m_spRouterInfo);
  780. }
  781. Error:
  782. if (!FHrSucceeded(hr) && (hr != HRESULT_FROM_WIN32(ERROR_CANCELLED)))
  783. {
  784. TCHAR szErr[2048];
  785. if (idsErr)
  786. AddHighLevelErrorStringId(idsErr);
  787. FormatRasError(hr, szErr, DimensionOf(szErr));
  788. AddLowLevelErrorString(szErr);
  789. DisplayTFSErrorMessage(NULL);
  790. }
  791. return hr;
  792. }
  793. #endif //KSL_IPINIP
  794. /*!--------------------------------------------------------------------------
  795. IfAdminNodeHandler::AddRouterManagerToInterface
  796. -
  797. Author: KennT
  798. ---------------------------------------------------------------------------*/
  799. HRESULT IfAdminNodeHandler::AddRouterManagerToInterface(IInterfaceInfo *pIf,
  800. IRouterInfo *pRouter,
  801. DWORD dwTransportId)
  802. {
  803. HRESULT hr = hrOK;
  804. SPIRtrMgrInfo spRm;
  805. SPIRtrMgrInterfaceInfo spRmIf;
  806. SPIInfoBase spInfoBase;
  807. // Get the router manager
  808. hr = pRouter->FindRtrMgr(dwTransportId, &spRm);
  809. // If this cannot find the RtrMgr, then just exit out.
  810. if (!FHrOK(hr))
  811. goto Error;
  812. // Construct a new CRmInterfaceInfo object
  813. CORg( CreateRtrMgrInterfaceInfo(&spRmIf,
  814. spRm->GetId(),
  815. spRm->GetTransportId(),
  816. pIf->GetId(),
  817. pIf->GetInterfaceType()) );
  818. CORg( spRmIf->SetTitle(pIf->GetTitle()) );
  819. CORg( spRmIf->SetMachineName(pRouter->GetMachineName()) );
  820. // Add this interface to the router-manager
  821. CORg( pIf->AddRtrMgrInterface(spRmIf, NULL) );
  822. // get/create the infobase for this interface
  823. CORg( spRmIf->Load(pIf->GetMachineName(), NULL, NULL, NULL) );
  824. CORg( spRmIf->GetInfoBase(NULL, NULL, NULL, &spInfoBase) );
  825. if (!spInfoBase)
  826. CORg( CreateInfoBase(&spInfoBase) );
  827. if (dwTransportId == PID_IP)
  828. CORg( AddIpPerInterfaceBlocks(pIf, spInfoBase) );
  829. else
  830. {
  831. Assert(dwTransportId == PID_IPX);
  832. CORg( AddIpxPerInterfaceBlocks(pIf, spInfoBase) );
  833. }
  834. // Save the infobase
  835. CORg( spRmIf->Save(pIf->GetMachineName(),
  836. NULL, NULL, NULL, spInfoBase, 0) );
  837. // Mark this interface (it can now be synced with the router)
  838. spRmIf->SetFlags( spRmIf->GetFlags() | RouterSnapin_InSyncWithRouter );
  839. // Notify RM of a new interface
  840. spRm->RtrNotify(ROUTER_CHILD_ADD, ROUTER_OBJ_RmIf, 0);
  841. Error:
  842. if (!FHrSucceeded(hr))
  843. {
  844. // Cleanup
  845. pIf->DeleteRtrMgrInterface(dwTransportId, TRUE);
  846. }
  847. return hr;
  848. }
  849. /*!--------------------------------------------------------------------------
  850. IfAdminNodeHandler::OnUseDemandDialWizard
  851. -
  852. Author: KennT
  853. ---------------------------------------------------------------------------*/
  854. HRESULT IfAdminNodeHandler::OnUseDemandDialWizard()
  855. {
  856. HRESULT hr = hrOK;
  857. DWORD dwWiz;
  858. hr = GetDemandDialWizardRegKey(OLE2CT(m_spRouterInfo->GetMachineName()),
  859. &dwWiz);
  860. if (FHrSucceeded(hr))
  861. {
  862. // Ok, now toggle the switch
  863. SetDemandDialWizardRegKey(OLE2CT(m_spRouterInfo->GetMachineName()),
  864. !dwWiz);
  865. }
  866. return hr;
  867. }
  868. /*!--------------------------------------------------------------------------
  869. IfAdminNodeHandler::SynchronizeNodeData
  870. -
  871. Author: KennT
  872. ---------------------------------------------------------------------------*/
  873. HRESULT IfAdminNodeHandler::SynchronizeNodeData(ITFSNode *pThisNode)
  874. {
  875. Assert(pThisNode);
  876. SPITFSNodeEnum spEnum;
  877. SPITFSNode spNode;
  878. DWORD dwStatus;
  879. DWORD dwConnState;
  880. DWORD dwUnReachabilityReason;
  881. int i;
  882. HRESULT hr = hrOK;
  883. InterfaceNodeData *pData;
  884. SPMprAdminBuffer spIf0Table;
  885. SPMprServerHandle sphMprServer;
  886. MPR_INTERFACE_0 * if0Table = NULL;
  887. DWORD if0Count = 0;
  888. DWORD dwTotal;
  889. DWORD dwErr;
  890. // Get the status data from the running router
  891. dwErr = ConnectRouter(m_spRouterInfo->GetMachineName(), &sphMprServer);
  892. if (dwErr == NO_ERROR)
  893. {
  894. ::MprAdminInterfaceEnum(sphMprServer,
  895. 0,
  896. (BYTE **) &spIf0Table,
  897. (DWORD) -1,
  898. &if0Count,
  899. &dwTotal,
  900. NULL);
  901. if0Table = (MPR_INTERFACE_0 *) (BYTE *) spIf0Table;
  902. }
  903. pThisNode->GetEnum(&spEnum);
  904. spEnum->Reset();
  905. while (spEnum->Next(1, &spNode, NULL) == hrOK)
  906. {
  907. pData = GET_INTERFACENODEDATA(spNode);
  908. Assert(pData);
  909. // default status/connection states
  910. dwConnState = ROUTER_IF_STATE_UNREACHABLE;
  911. dwUnReachabilityReason = MPR_INTERFACE_NOT_LOADED;
  912. pData->dwLastError = 0;
  913. // Match the status we find to the actual status
  914. for (i=0; i<(int) if0Count; i++)
  915. {
  916. // There could be a client interface with the same name
  917. // as a router interface, so filter the client interfaces
  918. if ((if0Table[i].dwIfType != ROUTER_IF_TYPE_CLIENT) &&
  919. !StriCmpW(pData->spIf->GetId(), if0Table[i].wszInterfaceName))
  920. {
  921. break;
  922. }
  923. }
  924. // If we found an entry in the table, pull the data out
  925. if (i < (int) if0Count)
  926. {
  927. dwConnState = if0Table[i].dwConnectionState;
  928. dwUnReachabilityReason = if0Table[i].fUnReachabilityReasons;
  929. if (dwUnReachabilityReason & MPR_INTERFACE_CONNECTION_FAILURE)
  930. pData->dwLastError = if0Table[i].dwLastError;
  931. }
  932. dwStatus = pData->spIf->IsInterfaceEnabled();
  933. // Place the data into the per-node data area
  934. pData->m_rgData[IFADMIN_SUBITEM_TITLE].m_stData = pData->spIf->GetTitle();
  935. pData->m_rgData[IFADMIN_SUBITEM_DEVICE_NAME].m_stData =
  936. pData->spIf->GetDeviceName();
  937. pData->m_rgData[IFADMIN_SUBITEM_TYPE].m_stData =
  938. InterfaceTypeToCString(pData->spIf->GetInterfaceType());
  939. pData->m_rgData[IFADMIN_SUBITEM_STATUS].m_stData = StatusToCString(dwStatus);
  940. pData->m_rgData[IFADMIN_SUBITEM_CONNECTION_STATE].m_stData =
  941. ConnectionStateToCString(dwConnState);
  942. pData->dwUnReachabilityReason = dwUnReachabilityReason;
  943. pData->dwConnectionState = dwConnState;
  944. pData->fIsRunning = ::MprAdminIsServiceRunning((LPWSTR) pData->spIf->GetMachineName());
  945. // Force MMC to redraw the nodes
  946. spNode->ChangeNode(RESULT_PANE_CHANGE_ITEM_DATA);
  947. // Cleanup
  948. spNode.Release();
  949. }
  950. return hr;
  951. }
  952. /*!--------------------------------------------------------------------------
  953. IfAdminNodeHandler::EnableAddInterface
  954. -
  955. Author: KennT
  956. ---------------------------------------------------------------------------*/
  957. BOOL IfAdminNodeHandler::EnableAddInterface()
  958. {
  959. return m_hInstRasDlg != 0;
  960. }
  961. /*!--------------------------------------------------------------------------
  962. IfAdminNodeHandler::GetPhoneBookPath
  963. -
  964. Author: KennT
  965. ---------------------------------------------------------------------------*/
  966. HRESULT IfAdminNodeHandler::GetPhoneBookPath(LPCTSTR pszMachine, CString *pstPath)
  967. {
  968. CString str = _T(""), stPath;
  969. CString stRouter = pszMachine;
  970. if (pszMachine && StrLen(pszMachine))
  971. {
  972. // add on the two slashes to the beginning of the machine name
  973. if (stRouter.Left(2) != _T("\\\\"))
  974. {
  975. stRouter = _T("\\\\");
  976. stRouter += pszMachine;
  977. }
  978. // If this is not the local machine, use this string
  979. if (stRouter.GetLength() &&
  980. StriCmp(stRouter, CString(_T("\\\\")) + GetLocalMachineName()))
  981. str = stRouter;
  982. }
  983. Verify( FHrSucceeded(::GetRouterPhonebookPath(str, &stPath)) );
  984. *pstPath = stPath;
  985. return hrOK;
  986. }
  987. ImplementEmbeddedUnknown(IfAdminNodeHandler, IRtrAdviseSink)
  988. STDMETHODIMP IfAdminNodeHandler::EIRtrAdviseSink::OnChange(LONG_PTR ulConn,
  989. DWORD dwChangeType, DWORD dwObjectType, LPARAM lUserParam, LPARAM lParam)
  990. {
  991. InitPThis(IfAdminNodeHandler, IRtrAdviseSink);
  992. SPIEnumInterfaceInfo spEnumIf;
  993. SPIInterfaceInfo spIf;
  994. SPITFSNode spThisNode;
  995. SPITFSNode spNode;
  996. SPITFSNodeEnum spEnumNode;
  997. InterfaceNodeData * pNodeData;
  998. BOOL fFound, fAdded;
  999. HRESULT hr = hrOK;
  1000. pThis->m_spNodeMgr->FindNode(pThis->m_cookie, &spThisNode);
  1001. if (dwObjectType == ROUTER_OBJ_If)
  1002. {
  1003. // Force a data refresh of the current result pane
  1004. if (dwChangeType == ROUTER_CHILD_DELETE)
  1005. {
  1006. // Go through the list of nodes, if we cannot find this
  1007. // node in the list of interfaces, delete the node
  1008. spThisNode->GetEnum(&spEnumNode);
  1009. spEnumNode->Reset();
  1010. while (spEnumNode->Next(1, &spNode, NULL) == hrOK)
  1011. {
  1012. // Get the node data, look for the interface
  1013. pNodeData = GET_INTERFACENODEDATA(spNode);
  1014. pThis->m_spRouterInfo->FindInterface(pNodeData->spIf->GetId(),
  1015. &spIf);
  1016. if (spIf == NULL)
  1017. {
  1018. // cannot find the interface, release this node!
  1019. spThisNode->RemoveChild(spNode);
  1020. spNode->Destroy();
  1021. }
  1022. spNode.Release();
  1023. spIf.Release();
  1024. }
  1025. }
  1026. else if (dwChangeType == ROUTER_CHILD_ADD)
  1027. {
  1028. // Enumerate through the list of interfaces
  1029. // if we cannot find this interface in our current
  1030. // set of nodes, then add it.
  1031. spThisNode->GetEnum(&spEnumNode);
  1032. CORg( pThis->m_spRouterInfo->EnumInterface(&spEnumIf) );
  1033. fAdded = FALSE;
  1034. spEnumIf->Reset();
  1035. while (spEnumIf->Next(1, &spIf, NULL) == hrOK)
  1036. {
  1037. // Look for this interface in our list of nodes
  1038. fFound = FALSE;
  1039. spEnumNode->Reset();
  1040. while (spEnumNode->Next(1, &spNode, NULL) == hrOK)
  1041. {
  1042. pNodeData = GET_INTERFACENODEDATA(spNode);
  1043. Assert(pNodeData);
  1044. if (StriCmpW(pNodeData->spIf->GetId(),spIf->GetId()) == 0)
  1045. {
  1046. fFound = TRUE;
  1047. break;
  1048. }
  1049. spNode.Release();
  1050. }
  1051. //
  1052. // If the interface was not found in the list of nodes,
  1053. // then we should add the interface to the UI.
  1054. //
  1055. if (!fFound)
  1056. {
  1057. pThis->AddInterfaceNode(spThisNode, spIf);
  1058. fAdded = TRUE;
  1059. }
  1060. spNode.Release();
  1061. spIf.Release();
  1062. }
  1063. // Now that we have all of the nodes, update the data for
  1064. // all of the nodes
  1065. if (fAdded)
  1066. pThis->SynchronizeNodeData(spThisNode);
  1067. // Windows NT Bug : 288247
  1068. // Set this here, so that we can avoid the nodes being
  1069. // added in the OnExpand().
  1070. pThis->m_bExpanded = TRUE;
  1071. }
  1072. // Determine what nodes were deleted, changed, or added
  1073. // and do the appropriate action
  1074. }
  1075. else if (dwChangeType == ROUTER_REFRESH)
  1076. {
  1077. // Ok, just call the synchronize on this node
  1078. pThis->SynchronizeNodeData(spThisNode);
  1079. }
  1080. Error:
  1081. return hr;
  1082. }
  1083. /*!--------------------------------------------------------------------------
  1084. IfAdminNodeHandler::CompareItems
  1085. Implementation of ITFSResultHandler::CompareItems
  1086. Author: KennT
  1087. ---------------------------------------------------------------------------*/
  1088. STDMETHODIMP_(int) IfAdminNodeHandler::CompareItems(
  1089. ITFSComponent * pComponent,
  1090. MMC_COOKIE cookieA,
  1091. MMC_COOKIE cookieB,
  1092. int nCol)
  1093. {
  1094. // Get the strings from the nodes and use that as a basis for
  1095. // comparison.
  1096. SPITFSNode spNode;
  1097. SPITFSResultHandler spResult;
  1098. m_spNodeMgr->FindNode(cookieA, &spNode);
  1099. spNode->GetResultHandler(&spResult);
  1100. return spResult->CompareItems(pComponent, cookieA, cookieB, nCol);
  1101. }
  1102. /*!--------------------------------------------------------------------------
  1103. IfAdminNodeHandler::AddMenuItems
  1104. Implementation of ITFSResultHandler::AddMenuItems
  1105. Use this to add commands to the context menu of the blank areas
  1106. of the result pane.
  1107. Author: KennT
  1108. ---------------------------------------------------------------------------*/
  1109. STDMETHODIMP IfAdminNodeHandler::AddMenuItems(ITFSComponent *pComponent,
  1110. MMC_COOKIE cookie,
  1111. LPDATAOBJECT pDataObject,
  1112. LPCONTEXTMENUCALLBACK pCallback,
  1113. long *pInsertionAllowed)
  1114. {
  1115. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1116. SPITFSNode spNode;
  1117. CString stMenu;
  1118. LONG lMenuText;
  1119. HRESULT hr = hrOK;
  1120. m_spNodeMgr->FindNode(cookie, &spNode);
  1121. hr = OnAddMenuItems(spNode,
  1122. pCallback,
  1123. pDataObject,
  1124. CCT_RESULT,
  1125. TFS_COMPDATA_CHILD_CONTEXTMENU,
  1126. pInsertionAllowed);
  1127. CORg( hr );
  1128. Error:
  1129. return hr;
  1130. }
  1131. /*!--------------------------------------------------------------------------
  1132. IfAdminNodeHandler::Command
  1133. -
  1134. Author: KennT
  1135. ---------------------------------------------------------------------------*/
  1136. STDMETHODIMP IfAdminNodeHandler::Command(ITFSComponent *pComponent,
  1137. MMC_COOKIE cookie,
  1138. int nCommandID,
  1139. LPDATAOBJECT pDataObject)
  1140. {
  1141. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1142. SPITFSNode spNode;
  1143. HRESULT hr = hrOK;
  1144. m_spNodeMgr->FindNode(cookie, &spNode);
  1145. hr = OnCommand(spNode,
  1146. nCommandID,
  1147. CCT_RESULT,
  1148. pDataObject,
  1149. TFS_COMPDATA_CHILD_CONTEXTMENU);
  1150. return hr;
  1151. }
  1152. typedef DWORD (APIENTRY* PRASRPCCONNECTSERVER)(LPTSTR, HANDLE *);
  1153. typedef DWORD (APIENTRY* PRASRPCDISCONNECTSERVER)(HANDLE);
  1154. typedef DWORD (APIENTRY* PRASRPCREMOTEGETUSERPREFERENCES)(HANDLE, PBUSER *, DWORD);
  1155. typedef DWORD (APIENTRY* PRASRPCREMOTESETUSERPREFERENCES)(HANDLE, PBUSER *, DWORD);
  1156. /*!--------------------------------------------------------------------------
  1157. GetDemandDialWizardRegKey
  1158. -
  1159. Author: KennT
  1160. ---------------------------------------------------------------------------*/
  1161. HRESULT GetDemandDialWizardRegKey(LPCTSTR szMachine, DWORD *pfWizard)
  1162. {
  1163. ASSERT(pfWizard);
  1164. BOOL fUnload = FALSE;
  1165. DWORD dwErr;
  1166. PBUSER pbUser;
  1167. PRASRPCCONNECTSERVER pRasRpcConnectServer;
  1168. PRASRPCDISCONNECTSERVER pRasRpcDisconnectServer;
  1169. PRASRPCREMOTEGETUSERPREFERENCES pRasRpcRemoteGetUserPreferences;
  1170. PRASRPCREMOTESETUSERPREFERENCES pRasRpcRemoteSetUserPreferences;
  1171. HINSTANCE hrpcdll = NULL;
  1172. HANDLE hConnection = NULL;
  1173. if (!(hrpcdll = LoadLibrary(TEXT("rasman.dll"))) ||
  1174. !(pRasRpcConnectServer =
  1175. (PRASRPCCONNECTSERVER)GetProcAddress(
  1176. hrpcdll, "RasRpcConnectServer"
  1177. )) ||
  1178. !(pRasRpcDisconnectServer =
  1179. (PRASRPCDISCONNECTSERVER)GetProcAddress(
  1180. hrpcdll, "RasRpcDisconnectServer"
  1181. )) ||
  1182. !(pRasRpcRemoteGetUserPreferences =
  1183. (PRASRPCREMOTEGETUSERPREFERENCES)GetProcAddress(
  1184. hrpcdll, "RasRpcRemoteGetUserPreferences"
  1185. )) ||
  1186. !(pRasRpcRemoteSetUserPreferences =
  1187. (PRASRPCREMOTESETUSERPREFERENCES)GetProcAddress(
  1188. hrpcdll, "RasRpcRemoteSetUserPreferences"
  1189. )))
  1190. {
  1191. if (hrpcdll) { FreeLibrary(hrpcdll); }
  1192. return HRESULT_FROM_WIN32(GetLastError());
  1193. }
  1194. dwErr = pRasRpcConnectServer((LPTSTR) szMachine, &hConnection);
  1195. if (dwErr)
  1196. goto Error;
  1197. fUnload = TRUE;
  1198. dwErr = pRasRpcRemoteGetUserPreferences(hConnection, &pbUser, UPM_Router);
  1199. if (dwErr)
  1200. goto Error;
  1201. *pfWizard = pbUser.fNewEntryWizard;
  1202. // Ignore error codes for these calls, we can't do
  1203. // anything about them if they fail.
  1204. pRasRpcRemoteSetUserPreferences(hConnection, &pbUser, UPM_Router);
  1205. DestroyUserPreferences((PBUSER *) &pbUser);
  1206. Error:
  1207. if (fUnload)
  1208. pRasRpcDisconnectServer(hConnection);
  1209. if (hrpcdll)
  1210. FreeLibrary(hrpcdll);
  1211. return HRESULT_FROM_WIN32(dwErr);
  1212. }
  1213. /*!--------------------------------------------------------------------------
  1214. SetDemandDialWizardRegistyKey
  1215. This is a function that was added for Beta1 of Steelhead. We want
  1216. to allow the user to use the wizard even though it was turned off.
  1217. So we have added this hack for the beta where we set the registry
  1218. key for the user/
  1219. Author: KennT
  1220. ---------------------------------------------------------------------------*/
  1221. HRESULT SetDemandDialWizardRegKey(LPCTSTR szMachine, DWORD fEnableWizard)
  1222. {
  1223. DWORD dwErr;
  1224. PBUSER pbUser;
  1225. BOOL fUnload = FALSE;
  1226. PRASRPCCONNECTSERVER pRasRpcConnectServer;
  1227. PRASRPCDISCONNECTSERVER pRasRpcDisconnectServer;
  1228. PRASRPCREMOTEGETUSERPREFERENCES pRasRpcRemoteGetUserPreferences;
  1229. PRASRPCREMOTESETUSERPREFERENCES pRasRpcRemoteSetUserPreferences;
  1230. HINSTANCE hrpcdll = NULL;
  1231. HANDLE hConnection = NULL;
  1232. if (!(hrpcdll = LoadLibrary(TEXT("rasman.dll"))) ||
  1233. !(pRasRpcConnectServer =
  1234. (PRASRPCCONNECTSERVER)GetProcAddress(
  1235. hrpcdll, "RasRpcConnectServer"
  1236. )) ||
  1237. !(pRasRpcDisconnectServer =
  1238. (PRASRPCDISCONNECTSERVER)GetProcAddress(
  1239. hrpcdll, "RasRpcDisconnectServer"
  1240. )) ||
  1241. !(pRasRpcRemoteGetUserPreferences =
  1242. (PRASRPCREMOTEGETUSERPREFERENCES)GetProcAddress(
  1243. hrpcdll, "RasRpcRemoteGetUserPreferences"
  1244. )) ||
  1245. !(pRasRpcRemoteSetUserPreferences =
  1246. (PRASRPCREMOTESETUSERPREFERENCES)GetProcAddress(
  1247. hrpcdll, "RasRpcRemoteSetUserPreferences"
  1248. )))
  1249. {
  1250. if (hrpcdll) { FreeLibrary(hrpcdll); }
  1251. return HRESULT_FROM_WIN32(GetLastError());
  1252. }
  1253. dwErr = pRasRpcConnectServer((LPTSTR) szMachine, &hConnection);
  1254. if (dwErr)
  1255. goto Error;
  1256. fUnload = TRUE;
  1257. dwErr = pRasRpcRemoteGetUserPreferences(hConnection, &pbUser, UPM_Router);
  1258. if (dwErr)
  1259. goto Error;
  1260. pbUser.fNewEntryWizard = fEnableWizard;
  1261. pbUser.fDirty = TRUE;
  1262. // Ignore error codes for these calls, we can't do
  1263. // anything about them if they fail.
  1264. pRasRpcRemoteSetUserPreferences(hConnection, &pbUser, UPM_Router);
  1265. DestroyUserPreferences((PBUSER *) &pbUser);
  1266. Error:
  1267. if (fUnload)
  1268. pRasRpcDisconnectServer(hConnection);
  1269. if (hrpcdll)
  1270. FreeLibrary(hrpcdll);
  1271. return HRESULT_FROM_WIN32(dwErr);
  1272. }
  1273. /*!--------------------------------------------------------------------------
  1274. IfAdminNodeHandler::AddInterfaceNode
  1275. Adds an interface to the UI. This will create a new result item
  1276. node for each interface.
  1277. Author: KennT
  1278. ---------------------------------------------------------------------------*/
  1279. HRESULT IfAdminNodeHandler::AddInterfaceNode(ITFSNode *pParent, IInterfaceInfo *pIf)
  1280. {
  1281. InterfaceNodeHandler * pHandler;
  1282. SPITFSResultHandler spHandler;
  1283. SPITFSNode spNode;
  1284. HRESULT hr = hrOK;
  1285. pHandler = new InterfaceNodeHandler(m_spTFSCompData);
  1286. spHandler = pHandler;
  1287. CORg( pHandler->Init(pIf, pParent) );
  1288. CORg( CreateLeafTFSNode(&spNode,
  1289. NULL,
  1290. static_cast<ITFSNodeHandler *>(pHandler),
  1291. static_cast<ITFSResultHandler *>(pHandler),
  1292. m_spNodeMgr) );
  1293. CORg( pHandler->ConstructNode(spNode, pIf) );
  1294. // Make the node immediately visible
  1295. CORg( spNode->SetVisibilityState(TFS_VIS_SHOW) );
  1296. CORg( pParent->AddChild(spNode) );
  1297. Error:
  1298. return hr;
  1299. }
  1300. /*!--------------------------------------------------------------------------
  1301. IfAdminNodeHandler::FLookForRoutingEnabledPorts
  1302. Returns TRUE if we find at least on routing-enabled port.
  1303. Author: KennT
  1304. ---------------------------------------------------------------------------*/
  1305. BOOL IfAdminNodeHandler::FLookForRoutingEnabledPorts(LPCTSTR pszMachineName)
  1306. {
  1307. PortsDataEntry portsData;
  1308. PortsDeviceList portsList;
  1309. PortsDeviceEntry * pPorts = NULL;
  1310. BOOL fReturn = FALSE;
  1311. HRESULT hr = hrOK;
  1312. POSITION pos;
  1313. COM_PROTECT_TRY
  1314. {
  1315. CORg( portsData.Initialize(pszMachineName) );
  1316. CORg( portsData.LoadDevices(&portsList) );
  1317. // Now go through the list, looking for a routing-enabled port
  1318. pos = portsList.GetHeadPosition();
  1319. while (pos)
  1320. {
  1321. pPorts = portsList.GetNext(pos);
  1322. if ((pPorts->m_dwEnableRouting) ||
  1323. (pPorts->m_dwEnableOutboundRouting))
  1324. {
  1325. fReturn = TRUE;
  1326. break;
  1327. }
  1328. }
  1329. COM_PROTECT_ERROR_LABEL;
  1330. }
  1331. COM_PROTECT_CATCH;
  1332. while (!portsList.IsEmpty())
  1333. delete portsList.RemoveHead();
  1334. return fReturn;
  1335. }
  1336. #ifdef KSL_IPINIP
  1337. /*---------------------------------------------------------------------------
  1338. TunnelDialog implementation
  1339. ---------------------------------------------------------------------------*/
  1340. /*!--------------------------------------------------------------------------
  1341. TunnelDialog::TunnelDialog
  1342. -
  1343. Author: KennT
  1344. ---------------------------------------------------------------------------*/
  1345. TunnelDialog::TunnelDialog()
  1346. : CBaseDialog(TunnelDialog::IDD)
  1347. {
  1348. }
  1349. /*!--------------------------------------------------------------------------
  1350. TunnelDialog::~TunnelDialog
  1351. -
  1352. Author: KennT
  1353. ---------------------------------------------------------------------------*/
  1354. TunnelDialog::~TunnelDialog()
  1355. {
  1356. }
  1357. BEGIN_MESSAGE_MAP(TunnelDialog, CBaseDialog)
  1358. //{{AFX_MSG_MAP(TunnelDialog)
  1359. //}}AFX_MSG_MAP
  1360. END_MESSAGE_MAP()
  1361. /*!--------------------------------------------------------------------------
  1362. RadiusServerDialog::DoDataExchange
  1363. -
  1364. Author: KennT
  1365. ---------------------------------------------------------------------------*/
  1366. void TunnelDialog::DoDataExchange(CDataExchange* pDX)
  1367. {
  1368. CBaseDialog::DoDataExchange(pDX);
  1369. //{{AFX_DATA_MAP(TunnelDialog)
  1370. //}}AFX_DATA_MAP
  1371. }
  1372. /*!--------------------------------------------------------------------------
  1373. TunnelDialog::OnInitDialog
  1374. -
  1375. Author: KennT
  1376. ---------------------------------------------------------------------------*/
  1377. BOOL TunnelDialog::OnInitDialog()
  1378. {
  1379. CBaseDialog::OnInitDialog();
  1380. return TRUE;
  1381. }
  1382. /*!--------------------------------------------------------------------------
  1383. TunnelDialog::OnOK
  1384. -
  1385. Author: KennT
  1386. ---------------------------------------------------------------------------*/
  1387. void TunnelDialog::OnOK()
  1388. {
  1389. CString stLocal, stRemote;
  1390. GetDlgItemText(IDC_TUNNEL_EDIT_NAME, m_stName);
  1391. m_stName.TrimLeft();
  1392. m_stName.TrimRight();
  1393. if (m_stName.IsEmpty())
  1394. {
  1395. AfxMessageBox(IDS_ERR_TUNNEL_NEEDS_A_NAME);
  1396. GetDlgItem(IDC_TUNNEL_EDIT_NAME)->SetFocus();
  1397. goto Error;
  1398. }
  1399. // Truncate the interface ID to MAX_INTERFACE_NAME_LEN characters
  1400. if (m_stName.GetLength() > MAX_INTERFACE_NAME_LEN)
  1401. {
  1402. m_stName.GetBufferSetLength(MAX_INTERFACE_NAME_LEN+1);
  1403. m_stName.ReleaseBuffer(MAX_INTERFACE_NAME_LEN);
  1404. }
  1405. CBaseDialog::OnOK();
  1406. Error:
  1407. return;
  1408. }
  1409. #endif //KSL_IPINIP