<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Linchi Shea : Security</title><link>http://sqlblog.com/blogs/linchi_shea/archive/tags/Security/default.aspx</link><description>Tags: Security</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Performance impact: Linked server security configuration and how it can hurt you</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/07/21/performance-impact-linked-server-security-configuration-and-how-it-can-hurt-you.aspx</link><pubDate>Tue, 21 Jul 2009 17:16:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15387</guid><dc:creator>Linchi Shea</dc:creator><slash:comments>22</slash:comments><comments>http://sqlblog.com/blogs/linchi_shea/comments/15387.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/linchi_shea/commentrss.aspx?PostID=15387</wfw:commentRss><description>If you change the security configuration of a linked server from using login UserA to login UserB, would you expect that to significantly impact the performance of a query that uses the linked server, assuming that both users have permission to select...(&lt;a href="http://sqlblog.com/blogs/linchi_shea/archive/2009/07/21/performance-impact-linked-server-security-configuration-and-how-it-can-hurt-you.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=15387" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Distributed+join/default.aspx">Distributed join</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Distributed+query/default.aspx">Distributed query</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Linked+server/default.aspx">Linked server</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Performance/default.aspx">Performance</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Query+Processing/default.aspx">Query Processing</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Security/default.aspx">Security</category></item><item><title>How does that AD user account get access to the database?</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/03/26/how-does-that-ad-user-account-get-access-to-the-database.aspx</link><pubDate>Thu, 26 Mar 2009 05:19:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:12927</guid><dc:creator>Linchi Shea</dc:creator><slash:comments>8</slash:comments><comments>http://sqlblog.com/blogs/linchi_shea/comments/12927.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/linchi_shea/commentrss.aspx?PostID=12927</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Granting Active Directory (AD) groups access to a database can quickly become complex when the AD groups&amp;nbsp;may nest many levels. Consider the following scenario: &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0.5in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;You are requested to give Joe the same access to a database as John has. You look up John in the database, and find no trace of John. You then find a bunch of AD groups have been granted access to the database. Obviously, John is getting his access to the database through one or more of these AD groups. But exactly how does John get his access via the AD groups? In other words, what are the AD groups through which John gets his database access?&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;How would you approach this request? You can fire up the AD Users &amp;amp; Computers management console, look up the user account for John, find all the AD groups John is a member of, and then for each such group, recursively find all the groups this group is a member of. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Unfortunately, that is a labor intensive process.&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="Times New Roman" size=3&gt;There is a better way. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;First, note that you can&amp;nbsp;use two AD utilities, DSquery and DSget, to recursively retrieve all the groups that John is a member of--either directly or indirectly--in a single line of command as follows:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;FONT face="Times New Roman" size=3&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;cmd&amp;gt;dsquery user -samid John | dsget user -memberof -expand | findstr OU=Groups&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&lt;/FONT&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;In addition, you can run the following SQL query to find what AD groups have been granted access to the database:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;select s1.name &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;from syslogins s1 &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;join &amp;lt;your database&amp;gt;..sysusers s2 on s1.sid = s2.sid &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;and s2.hasdbaccess = 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;where s1.isntgroup = 1 and s1.hasaccess = 1 and s1.sysadmin = 0&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;order by s1.name;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;/FONT&gt;&lt;/o:p&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Now, if you compare these two&amp;nbsp;results of the AD groups, and the ones that are common in both&amp;nbsp;results are the AD groups through which John gains access to the database.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;So far, all this work is still manual and labor intensive. But it’s not difficult to automate all the steps in a script. The following is a throw-away Perl script I wrote to do precisely that:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE:11pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman"&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;use strict;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;my ($user_account, $server, $database) = (shift, shift, shift);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;my $domain = 'NYD';&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;# domain name hardcoded. Change it, if necessary&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;my @groups = `dsquery user -samid $user_account | dsget user -memberof -expand | findstr OU=Groups`;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;my @ADGroups;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;# Extract the AD group names and prefix them with the domain name&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;foreach my $group (@groups)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;if ($group =~ /\"CN=([^,]+)\,/)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;@ADGroups = (@ADGroups, uc("$domain\\$1"));&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;my $sql = q/set nocount on;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;select s1.name &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;from syslogins s1 join $database..sysusers s2 &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;on s1.sid = s2.sid and s2.hasdbaccess = 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;where s1.isntgroup = 1 and s1.hasaccess = 1 and s1.sysadmin = 0&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;order by s1.name;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;/;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;my $rc = `osql -S$server -E -n -h-1 -w200 -Q\"$sql\"`;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;$rc =~ s/^\s*//;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;$rc =~ s/\s*$//;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;my @login_nt_groups = split /\s*\n\s*/, $rc;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;my @LoginGroups;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;foreach my $nt_group (sort {uc($a) cmp uc($b)} @login_nt_groups)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;@LoginGroups = (@LoginGroups, uc($nt_group));&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;foreach my $group (getSetCommon([@ADGroups], [@LoginGroups]))&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;print "** $group\n";&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;sub getSetCommon {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;my($setRef1, $setRef2) = @_;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;my %temp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;my %common;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;grep($temp{$_}++, @$setRef2);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;map {$temp{$_} and $common{$_}++} @$setRef1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;keys %common;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#b3b3b3;MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier New';"&gt;} &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;SPAN style="FONT-SIZE:11pt;"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The script takes three command-line parameters: the name of the AD user account (e.g. John in our case), the SQL instance name, and the database name. It retrieves all the AD groups that the user account is in (directly or recursively), retrieves the AD groups that have been granted access to the database, and the find the AD groups that are in both.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;FONT face="Times New Roman" size=3&gt;This is a quick and dirty approach that seems to work well so far. If you have a better approach, please share with us. Powershell solutions are welcome&amp;nbsp;as well.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=12927" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Scripts/default.aspx">Scripts</category><category domain="http://sqlblog.com/blogs/linchi_shea/archive/tags/Security/default.aspx">Security</category></item></channel></rss>