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.

281 lines
8.2 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 2000 **/
  4. /**********************************************************************/
  5. /*
  6. ipsmsnap.cpp
  7. IPSecMon 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 "initguid.h"
  15. #include "ncglobal.h" // network console global defines
  16. #include "cmptrmgr.h" // computer menagement snapin stuff
  17. #include "winipsec.h"
  18. #include "spdutil.h"
  19. #ifdef _DEBUG
  20. void DbgVerifyInstanceCounts();
  21. #define DEBUG_VERIFY_INSTANCE_COUNTS DbgVerifyInstanceCounts()
  22. #else
  23. #define DEBUG_VERIFY_INSTANCE_COUNTS
  24. #endif
  25. const TCHAR c_szHelpFile[] = _T("ipsecsnp.hlp");
  26. CComModule _Module;
  27. BEGIN_OBJECT_MAP(ObjectMap)
  28. OBJECT_ENTRY(CLSID_IpsmSnapin, CIpsmComponentDataPrimary)
  29. OBJECT_ENTRY(CLSID_IpsmSnapinExtension, CIpsmComponentDataExtension)
  30. OBJECT_ENTRY(CLSID_IpsmSnapinAbout, CIpsmAbout)
  31. END_OBJECT_MAP()
  32. #ifdef _DEBUG
  33. #define new DEBUG_NEW
  34. #undef THIS_FILE
  35. static char THIS_FILE[] = __FILE__;
  36. #endif
  37. //
  38. // CIpsmSnapinApp
  39. //
  40. BEGIN_MESSAGE_MAP(CIpsmSnapinApp, CWinApp)
  41. //{{AFX_MSG_MAP(CIpsmSnapinApp)
  42. //ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  43. //}}AFX_MSG_MAP
  44. // Standard file based document commands
  45. //ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  46. //ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  47. // Standard print setup command
  48. //ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  49. // Global help commands
  50. ON_COMMAND(ID_HELP_INDEX, CWinApp::OnHelpFinder)
  51. ON_COMMAND(ID_HELP_USING, CWinApp::OnHelpUsing)
  52. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  53. ON_COMMAND(ID_CONTEXT_HELP, CWinApp::OnContextHelp)
  54. ON_COMMAND(ID_DEFAULT_HELP, CWinApp::OnHelpIndex)
  55. END_MESSAGE_MAP()
  56. CIpsmSnapinApp theApp;
  57. BOOL CIpsmSnapinApp::InitInstance()
  58. {
  59. _Module.Init(ObjectMap, m_hInstance);
  60. //
  61. // Initialize the CWndIpAddress control window class IPADDRESS
  62. //
  63. CWndIpAddress::CreateWindowClass( m_hInstance ) ;
  64. //
  65. // Initialize use of the WinSock routines
  66. //
  67. WSADATA wsaData ;
  68. if ( ::WSAStartup( MAKEWORD( 1, 1 ), & wsaData ) != 0 )
  69. {
  70. m_bWinsockInited = TRUE;
  71. Trace0("InitInstance: Winsock initialized!\n");
  72. }
  73. else
  74. {
  75. m_bWinsockInited = FALSE;
  76. }
  77. if (m_pszHelpFilePath)
  78. free((void*)m_pszHelpFilePath);
  79. m_pszHelpFilePath=_tcsdup(c_szHelpFile);
  80. return CWinApp::InitInstance();
  81. }
  82. int CIpsmSnapinApp::ExitInstance()
  83. {
  84. _Module.Term();
  85. DEBUG_VERIFY_INSTANCE_COUNTS;
  86. //
  87. // Terminate use of the WinSock routines.
  88. //
  89. if ( m_bWinsockInited )
  90. {
  91. WSACleanup() ;
  92. }
  93. return CWinApp::ExitInstance();
  94. }
  95. /////////////////////////////////////////////////////////////////////////////
  96. // Used to determine whether the DLL can be unloaded by OLE
  97. STDAPI DllCanUnloadNow(void)
  98. {
  99. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  100. return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  101. }
  102. /////////////////////////////////////////////////////////////////////////////
  103. // Returns a class factory to create an object of the requested type
  104. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  105. {
  106. return _Module.GetClassObject(rclsid, riid, ppv);
  107. }
  108. /////////////////////////////////////////////////////////////////////////////
  109. // DllRegisterServer - Adds entries to the system registry
  110. STDAPI DllRegisterServer(void)
  111. {
  112. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  113. TCHAR szModuleFileName[MAX_PATH * 2 + 1] = {0};
  114. BOOL fGotModuleName = TRUE;
  115. fGotModuleName = (0 != ::GetModuleFileName(_Module.GetModuleInstance(),
  116. szModuleFileName,
  117. DimensionOf(szModuleFileName)));
  118. //
  119. // registers object, typelib and all interfaces in typelib
  120. //
  121. HRESULT hr = _Module.RegisterServer(/* bRegTypeLib */ FALSE);
  122. ASSERT(SUCCEEDED(hr));
  123. if (FAILED(hr))
  124. return hr;
  125. CString stName;
  126. CString stNameStringIndirect;
  127. stName.LoadString(IDS_SNAPIN_NAME);
  128. stNameStringIndirect.Format(L"@%s,-%-d", szModuleFileName, IDS_SNAPIN_DESC);
  129. //
  130. // register the snapin into the console snapin list
  131. //
  132. hr = RegisterSnapinGUID(&CLSID_IpsmSnapin,
  133. &GUID_IpsmRootNodeType,
  134. &CLSID_IpsmSnapinAbout,
  135. (LPCTSTR) stName,
  136. _T("1.0"),
  137. TRUE,
  138. fGotModuleName ? (LPCTSTR)stNameStringIndirect : NULL);
  139. ASSERT(SUCCEEDED(hr));
  140. if (FAILED(hr))
  141. return hr;
  142. CString stExtensionName;
  143. CString stExtensionNameIndirect;
  144. stExtensionName.LoadString(IDS_SNAPIN_EXTENSION);
  145. stExtensionNameIndirect.Format(L"@%s,-%-d", szModuleFileName, IDS_SNAPIN_EXTENSION);
  146. hr = RegisterSnapinGUID(&CLSID_IpsmSnapinExtension,
  147. NULL,
  148. &CLSID_IpsmSnapinAbout,
  149. (LPCTSTR) stExtensionName,
  150. _T("1.0"),
  151. FALSE,
  152. fGotModuleName ? (LPCTSTR)stExtensionNameIndirect : NULL);
  153. ASSERT(SUCCEEDED(hr));
  154. if (FAILED(hr))
  155. return hr;
  156. //
  157. // register the snapin nodes into the console node list
  158. //
  159. hr = RegisterNodeTypeGUID(&CLSID_IpsmSnapin,
  160. &GUID_IpsmRootNodeType,
  161. _T("Root of Manager"));
  162. ASSERT(SUCCEEDED(hr));
  163. #ifdef __NETWORK_CONSOLE__
  164. hr = RegisterAsRequiredExtensionGUID(&GUID_NetConsRootNodeType,
  165. &CLSID_IpsmSnapinExtension,
  166. (LPCTSTR) stExtensionName,
  167. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE,
  168. &GUID_NetConsRootNodeType); // doesn't matter what this is, just
  169. // needs to be non-null guid
  170. ASSERT(SUCCEEDED(hr));
  171. #endif
  172. hr = RegisterAsRequiredExtensionGUID(&NODETYPE_COMPUTERMANAGEMENT_SERVERAPPS,
  173. &CLSID_IpsmSnapinExtension,
  174. (LPCTSTR) stExtensionName,
  175. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE,
  176. &NODETYPE_COMPUTERMANAGEMENT_SERVERAPPS); // NULL makes it not dynamic
  177. ASSERT(SUCCEEDED(hr));
  178. return hr;
  179. }
  180. /////////////////////////////////////////////////////////////////////////////
  181. // DllUnregisterServer - Removes entries from the system registry
  182. STDAPI DllUnregisterServer(void)
  183. {
  184. HRESULT hr = _Module.UnregisterServer();
  185. ASSERT(SUCCEEDED(hr));
  186. if (FAILED(hr))
  187. return hr;
  188. // un register the snapin
  189. //
  190. hr = UnregisterSnapinGUID(&CLSID_IpsmSnapin);
  191. ASSERT(SUCCEEDED(hr));
  192. if (FAILED(hr))
  193. return hr;
  194. hr = UnregisterSnapinGUID(&CLSID_IpsmSnapinExtension);
  195. ASSERT(SUCCEEDED(hr));
  196. if (FAILED(hr))
  197. return hr;
  198. // unregister the snapin nodes
  199. //
  200. hr = UnregisterNodeTypeGUID(&GUID_IpsmRootNodeType);
  201. ASSERT(SUCCEEDED(hr));
  202. #ifdef __NETWORK_CONSOLE__
  203. hr = UnregisterAsExtensionGUID(&GUID_NetConsRootNodeType,
  204. &CLSID_IpsmSnapinExtension,
  205. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE);
  206. ASSERT(SUCCEEDED(hr));
  207. #endif
  208. hr = UnregisterAsExtensionGUID(&NODETYPE_COMPUTERMANAGEMENT_SERVERAPPS,
  209. &CLSID_IpsmSnapinExtension,
  210. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE);
  211. ASSERT(SUCCEEDED(hr));
  212. return hr;
  213. }
  214. #ifdef _DEBUG
  215. void DbgVerifyInstanceCounts()
  216. {
  217. DEBUG_VERIFY_INSTANCE_COUNT(CHandler);
  218. DEBUG_VERIFY_INSTANCE_COUNT(CMTHandler);
  219. DEBUG_VERIFY_INSTANCE_COUNT(CSpdInfo);
  220. }
  221. #endif // _DEBUG