本文大部分内容翻译自Sybase官方文档,原文:
sp_helprotect
描述(Description)
返回一个包含权限信息的报表,查询对象可以为:数据库对象,用户,用户组,角色。
语法(Syntax)
sp_helprotect [name[, username[, "grant"
[,"none" | "granted" | "enabled" | role_name[, permission_name]]]]]
参数(Parameters)
name
name 是当前数据库中的表、视图、存储过程、SQLJ存储过程、SQLJ函数、用户定义函数、用户名、角色、用户定义角色或组的名称。如果您不提供姓名,sp_helprotect 将报告在数据库中的所有权限。
username
username 是当前数据库中的用户,组或角色的名称。 如果未使用name,Adaptive Server 将生成空的报表。
grant
显示使用 grant 选项授予 name 到 username 的权限。 如果 username 为 null,则 sp_helprotect 将列出使用 grant 选项授予的所有权限。
none
包括在确定授予权限时授予用户的所有角色的信息。
enabled
包括用户在确定授予权限时激活的所有角色的信息。
role_name
列出通过 role_name 授予的权限。
permission_name
允许 sp_helprotect 为给定数据库中授予的任何特定权限提供信息(授予者名称,被授予者名称,表/列名称,可授予性)。
此参数的值可以是 sysprotects.action 列中的任何值。
示例(Examples)
示例1
以下的对 titles 表执行一系列 grant 和 revoke 语句,并执行 sp_helprotect titles,结果显示如下:
grant select on titles to judy
grant update on titles to judy
revoke update on titles(price) from judy
grant select on publishers to judy
with grant option
go
sp_helprotect titles
grantor grantee type action object column grantable ------- ------ ----- ------ ------ ------ --------- dbo judy Grant Select titles All FALSE dbo judy Grant Update titles advance FALSE dbo judy Grant Update titles notes FALSE dbo judy Grant Update titles pub_id FALSE dbo judy Grant Update titles pubdate FALSE dbo judy Grant Update titles title FALSE dbo judy Grant Update titles title_id FALSE dbo judy Grant Update titles total_sales FALSE dbo judy Grant Update titles type FALSE dbo judy Grant Select publishers all TRUE
示例2
执行以下 grant 语句会导致 sp_helprotect 显示以下内容:
grant select on titles to judy
grant update on titles to judy
revoke update on titles(price) from judy
grant select on publishers to judy
with grant option
go
sp_helprotect titles
grantor grantee type action object column grantable ------- ------- ------ ------- ------ ------ --------- dbo mary Grant Select titles advance TRUE dbo mary Grant Select titles price TRUE dbo mary Grant Update titles advance TRUE dbo mary Grant Update titles price TRUE
示例3
显示 “judy” 在数据库中拥有的所有权限:
sp_helprotect judy
示例4
显示 “csmith” 在 sysusers 表上具有的任何权限,以及 “csmith” 是否具有 grant 选项,允许 “csmith” 向其他用户授予权限:
sp_helprotect sysusers, csmith, "grant"
grantor grantee type action object column grantable ----------------------------------------------------------------- dbo doctor Grant Delete sysusers All FALSE dbo doctor Grant Insert sysusers All FALSE dbo doctor Grant References sysusers All FALSE dbo doctor Grant Select sysattributes All FALSE (1 row affected) (return status = 0)
示例5
显示 “doctor” 角色在数据库中的权限信息:
sp_helprotect doctor
grantor grantee type action object column grantable ----------------------------------------------------------------- dbo doctor Grant Delete sysusers All FALSE dbo doctor Grant Insert sysusers All FALSE dbo doctor Grant References sysusers All FALSE dbo doctor Grant Select sysattributes All FALSE (1 row affected) (return status = 0)
示例6
显示授予 “csmith” 的所有角色的信息:
sp_helprotect csmith, null, null, "granted"
grantor grantee type action object column grantable ----------------------------------------------------------------- dbo csmith Grant Update sysusers All FALSE dbo doctor Grant Delete sysusers All FALSE dbo doctor Grant Insert sysusers All FALSE dbo doctor Grant References sysusers All FALSE (1 row affected) (return status = 0)
示例7
显示授予 “rpillai” 的所有活动角色的信息:
sp_helprotect rpillai, null, null, "enabled"
grantor grantee type action object column grantable --------------- ----------------------------------------------- dbo public Grant Select sysattributes All FALSE (1 row affected) (return status = 0)
示例8
建议 SQLJ函数 的访问权限是公共:
sp_helprotect function_sqlj
Implicit grant to public for SQLJ functions.
示例9
使用 sysprotects.action 中的 “Decrypt” 操作:
sp_helprotect @permission_name = "Decrypt"
grantor grantee type action object column grantable ------- -------- ----- ------- ------- ------ --------- sa1 hr_login Grant Decrypt employee ssn TRUE sa1 hr_role Grant Decrypt employee ssn FALSE
用法注意事项(Usage)
- sp_helprotect 报告数据库对象的权限。如果提供 username 参数,则仅报告该用户对数据库对象的权限。如果 name 不是对象,则 sp_helprotect 将检查它是用户,组,角色还是权限名称。如果是其中之一,则 sp_helprotect 列出用户,组或角色的权限。
- sp_helprotect 仅查找当前数据库中的对象和用户。
- 如果未指定可选值(如granted,enabled,none 或 role_name),Adaptive Server 将返回有关当前指定用户激活的所有角色的信息。
- 如果指定的用户不是当前用户,Adaptive Server 将返回有关授予指定用户的所有角色的信息。
- 显示的信息始终包括授予指定用户所属组的权限。
- 在授予权限时,系统管理员将被视为对象所有者。如果系统管理员授予其他用户对象的权限,则所有者的名称将在sp_helprotect 输出中显示为授予者。
使用范围(Permissions)
任何用户都可以执行 sp_helprotect 来查看自己的权限。 只有 SSO(系统安全员角色) 才能查看所有用户的权限。
-------------------------------------------------------------------
原官方文档地址:
如有翻译不当,欢迎指出~