2002-02-05 19:11:17 +01:00
|
|
|
|
/*
|
2005-03-17 11:26:20 +01:00
|
|
|
|
* RPC Manager
|
2002-02-05 19:11:17 +01:00
|
|
|
|
*
|
2005-02-15 16:02:49 +01:00
|
|
|
|
* Copyright 2001 Ove K<EFBFBD>ven, TransGaming Technologies
|
2005-01-21 11:15:29 +01:00
|
|
|
|
* Copyright 2002 Marcus Meissner
|
|
|
|
|
* Copyright 2005 Mike Hearn, Rob Shearman for CodeWeavers
|
2002-03-10 00:29:33 +01:00
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2002-02-05 19:11:17 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
|
#include <stdarg.h>
|
2002-02-05 19:11:17 +01:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
|
#define COBJMACROS
|
2003-01-07 21:36:20 +01:00
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
|
#define NONAMELESSSTRUCT
|
2004-10-07 05:06:48 +02:00
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
|
#include "windef.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
|
#include "winbase.h"
|
2003-09-09 21:39:31 +02:00
|
|
|
|
#include "winuser.h"
|
2005-01-05 14:22:10 +01:00
|
|
|
|
#include "winsvc.h"
|
2002-02-05 19:11:17 +01:00
|
|
|
|
#include "objbase.h"
|
|
|
|
|
#include "ole2.h"
|
|
|
|
|
#include "rpc.h"
|
|
|
|
|
#include "winerror.h"
|
|
|
|
|
#include "winreg.h"
|
|
|
|
|
#include "wtypes.h"
|
2005-09-14 12:07:01 +02:00
|
|
|
|
#include "excpt.h"
|
2002-02-05 19:11:17 +01:00
|
|
|
|
#include "wine/unicode.h"
|
2005-09-14 12:07:01 +02:00
|
|
|
|
#include "wine/exception.h"
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
|
|
|
|
#include "compobj_private.h"
|
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
|
#include "wine/debug.h"
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
static void __RPC_STUB dispatch_rpc(RPC_MESSAGE *msg);
|
2004-12-27 20:27:57 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
/* we only use one function to dispatch calls for all methods - we use the
|
|
|
|
|
* RPC_IF_OLE flag to tell the RPC runtime that this is the case */
|
|
|
|
|
static RPC_DISPATCH_FUNCTION rpc_dispatch_table[1] = { dispatch_rpc }; /* (RO) */
|
|
|
|
|
static RPC_DISPATCH_TABLE rpc_dispatch = { 1, rpc_dispatch_table }; /* (RO) */
|
2005-01-21 11:15:29 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
static struct list registered_interfaces = LIST_INIT(registered_interfaces); /* (CS csRegIf) */
|
|
|
|
|
static CRITICAL_SECTION csRegIf;
|
|
|
|
|
static CRITICAL_SECTION_DEBUG csRegIf_debug =
|
2005-01-21 11:15:29 +01:00
|
|
|
|
{
|
2005-02-15 16:02:49 +01:00
|
|
|
|
0, 0, &csRegIf,
|
|
|
|
|
{ &csRegIf_debug.ProcessLocksList, &csRegIf_debug.ProcessLocksList },
|
2005-09-09 12:19:44 +02:00
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": dcom registered server interfaces") }
|
2005-01-21 11:15:29 +01:00
|
|
|
|
};
|
2005-02-15 16:02:49 +01:00
|
|
|
|
static CRITICAL_SECTION csRegIf = { &csRegIf_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
|
|
static WCHAR wszPipeTransport[] = {'n','c','a','c','n','_','n','p',0};
|
|
|
|
|
|
2004-07-23 01:44:54 +02:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
struct registered_if
|
2005-01-21 11:15:29 +01:00
|
|
|
|
{
|
2005-02-15 16:02:49 +01:00
|
|
|
|
struct list entry;
|
|
|
|
|
DWORD refs; /* ref count */
|
|
|
|
|
RPC_SERVER_INTERFACE If; /* interface registered with the RPC runtime */
|
2005-01-21 11:15:29 +01:00
|
|
|
|
};
|
2004-07-23 01:44:54 +02:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
/* get the pipe endpoint specified of the specified apartment */
|
|
|
|
|
static inline void get_rpc_endpoint(LPWSTR endpoint, const OXID *oxid)
|
|
|
|
|
{
|
|
|
|
|
/* FIXME: should get endpoint from rpcss */
|
|
|
|
|
static const WCHAR wszEndpointFormat[] = {'\\','p','i','p','e','\\','O','L','E','_','%','0','8','l','x','%','0','8','l','x',0};
|
|
|
|
|
wsprintfW(endpoint, wszEndpointFormat, (DWORD)(*oxid >> 32),(DWORD)*oxid);
|
|
|
|
|
}
|
2004-07-30 01:58:12 +02:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
const IRpcChannelBufferVtbl *lpVtbl;
|
2005-07-05 13:02:54 +02:00
|
|
|
|
LONG refs;
|
2005-02-15 16:02:49 +01:00
|
|
|
|
} RpcChannelBuffer;
|
2004-07-23 01:44:54 +02:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
typedef struct
|
2005-01-21 11:15:29 +01:00
|
|
|
|
{
|
2005-02-15 16:02:49 +01:00
|
|
|
|
RpcChannelBuffer super; /* superclass */
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
RPC_BINDING_HANDLE bind; /* handle to the remote server */
|
|
|
|
|
} ClientRpcChannelBuffer;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2005-03-17 11:26:20 +01:00
|
|
|
|
struct dispatch_params
|
|
|
|
|
{
|
|
|
|
|
RPCOLEMESSAGE *msg; /* message */
|
|
|
|
|
IRpcStubBuffer *stub; /* stub buffer, if applicable */
|
|
|
|
|
IRpcChannelBuffer *chan; /* server channel buffer, if applicable */
|
|
|
|
|
HANDLE handle; /* handle that will become signaled when call finishes */
|
|
|
|
|
RPC_STATUS status; /* status (out) */
|
2005-09-14 12:07:01 +02:00
|
|
|
|
HRESULT hr; /* hresult (out) */
|
2005-03-17 11:26:20 +01:00
|
|
|
|
};
|
|
|
|
|
|
2005-12-19 17:44:56 +01:00
|
|
|
|
static WINE_EXCEPTION_FILTER(ole_filter)
|
|
|
|
|
{
|
|
|
|
|
if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
|
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
static HRESULT WINAPI RpcChannelBuffer_QueryInterface(LPRPCCHANNELBUFFER iface, REFIID riid, LPVOID *ppv)
|
2005-01-21 11:15:29 +01:00
|
|
|
|
{
|
2005-02-15 16:02:49 +01:00
|
|
|
|
*ppv = NULL;
|
|
|
|
|
if (IsEqualIID(riid,&IID_IRpcChannelBuffer) || IsEqualIID(riid,&IID_IUnknown))
|
|
|
|
|
{
|
|
|
|
|
*ppv = (LPVOID)iface;
|
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
static ULONG WINAPI RpcChannelBuffer_AddRef(LPRPCCHANNELBUFFER iface)
|
|
|
|
|
{
|
|
|
|
|
RpcChannelBuffer *This = (RpcChannelBuffer *)iface;
|
|
|
|
|
return InterlockedIncrement(&This->refs);
|
|
|
|
|
}
|
2004-12-27 17:59:28 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
static ULONG WINAPI ServerRpcChannelBuffer_Release(LPRPCCHANNELBUFFER iface)
|
|
|
|
|
{
|
|
|
|
|
RpcChannelBuffer *This = (RpcChannelBuffer *)iface;
|
|
|
|
|
ULONG ref;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
ref = InterlockedDecrement(&This->refs);
|
|
|
|
|
if (ref)
|
|
|
|
|
return ref;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
static ULONG WINAPI ClientRpcChannelBuffer_Release(LPRPCCHANNELBUFFER iface)
|
|
|
|
|
{
|
|
|
|
|
ClientRpcChannelBuffer *This = (ClientRpcChannelBuffer *)iface;
|
|
|
|
|
ULONG ref;
|
2005-02-08 13:55:26 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
ref = InterlockedDecrement(&This->super.refs);
|
|
|
|
|
if (ref)
|
|
|
|
|
return ref;
|
2005-02-08 13:55:26 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
RpcBindingFree(&This->bind);
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2005-02-08 13:55:26 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
static HRESULT WINAPI ServerRpcChannelBuffer_GetBuffer(LPRPCCHANNELBUFFER iface, RPCOLEMESSAGE* olemsg, REFIID riid)
|
2005-02-08 13:55:26 +01:00
|
|
|
|
{
|
2005-02-15 16:02:49 +01:00
|
|
|
|
RpcChannelBuffer *This = (RpcChannelBuffer *)iface;
|
|
|
|
|
RPC_MESSAGE *msg = (RPC_MESSAGE *)olemsg;
|
|
|
|
|
RPC_STATUS status;
|
|
|
|
|
|
2005-03-17 11:26:20 +01:00
|
|
|
|
TRACE("(%p)->(%p,%s)\n", This, olemsg, debugstr_guid(riid));
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
|
|
|
|
status = I_RpcGetBuffer(msg);
|
|
|
|
|
|
|
|
|
|
TRACE("-- %ld\n", status);
|
|
|
|
|
|
|
|
|
|
return HRESULT_FROM_WIN32(status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI ClientRpcChannelBuffer_GetBuffer(LPRPCCHANNELBUFFER iface, RPCOLEMESSAGE* olemsg, REFIID riid)
|
|
|
|
|
{
|
|
|
|
|
ClientRpcChannelBuffer *This = (ClientRpcChannelBuffer *)iface;
|
|
|
|
|
RPC_MESSAGE *msg = (RPC_MESSAGE *)olemsg;
|
|
|
|
|
RPC_CLIENT_INTERFACE *cif;
|
|
|
|
|
RPC_STATUS status;
|
|
|
|
|
|
2005-03-17 11:26:20 +01:00
|
|
|
|
TRACE("(%p)->(%p,%s)\n", This, olemsg, debugstr_guid(riid));
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
|
|
|
|
cif = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RPC_CLIENT_INTERFACE));
|
|
|
|
|
if (!cif)
|
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
|
|
cif->Length = sizeof(RPC_CLIENT_INTERFACE);
|
|
|
|
|
/* RPC interface ID = COM interface ID */
|
|
|
|
|
cif->InterfaceId.SyntaxGUID = *riid;
|
|
|
|
|
/* COM objects always have a version of 0.0 */
|
|
|
|
|
cif->InterfaceId.SyntaxVersion.MajorVersion = 0;
|
|
|
|
|
cif->InterfaceId.SyntaxVersion.MinorVersion = 0;
|
|
|
|
|
msg->RpcInterfaceInformation = cif;
|
|
|
|
|
msg->Handle = This->bind;
|
2005-02-08 13:55:26 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
status = I_RpcGetBuffer(msg);
|
|
|
|
|
|
|
|
|
|
TRACE("-- %ld\n", status);
|
|
|
|
|
|
|
|
|
|
return HRESULT_FROM_WIN32(status);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-04 13:30:47 +01:00
|
|
|
|
/* this thread runs an outgoing RPC */
|
|
|
|
|
static DWORD WINAPI rpc_sendreceive_thread(LPVOID param)
|
|
|
|
|
{
|
2005-03-17 11:26:20 +01:00
|
|
|
|
struct dispatch_params *data = (struct dispatch_params *) param;
|
2005-03-04 13:30:47 +01:00
|
|
|
|
|
|
|
|
|
/* FIXME: trap and rethrow RPC exceptions in app thread */
|
2005-03-17 11:26:20 +01:00
|
|
|
|
data->status = I_RpcSendReceive((RPC_MESSAGE *)data->msg);
|
2005-03-04 13:30:47 +01:00
|
|
|
|
|
|
|
|
|
TRACE("completed with status 0x%lx\n", data->status);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
static HRESULT WINAPI RpcChannelBuffer_SendReceive(LPRPCCHANNELBUFFER iface, RPCOLEMESSAGE *olemsg, ULONG *pstatus)
|
|
|
|
|
{
|
2005-03-04 13:30:47 +01:00
|
|
|
|
HRESULT hr = S_OK;
|
2005-07-19 21:12:47 +02:00
|
|
|
|
RPC_MESSAGE *msg = (RPC_MESSAGE *)olemsg;
|
2005-02-15 16:02:49 +01:00
|
|
|
|
RPC_STATUS status;
|
2005-03-17 11:26:20 +01:00
|
|
|
|
DWORD index;
|
|
|
|
|
struct dispatch_params *params;
|
|
|
|
|
DWORD tid;
|
2005-07-19 21:12:47 +02:00
|
|
|
|
IRpcStubBuffer *stub;
|
|
|
|
|
APARTMENT *apt;
|
|
|
|
|
IPID ipid;
|
|
|
|
|
|
2005-03-17 11:26:20 +01:00
|
|
|
|
TRACE("(%p) iMethod=%ld\n", olemsg, olemsg->iMethod);
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
2005-03-17 11:26:20 +01:00
|
|
|
|
params = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*params));
|
2005-03-04 13:30:47 +01:00
|
|
|
|
if (!params) return E_OUTOFMEMORY;
|
|
|
|
|
|
2005-03-17 11:26:20 +01:00
|
|
|
|
params->msg = olemsg;
|
|
|
|
|
params->status = RPC_S_OK;
|
2005-09-14 12:07:01 +02:00
|
|
|
|
params->hr = S_OK;
|
2005-03-04 13:30:47 +01:00
|
|
|
|
|
2005-07-19 21:12:47 +02:00
|
|
|
|
/* Note: this is an optimization in the Microsoft OLE runtime that we need
|
|
|
|
|
* to copy, as shown by the test_no_couninitialize_client test. without
|
|
|
|
|
* short-circuiting the RPC runtime in the case below, the test will
|
|
|
|
|
* deadlock on the loader lock due to the RPC runtime needing to create
|
|
|
|
|
* a thread to process the RPC when this function is called indirectly
|
|
|
|
|
* from DllMain */
|
|
|
|
|
|
|
|
|
|
RpcBindingInqObject(msg->Handle, &ipid);
|
|
|
|
|
stub = ipid_to_apt_and_stubbuffer(&ipid, &apt);
|
|
|
|
|
if (apt && (apt->model & COINIT_APARTMENTTHREADED))
|
|
|
|
|
{
|
|
|
|
|
params->stub = stub;
|
|
|
|
|
params->chan = NULL; /* FIXME: pass server channel */
|
|
|
|
|
params->handle = CreateEventW(NULL, FALSE, FALSE, NULL);
|
|
|
|
|
|
|
|
|
|
TRACE("Calling apartment thread 0x%08lx...\n", apt->tid);
|
|
|
|
|
|
|
|
|
|
PostMessageW(apt->win, DM_EXECUTERPC, 0, (LPARAM)params);
|
|
|
|
|
}
|
|
|
|
|
else
|
2005-03-04 13:30:47 +01:00
|
|
|
|
{
|
2005-07-19 21:12:47 +02:00
|
|
|
|
if (stub) IRpcStubBuffer_Release(stub);
|
|
|
|
|
|
|
|
|
|
/* we use a separate thread here because we need to be able to
|
|
|
|
|
* pump the message loop in the application thread: if we do not,
|
|
|
|
|
* any windows created by this thread will hang and RPCs that try
|
|
|
|
|
* and re-enter this STA from an incoming server thread will
|
|
|
|
|
* deadlock. InstallShield is an example of that.
|
|
|
|
|
*/
|
|
|
|
|
params->handle = CreateThread(NULL, 0, rpc_sendreceive_thread, params, 0, &tid);
|
|
|
|
|
if (!params->handle)
|
|
|
|
|
{
|
|
|
|
|
ERR("Could not create RpcSendReceive thread, error %lx\n", GetLastError());
|
|
|
|
|
hr = E_UNEXPECTED;
|
|
|
|
|
}
|
2005-03-04 13:30:47 +01:00
|
|
|
|
}
|
2005-07-19 21:12:47 +02:00
|
|
|
|
if (apt) apartment_release(apt);
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
2005-03-17 11:26:20 +01:00
|
|
|
|
if (hr == S_OK)
|
|
|
|
|
hr = CoWaitForMultipleHandles(0, INFINITE, 1, ¶ms->handle, &index);
|
|
|
|
|
CloseHandle(params->handle);
|
2005-03-04 13:30:47 +01:00
|
|
|
|
|
2005-09-14 12:07:01 +02:00
|
|
|
|
if (hr == S_OK) hr = params->hr;
|
|
|
|
|
|
2005-03-04 13:30:47 +01:00
|
|
|
|
status = params->status;
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, params);
|
|
|
|
|
params = NULL;
|
2005-03-17 11:26:20 +01:00
|
|
|
|
|
2005-03-04 13:30:47 +01:00
|
|
|
|
if (hr) return hr;
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
if (pstatus) *pstatus = status;
|
|
|
|
|
|
2005-03-04 13:30:47 +01:00
|
|
|
|
TRACE("RPC call status: 0x%lx\n", status);
|
2005-02-15 16:02:49 +01:00
|
|
|
|
if (status == RPC_S_OK)
|
|
|
|
|
hr = S_OK;
|
|
|
|
|
else if (status == RPC_S_CALL_FAILED)
|
2005-03-17 11:26:20 +01:00
|
|
|
|
hr = *(HRESULT *)olemsg->Buffer;
|
2005-02-15 16:02:49 +01:00
|
|
|
|
else
|
|
|
|
|
hr = HRESULT_FROM_WIN32(status);
|
|
|
|
|
|
|
|
|
|
TRACE("-- 0x%08lx\n", hr);
|
|
|
|
|
|
|
|
|
|
return hr;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
static HRESULT WINAPI ServerRpcChannelBuffer_FreeBuffer(LPRPCCHANNELBUFFER iface, RPCOLEMESSAGE* olemsg)
|
2005-01-21 11:15:29 +01:00
|
|
|
|
{
|
2005-02-15 16:02:49 +01:00
|
|
|
|
RPC_MESSAGE *msg = (RPC_MESSAGE *)olemsg;
|
|
|
|
|
RPC_STATUS status;
|
|
|
|
|
|
|
|
|
|
TRACE("(%p)\n", msg);
|
|
|
|
|
|
|
|
|
|
status = I_RpcFreeBuffer(msg);
|
|
|
|
|
|
|
|
|
|
TRACE("-- %ld\n", status);
|
|
|
|
|
|
|
|
|
|
return HRESULT_FROM_WIN32(status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI ClientRpcChannelBuffer_FreeBuffer(LPRPCCHANNELBUFFER iface, RPCOLEMESSAGE* olemsg)
|
|
|
|
|
{
|
|
|
|
|
RPC_MESSAGE *msg = (RPC_MESSAGE *)olemsg;
|
|
|
|
|
RPC_STATUS status;
|
|
|
|
|
|
|
|
|
|
TRACE("(%p)\n", msg);
|
|
|
|
|
|
|
|
|
|
status = I_RpcFreeBuffer(msg);
|
|
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, msg->RpcInterfaceInformation);
|
|
|
|
|
msg->RpcInterfaceInformation = NULL;
|
|
|
|
|
|
|
|
|
|
TRACE("-- %ld\n", status);
|
|
|
|
|
|
|
|
|
|
return HRESULT_FROM_WIN32(status);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
static HRESULT WINAPI RpcChannelBuffer_GetDestCtx(LPRPCCHANNELBUFFER iface, DWORD* pdwDestContext, void** ppvDestContext)
|
|
|
|
|
{
|
|
|
|
|
FIXME("(%p,%p), stub!\n", pdwDestContext, ppvDestContext);
|
|
|
|
|
return E_FAIL;
|
|
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
static HRESULT WINAPI RpcChannelBuffer_IsConnected(LPRPCCHANNELBUFFER iface)
|
|
|
|
|
{
|
|
|
|
|
TRACE("()\n");
|
|
|
|
|
/* native does nothing too */
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
static const IRpcChannelBufferVtbl ClientRpcChannelBufferVtbl =
|
|
|
|
|
{
|
|
|
|
|
RpcChannelBuffer_QueryInterface,
|
|
|
|
|
RpcChannelBuffer_AddRef,
|
|
|
|
|
ClientRpcChannelBuffer_Release,
|
|
|
|
|
ClientRpcChannelBuffer_GetBuffer,
|
|
|
|
|
RpcChannelBuffer_SendReceive,
|
|
|
|
|
ClientRpcChannelBuffer_FreeBuffer,
|
|
|
|
|
RpcChannelBuffer_GetDestCtx,
|
|
|
|
|
RpcChannelBuffer_IsConnected
|
|
|
|
|
};
|
2005-02-08 13:55:26 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
static const IRpcChannelBufferVtbl ServerRpcChannelBufferVtbl =
|
|
|
|
|
{
|
|
|
|
|
RpcChannelBuffer_QueryInterface,
|
|
|
|
|
RpcChannelBuffer_AddRef,
|
|
|
|
|
ServerRpcChannelBuffer_Release,
|
|
|
|
|
ServerRpcChannelBuffer_GetBuffer,
|
|
|
|
|
RpcChannelBuffer_SendReceive,
|
|
|
|
|
ServerRpcChannelBuffer_FreeBuffer,
|
|
|
|
|
RpcChannelBuffer_GetDestCtx,
|
|
|
|
|
RpcChannelBuffer_IsConnected
|
|
|
|
|
};
|
2005-02-08 13:55:26 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
/* returns a channel buffer for proxies */
|
2005-02-15 16:44:25 +01:00
|
|
|
|
HRESULT RPC_CreateClientChannel(const OXID *oxid, const IPID *ipid, IRpcChannelBuffer **chan)
|
2005-02-08 13:55:26 +01:00
|
|
|
|
{
|
2005-02-15 16:02:49 +01:00
|
|
|
|
ClientRpcChannelBuffer *This;
|
|
|
|
|
WCHAR endpoint[200];
|
|
|
|
|
RPC_BINDING_HANDLE bind;
|
|
|
|
|
RPC_STATUS status;
|
|
|
|
|
LPWSTR string_binding;
|
|
|
|
|
|
|
|
|
|
/* connect to the apartment listener thread */
|
2005-02-15 16:44:25 +01:00
|
|
|
|
get_rpc_endpoint(endpoint, oxid);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
TRACE("proxy pipe: connecting to endpoint: %s\n", debugstr_w(endpoint));
|
|
|
|
|
|
|
|
|
|
status = RpcStringBindingComposeW(
|
|
|
|
|
NULL,
|
|
|
|
|
wszPipeTransport,
|
|
|
|
|
NULL,
|
|
|
|
|
endpoint,
|
|
|
|
|
NULL,
|
|
|
|
|
&string_binding);
|
|
|
|
|
|
|
|
|
|
if (status == RPC_S_OK)
|
2005-02-08 13:55:26 +01:00
|
|
|
|
{
|
2005-02-15 16:02:49 +01:00
|
|
|
|
status = RpcBindingFromStringBindingW(string_binding, &bind);
|
|
|
|
|
|
|
|
|
|
if (status == RPC_S_OK)
|
2005-02-08 13:55:26 +01:00
|
|
|
|
{
|
2005-02-15 16:44:25 +01:00
|
|
|
|
IPID ipid2 = *ipid; /* why can't RpcBindingSetObject take a const? */
|
|
|
|
|
status = RpcBindingSetObject(bind, &ipid2);
|
2005-02-15 16:02:49 +01:00
|
|
|
|
if (status != RPC_S_OK)
|
|
|
|
|
RpcBindingFree(&bind);
|
2005-02-08 13:55:26 +01:00
|
|
|
|
}
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
|
|
|
|
RpcStringFreeW(&string_binding);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
if (status != RPC_S_OK)
|
|
|
|
|
{
|
|
|
|
|
ERR("Couldn't get binding for endpoint %s, status = %ld\n", debugstr_w(endpoint), status);
|
|
|
|
|
return HRESULT_FROM_WIN32(status);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
|
|
|
|
|
if (!This)
|
|
|
|
|
{
|
|
|
|
|
RpcBindingFree(&bind);
|
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
This->super.lpVtbl = &ClientRpcChannelBufferVtbl;
|
|
|
|
|
This->super.refs = 1;
|
|
|
|
|
This->bind = bind;
|
2004-07-30 01:58:12 +02:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
*chan = (IRpcChannelBuffer*)This;
|
2004-07-30 01:58:12 +02:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
return S_OK;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
HRESULT RPC_CreateServerChannel(IRpcChannelBuffer **chan)
|
2005-01-21 11:15:29 +01:00
|
|
|
|
{
|
2005-02-15 16:02:49 +01:00
|
|
|
|
RpcChannelBuffer *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
|
|
|
|
|
if (!This)
|
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
|
|
This->lpVtbl = &ServerRpcChannelBufferVtbl;
|
|
|
|
|
This->refs = 1;
|
|
|
|
|
|
|
|
|
|
*chan = (IRpcChannelBuffer*)This;
|
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
2005-09-14 12:07:01 +02:00
|
|
|
|
void RPC_ExecuteCall(struct dispatch_params *params)
|
2005-02-14 12:50:51 +01:00
|
|
|
|
{
|
2005-09-14 12:07:01 +02:00
|
|
|
|
__TRY
|
|
|
|
|
{
|
|
|
|
|
params->hr = IRpcStubBuffer_Invoke(params->stub, params->msg, params->chan);
|
|
|
|
|
}
|
2005-12-19 17:44:56 +01:00
|
|
|
|
__EXCEPT(ole_filter)
|
2005-09-14 12:07:01 +02:00
|
|
|
|
{
|
|
|
|
|
params->hr = GetExceptionCode();
|
|
|
|
|
}
|
|
|
|
|
__ENDTRY
|
2005-03-17 11:26:20 +01:00
|
|
|
|
IRpcStubBuffer_Release(params->stub);
|
|
|
|
|
if (params->handle) SetEvent(params->handle);
|
2005-02-14 12:50:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
static void __RPC_STUB dispatch_rpc(RPC_MESSAGE *msg)
|
|
|
|
|
{
|
2005-03-17 11:26:20 +01:00
|
|
|
|
struct dispatch_params *params;
|
2004-12-27 20:21:47 +01:00
|
|
|
|
IRpcStubBuffer *stub;
|
2005-02-14 12:50:51 +01:00
|
|
|
|
APARTMENT *apt;
|
2005-02-15 16:02:49 +01:00
|
|
|
|
IPID ipid;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
RpcBindingInqObject(msg->Handle, &ipid);
|
2005-02-14 12:50:51 +01:00
|
|
|
|
|
2005-03-17 11:26:20 +01:00
|
|
|
|
TRACE("ipid = %s, iMethod = %d\n", debugstr_guid(&ipid), msg->ProcNum);
|
|
|
|
|
|
|
|
|
|
params = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*params));
|
|
|
|
|
if (!params) return RpcRaiseException(E_OUTOFMEMORY);
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
stub = ipid_to_apt_and_stubbuffer(&ipid, &apt);
|
|
|
|
|
if (!apt || !stub)
|
2005-02-14 12:50:51 +01:00
|
|
|
|
{
|
2005-03-11 11:19:10 +01:00
|
|
|
|
if (apt) apartment_release(apt);
|
2005-07-19 21:42:33 +02:00
|
|
|
|
ERR("no apartment found for ipid %s\n", debugstr_guid(&ipid));
|
2005-02-15 16:02:49 +01:00
|
|
|
|
return RpcRaiseException(RPC_E_DISCONNECTED);
|
2005-02-14 12:50:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-17 11:26:20 +01:00
|
|
|
|
params->msg = (RPCOLEMESSAGE *)msg;
|
|
|
|
|
params->stub = stub;
|
|
|
|
|
params->chan = NULL; /* FIXME: pass server channel */
|
|
|
|
|
params->status = RPC_S_OK;
|
|
|
|
|
|
2005-02-14 12:50:51 +01:00
|
|
|
|
/* Note: this is the important difference between STAs and MTAs - we
|
|
|
|
|
* always execute RPCs to STAs in the thread that originally created the
|
|
|
|
|
* apartment (i.e. the one that pumps messages to the window) */
|
|
|
|
|
if (apt->model & COINIT_APARTMENTTHREADED)
|
2005-03-17 11:26:20 +01:00
|
|
|
|
{
|
|
|
|
|
params->handle = CreateEventW(NULL, FALSE, FALSE, NULL);
|
|
|
|
|
|
|
|
|
|
TRACE("Calling apartment thread 0x%08lx...\n", apt->tid);
|
|
|
|
|
|
|
|
|
|
PostMessageW(apt->win, DM_EXECUTERPC, 0, (LPARAM)params);
|
|
|
|
|
WaitForSingleObject(params->handle, INFINITE);
|
|
|
|
|
CloseHandle(params->handle);
|
|
|
|
|
}
|
2005-02-14 12:50:51 +01:00
|
|
|
|
else
|
2005-03-17 11:26:20 +01:00
|
|
|
|
RPC_ExecuteCall(params);
|
|
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, params);
|
2005-02-14 12:50:51 +01:00
|
|
|
|
|
2005-03-11 11:19:10 +01:00
|
|
|
|
apartment_release(apt);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
/* stub registration */
|
|
|
|
|
HRESULT RPC_RegisterInterface(REFIID riid)
|
2005-02-08 13:55:26 +01:00
|
|
|
|
{
|
2005-02-15 16:02:49 +01:00
|
|
|
|
struct registered_if *rif;
|
|
|
|
|
BOOL found = FALSE;
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_guid(riid));
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
EnterCriticalSection(&csRegIf);
|
|
|
|
|
LIST_FOR_EACH_ENTRY(rif, ®istered_interfaces, struct registered_if, entry)
|
2005-02-08 13:55:26 +01:00
|
|
|
|
{
|
2005-02-15 16:02:49 +01:00
|
|
|
|
if (IsEqualGUID(&rif->If.InterfaceId.SyntaxGUID, riid))
|
|
|
|
|
{
|
|
|
|
|
rif->refs++;
|
|
|
|
|
found = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
2005-02-15 16:02:49 +01:00
|
|
|
|
if (!found)
|
|
|
|
|
{
|
|
|
|
|
TRACE("Creating new interface\n");
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2005-02-15 22:48:09 +01:00
|
|
|
|
rif = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*rif));
|
2005-02-15 16:02:49 +01:00
|
|
|
|
if (rif)
|
|
|
|
|
{
|
|
|
|
|
RPC_STATUS status;
|
|
|
|
|
|
|
|
|
|
rif->refs = 1;
|
|
|
|
|
rif->If.Length = sizeof(RPC_SERVER_INTERFACE);
|
|
|
|
|
/* RPC interface ID = COM interface ID */
|
|
|
|
|
rif->If.InterfaceId.SyntaxGUID = *riid;
|
|
|
|
|
rif->If.DispatchTable = &rpc_dispatch;
|
2005-02-15 22:48:09 +01:00
|
|
|
|
/* all other fields are 0, including the version asCOM objects
|
|
|
|
|
* always have a version of 0.0 */
|
2005-02-15 16:02:49 +01:00
|
|
|
|
status = RpcServerRegisterIfEx(
|
|
|
|
|
(RPC_IF_HANDLE)&rif->If,
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
RPC_IF_OLE | RPC_IF_AUTOLISTEN,
|
|
|
|
|
RPC_C_LISTEN_MAX_CALLS_DEFAULT,
|
|
|
|
|
NULL);
|
|
|
|
|
if (status == RPC_S_OK)
|
|
|
|
|
list_add_tail(®istered_interfaces, &rif->entry);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ERR("RpcServerRegisterIfEx failed with error %ld\n", status);
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, rif);
|
|
|
|
|
hr = HRESULT_FROM_WIN32(status);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
|
}
|
|
|
|
|
LeaveCriticalSection(&csRegIf);
|
|
|
|
|
return hr;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
/* stub unregistration */
|
|
|
|
|
void RPC_UnregisterInterface(REFIID riid)
|
2005-01-21 11:15:29 +01:00
|
|
|
|
{
|
2005-02-15 16:02:49 +01:00
|
|
|
|
struct registered_if *rif;
|
|
|
|
|
EnterCriticalSection(&csRegIf);
|
|
|
|
|
LIST_FOR_EACH_ENTRY(rif, ®istered_interfaces, struct registered_if, entry)
|
2005-02-08 13:55:26 +01:00
|
|
|
|
{
|
2005-02-15 16:02:49 +01:00
|
|
|
|
if (IsEqualGUID(&rif->If.InterfaceId.SyntaxGUID, riid))
|
2005-02-08 13:55:26 +01:00
|
|
|
|
{
|
2005-02-15 16:02:49 +01:00
|
|
|
|
if (!--rif->refs)
|
|
|
|
|
{
|
|
|
|
|
#if 0 /* this is a stub in builtin and spams the console with FIXME's */
|
|
|
|
|
IID iid = *riid; /* RpcServerUnregisterIf doesn't take const IID */
|
|
|
|
|
RpcServerUnregisterIf((RPC_IF_HANDLE)&rif->If, &iid, 0);
|
|
|
|
|
list_remove(&rif->entry);
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, rif);
|
2005-02-15 16:44:25 +01:00
|
|
|
|
#endif
|
2005-02-15 16:02:49 +01:00
|
|
|
|
}
|
|
|
|
|
break;
|
2005-01-21 11:15:29 +01:00
|
|
|
|
}
|
2005-02-15 16:02:49 +01:00
|
|
|
|
}
|
|
|
|
|
LeaveCriticalSection(&csRegIf);
|
|
|
|
|
}
|
2005-02-08 13:55:26 +01:00
|
|
|
|
|
2005-02-15 16:44:25 +01:00
|
|
|
|
/* make the apartment reachable by other threads and processes and create the
|
|
|
|
|
* IRemUnknown object */
|
|
|
|
|
void RPC_StartRemoting(struct apartment *apt)
|
2005-02-15 16:02:49 +01:00
|
|
|
|
{
|
2005-02-15 16:44:25 +01:00
|
|
|
|
if (!InterlockedExchange(&apt->remoting_started, TRUE))
|
2005-02-15 16:02:49 +01:00
|
|
|
|
{
|
|
|
|
|
WCHAR endpoint[200];
|
|
|
|
|
RPC_STATUS status;
|
2005-02-08 13:55:26 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
get_rpc_endpoint(endpoint, &apt->oxid);
|
2005-01-21 11:15:29 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
status = RpcServerUseProtseqEpW(
|
|
|
|
|
wszPipeTransport,
|
|
|
|
|
RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
|
|
|
|
|
endpoint,
|
|
|
|
|
NULL);
|
|
|
|
|
if (status != RPC_S_OK)
|
|
|
|
|
ERR("Couldn't register endpoint %s\n", debugstr_w(endpoint));
|
2005-02-15 16:44:25 +01:00
|
|
|
|
|
|
|
|
|
/* FIXME: move remote unknown exporting into this function */
|
2005-02-15 16:02:49 +01:00
|
|
|
|
}
|
2005-02-15 16:44:25 +01:00
|
|
|
|
start_apartment_remote_unknown();
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
2005-02-15 16:44:25 +01:00
|
|
|
|
static HRESULT create_server(REFCLSID rclsid)
|
2005-01-21 11:15:29 +01:00
|
|
|
|
{
|
2005-06-20 12:33:28 +02:00
|
|
|
|
static const WCHAR wszLocalServer32[] = { 'L','o','c','a','l','S','e','r','v','e','r','3','2',0 };
|
2005-01-21 11:15:29 +01:00
|
|
|
|
static const WCHAR embedding[] = { ' ', '-','E','m','b','e','d','d','i','n','g',0 };
|
|
|
|
|
HKEY key;
|
2005-11-08 11:56:02 +01:00
|
|
|
|
HRESULT hres;
|
2005-01-21 11:15:29 +01:00
|
|
|
|
WCHAR command[MAX_PATH+sizeof(embedding)/sizeof(WCHAR)];
|
2005-12-06 10:57:58 +01:00
|
|
|
|
DWORD size = (MAX_PATH+1) * sizeof(WCHAR);
|
2005-01-21 11:15:29 +01:00
|
|
|
|
STARTUPINFOW sinfo;
|
|
|
|
|
PROCESS_INFORMATION pinfo;
|
|
|
|
|
|
2005-11-09 11:29:11 +01:00
|
|
|
|
hres = COM_OpenKeyForCLSID(rclsid, wszLocalServer32, KEY_READ, &key);
|
|
|
|
|
if (FAILED(hres)) {
|
2005-06-20 12:33:28 +02:00
|
|
|
|
ERR("class %s not registered\n", debugstr_guid(rclsid));
|
2005-11-09 11:29:11 +01:00
|
|
|
|
return hres;
|
2005-01-21 11:15:29 +01:00
|
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2005-11-08 11:56:02 +01:00
|
|
|
|
hres = RegQueryValueExW(key, NULL, NULL, NULL, (LPBYTE)command, &size);
|
2005-01-21 11:15:29 +01:00
|
|
|
|
RegCloseKey(key);
|
|
|
|
|
if (hres) {
|
|
|
|
|
WARN("No default value for LocalServer32 key\n");
|
|
|
|
|
return REGDB_E_CLASSNOTREG; /* FIXME: check retval */
|
|
|
|
|
}
|
2004-07-23 21:10:13 +02:00
|
|
|
|
|
2005-01-21 11:15:29 +01:00
|
|
|
|
memset(&sinfo,0,sizeof(sinfo));
|
|
|
|
|
sinfo.cb = sizeof(sinfo);
|
2004-07-23 21:10:13 +02:00
|
|
|
|
|
2005-11-08 11:56:02 +01:00
|
|
|
|
/* EXE servers are started with the -Embedding switch. */
|
2004-07-23 21:10:13 +02:00
|
|
|
|
|
2005-01-21 11:15:29 +01:00
|
|
|
|
strcatW(command, embedding);
|
2004-07-23 21:10:13 +02:00
|
|
|
|
|
2005-06-20 12:33:28 +02:00
|
|
|
|
TRACE("activating local server %s for %s\n", debugstr_w(command), debugstr_guid(rclsid));
|
2004-07-23 21:10:13 +02:00
|
|
|
|
|
2005-11-08 11:56:02 +01:00
|
|
|
|
/* FIXME: Win2003 supports a ServerExecutable value that is passed into
|
|
|
|
|
* CreateProcess */
|
|
|
|
|
if (!CreateProcessW(NULL, command, NULL, NULL, FALSE, 0, NULL, NULL, &sinfo, &pinfo)) {
|
|
|
|
|
WARN("failed to run local server %s\n", debugstr_w(command));
|
2005-02-15 22:48:09 +01:00
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
2005-01-21 11:15:29 +01:00
|
|
|
|
}
|
2005-02-15 22:48:09 +01:00
|
|
|
|
CloseHandle(pinfo.hProcess);
|
|
|
|
|
CloseHandle(pinfo.hThread);
|
2004-07-23 21:10:13 +02:00
|
|
|
|
|
2005-01-21 11:15:29 +01:00
|
|
|
|
return S_OK;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
2005-01-05 14:22:10 +01:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* start_local_service() - start a service given its name and parameters
|
|
|
|
|
*/
|
2005-02-15 16:44:25 +01:00
|
|
|
|
static DWORD start_local_service(LPCWSTR name, DWORD num, LPWSTR *params)
|
2005-01-05 14:22:10 +01:00
|
|
|
|
{
|
|
|
|
|
SC_HANDLE handle, hsvc;
|
2005-01-21 11:15:29 +01:00
|
|
|
|
DWORD r = ERROR_FUNCTION_FAILED;
|
2005-01-05 14:22:10 +01:00
|
|
|
|
|
|
|
|
|
TRACE("Starting service %s %ld params\n", debugstr_w(name), num);
|
|
|
|
|
|
|
|
|
|
handle = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
|
|
|
|
if (!handle)
|
|
|
|
|
return r;
|
|
|
|
|
hsvc = OpenServiceW(handle, name, SC_MANAGER_ALL_ACCESS);
|
|
|
|
|
if (hsvc)
|
|
|
|
|
{
|
|
|
|
|
if(StartServiceW(hsvc, num, (LPCWSTR*)params))
|
|
|
|
|
r = ERROR_SUCCESS;
|
|
|
|
|
else
|
|
|
|
|
r = GetLastError();
|
2005-01-21 11:15:29 +01:00
|
|
|
|
if (r == ERROR_SERVICE_ALREADY_RUNNING)
|
2005-01-05 14:22:10 +01:00
|
|
|
|
r = ERROR_SUCCESS;
|
|
|
|
|
CloseServiceHandle(hsvc);
|
|
|
|
|
}
|
|
|
|
|
CloseServiceHandle(handle);
|
|
|
|
|
|
|
|
|
|
TRACE("StartService returned error %ld (%s)\n", r, r?"ok":"failed");
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* create_local_service() - start a COM server in a service
|
|
|
|
|
*
|
|
|
|
|
* To start a Local Service, we read the AppID value under
|
|
|
|
|
* the class's CLSID key, then open the HKCR\\AppId key specified
|
|
|
|
|
* there and check for a LocalService value.
|
|
|
|
|
*
|
|
|
|
|
* Note: Local Services are not supported under Windows 9x
|
|
|
|
|
*/
|
2005-02-15 16:44:25 +01:00
|
|
|
|
static HRESULT create_local_service(REFCLSID rclsid)
|
2005-01-05 14:22:10 +01:00
|
|
|
|
{
|
2005-11-09 11:29:11 +01:00
|
|
|
|
HRESULT hres;
|
2005-06-20 12:33:28 +02:00
|
|
|
|
WCHAR buf[CHARS_IN_GUID], keyname[50];
|
2005-01-05 14:22:10 +01:00
|
|
|
|
static const WCHAR szAppId[] = { 'A','p','p','I','d',0 };
|
|
|
|
|
static const WCHAR szAppIdKey[] = { 'A','p','p','I','d','\\',0 };
|
2005-01-21 11:15:29 +01:00
|
|
|
|
static const WCHAR szLocalService[] = { 'L','o','c','a','l','S','e','r','v','i','c','e',0 };
|
|
|
|
|
static const WCHAR szServiceParams[] = {'S','e','r','v','i','c','e','P','a','r','a','m','s',0};
|
2005-01-05 14:22:10 +01:00
|
|
|
|
HKEY hkey;
|
|
|
|
|
LONG r;
|
|
|
|
|
DWORD type, sz;
|
|
|
|
|
|
|
|
|
|
TRACE("Attempting to start Local service for %s\n", debugstr_guid(rclsid));
|
|
|
|
|
|
|
|
|
|
/* read the AppID value under the class's key */
|
2005-11-09 11:29:11 +01:00
|
|
|
|
hres = COM_OpenKeyForCLSID(rclsid, szAppId, KEY_READ, &hkey);
|
|
|
|
|
if (FAILED(hres))
|
2005-01-05 14:22:10 +01:00
|
|
|
|
return hres;
|
|
|
|
|
sz = sizeof buf;
|
2005-11-09 11:29:11 +01:00
|
|
|
|
r = RegQueryValueExW(hkey, NULL, NULL, &type, (LPBYTE)buf, &sz);
|
2005-01-05 14:22:10 +01:00
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
|
if (r!=ERROR_SUCCESS || type!=REG_SZ)
|
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
|
|
/* read the LocalService and ServiceParameters values from the AppID key */
|
|
|
|
|
strcpyW(keyname, szAppIdKey);
|
|
|
|
|
strcatW(keyname, buf);
|
|
|
|
|
r = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &hkey);
|
|
|
|
|
if (r!=ERROR_SUCCESS)
|
|
|
|
|
return hres;
|
|
|
|
|
sz = sizeof buf;
|
|
|
|
|
r = RegQueryValueExW(hkey, szLocalService, NULL, &type, (LPBYTE)buf, &sz);
|
|
|
|
|
if (r==ERROR_SUCCESS && type==REG_SZ)
|
|
|
|
|
{
|
|
|
|
|
DWORD num_args = 0;
|
|
|
|
|
LPWSTR args[1] = { NULL };
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* FIXME: I'm not really sure how to deal with the service parameters.
|
|
|
|
|
* I suspect that the string returned from RegQueryValueExW
|
|
|
|
|
* should be split into a number of arguments by spaces.
|
|
|
|
|
* It would make more sense if ServiceParams contained a
|
|
|
|
|
* REG_MULTI_SZ here, but it's a REG_SZ for the services
|
|
|
|
|
* that I'm interested in for the moment.
|
|
|
|
|
*/
|
|
|
|
|
r = RegQueryValueExW(hkey, szServiceParams, NULL, &type, NULL, &sz);
|
|
|
|
|
if (r == ERROR_SUCCESS && type == REG_SZ && sz)
|
|
|
|
|
{
|
|
|
|
|
args[0] = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sz);
|
|
|
|
|
num_args++;
|
|
|
|
|
RegQueryValueExW(hkey, szServiceParams, NULL, &type, (LPBYTE)args[0], &sz);
|
|
|
|
|
}
|
|
|
|
|
r = start_local_service(buf, num_args, args);
|
|
|
|
|
if (r==ERROR_SUCCESS)
|
|
|
|
|
hres = S_OK;
|
|
|
|
|
HeapFree(GetProcessHeap(),0,args[0]);
|
|
|
|
|
}
|
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-20 12:33:28 +02:00
|
|
|
|
|
|
|
|
|
static void get_localserver_pipe_name(WCHAR *pipefn, REFCLSID rclsid)
|
|
|
|
|
{
|
|
|
|
|
static const WCHAR wszPipeRef[] = {'\\','\\','.','\\','p','i','p','e','\\',0};
|
|
|
|
|
strcpyW(pipefn, wszPipeRef);
|
|
|
|
|
StringFromGUID2(rclsid, pipefn + sizeof(wszPipeRef)/sizeof(wszPipeRef[0]) - 1, CHARS_IN_GUID);
|
|
|
|
|
}
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
|
|
|
|
/* FIXME: should call to rpcss instead */
|
2005-02-15 16:44:25 +01:00
|
|
|
|
HRESULT RPC_GetLocalClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
|
2005-01-21 11:15:29 +01:00
|
|
|
|
{
|
|
|
|
|
HRESULT hres;
|
|
|
|
|
HANDLE hPipe;
|
2005-06-20 12:33:28 +02:00
|
|
|
|
WCHAR pipefn[100];
|
2005-01-21 11:15:29 +01:00
|
|
|
|
DWORD res, bufferlen;
|
|
|
|
|
char marshalbuffer[200];
|
|
|
|
|
IStream *pStm;
|
|
|
|
|
LARGE_INTEGER seekto;
|
|
|
|
|
ULARGE_INTEGER newpos;
|
|
|
|
|
int tries = 0;
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
2005-02-15 16:44:25 +01:00
|
|
|
|
static const int MAXTRIES = 30; /* 30 seconds */
|
2005-01-21 11:15:29 +01:00
|
|
|
|
|
|
|
|
|
TRACE("rclsid=%s, iid=%s\n", debugstr_guid(rclsid), debugstr_guid(iid));
|
|
|
|
|
|
2005-06-20 12:33:28 +02:00
|
|
|
|
get_localserver_pipe_name(pipefn, rclsid);
|
2005-01-21 11:15:29 +01:00
|
|
|
|
|
|
|
|
|
while (tries++ < MAXTRIES) {
|
2005-06-20 12:33:28 +02:00
|
|
|
|
TRACE("waiting for %s\n", debugstr_w(pipefn));
|
2004-12-27 17:59:28 +01:00
|
|
|
|
|
2005-06-20 12:33:28 +02:00
|
|
|
|
WaitNamedPipeW( pipefn, NMPWAIT_WAIT_FOREVER );
|
|
|
|
|
hPipe = CreateFileW(pipefn, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
|
2005-01-21 11:15:29 +01:00
|
|
|
|
if (hPipe == INVALID_HANDLE_VALUE) {
|
|
|
|
|
if (tries == 1) {
|
|
|
|
|
if ( (hres = create_server(rclsid)) &&
|
|
|
|
|
(hres = create_local_service(rclsid)) )
|
|
|
|
|
return hres;
|
|
|
|
|
Sleep(1000);
|
|
|
|
|
} else {
|
2005-06-20 12:33:28 +02:00
|
|
|
|
WARN("Connecting to %s, no response yet, retrying: le is %lx\n", debugstr_w(pipefn), GetLastError());
|
2005-01-21 11:15:29 +01:00
|
|
|
|
Sleep(1000);
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
bufferlen = 0;
|
|
|
|
|
if (!ReadFile(hPipe,marshalbuffer,sizeof(marshalbuffer),&bufferlen,NULL)) {
|
|
|
|
|
FIXME("Failed to read marshal id from classfactory of %s.\n",debugstr_guid(rclsid));
|
|
|
|
|
Sleep(1000);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
TRACE("read marshal id from pipe\n");
|
|
|
|
|
CloseHandle(hPipe);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tries >= MAXTRIES)
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
|
|
hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
|
|
|
|
|
if (hres) return hres;
|
|
|
|
|
hres = IStream_Write(pStm,marshalbuffer,bufferlen,&res);
|
|
|
|
|
if (hres) goto out;
|
|
|
|
|
seekto.u.LowPart = 0;seekto.u.HighPart = 0;
|
|
|
|
|
hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
|
|
|
|
|
|
|
|
|
|
TRACE("unmarshalling classfactory\n");
|
|
|
|
|
hres = CoUnmarshalInterface(pStm,&IID_IClassFactory,ppv);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
out:
|
2005-01-21 11:15:29 +01:00
|
|
|
|
IStream_Release(pStm);
|
|
|
|
|
return hres;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-12-27 20:24:55 +01:00
|
|
|
|
struct local_server_params
|
|
|
|
|
{
|
|
|
|
|
CLSID clsid;
|
|
|
|
|
IStream *stream;
|
|
|
|
|
};
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
/* FIXME: should call to rpcss instead */
|
2004-12-27 20:24:55 +01:00
|
|
|
|
static DWORD WINAPI local_server_thread(LPVOID param)
|
|
|
|
|
{
|
|
|
|
|
struct local_server_params * lsp = (struct local_server_params *)param;
|
|
|
|
|
HANDLE hPipe;
|
2005-06-20 12:33:28 +02:00
|
|
|
|
WCHAR pipefn[100];
|
2004-12-27 20:24:55 +01:00
|
|
|
|
HRESULT hres;
|
|
|
|
|
IStream *pStm = lsp->stream;
|
|
|
|
|
STATSTG ststg;
|
|
|
|
|
unsigned char *buffer;
|
|
|
|
|
int buflen;
|
|
|
|
|
LARGE_INTEGER seekto;
|
|
|
|
|
ULARGE_INTEGER newpos;
|
|
|
|
|
ULONG res;
|
|
|
|
|
|
|
|
|
|
TRACE("Starting threader for %s.\n",debugstr_guid(&lsp->clsid));
|
|
|
|
|
|
2005-06-20 12:33:28 +02:00
|
|
|
|
get_localserver_pipe_name(pipefn, &lsp->clsid);
|
2004-12-27 20:24:55 +01:00
|
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, lsp);
|
|
|
|
|
|
2005-06-20 12:33:28 +02:00
|
|
|
|
hPipe = CreateNamedPipeW( pipefn, PIPE_ACCESS_DUPLEX,
|
2005-02-08 13:55:26 +01:00
|
|
|
|
PIPE_TYPE_BYTE|PIPE_WAIT, PIPE_UNLIMITED_INSTANCES,
|
|
|
|
|
4096, 4096, 500 /* 0.5 second timeout */, NULL );
|
|
|
|
|
|
|
|
|
|
if (hPipe == INVALID_HANDLE_VALUE)
|
|
|
|
|
{
|
2005-06-20 12:33:28 +02:00
|
|
|
|
FIXME("pipe creation failed for %s, le is %ld\n", debugstr_w(pipefn), GetLastError());
|
2004-12-27 20:24:55 +01:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
2005-02-08 13:55:26 +01:00
|
|
|
|
|
2004-12-27 20:24:55 +01:00
|
|
|
|
while (1) {
|
|
|
|
|
if (!ConnectNamedPipe(hPipe,NULL)) {
|
|
|
|
|
ERR("Failure during ConnectNamedPipe %ld, ABORT!\n",GetLastError());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TRACE("marshalling IClassFactory to client\n");
|
|
|
|
|
|
|
|
|
|
hres = IStream_Stat(pStm,&ststg,0);
|
|
|
|
|
if (hres) return hres;
|
|
|
|
|
|
|
|
|
|
buflen = ststg.cbSize.u.LowPart;
|
|
|
|
|
buffer = HeapAlloc(GetProcessHeap(),0,buflen);
|
|
|
|
|
seekto.u.LowPart = 0;
|
|
|
|
|
seekto.u.HighPart = 0;
|
|
|
|
|
hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
|
|
|
|
|
if (hres) {
|
|
|
|
|
FIXME("IStream_Seek failed, %lx\n",hres);
|
|
|
|
|
return hres;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hres = IStream_Read(pStm,buffer,buflen,&res);
|
|
|
|
|
if (hres) {
|
|
|
|
|
FIXME("Stream Read failed, %lx\n",hres);
|
|
|
|
|
return hres;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WriteFile(hPipe,buffer,buflen,&res,NULL);
|
|
|
|
|
FlushFileBuffers(hPipe);
|
|
|
|
|
DisconnectNamedPipe(hPipe);
|
|
|
|
|
|
|
|
|
|
TRACE("done marshalling IClassFactory\n");
|
|
|
|
|
}
|
|
|
|
|
CloseHandle(hPipe);
|
2005-01-28 13:39:13 +01:00
|
|
|
|
IStream_Release(pStm);
|
2004-12-27 20:24:55 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RPC_StartLocalServer(REFCLSID clsid, IStream *stream)
|
|
|
|
|
{
|
|
|
|
|
DWORD tid;
|
|
|
|
|
HANDLE thread;
|
|
|
|
|
struct local_server_params *lsp = HeapAlloc(GetProcessHeap(), 0, sizeof(*lsp));
|
|
|
|
|
|
|
|
|
|
lsp->clsid = *clsid;
|
|
|
|
|
lsp->stream = stream;
|
|
|
|
|
|
|
|
|
|
thread = CreateThread(NULL, 0, local_server_thread, lsp, 0, &tid);
|
|
|
|
|
CloseHandle(thread);
|
|
|
|
|
/* FIXME: failure handling */
|
|
|
|
|
}
|