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 3 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, see <http://www.gnu.org/licenses/>.
25 void main(int argc, char **argv)
29 const char *username=NULL;
30 const char *password=NULL;
31 const char *domain=NULL;
32 unsigned sec_options = 0;
37 while (argc > 2 && argv[0][0] == '-') {
55 if (strcmp(option, "sign") == 0) {
56 if (sec_options == RPC_C_AUTHN_LEVEL_PKT_PRIVACY) {
57 printf("You must choose sign or seal, not both\n");
60 sec_options = RPC_C_AUTHN_LEVEL_PKT_INTEGRITY;
61 } else if (strcmp(option, "seal") == 0) {
62 if (sec_options == RPC_C_AUTHN_LEVEL_PKT_INTEGRITY) {
63 printf("You must choose sign or seal, not both\n");
66 sec_options = RPC_C_AUTHN_LEVEL_PKT_PRIVACY;
68 printf("Bad security option '%s'\n", option);
75 printf("Bad option -%c\n", argv[0][0]);
83 printf("Usage: client [options] hostname cmd [args]\n\n");
84 printf("Where hostname is the name of the host to connect to,\n");
85 printf("and cmd is the command to execute with optional args:\n\n");
86 printf("\taddone num\tAdd one to num and return the result\n");
87 printf("\techodata size\tSend an array of size bytes and receive it back\n");
88 printf("\tsinkdata size\tSend an array of size bytes\n");
89 printf("\tsourcedata size\tReceive an array of size bytes\n");
90 printf("\ttest\trun testcall\n");
91 printf("\noptions:\n");
92 printf("\t-u username -d domain -p password -e endpoint\n");
93 printf("\t--sign --seal\n");
94 printf("\nExamples:\n");
95 printf("\tclient HOSTNAME addone 3\n");
96 printf("\tclient 192.168.115.1 addone 3\n");
97 printf("\tclient -e ncacn_np:HOSTNAME[\\\\pipe\\\\rpcecho] addone 3\n");
98 printf("\tclient -e ncacn_ip_tcp:192.168.115.1 addone 3\n");
99 printf("\tclient -e ncacn_ip_tcp:192.168.115.1 -u tridge -d MYDOMAIN -p PASSWORD addone 3\n");
105 char *network_address = argv[0];
110 status = RpcStringBindingCompose(
119 printf("RpcStringBindingCompose returned %d\n", status);
124 printf("Endpoint is %s\n", binding);
126 status = RpcBindingFromStringBinding(
131 printf("RpcBindingFromStringBinding returned %d\n", status);
136 SEC_WINNT_AUTH_IDENTITY ident = { username, strlen(username),
137 domain, strlen(domain),
138 password, strlen(password),
139 SEC_WINNT_AUTH_IDENTITY_ANSI };
141 status = RpcBindingSetAuthInfo(rpcecho_IfHandle, NULL,
146 printf ("RpcBindingSetAuthInfo failed: 0x%x\n", status);
155 /* Add one to a number */
157 if (strcmp(argv[0], "addone") == 0) {
161 printf("Usage: addone num\n");
167 AddOne(arg, &result);
168 printf("%d + 1 = %d\n", arg, result);
177 if (strcmp(argv[0], "echodata") == 0) {
179 char *indata, *outdata;
182 printf("Usage: echo num\n");
188 if ((indata = malloc(arg)) == NULL) {
189 printf("Error allocating %d bytes for input\n", arg);
193 if ((outdata = malloc(arg)) == NULL) {
194 printf("Error allocating %d bytes for output\n", arg);
198 for (i = 0; i < arg; i++)
199 indata[i] = i & 0xff;
201 EchoData(arg, indata, outdata);
203 printf("echo %d\n", arg);
205 for (i = 0; i < arg; i++) {
206 if (indata[i] != outdata[i]) {
207 printf("data mismatch at offset %d, %d != %d\n",
208 i, indata[i], outdata[i]);
218 if (strcmp(argv[0], "sinkdata") == 0) {
223 printf("Usage: sinkdata num\n");
229 if ((indata = malloc(arg)) == NULL) {
230 printf("Error allocating %d bytes for input\n", arg);
234 for (i = 0; i < arg; i++)
235 indata[i] = i & 0xff;
237 SinkData(arg, indata);
239 printf("sinkdata %d\n", arg);
245 if (strcmp(argv[0], "sourcedata") == 0) {
247 unsigned char *outdata;
250 printf("Usage: sourcedata num\n");
256 if ((outdata = malloc(arg)) == NULL) {
257 printf("Error allocating %d bytes for output\n", arg);
261 SourceData(arg, outdata);
263 printf("sourcedata %d\n", arg);
265 for (i = 0; i < arg; i++) {
266 if (outdata[i] != (i & 0xff)) {
267 printf("data mismatch at offset %d, %d != %d\n",
268 i, outdata[i], i & 0xff);
277 if (strcmp(argv[0], "test") == 0) {
278 printf("no TestCall\n");
286 if (strcmp(argv[0], "enum") == 0) {
287 enum echo_Enum1 v = ECHO_ENUM1;
292 e2.e2 = ECHO_ENUM1_32;
298 echo_TestEnum(&v, &e2, &e3);
303 if (strcmp(argv[0], "double") == 0) {
304 typedef unsigned short uint16;
313 ret = echo_TestDoublePointer(&ppv);
315 printf("TestDoublePointer v=%d ret=%d\n", v, ret);
320 if (strcmp(argv[0], "sleep") == 0) {
324 printf("Usage: sleep num\n");
330 // result = TestSleep(arg);
331 // printf("Slept for %d seconds\n", result);
332 printf("Sleep disabled (need async code)\n");
339 printf("Invalid command '%s'\n", argv[0]);
345 ex = RpcExceptionCode();
346 printf("Runtime error 0x%x\n", ex);
352 status = RpcStringFree(&binding);
355 printf("RpcStringFree returned %d\n", status);
359 status = RpcBindingFree(&rpcecho_IfHandle);
362 printf("RpcBindingFree returned %d\n", status);