static void client(const char *test) { if (strcmp(test, "tcp_basic") == 0) { static unsigned char iptcp[] = "ncacn_ip_tcp"; static unsigned char address[] = "127.0.0.1"; static unsigned char port[] = PORT; unsigned char *binding; ok(RPC_S_OK == RpcStringBindingCompose(NULL, iptcp, address, port, NULL, &binding), "RpcStringBindingCompose\n"); ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n"); run_tests(); ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n"); ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n"); } else if (strcmp(test, "np_basic") == 0) { static unsigned char np[] = "ncacn_np"; static unsigned char address[] = "\\\\."; static unsigned char pipe[] = PIPE; unsigned char *binding; ok(RPC_S_OK == RpcStringBindingCompose(NULL, np, address, pipe, NULL, &binding), "RpcStringBindingCompose\n"); ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n"); run_tests(); stop(); ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n"); ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n"); } }
BOOL kull_m_rpc_drsr_deleteBinding(RPC_BINDING_HANDLE *hBinding) { BOOL status = FALSE; if(status = (RpcBindingFree(hBinding) == RPC_S_OK)) *hBinding = NULL; return status; }
/** @framework_function="RPCClientInterfaceTerminate" Purpose: Teardown the RPC client interface by unbinding and freeing the handles. <br> <br> Notes: <br> <br> MSDN_Ref: HTTP://MSDN.Microsoft.com/En-US/Library/Windows/Desktop/AA378651.aspx <br> HTTP://MSDN.Microsoft.com/En-US/Library/Windows/Desktop/AA375613.aspx <br> HTTP://MSDN.Microsoft.com/En-US/Library/Windows/Desktop/AA375588.aspx <br> */ UINT32 RPCClientInterfaceTerminate() { RPC_STATUS status = RPC_S_OK; if(pRPCData && pRPCData->bindingHandle) { if(pRPCData->isBound) { status = RpcBindingUnbind(pRPCData->bindingHandle); if(status != RPC_S_OK) HlprLogError(L"RPCClientInterfaceTerminate : RpcBindingUnbind() [status: %#x]", status); else pRPCData->isBound = FALSE; } status = RpcBindingFree(&(pRPCData->bindingHandle)); if(status != RPC_S_OK) HlprLogError(L"RPCClientInterfaceTerminate : RpcBindingFree() [status: %#x]", status); } HLPR_DELETE(pRPCData); return status; }
/*********************************************************************** * RpcSmDestroyClientContext [RPCRT4.@] */ RPC_STATUS WINAPI RpcSmDestroyClientContext(void **ContextHandle) { RPC_STATUS status = RPC_X_SS_CONTEXT_MISMATCH; struct context_handle_entry *che = NULL; TRACE("(%p)\n", ContextHandle); EnterCriticalSection(&ndr_context_cs); che = get_context_entry(*ContextHandle); *ContextHandle = NULL; if (che) { status = RPC_S_OK; list_remove(&che->entry); } LeaveCriticalSection(&ndr_context_cs); if (che) { RpcBindingFree(&che->handle); HeapFree(GetProcessHeap(), 0, che); } return status; }
static void test_RpcStringBindingFromBinding(void) { static unsigned char ncacn_np[] = "ncacn_np"; static unsigned char address[] = "."; static unsigned char endpoint[] = "\\pipe\\wine_rpc_test"; RPC_STATUS status; handle_t handle; RPC_CSTR binding; status = RpcStringBindingComposeA(NULL, ncacn_np, address, endpoint, NULL, &binding); ok(status == RPC_S_OK, "RpcStringBindingCompose failed (%u)\n", status); status = RpcBindingFromStringBindingA(binding, &handle); ok(status == RPC_S_OK, "RpcBindingFromStringBinding failed (%u)\n", status); RpcStringFreeA(&binding); status = RpcBindingToStringBindingA(handle, &binding); ok(status == RPC_S_OK, "RpcStringBindingFromBinding failed with error %u\n", status); ok(!strcmp((const char *)binding, "ncacn_np:.[\\\\pipe\\\\wine_rpc_test]"), "binding string didn't match what was expected: \"%s\"\n", binding); RpcStringFreeA(&binding); status = RpcBindingFree(&handle); ok(status == RPC_S_OK, "RpcBindingFree failed with error %u\n", status); }
JITManager::~JITManager() { if(m_targetHandle) { CleanupProcess(); } if (m_rpcBindingHandle) { RpcBindingFree(&m_rpcBindingHandle); } }
int main(int argc, char* argv[]) { RPC_STATUS status; unsigned char * pszNetworkAddress = NULL; unsigned char * pszStringBinding = NULL; int i; for ( i = 1; i < argc; ++i ) { if ( strcmp(argv[i], "-ip") == 0 ) { pszNetworkAddress = (unsigned char *)argv[++i]; } } status = RpcStringBindingCompose( NULL, (unsigned char *)"ncacn_np", pszNetworkAddress, (unsigned char *)"\\pipe\\{a5194558-21a6-4978-9610-2072fcf1dc6e}", NULL, &pszStringBinding ); if ( status != 0 ) { printf("RpcStringBindingCompose return %d !\n", status); return 1; } printf("pszStringBinding = %s\n", pszStringBinding); status = RpcBindingFromStringBinding( pszStringBinding, &hello_Binding ); if ( status != 0 ) { printf("RpcBindingFromStringBinding return %d !\n", status); return 1; } doRpcCall(); status = RpcStringFree( &pszStringBinding ); if ( status != 0 ) printf("RpcStringFree return %d !\n", status); status = RpcBindingFree( &hello_Binding ); if ( status != 0 ) printf("RpcBindingFree return %d !\n", status); getchar(); return 0; }
static void test_endpoint_mapper(RPC_CSTR protseq, RPC_CSTR address) { static unsigned char annotation[] = "Test annotation string."; RPC_STATUS status; RPC_BINDING_VECTOR *binding_vector; handle_t handle; unsigned char *binding; status = RpcServerRegisterIf(IFoo_v0_0_s_ifspec, NULL, NULL); ok(status == RPC_S_OK, "%s: RpcServerRegisterIf failed (%u)\n", protseq, status); status = RpcServerInqBindings(&binding_vector); ok(status == RPC_S_OK, "%s: RpcServerInqBindings failed with error %u\n", protseq, status); /* register endpoints created in test_RpcServerUseProtseq */ status = RpcEpRegisterA(IFoo_v0_0_s_ifspec, binding_vector, NULL, annotation); ok(status == RPC_S_OK, "%s: RpcEpRegisterA failed with error %u\n", protseq, status); /* reregister the same endpoint with no annotation */ status = RpcEpRegisterA(IFoo_v0_0_s_ifspec, binding_vector, NULL, NULL); ok(status == RPC_S_OK, "%s: RpcEpRegisterA failed with error %u\n", protseq, status); status = RpcStringBindingComposeA(NULL, protseq, address, NULL, NULL, &binding); ok(status == RPC_S_OK, "%s: RpcStringBindingCompose failed (%u)\n", protseq, status); status = RpcBindingFromStringBindingA(binding, &handle); ok(status == RPC_S_OK, "%s: RpcBindingFromStringBinding failed (%u)\n", protseq, status); RpcStringFreeA(&binding); status = RpcBindingReset(handle); ok(status == RPC_S_OK, "%s: RpcBindingReset failed with error %u\n", protseq, status); status = RpcEpResolveBinding(handle, IFoo_v0_0_s_ifspec); ok(status == RPC_S_OK || broken(status == RPC_S_SERVER_UNAVAILABLE), /* win9x */ "%s: RpcEpResolveBinding failed with error %u\n", protseq, status); status = RpcBindingReset(handle); ok(status == RPC_S_OK, "%s: RpcBindingReset failed with error %u\n", protseq, status); status = RpcBindingFree(&handle); ok(status == RPC_S_OK, "%s: RpcBindingFree failed with error %u\n", protseq, status); status = RpcServerUnregisterIf(NULL, NULL, FALSE); ok(status == RPC_S_OK, "%s: RpcServerUnregisterIf failed (%u)\n", protseq, status); status = RpcEpUnregister(IFoo_v0_0_s_ifspec, binding_vector, NULL); ok(status == RPC_S_OK, "%s: RpcEpUnregisterA failed with error %u\n", protseq, status); status = RpcBindingVectorFree(&binding_vector); ok(status == RPC_S_OK, "%s: RpcBindingVectorFree failed with error %u\n", protseq, status); }
DWORD VmDirRpcFreeBinding( handle_t* pBinding ) { DWORD dwError = ERROR_SUCCESS; #if !defined(_WIN32) || defined(HAVE_DCERPC_WIN32) rpc_binding_free(pBinding, &dwError); #else dwError = RpcBindingFree(pBinding); #endif return dwError; }
void __RPC_USER EVENTLOG_HANDLE_A_unbind(EVENTLOG_HANDLE_A UNCServerName, handle_t hBinding) { RPC_STATUS status; TRACE("EVENTLOG_HANDLE_A_unbind() called\n"); status = RpcBindingFree(&hBinding); if (status) { ERR("RpcBindingFree returned 0x%x\n", status); } }
void __RPC_USER WKSSVC_IDENTIFY_HANDLE_unbind(WKSSVC_IDENTIFY_HANDLE pszSystemName, handle_t hBinding) { RPC_STATUS status; TRACE("WKSSVC_IDENTIFY_HANDLE_unbind() called\n"); status = RpcBindingFree(&hBinding); if (status) { TRACE("RpcBindingFree returned 0x%x\n", status); } }
void __RPC_USER PLSAPR_SERVER_NAME_unbind(PLSAPR_SERVER_NAME pszSystemName, handle_t hBinding) { RPC_STATUS status; TRACE("PLSAPR_SERVER_NAME_unbind() called\n"); status = RpcBindingFree(&hBinding); if (status) { TRACE("RpcBindingFree returned 0x%x\n", status); } }
void __RPC_USER WLANSVC_HANDLE_unbind(WLANSVC_HANDLE szMachineName, handle_t hBinding) { RPC_STATUS Status; TRACE("WLANSVC_HANDLE_unbind() called\n"); Status = RpcBindingFree(&hBinding); if (Status != RPC_S_OK) { ERR("RpcBindingFree returned 0x%x\n", Status); } }
static void DsSetupUnbind( handle_t hBinding) { RPC_STATUS status; TRACE("DsSetupUnbind()\n"); status = RpcBindingFree(&hBinding); if (status) { TRACE("RpcBindingFree returned 0x%x\n", status); } }
static RPC_STATUS ScDestroyStatusBinding(VOID) { RPC_STATUS status; TRACE("ScDestroyStatusBinding() called\n"); if (hStatusBinding == NULL) return RPC_S_OK; status = RpcBindingFree(&hStatusBinding); if (status != RPC_S_OK) { ERR("RpcBindingFree returned 0x%x\n", status); } else { hStatusBinding = NULL; } return status; }
HRESULT StartClient( const wchar_t* sessionGuidStr, const GUID& sessionGuid, HCTXCMD* hContext ) { HRESULT hr = S_OK; RPC_STATUS rpcRet = RPC_S_OK; RPC_WSTR strBinding = NULL; RPC_BINDING_HANDLE hBinding = NULL; std::wstring endpoint( AGENT_CMD_IF_LOCAL_ENDPOINT_PREFIX ); endpoint.append( sessionGuidStr ); rpcRet = RpcStringBindingCompose( NULL, AGENT_LOCAL_PROTOCOL_SEQUENCE, NULL, (RPC_WSTR) endpoint.c_str(), NULL, &strBinding ); if ( rpcRet != RPC_S_OK ) return HRESULT_FROM_WIN32( rpcRet ); rpcRet = RpcBindingFromStringBinding( strBinding, &hBinding ); RpcStringFree( &strBinding ); if ( rpcRet != RPC_S_OK ) return HRESULT_FROM_WIN32( rpcRet ); // MSDN recommends letting the RPC runtime resolve the binding, so skip RpcEpResolveBinding hr = OpenCmdInterface( hBinding, sessionGuid, hContext ); // Now that we've connected and gotten a context handle, // we don't need the binding handle anymore. RpcBindingFree( &hBinding ); if ( FAILED( hr ) ) return hr; return S_OK; }
static IrotHandle get_irot_handle(void) { if (!irot_handle) { RPC_STATUS status; RPC_WSTR binding; IrotHandle new_handle; unsigned short ncacn_np[] = IROT_PROTSEQ; unsigned short endpoint[] = IROT_ENDPOINT; status = RpcStringBindingComposeW(NULL, ncacn_np, NULL, endpoint, NULL, &binding); if (status == RPC_S_OK) { status = RpcBindingFromStringBindingW(binding, &new_handle); RpcStringFreeW(&binding); } if (status != RPC_S_OK) return NULL; if (InterlockedCompareExchangePointer(&irot_handle, new_handle, NULL)) /* another thread beat us to it */ RpcBindingFree(&new_handle); } return irot_handle; }
static RPC_STATUS ndr_update_context_handle(NDR_CCONTEXT *CContext, RPC_BINDING_HANDLE hBinding, const ndr_context_handle *chi) { struct context_handle_entry *che = NULL; /* a null UUID means we should free the context handle */ if (IsEqualGUID(&chi->uuid, &GUID_NULL)) { if (*CContext) { che = get_context_entry(*CContext); if (!che) return RPC_X_SS_CONTEXT_MISMATCH; list_remove(&che->entry); RpcBindingFree(&che->handle); HeapFree(GetProcessHeap(), 0, che); che = NULL; } } /* if there's no existing entry matching the GUID, allocate one */ else if (!(che = context_entry_from_guid(&chi->uuid))) { che = HeapAlloc(GetProcessHeap(), 0, sizeof *che); if (!che) return RPC_X_NO_MEMORY; che->magic = NDR_CONTEXT_HANDLE_MAGIC; RpcBindingCopy(hBinding, &che->handle); list_add_tail(&context_handle_list, &che->entry); che->wire_data = *chi; } *CContext = che; return RPC_S_OK; }
// this unbinds to the interface after the RPC call void __stdcall UnBind() { RpcStringFree(&StringBinding); StringBinding = NULL; RpcBindingFree(&winamp_IfHandle); }
static void test_rpc_ncacn_ip_tcp(void) { RPC_STATUS status; unsigned char *binding, *principal; handle_t IFoo_IfHandle; ULONG level, authnsvc, authzsvc; RPC_AUTH_IDENTITY_HANDLE identity; static unsigned char foo[] = "foo"; static unsigned char ncacn_ip_tcp[] = "ncacn_ip_tcp"; static unsigned char address[] = "127.0.0.1"; static unsigned char endpoint[] = "4114"; static unsigned char spn[] = "principal"; status = RpcNetworkIsProtseqValidA(foo); ok(status == RPC_S_INVALID_RPC_PROTSEQ, "return wrong\n"); status = RpcNetworkIsProtseqValidA(ncacn_ip_tcp); ok(status == RPC_S_OK, "return wrong\n"); status = RpcMgmtStopServerListening(NULL); todo_wine { ok(status == RPC_S_NOT_LISTENING, "wrong RpcMgmtStopServerListening error (%u)\n", status); } status = RpcMgmtWaitServerListen(); ok(status == RPC_S_NOT_LISTENING, "wrong RpcMgmtWaitServerListen error status (%u)\n", status); status = RpcServerListen(1, 20, FALSE); ok(status == RPC_S_NO_PROTSEQS_REGISTERED, "wrong RpcServerListen error (%u)\n", status); status = RpcServerUseProtseqEpA(ncacn_ip_tcp, 20, endpoint, NULL); ok(status == RPC_S_OK, "RpcServerUseProtseqEp failed (%u)\n", status); status = RpcServerRegisterIf(IFoo_v0_0_s_ifspec, NULL, NULL); ok(status == RPC_S_OK, "RpcServerRegisterIf failed (%u)\n", status); status = RpcServerListen(1, 20, TRUE); todo_wine { ok(status == RPC_S_OK, "RpcServerListen failed (%u)\n", status); } status = RpcServerListen(1, 20, TRUE); todo_wine { ok(status == RPC_S_ALREADY_LISTENING, "wrong RpcServerListen error (%u)\n", status); } status = RpcStringBindingComposeA(NULL, ncacn_ip_tcp, address, endpoint, NULL, &binding); ok(status == RPC_S_OK, "RpcStringBindingCompose failed (%u)\n", status); status = RpcBindingFromStringBindingA(binding, &IFoo_IfHandle); ok(status == RPC_S_OK, "RpcBindingFromStringBinding failed (%u)\n", status); status = RpcBindingSetAuthInfoA(IFoo_IfHandle, NULL, RPC_C_AUTHN_LEVEL_NONE, RPC_C_AUTHN_WINNT, NULL, RPC_C_AUTHZ_NAME); ok(status == RPC_S_OK, "RpcBindingSetAuthInfo failed (%u)\n", status); status = RpcBindingInqAuthInfoA(IFoo_IfHandle, NULL, NULL, NULL, NULL, NULL); ok(status == RPC_S_BINDING_HAS_NO_AUTH, "RpcBindingInqAuthInfo failed (%u)\n", status); status = RpcBindingSetAuthInfoA(IFoo_IfHandle, spn, RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_AUTHN_WINNT, NULL, RPC_C_AUTHZ_NAME); ok(status == RPC_S_OK, "RpcBindingSetAuthInfo failed (%u)\n", status); level = authnsvc = authzsvc = 0; principal = (unsigned char *)0xdeadbeef; identity = (RPC_AUTH_IDENTITY_HANDLE *)0xdeadbeef; status = RpcBindingInqAuthInfoA(IFoo_IfHandle, &principal, &level, &authnsvc, &identity, &authzsvc); ok(status == RPC_S_OK, "RpcBindingInqAuthInfo failed (%u)\n", status); ok(identity == NULL, "expected NULL identity, got %p\n", identity); ok(principal != (unsigned char *)0xdeadbeef, "expected valid principal, got %p\n", principal); ok(level == RPC_C_AUTHN_LEVEL_PKT_PRIVACY, "expected RPC_C_AUTHN_LEVEL_PKT_PRIVACY, got %d\n", level); ok(authnsvc == RPC_C_AUTHN_WINNT, "expected RPC_C_AUTHN_WINNT, got %d\n", authnsvc); todo_wine ok(authzsvc == RPC_C_AUTHZ_NAME, "expected RPC_C_AUTHZ_NAME, got %d\n", authzsvc); if (status == RPC_S_OK) RpcStringFreeA(&principal); status = RpcMgmtStopServerListening(NULL); ok(status == RPC_S_OK, "RpcMgmtStopServerListening failed (%u)\n", status); status = RpcMgmtStopServerListening(NULL); ok(status == RPC_S_OK, "RpcMgmtStopServerListening failed (%u)\n", status); status = RpcServerUnregisterIf(NULL, NULL, FALSE); ok(status == RPC_S_OK, "RpcServerUnregisterIf failed (%u)\n", status); status = RpcMgmtWaitServerListen(); todo_wine { ok(status == RPC_S_OK, "RpcMgmtWaitServerListen failed (%u)\n", status); } status = RpcStringFreeA(&binding); ok(status == RPC_S_OK, "RpcStringFree failed (%u)\n", status); status = RpcBindingFree(&IFoo_IfHandle); ok(status == RPC_S_OK, "RpcBindingFree failed (%u)\n", status); }
DWORD WINAPI CreateJob(PLOCAL_PRINTER_HANDLE pPrinterHandle) { const WCHAR wszDoubleBackslash[] = L"\\"; const DWORD cchDoubleBackslash = _countof(wszDoubleBackslash) - 1; DWORD cchMachineName; DWORD cchUserName; DWORD dwErrorCode; PLOCAL_JOB pJob; RPC_BINDING_HANDLE hServerBinding = NULL; RPC_WSTR pwszBinding = NULL; RPC_WSTR pwszMachineName = NULL; // Create a new job. pJob = DllAllocSplMem(sizeof(LOCAL_JOB)); if (!pJob) { dwErrorCode = ERROR_NOT_ENOUGH_MEMORY; ERR("DllAllocSplMem failed with error %lu!\n", GetLastError()); goto Cleanup; } // Reserve an ID for this job. if (!_GetNextJobID(&pJob->dwJobID)) { dwErrorCode = ERROR_NOT_ENOUGH_MEMORY; goto Cleanup; } // Copy over defaults to the LOCAL_JOB structure. pJob->pPrinter = pPrinterHandle->pPrinter; pJob->pPrintProcessor = pPrinterHandle->pPrinter->pPrintProcessor; pJob->dwPriority = DEF_PRIORITY; pJob->dwStatus = JOB_STATUS_SPOOLING; pJob->pwszDatatype = AllocSplStr(pPrinterHandle->pwszDatatype); pJob->pwszDocumentName = AllocSplStr(wszDefaultDocumentName); pJob->pDevMode = DuplicateDevMode(pPrinterHandle->pDevMode); GetSystemTime(&pJob->stSubmitted); // Get the user name for the Job. cchUserName = UNLEN + 1; pJob->pwszUserName = DllAllocSplMem(cchUserName * sizeof(WCHAR)); if (!GetUserNameW(pJob->pwszUserName, &cchUserName)) { dwErrorCode = GetLastError(); ERR("GetUserNameW failed with error %lu!\n", dwErrorCode); goto Cleanup; } // FIXME: For now, pwszNotifyName equals pwszUserName. pJob->pwszNotifyName = AllocSplStr(pJob->pwszUserName); // Get the name of the machine that submitted the Job over RPC. dwErrorCode = RpcBindingServerFromClient(NULL, &hServerBinding); if (dwErrorCode != RPC_S_OK) { ERR("RpcBindingServerFromClient failed with status %lu!\n", dwErrorCode); goto Cleanup; } dwErrorCode = RpcBindingToStringBindingW(hServerBinding, &pwszBinding); if (dwErrorCode != RPC_S_OK) { ERR("RpcBindingToStringBindingW failed with status %lu!\n", dwErrorCode); goto Cleanup; } dwErrorCode = RpcStringBindingParseW(pwszBinding, NULL, NULL, &pwszMachineName, NULL, NULL); if (dwErrorCode != RPC_S_OK) { ERR("RpcStringBindingParseW failed with status %lu!\n", dwErrorCode); goto Cleanup; } cchMachineName = wcslen(pwszMachineName); pJob->pwszMachineName = DllAllocSplMem((cchMachineName + cchDoubleBackslash + 1) * sizeof(WCHAR)); CopyMemory(pJob->pwszMachineName, wszDoubleBackslash, cchDoubleBackslash * sizeof(WCHAR)); CopyMemory(&pJob->pwszMachineName[cchDoubleBackslash], pwszMachineName, (cchMachineName + 1) * sizeof(WCHAR)); // Add the job to the Global Job List. if (!InsertElementSkiplist(&GlobalJobList, pJob)) { dwErrorCode = ERROR_NOT_ENOUGH_MEMORY; ERR("InsertElementSkiplist failed for job %lu for the GlobalJobList!\n", pJob->dwJobID); goto Cleanup; } // Add the job at the end of the Printer's Job List. // As all new jobs are created with default priority, we can be sure that it would always be inserted at the end. if (!InsertTailElementSkiplist(&pJob->pPrinter->JobList, pJob)) { dwErrorCode = ERROR_NOT_ENOUGH_MEMORY; ERR("InsertTailElementSkiplist failed for job %lu for the Printer's Job List!\n", pJob->dwJobID); goto Cleanup; } // We were successful! pPrinterHandle->bStartedDoc = TRUE; pPrinterHandle->pJob = pJob; dwErrorCode = ERROR_SUCCESS; // Don't let the cleanup routine free this. pJob = NULL; Cleanup: if (pJob) DllFreeSplMem(pJob); if (pwszMachineName) RpcStringFreeW(&pwszMachineName); if (pwszBinding) RpcStringFreeW(&pwszBinding); if (hServerBinding) RpcBindingFree(&hServerBinding); return dwErrorCode; }
// // FUNCTION: main // // PURPOSE: Parses arguments and binds to the server. // // PARAMETERS: // argc - number of command line arguments // argv - array of command line arguments // // RETURN VALUE: // Program exit code. // // int main(int argc, char *argv[]) { char *serverAddress = NULL; char *protocol = "ncalrpc"; UINT iIterations = 100; unsigned char *stringBinding; RPC_BINDING_HANDLE Binding; RPC_STATUS status; ULONG SecurityLevel = RPC_C_AUTHN_LEVEL_PKT_PRIVACY; argc--; argv++; while(argc) { if ( argv[0][0] != '-' && argv[0][0] != '/') { Usage(); return(1); } switch(argv[0][1]) { case 'n': if (argc < 2) { Usage(); return(1); } serverAddress = argv[1]; argc--; argv++; break; case 't': if (argc < 2) { Usage(); return(1); } protocol = argv[1]; argc--; argv++; break; case 'i': if (argc < 2) { Usage(); return(1); } iIterations = atoi(argv[1]); argc--; argv++; break; case 's': if (argc < 2) { Usage(); return(1); } SecurityLevel = atoi(argv[1]); if (SecurityLevel > RPC_C_AUTHN_LEVEL_PKT_PRIVACY) { Usage(); return(1); } argc--; argv++; break; default: Usage(); return(1); break; } argc--; argv++; } status = RpcStringBindingCompose(0, protocol, serverAddress, 0, 0, &stringBinding); if (status != RPC_S_OK) { printf("RpcStringBindingCompose failed - %d\n", status); return(1); } status = RpcBindingFromStringBinding(stringBinding, &Binding); if (status != RPC_S_OK) { printf("RpcBindingFromStringBinding failed - %d\n", status); return(1); } status = RpcBindingSetAuthInfo(Binding, 0, SecurityLevel, RPC_C_AUTHN_WINNT, 0, 0 ); if (status != RPC_S_OK) { printf("RpcBindingSetAuthInfo failed - %d\n", status); return(1); } status = Ping(Binding); if (status != RPC_S_OK) { printf("Ping failed - %d\n", status); } printf("Connected.\n"); // // Call and time various RPC calls. // DoTimings(Binding, iIterations); // Cleanup status = RpcBindingFree(&Binding); // ASSERT(status == RPC_S_OK): status = RpcStringFree(&stringBinding); // ASSERT(status == RPC_S_OK); return(0); }
static void client(const char *test) { static unsigned char iptcp[] = "ncacn_ip_tcp"; static unsigned char np[] = "ncacn_np"; static unsigned char ncalrpc[] = "ncalrpc"; static unsigned char address[] = "127.0.0.1"; static unsigned char address_np[] = "\\\\."; static unsigned char port[] = PORT; static unsigned char pipe[] = PIPE; static unsigned char guid[] = "00000000-4114-0704-2301-000000000000"; unsigned char *binding; if (strcmp(test, "tcp_basic") == 0) { ok(RPC_S_OK == RpcStringBindingCompose(NULL, iptcp, address, port, NULL, &binding), "RpcStringBindingCompose\n"); ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n"); run_tests(); authinfo_test(RPC_PROTSEQ_TCP, 0); ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n"); ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n"); } else if (strcmp(test, "tcp_secure") == 0) { ok(RPC_S_OK == RpcStringBindingCompose(NULL, iptcp, address, port, NULL, &binding), "RpcStringBindingCompose\n"); ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n"); set_auth_info(IServer_IfHandle); authinfo_test(RPC_PROTSEQ_TCP, 1); ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n"); ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n"); } else if (strcmp(test, "ncalrpc_basic") == 0) { ok(RPC_S_OK == RpcStringBindingCompose(NULL, ncalrpc, NULL, guid, NULL, &binding), "RpcStringBindingCompose\n"); ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n"); run_tests(); /* can cause RPC_X_BAD_STUB_DATA exception */ authinfo_test(RPC_PROTSEQ_LRPC, 0); ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n"); ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n"); } else if (strcmp(test, "ncalrpc_secure") == 0) { ok(RPC_S_OK == RpcStringBindingCompose(NULL, ncalrpc, NULL, guid, NULL, &binding), "RpcStringBindingCompose\n"); ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n"); set_auth_info(IServer_IfHandle); authinfo_test(RPC_PROTSEQ_LRPC, 1); ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n"); ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n"); } else if (strcmp(test, "np_basic") == 0) { ok(RPC_S_OK == RpcStringBindingCompose(NULL, np, address_np, pipe, NULL, &binding), "RpcStringBindingCompose\n"); ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n"); run_tests(); authinfo_test(RPC_PROTSEQ_NMP, 0); stop(); ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n"); ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n"); } }
/*********************************************************************** * RpcEpRegisterA (RPCRT4.@) */ RPC_STATUS WINAPI RpcEpRegisterA( RPC_IF_HANDLE IfSpec, RPC_BINDING_VECTOR *BindingVector, UUID_VECTOR *UuidVector, RPC_CSTR Annotation ) { PRPC_SERVER_INTERFACE If = IfSpec; ULONG i; RPC_STATUS status = RPC_S_OK; error_status_t status2; ept_entry_t *entries; handle_t handle; TRACE("(%p,%p,%p,%s)\n", IfSpec, BindingVector, UuidVector, debugstr_a((char*)Annotation)); TRACE(" ifid=%s\n", debugstr_guid(&If->InterfaceId.SyntaxGUID)); for (i=0; i<BindingVector->Count; i++) { RpcBinding* bind = BindingVector->BindingH[i]; TRACE(" protseq[%d]=%s\n", i, debugstr_a(bind->Protseq)); TRACE(" endpoint[%d]=%s\n", i, debugstr_a(bind->Endpoint)); } if (UuidVector) { for (i=0; i<UuidVector->Count; i++) TRACE(" obj[%d]=%s\n", i, debugstr_guid(UuidVector->Uuid[i])); } if (!BindingVector->Count) return RPC_S_OK; entries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*entries) * BindingVector->Count * (UuidVector ? UuidVector->Count : 1)); if (!entries) return RPC_S_OUT_OF_MEMORY; status = get_epm_handle_server(&handle); if (status != RPC_S_OK) { HeapFree(GetProcessHeap(), 0, entries); return status; } for (i = 0; i < BindingVector->Count; i++) { unsigned j; RpcBinding* bind = BindingVector->BindingH[i]; for (j = 0; j < (UuidVector ? UuidVector->Count : 1); j++) { status = TowerConstruct(&If->InterfaceId, &If->TransferSyntax, bind->Protseq, bind->Endpoint, bind->NetworkAddr, &entries[i*(UuidVector ? UuidVector->Count : 1) + j].tower); if (status != RPC_S_OK) break; if (UuidVector) memcpy(&entries[i * UuidVector->Count].object, &UuidVector->Uuid[j], sizeof(GUID)); else memset(&entries[i].object, 0, sizeof(entries[i].object)); if (Annotation) memcpy(entries[i].annotation, Annotation, min(strlen((char *)Annotation) + 1, ept_max_annotation_size)); } } if (status == RPC_S_OK) { while (TRUE) { __TRY { ept_insert(handle, BindingVector->Count * (UuidVector ? UuidVector->Count : 1), entries, TRUE, &status2); } __EXCEPT(rpc_filter) { status2 = GetExceptionCode(); } __ENDTRY if (status2 == RPC_S_SERVER_UNAVAILABLE && is_epm_destination_local(handle)) { if (start_rpcss()) continue; } if (status2 != RPC_S_OK) ERR("ept_insert failed with error %d\n", status2); status = status2; /* FIXME: convert status? */ break; } } RpcBindingFree(&handle); for (i = 0; i < BindingVector->Count; i++) { unsigned j; for (j = 0; j < (UuidVector ? UuidVector->Count : 1); j++) I_RpcFree(entries[i*(UuidVector ? UuidVector->Count : 1) + j].tower); } HeapFree(GetProcessHeap(), 0, entries); return status; }
// This routine creates a binding with the server. HRESULT JITManager::CreateBinding( __in HANDLE serverProcessHandle, __in_opt void * serverSecurityDescriptor, __in UUID * connectionUuid, __out RPC_BINDING_HANDLE * bindingHandle) { Assert(IsOOPJITEnabled()); RPC_STATUS status; DWORD attemptCount = 0; DWORD sleepInterval = 100; // in milliseconds RPC_BINDING_HANDLE localBindingHandle; RPC_BINDING_HANDLE_TEMPLATE_V1 bindingTemplate; RPC_BINDING_HANDLE_SECURITY_V1_W bindingSecurity; #ifndef NTBUILD RPC_SECURITY_QOS_V4 securityQOS; ZeroMemory(&securityQOS, sizeof(RPC_SECURITY_QOS_V4)); securityQOS.Capabilities = RPC_C_QOS_CAPABILITIES_DEFAULT; securityQOS.IdentityTracking = RPC_C_QOS_IDENTITY_DYNAMIC; securityQOS.ImpersonationType = RPC_C_IMP_LEVEL_IDENTIFY; securityQOS.Version = 4; #else RPC_SECURITY_QOS_V5 securityQOS; ZeroMemory(&securityQOS, sizeof(RPC_SECURITY_QOS_V5)); securityQOS.Capabilities = RPC_C_QOS_CAPABILITIES_DEFAULT; securityQOS.IdentityTracking = RPC_C_QOS_IDENTITY_DYNAMIC; securityQOS.ImpersonationType = RPC_C_IMP_LEVEL_IDENTIFY; securityQOS.Version = 5; securityQOS.ServerSecurityDescriptor = serverSecurityDescriptor; #endif // NTBUILD ZeroMemory(&bindingTemplate, sizeof(bindingTemplate)); bindingTemplate.Version = 1; bindingTemplate.ProtocolSequence = RPC_PROTSEQ_LRPC; bindingTemplate.StringEndpoint = NULL; memcpy_s(&bindingTemplate.ObjectUuid, sizeof(UUID), connectionUuid, sizeof(UUID)); bindingTemplate.Flags |= RPC_BHT_OBJECT_UUID_VALID; ZeroMemory(&bindingSecurity, sizeof(bindingSecurity)); bindingSecurity.Version = 1; bindingSecurity.AuthnLevel = RPC_C_AUTHN_LEVEL_PKT_PRIVACY; bindingSecurity.AuthnSvc = RPC_C_AUTHN_KERNEL; bindingSecurity.SecurityQos = (RPC_SECURITY_QOS*)&securityQOS; status = RpcBindingCreate(&bindingTemplate, &bindingSecurity, NULL, &localBindingHandle); if (status != RPC_S_OK) { return HRESULT_FROM_WIN32(status); } // We keep attempting to connect to the server with increasing wait intervals in between. // This will wait close to 5 minutes before it finally gives up. do { DWORD waitStatus; status = RpcBindingBind(NULL, localBindingHandle, ClientIChakraJIT_v0_0_c_ifspec); if (status == RPC_S_OK) { break; } else if (status == EPT_S_NOT_REGISTERED) { // The Server side has not finished registering the RPC Server yet. // We should only breakout if we have reached the max attempt count. if (attemptCount > 600) { break; } } else { // Some unknown error occurred. We are not going to retry for arbitrary errors. break; } // When we come to this point, it means the server has not finished registration yet. // We should wait for a while and then reattempt to bind. waitStatus = WaitForSingleObject(serverProcessHandle, sleepInterval); if (waitStatus == WAIT_OBJECT_0) { DWORD exitCode = (DWORD)-1; // The server process died for some reason. No need to reattempt. // We use -1 as the exit code if GetExitCodeProcess fails. Assert(GetExitCodeProcess(serverProcessHandle, &exitCode)); status = RPC_S_SERVER_UNAVAILABLE; break; } else if (waitStatus == WAIT_TIMEOUT) { // Not an error. the server is still alive and we should reattempt. } else { // wait operation failed for an unknown reason. Assert(false); status = HRESULT_FROM_WIN32(waitStatus); break; } attemptCount++; if (sleepInterval < 500) { sleepInterval += 100; } } while (status != RPC_S_OK); // redundant check, but compiler would not allow true here. if (status != RPC_S_OK) { RpcBindingFree(&localBindingHandle); return HRESULT_FROM_WIN32(status); } *bindingHandle = localBindingHandle; return S_OK; }