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 "smb2cli_base.h"
25 #include "libsmb/proto.h"
26 #include "lib/util/tevent_ntstatus.h"
28 struct smb2cli_query_directory_state {
31 struct iovec *recv_iov;
36 static void smb2cli_query_directory_done(struct tevent_req *subreq);
38 struct tevent_req *smb2cli_query_directory_send(TALLOC_CTX *mem_ctx,
39 struct tevent_context *ev,
40 struct cli_state *cli,
44 uint64_t fid_persistent,
45 uint64_t fid_volatile,
49 struct tevent_req *req, *subreq;
50 struct smb2cli_query_directory_state *state;
55 req = tevent_req_create(mem_ctx, &state,
56 struct smb2cli_query_directory_state);
61 if (!convert_string_talloc(state, CH_UNIX, CH_UTF16,
65 return tevent_req_post(req, ev);
70 SCVAL(fixed, 2, level);
71 SCVAL(fixed, 3, flags);
72 SIVAL(fixed, 4, file_index);
73 SBVAL(fixed, 8, fid_persistent);
74 SBVAL(fixed, 16, fid_volatile);
75 SSVAL(fixed, 24, SMB2_HDR_BODY + 32);
76 SSVAL(fixed, 26, dyn_len);
77 SSVAL(fixed, 28, outbuf_len);
81 dyn_len = sizeof(state->dyn_pad);
84 subreq = smb2cli_req_send(state, ev, cli, SMB2_OP_FIND,
89 state->fixed, sizeof(state->fixed),
91 if (tevent_req_nomem(subreq, req)) {
92 return tevent_req_post(req, ev);
94 tevent_req_set_callback(subreq, smb2cli_query_directory_done, req);
98 static void smb2cli_query_directory_done(struct tevent_req *subreq)
100 struct tevent_req *req =
101 tevent_req_callback_data(subreq,
103 struct smb2cli_query_directory_state *state =
105 struct smb2cli_query_directory_state);
108 uint16_t data_offset;
110 status = smb2cli_req_recv(subreq, state, &iov, 9);
111 if (tevent_req_nterror(req, status)) {
115 data_offset = SVAL(iov[1].iov_base, 2);
116 state->data_length = IVAL(iov[1].iov_base, 4);
118 if ((data_offset != SMB2_HDR_BODY + 8) ||
119 (state->data_length > iov[2].iov_len)) {
120 tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
124 state->recv_iov = iov;
125 state->data = (uint8_t *)iov[2].iov_base;
126 tevent_req_done(req);
129 NTSTATUS smb2cli_query_directory_recv(struct tevent_req *req,
132 uint32_t *data_length)
134 struct smb2cli_query_directory_state *state =
136 struct smb2cli_query_directory_state);
139 if (tevent_req_is_nterror(req, &status)) {
142 talloc_steal(mem_ctx, state->recv_iov);
143 *data_length = state->data_length;
148 NTSTATUS smb2cli_query_directory(struct cli_state *cli,
152 uint64_t fid_persistent,
153 uint64_t fid_volatile,
158 uint32_t *data_length)
160 TALLOC_CTX *frame = talloc_stackframe();
161 struct event_context *ev;
162 struct tevent_req *req;
163 NTSTATUS status = NT_STATUS_NO_MEMORY;
165 if (cli_has_async_calls(cli)) {
167 * Can't use sync call while an async call is in flight
169 status = NT_STATUS_INVALID_PARAMETER;
172 ev = event_context_init(frame);
176 req = smb2cli_query_directory_send(frame, ev, cli, level, flags,
177 file_index, fid_persistent,
178 fid_volatile, mask, outbuf_len);
182 if (!tevent_req_poll_ntstatus(req, ev, &status)) {
185 status = smb2cli_query_directory_recv(req, mem_ctx,