WHATSNEW: Add release notes for Samba 4.6.13.
[Samba.git] / source3 / rpcclient / cmd_echo.c
blobb6072be079991d8c284e4bb9c4689ef0f502b210
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 3 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, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "rpcclient.h"
23 #include "../librpc/gen_ndr/ndr_echo_c.h"
25 static NTSTATUS cmd_echo_add_one(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
26 int argc, const char **argv)
28 struct dcerpc_binding_handle *b = cli->binding_handle;
29 uint32_t request = 1, response;
30 NTSTATUS status;
32 if (argc > 2) {
33 printf("Usage: %s [num]\n", argv[0]);
34 return NT_STATUS_OK;
37 if (argc == 2) {
38 request = atoi(argv[1]);
41 status = dcerpc_echo_AddOne(b, mem_ctx, request, &response);
42 if (!NT_STATUS_IS_OK(status)) {
43 goto done;
46 printf("%d + 1 = %d\n", request, response);
48 done:
49 return status;
52 static NTSTATUS cmd_echo_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
53 int argc, const char **argv)
55 struct dcerpc_binding_handle *b = cli->binding_handle;
56 uint32_t size, i;
57 NTSTATUS status;
58 uint8_t *in_data = NULL, *out_data = NULL;
60 if (argc != 2) {
61 printf("Usage: %s num\n", argv[0]);
62 return NT_STATUS_OK;
65 size = atoi(argv[1]);
66 if ( (in_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
67 printf("Failure to allocate buff of %d bytes\n",
68 size);
69 status = NT_STATUS_NO_MEMORY;
70 goto done;
72 if ( (out_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
73 printf("Failure to allocate buff of %d bytes\n",
74 size);
75 status = NT_STATUS_NO_MEMORY;
76 goto done;
79 for (i = 0; i < size; i++) {
80 in_data[i] = i & 0xff;
83 status = dcerpc_echo_EchoData(b, mem_ctx, size, in_data, out_data);
84 if (!NT_STATUS_IS_OK(status)) {
85 goto done;
88 for (i = 0; i < size; i++) {
89 if (in_data[i] != out_data[i]) {
90 printf("mismatch at offset %d, %d != %d\n",
91 i, in_data[i], out_data[i]);
92 status = NT_STATUS_UNSUCCESSFUL;
96 done:
97 SAFE_FREE(in_data);
98 SAFE_FREE(out_data);
100 return status;
103 static NTSTATUS cmd_echo_source_data(struct rpc_pipe_client *cli,
104 TALLOC_CTX *mem_ctx, int argc,
105 const char **argv)
107 struct dcerpc_binding_handle *b = cli->binding_handle;
108 uint32_t size, i;
109 NTSTATUS status;
110 uint8_t *out_data = NULL;
112 if (argc != 2) {
113 printf("Usage: %s num\n", argv[0]);
114 return NT_STATUS_OK;
117 size = atoi(argv[1]);
118 if ( (out_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
119 printf("Failure to allocate buff of %d bytes\n",
120 size);
121 status = NT_STATUS_NO_MEMORY;
122 goto done;
126 status = dcerpc_echo_SourceData(b, mem_ctx, size, out_data);
127 if (!NT_STATUS_IS_OK(status)) {
128 goto done;
131 for (i = 0; i < size; i++) {
132 if (out_data && out_data[i] != (i & 0xff)) {
133 printf("mismatch at offset %d, %d != %d\n",
134 i, out_data[i], i & 0xff);
135 status = NT_STATUS_UNSUCCESSFUL;
139 done:
141 SAFE_FREE(out_data);
142 return status;
145 static NTSTATUS cmd_echo_sink_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
146 int argc, const char **argv)
148 struct dcerpc_binding_handle *b = cli->binding_handle;
149 uint32_t size, i;
150 NTSTATUS status;
151 uint8_t *in_data = NULL;
153 if (argc != 2) {
154 printf("Usage: %s num\n", argv[0]);
155 return NT_STATUS_OK;
158 size = atoi(argv[1]);
159 if ( (in_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
160 printf("Failure to allocate buff of %d bytes\n",
161 size);
162 status = NT_STATUS_NO_MEMORY;
163 goto done;
166 for (i = 0; i < size; i++) {
167 in_data[i] = i & 0xff;
170 status = dcerpc_echo_SinkData(b, mem_ctx, size, in_data);
171 if (!NT_STATUS_IS_OK(status)) {
172 goto done;
175 done:
176 SAFE_FREE(in_data);
178 return status;
181 /* List of commands exported by this module */
183 struct cmd_set echo_commands[] = {
185 { "ECHO" },
187 { "echoaddone", RPC_RTYPE_NTSTATUS, cmd_echo_add_one, NULL, &ndr_table_rpcecho, NULL, "Add one to a number", "" },
188 { "echodata", RPC_RTYPE_NTSTATUS, cmd_echo_data, NULL, &ndr_table_rpcecho, NULL, "Echo data", "" },
189 { "sinkdata", RPC_RTYPE_NTSTATUS, cmd_echo_sink_data, NULL, &ndr_table_rpcecho, NULL, "Sink data", "" },
190 { "sourcedata", RPC_RTYPE_NTSTATUS, cmd_echo_source_data, NULL, &ndr_table_rpcecho, NULL, "Source data", "" },
191 { NULL }