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.

490 lines
14 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: package.c
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 10-02-96 RichardW Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "sslp.h"
  18. #include <ntmsv1_0.h>
  19. #include <wow64t.h>
  20. #define UNISP_NAME_WO L"Microsoft Unified Security Protocol Provider"
  21. #define SSL2SP_NAME_WO L"Microsoft SSL"
  22. #define SSL3SP_NAME_WO L"Microsoft SSL 3.0"
  23. #define PCT1SP_NAME_WO L"Microsoft PCT"
  24. #define SCHANNEL_PACKAGE_NAME L"Schannel"
  25. #define SCHANNEL_PACKAGE_NAME_A "Schannel"
  26. #define SCHANNEL_PACKAGE_COMMENT L"Schannel Security Package"
  27. #define SCHANNEL_DLL_NAME L"schannel.dll"
  28. DWORD dwSchannelPackageCapabilities = SECPKG_FLAG_INTEGRITY |
  29. SECPKG_FLAG_PRIVACY |
  30. SECPKG_FLAG_CONNECTION |
  31. SECPKG_FLAG_MULTI_REQUIRED |
  32. SECPKG_FLAG_EXTENDED_ERROR |
  33. SECPKG_FLAG_IMPERSONATION |
  34. SECPKG_FLAG_ACCEPT_WIN32_NAME |
  35. // SECPKG_FLAG_NEGOTIABLE |
  36. SECPKG_FLAG_MUTUAL_AUTH |
  37. SECPKG_FLAG_STREAM;
  38. // List of (QueryContextAttributes) attributes that are to be
  39. // thunked down to the LSA process.
  40. ULONG ThunkedContextLevels[] = {
  41. SECPKG_ATTR_AUTHORITY,
  42. SECPKG_ATTR_ISSUER_LIST,
  43. SECPKG_ATTR_ISSUER_LIST_EX,
  44. SECPKG_ATTR_LOCAL_CERT_CONTEXT,
  45. SECPKG_ATTR_LOCAL_CRED,
  46. SECPKG_ATTR_EAP_KEY_BLOCK,
  47. SECPKG_ATTR_USE_VALIDATED,
  48. SECPKG_ATTR_CREDENTIAL_NAME,
  49. SECPKG_ATTR_TARGET_INFORMATION,
  50. SECPKG_ATTR_APP_DATA
  51. };
  52. //
  53. // This package exports the following: A unified ssl/tls/pct provider,
  54. // and the same unified provider under a different name. We have to
  55. // keep the original one for backward compatibility, but whistler
  56. // components can start using the new friendlier name.
  57. //
  58. SECPKG_FUNCTION_TABLE SpTable[] = {
  59. { // The Schannel Provider
  60. NULL,
  61. NULL,
  62. SpCallPackage,
  63. SpLogonTerminated,
  64. SpCallPackageUntrusted,
  65. SpCallPackagePassthrough,
  66. NULL,
  67. NULL,
  68. SpInitialize,
  69. SpShutdown,
  70. SpSslGetInfo,
  71. SpAcceptCredentials,
  72. SpUniAcquireCredentialsHandle,
  73. SpQueryCredentialsAttributes,
  74. SpFreeCredentialsHandle,
  75. SpSaveCredentials,
  76. SpGetCredentials,
  77. SpDeleteCredentials,
  78. SpInitLsaModeContext,
  79. SpAcceptLsaModeContext,
  80. SpDeleteContext,
  81. SpApplyControlToken,
  82. SpGetUserInfo,
  83. SpGetExtendedInformation,
  84. SpLsaQueryContextAttributes,
  85. NULL,
  86. NULL,
  87. SpSetContextAttributes
  88. },
  89. { // The Unified Provider
  90. NULL,
  91. NULL,
  92. SpCallPackage,
  93. SpLogonTerminated,
  94. SpCallPackageUntrusted,
  95. SpCallPackagePassthrough,
  96. NULL,
  97. NULL,
  98. SpInitialize,
  99. SpShutdown,
  100. SpUniGetInfo,
  101. SpAcceptCredentials,
  102. SpUniAcquireCredentialsHandle,
  103. SpQueryCredentialsAttributes,
  104. SpFreeCredentialsHandle,
  105. SpSaveCredentials,
  106. SpGetCredentials,
  107. SpDeleteCredentials,
  108. SpInitLsaModeContext,
  109. SpAcceptLsaModeContext,
  110. SpDeleteContext,
  111. SpApplyControlToken,
  112. SpGetUserInfo,
  113. SpGetExtendedInformation,
  114. SpLsaQueryContextAttributes,
  115. NULL,
  116. NULL,
  117. SpSetContextAttributes
  118. }
  119. };
  120. ULONG_PTR SpPackageId;
  121. PLSA_SECPKG_FUNCTION_TABLE LsaTable ;
  122. BOOL SpInitialized = FALSE ;
  123. HINSTANCE hDllInstance ;
  124. BOOL ReplaceBaseProvider = TRUE;
  125. TOKEN_SOURCE SslTokenSource ;
  126. SECURITY_STRING SslNamePrefix = { 8, 10, L"X509" };
  127. SECURITY_STRING SslDomainName ;
  128. SECURITY_STRING SslGlobalDnsDomainName ;
  129. SECURITY_STRING SslPackageName ;
  130. SECURITY_STRING SslLegacyPackageName ;
  131. LSA_STRING SslPackageNameA ;
  132. RTL_RESOURCE SslGlobalLock;
  133. //+---------------------------------------------------------------------------
  134. //
  135. // Function: SpLsaModeInitialize
  136. //
  137. // Synopsis: LSA Mode Initialization Function
  138. //
  139. // Arguments: [LsaVersion] --
  140. // [PackageVersion] --
  141. // [Table] --
  142. // [TableCount] --
  143. //
  144. // History: 10-03-96 RichardW Created
  145. //
  146. // Notes:
  147. //
  148. //----------------------------------------------------------------------------
  149. SECURITY_STATUS
  150. SEC_ENTRY
  151. SpLsaModeInitialize(
  152. IN ULONG LsaVersion,
  153. OUT PULONG PackageVersion,
  154. OUT PSECPKG_FUNCTION_TABLE * Table,
  155. OUT PULONG TableCount)
  156. {
  157. UNREFERENCED_PARAMETER(LsaVersion);
  158. *PackageVersion = SECPKG_INTERFACE_VERSION_2;
  159. *Table = SpTable ;
  160. *TableCount = sizeof( SpTable ) / sizeof( SECPKG_FUNCTION_TABLE );
  161. return( SEC_E_OK );
  162. }
  163. //+---------------------------------------------------------------------------
  164. //
  165. // Function: SpInitialize
  166. //
  167. // Synopsis: Package Initialization Function
  168. //
  169. // Arguments: [dwPackageID] --
  170. // [pParameters] --
  171. // [Table] --
  172. //
  173. // History: 10-03-96 RichardW Created
  174. //
  175. // Notes:
  176. //
  177. //----------------------------------------------------------------------------
  178. SECURITY_STATUS
  179. SEC_ENTRY
  180. SpInitialize(
  181. ULONG_PTR dwPackageID,
  182. PSECPKG_PARAMETERS pParameters,
  183. PLSA_SECPKG_FUNCTION_TABLE Table)
  184. {
  185. if ( !SpInitialized )
  186. {
  187. SpPackageId = dwPackageID ;
  188. LsaTable = Table ;
  189. CopyMemory( SslTokenSource.SourceName, SCHANNEL_PACKAGE_NAME_A, 8 );
  190. AllocateLocallyUniqueId( &SslTokenSource.SourceIdentifier );
  191. SslDuplicateString( &SslDomainName, &pParameters->DomainName );
  192. SslDuplicateString( &SslGlobalDnsDomainName, &pParameters->DnsDomainName );
  193. RtlInitUnicodeString( &SslPackageName, SCHANNEL_PACKAGE_NAME );
  194. RtlInitUnicodeString( &SslLegacyPackageName, UNISP_NAME_W );
  195. RtlInitString( &SslPackageNameA, SCHANNEL_PACKAGE_NAME_A );
  196. __try {
  197. RtlInitializeResource(&SslGlobalLock);
  198. } __except(EXCEPTION_EXECUTE_HANDLER)
  199. {
  200. return STATUS_INSUFFICIENT_RESOURCES;
  201. }
  202. // Register for domain change notifications
  203. SslRegisterForDomainChange();
  204. SpInitialized = TRUE;
  205. }
  206. return(S_OK);
  207. }
  208. //+---------------------------------------------------------------------------
  209. //
  210. // Function: SpUniGetInfo
  211. //
  212. // Synopsis: Get Package Information
  213. //
  214. // Arguments: [pInfo] --
  215. //
  216. // History: 10-03-96 RichardW Created
  217. //
  218. // Notes:
  219. //
  220. //----------------------------------------------------------------------------
  221. SECURITY_STATUS
  222. SEC_ENTRY
  223. SpUniGetInfo(
  224. PSecPkgInfo pInfo
  225. )
  226. {
  227. pInfo->wVersion = 1;
  228. pInfo->wRPCID = UNISP_RPC_ID;
  229. pInfo->fCapabilities = dwSchannelPackageCapabilities;
  230. pInfo->cbMaxToken = 0x4000;
  231. pInfo->Name = ReplaceBaseProvider ? UNISP_NAME_WO : UNISP_NAME_W ;
  232. pInfo->Comment = UNISP_NAME_W ;
  233. return(S_OK);
  234. }
  235. //+---------------------------------------------------------------------------
  236. //
  237. // Function: SpSslGetInfo
  238. //
  239. // Synopsis: Get Package Information
  240. //
  241. // Arguments: [pInfo] --
  242. //
  243. // History: 10-03-96 RichardW Created
  244. //
  245. // Notes:
  246. //
  247. //----------------------------------------------------------------------------
  248. SECURITY_STATUS
  249. SEC_ENTRY
  250. SpSslGetInfo(
  251. PSecPkgInfo pInfo
  252. )
  253. {
  254. pInfo->wVersion = 1;
  255. pInfo->wRPCID = UNISP_RPC_ID;
  256. pInfo->fCapabilities = dwSchannelPackageCapabilities;
  257. pInfo->cbMaxToken = 0x4000;
  258. pInfo->Name = SCHANNEL_PACKAGE_NAME;
  259. pInfo->Comment = SCHANNEL_PACKAGE_COMMENT;
  260. return(S_OK);
  261. }
  262. //+---------------------------------------------------------------------------
  263. //
  264. // Function: SslDuplicateString
  265. //
  266. // Synopsis: Duplicate a unicode string
  267. //
  268. // Arguments: [Dest] --
  269. // [Source] --
  270. //
  271. // History: 10-18-96 RichardW Created
  272. //
  273. // Notes:
  274. //
  275. //----------------------------------------------------------------------------
  276. NTSTATUS
  277. SslDuplicateString(
  278. PUNICODE_STRING Dest,
  279. PUNICODE_STRING Source
  280. )
  281. {
  282. Dest->Buffer = (PWSTR) SPExternalAlloc( Source->Length + sizeof(WCHAR) );
  283. if ( Dest->Buffer )
  284. {
  285. Dest->Length = Source->Length ;
  286. Dest->MaximumLength = Source->Length + sizeof(WCHAR) ;
  287. CopyMemory( Dest->Buffer, Source->Buffer, Source->Length );
  288. Dest->Buffer[ Dest->Length / 2 ] = L'\0';
  289. return( STATUS_SUCCESS );
  290. }
  291. return( STATUS_NO_MEMORY );
  292. }
  293. //+-------------------------------------------------------------------------
  294. //
  295. // Function: SslFreeString
  296. //
  297. // Synopsis: Frees a string allocated by KerbDuplicateString
  298. //
  299. // Effects:
  300. //
  301. // Arguments: String - Optionally points to a UNICODE_STRING
  302. //
  303. // Requires:
  304. //
  305. // Returns:
  306. //
  307. // Notes:
  308. //
  309. //
  310. //--------------------------------------------------------------------------
  311. VOID
  312. SslFreeString(
  313. IN OPTIONAL PUNICODE_STRING String
  314. )
  315. {
  316. if (ARGUMENT_PRESENT(String) && String->Buffer != NULL)
  317. {
  318. SPExternalFree(String->Buffer);
  319. ZeroMemory(String, sizeof(UNICODE_STRING));
  320. }
  321. }
  322. //+---------------------------------------------------------------------------
  323. //
  324. // Function: SpGetExtendedInformation
  325. //
  326. // Synopsis: Return extended information to the LSA
  327. //
  328. // Arguments: [Class] -- Information Class
  329. // [pInfo] -- Returned Information Pointer
  330. //
  331. // History: 3-24-97 ramas Created
  332. //
  333. // Notes:
  334. //
  335. //----------------------------------------------------------------------------
  336. SECURITY_STATUS
  337. SEC_ENTRY
  338. SpGetExtendedInformation(
  339. SECPKG_EXTENDED_INFORMATION_CLASS Class,
  340. PSECPKG_EXTENDED_INFORMATION * pInfo
  341. )
  342. {
  343. PSECPKG_EXTENDED_INFORMATION Info ;
  344. PWSTR pszPath;
  345. SECURITY_STATUS Status ;
  346. ULONG Size ;
  347. switch ( Class )
  348. {
  349. case SecpkgContextThunks:
  350. Info = (PSECPKG_EXTENDED_INFORMATION) LsaTable->AllocateLsaHeap(
  351. sizeof( SECPKG_EXTENDED_INFORMATION ) +
  352. sizeof( ThunkedContextLevels ) );
  353. if ( Info )
  354. {
  355. Info->Class = Class ;
  356. Info->Info.ContextThunks.InfoLevelCount =
  357. sizeof( ThunkedContextLevels ) / sizeof( ULONG );
  358. CopyMemory( Info->Info.ContextThunks.Levels,
  359. ThunkedContextLevels,
  360. sizeof( ThunkedContextLevels ) );
  361. Status = SEC_E_OK ;
  362. }
  363. else
  364. {
  365. Status = SEC_E_INSUFFICIENT_MEMORY ;
  366. }
  367. break;
  368. #ifdef LATER
  369. case SecpkgGssInfo:
  370. Info = (PSECPKG_EXTENDED_INFORMATION) LsaTable->AllocateLsaHeap(
  371. sizeof( SECPKG_EXTENDED_INFORMATION ) +
  372. sizeof( Md5Oid ) );
  373. if ( Info )
  374. {
  375. Info->Class = Class ;
  376. Info->Info.GssInfo.EncodedIdLength = sizeof( Md5Oid );
  377. CopyMemory( Info->Info.GssInfo.EncodedId,
  378. Md5Oid,
  379. sizeof( Md5Oid ) );
  380. Status = SEC_E_OK ;
  381. }
  382. else
  383. {
  384. Status = SEC_E_INSUFFICIENT_MEMORY ;
  385. }
  386. #endif
  387. case SecpkgWowClientDll:
  388. //
  389. // This indicates that we're smart enough to handle wow client processes
  390. //
  391. Info = (PSECPKG_EXTENDED_INFORMATION)
  392. LsaTable->AllocateLsaHeap( sizeof( SECPKG_EXTENDED_INFORMATION ) +
  393. (MAX_PATH * sizeof(WCHAR) ) );
  394. if ( Info == NULL )
  395. {
  396. Status = STATUS_INSUFFICIENT_RESOURCES ;
  397. break;
  398. }
  399. pszPath = (PWSTR) (Info + 1);
  400. Size = GetSystemWow64Directory(pszPath, MAX_PATH);
  401. if(Size == 0)
  402. {
  403. // This call will fail on x86 platforms.
  404. Status = SEC_E_UNSUPPORTED_FUNCTION;
  405. LsaTable->FreeLsaHeap(Info);
  406. break;
  407. }
  408. if(Size + 1 + wcslen(SCHANNEL_DLL_NAME) >= MAX_PATH)
  409. {
  410. Status = STATUS_INSUFFICIENT_RESOURCES ;
  411. LsaTable->FreeLsaHeap(Info);
  412. break;
  413. }
  414. wcscat(pszPath, L"\\");
  415. wcscat(pszPath, SCHANNEL_DLL_NAME);
  416. Info->Class = SecpkgWowClientDll ;
  417. RtlInitUnicodeString(&Info->Info.WowClientDll.WowClientDllPath, pszPath);
  418. Status = SEC_E_OK;
  419. break;
  420. default:
  421. Status = SEC_E_UNSUPPORTED_FUNCTION ;
  422. Info = NULL ;
  423. break;
  424. }
  425. *pInfo = Info ;
  426. return Status ;
  427. }