예제 #1
0
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;
}
예제 #2
0
//
//  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;
}