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
|
2006-05-18 14:49:52 +02:00
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-02-05 19:11:17 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
2006-02-07 16:31:21 +01:00
|
|
|
|
#include "wine/port.h"
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
|
#include <stdarg.h>
|
2002-02-05 19:11:17 +01:00
|
|
|
|
#include <string.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 "wine/unicode.h"
|
|
|
|
|
|
|
|
|
|
#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 };
|
|
|
|
|
|
2006-12-19 20:35:42 +01:00
|
|
|
|
static struct list channel_hooks = LIST_INIT(channel_hooks); /* (CS csChannelHook) */
|
|
|
|
|
static CRITICAL_SECTION csChannelHook;
|
|
|
|
|
static CRITICAL_SECTION_DEBUG csChannelHook_debug =
|
|
|
|
|
{
|
|
|
|
|
0, 0, &csChannelHook,
|
|
|
|
|
{ &csChannelHook_debug.ProcessLocksList, &csChannelHook_debug.ProcessLocksList },
|
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": channel hooks") }
|
|
|
|
|
};
|
|
|
|
|
static CRITICAL_SECTION csChannelHook = { &csChannelHook_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
|
2006-03-31 13:34:25 +02:00
|
|
|
|
static WCHAR wszRpcTransport[] = {'n','c','a','l','r','p','c',0};
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
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 */
|
2006-01-20 16:16:08 +01:00
|
|
|
|
OXID oxid; /* apartment in which the channel is valid */
|
2007-03-27 19:15:41 +02:00
|
|
|
|
DWORD server_pid; /* id of server process */
|
2006-03-05 14:37:34 +01:00
|
|
|
|
DWORD dest_context; /* returned from GetDestCtx */
|
|
|
|
|
LPVOID dest_context_data; /* returned from GetDestCtx */
|
2006-06-17 13:31:44 +02:00
|
|
|
|
HANDLE event; /* cached event handle */
|
2005-02-15 16:02:49 +01:00
|
|
|
|
} 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 */
|
2006-12-19 20:37:15 +01:00
|
|
|
|
IID iid; /* ID of interface being called */
|
|
|
|
|
IUnknown *iface; /* interface being called */
|
2005-03-17 11:26:20 +01:00
|
|
|
|
HANDLE handle; /* handle that will become signaled when call finishes */
|
2008-01-07 18:14:54 +01:00
|
|
|
|
BOOL bypass_rpcrt; /* bypass RPC runtime? */
|
2005-03-17 11:26:20 +01:00
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
2006-12-19 20:35:35 +01:00
|
|
|
|
struct message_state
|
|
|
|
|
{
|
|
|
|
|
RPC_BINDING_HANDLE binding_handle;
|
|
|
|
|
ULONG prefix_data_len;
|
2006-12-19 20:35:51 +01:00
|
|
|
|
SChannelHookCallInfo channel_hook_info;
|
2008-01-07 18:14:54 +01:00
|
|
|
|
BOOL bypass_rpcrt;
|
2007-11-26 23:50:32 +01:00
|
|
|
|
|
|
|
|
|
/* client only */
|
2008-01-04 17:25:39 +01:00
|
|
|
|
HWND target_hwnd;
|
|
|
|
|
DWORD target_tid;
|
2007-11-26 23:50:32 +01:00
|
|
|
|
struct dispatch_params params;
|
2006-12-19 20:35:35 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
ULONG conformance; /* NDR */
|
|
|
|
|
GUID id;
|
|
|
|
|
ULONG size;
|
|
|
|
|
/* [size_is((size+7)&~7)] */ unsigned char data[1];
|
|
|
|
|
} WIRE_ORPC_EXTENT;
|
|
|
|
|
|
2006-12-19 20:35:42 +01:00
|
|
|
|
struct channel_hook_entry
|
|
|
|
|
{
|
|
|
|
|
struct list entry;
|
|
|
|
|
GUID id;
|
|
|
|
|
IChannelHook *hook;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct channel_hook_buffer_data
|
|
|
|
|
{
|
|
|
|
|
GUID id;
|
|
|
|
|
ULONG extension_size;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2006-12-27 14:04:07 +01:00
|
|
|
|
static HRESULT unmarshal_ORPCTHAT(RPC_MESSAGE *msg, ORPCTHAT *orpcthat,
|
|
|
|
|
ORPC_EXTENT_ARRAY *orpc_ext_array, WIRE_ORPC_EXTENT **first_wire_orpc_extent);
|
|
|
|
|
|
2006-12-19 20:35:42 +01:00
|
|
|
|
/* Channel Hook Functions */
|
|
|
|
|
|
|
|
|
|
static ULONG ChannelHooks_ClientGetSize(SChannelHookCallInfo *info,
|
|
|
|
|
struct channel_hook_buffer_data **data, unsigned int *hook_count,
|
|
|
|
|
ULONG *extension_count)
|
|
|
|
|
{
|
|
|
|
|
struct channel_hook_entry *entry;
|
|
|
|
|
ULONG total_size = 0;
|
|
|
|
|
unsigned int hook_index = 0;
|
|
|
|
|
|
|
|
|
|
*hook_count = 0;
|
|
|
|
|
*extension_count = 0;
|
|
|
|
|
|
|
|
|
|
EnterCriticalSection(&csChannelHook);
|
|
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(entry, &channel_hooks, struct channel_hook_entry, entry)
|
|
|
|
|
(*hook_count)++;
|
|
|
|
|
|
2006-12-27 14:04:07 +01:00
|
|
|
|
if (*hook_count)
|
2006-12-19 20:35:42 +01:00
|
|
|
|
*data = HeapAlloc(GetProcessHeap(), 0, *hook_count * sizeof(struct channel_hook_buffer_data));
|
|
|
|
|
else
|
|
|
|
|
*data = NULL;
|
|
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(entry, &channel_hooks, struct channel_hook_entry, entry)
|
|
|
|
|
{
|
|
|
|
|
ULONG extension_size = 0;
|
|
|
|
|
|
|
|
|
|
IChannelHook_ClientGetSize(entry->hook, &entry->id, &info->iid, &extension_size);
|
|
|
|
|
|
|
|
|
|
TRACE("%s: extension_size = %u\n", debugstr_guid(&entry->id), extension_size);
|
|
|
|
|
|
|
|
|
|
extension_size = (extension_size+7)&~7;
|
|
|
|
|
(*data)[hook_index].id = entry->id;
|
|
|
|
|
(*data)[hook_index].extension_size = extension_size;
|
|
|
|
|
|
|
|
|
|
/* an extension is only put onto the wire if it has data to write */
|
|
|
|
|
if (extension_size)
|
|
|
|
|
{
|
|
|
|
|
total_size += FIELD_OFFSET(WIRE_ORPC_EXTENT, data[extension_size]);
|
|
|
|
|
(*extension_count)++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hook_index++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LeaveCriticalSection(&csChannelHook);
|
|
|
|
|
|
|
|
|
|
return total_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned char * ChannelHooks_ClientFillBuffer(SChannelHookCallInfo *info,
|
|
|
|
|
unsigned char *buffer, struct channel_hook_buffer_data *data,
|
|
|
|
|
unsigned int hook_count)
|
|
|
|
|
{
|
|
|
|
|
struct channel_hook_entry *entry;
|
|
|
|
|
|
|
|
|
|
EnterCriticalSection(&csChannelHook);
|
|
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(entry, &channel_hooks, struct channel_hook_entry, entry)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
ULONG extension_size = 0;
|
|
|
|
|
WIRE_ORPC_EXTENT *wire_orpc_extent = (WIRE_ORPC_EXTENT *)buffer;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < hook_count; i++)
|
|
|
|
|
if (IsEqualGUID(&entry->id, &data[i].id))
|
|
|
|
|
extension_size = data[i].extension_size;
|
|
|
|
|
|
|
|
|
|
/* an extension is only put onto the wire if it has data to write */
|
|
|
|
|
if (!extension_size)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
IChannelHook_ClientFillBuffer(entry->hook, &entry->id, &info->iid,
|
|
|
|
|
&extension_size, buffer + FIELD_OFFSET(WIRE_ORPC_EXTENT, data[0]));
|
|
|
|
|
|
|
|
|
|
TRACE("%s: extension_size = %u\n", debugstr_guid(&entry->id), extension_size);
|
|
|
|
|
|
|
|
|
|
/* FIXME: set unused portion of wire_orpc_extent->data to 0? */
|
|
|
|
|
|
|
|
|
|
wire_orpc_extent->conformance = (extension_size+7)&~7;
|
|
|
|
|
wire_orpc_extent->size = extension_size;
|
|
|
|
|
memcpy(&wire_orpc_extent->id, &entry->id, sizeof(wire_orpc_extent->id));
|
|
|
|
|
buffer += FIELD_OFFSET(WIRE_ORPC_EXTENT, data[wire_orpc_extent->conformance]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LeaveCriticalSection(&csChannelHook);
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-19 20:35:51 +01:00
|
|
|
|
static void ChannelHooks_ServerNotify(SChannelHookCallInfo *info,
|
|
|
|
|
DWORD lDataRep, WIRE_ORPC_EXTENT *first_wire_orpc_extent,
|
|
|
|
|
ULONG extension_count)
|
|
|
|
|
{
|
|
|
|
|
struct channel_hook_entry *entry;
|
|
|
|
|
ULONG i;
|
|
|
|
|
|
|
|
|
|
EnterCriticalSection(&csChannelHook);
|
|
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(entry, &channel_hooks, struct channel_hook_entry, entry)
|
|
|
|
|
{
|
|
|
|
|
WIRE_ORPC_EXTENT *wire_orpc_extent;
|
|
|
|
|
for (i = 0, wire_orpc_extent = first_wire_orpc_extent;
|
|
|
|
|
i < extension_count;
|
|
|
|
|
i++, wire_orpc_extent = (WIRE_ORPC_EXTENT *)&wire_orpc_extent->data[wire_orpc_extent->conformance])
|
|
|
|
|
{
|
|
|
|
|
if (IsEqualGUID(&entry->id, &wire_orpc_extent->id))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (i == extension_count) wire_orpc_extent = NULL;
|
|
|
|
|
|
|
|
|
|
IChannelHook_ServerNotify(entry->hook, &entry->id, &info->iid,
|
|
|
|
|
wire_orpc_extent ? wire_orpc_extent->size : 0,
|
|
|
|
|
wire_orpc_extent ? wire_orpc_extent->data : NULL,
|
|
|
|
|
lDataRep);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LeaveCriticalSection(&csChannelHook);
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-27 14:04:07 +01:00
|
|
|
|
static ULONG ChannelHooks_ServerGetSize(SChannelHookCallInfo *info,
|
|
|
|
|
struct channel_hook_buffer_data **data, unsigned int *hook_count,
|
|
|
|
|
ULONG *extension_count)
|
|
|
|
|
{
|
|
|
|
|
struct channel_hook_entry *entry;
|
|
|
|
|
ULONG total_size = 0;
|
|
|
|
|
unsigned int hook_index = 0;
|
|
|
|
|
|
|
|
|
|
*hook_count = 0;
|
|
|
|
|
*extension_count = 0;
|
|
|
|
|
|
|
|
|
|
EnterCriticalSection(&csChannelHook);
|
|
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(entry, &channel_hooks, struct channel_hook_entry, entry)
|
|
|
|
|
(*hook_count)++;
|
|
|
|
|
|
|
|
|
|
if (*hook_count)
|
|
|
|
|
*data = HeapAlloc(GetProcessHeap(), 0, *hook_count * sizeof(struct channel_hook_buffer_data));
|
|
|
|
|
else
|
|
|
|
|
*data = NULL;
|
|
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(entry, &channel_hooks, struct channel_hook_entry, entry)
|
|
|
|
|
{
|
|
|
|
|
ULONG extension_size = 0;
|
|
|
|
|
|
|
|
|
|
IChannelHook_ServerGetSize(entry->hook, &entry->id, &info->iid, S_OK,
|
|
|
|
|
&extension_size);
|
|
|
|
|
|
|
|
|
|
TRACE("%s: extension_size = %u\n", debugstr_guid(&entry->id), extension_size);
|
|
|
|
|
|
|
|
|
|
extension_size = (extension_size+7)&~7;
|
|
|
|
|
(*data)[hook_index].id = entry->id;
|
|
|
|
|
(*data)[hook_index].extension_size = extension_size;
|
|
|
|
|
|
|
|
|
|
/* an extension is only put onto the wire if it has data to write */
|
|
|
|
|
if (extension_size)
|
|
|
|
|
{
|
|
|
|
|
total_size += FIELD_OFFSET(WIRE_ORPC_EXTENT, data[extension_size]);
|
|
|
|
|
(*extension_count)++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hook_index++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LeaveCriticalSection(&csChannelHook);
|
|
|
|
|
|
|
|
|
|
return total_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned char * ChannelHooks_ServerFillBuffer(SChannelHookCallInfo *info,
|
|
|
|
|
unsigned char *buffer, struct channel_hook_buffer_data *data,
|
|
|
|
|
unsigned int hook_count)
|
|
|
|
|
{
|
|
|
|
|
struct channel_hook_entry *entry;
|
|
|
|
|
|
|
|
|
|
EnterCriticalSection(&csChannelHook);
|
|
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(entry, &channel_hooks, struct channel_hook_entry, entry)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
ULONG extension_size = 0;
|
|
|
|
|
WIRE_ORPC_EXTENT *wire_orpc_extent = (WIRE_ORPC_EXTENT *)buffer;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < hook_count; i++)
|
|
|
|
|
if (IsEqualGUID(&entry->id, &data[i].id))
|
|
|
|
|
extension_size = data[i].extension_size;
|
|
|
|
|
|
|
|
|
|
/* an extension is only put onto the wire if it has data to write */
|
|
|
|
|
if (!extension_size)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
IChannelHook_ServerFillBuffer(entry->hook, &entry->id, &info->iid,
|
|
|
|
|
&extension_size, buffer + FIELD_OFFSET(WIRE_ORPC_EXTENT, data[0]),
|
|
|
|
|
S_OK);
|
|
|
|
|
|
|
|
|
|
TRACE("%s: extension_size = %u\n", debugstr_guid(&entry->id), extension_size);
|
|
|
|
|
|
|
|
|
|
/* FIXME: set unused portion of wire_orpc_extent->data to 0? */
|
|
|
|
|
|
|
|
|
|
wire_orpc_extent->conformance = (extension_size+7)&~7;
|
|
|
|
|
wire_orpc_extent->size = extension_size;
|
|
|
|
|
memcpy(&wire_orpc_extent->id, &entry->id, sizeof(wire_orpc_extent->id));
|
|
|
|
|
buffer += FIELD_OFFSET(WIRE_ORPC_EXTENT, data[wire_orpc_extent->conformance]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LeaveCriticalSection(&csChannelHook);
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void ChannelHooks_ClientNotify(SChannelHookCallInfo *info,
|
|
|
|
|
DWORD lDataRep, WIRE_ORPC_EXTENT *first_wire_orpc_extent,
|
|
|
|
|
ULONG extension_count, HRESULT hrFault)
|
|
|
|
|
{
|
|
|
|
|
struct channel_hook_entry *entry;
|
|
|
|
|
ULONG i;
|
|
|
|
|
|
|
|
|
|
EnterCriticalSection(&csChannelHook);
|
|
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(entry, &channel_hooks, struct channel_hook_entry, entry)
|
|
|
|
|
{
|
|
|
|
|
WIRE_ORPC_EXTENT *wire_orpc_extent;
|
|
|
|
|
for (i = 0, wire_orpc_extent = first_wire_orpc_extent;
|
|
|
|
|
i < extension_count;
|
|
|
|
|
i++, wire_orpc_extent = (WIRE_ORPC_EXTENT *)&wire_orpc_extent->data[wire_orpc_extent->conformance])
|
|
|
|
|
{
|
|
|
|
|
if (IsEqualGUID(&entry->id, &wire_orpc_extent->id))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (i == extension_count) wire_orpc_extent = NULL;
|
|
|
|
|
|
|
|
|
|
IChannelHook_ClientNotify(entry->hook, &entry->id, &info->iid,
|
|
|
|
|
wire_orpc_extent ? wire_orpc_extent->size : 0,
|
|
|
|
|
wire_orpc_extent ? wire_orpc_extent->data : NULL,
|
|
|
|
|
lDataRep, hrFault);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LeaveCriticalSection(&csChannelHook);
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-19 20:35:42 +01:00
|
|
|
|
HRESULT RPC_RegisterChannelHook(REFGUID rguid, IChannelHook *hook)
|
|
|
|
|
{
|
|
|
|
|
struct channel_hook_entry *entry;
|
|
|
|
|
|
|
|
|
|
TRACE("(%s, %p)\n", debugstr_guid(rguid), hook);
|
|
|
|
|
|
|
|
|
|
entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*entry));
|
|
|
|
|
if (!entry)
|
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
|
|
memcpy(&entry->id, rguid, sizeof(entry->id));
|
|
|
|
|
entry->hook = hook;
|
|
|
|
|
IChannelHook_AddRef(hook);
|
|
|
|
|
|
|
|
|
|
EnterCriticalSection(&csChannelHook);
|
|
|
|
|
list_add_tail(&channel_hooks, &entry->entry);
|
|
|
|
|
LeaveCriticalSection(&csChannelHook);
|
|
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RPC_UnregisterAllChannelHooks(void)
|
|
|
|
|
{
|
|
|
|
|
struct channel_hook_entry *cursor;
|
|
|
|
|
struct channel_hook_entry *cursor2;
|
|
|
|
|
|
|
|
|
|
EnterCriticalSection(&csChannelHook);
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, &channel_hooks, struct channel_hook_entry, entry)
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, cursor);
|
|
|
|
|
LeaveCriticalSection(&csChannelHook);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* RPC Channel Buffer Functions */
|
2006-12-19 20:35:35 +01:00
|
|
|
|
|
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
|
|
|
|
|
2006-06-17 13:31:44 +02:00
|
|
|
|
if (This->event) CloseHandle(This->event);
|
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;
|
2006-12-27 14:04:07 +01:00
|
|
|
|
ORPCTHAT *orpcthat;
|
2006-12-19 20:35:35 +01:00
|
|
|
|
struct message_state *message_state;
|
2006-12-27 14:04:07 +01:00
|
|
|
|
ULONG extensions_size;
|
|
|
|
|
struct channel_hook_buffer_data *channel_hook_data;
|
|
|
|
|
unsigned int channel_hook_count;
|
|
|
|
|
ULONG extension_count;
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
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
|
|
|
|
|
2006-12-19 20:35:35 +01:00
|
|
|
|
message_state = (struct message_state *)msg->Handle;
|
|
|
|
|
/* restore the binding handle and the real start of data */
|
|
|
|
|
msg->Handle = message_state->binding_handle;
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer - message_state->prefix_data_len;
|
|
|
|
|
|
2006-12-27 14:04:07 +01:00
|
|
|
|
extensions_size = ChannelHooks_ServerGetSize(&message_state->channel_hook_info,
|
|
|
|
|
&channel_hook_data, &channel_hook_count, &extension_count);
|
|
|
|
|
|
|
|
|
|
msg->BufferLength += FIELD_OFFSET(ORPCTHAT, extensions) + 4;
|
|
|
|
|
if (extensions_size)
|
|
|
|
|
{
|
|
|
|
|
msg->BufferLength += FIELD_OFFSET(ORPC_EXTENT_ARRAY, extent) + 2*sizeof(DWORD) + extensions_size;
|
|
|
|
|
if (extension_count & 1)
|
|
|
|
|
msg->BufferLength += FIELD_OFFSET(WIRE_ORPC_EXTENT, data[0]);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-07 18:14:54 +01:00
|
|
|
|
if (message_state->bypass_rpcrt)
|
|
|
|
|
{
|
|
|
|
|
msg->Buffer = HeapAlloc(GetProcessHeap(), 0, msg->BufferLength);
|
|
|
|
|
if (msg->Buffer)
|
|
|
|
|
status = RPC_S_OK;
|
|
|
|
|
else
|
|
|
|
|
status = ERROR_OUTOFMEMORY;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
status = I_RpcGetBuffer(msg);
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
2006-12-27 14:04:07 +01:00
|
|
|
|
orpcthat = (ORPCTHAT *)msg->Buffer;
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer + FIELD_OFFSET(ORPCTHAT, extensions);
|
|
|
|
|
|
|
|
|
|
orpcthat->flags = ORPCF_NULL /* FIXME? */;
|
|
|
|
|
|
|
|
|
|
/* NDR representation of orpcthat->extensions */
|
|
|
|
|
*(DWORD *)msg->Buffer = extensions_size ? 1 : 0;
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer + sizeof(DWORD);
|
|
|
|
|
|
|
|
|
|
if (extensions_size)
|
|
|
|
|
{
|
|
|
|
|
ORPC_EXTENT_ARRAY *orpc_extent_array = msg->Buffer;
|
|
|
|
|
orpc_extent_array->size = extension_count;
|
|
|
|
|
orpc_extent_array->reserved = 0;
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer + FIELD_OFFSET(ORPC_EXTENT_ARRAY, extent);
|
|
|
|
|
/* NDR representation of orpc_extent_array->extent */
|
|
|
|
|
*(DWORD *)msg->Buffer = 1;
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer + sizeof(DWORD);
|
|
|
|
|
/* NDR representation of [size_is] attribute of orpc_extent_array->extent */
|
|
|
|
|
*(DWORD *)msg->Buffer = (extension_count + 1) & ~1;
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer + sizeof(DWORD);
|
|
|
|
|
|
|
|
|
|
msg->Buffer = ChannelHooks_ServerFillBuffer(&message_state->channel_hook_info,
|
|
|
|
|
msg->Buffer, channel_hook_data, channel_hook_count);
|
|
|
|
|
|
|
|
|
|
/* we must add a dummy extension if there is an odd extension
|
|
|
|
|
* count to meet the contract specified by the size_is attribute */
|
|
|
|
|
if (extension_count & 1)
|
|
|
|
|
{
|
|
|
|
|
WIRE_ORPC_EXTENT *wire_orpc_extent = msg->Buffer;
|
|
|
|
|
wire_orpc_extent->conformance = 0;
|
|
|
|
|
memcpy(&wire_orpc_extent->id, &GUID_NULL, sizeof(wire_orpc_extent->id));
|
|
|
|
|
wire_orpc_extent->size = 0;
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer + FIELD_OFFSET(WIRE_ORPC_EXTENT, data[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-07 18:15:17 +01:00
|
|
|
|
HeapFree(GetProcessHeap(), 0, channel_hook_data);
|
|
|
|
|
|
2006-12-27 14:04:07 +01:00
|
|
|
|
/* store the prefixed data length so that we can restore the real buffer
|
|
|
|
|
* later */
|
|
|
|
|
message_state->prefix_data_len = (char *)msg->Buffer - (char *)orpcthat;
|
|
|
|
|
msg->BufferLength -= message_state->prefix_data_len;
|
2006-12-19 20:35:35 +01:00
|
|
|
|
/* save away the message state again */
|
|
|
|
|
msg->Handle = message_state;
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
TRACE("-- %ld\n", status);
|
|
|
|
|
|
|
|
|
|
return HRESULT_FROM_WIN32(status);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-04 17:25:39 +01:00
|
|
|
|
static HANDLE ClientRpcChannelBuffer_GetEventHandle(ClientRpcChannelBuffer *This)
|
|
|
|
|
{
|
|
|
|
|
HANDLE event = InterlockedExchangePointer(&This->event, NULL);
|
|
|
|
|
|
|
|
|
|
/* Note: must be auto-reset event so we can reuse it without a call
|
|
|
|
|
* to ResetEvent */
|
|
|
|
|
if (!event) event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
|
|
|
|
|
|
|
|
|
return event;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void ClientRpcChannelBuffer_ReleaseEventHandle(ClientRpcChannelBuffer *This, HANDLE event)
|
|
|
|
|
{
|
|
|
|
|
if (InterlockedCompareExchangePointer(&This->event, event, NULL))
|
|
|
|
|
/* already a handle cached in This */
|
|
|
|
|
CloseHandle(event);
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
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;
|
2006-12-19 20:35:35 +01:00
|
|
|
|
ORPCTHIS *orpcthis;
|
|
|
|
|
struct message_state *message_state;
|
2006-12-19 20:35:42 +01:00
|
|
|
|
ULONG extensions_size;
|
|
|
|
|
struct channel_hook_buffer_data *channel_hook_data;
|
|
|
|
|
unsigned int channel_hook_count;
|
|
|
|
|
ULONG extension_count;
|
2008-01-04 17:25:39 +01:00
|
|
|
|
IPID ipid;
|
|
|
|
|
HRESULT hr;
|
|
|
|
|
APARTMENT *apt = NULL;
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
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;
|
|
|
|
|
|
2006-12-19 20:35:35 +01:00
|
|
|
|
message_state = HeapAlloc(GetProcessHeap(), 0, sizeof(*message_state));
|
|
|
|
|
if (!message_state)
|
|
|
|
|
{
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, cif);
|
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
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->Handle = This->bind;
|
2006-12-19 20:35:35 +01:00
|
|
|
|
msg->RpcInterfaceInformation = cif;
|
|
|
|
|
|
2008-01-04 17:25:39 +01:00
|
|
|
|
message_state->prefix_data_len = 0;
|
|
|
|
|
message_state->binding_handle = This->bind;
|
|
|
|
|
|
2006-12-19 20:35:51 +01:00
|
|
|
|
message_state->channel_hook_info.iid = *riid;
|
|
|
|
|
message_state->channel_hook_info.cbSize = sizeof(message_state->channel_hook_info);
|
2006-12-19 20:37:34 +01:00
|
|
|
|
message_state->channel_hook_info.uCausality = COM_CurrentCausalityId();
|
2007-03-27 19:15:41 +02:00
|
|
|
|
message_state->channel_hook_info.dwServerPid = This->server_pid;
|
2006-12-19 20:35:51 +01:00
|
|
|
|
message_state->channel_hook_info.iMethod = msg->ProcNum;
|
|
|
|
|
message_state->channel_hook_info.pObject = NULL; /* only present on server-side */
|
2008-01-04 17:25:39 +01:00
|
|
|
|
message_state->target_hwnd = NULL;
|
|
|
|
|
message_state->target_tid = 0;
|
2007-11-26 23:50:32 +01:00
|
|
|
|
memset(&message_state->params, 0, sizeof(message_state->params));
|
2006-12-19 20:35:42 +01:00
|
|
|
|
|
2006-12-19 20:35:51 +01:00
|
|
|
|
extensions_size = ChannelHooks_ClientGetSize(&message_state->channel_hook_info,
|
2006-12-19 20:35:42 +01:00
|
|
|
|
&channel_hook_data, &channel_hook_count, &extension_count);
|
|
|
|
|
|
2006-12-19 20:35:35 +01:00
|
|
|
|
msg->BufferLength += FIELD_OFFSET(ORPCTHIS, extensions) + 4;
|
2006-12-19 20:35:42 +01:00
|
|
|
|
if (extensions_size)
|
|
|
|
|
{
|
|
|
|
|
msg->BufferLength += FIELD_OFFSET(ORPC_EXTENT_ARRAY, extent) + 2*sizeof(DWORD) + extensions_size;
|
|
|
|
|
if (extension_count & 1)
|
|
|
|
|
msg->BufferLength += FIELD_OFFSET(WIRE_ORPC_EXTENT, data[0]);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-04 17:25:39 +01:00
|
|
|
|
RpcBindingInqObject(message_state->binding_handle, &ipid);
|
|
|
|
|
hr = ipid_get_dispatch_params(&ipid, &apt, &message_state->params.stub,
|
|
|
|
|
&message_state->params.chan,
|
|
|
|
|
&message_state->params.iid,
|
|
|
|
|
&message_state->params.iface);
|
|
|
|
|
if (hr == S_OK)
|
|
|
|
|
{
|
|
|
|
|
/* stub, chan, iface and iid are unneeded in multi-threaded case as we go
|
|
|
|
|
* via the RPC runtime */
|
|
|
|
|
if (apt->multi_threaded)
|
|
|
|
|
{
|
|
|
|
|
IRpcStubBuffer_Release(message_state->params.stub);
|
|
|
|
|
message_state->params.stub = NULL;
|
|
|
|
|
IRpcChannelBuffer_Release(message_state->params.chan);
|
|
|
|
|
message_state->params.chan = NULL;
|
|
|
|
|
message_state->params.iface = NULL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2008-01-07 18:14:54 +01:00
|
|
|
|
message_state->params.bypass_rpcrt = TRUE;
|
2008-01-04 17:25:39 +01:00
|
|
|
|
message_state->target_hwnd = apartment_getwindow(apt);
|
|
|
|
|
message_state->target_tid = apt->tid;
|
|
|
|
|
/* we assume later on that this being non-NULL is the indicator that
|
|
|
|
|
* means call directly instead of going through RPC runtime */
|
|
|
|
|
if (!message_state->target_hwnd)
|
|
|
|
|
ERR("window for apartment %s is NULL\n", wine_dbgstr_longlong(apt->oxid));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (apt) apartment_release(apt);
|
|
|
|
|
message_state->params.handle = ClientRpcChannelBuffer_GetEventHandle(This);
|
|
|
|
|
/* Note: message_state->params.msg is initialised in
|
|
|
|
|
* ClientRpcChannelBuffer_SendReceive */
|
|
|
|
|
|
2008-01-07 18:14:54 +01:00
|
|
|
|
/* shortcut the RPC runtime */
|
|
|
|
|
if (message_state->target_hwnd)
|
|
|
|
|
{
|
|
|
|
|
msg->Buffer = HeapAlloc(GetProcessHeap(), 0, msg->BufferLength);
|
|
|
|
|
if (msg->Buffer)
|
|
|
|
|
status = RPC_S_OK;
|
|
|
|
|
else
|
|
|
|
|
status = ERROR_OUTOFMEMORY;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
status = I_RpcGetBuffer(msg);
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
2006-12-19 20:35:35 +01:00
|
|
|
|
msg->Handle = message_state;
|
|
|
|
|
|
|
|
|
|
if (status == RPC_S_OK)
|
|
|
|
|
{
|
|
|
|
|
orpcthis = (ORPCTHIS *)msg->Buffer;
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer + FIELD_OFFSET(ORPCTHIS, extensions);
|
|
|
|
|
|
|
|
|
|
orpcthis->version.MajorVersion = COM_MAJOR_VERSION;
|
|
|
|
|
orpcthis->version.MinorVersion = COM_MINOR_VERSION;
|
2006-12-19 20:35:51 +01:00
|
|
|
|
orpcthis->flags = message_state->channel_hook_info.dwServerPid ? ORPCF_LOCAL : ORPCF_NULL;
|
2006-12-19 20:35:35 +01:00
|
|
|
|
orpcthis->reserved1 = 0;
|
2006-12-19 20:35:51 +01:00
|
|
|
|
orpcthis->cid = message_state->channel_hook_info.uCausality;
|
2006-12-19 20:35:35 +01:00
|
|
|
|
|
|
|
|
|
/* NDR representation of orpcthis->extensions */
|
2006-12-19 20:35:42 +01:00
|
|
|
|
*(DWORD *)msg->Buffer = extensions_size ? 1 : 0;
|
2006-12-19 20:35:35 +01:00
|
|
|
|
msg->Buffer = (char *)msg->Buffer + sizeof(DWORD);
|
|
|
|
|
|
2006-12-19 20:35:42 +01:00
|
|
|
|
if (extensions_size)
|
|
|
|
|
{
|
|
|
|
|
ORPC_EXTENT_ARRAY *orpc_extent_array = msg->Buffer;
|
|
|
|
|
orpc_extent_array->size = extension_count;
|
|
|
|
|
orpc_extent_array->reserved = 0;
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer + FIELD_OFFSET(ORPC_EXTENT_ARRAY, extent);
|
|
|
|
|
/* NDR representation of orpc_extent_array->extent */
|
|
|
|
|
*(DWORD *)msg->Buffer = 1;
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer + sizeof(DWORD);
|
|
|
|
|
/* NDR representation of [size_is] attribute of orpc_extent_array->extent */
|
|
|
|
|
*(DWORD *)msg->Buffer = (extension_count + 1) & ~1;
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer + sizeof(DWORD);
|
|
|
|
|
|
2006-12-19 20:35:51 +01:00
|
|
|
|
msg->Buffer = ChannelHooks_ClientFillBuffer(&message_state->channel_hook_info,
|
2006-12-19 20:35:42 +01:00
|
|
|
|
msg->Buffer, channel_hook_data, channel_hook_count);
|
|
|
|
|
|
|
|
|
|
/* we must add a dummy extension if there is an odd extension
|
|
|
|
|
* count to meet the contract specified by the size_is attribute */
|
|
|
|
|
if (extension_count & 1)
|
|
|
|
|
{
|
|
|
|
|
WIRE_ORPC_EXTENT *wire_orpc_extent = msg->Buffer;
|
|
|
|
|
wire_orpc_extent->conformance = 0;
|
|
|
|
|
memcpy(&wire_orpc_extent->id, &GUID_NULL, sizeof(wire_orpc_extent->id));
|
|
|
|
|
wire_orpc_extent->size = 0;
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer + FIELD_OFFSET(WIRE_ORPC_EXTENT, data[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-19 20:35:35 +01:00
|
|
|
|
/* store the prefixed data length so that we can restore the real buffer
|
|
|
|
|
* pointer in ClientRpcChannelBuffer_SendReceive. */
|
|
|
|
|
message_state->prefix_data_len = (char *)msg->Buffer - (char *)orpcthis;
|
|
|
|
|
msg->BufferLength -= message_state->prefix_data_len;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-07 18:15:17 +01:00
|
|
|
|
HeapFree(GetProcessHeap(), 0, channel_hook_data);
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
TRACE("-- %ld\n", status);
|
|
|
|
|
|
|
|
|
|
return HRESULT_FROM_WIN32(status);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2006-01-20 16:16:08 +01:00
|
|
|
|
static HRESULT WINAPI ServerRpcChannelBuffer_SendReceive(LPRPCCHANNELBUFFER iface, RPCOLEMESSAGE *olemsg, ULONG *pstatus)
|
|
|
|
|
{
|
|
|
|
|
FIXME("stub\n");
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2006-03-18 17:09:53 +01:00
|
|
|
|
|
2007-01-09 18:14:45 +01:00
|
|
|
|
/* Note: I_RpcSendReceive doesn't raise exceptions like the higher-level
|
|
|
|
|
* RPC functions do */
|
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);
|
2006-03-18 17:09:53 +01:00
|
|
|
|
|
|
|
|
|
SetEvent(data->handle);
|
|
|
|
|
|
2005-03-04 13:30:47 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-20 16:16:08 +01:00
|
|
|
|
static inline HRESULT ClientRpcChannelBuffer_IsCorrectApartment(ClientRpcChannelBuffer *This, APARTMENT *apt)
|
|
|
|
|
{
|
|
|
|
|
OXID oxid;
|
|
|
|
|
if (!apt)
|
|
|
|
|
return S_FALSE;
|
|
|
|
|
if (apartment_getoxid(apt, &oxid) != S_OK)
|
|
|
|
|
return S_FALSE;
|
|
|
|
|
if (This->oxid != oxid)
|
|
|
|
|
return S_FALSE;
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI ClientRpcChannelBuffer_SendReceive(LPRPCCHANNELBUFFER iface, RPCOLEMESSAGE *olemsg, ULONG *pstatus)
|
2005-02-15 16:02:49 +01:00
|
|
|
|
{
|
2006-01-20 16:16:08 +01:00
|
|
|
|
ClientRpcChannelBuffer *This = (ClientRpcChannelBuffer *)iface;
|
|
|
|
|
HRESULT hr;
|
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;
|
2006-12-19 20:35:35 +01:00
|
|
|
|
struct message_state *message_state;
|
2006-12-27 14:04:07 +01:00
|
|
|
|
ORPCTHAT orpcthat;
|
|
|
|
|
ORPC_EXTENT_ARRAY orpc_ext_array;
|
|
|
|
|
WIRE_ORPC_EXTENT *first_wire_orpc_extent = NULL;
|
2007-01-04 17:55:21 +01:00
|
|
|
|
HRESULT hrFault = S_OK;
|
2005-07-19 21:12:47 +02:00
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
|
TRACE("(%p) iMethod=%d\n", olemsg, olemsg->iMethod);
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
2006-01-20 16:16:08 +01:00
|
|
|
|
hr = ClientRpcChannelBuffer_IsCorrectApartment(This, COM_CurrentApt());
|
|
|
|
|
if (hr != S_OK)
|
|
|
|
|
{
|
|
|
|
|
ERR("called from wrong apartment, should have been 0x%s\n",
|
|
|
|
|
wine_dbgstr_longlong(This->oxid));
|
|
|
|
|
return RPC_E_WRONG_THREAD;
|
|
|
|
|
}
|
2006-12-23 16:51:27 +01:00
|
|
|
|
/* this situation should be impossible in multi-threaded apartments,
|
|
|
|
|
* because the calling thread isn't re-entrable.
|
|
|
|
|
* Note: doing a COM call during the processing of a sent message is
|
|
|
|
|
* only disallowed if a client call is already being waited for
|
|
|
|
|
* completion */
|
|
|
|
|
if (!COM_CurrentApt()->multi_threaded &&
|
|
|
|
|
COM_CurrentInfo()->pending_call_count_client &&
|
|
|
|
|
InSendMessage())
|
|
|
|
|
{
|
|
|
|
|
ERR("can't make an outgoing COM call in response to a sent message\n");
|
|
|
|
|
return RPC_E_CANTCALLOUT_ININPUTSYNCCALL;
|
|
|
|
|
}
|
2006-01-20 16:16:08 +01:00
|
|
|
|
|
2006-12-19 20:35:35 +01:00
|
|
|
|
message_state = (struct message_state *)msg->Handle;
|
|
|
|
|
/* restore the binding handle and the real start of data */
|
|
|
|
|
msg->Handle = message_state->binding_handle;
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer - message_state->prefix_data_len;
|
|
|
|
|
msg->BufferLength += message_state->prefix_data_len;
|
|
|
|
|
|
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 */
|
|
|
|
|
|
2008-01-04 17:25:39 +01:00
|
|
|
|
message_state->params.msg = olemsg;
|
2008-01-07 18:14:54 +01:00
|
|
|
|
if (message_state->params.bypass_rpcrt)
|
2005-07-19 21:12:47 +02:00
|
|
|
|
{
|
2008-01-04 17:25:39 +01:00
|
|
|
|
TRACE("Calling apartment thread 0x%08x...\n", message_state->target_tid);
|
2005-07-19 21:12:47 +02:00
|
|
|
|
|
2008-01-07 18:09:52 +01:00
|
|
|
|
msg->ProcNum &= ~RPC_FLAGS_VALID_BIT;
|
|
|
|
|
|
2008-01-04 17:25:39 +01:00
|
|
|
|
if (!PostMessageW(message_state->target_hwnd, DM_EXECUTERPC, 0,
|
2007-11-26 23:50:32 +01:00
|
|
|
|
(LPARAM)&message_state->params))
|
2006-01-10 20:08:22 +01:00
|
|
|
|
{
|
2007-01-05 21:49:31 +01:00
|
|
|
|
ERR("PostMessage failed with error %u\n", GetLastError());
|
2007-11-26 23:50:48 +01:00
|
|
|
|
|
|
|
|
|
/* Note: message_state->params.iface doesn't have a reference and
|
|
|
|
|
* so doesn't need to be released */
|
|
|
|
|
|
2006-01-10 20:08:22 +01:00
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
|
}
|
2005-07-19 21:12:47 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
2005-03-04 13:30:47 +01:00
|
|
|
|
{
|
2005-07-19 21:12:47 +02:00
|
|
|
|
/* 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.
|
|
|
|
|
*/
|
2007-11-26 23:50:32 +01:00
|
|
|
|
if (!QueueUserWorkItem(rpc_sendreceive_thread, &message_state->params, WT_EXECUTEDEFAULT))
|
2005-07-19 21:12:47 +02:00
|
|
|
|
{
|
2007-01-05 21:49:31 +01:00
|
|
|
|
ERR("QueueUserWorkItem failed with error %u\n", GetLastError());
|
2005-07-19 21:12:47 +02:00
|
|
|
|
hr = E_UNEXPECTED;
|
|
|
|
|
}
|
2006-01-10 20:08:02 +01:00
|
|
|
|
else
|
|
|
|
|
hr = S_OK;
|
2005-03-04 13:30:47 +01:00
|
|
|
|
}
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
2005-03-17 11:26:20 +01:00
|
|
|
|
if (hr == S_OK)
|
2006-01-14 17:45:49 +01:00
|
|
|
|
{
|
2007-11-26 23:50:32 +01:00
|
|
|
|
if (WaitForSingleObject(message_state->params.handle, 0))
|
2006-12-23 16:51:27 +01:00
|
|
|
|
{
|
|
|
|
|
COM_CurrentInfo()->pending_call_count_client++;
|
2007-11-26 23:50:32 +01:00
|
|
|
|
hr = CoWaitForMultipleHandles(0, INFINITE, 1, &message_state->params.handle, &index);
|
2006-12-23 16:51:27 +01:00
|
|
|
|
COM_CurrentInfo()->pending_call_count_client--;
|
|
|
|
|
}
|
2006-01-14 17:45:49 +01:00
|
|
|
|
}
|
2007-11-26 23:50:32 +01:00
|
|
|
|
ClientRpcChannelBuffer_ReleaseEventHandle(This, message_state->params.handle);
|
2005-03-04 13:30:47 +01:00
|
|
|
|
|
2007-01-04 17:55:21 +01:00
|
|
|
|
/* for WM shortcut, faults are returned in params->hr */
|
|
|
|
|
if (hr == S_OK)
|
2007-11-26 23:50:32 +01:00
|
|
|
|
hrFault = message_state->params.hr;
|
2005-09-14 12:07:01 +02:00
|
|
|
|
|
2007-11-26 23:50:32 +01:00
|
|
|
|
status = message_state->params.status;
|
2005-03-17 11:26:20 +01:00
|
|
|
|
|
2006-12-27 14:04:07 +01:00
|
|
|
|
orpcthat.flags = ORPCF_NULL;
|
|
|
|
|
orpcthat.extensions = NULL;
|
|
|
|
|
|
2007-01-04 17:55:21 +01:00
|
|
|
|
TRACE("RPC call status: 0x%lx\n", status);
|
2008-01-21 23:54:43 +01:00
|
|
|
|
if (status != RPC_S_OK)
|
2007-01-04 17:55:21 +01:00
|
|
|
|
hr = HRESULT_FROM_WIN32(status);
|
|
|
|
|
|
|
|
|
|
TRACE("hrFault = 0x%08x\n", hrFault);
|
|
|
|
|
|
|
|
|
|
/* FIXME: this condition should be
|
2007-01-18 11:35:50 +01:00
|
|
|
|
* "hr == S_OK && (!hrFault || msg->BufferLength > FIELD_OFFSET(ORPCTHAT, extensions) + 4)"
|
2007-01-04 17:55:21 +01:00
|
|
|
|
* but we don't currently reset the message length for PostMessage
|
|
|
|
|
* dispatched calls */
|
|
|
|
|
if (hr == S_OK && hrFault == S_OK)
|
2006-12-27 14:04:07 +01:00
|
|
|
|
{
|
|
|
|
|
HRESULT hr2;
|
|
|
|
|
char *original_buffer = msg->Buffer;
|
|
|
|
|
|
|
|
|
|
/* handle ORPCTHAT and client extensions */
|
|
|
|
|
|
|
|
|
|
hr2 = unmarshal_ORPCTHAT(msg, &orpcthat, &orpc_ext_array, &first_wire_orpc_extent);
|
|
|
|
|
if (FAILED(hr2))
|
|
|
|
|
hr = hr2;
|
|
|
|
|
|
2007-01-02 19:08:49 +01:00
|
|
|
|
message_state->prefix_data_len = (char *)msg->Buffer - original_buffer;
|
2006-12-27 14:04:07 +01:00
|
|
|
|
msg->BufferLength -= message_state->prefix_data_len;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
message_state->prefix_data_len = 0;
|
|
|
|
|
|
2007-01-04 17:55:21 +01:00
|
|
|
|
if (hr == S_OK)
|
|
|
|
|
{
|
|
|
|
|
ChannelHooks_ClientNotify(&message_state->channel_hook_info,
|
|
|
|
|
msg->DataRepresentation,
|
|
|
|
|
first_wire_orpc_extent,
|
|
|
|
|
orpcthat.extensions && first_wire_orpc_extent ? orpcthat.extensions->size : 0,
|
|
|
|
|
hrFault);
|
|
|
|
|
}
|
2006-12-27 14:04:07 +01:00
|
|
|
|
|
|
|
|
|
/* save away the message state again */
|
|
|
|
|
msg->Handle = message_state;
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
if (pstatus) *pstatus = status;
|
|
|
|
|
|
2007-01-04 17:55:21 +01:00
|
|
|
|
if (hr == S_OK)
|
|
|
|
|
hr = hrFault;
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
|
TRACE("-- 0x%08x\n", hr);
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
|
|
|
|
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;
|
2006-12-19 20:35:35 +01:00
|
|
|
|
struct message_state *message_state;
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
|
|
|
|
TRACE("(%p)\n", msg);
|
|
|
|
|
|
2006-12-19 20:35:35 +01:00
|
|
|
|
message_state = (struct message_state *)msg->Handle;
|
|
|
|
|
/* restore the binding handle and the real start of data */
|
|
|
|
|
msg->Handle = message_state->binding_handle;
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer - message_state->prefix_data_len;
|
|
|
|
|
msg->BufferLength += message_state->prefix_data_len;
|
|
|
|
|
message_state->prefix_data_len = 0;
|
|
|
|
|
|
2008-01-07 18:14:54 +01:00
|
|
|
|
if (message_state->bypass_rpcrt)
|
|
|
|
|
{
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, msg->Buffer);
|
|
|
|
|
status = RPC_S_OK;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
status = I_RpcFreeBuffer(msg);
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
2006-12-19 20:35:35 +01:00
|
|
|
|
msg->Handle = message_state;
|
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
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;
|
2006-12-19 20:35:35 +01:00
|
|
|
|
struct message_state *message_state;
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
|
|
|
|
TRACE("(%p)\n", msg);
|
|
|
|
|
|
2006-12-19 20:35:35 +01:00
|
|
|
|
message_state = (struct message_state *)msg->Handle;
|
|
|
|
|
/* restore the binding handle and the real start of data */
|
|
|
|
|
msg->Handle = message_state->binding_handle;
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer - message_state->prefix_data_len;
|
|
|
|
|
msg->BufferLength += message_state->prefix_data_len;
|
|
|
|
|
|
2008-01-07 18:14:54 +01:00
|
|
|
|
if (message_state->params.bypass_rpcrt)
|
|
|
|
|
{
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, msg->Buffer);
|
|
|
|
|
status = RPC_S_OK;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
status = I_RpcFreeBuffer(msg);
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, msg->RpcInterfaceInformation);
|
|
|
|
|
msg->RpcInterfaceInformation = NULL;
|
2008-01-04 17:25:39 +01:00
|
|
|
|
|
|
|
|
|
if (message_state->params.stub)
|
|
|
|
|
IRpcStubBuffer_Release(message_state->params.stub);
|
|
|
|
|
if (message_state->params.chan)
|
|
|
|
|
IRpcChannelBuffer_Release(message_state->params.chan);
|
2006-12-19 20:35:35 +01:00
|
|
|
|
HeapFree(GetProcessHeap(), 0, message_state);
|
2005-02-15 16:02:49 +01:00
|
|
|
|
|
|
|
|
|
TRACE("-- %ld\n", status);
|
|
|
|
|
|
|
|
|
|
return HRESULT_FROM_WIN32(status);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2006-03-05 14:37:34 +01:00
|
|
|
|
static HRESULT WINAPI ClientRpcChannelBuffer_GetDestCtx(LPRPCCHANNELBUFFER iface, DWORD* pdwDestContext, void** ppvDestContext)
|
|
|
|
|
{
|
|
|
|
|
ClientRpcChannelBuffer *This = (ClientRpcChannelBuffer *)iface;
|
|
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", pdwDestContext, ppvDestContext);
|
|
|
|
|
|
|
|
|
|
*pdwDestContext = This->dest_context;
|
|
|
|
|
*ppvDestContext = This->dest_context_data;
|
|
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI ServerRpcChannelBuffer_GetDestCtx(LPRPCCHANNELBUFFER iface, DWORD* pdwDestContext, void** ppvDestContext)
|
2005-02-15 16:02:49 +01:00
|
|
|
|
{
|
2008-01-15 13:09:57 +01:00
|
|
|
|
WARN("(%p,%p), stub!\n", pdwDestContext, ppvDestContext);
|
|
|
|
|
|
|
|
|
|
/* FIXME: implement this by storing the dwDestContext and pvDestContext
|
|
|
|
|
* values passed into IMarshal_MarshalInterface and returning them here */
|
|
|
|
|
*pdwDestContext = MSHCTX_DIFFERENTMACHINE;
|
|
|
|
|
*ppvDestContext = NULL;
|
|
|
|
|
return S_OK;
|
2005-02-15 16:02:49 +01:00
|
|
|
|
}
|
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,
|
2006-01-20 16:16:08 +01:00
|
|
|
|
ClientRpcChannelBuffer_SendReceive,
|
2005-02-15 16:02:49 +01:00
|
|
|
|
ClientRpcChannelBuffer_FreeBuffer,
|
2006-03-05 14:37:34 +01:00
|
|
|
|
ClientRpcChannelBuffer_GetDestCtx,
|
2005-02-15 16:02:49 +01:00
|
|
|
|
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,
|
2006-01-20 16:16:08 +01:00
|
|
|
|
ServerRpcChannelBuffer_SendReceive,
|
2005-02-15 16:02:49 +01:00
|
|
|
|
ServerRpcChannelBuffer_FreeBuffer,
|
2006-03-05 14:37:34 +01:00
|
|
|
|
ServerRpcChannelBuffer_GetDestCtx,
|
2005-02-15 16:02:49 +01:00
|
|
|
|
RpcChannelBuffer_IsConnected
|
|
|
|
|
};
|
2005-02-08 13:55:26 +01:00
|
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
|
/* returns a channel buffer for proxies */
|
2006-03-05 14:37:34 +01:00
|
|
|
|
HRESULT RPC_CreateClientChannel(const OXID *oxid, const IPID *ipid,
|
2007-03-27 19:15:41 +02:00
|
|
|
|
const OXID_INFO *oxid_info,
|
2006-03-05 14:37:34 +01:00
|
|
|
|
DWORD dest_context, void *dest_context_data,
|
|
|
|
|
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;
|
|
|
|
|
|
2007-03-27 19:15:41 +02:00
|
|
|
|
/* FIXME: get the endpoint from oxid_info->psa instead */
|
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,
|
2006-03-31 13:34:25 +02:00
|
|
|
|
wszRpcTransport,
|
2005-02-15 16:02:49 +01:00
|
|
|
|
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;
|
2006-01-20 16:16:08 +01:00
|
|
|
|
apartment_getoxid(COM_CurrentApt(), &This->oxid);
|
2007-03-27 19:15:41 +02:00
|
|
|
|
This->server_pid = oxid_info->dwPid;
|
2006-03-05 14:37:34 +01:00
|
|
|
|
This->dest_context = dest_context;
|
|
|
|
|
This->dest_context_data = dest_context_data;
|
2006-06-17 13:31:44 +02:00
|
|
|
|
This->event = NULL;
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-27 14:04:07 +01:00
|
|
|
|
/* unmarshals ORPC_EXTENT_ARRAY according to NDR rules, but doesn't allocate
|
|
|
|
|
* any memory */
|
|
|
|
|
static HRESULT unmarshal_ORPC_EXTENT_ARRAY(RPC_MESSAGE *msg, const char *end,
|
|
|
|
|
ORPC_EXTENT_ARRAY *extensions,
|
|
|
|
|
WIRE_ORPC_EXTENT **first_wire_orpc_extent)
|
|
|
|
|
{
|
|
|
|
|
DWORD pointer_id;
|
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
|
|
memcpy(extensions, msg->Buffer, FIELD_OFFSET(ORPC_EXTENT_ARRAY, extent));
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer + FIELD_OFFSET(ORPC_EXTENT_ARRAY, extent);
|
|
|
|
|
|
|
|
|
|
if ((const char *)msg->Buffer + 2 * sizeof(DWORD) > end)
|
|
|
|
|
return RPC_E_INVALID_HEADER;
|
|
|
|
|
|
|
|
|
|
pointer_id = *(DWORD *)msg->Buffer;
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer + sizeof(DWORD);
|
|
|
|
|
extensions->extent = NULL;
|
|
|
|
|
|
|
|
|
|
if (pointer_id)
|
|
|
|
|
{
|
|
|
|
|
WIRE_ORPC_EXTENT *wire_orpc_extent;
|
|
|
|
|
|
|
|
|
|
/* conformance */
|
|
|
|
|
if (*(DWORD *)msg->Buffer != ((extensions->size+1)&~1))
|
|
|
|
|
return RPC_S_INVALID_BOUND;
|
|
|
|
|
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer + sizeof(DWORD);
|
|
|
|
|
|
|
|
|
|
/* arbritary limit for security (don't know what native does) */
|
|
|
|
|
if (extensions->size > 256)
|
|
|
|
|
{
|
|
|
|
|
ERR("too many extensions: %ld\n", extensions->size);
|
|
|
|
|
return RPC_S_INVALID_BOUND;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*first_wire_orpc_extent = wire_orpc_extent = (WIRE_ORPC_EXTENT *)msg->Buffer;
|
|
|
|
|
for (i = 0; i < ((extensions->size+1)&~1); i++)
|
|
|
|
|
{
|
|
|
|
|
if ((const char *)&wire_orpc_extent->data[0] > end)
|
|
|
|
|
return RPC_S_INVALID_BOUND;
|
|
|
|
|
if (wire_orpc_extent->conformance != ((wire_orpc_extent->size+7)&~7))
|
|
|
|
|
return RPC_S_INVALID_BOUND;
|
|
|
|
|
if ((const char *)&wire_orpc_extent->data[wire_orpc_extent->conformance] > end)
|
|
|
|
|
return RPC_S_INVALID_BOUND;
|
|
|
|
|
TRACE("size %u, guid %s\n", wire_orpc_extent->size, debugstr_guid(&wire_orpc_extent->id));
|
|
|
|
|
wire_orpc_extent = (WIRE_ORPC_EXTENT *)&wire_orpc_extent->data[wire_orpc_extent->conformance];
|
|
|
|
|
}
|
|
|
|
|
msg->Buffer = wire_orpc_extent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-19 20:35:35 +01:00
|
|
|
|
/* unmarshals ORPCTHIS according to NDR rules, but doesn't allocate any memory */
|
|
|
|
|
static HRESULT unmarshal_ORPCTHIS(RPC_MESSAGE *msg, ORPCTHIS *orpcthis,
|
|
|
|
|
ORPC_EXTENT_ARRAY *orpc_ext_array, WIRE_ORPC_EXTENT **first_wire_orpc_extent)
|
|
|
|
|
{
|
|
|
|
|
const char *end = (char *)msg->Buffer + msg->BufferLength;
|
|
|
|
|
|
|
|
|
|
*first_wire_orpc_extent = NULL;
|
|
|
|
|
|
|
|
|
|
if (msg->BufferLength < FIELD_OFFSET(ORPCTHIS, extensions) + 4)
|
|
|
|
|
{
|
|
|
|
|
ERR("invalid buffer length\n");
|
|
|
|
|
return RPC_E_INVALID_HEADER;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy(orpcthis, msg->Buffer, FIELD_OFFSET(ORPCTHIS, extensions));
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer + FIELD_OFFSET(ORPCTHIS, extensions);
|
|
|
|
|
|
|
|
|
|
if ((const char *)msg->Buffer + sizeof(DWORD) > end)
|
|
|
|
|
return RPC_E_INVALID_HEADER;
|
|
|
|
|
|
|
|
|
|
if (*(DWORD *)msg->Buffer)
|
|
|
|
|
orpcthis->extensions = orpc_ext_array;
|
|
|
|
|
else
|
|
|
|
|
orpcthis->extensions = NULL;
|
|
|
|
|
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer + sizeof(DWORD);
|
|
|
|
|
|
|
|
|
|
if (orpcthis->extensions)
|
|
|
|
|
{
|
2006-12-27 14:04:07 +01:00
|
|
|
|
HRESULT hr = unmarshal_ORPC_EXTENT_ARRAY(msg, end, orpc_ext_array,
|
|
|
|
|
first_wire_orpc_extent);
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
|
return hr;
|
2006-12-19 20:35:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((orpcthis->version.MajorVersion != COM_MAJOR_VERSION) ||
|
|
|
|
|
(orpcthis->version.MinorVersion > COM_MINOR_VERSION))
|
|
|
|
|
{
|
|
|
|
|
ERR("COM version {%d, %d} not supported\n",
|
|
|
|
|
orpcthis->version.MajorVersion, orpcthis->version.MinorVersion);
|
|
|
|
|
return RPC_E_VERSION_MISMATCH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (orpcthis->flags & ~(ORPCF_LOCAL|ORPCF_RESERVED1|ORPCF_RESERVED2|ORPCF_RESERVED3|ORPCF_RESERVED4))
|
|
|
|
|
{
|
|
|
|
|
ERR("invalid flags 0x%lx\n", orpcthis->flags & ~(ORPCF_LOCAL|ORPCF_RESERVED1|ORPCF_RESERVED2|ORPCF_RESERVED3|ORPCF_RESERVED4));
|
|
|
|
|
return RPC_E_INVALID_HEADER;
|
2006-12-27 14:04:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT unmarshal_ORPCTHAT(RPC_MESSAGE *msg, ORPCTHAT *orpcthat,
|
|
|
|
|
ORPC_EXTENT_ARRAY *orpc_ext_array, WIRE_ORPC_EXTENT **first_wire_orpc_extent)
|
|
|
|
|
{
|
|
|
|
|
const char *end = (char *)msg->Buffer + msg->BufferLength;
|
|
|
|
|
|
|
|
|
|
*first_wire_orpc_extent = NULL;
|
|
|
|
|
|
|
|
|
|
if (msg->BufferLength < FIELD_OFFSET(ORPCTHAT, extensions) + 4)
|
|
|
|
|
{
|
|
|
|
|
ERR("invalid buffer length\n");
|
|
|
|
|
return RPC_E_INVALID_HEADER;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy(orpcthat, msg->Buffer, FIELD_OFFSET(ORPCTHAT, extensions));
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer + FIELD_OFFSET(ORPCTHAT, extensions);
|
|
|
|
|
|
|
|
|
|
if ((const char *)msg->Buffer + sizeof(DWORD) > end)
|
|
|
|
|
return RPC_E_INVALID_HEADER;
|
|
|
|
|
|
|
|
|
|
if (*(DWORD *)msg->Buffer)
|
|
|
|
|
orpcthat->extensions = orpc_ext_array;
|
|
|
|
|
else
|
|
|
|
|
orpcthat->extensions = NULL;
|
|
|
|
|
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer + sizeof(DWORD);
|
|
|
|
|
|
|
|
|
|
if (orpcthat->extensions)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr = unmarshal_ORPC_EXTENT_ARRAY(msg, end, orpc_ext_array,
|
|
|
|
|
first_wire_orpc_extent);
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
|
return hr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (orpcthat->flags & ~(ORPCF_LOCAL|ORPCF_RESERVED1|ORPCF_RESERVED2|ORPCF_RESERVED3|ORPCF_RESERVED4))
|
|
|
|
|
{
|
|
|
|
|
ERR("invalid flags 0x%lx\n", orpcthat->flags & ~(ORPCF_LOCAL|ORPCF_RESERVED1|ORPCF_RESERVED2|ORPCF_RESERVED3|ORPCF_RESERVED4));
|
|
|
|
|
return RPC_E_INVALID_HEADER;
|
2006-12-19 20:35:35 +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
|
|
|
|
{
|
2006-12-19 20:37:09 +01:00
|
|
|
|
struct message_state *message_state = NULL;
|
2006-12-19 20:35:35 +01:00
|
|
|
|
RPC_MESSAGE *msg = (RPC_MESSAGE *)params->msg;
|
|
|
|
|
char *original_buffer = msg->Buffer;
|
|
|
|
|
ORPCTHIS orpcthis;
|
|
|
|
|
ORPC_EXTENT_ARRAY orpc_ext_array;
|
|
|
|
|
WIRE_ORPC_EXTENT *first_wire_orpc_extent;
|
2006-12-19 20:37:34 +01:00
|
|
|
|
GUID old_causality_id;
|
2006-12-19 20:35:35 +01:00
|
|
|
|
|
2006-12-19 20:37:09 +01:00
|
|
|
|
/* handle ORPCTHIS and server extensions */
|
|
|
|
|
|
2006-12-19 20:35:35 +01:00
|
|
|
|
params->hr = unmarshal_ORPCTHIS(msg, &orpcthis, &orpc_ext_array, &first_wire_orpc_extent);
|
|
|
|
|
if (params->hr != S_OK)
|
2007-01-04 17:55:21 +01:00
|
|
|
|
{
|
|
|
|
|
msg->Buffer = original_buffer;
|
2006-12-19 20:35:35 +01:00
|
|
|
|
goto exit;
|
2007-01-04 17:55:21 +01:00
|
|
|
|
}
|
2006-12-19 20:35:35 +01:00
|
|
|
|
|
|
|
|
|
message_state = HeapAlloc(GetProcessHeap(), 0, sizeof(*message_state));
|
|
|
|
|
if (!message_state)
|
|
|
|
|
{
|
|
|
|
|
params->hr = E_OUTOFMEMORY;
|
2007-01-04 17:55:21 +01:00
|
|
|
|
msg->Buffer = original_buffer;
|
2006-12-19 20:35:35 +01:00
|
|
|
|
goto exit;
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-02 19:08:49 +01:00
|
|
|
|
message_state->prefix_data_len = (char *)msg->Buffer - original_buffer;
|
2006-12-19 20:35:35 +01:00
|
|
|
|
message_state->binding_handle = msg->Handle;
|
2008-01-07 18:14:54 +01:00
|
|
|
|
message_state->bypass_rpcrt = params->bypass_rpcrt;
|
2006-12-19 20:35:51 +01:00
|
|
|
|
|
2006-12-19 20:37:15 +01:00
|
|
|
|
message_state->channel_hook_info.iid = params->iid;
|
2006-12-19 20:35:51 +01:00
|
|
|
|
message_state->channel_hook_info.cbSize = sizeof(message_state->channel_hook_info);
|
|
|
|
|
message_state->channel_hook_info.uCausality = orpcthis.cid;
|
|
|
|
|
message_state->channel_hook_info.dwServerPid = GetCurrentProcessId();
|
|
|
|
|
message_state->channel_hook_info.iMethod = msg->ProcNum;
|
2006-12-19 20:37:15 +01:00
|
|
|
|
message_state->channel_hook_info.pObject = params->iface;
|
2006-12-19 20:35:51 +01:00
|
|
|
|
|
|
|
|
|
if (orpcthis.extensions && first_wire_orpc_extent &&
|
|
|
|
|
orpcthis.extensions->size)
|
|
|
|
|
ChannelHooks_ServerNotify(&message_state->channel_hook_info, msg->DataRepresentation, first_wire_orpc_extent, orpcthis.extensions->size);
|
|
|
|
|
|
2006-12-19 20:35:35 +01:00
|
|
|
|
msg->Handle = message_state;
|
|
|
|
|
msg->BufferLength -= message_state->prefix_data_len;
|
|
|
|
|
|
2006-12-19 20:37:09 +01:00
|
|
|
|
/* call message filter */
|
|
|
|
|
|
|
|
|
|
if (COM_CurrentApt()->filter)
|
|
|
|
|
{
|
|
|
|
|
DWORD handlecall;
|
|
|
|
|
INTERFACEINFO interface_info;
|
2006-12-19 20:37:34 +01:00
|
|
|
|
CALLTYPE calltype;
|
2006-12-19 20:37:09 +01:00
|
|
|
|
|
2006-12-19 20:37:15 +01:00
|
|
|
|
interface_info.pUnk = params->iface;
|
|
|
|
|
interface_info.iid = params->iid;
|
2006-12-19 20:37:09 +01:00
|
|
|
|
interface_info.wMethod = msg->ProcNum;
|
2006-12-23 16:49:47 +01:00
|
|
|
|
|
2006-12-19 20:37:34 +01:00
|
|
|
|
if (IsEqualGUID(&orpcthis.cid, &COM_CurrentInfo()->causality_id))
|
|
|
|
|
calltype = CALLTYPE_NESTED;
|
2006-12-23 16:51:27 +01:00
|
|
|
|
else if (COM_CurrentInfo()->pending_call_count_server == 0)
|
2006-12-19 20:37:34 +01:00
|
|
|
|
calltype = CALLTYPE_TOPLEVEL;
|
2006-12-23 16:49:47 +01:00
|
|
|
|
else
|
|
|
|
|
calltype = CALLTYPE_TOPLEVEL_CALLPENDING;
|
|
|
|
|
|
2006-12-19 20:37:09 +01:00
|
|
|
|
handlecall = IMessageFilter_HandleInComingCall(COM_CurrentApt()->filter,
|
2006-12-19 20:37:34 +01:00
|
|
|
|
calltype,
|
2006-12-19 20:37:09 +01:00
|
|
|
|
(HTASK)GetCurrentProcessId(),
|
|
|
|
|
0 /* FIXME */,
|
|
|
|
|
&interface_info);
|
|
|
|
|
TRACE("IMessageFilter_HandleInComingCall returned %d\n", handlecall);
|
|
|
|
|
switch (handlecall)
|
|
|
|
|
{
|
|
|
|
|
case SERVERCALL_REJECTED:
|
|
|
|
|
params->hr = RPC_E_CALL_REJECTED;
|
2007-01-04 17:55:21 +01:00
|
|
|
|
goto exit_reset_state;
|
2006-12-19 20:37:09 +01:00
|
|
|
|
case SERVERCALL_RETRYLATER:
|
|
|
|
|
#if 0 /* FIXME: handle retries on the client side before enabling this code */
|
|
|
|
|
params->hr = RPC_E_RETRY;
|
2007-01-04 17:55:21 +01:00
|
|
|
|
goto exit_reset_state;
|
2006-12-19 20:37:09 +01:00
|
|
|
|
#else
|
|
|
|
|
FIXME("retry call later not implemented\n");
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
case SERVERCALL_ISHANDLED:
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-19 20:35:35 +01:00
|
|
|
|
/* invoke the method */
|
|
|
|
|
|
2006-12-19 20:37:34 +01:00
|
|
|
|
/* save the old causality ID - note: any calls executed while processing
|
|
|
|
|
* messages received during the SendReceive will appear to originate from
|
|
|
|
|
* this call - this should be checked with what Windows does */
|
|
|
|
|
old_causality_id = COM_CurrentInfo()->causality_id;
|
|
|
|
|
COM_CurrentInfo()->causality_id = orpcthis.cid;
|
2006-12-23 16:51:27 +01:00
|
|
|
|
COM_CurrentInfo()->pending_call_count_server++;
|
2006-05-10 14:11:49 +02:00
|
|
|
|
params->hr = IRpcStubBuffer_Invoke(params->stub, params->msg, params->chan);
|
2006-12-23 16:51:27 +01:00
|
|
|
|
COM_CurrentInfo()->pending_call_count_server--;
|
2006-12-19 20:37:34 +01:00
|
|
|
|
COM_CurrentInfo()->causality_id = old_causality_id;
|
2006-05-10 14:11:49 +02:00
|
|
|
|
|
2008-01-07 18:14:54 +01:00
|
|
|
|
/* the invoke allocated a new buffer, so free the old one */
|
|
|
|
|
if (message_state->bypass_rpcrt && original_buffer != msg->Buffer)
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, original_buffer);
|
|
|
|
|
|
2007-01-04 17:55:21 +01:00
|
|
|
|
exit_reset_state:
|
2006-12-19 20:35:35 +01:00
|
|
|
|
message_state = (struct message_state *)msg->Handle;
|
|
|
|
|
msg->Handle = message_state->binding_handle;
|
|
|
|
|
msg->Buffer = (char *)msg->Buffer - message_state->prefix_data_len;
|
|
|
|
|
msg->BufferLength += message_state->prefix_data_len;
|
|
|
|
|
|
|
|
|
|
exit:
|
2006-12-19 20:37:09 +01:00
|
|
|
|
HeapFree(GetProcessHeap(), 0, message_state);
|
2005-03-17 11:26:20 +01:00
|
|
|
|
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;
|
2006-01-10 20:08:02 +01:00
|
|
|
|
APARTMENT *apt;
|
|
|
|
|
IPID ipid;
|
|
|
|
|
HRESULT hr;
|
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);
|
|
|
|
|
|
2006-01-10 20:08:02 +01:00
|
|
|
|
params = HeapAlloc(GetProcessHeap(), 0, sizeof(*params));
|
2007-04-12 22:30:19 +02:00
|
|
|
|
if (!params)
|
|
|
|
|
{
|
|
|
|
|
RpcRaiseException(E_OUTOFMEMORY);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2005-03-17 11:26:20 +01:00
|
|
|
|
|
2006-12-19 20:37:15 +01:00
|
|
|
|
hr = ipid_get_dispatch_params(&ipid, &apt, ¶ms->stub, ¶ms->chan,
|
|
|
|
|
¶ms->iid, ¶ms->iface);
|
2006-01-10 20:08:02 +01:00
|
|
|
|
if (hr != S_OK)
|
2005-02-14 12:50:51 +01:00
|
|
|
|
{
|
2005-07-19 21:42:33 +02:00
|
|
|
|
ERR("no apartment found for ipid %s\n", debugstr_guid(&ipid));
|
2006-10-26 13:38:54 +02:00
|
|
|
|
HeapFree(GetProcessHeap(), 0, params);
|
2007-04-12 22:30:19 +02:00
|
|
|
|
RpcRaiseException(hr);
|
|
|
|
|
return;
|
2005-02-14 12:50:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-17 11:26:20 +01:00
|
|
|
|
params->msg = (RPCOLEMESSAGE *)msg;
|
|
|
|
|
params->status = RPC_S_OK;
|
2006-01-10 20:08:02 +01:00
|
|
|
|
params->hr = S_OK;
|
|
|
|
|
params->handle = NULL;
|
2008-01-07 18:14:54 +01:00
|
|
|
|
params->bypass_rpcrt = FALSE;
|
2005-03-17 11:26:20 +01:00
|
|
|
|
|
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) */
|
2006-02-20 11:15:57 +01:00
|
|
|
|
if (!apt->multi_threaded)
|
2005-03-17 11:26:20 +01:00
|
|
|
|
{
|
|
|
|
|
params->handle = CreateEventW(NULL, FALSE, FALSE, NULL);
|
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
|
TRACE("Calling apartment thread 0x%08x...\n", apt->tid);
|
2005-03-17 11:26:20 +01:00
|
|
|
|
|
2006-01-10 20:08:41 +01:00
|
|
|
|
if (PostMessageW(apartment_getwindow(apt), DM_EXECUTERPC, 0, (LPARAM)params))
|
2006-01-10 20:08:22 +01:00
|
|
|
|
WaitForSingleObject(params->handle, INFINITE);
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-01-05 21:49:31 +01:00
|
|
|
|
ERR("PostMessage failed with error %u\n", GetLastError());
|
2006-01-10 20:08:22 +01:00
|
|
|
|
IRpcChannelBuffer_Release(params->chan);
|
|
|
|
|
IRpcStubBuffer_Release(params->stub);
|
|
|
|
|
}
|
2005-03-17 11:26:20 +01:00
|
|
|
|
CloseHandle(params->handle);
|
|
|
|
|
}
|
2005-02-14 12:50:51 +01:00
|
|
|
|
else
|
2006-01-09 18:41:19 +01:00
|
|
|
|
{
|
|
|
|
|
BOOL joined = FALSE;
|
|
|
|
|
if (!COM_CurrentInfo()->apt)
|
|
|
|
|
{
|
|
|
|
|
apartment_joinmta();
|
|
|
|
|
joined = TRUE;
|
|
|
|
|
}
|
2005-03-17 11:26:20 +01:00
|
|
|
|
RPC_ExecuteCall(params);
|
2006-01-09 18:41:19 +01:00
|
|
|
|
if (joined)
|
|
|
|
|
{
|
|
|
|
|
apartment_release(COM_CurrentInfo()->apt);
|
|
|
|
|
COM_CurrentInfo()->apt = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-03-17 11:26:20 +01:00
|
|
|
|
|
2006-06-09 18:25:26 +02:00
|
|
|
|
hr = params->hr;
|
2008-01-04 17:25:39 +01:00
|
|
|
|
if (params->chan)
|
|
|
|
|
IRpcChannelBuffer_Release(params->chan);
|
|
|
|
|
if (params->stub)
|
|
|
|
|
IRpcStubBuffer_Release(params->stub);
|
2005-03-17 11:26:20 +01:00
|
|
|
|
HeapFree(GetProcessHeap(), 0, params);
|
2005-02-14 12:50:51 +01:00
|
|
|
|
|
2005-03-11 11:19:10 +01:00
|
|
|
|
apartment_release(apt);
|
2006-06-09 18:25:26 +02:00
|
|
|
|
|
|
|
|
|
/* if IRpcStubBuffer_Invoke fails, we should raise an exception to tell
|
|
|
|
|
* the RPC runtime that the call failed */
|
|
|
|
|
if (hr) RpcRaiseException(hr);
|
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)
|
|
|
|
|
{
|
2006-11-13 12:55:56 +01:00
|
|
|
|
RpcServerUnregisterIf((RPC_IF_HANDLE)&rif->If, NULL, TRUE);
|
2005-02-15 16:02:49 +01:00
|
|
|
|
list_remove(&rif->entry);
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, rif);
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2007-03-27 19:15:41 +02:00
|
|
|
|
/* get the info for an OXID, including the IPID for the rem unknown interface
|
|
|
|
|
* and the string binding */
|
2007-03-26 19:23:16 +02:00
|
|
|
|
HRESULT RPC_ResolveOxid(OXID oxid, OXID_INFO *oxid_info)
|
|
|
|
|
{
|
2007-03-27 19:15:41 +02:00
|
|
|
|
TRACE("%s\n", wine_dbgstr_longlong(oxid));
|
|
|
|
|
|
2007-03-26 19:23:16 +02:00
|
|
|
|
oxid_info->dwTid = 0;
|
|
|
|
|
oxid_info->dwPid = 0;
|
|
|
|
|
oxid_info->dwAuthnHint = RPC_C_AUTHN_LEVEL_NONE;
|
|
|
|
|
/* FIXME: this is a hack around not having an OXID resolver yet -
|
|
|
|
|
* this function should contact the machine's OXID resolver and then it
|
|
|
|
|
* should give us the IPID of the IRemUnknown interface */
|
|
|
|
|
oxid_info->ipidRemUnknown.Data1 = 0xffffffff;
|
|
|
|
|
oxid_info->ipidRemUnknown.Data2 = 0xffff;
|
|
|
|
|
oxid_info->ipidRemUnknown.Data3 = 0xffff;
|
|
|
|
|
memcpy(&oxid_info->ipidRemUnknown.Data4, &oxid, sizeof(OXID));
|
|
|
|
|
oxid_info->psa = NULL /* FIXME */;
|
|
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
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(
|
2006-03-31 13:34:25 +02:00
|
|
|
|
wszRpcTransport,
|
2005-02-15 16:02:49 +01:00
|
|
|
|
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
|
|
|
|
|
*/
|
2006-01-10 20:06:22 +01:00
|
|
|
|
static DWORD start_local_service(LPCWSTR name, DWORD num, LPCWSTR *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
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
|
TRACE("Starting service %s %d params\n", debugstr_w(name), num);
|
2005-01-05 14:22:10 +01:00
|
|
|
|
|
2006-01-10 20:06:22 +01:00
|
|
|
|
handle = OpenSCManagerW(NULL, NULL, SC_MANAGER_CONNECT);
|
2005-01-05 14:22:10 +01:00
|
|
|
|
if (!handle)
|
|
|
|
|
return r;
|
2006-01-10 20:06:22 +01:00
|
|
|
|
hsvc = OpenServiceW(handle, name, SERVICE_START);
|
2005-01-05 14:22:10 +01:00
|
|
|
|
if (hsvc)
|
|
|
|
|
{
|
2006-01-10 20:06:22 +01:00
|
|
|
|
if(StartServiceW(hsvc, num, params))
|
2005-01-05 14:22:10 +01:00
|
|
|
|
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);
|
|
|
|
|
}
|
2006-01-10 20:06:03 +01:00
|
|
|
|
else
|
|
|
|
|
r = GetLastError();
|
2005-01-05 14:22:10 +01:00
|
|
|
|
CloseServiceHandle(handle);
|
|
|
|
|
|
2007-01-05 21:49:31 +01:00
|
|
|
|
TRACE("StartService returned error %u (%s)\n", r, (r == ERROR_SUCCESS) ? "ok":"failed");
|
2005-01-05 14:22:10 +01:00
|
|
|
|
|
|
|
|
|
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;
|
2006-08-26 12:55:16 +02:00
|
|
|
|
WCHAR buf[CHARS_IN_GUID];
|
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));
|
|
|
|
|
|
2006-08-26 12:55:16 +02:00
|
|
|
|
hres = COM_OpenKeyForAppIdFromCLSID(rclsid, KEY_READ, &hkey);
|
2005-11-09 11:29:11 +01:00
|
|
|
|
if (FAILED(hres))
|
2005-01-05 14:22:10 +01:00
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
|
|
/* read the LocalService and ServiceParameters values from the AppID key */
|
|
|
|
|
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);
|
|
|
|
|
}
|
2006-01-10 20:06:22 +01:00
|
|
|
|
r = start_local_service(buf, num_args, (LPCWSTR *)args);
|
2006-08-28 15:19:13 +02:00
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
|
hres = REGDB_E_CLASSNOTREG; /* FIXME: check retval */
|
2005-01-05 14:22:10 +01:00
|
|
|
|
HeapFree(GetProcessHeap(),0,args[0]);
|
|
|
|
|
}
|
2006-08-28 15:19:13 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
WARN("No LocalService value\n");
|
|
|
|
|
hres = REGDB_E_CLASSNOTREG; /* FIXME: check retval */
|
|
|
|
|
}
|
2005-01-05 14:22:10 +01:00
|
|
|
|
RegCloseKey(hkey);
|
2006-08-28 15:19:13 +02:00
|
|
|
|
|
2005-01-05 14:22:10 +01:00
|
|
|
|
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));
|
2007-11-12 21:13:41 +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) {
|
2007-12-07 15:45:16 +01:00
|
|
|
|
DWORD index;
|
2007-12-20 10:51:57 +01:00
|
|
|
|
DWORD start_ticks;
|
2005-01-21 11:15:29 +01:00
|
|
|
|
if (tries == 1) {
|
2006-01-09 18:40:42 +01:00
|
|
|
|
if ( (hres = create_local_service(rclsid)) &&
|
|
|
|
|
(hres = create_server(rclsid)) )
|
2005-01-21 11:15:29 +01:00
|
|
|
|
return hres;
|
|
|
|
|
} else {
|
2007-01-05 21:49:31 +01:00
|
|
|
|
WARN("Connecting to %s, no response yet, retrying: le is %u\n", debugstr_w(pipefn), GetLastError());
|
2005-01-21 11:15:29 +01:00
|
|
|
|
}
|
2007-12-20 10:51:57 +01:00
|
|
|
|
/* wait for one second, even if messages arrive */
|
|
|
|
|
start_ticks = GetTickCount();
|
|
|
|
|
do {
|
|
|
|
|
CoWaitForMultipleHandles(0, 1000, 0, NULL, &index);
|
|
|
|
|
} while (GetTickCount() - start_ticks < 1000);
|
2005-01-21 11:15:29 +01:00
|
|
|
|
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;
|
2008-01-08 19:14:07 +01:00
|
|
|
|
hres = IStream_Seek(pStm,seekto,STREAM_SEEK_SET,&newpos);
|
2005-01-21 11:15:29 +01:00
|
|
|
|
|
|
|
|
|
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;
|
2006-09-27 17:23:42 +02:00
|
|
|
|
HANDLE ready_event;
|
2007-11-12 21:13:41 +01:00
|
|
|
|
HANDLE stop_event;
|
|
|
|
|
HANDLE thread;
|
2007-03-09 18:51:36 +01:00
|
|
|
|
BOOL multi_use;
|
2004-12-27 20:24:55 +01:00
|
|
|
|
};
|
|
|
|
|
|
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;
|
2007-03-09 18:51:36 +01:00
|
|
|
|
BOOL multi_use = lsp->multi_use;
|
2007-11-12 21:13:41 +01:00
|
|
|
|
OVERLAPPED ovl;
|
|
|
|
|
HANDLE pipe_event;
|
2004-12-27 20:24:55 +01:00
|
|
|
|
|
|
|
|
|
TRACE("Starting threader for %s.\n",debugstr_guid(&lsp->clsid));
|
|
|
|
|
|
2007-11-12 21:13:41 +01:00
|
|
|
|
memset(&ovl, 0, sizeof(ovl));
|
2005-06-20 12:33:28 +02:00
|
|
|
|
get_localserver_pipe_name(pipefn, &lsp->clsid);
|
2004-12-27 20:24:55 +01:00
|
|
|
|
|
2007-11-12 21:13:41 +01:00
|
|
|
|
hPipe = CreateNamedPipeW( pipefn, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
|
2005-02-08 13:55:26 +01:00
|
|
|
|
PIPE_TYPE_BYTE|PIPE_WAIT, PIPE_UNLIMITED_INSTANCES,
|
|
|
|
|
4096, 4096, 500 /* 0.5 second timeout */, NULL );
|
2006-09-27 17:23:42 +02:00
|
|
|
|
|
|
|
|
|
SetEvent(lsp->ready_event);
|
|
|
|
|
|
2005-02-08 13:55:26 +01:00
|
|
|
|
if (hPipe == INVALID_HANDLE_VALUE)
|
|
|
|
|
{
|
2007-01-05 21:49:31 +01:00
|
|
|
|
FIXME("pipe creation failed for %s, le is %u\n", debugstr_w(pipefn), GetLastError());
|
2004-12-27 20:24:55 +01:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
2007-11-12 21:13:41 +01:00
|
|
|
|
|
|
|
|
|
ovl.hEvent = pipe_event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
2005-02-08 13:55:26 +01:00
|
|
|
|
|
2004-12-27 20:24:55 +01:00
|
|
|
|
while (1) {
|
2007-11-12 21:13:41 +01:00
|
|
|
|
if (!ConnectNamedPipe(hPipe, &ovl))
|
2007-03-09 18:42:34 +01:00
|
|
|
|
{
|
|
|
|
|
DWORD error = GetLastError();
|
2007-11-12 21:13:41 +01:00
|
|
|
|
if (error == ERROR_IO_PENDING)
|
|
|
|
|
{
|
|
|
|
|
HANDLE handles[2] = { pipe_event, lsp->stop_event };
|
|
|
|
|
DWORD ret;
|
|
|
|
|
ret = WaitForMultipleObjects(2, handles, FALSE, INFINITE);
|
|
|
|
|
if (ret != WAIT_OBJECT_0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-03-09 18:42:34 +01:00
|
|
|
|
/* client already connected isn't an error */
|
2007-11-12 21:13:41 +01:00
|
|
|
|
else if (error != ERROR_PIPE_CONNECTED)
|
2007-03-09 18:42:34 +01:00
|
|
|
|
{
|
2007-11-12 21:13:41 +01:00
|
|
|
|
ERR("ConnectNamedPipe failed with error %d\n", GetLastError());
|
2007-03-09 18:42:34 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2004-12-27 20:24:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TRACE("marshalling IClassFactory to client\n");
|
|
|
|
|
|
|
|
|
|
hres = IStream_Stat(pStm,&ststg,0);
|
|
|
|
|
if (hres) return hres;
|
|
|
|
|
|
|
|
|
|
seekto.u.LowPart = 0;
|
|
|
|
|
seekto.u.HighPart = 0;
|
2008-01-08 19:14:07 +01:00
|
|
|
|
hres = IStream_Seek(pStm,seekto,STREAM_SEEK_SET,&newpos);
|
2004-12-27 20:24:55 +01:00
|
|
|
|
if (hres) {
|
2006-10-15 12:28:08 +02:00
|
|
|
|
FIXME("IStream_Seek failed, %x\n",hres);
|
2007-11-12 21:13:41 +01:00
|
|
|
|
CloseHandle(hPipe);
|
|
|
|
|
CloseHandle(pipe_event);
|
2004-12-27 20:24:55 +01:00
|
|
|
|
return hres;
|
|
|
|
|
}
|
2006-07-14 18:14:04 +02:00
|
|
|
|
|
|
|
|
|
buflen = ststg.cbSize.u.LowPart;
|
|
|
|
|
buffer = HeapAlloc(GetProcessHeap(),0,buflen);
|
2004-12-27 20:24:55 +01:00
|
|
|
|
|
|
|
|
|
hres = IStream_Read(pStm,buffer,buflen,&res);
|
|
|
|
|
if (hres) {
|
2006-10-15 12:28:08 +02:00
|
|
|
|
FIXME("Stream Read failed, %x\n",hres);
|
2007-11-12 21:13:41 +01:00
|
|
|
|
CloseHandle(hPipe);
|
|
|
|
|
CloseHandle(pipe_event);
|
2006-07-14 18:14:04 +02:00
|
|
|
|
HeapFree(GetProcessHeap(),0,buffer);
|
2004-12-27 20:24:55 +01:00
|
|
|
|
return hres;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-12 21:13:41 +01:00
|
|
|
|
WriteFile(hPipe,buffer,buflen,&res,&ovl);
|
|
|
|
|
GetOverlappedResult(hPipe, &ovl, NULL, TRUE);
|
2006-07-14 18:14:04 +02:00
|
|
|
|
HeapFree(GetProcessHeap(),0,buffer);
|
|
|
|
|
|
2004-12-27 20:24:55 +01:00
|
|
|
|
FlushFileBuffers(hPipe);
|
|
|
|
|
DisconnectNamedPipe(hPipe);
|
|
|
|
|
|
|
|
|
|
TRACE("done marshalling IClassFactory\n");
|
2007-03-09 18:51:36 +01:00
|
|
|
|
|
|
|
|
|
if (!multi_use)
|
|
|
|
|
{
|
|
|
|
|
TRACE("single use object, shutting down pipe %s\n", debugstr_w(pipefn));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-12-27 20:24:55 +01:00
|
|
|
|
}
|
2007-11-12 21:13:41 +01:00
|
|
|
|
CloseHandle(hPipe);
|
|
|
|
|
CloseHandle(pipe_event);
|
2004-12-27 20:24:55 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-09 18:42:34 +01:00
|
|
|
|
/* starts listening for a local server */
|
2007-03-09 18:51:36 +01:00
|
|
|
|
HRESULT RPC_StartLocalServer(REFCLSID clsid, IStream *stream, BOOL multi_use, void **registration)
|
2004-12-27 20:24:55 +01:00
|
|
|
|
{
|
|
|
|
|
DWORD tid;
|
2007-11-12 21:13:41 +01:00
|
|
|
|
struct local_server_params *lsp;
|
|
|
|
|
|
|
|
|
|
lsp = HeapAlloc(GetProcessHeap(), 0, sizeof(*lsp));
|
|
|
|
|
if (!lsp)
|
|
|
|
|
return E_OUTOFMEMORY;
|
2004-12-27 20:24:55 +01:00
|
|
|
|
|
|
|
|
|
lsp->clsid = *clsid;
|
|
|
|
|
lsp->stream = stream;
|
2006-08-31 18:19:49 +02:00
|
|
|
|
IStream_AddRef(stream);
|
2007-11-12 21:13:41 +01:00
|
|
|
|
lsp->ready_event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
|
|
|
|
if (!lsp->ready_event)
|
|
|
|
|
{
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, lsp);
|
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
|
}
|
|
|
|
|
lsp->stop_event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
|
|
|
|
if (!lsp->stop_event)
|
|
|
|
|
{
|
|
|
|
|
CloseHandle(lsp->ready_event);
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, lsp);
|
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
|
}
|
2007-03-09 18:51:36 +01:00
|
|
|
|
lsp->multi_use = multi_use;
|
2004-12-27 20:24:55 +01:00
|
|
|
|
|
2007-11-12 21:13:41 +01:00
|
|
|
|
lsp->thread = CreateThread(NULL, 0, local_server_thread, lsp, 0, &tid);
|
|
|
|
|
if (!lsp->thread)
|
|
|
|
|
{
|
|
|
|
|
CloseHandle(lsp->ready_event);
|
|
|
|
|
CloseHandle(lsp->stop_event);
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, lsp);
|
2007-03-09 18:42:34 +01:00
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
2007-11-12 21:13:41 +01:00
|
|
|
|
}
|
2006-09-27 17:23:42 +02:00
|
|
|
|
|
2007-11-12 21:13:41 +01:00
|
|
|
|
WaitForSingleObject(lsp->ready_event, INFINITE);
|
|
|
|
|
CloseHandle(lsp->ready_event);
|
|
|
|
|
lsp->ready_event = NULL;
|
2007-03-09 18:42:34 +01:00
|
|
|
|
|
2007-11-12 21:13:41 +01:00
|
|
|
|
*registration = lsp;
|
2007-03-09 18:42:34 +01:00
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* stops listening for a local server */
|
|
|
|
|
void RPC_StopLocalServer(void *registration)
|
|
|
|
|
{
|
2007-11-12 21:13:41 +01:00
|
|
|
|
struct local_server_params *lsp = registration;
|
|
|
|
|
|
|
|
|
|
/* signal local_server_thread to stop */
|
|
|
|
|
SetEvent(lsp->stop_event);
|
|
|
|
|
/* wait for it to exit */
|
|
|
|
|
WaitForSingleObject(lsp->thread, INFINITE);
|
|
|
|
|
|
|
|
|
|
IStream_Release(lsp->stream);
|
|
|
|
|
CloseHandle(lsp->stop_event);
|
|
|
|
|
CloseHandle(lsp->thread);
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, lsp);
|
2004-12-27 20:24:55 +01:00
|
|
|
|
}
|