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.

252 lines
6.4 KiB

  1. #include "stdafx.h"
  2. #include "advpub.h" // For REGINSTALL
  3. #pragma hdrstop
  4. #define DECL_CRTFREE
  5. #include <crtfree.h>
  6. // Fix the debug builds
  7. #define SZ_DEBUGINI "ccshell.ini"
  8. #define SZ_DEBUGSECTION "netplwiz"
  9. #define SZ_MODULE "NETPLWIZ"
  10. #define DECLARE_DEBUG
  11. #include "debug.h"
  12. // shell/lib files look for this instance variable
  13. EXTERN_C HINSTANCE g_hinst = 0;
  14. LONG g_cLocks = 0;
  15. BOOL g_bMirroredOS = FALSE;
  16. // DLL lifetime stuff
  17. STDAPI_(BOOL) DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved)
  18. {
  19. if (dwReason == DLL_PROCESS_ATTACH)
  20. {
  21. g_hinst = hinstDLL;
  22. g_hinst = hinstDLL; // For shell/lib files who extern him
  23. g_bMirroredOS = IS_MIRRORING_ENABLED();
  24. SHFusionInitializeFromModule(hinstDLL);
  25. }
  26. else if (dwReason == DLL_PROCESS_DETACH)
  27. {
  28. CleanUpIntroFont();
  29. SHFusionUninitialize();
  30. }
  31. return TRUE; // Successful DLL_PROCESS_ATTACH.
  32. }
  33. STDAPI DllInstall(BOOL bInstall, LPCWSTR pszCmdLine)
  34. {
  35. return S_OK;
  36. }
  37. STDAPI DllCanUnloadNow()
  38. {
  39. return (g_cLocks == 0) ? S_OK:S_FALSE;
  40. }
  41. STDAPI_(void) DllAddRef(void)
  42. {
  43. InterlockedIncrement(&g_cLocks);
  44. }
  45. STDAPI_(void) DllRelease(void)
  46. {
  47. InterlockedDecrement(&g_cLocks);
  48. }
  49. // helper to handle the SELFREG.INF parsing
  50. HRESULT _CallRegInstall(LPCSTR szSection, BOOL bUninstall)
  51. {
  52. HRESULT hr = E_FAIL;
  53. HINSTANCE hinstAdvPack = LoadLibrary(TEXT("ADVPACK.DLL"));
  54. if (hinstAdvPack)
  55. {
  56. REGINSTALL pfnri = (REGINSTALL)GetProcAddress(hinstAdvPack, "RegInstall");
  57. if (pfnri)
  58. {
  59. STRENTRY seReg[] = {
  60. { "25", "%SystemRoot%" },
  61. { "11", "%SystemRoot%\\system32" },
  62. };
  63. STRTABLE stReg = { ARRAYSIZE(seReg), seReg };
  64. hr = pfnri(g_hinst, szSection, &stReg);
  65. if (bUninstall)
  66. {
  67. // ADVPACK will return E_UNEXPECTED if you try to uninstall
  68. // (which does a registry restore) on an INF section that was
  69. // never installed. We uninstall sections that may never have
  70. // been installed, so ignore this error
  71. hr = ((E_UNEXPECTED == hr) ? S_OK : hr);
  72. }
  73. }
  74. FreeLibrary(hinstAdvPack);
  75. }
  76. return hr;
  77. }
  78. STDAPI DllRegisterServer()
  79. {
  80. _CallRegInstall("UnregDll", TRUE);
  81. HRESULT hres = _CallRegInstall("RegDll", FALSE);
  82. if ( SUCCEEDED(hres) )
  83. {
  84. // if this is a workstation build then lets install the users and password cpl
  85. NT_PRODUCT_TYPE NtProductType;
  86. RtlGetNtProductType(&NtProductType); // get the product type
  87. if (NtProductType == NtProductWinNt)
  88. {
  89. hres = _CallRegInstall("RegDllWorkstation", FALSE);
  90. }
  91. }
  92. return S_OK;
  93. }
  94. STDAPI DllUnregisterServer()
  95. {
  96. return S_OK;
  97. }
  98. //
  99. // This array holds information needed for ClassFacory.
  100. // OLEMISC_ flags are used by shembed and shocx.
  101. //
  102. // PERF: this table should be ordered in most-to-least used order
  103. //
  104. #define OIF_ALLOWAGGREGATION 0x0001
  105. CF_TABLE_BEGIN(g_ObjectInfo)
  106. CF_TABLE_ENTRY( &CLSID_PublishingWizard, CPublishingWizard_CreateInstance, COCREATEONLY),
  107. CF_TABLE_ENTRY( &CLSID_PublishDropTarget, CPublishDropTarget_CreateInstance, COCREATEONLY),
  108. CF_TABLE_ENTRY( &CLSID_UserPropertyPages, CUserPropertyPages_CreateInstance, COCREATEONLY),
  109. CF_TABLE_ENTRY( &CLSID_InternetPrintOrdering, CPublishDropTarget_CreateInstance, COCREATEONLY),
  110. CF_TABLE_ENTRY( &CLSID_PassportWizard, CPassportWizard_CreateInstance, COCREATEONLY),
  111. CF_TABLE_ENTRY( &CLSID_PassportClientServices, CPassportClientServices_CreateInstance, COCREATEONLY),
  112. CF_TABLE_END(g_ObjectInfo)
  113. // constructor for CObjectInfo.
  114. CObjectInfo::CObjectInfo(CLSID const* pclsidin, LPFNCREATEOBJINSTANCE pfnCreatein, IID const* piidIn,
  115. IID const* piidEventsIn, long lVersionIn, DWORD dwOleMiscFlagsIn,
  116. DWORD dwClassFactFlagsIn)
  117. {
  118. pclsid = pclsidin;
  119. pfnCreateInstance = pfnCreatein;
  120. piid = piidIn;
  121. piidEvents = piidEventsIn;
  122. lVersion = lVersionIn;
  123. dwOleMiscFlags = dwOleMiscFlagsIn;
  124. dwClassFactFlags = dwClassFactFlagsIn;
  125. }
  126. // static class factory (no allocs!)
  127. STDMETHODIMP CClassFactory::QueryInterface(REFIID riid, void **ppvObj)
  128. {
  129. if (IsEqualIID(riid, IID_IClassFactory) || IsEqualIID(riid, IID_IUnknown))
  130. {
  131. *ppvObj = (void *)GET_ICLASSFACTORY(this);
  132. DllAddRef();
  133. return NOERROR;
  134. }
  135. *ppvObj = NULL;
  136. return E_NOINTERFACE;
  137. }
  138. STDMETHODIMP_(ULONG) CClassFactory::AddRef()
  139. {
  140. DllAddRef();
  141. return 2;
  142. }
  143. STDMETHODIMP_(ULONG) CClassFactory::Release()
  144. {
  145. DllRelease();
  146. return 1;
  147. }
  148. STDMETHODIMP CClassFactory::CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppv)
  149. {
  150. *ppv = NULL;
  151. if (punkOuter && !IsEqualIID(riid, IID_IUnknown))
  152. {
  153. // It is technically illegal to aggregate an object and request
  154. // any interface other than IUnknown. Enforce this.
  155. //
  156. return CLASS_E_NOAGGREGATION;
  157. }
  158. else
  159. {
  160. LPOBJECTINFO pthisobj = (LPOBJECTINFO)this;
  161. if (punkOuter && !(pthisobj->dwClassFactFlags & OIF_ALLOWAGGREGATION))
  162. return CLASS_E_NOAGGREGATION;
  163. IUnknown *punk;
  164. HRESULT hres = pthisobj->pfnCreateInstance(punkOuter, &punk, pthisobj);
  165. if (SUCCEEDED(hres))
  166. {
  167. hres = punk->QueryInterface(riid, ppv);
  168. punk->Release();
  169. }
  170. _ASSERT(FAILED(hres) ? *ppv == NULL : TRUE);
  171. return hres;
  172. }
  173. }
  174. STDMETHODIMP CClassFactory::LockServer(BOOL fLock)
  175. {
  176. if (fLock)
  177. DllAddRef();
  178. else
  179. DllRelease();
  180. return S_OK;
  181. }
  182. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
  183. {
  184. HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;
  185. *ppv = NULL;
  186. if (IsEqualIID(riid, IID_IClassFactory) || IsEqualIID(riid, IID_IUnknown))
  187. {
  188. for (LPCOBJECTINFO pcls = g_ObjectInfo; pcls->pclsid; pcls++)
  189. {
  190. if (IsEqualGUID(rclsid, *(pcls->pclsid)))
  191. {
  192. *ppv = (void*)pcls;
  193. DllAddRef(); // class factory holds DLL ref count
  194. hr = S_OK;
  195. }
  196. }
  197. }
  198. #ifdef ATL_ENABLED
  199. if (hr == CLASS_E_CLASSNOTAVAILABLE)
  200. hr = AtlGetClassObject(rclsid, riid, ppv);
  201. #endif
  202. return hr;
  203. }