4 * Copyright 2001 Ove Kåven, TransGaming Technologies
5 * Copyright 2003 Mike Hearn
6 * Copyright 2004 Filip Navara
7 * Copyright 2006 CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include "wine/unicode.h"
39 #include "wine/debug.h"
41 #include "rpc_binding.h"
42 #include "rpc_assoc.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(rpc
);
46 LPSTR
RPCRT4_strndupA(LPCSTR src
, INT slen
)
50 if (!src
) return NULL
;
51 if (slen
== -1) slen
= strlen(src
);
53 s
= HeapAlloc(GetProcessHeap(), 0, len
+1);
59 LPSTR
RPCRT4_strdupWtoA(LPCWSTR src
)
63 if (!src
) return NULL
;
64 len
= WideCharToMultiByte(CP_ACP
, 0, src
, -1, NULL
, 0, NULL
, NULL
);
65 s
= HeapAlloc(GetProcessHeap(), 0, len
);
66 WideCharToMultiByte(CP_ACP
, 0, src
, -1, s
, len
, NULL
, NULL
);
70 LPWSTR
RPCRT4_strdupAtoW(LPCSTR src
)
74 if (!src
) return NULL
;
75 len
= MultiByteToWideChar(CP_ACP
, 0, src
, -1, NULL
, 0);
76 s
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
77 MultiByteToWideChar(CP_ACP
, 0, src
, -1, s
, len
);
81 static LPWSTR
RPCRT4_strndupAtoW(LPCSTR src
, INT slen
)
85 if (!src
) return NULL
;
86 len
= MultiByteToWideChar(CP_ACP
, 0, src
, slen
, NULL
, 0);
87 s
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
88 MultiByteToWideChar(CP_ACP
, 0, src
, slen
, s
, len
);
92 LPWSTR
RPCRT4_strndupW(LPCWSTR src
, INT slen
)
96 if (!src
) return NULL
;
97 if (slen
== -1) slen
= strlenW(src
);
99 s
= HeapAlloc(GetProcessHeap(), 0, (len
+1)*sizeof(WCHAR
));
100 memcpy(s
, src
, len
*sizeof(WCHAR
));
105 void RPCRT4_strfree(LPSTR src
)
107 HeapFree(GetProcessHeap(), 0, src
);
110 static RPC_STATUS
RPCRT4_AllocBinding(RpcBinding
** Binding
, BOOL server
)
112 RpcBinding
* NewBinding
;
114 NewBinding
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcBinding
));
115 NewBinding
->refs
= 1;
116 NewBinding
->server
= server
;
118 *Binding
= NewBinding
;
123 static RPC_STATUS
RPCRT4_CreateBindingA(RpcBinding
** Binding
, BOOL server
, LPCSTR Protseq
)
125 RpcBinding
* NewBinding
;
127 RPCRT4_AllocBinding(&NewBinding
, server
);
128 NewBinding
->Protseq
= RPCRT4_strdupA(Protseq
);
130 TRACE("binding: %p\n", NewBinding
);
131 *Binding
= NewBinding
;
136 static RPC_STATUS
RPCRT4_CreateBindingW(RpcBinding
** Binding
, BOOL server
, LPCWSTR Protseq
)
138 RpcBinding
* NewBinding
;
140 RPCRT4_AllocBinding(&NewBinding
, server
);
141 NewBinding
->Protseq
= RPCRT4_strdupWtoA(Protseq
);
143 TRACE("binding: %p\n", NewBinding
);
144 *Binding
= NewBinding
;
149 static RPC_STATUS
RPCRT4_CompleteBindingA(RpcBinding
* Binding
, LPCSTR NetworkAddr
,
150 LPCSTR Endpoint
, LPCSTR NetworkOptions
)
154 TRACE("(RpcBinding == ^%p, NetworkAddr == %s, EndPoint == %s, NetworkOptions == %s)\n", Binding
,
155 debugstr_a(NetworkAddr
), debugstr_a(Endpoint
), debugstr_a(NetworkOptions
));
157 RPCRT4_strfree(Binding
->NetworkAddr
);
158 Binding
->NetworkAddr
= RPCRT4_strdupA(NetworkAddr
);
159 RPCRT4_strfree(Binding
->Endpoint
);
161 Binding
->Endpoint
= RPCRT4_strdupA(Endpoint
);
163 Binding
->Endpoint
= RPCRT4_strdupA("");
165 HeapFree(GetProcessHeap(), 0, Binding
->NetworkOptions
);
166 Binding
->NetworkOptions
= RPCRT4_strdupAtoW(NetworkOptions
);
167 if (!Binding
->Endpoint
) ERR("out of memory?\n");
169 status
= RPCRT4_GetAssociation(Binding
->Protseq
, Binding
->NetworkAddr
,
170 Binding
->Endpoint
, Binding
->NetworkOptions
,
172 if (status
!= RPC_S_OK
)
178 static RPC_STATUS
RPCRT4_CompleteBindingW(RpcBinding
* Binding
, LPCWSTR NetworkAddr
,
179 LPCWSTR Endpoint
, LPCWSTR NetworkOptions
)
183 TRACE("(RpcBinding == ^%p, NetworkAddr == %s, EndPoint == %s, NetworkOptions == %s)\n", Binding
,
184 debugstr_w(NetworkAddr
), debugstr_w(Endpoint
), debugstr_w(NetworkOptions
));
186 RPCRT4_strfree(Binding
->NetworkAddr
);
187 Binding
->NetworkAddr
= RPCRT4_strdupWtoA(NetworkAddr
);
188 RPCRT4_strfree(Binding
->Endpoint
);
190 Binding
->Endpoint
= RPCRT4_strdupWtoA(Endpoint
);
192 Binding
->Endpoint
= RPCRT4_strdupA("");
194 if (!Binding
->Endpoint
) ERR("out of memory?\n");
195 HeapFree(GetProcessHeap(), 0, Binding
->NetworkOptions
);
196 Binding
->NetworkOptions
= RPCRT4_strdupW(NetworkOptions
);
198 status
= RPCRT4_GetAssociation(Binding
->Protseq
, Binding
->NetworkAddr
,
199 Binding
->Endpoint
, Binding
->NetworkOptions
,
201 if (status
!= RPC_S_OK
)
207 RPC_STATUS
RPCRT4_ResolveBinding(RpcBinding
* Binding
, LPCSTR Endpoint
)
211 TRACE("(RpcBinding == ^%p, EndPoint == \"%s\"\n", Binding
, Endpoint
);
213 RPCRT4_strfree(Binding
->Endpoint
);
214 Binding
->Endpoint
= RPCRT4_strdupA(Endpoint
);
216 RpcAssoc_Release(Binding
->Assoc
);
217 Binding
->Assoc
= NULL
;
218 status
= RPCRT4_GetAssociation(Binding
->Protseq
, Binding
->NetworkAddr
,
219 Binding
->Endpoint
, Binding
->NetworkOptions
,
221 if (status
!= RPC_S_OK
)
227 RPC_STATUS
RPCRT4_SetBindingObject(RpcBinding
* Binding
, const UUID
* ObjectUuid
)
229 TRACE("(*RpcBinding == ^%p, UUID == %s)\n", Binding
, debugstr_guid(ObjectUuid
));
230 if (ObjectUuid
) memcpy(&Binding
->ObjectUuid
, ObjectUuid
, sizeof(UUID
));
231 else UuidCreateNil(&Binding
->ObjectUuid
);
235 RPC_STATUS
RPCRT4_MakeBinding(RpcBinding
** Binding
, RpcConnection
* Connection
)
237 RpcBinding
* NewBinding
;
238 TRACE("(RpcBinding == ^%p, Connection == ^%p)\n", Binding
, Connection
);
240 RPCRT4_AllocBinding(&NewBinding
, Connection
->server
);
241 NewBinding
->Protseq
= RPCRT4_strdupA(rpcrt4_conn_get_name(Connection
));
242 NewBinding
->NetworkAddr
= RPCRT4_strdupA(Connection
->NetworkAddr
);
243 NewBinding
->Endpoint
= RPCRT4_strdupA(Connection
->Endpoint
);
244 NewBinding
->FromConn
= Connection
;
246 TRACE("binding: %p\n", NewBinding
);
247 *Binding
= NewBinding
;
252 RPC_STATUS
RPCRT4_ExportBinding(RpcBinding
** Binding
, RpcBinding
* OldBinding
)
254 InterlockedIncrement(&OldBinding
->refs
);
255 *Binding
= OldBinding
;
259 RPC_STATUS
RPCRT4_DestroyBinding(RpcBinding
* Binding
)
261 if (InterlockedDecrement(&Binding
->refs
))
264 TRACE("binding: %p\n", Binding
);
265 if (Binding
->Assoc
) RpcAssoc_Release(Binding
->Assoc
);
266 RPCRT4_strfree(Binding
->Endpoint
);
267 RPCRT4_strfree(Binding
->NetworkAddr
);
268 RPCRT4_strfree(Binding
->Protseq
);
269 HeapFree(GetProcessHeap(), 0, Binding
->NetworkOptions
);
270 if (Binding
->AuthInfo
) RpcAuthInfo_Release(Binding
->AuthInfo
);
271 if (Binding
->QOS
) RpcQualityOfService_Release(Binding
->QOS
);
272 HeapFree(GetProcessHeap(), 0, Binding
);
276 RPC_STATUS
RPCRT4_OpenBinding(RpcBinding
* Binding
, RpcConnection
** Connection
,
277 const RPC_SYNTAX_IDENTIFIER
*TransferSyntax
,
278 const RPC_SYNTAX_IDENTIFIER
*InterfaceId
)
280 TRACE("(Binding == ^%p)\n", Binding
);
282 if (!Binding
->server
) {
283 return RpcAssoc_GetClientConnection(Binding
->Assoc
, InterfaceId
,
284 TransferSyntax
, Binding
->AuthInfo
, Binding
->QOS
, Connection
);
286 /* we already have a connection with acceptable binding, so use it */
287 if (Binding
->FromConn
) {
288 *Connection
= Binding
->FromConn
;
291 ERR("no connection in binding\n");
292 return RPC_S_INTERNAL_ERROR
;
297 RPC_STATUS
RPCRT4_CloseBinding(RpcBinding
* Binding
, RpcConnection
* Connection
)
299 TRACE("(Binding == ^%p)\n", Binding
);
300 if (!Connection
) return RPC_S_OK
;
301 if (Binding
->server
) {
302 /* don't destroy a connection that is cached in the binding */
303 if (Binding
->FromConn
== Connection
)
305 return RPCRT4_DestroyConnection(Connection
);
308 RpcAssoc_ReleaseIdleConnection(Binding
->Assoc
, Connection
);
313 /* utility functions for string composing and parsing */
314 static unsigned RPCRT4_strcopyA(LPSTR data
, LPCSTR src
)
316 unsigned len
= strlen(src
);
317 memcpy(data
, src
, len
*sizeof(CHAR
));
321 static unsigned RPCRT4_strcopyW(LPWSTR data
, LPCWSTR src
)
323 unsigned len
= strlenW(src
);
324 memcpy(data
, src
, len
*sizeof(WCHAR
));
328 static LPSTR
RPCRT4_strconcatA(LPSTR dst
, LPCSTR src
)
330 DWORD len
= strlen(dst
), slen
= strlen(src
);
331 LPSTR ndst
= HeapReAlloc(GetProcessHeap(), 0, dst
, (len
+slen
+2)*sizeof(CHAR
));
334 HeapFree(GetProcessHeap(), 0, dst
);
338 memcpy(ndst
+len
+1, src
, slen
+1);
342 static LPWSTR
RPCRT4_strconcatW(LPWSTR dst
, LPCWSTR src
)
344 DWORD len
= strlenW(dst
), slen
= strlenW(src
);
345 LPWSTR ndst
= HeapReAlloc(GetProcessHeap(), 0, dst
, (len
+slen
+2)*sizeof(WCHAR
));
348 HeapFree(GetProcessHeap(), 0, dst
);
352 memcpy(ndst
+len
+1, src
, (slen
+1)*sizeof(WCHAR
));
357 /***********************************************************************
358 * RpcStringBindingComposeA (RPCRT4.@)
360 RPC_STATUS WINAPI
RpcStringBindingComposeA(RPC_CSTR ObjUuid
, RPC_CSTR Protseq
,
361 RPC_CSTR NetworkAddr
, RPC_CSTR Endpoint
,
362 RPC_CSTR Options
, RPC_CSTR
*StringBinding
)
367 TRACE( "(%s,%s,%s,%s,%s,%p)\n",
368 debugstr_a( (char*)ObjUuid
), debugstr_a( (char*)Protseq
),
369 debugstr_a( (char*)NetworkAddr
), debugstr_a( (char*)Endpoint
),
370 debugstr_a( (char*)Options
), StringBinding
);
372 if (ObjUuid
&& *ObjUuid
) len
+= strlen((char*)ObjUuid
) + 1;
373 if (Protseq
&& *Protseq
) len
+= strlen((char*)Protseq
) + 1;
374 if (NetworkAddr
&& *NetworkAddr
) len
+= strlen((char*)NetworkAddr
);
375 if (Endpoint
&& *Endpoint
) len
+= strlen((char*)Endpoint
) + 2;
376 if (Options
&& *Options
) len
+= strlen((char*)Options
) + 2;
378 data
= HeapAlloc(GetProcessHeap(), 0, len
);
379 *StringBinding
= (unsigned char*)data
;
381 if (ObjUuid
&& *ObjUuid
) {
382 data
+= RPCRT4_strcopyA(data
, (char*)ObjUuid
);
385 if (Protseq
&& *Protseq
) {
386 data
+= RPCRT4_strcopyA(data
, (char*)Protseq
);
389 if (NetworkAddr
&& *NetworkAddr
)
390 data
+= RPCRT4_strcopyA(data
, (char*)NetworkAddr
);
392 if ((Endpoint
&& *Endpoint
) ||
393 (Options
&& *Options
)) {
395 if (Endpoint
&& *Endpoint
) {
396 data
+= RPCRT4_strcopyA(data
, (char*)Endpoint
);
397 if (Options
&& *Options
) *data
++ = ',';
399 if (Options
&& *Options
) {
400 data
+= RPCRT4_strcopyA(data
, (char*)Options
);
409 /***********************************************************************
410 * RpcStringBindingComposeW (RPCRT4.@)
412 RPC_STATUS WINAPI
RpcStringBindingComposeW( RPC_WSTR ObjUuid
, RPC_WSTR Protseq
,
413 RPC_WSTR NetworkAddr
, RPC_WSTR Endpoint
,
414 RPC_WSTR Options
, RPC_WSTR
* StringBinding
)
419 TRACE("(%s,%s,%s,%s,%s,%p)\n",
420 debugstr_w( ObjUuid
), debugstr_w( Protseq
),
421 debugstr_w( NetworkAddr
), debugstr_w( Endpoint
),
422 debugstr_w( Options
), StringBinding
);
424 if (ObjUuid
&& *ObjUuid
) len
+= strlenW(ObjUuid
) + 1;
425 if (Protseq
&& *Protseq
) len
+= strlenW(Protseq
) + 1;
426 if (NetworkAddr
&& *NetworkAddr
) len
+= strlenW(NetworkAddr
);
427 if (Endpoint
&& *Endpoint
) len
+= strlenW(Endpoint
) + 2;
428 if (Options
&& *Options
) len
+= strlenW(Options
) + 2;
430 data
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
431 *StringBinding
= data
;
433 if (ObjUuid
&& *ObjUuid
) {
434 data
+= RPCRT4_strcopyW(data
, ObjUuid
);
437 if (Protseq
&& *Protseq
) {
438 data
+= RPCRT4_strcopyW(data
, Protseq
);
441 if (NetworkAddr
&& *NetworkAddr
) {
442 data
+= RPCRT4_strcopyW(data
, NetworkAddr
);
444 if ((Endpoint
&& *Endpoint
) ||
445 (Options
&& *Options
)) {
447 if (Endpoint
&& *Endpoint
) {
448 data
+= RPCRT4_strcopyW(data
, Endpoint
);
449 if (Options
&& *Options
) *data
++ = ',';
451 if (Options
&& *Options
) {
452 data
+= RPCRT4_strcopyW(data
, Options
);
462 /***********************************************************************
463 * RpcStringBindingParseA (RPCRT4.@)
465 RPC_STATUS WINAPI
RpcStringBindingParseA( RPC_CSTR StringBinding
, RPC_CSTR
*ObjUuid
,
466 RPC_CSTR
*Protseq
, RPC_CSTR
*NetworkAddr
,
467 RPC_CSTR
*Endpoint
, RPC_CSTR
*Options
)
470 static const char ep_opt
[] = "endpoint=";
472 TRACE("(%s,%p,%p,%p,%p,%p)\n", debugstr_a((char*)StringBinding
),
473 ObjUuid
, Protseq
, NetworkAddr
, Endpoint
, Options
);
475 if (ObjUuid
) *ObjUuid
= NULL
;
476 if (Protseq
) *Protseq
= NULL
;
477 if (NetworkAddr
) *NetworkAddr
= NULL
;
478 if (Endpoint
) *Endpoint
= NULL
;
479 if (Options
) *Options
= NULL
;
481 data
= (char*) StringBinding
;
483 next
= strchr(data
, '@');
485 if (ObjUuid
) *ObjUuid
= (unsigned char*)RPCRT4_strndupA(data
, next
- data
);
489 next
= strchr(data
, ':');
491 if (Protseq
) *Protseq
= (unsigned char*)RPCRT4_strndupA(data
, next
- data
);
495 next
= strchr(data
, '[');
499 if (NetworkAddr
) *NetworkAddr
= (unsigned char*)RPCRT4_strndupA(data
, next
- data
);
501 close
= strchr(data
, ']');
502 if (!close
) goto fail
;
504 /* tokenize options */
505 while (data
< close
) {
506 next
= strchr(data
, ',');
507 if (!next
|| next
> close
) next
= close
;
508 /* FIXME: this is kind of inefficient */
509 opt
= RPCRT4_strndupA(data
, next
- data
);
513 next
= strchr(opt
, '=');
515 /* not an option, must be an endpoint */
516 if (*Endpoint
) goto fail
;
517 *Endpoint
= (unsigned char*) opt
;
519 if (strncmp(opt
, ep_opt
, strlen(ep_opt
)) == 0) {
520 /* endpoint option */
521 if (*Endpoint
) goto fail
;
522 *Endpoint
= (unsigned char*) RPCRT4_strdupA(next
+1);
523 HeapFree(GetProcessHeap(), 0, opt
);
527 /* FIXME: this is kind of inefficient */
528 *Options
= (unsigned char*) RPCRT4_strconcatA( (char*)*Options
, opt
);
529 HeapFree(GetProcessHeap(), 0, opt
);
531 *Options
= (unsigned char*) opt
;
537 if (*data
) goto fail
;
539 else if (NetworkAddr
)
540 *NetworkAddr
= (unsigned char*)RPCRT4_strdupA(data
);
545 if (ObjUuid
) RpcStringFreeA((unsigned char**)ObjUuid
);
546 if (Protseq
) RpcStringFreeA((unsigned char**)Protseq
);
547 if (NetworkAddr
) RpcStringFreeA((unsigned char**)NetworkAddr
);
548 if (Endpoint
) RpcStringFreeA((unsigned char**)Endpoint
);
549 if (Options
) RpcStringFreeA((unsigned char**)Options
);
550 return RPC_S_INVALID_STRING_BINDING
;
553 /***********************************************************************
554 * RpcStringBindingParseW (RPCRT4.@)
556 RPC_STATUS WINAPI
RpcStringBindingParseW( RPC_WSTR StringBinding
, RPC_WSTR
*ObjUuid
,
557 RPC_WSTR
*Protseq
, RPC_WSTR
*NetworkAddr
,
558 RPC_WSTR
*Endpoint
, RPC_WSTR
*Options
)
561 static const WCHAR ep_opt
[] = {'e','n','d','p','o','i','n','t','=',0};
563 TRACE("(%s,%p,%p,%p,%p,%p)\n", debugstr_w(StringBinding
),
564 ObjUuid
, Protseq
, NetworkAddr
, Endpoint
, Options
);
566 if (ObjUuid
) *ObjUuid
= NULL
;
567 if (Protseq
) *Protseq
= NULL
;
568 if (NetworkAddr
) *NetworkAddr
= NULL
;
569 if (Endpoint
) *Endpoint
= NULL
;
570 if (Options
) *Options
= NULL
;
572 data
= StringBinding
;
574 next
= strchrW(data
, '@');
576 if (ObjUuid
) *ObjUuid
= RPCRT4_strndupW(data
, next
- data
);
580 next
= strchrW(data
, ':');
582 if (Protseq
) *Protseq
= RPCRT4_strndupW(data
, next
- data
);
586 next
= strchrW(data
, '[');
590 if (NetworkAddr
) *NetworkAddr
= RPCRT4_strndupW(data
, next
- data
);
592 close
= strchrW(data
, ']');
593 if (!close
) goto fail
;
595 /* tokenize options */
596 while (data
< close
) {
597 next
= strchrW(data
, ',');
598 if (!next
|| next
> close
) next
= close
;
599 /* FIXME: this is kind of inefficient */
600 opt
= RPCRT4_strndupW(data
, next
- data
);
604 next
= strchrW(opt
, '=');
606 /* not an option, must be an endpoint */
607 if (*Endpoint
) goto fail
;
610 if (strncmpW(opt
, ep_opt
, strlenW(ep_opt
)) == 0) {
611 /* endpoint option */
612 if (*Endpoint
) goto fail
;
613 *Endpoint
= RPCRT4_strdupW(next
+1);
614 HeapFree(GetProcessHeap(), 0, opt
);
618 /* FIXME: this is kind of inefficient */
619 *Options
= RPCRT4_strconcatW(*Options
, opt
);
620 HeapFree(GetProcessHeap(), 0, opt
);
628 if (*data
) goto fail
;
629 } else if (NetworkAddr
)
630 *NetworkAddr
= RPCRT4_strdupW(data
);
635 if (ObjUuid
) RpcStringFreeW(ObjUuid
);
636 if (Protseq
) RpcStringFreeW(Protseq
);
637 if (NetworkAddr
) RpcStringFreeW(NetworkAddr
);
638 if (Endpoint
) RpcStringFreeW(Endpoint
);
639 if (Options
) RpcStringFreeW(Options
);
640 return RPC_S_INVALID_STRING_BINDING
;
643 /***********************************************************************
644 * RpcBindingFree (RPCRT4.@)
646 RPC_STATUS WINAPI
RpcBindingFree( RPC_BINDING_HANDLE
* Binding
)
649 TRACE("(%p) = %p\n", Binding
, *Binding
);
650 status
= RPCRT4_DestroyBinding(*Binding
);
651 if (status
== RPC_S_OK
) *Binding
= 0;
655 /***********************************************************************
656 * RpcBindingVectorFree (RPCRT4.@)
658 RPC_STATUS WINAPI
RpcBindingVectorFree( RPC_BINDING_VECTOR
** BindingVector
)
663 TRACE("(%p)\n", BindingVector
);
664 for (c
=0; c
<(*BindingVector
)->Count
; c
++) {
665 status
= RpcBindingFree(&(*BindingVector
)->BindingH
[c
]);
667 HeapFree(GetProcessHeap(), 0, *BindingVector
);
668 *BindingVector
= NULL
;
672 /***********************************************************************
673 * RpcBindingInqObject (RPCRT4.@)
675 RPC_STATUS WINAPI
RpcBindingInqObject( RPC_BINDING_HANDLE Binding
, UUID
* ObjectUuid
)
677 RpcBinding
* bind
= (RpcBinding
*)Binding
;
679 TRACE("(%p,%p) = %s\n", Binding
, ObjectUuid
, debugstr_guid(&bind
->ObjectUuid
));
680 memcpy(ObjectUuid
, &bind
->ObjectUuid
, sizeof(UUID
));
684 /***********************************************************************
685 * RpcBindingSetObject (RPCRT4.@)
687 RPC_STATUS WINAPI
RpcBindingSetObject( RPC_BINDING_HANDLE Binding
, UUID
* ObjectUuid
)
689 RpcBinding
* bind
= (RpcBinding
*)Binding
;
691 TRACE("(%p,%s)\n", Binding
, debugstr_guid(ObjectUuid
));
692 if (bind
->server
) return RPC_S_WRONG_KIND_OF_BINDING
;
693 return RPCRT4_SetBindingObject(Binding
, ObjectUuid
);
696 /***********************************************************************
697 * RpcBindingFromStringBindingA (RPCRT4.@)
699 RPC_STATUS WINAPI
RpcBindingFromStringBindingA( RPC_CSTR StringBinding
, RPC_BINDING_HANDLE
* Binding
)
702 RpcBinding
* bind
= NULL
;
703 RPC_CSTR ObjectUuid
, Protseq
, NetworkAddr
, Endpoint
, Options
;
706 TRACE("(%s,%p)\n", debugstr_a((char*)StringBinding
), Binding
);
708 ret
= RpcStringBindingParseA(StringBinding
, &ObjectUuid
, &Protseq
,
709 &NetworkAddr
, &Endpoint
, &Options
);
710 if (ret
!= RPC_S_OK
) return ret
;
712 ret
= UuidFromStringA(ObjectUuid
, &Uuid
);
715 ret
= RPCRT4_CreateBindingA(&bind
, FALSE
, (char*)Protseq
);
717 ret
= RPCRT4_SetBindingObject(bind
, &Uuid
);
719 ret
= RPCRT4_CompleteBindingA(bind
, (char*)NetworkAddr
, (char*)Endpoint
, (char*)Options
);
721 RpcStringFreeA((unsigned char**)&Options
);
722 RpcStringFreeA((unsigned char**)&Endpoint
);
723 RpcStringFreeA((unsigned char**)&NetworkAddr
);
724 RpcStringFreeA((unsigned char**)&Protseq
);
725 RpcStringFreeA((unsigned char**)&ObjectUuid
);
728 *Binding
= (RPC_BINDING_HANDLE
)bind
;
730 RPCRT4_DestroyBinding(bind
);
735 /***********************************************************************
736 * RpcBindingFromStringBindingW (RPCRT4.@)
738 RPC_STATUS WINAPI
RpcBindingFromStringBindingW( RPC_WSTR StringBinding
, RPC_BINDING_HANDLE
* Binding
)
741 RpcBinding
* bind
= NULL
;
742 RPC_WSTR ObjectUuid
, Protseq
, NetworkAddr
, Endpoint
, Options
;
745 TRACE("(%s,%p)\n", debugstr_w(StringBinding
), Binding
);
747 ret
= RpcStringBindingParseW(StringBinding
, &ObjectUuid
, &Protseq
,
748 &NetworkAddr
, &Endpoint
, &Options
);
749 if (ret
!= RPC_S_OK
) return ret
;
751 ret
= UuidFromStringW(ObjectUuid
, &Uuid
);
754 ret
= RPCRT4_CreateBindingW(&bind
, FALSE
, Protseq
);
756 ret
= RPCRT4_SetBindingObject(bind
, &Uuid
);
758 ret
= RPCRT4_CompleteBindingW(bind
, NetworkAddr
, Endpoint
, Options
);
760 RpcStringFreeW(&Options
);
761 RpcStringFreeW(&Endpoint
);
762 RpcStringFreeW(&NetworkAddr
);
763 RpcStringFreeW(&Protseq
);
764 RpcStringFreeW(&ObjectUuid
);
767 *Binding
= (RPC_BINDING_HANDLE
)bind
;
769 RPCRT4_DestroyBinding(bind
);
774 /***********************************************************************
775 * RpcBindingToStringBindingA (RPCRT4.@)
777 RPC_STATUS WINAPI
RpcBindingToStringBindingA( RPC_BINDING_HANDLE Binding
, RPC_CSTR
*StringBinding
)
780 RpcBinding
* bind
= (RpcBinding
*)Binding
;
783 TRACE("(%p,%p)\n", Binding
, StringBinding
);
785 ret
= UuidToStringA(&bind
->ObjectUuid
, &ObjectUuid
);
786 if (ret
!= RPC_S_OK
) return ret
;
788 ret
= RpcStringBindingComposeA(ObjectUuid
, (unsigned char*)bind
->Protseq
, (unsigned char*) bind
->NetworkAddr
,
789 (unsigned char*) bind
->Endpoint
, NULL
, StringBinding
);
791 RpcStringFreeA(&ObjectUuid
);
796 /***********************************************************************
797 * RpcBindingToStringBindingW (RPCRT4.@)
799 RPC_STATUS WINAPI
RpcBindingToStringBindingW( RPC_BINDING_HANDLE Binding
, RPC_WSTR
*StringBinding
)
802 unsigned char *str
= NULL
;
803 TRACE("(%p,%p)\n", Binding
, StringBinding
);
804 ret
= RpcBindingToStringBindingA(Binding
, &str
);
805 *StringBinding
= RPCRT4_strdupAtoW((char*)str
);
806 RpcStringFreeA((unsigned char**)&str
);
810 /***********************************************************************
811 * I_RpcBindingSetAsync (RPCRT4.@)
813 * Exists in win9x and winNT, but with different number of arguments
814 * (9x version has 3 arguments, NT has 2).
816 RPC_STATUS WINAPI
I_RpcBindingSetAsync( RPC_BINDING_HANDLE Binding
, RPC_BLOCKING_FN BlockingFn
)
818 RpcBinding
* bind
= (RpcBinding
*)Binding
;
820 TRACE( "(%p,%p): stub\n", Binding
, BlockingFn
);
822 bind
->BlockingFn
= BlockingFn
;
827 /***********************************************************************
828 * RpcBindingCopy (RPCRT4.@)
830 RPC_STATUS RPC_ENTRY
RpcBindingCopy(
831 RPC_BINDING_HANDLE SourceBinding
,
832 RPC_BINDING_HANDLE
* DestinationBinding
)
834 RpcBinding
*DestBinding
;
835 RpcBinding
*SrcBinding
= (RpcBinding
*)SourceBinding
;
838 TRACE("(%p, %p)\n", SourceBinding
, DestinationBinding
);
840 status
= RPCRT4_AllocBinding(&DestBinding
, SrcBinding
->server
);
841 if (status
!= RPC_S_OK
) return status
;
843 DestBinding
->ObjectUuid
= SrcBinding
->ObjectUuid
;
844 DestBinding
->BlockingFn
= SrcBinding
->BlockingFn
;
845 DestBinding
->Protseq
= RPCRT4_strndupA(SrcBinding
->Protseq
, -1);
846 DestBinding
->NetworkAddr
= RPCRT4_strndupA(SrcBinding
->NetworkAddr
, -1);
847 DestBinding
->Endpoint
= RPCRT4_strndupA(SrcBinding
->Endpoint
, -1);
848 DestBinding
->NetworkOptions
= RPCRT4_strdupW(SrcBinding
->NetworkOptions
);
849 if (SrcBinding
->Assoc
) SrcBinding
->Assoc
->refs
++;
850 DestBinding
->Assoc
= SrcBinding
->Assoc
;
852 if (SrcBinding
->AuthInfo
) RpcAuthInfo_AddRef(SrcBinding
->AuthInfo
);
853 DestBinding
->AuthInfo
= SrcBinding
->AuthInfo
;
854 if (SrcBinding
->QOS
) RpcQualityOfService_AddRef(SrcBinding
->QOS
);
855 DestBinding
->QOS
= SrcBinding
->QOS
;
857 *DestinationBinding
= DestBinding
;
861 /***********************************************************************
862 * RpcImpersonateClient (RPCRT4.@)
864 * Impersonates the client connected via a binding handle so that security
865 * checks are done in the context of the client.
868 * BindingHandle [I] Handle to the binding to the client.
872 * Failure: RPC_STATUS value.
876 * If BindingHandle is NULL then the function impersonates the client
877 * connected to the binding handle of the current thread.
879 RPC_STATUS WINAPI
RpcImpersonateClient(RPC_BINDING_HANDLE BindingHandle
)
881 FIXME("(%p): stub\n", BindingHandle
);
882 ImpersonateSelf(SecurityImpersonation
);
886 /***********************************************************************
887 * RpcRevertToSelfEx (RPCRT4.@)
889 * Stops impersonating the client connected to the binding handle so that security
890 * checks are no longer done in the context of the client.
893 * BindingHandle [I] Handle to the binding to the client.
897 * Failure: RPC_STATUS value.
901 * If BindingHandle is NULL then the function stops impersonating the client
902 * connected to the binding handle of the current thread.
904 RPC_STATUS WINAPI
RpcRevertToSelfEx(RPC_BINDING_HANDLE BindingHandle
)
906 FIXME("(%p): stub\n", BindingHandle
);
910 static inline BOOL
has_nt_auth_identity(ULONG AuthnLevel
)
914 case RPC_C_AUTHN_GSS_NEGOTIATE
:
915 case RPC_C_AUTHN_WINNT
:
916 case RPC_C_AUTHN_GSS_KERBEROS
:
923 static RPC_STATUS
RpcAuthInfo_Create(ULONG AuthnLevel
, ULONG AuthnSvc
,
924 CredHandle cred
, TimeStamp exp
,
926 RPC_AUTH_IDENTITY_HANDLE identity
,
929 RpcAuthInfo
*AuthInfo
= HeapAlloc(GetProcessHeap(), 0, sizeof(*AuthInfo
));
931 return ERROR_OUTOFMEMORY
;
934 AuthInfo
->AuthnLevel
= AuthnLevel
;
935 AuthInfo
->AuthnSvc
= AuthnSvc
;
936 AuthInfo
->cred
= cred
;
938 AuthInfo
->cbMaxToken
= cbMaxToken
;
939 AuthInfo
->identity
= identity
;
940 AuthInfo
->server_principal_name
= NULL
;
942 /* duplicate the SEC_WINNT_AUTH_IDENTITY structure, if applicable, to
943 * enable better matching in RpcAuthInfo_IsEqual */
944 if (identity
&& has_nt_auth_identity(AuthnSvc
))
946 const SEC_WINNT_AUTH_IDENTITY_W
*nt_identity
= identity
;
947 AuthInfo
->nt_identity
= HeapAlloc(GetProcessHeap(), 0, sizeof(*AuthInfo
->nt_identity
));
948 if (!AuthInfo
->nt_identity
)
950 HeapFree(GetProcessHeap(), 0, AuthInfo
);
951 return ERROR_OUTOFMEMORY
;
954 AuthInfo
->nt_identity
->Flags
= SEC_WINNT_AUTH_IDENTITY_UNICODE
;
955 if (nt_identity
->Flags
& SEC_WINNT_AUTH_IDENTITY_UNICODE
)
956 AuthInfo
->nt_identity
->User
= RPCRT4_strndupW(nt_identity
->User
, nt_identity
->UserLength
);
958 AuthInfo
->nt_identity
->User
= RPCRT4_strndupAtoW((const char *)nt_identity
->User
, nt_identity
->UserLength
);
959 AuthInfo
->nt_identity
->UserLength
= nt_identity
->UserLength
;
960 if (nt_identity
->Flags
& SEC_WINNT_AUTH_IDENTITY_UNICODE
)
961 AuthInfo
->nt_identity
->Domain
= RPCRT4_strndupW(nt_identity
->Domain
, nt_identity
->DomainLength
);
963 AuthInfo
->nt_identity
->Domain
= RPCRT4_strndupAtoW((const char *)nt_identity
->Domain
, nt_identity
->DomainLength
);
964 AuthInfo
->nt_identity
->DomainLength
= nt_identity
->DomainLength
;
965 if (nt_identity
->Flags
& SEC_WINNT_AUTH_IDENTITY_UNICODE
)
966 AuthInfo
->nt_identity
->Password
= RPCRT4_strndupW(nt_identity
->Password
, nt_identity
->PasswordLength
);
968 AuthInfo
->nt_identity
->Password
= RPCRT4_strndupAtoW((const char *)nt_identity
->Password
, nt_identity
->PasswordLength
);
969 AuthInfo
->nt_identity
->PasswordLength
= nt_identity
->PasswordLength
;
971 if (!AuthInfo
->nt_identity
->User
||
972 !AuthInfo
->nt_identity
->Domain
||
973 !AuthInfo
->nt_identity
->Password
)
975 HeapFree(GetProcessHeap(), 0, AuthInfo
->nt_identity
->User
);
976 HeapFree(GetProcessHeap(), 0, AuthInfo
->nt_identity
->Domain
);
977 HeapFree(GetProcessHeap(), 0, AuthInfo
->nt_identity
->Password
);
978 HeapFree(GetProcessHeap(), 0, AuthInfo
->nt_identity
);
979 HeapFree(GetProcessHeap(), 0, AuthInfo
);
980 return ERROR_OUTOFMEMORY
;
984 AuthInfo
->nt_identity
= NULL
;
989 ULONG
RpcAuthInfo_AddRef(RpcAuthInfo
*AuthInfo
)
991 return InterlockedIncrement(&AuthInfo
->refs
);
994 ULONG
RpcAuthInfo_Release(RpcAuthInfo
*AuthInfo
)
996 ULONG refs
= InterlockedDecrement(&AuthInfo
->refs
);
1000 FreeCredentialsHandle(&AuthInfo
->cred
);
1001 if (AuthInfo
->nt_identity
)
1003 HeapFree(GetProcessHeap(), 0, AuthInfo
->nt_identity
->User
);
1004 HeapFree(GetProcessHeap(), 0, AuthInfo
->nt_identity
->Domain
);
1005 HeapFree(GetProcessHeap(), 0, AuthInfo
->nt_identity
->Password
);
1006 HeapFree(GetProcessHeap(), 0, AuthInfo
->nt_identity
);
1008 HeapFree(GetProcessHeap(), 0, AuthInfo
->server_principal_name
);
1009 HeapFree(GetProcessHeap(), 0, AuthInfo
);
1015 BOOL
RpcAuthInfo_IsEqual(const RpcAuthInfo
*AuthInfo1
, const RpcAuthInfo
*AuthInfo2
)
1017 if (AuthInfo1
== AuthInfo2
)
1020 if (!AuthInfo1
|| !AuthInfo2
)
1023 if ((AuthInfo1
->AuthnLevel
!= AuthInfo2
->AuthnLevel
) ||
1024 (AuthInfo1
->AuthnSvc
!= AuthInfo2
->AuthnSvc
))
1027 if (AuthInfo1
->identity
== AuthInfo2
->identity
)
1030 if (!AuthInfo1
->identity
|| !AuthInfo2
->identity
)
1033 if (has_nt_auth_identity(AuthInfo1
->AuthnSvc
))
1035 const SEC_WINNT_AUTH_IDENTITY_W
*identity1
= AuthInfo1
->nt_identity
;
1036 const SEC_WINNT_AUTH_IDENTITY_W
*identity2
= AuthInfo2
->nt_identity
;
1037 /* compare user names */
1038 if (identity1
->UserLength
!= identity2
->UserLength
||
1039 memcmp(identity1
->User
, identity2
->User
, identity1
->UserLength
))
1041 /* compare domain names */
1042 if (identity1
->DomainLength
!= identity2
->DomainLength
||
1043 memcmp(identity1
->Domain
, identity2
->Domain
, identity1
->DomainLength
))
1045 /* compare passwords */
1046 if (identity1
->PasswordLength
!= identity2
->PasswordLength
||
1047 memcmp(identity1
->Password
, identity2
->Password
, identity1
->PasswordLength
))
1056 static RPC_STATUS
RpcQualityOfService_Create(const RPC_SECURITY_QOS
*qos_src
, BOOL unicode
, RpcQualityOfService
**qos_dst
)
1058 RpcQualityOfService
*qos
= HeapAlloc(GetProcessHeap(), 0, sizeof(*qos
));
1061 return RPC_S_OUT_OF_RESOURCES
;
1064 qos
->qos
= HeapAlloc(GetProcessHeap(), 0, sizeof(*qos
->qos
));
1065 if (!qos
->qos
) goto error
;
1066 qos
->qos
->Version
= qos_src
->Version
;
1067 qos
->qos
->Capabilities
= qos_src
->Capabilities
;
1068 qos
->qos
->IdentityTracking
= qos_src
->IdentityTracking
;
1069 qos
->qos
->ImpersonationType
= qos_src
->ImpersonationType
;
1070 qos
->qos
->AdditionalSecurityInfoType
= 0;
1072 if (qos_src
->Version
>= 2)
1074 const RPC_SECURITY_QOS_V2_W
*qos_src2
= (const RPC_SECURITY_QOS_V2_W
*)qos_src
;
1075 qos
->qos
->AdditionalSecurityInfoType
= qos_src2
->AdditionalSecurityInfoType
;
1076 if (qos_src2
->AdditionalSecurityInfoType
== RPC_C_AUTHN_INFO_TYPE_HTTP
)
1078 const RPC_HTTP_TRANSPORT_CREDENTIALS_W
*http_credentials_src
= qos_src2
->u
.HttpCredentials
;
1079 RPC_HTTP_TRANSPORT_CREDENTIALS_W
*http_credentials_dst
;
1081 http_credentials_dst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*http_credentials_dst
));
1082 qos
->qos
->u
.HttpCredentials
= http_credentials_dst
;
1083 if (!http_credentials_dst
) goto error
;
1084 http_credentials_dst
->TransportCredentials
= NULL
;
1085 http_credentials_dst
->Flags
= http_credentials_src
->Flags
;
1086 http_credentials_dst
->AuthenticationTarget
= http_credentials_src
->AuthenticationTarget
;
1087 http_credentials_dst
->NumberOfAuthnSchemes
= http_credentials_src
->NumberOfAuthnSchemes
;
1088 http_credentials_dst
->AuthnSchemes
= NULL
;
1089 http_credentials_dst
->ServerCertificateSubject
= NULL
;
1090 if (http_credentials_src
->TransportCredentials
)
1092 SEC_WINNT_AUTH_IDENTITY_W
*cred_dst
;
1093 cred_dst
= http_credentials_dst
->TransportCredentials
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*cred_dst
));
1094 if (!cred_dst
) goto error
;
1095 cred_dst
->Flags
= SEC_WINNT_AUTH_IDENTITY_UNICODE
;
1098 const SEC_WINNT_AUTH_IDENTITY_W
*cred_src
= http_credentials_src
->TransportCredentials
;
1099 cred_dst
->UserLength
= cred_src
->UserLength
;
1100 cred_dst
->PasswordLength
= cred_src
->PasswordLength
;
1101 cred_dst
->DomainLength
= cred_src
->DomainLength
;
1102 cred_dst
->User
= RPCRT4_strndupW(cred_src
->User
, cred_src
->UserLength
);
1103 cred_dst
->Password
= RPCRT4_strndupW(cred_src
->Password
, cred_src
->PasswordLength
);
1104 cred_dst
->Domain
= RPCRT4_strndupW(cred_src
->Domain
, cred_src
->DomainLength
);
1108 const SEC_WINNT_AUTH_IDENTITY_A
*cred_src
= (const SEC_WINNT_AUTH_IDENTITY_A
*)http_credentials_src
->TransportCredentials
;
1109 cred_dst
->UserLength
= MultiByteToWideChar(CP_ACP
, 0, (char *)cred_src
->User
, cred_src
->UserLength
, NULL
, 0);
1110 cred_dst
->DomainLength
= MultiByteToWideChar(CP_ACP
, 0, (char *)cred_src
->Domain
, cred_src
->DomainLength
, NULL
, 0);
1111 cred_dst
->PasswordLength
= MultiByteToWideChar(CP_ACP
, 0, (char *)cred_src
->Password
, cred_src
->PasswordLength
, NULL
, 0);
1112 cred_dst
->User
= HeapAlloc(GetProcessHeap(), 0, cred_dst
->UserLength
* sizeof(WCHAR
));
1113 cred_dst
->Password
= HeapAlloc(GetProcessHeap(), 0, cred_dst
->PasswordLength
* sizeof(WCHAR
));
1114 cred_dst
->Domain
= HeapAlloc(GetProcessHeap(), 0, cred_dst
->DomainLength
* sizeof(WCHAR
));
1115 if (!cred_dst
|| !cred_dst
->Password
|| !cred_dst
->Domain
) goto error
;
1116 MultiByteToWideChar(CP_ACP
, 0, (char *)cred_src
->User
, cred_src
->UserLength
, cred_dst
->User
, cred_dst
->UserLength
);
1117 MultiByteToWideChar(CP_ACP
, 0, (char *)cred_src
->Domain
, cred_src
->DomainLength
, cred_dst
->Domain
, cred_dst
->DomainLength
);
1118 MultiByteToWideChar(CP_ACP
, 0, (char *)cred_src
->Password
, cred_src
->PasswordLength
, cred_dst
->Password
, cred_dst
->PasswordLength
);
1121 if (http_credentials_src
->NumberOfAuthnSchemes
)
1123 http_credentials_dst
->AuthnSchemes
= HeapAlloc(GetProcessHeap(), 0, http_credentials_src
->NumberOfAuthnSchemes
* sizeof(*http_credentials_dst
->AuthnSchemes
));
1124 if (!http_credentials_dst
->AuthnSchemes
) goto error
;
1125 memcpy(http_credentials_dst
->AuthnSchemes
, http_credentials_src
->AuthnSchemes
, http_credentials_src
->NumberOfAuthnSchemes
* sizeof(*http_credentials_dst
->AuthnSchemes
));
1127 if (http_credentials_src
->ServerCertificateSubject
)
1130 http_credentials_dst
->ServerCertificateSubject
=
1131 RPCRT4_strndupW(http_credentials_src
->ServerCertificateSubject
,
1132 strlenW(http_credentials_src
->ServerCertificateSubject
));
1134 http_credentials_dst
->ServerCertificateSubject
=
1135 RPCRT4_strdupAtoW((char *)http_credentials_src
->ServerCertificateSubject
);
1136 if (!http_credentials_dst
->ServerCertificateSubject
) goto error
;
1146 if (qos
->qos
->AdditionalSecurityInfoType
== RPC_C_AUTHN_INFO_TYPE_HTTP
&&
1147 qos
->qos
->u
.HttpCredentials
)
1149 if (qos
->qos
->u
.HttpCredentials
->TransportCredentials
)
1151 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->TransportCredentials
->User
);
1152 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->TransportCredentials
->Domain
);
1153 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->TransportCredentials
->Password
);
1154 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->TransportCredentials
);
1156 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->AuthnSchemes
);
1157 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->ServerCertificateSubject
);
1158 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
);
1160 HeapFree(GetProcessHeap(), 0, qos
->qos
);
1162 HeapFree(GetProcessHeap(), 0, qos
);
1163 return RPC_S_OUT_OF_RESOURCES
;
1166 ULONG
RpcQualityOfService_AddRef(RpcQualityOfService
*qos
)
1168 return InterlockedIncrement(&qos
->refs
);
1171 ULONG
RpcQualityOfService_Release(RpcQualityOfService
*qos
)
1173 ULONG refs
= InterlockedDecrement(&qos
->refs
);
1177 if (qos
->qos
->AdditionalSecurityInfoType
== RPC_C_AUTHN_INFO_TYPE_HTTP
)
1179 if (qos
->qos
->u
.HttpCredentials
->TransportCredentials
)
1181 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->TransportCredentials
->User
);
1182 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->TransportCredentials
->Domain
);
1183 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->TransportCredentials
->Password
);
1184 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->TransportCredentials
);
1186 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->AuthnSchemes
);
1187 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->ServerCertificateSubject
);
1188 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
);
1190 HeapFree(GetProcessHeap(), 0, qos
->qos
);
1191 HeapFree(GetProcessHeap(), 0, qos
);
1196 BOOL
RpcQualityOfService_IsEqual(const RpcQualityOfService
*qos1
, const RpcQualityOfService
*qos2
)
1204 TRACE("qos1 = { %ld %ld %ld %ld }, qos2 = { %ld %ld %ld %ld }\n",
1205 qos1
->qos
->Capabilities
, qos1
->qos
->IdentityTracking
,
1206 qos1
->qos
->ImpersonationType
, qos1
->qos
->AdditionalSecurityInfoType
,
1207 qos2
->qos
->Capabilities
, qos2
->qos
->IdentityTracking
,
1208 qos2
->qos
->ImpersonationType
, qos2
->qos
->AdditionalSecurityInfoType
);
1210 if ((qos1
->qos
->Capabilities
!= qos2
->qos
->Capabilities
) ||
1211 (qos1
->qos
->IdentityTracking
!= qos2
->qos
->IdentityTracking
) ||
1212 (qos1
->qos
->ImpersonationType
!= qos2
->qos
->ImpersonationType
) ||
1213 (qos1
->qos
->AdditionalSecurityInfoType
!= qos2
->qos
->AdditionalSecurityInfoType
))
1216 if (qos1
->qos
->AdditionalSecurityInfoType
== RPC_C_AUTHN_INFO_TYPE_HTTP
)
1218 const RPC_HTTP_TRANSPORT_CREDENTIALS_W
*http_credentials1
= qos1
->qos
->u
.HttpCredentials
;
1219 const RPC_HTTP_TRANSPORT_CREDENTIALS_W
*http_credentials2
= qos2
->qos
->u
.HttpCredentials
;
1221 if (http_credentials1
->Flags
!= http_credentials2
->Flags
)
1224 if (http_credentials1
->AuthenticationTarget
!= http_credentials2
->AuthenticationTarget
)
1227 /* authentication schemes and server certificate subject not currently used */
1229 if (http_credentials1
->TransportCredentials
!= http_credentials2
->TransportCredentials
)
1231 const SEC_WINNT_AUTH_IDENTITY_W
*identity1
= http_credentials1
->TransportCredentials
;
1232 const SEC_WINNT_AUTH_IDENTITY_W
*identity2
= http_credentials2
->TransportCredentials
;
1234 if (!identity1
|| !identity2
)
1237 /* compare user names */
1238 if (identity1
->UserLength
!= identity2
->UserLength
||
1239 memcmp(identity1
->User
, identity2
->User
, identity1
->UserLength
))
1241 /* compare domain names */
1242 if (identity1
->DomainLength
!= identity2
->DomainLength
||
1243 memcmp(identity1
->Domain
, identity2
->Domain
, identity1
->DomainLength
))
1245 /* compare passwords */
1246 if (identity1
->PasswordLength
!= identity2
->PasswordLength
||
1247 memcmp(identity1
->Password
, identity2
->Password
, identity1
->PasswordLength
))
1255 /***********************************************************************
1256 * RpcRevertToSelf (RPCRT4.@)
1258 RPC_STATUS WINAPI
RpcRevertToSelf(void)
1265 /***********************************************************************
1266 * RpcMgmtSetComTimeout (RPCRT4.@)
1268 RPC_STATUS WINAPI
RpcMgmtSetComTimeout(RPC_BINDING_HANDLE BindingHandle
, unsigned int Timeout
)
1270 FIXME("(%p, %d): stub\n", BindingHandle
, Timeout
);
1274 /***********************************************************************
1275 * RpcBindingInqAuthInfoExA (RPCRT4.@)
1277 RPCRTAPI RPC_STATUS RPC_ENTRY
1278 RpcBindingInqAuthInfoExA( RPC_BINDING_HANDLE Binding
, RPC_CSTR
*ServerPrincName
, ULONG
*AuthnLevel
,
1279 ULONG
*AuthnSvc
, RPC_AUTH_IDENTITY_HANDLE
*AuthIdentity
, ULONG
*AuthzSvc
,
1280 ULONG RpcQosVersion
, RPC_SECURITY_QOS
*SecurityQOS
)
1282 FIXME("%p %p %p %p %p %p %u %p\n", Binding
, ServerPrincName
, AuthnLevel
,
1283 AuthnSvc
, AuthIdentity
, AuthzSvc
, RpcQosVersion
, SecurityQOS
);
1284 return RPC_S_INVALID_BINDING
;
1287 /***********************************************************************
1288 * RpcBindingInqAuthInfoExW (RPCRT4.@)
1290 RPCRTAPI RPC_STATUS RPC_ENTRY
1291 RpcBindingInqAuthInfoExW( RPC_BINDING_HANDLE Binding
, RPC_WSTR
*ServerPrincName
, ULONG
*AuthnLevel
,
1292 ULONG
*AuthnSvc
, RPC_AUTH_IDENTITY_HANDLE
*AuthIdentity
, ULONG
*AuthzSvc
,
1293 ULONG RpcQosVersion
, RPC_SECURITY_QOS
*SecurityQOS
)
1295 FIXME("%p %p %p %p %p %p %u %p\n", Binding
, ServerPrincName
, AuthnLevel
,
1296 AuthnSvc
, AuthIdentity
, AuthzSvc
, RpcQosVersion
, SecurityQOS
);
1297 return RPC_S_INVALID_BINDING
;
1300 /***********************************************************************
1301 * RpcBindingInqAuthInfoA (RPCRT4.@)
1303 RPCRTAPI RPC_STATUS RPC_ENTRY
1304 RpcBindingInqAuthInfoA( RPC_BINDING_HANDLE Binding
, RPC_CSTR
*ServerPrincName
, ULONG
*AuthnLevel
,
1305 ULONG
*AuthnSvc
, RPC_AUTH_IDENTITY_HANDLE
*AuthIdentity
, ULONG
*AuthzSvc
)
1307 FIXME("%p %p %p %p %p %p\n", Binding
, ServerPrincName
, AuthnLevel
,
1308 AuthnSvc
, AuthIdentity
, AuthzSvc
);
1309 return RPC_S_INVALID_BINDING
;
1312 /***********************************************************************
1313 * RpcBindingInqAuthInfoW (RPCRT4.@)
1315 RPCRTAPI RPC_STATUS RPC_ENTRY
1316 RpcBindingInqAuthInfoW( RPC_BINDING_HANDLE Binding
, RPC_WSTR
*ServerPrincName
, ULONG
*AuthnLevel
,
1317 ULONG
*AuthnSvc
, RPC_AUTH_IDENTITY_HANDLE
*AuthIdentity
, ULONG
*AuthzSvc
)
1319 FIXME("%p %p %p %p %p %p\n", Binding
, ServerPrincName
, AuthnLevel
,
1320 AuthnSvc
, AuthIdentity
, AuthzSvc
);
1321 return RPC_S_INVALID_BINDING
;
1324 /***********************************************************************
1325 * RpcBindingSetAuthInfoExA (RPCRT4.@)
1327 RPCRTAPI RPC_STATUS RPC_ENTRY
1328 RpcBindingSetAuthInfoExA( RPC_BINDING_HANDLE Binding
, RPC_CSTR ServerPrincName
,
1329 ULONG AuthnLevel
, ULONG AuthnSvc
,
1330 RPC_AUTH_IDENTITY_HANDLE AuthIdentity
, ULONG AuthzSvr
,
1331 RPC_SECURITY_QOS
*SecurityQos
)
1333 RpcBinding
* bind
= (RpcBinding
*)Binding
;
1337 ULONG package_count
;
1339 PSecPkgInfoA packages
;
1342 TRACE("%p %s %u %u %p %u %p\n", Binding
, debugstr_a((const char*)ServerPrincName
),
1343 AuthnLevel
, AuthnSvc
, AuthIdentity
, AuthzSvr
, SecurityQos
);
1349 TRACE("SecurityQos { Version=%ld, Capabilties=0x%lx, IdentityTracking=%ld, ImpersonationLevel=%ld",
1350 SecurityQos
->Version
, SecurityQos
->Capabilities
, SecurityQos
->IdentityTracking
, SecurityQos
->ImpersonationType
);
1351 if (SecurityQos
->Version
>= 2)
1353 const RPC_SECURITY_QOS_V2_A
*SecurityQos2
= (const RPC_SECURITY_QOS_V2_A
*)SecurityQos
;
1354 TRACE(", AdditionalSecurityInfoType=%ld", SecurityQos2
->AdditionalSecurityInfoType
);
1355 if (SecurityQos2
->AdditionalSecurityInfoType
== RPC_C_AUTHN_INFO_TYPE_HTTP
)
1356 TRACE(", { %p, 0x%lx, %ld, %ld, %p, %s }",
1357 SecurityQos2
->u
.HttpCredentials
->TransportCredentials
,
1358 SecurityQos2
->u
.HttpCredentials
->Flags
,
1359 SecurityQos2
->u
.HttpCredentials
->AuthenticationTarget
,
1360 SecurityQos2
->u
.HttpCredentials
->NumberOfAuthnSchemes
,
1361 SecurityQos2
->u
.HttpCredentials
->AuthnSchemes
,
1362 SecurityQos2
->u
.HttpCredentials
->ServerCertificateSubject
);
1365 status
= RpcQualityOfService_Create(SecurityQos
, FALSE
, &bind
->QOS
);
1366 if (status
!= RPC_S_OK
)
1371 if (bind
->QOS
) RpcQualityOfService_Release(bind
->QOS
);
1375 if (AuthnSvc
== RPC_C_AUTHN_DEFAULT
)
1376 AuthnSvc
= RPC_C_AUTHN_WINNT
;
1378 /* FIXME: the mapping should probably be retrieved using SSPI somehow */
1379 if (AuthnLevel
== RPC_C_AUTHN_LEVEL_DEFAULT
)
1380 AuthnLevel
= RPC_C_AUTHN_LEVEL_NONE
;
1382 if ((AuthnLevel
== RPC_C_AUTHN_LEVEL_NONE
) || (AuthnSvc
== RPC_C_AUTHN_NONE
))
1384 if (bind
->AuthInfo
) RpcAuthInfo_Release(bind
->AuthInfo
);
1385 bind
->AuthInfo
= NULL
;
1389 if (AuthnLevel
> RPC_C_AUTHN_LEVEL_PKT_PRIVACY
)
1391 FIXME("unknown AuthnLevel %u\n", AuthnLevel
);
1392 return RPC_S_UNKNOWN_AUTHN_LEVEL
;
1397 FIXME("unsupported AuthzSvr %u\n", AuthzSvr
);
1398 return RPC_S_UNKNOWN_AUTHZ_SERVICE
;
1401 r
= EnumerateSecurityPackagesA(&package_count
, &packages
);
1404 ERR("EnumerateSecurityPackagesA failed with error 0x%08x\n", r
);
1405 return RPC_S_SEC_PKG_ERROR
;
1408 for (i
= 0; i
< package_count
; i
++)
1409 if (packages
[i
].wRPCID
== AuthnSvc
)
1412 if (i
== package_count
)
1414 FIXME("unsupported AuthnSvc %u\n", AuthnSvc
);
1415 FreeContextBuffer(packages
);
1416 return RPC_S_UNKNOWN_AUTHN_SERVICE
;
1419 TRACE("found package %s for service %u\n", packages
[i
].Name
, AuthnSvc
);
1420 r
= AcquireCredentialsHandleA(NULL
, packages
[i
].Name
, SECPKG_CRED_OUTBOUND
, NULL
,
1421 AuthIdentity
, NULL
, NULL
, &cred
, &exp
);
1422 cbMaxToken
= packages
[i
].cbMaxToken
;
1423 FreeContextBuffer(packages
);
1424 if (r
== ERROR_SUCCESS
)
1426 RpcAuthInfo
*new_auth_info
;
1427 r
= RpcAuthInfo_Create(AuthnLevel
, AuthnSvc
, cred
, exp
, cbMaxToken
,
1428 AuthIdentity
, &new_auth_info
);
1431 new_auth_info
->server_principal_name
= RPCRT4_strdupAtoW((char *)ServerPrincName
);
1432 if (new_auth_info
->server_principal_name
)
1434 if (bind
->AuthInfo
) RpcAuthInfo_Release(bind
->AuthInfo
);
1435 bind
->AuthInfo
= new_auth_info
;
1439 RpcAuthInfo_Release(new_auth_info
);
1440 r
= ERROR_OUTOFMEMORY
;
1444 FreeCredentialsHandle(&cred
);
1449 ERR("AcquireCredentialsHandleA failed with error 0x%08x\n", r
);
1450 return RPC_S_SEC_PKG_ERROR
;
1454 /***********************************************************************
1455 * RpcBindingSetAuthInfoExW (RPCRT4.@)
1457 RPCRTAPI RPC_STATUS RPC_ENTRY
1458 RpcBindingSetAuthInfoExW( RPC_BINDING_HANDLE Binding
, RPC_WSTR ServerPrincName
, ULONG AuthnLevel
,
1459 ULONG AuthnSvc
, RPC_AUTH_IDENTITY_HANDLE AuthIdentity
, ULONG AuthzSvr
,
1460 RPC_SECURITY_QOS
*SecurityQos
)
1462 RpcBinding
* bind
= (RpcBinding
*)Binding
;
1466 ULONG package_count
;
1468 PSecPkgInfoW packages
;
1471 TRACE("%p %s %u %u %p %u %p\n", Binding
, debugstr_w((const WCHAR
*)ServerPrincName
),
1472 AuthnLevel
, AuthnSvc
, AuthIdentity
, AuthzSvr
, SecurityQos
);
1478 TRACE("SecurityQos { Version=%ld, Capabilties=0x%lx, IdentityTracking=%ld, ImpersonationLevel=%ld",
1479 SecurityQos
->Version
, SecurityQos
->Capabilities
, SecurityQos
->IdentityTracking
, SecurityQos
->ImpersonationType
);
1480 if (SecurityQos
->Version
>= 2)
1482 const RPC_SECURITY_QOS_V2_W
*SecurityQos2
= (const RPC_SECURITY_QOS_V2_W
*)SecurityQos
;
1483 TRACE(", AdditionalSecurityInfoType=%ld", SecurityQos2
->AdditionalSecurityInfoType
);
1484 if (SecurityQos2
->AdditionalSecurityInfoType
== RPC_C_AUTHN_INFO_TYPE_HTTP
)
1485 TRACE(", { %p, 0x%lx, %ld, %ld, %p, %s }",
1486 SecurityQos2
->u
.HttpCredentials
->TransportCredentials
,
1487 SecurityQos2
->u
.HttpCredentials
->Flags
,
1488 SecurityQos2
->u
.HttpCredentials
->AuthenticationTarget
,
1489 SecurityQos2
->u
.HttpCredentials
->NumberOfAuthnSchemes
,
1490 SecurityQos2
->u
.HttpCredentials
->AuthnSchemes
,
1491 debugstr_w(SecurityQos2
->u
.HttpCredentials
->ServerCertificateSubject
));
1494 status
= RpcQualityOfService_Create(SecurityQos
, TRUE
, &bind
->QOS
);
1495 if (status
!= RPC_S_OK
)
1500 if (bind
->QOS
) RpcQualityOfService_Release(bind
->QOS
);
1504 if (AuthnSvc
== RPC_C_AUTHN_DEFAULT
)
1505 AuthnSvc
= RPC_C_AUTHN_WINNT
;
1507 /* FIXME: the mapping should probably be retrieved using SSPI somehow */
1508 if (AuthnLevel
== RPC_C_AUTHN_LEVEL_DEFAULT
)
1509 AuthnLevel
= RPC_C_AUTHN_LEVEL_NONE
;
1511 if ((AuthnLevel
== RPC_C_AUTHN_LEVEL_NONE
) || (AuthnSvc
== RPC_C_AUTHN_NONE
))
1513 if (bind
->AuthInfo
) RpcAuthInfo_Release(bind
->AuthInfo
);
1514 bind
->AuthInfo
= NULL
;
1518 if (AuthnLevel
> RPC_C_AUTHN_LEVEL_PKT_PRIVACY
)
1520 FIXME("unknown AuthnLevel %u\n", AuthnLevel
);
1521 return RPC_S_UNKNOWN_AUTHN_LEVEL
;
1526 FIXME("unsupported AuthzSvr %u\n", AuthzSvr
);
1527 return RPC_S_UNKNOWN_AUTHZ_SERVICE
;
1530 r
= EnumerateSecurityPackagesW(&package_count
, &packages
);
1533 ERR("EnumerateSecurityPackagesA failed with error 0x%08x\n", r
);
1534 return RPC_S_SEC_PKG_ERROR
;
1537 for (i
= 0; i
< package_count
; i
++)
1538 if (packages
[i
].wRPCID
== AuthnSvc
)
1541 if (i
== package_count
)
1543 FIXME("unsupported AuthnSvc %u\n", AuthnSvc
);
1544 FreeContextBuffer(packages
);
1545 return RPC_S_UNKNOWN_AUTHN_SERVICE
;
1548 TRACE("found package %s for service %u\n", debugstr_w(packages
[i
].Name
), AuthnSvc
);
1549 r
= AcquireCredentialsHandleW(NULL
, packages
[i
].Name
, SECPKG_CRED_OUTBOUND
, NULL
,
1550 AuthIdentity
, NULL
, NULL
, &cred
, &exp
);
1551 cbMaxToken
= packages
[i
].cbMaxToken
;
1552 FreeContextBuffer(packages
);
1553 if (r
== ERROR_SUCCESS
)
1555 RpcAuthInfo
*new_auth_info
;
1556 r
= RpcAuthInfo_Create(AuthnLevel
, AuthnSvc
, cred
, exp
, cbMaxToken
,
1557 AuthIdentity
, &new_auth_info
);
1560 new_auth_info
->server_principal_name
= RPCRT4_strdupW(ServerPrincName
);
1561 if (new_auth_info
->server_principal_name
)
1563 if (bind
->AuthInfo
) RpcAuthInfo_Release(bind
->AuthInfo
);
1564 bind
->AuthInfo
= new_auth_info
;
1568 RpcAuthInfo_Release(new_auth_info
);
1569 r
= ERROR_OUTOFMEMORY
;
1573 FreeCredentialsHandle(&cred
);
1578 ERR("AcquireCredentialsHandleA failed with error 0x%08x\n", r
);
1579 return RPC_S_SEC_PKG_ERROR
;
1583 /***********************************************************************
1584 * RpcBindingSetAuthInfoA (RPCRT4.@)
1586 RPCRTAPI RPC_STATUS RPC_ENTRY
1587 RpcBindingSetAuthInfoA( RPC_BINDING_HANDLE Binding
, RPC_CSTR ServerPrincName
, ULONG AuthnLevel
,
1588 ULONG AuthnSvc
, RPC_AUTH_IDENTITY_HANDLE AuthIdentity
, ULONG AuthzSvr
)
1590 TRACE("%p %s %u %u %p %u\n", Binding
, debugstr_a((const char*)ServerPrincName
),
1591 AuthnLevel
, AuthnSvc
, AuthIdentity
, AuthzSvr
);
1592 return RpcBindingSetAuthInfoExA(Binding
, ServerPrincName
, AuthnLevel
, AuthnSvc
, AuthIdentity
, AuthzSvr
, NULL
);
1595 /***********************************************************************
1596 * RpcBindingSetAuthInfoW (RPCRT4.@)
1598 RPCRTAPI RPC_STATUS RPC_ENTRY
1599 RpcBindingSetAuthInfoW( RPC_BINDING_HANDLE Binding
, RPC_WSTR ServerPrincName
, ULONG AuthnLevel
,
1600 ULONG AuthnSvc
, RPC_AUTH_IDENTITY_HANDLE AuthIdentity
, ULONG AuthzSvr
)
1602 TRACE("%p %s %u %u %p %u\n", Binding
, debugstr_w((const WCHAR
*)ServerPrincName
),
1603 AuthnLevel
, AuthnSvc
, AuthIdentity
, AuthzSvr
);
1604 return RpcBindingSetAuthInfoExW(Binding
, ServerPrincName
, AuthnLevel
, AuthnSvc
, AuthIdentity
, AuthzSvr
, NULL
);
1607 /***********************************************************************
1608 * RpcBindingSetOption (RPCRT4.@)
1610 RPC_STATUS WINAPI
RpcBindingSetOption(RPC_BINDING_HANDLE BindingHandle
, ULONG Option
, ULONG OptionValue
)
1612 FIXME("(%p, %d, %d): stub\n", BindingHandle
, Option
, OptionValue
);