2 Unix SMB/CIFS implementation.
4 Copyright (C) Volker Lendecke 2011
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/>.
22 #include "async_smb.h"
23 #include "../libcli/smb/smbXcli_base.h"
25 #include "libsmb/proto.h"
26 #include "lib/util/tevent_ntstatus.h"
28 struct smb2cli_write_state {
33 static void smb2cli_write_done(struct tevent_req *subreq);
35 struct tevent_req *smb2cli_write_send(TALLOC_CTX *mem_ctx,
36 struct tevent_context *ev,
37 struct smbXcli_conn *conn,
38 uint32_t timeout_msec,
39 struct smbXcli_session *session,
43 uint64_t fid_persistent,
44 uint64_t fid_volatile,
45 uint32_t remaining_bytes,
49 struct tevent_req *req, *subreq;
50 struct smb2cli_write_state *state;
55 req = tevent_req_create(mem_ctx, &state,
56 struct smb2cli_write_state);
64 SSVAL(fixed, 2, SMB2_HDR_BODY + 48);
65 SIVAL(fixed, 4, length);
66 SBVAL(fixed, 8, offset);
67 SBVAL(fixed, 16, fid_persistent);
68 SBVAL(fixed, 24, fid_volatile);
69 SIVAL(fixed, 36, remaining_bytes);
70 SIVAL(fixed, 44, flags);
76 dyn = state->dyn_pad;;
77 dyn_len = sizeof(state->dyn_pad);
80 subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_WRITE,
86 state->fixed, sizeof(state->fixed),
88 if (tevent_req_nomem(subreq, req)) {
89 return tevent_req_post(req, ev);
91 tevent_req_set_callback(subreq, smb2cli_write_done, req);
95 static void smb2cli_write_done(struct tevent_req *subreq)
97 struct tevent_req *req =
98 tevent_req_callback_data(subreq,
101 static const struct smb2cli_req_expected_response expected[] = {
103 .status = NT_STATUS_OK,
108 status = smb2cli_req_recv(subreq, NULL, NULL,
109 expected, ARRAY_SIZE(expected));
110 if (tevent_req_nterror(req, status)) {
113 tevent_req_done(req);
116 NTSTATUS smb2cli_write_recv(struct tevent_req *req)
118 return tevent_req_simple_recv_ntstatus(req);
121 NTSTATUS smb2cli_write(struct smbXcli_conn *conn,
122 uint32_t timeout_msec,
123 struct smbXcli_session *session,
127 uint64_t fid_persistent,
128 uint64_t fid_volatile,
129 uint32_t remaining_bytes,
133 TALLOC_CTX *frame = talloc_stackframe();
134 struct event_context *ev;
135 struct tevent_req *req;
136 NTSTATUS status = NT_STATUS_NO_MEMORY;
138 if (smbXcli_conn_has_async_calls(conn)) {
140 * Can't use sync call while an async call is in flight
142 status = NT_STATUS_INVALID_PARAMETER;
145 ev = event_context_init(frame);
149 req = smb2cli_write_send(frame, ev, conn, timeout_msec, session,
150 tcon_id, length, offset,
151 fid_persistent, fid_volatile,
152 remaining_bytes, flags, data);
156 if (!tevent_req_poll_ntstatus(req, ev, &status)) {
159 status = smb2cli_write_recv(req);