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.

217 lines
6.9 KiB

  1. // CertObj.cpp : Implementation of DLL Exports.
  2. // Note: Proxy/Stub Information
  3. // To merge the proxy/stub code into the object DLL, add the file
  4. // dlldatax.c to the project. Make sure precompiled headers
  5. // are turned off for this file, and add _MERGE_PROXYSTUB to the
  6. // defines for the project.
  7. //
  8. // If you are not running WinNT4.0 or Win95 with DCOM, then you
  9. // need to remove the following define from dlldatax.c
  10. // #define _WIN32_WINNT 0x0400
  11. //
  12. // Further, if you are running MIDL without /Oicf switch, you also
  13. // need to remove the following define from dlldatax.c.
  14. // #define USE_STUBLESS_PROXY
  15. //
  16. // Modify the custom build rule for CertObj.idl by adding the following
  17. // files to the Outputs.
  18. // CertObj_p.c
  19. // dlldata.c
  20. // To build a separate proxy/stub DLL,
  21. // run nmake -f CertObjps.mk in the project directory.
  22. #include "stdafx.h"
  23. #include "resource.h"
  24. #include <initguid.h>
  25. #include "dlldatax.h"
  26. #include "common.h"
  27. #include "CertObj.h"
  28. #include "CertObj_i.c"
  29. #include "IISCertObj.h"
  30. #include "certlog.h"
  31. #include "dcomperm.h"
  32. #include "IISCertRequest.h"
  33. #include <strsafe.h>
  34. #ifdef _MERGE_PROXYSTUB
  35. extern "C" HINSTANCE hProxyDll;
  36. #endif
  37. CComModule _Module;
  38. #ifdef USE_CERT_REQUEST_OBJECT
  39. BEGIN_OBJECT_MAP(ObjectMap)
  40. OBJECT_ENTRY(CLSID_IISCertObj, CIISCertObj)
  41. OBJECT_ENTRY(CLSID_IISCertRequest, CIISCertRequest)
  42. END_OBJECT_MAP()
  43. #else
  44. BEGIN_OBJECT_MAP(ObjectMap)
  45. OBJECT_ENTRY(CLSID_IISCertObj, CIISCertObj)
  46. END_OBJECT_MAP()
  47. #endif
  48. /////////////////////////////////////////////////////////////////////////////
  49. // DLL Entry Point
  50. extern "C"
  51. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  52. {
  53. lpReserved;
  54. #ifdef _MERGE_PROXYSTUB
  55. if (!PrxDllMain(hInstance, dwReason, lpReserved))
  56. return FALSE;
  57. #endif
  58. if (dwReason == DLL_PROCESS_ATTACH)
  59. {
  60. _Module.Init(ObjectMap, hInstance, &LIBID_CERTOBJLib);
  61. DisableThreadLibraryCalls(hInstance);
  62. GetOutputDebugFlag();
  63. }
  64. else if (dwReason == DLL_PROCESS_DETACH)
  65. _Module.Term();
  66. return TRUE; // ok
  67. }
  68. /////////////////////////////////////////////////////////////////////////////
  69. // Used to determine whether the DLL can be unloaded by OLE
  70. STDAPI DllCanUnloadNow(void)
  71. {
  72. #ifdef _MERGE_PROXYSTUB
  73. if (PrxDllCanUnloadNow() != S_OK)
  74. return S_FALSE;
  75. #endif
  76. IISDebugOutput(_T("DllCanUnloadNow?:%s\r\n"),_Module.GetLockCount()==0 ? _T("Yes") : _T("No"));
  77. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  78. }
  79. /////////////////////////////////////////////////////////////////////////////
  80. // Returns a class factory to create an object of the requested type
  81. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  82. {
  83. #ifdef _MERGE_PROXYSTUB
  84. if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  85. return S_OK;
  86. #endif
  87. IISDebugOutput(_T("DllGetClassObject\r\n"));
  88. return _Module.GetClassObject(rclsid, riid, ppv);
  89. }
  90. /////////////////////////////////////////////////////////////////////////////
  91. // DllRegisterServer - Adds entries to the system registry
  92. STDAPI DllRegisterServer(void)
  93. {
  94. HRESULT hRes = E_FAIL;
  95. #ifdef _MERGE_PROXYSTUB
  96. hRes = PrxDllRegisterServer();
  97. if (FAILED(hRes))
  98. return hRes;
  99. #endif
  100. if (RunningAsAdministrator())
  101. {
  102. // Add the event log entry
  103. EventlogRegistryInstall();
  104. // registers object, typelib and all interfaces in typelib
  105. hRes = _Module.RegisterServer(TRUE);
  106. if (SUCCEEDED(hRes))
  107. {
  108. if (ERROR_SUCCESS != ChangeAppIDLaunchACL(TEXT("{62B8CCBE-5A45-4372-8C4A-6A87DD3EDD60}"),TEXT("Administrators"),TRUE,TRUE))
  109. {
  110. _Module.UnregisterServer(TRUE);
  111. hRes = E_FAIL;
  112. }
  113. else
  114. {
  115. if (ERROR_SUCCESS != ChangeAppIDAccessACL(TEXT("{62B8CCBE-5A45-4372-8C4A-6A87DD3EDD60}"),TEXT("Administrators"),TRUE,TRUE))
  116. {
  117. _Module.UnregisterServer(TRUE);
  118. hRes = E_FAIL;
  119. }
  120. else
  121. {
  122. // make sure only the highest level of authentication is accepted.
  123. if (ERROR_SUCCESS != ChangeAppIDAuthenticationLevel(TEXT("{62B8CCBE-5A45-4372-8C4A-6A87DD3EDD60}"),RPC_C_AUTHN_LEVEL_PKT_PRIVACY))
  124. {
  125. _Module.UnregisterServer(TRUE);
  126. hRes = E_FAIL;
  127. }
  128. else
  129. {
  130. hRes = S_OK;
  131. }
  132. }
  133. }
  134. #ifdef USE_CERT_REQUEST_OBJECT
  135. if (ERROR_SUCCESS != ChangeAppIDLaunchACL(TEXT("{2B024027-594E-4D11-88EE-15F5AE28AC61}"),TEXT("Administrators"),TRUE,TRUE))
  136. {
  137. _Module.UnregisterServer(TRUE);
  138. hRes = E_FAIL;
  139. }
  140. else
  141. {
  142. if (ERROR_SUCCESS != ChangeAppIDAccessACL(TEXT("{2B024027-594E-4D11-88EE-15F5AE28AC61}"),TEXT("Administrators"),TRUE,TRUE))
  143. {
  144. _Module.UnregisterServer(TRUE);
  145. hRes = E_FAIL;
  146. }
  147. else
  148. {
  149. hRes = S_OK;
  150. }
  151. }
  152. #endif
  153. }
  154. }
  155. else
  156. {
  157. hRes = E_FAIL;
  158. }
  159. return hRes;
  160. }
  161. /////////////////////////////////////////////////////////////////////////////
  162. // DllUnregisterServer - Removes entries from the system registry
  163. STDAPI DllUnregisterServer(void)
  164. {
  165. HRESULT hRes = E_FAIL;
  166. #ifdef _MERGE_PROXYSTUB
  167. PrxDllUnregisterServer();
  168. #endif
  169. if (RunningAsAdministrator())
  170. {
  171. EventlogRegistryUnInstall();
  172. ChangeAppIDLaunchACL(TEXT("{62B8CCBE-5A45-4372-8C4A-6A87DD3EDD60}"),TEXT("Administrators"),FALSE,FALSE);
  173. ChangeAppIDLaunchACL(TEXT("{62B8CCBE-5A45-4372-8C4A-6A87DD3EDD60}"),TEXT("everyone"),FALSE,FALSE);
  174. ChangeAppIDAccessACL(TEXT("{62B8CCBE-5A45-4372-8C4A-6A87DD3EDD60}"),TEXT("Administrators"),FALSE,FALSE);
  175. ChangeAppIDAccessACL(TEXT("{62B8CCBE-5A45-4372-8C4A-6A87DD3EDD60}"),TEXT("everyone"),FALSE,FALSE);
  176. #ifdef USE_CERT_REQUEST_OBJECT
  177. ChangeAppIDLaunchACL(TEXT("{2B024027-594E-4D11-88EE-15F5AE28AC61}"),TEXT("Administrators"),FALSE,FALSE);
  178. ChangeAppIDLaunchACL(TEXT("{2B024027-594E-4D11-88EE-15F5AE28AC61}"),TEXT("everyone"),FALSE,FALSE);
  179. ChangeAppIDAccessACL(TEXT("{2B024027-594E-4D11-88EE-15F5AE28AC61}"),TEXT("Administrators"),FALSE,FALSE);
  180. ChangeAppIDAccessACL(TEXT("{2B024027-594E-4D11-88EE-15F5AE28AC61}"),TEXT("everyone"),FALSE,FALSE);
  181. #endif
  182. hRes = _Module.UnregisterServer(TRUE);
  183. }
  184. else
  185. {
  186. hRes = E_FAIL;
  187. }
  188. return hRes;
  189. }