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.

618 lines
16 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. nlp.h
  5. Abstract:
  6. NETLOGON private definitions.
  7. Author:
  8. Jim Kelly 11-Apr-1991
  9. Revision History:
  10. Chandana Surlu 21-Jul-96 Stolen from \\kernel\razzle3\src\security\msv1_0\nlp.h
  11. --*/
  12. #ifndef _NLP_
  13. #define _NLP_
  14. #include <windef.h>
  15. #include <winbase.h>
  16. #include <crypt.h>
  17. #include <lmcons.h>
  18. #include <ntsam.h>
  19. #include <ntsamp.h>
  20. #include <logonmsv.h>
  21. #include <samrpc.h>
  22. #include <align.h>
  23. #include <dsgetdc.h>
  24. #include <ntdsapi.h>
  25. #ifdef __cplusplus
  26. extern "C"
  27. {
  28. #endif // __cplusplus
  29. //
  30. // nlmain.c will #include this file with NLP_ALLOCATE defined.
  31. // That will cause each of these variables to be allocated.
  32. //
  33. #ifdef EXTERN
  34. #undef EXTERN
  35. #endif
  36. #ifdef NLP_ALLOCATE
  37. #define EXTERN
  38. #define INIT(_X) = _X
  39. #else
  40. #define EXTERN extern
  41. #define INIT(_X)
  42. #endif
  43. //
  44. // Amount of time to wait for netlogon to start.
  45. // Do this AFTER waiting for SAM to start.
  46. // Since Netlogon depends on SAM, don't timeout too soon.
  47. #define NETLOGON_STARTUP_TIME 45 // 45 seconds
  48. //
  49. // Amount of time to wait for SAM to start.
  50. // DS recovery can take a very long time.
  51. #define SAM_STARTUP_TIME (20*60) // 20 minutes
  52. ///////////////////////////////////////////////////////////////////////////////
  53. // //
  54. // Private data structures //
  55. // //
  56. ///////////////////////////////////////////////////////////////////////////////
  57. //
  58. // Magic values to protect ourselves from mean spirited packages "NTLM"
  59. //
  60. #define NTLM_ACTIVE_LOGON_MAGIC_SIGNATURE 0x4D4C544E
  61. //
  62. // Structure used to keep track of all private information related to a
  63. // particular LogonId.
  64. //
  65. typedef struct _ACTIVE_LOGON {
  66. LIST_ENTRY ListEntry;
  67. ULONG Signature;
  68. LUID LogonId; // The logon Id of this logon session
  69. ULONG EnumHandle; // The enumeration handle of this logon session
  70. SECURITY_LOGON_TYPE LogonType; // Type of logon (interactive or service)
  71. PSID UserSid; // Sid of the logged on user
  72. UNICODE_STRING UserName; // SAM Account name of the logged on user (Required)
  73. UNICODE_STRING LogonDomainName; // Netbios name of the domain logged onto (Required)
  74. UNICODE_STRING LogonServer; // Name of the server which logged this user on
  75. ULONG Flags; // Attributes of this entry.
  76. #define LOGON_BY_NETLOGON 0x01 // Entry was validated by NETLOGON service
  77. #define LOGON_BY_CACHE 0x02 // Entry was validated by local cache
  78. #define LOGON_BY_OTHER_PACKAGE 0x04 // Entry was validated by another authentication package
  79. #define LOGON_BY_LOCAL 0x08 // Entry was validated by local sam
  80. #define LOGON_BY_NTLM3_DC 0x10 // Entry was validated by DC that understands NTLM3
  81. } ACTIVE_LOGON, *PACTIVE_LOGON;
  82. ///////////////////////////////////////////////////////////////////////////////
  83. // //
  84. // CREDENTIAL Related Data Structures //
  85. // //
  86. ///////////////////////////////////////////////////////////////////////////////
  87. //
  88. // Following is a description of the content and format of each type
  89. // of credential maintained by the MsV1_0 authentication package.
  90. //
  91. // The MsV1_0 authentication package defines the following credential
  92. // primary key string values:
  93. //
  94. // "Primary" - Is used to hold the primary credentials provided at
  95. // initial logon time. This includes the username and both
  96. // case-sensitive and case-insensitive forms of the user's
  97. // password.
  98. //
  99. // NOTE: All poitners stored in credentials must be
  100. // changed to be an offset to the body rather than a pointer. This is
  101. // because credential fields are copied by the LSA and so the pointer
  102. // would become invalid.
  103. //
  104. //
  105. // MsV1_0 Primary Credentials
  106. //
  107. //
  108. // The PrimaryKeyValue string of this type of credential contains the
  109. // following string:
  110. //
  111. // "Primary"
  112. //
  113. // The Credential string of a Primary credential contains the following
  114. // values:
  115. //
  116. // o The user's username
  117. //
  118. // o A one-way function of the user's password as typed.
  119. //
  120. // o A one-way function of the user's password upper-cased.
  121. //
  122. // These values are structured as follows:
  123. //
  124. #define MSV1_0_PRIMARY_KEY "Primary"
  125. //
  126. // move the SHA stuff to crypt.h when possible.
  127. //
  128. typedef UNICODE_STRING SHA_PASSWORD;
  129. typedef SHA_PASSWORD * PSHA_PASSWORD;
  130. #define SHA_OWF_PASSWORD_LENGTH (20)
  131. typedef struct {
  132. CHAR Data[ SHA_OWF_PASSWORD_LENGTH ];
  133. } SHA_OWF_PASSWORD, *PSHA_OWF_PASSWORD;
  134. NTSTATUS
  135. RtlCalculateShaOwfPassword(
  136. IN PSHA_PASSWORD ShaPassword,
  137. OUT PSHA_OWF_PASSWORD ShaOwfPassword
  138. );
  139. typedef struct _MSV1_0_PRIMARY_CREDENTIAL {
  140. UNICODE_STRING LogonDomainName;
  141. UNICODE_STRING UserName;
  142. NT_OWF_PASSWORD NtOwfPassword;
  143. LM_OWF_PASSWORD LmOwfPassword;
  144. SHA_OWF_PASSWORD ShaOwfPassword;
  145. BOOLEAN NtPasswordPresent;
  146. BOOLEAN LmPasswordPresent;
  147. BOOLEAN ShaPasswordPresent;
  148. } MSV1_0_PRIMARY_CREDENTIAL, *PMSV1_0_PRIMARY_CREDENTIAL;
  149. //
  150. // Structure describing a buffer in the clients address space.
  151. //
  152. typedef struct _CLIENT_BUFFER_DESC {
  153. PLSA_CLIENT_REQUEST ClientRequest;
  154. LPBYTE UserBuffer; // Address of buffer in client's address space
  155. LPBYTE MsvBuffer; // Address of mirror buffer in MSV's address space
  156. ULONG StringOffset; // Current offset to variable length data
  157. ULONG TotalSize; // Size (in bytes) of buffer
  158. } CLIENT_BUFFER_DESC, *PCLIENT_BUFFER_DESC;
  159. ///////////////////////////////////////////////////////////////////////////////
  160. // //
  161. // Internal routine definitions //
  162. // //
  163. ///////////////////////////////////////////////////////////////////////////////
  164. //
  165. // From nlmain.c.
  166. //
  167. NTSTATUS
  168. NlSamInitialize(
  169. ULONG Timeout
  170. );
  171. //
  172. // From nlp.c.
  173. //
  174. VOID
  175. NlpPutString(
  176. IN PUNICODE_STRING OutString,
  177. IN PUNICODE_STRING InString,
  178. IN PUCHAR *Where
  179. );
  180. VOID
  181. NlpInitClientBuffer(
  182. OUT PCLIENT_BUFFER_DESC ClientBufferDesc,
  183. IN PLSA_CLIENT_REQUEST ClientRequest
  184. );
  185. NTSTATUS
  186. NlpAllocateClientBuffer(
  187. IN OUT PCLIENT_BUFFER_DESC ClientBufferDesc,
  188. IN ULONG FixedSize,
  189. IN ULONG TotalSize
  190. );
  191. NTSTATUS
  192. NlpFlushClientBuffer(
  193. IN OUT PCLIENT_BUFFER_DESC ClientBufferDesc,
  194. OUT PVOID* UserBuffer
  195. );
  196. VOID
  197. NlpFreeClientBuffer(
  198. IN OUT PCLIENT_BUFFER_DESC ClientBufferDesc
  199. );
  200. VOID
  201. NlpPutClientString(
  202. IN OUT PCLIENT_BUFFER_DESC ClientBufferDesc,
  203. IN PUNICODE_STRING OutString,
  204. IN PUNICODE_STRING InString
  205. );
  206. VOID
  207. NlpMakeRelativeString(
  208. IN PUCHAR BaseAddress,
  209. IN OUT PUNICODE_STRING String
  210. );
  211. VOID
  212. NlpRelativeToAbsolute(
  213. IN PVOID BaseAddress,
  214. IN OUT PULONG_PTR RelativeValue
  215. );
  216. ACTIVE_LOGON*
  217. NlpFindActiveLogon(
  218. IN LUID* pLogonId
  219. );
  220. ULONG
  221. NlpCountActiveLogon(
  222. IN PUNICODE_STRING LogonDomainName,
  223. IN PUNICODE_STRING UserName
  224. );
  225. NTSTATUS
  226. NlpAllocateInteractiveProfile (
  227. IN PLSA_CLIENT_REQUEST ClientRequest,
  228. OUT PMSV1_0_INTERACTIVE_PROFILE *ProfileBuffer,
  229. OUT PULONG ProfileBufferSize,
  230. IN PNETLOGON_VALIDATION_SAM_INFO4 NlpUser
  231. );
  232. NTSTATUS
  233. NlpAllocateNetworkProfile (
  234. IN PLSA_CLIENT_REQUEST ClientRequest,
  235. OUT PMSV1_0_LM20_LOGON_PROFILE *ProfileBuffer,
  236. OUT PULONG ProfileBufferSize,
  237. IN PNETLOGON_VALIDATION_SAM_INFO4 NlpUser,
  238. IN ULONG ParameterControl
  239. );
  240. PSID
  241. NlpMakeDomainRelativeSid(
  242. IN PSID DomainId,
  243. IN ULONG RelativeId
  244. );
  245. NTSTATUS
  246. NlpMakeTokenInformationV2(
  247. IN PNETLOGON_VALIDATION_SAM_INFO4 NlpUser,
  248. OUT PLSA_TOKEN_INFORMATION_V1 *TokenInformation
  249. );
  250. VOID
  251. NlpPutOwfsInPrimaryCredential(
  252. IN PUNICODE_STRING CleartextPassword,
  253. IN BOOLEAN bIsOwfPassword,
  254. OUT PMSV1_0_PRIMARY_CREDENTIAL Credential
  255. );
  256. NTSTATUS
  257. NlpMakePrimaryCredential(
  258. IN PUNICODE_STRING LogonDomainName,
  259. IN PUNICODE_STRING UserName,
  260. IN PUNICODE_STRING CleartextPassword,
  261. OUT PMSV1_0_PRIMARY_CREDENTIAL *CredentialBuffer,
  262. OUT PULONG CredentialSize
  263. );
  264. NTSTATUS
  265. NlpMakePrimaryCredentialFromMsvCredential(
  266. IN PUNICODE_STRING LogonDomainName,
  267. IN PUNICODE_STRING UserName,
  268. IN PMSV1_0_SUPPLEMENTAL_CREDENTIAL MsvCredential,
  269. OUT PMSV1_0_PRIMARY_CREDENTIAL *CredentialBuffer,
  270. OUT PULONG CredentialSize
  271. );
  272. NTSTATUS
  273. NlpAddPrimaryCredential(
  274. IN PLUID LogonId,
  275. IN PMSV1_0_PRIMARY_CREDENTIAL Credential,
  276. IN ULONG CredentialSize
  277. );
  278. NTSTATUS
  279. NlpGetPrimaryCredential(
  280. IN PLUID LogonId,
  281. OUT PMSV1_0_PRIMARY_CREDENTIAL *CredentialBuffer,
  282. OUT PULONG CredentialSize
  283. );
  284. NTSTATUS
  285. NlpGetPrimaryCredentialByUserSid(
  286. IN PSID pSid,
  287. OUT PMSV1_0_PRIMARY_CREDENTIAL *CredentialBuffer,
  288. OUT PULONG CredentialSize OPTIONAL
  289. );
  290. NTSTATUS
  291. NlpDeletePrimaryCredential(
  292. IN PLUID LogonId
  293. );
  294. NTSTATUS
  295. NlpChangePassword(
  296. IN BOOLEAN Validated,
  297. IN PUNICODE_STRING DomainName,
  298. IN PUNICODE_STRING UserName,
  299. IN PUNICODE_STRING Password
  300. );
  301. NTSTATUS
  302. NlpChangePwdCredByLogonId(
  303. IN PLUID pLogonId,
  304. IN PMSV1_0_PRIMARY_CREDENTIAL pNewCredential,
  305. IN BOOL bNotify
  306. );
  307. VOID
  308. NlpGetAccountNames(
  309. IN PNETLOGON_LOGON_IDENTITY_INFO LogonInfo,
  310. IN PNETLOGON_VALIDATION_SAM_INFO4 NlpUser,
  311. OUT PUNICODE_STRING SamAccountName,
  312. OUT PUNICODE_STRING NetbiosDomainName,
  313. OUT PUNICODE_STRING DnsDomainName,
  314. OUT PUNICODE_STRING Upn
  315. );
  316. //
  317. // msvsam.c
  318. //
  319. BOOLEAN
  320. MsvpPasswordValidate (
  321. IN BOOLEAN UasCompatibilityRequired,
  322. IN NETLOGON_LOGON_INFO_CLASS LogonLevel,
  323. IN PVOID LogonInformation,
  324. IN PUSER_INTERNAL1_INFORMATION Passwords,
  325. OUT PULONG UserFlags,
  326. OUT PUSER_SESSION_KEY UserSessionKey,
  327. OUT PLM_SESSION_KEY LmSessionKey
  328. );
  329. //
  330. // nlnetapi.c
  331. //
  332. VOID
  333. NlpLoadNetapiDll (
  334. VOID
  335. );
  336. VOID
  337. NlpLoadNetlogonDll (
  338. VOID
  339. );
  340. //
  341. // subauth.c
  342. //
  343. VOID
  344. Msv1_0SubAuthenticationInitialization(
  345. VOID
  346. );
  347. ///////////////////////////////////////////////////////////////////////
  348. // //
  349. // Global variables //
  350. // //
  351. ///////////////////////////////////////////////////////////////////////
  352. ////////////////////////////////////////////////////////////////////////
  353. // //
  354. // READ ONLY Variables //
  355. // //
  356. ////////////////////////////////////////////////////////////////////////
  357. //
  358. // Null copies of Lanman and NT OWF password.
  359. //
  360. //
  361. EXTERN LM_OWF_PASSWORD NlpNullLmOwfPassword;
  362. EXTERN NT_OWF_PASSWORD NlpNullNtOwfPassword;
  363. //
  364. // Flag indicating our support for the LM challenge response protocol.
  365. // If the flag is set to NoLm, MSV1_0 will not ever compute a LM
  366. // challenge response. If it is set to AllowLm, MSV1_0 will not return
  367. // it unless requested. Otherwise it will do the normal behaviour of
  368. // returning both NT and LM challenge responses
  369. //
  370. typedef enum _LM_PROTOCOL_SUPPORT {
  371. UseLm, // send LM response, NTLM response
  372. AllowLm, // same as UseLm; for b/w compat w/lsa2-fix
  373. NoLm, //UseNtlm, // Send NTLM response only; for b/w compat w/lsa2-fix
  374. UseNtlm3, // Send NTLM3 response even if no target domain\server specified
  375. RefuseLm, // Refuse LM responses (no Win9x clients) -- unsupported, reserved
  376. RefuseNtlm, // Refuse LM and NTLM responses (require all clients are upgraded)
  377. RefuseNtlm3NoTarget // Refuse NTLM3 response witout domain and server info
  378. } LM_PROTOCOL_SUPPORT, *PLM_PROTOCOL_SUPPORT;
  379. #if 0
  380. //
  381. // This macro determines whether or not to return an LM challenge response.
  382. // If NlpProtocolSupport == UseLm, we always return it. If it is
  383. // AllowLm, only return it if the RETURN_LM_RESPONSE flag is set. Otherwise
  384. // don't return it ever.
  385. //
  386. #define NlpReturnLmResponse(_Flags_) \
  387. ((NlpLmProtocolSupport == UseLm) || \
  388. ((NlpLmProtocolSupport == AllowLm) && \
  389. (((_Flags_) & RETURN_NON_NT_USER_SESSION_KEY) != 0)))
  390. #define NlpChallengeResponseRequestSupported( _Flags_ ) \
  391. ((((_Flags_) & RETURN_NON_NT_USER_SESSION_KEY) == 0) || (NlpLmProtocolSupport != NoLm))
  392. #endif
  393. NET_API_STATUS NET_API_FUNCTION RxNetUserPasswordSet(LPWSTR, LPWSTR, LPWSTR, LPWSTR);
  394. NTSTATUS NetpApiStatusToNtStatus( NET_API_STATUS );
  395. //
  396. // Routines in netlogon.dll
  397. //
  398. EXTERN HANDLE NlpNetlogonDllHandle;
  399. EXTERN PNETLOGON_SAM_LOGON_PROCEDURE NlpNetLogonSamLogon;
  400. typedef NTSTATUS
  401. (*PNETLOGON_MIXED_DOMAIN_PROCEDURE)(
  402. OUT PBOOL MixedMode
  403. );
  404. EXTERN PNETLOGON_MIXED_DOMAIN_PROCEDURE NlpNetLogonMixedDomain;
  405. //
  406. // TRUE if package is initialized
  407. //
  408. EXTERN BOOLEAN NlpMsvInitialized INIT(FALSE);
  409. //
  410. // TRUE if this is a workstation.
  411. //
  412. EXTERN BOOLEAN NlpWorkstation INIT(TRUE);
  413. //
  414. // TRUE once the MSV AP has initialized its connection to SAM.
  415. //
  416. EXTERN BOOLEAN NlpSamInitialized INIT(FALSE);
  417. //
  418. // TRUE if the MSV AP has initialized its connection to the NETLOGON service
  419. //
  420. EXTERN BOOLEAN NlpNetlogonInitialized INIT(FALSE);
  421. //
  422. // TRUE if LanMan is installed.
  423. //
  424. EXTERN BOOLEAN NlpLanmanInstalled INIT(FALSE);
  425. //
  426. // Computername of this computer.
  427. //
  428. EXTERN UNICODE_STRING NlpComputerName;
  429. //
  430. // Domain of which I am a member.
  431. //
  432. EXTERN UNICODE_STRING NlpPrimaryDomainName;
  433. //
  434. // Name of the MSV1_0 package
  435. //
  436. EXTERN UNICODE_STRING NlpMsv1_0PackageName;
  437. //
  438. // Name and domain id of the SAM account database.
  439. //
  440. EXTERN UNICODE_STRING NlpSamDomainName;
  441. EXTERN PSID NlpSamDomainId;
  442. EXTERN SAMPR_HANDLE NlpSamDomainHandle;
  443. EXTERN BOOLEAN NlpUasCompatibilityRequired INIT(TRUE);
  444. //
  445. // TRUE if there is a subauthentication package zero
  446. //
  447. EXTERN BOOLEAN NlpSubAuthZeroExists INIT(TRUE);
  448. ////////////////////////////////////////////////////////////////////////
  449. // //
  450. // READ/WRITE Variables //
  451. // //
  452. ////////////////////////////////////////////////////////////////////////
  453. //
  454. // Define the list of active interactive logons.
  455. //
  456. // The NlpActiveLogonLock must be locked while referencing the list or
  457. // any of its elements.
  458. //
  459. #define NlpLockActiveLogonsRead() RtlAcquireResourceShared(&NlpActiveLogonLock,TRUE)
  460. #define NlpLockActiveLogonsWrite() RtlAcquireResourceExclusive(&NlpActiveLogonLock,TRUE)
  461. #define NlpLockActiveLogonsReadToWrite() RtlConvertSharedToExclusive(&NlpActiveLogonLock)
  462. #define NlpUnlockActiveLogons() RtlReleaseResource(&NlpActiveLogonLock)
  463. EXTERN RTL_RESOURCE NlpActiveLogonLock;
  464. EXTERN LIST_ENTRY NlpActiveLogonListAnchor;
  465. //
  466. // Define the running enumeration handle.
  467. //
  468. // This variable defines the enumeration handle to assign to a logon
  469. // session. It will be incremented prior to assigning it value to
  470. // the next created logon session. Access is serialize using
  471. // the interlocked primitives.
  472. EXTERN ULONG NlpEnumerationHandle;
  473. EXTERN ULONG NlpLogonAttemptCount;
  474. NTSTATUS
  475. NlWaitForNetlogon(
  476. IN ULONG Timeout
  477. );
  478. #undef EXTERN
  479. #undef INIT
  480. #ifdef __cplusplus
  481. }
  482. #endif // __cplusplus
  483. #endif _NLP_