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.

108 lines
4.9 KiB

  1. USE Winlogon
  2. DECLARE @Sendmail int
  3. SET @Sendmail = 1
  4. DECLARE @crlf nvarchar(2)
  5. SET @crlf = CHAR(13) + CHAR(10)
  6. DECLARE @Checkdate datetime
  7. SET @Checkdate = DATEADD(day, -8, GETDATE())
  8. CREATE TABLE #Logons
  9. (
  10. USERNAME nvarchar(32),
  11. TOTAL int,
  12. FAILURE int
  13. )
  14. DECLARE @TotalNum int, @FailureNum int, @iSuccess int
  15. DECLARE @Username nvarchar(32), @Machinename nvarchar(32), @Userlist as nvarchar(4000)
  16. DECLARE @Buffer nvarchar(256), @Total nvarchar(5), @Failures nvarchar(5)
  17. SET @Userlist = "Smart Card Authentications Total | Failures" + @crlf +
  18. REPLICATE("-", 46) + @crlf
  19. DECLARE UserCursor CURSOR FOR
  20. SELECT DISTINCT USERNAME
  21. FROM AuthMonitor
  22. WHERE TIMESTAMP > @Checkdate
  23. AND CARD <> ""
  24. ORDER BY USERNAME ASC
  25. OPEN UserCursor
  26. FETCH NEXT FROM UserCursor
  27. INTO @Username
  28. WHILE @@FETCH_STATUS = 0
  29. BEGIN
  30. SET @Machinename = RTRIM(@Username) + "%"
  31. SELECT MACHINENAME, CARD, STATUS
  32. FROM AuthMonitor
  33. WHERE TIMESTAMP > @Checkdate
  34. AND CARD <> ""
  35. AND MACHINENAME LIKE @Machinename
  36. AND STATUS <> 0
  37. SET @FailureNum = @@ROWCOUNT
  38. SELECT USERNAME
  39. FROM AuthMonitor
  40. WHERE TIMESTAMP > @Checkdate
  41. AND CARD <> ""
  42. AND USERNAME = @Username
  43. AND STATUS = 0
  44. SET @iSuccess = @@ROWCOUNT
  45. INSERT INTO #Logons VALUES (@Username, @iSuccess + @FailureNum, @FailureNum)
  46. FETCH NEXT FROM UserCursor
  47. INTO @Username
  48. END
  49. CLOSE UserCursor
  50. DEALLOCATE UserCursor
  51. DECLARE UserCursor CURSOR FOR
  52. SELECT USERNAME, TOTAL, FAILURE
  53. FROM #Logons
  54. ORDER BY TOTAL DESC
  55. OPEN UserCursor
  56. FETCH NEXT FROM UserCursor
  57. INTO @Username, @TotalNum, @FailureNum
  58. WHILE @@FETCH_STATUS = 0
  59. BEGIN
  60. SET @Total = CAST(@TotalNum AS nvarchar(5))
  61. SET @Failures = CAST(@FailureNum AS nvarchar(5))
  62. SET @Username = RTRIM(@Username)
  63. IF @Username <> "" AND @Total <> 0
  64. BEGIN
  65. EXEC master.dbo.xp_sprintf @Buffer OUTPUT, "%-29s%5s | %5s", @Username, @Total, @Failures
  66. SET @Userlist = @Userlist + @Buffer + @crlf
  67. END
  68. FETCH NEXT FROM UserCursor
  69. INTO @Username, @TotalNum, @FailureNum
  70. END
  71. CLOSE UserCursor
  72. DEALLOCATE UserCursor
  73. --
  74. -- Send mail
  75. --
  76. IF @Sendmail <> 0
  77. EXEC master.dbo.xp_sendmail
  78. @recipients = 'smcaft',
  79. @message = @Userlist,
  80. @subject = 'Smart card self host report - Authentications per user'
  81. ELSE
  82. PRINT @Userlist
  83. GO