OK, after much testing, I'm starting to see what the problem is.
Apparently, if you want to use IS_SRVROLEMEMBER, as long as the user you are
checking is the current user or a SQL Server account, the function will
return the expected value. If I want to check another Windows (local or
domain) user, it looks like I have to have at least the securityadmin role on
the current user to do so.
Here's a test procedure:
CREATE PROCEDURE [dbo].[testRole] (@UserName sysname)
AS SELECT IS_SRVROLEMEMBER('sysadmin', @UserName)
The problem is how to grant any other user the right to run this function?
1. Use the EXECUTE AS LOGIN in a SQL batch. - works, but Impersonation
must be allowed for the user you wish to impersonate and you also get the
rights and abilities of that user - Not Good!
2. Use WITH EXECUTE AS when defining my stored procedure. - can't get
any varioation to work. You'd figure that I would be able to specify that
the execution runs as a user that would have permissions to execute the
function and return the value as expected, but not a chance.
EXECUTE AS SELF and EXECUTE AS OWNER return null values for *ANY* user that
attempt to run the stored procedure. This includes users with the ability to
get the right values for IS_SRVROLEMEMBER.
EXECUTE AS CALLER is the only way to get anyone to be able to return the
right values, but that still is restricted to securityadmin and sysadmin
roles.
EXECUTE AS <user> you'd think would be the key, but not even a chance.
Instead, we get a new error: The server principal <user> is not able to
access the database <database> under the current security context.
Though the last one seems like we are getting somewhere, the suggestions for
resolution don't really help. The only thing that is close is this article:
http://support.microsoft.com/default.aspx/kb/913422. Unfortunately, the
workarounds described, don't work for this situation. What seem to be the
key here is in the cause for this article:
This issue occurs because SQL Server strips down the server-scoped
permissions when you impersonate a database user.
For security considerations, the server-scoped permissions are stripped down
when you impersonate a database user unless the system administrator has
explicitly set SQL Server to trust the impersonated context at the
server-scope. In this case, a login with the control server server-scoped
permission has no permissions to access any particular database. Therefore,
the trigger module that is executed as this login cannot run.
My question is does anyone know how if there is anyway around this
limitation? For the Microsoft support team, would this be something worthy