Make 3.0.x in sync with 3.2 here.
[Samba.git] / source / rpc_client / cli_echo.c
blob9818fad79b512161c5606f9c10f79e3da791bfda
1 /*
2 Unix SMB/CIFS implementation.
4 RPC pipe client
6 Copyright (C) Tim Potter 2003
7 Copyright (C) Jeremy Allison 2005.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "includes.h"
26 NTSTATUS rpccli_echo_add_one(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
27 uint32 request, uint32 *response)
29 prs_struct qbuf, rbuf;
30 ECHO_Q_ADD_ONE q;
31 ECHO_R_ADD_ONE r;
32 BOOL result = False;
34 ZERO_STRUCT(q);
35 ZERO_STRUCT(r);
37 /* Marshall data and send request */
39 init_echo_q_add_one(&q, request);
41 CLI_DO_RPC( cli, mem_ctx, PI_ECHO, ECHO_ADD_ONE,
42 q, r,
43 qbuf, rbuf,
44 echo_io_q_add_one,
45 echo_io_r_add_one,
46 NT_STATUS_UNSUCCESSFUL);
48 if (response)
49 *response = r.response;
51 result = True;
53 return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
56 NTSTATUS rpccli_echo_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
57 uint32 size, char *in_data, char **out_data)
59 prs_struct qbuf, rbuf;
60 ECHO_Q_ECHO_DATA q;
61 ECHO_R_ECHO_DATA r;
62 BOOL result = False;
64 ZERO_STRUCT(q);
65 ZERO_STRUCT(r);
67 /* Marshall data and send request */
69 init_echo_q_echo_data(&q, size, in_data);
71 CLI_DO_RPC( cli, mem_ctx, PI_ECHO, ECHO_DATA,
72 q, r,
73 qbuf, rbuf,
74 echo_io_q_echo_data,
75 echo_io_r_echo_data,
76 NT_STATUS_UNSUCCESSFUL);
78 result = True;
80 if (out_data) {
81 *out_data = TALLOC(mem_ctx, size);
82 if (!*out_data) {
83 return NT_STATUS_NO_MEMORY;
85 memcpy(*out_data, r.data, size);
88 return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
91 NTSTATUS rpccli_echo_sink_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
92 uint32 size, char *in_data)
94 prs_struct qbuf, rbuf;
95 ECHO_Q_SINK_DATA q;
96 ECHO_R_SINK_DATA r;
97 BOOL result = False;
99 ZERO_STRUCT(q);
100 ZERO_STRUCT(r);
102 /* Marshall data and send request */
104 init_echo_q_sink_data(&q, size, in_data);
106 CLI_DO_RPC( cli, mem_ctx, PI_ECHO, ECHO_SINK_DATA,
107 q, r,
108 qbuf, rbuf,
109 echo_io_q_sink_data,
110 echo_io_r_sink_data,
111 NT_STATUS_UNSUCCESSFUL);
113 result = True;
115 return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
118 NTSTATUS rpccli_echo_source_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
119 uint32 size, char **out_data)
121 prs_struct qbuf, rbuf;
122 ECHO_Q_SOURCE_DATA q;
123 ECHO_R_SOURCE_DATA r;
124 BOOL result = False;
126 ZERO_STRUCT(q);
127 ZERO_STRUCT(r);
129 /* Marshall data and send request */
131 init_echo_q_source_data(&q, size);
133 CLI_DO_RPC( cli, mem_ctx, PI_ECHO, ECHO_SOURCE_DATA,
134 q, r,
135 qbuf, rbuf,
136 echo_io_q_source_data,
137 echo_io_r_source_data,
138 NT_STATUS_UNSUCCESSFUL);
140 result = True;
142 return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;