Skip to content

Commit 1c7e81b

Browse files
authored
Merge pull request #2393 from jeffchulg/dev
Addresses issue #2387
2 parents 871954f + a6abeaa commit 1c7e81b

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

Documentation/sp_Blitz_Checks_by_Priority.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ If you want to add a new one, start at 235.
278278
| 230 | Security | SQL Agent Job Runs at Startup | https://www.BrentOzar.com/go/startup | 57 |
279279
| 230 | Security | Stored Procedure Runs at Startup | https://www.BrentOzar.com/go/startup | 7 |
280280
| 230 | Security | Sysadmins | https://www.BrentOzar.com/go/sa | 4 |
281+
| 230 | Security | Invalid Active Directory Accounts | | 2301|
281282
| 240 | Wait Stats | No Significant Waits Detected | https://www.BrentOzar.com/go/waits | 153 |
282283
| 240 | Wait Stats | Top Wait Stats | https://www.BrentOzar.com/go/waits | 152 |
283284
| 240 | Wait Stats | Wait Stats Have Been Cleared | https://www.BrentOzar.com/go/waits | 185 |

sp_Blitz.sql

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,16 @@ AS
320320
);
321321
CREATE CLUSTERED INDEX IX_CheckID_DatabaseName ON #SkipChecks(CheckID, DatabaseName);
322322

323+
IF(OBJECT_ID('tempdb..#InvalidLogins') IS NOT NULL)
324+
BEGIN
325+
EXEC sp_executesql N'DROP TABLE #InvalidLogins;';
326+
END;
327+
328+
CREATE TABLE #InvalidLogins (
329+
LoginSID varbinary(85),
330+
LoginName VARCHAR(256)
331+
);
332+
323333
IF @SkipChecksTable IS NOT NULL
324334
AND @SkipChecksSchema IS NOT NULL
325335
AND @SkipChecksDatabase IS NOT NULL
@@ -1297,7 +1307,35 @@ AS
12971307
AND l.name <> 'l_certSignSmDetach'; /* Added in SQL 2016 */
12981308
END;
12991309

1300-
IF NOT EXISTS ( SELECT 1
1310+
IF NOT EXISTS ( SELECT 1
1311+
FROM #SkipChecks
1312+
WHERE CheckID = 2301 )
1313+
BEGIN
1314+
1315+
IF @Debug IN (1, 2) RAISERROR('Running CheckId [%d].', 0, 1, 2301) WITH NOWAIT;
1316+
1317+
INSERT INTO #InvalidLogins
1318+
EXEC sp_validatelogins
1319+
;
1320+
1321+
INSERT INTO #BlitzResults
1322+
( CheckID ,
1323+
Priority ,
1324+
FindingsGroup ,
1325+
Finding ,
1326+
URL ,
1327+
Details
1328+
)
1329+
SELECT 2301 AS CheckID ,
1330+
230 AS Priority ,
1331+
'Security' AS FindingsGroup ,
1332+
'Invalid login defined with Windows Authentication' AS Finding ,
1333+
'https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-validatelogins-transact-sql' AS URL ,
1334+
( 'Windows user or group ' + QUOTENAME(LoginName) + ' is mapped to a SQL Server principal but no longer exists in the Windows environment.') AS Details
1335+
FROM #InvalidLogins
1336+
;
1337+
END;
1338+
IF NOT EXISTS ( SELECT 1
13011339
FROM #SkipChecks
13021340
WHERE DatabaseName IS NULL AND CheckID = 5 )
13031341
BEGIN
@@ -9144,6 +9182,15 @@ IF @ProductVersionMajor >= 10 AND NOT EXISTS ( SELECT 1
91449182

91459183
END; /* ELSE -- IF @OutputType = 'SCHEMA' */
91469184

9185+
/*
9186+
Cleanups - drop temporary tables that have been created by this SP.
9187+
*/
9188+
9189+
IF(OBJECT_ID('tempdb..#InvalidLogins') IS NOT NULL)
9190+
BEGIN
9191+
EXEC sp_executesql N'DROP TABLE #InvalidLogins;';
9192+
END;
9193+
91479194
/*
91489195
Reset the Nmumeric_RoundAbort session state back to enabled if it was disabled earlier.
91499196
See Github issue #2302 for more info.

0 commit comments

Comments
 (0)