1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 | transaction2 handling
|
---|
4 | Copyright (C) Andrew Tridgell 2003
|
---|
5 | Copyright Matthieu Patou 2010 mat@matws.net
|
---|
6 |
|
---|
7 | This program is free software; you can redistribute it and/or modify
|
---|
8 | it under the terms of the GNU General Public License as published by
|
---|
9 | the Free Software Foundation; either version 3 of the License, or
|
---|
10 | (at your option) any later version.
|
---|
11 |
|
---|
12 | This program is distributed in the hope that it will be useful,
|
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | GNU General Public License for more details.
|
---|
16 |
|
---|
17 | You should have received a copy of the GNU General Public License
|
---|
18 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | /*
|
---|
21 | This file handles the parsing of transact2 requests
|
---|
22 | */
|
---|
23 |
|
---|
24 | #include "includes.h"
|
---|
25 | #include "smbd/service_stream.h"
|
---|
26 | #include "smb_server/smb_server.h"
|
---|
27 | #include "ntvfs/ntvfs.h"
|
---|
28 | #include "libcli/raw/libcliraw.h"
|
---|
29 | #include "libcli/raw/raw_proto.h"
|
---|
30 | #include "librpc/gen_ndr/dfsblobs.h"
|
---|
31 | #include "librpc/gen_ndr/ndr_dfsblobs.h"
|
---|
32 | #include "dsdb/samdb/samdb.h"
|
---|
33 | #include "auth/session.h"
|
---|
34 | #include "param/param.h"
|
---|
35 | #include "lib/tsocket/tsocket.h"
|
---|
36 |
|
---|
37 | #define MAX_DFS_RESPONSE 56*1024 /* 56 Kb */
|
---|
38 |
|
---|
39 | #define TRANS2_CHECK_ASYNC_STATUS_SIMPLE do { \
|
---|
40 | if (!NT_STATUS_IS_OK(req->ntvfs->async_states->status)) { \
|
---|
41 | trans2_setup_reply(trans, 0, 0, 0);\
|
---|
42 | return req->ntvfs->async_states->status; \
|
---|
43 | } \
|
---|
44 | } while (0)
|
---|
45 | #define TRANS2_CHECK_ASYNC_STATUS(ptr, type) do { \
|
---|
46 | TRANS2_CHECK_ASYNC_STATUS_SIMPLE; \
|
---|
47 | ptr = talloc_get_type(op->op_info, type); \
|
---|
48 | } while (0)
|
---|
49 | #define TRANS2_CHECK(cmd) do { \
|
---|
50 | NTSTATUS _status; \
|
---|
51 | _status = cmd; \
|
---|
52 | NT_STATUS_NOT_OK_RETURN(_status); \
|
---|
53 | } while (0)
|
---|
54 |
|
---|
55 | /*
|
---|
56 | hold the state of a nttrans op while in progress. Needed to allow for async backend
|
---|
57 | functions.
|
---|
58 | */
|
---|
59 | struct trans_op {
|
---|
60 | struct smbsrv_request *req;
|
---|
61 | struct smb_trans2 *trans;
|
---|
62 | uint8_t command;
|
---|
63 | NTSTATUS (*send_fn)(struct trans_op *);
|
---|
64 | void *op_info;
|
---|
65 | };
|
---|
66 | /* A DC set is a group of DC, they might have been grouped together
|
---|
67 | because they belong to the same site, or to site with same cost ...
|
---|
68 | */
|
---|
69 | struct dc_set {
|
---|
70 | const char **names;
|
---|
71 | uint32_t count;
|
---|
72 | };
|
---|
73 | #define CHECK_MIN_BLOB_SIZE(blob, size) do { \
|
---|
74 | if ((blob)->length < (size)) { \
|
---|
75 | return NT_STATUS_INFO_LENGTH_MISMATCH; \
|
---|
76 | }} while (0)
|
---|
77 |
|
---|
78 | /* setup a trans2 reply, given the data and params sizes */
|
---|
79 | static NTSTATUS trans2_setup_reply(struct smb_trans2 *trans,
|
---|
80 | uint16_t param_size, uint16_t data_size,
|
---|
81 | uint8_t setup_count)
|
---|
82 | {
|
---|
83 | trans->out.setup_count = setup_count;
|
---|
84 | if (setup_count > 0) {
|
---|
85 | trans->out.setup = talloc_zero_array(trans, uint16_t, setup_count);
|
---|
86 | NT_STATUS_HAVE_NO_MEMORY(trans->out.setup);
|
---|
87 | }
|
---|
88 | trans->out.params = data_blob_talloc(trans, NULL, param_size);
|
---|
89 | if (param_size > 0) NT_STATUS_HAVE_NO_MEMORY(trans->out.params.data);
|
---|
90 |
|
---|
91 | trans->out.data = data_blob_talloc(trans, NULL, data_size);
|
---|
92 | if (data_size > 0) NT_STATUS_HAVE_NO_MEMORY(trans->out.data.data);
|
---|
93 |
|
---|
94 | return NT_STATUS_OK;
|
---|
95 | }
|
---|
96 |
|
---|
97 | static NTSTATUS trans2_push_fsinfo(struct smbsrv_connection *smb_conn,
|
---|
98 | TALLOC_CTX *mem_ctx,
|
---|
99 | DATA_BLOB *blob,
|
---|
100 | union smb_fsinfo *fsinfo,
|
---|
101 | int default_str_flags)
|
---|
102 | {
|
---|
103 | enum smb_fsinfo_level passthru_level;
|
---|
104 |
|
---|
105 | switch (fsinfo->generic.level) {
|
---|
106 | case RAW_QFS_ALLOCATION:
|
---|
107 | TRANS2_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 18));
|
---|
108 |
|
---|
109 | SIVAL(blob->data, 0, fsinfo->allocation.out.fs_id);
|
---|
110 | SIVAL(blob->data, 4, fsinfo->allocation.out.sectors_per_unit);
|
---|
111 | SIVAL(blob->data, 8, fsinfo->allocation.out.total_alloc_units);
|
---|
112 | SIVAL(blob->data, 12, fsinfo->allocation.out.avail_alloc_units);
|
---|
113 | SSVAL(blob->data, 16, fsinfo->allocation.out.bytes_per_sector);
|
---|
114 |
|
---|
115 | return NT_STATUS_OK;
|
---|
116 |
|
---|
117 | case RAW_QFS_VOLUME:
|
---|
118 | TRANS2_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 5));
|
---|
119 |
|
---|
120 | SIVAL(blob->data, 0, fsinfo->volume.out.serial_number);
|
---|
121 | /* w2k3 implements this incorrectly for unicode - it
|
---|
122 | * leaves the last byte off the string */
|
---|
123 | TRANS2_CHECK(smbsrv_blob_append_string(mem_ctx, blob,
|
---|
124 | fsinfo->volume.out.volume_name.s,
|
---|
125 | 4, default_str_flags,
|
---|
126 | STR_LEN8BIT|STR_NOALIGN));
|
---|
127 |
|
---|
128 | return NT_STATUS_OK;
|
---|
129 |
|
---|
130 | case RAW_QFS_VOLUME_INFO:
|
---|
131 | passthru_level = RAW_QFS_VOLUME_INFORMATION;
|
---|
132 | break;
|
---|
133 |
|
---|
134 | case RAW_QFS_SIZE_INFO:
|
---|
135 | passthru_level = RAW_QFS_SIZE_INFORMATION;
|
---|
136 | break;
|
---|
137 |
|
---|
138 | case RAW_QFS_DEVICE_INFO:
|
---|
139 | passthru_level = RAW_QFS_DEVICE_INFORMATION;
|
---|
140 | break;
|
---|
141 |
|
---|
142 | case RAW_QFS_ATTRIBUTE_INFO:
|
---|
143 | passthru_level = RAW_QFS_ATTRIBUTE_INFORMATION;
|
---|
144 | break;
|
---|
145 |
|
---|
146 | default:
|
---|
147 | passthru_level = fsinfo->generic.level;
|
---|
148 | break;
|
---|
149 | }
|
---|
150 |
|
---|
151 | return smbsrv_push_passthru_fsinfo(mem_ctx, blob,
|
---|
152 | passthru_level, fsinfo,
|
---|
153 | default_str_flags);
|
---|
154 | }
|
---|
155 |
|
---|
156 | /*
|
---|
157 | trans2 qfsinfo implementation send
|
---|
158 | */
|
---|
159 | static NTSTATUS trans2_qfsinfo_send(struct trans_op *op)
|
---|
160 | {
|
---|
161 | struct smbsrv_request *req = op->req;
|
---|
162 | struct smb_trans2 *trans = op->trans;
|
---|
163 | union smb_fsinfo *fsinfo;
|
---|
164 |
|
---|
165 | TRANS2_CHECK_ASYNC_STATUS(fsinfo, union smb_fsinfo);
|
---|
166 |
|
---|
167 | TRANS2_CHECK(trans2_setup_reply(trans, 0, 0, 0));
|
---|
168 |
|
---|
169 | TRANS2_CHECK(trans2_push_fsinfo(req->smb_conn, trans,
|
---|
170 | &trans->out.data, fsinfo,
|
---|
171 | SMBSRV_REQ_DEFAULT_STR_FLAGS(req)));
|
---|
172 |
|
---|
173 | return NT_STATUS_OK;
|
---|
174 | }
|
---|
175 |
|
---|
176 | /*
|
---|
177 | trans2 qfsinfo implementation
|
---|
178 | */
|
---|
179 | static NTSTATUS trans2_qfsinfo(struct smbsrv_request *req, struct trans_op *op)
|
---|
180 | {
|
---|
181 | struct smb_trans2 *trans = op->trans;
|
---|
182 | union smb_fsinfo *fsinfo;
|
---|
183 | uint16_t level;
|
---|
184 |
|
---|
185 | /* make sure we got enough parameters */
|
---|
186 | if (trans->in.params.length != 2) {
|
---|
187 | return NT_STATUS_FOOBAR;
|
---|
188 | }
|
---|
189 |
|
---|
190 | fsinfo = talloc(op, union smb_fsinfo);
|
---|
191 | NT_STATUS_HAVE_NO_MEMORY(fsinfo);
|
---|
192 |
|
---|
193 | level = SVAL(trans->in.params.data, 0);
|
---|
194 |
|
---|
195 | /* work out the backend level - we make it 1-1 in the header */
|
---|
196 | fsinfo->generic.level = (enum smb_fsinfo_level)level;
|
---|
197 | if (fsinfo->generic.level >= RAW_QFS_GENERIC) {
|
---|
198 | return NT_STATUS_INVALID_LEVEL;
|
---|
199 | }
|
---|
200 |
|
---|
201 | op->op_info = fsinfo;
|
---|
202 | op->send_fn = trans2_qfsinfo_send;
|
---|
203 |
|
---|
204 | return ntvfs_fsinfo(req->ntvfs, fsinfo);
|
---|
205 | }
|
---|
206 |
|
---|
207 |
|
---|
208 | /*
|
---|
209 | trans2 open implementation send
|
---|
210 | */
|
---|
211 | static NTSTATUS trans2_open_send(struct trans_op *op)
|
---|
212 | {
|
---|
213 | struct smbsrv_request *req = op->req;
|
---|
214 | struct smb_trans2 *trans = op->trans;
|
---|
215 | union smb_open *io;
|
---|
216 |
|
---|
217 | TRANS2_CHECK_ASYNC_STATUS(io, union smb_open);
|
---|
218 |
|
---|
219 | TRANS2_CHECK(trans2_setup_reply(trans, 30, 0, 0));
|
---|
220 |
|
---|
221 | smbsrv_push_fnum(trans->out.params.data, VWV(0), io->t2open.out.file.ntvfs);
|
---|
222 | SSVAL(trans->out.params.data, VWV(1), io->t2open.out.attrib);
|
---|
223 | srv_push_dos_date3(req->smb_conn, trans->out.params.data,
|
---|
224 | VWV(2), io->t2open.out.write_time);
|
---|
225 | SIVAL(trans->out.params.data, VWV(4), io->t2open.out.size);
|
---|
226 | SSVAL(trans->out.params.data, VWV(6), io->t2open.out.access);
|
---|
227 | SSVAL(trans->out.params.data, VWV(7), io->t2open.out.ftype);
|
---|
228 | SSVAL(trans->out.params.data, VWV(8), io->t2open.out.devstate);
|
---|
229 | SSVAL(trans->out.params.data, VWV(9), io->t2open.out.action);
|
---|
230 | SIVAL(trans->out.params.data, VWV(10), 0); /* reserved */
|
---|
231 | SSVAL(trans->out.params.data, VWV(12), 0); /* EaErrorOffset */
|
---|
232 | SIVAL(trans->out.params.data, VWV(13), 0); /* EaLength */
|
---|
233 |
|
---|
234 | return NT_STATUS_OK;
|
---|
235 | }
|
---|
236 |
|
---|
237 | /*
|
---|
238 | trans2 open implementation
|
---|
239 | */
|
---|
240 | static NTSTATUS trans2_open(struct smbsrv_request *req, struct trans_op *op)
|
---|
241 | {
|
---|
242 | struct smb_trans2 *trans = op->trans;
|
---|
243 | union smb_open *io;
|
---|
244 |
|
---|
245 | /* make sure we got enough parameters */
|
---|
246 | if (trans->in.params.length < 29) {
|
---|
247 | return NT_STATUS_FOOBAR;
|
---|
248 | }
|
---|
249 |
|
---|
250 | io = talloc(op, union smb_open);
|
---|
251 | NT_STATUS_HAVE_NO_MEMORY(io);
|
---|
252 |
|
---|
253 | io->t2open.level = RAW_OPEN_T2OPEN;
|
---|
254 | io->t2open.in.flags = SVAL(trans->in.params.data, VWV(0));
|
---|
255 | io->t2open.in.open_mode = SVAL(trans->in.params.data, VWV(1));
|
---|
256 | io->t2open.in.search_attrs = SVAL(trans->in.params.data, VWV(2));
|
---|
257 | io->t2open.in.file_attrs = SVAL(trans->in.params.data, VWV(3));
|
---|
258 | io->t2open.in.write_time = srv_pull_dos_date(req->smb_conn,
|
---|
259 | trans->in.params.data + VWV(4));
|
---|
260 | io->t2open.in.open_func = SVAL(trans->in.params.data, VWV(6));
|
---|
261 | io->t2open.in.size = IVAL(trans->in.params.data, VWV(7));
|
---|
262 | io->t2open.in.timeout = IVAL(trans->in.params.data, VWV(9));
|
---|
263 | io->t2open.in.num_eas = 0;
|
---|
264 | io->t2open.in.eas = NULL;
|
---|
265 |
|
---|
266 | smbsrv_blob_pull_string(&req->in.bufinfo, &trans->in.params, 28, &io->t2open.in.fname, 0);
|
---|
267 | if (io->t2open.in.fname == NULL) {
|
---|
268 | return NT_STATUS_FOOBAR;
|
---|
269 | }
|
---|
270 |
|
---|
271 | TRANS2_CHECK(ea_pull_list(&trans->in.data, io, &io->t2open.in.num_eas, &io->t2open.in.eas));
|
---|
272 |
|
---|
273 | op->op_info = io;
|
---|
274 | op->send_fn = trans2_open_send;
|
---|
275 |
|
---|
276 | return ntvfs_open(req->ntvfs, io);
|
---|
277 | }
|
---|
278 |
|
---|
279 |
|
---|
280 | /*
|
---|
281 | trans2 simple send
|
---|
282 | */
|
---|
283 | static NTSTATUS trans2_simple_send(struct trans_op *op)
|
---|
284 | {
|
---|
285 | struct smbsrv_request *req = op->req;
|
---|
286 | struct smb_trans2 *trans = op->trans;
|
---|
287 |
|
---|
288 | TRANS2_CHECK_ASYNC_STATUS_SIMPLE;
|
---|
289 |
|
---|
290 | TRANS2_CHECK(trans2_setup_reply(trans, 2, 0, 0));
|
---|
291 |
|
---|
292 | SSVAL(trans->out.params.data, VWV(0), 0);
|
---|
293 |
|
---|
294 | return NT_STATUS_OK;
|
---|
295 | }
|
---|
296 |
|
---|
297 | /*
|
---|
298 | trans2 mkdir implementation
|
---|
299 | */
|
---|
300 | static NTSTATUS trans2_mkdir(struct smbsrv_request *req, struct trans_op *op)
|
---|
301 | {
|
---|
302 | struct smb_trans2 *trans = op->trans;
|
---|
303 | union smb_mkdir *io;
|
---|
304 |
|
---|
305 | /* make sure we got enough parameters */
|
---|
306 | if (trans->in.params.length < 5) {
|
---|
307 | return NT_STATUS_FOOBAR;
|
---|
308 | }
|
---|
309 |
|
---|
310 | io = talloc(op, union smb_mkdir);
|
---|
311 | NT_STATUS_HAVE_NO_MEMORY(io);
|
---|
312 |
|
---|
313 | io->t2mkdir.level = RAW_MKDIR_T2MKDIR;
|
---|
314 | smbsrv_blob_pull_string(&req->in.bufinfo, &trans->in.params, 4, &io->t2mkdir.in.path, 0);
|
---|
315 | if (io->t2mkdir.in.path == NULL) {
|
---|
316 | return NT_STATUS_FOOBAR;
|
---|
317 | }
|
---|
318 |
|
---|
319 | TRANS2_CHECK(ea_pull_list(&trans->in.data, io,
|
---|
320 | &io->t2mkdir.in.num_eas,
|
---|
321 | &io->t2mkdir.in.eas));
|
---|
322 |
|
---|
323 | op->op_info = io;
|
---|
324 | op->send_fn = trans2_simple_send;
|
---|
325 |
|
---|
326 | return ntvfs_mkdir(req->ntvfs, io);
|
---|
327 | }
|
---|
328 |
|
---|
329 | static NTSTATUS trans2_push_fileinfo(struct smbsrv_connection *smb_conn,
|
---|
330 | TALLOC_CTX *mem_ctx,
|
---|
331 | DATA_BLOB *blob,
|
---|
332 | union smb_fileinfo *st,
|
---|
333 | int default_str_flags)
|
---|
334 | {
|
---|
335 | uint32_t list_size;
|
---|
336 | enum smb_fileinfo_level passthru_level;
|
---|
337 |
|
---|
338 | switch (st->generic.level) {
|
---|
339 | case RAW_FILEINFO_GENERIC:
|
---|
340 | case RAW_FILEINFO_GETATTR:
|
---|
341 | case RAW_FILEINFO_GETATTRE:
|
---|
342 | case RAW_FILEINFO_SEC_DESC:
|
---|
343 | case RAW_FILEINFO_SMB2_ALL_EAS:
|
---|
344 | case RAW_FILEINFO_SMB2_ALL_INFORMATION:
|
---|
345 | /* handled elsewhere */
|
---|
346 | return NT_STATUS_INVALID_LEVEL;
|
---|
347 |
|
---|
348 | case RAW_FILEINFO_UNIX_BASIC:
|
---|
349 | case RAW_FILEINFO_UNIX_LINK:
|
---|
350 | /* not implemented yet */
|
---|
351 | return NT_STATUS_INVALID_LEVEL;
|
---|
352 |
|
---|
353 | case RAW_FILEINFO_STANDARD:
|
---|
354 | TRANS2_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 22));
|
---|
355 |
|
---|
356 | srv_push_dos_date2(smb_conn, blob->data, 0, st->standard.out.create_time);
|
---|
357 | srv_push_dos_date2(smb_conn, blob->data, 4, st->standard.out.access_time);
|
---|
358 | srv_push_dos_date2(smb_conn, blob->data, 8, st->standard.out.write_time);
|
---|
359 | SIVAL(blob->data, 12, st->standard.out.size);
|
---|
360 | SIVAL(blob->data, 16, st->standard.out.alloc_size);
|
---|
361 | SSVAL(blob->data, 20, st->standard.out.attrib);
|
---|
362 | return NT_STATUS_OK;
|
---|
363 |
|
---|
364 | case RAW_FILEINFO_EA_SIZE:
|
---|
365 | TRANS2_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 26));
|
---|
366 |
|
---|
367 | srv_push_dos_date2(smb_conn, blob->data, 0, st->ea_size.out.create_time);
|
---|
368 | srv_push_dos_date2(smb_conn, blob->data, 4, st->ea_size.out.access_time);
|
---|
369 | srv_push_dos_date2(smb_conn, blob->data, 8, st->ea_size.out.write_time);
|
---|
370 | SIVAL(blob->data, 12, st->ea_size.out.size);
|
---|
371 | SIVAL(blob->data, 16, st->ea_size.out.alloc_size);
|
---|
372 | SSVAL(blob->data, 20, st->ea_size.out.attrib);
|
---|
373 | SIVAL(blob->data, 22, st->ea_size.out.ea_size);
|
---|
374 | return NT_STATUS_OK;
|
---|
375 |
|
---|
376 | case RAW_FILEINFO_EA_LIST:
|
---|
377 | list_size = ea_list_size(st->ea_list.out.num_eas,
|
---|
378 | st->ea_list.out.eas);
|
---|
379 | TRANS2_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, list_size));
|
---|
380 |
|
---|
381 | ea_put_list(blob->data,
|
---|
382 | st->ea_list.out.num_eas, st->ea_list.out.eas);
|
---|
383 | return NT_STATUS_OK;
|
---|
384 |
|
---|
385 | case RAW_FILEINFO_ALL_EAS:
|
---|
386 | list_size = ea_list_size(st->all_eas.out.num_eas,
|
---|
387 | st->all_eas.out.eas);
|
---|
388 | TRANS2_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, list_size));
|
---|
389 |
|
---|
390 | ea_put_list(blob->data,
|
---|
391 | st->all_eas.out.num_eas, st->all_eas.out.eas);
|
---|
392 | return NT_STATUS_OK;
|
---|
393 |
|
---|
394 | case RAW_FILEINFO_IS_NAME_VALID:
|
---|
395 | return NT_STATUS_OK;
|
---|
396 |
|
---|
397 | case RAW_FILEINFO_BASIC_INFO:
|
---|
398 | passthru_level = RAW_FILEINFO_BASIC_INFORMATION;
|
---|
399 | break;
|
---|
400 |
|
---|
401 | case RAW_FILEINFO_STANDARD_INFO:
|
---|
402 | passthru_level = RAW_FILEINFO_STANDARD_INFORMATION;
|
---|
403 | break;
|
---|
404 |
|
---|
405 | case RAW_FILEINFO_EA_INFO:
|
---|
406 | passthru_level = RAW_FILEINFO_EA_INFORMATION;
|
---|
407 | break;
|
---|
408 |
|
---|
409 | case RAW_FILEINFO_COMPRESSION_INFO:
|
---|
410 | passthru_level = RAW_FILEINFO_COMPRESSION_INFORMATION;
|
---|
411 | break;
|
---|
412 |
|
---|
413 | case RAW_FILEINFO_ALL_INFO:
|
---|
414 | passthru_level = RAW_FILEINFO_ALL_INFORMATION;
|
---|
415 | break;
|
---|
416 |
|
---|
417 | case RAW_FILEINFO_NAME_INFO:
|
---|
418 | passthru_level = RAW_FILEINFO_NAME_INFORMATION;
|
---|
419 | break;
|
---|
420 |
|
---|
421 | case RAW_FILEINFO_ALT_NAME_INFO:
|
---|
422 | passthru_level = RAW_FILEINFO_ALT_NAME_INFORMATION;
|
---|
423 | break;
|
---|
424 |
|
---|
425 | case RAW_FILEINFO_STREAM_INFO:
|
---|
426 | passthru_level = RAW_FILEINFO_STREAM_INFORMATION;
|
---|
427 | break;
|
---|
428 |
|
---|
429 | default:
|
---|
430 | passthru_level = st->generic.level;
|
---|
431 | break;
|
---|
432 | }
|
---|
433 |
|
---|
434 | return smbsrv_push_passthru_fileinfo(mem_ctx, blob,
|
---|
435 | passthru_level, st,
|
---|
436 | default_str_flags);
|
---|
437 | }
|
---|
438 |
|
---|
439 | /*
|
---|
440 | fill in the reply from a qpathinfo or qfileinfo call
|
---|
441 | */
|
---|
442 | static NTSTATUS trans2_fileinfo_send(struct trans_op *op)
|
---|
443 | {
|
---|
444 | struct smbsrv_request *req = op->req;
|
---|
445 | struct smb_trans2 *trans = op->trans;
|
---|
446 | union smb_fileinfo *st;
|
---|
447 |
|
---|
448 | TRANS2_CHECK_ASYNC_STATUS(st, union smb_fileinfo);
|
---|
449 |
|
---|
450 | TRANS2_CHECK(trans2_setup_reply(trans, 2, 0, 0));
|
---|
451 | SSVAL(trans->out.params.data, 0, 0);
|
---|
452 |
|
---|
453 | TRANS2_CHECK(trans2_push_fileinfo(req->smb_conn, trans,
|
---|
454 | &trans->out.data, st,
|
---|
455 | SMBSRV_REQ_DEFAULT_STR_FLAGS(req)));
|
---|
456 |
|
---|
457 | return NT_STATUS_OK;
|
---|
458 | }
|
---|
459 |
|
---|
460 | /*
|
---|
461 | trans2 qpathinfo implementation
|
---|
462 | */
|
---|
463 | static NTSTATUS trans2_qpathinfo(struct smbsrv_request *req, struct trans_op *op)
|
---|
464 | {
|
---|
465 | struct smb_trans2 *trans = op->trans;
|
---|
466 | union smb_fileinfo *st;
|
---|
467 | uint16_t level;
|
---|
468 |
|
---|
469 | /* make sure we got enough parameters */
|
---|
470 | if (trans->in.params.length < 2) {
|
---|
471 | return NT_STATUS_FOOBAR;
|
---|
472 | }
|
---|
473 |
|
---|
474 | st = talloc(op, union smb_fileinfo);
|
---|
475 | NT_STATUS_HAVE_NO_MEMORY(st);
|
---|
476 |
|
---|
477 | level = SVAL(trans->in.params.data, 0);
|
---|
478 |
|
---|
479 | smbsrv_blob_pull_string(&req->in.bufinfo, &trans->in.params, 6, &st->generic.in.file.path, 0);
|
---|
480 | if (st->generic.in.file.path == NULL) {
|
---|
481 | return NT_STATUS_FOOBAR;
|
---|
482 | }
|
---|
483 |
|
---|
484 | /* work out the backend level - we make it 1-1 in the header */
|
---|
485 | st->generic.level = (enum smb_fileinfo_level)level;
|
---|
486 | if (st->generic.level >= RAW_FILEINFO_GENERIC) {
|
---|
487 | return NT_STATUS_INVALID_LEVEL;
|
---|
488 | }
|
---|
489 |
|
---|
490 | if (st->generic.level == RAW_FILEINFO_EA_LIST) {
|
---|
491 | TRANS2_CHECK(ea_pull_name_list(&trans->in.data, req,
|
---|
492 | &st->ea_list.in.num_names,
|
---|
493 | &st->ea_list.in.ea_names));
|
---|
494 | }
|
---|
495 |
|
---|
496 | op->op_info = st;
|
---|
497 | op->send_fn = trans2_fileinfo_send;
|
---|
498 |
|
---|
499 | return ntvfs_qpathinfo(req->ntvfs, st);
|
---|
500 | }
|
---|
501 |
|
---|
502 |
|
---|
503 | /*
|
---|
504 | trans2 qpathinfo implementation
|
---|
505 | */
|
---|
506 | static NTSTATUS trans2_qfileinfo(struct smbsrv_request *req, struct trans_op *op)
|
---|
507 | {
|
---|
508 | struct smb_trans2 *trans = op->trans;
|
---|
509 | union smb_fileinfo *st;
|
---|
510 | uint16_t level;
|
---|
511 | struct ntvfs_handle *h;
|
---|
512 |
|
---|
513 | /* make sure we got enough parameters */
|
---|
514 | if (trans->in.params.length < 4) {
|
---|
515 | return NT_STATUS_FOOBAR;
|
---|
516 | }
|
---|
517 |
|
---|
518 | st = talloc(op, union smb_fileinfo);
|
---|
519 | NT_STATUS_HAVE_NO_MEMORY(st);
|
---|
520 |
|
---|
521 | h = smbsrv_pull_fnum(req, trans->in.params.data, 0);
|
---|
522 | level = SVAL(trans->in.params.data, 2);
|
---|
523 |
|
---|
524 | st->generic.in.file.ntvfs = h;
|
---|
525 | /* work out the backend level - we make it 1-1 in the header */
|
---|
526 | st->generic.level = (enum smb_fileinfo_level)level;
|
---|
527 | if (st->generic.level >= RAW_FILEINFO_GENERIC) {
|
---|
528 | return NT_STATUS_INVALID_LEVEL;
|
---|
529 | }
|
---|
530 |
|
---|
531 | if (st->generic.level == RAW_FILEINFO_EA_LIST) {
|
---|
532 | TRANS2_CHECK(ea_pull_name_list(&trans->in.data, req,
|
---|
533 | &st->ea_list.in.num_names,
|
---|
534 | &st->ea_list.in.ea_names));
|
---|
535 | }
|
---|
536 |
|
---|
537 | op->op_info = st;
|
---|
538 | op->send_fn = trans2_fileinfo_send;
|
---|
539 |
|
---|
540 | SMBSRV_CHECK_FILE_HANDLE_NTSTATUS(st->generic.in.file.ntvfs);
|
---|
541 | return ntvfs_qfileinfo(req->ntvfs, st);
|
---|
542 | }
|
---|
543 |
|
---|
544 |
|
---|
545 | /*
|
---|
546 | parse a trans2 setfileinfo/setpathinfo data blob
|
---|
547 | */
|
---|
548 | static NTSTATUS trans2_parse_sfileinfo(struct smbsrv_request *req,
|
---|
549 | union smb_setfileinfo *st,
|
---|
550 | const DATA_BLOB *blob)
|
---|
551 | {
|
---|
552 | enum smb_setfileinfo_level passthru_level;
|
---|
553 |
|
---|
554 | switch (st->generic.level) {
|
---|
555 | case RAW_SFILEINFO_GENERIC:
|
---|
556 | case RAW_SFILEINFO_SETATTR:
|
---|
557 | case RAW_SFILEINFO_SETATTRE:
|
---|
558 | case RAW_SFILEINFO_SEC_DESC:
|
---|
559 | /* handled elsewhere */
|
---|
560 | return NT_STATUS_INVALID_LEVEL;
|
---|
561 |
|
---|
562 | case RAW_SFILEINFO_STANDARD:
|
---|
563 | CHECK_MIN_BLOB_SIZE(blob, 12);
|
---|
564 |
|
---|
565 | st->standard.in.create_time = srv_pull_dos_date2(req->smb_conn, blob->data + 0);
|
---|
566 | st->standard.in.access_time = srv_pull_dos_date2(req->smb_conn, blob->data + 4);
|
---|
567 | st->standard.in.write_time = srv_pull_dos_date2(req->smb_conn, blob->data + 8);
|
---|
568 |
|
---|
569 | return NT_STATUS_OK;
|
---|
570 |
|
---|
571 | case RAW_SFILEINFO_EA_SET:
|
---|
572 | return ea_pull_list(blob, req,
|
---|
573 | &st->ea_set.in.num_eas,
|
---|
574 | &st->ea_set.in.eas);
|
---|
575 |
|
---|
576 | case SMB_SFILEINFO_BASIC_INFO:
|
---|
577 | case SMB_SFILEINFO_BASIC_INFORMATION:
|
---|
578 | passthru_level = SMB_SFILEINFO_BASIC_INFORMATION;
|
---|
579 | break;
|
---|
580 |
|
---|
581 | case SMB_SFILEINFO_DISPOSITION_INFO:
|
---|
582 | case SMB_SFILEINFO_DISPOSITION_INFORMATION:
|
---|
583 | passthru_level = SMB_SFILEINFO_DISPOSITION_INFORMATION;
|
---|
584 | break;
|
---|
585 |
|
---|
586 | case SMB_SFILEINFO_ALLOCATION_INFO:
|
---|
587 | case SMB_SFILEINFO_ALLOCATION_INFORMATION:
|
---|
588 | passthru_level = SMB_SFILEINFO_ALLOCATION_INFORMATION;
|
---|
589 | break;
|
---|
590 |
|
---|
591 | case RAW_SFILEINFO_END_OF_FILE_INFO:
|
---|
592 | case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
|
---|
593 | passthru_level = RAW_SFILEINFO_END_OF_FILE_INFORMATION;
|
---|
594 | break;
|
---|
595 |
|
---|
596 | case RAW_SFILEINFO_RENAME_INFORMATION:
|
---|
597 | case RAW_SFILEINFO_POSITION_INFORMATION:
|
---|
598 | case RAW_SFILEINFO_MODE_INFORMATION:
|
---|
599 | passthru_level = st->generic.level;
|
---|
600 | break;
|
---|
601 |
|
---|
602 | case RAW_SFILEINFO_UNIX_BASIC:
|
---|
603 | case RAW_SFILEINFO_UNIX_LINK:
|
---|
604 | case RAW_SFILEINFO_UNIX_HLINK:
|
---|
605 | case RAW_SFILEINFO_PIPE_INFORMATION:
|
---|
606 | case RAW_SFILEINFO_VALID_DATA_INFORMATION:
|
---|
607 | case RAW_SFILEINFO_SHORT_NAME_INFORMATION:
|
---|
608 | case RAW_SFILEINFO_1025:
|
---|
609 | case RAW_SFILEINFO_1027:
|
---|
610 | case RAW_SFILEINFO_1029:
|
---|
611 | case RAW_SFILEINFO_1030:
|
---|
612 | case RAW_SFILEINFO_1031:
|
---|
613 | case RAW_SFILEINFO_1032:
|
---|
614 | case RAW_SFILEINFO_1036:
|
---|
615 | case RAW_SFILEINFO_1041:
|
---|
616 | case RAW_SFILEINFO_1042:
|
---|
617 | case RAW_SFILEINFO_1043:
|
---|
618 | case RAW_SFILEINFO_1044:
|
---|
619 | return NT_STATUS_INVALID_LEVEL;
|
---|
620 |
|
---|
621 | default:
|
---|
622 | /* we need a default here to cope with invalid values on the wire */
|
---|
623 | return NT_STATUS_INVALID_LEVEL;
|
---|
624 | }
|
---|
625 |
|
---|
626 | return smbsrv_pull_passthru_sfileinfo(st, passthru_level, st,
|
---|
627 | blob, SMBSRV_REQ_DEFAULT_STR_FLAGS(req),
|
---|
628 | &req->in.bufinfo);
|
---|
629 | }
|
---|
630 |
|
---|
631 | /*
|
---|
632 | trans2 setfileinfo implementation
|
---|
633 | */
|
---|
634 | static NTSTATUS trans2_setfileinfo(struct smbsrv_request *req, struct trans_op *op)
|
---|
635 | {
|
---|
636 | struct smb_trans2 *trans = op->trans;
|
---|
637 | union smb_setfileinfo *st;
|
---|
638 | uint16_t level;
|
---|
639 | struct ntvfs_handle *h;
|
---|
640 |
|
---|
641 | /* make sure we got enough parameters */
|
---|
642 | if (trans->in.params.length < 4) {
|
---|
643 | return NT_STATUS_FOOBAR;
|
---|
644 | }
|
---|
645 |
|
---|
646 | st = talloc(op, union smb_setfileinfo);
|
---|
647 | NT_STATUS_HAVE_NO_MEMORY(st);
|
---|
648 |
|
---|
649 | h = smbsrv_pull_fnum(req, trans->in.params.data, 0);
|
---|
650 | level = SVAL(trans->in.params.data, 2);
|
---|
651 |
|
---|
652 | st->generic.in.file.ntvfs = h;
|
---|
653 | /* work out the backend level - we make it 1-1 in the header */
|
---|
654 | st->generic.level = (enum smb_setfileinfo_level)level;
|
---|
655 | if (st->generic.level >= RAW_SFILEINFO_GENERIC) {
|
---|
656 | return NT_STATUS_INVALID_LEVEL;
|
---|
657 | }
|
---|
658 |
|
---|
659 | TRANS2_CHECK(trans2_parse_sfileinfo(req, st, &trans->in.data));
|
---|
660 |
|
---|
661 | op->op_info = st;
|
---|
662 | op->send_fn = trans2_simple_send;
|
---|
663 |
|
---|
664 | SMBSRV_CHECK_FILE_HANDLE_NTSTATUS(st->generic.in.file.ntvfs);
|
---|
665 | return ntvfs_setfileinfo(req->ntvfs, st);
|
---|
666 | }
|
---|
667 |
|
---|
668 | /*
|
---|
669 | trans2 setpathinfo implementation
|
---|
670 | */
|
---|
671 | static NTSTATUS trans2_setpathinfo(struct smbsrv_request *req, struct trans_op *op)
|
---|
672 | {
|
---|
673 | struct smb_trans2 *trans = op->trans;
|
---|
674 | union smb_setfileinfo *st;
|
---|
675 | uint16_t level;
|
---|
676 |
|
---|
677 | /* make sure we got enough parameters */
|
---|
678 | if (trans->in.params.length < 4) {
|
---|
679 | return NT_STATUS_FOOBAR;
|
---|
680 | }
|
---|
681 |
|
---|
682 | st = talloc(op, union smb_setfileinfo);
|
---|
683 | NT_STATUS_HAVE_NO_MEMORY(st);
|
---|
684 |
|
---|
685 | level = SVAL(trans->in.params.data, 0);
|
---|
686 |
|
---|
687 | smbsrv_blob_pull_string(&req->in.bufinfo, &trans->in.params, 6, &st->generic.in.file.path, 0);
|
---|
688 | if (st->generic.in.file.path == NULL) {
|
---|
689 | return NT_STATUS_FOOBAR;
|
---|
690 | }
|
---|
691 |
|
---|
692 | /* work out the backend level - we make it 1-1 in the header */
|
---|
693 | st->generic.level = (enum smb_setfileinfo_level)level;
|
---|
694 | if (st->generic.level >= RAW_SFILEINFO_GENERIC) {
|
---|
695 | return NT_STATUS_INVALID_LEVEL;
|
---|
696 | }
|
---|
697 |
|
---|
698 | TRANS2_CHECK(trans2_parse_sfileinfo(req, st, &trans->in.data));
|
---|
699 |
|
---|
700 | op->op_info = st;
|
---|
701 | op->send_fn = trans2_simple_send;
|
---|
702 |
|
---|
703 | return ntvfs_setpathinfo(req->ntvfs, st);
|
---|
704 | }
|
---|
705 |
|
---|
706 |
|
---|
707 | /* a structure to encapsulate the state information about an in-progress ffirst/fnext operation */
|
---|
708 | struct find_state {
|
---|
709 | struct trans_op *op;
|
---|
710 | void *search;
|
---|
711 | enum smb_search_data_level data_level;
|
---|
712 | uint16_t last_entry_offset;
|
---|
713 | uint16_t flags;
|
---|
714 | };
|
---|
715 |
|
---|
716 | /*
|
---|
717 | fill a single entry in a trans2 find reply
|
---|
718 | */
|
---|
719 | static NTSTATUS find_fill_info(struct find_state *state,
|
---|
720 | const union smb_search_data *file)
|
---|
721 | {
|
---|
722 | struct smbsrv_request *req = state->op->req;
|
---|
723 | struct smb_trans2 *trans = state->op->trans;
|
---|
724 | uint8_t *data;
|
---|
725 | unsigned int ofs = trans->out.data.length;
|
---|
726 | uint32_t ea_size;
|
---|
727 |
|
---|
728 | switch (state->data_level) {
|
---|
729 | case RAW_SEARCH_DATA_GENERIC:
|
---|
730 | case RAW_SEARCH_DATA_SEARCH:
|
---|
731 | /* handled elsewhere */
|
---|
732 | return NT_STATUS_INVALID_LEVEL;
|
---|
733 |
|
---|
734 | case RAW_SEARCH_DATA_STANDARD:
|
---|
735 | if (state->flags & FLAG_TRANS2_FIND_REQUIRE_RESUME) {
|
---|
736 | TRANS2_CHECK(smbsrv_blob_grow_data(trans, &trans->out.data, ofs + 27));
|
---|
737 | SIVAL(trans->out.data.data, ofs, file->standard.resume_key);
|
---|
738 | ofs += 4;
|
---|
739 | } else {
|
---|
740 | TRANS2_CHECK(smbsrv_blob_grow_data(trans, &trans->out.data, ofs + 23));
|
---|
741 | }
|
---|
742 | data = trans->out.data.data + ofs;
|
---|
743 | srv_push_dos_date2(req->smb_conn, data, 0, file->standard.create_time);
|
---|
744 | srv_push_dos_date2(req->smb_conn, data, 4, file->standard.access_time);
|
---|
745 | srv_push_dos_date2(req->smb_conn, data, 8, file->standard.write_time);
|
---|
746 | SIVAL(data, 12, file->standard.size);
|
---|
747 | SIVAL(data, 16, file->standard.alloc_size);
|
---|
748 | SSVAL(data, 20, file->standard.attrib);
|
---|
749 | TRANS2_CHECK(smbsrv_blob_append_string(trans, &trans->out.data, file->standard.name.s,
|
---|
750 | ofs + 22, SMBSRV_REQ_DEFAULT_STR_FLAGS(req),
|
---|
751 | STR_LEN8BIT | STR_TERMINATE | STR_LEN_NOTERM));
|
---|
752 | break;
|
---|
753 |
|
---|
754 | case RAW_SEARCH_DATA_EA_SIZE:
|
---|
755 | if (state->flags & FLAG_TRANS2_FIND_REQUIRE_RESUME) {
|
---|
756 | TRANS2_CHECK(smbsrv_blob_grow_data(trans, &trans->out.data, ofs + 31));
|
---|
757 | SIVAL(trans->out.data.data, ofs, file->ea_size.resume_key);
|
---|
758 | ofs += 4;
|
---|
759 | } else {
|
---|
760 | TRANS2_CHECK(smbsrv_blob_grow_data(trans, &trans->out.data, ofs + 27));
|
---|
761 | }
|
---|
762 | data = trans->out.data.data + ofs;
|
---|
763 | srv_push_dos_date2(req->smb_conn, data, 0, file->ea_size.create_time);
|
---|
764 | srv_push_dos_date2(req->smb_conn, data, 4, file->ea_size.access_time);
|
---|
765 | srv_push_dos_date2(req->smb_conn, data, 8, file->ea_size.write_time);
|
---|
766 | SIVAL(data, 12, file->ea_size.size);
|
---|
767 | SIVAL(data, 16, file->ea_size.alloc_size);
|
---|
768 | SSVAL(data, 20, file->ea_size.attrib);
|
---|
769 | SIVAL(data, 22, file->ea_size.ea_size);
|
---|
770 | TRANS2_CHECK(smbsrv_blob_append_string(trans, &trans->out.data, file->ea_size.name.s,
|
---|
771 | ofs + 26, SMBSRV_REQ_DEFAULT_STR_FLAGS(req),
|
---|
772 | STR_LEN8BIT | STR_NOALIGN));
|
---|
773 | TRANS2_CHECK(smbsrv_blob_fill_data(trans, &trans->out.data, trans->out.data.length + 1));
|
---|
774 | break;
|
---|
775 |
|
---|
776 | case RAW_SEARCH_DATA_EA_LIST:
|
---|
777 | ea_size = ea_list_size(file->ea_list.eas.num_eas, file->ea_list.eas.eas);
|
---|
778 | if (state->flags & FLAG_TRANS2_FIND_REQUIRE_RESUME) {
|
---|
779 | TRANS2_CHECK(smbsrv_blob_grow_data(trans, &trans->out.data, ofs + 27 + ea_size));
|
---|
780 | SIVAL(trans->out.data.data, ofs, file->ea_list.resume_key);
|
---|
781 | ofs += 4;
|
---|
782 | } else {
|
---|
783 | TRANS2_CHECK(smbsrv_blob_grow_data(trans, &trans->out.data, ofs + 23 + ea_size));
|
---|
784 | }
|
---|
785 | data = trans->out.data.data + ofs;
|
---|
786 | srv_push_dos_date2(req->smb_conn, data, 0, file->ea_list.create_time);
|
---|
787 | srv_push_dos_date2(req->smb_conn, data, 4, file->ea_list.access_time);
|
---|
788 | srv_push_dos_date2(req->smb_conn, data, 8, file->ea_list.write_time);
|
---|
789 | SIVAL(data, 12, file->ea_list.size);
|
---|
790 | SIVAL(data, 16, file->ea_list.alloc_size);
|
---|
791 | SSVAL(data, 20, file->ea_list.attrib);
|
---|
792 | ea_put_list(data+22, file->ea_list.eas.num_eas, file->ea_list.eas.eas);
|
---|
793 | TRANS2_CHECK(smbsrv_blob_append_string(trans, &trans->out.data, file->ea_list.name.s,
|
---|
794 | ofs + 22 + ea_size, SMBSRV_REQ_DEFAULT_STR_FLAGS(req),
|
---|
795 | STR_LEN8BIT | STR_NOALIGN));
|
---|
796 | TRANS2_CHECK(smbsrv_blob_fill_data(trans, &trans->out.data, trans->out.data.length + 1));
|
---|
797 | break;
|
---|
798 |
|
---|
799 | case RAW_SEARCH_DATA_DIRECTORY_INFO:
|
---|
800 | case RAW_SEARCH_DATA_FULL_DIRECTORY_INFO:
|
---|
801 | case RAW_SEARCH_DATA_NAME_INFO:
|
---|
802 | case RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO:
|
---|
803 | case RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO:
|
---|
804 | case RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO:
|
---|
805 | return smbsrv_push_passthru_search(trans, &trans->out.data, state->data_level, file,
|
---|
806 | SMBSRV_REQ_DEFAULT_STR_FLAGS(req));
|
---|
807 |
|
---|
808 | case RAW_SEARCH_DATA_UNIX_INFO:
|
---|
809 | case RAW_SEARCH_DATA_UNIX_INFO2:
|
---|
810 | return NT_STATUS_INVALID_LEVEL;
|
---|
811 | }
|
---|
812 |
|
---|
813 | return NT_STATUS_OK;
|
---|
814 | }
|
---|
815 |
|
---|
816 | /* callback function for trans2 findfirst/findnext */
|
---|
817 | static bool find_callback(void *private_data, const union smb_search_data *file)
|
---|
818 | {
|
---|
819 | struct find_state *state = talloc_get_type(private_data, struct find_state);
|
---|
820 | struct smb_trans2 *trans = state->op->trans;
|
---|
821 | unsigned int old_length;
|
---|
822 |
|
---|
823 | old_length = trans->out.data.length;
|
---|
824 |
|
---|
825 | if (!NT_STATUS_IS_OK(find_fill_info(state, file)) ||
|
---|
826 | trans->out.data.length > trans->in.max_data) {
|
---|
827 | /* restore the old length and tell the backend to stop */
|
---|
828 | smbsrv_blob_grow_data(trans, &trans->out.data, old_length);
|
---|
829 | return false;
|
---|
830 | }
|
---|
831 |
|
---|
832 | state->last_entry_offset = old_length;
|
---|
833 | return true;
|
---|
834 | }
|
---|
835 |
|
---|
836 | /*
|
---|
837 | trans2 findfirst send
|
---|
838 | */
|
---|
839 | static NTSTATUS trans2_findfirst_send(struct trans_op *op)
|
---|
840 | {
|
---|
841 | struct smbsrv_request *req = op->req;
|
---|
842 | struct smb_trans2 *trans = op->trans;
|
---|
843 | union smb_search_first *search;
|
---|
844 | struct find_state *state;
|
---|
845 | uint8_t *param;
|
---|
846 |
|
---|
847 | TRANS2_CHECK_ASYNC_STATUS(state, struct find_state);
|
---|
848 | search = talloc_get_type(state->search, union smb_search_first);
|
---|
849 |
|
---|
850 | /* fill in the findfirst reply header */
|
---|
851 | param = trans->out.params.data;
|
---|
852 | SSVAL(param, VWV(0), search->t2ffirst.out.handle);
|
---|
853 | SSVAL(param, VWV(1), search->t2ffirst.out.count);
|
---|
854 | SSVAL(param, VWV(2), search->t2ffirst.out.end_of_search);
|
---|
855 | SSVAL(param, VWV(3), 0);
|
---|
856 | SSVAL(param, VWV(4), state->last_entry_offset);
|
---|
857 |
|
---|
858 | return NT_STATUS_OK;
|
---|
859 | }
|
---|
860 |
|
---|
861 |
|
---|
862 | /*
|
---|
863 | fill a referral type structure
|
---|
864 | */
|
---|
865 | static NTSTATUS fill_normal_dfs_referraltype(struct dfs_referral_type *ref,
|
---|
866 | uint16_t version,
|
---|
867 | const char *dfs_path,
|
---|
868 | const char *server_path, int isfirstoffset)
|
---|
869 | {
|
---|
870 |
|
---|
871 | switch (version) {
|
---|
872 | case 3:
|
---|
873 | ZERO_STRUCTP(ref);
|
---|
874 | ref->version = version;
|
---|
875 | ref->referral.v3.data.server_type = DFS_SERVER_NON_ROOT;
|
---|
876 | /* "normal" referral seems to always include the GUID */
|
---|
877 | ref->referral.v3.size = 34;
|
---|
878 |
|
---|
879 | ref->referral.v3.data.entry_flags = 0;
|
---|
880 | ref->referral.v3.data.ttl = 600; /* As w2k3 */
|
---|
881 | ref->referral.v3.data.referrals.r1.DFS_path = dfs_path;
|
---|
882 | ref->referral.v3.data.referrals.r1.DFS_alt_path = dfs_path;
|
---|
883 | ref->referral.v3.data.referrals.r1.netw_address = server_path;
|
---|
884 | return NT_STATUS_OK;
|
---|
885 | case 4:
|
---|
886 | ZERO_STRUCTP(ref);
|
---|
887 | ref->version = version;
|
---|
888 | ref->referral.v4.server_type = DFS_SERVER_NON_ROOT;
|
---|
889 | /* "normal" referral seems to always include the GUID */
|
---|
890 | ref->referral.v4.size = 34;
|
---|
891 |
|
---|
892 | if (isfirstoffset) {
|
---|
893 | ref->referral.v4.entry_flags = DFS_HEADER_FLAG_TARGET_BCK;
|
---|
894 | }
|
---|
895 | ref->referral.v4.ttl = 600; /* As w2k3 */
|
---|
896 | ref->referral.v4.r1.DFS_path = dfs_path;
|
---|
897 | ref->referral.v4.r1.DFS_alt_path = dfs_path;
|
---|
898 | ref->referral.v4.r1.netw_address = server_path;
|
---|
899 |
|
---|
900 | return NT_STATUS_OK;
|
---|
901 | }
|
---|
902 | return NT_STATUS_INVALID_LEVEL;
|
---|
903 | }
|
---|
904 |
|
---|
905 | /*
|
---|
906 | fill a domain refererral
|
---|
907 | */
|
---|
908 | static NTSTATUS fill_domain_dfs_referraltype(struct dfs_referral_type *ref,
|
---|
909 | uint16_t version,
|
---|
910 | const char *domain,
|
---|
911 | const char **names,
|
---|
912 | uint16_t numnames)
|
---|
913 | {
|
---|
914 | switch (version) {
|
---|
915 | case 3:
|
---|
916 | ZERO_STRUCTP(ref);
|
---|
917 | ref->version = version;
|
---|
918 | ref->referral.v3.data.server_type = DFS_SERVER_NON_ROOT;
|
---|
919 | /* It's hard coded ... don't think it's a good way but the sizeof return not the
|
---|
920 | * correct values
|
---|
921 | *
|
---|
922 | * We have 18 if the GUID is not included 34 otherwise
|
---|
923 | */
|
---|
924 | ref->referral.v3.size = 18;
|
---|
925 | ref->referral.v3.data.entry_flags = DFS_FLAG_REFERRAL_DOMAIN_RESP;
|
---|
926 | ref->referral.v3.data.ttl = 600; /* As w2k3 */
|
---|
927 | ref->referral.v3.data.referrals.r2.special_name = domain;
|
---|
928 | ref->referral.v3.data.referrals.r2.nb_expanded_names = numnames;
|
---|
929 | /* Put the final terminator */
|
---|
930 | if (names) {
|
---|
931 | const char **names2 = talloc_array(ref, const char *, numnames+1);
|
---|
932 | NT_STATUS_HAVE_NO_MEMORY(names2);
|
---|
933 | int i;
|
---|
934 | for (i = 0; i<numnames; i++) {
|
---|
935 | names2[i] = talloc_asprintf(names2, "\\%s", names[i]);
|
---|
936 | NT_STATUS_HAVE_NO_MEMORY(names2[i]);
|
---|
937 | }
|
---|
938 | names2[numnames] = 0;
|
---|
939 | ref->referral.v3.data.referrals.r2.expanded_names = names2;
|
---|
940 | }
|
---|
941 | return NT_STATUS_OK;
|
---|
942 | }
|
---|
943 | return NT_STATUS_INVALID_LEVEL;
|
---|
944 | }
|
---|
945 |
|
---|
946 | /*
|
---|
947 | get the DCs list within a site
|
---|
948 | */
|
---|
949 | static NTSTATUS get_dcs_insite(TALLOC_CTX *ctx, struct ldb_context *ldb,
|
---|
950 | struct ldb_dn *sitedn, struct dc_set *list,
|
---|
951 | bool dofqdn)
|
---|
952 | {
|
---|
953 | static const char *attrs[] = { "serverReference", NULL };
|
---|
954 | static const char *attrs2[] = { "dNSHostName", "sAMAccountName", NULL };
|
---|
955 | struct ldb_result *r;
|
---|
956 | unsigned int i;
|
---|
957 | int ret;
|
---|
958 | const char **dc_list;
|
---|
959 |
|
---|
960 | ret = ldb_search(ldb, ctx, &r, sitedn, LDB_SCOPE_SUBTREE, attrs,
|
---|
961 | "(&(objectClass=server)(serverReference=*))");
|
---|
962 | if (ret != LDB_SUCCESS) {
|
---|
963 | DEBUG(2,(__location__ ": Failed to get list of servers - %s\n",
|
---|
964 | ldb_errstring(ldb)));
|
---|
965 | return NT_STATUS_INTERNAL_ERROR;
|
---|
966 | }
|
---|
967 |
|
---|
968 | if (r->count == 0) {
|
---|
969 | /* none in this site */
|
---|
970 | talloc_free(r);
|
---|
971 | return NT_STATUS_OK;
|
---|
972 | }
|
---|
973 |
|
---|
974 | /*
|
---|
975 | * need to search for all server object to know the size of the array.
|
---|
976 | * Search all the object of class server in this site
|
---|
977 | */
|
---|
978 | dc_list = talloc_array(r, const char *, r->count);
|
---|
979 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(dc_list, r);
|
---|
980 |
|
---|
981 | /* TODO put some random here in the order */
|
---|
982 | list->names = talloc_realloc(list, list->names, const char *, list->count + r->count);
|
---|
983 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(list->names, r);
|
---|
984 |
|
---|
985 | for (i = 0; i<r->count; i++) {
|
---|
986 | struct ldb_dn *dn;
|
---|
987 | struct ldb_result *r2;
|
---|
988 |
|
---|
989 | dn = ldb_msg_find_attr_as_dn(ldb, ctx, r->msgs[i], "serverReference");
|
---|
990 | if (!dn) {
|
---|
991 | return NT_STATUS_INTERNAL_ERROR;
|
---|
992 | }
|
---|
993 |
|
---|
994 | ret = ldb_search(ldb, r, &r2, dn, LDB_SCOPE_BASE, attrs2, "(objectClass=computer)");
|
---|
995 | if (ret != LDB_SUCCESS) {
|
---|
996 | DEBUG(2,(__location__ ": Search for computer on %s failed - %s\n",
|
---|
997 | ldb_dn_get_linearized(dn), ldb_errstring(ldb)));
|
---|
998 | return NT_STATUS_INTERNAL_ERROR;
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | if (dofqdn) {
|
---|
1002 | const char *dns = ldb_msg_find_attr_as_string(r2->msgs[0], "dNSHostName", NULL);
|
---|
1003 | if (dns == NULL) {
|
---|
1004 | DEBUG(2,(__location__ ": dNSHostName missing on %s\n",
|
---|
1005 | ldb_dn_get_linearized(dn)));
|
---|
1006 | talloc_free(r);
|
---|
1007 | return NT_STATUS_INTERNAL_ERROR;
|
---|
1008 | }
|
---|
1009 |
|
---|
1010 | list->names[list->count] = talloc_strdup(list->names, dns);
|
---|
1011 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(list->names[list->count], r);
|
---|
1012 | } else {
|
---|
1013 | char *tmp;
|
---|
1014 | const char *acct = ldb_msg_find_attr_as_string(r2->msgs[0], "sAMAccountName", NULL);
|
---|
1015 | if (acct == NULL) {
|
---|
1016 | DEBUG(2,(__location__ ": sAMAccountName missing on %s\n",
|
---|
1017 | ldb_dn_get_linearized(dn)));
|
---|
1018 | talloc_free(r);
|
---|
1019 | return NT_STATUS_INTERNAL_ERROR;
|
---|
1020 | }
|
---|
1021 |
|
---|
1022 | tmp = talloc_strdup(list->names, acct);
|
---|
1023 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(tmp, r);
|
---|
1024 |
|
---|
1025 | /* Netbios name is also the sAMAccountName for
|
---|
1026 | computer but without the final $ */
|
---|
1027 | tmp[strlen(tmp) - 1] = '\0';
|
---|
1028 | list->names[list->count] = tmp;
|
---|
1029 | }
|
---|
1030 | list->count++;
|
---|
1031 | talloc_free(r2);
|
---|
1032 | }
|
---|
1033 |
|
---|
1034 | talloc_free(r);
|
---|
1035 | return NT_STATUS_OK;
|
---|
1036 | }
|
---|
1037 |
|
---|
1038 |
|
---|
1039 | /*
|
---|
1040 | get all DCs
|
---|
1041 | */
|
---|
1042 | static NTSTATUS get_dcs(TALLOC_CTX *ctx, struct ldb_context *ldb,
|
---|
1043 | const char *searched_site, bool need_fqdn,
|
---|
1044 | struct dc_set ***pset_list, uint32_t flags)
|
---|
1045 | {
|
---|
1046 | /*
|
---|
1047 | * Flags will be used later to indicate things like least-expensive
|
---|
1048 | * or same-site options
|
---|
1049 | */
|
---|
1050 | const char *attrs_none[] = { NULL };
|
---|
1051 | const char *attrs3[] = { "name", NULL };
|
---|
1052 | struct ldb_dn *configdn, *sitedn, *dn, *sitescontainerdn;
|
---|
1053 | struct ldb_result *r;
|
---|
1054 | struct dc_set **set_list = NULL;
|
---|
1055 | uint32_t i;
|
---|
1056 | int ret;
|
---|
1057 | uint32_t current_pos = 0;
|
---|
1058 | NTSTATUS status;
|
---|
1059 | TALLOC_CTX *subctx = talloc_new(ctx);
|
---|
1060 |
|
---|
1061 | *pset_list = set_list = NULL;
|
---|
1062 |
|
---|
1063 | subctx = talloc_new(ctx);
|
---|
1064 | NT_STATUS_HAVE_NO_MEMORY(subctx);
|
---|
1065 |
|
---|
1066 | configdn = ldb_get_config_basedn(ldb);
|
---|
1067 |
|
---|
1068 | /* Let's search for the Site container */
|
---|
1069 | ret = ldb_search(ldb, subctx, &r, configdn, LDB_SCOPE_SUBTREE, attrs_none,
|
---|
1070 | "(objectClass=sitesContainer)");
|
---|
1071 | if (ret != LDB_SUCCESS) {
|
---|
1072 | DEBUG(2,(__location__ ": Failed to find sitesContainer within %s - %s\n",
|
---|
1073 | ldb_dn_get_linearized(configdn), ldb_errstring(ldb)));
|
---|
1074 | talloc_free(subctx);
|
---|
1075 | return NT_STATUS_INTERNAL_ERROR;
|
---|
1076 | }
|
---|
1077 | if (r->count > 1) {
|
---|
1078 | DEBUG(2,(__location__ ": Expected 1 sitesContainer - found %u within %s\n",
|
---|
1079 | r->count, ldb_dn_get_linearized(configdn)));
|
---|
1080 | talloc_free(subctx);
|
---|
1081 | return NT_STATUS_INTERNAL_ERROR;
|
---|
1082 | }
|
---|
1083 |
|
---|
1084 | sitescontainerdn = talloc_steal(subctx, r->msgs[0]->dn);
|
---|
1085 | talloc_free(r);
|
---|
1086 |
|
---|
1087 | /*
|
---|
1088 | * TODO: Here we should have a more subtle handling
|
---|
1089 | * for the case "same-site"
|
---|
1090 | */
|
---|
1091 | ret = ldb_search(ldb, subctx, &r, sitescontainerdn, LDB_SCOPE_SUBTREE,
|
---|
1092 | attrs_none, "(objectClass=server)");
|
---|
1093 | if (ret != LDB_SUCCESS) {
|
---|
1094 | DEBUG(2,(__location__ ": Failed to find servers within %s - %s\n",
|
---|
1095 | ldb_dn_get_linearized(sitescontainerdn), ldb_errstring(ldb)));
|
---|
1096 | talloc_free(subctx);
|
---|
1097 | return NT_STATUS_INTERNAL_ERROR;
|
---|
1098 | }
|
---|
1099 | talloc_free(r);
|
---|
1100 |
|
---|
1101 | if (searched_site != NULL) {
|
---|
1102 | ret = ldb_search(ldb, subctx, &r, configdn, LDB_SCOPE_SUBTREE,
|
---|
1103 | attrs_none, "(&(name=%s)(objectClass=site))", searched_site);
|
---|
1104 | if (ret != LDB_SUCCESS) {
|
---|
1105 | talloc_free(subctx);
|
---|
1106 | return NT_STATUS_FOOBAR;
|
---|
1107 | } else if (r->count != 1) {
|
---|
1108 | talloc_free(subctx);
|
---|
1109 | return NT_STATUS_FOOBAR;
|
---|
1110 | }
|
---|
1111 |
|
---|
1112 | /* All of this was to get the DN of the searched_site */
|
---|
1113 | sitedn = r->msgs[0]->dn;
|
---|
1114 |
|
---|
1115 | set_list = talloc_realloc(subctx, set_list, struct dc_set *, current_pos+1);
|
---|
1116 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(set_list, subctx);
|
---|
1117 |
|
---|
1118 | set_list[current_pos] = talloc(set_list, struct dc_set);
|
---|
1119 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(set_list[current_pos], subctx);
|
---|
1120 |
|
---|
1121 | set_list[current_pos]->names = NULL;
|
---|
1122 | set_list[current_pos]->count = 0;
|
---|
1123 | status = get_dcs_insite(subctx, ldb, sitedn,
|
---|
1124 | set_list[current_pos], need_fqdn);
|
---|
1125 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1126 | DEBUG(2,(__location__ ": Failed to get DC from site %s - %s\n",
|
---|
1127 | ldb_dn_get_linearized(sitedn), nt_errstr(status)));
|
---|
1128 | talloc_free(subctx);
|
---|
1129 | return status;
|
---|
1130 | }
|
---|
1131 | talloc_free(r);
|
---|
1132 | current_pos++;
|
---|
1133 | }
|
---|
1134 |
|
---|
1135 | /* Let's find all the sites */
|
---|
1136 | ret = ldb_search(ldb, subctx, &r, configdn, LDB_SCOPE_SUBTREE, attrs3, "(objectClass=site)");
|
---|
1137 | if (ret != LDB_SUCCESS) {
|
---|
1138 | DEBUG(2,(__location__ ": Failed to find any site containers in %s\n",
|
---|
1139 | ldb_dn_get_linearized(configdn)));
|
---|
1140 | talloc_free(subctx);
|
---|
1141 | return NT_STATUS_INTERNAL_DB_CORRUPTION;
|
---|
1142 | }
|
---|
1143 |
|
---|
1144 | /*
|
---|
1145 | * TODO:
|
---|
1146 | * We should randomize the order in the main site,
|
---|
1147 | * it's mostly needed for sysvol/netlogon referral.
|
---|
1148 | * Depending of flag we either randomize order of the
|
---|
1149 | * not "in the same site DCs"
|
---|
1150 | * or we randomize by group of site that have the same cost
|
---|
1151 | * In the long run we want to manipulate an array of site_set
|
---|
1152 | * All the site in one set have the same cost (if least-expansive options is selected)
|
---|
1153 | * and we will put all the dc related to 1 site set into 1 DCs set.
|
---|
1154 | * Within a site set, site order has to be randomized
|
---|
1155 | *
|
---|
1156 | * But for the moment we just return the list of sites
|
---|
1157 | */
|
---|
1158 | if (r->count) {
|
---|
1159 | /*
|
---|
1160 | * We will realloc + 2 because we will need one additional place
|
---|
1161 | * for element at current_pos + 1 for the NULL element
|
---|
1162 | */
|
---|
1163 | set_list = talloc_realloc(subctx, set_list, struct dc_set *,
|
---|
1164 | current_pos+2);
|
---|
1165 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(set_list, subctx);
|
---|
1166 |
|
---|
1167 | set_list[current_pos] = talloc(ctx, struct dc_set);
|
---|
1168 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(set_list[current_pos], subctx);
|
---|
1169 |
|
---|
1170 | set_list[current_pos]->names = NULL;
|
---|
1171 | set_list[current_pos]->count = 0;
|
---|
1172 |
|
---|
1173 | set_list[current_pos+1] = NULL;
|
---|
1174 | }
|
---|
1175 |
|
---|
1176 | for (i=0; i<r->count; i++) {
|
---|
1177 | const char *site_name = ldb_msg_find_attr_as_string(r->msgs[i], "name", NULL);
|
---|
1178 | if (site_name == NULL) {
|
---|
1179 | DEBUG(2,(__location__ ": Failed to find name attribute in %s\n",
|
---|
1180 | ldb_dn_get_linearized(r->msgs[i]->dn)));
|
---|
1181 | talloc_free(subctx);
|
---|
1182 | return NT_STATUS_INTERNAL_DB_CORRUPTION;
|
---|
1183 | }
|
---|
1184 |
|
---|
1185 | if (searched_site == NULL ||
|
---|
1186 | strcmp(searched_site, site_name) != 0) {
|
---|
1187 | DEBUG(2,(__location__ ": Site: %s %s\n",
|
---|
1188 | searched_site, site_name));
|
---|
1189 |
|
---|
1190 | /*
|
---|
1191 | * Do all the site but the one of the client
|
---|
1192 | * (because it has already been done ...)
|
---|
1193 | */
|
---|
1194 | dn = r->msgs[i]->dn;
|
---|
1195 |
|
---|
1196 | status = get_dcs_insite(subctx, ldb, dn,
|
---|
1197 | set_list[current_pos],
|
---|
1198 | need_fqdn);
|
---|
1199 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1200 | talloc_free(subctx);
|
---|
1201 | return status;
|
---|
1202 | }
|
---|
1203 | }
|
---|
1204 | }
|
---|
1205 | current_pos++;
|
---|
1206 | set_list[current_pos] = NULL;
|
---|
1207 |
|
---|
1208 | *pset_list = talloc_move(ctx, &set_list);
|
---|
1209 | talloc_free(subctx);
|
---|
1210 | return NT_STATUS_OK;
|
---|
1211 | }
|
---|
1212 |
|
---|
1213 | static NTSTATUS dodomain_referral(TALLOC_CTX *ctx,
|
---|
1214 | const struct dfs_GetDFSReferral_in *dfsreq,
|
---|
1215 | struct ldb_context *ldb,
|
---|
1216 | struct smb_trans2 *trans,
|
---|
1217 | struct loadparm_context *lp_ctx)
|
---|
1218 | {
|
---|
1219 | /*
|
---|
1220 | * TODO for the moment we just return the local domain
|
---|
1221 | */
|
---|
1222 | DATA_BLOB outblob;
|
---|
1223 | enum ndr_err_code ndr_err;
|
---|
1224 | NTSTATUS status;
|
---|
1225 | const char *dns_domain = lpcfg_dnsdomain(lp_ctx);
|
---|
1226 | const char *netbios_domain = lpcfg_workgroup(lp_ctx);
|
---|
1227 | struct dfs_referral_resp resp;
|
---|
1228 | struct dfs_referral_type *tab;
|
---|
1229 | struct dfs_referral_type *referral;
|
---|
1230 | const char *referral_str;
|
---|
1231 | /* In the future this needs to be fetched from the ldb */
|
---|
1232 | uint32_t found_domain = 2;
|
---|
1233 | uint32_t current_pos = 0;
|
---|
1234 | TALLOC_CTX *context;
|
---|
1235 |
|
---|
1236 | if (lpcfg_server_role(lp_ctx) != ROLE_DOMAIN_CONTROLLER) {
|
---|
1237 | DEBUG(10 ,("Received a domain referral request on a non DC\n"));
|
---|
1238 | return NT_STATUS_INVALID_PARAMETER;
|
---|
1239 | }
|
---|
1240 |
|
---|
1241 | if (dfsreq->max_referral_level < 3) {
|
---|
1242 | DEBUG(2,("invalid max_referral_level %u\n",
|
---|
1243 | dfsreq->max_referral_level));
|
---|
1244 | return NT_STATUS_UNSUCCESSFUL;
|
---|
1245 | }
|
---|
1246 |
|
---|
1247 | context = talloc_new(ctx);
|
---|
1248 | NT_STATUS_HAVE_NO_MEMORY(context);
|
---|
1249 |
|
---|
1250 | resp.path_consumed = 0;
|
---|
1251 | resp.header_flags = 0; /* Do like w2k3 */
|
---|
1252 | resp.nb_referrals = found_domain; /* the fqdn one + the NT domain */
|
---|
1253 |
|
---|
1254 | tab = talloc_array(context, struct dfs_referral_type, found_domain);
|
---|
1255 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(tab, context);
|
---|
1256 |
|
---|
1257 | referral = talloc(tab, struct dfs_referral_type);
|
---|
1258 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(referral, context);
|
---|
1259 | referral_str = talloc_asprintf(referral, "\\%s", netbios_domain);
|
---|
1260 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(referral_str, context);
|
---|
1261 | status = fill_domain_dfs_referraltype(referral, 3,
|
---|
1262 | referral_str,
|
---|
1263 | NULL, 0);
|
---|
1264 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1265 | DEBUG(2,(__location__ ":Unable to fill domain referral structure\n"));
|
---|
1266 | talloc_free(context);
|
---|
1267 | return NT_STATUS_UNSUCCESSFUL;
|
---|
1268 | }
|
---|
1269 |
|
---|
1270 | tab[current_pos] = *referral;
|
---|
1271 | current_pos++;
|
---|
1272 |
|
---|
1273 | referral = talloc(tab, struct dfs_referral_type);
|
---|
1274 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(referral, context);
|
---|
1275 | referral_str = talloc_asprintf(referral, "\\%s", dns_domain);
|
---|
1276 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(referral_str, context);
|
---|
1277 | status = fill_domain_dfs_referraltype(referral, 3,
|
---|
1278 | referral_str,
|
---|
1279 | NULL, 0);
|
---|
1280 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1281 | DEBUG(2,(__location__ ":Unable to fill domain referral structure\n"));
|
---|
1282 | talloc_free(context);
|
---|
1283 | return NT_STATUS_UNSUCCESSFUL;
|
---|
1284 | }
|
---|
1285 | tab[current_pos] = *referral;
|
---|
1286 | current_pos++;
|
---|
1287 |
|
---|
1288 | /*
|
---|
1289 | * Put here the code from filling the array for trusted domain
|
---|
1290 | */
|
---|
1291 | resp.referral_entries = tab;
|
---|
1292 |
|
---|
1293 | ndr_err = ndr_push_struct_blob(&outblob, context,
|
---|
1294 | &resp,
|
---|
1295 | (ndr_push_flags_fn_t)ndr_push_dfs_referral_resp);
|
---|
1296 | if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
|
---|
1297 | DEBUG(2,(__location__ ":NDR marchalling of domain deferral response failed\n"));
|
---|
1298 | talloc_free(context);
|
---|
1299 | return NT_STATUS_INTERNAL_ERROR;
|
---|
1300 | }
|
---|
1301 |
|
---|
1302 | if (outblob.length > trans->in.max_data) {
|
---|
1303 | bool ok = false;
|
---|
1304 |
|
---|
1305 | DEBUG(3, ("Blob is too big for the output buffer "
|
---|
1306 | "size %u max %u\n",
|
---|
1307 | (unsigned int)outblob.length, trans->in.max_data));
|
---|
1308 |
|
---|
1309 | if (trans->in.max_data != MAX_DFS_RESPONSE) {
|
---|
1310 | /* As specified in MS-DFSC.pdf 3.3.5.2 */
|
---|
1311 | talloc_free(context);
|
---|
1312 | return STATUS_BUFFER_OVERFLOW;
|
---|
1313 | }
|
---|
1314 |
|
---|
1315 | /*
|
---|
1316 | * The answer is too big, so let's remove some answers
|
---|
1317 | */
|
---|
1318 | while (!ok && resp.nb_referrals > 2) {
|
---|
1319 | data_blob_free(&outblob);
|
---|
1320 |
|
---|
1321 | /*
|
---|
1322 | * Let's scrap the first referral (for now)
|
---|
1323 | */
|
---|
1324 | resp.nb_referrals -= 1;
|
---|
1325 | resp.referral_entries += 1;
|
---|
1326 |
|
---|
1327 | ndr_err = ndr_push_struct_blob(&outblob, context,
|
---|
1328 | &resp,
|
---|
1329 | (ndr_push_flags_fn_t)ndr_push_dfs_referral_resp);
|
---|
1330 | if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
|
---|
1331 | talloc_free(context);
|
---|
1332 | return NT_STATUS_INTERNAL_ERROR;
|
---|
1333 | }
|
---|
1334 |
|
---|
1335 | if (outblob.length <= MAX_DFS_RESPONSE) {
|
---|
1336 | DEBUG(10,("DFS: managed to reduce the size of referral initial"
|
---|
1337 | "number of referral %d, actual count: %d",
|
---|
1338 | found_domain, resp.nb_referrals));
|
---|
1339 | ok = true;
|
---|
1340 | break;
|
---|
1341 | }
|
---|
1342 | }
|
---|
1343 |
|
---|
1344 | if (!ok && resp.nb_referrals == 2) {
|
---|
1345 | DEBUG(0, (__location__ "; Not able to fit the domain and realm in DFS a "
|
---|
1346 | " 56K buffer, something must be broken"));
|
---|
1347 | talloc_free(context);
|
---|
1348 | return NT_STATUS_INTERNAL_ERROR;
|
---|
1349 | }
|
---|
1350 | }
|
---|
1351 |
|
---|
1352 | TRANS2_CHECK(trans2_setup_reply(trans, 0, outblob.length, 0));
|
---|
1353 |
|
---|
1354 | trans->out.data = outblob;
|
---|
1355 | talloc_steal(ctx, outblob.data);
|
---|
1356 | talloc_free(context);
|
---|
1357 | return NT_STATUS_OK;
|
---|
1358 | }
|
---|
1359 |
|
---|
1360 | /*
|
---|
1361 | * Handle the logic for dfs referral request like \\domain
|
---|
1362 | * or \\domain\sysvol or \\fqdn or \\fqdn\netlogon
|
---|
1363 | */
|
---|
1364 | static NTSTATUS dodc_or_sysvol_referral(TALLOC_CTX *ctx,
|
---|
1365 | const struct dfs_GetDFSReferral_in dfsreq,
|
---|
1366 | const char* requestedname,
|
---|
1367 | struct ldb_context *ldb,
|
---|
1368 | struct smb_trans2 *trans,
|
---|
1369 | struct smbsrv_request *req,
|
---|
1370 | struct loadparm_context *lp_ctx)
|
---|
1371 | {
|
---|
1372 | /*
|
---|
1373 | * It's not a "standard" DFS referral but a referral to get the DC list
|
---|
1374 | * or sysvol/netlogon
|
---|
1375 | * Let's check that it's for one of our domain ...
|
---|
1376 | */
|
---|
1377 | DATA_BLOB outblob;
|
---|
1378 | NTSTATUS status;
|
---|
1379 | unsigned int num_domain = 1;
|
---|
1380 | enum ndr_err_code ndr_err;
|
---|
1381 | const char *requesteddomain;
|
---|
1382 | const char *realm = lpcfg_realm(lp_ctx);
|
---|
1383 | const char *domain = lpcfg_workgroup(lp_ctx);
|
---|
1384 | const char *site_name = NULL; /* Name of the site where the client is */
|
---|
1385 | char *share = NULL;
|
---|
1386 | bool found = false;
|
---|
1387 | bool need_fqdn = false;
|
---|
1388 | bool dc_referral = true;
|
---|
1389 | unsigned int i;
|
---|
1390 | char *tmp;
|
---|
1391 | struct dc_set **set;
|
---|
1392 | char const **domain_list;
|
---|
1393 | struct tsocket_address *remote_address;
|
---|
1394 | char *client_addr = NULL;
|
---|
1395 | TALLOC_CTX *context;
|
---|
1396 |
|
---|
1397 | if (lpcfg_server_role(lp_ctx) != ROLE_DOMAIN_CONTROLLER) {
|
---|
1398 | return NT_STATUS_INVALID_PARAMETER;
|
---|
1399 | }
|
---|
1400 |
|
---|
1401 | if (dfsreq.max_referral_level < 3) {
|
---|
1402 | DEBUG(2,("invalid max_referral_level %u\n",
|
---|
1403 | dfsreq.max_referral_level));
|
---|
1404 | return NT_STATUS_UNSUCCESSFUL;
|
---|
1405 | }
|
---|
1406 |
|
---|
1407 | context = talloc_new(ctx);
|
---|
1408 | NT_STATUS_HAVE_NO_MEMORY(context);
|
---|
1409 |
|
---|
1410 | if (requestedname[0] == '\\' && !strchr(requestedname+1,'\\')) {
|
---|
1411 | requestedname++;
|
---|
1412 | }
|
---|
1413 | requesteddomain = requestedname;
|
---|
1414 |
|
---|
1415 | if (strchr(requestedname,'\\')) {
|
---|
1416 | char *subpart;
|
---|
1417 | /* we have a second part */
|
---|
1418 | requesteddomain = talloc_strdup(context, requestedname+1);
|
---|
1419 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(requesteddomain, context);
|
---|
1420 | subpart = strchr(requesteddomain,'\\');
|
---|
1421 | subpart[0] = '\0';
|
---|
1422 | }
|
---|
1423 | tmp = strchr(requestedname + 1,'\\'); /* To get second \ if any */
|
---|
1424 |
|
---|
1425 | if (tmp != NULL) {
|
---|
1426 | /* There was a share */
|
---|
1427 | share = tmp+1;
|
---|
1428 | dc_referral = false;
|
---|
1429 | }
|
---|
1430 |
|
---|
1431 | /*
|
---|
1432 | * We will fetch the trusted domain list soon with something like this:
|
---|
1433 | *
|
---|
1434 | * "(&(|(flatname=%s)(cn=%s)(trustPartner=%s)(flatname=%s)(cn=%s)
|
---|
1435 | * (trustPartner=%s))(objectclass=trustedDomain))"
|
---|
1436 | *
|
---|
1437 | * Allocate for num_domain + 1 so that the last element will be NULL)
|
---|
1438 | */
|
---|
1439 | domain_list = talloc_array(context, const char*, num_domain+1);
|
---|
1440 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(domain_list, context);
|
---|
1441 |
|
---|
1442 | domain_list[0] = realm;
|
---|
1443 | domain_list[1] = domain;
|
---|
1444 | for (i=0; i<=num_domain; i++) {
|
---|
1445 | if (strncasecmp(domain_list[i], requesteddomain, strlen(domain_list[i])) == 0) {
|
---|
1446 | found = true;
|
---|
1447 | break;
|
---|
1448 | }
|
---|
1449 | }
|
---|
1450 |
|
---|
1451 | if (!found) {
|
---|
1452 | /* The requested domain is not one that we support */
|
---|
1453 | DEBUG(3,("Requested referral for domain %s, but we don't handle it",
|
---|
1454 | requesteddomain));
|
---|
1455 | return NT_STATUS_INVALID_PARAMETER;
|
---|
1456 | }
|
---|
1457 |
|
---|
1458 | if (strchr(requestedname,'.')) {
|
---|
1459 | need_fqdn = 1;
|
---|
1460 | }
|
---|
1461 |
|
---|
1462 | remote_address = req->smb_conn->connection->remote_address;
|
---|
1463 | if (tsocket_address_is_inet(remote_address, "ip")) {
|
---|
1464 | client_addr = tsocket_address_inet_addr_string(remote_address, context);
|
---|
1465 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(client_addr, context);
|
---|
1466 | }
|
---|
1467 |
|
---|
1468 | status = get_dcs(context, ldb, site_name, need_fqdn, &set, 0);
|
---|
1469 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1470 | DEBUG(3,("Unable to get list of DCs\n"));
|
---|
1471 | talloc_free(context);
|
---|
1472 | return status;
|
---|
1473 | }
|
---|
1474 |
|
---|
1475 | if (dc_referral) {
|
---|
1476 | const char **dc_list = NULL;
|
---|
1477 | uint32_t num_dcs = 0;
|
---|
1478 | struct dfs_referral_type *referral;
|
---|
1479 | const char *referral_str;
|
---|
1480 | struct dfs_referral_resp resp;
|
---|
1481 |
|
---|
1482 | for(i=0; set[i]; i++) {
|
---|
1483 | uint32_t j;
|
---|
1484 |
|
---|
1485 | dc_list = talloc_realloc(context, dc_list, const char*,
|
---|
1486 | num_dcs + set[i]->count + 1);
|
---|
1487 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(dc_list, context);
|
---|
1488 |
|
---|
1489 | for(j=0; j<set[i]->count; j++) {
|
---|
1490 | dc_list[num_dcs + j] = talloc_move(context, &set[i]->names[j]);
|
---|
1491 | }
|
---|
1492 | num_dcs = num_dcs + set[i]->count;
|
---|
1493 | TALLOC_FREE(set[i]);
|
---|
1494 | dc_list[num_dcs] = NULL;
|
---|
1495 | }
|
---|
1496 |
|
---|
1497 | resp.path_consumed = 0;
|
---|
1498 | resp.header_flags = 0; /* Do like w2k3 and like in 3.3.5.3 of MS-DFSC*/
|
---|
1499 |
|
---|
1500 | /*
|
---|
1501 | * The NumberOfReferrals field MUST be set to 1,
|
---|
1502 | * independent of the number of DC names
|
---|
1503 | * returned. (as stated in 3.3.5.3 of MS-DFSC)
|
---|
1504 | */
|
---|
1505 | resp.nb_referrals = 1;
|
---|
1506 |
|
---|
1507 | /* Put here the code from filling the array for trusted domain */
|
---|
1508 | referral = talloc(context, struct dfs_referral_type);
|
---|
1509 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(referral, context);
|
---|
1510 |
|
---|
1511 | referral_str = talloc_asprintf(referral, "\\%s",
|
---|
1512 | requestedname);
|
---|
1513 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(referral_str, context);
|
---|
1514 |
|
---|
1515 | status = fill_domain_dfs_referraltype(referral, 3,
|
---|
1516 | referral_str,
|
---|
1517 | dc_list, num_dcs);
|
---|
1518 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1519 | DEBUG(2,(__location__ ":Unable to fill domain referral structure\n"));
|
---|
1520 | talloc_free(context);
|
---|
1521 | return NT_STATUS_UNSUCCESSFUL;
|
---|
1522 | }
|
---|
1523 | resp.referral_entries = referral;
|
---|
1524 |
|
---|
1525 | ndr_err = ndr_push_struct_blob(&outblob, context,
|
---|
1526 | &resp,
|
---|
1527 | (ndr_push_flags_fn_t)ndr_push_dfs_referral_resp);
|
---|
1528 | if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
|
---|
1529 | DEBUG(2,(__location__ ":NDR marshalling of dfs referral response failed\n"));
|
---|
1530 | talloc_free(context);
|
---|
1531 | return NT_STATUS_INTERNAL_ERROR;
|
---|
1532 | }
|
---|
1533 | } else {
|
---|
1534 | unsigned int nb_entries = 0;
|
---|
1535 | unsigned int current = 0;
|
---|
1536 | struct dfs_referral_type *tab;
|
---|
1537 | struct dfs_referral_resp resp;
|
---|
1538 |
|
---|
1539 | for(i=0; set[i]; i++) {
|
---|
1540 | nb_entries = nb_entries + set[i]->count;
|
---|
1541 | }
|
---|
1542 |
|
---|
1543 | resp.path_consumed = 2*strlen(requestedname); /* The length is expected in bytes */
|
---|
1544 | resp.header_flags = DFS_HEADER_FLAG_STORAGE_SVR; /* Do like w2k3 and like in 3.3.5.3 of MS-DFSC*/
|
---|
1545 |
|
---|
1546 | /*
|
---|
1547 | * The NumberOfReferrals field MUST be set to 1,
|
---|
1548 | * independent of the number of DC names
|
---|
1549 | * returned. (as stated in 3.3.5.3 of MS-DFSC)
|
---|
1550 | */
|
---|
1551 | resp.nb_referrals = nb_entries;
|
---|
1552 |
|
---|
1553 | tab = talloc_array(context, struct dfs_referral_type, nb_entries);
|
---|
1554 | NT_STATUS_HAVE_NO_MEMORY(tab);
|
---|
1555 |
|
---|
1556 | for(i=0; set[i]; i++) {
|
---|
1557 | uint32_t j;
|
---|
1558 |
|
---|
1559 | for(j=0; j< set[i]->count; j++) {
|
---|
1560 | struct dfs_referral_type *referral;
|
---|
1561 | const char *referral_str;
|
---|
1562 |
|
---|
1563 | referral = talloc(tab, struct dfs_referral_type);
|
---|
1564 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(referral, context);
|
---|
1565 |
|
---|
1566 | referral_str = talloc_asprintf(referral, "\\%s\\%s",
|
---|
1567 | set[i]->names[j], share);
|
---|
1568 | NT_STATUS_HAVE_NO_MEMORY_AND_FREE(referral_str, context);
|
---|
1569 |
|
---|
1570 | status = fill_normal_dfs_referraltype(referral,
|
---|
1571 | dfsreq.max_referral_level,
|
---|
1572 | requestedname, referral_str, j==0);
|
---|
1573 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1574 | DEBUG(2, (__location__ ": Unable to fill a normal dfs referral object"));
|
---|
1575 | talloc_free(context);
|
---|
1576 | return NT_STATUS_UNSUCCESSFUL;
|
---|
1577 | }
|
---|
1578 | tab[current] = *referral;
|
---|
1579 | current++;
|
---|
1580 | }
|
---|
1581 | }
|
---|
1582 | resp.referral_entries = tab;
|
---|
1583 |
|
---|
1584 | ndr_err = ndr_push_struct_blob(&outblob, context,
|
---|
1585 | &resp,
|
---|
1586 | (ndr_push_flags_fn_t)ndr_push_dfs_referral_resp);
|
---|
1587 | if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
|
---|
1588 | DEBUG(2,(__location__ ":NDR marchalling of domain deferral response failed\n"));
|
---|
1589 | talloc_free(context);
|
---|
1590 | return NT_STATUS_INTERNAL_ERROR;
|
---|
1591 | }
|
---|
1592 | }
|
---|
1593 |
|
---|
1594 | TRANS2_CHECK(trans2_setup_reply(trans, 0, outblob.length, 0));
|
---|
1595 |
|
---|
1596 | /*
|
---|
1597 | * TODO If the size is too big we should remove
|
---|
1598 | * some DC from the answer or return STATUS_BUFFER_OVERFLOW
|
---|
1599 | */
|
---|
1600 | trans->out.data = outblob;
|
---|
1601 | talloc_steal(ctx, outblob.data);
|
---|
1602 | talloc_free(context);
|
---|
1603 | return NT_STATUS_OK;
|
---|
1604 | }
|
---|
1605 |
|
---|
1606 | /*
|
---|
1607 | trans2 getdfsreferral implementation
|
---|
1608 | */
|
---|
1609 | static NTSTATUS trans2_getdfsreferral(struct smbsrv_request *req,
|
---|
1610 | struct trans_op *op)
|
---|
1611 | {
|
---|
1612 | enum ndr_err_code ndr_err;
|
---|
1613 | struct smb_trans2 *trans = op->trans;
|
---|
1614 | struct dfs_GetDFSReferral_in dfsreq;
|
---|
1615 | TALLOC_CTX *context;
|
---|
1616 | struct ldb_context *ldb;
|
---|
1617 | struct loadparm_context *lp_ctx;
|
---|
1618 | const char *realm, *nbname, *requestedname;
|
---|
1619 | char *fqdn, *tmp;
|
---|
1620 | NTSTATUS status;
|
---|
1621 |
|
---|
1622 | lp_ctx = req->tcon->ntvfs->lp_ctx;
|
---|
1623 | if (!lpcfg_host_msdfs(lp_ctx)) {
|
---|
1624 | return NT_STATUS_NOT_IMPLEMENTED;
|
---|
1625 | }
|
---|
1626 |
|
---|
1627 | context = talloc_new(req);
|
---|
1628 | NT_STATUS_HAVE_NO_MEMORY(context);
|
---|
1629 |
|
---|
1630 | ldb = samdb_connect(context, req->tcon->ntvfs->event_ctx, lp_ctx, system_session(lp_ctx), 0);
|
---|
1631 | if (ldb == NULL) {
|
---|
1632 | DEBUG(2,(__location__ ": Failed to open samdb\n"));
|
---|
1633 | talloc_free(context);
|
---|
1634 | return NT_STATUS_INTERNAL_ERROR;
|
---|
1635 | }
|
---|
1636 |
|
---|
1637 | ndr_err = ndr_pull_struct_blob(&trans->in.params, op,
|
---|
1638 | &dfsreq,
|
---|
1639 | (ndr_pull_flags_fn_t)ndr_pull_dfs_GetDFSReferral_in);
|
---|
1640 | if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
|
---|
1641 | status = ndr_map_error2ntstatus(ndr_err);
|
---|
1642 | DEBUG(2,(__location__ ": Failed to parse GetDFSReferral_in - %s\n",
|
---|
1643 | nt_errstr(status)));
|
---|
1644 | talloc_free(context);
|
---|
1645 | return status;
|
---|
1646 | }
|
---|
1647 |
|
---|
1648 | DEBUG(10, ("Requested DFS name: %s length: %u\n",
|
---|
1649 | dfsreq.servername, (unsigned int)strlen(dfsreq.servername)));
|
---|
1650 |
|
---|
1651 | /*
|
---|
1652 | * If the servername is "" then we are in a case of domain dfs
|
---|
1653 | * and the client just searches for the list of local domain
|
---|
1654 | * it is attached and also trusted ones.
|
---|
1655 | */
|
---|
1656 | requestedname = dfsreq.servername;
|
---|
1657 | if (requestedname == NULL || requestedname[0] == '\0') {
|
---|
1658 | return dodomain_referral(op, &dfsreq, ldb, trans, lp_ctx);
|
---|
1659 | }
|
---|
1660 |
|
---|
1661 | realm = lpcfg_realm(lp_ctx);
|
---|
1662 | nbname = lpcfg_netbios_name(lp_ctx);
|
---|
1663 | fqdn = talloc_asprintf(context, "%s.%s", nbname, realm);
|
---|
1664 |
|
---|
1665 | if ((strncasecmp(requestedname+1, nbname, strlen(nbname)) == 0) ||
|
---|
1666 | (strncasecmp(requestedname+1, fqdn, strlen(fqdn)) == 0) ) {
|
---|
1667 | /*
|
---|
1668 | * the referral request starts with \NETBIOSNAME or \fqdn
|
---|
1669 | * it's a standalone referral we do not do it
|
---|
1670 | * (TODO correct this)
|
---|
1671 | * If a DFS link that is a complete prefix of the DFS referral
|
---|
1672 | * request path is identified, the server MUST return a DFS link
|
---|
1673 | * referral response; otherwise, if it has a match for the DFS root,
|
---|
1674 | * it MUST return a root referral response.
|
---|
1675 | */
|
---|
1676 | DEBUG(3, ("Received a standalone request for %s, we do not support standalone referral yet",requestedname));
|
---|
1677 | talloc_free(context);
|
---|
1678 | return NT_STATUS_NOT_FOUND;
|
---|
1679 | }
|
---|
1680 | talloc_free(fqdn);
|
---|
1681 |
|
---|
1682 | tmp = strchr(requestedname + 1,'\\'); /* To get second \ if any */
|
---|
1683 |
|
---|
1684 | /*
|
---|
1685 | * If we have no slash at the first position or (foo.bar.domain.net)
|
---|
1686 | * a slash at the first position but no other slash (\foo.bar.domain.net)
|
---|
1687 | * or a slash at the first position and another slash
|
---|
1688 | * and netlogon or sysvol after the second slash
|
---|
1689 | * (\foo.bar.domain.net\sysvol) then we will handle it because
|
---|
1690 | * it's either a dc referral or a sysvol/netlogon referral
|
---|
1691 | */
|
---|
1692 | if (requestedname[0] != '\\' ||
|
---|
1693 | tmp == NULL ||
|
---|
1694 | strcasecmp(tmp+1, "sysvol") == 0 ||
|
---|
1695 | strcasecmp(tmp+1, "netlogon") == 0) {
|
---|
1696 | status = dodc_or_sysvol_referral(op, dfsreq, requestedname,
|
---|
1697 | ldb, trans, req, lp_ctx);
|
---|
1698 | talloc_free(context);
|
---|
1699 | return status;
|
---|
1700 | }
|
---|
1701 |
|
---|
1702 | if (requestedname[0] == '\\' &&
|
---|
1703 | tmp &&
|
---|
1704 | strchr(tmp+1, '\\') &&
|
---|
1705 | (strncasecmp(tmp+1, "sysvol", 6) == 0 ||
|
---|
1706 | strncasecmp(tmp+1, "netlogon", 8) == 0)) {
|
---|
1707 | /*
|
---|
1708 | * We have more than two \ so it something like
|
---|
1709 | * \domain\sysvol\foobar
|
---|
1710 | */
|
---|
1711 | talloc_free(context);
|
---|
1712 | return NT_STATUS_NOT_FOUND;
|
---|
1713 | }
|
---|
1714 |
|
---|
1715 | talloc_free(context);
|
---|
1716 | /* By default until all the case are handled*/
|
---|
1717 | return NT_STATUS_NOT_FOUND;
|
---|
1718 | }
|
---|
1719 |
|
---|
1720 | /*
|
---|
1721 | trans2 findfirst implementation
|
---|
1722 | */
|
---|
1723 | static NTSTATUS trans2_findfirst(struct smbsrv_request *req, struct trans_op *op)
|
---|
1724 | {
|
---|
1725 | struct smb_trans2 *trans = op->trans;
|
---|
1726 | union smb_search_first *search;
|
---|
1727 | uint16_t level;
|
---|
1728 | struct find_state *state;
|
---|
1729 |
|
---|
1730 | /* make sure we got all the parameters */
|
---|
1731 | if (trans->in.params.length < 14) {
|
---|
1732 | return NT_STATUS_FOOBAR;
|
---|
1733 | }
|
---|
1734 |
|
---|
1735 | search = talloc(op, union smb_search_first);
|
---|
1736 | NT_STATUS_HAVE_NO_MEMORY(search);
|
---|
1737 |
|
---|
1738 | search->t2ffirst.in.search_attrib = SVAL(trans->in.params.data, 0);
|
---|
1739 | search->t2ffirst.in.max_count = SVAL(trans->in.params.data, 2);
|
---|
1740 | search->t2ffirst.in.flags = SVAL(trans->in.params.data, 4);
|
---|
1741 | level = SVAL(trans->in.params.data, 6);
|
---|
1742 | search->t2ffirst.in.storage_type = IVAL(trans->in.params.data, 8);
|
---|
1743 |
|
---|
1744 | smbsrv_blob_pull_string(&req->in.bufinfo, &trans->in.params, 12, &search->t2ffirst.in.pattern, 0);
|
---|
1745 | if (search->t2ffirst.in.pattern == NULL) {
|
---|
1746 | return NT_STATUS_FOOBAR;
|
---|
1747 | }
|
---|
1748 |
|
---|
1749 | search->t2ffirst.level = RAW_SEARCH_TRANS2;
|
---|
1750 | search->t2ffirst.data_level = (enum smb_search_data_level)level;
|
---|
1751 | if (search->t2ffirst.data_level >= RAW_SEARCH_DATA_GENERIC) {
|
---|
1752 | return NT_STATUS_INVALID_LEVEL;
|
---|
1753 | }
|
---|
1754 |
|
---|
1755 | if (search->t2ffirst.data_level == RAW_SEARCH_DATA_EA_LIST) {
|
---|
1756 | TRANS2_CHECK(ea_pull_name_list(&trans->in.data, req,
|
---|
1757 | &search->t2ffirst.in.num_names,
|
---|
1758 | &search->t2ffirst.in.ea_names));
|
---|
1759 | }
|
---|
1760 |
|
---|
1761 | /* setup the private state structure that the backend will
|
---|
1762 | give us in the callback */
|
---|
1763 | state = talloc(op, struct find_state);
|
---|
1764 | NT_STATUS_HAVE_NO_MEMORY(state);
|
---|
1765 | state->op = op;
|
---|
1766 | state->search = search;
|
---|
1767 | state->data_level = search->t2ffirst.data_level;
|
---|
1768 | state->last_entry_offset= 0;
|
---|
1769 | state->flags = search->t2ffirst.in.flags;
|
---|
1770 |
|
---|
1771 | /* setup for just a header in the reply */
|
---|
1772 | TRANS2_CHECK(trans2_setup_reply(trans, 10, 0, 0));
|
---|
1773 |
|
---|
1774 | op->op_info = state;
|
---|
1775 | op->send_fn = trans2_findfirst_send;
|
---|
1776 |
|
---|
1777 | return ntvfs_search_first(req->ntvfs, search, state, find_callback);
|
---|
1778 | }
|
---|
1779 |
|
---|
1780 |
|
---|
1781 | /*
|
---|
1782 | trans2 findnext send
|
---|
1783 | */
|
---|
1784 | static NTSTATUS trans2_findnext_send(struct trans_op *op)
|
---|
1785 | {
|
---|
1786 | struct smbsrv_request *req = op->req;
|
---|
1787 | struct smb_trans2 *trans = op->trans;
|
---|
1788 | union smb_search_next *search;
|
---|
1789 | struct find_state *state;
|
---|
1790 | uint8_t *param;
|
---|
1791 |
|
---|
1792 | TRANS2_CHECK_ASYNC_STATUS(state, struct find_state);
|
---|
1793 | search = talloc_get_type(state->search, union smb_search_next);
|
---|
1794 |
|
---|
1795 | /* fill in the findfirst reply header */
|
---|
1796 | param = trans->out.params.data;
|
---|
1797 | SSVAL(param, VWV(0), search->t2fnext.out.count);
|
---|
1798 | SSVAL(param, VWV(1), search->t2fnext.out.end_of_search);
|
---|
1799 | SSVAL(param, VWV(2), 0);
|
---|
1800 | SSVAL(param, VWV(3), state->last_entry_offset);
|
---|
1801 |
|
---|
1802 | return NT_STATUS_OK;
|
---|
1803 | }
|
---|
1804 |
|
---|
1805 |
|
---|
1806 | /*
|
---|
1807 | trans2 findnext implementation
|
---|
1808 | */
|
---|
1809 | static NTSTATUS trans2_findnext(struct smbsrv_request *req, struct trans_op *op)
|
---|
1810 | {
|
---|
1811 | struct smb_trans2 *trans = op->trans;
|
---|
1812 | union smb_search_next *search;
|
---|
1813 | uint16_t level;
|
---|
1814 | struct find_state *state;
|
---|
1815 |
|
---|
1816 | /* make sure we got all the parameters */
|
---|
1817 | if (trans->in.params.length < 12) {
|
---|
1818 | return NT_STATUS_FOOBAR;
|
---|
1819 | }
|
---|
1820 |
|
---|
1821 | search = talloc(op, union smb_search_next);
|
---|
1822 | NT_STATUS_HAVE_NO_MEMORY(search);
|
---|
1823 |
|
---|
1824 | search->t2fnext.in.handle = SVAL(trans->in.params.data, 0);
|
---|
1825 | search->t2fnext.in.max_count = SVAL(trans->in.params.data, 2);
|
---|
1826 | level = SVAL(trans->in.params.data, 4);
|
---|
1827 | search->t2fnext.in.resume_key = IVAL(trans->in.params.data, 6);
|
---|
1828 | search->t2fnext.in.flags = SVAL(trans->in.params.data, 10);
|
---|
1829 |
|
---|
1830 | smbsrv_blob_pull_string(&req->in.bufinfo, &trans->in.params, 12, &search->t2fnext.in.last_name, 0);
|
---|
1831 | if (search->t2fnext.in.last_name == NULL) {
|
---|
1832 | return NT_STATUS_FOOBAR;
|
---|
1833 | }
|
---|
1834 |
|
---|
1835 | search->t2fnext.level = RAW_SEARCH_TRANS2;
|
---|
1836 | search->t2fnext.data_level = (enum smb_search_data_level)level;
|
---|
1837 | if (search->t2fnext.data_level >= RAW_SEARCH_DATA_GENERIC) {
|
---|
1838 | return NT_STATUS_INVALID_LEVEL;
|
---|
1839 | }
|
---|
1840 |
|
---|
1841 | if (search->t2fnext.data_level == RAW_SEARCH_DATA_EA_LIST) {
|
---|
1842 | TRANS2_CHECK(ea_pull_name_list(&trans->in.data, req,
|
---|
1843 | &search->t2fnext.in.num_names,
|
---|
1844 | &search->t2fnext.in.ea_names));
|
---|
1845 | }
|
---|
1846 |
|
---|
1847 | /* setup the private state structure that the backend will give us in the callback */
|
---|
1848 | state = talloc(op, struct find_state);
|
---|
1849 | NT_STATUS_HAVE_NO_MEMORY(state);
|
---|
1850 | state->op = op;
|
---|
1851 | state->search = search;
|
---|
1852 | state->data_level = search->t2fnext.data_level;
|
---|
1853 | state->last_entry_offset= 0;
|
---|
1854 | state->flags = search->t2fnext.in.flags;
|
---|
1855 |
|
---|
1856 | /* setup for just a header in the reply */
|
---|
1857 | TRANS2_CHECK(trans2_setup_reply(trans, 8, 0, 0));
|
---|
1858 |
|
---|
1859 | op->op_info = state;
|
---|
1860 | op->send_fn = trans2_findnext_send;
|
---|
1861 |
|
---|
1862 | return ntvfs_search_next(req->ntvfs, search, state, find_callback);
|
---|
1863 | }
|
---|
1864 |
|
---|
1865 |
|
---|
1866 | /*
|
---|
1867 | backend for trans2 requests
|
---|
1868 | */
|
---|
1869 | static NTSTATUS trans2_backend(struct smbsrv_request *req, struct trans_op *op)
|
---|
1870 | {
|
---|
1871 | struct smb_trans2 *trans = op->trans;
|
---|
1872 | NTSTATUS status;
|
---|
1873 |
|
---|
1874 | /* direct trans2 pass thru */
|
---|
1875 | status = ntvfs_trans2(req->ntvfs, trans);
|
---|
1876 | if (!NT_STATUS_EQUAL(NT_STATUS_NOT_IMPLEMENTED, status)) {
|
---|
1877 | return status;
|
---|
1878 | }
|
---|
1879 |
|
---|
1880 | /* must have at least one setup word */
|
---|
1881 | if (trans->in.setup_count < 1) {
|
---|
1882 | return NT_STATUS_FOOBAR;
|
---|
1883 | }
|
---|
1884 |
|
---|
1885 | /* the trans2 command is in setup[0] */
|
---|
1886 | switch (trans->in.setup[0]) {
|
---|
1887 | case TRANSACT2_GET_DFS_REFERRAL:
|
---|
1888 | return trans2_getdfsreferral(req, op);
|
---|
1889 | case TRANSACT2_FINDFIRST:
|
---|
1890 | return trans2_findfirst(req, op);
|
---|
1891 | case TRANSACT2_FINDNEXT:
|
---|
1892 | return trans2_findnext(req, op);
|
---|
1893 | case TRANSACT2_QPATHINFO:
|
---|
1894 | return trans2_qpathinfo(req, op);
|
---|
1895 | case TRANSACT2_QFILEINFO:
|
---|
1896 | return trans2_qfileinfo(req, op);
|
---|
1897 | case TRANSACT2_SETFILEINFO:
|
---|
1898 | return trans2_setfileinfo(req, op);
|
---|
1899 | case TRANSACT2_SETPATHINFO:
|
---|
1900 | return trans2_setpathinfo(req, op);
|
---|
1901 | case TRANSACT2_QFSINFO:
|
---|
1902 | return trans2_qfsinfo(req, op);
|
---|
1903 | case TRANSACT2_OPEN:
|
---|
1904 | return trans2_open(req, op);
|
---|
1905 | case TRANSACT2_MKDIR:
|
---|
1906 | return trans2_mkdir(req, op);
|
---|
1907 | }
|
---|
1908 |
|
---|
1909 | /* an unknown trans2 command */
|
---|
1910 | return NT_STATUS_FOOBAR;
|
---|
1911 | }
|
---|
1912 |
|
---|
1913 | int smbsrv_trans_partial_destructor(struct smbsrv_trans_partial *tp)
|
---|
1914 | {
|
---|
1915 | DLIST_REMOVE(tp->req->smb_conn->trans_partial, tp);
|
---|
1916 | return 0;
|
---|
1917 | }
|
---|
1918 |
|
---|
1919 |
|
---|
1920 | /*
|
---|
1921 | send a continue request
|
---|
1922 | */
|
---|
1923 | static void reply_trans_continue(struct smbsrv_request *req, uint8_t command,
|
---|
1924 | struct smb_trans2 *trans)
|
---|
1925 | {
|
---|
1926 | struct smbsrv_request *req2;
|
---|
1927 | struct smbsrv_trans_partial *tp;
|
---|
1928 | int count;
|
---|
1929 |
|
---|
1930 | /* make sure they don't flood us */
|
---|
1931 | for (count=0,tp=req->smb_conn->trans_partial;tp;tp=tp->next) count++;
|
---|
1932 | if (count > 100) {
|
---|
1933 | smbsrv_send_error(req, NT_STATUS_INSUFFICIENT_RESOURCES);
|
---|
1934 | return;
|
---|
1935 | }
|
---|
1936 |
|
---|
1937 | tp = talloc(req, struct smbsrv_trans_partial);
|
---|
1938 |
|
---|
1939 | tp->req = req;
|
---|
1940 | tp->u.trans = trans;
|
---|
1941 | tp->command = command;
|
---|
1942 |
|
---|
1943 | DLIST_ADD(req->smb_conn->trans_partial, tp);
|
---|
1944 | talloc_set_destructor(tp, smbsrv_trans_partial_destructor);
|
---|
1945 |
|
---|
1946 | req2 = smbsrv_setup_secondary_request(req);
|
---|
1947 |
|
---|
1948 | /* send a 'please continue' reply */
|
---|
1949 | smbsrv_setup_reply(req2, 0, 0);
|
---|
1950 | smbsrv_send_reply(req2);
|
---|
1951 | }
|
---|
1952 |
|
---|
1953 |
|
---|
1954 | /*
|
---|
1955 | answer a reconstructed trans request
|
---|
1956 | */
|
---|
1957 | static void reply_trans_send(struct ntvfs_request *ntvfs)
|
---|
1958 | {
|
---|
1959 | struct smbsrv_request *req;
|
---|
1960 | struct trans_op *op;
|
---|
1961 | struct smb_trans2 *trans;
|
---|
1962 | uint16_t params_left, data_left;
|
---|
1963 | uint8_t *params, *data;
|
---|
1964 | int i;
|
---|
1965 |
|
---|
1966 | SMBSRV_CHECK_ASYNC_STATUS_ERR(op, struct trans_op);
|
---|
1967 | trans = op->trans;
|
---|
1968 |
|
---|
1969 | /* if this function needs work to form the nttrans reply buffer, then
|
---|
1970 | call that now */
|
---|
1971 | if (op->send_fn != NULL) {
|
---|
1972 | NTSTATUS status;
|
---|
1973 | status = op->send_fn(op);
|
---|
1974 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1975 | smbsrv_send_error(req, status);
|
---|
1976 | return;
|
---|
1977 | }
|
---|
1978 | }
|
---|
1979 |
|
---|
1980 | params_left = trans->out.params.length;
|
---|
1981 | data_left = trans->out.data.length;
|
---|
1982 | params = trans->out.params.data;
|
---|
1983 | data = trans->out.data.data;
|
---|
1984 |
|
---|
1985 | smbsrv_setup_reply(req, 10 + trans->out.setup_count, 0);
|
---|
1986 |
|
---|
1987 | if (!NT_STATUS_IS_OK(req->ntvfs->async_states->status)) {
|
---|
1988 | smbsrv_setup_error(req, req->ntvfs->async_states->status);
|
---|
1989 | }
|
---|
1990 |
|
---|
1991 | /* we need to divide up the reply into chunks that fit into
|
---|
1992 | the negotiated buffer size */
|
---|
1993 | do {
|
---|
1994 | uint16_t this_data, this_param, max_bytes;
|
---|
1995 | unsigned int align1 = 1, align2 = (params_left ? 2 : 0);
|
---|
1996 | struct smbsrv_request *this_req;
|
---|
1997 |
|
---|
1998 | max_bytes = req_max_data(req) - (align1 + align2);
|
---|
1999 |
|
---|
2000 | this_param = params_left;
|
---|
2001 | if (this_param > max_bytes) {
|
---|
2002 | this_param = max_bytes;
|
---|
2003 | }
|
---|
2004 | max_bytes -= this_param;
|
---|
2005 |
|
---|
2006 | this_data = data_left;
|
---|
2007 | if (this_data > max_bytes) {
|
---|
2008 | this_data = max_bytes;
|
---|
2009 | }
|
---|
2010 |
|
---|
2011 | /* don't destroy unless this is the last chunk */
|
---|
2012 | if (params_left - this_param != 0 ||
|
---|
2013 | data_left - this_data != 0) {
|
---|
2014 | this_req = smbsrv_setup_secondary_request(req);
|
---|
2015 | } else {
|
---|
2016 | this_req = req;
|
---|
2017 | }
|
---|
2018 |
|
---|
2019 | req_grow_data(this_req, this_param + this_data + (align1 + align2));
|
---|
2020 |
|
---|
2021 | SSVAL(this_req->out.vwv, VWV(0), trans->out.params.length);
|
---|
2022 | SSVAL(this_req->out.vwv, VWV(1), trans->out.data.length);
|
---|
2023 | SSVAL(this_req->out.vwv, VWV(2), 0);
|
---|
2024 |
|
---|
2025 | SSVAL(this_req->out.vwv, VWV(3), this_param);
|
---|
2026 | SSVAL(this_req->out.vwv, VWV(4), align1 + PTR_DIFF(this_req->out.data, this_req->out.hdr));
|
---|
2027 | SSVAL(this_req->out.vwv, VWV(5), PTR_DIFF(params, trans->out.params.data));
|
---|
2028 |
|
---|
2029 | SSVAL(this_req->out.vwv, VWV(6), this_data);
|
---|
2030 | SSVAL(this_req->out.vwv, VWV(7), align1 + align2 +
|
---|
2031 | PTR_DIFF(this_req->out.data + this_param, this_req->out.hdr));
|
---|
2032 | SSVAL(this_req->out.vwv, VWV(8), PTR_DIFF(data, trans->out.data.data));
|
---|
2033 |
|
---|
2034 | SCVAL(this_req->out.vwv, VWV(9), trans->out.setup_count);
|
---|
2035 | SCVAL(this_req->out.vwv, VWV(9)+1, 0); /* reserved */
|
---|
2036 | for (i=0;i<trans->out.setup_count;i++) {
|
---|
2037 | SSVAL(this_req->out.vwv, VWV(10+i), trans->out.setup[i]);
|
---|
2038 | }
|
---|
2039 |
|
---|
2040 | memset(this_req->out.data, 0, align1);
|
---|
2041 | if (this_param != 0) {
|
---|
2042 | memcpy(this_req->out.data + align1, params, this_param);
|
---|
2043 | }
|
---|
2044 | memset(this_req->out.data+this_param+align1, 0, align2);
|
---|
2045 | if (this_data != 0) {
|
---|
2046 | memcpy(this_req->out.data+this_param+align1+align2, data, this_data);
|
---|
2047 | }
|
---|
2048 |
|
---|
2049 | params_left -= this_param;
|
---|
2050 | data_left -= this_data;
|
---|
2051 | params += this_param;
|
---|
2052 | data += this_data;
|
---|
2053 |
|
---|
2054 | smbsrv_send_reply(this_req);
|
---|
2055 | } while (params_left != 0 || data_left != 0);
|
---|
2056 | }
|
---|
2057 |
|
---|
2058 |
|
---|
2059 | /*
|
---|
2060 | answer a reconstructed trans request
|
---|
2061 | */
|
---|
2062 | static void reply_trans_complete(struct smbsrv_request *req, uint8_t command,
|
---|
2063 | struct smb_trans2 *trans)
|
---|
2064 | {
|
---|
2065 | struct trans_op *op;
|
---|
2066 |
|
---|
2067 | SMBSRV_TALLOC_IO_PTR(op, struct trans_op);
|
---|
2068 | SMBSRV_SETUP_NTVFS_REQUEST(reply_trans_send, NTVFS_ASYNC_STATE_MAY_ASYNC);
|
---|
2069 |
|
---|
2070 | op->req = req;
|
---|
2071 | op->trans = trans;
|
---|
2072 | op->command = command;
|
---|
2073 | op->op_info = NULL;
|
---|
2074 | op->send_fn = NULL;
|
---|
2075 |
|
---|
2076 | /* its a full request, give it to the backend */
|
---|
2077 | if (command == SMBtrans) {
|
---|
2078 | SMBSRV_CALL_NTVFS_BACKEND(ntvfs_trans(req->ntvfs, trans));
|
---|
2079 | return;
|
---|
2080 | } else {
|
---|
2081 | SMBSRV_CALL_NTVFS_BACKEND(trans2_backend(req, op));
|
---|
2082 | return;
|
---|
2083 | }
|
---|
2084 | }
|
---|
2085 |
|
---|
2086 | /*
|
---|
2087 | Reply to an SMBtrans or SMBtrans2 request
|
---|
2088 | */
|
---|
2089 | static void reply_trans_generic(struct smbsrv_request *req, uint8_t command)
|
---|
2090 | {
|
---|
2091 | struct smb_trans2 *trans;
|
---|
2092 | int i;
|
---|
2093 | uint16_t param_ofs, data_ofs;
|
---|
2094 | uint16_t param_count, data_count;
|
---|
2095 | uint16_t param_total, data_total;
|
---|
2096 |
|
---|
2097 | /* parse request */
|
---|
2098 | if (req->in.wct < 14) {
|
---|
2099 | smbsrv_send_error(req, NT_STATUS_INVALID_PARAMETER);
|
---|
2100 | return;
|
---|
2101 | }
|
---|
2102 |
|
---|
2103 | trans = talloc(req, struct smb_trans2);
|
---|
2104 | if (trans == NULL) {
|
---|
2105 | smbsrv_send_error(req, NT_STATUS_NO_MEMORY);
|
---|
2106 | return;
|
---|
2107 | }
|
---|
2108 |
|
---|
2109 | param_total = SVAL(req->in.vwv, VWV(0));
|
---|
2110 | data_total = SVAL(req->in.vwv, VWV(1));
|
---|
2111 | trans->in.max_param = SVAL(req->in.vwv, VWV(2));
|
---|
2112 | trans->in.max_data = SVAL(req->in.vwv, VWV(3));
|
---|
2113 | trans->in.max_setup = CVAL(req->in.vwv, VWV(4));
|
---|
2114 | trans->in.flags = SVAL(req->in.vwv, VWV(5));
|
---|
2115 | trans->in.timeout = IVAL(req->in.vwv, VWV(6));
|
---|
2116 | param_count = SVAL(req->in.vwv, VWV(9));
|
---|
2117 | param_ofs = SVAL(req->in.vwv, VWV(10));
|
---|
2118 | data_count = SVAL(req->in.vwv, VWV(11));
|
---|
2119 | data_ofs = SVAL(req->in.vwv, VWV(12));
|
---|
2120 | trans->in.setup_count = CVAL(req->in.vwv, VWV(13));
|
---|
2121 |
|
---|
2122 | if (req->in.wct != 14 + trans->in.setup_count) {
|
---|
2123 | smbsrv_send_error(req, NT_STATUS_DOS(ERRSRV, ERRerror));
|
---|
2124 | return;
|
---|
2125 | }
|
---|
2126 |
|
---|
2127 | /* parse out the setup words */
|
---|
2128 | trans->in.setup = talloc_array(trans, uint16_t, trans->in.setup_count);
|
---|
2129 | if (trans->in.setup_count && !trans->in.setup) {
|
---|
2130 | smbsrv_send_error(req, NT_STATUS_NO_MEMORY);
|
---|
2131 | return;
|
---|
2132 | }
|
---|
2133 | for (i=0;i<trans->in.setup_count;i++) {
|
---|
2134 | trans->in.setup[i] = SVAL(req->in.vwv, VWV(14+i));
|
---|
2135 | }
|
---|
2136 |
|
---|
2137 | if (command == SMBtrans) {
|
---|
2138 | req_pull_string(&req->in.bufinfo, &trans->in.trans_name, req->in.data, -1, STR_TERMINATE);
|
---|
2139 | }
|
---|
2140 |
|
---|
2141 | if (!req_pull_blob(&req->in.bufinfo, req->in.hdr + param_ofs, param_count, &trans->in.params) ||
|
---|
2142 | !req_pull_blob(&req->in.bufinfo, req->in.hdr + data_ofs, data_count, &trans->in.data)) {
|
---|
2143 | smbsrv_send_error(req, NT_STATUS_FOOBAR);
|
---|
2144 | return;
|
---|
2145 | }
|
---|
2146 |
|
---|
2147 | /* is it a partial request? if so, then send a 'send more' message */
|
---|
2148 | if (param_total > param_count || data_total > data_count) {
|
---|
2149 | reply_trans_continue(req, command, trans);
|
---|
2150 | return;
|
---|
2151 | }
|
---|
2152 |
|
---|
2153 | reply_trans_complete(req, command, trans);
|
---|
2154 | }
|
---|
2155 |
|
---|
2156 |
|
---|
2157 | /*
|
---|
2158 | Reply to an SMBtranss2 request
|
---|
2159 | */
|
---|
2160 | static void reply_transs_generic(struct smbsrv_request *req, uint8_t command)
|
---|
2161 | {
|
---|
2162 | struct smbsrv_trans_partial *tp;
|
---|
2163 | struct smb_trans2 *trans = NULL;
|
---|
2164 | uint16_t param_ofs, data_ofs;
|
---|
2165 | uint16_t param_count, data_count;
|
---|
2166 | uint16_t param_disp, data_disp;
|
---|
2167 | uint16_t param_total, data_total;
|
---|
2168 | DATA_BLOB params, data;
|
---|
2169 | uint8_t wct;
|
---|
2170 |
|
---|
2171 | if (command == SMBtrans2) {
|
---|
2172 | wct = 9;
|
---|
2173 | } else {
|
---|
2174 | wct = 8;
|
---|
2175 | }
|
---|
2176 |
|
---|
2177 | /* parse request */
|
---|
2178 | if (req->in.wct != wct) {
|
---|
2179 | /*
|
---|
2180 | * TODO: add some error code tests
|
---|
2181 | * w2k3 returns NT_STATUS_DOS(ERRSRV, ERRerror) here
|
---|
2182 | */
|
---|
2183 | smbsrv_send_error(req, NT_STATUS_INVALID_PARAMETER);
|
---|
2184 | return;
|
---|
2185 | }
|
---|
2186 |
|
---|
2187 | for (tp=req->smb_conn->trans_partial;tp;tp=tp->next) {
|
---|
2188 | if (tp->command == command &&
|
---|
2189 | SVAL(tp->req->in.hdr, HDR_MID) == SVAL(req->in.hdr, HDR_MID)) {
|
---|
2190 | /* TODO: check the VUID, PID and TID too? */
|
---|
2191 | break;
|
---|
2192 | }
|
---|
2193 | }
|
---|
2194 |
|
---|
2195 | if (tp == NULL) {
|
---|
2196 | smbsrv_send_error(req, NT_STATUS_INVALID_PARAMETER);
|
---|
2197 | return;
|
---|
2198 | }
|
---|
2199 |
|
---|
2200 | trans = tp->u.trans;
|
---|
2201 |
|
---|
2202 | param_total = SVAL(req->in.vwv, VWV(0));
|
---|
2203 | data_total = SVAL(req->in.vwv, VWV(1));
|
---|
2204 | param_count = SVAL(req->in.vwv, VWV(2));
|
---|
2205 | param_ofs = SVAL(req->in.vwv, VWV(3));
|
---|
2206 | param_disp = SVAL(req->in.vwv, VWV(4));
|
---|
2207 | data_count = SVAL(req->in.vwv, VWV(5));
|
---|
2208 | data_ofs = SVAL(req->in.vwv, VWV(6));
|
---|
2209 | data_disp = SVAL(req->in.vwv, VWV(7));
|
---|
2210 |
|
---|
2211 | if (!req_pull_blob(&req->in.bufinfo, req->in.hdr + param_ofs, param_count, ¶ms) ||
|
---|
2212 | !req_pull_blob(&req->in.bufinfo, req->in.hdr + data_ofs, data_count, &data)) {
|
---|
2213 | smbsrv_send_error(req, NT_STATUS_INVALID_PARAMETER);
|
---|
2214 | return;
|
---|
2215 | }
|
---|
2216 |
|
---|
2217 | /* only allow contiguous requests */
|
---|
2218 | if ((param_count != 0 &&
|
---|
2219 | param_disp != trans->in.params.length) ||
|
---|
2220 | (data_count != 0 &&
|
---|
2221 | data_disp != trans->in.data.length)) {
|
---|
2222 | smbsrv_send_error(req, NT_STATUS_INVALID_PARAMETER);
|
---|
2223 | return;
|
---|
2224 | }
|
---|
2225 |
|
---|
2226 | /* add to the existing request */
|
---|
2227 | if (param_count != 0) {
|
---|
2228 | trans->in.params.data = talloc_realloc(trans,
|
---|
2229 | trans->in.params.data,
|
---|
2230 | uint8_t,
|
---|
2231 | param_disp + param_count);
|
---|
2232 | if (trans->in.params.data == NULL) {
|
---|
2233 | smbsrv_send_error(tp->req, NT_STATUS_NO_MEMORY);
|
---|
2234 | return;
|
---|
2235 | }
|
---|
2236 | trans->in.params.length = param_disp + param_count;
|
---|
2237 | }
|
---|
2238 |
|
---|
2239 | if (data_count != 0) {
|
---|
2240 | trans->in.data.data = talloc_realloc(trans,
|
---|
2241 | trans->in.data.data,
|
---|
2242 | uint8_t,
|
---|
2243 | data_disp + data_count);
|
---|
2244 | if (trans->in.data.data == NULL) {
|
---|
2245 | smbsrv_send_error(tp->req, NT_STATUS_NO_MEMORY);
|
---|
2246 | return;
|
---|
2247 | }
|
---|
2248 | trans->in.data.length = data_disp + data_count;
|
---|
2249 | }
|
---|
2250 |
|
---|
2251 | memcpy(trans->in.params.data + param_disp, params.data, params.length);
|
---|
2252 | memcpy(trans->in.data.data + data_disp, data.data, data.length);
|
---|
2253 |
|
---|
2254 | /* the sequence number of the reply is taken from the last secondary
|
---|
2255 | response */
|
---|
2256 | tp->req->seq_num = req->seq_num;
|
---|
2257 |
|
---|
2258 | /* we don't reply to Transs2 requests */
|
---|
2259 | talloc_free(req);
|
---|
2260 |
|
---|
2261 | if (trans->in.params.length == param_total &&
|
---|
2262 | trans->in.data.length == data_total) {
|
---|
2263 | /* its now complete */
|
---|
2264 | req = tp->req;
|
---|
2265 | talloc_free(tp);
|
---|
2266 | reply_trans_complete(req, command, trans);
|
---|
2267 | }
|
---|
2268 | return;
|
---|
2269 | }
|
---|
2270 |
|
---|
2271 |
|
---|
2272 | /*
|
---|
2273 | Reply to an SMBtrans2
|
---|
2274 | */
|
---|
2275 | void smbsrv_reply_trans2(struct smbsrv_request *req)
|
---|
2276 | {
|
---|
2277 | reply_trans_generic(req, SMBtrans2);
|
---|
2278 | }
|
---|
2279 |
|
---|
2280 | /*
|
---|
2281 | Reply to an SMBtrans
|
---|
2282 | */
|
---|
2283 | void smbsrv_reply_trans(struct smbsrv_request *req)
|
---|
2284 | {
|
---|
2285 | reply_trans_generic(req, SMBtrans);
|
---|
2286 | }
|
---|
2287 |
|
---|
2288 | /*
|
---|
2289 | Reply to an SMBtranss request
|
---|
2290 | */
|
---|
2291 | void smbsrv_reply_transs(struct smbsrv_request *req)
|
---|
2292 | {
|
---|
2293 | reply_transs_generic(req, SMBtrans);
|
---|
2294 | }
|
---|
2295 |
|
---|
2296 | /*
|
---|
2297 | Reply to an SMBtranss2 request
|
---|
2298 | */
|
---|
2299 | void smbsrv_reply_transs2(struct smbsrv_request *req)
|
---|
2300 | {
|
---|
2301 | reply_transs_generic(req, SMBtrans2);
|
---|
2302 | }
|
---|