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.

172 lines
4.0 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 1991 - 1992
  6. //
  7. // File: restrict.cxx
  8. //
  9. // Contents: Logon restriction code
  10. //
  11. //
  12. // History: 4-Aug-1996 MikeSw Created from tickets.cxx
  13. //
  14. //------------------------------------------------------------------------
  15. extern "C"
  16. {
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <ntlsa.h>
  21. #include <samrpc.h>
  22. #include <samisrv.h>
  23. }
  24. #include <kerbcomm.h>
  25. #include <kerberr.h>
  26. #include <kerbcon.h>
  27. #include <lmcons.h>
  28. #include "debug.h"
  29. //+-------------------------------------------------------------------------
  30. //
  31. // Function: KerbCheckLogonRestrictions
  32. //
  33. // Synopsis: Checks logon restrictions for an account
  34. //
  35. // Effects:
  36. //
  37. // Arguments: UserHandle - handle to a user
  38. // Workstation - Name of client's workstation
  39. // SecondsToLogon - Receives logon duration in seconds
  40. //
  41. // Requires:
  42. //
  43. // Returns: kerberos errors
  44. //
  45. // Notes:
  46. //
  47. //
  48. //--------------------------------------------------------------------------
  49. KERBERR
  50. KerbCheckLogonRestrictions(
  51. IN PVOID UserHandle,
  52. IN PUNICODE_STRING Workstation,
  53. IN PUSER_ALL_INFORMATION UserAll,
  54. IN ULONG LogonRestrictionsFlags,
  55. OUT PLARGE_INTEGER LogoffTime,
  56. OUT PNTSTATUS RetStatus
  57. )
  58. {
  59. NTSTATUS Status;
  60. KERBERR KerbErr;
  61. LARGE_INTEGER KickoffTime;
  62. LARGE_INTEGER CurrentTime;
  63. PLARGE_INTEGER TempTime;
  64. GetSystemTimeAsFileTime((PFILETIME) &CurrentTime );
  65. //
  66. // Check the restrictions SAM doesn't:
  67. //
  68. TempTime = (PLARGE_INTEGER) &UserAll->AccountExpires;
  69. if ((TempTime->QuadPart != 0) &&
  70. (TempTime->QuadPart < CurrentTime.QuadPart))
  71. {
  72. Status = STATUS_ACCOUNT_EXPIRED;
  73. goto Cleanup;
  74. }
  75. //
  76. // For user accounts, check if the password has expired.
  77. //
  78. if (((LogonRestrictionsFlags & KDC_RESTRICT_IGNORE_PW_EXPIRATION) == 0) &&
  79. ((UserAll->UserAccountControl & USER_NORMAL_ACCOUNT) != 0))
  80. {
  81. TempTime = (PLARGE_INTEGER) &UserAll->PasswordMustChange;
  82. if (TempTime->QuadPart < CurrentTime.QuadPart)
  83. {
  84. if (TempTime->QuadPart == 0)
  85. {
  86. Status = STATUS_PASSWORD_MUST_CHANGE;
  87. }
  88. else
  89. {
  90. Status = STATUS_PASSWORD_EXPIRED;
  91. }
  92. goto Cleanup;
  93. }
  94. }
  95. if ((UserAll->UserAccountControl & USER_ACCOUNT_DISABLED))
  96. {
  97. Status = STATUS_ACCOUNT_DISABLED;
  98. goto Cleanup;
  99. }
  100. //
  101. // The Administrator account can not be locked out.
  102. //
  103. if ((UserAll->UserAccountControl & USER_ACCOUNT_AUTO_LOCKED) &&
  104. (UserAll->UserId != DOMAIN_USER_RID_ADMIN))
  105. {
  106. Status = STATUS_ACCOUNT_LOCKED_OUT;
  107. goto Cleanup;
  108. }
  109. if ((UserAll->UserAccountControl & USER_SMARTCARD_REQUIRED) &&
  110. ((LogonRestrictionsFlags & KDC_RESTRICT_PKINIT_USED) == 0))
  111. {
  112. Status = STATUS_SMARTCARD_LOGON_REQUIRED;
  113. goto Cleanup;
  114. }
  115. Status = SamIAccountRestrictions(
  116. UserHandle,
  117. Workstation,
  118. &UserAll->WorkStations,
  119. &UserAll->LogonHours,
  120. LogoffTime,
  121. &KickoffTime
  122. );
  123. if (!NT_SUCCESS(Status))
  124. {
  125. goto Cleanup;
  126. }
  127. Cleanup:
  128. *RetStatus = Status;
  129. switch(Status)
  130. {
  131. case STATUS_SUCCESS:
  132. KerbErr = KDC_ERR_NONE;
  133. break;
  134. case STATUS_ACCOUNT_EXPIRED: // See bug #23456
  135. case STATUS_ACCOUNT_LOCKED_OUT:
  136. case STATUS_ACCOUNT_DISABLED:
  137. case STATUS_INVALID_LOGON_HOURS:
  138. case STATUS_LOGIN_TIME_RESTRICTION:
  139. case STATUS_LOGIN_WKSTA_RESTRICTION:
  140. KerbErr = KDC_ERR_CLIENT_REVOKED;
  141. break;
  142. case STATUS_PASSWORD_EXPIRED:
  143. case STATUS_PASSWORD_MUST_CHANGE:
  144. KerbErr = KDC_ERR_KEY_EXPIRED;
  145. break;
  146. default:
  147. KerbErr = KDC_ERR_POLICY;
  148. }
  149. return(KerbErr);
  150. }