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 const RPC_SYNTAX_IDENTIFIER *TransferSyntax,
278 const RPC_SYNTAX_IDENTIFIER *InterfaceId)
280 TRACE("(Binding == ^%p)\n", Binding);
282 if (!Binding->server) {
283 return RpcAssoc_GetClientConnection(Binding->Assoc, InterfaceId,
284 TransferSyntax, Binding->AuthInfo, Binding->QOS, Connection);
286 /* we already have a connection with acceptable binding, so use it */
287 if (Binding->FromConn) {
288 *Connection = Binding->FromConn;
291 ERR("no connection in binding\n");
292 return RPC_S_INTERNAL_ERROR;
297 RPC_STATUS RPCRT4_CloseBinding(RpcBinding* Binding, RpcConnection* Connection)
299 TRACE("(Binding == ^%p)\n", Binding);
300 if (!Connection) return RPC_S_OK;
301 if (Binding->server) {
302 /* don't destroy a connection that is cached in the binding */
303 if (Binding->FromConn == Connection)
305 return RPCRT4_DestroyConnection(Connection);
308 RpcAssoc_ReleaseIdleConnection(Binding->Assoc, Connection);
313 /* utility functions for string composing and parsing */
314 static unsigned RPCRT4_strcopyA(LPSTR data, LPCSTR src)
316 unsigned len = strlen(src);
317 memcpy(data, src, len*sizeof(CHAR));
321 static unsigned RPCRT4_strcopyW(LPWSTR data, LPCWSTR src)
323 unsigned len = strlenW(src);
324 memcpy(data, src, len*sizeof(WCHAR));
328 static LPSTR RPCRT4_strconcatA(LPSTR dst, LPCSTR src)
330 DWORD len = strlen(dst), slen = strlen(src);
331 LPSTR ndst = HeapReAlloc(GetProcessHeap(), 0, dst, (len+slen+2)*sizeof(CHAR));
334 HeapFree(GetProcessHeap(), 0, dst);
338 memcpy(ndst+len+1, src, slen+1);
342 static LPWSTR RPCRT4_strconcatW(LPWSTR dst, LPCWSTR src)
344 DWORD len = strlenW(dst), slen = strlenW(src);
345 LPWSTR ndst = HeapReAlloc(GetProcessHeap(), 0, dst, (len+slen+2)*sizeof(WCHAR));
348 HeapFree(GetProcessHeap(), 0, dst);
352 memcpy(ndst+len+1, src, (slen+1)*sizeof(WCHAR));
357 /***********************************************************************
358 * RpcStringBindingComposeA (RPCRT4.@)
360 RPC_STATUS WINAPI RpcStringBindingComposeA(RPC_CSTR ObjUuid, RPC_CSTR Protseq,
361 RPC_CSTR NetworkAddr, RPC_CSTR Endpoint,
362 RPC_CSTR Options, RPC_CSTR *StringBinding )
367 TRACE( "(%s,%s,%s,%s,%s,%p)\n",
368 debugstr_a( (char*)ObjUuid ), debugstr_a( (char*)Protseq ),
369 debugstr_a( (char*)NetworkAddr ), debugstr_a( (char*)Endpoint ),
370 debugstr_a( (char*)Options ), StringBinding );
372 if (ObjUuid && *ObjUuid) len += strlen((char*)ObjUuid) + 1;
373 if (Protseq && *Protseq) len += strlen((char*)Protseq) + 1;
374 if (NetworkAddr && *NetworkAddr) len += strlen((char*)NetworkAddr);
375 if (Endpoint && *Endpoint) len += strlen((char*)Endpoint) + 2;
376 if (Options && *Options) len += strlen((char*)Options) + 2;
378 data = HeapAlloc(GetProcessHeap(), 0, len);
379 *StringBinding = (unsigned char*)data;
381 if (ObjUuid && *ObjUuid) {
382 data += RPCRT4_strcopyA(data, (char*)ObjUuid);
385 if (Protseq && *Protseq) {
386 data += RPCRT4_strcopyA(data, (char*)Protseq);
389 if (NetworkAddr && *NetworkAddr)
390 data += RPCRT4_strcopyA(data, (char*)NetworkAddr);
392 if ((Endpoint && *Endpoint) ||
393 (Options && *Options)) {
395 if (Endpoint && *Endpoint) {
396 data += RPCRT4_strcopyA(data, (char*)Endpoint);
397 if (Options && *Options) *data++ = ',';
399 if (Options && *Options) {
400 data += RPCRT4_strcopyA(data, (char*)Options);
409 /***********************************************************************
410 * RpcStringBindingComposeW (RPCRT4.@)
412 RPC_STATUS WINAPI RpcStringBindingComposeW( RPC_WSTR ObjUuid, RPC_WSTR Protseq,
413 RPC_WSTR NetworkAddr, RPC_WSTR Endpoint,
414 RPC_WSTR Options, RPC_WSTR* StringBinding )
419 TRACE("(%s,%s,%s,%s,%s,%p)\n",
420 debugstr_w( ObjUuid ), debugstr_w( Protseq ),
421 debugstr_w( NetworkAddr ), debugstr_w( Endpoint ),
422 debugstr_w( Options ), StringBinding);
424 if (ObjUuid && *ObjUuid) len += strlenW(ObjUuid) + 1;
425 if (Protseq && *Protseq) len += strlenW(Protseq) + 1;
426 if (NetworkAddr && *NetworkAddr) len += strlenW(NetworkAddr);
427 if (Endpoint && *Endpoint) len += strlenW(Endpoint) + 2;
428 if (Options && *Options) len += strlenW(Options) + 2;
430 data = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
431 *StringBinding = data;
433 if (ObjUuid && *ObjUuid) {
434 data += RPCRT4_strcopyW(data, ObjUuid);
437 if (Protseq && *Protseq) {
438 data += RPCRT4_strcopyW(data, Protseq);
441 if (NetworkAddr && *NetworkAddr) {
442 data += RPCRT4_strcopyW(data, NetworkAddr);
444 if ((Endpoint && *Endpoint) ||
445 (Options && *Options)) {
447 if (Endpoint && *Endpoint) {
448 data += RPCRT4_strcopyW(data, Endpoint);
449 if (Options && *Options) *data++ = ',';
451 if (Options && *Options) {
452 data += RPCRT4_strcopyW(data, Options);
462 /***********************************************************************
463 * RpcStringBindingParseA (RPCRT4.@)
465 RPC_STATUS WINAPI RpcStringBindingParseA( RPC_CSTR StringBinding, RPC_CSTR *ObjUuid,
466 RPC_CSTR *Protseq, RPC_CSTR *NetworkAddr,
467 RPC_CSTR *Endpoint, RPC_CSTR *Options)
470 static const char ep_opt[] = "endpoint=";
472 TRACE("(%s,%p,%p,%p,%p,%p)\n", debugstr_a((char*)StringBinding),
473 ObjUuid, Protseq, NetworkAddr, Endpoint, Options);
475 if (ObjUuid) *ObjUuid = NULL;
476 if (Protseq) *Protseq = NULL;
477 if (NetworkAddr) *NetworkAddr = NULL;
478 if (Endpoint) *Endpoint = NULL;
479 if (Options) *Options = NULL;
481 data = (char*) StringBinding;
483 next = strchr(data, '@');
485 if (ObjUuid) *ObjUuid = (unsigned char*)RPCRT4_strndupA(data, next - data);
489 next = strchr(data, ':');
491 if (Protseq) *Protseq = (unsigned char*)RPCRT4_strndupA(data, next - data);
495 next = strchr(data, '[');
499 if (NetworkAddr) *NetworkAddr = (unsigned char*)RPCRT4_strndupA(data, next - data);
501 close = strchr(data, ']');
502 if (!close) goto fail;
504 /* tokenize options */
505 while (data < close) {
506 next = strchr(data, ',');
507 if (!next || next > close) next = close;
508 /* FIXME: this is kind of inefficient */
509 opt = RPCRT4_strndupA(data, next - data);
513 next = strchr(opt, '=');
515 /* not an option, must be an endpoint */
516 if (*Endpoint) goto fail;
517 *Endpoint = (unsigned char*) opt;
519 if (strncmp(opt, ep_opt, strlen(ep_opt)) == 0) {
520 /* endpoint option */
521 if (*Endpoint) goto fail;
522 *Endpoint = (unsigned char*) RPCRT4_strdupA(next+1);
523 HeapFree(GetProcessHeap(), 0, opt);
527 /* FIXME: this is kind of inefficient */
528 *Options = (unsigned char*) RPCRT4_strconcatA( (char*)*Options, opt);
529 HeapFree(GetProcessHeap(), 0, opt);
531 *Options = (unsigned char*) opt;
537 if (*data) goto fail;
539 else if (NetworkAddr)
540 *NetworkAddr = (unsigned char*)RPCRT4_strdupA(data);
545 if (ObjUuid) RpcStringFreeA((unsigned char**)ObjUuid);
546 if (Protseq) RpcStringFreeA((unsigned char**)Protseq);
547 if (NetworkAddr) RpcStringFreeA((unsigned char**)NetworkAddr);
548 if (Endpoint) RpcStringFreeA((unsigned char**)Endpoint);
549 if (Options) RpcStringFreeA((unsigned char**)Options);
550 return RPC_S_INVALID_STRING_BINDING;
553 /***********************************************************************
554 * RpcStringBindingParseW (RPCRT4.@)
556 RPC_STATUS WINAPI RpcStringBindingParseW( RPC_WSTR StringBinding, RPC_WSTR *ObjUuid,
557 RPC_WSTR *Protseq, RPC_WSTR *NetworkAddr,
558 RPC_WSTR *Endpoint, RPC_WSTR *Options)
561 static const WCHAR ep_opt[] = {'e','n','d','p','o','i','n','t','=',0};
563 TRACE("(%s,%p,%p,%p,%p,%p)\n", debugstr_w(StringBinding),
564 ObjUuid, Protseq, NetworkAddr, Endpoint, Options);
566 if (ObjUuid) *ObjUuid = NULL;
567 if (Protseq) *Protseq = NULL;
568 if (NetworkAddr) *NetworkAddr = NULL;
569 if (Endpoint) *Endpoint = NULL;
570 if (Options) *Options = NULL;
572 data = StringBinding;
574 next = strchrW(data, '@');
576 if (ObjUuid) *ObjUuid = RPCRT4_strndupW(data, next - data);
580 next = strchrW(data, ':');
582 if (Protseq) *Protseq = RPCRT4_strndupW(data, next - data);
586 next = strchrW(data, '[');
590 if (NetworkAddr) *NetworkAddr = RPCRT4_strndupW(data, next - data);
592 close = strchrW(data, ']');
593 if (!close) goto fail;
595 /* tokenize options */
596 while (data < close) {
597 next = strchrW(data, ',');
598 if (!next || next > close) next = close;
599 /* FIXME: this is kind of inefficient */
600 opt = RPCRT4_strndupW(data, next - data);
604 next = strchrW(opt, '=');
606 /* not an option, must be an endpoint */
607 if (*Endpoint) goto fail;
610 if (strncmpW(opt, ep_opt, strlenW(ep_opt)) == 0) {
611 /* endpoint option */
612 if (*Endpoint) goto fail;
613 *Endpoint = RPCRT4_strdupW(next+1);
614 HeapFree(GetProcessHeap(), 0, opt);
618 /* FIXME: this is kind of inefficient */
619 *Options = RPCRT4_strconcatW(*Options, opt);
620 HeapFree(GetProcessHeap(), 0, opt);
628 if (*data) goto fail;
629 } else if (NetworkAddr)
630 *NetworkAddr = RPCRT4_strdupW(data);
635 if (ObjUuid) RpcStringFreeW(ObjUuid);
636 if (Protseq) RpcStringFreeW(Protseq);
637 if (NetworkAddr) RpcStringFreeW(NetworkAddr);
638 if (Endpoint) RpcStringFreeW(Endpoint);
639 if (Options) RpcStringFreeW(Options);
640 return RPC_S_INVALID_STRING_BINDING;
643 /***********************************************************************
644 * RpcBindingFree (RPCRT4.@)
646 RPC_STATUS WINAPI RpcBindingFree( RPC_BINDING_HANDLE* Binding )
649 TRACE("(%p) = %p\n", Binding, *Binding);
650 status = RPCRT4_DestroyBinding(*Binding);
651 if (status == RPC_S_OK) *Binding = 0;
655 /***********************************************************************
656 * RpcBindingVectorFree (RPCRT4.@)
658 RPC_STATUS WINAPI RpcBindingVectorFree( RPC_BINDING_VECTOR** BindingVector )
663 TRACE("(%p)\n", BindingVector);
664 for (c=0; c<(*BindingVector)->Count; c++) {
665 status = RpcBindingFree(&(*BindingVector)->BindingH[c]);
667 HeapFree(GetProcessHeap(), 0, *BindingVector);
668 *BindingVector = NULL;
672 /***********************************************************************
673 * RpcBindingInqObject (RPCRT4.@)
675 RPC_STATUS WINAPI RpcBindingInqObject( RPC_BINDING_HANDLE Binding, UUID* ObjectUuid )
677 RpcBinding* bind = (RpcBinding*)Binding;
679 TRACE("(%p,%p) = %s\n", Binding, ObjectUuid, debugstr_guid(&bind->ObjectUuid));
680 memcpy(ObjectUuid, &bind->ObjectUuid, sizeof(UUID));
684 /***********************************************************************
685 * RpcBindingSetObject (RPCRT4.@)
687 RPC_STATUS WINAPI RpcBindingSetObject( RPC_BINDING_HANDLE Binding, UUID* ObjectUuid )
689 RpcBinding* bind = (RpcBinding*)Binding;
691 TRACE("(%p,%s)\n", Binding, debugstr_guid(ObjectUuid));
692 if (bind->server) return RPC_S_WRONG_KIND_OF_BINDING;
693 return RPCRT4_SetBindingObject(Binding, ObjectUuid);
696 /***********************************************************************
697 * RpcBindingFromStringBindingA (RPCRT4.@)
699 RPC_STATUS WINAPI RpcBindingFromStringBindingA( RPC_CSTR StringBinding, RPC_BINDING_HANDLE* Binding )
702 RpcBinding* bind = NULL;
703 RPC_CSTR ObjectUuid, Protseq, NetworkAddr, Endpoint, Options;
706 TRACE("(%s,%p)\n", debugstr_a((char*)StringBinding), Binding);
708 ret = RpcStringBindingParseA(StringBinding, &ObjectUuid, &Protseq,
709 &NetworkAddr, &Endpoint, &Options);
710 if (ret != RPC_S_OK) return ret;
712 ret = UuidFromStringA(ObjectUuid, &Uuid);
715 ret = RPCRT4_CreateBindingA(&bind, FALSE, (char*)Protseq);
717 ret = RPCRT4_SetBindingObject(bind, &Uuid);
719 ret = RPCRT4_CompleteBindingA(bind, (char*)NetworkAddr, (char*)Endpoint, (char*)Options);
721 RpcStringFreeA((unsigned char**)&Options);
722 RpcStringFreeA((unsigned char**)&Endpoint);
723 RpcStringFreeA((unsigned char**)&NetworkAddr);
724 RpcStringFreeA((unsigned char**)&Protseq);
725 RpcStringFreeA((unsigned char**)&ObjectUuid);
728 *Binding = (RPC_BINDING_HANDLE)bind;
730 RPCRT4_DestroyBinding(bind);
735 /***********************************************************************
736 * RpcBindingFromStringBindingW (RPCRT4.@)
738 RPC_STATUS WINAPI RpcBindingFromStringBindingW( RPC_WSTR StringBinding, RPC_BINDING_HANDLE* Binding )
741 RpcBinding* bind = NULL;
742 RPC_WSTR ObjectUuid, Protseq, NetworkAddr, Endpoint, Options;
745 TRACE("(%s,%p)\n", debugstr_w(StringBinding), Binding);
747 ret = RpcStringBindingParseW(StringBinding, &ObjectUuid, &Protseq,
748 &NetworkAddr, &Endpoint, &Options);
749 if (ret != RPC_S_OK) return ret;
751 ret = UuidFromStringW(ObjectUuid, &Uuid);
754 ret = RPCRT4_CreateBindingW(&bind, FALSE, Protseq);
756 ret = RPCRT4_SetBindingObject(bind, &Uuid);
758 ret = RPCRT4_CompleteBindingW(bind, NetworkAddr, Endpoint, Options);
760 RpcStringFreeW(&Options);
761 RpcStringFreeW(&Endpoint);
762 RpcStringFreeW(&NetworkAddr);
763 RpcStringFreeW(&Protseq);
764 RpcStringFreeW(&ObjectUuid);
767 *Binding = (RPC_BINDING_HANDLE)bind;
769 RPCRT4_DestroyBinding(bind);
774 /***********************************************************************
775 * RpcBindingToStringBindingA (RPCRT4.@)
777 RPC_STATUS WINAPI RpcBindingToStringBindingA( RPC_BINDING_HANDLE Binding, RPC_CSTR *StringBinding )
780 RpcBinding* bind = (RpcBinding*)Binding;
783 TRACE("(%p,%p)\n", Binding, StringBinding);
785 ret = UuidToStringA(&bind->ObjectUuid, &ObjectUuid);
786 if (ret != RPC_S_OK) return ret;
788 ret = RpcStringBindingComposeA(ObjectUuid, (unsigned char*)bind->Protseq, (unsigned char*) bind->NetworkAddr,
789 (unsigned char*) bind->Endpoint, NULL, StringBinding);
791 RpcStringFreeA(&ObjectUuid);
796 /***********************************************************************
797 * RpcBindingToStringBindingW (RPCRT4.@)
799 RPC_STATUS WINAPI RpcBindingToStringBindingW( RPC_BINDING_HANDLE Binding, RPC_WSTR *StringBinding )
802 unsigned char *str = NULL;
803 TRACE("(%p,%p)\n", Binding, StringBinding);
804 ret = RpcBindingToStringBindingA(Binding, &str);
805 *StringBinding = RPCRT4_strdupAtoW((char*)str);
806 RpcStringFreeA((unsigned char**)&str);
810 /***********************************************************************
811 * I_RpcBindingSetAsync (RPCRT4.@)
813 * Exists in win9x and winNT, but with different number of arguments
814 * (9x version has 3 arguments, NT has 2).
816 RPC_STATUS WINAPI I_RpcBindingSetAsync( RPC_BINDING_HANDLE Binding, RPC_BLOCKING_FN BlockingFn)
818 RpcBinding* bind = (RpcBinding*)Binding;
820 TRACE( "(%p,%p): stub\n", Binding, BlockingFn );
822 bind->BlockingFn = BlockingFn;
827 /***********************************************************************
828 * RpcBindingCopy (RPCRT4.@)
830 RPC_STATUS RPC_ENTRY RpcBindingCopy(
831 RPC_BINDING_HANDLE SourceBinding,
832 RPC_BINDING_HANDLE* DestinationBinding)
834 RpcBinding *DestBinding;
835 RpcBinding *SrcBinding = (RpcBinding*)SourceBinding;
838 TRACE("(%p, %p)\n", SourceBinding, DestinationBinding);
840 status = RPCRT4_AllocBinding(&DestBinding, SrcBinding->server);
841 if (status != RPC_S_OK) return status;
843 DestBinding->ObjectUuid = SrcBinding->ObjectUuid;
844 DestBinding->BlockingFn = SrcBinding->BlockingFn;
845 DestBinding->Protseq = RPCRT4_strndupA(SrcBinding->Protseq, -1);
846 DestBinding->NetworkAddr = RPCRT4_strndupA(SrcBinding->NetworkAddr, -1);
847 DestBinding->Endpoint = RPCRT4_strndupA(SrcBinding->Endpoint, -1);
848 DestBinding->NetworkOptions = RPCRT4_strdupW(SrcBinding->NetworkOptions);
849 if (SrcBinding->Assoc) SrcBinding->Assoc->refs++;
850 DestBinding->Assoc = SrcBinding->Assoc;
852 if (SrcBinding->AuthInfo) RpcAuthInfo_AddRef(SrcBinding->AuthInfo);
853 DestBinding->AuthInfo = SrcBinding->AuthInfo;
854 if (SrcBinding->QOS) RpcQualityOfService_AddRef(SrcBinding->QOS);
855 DestBinding->QOS = SrcBinding->QOS;
857 *DestinationBinding = DestBinding;
861 /***********************************************************************
862 * RpcImpersonateClient (RPCRT4.@)
864 * Impersonates the client connected via a binding handle so that security
865 * checks are done in the context of the client.
868 * BindingHandle [I] Handle to the binding to the client.
872 * Failure: RPC_STATUS value.
876 * If BindingHandle is NULL then the function impersonates the client
877 * connected to the binding handle of the current thread.
879 RPC_STATUS WINAPI RpcImpersonateClient(RPC_BINDING_HANDLE BindingHandle)
881 FIXME("(%p): stub\n", BindingHandle);
882 ImpersonateSelf(SecurityImpersonation);
886 /***********************************************************************
887 * RpcRevertToSelfEx (RPCRT4.@)
889 * Stops impersonating the client connected to the binding handle so that security
890 * checks are no longer done in the context of the client.
893 * BindingHandle [I] Handle to the binding to the client.
897 * Failure: RPC_STATUS value.
901 * If BindingHandle is NULL then the function stops impersonating the client
902 * connected to the binding handle of the current thread.
904 RPC_STATUS WINAPI RpcRevertToSelfEx(RPC_BINDING_HANDLE BindingHandle)
906 FIXME("(%p): stub\n", BindingHandle);
910 static inline BOOL has_nt_auth_identity(ULONG AuthnLevel)
914 case RPC_C_AUTHN_GSS_NEGOTIATE:
915 case RPC_C_AUTHN_WINNT:
916 case RPC_C_AUTHN_GSS_KERBEROS:
923 static RPC_STATUS RpcAuthInfo_Create(ULONG AuthnLevel, ULONG AuthnSvc,
924 CredHandle cred, TimeStamp exp,
926 RPC_AUTH_IDENTITY_HANDLE identity,
929 RpcAuthInfo *AuthInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(*AuthInfo));
931 return ERROR_OUTOFMEMORY;
934 AuthInfo->AuthnLevel = AuthnLevel;
935 AuthInfo->AuthnSvc = AuthnSvc;
936 AuthInfo->cred = cred;
938 AuthInfo->cbMaxToken = cbMaxToken;
939 AuthInfo->identity = identity;
941 /* duplicate the SEC_WINNT_AUTH_IDENTITY structure, if applicable, to
942 * enable better matching in RpcAuthInfo_IsEqual */
943 if (identity && has_nt_auth_identity(AuthnSvc))
945 const SEC_WINNT_AUTH_IDENTITY_W *nt_identity = identity;
946 AuthInfo->nt_identity = HeapAlloc(GetProcessHeap(), 0, sizeof(*AuthInfo->nt_identity));
947 if (!AuthInfo->nt_identity)
949 HeapFree(GetProcessHeap(), 0, AuthInfo);
950 return ERROR_OUTOFMEMORY;
953 AuthInfo->nt_identity->Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
954 if (nt_identity->Flags & SEC_WINNT_AUTH_IDENTITY_UNICODE)
955 AuthInfo->nt_identity->User = RPCRT4_strndupW(nt_identity->User, nt_identity->UserLength);
957 AuthInfo->nt_identity->User = RPCRT4_strndupAtoW((const char *)nt_identity->User, nt_identity->UserLength);
958 AuthInfo->nt_identity->UserLength = nt_identity->UserLength;
959 if (nt_identity->Flags & SEC_WINNT_AUTH_IDENTITY_UNICODE)
960 AuthInfo->nt_identity->Domain = RPCRT4_strndupW(nt_identity->Domain, nt_identity->DomainLength);
962 AuthInfo->nt_identity->Domain = RPCRT4_strndupAtoW((const char *)nt_identity->Domain, nt_identity->DomainLength);
963 AuthInfo->nt_identity->DomainLength = nt_identity->DomainLength;
964 if (nt_identity->Flags & SEC_WINNT_AUTH_IDENTITY_UNICODE)
965 AuthInfo->nt_identity->Password = RPCRT4_strndupW(nt_identity->Password, nt_identity->PasswordLength);
967 AuthInfo->nt_identity->Password = RPCRT4_strndupAtoW((const char *)nt_identity->Password, nt_identity->PasswordLength);
968 AuthInfo->nt_identity->PasswordLength = nt_identity->PasswordLength;
970 if (!AuthInfo->nt_identity->User ||
971 !AuthInfo->nt_identity->Domain ||
972 !AuthInfo->nt_identity->Password)
974 HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity->User);
975 HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity->Domain);
976 HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity->Password);
977 HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity);
978 HeapFree(GetProcessHeap(), 0, AuthInfo);
979 return ERROR_OUTOFMEMORY;
983 AuthInfo->nt_identity = NULL;
988 ULONG RpcAuthInfo_AddRef(RpcAuthInfo *AuthInfo)
990 return InterlockedIncrement(&AuthInfo->refs);
993 ULONG RpcAuthInfo_Release(RpcAuthInfo *AuthInfo)
995 ULONG refs = InterlockedDecrement(&AuthInfo->refs);
999 FreeCredentialsHandle(&AuthInfo->cred);
1000 if (AuthInfo->nt_identity)
1002 HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity->User);
1003 HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity->Domain);
1004 HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity->Password);
1005 HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity);
1007 HeapFree(GetProcessHeap(), 0, AuthInfo);
1013 BOOL RpcAuthInfo_IsEqual(const RpcAuthInfo *AuthInfo1, const RpcAuthInfo *AuthInfo2)
1015 if (AuthInfo1 == AuthInfo2)
1018 if (!AuthInfo1 || !AuthInfo2)
1021 if ((AuthInfo1->AuthnLevel != AuthInfo2->AuthnLevel) ||
1022 (AuthInfo1->AuthnSvc != AuthInfo2->AuthnSvc))
1025 if (AuthInfo1->identity == AuthInfo2->identity)
1028 if (!AuthInfo1->identity || !AuthInfo2->identity)
1031 if (has_nt_auth_identity(AuthInfo1->AuthnSvc))
1033 const SEC_WINNT_AUTH_IDENTITY_W *identity1 = AuthInfo1->nt_identity;
1034 const SEC_WINNT_AUTH_IDENTITY_W *identity2 = AuthInfo2->nt_identity;
1035 /* compare user names */
1036 if (identity1->UserLength != identity2->UserLength ||
1037 memcmp(identity1->User, identity2->User, identity1->UserLength))
1039 /* compare domain names */
1040 if (identity1->DomainLength != identity2->DomainLength ||
1041 memcmp(identity1->Domain, identity2->Domain, identity1->DomainLength))
1043 /* compare passwords */
1044 if (identity1->PasswordLength != identity2->PasswordLength ||
1045 memcmp(identity1->Password, identity2->Password, identity1->PasswordLength))
1054 static RPC_STATUS RpcQualityOfService_Create(const RPC_SECURITY_QOS *qos_src, BOOL unicode, RpcQualityOfService **qos_dst)
1056 RpcQualityOfService *qos = HeapAlloc(GetProcessHeap(), 0, sizeof(*qos));
1059 return RPC_S_OUT_OF_RESOURCES;
1062 qos->qos = HeapAlloc(GetProcessHeap(), 0, sizeof(*qos->qos));
1063 if (!qos->qos) goto error;
1064 qos->qos->Version = qos_src->Version;
1065 qos->qos->Capabilities = qos_src->Capabilities;
1066 qos->qos->IdentityTracking = qos_src->IdentityTracking;
1067 qos->qos->ImpersonationType = qos_src->ImpersonationType;
1068 qos->qos->AdditionalSecurityInfoType = 0;
1070 if (qos_src->Version >= 2)
1072 const RPC_SECURITY_QOS_V2_W *qos_src2 = (const RPC_SECURITY_QOS_V2_W *)qos_src;
1073 qos->qos->AdditionalSecurityInfoType = qos_src2->AdditionalSecurityInfoType;
1074 if (qos_src2->AdditionalSecurityInfoType == RPC_C_AUTHN_INFO_TYPE_HTTP)
1076 const RPC_HTTP_TRANSPORT_CREDENTIALS_W *http_credentials_src = qos_src2->u.HttpCredentials;
1077 RPC_HTTP_TRANSPORT_CREDENTIALS_W *http_credentials_dst;
1079 http_credentials_dst = HeapAlloc(GetProcessHeap(), 0, sizeof(*http_credentials_dst));
1080 qos->qos->u.HttpCredentials = http_credentials_dst;
1081 if (!http_credentials_dst) goto error;
1082 http_credentials_dst->TransportCredentials = NULL;
1083 http_credentials_dst->Flags = http_credentials_src->Flags;
1084 http_credentials_dst->AuthenticationTarget = http_credentials_src->AuthenticationTarget;
1085 http_credentials_dst->NumberOfAuthnSchemes = http_credentials_src->NumberOfAuthnSchemes;
1086 http_credentials_dst->AuthnSchemes = NULL;
1087 http_credentials_dst->ServerCertificateSubject = NULL;
1088 if (http_credentials_src->TransportCredentials)
1090 SEC_WINNT_AUTH_IDENTITY_W *cred_dst;
1091 cred_dst = http_credentials_dst->TransportCredentials = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*cred_dst));
1092 if (!cred_dst) goto error;
1093 cred_dst->Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
1096 const SEC_WINNT_AUTH_IDENTITY_W *cred_src = http_credentials_src->TransportCredentials;
1097 cred_dst->UserLength = cred_src->UserLength;
1098 cred_dst->PasswordLength = cred_src->PasswordLength;
1099 cred_dst->DomainLength = cred_src->DomainLength;
1100 cred_dst->User = RPCRT4_strndupW(cred_src->User, cred_src->UserLength);
1101 cred_dst->Password = RPCRT4_strndupW(cred_src->Password, cred_src->PasswordLength);
1102 cred_dst->Domain = RPCRT4_strndupW(cred_src->Domain, cred_src->DomainLength);
1106 const SEC_WINNT_AUTH_IDENTITY_A *cred_src = (const SEC_WINNT_AUTH_IDENTITY_A *)http_credentials_src->TransportCredentials;
1107 cred_dst->UserLength = MultiByteToWideChar(CP_ACP, 0, (char *)cred_src->User, cred_src->UserLength, NULL, 0);
1108 cred_dst->DomainLength = MultiByteToWideChar(CP_ACP, 0, (char *)cred_src->Domain, cred_src->DomainLength, NULL, 0);
1109 cred_dst->PasswordLength = MultiByteToWideChar(CP_ACP, 0, (char *)cred_src->Password, cred_src->PasswordLength, NULL, 0);
1110 cred_dst->User = HeapAlloc(GetProcessHeap(), 0, cred_dst->UserLength * sizeof(WCHAR));
1111 cred_dst->Password = HeapAlloc(GetProcessHeap(), 0, cred_dst->PasswordLength * sizeof(WCHAR));
1112 cred_dst->Domain = HeapAlloc(GetProcessHeap(), 0, cred_dst->DomainLength * sizeof(WCHAR));
1113 if (!cred_dst || !cred_dst->Password || !cred_dst->Domain) goto error;
1114 MultiByteToWideChar(CP_ACP, 0, (char *)cred_src->User, cred_src->UserLength, cred_dst->User, cred_dst->UserLength);
1115 MultiByteToWideChar(CP_ACP, 0, (char *)cred_src->Domain, cred_src->DomainLength, cred_dst->Domain, cred_dst->DomainLength);
1116 MultiByteToWideChar(CP_ACP, 0, (char *)cred_src->Password, cred_src->PasswordLength, cred_dst->Password, cred_dst->PasswordLength);
1119 if (http_credentials_src->NumberOfAuthnSchemes)
1121 http_credentials_dst->AuthnSchemes = HeapAlloc(GetProcessHeap(), 0, http_credentials_src->NumberOfAuthnSchemes * sizeof(*http_credentials_dst->AuthnSchemes));
1122 if (!http_credentials_dst->AuthnSchemes) goto error;
1123 memcpy(http_credentials_dst->AuthnSchemes, http_credentials_src->AuthnSchemes, http_credentials_src->NumberOfAuthnSchemes * sizeof(*http_credentials_dst->AuthnSchemes));
1125 if (http_credentials_src->ServerCertificateSubject)
1128 http_credentials_dst->ServerCertificateSubject =
1129 RPCRT4_strndupW(http_credentials_src->ServerCertificateSubject,
1130 strlenW(http_credentials_src->ServerCertificateSubject));
1132 http_credentials_dst->ServerCertificateSubject =
1133 RPCRT4_strdupAtoW((char *)http_credentials_src->ServerCertificateSubject);
1134 if (!http_credentials_dst->ServerCertificateSubject) goto error;
1144 if (qos->qos->AdditionalSecurityInfoType == RPC_C_AUTHN_INFO_TYPE_HTTP &&
1145 qos->qos->u.HttpCredentials)
1147 if (qos->qos->u.HttpCredentials->TransportCredentials)
1149 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials->User);
1150 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials->Domain);
1151 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials->Password);
1152 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials);
1154 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->AuthnSchemes);
1155 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->ServerCertificateSubject);
1156 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials);
1158 HeapFree(GetProcessHeap(), 0, qos->qos);
1160 HeapFree(GetProcessHeap(), 0, qos);
1161 return RPC_S_OUT_OF_RESOURCES;
1164 ULONG RpcQualityOfService_AddRef(RpcQualityOfService *qos)
1166 return InterlockedIncrement(&qos->refs);
1169 ULONG RpcQualityOfService_Release(RpcQualityOfService *qos)
1171 ULONG refs = InterlockedDecrement(&qos->refs);
1175 if (qos->qos->AdditionalSecurityInfoType == RPC_C_AUTHN_INFO_TYPE_HTTP)
1177 if (qos->qos->u.HttpCredentials->TransportCredentials)
1179 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials->User);
1180 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials->Domain);
1181 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials->Password);
1182 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials);
1184 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->AuthnSchemes);
1185 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->ServerCertificateSubject);
1186 HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials);
1188 HeapFree(GetProcessHeap(), 0, qos->qos);
1189 HeapFree(GetProcessHeap(), 0, qos);
1194 BOOL RpcQualityOfService_IsEqual(const RpcQualityOfService *qos1, const RpcQualityOfService *qos2)
1202 TRACE("qos1 = { %ld %ld %ld %ld }, qos2 = { %ld %ld %ld %ld }\n",
1203 qos1->qos->Capabilities, qos1->qos->IdentityTracking,
1204 qos1->qos->ImpersonationType, qos1->qos->AdditionalSecurityInfoType,
1205 qos2->qos->Capabilities, qos2->qos->IdentityTracking,
1206 qos2->qos->ImpersonationType, qos2->qos->AdditionalSecurityInfoType);
1208 if ((qos1->qos->Capabilities != qos2->qos->Capabilities) ||
1209 (qos1->qos->IdentityTracking != qos2->qos->IdentityTracking) ||
1210 (qos1->qos->ImpersonationType != qos2->qos->ImpersonationType) ||
1211 (qos1->qos->AdditionalSecurityInfoType != qos2->qos->AdditionalSecurityInfoType))
1214 if (qos1->qos->AdditionalSecurityInfoType == RPC_C_AUTHN_INFO_TYPE_HTTP)
1216 const RPC_HTTP_TRANSPORT_CREDENTIALS_W *http_credentials1 = qos1->qos->u.HttpCredentials;
1217 const RPC_HTTP_TRANSPORT_CREDENTIALS_W *http_credentials2 = qos2->qos->u.HttpCredentials;
1219 if (http_credentials1->Flags != http_credentials2->Flags)
1222 if (http_credentials1->AuthenticationTarget != http_credentials2->AuthenticationTarget)
1225 /* authentication schemes and server certificate subject not currently used */
1227 if (http_credentials1->TransportCredentials != http_credentials2->TransportCredentials)
1229 const SEC_WINNT_AUTH_IDENTITY_W *identity1 = http_credentials1->TransportCredentials;
1230 const SEC_WINNT_AUTH_IDENTITY_W *identity2 = http_credentials2->TransportCredentials;
1232 if (!identity1 || !identity2)
1235 /* compare user names */
1236 if (identity1->UserLength != identity2->UserLength ||
1237 memcmp(identity1->User, identity2->User, identity1->UserLength))
1239 /* compare domain names */
1240 if (identity1->DomainLength != identity2->DomainLength ||
1241 memcmp(identity1->Domain, identity2->Domain, identity1->DomainLength))
1243 /* compare passwords */
1244 if (identity1->PasswordLength != identity2->PasswordLength ||
1245 memcmp(identity1->Password, identity2->Password, identity1->PasswordLength))
1253 /***********************************************************************
1254 * RpcRevertToSelf (RPCRT4.@)
1256 RPC_STATUS WINAPI RpcRevertToSelf(void)
1263 /***********************************************************************
1264 * RpcMgmtSetComTimeout (RPCRT4.@)
1266 RPC_STATUS WINAPI RpcMgmtSetComTimeout(RPC_BINDING_HANDLE BindingHandle, unsigned int Timeout)
1268 FIXME("(%p, %d): stub\n", BindingHandle, Timeout);
1272 /***********************************************************************
1273 * RpcBindingInqAuthInfoExA (RPCRT4.@)
1275 RPCRTAPI RPC_STATUS RPC_ENTRY
1276 RpcBindingInqAuthInfoExA( RPC_BINDING_HANDLE Binding, RPC_CSTR *ServerPrincName, ULONG *AuthnLevel,
1277 ULONG *AuthnSvc, RPC_AUTH_IDENTITY_HANDLE *AuthIdentity, ULONG *AuthzSvc,
1278 ULONG RpcQosVersion, RPC_SECURITY_QOS *SecurityQOS )
1280 FIXME("%p %p %p %p %p %p %u %p\n", Binding, ServerPrincName, AuthnLevel,
1281 AuthnSvc, AuthIdentity, AuthzSvc, RpcQosVersion, SecurityQOS);
1282 return RPC_S_INVALID_BINDING;
1285 /***********************************************************************
1286 * RpcBindingInqAuthInfoExW (RPCRT4.@)
1288 RPCRTAPI RPC_STATUS RPC_ENTRY
1289 RpcBindingInqAuthInfoExW( RPC_BINDING_HANDLE Binding, RPC_WSTR *ServerPrincName, ULONG *AuthnLevel,
1290 ULONG *AuthnSvc, RPC_AUTH_IDENTITY_HANDLE *AuthIdentity, ULONG *AuthzSvc,
1291 ULONG RpcQosVersion, RPC_SECURITY_QOS *SecurityQOS )
1293 FIXME("%p %p %p %p %p %p %u %p\n", Binding, ServerPrincName, AuthnLevel,
1294 AuthnSvc, AuthIdentity, AuthzSvc, RpcQosVersion, SecurityQOS);
1295 return RPC_S_INVALID_BINDING;
1298 /***********************************************************************
1299 * RpcBindingInqAuthInfoA (RPCRT4.@)
1301 RPCRTAPI RPC_STATUS RPC_ENTRY
1302 RpcBindingInqAuthInfoA( RPC_BINDING_HANDLE Binding, RPC_CSTR *ServerPrincName, ULONG *AuthnLevel,
1303 ULONG *AuthnSvc, RPC_AUTH_IDENTITY_HANDLE *AuthIdentity, ULONG *AuthzSvc )
1305 FIXME("%p %p %p %p %p %p\n", Binding, ServerPrincName, AuthnLevel,
1306 AuthnSvc, AuthIdentity, AuthzSvc);
1307 return RPC_S_INVALID_BINDING;
1310 /***********************************************************************
1311 * RpcBindingInqAuthInfoW (RPCRT4.@)
1313 RPCRTAPI RPC_STATUS RPC_ENTRY
1314 RpcBindingInqAuthInfoW( RPC_BINDING_HANDLE Binding, RPC_WSTR *ServerPrincName, ULONG *AuthnLevel,
1315 ULONG *AuthnSvc, RPC_AUTH_IDENTITY_HANDLE *AuthIdentity, ULONG *AuthzSvc )
1317 FIXME("%p %p %p %p %p %p\n", Binding, ServerPrincName, AuthnLevel,
1318 AuthnSvc, AuthIdentity, AuthzSvc);
1319 return RPC_S_INVALID_BINDING;
1322 /***********************************************************************
1323 * RpcBindingSetAuthInfoExA (RPCRT4.@)
1325 RPCRTAPI RPC_STATUS RPC_ENTRY
1326 RpcBindingSetAuthInfoExA( RPC_BINDING_HANDLE Binding, RPC_CSTR ServerPrincName,
1327 ULONG AuthnLevel, ULONG AuthnSvc,
1328 RPC_AUTH_IDENTITY_HANDLE AuthIdentity, ULONG AuthzSvr,
1329 RPC_SECURITY_QOS *SecurityQos )
1331 RpcBinding* bind = (RpcBinding*)Binding;
1335 ULONG package_count;
1337 PSecPkgInfoA packages;
1340 TRACE("%p %s %u %u %p %u %p\n", Binding, debugstr_a((const char*)ServerPrincName),
1341 AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvr, SecurityQos);
1347 TRACE("SecurityQos { Version=%ld, Capabilties=0x%lx, IdentityTracking=%ld, ImpersonationLevel=%ld",
1348 SecurityQos->Version, SecurityQos->Capabilities, SecurityQos->IdentityTracking, SecurityQos->ImpersonationType);
1349 if (SecurityQos->Version >= 2)
1351 const RPC_SECURITY_QOS_V2_A *SecurityQos2 = (const RPC_SECURITY_QOS_V2_A *)SecurityQos;
1352 TRACE(", AdditionalSecurityInfoType=%ld", SecurityQos2->AdditionalSecurityInfoType);
1353 if (SecurityQos2->AdditionalSecurityInfoType == RPC_C_AUTHN_INFO_TYPE_HTTP)
1354 TRACE(", { %p, 0x%lx, %ld, %ld, %p, %s }",
1355 SecurityQos2->u.HttpCredentials->TransportCredentials,
1356 SecurityQos2->u.HttpCredentials->Flags,
1357 SecurityQos2->u.HttpCredentials->AuthenticationTarget,
1358 SecurityQos2->u.HttpCredentials->NumberOfAuthnSchemes,
1359 SecurityQos2->u.HttpCredentials->AuthnSchemes,
1360 SecurityQos2->u.HttpCredentials->ServerCertificateSubject);
1363 status = RpcQualityOfService_Create(SecurityQos, FALSE, &bind->QOS);
1364 if (status != RPC_S_OK)
1369 if (bind->QOS) RpcQualityOfService_Release(bind->QOS);
1373 if (AuthnSvc == RPC_C_AUTHN_DEFAULT)
1374 AuthnSvc = RPC_C_AUTHN_WINNT;
1376 /* FIXME: the mapping should probably be retrieved using SSPI somehow */
1377 if (AuthnLevel == RPC_C_AUTHN_LEVEL_DEFAULT)
1378 AuthnLevel = RPC_C_AUTHN_LEVEL_NONE;
1380 if ((AuthnLevel == RPC_C_AUTHN_LEVEL_NONE) || (AuthnSvc == RPC_C_AUTHN_NONE))
1382 if (bind->AuthInfo) RpcAuthInfo_Release(bind->AuthInfo);
1383 bind->AuthInfo = NULL;
1387 if (AuthnLevel > RPC_C_AUTHN_LEVEL_PKT_PRIVACY)
1389 FIXME("unknown AuthnLevel %u\n", AuthnLevel);
1390 return RPC_S_UNKNOWN_AUTHN_LEVEL;
1395 FIXME("unsupported AuthzSvr %u\n", AuthzSvr);
1396 return RPC_S_UNKNOWN_AUTHZ_SERVICE;
1399 r = EnumerateSecurityPackagesA(&package_count, &packages);
1402 ERR("EnumerateSecurityPackagesA failed with error 0x%08x\n", r);
1403 return RPC_S_SEC_PKG_ERROR;
1406 for (i = 0; i < package_count; i++)
1407 if (packages[i].wRPCID == AuthnSvc)
1410 if (i == package_count)
1412 FIXME("unsupported AuthnSvc %u\n", AuthnSvc);
1413 FreeContextBuffer(packages);
1414 return RPC_S_UNKNOWN_AUTHN_SERVICE;
1417 TRACE("found package %s for service %u\n", packages[i].Name, AuthnSvc);
1418 r = AcquireCredentialsHandleA((SEC_CHAR *)ServerPrincName, packages[i].Name, SECPKG_CRED_OUTBOUND, NULL,
1419 AuthIdentity, NULL, NULL, &cred, &exp);
1420 cbMaxToken = packages[i].cbMaxToken;
1421 FreeContextBuffer(packages);
1422 if (r == ERROR_SUCCESS)
1424 if (bind->AuthInfo) RpcAuthInfo_Release(bind->AuthInfo);
1425 bind->AuthInfo = NULL;
1426 r = RpcAuthInfo_Create(AuthnLevel, AuthnSvc, cred, exp, cbMaxToken,
1427 AuthIdentity, &bind->AuthInfo);
1429 FreeCredentialsHandle(&cred);
1434 ERR("AcquireCredentialsHandleA failed with error 0x%08x\n", r);
1435 return RPC_S_SEC_PKG_ERROR;
1439 /***********************************************************************
1440 * RpcBindingSetAuthInfoExW (RPCRT4.@)
1442 RPCRTAPI RPC_STATUS RPC_ENTRY
1443 RpcBindingSetAuthInfoExW( RPC_BINDING_HANDLE Binding, RPC_WSTR ServerPrincName, ULONG AuthnLevel,
1444 ULONG AuthnSvc, RPC_AUTH_IDENTITY_HANDLE AuthIdentity, ULONG AuthzSvr,
1445 RPC_SECURITY_QOS *SecurityQos )
1447 RpcBinding* bind = (RpcBinding*)Binding;
1451 ULONG package_count;
1453 PSecPkgInfoW packages;
1456 TRACE("%p %s %u %u %p %u %p\n", Binding, debugstr_w((const WCHAR*)ServerPrincName),
1457 AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvr, SecurityQos);
1463 TRACE("SecurityQos { Version=%ld, Capabilties=0x%lx, IdentityTracking=%ld, ImpersonationLevel=%ld",
1464 SecurityQos->Version, SecurityQos->Capabilities, SecurityQos->IdentityTracking, SecurityQos->ImpersonationType);
1465 if (SecurityQos->Version >= 2)
1467 const RPC_SECURITY_QOS_V2_W *SecurityQos2 = (const RPC_SECURITY_QOS_V2_W *)SecurityQos;
1468 TRACE(", AdditionalSecurityInfoType=%ld", SecurityQos2->AdditionalSecurityInfoType);
1469 if (SecurityQos2->AdditionalSecurityInfoType == RPC_C_AUTHN_INFO_TYPE_HTTP)
1470 TRACE(", { %p, 0x%lx, %ld, %ld, %p, %s }",
1471 SecurityQos2->u.HttpCredentials->TransportCredentials,
1472 SecurityQos2->u.HttpCredentials->Flags,
1473 SecurityQos2->u.HttpCredentials->AuthenticationTarget,
1474 SecurityQos2->u.HttpCredentials->NumberOfAuthnSchemes,
1475 SecurityQos2->u.HttpCredentials->AuthnSchemes,
1476 debugstr_w(SecurityQos2->u.HttpCredentials->ServerCertificateSubject));
1479 status = RpcQualityOfService_Create(SecurityQos, TRUE, &bind->QOS);
1480 if (status != RPC_S_OK)
1485 if (bind->QOS) RpcQualityOfService_Release(bind->QOS);
1489 if (AuthnSvc == RPC_C_AUTHN_DEFAULT)
1490 AuthnSvc = RPC_C_AUTHN_WINNT;
1492 /* FIXME: the mapping should probably be retrieved using SSPI somehow */
1493 if (AuthnLevel == RPC_C_AUTHN_LEVEL_DEFAULT)
1494 AuthnLevel = RPC_C_AUTHN_LEVEL_NONE;
1496 if ((AuthnLevel == RPC_C_AUTHN_LEVEL_NONE) || (AuthnSvc == RPC_C_AUTHN_NONE))
1498 if (bind->AuthInfo) RpcAuthInfo_Release(bind->AuthInfo);
1499 bind->AuthInfo = NULL;
1503 if (AuthnLevel > RPC_C_AUTHN_LEVEL_PKT_PRIVACY)
1505 FIXME("unknown AuthnLevel %u\n", AuthnLevel);
1506 return RPC_S_UNKNOWN_AUTHN_LEVEL;
1511 FIXME("unsupported AuthzSvr %u\n", AuthzSvr);
1512 return RPC_S_UNKNOWN_AUTHZ_SERVICE;
1515 r = EnumerateSecurityPackagesW(&package_count, &packages);
1518 ERR("EnumerateSecurityPackagesA failed with error 0x%08x\n", r);
1519 return RPC_S_SEC_PKG_ERROR;
1522 for (i = 0; i < package_count; i++)
1523 if (packages[i].wRPCID == AuthnSvc)
1526 if (i == package_count)
1528 FIXME("unsupported AuthnSvc %u\n", AuthnSvc);
1529 FreeContextBuffer(packages);
1530 return RPC_S_UNKNOWN_AUTHN_SERVICE;
1533 TRACE("found package %s for service %u\n", debugstr_w(packages[i].Name), AuthnSvc);
1534 r = AcquireCredentialsHandleW((SEC_WCHAR *)ServerPrincName, packages[i].Name, SECPKG_CRED_OUTBOUND, NULL,
1535 AuthIdentity, NULL, NULL, &cred, &exp);
1536 cbMaxToken = packages[i].cbMaxToken;
1537 FreeContextBuffer(packages);
1538 if (r == ERROR_SUCCESS)
1540 if (bind->AuthInfo) RpcAuthInfo_Release(bind->AuthInfo);
1541 bind->AuthInfo = NULL;
1542 r = RpcAuthInfo_Create(AuthnLevel, AuthnSvc, cred, exp, cbMaxToken,
1543 AuthIdentity, &bind->AuthInfo);
1545 FreeCredentialsHandle(&cred);
1550 ERR("AcquireCredentialsHandleA failed with error 0x%08x\n", r);
1551 return RPC_S_SEC_PKG_ERROR;
1555 /***********************************************************************
1556 * RpcBindingSetAuthInfoA (RPCRT4.@)
1558 RPCRTAPI RPC_STATUS RPC_ENTRY
1559 RpcBindingSetAuthInfoA( RPC_BINDING_HANDLE Binding, RPC_CSTR ServerPrincName, ULONG AuthnLevel,
1560 ULONG AuthnSvc, RPC_AUTH_IDENTITY_HANDLE AuthIdentity, ULONG AuthzSvr )
1562 TRACE("%p %s %u %u %p %u\n", Binding, debugstr_a((const char*)ServerPrincName),
1563 AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvr);
1564 return RpcBindingSetAuthInfoExA(Binding, ServerPrincName, AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvr, NULL);
1567 /***********************************************************************
1568 * RpcBindingSetAuthInfoW (RPCRT4.@)
1570 RPCRTAPI RPC_STATUS RPC_ENTRY
1571 RpcBindingSetAuthInfoW( RPC_BINDING_HANDLE Binding, RPC_WSTR ServerPrincName, ULONG AuthnLevel,
1572 ULONG AuthnSvc, RPC_AUTH_IDENTITY_HANDLE AuthIdentity, ULONG AuthzSvr )
1574 TRACE("%p %s %u %u %p %u\n", Binding, debugstr_w((const WCHAR*)ServerPrincName),
1575 AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvr);
1576 return RpcBindingSetAuthInfoExW(Binding, ServerPrincName, AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvr, NULL);
1579 /***********************************************************************
1580 * RpcBindingSetOption (RPCRT4.@)
1582 RPC_STATUS WINAPI RpcBindingSetOption(RPC_BINDING_HANDLE BindingHandle, ULONG Option, ULONG OptionValue)
1584 FIXME("(%p, %d, %d): stub\n", BindingHandle, Option, OptionValue);