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.

3013 lines
94 KiB

  1. /*++
  2. Copyright (c) 1987-1999 Microsoft Corporation
  3. Module Name:
  4. msvsam.c
  5. Abstract:
  6. Sam account validation interface.
  7. These routines are shared by the MSV authentication package and
  8. the Netlogon service.
  9. Author:
  10. Cliff Van Dyke (cliffv) 15-Jan-1992
  11. Environment:
  12. User mode only.
  13. Contains NT-specific code.
  14. Requires ANSI C extensions: slash-slash comments, long external names.
  15. Revision History:
  16. Chandana Surlu 21-Jul-96 Stolen from \\kernel\razzle3\src\security\msv1_0\msvsam.c
  17. JClark 28-Jun-2000 Added WMI Trace Logging Support
  18. Fixed bug 73583 - Password Expiration and Subauth DLLs
  19. --*/
  20. #include <global.h>
  21. #undef EXTERN
  22. #include "msp.h"
  23. #include "nlp.h"
  24. #include <stddef.h> // offsetof()
  25. #include <msaudite.h> // SE_AUDITID_xxx
  26. #include "trace.h" // WMI Tracing goo
  27. ///////////////////////////////////////////////////////////////////////
  28. // //
  29. // SubAuth package zero helper routine //
  30. // //
  31. ///////////////////////////////////////////////////////////////////////
  32. NTSTATUS
  33. Msv1_0SubAuthenticationRoutineZero(
  34. IN NETLOGON_LOGON_INFO_CLASS LogonLevel,
  35. IN PVOID LogonInformation,
  36. IN ULONG Flags,
  37. IN PUSER_ALL_INFORMATION UserAll,
  38. OUT PULONG WhichFields,
  39. OUT PULONG UserFlags,
  40. OUT PBOOLEAN Authoritative,
  41. OUT PLARGE_INTEGER LogoffTime,
  42. OUT PLARGE_INTEGER KickoffTime
  43. );
  44. BOOLEAN
  45. MsvpLm3ValidateResponse (
  46. IN PNT_OWF_PASSWORD pNtOwfPassword,
  47. IN PUNICODE_STRING pUserName,
  48. IN PUNICODE_STRING pLogonDomainName,
  49. IN UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH],
  50. IN PMSV1_0_LM3_RESPONSE pLm3Response
  51. )
  52. {
  53. UCHAR Response[MSV1_0_NTLM3_RESPONSE_LENGTH];
  54. ULONG i;
  55. // compute the response again
  56. MsvpLm3Response (
  57. pNtOwfPassword,
  58. pUserName,
  59. pLogonDomainName,
  60. ChallengeToClient,
  61. pLm3Response,
  62. Response
  63. );
  64. // compare with what we were passed
  65. i = (ULONG)RtlCompareMemory(
  66. pLm3Response->Response,
  67. Response,
  68. MSV1_0_NTLM3_RESPONSE_LENGTH);
  69. return (i == MSV1_0_NTLM3_RESPONSE_LENGTH);
  70. }
  71. BOOLEAN
  72. MsvpNtlm3ValidateResponse (
  73. IN PNT_OWF_PASSWORD pNtOwfPassword,
  74. IN PUNICODE_STRING pUserName,
  75. IN PUNICODE_STRING pLogonDomainName,
  76. IN UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH],
  77. IN PMSV1_0_NTLM3_RESPONSE pNtlm3Response,
  78. IN ULONG Ntlm3ResponseLength,
  79. OUT PUSER_SESSION_KEY UserSessionKey,
  80. OUT PLM_SESSION_KEY LmSessionKey
  81. )
  82. {
  83. UCHAR Response[MSV1_0_NTLM3_RESPONSE_LENGTH];
  84. ULONG i;
  85. LARGE_INTEGER Time;
  86. NTSTATUS Status;
  87. const LONGLONG TicksPerSecond = 10*1000*1000; // 100 ns ticks per second
  88. // check version numbers
  89. if (pNtlm3Response->RespType > 1 ||
  90. pNtlm3Response->HiRespType < 1)
  91. return FALSE;
  92. // check that the timestamp isn't too old
  93. Status = NtQuerySystemTime ( &Time );
  94. ASSERT( NT_SUCCESS(Status) );
  95. #ifndef USE_CONSTANT_CHALLENGE
  96. // make sure time hasn't expired
  97. // don't forget that client's clock could be behind ours
  98. if (Time.QuadPart > (LONGLONG)pNtlm3Response->TimeStamp) {
  99. if (Time.QuadPart - (LONGLONG)pNtlm3Response->TimeStamp >
  100. (MSV1_0_MAX_NTLM3_LIFE*TicksPerSecond))
  101. return FALSE;
  102. } else if ((LONGLONG)pNtlm3Response->TimeStamp - Time.QuadPart >
  103. (MSV1_0_MAX_NTLM3_LIFE*TicksPerSecond)) {
  104. return FALSE;
  105. }
  106. #endif
  107. // compute the response itself
  108. MsvpNtlm3Response (
  109. pNtOwfPassword,
  110. pUserName,
  111. pLogonDomainName,
  112. (Ntlm3ResponseLength-sizeof(MSV1_0_NTLM3_RESPONSE)),
  113. ChallengeToClient,
  114. pNtlm3Response,
  115. Response,
  116. UserSessionKey,
  117. LmSessionKey
  118. );
  119. // compare with what we were passed
  120. i = (ULONG)RtlCompareMemory(
  121. pNtlm3Response->Response,
  122. Response,
  123. (size_t)MSV1_0_NTLM3_RESPONSE_LENGTH);
  124. return (i == MSV1_0_NTLM3_RESPONSE_LENGTH);
  125. }
  126. BOOLEAN
  127. MsvpPasswordValidate (
  128. IN BOOLEAN UasCompatibilityRequired,
  129. IN NETLOGON_LOGON_INFO_CLASS LogonLevel,
  130. IN PVOID LogonInformation,
  131. IN PUSER_INTERNAL1_INFORMATION Passwords,
  132. OUT PULONG UserFlags,
  133. OUT PUSER_SESSION_KEY UserSessionKey,
  134. OUT PLM_SESSION_KEY LmSessionKey
  135. )
  136. /*++
  137. Routine Description:
  138. Process an interactive, network, or session logon. It calls
  139. SamIUserValidation, validates the passed in credentials, updates the logon
  140. statistics and packages the result for return to the caller.
  141. This routine is called directly from the MSV Authentication package
  142. on any system where LanMan is not installed. This routine is called
  143. from the Netlogon Service otherwise.
  144. Arguments:
  145. UasCompatibilityRequired -- True, if UAS compatibility is required.
  146. LogonLevel -- Specifies the level of information given in
  147. LogonInformation.
  148. LogonInformation -- Specifies the description for the user
  149. logging on. The LogonDomainName field should be ignored.
  150. The caller is responsible for validating this field.
  151. Passwords -- Specifies the passwords for the user account.
  152. UserFlags -- Returns flags identifying how the password was validated.
  153. Returns LOGON_NOENCRYPTION if the password wasn't encrypted
  154. Returns LOGON_USED_LM_PASSWORD if the LM password from SAM was used.
  155. UserSessionKey -- Returns the NT User session key for this network logon
  156. session.
  157. LmSessionKey -- Returns the LM compatible session key for this network
  158. logon session.
  159. Return Value:
  160. TRUE -- Password validation is successful
  161. FALSE -- Password validation failed
  162. --*/
  163. {
  164. NTSTATUS Status;
  165. PNETLOGON_LOGON_IDENTITY_INFO LogonInfo;
  166. PNETLOGON_INTERACTIVE_INFO LogonInteractiveInfo;
  167. PNETLOGON_NETWORK_INFO LogonNetworkInfo;
  168. BOOLEAN AlreadyValidated = FALSE;
  169. BOOLEAN TryLmResponse = TRUE;
  170. UNICODE_STRING NullUnicodeString;
  171. ULONG NtLmProtocolSupported;
  172. //
  173. // Initialization.
  174. //
  175. LogonInfo = (PNETLOGON_LOGON_IDENTITY_INFO) LogonInformation;
  176. *UserFlags = LOGON_NTLMV2_ENABLED;
  177. RtlZeroMemory( UserSessionKey, sizeof(*UserSessionKey) );
  178. RtlZeroMemory( LmSessionKey, sizeof(*LmSessionKey) );
  179. RtlInitUnicodeString( &NullUnicodeString, NULL );
  180. //
  181. // Ensure the OWF password is always defined
  182. //
  183. if ( !Passwords->NtPasswordPresent ){
  184. RtlCopyMemory( &Passwords->NtOwfPassword,
  185. &NlpNullNtOwfPassword,
  186. sizeof(Passwords->NtOwfPassword) );
  187. }
  188. if ( !Passwords->LmPasswordPresent ){
  189. RtlCopyMemory( &Passwords->LmOwfPassword,
  190. &NlpNullLmOwfPassword,
  191. sizeof(Passwords->LmOwfPassword) );
  192. }
  193. //
  194. // Handle interactive/service validation.
  195. //
  196. // Simply compare the OWF password passed in with the one from the
  197. // SAM database.
  198. //
  199. switch ( LogonLevel ) {
  200. case NetlogonInteractiveInformation:
  201. case NetlogonServiceInformation:
  202. ASSERT( offsetof( NETLOGON_INTERACTIVE_INFO, LmOwfPassword)
  203. == offsetof( NETLOGON_SERVICE_INFO, LmOwfPassword) );
  204. ASSERT( offsetof( NETLOGON_INTERACTIVE_INFO, NtOwfPassword)
  205. == offsetof( NETLOGON_SERVICE_INFO, NtOwfPassword) );
  206. LogonInteractiveInfo =
  207. (PNETLOGON_INTERACTIVE_INFO) LogonInformation;
  208. //
  209. // If we're in UasCompatibilityMode,
  210. // and we don't have the NT password in SAM (but do have LM password),
  211. // validate against the LM version of the password.
  212. //
  213. if ( UasCompatibilityRequired &&
  214. !Passwords->NtPasswordPresent &&
  215. Passwords->LmPasswordPresent ) {
  216. if ( RtlCompareMemory( &Passwords->LmOwfPassword,
  217. &LogonInteractiveInfo->LmOwfPassword,
  218. LM_OWF_PASSWORD_LENGTH ) !=
  219. LM_OWF_PASSWORD_LENGTH ) {
  220. return FALSE;
  221. }
  222. *UserFlags |= LOGON_USED_LM_PASSWORD;
  223. //
  224. // In all other circumstances, use the NT version of the password.
  225. // This enforces case sensitivity.
  226. //
  227. } else {
  228. if ( RtlCompareMemory( &Passwords->NtOwfPassword,
  229. &LogonInteractiveInfo->NtOwfPassword,
  230. NT_OWF_PASSWORD_LENGTH ) !=
  231. NT_OWF_PASSWORD_LENGTH ) {
  232. return FALSE;
  233. }
  234. }
  235. break;
  236. //
  237. // Handle network logon validation.
  238. //
  239. case NetlogonNetworkInformation:
  240. //
  241. // First, assume the passed password information is a challenge
  242. // response.
  243. //
  244. LogonNetworkInfo =
  245. (PNETLOGON_NETWORK_INFO) LogonInformation;
  246. // If the NT response is an NTLM3 response, do NTLM3 or NTLM3 with LM OWF
  247. // if the length is > NT_RESPONSE_LENGTH, then it's an NTLM3 response
  248. if (LogonNetworkInfo->NtChallengeResponse.Length > NT_RESPONSE_LENGTH) {
  249. AlreadyValidated = MsvpNtlm3ValidateResponse (
  250. &Passwords->NtOwfPassword,
  251. &LogonNetworkInfo->Identity.UserName,
  252. &LogonNetworkInfo->Identity.LogonDomainName,
  253. (PUCHAR)&LogonNetworkInfo->LmChallenge,
  254. (PMSV1_0_NTLM3_RESPONSE) LogonNetworkInfo->NtChallengeResponse.Buffer,
  255. LogonNetworkInfo->NtChallengeResponse.Length,
  256. UserSessionKey,
  257. LmSessionKey
  258. );
  259. //
  260. // because a Subauth may have been used, we will only return failure
  261. // here if we know the request was NTLMv2.
  262. //
  263. if( AlreadyValidated ||
  264. (LogonNetworkInfo->Identity.ParameterControl & MSV1_0_USE_CLIENT_CHALLENGE) ) {
  265. return AlreadyValidated;
  266. }
  267. }
  268. //
  269. // check the LM3 response based on NT OWF hash next
  270. // this will be recieved from Win9x server with NTLMv2 client
  271. //
  272. if (LogonNetworkInfo->LmChallengeResponse.Length == NT_RESPONSE_LENGTH) {
  273. AlreadyValidated = MsvpLm3ValidateResponse (
  274. &Passwords->NtOwfPassword,
  275. &LogonNetworkInfo->Identity.UserName,
  276. &LogonNetworkInfo->Identity.LogonDomainName,
  277. (PUCHAR)&LogonNetworkInfo->LmChallenge,
  278. (PMSV1_0_LM3_RESPONSE) LogonNetworkInfo->LmChallengeResponse.Buffer
  279. );
  280. if (AlreadyValidated)
  281. return TRUE;
  282. }
  283. NtLmProtocolSupported = NtLmGlobalLmProtocolSupported;
  284. // if we're requiring all clients (Win9x and NT) to have been upgraded, fail out now
  285. //if (NtLmProtocolSupported >= RefuseNtlm)
  286. //return FALSE;
  287. // if that fails, check the NTLM response if there is one of the
  288. // appropriate size in either NT response or LM response
  289. if (!AlreadyValidated &&
  290. (NtLmProtocolSupported < RefuseNtlm) &&
  291. (Passwords->NtPasswordPresent || (!Passwords->NtPasswordPresent && !Passwords->LmPasswordPresent)) &&
  292. (LogonNetworkInfo->NtChallengeResponse.Length == NT_RESPONSE_LENGTH ||
  293. LogonNetworkInfo->LmChallengeResponse.Length == NT_RESPONSE_LENGTH)) {
  294. NT_RESPONSE NtResponse;
  295. //
  296. // NT response is present and hash exists, don't try the LM respnose.
  297. //
  298. if( LogonNetworkInfo->NtChallengeResponse.Length == NT_RESPONSE_LENGTH )
  299. {
  300. TryLmResponse = FALSE;
  301. }
  302. //
  303. // Compute what the response should be.
  304. //
  305. Status = RtlCalculateNtResponse(
  306. &LogonNetworkInfo->LmChallenge,
  307. &Passwords->NtOwfPassword,
  308. &NtResponse );
  309. if ( NT_SUCCESS(Status) ) {
  310. //
  311. // If the responses match, the passwords are valid.
  312. // Try the NT response first, then the LM response
  313. //
  314. if ( RtlCompareMemory(
  315. LogonNetworkInfo->
  316. NtChallengeResponse.Buffer,
  317. &NtResponse,
  318. LogonNetworkInfo->NtChallengeResponse.Length ) ==
  319. NT_RESPONSE_LENGTH ) {
  320. AlreadyValidated = TRUE;
  321. } else if ( RtlCompareMemory(
  322. LogonNetworkInfo->
  323. LmChallengeResponse.Buffer,
  324. &NtResponse,
  325. LogonNetworkInfo->LmChallengeResponse.Length ) ==
  326. NT_RESPONSE_LENGTH ) {
  327. AlreadyValidated = TRUE;
  328. }
  329. }
  330. }
  331. // if we're requiring all Win9x clients to have been upgraded, fail out now
  332. //if (!AlreadyValidated && NtLmProtocolSupported >= RefuseLm)
  333. // return FALSE;
  334. //
  335. // if the LM response is the right size
  336. // validate against the LM version of the response
  337. // this applies also when both NTOWF and LMOWF are not present in SAM.
  338. //
  339. if (!AlreadyValidated &&
  340. ( TryLmResponse ) &&
  341. ( NtLmProtocolSupported < RefuseLm ) &&
  342. ( LogonNetworkInfo->LmChallengeResponse.Length == LM_RESPONSE_LENGTH ) &&
  343. ( (Passwords->LmPasswordPresent) || (!Passwords->LmPasswordPresent && !Passwords->NtPasswordPresent) )
  344. ) {
  345. LM_RESPONSE LmResponse;
  346. //
  347. // Compute what the response should be.
  348. //
  349. Status = RtlCalculateLmResponse(
  350. &LogonNetworkInfo->LmChallenge,
  351. &Passwords->LmOwfPassword,
  352. &LmResponse );
  353. if ( NT_SUCCESS(Status) ) {
  354. //
  355. // If the responses match, the passwords are valid.
  356. //
  357. if ( RtlCompareMemory(
  358. LogonNetworkInfo->
  359. LmChallengeResponse.Buffer,
  360. &LmResponse,
  361. LM_RESPONSE_LENGTH ) ==
  362. LM_RESPONSE_LENGTH ) {
  363. AlreadyValidated = TRUE;
  364. *UserFlags |= LOGON_USED_LM_PASSWORD;
  365. }
  366. }
  367. }
  368. //
  369. // If we haven't already validated this user,
  370. // Validate a Cleartext password on a Network logon request.
  371. //
  372. if ( !AlreadyValidated ) {
  373. // If Cleartext passwords are not allowed,
  374. // indicate the password doesn't match.
  375. //
  376. if((LogonInfo->ParameterControl & CLEARTEXT_PASSWORD_ALLOWED) == 0){
  377. return FALSE;
  378. }
  379. //
  380. // Compute the OWF password for the specified Cleartext password and
  381. // compare that to the OWF password retrieved from SAM.
  382. //
  383. //
  384. // If we're in UasCompatibilityMode,
  385. // and we don't have the NT password in SAM or
  386. // we don't have the NT password supplied by the caller.
  387. // validate against the LM version of the password.
  388. //
  389. // if neither password are present, we validate against
  390. // the empty computed LMOWF.
  391. //
  392. if ( UasCompatibilityRequired &&
  393. (NtLmProtocolSupported < RefuseLm) &&
  394. ((Passwords->LmPasswordPresent) || (!Passwords->LmPasswordPresent && !Passwords->NtPasswordPresent)) &&
  395. (!Passwords->NtPasswordPresent ||
  396. LogonNetworkInfo->NtChallengeResponse.Length == 0 ) ) {
  397. LM_OWF_PASSWORD LmOwfPassword;
  398. CHAR LmPassword[LM20_PWLEN+1];
  399. USHORT i;
  400. //
  401. // Compute the LmOwfPassword for the cleartext password passed in.
  402. // (Enforce length restrictions on LanMan compatible passwords.)
  403. //
  404. if ( LogonNetworkInfo->LmChallengeResponse.Length >
  405. sizeof(LmPassword) ) {
  406. return FALSE;
  407. }
  408. RtlZeroMemory( &LmPassword, sizeof(LmPassword) );
  409. for (i = 0; i < LogonNetworkInfo->LmChallengeResponse.Length; i++) {
  410. LmPassword[i] =
  411. RtlUpperChar(LogonNetworkInfo->LmChallengeResponse.Buffer[i]);
  412. }
  413. (VOID) RtlCalculateLmOwfPassword( LmPassword, &LmOwfPassword );
  414. if ( RtlCompareMemory( &Passwords->LmOwfPassword,
  415. &LmOwfPassword,
  416. LM_OWF_PASSWORD_LENGTH ) !=
  417. LM_OWF_PASSWORD_LENGTH ) {
  418. //
  419. // Try the case preserved clear text password, too.
  420. // (I know of no client that does this,
  421. // but it is compatible with the LM 2.x server.)
  422. //
  423. RtlZeroMemory( &LmPassword, sizeof(LmPassword) );
  424. RtlCopyMemory(
  425. &LmPassword,
  426. LogonNetworkInfo->LmChallengeResponse.Buffer,
  427. LogonNetworkInfo->LmChallengeResponse.Length);
  428. (VOID) RtlCalculateLmOwfPassword( LmPassword,
  429. &LmOwfPassword );
  430. if ( RtlCompareMemory( &Passwords->LmOwfPassword,
  431. &LmOwfPassword,
  432. LM_OWF_PASSWORD_LENGTH ) !=
  433. LM_OWF_PASSWORD_LENGTH ) {
  434. return FALSE;
  435. }
  436. }
  437. *UserFlags |= LOGON_USED_LM_PASSWORD;
  438. //
  439. // In all other circumstances, use the NT version of the password.
  440. // This enforces case sensitivity.
  441. //
  442. } else {
  443. NT_OWF_PASSWORD NtOwfPassword;
  444. //
  445. // Compute the NtOwfPassword for the cleartext password passed in.
  446. //
  447. Status = RtlCalculateNtOwfPassword(
  448. (PUNICODE_STRING)
  449. &LogonNetworkInfo->NtChallengeResponse,
  450. &NtOwfPassword );
  451. if ( RtlCompareMemory( &Passwords->NtOwfPassword,
  452. &NtOwfPassword,
  453. NT_OWF_PASSWORD_LENGTH ) !=
  454. NT_OWF_PASSWORD_LENGTH ) {
  455. return FALSE;
  456. }
  457. }
  458. *UserFlags |= LOGON_NOENCRYPTION;
  459. }
  460. //
  461. // ASSERT: the network logon has been authenticated
  462. //
  463. // Compute the session keys.
  464. //
  465. // If the client negotiated a non-NT protocol,
  466. // use the lanman session key as the UserSessionKey.
  467. //
  468. if ( LogonNetworkInfo->NtChallengeResponse.Length == 0 ) {
  469. ASSERT( sizeof(*UserSessionKey) >= sizeof(*LmSessionKey) );
  470. RtlCopyMemory( UserSessionKey,
  471. &Passwords->LmOwfPassword,
  472. sizeof(*LmSessionKey) );
  473. } else {
  474. //
  475. // Return the NT UserSessionKey unless this is an account
  476. // that doesn't have the NT version of the password.
  477. // (A null password counts as a password).
  478. //
  479. if ( Passwords->NtPasswordPresent || !Passwords->LmPasswordPresent){
  480. Status = RtlCalculateUserSessionKeyNt(
  481. (PNT_RESPONSE) NULL, // Argument not used
  482. &Passwords->NtOwfPassword,
  483. UserSessionKey );
  484. ASSERT( NT_SUCCESS(Status) );
  485. }
  486. }
  487. //
  488. // Return the LM SessionKey unless this is an account
  489. // that doesn't have the LM version of the password.
  490. // (A null password counts as a password).
  491. //
  492. if ( Passwords->LmPasswordPresent || !Passwords->NtPasswordPresent ) {
  493. RtlCopyMemory( LmSessionKey,
  494. &Passwords->LmOwfPassword,
  495. sizeof(*LmSessionKey) );
  496. }
  497. break;
  498. //
  499. // Any other LogonLevel is an internal error.
  500. //
  501. default:
  502. return FALSE;
  503. }
  504. return TRUE;
  505. }
  506. BOOLEAN
  507. MsvpEqualSidPrefix(
  508. IN PSID DomainSid,
  509. IN PSID GroupSid
  510. )
  511. /*++
  512. Routine Description:
  513. This routine checks to see if the specified group sid came from the
  514. specified domain by verifying that the domain portion of the group sid
  515. is equal to the domain sid.
  516. Arguments:
  517. DomainSid - Sid of the domain for comparison.
  518. GroupSid - Sid of the group for comparison
  519. Returns:
  520. TRUE - The group sid came from the specified domain.
  521. FALSE - The group sid did not come from the specified domain.
  522. --*/
  523. {
  524. PISID LocalGroupSid = (PISID) GroupSid;
  525. PISID LocalDomainSid = (PISID) DomainSid;
  526. if ((LocalGroupSid->SubAuthorityCount == LocalDomainSid->SubAuthorityCount + 1) &&
  527. RtlEqualMemory(
  528. RtlIdentifierAuthoritySid(LocalDomainSid),
  529. RtlIdentifierAuthoritySid(LocalGroupSid),
  530. RtlLengthRequiredSid(
  531. LocalDomainSid->SubAuthorityCount
  532. ) - FIELD_OFFSET(SID,IdentifierAuthority)
  533. )) {
  534. return(TRUE);
  535. }
  536. return(FALSE);
  537. }
  538. NTSTATUS
  539. MsvpFilterGroupMembership(
  540. IN PSID_AND_ATTRIBUTES_LIST CompleteMembership,
  541. IN PSID LogonDomainId,
  542. OUT PSAMPR_GET_GROUPS_BUFFER LocalMembership,
  543. OUT PSID_AND_ATTRIBUTES_LIST GlobalMembership,
  544. OUT PULONG GlobalMembershipSize
  545. )
  546. /*++
  547. Routine Description:
  548. This routine separates the complete transitive group membership into
  549. portions from this domain and portions from others.
  550. Arguments:
  551. CompleteMembership - The complete transitive membership.
  552. LogonDomainId - SID of the logon domain, used for compressing group
  553. membership.
  554. LocalMembership - Receives a list of rids corresponding to groups in this
  555. domain. The list should be freed with MIDL_user_free.
  556. GlobalMembership - Recevies a list of sids corresponding to groups in
  557. other domain. The list, but not the sids, should be free with
  558. MIDL_user_free.
  559. GlobalMembershipSize - Size, in bytes, of the sids in the global membership
  560. and the size of the SID_AND_ATTRIBUTES structures.
  561. Returns:
  562. STATUS_SUCCESS on success
  563. STATUS_INSUFFICIENT_RESOURCES on for memory allocation failures.
  564. --*/
  565. {
  566. NTSTATUS Status = STATUS_SUCCESS;
  567. ULONG LocalCount = 0;
  568. ULONG GlobalCount = 0;
  569. ULONG GlobalSize = 0;
  570. ULONG Index;
  571. LocalMembership->MembershipCount = 0;
  572. LocalMembership->Groups = NULL;
  573. GlobalMembership->Count = 0;
  574. GlobalMembership->SidAndAttributes = NULL;
  575. //
  576. // Define a flag so we don't have to do the comparison twice.
  577. //
  578. #define MSVP_LOCAL_GROUP_ATTR 0x20000000
  579. for (Index = 0; Index < CompleteMembership->Count ; Index++ ) {
  580. ASSERT((CompleteMembership->SidAndAttributes[Index].Attributes & MSVP_LOCAL_GROUP_ATTR) == 0);
  581. if (MsvpEqualSidPrefix(
  582. LogonDomainId,
  583. CompleteMembership->SidAndAttributes[Index].Sid
  584. )) {
  585. CompleteMembership->SidAndAttributes[Index].Attributes |= MSVP_LOCAL_GROUP_ATTR;
  586. LocalCount++;
  587. } else {
  588. GlobalCount++;
  589. GlobalSize += sizeof(SID_AND_ATTRIBUTES) + RtlLengthSid(CompleteMembership->SidAndAttributes[Index].Sid);
  590. }
  591. }
  592. //
  593. // Allocate the arrays for the output
  594. //
  595. if (LocalCount != 0)
  596. {
  597. LocalMembership->Groups = (PGROUP_MEMBERSHIP) I_NtLmAllocate(LocalCount * sizeof(GROUP_MEMBERSHIP));
  598. if (LocalMembership->Groups == NULL) {
  599. Status = STATUS_INSUFFICIENT_RESOURCES;
  600. goto Cleanup;
  601. }
  602. LocalMembership->MembershipCount = LocalCount;
  603. }
  604. if (GlobalCount != 0)
  605. {
  606. GlobalMembership->SidAndAttributes = (PSID_AND_ATTRIBUTES) I_NtLmAllocate(GlobalCount * sizeof(SID_AND_ATTRIBUTES));
  607. if (GlobalMembership->SidAndAttributes == NULL) {
  608. Status = STATUS_INSUFFICIENT_RESOURCES;
  609. goto Cleanup;
  610. }
  611. GlobalMembership->Count = GlobalCount;
  612. }
  613. //
  614. // Loop through again copy the rid or sid into the respective array
  615. //
  616. LocalCount = 0;
  617. GlobalCount = 0;
  618. for (Index = 0; Index < CompleteMembership->Count ; Index++ ) {
  619. if ((CompleteMembership->SidAndAttributes[Index].Attributes & MSVP_LOCAL_GROUP_ATTR) != 0) {
  620. LocalMembership->Groups[LocalCount].Attributes = CompleteMembership->SidAndAttributes[Index].Attributes & ~MSVP_LOCAL_GROUP_ATTR;
  621. LocalMembership->Groups[LocalCount].RelativeId =
  622. *RtlSubAuthoritySid(
  623. CompleteMembership->SidAndAttributes[Index].Sid,
  624. *RtlSubAuthorityCountSid(
  625. CompleteMembership->SidAndAttributes[Index].Sid
  626. ) - 1
  627. );
  628. LocalCount++;
  629. } else {
  630. GlobalMembership->SidAndAttributes[GlobalCount] = CompleteMembership->SidAndAttributes[Index];
  631. GlobalCount++;
  632. }
  633. }
  634. *GlobalMembershipSize = GlobalSize;
  635. Cleanup:
  636. if (!NT_SUCCESS(Status)) {
  637. if (LocalMembership->Groups != NULL)
  638. {
  639. I_NtLmFree(LocalMembership->Groups);
  640. LocalMembership->Groups = NULL;
  641. }
  642. if (GlobalMembership->SidAndAttributes != NULL)
  643. {
  644. I_NtLmFree(GlobalMembership->SidAndAttributes);
  645. GlobalMembership->SidAndAttributes = NULL;
  646. }
  647. }
  648. return(Status);
  649. }
  650. NTSTATUS
  651. MsvpSamValidate (
  652. IN SAMPR_HANDLE DomainHandle,
  653. IN BOOLEAN UasCompatibilityRequired,
  654. IN NETLOGON_SECURE_CHANNEL_TYPE SecureChannelType,
  655. IN PUNICODE_STRING LogonServer,
  656. IN PUNICODE_STRING LogonDomainName,
  657. IN PSID LogonDomainId,
  658. IN NETLOGON_LOGON_INFO_CLASS LogonLevel,
  659. IN PVOID LogonInformation,
  660. IN ULONG GuestRelativeId,
  661. IN NETLOGON_VALIDATION_INFO_CLASS ValidationLevel,
  662. OUT PVOID * ValidationInformation,
  663. OUT PBOOLEAN Authoritative,
  664. OUT PBOOLEAN BadPasswordCountZeroed
  665. )
  666. /*++
  667. Routine Description:
  668. Process an interactive, network, or session logon. It calls
  669. SamIUserValidation, validates the passed in credentials, updates the logon
  670. statistics and packages the result for return to the caller.
  671. This routine is called by MsvSamValidate.
  672. Arguments:
  673. DomainHandle -- Specifies a handle to the SamDomain to use to
  674. validate the request.
  675. UasCompatibilityRequired -- TRUE iff UasCompatibilityMode is on.
  676. SecureChannelType -- The secure channel type this request was made on.
  677. When netlogon on the BDC is called, the user is actually
  678. already authenticated (via PDC) through a prior "net use"
  679. from the win9x client. Netlogon merely returns the validation
  680. info to the win9x caller. To do that Netlogon calls
  681. MsvSamValidate passing NullSecureChannel as the 3rd parameter
  682. indicating to skip the password check.
  683. LogonServer -- Specifies the server name of the caller.
  684. LogonDomainName -- Specifies the domain of the caller.
  685. LogonDomainId -- Specifies the DomainId of the domain of the caller.
  686. LogonLevel -- Specifies the level of information given in
  687. LogonInformation.
  688. LogonInformation -- Specifies the description for the user
  689. logging on. The LogonDomainName field should be ignored.
  690. The caller is responsible for validating this field.
  691. GuestRelativeId - If non-zero, specifies the relative ID of the account
  692. to validate against.
  693. ValidationLevel -- Specifies the level of information returned in
  694. ValidationInformation. Must be NetlogonValidationSamInfo,
  695. NetlogonValidationSamInfo2 or NetlogonValidationSamInfo4.
  696. ValidationInformation -- Returns the requested validation
  697. information. This buffer must be freed user MIDL_user_free.
  698. This information is only return on STATUS_SUCCESS.
  699. Authoritative -- Returns whether the status returned is an
  700. authoritative status which should be returned to the original
  701. caller. If not, this logon request may be tried again on another
  702. domain controller. This parameter is returned regardless of the
  703. status code.
  704. BadPasswordCountZeroed - Returns TRUE iff we zeroed the BadPasswordCount
  705. field of this user.
  706. Return Value:
  707. STATUS_SUCCESS: if there was no error.
  708. STATUS_INVALID_INFO_CLASS: LogonLevel or ValidationLevel are invalid.
  709. STATUS_NO_SUCH_USER: The specified user has no account.
  710. STATUS_WRONG_PASSWORD: The password was invalid.
  711. Other return codes from SamIUserValidation
  712. --*/
  713. {
  714. NTSTATUS Status;
  715. NTSTATUS SubAuthExStatus = STATUS_SUCCESS;
  716. PNETLOGON_LOGON_IDENTITY_INFO LogonInfo;
  717. SAMPR_HANDLE UserHandle = NULL;
  718. ULONG RelativeId = GuestRelativeId;
  719. ULONG SamFlags;
  720. PSID LocalSidUser = NULL;
  721. PSAMPR_USER_INFO_BUFFER UserAllInfo = NULL;
  722. PSAMPR_USER_ALL_INFORMATION UserAll = NULL;
  723. SAMPR_GET_GROUPS_BUFFER GroupsBuffer;
  724. ULONG UserFlags = 0;
  725. USER_SESSION_KEY UserSessionKey;
  726. LM_SESSION_KEY LmSessionKey;
  727. ULONG WhichFields = 0;
  728. UNICODE_STRING LocalUserName;
  729. UNICODE_STRING LocalWorkstation;
  730. ULONG UserAccountControl;
  731. LARGE_INTEGER LogonTime;
  732. LARGE_INTEGER LogoffTime;
  733. LARGE_INTEGER KickoffTime;
  734. UNICODE_STRING Upn;
  735. LARGE_INTEGER AccountExpires;
  736. LARGE_INTEGER PasswordMustChange;
  737. LARGE_INTEGER PasswordLastSet;
  738. PNETLOGON_VALIDATION_SAM_INFO4 ValidationSam = NULL;
  739. ULONG ValidationSamSize;
  740. PUCHAR Where;
  741. ULONG Index;
  742. SAMPR_RETURNED_USTRING_ARRAY NameArray;
  743. SAMPR_ULONG_ARRAY UseArray;
  744. SID_AND_ATTRIBUTES_LIST GroupMembership;
  745. SID_AND_ATTRIBUTES_LIST GlobalGroupMembership;
  746. ULONG GlobalMembershipSize = 0;
  747. MSV1_0_VALIDATION_INFO SubAuthValidationInformation;
  748. BOOLEAN fSubAuthEx = FALSE;
  749. BOOLEAN fMachineAccount;
  750. ULONG ActionsPerformed = 0;
  751. LogonInfo = (PNETLOGON_LOGON_IDENTITY_INFO) LogonInformation;
  752. //
  753. // check if caller requested that logon only target specified domain.
  754. //
  755. if( LogonInfo->ParameterControl & MSV1_0_TRY_SPECIFIED_DOMAIN_ONLY &&
  756. LogonInfo->LogonDomainName.Length ) {
  757. //
  758. // common case is a match for LogonDomainName, so avoid taking locks
  759. // until mis-match occurs.
  760. //
  761. if(!RtlEqualDomainName( &LogonInfo->LogonDomainName, LogonDomainName )) {
  762. WCHAR LocalTarget[ DNS_MAX_NAME_LENGTH + 1 ];
  763. WCHAR SpecifiedTarget[ DNS_MAX_NAME_LENGTH + 1 ];
  764. ULONG cchLocalTarget = 0;
  765. ULONG cchSpecifiedTarget = 0;
  766. //
  767. // pickup the local target name, based on whether this computer is
  768. // a domain controller.
  769. //
  770. RtlAcquireResourceShared(&NtLmGlobalCritSect, TRUE);
  771. if( NlpWorkstation ) {
  772. if( (NtLmGlobalUnicodeDnsComputerNameString.Length + sizeof(WCHAR)) <=
  773. sizeof( LocalTarget ) ) {
  774. RtlCopyMemory(
  775. LocalTarget,
  776. NtLmGlobalUnicodeDnsComputerName,
  777. NtLmGlobalUnicodeDnsComputerNameString.Length
  778. );
  779. cchLocalTarget = (NtLmGlobalUnicodeDnsComputerNameString.Length) /
  780. sizeof(WCHAR);
  781. }
  782. } else {
  783. if( (NtLmGlobalUnicodeDnsDomainNameString.Length + sizeof(WCHAR)) <=
  784. sizeof( LocalTarget ) ) {
  785. RtlCopyMemory(
  786. LocalTarget,
  787. NtLmGlobalUnicodeDnsDomainName,
  788. NtLmGlobalUnicodeDnsDomainNameString.Length
  789. );
  790. cchLocalTarget = (NtLmGlobalUnicodeDnsDomainNameString.Length) /
  791. sizeof(WCHAR);
  792. }
  793. }
  794. RtlReleaseResource(&NtLmGlobalCritSect);
  795. //
  796. // pull out target name.
  797. //
  798. if( (LogonInfo->LogonDomainName.Length + sizeof(WCHAR)) <= sizeof( SpecifiedTarget ) ) {
  799. cchSpecifiedTarget = (LogonInfo->LogonDomainName.Length) / sizeof(WCHAR);
  800. RtlCopyMemory(
  801. SpecifiedTarget,
  802. LogonInfo->LogonDomainName.Buffer,
  803. LogonInfo->LogonDomainName.Length
  804. );
  805. }
  806. if ( cchLocalTarget && cchSpecifiedTarget ) {
  807. LocalTarget[ cchLocalTarget ] = L'\0';
  808. SpecifiedTarget[ cchSpecifiedTarget ] = L'\0';
  809. if(!DnsNameCompare_W( LocalTarget, SpecifiedTarget ) ) {
  810. *Authoritative = FALSE;
  811. return STATUS_NO_SUCH_USER;
  812. }
  813. }
  814. }
  815. }
  816. //
  817. // Initialization.
  818. //
  819. RtlZeroMemory(
  820. &SubAuthValidationInformation,
  821. sizeof(MSV1_0_VALIDATION_INFO));
  822. SubAuthValidationInformation.Authoritative = TRUE;
  823. SubAuthValidationInformation.WhichFields = 0;
  824. NameArray.Count = 0;
  825. NameArray.Element = NULL;
  826. UseArray.Count = 0;
  827. UseArray.Element = NULL;
  828. *BadPasswordCountZeroed = FALSE;
  829. GroupMembership.Count = 0;
  830. GroupMembership.SidAndAttributes = NULL;
  831. GlobalGroupMembership.Count = 0;
  832. GlobalGroupMembership.SidAndAttributes = NULL;
  833. GroupsBuffer.MembershipCount = 0;
  834. GroupsBuffer.Groups = NULL;
  835. RtlInitUnicodeString( &Upn, NULL );
  836. (VOID) NtQuerySystemTime( &LogonTime );
  837. //
  838. // Determine what account types are valid.
  839. //
  840. // Normal user accounts are always allowed.
  841. //
  842. UserAccountControl = USER_NORMAL_ACCOUNT;
  843. *Authoritative = TRUE;
  844. switch ( LogonLevel ) {
  845. case NetlogonInteractiveInformation:
  846. case NetlogonServiceInformation:
  847. break;
  848. case NetlogonNetworkInformation:
  849. //
  850. // Local user (Temp Duplicate) accounts are only used on the machine
  851. // being directly logged onto.
  852. // (Nor are interactive or service logons allowed to them.)
  853. //
  854. if ( SecureChannelType == MsvApSecureChannel ) {
  855. UserAccountControl |= USER_TEMP_DUPLICATE_ACCOUNT;
  856. }
  857. //
  858. // Machine accounts can be accessed on network connections.
  859. //
  860. UserAccountControl |= USER_INTERDOMAIN_TRUST_ACCOUNT |
  861. USER_WORKSTATION_TRUST_ACCOUNT |
  862. USER_SERVER_TRUST_ACCOUNT;
  863. break;
  864. default:
  865. *Authoritative = TRUE;
  866. return STATUS_INVALID_INFO_CLASS;
  867. }
  868. //
  869. // Check the ValidationLevel
  870. //
  871. switch (ValidationLevel) {
  872. case NetlogonValidationSamInfo:
  873. case NetlogonValidationSamInfo2:
  874. case NetlogonValidationSamInfo4:
  875. break;
  876. default:
  877. *Authoritative = TRUE;
  878. return STATUS_INVALID_INFO_CLASS;
  879. }
  880. //
  881. // Convert the user name to a RelativeId.
  882. //
  883. if ( RelativeId != 0 ) {
  884. UCHAR cDomainSubAuthorities;
  885. UCHAR SubAuthIndex;
  886. ULONG cbLocalSidUser;
  887. PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority;
  888. //
  889. // build a Sid out of the DomainId and the supplied Rid.
  890. //
  891. cDomainSubAuthorities = *RtlSubAuthorityCountSid( LogonDomainId );
  892. pIdentifierAuthority = RtlIdentifierAuthoritySid( LogonDomainId );
  893. cbLocalSidUser = RtlLengthRequiredSid( (ULONG)(cDomainSubAuthorities + 1) );
  894. LocalSidUser = I_NtLmAllocate( cbLocalSidUser );
  895. if (LocalSidUser == NULL) {
  896. *Authoritative = FALSE;
  897. Status = STATUS_INSUFFICIENT_RESOURCES;
  898. goto Cleanup;
  899. }
  900. Status = RtlInitializeSid(LocalSidUser, pIdentifierAuthority, (UCHAR)((DWORD)cDomainSubAuthorities+1));
  901. if(!NT_SUCCESS(Status)) {
  902. *Authoritative = FALSE;
  903. goto Cleanup;
  904. }
  905. //
  906. // loop copying subauthorities.
  907. //
  908. for( SubAuthIndex = 0 ; SubAuthIndex < cDomainSubAuthorities ; SubAuthIndex++ )
  909. {
  910. *RtlSubAuthoritySid( LocalSidUser, (ULONG)SubAuthIndex ) =
  911. *RtlSubAuthoritySid( LogonDomainId, (ULONG)SubAuthIndex );
  912. }
  913. //
  914. // append relative ID.
  915. //
  916. *RtlSubAuthoritySid(LocalSidUser, cDomainSubAuthorities) = RelativeId;
  917. LocalUserName.Buffer = LocalSidUser;
  918. LocalUserName.Length = (USHORT)cbLocalSidUser;
  919. LocalUserName.MaximumLength = (USHORT)cbLocalSidUser;
  920. SamFlags = SAM_OPEN_BY_SID;
  921. } else {
  922. LocalUserName = LogonInfo->UserName;
  923. SamFlags = 0;
  924. }
  925. //
  926. // if this is a domain controller, and, we get a logon request that
  927. // looks like a possible UPN, set the flag...
  928. //
  929. if( (SamFlags == 0) &&
  930. (LogonInfo->LogonDomainName.Buffer == NULL) &&
  931. !NlpWorkstation
  932. )
  933. {
  934. SamFlags |= SAM_OPEN_BY_UPN_OR_ACCOUNTNAME;
  935. }
  936. //
  937. // Open the user account.
  938. //
  939. if (( LogonInfo->ParameterControl & MSV1_0_SUBAUTHENTICATION_DLL ) ||
  940. ( LogonInfo->ParameterControl & MSV1_0_SUBAUTHENTICATION_DLL_EX ) ||
  941. NlpSubAuthZeroExists ) {
  942. //
  943. // Fetch all attributes in the presence of a subauthentication DLL
  944. //
  945. Status = I_SamIGetUserLogonInformation(
  946. DomainHandle,
  947. SamFlags,
  948. &LocalUserName,
  949. &UserAllInfo,
  950. &GroupMembership,
  951. &UserHandle
  952. );
  953. } else {
  954. //
  955. // Performance optimization:
  956. // Fetch only select attributes in the absence of a subauthentication DLL
  957. //
  958. Status = I_SamIGetUserLogonInformationEx(
  959. DomainHandle,
  960. SamFlags,
  961. &LocalUserName,
  962. USER_ALL_ACCOUNTEXPIRES |
  963. USER_ALL_BADPASSWORDCOUNT |
  964. USER_ALL_FULLNAME |
  965. USER_ALL_HOMEDIRECTORY |
  966. USER_ALL_HOMEDIRECTORYDRIVE |
  967. USER_ALL_LASTLOGON |
  968. USER_ALL_LMPASSWORDPRESENT |
  969. USER_ALL_LOGONCOUNT |
  970. USER_ALL_LOGONHOURS |
  971. USER_ALL_NTPASSWORDPRESENT |
  972. USER_ALL_OWFPASSWORD |
  973. USER_ALL_PARAMETERS |
  974. USER_ALL_PASSWORDCANCHANGE |
  975. USER_ALL_PASSWORDLASTSET |
  976. USER_ALL_PASSWORDMUSTCHANGE |
  977. USER_ALL_PRIMARYGROUPID |
  978. USER_ALL_PROFILEPATH |
  979. USER_ALL_SCRIPTPATH |
  980. USER_ALL_USERACCOUNTCONTROL |
  981. USER_ALL_USERID |
  982. USER_ALL_USERNAME |
  983. USER_ALL_WORKSTATIONS,
  984. &UserAllInfo,
  985. &GroupMembership,
  986. &UserHandle
  987. );
  988. }
  989. if ( !NT_SUCCESS(Status) ) {
  990. UserHandle = NULL;
  991. *Authoritative = FALSE;
  992. Status = STATUS_NO_SUCH_USER;
  993. goto Cleanup;
  994. }
  995. if( !NlpWorkstation )
  996. {
  997. BOOLEAN UpnDefaulted;
  998. //
  999. // get the UPN. Ignore the failure, as, there is existing logic
  1000. // for dealing with the lack of Upn.
  1001. //
  1002. I_SamIUPNFromUserHandle(
  1003. UserHandle,
  1004. &UpnDefaulted,
  1005. &Upn
  1006. );
  1007. }
  1008. UserAll = &UserAllInfo->All;
  1009. if ( RelativeId != 0 )
  1010. {
  1011. //
  1012. // reset LocalUserName to be an actual username rather than a Sid
  1013. // for Guest logon. This allows proper audit later on.
  1014. //
  1015. RtlCopyMemory( &LocalUserName, &UserAll->UserName, sizeof(LocalUserName) );
  1016. }
  1017. //
  1018. // pickup RelativeId from looked up information.
  1019. //
  1020. RelativeId = UserAll->UserId;
  1021. //
  1022. // If the account type isn't allowed,
  1023. // Treat this as though the User Account doesn't exist.
  1024. //
  1025. // SubAuthentication packages can be more specific than this test but
  1026. // they can't become less restrictive.
  1027. //
  1028. if ( (UserAccountControl & UserAll->UserAccountControl) == 0 ) {
  1029. *Authoritative = FALSE;
  1030. Status = STATUS_NO_SUCH_USER;
  1031. goto Cleanup;
  1032. }
  1033. //
  1034. // determine if machine account, if so, certain failures are treated
  1035. // as Authoritative, to prevent fallback to guest and returning incorrect
  1036. // error codes.
  1037. //
  1038. if ( (UserAll->UserAccountControl & USER_MACHINE_ACCOUNT_MASK) != 0 ) {
  1039. fMachineAccount = TRUE;
  1040. } else {
  1041. fMachineAccount = FALSE;
  1042. }
  1043. //
  1044. // If there is a SubAuthentication DLL,
  1045. // call it to do all the authentication work.
  1046. //
  1047. if ( (LogonInfo->ParameterControl & MSV1_0_SUBAUTHENTICATION_DLL) &&
  1048. (!(LogonInfo->ParameterControl & MSV1_0_SUBAUTHENTICATION_DLL_EX))) {
  1049. ULONG LocalUserFlags = 0;
  1050. ULONG Flags = 0;
  1051. //
  1052. // Ensure the account isn't locked out.
  1053. // We did this regardless before NT 5.0. Now, we do it when either
  1054. // No SubAuth package is specified or
  1055. // New SubAuth package asks us to do account lockout test
  1056. // But, for those who call with old SubAuth packages, they will expect
  1057. // us to do the dirty work.
  1058. //
  1059. if ( (UserAll->UserAccountControl & USER_ACCOUNT_AUTO_LOCKED) &&
  1060. (SecureChannelType != NullSecureChannel) )
  1061. {
  1062. BOOL LockOut = TRUE;
  1063. if (RelativeId == DOMAIN_USER_RID_ADMIN) {
  1064. if(LogonLevel != NetlogonInteractiveInformation) {
  1065. PDOMAIN_PASSWORD_INFORMATION DomainPasswordInfo = NULL;
  1066. Status = I_SamrQueryInformationDomain(
  1067. NlpSamDomainHandle,
  1068. DomainPasswordInformation,
  1069. (PSAMPR_DOMAIN_INFO_BUFFER *)&DomainPasswordInfo );
  1070. if (!NT_SUCCESS(Status)) {
  1071. Status = STATUS_INTERNAL_ERROR;
  1072. *Authoritative = TRUE;
  1073. goto Cleanup;
  1074. }
  1075. if(DomainPasswordInfo->PasswordProperties & DOMAIN_LOCKOUT_ADMINS) {
  1076. LockOut = TRUE;
  1077. } else {
  1078. LockOut = FALSE;
  1079. }
  1080. SamFreeMemory(DomainPasswordInfo);
  1081. } else {
  1082. //
  1083. // if the process is configured to allow over-ride
  1084. // (true if physical console logon), then don't enforce lockout.
  1085. //
  1086. if( NtLmCheckProcessOption( MSV1_0_OPTION_DISABLE_ADMIN_LOCKOUT ) & MSV1_0_OPTION_DISABLE_ADMIN_LOCKOUT )
  1087. {
  1088. LockOut = FALSE;
  1089. }
  1090. }
  1091. }
  1092. if(LockOut){
  1093. //
  1094. // Since the UI strongly encourages admins to disable user
  1095. // accounts rather than delete them. Treat disabled acccount as
  1096. // non-authoritative allowing the search to continue for other
  1097. // accounts by the same name.
  1098. //
  1099. if ( UserAll->UserAccountControl & USER_ACCOUNT_DISABLED ) {
  1100. *Authoritative = fMachineAccount;
  1101. } else {
  1102. *Authoritative = TRUE;
  1103. }
  1104. Status = STATUS_ACCOUNT_LOCKED_OUT;
  1105. goto Cleanup;
  1106. }
  1107. }
  1108. if ( SecureChannelType != MsvApSecureChannel ) {
  1109. Flags |= MSV1_0_PASSTHRU;
  1110. }
  1111. if ( GuestRelativeId != 0 ) {
  1112. Flags |= MSV1_0_GUEST_LOGON;
  1113. }
  1114. Status = Msv1_0SubAuthenticationRoutine(
  1115. LogonLevel,
  1116. LogonInformation,
  1117. Flags,
  1118. (PUSER_ALL_INFORMATION) UserAll,
  1119. &WhichFields,
  1120. &LocalUserFlags,
  1121. Authoritative,
  1122. &LogoffTime,
  1123. &KickoffTime );
  1124. if ( !NT_SUCCESS(Status) ) {
  1125. goto Cleanup;
  1126. }
  1127. //
  1128. // Sanity check what the SubAuthentication package returned
  1129. //
  1130. if ( (WhichFields & ~USER_ALL_PARAMETERS) != 0 ) {
  1131. Status = STATUS_INTERNAL_ERROR;
  1132. *Authoritative = TRUE;
  1133. goto Cleanup;
  1134. }
  1135. UserFlags |= LocalUserFlags;
  1136. } else { // we may still have an NT 5.0 SubAuth dll
  1137. //
  1138. // If there is an NT 5.0 SubAuthentication DLL,
  1139. // call it to do all the authentication work.
  1140. //
  1141. if ( (LogonInfo->ParameterControl & MSV1_0_SUBAUTHENTICATION_DLL_EX))
  1142. {
  1143. ULONG LocalUserFlags = 0;
  1144. ULONG Flags = 0;
  1145. if ( SecureChannelType != MsvApSecureChannel ) {
  1146. Flags |= MSV1_0_PASSTHRU;
  1147. }
  1148. if ( GuestRelativeId != 0 ) {
  1149. Flags |= MSV1_0_GUEST_LOGON;
  1150. }
  1151. Status = Msv1_0SubAuthenticationRoutineEx(
  1152. LogonLevel,
  1153. LogonInformation,
  1154. Flags,
  1155. (PUSER_ALL_INFORMATION) UserAll,
  1156. (SAM_HANDLE)UserHandle,
  1157. &SubAuthValidationInformation,
  1158. &ActionsPerformed );
  1159. *Authoritative = SubAuthValidationInformation.Authoritative;
  1160. if ( !NT_SUCCESS(Status) ) {
  1161. goto Cleanup;
  1162. }
  1163. // We need to do this because even if any of the following checks
  1164. // fail, ARAP stills wants the returned blobs from the subauth
  1165. // package to be returned to the caller.
  1166. fSubAuthEx = TRUE;
  1167. }
  1168. //
  1169. // Ensure the account isn't locked out.
  1170. //
  1171. if ((ActionsPerformed & MSV1_0_SUBAUTH_LOCKOUT) == 0)
  1172. {
  1173. if ( (UserAll->UserAccountControl & USER_ACCOUNT_AUTO_LOCKED) &&
  1174. (SecureChannelType != NullSecureChannel) )
  1175. {
  1176. BOOL LockOut = TRUE;
  1177. if (RelativeId == DOMAIN_USER_RID_ADMIN) {
  1178. if(LogonLevel != NetlogonInteractiveInformation) {
  1179. PDOMAIN_PASSWORD_INFORMATION DomainPasswordInfo = NULL;
  1180. Status = I_SamrQueryInformationDomain(
  1181. NlpSamDomainHandle,
  1182. DomainPasswordInformation,
  1183. (PSAMPR_DOMAIN_INFO_BUFFER *)&DomainPasswordInfo );
  1184. if (!NT_SUCCESS(Status)) {
  1185. Status = STATUS_INTERNAL_ERROR;
  1186. *Authoritative = TRUE;
  1187. goto Cleanup;
  1188. }
  1189. if(DomainPasswordInfo->PasswordProperties & DOMAIN_LOCKOUT_ADMINS) {
  1190. LockOut = TRUE;
  1191. } else {
  1192. LockOut = FALSE;
  1193. }
  1194. SamFreeMemory(DomainPasswordInfo);
  1195. } else {
  1196. //
  1197. // if the process is configured to allow over-ride
  1198. // (true if physical console logon), then don't enforce lockout.
  1199. //
  1200. if( NtLmCheckProcessOption( MSV1_0_OPTION_DISABLE_ADMIN_LOCKOUT ) & MSV1_0_OPTION_DISABLE_ADMIN_LOCKOUT )
  1201. {
  1202. LockOut = FALSE;
  1203. }
  1204. }
  1205. }
  1206. if (LockOut) {
  1207. //
  1208. // Since the UI strongly encourages admins to disable user
  1209. // accounts rather than delete them. Treat disabled acccount as
  1210. // non-authoritative allowing the search to continue for other
  1211. // accounts by the same name.
  1212. //
  1213. if ( UserAll->UserAccountControl & USER_ACCOUNT_DISABLED ) {
  1214. *Authoritative = fMachineAccount;
  1215. } else {
  1216. *Authoritative = TRUE;
  1217. }
  1218. Status = STATUS_ACCOUNT_LOCKED_OUT;
  1219. goto Cleanup;
  1220. }
  1221. }
  1222. }
  1223. //
  1224. // Check the password if there's no subauth or if subauth did
  1225. // not already check password.
  1226. //
  1227. if ((ActionsPerformed & MSV1_0_SUBAUTH_PASSWORD) == 0)
  1228. {
  1229. if ( SecureChannelType != NullSecureChannel ) {
  1230. USER_INTERNAL1_INFORMATION Passwords;
  1231. //
  1232. // Copy the password info to the right structure.
  1233. //
  1234. Passwords.NtPasswordPresent = UserAll->NtPasswordPresent;
  1235. if ( UserAll->NtPasswordPresent ) {
  1236. Passwords.NtOwfPassword =
  1237. *((PNT_OWF_PASSWORD)(UserAll->NtOwfPassword.Buffer));
  1238. }
  1239. Passwords.LmPasswordPresent = UserAll->LmPasswordPresent;
  1240. if ( UserAll->LmPasswordPresent ) {
  1241. Passwords.LmOwfPassword =
  1242. *((PLM_OWF_PASSWORD)(UserAll->LmOwfPassword.Buffer));
  1243. }
  1244. //
  1245. // If the password specified doesn't match the SAM password,
  1246. // then we've got a password mismatch.
  1247. //
  1248. if ( ! MsvpPasswordValidate (
  1249. UasCompatibilityRequired,
  1250. LogonLevel,
  1251. LogonInformation,
  1252. &Passwords,
  1253. &UserFlags,
  1254. &UserSessionKey,
  1255. &LmSessionKey ) ) {
  1256. //
  1257. // If this is a guest logon and the guest account has no password,
  1258. // let the user log on.
  1259. //
  1260. // This special case check is after the MsvpPasswordValidate to
  1261. // give MsvpPasswordValidate every opportunity to compute the
  1262. // correct values for UserSessionKey and LmSessionKey.
  1263. //
  1264. if ( GuestRelativeId != 0 &&
  1265. !UserAll->NtPasswordPresent &&
  1266. !UserAll->LmPasswordPresent ) {
  1267. RtlZeroMemory( &UserSessionKey, sizeof(UserSessionKey) );
  1268. RtlZeroMemory( &LmSessionKey, sizeof(LmSessionKey) );
  1269. //
  1270. // The password mismatched. We treat STATUS_WRONG_PASSWORD as
  1271. // an authoritative response. Our caller may choose to do otherwise.
  1272. //
  1273. } else {
  1274. Status = STATUS_WRONG_PASSWORD;
  1275. //
  1276. // Since the UI strongly encourages admins to disable user
  1277. // accounts rather than delete them. Treat disabled acccount as
  1278. // non-authoritative allowing the search to continue for other
  1279. // accounts by the same name.
  1280. //
  1281. if ( UserAll->UserAccountControl & USER_ACCOUNT_DISABLED ) {
  1282. *Authoritative = fMachineAccount;
  1283. } else {
  1284. *Authoritative = TRUE;
  1285. }
  1286. goto Cleanup;
  1287. }
  1288. }
  1289. }
  1290. //
  1291. // If SubAuth DLL checked the password, then it implicitly
  1292. // checked the password's expiration, and we don't have to.
  1293. //
  1294. } else { // end if((ActionsPerformed & MSV1_0_SUBAUTH_PASSWORD) == 0)
  1295. ActionsPerformed |= MSV1_0_SUBAUTH_PASSWORD_EXPIRY;
  1296. }
  1297. //
  1298. // Check if the account is disabled if there's no subauth or if
  1299. // subauth has not already checked.
  1300. //
  1301. if ((ActionsPerformed & MSV1_0_SUBAUTH_ACCOUNT_DISABLED) == 0)
  1302. {
  1303. if ( UserAll->UserAccountControl & USER_ACCOUNT_DISABLED ) {
  1304. //
  1305. // Since the UI strongly encourages admins to disable user
  1306. // accounts rather than delete them. Treat disabled acccount as
  1307. // non-authoritative allowing the search to continue for other
  1308. // accounts by the same name.
  1309. //
  1310. *Authoritative = fMachineAccount;
  1311. Status = STATUS_ACCOUNT_DISABLED;
  1312. goto Cleanup;
  1313. }
  1314. }
  1315. //
  1316. // Prevent some things from effecting the Administrator user
  1317. //
  1318. if (RelativeId != DOMAIN_USER_RID_ADMIN) {
  1319. //
  1320. // Check if the account has expired if there's no subauth or if
  1321. // subauth has not already checked.
  1322. //
  1323. if ((ActionsPerformed & MSV1_0_SUBAUTH_ACCOUNT_EXPIRY) == 0)
  1324. {
  1325. OLD_TO_NEW_LARGE_INTEGER( UserAll->AccountExpires, AccountExpires );
  1326. if ( AccountExpires.QuadPart != 0 &&
  1327. LogonTime.QuadPart >= AccountExpires.QuadPart ) {
  1328. *Authoritative = TRUE;
  1329. Status = STATUS_ACCOUNT_EXPIRED;
  1330. goto Cleanup;
  1331. }
  1332. }
  1333. //
  1334. // The password is valid, check to see if the password is expired.
  1335. // (SAM will have appropriately set PasswordMustChange to reflect
  1336. // USER_DONT_EXPIRE_PASSWORD)
  1337. //
  1338. // We only check password expiration if we also checked the password.
  1339. //
  1340. if ((ActionsPerformed & MSV1_0_SUBAUTH_PASSWORD_EXPIRY) == 0)
  1341. {
  1342. OLD_TO_NEW_LARGE_INTEGER( UserAll->PasswordMustChange, PasswordMustChange );
  1343. OLD_TO_NEW_LARGE_INTEGER( UserAll->PasswordLastSet, PasswordLastSet );
  1344. if ( SecureChannelType != NullSecureChannel ) {
  1345. if ( LogonTime.QuadPart >= PasswordMustChange.QuadPart ) {
  1346. if ( PasswordLastSet.QuadPart == 0 ) {
  1347. Status = STATUS_PASSWORD_MUST_CHANGE;
  1348. } else {
  1349. Status = STATUS_PASSWORD_EXPIRED;
  1350. }
  1351. *Authoritative = TRUE;
  1352. goto Cleanup;
  1353. }
  1354. }
  1355. }
  1356. }
  1357. //
  1358. // Validate the workstation the user logged on from.
  1359. //
  1360. // Ditch leading \\ on workstation name before passing it to SAM.
  1361. //
  1362. LocalWorkstation = LogonInfo->Workstation;
  1363. if ( LocalWorkstation.Length > 0 &&
  1364. LocalWorkstation.Buffer[0] == L'\\' &&
  1365. LocalWorkstation.Buffer[1] == L'\\' ) {
  1366. LocalWorkstation.Buffer += 2;
  1367. LocalWorkstation.Length -= 2*sizeof(WCHAR);
  1368. LocalWorkstation.MaximumLength -= 2*sizeof(WCHAR);
  1369. }
  1370. //
  1371. // Check if SAM found some more specific reason to not allow logon.
  1372. //
  1373. Status = I_SamIAccountRestrictions(
  1374. UserHandle,
  1375. &LocalWorkstation,
  1376. (PUNICODE_STRING) &UserAll->WorkStations,
  1377. (PLOGON_HOURS) &UserAll->LogonHours,
  1378. &LogoffTime,
  1379. &KickoffTime );
  1380. if ( !NT_SUCCESS(Status) ) {
  1381. *Authoritative = TRUE;
  1382. goto Cleanup;
  1383. }
  1384. //
  1385. // If there is a SubAuthentication package zero, call it
  1386. //
  1387. if (NlpSubAuthZeroExists) {
  1388. ULONG LocalUserFlags = 0;
  1389. ULONG Flags = 0;
  1390. if ( SecureChannelType != MsvApSecureChannel ) {
  1391. Flags |= MSV1_0_PASSTHRU;
  1392. }
  1393. if ( GuestRelativeId != 0 ) {
  1394. Flags |= MSV1_0_GUEST_LOGON;
  1395. }
  1396. Status = Msv1_0SubAuthenticationRoutineZero(
  1397. LogonLevel,
  1398. LogonInformation,
  1399. Flags,
  1400. (PUSER_ALL_INFORMATION) UserAll,
  1401. &WhichFields,
  1402. &LocalUserFlags,
  1403. Authoritative,
  1404. &LogoffTime,
  1405. &KickoffTime );
  1406. if ( !NT_SUCCESS(Status) ) {
  1407. goto Cleanup;
  1408. }
  1409. //
  1410. // Sanity check what the SubAuthentication package returned
  1411. //
  1412. if ( (WhichFields & ~USER_ALL_PARAMETERS) != 0 ) {
  1413. Status = STATUS_INTERNAL_ERROR;
  1414. *Authoritative = TRUE;
  1415. goto Cleanup;
  1416. }
  1417. UserFlags |= LocalUserFlags;
  1418. }
  1419. }
  1420. //
  1421. // If the account is a machine account,
  1422. // let the caller know he got the password right.
  1423. // (But don't let him actually log on).
  1424. //
  1425. // But, for NT 5.0, we must allow accounts with account control
  1426. // USER_WORKSTATION_TRUST_ACCOUNT for remote boot clients who
  1427. // will logon with their machine accounts
  1428. if ( (UserAll->UserAccountControl & USER_MACHINE_ACCOUNT_MASK) != 0 ) {
  1429. if (UserAll->UserAccountControl & USER_INTERDOMAIN_TRUST_ACCOUNT) {
  1430. Status = STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT;
  1431. } else if (UserAll->UserAccountControl &
  1432. USER_WORKSTATION_TRUST_ACCOUNT) {
  1433. if ( (LogonInfo->ParameterControl & MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT) == 0) {
  1434. Status = STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT;
  1435. } else {
  1436. UNICODE_STRING MachineAccountName;
  1437. NTSTATUS TempStatus;
  1438. //
  1439. // if the password was correct, and it happened to match
  1440. // the machine name, dis-allow it regardless.
  1441. //
  1442. //
  1443. // Compute the lower case user name.
  1444. //
  1445. TempStatus = RtlDowncaseUnicodeString( &MachineAccountName,
  1446. (PUNICODE_STRING)&UserAll->UserName,
  1447. TRUE );
  1448. if( NT_SUCCESS( TempStatus ) )
  1449. {
  1450. USHORT LastChar = MachineAccountName.Length / sizeof(WCHAR);
  1451. if( LastChar )
  1452. {
  1453. if( MachineAccountName.Buffer[LastChar-1] == L'$' )
  1454. {
  1455. MachineAccountName.Length -= sizeof(WCHAR);
  1456. }
  1457. if( LastChar > LM20_PWLEN )
  1458. {
  1459. MachineAccountName.Length = LM20_PWLEN * sizeof(WCHAR);
  1460. }
  1461. }
  1462. if ( UserAll->NtPasswordPresent ) {
  1463. NT_OWF_PASSWORD NtOwfMachineName;
  1464. NT_OWF_PASSWORD *pOwf;
  1465. pOwf = ((PNT_OWF_PASSWORD)(UserAll->NtOwfPassword.Buffer));
  1466. RtlCalculateNtOwfPassword(
  1467. &MachineAccountName,
  1468. &NtOwfMachineName );
  1469. if ( RtlCompareMemory( pOwf,
  1470. &NtOwfMachineName,
  1471. NT_OWF_PASSWORD_LENGTH ) ==
  1472. NT_OWF_PASSWORD_LENGTH ) {
  1473. Status = STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT;
  1474. }
  1475. }
  1476. RtlFreeUnicodeString( &MachineAccountName );
  1477. }
  1478. }
  1479. } else if (UserAll->UserAccountControl & USER_SERVER_TRUST_ACCOUNT) {
  1480. if ( (LogonInfo->ParameterControl & MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT) == 0) {
  1481. Status = STATUS_NOLOGON_SERVER_TRUST_ACCOUNT;
  1482. } else {
  1483. //
  1484. // it's a server trust account.
  1485. // treat same way as workstation trust account.
  1486. UNICODE_STRING MachineAccountName;
  1487. NTSTATUS TempStatus;
  1488. // NOTE: some code here is duplicated from above.
  1489. // this will be merged when a new Rtl has been added for
  1490. // computing initial machine password from machine acct name.
  1491. //
  1492. //
  1493. // if the password was correct, and it happened to match
  1494. // the machine name, dis-allow it regardless.
  1495. //
  1496. //
  1497. // Compute the lower case user name.
  1498. //
  1499. TempStatus = RtlDowncaseUnicodeString( &MachineAccountName,
  1500. (PUNICODE_STRING)&UserAll->UserName,
  1501. TRUE );
  1502. if( NT_SUCCESS( TempStatus ) )
  1503. {
  1504. USHORT LastChar = MachineAccountName.Length / sizeof(WCHAR);
  1505. if( LastChar )
  1506. {
  1507. if( MachineAccountName.Buffer[LastChar-1] == L'$' )
  1508. {
  1509. MachineAccountName.Length -= sizeof(WCHAR);
  1510. }
  1511. if( LastChar > LM20_PWLEN )
  1512. {
  1513. MachineAccountName.Length = LM20_PWLEN * sizeof(WCHAR);
  1514. }
  1515. }
  1516. if ( UserAll->NtPasswordPresent ) {
  1517. NT_OWF_PASSWORD NtOwfMachineName;
  1518. NT_OWF_PASSWORD *pOwf;
  1519. pOwf = ((PNT_OWF_PASSWORD)(UserAll->NtOwfPassword.Buffer));
  1520. RtlCalculateNtOwfPassword(
  1521. &MachineAccountName,
  1522. &NtOwfMachineName );
  1523. if ( RtlCompareMemory( pOwf,
  1524. &NtOwfMachineName,
  1525. NT_OWF_PASSWORD_LENGTH ) ==
  1526. NT_OWF_PASSWORD_LENGTH ) {
  1527. Status = STATUS_NOLOGON_SERVER_TRUST_ACCOUNT;
  1528. }
  1529. }
  1530. RtlFreeUnicodeString( &MachineAccountName );
  1531. }
  1532. //
  1533. // Let the client know that this was
  1534. // a server trust account
  1535. //
  1536. UserFlags |= LOGON_SERVER_TRUST_ACCOUNT;
  1537. }
  1538. } else {
  1539. Status = STATUS_NO_SUCH_USER;
  1540. }
  1541. if (!NT_SUCCESS(Status)) {
  1542. *Authoritative = TRUE;
  1543. goto Cleanup;
  1544. }
  1545. }
  1546. //
  1547. // don't allow blank password logons.
  1548. //
  1549. if(
  1550. (RelativeId != DOMAIN_USER_RID_GUEST)
  1551. &&
  1552. (!NtLmGlobalAllowBlankPassword)
  1553. &&
  1554. (!UserAll->NtPasswordPresent || (RtlCompareMemory(
  1555. &NlpNullNtOwfPassword,
  1556. UserAll->NtOwfPassword.Buffer,
  1557. NT_OWF_PASSWORD_LENGTH
  1558. ) == NT_OWF_PASSWORD_LENGTH))
  1559. &&
  1560. (!UserAll->LmPasswordPresent || (RtlCompareMemory(
  1561. &NlpNullLmOwfPassword,
  1562. UserAll->LmOwfPassword.Buffer,
  1563. LM_OWF_PASSWORD_LENGTH
  1564. ) == LM_OWF_PASSWORD_LENGTH))
  1565. &&
  1566. ( ((NtLmCheckProcessOption( MSV1_0_OPTION_ALLOW_BLANK_PASSWORD )) & MSV1_0_OPTION_ALLOW_BLANK_PASSWORD) == 0 )
  1567. )
  1568. {
  1569. *Authoritative = FALSE;
  1570. Status = STATUS_ACCOUNT_RESTRICTION;
  1571. goto Cleanup;
  1572. }
  1573. //
  1574. // Filter the groups into global groups (from other domains) and local
  1575. // groups (from this domain).
  1576. //
  1577. Status = MsvpFilterGroupMembership(
  1578. &GroupMembership,
  1579. LogonDomainId,
  1580. &GroupsBuffer,
  1581. &GlobalGroupMembership,
  1582. &GlobalMembershipSize
  1583. );
  1584. if ( !NT_SUCCESS(Status) ) {
  1585. *Authoritative = FALSE;
  1586. goto Cleanup;
  1587. }
  1588. Cleanup:
  1589. if (NT_SUCCESS(Status) || fSubAuthEx)
  1590. {
  1591. UNICODE_STRING ReturnDnsDomainName;
  1592. BOOLEAN UseDefaultUpn;
  1593. //
  1594. // Allocate a return buffer for validation information.
  1595. // (Return less information for a network logon)
  1596. // (Return UserParameters for a MNS logon)
  1597. //
  1598. ValidationSamSize = sizeof( NETLOGON_VALIDATION_SAM_INFO4 ) +
  1599. GroupsBuffer.MembershipCount * sizeof(GROUP_MEMBERSHIP) +
  1600. LogonDomainName->Length + sizeof(WCHAR) +
  1601. LogonServer->Length + sizeof(WCHAR) +
  1602. RtlLengthSid( LogonDomainId );
  1603. //
  1604. // all logon types get the username, as, this could be mapped
  1605. // to guest account, for instance, and logon session needs correct
  1606. // names.
  1607. //
  1608. ValidationSamSize +=
  1609. UserAll->UserName.Length + sizeof(WCHAR) ;
  1610. if ( LogonLevel != NetlogonNetworkInformation ) {
  1611. ValidationSamSize +=
  1612. UserAll->FullName.Length + sizeof(WCHAR) +
  1613. UserAll->ScriptPath.Length + sizeof(WCHAR)+
  1614. UserAll->ProfilePath.Length + sizeof(WCHAR) +
  1615. UserAll->HomeDirectory.Length + sizeof(WCHAR) +
  1616. UserAll->HomeDirectoryDrive.Length + sizeof(WCHAR);
  1617. }
  1618. if ( LogonInfo->ParameterControl & MSV1_0_RETURN_USER_PARAMETERS ) {
  1619. ValidationSamSize +=
  1620. UserAll->Parameters.Length + sizeof(WCHAR);
  1621. } else if ( LogonInfo->ParameterControl & MSV1_0_RETURN_PROFILE_PATH ) {
  1622. ValidationSamSize +=
  1623. UserAll->ProfilePath.Length + sizeof(WCHAR);
  1624. }
  1625. //
  1626. // If the caller can handle extra groups, let them have the groups from
  1627. // other domains.
  1628. //
  1629. if ( ValidationLevel == NetlogonValidationSamInfo2 ||
  1630. ValidationLevel == NetlogonValidationSamInfo4 ) {
  1631. ValidationSamSize += GlobalMembershipSize;
  1632. }
  1633. //
  1634. // If the caller wants the logon domain in DNS and UPN form,
  1635. // grab it.
  1636. //
  1637. if ( ValidationLevel == NetlogonValidationSamInfo4 ) {
  1638. //
  1639. // Grab the dns name of the account domain.
  1640. //
  1641. RtlAcquireResourceShared(&NtLmGlobalCritSect, TRUE);
  1642. if( NlpWorkstation ) {
  1643. //ReturnDnsDomainName = NtLmGlobalUnicodeDnsComputerNameString;
  1644. //
  1645. // for local accounts, DnsDomainName doesn't exist.
  1646. //
  1647. RtlInitUnicodeString( &ReturnDnsDomainName, L"" );
  1648. } else {
  1649. ReturnDnsDomainName = NtLmGlobalUnicodeDnsDomainNameString;
  1650. }
  1651. ValidationSamSize += ReturnDnsDomainName.Length + sizeof(WCHAR);
  1652. //
  1653. // If we couldn't get the UPN from SAM,
  1654. // build the default one.
  1655. //
  1656. if( Upn.Buffer != NULL )
  1657. {
  1658. UseDefaultUpn = FALSE;
  1659. ValidationSamSize += (Upn.Length + sizeof(WCHAR));
  1660. } else {
  1661. UseDefaultUpn = TRUE;
  1662. if ( !NlpWorkstation )
  1663. {
  1664. ValidationSamSize +=
  1665. UserAll->UserName.Length +
  1666. sizeof(WCHAR) +
  1667. ReturnDnsDomainName.Length + sizeof(WCHAR);
  1668. }
  1669. }
  1670. }
  1671. ValidationSamSize = ROUND_UP_COUNT( ValidationSamSize, sizeof(WCHAR) );
  1672. ValidationSam = MIDL_user_allocate( ValidationSamSize );
  1673. if ( ValidationSam == NULL ) {
  1674. *Authoritative = FALSE;
  1675. fSubAuthEx = FALSE; // avoid nasty loop condition
  1676. Status = STATUS_NO_MEMORY;
  1677. RtlReleaseResource(&NtLmGlobalCritSect);
  1678. goto Cleanup;
  1679. }
  1680. //
  1681. // Default unused fields (and ExpansionRoom) to zero.
  1682. //
  1683. RtlZeroMemory( ValidationSam, ValidationSamSize );
  1684. //
  1685. // Copy the scalars to the validation buffer.
  1686. //
  1687. Where = (PUCHAR) (ValidationSam + 1);
  1688. if ((SubAuthValidationInformation.WhichFields & MSV1_0_VALIDATION_LOGOFF_TIME) != 0) {
  1689. NEW_TO_OLD_LARGE_INTEGER( SubAuthValidationInformation.LogoffTime, ValidationSam->LogoffTime );
  1690. }
  1691. else {
  1692. NEW_TO_OLD_LARGE_INTEGER( LogoffTime, ValidationSam->LogoffTime );
  1693. }
  1694. if ((SubAuthValidationInformation.WhichFields & MSV1_0_VALIDATION_KICKOFF_TIME) != 0) {
  1695. NEW_TO_OLD_LARGE_INTEGER( SubAuthValidationInformation.KickoffTime, ValidationSam->KickOffTime );
  1696. }
  1697. else {
  1698. NEW_TO_OLD_LARGE_INTEGER( KickoffTime, ValidationSam->KickOffTime );
  1699. }
  1700. if ((SubAuthValidationInformation.WhichFields & MSV1_0_VALIDATION_SESSION_KEY) != 0) {
  1701. ValidationSam->UserSessionKey = SubAuthValidationInformation.SessionKey;
  1702. }
  1703. else {
  1704. ValidationSam->UserSessionKey = UserSessionKey;
  1705. }
  1706. if ((SubAuthValidationInformation.WhichFields & MSV1_0_VALIDATION_USER_FLAGS) != 0) {
  1707. ValidationSam->UserFlags = SubAuthValidationInformation.UserFlags;
  1708. }
  1709. else {
  1710. ValidationSam->UserFlags = UserFlags;
  1711. }
  1712. if ((SubAuthValidationInformation.WhichFields & MSV1_0_VALIDATION_USER_ID) != 0) {
  1713. ValidationSam->UserId = SubAuthValidationInformation.UserId;
  1714. }
  1715. else {
  1716. ValidationSam->UserId = UserAll->UserId;
  1717. }
  1718. ValidationSam->LogonTime = UserAll->LastLogon;
  1719. ValidationSam->PasswordLastSet = UserAll->PasswordLastSet;
  1720. ValidationSam->PasswordCanChange = UserAll->PasswordCanChange;
  1721. ValidationSam->PasswordMustChange = UserAll->PasswordMustChange;
  1722. ValidationSam->LogonCount = UserAll->LogonCount;
  1723. ValidationSam->BadPasswordCount = UserAll->BadPasswordCount;
  1724. ValidationSam->PrimaryGroupId = UserAll->PrimaryGroupId;
  1725. ValidationSam->GroupCount = GroupsBuffer.MembershipCount;
  1726. ASSERT( SAMINFO_LM_SESSION_KEY_SIZE == sizeof(LmSessionKey) );
  1727. RtlCopyMemory( &ValidationSam->ExpansionRoom[SAMINFO_LM_SESSION_KEY],
  1728. &LmSessionKey,
  1729. SAMINFO_LM_SESSION_KEY_SIZE );
  1730. ValidationSam->ExpansionRoom[SAMINFO_USER_ACCOUNT_CONTROL] = UserAll->UserAccountControl;
  1731. // Save any status for subuath users not returned by the subauth package
  1732. if (fSubAuthEx)
  1733. {
  1734. ValidationSam->ExpansionRoom[SAMINFO_SUBAUTH_STATUS] = Status;
  1735. }
  1736. //
  1737. // Copy ULONG aligned data to the validation buffer.
  1738. //
  1739. RtlCopyMemory(
  1740. Where,
  1741. GroupsBuffer.Groups,
  1742. GroupsBuffer.MembershipCount * sizeof(GROUP_MEMBERSHIP) );
  1743. ValidationSam->GroupIds = (PGROUP_MEMBERSHIP) Where;
  1744. Where += GroupsBuffer.MembershipCount * sizeof(GROUP_MEMBERSHIP);
  1745. RtlCopyMemory(
  1746. Where,
  1747. LogonDomainId,
  1748. RtlLengthSid( LogonDomainId ) );
  1749. ValidationSam->LogonDomainId = (PSID) Where;
  1750. Where += RtlLengthSid( LogonDomainId );
  1751. //
  1752. // If the client asked for extra information, return that
  1753. // we support it
  1754. //
  1755. if ( ValidationLevel == NetlogonValidationSamInfo2 ||
  1756. ValidationLevel == NetlogonValidationSamInfo4 ) {
  1757. ValidationSam->UserFlags |= LOGON_EXTRA_SIDS;
  1758. if (GlobalMembershipSize != 0) {
  1759. ULONG SidLength;
  1760. ValidationSam->SidCount = GlobalGroupMembership.Count;
  1761. ValidationSam->ExtraSids = (PNETLOGON_SID_AND_ATTRIBUTES) Where;
  1762. Where += ValidationSam->SidCount * sizeof(NETLOGON_SID_AND_ATTRIBUTES);
  1763. //
  1764. // Copy all the extra sids into the buffer
  1765. //
  1766. for (Index = 0; Index < ValidationSam->SidCount ; Index++ ) {
  1767. ValidationSam->ExtraSids[Index].Attributes = GlobalGroupMembership.SidAndAttributes[Index].Attributes;
  1768. ValidationSam->ExtraSids[Index].Sid = Where;
  1769. SidLength = RtlLengthSid(GlobalGroupMembership.SidAndAttributes[Index].Sid);
  1770. RtlCopyMemory(
  1771. ValidationSam->ExtraSids[Index].Sid,
  1772. GlobalGroupMembership.SidAndAttributes[Index].Sid,
  1773. SidLength
  1774. );
  1775. Where += SidLength;
  1776. }
  1777. }
  1778. }
  1779. //
  1780. // Copy WCHAR aligned data to the validation buffer.
  1781. // (Return less information for a network logon)
  1782. //
  1783. Where = ROUND_UP_POINTER( Where, sizeof(WCHAR) );
  1784. NlpPutString( &ValidationSam->EffectiveName,
  1785. (PUNICODE_STRING)&UserAll->UserName,
  1786. &Where );
  1787. if ( LogonLevel != NetlogonNetworkInformation ) {
  1788. NlpPutString( &ValidationSam->FullName,
  1789. (PUNICODE_STRING)&UserAll->FullName,
  1790. &Where );
  1791. NlpPutString( &ValidationSam->LogonScript,
  1792. (PUNICODE_STRING)&UserAll->ScriptPath,
  1793. &Where );
  1794. NlpPutString( &ValidationSam->ProfilePath,
  1795. (PUNICODE_STRING)&UserAll->ProfilePath,
  1796. &Where );
  1797. NlpPutString( &ValidationSam->HomeDirectory,
  1798. (PUNICODE_STRING)&UserAll->HomeDirectory,
  1799. &Where );
  1800. NlpPutString( &ValidationSam->HomeDirectoryDrive,
  1801. (PUNICODE_STRING)&UserAll->HomeDirectoryDrive,
  1802. &Where );
  1803. }
  1804. if ((SubAuthValidationInformation.WhichFields & MSV1_0_VALIDATION_LOGON_SERVER) != 0) {
  1805. NlpPutString( &ValidationSam->LogonServer,
  1806. &SubAuthValidationInformation.LogonServer,
  1807. &Where );
  1808. }
  1809. else {
  1810. NlpPutString( &ValidationSam->LogonServer,
  1811. LogonServer,
  1812. &Where );
  1813. }
  1814. if ((SubAuthValidationInformation.WhichFields & MSV1_0_VALIDATION_LOGON_DOMAIN) != 0) {
  1815. NlpPutString( &ValidationSam->LogonDomainName,
  1816. &SubAuthValidationInformation.LogonDomainName,
  1817. &Where );
  1818. }
  1819. else {
  1820. NlpPutString( &ValidationSam->LogonDomainName,
  1821. LogonDomainName,
  1822. &Where );
  1823. }
  1824. //
  1825. // If the caller wants the logon domain in DNS and UPN form,
  1826. // return them.
  1827. //
  1828. if ( ValidationLevel == NetlogonValidationSamInfo4 ) {
  1829. //
  1830. // Copy the DNS domain name into the allocated buffer
  1831. //
  1832. NlpPutString( &ValidationSam->DnsLogonDomainName,
  1833. &ReturnDnsDomainName,
  1834. &Where );
  1835. //
  1836. // If we couldn't get the UPN from SAM,
  1837. // copy the default one into the buffer.
  1838. //
  1839. if ( !NlpWorkstation )
  1840. {
  1841. if( UseDefaultUpn )
  1842. {
  1843. UNICODE_STRING TempString1;
  1844. UNICODE_STRING TempString2;
  1845. UNICODE_STRING TempString3;
  1846. UNICODE_STRING AtString;
  1847. NlpPutString( &TempString1,
  1848. (PUNICODE_STRING)&UserAll->UserName,
  1849. &Where );
  1850. Where -= sizeof(WCHAR);
  1851. RtlInitUnicodeString( &AtString, L"@" );
  1852. NlpPutString( &TempString2,
  1853. &AtString,
  1854. &Where );
  1855. Where -= sizeof(WCHAR);
  1856. NlpPutString( &TempString3,
  1857. &ReturnDnsDomainName,
  1858. &Where );
  1859. ValidationSam->Upn.Buffer = TempString1.Buffer;
  1860. ValidationSam->Upn.Length =
  1861. TempString1.Length +
  1862. TempString2.Length +
  1863. TempString3.Length;
  1864. ValidationSam->Upn.MaximumLength = ValidationSam->Upn.Length + sizeof(WCHAR);
  1865. } else {
  1866. UNICODE_STRING TempString1;
  1867. NlpPutString( &TempString1,
  1868. &Upn,
  1869. &Where );
  1870. Where -= sizeof(WCHAR);
  1871. ValidationSam->Upn.Buffer = TempString1.Buffer;
  1872. ValidationSam->Upn.Length = TempString1.Length;
  1873. ValidationSam->Upn.MaximumLength = ValidationSam->Upn.Length;
  1874. }
  1875. }
  1876. //
  1877. // Drop the lock that we've held since we grabbed pointer to the globals
  1878. //
  1879. RtlReleaseResource(&NtLmGlobalCritSect);
  1880. }
  1881. //
  1882. // Kludge: Pass back UserParameters in HomeDirectoryDrive since we
  1883. // can't change the NETLOGON_VALIDATION_SAM_INFO structure between
  1884. // releases NT 3.1 and NT 3.5. HomeDirectoryDrive was NULL for release 3.1
  1885. // so we'll use that field.
  1886. //
  1887. if ( LogonInfo->ParameterControl & MSV1_0_RETURN_USER_PARAMETERS ) {
  1888. NlpPutString( &ValidationSam->HomeDirectoryDrive,
  1889. (PUNICODE_STRING)&UserAll->Parameters,
  1890. &Where );
  1891. } else if ( LogonInfo->ParameterControl & MSV1_0_RETURN_PROFILE_PATH ) {
  1892. NlpPutString( &ValidationSam->HomeDirectoryDrive,
  1893. (PUNICODE_STRING)&UserAll->ProfilePath,
  1894. &Where );
  1895. ValidationSam->UserFlags |= LOGON_PROFILE_PATH_RETURNED;
  1896. }
  1897. *Authoritative = TRUE;
  1898. //
  1899. // For SubAuthEx, we save away the original Status to make decisions
  1900. // later on about additional processing to perform.
  1901. //
  1902. if( fSubAuthEx ) {
  1903. SubAuthExStatus = Status;
  1904. }
  1905. Status = STATUS_SUCCESS;
  1906. }
  1907. //
  1908. // Cleanup up before returning.
  1909. //
  1910. //
  1911. // If the User Parameters have been changed,
  1912. // write them back to SAM.
  1913. //
  1914. if ( NT_SUCCESS(Status) &&
  1915. (WhichFields & USER_ALL_PARAMETERS) )
  1916. {
  1917. SAMPR_USER_INFO_BUFFER UserInfo;
  1918. UserInfo.Parameters.Parameters = UserAll->Parameters;
  1919. Status = I_SamrSetInformationUser(
  1920. UserHandle,
  1921. UserParametersInformation,
  1922. &UserInfo );
  1923. }
  1924. //
  1925. // Update the logon statistics.
  1926. //
  1927. if ( NT_SUCCESS( SubAuthExStatus ) &&
  1928. ( NT_SUCCESS(Status)
  1929. || Status == STATUS_WRONG_PASSWORD
  1930. || Status == STATUS_NO_LOGON_SERVERS ) ) {
  1931. SAM_LOGON_STATISTICS LogonStats;
  1932. RtlZeroMemory(&LogonStats, sizeof(LogonStats));
  1933. if ( NT_SUCCESS( Status ) ) {
  1934. if ( LogonLevel == NetlogonInteractiveInformation ) {
  1935. LogonStats.StatisticsToApply =
  1936. USER_LOGON_INTER_SUCCESS_LOGON;
  1937. } else {
  1938. //
  1939. // On network logons,
  1940. // only update the statistics on 'success' if explicitly asked,
  1941. // or the Bad Password count will be zeroed.
  1942. //
  1943. LogonStats.StatisticsToApply =
  1944. USER_LOGON_NET_SUCCESS_LOGON | USER_LOGON_NO_WRITE;
  1945. if ( (LogonInfo->ParameterControl & MSV1_0_UPDATE_LOGON_STATISTICS) ||
  1946. UserAll->BadPasswordCount != 0 ) {
  1947. LogonStats.StatisticsToApply &= ~USER_LOGON_NO_WRITE;
  1948. }
  1949. }
  1950. // Tell the caller we zeroed the bad password count
  1951. if ( UserAll->BadPasswordCount != 0 ) {
  1952. *BadPasswordCountZeroed = TRUE;
  1953. }
  1954. } else {
  1955. if (Status == STATUS_WRONG_PASSWORD) {
  1956. LogonStats.StatisticsToApply =
  1957. USER_LOGON_BAD_PASSWORD | USER_LOGON_BAD_PASSWORD_WKSTA;
  1958. LogonStats.Workstation = LogonInfo->Workstation;
  1959. } else {
  1960. LogonStats.StatisticsToApply = USER_LOGON_NO_LOGON_SERVERS;
  1961. if (LogonLevel == NetlogonInteractiveInformation) {
  1962. LogonStats.StatisticsToApply |= USER_LOGON_INTER_FAILURE;
  1963. }
  1964. }
  1965. }
  1966. if ( LogonStats.StatisticsToApply != 0 ) {
  1967. NTSTATUS LogonStatus;
  1968. LogonStats.StatisticsToApply |= USER_LOGON_TYPE_NTLM;
  1969. LogonStatus = I_SamIUpdateLogonStatistics(
  1970. UserHandle,
  1971. &LogonStats );
  1972. }
  1973. }
  1974. //
  1975. // Audit this logon. We don't audit failures for the guest account because
  1976. // they are so frequent.
  1977. //
  1978. if (GuestRelativeId == 0 || NT_SUCCESS(Status)) {
  1979. NTSTATUS AuditStatus;
  1980. AuditStatus = Status;
  1981. //
  1982. // if there was a possibly un-successful SubAuthEx status, use it
  1983. //
  1984. if( NT_SUCCESS( AuditStatus ) && fSubAuthEx ) {
  1985. AuditStatus = SubAuthExStatus;
  1986. }
  1987. I_LsaIAuditAccountLogon(
  1988. SE_AUDITID_ACCOUNT_LOGON,
  1989. (BOOLEAN) NT_SUCCESS(AuditStatus),
  1990. &NlpMsv1_0PackageName,
  1991. &LocalUserName,
  1992. &LogonInfo->Workstation,
  1993. AuditStatus
  1994. );
  1995. }
  1996. //
  1997. // Return the validation buffer to the caller.
  1998. //
  1999. if ( !NT_SUCCESS(Status) ) {
  2000. if (ValidationSam != NULL) {
  2001. MIDL_user_free( ValidationSam );
  2002. ValidationSam = NULL;
  2003. }
  2004. }
  2005. *ValidationInformation = ValidationSam;
  2006. //
  2007. // Free locally used resources.
  2008. //
  2009. I_SamIFree_SAMPR_RETURNED_USTRING_ARRAY( &NameArray );
  2010. I_SamIFree_SAMPR_ULONG_ARRAY( &UseArray );
  2011. if ( UserAllInfo != NULL ) {
  2012. I_SamIFree_SAMPR_USER_INFO_BUFFER( UserAllInfo, UserAllInformation );
  2013. }
  2014. if( Upn.Buffer != NULL )
  2015. {
  2016. I_SamIFreeVoid( Upn.Buffer );
  2017. }
  2018. if (GroupMembership.SidAndAttributes != NULL)
  2019. {
  2020. I_SamIFreeSidAndAttributesList(&GroupMembership);
  2021. }
  2022. if ( GroupsBuffer.Groups != NULL ) {
  2023. I_NtLmFree(GroupsBuffer.Groups);
  2024. }
  2025. if ( GlobalGroupMembership.SidAndAttributes != NULL ) {
  2026. I_NtLmFree(GlobalGroupMembership.SidAndAttributes);
  2027. }
  2028. if ( UserHandle != NULL ) {
  2029. I_SamrCloseHandle( &UserHandle );
  2030. }
  2031. if (SubAuthValidationInformation.LogonDomainName.Buffer != NULL) {
  2032. MIDL_user_free(SubAuthValidationInformation.LogonDomainName.Buffer);
  2033. }
  2034. if (SubAuthValidationInformation.LogonServer.Buffer != NULL) {
  2035. MIDL_user_free(SubAuthValidationInformation.LogonServer.Buffer);
  2036. }
  2037. if (LocalSidUser != NULL) {
  2038. I_NtLmFree(LocalSidUser);
  2039. }
  2040. return Status;
  2041. }
  2042. NTSTATUS
  2043. MsvSamValidate (
  2044. IN SAM_HANDLE DomainHandle,
  2045. IN BOOLEAN UasCompatibilityRequired,
  2046. IN NETLOGON_SECURE_CHANNEL_TYPE SecureChannelType,
  2047. IN PUNICODE_STRING LogonServer,
  2048. IN PUNICODE_STRING LogonDomainName,
  2049. IN PSID LogonDomainId,
  2050. IN NETLOGON_LOGON_INFO_CLASS LogonLevel,
  2051. IN PVOID LogonInformation,
  2052. IN NETLOGON_VALIDATION_INFO_CLASS ValidationLevel,
  2053. OUT PVOID * ValidationInformation,
  2054. OUT PBOOLEAN Authoritative,
  2055. OUT PBOOLEAN BadPasswordCountZeroed,
  2056. IN DWORD AccountsToTry
  2057. )
  2058. /*++
  2059. Routine Description:
  2060. Process an interactive, network, or session logon. It calls
  2061. SamIUserValidation, validates the passed in credentials, updates the logon
  2062. statistics and packages the result for return to the caller.
  2063. This routine is called directly from the MSV Authentication package
  2064. if the account is defined locally. This routine is called
  2065. from the Netlogon Service otherwise.
  2066. Arguments:
  2067. DomainHandle -- Specifies a handle to the SamDomain to use to
  2068. validate the request.
  2069. UasCompatibilityRequired -- TRUE if UasCompatibilityRequired is on.
  2070. SecureChannelType -- The secure channel type this request was made on.
  2071. LogonServer -- Specifies the server name of the caller.
  2072. LogonDomainName -- Specifies the domain of the caller.
  2073. LogonDomainId -- Specifies the DomainId of the domain of the caller.
  2074. LogonLevel -- Specifies the level of information given in
  2075. LogonInformation.
  2076. LogonInformation -- Specifies the description for the user
  2077. logging on. The LogonDomainName field should be ignored.
  2078. The caller is responsible for validating this field.
  2079. ValidationLevel -- Specifies the level of information returned in
  2080. ValidationInformation. Must be NetlogonValidationSamInfo,
  2081. NetlogonValidationSamInfo2 or NetlogonValidationSamInfo4
  2082. ValidationInformation -- Returns the requested validation
  2083. information. This buffer must be freed user MIDL_user_free.
  2084. Authoritative -- Returns whether the status returned is an
  2085. authoritative status which should be returned to the original
  2086. caller. If not, this logon request may be tried again on another
  2087. domain controller. This parameter is returned regardless of the
  2088. status code.
  2089. BadPasswordCountZeroed - Returns TRUE if we zeroed the BadPasswordCount
  2090. field of this user.
  2091. AccountsToTry -- Specifies whether the username specified in
  2092. LogonInformation is to be used to logon, whether to guest account
  2093. is to be used to logon, or both serially.
  2094. Return Value:
  2095. STATUS_SUCCESS: if there was no error.
  2096. STATUS_INVALID_INFO_CLASS: LogonLevel or ValidationLevel are invalid.
  2097. STATUS_NO_SUCH_USER: The specified user has no account.
  2098. STATUS_WRONG_PASSWORD: The password was invalid.
  2099. Other return codes from SamIUserValidation
  2100. --*/
  2101. {
  2102. NTSTATUS Status;
  2103. NTSTATUS GuestStatus;
  2104. PNETLOGON_LOGON_IDENTITY_INFO LogonInfo;
  2105. //
  2106. // Tracing
  2107. //
  2108. NTLM_TRACE_INFO TraceInfo = {0};
  2109. //
  2110. // Begin tracing a sam validate call for NTLM
  2111. //
  2112. if (NtlmGlobalEventTraceFlag){
  2113. //Header goo
  2114. SET_TRACE_HEADER(TraceInfo,
  2115. NtlmValidateGuid,
  2116. EVENT_TRACE_TYPE_START,
  2117. WNODE_FLAG_TRACED_GUID,
  2118. 0);
  2119. TraceEvent(NtlmGlobalTraceLoggerHandle,
  2120. (PEVENT_TRACE_HEADER)&TraceInfo);
  2121. }
  2122. LogonInfo = (PNETLOGON_LOGON_IDENTITY_INFO) LogonInformation;
  2123. //
  2124. // if simple file/print option is enabled (applies to SSPI callers),
  2125. // check if ForceGuest should occur.
  2126. //
  2127. if( (LogonInfo->ParameterControl & MSV1_0_ALLOW_FORCE_GUEST) )
  2128. {
  2129. if( NtLmGlobalForceGuest )
  2130. {
  2131. if((LogonInfo->ParameterControl & MSV1_0_DISABLE_PERSONAL_FALLBACK)==0)
  2132. {
  2133. if( (LogonLevel == NetlogonNetworkInformation) &&
  2134. (((NtLmCheckProcessOption( MSV1_0_OPTION_DISABLE_FORCE_GUEST ) & MSV1_0_OPTION_DISABLE_FORCE_GUEST )) == 0)
  2135. )
  2136. {
  2137. AccountsToTry &= ~(MSVSAM_SPECIFIED);
  2138. AccountsToTry |= MSVSAM_GUEST;
  2139. }
  2140. }
  2141. }
  2142. }
  2143. //
  2144. // Validate the specified user.
  2145. //
  2146. *BadPasswordCountZeroed = FALSE;
  2147. if ( AccountsToTry & MSVSAM_SPECIFIED ) {
  2148. //
  2149. // Keep track of the total number of logons attempted.
  2150. //
  2151. I_SamIIncrementPerformanceCounter(
  2152. MsvLogonCounter
  2153. );
  2154. InterlockedIncrement(&NlpLogonAttemptCount);
  2155. Status = MsvpSamValidate( (SAMPR_HANDLE) DomainHandle,
  2156. UasCompatibilityRequired,
  2157. SecureChannelType,
  2158. LogonServer,
  2159. LogonDomainName,
  2160. LogonDomainId,
  2161. LogonLevel,
  2162. LogonInformation,
  2163. 0,
  2164. ValidationLevel,
  2165. ValidationInformation,
  2166. Authoritative,
  2167. BadPasswordCountZeroed );
  2168. //
  2169. // If the SAM database authoritatively handled this logon attempt,
  2170. // just return.
  2171. //
  2172. if ( *Authoritative ) {
  2173. goto Cleanup;
  2174. }
  2175. //
  2176. // If the caller only wants to log on as guest,
  2177. // Pretend the first validation simply didn't find the user.
  2178. //
  2179. } else {
  2180. *Authoritative = FALSE;
  2181. Status = STATUS_NO_SUCH_USER;
  2182. }
  2183. //
  2184. // If guest accounts are not allowed,
  2185. // return now.
  2186. //
  2187. if ( LogonLevel != NetlogonNetworkInformation ||
  2188. SecureChannelType != MsvApSecureChannel ||
  2189. ( LogonInfo->ParameterControl & MSV1_0_DONT_TRY_GUEST_ACCOUNT ) ||
  2190. (AccountsToTry & MSVSAM_GUEST) == 0 ) {
  2191. goto Cleanup;
  2192. //return Status;
  2193. }
  2194. //
  2195. // Try the Guest Account.
  2196. //
  2197. GuestStatus = MsvpSamValidate( (SAMPR_HANDLE) DomainHandle,
  2198. UasCompatibilityRequired,
  2199. SecureChannelType,
  2200. LogonServer,
  2201. LogonDomainName,
  2202. LogonDomainId,
  2203. LogonLevel,
  2204. LogonInformation,
  2205. DOMAIN_USER_RID_GUEST,
  2206. ValidationLevel,
  2207. ValidationInformation,
  2208. Authoritative,
  2209. BadPasswordCountZeroed );
  2210. if ( NT_SUCCESS(GuestStatus) ) {
  2211. PNETLOGON_VALIDATION_SAM_INFO4 ValidationInfo;
  2212. ASSERT ((ValidationLevel == NetlogonValidationSamInfo) ||
  2213. (ValidationLevel == NetlogonValidationSamInfo2) ||
  2214. (ValidationLevel == NetlogonValidationSamInfo4) );
  2215. ValidationInfo =
  2216. (PNETLOGON_VALIDATION_SAM_INFO4) *ValidationInformation;
  2217. ValidationInfo->UserFlags |= LOGON_GUEST;
  2218. Status = GuestStatus;
  2219. goto Cleanup;
  2220. //return GuestStatus;
  2221. }
  2222. //
  2223. // Failed Guest logon attempts are never authoritative and the status from
  2224. // the original logon attempt is more significant than the Guest logon
  2225. // status.
  2226. //
  2227. *Authoritative = FALSE;
  2228. Cleanup:
  2229. //
  2230. // Trace the end of this call
  2231. //
  2232. if (NtlmGlobalEventTraceFlag){
  2233. UINT32 Success;
  2234. PNETLOGON_LOGON_IDENTITY_INFO LogonInfo =
  2235. (PNETLOGON_LOGON_IDENTITY_INFO) LogonInformation;
  2236. SET_TRACE_HEADER(TraceInfo,
  2237. NtlmValidateGuid,
  2238. EVENT_TRACE_TYPE_END,
  2239. WNODE_FLAG_TRACED_GUID|WNODE_FLAG_USE_MOF_PTR,
  2240. 9);
  2241. //
  2242. // Build the "success" trace state bit mask
  2243. // 1bit - Success
  2244. // 2bit - Authoritative
  2245. //
  2246. Success = (Status == STATUS_SUCCESS)?1:0;
  2247. Success |= (*Authoritative)?2:0;
  2248. SET_TRACE_DATA(TraceInfo,
  2249. TRACE_VALIDATE_SUCCESS,
  2250. Success);
  2251. SET_TRACE_USTRING(TraceInfo,
  2252. TRACE_VALIDATE_SERVER,
  2253. (*LogonServer));
  2254. SET_TRACE_USTRING(TraceInfo,
  2255. TRACE_VALIDATE_DOMAIN,
  2256. (*LogonDomainName));
  2257. SET_TRACE_USTRING(TraceInfo,
  2258. TRACE_VALIDATE_USERNAME,
  2259. LogonInfo->UserName);
  2260. SET_TRACE_USTRING(TraceInfo,
  2261. TRACE_VALIDATE_WORKSTATION,
  2262. LogonInfo->Workstation);
  2263. TraceEvent(
  2264. NtlmGlobalTraceLoggerHandle,
  2265. (PEVENT_TRACE_HEADER)&TraceInfo
  2266. );
  2267. }
  2268. return Status;
  2269. }
  2270. NTSTATUS
  2271. MsvSamLogoff (
  2272. IN SAM_HANDLE DomainHandle,
  2273. IN NETLOGON_LOGON_INFO_CLASS LogonLevel,
  2274. IN PVOID LogonInformation
  2275. )
  2276. /*++
  2277. Routine Description:
  2278. Process an interactive, network, or session logoff. It simply updates
  2279. the logon statistics for the user account.
  2280. This routine is called directly from the MSV Authentication package
  2281. if the user was logged on not using the Netlogon service. This routine
  2282. is called from the Netlogon Service otherwise.
  2283. Arguments:
  2284. DomainHandle -- Specifies a handle to the SamDomain containing
  2285. the user to logoff.
  2286. LogonLevel -- Specifies the level of information given in
  2287. LogonInformation.
  2288. LogonInformation -- Specifies the description for the user
  2289. logging on. The LogonDomainName field should be ignored.
  2290. The caller is responsible for validating this field.
  2291. Return Value:
  2292. STATUS_SUCCESS: if there was no error.
  2293. STATUS_INVALID_INFO_CLASS: LogonLevel or ValidationLevel are invalid.
  2294. STATUS_NO_SUCH_USER: The specified user has no account.
  2295. STATUS_WRONG_PASSWORD: The password was invalid.
  2296. Other return codes from SamIUserValidation
  2297. --*/
  2298. {
  2299. return(STATUS_SUCCESS);
  2300. UNREFERENCED_PARAMETER( DomainHandle );
  2301. UNREFERENCED_PARAMETER( LogonLevel );
  2302. UNREFERENCED_PARAMETER( LogonInformation );
  2303. }
  2304. ULONG
  2305. MsvGetLogonAttemptCount (
  2306. VOID
  2307. )
  2308. /*++
  2309. Routine Description:
  2310. Return the number of logon attempts since the last reboot.
  2311. Arguments:
  2312. NONE
  2313. Return Value:
  2314. Returns the number of logon attempts since the last reboot.
  2315. --*/
  2316. {
  2317. //
  2318. // Keep track of the total number of logons attempted.
  2319. //
  2320. return NlpLogonAttemptCount;
  2321. }