source: branches/samba-3.3.x/source/rpcclient/cmd_echo.c

Last change on this file was 206, checked in by Herwig Bauernfeind, 16 years ago

Import Samba 3.3 branch at 3.0.0 level (psmedley's port)

File size: 4.4 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
4
5 Copyright (C) Tim Potter 2003
6
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.
11
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.
16
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/>.
19*/
20
21#include "includes.h"
22#include "rpcclient.h"
23
24static NTSTATUS cmd_echo_add_one(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
25 int argc, const char **argv)
26{
27 uint32 request = 1, response;
28 NTSTATUS result;
29
30 if (argc > 2) {
31 printf("Usage: %s [num]\n", argv[0]);
32 return NT_STATUS_OK;
33 }
34
35 if (argc == 2)
36 request = atoi(argv[1]);
37
38 result = rpccli_echo_AddOne(cli, mem_ctx, request, &response);
39
40 if (!NT_STATUS_IS_OK(result))
41 goto done;
42
43 printf("%d + 1 = %d\n", request, response);
44
45done:
46 return result;
47}
48
49static NTSTATUS cmd_echo_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
50 int argc, const char **argv)
51{
52 uint32 size, i;
53 NTSTATUS result;
54 uint8_t *in_data = NULL, *out_data = NULL;
55
56 if (argc != 2) {
57 printf("Usage: %s num\n", argv[0]);
58 return NT_STATUS_OK;
59 }
60
61 size = atoi(argv[1]);
62 if ( (in_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
63 printf("Failure to allocate buff of %d bytes\n",
64 size);
65 result = NT_STATUS_NO_MEMORY;
66 goto done;
67 }
68 if ( (out_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
69 printf("Failure to allocate buff of %d bytes\n",
70 size);
71 result = NT_STATUS_NO_MEMORY;
72 goto done;
73 }
74
75 for (i = 0; i < size; i++)
76 in_data[i] = i & 0xff;
77
78 result = rpccli_echo_EchoData(cli, mem_ctx, size, in_data, out_data);
79
80 if (!NT_STATUS_IS_OK(result))
81 goto done;
82
83 for (i = 0; i < size; i++) {
84 if (in_data[i] != out_data[i]) {
85 printf("mismatch at offset %d, %d != %d\n",
86 i, in_data[i], out_data[i]);
87 result = NT_STATUS_UNSUCCESSFUL;
88 }
89 }
90
91done:
92 SAFE_FREE(in_data);
93 SAFE_FREE(out_data);
94
95 return result;
96}
97
98static NTSTATUS cmd_echo_source_data(struct rpc_pipe_client *cli,
99 TALLOC_CTX *mem_ctx, int argc,
100 const char **argv)
101{
102 uint32 size, i;
103 NTSTATUS result;
104 uint8_t *out_data = NULL;
105
106 if (argc != 2) {
107 printf("Usage: %s num\n", argv[0]);
108 return NT_STATUS_OK;
109 }
110
111 size = atoi(argv[1]);
112 if ( (out_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
113 printf("Failure to allocate buff of %d bytes\n",
114 size);
115 result = NT_STATUS_NO_MEMORY;
116 goto done;
117 }
118
119
120 result = rpccli_echo_SourceData(cli, mem_ctx, size, out_data);
121
122 if (!NT_STATUS_IS_OK(result))
123 goto done;
124
125 for (i = 0; i < size; i++) {
126 if (out_data && out_data[i] != (i & 0xff)) {
127 printf("mismatch at offset %d, %d != %d\n",
128 i, out_data[i], i & 0xff);
129 result = NT_STATUS_UNSUCCESSFUL;
130 }
131 }
132
133done:
134
135 SAFE_FREE(out_data);
136 return result;
137}
138
139static NTSTATUS cmd_echo_sink_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
140 int argc, const char **argv)
141{
142 uint32 size, i;
143 NTSTATUS result;
144 uint8_t *in_data = NULL;
145
146 if (argc != 2) {
147 printf("Usage: %s num\n", argv[0]);
148 return NT_STATUS_OK;
149 }
150
151 size = atoi(argv[1]);
152 if ( (in_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
153 printf("Failure to allocate buff of %d bytes\n",
154 size);
155 result = NT_STATUS_NO_MEMORY;
156 goto done;
157 }
158
159 for (i = 0; i < size; i++)
160 in_data[i] = i & 0xff;
161
162 result = rpccli_echo_SinkData(cli, mem_ctx, size, in_data);
163
164 if (!NT_STATUS_IS_OK(result))
165 goto done;
166
167done:
168 SAFE_FREE(in_data);
169
170 return result;
171}
172
173/* List of commands exported by this module */
174
175struct cmd_set echo_commands[] = {
176
177 { "ECHO" },
178
179 { "echoaddone", RPC_RTYPE_NTSTATUS, cmd_echo_add_one, NULL, &ndr_table_rpcecho.syntax_id, NULL, "Add one to a number", "" },
180 { "echodata", RPC_RTYPE_NTSTATUS, cmd_echo_data, NULL, &ndr_table_rpcecho.syntax_id, NULL, "Echo data", "" },
181 { "sinkdata", RPC_RTYPE_NTSTATUS, cmd_echo_sink_data, NULL, &ndr_table_rpcecho.syntax_id, NULL, "Sink data", "" },
182 { "sourcedata", RPC_RTYPE_NTSTATUS, cmd_echo_source_data, NULL, &ndr_table_rpcecho.syntax_id, NULL, "Source data", "" },
183 { NULL }
184};
Note: See TracBrowser for help on using the repository browser.