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.

271 lines
5.7 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. credcach.hxx
  5. Abstract:
  6. This module contains the public definitions to the credential cache
  7. Author:
  8. John Ludeman (johnl) 18-Oct-1995
  9. Revision History:
  10. --*/
  11. #ifndef _CREDCACH_HXX_
  12. #define _CREDCACH_HXX_
  13. #include <tracelog.h>
  14. #define IIS3
  15. #include <mapctxt.h>
  16. #include <refb.hxx>
  17. #include <certmap.h>
  18. #include <imd.h>
  19. #include "sslinfo.hxx"
  20. #ifndef DEFINE_SIMSSL_GLOBAL
  21. #define EXTERN extern
  22. #else
  23. #define EXTERN
  24. #endif
  25. //
  26. // Constants
  27. //
  28. #define MAX_SECRET_NAME 255
  29. #define MAX_ADDRESS_LEN 64
  30. #define SHA1_HASH_LEN 20
  31. #define MAX_SSL_ID_LEN 2*SHA1_HASH_LEN + 1
  32. #define SSL_SERVICE_KEYS_MD_PATH "/LM/%S/SSLKEYS"
  33. #define SSL_SERVICE_KEYS_MD_PATH_W L"/LM/%s/SSLKEYS"
  34. //
  35. // The maximum number of providers we'll support
  36. //
  37. #define MAX_PROVIDERS 7
  38. typedef struct _ENC_PROVIDER
  39. {
  40. WCHAR * pszName;
  41. DWORD dwFlags;
  42. BOOL fEnabled;
  43. } ENC_PROVIDER, *PENC_PROVIDER;
  44. typedef PSecurityFunctionTableW (APIENTRY *INITSECURITYINTERFACE) (VOID);
  45. extern PSecurityFunctionTableW g_pSecFuncTableW;
  46. #define g_EnumerateSecurityPackages \
  47. (*(g_pSecFuncTableW->EnumerateSecurityPackagesW))
  48. #define g_AcquireCredentialsHandle \
  49. (*(g_pSecFuncTableW->AcquireCredentialsHandleW))
  50. #define g_FreeCredentialsHandle \
  51. (*(g_pSecFuncTableW->FreeCredentialHandle))
  52. #define g_InitializeSecurityContext \
  53. (*(g_pSecFuncTableW->InitializeSecurityContextW))
  54. #define g_AcceptSecurityContext \
  55. (*(g_pSecFuncTableW->AcceptSecurityContext))
  56. #define g_CompleteAuthToken \
  57. (*(g_pSecFuncTableW->CompleteAuthToken))
  58. #define g_DeleteSecurityContext \
  59. (*(g_pSecFuncTableW->DeleteSecurityContext))
  60. #define g_QueryContextAttributes \
  61. (*(g_pSecFuncTableW->QueryContextAttributesW))
  62. #define g_QuerySecurityContextToken \
  63. (*(g_pSecFuncTableW->QuerySecurityContextToken))
  64. #define g_FreeContextBuffer \
  65. (*(g_pSecFuncTableW->FreeContextBuffer))
  66. #define g_SealMessage \
  67. (*((SEAL_MESSAGE_FN)g_pSecFuncTableW->Reserved3))
  68. #define g_UnsealMessage \
  69. (*((UNSEAL_MESSAGE_FN)g_pSecFuncTableW->Reserved4))
  70. //
  71. // Cached credential item. This contains an array of credentials for each
  72. // security package. There is one of these for every installed key
  73. //
  74. BOOL
  75. TerminateCertMapping(
  76. HMAPPER** ppMappers,
  77. DWORD cNbMappers
  78. );
  79. //
  80. // Lock for the credential cache
  81. //
  82. EXTERN CRITICAL_SECTION csGlobalLock;
  83. //
  84. // Locks the credential cache
  85. //
  86. #define LockGlobals() EnterCriticalSection( &csGlobalLock )
  87. #define UnlockGlobals() LeaveCriticalSection( &csGlobalLock );
  88. class CRED_CACHE_ITEM
  89. {
  90. public:
  91. CRED_CACHE_ITEM()
  92. {
  93. m_lRef = 1;
  94. m_fValid = FALSE;
  95. m_cCred = 0;
  96. m_cCredMap = 0;
  97. m_pSslInfo = NULL;
  98. }
  99. ~CRED_CACHE_ITEM();
  100. VOID AddRef()
  101. {
  102. InterlockedIncrement( &m_lRef );
  103. }
  104. VOID Release()
  105. {
  106. if ( !InterlockedDecrement( &m_lRef ) )
  107. {
  108. delete this;
  109. }
  110. }
  111. //
  112. // The "SSL info" blob identifying this credential handle set
  113. //
  114. CHAR m_achSSLIdBlob[MAX_SSL_ID_LEN];
  115. //
  116. // The IP address for this credential handle set
  117. //
  118. // CHAR m_achAddr[MAX_ADDRESS_LEN+1];
  119. LPVOID m_pvInstanceId;
  120. //
  121. // m_fValid is FALSE if there isn't a matching key set on the
  122. // server
  123. //
  124. BOOL m_fValid;
  125. LONG m_lRef;
  126. DWORD m_cCred; // Count of credentials
  127. CredHandle m_ahCred[MAX_PROVIDERS];
  128. DWORD m_cCredMap; // Count of credentials w/ mapping
  129. CredHandle m_ahCredMap[MAX_PROVIDERS];
  130. DWORD m_acbTrailer[MAX_PROVIDERS];
  131. DWORD m_acbHeader[MAX_PROVIDERS];
  132. DWORD m_acbBlockSize[MAX_PROVIDERS];
  133. RefBlob* m_pBlob11;
  134. RefBlob* m_pBlobW;
  135. IIS_SSL_INFO *m_pSslInfo;
  136. HMAPPER** m_ppMappers;
  137. DWORD m_cNbMappers;
  138. LIST_ENTRY m_ListEntry;
  139. };
  140. class INSTANCE_CACHE_ITEM
  141. {
  142. public:
  143. ~INSTANCE_CACHE_ITEM()
  144. {
  145. if ( m_fValid )
  146. {
  147. m_pcci->Release();
  148. }
  149. }
  150. //
  151. // The IP address for this credential handle set
  152. //
  153. //CHAR m_achId[MAX_ADDRESS_LEN+1];
  154. //DWORD m_cbId;
  155. LPVOID m_pvInstanceId;
  156. CRED_CACHE_ITEM* m_pcci;
  157. //
  158. // m_fValid is FALSE if there isn't a matching key set on the
  159. // server
  160. //
  161. BOOL m_fValid;
  162. LIST_ENTRY m_ListEntry;
  163. };
  164. //
  165. // Array of encryption providers
  166. //
  167. extern ENC_PROVIDER* pEncProviders;
  168. extern CRED_CACHE_ITEM* g_pcciClient;
  169. VOID
  170. InitCredCache(
  171. VOID
  172. );
  173. VOID
  174. FreeCredCache(
  175. VOID
  176. );
  177. BOOL
  178. LookupFullyQualifiedCredential(
  179. IN WCHAR * pwszServerPrefix,
  180. IN CHAR * pszIpAddress,
  181. IN DWORD cbAddress,
  182. IN CHAR * pszPort,
  183. IN DWORD cbPort,
  184. IN LPVOID pvInstanceId,
  185. OUT CRED_CACHE_ITEM * * ppCCI,
  186. IN PVOID pvsmc,
  187. IN DWORD dwInstanceId
  188. );
  189. VOID
  190. ReleaseCredential(
  191. CRED_CACHE_ITEM * pcci
  192. );
  193. BOOL
  194. LookupClientCredential(
  195. IN WCHAR* pwszServerPrefix,
  196. IN BOOL fUseCertificate,
  197. OUT CRED_CACHE_ITEM * * ppCCI
  198. );
  199. BOOL
  200. GetSecretW(
  201. WCHAR * pszSecretName,
  202. UNICODE_STRING * * ppSecretValue
  203. );
  204. BOOL
  205. InitializeCredentials(
  206. VOID
  207. );
  208. #define CERT_DER_PREFIX 17
  209. #endif // _CREDCACH_HXX_
  210.