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.

303 lines
6.0 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name :
  4. digestcontextcache.cxx
  5. Abstract:
  6. Server context cache for Digest authentication
  7. Author:
  8. Ming Lu (minglu) June-10-2001
  9. Revision History:
  10. --*/
  11. #include "precomp.hxx"
  12. ALLOC_CACHE_HANDLER * DIGEST_CONTEXT_CACHE_ENTRY::
  13. sm_pachDigestContextCacheEntry = NULL;
  14. //static
  15. HRESULT
  16. DIGEST_CONTEXT_CACHE_ENTRY::Initialize(
  17. VOID
  18. )
  19. /*++
  20. Description:
  21. Digest server context entry lookaside initialization
  22. Arguments:
  23. None
  24. Return:
  25. HRESULT
  26. --*/
  27. {
  28. ALLOC_CACHE_CONFIGURATION acConfig;
  29. HRESULT hr;
  30. //
  31. // Initialize allocation lookaside
  32. //
  33. acConfig.nConcurrency = 1;
  34. acConfig.nThreshold = 100;
  35. acConfig.cbSize = sizeof( DIGEST_CONTEXT_CACHE_ENTRY );
  36. DBG_ASSERT( sm_pachDigestContextCacheEntry == NULL );
  37. sm_pachDigestContextCacheEntry = new ALLOC_CACHE_HANDLER(
  38. "DIGEST_CONTEXT_CACHE_ENTRY",
  39. &acConfig );
  40. if ( sm_pachDigestContextCacheEntry == NULL ||
  41. !sm_pachDigestContextCacheEntry->IsValid() )
  42. {
  43. if( sm_pachDigestContextCacheEntry != NULL )
  44. {
  45. delete sm_pachDigestContextCacheEntry;
  46. sm_pachDigestContextCacheEntry = NULL;
  47. }
  48. hr = HRESULT_FROM_WIN32( GetLastError() );
  49. DBGPRINTF(( DBG_CONTEXT,
  50. "Error initializing sm_pachDigestContextCacheEntry. hr = 0x%x\n",
  51. hr ));
  52. return hr;
  53. }
  54. return NO_ERROR;
  55. }
  56. //static
  57. VOID
  58. DIGEST_CONTEXT_CACHE_ENTRY::Terminate(
  59. VOID
  60. )
  61. /*++
  62. Description:
  63. Digest server context cache cleanup
  64. Arguments:
  65. None
  66. Return:
  67. None
  68. --*/
  69. {
  70. if ( sm_pachDigestContextCacheEntry != NULL )
  71. {
  72. delete sm_pachDigestContextCacheEntry;
  73. sm_pachDigestContextCacheEntry = NULL;
  74. }
  75. }
  76. HRESULT
  77. DIGEST_CONTEXT_CACHE::Initialize(
  78. VOID
  79. )
  80. /*++
  81. Description:
  82. Initialize digest server context cache
  83. Arguments:
  84. None
  85. Return:
  86. HRESULT
  87. --*/
  88. {
  89. HRESULT hr;
  90. DWORD csecTTL = DEFAULT_CACHED_DIGEST_CONTEXT_TTL;
  91. //
  92. // We'll use TTL for scavenge period, and expect two inactive periods to
  93. // flush
  94. //
  95. hr = SetCacheConfiguration( csecTTL * 1000,
  96. csecTTL * 1000,
  97. 0,
  98. NULL );
  99. if ( FAILED( hr ) )
  100. {
  101. return hr;
  102. }
  103. return DIGEST_CONTEXT_CACHE_ENTRY::Initialize();
  104. }
  105. VOID
  106. DIGEST_CONTEXT_CACHE::Terminate(
  107. VOID
  108. )
  109. /*++
  110. Description:
  111. Terminate digest server context cache
  112. Arguments:
  113. None
  114. Return:
  115. None
  116. --*/
  117. {
  118. return DIGEST_CONTEXT_CACHE_ENTRY::Terminate();
  119. }
  120. HRESULT
  121. DIGEST_CONTEXT_CACHE::AddContextCacheEntry(
  122. IN CtxtHandle * phCtxtHandle
  123. )
  124. /*++
  125. Description:
  126. Add a digest server context to the cache
  127. Arguments:
  128. phCtxtHandle - Pointer to a digest server context handle
  129. Return:
  130. HRESULT
  131. --*/
  132. {
  133. HRESULT hr;
  134. DIGEST_CONTEXT_CACHE_KEY cacheKey;
  135. DIGEST_CONTEXT_CACHE_ENTRY * pContextCacheEntry = NULL;
  136. if ( phCtxtHandle == NULL )
  137. {
  138. DBG_ASSERT( FALSE );
  139. return HRESULT_FROM_WIN32( ERROR_INVALID_PARAMETER );
  140. }
  141. //
  142. // Generate the cache key to look for
  143. //
  144. hr = cacheKey.CreateCacheKey( phCtxtHandle );
  145. if ( FAILED( hr ) )
  146. {
  147. return hr;
  148. }
  149. //
  150. // Look for the cache entry
  151. //
  152. hr = FindCacheEntry( &cacheKey,
  153. ( CACHE_ENTRY ** )&pContextCacheEntry );
  154. if ( SUCCEEDED( hr ) )
  155. {
  156. //
  157. // Cache hit, meaning the security context is a full formed
  158. // context after the second ASC call, thus the ref count for
  159. // it in LSA is two now
  160. //
  161. DBG_ASSERT( pContextCacheEntry != NULL );
  162. //
  163. // Decrement the ref count for the security context in LSA
  164. // to one, so the scanvenger could delete the security
  165. // context when the TTL for the security context is expired.
  166. // This is done by the caller of this function
  167. //
  168. hr = E_FAIL;
  169. goto exit;
  170. }
  171. DBG_ASSERT( pContextCacheEntry == NULL );
  172. //
  173. // For cache miss, create a cache entry and add it
  174. //
  175. //
  176. // Create the entry
  177. //
  178. pContextCacheEntry = new DIGEST_CONTEXT_CACHE_ENTRY( this );
  179. if ( pContextCacheEntry == NULL )
  180. {
  181. return HRESULT_FROM_WIN32( GetLastError() );
  182. }
  183. //
  184. // Set the cache key
  185. //
  186. hr = pContextCacheEntry->SetCacheKey( &cacheKey );
  187. if ( FAILED( hr ) )
  188. {
  189. goto exit;
  190. }
  191. hr = AddCacheEntry( pContextCacheEntry );
  192. exit:
  193. if( pContextCacheEntry != NULL )
  194. {
  195. pContextCacheEntry->DereferenceCacheEntry();
  196. pContextCacheEntry = NULL;
  197. }
  198. return hr;
  199. }
  200. DIGEST_CONTEXT_CACHE_ENTRY::~DIGEST_CONTEXT_CACHE_ENTRY()
  201. {
  202. DBG_ASSERT( CheckSignature() );
  203. m_dwSignature = DIGEST_CONTEXT_CACHE_ENTRY_FREE_SIGNATURE;
  204. if( m_cacheKey.QueryContextHandle() != NULL )
  205. {
  206. if (g_pW3Server->QueryDigestContextCache()->QueryTraceLog() != NULL)
  207. {
  208. WriteRefTraceLogEx(g_pW3Server->QueryDigestContextCache()->QueryTraceLog(),
  209. 0,
  210. (PVOID)m_cacheKey.QueryContextHandle()->dwLower,
  211. (PVOID)m_cacheKey.QueryContextHandle()->dwUpper,
  212. NULL,
  213. NULL);
  214. }
  215. DeleteSecurityContext( m_cacheKey.QueryContextHandle() );
  216. }
  217. }