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;
55 unsigned char *auth_data;
59 typedef struct _RpcObjTypeMap
61 /* FIXME: a hash table would be better. */
62 struct _RpcObjTypeMap *next;
67 static RpcObjTypeMap *RpcObjTypeMaps;
69 /* list of type RpcServerProtseq */
70 static struct list protseqs = LIST_INIT(protseqs);
71 static struct list server_interfaces = LIST_INIT(server_interfaces);
72 static struct list server_registered_auth_info = LIST_INIT(server_registered_auth_info);
74 static CRITICAL_SECTION server_cs;
75 static CRITICAL_SECTION_DEBUG server_cs_debug =
78 { &server_cs_debug.ProcessLocksList, &server_cs_debug.ProcessLocksList },
79 0, 0, { (DWORD_PTR)(__FILE__ ": server_cs") }
81 static CRITICAL_SECTION server_cs = { &server_cs_debug, -1, 0, 0, 0, 0 };
83 static CRITICAL_SECTION listen_cs;
84 static CRITICAL_SECTION_DEBUG listen_cs_debug =
87 { &listen_cs_debug.ProcessLocksList, &listen_cs_debug.ProcessLocksList },
88 0, 0, { (DWORD_PTR)(__FILE__ ": listen_cs") }
90 static CRITICAL_SECTION listen_cs = { &listen_cs_debug, -1, 0, 0, 0, 0 };
92 static CRITICAL_SECTION server_auth_info_cs;
93 static CRITICAL_SECTION_DEBUG server_auth_info_cs_debug =
95 0, 0, &server_auth_info_cs,
96 { &server_auth_info_cs_debug.ProcessLocksList, &server_auth_info_cs_debug.ProcessLocksList },
97 0, 0, { (DWORD_PTR)(__FILE__ ": server_auth_info_cs") }
99 static CRITICAL_SECTION server_auth_info_cs = { &server_auth_info_cs_debug, -1, 0, 0, 0, 0 };
101 /* whether the server is currently listening */
102 static BOOL std_listen;
103 /* number of manual listeners (calls to RpcServerListen) */
104 static LONG manual_listen_count;
105 /* total listeners including auto listeners */
106 static LONG listen_count;
108 static UUID uuid_nil;
110 static inline RpcObjTypeMap *LookupObjTypeMap(UUID *ObjUuid)
112 RpcObjTypeMap *rslt = RpcObjTypeMaps;
116 if (! UuidCompare(ObjUuid, &rslt->Object, &dummy)) break;
123 static inline UUID *LookupObjType(UUID *ObjUuid)
125 RpcObjTypeMap *map = LookupObjTypeMap(ObjUuid);
132 static RpcServerInterface* RPCRT4_find_interface(UUID* object,
133 const RPC_SYNTAX_IDENTIFIER *if_id,
134 const RPC_SYNTAX_IDENTIFIER *transfer_syntax,
137 UUID* MgrType = NULL;
138 RpcServerInterface* cif;
142 MgrType = LookupObjType(object);
143 EnterCriticalSection(&server_cs);
144 LIST_FOR_EACH_ENTRY(cif, &server_interfaces, RpcServerInterface, entry) {
145 if (!memcmp(if_id, &cif->If->InterfaceId, sizeof(RPC_SYNTAX_IDENTIFIER)) &&
146 (!transfer_syntax || !memcmp(transfer_syntax, &cif->If->TransferSyntax, sizeof(RPC_SYNTAX_IDENTIFIER))) &&
147 (check_object == FALSE || UuidEqual(MgrType, &cif->MgrTypeUuid, &status)) &&
149 InterlockedIncrement(&cif->CurrentCalls);
153 LeaveCriticalSection(&server_cs);
154 if (&cif->entry == &server_interfaces) cif = NULL;
155 TRACE("returning %p for object %s, if_id { %d.%d %s }\n", cif,
156 debugstr_guid(object), if_id->SyntaxVersion.MajorVersion,
157 if_id->SyntaxVersion.MinorVersion, debugstr_guid(&if_id->SyntaxGUID));
161 static void RPCRT4_release_server_interface(RpcServerInterface *sif)
163 if (!InterlockedDecrement(&sif->CurrentCalls) &&
165 /* sif must have been removed from server_interfaces before
166 * CallsCompletedEvent is set */
167 if (sif->CallsCompletedEvent)
168 SetEvent(sif->CallsCompletedEvent);
169 HeapFree(GetProcessHeap(), 0, sif);
173 static RpcPktHdr *handle_bind_error(RpcConnection *conn, RPC_STATUS error)
175 unsigned int reject_reason;
178 case RPC_S_SERVER_TOO_BUSY:
179 reject_reason = REJECT_TEMPORARY_CONGESTION;
181 case ERROR_OUTOFMEMORY:
182 case RPC_S_OUT_OF_RESOURCES:
183 reject_reason = REJECT_LOCAL_LIMIT_EXCEEDED;
185 case RPC_S_PROTOCOL_ERROR:
186 reject_reason = REJECT_PROTOCOL_VERSION_NOT_SUPPORTED;
188 case RPC_S_UNKNOWN_AUTHN_SERVICE:
189 reject_reason = REJECT_UNKNOWN_AUTHN_SERVICE;
191 case ERROR_ACCESS_DENIED:
192 reject_reason = REJECT_INVALID_CHECKSUM;
195 FIXME("unexpected status value %d\n", error);
197 case RPC_S_INVALID_BOUND:
198 reject_reason = REJECT_REASON_NOT_SPECIFIED;
201 return RPCRT4_BuildBindNackHeader(NDR_LOCAL_DATA_REPRESENTATION,
202 RPC_VER_MAJOR, RPC_VER_MINOR,
206 static RPC_STATUS process_bind_packet_no_send(
207 RpcConnection *conn, RpcPktBindHdr *hdr, RPC_MESSAGE *msg,
208 unsigned char *auth_data, ULONG auth_length, RpcPktHdr **ack_response,
209 unsigned char **auth_data_out, ULONG *auth_length_out)
212 RpcContextElement *ctxt_elem;
217 for (i = 0, ctxt_elem = msg->Buffer;
218 i < hdr->num_elements;
219 i++, ctxt_elem = (RpcContextElement *)&ctxt_elem->transfer_syntaxes[ctxt_elem->num_syntaxes])
221 if (((char *)ctxt_elem - (char *)msg->Buffer) > msg->BufferLength ||
222 ((char *)&ctxt_elem->transfer_syntaxes[ctxt_elem->num_syntaxes] - (char *)msg->Buffer) > msg->BufferLength)
224 ERR("inconsistent data in packet - packet length %d, num elements %d\n",
225 msg->BufferLength, hdr->num_elements);
226 return RPC_S_INVALID_BOUND;
230 if (hdr->max_tsize < RPC_MIN_PACKET_SIZE ||
231 !UuidIsNil(&conn->ActiveInterface.SyntaxGUID, &status) ||
232 conn->server_binding)
234 TRACE("packet size less than min size, or active interface syntax guid non-null\n");
236 return RPC_S_INVALID_BOUND;
239 results = HeapAlloc(GetProcessHeap(), 0,
240 hdr->num_elements * sizeof(*results));
242 return RPC_S_OUT_OF_RESOURCES;
244 for (i = 0, ctxt_elem = (RpcContextElement *)msg->Buffer;
245 i < hdr->num_elements;
246 i++, ctxt_elem = (RpcContextElement *)&ctxt_elem->transfer_syntaxes[ctxt_elem->num_syntaxes])
248 RpcServerInterface* sif = NULL;
251 for (j = 0; !sif && j < ctxt_elem->num_syntaxes; j++)
253 sif = RPCRT4_find_interface(NULL, &ctxt_elem->abstract_syntax,
254 &ctxt_elem->transfer_syntaxes[j], FALSE);
260 RPCRT4_release_server_interface(sif);
261 TRACE("accepting bind request on connection %p for %s\n", conn,
262 debugstr_guid(&ctxt_elem->abstract_syntax.SyntaxGUID));
263 results[i].result = RESULT_ACCEPT;
264 results[i].reason = REASON_NONE;
265 results[i].transfer_syntax = ctxt_elem->transfer_syntaxes[j];
267 /* save the interface for later use */
268 /* FIXME: save linked list */
269 conn->ActiveInterface = ctxt_elem->abstract_syntax;
271 else if ((sif = RPCRT4_find_interface(NULL, &ctxt_elem->abstract_syntax,
272 NULL, FALSE)) != NULL)
274 RPCRT4_release_server_interface(sif);
275 TRACE("not accepting bind request on connection %p for %s - no transfer syntaxes supported\n",
276 conn, debugstr_guid(&ctxt_elem->abstract_syntax.SyntaxGUID));
277 results[i].result = RESULT_PROVIDER_REJECTION;
278 results[i].reason = REASON_TRANSFER_SYNTAXES_NOT_SUPPORTED;
279 memset(&results[i].transfer_syntax, 0, sizeof(results[i].transfer_syntax));
283 TRACE("not accepting bind request on connection %p for %s - abstract syntax not supported\n",
284 conn, debugstr_guid(&ctxt_elem->abstract_syntax.SyntaxGUID));
285 results[i].result = RESULT_PROVIDER_REJECTION;
286 results[i].reason = REASON_ABSTRACT_SYNTAX_NOT_SUPPORTED;
287 memset(&results[i].transfer_syntax, 0, sizeof(results[i].transfer_syntax));
291 /* create temporary binding */
292 status = RPCRT4_MakeBinding(&conn->server_binding, conn);
293 if (status != RPC_S_OK)
295 HeapFree(GetProcessHeap(), 0, results);
299 status = RpcServerAssoc_GetAssociation(rpcrt4_conn_get_name(conn),
300 conn->NetworkAddr, conn->Endpoint,
301 conn->NetworkOptions,
303 &conn->server_binding->Assoc);
304 if (status != RPC_S_OK)
306 HeapFree(GetProcessHeap(), 0, results);
312 status = RPCRT4_ServerConnectionAuth(conn, TRUE,
313 (RpcAuthVerifier *)auth_data,
314 auth_length, auth_data_out,
316 if (status != RPC_S_OK)
318 HeapFree(GetProcessHeap(), 0, results);
323 *ack_response = RPCRT4_BuildBindAckHeader(NDR_LOCAL_DATA_REPRESENTATION,
326 conn->server_binding->Assoc->assoc_group_id,
327 conn->Endpoint, hdr->num_elements,
329 HeapFree(GetProcessHeap(), 0, results);
332 conn->MaxTransmissionSize = hdr->max_tsize;
334 status = RPC_S_OUT_OF_RESOURCES;
339 static RPC_STATUS process_bind_packet(RpcConnection *conn, RpcPktBindHdr *hdr,
341 unsigned char *auth_data,
345 RpcPktHdr *response = NULL;
346 unsigned char *auth_data_out = NULL;
347 ULONG auth_length_out = 0;
349 status = process_bind_packet_no_send(conn, hdr, msg, auth_data, auth_length,
350 &response, &auth_data_out,
352 if (status != RPC_S_OK)
353 response = handle_bind_error(conn, status);
355 status = RPCRT4_SendWithAuth(conn, response, NULL, 0, auth_data_out, auth_length_out);
357 status = ERROR_OUTOFMEMORY;
358 RPCRT4_FreeHeader(response);
364 static RPC_STATUS process_request_packet(RpcConnection *conn, RpcPktRequestHdr *hdr, RPC_MESSAGE *msg)
367 RpcPktHdr *response = NULL;
368 RpcServerInterface* sif;
369 RPC_DISPATCH_FUNCTION func;
372 NDR_SCONTEXT context_handle;
373 void *buf = msg->Buffer;
375 /* fail if the connection isn't bound with an interface */
376 if (UuidIsNil(&conn->ActiveInterface.SyntaxGUID, &status)) {
377 /* FIXME: should send BindNack instead */
378 response = RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION,
381 RPCRT4_Send(conn, response, NULL, 0);
382 RPCRT4_FreeHeader(response);
386 if (hdr->common.flags & RPC_FLG_OBJECT_UUID) {
387 object_uuid = (UUID*)(hdr + 1);
392 sif = RPCRT4_find_interface(object_uuid, &conn->ActiveInterface, NULL, TRUE);
394 WARN("interface %s no longer registered, returning fault packet\n", debugstr_guid(&conn->ActiveInterface.SyntaxGUID));
395 response = RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION,
398 RPCRT4_Send(conn, response, NULL, 0);
399 RPCRT4_FreeHeader(response);
402 msg->RpcInterfaceInformation = sif->If;
403 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
404 msg->ManagerEpv = sif->MgrEpv;
405 if (object_uuid != NULL) {
406 RPCRT4_SetBindingObject(msg->Handle, object_uuid);
409 /* find dispatch function */
410 msg->ProcNum = hdr->opnum;
411 if (sif->Flags & RPC_IF_OLE) {
412 /* native ole32 always gives us a dispatch table with a single entry
413 * (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
414 func = *sif->If->DispatchTable->DispatchTable;
416 if (msg->ProcNum >= sif->If->DispatchTable->DispatchTableCount) {
417 WARN("invalid procnum (%d/%d)\n", msg->ProcNum, sif->If->DispatchTable->DispatchTableCount);
418 response = RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION,
421 RPCRT4_Send(conn, response, NULL, 0);
422 RPCRT4_FreeHeader(response);
424 func = sif->If->DispatchTable->DispatchTable[msg->ProcNum];
427 /* put in the drep. FIXME: is this more universally applicable?
428 perhaps we should move this outward... */
429 msg->DataRepresentation =
430 MAKELONG( MAKEWORD(hdr->common.drep[0], hdr->common.drep[1]),
431 MAKEWORD(hdr->common.drep[2], hdr->common.drep[3]));
436 RPCRT4_SetThreadCurrentCallHandle(msg->Handle);
440 WARN("exception caught with code 0x%08x = %d\n", GetExceptionCode(), GetExceptionCode());
442 if (GetExceptionCode() == STATUS_ACCESS_VIOLATION)
443 status = ERROR_NOACCESS;
445 status = GetExceptionCode();
446 response = RPCRT4_BuildFaultHeader(msg->DataRepresentation,
447 RPC2NCA_STATUS(status));
449 RPCRT4_SetThreadCurrentCallHandle(NULL);
451 /* release any unmarshalled context handles */
452 while ((context_handle = RPCRT4_PopThreadContextHandle()) != NULL)
453 RpcServerAssoc_ReleaseContextHandle(conn->server_binding->Assoc, context_handle, TRUE);
456 response = RPCRT4_BuildResponseHeader(msg->DataRepresentation,
459 /* send response packet */
461 status = RPCRT4_Send(conn, response, exception ? NULL : msg->Buffer,
462 exception ? 0 : msg->BufferLength);
463 RPCRT4_FreeHeader(response);
465 ERR("out of memory\n");
467 msg->RpcInterfaceInformation = NULL;
468 RPCRT4_release_server_interface(sif);
470 if (msg->Buffer == buf) buf = NULL;
471 TRACE("freeing Buffer=%p\n", buf);
477 static RPC_STATUS process_auth3_packet(RpcConnection *conn,
478 RpcPktCommonHdr *hdr,
480 unsigned char *auth_data,
485 if (UuidIsNil(&conn->ActiveInterface.SyntaxGUID, &status) ||
486 !auth_length || msg->BufferLength != 0)
487 status = RPC_S_PROTOCOL_ERROR;
490 status = RPCRT4_ServerConnectionAuth(conn, FALSE,
491 (RpcAuthVerifier *)auth_data,
492 auth_length, NULL, NULL);
495 /* FIXME: client doesn't expect a response to this message so must store
496 * status in connection so that fault packet can be returned when next
497 * packet is received */
502 static void RPCRT4_process_packet(RpcConnection* conn, RpcPktHdr* hdr,
503 RPC_MESSAGE* msg, unsigned char *auth_data,
506 msg->Handle = (RPC_BINDING_HANDLE)conn->server_binding;
508 switch (hdr->common.ptype) {
510 TRACE("got bind packet\n");
511 process_bind_packet(conn, &hdr->bind, msg, auth_data, auth_length);
515 TRACE("got request packet\n");
516 process_request_packet(conn, &hdr->request, msg);
520 TRACE("got auth3 packet\n");
521 process_auth3_packet(conn, &hdr->common, msg, auth_data, auth_length);
524 FIXME("unhandled packet type %u\n", hdr->common.ptype);
529 I_RpcFree(msg->Buffer);
530 RPCRT4_FreeHeader(hdr);
531 HeapFree(GetProcessHeap(), 0, msg);
532 HeapFree(GetProcessHeap(), 0, auth_data);
535 static DWORD CALLBACK RPCRT4_worker_thread(LPVOID the_arg)
537 RpcPacket *pkt = the_arg;
538 RPCRT4_process_packet(pkt->conn, pkt->hdr, pkt->msg, pkt->auth_data,
540 HeapFree(GetProcessHeap(), 0, pkt);
544 static DWORD CALLBACK RPCRT4_io_thread(LPVOID the_arg)
546 RpcConnection* conn = the_arg;
551 unsigned char *auth_data;
554 TRACE("(%p)\n", conn);
557 msg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RPC_MESSAGE));
560 status = RPCRT4_ReceiveWithAuth(conn, &hdr, msg, &auth_data, &auth_length);
561 if (status != RPC_S_OK) {
562 WARN("receive failed with error %x\n", status);
563 HeapFree(GetProcessHeap(), 0, msg);
567 switch (hdr->common.ptype) {
569 TRACE("got bind packet\n");
571 status = process_bind_packet(conn, &hdr->bind, msg, auth_data,
576 TRACE("got request packet\n");
578 packet = HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket));
580 I_RpcFree(msg->Buffer);
581 RPCRT4_FreeHeader(hdr);
582 HeapFree(GetProcessHeap(), 0, msg);
583 HeapFree(GetProcessHeap(), 0, auth_data);
589 packet->auth_data = auth_data;
590 packet->auth_length = auth_length;
591 if (!QueueUserWorkItem(RPCRT4_worker_thread, packet, WT_EXECUTELONGFUNCTION)) {
592 ERR("couldn't queue work item for worker thread, error was %d\n", GetLastError());
593 HeapFree(GetProcessHeap(), 0, packet);
594 status = RPC_S_OUT_OF_RESOURCES;
601 TRACE("got auth3 packet\n");
603 status = process_auth3_packet(conn, &hdr->common, msg, auth_data,
607 FIXME("unhandled packet type %u\n", hdr->common.ptype);
611 I_RpcFree(msg->Buffer);
612 RPCRT4_FreeHeader(hdr);
613 HeapFree(GetProcessHeap(), 0, msg);
614 HeapFree(GetProcessHeap(), 0, auth_data);
616 if (status != RPC_S_OK) {
617 WARN("processing packet failed with error %u\n", status);
622 RPCRT4_DestroyConnection(conn);
626 void RPCRT4_new_client(RpcConnection* conn)
628 HANDLE thread = CreateThread(NULL, 0, RPCRT4_io_thread, conn, 0, NULL);
630 DWORD err = GetLastError();
631 ERR("failed to create thread, error=%08x\n", err);
632 RPCRT4_DestroyConnection(conn);
634 /* we could set conn->thread, but then we'd have to make the io_thread wait
635 * for that, otherwise the thread might finish, destroy the connection, and
636 * free the memory we'd write to before we did, causing crashes and stuff -
637 * so let's implement that later, when we really need conn->thread */
639 CloseHandle( thread );
642 static DWORD CALLBACK RPCRT4_server_thread(LPVOID the_arg)
647 RpcServerProtseq* cps = the_arg;
649 BOOL set_ready_event = FALSE;
651 TRACE("(the_arg == ^%p)\n", the_arg);
654 objs = cps->ops->get_wait_array(cps, objs, &count);
658 /* signal to function that changed state that we are now sync'ed */
659 SetEvent(cps->server_ready_event);
660 set_ready_event = FALSE;
664 res = cps->ops->wait_for_new_connection(cps, count, objs);
666 if (res == -1 || (res == 0 && !std_listen))
669 cps->ops->free_wait_array(cps, objs);
670 EnterCriticalSection(&cps->cs);
671 for (conn = cps->conn; conn; conn = conn->Next)
672 RPCRT4_CloseConnection(conn);
673 LeaveCriticalSection(&cps->cs);
675 if (res == 0 && !std_listen)
676 SetEvent(cps->server_ready_event);
680 set_ready_event = TRUE;
685 /* tells the server thread that the state has changed and waits for it to
686 * make the changes */
687 static void RPCRT4_sync_with_server_thread(RpcServerProtseq *ps)
689 /* make sure we are the only thread sync'ing the server state, otherwise
690 * there is a race with the server thread setting an older state and setting
691 * the server_ready_event when the new state hasn't yet been applied */
692 WaitForSingleObject(ps->mgr_mutex, INFINITE);
694 ps->ops->signal_state_changed(ps);
696 /* wait for server thread to make the requested changes before returning */
697 WaitForSingleObject(ps->server_ready_event, INFINITE);
699 ReleaseMutex(ps->mgr_mutex);
702 static RPC_STATUS RPCRT4_start_listen_protseq(RpcServerProtseq *ps, BOOL auto_listen)
704 RPC_STATUS status = RPC_S_OK;
705 HANDLE server_thread;
707 EnterCriticalSection(&listen_cs);
708 if (ps->is_listening) goto done;
710 if (!ps->mgr_mutex) ps->mgr_mutex = CreateMutexW(NULL, FALSE, NULL);
711 if (!ps->server_ready_event) ps->server_ready_event = CreateEventW(NULL, FALSE, FALSE, NULL);
712 server_thread = CreateThread(NULL, 0, RPCRT4_server_thread, ps, 0, NULL);
715 status = RPC_S_OUT_OF_RESOURCES;
718 ps->is_listening = TRUE;
719 CloseHandle(server_thread);
722 LeaveCriticalSection(&listen_cs);
726 static RPC_STATUS RPCRT4_start_listen(BOOL auto_listen)
728 RPC_STATUS status = RPC_S_ALREADY_LISTENING;
729 RpcServerProtseq *cps;
733 EnterCriticalSection(&listen_cs);
734 if (auto_listen || (manual_listen_count++ == 0))
737 if (++listen_count == 1)
740 LeaveCriticalSection(&listen_cs);
744 EnterCriticalSection(&server_cs);
745 LIST_FOR_EACH_ENTRY(cps, &protseqs, RpcServerProtseq, entry)
747 status = RPCRT4_start_listen_protseq(cps, TRUE);
748 if (status != RPC_S_OK)
751 /* make sure server is actually listening on the interface before
753 RPCRT4_sync_with_server_thread(cps);
755 LeaveCriticalSection(&server_cs);
761 static void RPCRT4_stop_listen(BOOL auto_listen)
763 EnterCriticalSection(&listen_cs);
764 if (auto_listen || (--manual_listen_count == 0))
766 if (listen_count != 0 && --listen_count == 0) {
767 RpcServerProtseq *cps;
770 LeaveCriticalSection(&listen_cs);
772 LIST_FOR_EACH_ENTRY(cps, &protseqs, RpcServerProtseq, entry)
773 RPCRT4_sync_with_server_thread(cps);
777 assert(listen_count >= 0);
779 LeaveCriticalSection(&listen_cs);
782 static BOOL RPCRT4_protseq_is_endpoint_registered(RpcServerProtseq *protseq, const char *endpoint)
785 EnterCriticalSection(&protseq->cs);
786 for (conn = protseq->conn; conn; conn = conn->Next)
788 if (!endpoint || !strcmp(endpoint, conn->Endpoint))
791 LeaveCriticalSection(&protseq->cs);
792 return (conn != NULL);
795 static RPC_STATUS RPCRT4_use_protseq(RpcServerProtseq* ps, const char *endpoint)
799 EnterCriticalSection(&ps->cs);
801 if (RPCRT4_protseq_is_endpoint_registered(ps, endpoint))
804 status = ps->ops->open_endpoint(ps, endpoint);
806 LeaveCriticalSection(&ps->cs);
808 if (status != RPC_S_OK)
813 status = RPCRT4_start_listen_protseq(ps, FALSE);
814 if (status == RPC_S_OK)
815 RPCRT4_sync_with_server_thread(ps);
821 /***********************************************************************
822 * RpcServerInqBindings (RPCRT4.@)
824 RPC_STATUS WINAPI RpcServerInqBindings( RPC_BINDING_VECTOR** BindingVector )
828 RpcServerProtseq* ps;
832 TRACE("(*BindingVector == ^%p)\n", *BindingVector);
834 ERR("(BindingVector == NULL!!?)\n");
836 EnterCriticalSection(&server_cs);
837 /* count connections */
839 LIST_FOR_EACH_ENTRY(ps, &protseqs, RpcServerProtseq, entry) {
840 EnterCriticalSection(&ps->cs);
841 for (conn = ps->conn; conn; conn = conn->Next)
843 LeaveCriticalSection(&ps->cs);
846 /* export bindings */
847 *BindingVector = HeapAlloc(GetProcessHeap(), 0,
848 sizeof(RPC_BINDING_VECTOR) +
849 sizeof(RPC_BINDING_HANDLE)*(count-1));
850 (*BindingVector)->Count = count;
852 LIST_FOR_EACH_ENTRY(ps, &protseqs, RpcServerProtseq, entry) {
853 EnterCriticalSection(&ps->cs);
854 for (conn = ps->conn; conn; conn = conn->Next) {
855 RPCRT4_MakeBinding((RpcBinding**)&(*BindingVector)->BindingH[count],
859 LeaveCriticalSection(&ps->cs);
863 *BindingVector = NULL;
864 status = RPC_S_NO_BINDINGS;
866 LeaveCriticalSection(&server_cs);
870 /***********************************************************************
871 * RpcServerUseProtseqEpA (RPCRT4.@)
873 RPC_STATUS WINAPI RpcServerUseProtseqEpA( RPC_CSTR Protseq, UINT MaxCalls, RPC_CSTR Endpoint, LPVOID SecurityDescriptor )
877 TRACE( "(%s,%u,%s,%p)\n", Protseq, MaxCalls, Endpoint, SecurityDescriptor );
879 /* This should provide the default behaviour */
880 policy.Length = sizeof( policy );
881 policy.EndpointFlags = 0;
884 return RpcServerUseProtseqEpExA( Protseq, MaxCalls, Endpoint, SecurityDescriptor, &policy );
887 /***********************************************************************
888 * RpcServerUseProtseqEpW (RPCRT4.@)
890 RPC_STATUS WINAPI RpcServerUseProtseqEpW( RPC_WSTR Protseq, UINT MaxCalls, RPC_WSTR Endpoint, LPVOID SecurityDescriptor )
894 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq ), MaxCalls, debugstr_w( Endpoint ), SecurityDescriptor );
896 /* This should provide the default behaviour */
897 policy.Length = sizeof( policy );
898 policy.EndpointFlags = 0;
901 return RpcServerUseProtseqEpExW( Protseq, MaxCalls, Endpoint, SecurityDescriptor, &policy );
904 /***********************************************************************
905 * alloc_serverprotoseq (internal)
907 * Must be called with server_cs held.
909 static RPC_STATUS alloc_serverprotoseq(UINT MaxCalls, const char *Protseq, RpcServerProtseq **ps)
911 const struct protseq_ops *ops = rpcrt4_get_protseq_ops(Protseq);
915 FIXME("protseq %s not supported\n", debugstr_a(Protseq));
916 return RPC_S_PROTSEQ_NOT_SUPPORTED;
921 return RPC_S_OUT_OF_RESOURCES;
922 (*ps)->MaxCalls = MaxCalls;
923 (*ps)->Protseq = RPCRT4_strdupA(Protseq);
927 InitializeCriticalSection(&(*ps)->cs);
928 (*ps)->is_listening = FALSE;
929 (*ps)->mgr_mutex = NULL;
930 (*ps)->server_ready_event = NULL;
932 list_add_head(&protseqs, &(*ps)->entry);
934 TRACE("new protseq %p created for %s\n", *ps, Protseq);
939 /* must be called with server_cs held */
940 static void destroy_serverprotoseq(RpcServerProtseq *ps)
942 RPCRT4_strfree(ps->Protseq);
943 DeleteCriticalSection(&ps->cs);
944 CloseHandle(ps->mgr_mutex);
945 CloseHandle(ps->server_ready_event);
946 list_remove(&ps->entry);
947 HeapFree(GetProcessHeap(), 0, ps);
950 /* Finds a given protseq or creates a new one if one doesn't already exist */
951 static RPC_STATUS RPCRT4_get_or_create_serverprotseq(UINT MaxCalls, const char *Protseq, RpcServerProtseq **ps)
954 RpcServerProtseq *cps;
956 EnterCriticalSection(&server_cs);
958 LIST_FOR_EACH_ENTRY(cps, &protseqs, RpcServerProtseq, entry)
959 if (!strcmp(cps->Protseq, Protseq))
961 TRACE("found existing protseq object for %s\n", Protseq);
963 LeaveCriticalSection(&server_cs);
967 status = alloc_serverprotoseq(MaxCalls, Protseq, ps);
969 LeaveCriticalSection(&server_cs);
974 /***********************************************************************
975 * RpcServerUseProtseqEpExA (RPCRT4.@)
977 RPC_STATUS WINAPI RpcServerUseProtseqEpExA( RPC_CSTR Protseq, UINT MaxCalls, RPC_CSTR Endpoint, LPVOID SecurityDescriptor,
978 PRPC_POLICY lpPolicy )
980 RpcServerProtseq* ps;
983 TRACE("(%s,%u,%s,%p,{%u,%u,%u})\n", debugstr_a((const char *)Protseq),
984 MaxCalls, debugstr_a((const char *)Endpoint), SecurityDescriptor,
985 lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
987 status = RPCRT4_get_or_create_serverprotseq(MaxCalls, (const char *)Protseq, &ps);
988 if (status != RPC_S_OK)
991 return RPCRT4_use_protseq(ps, (const char *)Endpoint);
994 /***********************************************************************
995 * RpcServerUseProtseqEpExW (RPCRT4.@)
997 RPC_STATUS WINAPI RpcServerUseProtseqEpExW( RPC_WSTR Protseq, UINT MaxCalls, RPC_WSTR Endpoint, LPVOID SecurityDescriptor,
998 PRPC_POLICY lpPolicy )
1000 RpcServerProtseq* ps;
1005 TRACE("(%s,%u,%s,%p,{%u,%u,%u})\n", debugstr_w( Protseq ), MaxCalls,
1006 debugstr_w( Endpoint ), SecurityDescriptor,
1007 lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
1009 ProtseqA = RPCRT4_strdupWtoA(Protseq);
1010 status = RPCRT4_get_or_create_serverprotseq(MaxCalls, ProtseqA, &ps);
1011 RPCRT4_strfree(ProtseqA);
1012 if (status != RPC_S_OK)
1015 EndpointA = RPCRT4_strdupWtoA(Endpoint);
1016 status = RPCRT4_use_protseq(ps, EndpointA);
1017 RPCRT4_strfree(EndpointA);
1021 /***********************************************************************
1022 * RpcServerUseProtseqA (RPCRT4.@)
1024 RPC_STATUS WINAPI RpcServerUseProtseqA(RPC_CSTR Protseq, unsigned int MaxCalls, void *SecurityDescriptor)
1027 RpcServerProtseq* ps;
1029 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a((char*)Protseq), MaxCalls, SecurityDescriptor);
1031 status = RPCRT4_get_or_create_serverprotseq(MaxCalls, (const char *)Protseq, &ps);
1032 if (status != RPC_S_OK)
1035 return RPCRT4_use_protseq(ps, NULL);
1038 /***********************************************************************
1039 * RpcServerUseProtseqW (RPCRT4.@)
1041 RPC_STATUS WINAPI RpcServerUseProtseqW(RPC_WSTR Protseq, unsigned int MaxCalls, void *SecurityDescriptor)
1044 RpcServerProtseq* ps;
1047 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_w(Protseq), MaxCalls, SecurityDescriptor);
1049 ProtseqA = RPCRT4_strdupWtoA(Protseq);
1050 status = RPCRT4_get_or_create_serverprotseq(MaxCalls, ProtseqA, &ps);
1051 RPCRT4_strfree(ProtseqA);
1052 if (status != RPC_S_OK)
1055 return RPCRT4_use_protseq(ps, NULL);
1058 void RPCRT4_destroy_all_protseqs(void)
1060 RpcServerProtseq *cps, *cursor2;
1062 if (listen_count != 0)
1065 EnterCriticalSection(&server_cs);
1066 LIST_FOR_EACH_ENTRY_SAFE(cps, cursor2, &protseqs, RpcServerProtseq, entry)
1068 if (listen_count != 0)
1069 RPCRT4_sync_with_server_thread(cps);
1070 destroy_serverprotoseq(cps);
1072 LeaveCriticalSection(&server_cs);
1075 /***********************************************************************
1076 * RpcServerRegisterIf (RPCRT4.@)
1078 RPC_STATUS WINAPI RpcServerRegisterIf( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv )
1080 TRACE("(%p,%s,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv);
1081 return RpcServerRegisterIf2( IfSpec, MgrTypeUuid, MgrEpv, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, (UINT)-1, NULL );
1084 /***********************************************************************
1085 * RpcServerRegisterIfEx (RPCRT4.@)
1087 RPC_STATUS WINAPI RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv,
1088 UINT Flags, UINT MaxCalls, RPC_IF_CALLBACK_FN* IfCallbackFn )
1090 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv, Flags, MaxCalls, IfCallbackFn);
1091 return RpcServerRegisterIf2( IfSpec, MgrTypeUuid, MgrEpv, Flags, MaxCalls, (UINT)-1, IfCallbackFn );
1094 /***********************************************************************
1095 * RpcServerRegisterIf2 (RPCRT4.@)
1097 RPC_STATUS WINAPI RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv,
1098 UINT Flags, UINT MaxCalls, UINT MaxRpcSize, RPC_IF_CALLBACK_FN* IfCallbackFn )
1100 PRPC_SERVER_INTERFACE If = IfSpec;
1101 RpcServerInterface* sif;
1104 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv, Flags, MaxCalls,
1105 MaxRpcSize, IfCallbackFn);
1106 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If->InterfaceId.SyntaxGUID),
1107 If->InterfaceId.SyntaxVersion.MajorVersion,
1108 If->InterfaceId.SyntaxVersion.MinorVersion);
1109 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If->TransferSyntax.SyntaxGUID),
1110 If->TransferSyntax.SyntaxVersion.MajorVersion,
1111 If->TransferSyntax.SyntaxVersion.MinorVersion);
1112 TRACE(" dispatch table: %p\n", If->DispatchTable);
1113 if (If->DispatchTable) {
1114 TRACE(" dispatch table count: %d\n", If->DispatchTable->DispatchTableCount);
1115 for (i=0; i<If->DispatchTable->DispatchTableCount; i++) {
1116 TRACE(" entry %d: %p\n", i, If->DispatchTable->DispatchTable[i]);
1118 TRACE(" reserved: %ld\n", If->DispatchTable->Reserved);
1120 TRACE(" protseq endpoint count: %d\n", If->RpcProtseqEndpointCount);
1121 TRACE(" default manager epv: %p\n", If->DefaultManagerEpv);
1122 TRACE(" interpreter info: %p\n", If->InterpreterInfo);
1124 sif = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcServerInterface));
1127 sif->MgrTypeUuid = *MgrTypeUuid;
1128 sif->MgrEpv = MgrEpv;
1130 memset(&sif->MgrTypeUuid, 0, sizeof(UUID));
1131 sif->MgrEpv = If->DefaultManagerEpv;
1134 sif->MaxCalls = MaxCalls;
1135 sif->MaxRpcSize = MaxRpcSize;
1136 sif->IfCallbackFn = IfCallbackFn;
1138 EnterCriticalSection(&server_cs);
1139 list_add_head(&server_interfaces, &sif->entry);
1140 LeaveCriticalSection(&server_cs);
1142 if (sif->Flags & RPC_IF_AUTOLISTEN)
1143 RPCRT4_start_listen(TRUE);
1148 /***********************************************************************
1149 * RpcServerUnregisterIf (RPCRT4.@)
1151 RPC_STATUS WINAPI RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, UINT WaitForCallsToComplete )
1153 PRPC_SERVER_INTERFACE If = IfSpec;
1154 HANDLE event = NULL;
1156 BOOL completed = TRUE;
1157 RpcServerInterface *cif;
1160 TRACE("(IfSpec == (RPC_IF_HANDLE)^%p (%s), MgrTypeUuid == %s, WaitForCallsToComplete == %u)\n",
1161 IfSpec, debugstr_guid(&If->InterfaceId.SyntaxGUID), debugstr_guid(MgrTypeUuid), WaitForCallsToComplete);
1163 EnterCriticalSection(&server_cs);
1164 LIST_FOR_EACH_ENTRY(cif, &server_interfaces, RpcServerInterface, entry) {
1165 if ((!IfSpec || !memcmp(&If->InterfaceId, &cif->If->InterfaceId, sizeof(RPC_SYNTAX_IDENTIFIER))) &&
1166 UuidEqual(MgrTypeUuid, &cif->MgrTypeUuid, &status)) {
1167 list_remove(&cif->entry);
1168 TRACE("unregistering cif %p\n", cif);
1169 if (cif->CurrentCalls) {
1172 if (WaitForCallsToComplete)
1173 cif->CallsCompletedEvent = event = CreateEventW(NULL, FALSE, FALSE, NULL);
1179 LeaveCriticalSection(&server_cs);
1182 ERR("not found for object %s\n", debugstr_guid(MgrTypeUuid));
1183 return RPC_S_UNKNOWN_IF;
1187 HeapFree(GetProcessHeap(), 0, cif);
1189 /* sif will be freed when the last call is completed, so be careful not to
1190 * touch that memory here as that could happen before we get here */
1191 WaitForSingleObject(event, INFINITE);
1198 /***********************************************************************
1199 * RpcServerUnregisterIfEx (RPCRT4.@)
1201 RPC_STATUS WINAPI RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, int RundownContextHandles )
1203 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
1204 IfSpec, debugstr_guid(MgrTypeUuid), RundownContextHandles);
1209 /***********************************************************************
1210 * RpcObjectSetType (RPCRT4.@)
1213 * ObjUuid [I] "Object" UUID
1214 * TypeUuid [I] "Type" UUID
1217 * RPC_S_OK The call succeeded
1218 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
1219 * RPC_S_ALREADY_REGISTERED The provided object is already registered
1221 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
1222 * resets the mapping for the specified object UUID to nil (the default).
1223 * The nil object is always associated with the nil type and cannot be
1224 * reassigned. Servers can support multiple implementations on the same
1225 * interface by registering different end-point vectors for the different
1226 * types. There's no need to call this if a server only supports the nil
1227 * type, as is typical.
1229 RPC_STATUS WINAPI RpcObjectSetType( UUID* ObjUuid, UUID* TypeUuid )
1231 RpcObjTypeMap *map = RpcObjTypeMaps, *prev = NULL;
1234 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid), debugstr_guid(TypeUuid));
1235 if ((! ObjUuid) || UuidIsNil(ObjUuid, &dummy)) {
1236 /* nil uuid cannot be remapped */
1237 return RPC_S_INVALID_OBJECT;
1240 /* find the mapping for this object if there is one ... */
1242 if (! UuidCompare(ObjUuid, &map->Object, &dummy)) break;
1246 if ((! TypeUuid) || UuidIsNil(TypeUuid, &dummy)) {
1247 /* ... and drop it from the list */
1250 prev->next = map->next;
1252 RpcObjTypeMaps = map->next;
1253 HeapFree(GetProcessHeap(), 0, map);
1256 /* ... , fail if we found it ... */
1258 return RPC_S_ALREADY_REGISTERED;
1259 /* ... otherwise create a new one and add it in. */
1260 map = HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap));
1261 map->Object = *ObjUuid;
1262 map->Type = *TypeUuid;
1265 prev->next = map; /* prev is the last map in the linklist */
1267 RpcObjTypeMaps = map;
1273 struct rpc_server_registered_auth_info
1282 RPC_STATUS RPCRT4_ServerGetRegisteredAuthInfo(
1283 USHORT auth_type, CredHandle *cred, TimeStamp *exp, ULONG *max_token)
1285 RPC_STATUS status = RPC_S_UNKNOWN_AUTHN_SERVICE;
1286 struct rpc_server_registered_auth_info *auth_info;
1288 EnterCriticalSection(&server_auth_info_cs);
1289 LIST_FOR_EACH_ENTRY(auth_info, &server_registered_auth_info, struct rpc_server_registered_auth_info, entry)
1291 if (auth_info->auth_type == auth_type)
1293 *cred = auth_info->cred;
1294 *exp = auth_info->exp;
1295 *max_token = auth_info->max_token;
1300 LeaveCriticalSection(&server_auth_info_cs);
1305 void RPCRT4_ServerFreeAllRegisteredAuthInfo(void)
1307 struct rpc_server_registered_auth_info *auth_info, *cursor2;
1309 EnterCriticalSection(&server_auth_info_cs);
1310 LIST_FOR_EACH_ENTRY_SAFE(auth_info, cursor2, &server_registered_auth_info, struct rpc_server_registered_auth_info, entry)
1312 FreeCredentialsHandle(&auth_info->cred);
1313 HeapFree(GetProcessHeap(), 0, auth_info);
1315 LeaveCriticalSection(&server_auth_info_cs);
1318 /***********************************************************************
1319 * RpcServerRegisterAuthInfoA (RPCRT4.@)
1321 RPC_STATUS WINAPI RpcServerRegisterAuthInfoA( RPC_CSTR ServerPrincName, ULONG AuthnSvc, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
1324 SECURITY_STATUS sec_status;
1327 ULONG package_count;
1329 PSecPkgInfoA packages;
1331 struct rpc_server_registered_auth_info *auth_info;
1333 TRACE("(%s,%u,%p,%p)\n", ServerPrincName, AuthnSvc, GetKeyFn, Arg);
1335 sec_status = EnumerateSecurityPackagesA(&package_count, &packages);
1336 if (sec_status != SEC_E_OK)
1338 ERR("EnumerateSecurityPackagesA failed with error 0x%08x\n",
1340 return RPC_S_SEC_PKG_ERROR;
1343 for (i = 0; i < package_count; i++)
1344 if (packages[i].wRPCID == AuthnSvc)
1347 if (i == package_count)
1349 WARN("unsupported AuthnSvc %u\n", AuthnSvc);
1350 FreeContextBuffer(packages);
1351 return RPC_S_UNKNOWN_AUTHN_SERVICE;
1353 TRACE("found package %s for service %u\n", packages[i].Name,
1355 sec_status = AcquireCredentialsHandleA((SEC_CHAR *)ServerPrincName,
1357 SECPKG_CRED_INBOUND, NULL, NULL,
1358 NULL, NULL, &cred, &exp);
1359 max_token = packages[i].cbMaxToken;
1360 FreeContextBuffer(packages);
1361 if (sec_status != SEC_E_OK)
1362 return RPC_S_SEC_PKG_ERROR;
1364 auth_info = HeapAlloc(GetProcessHeap(), 0, sizeof(*auth_info));
1367 FreeCredentialsHandle(&cred);
1368 return RPC_S_OUT_OF_RESOURCES;
1371 auth_info->exp = exp;
1372 auth_info->cred = cred;
1373 auth_info->max_token = max_token;
1374 auth_info->auth_type = AuthnSvc;
1376 EnterCriticalSection(&server_auth_info_cs);
1377 list_add_tail(&server_registered_auth_info, &auth_info->entry);
1378 LeaveCriticalSection(&server_auth_info_cs);
1383 /***********************************************************************
1384 * RpcServerRegisterAuthInfoW (RPCRT4.@)
1386 RPC_STATUS WINAPI RpcServerRegisterAuthInfoW( RPC_WSTR ServerPrincName, ULONG AuthnSvc, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
1389 SECURITY_STATUS sec_status;
1392 ULONG package_count;
1394 PSecPkgInfoW packages;
1396 struct rpc_server_registered_auth_info *auth_info;
1398 TRACE("(%s,%u,%p,%p)\n", debugstr_w(ServerPrincName), AuthnSvc, GetKeyFn, Arg);
1400 sec_status = EnumerateSecurityPackagesW(&package_count, &packages);
1401 if (sec_status != SEC_E_OK)
1403 ERR("EnumerateSecurityPackagesW failed with error 0x%08x\n",
1405 return RPC_S_SEC_PKG_ERROR;
1408 for (i = 0; i < package_count; i++)
1409 if (packages[i].wRPCID == AuthnSvc)
1412 if (i == package_count)
1414 WARN("unsupported AuthnSvc %u\n", AuthnSvc);
1415 FreeContextBuffer(packages);
1416 return RPC_S_UNKNOWN_AUTHN_SERVICE;
1418 TRACE("found package %s for service %u\n", debugstr_w(packages[i].Name),
1420 sec_status = AcquireCredentialsHandleW((SEC_WCHAR *)ServerPrincName,
1422 SECPKG_CRED_INBOUND, NULL, NULL,
1423 NULL, NULL, &cred, &exp);
1424 max_token = packages[i].cbMaxToken;
1425 FreeContextBuffer(packages);
1426 if (sec_status != SEC_E_OK)
1427 return RPC_S_SEC_PKG_ERROR;
1429 auth_info = HeapAlloc(GetProcessHeap(), 0, sizeof(*auth_info));
1432 FreeCredentialsHandle(&cred);
1433 return RPC_S_OUT_OF_RESOURCES;
1436 auth_info->exp = exp;
1437 auth_info->cred = cred;
1438 auth_info->max_token = max_token;
1439 auth_info->auth_type = AuthnSvc;
1441 EnterCriticalSection(&server_auth_info_cs);
1442 list_add_tail(&server_registered_auth_info, &auth_info->entry);
1443 LeaveCriticalSection(&server_auth_info_cs);
1448 /***********************************************************************
1449 * RpcServerListen (RPCRT4.@)
1451 RPC_STATUS WINAPI RpcServerListen( UINT MinimumCallThreads, UINT MaxCalls, UINT DontWait )
1453 RPC_STATUS status = RPC_S_OK;
1455 TRACE("(%u,%u,%u)\n", MinimumCallThreads, MaxCalls, DontWait);
1457 if (list_empty(&protseqs))
1458 return RPC_S_NO_PROTSEQS_REGISTERED;
1460 status = RPCRT4_start_listen(FALSE);
1462 if (DontWait || (status != RPC_S_OK)) return status;
1464 return RpcMgmtWaitServerListen();
1467 /***********************************************************************
1468 * RpcMgmtServerWaitListen (RPCRT4.@)
1470 RPC_STATUS WINAPI RpcMgmtWaitServerListen( void )
1474 EnterCriticalSection(&listen_cs);
1477 LeaveCriticalSection(&listen_cs);
1478 return RPC_S_NOT_LISTENING;
1481 LeaveCriticalSection(&listen_cs);
1483 FIXME("not waiting for server calls to finish\n");
1488 /***********************************************************************
1489 * RpcMgmtStopServerListening (RPCRT4.@)
1491 RPC_STATUS WINAPI RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding )
1493 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding);
1496 FIXME("client-side invocation not implemented.\n");
1497 return RPC_S_WRONG_KIND_OF_BINDING;
1500 RPCRT4_stop_listen(FALSE);
1505 /***********************************************************************
1506 * RpcMgmtEnableIdleCleanup (RPCRT4.@)
1508 RPC_STATUS WINAPI RpcMgmtEnableIdleCleanup(void)
1510 FIXME("(): stub\n");
1514 /***********************************************************************
1515 * I_RpcServerStartListening (RPCRT4.@)
1517 RPC_STATUS WINAPI I_RpcServerStartListening( HWND hWnd )
1519 FIXME( "(%p): stub\n", hWnd );
1524 /***********************************************************************
1525 * I_RpcServerStopListening (RPCRT4.@)
1527 RPC_STATUS WINAPI I_RpcServerStopListening( void )
1529 FIXME( "(): stub\n" );
1534 /***********************************************************************
1535 * I_RpcWindowProc (RPCRT4.@)
1537 UINT WINAPI I_RpcWindowProc( void *hWnd, UINT Message, UINT wParam, ULONG lParam )
1539 FIXME( "(%p,%08x,%08x,%08x): stub\n", hWnd, Message, wParam, lParam );
1544 /***********************************************************************
1545 * RpcMgmtInqIfIds (RPCRT4.@)
1547 RPC_STATUS WINAPI RpcMgmtInqIfIds(RPC_BINDING_HANDLE Binding, RPC_IF_ID_VECTOR **IfIdVector)
1549 FIXME("(%p,%p): stub\n", Binding, IfIdVector);
1550 return RPC_S_INVALID_BINDING;
1553 /***********************************************************************
1554 * RpcMgmtInqStats (RPCRT4.@)
1556 RPC_STATUS WINAPI RpcMgmtInqStats(RPC_BINDING_HANDLE Binding, RPC_STATS_VECTOR **Statistics)
1558 RPC_STATS_VECTOR *stats;
1560 FIXME("(%p,%p)\n", Binding, Statistics);
1562 if ((stats = HeapAlloc(GetProcessHeap(), 0, sizeof(RPC_STATS_VECTOR))))
1565 stats->Stats[0] = 0;
1566 *Statistics = stats;
1569 return RPC_S_OUT_OF_RESOURCES;
1572 /***********************************************************************
1573 * RpcMgmtStatsVectorFree (RPCRT4.@)
1575 RPC_STATUS WINAPI RpcMgmtStatsVectorFree(RPC_STATS_VECTOR **StatsVector)
1577 FIXME("(%p)\n", StatsVector);
1581 HeapFree(GetProcessHeap(), 0, *StatsVector);
1582 *StatsVector = NULL;
1587 /***********************************************************************
1588 * RpcMgmtEpEltInqBegin (RPCRT4.@)
1590 RPC_STATUS WINAPI RpcMgmtEpEltInqBegin(RPC_BINDING_HANDLE Binding, ULONG InquiryType,
1591 RPC_IF_ID *IfId, ULONG VersOption, UUID *ObjectUuid, RPC_EP_INQ_HANDLE* InquiryContext)
1593 FIXME("(%p,%u,%p,%u,%p,%p): stub\n",
1594 Binding, InquiryType, IfId, VersOption, ObjectUuid, InquiryContext);
1595 return RPC_S_INVALID_BINDING;
1598 /***********************************************************************
1599 * RpcMgmtIsServerListening (RPCRT4.@)
1601 RPC_STATUS WINAPI RpcMgmtIsServerListening(RPC_BINDING_HANDLE Binding)
1603 FIXME("(%p): stub\n", Binding);
1604 return RPC_S_INVALID_BINDING;
1607 /***********************************************************************
1608 * RpcMgmtSetServerStackSize (RPCRT4.@)
1610 RPC_STATUS WINAPI RpcMgmtSetServerStackSize(ULONG ThreadStackSize)
1612 FIXME("(0x%x): stub\n", ThreadStackSize);
1616 /***********************************************************************
1617 * I_RpcGetCurrentCallHandle (RPCRT4.@)
1619 RPC_BINDING_HANDLE WINAPI I_RpcGetCurrentCallHandle(void)
1622 return RPCRT4_GetThreadCurrentCallHandle();