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.

200 lines
4.7 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: certpdef.cpp
  7. //
  8. // Contents: Cert Server Policy Module implementation
  9. //
  10. //---------------------------------------------------------------------------
  11. #include "pch.cpp"
  12. #pragma hdrstop
  13. #include "resource.h"
  14. #include "policy.h"
  15. #include "module.h"
  16. #define __dwFILE__ __dwFILE_POLICY_DEFAULT_CERTPDEF_CPP__
  17. CComModule _Module;
  18. BEGIN_OBJECT_MAP(ObjectMap)
  19. OBJECT_ENTRY(CLSID_CCertPolicy, CCertPolicyEnterprise)
  20. OBJECT_ENTRY(CLSID_CCertManagePolicyModule, CCertManagePolicyModule)
  21. END_OBJECT_MAP()
  22. #define EVENT_SOURCE_LOCATION L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\"
  23. #define EVENT_SOURCE_NAME L"CertEnterprisePolicy"
  24. HANDLE g_hEventLog = NULL;
  25. HINSTANCE g_hInstance = NULL;
  26. /////////////////////////////////////////////////////////////////////////////
  27. // DLL Entry Point
  28. extern "C"
  29. BOOL WINAPI
  30. DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  31. {
  32. switch (dwReason)
  33. {
  34. case DLL_PROCESS_ATTACH:
  35. _Module.Init(ObjectMap, hInstance);
  36. g_hEventLog = RegisterEventSource(NULL, EVENT_SOURCE_NAME);
  37. g_hInstance = hInstance;
  38. DisableThreadLibraryCalls(hInstance);
  39. break;
  40. case DLL_PROCESS_DETACH:
  41. if(g_hEventLog)
  42. {
  43. DeregisterEventSource(g_hEventLog);
  44. g_hEventLog = NULL;
  45. }
  46. _Module.Term();
  47. break;
  48. }
  49. return(TRUE); // ok
  50. }
  51. /////////////////////////////////////////////////////////////////////////////
  52. // Used to determine whether the DLL can be unloaded by OLE
  53. STDAPI
  54. DllCanUnloadNow(void)
  55. {
  56. return(_Module.GetLockCount() == 0? S_OK : S_FALSE);
  57. }
  58. /////////////////////////////////////////////////////////////////////////////
  59. // Returns a class factory to create an object of the requested type
  60. STDAPI
  61. DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  62. {
  63. HRESULT hr;
  64. hr = _Module.GetClassObject(rclsid, riid, ppv);
  65. if (S_OK == hr && NULL != ppv && NULL != *ppv)
  66. {
  67. myRegisterMemFree(*ppv, CSM_NEW | CSM_GLOBALDESTRUCTOR);
  68. }
  69. return(hr);
  70. }
  71. /////////////////////////////////////////////////////////////////////////////
  72. // DllRegisterServer - Adds entries to the system registry
  73. STDAPI
  74. DllRegisterServer(void)
  75. {
  76. HRESULT hr;
  77. HRESULT hr2;
  78. HKEY hkey = NULL;
  79. DWORD disp;
  80. DWORD dwData;
  81. LPWSTR wszModuleLocation = L"%SystemRoot%\\System32\\certpdef.dll";
  82. // wrap delayloaded func with try/except
  83. hr = S_OK;
  84. __try
  85. {
  86. // registers object, typelib and all interfaces in typelib
  87. // Register the event logging
  88. hr = RegCreateKeyEx(
  89. HKEY_LOCAL_MACHINE,
  90. EVENT_SOURCE_LOCATION EVENT_SOURCE_NAME,
  91. NULL,
  92. TEXT(""),
  93. REG_OPTION_NON_VOLATILE,
  94. KEY_ALL_ACCESS,
  95. NULL,
  96. &hkey,
  97. &disp);
  98. _LeaveIfError(hr, "RegCreateKeyEx");
  99. hr = RegSetValueEx(
  100. hkey, // subkey handle
  101. L"EventMessageFile", // value name
  102. 0,
  103. REG_EXPAND_SZ,
  104. (LPBYTE) wszModuleLocation, // pointer to value data
  105. sizeof(WCHAR) * (wcslen(wszModuleLocation) + 1));
  106. _LeaveIfError(hr, "RegSetValueEx");
  107. dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
  108. EVENTLOG_INFORMATION_TYPE;
  109. hr = RegSetValueEx(
  110. hkey,
  111. L"TypesSupported", // value name
  112. 0,
  113. REG_DWORD,
  114. (LPBYTE) &dwData, // pointer to value data
  115. sizeof(DWORD));
  116. _LeaveIfError(hr, "RegSetValueEx");
  117. }
  118. __except(hr = myHEXCEPTIONCODE(), EXCEPTION_EXECUTE_HANDLER)
  119. {
  120. _PrintError(hr, "Exception");
  121. }
  122. hr2 = _Module.RegisterServer(TRUE);
  123. _PrintIfError(hr2, "_Module.RegisterServer");
  124. if (S_OK == hr)
  125. {
  126. hr = hr2;
  127. }
  128. if (NULL != hkey)
  129. {
  130. RegCloseKey(hkey);
  131. }
  132. return(myHError(hr));
  133. }
  134. /////////////////////////////////////////////////////////////////////////////
  135. // DllUnregisterServer - Removes entries from the system registry
  136. STDAPI
  137. DllUnregisterServer(void)
  138. {
  139. // wrap delayloaded func with try/except
  140. HRESULT hr;
  141. hr = S_OK;
  142. __try
  143. {
  144. hr = RegDeleteKey(
  145. HKEY_LOCAL_MACHINE,
  146. EVENT_SOURCE_LOCATION EVENT_SOURCE_NAME);
  147. }
  148. __except(hr = myHEXCEPTIONCODE(), EXCEPTION_EXECUTE_HANDLER)
  149. {
  150. _PrintError(hr, "Exception");
  151. }
  152. _Module.UnregisterServer();
  153. return(S_OK);
  154. }
  155. void __RPC_FAR *__RPC_USER
  156. MIDL_user_allocate(size_t cb)
  157. {
  158. return(LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, cb));
  159. }
  160. void __RPC_USER
  161. MIDL_user_free(void __RPC_FAR *pb)
  162. {
  163. LocalFree(pb);
  164. }