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
;
107 /* event set once all listening is finished */
108 static HANDLE listen_done_event
;
110 static UUID uuid_nil
;
112 static inline RpcObjTypeMap
*LookupObjTypeMap(UUID
*ObjUuid
)
114 RpcObjTypeMap
*rslt
= RpcObjTypeMaps
;
118 if (! UuidCompare(ObjUuid
, &rslt
->Object
, &dummy
)) break;
125 static inline UUID
*LookupObjType(UUID
*ObjUuid
)
127 RpcObjTypeMap
*map
= LookupObjTypeMap(ObjUuid
);
134 static RpcServerInterface
* RPCRT4_find_interface(UUID
* object
,
135 const RPC_SYNTAX_IDENTIFIER
*if_id
,
136 const RPC_SYNTAX_IDENTIFIER
*transfer_syntax
,
139 UUID
* MgrType
= NULL
;
140 RpcServerInterface
* cif
;
144 MgrType
= LookupObjType(object
);
145 EnterCriticalSection(&server_cs
);
146 LIST_FOR_EACH_ENTRY(cif
, &server_interfaces
, RpcServerInterface
, entry
) {
147 if (!memcmp(if_id
, &cif
->If
->InterfaceId
, sizeof(RPC_SYNTAX_IDENTIFIER
)) &&
148 (!transfer_syntax
|| !memcmp(transfer_syntax
, &cif
->If
->TransferSyntax
, sizeof(RPC_SYNTAX_IDENTIFIER
))) &&
149 (check_object
== FALSE
|| UuidEqual(MgrType
, &cif
->MgrTypeUuid
, &status
)) &&
151 InterlockedIncrement(&cif
->CurrentCalls
);
155 LeaveCriticalSection(&server_cs
);
156 if (&cif
->entry
== &server_interfaces
) cif
= NULL
;
157 TRACE("returning %p for object %s, if_id { %d.%d %s }\n", cif
,
158 debugstr_guid(object
), if_id
->SyntaxVersion
.MajorVersion
,
159 if_id
->SyntaxVersion
.MinorVersion
, debugstr_guid(&if_id
->SyntaxGUID
));
163 static void RPCRT4_release_server_interface(RpcServerInterface
*sif
)
165 if (!InterlockedDecrement(&sif
->CurrentCalls
) &&
167 /* sif must have been removed from server_interfaces before
168 * CallsCompletedEvent is set */
169 if (sif
->CallsCompletedEvent
)
170 SetEvent(sif
->CallsCompletedEvent
);
171 HeapFree(GetProcessHeap(), 0, sif
);
175 static RpcPktHdr
*handle_bind_error(RpcConnection
*conn
, RPC_STATUS error
)
177 unsigned int reject_reason
;
180 case RPC_S_SERVER_TOO_BUSY
:
181 reject_reason
= REJECT_TEMPORARY_CONGESTION
;
183 case ERROR_OUTOFMEMORY
:
184 case RPC_S_OUT_OF_RESOURCES
:
185 reject_reason
= REJECT_LOCAL_LIMIT_EXCEEDED
;
187 case RPC_S_PROTOCOL_ERROR
:
188 reject_reason
= REJECT_PROTOCOL_VERSION_NOT_SUPPORTED
;
190 case RPC_S_UNKNOWN_AUTHN_SERVICE
:
191 reject_reason
= REJECT_UNKNOWN_AUTHN_SERVICE
;
193 case ERROR_ACCESS_DENIED
:
194 reject_reason
= REJECT_INVALID_CHECKSUM
;
197 FIXME("unexpected status value %d\n", error
);
199 case RPC_S_INVALID_BOUND
:
200 reject_reason
= REJECT_REASON_NOT_SPECIFIED
;
203 return RPCRT4_BuildBindNackHeader(NDR_LOCAL_DATA_REPRESENTATION
,
204 RPC_VER_MAJOR
, RPC_VER_MINOR
,
208 static RPC_STATUS
process_bind_packet_no_send(
209 RpcConnection
*conn
, RpcPktBindHdr
*hdr
, RPC_MESSAGE
*msg
,
210 unsigned char *auth_data
, ULONG auth_length
, RpcPktHdr
**ack_response
,
211 unsigned char **auth_data_out
, ULONG
*auth_length_out
)
214 RpcContextElement
*ctxt_elem
;
219 for (i
= 0, ctxt_elem
= msg
->Buffer
;
220 i
< hdr
->num_elements
;
221 i
++, ctxt_elem
= (RpcContextElement
*)&ctxt_elem
->transfer_syntaxes
[ctxt_elem
->num_syntaxes
])
223 if (((char *)ctxt_elem
- (char *)msg
->Buffer
) > msg
->BufferLength
||
224 ((char *)&ctxt_elem
->transfer_syntaxes
[ctxt_elem
->num_syntaxes
] - (char *)msg
->Buffer
) > msg
->BufferLength
)
226 ERR("inconsistent data in packet - packet length %d, num elements %d\n",
227 msg
->BufferLength
, hdr
->num_elements
);
228 return RPC_S_INVALID_BOUND
;
232 if (hdr
->max_tsize
< RPC_MIN_PACKET_SIZE
||
233 !UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
) ||
234 conn
->server_binding
)
236 TRACE("packet size less than min size, or active interface syntax guid non-null\n");
238 return RPC_S_INVALID_BOUND
;
241 results
= HeapAlloc(GetProcessHeap(), 0,
242 hdr
->num_elements
* sizeof(*results
));
244 return RPC_S_OUT_OF_RESOURCES
;
246 for (i
= 0, ctxt_elem
= (RpcContextElement
*)msg
->Buffer
;
247 i
< hdr
->num_elements
;
248 i
++, ctxt_elem
= (RpcContextElement
*)&ctxt_elem
->transfer_syntaxes
[ctxt_elem
->num_syntaxes
])
250 RpcServerInterface
* sif
= NULL
;
253 for (j
= 0; !sif
&& j
< ctxt_elem
->num_syntaxes
; j
++)
255 sif
= RPCRT4_find_interface(NULL
, &ctxt_elem
->abstract_syntax
,
256 &ctxt_elem
->transfer_syntaxes
[j
], FALSE
);
262 RPCRT4_release_server_interface(sif
);
263 TRACE("accepting bind request on connection %p for %s\n", conn
,
264 debugstr_guid(&ctxt_elem
->abstract_syntax
.SyntaxGUID
));
265 results
[i
].result
= RESULT_ACCEPT
;
266 results
[i
].reason
= REASON_NONE
;
267 results
[i
].transfer_syntax
= ctxt_elem
->transfer_syntaxes
[j
];
269 /* save the interface for later use */
270 /* FIXME: save linked list */
271 conn
->ActiveInterface
= ctxt_elem
->abstract_syntax
;
273 else if ((sif
= RPCRT4_find_interface(NULL
, &ctxt_elem
->abstract_syntax
,
274 NULL
, FALSE
)) != NULL
)
276 RPCRT4_release_server_interface(sif
);
277 TRACE("not accepting bind request on connection %p for %s - no transfer syntaxes supported\n",
278 conn
, debugstr_guid(&ctxt_elem
->abstract_syntax
.SyntaxGUID
));
279 results
[i
].result
= RESULT_PROVIDER_REJECTION
;
280 results
[i
].reason
= REASON_TRANSFER_SYNTAXES_NOT_SUPPORTED
;
281 memset(&results
[i
].transfer_syntax
, 0, sizeof(results
[i
].transfer_syntax
));
285 TRACE("not accepting bind request on connection %p for %s - abstract syntax not supported\n",
286 conn
, debugstr_guid(&ctxt_elem
->abstract_syntax
.SyntaxGUID
));
287 results
[i
].result
= RESULT_PROVIDER_REJECTION
;
288 results
[i
].reason
= REASON_ABSTRACT_SYNTAX_NOT_SUPPORTED
;
289 memset(&results
[i
].transfer_syntax
, 0, sizeof(results
[i
].transfer_syntax
));
293 /* create temporary binding */
294 status
= RPCRT4_MakeBinding(&conn
->server_binding
, conn
);
295 if (status
!= RPC_S_OK
)
297 HeapFree(GetProcessHeap(), 0, results
);
301 status
= RpcServerAssoc_GetAssociation(rpcrt4_conn_get_name(conn
),
302 conn
->NetworkAddr
, conn
->Endpoint
,
303 conn
->NetworkOptions
,
305 &conn
->server_binding
->Assoc
);
306 if (status
!= RPC_S_OK
)
308 HeapFree(GetProcessHeap(), 0, results
);
314 status
= RPCRT4_ServerConnectionAuth(conn
, TRUE
,
315 (RpcAuthVerifier
*)auth_data
,
316 auth_length
, auth_data_out
,
318 if (status
!= RPC_S_OK
)
320 HeapFree(GetProcessHeap(), 0, results
);
325 *ack_response
= RPCRT4_BuildBindAckHeader(NDR_LOCAL_DATA_REPRESENTATION
,
328 conn
->server_binding
->Assoc
->assoc_group_id
,
329 conn
->Endpoint
, hdr
->num_elements
,
331 HeapFree(GetProcessHeap(), 0, results
);
334 conn
->MaxTransmissionSize
= hdr
->max_tsize
;
336 status
= RPC_S_OUT_OF_RESOURCES
;
341 static RPC_STATUS
process_bind_packet(RpcConnection
*conn
, RpcPktBindHdr
*hdr
,
343 unsigned char *auth_data
,
347 RpcPktHdr
*response
= NULL
;
348 unsigned char *auth_data_out
= NULL
;
349 ULONG auth_length_out
= 0;
351 status
= process_bind_packet_no_send(conn
, hdr
, msg
, auth_data
, auth_length
,
352 &response
, &auth_data_out
,
354 if (status
!= RPC_S_OK
)
355 response
= handle_bind_error(conn
, status
);
357 status
= RPCRT4_SendWithAuth(conn
, response
, NULL
, 0, auth_data_out
, auth_length_out
);
359 status
= ERROR_OUTOFMEMORY
;
360 RPCRT4_FreeHeader(response
);
366 static RPC_STATUS
process_request_packet(RpcConnection
*conn
, RpcPktRequestHdr
*hdr
, RPC_MESSAGE
*msg
)
369 RpcPktHdr
*response
= NULL
;
370 RpcServerInterface
* sif
;
371 RPC_DISPATCH_FUNCTION func
;
374 NDR_SCONTEXT context_handle
;
375 void *buf
= msg
->Buffer
;
377 /* fail if the connection isn't bound with an interface */
378 if (UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
379 /* FIXME: should send BindNack instead */
380 response
= RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION
,
383 RPCRT4_Send(conn
, response
, NULL
, 0);
384 RPCRT4_FreeHeader(response
);
388 if (hdr
->common
.flags
& RPC_FLG_OBJECT_UUID
) {
389 object_uuid
= (UUID
*)(hdr
+ 1);
394 sif
= RPCRT4_find_interface(object_uuid
, &conn
->ActiveInterface
, NULL
, TRUE
);
396 WARN("interface %s no longer registered, returning fault packet\n", debugstr_guid(&conn
->ActiveInterface
.SyntaxGUID
));
397 response
= RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION
,
400 RPCRT4_Send(conn
, response
, NULL
, 0);
401 RPCRT4_FreeHeader(response
);
404 msg
->RpcInterfaceInformation
= sif
->If
;
405 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
406 msg
->ManagerEpv
= sif
->MgrEpv
;
407 if (object_uuid
!= NULL
) {
408 RPCRT4_SetBindingObject(msg
->Handle
, object_uuid
);
411 /* find dispatch function */
412 msg
->ProcNum
= hdr
->opnum
;
413 if (sif
->Flags
& RPC_IF_OLE
) {
414 /* native ole32 always gives us a dispatch table with a single entry
415 * (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
416 func
= *sif
->If
->DispatchTable
->DispatchTable
;
418 if (msg
->ProcNum
>= sif
->If
->DispatchTable
->DispatchTableCount
) {
419 WARN("invalid procnum (%d/%d)\n", msg
->ProcNum
, sif
->If
->DispatchTable
->DispatchTableCount
);
420 response
= RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION
,
423 RPCRT4_Send(conn
, response
, NULL
, 0);
424 RPCRT4_FreeHeader(response
);
426 func
= sif
->If
->DispatchTable
->DispatchTable
[msg
->ProcNum
];
429 /* put in the drep. FIXME: is this more universally applicable?
430 perhaps we should move this outward... */
431 msg
->DataRepresentation
=
432 MAKELONG( MAKEWORD(hdr
->common
.drep
[0], hdr
->common
.drep
[1]),
433 MAKEWORD(hdr
->common
.drep
[2], hdr
->common
.drep
[3]));
438 RPCRT4_SetThreadCurrentCallHandle(msg
->Handle
);
442 WARN("exception caught with code 0x%08x = %d\n", GetExceptionCode(), GetExceptionCode());
444 if (GetExceptionCode() == STATUS_ACCESS_VIOLATION
)
445 status
= ERROR_NOACCESS
;
447 status
= GetExceptionCode();
448 response
= RPCRT4_BuildFaultHeader(msg
->DataRepresentation
,
449 RPC2NCA_STATUS(status
));
451 RPCRT4_SetThreadCurrentCallHandle(NULL
);
453 /* release any unmarshalled context handles */
454 while ((context_handle
= RPCRT4_PopThreadContextHandle()) != NULL
)
455 RpcServerAssoc_ReleaseContextHandle(conn
->server_binding
->Assoc
, context_handle
, TRUE
);
458 response
= RPCRT4_BuildResponseHeader(msg
->DataRepresentation
,
461 /* send response packet */
463 status
= RPCRT4_Send(conn
, response
, exception
? NULL
: msg
->Buffer
,
464 exception
? 0 : msg
->BufferLength
);
465 RPCRT4_FreeHeader(response
);
467 ERR("out of memory\n");
469 msg
->RpcInterfaceInformation
= NULL
;
470 RPCRT4_release_server_interface(sif
);
472 if (msg
->Buffer
== buf
) buf
= NULL
;
473 TRACE("freeing Buffer=%p\n", buf
);
479 static RPC_STATUS
process_auth3_packet(RpcConnection
*conn
,
480 RpcPktCommonHdr
*hdr
,
482 unsigned char *auth_data
,
487 if (UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
) ||
488 !auth_length
|| msg
->BufferLength
!= 0)
489 status
= RPC_S_PROTOCOL_ERROR
;
492 status
= RPCRT4_ServerConnectionAuth(conn
, FALSE
,
493 (RpcAuthVerifier
*)auth_data
,
494 auth_length
, NULL
, NULL
);
497 /* FIXME: client doesn't expect a response to this message so must store
498 * status in connection so that fault packet can be returned when next
499 * packet is received */
504 static void RPCRT4_process_packet(RpcConnection
* conn
, RpcPktHdr
* hdr
,
505 RPC_MESSAGE
* msg
, unsigned char *auth_data
,
508 msg
->Handle
= (RPC_BINDING_HANDLE
)conn
->server_binding
;
510 switch (hdr
->common
.ptype
) {
512 TRACE("got bind packet\n");
513 process_bind_packet(conn
, &hdr
->bind
, msg
, auth_data
, auth_length
);
517 TRACE("got request packet\n");
518 process_request_packet(conn
, &hdr
->request
, msg
);
522 TRACE("got auth3 packet\n");
523 process_auth3_packet(conn
, &hdr
->common
, msg
, auth_data
, auth_length
);
526 FIXME("unhandled packet type %u\n", hdr
->common
.ptype
);
531 I_RpcFree(msg
->Buffer
);
532 RPCRT4_FreeHeader(hdr
);
533 HeapFree(GetProcessHeap(), 0, msg
);
534 HeapFree(GetProcessHeap(), 0, auth_data
);
537 static DWORD CALLBACK
RPCRT4_worker_thread(LPVOID the_arg
)
539 RpcPacket
*pkt
= the_arg
;
540 RPCRT4_process_packet(pkt
->conn
, pkt
->hdr
, pkt
->msg
, pkt
->auth_data
,
542 RPCRT4_ReleaseConnection(pkt
->conn
);
543 HeapFree(GetProcessHeap(), 0, pkt
);
547 static DWORD CALLBACK
RPCRT4_io_thread(LPVOID the_arg
)
549 RpcConnection
* conn
= the_arg
;
554 unsigned char *auth_data
;
557 TRACE("(%p)\n", conn
);
560 msg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RPC_MESSAGE
));
563 status
= RPCRT4_ReceiveWithAuth(conn
, &hdr
, msg
, &auth_data
, &auth_length
);
564 if (status
!= RPC_S_OK
) {
565 WARN("receive failed with error %x\n", status
);
566 HeapFree(GetProcessHeap(), 0, msg
);
570 switch (hdr
->common
.ptype
) {
572 TRACE("got bind packet\n");
574 status
= process_bind_packet(conn
, &hdr
->bind
, msg
, auth_data
,
579 TRACE("got request packet\n");
581 packet
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket
));
583 I_RpcFree(msg
->Buffer
);
584 RPCRT4_FreeHeader(hdr
);
585 HeapFree(GetProcessHeap(), 0, msg
);
586 HeapFree(GetProcessHeap(), 0, auth_data
);
589 packet
->conn
= RPCRT4_GrabConnection( conn
);
592 packet
->auth_data
= auth_data
;
593 packet
->auth_length
= auth_length
;
594 if (!QueueUserWorkItem(RPCRT4_worker_thread
, packet
, WT_EXECUTELONGFUNCTION
)) {
595 ERR("couldn't queue work item for worker thread, error was %d\n", GetLastError());
596 HeapFree(GetProcessHeap(), 0, packet
);
597 status
= RPC_S_OUT_OF_RESOURCES
;
604 TRACE("got auth3 packet\n");
606 status
= process_auth3_packet(conn
, &hdr
->common
, msg
, auth_data
,
610 FIXME("unhandled packet type %u\n", hdr
->common
.ptype
);
614 I_RpcFree(msg
->Buffer
);
615 RPCRT4_FreeHeader(hdr
);
616 HeapFree(GetProcessHeap(), 0, msg
);
617 HeapFree(GetProcessHeap(), 0, auth_data
);
619 if (status
!= RPC_S_OK
) {
620 WARN("processing packet failed with error %u\n", status
);
625 RPCRT4_ReleaseConnection(conn
);
629 void RPCRT4_new_client(RpcConnection
* conn
)
631 HANDLE thread
= CreateThread(NULL
, 0, RPCRT4_io_thread
, conn
, 0, NULL
);
633 DWORD err
= GetLastError();
634 ERR("failed to create thread, error=%08x\n", err
);
635 RPCRT4_ReleaseConnection(conn
);
637 /* we could set conn->thread, but then we'd have to make the io_thread wait
638 * for that, otherwise the thread might finish, destroy the connection, and
639 * free the memory we'd write to before we did, causing crashes and stuff -
640 * so let's implement that later, when we really need conn->thread */
642 CloseHandle( thread
);
645 static DWORD CALLBACK
RPCRT4_server_thread(LPVOID the_arg
)
650 RpcServerProtseq
* cps
= the_arg
;
652 BOOL set_ready_event
= FALSE
;
654 TRACE("(the_arg == ^%p)\n", the_arg
);
657 objs
= cps
->ops
->get_wait_array(cps
, objs
, &count
);
661 /* signal to function that changed state that we are now sync'ed */
662 SetEvent(cps
->server_ready_event
);
663 set_ready_event
= FALSE
;
667 res
= cps
->ops
->wait_for_new_connection(cps
, count
, objs
);
669 if (res
== -1 || (res
== 0 && !std_listen
))
672 cps
->ops
->free_wait_array(cps
, objs
);
673 EnterCriticalSection(&cps
->cs
);
674 for (conn
= cps
->conn
; conn
; conn
= conn
->Next
)
675 RPCRT4_CloseConnection(conn
);
676 LeaveCriticalSection(&cps
->cs
);
678 if (res
== 0 && !std_listen
)
679 SetEvent(cps
->server_ready_event
);
683 set_ready_event
= TRUE
;
688 /* tells the server thread that the state has changed and waits for it to
689 * make the changes */
690 static void RPCRT4_sync_with_server_thread(RpcServerProtseq
*ps
)
692 /* make sure we are the only thread sync'ing the server state, otherwise
693 * there is a race with the server thread setting an older state and setting
694 * the server_ready_event when the new state hasn't yet been applied */
695 WaitForSingleObject(ps
->mgr_mutex
, INFINITE
);
697 ps
->ops
->signal_state_changed(ps
);
699 /* wait for server thread to make the requested changes before returning */
700 WaitForSingleObject(ps
->server_ready_event
, INFINITE
);
702 ReleaseMutex(ps
->mgr_mutex
);
705 static RPC_STATUS
RPCRT4_start_listen_protseq(RpcServerProtseq
*ps
, BOOL auto_listen
)
707 RPC_STATUS status
= RPC_S_OK
;
708 HANDLE server_thread
;
710 EnterCriticalSection(&listen_cs
);
711 if (ps
->is_listening
) goto done
;
713 if (!ps
->mgr_mutex
) ps
->mgr_mutex
= CreateMutexW(NULL
, FALSE
, NULL
);
714 if (!ps
->server_ready_event
) ps
->server_ready_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
715 server_thread
= CreateThread(NULL
, 0, RPCRT4_server_thread
, ps
, 0, NULL
);
718 status
= RPC_S_OUT_OF_RESOURCES
;
721 ps
->is_listening
= TRUE
;
722 CloseHandle(server_thread
);
725 LeaveCriticalSection(&listen_cs
);
729 static RPC_STATUS
RPCRT4_start_listen(BOOL auto_listen
)
731 RPC_STATUS status
= RPC_S_ALREADY_LISTENING
;
732 RpcServerProtseq
*cps
;
736 EnterCriticalSection(&listen_cs
);
737 if (auto_listen
|| (manual_listen_count
++ == 0))
740 if (++listen_count
== 1)
743 LeaveCriticalSection(&listen_cs
);
747 EnterCriticalSection(&server_cs
);
748 LIST_FOR_EACH_ENTRY(cps
, &protseqs
, RpcServerProtseq
, entry
)
750 status
= RPCRT4_start_listen_protseq(cps
, TRUE
);
751 if (status
!= RPC_S_OK
)
754 /* make sure server is actually listening on the interface before
756 RPCRT4_sync_with_server_thread(cps
);
758 LeaveCriticalSection(&server_cs
);
764 static void RPCRT4_stop_listen(BOOL auto_listen
)
766 EnterCriticalSection(&listen_cs
);
767 if (auto_listen
|| (--manual_listen_count
== 0))
769 if (listen_count
!= 0 && --listen_count
== 0) {
770 RpcServerProtseq
*cps
;
773 LeaveCriticalSection(&listen_cs
);
775 LIST_FOR_EACH_ENTRY(cps
, &protseqs
, RpcServerProtseq
, entry
)
776 RPCRT4_sync_with_server_thread(cps
);
778 EnterCriticalSection(&listen_cs
);
779 if (listen_done_event
) SetEvent( listen_done_event
);
780 listen_done_event
= 0;
781 LeaveCriticalSection(&listen_cs
);
784 assert(listen_count
>= 0);
786 LeaveCriticalSection(&listen_cs
);
789 static BOOL
RPCRT4_protseq_is_endpoint_registered(RpcServerProtseq
*protseq
, const char *endpoint
)
792 EnterCriticalSection(&protseq
->cs
);
793 for (conn
= protseq
->conn
; conn
; conn
= conn
->Next
)
795 if (!endpoint
|| !strcmp(endpoint
, conn
->Endpoint
))
798 LeaveCriticalSection(&protseq
->cs
);
799 return (conn
!= NULL
);
802 static RPC_STATUS
RPCRT4_use_protseq(RpcServerProtseq
* ps
, const char *endpoint
)
806 EnterCriticalSection(&ps
->cs
);
808 if (RPCRT4_protseq_is_endpoint_registered(ps
, endpoint
))
811 status
= ps
->ops
->open_endpoint(ps
, endpoint
);
813 LeaveCriticalSection(&ps
->cs
);
815 if (status
!= RPC_S_OK
)
820 status
= RPCRT4_start_listen_protseq(ps
, FALSE
);
821 if (status
== RPC_S_OK
)
822 RPCRT4_sync_with_server_thread(ps
);
828 /***********************************************************************
829 * RpcServerInqBindings (RPCRT4.@)
831 RPC_STATUS WINAPI
RpcServerInqBindings( RPC_BINDING_VECTOR
** BindingVector
)
835 RpcServerProtseq
* ps
;
839 TRACE("(*BindingVector == ^%p)\n", *BindingVector
);
841 ERR("(BindingVector == NULL!!?)\n");
843 EnterCriticalSection(&server_cs
);
844 /* count connections */
846 LIST_FOR_EACH_ENTRY(ps
, &protseqs
, RpcServerProtseq
, entry
) {
847 EnterCriticalSection(&ps
->cs
);
848 for (conn
= ps
->conn
; conn
; conn
= conn
->Next
)
850 LeaveCriticalSection(&ps
->cs
);
853 /* export bindings */
854 *BindingVector
= HeapAlloc(GetProcessHeap(), 0,
855 sizeof(RPC_BINDING_VECTOR
) +
856 sizeof(RPC_BINDING_HANDLE
)*(count
-1));
857 (*BindingVector
)->Count
= count
;
859 LIST_FOR_EACH_ENTRY(ps
, &protseqs
, RpcServerProtseq
, entry
) {
860 EnterCriticalSection(&ps
->cs
);
861 for (conn
= ps
->conn
; conn
; conn
= conn
->Next
) {
862 RPCRT4_MakeBinding((RpcBinding
**)&(*BindingVector
)->BindingH
[count
],
866 LeaveCriticalSection(&ps
->cs
);
870 *BindingVector
= NULL
;
871 status
= RPC_S_NO_BINDINGS
;
873 LeaveCriticalSection(&server_cs
);
877 /***********************************************************************
878 * RpcServerUseProtseqEpA (RPCRT4.@)
880 RPC_STATUS WINAPI
RpcServerUseProtseqEpA( RPC_CSTR Protseq
, UINT MaxCalls
, RPC_CSTR Endpoint
, LPVOID SecurityDescriptor
)
884 TRACE( "(%s,%u,%s,%p)\n", Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
);
886 /* This should provide the default behaviour */
887 policy
.Length
= sizeof( policy
);
888 policy
.EndpointFlags
= 0;
891 return RpcServerUseProtseqEpExA( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
894 /***********************************************************************
895 * RpcServerUseProtseqEpW (RPCRT4.@)
897 RPC_STATUS WINAPI
RpcServerUseProtseqEpW( RPC_WSTR Protseq
, UINT MaxCalls
, RPC_WSTR Endpoint
, LPVOID SecurityDescriptor
)
901 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq
), MaxCalls
, debugstr_w( Endpoint
), SecurityDescriptor
);
903 /* This should provide the default behaviour */
904 policy
.Length
= sizeof( policy
);
905 policy
.EndpointFlags
= 0;
908 return RpcServerUseProtseqEpExW( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
911 /***********************************************************************
912 * alloc_serverprotoseq (internal)
914 * Must be called with server_cs held.
916 static RPC_STATUS
alloc_serverprotoseq(UINT MaxCalls
, const char *Protseq
, RpcServerProtseq
**ps
)
918 const struct protseq_ops
*ops
= rpcrt4_get_protseq_ops(Protseq
);
922 FIXME("protseq %s not supported\n", debugstr_a(Protseq
));
923 return RPC_S_PROTSEQ_NOT_SUPPORTED
;
928 return RPC_S_OUT_OF_RESOURCES
;
929 (*ps
)->MaxCalls
= MaxCalls
;
930 (*ps
)->Protseq
= RPCRT4_strdupA(Protseq
);
934 InitializeCriticalSection(&(*ps
)->cs
);
935 (*ps
)->cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": RpcServerProtseq.cs");
936 (*ps
)->is_listening
= FALSE
;
937 (*ps
)->mgr_mutex
= NULL
;
938 (*ps
)->server_ready_event
= NULL
;
940 list_add_head(&protseqs
, &(*ps
)->entry
);
942 TRACE("new protseq %p created for %s\n", *ps
, Protseq
);
947 /* must be called with server_cs held */
948 static void destroy_serverprotoseq(RpcServerProtseq
*ps
)
950 RPCRT4_strfree(ps
->Protseq
);
951 ps
->cs
.DebugInfo
->Spare
[0] = 0;
952 DeleteCriticalSection(&ps
->cs
);
953 CloseHandle(ps
->mgr_mutex
);
954 CloseHandle(ps
->server_ready_event
);
955 list_remove(&ps
->entry
);
956 HeapFree(GetProcessHeap(), 0, ps
);
959 /* Finds a given protseq or creates a new one if one doesn't already exist */
960 static RPC_STATUS
RPCRT4_get_or_create_serverprotseq(UINT MaxCalls
, const char *Protseq
, RpcServerProtseq
**ps
)
963 RpcServerProtseq
*cps
;
965 EnterCriticalSection(&server_cs
);
967 LIST_FOR_EACH_ENTRY(cps
, &protseqs
, RpcServerProtseq
, entry
)
968 if (!strcmp(cps
->Protseq
, Protseq
))
970 TRACE("found existing protseq object for %s\n", Protseq
);
972 LeaveCriticalSection(&server_cs
);
976 status
= alloc_serverprotoseq(MaxCalls
, Protseq
, ps
);
978 LeaveCriticalSection(&server_cs
);
983 /***********************************************************************
984 * RpcServerUseProtseqEpExA (RPCRT4.@)
986 RPC_STATUS WINAPI
RpcServerUseProtseqEpExA( RPC_CSTR Protseq
, UINT MaxCalls
, RPC_CSTR Endpoint
, LPVOID SecurityDescriptor
,
987 PRPC_POLICY lpPolicy
)
989 RpcServerProtseq
* ps
;
992 TRACE("(%s,%u,%s,%p,{%u,%u,%u})\n", debugstr_a((const char *)Protseq
),
993 MaxCalls
, debugstr_a((const char *)Endpoint
), SecurityDescriptor
,
994 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
996 status
= RPCRT4_get_or_create_serverprotseq(MaxCalls
, (const char *)Protseq
, &ps
);
997 if (status
!= RPC_S_OK
)
1000 return RPCRT4_use_protseq(ps
, (const char *)Endpoint
);
1003 /***********************************************************************
1004 * RpcServerUseProtseqEpExW (RPCRT4.@)
1006 RPC_STATUS WINAPI
RpcServerUseProtseqEpExW( RPC_WSTR Protseq
, UINT MaxCalls
, RPC_WSTR Endpoint
, LPVOID SecurityDescriptor
,
1007 PRPC_POLICY lpPolicy
)
1009 RpcServerProtseq
* ps
;
1014 TRACE("(%s,%u,%s,%p,{%u,%u,%u})\n", debugstr_w( Protseq
), MaxCalls
,
1015 debugstr_w( Endpoint
), SecurityDescriptor
,
1016 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
1018 ProtseqA
= RPCRT4_strdupWtoA(Protseq
);
1019 status
= RPCRT4_get_or_create_serverprotseq(MaxCalls
, ProtseqA
, &ps
);
1020 RPCRT4_strfree(ProtseqA
);
1021 if (status
!= RPC_S_OK
)
1024 EndpointA
= RPCRT4_strdupWtoA(Endpoint
);
1025 status
= RPCRT4_use_protseq(ps
, EndpointA
);
1026 RPCRT4_strfree(EndpointA
);
1030 /***********************************************************************
1031 * RpcServerUseProtseqA (RPCRT4.@)
1033 RPC_STATUS WINAPI
RpcServerUseProtseqA(RPC_CSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
1036 RpcServerProtseq
* ps
;
1038 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a((char*)Protseq
), MaxCalls
, SecurityDescriptor
);
1040 status
= RPCRT4_get_or_create_serverprotseq(MaxCalls
, (const char *)Protseq
, &ps
);
1041 if (status
!= RPC_S_OK
)
1044 return RPCRT4_use_protseq(ps
, NULL
);
1047 /***********************************************************************
1048 * RpcServerUseProtseqW (RPCRT4.@)
1050 RPC_STATUS WINAPI
RpcServerUseProtseqW(RPC_WSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
1053 RpcServerProtseq
* ps
;
1056 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_w(Protseq
), MaxCalls
, SecurityDescriptor
);
1058 ProtseqA
= RPCRT4_strdupWtoA(Protseq
);
1059 status
= RPCRT4_get_or_create_serverprotseq(MaxCalls
, ProtseqA
, &ps
);
1060 RPCRT4_strfree(ProtseqA
);
1061 if (status
!= RPC_S_OK
)
1064 return RPCRT4_use_protseq(ps
, NULL
);
1067 void RPCRT4_destroy_all_protseqs(void)
1069 RpcServerProtseq
*cps
, *cursor2
;
1071 if (listen_count
!= 0)
1074 EnterCriticalSection(&server_cs
);
1075 LIST_FOR_EACH_ENTRY_SAFE(cps
, cursor2
, &protseqs
, RpcServerProtseq
, entry
)
1077 if (listen_count
!= 0)
1078 RPCRT4_sync_with_server_thread(cps
);
1079 destroy_serverprotoseq(cps
);
1081 LeaveCriticalSection(&server_cs
);
1082 DeleteCriticalSection(&server_cs
);
1083 DeleteCriticalSection(&listen_cs
);
1086 /***********************************************************************
1087 * RpcServerRegisterIf (RPCRT4.@)
1089 RPC_STATUS WINAPI
RpcServerRegisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
)
1091 TRACE("(%p,%s,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
);
1092 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, (UINT
)-1, NULL
);
1095 /***********************************************************************
1096 * RpcServerRegisterIfEx (RPCRT4.@)
1098 RPC_STATUS WINAPI
RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
1099 UINT Flags
, UINT MaxCalls
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
1101 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
, IfCallbackFn
);
1102 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, Flags
, MaxCalls
, (UINT
)-1, IfCallbackFn
);
1105 /***********************************************************************
1106 * RpcServerRegisterIf2 (RPCRT4.@)
1108 RPC_STATUS WINAPI
RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
1109 UINT Flags
, UINT MaxCalls
, UINT MaxRpcSize
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
1111 PRPC_SERVER_INTERFACE If
= IfSpec
;
1112 RpcServerInterface
* sif
;
1115 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
,
1116 MaxRpcSize
, IfCallbackFn
);
1117 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
),
1118 If
->InterfaceId
.SyntaxVersion
.MajorVersion
,
1119 If
->InterfaceId
.SyntaxVersion
.MinorVersion
);
1120 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If
->TransferSyntax
.SyntaxGUID
),
1121 If
->TransferSyntax
.SyntaxVersion
.MajorVersion
,
1122 If
->TransferSyntax
.SyntaxVersion
.MinorVersion
);
1123 TRACE(" dispatch table: %p\n", If
->DispatchTable
);
1124 if (If
->DispatchTable
) {
1125 TRACE(" dispatch table count: %d\n", If
->DispatchTable
->DispatchTableCount
);
1126 for (i
=0; i
<If
->DispatchTable
->DispatchTableCount
; i
++) {
1127 TRACE(" entry %d: %p\n", i
, If
->DispatchTable
->DispatchTable
[i
]);
1129 TRACE(" reserved: %ld\n", If
->DispatchTable
->Reserved
);
1131 TRACE(" protseq endpoint count: %d\n", If
->RpcProtseqEndpointCount
);
1132 TRACE(" default manager epv: %p\n", If
->DefaultManagerEpv
);
1133 TRACE(" interpreter info: %p\n", If
->InterpreterInfo
);
1135 sif
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerInterface
));
1138 sif
->MgrTypeUuid
= *MgrTypeUuid
;
1139 sif
->MgrEpv
= MgrEpv
;
1141 memset(&sif
->MgrTypeUuid
, 0, sizeof(UUID
));
1142 sif
->MgrEpv
= If
->DefaultManagerEpv
;
1145 sif
->MaxCalls
= MaxCalls
;
1146 sif
->MaxRpcSize
= MaxRpcSize
;
1147 sif
->IfCallbackFn
= IfCallbackFn
;
1149 EnterCriticalSection(&server_cs
);
1150 list_add_head(&server_interfaces
, &sif
->entry
);
1151 LeaveCriticalSection(&server_cs
);
1153 if (sif
->Flags
& RPC_IF_AUTOLISTEN
)
1154 RPCRT4_start_listen(TRUE
);
1159 /***********************************************************************
1160 * RpcServerUnregisterIf (RPCRT4.@)
1162 RPC_STATUS WINAPI
RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, UINT WaitForCallsToComplete
)
1164 PRPC_SERVER_INTERFACE If
= IfSpec
;
1165 HANDLE event
= NULL
;
1167 BOOL completed
= TRUE
;
1168 RpcServerInterface
*cif
;
1171 TRACE("(IfSpec == (RPC_IF_HANDLE)^%p (%s), MgrTypeUuid == %s, WaitForCallsToComplete == %u)\n",
1172 IfSpec
, debugstr_guid(&If
->InterfaceId
.SyntaxGUID
), debugstr_guid(MgrTypeUuid
), WaitForCallsToComplete
);
1174 EnterCriticalSection(&server_cs
);
1175 LIST_FOR_EACH_ENTRY(cif
, &server_interfaces
, RpcServerInterface
, entry
) {
1176 if ((!IfSpec
|| !memcmp(&If
->InterfaceId
, &cif
->If
->InterfaceId
, sizeof(RPC_SYNTAX_IDENTIFIER
))) &&
1177 UuidEqual(MgrTypeUuid
, &cif
->MgrTypeUuid
, &status
)) {
1178 list_remove(&cif
->entry
);
1179 TRACE("unregistering cif %p\n", cif
);
1180 if (cif
->CurrentCalls
) {
1183 if (WaitForCallsToComplete
)
1184 cif
->CallsCompletedEvent
= event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1190 LeaveCriticalSection(&server_cs
);
1193 ERR("not found for object %s\n", debugstr_guid(MgrTypeUuid
));
1194 return RPC_S_UNKNOWN_IF
;
1198 HeapFree(GetProcessHeap(), 0, cif
);
1200 /* sif will be freed when the last call is completed, so be careful not to
1201 * touch that memory here as that could happen before we get here */
1202 WaitForSingleObject(event
, INFINITE
);
1209 /***********************************************************************
1210 * RpcServerUnregisterIfEx (RPCRT4.@)
1212 RPC_STATUS WINAPI
RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, int RundownContextHandles
)
1214 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
1215 IfSpec
, debugstr_guid(MgrTypeUuid
), RundownContextHandles
);
1220 /***********************************************************************
1221 * RpcObjectSetType (RPCRT4.@)
1224 * ObjUuid [I] "Object" UUID
1225 * TypeUuid [I] "Type" UUID
1228 * RPC_S_OK The call succeeded
1229 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
1230 * RPC_S_ALREADY_REGISTERED The provided object is already registered
1232 * Maps "Object" UUIDs to "Type" UUIDs. Passing the nil UUID as the type
1233 * resets the mapping for the specified object UUID to nil (the default).
1234 * The nil object is always associated with the nil type and cannot be
1235 * reassigned. Servers can support multiple implementations on the same
1236 * interface by registering different end-point vectors for the different
1237 * types. There's no need to call this if a server only supports the nil
1238 * type, as is typical.
1240 RPC_STATUS WINAPI
RpcObjectSetType( UUID
* ObjUuid
, UUID
* TypeUuid
)
1242 RpcObjTypeMap
*map
= RpcObjTypeMaps
, *prev
= NULL
;
1245 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid
), debugstr_guid(TypeUuid
));
1246 if ((! ObjUuid
) || UuidIsNil(ObjUuid
, &dummy
)) {
1247 /* nil uuid cannot be remapped */
1248 return RPC_S_INVALID_OBJECT
;
1251 /* find the mapping for this object if there is one ... */
1253 if (! UuidCompare(ObjUuid
, &map
->Object
, &dummy
)) break;
1257 if ((! TypeUuid
) || UuidIsNil(TypeUuid
, &dummy
)) {
1258 /* ... and drop it from the list */
1261 prev
->next
= map
->next
;
1263 RpcObjTypeMaps
= map
->next
;
1264 HeapFree(GetProcessHeap(), 0, map
);
1267 /* ... , fail if we found it ... */
1269 return RPC_S_ALREADY_REGISTERED
;
1270 /* ... otherwise create a new one and add it in. */
1271 map
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap
));
1272 map
->Object
= *ObjUuid
;
1273 map
->Type
= *TypeUuid
;
1276 prev
->next
= map
; /* prev is the last map in the linklist */
1278 RpcObjTypeMaps
= map
;
1284 struct rpc_server_registered_auth_info
1293 RPC_STATUS
RPCRT4_ServerGetRegisteredAuthInfo(
1294 USHORT auth_type
, CredHandle
*cred
, TimeStamp
*exp
, ULONG
*max_token
)
1296 RPC_STATUS status
= RPC_S_UNKNOWN_AUTHN_SERVICE
;
1297 struct rpc_server_registered_auth_info
*auth_info
;
1299 EnterCriticalSection(&server_auth_info_cs
);
1300 LIST_FOR_EACH_ENTRY(auth_info
, &server_registered_auth_info
, struct rpc_server_registered_auth_info
, entry
)
1302 if (auth_info
->auth_type
== auth_type
)
1304 *cred
= auth_info
->cred
;
1305 *exp
= auth_info
->exp
;
1306 *max_token
= auth_info
->max_token
;
1311 LeaveCriticalSection(&server_auth_info_cs
);
1316 void RPCRT4_ServerFreeAllRegisteredAuthInfo(void)
1318 struct rpc_server_registered_auth_info
*auth_info
, *cursor2
;
1320 EnterCriticalSection(&server_auth_info_cs
);
1321 LIST_FOR_EACH_ENTRY_SAFE(auth_info
, cursor2
, &server_registered_auth_info
, struct rpc_server_registered_auth_info
, entry
)
1323 FreeCredentialsHandle(&auth_info
->cred
);
1324 HeapFree(GetProcessHeap(), 0, auth_info
);
1326 LeaveCriticalSection(&server_auth_info_cs
);
1327 DeleteCriticalSection(&server_auth_info_cs
);
1330 /***********************************************************************
1331 * RpcServerRegisterAuthInfoA (RPCRT4.@)
1333 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoA( RPC_CSTR ServerPrincName
, ULONG AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
1336 SECURITY_STATUS sec_status
;
1339 ULONG package_count
;
1341 PSecPkgInfoA packages
;
1343 struct rpc_server_registered_auth_info
*auth_info
;
1345 TRACE("(%s,%u,%p,%p)\n", ServerPrincName
, AuthnSvc
, GetKeyFn
, Arg
);
1347 sec_status
= EnumerateSecurityPackagesA(&package_count
, &packages
);
1348 if (sec_status
!= SEC_E_OK
)
1350 ERR("EnumerateSecurityPackagesA failed with error 0x%08x\n",
1352 return RPC_S_SEC_PKG_ERROR
;
1355 for (i
= 0; i
< package_count
; i
++)
1356 if (packages
[i
].wRPCID
== AuthnSvc
)
1359 if (i
== package_count
)
1361 WARN("unsupported AuthnSvc %u\n", AuthnSvc
);
1362 FreeContextBuffer(packages
);
1363 return RPC_S_UNKNOWN_AUTHN_SERVICE
;
1365 TRACE("found package %s for service %u\n", packages
[i
].Name
,
1367 sec_status
= AcquireCredentialsHandleA((SEC_CHAR
*)ServerPrincName
,
1369 SECPKG_CRED_INBOUND
, NULL
, NULL
,
1370 NULL
, NULL
, &cred
, &exp
);
1371 max_token
= packages
[i
].cbMaxToken
;
1372 FreeContextBuffer(packages
);
1373 if (sec_status
!= SEC_E_OK
)
1374 return RPC_S_SEC_PKG_ERROR
;
1376 auth_info
= HeapAlloc(GetProcessHeap(), 0, sizeof(*auth_info
));
1379 FreeCredentialsHandle(&cred
);
1380 return RPC_S_OUT_OF_RESOURCES
;
1383 auth_info
->exp
= exp
;
1384 auth_info
->cred
= cred
;
1385 auth_info
->max_token
= max_token
;
1386 auth_info
->auth_type
= AuthnSvc
;
1388 EnterCriticalSection(&server_auth_info_cs
);
1389 list_add_tail(&server_registered_auth_info
, &auth_info
->entry
);
1390 LeaveCriticalSection(&server_auth_info_cs
);
1395 /***********************************************************************
1396 * RpcServerRegisterAuthInfoW (RPCRT4.@)
1398 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoW( RPC_WSTR ServerPrincName
, ULONG AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
1401 SECURITY_STATUS sec_status
;
1404 ULONG package_count
;
1406 PSecPkgInfoW packages
;
1408 struct rpc_server_registered_auth_info
*auth_info
;
1410 TRACE("(%s,%u,%p,%p)\n", debugstr_w(ServerPrincName
), AuthnSvc
, GetKeyFn
, Arg
);
1412 sec_status
= EnumerateSecurityPackagesW(&package_count
, &packages
);
1413 if (sec_status
!= SEC_E_OK
)
1415 ERR("EnumerateSecurityPackagesW failed with error 0x%08x\n",
1417 return RPC_S_SEC_PKG_ERROR
;
1420 for (i
= 0; i
< package_count
; i
++)
1421 if (packages
[i
].wRPCID
== AuthnSvc
)
1424 if (i
== package_count
)
1426 WARN("unsupported AuthnSvc %u\n", AuthnSvc
);
1427 FreeContextBuffer(packages
);
1428 return RPC_S_UNKNOWN_AUTHN_SERVICE
;
1430 TRACE("found package %s for service %u\n", debugstr_w(packages
[i
].Name
),
1432 sec_status
= AcquireCredentialsHandleW((SEC_WCHAR
*)ServerPrincName
,
1434 SECPKG_CRED_INBOUND
, NULL
, NULL
,
1435 NULL
, NULL
, &cred
, &exp
);
1436 max_token
= packages
[i
].cbMaxToken
;
1437 FreeContextBuffer(packages
);
1438 if (sec_status
!= SEC_E_OK
)
1439 return RPC_S_SEC_PKG_ERROR
;
1441 auth_info
= HeapAlloc(GetProcessHeap(), 0, sizeof(*auth_info
));
1444 FreeCredentialsHandle(&cred
);
1445 return RPC_S_OUT_OF_RESOURCES
;
1448 auth_info
->exp
= exp
;
1449 auth_info
->cred
= cred
;
1450 auth_info
->max_token
= max_token
;
1451 auth_info
->auth_type
= AuthnSvc
;
1453 EnterCriticalSection(&server_auth_info_cs
);
1454 list_add_tail(&server_registered_auth_info
, &auth_info
->entry
);
1455 LeaveCriticalSection(&server_auth_info_cs
);
1460 /***********************************************************************
1461 * RpcServerListen (RPCRT4.@)
1463 RPC_STATUS WINAPI
RpcServerListen( UINT MinimumCallThreads
, UINT MaxCalls
, UINT DontWait
)
1465 RPC_STATUS status
= RPC_S_OK
;
1467 TRACE("(%u,%u,%u)\n", MinimumCallThreads
, MaxCalls
, DontWait
);
1469 if (list_empty(&protseqs
))
1470 return RPC_S_NO_PROTSEQS_REGISTERED
;
1472 status
= RPCRT4_start_listen(FALSE
);
1474 if (DontWait
|| (status
!= RPC_S_OK
)) return status
;
1476 return RpcMgmtWaitServerListen();
1479 /***********************************************************************
1480 * RpcMgmtServerWaitListen (RPCRT4.@)
1482 RPC_STATUS WINAPI
RpcMgmtWaitServerListen( void )
1488 EnterCriticalSection(&listen_cs
);
1491 LeaveCriticalSection(&listen_cs
);
1492 return RPC_S_NOT_LISTENING
;
1494 if (listen_done_event
) {
1495 LeaveCriticalSection(&listen_cs
);
1496 return RPC_S_ALREADY_LISTENING
;
1498 event
= CreateEventW( NULL
, TRUE
, FALSE
, NULL
);
1499 listen_done_event
= event
;
1501 LeaveCriticalSection(&listen_cs
);
1503 TRACE( "waiting for server calls to finish\n" );
1504 WaitForSingleObject( event
, INFINITE
);
1505 TRACE( "done waiting\n" );
1507 CloseHandle( event
);
1511 /***********************************************************************
1512 * RpcMgmtStopServerListening (RPCRT4.@)
1514 RPC_STATUS WINAPI
RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding
)
1516 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding
);
1519 FIXME("client-side invocation not implemented.\n");
1520 return RPC_S_WRONG_KIND_OF_BINDING
;
1523 RPCRT4_stop_listen(FALSE
);
1528 /***********************************************************************
1529 * RpcMgmtEnableIdleCleanup (RPCRT4.@)
1531 RPC_STATUS WINAPI
RpcMgmtEnableIdleCleanup(void)
1533 FIXME("(): stub\n");
1537 /***********************************************************************
1538 * I_RpcServerStartListening (RPCRT4.@)
1540 RPC_STATUS WINAPI
I_RpcServerStartListening( HWND hWnd
)
1542 FIXME( "(%p): stub\n", hWnd
);
1547 /***********************************************************************
1548 * I_RpcServerStopListening (RPCRT4.@)
1550 RPC_STATUS WINAPI
I_RpcServerStopListening( void )
1552 FIXME( "(): stub\n" );
1557 /***********************************************************************
1558 * I_RpcWindowProc (RPCRT4.@)
1560 UINT WINAPI
I_RpcWindowProc( void *hWnd
, UINT Message
, UINT wParam
, ULONG lParam
)
1562 FIXME( "(%p,%08x,%08x,%08x): stub\n", hWnd
, Message
, wParam
, lParam
);
1567 /***********************************************************************
1568 * RpcMgmtInqIfIds (RPCRT4.@)
1570 RPC_STATUS WINAPI
RpcMgmtInqIfIds(RPC_BINDING_HANDLE Binding
, RPC_IF_ID_VECTOR
**IfIdVector
)
1572 FIXME("(%p,%p): stub\n", Binding
, IfIdVector
);
1573 return RPC_S_INVALID_BINDING
;
1576 /***********************************************************************
1577 * RpcMgmtInqStats (RPCRT4.@)
1579 RPC_STATUS WINAPI
RpcMgmtInqStats(RPC_BINDING_HANDLE Binding
, RPC_STATS_VECTOR
**Statistics
)
1581 RPC_STATS_VECTOR
*stats
;
1583 FIXME("(%p,%p)\n", Binding
, Statistics
);
1585 if ((stats
= HeapAlloc(GetProcessHeap(), 0, sizeof(RPC_STATS_VECTOR
))))
1588 stats
->Stats
[0] = 0;
1589 *Statistics
= stats
;
1592 return RPC_S_OUT_OF_RESOURCES
;
1595 /***********************************************************************
1596 * RpcMgmtStatsVectorFree (RPCRT4.@)
1598 RPC_STATUS WINAPI
RpcMgmtStatsVectorFree(RPC_STATS_VECTOR
**StatsVector
)
1600 FIXME("(%p)\n", StatsVector
);
1604 HeapFree(GetProcessHeap(), 0, *StatsVector
);
1605 *StatsVector
= NULL
;
1610 /***********************************************************************
1611 * RpcMgmtEpEltInqBegin (RPCRT4.@)
1613 RPC_STATUS WINAPI
RpcMgmtEpEltInqBegin(RPC_BINDING_HANDLE Binding
, ULONG InquiryType
,
1614 RPC_IF_ID
*IfId
, ULONG VersOption
, UUID
*ObjectUuid
, RPC_EP_INQ_HANDLE
* InquiryContext
)
1616 FIXME("(%p,%u,%p,%u,%p,%p): stub\n",
1617 Binding
, InquiryType
, IfId
, VersOption
, ObjectUuid
, InquiryContext
);
1618 return RPC_S_INVALID_BINDING
;
1621 /***********************************************************************
1622 * RpcMgmtIsServerListening (RPCRT4.@)
1624 RPC_STATUS WINAPI
RpcMgmtIsServerListening(RPC_BINDING_HANDLE Binding
)
1626 FIXME("(%p): stub\n", Binding
);
1627 return RPC_S_INVALID_BINDING
;
1630 /***********************************************************************
1631 * RpcMgmtSetAuthorizationFn (RPCRT4.@)
1633 RPC_STATUS WINAPI
RpcMgmtSetAuthorizationFn(RPC_MGMT_AUTHORIZATION_FN fn
)
1635 FIXME("(%p): stub\n", fn
);
1639 /***********************************************************************
1640 * RpcMgmtSetServerStackSize (RPCRT4.@)
1642 RPC_STATUS WINAPI
RpcMgmtSetServerStackSize(ULONG ThreadStackSize
)
1644 FIXME("(0x%x): stub\n", ThreadStackSize
);
1648 /***********************************************************************
1649 * I_RpcGetCurrentCallHandle (RPCRT4.@)
1651 RPC_BINDING_HANDLE WINAPI
I_RpcGetCurrentCallHandle(void)
1654 return RPCRT4_GetThreadCurrentCallHandle();