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.

169 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name :
  4. sitecred.cxx
  5. Abstract:
  6. SChannel site credentials
  7. Author:
  8. Bilal Alam (BAlam) 29-March-2000
  9. Environment:
  10. Win32 - User Mode
  11. Project:
  12. Stream Filter Worker Process
  13. --*/
  14. #include "precomp.hxx"
  15. SITE_CREDENTIALS::SITE_CREDENTIALS()
  16. : _fInitCreds( FALSE )
  17. {
  18. ZeroMemory( &_hCreds, sizeof( _hCreds ) );
  19. }
  20. SITE_CREDENTIALS::~SITE_CREDENTIALS()
  21. {
  22. if ( _fInitCreds )
  23. {
  24. FreeCredentialsHandle( &_hCreds );
  25. _fInitCreds = FALSE;
  26. }
  27. }
  28. //static
  29. HRESULT
  30. SITE_CREDENTIALS::Initialize(
  31. VOID
  32. )
  33. /*++
  34. Routine Description:
  35. Credentials global init
  36. Arguments:
  37. None
  38. Return Value:
  39. HRESULT
  40. --*/
  41. {
  42. return NO_ERROR;
  43. }
  44. //static
  45. VOID
  46. SITE_CREDENTIALS::Terminate(
  47. VOID
  48. )
  49. /*++
  50. Routine Description:
  51. Cleanup globals
  52. Arguments:
  53. None
  54. Return Value:
  55. None
  56. --*/
  57. {
  58. }
  59. HRESULT
  60. SITE_CREDENTIALS::AcquireCredentials(
  61. SERVER_CERT * pServerCert,
  62. BOOL fUseDsMapper
  63. )
  64. /*++
  65. Routine Description:
  66. Acquire SChannel credentials for the given server certificate and
  67. certificate mapping configuration
  68. Arguments:
  69. pServerCert - Server certificate
  70. fUseDsMapper - enable Ds mappings
  71. Return Value:
  72. HRESULT
  73. --*/
  74. {
  75. SCHANNEL_CRED schannelCreds;
  76. SECURITY_STATUS secStatus;
  77. TimeStamp tsExpiry;
  78. if ( pServerCert == NULL )
  79. {
  80. DBG_ASSERT( FALSE );
  81. return HRESULT_FROM_WIN32( ERROR_INVALID_PARAMETER );
  82. }
  83. //
  84. // If DS mapper is enabled (global setting) then create credentials
  85. // that always enable DS mapping (see schannelCreds.dwFlags)
  86. // Mapped Token will be used optionally
  87. // if certificate mapping is enabled for requested file
  88. //
  89. // This approach may cause performance problems
  90. // for scenarios where Ds mapping is enabled but requested
  91. // file doesn't enable certificate mappings.
  92. // Currently there is no workaround because schannel performs
  93. // ds mapping during the ssl handshake. Ideally schannel should
  94. // map only if QuerySecurityContextToken() is called
  95. //
  96. ZeroMemory( &schannelCreds, sizeof( schannelCreds ) );
  97. schannelCreds.dwVersion = SCHANNEL_CRED_VERSION;
  98. schannelCreds.cCreds = 1;
  99. schannelCreds.paCred = pServerCert->QueryCertContext();
  100. schannelCreds.cMappers = 0;
  101. schannelCreds.aphMappers = NULL;
  102. schannelCreds.hRootStore = NULL;
  103. if ( fUseDsMapper )
  104. {
  105. schannelCreds.dwFlags = 0;
  106. }
  107. else
  108. {
  109. schannelCreds.dwFlags = SCH_CRED_NO_SYSTEM_MAPPER;
  110. }
  111. secStatus = AcquireCredentialsHandle( NULL,
  112. UNISP_NAME_W,
  113. SECPKG_CRED_INBOUND,
  114. NULL,
  115. &schannelCreds,
  116. NULL,
  117. NULL,
  118. &_hCreds,
  119. &tsExpiry );
  120. if ( FAILED( secStatus ) )
  121. {
  122. //
  123. // If we can't even establish plain-jane credentials, then bail
  124. //
  125. return secStatus;
  126. }
  127. _fInitCreds = TRUE;
  128. return NO_ERROR;
  129. }