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
5.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: init.c
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 8-01-95 RichardW Created
  15. // 8-13-95 TerenceS Mutated to PCT
  16. //
  17. //----------------------------------------------------------------------------
  18. #include "sslp.h"
  19. #include <basetyps.h>
  20. #include <oidenc.h>
  21. #include <userenv.h>
  22. RTL_CRITICAL_SECTION g_InitCritSec;
  23. BOOL g_fSchannelInitialized = FALSE;
  24. void LoadSecurityDll(void);
  25. void UnloadSecurityDll(void);
  26. // MyStrToL
  27. // Can't use CRT routines, so steal from the C runtime sources
  28. DWORD MyStrToL(CHAR *InStr)
  29. {
  30. DWORD dwVal = 0;
  31. while(*InStr)
  32. {
  33. dwVal = (10 * dwVal) + (*InStr - '0');
  34. InStr++;
  35. }
  36. return dwVal;
  37. }
  38. /*++
  39. Routine Description:
  40. This routine checks whether encryption is getting the system default
  41. LCID and checking whether the country code is CTRY_FRANCE.
  42. --*/
  43. void
  44. IsSchEncryptionPermitted(VOID)
  45. {
  46. LCID DefaultLcid;
  47. CHAR CountryCode[10];
  48. ULONG CountryValue;
  49. BOOL fAllowed = TRUE;
  50. DefaultLcid = GetSystemDefaultLCID();
  51. //
  52. // Check if the default language is Standard French
  53. //
  54. if (LANGIDFROMLCID(DefaultLcid) == 0x40c)
  55. {
  56. fAllowed = FALSE;
  57. goto Ret;
  58. }
  59. //
  60. // Check if the users's country is set to FRANCE
  61. //
  62. if (GetLocaleInfoA(DefaultLcid,LOCALE_ICOUNTRY,CountryCode,10) == 0)
  63. {
  64. fAllowed = FALSE;
  65. goto Ret;
  66. }
  67. CountryValue = (ULONG) MyStrToL(CountryCode);
  68. if (CountryValue == CTRY_FRANCE)
  69. {
  70. fAllowed = FALSE;
  71. }
  72. Ret:
  73. if(FALSE == fAllowed)
  74. {
  75. // Disable PCT in France.
  76. g_ProtEnabled &= ~(SP_PROT_PCT1);
  77. g_fFranceLocale = TRUE;
  78. }
  79. }
  80. /*****************************************************************************/
  81. BOOL
  82. SchannelInit(BOOL fAppProcess)
  83. {
  84. DWORD Status;
  85. if(g_fSchannelInitialized) return TRUE;
  86. RtlEnterCriticalSection(&g_InitCritSec);
  87. if(g_fSchannelInitialized)
  88. {
  89. RtlLeaveCriticalSection(&g_InitCritSec);
  90. return TRUE;
  91. }
  92. DisableThreadLibraryCalls( g_hInstance );
  93. SafeAllocaInitialize(SAFEALLOCA_USE_DEFAULT, SAFEALLOCA_USE_DEFAULT, NULL, NULL);
  94. // Read configuration parameters from registry.
  95. if(!fAppProcess)
  96. {
  97. IsSchEncryptionPermitted();
  98. SPLoadRegOptions();
  99. }
  100. #if DBG
  101. else
  102. {
  103. InitDebugSupport(NULL);
  104. }
  105. #endif
  106. if(!fAppProcess)
  107. {
  108. SchInitializeEvents();
  109. }
  110. if(!CryptAcquireContextA(&g_hRsaSchannel,
  111. NULL,
  112. NULL,
  113. PROV_RSA_SCHANNEL,
  114. CRYPT_VERIFYCONTEXT))
  115. {
  116. g_hRsaSchannel = 0;
  117. Status = GetLastError();
  118. DebugLog((DEB_ERROR, "Could not open static PROV_RSA_SCHANNEL: %x\n", Status));
  119. if(!fAppProcess)
  120. {
  121. LogGlobalAcquireContextFailedEvent(L"RSA", Status);
  122. }
  123. RtlLeaveCriticalSection(&g_InitCritSec);
  124. return FALSE;
  125. }
  126. if(!fAppProcess && g_hRsaSchannel)
  127. {
  128. GetSupportedCapiAlgs(g_hRsaSchannel,
  129. &g_pRsaSchannelAlgs,
  130. &g_cRsaSchannelAlgs);
  131. }
  132. if(!CryptAcquireContext(&g_hDhSchannelProv,
  133. NULL,
  134. NULL,
  135. PROV_DH_SCHANNEL,
  136. CRYPT_VERIFYCONTEXT))
  137. {
  138. g_hDhSchannelProv = 0;
  139. Status = GetLastError();
  140. DebugLog((DEB_WARN, "Could not open PROV_DH_SCHANNEL: %x\n", Status));
  141. if(!fAppProcess)
  142. {
  143. LogGlobalAcquireContextFailedEvent(L"DSS", Status);
  144. }
  145. CryptReleaseContext(g_hRsaSchannel, 0);
  146. RtlLeaveCriticalSection(&g_InitCritSec);
  147. return FALSE;
  148. }
  149. if(!fAppProcess && g_hDhSchannelProv)
  150. {
  151. GetSupportedCapiAlgs(g_hDhSchannelProv,
  152. &g_pDhSchannelAlgs,
  153. &g_cDhSchannelAlgs);
  154. }
  155. InitSchannelAsn1(g_hInstance);
  156. LoadSecurityDll();
  157. if(!fAppProcess)
  158. {
  159. SPInitSessionCache();
  160. SslInitCredentialManager();
  161. SslInitSystemMapper();
  162. }
  163. g_fSchannelInitialized = TRUE;
  164. if(!fAppProcess)
  165. {
  166. LogSchannelStartedEvent();
  167. }
  168. RtlLeaveCriticalSection(&g_InitCritSec);
  169. return TRUE;
  170. }
  171. BOOL SchannelShutdown(VOID)
  172. {
  173. BOOL fAppProcess = (LsaTable == NULL);
  174. RtlEnterCriticalSection(&g_InitCritSec);
  175. if(!g_fSchannelInitialized)
  176. {
  177. RtlLeaveCriticalSection(&g_InitCritSec);
  178. return TRUE;
  179. }
  180. SPShutdownSessionCache();
  181. UnloadSecurityDll();
  182. if(!fAppProcess)
  183. {
  184. SslFreeCredentialManager();
  185. }
  186. ShutdownSchannelAsn1();
  187. SchShutdownEvents();
  188. SPUnloadRegOptions();
  189. g_fSchannelInitialized = FALSE;
  190. RtlLeaveCriticalSection(&g_InitCritSec);
  191. return TRUE;
  192. }
  193. HINSTANCE g_hSecur32;
  194. FREE_CONTEXT_BUFFER_FN g_pFreeContextBuffer;
  195. void LoadSecurityDll(void)
  196. {
  197. g_hSecur32 = LoadLibrary(TEXT("secur32.dll"));
  198. if(g_hSecur32)
  199. {
  200. g_pFreeContextBuffer = (FREE_CONTEXT_BUFFER_FN)GetProcAddress(
  201. g_hSecur32,
  202. "FreeContextBuffer");
  203. }
  204. else
  205. {
  206. g_pFreeContextBuffer = NULL;
  207. }
  208. }
  209. void UnloadSecurityDll(void)
  210. {
  211. if(g_hSecur32)
  212. {
  213. FreeLibrary(g_hSecur32);
  214. }
  215. }