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.

283 lines
8.8 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. dhcpsnap.cpp
  7. DHCP 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 "dhcpcomp.h"
  16. #include "classed.h"
  17. #include "ncglobal.h" // network console global defines
  18. #include "cmptrmgr.h" // computer management snapin NODETYPE
  19. #include "ipaddr.h"
  20. #include "locale.h" // setlocall function call
  21. #include <ntverp.h>
  22. #ifdef _DEBUG
  23. void DbgVerifyInstanceCounts();
  24. #define DEBUG_VERIFY_INSTANCE_COUNTS DbgVerifyInstanceCounts()
  25. #else
  26. #define DEBUG_VERIFY_INSTANCE_COUNTS
  27. #endif
  28. CComModule _Module;
  29. BEGIN_OBJECT_MAP(ObjectMap)
  30. OBJECT_ENTRY(CLSID_DhcpSnapin, CDhcpComponentDataPrimary)
  31. OBJECT_ENTRY(CLSID_DhcpSnapinExtension, CDhcpComponentDataExtension)
  32. OBJECT_ENTRY(CLSID_DhcpSnapinAbout, CDhcpAbout)
  33. END_OBJECT_MAP()
  34. #ifdef _DEBUG
  35. #define new DEBUG_NEW
  36. #undef THIS_FILE
  37. static char THIS_FILE[] = __FILE__;
  38. #endif
  39. //
  40. // CDhcpSnapinApp
  41. //
  42. BEGIN_MESSAGE_MAP(CDhcpSnapinApp, CWinApp)
  43. //{{AFX_MSG_MAP(CDhcpSnapinApp)
  44. //ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  45. //}}AFX_MSG_MAP
  46. // Standard file based document commands
  47. //ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  48. //ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  49. // Standard print setup command
  50. //ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  51. // Global help commands
  52. ON_COMMAND(ID_HELP_INDEX, CWinApp::OnHelpFinder)
  53. ON_COMMAND(ID_HELP_USING, CWinApp::OnHelpUsing)
  54. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  55. ON_COMMAND(ID_CONTEXT_HELP, CWinApp::OnContextHelp)
  56. ON_COMMAND(ID_DEFAULT_HELP, CWinApp::OnHelpIndex)
  57. END_MESSAGE_MAP()
  58. CDhcpSnapinApp theApp;
  59. BOOL CDhcpSnapinApp::InitInstance()
  60. {
  61. _Module.Init(ObjectMap, m_hInstance);
  62. //
  63. // Initialize the CWndIpAddress control window class IPADDRESS
  64. //
  65. CWndIpAddress::CreateWindowClass( m_hInstance ) ;
  66. // register the window class for the hex editor (class ID)
  67. ::RegisterHexEditClass(m_hInstance);
  68. //
  69. // Initialize use of the WinSock routines
  70. //
  71. WSADATA wsaData ;
  72. if ( ::WSAStartup( MAKEWORD( 1, 1 ), & wsaData ) != 0 )
  73. {
  74. m_bWinsockInited = TRUE;
  75. Trace0("InitInstance: Winsock initialized!\n");
  76. }
  77. else
  78. {
  79. m_bWinsockInited = FALSE;
  80. }
  81. // set the default locale for the c runtime to system locale
  82. setlocale(LC_ALL, "");
  83. ::IPAddrInit(m_hInstance);
  84. return CWinApp::InitInstance();
  85. }
  86. int CDhcpSnapinApp::ExitInstance()
  87. {
  88. _Module.Term();
  89. DEBUG_VERIFY_INSTANCE_COUNTS;
  90. //
  91. // Terminate use of the WinSock routines.
  92. //
  93. if ( m_bWinsockInited )
  94. {
  95. WSACleanup() ;
  96. }
  97. return CWinApp::ExitInstance();
  98. }
  99. /////////////////////////////////////////////////////////////////////////////
  100. // Used to determine whether the DLL can be unloaded by OLE
  101. STDAPI DllCanUnloadNow(void)
  102. {
  103. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  104. return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  105. }
  106. /////////////////////////////////////////////////////////////////////////////
  107. // Returns a class factory to create an object of the requested type
  108. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  109. {
  110. return _Module.GetClassObject(rclsid, riid, ppv);
  111. }
  112. /////////////////////////////////////////////////////////////////////////////
  113. // DllRegisterServer - Adds entries to the system registry
  114. STDAPI DllRegisterServer(void)
  115. {
  116. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  117. //
  118. // registers object, typelib and all interfaces in typelib
  119. //
  120. HRESULT hr = _Module.RegisterServer(/* bRegTypeLib */ FALSE);
  121. ASSERT(SUCCEEDED(hr));
  122. if (FAILED(hr))
  123. return hr;
  124. CString strDesc, strExtDesc, strRootDesc, strVersion;
  125. CString strIndirect, strPrefix;
  126. strPrefix = L"@dhcpsnap.dll,-";
  127. strDesc.LoadString(IDS_SNAPIN_DESC);
  128. strExtDesc.LoadString(IDS_SNAPIN_EXTENSION_DESC);
  129. strRootDesc.LoadString(IDS_ROOT_DESC);
  130. strVersion = LVER_PRODUCTVERSION_STRING;
  131. //
  132. // register the snapin into the console snapin list
  133. // Register CLSID_DhcpSnapin as Standalone, so that it
  134. // shows up in the MMC available snapins list.
  135. //
  136. strIndirect.Format( L"%ws%u", strPrefix, IDS_SNAPIN_DESC );
  137. hr = RegisterSnapinGUID( &CLSID_DhcpSnapin,
  138. &GUID_DhcpRootNodeType,
  139. &CLSID_DhcpSnapinAbout,
  140. strDesc,
  141. strVersion,
  142. TRUE, // Standalone
  143. strIndirect );
  144. ASSERT(SUCCEEDED(hr));
  145. if (FAILED(hr))
  146. return hr;
  147. strIndirect.Format( L"%ws%u", strPrefix, IDS_SNAPIN_EXTENSION_DESC );
  148. hr = RegisterSnapinGUID( &CLSID_DhcpSnapinExtension,
  149. NULL,
  150. &CLSID_DhcpSnapinAbout,
  151. strExtDesc,
  152. strVersion,
  153. FALSE,
  154. strIndirect );
  155. ASSERT(SUCCEEDED(hr));
  156. if (FAILED(hr))
  157. return hr;
  158. //
  159. // register the snapin nodes into the console node list
  160. //
  161. hr = RegisterNodeTypeGUID( &CLSID_DhcpSnapin,
  162. &GUID_DhcpRootNodeType,
  163. strRootDesc );
  164. ASSERT(SUCCEEDED(hr));
  165. #ifdef __NETWORK_CONSOLE__
  166. hr = RegisterAsRequiredExtensionGUID( &GUID_NetConsRootNodeType,
  167. &CLSID_DhcpSnapinExtension,
  168. strExtDesc,
  169. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE,
  170. &CLSID_DhcpSnapinExtension ); // doesn't matter what this is,
  171. // just needs to be non-null
  172. ASSERT(SUCCEEDED(hr));
  173. #endif
  174. // extending computer management snapin
  175. hr = RegisterAsRequiredExtensionGUID( &NODETYPE_COMPUTERMANAGEMENT_SERVERAPPS,
  176. &CLSID_DhcpSnapinExtension,
  177. strExtDesc,
  178. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE,
  179. &NODETYPE_COMPUTERMANAGEMENT_SERVERAPPS ); // doesn't matter what this is
  180. // just needs to be non-null
  181. ASSERT(SUCCEEDED(hr));
  182. return hr;
  183. }
  184. /////////////////////////////////////////////////////////////////////////////
  185. // DllUnregisterServer - Removes entries from the system registry
  186. STDAPI DllUnregisterServer(void)
  187. {
  188. HRESULT hr = _Module.UnregisterServer();
  189. ASSERT(SUCCEEDED(hr));
  190. if (FAILED(hr))
  191. return hr;
  192. // un register the snapin
  193. //
  194. hr = UnregisterSnapinGUID(&CLSID_DhcpSnapin);
  195. ASSERT(SUCCEEDED(hr));
  196. if (FAILED(hr))
  197. return hr;
  198. hr = UnregisterSnapinGUID(&CLSID_DhcpSnapinExtension);
  199. ASSERT(SUCCEEDED(hr));
  200. if (FAILED(hr))
  201. return hr;
  202. // unregister the snapin nodes
  203. //
  204. hr = UnregisterNodeTypeGUID(&GUID_DhcpRootNodeType);
  205. ASSERT(SUCCEEDED(hr));
  206. #ifdef __NETWORK_CONSOLE__
  207. hr = UnregisterAsExtensionGUID(&GUID_NetConsRootNodeType,
  208. &CLSID_DhcpSnapinExtension,
  209. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE);
  210. #endif
  211. hr = UnregisterAsExtensionGUID(&NODETYPE_COMPUTERMANAGEMENT_SERVERAPPS,
  212. &CLSID_DhcpSnapinExtension,
  213. EXTENSION_TYPE_TASK | EXTENSION_TYPE_NAMESPACE);
  214. return hr;
  215. }
  216. #ifdef _DEBUG
  217. void DbgVerifyInstanceCounts()
  218. {
  219. DEBUG_VERIFY_INSTANCE_COUNT(CHandler);
  220. DEBUG_VERIFY_INSTANCE_COUNT(CMTHandler);
  221. DEBUG_VERIFY_INSTANCE_COUNT(CTaskList);
  222. DEBUG_VERIFY_INSTANCE_COUNT(CDhcpActiveLease);
  223. DEBUG_VERIFY_INSTANCE_COUNT(CDhcpOptionItem);
  224. DEBUG_VERIFY_INSTANCE_COUNT(COptionsConfig);
  225. }
  226. #endif // _DEBUG