views:

30

answers:

3

I need to call one function using maximum privileges (NT AUTHORY\System) from other process (IIS7 module work process) running in same local computer in much less privileged mode (NT AUTHORY\Network service).

IIS module will call that function passing some text (user name) and that function need to return HADNLE type witch will be closed after process using CloseHandle function.

( function: LogonUser http://msdn.microsoft.com/en-us/library/aa378184(VS.85).aspx )

What is the best way to do this? COM+, shared memory, named pipes? I don't have any experience in this programming, so i need some help. I don't know how to pass handle type with named pipes? (i saw only examples that are passing only text based messages, not pointers or other data types).

+1  A: 

Handles are not usable across the session boundary. And I'm not 100% sure it is usable across the process boundary for all types of handles.

It's better to for example use pipes to notify the other process who is running with elevated priveleges to get it's own handle and perform whatever operation you want.

As to what is the best method to do the communication, this really depends on your exact needs and your exact experience level in each way.

Brian R. Bondy
I can't let the service to perform what i need because that handle is impersonation token which is used in whole IIS7 process pipeline to perform identification and authorization of user running that request/response ..
DoDo
A: 

Just FYI, a HANDLE is just a 32-bit integer value in Windows. It is not a pointer to a memory location.

Jeff Wilhite
A: 

You can't pass a handle to another process, handles are process local. But you can use DuplicateHandle to create a clone of your handle for use by another process. Only the other process can use the duplicate. The other process is responsible for calling CloseHandle on it.

John Knoeller
And how can i do this? With windows service? how to get handle from first process to duplicate it? ( i suppose that i need to run DuplicateHandle function from process where i need to use it as you said .. )
DoDo
You can't duplicate another process's handles, you can only duplicate our own handles for another process.
John Knoeller
Tnx, but can you tell me what's the best way to return that handle to main process which need that handle? just to create main handle, duplicate it, and return number of that handle (as Jeff Wilhite wrote that HANDLE is 32bit integer ..)
DoDo
@DoDo: you can use any IPC machanism that you want, SendMessage works fine, or shared memory, named pipes, Interprocess COM, the handle can be passed as 32 bit integer. (64 bit on Win64)
John Knoeller