涵蓋/隱含權限 (Database Engine)
在 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')