r5657: Fix uninitialized variable warning
[Samba.git] / source / rpc_client / cli_echo.c
blobcd7e21f918f2e0e7d3ae32455759c025234f4171
1 /*
2 Unix SMB/CIFS implementation.
4 RPC pipe client
6 Copyright (C) Tim Potter 2003
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "includes.h"
25 NTSTATUS cli_echo_add_one(struct cli_state *cli, TALLOC_CTX *mem_ctx,
26 uint32 request, uint32 *response)
28 prs_struct qbuf, rbuf;
29 ECHO_Q_ADD_ONE q;
30 ECHO_R_ADD_ONE r;
31 BOOL result = False;
33 ZERO_STRUCT(q);
34 ZERO_STRUCT(r);
36 /* Initialise parse structures */
38 if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) {
39 return NT_STATUS_NO_MEMORY;
41 if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) {
42 prs_mem_free(&qbuf);
43 return NT_STATUS_NO_MEMORY;
46 /* Marshall data and send request */
48 init_echo_q_add_one(&q, request);
50 if (!echo_io_q_add_one("", &q, &qbuf, 0) ||
51 !rpc_api_pipe_req(cli, PI_ECHO, ECHO_ADD_ONE, &qbuf, &rbuf))
52 goto done;
54 /* Unmarshall response */
56 if (!echo_io_r_add_one("", &r, &rbuf, 0))
57 goto done;
59 if (response)
60 *response = r.response;
62 result = True;
64 done:
65 prs_mem_free(&qbuf);
66 prs_mem_free(&rbuf);
68 return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
71 NTSTATUS cli_echo_data(struct cli_state *cli, TALLOC_CTX *mem_ctx,
72 uint32 size, char *in_data, char **out_data)
74 prs_struct qbuf, rbuf;
75 ECHO_Q_ECHO_DATA q;
76 ECHO_R_ECHO_DATA r;
77 BOOL result = False;
79 ZERO_STRUCT(q);
80 ZERO_STRUCT(r);
82 /* Initialise parse structures */
84 if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) {
85 return NT_STATUS_NO_MEMORY;
87 if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) {
88 prs_mem_free(&qbuf);
89 return NT_STATUS_NO_MEMORY;
92 /* Marshall data and send request */
94 init_echo_q_echo_data(&q, size, in_data);
96 if (!echo_io_q_echo_data("", &q, &qbuf, 0) ||
97 !rpc_api_pipe_req(cli, PI_ECHO, ECHO_DATA, &qbuf, &rbuf))
98 goto done;
100 /* Unmarshall response */
102 if (!echo_io_r_echo_data("", &r, &rbuf, 0))
103 goto done;
105 result = True;
107 if (out_data) {
108 *out_data = TALLOC(mem_ctx, size);
109 memcpy(*out_data, r.data, size);
112 done:
113 prs_mem_free(&qbuf);
114 prs_mem_free(&rbuf);
116 return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
119 NTSTATUS cli_echo_sink_data(struct cli_state *cli, TALLOC_CTX *mem_ctx,
120 uint32 size, char *in_data)
122 prs_struct qbuf, rbuf;
123 ECHO_Q_SINK_DATA q;
124 ECHO_R_SINK_DATA r;
125 BOOL result = False;
127 ZERO_STRUCT(q);
128 ZERO_STRUCT(r);
130 /* Initialise parse structures */
132 if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) {
133 return NT_STATUS_NO_MEMORY;
135 if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) {
136 prs_mem_free(&qbuf);
137 return NT_STATUS_NO_MEMORY;
140 /* Marshall data and send request */
142 init_echo_q_sink_data(&q, size, in_data);
144 if (!echo_io_q_sink_data("", &q, &qbuf, 0) ||
145 !rpc_api_pipe_req(cli, PI_ECHO, ECHO_SINK_DATA, &qbuf, &rbuf)) {
146 goto done;
149 /* Unmarshall response */
151 if (!echo_io_r_sink_data("", &r, &rbuf, 0)) {
152 goto done;
155 result = True;
157 done:
158 prs_mem_free(&qbuf);
159 prs_mem_free(&rbuf);
161 return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
164 NTSTATUS cli_echo_source_data(struct cli_state *cli, TALLOC_CTX *mem_ctx,
165 uint32 size, char **out_data)
167 prs_struct qbuf, rbuf;
168 ECHO_Q_SOURCE_DATA q;
169 ECHO_R_SOURCE_DATA r;
170 BOOL result = False;
172 ZERO_STRUCT(q);
173 ZERO_STRUCT(r);
175 /* Initialise parse structures */
177 if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) {
178 return NT_STATUS_NO_MEMORY;
180 if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) {
181 prs_mem_free(&qbuf);
182 return NT_STATUS_NO_MEMORY;
185 /* Marshall data and send request */
187 init_echo_q_source_data(&q, size);
189 if (!echo_io_q_source_data("", &q, &qbuf, 0) ||
190 !rpc_api_pipe_req(cli, PI_ECHO, ECHO_SOURCE_DATA, &qbuf, &rbuf)) {
191 goto done;
194 /* Unmarshall response */
196 if (!echo_io_r_source_data("", &r, &rbuf, 0)) {
197 goto done;
200 result = True;
202 done:
203 prs_mem_free(&qbuf);
204 prs_mem_free(&rbuf);
206 return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;