2 Unix SMB/CIFS implementation.
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/>.
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
;
33 printf("Usage: %s [num]\n", argv
[0]);
38 request
= atoi(argv
[1]);
41 status
= dcerpc_echo_AddOne(b
, mem_ctx
, request
, &response
);
42 if (!NT_STATUS_IS_OK(status
)) {
46 printf("%d + 1 = %d\n", request
, response
);
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
;
58 uint8_t *in_data
= NULL
, *out_data
= NULL
;
61 printf("Usage: %s num\n", argv
[0]);
66 if ( (in_data
= (uint8_t*)SMB_MALLOC(size
)) == NULL
) {
67 printf("Failure to allocate buff of %d bytes\n",
69 status
= NT_STATUS_NO_MEMORY
;
72 if ( (out_data
= (uint8_t*)SMB_MALLOC(size
)) == NULL
) {
73 printf("Failure to allocate buff of %d bytes\n",
75 status
= NT_STATUS_NO_MEMORY
;
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
)) {
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
;
103 static NTSTATUS
cmd_echo_source_data(struct rpc_pipe_client
*cli
,
104 TALLOC_CTX
*mem_ctx
, int argc
,
107 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
110 uint8_t *out_data
= NULL
;
113 printf("Usage: %s num\n", argv
[0]);
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",
121 status
= NT_STATUS_NO_MEMORY
;
126 status
= dcerpc_echo_SourceData(b
, mem_ctx
, size
, out_data
);
127 if (!NT_STATUS_IS_OK(status
)) {
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
;
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
;
151 uint8_t *in_data
= NULL
;
154 printf("Usage: %s num\n", argv
[0]);
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",
162 status
= NT_STATUS_NO_MEMORY
;
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
)) {
181 /* List of commands exported by this module */
183 struct cmd_set echo_commands
[] = {
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", "" },