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_message.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 PRPC_SYNTAX_IDENTIFIER TransferSyntax,
278 PRPC_SYNTAX_IDENTIFIER InterfaceId)
280 RpcConnection* NewConnection;
283 TRACE("(Binding == ^%p)\n", Binding);
285 if (!Binding->server) {
286 /* try to find a compatible connection from the connection pool */
287 NewConnection = RpcAssoc_GetIdleConnection(Binding->Assoc, InterfaceId,
288 TransferSyntax, Binding->AuthInfo, Binding->QOS);
290 *Connection = NewConnection;
294 /* we already have a connection with acceptable binding, so use it */
295 if (Binding->FromConn) {
296 *Connection = Binding->FromConn;
301 /* create a new connection */
302 status = RPCRT4_CreateConnection(&NewConnection, Binding->server,
303 Binding->Protseq, Binding->NetworkAddr,
304 Binding->Endpoint, Binding->NetworkOptions,
305 Binding->AuthInfo, Binding->QOS);
306 if (status != RPC_S_OK)
309 status = RPCRT4_OpenClientConnection(NewConnection);
310 if (status != RPC_S_OK)
312 RPCRT4_DestroyConnection(NewConnection);
316 /* we need to send a binding packet if we are client. */
317 if (!NewConnection->server) {
319 RpcPktHdr *response_hdr;
322 TRACE("sending bind request to server\n");
324 hdr = RPCRT4_BuildBindHeader(NDR_LOCAL_DATA_REPRESENTATION,
325 RPC_MAX_PACKET_SIZE, RPC_MAX_PACKET_SIZE,
326 Binding->Assoc->assoc_group_id,
327 InterfaceId, TransferSyntax);
329 status = RPCRT4_Send(NewConnection, hdr, NULL, 0);
330 RPCRT4_FreeHeader(hdr);
331 if (status != RPC_S_OK) {
332 RPCRT4_DestroyConnection(NewConnection);
336 status = RPCRT4_Receive(NewConnection, &response_hdr, &msg);
337 if (status != RPC_S_OK) {
338 ERR("receive failed\n");
339 RPCRT4_DestroyConnection(NewConnection);
343 if (response_hdr->common.ptype != PKT_BIND_ACK ||
344 response_hdr->bind_ack.max_tsize < RPC_MIN_PACKET_SIZE) {
345 ERR("failed to bind for interface %s, %d.%d\n",
346 debugstr_guid(&InterfaceId->SyntaxGUID),
347 InterfaceId->SyntaxVersion.MajorVersion,
348 InterfaceId->SyntaxVersion.MinorVersion);
349 RPCRT4_FreeHeader(response_hdr);
350 RPCRT4_DestroyConnection(NewConnection);
351 return RPC_S_PROTOCOL_ERROR;
354 /* FIXME: do more checks? */
356 NewConnection->MaxTransmissionSize = response_hdr->bind_ack.max_tsize;
357 NewConnection->ActiveInterface = *InterfaceId;
358 RPCRT4_FreeHeader(response_hdr);
362 Binding->FromConn = NewConnection;
363 *Connection = NewConnection;
368 RPC_STATUS RPCRT4_CloseBinding(RpcBinding* Binding, RpcConnection* Connection)
370 TRACE("(Binding == ^%p)\n", Binding);
371 if (!Connection) return RPC_S_OK;
372 if (Binding->server) {
373 /* don't destroy a connection that is cached in the binding */
374 if (Binding->FromConn == Connection)
376 return RPCRT4_DestroyConnection(Connection);
379 RpcAssoc_ReleaseIdleConnection(Binding->Assoc, Connection);
384 /* utility functions for string composing and parsing */
385 static unsigned RPCRT4_strcopyA(LPSTR data, LPCSTR src)
387 unsigned len = strlen(src);
388 memcpy(data, src, len*sizeof(CHAR));
392 static unsigned RPCRT4_strcopyW(LPWSTR data, LPCWSTR src)
394 unsigned len = strlenW(src);
395 memcpy(data, src, len*sizeof(WCHAR));
399 static LPSTR RPCRT4_strconcatA(LPSTR dst, LPCSTR src)
401 DWORD len = strlen(dst), slen = strlen(src);
402 LPSTR ndst = HeapReAlloc(GetProcessHeap(), 0, dst, (len+slen+2)*sizeof(CHAR));
405 HeapFree(GetProcessHeap(), 0, dst);
409 memcpy(ndst+len+1, src, slen+1);
413 static LPWSTR RPCRT4_strconcatW(LPWSTR dst, LPCWSTR src)
415 DWORD len = strlenW(dst), slen = strlenW(src);
416 LPWSTR ndst = HeapReAlloc(GetProcessHeap(), 0, dst, (len+slen+2)*sizeof(WCHAR));
419 HeapFree(GetProcessHeap(), 0, dst);
423 memcpy(ndst+len+1, src, (slen+1)*sizeof(WCHAR));
428 /***********************************************************************
429 * RpcStringBindingComposeA (RPCRT4.@)
431 RPC_STATUS WINAPI RpcStringBindingComposeA(RPC_CSTR ObjUuid, RPC_CSTR Protseq,
432 RPC_CSTR NetworkAddr, RPC_CSTR Endpoint,
433 RPC_CSTR Options, RPC_CSTR *StringBinding )
438 TRACE( "(%s,%s,%s,%s,%s,%p)\n",
439 debugstr_a( (char*)ObjUuid ), debugstr_a( (char*)Protseq ),
440 debugstr_a( (char*)NetworkAddr ), debugstr_a( (char*)Endpoint ),
441 debugstr_a( (char*)Options ), StringBinding );
443 if (ObjUuid && *ObjUuid) len += strlen((char*)ObjUuid) + 1;
444 if (Protseq && *Protseq) len += strlen((char*)Protseq) + 1;
445 if (NetworkAddr && *NetworkAddr) len += strlen((char*)NetworkAddr);
446 if (Endpoint && *Endpoint) len += strlen((char*)Endpoint) + 2;
447 if (Options && *Options) len += strlen((char*)Options) + 2;
449 data = HeapAlloc(GetProcessHeap(), 0, len);
450 *StringBinding = (unsigned char*)data;
452 if (ObjUuid && *ObjUuid) {
453 data += RPCRT4_strcopyA(data, (char*)ObjUuid);
456 if (Protseq && *Protseq) {
457 data += RPCRT4_strcopyA(data, (char*)Protseq);
460 if (NetworkAddr && *NetworkAddr)
461 data += RPCRT4_strcopyA(data, (char*)NetworkAddr);
463 if ((Endpoint && *Endpoint) ||
464 (Options && *Options)) {
466 if (Endpoint && *Endpoint) {
467 data += RPCRT4_strcopyA(data, (char*)Endpoint);
468 if (Options && *Options) *data++ = ',';
470 if (Options && *Options) {
471 data += RPCRT4_strcopyA(data, (char*)Options);
480 /***********************************************************************
481 * RpcStringBindingComposeW (RPCRT4.@)
483 RPC_STATUS WINAPI RpcStringBindingComposeW( RPC_WSTR ObjUuid, RPC_WSTR Protseq,
484 RPC_WSTR NetworkAddr, RPC_WSTR Endpoint,
485 RPC_WSTR Options, RPC_WSTR* StringBinding )
490 TRACE("(%s,%s,%s,%s,%s,%p)\n",
491 debugstr_w( ObjUuid ), debugstr_w( Protseq ),
492 debugstr_w( NetworkAddr ), debugstr_w( Endpoint ),
493 debugstr_w( Options ), StringBinding);
495 if (ObjUuid && *ObjUuid) len += strlenW(ObjUuid) + 1;
496 if (Protseq && *Protseq) len += strlenW(Protseq) + 1;
497 if (NetworkAddr && *NetworkAddr) len += strlenW(NetworkAddr);
498 if (Endpoint && *Endpoint) len += strlenW(Endpoint) + 2;
499 if (Options && *Options) len += strlenW(Options) + 2;
501 data = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
502 *StringBinding = data;
504 if (ObjUuid && *ObjUuid) {
505 data += RPCRT4_strcopyW(data, ObjUuid);
508 if (Protseq && *Protseq) {
509 data += RPCRT4_strcopyW(data, Protseq);
512 if (NetworkAddr && *NetworkAddr) {
513 data += RPCRT4_strcopyW(data, NetworkAddr);
515 if ((Endpoint && *Endpoint) ||
516 (Options && *Options)) {
518 if (Endpoint && *Endpoint) {
519 data += RPCRT4_strcopyW(data, Endpoint);
520 if (Options && *Options) *data++ = ',';
522 if (Options && *Options) {
523 data += RPCRT4_strcopyW(data, Options);
533 /***********************************************************************
534 * RpcStringBindingParseA (RPCRT4.@)
536 RPC_STATUS WINAPI RpcStringBindingParseA( RPC_CSTR StringBinding, RPC_CSTR *ObjUuid,
537 RPC_CSTR *Protseq, RPC_CSTR *NetworkAddr,
538 RPC_CSTR *Endpoint, RPC_CSTR *Options)
541 static const char ep_opt[] = "endpoint=";
543 TRACE("(%s,%p,%p,%p,%p,%p)\n", debugstr_a((char*)StringBinding),
544 ObjUuid, Protseq, NetworkAddr, Endpoint, Options);
546 if (ObjUuid) *ObjUuid = NULL;
547 if (Protseq) *Protseq = NULL;
548 if (NetworkAddr) *NetworkAddr = NULL;
549 if (Endpoint) *Endpoint = NULL;
550 if (Options) *Options = NULL;
552 data = (char*) StringBinding;
554 next = strchr(data, '@');
556 if (ObjUuid) *ObjUuid = (unsigned char*)RPCRT4_strndupA(data, next - data);
560 next = strchr(data, ':');
562 if (Protseq) *Protseq = (unsigned char*)RPCRT4_strndupA(data, next - data);
566 next = strchr(data, '[');
570 if (NetworkAddr) *NetworkAddr = (unsigned char*)RPCRT4_strndupA(data, next - data);
572 close = strchr(data, ']');
573 if (!close) goto fail;
575 /* tokenize options */
576 while (data < close) {
577 next = strchr(data, ',');
578 if (!next || next > close) next = close;
579 /* FIXME: this is kind of inefficient */
580 opt = RPCRT4_strndupA(data, next - data);
584 next = strchr(opt, '=');
586 /* not an option, must be an endpoint */
587 if (*Endpoint) goto fail;
588 *Endpoint = (unsigned char*) opt;
590 if (strncmp(opt, ep_opt, strlen(ep_opt)) == 0) {
591 /* endpoint option */
592 if (*Endpoint) goto fail;
593 *Endpoint = (unsigned char*) RPCRT4_strdupA(next+1);
594 HeapFree(GetProcessHeap(), 0, opt);
598 /* FIXME: this is kind of inefficient */
599 *Options = (unsigned char*) RPCRT4_strconcatA( (char*)*Options, opt);
600 HeapFree(GetProcessHeap(), 0, opt);
602 *Options = (unsigned char*) opt;
608 if (*data) goto fail;
610 else if (NetworkAddr)
611 *NetworkAddr = (unsigned char*)RPCRT4_strdupA(data);
616 if (ObjUuid) RpcStringFreeA((unsigned char**)ObjUuid);
617 if (Protseq) RpcStringFreeA((unsigned char**)Protseq);
618 if (NetworkAddr) RpcStringFreeA((unsigned char**)NetworkAddr);
619 if (Endpoint) RpcStringFreeA((unsigned char**)Endpoint);
620 if (Options) RpcStringFreeA((unsigned char**)Options);
621 return RPC_S_INVALID_STRING_BINDING;
624 /***********************************************************************
625 * RpcStringBindingParseW (RPCRT4.@)
627 RPC_STATUS WINAPI RpcStringBindingParseW( RPC_WSTR StringBinding, RPC_WSTR *ObjUuid,
628 RPC_WSTR *Protseq, RPC_WSTR *NetworkAddr,
629 RPC_WSTR *Endpoint, RPC_WSTR *Options)
632 static const WCHAR ep_opt[] = {'e','n','d','p','o','i','n','t','=',0};
634 TRACE("(%s,%p,%p,%p,%p,%p)\n", debugstr_w(StringBinding),
635 ObjUuid, Protseq, NetworkAddr, Endpoint, Options);
637 if (ObjUuid) *ObjUuid = NULL;
638 if (Protseq) *Protseq = NULL;
639 if (NetworkAddr) *NetworkAddr = NULL;
640 if (Endpoint) *Endpoint = NULL;
641 if (Options) *Options = NULL;
643 data = StringBinding;
645 next = strchrW(data, '@');
647 if (ObjUuid) *ObjUuid = RPCRT4_strndupW(data, next - data);
651 next = strchrW(data, ':');
653 if (Protseq) *Protseq = RPCRT4_strndupW(data, next - data);
657 next = strchrW(data, '[');
661 if (NetworkAddr) *NetworkAddr = RPCRT4_strndupW(data, next - data);
663 close = strchrW(data, ']');
664 if (!close) goto fail;
666 /* tokenize options */
667 while (data < close) {
668 next = strchrW(data, ',');
669 if (!next || next > close) next = close;
670 /* FIXME: this is kind of inefficient */
671 opt = RPCRT4_strndupW(data, next - data);
675 next = strchrW(opt, '=');
677 /* not an option, must be an endpoint */
678 if (*Endpoint) goto fail;
681 if (strncmpW(opt, ep_opt, strlenW(ep_opt)) == 0) {
682 /* endpoint option */
683 if (*Endpoint) goto fail;
684 *Endpoint = RPCRT4_strdupW(next+1);
685 HeapFree(GetProcessHeap(), 0, opt);
689 /* FIXME: this is kind of inefficient */
690 *Options = RPCRT4_strconcatW(*Options, opt);
691 HeapFree(GetProcessHeap(), 0, opt);
699 if (*data) goto fail;
700 } else if (NetworkAddr)
701 *NetworkAddr = RPCRT4_strdupW(data);
706 if (ObjUuid) RpcStringFreeW(ObjUuid);
707 if (Protseq) RpcStringFreeW(Protseq);
708 if (NetworkAddr) RpcStringFreeW(NetworkAddr);
709 if (Endpoint) RpcStringFreeW(Endpoint);
710 if (Options) RpcStringFreeW(Options);
711 return RPC_S_INVALID_STRING_BINDING;
714 /***********************************************************************
715 * RpcBindingFree (RPCRT4.@)
717 RPC_STATUS WINAPI RpcBindingFree( RPC_BINDING_HANDLE* Binding )
720 TRACE("(%p) = %p\n", Binding, *Binding);
721 status = RPCRT4_DestroyBinding(*Binding);
722 if (status == RPC_S_OK) *Binding = 0;
726 /***********************************************************************
727 * RpcBindingVectorFree (RPCRT4.@)
729 RPC_STATUS WINAPI RpcBindingVectorFree( RPC_BINDING_VECTOR** BindingVector )
734 TRACE("(%p)\n", BindingVector);
735 for (c=0; c<(*BindingVector)->Count; c++) {
736 status = RpcBindingFree(&(*BindingVector)->BindingH[c]);
738 HeapFree(GetProcessHeap(), 0, *BindingVector);
739 *BindingVector = NULL;
743 /***********************************************************************
744 * RpcBindingInqObject (RPCRT4.@)
746 RPC_STATUS WINAPI RpcBindingInqObject( RPC_BINDING_HANDLE Binding, UUID* ObjectUuid )
748 RpcBinding* bind = (RpcBinding*)Binding;
750 TRACE("(%p,%p) = %s\n", Binding, ObjectUuid, debugstr_guid(&bind->ObjectUuid));
751 memcpy(ObjectUuid, &bind->ObjectUuid, sizeof(UUID));
755 /***********************************************************************
756 * RpcBindingSetObject (RPCRT4.@)
758 RPC_STATUS WINAPI RpcBindingSetObject( RPC_BINDING_HANDLE Binding, UUID* ObjectUuid )
760 RpcBinding* bind = (RpcBinding*)Binding;
762 TRACE("(%p,%s)\n", Binding, debugstr_guid(ObjectUuid));
763 if (bind->server) return RPC_S_WRONG_KIND_OF_BINDING;
764 return RPCRT4_SetBindingObject(Binding, ObjectUuid);
767 /***********************************************************************
768 * RpcBindingFromStringBindingA (RPCRT4.@)
770 RPC_STATUS WINAPI RpcBindingFromStringBindingA( RPC_CSTR StringBinding, RPC_BINDING_HANDLE* Binding )
773 RpcBinding* bind = NULL;
774 RPC_CSTR ObjectUuid, Protseq, NetworkAddr, Endpoint, Options;
777 TRACE("(%s,%p)\n", debugstr_a((char*)StringBinding), Binding);
779 ret = RpcStringBindingParseA(StringBinding, &ObjectUuid, &Protseq,
780 &NetworkAddr, &Endpoint, &Options);
781 if (ret != RPC_S_OK) return ret;
783 ret = UuidFromStringA(ObjectUuid, &Uuid);
786 ret = RPCRT4_CreateBindingA(&bind, FALSE, (char*)Protseq);
788 ret = RPCRT4_SetBindingObject(bind, &Uuid);
790 ret = RPCRT4_CompleteBindingA(bind, (char*)NetworkAddr, (char*)Endpoint, (char*)Options);
792 RpcStringFreeA((unsigned char**)&Options);
793 RpcStringFreeA((unsigned char**)&Endpoint);
794 RpcStringFreeA((unsigned char**)&NetworkAddr);
795 RpcStringFreeA((unsigned char**)&Protseq);
796 RpcStringFreeA((unsigned char**)&ObjectUuid);
799 *Binding = (RPC_BINDING_HANDLE)bind;
801 RPCRT4_DestroyBinding(bind);
806 /***********************************************************************
807 * RpcBindingFromStringBindingW (RPCRT4.@)
809 RPC_STATUS WINAPI RpcBindingFromStringBindingW( RPC_WSTR StringBinding, RPC_BINDING_HANDLE* Binding )
812 RpcBinding* bind = NULL;
813 RPC_WSTR ObjectUuid, Protseq, NetworkAddr, Endpoint, Options;
816 TRACE("(%s,%p)\n", debugstr_w(StringBinding), Binding);
818 ret = RpcStringBindingParseW(StringBinding, &ObjectUuid, &Protseq,
819 &NetworkAddr, &Endpoint, &Options);
820 if (ret != RPC_S_OK) return ret;
822 ret = UuidFromStringW(ObjectUuid, &Uuid);
825 ret = RPCRT4_CreateBindingW(&bind, FALSE, Protseq);
827 ret = RPCRT4_SetBindingObject(bind, &Uuid);
829 ret = RPCRT4_CompleteBindingW(bind, NetworkAddr, Endpoint, Options);
831 RpcStringFreeW(&Options);
832 RpcStringFreeW(&Endpoint);
833 RpcStringFreeW(&NetworkAddr);
834 RpcStringFreeW(&Protseq);
835 RpcStringFreeW(&ObjectUuid);
838 *Binding = (RPC_BINDING_HANDLE)bind;
840 RPCRT4_DestroyBinding(bind);
845 /***********************************************************************
846 * RpcBindingToStringBindingA (RPCRT4.@)
848 RPC_STATUS WINAPI RpcBindingToStringBindingA( RPC_BINDING_HANDLE Binding, RPC_CSTR *StringBinding )
851 RpcBinding* bind = (RpcBinding*)Binding;
854 TRACE("(%p,%p)\n", Binding, StringBinding);
856 ret = UuidToStringA(&bind->ObjectUuid, &ObjectUuid);
857 if (ret != RPC_S_OK) return ret;
859 ret = RpcStringBindingComposeA(ObjectUuid, (unsigned char*)bind->Protseq, (unsigned char*) bind->NetworkAddr,
860 (unsigned char*) bind->Endpoint, NULL, StringBinding);
862 RpcStringFreeA(&ObjectUuid);
867 /***********************************************************************
868 * RpcBindingToStringBindingW (RPCRT4.@)
870 RPC_STATUS WINAPI RpcBindingToStringBindingW( RPC_BINDING_HANDLE Binding, RPC_WSTR *StringBinding )
873 unsigned char *str = NULL;
874 TRACE("(%p,%p)\n", Binding, StringBinding);
875 ret = RpcBindingToStringBindingA(Binding, &str);
876 *StringBinding = RPCRT4_strdupAtoW((char*)str);
877 RpcStringFreeA((unsigned char**)&str);
881 /***********************************************************************
882 * I_RpcBindingSetAsync (RPCRT4.@)
884 * Exists in win9x and winNT, but with different number of arguments
885 * (9x version has 3 arguments, NT has 2).
887 RPC_STATUS WINAPI I_RpcBindingSetAsync( RPC_BINDING_HANDLE Binding, RPC_BLOCKING_FN BlockingFn)
889 RpcBinding* bind = (RpcBinding*)Binding;
891 TRACE( "(%p,%p): stub\n", Binding, BlockingFn );
893 bind->BlockingFn = BlockingFn;
898 /***********************************************************************
899 * RpcBindingCopy (RPCRT4.@)
901 RPC_STATUS RPC_ENTRY RpcBindingCopy(
902 RPC_BINDING_HANDLE SourceBinding,
903 RPC_BINDING_HANDLE* DestinationBinding)
905 RpcBinding *DestBinding;
906 RpcBinding *SrcBinding = (RpcBinding*)SourceBinding;
909 TRACE("(%p, %p)\n", SourceBinding, DestinationBinding);
911 status = RPCRT4_AllocBinding(&DestBinding, SrcBinding->server);
912 if (status != RPC_S_OK) return status;
914 DestBinding->ObjectUuid = SrcBinding->ObjectUuid;
915 DestBinding->BlockingFn = SrcBinding->BlockingFn;
916 DestBinding->Protseq = RPCRT4_strndupA(SrcBinding->Protseq, -1);
917 DestBinding->NetworkAddr = RPCRT4_strndupA(SrcBinding->NetworkAddr, -1);
918 DestBinding->Endpoint = RPCRT4_strndupA(SrcBinding->Endpoint, -1);
919 DestBinding->NetworkOptions = RPCRT4_strdupW(SrcBinding->NetworkOptions);
920 if (SrcBinding->Assoc) SrcBinding->Assoc->refs++;
921 DestBinding->Assoc = SrcBinding->Assoc;
923 if (SrcBinding->AuthInfo) RpcAuthInfo_AddRef(SrcBinding->AuthInfo);
924 DestBinding->AuthInfo = SrcBinding->AuthInfo;
925 if (SrcBinding->QOS) RpcQualityOfService_AddRef(SrcBinding->QOS);
926 DestBinding->QOS = SrcBinding->QOS;
928 *DestinationBinding = DestBinding;
932 /***********************************************************************
933 * RpcImpersonateClient (RPCRT4.@)
935 * Impersonates the client connected via a binding handle so that security
936 * checks are done in the context of the client.
939 * BindingHandle [I] Handle to the binding to the client.
943 * Failure: RPC_STATUS value.
947 * If BindingHandle is NULL then the function impersonates the client
948 * connected to the binding handle of the current thread.
950 RPC_STATUS WINAPI RpcImpersonateClient(RPC_BINDING_HANDLE BindingHandle)
952 FIXME("(%p): stub\n", BindingHandle);
953 ImpersonateSelf(SecurityImpersonation);
957 /***********************************************************************
958 * RpcRevertToSelfEx (RPCRT4.@)
960 * Stops impersonating the client connected to the binding handle so that security
961 * checks are no longer done in the context of the client.
964 * BindingHandle [I] Handle to the binding to the client.
968 * Failure: RPC_STATUS value.
972 * If BindingHandle is NULL then the function stops impersonating the client
973 * connected to the binding handle of the current thread.
975 RPC_STATUS WINAPI RpcRevertToSelfEx(RPC_BINDING_HANDLE BindingHandle)
977 FIXME("(%p): stub\n", BindingHandle);
981 static inline BOOL has_nt_auth_identity(ULONG AuthnLevel)
985 case RPC_C_AUTHN_GSS_NEGOTIATE:
986 case RPC_C_AUTHN_WINNT:
987 case RPC_C_AUTHN_GSS_KERBEROS:
994 static RPC_STATUS RpcAuthInfo_Create(ULONG AuthnLevel, ULONG AuthnSvc,
995 CredHandle cred, TimeStamp exp,
997 RPC_AUTH_IDENTITY_HANDLE identity,
1000 RpcAuthInfo *AuthInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(*AuthInfo));
1002 return ERROR_OUTOFMEMORY;
1005 AuthInfo->AuthnLevel = AuthnLevel;
1006 AuthInfo->AuthnSvc = AuthnSvc;
1007 AuthInfo->cred = cred;
1008 AuthInfo->exp = exp;
1009 AuthInfo->cbMaxToken = cbMaxToken;
1010 AuthInfo->identity = identity;
1012 /* duplicate the SEC_WINNT_AUTH_IDENTITY structure, if applicable, to
1013 * enable better matching in RpcAuthInfo_IsEqual */
1014 if (identity && has_nt_auth_identity(AuthnSvc))
1016 const SEC_WINNT_AUTH_IDENTITY_W *nt_identity = identity;
1017 AuthInfo->nt_identity = HeapAlloc(GetProcessHeap(), 0, sizeof(*AuthInfo->nt_identity));
1018 if (!AuthInfo->nt_identity)
1020 HeapFree(GetProcessHeap(), 0, AuthInfo);
1021 return ERROR_OUTOFMEMORY;
1024 AuthInfo->nt_identity->Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
1025 if (nt_identity->Flags & SEC_WINNT_AUTH_IDENTITY_UNICODE)
1026 AuthInfo->nt_identity->User = RPCRT4_strndupW(nt_identity->User, nt_identity->UserLength);
1028 AuthInfo->nt_identity->User = RPCRT4_strndupAtoW((const char *)nt_identity->User, nt_identity->UserLength);
1029 AuthInfo->nt_identity->UserLength = nt_identity->UserLength;
1030 if (nt_identity->Flags & SEC_WINNT_AUTH_IDENTITY_UNICODE)
1031 AuthInfo->nt_identity->Domain = RPCRT4_strndupW(nt_identity->Domain, nt_identity->DomainLength);
1033 AuthInfo->nt_identity->Domain = RPCRT4_strndupAtoW((const char *)nt_identity->Domain, nt_identity->DomainLength);
1034 AuthInfo->nt_identity->DomainLength = nt_identity->DomainLength;
1035 if (nt_identity->Flags & SEC_WINNT_AUTH_IDENTITY_UNICODE)
1036 AuthInfo->nt_identity->Password = RPCRT4_strndupW(nt_identity->Password, nt_identity->PasswordLength);
1038 AuthInfo->nt_identity->Password = RPCRT4_strndupAtoW((const char *)nt_identity->Password, nt_identity->PasswordLength);
1039 AuthInfo->nt_identity->PasswordLength = nt_identity->PasswordLength;
1041 if (!AuthInfo->nt_identity->User ||
1042 !AuthInfo->nt_identity->Domain ||
1043 !AuthInfo->nt_identity->Password)
1045 HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity->User);
1046 HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity->Domain);
1047 HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity->Password);
1048 HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity);
1049 HeapFree(GetProcessHeap(), 0, AuthInfo);
1050 return ERROR_OUTOFMEMORY;
1054 AuthInfo->nt_identity = NULL;
1059 ULONG RpcAuthInfo_AddRef(RpcAuthInfo *AuthInfo)
1061 return InterlockedIncrement(&AuthInfo->refs);
1064 ULONG RpcAuthInfo_Release(RpcAuthInfo *AuthInfo)
1066 ULONG refs = InterlockedDecrement(&AuthInfo->refs);
1070 FreeCredentialsHandle(&AuthInfo->cred);
1071 if (AuthInfo->nt_identity)
1073 HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity->User);
1074 HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity->Domain);
1075 HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity->User);
1076 HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity);
1078 HeapFree(GetProcessHeap(), 0, AuthInfo);
1084 BOOL RpcAuthInfo_IsEqual(const RpcAuthInfo *AuthInfo1, const RpcAuthInfo *AuthInfo2)
1086 if (AuthInfo1 == AuthInfo2)
1089 if (!AuthInfo1 || !AuthInfo2)
1092 if ((AuthInfo1->AuthnLevel != AuthInfo2->AuthnLevel) ||
1093 (AuthInfo1->AuthnSvc != AuthInfo2->AuthnSvc))
1096 if (AuthInfo1->identity == AuthInfo2->identity)
1099 if (!AuthInfo1->identity || !AuthInfo2->identity)
1102 if (has_nt_auth_identity(AuthInfo1->AuthnSvc))
1104 const SEC_WINNT_AUTH_IDENTITY_W *identity1 = AuthInfo1->nt_identity;
1105 const SEC_WINNT_AUTH_IDENTITY_W *identity2 = AuthInfo2->nt_identity;
1106 /* compare user names */
1107 if (identity1->UserLength != identity2->UserLength ||
1108 memcmp(identity1->User, identity2->User, identity1->UserLength))
1110 /* compare domain names */
1111 if (identity1->DomainLength != identity2->DomainLength ||
1112 memcmp(identity1->Domain, identity2->Domain, identity1->DomainLength))
1114 /* compare passwords */
1115 if (identity1->PasswordLength != identity2->PasswordLength ||
1116 memcmp(identity1->Password, identity2->Password, identity1->PasswordLength))
1125 static RPC_STATUS RpcQualityOfService_Create(const RPC_SECURITY_QOS *qos_src, BOOL unicode, RpcQualityOfService **qos_dst)
1127 RpcQualityOfService *qos = HeapAlloc(GetProcessHeap(), 0, sizeof(*qos));
1130 return RPC_S_OUT_OF_RESOURCES;
1133 qos->qos = HeapAlloc(GetProcessHeap(), 0, sizeof(*qos->qos));
1134 if (!qos->qos) goto error;
1135 qos->qos->Version = qos_src->Version;
1136 qos->qos->Capabilities = qos_src->Capabilities;
1137 qos->qos->IdentityTracking = qos_src->IdentityTracking;
1138 qos->qos->ImpersonationType = qos_src->ImpersonationType;
1139 qos->qos->AdditionalSecurityInfoType = 0;
1141 if (qos_src->Version >= 2)
1143 const RPC_SECURITY_QOS_V2_W *qos_src2 = (const RPC_SECURITY_QOS_V2_W *)qos_src;
1144 qos->qos->AdditionalSecurityInfoType = qos_src2->AdditionalSecurityInfoType;
1145 if (qos_src2->AdditionalSecurityInfoType == RPC_C_AUTHN_INFO_TYPE_HTTP)
1147 const RPC_HTTP_TRANSPORT_CREDENTIALS_W *http_credentials_src = qos_src2->u.HttpCredentials;
1148 RPC_HTTP_TRANSPORT_CREDENTIALS_W *http_credentials_dst;
1150 http_credentials_dst = HeapAlloc(GetProcessHeap(), 0, sizeof(*http_credentials_dst));
1151 qos->qos->u.HttpCredentials = http_credentials_dst;
1152 if (!http_credentials_dst) goto error;
1153 http_credentials_dst->TransportCredentials = NULL;
1154 http_credentials_dst->Flags = http_credentials_src->Flags;
1155 http_credentials_dst->AuthenticationTarget = http_credentials_src->AuthenticationTarget;
1156 http_credentials_dst->NumberOfAuthnSchemes = http_credentials_src->NumberOfAuthnSchemes;
1157 http_credentials_dst->AuthnSchemes = NULL;
1158 http_credentials_dst->ServerCertificateSubject = NULL;
1159 if (http_credentials_src->TransportCredentials)
1161 SEC_WINNT_AUTH_IDENTITY_W *cred_dst;
1162 cred_dst = http_credentials_dst->TransportCredentials = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*cred_dst));
1163 if (!cred_dst) goto error;
1164 cred_dst->Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
1167 const SEC_WINNT_AUTH_IDENTITY_W *cred_src = http_credentials_src->TransportCredentials;
1168 cred_dst->UserLength = cred_src->UserLength;
1169 cred_dst->PasswordLength = cred_src->PasswordLength;
1170 cred_dst->DomainLength = cred_src->DomainLength;
1171 cred_dst->User = RPCRT4_strndupW(cred_src->User, cred_src->UserLength);
1172 cred_dst->Password = RPCRT4_strndupW(cred_src->Password, cred_src->PasswordLength);
1173 cred_dst->Domain = RPCRT4_strndupW(cred_src->Domain, cred_src->DomainLength);
1177 const SEC_WINNT_AUTH_IDENTITY_A *cred_src = (const SEC_WINNT_AUTH_IDENTITY_A *)http_credentials_src->TransportCredentials;
1178 cred_dst->UserLength = MultiByteToWideChar(CP_ACP, 0, (char *)cred_src->User, cred_src->UserLength, NULL, 0);
1179 cred_dst->DomainLength = MultiByteToWideChar(CP_ACP, 0, (char *)cred_src->Domain, cred_src->DomainLength, NULL, 0);
1180 cred_dst->PasswordLength = MultiByteToWideChar(CP_ACP, 0, (char *)cred_src->Password, cred_src->PasswordLength, NULL, 0);
1181 cred_dst->User = HeapAlloc(GetProcessHeap(), 0, cred_dst->UserLength * sizeof(WCHAR));
1182 cred_dst->Password = HeapAlloc(GetProcessHeap(), 0, cred_dst->PasswordLength * sizeof(WCHAR));
1183 cred_dst->Domain = HeapAlloc(GetProcessHeap(), 0, cred_dst->DomainLength * sizeof(WCHAR));
1184 if (!cred_dst || !cred_dst->Password || !cred_dst->Domain) goto error;
1185 MultiByteToWideChar(CP_ACP, 0, (char *)cred_src->User, cred_src->UserLength, cred_dst->User, cred_dst->UserLength);
1186 MultiByteToWideChar(CP_ACP, 0, (char *)cred_src->Domain, cred_src->DomainLength, cred_dst->Domain, cred_dst->DomainLength);
1187 MultiByteToWideChar(CP_ACP, 0, (char *)cred_src->Password, cred_src->PasswordLength, cred_dst->Password, cred_dst->PasswordLength);
1190 if (http_credentials_src->NumberOfAuthnSchemes)
1192 http_credentials_dst->AuthnSchemes = HeapAlloc(GetProcessHeap(), 0, http_credentials_src->NumberOfAuthnSchemes * sizeof(*http_credentials_dst->AuthnSchemes));
1193 if (!http_credentials_dst->AuthnSchemes) goto error;
1194 memcpy(http_credentials_dst->AuthnSchemes, http_credentials_src->AuthnSchemes, http_credentials_src->NumberOfAuthnSchemes * sizeof(*http_credentials_dst->AuthnSchemes));
1196 if (http_credentials_src->ServerCertificateSubject)
1199 http_credentials_dst->ServerCertificateSubject =
1200 RPCRT4_strndupW(http_credentials_src->ServerCertificateSubject,
1201 strlenW(http_credentials_src->ServerCertificateSubject));
1203 http_credentials_dst->ServerCertificateSubject =
1204 RPCRT4_strdupAtoW((char *)http_credentials_src->ServerCertificateSubject);
1205 if (!http_credentials_dst->ServerCertificateSubject) goto error;
1215 if (qos->qos->AdditionalSecurityInfoType == RPC_C_AUTHN_INFO_TYPE_HTTP &&
1216 qos->qos->u.HttpCredentials)
1218 if (qos->qos->u.HttpCredentials->TransportCredentials)
1220 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials->User);
1221 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials->Domain);
1222 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials->Password);
1223 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials);
1225 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->AuthnSchemes);
1226 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->ServerCertificateSubject);
1227 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials);
1229 HeapFree(GetProcessHeap(), 0, qos->qos);
1231 HeapFree(GetProcessHeap(), 0, qos);
1232 return RPC_S_OUT_OF_RESOURCES;
1235 ULONG RpcQualityOfService_AddRef(RpcQualityOfService *qos)
1237 return InterlockedIncrement(&qos->refs);
1240 ULONG RpcQualityOfService_Release(RpcQualityOfService *qos)
1242 ULONG refs = InterlockedDecrement(&qos->refs);
1246 if (qos->qos->AdditionalSecurityInfoType == RPC_C_AUTHN_INFO_TYPE_HTTP)
1248 if (qos->qos->u.HttpCredentials->TransportCredentials)
1250 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials->User);
1251 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials->Domain);
1252 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials->Password);
1253 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials);
1255 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->AuthnSchemes);
1256 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->ServerCertificateSubject);
1257 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials);
1259 HeapFree(GetProcessHeap(), 0, qos->qos);
1260 HeapFree(GetProcessHeap(), 0, qos);
1265 BOOL RpcQualityOfService_IsEqual(const RpcQualityOfService *qos1, const RpcQualityOfService *qos2)
1273 TRACE("qos1 = { %ld %ld %ld %ld }, qos2 = { %ld %ld %ld %ld }\n",
1274 qos1->qos->Capabilities, qos1->qos->IdentityTracking,
1275 qos1->qos->ImpersonationType, qos1->qos->AdditionalSecurityInfoType,
1276 qos2->qos->Capabilities, qos2->qos->IdentityTracking,
1277 qos2->qos->ImpersonationType, qos2->qos->AdditionalSecurityInfoType);
1279 if ((qos1->qos->Capabilities != qos2->qos->Capabilities) ||
1280 (qos1->qos->IdentityTracking != qos2->qos->IdentityTracking) ||
1281 (qos1->qos->ImpersonationType != qos2->qos->ImpersonationType) ||
1282 (qos1->qos->AdditionalSecurityInfoType != qos2->qos->AdditionalSecurityInfoType))
1285 if (qos1->qos->AdditionalSecurityInfoType == RPC_C_AUTHN_INFO_TYPE_HTTP)
1287 const RPC_HTTP_TRANSPORT_CREDENTIALS_W *http_credentials1 = qos1->qos->u.HttpCredentials;
1288 const RPC_HTTP_TRANSPORT_CREDENTIALS_W *http_credentials2 = qos2->qos->u.HttpCredentials;
1290 if (http_credentials1->Flags != http_credentials2->Flags)
1293 if (http_credentials1->AuthenticationTarget != http_credentials2->AuthenticationTarget)
1296 /* authentication schemes and server certificate subject not currently used */
1298 if (http_credentials1->TransportCredentials != http_credentials2->TransportCredentials)
1300 const SEC_WINNT_AUTH_IDENTITY_W *identity1 = http_credentials1->TransportCredentials;
1301 const SEC_WINNT_AUTH_IDENTITY_W *identity2 = http_credentials2->TransportCredentials;
1303 if (!identity1 || !identity2)
1306 /* compare user names */
1307 if (identity1->UserLength != identity2->UserLength ||
1308 memcmp(identity1->User, identity2->User, identity1->UserLength))
1310 /* compare domain names */
1311 if (identity1->DomainLength != identity2->DomainLength ||
1312 memcmp(identity1->Domain, identity2->Domain, identity1->DomainLength))
1314 /* compare passwords */
1315 if (identity1->PasswordLength != identity2->PasswordLength ||
1316 memcmp(identity1->Password, identity2->Password, identity1->PasswordLength))
1324 /***********************************************************************
1325 * RpcRevertToSelf (RPCRT4.@)
1327 RPC_STATUS WINAPI RpcRevertToSelf(void)
1334 /***********************************************************************
1335 * RpcMgmtSetComTimeout (RPCRT4.@)
1337 RPC_STATUS WINAPI RpcMgmtSetComTimeout(RPC_BINDING_HANDLE BindingHandle, unsigned int Timeout)
1339 FIXME("(%p, %d): stub\n", BindingHandle, Timeout);
1343 /***********************************************************************
1344 * RpcBindingInqAuthInfoExA (RPCRT4.@)
1346 RPCRTAPI RPC_STATUS RPC_ENTRY
1347 RpcBindingInqAuthInfoExA( RPC_BINDING_HANDLE Binding, RPC_CSTR *ServerPrincName, ULONG *AuthnLevel,
1348 ULONG *AuthnSvc, RPC_AUTH_IDENTITY_HANDLE *AuthIdentity, ULONG *AuthzSvc,
1349 ULONG RpcQosVersion, RPC_SECURITY_QOS *SecurityQOS )
1351 FIXME("%p %p %p %p %p %p %u %p\n", Binding, ServerPrincName, AuthnLevel,
1352 AuthnSvc, AuthIdentity, AuthzSvc, RpcQosVersion, SecurityQOS);
1353 return RPC_S_INVALID_BINDING;
1356 /***********************************************************************
1357 * RpcBindingInqAuthInfoExW (RPCRT4.@)
1359 RPCRTAPI RPC_STATUS RPC_ENTRY
1360 RpcBindingInqAuthInfoExW( RPC_BINDING_HANDLE Binding, RPC_WSTR *ServerPrincName, ULONG *AuthnLevel,
1361 ULONG *AuthnSvc, RPC_AUTH_IDENTITY_HANDLE *AuthIdentity, ULONG *AuthzSvc,
1362 ULONG RpcQosVersion, RPC_SECURITY_QOS *SecurityQOS )
1364 FIXME("%p %p %p %p %p %p %u %p\n", Binding, ServerPrincName, AuthnLevel,
1365 AuthnSvc, AuthIdentity, AuthzSvc, RpcQosVersion, SecurityQOS);
1366 return RPC_S_INVALID_BINDING;
1369 /***********************************************************************
1370 * RpcBindingInqAuthInfoA (RPCRT4.@)
1372 RPCRTAPI RPC_STATUS RPC_ENTRY
1373 RpcBindingInqAuthInfoA( RPC_BINDING_HANDLE Binding, RPC_CSTR *ServerPrincName, ULONG *AuthnLevel,
1374 ULONG *AuthnSvc, RPC_AUTH_IDENTITY_HANDLE *AuthIdentity, ULONG *AuthzSvc )
1376 FIXME("%p %p %p %p %p %p\n", Binding, ServerPrincName, AuthnLevel,
1377 AuthnSvc, AuthIdentity, AuthzSvc);
1378 return RPC_S_INVALID_BINDING;
1381 /***********************************************************************
1382 * RpcBindingInqAuthInfoW (RPCRT4.@)
1384 RPCRTAPI RPC_STATUS RPC_ENTRY
1385 RpcBindingInqAuthInfoW( RPC_BINDING_HANDLE Binding, RPC_WSTR *ServerPrincName, ULONG *AuthnLevel,
1386 ULONG *AuthnSvc, RPC_AUTH_IDENTITY_HANDLE *AuthIdentity, ULONG *AuthzSvc )
1388 FIXME("%p %p %p %p %p %p\n", Binding, ServerPrincName, AuthnLevel,
1389 AuthnSvc, AuthIdentity, AuthzSvc);
1390 return RPC_S_INVALID_BINDING;
1393 /***********************************************************************
1394 * RpcBindingSetAuthInfoExA (RPCRT4.@)
1396 RPCRTAPI RPC_STATUS RPC_ENTRY
1397 RpcBindingSetAuthInfoExA( RPC_BINDING_HANDLE Binding, RPC_CSTR ServerPrincName,
1398 ULONG AuthnLevel, ULONG AuthnSvc,
1399 RPC_AUTH_IDENTITY_HANDLE AuthIdentity, ULONG AuthzSvr,
1400 RPC_SECURITY_QOS *SecurityQos )
1402 RpcBinding* bind = (RpcBinding*)Binding;
1406 ULONG package_count;
1408 PSecPkgInfoA packages;
1411 TRACE("%p %s %u %u %p %u %p\n", Binding, debugstr_a((const char*)ServerPrincName),
1412 AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvr, SecurityQos);
1418 TRACE("SecurityQos { Version=%ld, Capabilties=0x%lx, IdentityTracking=%ld, ImpersonationLevel=%ld",
1419 SecurityQos->Version, SecurityQos->Capabilities, SecurityQos->IdentityTracking, SecurityQos->ImpersonationType);
1420 if (SecurityQos->Version >= 2)
1422 const RPC_SECURITY_QOS_V2_A *SecurityQos2 = (const RPC_SECURITY_QOS_V2_A *)SecurityQos;
1423 TRACE(", AdditionalSecurityInfoType=%ld", SecurityQos2->AdditionalSecurityInfoType);
1424 if (SecurityQos2->AdditionalSecurityInfoType == RPC_C_AUTHN_INFO_TYPE_HTTP)
1425 TRACE(", { %p, 0x%lx, %ld, %ld, %p, %s }",
1426 SecurityQos2->u.HttpCredentials->TransportCredentials,
1427 SecurityQos2->u.HttpCredentials->Flags,
1428 SecurityQos2->u.HttpCredentials->AuthenticationTarget,
1429 SecurityQos2->u.HttpCredentials->NumberOfAuthnSchemes,
1430 SecurityQos2->u.HttpCredentials->AuthnSchemes,
1431 SecurityQos2->u.HttpCredentials->ServerCertificateSubject);
1434 status = RpcQualityOfService_Create(SecurityQos, FALSE, &bind->QOS);
1435 if (status != RPC_S_OK)
1440 if (bind->QOS) RpcQualityOfService_Release(bind->QOS);
1444 if (AuthnSvc == RPC_C_AUTHN_DEFAULT)
1445 AuthnSvc = RPC_C_AUTHN_WINNT;
1447 /* FIXME: the mapping should probably be retrieved using SSPI somehow */
1448 if (AuthnLevel == RPC_C_AUTHN_LEVEL_DEFAULT)
1449 AuthnLevel = RPC_C_AUTHN_LEVEL_NONE;
1451 if ((AuthnLevel == RPC_C_AUTHN_LEVEL_NONE) || (AuthnSvc == RPC_C_AUTHN_NONE))
1453 if (bind->AuthInfo) RpcAuthInfo_Release(bind->AuthInfo);
1454 bind->AuthInfo = NULL;
1458 if (AuthnLevel > RPC_C_AUTHN_LEVEL_PKT_PRIVACY)
1460 FIXME("unknown AuthnLevel %u\n", AuthnLevel);
1461 return RPC_S_UNKNOWN_AUTHN_LEVEL;
1466 FIXME("unsupported AuthzSvr %u\n", AuthzSvr);
1467 return RPC_S_UNKNOWN_AUTHZ_SERVICE;
1470 r = EnumerateSecurityPackagesA(&package_count, &packages);
1473 ERR("EnumerateSecurityPackagesA failed with error 0x%08x\n", r);
1474 return RPC_S_SEC_PKG_ERROR;
1477 for (i = 0; i < package_count; i++)
1478 if (packages[i].wRPCID == AuthnSvc)
1481 if (i == package_count)
1483 FIXME("unsupported AuthnSvc %u\n", AuthnSvc);
1484 FreeContextBuffer(packages);
1485 return RPC_S_UNKNOWN_AUTHN_SERVICE;
1488 TRACE("found package %s for service %u\n", packages[i].Name, AuthnSvc);
1489 r = AcquireCredentialsHandleA((SEC_CHAR *)ServerPrincName, packages[i].Name, SECPKG_CRED_OUTBOUND, NULL,
1490 AuthIdentity, NULL, NULL, &cred, &exp);
1491 cbMaxToken = packages[i].cbMaxToken;
1492 FreeContextBuffer(packages);
1493 if (r == ERROR_SUCCESS)
1495 if (bind->AuthInfo) RpcAuthInfo_Release(bind->AuthInfo);
1496 bind->AuthInfo = NULL;
1497 r = RpcAuthInfo_Create(AuthnLevel, AuthnSvc, cred, exp, cbMaxToken,
1498 AuthIdentity, &bind->AuthInfo);
1500 FreeCredentialsHandle(&cred);
1505 ERR("AcquireCredentialsHandleA failed with error 0x%08x\n", r);
1506 return RPC_S_SEC_PKG_ERROR;
1510 /***********************************************************************
1511 * RpcBindingSetAuthInfoExW (RPCRT4.@)
1513 RPCRTAPI RPC_STATUS RPC_ENTRY
1514 RpcBindingSetAuthInfoExW( RPC_BINDING_HANDLE Binding, RPC_WSTR ServerPrincName, ULONG AuthnLevel,
1515 ULONG AuthnSvc, RPC_AUTH_IDENTITY_HANDLE AuthIdentity, ULONG AuthzSvr,
1516 RPC_SECURITY_QOS *SecurityQos )
1518 RpcBinding* bind = (RpcBinding*)Binding;
1522 ULONG package_count;
1524 PSecPkgInfoW packages;
1527 TRACE("%p %s %u %u %p %u %p\n", Binding, debugstr_w((const WCHAR*)ServerPrincName),
1528 AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvr, SecurityQos);
1534 TRACE("SecurityQos { Version=%ld, Capabilties=0x%lx, IdentityTracking=%ld, ImpersonationLevel=%ld",
1535 SecurityQos->Version, SecurityQos->Capabilities, SecurityQos->IdentityTracking, SecurityQos->ImpersonationType);
1536 if (SecurityQos->Version >= 2)
1538 const RPC_SECURITY_QOS_V2_W *SecurityQos2 = (const RPC_SECURITY_QOS_V2_W *)SecurityQos;
1539 TRACE(", AdditionalSecurityInfoType=%ld", SecurityQos2->AdditionalSecurityInfoType);
1540 if (SecurityQos2->AdditionalSecurityInfoType == RPC_C_AUTHN_INFO_TYPE_HTTP)
1541 TRACE(", { %p, 0x%lx, %ld, %ld, %p, %s }",
1542 SecurityQos2->u.HttpCredentials->TransportCredentials,
1543 SecurityQos2->u.HttpCredentials->Flags,
1544 SecurityQos2->u.HttpCredentials->AuthenticationTarget,
1545 SecurityQos2->u.HttpCredentials->NumberOfAuthnSchemes,
1546 SecurityQos2->u.HttpCredentials->AuthnSchemes,
1547 debugstr_w(SecurityQos2->u.HttpCredentials->ServerCertificateSubject));
1550 status = RpcQualityOfService_Create(SecurityQos, TRUE, &bind->QOS);
1551 if (status != RPC_S_OK)
1556 if (bind->QOS) RpcQualityOfService_Release(bind->QOS);
1560 if (AuthnSvc == RPC_C_AUTHN_DEFAULT)
1561 AuthnSvc = RPC_C_AUTHN_WINNT;
1563 /* FIXME: the mapping should probably be retrieved using SSPI somehow */
1564 if (AuthnLevel == RPC_C_AUTHN_LEVEL_DEFAULT)
1565 AuthnLevel = RPC_C_AUTHN_LEVEL_NONE;
1567 if ((AuthnLevel == RPC_C_AUTHN_LEVEL_NONE) || (AuthnSvc == RPC_C_AUTHN_NONE))
1569 if (bind->AuthInfo) RpcAuthInfo_Release(bind->AuthInfo);
1570 bind->AuthInfo = NULL;
1574 if (AuthnLevel > RPC_C_AUTHN_LEVEL_PKT_PRIVACY)
1576 FIXME("unknown AuthnLevel %u\n", AuthnLevel);
1577 return RPC_S_UNKNOWN_AUTHN_LEVEL;
1582 FIXME("unsupported AuthzSvr %u\n", AuthzSvr);
1583 return RPC_S_UNKNOWN_AUTHZ_SERVICE;
1586 r = EnumerateSecurityPackagesW(&package_count, &packages);
1589 ERR("EnumerateSecurityPackagesA failed with error 0x%08x\n", r);
1590 return RPC_S_SEC_PKG_ERROR;
1593 for (i = 0; i < package_count; i++)
1594 if (packages[i].wRPCID == AuthnSvc)
1597 if (i == package_count)
1599 FIXME("unsupported AuthnSvc %u\n", AuthnSvc);
1600 FreeContextBuffer(packages);
1601 return RPC_S_UNKNOWN_AUTHN_SERVICE;
1604 TRACE("found package %s for service %u\n", debugstr_w(packages[i].Name), AuthnSvc);
1605 r = AcquireCredentialsHandleW((SEC_WCHAR *)ServerPrincName, packages[i].Name, SECPKG_CRED_OUTBOUND, NULL,
1606 AuthIdentity, NULL, NULL, &cred, &exp);
1607 cbMaxToken = packages[i].cbMaxToken;
1608 FreeContextBuffer(packages);
1609 if (r == ERROR_SUCCESS)
1611 if (bind->AuthInfo) RpcAuthInfo_Release(bind->AuthInfo);
1612 bind->AuthInfo = NULL;
1613 r = RpcAuthInfo_Create(AuthnLevel, AuthnSvc, cred, exp, cbMaxToken,
1614 AuthIdentity, &bind->AuthInfo);
1616 FreeCredentialsHandle(&cred);
1621 ERR("AcquireCredentialsHandleA failed with error 0x%08x\n", r);
1622 return RPC_S_SEC_PKG_ERROR;
1626 /***********************************************************************
1627 * RpcBindingSetAuthInfoA (RPCRT4.@)
1629 RPCRTAPI RPC_STATUS RPC_ENTRY
1630 RpcBindingSetAuthInfoA( RPC_BINDING_HANDLE Binding, RPC_CSTR ServerPrincName, ULONG AuthnLevel,
1631 ULONG AuthnSvc, RPC_AUTH_IDENTITY_HANDLE AuthIdentity, ULONG AuthzSvr )
1633 TRACE("%p %s %u %u %p %u\n", Binding, debugstr_a((const char*)ServerPrincName),
1634 AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvr);
1635 return RpcBindingSetAuthInfoExA(Binding, ServerPrincName, AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvr, NULL);
1638 /***********************************************************************
1639 * RpcBindingSetAuthInfoW (RPCRT4.@)
1641 RPCRTAPI RPC_STATUS RPC_ENTRY
1642 RpcBindingSetAuthInfoW( RPC_BINDING_HANDLE Binding, RPC_WSTR ServerPrincName, ULONG AuthnLevel,
1643 ULONG AuthnSvc, RPC_AUTH_IDENTITY_HANDLE AuthIdentity, ULONG AuthzSvr )
1645 TRACE("%p %s %u %u %p %u\n", Binding, debugstr_w((const WCHAR*)ServerPrincName),
1646 AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvr);
1647 return RpcBindingSetAuthInfoExW(Binding, ServerPrincName, AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvr, NULL);
1650 /***********************************************************************
1651 * RpcBindingSetOption (RPCRT4.@)
1653 RPC_STATUS WINAPI RpcBindingSetOption(RPC_BINDING_HANDLE BindingHandle, ULONG Option, ULONG OptionValue)
1655 FIXME("(%p, %d, %d): stub\n", BindingHandle, Option, OptionValue);