ReactOS 0.4.15-dev-7788-g1ad9096
ndr_contexthandle.c
Go to the documentation of this file.
1/*
2 * NDR data marshalling
3 *
4 * Copyright 2006 Mike McCormack (for CodeWeavers)
5 * Copyright 2006-2007 Robert Shearman (for CodeWeavers)
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22#include "ndr_misc.h"
23#include "rpc_assoc.h"
24#include "rpcndr.h"
25
26#include "wine/debug.h"
27#include "wine/list.h"
28
30
31#define NDR_CONTEXT_HANDLE_MAGIC 0x4352444e
32
33typedef struct ndr_context_handle
34{
38
40{
41 struct list entry;
45};
46
48
51{
52 0, 0, &ndr_context_cs,
54 0, 0, { (DWORD_PTR)(__FILE__ ": ndr_context") }
55};
56static CRITICAL_SECTION ndr_context_cs = { &ndr_context_debug, -1, 0, 0, 0, 0 };
57
59{
60 struct context_handle_entry *che = CContext;
61
63 return NULL;
64 return che;
65}
66
68{
69 struct context_handle_entry *che;
71 if (IsEqualGUID(&che->wire_data.uuid, uuid))
72 return che;
73 return NULL;
74}
75
77{
78 struct context_handle_entry *che;
80
81 TRACE("%p\n", CContext);
82
84 che = get_context_entry(CContext);
85 if (che)
86 handle = che->handle;
88
89 if (!handle)
90 {
91 ERR("invalid handle %p\n", CContext);
93 }
94 return handle;
95}
96
97void WINAPI NDRCContextMarshall(NDR_CCONTEXT CContext, void *pBuff)
98{
99 struct context_handle_entry *che;
100
101 TRACE("%p %p\n", CContext, pBuff);
102
103 if (CContext)
104 {
106 che = get_context_entry(CContext);
107 memcpy(pBuff, &che->wire_data, sizeof (ndr_context_handle));
109 }
110 else
111 {
115 }
116}
117
118/***********************************************************************
119 * RpcSmDestroyClientContext [RPCRT4.@]
120 */
122{
124 struct context_handle_entry *che = NULL;
125
126 TRACE("(%p)\n", ContextHandle);
127
129 che = get_context_entry(*ContextHandle);
130 *ContextHandle = NULL;
131 if (che)
132 {
134 list_remove(&che->entry);
135 }
136
138
139 if (che)
140 {
141 RpcBindingFree(&che->handle);
142 HeapFree(GetProcessHeap(), 0, che);
143 }
144
145 return status;
146}
147
148/***********************************************************************
149 * RpcSsDestroyClientContext [RPCRT4.@]
150 */
151void WINAPI RpcSsDestroyClientContext(void **ContextHandle)
152{
154 if (status != RPC_S_OK)
156}
157
158/***********************************************************************
159 * RpcSsDontSerializeContext [RPCRT4.@]
160 */
162{
163 FIXME("stub\n");
164}
165
168 const ndr_context_handle *chi)
169{
170 struct context_handle_entry *che = NULL;
171
172 /* a null UUID means we should free the context handle */
173 if (IsEqualGUID(&chi->uuid, &GUID_NULL))
174 {
175 if (*CContext)
176 {
177 che = get_context_entry(*CContext);
178 if (!che)
180 list_remove(&che->entry);
181 RpcBindingFree(&che->handle);
182 HeapFree(GetProcessHeap(), 0, che);
183 che = NULL;
184 }
185 }
186 /* if there's no existing entry matching the GUID, allocate one */
187 else if (!(che = context_entry_from_guid(&chi->uuid)))
188 {
189 che = HeapAlloc(GetProcessHeap(), 0, sizeof *che);
190 if (!che)
191 return RPC_X_NO_MEMORY;
195 che->wire_data = *chi;
196 }
197
198 *CContext = che;
199
200 return RPC_S_OK;
201}
202
203/***********************************************************************
204 * NDRCContextUnmarshall [RPCRT4.@]
205 */
208 void *pBuff, ULONG DataRepresentation)
209{
211
212 TRACE("*%p=(%p) %p %p %08x\n",
213 CContext, *CContext, hBinding, pBuff, DataRepresentation);
214
216 status = ndr_update_context_handle(CContext, hBinding, pBuff);
218 if (status)
220}
221
222/***********************************************************************
223 * NDRSContextMarshall [RPCRT4.@]
224 */
226 void *pBuff,
227 NDR_RUNDOWN userRunDownIn)
228{
229 TRACE("(%p %p %p)\n", SContext, pBuff, userRunDownIn);
231 userRunDownIn, NULL, RPC_CONTEXT_HANDLE_DEFAULT_FLAGS);
232}
233
234/***********************************************************************
235 * NDRSContextMarshallEx [RPCRT4.@]
236 */
238 NDR_SCONTEXT SContext,
239 void *pBuff,
240 NDR_RUNDOWN userRunDownIn)
241{
242 TRACE("(%p %p %p %p)\n", hBinding, SContext, pBuff, userRunDownIn);
243 NDRSContextMarshall2(hBinding, SContext, pBuff, userRunDownIn, NULL,
245}
246
247/***********************************************************************
248 * NDRSContextMarshall2 [RPCRT4.@]
249 */
251 NDR_SCONTEXT SContext,
252 void *pBuff,
253 NDR_RUNDOWN userRunDownIn,
254 void *CtxGuard, ULONG Flags)
255{
256 RpcBinding *binding = hBinding;
258 ndr_context_handle *ndr = pBuff;
259
260 TRACE("(%p %p %p %p %p %u)\n",
261 hBinding, SContext, pBuff, userRunDownIn, CtxGuard, Flags);
262
263 if (!binding->server || !binding->Assoc)
265
266 if (SContext->userContext)
267 {
268 status = RpcServerAssoc_UpdateContextHandle(binding->Assoc, SContext, CtxGuard, userRunDownIn);
269 if (status != RPC_S_OK)
271 ndr->attributes = 0;
272 RpcContextHandle_GetUuid(SContext, &ndr->uuid);
273
276 }
277 else
278 {
279 if (!RpcContextHandle_IsGuardCorrect(SContext, CtxGuard))
281 memset(ndr, 0, sizeof(*ndr));
282
284 /* Note: release the context handle twice in this case to release
285 * one ref being kept around for the data and one ref for the
286 * unmarshall/marshall sequence */
287 if (!RpcServerAssoc_ReleaseContextHandle(binding->Assoc, SContext, TRUE))
288 return; /* this is to cope with the case of the data not being valid
289 * before and so not having a further reference */
291 }
292}
293
294/***********************************************************************
295 * NDRSContextUnmarshall [RPCRT4.@]
296 */
298 ULONG DataRepresentation)
299{
300 TRACE("(%p %08x)\n", pBuff, DataRepresentation);
302 DataRepresentation, NULL,
304}
305
306/***********************************************************************
307 * NDRSContextUnmarshallEx [RPCRT4.@]
308 */
310 void *pBuff,
311 ULONG DataRepresentation)
312{
313 TRACE("(%p %p %08x)\n", hBinding, pBuff, DataRepresentation);
314 return NDRSContextUnmarshall2(hBinding, pBuff, DataRepresentation, NULL,
316}
317
318/***********************************************************************
319 * NDRSContextUnmarshall2 [RPCRT4.@]
320 */
322 void *pBuff,
323 ULONG DataRepresentation,
324 void *CtxGuard, ULONG Flags)
325{
326 RpcBinding *binding = hBinding;
327 NDR_SCONTEXT SContext;
329 const ndr_context_handle *context_ndr = pBuff;
330
331 TRACE("(%p %p %08x %p %u)\n",
332 hBinding, pBuff, DataRepresentation, CtxGuard, Flags);
333
334 if (!binding->server || !binding->Assoc)
336
337 if (!pBuff || (!context_ndr->attributes &&
338 UuidIsNil((UUID *)&context_ndr->uuid, &status)))
340 &SContext);
341 else
342 {
343 if (context_ndr->attributes)
344 {
345 ERR("non-null attributes 0x%x\n", context_ndr->attributes);
347 }
348 else
350 &context_ndr->uuid,
351 CtxGuard, Flags,
352 &SContext);
353 }
354
355 if (status != RPC_S_OK)
357
359 return SContext;
360}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
static void list_remove(struct list_entry *entry)
Definition: list.h:90
static void list_add_tail(struct list_entry *head, struct list_entry *entry)
Definition: list.h:83
#define FIXME(fmt,...)
Definition: debug.h:111
#define ERR(fmt,...)
Definition: debug.h:110
Definition: list.h:37
handle_t hBinding
Definition: ctx_c.c:54
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned long DWORD
Definition: ntddk_ex.h:95
Definition: msctf.idl:550
uint32_t entry
Definition: isohybrid.c:63
#define GUID_NULL
Definition: ks.h:106
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
void WINAPI RpcSsDestroyClientContext(void **ContextHandle)
static CRITICAL_SECTION ndr_context_cs
void WINAPI NDRSContextMarshallEx(RPC_BINDING_HANDLE hBinding, NDR_SCONTEXT SContext, void *pBuff, NDR_RUNDOWN userRunDownIn)
RPC_STATUS WINAPI RpcSmDestroyClientContext(void **ContextHandle)
void WINAPI RpcSsDontSerializeContext(void)
RPC_BINDING_HANDLE WINAPI NDRCContextBinding(NDR_CCONTEXT CContext)
static CRITICAL_SECTION_DEBUG ndr_context_debug
NDR_SCONTEXT WINAPI NDRSContextUnmarshall2(RPC_BINDING_HANDLE hBinding, void *pBuff, ULONG DataRepresentation, void *CtxGuard, ULONG Flags)
void WINAPI NDRCContextUnmarshall(NDR_CCONTEXT *CContext, RPC_BINDING_HANDLE hBinding, void *pBuff, ULONG DataRepresentation)
struct ndr_context_handle ndr_context_handle
#define NDR_CONTEXT_HANDLE_MAGIC
static struct context_handle_entry * get_context_entry(NDR_CCONTEXT CContext)
NDR_SCONTEXT WINAPI NDRSContextUnmarshallEx(RPC_BINDING_HANDLE hBinding, void *pBuff, ULONG DataRepresentation)
NDR_SCONTEXT WINAPI NDRSContextUnmarshall(void *pBuff, ULONG DataRepresentation)
static RPC_STATUS ndr_update_context_handle(NDR_CCONTEXT *CContext, RPC_BINDING_HANDLE hBinding, const ndr_context_handle *chi)
void WINAPI NDRSContextMarshall2(RPC_BINDING_HANDLE hBinding, NDR_SCONTEXT SContext, void *pBuff, NDR_RUNDOWN userRunDownIn, void *CtxGuard, ULONG Flags)
void WINAPI NDRCContextMarshall(NDR_CCONTEXT CContext, void *pBuff)
static struct context_handle_entry * context_entry_from_guid(LPCGUID uuid)
void WINAPI NDRSContextMarshall(NDR_SCONTEXT SContext, void *pBuff, NDR_RUNDOWN userRunDownIn)
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
RPC_STATUS RpcServerAssoc_FindContextHandle(RpcAssoc *assoc, const UUID *uuid, void *CtxGuard, ULONG Flags, NDR_SCONTEXT *SContext)
Definition: rpc_assoc.c:487
void RpcContextHandle_GetUuid(NDR_SCONTEXT SContext, UUID *uuid)
Definition: rpc_assoc.c:541
RPC_STATUS RpcServerAssoc_UpdateContextHandle(RpcAssoc *assoc, NDR_SCONTEXT SContext, void *CtxGuard, NDR_RUNDOWN rundown_routine)
Definition: rpc_assoc.c:515
BOOL RpcContextHandle_IsGuardCorrect(NDR_SCONTEXT SContext, void *CtxGuard)
Definition: rpc_assoc.c:481
unsigned int RpcServerAssoc_ReleaseContextHandle(RpcAssoc *assoc, NDR_SCONTEXT SContext, BOOL release_lock)
Definition: rpc_assoc.c:563
RPC_STATUS RpcServerAssoc_AllocateContextHandle(RpcAssoc *assoc, void *CtxGuard, NDR_SCONTEXT *SContext)
Definition: rpc_assoc.c:456
RPC_STATUS WINAPI RpcBindingFree(RPC_BINDING_HANDLE *Binding)
Definition: rpc_binding.c:787
RPC_STATUS RPC_ENTRY RpcBindingCopy(RPC_BINDING_HANDLE SourceBinding, RPC_BINDING_HANDLE *DestinationBinding)
Definition: rpc_binding.c:989
void RPCRT4_RemoveThreadContextHandle(NDR_SCONTEXT SContext) DECLSPEC_HIDDEN
Definition: rpcrt4_main.c:995
void RPCRT4_PushThreadContextHandle(NDR_SCONTEXT SContext) DECLSPEC_HIDDEN
Definition: rpcrt4_main.c:980
RPC_BINDING_HANDLE WINAPI I_RpcGetCurrentCallHandle(void)
Definition: rpc_server.c:1743
#define RPC_CONTEXT_HANDLE_DEFAULT_FLAGS
Definition: rpcdcep.h:56
void(__RPC_USER * NDR_RUNDOWN)(void *context)
Definition: rpcndr.h:153
#define RPC_X_SS_CONTEXT_MISMATCH
Definition: rpcnterr.h:39
#define RPC_X_NO_MEMORY
Definition: rpcnterr.h:35
#define RPC_S_OK
Definition: rpcnterr.h:22
int WINAPI UuidIsNil(UUID *Uuid, RPC_STATUS *Status)
Definition: rpcrt4_main.c:268
void DECLSPEC_NORETURN WINAPI RpcRaiseException(RPC_STATUS exception)
Definition: rpcrt4_main.c:188
long RPC_STATUS
Definition: rpc.h:52
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
#define memset(x, y, z)
Definition: compat.h:39
#define TRACE(s)
Definition: solgame.cpp:4
LIST_ENTRY ProcessLocksList
Definition: winbase.h:883
void * userContext
Definition: rpcndr.h:147
struct _RpcAssoc * Assoc
Definition: rpc_binding.h:137
ndr_context_handle wire_data
DWORD magic
struct list entry
RPC_BINDING_HANDLE handle
Definition: ps.c:97
#define LIST_INIT(head)
Definition: queue.h:197
#define DWORD_PTR
Definition: treelist.c:76
uint32_t ULONG
Definition: typedefs.h:59
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define WINAPI
Definition: msvc.h:6
#define RPC_S_INVALID_BINDING
Definition: winerror.h:1013
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList