Search code examples
c++comdcom

Check whether COM-method call is local or remote


I have a COM server written in C++ running on some computer in a network. Clients may perform remote calls to it from the other computers. How do I check inside a method of the COM server if the given call is local (from the same computer) or remote?


Solution

  • If you don't use a certificate based authentication service, I suggest you to take a look at QueryBlanket

    IServerSecurity::QueryBlanket([out] DWORD *pAuthnSvc..., [out] void** pPrivs, ...)
    

    Depending on the actual authentication service, pPrivs may represent a pointer to an object of type SEC_WINNT_AUTH_IDENTITY. This structure contains the client's Domain name. So you may easily check if it matches the server's one.

    To get an instance of server security object one may use the following code:

    HRESULT hr;
    CComQIPtr<IServerSecurity> ss;
    if(FAILED(hr = ::CoGetCallContext(__uuidof(IServerSecurity), reinterpret_cast<void**>(&ss))))
        throw com_exception(hr, "Unable to retrieve the server security object");