2 Unix SMB/CIFS implementation.
4 Copyright (C) Stefan Metzmacher 2012
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "system/network.h"
22 #include "lib/util/tevent_ntstatus.h"
23 #include "smb_common.h"
24 #include "smbXcli_base.h"
26 struct smb1cli_echo_state
{
32 static void smb1cli_echo_done(struct tevent_req
*subreq
);
34 struct tevent_req
*smb1cli_echo_send(TALLOC_CTX
*mem_ctx
,
35 struct tevent_context
*ev
,
36 struct smbXcli_conn
*conn
,
37 uint32_t timeout_msec
,
41 struct tevent_req
*req
, *subreq
;
42 struct smb1cli_echo_state
*state
;
44 req
= tevent_req_create(mem_ctx
, &state
, struct smb1cli_echo_state
);
48 SSVAL(state
->vwv
, 0, num_echos
);
50 state
->num_echos
= num_echos
;
52 subreq
= smb1cli_req_send(state
, ev
, conn
, SMBecho
,
59 ARRAY_SIZE(state
->vwv
), state
->vwv
,
60 data
.length
, data
.data
);
64 tevent_req_set_callback(subreq
, smb1cli_echo_done
, req
);
71 static void smb1cli_echo_done(struct tevent_req
*subreq
)
73 struct tevent_req
*req
= tevent_req_callback_data(
74 subreq
, struct tevent_req
);
75 struct smb1cli_echo_state
*state
= tevent_req_data(
76 req
, struct smb1cli_echo_state
);
80 struct iovec
*recv_iov
;
81 struct smb1cli_req_expected_response expected
[] = {
83 .status
= NT_STATUS_OK
,
88 status
= smb1cli_req_recv(subreq
, state
,
93 NULL
, /* pvwv_offset */
96 NULL
, /* pbytes_offset */
98 expected
, ARRAY_SIZE(expected
));
100 if (!NT_STATUS_IS_OK(status
)) {
101 tevent_req_nterror(req
, status
);
105 if (num_bytes
!= state
->data
.length
) {
106 tevent_req_nterror(req
, NT_STATUS_INVALID_NETWORK_RESPONSE
);
110 if (memcmp(bytes
, state
->data
.data
, num_bytes
) != 0) {
111 tevent_req_nterror(req
, NT_STATUS_INVALID_NETWORK_RESPONSE
);
115 /* TODO: do we want to verify the sequence number? */
117 state
->num_echos
-=1;
118 if (state
->num_echos
== 0) {
119 tevent_req_done(req
);
123 if (!smbXcli_req_set_pending(subreq
)) {
124 tevent_req_nterror(req
, NT_STATUS_NO_MEMORY
);
130 * Get the result out from an echo request
131 * @param[in] req The async_req from smb1cli_echo_send
132 * @retval Did the server reply correctly?
135 NTSTATUS
smb1cli_echo_recv(struct tevent_req
*req
)
137 return tevent_req_simple_recv_ntstatus(req
);
140 NTSTATUS
smb1cli_echo(struct smbXcli_conn
*conn
, uint32_t timeout_msec
,
141 uint16_t num_echos
, DATA_BLOB data
)
143 TALLOC_CTX
*frame
= talloc_stackframe();
144 struct tevent_context
*ev
;
145 struct tevent_req
*req
;
146 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
148 if (smbXcli_conn_has_async_calls(conn
)) {
150 * Can't use sync call while an async call is in flight
152 status
= NT_STATUS_INVALID_PARAMETER
;
155 ev
= tevent_context_init(frame
);
159 req
= smb1cli_echo_send(frame
, ev
, conn
, timeout_msec
, num_echos
, data
);
163 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
166 status
= smb1cli_echo_recv(req
);