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.

321 lines
7.6 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 1992 - 1996
  6. //
  7. // File: logonses.h
  8. //
  9. // Contents: prototypes and structures for the logon session list
  10. //
  11. //
  12. // History: 16-April-1996 Created MikeSw
  13. //
  14. //------------------------------------------------------------------------
  15. #ifndef __LOGONSES_H__
  16. #define __LOGONSES_H__
  17. #include <safelock.h>
  18. //
  19. // All global variables declared as EXTERN will be allocated in the file
  20. // that defines LOGONSES_ALLOCATE
  21. //
  22. #ifdef EXTERN
  23. #undef EXTERN
  24. #endif
  25. #ifdef LOGONSES_ALLOCATE
  26. #define EXTERN
  27. #else
  28. #define EXTERN extern
  29. #endif
  30. EXTERN KERBEROS_LIST KerbLogonSessionList;
  31. EXTERN BOOLEAN KerberosLogonSessionsInitialized;
  32. //
  33. // Keep track a list of session keys for network service in ISC. These keys are
  34. // used in ASC to detect whether a kerb logon session is from ISC called by the
  35. // local network serivce (the client)
  36. //
  37. EXTERN LIST_ENTRY KerbSKeyList;
  38. EXTERN SAFE_RESOURCE KerbSKeyLock;
  39. //
  40. // the number of entries is only used in debugger spew of checked builds
  41. //
  42. #if DBG
  43. EXTERN volatile LONG KerbcSKeyEntries;
  44. #endif
  45. //
  46. // timer used to clean up the session key list above
  47. //
  48. EXTERN HANDLE KerbhSKeyTimerQueue;
  49. //
  50. // NOTICE: The logon session resource, credential resource, and context
  51. // resource must all be acquired carefully to prevent deadlock. They
  52. // can only be acquired in this order:
  53. //
  54. // 1. Logon Sessions
  55. // 2. Credentials
  56. // 3. Contexts
  57. //
  58. #if DBG
  59. #ifdef WIN32_CHICAGO
  60. #define KerbWriteLockLogonSessions(_X_) \
  61. { \
  62. DebugLog((DEB_TRACE_LOCKS,"Write locking LogonSessions\n")); \
  63. DsysAssert(KerbGlobalContextsLocked != GetCurrentThreadId()); \
  64. EnterCriticalSection(&(_X_)->Lock); \
  65. }
  66. #define KerbReadLockLogonSessions(_X_) \
  67. { \
  68. DebugLog((DEB_TRACE_LOCKS,"Read locking LogonSessions\n")); \
  69. DsysAssert(KerbGlobalContextsLocked != GetCurrentThreadId()); \
  70. EnterCriticalSection(&(_X_)->Lock); \
  71. }
  72. #define KerbUnlockLogonSessions(_X_) \
  73. { \
  74. DebugLog((DEB_TRACE_LOCKS,"Unlocking LogonSessions\n")); \
  75. LeaveCriticalSection(&(_X_)->Lock); \
  76. }
  77. #else // WIN32_CHICAGO
  78. #define KerbWriteLockLogonSessions(_X_) \
  79. { \
  80. DebugLog((DEB_TRACE_LOCKS,"Write locking LogonSession %p\n",(_X_))); \
  81. DsysAssert(KerbGlobalContextsLocked != GetCurrentThreadId()); \
  82. SafeEnterCriticalSection(&(_X_)->Lock); \
  83. }
  84. #define KerbReadLockLogonSessions(_X_) \
  85. { \
  86. DebugLog((DEB_TRACE_LOCKS,"Read locking LogonSession %p\n",(_X_))); \
  87. DsysAssert(KerbGlobalContextsLocked != GetCurrentThreadId()); \
  88. SafeEnterCriticalSection(&(_X_)->Lock); \
  89. }
  90. #define KerbUnlockLogonSessions(_X_) \
  91. { \
  92. DebugLog((DEB_TRACE_LOCKS,"Unlocking LogonSessions\n")); \
  93. SafeLeaveCriticalSection(&(_X_)->Lock); \
  94. }
  95. #endif // WIN32_CHICAGO
  96. #else
  97. #ifdef WIN32_CHICAGO
  98. #define KerbWriteLockLogonSessions(_X_) \
  99. EnterCriticalSection(&(_X_)->Lock)
  100. #define KerbReadLockLogonSessions(_X_) \
  101. EnterCriticalSection(&(_X_)->Lock)
  102. #define KerbUnlockLogonSessions(_X_) \
  103. LeaveCriticalSection(&(_X_)->Lock)
  104. #else // WIN32_CHICAGO
  105. #define KerbWriteLockLogonSessions(_X_) \
  106. SafeEnterCriticalSection(&(_X_)->Lock);
  107. #define KerbReadLockLogonSessions(_X_) \
  108. SafeEnterCriticalSection(&(_X_)->Lock);
  109. #define KerbUnlockLogonSessions(_X_) \
  110. SafeLeaveCriticalSection(&(_X_)->Lock);
  111. #endif // WIN32_CHICAGO
  112. #endif
  113. //
  114. // Helper routines for Logon Sessions
  115. //
  116. NTSTATUS
  117. KerbInitLogonSessionList(
  118. VOID
  119. );
  120. NTSTATUS
  121. KerbInitLoopbackDetection(
  122. VOID
  123. );
  124. VOID
  125. KerbFreeSKeyListAndLock(
  126. VOID
  127. );
  128. VOID
  129. KerbFreeLogonSessionList(
  130. VOID
  131. );
  132. VOID
  133. KerbFreeExtraCredList(
  134. IN PEXTRA_CRED_LIST Credlist
  135. );
  136. NTSTATUS
  137. KerbAllocateLogonSession(
  138. PKERB_LOGON_SESSION * NewLogonSession
  139. );
  140. NTSTATUS
  141. KerbInsertLogonSession(
  142. IN PKERB_LOGON_SESSION LogonSession
  143. );
  144. PKERB_LOGON_SESSION
  145. KerbReferenceLogonSession(
  146. IN PLUID LogonId,
  147. IN BOOLEAN RemoveFromList
  148. );
  149. VOID
  150. KerbReferenceLogonSessionByPointer(
  151. IN PKERB_LOGON_SESSION LogonSession,
  152. IN BOOLEAN RemoveFromList
  153. );
  154. VOID
  155. KerbDereferenceLogonSession(
  156. IN PKERB_LOGON_SESSION LogonSession
  157. );
  158. NTSTATUS
  159. KerbCreateLogonSession(
  160. IN PLUID LogonId,
  161. IN PUNICODE_STRING AccountName,
  162. IN PUNICODE_STRING DomainName,
  163. IN OPTIONAL PUNICODE_STRING Password,
  164. IN OPTIONAL PUNICODE_STRING OldPassword,
  165. IN ULONG PasswordFlags,
  166. IN ULONG LogonSessionFlags,
  167. IN BOOLEAN AllowDuplicate,
  168. OUT PKERB_LOGON_SESSION * NewLogonSession
  169. );
  170. NTSTATUS
  171. KerbCreateDummyLogonSession(
  172. IN PLUID LogonId,
  173. IN OUT PKERB_LOGON_SESSION * NewLogonSession,
  174. IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
  175. IN BOOLEAN Impersonating,
  176. IN HANDLE hProcess
  177. );
  178. VOID
  179. KerbFreeLogonSession(
  180. IN PKERB_LOGON_SESSION LogonSession
  181. );
  182. NTSTATUS
  183. KerbCreateLogonSessionFromKerbCred(
  184. IN OPTIONAL PLUID LogonId,
  185. IN PKERB_ENCRYPTED_TICKET Ticket,
  186. IN PKERB_CRED KerbCred,
  187. IN PKERB_ENCRYPTED_CRED EncryptedCred,
  188. IN OUT PKERB_LOGON_SESSION *OldLogonSession
  189. );
  190. NTSTATUS
  191. KerbCreateLogonSessionFromTicket(
  192. IN PLUID NewLuid,
  193. IN OPTIONAL PLUID AcceptingLuid,
  194. IN PUNICODE_STRING ClientName,
  195. IN PUNICODE_STRING ClientRealm,
  196. IN PKERB_AP_REQUEST ApRequest,
  197. IN PKERB_ENCRYPTED_TICKET Ticket,
  198. IN OUT OPTIONAL PKERB_LOGON_SESSION *NewLogonSession
  199. );
  200. NTSTATUS
  201. KerbBuildPasswordList(
  202. IN PUNICODE_STRING Password,
  203. IN PUNICODE_STRING UserName,
  204. IN PUNICODE_STRING DomainName,
  205. IN PKERB_ETYPE_INFO SuppliedSalt,
  206. IN PKERB_STORED_CREDENTIAL OldPasswords,
  207. IN OPTIONAL PUNICODE_STRING PrincipalName,
  208. IN KERB_ACCOUNT_TYPE AccountType,
  209. IN ULONG PasswordFlags,
  210. OUT PKERB_STORED_CREDENTIAL * PasswordList
  211. );
  212. VOID
  213. KerbFreeStoredCred(
  214. IN PKERB_STORED_CREDENTIAL StoredCred
  215. );
  216. NTSTATUS
  217. KerbReplacePasswords(
  218. IN PKERB_PRIMARY_CREDENTIAL Current,
  219. IN PKERB_PRIMARY_CREDENTIAL New
  220. );
  221. NTSTATUS
  222. KerbChangeCredentialsPassword(
  223. IN PKERB_PRIMARY_CREDENTIAL PrimaryCredentials,
  224. IN OPTIONAL PUNICODE_STRING NewPassword,
  225. IN OPTIONAL PKERB_ETYPE_INFO EtypeInfo,
  226. IN KERB_ACCOUNT_TYPE AccountType,
  227. IN ULONG PasswordFlags
  228. );
  229. NTSTATUS
  230. KerbAddExtraCredentialsToLogonSession(
  231. IN PKERB_LOGON_SESSION LogonSession,
  232. IN PKERB_ADD_CREDENTIALS_REQUEST AddCredRequest
  233. );
  234. //
  235. // Flags for logon sessions
  236. //
  237. #define KERB_LOGON_DEFERRED 0x1
  238. #define KERB_LOGON_NO_PASSWORD 0x2
  239. #define KERB_LOGON_LOCAL_ONLY 0x4
  240. #define KERB_LOGON_ONE_SHOT 0x8
  241. #define KERB_LOGON_SMARTCARD 0x10
  242. #define KERB_LOGON_MIT_REALM 0x20
  243. #define KERB_LOGON_HAS_TCB 0x40
  244. //
  245. // None of the below have credentials (TGT / pwd), so we need
  246. // to do S4U to go off box, or we'll use a NULL connection..
  247. //
  248. #define KERB_LOGON_S4U_SESSION 0x1000
  249. #define KERB_LOGON_DUMMY_SESSION 0x2000 // "other" package satisfied logon
  250. #define KERB_LOGON_ASC_SESSION 0x4000 // formed from AcceptSecurityCtxt.
  251. #define KERB_LOGON_TICKET_SESSION 0x0200
  252. #define KERB_LOGON_DELEGATE_OK 0x0100 // Means we can delegate this - ok for proxy
  253. #define KERB_LOGON_S4U_REQUIRED 0xF000
  254. //
  255. // Delegation with unconstrained delegation.
  256. //
  257. #define KERB_LOGON_DELEGATED 0x10000
  258. //
  259. // NewCredentials logon
  260. //
  261. #define KERB_LOGON_NEW_CREDENTIALS 0x20000
  262. #endif // __LOGONSES_H__