像SSMS一样获取Linked Servers的安全配置

时间:2016-02-03 04:47:32

标签: sql-server linked-server

我需要查询链接服务器列表并确保它们都具有安全设置。对于未在上面列表中定义的登录,连接将:'不是女佣' (第一个无线电选项)。

1 个答案:

答案 0 :(得分:0)

事实恰恰相反,每个选项都是多个领域的扭曲组合。

-- Representation of Linked Server GUI
-- {3} represent the third option on the GUI:Be made using the login's current security context
-- This way you can filter out some configuration that are considered too loose security wise.

use master
go
select l.server_id, s.name
    , case 
        when l.uses_self_credential = 0 and p.name is not null          then 'top: Local server login to remote server login mapping'
        when l.uses_self_credential = 1 and p.name is not null          then 'top: Local server login to impersonate'
        when l.uses_self_credential = 0 and l.remote_name = ''          then '{2} Be made without using a security context'
        when l.uses_self_credential = 1 and l.remote_name is null       then '{3} Be made using the login''s current security context'
        when l.uses_self_credential = 0 and l.remote_name is not null   then '{4} Be made using this security context'
      end as detail
    , l.uses_self_credential, p.name as local_name, l.remote_name, l.modify_date
    from sys.linked_logins l
    join sys.servers s on s.server_id = l.server_id
    left join sys.server_principals p on p.principal_id = l.local_principal_id
union all
    select server_id, name, '{1} Not be made',0 ,null , null, null
    from sys.servers
    where server_id not in(select server_id from sys.linked_logins where local_principal_id = 0)
order by name