Impersonating when creating a process from inside a SQL Server Assembly
- From: "Keith" <keith@xxxxxxx>
- Date: Thu, 14 Dec 2006 11:58:45 -0800
Hello,
This is my situation: I'm trying to impersonate a different user when
creating a process from inside a .NET assembly on SQL Server. Basically the
flow looks like this:
stored procedure->static C# function in Assembly->Process created in
Asembly->External Application
This works, but the external app fails because the current WindowsIdentity
is NT AUTHORITY/WINDOWS SERVICE. ; it needs to be someone else.
Now, when you are inside a .NET assembly in SQL Server, you have access to
an object called SqlContext, and it contains (among other things) a
WindowsIdentity object that is the login user who called the stored
procedure in the first place. This is the user I want to impersonate but I
can't seem to get it to work.
In other postings I've read that you can't get this to work with a Process -
apparently the process still inherits the Principal token and but the
Impersonation token - but it DOES work with Threads. So I thought I'd spawn
a new Thread with the correct identity and launch my process from inside.
To test the Thread idea I used:
ParameterizedThreadStart pts = new
ParameterizedThreadStart(someThreadFunction);
Thread thread = new Thread(pts);
WindowsIdentity contextID = SqlContext.WindowsIdentity;
using (WindowsImpersonationContext wip = contextID.Impersonate())
{
thread.Start(test);
while (thread.ThreadState == System.Threading.ThreadState.Running) { }
wip.Undo();
}
But inside the Thread function (someThreadFunction) the
WindowsIdentity.GetCurrent() still returns NT AUTHORITY/WINDOWS SERVICE.
Am I going about this all wrong? Is this even possible?
Any advice/suggestions appreciated!
Keith
.
- Follow-Ups:
- Prev by Date: Re: GetOwner and IdentityNotMappedException
- Next by Date: Re: Impersonating when creating a process from inside a SQL Server Assembly
- Previous by thread: Re: GetOwner and IdentityNotMappedException
- Next by thread: Re: Impersonating when creating a process from inside a SQL Server Assembly
- Index(es):
Relevant Pages
|