Imported Upstream version 1.10.2
[platform/upstream/krb5.git] / src / ccapi / test / pingtest.c
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
26 DWORD GetTlsIndex()    {return dwTlsIndex;}
27
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
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 //    send_test("krbcc.229026.0.ep");
78
79 #if 0
80     err = cc_initialize(&context, ccapi_version_7, NULL, NULL);
81 #endif
82
83     if (!err) {
84         err = cci_os_ipc_thread_init();
85         }
86     if (!err) {
87         err = krb5int_ipc_stream_new  (&send_stream);
88         err = krb5int_ipc_stream_write(send_stream, message,
89                                        1+strlen(message));
90         }
91
92     if (!err) {
93         err = cci_os_ipc_msg(TRUE, send_stream, CCMSG_PING, &reply_stream);
94         }
95     Sleep(10*1000);
96     cci_debug_printf("Try finishing async call.");
97
98     Sleep(INFINITE);
99     cci_debug_printf("main: return. err == %d", err);
100
101     return 0;
102     }
103
104
105
106 /*********************************************************************/
107 /*                 MIDL allocate and free                            */
108 /*********************************************************************/
109
110 void  __RPC_FAR * __RPC_USER midl_user_allocate(size_t len) {
111     return(malloc(len));
112     }
113
114 void __RPC_USER midl_user_free(void __RPC_FAR * ptr) {
115     free(ptr);
116     }