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.

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