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.

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