VMDNS_API DWORD VmDnsOpenServerWithTimeOutA( PCSTR pszNetworkAddress, PCSTR pszUserName, PCSTR pszDomain, PCSTR pszPassword, DWORD dwFlags, PVOID pReserved, DWORD dwTimeOut, PVMDNS_SERVER_CONTEXT *ppServerContext ) { DWORD dwError = 0; handle_t hBinding = NULL; PVMDNS_SERVER_CONTEXT pServerContext = NULL; CHAR szRpcPort[] = VMDNS_RPC_TCP_END_POINT; dwError = VmDnsAllocateMemory( sizeof(*pServerContext), (PVOID)&pServerContext); BAIL_ON_VMDNS_ERROR(dwError); dwError = VmDnsCreateBindingHandleA( pszNetworkAddress, szRpcPort, pszUserName, pszDomain, pszPassword, &hBinding); BAIL_ON_VMDNS_ERROR(dwError); pServerContext->hBinding = hBinding; hBinding = NULL; rpc_mgmt_set_com_timeout(pServerContext->hBinding, dwTimeOut, &dwError); BAIL_ON_VMDNS_ERROR(dwError); *ppServerContext = pServerContext; pServerContext = NULL; cleanup: return dwError; error: VmDnsCloseServer(pServerContext); goto cleanup; }
static NTSTATUS LsaInitBindingFullA( OUT PLSA_BINDING phBinding, IN PCSTR pszProtSeq, IN PCSTR pszHostname, IN PCSTR pszEndpoint, IN PCSTR pszUuid, IN PCSTR pszOptions, IN PIO_CREDS pCreds ) { NTSTATUS ntStatus = STATUS_SUCCESS; unsigned32 rpcStatus = RPC_S_OK; unsigned32 rpcStatus2 = RPC_S_OK; PBYTE pbBindingString = NULL; PBYTE pbProtSeq = NULL; PBYTE pbEndpoint = NULL; PBYTE pbUuid = NULL; PBYTE pbOpts = NULL; PBYTE pbAddr = NULL; handle_t hBinding = NULL; rpc_transport_info_handle_t hInfo = NULL; BAIL_ON_INVALID_PTR(phBinding, ntStatus); BAIL_ON_INVALID_PTR(pszProtSeq, ntStatus); pbProtSeq = (PBYTE)strdup(pszProtSeq); BAIL_ON_NULL_PTR(pbProtSeq, ntStatus); if (pszEndpoint != NULL) { pbEndpoint = (PBYTE) strdup(pszEndpoint); BAIL_ON_NULL_PTR(pbEndpoint, ntStatus); } if (pszUuid != NULL) { pbUuid = (PBYTE)strdup(pszUuid); BAIL_ON_NULL_PTR(pbUuid, ntStatus); } if (pszOptions != NULL) { pbOpts = (PBYTE)strdup(pszOptions); BAIL_ON_NULL_PTR(pbOpts, ntStatus); } if (pszHostname) { pbAddr = (PBYTE)strdup(pszHostname); BAIL_ON_NULL_PTR(pbAddr, ntStatus); } rpc_string_binding_compose( pbUuid, pbProtSeq, pbAddr, pbEndpoint, pbOpts, &pbBindingString, &rpcStatus); BAIL_ON_RPC_STATUS(rpcStatus); rpc_binding_from_string_binding( pbBindingString, &hBinding, &rpcStatus); BAIL_ON_RPC_STATUS(rpcStatus); if (strcmp(pszProtSeq, "ncacn_np") == 0) { rpc_smb_transport_info_from_lwio_creds( pCreds, &hInfo, &rpcStatus); BAIL_ON_RPC_STATUS(rpcStatus); rpc_binding_set_transport_info( hBinding, hInfo, &rpcStatus); BAIL_ON_RPC_STATUS(rpcStatus); hInfo = NULL; } rpc_mgmt_set_com_timeout(hBinding, 6, &rpcStatus); BAIL_ON_RPC_STATUS(rpcStatus); *phBinding = (LSA_BINDING)hBinding; cleanup: LW_SAFE_FREE_MEMORY(pbProtSeq); LW_SAFE_FREE_MEMORY(pbEndpoint); LW_SAFE_FREE_MEMORY(pbUuid); LW_SAFE_FREE_MEMORY(pbOpts); LW_SAFE_FREE_MEMORY(pbAddr); if (pbBindingString) { rpc_string_free(&pbBindingString, &rpcStatus2); } if ((rpcStatus == RPC_S_OK) && (rpcStatus2 != RPC_S_OK)) { rpcStatus = rpcStatus2; } if (hInfo) { rpc_smb_transport_info_free(hInfo); } if (ntStatus == STATUS_SUCCESS && rpcStatus != RPC_S_OK) { ntStatus = LwRpcStatusToNtStatus(rpcStatus); } return ntStatus; error: if (hBinding) { rpc_binding_free(&hBinding, &rpcStatus2); } if (phBinding) { *phBinding = NULL; } goto cleanup; }