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
));
99 if (!NT_STATUS_IS_OK(status
)) {
100 tevent_req_nterror(req
, status
);
104 if (num_bytes
!= state
->data
.length
) {
105 tevent_req_nterror(req
, NT_STATUS_INVALID_NETWORK_RESPONSE
);
109 if (memcmp(bytes
, state
->data
.data
, num_bytes
) != 0) {
110 tevent_req_nterror(req
, NT_STATUS_INVALID_NETWORK_RESPONSE
);
114 /* TODO: do we want to verify the sequence number? */
116 state
->num_echos
-=1;
117 if (state
->num_echos
== 0) {
118 tevent_req_done(req
);
122 if (!smbXcli_req_set_pending(subreq
)) {
123 tevent_req_nterror(req
, NT_STATUS_NO_MEMORY
);
129 * Get the result out from an echo request
130 * @param[in] req The async_req from smb1cli_echo_send
131 * @retval Did the server reply correctly?
134 NTSTATUS
smb1cli_echo_recv(struct tevent_req
*req
)
136 return tevent_req_simple_recv_ntstatus(req
);
139 NTSTATUS
smb1cli_echo(struct smbXcli_conn
*conn
, uint32_t timeout_msec
,
140 uint16_t num_echos
, DATA_BLOB data
)
142 TALLOC_CTX
*frame
= talloc_stackframe();
143 struct tevent_context
*ev
;
144 struct tevent_req
*req
;
145 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
147 if (smbXcli_conn_has_async_calls(conn
)) {
149 * Can't use sync call while an async call is in flight
151 status
= NT_STATUS_INVALID_PARAMETER
;
154 ev
= samba_tevent_context_init(frame
);
158 req
= smb1cli_echo_send(frame
, ev
, conn
, timeout_msec
, num_echos
, data
);
162 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
165 status
= smb1cli_echo_recv(req
);