涵盖/隐含的权限(数据库引擎)
在 SQL Server 权限层次结构中,授予特定的权限可能隐含包括其他权限。高级权限可以描述为“涵盖”它们所“隐含”的更详细的低级权限。
dbo.ImplyingPermissions
下面的示例脚本将安全对象的类名称和权限的名称作为其参数。此示例遍历权限层次结构,从指定的节点到服务器中的根目录:CONTROL SERVER。此示例产生包含指定隐含权限的权限列表。
CREATE FUNCTION dbo.ImplyingPermissions (@class nvarchar(64),
@permname nvarchar(64))
RETURNS @ImplPerms table (permname nvarchar(64),
class nvarchar(64), height int, rank int)
AS
BEGIN
WITH
class_hierarchy(class_desc, parent_class_desc)
AS
(
SELECT DISTINCT class_desc, parent_class_desc
FROM sys.fn_builtin_permissions('')
),
PermT(class_desc, permission_name, covering_permission_name,
parent_covering_permission_name, parent_class_desc)
AS
(
SELECT class_desc, permission_name, covering_permission_name,
parent_covering_permission_name, parent_class_desc
FROM sys.fn_builtin_permissions('')
),
permission_covers(permission_name, class_desc, level,
inserted_as)
AS
(
SELECT permission_name, class_desc, 0, 0
FROM PermT
WHERE permission_name = @permname AND
class_desc = @class
UNION ALL
SELECT covering_permission_name, class_desc, 0, 1
FROM PermT
WHERE class_desc = @class AND
permission_name = @permname AND
len(covering_permission_name) > 0
UNION ALL
SELECT PermT.covering_permission_name,
PermT.class_desc, permission_covers.level,
permission_covers.inserted_as + 1
FROM PermT, permission_covers WHERE
permission_covers.permission_name =
PermT.permission_name AND
permission_covers.class_desc = PermT.class_desc
AND len(PermT.covering_permission_name) > 0
UNION ALL
SELECT PermT.parent_covering_permission_name,
PermT.parent_class_desc,
permission_covers.level + 1,
permission_covers.inserted_as + 1
FROM PermT, permission_covers, class_hierarchy
WHERE permission_covers.permission_name =
PermT.permission_name AND
permission_covers.class_desc = PermT.class_desc
AND permission_covers.class_desc = class_hierarchy.class_desc
AND class_hierarchy.parent_class_desc =
PermT.parent_class_desc AND
len(PermT.parent_covering_permission_name) > 0
)
INSERT @ImplPerms
SELECT DISTINCT permission_name, class_desc,
level, max(inserted_as) AS mia
FROM permission_covers
GROUP BY class_desc, permission_name, level
ORDER BY level, mia
RETURN
END
A. 列出隐含对架构的 ALTER 权限的权限
SELECT * FROM dbo.ImplyingPermissions('schema', 'alter')
B. 列出隐含对对象的 VIEW DEFINITION 权限的权限
SELECT * FROM dbo.ImplyingPermissions('object', 'view definition')
C. 列出隐含对路由的 TAKE OWNERSHIP 权限的权限
SELECT * FROM dbo.ImplyingPermissions('route', 'take ownership')
D. 列出隐含对 XML 架构集合的 EXECUTE 权限的权限
SELECT * FROM dbo.ImplyingPermissions('xml schema collection', 'execute')