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.

599 lines
12 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. ntlmsspi.h
  5. Abstract:
  6. Header file describing the interface to code common to the
  7. NT Lanman Security Support Provider (NtLmSsp) Service and the DLL.
  8. Author:
  9. Cliff Van Dyke (CliffV) 17-Sep-1993
  10. Revision History:
  11. ChandanS 03-Aug-1996 Stolen from net\svcdlls\ntlmssp\common\ntlmsspi.h
  12. --*/
  13. #ifndef _NTLMSSPI_INCLUDED_
  14. #define _NTLMSSPI_INCLUDED_
  15. //
  16. // init.c will #include this file with NTLMCOMN_ALLOCATE defined.
  17. // That will cause each of these variables to be allocated.
  18. //
  19. #ifdef NTLMSSPI_ALLOCATE
  20. #define EXTERN
  21. #else
  22. #define EXTERN extern
  23. #endif
  24. ////////////////////////////////////////////////////////////////////////
  25. //
  26. // Global Definitions
  27. //
  28. ////////////////////////////////////////////////////////////////////////
  29. //
  30. // Description of a credential.
  31. //
  32. #define SSP_CREDENTIAL_TAG_ACTIVE (ULONG)('AdrC')
  33. #define SSP_CREDENTIAL_TAG_DELETE (ULONG)('DdrC')
  34. #define SSP_CREDENTIAL_FLAG_WAS_NETWORK_SERVICE 0x1
  35. typedef struct _SSP_CREDENTIAL {
  36. //
  37. // Global list of all Credentials.
  38. // (Serialized by SspCredentialCritSect)
  39. //
  40. LIST_ENTRY Next;
  41. //
  42. // Used to prevent this Credential from being deleted prematurely.
  43. // (Serialized by SspCredentialCritSect)
  44. //
  45. ULONG References;
  46. //
  47. // Flag of how credential may be used.
  48. //
  49. // SECPKG_CRED_* flags
  50. //
  51. ULONG CredentialUseFlags;
  52. //
  53. // Logon ID of the client
  54. //
  55. LUID LogonId;
  56. //
  57. // Process Id of client
  58. //
  59. ULONG ClientProcessID;
  60. //
  61. // Tag indicating credential is valid for fast reference.
  62. //
  63. ULONG CredentialTag;
  64. //
  65. // Impersonation level of caller at time of AcquireCredentialsHandle
  66. //
  67. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  68. //
  69. // Default credentials on client context, on server context UserName
  70. // holds a full user name (domain\user) and the other two should be
  71. // NULL.
  72. //
  73. UNICODE_STRING DomainName;
  74. UNICODE_STRING UserName;
  75. UNICODE_STRING Password;
  76. //
  77. // This flag should be set when the credential is unlinked
  78. // from the list.
  79. //
  80. BOOLEAN Unlinked;
  81. //
  82. // This flag is set when the credential was granted to a
  83. // kernel mode caller
  84. //
  85. BOOLEAN KernelClient ;
  86. //
  87. // ntlm specific credential usage flags
  88. //
  89. ULONG MutableCredFlags;
  90. } SSP_CREDENTIAL, *PSSP_CREDENTIAL;
  91. typedef enum {
  92. IdleState,
  93. NegotiateSentState, // Outbound context only
  94. ChallengeSentState, // Inbound context only
  95. AuthenticateSentState, // Outbound context only
  96. AuthenticatedState, // Inbound context only
  97. PassedToServiceState // Outbound context only
  98. } SSP_CONTEXT_STATE, *PSSP_CONTEXT_STATE;
  99. //
  100. // Description of a Context
  101. //
  102. #define SSP_CONTEXT_TAG_ACTIVE (ULONG64)('AxtC')
  103. #define SSP_CONTEXT_TAG_DELETE (ULONG64)('DxtC')
  104. typedef struct _SSP_CONTEXT {
  105. //
  106. // Tag indicating context is valid.
  107. //
  108. ULONG64 ContextTag;
  109. //
  110. // Timeout the context after awhile.
  111. //
  112. LARGE_INTEGER StartTime;
  113. ULONG Interval;
  114. //
  115. // Used to prevent this Context from being deleted prematurely.
  116. // (Serialized by SspContextCritSect)
  117. //
  118. ULONG References;
  119. //
  120. // Maintain the Negotiated protocol
  121. //
  122. ULONG NegotiateFlags;
  123. //
  124. // Maintain the context requirements
  125. //
  126. ULONG ContextFlags;
  127. //
  128. // State of the context
  129. //
  130. SSP_CONTEXT_STATE State;
  131. //
  132. // Token Handle of authenticated user
  133. // Only valid when in AuthenticatedState.
  134. //
  135. HANDLE TokenHandle;
  136. //
  137. // Referenced pointer to the credential used to create this
  138. // context.
  139. //
  140. PSSP_CREDENTIAL Credential;
  141. //
  142. // The challenge passed to the client.
  143. // Only valid when in ChallengeSentState.
  144. //
  145. UCHAR Challenge[MSV1_0_CHALLENGE_LENGTH];
  146. //
  147. // The session key calculated by the LSA
  148. //
  149. UCHAR SessionKey[MSV1_0_USER_SESSION_KEY_LENGTH];
  150. //
  151. // Default credentials.
  152. //
  153. UNICODE_STRING DomainName;
  154. UNICODE_STRING UserName;
  155. UNICODE_STRING Password;
  156. //
  157. // optional marshalled targetinfo for credential manager.
  158. //
  159. PCREDENTIAL_TARGET_INFORMATIONW TargetInfo;
  160. //
  161. // marshalled target info for DFS/RDR.
  162. //
  163. PBYTE pbMarshalledTargetInfo;
  164. ULONG cbMarshalledTargetInfo;
  165. //
  166. // context handle referenced to validate loopback operations.
  167. //
  168. ULONG_PTR ServerContextHandle;
  169. //
  170. // Process Id of client
  171. //
  172. ULONG ClientProcessID;
  173. NTSTATUS LastStatus;
  174. BOOLEAN Server; // client or server ? (can be implied by other fields...)
  175. BOOLEAN DownLevel; // downlevel RDR/SRV ?
  176. //
  177. // This flag is set when the context was granted to a
  178. // kernel mode caller
  179. //
  180. BOOLEAN KernelClient;
  181. } SSP_CONTEXT, *PSSP_CONTEXT;
  182. //
  183. // Maximum lifetime of a context
  184. //
  185. #if DBG
  186. #define NTLMSSP_MAX_LIFETIME (2*60*60*1000) // 2 hours
  187. #else
  188. // used to be 2 minutes, changed to 5 minutes to allow negotiation in
  189. // wide-area networks which can have long retry timeouts
  190. #define NTLMSSP_MAX_LIFETIME (5*60*1000) // 5 minutes
  191. #endif // DBG
  192. typedef struct _SSP_PROCESSOPTIONS {
  193. //
  194. // Global list of all process options.
  195. // (Serialized by NtLmGlobalProcessOptionsLock
  196. //
  197. LIST_ENTRY Next;
  198. //
  199. // Process Id of client
  200. //
  201. ULONG ClientProcessID;
  202. //
  203. // options bitmask.
  204. //
  205. ULONG ProcessOptions;
  206. } SSP_PROCESSOPTIONS, *PSSP_PROCESSOPTIONS;
  207. ////////////////////////////////////////////////////////////////////////
  208. //
  209. // Procedure Forwards
  210. //
  211. ////////////////////////////////////////////////////////////////////////
  212. //
  213. // Procedure forwards from credhand.cxx
  214. //
  215. NTSTATUS
  216. SspCredentialInitialize(
  217. VOID
  218. );
  219. VOID
  220. SspCredentialTerminate(
  221. VOID
  222. );
  223. NTSTATUS
  224. SspCredentialReferenceCredential(
  225. IN ULONG_PTR CredentialHandle,
  226. IN BOOLEAN DereferenceCredential,
  227. OUT PSSP_CREDENTIAL * UserCredential
  228. );
  229. VOID
  230. SspCredentialDereferenceCredential(
  231. PSSP_CREDENTIAL Credential
  232. );
  233. NTSTATUS
  234. SspCredentialGetPassword(
  235. IN PSSP_CREDENTIAL Credential,
  236. OUT PUNICODE_STRING Password
  237. );
  238. //
  239. // Procedure forwards from context.cxx
  240. //
  241. NTSTATUS
  242. SspContextInitialize(
  243. VOID
  244. );
  245. VOID
  246. SspContextTerminate(
  247. VOID
  248. );
  249. //
  250. // from ctxtcli.cxx
  251. //
  252. NTSTATUS
  253. CredpParseUserName(
  254. IN OUT LPWSTR ParseName,
  255. OUT LPWSTR* pUserName,
  256. OUT LPWSTR* pDomainName
  257. );
  258. NTSTATUS
  259. CopyCredManCredentials(
  260. IN PLUID LogonId,
  261. CREDENTIAL_TARGET_INFORMATIONW* pTargetInfo,
  262. IN OUT PSSP_CONTEXT Context,
  263. IN BOOLEAN fShareLevel
  264. );
  265. NTSTATUS
  266. CredpExtractMarshalledTargetInfo(
  267. IN PUNICODE_STRING TargetServerName,
  268. OUT CREDENTIAL_TARGET_INFORMATIONW **pTargetInfo
  269. );
  270. NTSTATUS
  271. CredpProcessUserNameCredential(
  272. IN PUNICODE_STRING MarshalledUserName,
  273. OUT PUNICODE_STRING UserName,
  274. OUT PUNICODE_STRING DomainName,
  275. OUT PUNICODE_STRING Password
  276. );
  277. //
  278. // random number generator.
  279. //
  280. NTSTATUS
  281. SspGenerateRandomBits(
  282. VOID *pRandomData,
  283. ULONG cRandomData
  284. );
  285. //
  286. // Procedure forwards from ntlm.cxx
  287. //
  288. VOID
  289. NtLmCheckLmCompatibility(
  290. );
  291. VOID
  292. NtLmQueryMappedDomains(
  293. VOID
  294. );
  295. VOID
  296. NtLmFreeMappedDomains(
  297. VOID
  298. );
  299. VOID
  300. NTAPI
  301. NtLmQueryDynamicGlobals(
  302. PVOID pvContext,
  303. BOOLEAN f
  304. );
  305. ULONG
  306. NtLmCheckProcessOption(
  307. IN ULONG OptionRequest
  308. );
  309. BOOLEAN
  310. NtLmSetProcessOption(
  311. IN ULONG OptionRequest,
  312. IN BOOLEAN DisableOption
  313. );
  314. //
  315. // Procedure forwards from rng.cxx
  316. //
  317. VOID
  318. NtLmCleanupRNG(VOID);
  319. BOOL
  320. NtLmInitializeRNG(VOID);
  321. /*++
  322. Brief description of the challenge/response algorithms for LM, NTLM, and NTLM3
  323. The basic outline is the same for all versions, just the OWF, RESP, and SESSKEY
  324. funcs are different:
  325. 1. Compute a "response key" (Kr) from the user's name (U), domain (UD) and password (P):
  326. Kr = OWF(U, UD, P)
  327. 2. Compute a response using the response key, server challenge (NS),
  328. client challenge (NC), timestamp (T), version (V), highest version
  329. client understands (HV), and the server's principal name (S)
  330. R = RESP(Kr, NS, NC, T, V, HV, S)
  331. 3. Compute a session key from Kr, U, UD
  332. Kx = SESSKEY(Kr, R, U, UD)
  333. The are the OWF, RESP, and SESSKEY funcs for NTLM3
  334. OWF(U, UD, P) = MD5(MD4(P), U, UD)
  335. RESP(Kr, NS, NC, T, V, HV, S) = (V, HV, R, T, NC, HMAC(Kr, (NS, V, HV, T, NC, S)), S)
  336. SESSKEY(Ku, R, U, UD) = HMAC(Kr, R)
  337. --*/
  338. PMSV1_0_AV_PAIR
  339. MsvpAvlInit(
  340. IN void * pAvList
  341. );
  342. PMSV1_0_AV_PAIR
  343. MsvpAvlGet(
  344. IN PMSV1_0_AV_PAIR pAvList, // first pair of AV pair list
  345. IN MSV1_0_AVID AvId, // AV pair to find
  346. IN LONG cAvList // size of AV list
  347. );
  348. ULONG
  349. MsvpAvlLen(
  350. IN PMSV1_0_AV_PAIR pAvList, // first pair of AV pair list
  351. IN LONG cAvList // max size of AV list
  352. );
  353. PMSV1_0_AV_PAIR
  354. MsvpAvlAdd(
  355. IN PMSV1_0_AV_PAIR pAvList, // first pair of AV pair list
  356. IN MSV1_0_AVID AvId, // AV pair to add
  357. IN PUNICODE_STRING pString, // value of pair
  358. IN LONG cAvList // max size of AV list
  359. );
  360. ULONG
  361. MsvpAvlSize(
  362. IN ULONG iPairs, // number of AV pairs response will include
  363. IN ULONG iPairsLen // total size of values for the pairs
  364. );
  365. NTSTATUS
  366. MsvpAvlToString(
  367. IN PUNICODE_STRING AvlString,
  368. IN MSV1_0_AVID AvId,
  369. IN OUT LPWSTR *szAvlString
  370. );
  371. NTSTATUS
  372. MsvpAvlToFlag(
  373. IN PUNICODE_STRING AvlString,
  374. IN MSV1_0_AVID AvId,
  375. IN OUT ULONG *ulAvlFlag
  376. );
  377. VOID
  378. MsvpCalculateNtlm2Challenge (
  379. IN UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH],
  380. IN UCHAR ChallengeFromClient[MSV1_0_CHALLENGE_LENGTH],
  381. OUT UCHAR Challenge[MSV1_0_CHALLENGE_LENGTH]
  382. );
  383. VOID
  384. MsvpCalculateNtlm2SessionKeys (
  385. IN PUSER_SESSION_KEY NtUserSessionKey,
  386. IN UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH],
  387. IN UCHAR ChallengeFromClient[MSV1_0_CHALLENGE_LENGTH],
  388. OUT PUSER_SESSION_KEY LocalUserSessionKey,
  389. OUT PLM_SESSION_KEY LocalLmSessionKey
  390. );
  391. //
  392. // calculate NTLM3 response from credentials and server name
  393. // called with pNtlm3Response filled in with version, client challenge, timestamp
  394. //
  395. VOID
  396. MsvpNtlm3Response (
  397. IN PNT_OWF_PASSWORD pNtOwfPassword,
  398. IN PUNICODE_STRING pUserName,
  399. IN PUNICODE_STRING pLogonDomainName,
  400. IN ULONG ServerNameLength,
  401. IN UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH],
  402. IN PMSV1_0_NTLM3_RESPONSE pNtlm3Response,
  403. OUT UCHAR Response[MSV1_0_NTLM3_RESPONSE_LENGTH],
  404. OUT PUSER_SESSION_KEY UserSessionKey,
  405. OUT PLM_SESSION_KEY LmSessionKey
  406. );
  407. typedef struct {
  408. UCHAR Response[MSV1_0_NTLM3_RESPONSE_LENGTH];
  409. UCHAR ChallengeFromClient[MSV1_0_CHALLENGE_LENGTH];
  410. } MSV1_0_LM3_RESPONSE, *PMSV1_0_LM3_RESPONSE;
  411. //
  412. // calculate LM3 response from credentials
  413. //
  414. VOID
  415. MsvpLm3Response (
  416. IN PNT_OWF_PASSWORD pNtOwfPassword,
  417. IN PUNICODE_STRING pUserName,
  418. IN PUNICODE_STRING pLogonDomainName,
  419. IN UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH],
  420. IN PMSV1_0_LM3_RESPONSE pLm3Response,
  421. OUT UCHAR Response[MSV1_0_NTLM3_RESPONSE_LENGTH]
  422. );
  423. NTSTATUS
  424. MsvpLm20GetNtlm3ChallengeResponse (
  425. IN PNT_OWF_PASSWORD pNtOwfPassword,
  426. IN PUNICODE_STRING pUserName,
  427. IN PUNICODE_STRING pLogonDomainName,
  428. IN PUNICODE_STRING pServerName,
  429. IN UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH],
  430. OUT PMSV1_0_NTLM3_RESPONSE pNtlm3Response,
  431. OUT PMSV1_0_LM3_RESPONSE pLm3Response,
  432. OUT PUSER_SESSION_KEY UserSessionKey,
  433. OUT PLM_SESSION_KEY LmSessionKey
  434. );
  435. #endif // ifndef _NTLMSSPI_INCLUDED_