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.

463 lines
14 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: D L L M A I N . C P P
  7. //
  8. // Contents: Entry points for netcfgx.dll
  9. //
  10. // Notes:
  11. //
  12. // Author: shaunco 23 Apr 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "ncxbase.h"
  18. // Include support for all of the COM objects
  19. #include "..\alanecfg\alaneobj.h"
  20. #include "..\atlkcfg\atlkobj.h"
  21. #include "..\atmcfg\arpsobj.h"
  22. #include "..\atmcfg\auniobj.h"
  23. #include "..\brdgcfg\brdgobj.h"
  24. #include "..\dhcpscfg\dhcpsobj.h"
  25. #include "..\msclicfg\mscliobj.h"
  26. #include "..\nbfcfg\nbfobj.h"
  27. #include "..\engine\inetcfg.h"
  28. #include "..\nwclicfg\nwcliobj.h"
  29. #include "..\nwlnkcfg\nwlnkipx.h"
  30. #include "..\nwlnkcfg\nwlnknb.h"
  31. #include "..\rascfg\rasobj.h"
  32. #include "..\sapcfg\sapobj.h"
  33. #include "..\srvrcfg\srvrobj.h"
  34. #include "..\tcpipcfg\tcpipobj.h"
  35. #include "..\wlbscfg\wlbs.h"
  36. // Network class installer
  37. #include "..\engine\dihook.h"
  38. // Net class prop page providers
  39. #include "netpages.h"
  40. #define INITGUID
  41. #include "ncxclsid.h"
  42. // Global
  43. CComModule _Module;
  44. BEGIN_OBJECT_MAP(ObjectMap)
  45. OBJECT_ENTRY(CLSID_CALaneCfg, CALaneCfg)
  46. OBJECT_ENTRY(CLSID_CATlkObj, CATlkObj)
  47. OBJECT_ENTRY(CLSID_CArpsCfg, CArpsCfg)
  48. OBJECT_ENTRY(CLSID_CAtmUniCfg, CAtmUniCfg)
  49. OBJECT_ENTRY(CLSID_CBridgeObj, CBridgeNO)
  50. OBJECT_ENTRY(CLSID_CDHCPServer, CDHCPServer)
  51. OBJECT_ENTRY(CLSID_CL2tp, CL2tp)
  52. OBJECT_ENTRY(CLSID_CMSClient, CMSClient)
  53. OBJECT_ENTRY(CLSID_CNWClient, CNWClient)
  54. OBJECT_ENTRY(CLSID_CNbfObj, CNbfObj)
  55. OBJECT_ENTRY(CLSID_CNdisWan, CNdisWan)
  56. OBJECT_ENTRY(CLSID_CNetCfg, CImplINetCfg)
  57. OBJECT_ENTRY(CLSID_CNwlnkIPX, CNwlnkIPX)
  58. OBJECT_ENTRY(CLSID_CNwlnkNB, CNwlnkNB)
  59. OBJECT_ENTRY(CLSID_CPppoe, CPppoe)
  60. OBJECT_ENTRY(CLSID_CPptp, CPptp)
  61. OBJECT_ENTRY(CLSID_CRasCli, CRasCli)
  62. OBJECT_ENTRY(CLSID_CRasSrv, CRasSrv)
  63. OBJECT_ENTRY(CLSID_CSAPCfg, CSAPCfg)
  64. OBJECT_ENTRY(CLSID_CSrvrcfg, CSrvrcfg)
  65. OBJECT_ENTRY(CLSID_CSteelhead, CSteelhead)
  66. OBJECT_ENTRY(CLSID_CTcpipcfg, CTcpipcfg)
  67. OBJECT_ENTRY(CLSID_CWLBS, CWLBS)
  68. END_OBJECT_MAP()
  69. //+---------------------------------------------------------------------------
  70. // DLL Entry Point
  71. //
  72. EXTERN_C
  73. BOOL
  74. WINAPI
  75. DllMain (
  76. HINSTANCE hInstance,
  77. DWORD dwReason,
  78. LPVOID /* lpReserved */)
  79. {
  80. if (DLL_PROCESS_ATTACH == dwReason)
  81. {
  82. DisableThreadLibraryCalls (hInstance);
  83. InitializeDebugging();
  84. _Module.Init (ObjectMap, hInstance);
  85. }
  86. else if (DLL_PROCESS_DETACH == dwReason)
  87. {
  88. DbgCheckPrematureDllUnload ("netcfgx.dll", _Module.GetLockCount());
  89. _Module.Term ();
  90. UnInitializeDebugging();
  91. }
  92. return TRUE; // ok
  93. }
  94. /////////////////////////////////////////////////////////////////////////////
  95. // Used to determine whether the DLL can be unloaded by OLE
  96. STDAPI DllCanUnloadNow(VOID)
  97. {
  98. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  99. }
  100. /////////////////////////////////////////////////////////////////////////////
  101. // Returns a class factory to create an object of the requested type
  102. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  103. {
  104. // The check is to works around an ATL problem where AtlModuleGetClassObject will AV
  105. // if _Module.m_pObjMap == NULL
  106. if (_Module.m_pObjMap)
  107. {
  108. return _Module.GetClassObject(rclsid, riid, ppv);
  109. }
  110. else
  111. {
  112. return E_FAIL;
  113. }
  114. }
  115. /////////////////////////////////////////////////////////////////////////////
  116. // DllRegisterServer - Adds entries to the system registry
  117. STDAPI DllRegisterServer(VOID)
  118. {
  119. BOOL fCoUninitialize = TRUE;
  120. HRESULT hr = CoInitializeEx (NULL,
  121. COINIT_DISABLE_OLE1DDE | COINIT_APARTMENTTHREADED);
  122. if (FAILED(hr))
  123. {
  124. fCoUninitialize = FALSE;
  125. if (RPC_E_CHANGED_MODE == hr)
  126. {
  127. hr = S_OK;
  128. }
  129. }
  130. if (SUCCEEDED(hr))
  131. {
  132. hr = NcAtlModuleRegisterServer (&_Module);
  133. if (fCoUninitialize)
  134. {
  135. CoUninitialize ();
  136. }
  137. }
  138. TraceHr (ttidError, FAL, hr, FALSE, "netcfgx!DllRegisterServer");
  139. return hr;
  140. }
  141. /////////////////////////////////////////////////////////////////////////////
  142. // DllUnregisterServer - Removes entries from the system registry
  143. STDAPI DllUnregisterServer(VOID)
  144. {
  145. _Module.UnregisterServer();
  146. return S_OK;
  147. }
  148. #if DBG
  149. const char * SzDifToString(DI_FUNCTION dif)
  150. {
  151. switch(dif)
  152. {
  153. case DIF_SELECTDEVICE: return "DIF_SELECTDEVICE";
  154. case DIF_INSTALLDEVICE: return "DIF_INSTALLDEVICE";
  155. case DIF_ASSIGNRESOURCES: return "DIF_ASSIGNRESOURCES";
  156. case DIF_PROPERTIES: return "DIF_PROPERTIES";
  157. case DIF_REMOVE: return "DIF_REMOVE";
  158. case DIF_FIRSTTIMESETUP: return "DIF_FIRSTTIMESETUP";
  159. case DIF_FOUNDDEVICE: return "DIF_FOUNDDEVICE";
  160. case DIF_SELECTCLASSDRIVERS: return "DIF_SELECTCLASSDRIVERS";
  161. case DIF_VALIDATECLASSDRIVERS: return "DIF_VALIDATECLASSDRIVERS";
  162. case DIF_INSTALLCLASSDRIVERS: return "DIF_INSTALLCLASSDRIVERS";
  163. case DIF_CALCDISKSPACE: return "DIF_CALCDISKSPACE";
  164. case DIF_DESTROYPRIVATEDATA: return "DIF_DESTROYPRIVATEDATA";
  165. case DIF_VALIDATEDRIVER: return "DIF_VALIDATEDRIVER";
  166. case DIF_MOVEDEVICE: return "DIF_MOVEDEVICE";
  167. case DIF_DETECT: return "DIF_DETECT";
  168. case DIF_INSTALLWIZARD: return "DIF_INSTALLWIZARD";
  169. case DIF_DESTROYWIZARDDATA: return "DIF_DESTROYWIZARDDATA";
  170. case DIF_PROPERTYCHANGE: return "DIF_PROPERTYCHANGE";
  171. case DIF_ENABLECLASS: return "DIF_ENABLECLASS";
  172. case DIF_DETECTVERIFY: return "DIF_DETECTVERIFY";
  173. case DIF_INSTALLDEVICEFILES: return "DIF_INSTALLDEVICEFILES";
  174. case DIF_UNREMOVE: return "DIF_UNREMOVE";
  175. case DIF_SELECTBESTCOMPATDRV: return "DIF_SELECTBESTCOMPATDRV";
  176. case DIF_ALLOW_INSTALL: return "DIF_ALLOW_INSTALL";
  177. case DIF_REGISTERDEVICE: return "DIF_REGISTERDEVICE";
  178. case DIF_NEWDEVICEWIZARD_PRESELECT: return "DIF_NEWDEVICEWIZARD_PRESELECT";
  179. case DIF_NEWDEVICEWIZARD_SELECT: return "DIF_NEWDEVICEWIZARD_SELECT";
  180. case DIF_NEWDEVICEWIZARD_PREANALYZE: return "DIF_NEWDEVICEWIZARD_PREANALYZE";
  181. case DIF_NEWDEVICEWIZARD_POSTANALYZE: return "DIF_NEWDEVICEWIZARD_POSTANALYZE";
  182. case DIF_NEWDEVICEWIZARD_FINISHINSTALL: return "DIF_NEWDEVICEWIZARD_FINISHINSTALL";
  183. case DIF_UNUSED1: return "DIF_UNUSED1";
  184. case DIF_INSTALLINTERFACES: return "DIF_INSTALLINTERFACES";
  185. case DIF_DETECTCANCEL: return "DIF_DETECTCANCEL";
  186. case DIF_REGISTER_COINSTALLERS: return "DIF_REGISTER_COINSTALLERS";
  187. case DIF_ADDPROPERTYPAGE_ADVANCED: return "DIF_ADDPROPERTYPAGE_ADVANCED";
  188. case DIF_ADDPROPERTYPAGE_BASIC: return "DIF_ADDPROPERTYPAGE_BASIC";
  189. case DIF_RESERVED1: return "DIF_RESERVED1";
  190. case DIF_TROUBLESHOOTER: return "DIF_TROUBLESHOOTER";
  191. case DIF_POWERMESSAGEWAKE: return "DIF_POWERMESSAGEWAKE";
  192. case DIF_ADDREMOTEPROPERTYPAGE_ADVANCED: return "DIF_ADDREMOTEPROPERTYPAGE_ADVANCED";
  193. default: return "Unknown DI_FUNCTION - update SzDifToString()";
  194. }
  195. }
  196. #endif // DBG
  197. //+--------------------------------------------------------------------------
  198. //
  199. // Function: NetClassInstaller
  200. //
  201. // Purpose: This function is called by SetupApi for a variety of
  202. // functions defined by dif.
  203. // See SetupDiCallClassInstaller in the SetupApi documentation
  204. // for more information.
  205. //
  206. // Arguments:
  207. // dif [in] See Device Installer documentation
  208. // hdi [in]
  209. // pdeid [in] if dif == DIF_INSTALLDEVICE, this parameter is not
  210. // optional.
  211. //
  212. //
  213. // Returns: Win32/Device Installer error code
  214. //
  215. // Author: BillBe 24 Nov 1996
  216. //
  217. // Notes:
  218. //
  219. EXTERN_C
  220. DWORD
  221. __stdcall
  222. NetClassInstaller (
  223. DI_FUNCTION dif,
  224. HDEVINFO hdi,
  225. PSP_DEVINFO_DATA pdeid)
  226. {
  227. #if DBG
  228. TraceTag(ttidNetcfgBase, "NetClassInstaller: dif=0x%08X (%s)", dif, SzDifToString(dif));
  229. #endif
  230. DWORD dwRet = ERROR_DI_DO_DEFAULT;
  231. NC_TRY
  232. {
  233. HRESULT hr = _HrNetClassInstaller (dif, hdi, pdeid);
  234. // Convert errors that can be converted otherwise
  235. // leave error as is and Device Installer Api will treat is as
  236. // a generic failure
  237. //
  238. if (FAILED(hr))
  239. {
  240. DWORD dwFac = HRESULT_FACILITY(hr);
  241. if ((FACILITY_SETUPAPI == dwFac) || (FACILITY_WIN32 == dwFac))
  242. {
  243. dwRet = DwWin32ErrorFromHr (hr);
  244. }
  245. else
  246. {
  247. dwRet = ERROR_GEN_FAILURE;
  248. }
  249. }
  250. else
  251. {
  252. dwRet = NO_ERROR;
  253. }
  254. }
  255. NC_CATCH_ALL
  256. {
  257. dwRet = ERROR_GEN_FAILURE;
  258. }
  259. TraceTag(ttidNetcfgBase, "NetClassInstaller Exiting. Result %X", dwRet);
  260. return dwRet;
  261. }
  262. //+---------------------------------------------------------------------------
  263. //
  264. // Function: ModemClassCoInstaller
  265. //
  266. // Purpose: Implements the co-installer for modem devices.
  267. //
  268. // Arguments:
  269. // dif [in] See Device Installer Api documentation.
  270. // hdi [in]
  271. // pdeid [in]
  272. // pContext [inout]
  273. //
  274. // Returns: See Device Installer Api documentation.
  275. //
  276. // Author: shaunco 6 May 1997
  277. //
  278. // Notes:
  279. //
  280. EXTERN_C
  281. DWORD
  282. __stdcall
  283. ModemClassCoInstaller (
  284. DI_FUNCTION dif,
  285. HDEVINFO hdi,
  286. PSP_DEVINFO_DATA pdeid,
  287. PCOINSTALLER_CONTEXT_DATA pContext)
  288. {
  289. AssertSz (pContext, "ModemClassCoInstaller: Hey! How about some context "
  290. "data?");
  291. TraceTag (ttidRasCfg, "ModemClassCoInstaller: dif=0x%08X %s",
  292. dif,
  293. (pContext->PostProcessing) ? "(post processing)" : "");
  294. // If we're post processing for anything and the install result from
  295. // the class installer indicates an error, propagate this error and
  296. // take no action.
  297. //
  298. if (pContext->PostProcessing && (NO_ERROR != pContext->InstallResult))
  299. {
  300. TraceTag (ttidRasCfg, "ModemClassCoInstaller: taking no action. "
  301. "propagating pContext->InstallResult = 0x%08X",
  302. pContext->InstallResult);
  303. return pContext->InstallResult;
  304. }
  305. DWORD dwRet = NO_ERROR;
  306. if (!FInSystemSetup())
  307. {
  308. NC_TRY
  309. {
  310. HRESULT hr = HrModemClassCoInstaller (dif, hdi, pdeid, pContext);
  311. // Convert errors that can be converted otherwise
  312. // return generic faliure.
  313. //
  314. if (FAILED(hr))
  315. {
  316. DWORD dwFac = HRESULT_FACILITY(hr);
  317. if ((FACILITY_SETUPAPI == dwFac) || (FACILITY_WIN32 == dwFac))
  318. {
  319. dwRet = DwWin32ErrorFromHr (hr);
  320. }
  321. else
  322. {
  323. dwRet = ERROR_GEN_FAILURE;
  324. }
  325. }
  326. }
  327. NC_CATCH_ALL
  328. {
  329. dwRet = ERROR_GEN_FAILURE;
  330. }
  331. }
  332. return dwRet;
  333. }
  334. //+---------------------------------------------------------------------------
  335. //
  336. // Function: NetPropPageProvider
  337. //
  338. // Purpose:
  339. //
  340. // Arguments:
  341. // ppspr [in] See Win32 ExtensionPropSheetPageProc fcn for info
  342. // lpfn [in]
  343. // lParama [in]
  344. //
  345. // Returns: See Win32ExtensionPropSheetPageProc
  346. //
  347. // Author: billbe 24 June 1997
  348. //
  349. // Notes:
  350. //
  351. EXTERN_C
  352. BOOL
  353. __stdcall
  354. NetPropPageProvider(
  355. PSP_PROPSHEETPAGE_REQUEST ppspr,
  356. LPFNADDPROPSHEETPAGE lpfnAddPage,
  357. LPARAM lParam)
  358. {
  359. Assert(ppspr);
  360. Assert(lpfnAddPage);
  361. TraceTag(ttidNetcfgBase, "NetPropPageProvider called");
  362. // Assume we can't handle the request
  363. BOOL bSuccess = FALSE;
  364. HPROPSHEETPAGE hpspAdvanced = NULL;
  365. HPROPSHEETPAGE hpspIsdn = NULL;
  366. // Only supply the property page if we there is a specific device
  367. // in other words, don't do it if properties on the general Net class
  368. // is being requested.
  369. // Also, we only respond to the advanced device properties request
  370. HRESULT hr = S_OK;
  371. if ((ppspr->DeviceInfoData) &&
  372. (SPPSR_ENUM_ADV_DEVICE_PROPERTIES == ppspr->PageRequested))
  373. {
  374. // Get the advanced page ready for hand off to the requestor
  375. hr = HrGetAdvancedPage(ppspr->DeviceInfoSet, ppspr->DeviceInfoData,
  376. &hpspAdvanced);
  377. if (SUCCEEDED(hr))
  378. {
  379. if (lpfnAddPage(hpspAdvanced, lParam))
  380. {
  381. // We successfully made the hand off to the requestor
  382. // Now we reset our handle so we don't try to free it
  383. hpspAdvanced = NULL;
  384. bSuccess = TRUE;
  385. }
  386. // clean up if needed
  387. if (hpspAdvanced)
  388. {
  389. DestroyPropertySheetPage(hpspAdvanced);
  390. }
  391. }
  392. // Get the isdn page ready for hand off to the requestor
  393. //
  394. // We don't need to save the hr value from the last so we can reuse
  395. hr = HrGetIsdnPage(ppspr->DeviceInfoSet, ppspr->DeviceInfoData,
  396. &hpspIsdn);
  397. if (SUCCEEDED(hr))
  398. {
  399. if (lpfnAddPage(hpspIsdn, lParam))
  400. {
  401. // We successfully made the hand off to the requestor
  402. // Now we reset our handle so we don't try to free it
  403. hpspIsdn = NULL;
  404. bSuccess = TRUE;
  405. }
  406. // clean up if needed
  407. if (hpspIsdn)
  408. {
  409. DestroyPropertySheetPage(hpspIsdn);
  410. }
  411. }
  412. }
  413. return bSuccess;
  414. }