📄 rpc_binding.c
字号:
/*********************************************************************** * RpcBindingToStringBindingW (RPCRT4.@) */RPC_STATUS WINAPI RpcBindingToStringBindingW( RPC_BINDING_HANDLE Binding, RPC_WSTR *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;}/*********************************************************************** * RpcBindingCopy (RPCRT4.@) */RPC_STATUS RPC_ENTRY RpcBindingCopy( RPC_BINDING_HANDLE SourceBinding, RPC_BINDING_HANDLE* DestinationBinding){ RpcBinding *DestBinding; RpcBinding *SrcBinding = (RpcBinding*)SourceBinding; RPC_STATUS status; TRACE("(%p, %p)\n", SourceBinding, DestinationBinding); status = RPCRT4_AllocBinding(&DestBinding, SrcBinding->server); if (status != RPC_S_OK) return status; DestBinding->ObjectUuid = SrcBinding->ObjectUuid; DestBinding->BlockingFn = SrcBinding->BlockingFn; DestBinding->Protseq = RPCRT4_strndupA(SrcBinding->Protseq, -1); DestBinding->NetworkAddr = RPCRT4_strndupA(SrcBinding->NetworkAddr, -1); DestBinding->Endpoint = RPCRT4_strndupA(SrcBinding->Endpoint, -1); DestBinding->NetworkOptions = RPCRT4_strdupW(SrcBinding->NetworkOptions); if (SrcBinding->Assoc) SrcBinding->Assoc->refs++; DestBinding->Assoc = SrcBinding->Assoc; if (SrcBinding->AuthInfo) RpcAuthInfo_AddRef(SrcBinding->AuthInfo); DestBinding->AuthInfo = SrcBinding->AuthInfo; if (SrcBinding->QOS) RpcQualityOfService_AddRef(SrcBinding->QOS); DestBinding->QOS = SrcBinding->QOS; *DestinationBinding = DestBinding; return RPC_S_OK;}/*********************************************************************** * 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;}static inline BOOL has_nt_auth_identity(ULONG AuthnLevel){ switch (AuthnLevel) { case RPC_C_AUTHN_GSS_NEGOTIATE: case RPC_C_AUTHN_WINNT: case RPC_C_AUTHN_GSS_KERBEROS: return TRUE; default: return FALSE; }}static RPC_STATUS RpcAuthInfo_Create(ULONG AuthnLevel, ULONG AuthnSvc, CredHandle cred, TimeStamp exp, ULONG cbMaxToken, RPC_AUTH_IDENTITY_HANDLE identity, RpcAuthInfo **ret){ RpcAuthInfo *AuthInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(*AuthInfo)); if (!AuthInfo) return ERROR_OUTOFMEMORY; AuthInfo->refs = 1; AuthInfo->AuthnLevel = AuthnLevel; AuthInfo->AuthnSvc = AuthnSvc; AuthInfo->cred = cred; AuthInfo->exp = exp; AuthInfo->cbMaxToken = cbMaxToken; AuthInfo->identity = identity; /* duplicate the SEC_WINNT_AUTH_IDENTITY structure, if applicable, to * enable better matching in RpcAuthInfo_IsEqual */ if (identity && has_nt_auth_identity(AuthnSvc)) { const SEC_WINNT_AUTH_IDENTITY_W *nt_identity = identity; AuthInfo->nt_identity = HeapAlloc(GetProcessHeap(), 0, sizeof(*AuthInfo->nt_identity)); if (!AuthInfo->nt_identity) { HeapFree(GetProcessHeap(), 0, AuthInfo); return ERROR_OUTOFMEMORY; } AuthInfo->nt_identity->Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE; if (nt_identity->Flags & SEC_WINNT_AUTH_IDENTITY_UNICODE) AuthInfo->nt_identity->User = RPCRT4_strndupW(nt_identity->User, nt_identity->UserLength); else AuthInfo->nt_identity->User = RPCRT4_strndupAtoW((const char *)nt_identity->User, nt_identity->UserLength); AuthInfo->nt_identity->UserLength = nt_identity->UserLength; if (nt_identity->Flags & SEC_WINNT_AUTH_IDENTITY_UNICODE) AuthInfo->nt_identity->Domain = RPCRT4_strndupW(nt_identity->Domain, nt_identity->DomainLength); else AuthInfo->nt_identity->Domain = RPCRT4_strndupAtoW((const char *)nt_identity->Domain, nt_identity->DomainLength); AuthInfo->nt_identity->DomainLength = nt_identity->DomainLength; if (nt_identity->Flags & SEC_WINNT_AUTH_IDENTITY_UNICODE) AuthInfo->nt_identity->Password = RPCRT4_strndupW(nt_identity->Password, nt_identity->PasswordLength); else AuthInfo->nt_identity->Password = RPCRT4_strndupAtoW((const char *)nt_identity->Password, nt_identity->PasswordLength); AuthInfo->nt_identity->PasswordLength = nt_identity->PasswordLength; if (!AuthInfo->nt_identity->User || !AuthInfo->nt_identity->Domain || !AuthInfo->nt_identity->Password) { HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity->User); HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity->Domain); HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity->Password); HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity); HeapFree(GetProcessHeap(), 0, AuthInfo); return ERROR_OUTOFMEMORY; } } else AuthInfo->nt_identity = NULL; *ret = AuthInfo; return RPC_S_OK;}ULONG RpcAuthInfo_AddRef(RpcAuthInfo *AuthInfo){ return InterlockedIncrement(&AuthInfo->refs);}ULONG RpcAuthInfo_Release(RpcAuthInfo *AuthInfo){ ULONG refs = InterlockedDecrement(&AuthInfo->refs); if (!refs) { FreeCredentialsHandle(&AuthInfo->cred); if (AuthInfo->nt_identity) { HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity->User); HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity->Domain); HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity->User); HeapFree(GetProcessHeap(), 0, AuthInfo->nt_identity); } HeapFree(GetProcessHeap(), 0, AuthInfo); } return refs;}BOOL RpcAuthInfo_IsEqual(const RpcAuthInfo *AuthInfo1, const RpcAuthInfo *AuthInfo2){ if (AuthInfo1 == AuthInfo2) return TRUE; if (!AuthInfo1 || !AuthInfo2) return FALSE; if ((AuthInfo1->AuthnLevel != AuthInfo2->AuthnLevel) || (AuthInfo1->AuthnSvc != AuthInfo2->AuthnSvc)) return FALSE; if (AuthInfo1->identity == AuthInfo2->identity) return TRUE; if (!AuthInfo1->identity || !AuthInfo2->identity) return FALSE; if (has_nt_auth_identity(AuthInfo1->AuthnSvc)) { const SEC_WINNT_AUTH_IDENTITY_W *identity1 = AuthInfo1->nt_identity; const SEC_WINNT_AUTH_IDENTITY_W *identity2 = AuthInfo2->nt_identity; /* compare user names */ if (identity1->UserLength != identity2->UserLength || memcmp(identity1->User, identity2->User, identity1->UserLength)) return FALSE; /* compare domain names */ if (identity1->DomainLength != identity2->DomainLength || memcmp(identity1->Domain, identity2->Domain, identity1->DomainLength)) return FALSE; /* compare passwords */ if (identity1->PasswordLength != identity2->PasswordLength || memcmp(identity1->Password, identity2->Password, identity1->PasswordLength)) return FALSE; } else return FALSE; return TRUE;}static RPC_STATUS RpcQualityOfService_Create(const RPC_SECURITY_QOS *qos_src, BOOL unicode, RpcQualityOfService **qos_dst){ RpcQualityOfService *qos = HeapAlloc(GetProcessHeap(), 0, sizeof(*qos)); if (!qos) return RPC_S_OUT_OF_RESOURCES; qos->refs = 1; qos->qos = HeapAlloc(GetProcessHeap(), 0, sizeof(*qos->qos)); if (!qos->qos) goto error; qos->qos->Version = qos_src->Version; qos->qos->Capabilities = qos_src->Capabilities; qos->qos->IdentityTracking = qos_src->IdentityTracking; qos->qos->ImpersonationType = qos_src->ImpersonationType; qos->qos->AdditionalSecurityInfoType = 0; if (qos_src->Version >= 2) { const RPC_SECURITY_QOS_V2_W *qos_src2 = (const RPC_SECURITY_QOS_V2_W *)qos_src; qos->qos->AdditionalSecurityInfoType = qos_src2->AdditionalSecurityInfoType; if (qos_src2->AdditionalSecurityInfoType == RPC_C_AUTHN_INFO_TYPE_HTTP) { const RPC_HTTP_TRANSPORT_CREDENTIALS_W *http_credentials_src = qos_src2->u.HttpCredentials; RPC_HTTP_TRANSPORT_CREDENTIALS_W *http_credentials_dst; http_credentials_dst = HeapAlloc(GetProcessHeap(), 0, sizeof(*http_credentials_dst)); qos->qos->u.HttpCredentials = http_credentials_dst; if (!http_credentials_dst) goto error; http_credentials_dst->TransportCredentials = NULL; http_credentials_dst->Flags = http_credentials_src->Flags; http_credentials_dst->AuthenticationTarget = http_credentials_src->AuthenticationTarget; http_credentials_dst->NumberOfAuthnSchemes = http_credentials_src->NumberOfAuthnSchemes; http_credentials_dst->AuthnSchemes = NULL; http_credentials_dst->ServerCertificateSubject = NULL; if (http_credentials_src->TransportCredentials) { SEC_WINNT_AUTH_IDENTITY_W *cred_dst; cred_dst = http_credentials_dst->TransportCredentials = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*cred_dst)); if (!cred_dst) goto error; cred_dst->Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE; if (unicode) { const SEC_WINNT_AUTH_IDENTITY_W *cred_src = http_credentials_src->TransportCredentials; cred_dst->UserLength = cred_src->UserLength; cred_dst->PasswordLength = cred_src->PasswordLength; cred_dst->DomainLength = cred_src->DomainLength; cred_dst->User = RPCRT4_strndupW(cred_src->User, cred_src->UserLength); cred_dst->Password = RPCRT4_strndupW(cred_src->Password, cred_src->PasswordLength); cred_dst->Domain = RPCRT4_strndupW(cred_src->Domain, cred_src->DomainLength); } else { const SEC_WINNT_AUTH_IDENTITY_A *cred_src = (const SEC_WINNT_AUTH_IDENTITY_A *)http_credentials_src->TransportCredentials; cred_dst->UserLength = MultiByteToWideChar(CP_ACP, 0, (char *)cred_src->User, cred_src->UserLength, NULL, 0); cred_dst->DomainLength = MultiByteToWideChar(CP_ACP, 0, (char *)cred_src->Domain, cred_src->DomainLength, NULL, 0); cred_dst->PasswordLength = MultiByteToWideChar(CP_ACP, 0, (char *)cred_src->Password, cred_src->PasswordLength, NULL, 0); cred_dst->User = HeapAlloc(GetProcessHeap(), 0, cred_dst->UserLength * sizeof(WCHAR)); cred_dst->Password = HeapAlloc(GetProcessHeap(), 0, cred_dst->PasswordLength * sizeof(WCHAR)); cred_dst->Domain = HeapAlloc(GetProcessHeap(), 0, cred_dst->DomainLength * sizeof(WCHAR)); if (!cred_dst || !cred_dst->Password || !cred_dst->Domain) goto error; MultiByteToWideChar(CP_ACP, 0, (char *)cred_src->User, cred_src->UserLength, cred_dst->User, cred_dst->UserLength); MultiByteToWideChar(CP_ACP, 0, (char *)cred_src->Domain, cred_src->DomainLength, cred_dst->Domain, cred_dst->DomainLength); MultiByteToWideChar(CP_ACP, 0, (char *)cred_src->Password, cred_src->PasswordLength, cred_dst->Password, cred_dst->PasswordLength); } } if (http_credentials_src->NumberOfAuthnSchemes) { http_credentials_dst->AuthnSchemes = HeapAlloc(GetProcessHeap(), 0, http_credentials_src->NumberOfAuthnSchemes * sizeof(*http_credentials_dst->AuthnSchemes)); if (!http_credentials_dst->AuthnSchemes) goto error; memcpy(http_credentials_dst->AuthnSchemes, http_credentials_src->AuthnSchemes, http_credentials_src->NumberOfAuthnSchemes * sizeof(*http_credentials_dst->AuthnSchemes)); } if (http_credentials_src->ServerCertificateSubject) { if (unicode) http_credentials_dst->ServerCertificateSubject = RPCRT4_strndupW(http_credentials_src->ServerCertificateSubject, strlenW(http_credentials_src->ServerCertificateSubject)); else http_credentials_dst->ServerCertificateSubject = RPCRT4_strdupAtoW((char *)http_credentials_src->ServerCertificateSubject); if (!http_credentials_dst->ServerCertificateSubject) goto error; } } } *qos_dst = qos; return RPC_S_OK;error: if (qos->qos) { if (qos->qos->AdditionalSecurityInfoType == RPC_C_AUTHN_INFO_TYPE_HTTP && qos->qos->u.HttpCredentials) { if (qos->qos->u.HttpCredentials->TransportCredentials) { HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials->User); HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials->Domain); HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials->Password); HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials); } HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->AuthnSchemes); HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->ServerCertificateSubject); HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials); } HeapFree(GetProcessHeap(), 0, qos->qos); } HeapFree(GetProcessHeap(), 0, qos); return RPC_S_OUT_OF_RESOURCES;}ULONG RpcQualityOfService_AddRef(RpcQualityOfService *qos){ return InterlockedIncrement(&qos->refs);}ULONG RpcQualityOfService_Release(RpcQualityOfService *qos){ ULONG refs = InterlockedDecrement(&qos->refs); if (!refs) { if (qos->qos->AdditionalSecurityInfoType == RPC_C_AUTHN_INFO_TYPE_HTTP) { if (qos->qos->u.HttpCredentials->TransportCredentials) { HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials->User); HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials->Domain); HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials->Password); HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->TransportCredentials); } HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->AuthnSchemes); HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials->ServerCertificateSubject); HeapFree(GetProcessHeap(), 0, qos->qos->u.HttpCredentials); } HeapFree(GetProcessHeap(), 0, qos->qos); HeapFree(GetProcessHeap(), 0, qos); } return refs;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -