2002-10-11 19:52:37 +02:00
|
|
|
|
/*
|
|
|
|
|
* RPC server API
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2001 Ove K<EFBFBD>ven, TransGaming Technologies
|
2004-04-27 01:33:39 +02:00
|
|
|
|
* Copyright 2004 Filip Navara
|
2002-10-11 19:52:37 +02:00
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*
|
|
|
|
|
* TODO:
|
|
|
|
|
* - a whole lot
|
|
|
|
|
*/
|
|
|
|
|
|
2003-11-27 01:59:36 +01:00
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
|
#include <stdarg.h>
|
2002-10-11 19:52:37 +02:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
2002-10-31 23:45:12 +01:00
|
|
|
|
#include <assert.h>
|
2002-10-11 19:52:37 +02:00
|
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
|
#include "winbase.h"
|
|
|
|
|
#include "winerror.h"
|
|
|
|
|
#include "winreg.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
|
#include "ntstatus.h"
|
2002-10-11 19:52:37 +02:00
|
|
|
|
|
|
|
|
|
#include "rpc.h"
|
2004-04-27 01:33:39 +02:00
|
|
|
|
#include "rpcndr.h"
|
2003-05-22 05:36:00 +02:00
|
|
|
|
#include "excpt.h"
|
2002-10-11 19:52:37 +02:00
|
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
2003-05-22 05:36:00 +02:00
|
|
|
|
#include "wine/exception.h"
|
2002-10-11 19:52:37 +02:00
|
|
|
|
|
|
|
|
|
#include "rpc_server.h"
|
2003-05-22 05:36:00 +02:00
|
|
|
|
#include "rpc_misc.h"
|
2004-04-27 01:33:39 +02:00
|
|
|
|
#include "rpc_message.h"
|
2002-10-11 19:52:37 +02:00
|
|
|
|
#include "rpc_defs.h"
|
|
|
|
|
|
2003-02-19 04:44:35 +01:00
|
|
|
|
#define MAX_THREADS 128
|
|
|
|
|
|
2002-10-11 19:52:37 +02:00
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
|
|
|
|
|
2003-02-19 04:44:35 +01:00
|
|
|
|
typedef struct _RpcPacket
|
|
|
|
|
{
|
|
|
|
|
struct _RpcPacket* next;
|
|
|
|
|
struct _RpcConnection* conn;
|
2004-04-27 01:33:39 +02:00
|
|
|
|
RpcPktHdr* hdr;
|
|
|
|
|
RPC_MESSAGE* msg;
|
2003-02-19 04:44:35 +01:00
|
|
|
|
} RpcPacket;
|
|
|
|
|
|
2003-11-21 23:14:42 +01:00
|
|
|
|
typedef struct _RpcObjTypeMap
|
|
|
|
|
{
|
|
|
|
|
/* FIXME: a hash table would be better. */
|
|
|
|
|
struct _RpcObjTypeMap *next;
|
|
|
|
|
UUID Object;
|
|
|
|
|
UUID Type;
|
|
|
|
|
} RpcObjTypeMap;
|
|
|
|
|
|
|
|
|
|
static RpcObjTypeMap *RpcObjTypeMaps;
|
|
|
|
|
|
2002-10-11 19:52:37 +02:00
|
|
|
|
static RpcServerProtseq* protseqs;
|
|
|
|
|
static RpcServerInterface* ifs;
|
|
|
|
|
|
2003-08-13 01:50:54 +02:00
|
|
|
|
static CRITICAL_SECTION server_cs;
|
|
|
|
|
static CRITICAL_SECTION_DEBUG server_cs_debug =
|
|
|
|
|
{
|
|
|
|
|
0, 0, &server_cs,
|
|
|
|
|
{ &server_cs_debug.ProcessLocksList, &server_cs_debug.ProcessLocksList },
|
|
|
|
|
0, 0, { 0, (DWORD)(__FILE__ ": server_cs") }
|
|
|
|
|
};
|
|
|
|
|
static CRITICAL_SECTION server_cs = { &server_cs_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
|
|
static CRITICAL_SECTION listen_cs;
|
|
|
|
|
static CRITICAL_SECTION_DEBUG listen_cs_debug =
|
|
|
|
|
{
|
|
|
|
|
0, 0, &listen_cs,
|
|
|
|
|
{ &listen_cs_debug.ProcessLocksList, &listen_cs_debug.ProcessLocksList },
|
|
|
|
|
0, 0, { 0, (DWORD)(__FILE__ ": listen_cs") }
|
|
|
|
|
};
|
|
|
|
|
static CRITICAL_SECTION listen_cs = { &listen_cs_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
|
2002-10-11 19:52:37 +02:00
|
|
|
|
static BOOL std_listen;
|
|
|
|
|
static LONG listen_count = -1;
|
|
|
|
|
static HANDLE mgr_event, server_thread;
|
|
|
|
|
|
2003-08-13 01:50:54 +02:00
|
|
|
|
static CRITICAL_SECTION spacket_cs;
|
|
|
|
|
static CRITICAL_SECTION_DEBUG spacket_cs_debug =
|
|
|
|
|
{
|
|
|
|
|
0, 0, &spacket_cs,
|
|
|
|
|
{ &spacket_cs_debug.ProcessLocksList, &spacket_cs_debug.ProcessLocksList },
|
|
|
|
|
0, 0, { 0, (DWORD)(__FILE__ ": spacket_cs") }
|
|
|
|
|
};
|
|
|
|
|
static CRITICAL_SECTION spacket_cs = { &spacket_cs_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
|
2003-02-19 04:44:35 +01:00
|
|
|
|
static RpcPacket* spacket_head;
|
|
|
|
|
static RpcPacket* spacket_tail;
|
|
|
|
|
static HANDLE server_sem;
|
|
|
|
|
|
2003-05-22 05:36:00 +02:00
|
|
|
|
static DWORD worker_count, worker_free, worker_tls;
|
2003-02-19 04:44:35 +01:00
|
|
|
|
|
2003-11-21 23:14:42 +01:00
|
|
|
|
static UUID uuid_nil;
|
|
|
|
|
|
|
|
|
|
inline static RpcObjTypeMap *LookupObjTypeMap(UUID *ObjUuid)
|
|
|
|
|
{
|
|
|
|
|
RpcObjTypeMap *rslt = RpcObjTypeMaps;
|
|
|
|
|
RPC_STATUS dummy;
|
|
|
|
|
|
|
|
|
|
while (rslt) {
|
|
|
|
|
if (! UuidCompare(ObjUuid, &rslt->Object, &dummy)) break;
|
|
|
|
|
rslt = rslt->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rslt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline static UUID *LookupObjType(UUID *ObjUuid)
|
|
|
|
|
{
|
|
|
|
|
RpcObjTypeMap *map = LookupObjTypeMap(ObjUuid);
|
|
|
|
|
if (map)
|
|
|
|
|
return &map->Type;
|
|
|
|
|
else
|
|
|
|
|
return &uuid_nil;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-27 01:33:39 +02:00
|
|
|
|
static RpcServerInterface* RPCRT4_find_interface(UUID* object,
|
|
|
|
|
RPC_SYNTAX_IDENTIFIER* if_id,
|
|
|
|
|
BOOL check_object)
|
2002-10-11 19:52:37 +02:00
|
|
|
|
{
|
|
|
|
|
UUID* MgrType = NULL;
|
|
|
|
|
RpcServerInterface* cif = NULL;
|
|
|
|
|
RPC_STATUS status;
|
|
|
|
|
|
2004-04-27 01:33:39 +02:00
|
|
|
|
if (check_object)
|
|
|
|
|
MgrType = LookupObjType(object);
|
2002-10-11 19:52:37 +02:00
|
|
|
|
EnterCriticalSection(&server_cs);
|
|
|
|
|
cif = ifs;
|
|
|
|
|
while (cif) {
|
2004-04-27 01:33:39 +02:00
|
|
|
|
if (!memcmp(if_id, &cif->If->InterfaceId, sizeof(RPC_SYNTAX_IDENTIFIER)) &&
|
|
|
|
|
(check_object == FALSE || UuidEqual(MgrType, &cif->MgrTypeUuid, &status)) &&
|
|
|
|
|
(std_listen || (cif->Flags & RPC_IF_AUTOLISTEN))) break;
|
2002-10-11 19:52:37 +02:00
|
|
|
|
cif = cif->Next;
|
|
|
|
|
}
|
|
|
|
|
LeaveCriticalSection(&server_cs);
|
2004-06-17 21:54:34 +02:00
|
|
|
|
TRACE("returning %p for %s\n", cif, debugstr_guid(object));
|
2002-10-11 19:52:37 +02:00
|
|
|
|
return cif;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-19 04:44:35 +01:00
|
|
|
|
static void RPCRT4_push_packet(RpcPacket* packet)
|
2002-10-11 19:52:37 +02:00
|
|
|
|
{
|
2003-02-19 04:44:35 +01:00
|
|
|
|
packet->next = NULL;
|
|
|
|
|
EnterCriticalSection(&spacket_cs);
|
2003-09-15 21:57:11 +02:00
|
|
|
|
if (spacket_tail) {
|
|
|
|
|
spacket_tail->next = packet;
|
|
|
|
|
spacket_tail = packet;
|
|
|
|
|
} else {
|
2003-02-19 04:44:35 +01:00
|
|
|
|
spacket_head = packet;
|
|
|
|
|
spacket_tail = packet;
|
|
|
|
|
}
|
|
|
|
|
LeaveCriticalSection(&spacket_cs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static RpcPacket* RPCRT4_pop_packet(void)
|
|
|
|
|
{
|
|
|
|
|
RpcPacket* packet;
|
|
|
|
|
EnterCriticalSection(&spacket_cs);
|
|
|
|
|
packet = spacket_head;
|
|
|
|
|
if (packet) {
|
|
|
|
|
spacket_head = packet->next;
|
|
|
|
|
if (!spacket_head) spacket_tail = NULL;
|
|
|
|
|
}
|
|
|
|
|
LeaveCriticalSection(&spacket_cs);
|
|
|
|
|
if (packet) packet->next = NULL;
|
|
|
|
|
return packet;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-09 01:35:04 +01:00
|
|
|
|
typedef struct {
|
|
|
|
|
PRPC_MESSAGE msg;
|
|
|
|
|
void* buf;
|
|
|
|
|
} packet_state;
|
|
|
|
|
|
2003-05-22 05:36:00 +02:00
|
|
|
|
static WINE_EXCEPTION_FILTER(rpc_filter)
|
|
|
|
|
{
|
2004-01-09 01:35:04 +01:00
|
|
|
|
packet_state* state;
|
2003-05-22 05:36:00 +02:00
|
|
|
|
PRPC_MESSAGE msg;
|
2004-01-09 01:35:04 +01:00
|
|
|
|
state = TlsGetValue(worker_tls);
|
|
|
|
|
msg = state->msg;
|
|
|
|
|
if (msg->Buffer != state->buf) I_RpcFreeBuffer(msg);
|
2003-05-22 05:36:00 +02:00
|
|
|
|
msg->RpcFlags |= WINE_RPCFLAG_EXCEPTION;
|
|
|
|
|
msg->BufferLength = sizeof(DWORD);
|
|
|
|
|
I_RpcGetBuffer(msg);
|
|
|
|
|
*(DWORD*)msg->Buffer = GetExceptionCode();
|
2004-02-27 05:33:41 +01:00
|
|
|
|
WARN("exception caught with code 0x%08lx = %ld\n", *(DWORD*)msg->Buffer, *(DWORD*)msg->Buffer);
|
|
|
|
|
TRACE("returning failure packet\n");
|
2003-05-22 05:36:00 +02:00
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-27 01:33:39 +02:00
|
|
|
|
static void RPCRT4_process_packet(RpcConnection* conn, RpcPktHdr* hdr, RPC_MESSAGE* msg)
|
2003-02-19 04:44:35 +01:00
|
|
|
|
{
|
2002-10-11 19:52:37 +02:00
|
|
|
|
RpcServerInterface* sif;
|
|
|
|
|
RPC_DISPATCH_FUNCTION func;
|
2004-01-09 01:35:04 +01:00
|
|
|
|
packet_state state;
|
2004-04-27 01:33:39 +02:00
|
|
|
|
UUID *object_uuid;
|
|
|
|
|
RpcPktHdr *response;
|
|
|
|
|
void *buf = msg->Buffer;
|
|
|
|
|
RPC_STATUS status;
|
2002-10-11 19:52:37 +02:00
|
|
|
|
|
2004-04-27 01:33:39 +02:00
|
|
|
|
state.msg = msg;
|
2004-01-09 01:35:04 +01:00
|
|
|
|
state.buf = buf;
|
|
|
|
|
TlsSetValue(worker_tls, &state);
|
2004-04-27 01:33:39 +02:00
|
|
|
|
|
|
|
|
|
switch (hdr->common.ptype) {
|
|
|
|
|
case PKT_BIND:
|
|
|
|
|
TRACE("got bind packet\n");
|
|
|
|
|
|
|
|
|
|
/* FIXME: do more checks! */
|
|
|
|
|
if (hdr->bind.max_tsize < RPC_MIN_PACKET_SIZE ||
|
|
|
|
|
!UuidIsNil(&conn->ActiveInterface.SyntaxGUID, &status)) {
|
2004-06-17 21:54:34 +02:00
|
|
|
|
TRACE("packet size less than min size, or active interface syntax guid non-null\n");
|
2004-04-27 01:33:39 +02:00
|
|
|
|
sif = NULL;
|
|
|
|
|
} else {
|
|
|
|
|
sif = RPCRT4_find_interface(NULL, &hdr->bind.abstract, FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (sif == NULL) {
|
2004-06-17 21:54:34 +02:00
|
|
|
|
TRACE("rejecting bind request on connection %p\n", conn);
|
2004-04-27 01:33:39 +02:00
|
|
|
|
/* Report failure to client. */
|
|
|
|
|
response = RPCRT4_BuildBindNackHeader(NDR_LOCAL_DATA_REPRESENTATION,
|
|
|
|
|
RPC_VER_MAJOR, RPC_VER_MINOR);
|
|
|
|
|
} else {
|
2004-06-17 21:54:34 +02:00
|
|
|
|
TRACE("accepting bind request on connection %p\n", conn);
|
2004-04-27 01:33:39 +02:00
|
|
|
|
|
|
|
|
|
/* accept. */
|
|
|
|
|
response = RPCRT4_BuildBindAckHeader(NDR_LOCAL_DATA_REPRESENTATION,
|
|
|
|
|
RPC_MAX_PACKET_SIZE,
|
|
|
|
|
RPC_MAX_PACKET_SIZE,
|
|
|
|
|
conn->Endpoint,
|
|
|
|
|
RESULT_ACCEPT, NO_REASON,
|
|
|
|
|
&sif->If->TransferSyntax);
|
|
|
|
|
|
|
|
|
|
/* save the interface for later use */
|
|
|
|
|
conn->ActiveInterface = hdr->bind.abstract;
|
|
|
|
|
conn->MaxTransmissionSize = hdr->bind.max_tsize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (RPCRT4_Send(conn, response, NULL, 0) != RPC_S_OK)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
2003-02-19 04:44:35 +01:00
|
|
|
|
case PKT_REQUEST:
|
2004-04-27 01:33:39 +02:00
|
|
|
|
TRACE("got request packet\n");
|
|
|
|
|
|
|
|
|
|
/* fail if the connection isn't bound with an interface */
|
|
|
|
|
if (UuidIsNil(&conn->ActiveInterface.SyntaxGUID, &status)) {
|
|
|
|
|
response = RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION,
|
|
|
|
|
status);
|
|
|
|
|
|
|
|
|
|
RPCRT4_Send(conn, response, NULL, 0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hdr->common.flags & RPC_FLG_OBJECT_UUID) {
|
|
|
|
|
object_uuid = (UUID*)(&hdr->request + 1);
|
|
|
|
|
} else {
|
|
|
|
|
object_uuid = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sif = RPCRT4_find_interface(object_uuid, &conn->ActiveInterface, TRUE);
|
|
|
|
|
msg->RpcInterfaceInformation = sif->If;
|
|
|
|
|
/* copy the endpoint vector from sif to msg so that midl-generated code will use it */
|
|
|
|
|
msg->ManagerEpv = sif->MgrEpv;
|
|
|
|
|
if (object_uuid != NULL) {
|
|
|
|
|
RPCRT4_SetBindingObject(msg->Handle, object_uuid);
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-19 04:44:35 +01:00
|
|
|
|
/* find dispatch function */
|
2004-04-27 01:33:39 +02:00
|
|
|
|
msg->ProcNum = hdr->request.opnum;
|
2003-02-19 04:44:35 +01:00
|
|
|
|
if (sif->Flags & RPC_IF_OLE) {
|
|
|
|
|
/* native ole32 always gives us a dispatch table with a single entry
|
|
|
|
|
* (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
|
|
|
|
|
func = *sif->If->DispatchTable->DispatchTable;
|
|
|
|
|
} else {
|
2004-04-27 01:33:39 +02:00
|
|
|
|
if (msg->ProcNum >= sif->If->DispatchTable->DispatchTableCount) {
|
2003-02-19 04:44:35 +01:00
|
|
|
|
ERR("invalid procnum\n");
|
|
|
|
|
func = NULL;
|
|
|
|
|
}
|
2004-04-27 01:33:39 +02:00
|
|
|
|
func = sif->If->DispatchTable->DispatchTable[msg->ProcNum];
|
2003-02-19 04:44:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* put in the drep. FIXME: is this more universally applicable?
|
|
|
|
|
perhaps we should move this outward... */
|
2004-04-27 01:33:39 +02:00
|
|
|
|
msg->DataRepresentation =
|
|
|
|
|
MAKELONG( MAKEWORD(hdr->common.drep[0], hdr->common.drep[1]),
|
|
|
|
|
MAKEWORD(hdr->common.drep[2], hdr->common.drep[3]));
|
2003-02-19 04:44:35 +01:00
|
|
|
|
|
|
|
|
|
/* dispatch */
|
2003-05-22 05:36:00 +02:00
|
|
|
|
__TRY {
|
2004-04-27 01:33:39 +02:00
|
|
|
|
if (func) func(msg);
|
2003-05-22 05:36:00 +02:00
|
|
|
|
} __EXCEPT(rpc_filter) {
|
|
|
|
|
/* failure packet was created in rpc_filter */
|
|
|
|
|
} __ENDTRY
|
2003-02-19 04:44:35 +01:00
|
|
|
|
|
|
|
|
|
/* send response packet */
|
2004-04-27 01:33:39 +02:00
|
|
|
|
I_RpcSend(msg);
|
|
|
|
|
|
|
|
|
|
msg->RpcInterfaceInformation = NULL;
|
|
|
|
|
|
2003-02-19 04:44:35 +01:00
|
|
|
|
break;
|
2004-04-27 01:33:39 +02:00
|
|
|
|
|
2003-02-19 04:44:35 +01:00
|
|
|
|
default:
|
2004-04-27 01:33:39 +02:00
|
|
|
|
FIXME("unhandled packet type\n");
|
2003-02-19 04:44:35 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-27 01:33:39 +02:00
|
|
|
|
fail:
|
2003-02-19 04:44:35 +01:00
|
|
|
|
/* clean up */
|
2004-04-27 01:33:39 +02:00
|
|
|
|
if (msg->Buffer == buf) msg->Buffer = NULL;
|
2003-05-21 20:23:06 +02:00
|
|
|
|
TRACE("freeing Buffer=%p\n", buf);
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
2004-04-27 01:33:39 +02:00
|
|
|
|
RPCRT4_DestroyBinding(msg->Handle);
|
|
|
|
|
msg->Handle = 0;
|
|
|
|
|
I_RpcFreeBuffer(msg);
|
|
|
|
|
msg->Buffer = NULL;
|
|
|
|
|
RPCRT4_FreeHeader(hdr);
|
2003-05-22 05:36:00 +02:00
|
|
|
|
TlsSetValue(worker_tls, NULL);
|
2003-02-19 04:44:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DWORD CALLBACK RPCRT4_worker_thread(LPVOID the_arg)
|
|
|
|
|
{
|
|
|
|
|
DWORD obj;
|
|
|
|
|
RpcPacket* pkt;
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
/* idle timeout after 5s */
|
|
|
|
|
obj = WaitForSingleObject(server_sem, 5000);
|
|
|
|
|
if (obj == WAIT_TIMEOUT) {
|
|
|
|
|
/* if another idle thread exist, self-destruct */
|
|
|
|
|
if (worker_free > 1) break;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
pkt = RPCRT4_pop_packet();
|
|
|
|
|
if (!pkt) continue;
|
|
|
|
|
InterlockedDecrement(&worker_free);
|
|
|
|
|
for (;;) {
|
2004-04-27 01:33:39 +02:00
|
|
|
|
RPCRT4_process_packet(pkt->conn, pkt->hdr, pkt->msg);
|
2003-02-19 04:44:35 +01:00
|
|
|
|
HeapFree(GetProcessHeap(), 0, pkt);
|
|
|
|
|
/* try to grab another packet here without waiting
|
|
|
|
|
* on the semaphore, in case it hits max */
|
|
|
|
|
pkt = RPCRT4_pop_packet();
|
|
|
|
|
if (!pkt) break;
|
|
|
|
|
/* decrement semaphore */
|
|
|
|
|
WaitForSingleObject(server_sem, 0);
|
|
|
|
|
}
|
|
|
|
|
InterlockedIncrement(&worker_free);
|
|
|
|
|
}
|
|
|
|
|
InterlockedDecrement(&worker_free);
|
|
|
|
|
InterlockedDecrement(&worker_count);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void RPCRT4_create_worker_if_needed(void)
|
|
|
|
|
{
|
|
|
|
|
if (!worker_free && worker_count < MAX_THREADS) {
|
|
|
|
|
HANDLE thread;
|
|
|
|
|
InterlockedIncrement(&worker_count);
|
|
|
|
|
InterlockedIncrement(&worker_free);
|
|
|
|
|
thread = CreateThread(NULL, 0, RPCRT4_worker_thread, NULL, 0, NULL);
|
|
|
|
|
if (thread) CloseHandle(thread);
|
|
|
|
|
else {
|
|
|
|
|
InterlockedDecrement(&worker_free);
|
|
|
|
|
InterlockedDecrement(&worker_count);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DWORD CALLBACK RPCRT4_io_thread(LPVOID the_arg)
|
|
|
|
|
{
|
|
|
|
|
RpcConnection* conn = (RpcConnection*)the_arg;
|
2004-04-27 01:33:39 +02:00
|
|
|
|
RpcPktHdr *hdr;
|
|
|
|
|
RpcBinding *pbind;
|
|
|
|
|
RPC_MESSAGE *msg;
|
|
|
|
|
RPC_STATUS status;
|
|
|
|
|
RpcPacket *packet;
|
2003-02-19 04:44:35 +01:00
|
|
|
|
|
|
|
|
|
TRACE("(%p)\n", conn);
|
2002-10-11 19:52:37 +02:00
|
|
|
|
|
|
|
|
|
for (;;) {
|
2004-04-27 01:33:39 +02:00
|
|
|
|
msg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RPC_MESSAGE));
|
2002-10-11 19:52:37 +02:00
|
|
|
|
|
2004-04-27 01:33:39 +02:00
|
|
|
|
/* create temporary binding for dispatch, it will be freed in
|
|
|
|
|
* RPCRT4_process_packet */
|
|
|
|
|
RPCRT4_MakeBinding(&pbind, conn);
|
|
|
|
|
msg->Handle = (RPC_BINDING_HANDLE)pbind;
|
|
|
|
|
|
|
|
|
|
status = RPCRT4_Receive(conn, &hdr, msg);
|
|
|
|
|
if (status != RPC_S_OK) {
|
|
|
|
|
WARN("receive failed with error %lx\n", status);
|
2002-10-11 19:52:37 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-19 04:44:35 +01:00
|
|
|
|
#if 0
|
2004-04-27 01:33:39 +02:00
|
|
|
|
RPCRT4_process_packet(conn, hdr, msg);
|
2003-02-19 04:44:35 +01:00
|
|
|
|
#else
|
|
|
|
|
packet = HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket));
|
|
|
|
|
packet->conn = conn;
|
|
|
|
|
packet->hdr = hdr;
|
2004-04-27 01:33:39 +02:00
|
|
|
|
packet->msg = msg;
|
2003-02-19 04:44:35 +01:00
|
|
|
|
RPCRT4_create_worker_if_needed();
|
|
|
|
|
RPCRT4_push_packet(packet);
|
|
|
|
|
ReleaseSemaphore(server_sem, 1, NULL);
|
|
|
|
|
#endif
|
2004-04-27 01:33:39 +02:00
|
|
|
|
msg = NULL;
|
2002-10-11 19:52:37 +02:00
|
|
|
|
}
|
2004-04-27 01:33:39 +02:00
|
|
|
|
if (msg) HeapFree(GetProcessHeap(), 0, msg);
|
2003-02-19 04:44:35 +01:00
|
|
|
|
RPCRT4_DestroyConnection(conn);
|
2002-10-11 19:52:37 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-19 04:44:35 +01:00
|
|
|
|
static void RPCRT4_new_client(RpcConnection* conn)
|
2002-10-11 19:52:37 +02:00
|
|
|
|
{
|
2003-04-19 04:49:35 +02:00
|
|
|
|
HANDLE thread = CreateThread(NULL, 0, RPCRT4_io_thread, conn, 0, NULL);
|
|
|
|
|
if (!thread) {
|
2003-02-19 04:44:35 +01:00
|
|
|
|
DWORD err = GetLastError();
|
|
|
|
|
ERR("failed to create thread, error=%08lx\n", err);
|
2003-04-19 04:49:35 +02:00
|
|
|
|
RPCRT4_DestroyConnection(conn);
|
2003-02-19 04:44:35 +01:00
|
|
|
|
}
|
2003-04-19 04:49:35 +02:00
|
|
|
|
/* we could set conn->thread, but then we'd have to make the io_thread wait
|
|
|
|
|
* for that, otherwise the thread might finish, destroy the connection, and
|
|
|
|
|
* free the memory we'd write to before we did, causing crashes and stuff -
|
|
|
|
|
* so let's implement that later, when we really need conn->thread */
|
|
|
|
|
|
|
|
|
|
CloseHandle( thread );
|
2002-10-11 19:52:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DWORD CALLBACK RPCRT4_server_thread(LPVOID the_arg)
|
|
|
|
|
{
|
|
|
|
|
HANDLE m_event = mgr_event, b_handle;
|
|
|
|
|
HANDLE *objs = NULL;
|
|
|
|
|
DWORD count, res;
|
|
|
|
|
RpcServerProtseq* cps;
|
2003-02-19 04:44:35 +01:00
|
|
|
|
RpcConnection* conn;
|
|
|
|
|
RpcConnection* cconn;
|
2002-10-11 19:52:37 +02:00
|
|
|
|
|
2003-11-21 00:39:18 +01:00
|
|
|
|
TRACE("(the_arg == ^%p)\n", the_arg);
|
|
|
|
|
|
2002-10-11 19:52:37 +02:00
|
|
|
|
for (;;) {
|
|
|
|
|
EnterCriticalSection(&server_cs);
|
2003-02-19 04:44:35 +01:00
|
|
|
|
/* open and count connections */
|
2002-10-11 19:52:37 +02:00
|
|
|
|
count = 1;
|
|
|
|
|
cps = protseqs;
|
|
|
|
|
while (cps) {
|
2003-02-19 04:44:35 +01:00
|
|
|
|
conn = cps->conn;
|
|
|
|
|
while (conn) {
|
|
|
|
|
RPCRT4_OpenConnection(conn);
|
|
|
|
|
if (conn->ovl.hEvent) count++;
|
|
|
|
|
conn = conn->Next;
|
2002-10-11 19:52:37 +02:00
|
|
|
|
}
|
|
|
|
|
cps = cps->Next;
|
|
|
|
|
}
|
2003-04-19 04:49:35 +02:00
|
|
|
|
/* make array of connections */
|
2003-10-14 07:24:20 +02:00
|
|
|
|
if (objs)
|
|
|
|
|
objs = HeapReAlloc(GetProcessHeap(), 0, objs, count*sizeof(HANDLE));
|
|
|
|
|
else
|
|
|
|
|
objs = HeapAlloc(GetProcessHeap(), 0, count*sizeof(HANDLE));
|
|
|
|
|
|
2002-10-11 19:52:37 +02:00
|
|
|
|
objs[0] = m_event;
|
|
|
|
|
count = 1;
|
|
|
|
|
cps = protseqs;
|
|
|
|
|
while (cps) {
|
2003-02-19 04:44:35 +01:00
|
|
|
|
conn = cps->conn;
|
|
|
|
|
while (conn) {
|
|
|
|
|
if (conn->ovl.hEvent) objs[count++] = conn->ovl.hEvent;
|
|
|
|
|
conn = conn->Next;
|
2002-10-11 19:52:37 +02:00
|
|
|
|
}
|
|
|
|
|
cps = cps->Next;
|
|
|
|
|
}
|
|
|
|
|
LeaveCriticalSection(&server_cs);
|
|
|
|
|
|
|
|
|
|
/* start waiting */
|
|
|
|
|
res = WaitForMultipleObjects(count, objs, FALSE, INFINITE);
|
|
|
|
|
if (res == WAIT_OBJECT_0) {
|
2002-10-31 23:45:12 +01:00
|
|
|
|
ResetEvent(m_event);
|
|
|
|
|
if (!std_listen) break;
|
2002-10-11 19:52:37 +02:00
|
|
|
|
}
|
|
|
|
|
else if (res == WAIT_FAILED) {
|
|
|
|
|
ERR("wait failed\n");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
b_handle = objs[res - WAIT_OBJECT_0];
|
2003-02-19 04:44:35 +01:00
|
|
|
|
/* find which connection got a RPC */
|
2002-10-11 19:52:37 +02:00
|
|
|
|
EnterCriticalSection(&server_cs);
|
2003-02-19 04:44:35 +01:00
|
|
|
|
conn = NULL;
|
2002-10-11 19:52:37 +02:00
|
|
|
|
cps = protseqs;
|
|
|
|
|
while (cps) {
|
2003-02-19 04:44:35 +01:00
|
|
|
|
conn = cps->conn;
|
|
|
|
|
while (conn) {
|
|
|
|
|
if (conn->ovl.hEvent == b_handle) break;
|
|
|
|
|
conn = conn->Next;
|
2002-10-11 19:52:37 +02:00
|
|
|
|
}
|
2003-02-19 04:44:35 +01:00
|
|
|
|
if (conn) break;
|
2002-10-11 19:52:37 +02:00
|
|
|
|
cps = cps->Next;
|
|
|
|
|
}
|
2003-02-19 04:44:35 +01:00
|
|
|
|
cconn = NULL;
|
|
|
|
|
if (conn) RPCRT4_SpawnConnection(&cconn, conn);
|
2002-10-11 19:52:37 +02:00
|
|
|
|
LeaveCriticalSection(&server_cs);
|
2003-02-19 04:44:35 +01:00
|
|
|
|
if (!conn) {
|
|
|
|
|
ERR("failed to locate connection for handle %p\n", b_handle);
|
2002-10-11 19:52:37 +02:00
|
|
|
|
}
|
2003-02-19 04:44:35 +01:00
|
|
|
|
if (cconn) RPCRT4_new_client(cconn);
|
2002-10-11 19:52:37 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, objs);
|
|
|
|
|
EnterCriticalSection(&server_cs);
|
2003-02-19 04:44:35 +01:00
|
|
|
|
/* close connections */
|
2002-10-11 19:52:37 +02:00
|
|
|
|
cps = protseqs;
|
|
|
|
|
while (cps) {
|
2003-02-19 04:44:35 +01:00
|
|
|
|
conn = cps->conn;
|
|
|
|
|
while (conn) {
|
|
|
|
|
RPCRT4_CloseConnection(conn);
|
|
|
|
|
conn = conn->Next;
|
2002-10-11 19:52:37 +02:00
|
|
|
|
}
|
|
|
|
|
cps = cps->Next;
|
|
|
|
|
}
|
|
|
|
|
LeaveCriticalSection(&server_cs);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void RPCRT4_start_listen(void)
|
|
|
|
|
{
|
2002-10-18 05:56:56 +02:00
|
|
|
|
TRACE("\n");
|
2002-10-31 23:45:12 +01:00
|
|
|
|
|
|
|
|
|
EnterCriticalSection(&listen_cs);
|
|
|
|
|
if (! ++listen_count) {
|
|
|
|
|
if (!mgr_event) mgr_event = CreateEventA(NULL, TRUE, FALSE, NULL);
|
2003-02-19 04:44:35 +01:00
|
|
|
|
if (!server_sem) server_sem = CreateSemaphoreA(NULL, 0, MAX_THREADS, NULL);
|
2003-05-22 05:36:00 +02:00
|
|
|
|
if (!worker_tls) worker_tls = TlsAlloc();
|
2002-10-31 23:45:12 +01:00
|
|
|
|
std_listen = TRUE;
|
2002-10-11 19:52:37 +02:00
|
|
|
|
server_thread = CreateThread(NULL, 0, RPCRT4_server_thread, NULL, 0, NULL);
|
2002-10-31 23:45:12 +01:00
|
|
|
|
LeaveCriticalSection(&listen_cs);
|
|
|
|
|
} else {
|
|
|
|
|
LeaveCriticalSection(&listen_cs);
|
|
|
|
|
SetEvent(mgr_event);
|
2002-10-11 19:52:37 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void RPCRT4_stop_listen(void)
|
|
|
|
|
{
|
2002-10-31 23:45:12 +01:00
|
|
|
|
EnterCriticalSection(&listen_cs);
|
|
|
|
|
if (listen_count == -1)
|
|
|
|
|
LeaveCriticalSection(&listen_cs);
|
|
|
|
|
else if (--listen_count == -1) {
|
|
|
|
|
std_listen = FALSE;
|
|
|
|
|
LeaveCriticalSection(&listen_cs);
|
|
|
|
|
SetEvent(mgr_event);
|
|
|
|
|
} else
|
|
|
|
|
LeaveCriticalSection(&listen_cs);
|
|
|
|
|
assert(listen_count > -2);
|
2002-10-11 19:52:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static RPC_STATUS RPCRT4_use_protseq(RpcServerProtseq* ps)
|
|
|
|
|
{
|
2003-04-19 22:06:42 +02:00
|
|
|
|
RPCRT4_CreateConnection(&ps->conn, TRUE, ps->Protseq, NULL, ps->Endpoint, NULL, NULL);
|
2002-10-11 19:52:37 +02:00
|
|
|
|
|
|
|
|
|
EnterCriticalSection(&server_cs);
|
|
|
|
|
ps->Next = protseqs;
|
|
|
|
|
protseqs = ps;
|
|
|
|
|
LeaveCriticalSection(&server_cs);
|
|
|
|
|
|
2002-10-31 23:45:12 +01:00
|
|
|
|
if (std_listen) SetEvent(mgr_event);
|
2002-10-11 19:52:37 +02:00
|
|
|
|
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* RpcServerInqBindings (RPCRT4.@)
|
|
|
|
|
*/
|
|
|
|
|
RPC_STATUS WINAPI RpcServerInqBindings( RPC_BINDING_VECTOR** BindingVector )
|
|
|
|
|
{
|
|
|
|
|
RPC_STATUS status;
|
|
|
|
|
DWORD count;
|
|
|
|
|
RpcServerProtseq* ps;
|
2003-02-19 04:44:35 +01:00
|
|
|
|
RpcConnection* conn;
|
2002-10-11 19:52:37 +02:00
|
|
|
|
|
2002-10-18 05:56:56 +02:00
|
|
|
|
if (BindingVector)
|
|
|
|
|
TRACE("(*BindingVector == ^%p)\n", *BindingVector);
|
|
|
|
|
else
|
2003-11-21 00:39:18 +01:00
|
|
|
|
ERR("(BindingVector == NULL!!?)\n");
|
2002-10-18 05:56:56 +02:00
|
|
|
|
|
2002-10-11 19:52:37 +02:00
|
|
|
|
EnterCriticalSection(&server_cs);
|
2003-02-19 04:44:35 +01:00
|
|
|
|
/* count connections */
|
2002-10-11 19:52:37 +02:00
|
|
|
|
count = 0;
|
|
|
|
|
ps = protseqs;
|
|
|
|
|
while (ps) {
|
2003-02-19 04:44:35 +01:00
|
|
|
|
conn = ps->conn;
|
|
|
|
|
while (conn) {
|
2002-10-11 19:52:37 +02:00
|
|
|
|
count++;
|
2003-02-19 04:44:35 +01:00
|
|
|
|
conn = conn->Next;
|
2002-10-11 19:52:37 +02:00
|
|
|
|
}
|
|
|
|
|
ps = ps->Next;
|
|
|
|
|
}
|
|
|
|
|
if (count) {
|
|
|
|
|
/* export bindings */
|
|
|
|
|
*BindingVector = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
|
sizeof(RPC_BINDING_VECTOR) +
|
|
|
|
|
sizeof(RPC_BINDING_HANDLE)*(count-1));
|
|
|
|
|
(*BindingVector)->Count = count;
|
|
|
|
|
count = 0;
|
|
|
|
|
ps = protseqs;
|
|
|
|
|
while (ps) {
|
2003-02-19 04:44:35 +01:00
|
|
|
|
conn = ps->conn;
|
|
|
|
|
while (conn) {
|
|
|
|
|
RPCRT4_MakeBinding((RpcBinding**)&(*BindingVector)->BindingH[count],
|
|
|
|
|
conn);
|
2002-10-11 19:52:37 +02:00
|
|
|
|
count++;
|
2003-02-19 04:44:35 +01:00
|
|
|
|
conn = conn->Next;
|
2002-10-11 19:52:37 +02:00
|
|
|
|
}
|
|
|
|
|
ps = ps->Next;
|
|
|
|
|
}
|
|
|
|
|
status = RPC_S_OK;
|
|
|
|
|
} else {
|
|
|
|
|
*BindingVector = NULL;
|
|
|
|
|
status = RPC_S_NO_BINDINGS;
|
|
|
|
|
}
|
|
|
|
|
LeaveCriticalSection(&server_cs);
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* RpcServerUseProtseqEpA (RPCRT4.@)
|
|
|
|
|
*/
|
2004-04-20 01:03:58 +02:00
|
|
|
|
RPC_STATUS WINAPI RpcServerUseProtseqEpA( unsigned char *Protseq, UINT MaxCalls, unsigned char *Endpoint, LPVOID SecurityDescriptor )
|
2002-10-11 19:52:37 +02:00
|
|
|
|
{
|
|
|
|
|
RPC_POLICY policy;
|
|
|
|
|
|
|
|
|
|
TRACE( "(%s,%u,%s,%p)\n", Protseq, MaxCalls, Endpoint, SecurityDescriptor );
|
|
|
|
|
|
|
|
|
|
/* This should provide the default behaviour */
|
|
|
|
|
policy.Length = sizeof( policy );
|
|
|
|
|
policy.EndpointFlags = 0;
|
|
|
|
|
policy.NICFlags = 0;
|
|
|
|
|
|
|
|
|
|
return RpcServerUseProtseqEpExA( Protseq, MaxCalls, Endpoint, SecurityDescriptor, &policy );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* RpcServerUseProtseqEpW (RPCRT4.@)
|
|
|
|
|
*/
|
|
|
|
|
RPC_STATUS WINAPI RpcServerUseProtseqEpW( LPWSTR Protseq, UINT MaxCalls, LPWSTR Endpoint, LPVOID SecurityDescriptor )
|
|
|
|
|
{
|
|
|
|
|
RPC_POLICY policy;
|
|
|
|
|
|
|
|
|
|
TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq ), MaxCalls, debugstr_w( Endpoint ), SecurityDescriptor );
|
|
|
|
|
|
|
|
|
|
/* This should provide the default behaviour */
|
|
|
|
|
policy.Length = sizeof( policy );
|
|
|
|
|
policy.EndpointFlags = 0;
|
|
|
|
|
policy.NICFlags = 0;
|
|
|
|
|
|
|
|
|
|
return RpcServerUseProtseqEpExW( Protseq, MaxCalls, Endpoint, SecurityDescriptor, &policy );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* RpcServerUseProtseqEpExA (RPCRT4.@)
|
|
|
|
|
*/
|
2004-04-20 01:03:58 +02:00
|
|
|
|
RPC_STATUS WINAPI RpcServerUseProtseqEpExA( unsigned char *Protseq, UINT MaxCalls, unsigned char *Endpoint, LPVOID SecurityDescriptor,
|
2002-10-11 19:52:37 +02:00
|
|
|
|
PRPC_POLICY lpPolicy )
|
|
|
|
|
{
|
|
|
|
|
RpcServerProtseq* ps;
|
|
|
|
|
|
2002-10-28 21:07:01 +01:00
|
|
|
|
TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a( Protseq ), MaxCalls,
|
2002-10-11 19:52:37 +02:00
|
|
|
|
debugstr_a( Endpoint ), SecurityDescriptor,
|
|
|
|
|
lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
|
|
|
|
|
|
|
|
|
|
ps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcServerProtseq));
|
|
|
|
|
ps->MaxCalls = MaxCalls;
|
|
|
|
|
ps->Protseq = RPCRT4_strdupA(Protseq);
|
|
|
|
|
ps->Endpoint = RPCRT4_strdupA(Endpoint);
|
|
|
|
|
|
|
|
|
|
return RPCRT4_use_protseq(ps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* RpcServerUseProtseqEpExW (RPCRT4.@)
|
|
|
|
|
*/
|
|
|
|
|
RPC_STATUS WINAPI RpcServerUseProtseqEpExW( LPWSTR Protseq, UINT MaxCalls, LPWSTR Endpoint, LPVOID SecurityDescriptor,
|
|
|
|
|
PRPC_POLICY lpPolicy )
|
|
|
|
|
{
|
|
|
|
|
RpcServerProtseq* ps;
|
|
|
|
|
|
2002-10-28 21:07:01 +01:00
|
|
|
|
TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq ), MaxCalls,
|
2002-10-11 19:52:37 +02:00
|
|
|
|
debugstr_w( Endpoint ), SecurityDescriptor,
|
|
|
|
|
lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
|
|
|
|
|
|
|
|
|
|
ps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcServerProtseq));
|
|
|
|
|
ps->MaxCalls = MaxCalls;
|
|
|
|
|
ps->Protseq = RPCRT4_strdupWtoA(Protseq);
|
|
|
|
|
ps->Endpoint = RPCRT4_strdupWtoA(Endpoint);
|
|
|
|
|
|
|
|
|
|
return RPCRT4_use_protseq(ps);
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-22 01:41:35 +02:00
|
|
|
|
/***********************************************************************
|
|
|
|
|
* RpcServerUseProtseqA (RPCRT4.@)
|
|
|
|
|
*/
|
2004-04-20 01:03:58 +02:00
|
|
|
|
RPC_STATUS WINAPI RpcServerUseProtseqA(unsigned char *Protseq, unsigned int MaxCalls, void *SecurityDescriptor)
|
2002-10-22 01:41:35 +02:00
|
|
|
|
{
|
2004-01-27 01:01:43 +01:00
|
|
|
|
TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a(Protseq), MaxCalls, SecurityDescriptor);
|
2002-10-22 02:40:01 +02:00
|
|
|
|
return RpcServerUseProtseqEpA(Protseq, MaxCalls, NULL, SecurityDescriptor);
|
2002-10-22 01:41:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* RpcServerUseProtseqW (RPCRT4.@)
|
|
|
|
|
*/
|
|
|
|
|
RPC_STATUS WINAPI RpcServerUseProtseqW(LPWSTR Protseq, unsigned int MaxCalls, void *SecurityDescriptor)
|
|
|
|
|
{
|
2004-01-27 01:01:43 +01:00
|
|
|
|
TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_w(Protseq), MaxCalls, SecurityDescriptor);
|
2002-10-22 02:40:01 +02:00
|
|
|
|
return RpcServerUseProtseqEpW(Protseq, MaxCalls, NULL, SecurityDescriptor);
|
2002-10-22 01:41:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
2002-10-11 19:52:37 +02:00
|
|
|
|
/***********************************************************************
|
|
|
|
|
* RpcServerRegisterIf (RPCRT4.@)
|
|
|
|
|
*/
|
|
|
|
|
RPC_STATUS WINAPI RpcServerRegisterIf( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv )
|
|
|
|
|
{
|
|
|
|
|
TRACE("(%p,%s,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv);
|
|
|
|
|
return RpcServerRegisterIf2( IfSpec, MgrTypeUuid, MgrEpv, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, (UINT)-1, NULL );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* RpcServerRegisterIfEx (RPCRT4.@)
|
|
|
|
|
*/
|
|
|
|
|
RPC_STATUS WINAPI RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv,
|
|
|
|
|
UINT Flags, UINT MaxCalls, RPC_IF_CALLBACK_FN* IfCallbackFn )
|
|
|
|
|
{
|
|
|
|
|
TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv, Flags, MaxCalls, IfCallbackFn);
|
|
|
|
|
return RpcServerRegisterIf2( IfSpec, MgrTypeUuid, MgrEpv, Flags, MaxCalls, (UINT)-1, IfCallbackFn );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* RpcServerRegisterIf2 (RPCRT4.@)
|
|
|
|
|
*/
|
|
|
|
|
RPC_STATUS WINAPI RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv,
|
|
|
|
|
UINT Flags, UINT MaxCalls, UINT MaxRpcSize, RPC_IF_CALLBACK_FN* IfCallbackFn )
|
|
|
|
|
{
|
|
|
|
|
PRPC_SERVER_INTERFACE If = (PRPC_SERVER_INTERFACE)IfSpec;
|
|
|
|
|
RpcServerInterface* sif;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv, Flags, MaxCalls,
|
|
|
|
|
MaxRpcSize, IfCallbackFn);
|
|
|
|
|
TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If->InterfaceId.SyntaxGUID),
|
|
|
|
|
If->InterfaceId.SyntaxVersion.MajorVersion,
|
|
|
|
|
If->InterfaceId.SyntaxVersion.MinorVersion);
|
2002-10-24 01:36:05 +02:00
|
|
|
|
TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If->TransferSyntax.SyntaxGUID),
|
|
|
|
|
If->TransferSyntax.SyntaxVersion.MajorVersion,
|
|
|
|
|
If->TransferSyntax.SyntaxVersion.MinorVersion);
|
2002-10-11 19:52:37 +02:00
|
|
|
|
TRACE(" dispatch table: %p\n", If->DispatchTable);
|
|
|
|
|
if (If->DispatchTable) {
|
|
|
|
|
TRACE(" dispatch table count: %d\n", If->DispatchTable->DispatchTableCount);
|
|
|
|
|
for (i=0; i<If->DispatchTable->DispatchTableCount; i++) {
|
|
|
|
|
TRACE(" entry %d: %p\n", i, If->DispatchTable->DispatchTable[i]);
|
|
|
|
|
}
|
|
|
|
|
TRACE(" reserved: %ld\n", If->DispatchTable->Reserved);
|
|
|
|
|
}
|
|
|
|
|
TRACE(" protseq endpoint count: %d\n", If->RpcProtseqEndpointCount);
|
|
|
|
|
TRACE(" default manager epv: %p\n", If->DefaultManagerEpv);
|
|
|
|
|
TRACE(" interpreter info: %p\n", If->InterpreterInfo);
|
|
|
|
|
|
|
|
|
|
sif = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcServerInterface));
|
|
|
|
|
sif->If = If;
|
2003-11-21 23:14:42 +01:00
|
|
|
|
if (MgrTypeUuid) {
|
2002-10-11 19:52:37 +02:00
|
|
|
|
memcpy(&sif->MgrTypeUuid, MgrTypeUuid, sizeof(UUID));
|
2003-11-21 23:14:42 +01:00
|
|
|
|
sif->MgrEpv = MgrEpv;
|
|
|
|
|
} else {
|
2002-10-11 19:52:37 +02:00
|
|
|
|
memset(&sif->MgrTypeUuid, 0, sizeof(UUID));
|
2003-11-21 23:14:42 +01:00
|
|
|
|
sif->MgrEpv = If->DefaultManagerEpv;
|
|
|
|
|
}
|
2002-10-11 19:52:37 +02:00
|
|
|
|
sif->Flags = Flags;
|
|
|
|
|
sif->MaxCalls = MaxCalls;
|
|
|
|
|
sif->MaxRpcSize = MaxRpcSize;
|
|
|
|
|
sif->IfCallbackFn = IfCallbackFn;
|
|
|
|
|
|
|
|
|
|
EnterCriticalSection(&server_cs);
|
|
|
|
|
sif->Next = ifs;
|
|
|
|
|
ifs = sif;
|
|
|
|
|
LeaveCriticalSection(&server_cs);
|
|
|
|
|
|
|
|
|
|
if (sif->Flags & RPC_IF_AUTOLISTEN) {
|
|
|
|
|
/* well, start listening, I think... */
|
|
|
|
|
RPCRT4_start_listen();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-31 23:45:12 +01:00
|
|
|
|
/***********************************************************************
|
|
|
|
|
* RpcServerUnregisterIf (RPCRT4.@)
|
|
|
|
|
*/
|
|
|
|
|
RPC_STATUS WINAPI RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, UINT WaitForCallsToComplete )
|
|
|
|
|
{
|
|
|
|
|
FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, WaitForCallsToComplete == %u): stub\n",
|
|
|
|
|
IfSpec, debugstr_guid(MgrTypeUuid), WaitForCallsToComplete);
|
|
|
|
|
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* RpcServerUnregisterIfEx (RPCRT4.@)
|
|
|
|
|
*/
|
|
|
|
|
RPC_STATUS WINAPI RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, int RundownContextHandles )
|
|
|
|
|
{
|
|
|
|
|
FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
|
|
|
|
|
IfSpec, debugstr_guid(MgrTypeUuid), RundownContextHandles);
|
|
|
|
|
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-21 23:14:42 +01:00
|
|
|
|
/***********************************************************************
|
|
|
|
|
* RpcObjectSetType (RPCRT4.@)
|
|
|
|
|
*
|
|
|
|
|
* PARAMS
|
|
|
|
|
* ObjUuid [I] "Object" UUID
|
|
|
|
|
* TypeUuid [I] "Type" UUID
|
|
|
|
|
*
|
|
|
|
|
* RETURNS
|
|
|
|
|
* RPC_S_OK The call succeeded
|
|
|
|
|
* RPC_S_INVALID_OBJECT The provided object (nil) is not valid
|
|
|
|
|
* RPC_S_ALREADY_REGISTERED The provided object is already registered
|
|
|
|
|
*
|
|
|
|
|
* Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
|
|
|
|
|
* resets the mapping for the specified object UUID to nil (the default).
|
|
|
|
|
* The nil object is always associated with the nil type and cannot be
|
|
|
|
|
* reassigned. Servers can support multiple implementations on the same
|
|
|
|
|
* interface by registering different end-point vectors for the different
|
|
|
|
|
* types. There's no need to call this if a server only supports the nil
|
|
|
|
|
* type, as is typical.
|
|
|
|
|
*/
|
|
|
|
|
RPC_STATUS WINAPI RpcObjectSetType( UUID* ObjUuid, UUID* TypeUuid )
|
|
|
|
|
{
|
|
|
|
|
RpcObjTypeMap *map = RpcObjTypeMaps, *prev = NULL;
|
|
|
|
|
RPC_STATUS dummy;
|
|
|
|
|
|
|
|
|
|
TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid), debugstr_guid(TypeUuid));
|
|
|
|
|
if ((! ObjUuid) || UuidIsNil(ObjUuid, &dummy)) {
|
|
|
|
|
/* nil uuid cannot be remapped */
|
|
|
|
|
return RPC_S_INVALID_OBJECT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* find the mapping for this object if there is one ... */
|
|
|
|
|
while (map) {
|
|
|
|
|
if (! UuidCompare(ObjUuid, &map->Object, &dummy)) break;
|
|
|
|
|
prev = map;
|
|
|
|
|
map = map->next;
|
|
|
|
|
}
|
|
|
|
|
if ((! TypeUuid) || UuidIsNil(TypeUuid, &dummy)) {
|
|
|
|
|
/* ... and drop it from the list */
|
|
|
|
|
if (map) {
|
|
|
|
|
if (prev)
|
|
|
|
|
prev->next = map->next;
|
|
|
|
|
else
|
|
|
|
|
RpcObjTypeMaps = map->next;
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, map);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* ... , fail if we found it ... */
|
|
|
|
|
if (map)
|
|
|
|
|
return RPC_S_ALREADY_REGISTERED;
|
|
|
|
|
/* ... otherwise create a new one and add it in. */
|
|
|
|
|
map = HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap));
|
|
|
|
|
memcpy(&map->Object, ObjUuid, sizeof(UUID));
|
|
|
|
|
memcpy(&map->Type, TypeUuid, sizeof(UUID));
|
|
|
|
|
map->next = NULL;
|
|
|
|
|
if (prev)
|
|
|
|
|
prev->next = map; /* prev is the last map in the linklist */
|
|
|
|
|
else
|
|
|
|
|
RpcObjTypeMaps = map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-11 19:52:37 +02:00
|
|
|
|
/***********************************************************************
|
|
|
|
|
* RpcServerRegisterAuthInfoA (RPCRT4.@)
|
|
|
|
|
*/
|
2004-04-20 01:03:58 +02:00
|
|
|
|
RPC_STATUS WINAPI RpcServerRegisterAuthInfoA( unsigned char *ServerPrincName, ULONG AuthnSvc, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
|
2002-10-11 19:52:37 +02:00
|
|
|
|
LPVOID Arg )
|
|
|
|
|
{
|
|
|
|
|
FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName, AuthnSvc, GetKeyFn, Arg );
|
|
|
|
|
|
|
|
|
|
return RPC_S_UNKNOWN_AUTHN_SERVICE; /* We don't know any authentication services */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* RpcServerRegisterAuthInfoW (RPCRT4.@)
|
|
|
|
|
*/
|
|
|
|
|
RPC_STATUS WINAPI RpcServerRegisterAuthInfoW( LPWSTR ServerPrincName, ULONG AuthnSvc, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
|
|
|
|
|
LPVOID Arg )
|
|
|
|
|
{
|
|
|
|
|
FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName ), AuthnSvc, GetKeyFn, Arg );
|
|
|
|
|
|
|
|
|
|
return RPC_S_UNKNOWN_AUTHN_SERVICE; /* We don't know any authentication services */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* RpcServerListen (RPCRT4.@)
|
|
|
|
|
*/
|
|
|
|
|
RPC_STATUS WINAPI RpcServerListen( UINT MinimumCallThreads, UINT MaxCalls, UINT DontWait )
|
|
|
|
|
{
|
|
|
|
|
TRACE("(%u,%u,%u)\n", MinimumCallThreads, MaxCalls, DontWait);
|
|
|
|
|
|
|
|
|
|
if (!protseqs)
|
|
|
|
|
return RPC_S_NO_PROTSEQS_REGISTERED;
|
|
|
|
|
|
2002-10-31 23:45:12 +01:00
|
|
|
|
EnterCriticalSection(&listen_cs);
|
|
|
|
|
|
|
|
|
|
if (std_listen) {
|
|
|
|
|
LeaveCriticalSection(&listen_cs);
|
|
|
|
|
return RPC_S_ALREADY_LISTENING;
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-11 19:52:37 +02:00
|
|
|
|
RPCRT4_start_listen();
|
|
|
|
|
|
2002-10-31 23:45:12 +01:00
|
|
|
|
LeaveCriticalSection(&listen_cs);
|
|
|
|
|
|
2002-10-11 19:52:37 +02:00
|
|
|
|
if (DontWait) return RPC_S_OK;
|
|
|
|
|
|
2002-10-18 05:56:56 +02:00
|
|
|
|
return RpcMgmtWaitServerListen();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* RpcMgmtServerWaitListen (RPCRT4.@)
|
|
|
|
|
*/
|
|
|
|
|
RPC_STATUS WINAPI RpcMgmtWaitServerListen( void )
|
|
|
|
|
{
|
2002-10-19 21:14:45 +02:00
|
|
|
|
RPC_STATUS rslt = RPC_S_OK;
|
2002-10-18 05:56:56 +02:00
|
|
|
|
|
2002-10-19 21:14:45 +02:00
|
|
|
|
TRACE("\n");
|
2002-10-31 23:45:12 +01:00
|
|
|
|
|
|
|
|
|
EnterCriticalSection(&listen_cs);
|
|
|
|
|
|
2002-10-19 21:14:45 +02:00
|
|
|
|
if (!std_listen)
|
2002-10-31 23:45:12 +01:00
|
|
|
|
if ( (rslt = RpcServerListen(1, 0, TRUE)) != RPC_S_OK ) {
|
|
|
|
|
LeaveCriticalSection(&listen_cs);
|
2002-10-19 21:14:45 +02:00
|
|
|
|
return rslt;
|
2002-10-31 23:45:12 +01:00
|
|
|
|
}
|
2002-10-19 21:14:45 +02:00
|
|
|
|
|
2002-10-31 23:45:12 +01:00
|
|
|
|
LeaveCriticalSection(&listen_cs);
|
|
|
|
|
|
2002-10-19 21:14:45 +02:00
|
|
|
|
while (std_listen) {
|
2002-10-31 23:45:12 +01:00
|
|
|
|
WaitForSingleObject(mgr_event, INFINITE);
|
|
|
|
|
if (!std_listen) {
|
|
|
|
|
Sleep(100); /* don't spin violently */
|
|
|
|
|
TRACE("spinning.\n");
|
|
|
|
|
}
|
2002-10-18 05:56:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
2002-10-19 21:14:45 +02:00
|
|
|
|
return rslt;
|
2002-10-11 19:52:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
2002-10-31 23:45:12 +01:00
|
|
|
|
/***********************************************************************
|
|
|
|
|
* RpcMgmtStopServerListening (RPCRT4.@)
|
|
|
|
|
*/
|
|
|
|
|
RPC_STATUS WINAPI RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding )
|
|
|
|
|
{
|
|
|
|
|
TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding);
|
|
|
|
|
|
|
|
|
|
if (Binding) {
|
|
|
|
|
FIXME("client-side invocation not implemented.\n");
|
|
|
|
|
return RPC_S_WRONG_KIND_OF_BINDING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* hmm... */
|
|
|
|
|
EnterCriticalSection(&listen_cs);
|
|
|
|
|
while (std_listen)
|
|
|
|
|
RPCRT4_stop_listen();
|
|
|
|
|
LeaveCriticalSection(&listen_cs);
|
|
|
|
|
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-11 19:52:37 +02:00
|
|
|
|
/***********************************************************************
|
|
|
|
|
* I_RpcServerStartListening (RPCRT4.@)
|
|
|
|
|
*/
|
|
|
|
|
RPC_STATUS WINAPI I_RpcServerStartListening( void* hWnd )
|
|
|
|
|
{
|
|
|
|
|
FIXME( "(%p): stub\n", hWnd );
|
|
|
|
|
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* I_RpcServerStopListening (RPCRT4.@)
|
|
|
|
|
*/
|
|
|
|
|
RPC_STATUS WINAPI I_RpcServerStopListening( void )
|
|
|
|
|
{
|
|
|
|
|
FIXME( "(): stub\n" );
|
|
|
|
|
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* I_RpcWindowProc (RPCRT4.@)
|
|
|
|
|
*/
|
2002-11-01 02:47:43 +01:00
|
|
|
|
UINT WINAPI I_RpcWindowProc( void *hWnd, UINT Message, UINT wParam, ULONG lParam )
|
2002-10-11 19:52:37 +02:00
|
|
|
|
{
|
|
|
|
|
FIXME( "(%p,%08x,%08x,%08lx): stub\n", hWnd, Message, wParam, lParam );
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|