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.

261 lines
6.2 KiB

  1. #include "msrating.h"
  2. #include "ratings.h"
  3. #include "rors.h"
  4. #include "msluglob.h"
  5. #include "mslubase.h"
  6. #include <advpub.h>
  7. #include <atlmisc.h> // CString
  8. STDMETHODIMP CLUClassFactory::QueryInterface(
  9. /* [in] */ REFIID riid,
  10. /* [out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
  11. {
  12. *ppvObject = NULL;
  13. if (IsEqualIID(riid, IID_IUnknown) ||
  14. IsEqualIID(riid, IID_IClassFactory)) {
  15. *ppvObject = (LPVOID)this;
  16. AddRef();
  17. return NOERROR;
  18. }
  19. return ResultFromScode(E_NOINTERFACE);
  20. }
  21. STDMETHODIMP_(ULONG) CLUClassFactory::AddRef(void)
  22. {
  23. RefThisDLL(TRUE);
  24. return 1;
  25. }
  26. STDMETHODIMP_(ULONG) CLUClassFactory::Release(void)
  27. {
  28. RefThisDLL(FALSE);
  29. return 1;
  30. }
  31. STDMETHODIMP CLUClassFactory::CreateInstance(
  32. /* [unique][in] */ IUnknown __RPC_FAR *pUnkOuter,
  33. /* [in] */ REFIID riid,
  34. /* [out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
  35. {
  36. if (NULL != pUnkOuter)
  37. return ResultFromScode(CLASS_E_NOAGGREGATION);
  38. CRORemoteSite *pObj = new CRORemoteSite;
  39. if (NULL == pObj)
  40. return ResultFromScode(E_OUTOFMEMORY);
  41. HRESULT hr = pObj->QueryInterface(riid, ppvObject);
  42. if (FAILED(hr)) {
  43. delete pObj;
  44. pObj = NULL;
  45. }
  46. return hr;
  47. }
  48. STDMETHODIMP CLUClassFactory::LockServer(
  49. /* [in] */ BOOL fLock)
  50. {
  51. LockThisDLL(fLock);
  52. return NOERROR;
  53. }
  54. HRESULT CallRegInstall(LPSTR pszSection)
  55. {
  56. HRESULT hr = E_FAIL;
  57. HINSTANCE hinstAdvPack = LoadLibrary(TEXT("ADVPACK.DLL"));
  58. if (hinstAdvPack)
  59. {
  60. REGINSTALL pfnri = (REGINSTALL)GetProcAddress(hinstAdvPack, "RegInstall");
  61. if (pfnri)
  62. {
  63. char szIEPath[MAX_PATH];
  64. STRENTRY seReg[] = {
  65. { "MSIEXPLORE", szIEPath },
  66. // These two NT-specific entries must be at the end
  67. { "25", "%SystemRoot%" },
  68. { "11", "%SystemRoot%\\system32" },
  69. };
  70. STRTABLE stReg = { ARRAYSIZE(seReg) - 2, seReg };
  71. lstrcpy(szIEPath,"iexplore.exe");
  72. if ( RunningOnNT() ) //are we on NT?
  73. {
  74. // If on NT, we want custom action for %25% %11%
  75. // so that it uses %SystemRoot% in writing the
  76. // path to the registry.
  77. stReg.cEntries += 2;
  78. }
  79. hr = pfnri(g_hInstance, pszSection, &stReg);
  80. }
  81. FreeLibrary(hinstAdvPack);
  82. }
  83. return hr;
  84. }
  85. extern "C" {
  86. STDAPI DllRegisterServer(void)
  87. {
  88. HKEY hkeyCLSID;
  89. HKEY hkeyOurs;
  90. HKEY hkeyInproc;
  91. LONG err;
  92. err = ::RegOpenKey(HKEY_CLASSES_ROOT, ::szCLSID, &hkeyCLSID);
  93. if (err == ERROR_SUCCESS)
  94. {
  95. err = ::RegCreateKey(hkeyCLSID, ::szRORSGUID, &hkeyOurs);
  96. if (err == ERROR_SUCCESS)
  97. {
  98. err = ::RegCreateKey(hkeyOurs, ::szINPROCSERVER32, &hkeyInproc);
  99. if (err == ERROR_SUCCESS)
  100. {
  101. DWORD dwType;
  102. CString strDLL;
  103. int cchNull;
  104. if ( RunningOnNT() )
  105. {
  106. dwType = REG_EXPAND_SZ;
  107. strDLL = CString( ::szNTRootDir ) + CString( ::szDLLNAME );
  108. cchNull = 0;
  109. }
  110. else
  111. {
  112. dwType = REG_SZ;
  113. strDLL = CString( ::sz9XRootDir ) + CString( ::szDLLNAME );
  114. TCHAR tchDLL[ MAX_PATH + 1 ];
  115. int cchDLL;
  116. tchDLL[0] = '\0';
  117. cchDLL = ::ExpandEnvironmentStrings( strDLL, tchDLL, MAX_PATH + 1 );
  118. if ( cchDLL == 0 || cchDLL > MAX_PATH || strDLL == tchDLL )
  119. {
  120. strDLL = ::szDLLNAME;
  121. }
  122. else
  123. {
  124. strDLL = tchDLL;
  125. }
  126. cchNull = 1;
  127. }
  128. err = ::RegSetValueEx(hkeyInproc, NULL, 0, dwType,
  129. (LPBYTE) (LPCTSTR) strDLL, strDLL.GetLength() + cchNull );
  130. if (err == ERROR_SUCCESS)
  131. {
  132. err = ::RegSetValueEx(hkeyInproc, ::szTHREADINGMODEL, 0,
  133. REG_SZ, (LPBYTE)::szAPARTMENT,
  134. ::strlenf(::szAPARTMENT) + cchNull );
  135. }
  136. ::RegCloseKey(hkeyInproc);
  137. }
  138. ::RegCloseKey(hkeyOurs);
  139. }
  140. ::RegCloseKey(hkeyCLSID);
  141. }
  142. CallRegInstall("InstallAssociations");
  143. if (err == ERROR_SUCCESS)
  144. return S_OK;
  145. else
  146. return HRESULT_FROM_WIN32(err);
  147. }
  148. STDAPI DllUnregisterServer(void)
  149. {
  150. HKEY hkeyCLSID;
  151. HKEY hkeyOurs;
  152. LONG err;
  153. err = ::RegOpenKey(HKEY_CLASSES_ROOT, ::szCLSID, &hkeyCLSID);
  154. if (err == ERROR_SUCCESS)
  155. {
  156. err = ::RegOpenKey(hkeyCLSID, ::szRORSGUID, &hkeyOurs);
  157. if (err == ERROR_SUCCESS)
  158. {
  159. err = ::RegDeleteKey(hkeyOurs, ::szINPROCSERVER32);
  160. ::RegCloseKey(hkeyOurs);
  161. if (err == ERROR_SUCCESS)
  162. {
  163. err = ::RegDeleteKey(hkeyCLSID, ::szRORSGUID);
  164. }
  165. }
  166. ::RegCloseKey(hkeyCLSID);
  167. }
  168. CallRegInstall("UnInstallAssociations");
  169. if (err == ERROR_SUCCESS)
  170. return S_OK;
  171. else
  172. return HRESULT_FROM_WIN32(err);
  173. }
  174. STDAPI DllCanUnloadNow(void)
  175. {
  176. SCODE sc;
  177. sc = (0 == g_cRefThisDll && 0 == g_cLocks) ? S_OK : S_FALSE;
  178. return ResultFromScode(sc);
  179. }
  180. STDAPI DllGetClassObject(
  181. REFCLSID rclsid,
  182. REFIID riid,
  183. LPVOID FAR *ppv)
  184. {
  185. if (!IsEqualCLSID(rclsid, CLSID_RemoteSite)) {
  186. return ResultFromScode(E_FAIL);
  187. }
  188. if (!IsEqualIID(riid, IID_IUnknown) &&
  189. !IsEqualIID(riid, IID_IClassFactory)) {
  190. return ResultFromScode(E_NOINTERFACE);
  191. }
  192. static CLUClassFactory cf;
  193. *ppv = (LPVOID)&cf;
  194. cf.AddRef();
  195. return NOERROR;
  196. }
  197. }; /* extern "C" */