question

amrutanegundi-7060 avatar image
0 Votes"
amrutanegundi-7060 asked RLWA32-6355 commented

Geting the ProcessID of the client that makes COM call running as dllSurrogate?

I am kind of new to COM and had a query. We have registered a COM DLL as DLLSurrogate to run under default dllhost.exe.
We have an app/3rd party app that is consuming this COM, and when we try to get the current process id it is returning the process id of dllhost.exe and not the app.
Is there a way to get the process id of the client that made the COM call (app)?

windows-apic++
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NO WAY! DLL is not executable module. So it must instance(initialize) in host executable programs.
See. Task manager.

0 Votes 0 ·
SongZhu-MSFT avatar image
0 Votes"
SongZhu-MSFT answered amrutanegundi-7060 commented

Refer to: Determine the Process ID of the Client Process communicating with a COM RPC Server
I think you cannot get the identifier of the process.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Is there a way to identify the process since I know that it is a local server and I need a way to get processid to read the exe cert info. Also want to understand if custom surrogate can help here?


0 Votes 0 ·
RLWA32-6355 avatar image
0 Votes"
RLWA32-6355 answered RLWA32-6355 commented

An out-of-process COM server handling an incoming call from a COM client can use the RpcServerInqCallAttributes function and request RPC_QUERY_CLIENT_PID in the RPC_CALL_ATTRIBUTES_V2 struct that is passed to the function.


· 14
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@RLWA32-6355
I tried out the below code but getting the status as (RPC_S_NO_CALL_ACTIVE)1725 but I was expecting ERROR_MORE_DATA. I even tried assigning to a temp buffer and still got the same error. And also I see RPC_CALL_ATTRIBUTES_V2 disabled as my code is legacy.

     RPC_CALL_ATTRIBUTES CallAttributes;  // this maps to RPC_CALL_ATTRIBUTES_V1

 memset(&CallAttributes, 0, sizeof(CallAttributes));
 CallAttributes.Version = RPC_CALL_ATTRIBUTES_VERSION;    // maps to 1
 CallAttributes.Flags = RPC_QUERY_CLIENT_PRINCIPAL_NAME;//....
 RPC_STATUS Status = RpcServerInqCallAttributes(0, &CallAttributes);


The above code is called in the context of dllhost.exe...
Is there something I am missing?

0 Votes 0 ·

The RpcServerInqCallAttributes function should be called while the COM server is handling an incoming call. The error return of RPC_S_NO_CALL_ACTIVE seems to indicate that the function is being called at some other point in processing.

0 Votes 0 ·

Following is the sample code that I used in my test -

     RPC_CALL_ATTRIBUTES_V2 rpcAttributes{};
    
     rpcAttributes.Version = 2;
     rpcAttributes.Flags = RPC_QUERY_CLIENT_PID;
     RPC_STATUS rpcRet = RpcServerInqCallAttributes(NULL, &rpcAttributes);
0 Votes 0 ·

@RLWA32-6355
I am making the call in the context of dllhost.exe (if I do getprocessid it is returning processid of dllhost.exe) so I believe it is getting called while the COM server is handling an incoming call.
Correct me if I am wrong here?

Since the code is legacy I see that RPC_CALL_ATTRIBUTES_V2 is not defined maybe due to NTDDI_VERSION<NTDDI_VISTA.



0 Votes 0 ·
Show more comments