Path: blob/main/crypto/krb5/src/ccapi/test/pingtest.c
39537 views
// pingtest.c1//2// Test RPC to server, with PING message, which exists for no other purpose than this test.34#include <stdio.h>5#include <stdarg.h>6#include <stdlib.h>7#include <malloc.h>89#include "cci_debugging.h"10#include "CredentialsCache.h"11#include "win-utils.h"1213#include "ccs_request.h"14#define CLIENT_REQUEST_RPC_HANDLE ccs_request_IfHandle151617extern cc_int32 cci_os_ipc_thread_init (void);18extern cc_int32 cci_os_ipc_msg( cc_int32 in_launch_server,19k5_ipc_stream in_request_stream,20cc_int32 in_msg,21k5_ipc_stream* out_reply_stream);2223static DWORD dwTlsIndex;2425DWORD GetTlsIndex(void) {return dwTlsIndex;}2627RPC_STATUS send_test(char* endpoint) {28unsigned char* pszNetworkAddress = NULL;29unsigned char* pszOptions = NULL;30unsigned char* pszStringBinding = NULL;31unsigned char* pszUuid = NULL;32RPC_STATUS status;3334status = RpcStringBindingCompose(pszUuid,35(RPC_CSTR)"ncalrpc",36pszNetworkAddress,37(unsigned char*)endpoint,38pszOptions,39&pszStringBinding);40cci_debug_printf("%s pszStringBinding = %s", __FUNCTION__, pszStringBinding);41if (status) {return cci_check_error(status);}4243/* Set the binding handle that will be used to bind to the RPC server [the 'client']. */44status = RpcBindingFromStringBinding(pszStringBinding, &CLIENT_REQUEST_RPC_HANDLE);45if (status) {return cci_check_error(status);}4647status = RpcStringFree(&pszStringBinding); // Temp var no longer needed.4849if (!status) {50RpcTryExcept {51cci_debug_printf("%s calling remote procedure 'ccs_authenticate'", __FUNCTION__);52status = ccs_authenticate((CC_CHAR*)"DLLMAIN TEST!");53cci_debug_printf(" ccs_authenticate returned %d", status);54}55RpcExcept(1) {56status = cci_check_error(RpcExceptionCode());57}58RpcEndExcept59}6061cci_check_error(RpcBindingFree(&CLIENT_REQUEST_RPC_HANDLE));6263return (status);64}6566int main( int argc, char *argv[]) {67cc_int32 err = 0;68cc_context_t context = NULL;69k5_ipc_stream send_stream = NULL;70k5_ipc_stream reply_stream = NULL;71char* message = "Hello, RPC!";727374if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) return FALSE;7576if (!err) {77err = cci_os_ipc_thread_init();78}79if (!err) {80err = krb5int_ipc_stream_new (&send_stream);81err = krb5int_ipc_stream_write(send_stream, message,821+strlen(message));83}8485if (!err) {86err = cci_os_ipc_msg(TRUE, send_stream, CCMSG_PING, &reply_stream);87}88Sleep(10*1000);89cci_debug_printf("Try finishing async call.");9091Sleep(INFINITE);92cci_debug_printf("main: return. err == %d", err);9394return 0;95}96979899/*********************************************************************/100/* MIDL allocate and free */101/*********************************************************************/102103void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len) {104return(malloc(len));105}106107void __RPC_USER midl_user_free(void __RPC_FAR * ptr) {108free(ptr);109}110111112