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.

358 lines
9.3 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation
  4. Module Name:
  5. NAPMMCDLL.cpp
  6. Abstract:
  7. Implementation of DLL Exports.
  8. --*/
  9. //////////////////////////////////////////////////////////////////////////////
  10. //////////////////////////////////////////////////////////////////////////////
  11. // BEGIN INCLUDES
  12. //
  13. // standard includes:
  14. //
  15. #include "Precompiled.h"
  16. //
  17. // where we can find declaration for main class in this file:
  18. //
  19. //
  20. // where we can find declarations needed in this file:
  21. //
  22. #include "initguid.h"
  23. #include "NAPMMC_i.c"
  24. // For IComponent, IComponentData, and ISnapinAbout COM classes:
  25. #include "Component.h"
  26. #include "About.h"
  27. #include "LogComp.h"
  28. #include "LogAbout.H"
  29. // For AttributeInfo COM classes:
  30. #include "IASAttributeInfo.h"
  31. #include "IASEnumerableAttributeInfo.h"
  32. //
  33. // Need to include this at least once to compile it in from the common directory:
  34. #include "mmcutility.cpp"
  35. // We are hosting a few extra COM objects in this dll:
  36. // For AttributeEditor COM classes:
  37. #include "IASIPAttributeEditor.h"
  38. #include "IASMultivaluedAttributeEditor.h"
  39. #include "IASVendorSpecificAttributeEditor.h"
  40. #include "IASEnumerableAttributeEditor.h"
  41. #include "IASStringAttributeEditor.h"
  42. #include "IASBooleanAttributeEditor.h"
  43. #include "iasipfilterattributeeditor.h"
  44. #include "NTGroups.h"
  45. // For NASVendors COM object:
  46. #include "Vendors.h"
  47. #include <proxyext.h>
  48. #include <proxyres.h>
  49. unsigned int CF_MMC_NodeID = RegisterClipboardFormatW(CCF_NODEID2);
  50. //
  51. // END INCLUDES
  52. //////////////////////////////////////////////////////////////////////////////
  53. CComModule _Module;
  54. BEGIN_OBJECT_MAP(ObjectMap)
  55. OBJECT_ENTRY(CLSID_NAPSnapin, CComponentData)
  56. OBJECT_ENTRY(CLSID_NAPSnapinAbout, CSnapinAbout)
  57. OBJECT_ENTRY(CLSID_LoggingSnapin, CLoggingComponentData)
  58. OBJECT_ENTRY(CLSID_LoggingSnapinAbout, CLoggingSnapinAbout)
  59. OBJECT_ENTRY(CLSID_IASAttributeInfo, CAttributeInfo)
  60. OBJECT_ENTRY(CLSID_IASEnumerableAttributeInfo, CEnumerableAttributeInfo)
  61. OBJECT_ENTRY(CLSID_IASIPAttributeEditor, CIASIPAttributeEditor)
  62. OBJECT_ENTRY(CLSID_IASMultivaluedAttributeEditor, CIASMultivaluedAttributeEditor)
  63. OBJECT_ENTRY(CLSID_IASVendorSpecificAttributeEditor, CIASVendorSpecificAttributeEditor)
  64. OBJECT_ENTRY(CLSID_IASEnumerableAttributeEditor, CIASEnumerableAttributeEditor)
  65. OBJECT_ENTRY(CLSID_IASStringAttributeEditor, CIASStringAttributeEditor)
  66. OBJECT_ENTRY(CLSID_IASBooleanAttributeEditor, CIASBooleanAttributeEditor)
  67. OBJECT_ENTRY(__uuidof(IASIPFilterAttributeEditor), CIASIPFilterAttributeEditor)
  68. OBJECT_ENTRY(CLSID_IASGroupsAttributeEditor, CIASGroupsAttributeEditor)
  69. OBJECT_ENTRY(CLSID_IASNASVendors, CIASNASVendors)
  70. OBJECT_ENTRY(__uuidof(ProxyExtension), ProxyExtension)
  71. END_OBJECT_MAP()
  72. #if 1 // Use CWinApp for MFC support -- some of the COM objects in this dll use MFC.
  73. class CNAPMMCApp : public CWinApp
  74. {
  75. public:
  76. virtual BOOL InitInstance();
  77. virtual int ExitInstance();
  78. };
  79. CNAPMMCApp theApp;
  80. //////////////////////////////////////////////////////////////////////////////
  81. /*++
  82. CNAPMMCApp::InitInstance
  83. MFC's dll entry point.
  84. --*/
  85. //////////////////////////////////////////////////////////////////////////////
  86. BOOL CNAPMMCApp::InitInstance()
  87. {
  88. _Module.Init(ObjectMap, m_hInstance);
  89. // Initialize static class variables of CSnapInItem.
  90. CSnapInItem::Init();
  91. // Initialize any other static class variables.
  92. CMachineNode::InitClipboardFormat();
  93. CLoggingMachineNode::InitClipboardFormat();
  94. return CWinApp::InitInstance();
  95. }
  96. //////////////////////////////////////////////////////////////////////////////
  97. /*++
  98. CNAPMMCApp::ExitInstance
  99. MFC's dll exit point.
  100. --*/
  101. //////////////////////////////////////////////////////////////////////////////
  102. int CNAPMMCApp::ExitInstance()
  103. {
  104. _Module.Term();
  105. return CWinApp::ExitInstance();
  106. }
  107. #else // Use CWinApp
  108. //////////////////////////////////////////////////////////////////////////////
  109. /*++
  110. DllMain
  111. Remarks
  112. DLL Entry Point
  113. --*/
  114. //////////////////////////////////////////////////////////////////////////////
  115. extern "C"
  116. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  117. {
  118. if (dwReason == DLL_PROCESS_ATTACH)
  119. {
  120. _Module.Init(ObjectMap, hInstance);
  121. // Initialize static class variables of CSnapInItem.
  122. CSnapInItem::Init();
  123. // Initialize any other static class variables.
  124. CMachineNode::InitClipboardFormat();
  125. DisableThreadLibraryCalls(hInstance);
  126. }
  127. else if (dwReason == DLL_PROCESS_DETACH)
  128. _Module.Term();
  129. return TRUE; // ok
  130. }
  131. #endif // Use CWinApp
  132. //////////////////////////////////////////////////////////////////////////////
  133. /*++
  134. DllCanUnloadNow
  135. Remarks
  136. Used to determine whether the DLL can be unloaded by OLE
  137. --*/
  138. //////////////////////////////////////////////////////////////////////////////
  139. STDAPI DllCanUnloadNow(void)
  140. {
  141. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  142. }
  143. //////////////////////////////////////////////////////////////////////////////
  144. /*++
  145. DllGetClassObject
  146. Remarks
  147. Returns a class factory to create an object of the requested type
  148. --*/
  149. //////////////////////////////////////////////////////////////////////////////
  150. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  151. {
  152. return _Module.GetClassObject(rclsid, riid, ppv);
  153. }
  154. //////////////////////////////////////////////////////////////////////////////
  155. /*++
  156. DllRegisterServer
  157. Remarks
  158. Adds entries to the system registry
  159. --*/
  160. //////////////////////////////////////////////////////////////////////////////
  161. STDAPI DllRegisterServer(void)
  162. {
  163. // Set the protocol.
  164. TCHAR NapName[IAS_MAX_STRING];
  165. TCHAR NapName_Indirect[IAS_MAX_STRING];
  166. TCHAR ModuleName[MAX_PATH];
  167. TCHAR LoggingName[IAS_MAX_STRING];
  168. TCHAR LoggingName_Indirect[IAS_MAX_STRING];
  169. if (!GetModuleFileNameOnly(_Module.GetModuleInstance(), ModuleName, MAX_PATH))
  170. {
  171. return E_FAIL;
  172. }
  173. int iLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_SNAPINNAME_NAP, NapName, IAS_MAX_STRING );
  174. swprintf(NapName_Indirect, L"@%s,-%-d", ModuleName, IDS_SNAPINNAME_NAP);
  175. iLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_SNAPINNAME_LOGGING, LoggingName, IAS_MAX_STRING );
  176. swprintf(LoggingName_Indirect, L"@%s,-%-d", ModuleName, IDS_SNAPINNAME_LOGGING);
  177. struct _ATL_REGMAP_ENTRY regMap[] = {
  178. {OLESTR("NAPSNAPIN"), NapName}, // subsitute %NAPSNAPIN% for registry
  179. {OLESTR("NAPSNAPIN_INDIRECT"), NapName_Indirect}, // subsitute %IASSNAPIN% for registry
  180. {OLESTR("LOGGINGSNAPIN"), LoggingName}, // subsitute %LOGGINGSNAPIN% for registry
  181. {OLESTR("LOGGINGSNAPIN_INDIRECT"), LoggingName_Indirect}, // subsitute %IASSNAPIN% for registry
  182. {0, 0}
  183. };
  184. HRESULT hr = _Module.UpdateRegistryFromResource(IDR_NAPSNAPIN, TRUE, regMap);
  185. if (SUCCEEDED(hr))
  186. {
  187. ResourceString proxyName(IDS_PROXY_EXTENSION);
  188. _ATL_REGMAP_ENTRY entries[] =
  189. {
  190. { L"PROXY_EXTENSION", proxyName },
  191. { NULL, NULL }
  192. };
  193. hr = _Module.UpdateRegistryFromResource(
  194. IDR_PROXY_REGISTRY,
  195. TRUE,
  196. entries
  197. );
  198. }
  199. return hr;
  200. }
  201. //////////////////////////////////////////////////////////////////////////////
  202. /*++
  203. DllUnregisterServer
  204. Remarks
  205. Removes entries from the system registry
  206. --*/
  207. //////////////////////////////////////////////////////////////////////////////
  208. STDAPI DllUnregisterServer(void)
  209. {
  210. // Set the protocol.
  211. TCHAR NapName[IAS_MAX_STRING];
  212. TCHAR LoggingName[IAS_MAX_STRING];
  213. int iLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_SNAPINNAME_NAP, NapName, IAS_MAX_STRING );
  214. iLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_SNAPINNAME_LOGGING, LoggingName, IAS_MAX_STRING );
  215. struct _ATL_REGMAP_ENTRY regMap[] = {
  216. {OLESTR("NAPSNAPIN"), NapName}, // subsitute %NAPSNAPIN% for registry
  217. {OLESTR("LOGGINGSNAPIN"), LoggingName}, // subsitute %LOGGINGSNAPIN% for registry
  218. {0, 0}
  219. };
  220. _Module.UpdateRegistryFromResource(IDR_NAPSNAPIN, FALSE, regMap);
  221. _Module.UpdateRegistryFromResource(IDR_PROXY_REGISTRY, FALSE, NULL);
  222. return S_OK;
  223. }
  224. #include "resolver.h"
  225. #define NAPMMCAPI
  226. #include "VerifyAddress.h"
  227. HRESULT
  228. WINAPI
  229. IASVerifyClientAddress(
  230. const wchar_t* address,
  231. BSTR* result
  232. )
  233. {
  234. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  235. *result = 0;
  236. HRESULT hr;
  237. try
  238. {
  239. ClientResolver resolver(address);
  240. if (resolver.DoModal() == IDOK)
  241. {
  242. *result = SysAllocString(resolver.getChoice());
  243. if (*result != 0)
  244. {
  245. hr = S_OK;
  246. }
  247. else
  248. {
  249. hr = E_OUTOFMEMORY;
  250. }
  251. }
  252. else
  253. {
  254. hr = S_FALSE;
  255. }
  256. }
  257. catch (CException* e)
  258. {
  259. e->Delete();
  260. hr = DISP_E_EXCEPTION;
  261. }
  262. return hr;
  263. }