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

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