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.

444 lines
14 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. rtrsnap.cpp
  7. Snapin entry points/registration functions
  8. Note: Proxy/Stub Information
  9. To build a separate proxy/stub DLL,
  10. run nmake -f Snapinps.mak in the project directory.
  11. FILE HISTORY:
  12. */
  13. #include "stdafx.h"
  14. #include <advpub.h> // For REGINSTALL
  15. #include "dmvcomp.h"
  16. #include "register.h"
  17. #include "rtrguid.h"
  18. #include "atlkcomp.h"
  19. #include "radcfg.h" // for RouterAuthRadiusConfig
  20. #include "qryfrm.h"
  21. #include "ncglobal.h" // network console global defines
  22. #include "cmptrmgr.h" // computer management snapin node types
  23. #include "rtrutilp.h"
  24. #include "dialog.h"
  25. #ifdef _DEBUG
  26. void DbgVerifyInstanceCounts();
  27. #define DEBUG_VERIFY_INSTANCE_COUNTS DbgVerifyInstanceCounts()
  28. #else
  29. #define DEBUG_VERIFY_INSTANCE_COUNTS
  30. #endif
  31. CComModule _Module;
  32. BEGIN_OBJECT_MAP(ObjectMap)
  33. OBJECT_ENTRY(CLSID_ATLKAdminExtension, CATLKComponentData)
  34. OBJECT_ENTRY(CLSID_ATLKAdminAbout, CATLKAbout)
  35. OBJECT_ENTRY(CLSID_RouterSnapin, CDomainViewSnap)
  36. OBJECT_ENTRY(CLSID_RouterSnapinExtension, CDomainViewSnapExtension)
  37. OBJECT_ENTRY(CLSID_RouterSnapinAbout, CDomainViewSnapAbout)
  38. OBJECT_ENTRY(CLSID_RouterAuthRADIUS, RouterAuthRadiusConfig)
  39. OBJECT_ENTRY(CLSID_RouterAcctRADIUS, RouterAcctRadiusConfig)
  40. OBJECT_ENTRY(CLSID_RRASQueryForm, CRRASQueryForm)
  41. END_OBJECT_MAP()
  42. #ifdef _DEBUG
  43. #define new DEBUG_NEW
  44. #undef THIS_FILE
  45. static char THIS_FILE[] = __FILE__;
  46. #endif
  47. /*---------------------------------------------------------------------------
  48. This is a list of nodetypes that need to be registered.
  49. ---------------------------------------------------------------------------*/
  50. struct RegisteredNodeTypes
  51. {
  52. const GUID *m_pGuid;
  53. LPCTSTR m_pszName;
  54. };
  55. const static RegisteredNodeTypes s_rgNodeTypes[] =
  56. {
  57. { &GUID_RouterDomainNodeType, _T("Root of Router Domain Snapin") },
  58. { &GUID_RouterIfAdminNodeType, _T("Routing Interfaces") },
  59. { &GUID_RouterMachineErrorNodeType, _T("Router - Error") },
  60. { &GUID_RouterMachineNodeType, _T("Router Machine - General (7)") },
  61. { &GUID_RouterDialInNodeType, _T("Routing dial-in users") },
  62. { &GUID_RouterPortsNodeType, _T("Ports") },
  63. };
  64. class CRouterSnapinApp : public CWinApp
  65. {
  66. public:
  67. virtual BOOL InitInstance();
  68. virtual int ExitInstance();
  69. };
  70. CRouterSnapinApp theApp;
  71. BOOL CRouterSnapinApp::InitInstance()
  72. {
  73. TCHAR tszHelpFilePath[MAX_PATH+1]={0};
  74. _Module.Init(ObjectMap, m_hInstance);
  75. InitializeTFSError();
  76. CreateTFSErrorInfo(0);
  77. // Setup the global help function
  78. extern DWORD * MprSnapHelpMap(DWORD dwIDD);
  79. SetGlobalHelpMapFunction(MprSnapHelpMap);
  80. IPAddrInit(m_hInstance);
  81. //Set the help file path
  82. free((void*)m_pszHelpFilePath);
  83. GetWindowsDirectory(tszHelpFilePath, MAX_PATH);
  84. _tcscat(tszHelpFilePath, TEXT("\\help\\mprsnap.hlp"));
  85. m_pszHelpFilePath = _tcsdup(tszHelpFilePath);
  86. return CWinApp::InitInstance();
  87. }
  88. int CRouterSnapinApp::ExitInstance()
  89. {
  90. RemoveAllNetConnections();
  91. _Module.Term();
  92. DestroyTFSErrorInfo(0);
  93. CleanupTFSError();
  94. DEBUG_VERIFY_INSTANCE_COUNTS;
  95. return CWinApp::ExitInstance();
  96. }
  97. /////////////////////////////////////////////////////////////////////////////
  98. // Used to determine whether the DLL can be unloaded by OLE
  99. STDAPI DllCanUnloadNow(void)
  100. {
  101. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  102. return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  103. }
  104. const static GUID * s_pExtensionGuids[] =
  105. {
  106. &GUID_RouterMachineNodeType,
  107. };
  108. /////////////////////////////////////////////////////////////////////////////
  109. // Returns a class factory to create an object of the requested type
  110. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  111. {
  112. return _Module.GetClassObject(rclsid, riid, ppv);
  113. }
  114. HRESULT CallRegInstall(LPSTR szSection);
  115. /////////////////////////////////////////////////////////////////////////////
  116. // DllRegisterServer - Adds entries to the system registry
  117. STDAPI DllRegisterServer(void)
  118. {
  119. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  120. HRESULT hr = hrOK;
  121. CString stDisplayName, stAtlkDisplayName, stNameStringIndirect;
  122. TCHAR moduleFileName[MAX_PATH * 2];
  123. GetModuleFileNameOnly(_Module.GetModuleInstance(), moduleFileName, MAX_PATH * 2);
  124. int i;
  125. // registers object, typelib and all interfaces in typelib
  126. //
  127. hr = _Module.RegisterServer(/* bRegTypeLib */ FALSE);
  128. Assert(SUCCEEDED(hr));
  129. CORg( hr );
  130. // Load the name of the router snapins
  131. stDisplayName.LoadString(IDS_SNAPIN_DISPLAY_NAME);
  132. stAtlkDisplayName.LoadString(IDS_ATLK_DISPLAY_NAME);
  133. stNameStringIndirect.Format(L"@%s,-%-d", moduleFileName, IDS_SNAPIN_DISPLAY_NAME);
  134. // register the snapin into the console snapin list
  135. // ~domain view snapin
  136. CORg( RegisterSnapinGUID(&CLSID_RouterSnapin,
  137. NULL,
  138. &CLSID_RouterSnapinAbout,
  139. stDisplayName,
  140. _T("1.0"),
  141. TRUE,
  142. stNameStringIndirect
  143. ) );
  144. CORg( RegisterSnapinGUID(&CLSID_RouterSnapinExtension,
  145. NULL,
  146. &CLSID_RouterSnapinAbout,
  147. stDisplayName,
  148. _T("1.0"),
  149. FALSE,
  150. stNameStringIndirect));
  151. stNameStringIndirect.Format(L"@%s,-%-d", moduleFileName, IDS_ATLK_DISPLAY_NAME);
  152. CORg( RegisterSnapinGUID(&CLSID_ATLKAdminExtension,
  153. NULL,
  154. &CLSID_ATLKAdminAbout,
  155. stAtlkDisplayName,
  156. _T("1.0"),
  157. FALSE,
  158. stNameStringIndirect) );
  159. // register the snapin nodes into the console node list
  160. //
  161. for (i=0; i<DimensionOf(s_rgNodeTypes); i++)
  162. {
  163. CORg( RegisterNodeTypeGUID(&CLSID_RouterSnapin,
  164. s_rgNodeTypes[i].m_pGuid,
  165. s_rgNodeTypes[i].m_pszName) );
  166. }
  167. // register apple talk as extension of machine
  168. for (i=0; i<DimensionOf(s_pExtensionGuids); i++)
  169. {
  170. CORg( RegisterAsRequiredExtensionGUID(s_pExtensionGuids[i],
  171. &CLSID_ATLKAdminExtension,
  172. stAtlkDisplayName,
  173. EXTENSION_TYPE_NAMESPACE,
  174. &CLSID_RouterSnapin) );
  175. }
  176. #ifdef __NETWORK_CONSOLE__
  177. // register as extension of network console
  178. CORg( RegisterAsRequiredExtensionGUID(&GUID_NetConsRootNodeType,
  179. &CLSID_RouterSnapinExtension,
  180. stDisplayName,
  181. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE,
  182. &GUID_NetConsRootNodeType)); // doesn't matter what this is, just
  183. // needs to be non-null guid
  184. #endif
  185. // register as extension of computer management
  186. CORg( RegisterAsRequiredExtensionGUID(&NODETYPE_COMPUTERMANAGEMENT_SERVERAPPS,
  187. &CLSID_RouterSnapinExtension,
  188. stDisplayName,
  189. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE,
  190. &NODETYPE_COMPUTERMANAGEMENT_SERVERAPPS));
  191. // Register DS Query Forms -- WeiJiang 1-29-98
  192. CORg(CallRegInstall("RegDll"));
  193. // End of DS Query
  194. Error:
  195. if (!FHrSucceeded(hr))
  196. {
  197. // Now we need to get the error object and display it
  198. if (!FHrSucceeded(DisplayTFSErrorMessage(NULL)))
  199. {
  200. TCHAR szBuffer[1024];
  201. // Couldn't find a TFS error, bring up a general
  202. // error message
  203. FormatError(hr, szBuffer, DimensionOf(szBuffer));
  204. AfxMessageBox(szBuffer);
  205. }
  206. }
  207. return hr;
  208. }
  209. /////////////////////////////////////////////////////////////////////////////
  210. // DllUnregisterServer - Removes entries from the system registry
  211. STDAPI DllUnregisterServer(void)
  212. {
  213. int i;
  214. HRESULT hr = hrOK;
  215. // Initialize the error handling system
  216. InitializeTFSError();
  217. // Create an error object for this thread
  218. Verify( CreateTFSErrorInfo(0) == hrOK );
  219. hr = _Module.UnregisterServer();
  220. Assert(SUCCEEDED(hr));
  221. CORg( hr );
  222. // un register the snapin
  223. //
  224. // We don't care about the error return for this
  225. UnregisterSnapinGUID(&CLSID_OldRouterSnapin);
  226. // Domain View Snapin -- weijiang 1-14-98
  227. hr = UnregisterSnapinGUID(&CLSID_RouterSnapin);
  228. Assert(SUCCEEDED(hr));
  229. // ~Domain View Snapin
  230. // Unregister the nodes that Appletalk extends
  231. for (i=0; i<DimensionOf(s_pExtensionGuids); i++)
  232. {
  233. hr = UnregisterAsRequiredExtensionGUID(s_pExtensionGuids[i],
  234. &CLSID_ATLKAdminExtension,
  235. EXTENSION_TYPE_NAMESPACE,
  236. &CLSID_RouterSnapin);
  237. Assert(SUCCEEDED(hr));
  238. }
  239. // Unregister the appletalk extension snapin
  240. // -----------------------------------------------------------------
  241. hr = UnregisterSnapinGUID(&CLSID_ATLKAdminExtension);
  242. Assert(SUCCEEDED(hr));
  243. // Unregister the router snapin extension snapin
  244. // -----------------------------------------------------------------
  245. hr = UnregisterSnapinGUID(&CLSID_RouterSnapinExtension);
  246. Assert(SUCCEEDED(hr));
  247. // unregister the snapin nodes
  248. // -----------------------------------------------------------------
  249. for (i=0; i<DimensionOf(s_rgNodeTypes); i++)
  250. {
  251. hr = UnregisterNodeTypeGUID(s_rgNodeTypes[i].m_pGuid);
  252. Assert(SUCCEEDED(hr));
  253. }
  254. // computer manangement
  255. hr = UnregisterAsExtensionGUID(&NODETYPE_COMPUTERMANAGEMENT_SERVERAPPS,
  256. &CLSID_RouterSnapinExtension,
  257. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE);
  258. ASSERT(SUCCEEDED(hr));
  259. // Unregister DS Query Form -- WeiJiang 1-29-98
  260. hr = CallRegInstall("UnRegDll");
  261. Assert(SUCCEEDED(hr));
  262. // End of DS Query FOrm
  263. Error:
  264. if (!FHrSucceeded(hr))
  265. {
  266. // Now we need to get the error object and display it
  267. if (!FHrSucceeded(DisplayTFSErrorMessage(NULL)))
  268. {
  269. TCHAR szBuffer[1024];
  270. // Couldn't find a TFS error, bring up a general
  271. // error message
  272. FormatError(hr, szBuffer, DimensionOf(szBuffer));
  273. AfxMessageBox(szBuffer);
  274. }
  275. }
  276. // Destroy the TFS error information for this thread
  277. DestroyTFSErrorInfo(0);
  278. // Cleanup the entire error system
  279. CleanupTFSError();
  280. return hr;
  281. }
  282. /*-----------------------------------------------------------------------------
  283. / CallRegInstall
  284. / --------------
  285. / Call ADVPACK for the given section of our resource based INF>
  286. /
  287. / In:
  288. / szSection = section name to invoke
  289. /
  290. / Out:
  291. / HRESULT:
  292. /----------------------------------------------------------------------------*/
  293. HRESULT CallRegInstall(LPSTR szSection)
  294. {
  295. HRESULT hr = E_FAIL;
  296. HINSTANCE hinstAdvPack = LoadLibrary(TEXT("ADVPACK.DLL"));
  297. if (hinstAdvPack)
  298. {
  299. REGINSTALL pfnri = (REGINSTALL)GetProcAddress(hinstAdvPack, "RegInstall");
  300. #ifdef UNICODE
  301. if ( pfnri )
  302. {
  303. STRENTRY seReg[] =
  304. {
  305. // These two NT-specific entries must be at the end
  306. { "25", "%SystemRoot%" },
  307. { "11", "%SystemRoot%\\system32" },
  308. };
  309. STRTABLE stReg = { ARRAYSIZE(seReg), seReg };
  310. hr = pfnri(_Module.m_hInst, szSection, &stReg);
  311. }
  312. #else
  313. if (pfnri)
  314. {
  315. hr = pfnri(_Module.m_hInst, szSection, NULL);
  316. }
  317. #endif
  318. FreeLibrary(hinstAdvPack);
  319. }
  320. return hr;
  321. }
  322. #ifdef _DEBUG
  323. void DbgVerifyInstanceCounts()
  324. {
  325. extern void TFSCore_DbgVerifyInstanceCounts();
  326. TFSCore_DbgVerifyInstanceCounts();
  327. DEBUG_VERIFY_INSTANCE_COUNT(MachineNodeData);
  328. DEBUG_VERIFY_INSTANCE_COUNT(InfoBase);
  329. DEBUG_VERIFY_INSTANCE_COUNT(InfoBlockEnumerator);
  330. DEBUG_VERIFY_INSTANCE_COUNT(RouterInfo);
  331. DEBUG_VERIFY_INSTANCE_COUNT(RtrMgrInfo);
  332. DEBUG_VERIFY_INSTANCE_COUNT(RtrMgrProtocolInfo);
  333. DEBUG_VERIFY_INSTANCE_COUNT(InterfaceInfo);
  334. DEBUG_VERIFY_INSTANCE_COUNT(RtrMgrInterfaceInfo);
  335. DEBUG_VERIFY_INSTANCE_COUNT(RtrMgrProtocolInterfaceInfo);
  336. DEBUG_VERIFY_INSTANCE_COUNT(EnumRtrMgrCB);
  337. DEBUG_VERIFY_INSTANCE_COUNT(EnumRtrMgrProtocolCB);
  338. DEBUG_VERIFY_INSTANCE_COUNT(EnumInterfaceCB);
  339. DEBUG_VERIFY_INSTANCE_COUNT(EnumRtrMgrInterfaceCB);
  340. DEBUG_VERIFY_INSTANCE_COUNT(EnumRtrMgrProtocolInterfaceCB);
  341. DEBUG_VERIFY_INSTANCE_COUNT(InterfaceNodeHandler);
  342. DEBUG_VERIFY_INSTANCE_COUNT(MachineHandler);
  343. DEBUG_VERIFY_INSTANCE_COUNT(RouterInfoAggregationWrapper);
  344. DEBUG_VERIFY_INSTANCE_COUNT(InterfaceInfoAggregationWrapper);
  345. DEBUG_VERIFY_INSTANCE_COUNT(RtrMgrInfoAggregationWrapper);
  346. DEBUG_VERIFY_INSTANCE_COUNT(RtrMgrProtocolInfoAggregationWrapper);
  347. DEBUG_VERIFY_INSTANCE_COUNT(RtrMgrProtocolInterfaceInfoAggregationWrapper);
  348. DEBUG_VERIFY_INSTANCE_COUNT(RouterRefreshObjectGroup);
  349. DEBUG_VERIFY_INSTANCE_COUNT(RefreshItem);
  350. }
  351. #endif // _DEBUG