sp_SrvPermissions & sp_DBPermissions V4.0

Leave a comment

January 15, 2014 by Kenneth Fisher

These are a couple of stored procedures I wrote to help me with security research. Each sp returns three data sets.

  1. A list of principals and some basic properties about them.
  2. Role membership
  3. Object/Database/Server level permissions

Each row of each dataset has not only the appropriate properties but a set of do/undo scripts. For example a script to add someone to a role, or remove them for a role, grant them a permission, revoke the permission from them.

Last but not least each sp has a number of parameters for restricting the result sets. For example principal name, role name, principal type, object name etc.

These sp’s can be run/stored anywhere and work just fine but if you run them in master then you can call them from any database on the instance.

Examples of times I’ve found them handy:

  • I need to know every database a user has access to and what access they have.
  • I need to know all permissions for a given user.
  • I need to copy a login from one server to another (with SID and password).
  • I need to know everyone who has permissions to a specific object in the database.
  • I need to know everyone who is a member of sysadmin.

Latest update: Below are the latest additions. My personal favorite is the new ALL option for the DBName parameter. And of course if you happen to notice a problem, or have a suggestion please post them here and I’ll be glad to fix/add as appropriate.

— 11/18/2013 – Corrected bug in the order of the parameters for sp_addsrvrolemember
and sp_dropsrvrolemember, also added parameter names both.
— 01/09/2014 – Added an ORDER BY to each of the result sets. See above for details.

— 11/18/2013 – Added parameter names to sp_addrolemember and sp_droprolemember.
— 11/19/2013 – Added an ORDER BY to each of the result sets. See above for details.
— 01/04/2014 – Add an ALL option to the DBName parameter.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 3,755 other subscribers

Follow me on Twitter

ToadWorld Pro of the Month November 2013
%d bloggers like this: