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.

621 lines
13 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. typedef struct _NTLM_VER_INFO {
  100. ULONG64 Major : 8;
  101. ULONG64 Minor : 8;
  102. ULONG64 Build : 16;
  103. ULONG64 Reserved : 24;
  104. ULONG64 Revision : 8;
  105. } NTLM_VER_INFO, *PNTLM_VER_INFO;
  106. //
  107. // Description of a Context
  108. //
  109. #define SSP_CONTEXT_TAG_ACTIVE (ULONG64)('AxtC')
  110. #define SSP_CONTEXT_TAG_DELETE (ULONG64)('DxtC')
  111. typedef struct _SSP_CONTEXT {
  112. //
  113. // Tag indicating context is valid.
  114. //
  115. ULONG64 ContextTag;
  116. //
  117. // Timeout the context after awhile.
  118. //
  119. ULONG TickStart;
  120. LARGE_INTEGER StartTime;
  121. ULONG Interval;
  122. //
  123. // Used to prevent this Context from being deleted prematurely.
  124. // (Serialized by SspContextCritSect)
  125. //
  126. ULONG References;
  127. //
  128. // Maintain the Negotiated protocol
  129. //
  130. ULONG NegotiateFlags;
  131. //
  132. // Maintain the context requirements
  133. //
  134. ULONG ContextFlags;
  135. //
  136. // State of the context
  137. //
  138. SSP_CONTEXT_STATE State;
  139. //
  140. // Token Handle of authenticated user
  141. // Only valid when in AuthenticatedState.
  142. //
  143. HANDLE TokenHandle;
  144. //
  145. // Referenced pointer to the credential used to create this
  146. // context.
  147. //
  148. PSSP_CREDENTIAL Credential;
  149. //
  150. // The challenge passed to the client.
  151. // Only valid when in ChallengeSentState.
  152. //
  153. UCHAR Challenge[MSV1_0_CHALLENGE_LENGTH];
  154. //
  155. // The session key calculated by the LSA
  156. //
  157. UCHAR SessionKey[MSV1_0_USER_SESSION_KEY_LENGTH];
  158. //
  159. // Default credentials.
  160. //
  161. UNICODE_STRING DomainName;
  162. UNICODE_STRING UserName;
  163. UNICODE_STRING Password;
  164. //
  165. // optional marshalled targetinfo for credential manager.
  166. //
  167. PCREDENTIAL_TARGET_INFORMATIONW TargetInfo;
  168. //
  169. // marshalled target info for DFS/RDR.
  170. //
  171. PBYTE pbMarshalledTargetInfo;
  172. ULONG cbMarshalledTargetInfo;
  173. //
  174. // context handle referenced to validate loopback operations.
  175. //
  176. ULONG_PTR ServerContextHandle;
  177. //
  178. // Process Id of client
  179. //
  180. ULONG ClientProcessID;
  181. NTSTATUS LastStatus;
  182. BOOLEAN Server; // client or server ? (can be implied by other fields...)
  183. BOOLEAN DownLevel; // downlevel RDR/SRV ?
  184. //
  185. // This flag is set when the context was granted to a
  186. // kernel mode caller
  187. //
  188. BOOLEAN KernelClient;
  189. //
  190. // version control
  191. //
  192. union {
  193. NTLM_VER_INFO ClientVersion; // stored in server context
  194. NTLM_VER_INFO ServerVersion; // stored in client context
  195. };
  196. CHAR ContextMagicNumber[MSV1_0_USER_SESSION_KEY_LENGTH];
  197. } SSP_CONTEXT, *PSSP_CONTEXT;
  198. //
  199. // Maximum lifetime of a context
  200. //
  201. #if DBG
  202. #define NTLMSSP_MAX_LIFETIME (2*60*60*1000) // 2 hours
  203. #else
  204. // used to be 2 minutes, changed to 5 minutes to allow negotiation in
  205. // wide-area networks which can have long retry timeouts
  206. #define NTLMSSP_MAX_LIFETIME (5*60*1000) // 5 minutes
  207. #endif // DBG
  208. typedef struct _SSP_PROCESSOPTIONS {
  209. //
  210. // Global list of all process options.
  211. // (Serialized by NtLmGlobalProcessOptionsLock
  212. //
  213. LIST_ENTRY Next;
  214. //
  215. // Process Id of client
  216. //
  217. ULONG ClientProcessID;
  218. //
  219. // options bitmask.
  220. //
  221. ULONG ProcessOptions;
  222. } SSP_PROCESSOPTIONS, *PSSP_PROCESSOPTIONS;
  223. ////////////////////////////////////////////////////////////////////////
  224. //
  225. // Procedure Forwards
  226. //
  227. ////////////////////////////////////////////////////////////////////////
  228. //
  229. // Procedure forwards from credhand.cxx
  230. //
  231. NTSTATUS
  232. SspCredentialInitialize(
  233. VOID
  234. );
  235. VOID
  236. SspCredentialTerminate(
  237. VOID
  238. );
  239. NTSTATUS
  240. SspCredentialReferenceCredential(
  241. IN ULONG_PTR CredentialHandle,
  242. IN BOOLEAN DereferenceCredential,
  243. OUT PSSP_CREDENTIAL * UserCredential
  244. );
  245. VOID
  246. SspCredentialDereferenceCredential(
  247. PSSP_CREDENTIAL Credential
  248. );
  249. NTSTATUS
  250. SspCredentialGetPassword(
  251. IN PSSP_CREDENTIAL Credential,
  252. OUT PUNICODE_STRING Password
  253. );
  254. //
  255. // Procedure forwards from context.cxx
  256. //
  257. NTSTATUS
  258. SspContextInitialize(
  259. VOID
  260. );
  261. VOID
  262. SspContextTerminate(
  263. VOID
  264. );
  265. //
  266. // from ctxtcli.cxx
  267. //
  268. NTSTATUS
  269. CredpParseUserName(
  270. IN OUT LPWSTR ParseName,
  271. OUT LPWSTR* pUserName,
  272. OUT LPWSTR* pDomainName
  273. );
  274. NTSTATUS
  275. CopyCredManCredentials(
  276. IN PLUID LogonId,
  277. IN CREDENTIAL_TARGET_INFORMATIONW* pTargetInfo,
  278. IN OUT PSSP_CONTEXT Context,
  279. IN BOOLEAN fShareLevel,
  280. IN BOOLEAN bAllowOwfPassword,
  281. OUT BOOLEAN* pbIsOwfPassword
  282. );
  283. NTSTATUS
  284. CredpExtractMarshalledTargetInfo(
  285. IN PUNICODE_STRING TargetServerName,
  286. OUT CREDENTIAL_TARGET_INFORMATIONW **pTargetInfo
  287. );
  288. NTSTATUS
  289. CredpProcessUserNameCredential(
  290. IN PUNICODE_STRING MarshalledUserName,
  291. OUT PUNICODE_STRING UserName,
  292. OUT PUNICODE_STRING DomainName,
  293. OUT PUNICODE_STRING Password
  294. );
  295. //
  296. // random number generator.
  297. //
  298. NTSTATUS
  299. SspGenerateRandomBits(
  300. VOID *pRandomData,
  301. ULONG cRandomData
  302. );
  303. //
  304. // Procedure forwards from ntlm.cxx
  305. //
  306. VOID
  307. NtLmCheckLmCompatibility(
  308. );
  309. VOID
  310. NtLmQueryMappedDomains(
  311. VOID
  312. );
  313. VOID
  314. NtLmFreeMappedDomains(
  315. VOID
  316. );
  317. VOID
  318. NTAPI
  319. NtLmQueryDynamicGlobals(
  320. PVOID pvContext,
  321. BOOLEAN TimedOut
  322. );
  323. ULONG
  324. NtLmCheckProcessOption(
  325. IN ULONG OptionRequest
  326. );
  327. BOOLEAN
  328. NtLmSetProcessOption(
  329. IN ULONG OptionRequest,
  330. IN BOOLEAN DisableOption
  331. );
  332. //
  333. // Procedure forwards from rng.cxx
  334. //
  335. VOID
  336. NtLmCleanupRNG(VOID);
  337. BOOL
  338. NtLmInitializeRNG(VOID);
  339. /*++
  340. Brief description of the challenge/response algorithms for LM, NTLM, and NTLM3
  341. The basic outline is the same for all versions, just the OWF, RESP, and SESSKEY
  342. funcs are different:
  343. 1. Compute a "response key" (Kr) from the user's name (U), domain (UD) and password (P):
  344. Kr = OWF(U, UD, P)
  345. 2. Compute a response using the response key, server challenge (NS),
  346. client challenge (NC), timestamp (T), version (V), highest version
  347. client understands (HV), and the server's principal name (S)
  348. R = RESP(Kr, NS, NC, T, V, HV, S)
  349. 3. Compute a session key from Kr, U, UD
  350. Kx = SESSKEY(Kr, R, U, UD)
  351. The are the OWF, RESP, and SESSKEY funcs for NTLM3
  352. OWF(U, UD, P) = MD5(MD4(P), U, UD)
  353. RESP(Kr, NS, NC, T, V, HV, S) = (V, HV, R, T, NC, HMAC(Kr, (NS, V, HV, T, NC, S)), S)
  354. SESSKEY(Ku, R, U, UD) = HMAC(Kr, R)
  355. --*/
  356. PMSV1_0_AV_PAIR
  357. MsvpAvlInit(
  358. IN void * pAvList
  359. );
  360. PMSV1_0_AV_PAIR
  361. MsvpAvlGet(
  362. IN PMSV1_0_AV_PAIR pAvList, // first pair of AV pair list
  363. IN MSV1_0_AVID AvId, // AV pair to find
  364. IN LONG cAvList // size of AV list
  365. );
  366. ULONG
  367. MsvpAvlLen(
  368. IN PMSV1_0_AV_PAIR pAvList, // first pair of AV pair list
  369. IN LONG cAvList // max size of AV list
  370. );
  371. PMSV1_0_AV_PAIR
  372. MsvpAvlAdd(
  373. IN PMSV1_0_AV_PAIR pAvList, // first pair of AV pair list
  374. IN MSV1_0_AVID AvId, // AV pair to add
  375. IN PUNICODE_STRING pString, // value of pair
  376. IN LONG cAvList // max size of AV list
  377. );
  378. ULONG
  379. MsvpAvlSize(
  380. IN ULONG iPairs, // number of AV pairs response will include
  381. IN ULONG iPairsLen // total size of values for the pairs
  382. );
  383. NTSTATUS
  384. MsvpAvlToString(
  385. IN PUNICODE_STRING AvlString,
  386. IN MSV1_0_AVID AvId,
  387. IN OUT LPWSTR *szAvlString
  388. );
  389. NTSTATUS
  390. MsvpAvlToFlag(
  391. IN PUNICODE_STRING AvlString,
  392. IN MSV1_0_AVID AvId,
  393. IN OUT ULONG *ulAvlFlag
  394. );
  395. VOID
  396. MsvpCalculateNtlm2Challenge (
  397. IN UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH],
  398. IN UCHAR ChallengeFromClient[MSV1_0_CHALLENGE_LENGTH],
  399. OUT UCHAR Challenge[MSV1_0_CHALLENGE_LENGTH]
  400. );
  401. VOID
  402. MsvpCalculateNtlm2SessionKeys (
  403. IN PUSER_SESSION_KEY NtUserSessionKey,
  404. IN UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH],
  405. IN UCHAR ChallengeFromClient[MSV1_0_CHALLENGE_LENGTH],
  406. OUT PUSER_SESSION_KEY LocalUserSessionKey,
  407. OUT PLM_SESSION_KEY LocalLmSessionKey
  408. );
  409. //
  410. // calculate NTLM3 response from credentials and server name
  411. // called with pNtlm3Response filled in with version, client challenge, timestamp
  412. //
  413. VOID
  414. MsvpNtlm3Response (
  415. IN PNT_OWF_PASSWORD pNtOwfPassword,
  416. IN PUNICODE_STRING pUserName,
  417. IN PUNICODE_STRING pLogonDomainName,
  418. IN ULONG ServerNameLength,
  419. IN UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH],
  420. IN PMSV1_0_NTLM3_RESPONSE pNtlm3Response,
  421. OUT UCHAR Response[MSV1_0_NTLM3_RESPONSE_LENGTH],
  422. OUT PUSER_SESSION_KEY UserSessionKey,
  423. OUT PLM_SESSION_KEY LmSessionKey
  424. );
  425. typedef struct {
  426. UCHAR Response[MSV1_0_NTLM3_RESPONSE_LENGTH];
  427. UCHAR ChallengeFromClient[MSV1_0_CHALLENGE_LENGTH];
  428. } MSV1_0_LM3_RESPONSE, *PMSV1_0_LM3_RESPONSE;
  429. //
  430. // calculate LM3 response from credentials
  431. //
  432. VOID
  433. MsvpLm3Response (
  434. IN PNT_OWF_PASSWORD pNtOwfPassword,
  435. IN PUNICODE_STRING pUserName,
  436. IN PUNICODE_STRING pLogonDomainName,
  437. IN UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH],
  438. IN PMSV1_0_LM3_RESPONSE pLm3Response,
  439. OUT UCHAR Response[MSV1_0_NTLM3_RESPONSE_LENGTH],
  440. OUT PUSER_SESSION_KEY UserSessionKey,
  441. OUT PLM_SESSION_KEY LmSessionKey
  442. );
  443. NTSTATUS
  444. MsvpLm20GetNtlm3ChallengeResponse (
  445. IN PNT_OWF_PASSWORD pNtOwfPassword,
  446. IN PUNICODE_STRING pUserName,
  447. IN PUNICODE_STRING pLogonDomainName,
  448. IN PUNICODE_STRING pServerName,
  449. IN UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH],
  450. OUT PMSV1_0_NTLM3_RESPONSE pNtlm3Response,
  451. OUT PMSV1_0_LM3_RESPONSE pLm3Response,
  452. OUT PUSER_SESSION_KEY UserSessionKey,
  453. OUT PLM_SESSION_KEY LmSessionKey
  454. );
  455. #endif // ifndef _NTLMSSPI_INCLUDED_