Solved

sp_MSdbuserpriv

Posted on 2010-08-20
4
1,263 Views
Last Modified: 2012-05-10
what is meaning of the following SP:
exec master.dbo.sp_MSdbuserpriv 'serv123456789012345678901234567890'

as long as the paramter starts with 'serv' and it does not care about the rest of the details in the string. what value does the above return for you and how do you interpret it?

thanks
0
Comment
Question by:anushahanna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 167 total points
ID: 33490259
use master
exec sp_Helptext sp_MSdbuserpriv

defaults to 'perm' if @mode not supplied
checks for 'serv','role','ver'

Everything else after these text are ignored.

It returns 7 to me, because I am a sysadmin.
The possible returns for 'serv' are

7 - sysadmin or user in sysadmin role
2 - has create database permission
4 - has permission to sp_addextendedproc
6 - both 2 & 4
0
 
LVL 51

Assisted Solution

by:Mark Wills
Mark Wills earned 333 total points
ID: 33491852
Well, it has been around for quite some time. One of those cute undocumented stored procedures. This one is for privileges - ie db permissions and roles basically. The actual code is below as extracted from SQL server... Not unsurprising is a newer function : fn_my_permissions()

As mentioned above, it has one parameter @mode and returns a status based on permissions() and is_srvrolemember()  (and a couple of combinations or server properties etc).

If you look for permissions function in Books Online you will see what the bitmaps represent : http://technet.microsoft.com/en-us/library/ms186915.aspx

The mode is one of 'perm%', 'role%', 'ver%', or 'serv%'. And call it like :  EXEC sp_MSdbuserpriv @mode = 'ver'



create proc sys.sp_MSdbuserpriv   @mode nvarchar(10) = N'perm'  
as    
/* Order of privilege evaluation is:  user granted/revoked, then group granted/revoked, then public granted/revoked */ 
     set nocount on
     declare @bits int, @status int, @prot int, @perms int
     declare @dbrole int, @dbrolestr nvarchar(12)
     /* If 'srv', we're selecting the server (master db) user profile - currently, just create db priv. */
     if (lower(@mode) like N'serv%')
        begin
        select @bits = 0x0000
        if (user_id() = 1 or is_srvrolemember(N'sysadmin') = 1 or is_member(N'db_owner') = 1)
           begin
           /* sa has everything */
           select @bits = 0x0007
           end
        else begin
           if ((PERMISSIONS() & 1) > 0)
              SELECT @bits = @bits | 0x0002
           if ((PERMISSIONS(OBJECT_ID(N'sp_addextendedproc')) & 32) > 0)
              SELECT @bits = @bits | 0x0004
           end
        select @bits
        return 0
        end
       /* If 'perm', we're selecting the current database priv and role membership for the login user. */
   if (lower(@mode) like N'role%' or lower(@mode) like N'ver%' or lower(@mode) like N'perm%')
        begin
        if (user_id() = 1 or is_srvrolemember(N'sysadmin') = 1 or is_member(N'db_owner') = 1)
           begin
           /* sa/Dbo has everything. */
           select @bits = 0x03ff
           end
        else begin
           /* Not dbo so get individual privileges */
           select @bits = 0x0000, @perms = PERMISSIONS(), @status = status from dbo.sysusers where uid = user_id()
           if ((@perms & 2) > 0)
              SELECT @bits = @bits | 0x0002
           if ((@perms & 8) > 0)
              SELECT @bits = @bits | 0x0004
           if ((@perms & 4) > 0)
              SELECT @bits = @bits | 0x0008
           if ((@perms & 64) > 0)
              SELECT @bits = @bits | 0x0010
           if ((@perms & 32) > 0)
              SELECT @bits = @bits | 0x0020
           if ((@perms & 128) > 0)
              SELECT @bits = @bits | 0x0040
           if ((@perms & 16) > 0)
              SELECT @bits = @bits | 0x0080
           if ((@perms & 256) > 0)
              SELECT @bits = @bits | 0x0100
           if ((@perms & 512) > 0)
              SELECT @bits = @bits | 0x0200
           end
          /* Get both Server and Database Role information */
        select @dbrole = 0x0000
        /* Server Roles */
        select @dbrole = (case when (is_srvrolemember(N'dbcreator') = 1) then @dbrole | 0x0001 else @dbrole end),
               @dbrole = (case when (is_srvrolemember(N'diskadmin') = 1) then @dbrole | 0x0002 else @dbrole end),
               @dbrole = (case when (is_srvrolemember(N'processadmin') = 1) then @dbrole | 0x0004 else @dbrole end),
               @dbrole = (case when (is_srvrolemember(N'securityadmin') = 1) then @dbrole | 0x0008 else @dbrole end),
               @dbrole = (case when (is_srvrolemember(N'serveradmin') = 1) then @dbrole | 0x0010 else @dbrole end),
               @dbrole = (case when (is_srvrolemember(N'setupadmin') = 1) then @dbrole | 0x0020 else @dbrole end),
               @dbrole = (case when (is_srvrolemember(N'sysadmin') = 1) then @dbrole | 0x0040 else @dbrole end),
               @dbrole = (case when (is_srvrolemember(N'bulkadmin') = 1) then @dbrole | 0x10000 else @dbrole end),
        /* Database Roles */
               @dbrole = (case when (is_member(N'db_accessadmin') = 1) then @dbrole | 0x0080 else @dbrole end),
               @dbrole = (case when (is_member(N'db_datareader') = 1) then @dbrole | 0x0100 else @dbrole end),
               @dbrole = (case when (is_member(N'db_ddladmin') = 1) then @dbrole | 0x0200 else @dbrole end),
               @dbrole = (case when (is_member(N'db_denydatareader') = 1) then @dbrole | 0x0400 else @dbrole end),
               @dbrole = (case when (is_member(N'db_denydatawriter') = 1) then @dbrole | 0x0800 else @dbrole end),
               @dbrole = (case when (is_member(N'db_backupoperator') = 1) then @dbrole | 0x1000 else @dbrole end),
               @dbrole = (case when (is_member(N'db_owner') = 1) then @dbrole | 0x2000 else @dbrole end),
               @dbrole = (case when (is_member(N'db_securityadmin') = 1) then @dbrole | 0x4000 else @dbrole end),
               @dbrole = (case when (is_member(N'db_datawriter') = 1) then @dbrole | 0x8000 else @dbrole end)
          if (lower(@mode) like N'ver%')
           begin  
/* 
7.0           select @@version, N'login_id' = convert(int, suser_sid()), N'pagesize' = v.low, N'highbit' = v2.low, N'highbyte' = v3.low,
              N'casesens' = (case when (N'A' != N'a') then 1 else 0 end), @@spid, @@servername, is_srvrolemember(N'sysadmin'), @dbrole
              from master..spt_values v,master..spt_values v2,master..spt_values v3 where v.number=1 and v.type=N'E' and v2.number=2
              and v2.type=N'E' and v3.number=3 and v3.type=N'E'  
*/
           select @@version, N'login_id' = convert(int, suser_sid()), N'pagesize' = v.low, N'highbit' = v2.low, N'highbyte' = v3.low,
              N'casesens' = (case when (N'A' != N'a') then 1 else 0 end), @@spid, convert(sysname, serverproperty(N'servername')),
              is_srvrolemember(N'sysadmin'), @dbrole,
              N'InstanceName' = convert(sysname, serverproperty(N'instancename')),
              N'PID' = convert(int, serverproperty(N'processid'))
              from master..spt_values v,master..spt_values v2,master..spt_values v3 where v.number=1 and v.type=N'E' and v2.number=2
              and v2.type=N'E' and v3.number=3 and v3.type=N'E'
           end
        else if (lower(@mode) like N'role%')
           begin
           select @dbrole
           end
        else if (lower(@mode) like N'perm%')
           begin
           select @bits
           end
        return 0
        end

Open in new window

0
 
LVL 51

Assisted Solution

by:Mark Wills
Mark Wills earned 333 total points
ID: 33491870
Oh, and that above link to technet also shows on the left hand side the entry / reference for : is_srvrolemember()

0
 
LVL 6

Author Comment

by:anushahanna
ID: 33588007
Thanks indeed for the helpful clarification.
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question