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.

432 lines
11 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. nbprop.cpp
  7. IPX summary node property sheet and property pages
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "rtrutil.h" // smart MPR handle pointers
  12. #include "format.h" // FormatNumber function
  13. #include "nbprop.h"
  14. #include "summary.h"
  15. #include "ipxrtdef.h"
  16. #include "filter.h"
  17. extern "C"
  18. {
  19. #include "routprot.h"
  20. };
  21. IpxNBInterfaceProperties::IpxNBInterfaceProperties(ITFSNode *pNode,
  22. IComponentData *pComponentData,
  23. ITFSComponentData *pTFSCompData,
  24. LPCTSTR pszSheetName,
  25. CWnd *pParent,
  26. UINT iPage,
  27. BOOL fScopePane)
  28. : RtrPropertySheet(pNode, pComponentData, pTFSCompData,
  29. pszSheetName, pParent, iPage, fScopePane),
  30. m_pageGeneral(IDD_IPX_NB_IF_GENERAL_PAGE)
  31. {
  32. m_spNode.Set(pNode);
  33. }
  34. /*!--------------------------------------------------------------------------
  35. IpxNBInterfaceProperties::Init
  36. Initialize the property sheets. The general action here will be
  37. to initialize/add the various pages.
  38. Author: KennT
  39. ---------------------------------------------------------------------------*/
  40. HRESULT IpxNBInterfaceProperties::Init(IRtrMgrInfo *pRm,
  41. IInterfaceInfo *pIfInfo)
  42. {
  43. HRESULT hr = hrOK;
  44. IPXConnection * pIPXConn;
  45. BaseIPXResultNodeData * pData;
  46. pData = GET_BASEIPXRESULT_NODEDATA(m_spNode);
  47. ASSERT_BASEIPXRESULT_NODEDATA(pData);
  48. pIPXConn = pData->m_pIPXConnection;
  49. m_spRm.Set(pRm);
  50. m_spIf.Set(pIfInfo);
  51. // The pages are embedded members of the class
  52. // do not delete them.
  53. m_bAutoDeletePages = FALSE;
  54. // Initialize the infobase
  55. // Do this here, because the init is called in the context
  56. // of the main thread
  57. CORg( LoadInfoBase(pIPXConn) );
  58. m_pageGeneral.Init(m_spIf, pIPXConn, this);
  59. AddPageToList((CPropertyPageBase*) &m_pageGeneral);
  60. Error:
  61. return hr;
  62. }
  63. /*!--------------------------------------------------------------------------
  64. IpxNBInterfaceProperties::LoadInfoBase
  65. -
  66. Author: KennT
  67. ---------------------------------------------------------------------------*/
  68. HRESULT IpxNBInterfaceProperties::LoadInfoBase(IPXConnection *pIPXConn)
  69. {
  70. Assert(pIPXConn);
  71. HRESULT hr = hrOK;
  72. SPIRouterInfo spRouterInfo;
  73. HANDLE hTransport= NULL;
  74. LPCOLESTR pszInterfaceId = NULL;
  75. SPIInfoBase spInfoBase;
  76. BYTE * pDefault;
  77. int cBlocks = 0;
  78. // Get the transport handle
  79. CWRg( ::MprConfigTransportGetHandle(pIPXConn->GetConfigHandle(),
  80. PID_IPX,
  81. &hTransport) );
  82. // If configuring the client-interface, load the client-interface info,
  83. // otherwise, retrieve the interface being configured and load
  84. // its info.
  85. // The client interface doesn't have an ID
  86. if (m_spIf)
  87. pszInterfaceId = m_spIf->GetId();
  88. if ((pszInterfaceId == NULL) || (StrLenW(pszInterfaceId) == 0))
  89. {
  90. #ifdef DEBUG
  91. // Check to see that this is really an client node
  92. {
  93. BaseIPXResultNodeData * pResultData = NULL;
  94. pResultData = GET_BASEIPXRESULT_NODEDATA(m_spNode);
  95. Assert(pResultData);
  96. ASSERT_BASEIPXRESULT_NODEDATA(pResultData);
  97. Assert(pResultData->m_fClient);
  98. }
  99. #endif
  100. // Load the client interface info
  101. CORg( m_spRm->GetInfoBase(pIPXConn->GetConfigHandle(),
  102. hTransport,
  103. NULL,
  104. &spInfoBase) );
  105. m_bClientInfoBase = TRUE;
  106. }
  107. else
  108. {
  109. m_spRmIf.Release();
  110. CORg( m_spIf->FindRtrMgrInterface(PID_IPX,
  111. &m_spRmIf) );
  112. //
  113. // Future Opt. This should be made into a sync call rather
  114. // than a Load.
  115. //
  116. // Reload the information for this router-manager interface
  117. //
  118. CORg( m_spRmIf->Load(m_spIf->GetMachineName(), NULL,
  119. NULL, NULL) );
  120. //
  121. // The parameters are all NULL so that we can use the
  122. // default RPC handles.
  123. //
  124. CORg( m_spRmIf->GetInfoBase(NULL, NULL, NULL, &spInfoBase) );
  125. m_bClientInfoBase = FALSE;
  126. }
  127. if (!spInfoBase)
  128. {
  129. // No info was found for the inteface
  130. // allocate a new InfoBase instead
  131. CORg( CreateInfoBase(&spInfoBase) );
  132. }
  133. //
  134. // Check that there is a block for interface-status in the info,
  135. // and insert the default block if none is found.
  136. //
  137. if (spInfoBase->BlockExists(IPX_INTERFACE_INFO_TYPE) == hrFalse)
  138. {
  139. IPX_IF_INFO ipx;
  140. ipx.AdminState = ADMIN_STATE_ENABLED;
  141. ipx.NetbiosAccept = ADMIN_STATE_DISABLED;
  142. ipx.NetbiosDeliver = ADMIN_STATE_DISABLED;
  143. CORg( spInfoBase->AddBlock(IPX_INTERFACE_INFO_TYPE,
  144. sizeof(ipx),
  145. (PBYTE) &ipx,
  146. 1 /* count */,
  147. FALSE /* bRemoveFirst */) );
  148. }
  149. //
  150. // Check that there is a block for WAN interface-status in the info,
  151. // and insert the default block if none is found.
  152. //
  153. if (spInfoBase->BlockExists(IPXWAN_INTERFACE_INFO_TYPE) == hrFalse)
  154. {
  155. IPXWAN_IF_INFO ipxwan;
  156. ipxwan.AdminState = ADMIN_STATE_DISABLED;
  157. CORg( spInfoBase->AddBlock(IPXWAN_INTERFACE_INFO_TYPE,
  158. sizeof(ipxwan),
  159. (PBYTE) &ipxwan,
  160. 1 /* count */,
  161. FALSE /* bRemoveFirst */) );
  162. }
  163. m_spInfoBase = spInfoBase.Transfer();
  164. Error:
  165. return hr;
  166. }
  167. /*!--------------------------------------------------------------------------
  168. IpxNBInterfaceProperties::GetInfoBase
  169. -
  170. Author: KennT
  171. ---------------------------------------------------------------------------*/
  172. HRESULT IpxNBInterfaceProperties::GetInfoBase(IInfoBase **ppInfoBase)
  173. {
  174. Assert(ppInfoBase);
  175. *ppInfoBase = m_spInfoBase;
  176. m_spInfoBase->AddRef();
  177. return hrOK;
  178. }
  179. BOOL IpxNBInterfaceProperties::SaveSheetData()
  180. {
  181. SPITFSNodeHandler spHandler;
  182. SPITFSNode spParent;
  183. // By this time each page should have written its information out
  184. // to the infobase
  185. if (m_spInfoBase)
  186. {
  187. if (m_bClientInfoBase)
  188. {
  189. Assert(m_spRm);
  190. m_spRm->Save(m_spRm->GetMachineName(), 0, 0, NULL,
  191. m_spInfoBase, 0);
  192. }
  193. else
  194. {
  195. Assert(m_spRmIf);
  196. m_spRmIf->Save(m_spIf->GetMachineName(),
  197. NULL, NULL, NULL, m_spInfoBase, 0);
  198. }
  199. }
  200. // Force the node to do a resync
  201. m_spNode->GetParent(&spParent);
  202. spParent->GetHandler(&spHandler);
  203. spHandler->OnCommand(spParent, IDS_MENU_SYNC, CCT_RESULT,
  204. NULL, 0);
  205. return TRUE;
  206. }
  207. /*!--------------------------------------------------------------------------
  208. IpxNBInterfaceProperties::CancelSheetData
  209. -
  210. Author: KennT
  211. ---------------------------------------------------------------------------*/
  212. void IpxNBInterfaceProperties::CancelSheetData()
  213. {
  214. }
  215. /*---------------------------------------------------------------------------
  216. IpxNBIfPageGeneral
  217. ---------------------------------------------------------------------------*/
  218. IpxNBIfPageGeneral::~IpxNBIfPageGeneral()
  219. {
  220. if (m_pIPXConn)
  221. {
  222. m_pIPXConn->Release();
  223. m_pIPXConn = NULL;
  224. }
  225. }
  226. BEGIN_MESSAGE_MAP(IpxNBIfPageGeneral, RtrPropertyPage)
  227. //{{AFX_MSG_MAP(IpxNBIfPageGeneral)
  228. ON_BN_CLICKED(IDC_NIG_BTN_ACCEPT, OnChangeButton)
  229. ON_BN_CLICKED(IDC_NIG_BTN_DELIVER_ALWAYS, OnChangeButton)
  230. ON_BN_CLICKED(IDC_NIG_BTN_DELIVER_NEVER, OnChangeButton)
  231. ON_BN_CLICKED(IDC_NIG_BTN_DELIVER_STATIC, OnChangeButton)
  232. ON_BN_CLICKED(IDC_NIG_BTN_DELIVER_WHEN_UP, OnChangeButton)
  233. //}}AFX_MSG_MAP
  234. END_MESSAGE_MAP()
  235. void IpxNBIfPageGeneral::OnChangeButton()
  236. {
  237. SetDirty(TRUE);
  238. SetModified();
  239. }
  240. /*!--------------------------------------------------------------------------
  241. IpxNBIfPageGeneral::Init
  242. -
  243. Author: KennT
  244. ---------------------------------------------------------------------------*/
  245. HRESULT IpxNBIfPageGeneral::Init(IInterfaceInfo *pIfInfo,
  246. IPXConnection *pIPXConn,
  247. IpxNBInterfaceProperties *pPropSheet)
  248. {
  249. m_spIf.Set(pIfInfo);
  250. m_pIPXConn = pIPXConn;
  251. pIPXConn->AddRef();
  252. m_pIPXPropSheet = pPropSheet;
  253. return hrOK;
  254. }
  255. /*!--------------------------------------------------------------------------
  256. IpxNBIfPageGeneral::OnInitDialog
  257. -
  258. Author: KennT
  259. ---------------------------------------------------------------------------*/
  260. BOOL IpxNBIfPageGeneral::OnInitDialog()
  261. {
  262. HRESULT hr = hrOK;
  263. PBYTE pData;
  264. SPIInfoBase spInfoBase;
  265. IPX_IF_INFO * pIpxIf = NULL;
  266. IPXWAN_IF_INFO *pIpxWanIf = NULL;
  267. DWORD dwIfType;
  268. UINT iButton;
  269. RtrPropertyPage::OnInitDialog();
  270. //
  271. // The page is now initialized. Load the current configuration
  272. // for the interface being configured, and display its settings.
  273. //
  274. // Get the infobase from the property sheet.
  275. //
  276. CORg( m_pIPXPropSheet->GetInfoBase(&spInfoBase) );
  277. //
  278. // Retrieve the interface-status block configured
  279. //
  280. CORg( spInfoBase->GetData(IPX_INTERFACE_INFO_TYPE, 0, (BYTE **) &pIpxIf) );
  281. CheckDlgButton(IDC_NIG_BTN_ACCEPT, pIpxIf->NetbiosAccept == ADMIN_STATE_ENABLED);
  282. switch (pIpxIf->NetbiosDeliver)
  283. {
  284. case ADMIN_STATE_ENABLED:
  285. iButton = IDC_NIG_BTN_DELIVER_ALWAYS;
  286. break;
  287. case ADMIN_STATE_DISABLED:
  288. iButton = IDC_NIG_BTN_DELIVER_NEVER;
  289. break;
  290. case ADMIN_STATE_ENABLED_ONLY_FOR_NETBIOS_STATIC_ROUTING:
  291. iButton = IDC_NIG_BTN_DELIVER_STATIC;
  292. break;
  293. case ADMIN_STATE_ENABLED_ONLY_FOR_OPER_STATE_UP:
  294. iButton = IDC_NIG_BTN_DELIVER_WHEN_UP;
  295. break;
  296. default:
  297. Panic1("Unknown NetbiosDeliver state: %d", pIpxIf->NetbiosDeliver);
  298. iButton = -1;
  299. break;
  300. }
  301. if (iButton != -1)
  302. CheckDlgButton(iButton, ENABLED);
  303. SetDirty(FALSE);
  304. Error:
  305. if (!FHrSucceeded(hr))
  306. Cancel();
  307. return FHrSucceeded(hr) ? TRUE : FALSE;
  308. }
  309. /*!--------------------------------------------------------------------------
  310. IpxNBIfPageGeneral::DoDataExchange
  311. -
  312. Author: KennT
  313. ---------------------------------------------------------------------------*/
  314. void IpxNBIfPageGeneral::DoDataExchange(CDataExchange *pDX)
  315. {
  316. RtrPropertyPage::DoDataExchange(pDX);
  317. //{{AFX_DATA_MAP(IpxNBIfPageGeneral)
  318. //}}AFX_DATA_MAP
  319. }
  320. BOOL IpxNBIfPageGeneral::OnApply()
  321. {
  322. INT i;
  323. SPIInfoBase spInfoBase;
  324. IPX_IF_INFO * pIpxIf = NULL;
  325. IPXWAN_IF_INFO *pIpxWanIf = NULL;
  326. BOOL fReturn;
  327. HRESULT hr = hrOK;
  328. DWORD dwIfType;
  329. if ( m_pIPXPropSheet->IsCancel() )
  330. {
  331. CancelApply();
  332. return TRUE;
  333. }
  334. //
  335. // Retrieve the interface-status block configured
  336. //
  337. m_pIPXPropSheet->GetInfoBase(&spInfoBase);
  338. CORg( spInfoBase->GetData(IPX_INTERFACE_INFO_TYPE, 0, (BYTE **) &pIpxIf) );
  339. pIpxIf->NetbiosAccept = IsDlgButtonChecked(IDC_NIG_BTN_ACCEPT) ?
  340. ADMIN_STATE_ENABLED : ADMIN_STATE_DISABLED;
  341. if (IsDlgButtonChecked(IDC_NIG_BTN_DELIVER_ALWAYS))
  342. pIpxIf->NetbiosDeliver = ADMIN_STATE_ENABLED;
  343. else if (IsDlgButtonChecked(IDC_NIG_BTN_DELIVER_NEVER))
  344. pIpxIf->NetbiosDeliver = ADMIN_STATE_DISABLED;
  345. else if (IsDlgButtonChecked(IDC_NIG_BTN_DELIVER_STATIC))
  346. pIpxIf->NetbiosDeliver = ADMIN_STATE_ENABLED_ONLY_FOR_NETBIOS_STATIC_ROUTING;
  347. else if (IsDlgButtonChecked(IDC_NIG_BTN_DELIVER_WHEN_UP))
  348. pIpxIf->NetbiosDeliver = ADMIN_STATE_ENABLED_ONLY_FOR_OPER_STATE_UP;
  349. else
  350. {
  351. Panic0("A radio button in IPX NetBIOS Broadcasts interface config is not checked!");
  352. }
  353. fReturn = RtrPropertyPage::OnApply();
  354. Error:
  355. return fReturn;
  356. }