r23249: another sync from 3.0.26 for the echo work to rpcclient
[Samba.git] / source / rpcclient / cmd_echo.c
blobd9d14247f4d1b02156e1e90d5ac08a3ca56473a4
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
5 Copyright (C) Tim Potter 2003
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
23 #include "rpcclient.h"
25 static NTSTATUS cmd_echo_add_one(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
26 int argc, const char **argv)
28 uint32 request = 1, response;
29 NTSTATUS result;
31 if (argc > 2) {
32 printf("Usage: %s [num]\n", argv[0]);
33 return NT_STATUS_OK;
36 if (argc == 2)
37 request = atoi(argv[1]);
39 result = rpccli_echo_AddOne(cli, mem_ctx, request, &response);
41 if (!NT_STATUS_IS_OK(result))
42 goto done;
44 printf("%d + 1 = %d\n", request, response);
46 done:
47 return result;
50 static NTSTATUS cmd_echo_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
51 int argc, const char **argv)
53 uint32 size, i;
54 NTSTATUS result;
55 uint8_t *in_data = NULL, *out_data = NULL;
57 if (argc != 2) {
58 printf("Usage: %s num\n", argv[0]);
59 return NT_STATUS_OK;
62 size = atoi(argv[1]);
63 if ( (in_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
64 printf("Failure to allocate buff of %d bytes\n",
65 size);
66 goto done;
68 if ( (out_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
69 printf("Failure to allocate buff of %d bytes\n",
70 size);
71 goto done;
74 for (i = 0; i < size; i++)
75 in_data[i] = i & 0xff;
77 result = rpccli_echo_EchoData(cli, mem_ctx, size, in_data, out_data);
79 if (!NT_STATUS_IS_OK(result))
80 goto done;
82 for (i = 0; i < size; i++) {
83 if (in_data[i] != out_data[i]) {
84 printf("mismatch at offset %d, %d != %d\n",
85 i, in_data[i], out_data[i]);
86 result = NT_STATUS_UNSUCCESSFUL;
90 done:
91 SAFE_FREE(in_data);
92 SAFE_FREE(out_data);
94 return result;
97 static NTSTATUS cmd_echo_source_data(struct rpc_pipe_client *cli,
98 TALLOC_CTX *mem_ctx, int argc,
99 const char **argv)
101 uint32 size, i;
102 NTSTATUS result;
103 uint8_t *out_data = NULL;
105 if (argc != 2) {
106 printf("Usage: %s num\n", argv[0]);
107 return NT_STATUS_OK;
110 size = atoi(argv[1]);
111 if ( (out_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
112 printf("Failure to allocate buff of %d bytes\n",
113 size);
114 goto done;
118 result = rpccli_echo_SourceData(cli, mem_ctx, size, out_data);
120 if (!NT_STATUS_IS_OK(result))
121 goto done;
123 for (i = 0; i < size; i++) {
124 if (out_data && out_data[i] != (i & 0xff)) {
125 printf("mismatch at offset %d, %d != %d\n",
126 i, out_data[i], i & 0xff);
127 result = NT_STATUS_UNSUCCESSFUL;
131 done:
132 return result;
135 static NTSTATUS cmd_echo_sink_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
136 int argc, const char **argv)
138 uint32 size, i;
139 NTSTATUS result;
140 uint8_t *in_data = NULL;
142 if (argc != 2) {
143 printf("Usage: %s num\n", argv[0]);
144 return NT_STATUS_OK;
147 size = atoi(argv[1]);
148 if ( (in_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
149 printf("Failure to allocate buff of %d bytes\n",
150 size);
151 goto done;
154 for (i = 0; i < size; i++)
155 in_data[i] = i & 0xff;
157 result = rpccli_echo_SinkData(cli, mem_ctx, size, in_data);
159 if (!NT_STATUS_IS_OK(result))
160 goto done;
162 done:
163 SAFE_FREE(in_data);
165 return result;
168 /* List of commands exported by this module */
170 struct cmd_set echo_commands[] = {
172 { "ECHO" },
174 { "echoaddone", RPC_RTYPE_NTSTATUS, cmd_echo_add_one, NULL, PI_RPCECHO, NULL, "Add one to a number", "" },
175 { "echodata", RPC_RTYPE_NTSTATUS, cmd_echo_data, NULL, PI_RPCECHO, NULL, "Echo data", "" },
176 { "sinkdata", RPC_RTYPE_NTSTATUS, cmd_echo_sink_data, NULL, PI_RPCECHO, NULL, "Sink data", "" },
177 { "sourcedata", RPC_RTYPE_NTSTATUS, cmd_echo_source_data, NULL, PI_RPCECHO, NULL, "Source data", "" },
178 { NULL }