ReactOS  0.4.14-dev-614-gbfd8a84
rpc_assoc.c File Reference
#include <stdarg.h>
#include <assert.h>
#include "rpc.h"
#include "rpcndr.h"
#include "wine/winternl.h"
#include "wine/debug.h"
#include "rpc_binding.h"
#include "rpc_assoc.h"
#include "rpc_message.h"
Include dependency graph for rpc_assoc.c:

Go to the source code of this file.

Classes

struct  _RpcContextHandle
 

Macros

#define ROUND_UP(value, alignment)   (((value) + ((alignment) - 1)) & ~((alignment)-1))
 

Typedefs

typedef struct _RpcContextHandle RpcContextHandle
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (rpc)
 
static void RpcContextHandle_Destroy (RpcContextHandle *context_handle)
 
static RPC_STATUS RpcAssoc_Alloc (LPCSTR Protseq, LPCSTR NetworkAddr, LPCSTR Endpoint, LPCWSTR NetworkOptions, RpcAssoc **assoc_out)
 
static BOOL compare_networkoptions (LPCWSTR opts1, LPCWSTR opts2)
 
RPC_STATUS RPCRT4_GetAssociation (LPCSTR Protseq, LPCSTR NetworkAddr, LPCSTR Endpoint, LPCWSTR NetworkOptions, RpcAssoc **assoc_out)
 
RPC_STATUS RpcServerAssoc_GetAssociation (LPCSTR Protseq, LPCSTR NetworkAddr, LPCSTR Endpoint, LPCWSTR NetworkOptions, ULONG assoc_gid, RpcAssoc **assoc_out)
 
ULONG RpcAssoc_Release (RpcAssoc *assoc)
 
static RPC_STATUS RpcAssoc_BindConnection (const RpcAssoc *assoc, RpcConnection *conn, const RPC_SYNTAX_IDENTIFIER *InterfaceId, const RPC_SYNTAX_IDENTIFIER *TransferSyntax)
 
static RpcConnectionRpcAssoc_GetIdleConnection (RpcAssoc *assoc, const RPC_SYNTAX_IDENTIFIER *InterfaceId, const RPC_SYNTAX_IDENTIFIER *TransferSyntax, const RpcAuthInfo *AuthInfo, const RpcQualityOfService *QOS)
 
RPC_STATUS RpcAssoc_GetClientConnection (RpcAssoc *assoc, const RPC_SYNTAX_IDENTIFIER *InterfaceId, const RPC_SYNTAX_IDENTIFIER *TransferSyntax, RpcAuthInfo *AuthInfo, RpcQualityOfService *QOS, LPCWSTR CookieAuth, RpcConnection **Connection, BOOL *from_cache)
 
void RpcAssoc_ReleaseIdleConnection (RpcAssoc *assoc, RpcConnection *Connection)
 
void RpcAssoc_ConnectionReleased (RpcAssoc *assoc)
 
RPC_STATUS RpcServerAssoc_AllocateContextHandle (RpcAssoc *assoc, void *CtxGuard, NDR_SCONTEXT *SContext)
 
BOOL RpcContextHandle_IsGuardCorrect (NDR_SCONTEXT SContext, void *CtxGuard)
 
RPC_STATUS RpcServerAssoc_FindContextHandle (RpcAssoc *assoc, const UUID *uuid, void *CtxGuard, ULONG Flags, NDR_SCONTEXT *SContext)
 
RPC_STATUS RpcServerAssoc_UpdateContextHandle (RpcAssoc *assoc, NDR_SCONTEXT SContext, void *CtxGuard, NDR_RUNDOWN rundown_routine)
 
void RpcContextHandle_GetUuid (NDR_SCONTEXT SContext, UUID *uuid)
 
unsigned int RpcServerAssoc_ReleaseContextHandle (RpcAssoc *assoc, NDR_SCONTEXT SContext, BOOL release_lock)
 

Variables

static CRITICAL_SECTION assoc_list_cs = { &assoc_list_cs_debug, -1, 0, 0, 0, 0 }
 
static CRITICAL_SECTION_DEBUG assoc_list_cs_debug
 
static struct list client_assoc_list = LIST_INIT(client_assoc_list)
 
static struct list server_assoc_list = LIST_INIT(server_assoc_list)
 
static LONG last_assoc_group_id
 

Macro Definition Documentation

◆ ROUND_UP

#define ROUND_UP (   value,
  alignment 
)    (((value) + ((alignment) - 1)) & ~((alignment)-1))

Definition at line 227 of file rpc_assoc.c.

Typedef Documentation

◆ RpcContextHandle

Function Documentation

◆ compare_networkoptions()

static BOOL compare_networkoptions ( LPCWSTR  opts1,
LPCWSTR  opts2 
)
static

Definition at line 89 of file rpc_assoc.c.

90 {
91  if ((opts1 == NULL) && (opts2 == NULL))
92  return TRUE;
93  if ((opts1 == NULL) || (opts2 == NULL))
94  return FALSE;
95  return !wcscmp(opts1, opts2);
96 }
#define TRUE
Definition: types.h:120
smooth NULL
Definition: ftsmooth.c:416
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

Referenced by RPCRT4_GetAssociation().

◆ RpcAssoc_Alloc()

static RPC_STATUS RpcAssoc_Alloc ( LPCSTR  Protseq,
LPCSTR  NetworkAddr,
LPCSTR  Endpoint,
LPCWSTR  NetworkOptions,
RpcAssoc **  assoc_out 
)
static

Definition at line 64 of file rpc_assoc.c.

67 {
68  RpcAssoc *assoc;
69  assoc = HeapAlloc(GetProcessHeap(), 0, sizeof(*assoc));
70  if (!assoc)
72  assoc->refs = 1;
76  assoc->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": RpcAssoc.cs");
77  assoc->Protseq = RPCRT4_strdupA(Protseq);
78  assoc->NetworkAddr = RPCRT4_strdupA(NetworkAddr);
79  assoc->Endpoint = RPCRT4_strdupA(Endpoint);
80  assoc->NetworkOptions = NetworkOptions ? RPCRT4_strdupW(NetworkOptions) : NULL;
81  assoc->assoc_group_id = 0;
82  assoc->connection_cnt = 0;
83  UuidCreate(&assoc->http_uuid);
84  list_init(&assoc->entry);
85  *assoc_out = assoc;
86  return RPC_S_OK;
87 }
struct list entry
Definition: rpc_assoc.h:29
#define DWORD_PTR
Definition: treelist.c:76
struct list context_handle_list
Definition: rpc_assoc.h:49
LPSTR Endpoint
Definition: rpc_assoc.h:34
LONG connection_cnt
Definition: rpc_assoc.h:46
ULONG assoc_group_id
Definition: rpc_assoc.h:38
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
smooth NULL
Definition: ftsmooth.c:416
CRITICAL_SECTION cs
Definition: rpc_assoc.h:41
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LPSTR NetworkAddr
Definition: rpc_assoc.h:33
LONG refs
Definition: rpc_assoc.h:30
PCRITICAL_SECTION_DEBUG DebugInfo
Definition: winbase.h:866
RPC_STATUS WINAPI UuidCreate(UUID *Uuid)
Definition: rpcrt4_main.c:303
#define RPCRT4_strdupA(x)
Definition: rpc_binding.h:151
#define RPC_S_OUT_OF_RESOURCES
Definition: winerror.h:1032
struct list free_connection_pool
Definition: rpc_assoc.h:45
LPWSTR NetworkOptions
Definition: rpc_assoc.h:35
__WINE_SERVER_LIST_INLINE void list_init(struct list *list)
Definition: list.h:149
#define RPCRT4_strdupW(x)
Definition: rpc_binding.h:152
#define RPC_S_OK
Definition: rpcnterr.h:22
UUID http_uuid
Definition: rpc_assoc.h:39
DWORD_PTR Spare[8/sizeof(DWORD_PTR)]
Definition: winbase.h:859
LPSTR Protseq
Definition: rpc_assoc.h:32

Referenced by RPCRT4_GetAssociation(), and RpcServerAssoc_GetAssociation().

◆ RpcAssoc_BindConnection()

static RPC_STATUS RpcAssoc_BindConnection ( const RpcAssoc assoc,
RpcConnection conn,
const RPC_SYNTAX_IDENTIFIER InterfaceId,
const RPC_SYNTAX_IDENTIFIER TransferSyntax 
)
static

Definition at line 229 of file rpc_assoc.c.

232 {
233  RpcPktHdr *hdr;
234  RpcPktHdr *response_hdr;
237  unsigned char *auth_data = NULL;
238  ULONG auth_length;
239 
240  TRACE("sending bind request to server\n");
241 
244  assoc->assoc_group_id,
245  InterfaceId, TransferSyntax);
246 
247  status = RPCRT4_Send(conn, hdr, NULL, 0);
249  if (status != RPC_S_OK)
250  return status;
251 
252  status = RPCRT4_ReceiveWithAuth(conn, &response_hdr, &msg, &auth_data, &auth_length);
253  if (status != RPC_S_OK)
254  {
255  ERR("receive failed with error %d\n", status);
256  return status;
257  }
258 
259  switch (response_hdr->common.ptype)
260  {
261  case PKT_BIND_ACK:
262  {
263  RpcAddressString *server_address = msg.Buffer;
264  if ((msg.BufferLength >= FIELD_OFFSET(RpcAddressString, string[0])) ||
265  (msg.BufferLength >= ROUND_UP(FIELD_OFFSET(RpcAddressString, string[server_address->length]), 4)))
266  {
267  unsigned short remaining = msg.BufferLength -
268  ROUND_UP(FIELD_OFFSET(RpcAddressString, string[server_address->length]), 4);
269  RpcResultList *results = (RpcResultList*)((ULONG_PTR)server_address +
270  ROUND_UP(FIELD_OFFSET(RpcAddressString, string[server_address->length]), 4));
271  if ((results->num_results == 1) &&
272  (remaining >= FIELD_OFFSET(RpcResultList, results[results->num_results])))
273  {
274  switch (results->results[0].result)
275  {
276  case RESULT_ACCEPT:
277  /* respond to authorization request */
278  if (auth_length > sizeof(RpcAuthVerifier))
280  auth_data + sizeof(RpcAuthVerifier),
281  auth_length);
282  if (status == RPC_S_OK)
283  {
284  conn->assoc_group_id = response_hdr->bind_ack.assoc_gid;
285  conn->MaxTransmissionSize = response_hdr->bind_ack.max_tsize;
286  conn->ActiveInterface = *InterfaceId;
287  }
288  break;
290  switch (results->results[0].reason)
291  {
293  ERR("syntax %s, %d.%d not supported\n",
294  debugstr_guid(&InterfaceId->SyntaxGUID),
295  InterfaceId->SyntaxVersion.MajorVersion,
296  InterfaceId->SyntaxVersion.MinorVersion);
298  break;
300  ERR("transfer syntax not supported\n");
302  break;
303  case REASON_NONE:
304  default:
306  }
307  break;
309  default:
310  ERR("rejection result %d\n", results->results[0].result);
312  }
313  }
314  else
315  {
316  ERR("incorrect results size\n");
318  }
319  }
320  else
321  {
322  ERR("bind ack packet too small (%d)\n", msg.BufferLength);
324  }
325  break;
326  }
327  case PKT_BIND_NACK:
328  switch (response_hdr->bind_nack.reject_reason)
329  {
332  ERR("server too busy\n");
334  break;
336  ERR("protocol version not supported\n");
338  break;
340  ERR("unknown authentication service\n");
342  break;
344  ERR("invalid checksum\n");
346  break;
347  default:
348  ERR("rejected bind for reason %d\n", response_hdr->bind_nack.reject_reason);
350  }
351  break;
352  default:
353  ERR("wrong packet type received %d\n", response_hdr->common.ptype);
355  break;
356  }
357 
358  I_RpcFree(msg.Buffer);
359  RPCRT4_FreeHeader(response_hdr);
360  HeapFree(GetProcessHeap(), 0, auth_data);
361  return status;
362 }
USHORT MaxTransmissionSize
Definition: rpc_binding.h:71
#define RPC_S_UNKNOWN_IF
Definition: winerror.h:1028
#define ROUND_UP(value, alignment)
Definition: rpc_assoc.c:227
#define RESULT_PROVIDER_REJECTION
Definition: rpc_defs.h:213
#define REASON_NONE
Definition: rpc_defs.h:215
char hdr[14]
Definition: iptest.cpp:33
void WINAPI I_RpcFree(void *Object)
Definition: rpcrt4_main.c:722
unsigned short MajorVersion
Definition: rpcdcep.h:27
RPC_STATUS RPCRT4_ClientConnectionAuth(RpcConnection *conn, BYTE *challenge, ULONG count)
Definition: rpc_message.c:992
#define RESULT_ACCEPT
Definition: rpc_defs.h:211
#define REJECT_LOCAL_LIMIT_EXCEEDED
Definition: rpc_defs.h:222
VOID RPCRT4_FreeHeader(RpcPktHdr *Header)
Definition: rpc_message.c:403
#define RPC_S_SERVER_UNAVAILABLE
Definition: winerror.h:1033
#define REJECT_UNKNOWN_AUTHN_SERVICE
Definition: rpc_defs.h:228
unsigned short length
Definition: rpc_defs.h:91
#define RPC_S_ACCESS_DENIED
Definition: rpcnterr.h:29
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define REJECT_TEMPORARY_CONGESTION
Definition: rpc_defs.h:221
long RPC_STATUS
Definition: rpc.h:52
RpcPktCommonHdr common
Definition: rpc_defs.h:152
unsigned int assoc_gid
Definition: rpc_defs.h:114
ULONG assoc_group_id
Definition: rpc_assoc.h:38
RpcPktBindAckHdr bind_ack
Definition: rpc_defs.h:157
#define RPC_S_CALL_FAILED_DNE
Definition: winerror.h:1038
RPC_VERSION SyntaxVersion
Definition: rpcdcep.h:33
smooth NULL
Definition: ftsmooth.c:416
ULONG assoc_group_id
Definition: rpc_binding.h:86
RpcPktBindNAckHdr bind_nack
Definition: rpc_defs.h:158
unsigned short max_tsize
Definition: rpc_defs.h:112
#define debugstr_guid
Definition: kernel32.h:35
#define RPC_S_PROTOCOL_ERROR
Definition: winerror.h:1039
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:403
#define REJECT_INVALID_CHECKSUM
Definition: rpc_defs.h:229
RPC_STATUS RPCRT4_ReceiveWithAuth(RpcConnection *Connection, RpcPktHdr **Header, PRPC_MESSAGE pMsg, unsigned char **auth_data_out, ULONG *auth_length_out)
Definition: rpc_message.c:1376
struct _test_info results[8]
Definition: SetCursorPos.c:29
unsigned char ptype
Definition: rpc_defs.h:30
RpcPktHdr * RPCRT4_BuildBindHeader(ULONG DataRepresentation, unsigned short MaxTransmissionSize, unsigned short MaxReceiveSize, ULONG AssocGroupId, const RPC_SYNTAX_IDENTIFIER *AbstractId, const RPC_SYNTAX_IDENTIFIER *TransferId)
Definition: rpc_message.c:186
unsigned short MinorVersion
Definition: rpcdcep.h:28
#define RPC_S_UNKNOWN_AUTHN_SERVICE
Definition: winerror.h:1055
#define RPC_S_SERVER_TOO_BUSY
Definition: winerror.h:1034
#define ERR(fmt,...)
Definition: debug.h:109
#define NDR_LOCAL_DATA_REPRESENTATION
Definition: rpcndr.h:107
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
RPC_STATUS RPCRT4_Send(RpcConnection *Connection, RpcPktHdr *Header, void *Buffer, unsigned int BufferLength)
Definition: rpc_message.c:1223
#define RESULT_USER_REJECTION
Definition: rpc_defs.h:212
#define msg(x)
Definition: auth_time.c:54
#define REASON_ABSTRACT_SYNTAX_NOT_SUPPORTED
Definition: rpc_defs.h:216
#define REASON_TRANSFER_SYNTAXES_NOT_SUPPORTED
Definition: rpc_defs.h:217
#define RPC_MAX_PACKET_SIZE
Definition: rpc_defs.h:184
unsigned int ULONG
Definition: retypes.h:1
unsigned short reject_reason
Definition: rpc_defs.h:126
static SERVICE_STATUS status
Definition: service.c:31
#define REJECT_PROTOCOL_VERSION_NOT_SUPPORTED
Definition: rpc_defs.h:224
#define HeapFree(x, y, z)
Definition: compat.h:402
#define RPC_S_OK
Definition: rpcnterr.h:22
RPC_SYNTAX_IDENTIFIER ActiveInterface
Definition: rpc_binding.h:92
Definition: ps.c:97

Referenced by RpcAssoc_GetClientConnection().

◆ RpcAssoc_ConnectionReleased()

void RpcAssoc_ConnectionReleased ( RpcAssoc assoc)

Definition at line 447 of file rpc_assoc.c.

448 {
450  return;
451 
452  TRACE("Last %p connection released\n", assoc);
453  assoc->assoc_group_id = 0;
454 }
LONG connection_cnt
Definition: rpc_assoc.h:46
ULONG assoc_group_id
Definition: rpc_assoc.h:38
#define TRACE(s)
Definition: solgame.cpp:4
#define InterlockedDecrement
Definition: armddk.h:52

Referenced by RPCRT4_ReleaseConnection().

◆ RpcAssoc_GetClientConnection()

RPC_STATUS RpcAssoc_GetClientConnection ( RpcAssoc assoc,
const RPC_SYNTAX_IDENTIFIER InterfaceId,
const RPC_SYNTAX_IDENTIFIER TransferSyntax,
RpcAuthInfo AuthInfo,
RpcQualityOfService QOS,
LPCWSTR  CookieAuth,
RpcConnection **  Connection,
BOOL from_cache 
)

Definition at line 390 of file rpc_assoc.c.

395 {
396  RpcConnection *NewConnection;
398 
399  *Connection = RpcAssoc_GetIdleConnection(assoc, InterfaceId, TransferSyntax, AuthInfo, QOS);
400  if (*Connection) {
401  TRACE("return idle connection %p for association %p\n", *Connection, assoc);
402  if (from_cache) *from_cache = TRUE;
403  return RPC_S_OK;
404  }
405 
406  /* create a new connection */
407  status = RPCRT4_CreateConnection(&NewConnection, FALSE /* is this a server connection? */,
408  assoc->Protseq, assoc->NetworkAddr,
409  assoc->Endpoint, assoc->NetworkOptions,
410  AuthInfo, QOS, CookieAuth);
411  if (status != RPC_S_OK)
412  return status;
413 
414  NewConnection->assoc = assoc;
415  status = RPCRT4_OpenClientConnection(NewConnection);
416  if (status != RPC_S_OK)
417  {
418  RPCRT4_ReleaseConnection(NewConnection);
419  return status;
420  }
421 
422  status = RpcAssoc_BindConnection(assoc, NewConnection, InterfaceId, TransferSyntax);
423  if (status != RPC_S_OK)
424  {
425  RPCRT4_ReleaseConnection(NewConnection);
426  return status;
427  }
428 
430 
431  TRACE("return new connection %p for association %p\n", *Connection, assoc);
432  *Connection = NewConnection;
433  if (from_cache) *from_cache = FALSE;
434  return RPC_S_OK;
435 }
#define TRUE
Definition: types.h:120
long RPC_STATUS
Definition: rpc.h:52
LPSTR Endpoint
Definition: rpc_assoc.h:34
LONG connection_cnt
Definition: rpc_assoc.h:46
void RPCRT4_ReleaseConnection(RpcConnection *Connection) DECLSPEC_HIDDEN
#define TRACE(s)
Definition: solgame.cpp:4
LPSTR NetworkAddr
Definition: rpc_assoc.h:33
RPC_STATUS RPCRT4_CreateConnection(RpcConnection **Connection, BOOL server, LPCSTR Protseq, LPCSTR NetworkAddr, LPCSTR Endpoint, LPCWSTR NetworkOptions, RpcAuthInfo *AuthInfo, RpcQualityOfService *QOS, LPCWSTR CookieAuth) DECLSPEC_HIDDEN
static RpcConnection * RpcAssoc_GetIdleConnection(RpcAssoc *assoc, const RPC_SYNTAX_IDENTIFIER *InterfaceId, const RPC_SYNTAX_IDENTIFIER *TransferSyntax, const RpcAuthInfo *AuthInfo, const RpcQualityOfService *QOS)
Definition: rpc_assoc.c:364
#define InterlockedIncrement
Definition: armddk.h:53
RPC_STATUS RPCRT4_OpenClientConnection(RpcConnection *Connection) DECLSPEC_HIDDEN
LPWSTR NetworkOptions
Definition: rpc_assoc.h:35
static RPC_STATUS RpcAssoc_BindConnection(const RpcAssoc *assoc, RpcConnection *conn, const RPC_SYNTAX_IDENTIFIER *InterfaceId, const RPC_SYNTAX_IDENTIFIER *TransferSyntax)
Definition: rpc_assoc.c:229
static SERVICE_STATUS status
Definition: service.c:31
struct _RpcAssoc * assoc
Definition: rpc_binding.h:88
#define RPC_S_OK
Definition: rpcnterr.h:22
LPSTR Protseq
Definition: rpc_assoc.h:32
Definition: ps.c:97

Referenced by RPCRT4_OpenBinding().

◆ RpcAssoc_GetIdleConnection()

static RpcConnection* RpcAssoc_GetIdleConnection ( RpcAssoc assoc,
const RPC_SYNTAX_IDENTIFIER InterfaceId,
const RPC_SYNTAX_IDENTIFIER TransferSyntax,
const RpcAuthInfo AuthInfo,
const RpcQualityOfService QOS 
)
static

Definition at line 364 of file rpc_assoc.c.

368 {
369  RpcConnection *Connection;
370  EnterCriticalSection(&assoc->cs);
371  /* try to find a compatible connection from the connection pool */
372  LIST_FOR_EACH_ENTRY(Connection, &assoc->free_connection_pool, RpcConnection, conn_pool_entry)
373  {
374  if (!memcmp(&Connection->ActiveInterface, InterfaceId,
375  sizeof(RPC_SYNTAX_IDENTIFIER)) &&
376  RpcAuthInfo_IsEqual(Connection->AuthInfo, AuthInfo) &&
377  RpcQualityOfService_IsEqual(Connection->QOS, QOS))
378  {
379  list_remove(&Connection->conn_pool_entry);
380  LeaveCriticalSection(&assoc->cs);
381  TRACE("got connection from pool %p\n", Connection);
382  return Connection;
383  }
384  }
385 
386  LeaveCriticalSection(&assoc->cs);
387  return NULL;
388 }
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
struct list conn_pool_entry
Definition: rpc_binding.h:85
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
smooth NULL
Definition: ftsmooth.c:416
BOOL RpcAuthInfo_IsEqual(const RpcAuthInfo *AuthInfo1, const RpcAuthInfo *AuthInfo2)
Definition: rpc_binding.c:1205
CRITICAL_SECTION cs
Definition: rpc_assoc.h:41
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
#define TRACE(s)
Definition: solgame.cpp:4
RpcAuthInfo * AuthInfo
Definition: rpc_binding.h:77
struct list free_connection_pool
Definition: rpc_assoc.h:45
BOOL RpcQualityOfService_IsEqual(const RpcQualityOfService *qos1, const RpcQualityOfService *qos2)
Definition: rpc_binding.c:1386
RpcQualityOfService * QOS
Definition: rpc_binding.h:81
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
RPC_SYNTAX_IDENTIFIER ActiveInterface
Definition: rpc_binding.h:92

Referenced by RpcAssoc_GetClientConnection().

◆ RpcAssoc_Release()

ULONG RpcAssoc_Release ( RpcAssoc assoc)

Definition at line 187 of file rpc_assoc.c.

188 {
189  ULONG refs;
190 
192  refs = --assoc->refs;
193  if (!refs)
194  list_remove(&assoc->entry);
196 
197  if (!refs)
198  {
199  RpcConnection *Connection, *cursor2;
200  RpcContextHandle *context_handle, *context_handle_cursor;
201 
202  TRACE("destroying assoc %p\n", assoc);
203 
204  LIST_FOR_EACH_ENTRY_SAFE(Connection, cursor2, &assoc->free_connection_pool, RpcConnection, conn_pool_entry)
205  {
206  list_remove(&Connection->conn_pool_entry);
207  RPCRT4_ReleaseConnection(Connection);
208  }
209 
210  LIST_FOR_EACH_ENTRY_SAFE(context_handle, context_handle_cursor, &assoc->context_handle_list, RpcContextHandle, entry)
211  RpcContextHandle_Destroy(context_handle);
212 
213  HeapFree(GetProcessHeap(), 0, assoc->NetworkOptions);
214  HeapFree(GetProcessHeap(), 0, assoc->Endpoint);
215  HeapFree(GetProcessHeap(), 0, assoc->NetworkAddr);
216  HeapFree(GetProcessHeap(), 0, assoc->Protseq);
217 
218  assoc->cs.DebugInfo->Spare[0] = 0;
219  DeleteCriticalSection(&assoc->cs);
220 
221  HeapFree(GetProcessHeap(), 0, assoc);
222  }
223 
224  return refs;
225 }
struct list entry
Definition: rpc_assoc.h:29
struct list context_handle_list
Definition: rpc_assoc.h:49
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
struct list conn_pool_entry
Definition: rpc_binding.h:85
LPSTR Endpoint
Definition: rpc_assoc.h:34
CRITICAL_SECTION cs
Definition: rpc_assoc.h:41
void RPCRT4_ReleaseConnection(RpcConnection *Connection) DECLSPEC_HIDDEN
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:403
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
LPSTR NetworkAddr
Definition: rpc_assoc.h:33
LONG refs
Definition: rpc_assoc.h:30
PCRITICAL_SECTION_DEBUG DebugInfo
Definition: winbase.h:866
uint32_t entry
Definition: isohybrid.c:63
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:204
struct list free_connection_pool
Definition: rpc_assoc.h:45
LPWSTR NetworkOptions
Definition: rpc_assoc.h:35
unsigned int ULONG
Definition: retypes.h:1
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static void RpcContextHandle_Destroy(RpcContextHandle *context_handle)
Definition: rpc_assoc.c:547
#define HeapFree(x, y, z)
Definition: compat.h:402
static CRITICAL_SECTION assoc_list_cs
Definition: rpc_assoc.c:37
DWORD_PTR Spare[8/sizeof(DWORD_PTR)]
Definition: winbase.h:859
LPSTR Protseq
Definition: rpc_assoc.h:32

Referenced by RpcBindingReset(), RPCRT4_ReleaseBinding(), and RPCRT4_ResolveBinding().

◆ RpcAssoc_ReleaseIdleConnection()

void RpcAssoc_ReleaseIdleConnection ( RpcAssoc assoc,
RpcConnection Connection 
)

Definition at line 437 of file rpc_assoc.c.

438 {
439  assert(!Connection->server);
440  Connection->async_state = NULL;
441  EnterCriticalSection(&assoc->cs);
442  if (!assoc->assoc_group_id) assoc->assoc_group_id = Connection->assoc_group_id;
443  list_add_head(&assoc->free_connection_pool, &Connection->conn_pool_entry);
444  LeaveCriticalSection(&assoc->cs);
445 }
__WINE_SERVER_LIST_INLINE void list_add_head(struct list *list, struct list *elem)
Definition: list.h:96
#define assert(x)
Definition: debug.h:53
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
struct list conn_pool_entry
Definition: rpc_binding.h:85
ULONG assoc_group_id
Definition: rpc_assoc.h:38
smooth NULL
Definition: ftsmooth.c:416
ULONG assoc_group_id
Definition: rpc_binding.h:86
CRITICAL_SECTION cs
Definition: rpc_assoc.h:41
RPC_ASYNC_STATE * async_state
Definition: rpc_binding.h:87
struct list free_connection_pool
Definition: rpc_assoc.h:45
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by RPCRT4_CloseBinding().

◆ RpcContextHandle_Destroy()

static void RpcContextHandle_Destroy ( RpcContextHandle context_handle)
static

Definition at line 547 of file rpc_assoc.c.

548 {
549  TRACE("freeing %p\n", context_handle);
550 
551  if (context_handle->user_context && context_handle->rundown_routine)
552  {
553  TRACE("calling rundown routine %p with user context %p\n",
554  context_handle->rundown_routine, context_handle->user_context);
555  context_handle->rundown_routine(context_handle->user_context);
556  }
557 
558  RtlDeleteResource(&context_handle->rw_lock);
559 
560  HeapFree(GetProcessHeap(), 0, context_handle);
561 }
NTSYSAPI VOID NTAPI RtlDeleteResource(_In_ PRTL_RESOURCE Resource)
void * user_context
Definition: rpc_assoc.c:54
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:403
NDR_RUNDOWN rundown_routine
Definition: rpc_assoc.c:55
RTL_RWLOCK rw_lock
Definition: rpc_assoc.c:58
#define HeapFree(x, y, z)
Definition: compat.h:402

Referenced by RpcAssoc_Release(), and RpcServerAssoc_ReleaseContextHandle().

◆ RpcContextHandle_GetUuid()

void RpcContextHandle_GetUuid ( NDR_SCONTEXT  SContext,
UUID uuid 
)

Definition at line 541 of file rpc_assoc.c.

542 {
543  RpcContextHandle *context_handle = (RpcContextHandle *)SContext;
544  *uuid = context_handle->uuid;
545 }
Definition: msctf.idl:510

Referenced by NDRSContextMarshall2().

◆ RpcContextHandle_IsGuardCorrect()

BOOL RpcContextHandle_IsGuardCorrect ( NDR_SCONTEXT  SContext,
void CtxGuard 
)

Definition at line 481 of file rpc_assoc.c.

482 {
483  RpcContextHandle *context_handle = (RpcContextHandle *)SContext;
484  return context_handle->ctx_guard == CtxGuard;
485 }
void * ctx_guard
Definition: rpc_assoc.c:56

Referenced by NDRSContextMarshall2(), RpcServerAssoc_FindContextHandle(), and RpcServerAssoc_UpdateContextHandle().

◆ RPCRT4_GetAssociation()

RPC_STATUS RPCRT4_GetAssociation ( LPCSTR  Protseq,
LPCSTR  NetworkAddr,
LPCSTR  Endpoint,
LPCWSTR  NetworkOptions,
RpcAssoc **  assoc_out 
)

Definition at line 98 of file rpc_assoc.c.

101 {
102  RpcAssoc *assoc;
104 
107  {
108  if (!strcmp(Protseq, assoc->Protseq) &&
109  !strcmp(NetworkAddr, assoc->NetworkAddr) &&
110  !strcmp(Endpoint, assoc->Endpoint) &&
111  compare_networkoptions(NetworkOptions, assoc->NetworkOptions))
112  {
113  assoc->refs++;
114  *assoc_out = assoc;
116  TRACE("using existing assoc %p\n", assoc);
117  return RPC_S_OK;
118  }
119  }
120 
121  status = RpcAssoc_Alloc(Protseq, NetworkAddr, Endpoint, NetworkOptions, &assoc);
122  if (status != RPC_S_OK)
123  {
125  return status;
126  }
128  *assoc_out = assoc;
129 
131 
132  TRACE("new assoc %p\n", assoc);
133 
134  return RPC_S_OK;
135 }
struct list entry
Definition: rpc_assoc.h:29
__WINE_SERVER_LIST_INLINE void list_add_head(struct list *list, struct list *elem)
Definition: list.h:96
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
long RPC_STATUS
Definition: rpc.h:52
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
LPSTR Endpoint
Definition: rpc_assoc.h:34
static BOOL compare_networkoptions(LPCWSTR opts1, LPCWSTR opts2)
Definition: rpc_assoc.c:89
#define TRACE(s)
Definition: solgame.cpp:4
LPSTR NetworkAddr
Definition: rpc_assoc.h:33
LONG refs
Definition: rpc_assoc.h:30
static RPC_STATUS RpcAssoc_Alloc(LPCSTR Protseq, LPCSTR NetworkAddr, LPCSTR Endpoint, LPCWSTR NetworkOptions, RpcAssoc **assoc_out)
Definition: rpc_assoc.c:64
uint32_t entry
Definition: isohybrid.c:63
static struct list client_assoc_list
Definition: rpc_assoc.c:46
LPWSTR NetworkOptions
Definition: rpc_assoc.h:35
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static SERVICE_STATUS status
Definition: service.c:31
#define RPC_S_OK
Definition: rpcnterr.h:22
static CRITICAL_SECTION assoc_list_cs
Definition: rpc_assoc.c:37
LPSTR Protseq
Definition: rpc_assoc.h:32
Definition: ps.c:97

Referenced by RPCRT4_CompleteBindingA(), RPCRT4_CompleteBindingW(), and RPCRT4_ResolveBinding().

◆ RpcServerAssoc_AllocateContextHandle()

RPC_STATUS RpcServerAssoc_AllocateContextHandle ( RpcAssoc assoc,
void CtxGuard,
NDR_SCONTEXT SContext 
)

Definition at line 456 of file rpc_assoc.c.

458 {
459  RpcContextHandle *context_handle;
460 
461  context_handle = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*context_handle));
462  if (!context_handle)
463  return RPC_S_OUT_OF_MEMORY;
464 
465  context_handle->ctx_guard = CtxGuard;
466  RtlInitializeResource(&context_handle->rw_lock);
467  context_handle->refs = 1;
468 
469  /* lock here to mirror unmarshall, so we don't need to special-case the
470  * freeing of a non-marshalled context handle */
471  RtlAcquireResourceExclusive(&context_handle->rw_lock, TRUE);
472 
473  EnterCriticalSection(&assoc->cs);
474  list_add_tail(&assoc->context_handle_list, &context_handle->entry);
475  LeaveCriticalSection(&assoc->cs);
476 
477  *SContext = (NDR_SCONTEXT)context_handle;
478  return RPC_S_OK;
479 }
#define TRUE
Definition: types.h:120
struct list context_handle_list
Definition: rpc_assoc.h:49
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
__WINE_SERVER_LIST_INLINE void list_add_tail(struct list *list, struct list *elem)
Definition: list.h:102
#define RPC_S_OUT_OF_MEMORY
Definition: rpcnterr.h:24
CRITICAL_SECTION cs
Definition: rpc_assoc.h:41
struct _NDR_SCONTEXT * NDR_SCONTEXT
NTSYSAPI VOID NTAPI RtlInitializeResource(_In_ PRTL_RESOURCE Resource)
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
RTL_RWLOCK rw_lock
Definition: rpc_assoc.c:58
unsigned int refs
Definition: rpc_assoc.c:59
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
struct list entry
Definition: rpc_assoc.c:53
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void * ctx_guard
Definition: rpc_assoc.c:56
#define RPC_S_OK
Definition: rpcnterr.h:22
NTSYSAPI BOOLEAN NTAPI RtlAcquireResourceExclusive(_In_ PRTL_RESOURCE Resource, _In_ BOOLEAN Wait)

Referenced by NDRSContextUnmarshall2().

◆ RpcServerAssoc_FindContextHandle()

RPC_STATUS RpcServerAssoc_FindContextHandle ( RpcAssoc assoc,
const UUID uuid,
void CtxGuard,
ULONG  Flags,
NDR_SCONTEXT SContext 
)

Definition at line 487 of file rpc_assoc.c.

489 {
490  RpcContextHandle *context_handle;
491 
492  EnterCriticalSection(&assoc->cs);
494  {
495  if (RpcContextHandle_IsGuardCorrect((NDR_SCONTEXT)context_handle, CtxGuard) &&
496  !memcmp(&context_handle->uuid, uuid, sizeof(*uuid)))
497  {
498  *SContext = (NDR_SCONTEXT)context_handle;
499  if (context_handle->refs++)
500  {
501  LeaveCriticalSection(&assoc->cs);
502  TRACE("found %p\n", context_handle);
503  RtlAcquireResourceExclusive(&context_handle->rw_lock, TRUE);
504  return RPC_S_OK;
505  }
506  }
507  }
508  LeaveCriticalSection(&assoc->cs);
509 
510  ERR("no context handle found for uuid %s, guard %p\n",
511  debugstr_guid(uuid), CtxGuard);
512  return ERROR_INVALID_HANDLE;
513 }
#define TRUE
Definition: types.h:120
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
struct list context_handle_list
Definition: rpc_assoc.h:49
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
CRITICAL_SECTION cs
Definition: rpc_assoc.h:41
#define debugstr_guid
Definition: kernel32.h:35
struct _NDR_SCONTEXT * NDR_SCONTEXT
#define TRACE(s)
Definition: solgame.cpp:4
uint32_t entry
Definition: isohybrid.c:63
#define ERR(fmt,...)
Definition: debug.h:109
Definition: msctf.idl:510
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
BOOL RpcContextHandle_IsGuardCorrect(NDR_SCONTEXT SContext, void *CtxGuard)
Definition: rpc_assoc.c:481
#define RPC_S_OK
Definition: rpcnterr.h:22
NTSYSAPI BOOLEAN NTAPI RtlAcquireResourceExclusive(_In_ PRTL_RESOURCE Resource, _In_ BOOLEAN Wait)

Referenced by NDRSContextUnmarshall2().

◆ RpcServerAssoc_GetAssociation()

RPC_STATUS RpcServerAssoc_GetAssociation ( LPCSTR  Protseq,
LPCSTR  NetworkAddr,
LPCSTR  Endpoint,
LPCWSTR  NetworkOptions,
ULONG  assoc_gid,
RpcAssoc **  assoc_out 
)

Definition at line 137 of file rpc_assoc.c.

141 {
142  RpcAssoc *assoc;
144 
146  if (assoc_gid)
147  {
149  {
150  /* FIXME: NetworkAddr shouldn't be NULL */
151  if (assoc->assoc_group_id == assoc_gid &&
152  !strcmp(Protseq, assoc->Protseq) &&
153  (!NetworkAddr || !assoc->NetworkAddr || !strcmp(NetworkAddr, assoc->NetworkAddr)) &&
154  !strcmp(Endpoint, assoc->Endpoint) &&
155  ((!assoc->NetworkOptions == !NetworkOptions) &&
156  (!NetworkOptions || !wcscmp(NetworkOptions, assoc->NetworkOptions))))
157  {
158  assoc->refs++;
159  *assoc_out = assoc;
161  TRACE("using existing assoc %p\n", assoc);
162  return RPC_S_OK;
163  }
164  }
165  *assoc_out = NULL;
168  }
169 
170  status = RpcAssoc_Alloc(Protseq, NetworkAddr, Endpoint, NetworkOptions, &assoc);
171  if (status != RPC_S_OK)
172  {
174  return status;
175  }
178  *assoc_out = assoc;
179 
181 
182  TRACE("new assoc %p\n", assoc);
183 
184  return RPC_S_OK;
185 }
struct list entry
Definition: rpc_assoc.h:29
static LONG last_assoc_group_id
Definition: rpc_assoc.c:49
#define RPC_S_NO_CONTEXT_AVAILABLE
Definition: winerror.h:1073
static struct list server_assoc_list
Definition: rpc_assoc.c:47
__WINE_SERVER_LIST_INLINE void list_add_head(struct list *list, struct list *elem)
Definition: list.h:96
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
long RPC_STATUS
Definition: rpc.h:52
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
LPSTR Endpoint
Definition: rpc_assoc.h:34
ULONG assoc_group_id
Definition: rpc_assoc.h:38
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
LPSTR NetworkAddr
Definition: rpc_assoc.h:33
LONG refs
Definition: rpc_assoc.h:30
static RPC_STATUS RpcAssoc_Alloc(LPCSTR Protseq, LPCSTR NetworkAddr, LPCSTR Endpoint, LPCWSTR NetworkOptions, RpcAssoc **assoc_out)
Definition: rpc_assoc.c:64
uint32_t entry
Definition: isohybrid.c:63
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define InterlockedIncrement
Definition: armddk.h:53
LPWSTR NetworkOptions
Definition: rpc_assoc.h:35
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static SERVICE_STATUS status
Definition: service.c:31
#define RPC_S_OK
Definition: rpcnterr.h:22
static CRITICAL_SECTION assoc_list_cs
Definition: rpc_assoc.c:37
LPSTR Protseq
Definition: rpc_assoc.h:32
Definition: ps.c:97

Referenced by process_bind_packet_no_send().

◆ RpcServerAssoc_ReleaseContextHandle()

unsigned int RpcServerAssoc_ReleaseContextHandle ( RpcAssoc assoc,
NDR_SCONTEXT  SContext,
BOOL  release_lock 
)

Definition at line 563 of file rpc_assoc.c.

564 {
565  RpcContextHandle *context_handle = (RpcContextHandle *)SContext;
566  unsigned int refs;
567 
568  if (release_lock)
569  RtlReleaseResource(&context_handle->rw_lock);
570 
571  EnterCriticalSection(&assoc->cs);
572  refs = --context_handle->refs;
573  if (!refs)
574  list_remove(&context_handle->entry);
575  LeaveCriticalSection(&assoc->cs);
576 
577  if (!refs)
578  RpcContextHandle_Destroy(context_handle);
579 
580  return refs;
581 }
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
NTSYSAPI VOID NTAPI RtlReleaseResource(_In_ PRTL_RESOURCE Resource)
CRITICAL_SECTION cs
Definition: rpc_assoc.h:41
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
RTL_RWLOCK rw_lock
Definition: rpc_assoc.c:58
unsigned int refs
Definition: rpc_assoc.c:59
struct list entry
Definition: rpc_assoc.c:53
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static void RpcContextHandle_Destroy(RpcContextHandle *context_handle)
Definition: rpc_assoc.c:547

Referenced by NDRSContextMarshall2(), and process_request_packet().

◆ RpcServerAssoc_UpdateContextHandle()

RPC_STATUS RpcServerAssoc_UpdateContextHandle ( RpcAssoc assoc,
NDR_SCONTEXT  SContext,
void CtxGuard,
NDR_RUNDOWN  rundown_routine 
)

Definition at line 515 of file rpc_assoc.c.

519 {
520  RpcContextHandle *context_handle = (RpcContextHandle *)SContext;
522 
523  if (!RpcContextHandle_IsGuardCorrect((NDR_SCONTEXT)context_handle, CtxGuard))
524  return ERROR_INVALID_HANDLE;
525 
526  EnterCriticalSection(&assoc->cs);
527  if (UuidIsNil(&context_handle->uuid, &status))
528  {
529  /* add a ref for the data being valid */
530  context_handle->refs++;
531  UuidCreate(&context_handle->uuid);
532  context_handle->rundown_routine = rundown_routine;
533  TRACE("allocated uuid %s for context handle %p\n",
534  debugstr_guid(&context_handle->uuid), context_handle);
535  }
536  LeaveCriticalSection(&assoc->cs);
537 
538  return RPC_S_OK;
539 }
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
int WINAPI UuidIsNil(UUID *Uuid, RPC_STATUS *Status)
Definition: rpcrt4_main.c:266
long RPC_STATUS
Definition: rpc.h:52
CRITICAL_SECTION cs
Definition: rpc_assoc.h:41
#define debugstr_guid
Definition: kernel32.h:35
#define TRACE(s)
Definition: solgame.cpp:4
RPC_STATUS WINAPI UuidCreate(UUID *Uuid)
Definition: rpcrt4_main.c:303
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static SERVICE_STATUS status
Definition: service.c:31
BOOL RpcContextHandle_IsGuardCorrect(NDR_SCONTEXT SContext, void *CtxGuard)
Definition: rpc_assoc.c:481
#define RPC_S_OK
Definition: rpcnterr.h:22
Definition: ps.c:97

Referenced by NDRSContextMarshall2().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( rpc  )

Variable Documentation

◆ assoc_list_cs

static CRITICAL_SECTION assoc_list_cs = { &assoc_list_cs_debug, -1, 0, 0, 0, 0 }
static

◆ assoc_list_cs_debug

CRITICAL_SECTION_DEBUG assoc_list_cs_debug
static
Initial value:
=
{
0, 0, &assoc_list_cs,
0, 0, { (DWORD_PTR)(__FILE__ ": assoc_list_cs") }
}
#define DWORD_PTR
Definition: treelist.c:76
LIST_ENTRY ProcessLocksList
Definition: winbase.h:855
static CRITICAL_SECTION assoc_list_cs
Definition: rpc_assoc.c:37
static CRITICAL_SECTION_DEBUG assoc_list_cs_debug
Definition: rpc_assoc.c:38

Definition at line 38 of file rpc_assoc.c.

◆ client_assoc_list

struct list client_assoc_list = LIST_INIT(client_assoc_list)
static

Definition at line 46 of file rpc_assoc.c.

Referenced by RPCRT4_GetAssociation().

◆ last_assoc_group_id

LONG last_assoc_group_id
static

Definition at line 49 of file rpc_assoc.c.

Referenced by RpcServerAssoc_GetAssociation().

◆ server_assoc_list

struct list server_assoc_list = LIST_INIT(server_assoc_list)
static

Definition at line 47 of file rpc_assoc.c.

Referenced by RpcServerAssoc_GetAssociation().