DWORD VmDnsRpcServerUseProtSeqEp( PCSTR pszProtSeq, PCSTR pszEndpoint ) { DWORD dwError = 0; DCETHREAD_TRY { rpc_server_use_protseq_ep( (unsigned char*) pszProtSeq, rpc_c_protseq_max_calls_default, (unsigned char*) pszEndpoint, (unsigned32*)&dwError); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if ( dwError == rpc_s_ok ) { dwError = dcethread_exc_getstatus(THIS_CATCH); if (!dwError) { dwError = RPC_S_INTERNAL_ERROR; } } } DCETHREAD_ENDTRY; BAIL_ON_VMDNS_ERROR(dwError); error: return dwError; }
DWORD VmDnsRpcServerRegisterAuthInfo( VOID ) { DWORD dwError = 0; DCETHREAD_TRY { rpc_server_register_auth_info ( NULL, // Server principal name rpc_c_authn_gss_negotiate, // Authentication service NULL, // Use default key function NULL, &dwError); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if (dwError == rpc_s_ok ) { dwError = dcethread_exc_getstatus(THIS_CATCH); if (!dwError) { dwError = RPC_S_INTERNAL_ERROR; } } } DCETHREAD_ENDTRY; return dwError; }
PVOID SrvSvcListenForRPC( PVOID pArg ) { volatile DWORD dwError = 0; DCETHREAD_TRY { rpc_server_listen(rpc_c_listen_max_calls_default, (unsigned32*)&dwError); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if (!dwError) { dwError = dcethread_exc_getstatus (THIS_CATCH); } if(!dwError) { dwError = SRVSVC_ERROR_RPC_EXCEPTION_UPON_LISTEN; } } DCETHREAD_ENDTRY BAIL_ON_SRVSVC_ERROR(dwError); cleanup: return NULL; error: SRVSVC_LOG_ERROR("Failed to begin RPC listening. Error code [%d]\n", dwError); goto cleanup; }
DWORD VmDnsRpcServerInqBindings( rpc_binding_vector_p_t* ppServerBindings ) { DWORD dwError = 0; DCETHREAD_TRY { rpc_server_inq_bindings(ppServerBindings, (unsigned32*)&dwError); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if ( dwError == rpc_s_ok ) { dwError = dcethread_exc_getstatus(THIS_CATCH); if (!dwError) { dwError = RPC_S_INTERNAL_ERROR; } } } DCETHREAD_ENDTRY; BAIL_ON_VMDNS_ERROR(dwError); error: return dwError; }
DWORD VmDnsRpcServerStopListen( VOID ) { DWORD dwError = 0; DCETHREAD_TRY { rpc_mgmt_stop_server_listening(NULL, (unsigned32*)&dwError); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if (!dwError) { dwError = dcethread_exc_getstatus(THIS_CATCH); } if(!dwError) { dwError = RPC_S_INTERNAL_ERROR; } } DCETHREAD_ENDTRY; BAIL_ON_VMDNS_ERROR(dwError); error: return dwError; }
DWORD VmDnsRpcServerRegisterIf( rpc_if_handle_t pInterfaceSpec ) { DWORD dwError = 0; DCETHREAD_TRY { rpc_server_register_if_ex( pInterfaceSpec, NULL, NULL, rpc_if_allow_secure_only, rpc_c_listen_max_calls_default, VmDnsRpcIfCallbackFn, &dwError ); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if ( dwError == rpc_s_ok ) { dwError = dcethread_exc_getstatus(THIS_CATCH); if (!dwError) { dwError = RPC_S_INTERNAL_ERROR; } } } DCETHREAD_ENDTRY; return dwError; }
// macros use this function // static DWORD VmAuthsvcRpcGetErrorCode( dcethread_exc* pDceException ) { DWORD dwError = 0; dwError = dcethread_exc_getstatus(pDceException); #ifndef _WIN32 dwError = LwNtStatusToWin32Error(LwRpcStatusToNtStatus(dwError)); #endif return dwError; }
error_status_t rpc_exception_status( dcethread_exc * exc) { int status; status = dcethread_exc_getstatus(exc); if (status == -1) { SMBLogInfo("unexpected RPC exception: kind=%#x address=%p %s", ASL_LEVEL_DEBUG, exc->kind, exc->match.address, exc->name); return rpc_m_unexpected_exc; } return status; }
static PVOID VmDnsListenRpcServer( PVOID pInfo ) { DWORD dwError = 0; DCETHREAD_TRY { rpc_server_listen( rpc_c_listen_max_calls_default, (unsigned32*)&dwError); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if (!dwError) { dwError = dcethread_exc_getstatus(THIS_CATCH); } if(!dwError) { dwError = RPC_S_INTERNAL_ERROR; } } DCETHREAD_ENDTRY; BAIL_ON_VMDNS_ERROR(dwError); cleanup: #ifndef _WIN32 raise(SIGTERM); // indicate that process must terminate #endif return NULL; error: goto cleanup; }
static BOOLEAN VmDnsRpcCheckServerIsActive( VOID ) { DWORD dwError = 0; BOOLEAN bIsActive = FALSE; DCETHREAD_TRY { bIsActive = rpc_mgmt_is_server_listening(NULL, (unsigned32*)&dwError); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if (!dwError) { dwError = dcethread_exc_getstatus(THIS_CATCH); } if (!dwError) { dwError = RPC_S_INTERNAL_ERROR; } } DCETHREAD_ENDTRY; BAIL_ON_VMDNS_ERROR(dwError); cleanup: return bIsActive; error: bIsActive = FALSE; goto cleanup; }
BOOLEAN VMCACheckRPCServerIsActive( VOID ) { DWORD dwError = 0; BOOLEAN bIsActive = FALSE; DCETHREAD_TRY { bIsActive = rpc_mgmt_is_server_listening(NULL, (unsigned32*)&dwError); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if (!dwError) { dwError = dcethread_exc_getstatus (THIS_CATCH); } if (!dwError) { dwError = VMCAMapDCEErrorCode(dwError); } } DCETHREAD_ENDTRY; BAIL_ON_VMCA_ERROR(dwError); cleanup: return bIsActive; error: bIsActive = FALSE; goto cleanup; }
BOOLEAN SrvSvcRpcIsListening( VOID ) { volatile DWORD dwError = 0; BOOLEAN bIsListening = FALSE; DCETHREAD_TRY { bIsListening = rpc_mgmt_is_server_listening(NULL, (unsigned32*)&dwError); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if (!dwError) { dwError = dcethread_exc_getstatus (THIS_CATCH); } if (!dwError) { dwError = SRVSVC_ERROR_RPC_EXCEPTION_UPON_LISTEN; } } DCETHREAD_ENDTRY; BAIL_ON_SRVSVC_ERROR(dwError); cleanup: return bIsListening; error: bIsListening = FALSE; goto cleanup; }
DWORD VmDnsRpcEpRegister( rpc_binding_vector_p_t pServerBinding, rpc_if_handle_t pInterfaceSpec, PCSTR pszAnnotation ) { DWORD dwError = 0; #if 1 /* Do not register with dcerpc; all services use fixed endpoints */ return dwError; #else DCETHREAD_TRY { rpc_ep_register( pInterfaceSpec, pServerBinding, NULL, (idl_char*)pszAnnotation, (unsigned32*)&dwError); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if (dwError == rpc_s_ok ) { dwError = dcethread_exc_getstatus(THIS_CATCH); if (!dwError) { dwError = RPC_S_INTERNAL_ERROR; } } } DCETHREAD_ENDTRY; return dwError; #endif }
DWORD SrvSvcRpcStopListening( VOID ) { volatile DWORD dwError = 0; DCETHREAD_TRY { rpc_mgmt_stop_server_listening(NULL, (unsigned32*)&dwError); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if (!dwError) { dwError = dcethread_exc_getstatus (THIS_CATCH); } if(!dwError) { dwError = SRVSVC_ERROR_RPC_EXCEPTION_UPON_LISTEN; } } DCETHREAD_ENDTRY; BAIL_ON_SRVSVC_ERROR(dwError); cleanup: return dwError; error: SRVSVC_LOG_ERROR("Failed to stop RPC listening. Error code [%d]\n", dwError); goto cleanup; }
DWORD WinRegUnregisterForRPC( rpc_binding_vector_p_t pServerBinding ) { volatile DWORD dwError = 0; volatile DWORD dwRpcStatus = 0; DCETHREAD_TRY { SRVSVC_LOG_INFO("Unregistering server from the endpoint mapper..."); rpc_ep_unregister(winreg_v1_0_s_ifspec, pServerBinding, NULL, (unsigned32*)&dwRpcStatus); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if (dwRpcStatus == RPC_S_OK) { dwError = dcethread_exc_getstatus(THIS_CATCH); if (!dwError) { dwError = SRVSVC_ERROR_RPC_EXCEPTION_UPON_UNREGISTER; } } } DCETHREAD_ENDTRY BAIL_ON_DCE_ERROR(dwError, dwRpcStatus); BAIL_ON_SRVSVC_ERROR(dwError); DCETHREAD_TRY { rpc_binding_vector_free(&pServerBinding, (unsigned32*)&dwRpcStatus); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if (dwRpcStatus == RPC_S_OK) { dwError = dcethread_exc_getstatus(THIS_CATCH); if (!dwError) { dwError = SRVSVC_ERROR_RPC_EXCEPTION_UPON_UNREGISTER; } } } DCETHREAD_ENDTRY BAIL_ON_DCE_ERROR(dwError, dwRpcStatus); BAIL_ON_SRVSVC_ERROR(dwError); DCETHREAD_TRY { SRVSVC_LOG_INFO("Cleaning up the communications endpoints..."); rpc_server_unregister_if(winreg_v1_0_s_ifspec, NULL, (unsigned32*)&dwRpcStatus); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if (dwRpcStatus == RPC_S_OK) { dwError = dcethread_exc_getstatus(THIS_CATCH); if (!dwError) { dwError = SRVSVC_ERROR_RPC_EXCEPTION_UPON_UNREGISTER; } } } DCETHREAD_ENDTRY BAIL_ON_DCE_ERROR(dwError, dwRpcStatus); BAIL_ON_SRVSVC_ERROR(dwError); cleanup: return dwError; error: SRVSVC_LOG_ERROR("Failed to unregister RPC endpoint. Error code [%d]\n", dwError); goto cleanup; }
DWORD WinRegRegisterForRPC( PSTR pszServiceName, rpc_binding_vector_p_t* ppServerBinding ) { volatile DWORD dwError = 0; volatile DWORD dwRpcStatus = 0; rpc_binding_vector_p_t pServerBinding = NULL; BOOLEAN bRegistered = FALSE; BOOLEAN bBound = FALSE; BOOLEAN bEPRegistered = FALSE; static ENDPOINT endpoints[] = { {"ncacn_ip_tcp", NULL}, {"ncacn_np" , "\\\\pipe\\\\winreg"}, {NULL , NULL} }; DCETHREAD_TRY { rpc_server_register_if(winreg_v1_0_s_ifspec, NULL, NULL, (unsigned32*)&dwRpcStatus); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if (dwRpcStatus == RPC_S_OK) { dwError = dcethread_exc_getstatus(THIS_CATCH); if (!dwError) { dwError = SRVSVC_ERROR_RPC_EXCEPTION_UPON_REGISTER; } } } DCETHREAD_ENDTRY; BAIL_ON_DCE_ERROR(dwError, dwRpcStatus); BAIL_ON_SRVSVC_ERROR(dwError); bRegistered = TRUE; SRVSVC_LOG_INFO("RPC Service registered successfully."); DCETHREAD_TRY { dwError = bind_server(&pServerBinding, winreg_v1_0_s_ifspec, endpoints); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if (!dwError) { dwError = dcethread_exc_getstatus(THIS_CATCH); } if (!dwError) { dwError = SRVSVC_ERROR_RPC_EXCEPTION_UPON_REGISTER; } } DCETHREAD_ENDTRY; BAIL_ON_SRVSVC_ERROR(dwError); bBound = TRUE; DCETHREAD_TRY { rpc_ep_register(winreg_v1_0_s_ifspec, pServerBinding, NULL, (idl_char*)pszServiceName, (unsigned32*)&dwRpcStatus); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if (dwRpcStatus == RPC_S_OK) { dwError = dcethread_exc_getstatus(THIS_CATCH); if (!dwError) { dwError = SRVSVC_ERROR_RPC_EXCEPTION_UPON_REGISTER; } } } DCETHREAD_ENDTRY; BAIL_ON_DCE_ERROR(dwError, dwRpcStatus); BAIL_ON_SRVSVC_ERROR(dwError); bEPRegistered = TRUE; SRVSVC_LOG_INFO("RPC Endpoint registered successfully."); *ppServerBinding = pServerBinding; cleanup: return dwError; error: SRVSVC_LOG_ERROR("Failed to register RPC endpoint. Error Code: [%u]\n", dwError); if (bEPRegistered) { DCETHREAD_TRY { DWORD tmpStatus = 0; rpc_ep_unregister(winreg_v1_0_s_ifspec, pServerBinding, NULL, (unsigned32*)&tmpStatus); } DCETHREAD_CATCH_ALL(THIS_CATCH) DCETHREAD_ENDTRY; } if (bBound) { DCETHREAD_TRY { DWORD tmpStatus = 0; rpc_binding_vector_free(&pServerBinding, (unsigned32*)&tmpStatus); } DCETHREAD_CATCH_ALL(THIS_CATCH) DCETHREAD_ENDTRY; } if (bRegistered) { DCETHREAD_TRY { DWORD tmpStatus = 0; rpc_server_unregister_if(winreg_v1_0_s_ifspec, NULL, (unsigned32*)&tmpStatus); } DCETHREAD_CATCH_ALL(THIS_CATCH) DCETHREAD_ENDTRY; } *ppServerBinding = NULL; goto cleanup; }
DWORD SrvSvcRegisterForRPC( PSTR pszServiceName, rpc_binding_vector_p_t* ppServerBinding ) { volatile DWORD dwError = 0; volatile DWORD dwRpcStatus = 0; rpc_binding_vector_p_t pServerBinding = NULL; BOOLEAN bRegistered = FALSE; BOOLEAN bBound = FALSE; BOOLEAN bEPRegistered = FALSE; static ENDPOINT endpoints[] = { {"ncacn_np", "\\\\pipe\\\\srvsvc"}, {"ncalrpc", NULL}, // endpoint is fetched from config parameter {NULL, NULL}, // placeholder for ncacn_ip_tcp (if enabled) {NULL, NULL} }; DWORD i = 0; PSTR lpcSocketPath = NULL; BOOLEAN registerTcpIp = FALSE; dwError = SrvSvcConfigGetLpcSocketPath(&lpcSocketPath); BAIL_ON_SRVSVC_ERROR(dwError); // Fill in the socket path for local procedure calls (ncalrpc) while (endpoints[i].protocol) { if (lpcSocketPath && LwRtlCStringIsEqual(endpoints[i].protocol, "ncalrpc", TRUE)) { endpoints[i].endpoint = lpcSocketPath; } i++; } dwError = SrvSvcConfigGetRegisterTcpIp(®isterTcpIp); BAIL_ON_SRVSVC_ERROR(dwError); // Append ncacn_ip_tcp endpoint if it's enabled in the configuration if (registerTcpIp) { endpoints[i++].protocol = "ncacn_ip_tcp"; } DCETHREAD_TRY { rpc_server_register_if (srvsvc_v3_0_s_ifspec, NULL, NULL, (unsigned32*)&dwRpcStatus); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if ( dwRpcStatus == RPC_S_OK ) { dwError = dcethread_exc_getstatus (THIS_CATCH); if(!dwError) { dwError = SRVSVC_ERROR_RPC_EXCEPTION_UPON_REGISTER; } } } DCETHREAD_ENDTRY; BAIL_ON_DCE_ERROR(dwError, dwRpcStatus); BAIL_ON_SRVSVC_ERROR(dwError); bRegistered = TRUE; SRVSVC_LOG_INFO("RPC Service registered successfully."); DCETHREAD_TRY { dwError = bind_server(&pServerBinding, srvsvc_v3_0_s_ifspec, endpoints); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if(!dwError) { dwError = dcethread_exc_getstatus (THIS_CATCH); } if(!dwError) { dwError = SRVSVC_ERROR_RPC_EXCEPTION_UPON_REGISTER; } } DCETHREAD_ENDTRY; BAIL_ON_SRVSVC_ERROR(dwError); bBound = TRUE; DCETHREAD_TRY { rpc_ep_register(srvsvc_v3_0_s_ifspec, pServerBinding, NULL, (idl_char*)pszServiceName, (unsigned32*)&dwRpcStatus); } DCETHREAD_CATCH_ALL(THIS_CATCH) { if ( dwRpcStatus == RPC_S_OK ) { dwError = dcethread_exc_getstatus (THIS_CATCH); if(!dwError) { dwError = SRVSVC_ERROR_RPC_EXCEPTION_UPON_REGISTER; } } } DCETHREAD_ENDTRY; BAIL_ON_DCE_ERROR(dwError, dwRpcStatus); BAIL_ON_SRVSVC_ERROR(dwError); bEPRegistered = TRUE; SRVSVC_LOG_INFO("RPC Endpoint registered successfully."); *ppServerBinding = pServerBinding; cleanup: // DCE/RPC runtime makes a copy of ncalrpc socket path internally // so it is safe to free it here LW_SAFE_FREE_MEMORY(lpcSocketPath); return dwError; error: SRVSVC_LOG_ERROR("Failed to register RPC endpoint. Error Code: [%u]\n", dwError); if (bEPRegistered) { DCETHREAD_TRY { DWORD tmpStatus = 0; rpc_ep_unregister(srvsvc_v3_0_s_ifspec, pServerBinding, NULL, (unsigned32*)&tmpStatus); } DCETHREAD_CATCH_ALL(THIS_CATCH) DCETHREAD_ENDTRY; } if (bBound) { DCETHREAD_TRY { DWORD tmpStatus = 0; rpc_binding_vector_free(&pServerBinding, (unsigned32*)&tmpStatus); } DCETHREAD_CATCH_ALL(THIS_CATCH) DCETHREAD_ENDTRY; } if (bRegistered) { DCETHREAD_TRY { DWORD tmpStatus = 0; rpc_server_unregister_if (srvsvc_v3_0_s_ifspec, NULL, (unsigned32*)&tmpStatus); } DCETHREAD_CATCH_ALL(THIS_CATCH) DCETHREAD_ENDTRY; } *ppServerBinding = NULL; goto cleanup; }