RPC_STATUS rpcSrv_initialize() { nvdaUnregisteredEvent=CreateEvent(NULL,TRUE,true,NULL); RPC_STATUS status; //Set the protocol status=RpcServerUseProtseq((RPC_WSTR)L"ncalrpc",RPC_C_PROTSEQ_MAX_REQS_DEFAULT,NULL); //We can ignore the error where the endpoint is already set if(status!=RPC_S_OK&&status!=RPC_S_DUPLICATE_ENDPOINT) { LOG_ERROR(L"Unable to use RPC endPoint. RPC error "<<status); return status; } if((status=RpcServerInqBindings(&bindingVector))!=RPC_S_OK) { LOG_ERROR(L"RpcServerInqBindings failed with status "<<status); return status; } UuidCreate(&nvdaInprocUuid); UUID_VECTOR nvdaInprocUuidVector={1,&nvdaInprocUuid}; //Register the interfaces for(int i=0;i<ARRAYSIZE(availableInterfaces);++i) { if((status=RpcServerRegisterIfEx(availableInterfaces[i],NULL,NULL,RPC_IF_AUTOLISTEN,RPC_C_LISTEN_MAX_CALLS_DEFAULT,NULL))!=RPC_S_OK) { LOG_ERROR(L"RpcServerRegisterIfEx for interface at index "<<i<<L" failed with status "<<status); continue; } if((status=RpcEpRegister(availableInterfaces[i],bindingVector,&nvdaInprocUuidVector,(RPC_WSTR)L"NVDAHelperRemote interface"))!=RPC_S_OK) { LOG_ERROR(L"RpcEpRegister failed for interface at index "<<i<<L" with status "<<status); continue; } } RPC_WSTR uuidString; UuidToString(&nvdaInprocUuid,&uuidString); RpcBindingSetObject(nvdaControllerInternalBindingHandle,&nvdaInprocUuid); if((status=nvdaControllerInternal_requestRegistration((wchar_t*)uuidString))!=RPC_S_OK) { LOG_ERROR(L"nvdaControllerInternal_requestRegistration failed with status "<<status); } RpcStringFree(&uuidString); return status; }
HRESULT JsInitializeJITServer( __in UUID* connectionUuid, __in_opt void* securityDescriptor, __in_opt void* alpcSecurityDescriptor) { RPC_STATUS status; RPC_BINDING_VECTOR* bindingVector = NULL; UUID_VECTOR uuidVector; uuidVector.Count = 1; uuidVector.Uuid[0] = connectionUuid; status = RpcServerUseProtseqW( (RPC_WSTR)L"ncalrpc", RPC_C_PROTSEQ_MAX_REQS_DEFAULT, alpcSecurityDescriptor); if (status != RPC_S_OK) { return status; } #ifndef NTBUILD status = RpcServerRegisterIf2( ServerIChakraJIT_v0_0_s_ifspec, NULL, NULL, RPC_IF_AUTOLISTEN, RPC_C_LISTEN_MAX_CALLS_DEFAULT, (ULONG)-1, NULL); #else status = RpcServerRegisterIf3( ServerIChakraJIT_v0_0_s_ifspec, NULL, NULL, RPC_IF_AUTOLISTEN, RPC_C_LISTEN_MAX_CALLS_DEFAULT, (ULONG)-1, NULL, securityDescriptor); #endif if (status != RPC_S_OK) { return status; } status = RpcServerInqBindings(&bindingVector); if (status != RPC_S_OK) { return status; } status = RpcEpRegister( ServerIChakraJIT_v0_0_s_ifspec, bindingVector, &uuidVector, NULL); RpcBindingVectorFree(&bindingVector); if (status != RPC_S_OK) { return status; } JITManager::GetJITManager()->SetIsJITServer(); status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, FALSE); return status; }
// // FUNCTION: ServiceStart // // PURPOSE: Actual code of the service // that does the work. // // PARAMETERS: // dwArgc - number of command line arguments // lpszArgv - array of command line arguments // // RETURN VALUE: // none // // COMMENTS: // Starts the service listening for RPC requests. // VOID ServiceStart (HWND NotifyWindow) { UINT i; RPC_BINDING_VECTOR *pbindingVector = 0; RPC_STATUS status; BOOL fListening = FALSE; /////////////////////////////////////////////////// // // Service initialization // // // Use protocol sequences (protseqs) specified in ProtocolArray. // if(NotifyWindow) PostMessage(NotifyWindow,MPM_SERVER_STARTING,0,0); for(i = 0; i < sizeof(ProtocolArray)/sizeof(TCHAR *); i++) { status = RpcServerUseProtseq(ProtocolArray[i], ProtocolBuffer, 0); if (status == RPC_S_OK) { if(NotifyWindow) PostMessage(NotifyWindow,MPM_SERVER_PENDING,0,0); fListening = TRUE; } } if (!fListening) { // Unable to listen to any protocol! // if(NotifyWindow) PostMessage(NotifyWindow,MPM_SERVER_STOPPED,0,status); dwErr = status; return; } // // Register the services interface(s). // status = RpcServerRegisterIf(R_MPE_v1_0_s_ifspec,0,0); if (status != RPC_S_OK) { if(NotifyWindow) PostMessage(NotifyWindow,MPM_SERVER_STOPPED,0,status); dwErr = status; hMainThread = 0; return; } if(NotifyWindow) PostMessage(NotifyWindow,MPM_SERVER_PENDING,0,0); // Register interface(s) and binding(s) (endpoints) with // the endpoint mapper. // status = RpcServerInqBindings(&pbindingVector); if (status != RPC_S_OK) { if(NotifyWindow) PostMessage(NotifyWindow,MPM_SERVER_STOPPED,0,status); dwErr = status; hMainThread = 0; return; } if(NotifyWindow) PostMessage(NotifyWindow,MPM_SERVER_PENDING,0,0); status = RpcEpRegister(R_MPE_v1_0_s_ifspec,pbindingVector,0,0); if (status != RPC_S_OK) { dwErr = status; if(NotifyWindow) PostMessage(NotifyWindow,MPM_SERVER_STOPPED,0,status); hMainThread = 0; return; } if(NotifyWindow) PostMessage(NotifyWindow,MPM_SERVER_PENDING,0,0); // Enable NT LM Security Support Provider (NtLmSsp service) // status = RpcServerRegisterAuthInfo(0, RPC_C_AUTHN_WINNT, 0, 0 ); if (status != RPC_S_OK){ dwErr = status; if(NotifyWindow) PostMessage(NotifyWindow,MPM_SERVER_STOPPED,0,status); hMainThread = 0; return; } if(NotifyWindow) PostMessage(NotifyWindow,MPM_SERVER_PENDING,0,0); // Start accepting client calls. // status = RpcServerListen(MinimumThreads, RPC_C_LISTEN_MAX_CALLS_DEFAULT, // rpcdce.h TRUE); // don't block. if (status != RPC_S_OK) { dwErr = status; PostMessage(NotifyWindow,MPM_SERVER_STOPPED,0,status); hMainThread = 0; return; } // // End of initialization // //////////////////////////////////////////////////////////// if(NotifyWindow) PostMessage(NotifyWindow,MPM_SERVER_STARTED,0,status); else SetEvent(StartEvent); //////////////////////////////////////////////////////////// // // Cleanup // // RpcMgmtWaitServerListen() will block until the server has // stopped listening. If this service had something better to // do with this thread, it would delay this call until // ServiceStop() had been called. (Set an event in ServiceStop()). // status = RpcMgmtWaitServerListen(); if (status != RPC_S_OK) { dwErr = status; PostMessage(NotifyWindow,MPM_SERVER_STOPPED,0,status); hMainThread = 0; return; } NotifyWindow = g_hNotifyWindow; if(NotifyWindow) PostMessage(NotifyWindow,MPM_SERVER_PENDING,0,0); // ASSERT(status == RPC_S_OK) status = RpcServerUnregisterIf(R_MPE_v1_0_s_ifspec,0,TRUE); if(NotifyWindow) PostMessage(NotifyWindow,MPM_SERVER_PENDING,0,0); // Remove entries from the endpoint mapper database. // RpcEpUnregister(R_MPE_v1_0_s_ifspec, // from rpcsvc.h pbindingVector, 0); if(NotifyWindow) PostMessage(NotifyWindow,MPM_SERVER_PENDING,0,0); // Delete the binding vector // status = RpcBindingVectorFree(&pbindingVector); if(NotifyWindow) PostMessage(NotifyWindow,MPM_SERVER_STOPPED,0,status); // //////////////////////////////////////////////////////////// return; }
void RpcListen() { RPC_STATUS status; char *task; RPC_BINDING_VECTOR *ptrBindingVector = NULL; BOOLEAN ifaceRegistered = FALSE; BOOLEAN epRegistered = FALSE; #ifdef NOOSIDEBUGSERVER /* Use All Protseqs already done in OSI */ status = RpcServerUseAllProtseqs(1, NULL); if (status != RPC_S_OK) { task = "Use All Protocol Sequences"; goto cleanup; } #endif /* NOOSIDEBUGSERVER */ status = RpcServerRegisterIf(afsrpc_v1_0_s_ifspec, NULL, NULL); if (status != RPC_S_OK) { task = "Register Interface"; goto cleanup; } ifaceRegistered = TRUE; status = RpcServerInqBindings(&ptrBindingVector); if (status != RPC_S_OK) { task = "Inquire Bindings"; goto cleanup; } status = RpcServerRegisterAuthInfo(NULL, RPC_C_AUTHN_WINNT, NULL, NULL); if (status != RPC_S_OK) { task = "Register Authentication Info"; goto cleanup; } status = RpcEpRegister(afsrpc_v1_0_s_ifspec, ptrBindingVector, NULL, "AFS session key interface"); if (status != RPC_S_OK) { task = "Register Endpoints"; goto cleanup; } epRegistered = TRUE; afsi_log("RPC server listening"); status = RpcServerListen(OSI_MAXRPCCALLS, OSI_MAXRPCCALLS, 0); if (status != RPC_S_OK) { task = "Server Listen"; } cleanup: if (epRegistered) (void) RpcEpUnregister(afsrpc_v1_0_s_ifspec, ptrBindingVector, NULL); if (ptrBindingVector) (void) RpcBindingVectorFree(&ptrBindingVector); if (ifaceRegistered) (void) RpcServerUnregisterIf(afsrpc_v1_0_s_ifspec, NULL, FALSE); if (status != RPC_S_OK) afsi_log("RPC problem, code %d for %s", status, task); else afsi_log("RPC shutdown"); if (rpc_ShutdownEvent != NULL) thrd_SetEvent(rpc_ShutdownEvent); return; }