1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/*
Unix SMB/CIFS implementation.
RPC pipe client
Copyright (C) Tim Potter 2003
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "rpcclient.h"
static NTSTATUS cmd_echo_add_one(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
uint32 request = 1, response;
NTSTATUS result;
if (argc > 2) {
printf("Usage: %s [num]\n", argv[0]);
return NT_STATUS_OK;
}
if (argc == 2)
request = atoi(argv[1]);
result = rpccli_echo_AddOne(cli, mem_ctx, request, &response);
if (!NT_STATUS_IS_OK(result))
goto done;
printf("%d + 1 = %d\n", request, response);
done:
return result;
}
static NTSTATUS cmd_echo_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
uint32 size, i;
NTSTATUS result;
uint8_t *in_data = NULL, *out_data = NULL;
if (argc != 2) {
printf("Usage: %s num\n", argv[0]);
return NT_STATUS_OK;
}
size = atoi(argv[1]);
if ( (in_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
printf("Failure to allocate buff of %d bytes\n",
size);
goto done;
}
if ( (out_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
printf("Failure to allocate buff of %d bytes\n",
size);
goto done;
}
for (i = 0; i < size; i++)
in_data[i] = i & 0xff;
result = rpccli_echo_EchoData(cli, mem_ctx, size, in_data, out_data);
if (!NT_STATUS_IS_OK(result))
goto done;
for (i = 0; i < size; i++) {
if (in_data[i] != out_data[i]) {
printf("mismatch at offset %d, %d != %d\n",
i, in_data[i], out_data[i]);
result = NT_STATUS_UNSUCCESSFUL;
}
}
done:
SAFE_FREE(in_data);
SAFE_FREE(out_data);
return result;
}
static NTSTATUS cmd_echo_source_data(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
uint32 size, i;
NTSTATUS result;
uint8_t *out_data = NULL;
if (argc != 2) {
printf("Usage: %s num\n", argv[0]);
return NT_STATUS_OK;
}
size = atoi(argv[1]);
if ( (out_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
printf("Failure to allocate buff of %d bytes\n",
size);
goto done;
}
result = rpccli_echo_SourceData(cli, mem_ctx, size, out_data);
if (!NT_STATUS_IS_OK(result))
goto done;
for (i = 0; i < size; i++) {
if (out_data && out_data[i] != (i & 0xff)) {
printf("mismatch at offset %d, %d != %d\n",
i, out_data[i], i & 0xff);
result = NT_STATUS_UNSUCCESSFUL;
}
}
done:
return result;
}
static NTSTATUS cmd_echo_sink_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
uint32 size, i;
NTSTATUS result;
uint8_t *in_data = NULL;
if (argc != 2) {
printf("Usage: %s num\n", argv[0]);
return NT_STATUS_OK;
}
size = atoi(argv[1]);
if ( (in_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
printf("Failure to allocate buff of %d bytes\n",
size);
goto done;
}
for (i = 0; i < size; i++)
in_data[i] = i & 0xff;
result = rpccli_echo_SinkData(cli, mem_ctx, size, in_data);
if (!NT_STATUS_IS_OK(result))
goto done;
done:
SAFE_FREE(in_data);
return result;
}
/* List of commands exported by this module */
struct cmd_set echo_commands[] = {
{ "ECHO" },
{ "echoaddone", RPC_RTYPE_NTSTATUS, cmd_echo_add_one, NULL, PI_RPCECHO, NULL, "Add one to a number", "" },
{ "echodata", RPC_RTYPE_NTSTATUS, cmd_echo_data, NULL, PI_RPCECHO, NULL, "Echo data", "" },
{ "sinkdata", RPC_RTYPE_NTSTATUS, cmd_echo_sink_data, NULL, PI_RPCECHO, NULL, "Sink data", "" },
{ "sourcedata", RPC_RTYPE_NTSTATUS, cmd_echo_source_data, NULL, PI_RPCECHO, NULL, "Source data", "" },
{ NULL }
};
|