Source code of Windows XP (NT5)
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.

331 lines
7.9 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 RTL_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. RtlAcquireResourceExclusive(&KerbContextResource,TRUE); \
  86. KerbGlobalContextsLocked = GetCurrentThreadId(); \
  87. }
  88. #define KerbReadLockContexts() \
  89. { \
  90. DebugLog((DEB_TRACE_LOCKS,"Read locking Contexts\n")); \
  91. RtlAcquireResourceShared(&KerbContextResource, TRUE); \
  92. KerbGlobalContextsLocked = GetCurrentThreadId(); \
  93. }
  94. #define KerbUnlockContexts() \
  95. { \
  96. DebugLog((DEB_TRACE_LOCKS,"Unlocking Contexts\n")); \
  97. KerbGlobalContextsLocked = 0; \
  98. RtlReleaseResource(&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. RtlAcquireResourceExclusive(&KerbContextResource,TRUE);
  112. #define KerbReadLockContexts() \
  113. RtlAcquireResourceShared(&KerbContextResource, TRUE);
  114. #define KerbUnlockContexts() \
  115. RtlReleaseResource(&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 ULONG ContextFlags,
  158. IN ULONG ContextAttributes,
  159. IN OPTIONAL PKERB_ENCRYPTION_KEY SubSessionKey,
  160. OUT PKERB_CONTEXT * NewContext,
  161. OUT PTimeStamp ContextLifetime
  162. );
  163. NTSTATUS
  164. KerbCreateServerContext(
  165. IN PKERB_LOGON_SESSION LogonSession,
  166. IN PKERB_CREDENTIAL Credential,
  167. IN PKERB_ENCRYPTED_TICKET InternalTicket,
  168. IN PKERB_AP_REQUEST ApRequest,
  169. IN PKERB_ENCRYPTION_KEY SessionKey,
  170. IN PLUID LogonId,
  171. IN OUT PSID * UserSid,
  172. IN ULONG ContextFlags,
  173. IN ULONG ContextAttributes,
  174. IN ULONG Nonce,
  175. IN ULONG ReceiveNonce,
  176. IN OUT PHANDLE TokenHandle,
  177. IN PUNICODE_STRING ClientName,
  178. IN PUNICODE_STRING ClientDomain,
  179. OUT PKERB_CONTEXT * NewContext,
  180. OUT PTimeStamp ContextLifetime
  181. );
  182. NTSTATUS
  183. KerbUpdateServerContext(
  184. IN PKERB_CONTEXT Context,
  185. IN PKERB_ENCRYPTED_TICKET InternalTicket,
  186. IN PKERB_AP_REQUEST ApRequest,
  187. IN PKERB_ENCRYPTION_KEY SessionKey,
  188. IN PLUID LogonId,
  189. IN OUT PSID * UserSid,
  190. IN ULONG ContextFlags,
  191. IN ULONG ContextAttributes,
  192. IN ULONG Nonce,
  193. IN ULONG ReceiveNonce,
  194. IN OUT PHANDLE TokenHandle,
  195. IN PUNICODE_STRING ClientName,
  196. IN PUNICODE_STRING ClientDomain,
  197. OUT PTimeStamp ContextLifetime
  198. );
  199. NTSTATUS
  200. KerbCreateEmptyContext(
  201. IN PKERB_CREDENTIAL Credential,
  202. IN ULONG ContextFlags,
  203. IN ULONG ContextAttributes,
  204. IN PLUID LogonId,
  205. OUT PKERB_CONTEXT * NewContext,
  206. OUT PTimeStamp ContextLifetime
  207. );
  208. NTSTATUS
  209. KerbMapContext(
  210. IN PKERB_CONTEXT Context,
  211. OUT PBOOLEAN MappedContext,
  212. OUT PSecBuffer ContextData
  213. );
  214. NTSTATUS
  215. KerbCreateUserModeContext(
  216. IN LSA_SEC_HANDLE ContextHandle,
  217. IN PSecBuffer MarshalledContext,
  218. OUT PKERB_CONTEXT * NewContext
  219. );
  220. SECURITY_STATUS
  221. KerbReferenceContextByLsaHandle(
  222. IN LSA_SEC_HANDLE ContextHandle,
  223. IN BOOLEAN RemoveFromList,
  224. OUT PKERB_CONTEXT * FoundContext
  225. );
  226. NTSTATUS
  227. KerbUpdateClientContext(
  228. IN PKERB_CONTEXT Context,
  229. IN PKERB_TICKET_CACHE_ENTRY TicketCacheEntry,
  230. IN ULONG Nonce,
  231. IN ULONG ReceiveNonce,
  232. IN ULONG ContextFlags,
  233. IN ULONG ContextAttribs,
  234. IN OPTIONAL PKERB_ENCRYPTION_KEY SubSessionKey,
  235. OUT PTimeStamp ContextLifetime
  236. );
  237. NTSTATUS
  238. KerbCreateSKeyEntry(
  239. IN KERB_ENCRYPTION_KEY* pSessionKey,
  240. IN FILETIME* pExpireTime
  241. );
  242. NTSTATUS
  243. KerbDoesSKeyExist(
  244. IN KERB_ENCRYPTION_KEY* pKey,
  245. OUT BOOLEAN* pbExist
  246. );
  247. NTSTATUS
  248. KerbEqualKey(
  249. IN KERB_ENCRYPTION_KEY* pKeyFoo,
  250. IN KERB_ENCRYPTION_KEY* pKeyBar,
  251. OUT BOOLEAN* pbEqual
  252. );
  253. NTSTATUS
  254. KerbInsertSKey(
  255. IN KERB_SESSION_KEY_ENTRY* pSKeyEntry
  256. );
  257. VOID
  258. KerbTrimSKeyList(
  259. VOID
  260. );
  261. VOID
  262. KerbNetworkServiceSKeyListCleanupCallback(
  263. IN VOID* pContext,
  264. IN BOOLEAN bTimeOut
  265. );
  266. NTSTATUS
  267. KerbCreateSKeyTimer(
  268. VOID
  269. );
  270. VOID
  271. KerbFreeSKeyTimer(
  272. VOID
  273. );
  274. VOID
  275. KerbFreeSKeyEntry(
  276. IN KERB_SESSION_KEY_ENTRY* pSKeyEntry
  277. );
  278. NTSTATUS
  279. KerbProcessTargetNames(
  280. IN PUNICODE_STRING TargetName,
  281. IN OPTIONAL PUNICODE_STRING SuppTargetName,
  282. IN ULONG Flags,
  283. IN OUT ULONG *ProcessFlags,
  284. OUT PKERB_INTERNAL_NAME * FinalTarget,
  285. OUT PUNICODE_STRING TargetRealm,
  286. OUT OPTIONAL PKERB_SPN_CACHE_ENTRY * SpnCacheEntry
  287. );
  288. #define KERB_CRACK_NAME_USE_WKSTA_REALM 0x1
  289. #define KERB_CRACK_NAME_REALM_SUPPLIED 0x2
  290. #endif // __CTXTMGR_H__