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.

264 lines
5.6 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: certcli.cpp
  7. //
  8. // Contents: Cert Server client implementation
  9. //
  10. // History: 24-Aug-96 vich created
  11. //
  12. //---------------------------------------------------------------------------
  13. #include "pch.cpp"
  14. #pragma hdrstop
  15. #include "certsrvd.h"
  16. #include "configp.h"
  17. #include "config.h"
  18. #include "getconf.h"
  19. #include "request.h"
  20. #include "certtype.h"
  21. #include "csif.h" // CertIf includes
  22. #include "csprxy.h" // CertPrxy includes
  23. #include "resource.h"
  24. #include "csresstr.h"
  25. HINSTANCE g_hInstance = NULL;
  26. extern CRITICAL_SECTION g_csDomainSidCache;
  27. extern CRITICAL_SECTION g_csOidURL;
  28. extern BOOL g_fInitDone = FALSE;
  29. extern BOOL g_fOidURL = FALSE;
  30. CComModule _Module;
  31. BEGIN_OBJECT_MAP(ObjectMap)
  32. OBJECT_ENTRY(CLSID_CCertConfig, CCertConfig)
  33. OBJECT_ENTRY(CLSID_CCertGetConfig, CCertGetConfig)
  34. OBJECT_ENTRY(CLSID_CCertRequest, CCertRequest)
  35. #include "csifm.h" // CertIf object map entries
  36. END_OBJECT_MAP()
  37. /////////////////////////////////////////////////////////////////////////////
  38. // DLL Entry Point
  39. extern "C"
  40. BOOL WINAPI
  41. DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  42. {
  43. BOOL fRet = TRUE; // assume OK
  44. __try
  45. {
  46. fRet = CertPrxyDllMain(hInstance, dwReason, lpReserved);
  47. switch (dwReason)
  48. {
  49. case DLL_PROCESS_ATTACH:
  50. myVerifyResourceStrings(hInstance);
  51. _Module.Init(ObjectMap, hInstance);
  52. DisableThreadLibraryCalls(hInstance);
  53. g_hInstance = hInstance;
  54. InitializeCriticalSection(&g_csDomainSidCache);
  55. g_fInitDone = TRUE;
  56. InitializeCriticalSection(&g_csOidURL);
  57. g_fOidURL = TRUE;
  58. break;
  59. case DLL_PROCESS_DETACH:
  60. myFreeColumnDisplayNames();
  61. if (g_fOidURL)
  62. {
  63. DeleteCriticalSection(&g_csOidURL);
  64. }
  65. if (g_fInitDone)
  66. {
  67. DeleteCriticalSection(&g_csDomainSidCache);
  68. }
  69. _Module.Term();
  70. g_hInstance = NULL;
  71. break;
  72. }
  73. }
  74. __except(EXCEPTION_EXECUTE_HANDLER)
  75. {
  76. // return failure
  77. fRet = FALSE;
  78. }
  79. return(fRet);
  80. }
  81. /////////////////////////////////////////////////////////////////////////////
  82. // Used to determine whether the DLL can be unloaded by OLE
  83. STDAPI
  84. DllCanUnloadNow(void)
  85. {
  86. return(
  87. (S_OK == CertPrxyDllCanUnloadNow() && 0 == _Module.GetLockCount())?
  88. S_OK : S_FALSE);
  89. }
  90. /////////////////////////////////////////////////////////////////////////////
  91. // Returns a class factory to create an object of the requested type
  92. STDAPI
  93. DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  94. {
  95. HRESULT hr;
  96. hr = CertPrxyDllGetClassObject(rclsid, riid, ppv);
  97. if (S_OK != hr)
  98. {
  99. hr = _Module.GetClassObject(rclsid, riid, ppv);
  100. if (S_OK == hr && NULL != *ppv)
  101. {
  102. myRegisterMemFree(*ppv, CSM_NEW | CSM_GLOBALDESTRUCTOR);
  103. }
  104. }
  105. return(hr);
  106. }
  107. /////////////////////////////////////////////////////////////////////////////
  108. // DllRegisterServer - Adds entries to the system registry
  109. STDAPI
  110. DllRegisterServer(void)
  111. {
  112. HRESULT hr;
  113. HRESULT hr2;
  114. HKEY hGPOExtensions;
  115. // we remove the registration of GPO Processing call backs. This was
  116. // intended for upgrading B2 clients.
  117. hr = RegOpenKeyEx(
  118. HKEY_LOCAL_MACHINE,
  119. TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\GPExtensions"),
  120. 0,
  121. KEY_WRITE | KEY_READ,
  122. &hGPOExtensions);
  123. if (S_OK == hr)
  124. {
  125. RegDeleteKey(hGPOExtensions, TEXT("PublicKeyPolicy"));
  126. RegCloseKey(hGPOExtensions);
  127. }
  128. hr = CertPrxyDllRegisterServer();
  129. // registers object, typelib and all interfaces in typelib
  130. hr2 = _Module.RegisterServer(TRUE);
  131. if (S_OK == hr)
  132. {
  133. hr = hr2;
  134. }
  135. //register the evenlog
  136. hr2 = myAddLogSourceToRegistry(L"%SystemRoot%\\System32\\pautoenr.dll",
  137. L"AutoEnrollment");
  138. if (S_OK == hr)
  139. {
  140. hr = hr2;
  141. }
  142. return(hr);
  143. }
  144. /////////////////////////////////////////////////////////////////////////////
  145. // DllUnregisterServer - Removes entries from the system registry
  146. STDAPI
  147. DllUnregisterServer(void)
  148. {
  149. HRESULT hr;
  150. HRESULT hr2;
  151. HKEY hGPOExtensions;
  152. hr = RegOpenKeyEx(
  153. HKEY_LOCAL_MACHINE,
  154. TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\GPExtensions"),
  155. 0,
  156. KEY_WRITE | KEY_READ,
  157. &hGPOExtensions);
  158. if (S_OK == hr)
  159. {
  160. hr = RegDeleteKey(hGPOExtensions, TEXT("PublicKeyPolicy"));
  161. RegCloseKey(hGPOExtensions);
  162. }
  163. hr = CertPrxyDllUnregisterServer();
  164. hr2 = _Module.UnregisterServer();
  165. if (S_OK == hr)
  166. {
  167. hr = hr2;
  168. }
  169. return(hr);
  170. }
  171. // Register certcli.dll with the following command line to install templates:
  172. // regsvr32 /i:i /n certcli.dll
  173. STDAPI
  174. DllInstall(BOOL bInstall, LPCWSTR pszCmdLine)
  175. {
  176. LONG lResult;
  177. LPCWSTR wszCurrentCmd = pszCmdLine;
  178. // parse the cmd line
  179. while(wszCurrentCmd && *wszCurrentCmd)
  180. {
  181. while(*wszCurrentCmd == L' ')
  182. wszCurrentCmd++;
  183. if(*wszCurrentCmd == 0)
  184. break;
  185. switch(*wszCurrentCmd++)
  186. {
  187. case L'i':
  188. CCertTypeInfo::InstallDefaultTypes();
  189. return S_OK;
  190. }
  191. }
  192. return S_OK;
  193. }
  194. void __RPC_FAR *__RPC_USER
  195. MIDL_user_allocate(
  196. IN size_t cb)
  197. {
  198. return(CoTaskMemAlloc(cb));
  199. }
  200. void __RPC_USER
  201. MIDL_user_free(
  202. IN void __RPC_FAR *pb)
  203. {
  204. CoTaskMemFree(pb);
  205. }
  206. VOID
  207. myFreeColumnDisplayNames()
  208. {
  209. extern VOID myFreeColumnDisplayNames2();
  210. CACleanup();
  211. myFreeColumnDisplayNames2();
  212. myFreeResourceStrings("certcli.dll");
  213. }