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.

164 lines
4.7 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. #ifdef _MERGE_PROXYSTUB
  33. extern "C" HINSTANCE hProxyDll;
  34. #endif
  35. CComModule _Module;
  36. BEGIN_OBJECT_MAP(ObjectMap)
  37. OBJECT_ENTRY(CLSID_IISCertObj, CIISCertObj)
  38. END_OBJECT_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. // DLL Entry Point
  41. extern "C"
  42. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  43. {
  44. lpReserved;
  45. #ifdef _MERGE_PROXYSTUB
  46. if (!PrxDllMain(hInstance, dwReason, lpReserved))
  47. return FALSE;
  48. #endif
  49. if (dwReason == DLL_PROCESS_ATTACH)
  50. {
  51. _Module.Init(ObjectMap, hInstance, &LIBID_CERTOBJLib);
  52. DisableThreadLibraryCalls(hInstance);
  53. }
  54. else if (dwReason == DLL_PROCESS_DETACH)
  55. _Module.Term();
  56. return TRUE; // ok
  57. }
  58. /////////////////////////////////////////////////////////////////////////////
  59. // Used to determine whether the DLL can be unloaded by OLE
  60. STDAPI DllCanUnloadNow(void)
  61. {
  62. #ifdef _MERGE_PROXYSTUB
  63. if (PrxDllCanUnloadNow() != S_OK)
  64. return S_FALSE;
  65. #endif
  66. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  67. }
  68. /////////////////////////////////////////////////////////////////////////////
  69. // Returns a class factory to create an object of the requested type
  70. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  71. {
  72. #ifdef _MERGE_PROXYSTUB
  73. if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  74. return S_OK;
  75. #endif
  76. return _Module.GetClassObject(rclsid, riid, ppv);
  77. }
  78. /////////////////////////////////////////////////////////////////////////////
  79. // DllRegisterServer - Adds entries to the system registry
  80. STDAPI DllRegisterServer(void)
  81. {
  82. HRESULT hRes = E_FAIL;
  83. #ifdef _MERGE_PROXYSTUB
  84. hRes = PrxDllRegisterServer();
  85. if (FAILED(hRes))
  86. return hRes;
  87. #endif
  88. if (RunningAsAdministrator())
  89. {
  90. // Add the event log entry
  91. EventlogRegistryInstall();
  92. // registers object, typelib and all interfaces in typelib
  93. hRes = _Module.RegisterServer(TRUE);
  94. if (SUCCEEDED(hRes))
  95. {
  96. if (ERROR_SUCCESS != ChangeAppIDLaunchACL(TEXT("{62B8CCBE-5A45-4372-8C4A-6A87DD3EDD60}"),TEXT("Administrators"),TRUE,TRUE))
  97. {
  98. _Module.UnregisterServer(TRUE);
  99. hRes = E_FAIL;
  100. }
  101. else
  102. {
  103. if (ERROR_SUCCESS != ChangeAppIDAccessACL(TEXT("{62B8CCBE-5A45-4372-8C4A-6A87DD3EDD60}"),TEXT("Administrators"),TRUE,TRUE))
  104. {
  105. _Module.UnregisterServer(TRUE);
  106. hRes = E_FAIL;
  107. }
  108. else
  109. {
  110. hRes = S_OK;
  111. }
  112. }
  113. }
  114. }
  115. else
  116. {
  117. hRes = E_FAIL;
  118. }
  119. return hRes;
  120. }
  121. /////////////////////////////////////////////////////////////////////////////
  122. // DllUnregisterServer - Removes entries from the system registry
  123. STDAPI DllUnregisterServer(void)
  124. {
  125. HRESULT hRes = E_FAIL;
  126. #ifdef _MERGE_PROXYSTUB
  127. PrxDllUnregisterServer();
  128. #endif
  129. if (RunningAsAdministrator())
  130. {
  131. EventlogRegistryUnInstall();
  132. ChangeAppIDLaunchACL(TEXT("{62B8CCBE-5A45-4372-8C4A-6A87DD3EDD60}"),TEXT("Administrators"),FALSE,FALSE);
  133. ChangeAppIDLaunchACL(TEXT("{62B8CCBE-5A45-4372-8C4A-6A87DD3EDD60}"),TEXT("everyone"),FALSE,FALSE);
  134. ChangeAppIDAccessACL(TEXT("{62B8CCBE-5A45-4372-8C4A-6A87DD3EDD60}"),TEXT("Administrators"),FALSE,FALSE);
  135. ChangeAppIDAccessACL(TEXT("{62B8CCBE-5A45-4372-8C4A-6A87DD3EDD60}"),TEXT("everyone"),FALSE,FALSE);
  136. hRes = _Module.UnregisterServer(TRUE);
  137. }
  138. else
  139. {
  140. hRes = E_FAIL;
  141. }
  142. return hRes;
  143. }