Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
2.6 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // lockout.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines the account lockout API.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 10/21/1998 Original version.
  16. // 11/10/1998 Do not revoke dialin privilege.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <ias.h>
  20. #include <iastlb.h>
  21. #include <iaslsa.h>
  22. #include <acctinfo.h>
  23. #include <lockout.h>
  24. DWORD
  25. WINAPI
  26. AccountLockoutInitialize( VOID )
  27. {
  28. AccountInfo::initialize();
  29. return NO_ERROR;
  30. }
  31. VOID
  32. WINAPI
  33. AccountLockoutShutdown( VOID )
  34. {
  35. AccountInfo::finalize();
  36. }
  37. BOOL
  38. WINAPI
  39. AccountLockoutOpenAndQuery(
  40. IN PCWSTR pszUser,
  41. IN PCWSTR pszDomain,
  42. OUT PHANDLE phAccount
  43. )
  44. {
  45. // Check the arguments.
  46. if (phAccount == NULL) { return ERROR_INVALID_PARAMETER; }
  47. // Open the AccountInfo object for this user.
  48. AccountInfo* info = AccountInfo::open(pszDomain, pszUser);
  49. // Return it to the caller as an opaque handle.
  50. *phAccount = (HANDLE)info;
  51. // If the info doesn't exist, it's not an error; it just means account
  52. // lockout is disabled.
  53. return info && info->isLockedOut() ? TRUE : FALSE;
  54. }
  55. VOID
  56. WINAPI
  57. AccountLockoutUpdatePass(
  58. IN HANDLE hAccount
  59. )
  60. {
  61. if (hAccount)
  62. {
  63. // The logon succeeded, so reset the lockout count.
  64. ((AccountInfo*)hAccount)->reset();
  65. }
  66. }
  67. VOID
  68. WINAPI
  69. AccountLockoutUpdateFail(
  70. IN HANDLE hAccount
  71. )
  72. {
  73. if (hAccount)
  74. {
  75. IASTraceString("Authentication failed; incrementing lockout count.");
  76. AccountInfo* info = (AccountInfo*)hAccount;
  77. // Is this the first denial ?
  78. if (info->isClean())
  79. {
  80. IASTraceString("Validating account name for new entry.");
  81. // Yes, so make sure it's a valid account. We don't want to create a
  82. // lot of registry keys for bogus accounts.
  83. DWORD status = IASValidateUserName(
  84. info->getUserName(),
  85. info->getDomain()
  86. );
  87. if (status != NO_ERROR)
  88. {
  89. IASTraceFailure("IASValidateUserName", status);
  90. return;
  91. }
  92. IASTraceString("Account name is valid.");
  93. }
  94. // Bump up the denial count.
  95. info->incrementDenials();
  96. }
  97. }
  98. VOID
  99. WINAPI
  100. AccountLockoutClose(
  101. IN HANDLE hAccount
  102. )
  103. {
  104. AccountInfo::close((AccountInfo*)hAccount);
  105. }