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.

290 lines
8.7 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 2002 **/
  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. SHFusionInitializeFromModuleID (m_hInstance, 2);
  61. //
  62. // Initialize the CWndIpAddress control window class IPADDRESS
  63. //
  64. CWndIpAddress::CreateWindowClass( m_hInstance ) ;
  65. //
  66. // Initialize use of the WinSock routines
  67. //
  68. WSADATA wsaData ;
  69. if ( ::WSAStartup( MAKEWORD( 1, 1 ), & wsaData ) != 0 )
  70. {
  71. m_bWinsockInited = TRUE;
  72. Trace0("InitInstance: Winsock initialized!\n");
  73. }
  74. else
  75. {
  76. m_bWinsockInited = FALSE;
  77. }
  78. if (m_pszHelpFilePath)
  79. free((void*)m_pszHelpFilePath);
  80. m_pszHelpFilePath=_tcsdup(c_szHelpFile);
  81. return CWinApp::InitInstance();
  82. }
  83. int CIpsmSnapinApp::ExitInstance()
  84. {
  85. SHFusionUninitialize();
  86. _Module.Term();
  87. DEBUG_VERIFY_INSTANCE_COUNTS;
  88. //
  89. // Terminate use of the WinSock routines.
  90. //
  91. if ( m_bWinsockInited )
  92. {
  93. WSACleanup() ;
  94. }
  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. /////////////////////////////////////////////////////////////////////////////
  105. // Returns a class factory to create an object of the requested type
  106. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  107. {
  108. return _Module.GetClassObject(rclsid, riid, ppv);
  109. }
  110. /////////////////////////////////////////////////////////////////////////////
  111. // DllRegisterServer - Adds entries to the system registry
  112. STDAPI DllRegisterServer(void)
  113. {
  114. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  115. TCHAR szModuleFileName[MAX_PATH * 2 + 1] = {0};
  116. size_t uiModuleFileNameLength = 0;
  117. BOOL fGotModuleName = TRUE;
  118. uiModuleFileNameLength = ::GetModuleFileName(
  119. _Module.GetModuleInstance(),
  120. szModuleFileName,
  121. DimensionOf(szModuleFileName) - 1
  122. );
  123. szModuleFileName[uiModuleFileNameLength] = _TEXT('\0');
  124. fGotModuleName = (uiModuleFileNameLength != 0);
  125. //
  126. // registers object, typelib and all interfaces in typelib
  127. //
  128. HRESULT hr = _Module.RegisterServer(/* bRegTypeLib */ FALSE);
  129. ASSERT(SUCCEEDED(hr));
  130. if (FAILED(hr))
  131. return hr;
  132. CString stName;
  133. CString stNameStringIndirect;
  134. stName.LoadString(IDS_SNAPIN_NAME);
  135. stNameStringIndirect.Format(L"@%s,-%-d", szModuleFileName, IDS_SNAPIN_DESC);
  136. //
  137. // register the snapin into the console snapin list
  138. //
  139. hr = RegisterSnapinGUID(&CLSID_IpsmSnapin,
  140. &GUID_IpsmRootNodeType,
  141. &CLSID_IpsmSnapinAbout,
  142. (LPCTSTR) stName,
  143. _T("1.0"),
  144. TRUE,
  145. fGotModuleName ? (LPCTSTR)stNameStringIndirect : NULL);
  146. ASSERT(SUCCEEDED(hr));
  147. if (FAILED(hr))
  148. return hr;
  149. CString stExtensionName;
  150. CString stExtensionNameIndirect;
  151. stExtensionName.LoadString(IDS_SNAPIN_EXTENSION);
  152. stExtensionNameIndirect.Format(L"@%s,-%-d", szModuleFileName, IDS_SNAPIN_EXTENSION);
  153. hr = RegisterSnapinGUID(&CLSID_IpsmSnapinExtension,
  154. NULL,
  155. &CLSID_IpsmSnapinAbout,
  156. (LPCTSTR) stExtensionName,
  157. _T("1.0"),
  158. FALSE,
  159. fGotModuleName ? (LPCTSTR)stExtensionNameIndirect : NULL);
  160. ASSERT(SUCCEEDED(hr));
  161. if (FAILED(hr))
  162. return hr;
  163. //
  164. // register the snapin nodes into the console node list
  165. //
  166. hr = RegisterNodeTypeGUID(&CLSID_IpsmSnapin,
  167. &GUID_IpsmRootNodeType,
  168. _T("Root of Manager"));
  169. ASSERT(SUCCEEDED(hr));
  170. #ifdef __NETWORK_CONSOLE__
  171. hr = RegisterAsRequiredExtensionGUID(&GUID_NetConsRootNodeType,
  172. &CLSID_IpsmSnapinExtension,
  173. (LPCTSTR) stExtensionName,
  174. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE,
  175. &GUID_NetConsRootNodeType); // doesn't matter what this is, just
  176. // needs to be non-null guid
  177. ASSERT(SUCCEEDED(hr));
  178. #endif
  179. hr = RegisterAsRequiredExtensionGUID(&NODETYPE_COMPUTERMANAGEMENT_SERVERAPPS,
  180. &CLSID_IpsmSnapinExtension,
  181. (LPCTSTR) stExtensionName,
  182. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE,
  183. &NODETYPE_COMPUTERMANAGEMENT_SERVERAPPS); // NULL makes it not dynamic
  184. ASSERT(SUCCEEDED(hr));
  185. return hr;
  186. }
  187. /////////////////////////////////////////////////////////////////////////////
  188. // DllUnregisterServer - Removes entries from the system registry
  189. STDAPI DllUnregisterServer(void)
  190. {
  191. HRESULT hr = _Module.UnregisterServer();
  192. ASSERT(SUCCEEDED(hr));
  193. if (FAILED(hr))
  194. return hr;
  195. // un register the snapin
  196. //
  197. hr = UnregisterSnapinGUID(&CLSID_IpsmSnapin);
  198. ASSERT(SUCCEEDED(hr));
  199. if (FAILED(hr))
  200. return hr;
  201. hr = UnregisterSnapinGUID(&CLSID_IpsmSnapinExtension);
  202. ASSERT(SUCCEEDED(hr));
  203. if (FAILED(hr))
  204. return hr;
  205. // unregister the snapin nodes
  206. //
  207. hr = UnregisterNodeTypeGUID(&GUID_IpsmRootNodeType);
  208. ASSERT(SUCCEEDED(hr));
  209. #ifdef __NETWORK_CONSOLE__
  210. hr = UnregisterAsExtensionGUID(&GUID_NetConsRootNodeType,
  211. &CLSID_IpsmSnapinExtension,
  212. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE);
  213. ASSERT(SUCCEEDED(hr));
  214. #endif
  215. hr = UnregisterAsExtensionGUID(&NODETYPE_COMPUTERMANAGEMENT_SERVERAPPS,
  216. &CLSID_IpsmSnapinExtension,
  217. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE);
  218. ASSERT(SUCCEEDED(hr));
  219. return hr;
  220. }
  221. #ifdef _DEBUG
  222. void DbgVerifyInstanceCounts()
  223. {
  224. DEBUG_VERIFY_INSTANCE_COUNT(CHandler);
  225. DEBUG_VERIFY_INSTANCE_COUNT(CMTHandler);
  226. DEBUG_VERIFY_INSTANCE_COUNT(CSpdInfo);
  227. }
  228. #endif // _DEBUG