4 Copyright (C) Tim Potter 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 void main(int argc, char **argv)
30 const char *username=NULL;
31 const char *password=NULL;
32 const char *domain=NULL;
33 unsigned sec_options = 0;
38 while (argc > 2 && argv[0][0] == '-') {
56 if (strcmp(option, "sign") == 0) {
57 if (sec_options == RPC_C_AUTHN_LEVEL_PKT_PRIVACY) {
58 printf("You must choose sign or seal, not both\n");
61 sec_options = RPC_C_AUTHN_LEVEL_PKT_INTEGRITY;
62 } else if (strcmp(option, "seal") == 0) {
63 if (sec_options == RPC_C_AUTHN_LEVEL_PKT_INTEGRITY) {
64 printf("You must choose sign or seal, not both\n");
67 sec_options = RPC_C_AUTHN_LEVEL_PKT_PRIVACY;
69 printf("Bad security option '%s'\n", option);
76 printf("Bad option -%c\n", argv[0][0]);
84 printf("Usage: client [options] hostname cmd [args]\n\n");
85 printf("Where hostname is the name of the host to connect to,\n");
86 printf("and cmd is the command to execute with optional args:\n\n");
87 printf("\taddone num\tAdd one to num and return the result\n");
88 printf("\techodata size\tSend an array of size bytes and receive it back\n");
89 printf("\tsinkdata size\tSend an array of size bytes\n");
90 printf("\tsourcedata size\tReceive an array of size bytes\n");
91 printf("\ttest\trun testcall\n");
92 printf("\noptions:\n");
93 printf("\t-u username -d domain -p password -e endpoint\n");
94 printf("\t--sign --seal\n");
95 printf("\nExamples:\n");
96 printf("\tclient HOSTNAME addone 3\n");
97 printf("\tclient 192.168.115.1 addone 3\n");
98 printf("\tclient -e ncacn_np:HOSTNAME[\\\\pipe\\\\rpcecho] addone 3\n");
99 printf("\tclient -e ncacn_ip_tcp:192.168.115.1 addone 3\n");
100 printf("\tclient -e ncacn_ip_tcp:192.168.115.1 -u tridge -d MYDOMAIN -p PASSWORD addone 3\n");
106 char *network_address = argv[0];
111 status = RpcStringBindingCompose(
120 printf("RpcStringBindingCompose returned %d\n", status);
125 printf("Endpoint is %s\n", binding);
127 status = RpcBindingFromStringBinding(
132 printf("RpcBindingFromStringBinding returned %d\n", status);
137 SEC_WINNT_AUTH_IDENTITY ident = { username, strlen(username),
138 domain, strlen(domain),
139 password, strlen(password),
140 SEC_WINNT_AUTH_IDENTITY_ANSI };
142 status = RpcBindingSetAuthInfo(rpcecho_IfHandle, NULL,
147 printf ("RpcBindingSetAuthInfo failed: 0x%x\n", status);
156 /* Add one to a number */
158 if (strcmp(argv[0], "addone") == 0) {
162 printf("Usage: addone num\n");
168 AddOne(arg, &result);
169 printf("%d + 1 = %d\n", arg, result);
178 if (strcmp(argv[0], "echodata") == 0) {
180 char *indata, *outdata;
183 printf("Usage: echo num\n");
189 if ((indata = malloc(arg)) == NULL) {
190 printf("Error allocating %d bytes for input\n", arg);
194 if ((outdata = malloc(arg)) == NULL) {
195 printf("Error allocating %d bytes for output\n", arg);
199 for (i = 0; i < arg; i++)
200 indata[i] = i & 0xff;
202 EchoData(arg, indata, outdata);
204 printf("echo %d\n", arg);
206 for (i = 0; i < arg; i++) {
207 if (indata[i] != outdata[i]) {
208 printf("data mismatch at offset %d, %d != %d\n",
209 i, indata[i], outdata[i]);
219 if (strcmp(argv[0], "sinkdata") == 0) {
224 printf("Usage: sinkdata num\n");
230 if ((indata = malloc(arg)) == NULL) {
231 printf("Error allocating %d bytes for input\n", arg);
235 for (i = 0; i < arg; i++)
236 indata[i] = i & 0xff;
238 SinkData(arg, indata);
240 printf("sinkdata %d\n", arg);
246 if (strcmp(argv[0], "sourcedata") == 0) {
248 unsigned char *outdata;
251 printf("Usage: sourcedata num\n");
257 if ((outdata = malloc(arg)) == NULL) {
258 printf("Error allocating %d bytes for output\n", arg);
262 SourceData(arg, outdata);
264 printf("sourcedata %d\n", arg);
266 for (i = 0; i < arg; i++) {
267 if (outdata[i] != (i & 0xff)) {
268 printf("data mismatch at offset %d, %d != %d\n",
269 i, outdata[i], i & 0xff);
278 if (strcmp(argv[0], "test") == 0) {
279 printf("no TestCall\n");
287 if (strcmp(argv[0], "enum") == 0) {
288 enum echo_Enum1 v = ECHO_ENUM1;
293 e2.e2 = ECHO_ENUM1_32;
299 echo_TestEnum(&v, &e2, &e3);
304 if (strcmp(argv[0], "sleep") == 0) {
308 printf("Usage: sleep num\n");
314 // result = TestSleep(arg);
315 // printf("Slept for %d seconds\n", result);
316 printf("Sleep disabled (need async code)\n");
323 printf("Invalid command '%s'\n", argv[0]);
329 ex = RpcExceptionCode();
330 printf("Runtime error 0x%x\n", ex);
336 status = RpcStringFree(&binding);
339 printf("RpcStringFree returned %d\n", status);
343 status = RpcBindingFree(&rpcecho_IfHandle);
346 printf("RpcBindingFree returned %d\n", status);