4 * Copyright 2001 Ove Kåven, TransGaming Technologies
5 * Copyright 2004 Filip Navara
6 * Copyright 2006-2008 Robert Shearman (for CodeWeavers)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
39 #include "wine/debug.h"
40 #include "wine/exception.h"
42 #include "rpc_server.h"
43 #include "rpc_assoc.h"
44 #include "rpc_message.h"
46 #include "ncastatus.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(rpc
);
50 typedef struct _RpcPacket
52 struct _RpcConnection
* conn
;
57 typedef struct _RpcObjTypeMap
59 /* FIXME: a hash table would be better. */
60 struct _RpcObjTypeMap
*next
;
65 static RpcObjTypeMap
*RpcObjTypeMaps
;
67 /* list of type RpcServerProtseq */
68 static struct list protseqs
= LIST_INIT(protseqs
);
69 static struct list server_interfaces
= LIST_INIT(server_interfaces
);
71 static CRITICAL_SECTION server_cs
;
72 static CRITICAL_SECTION_DEBUG server_cs_debug
=
75 { &server_cs_debug
.ProcessLocksList
, &server_cs_debug
.ProcessLocksList
},
76 0, 0, { (DWORD_PTR
)(__FILE__
": server_cs") }
78 static CRITICAL_SECTION server_cs
= { &server_cs_debug
, -1, 0, 0, 0, 0 };
80 static CRITICAL_SECTION listen_cs
;
81 static CRITICAL_SECTION_DEBUG listen_cs_debug
=
84 { &listen_cs_debug
.ProcessLocksList
, &listen_cs_debug
.ProcessLocksList
},
85 0, 0, { (DWORD_PTR
)(__FILE__
": listen_cs") }
87 static CRITICAL_SECTION listen_cs
= { &listen_cs_debug
, -1, 0, 0, 0, 0 };
89 /* whether the server is currently listening */
90 static BOOL std_listen
;
91 /* number of manual listeners (calls to RpcServerListen) */
92 static LONG manual_listen_count
;
93 /* total listeners including auto listeners */
94 static LONG listen_count
;
98 static inline RpcObjTypeMap
*LookupObjTypeMap(UUID
*ObjUuid
)
100 RpcObjTypeMap
*rslt
= RpcObjTypeMaps
;
104 if (! UuidCompare(ObjUuid
, &rslt
->Object
, &dummy
)) break;
111 static inline UUID
*LookupObjType(UUID
*ObjUuid
)
113 RpcObjTypeMap
*map
= LookupObjTypeMap(ObjUuid
);
120 static RpcServerInterface
* RPCRT4_find_interface(UUID
* object
,
121 const RPC_SYNTAX_IDENTIFIER
* if_id
,
124 UUID
* MgrType
= NULL
;
125 RpcServerInterface
* cif
;
129 MgrType
= LookupObjType(object
);
130 EnterCriticalSection(&server_cs
);
131 LIST_FOR_EACH_ENTRY(cif
, &server_interfaces
, RpcServerInterface
, entry
) {
132 if (!memcmp(if_id
, &cif
->If
->InterfaceId
, sizeof(RPC_SYNTAX_IDENTIFIER
)) &&
133 (check_object
== FALSE
|| UuidEqual(MgrType
, &cif
->MgrTypeUuid
, &status
)) &&
135 InterlockedIncrement(&cif
->CurrentCalls
);
139 LeaveCriticalSection(&server_cs
);
140 if (&cif
->entry
== &server_interfaces
) cif
= NULL
;
141 TRACE("returning %p for object %s, if_id { %d.%d %s }\n", cif
,
142 debugstr_guid(object
), if_id
->SyntaxVersion
.MajorVersion
,
143 if_id
->SyntaxVersion
.MinorVersion
, debugstr_guid(&if_id
->SyntaxGUID
));
147 static void RPCRT4_release_server_interface(RpcServerInterface
*sif
)
149 if (!InterlockedDecrement(&sif
->CurrentCalls
) &&
150 sif
->CallsCompletedEvent
) {
151 /* sif must have been removed from server_interfaces before
152 * CallsCompletedEvent is set */
153 SetEvent(sif
->CallsCompletedEvent
);
154 HeapFree(GetProcessHeap(), 0, sif
);
158 static RPC_STATUS
process_bind_packet(RpcConnection
*conn
, RpcPktBindHdr
*hdr
, RPC_MESSAGE
*msg
)
161 RpcServerInterface
* sif
;
162 RpcPktHdr
*response
= NULL
;
164 /* FIXME: do more checks! */
165 if (hdr
->max_tsize
< RPC_MIN_PACKET_SIZE
||
166 !UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
) ||
167 conn
->server_binding
) {
168 TRACE("packet size less than min size, or active interface syntax guid non-null\n");
171 /* create temporary binding */
172 if (RPCRT4_MakeBinding(&conn
->server_binding
, conn
) == RPC_S_OK
&&
173 RpcServerAssoc_GetAssociation(rpcrt4_conn_get_name(conn
),
174 conn
->NetworkAddr
, conn
->Endpoint
,
175 conn
->NetworkOptions
,
177 &conn
->server_binding
->Assoc
) == RPC_S_OK
)
178 sif
= RPCRT4_find_interface(NULL
, &hdr
->abstract
, FALSE
);
183 TRACE("rejecting bind request on connection %p\n", conn
);
184 /* Report failure to client. */
185 response
= RPCRT4_BuildBindNackHeader(NDR_LOCAL_DATA_REPRESENTATION
,
186 RPC_VER_MAJOR
, RPC_VER_MINOR
);
188 TRACE("accepting bind request on connection %p for %s\n", conn
,
189 debugstr_guid(&hdr
->abstract
.SyntaxGUID
));
192 response
= RPCRT4_BuildBindAckHeader(NDR_LOCAL_DATA_REPRESENTATION
,
195 conn
->server_binding
->Assoc
->assoc_group_id
,
197 RESULT_ACCEPT
, REASON_NONE
,
198 &sif
->If
->TransferSyntax
);
200 /* save the interface for later use */
201 conn
->ActiveInterface
= hdr
->abstract
;
202 conn
->MaxTransmissionSize
= hdr
->max_tsize
;
204 RPCRT4_release_server_interface(sif
);
208 status
= RPCRT4_Send(conn
, response
, NULL
, 0);
210 status
= ERROR_OUTOFMEMORY
;
211 RPCRT4_FreeHeader(response
);
216 static RPC_STATUS
process_request_packet(RpcConnection
*conn
, RpcPktRequestHdr
*hdr
, RPC_MESSAGE
*msg
)
219 RpcPktHdr
*response
= NULL
;
220 RpcServerInterface
* sif
;
221 RPC_DISPATCH_FUNCTION func
;
224 NDR_SCONTEXT context_handle
;
225 void *buf
= msg
->Buffer
;
227 /* fail if the connection isn't bound with an interface */
228 if (UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
229 /* FIXME: should send BindNack instead */
230 response
= RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION
,
233 RPCRT4_Send(conn
, response
, NULL
, 0);
234 RPCRT4_FreeHeader(response
);
238 if (hdr
->common
.flags
& RPC_FLG_OBJECT_UUID
) {
239 object_uuid
= (UUID
*)(hdr
+ 1);
244 sif
= RPCRT4_find_interface(object_uuid
, &conn
->ActiveInterface
, TRUE
);
246 WARN("interface %s no longer registered, returning fault packet\n", debugstr_guid(&conn
->ActiveInterface
.SyntaxGUID
));
247 response
= RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION
,
250 RPCRT4_Send(conn
, response
, NULL
, 0);
251 RPCRT4_FreeHeader(response
);
254 msg
->RpcInterfaceInformation
= sif
->If
;
255 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
256 msg
->ManagerEpv
= sif
->MgrEpv
;
257 if (object_uuid
!= NULL
) {
258 RPCRT4_SetBindingObject(msg
->Handle
, object_uuid
);
261 /* find dispatch function */
262 msg
->ProcNum
= hdr
->opnum
;
263 if (sif
->Flags
& RPC_IF_OLE
) {
264 /* native ole32 always gives us a dispatch table with a single entry
265 * (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
266 func
= *sif
->If
->DispatchTable
->DispatchTable
;
268 if (msg
->ProcNum
>= sif
->If
->DispatchTable
->DispatchTableCount
) {
269 WARN("invalid procnum (%d/%d)\n", msg
->ProcNum
, sif
->If
->DispatchTable
->DispatchTableCount
);
270 response
= RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION
,
273 RPCRT4_Send(conn
, response
, NULL
, 0);
274 RPCRT4_FreeHeader(response
);
276 func
= sif
->If
->DispatchTable
->DispatchTable
[msg
->ProcNum
];
279 /* put in the drep. FIXME: is this more universally applicable?
280 perhaps we should move this outward... */
281 msg
->DataRepresentation
=
282 MAKELONG( MAKEWORD(hdr
->common
.drep
[0], hdr
->common
.drep
[1]),
283 MAKEWORD(hdr
->common
.drep
[2], hdr
->common
.drep
[3]));
288 RPCRT4_SetThreadCurrentCallHandle(msg
->Handle
);
292 WARN("exception caught with code 0x%08x = %d\n", GetExceptionCode(), GetExceptionCode());
294 if (GetExceptionCode() == STATUS_ACCESS_VIOLATION
)
295 status
= ERROR_NOACCESS
;
297 status
= GetExceptionCode();
298 response
= RPCRT4_BuildFaultHeader(msg
->DataRepresentation
,
299 RPC2NCA_STATUS(status
));
301 RPCRT4_SetThreadCurrentCallHandle(NULL
);
303 /* release any unmarshalled context handles */
304 while ((context_handle
= RPCRT4_PopThreadContextHandle()) != NULL
)
305 RpcServerAssoc_ReleaseContextHandle(conn
->server_binding
->Assoc
, context_handle
, TRUE
);
308 response
= RPCRT4_BuildResponseHeader(msg
->DataRepresentation
,
311 /* send response packet */
313 status
= RPCRT4_Send(conn
, response
, exception
? NULL
: msg
->Buffer
,
314 exception
? 0 : msg
->BufferLength
);
315 RPCRT4_FreeHeader(response
);
317 ERR("out of memory\n");
319 msg
->RpcInterfaceInformation
= NULL
;
320 RPCRT4_release_server_interface(sif
);
322 if (msg
->Buffer
== buf
) buf
= NULL
;
323 TRACE("freeing Buffer=%p\n", buf
);
329 static void RPCRT4_process_packet(RpcConnection
* conn
, RpcPktHdr
* hdr
, RPC_MESSAGE
* msg
)
333 msg
->Handle
= (RPC_BINDING_HANDLE
)conn
->server_binding
;
335 switch (hdr
->common
.ptype
) {
337 TRACE("got bind packet\n");
339 status
= process_bind_packet(conn
, &hdr
->bind
, msg
);
343 TRACE("got request packet\n");
345 status
= process_request_packet(conn
, &hdr
->request
, msg
);
349 FIXME("unhandled packet type %u\n", hdr
->common
.ptype
);
354 I_RpcFreeBuffer(msg
);
355 RPCRT4_FreeHeader(hdr
);
356 HeapFree(GetProcessHeap(), 0, msg
);
359 static DWORD CALLBACK
RPCRT4_worker_thread(LPVOID the_arg
)
361 RpcPacket
*pkt
= the_arg
;
362 RPCRT4_process_packet(pkt
->conn
, pkt
->hdr
, pkt
->msg
);
363 HeapFree(GetProcessHeap(), 0, pkt
);
367 static DWORD CALLBACK
RPCRT4_io_thread(LPVOID the_arg
)
369 RpcConnection
* conn
= (RpcConnection
*)the_arg
;
375 TRACE("(%p)\n", conn
);
378 msg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RPC_MESSAGE
));
380 status
= RPCRT4_Receive(conn
, &hdr
, msg
);
381 if (status
!= RPC_S_OK
) {
382 WARN("receive failed with error %lx\n", status
);
383 HeapFree(GetProcessHeap(), 0, msg
);
387 packet
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket
));
389 I_RpcFree(msg
->Buffer
);
390 HeapFree(GetProcessHeap(), 0, msg
);
396 if (!QueueUserWorkItem(RPCRT4_worker_thread
, packet
, WT_EXECUTELONGFUNCTION
)) {
397 ERR("couldn't queue work item for worker thread, error was %d\n", GetLastError());
398 I_RpcFree(msg
->Buffer
);
399 HeapFree(GetProcessHeap(), 0, msg
);
400 HeapFree(GetProcessHeap(), 0, packet
);
406 RPCRT4_DestroyConnection(conn
);
410 void RPCRT4_new_client(RpcConnection
* conn
)
412 HANDLE thread
= CreateThread(NULL
, 0, RPCRT4_io_thread
, conn
, 0, NULL
);
414 DWORD err
= GetLastError();
415 ERR("failed to create thread, error=%08x\n", err
);
416 RPCRT4_DestroyConnection(conn
);
418 /* we could set conn->thread, but then we'd have to make the io_thread wait
419 * for that, otherwise the thread might finish, destroy the connection, and
420 * free the memory we'd write to before we did, causing crashes and stuff -
421 * so let's implement that later, when we really need conn->thread */
423 CloseHandle( thread
);
426 static DWORD CALLBACK
RPCRT4_server_thread(LPVOID the_arg
)
431 RpcServerProtseq
* cps
= the_arg
;
433 BOOL set_ready_event
= FALSE
;
435 TRACE("(the_arg == ^%p)\n", the_arg
);
438 objs
= cps
->ops
->get_wait_array(cps
, objs
, &count
);
442 /* signal to function that changed state that we are now sync'ed */
443 SetEvent(cps
->server_ready_event
);
444 set_ready_event
= FALSE
;
448 res
= cps
->ops
->wait_for_new_connection(cps
, count
, objs
);
455 SetEvent(cps
->server_ready_event
);
458 set_ready_event
= TRUE
;
461 cps
->ops
->free_wait_array(cps
, objs
);
462 EnterCriticalSection(&cps
->cs
);
463 /* close connections */
466 RPCRT4_CloseConnection(conn
);
469 LeaveCriticalSection(&cps
->cs
);
473 /* tells the server thread that the state has changed and waits for it to
474 * make the changes */
475 static void RPCRT4_sync_with_server_thread(RpcServerProtseq
*ps
)
477 /* make sure we are the only thread sync'ing the server state, otherwise
478 * there is a race with the server thread setting an older state and setting
479 * the server_ready_event when the new state hasn't yet been applied */
480 WaitForSingleObject(ps
->mgr_mutex
, INFINITE
);
482 ps
->ops
->signal_state_changed(ps
);
484 /* wait for server thread to make the requested changes before returning */
485 WaitForSingleObject(ps
->server_ready_event
, INFINITE
);
487 ReleaseMutex(ps
->mgr_mutex
);
490 static RPC_STATUS
RPCRT4_start_listen_protseq(RpcServerProtseq
*ps
, BOOL auto_listen
)
492 RPC_STATUS status
= RPC_S_OK
;
493 HANDLE server_thread
;
495 EnterCriticalSection(&listen_cs
);
496 if (ps
->is_listening
) goto done
;
498 if (!ps
->mgr_mutex
) ps
->mgr_mutex
= CreateMutexW(NULL
, FALSE
, NULL
);
499 if (!ps
->server_ready_event
) ps
->server_ready_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
500 server_thread
= CreateThread(NULL
, 0, RPCRT4_server_thread
, ps
, 0, NULL
);
503 status
= RPC_S_OUT_OF_RESOURCES
;
506 ps
->is_listening
= TRUE
;
507 CloseHandle(server_thread
);
510 LeaveCriticalSection(&listen_cs
);
514 static RPC_STATUS
RPCRT4_start_listen(BOOL auto_listen
)
516 RPC_STATUS status
= RPC_S_ALREADY_LISTENING
;
517 RpcServerProtseq
*cps
;
521 EnterCriticalSection(&listen_cs
);
522 if (auto_listen
|| (manual_listen_count
++ == 0))
525 if (++listen_count
== 1)
528 LeaveCriticalSection(&listen_cs
);
532 EnterCriticalSection(&server_cs
);
533 LIST_FOR_EACH_ENTRY(cps
, &protseqs
, RpcServerProtseq
, entry
)
535 status
= RPCRT4_start_listen_protseq(cps
, TRUE
);
536 if (status
!= RPC_S_OK
)
539 /* make sure server is actually listening on the interface before
541 RPCRT4_sync_with_server_thread(cps
);
543 LeaveCriticalSection(&server_cs
);
549 static void RPCRT4_stop_listen(BOOL auto_listen
)
551 EnterCriticalSection(&listen_cs
);
552 if (auto_listen
|| (--manual_listen_count
== 0))
554 if (listen_count
!= 0 && --listen_count
== 0) {
555 RpcServerProtseq
*cps
;
558 LeaveCriticalSection(&listen_cs
);
560 LIST_FOR_EACH_ENTRY(cps
, &protseqs
, RpcServerProtseq
, entry
)
561 RPCRT4_sync_with_server_thread(cps
);
565 assert(listen_count
>= 0);
567 LeaveCriticalSection(&listen_cs
);
570 static RPC_STATUS
RPCRT4_use_protseq(RpcServerProtseq
* ps
, LPSTR endpoint
)
574 status
= ps
->ops
->open_endpoint(ps
, endpoint
);
575 if (status
!= RPC_S_OK
)
580 status
= RPCRT4_start_listen_protseq(ps
, FALSE
);
581 if (status
== RPC_S_OK
)
582 RPCRT4_sync_with_server_thread(ps
);
588 /***********************************************************************
589 * RpcServerInqBindings (RPCRT4.@)
591 RPC_STATUS WINAPI
RpcServerInqBindings( RPC_BINDING_VECTOR
** BindingVector
)
595 RpcServerProtseq
* ps
;
599 TRACE("(*BindingVector == ^%p)\n", *BindingVector
);
601 ERR("(BindingVector == NULL!!?)\n");
603 EnterCriticalSection(&server_cs
);
604 /* count connections */
606 LIST_FOR_EACH_ENTRY(ps
, &protseqs
, RpcServerProtseq
, entry
) {
607 EnterCriticalSection(&ps
->cs
);
613 LeaveCriticalSection(&ps
->cs
);
616 /* export bindings */
617 *BindingVector
= HeapAlloc(GetProcessHeap(), 0,
618 sizeof(RPC_BINDING_VECTOR
) +
619 sizeof(RPC_BINDING_HANDLE
)*(count
-1));
620 (*BindingVector
)->Count
= count
;
622 LIST_FOR_EACH_ENTRY(ps
, &protseqs
, RpcServerProtseq
, entry
) {
623 EnterCriticalSection(&ps
->cs
);
626 RPCRT4_MakeBinding((RpcBinding
**)&(*BindingVector
)->BindingH
[count
],
631 LeaveCriticalSection(&ps
->cs
);
635 *BindingVector
= NULL
;
636 status
= RPC_S_NO_BINDINGS
;
638 LeaveCriticalSection(&server_cs
);
642 /***********************************************************************
643 * RpcServerUseProtseqEpA (RPCRT4.@)
645 RPC_STATUS WINAPI
RpcServerUseProtseqEpA( RPC_CSTR Protseq
, UINT MaxCalls
, RPC_CSTR Endpoint
, LPVOID SecurityDescriptor
)
649 TRACE( "(%s,%u,%s,%p)\n", Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
);
651 /* This should provide the default behaviour */
652 policy
.Length
= sizeof( policy
);
653 policy
.EndpointFlags
= 0;
656 return RpcServerUseProtseqEpExA( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
659 /***********************************************************************
660 * RpcServerUseProtseqEpW (RPCRT4.@)
662 RPC_STATUS WINAPI
RpcServerUseProtseqEpW( RPC_WSTR Protseq
, UINT MaxCalls
, RPC_WSTR Endpoint
, LPVOID SecurityDescriptor
)
666 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq
), MaxCalls
, debugstr_w( Endpoint
), SecurityDescriptor
);
668 /* This should provide the default behaviour */
669 policy
.Length
= sizeof( policy
);
670 policy
.EndpointFlags
= 0;
673 return RpcServerUseProtseqEpExW( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
676 /***********************************************************************
677 * alloc_serverprotoseq (internal)
679 * Must be called with server_cs held.
681 static RPC_STATUS
alloc_serverprotoseq(UINT MaxCalls
, char *Protseq
, RpcServerProtseq
**ps
)
683 const struct protseq_ops
*ops
= rpcrt4_get_protseq_ops(Protseq
);
687 FIXME("protseq %s not supported\n", debugstr_a(Protseq
));
688 return RPC_S_PROTSEQ_NOT_SUPPORTED
;
693 return RPC_S_OUT_OF_RESOURCES
;
694 (*ps
)->MaxCalls
= MaxCalls
;
695 (*ps
)->Protseq
= Protseq
;
699 InitializeCriticalSection(&(*ps
)->cs
);
700 (*ps
)->is_listening
= FALSE
;
701 (*ps
)->mgr_mutex
= NULL
;
702 (*ps
)->server_ready_event
= NULL
;
704 list_add_head(&protseqs
, &(*ps
)->entry
);
706 TRACE("new protseq %p created for %s\n", *ps
, Protseq
);
711 /* Finds a given protseq or creates a new one if one doesn't already exist */
712 static RPC_STATUS
RPCRT4_get_or_create_serverprotseq(UINT MaxCalls
, char *Protseq
, RpcServerProtseq
**ps
)
715 RpcServerProtseq
*cps
;
717 EnterCriticalSection(&server_cs
);
719 LIST_FOR_EACH_ENTRY(cps
, &protseqs
, RpcServerProtseq
, entry
)
720 if (!strcmp(cps
->Protseq
, Protseq
))
722 TRACE("found existing protseq object for %s\n", Protseq
);
724 LeaveCriticalSection(&server_cs
);
728 status
= alloc_serverprotoseq(MaxCalls
, Protseq
, ps
);
730 LeaveCriticalSection(&server_cs
);
735 /***********************************************************************
736 * RpcServerUseProtseqEpExA (RPCRT4.@)
738 RPC_STATUS WINAPI
RpcServerUseProtseqEpExA( RPC_CSTR Protseq
, UINT MaxCalls
, RPC_CSTR Endpoint
, LPVOID SecurityDescriptor
,
739 PRPC_POLICY lpPolicy
)
741 char *szps
= (char*)Protseq
, *szep
= (char*)Endpoint
;
742 RpcServerProtseq
* ps
;
745 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a(szps
), MaxCalls
,
746 debugstr_a(szep
), SecurityDescriptor
,
747 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
749 status
= RPCRT4_get_or_create_serverprotseq(MaxCalls
, RPCRT4_strdupA(szps
), &ps
);
750 if (status
!= RPC_S_OK
)
753 return RPCRT4_use_protseq(ps
, szep
);
756 /***********************************************************************
757 * RpcServerUseProtseqEpExW (RPCRT4.@)
759 RPC_STATUS WINAPI
RpcServerUseProtseqEpExW( RPC_WSTR Protseq
, UINT MaxCalls
, RPC_WSTR Endpoint
, LPVOID SecurityDescriptor
,
760 PRPC_POLICY lpPolicy
)
762 RpcServerProtseq
* ps
;
766 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq
), MaxCalls
,
767 debugstr_w( Endpoint
), SecurityDescriptor
,
768 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
770 status
= RPCRT4_get_or_create_serverprotseq(MaxCalls
, RPCRT4_strdupWtoA(Protseq
), &ps
);
771 if (status
!= RPC_S_OK
)
774 EndpointA
= RPCRT4_strdupWtoA(Endpoint
);
775 status
= RPCRT4_use_protseq(ps
, EndpointA
);
776 RPCRT4_strfree(EndpointA
);
780 /***********************************************************************
781 * RpcServerUseProtseqA (RPCRT4.@)
783 RPC_STATUS WINAPI
RpcServerUseProtseqA(RPC_CSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
785 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a((char*)Protseq
), MaxCalls
, SecurityDescriptor
);
786 return RpcServerUseProtseqEpA(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
789 /***********************************************************************
790 * RpcServerUseProtseqW (RPCRT4.@)
792 RPC_STATUS WINAPI
RpcServerUseProtseqW(RPC_WSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
794 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_w(Protseq
), MaxCalls
, SecurityDescriptor
);
795 return RpcServerUseProtseqEpW(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
798 /***********************************************************************
799 * RpcServerRegisterIf (RPCRT4.@)
801 RPC_STATUS WINAPI
RpcServerRegisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
)
803 TRACE("(%p,%s,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
);
804 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, (UINT
)-1, NULL
);
807 /***********************************************************************
808 * RpcServerRegisterIfEx (RPCRT4.@)
810 RPC_STATUS WINAPI
RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
811 UINT Flags
, UINT MaxCalls
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
813 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
, IfCallbackFn
);
814 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, Flags
, MaxCalls
, (UINT
)-1, IfCallbackFn
);
817 /***********************************************************************
818 * RpcServerRegisterIf2 (RPCRT4.@)
820 RPC_STATUS WINAPI
RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
821 UINT Flags
, UINT MaxCalls
, UINT MaxRpcSize
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
823 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
824 RpcServerInterface
* sif
;
827 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
,
828 MaxRpcSize
, IfCallbackFn
);
829 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
),
830 If
->InterfaceId
.SyntaxVersion
.MajorVersion
,
831 If
->InterfaceId
.SyntaxVersion
.MinorVersion
);
832 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If
->TransferSyntax
.SyntaxGUID
),
833 If
->TransferSyntax
.SyntaxVersion
.MajorVersion
,
834 If
->TransferSyntax
.SyntaxVersion
.MinorVersion
);
835 TRACE(" dispatch table: %p\n", If
->DispatchTable
);
836 if (If
->DispatchTable
) {
837 TRACE(" dispatch table count: %d\n", If
->DispatchTable
->DispatchTableCount
);
838 for (i
=0; i
<If
->DispatchTable
->DispatchTableCount
; i
++) {
839 TRACE(" entry %d: %p\n", i
, If
->DispatchTable
->DispatchTable
[i
]);
841 TRACE(" reserved: %ld\n", If
->DispatchTable
->Reserved
);
843 TRACE(" protseq endpoint count: %d\n", If
->RpcProtseqEndpointCount
);
844 TRACE(" default manager epv: %p\n", If
->DefaultManagerEpv
);
845 TRACE(" interpreter info: %p\n", If
->InterpreterInfo
);
847 sif
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerInterface
));
850 sif
->MgrTypeUuid
= *MgrTypeUuid
;
851 sif
->MgrEpv
= MgrEpv
;
853 memset(&sif
->MgrTypeUuid
, 0, sizeof(UUID
));
854 sif
->MgrEpv
= If
->DefaultManagerEpv
;
857 sif
->MaxCalls
= MaxCalls
;
858 sif
->MaxRpcSize
= MaxRpcSize
;
859 sif
->IfCallbackFn
= IfCallbackFn
;
861 EnterCriticalSection(&server_cs
);
862 list_add_head(&server_interfaces
, &sif
->entry
);
863 LeaveCriticalSection(&server_cs
);
865 if (sif
->Flags
& RPC_IF_AUTOLISTEN
)
866 RPCRT4_start_listen(TRUE
);
871 /***********************************************************************
872 * RpcServerUnregisterIf (RPCRT4.@)
874 RPC_STATUS WINAPI
RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, UINT WaitForCallsToComplete
)
876 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
879 BOOL completed
= TRUE
;
880 RpcServerInterface
*cif
;
883 TRACE("(IfSpec == (RPC_IF_HANDLE)^%p (%s), MgrTypeUuid == %s, WaitForCallsToComplete == %u)\n",
884 IfSpec
, debugstr_guid(&If
->InterfaceId
.SyntaxGUID
), debugstr_guid(MgrTypeUuid
), WaitForCallsToComplete
);
886 EnterCriticalSection(&server_cs
);
887 LIST_FOR_EACH_ENTRY(cif
, &server_interfaces
, RpcServerInterface
, entry
) {
888 if ((!IfSpec
|| !memcmp(&If
->InterfaceId
, &cif
->If
->InterfaceId
, sizeof(RPC_SYNTAX_IDENTIFIER
))) &&
889 UuidEqual(MgrTypeUuid
, &cif
->MgrTypeUuid
, &status
)) {
890 list_remove(&cif
->entry
);
891 if (cif
->CurrentCalls
) {
893 if (WaitForCallsToComplete
)
894 cif
->CallsCompletedEvent
= event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
900 LeaveCriticalSection(&server_cs
);
903 ERR("not found for object %s\n", debugstr_guid(MgrTypeUuid
));
904 return RPC_S_UNKNOWN_IF
;
908 HeapFree(GetProcessHeap(), 0, cif
);
910 /* sif will be freed when the last call is completed, so be careful not to
911 * touch that memory here as that could happen before we get here */
912 WaitForSingleObject(event
, INFINITE
);
919 /***********************************************************************
920 * RpcServerUnregisterIfEx (RPCRT4.@)
922 RPC_STATUS WINAPI
RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, int RundownContextHandles
)
924 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
925 IfSpec
, debugstr_guid(MgrTypeUuid
), RundownContextHandles
);
930 /***********************************************************************
931 * RpcObjectSetType (RPCRT4.@)
934 * ObjUuid [I] "Object" UUID
935 * TypeUuid [I] "Type" UUID
938 * RPC_S_OK The call succeeded
939 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
940 * RPC_S_ALREADY_REGISTERED The provided object is already registered
942 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
943 * resets the mapping for the specified object UUID to nil (the default).
944 * The nil object is always associated with the nil type and cannot be
945 * reassigned. Servers can support multiple implementations on the same
946 * interface by registering different end-point vectors for the different
947 * types. There's no need to call this if a server only supports the nil
948 * type, as is typical.
950 RPC_STATUS WINAPI
RpcObjectSetType( UUID
* ObjUuid
, UUID
* TypeUuid
)
952 RpcObjTypeMap
*map
= RpcObjTypeMaps
, *prev
= NULL
;
955 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid
), debugstr_guid(TypeUuid
));
956 if ((! ObjUuid
) || UuidIsNil(ObjUuid
, &dummy
)) {
957 /* nil uuid cannot be remapped */
958 return RPC_S_INVALID_OBJECT
;
961 /* find the mapping for this object if there is one ... */
963 if (! UuidCompare(ObjUuid
, &map
->Object
, &dummy
)) break;
967 if ((! TypeUuid
) || UuidIsNil(TypeUuid
, &dummy
)) {
968 /* ... and drop it from the list */
971 prev
->next
= map
->next
;
973 RpcObjTypeMaps
= map
->next
;
974 HeapFree(GetProcessHeap(), 0, map
);
977 /* ... , fail if we found it ... */
979 return RPC_S_ALREADY_REGISTERED
;
980 /* ... otherwise create a new one and add it in. */
981 map
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap
));
982 map
->Object
= *ObjUuid
;
983 map
->Type
= *TypeUuid
;
986 prev
->next
= map
; /* prev is the last map in the linklist */
988 RpcObjTypeMaps
= map
;
994 /***********************************************************************
995 * RpcServerRegisterAuthInfoA (RPCRT4.@)
997 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoA( RPC_CSTR ServerPrincName
, ULONG AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
1000 FIXME( "(%s,%u,%p,%p): stub\n", ServerPrincName
, AuthnSvc
, GetKeyFn
, Arg
);
1002 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
1005 /***********************************************************************
1006 * RpcServerRegisterAuthInfoW (RPCRT4.@)
1008 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoW( RPC_WSTR ServerPrincName
, ULONG AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
1011 FIXME( "(%s,%u,%p,%p): stub\n", debugstr_w( ServerPrincName
), AuthnSvc
, GetKeyFn
, Arg
);
1013 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
1016 /***********************************************************************
1017 * RpcServerListen (RPCRT4.@)
1019 RPC_STATUS WINAPI
RpcServerListen( UINT MinimumCallThreads
, UINT MaxCalls
, UINT DontWait
)
1021 RPC_STATUS status
= RPC_S_OK
;
1023 TRACE("(%u,%u,%u)\n", MinimumCallThreads
, MaxCalls
, DontWait
);
1025 if (list_empty(&protseqs
))
1026 return RPC_S_NO_PROTSEQS_REGISTERED
;
1028 status
= RPCRT4_start_listen(FALSE
);
1030 if (DontWait
|| (status
!= RPC_S_OK
)) return status
;
1032 return RpcMgmtWaitServerListen();
1035 /***********************************************************************
1036 * RpcMgmtServerWaitListen (RPCRT4.@)
1038 RPC_STATUS WINAPI
RpcMgmtWaitServerListen( void )
1042 EnterCriticalSection(&listen_cs
);
1045 LeaveCriticalSection(&listen_cs
);
1046 return RPC_S_NOT_LISTENING
;
1049 LeaveCriticalSection(&listen_cs
);
1051 FIXME("not waiting for server calls to finish\n");
1056 /***********************************************************************
1057 * RpcMgmtStopServerListening (RPCRT4.@)
1059 RPC_STATUS WINAPI
RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding
)
1061 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding
);
1064 FIXME("client-side invocation not implemented.\n");
1065 return RPC_S_WRONG_KIND_OF_BINDING
;
1068 RPCRT4_stop_listen(FALSE
);
1073 /***********************************************************************
1074 * RpcMgmtEnableIdleCleanup (RPCRT4.@)
1076 RPC_STATUS WINAPI
RpcMgmtEnableIdleCleanup(void)
1078 FIXME("(): stub\n");
1082 /***********************************************************************
1083 * I_RpcServerStartListening (RPCRT4.@)
1085 RPC_STATUS WINAPI
I_RpcServerStartListening( HWND hWnd
)
1087 FIXME( "(%p): stub\n", hWnd
);
1092 /***********************************************************************
1093 * I_RpcServerStopListening (RPCRT4.@)
1095 RPC_STATUS WINAPI
I_RpcServerStopListening( void )
1097 FIXME( "(): stub\n" );
1102 /***********************************************************************
1103 * I_RpcWindowProc (RPCRT4.@)
1105 UINT WINAPI
I_RpcWindowProc( void *hWnd
, UINT Message
, UINT wParam
, ULONG lParam
)
1107 FIXME( "(%p,%08x,%08x,%08x): stub\n", hWnd
, Message
, wParam
, lParam
);
1112 /***********************************************************************
1113 * RpcMgmtInqIfIds (RPCRT4.@)
1115 RPC_STATUS WINAPI
RpcMgmtInqIfIds(RPC_BINDING_HANDLE Binding
, RPC_IF_ID_VECTOR
**IfIdVector
)
1117 FIXME("(%p,%p): stub\n", Binding
, IfIdVector
);
1118 return RPC_S_INVALID_BINDING
;
1121 /***********************************************************************
1122 * RpcMgmtEpEltInqBegin (RPCRT4.@)
1124 RPC_STATUS WINAPI
RpcMgmtEpEltInqBegin(RPC_BINDING_HANDLE Binding
, ULONG InquiryType
,
1125 RPC_IF_ID
*IfId
, ULONG VersOption
, UUID
*ObjectUuid
, RPC_EP_INQ_HANDLE
* InquiryContext
)
1127 FIXME("(%p,%u,%p,%u,%p,%p): stub\n",
1128 Binding
, InquiryType
, IfId
, VersOption
, ObjectUuid
, InquiryContext
);
1129 return RPC_S_INVALID_BINDING
;
1132 /***********************************************************************
1133 * RpcMgmtIsServerListening (RPCRT4.@)
1135 RPC_STATUS WINAPI
RpcMgmtIsServerListening(RPC_BINDING_HANDLE Binding
)
1137 FIXME("(%p): stub\n", Binding
);
1138 return RPC_S_INVALID_BINDING
;
1141 /***********************************************************************
1142 * RpcMgmtSetServerStackSize (RPCRT4.@)
1144 RPC_STATUS WINAPI
RpcMgmtSetServerStackSize(ULONG ThreadStackSize
)
1146 FIXME("(0x%x): stub\n", ThreadStackSize
);
1150 /***********************************************************************
1151 * I_RpcGetCurrentCallHandle (RPCRT4.@)
1153 RPC_BINDING_HANDLE WINAPI
I_RpcGetCurrentCallHandle(void)
1156 return RPCRT4_GetThreadCurrentCallHandle();