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.

236 lines
14 KiB

  1. USE Winlogon
  2. DECLARE @bSendmail bit
  3. SET @bSendmail = 1
  4. DECLARE @SCARD_W_WRONG_CHV bigint
  5. SET @SCARD_W_WRONG_CHV = -2146434965
  6. DECLARE @stMessageBody AS nvarchar(4000), @stMessageBody1 nvarchar(4000)
  7. SET @stMessageBody = ""
  8. SET @stMessageBody1 = ""
  9. DECLARE @crlf nvarchar(2)
  10. SET @crlf = CHAR(13) + CHAR(10)
  11. DECLARE @Buffer nvarchar(256), @Number nvarchar(5), @Percent nvarchar(3)
  12. DECLARE @Checkdate datetime
  13. SET @Checkdate = DATEADD(day, -8, GETDATE())
  14. --SET @Checkdate = DATEADD(day, -2, GETDATE())
  15. SELECT CARD
  16. FROM AuthMonitor
  17. WHERE TIMESTAMP > @Checkdate
  18. AND CARD <> ""
  19. DECLARE @NumCardAuth int
  20. SET @NumCardAuth = @@ROWCOUNT
  21. --
  22. -- Get number of reader / card operations
  23. --
  24. CREATE TABLE #CardReaderAuth
  25. (
  26. CARD nvarchar(64),
  27. READER nvarchar(64),
  28. FAILURE int,
  29. NUMBER int
  30. )
  31. DECLARE @iCardHandle int, @stCard nvarchar(64)
  32. SET @iCardHandle = 0
  33. EXEC #GetCard @stCard OUTPUT, @iCardHandle OUTPUT
  34. WHILE @stCard <> ""
  35. BEGIN
  36. DECLARE @iReaderHandle int, @stReader nvarchar(64)
  37. SET @iReaderHandle = 0
  38. EXEC #GetReader @stReader OUTPUT, @iReaderHandle OUTPUT
  39. WHILE @stReader <> ""
  40. BEGIN
  41. -- Get number of total operations
  42. SELECT CARD, READER
  43. FROM AuthMonitor
  44. WHERE TIMESTAMP > @Checkdate
  45. AND CARD = @stCard
  46. AND READER LIKE @stReader + "%"
  47. INSERT INTO #CardReaderAuth VALUES (@stCard, @stReader, 0, @@ROWCOUNT)
  48. -- Get number of failures
  49. SELECT CARD, READER
  50. FROM AuthMonitor
  51. WHERE TIMESTAMP > @Checkdate
  52. AND CARD = @stCard
  53. AND READER LIKE @stReader + "%"
  54. AND STATUS <> 0
  55. AND STATUS <> @SCARD_W_WRONG_CHV
  56. INSERT INTO #CardReaderAuth VALUES (@stCard, @stReader, 1, @@ROWCOUNT)
  57. EXEC #GetReader @stReader OUTPUT, @iReaderHandle OUTPUT
  58. END
  59. EXEC #GetCard @stCard OUTPUT, @iCardHandle OUTPUT
  60. END
  61. --
  62. -- Create the message for Card / Reader authentications and failures
  63. --
  64. DECLARE CardReaderCursor CURSOR FOR
  65. SELECT CARD, READER, FAILURE, NUMBER
  66. FROM #CardReaderAuth
  67. ORDER BY READER ASC, CARD ASC
  68. DECLARE @iNumPerCardReaderAuth int, @NumPerCardReaderFailures int
  69. SET @iNumPerCardReaderAuth = -1
  70. SET @NumPerCardReaderFailures = -1
  71. DECLARE @LastReader nvarchar(64)
  72. SET @LastReader = ""
  73. DECLARE @NumAuth int, @Failure int
  74. OPEN CardReaderCursor
  75. FETCH NEXT FROM CardReaderCursor
  76. INTO @stCard, @stReader, @Failure, @NumAuth
  77. WHILE @@FETCH_STATUS = 0
  78. BEGIN
  79. IF @Failure = 0
  80. SET @iNumPerCardReaderAuth = @NumAuth
  81. ELSE
  82. SET @NumPerCardReaderFailures = @NumAuth
  83. IF @iNumPerCardReaderAuth <> -1 AND @NumPerCardReaderFailures <> -1
  84. BEGIN
  85. DECLARE TimerCursor CURSOR FOR
  86. SELECT STOPWATCH, STATUS
  87. FROM AuthMonitor
  88. WHERE TIMESTAMP > @Checkdate
  89. AND CARD = @stCard
  90. AND READER LIKE @stReader + "%"
  91. AND STATUS <> @SCARD_W_WRONG_CHV
  92. DECLARE @iStopwatch int, @iStatus int
  93. OPEN TimerCursor
  94. FETCH NEXT FROM TimerCursor
  95. INTO @iStopwatch, @iStatus
  96. DECLARE @iAverageSuccess int, @iNumSuccess int
  97. DECLARE @iAverageFailure int, @iNumFailure int
  98. SET @iAverageSuccess = 0
  99. SET @iNumSuccess = 0
  100. SET @iAverageFailure = 0
  101. SET @iNumFailure = 0
  102. WHILE @@FETCH_STATUS = 0
  103. BEGIN
  104. IF @iStatus = 0
  105. BEGIN
  106. SET @iAverageSuccess = @iAverageSuccess + @iStopwatch
  107. SET @iNumSuccess = @iNumSuccess + 1
  108. END
  109. ELSE
  110. BEGIN
  111. SET @iAverageFailure = @iAverageFailure + @iStopwatch
  112. SET @iNumFailure = @iNumFailure + 1
  113. END
  114. FETCH NEXT FROM TimerCursor
  115. INTO @iStopwatch, @iStatus
  116. END
  117. CLOSE TimerCursor
  118. DEALLOCATE TimerCursor
  119. IF @iNumPerCardReaderAuth <> 0
  120. BEGIN
  121. IF @stReader <> @LastReader
  122. BEGIN
  123. IF LEN(@stMessageBody) > 3000
  124. BEGIN
  125. SET @stMessageBody1 = @stMessageBody
  126. SET @stMessageBody = ""
  127. SET @LastReader = ""
  128. END
  129. IF @LastReader <> ""
  130. SET @stMessageBody = @stMessageBody + @crlf
  131. EXEC master.dbo.xp_sprintf @Buffer OUTPUT, "%-34s Total | Failures | Times", @stReader
  132. SET @stMessageBody = @stMessageBody + @Buffer + @crlf +
  133. REPLICATE("-", 70) + @crlf
  134. END
  135. SET @LastReader = @stReader
  136. -- Card / reader total
  137. SET @Number = CAST(@iNumPerCardReaderAuth AS nvarchar(5))
  138. SET @Percent = CAST(@iNumPerCardReaderAuth * 100 / @NumCardAuth AS nvarchar(3))
  139. EXEC master.dbo.xp_sprintf @Buffer OUTPUT, "� %-34s%5s%4s%%", @stCard, @Number, @Percent
  140. SET @stMessageBody = @stMessageBody + @Buffer
  141. -- Card / reader failures
  142. SET @Number = CAST(@NumPerCardReaderFailures AS nvarchar(5))
  143. SET @Percent = CAST(@NumPerCardReaderFailures * 100 / @iNumPerCardReaderAuth AS nvarchar(3))
  144. EXEC master.dbo.xp_sprintf @Buffer OUTPUT, " | %5s%4s%%", @Number, @Percent
  145. SET @stMessageBody = @stMessageBody + @Buffer
  146. -- Times
  147. DECLARE @stAverageSuccess nvarchar(5), @stAverageFailure nvarchar(5)
  148. IF @iNumSuccess <> 0
  149. SET @stAverageSuccess = CAST(@iAverageSuccess / @iNumSuccess / 1000 AS nvarchar(5))
  150. ELSE
  151. SET @stAverageSuccess = "-"
  152. IF @iNumFailure <> 0
  153. SET @stAverageFailure = CAST(@iAverageFailure / @iNumFailure / 1000 AS nvarchar(5))
  154. ELSE
  155. SET @stAverageFailure = "-"
  156. EXEC master.dbo.xp_sprintf @Buffer OUTPUT, " | %3s/%3s", @stAverageSuccess, @stAverageFailure
  157. SET @stMessageBody = @stMessageBody + @Buffer + @crlf
  158. END
  159. SET @iNumPerCardReaderAuth = -1
  160. SET @NumPerCardReaderFailures = -1
  161. END
  162. FETCH NEXT FROM CardReaderCursor
  163. INTO @stCard, @stReader, @Failure, @NumAuth
  164. END
  165. CLOSE CardReaderCursor
  166. DEALLOCATE CardReaderCursor
  167. IF @stMessageBody1 = ""
  168. BEGIN
  169. SET @stMessageBody1 = @stMessageBody
  170. SET @stMessageBody = ""
  171. END
  172. IF @bSendmail <> 0
  173. BEGIN
  174. EXEC master.dbo.xp_sendmail
  175. @recipients = 'smcaft',
  176. @message = @stMessageBody1,
  177. @subject = 'Smart card self host report - reader/card matrix'
  178. IF @stMessageBody <> ""
  179. EXEC master.dbo.xp_sendmail
  180. @recipients = 'smcaft',
  181. @message = @stMessageBody,
  182. @subject = 'Smart card self host report - reader/card matrix II'
  183. END
  184. ELSE
  185. BEGIN
  186. PRINT @stMessageBody1 + @crlf
  187. PRINT @stMessageBody
  188. END