1/* 2 Unix SMB/CIFS implementation. 3 4 RPC pipe client 5 6 Copyright (C) Tim Potter 2003 7 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. 12 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. 17 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. 21*/ 22 23#include "includes.h" 24 25NTSTATUS cli_echo_add_one(struct cli_state *cli, TALLOC_CTX *mem_ctx, 26 uint32 request, uint32 *response) 27{ 28 prs_struct qbuf, rbuf; 29 ECHO_Q_ADD_ONE q; 30 ECHO_R_ADD_ONE r; 31 BOOL result = False; 32 33 ZERO_STRUCT(q); 34 ZERO_STRUCT(r); 35 36 /* Initialise parse structures */ 37 38 if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) { 39 return NT_STATUS_NO_MEMORY; 40 } 41 if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) { 42 prs_mem_free(&qbuf); 43 return NT_STATUS_NO_MEMORY; 44 } 45 46 /* Marshall data and send request */ 47 48 init_echo_q_add_one(&q, request); 49 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; 53 54 /* Unmarshall response */ 55 56 if (!echo_io_r_add_one("", &r, &rbuf, 0)) 57 goto done; 58 59 if (response) 60 *response = r.response; 61 62 result = True; 63 64 done: 65 prs_mem_free(&qbuf); 66 prs_mem_free(&rbuf); 67 68 return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; 69} 70 71NTSTATUS cli_echo_data(struct cli_state *cli, TALLOC_CTX *mem_ctx, 72 uint32 size, char *in_data, char **out_data) 73{ 74 prs_struct qbuf, rbuf; 75 ECHO_Q_ECHO_DATA q; 76 ECHO_R_ECHO_DATA r; 77 BOOL result = False; 78 79 ZERO_STRUCT(q); 80 ZERO_STRUCT(r); 81 82 /* Initialise parse structures */ 83 84 if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) { 85 return NT_STATUS_NO_MEMORY; 86 } 87 if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) { 88 prs_mem_free(&qbuf); 89 return NT_STATUS_NO_MEMORY; 90 } 91 92 /* Marshall data and send request */ 93 94 init_echo_q_echo_data(&q, size, in_data); 95 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; 99 100 /* Unmarshall response */ 101 102 if (!echo_io_r_echo_data("", &r, &rbuf, 0)) 103 goto done; 104 105 result = True; 106 107 if (out_data) { 108 *out_data = TALLOC(mem_ctx, size); 109 memcpy(*out_data, r.data, size); 110 } 111 112 done: 113 prs_mem_free(&qbuf); 114 prs_mem_free(&rbuf); 115 116 return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; 117} 118 119NTSTATUS cli_echo_sink_data(struct cli_state *cli, TALLOC_CTX *mem_ctx, 120 uint32 size, char *in_data) 121{ 122 prs_struct qbuf, rbuf; 123 ECHO_Q_SINK_DATA q; 124 ECHO_R_SINK_DATA r; 125 BOOL result = False; 126 127 ZERO_STRUCT(q); 128 ZERO_STRUCT(r); 129 130 /* Initialise parse structures */ 131 132 if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) { 133 return NT_STATUS_NO_MEMORY; 134 } 135 if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) { 136 prs_mem_free(&qbuf); 137 return NT_STATUS_NO_MEMORY; 138 } 139 140 /* Marshall data and send request */ 141 142 init_echo_q_sink_data(&q, size, in_data); 143 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; 147 } 148 149 /* Unmarshall response */ 150 151 if (!echo_io_r_sink_data("", &r, &rbuf, 0)) { 152 goto done; 153 } 154 155 result = True; 156 157 done: 158 prs_mem_free(&qbuf); 159 prs_mem_free(&rbuf); 160 161 return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; 162} 163 164NTSTATUS cli_echo_source_data(struct cli_state *cli, TALLOC_CTX *mem_ctx, 165 uint32 size, char **out_data) 166{ 167 prs_struct qbuf, rbuf; 168 ECHO_Q_SOURCE_DATA q; 169 ECHO_R_SOURCE_DATA r; 170 BOOL result = False; 171 172 ZERO_STRUCT(q); 173 ZERO_STRUCT(r); 174 175 /* Initialise parse structures */ 176 177 if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) { 178 return NT_STATUS_NO_MEMORY; 179 } 180 if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) { 181 prs_mem_free(&qbuf); 182 return NT_STATUS_NO_MEMORY; 183 } 184 185 /* Marshall data and send request */ 186 187 init_echo_q_source_data(&q, size); 188 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; 192 } 193 194 /* Unmarshall response */ 195 196 if (!echo_io_r_source_data("", &r, &rbuf, 0)) { 197 goto done; 198 } 199 200 result = True; 201 202 done: 203 prs_mem_free(&qbuf); 204 prs_mem_free(&rbuf); 205 206 return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; 207} 208