void rpcSrv_inProcess_initialize() { RPC_STATUS status; //Set the protocol std::wostringstream endPoint; endPoint<<L"nvdaHelperRemote_"<<GetCurrentProcessId(); status=RpcServerUseProtseqEp((RPC_WSTR)L"ncalrpc",RPC_C_PROTSEQ_MAX_REQS_DEFAULT,(RPC_WSTR)(endPoint.str().c_str()),NULL); if(status!=RPC_S_OK&&status!=RPC_S_DUPLICATE_ENDPOINT) { LOG_ERROR(L"RpcServerUseProtseqEp failed with status "<<status); } //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); } } }
ULONG VmDirRpcServerRegisterIf( VMDIR_IF_HANDLE_T pInterfaceSpec ) { DWORD dwError = 0; dwError = RpcServerRegisterIfEx( pInterfaceSpec, NULL, NULL, RPC_IF_ALLOW_SECURE_ONLY, RPC_C_LISTEN_MAX_CALLS_DEFAULT, VmDirRpcIfCallbackFn ); BAIL_ON_VMDIR_ERROR(dwError); error: return dwError; }
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; }
/* main: register the interface, start listening for clients */ void __cdecl main(int argc, char * argv[]) { RPC_STATUS status; unsigned char * pszProtocolSequence = "ncacn_ip_tcp"; unsigned char * pszSecurity = NULL; unsigned char * pszEndpoint = "8765"; unsigned char * pszSpn = NULL; unsigned int cMinCalls = 1; unsigned int cMaxCalls = 20; unsigned int fDontWait = FALSE; int i; /* allow the user to override settings with command line switches */ for (i = 1; i < argc; i++) { if ((*argv[i] == '-') || (*argv[i] == '/')) { switch (tolower(*(argv[i]+1))) { case 'p': // protocol sequence pszProtocolSequence = argv[++i]; break; case 'e': pszEndpoint = argv[++i]; break; case 'a': pszSpn = argv[++i]; break; case 'm': cMaxCalls = (unsigned int) atoi(argv[++i]); break; case 'n': cMinCalls = (unsigned int) atoi(argv[++i]); break; case 'f': fDontWait = (unsigned int) atoi(argv[++i]); break; /* case 'i': if(!_stricmp(argv[++i],"No_Authenticate")) ifFlag = RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH; break;*/ case 'h': case '?': default: Usage(argv[0]); } } else Usage(argv[0]); } status = RpcServerUseProtseqEp(pszProtocolSequence, cMaxCalls, pszEndpoint, pszSecurity); // Security descriptor printf_s("RpcServerUseProtseqEp returned 0x%x\n", status); if (status) { exit(status); } /* User did not specify spn, construct one. */ if (pszSpn == NULL) { MakeSpn(&pszSpn); } /* Using Negotiate as security provider */ status = RpcServerRegisterAuthInfo(pszSpn, RPC_C_AUTHN_GSS_NEGOTIATE, NULL, NULL); printf_s("RpcServerRegisterAuthInfo returned 0x%x\n", status); if (status) { exit(status); } status = RpcServerRegisterIfEx(umarsh_ServerIfHandle, NULL, NULL, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL ); printf_s("Calling RpcServerListen\n"); status = RpcServerListen(cMinCalls, cMaxCalls, fDontWait); printf_s("RpcServerListen returned: 0x%x\n", status); if (status) { exit(status); } if (fDontWait) { printf_s("Calling RpcMgmtWaitServerListen\n"); status = RpcMgmtWaitServerListen(); // wait operation printf_s("RpcMgmtWaitServerListen returned: 0x%x\n", status); if (status) { exit(status); } } } // end main()
__declspec(dllexport) long RegisterRpc( LPWSTR pszProtocolSequence , LPWSTR pszEndpoint , LPWSTR pszServiceClass , LPWSTR pszNetworkAddress , LPWSTR psErrorMessageBuffer , int errorMessageBufferLength ) { LPWSTR pszSpn = NULL; long lStatus; // The RpcServerUseProtseqEp function tells the RPC run-time library to // use the specified protocol sequence combined with the specified // endpoint for receiving remote procedure calls. // lStatus = RpcServerUseProtseqEp( ( RPC_WSTR ) pszProtocolSequence, RPC_C_PROTSEQ_MAX_REQS_DEFAULT, ( RPC_WSTR ) pszEndpoint, NULL ); if ( lStatus ) { swprintf_s(psErrorMessageBuffer, errorMessageBufferLength, L"RpcServerUseProtseqEp returned 0x%x", lStatus ); return KEYPROVIDER_FAILED; } // User did not specify spn, construct one. if ( NULL == pszSpn ) { // Add 2 for the slash character and null terminator. INT nSpnLength = wcslen( pszServiceClass ) + wcslen( pszNetworkAddress ) + 2; pszSpn = ( LPWSTR ) malloc( nSpnLength * sizeof( wchar_t ) ); if ( !pszSpn ) { return KEYPROVIDER_NOT_ENOUGH_MEMORY; } wcscpy_s( pszSpn, nSpnLength, pszServiceClass ); wcscat_s( pszSpn, nSpnLength, L"/" ); wcscat_s( pszSpn, nSpnLength, pszNetworkAddress ); } // The RpcServerRegisterIfEx function registers an interface with // the RPC run-time library. // lStatus = RpcServerRegisterIfEx( KeyProviderListener_v1_0_s_ifspec, NULL, NULL, RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH, RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL ); if ( lStatus ) { swprintf_s(psErrorMessageBuffer, errorMessageBufferLength, L"RpcServerRegisterIfEx returned 0x%x", lStatus ); return KEYPROVIDER_FAILED; } // The RpcServerRegisterAuthInfo function registers authentication // information with the RPC run-time library. // // Using Negotiate as security provider. lStatus = RpcServerRegisterAuthInfo( ( RPC_WSTR ) pszSpn, RPC_C_AUTHN_GSS_NEGOTIATE, NULL, NULL ); if ( lStatus ) { swprintf_s(psErrorMessageBuffer, errorMessageBufferLength, L"RpcServerRegisterAuthInfo returned 0x%x", lStatus ); return KEYPROVIDER_FAILED; } // The RpcServerListen function signals the RPC run-time library to listen // for remote procedure calls. // lStatus = RpcServerListen( 1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE ); if ( lStatus ) { swprintf_s(psErrorMessageBuffer, errorMessageBufferLength, L"RpcServerListen returned: 0x%x", lStatus ); return KEYPROVIDER_FAILED; } return 0; }
/* main: register the interface, start listening for clients */ void __cdecl main(int argc, char * argv[]) { RPC_STATUS status; UUID MgrTypeUuid, ClientUuid; unsigned char * pszProtocolSequence = "ncacn_ip_tcp"; unsigned char * pszSecurity = NULL; unsigned char * pszClientUuid = NULL_UUID_STRING; unsigned char * pszMgrTypeUuid = "11111111-1111-1111-1111-111111111111"; unsigned char * pszEndpoint = "8765"; unsigned char * pszSpn = NULL; unsigned int cMinCalls = 1; unsigned int cMaxCalls = 20; unsigned int fDontWait = FALSE; int i; cluuid_SERVER_EPV epv2; // the mgr_epv for the 2nd implementation /* allow the user to override settings with command line switches */ for (i = 1; i < argc; i++) { if ((*argv[i] == '-') || (*argv[i] == '/')) { switch (tolower(*(argv[i]+1))) { case 'p': // protocol sequence pszProtocolSequence = argv[++i]; break; case 'e': pszEndpoint = argv[++i]; break; case 'a': pszSpn = argv[++i]; break; case 'm': cMaxCalls = (unsigned int) atoi(argv[++i]); break; case 'n': cMinCalls = (unsigned int) atoi(argv[++i]); break; case 'f': fDontWait = (unsigned int) atoi(argv[++i]); break; case '1': pszMgrTypeUuid = argv[++i]; break; case '2': pszClientUuid = argv[++i]; break; case 'h': case '?': default: Usage(argv[0]); } } else Usage(argv[0]); } status = RpcServerUseProtseqEp(pszProtocolSequence, cMaxCalls, pszEndpoint, pszSecurity); // Security descriptor printf_s("RpcServerUseProtseqEp returned 0x%x\n", status); if (status) { exit(status); } status = UuidFromString(pszClientUuid, &ClientUuid); printf_s("UuidFromString returned 0x%x = %d\n", status, status); if (status) { exit(status); } status = UuidFromString(pszMgrTypeUuid, &MgrTypeUuid); printf_s("UuidFromString returned 0x%x = %d\n", status, status); if (status) { exit(status); } if (strcmp (pszMgrTypeUuid, NULL_UUID_STRING) == 0) { printf_s("Register object using non-null uuid %s\n", pszMgrTypeUuid); exit(1); } if (strcmp (pszClientUuid, NULL_UUID_STRING) == 0) { printf_s("Register object using non-null uuid %s\n", pszMgrTypeUuid); ClientUuid = MgrTypeUuid; } RpcObjectSetType(&ClientUuid, &MgrTypeUuid); // associate type UUID with nil UUID printf_s("RpcObjectSetType returned 0x%x\n", status); if (status) { exit(status); } /* User did not specify spn, construct one. */ if (pszSpn == NULL) { MakeSpn(&pszSpn); } /* Using Negotiate as security provider. */ status = RpcServerRegisterAuthInfo(pszSpn, RPC_C_AUTHN_GSS_NEGOTIATE, NULL, NULL); printf_s("RpcServerRegisterAuthInfo returned 0x%x\n", status); if (status) { exit(status); } status = RpcServerRegisterIfEx(cluuid_ServerIfHandle, NULL, NULL, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL ); /* register the second manager epv and associate it with the specified uuid. the second uuid must be non-null so that it will not conflict with the NULL uuid already registered for this interface */ epv2.HelloProc = HelloProc2; epv2.Shutdown = Shutdown; status = RpcServerRegisterIfEx(cluuid_ServerIfHandle, &MgrTypeUuid, &epv2, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL ); printf_s("RpcServerRegisterIfEx returned 0x%x\n", status); if (status) { exit(status); } printf_s("Calling RpcServerListen\n"); status = RpcServerListen(cMinCalls, cMaxCalls, fDontWait); printf_s("RpcServerListen returned: 0x%x\n", status); if (status) { exit(status); } if (fDontWait) { printf_s("Calling RpcMgmtWaitServerListen\n"); status = RpcMgmtWaitServerListen(); // wait operation printf_s("RpcMgmtWaitServerListen returned: 0x%x\n", status); if (status) { exit(status); } } } // end main()
void __cdecl main(int argc, char * argv[]) { unsigned char *pszProtocolSequence = DEFAULT_PROTOCOL_SEQUENCE; unsigned char *pszEndpoint = DEFAULT_ENDPOINT; unsigned char *pszSpn = NULL; unsigned int nMinCalls = DEFAULT_MIN_CALLS; unsigned int nMaxCalls = DEFAULT_MAX_CALLS; BOOL bDontWait = DEFAULT_WAIT_FLAG; PSECURITY_DESCRIPTOR pszSecurity = NULL; int i; RPC_STATUS status; // allow the user to override settings with command line switches for (i = 1; i < argc; i++) { if ((*argv[i] == '-') || (*argv[i] == '/')) { switch (tolower(*(argv[i]+1))) { case 'p': pszProtocolSequence = argv[++i]; break; case 'e': pszEndpoint = argv[++i]; break; case 'a': pszSpn = argv[++i]; break; case 'm': nMaxCalls = (unsigned int) atoi(argv[++i]); break; case 'n': nMinCalls = (unsigned int) atoi(argv[++i]); break; case 'f': bDontWait = (unsigned int) atoi(argv[++i]); break; case 'h': case '?': default: Usage(argv[0]); } } else Usage(argv[0]); } if ((pszProtocolSequence == NULL) || (pszEndpoint == NULL) || (nMinCalls < 1) || (nMinCalls > nMaxCalls)) Usage(argv[0]); status = RpcServerUseProtseqEp(pszProtocolSequence, nMaxCalls, pszEndpoint, pszSecurity); printf_s("RpcServerUseProtseqEp returned 0x%x\n", status); if (status) Quit(status); // User did not specify spn, construct one. if (pszSpn == NULL) { MakeSpn(&pszSpn); } // Using Negotiate as security provider. status = RpcServerRegisterAuthInfo(pszSpn, RPC_C_AUTHN_GSS_NEGOTIATE, NULL, NULL); printf_s("RpcServerRegisterAuthInfo returned 0x%x\n", status); if (status) { exit(status); } status = RpcServerRegisterIfEx(AsyncRPC_ServerIfHandle, NULL, NULL, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL); printf_s("Calling RpcServerListen\n"); status = RpcServerListen(nMinCalls, nMaxCalls, bDontWait); printf_s("RpcServerListen returned: 0x%x\n", status); if (status) Quit(status); if (bDontWait) { printf_s("Calling RpcMgmtWaitServerListen\n"); status = RpcMgmtWaitServerListen(); // wait operation printf_s("RpcMgmtWaitServerListen returned: 0x%x\n", status); if (status) Quit(status); } free(pszSecurity); }