📄 rpc_binding.c
字号:
*Options = (unsigned char*) RPCRT4_strconcatA( (char*)*Options, opt);
HeapFree(GetProcessHeap(), 0, opt);
} else
*Options = (unsigned char*) opt;
}
}
}
data = close+1;
if (*data) goto fail;
}
else if (NetworkAddr)
*NetworkAddr = (unsigned char*)RPCRT4_strdupA(data);
return RPC_S_OK;
fail:
if (ObjUuid) RpcStringFreeA((unsigned char**)ObjUuid);
if (Protseq) RpcStringFreeA((unsigned char**)Protseq);
if (NetworkAddr) RpcStringFreeA((unsigned char**)NetworkAddr);
if (Endpoint) RpcStringFreeA((unsigned char**)Endpoint);
if (Options) RpcStringFreeA((unsigned char**)Options);
return RPC_S_INVALID_STRING_BINDING;
}
/***********************************************************************
* RpcStringBindingParseW (RPCRT4.@)
*/
RPC_STATUS WINAPI RpcStringBindingParseW( LPWSTR StringBinding, LPWSTR *ObjUuid,
LPWSTR *Protseq, LPWSTR *NetworkAddr,
LPWSTR *Endpoint, LPWSTR *Options)
{
WCHAR *data, *next;
static const WCHAR ep_opt[] = {'e','n','d','p','o','i','n','t','=',0};
TRACE("(%s,%p,%p,%p,%p,%p)\n", debugstr_w(StringBinding),
ObjUuid, Protseq, NetworkAddr, Endpoint, Options);
if (ObjUuid) *ObjUuid = NULL;
if (Protseq) *Protseq = NULL;
if (NetworkAddr) *NetworkAddr = NULL;
if (Endpoint) *Endpoint = NULL;
if (Options) *Options = NULL;
data = StringBinding;
next = strchrW(data, '@');
if (next) {
if (ObjUuid) *ObjUuid = RPCRT4_strndupW(data, next - data);
data = next+1;
}
next = strchrW(data, ':');
if (next) {
if (Protseq) *Protseq = RPCRT4_strndupW(data, next - data);
data = next+1;
}
next = strchrW(data, '[');
if (next) {
WCHAR *close, *opt;
if (NetworkAddr) *NetworkAddr = RPCRT4_strndupW(data, next - data);
data = next+1;
close = strchrW(data, ']');
if (!close) goto fail;
/* tokenize options */
while (data < close) {
next = strchrW(data, ',');
if (!next || next > close) next = close;
/* FIXME: this is kind of inefficient */
opt = RPCRT4_strndupW(data, next - data);
data = next+1;
/* parse option */
next = strchrW(opt, '=');
if (!next) {
/* not an option, must be an endpoint */
if (*Endpoint) goto fail;
*Endpoint = opt;
} else {
if (strncmpW(opt, ep_opt, strlenW(ep_opt)) == 0) {
/* endpoint option */
if (*Endpoint) goto fail;
*Endpoint = RPCRT4_strdupW(next+1);
HeapFree(GetProcessHeap(), 0, opt);
} else {
/* network option */
if (*Options) {
/* FIXME: this is kind of inefficient */
*Options = RPCRT4_strconcatW(*Options, opt);
HeapFree(GetProcessHeap(), 0, opt);
} else
*Options = opt;
}
}
}
data = close+1;
if (*data) goto fail;
} else if (NetworkAddr)
*NetworkAddr = RPCRT4_strdupW(data);
return RPC_S_OK;
fail:
if (ObjUuid) RpcStringFreeW(ObjUuid);
if (Protseq) RpcStringFreeW(Protseq);
if (NetworkAddr) RpcStringFreeW(NetworkAddr);
if (Endpoint) RpcStringFreeW(Endpoint);
if (Options) RpcStringFreeW(Options);
return RPC_S_INVALID_STRING_BINDING;
}
/***********************************************************************
* RpcBindingFree (RPCRT4.@)
*/
RPC_STATUS WINAPI RpcBindingFree( RPC_BINDING_HANDLE* Binding )
{
RPC_STATUS status;
TRACE("(%p) = %p\n", Binding, *Binding);
status = RPCRT4_DestroyBinding(*Binding);
if (status == RPC_S_OK) *Binding = 0;
return status;
}
/***********************************************************************
* RpcBindingVectorFree (RPCRT4.@)
*/
RPC_STATUS WINAPI RpcBindingVectorFree( RPC_BINDING_VECTOR** BindingVector )
{
RPC_STATUS status;
unsigned long c;
TRACE("(%p)\n", BindingVector);
for (c=0; c<(*BindingVector)->Count; c++) {
status = RpcBindingFree(&(*BindingVector)->BindingH[c]);
}
HeapFree(GetProcessHeap(), 0, *BindingVector);
*BindingVector = NULL;
return RPC_S_OK;
}
/***********************************************************************
* RpcBindingInqObject (RPCRT4.@)
*/
RPC_STATUS WINAPI RpcBindingInqObject( RPC_BINDING_HANDLE Binding, UUID* ObjectUuid )
{
RpcBinding* bind = (RpcBinding*)Binding;
TRACE("(%p,%p) = %s\n", Binding, ObjectUuid, debugstr_guid(&bind->ObjectUuid));
memcpy(ObjectUuid, &bind->ObjectUuid, sizeof(UUID));
return RPC_S_OK;
}
/***********************************************************************
* RpcBindingSetObject (RPCRT4.@)
*/
RPC_STATUS WINAPI RpcBindingSetObject( RPC_BINDING_HANDLE Binding, UUID* ObjectUuid )
{
RpcBinding* bind = (RpcBinding*)Binding;
TRACE("(%p,%s)\n", Binding, debugstr_guid(ObjectUuid));
if (bind->server) return RPC_S_WRONG_KIND_OF_BINDING;
return RPCRT4_SetBindingObject(Binding, ObjectUuid);
}
/***********************************************************************
* RpcBindingFromStringBindingA (RPCRT4.@)
*/
RPC_STATUS WINAPI RpcBindingFromStringBindingA( unsigned char *StringBinding, RPC_BINDING_HANDLE* Binding )
{
RPC_STATUS ret;
RpcBinding* bind = NULL;
unsigned char *ObjectUuid, *Protseq, *NetworkAddr, *Endpoint, *Options;
UUID Uuid;
TRACE("(%s,%p)\n", debugstr_a((char*)StringBinding), Binding);
ret = RpcStringBindingParseA(StringBinding, &ObjectUuid, &Protseq,
&NetworkAddr, &Endpoint, &Options);
if (ret != RPC_S_OK) return ret;
ret = UuidFromStringA(ObjectUuid, &Uuid);
if (ret == RPC_S_OK)
ret = RPCRT4_CreateBindingA(&bind, FALSE, (char*)Protseq);
if (ret == RPC_S_OK)
ret = RPCRT4_SetBindingObject(bind, &Uuid);
if (ret == RPC_S_OK)
ret = RPCRT4_CompleteBindingA(bind, (char*)NetworkAddr, (char*)Endpoint, (char*)Options);
RpcStringFreeA((unsigned char**)&Options);
RpcStringFreeA((unsigned char**)&Endpoint);
RpcStringFreeA((unsigned char**)&NetworkAddr);
RpcStringFreeA((unsigned char**)&Protseq);
RpcStringFreeA((unsigned char**)&ObjectUuid);
if (ret == RPC_S_OK)
*Binding = (RPC_BINDING_HANDLE)bind;
else
RPCRT4_DestroyBinding(bind);
return ret;
}
/***********************************************************************
* RpcBindingFromStringBindingW (RPCRT4.@)
*/
RPC_STATUS WINAPI RpcBindingFromStringBindingW( LPWSTR StringBinding, RPC_BINDING_HANDLE* Binding )
{
RPC_STATUS ret;
RpcBinding* bind = NULL;
LPWSTR ObjectUuid, Protseq, NetworkAddr, Endpoint, Options;
UUID Uuid;
TRACE("(%s,%p)\n", debugstr_w(StringBinding), Binding);
ret = RpcStringBindingParseW(StringBinding, &ObjectUuid, &Protseq,
&NetworkAddr, &Endpoint, &Options);
if (ret != RPC_S_OK) return ret;
ret = UuidFromStringW(ObjectUuid, &Uuid);
if (ret == RPC_S_OK)
ret = RPCRT4_CreateBindingW(&bind, FALSE, Protseq);
if (ret == RPC_S_OK)
ret = RPCRT4_SetBindingObject(bind, &Uuid);
if (ret == RPC_S_OK)
ret = RPCRT4_CompleteBindingW(bind, NetworkAddr, Endpoint, Options);
RpcStringFreeW(&Options);
RpcStringFreeW(&Endpoint);
RpcStringFreeW(&NetworkAddr);
RpcStringFreeW(&Protseq);
RpcStringFreeW(&ObjectUuid);
if (ret == RPC_S_OK)
*Binding = (RPC_BINDING_HANDLE)bind;
else
RPCRT4_DestroyBinding(bind);
return ret;
}
/***********************************************************************
* RpcBindingToStringBindingA (RPCRT4.@)
*/
RPC_STATUS WINAPI RpcBindingToStringBindingA( RPC_BINDING_HANDLE Binding, unsigned char** StringBinding )
{
RPC_STATUS ret;
RpcBinding* bind = (RpcBinding*)Binding;
LPSTR ObjectUuid;
TRACE("(%p,%p)\n", Binding, StringBinding);
ret = UuidToStringA(&bind->ObjectUuid, (unsigned char**)&ObjectUuid);
if (ret != RPC_S_OK) return ret;
ret = RpcStringBindingComposeA((unsigned char*) ObjectUuid, (unsigned char*)bind->Protseq, (unsigned char*) bind->NetworkAddr,
(unsigned char*) bind->Endpoint, NULL, StringBinding);
RpcStringFreeA((unsigned char**)&ObjectUuid);
return ret;
}
/***********************************************************************
* RpcBindingToStringBindingW (RPCRT4.@)
*/
RPC_STATUS WINAPI RpcBindingToStringBindingW( RPC_BINDING_HANDLE Binding, unsigned short** StringBinding )
{
RPC_STATUS ret;
unsigned char *str = NULL;
TRACE("(%p,%p)\n", Binding, StringBinding);
ret = RpcBindingToStringBindingA(Binding, &str);
*StringBinding = RPCRT4_strdupAtoW((char*)str);
RpcStringFreeA((unsigned char**)&str);
return ret;
}
/***********************************************************************
* I_RpcBindingSetAsync (RPCRT4.@)
* NOTES
* Exists in win9x and winNT, but with different number of arguments
* (9x version has 3 arguments, NT has 2).
*/
RPC_STATUS WINAPI I_RpcBindingSetAsync( RPC_BINDING_HANDLE Binding, RPC_BLOCKING_FN BlockingFn)
{
RpcBinding* bind = (RpcBinding*)Binding;
TRACE( "(%p,%p): stub\n", Binding, BlockingFn );
bind->BlockingFn = BlockingFn;
return RPC_S_OK;
}
/***********************************************************************
* RpcNetworkIsProtseqValidA (RPCRT4.@)
*/
RPC_STATUS WINAPI RpcNetworkIsProtseqValidA(unsigned char *protseq) {
UNICODE_STRING protseqW;
if (!protseq) return RPC_S_INVALID_RPC_PROTSEQ; /* ? */
if (RtlCreateUnicodeStringFromAsciiz(&protseqW, (char*)protseq)) {
RPC_STATUS ret = RpcNetworkIsProtseqValidW(protseqW.Buffer);
RtlFreeUnicodeString(&protseqW);
return ret;
} else return RPC_S_OUT_OF_MEMORY;
}
/***********************************************************************
* RpcNetworkIsProtseqValidW (RPCRT4.@)
*
* Checks if the given protocol sequence is known by the RPC system.
* If it is, returns RPC_S_OK, otherwise RPC_S_PROTSEQ_NOT_SUPPORTED.
*
* We currently support:
* ncalrpc local-only rpc over LPC (LPC is not really used)
* ncacn_np rpc over named pipes
*/
RPC_STATUS WINAPI RpcNetworkIsProtseqValidW(LPWSTR protseq) {
static const WCHAR protseqsW[][15] = {
{'n','c','a','l','r','p','c',0},
{'n','c','a','c','n','_','n','p',0}
};
static const int count = sizeof(protseqsW) / sizeof(protseqsW[0]);
int i;
if (!protseq) return RPC_S_INVALID_RPC_PROTSEQ; /* ? */
for (i = 0; i < count; i++) {
if (!strcmpW(protseq, protseqsW[i])) return RPC_S_OK;
}
FIXME("Unknown protseq %s - we probably need to implement it one day\n", debugstr_w(protseq));
return RPC_S_PROTSEQ_NOT_SUPPORTED;
}
/***********************************************************************
* RpcImpersonateClient (RPCRT4.@)
*
* Impersonates the client connected via a binding handle so that security
* checks are done in the context of the client.
*
* PARAMS
* BindingHandle [I] Handle to the binding to the client.
*
* RETURNS
* Success: RPS_S_OK.
* Failure: RPC_STATUS value.
*
* NOTES
*
* If BindingHandle is NULL then the function impersonates the client
* connected to the binding handle of the current thread.
*/
RPC_STATUS WINAPI RpcImpersonateClient(RPC_BINDING_HANDLE BindingHandle)
{
FIXME("(%p): stub\n", BindingHandle);
ImpersonateSelf(SecurityImpersonation);
return RPC_S_OK;
}
/***********************************************************************
* RpcRevertToSelfEx (RPCRT4.@)
*
* Stops impersonating the client connected to the binding handle so that security
* checks are no longer done in the context of the client.
*
* PARAMS
* BindingHandle [I] Handle to the binding to the client.
*
* RETURNS
* Success: RPS_S_OK.
* Failure: RPC_STATUS value.
*
* NOTES
*
* If BindingHandle is NULL then the function stops impersonating the client
* connected to the binding handle of the current thread.
*/
RPC_STATUS WINAPI RpcRevertToSelfEx(RPC_BINDING_HANDLE BindingHandle)
{
FIXME("(%p): stub\n", BindingHandle);
return RPC_S_OK;
}
/***********************************************************************
* RpcRevertToSelf (RPCRT4.@)
*/
RPC_STATUS WINAPI RpcRevertToSelf(void)
{
FIXME("stub\n");
RevertToSelf();
return RPC_S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -