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.

1629 lines
43 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" // need to use node data
  12. #include "iface.h"
  13. #include "raserror.h"
  14. #include "rtrres.h" // common router resources
  15. #include "column.h" // ComponentConfigStream
  16. #include "mprfltr.h"
  17. #include "rtrutilp.h"
  18. #include "rtrui.h" // for IsWanInterface
  19. #include "dmvcomp.h"
  20. #include "timeofday.h" // for timeofday dialog
  21. #include "dumbprop.h" // dummy property page
  22. InterfaceNodeData::InterfaceNodeData()
  23. : lParamPrivate(0)
  24. {
  25. #ifdef DEBUG
  26. StrCpyA(m_szDebug, "InterfaceNodeData");
  27. #endif
  28. }
  29. InterfaceNodeData::~InterfaceNodeData()
  30. {
  31. }
  32. HRESULT InterfaceNodeData::Init(ITFSNode *pNode, IInterfaceInfo *pIf)
  33. {
  34. HRESULT hr = hrOK;
  35. InterfaceNodeData * pData = NULL;
  36. pData = new InterfaceNodeData;
  37. pData->spIf.Set(pIf);
  38. SET_INTERFACENODEDATA(pNode, pData);
  39. return hr;
  40. }
  41. HRESULT InterfaceNodeData::Free(ITFSNode *pNode)
  42. {
  43. InterfaceNodeData * pData = GET_INTERFACENODEDATA(pNode);
  44. pData->spIf.Release();
  45. delete pData;
  46. SET_INTERFACENODEDATA(pNode, NULL);
  47. return hrOK;
  48. }
  49. /*---------------------------------------------------------------------------
  50. InterfaceNodeHandler implementation
  51. ---------------------------------------------------------------------------*/
  52. DEBUG_DECLARE_INSTANCE_COUNTER(InterfaceNodeHandler)
  53. IMPLEMENT_ADDREF_RELEASE(InterfaceNodeHandler)
  54. STDMETHODIMP InterfaceNodeHandler::QueryInterface(REFIID riid, LPVOID *ppv)
  55. {
  56. // Is the pointer bad?
  57. if (ppv == NULL)
  58. return E_INVALIDARG;
  59. // Place NULL in *ppv in case of failure
  60. *ppv = NULL;
  61. // This is the non-delegating IUnknown implementation
  62. if (riid == IID_IUnknown)
  63. *ppv = (LPVOID) this;
  64. else if (riid == IID_IRtrAdviseSink)
  65. *ppv = &m_IRtrAdviseSink;
  66. else
  67. return CBaseResultHandler::QueryInterface(riid, ppv);
  68. // If we're going to return an interface, AddRef it first
  69. if (*ppv)
  70. {
  71. ((LPUNKNOWN) *ppv)->AddRef();
  72. return hrOK;
  73. }
  74. else
  75. return E_NOINTERFACE;
  76. }
  77. /*---------------------------------------------------------------------------
  78. NodeHandler implementation
  79. ---------------------------------------------------------------------------*/
  80. InterfaceNodeHandler::InterfaceNodeHandler(ITFSComponentData *pCompData)
  81. : BaseRouterHandler(pCompData),
  82. m_ulConnId(0)
  83. {
  84. DEBUG_INCREMENT_INSTANCE_COUNTER(InterfaceNodeHandler);
  85. }
  86. /*!--------------------------------------------------------------------------
  87. InterfaceNodeHandler::Init
  88. -
  89. Author: KennT
  90. ---------------------------------------------------------------------------*/
  91. HRESULT InterfaceNodeHandler::Init(IInterfaceInfo *pIfInfo, ITFSNode *pParent)
  92. {
  93. SPIRouterInfo spRouter;
  94. SRouterNodeMenu menuData;
  95. Assert(pIfInfo);
  96. m_spInterfaceInfo.Set(pIfInfo);
  97. pIfInfo->GetParentRouterInfo(&spRouter);
  98. m_spRouterInfo.Set(spRouter);
  99. // Also need to register for change notifications
  100. // ----------------------------------------------------------------
  101. m_spInterfaceInfo->RtrAdvise(&m_IRtrAdviseSink, &m_ulConnId, 0);
  102. m_pIfAdminData = GET_IFADMINNODEDATA(pParent);
  103. // Setup the verb states
  104. // ----------------------------------------------------------------
  105. // Always enable refresh
  106. // ----------------------------------------------------------------
  107. m_rgButtonState[MMC_VERB_REFRESH_INDEX] = ENABLED;
  108. m_bState[MMC_VERB_REFRESH_INDEX] = TRUE;
  109. // Need to enable properties only for certain cases
  110. // ----------------------------------------------------------------
  111. if (IsWanInterface(m_spInterfaceInfo->GetInterfaceType()))
  112. {
  113. m_rgButtonState[MMC_VERB_DELETE_INDEX] = ENABLED;
  114. m_bState[MMC_VERB_DELETE_INDEX] = TRUE;
  115. m_rgButtonState[MMC_VERB_PROPERTIES_INDEX] = ENABLED;
  116. m_bState[MMC_VERB_PROPERTIES_INDEX] = TRUE;
  117. m_verbDefault = MMC_VERB_PROPERTIES;
  118. }
  119. else
  120. {
  121. // Windows NT Bugs : 206524
  122. // Need to add a special case for IP-in-IP tunnel
  123. // Enable DELETE for the tunnel
  124. if (m_spInterfaceInfo->GetInterfaceType() == ROUTER_IF_TYPE_TUNNEL1)
  125. {
  126. m_rgButtonState[MMC_VERB_DELETE_INDEX] = ENABLED;
  127. m_bState[MMC_VERB_DELETE_INDEX] = TRUE;
  128. }
  129. m_rgButtonState[MMC_VERB_PROPERTIES_INDEX] = ENABLED;
  130. m_bState[MMC_VERB_PROPERTIES_INDEX] = FALSE;
  131. }
  132. return hrOK;
  133. }
  134. /*!--------------------------------------------------------------------------
  135. InterfaceNodeHandler::DestroyResultHandler
  136. -
  137. Author: KennT
  138. ---------------------------------------------------------------------------*/
  139. STDMETHODIMP InterfaceNodeHandler::DestroyResultHandler(MMC_COOKIE cookie)
  140. {
  141. SPITFSNode spNode;
  142. m_spNodeMgr->FindNode(cookie, &spNode);
  143. InterfaceNodeData::Free(spNode);
  144. m_pIfAdminData = NULL;
  145. m_spInterfaceInfo->RtrUnadvise(m_ulConnId);
  146. m_spInterfaceInfo.Release();
  147. CHandler::DestroyResultHandler(cookie);
  148. return hrOK;
  149. }
  150. static DWORD s_rgInterfaceImageMap[] =
  151. {
  152. ROUTER_IF_TYPE_HOME_ROUTER, IMAGE_IDX_WAN_CARD,
  153. ROUTER_IF_TYPE_FULL_ROUTER, IMAGE_IDX_WAN_CARD,
  154. ROUTER_IF_TYPE_CLIENT, IMAGE_IDX_WAN_CARD,
  155. ROUTER_IF_TYPE_DEDICATED, IMAGE_IDX_LAN_CARD,
  156. ROUTER_IF_TYPE_INTERNAL, IMAGE_IDX_LAN_CARD,
  157. ROUTER_IF_TYPE_LOOPBACK, IMAGE_IDX_LAN_CARD,
  158. -1, IMAGE_IDX_WAN_CARD, // sentinel value
  159. };
  160. /*!--------------------------------------------------------------------------
  161. InterfaceNodeHandler::ConstructNode
  162. Initializes the Domain node (sets it up).
  163. Author: KennT
  164. ---------------------------------------------------------------------------*/
  165. HRESULT InterfaceNodeHandler::ConstructNode(ITFSNode *pNode, IInterfaceInfo *pIfInfo)
  166. {
  167. HRESULT hr = hrOK;
  168. int i;
  169. if (pNode == NULL)
  170. return hrOK;
  171. COM_PROTECT_TRY
  172. {
  173. // Need to initialize the data for the Domain node
  174. // Find the right image index for this type of node
  175. for (i=0; i<DimensionOf(s_rgInterfaceImageMap); i+=2)
  176. {
  177. if ((pIfInfo->GetInterfaceType() == s_rgInterfaceImageMap[i]) ||
  178. (-1 == s_rgInterfaceImageMap[i]))
  179. break;
  180. }
  181. pNode->SetData(TFS_DATA_IMAGEINDEX, s_rgInterfaceImageMap[i+1]);
  182. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, s_rgInterfaceImageMap[i+1]);
  183. pNode->SetData(TFS_DATA_SCOPEID, 0);
  184. pNode->SetData(TFS_DATA_COOKIE, reinterpret_cast<LONG_PTR>(pNode));
  185. //$ Review: kennt, what are the different type of interfaces
  186. // do we distinguish based on the same list as above? (i.e. the
  187. // one for image indexes).
  188. pNode->SetNodeType(&GUID_RouterLanInterfaceNodeType);
  189. InterfaceNodeData::Init(pNode, pIfInfo);
  190. }
  191. COM_PROTECT_CATCH
  192. return hr;
  193. }
  194. /*!--------------------------------------------------------------------------
  195. InterfaceNodeHandler::GetString
  196. -
  197. Author: KennT
  198. ---------------------------------------------------------------------------*/
  199. STDMETHODIMP_(LPCTSTR) InterfaceNodeHandler::GetString(ITFSComponent * pComponent,
  200. MMC_COOKIE cookie,
  201. int nCol)
  202. {
  203. Assert(m_spNodeMgr);
  204. Assert(m_pIfAdminData);
  205. SPITFSNode spNode;
  206. InterfaceNodeData * pData;
  207. ConfigStream * pConfig;
  208. m_spNodeMgr->FindNode(cookie, &spNode);
  209. Assert(spNode);
  210. pData = GET_INTERFACENODEDATA(spNode);
  211. Assert(pData);
  212. pComponent->GetUserData((LONG_PTR *) &pConfig);
  213. Assert(pConfig);
  214. return pData->m_rgData[pConfig->MapColumnToSubitem(DM_COLUMNS_IFADMIN, nCol)].m_stData;
  215. }
  216. /*!--------------------------------------------------------------------------
  217. InterfaceNodeHandler::CompareItems
  218. -
  219. Author: KennT
  220. ---------------------------------------------------------------------------*/
  221. STDMETHODIMP_(int) InterfaceNodeHandler::CompareItems(ITFSComponent * pComponent,
  222. MMC_COOKIE cookieA,
  223. MMC_COOKIE cookieB,
  224. int nCol)
  225. {
  226. return StriCmpW(GetString(pComponent, cookieA, nCol),
  227. GetString(pComponent, cookieB, nCol));
  228. }
  229. static const SRouterNodeMenu s_rgIfNodeMenu[] =
  230. {
  231. { IDS_MENU_SET_CREDENTIALS, InterfaceNodeHandler::GetRemoveIfMenuFlags,
  232. CCM_INSERTIONPOINTID_PRIMARY_TOP},
  233. { IDS_MENU_SEPARATOR, 0,
  234. CCM_INSERTIONPOINTID_PRIMARY_TOP},
  235. { IDS_MENU_CONNECT, InterfaceNodeHandler::GetConnectMenuFlags,
  236. CCM_INSERTIONPOINTID_PRIMARY_TOP},
  237. { IDS_MENU_DISCONNECT, InterfaceNodeHandler::GetConnectMenuFlags,
  238. CCM_INSERTIONPOINTID_PRIMARY_TOP},
  239. { IDS_MENU_SEPARATOR, 0,
  240. CCM_INSERTIONPOINTID_PRIMARY_TOP},
  241. { IDS_MENU_ENABLE, InterfaceNodeHandler::GetEnableMenuFlags,
  242. CCM_INSERTIONPOINTID_PRIMARY_TOP},
  243. { IDS_MENU_DISABLE, InterfaceNodeHandler::GetEnableMenuFlags,
  244. CCM_INSERTIONPOINTID_PRIMARY_TOP},
  245. { IDS_MENU_SEPARATOR, 0,
  246. CCM_INSERTIONPOINTID_PRIMARY_TOP},
  247. { IDS_MENU_UNREACHABILITY_REASON, InterfaceNodeHandler::GetUnreachMenuFlags,
  248. CCM_INSERTIONPOINTID_PRIMARY_TOP},
  249. { IDS_MENU_SEPARATOR, 0,
  250. CCM_INSERTIONPOINTID_PRIMARY_TOP},
  251. { IDS_MENU_DEMAND_DIAL_FILTERS, InterfaceNodeHandler::GetDDFiltersFlag,
  252. CCM_INSERTIONPOINTID_PRIMARY_TOP},
  253. { IDS_MENU_DIALIN_HOURS, InterfaceNodeHandler::GetDDFiltersFlag,
  254. CCM_INSERTIONPOINTID_PRIMARY_TOP},
  255. };
  256. /*!--------------------------------------------------------------------------
  257. InterfaceNodeHandler::AddMenuItems
  258. Implementation of ITFSNodeHandler::OnAddMenuItems
  259. Author: KennT
  260. ---------------------------------------------------------------------------*/
  261. STDMETHODIMP InterfaceNodeHandler::AddMenuItems(ITFSComponent *pComponent,
  262. MMC_COOKIE cookie,
  263. LPDATAOBJECT lpDataObject,
  264. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  265. long *pInsertionAllowed)
  266. {
  267. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  268. HRESULT hr = S_OK;
  269. SPITFSNode spNode;
  270. InterfaceNodeHandler::SMenuData menuData;
  271. COM_PROTECT_TRY
  272. {
  273. m_spNodeMgr->FindNode(cookie, &spNode);
  274. // Now go through and add our menu items
  275. menuData.m_spNode.Set(spNode);
  276. menuData.m_fRouterIsRunning = (IsRouterServiceRunning(
  277. m_spInterfaceInfo->GetMachineName(),
  278. NULL) == hrOK);
  279. hr = AddArrayOfMenuItems(spNode, s_rgIfNodeMenu,
  280. DimensionOf(s_rgIfNodeMenu),
  281. pContextMenuCallback,
  282. *pInsertionAllowed,
  283. reinterpret_cast<INT_PTR>(&menuData));
  284. }
  285. COM_PROTECT_CATCH;
  286. return hr;
  287. }
  288. /*!--------------------------------------------------------------------------
  289. InterfaceNodeHandler::Command
  290. -
  291. Author: KennT
  292. ---------------------------------------------------------------------------*/
  293. STDMETHODIMP InterfaceNodeHandler::Command(ITFSComponent *pComponent,
  294. MMC_COOKIE cookie,
  295. int nCommandId,
  296. LPDATAOBJECT pDataObject)
  297. {
  298. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  299. HRESULT hr = S_OK;
  300. SPITFSNode spNode;
  301. SPITFSNode spNodeParent;
  302. SPITFSNodeHandler spParentHandler;
  303. COM_PROTECT_TRY
  304. {
  305. switch (nCommandId)
  306. {
  307. case IDS_MENU_SET_CREDENTIALS:
  308. hr = OnSetCredentials();
  309. break;
  310. case IDS_MENU_CONNECT:
  311. case IDS_MENU_DISCONNECT:
  312. hr = OnConnectDisconnect(cookie,nCommandId);
  313. break;
  314. case IDS_MENU_ENABLE:
  315. case IDS_MENU_DISABLE:
  316. hr = OnEnableDisable(cookie, nCommandId);
  317. break;
  318. case IDS_MENU_UNREACHABILITY_REASON:
  319. hr = OnUnreachabilityReason(cookie);
  320. break;
  321. case IDS_MENU_DEMAND_DIAL_FILTERS:
  322. hr = OnDemandDialFilters(cookie);
  323. break;
  324. case IDS_MENU_DIALIN_HOURS:
  325. hr = OnDialinHours(pComponent, cookie);
  326. break;
  327. default:
  328. Panic0("InterfaceNodeHandler: Unknown menu command!");
  329. break;
  330. }
  331. if (!FHrSucceeded(hr))
  332. {
  333. DisplayErrorMessage(NULL, hr);
  334. }
  335. }
  336. COM_PROTECT_CATCH;
  337. return hr;
  338. }
  339. ImplementEmbeddedUnknown(InterfaceNodeHandler, IRtrAdviseSink)
  340. STDMETHODIMP InterfaceNodeHandler::EIRtrAdviseSink::OnChange(LONG_PTR ulConn,
  341. DWORD dwChangeType, DWORD dwObjectType, LPARAM lUserParam, LPARAM lParam)
  342. {
  343. InitPThis(InterfaceNodeHandler, IRtrAdviseSink);
  344. HRESULT hr = hrOK;
  345. return hr;
  346. }
  347. /*!--------------------------------------------------------------------------
  348. InterfaceNodeHandler::GetRemoveIfMenuFlags
  349. -
  350. Author: KennT
  351. ---------------------------------------------------------------------------*/
  352. ULONG InterfaceNodeHandler::GetRemoveIfMenuFlags(const SRouterNodeMenu *pMenuData,
  353. INT_PTR pUserData)
  354. {
  355. InterfaceNodeData * pNodeData;
  356. SMenuData * pData = reinterpret_cast<SMenuData *>(pUserData);
  357. pNodeData = GET_INTERFACENODEDATA(pData->m_spNode);
  358. Assert(pNodeData);
  359. ULONG ulType = pNodeData->spIf->GetInterfaceType();
  360. if (!IsWanInterface(ulType) || (!pData->m_fRouterIsRunning))
  361. return MF_GRAYED;
  362. else
  363. return 0;
  364. }
  365. ULONG InterfaceNodeHandler::GetEnableMenuFlags(const SRouterNodeMenu *pMenuData,
  366. INT_PTR pUserData)
  367. {
  368. ULONG ulFlags;
  369. InterfaceNodeData * pNodeData;
  370. SMenuData * pData = reinterpret_cast<SMenuData *>(pUserData);
  371. pNodeData = GET_INTERFACENODEDATA(pData->m_spNode);
  372. Assert(pNodeData);
  373. ulFlags = GetRemoveIfMenuFlags(pMenuData, pUserData);
  374. if (pNodeData->spIf->IsInterfaceEnabled())
  375. ulFlags |= pMenuData->m_sidMenu == IDS_MENU_ENABLE ? MF_GRAYED : 0;
  376. else
  377. ulFlags |= pMenuData->m_sidMenu == IDS_MENU_ENABLE ? 0 : MF_GRAYED;
  378. return ulFlags;
  379. }
  380. ULONG InterfaceNodeHandler::GetConnectMenuFlags(const SRouterNodeMenu *pMenuData, INT_PTR pUserData)
  381. {
  382. ULONG ulFlags;
  383. InterfaceNodeData * pNodeData;
  384. SMenuData * pData = reinterpret_cast<SMenuData *>(pUserData);
  385. ulFlags = GetRemoveIfMenuFlags(pMenuData, pUserData);
  386. pNodeData = GET_INTERFACENODEDATA(pData->m_spNode);
  387. Assert(pNodeData);
  388. if ((pNodeData->dwConnectionState == ROUTER_IF_STATE_DISCONNECTED) ||
  389. (pNodeData->dwConnectionState == ROUTER_IF_STATE_UNREACHABLE))
  390. {
  391. ulFlags |= (pMenuData->m_sidMenu == IDS_MENU_CONNECT ? 0 : MF_GRAYED);
  392. }
  393. else
  394. {
  395. ulFlags |= (pMenuData->m_sidMenu == IDS_MENU_CONNECT ? MF_GRAYED : 0);
  396. }
  397. return ulFlags;
  398. }
  399. ULONG InterfaceNodeHandler::GetUnreachMenuFlags(const SRouterNodeMenu *pMenuData, INT_PTR pUserData)
  400. {
  401. ULONG ulFlags;
  402. InterfaceNodeData * pNodeData;
  403. SMenuData * pData = reinterpret_cast<SMenuData *>(pUserData);
  404. pNodeData = GET_INTERFACENODEDATA(pData->m_spNode);
  405. Assert(pNodeData);
  406. return pNodeData->dwConnectionState == ROUTER_IF_STATE_UNREACHABLE ?
  407. 0 : MF_GRAYED;
  408. }
  409. ULONG InterfaceNodeHandler::GetDDFiltersFlag(const SRouterNodeMenu *pMenuData, INT_PTR pUserData)
  410. {
  411. InterfaceNodeData * pNodeData;
  412. DWORD dwIfType;
  413. SPIRouterInfo spRouter;
  414. SMenuData * pData = reinterpret_cast<SMenuData *>(pUserData);
  415. pNodeData = GET_INTERFACENODEDATA(pData->m_spNode);
  416. Assert(pNodeData);
  417. // For NT4 and NT5 Beta1, we didn't have DD filters
  418. pNodeData->spIf->GetParentRouterInfo(&spRouter);
  419. if (spRouter)
  420. {
  421. RouterVersionInfo routerVer;
  422. spRouter->GetRouterVersionInfo(&routerVer);
  423. if (routerVer.dwOsBuildNo <= 1717)
  424. {
  425. return 0xFFFFFFFF;
  426. }
  427. }
  428. dwIfType = pNodeData->spIf->GetInterfaceType();
  429. if (!IsWanInterface(dwIfType))
  430. return 0xFFFFFFFF;
  431. else
  432. return 0;
  433. }
  434. /*!--------------------------------------------------------------------------
  435. InterfaceNodeHandler::OnCreateDataObject
  436. Implementation of ITFSResultHandler::OnCreateDataObject
  437. Author: KennT
  438. ---------------------------------------------------------------------------*/
  439. STDMETHODIMP InterfaceNodeHandler::OnCreateDataObject(ITFSComponent *pComp,
  440. MMC_COOKIE cookie,
  441. DATA_OBJECT_TYPES type,
  442. IDataObject **ppDataObject)
  443. {
  444. HRESULT hr = hrOK;
  445. COM_PROTECT_TRY
  446. {
  447. CORg( CreateDataObjectFromInterfaceInfo(m_spInterfaceInfo,
  448. type, cookie, m_spTFSCompData,
  449. ppDataObject) );
  450. COM_PROTECT_ERROR_LABEL;
  451. }
  452. COM_PROTECT_CATCH;
  453. return hr;
  454. }
  455. /*!--------------------------------------------------------------------------
  456. InterfaceNodeHandler::CreatePropertyPages
  457. -
  458. Author: KennT
  459. ---------------------------------------------------------------------------*/
  460. STDMETHODIMP InterfaceNodeHandler::CreatePropertyPages(
  461. ITFSComponent * pComponent,
  462. MMC_COOKIE cookie,
  463. LPPROPERTYSHEETCALLBACK lpProvider,
  464. LPDATAOBJECT pDataObject,
  465. LONG_PTR handle)
  466. {
  467. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  468. HRESULT hr = hrOK;
  469. BOOL fIsServiceRunning;
  470. DWORD dwErr;
  471. IfAdminNodeData * pAdminData;
  472. SPITFSNode spParent;
  473. SPITFSNode spNode;
  474. SPIConsole spConsole;
  475. HWND hwndMain;
  476. DWORD dwIfType;
  477. CString stServiceDesc;
  478. SPIComponentData spComponentData;
  479. CDummyProperties * pProp;
  480. // Bring up the RASDLG instead
  481. // Start the service if the service is stopped
  482. CORg( IsRouterServiceRunning(m_spInterfaceInfo->GetMachineName(), NULL) );
  483. fIsServiceRunning = (hr == hrOK);
  484. if (!fIsServiceRunning)
  485. {
  486. // Ask the user if they want to start the service
  487. if (AfxMessageBox(IDS_PROMPT_SERVICESTART, MB_YESNO) != IDYES)
  488. CWRg( ERROR_CANCELLED );
  489. // Else start the service
  490. stServiceDesc.LoadString(IDS_RRAS_SERVICE_DESC);
  491. dwErr = TFSStartService(m_spInterfaceInfo->GetMachineName(),
  492. c_szRemoteAccess,
  493. stServiceDesc);
  494. if (dwErr != NO_ERROR)
  495. {
  496. CWRg( dwErr );
  497. }
  498. }
  499. m_spNodeMgr->FindNode(cookie, &spNode);
  500. spNode->GetParent(&spParent);
  501. pAdminData = GET_IFADMINNODEDATA(spParent);
  502. if (pAdminData->m_hInstRasDlg == NULL)
  503. {
  504. AfxMessageBox(IDS_ERR_EDITPBKLOCAL);
  505. }
  506. else
  507. {
  508. // First edit the phone book entry.
  509. // Only for wan interfaces.
  510. dwIfType = m_spInterfaceInfo->GetInterfaceType();
  511. if (IsWanInterface(dwIfType))
  512. {
  513. pComponent->GetConsole(&spConsole);
  514. spConsole->GetMainWindow(&hwndMain);
  515. // First create the phone book entry.
  516. RASENTRYDLG info;
  517. CString sPhoneBook;
  518. CString sRouter;
  519. ZeroMemory( &info, sizeof(info) );
  520. info.dwSize = sizeof(info);
  521. info.hwndOwner = hwndMain;
  522. info.dwFlags |= RASEDFLAG_NoRename;
  523. TRACE0("RouterEntryDlg\n");
  524. Assert(pAdminData->m_pfnRouterEntryDlg);
  525. sRouter = m_spInterfaceInfo->GetMachineName();
  526. IfAdminNodeHandler::GetPhoneBookPath(sRouter, &sPhoneBook);
  527. BOOL bStatus = pAdminData->m_pfnRouterEntryDlg(
  528. (LPTSTR)(LPCTSTR)sRouter,
  529. (LPTSTR)(LPCTSTR)sPhoneBook,
  530. (LPTSTR)(LPCTSTR)m_spInterfaceInfo->GetTitle(),
  531. &info);
  532. TRACE2("RouterEntryDlg=%f,e=%d\n", bStatus, info.dwError);
  533. if (!bStatus)
  534. {
  535. if (info.dwError != NO_ERROR)
  536. {
  537. AfxMessageBox(IDS_ERR_UNABLETOCONFIGPBK);
  538. }
  539. }
  540. else
  541. {
  542. //
  543. // Inform DDM about changes to phonebook entry.
  544. //
  545. UpdateDDM( m_spInterfaceInfo );
  546. }
  547. }
  548. }
  549. Error:
  550. CORg( m_spNodeMgr->GetComponentData(&spComponentData) );
  551. pProp = new CDummyProperties(spNode, spComponentData, NULL);
  552. hr = pProp->CreateModelessSheet(lpProvider, handle);
  553. return hr;
  554. }
  555. STDMETHODIMP InterfaceNodeHandler::HasPropertyPages (
  556. ITFSComponent *pComp,
  557. MMC_COOKIE cookie,
  558. LPDATAOBJECT pDataObject)
  559. {
  560. // Only provide "property pages" for WAN entries
  561. // First edit the phone book entry.
  562. // Only for wan interfaces.
  563. DWORD dwIfType = m_spInterfaceInfo->GetInterfaceType();
  564. if (IsWanInterface(dwIfType))
  565. return hrOK;
  566. else
  567. return hrFalse;
  568. }
  569. /*!--------------------------------------------------------------------------
  570. InterfaceNodeHandler::OnRemoveInterface
  571. -
  572. Author: KennT
  573. ---------------------------------------------------------------------------*/
  574. HRESULT InterfaceNodeHandler::OnRemoveInterface(MMC_COOKIE cookie)
  575. {
  576. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  577. SPITFSNode spNode;
  578. InterfaceNodeData * pNodeData = NULL;
  579. SPIRouterInfo spRouterInfo;
  580. HRESULT hr = hrOK;
  581. SPITFSNodeHandler spHandler;
  582. DWORD dwErr;
  583. BOOL fIsServiceRunning;
  584. CString stServiceDesc;
  585. RefreshInterface(cookie); // Find out whether the interface is connected to
  586. m_spNodeMgr->FindNode(cookie, &spNode);
  587. pNodeData = GET_INTERFACENODEDATA(spNode);
  588. Assert(pNodeData);
  589. BOOL bNotConnected = ((pNodeData->dwConnectionState == ROUTER_IF_STATE_DISCONNECTED)
  590. || (pNodeData->dwConnectionState == ROUTER_IF_STATE_UNREACHABLE));
  591. m_spInterfaceInfo->GetParentRouterInfo(&spRouterInfo);
  592. // Windows NT Bug : 208471
  593. // Do NOT check for the running router if we are deleting a
  594. // DD interface and we are in LAN-only mode.
  595. // We can also skip this if we are a tunnel.
  596. if ((!IsWanInterface(m_spInterfaceInfo->GetInterfaceType()) ||
  597. (m_spRouterInfo->GetRouterType() != ROUTER_TYPE_LAN)) &&
  598. (m_spInterfaceInfo->GetInterfaceType() != ROUTER_IF_TYPE_TUNNEL1))
  599. {
  600. // Start the service if the service is stopped
  601. CORg( IsRouterServiceRunning(m_spInterfaceInfo->GetMachineName(), NULL));
  602. fIsServiceRunning = (hr == hrOK);
  603. if (!fIsServiceRunning)
  604. {
  605. // Ask the user if they want to start the service
  606. if (AfxMessageBox(IDS_PROMPT_SERVICESTART, MB_YESNO) != IDYES)
  607. CWRg( ERROR_CANCELLED );
  608. // Else start the service
  609. stServiceDesc.LoadString(IDS_RRAS_SERVICE_DESC);
  610. dwErr = TFSStartService(m_spInterfaceInfo->GetMachineName(), c_szRemoteAccess, stServiceDesc);
  611. if (dwErr != NO_ERROR)
  612. {
  613. CWRg( dwErr );
  614. }
  615. }
  616. }
  617. // Addref this node so that it won't get deleted before we're out
  618. // of this function
  619. spHandler.Set(this);
  620. // if connected, disconnect first
  621. if(!bNotConnected && ROUTER_IF_TYPE_FULL_ROUTER == m_spInterfaceInfo->GetInterfaceType())
  622. {
  623. if (AfxMessageBox(IDS_PROMPT_VERIFY_DISCONNECT_INTERFACE, MB_YESNO|MB_DEFBUTTON2) == IDNO)
  624. return HRESULT_FROM_WIN32(ERROR_CANCELLED);
  625. // Disconnect
  626. hr = OnConnectDisconnect(cookie, IDS_MENU_DISCONNECT);
  627. if(FAILED(hr))
  628. return hr;
  629. SPMprServerHandle sphRouter;
  630. MPR_SERVER_HANDLE hRouter = NULL;
  631. dwErr = ConnectRouter(m_spInterfaceInfo->GetMachineName(), &hRouter);
  632. if (dwErr != NO_ERROR)
  633. {
  634. AfxMessageBox(IDS_ERR_DELETE_INTERFACE);
  635. return HRESULT_FROM_WIN32(dwErr);
  636. }
  637. sphRouter.Attach(hRouter); // so that it gets released
  638. WCHAR wszInterface[MAX_INTERFACE_NAME_LEN+1];
  639. StrCpyWFromT(wszInterface, m_spInterfaceInfo->GetId());
  640. HANDLE hInterface;
  641. dwErr = ::MprAdminInterfaceGetHandle(
  642. hRouter,
  643. wszInterface,
  644. &hInterface,
  645. FALSE
  646. );
  647. if (dwErr != NO_ERROR)
  648. {
  649. AfxMessageBox(IDS_ERR_DELETE_INTERFACE);
  650. return HRESULT_FROM_WIN32(dwErr);
  651. }
  652. SPMprAdminBuffer spMprBuffer;
  653. DWORD dwConnectionState = 0;
  654. do
  655. {
  656. dwErr = ::MprAdminInterfaceGetInfo(
  657. hRouter,
  658. hInterface,
  659. 0,
  660. (LPBYTE*)&spMprBuffer
  661. );
  662. if (dwErr != NO_ERROR || !spMprBuffer)
  663. {
  664. AfxMessageBox(IDS_ERR_DELETE_INTERFACE);
  665. return HRESULT_FROM_WIN32(dwErr);
  666. }
  667. MPR_INTERFACE_0 *pInfo = (MPR_INTERFACE_0 *) (LPBYTE) spMprBuffer;
  668. dwConnectionState = pInfo->dwConnectionState;
  669. if (dwConnectionState != ROUTER_IF_STATE_DISCONNECTED)
  670. Sleep(0);
  671. } while (dwConnectionState != ROUTER_IF_STATE_DISCONNECTED);
  672. }
  673. else
  674. {
  675. if (AfxMessageBox(IDS_PROMPT_VERIFY_REMOVE_INTERFACE, MB_YESNO|MB_DEFBUTTON2) == IDNO)
  676. return HRESULT_FROM_WIN32(ERROR_CANCELLED);
  677. }
  678. if (spRouterInfo)
  679. {
  680. hr = spRouterInfo->DeleteInterface(m_spInterfaceInfo->GetId(), TRUE);
  681. if (!FHrSucceeded(hr))
  682. {
  683. AfxMessageBox(IDS_ERR_DELETE_INTERFACE);
  684. }
  685. }
  686. Error:
  687. return hr;
  688. }
  689. /*!--------------------------------------------------------------------------
  690. InterfaceNodeHandler::OnUnreachabilityReason
  691. -
  692. Author: KennT
  693. ---------------------------------------------------------------------------*/
  694. HRESULT InterfaceNodeHandler::OnUnreachabilityReason(MMC_COOKIE cookie)
  695. {
  696. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  697. CString stReason;
  698. SPITFSNode spNode;
  699. InterfaceNodeData * pNodeData;
  700. DWORD dwUnreach;
  701. LPWSTR lpwErr;
  702. SPMprAdminBuffer spMprBuffer;
  703. m_spNodeMgr->FindNode(cookie, &spNode);
  704. Assert(spNode);
  705. pNodeData = GET_INTERFACENODEDATA(spNode);
  706. Assert(pNodeData);
  707. dwUnreach = pNodeData->dwUnReachabilityReason;
  708. if (dwUnreach == MPR_INTERFACE_NOT_LOADED)
  709. {
  710. if (pNodeData->fIsRunning)
  711. stReason += GetUnreachReasonCString(IDS_ERR_UNREACH_NOT_LOADED);
  712. else
  713. stReason += GetUnreachReasonCString(IDS_ERR_UNREACH_NOT_RUNNING);
  714. }
  715. if (dwUnreach & MPR_INTERFACE_DIALOUT_HOURS_RESTRICTION)
  716. stReason += GetUnreachReasonCString(IDS_ERR_UNREACH_DIALOUT_HOURS_RESTRICTION);
  717. if (dwUnreach & MPR_INTERFACE_NO_MEDIA_SENSE)
  718. stReason += GetUnreachReasonCString(IDS_ERR_UNREACH_NO_MEDIA_SENSE);
  719. if (dwUnreach & MPR_INTERFACE_ADMIN_DISABLED)
  720. stReason += GetUnreachReasonCString(IDS_ERR_UNREACH_ADMIN_DISABLED);
  721. if (dwUnreach & MPR_INTERFACE_SERVICE_PAUSED)
  722. stReason += GetUnreachReasonCString(IDS_ERR_UNREACH_SERVICE_PAUSED);
  723. if (dwUnreach & MPR_INTERFACE_OUT_OF_RESOURCES)
  724. stReason += GetUnreachReasonCString(IDS_ERR_UNREACH_NO_PORTS);
  725. else if ( dwUnreach & MPR_INTERFACE_CONNECTION_FAILURE )
  726. {
  727. stReason += GetUnreachReasonCString(IDS_ERR_UNREACH_CONNECT_FAILURE);
  728. //Workaround for bugid: 96347. Change this once
  729. //schannel has an alert for SEC_E_MULTIPLE_ACCOUNTS
  730. if ( pNodeData->dwLastError == SEC_E_CERT_UNKNOWN )
  731. {
  732. pNodeData->dwLastError = SEC_E_MULTIPLE_ACCOUNTS;
  733. }
  734. if (::MprAdminGetErrorString(pNodeData->dwLastError, &lpwErr) == NO_ERROR )
  735. {
  736. spMprBuffer = (BYTE *) lpwErr;
  737. stReason += (LPCTSTR) lpwErr;
  738. }
  739. }
  740. AfxMessageBox(stReason);
  741. return hrOK;
  742. }
  743. /*!--------------------------------------------------------------------------
  744. InterfaceNodeHandler::OnEnableDisable
  745. -
  746. Author: KennT
  747. ---------------------------------------------------------------------------*/
  748. HRESULT InterfaceNodeHandler::OnEnableDisable(MMC_COOKIE cookie, int nCommandID)
  749. {
  750. HRESULT hr = hrOK;
  751. m_spInterfaceInfo->SetInterfaceEnabledState(nCommandID == IDS_MENU_ENABLE);
  752. {
  753. CWaitCursor waitcursor;
  754. hr = m_spInterfaceInfo->Save(NULL, NULL, NULL);
  755. }
  756. // Actually the above call should trigger an event that causes a
  757. // refresh, the explicit RefreshInterface() should not be necessary.
  758. RefreshInterface(cookie);
  759. return hrOK;
  760. }
  761. /*!--------------------------------------------------------------------------
  762. InterfaceNodeHandler::OnConnectDisconnect
  763. -
  764. Author: KennT
  765. ---------------------------------------------------------------------------*/
  766. HRESULT InterfaceNodeHandler::OnConnectDisconnect(MMC_COOKIE cookie, int nCommandID)
  767. {
  768. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  769. HRESULT hr = hrOK;
  770. DWORD dwErr;
  771. InterfaceNodeData * pData;
  772. SPITFSNode spNode;
  773. dwErr = ::ConnectInterface(m_spInterfaceInfo->GetMachineName(),
  774. m_spInterfaceInfo->GetId(),
  775. nCommandID == IDS_MENU_CONNECT /* bConnect */,
  776. NULL /*hwndParent*/);
  777. RefreshInterface(cookie);
  778. /*
  779. m_spNodeMgr->FindNode(cookie, &spNode);
  780. pData = GET_INTERFACENODEDATA(spNode);
  781. Assert(pData);
  782. if (dwErr != NO_ERROR && dwErr != PENDING)
  783. {
  784. TCHAR szErr[1024];
  785. FormatSystemError(pData->dwLastError, szErr, 1024, IDS_ERR_ERROR_OCCURRED, 0xFFFFFFFF);
  786. AfxMessageBox(szErr);
  787. }
  788. */
  789. if (dwErr != NO_ERROR && dwErr != PENDING)
  790. {
  791. TCHAR szErr[1024];
  792. FormatSystemError(dwErr, szErr, 1024, IDS_ERR_ERROR_OCCURRED, 0xFFFFFFFF);
  793. AfxMessageBox(szErr);
  794. }
  795. return hrOK;
  796. }
  797. /*!--------------------------------------------------------------------------
  798. InterfaceNodeHandler::OnSetCredentials
  799. -
  800. Author: KennT
  801. ---------------------------------------------------------------------------*/
  802. HRESULT InterfaceNodeHandler::OnSetCredentials()
  803. {
  804. SPIRouterInfo spRouter;
  805. BOOL fNT4 = FALSE;
  806. DWORD dwErr;
  807. m_spInterfaceInfo->GetParentRouterInfo(&spRouter);
  808. if (spRouter)
  809. {
  810. RouterVersionInfo routerVer;
  811. spRouter->GetRouterVersionInfo(&routerVer);
  812. if (routerVer.dwOsBuildNo <= 1877)
  813. {
  814. fNT4 = TRUE;
  815. }
  816. }
  817. dwErr = PromptForCredentials(m_spInterfaceInfo->GetMachineName(),
  818. m_spInterfaceInfo->GetId(),
  819. fNT4,
  820. FALSE /* fNewInterface */,
  821. NULL /* hwndParent */
  822. );
  823. return HRESULT_FROM_WIN32(dwErr);
  824. }
  825. /*!--------------------------------------------------------------------------
  826. InterfaceNodeHandler::OnDemandDialFilters
  827. -
  828. Author: KennT
  829. ---------------------------------------------------------------------------*/
  830. HRESULT InterfaceNodeHandler::OnDemandDialFilters(MMC_COOKIE cookie)
  831. {
  832. HRESULT hr = hrOK;
  833. CWaitCursor wait;
  834. SPIInfoBase spInfoBase;
  835. SPIRtrMgrInterfaceInfo spRmIf;
  836. CORg( m_spInterfaceInfo->FindRtrMgrInterface(PID_IP, &spRmIf) );
  837. if (spRmIf == NULL)
  838. {
  839. //$ TODO : need to bring up an error message, about requiring
  840. // that IP be added to this interface
  841. AfxMessageBox(IDS_ERR_DDFILTERS_REQUIRE_IP);
  842. goto Error;
  843. }
  844. CORg( spRmIf->GetInfoBase(NULL, NULL, NULL, &spInfoBase) );
  845. CORg( MprUIFilterConfigInfoBase(NULL,
  846. spInfoBase,
  847. NULL,
  848. PID_IP,
  849. FILTER_DEMAND_DIAL) );
  850. if (hr == hrOK)
  851. {
  852. CORg( spRmIf->Save(m_spInterfaceInfo->GetMachineName(),
  853. NULL, NULL, NULL, spInfoBase, 0) );
  854. }
  855. Error:
  856. if (!FHrSucceeded(hr))
  857. {
  858. DisplayErrorMessage(NULL, hr);
  859. }
  860. return hr;
  861. }
  862. /*!--------------------------------------------------------------------------
  863. InterfaceNodeHandler::LoadDialOutHours
  864. -
  865. Author: WeiJiang
  866. ---------------------------------------------------------------------------*/
  867. // if the service is not running, return S_FALSE,
  868. // otherwise, using MprAdminInterfaceSetInfo to notify the service of dialin hours changes
  869. HRESULT InterfaceNodeHandler::LoadDialOutHours(CStringList& strList)
  870. {
  871. HANDLE hMachine = INVALID_HANDLE_VALUE;
  872. HANDLE hInterface = INVALID_HANDLE_VALUE;
  873. BOOL bLoaded = FALSE;
  874. HRESULT hr = S_OK;
  875. MPR_INTERFACE_1* pmprif1 = NULL;
  876. DWORD dwErr = 0;
  877. DWORD size;
  878. // Try to connect to the mpradmin service
  879. // Note: this may fail but the service queries down below may
  880. // succeed, so we should setup the states as well as we can here.
  881. // ----------------------------------------------------------------
  882. CORg( IsRouterServiceRunning(m_spInterfaceInfo->GetMachineName(), NULL));
  883. while(hr == S_OK /*running*/ && !bLoaded) // FALSE loop, if runing, load from Service
  884. {
  885. dwErr = ::MprAdminServerConnect((LPWSTR)m_spInterfaceInfo->GetMachineName(), &hMachine);
  886. if(dwErr != NOERROR || hMachine == INVALID_HANDLE_VALUE)
  887. break;
  888. dwErr = ::MprAdminInterfaceGetHandle(hMachine,
  889. (LPWSTR) m_spInterfaceInfo->GetId(),
  890. &hInterface,
  891. FALSE );
  892. if(dwErr != NOERROR || hInterface == INVALID_HANDLE_VALUE)
  893. break;
  894. // See if the interface is connected
  895. dwErr = ::MprAdminInterfaceGetInfo(hMachine,
  896. hInterface,
  897. 1,
  898. (LPBYTE*)&pmprif1);
  899. if(dwErr != NOERROR || pmprif1 == NULL)
  900. break;
  901. // get the dialin out information
  902. dwErr = MULTI_SZ2StrList(pmprif1->lpwsDialoutHoursRestriction, strList);
  903. // Windows NT Bug : 317146
  904. // Add on an emptry string to the string list
  905. // This signifies that we have no data (as opposed to the NULL data)
  906. if (pmprif1->lpwsDialoutHoursRestriction)
  907. strList.AddTail(_T(""));
  908. bLoaded = TRUE;
  909. // free the buffer
  910. ::MprAdminBufferFree(pmprif1);
  911. pmprif1 = NULL;
  912. break;
  913. };
  914. // disconnect it
  915. if(hMachine != INVALID_HANDLE_VALUE)
  916. {
  917. ::MprAdminServerDisconnect(hMachine);
  918. hMachine = INVALID_HANDLE_VALUE;
  919. }
  920. // if not loaded, try MprConfig APIs
  921. while(!bLoaded)
  922. {
  923. dwErr = ::MprConfigServerConnect((LPWSTR)m_spInterfaceInfo->GetMachineName(), &hMachine);
  924. if(dwErr != NOERROR || hMachine == INVALID_HANDLE_VALUE)
  925. break;
  926. dwErr = ::MprConfigInterfaceGetHandle(hMachine,
  927. (LPWSTR) m_spInterfaceInfo->GetId(),
  928. &hInterface);
  929. if(dwErr != NOERROR || hInterface == INVALID_HANDLE_VALUE)
  930. break;
  931. // See if the interface is connected
  932. dwErr = ::MprConfigInterfaceGetInfo(hMachine,
  933. hInterface,
  934. 1,
  935. (LPBYTE*)&pmprif1,
  936. &size);
  937. if(dwErr != NOERROR || pmprif1 == NULL)
  938. break;
  939. // get the dialin out information
  940. dwErr = MULTI_SZ2StrList(pmprif1->lpwsDialoutHoursRestriction, strList);
  941. // Windows NT Bug : 317146
  942. // Add on an emptry string to the string list
  943. // This signifies that we have no data (as opposed to the NULL data)
  944. if (pmprif1->lpwsDialoutHoursRestriction)
  945. strList.AddTail(_T(""));
  946. bLoaded = TRUE;
  947. // free the buffer
  948. ::MprConfigBufferFree(pmprif1);
  949. pmprif1 = NULL;
  950. break;
  951. }
  952. // disconnect it
  953. if(hMachine != INVALID_HANDLE_VALUE)
  954. {
  955. ::MprConfigServerDisconnect(hMachine);
  956. hMachine = INVALID_HANDLE_VALUE;
  957. }
  958. if(!bLoaded)
  959. {
  960. HKEY hkeyMachine = NULL;
  961. HKEY hkeyIf;
  962. RegKey regkeyIf;
  963. // last chance if to connect to registry directly
  964. // Load up the information (from the registry) for the dialin hours
  965. CWRg( ConnectRegistry(m_spInterfaceInfo->GetMachineName(), &hkeyMachine) );
  966. CORg( RegFindInterfaceKey(m_spInterfaceInfo->GetId(), hkeyMachine,
  967. KEY_ALL_ACCESS, &hkeyIf));
  968. regkeyIf.Attach(hkeyIf);
  969. // Now grab the data
  970. dwErr = regkeyIf.QueryValue(c_szDialOutHours, strList);
  971. if (dwErr == NOERROR)
  972. bLoaded = TRUE;
  973. if(hkeyMachine != NULL)
  974. {
  975. DisconnectRegistry(hkeyMachine);
  976. hkeyMachine = NULL;
  977. }
  978. }
  979. Error:
  980. if(dwErr != NOERROR)
  981. hr = HRESULT_FROM_WIN32(dwErr);
  982. return hr;
  983. }
  984. /*!--------------------------------------------------------------------------
  985. InterfaceNodeHandler::SaveDialOutHours
  986. -
  987. Author: WeiJiang
  988. ---------------------------------------------------------------------------*/
  989. // if the service is not running, return S_FALSE,
  990. // otherwise, using MprAdminInterfaceSetInfo to notify the service of dialin hours changes
  991. HRESULT InterfaceNodeHandler::SaveDialOutHours(CStringList& strList)
  992. {
  993. HANDLE hMachine = INVALID_HANDLE_VALUE;
  994. HANDLE hInterface = INVALID_HANDLE_VALUE;
  995. HRESULT hr = S_OK;
  996. MPR_INTERFACE_1* pmprif1 = NULL;
  997. MPR_INTERFACE_1 mprif1;
  998. DWORD dwErr = 0;
  999. BYTE* pbData = NULL;
  1000. DWORD size;
  1001. BOOL bSaved = FALSE;
  1002. dwErr = StrList2MULTI_SZ(strList, &size, &pbData);
  1003. if(dwErr != NOERROR)
  1004. {
  1005. goto Error;
  1006. }
  1007. //try MprConfig APIs
  1008. while(!bSaved)
  1009. {
  1010. dwErr = ::MprConfigServerConnect((LPWSTR)m_spInterfaceInfo->GetMachineName(), &hMachine);
  1011. if(dwErr != NOERROR || hMachine == INVALID_HANDLE_VALUE)
  1012. break;
  1013. dwErr = ::MprConfigInterfaceGetHandle(hMachine,
  1014. (LPWSTR) m_spInterfaceInfo->GetId(),
  1015. &hInterface);
  1016. if(dwErr != NOERROR || hInterface == INVALID_HANDLE_VALUE)
  1017. break;
  1018. // See if the interface is connected
  1019. dwErr = ::MprConfigInterfaceGetInfo(hMachine,
  1020. hInterface,
  1021. 1,
  1022. (LPBYTE*)&pmprif1,
  1023. &size);
  1024. if(dwErr != NOERROR || pmprif1 == NULL)
  1025. break;
  1026. memcpy(&mprif1, pmprif1, sizeof(MPR_INTERFACE_1));
  1027. mprif1.lpwsDialoutHoursRestriction = (LPWSTR)pbData;
  1028. // See if the interface is connected
  1029. dwErr = ::MprConfigInterfaceSetInfo(hMachine,
  1030. hInterface,
  1031. 1,
  1032. (LPBYTE)&mprif1);
  1033. if(dwErr == NOERROR)
  1034. bSaved = TRUE;
  1035. // free the buffer
  1036. ::MprConfigBufferFree(pmprif1);
  1037. pmprif1 = NULL;
  1038. break;
  1039. }
  1040. // disconnect it
  1041. if(hMachine != INVALID_HANDLE_VALUE)
  1042. {
  1043. ::MprConfigServerDisconnect(hMachine);
  1044. hMachine = INVALID_HANDLE_VALUE;
  1045. }
  1046. if(dwErr != NOERROR)
  1047. hr = HRESULT_FROM_WIN32(dwErr);
  1048. // Try to connect to the mpradmin service
  1049. // Note: this may fail but the service queries down below may
  1050. // succeed, so we should setup the states as well as we can here.
  1051. // ----------------------------------------------------------------
  1052. CORg( IsRouterServiceRunning(m_spInterfaceInfo->GetMachineName(), NULL));
  1053. while(hr == S_OK) // FALSE loop, if runing, save to Service
  1054. {
  1055. DWORD dwErr1 = ::MprAdminServerConnect((LPWSTR)m_spInterfaceInfo->GetMachineName(), &hMachine);
  1056. if(dwErr1 != NOERROR || hMachine == INVALID_HANDLE_VALUE)
  1057. break;
  1058. dwErr1 = ::MprAdminInterfaceGetHandle(hMachine,
  1059. (LPWSTR) m_spInterfaceInfo->GetId(),
  1060. &hInterface,
  1061. FALSE );
  1062. if(dwErr1 != NOERROR || hInterface == INVALID_HANDLE_VALUE)
  1063. break;
  1064. // See if the interface is connected
  1065. dwErr1 = ::MprAdminInterfaceGetInfo(hMachine,
  1066. hInterface,
  1067. 1,
  1068. (LPBYTE*)&pmprif1);
  1069. if(dwErr1 != NOERROR || pmprif1 == NULL)
  1070. break;
  1071. memcpy(&mprif1, pmprif1, sizeof(MPR_INTERFACE_1));
  1072. mprif1.lpwsDialoutHoursRestriction = (LPWSTR)pbData;
  1073. dwErr1 = ::MprAdminInterfaceSetInfo(hMachine,
  1074. hInterface,
  1075. 1,
  1076. (LPBYTE)&mprif1);
  1077. // free the buffer
  1078. ::MprAdminBufferFree(pmprif1);
  1079. pmprif1 = NULL;
  1080. break;
  1081. };
  1082. // disconnect it
  1083. if(hMachine != INVALID_HANDLE_VALUE)
  1084. {
  1085. ::MprAdminServerDisconnect(hMachine);
  1086. hMachine = INVALID_HANDLE_VALUE;
  1087. }
  1088. if (!bSaved)
  1089. {
  1090. HKEY hkeyMachine = NULL;
  1091. HKEY hkeyIf;
  1092. RegKey regkeyIf;
  1093. // last chance if to connect to registry directly
  1094. // Load up the information (from the registry) for the dialin hours
  1095. CWRg( ConnectRegistry(m_spInterfaceInfo->GetMachineName(), &hkeyMachine) );
  1096. CORg( RegFindInterfaceKey(m_spInterfaceInfo->GetId(), hkeyMachine,
  1097. KEY_ALL_ACCESS, &hkeyIf));
  1098. regkeyIf.Attach(hkeyIf);
  1099. // Now grab the data
  1100. dwErr = regkeyIf.SetValue(c_szDialOutHours, strList);
  1101. if(dwErr == NOERROR)
  1102. bSaved = TRUE;
  1103. if(hkeyMachine != NULL)
  1104. DisconnectRegistry(hkeyMachine);
  1105. }
  1106. Error:
  1107. if(pbData)
  1108. delete pbData;
  1109. if(dwErr != NOERROR)
  1110. hr = HRESULT_FROM_WIN32(dwErr);
  1111. return hr;
  1112. }
  1113. /*!--------------------------------------------------------------------------
  1114. InterfaceNodeHandler::OnDialinHours
  1115. -
  1116. Author: KennT
  1117. ---------------------------------------------------------------------------*/
  1118. HRESULT InterfaceNodeHandler::OnDialinHours(ITFSComponent *pComponent, MMC_COOKIE cookie)
  1119. {
  1120. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1121. HRESULT hr = hrOK;
  1122. BYTE rgbDialinHoursMap[21];
  1123. CString stDialogTitle;
  1124. HWND hWnd;
  1125. SPIConsole spConsole;
  1126. HKEY hkeyMachine = NULL;
  1127. HKEY hkeyIf;
  1128. RegKey regkeyIf;
  1129. CStringList rgstList;
  1130. BYTE * pMap = &(rgbDialinHoursMap[0]);
  1131. // Get various MMC information
  1132. CORg( pComponent->GetConsole(&spConsole) );
  1133. CORg( spConsole->GetMainWindow(&hWnd) );
  1134. // If the key doesn't exist then we should set the entire thing to FF
  1135. memset(rgbDialinHoursMap, 0xFF, sizeof(rgbDialinHoursMap));
  1136. CORg(LoadDialOutHours(rgstList));
  1137. // Convert this string list into the binary data
  1138. if(rgstList.GetCount())
  1139. StrListToHourMap(rgstList, pMap);
  1140. stDialogTitle.LoadString(IDS_TITLE_DIALINHOURS);
  1141. if (OpenTimeOfDayDlgEx(hWnd, (BYTE **) &pMap, stDialogTitle, SCHED_FLAG_INPUT_LOCAL_TIME) == S_OK)
  1142. {
  1143. rgstList.RemoveAll();
  1144. // Write the information back out to the registry
  1145. HourMapToStrList(pMap, rgstList);
  1146. CORg(SaveDialOutHours(rgstList));
  1147. }
  1148. Error:
  1149. if (!FHrSucceeded(hr))
  1150. DisplayErrorMessage(NULL, hr);
  1151. return hr;
  1152. }
  1153. /*!--------------------------------------------------------------------------
  1154. InterfaceNodeHandler::RefreshInterface
  1155. -
  1156. Author: KennT
  1157. ---------------------------------------------------------------------------*/
  1158. void InterfaceNodeHandler::RefreshInterface(MMC_COOKIE cookie)
  1159. {
  1160. SPITFSNode spNode;
  1161. SPITFSNode spParent;
  1162. SPITFSNodeHandler spHandler;
  1163. m_spNodeMgr->FindNode(cookie, &spNode);
  1164. // Can't do it for a single node at this time, just refresh the
  1165. // whole thing.
  1166. spNode->GetParent(&spParent);
  1167. spParent->GetHandler(&spHandler);
  1168. spHandler->OnCommand(spParent,
  1169. IDS_MENU_REFRESH,
  1170. CCT_RESULT, NULL, 0);
  1171. }
  1172. /*!--------------------------------------------------------------------------
  1173. InterfaceNodeHandler::OnResultDelete
  1174. This notification is received for the delete key from the toolbar
  1175. or from the 'delete' key. Forward this to the RemoveInterface
  1176. operation.
  1177. Author: KennT
  1178. ---------------------------------------------------------------------------*/
  1179. HRESULT InterfaceNodeHandler::OnResultDelete(ITFSComponent *pComponent,
  1180. LPDATAOBJECT pDataObject,
  1181. MMC_COOKIE cookie,
  1182. LPARAM arg,
  1183. LPARAM param)
  1184. {
  1185. return OnRemoveInterface(cookie);
  1186. // add new parameter to provide interface data -- bug 166461
  1187. // return OnRemoveInterface();
  1188. }
  1189. /*---------------------------------------------------------------------------
  1190. BaseResultHandler implementation
  1191. ---------------------------------------------------------------------------*/
  1192. DEBUG_DECLARE_INSTANCE_COUNTER(BaseResultHandler)
  1193. IMPLEMENT_ADDREF_RELEASE(BaseResultHandler)
  1194. STDMETHODIMP BaseResultHandler::QueryInterface(REFIID riid, LPVOID *ppv)
  1195. {
  1196. // Is the pointer bad?
  1197. if (ppv == NULL)
  1198. return E_INVALIDARG;
  1199. // Place NULL in *ppv in case of failure
  1200. *ppv = NULL;
  1201. // This is the non-delegating IUnknown implementation
  1202. if (riid == IID_IUnknown)
  1203. *ppv = (LPVOID) this;
  1204. else if (riid == IID_IRtrAdviseSink)
  1205. *ppv = &m_IRtrAdviseSink;
  1206. else
  1207. return CBaseResultHandler::QueryInterface(riid, ppv);
  1208. // If we're going to return an interface, AddRef it first
  1209. if (*ppv)
  1210. {
  1211. ((LPUNKNOWN) *ppv)->AddRef();
  1212. return hrOK;
  1213. }
  1214. else
  1215. return E_NOINTERFACE;
  1216. }
  1217. /*---------------------------------------------------------------------------
  1218. NodeHandler implementation
  1219. ---------------------------------------------------------------------------*/
  1220. /*!--------------------------------------------------------------------------
  1221. BaseResultHandler::GetString
  1222. -
  1223. Author: KennT
  1224. ---------------------------------------------------------------------------*/
  1225. STDMETHODIMP_(LPCTSTR) BaseResultHandler::GetString(ITFSComponent * pComponent,
  1226. MMC_COOKIE cookie,
  1227. int nCol)
  1228. {
  1229. Assert(m_spNodeMgr);
  1230. SPITFSNode spNode;
  1231. InterfaceNodeData * pData;
  1232. ConfigStream * pConfig;
  1233. m_spNodeMgr->FindNode(cookie, &spNode);
  1234. Assert(spNode);
  1235. pData = GET_INTERFACENODEDATA(spNode);
  1236. Assert(pData);
  1237. pComponent->GetUserData((LONG_PTR *) &pConfig);
  1238. Assert(pConfig);
  1239. return pData->m_rgData[pConfig->MapColumnToSubitem(m_ulColumnId, nCol)].m_stData;
  1240. }
  1241. /*!--------------------------------------------------------------------------
  1242. BaseResultHandler::CompareItems
  1243. -
  1244. Author: KennT
  1245. ---------------------------------------------------------------------------*/
  1246. STDMETHODIMP_(int) BaseResultHandler::CompareItems(ITFSComponent * pComponent,
  1247. MMC_COOKIE cookieA,
  1248. MMC_COOKIE cookieB,
  1249. int nCol)
  1250. {
  1251. ConfigStream * pConfig;
  1252. pComponent->GetUserData((LONG_PTR *) &pConfig);
  1253. Assert(pConfig);
  1254. int nSubItem = pConfig->MapColumnToSubitem(m_ulColumnId, nCol);
  1255. if (pConfig->GetSortCriteria(m_ulColumnId, nCol) == CON_SORT_BY_DWORD)
  1256. {
  1257. SPITFSNode spNodeA, spNodeB;
  1258. InterfaceNodeData * pNodeDataA, *pNodeDataB;
  1259. m_spNodeMgr->FindNode(cookieA, &spNodeA);
  1260. m_spNodeMgr->FindNode(cookieB, &spNodeB);
  1261. pNodeDataA = GET_INTERFACENODEDATA(spNodeA);
  1262. Assert(pNodeDataA);
  1263. pNodeDataB = GET_INTERFACENODEDATA(spNodeB);
  1264. Assert(pNodeDataB);
  1265. return pNodeDataA->m_rgData[nSubItem].m_dwData -
  1266. pNodeDataB->m_rgData[nSubItem].m_dwData;
  1267. }
  1268. else
  1269. return StriCmpW(GetString(pComponent, cookieA, nCol),
  1270. GetString(pComponent, cookieB, nCol));
  1271. }
  1272. ImplementEmbeddedUnknown(BaseResultHandler, IRtrAdviseSink)
  1273. STDMETHODIMP BaseResultHandler::EIRtrAdviseSink::OnChange(LONG_PTR dwConn,
  1274. DWORD dwChangeType, DWORD dwObjectType, LPARAM lUserParam, LPARAM lParam)
  1275. {
  1276. InitPThis(BaseResultHandler, IRtrAdviseSink);
  1277. HRESULT hr = hrOK;
  1278. Panic0("Should never reach here, interface nodes have no children");
  1279. return hr;
  1280. }
  1281. HRESULT BaseResultHandler::Init(IInterfaceInfo *pIfInfo, ITFSNode *pParent)
  1282. {
  1283. return hrOK;
  1284. }
  1285. STDMETHODIMP BaseResultHandler::DestroyResultHandler(MMC_COOKIE cookie)
  1286. {
  1287. SPITFSNode spNode;
  1288. m_spNodeMgr->FindNode(cookie, &spNode);
  1289. InterfaceNodeData::Free(spNode);
  1290. BaseRouterHandler::DestroyResultHandler(cookie);
  1291. return hrOK;
  1292. }