Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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