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.

255 lines
6.7 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. ASSERT( 0 != g_cLocks );
  48. InterlockedDecrement(&g_cLocks);
  49. }
  50. // helper to handle the SELFREG.INF parsing
  51. HRESULT _CallRegInstall(LPCSTR szSection, BOOL bUninstall)
  52. {
  53. HRESULT hr = E_FAIL;
  54. HINSTANCE hinstAdvPack = LoadLibrary(TEXT("ADVPACK.DLL"));
  55. if (hinstAdvPack)
  56. {
  57. REGINSTALL pfnri = (REGINSTALL)GetProcAddress(hinstAdvPack, "RegInstall");
  58. if (pfnri)
  59. {
  60. STRENTRY seReg[] = {
  61. { "25", "%SystemRoot%" },
  62. { "11", "%SystemRoot%\\system32" },
  63. };
  64. STRTABLE stReg = { ARRAYSIZE(seReg), seReg };
  65. hr = pfnri(g_hinst, szSection, &stReg);
  66. if (bUninstall)
  67. {
  68. // ADVPACK will return E_UNEXPECTED if you try to uninstall
  69. // (which does a registry restore) on an INF section that was
  70. // never installed. We uninstall sections that may never have
  71. // been installed, so ignore this error
  72. hr = ((E_UNEXPECTED == hr) ? S_OK : hr);
  73. }
  74. }
  75. FreeLibrary(hinstAdvPack);
  76. }
  77. return hr;
  78. }
  79. STDAPI DllRegisterServer()
  80. {
  81. _CallRegInstall("UnregDll", TRUE);
  82. HRESULT hres = _CallRegInstall("RegDll", FALSE);
  83. if ( SUCCEEDED(hres) )
  84. {
  85. // if this is server set the policy to restrict web publishing
  86. if (IsOS(OS_ANYSERVER))
  87. {
  88. hres = _CallRegInstall("RegDllServer", FALSE);
  89. }
  90. else
  91. {
  92. // this is a workstation; lets install the users and password cpl
  93. hres = _CallRegInstall("RegDllWorkstation", FALSE);
  94. }
  95. }
  96. return S_OK;
  97. }
  98. STDAPI DllUnregisterServer()
  99. {
  100. return S_OK;
  101. }
  102. //
  103. // This array holds information needed for ClassFacory.
  104. // OLEMISC_ flags are used by shembed and shocx.
  105. //
  106. // PERF: this table should be ordered in most-to-least used order
  107. //
  108. #define OIF_ALLOWAGGREGATION 0x0001
  109. CF_TABLE_BEGIN(g_ObjectInfo)
  110. CF_TABLE_ENTRY( &CLSID_PublishingWizard, CPublishingWizard_CreateInstance, COCREATEONLY),
  111. CF_TABLE_ENTRY( &CLSID_PublishDropTarget, CPublishDropTarget_CreateInstance, COCREATEONLY),
  112. CF_TABLE_ENTRY( &CLSID_UserPropertyPages, CUserPropertyPages_CreateInstance, COCREATEONLY),
  113. CF_TABLE_ENTRY( &CLSID_InternetPrintOrdering, CPublishDropTarget_CreateInstance, COCREATEONLY),
  114. CF_TABLE_ENTRY( &CLSID_PassportWizard, CPassportWizard_CreateInstance, COCREATEONLY),
  115. CF_TABLE_ENTRY( &CLSID_PassportClientServices, CPassportClientServices_CreateInstance, COCREATEONLY),
  116. CF_TABLE_END(g_ObjectInfo)
  117. // constructor for CObjectInfo.
  118. CObjectInfo::CObjectInfo(CLSID const* pclsidin, LPFNCREATEOBJINSTANCE pfnCreatein, IID const* piidIn,
  119. IID const* piidEventsIn, long lVersionIn, DWORD dwOleMiscFlagsIn,
  120. DWORD dwClassFactFlagsIn)
  121. {
  122. pclsid = pclsidin;
  123. pfnCreateInstance = pfnCreatein;
  124. piid = piidIn;
  125. piidEvents = piidEventsIn;
  126. lVersion = lVersionIn;
  127. dwOleMiscFlags = dwOleMiscFlagsIn;
  128. dwClassFactFlags = dwClassFactFlagsIn;
  129. }
  130. // static class factory (no allocs!)
  131. STDMETHODIMP CClassFactory::QueryInterface(REFIID riid, void **ppvObj)
  132. {
  133. if (IsEqualIID(riid, IID_IClassFactory) || IsEqualIID(riid, IID_IUnknown))
  134. {
  135. *ppvObj = (void *)GET_ICLASSFACTORY(this);
  136. DllAddRef();
  137. return NOERROR;
  138. }
  139. *ppvObj = NULL;
  140. return E_NOINTERFACE;
  141. }
  142. STDMETHODIMP_(ULONG) CClassFactory::AddRef()
  143. {
  144. DllAddRef();
  145. return 2;
  146. }
  147. STDMETHODIMP_(ULONG) CClassFactory::Release()
  148. {
  149. DllRelease();
  150. return 1;
  151. }
  152. STDMETHODIMP CClassFactory::CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppv)
  153. {
  154. *ppv = NULL;
  155. if (punkOuter && !IsEqualIID(riid, IID_IUnknown))
  156. {
  157. // It is technically illegal to aggregate an object and request
  158. // any interface other than IUnknown. Enforce this.
  159. //
  160. return CLASS_E_NOAGGREGATION;
  161. }
  162. else
  163. {
  164. LPOBJECTINFO pthisobj = (LPOBJECTINFO)this;
  165. if (punkOuter && !(pthisobj->dwClassFactFlags & OIF_ALLOWAGGREGATION))
  166. return CLASS_E_NOAGGREGATION;
  167. IUnknown *punk;
  168. HRESULT hres = pthisobj->pfnCreateInstance(punkOuter, &punk, pthisobj);
  169. if (SUCCEEDED(hres))
  170. {
  171. hres = punk->QueryInterface(riid, ppv);
  172. punk->Release();
  173. }
  174. _ASSERT(FAILED(hres) ? *ppv == NULL : TRUE);
  175. return hres;
  176. }
  177. }
  178. STDMETHODIMP CClassFactory::LockServer(BOOL fLock)
  179. {
  180. if (fLock)
  181. DllAddRef();
  182. else
  183. DllRelease();
  184. return S_OK;
  185. }
  186. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
  187. {
  188. HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;
  189. *ppv = NULL;
  190. if (IsEqualIID(riid, IID_IClassFactory) || IsEqualIID(riid, IID_IUnknown))
  191. {
  192. for (LPCOBJECTINFO pcls = g_ObjectInfo; pcls->pclsid; pcls++)
  193. {
  194. if (IsEqualGUID(rclsid, *(pcls->pclsid)))
  195. {
  196. *ppv = (void*)pcls;
  197. DllAddRef(); // class factory holds DLL ref count
  198. hr = S_OK;
  199. }
  200. }
  201. }
  202. #ifdef ATL_ENABLED
  203. if (hr == CLASS_E_CLASSNOTAVAILABLE)
  204. hr = AtlGetClassObject(rclsid, riid, ppv);
  205. #endif
  206. return hr;
  207. }