xref: /freebsd/crypto/krb5/src/ccapi/test/pingtest.c (revision f1c4c3daccbaf3820f0e2224de53df12fc952fcc)
1 // pingtest.c
2 //
3 // Test RPC to server, with PING message, which exists for no other purpose than this test.
4 
5 #include <stdio.h>
6 #include <stdarg.h>
7 #include <stdlib.h>
8 #include <malloc.h>
9 
10 #include "cci_debugging.h"
11 #include "CredentialsCache.h"
12 #include "win-utils.h"
13 
14 #include "ccs_request.h"
15 #define CLIENT_REQUEST_RPC_HANDLE ccs_request_IfHandle
16 
17 
18 extern cc_int32 cci_os_ipc_thread_init (void);
19 extern cc_int32 cci_os_ipc_msg( cc_int32        in_launch_server,
20                                 k5_ipc_stream   in_request_stream,
21                                 cc_int32        in_msg,
22                                 k5_ipc_stream*  out_reply_stream);
23 
24 static DWORD    dwTlsIndex;
25 
GetTlsIndex(void)26 DWORD GetTlsIndex(void)    {return dwTlsIndex;}
27 
send_test(char * endpoint)28 RPC_STATUS send_test(char* endpoint) {
29     unsigned char*  pszNetworkAddress   = NULL;
30     unsigned char*  pszOptions          = NULL;
31     unsigned char*  pszStringBinding    = NULL;
32     unsigned char*  pszUuid             = NULL;
33     RPC_STATUS      status;
34 
35     status = RpcStringBindingCompose(pszUuid,
36                                      (RPC_CSTR)"ncalrpc",
37                                      pszNetworkAddress,
38                                      (unsigned char*)endpoint,
39                                      pszOptions,
40                                      &pszStringBinding);
41     cci_debug_printf("%s pszStringBinding = %s", __FUNCTION__, pszStringBinding);
42     if (status) {return cci_check_error(status);}
43 
44     /* Set the binding handle that will be used to bind to the RPC server [the 'client']. */
45     status = RpcBindingFromStringBinding(pszStringBinding, &CLIENT_REQUEST_RPC_HANDLE);
46     if (status) {return cci_check_error(status);}
47 
48     status = RpcStringFree(&pszStringBinding);  // Temp var no longer needed.
49 
50     if (!status) {
51         RpcTryExcept {
52             cci_debug_printf("%s calling remote procedure 'ccs_authenticate'", __FUNCTION__);
53             status = ccs_authenticate((CC_CHAR*)"DLLMAIN TEST!");
54             cci_debug_printf("  ccs_authenticate returned %d", status);
55             }
56         RpcExcept(1) {
57             status = cci_check_error(RpcExceptionCode());
58             }
59         RpcEndExcept
60         }
61 
62     cci_check_error(RpcBindingFree(&CLIENT_REQUEST_RPC_HANDLE));
63 
64     return (status);
65     }
66 
main(int argc,char * argv[])67 int main(   int argc, char *argv[]) {
68     cc_int32        err             = 0;
69     cc_context_t    context         = NULL;
70     k5_ipc_stream   send_stream     = NULL;
71     k5_ipc_stream   reply_stream    = NULL;
72     char*           message         = "Hello, RPC!";
73 
74 
75     if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) return FALSE;
76 
77     if (!err) {
78         err = cci_os_ipc_thread_init();
79         }
80     if (!err) {
81         err = krb5int_ipc_stream_new  (&send_stream);
82         err = krb5int_ipc_stream_write(send_stream, message,
83 				       1+strlen(message));
84         }
85 
86     if (!err) {
87         err = cci_os_ipc_msg(TRUE, send_stream, CCMSG_PING, &reply_stream);
88         }
89     Sleep(10*1000);
90     cci_debug_printf("Try finishing async call.");
91 
92     Sleep(INFINITE);
93     cci_debug_printf("main: return. err == %d", err);
94 
95     return 0;
96     }
97 
98 
99 
100 /*********************************************************************/
101 /*                 MIDL allocate and free                            */
102 /*********************************************************************/
103 
midl_user_allocate(size_t len)104 void  __RPC_FAR * __RPC_USER midl_user_allocate(size_t len) {
105     return(malloc(len));
106     }
107 
midl_user_free(void __RPC_FAR * ptr)108 void __RPC_USER midl_user_free(void __RPC_FAR * ptr) {
109     free(ptr);
110     }
111