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=";
471 BOOL endpoint_already_found
= FALSE
;
473 TRACE("(%s,%p,%p,%p,%p,%p)\n", debugstr_a((char*)StringBinding
),
474 ObjUuid
, Protseq
, NetworkAddr
, Endpoint
, Options
);
476 if (ObjUuid
) *ObjUuid
= NULL
;
477 if (Protseq
) *Protseq
= NULL
;
478 if (NetworkAddr
) *NetworkAddr
= NULL
;
479 if (Endpoint
) *Endpoint
= NULL
;
480 if (Options
) *Options
= NULL
;
482 data
= (char*) StringBinding
;
484 next
= strchr(data
, '@');
486 if (ObjUuid
) *ObjUuid
= (unsigned char*)RPCRT4_strndupA(data
, next
- data
);
490 next
= strchr(data
, ':');
492 if (Protseq
) *Protseq
= (unsigned char*)RPCRT4_strndupA(data
, next
- data
);
496 next
= strchr(data
, '[');
500 if (NetworkAddr
) *NetworkAddr
= (unsigned char*)RPCRT4_strndupA(data
, next
- data
);
502 close
= strchr(data
, ']');
503 if (!close
) goto fail
;
505 /* tokenize options */
506 while (data
< close
) {
507 next
= strchr(data
, ',');
508 if (!next
|| next
> close
) next
= close
;
509 /* FIXME: this is kind of inefficient */
510 opt
= RPCRT4_strndupA(data
, next
- data
);
514 next
= strchr(opt
, '=');
516 /* not an option, must be an endpoint */
517 if (endpoint_already_found
) goto fail
;
518 if (Endpoint
) *Endpoint
= (unsigned char*) opt
;
519 else HeapFree(GetProcessHeap(), 0, opt
);
520 endpoint_already_found
= TRUE
;
522 if (strncmp(opt
, ep_opt
, strlen(ep_opt
)) == 0) {
523 /* endpoint option */
524 if (endpoint_already_found
) goto fail
;
525 if (Endpoint
) *Endpoint
= (unsigned char*) RPCRT4_strdupA(next
+1);
526 HeapFree(GetProcessHeap(), 0, opt
);
527 endpoint_already_found
= TRUE
;
532 /* FIXME: this is kind of inefficient */
533 *Options
= (unsigned char*) RPCRT4_strconcatA( (char*)*Options
, opt
);
534 HeapFree(GetProcessHeap(), 0, opt
);
536 *Options
= (unsigned char*) opt
;
538 HeapFree(GetProcessHeap(), 0, opt
);
544 if (*data
) goto fail
;
546 else if (NetworkAddr
)
547 *NetworkAddr
= (unsigned char*)RPCRT4_strdupA(data
);
552 if (ObjUuid
) RpcStringFreeA((unsigned char**)ObjUuid
);
553 if (Protseq
) RpcStringFreeA((unsigned char**)Protseq
);
554 if (NetworkAddr
) RpcStringFreeA((unsigned char**)NetworkAddr
);
555 if (Endpoint
) RpcStringFreeA((unsigned char**)Endpoint
);
556 if (Options
) RpcStringFreeA((unsigned char**)Options
);
557 return RPC_S_INVALID_STRING_BINDING
;
560 /***********************************************************************
561 * RpcStringBindingParseW (RPCRT4.@)
563 RPC_STATUS WINAPI
RpcStringBindingParseW( RPC_WSTR StringBinding
, RPC_WSTR
*ObjUuid
,
564 RPC_WSTR
*Protseq
, RPC_WSTR
*NetworkAddr
,
565 RPC_WSTR
*Endpoint
, RPC_WSTR
*Options
)
568 static const WCHAR ep_opt
[] = {'e','n','d','p','o','i','n','t','=',0};
569 BOOL endpoint_already_found
= FALSE
;
571 TRACE("(%s,%p,%p,%p,%p,%p)\n", debugstr_w(StringBinding
),
572 ObjUuid
, Protseq
, NetworkAddr
, Endpoint
, Options
);
574 if (ObjUuid
) *ObjUuid
= NULL
;
575 if (Protseq
) *Protseq
= NULL
;
576 if (NetworkAddr
) *NetworkAddr
= NULL
;
577 if (Endpoint
) *Endpoint
= NULL
;
578 if (Options
) *Options
= NULL
;
580 data
= StringBinding
;
582 next
= strchrW(data
, '@');
584 if (ObjUuid
) *ObjUuid
= RPCRT4_strndupW(data
, next
- data
);
588 next
= strchrW(data
, ':');
590 if (Protseq
) *Protseq
= RPCRT4_strndupW(data
, next
- data
);
594 next
= strchrW(data
, '[');
598 if (NetworkAddr
) *NetworkAddr
= RPCRT4_strndupW(data
, next
- data
);
600 close
= strchrW(data
, ']');
601 if (!close
) goto fail
;
603 /* tokenize options */
604 while (data
< close
) {
605 next
= strchrW(data
, ',');
606 if (!next
|| next
> close
) next
= close
;
607 /* FIXME: this is kind of inefficient */
608 opt
= RPCRT4_strndupW(data
, next
- data
);
612 next
= strchrW(opt
, '=');
614 /* not an option, must be an endpoint */
615 if (endpoint_already_found
) goto fail
;
616 if (Endpoint
) *Endpoint
= opt
;
617 else HeapFree(GetProcessHeap(), 0, opt
);
618 endpoint_already_found
= TRUE
;
620 if (strncmpW(opt
, ep_opt
, strlenW(ep_opt
)) == 0) {
621 /* endpoint option */
622 if (endpoint_already_found
) goto fail
;
623 if (Endpoint
) *Endpoint
= RPCRT4_strdupW(next
+1);
624 HeapFree(GetProcessHeap(), 0, opt
);
625 endpoint_already_found
= TRUE
;
630 /* FIXME: this is kind of inefficient */
631 *Options
= RPCRT4_strconcatW(*Options
, opt
);
632 HeapFree(GetProcessHeap(), 0, opt
);
636 HeapFree(GetProcessHeap(), 0, opt
);
642 if (*data
) goto fail
;
643 } else if (NetworkAddr
)
644 *NetworkAddr
= RPCRT4_strdupW(data
);
649 if (ObjUuid
) RpcStringFreeW(ObjUuid
);
650 if (Protseq
) RpcStringFreeW(Protseq
);
651 if (NetworkAddr
) RpcStringFreeW(NetworkAddr
);
652 if (Endpoint
) RpcStringFreeW(Endpoint
);
653 if (Options
) RpcStringFreeW(Options
);
654 return RPC_S_INVALID_STRING_BINDING
;
657 /***********************************************************************
658 * RpcBindingFree (RPCRT4.@)
660 RPC_STATUS WINAPI
RpcBindingFree( RPC_BINDING_HANDLE
* Binding
)
663 TRACE("(%p) = %p\n", Binding
, *Binding
);
664 status
= RPCRT4_DestroyBinding(*Binding
);
665 if (status
== RPC_S_OK
) *Binding
= 0;
669 /***********************************************************************
670 * RpcBindingVectorFree (RPCRT4.@)
672 RPC_STATUS WINAPI
RpcBindingVectorFree( RPC_BINDING_VECTOR
** BindingVector
)
677 TRACE("(%p)\n", BindingVector
);
678 for (c
=0; c
<(*BindingVector
)->Count
; c
++) {
679 status
= RpcBindingFree(&(*BindingVector
)->BindingH
[c
]);
681 HeapFree(GetProcessHeap(), 0, *BindingVector
);
682 *BindingVector
= NULL
;
686 /***********************************************************************
687 * RpcBindingInqObject (RPCRT4.@)
689 RPC_STATUS WINAPI
RpcBindingInqObject( RPC_BINDING_HANDLE Binding
, UUID
* ObjectUuid
)
691 RpcBinding
* bind
= (RpcBinding
*)Binding
;
693 TRACE("(%p,%p) = %s\n", Binding
, ObjectUuid
, debugstr_guid(&bind
->ObjectUuid
));
694 memcpy(ObjectUuid
, &bind
->ObjectUuid
, sizeof(UUID
));
698 /***********************************************************************
699 * RpcBindingSetObject (RPCRT4.@)
701 RPC_STATUS WINAPI
RpcBindingSetObject( RPC_BINDING_HANDLE Binding
, UUID
* ObjectUuid
)
703 RpcBinding
* bind
= (RpcBinding
*)Binding
;
705 TRACE("(%p,%s)\n", Binding
, debugstr_guid(ObjectUuid
));
706 if (bind
->server
) return RPC_S_WRONG_KIND_OF_BINDING
;
707 return RPCRT4_SetBindingObject(Binding
, ObjectUuid
);
710 /***********************************************************************
711 * RpcBindingFromStringBindingA (RPCRT4.@)
713 RPC_STATUS WINAPI
RpcBindingFromStringBindingA( RPC_CSTR StringBinding
, RPC_BINDING_HANDLE
* Binding
)
716 RpcBinding
* bind
= NULL
;
717 RPC_CSTR ObjectUuid
, Protseq
, NetworkAddr
, Endpoint
, Options
;
720 TRACE("(%s,%p)\n", debugstr_a((char*)StringBinding
), Binding
);
722 ret
= RpcStringBindingParseA(StringBinding
, &ObjectUuid
, &Protseq
,
723 &NetworkAddr
, &Endpoint
, &Options
);
724 if (ret
!= RPC_S_OK
) return ret
;
726 ret
= UuidFromStringA(ObjectUuid
, &Uuid
);
729 ret
= RPCRT4_CreateBindingA(&bind
, FALSE
, (char*)Protseq
);
731 ret
= RPCRT4_SetBindingObject(bind
, &Uuid
);
733 ret
= RPCRT4_CompleteBindingA(bind
, (char*)NetworkAddr
, (char*)Endpoint
, (char*)Options
);
735 RpcStringFreeA((unsigned char**)&Options
);
736 RpcStringFreeA((unsigned char**)&Endpoint
);
737 RpcStringFreeA((unsigned char**)&NetworkAddr
);
738 RpcStringFreeA((unsigned char**)&Protseq
);
739 RpcStringFreeA((unsigned char**)&ObjectUuid
);
742 *Binding
= (RPC_BINDING_HANDLE
)bind
;
744 RPCRT4_DestroyBinding(bind
);
749 /***********************************************************************
750 * RpcBindingFromStringBindingW (RPCRT4.@)
752 RPC_STATUS WINAPI
RpcBindingFromStringBindingW( RPC_WSTR StringBinding
, RPC_BINDING_HANDLE
* Binding
)
755 RpcBinding
* bind
= NULL
;
756 RPC_WSTR ObjectUuid
, Protseq
, NetworkAddr
, Endpoint
, Options
;
759 TRACE("(%s,%p)\n", debugstr_w(StringBinding
), Binding
);
761 ret
= RpcStringBindingParseW(StringBinding
, &ObjectUuid
, &Protseq
,
762 &NetworkAddr
, &Endpoint
, &Options
);
763 if (ret
!= RPC_S_OK
) return ret
;
765 ret
= UuidFromStringW(ObjectUuid
, &Uuid
);
768 ret
= RPCRT4_CreateBindingW(&bind
, FALSE
, Protseq
);
770 ret
= RPCRT4_SetBindingObject(bind
, &Uuid
);
772 ret
= RPCRT4_CompleteBindingW(bind
, NetworkAddr
, Endpoint
, Options
);
774 RpcStringFreeW(&Options
);
775 RpcStringFreeW(&Endpoint
);
776 RpcStringFreeW(&NetworkAddr
);
777 RpcStringFreeW(&Protseq
);
778 RpcStringFreeW(&ObjectUuid
);
781 *Binding
= (RPC_BINDING_HANDLE
)bind
;
783 RPCRT4_DestroyBinding(bind
);
788 /***********************************************************************
789 * RpcBindingToStringBindingA (RPCRT4.@)
791 RPC_STATUS WINAPI
RpcBindingToStringBindingA( RPC_BINDING_HANDLE Binding
, RPC_CSTR
*StringBinding
)
794 RpcBinding
* bind
= (RpcBinding
*)Binding
;
797 TRACE("(%p,%p)\n", Binding
, StringBinding
);
799 ret
= UuidToStringA(&bind
->ObjectUuid
, &ObjectUuid
);
800 if (ret
!= RPC_S_OK
) return ret
;
802 ret
= RpcStringBindingComposeA(ObjectUuid
, (unsigned char*)bind
->Protseq
, (unsigned char*) bind
->NetworkAddr
,
803 (unsigned char*) bind
->Endpoint
, NULL
, StringBinding
);
805 RpcStringFreeA(&ObjectUuid
);
810 /***********************************************************************
811 * RpcBindingToStringBindingW (RPCRT4.@)
813 RPC_STATUS WINAPI
RpcBindingToStringBindingW( RPC_BINDING_HANDLE Binding
, RPC_WSTR
*StringBinding
)
816 unsigned char *str
= NULL
;
817 TRACE("(%p,%p)\n", Binding
, StringBinding
);
818 ret
= RpcBindingToStringBindingA(Binding
, &str
);
819 *StringBinding
= RPCRT4_strdupAtoW((char*)str
);
820 RpcStringFreeA((unsigned char**)&str
);
824 /***********************************************************************
825 * I_RpcBindingSetAsync (RPCRT4.@)
827 * Exists in win9x and winNT, but with different number of arguments
828 * (9x version has 3 arguments, NT has 2).
830 RPC_STATUS WINAPI
I_RpcBindingSetAsync( RPC_BINDING_HANDLE Binding
, RPC_BLOCKING_FN BlockingFn
)
832 RpcBinding
* bind
= (RpcBinding
*)Binding
;
834 TRACE( "(%p,%p): stub\n", Binding
, BlockingFn
);
836 bind
->BlockingFn
= BlockingFn
;
841 /***********************************************************************
842 * RpcBindingCopy (RPCRT4.@)
844 RPC_STATUS RPC_ENTRY
RpcBindingCopy(
845 RPC_BINDING_HANDLE SourceBinding
,
846 RPC_BINDING_HANDLE
* DestinationBinding
)
848 RpcBinding
*DestBinding
;
849 RpcBinding
*SrcBinding
= (RpcBinding
*)SourceBinding
;
852 TRACE("(%p, %p)\n", SourceBinding
, DestinationBinding
);
854 status
= RPCRT4_AllocBinding(&DestBinding
, SrcBinding
->server
);
855 if (status
!= RPC_S_OK
) return status
;
857 DestBinding
->ObjectUuid
= SrcBinding
->ObjectUuid
;
858 DestBinding
->BlockingFn
= SrcBinding
->BlockingFn
;
859 DestBinding
->Protseq
= RPCRT4_strndupA(SrcBinding
->Protseq
, -1);
860 DestBinding
->NetworkAddr
= RPCRT4_strndupA(SrcBinding
->NetworkAddr
, -1);
861 DestBinding
->Endpoint
= RPCRT4_strndupA(SrcBinding
->Endpoint
, -1);
862 DestBinding
->NetworkOptions
= RPCRT4_strdupW(SrcBinding
->NetworkOptions
);
863 if (SrcBinding
->Assoc
) SrcBinding
->Assoc
->refs
++;
864 DestBinding
->Assoc
= SrcBinding
->Assoc
;
866 if (SrcBinding
->AuthInfo
) RpcAuthInfo_AddRef(SrcBinding
->AuthInfo
);
867 DestBinding
->AuthInfo
= SrcBinding
->AuthInfo
;
868 if (SrcBinding
->QOS
) RpcQualityOfService_AddRef(SrcBinding
->QOS
);
869 DestBinding
->QOS
= SrcBinding
->QOS
;
871 *DestinationBinding
= DestBinding
;
875 /***********************************************************************
876 * RpcImpersonateClient (RPCRT4.@)
878 * Impersonates the client connected via a binding handle so that security
879 * checks are done in the context of the client.
882 * BindingHandle [I] Handle to the binding to the client.
886 * Failure: RPC_STATUS value.
890 * If BindingHandle is NULL then the function impersonates the client
891 * connected to the binding handle of the current thread.
893 RPC_STATUS WINAPI
RpcImpersonateClient(RPC_BINDING_HANDLE BindingHandle
)
895 FIXME("(%p): stub\n", BindingHandle
);
896 ImpersonateSelf(SecurityImpersonation
);
900 /***********************************************************************
901 * RpcRevertToSelfEx (RPCRT4.@)
903 * Stops impersonating the client connected to the binding handle so that security
904 * checks are no longer done in the context of the client.
907 * BindingHandle [I] Handle to the binding to the client.
911 * Failure: RPC_STATUS value.
915 * If BindingHandle is NULL then the function stops impersonating the client
916 * connected to the binding handle of the current thread.
918 RPC_STATUS WINAPI
RpcRevertToSelfEx(RPC_BINDING_HANDLE BindingHandle
)
920 FIXME("(%p): stub\n", BindingHandle
);
924 static inline BOOL
has_nt_auth_identity(ULONG AuthnLevel
)
928 case RPC_C_AUTHN_GSS_NEGOTIATE
:
929 case RPC_C_AUTHN_WINNT
:
930 case RPC_C_AUTHN_GSS_KERBEROS
:
937 static RPC_STATUS
RpcAuthInfo_Create(ULONG AuthnLevel
, ULONG AuthnSvc
,
938 CredHandle cred
, TimeStamp exp
,
940 RPC_AUTH_IDENTITY_HANDLE identity
,
943 RpcAuthInfo
*AuthInfo
= HeapAlloc(GetProcessHeap(), 0, sizeof(*AuthInfo
));
945 return ERROR_OUTOFMEMORY
;
948 AuthInfo
->AuthnLevel
= AuthnLevel
;
949 AuthInfo
->AuthnSvc
= AuthnSvc
;
950 AuthInfo
->cred
= cred
;
952 AuthInfo
->cbMaxToken
= cbMaxToken
;
953 AuthInfo
->identity
= identity
;
954 AuthInfo
->server_principal_name
= NULL
;
956 /* duplicate the SEC_WINNT_AUTH_IDENTITY structure, if applicable, to
957 * enable better matching in RpcAuthInfo_IsEqual */
958 if (identity
&& has_nt_auth_identity(AuthnSvc
))
960 const SEC_WINNT_AUTH_IDENTITY_W
*nt_identity
= identity
;
961 AuthInfo
->nt_identity
= HeapAlloc(GetProcessHeap(), 0, sizeof(*AuthInfo
->nt_identity
));
962 if (!AuthInfo
->nt_identity
)
964 HeapFree(GetProcessHeap(), 0, AuthInfo
);
965 return ERROR_OUTOFMEMORY
;
968 AuthInfo
->nt_identity
->Flags
= SEC_WINNT_AUTH_IDENTITY_UNICODE
;
969 if (nt_identity
->Flags
& SEC_WINNT_AUTH_IDENTITY_UNICODE
)
970 AuthInfo
->nt_identity
->User
= RPCRT4_strndupW(nt_identity
->User
, nt_identity
->UserLength
);
972 AuthInfo
->nt_identity
->User
= RPCRT4_strndupAtoW((const char *)nt_identity
->User
, nt_identity
->UserLength
);
973 AuthInfo
->nt_identity
->UserLength
= nt_identity
->UserLength
;
974 if (nt_identity
->Flags
& SEC_WINNT_AUTH_IDENTITY_UNICODE
)
975 AuthInfo
->nt_identity
->Domain
= RPCRT4_strndupW(nt_identity
->Domain
, nt_identity
->DomainLength
);
977 AuthInfo
->nt_identity
->Domain
= RPCRT4_strndupAtoW((const char *)nt_identity
->Domain
, nt_identity
->DomainLength
);
978 AuthInfo
->nt_identity
->DomainLength
= nt_identity
->DomainLength
;
979 if (nt_identity
->Flags
& SEC_WINNT_AUTH_IDENTITY_UNICODE
)
980 AuthInfo
->nt_identity
->Password
= RPCRT4_strndupW(nt_identity
->Password
, nt_identity
->PasswordLength
);
982 AuthInfo
->nt_identity
->Password
= RPCRT4_strndupAtoW((const char *)nt_identity
->Password
, nt_identity
->PasswordLength
);
983 AuthInfo
->nt_identity
->PasswordLength
= nt_identity
->PasswordLength
;
985 if (!AuthInfo
->nt_identity
->User
||
986 !AuthInfo
->nt_identity
->Domain
||
987 !AuthInfo
->nt_identity
->Password
)
989 HeapFree(GetProcessHeap(), 0, AuthInfo
->nt_identity
->User
);
990 HeapFree(GetProcessHeap(), 0, AuthInfo
->nt_identity
->Domain
);
991 HeapFree(GetProcessHeap(), 0, AuthInfo
->nt_identity
->Password
);
992 HeapFree(GetProcessHeap(), 0, AuthInfo
->nt_identity
);
993 HeapFree(GetProcessHeap(), 0, AuthInfo
);
994 return ERROR_OUTOFMEMORY
;
998 AuthInfo
->nt_identity
= NULL
;
1003 ULONG
RpcAuthInfo_AddRef(RpcAuthInfo
*AuthInfo
)
1005 return InterlockedIncrement(&AuthInfo
->refs
);
1008 ULONG
RpcAuthInfo_Release(RpcAuthInfo
*AuthInfo
)
1010 ULONG refs
= InterlockedDecrement(&AuthInfo
->refs
);
1014 FreeCredentialsHandle(&AuthInfo
->cred
);
1015 if (AuthInfo
->nt_identity
)
1017 HeapFree(GetProcessHeap(), 0, AuthInfo
->nt_identity
->User
);
1018 HeapFree(GetProcessHeap(), 0, AuthInfo
->nt_identity
->Domain
);
1019 HeapFree(GetProcessHeap(), 0, AuthInfo
->nt_identity
->Password
);
1020 HeapFree(GetProcessHeap(), 0, AuthInfo
->nt_identity
);
1022 HeapFree(GetProcessHeap(), 0, AuthInfo
->server_principal_name
);
1023 HeapFree(GetProcessHeap(), 0, AuthInfo
);
1029 BOOL
RpcAuthInfo_IsEqual(const RpcAuthInfo
*AuthInfo1
, const RpcAuthInfo
*AuthInfo2
)
1031 if (AuthInfo1
== AuthInfo2
)
1034 if (!AuthInfo1
|| !AuthInfo2
)
1037 if ((AuthInfo1
->AuthnLevel
!= AuthInfo2
->AuthnLevel
) ||
1038 (AuthInfo1
->AuthnSvc
!= AuthInfo2
->AuthnSvc
))
1041 if (AuthInfo1
->identity
== AuthInfo2
->identity
)
1044 if (!AuthInfo1
->identity
|| !AuthInfo2
->identity
)
1047 if (has_nt_auth_identity(AuthInfo1
->AuthnSvc
))
1049 const SEC_WINNT_AUTH_IDENTITY_W
*identity1
= AuthInfo1
->nt_identity
;
1050 const SEC_WINNT_AUTH_IDENTITY_W
*identity2
= AuthInfo2
->nt_identity
;
1051 /* compare user names */
1052 if (identity1
->UserLength
!= identity2
->UserLength
||
1053 memcmp(identity1
->User
, identity2
->User
, identity1
->UserLength
))
1055 /* compare domain names */
1056 if (identity1
->DomainLength
!= identity2
->DomainLength
||
1057 memcmp(identity1
->Domain
, identity2
->Domain
, identity1
->DomainLength
))
1059 /* compare passwords */
1060 if (identity1
->PasswordLength
!= identity2
->PasswordLength
||
1061 memcmp(identity1
->Password
, identity2
->Password
, identity1
->PasswordLength
))
1070 static RPC_STATUS
RpcQualityOfService_Create(const RPC_SECURITY_QOS
*qos_src
, BOOL unicode
, RpcQualityOfService
**qos_dst
)
1072 RpcQualityOfService
*qos
= HeapAlloc(GetProcessHeap(), 0, sizeof(*qos
));
1075 return RPC_S_OUT_OF_RESOURCES
;
1078 qos
->qos
= HeapAlloc(GetProcessHeap(), 0, sizeof(*qos
->qos
));
1079 if (!qos
->qos
) goto error
;
1080 qos
->qos
->Version
= qos_src
->Version
;
1081 qos
->qos
->Capabilities
= qos_src
->Capabilities
;
1082 qos
->qos
->IdentityTracking
= qos_src
->IdentityTracking
;
1083 qos
->qos
->ImpersonationType
= qos_src
->ImpersonationType
;
1084 qos
->qos
->AdditionalSecurityInfoType
= 0;
1086 if (qos_src
->Version
>= 2)
1088 const RPC_SECURITY_QOS_V2_W
*qos_src2
= (const RPC_SECURITY_QOS_V2_W
*)qos_src
;
1089 qos
->qos
->AdditionalSecurityInfoType
= qos_src2
->AdditionalSecurityInfoType
;
1090 if (qos_src2
->AdditionalSecurityInfoType
== RPC_C_AUTHN_INFO_TYPE_HTTP
)
1092 const RPC_HTTP_TRANSPORT_CREDENTIALS_W
*http_credentials_src
= qos_src2
->u
.HttpCredentials
;
1093 RPC_HTTP_TRANSPORT_CREDENTIALS_W
*http_credentials_dst
;
1095 http_credentials_dst
= HeapAlloc(GetProcessHeap(), 0, sizeof(*http_credentials_dst
));
1096 qos
->qos
->u
.HttpCredentials
= http_credentials_dst
;
1097 if (!http_credentials_dst
) goto error
;
1098 http_credentials_dst
->TransportCredentials
= NULL
;
1099 http_credentials_dst
->Flags
= http_credentials_src
->Flags
;
1100 http_credentials_dst
->AuthenticationTarget
= http_credentials_src
->AuthenticationTarget
;
1101 http_credentials_dst
->NumberOfAuthnSchemes
= http_credentials_src
->NumberOfAuthnSchemes
;
1102 http_credentials_dst
->AuthnSchemes
= NULL
;
1103 http_credentials_dst
->ServerCertificateSubject
= NULL
;
1104 if (http_credentials_src
->TransportCredentials
)
1106 SEC_WINNT_AUTH_IDENTITY_W
*cred_dst
;
1107 cred_dst
= http_credentials_dst
->TransportCredentials
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*cred_dst
));
1108 if (!cred_dst
) goto error
;
1109 cred_dst
->Flags
= SEC_WINNT_AUTH_IDENTITY_UNICODE
;
1112 const SEC_WINNT_AUTH_IDENTITY_W
*cred_src
= http_credentials_src
->TransportCredentials
;
1113 cred_dst
->UserLength
= cred_src
->UserLength
;
1114 cred_dst
->PasswordLength
= cred_src
->PasswordLength
;
1115 cred_dst
->DomainLength
= cred_src
->DomainLength
;
1116 cred_dst
->User
= RPCRT4_strndupW(cred_src
->User
, cred_src
->UserLength
);
1117 cred_dst
->Password
= RPCRT4_strndupW(cred_src
->Password
, cred_src
->PasswordLength
);
1118 cred_dst
->Domain
= RPCRT4_strndupW(cred_src
->Domain
, cred_src
->DomainLength
);
1122 const SEC_WINNT_AUTH_IDENTITY_A
*cred_src
= (const SEC_WINNT_AUTH_IDENTITY_A
*)http_credentials_src
->TransportCredentials
;
1123 cred_dst
->UserLength
= MultiByteToWideChar(CP_ACP
, 0, (char *)cred_src
->User
, cred_src
->UserLength
, NULL
, 0);
1124 cred_dst
->DomainLength
= MultiByteToWideChar(CP_ACP
, 0, (char *)cred_src
->Domain
, cred_src
->DomainLength
, NULL
, 0);
1125 cred_dst
->PasswordLength
= MultiByteToWideChar(CP_ACP
, 0, (char *)cred_src
->Password
, cred_src
->PasswordLength
, NULL
, 0);
1126 cred_dst
->User
= HeapAlloc(GetProcessHeap(), 0, cred_dst
->UserLength
* sizeof(WCHAR
));
1127 cred_dst
->Password
= HeapAlloc(GetProcessHeap(), 0, cred_dst
->PasswordLength
* sizeof(WCHAR
));
1128 cred_dst
->Domain
= HeapAlloc(GetProcessHeap(), 0, cred_dst
->DomainLength
* sizeof(WCHAR
));
1129 if (!cred_dst
|| !cred_dst
->Password
|| !cred_dst
->Domain
) goto error
;
1130 MultiByteToWideChar(CP_ACP
, 0, (char *)cred_src
->User
, cred_src
->UserLength
, cred_dst
->User
, cred_dst
->UserLength
);
1131 MultiByteToWideChar(CP_ACP
, 0, (char *)cred_src
->Domain
, cred_src
->DomainLength
, cred_dst
->Domain
, cred_dst
->DomainLength
);
1132 MultiByteToWideChar(CP_ACP
, 0, (char *)cred_src
->Password
, cred_src
->PasswordLength
, cred_dst
->Password
, cred_dst
->PasswordLength
);
1135 if (http_credentials_src
->NumberOfAuthnSchemes
)
1137 http_credentials_dst
->AuthnSchemes
= HeapAlloc(GetProcessHeap(), 0, http_credentials_src
->NumberOfAuthnSchemes
* sizeof(*http_credentials_dst
->AuthnSchemes
));
1138 if (!http_credentials_dst
->AuthnSchemes
) goto error
;
1139 memcpy(http_credentials_dst
->AuthnSchemes
, http_credentials_src
->AuthnSchemes
, http_credentials_src
->NumberOfAuthnSchemes
* sizeof(*http_credentials_dst
->AuthnSchemes
));
1141 if (http_credentials_src
->ServerCertificateSubject
)
1144 http_credentials_dst
->ServerCertificateSubject
=
1145 RPCRT4_strndupW(http_credentials_src
->ServerCertificateSubject
,
1146 strlenW(http_credentials_src
->ServerCertificateSubject
));
1148 http_credentials_dst
->ServerCertificateSubject
=
1149 RPCRT4_strdupAtoW((char *)http_credentials_src
->ServerCertificateSubject
);
1150 if (!http_credentials_dst
->ServerCertificateSubject
) goto error
;
1160 if (qos
->qos
->AdditionalSecurityInfoType
== RPC_C_AUTHN_INFO_TYPE_HTTP
&&
1161 qos
->qos
->u
.HttpCredentials
)
1163 if (qos
->qos
->u
.HttpCredentials
->TransportCredentials
)
1165 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->TransportCredentials
->User
);
1166 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->TransportCredentials
->Domain
);
1167 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->TransportCredentials
->Password
);
1168 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->TransportCredentials
);
1170 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->AuthnSchemes
);
1171 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->ServerCertificateSubject
);
1172 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
);
1174 HeapFree(GetProcessHeap(), 0, qos
->qos
);
1176 HeapFree(GetProcessHeap(), 0, qos
);
1177 return RPC_S_OUT_OF_RESOURCES
;
1180 ULONG
RpcQualityOfService_AddRef(RpcQualityOfService
*qos
)
1182 return InterlockedIncrement(&qos
->refs
);
1185 ULONG
RpcQualityOfService_Release(RpcQualityOfService
*qos
)
1187 ULONG refs
= InterlockedDecrement(&qos
->refs
);
1191 if (qos
->qos
->AdditionalSecurityInfoType
== RPC_C_AUTHN_INFO_TYPE_HTTP
)
1193 if (qos
->qos
->u
.HttpCredentials
->TransportCredentials
)
1195 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->TransportCredentials
->User
);
1196 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->TransportCredentials
->Domain
);
1197 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->TransportCredentials
->Password
);
1198 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->TransportCredentials
);
1200 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->AuthnSchemes
);
1201 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
->ServerCertificateSubject
);
1202 HeapFree(GetProcessHeap(), 0, qos
->qos
->u
.HttpCredentials
);
1204 HeapFree(GetProcessHeap(), 0, qos
->qos
);
1205 HeapFree(GetProcessHeap(), 0, qos
);
1210 BOOL
RpcQualityOfService_IsEqual(const RpcQualityOfService
*qos1
, const RpcQualityOfService
*qos2
)
1218 TRACE("qos1 = { %ld %ld %ld %ld }, qos2 = { %ld %ld %ld %ld }\n",
1219 qos1
->qos
->Capabilities
, qos1
->qos
->IdentityTracking
,
1220 qos1
->qos
->ImpersonationType
, qos1
->qos
->AdditionalSecurityInfoType
,
1221 qos2
->qos
->Capabilities
, qos2
->qos
->IdentityTracking
,
1222 qos2
->qos
->ImpersonationType
, qos2
->qos
->AdditionalSecurityInfoType
);
1224 if ((qos1
->qos
->Capabilities
!= qos2
->qos
->Capabilities
) ||
1225 (qos1
->qos
->IdentityTracking
!= qos2
->qos
->IdentityTracking
) ||
1226 (qos1
->qos
->ImpersonationType
!= qos2
->qos
->ImpersonationType
) ||
1227 (qos1
->qos
->AdditionalSecurityInfoType
!= qos2
->qos
->AdditionalSecurityInfoType
))
1230 if (qos1
->qos
->AdditionalSecurityInfoType
== RPC_C_AUTHN_INFO_TYPE_HTTP
)
1232 const RPC_HTTP_TRANSPORT_CREDENTIALS_W
*http_credentials1
= qos1
->qos
->u
.HttpCredentials
;
1233 const RPC_HTTP_TRANSPORT_CREDENTIALS_W
*http_credentials2
= qos2
->qos
->u
.HttpCredentials
;
1235 if (http_credentials1
->Flags
!= http_credentials2
->Flags
)
1238 if (http_credentials1
->AuthenticationTarget
!= http_credentials2
->AuthenticationTarget
)
1241 /* authentication schemes and server certificate subject not currently used */
1243 if (http_credentials1
->TransportCredentials
!= http_credentials2
->TransportCredentials
)
1245 const SEC_WINNT_AUTH_IDENTITY_W
*identity1
= http_credentials1
->TransportCredentials
;
1246 const SEC_WINNT_AUTH_IDENTITY_W
*identity2
= http_credentials2
->TransportCredentials
;
1248 if (!identity1
|| !identity2
)
1251 /* compare user names */
1252 if (identity1
->UserLength
!= identity2
->UserLength
||
1253 memcmp(identity1
->User
, identity2
->User
, identity1
->UserLength
))
1255 /* compare domain names */
1256 if (identity1
->DomainLength
!= identity2
->DomainLength
||
1257 memcmp(identity1
->Domain
, identity2
->Domain
, identity1
->DomainLength
))
1259 /* compare passwords */
1260 if (identity1
->PasswordLength
!= identity2
->PasswordLength
||
1261 memcmp(identity1
->Password
, identity2
->Password
, identity1
->PasswordLength
))
1269 /***********************************************************************
1270 * RpcRevertToSelf (RPCRT4.@)
1272 RPC_STATUS WINAPI
RpcRevertToSelf(void)
1279 /***********************************************************************
1280 * RpcMgmtSetComTimeout (RPCRT4.@)
1282 RPC_STATUS WINAPI
RpcMgmtSetComTimeout(RPC_BINDING_HANDLE BindingHandle
, unsigned int Timeout
)
1284 FIXME("(%p, %d): stub\n", BindingHandle
, Timeout
);
1288 /***********************************************************************
1289 * RpcBindingInqAuthInfoExA (RPCRT4.@)
1291 RPCRTAPI RPC_STATUS RPC_ENTRY
1292 RpcBindingInqAuthInfoExA( RPC_BINDING_HANDLE Binding
, RPC_CSTR
*ServerPrincName
, ULONG
*AuthnLevel
,
1293 ULONG
*AuthnSvc
, RPC_AUTH_IDENTITY_HANDLE
*AuthIdentity
, ULONG
*AuthzSvc
,
1294 ULONG RpcQosVersion
, RPC_SECURITY_QOS
*SecurityQOS
)
1296 FIXME("%p %p %p %p %p %p %u %p\n", Binding
, ServerPrincName
, AuthnLevel
,
1297 AuthnSvc
, AuthIdentity
, AuthzSvc
, RpcQosVersion
, SecurityQOS
);
1298 return RPC_S_INVALID_BINDING
;
1301 /***********************************************************************
1302 * RpcBindingInqAuthInfoExW (RPCRT4.@)
1304 RPCRTAPI RPC_STATUS RPC_ENTRY
1305 RpcBindingInqAuthInfoExW( RPC_BINDING_HANDLE Binding
, RPC_WSTR
*ServerPrincName
, ULONG
*AuthnLevel
,
1306 ULONG
*AuthnSvc
, RPC_AUTH_IDENTITY_HANDLE
*AuthIdentity
, ULONG
*AuthzSvc
,
1307 ULONG RpcQosVersion
, RPC_SECURITY_QOS
*SecurityQOS
)
1309 FIXME("%p %p %p %p %p %p %u %p\n", Binding
, ServerPrincName
, AuthnLevel
,
1310 AuthnSvc
, AuthIdentity
, AuthzSvc
, RpcQosVersion
, SecurityQOS
);
1311 return RPC_S_INVALID_BINDING
;
1314 /***********************************************************************
1315 * RpcBindingInqAuthInfoA (RPCRT4.@)
1317 RPCRTAPI RPC_STATUS RPC_ENTRY
1318 RpcBindingInqAuthInfoA( RPC_BINDING_HANDLE Binding
, RPC_CSTR
*ServerPrincName
, ULONG
*AuthnLevel
,
1319 ULONG
*AuthnSvc
, RPC_AUTH_IDENTITY_HANDLE
*AuthIdentity
, ULONG
*AuthzSvc
)
1321 FIXME("%p %p %p %p %p %p\n", Binding
, ServerPrincName
, AuthnLevel
,
1322 AuthnSvc
, AuthIdentity
, AuthzSvc
);
1323 return RPC_S_INVALID_BINDING
;
1326 /***********************************************************************
1327 * RpcBindingInqAuthInfoW (RPCRT4.@)
1329 RPCRTAPI RPC_STATUS RPC_ENTRY
1330 RpcBindingInqAuthInfoW( RPC_BINDING_HANDLE Binding
, RPC_WSTR
*ServerPrincName
, ULONG
*AuthnLevel
,
1331 ULONG
*AuthnSvc
, RPC_AUTH_IDENTITY_HANDLE
*AuthIdentity
, ULONG
*AuthzSvc
)
1333 FIXME("%p %p %p %p %p %p\n", Binding
, ServerPrincName
, AuthnLevel
,
1334 AuthnSvc
, AuthIdentity
, AuthzSvc
);
1335 return RPC_S_INVALID_BINDING
;
1338 /***********************************************************************
1339 * RpcBindingSetAuthInfoExA (RPCRT4.@)
1341 RPCRTAPI RPC_STATUS RPC_ENTRY
1342 RpcBindingSetAuthInfoExA( RPC_BINDING_HANDLE Binding
, RPC_CSTR ServerPrincName
,
1343 ULONG AuthnLevel
, ULONG AuthnSvc
,
1344 RPC_AUTH_IDENTITY_HANDLE AuthIdentity
, ULONG AuthzSvr
,
1345 RPC_SECURITY_QOS
*SecurityQos
)
1347 RpcBinding
* bind
= (RpcBinding
*)Binding
;
1351 ULONG package_count
;
1353 PSecPkgInfoA packages
;
1356 TRACE("%p %s %u %u %p %u %p\n", Binding
, debugstr_a((const char*)ServerPrincName
),
1357 AuthnLevel
, AuthnSvc
, AuthIdentity
, AuthzSvr
, SecurityQos
);
1363 TRACE("SecurityQos { Version=%ld, Capabilties=0x%lx, IdentityTracking=%ld, ImpersonationLevel=%ld",
1364 SecurityQos
->Version
, SecurityQos
->Capabilities
, SecurityQos
->IdentityTracking
, SecurityQos
->ImpersonationType
);
1365 if (SecurityQos
->Version
>= 2)
1367 const RPC_SECURITY_QOS_V2_A
*SecurityQos2
= (const RPC_SECURITY_QOS_V2_A
*)SecurityQos
;
1368 TRACE(", AdditionalSecurityInfoType=%ld", SecurityQos2
->AdditionalSecurityInfoType
);
1369 if (SecurityQos2
->AdditionalSecurityInfoType
== RPC_C_AUTHN_INFO_TYPE_HTTP
)
1370 TRACE(", { %p, 0x%lx, %ld, %ld, %p, %s }",
1371 SecurityQos2
->u
.HttpCredentials
->TransportCredentials
,
1372 SecurityQos2
->u
.HttpCredentials
->Flags
,
1373 SecurityQos2
->u
.HttpCredentials
->AuthenticationTarget
,
1374 SecurityQos2
->u
.HttpCredentials
->NumberOfAuthnSchemes
,
1375 SecurityQos2
->u
.HttpCredentials
->AuthnSchemes
,
1376 SecurityQos2
->u
.HttpCredentials
->ServerCertificateSubject
);
1379 status
= RpcQualityOfService_Create(SecurityQos
, FALSE
, &bind
->QOS
);
1380 if (status
!= RPC_S_OK
)
1385 if (bind
->QOS
) RpcQualityOfService_Release(bind
->QOS
);
1389 if (AuthnSvc
== RPC_C_AUTHN_DEFAULT
)
1390 AuthnSvc
= RPC_C_AUTHN_WINNT
;
1392 /* FIXME: the mapping should probably be retrieved using SSPI somehow */
1393 if (AuthnLevel
== RPC_C_AUTHN_LEVEL_DEFAULT
)
1394 AuthnLevel
= RPC_C_AUTHN_LEVEL_NONE
;
1396 if ((AuthnLevel
== RPC_C_AUTHN_LEVEL_NONE
) || (AuthnSvc
== RPC_C_AUTHN_NONE
))
1398 if (bind
->AuthInfo
) RpcAuthInfo_Release(bind
->AuthInfo
);
1399 bind
->AuthInfo
= NULL
;
1403 if (AuthnLevel
> RPC_C_AUTHN_LEVEL_PKT_PRIVACY
)
1405 FIXME("unknown AuthnLevel %u\n", AuthnLevel
);
1406 return RPC_S_UNKNOWN_AUTHN_LEVEL
;
1411 FIXME("unsupported AuthzSvr %u\n", AuthzSvr
);
1412 return RPC_S_UNKNOWN_AUTHZ_SERVICE
;
1415 r
= EnumerateSecurityPackagesA(&package_count
, &packages
);
1418 ERR("EnumerateSecurityPackagesA failed with error 0x%08x\n", r
);
1419 return RPC_S_SEC_PKG_ERROR
;
1422 for (i
= 0; i
< package_count
; i
++)
1423 if (packages
[i
].wRPCID
== AuthnSvc
)
1426 if (i
== package_count
)
1428 FIXME("unsupported AuthnSvc %u\n", AuthnSvc
);
1429 FreeContextBuffer(packages
);
1430 return RPC_S_UNKNOWN_AUTHN_SERVICE
;
1433 TRACE("found package %s for service %u\n", packages
[i
].Name
, AuthnSvc
);
1434 r
= AcquireCredentialsHandleA(NULL
, packages
[i
].Name
, SECPKG_CRED_OUTBOUND
, NULL
,
1435 AuthIdentity
, NULL
, NULL
, &cred
, &exp
);
1436 cbMaxToken
= packages
[i
].cbMaxToken
;
1437 FreeContextBuffer(packages
);
1438 if (r
== ERROR_SUCCESS
)
1440 RpcAuthInfo
*new_auth_info
;
1441 r
= RpcAuthInfo_Create(AuthnLevel
, AuthnSvc
, cred
, exp
, cbMaxToken
,
1442 AuthIdentity
, &new_auth_info
);
1445 new_auth_info
->server_principal_name
= RPCRT4_strdupAtoW((char *)ServerPrincName
);
1446 if (new_auth_info
->server_principal_name
)
1448 if (bind
->AuthInfo
) RpcAuthInfo_Release(bind
->AuthInfo
);
1449 bind
->AuthInfo
= new_auth_info
;
1453 RpcAuthInfo_Release(new_auth_info
);
1454 r
= ERROR_OUTOFMEMORY
;
1458 FreeCredentialsHandle(&cred
);
1463 ERR("AcquireCredentialsHandleA failed with error 0x%08x\n", r
);
1464 return RPC_S_SEC_PKG_ERROR
;
1468 /***********************************************************************
1469 * RpcBindingSetAuthInfoExW (RPCRT4.@)
1471 RPCRTAPI RPC_STATUS RPC_ENTRY
1472 RpcBindingSetAuthInfoExW( RPC_BINDING_HANDLE Binding
, RPC_WSTR ServerPrincName
, ULONG AuthnLevel
,
1473 ULONG AuthnSvc
, RPC_AUTH_IDENTITY_HANDLE AuthIdentity
, ULONG AuthzSvr
,
1474 RPC_SECURITY_QOS
*SecurityQos
)
1476 RpcBinding
* bind
= (RpcBinding
*)Binding
;
1480 ULONG package_count
;
1482 PSecPkgInfoW packages
;
1485 TRACE("%p %s %u %u %p %u %p\n", Binding
, debugstr_w((const WCHAR
*)ServerPrincName
),
1486 AuthnLevel
, AuthnSvc
, AuthIdentity
, AuthzSvr
, SecurityQos
);
1492 TRACE("SecurityQos { Version=%ld, Capabilties=0x%lx, IdentityTracking=%ld, ImpersonationLevel=%ld",
1493 SecurityQos
->Version
, SecurityQos
->Capabilities
, SecurityQos
->IdentityTracking
, SecurityQos
->ImpersonationType
);
1494 if (SecurityQos
->Version
>= 2)
1496 const RPC_SECURITY_QOS_V2_W
*SecurityQos2
= (const RPC_SECURITY_QOS_V2_W
*)SecurityQos
;
1497 TRACE(", AdditionalSecurityInfoType=%ld", SecurityQos2
->AdditionalSecurityInfoType
);
1498 if (SecurityQos2
->AdditionalSecurityInfoType
== RPC_C_AUTHN_INFO_TYPE_HTTP
)
1499 TRACE(", { %p, 0x%lx, %ld, %ld, %p, %s }",
1500 SecurityQos2
->u
.HttpCredentials
->TransportCredentials
,
1501 SecurityQos2
->u
.HttpCredentials
->Flags
,
1502 SecurityQos2
->u
.HttpCredentials
->AuthenticationTarget
,
1503 SecurityQos2
->u
.HttpCredentials
->NumberOfAuthnSchemes
,
1504 SecurityQos2
->u
.HttpCredentials
->AuthnSchemes
,
1505 debugstr_w(SecurityQos2
->u
.HttpCredentials
->ServerCertificateSubject
));
1508 status
= RpcQualityOfService_Create(SecurityQos
, TRUE
, &bind
->QOS
);
1509 if (status
!= RPC_S_OK
)
1514 if (bind
->QOS
) RpcQualityOfService_Release(bind
->QOS
);
1518 if (AuthnSvc
== RPC_C_AUTHN_DEFAULT
)
1519 AuthnSvc
= RPC_C_AUTHN_WINNT
;
1521 /* FIXME: the mapping should probably be retrieved using SSPI somehow */
1522 if (AuthnLevel
== RPC_C_AUTHN_LEVEL_DEFAULT
)
1523 AuthnLevel
= RPC_C_AUTHN_LEVEL_NONE
;
1525 if ((AuthnLevel
== RPC_C_AUTHN_LEVEL_NONE
) || (AuthnSvc
== RPC_C_AUTHN_NONE
))
1527 if (bind
->AuthInfo
) RpcAuthInfo_Release(bind
->AuthInfo
);
1528 bind
->AuthInfo
= NULL
;
1532 if (AuthnLevel
> RPC_C_AUTHN_LEVEL_PKT_PRIVACY
)
1534 FIXME("unknown AuthnLevel %u\n", AuthnLevel
);
1535 return RPC_S_UNKNOWN_AUTHN_LEVEL
;
1540 FIXME("unsupported AuthzSvr %u\n", AuthzSvr
);
1541 return RPC_S_UNKNOWN_AUTHZ_SERVICE
;
1544 r
= EnumerateSecurityPackagesW(&package_count
, &packages
);
1547 ERR("EnumerateSecurityPackagesA failed with error 0x%08x\n", r
);
1548 return RPC_S_SEC_PKG_ERROR
;
1551 for (i
= 0; i
< package_count
; i
++)
1552 if (packages
[i
].wRPCID
== AuthnSvc
)
1555 if (i
== package_count
)
1557 FIXME("unsupported AuthnSvc %u\n", AuthnSvc
);
1558 FreeContextBuffer(packages
);
1559 return RPC_S_UNKNOWN_AUTHN_SERVICE
;
1562 TRACE("found package %s for service %u\n", debugstr_w(packages
[i
].Name
), AuthnSvc
);
1563 r
= AcquireCredentialsHandleW(NULL
, packages
[i
].Name
, SECPKG_CRED_OUTBOUND
, NULL
,
1564 AuthIdentity
, NULL
, NULL
, &cred
, &exp
);
1565 cbMaxToken
= packages
[i
].cbMaxToken
;
1566 FreeContextBuffer(packages
);
1567 if (r
== ERROR_SUCCESS
)
1569 RpcAuthInfo
*new_auth_info
;
1570 r
= RpcAuthInfo_Create(AuthnLevel
, AuthnSvc
, cred
, exp
, cbMaxToken
,
1571 AuthIdentity
, &new_auth_info
);
1574 new_auth_info
->server_principal_name
= RPCRT4_strdupW(ServerPrincName
);
1575 if (new_auth_info
->server_principal_name
)
1577 if (bind
->AuthInfo
) RpcAuthInfo_Release(bind
->AuthInfo
);
1578 bind
->AuthInfo
= new_auth_info
;
1582 RpcAuthInfo_Release(new_auth_info
);
1583 r
= ERROR_OUTOFMEMORY
;
1587 FreeCredentialsHandle(&cred
);
1592 ERR("AcquireCredentialsHandleA failed with error 0x%08x\n", r
);
1593 return RPC_S_SEC_PKG_ERROR
;
1597 /***********************************************************************
1598 * RpcBindingSetAuthInfoA (RPCRT4.@)
1600 RPCRTAPI RPC_STATUS RPC_ENTRY
1601 RpcBindingSetAuthInfoA( RPC_BINDING_HANDLE Binding
, RPC_CSTR ServerPrincName
, ULONG AuthnLevel
,
1602 ULONG AuthnSvc
, RPC_AUTH_IDENTITY_HANDLE AuthIdentity
, ULONG AuthzSvr
)
1604 TRACE("%p %s %u %u %p %u\n", Binding
, debugstr_a((const char*)ServerPrincName
),
1605 AuthnLevel
, AuthnSvc
, AuthIdentity
, AuthzSvr
);
1606 return RpcBindingSetAuthInfoExA(Binding
, ServerPrincName
, AuthnLevel
, AuthnSvc
, AuthIdentity
, AuthzSvr
, NULL
);
1609 /***********************************************************************
1610 * RpcBindingSetAuthInfoW (RPCRT4.@)
1612 RPCRTAPI RPC_STATUS RPC_ENTRY
1613 RpcBindingSetAuthInfoW( RPC_BINDING_HANDLE Binding
, RPC_WSTR ServerPrincName
, ULONG AuthnLevel
,
1614 ULONG AuthnSvc
, RPC_AUTH_IDENTITY_HANDLE AuthIdentity
, ULONG AuthzSvr
)
1616 TRACE("%p %s %u %u %p %u\n", Binding
, debugstr_w((const WCHAR
*)ServerPrincName
),
1617 AuthnLevel
, AuthnSvc
, AuthIdentity
, AuthzSvr
);
1618 return RpcBindingSetAuthInfoExW(Binding
, ServerPrincName
, AuthnLevel
, AuthnSvc
, AuthIdentity
, AuthzSvr
, NULL
);
1621 /***********************************************************************
1622 * RpcBindingSetOption (RPCRT4.@)
1624 RPC_STATUS WINAPI
RpcBindingSetOption(RPC_BINDING_HANDLE BindingHandle
, ULONG Option
, ULONG OptionValue
)
1626 FIXME("(%p, %d, %d): stub\n", BindingHandle
, Option
, OptionValue
);