windows-nt/Source/XPSP1/NT/ds/security/gina/msgina/sqlscripts/deployment.sql
2020-09-26 16:20:57 +08:00

95 lines
4.6 KiB
Transact-SQL
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

USE Winlogon
DECLARE @bSendmail bit
SET @bSendmail = 1
DECLARE @SCARD_W_WRONG_CHV bigint
SET @SCARD_W_WRONG_CHV = -2146434965
DECLARE @crlf nvarchar(2)
SET @crlf = CHAR(13) + CHAR(10)
DECLARE @MessageBody nvarchar(4000)
SET @MessageBody = ""
DECLARE @Buffer nvarchar(256), @Number nvarchar(5), @Percent nvarchar(3)
DECLARE @Checkdate datetime
SET @Checkdate = DATEADD(day, -8, GETDATE())
-- SET @Checkdate = DATEADD(day, -1, GETDATE())
--
-- Get number of deployed readers
--
DECLARE @ReaderNumbers nvarchar(1000)
SET @ReaderNumbers = "Deployed readers" + @crlf +
REPLICATE("-", 45) + @crlf
DECLARE @iReaderHandle int, @stReader nvarchar(64)
SET @iReaderHandle = 0
EXEC #GetReader @stReader OUTPUT, @iReaderHandle OUTPUT
WHILE @stReader <> ""
BEGIN
SELECT DISTINCT READER, MACHINENAME
FROM AuthMonitor
WHERE TIMESTAMP > @Checkdate
AND READER LIKE @stReader + "%"
SET @Number = CAST(@@ROWCOUNT AS nvarchar(5))
IF @Number <> 0
BEGIN
EXEC master.dbo.xp_sprintf @Buffer OUTPUT, "  %-34s%5s", @stReader, @Number
SET @ReaderNumbers =
@ReaderNumbers + @Buffer + @crlf
END
EXEC #GetReader @stReader OUTPUT, @iReaderHandle OUTPUT
END
--
-- Get number of deployed cards
--
DECLARE @CardNumbers nvarchar(1000)
SET @CardNumbers = "Deployed smart cards" + @crlf +
REPLICATE("-", 45) + @crlf
DECLARE @iCardHandle int, @stCard nvarchar(64)
SET @iCardHandle = 0
EXEC #GetCard @stCard OUTPUT, @iCardHandle OUTPUT
WHILE @stCard <> ""
BEGIN
SELECT DISTINCT CARD, USERNAME
FROM AuthMonitor
WHERE TIMESTAMP > @Checkdate
AND CARD = @stCard
SET @Number = CAST(@@ROWCOUNT AS nvarchar(5))
IF @Number <> 0
BEGIN
EXEC master.dbo.xp_sprintf @Buffer OUTPUT, "  %-34s%5s", @stCard, @Number
SET @CardNumbers =
@CardNumbers + @Buffer + @crlf
END
EXEC #GetCard @stCard OUTPUT, @iCardHandle OUTPUT
END
--
-- Send mail
--
SET @MessageBody = @ReaderNumbers + @crlf +
@CardNumbers
IF @bSendmail <> 0
EXEC master.dbo.xp_sendmail
@recipients = 'smcaft',
@message = @MessageBody,
@subject = 'Smart card self host report - deployment data'
ELSE
PRINT @MessageBody
GO