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.

344 lines
8.4 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 1992 - 1996
  6. //
  7. // File: ctxtmgr.h
  8. //
  9. // Contents: Structures and prototyps for Kerberos context list
  10. //
  11. //
  12. // History: 17-April-1996 Created MikeSw
  13. //
  14. //------------------------------------------------------------------------
  15. #ifndef __CTXTMGR_H__
  16. #define __CTXTMGR_H__
  17. //
  18. // All global variables declared as EXTERN will be allocated in the file
  19. // that defines CTXTMGR_ALLOCATE
  20. //
  21. #ifdef EXTERN
  22. #undef EXTERN
  23. #endif
  24. #ifdef CTXTMGR_ALLOCATE
  25. #define EXTERN
  26. #else
  27. #define EXTERN extern
  28. #endif
  29. #ifdef WIN32_CHICAGO
  30. EXTERN CRITICAL_SECTION KerbContextResource;
  31. #else // WIN32_CHICAGO
  32. EXTERN SAFE_RESOURCE KerbContextResource;
  33. #endif // WIN32_CHICAGO
  34. #define KERB_USERLIST_COUNT (16) // count of lists
  35. EXTERN KERBEROS_LIST KerbContextList[ KERB_USERLIST_COUNT ];
  36. EXTERN BOOLEAN KerberosContextsInitialized;
  37. #define KerbGetContextHandle(_Context_) ((LSA_SEC_HANDLE)(_Context_))
  38. //
  39. // Context flags - these are attributes of a context and are stored in
  40. // the ContextAttributes field of a KERB_CONTEXT.
  41. //
  42. #define KERB_CONTEXT_MAPPED 0x1
  43. #define KERB_CONTEXT_OUTBOUND 0x2
  44. #define KERB_CONTEXT_INBOUND 0x4
  45. #define KERB_CONTEXT_USED_SUPPLIED_CREDS 0x8
  46. #define KERB_CONTEXT_USER_TO_USER 0x10
  47. #define KERB_CONTEXT_REQ_SERVER_NAME 0x20
  48. #define KERB_CONTEXT_REQ_SERVER_REALM 0x40
  49. #define KERB_CONTEXT_IMPORTED 0x80
  50. #define KERB_CONTEXT_EXPORTED 0x100
  51. #define KERB_CONTEXT_USING_CREDMAN 0x200
  52. //
  53. // NOTICE: The logon session resource, credential resource, and context
  54. // resource must all be acquired carefully to prevent deadlock. They
  55. // can only be acquired in this order:
  56. //
  57. // 1. Logon Sessions
  58. // 2. Credentials
  59. // 3. Contexts
  60. //
  61. #if DBG
  62. #ifdef WIN32_CHICAGO
  63. #define KerbWriteLockContexts() \
  64. { \
  65. DebugLog((DEB_TRACE_LOCKS,"Write locking Contexts\n")); \
  66. EnterCriticalSection(&KerbContextResource); \
  67. KerbGlobalContextsLocked = GetCurrentThreadId(); \
  68. }
  69. #define KerbReadLockContexts() \
  70. { \
  71. DebugLog((DEB_TRACE_LOCKS,"Read locking Contexts\n")); \
  72. EnterCriticalSection(&KerbContextResource); \
  73. KerbGlobalContextsLocked = GetCurrentThreadId(); \
  74. }
  75. #define KerbUnlockContexts() \
  76. { \
  77. DebugLog((DEB_TRACE_LOCKS,"Unlocking Contexts\n")); \
  78. KerbGlobalContextsLocked = 0; \
  79. LeaveCriticalSection(&KerbContextResource); \
  80. }
  81. #else // WIN32_CHICAGO
  82. #define KerbWriteLockContexts() \
  83. { \
  84. DebugLog((DEB_TRACE_LOCKS,"Write locking Contexts\n")); \
  85. SafeAcquireResourceExclusive(&KerbContextResource,TRUE); \
  86. KerbGlobalContextsLocked = GetCurrentThreadId(); \
  87. }
  88. #define KerbReadLockContexts() \
  89. { \
  90. DebugLog((DEB_TRACE_LOCKS,"Read locking Contexts\n")); \
  91. SafeAcquireResourceShared(&KerbContextResource, TRUE); \
  92. KerbGlobalContextsLocked = GetCurrentThreadId(); \
  93. }
  94. #define KerbUnlockContexts() \
  95. { \
  96. DebugLog((DEB_TRACE_LOCKS,"Unlocking Contexts\n")); \
  97. KerbGlobalContextsLocked = 0; \
  98. SafeReleaseResource(&KerbContextResource); \
  99. }
  100. #endif // WIN32_CHICAGO
  101. #else
  102. #ifdef WIN32_CHICAGO
  103. #define KerbWriteLockContexts() \
  104. EnterCriticalSection(&KerbContextResource)
  105. #define KerbReadLockContexts() \
  106. EnterCriticalSection(&KerbContextResource)
  107. #define KerbUnlockContexts() \
  108. LeaveCriticalSection(&KerbContextResource)
  109. #else // WIN32_CHICAGO
  110. #define KerbWriteLockContexts() \
  111. SafeAcquireResourceExclusive(&KerbContextResource,TRUE);
  112. #define KerbReadLockContexts() \
  113. SafeAcquireResourceShared(&KerbContextResource, TRUE);
  114. #define KerbUnlockContexts() \
  115. SafeReleaseResource(&KerbContextResource);
  116. #endif // WIN32_CHICAGO
  117. #endif
  118. NTSTATUS
  119. KerbInitContextList(
  120. VOID
  121. );
  122. VOID
  123. KerbFreeContextList(
  124. VOID
  125. );
  126. NTSTATUS
  127. KerbAllocateContext(
  128. PKERB_CONTEXT * NewContext
  129. );
  130. NTSTATUS
  131. KerbInsertContext(
  132. IN PKERB_CONTEXT Context
  133. );
  134. SECURITY_STATUS
  135. KerbReferenceContext(
  136. IN LSA_SEC_HANDLE ContextHandle,
  137. IN BOOLEAN RemoveFromList,
  138. OUT PKERB_CONTEXT * FoundContext
  139. );
  140. VOID
  141. KerbDereferenceContext(
  142. IN PKERB_CONTEXT Context
  143. );
  144. VOID
  145. KerbReferenceContextByPointer(
  146. IN PKERB_CONTEXT Context,
  147. IN BOOLEAN RemoveFromList
  148. );
  149. NTSTATUS
  150. KerbCreateClientContext(
  151. IN PKERB_LOGON_SESSION LogonSession,
  152. IN PKERB_CREDENTIAL Credential,
  153. IN OPTIONAL PKERB_CREDMAN_CRED CredManCredentials,
  154. IN OPTIONAL PKERB_TICKET_CACHE_ENTRY TicketCacheEntry,
  155. IN OPTIONAL PUNICODE_STRING TargetName,
  156. IN ULONG Nonce,
  157. IN PTimeStamp pAuthenticatorTime,
  158. IN ULONG ContextFlags,
  159. IN ULONG ContextAttributes,
  160. IN OPTIONAL PKERB_ENCRYPTION_KEY SubSessionKey,
  161. OUT PKERB_CONTEXT * NewContext,
  162. OUT PTimeStamp ContextLifetime
  163. );
  164. NTSTATUS
  165. KerbCreateServerContext(
  166. IN PKERB_LOGON_SESSION LogonSession,
  167. IN PKERB_CREDENTIAL Credential,
  168. IN PKERB_ENCRYPTED_TICKET InternalTicket,
  169. IN PKERB_AP_REQUEST ApRequest,
  170. IN PKERB_ENCRYPTION_KEY SessionKey,
  171. IN PLUID LogonId,
  172. IN OUT PSID * UserSid,
  173. IN ULONG ContextFlags,
  174. IN ULONG ContextAttributes,
  175. IN ULONG NegotiationInfo,
  176. IN ULONG Nonce,
  177. IN ULONG ReceiveNonce,
  178. IN OUT PHANDLE TokenHandle,
  179. IN PUNICODE_STRING ClientName,
  180. IN PUNICODE_STRING ClientDomain,
  181. IN PUNICODE_STRING ClientNetbiosDomain,
  182. OUT PKERB_CONTEXT * NewContext,
  183. OUT PTimeStamp ContextLifetime
  184. );
  185. NTSTATUS
  186. KerbUpdateServerContext(
  187. IN PKERB_CONTEXT Context,
  188. IN PKERB_ENCRYPTED_TICKET InternalTicket,
  189. IN PKERB_AP_REQUEST ApRequest,
  190. IN PKERB_ENCRYPTION_KEY SessionKey,
  191. IN PLUID LogonId,
  192. IN OUT PSID * UserSid,
  193. IN ULONG ContextFlags,
  194. IN ULONG ContextAttributes,
  195. IN ULONG NegotiationInfo,
  196. IN ULONG Nonce,
  197. IN ULONG ReceiveNonce,
  198. IN OUT PHANDLE TokenHandle,
  199. IN PUNICODE_STRING ClientName,
  200. IN PUNICODE_STRING ClientDomain,
  201. IN PUNICODE_STRING ClientNetbiosDomain,
  202. OUT PTimeStamp ContextLifetime
  203. );
  204. NTSTATUS
  205. KerbCreateEmptyContext(
  206. IN PKERB_CREDENTIAL Credential,
  207. IN ULONG ContextFlags,
  208. IN ULONG ContextAttributes,
  209. IN ULONG NegotiationInfo,
  210. IN PLUID LogonId,
  211. OUT PKERB_CONTEXT * NewContext,
  212. OUT PTimeStamp ContextLifetime
  213. );
  214. NTSTATUS
  215. KerbMapContext(
  216. IN PKERB_CONTEXT Context,
  217. OUT PBOOLEAN MappedContext,
  218. OUT PSecBuffer ContextData
  219. );
  220. NTSTATUS
  221. KerbCreateUserModeContext(
  222. IN LSA_SEC_HANDLE ContextHandle,
  223. IN PSecBuffer MarshalledContext,
  224. OUT PKERB_CONTEXT * NewContext
  225. );
  226. SECURITY_STATUS
  227. KerbReferenceContextByLsaHandle(
  228. IN LSA_SEC_HANDLE ContextHandle,
  229. IN BOOLEAN RemoveFromList,
  230. OUT PKERB_CONTEXT * FoundContext
  231. );
  232. NTSTATUS
  233. KerbUpdateClientContext(
  234. IN PKERB_CONTEXT Context,
  235. IN PKERB_TICKET_CACHE_ENTRY TicketCacheEntry,
  236. IN ULONG Nonce,
  237. IN PTimeStamp pAuthenticatorTime,
  238. IN ULONG ReceiveNonce,
  239. IN ULONG ContextFlags,
  240. IN ULONG ContextAttribs,
  241. IN OPTIONAL PKERB_ENCRYPTION_KEY SubSessionKey,
  242. OUT PTimeStamp ContextLifetime
  243. );
  244. NTSTATUS
  245. KerbCreateSKeyEntry(
  246. IN KERB_ENCRYPTION_KEY* pSessionKey,
  247. IN FILETIME* pExpireTime
  248. );
  249. VOID
  250. KerbDeleteSKeyEntry(
  251. IN OPTIONAL KERB_ENCRYPTION_KEY* pKey
  252. );
  253. NTSTATUS
  254. KerbDoesSKeyExist(
  255. IN KERB_ENCRYPTION_KEY* pKey,
  256. OUT BOOLEAN* pbExist
  257. );
  258. NTSTATUS
  259. KerbEqualKey(
  260. IN KERB_ENCRYPTION_KEY* pKeyFoo,
  261. IN KERB_ENCRYPTION_KEY* pKeyBar,
  262. OUT BOOLEAN* pbEqual
  263. );
  264. VOID
  265. KerbTrimSKeyList(
  266. VOID
  267. );
  268. VOID
  269. KerbSKeyListCleanupCallback(
  270. IN VOID* pContext,
  271. IN BOOLEAN bTimeOut
  272. );
  273. NTSTATUS
  274. KerbCreateSKeyTimer(
  275. VOID
  276. );
  277. VOID
  278. KerbFreeSKeyTimer(
  279. VOID
  280. );
  281. VOID
  282. KerbFreeSKeyEntry(
  283. IN KERB_SESSION_KEY_ENTRY* pSKeyEntry
  284. );
  285. NTSTATUS
  286. KerbProcessTargetNames(
  287. IN PUNICODE_STRING TargetName,
  288. IN OPTIONAL PUNICODE_STRING SuppTargetName,
  289. IN ULONG Flags,
  290. IN OUT PULONG ProcessFlags,
  291. OUT PKERB_INTERNAL_NAME * FinalTarget,
  292. OUT PUNICODE_STRING TargetRealm,
  293. OUT OPTIONAL PKERB_SPN_CACHE_ENTRY * SpnCacheEntry
  294. );
  295. #define KERB_CRACK_NAME_USE_WKSTA_REALM 0x1
  296. #define KERB_CRACK_NAME_REALM_SUPPLIED 0x2
  297. #endif // __CTXTMGR_H__