r4591: - converted the other _p talloc functions to not need _p
[jelmer/samba4-debian.git] / source / smb_server / trans2.c
1 /* 
2    Unix SMB/CIFS implementation.
3    transaction2 handling
4    Copyright (C) Andrew Tridgell 2003
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20 /*
21    This file handles the parsing of transact2 requests
22 */
23
24 #include "includes.h"
25 #include "dlinklist.h"
26 #include "smb_server/smb_server.h"
27
28
29
30 #define CHECK_MIN_BLOB_SIZE(blob, size) do { \
31         if ((blob)->length < (size)) { \
32                 return NT_STATUS_INFO_LENGTH_MISMATCH; \
33         }} while (0)
34
35 /* grow the data allocation size of a trans2 reply - this guarantees
36    that requests to grow the data size later will not change the
37    pointer */
38 static BOOL trans2_grow_data_allocation(struct smbsrv_request *req, 
39                                         struct smb_trans2 *trans,
40                                         uint32_t new_size)
41 {
42         if (new_size <= trans->out.data.length) {
43                 return True;
44         }
45         trans->out.data.data = talloc_realloc(req, trans->out.data.data, 
46                                               uint8_t, new_size);
47         return (trans->out.data.data != NULL);
48 }
49
50
51 /* grow the data size of a trans2 reply */
52 static BOOL trans2_grow_data(struct smbsrv_request *req, 
53                              struct smb_trans2 *trans,
54                              uint32_t new_size)
55 {
56         if (!trans2_grow_data_allocation(req, trans, new_size)) {
57                 return False;
58         }
59         trans->out.data.length = new_size;
60         return True;
61 }
62
63 /* grow the data, zero filling any new bytes */
64 static BOOL trans2_grow_data_fill(struct smbsrv_request *req, 
65                                   struct smb_trans2 *trans,
66                                   uint32_t new_size)
67 {
68         uint32_t old_size = trans->out.data.length;
69         if (!trans2_grow_data(req, trans, new_size)) {
70                 return False;
71         }
72         if (new_size > old_size) {
73                 memset(trans->out.data.data + old_size, 0, new_size - old_size);
74         }
75         return True;
76 }
77
78
79 /* setup a trans2 reply, given the data and params sizes */
80 static void trans2_setup_reply(struct smbsrv_request *req, 
81                                struct smb_trans2 *trans,
82                                uint16_t param_size, uint16_t data_size,
83                                uint16_t setup_count)
84 {
85         trans->out.setup_count = setup_count;
86         if (setup_count != 0) {
87                 trans->out.setup = talloc_zero_array(req, uint16_t, setup_count);
88         }
89         trans->out.params = data_blob_talloc(req, NULL, param_size);
90         trans->out.data = data_blob_talloc(req, NULL, data_size);
91 }
92
93
94 /*
95   pull a string from a blob in a trans2 request
96 */
97 static size_t trans2_pull_blob_string(struct smbsrv_request *req, 
98                                       const DATA_BLOB *blob,
99                                       uint16_t offset,
100                                       const char **str,
101                                       int flags)
102 {
103         /* we use STR_NO_RANGE_CHECK because the params are allocated
104            separately in a DATA_BLOB, so we need to do our own range
105            checking */
106         if (offset >= blob->length) {
107                 *str = NULL;
108                 return 0;
109         }
110         
111         return req_pull_string(req, str, 
112                                blob->data + offset, 
113                                blob->length - offset,
114                                STR_NO_RANGE_CHECK | flags);
115 }
116
117 /*
118   push a string into the data section of a trans2 request
119   return the number of bytes consumed in the output
120 */
121 static size_t trans2_push_data_string(struct smbsrv_request *req, 
122                                       struct smb_trans2 *trans,
123                                       uint32_t len_offset,
124                                       uint32_t offset,
125                                       const WIRE_STRING *str,
126                                       int dest_len,
127                                       int flags)
128 {
129         int alignment = 0, ret = 0, pkt_len;
130
131         /* we use STR_NO_RANGE_CHECK because the params are allocated
132            separately in a DATA_BLOB, so we need to do our own range
133            checking */
134         if (!str->s || offset >= trans->out.data.length) {
135                 if (flags & STR_LEN8BIT) {
136                         SCVAL(trans->out.data.data, len_offset, 0);
137                 } else {
138                         SIVAL(trans->out.data.data, len_offset, 0);
139                 }
140                 return 0;
141         }
142
143         flags |= STR_NO_RANGE_CHECK;
144
145         if (dest_len == -1 || (dest_len > trans->out.data.length - offset)) {
146                 dest_len = trans->out.data.length - offset;
147         }
148
149         if (!(flags & (STR_ASCII|STR_UNICODE))) {
150                 flags |= (req->flags2 & FLAGS2_UNICODE_STRINGS) ? STR_UNICODE : STR_ASCII;
151         }
152
153         if ((offset&1) && (flags & STR_UNICODE) && !(flags & STR_NOALIGN)) {
154                 alignment = 1;
155                 if (dest_len > 0) {
156                         SCVAL(trans->out.data.data + offset, 0, 0);
157                         ret = push_string(trans->out.data.data + offset + 1, str->s, dest_len-1, flags);
158                 }
159         } else {
160                 ret = push_string(trans->out.data.data + offset, str->s, dest_len, flags);
161         }
162
163         /* sometimes the string needs to be terminated, but the length
164            on the wire must not include the termination! */
165         pkt_len = ret;
166
167         if ((flags & STR_LEN_NOTERM) && (flags & STR_TERMINATE)) {
168                 if ((flags & STR_UNICODE) && ret >= 2) {
169                         pkt_len = ret-2;
170                 }
171                 if ((flags & STR_ASCII) && ret >= 1) {
172                         pkt_len = ret-1;
173                 }
174         }       
175
176         if (flags & STR_LEN8BIT) {
177                 SCVAL(trans->out.data.data, len_offset, pkt_len);
178         } else {
179                 SIVAL(trans->out.data.data, len_offset, pkt_len);
180         }
181
182         return ret + alignment;
183 }
184
185 /*
186   append a string to the data section of a trans2 reply
187   len_offset points to the place in the packet where the length field
188   should go
189 */
190 static void trans2_append_data_string(struct smbsrv_request *req, 
191                                         struct smb_trans2 *trans,
192                                         const WIRE_STRING *str,
193                                         uint_t len_offset,
194                                         int flags)
195 {
196         size_t ret;
197         uint32_t offset;
198         const int max_bytes_per_char = 3;
199
200         offset = trans->out.data.length;
201         trans2_grow_data(req, trans, offset + (2+strlen_m(str->s))*max_bytes_per_char);
202         ret = trans2_push_data_string(req, trans, len_offset, offset, str, -1, flags);
203         trans2_grow_data(req, trans, offset + ret);
204 }
205
206 /*
207   align the end of the data section of a trans reply on an even boundary
208 */
209 static void trans2_align_data(struct smbsrv_request *req, struct smb_trans2 *trans)
210 {
211         if ((trans->out.data.length & 1) == 0) {
212                 return;
213         }
214         trans2_grow_data(req, trans, trans->out.data.length+1);
215         SCVAL(trans->out.data.data, trans->out.data.length-1, 0);
216 }
217
218
219 /*
220   trans2 qfsinfo implementation
221 */
222 static NTSTATUS trans2_qfsinfo(struct smbsrv_request *req, struct smb_trans2 *trans)
223 {
224         union smb_fsinfo fsinfo;
225         NTSTATUS status;
226         uint16_t level;
227         uint_t i;
228         DATA_BLOB guid_blob;
229
230         /* make sure we got enough parameters */
231         if (trans->in.params.length != 2) {
232                 return NT_STATUS_FOOBAR;
233         }
234
235         level = SVAL(trans->in.params.data, 0);
236
237         switch (level) {
238         case SMB_QFS_ALLOCATION:
239                 fsinfo.allocation.level = RAW_QFS_ALLOCATION;
240
241                 status = ntvfs_fsinfo(req, &fsinfo);
242                 if (!NT_STATUS_IS_OK(status)) {
243                         return status;
244                 }
245
246                 trans2_setup_reply(req, trans, 0, 18, 0);
247
248                 SIVAL(trans->out.data.data,  0, fsinfo.allocation.out.fs_id);
249                 SIVAL(trans->out.data.data,  4, fsinfo.allocation.out.sectors_per_unit);
250                 SIVAL(trans->out.data.data,  8, fsinfo.allocation.out.total_alloc_units);
251                 SIVAL(trans->out.data.data, 12, fsinfo.allocation.out.avail_alloc_units);
252                 SSVAL(trans->out.data.data, 16, fsinfo.allocation.out.bytes_per_sector);
253
254                 return NT_STATUS_OK;
255
256         case SMB_QFS_VOLUME:
257                 fsinfo.volume.level = RAW_QFS_VOLUME;
258
259                 status = ntvfs_fsinfo(req, &fsinfo);
260                 if (!NT_STATUS_IS_OK(status)) {
261                         return status;
262                 }
263
264                 trans2_setup_reply(req, trans, 0, 5, 0);
265
266                 SIVAL(trans->out.data.data,       0, fsinfo.volume.out.serial_number);
267                 /* w2k3 implements this incorrectly for unicode - it
268                  * leaves the last byte off the string */
269                 trans2_append_data_string(req, trans, 
270                                           &fsinfo.volume.out.volume_name, 
271                                           4, STR_LEN8BIT|STR_NOALIGN);
272
273                 return NT_STATUS_OK;
274
275         case SMB_QFS_VOLUME_INFO:
276         case SMB_QFS_VOLUME_INFORMATION:
277                 fsinfo.volume_info.level = RAW_QFS_VOLUME_INFO;
278
279                 status = ntvfs_fsinfo(req, &fsinfo);
280                 if (!NT_STATUS_IS_OK(status)) {
281                         return status;
282                 }
283
284                 trans2_setup_reply(req, trans, 0, 18, 0);
285
286                 push_nttime(trans->out.data.data, 0, fsinfo.volume_info.out.create_time);
287                 SIVAL(trans->out.data.data,       8, fsinfo.volume_info.out.serial_number);
288                 SSVAL(trans->out.data.data,      16, 0); /* padding */
289                 trans2_append_data_string(req, trans, 
290                                           &fsinfo.volume_info.out.volume_name, 
291                                           12, STR_UNICODE);
292
293                 return NT_STATUS_OK;
294
295         case SMB_QFS_SIZE_INFO:
296         case SMB_QFS_SIZE_INFORMATION:
297                 fsinfo.size_info.level = RAW_QFS_SIZE_INFO;
298
299                 status = ntvfs_fsinfo(req, &fsinfo);
300                 if (!NT_STATUS_IS_OK(status)) {
301                         return status;
302                 }
303
304                 trans2_setup_reply(req, trans, 0, 24, 0);
305
306                 SBVAL(trans->out.data.data,  0, fsinfo.size_info.out.total_alloc_units);
307                 SBVAL(trans->out.data.data,  8, fsinfo.size_info.out.avail_alloc_units);
308                 SIVAL(trans->out.data.data, 16, fsinfo.size_info.out.sectors_per_unit);
309                 SIVAL(trans->out.data.data, 20, fsinfo.size_info.out.bytes_per_sector);
310
311                 return NT_STATUS_OK;
312
313         case SMB_QFS_DEVICE_INFO:
314         case SMB_QFS_DEVICE_INFORMATION:
315                 fsinfo.device_info.level = RAW_QFS_DEVICE_INFO;
316
317                 status = ntvfs_fsinfo(req, &fsinfo);
318                 if (!NT_STATUS_IS_OK(status)) {
319                         return status;
320                 }
321                 trans2_setup_reply(req, trans, 0, 8, 0);
322                 SIVAL(trans->out.data.data,      0, fsinfo.device_info.out.device_type);
323                 SIVAL(trans->out.data.data,      4, fsinfo.device_info.out.characteristics);
324                 return NT_STATUS_OK;
325
326
327         case SMB_QFS_ATTRIBUTE_INFO:
328         case SMB_QFS_ATTRIBUTE_INFORMATION:
329                 fsinfo.attribute_info.level = RAW_QFS_ATTRIBUTE_INFO;
330
331                 status = ntvfs_fsinfo(req, &fsinfo);
332                 if (!NT_STATUS_IS_OK(status)) {
333                         return status;
334                 }
335
336                 trans2_setup_reply(req, trans, 0, 12, 0);
337
338                 SIVAL(trans->out.data.data, 0, fsinfo.attribute_info.out.fs_attr);
339                 SIVAL(trans->out.data.data, 4, fsinfo.attribute_info.out.max_file_component_length);
340                 /* this must not be null terminated or win98 gets
341                    confused!  also note that w2k3 returns this as
342                    unicode even when ascii is negotiated */
343                 trans2_append_data_string(req, trans, 
344                                           &fsinfo.attribute_info.out.fs_type,
345                                           8, STR_UNICODE);
346                 return NT_STATUS_OK;
347
348
349         case SMB_QFS_QUOTA_INFORMATION:
350                 fsinfo.quota_information.level = RAW_QFS_QUOTA_INFORMATION;
351
352                 status = ntvfs_fsinfo(req, &fsinfo);
353                 if (!NT_STATUS_IS_OK(status)) {
354                         return status;
355                 }
356
357                 trans2_setup_reply(req, trans, 0, 48, 0);
358
359                 SBVAL(trans->out.data.data,   0, fsinfo.quota_information.out.unknown[0]);
360                 SBVAL(trans->out.data.data,   8, fsinfo.quota_information.out.unknown[1]);
361                 SBVAL(trans->out.data.data,  16, fsinfo.quota_information.out.unknown[2]);
362                 SBVAL(trans->out.data.data,  24, fsinfo.quota_information.out.quota_soft);
363                 SBVAL(trans->out.data.data,  32, fsinfo.quota_information.out.quota_hard);
364                 SBVAL(trans->out.data.data,  40, fsinfo.quota_information.out.quota_flags);
365
366                 return NT_STATUS_OK;
367
368
369         case SMB_QFS_FULL_SIZE_INFORMATION:
370                 fsinfo.full_size_information.level = RAW_QFS_FULL_SIZE_INFORMATION;
371
372                 status = ntvfs_fsinfo(req, &fsinfo);
373                 if (!NT_STATUS_IS_OK(status)) {
374                         return status;
375                 }
376
377                 trans2_setup_reply(req, trans, 0, 32, 0);
378
379                 SBVAL(trans->out.data.data,  0, fsinfo.full_size_information.out.total_alloc_units);
380                 SBVAL(trans->out.data.data,  8, fsinfo.full_size_information.out.call_avail_alloc_units);
381                 SBVAL(trans->out.data.data, 16, fsinfo.full_size_information.out.actual_avail_alloc_units);
382                 SIVAL(trans->out.data.data, 24, fsinfo.full_size_information.out.sectors_per_unit);
383                 SIVAL(trans->out.data.data, 28, fsinfo.full_size_information.out.bytes_per_sector);
384
385                 return NT_STATUS_OK;
386
387         case SMB_QFS_OBJECTID_INFORMATION:
388                 fsinfo.objectid_information.level = RAW_QFS_OBJECTID_INFORMATION;
389
390                 status = ntvfs_fsinfo(req, &fsinfo);
391                 if (!NT_STATUS_IS_OK(status)) {
392                         return status;
393                 }
394
395                 trans2_setup_reply(req, trans, 0, 64, 0);
396
397                 status = ndr_push_struct_blob(&guid_blob, req, 
398                                               &fsinfo.objectid_information.out.guid,
399                                               (ndr_push_flags_fn_t)ndr_push_GUID);
400                 if (!NT_STATUS_IS_OK(status)) {
401                         return status;
402                 }
403
404                 memcpy(trans->out.data.data, guid_blob.data, guid_blob.length);
405
406                 for (i=0;i<6;i++) {
407                         SBVAL(trans->out.data.data, 16 + 8*i, fsinfo.objectid_information.out.unknown[i]);
408                 }
409                 return NT_STATUS_OK;
410         }
411
412         return NT_STATUS_INVALID_LEVEL;
413 }
414
415
416 /*
417   trans2 open implementation
418 */
419 static NTSTATUS trans2_open(struct smbsrv_request *req, struct smb_trans2 *trans)
420 {
421         union smb_open *io;
422         NTSTATUS status;
423
424         /* make sure we got enough parameters */
425         if (trans->in.params.length < 29) {
426                 return NT_STATUS_FOOBAR;
427         }
428
429         io = talloc_p(req, union smb_open);
430         if (io == NULL) {
431                 return NT_STATUS_NO_MEMORY;
432         }
433
434         io->t2open.level         = RAW_OPEN_T2OPEN;
435         io->t2open.in.flags      = SVAL(trans->in.params.data, VWV(0));
436         io->t2open.in.open_mode  = SVAL(trans->in.params.data, VWV(1));
437         io->t2open.in.file_attrs = SVAL(trans->in.params.data, VWV(3));
438         io->t2open.in.write_time = srv_pull_dos_date(req->smb_conn, 
439                                                     trans->in.params.data + VWV(4));;
440         io->t2open.in.open_func  = SVAL(trans->in.params.data, VWV(6));
441         io->t2open.in.size       = IVAL(trans->in.params.data, VWV(7));
442         io->t2open.in.timeout    = IVAL(trans->in.params.data, VWV(9));
443         io->t2open.in.num_eas    = 0;
444         io->t2open.in.eas        = NULL;
445
446         trans2_pull_blob_string(req, &trans->in.params, 28, &io->t2open.in.fname, 0);
447
448         status = ea_pull_list(&trans->in.data, io, &io->t2open.in.num_eas, &io->t2open.in.eas);
449         if (!NT_STATUS_IS_OK(status)) {
450                 return status;
451         }
452
453         status = ntvfs_openfile(req, io);
454         if (!NT_STATUS_IS_OK(status)) {
455                 return status;
456         }
457
458         trans2_setup_reply(req, trans, 30, 0, 0);
459
460         SSVAL(trans->out.params.data, VWV(0), io->t2open.out.fnum);
461         SSVAL(trans->out.params.data, VWV(1), io->t2open.out.attrib);
462         srv_push_dos_date3(req->smb_conn, trans->out.params.data, 
463                            VWV(2), io->t2open.out.write_time);
464         SIVAL(trans->out.params.data, VWV(4), io->t2open.out.size);
465         SSVAL(trans->out.params.data, VWV(6), io->t2open.out.access);
466         SSVAL(trans->out.params.data, VWV(7), io->t2open.out.ftype);
467         SSVAL(trans->out.params.data, VWV(8), io->t2open.out.devstate);
468         SSVAL(trans->out.params.data, VWV(9), io->t2open.out.action);
469         SIVAL(trans->out.params.data, VWV(10), 0); /* reserved */
470         SSVAL(trans->out.params.data, VWV(12), 0); /* EaErrorOffset */
471         SIVAL(trans->out.params.data, VWV(13), 0); /* EaLength */
472
473         return status;
474 }
475
476
477 /*
478   trans2 mkdir implementation
479 */
480 static NTSTATUS trans2_mkdir(struct smbsrv_request *req, struct smb_trans2 *trans)
481 {
482         union smb_mkdir *io;
483         NTSTATUS status;
484
485         /* make sure we got enough parameters */
486         if (trans->in.params.length < 5) {
487                 return NT_STATUS_FOOBAR;
488         }
489
490         io = talloc_p(req, union smb_mkdir);
491         if (io == NULL) {
492                 return NT_STATUS_NO_MEMORY;
493         }
494
495         io->t2mkdir.level = RAW_MKDIR_T2MKDIR;
496         trans2_pull_blob_string(req, &trans->in.params, 4, &io->t2mkdir.in.path, 0);
497
498         status = ea_pull_list(&trans->in.data, io, 
499                               &io->t2mkdir.in.num_eas, 
500                               &io->t2mkdir.in.eas);
501         if (!NT_STATUS_IS_OK(status)) {
502                 return status;
503         }
504
505         status = ntvfs_mkdir(req, io);
506         if (!NT_STATUS_IS_OK(status)) {
507                 return status;
508         }
509
510         trans2_setup_reply(req, trans, 2, 0, 0);
511
512         SSVAL(trans->out.params.data, VWV(0), 0);
513
514         return status;
515 }
516
517 /*
518   fill in the reply from a qpathinfo or qfileinfo call
519 */
520 static NTSTATUS trans2_fileinfo_fill(struct smbsrv_request *req, struct smb_trans2 *trans,
521                                      union smb_fileinfo *st)
522 {
523         uint_t i;
524         uint32_t list_size;
525         
526         switch (st->generic.level) {
527         case RAW_FILEINFO_GENERIC:
528         case RAW_FILEINFO_GETATTR:
529         case RAW_FILEINFO_GETATTRE:
530         case RAW_FILEINFO_SEC_DESC:
531                 /* handled elsewhere */
532                 return NT_STATUS_INVALID_LEVEL;
533
534         case RAW_FILEINFO_BASIC_INFO:
535         case RAW_FILEINFO_BASIC_INFORMATION:
536                 trans2_setup_reply(req, trans, 2, 40, 0);
537
538                 SSVAL(trans->out.params.data, 0, 0);
539                 push_nttime(trans->out.data.data,  0, st->basic_info.out.create_time);
540                 push_nttime(trans->out.data.data,  8, st->basic_info.out.access_time);
541                 push_nttime(trans->out.data.data, 16, st->basic_info.out.write_time);
542                 push_nttime(trans->out.data.data, 24, st->basic_info.out.change_time);
543                 SIVAL(trans->out.data.data,       32, st->basic_info.out.attrib);
544                 SIVAL(trans->out.data.data,       36, 0); /* padding */
545                 return NT_STATUS_OK;
546
547         case RAW_FILEINFO_STANDARD:
548                 trans2_setup_reply(req, trans, 2, 22, 0);
549
550                 SSVAL(trans->out.params.data, 0, 0);
551                 srv_push_dos_date2(req->smb_conn, trans->out.data.data, 0, st->standard.out.create_time);
552                 srv_push_dos_date2(req->smb_conn, trans->out.data.data, 4, st->standard.out.access_time);
553                 srv_push_dos_date2(req->smb_conn, trans->out.data.data, 8, st->standard.out.write_time);
554                 SIVAL(trans->out.data.data,        12, st->standard.out.size);
555                 SIVAL(trans->out.data.data,        16, st->standard.out.alloc_size);
556                 SSVAL(trans->out.data.data,        20, st->standard.out.attrib);
557                 return NT_STATUS_OK;
558
559         case RAW_FILEINFO_EA_SIZE:
560                 trans2_setup_reply(req, trans, 2, 26, 0);
561
562                 SSVAL(trans->out.params.data, 0, 0);
563                 srv_push_dos_date2(req->smb_conn, trans->out.data.data, 0, st->ea_size.out.create_time);
564                 srv_push_dos_date2(req->smb_conn, trans->out.data.data, 4, st->ea_size.out.access_time);
565                 srv_push_dos_date2(req->smb_conn, trans->out.data.data, 8, st->ea_size.out.write_time);
566                 SIVAL(trans->out.data.data,        12, st->ea_size.out.size);
567                 SIVAL(trans->out.data.data,        16, st->ea_size.out.alloc_size);
568                 SSVAL(trans->out.data.data,        20, st->ea_size.out.attrib);
569                 SIVAL(trans->out.data.data,        22, st->ea_size.out.ea_size);
570                 return NT_STATUS_OK;
571
572         case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
573                 trans2_setup_reply(req, trans, 2, 56, 0);
574
575                 SSVAL(trans->out.params.data, 0, 0);
576                 push_nttime(trans->out.data.data,  0, st->network_open_information.out.create_time);
577                 push_nttime(trans->out.data.data,  8, st->network_open_information.out.access_time);
578                 push_nttime(trans->out.data.data, 16, st->network_open_information.out.write_time);
579                 push_nttime(trans->out.data.data, 24, st->network_open_information.out.change_time);
580                 SBVAL(trans->out.data.data,       32, st->network_open_information.out.alloc_size);
581                 SBVAL(trans->out.data.data,       40, st->network_open_information.out.size);
582                 SIVAL(trans->out.data.data,       48, st->network_open_information.out.attrib);
583                 SIVAL(trans->out.data.data,       52, 0); /* padding */
584                 return NT_STATUS_OK;
585
586         case RAW_FILEINFO_STANDARD_INFO:
587         case RAW_FILEINFO_STANDARD_INFORMATION:
588                 trans2_setup_reply(req, trans, 2, 24, 0);
589                 SSVAL(trans->out.params.data, 0, 0);
590                 SBVAL(trans->out.data.data,  0, st->standard_info.out.alloc_size);
591                 SBVAL(trans->out.data.data,  8, st->standard_info.out.size);
592                 SIVAL(trans->out.data.data, 16, st->standard_info.out.nlink);
593                 SCVAL(trans->out.data.data, 20, st->standard_info.out.delete_pending);
594                 SCVAL(trans->out.data.data, 21, st->standard_info.out.directory);
595                 SSVAL(trans->out.data.data, 22, 0); /* padding */
596                 return NT_STATUS_OK;
597
598         case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
599                 trans2_setup_reply(req, trans, 2, 8, 0);
600                 SSVAL(trans->out.params.data, 0, 0);
601                 SIVAL(trans->out.data.data,  0, st->attribute_tag_information.out.attrib);
602                 SIVAL(trans->out.data.data,  4, st->attribute_tag_information.out.reparse_tag);
603                 return NT_STATUS_OK;
604
605         case RAW_FILEINFO_EA_INFO:
606         case RAW_FILEINFO_EA_INFORMATION:
607                 trans2_setup_reply(req, trans, 2, 4, 0);
608                 SSVAL(trans->out.params.data, 0, 0);
609                 SIVAL(trans->out.data.data,  0, st->ea_info.out.ea_size);
610                 return NT_STATUS_OK;
611
612         case RAW_FILEINFO_MODE_INFORMATION:
613                 trans2_setup_reply(req, trans, 2, 4, 0);
614                 SSVAL(trans->out.params.data, 0, 0);
615                 SIVAL(trans->out.data.data,  0, st->mode_information.out.mode);
616                 return NT_STATUS_OK;
617
618         case RAW_FILEINFO_ALIGNMENT_INFORMATION:
619                 trans2_setup_reply(req, trans, 2, 4, 0);
620                 SSVAL(trans->out.params.data, 0, 0);
621                 SIVAL(trans->out.data.data,  0, 
622                       st->alignment_information.out.alignment_requirement);
623                 return NT_STATUS_OK;
624
625         case RAW_FILEINFO_EA_LIST:
626                 list_size = ea_list_size(st->ea_list.out.num_eas,
627                                          st->ea_list.out.eas);
628                 trans2_setup_reply(req, trans, 2, list_size, 0);
629                 SSVAL(trans->out.params.data, 0, 0);
630                 ea_put_list(trans->out.data.data, 
631                             st->ea_list.out.num_eas, st->ea_list.out.eas);
632                 return NT_STATUS_OK;
633
634         case RAW_FILEINFO_ALL_EAS:
635                 list_size = ea_list_size(st->all_eas.out.num_eas,
636                                                   st->all_eas.out.eas);
637                 trans2_setup_reply(req, trans, 2, list_size, 0);
638                 SSVAL(trans->out.params.data, 0, 0);
639                 ea_put_list(trans->out.data.data, 
640                             st->all_eas.out.num_eas, st->all_eas.out.eas);
641                 return NT_STATUS_OK;
642
643         case RAW_FILEINFO_ACCESS_INFORMATION:
644                 trans2_setup_reply(req, trans, 2, 4, 0);
645                 SSVAL(trans->out.params.data, 0, 0);
646                 SIVAL(trans->out.data.data,  0, st->access_information.out.access_flags);
647                 return NT_STATUS_OK;
648
649         case RAW_FILEINFO_POSITION_INFORMATION:
650                 trans2_setup_reply(req, trans, 2, 8, 0);
651                 SSVAL(trans->out.params.data, 0, 0);
652                 SBVAL(trans->out.data.data,  0, st->position_information.out.position);
653                 return NT_STATUS_OK;
654
655         case RAW_FILEINFO_COMPRESSION_INFO:
656         case RAW_FILEINFO_COMPRESSION_INFORMATION:
657                 trans2_setup_reply(req, trans, 2, 16, 0);
658                 SSVAL(trans->out.params.data, 0, 0);
659                 SBVAL(trans->out.data.data,  0, st->compression_info.out.compressed_size);
660                 SSVAL(trans->out.data.data,  8, st->compression_info.out.format);
661                 SCVAL(trans->out.data.data, 10, st->compression_info.out.unit_shift);
662                 SCVAL(trans->out.data.data, 11, st->compression_info.out.chunk_shift);
663                 SCVAL(trans->out.data.data, 12, st->compression_info.out.cluster_shift);
664                 SSVAL(trans->out.data.data, 13, 0); /* 3 bytes padding */
665                 SCVAL(trans->out.data.data, 15, 0);
666                 return NT_STATUS_OK;
667
668         case RAW_FILEINFO_IS_NAME_VALID:
669                 trans2_setup_reply(req, trans, 2, 0, 0);
670                 SSVAL(trans->out.params.data, 0, 0);
671                 return NT_STATUS_OK;
672
673         case RAW_FILEINFO_INTERNAL_INFORMATION:
674                 trans2_setup_reply(req, trans, 2, 8, 0);
675                 SSVAL(trans->out.params.data, 0, 0);
676                 SBVAL(trans->out.data.data,  0, st->internal_information.out.file_id);
677                 return NT_STATUS_OK;
678
679         case RAW_FILEINFO_ALL_INFO:
680         case RAW_FILEINFO_ALL_INFORMATION:
681                 trans2_setup_reply(req, trans, 2, 72, 0);
682
683                 SSVAL(trans->out.params.data, 0, 0);
684                 push_nttime(trans->out.data.data,  0, st->all_info.out.create_time);
685                 push_nttime(trans->out.data.data,  8, st->all_info.out.access_time);
686                 push_nttime(trans->out.data.data, 16, st->all_info.out.write_time);
687                 push_nttime(trans->out.data.data, 24, st->all_info.out.change_time);
688                 SIVAL(trans->out.data.data,       32, st->all_info.out.attrib);
689                 SIVAL(trans->out.data.data,       36, 0);
690                 SBVAL(trans->out.data.data,       40, st->all_info.out.alloc_size);
691                 SBVAL(trans->out.data.data,       48, st->all_info.out.size);
692                 SIVAL(trans->out.data.data,       56, st->all_info.out.nlink);
693                 SCVAL(trans->out.data.data,       60, st->all_info.out.delete_pending);
694                 SCVAL(trans->out.data.data,       61, st->all_info.out.directory);
695                 SSVAL(trans->out.data.data,       62, 0); /* padding */
696                 SIVAL(trans->out.data.data,       64, st->all_info.out.ea_size);
697                 trans2_append_data_string(req, trans, &st->all_info.out.fname, 
698                                           68, STR_UNICODE);
699                 return NT_STATUS_OK;
700
701         case RAW_FILEINFO_NAME_INFO:
702         case RAW_FILEINFO_NAME_INFORMATION:
703                 trans2_setup_reply(req, trans, 2, 4, 0);
704                 SSVAL(trans->out.params.data, 0, 0);
705                 trans2_append_data_string(req, trans, &st->name_info.out.fname, 0, STR_UNICODE);
706                 return NT_STATUS_OK;
707
708         case RAW_FILEINFO_ALT_NAME_INFO:
709         case RAW_FILEINFO_ALT_NAME_INFORMATION:
710                 trans2_setup_reply(req, trans, 2, 4, 0);
711                 SSVAL(trans->out.params.data, 0, 0);
712                 trans2_append_data_string(req, trans, &st->alt_name_info.out.fname, 0, STR_UNICODE);
713                 return NT_STATUS_OK;
714
715         case RAW_FILEINFO_STREAM_INFO:
716         case RAW_FILEINFO_STREAM_INFORMATION:
717                 trans2_setup_reply(req, trans, 2, 0, 0);
718
719                 SSVAL(trans->out.params.data, 0, 0);
720
721                 for (i=0;i<st->stream_info.out.num_streams;i++) {
722                         uint32_t data_size = trans->out.data.length;
723                         uint8_t *data;
724
725                         trans2_grow_data(req, trans, data_size + 24);
726                         data = trans->out.data.data + data_size;
727                         SBVAL(data,  8, st->stream_info.out.streams[i].size);
728                         SBVAL(data, 16, st->stream_info.out.streams[i].alloc_size);
729                         trans2_append_data_string(req, trans, 
730                                                   &st->stream_info.out.streams[i].stream_name, 
731                                                   data_size + 4, STR_UNICODE);
732                         if (i == st->stream_info.out.num_streams - 1) {
733                                 SIVAL(trans->out.data.data, data_size, 0);
734                         } else {
735                                 trans2_grow_data_fill(req, trans, (trans->out.data.length+7)&~7);
736                                 SIVAL(trans->out.data.data, data_size, 
737                                       trans->out.data.length - data_size);
738                         }
739                 }
740                 return NT_STATUS_OK;
741         }
742
743         return NT_STATUS_INVALID_LEVEL;
744 }
745
746 /*
747   trans2 qpathinfo implementation
748 */
749 static NTSTATUS trans2_qpathinfo(struct smbsrv_request *req, struct smb_trans2 *trans)
750 {
751         union smb_fileinfo st;
752         NTSTATUS status;
753         uint16_t level;
754
755         /* make sure we got enough parameters */
756         if (trans->in.params.length < 2) {
757                 return NT_STATUS_FOOBAR;
758         }
759
760         level = SVAL(trans->in.params.data, 0);
761
762         trans2_pull_blob_string(req, &trans->in.params, 6, &st.generic.in.fname, 0);
763         if (st.generic.in.fname == NULL) {
764                 return NT_STATUS_FOOBAR;
765         }
766
767         /* work out the backend level - we make it 1-1 in the header */
768         st.generic.level = (enum smb_fileinfo_level)level;
769         if (st.generic.level >= RAW_FILEINFO_GENERIC) {
770                 return NT_STATUS_INVALID_LEVEL;
771         }
772
773         if (st.generic.level == RAW_FILEINFO_EA_LIST) {
774                 status = ea_pull_name_list(&trans->in.data, req, 
775                                            &st.ea_list.in.num_names,
776                                            &st.ea_list.in.ea_names);
777                 if (!NT_STATUS_IS_OK(status)) {
778                         return status;
779                 }
780         }
781
782         /* call the backend */
783         status = ntvfs_qpathinfo(req, &st);
784         if (!NT_STATUS_IS_OK(status)) {
785                 return status;
786         }
787
788         /* fill in the reply parameters */
789         status = trans2_fileinfo_fill(req, trans, &st);
790
791         return status;
792 }
793
794
795 /*
796   trans2 qpathinfo implementation
797 */
798 static NTSTATUS trans2_qfileinfo(struct smbsrv_request *req, struct smb_trans2 *trans)
799 {
800         union smb_fileinfo st;
801         NTSTATUS status;
802         uint16_t level;
803
804         /* make sure we got enough parameters */
805         if (trans->in.params.length < 4) {
806                 return NT_STATUS_FOOBAR;
807         }
808
809         st.generic.in.fnum  = SVAL(trans->in.params.data, 0);
810         level = SVAL(trans->in.params.data, 2);
811
812         /* work out the backend level - we make it 1-1 in the header */
813         st.generic.level = (enum smb_fileinfo_level)level;
814         if (st.generic.level >= RAW_FILEINFO_GENERIC) {
815                 return NT_STATUS_INVALID_LEVEL;
816         }
817
818         if (st.generic.level == RAW_FILEINFO_EA_LIST) {
819                 status = ea_pull_name_list(&trans->in.data, req, 
820                                            &st.ea_list.in.num_names,
821                                            &st.ea_list.in.ea_names);
822                 if (!NT_STATUS_IS_OK(status)) {
823                         return status;
824                 }
825         }
826
827         /* call the backend */
828         status = ntvfs_qfileinfo(req, &st);
829         if (!NT_STATUS_IS_OK(status)) {
830                 return status;
831         }
832
833         /* fill in the reply parameters */
834         status = trans2_fileinfo_fill(req, trans, &st);
835
836         return status;
837 }
838
839
840 /*
841   parse a trans2 setfileinfo/setpathinfo data blob
842 */
843 static NTSTATUS trans2_parse_sfileinfo(struct smbsrv_request *req,
844                                        union smb_setfileinfo *st,
845                                        const DATA_BLOB *blob)
846 {
847         uint32_t len;
848
849         switch (st->generic.level) {
850         case RAW_SFILEINFO_GENERIC:
851         case RAW_SFILEINFO_SETATTR:
852         case RAW_SFILEINFO_SETATTRE:
853         case RAW_SFILEINFO_SEC_DESC:
854                 /* handled elsewhere */
855                 return NT_STATUS_INVALID_LEVEL;
856
857         case RAW_SFILEINFO_STANDARD:
858                 CHECK_MIN_BLOB_SIZE(blob, 12);
859                 st->standard.in.create_time = srv_pull_dos_date2(req->smb_conn, blob->data + 0);
860                 st->standard.in.access_time = srv_pull_dos_date2(req->smb_conn, blob->data + 4);
861                 st->standard.in.write_time  = srv_pull_dos_date2(req->smb_conn, blob->data + 8);
862                 return NT_STATUS_OK;
863
864         case RAW_SFILEINFO_EA_SET:
865                 return ea_pull_list(blob, req, 
866                                     &st->ea_set.in.num_eas, 
867                                     &st->ea_set.in.eas);
868
869         case SMB_SFILEINFO_BASIC_INFO:
870         case SMB_SFILEINFO_BASIC_INFORMATION:
871                 CHECK_MIN_BLOB_SIZE(blob, 36);
872                 st->basic_info.in.create_time = pull_nttime(blob->data,  0);
873                 st->basic_info.in.access_time = pull_nttime(blob->data,  8);
874                 st->basic_info.in.write_time =  pull_nttime(blob->data, 16);
875                 st->basic_info.in.change_time = pull_nttime(blob->data, 24);
876                 st->basic_info.in.attrib =      IVAL(blob->data,        32);
877                 return NT_STATUS_OK;
878
879         case SMB_SFILEINFO_DISPOSITION_INFO:
880         case SMB_SFILEINFO_DISPOSITION_INFORMATION:
881                 CHECK_MIN_BLOB_SIZE(blob, 1);
882                 st->disposition_info.in.delete_on_close = CVAL(blob->data, 0);
883                 return NT_STATUS_OK;
884
885         case SMB_SFILEINFO_ALLOCATION_INFO:
886         case SMB_SFILEINFO_ALLOCATION_INFORMATION:
887                 CHECK_MIN_BLOB_SIZE(blob, 8);
888                 st->allocation_info.in.alloc_size = BVAL(blob->data, 0);
889                 return NT_STATUS_OK;                            
890
891         case RAW_SFILEINFO_END_OF_FILE_INFO:
892         case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
893                 CHECK_MIN_BLOB_SIZE(blob, 8);
894                 st->end_of_file_info.in.size = BVAL(blob->data, 0);
895                 return NT_STATUS_OK;
896
897         case RAW_SFILEINFO_RENAME_INFORMATION: {
898                 DATA_BLOB blob2;
899
900                 CHECK_MIN_BLOB_SIZE(blob, 12);
901                 st->rename_information.in.overwrite = CVAL(blob->data, 0);
902                 st->rename_information.in.root_fid  = IVAL(blob->data, 4);
903                 len                                 = IVAL(blob->data, 8);
904                 blob2.data = blob->data+12;
905                 blob2.length = MIN(blob->length, len);
906                 trans2_pull_blob_string(req, &blob2, 0, 
907                                         &st->rename_information.in.new_name, STR_UNICODE);
908                 return NT_STATUS_OK;
909         }
910
911         case RAW_SFILEINFO_POSITION_INFORMATION:
912                 CHECK_MIN_BLOB_SIZE(blob, 8);
913                 st->position_information.in.position = BVAL(blob->data, 0);
914                 return NT_STATUS_OK;
915
916         case RAW_SFILEINFO_MODE_INFORMATION:
917                 CHECK_MIN_BLOB_SIZE(blob, 4);
918                 st->mode_information.in.mode = IVAL(blob->data, 0);
919                 return NT_STATUS_OK;
920         }
921
922         return NT_STATUS_INVALID_LEVEL;
923 }
924
925 /*
926   trans2 setfileinfo implementation
927 */
928 static NTSTATUS trans2_setfileinfo(struct smbsrv_request *req, struct smb_trans2 *trans)
929 {
930         union smb_setfileinfo st;
931         NTSTATUS status;
932         uint16_t level, fnum;
933         DATA_BLOB *blob;
934
935         /* make sure we got enough parameters */
936         if (trans->in.params.length < 4) {
937                 return NT_STATUS_FOOBAR;
938         }
939
940         fnum  = SVAL(trans->in.params.data, 0);
941         level = SVAL(trans->in.params.data, 2);
942
943         blob = &trans->in.data;
944
945         st.generic.file.fnum = fnum;
946         st.generic.level = (enum smb_setfileinfo_level)level;
947
948         status = trans2_parse_sfileinfo(req, &st, blob);
949         if (!NT_STATUS_IS_OK(status)) {
950                 return status;
951         }
952
953         status = ntvfs_setfileinfo(req, &st);
954         if (!NT_STATUS_IS_OK(status)) {
955                 return status;
956         }
957
958         trans2_setup_reply(req, trans, 2, 0, 0);
959         SSVAL(trans->out.params.data, 0, 0);
960         return NT_STATUS_OK;
961 }
962
963 /*
964   trans2 setpathinfo implementation
965 */
966 static NTSTATUS trans2_setpathinfo(struct smbsrv_request *req, struct smb_trans2 *trans)
967 {
968         union smb_setfileinfo st;
969         NTSTATUS status;
970         uint16_t level;
971         DATA_BLOB *blob;
972
973         /* make sure we got enough parameters */
974         if (trans->in.params.length < 4) {
975                 return NT_STATUS_FOOBAR;
976         }
977
978         level = SVAL(trans->in.params.data, 0);
979         blob = &trans->in.data;
980         st.generic.level = (enum smb_setfileinfo_level)level;
981
982         trans2_pull_blob_string(req, &trans->in.params, 6, &st.generic.file.fname, 0);
983         if (st.generic.file.fname == NULL) {
984                 return NT_STATUS_FOOBAR;
985         }
986
987         status = trans2_parse_sfileinfo(req, &st, blob);
988         if (!NT_STATUS_IS_OK(status)) {
989                 return status;
990         }
991
992         status = ntvfs_setpathinfo(req, &st);
993         if (!NT_STATUS_IS_OK(status)) {
994                 return status;
995         }
996
997         trans2_setup_reply(req, trans, 2, 0, 0);
998         SSVAL(trans->out.params.data, 0, 0);
999         return NT_STATUS_OK;
1000 }
1001
1002
1003 /* a structure to encapsulate the state information about an in-progress ffirst/fnext operation */
1004 struct find_state {
1005         struct smbsrv_request *req;
1006         struct smb_trans2 *trans;
1007         enum smb_search_level level;
1008         uint16_t last_entry_offset;
1009         uint16_t flags;
1010 };
1011
1012 /*
1013   fill a single entry in a trans2 find reply 
1014 */
1015 static BOOL find_fill_info(struct smbsrv_request *req,
1016                            struct smb_trans2 *trans, 
1017                            struct find_state *state,
1018                            union smb_search_data *file)
1019 {
1020         uint8_t *data;
1021         uint_t ofs = trans->out.data.length;
1022         uint32_t ea_size;
1023
1024         switch (state->level) {
1025         case RAW_SEARCH_SEARCH:
1026         case RAW_SEARCH_FFIRST:
1027         case RAW_SEARCH_FUNIQUE:
1028         case RAW_SEARCH_GENERIC:
1029                 /* handled elsewhere */
1030                 break;
1031
1032         case RAW_SEARCH_STANDARD:
1033                 if (state->flags & FLAG_TRANS2_FIND_REQUIRE_RESUME) {
1034                         trans2_grow_data(req, trans, ofs + 27);
1035                         SIVAL(trans->out.data.data, ofs, file->standard.resume_key);
1036                         ofs += 4;
1037                 } else {
1038                         trans2_grow_data(req, trans, ofs + 23);
1039                 }
1040                 data = trans->out.data.data + ofs;
1041                 srv_push_dos_date2(req->smb_conn, data, 0, file->standard.create_time);
1042                 srv_push_dos_date2(req->smb_conn, data, 4, file->standard.access_time);
1043                 srv_push_dos_date2(req->smb_conn, data, 8, file->standard.write_time);
1044                 SIVAL(data, 12, file->standard.size);
1045                 SIVAL(data, 16, file->standard.alloc_size);
1046                 SSVAL(data, 20, file->standard.attrib);
1047                 trans2_append_data_string(req, trans, &file->standard.name, 
1048                                           ofs + 22, STR_LEN8BIT | STR_TERMINATE | STR_LEN_NOTERM);
1049                 break;
1050
1051         case RAW_SEARCH_EA_SIZE:
1052                 if (state->flags & FLAG_TRANS2_FIND_REQUIRE_RESUME) {
1053                         trans2_grow_data(req, trans, ofs + 31);
1054                         SIVAL(trans->out.data.data, ofs, file->ea_size.resume_key);
1055                         ofs += 4;
1056                 } else {
1057                         trans2_grow_data(req, trans, ofs + 27);
1058                 }
1059                 data = trans->out.data.data + ofs;
1060                 srv_push_dos_date2(req->smb_conn, data, 0, file->ea_size.create_time);
1061                 srv_push_dos_date2(req->smb_conn, data, 4, file->ea_size.access_time);
1062                 srv_push_dos_date2(req->smb_conn, data, 8, file->ea_size.write_time);
1063                 SIVAL(data, 12, file->ea_size.size);
1064                 SIVAL(data, 16, file->ea_size.alloc_size);
1065                 SSVAL(data, 20, file->ea_size.attrib);
1066                 SIVAL(data, 22, file->ea_size.ea_size);
1067                 trans2_append_data_string(req, trans, &file->ea_size.name, 
1068                                           ofs + 26, STR_LEN8BIT | STR_NOALIGN);
1069                 trans2_grow_data(req, trans, trans->out.data.length + 1);
1070                 trans->out.data.data[trans->out.data.length-1] = 0;
1071                 break;
1072
1073         case RAW_SEARCH_EA_LIST:
1074                 ea_size = ea_list_size(file->ea_list.eas.num_eas, file->ea_list.eas.eas);
1075                 if (state->flags & FLAG_TRANS2_FIND_REQUIRE_RESUME) {
1076                         if (!trans2_grow_data(req, trans, ofs + 27 + ea_size)) {
1077                                 return False;
1078                         }
1079                         SIVAL(trans->out.data.data, ofs, file->ea_list.resume_key);
1080                         ofs += 4;
1081                 } else {
1082                         if (!trans2_grow_data(req, trans, ofs + 23 + ea_size)) {
1083                                 return False;
1084                         }
1085                 }
1086                 data = trans->out.data.data + ofs;
1087                 srv_push_dos_date2(req->smb_conn, data, 0, file->ea_list.create_time);
1088                 srv_push_dos_date2(req->smb_conn, data, 4, file->ea_list.access_time);
1089                 srv_push_dos_date2(req->smb_conn, data, 8, file->ea_list.write_time);
1090                 SIVAL(data, 12, file->ea_list.size);
1091                 SIVAL(data, 16, file->ea_list.alloc_size);
1092                 SSVAL(data, 20, file->ea_list.attrib);
1093                 ea_put_list(data+22, file->ea_list.eas.num_eas, file->ea_list.eas.eas);
1094                 trans2_append_data_string(req, trans, &file->ea_list.name, 
1095                                           ofs + 22 + ea_size, STR_LEN8BIT | STR_NOALIGN);
1096                 trans2_grow_data(req, trans, trans->out.data.length + 1);
1097                 trans->out.data.data[trans->out.data.length-1] = 0;
1098                 break;
1099
1100         case RAW_SEARCH_DIRECTORY_INFO:
1101                 trans2_grow_data(req, trans, ofs + 64);
1102                 data = trans->out.data.data + ofs;
1103                 SIVAL(data,          4, file->directory_info.file_index);
1104                 push_nttime(data,    8, file->directory_info.create_time);
1105                 push_nttime(data,   16, file->directory_info.access_time);
1106                 push_nttime(data,   24, file->directory_info.write_time);
1107                 push_nttime(data,   32, file->directory_info.change_time);
1108                 SBVAL(data,         40, file->directory_info.size);
1109                 SBVAL(data,         48, file->directory_info.alloc_size);
1110                 SIVAL(data,         56, file->directory_info.attrib);
1111                 trans2_append_data_string(req, trans, &file->directory_info.name, 
1112                                           ofs + 60, STR_TERMINATE_ASCII);
1113                 data = trans->out.data.data + ofs;
1114                 SIVAL(data,          0, trans->out.data.length - ofs);
1115                 break;
1116
1117         case RAW_SEARCH_FULL_DIRECTORY_INFO:
1118                 trans2_grow_data(req, trans, ofs + 68);
1119                 data = trans->out.data.data + ofs;
1120                 SIVAL(data,          4, file->full_directory_info.file_index);
1121                 push_nttime(data,    8, file->full_directory_info.create_time);
1122                 push_nttime(data,   16, file->full_directory_info.access_time);
1123                 push_nttime(data,   24, file->full_directory_info.write_time);
1124                 push_nttime(data,   32, file->full_directory_info.change_time);
1125                 SBVAL(data,         40, file->full_directory_info.size);
1126                 SBVAL(data,         48, file->full_directory_info.alloc_size);
1127                 SIVAL(data,         56, file->full_directory_info.attrib);
1128                 SIVAL(data,         64, file->full_directory_info.ea_size);
1129                 trans2_append_data_string(req, trans, &file->full_directory_info.name, 
1130                                           ofs + 60, STR_TERMINATE_ASCII);
1131                 data = trans->out.data.data + ofs;
1132                 SIVAL(data,          0, trans->out.data.length - ofs);
1133                 break;
1134
1135         case RAW_SEARCH_NAME_INFO:
1136                 trans2_grow_data(req, trans, ofs + 12);
1137                 data = trans->out.data.data + ofs;
1138                 SIVAL(data,          4, file->name_info.file_index);
1139                 trans2_append_data_string(req, trans, &file->name_info.name, 
1140                                           ofs + 8, STR_TERMINATE_ASCII);
1141                 data = trans->out.data.data + ofs;
1142                 SIVAL(data,          0, trans->out.data.length - ofs);
1143                 break;
1144
1145         case RAW_SEARCH_BOTH_DIRECTORY_INFO:
1146                 trans2_grow_data(req, trans, ofs + 94);
1147                 data = trans->out.data.data + ofs;
1148                 SIVAL(data,          4, file->both_directory_info.file_index);
1149                 push_nttime(data,    8, file->both_directory_info.create_time);
1150                 push_nttime(data,   16, file->both_directory_info.access_time);
1151                 push_nttime(data,   24, file->both_directory_info.write_time);
1152                 push_nttime(data,   32, file->both_directory_info.change_time);
1153                 SBVAL(data,         40, file->both_directory_info.size);
1154                 SBVAL(data,         48, file->both_directory_info.alloc_size);
1155                 SIVAL(data,         56, file->both_directory_info.attrib);
1156                 SIVAL(data,         64, file->both_directory_info.ea_size);
1157                 SCVAL(data,         69, 0); /* reserved */
1158                 memset(data+70,0,24);
1159                 trans2_push_data_string(req, trans, 
1160                                         68 + ofs, 70 + ofs, 
1161                                         &file->both_directory_info.short_name, 
1162                                         24, STR_UNICODE | STR_LEN8BIT);
1163                 trans2_append_data_string(req, trans, &file->both_directory_info.name, 
1164                                           ofs + 60, STR_TERMINATE_ASCII);
1165                 trans2_align_data(req, trans);
1166                 data = trans->out.data.data + ofs;
1167                 SIVAL(data,          0, trans->out.data.length - ofs);
1168                 break;
1169
1170         case RAW_SEARCH_ID_FULL_DIRECTORY_INFO:
1171                 trans2_grow_data(req, trans, ofs + 80);
1172                 data = trans->out.data.data + ofs;
1173                 SIVAL(data,          4, file->id_full_directory_info.file_index);
1174                 push_nttime(data,    8, file->id_full_directory_info.create_time);
1175                 push_nttime(data,   16, file->id_full_directory_info.access_time);
1176                 push_nttime(data,   24, file->id_full_directory_info.write_time);
1177                 push_nttime(data,   32, file->id_full_directory_info.change_time);
1178                 SBVAL(data,         40, file->id_full_directory_info.size);
1179                 SBVAL(data,         48, file->id_full_directory_info.alloc_size);
1180                 SIVAL(data,         56, file->id_full_directory_info.attrib);
1181                 SIVAL(data,         64, file->id_full_directory_info.ea_size);
1182                 SIVAL(data,         68, 0); /* padding */
1183                 SBVAL(data,         72, file->id_full_directory_info.file_id);
1184                 trans2_append_data_string(req, trans, &file->id_full_directory_info.name, 
1185                                           ofs + 60, STR_TERMINATE_ASCII);
1186                 data = trans->out.data.data + ofs;
1187                 SIVAL(data,          0, trans->out.data.length - ofs);
1188                 break;
1189
1190         case RAW_SEARCH_ID_BOTH_DIRECTORY_INFO:
1191                 trans2_grow_data(req, trans, ofs + 104);
1192                 data = trans->out.data.data + ofs;
1193                 SIVAL(data,          4, file->id_both_directory_info.file_index);
1194                 push_nttime(data,    8, file->id_both_directory_info.create_time);
1195                 push_nttime(data,   16, file->id_both_directory_info.access_time);
1196                 push_nttime(data,   24, file->id_both_directory_info.write_time);
1197                 push_nttime(data,   32, file->id_both_directory_info.change_time);
1198                 SBVAL(data,         40, file->id_both_directory_info.size);
1199                 SBVAL(data,         48, file->id_both_directory_info.alloc_size);
1200                 SIVAL(data,         56, file->id_both_directory_info.attrib);
1201                 SIVAL(data,         64, file->id_both_directory_info.ea_size);
1202                 SCVAL(data,         69, 0); /* reserved */
1203                 memset(data+70,0,26);
1204                 trans2_push_data_string(req, trans, 
1205                                         68 + ofs, 70 + ofs, 
1206                                         &file->id_both_directory_info.short_name, 
1207                                         24, STR_UNICODE | STR_LEN8BIT);
1208                 SBVAL(data,         96, file->id_both_directory_info.file_id);
1209                 trans2_append_data_string(req, trans, &file->id_both_directory_info.name, 
1210                                           ofs + 60, STR_TERMINATE_ASCII);
1211                 data = trans->out.data.data + ofs;
1212                 SIVAL(data,          0, trans->out.data.length - ofs);
1213                 break;
1214         }
1215
1216         return True;
1217 }
1218
1219 /* callback function for trans2 findfirst/findnext */
1220 static BOOL find_callback(void *private, union smb_search_data *file)
1221 {
1222         struct find_state *state = (struct find_state *)private;
1223         struct smb_trans2 *trans = state->trans;
1224         uint_t old_length;
1225
1226         old_length = trans->out.data.length;
1227
1228         if (!find_fill_info(state->req, trans, state, file) ||
1229             trans->out.data.length > trans->in.max_data) {
1230                 /* restore the old length and tell the backend to stop */
1231                 trans2_grow_data(state->req, trans, old_length);
1232                 return False;
1233         }
1234
1235         state->last_entry_offset = old_length;  
1236         return True;
1237 }
1238
1239
1240 /*
1241   trans2 findfirst implementation
1242 */
1243 static NTSTATUS trans2_findfirst(struct smbsrv_request *req, struct smb_trans2 *trans)
1244 {
1245         union smb_search_first search;
1246         NTSTATUS status;
1247         uint16_t level;
1248         uint8_t *param;
1249         struct find_state state;
1250
1251         /* make sure we got all the parameters */
1252         if (trans->in.params.length < 14) {
1253                 return NT_STATUS_FOOBAR;
1254         }
1255
1256         search.t2ffirst.in.search_attrib = SVAL(trans->in.params.data, 0);
1257         search.t2ffirst.in.max_count     = SVAL(trans->in.params.data, 2);
1258         search.t2ffirst.in.flags         = SVAL(trans->in.params.data, 4);
1259         level                            = SVAL(trans->in.params.data, 6);
1260         search.t2ffirst.in.storage_type  = IVAL(trans->in.params.data, 8);
1261
1262         trans2_pull_blob_string(req, &trans->in.params, 12, &search.t2ffirst.in.pattern, 0);
1263         if (search.t2ffirst.in.pattern == NULL) {
1264                 return NT_STATUS_FOOBAR;
1265         }
1266
1267         search.t2ffirst.level = (enum smb_search_level)level;
1268         if (search.t2ffirst.level >= RAW_SEARCH_GENERIC) {
1269                 return NT_STATUS_INVALID_LEVEL;
1270         }
1271
1272         if (search.t2ffirst.level == RAW_SEARCH_EA_LIST) {
1273                 status = ea_pull_name_list(&trans->in.data, req,
1274                                            &search.t2ffirst.in.num_names, 
1275                                            &search.t2ffirst.in.ea_names);
1276                 if (!NT_STATUS_IS_OK(status)) {
1277                         return status;
1278                 }
1279         }
1280
1281         /* setup the private state structure that the backend will
1282            give us in the callback */
1283         state.req = req;
1284         state.trans = trans;
1285         state.level = search.t2ffirst.level;
1286         state.last_entry_offset = 0;
1287         state.flags = search.t2ffirst.in.flags;
1288
1289         /* setup for just a header in the reply */
1290         trans2_setup_reply(req, trans, 10, 0, 0);
1291
1292         /* call the backend */
1293         status = ntvfs_search_first(req, &search, &state, find_callback);
1294         if (!NT_STATUS_IS_OK(status)) {
1295                 trans2_setup_reply(req, trans, 0, 0, 0);
1296                 return status;
1297         }
1298
1299         /* fill in the findfirst reply header */
1300         param = trans->out.params.data;
1301         SSVAL(param, VWV(0), search.t2ffirst.out.handle);
1302         SSVAL(param, VWV(1), search.t2ffirst.out.count);
1303         SSVAL(param, VWV(2), search.t2ffirst.out.end_of_search);
1304         SSVAL(param, VWV(3), 0);
1305         SSVAL(param, VWV(4), state.last_entry_offset);
1306
1307         return NT_STATUS_OK;
1308 }
1309
1310
1311 /*
1312   trans2 findnext implementation
1313 */
1314 static NTSTATUS trans2_findnext(struct smbsrv_request *req, struct smb_trans2 *trans)
1315 {
1316         union smb_search_next search;
1317         NTSTATUS status;
1318         uint16_t level;
1319         uint8_t *param;
1320         struct find_state state;
1321
1322         /* make sure we got all the parameters */
1323         if (trans->in.params.length < 12) {
1324                 return NT_STATUS_FOOBAR;
1325         }
1326
1327         search.t2fnext.in.handle        = SVAL(trans->in.params.data, 0);
1328         search.t2fnext.in.max_count     = SVAL(trans->in.params.data, 2);
1329         level                           = SVAL(trans->in.params.data, 4);
1330         search.t2fnext.in.resume_key    = IVAL(trans->in.params.data, 6);
1331         search.t2fnext.in.flags         = SVAL(trans->in.params.data, 10);
1332
1333         trans2_pull_blob_string(req, &trans->in.params, 12, &search.t2fnext.in.last_name, 0);
1334         if (search.t2fnext.in.last_name == NULL) {
1335                 return NT_STATUS_FOOBAR;
1336         }
1337
1338         search.t2fnext.level = (enum smb_search_level)level;
1339         if (search.t2fnext.level >= RAW_SEARCH_GENERIC) {
1340                 return NT_STATUS_INVALID_LEVEL;
1341         }
1342
1343         if (search.t2fnext.level == RAW_SEARCH_EA_LIST) {
1344                 status = ea_pull_name_list(&trans->in.data, req,
1345                                            &search.t2fnext.in.num_names, 
1346                                            &search.t2fnext.in.ea_names);
1347                 if (!NT_STATUS_IS_OK(status)) {
1348                         return status;
1349                 }
1350         }
1351
1352         /* setup the private state structure that the backend will give us in the callback */
1353         state.req = req;
1354         state.trans = trans;
1355         state.level = search.t2fnext.level;
1356         state.last_entry_offset = 0;
1357         state.flags = search.t2fnext.in.flags;
1358
1359         /* setup for just a header in the reply */
1360         trans2_setup_reply(req, trans, 8, 0, 0);
1361
1362         /* call the backend */
1363         status = ntvfs_search_next(req, &search, &state, find_callback);
1364         if (!NT_STATUS_IS_OK(status)) {
1365                 return status;
1366         }
1367
1368         /* fill in the findfirst reply header */
1369         param = trans->out.params.data;
1370         SSVAL(param, VWV(0), search.t2fnext.out.count);
1371         SSVAL(param, VWV(1), search.t2fnext.out.end_of_search);
1372         SSVAL(param, VWV(2), 0);
1373         SSVAL(param, VWV(3), state.last_entry_offset);
1374         
1375         return NT_STATUS_OK;
1376 }
1377
1378
1379 /*
1380   backend for trans2 requests
1381 */
1382 static NTSTATUS trans2_backend(struct smbsrv_request *req, struct smb_trans2 *trans)
1383 {
1384         NTSTATUS status;
1385
1386         /* direct trans2 pass thru */
1387         status = ntvfs_trans2(req, trans);
1388         if (!NT_STATUS_EQUAL(NT_STATUS_NOT_IMPLEMENTED, status)) {
1389                 return status;
1390         }
1391
1392         /* must have at least one setup word */
1393         if (trans->in.setup_count < 1) {
1394                 return NT_STATUS_FOOBAR;
1395         }
1396
1397         /* the trans2 command is in setup[0] */
1398         switch (trans->in.setup[0]) {
1399         case TRANSACT2_FINDFIRST:
1400                 return trans2_findfirst(req, trans);
1401         case TRANSACT2_FINDNEXT:
1402                 return trans2_findnext(req, trans);
1403         case TRANSACT2_QPATHINFO:
1404                 return trans2_qpathinfo(req, trans);
1405         case TRANSACT2_QFILEINFO:
1406                 return trans2_qfileinfo(req, trans);
1407         case TRANSACT2_SETFILEINFO:
1408                 return trans2_setfileinfo(req, trans);
1409         case TRANSACT2_SETPATHINFO:
1410                 return trans2_setpathinfo(req, trans);
1411         case TRANSACT2_QFSINFO:
1412                 return trans2_qfsinfo(req, trans);
1413         case TRANSACT2_OPEN:
1414                 return trans2_open(req, trans);
1415         case TRANSACT2_MKDIR:
1416                 return trans2_mkdir(req, trans);
1417         }
1418
1419         /* an unknown trans2 command */
1420         return NT_STATUS_FOOBAR;
1421 }
1422
1423
1424 /*
1425   send a continue request
1426 */
1427 static void reply_trans_continue(struct smbsrv_request *req, uint8_t command, 
1428                                  struct smb_trans2 *trans)
1429 {
1430         struct smbsrv_trans_partial *tp;
1431         int count;
1432
1433         /* make sure they don't flood us */
1434         for (count=0,tp=req->smb_conn->trans_partial;tp;tp=tp->next) count++;
1435         if (count > 100) {
1436                 req_reply_error(req, NT_STATUS_INSUFFICIENT_RESOURCES);
1437                 return;
1438         }
1439
1440         tp = talloc_p(req, struct smbsrv_trans_partial);
1441
1442         tp->req = talloc_reference(tp, req);
1443         tp->trans = trans;
1444         tp->command = command;
1445
1446         DLIST_ADD(req->smb_conn->trans_partial, tp);
1447
1448         /* send a 'please continue' reply */
1449         req_setup_reply(req, 0, 0);
1450         req_send_reply(req);
1451 }
1452
1453
1454 /*
1455   answer a reconstructed trans request
1456 */
1457 static void reply_trans_complete(struct smbsrv_request *req, uint8_t command, 
1458                                  struct smb_trans2 *trans)
1459 {
1460         uint16_t params_left, data_left;
1461         uint8_t *params, *data;
1462         NTSTATUS status;
1463         int i;
1464
1465         /* its a full request, give it to the backend */
1466         if (command == SMBtrans) {
1467                 status = ntvfs_trans(req, trans);
1468         } else {
1469                 status = trans2_backend(req, trans);
1470         }
1471
1472         if (NT_STATUS_IS_ERR(status)) {
1473                 req_reply_error(req, status);
1474                 return;
1475         }
1476
1477         params_left = trans->out.params.length;
1478         data_left   = trans->out.data.length;
1479         params      = trans->out.params.data;
1480         data        = trans->out.data.data;
1481
1482         req_setup_reply(req, 10 + trans->out.setup_count, 0);
1483
1484         if (!NT_STATUS_IS_OK(status)) {
1485                 req_setup_error(req, status);
1486         }
1487
1488         /* we need to divide up the reply into chunks that fit into
1489            the negotiated buffer size */
1490         do {
1491                 uint16_t this_data, this_param, max_bytes;
1492                 uint_t align1 = 1, align2 = (params_left ? 2 : 0);
1493                 struct smbsrv_request *this_req;
1494
1495                 max_bytes = req_max_data(req) - (align1 + align2);
1496
1497                 this_param = params_left;
1498                 if (this_param > max_bytes) {
1499                         this_param = max_bytes;
1500                 }
1501                 max_bytes -= this_param;
1502
1503                 this_data = data_left;
1504                 if (this_data > max_bytes) {
1505                         this_data = max_bytes;
1506                 }
1507
1508                 /* don't destroy unless this is the last chunk */
1509                 if (params_left - this_param != 0 || 
1510                     data_left - this_data != 0) {
1511                         this_req = req_setup_secondary(req);
1512                 } else {
1513                         this_req = req;
1514                 }
1515
1516                 req_grow_data(this_req, this_param + this_data + (align1 + align2));
1517
1518                 SSVAL(this_req->out.vwv, VWV(0), trans->out.params.length);
1519                 SSVAL(this_req->out.vwv, VWV(1), trans->out.data.length);
1520                 SSVAL(this_req->out.vwv, VWV(2), 0);
1521
1522                 SSVAL(this_req->out.vwv, VWV(3), this_param);
1523                 SSVAL(this_req->out.vwv, VWV(4), align1 + PTR_DIFF(this_req->out.data, this_req->out.hdr));
1524                 SSVAL(this_req->out.vwv, VWV(5), PTR_DIFF(params, trans->out.params.data));
1525
1526                 SSVAL(this_req->out.vwv, VWV(6), this_data);
1527                 SSVAL(this_req->out.vwv, VWV(7), align1 + align2 + 
1528                       PTR_DIFF(this_req->out.data + this_param, this_req->out.hdr));
1529                 SSVAL(this_req->out.vwv, VWV(8), PTR_DIFF(data, trans->out.data.data));
1530
1531                 SSVAL(this_req->out.vwv, VWV(9), trans->out.setup_count);
1532                 for (i=0;i<trans->out.setup_count;i++) {
1533                         SSVAL(this_req->out.vwv, VWV(10+i), trans->out.setup[i]);
1534                 }
1535
1536                 memset(this_req->out.data, 0, align1);
1537                 if (this_param != 0) {
1538                         memcpy(this_req->out.data + align1, params, this_param);
1539                 }
1540                 memset(this_req->out.data+this_param+align1, 0, align2);
1541                 if (this_data != 0) {
1542                         memcpy(this_req->out.data+this_param+align1+align2, data, this_data);
1543                 }
1544
1545                 params_left -= this_param;
1546                 data_left -= this_data;
1547                 params += this_param;
1548                 data += this_data;
1549
1550                 req_send_reply(this_req);
1551         } while (params_left != 0 || data_left != 0);
1552 }
1553
1554
1555 /*
1556   Reply to an SMBtrans or SMBtrans2 request
1557 */
1558 void reply_trans_generic(struct smbsrv_request *req, uint8_t command)
1559 {
1560         struct smb_trans2 *trans;
1561         int i;
1562         uint16_t param_ofs, data_ofs;
1563         uint16_t param_count, data_count;
1564         uint16_t param_total, data_total;
1565
1566         trans = talloc_p(req, struct smb_trans2);
1567         if (trans == NULL) {
1568                 req_reply_error(req, NT_STATUS_NO_MEMORY);
1569                 return;
1570         }
1571
1572         /* parse request */
1573         if (req->in.wct < 14) {
1574                 req_reply_error(req, NT_STATUS_INVALID_PARAMETER);
1575                 return;
1576         }
1577
1578         param_total           = SVAL(req->in.vwv, VWV(0));
1579         data_total            = SVAL(req->in.vwv, VWV(1));
1580         trans->in.max_param   = SVAL(req->in.vwv, VWV(2));
1581         trans->in.max_data    = SVAL(req->in.vwv, VWV(3));
1582         trans->in.max_setup   = CVAL(req->in.vwv, VWV(4));
1583         trans->in.flags       = SVAL(req->in.vwv, VWV(5));
1584         trans->in.timeout     = IVAL(req->in.vwv, VWV(6));
1585         param_count           = SVAL(req->in.vwv, VWV(9));
1586         param_ofs             = SVAL(req->in.vwv, VWV(10));
1587         data_count            = SVAL(req->in.vwv, VWV(11));
1588         data_ofs              = SVAL(req->in.vwv, VWV(12));
1589         trans->in.setup_count = CVAL(req->in.vwv, VWV(13));
1590
1591         if (req->in.wct != 14 + trans->in.setup_count) {
1592                 req_reply_dos_error(req, ERRSRV, ERRerror);
1593                 return;
1594         }
1595
1596         /* parse out the setup words */
1597         trans->in.setup = talloc_array_p(req, uint16_t, trans->in.setup_count);
1598         if (trans->in.setup_count && !trans->in.setup) {
1599                 req_reply_error(req, NT_STATUS_NO_MEMORY);
1600                 return;
1601         }
1602         for (i=0;i<trans->in.setup_count;i++) {
1603                 trans->in.setup[i] = SVAL(req->in.vwv, VWV(14+i));
1604         }
1605
1606         if (command == SMBtrans) {
1607                 req_pull_string(req, &trans->in.trans_name, req->in.data, -1, STR_TERMINATE);
1608         }
1609
1610         if (!req_pull_blob(req, req->in.hdr + param_ofs, param_count, &trans->in.params) ||
1611             !req_pull_blob(req, req->in.hdr + data_ofs, data_count, &trans->in.data)) {
1612                 req_reply_error(req, NT_STATUS_FOOBAR);
1613                 return;
1614         }
1615
1616         /* is it a partial request? if so, then send a 'send more' message */
1617         if (param_total > param_count || data_total > data_count) {
1618                 reply_trans_continue(req, command, trans);
1619                 return;
1620         }
1621
1622         reply_trans_complete(req, command, trans);
1623 }
1624
1625
1626 /*
1627   Reply to an SMBtranss2 request
1628 */
1629 static void reply_transs_generic(struct smbsrv_request *req, uint8_t command)
1630 {
1631         struct smbsrv_trans_partial *tp;
1632         struct smb_trans2 *trans = NULL;
1633         uint16_t param_ofs, data_ofs;
1634         uint16_t param_count, data_count;
1635         uint16_t param_disp, data_disp;
1636         uint16_t param_total, data_total;
1637         DATA_BLOB params, data;
1638
1639         for (tp=req->smb_conn->trans_partial;tp;tp=tp->next) {
1640                 if (tp->command == command &&
1641                     SVAL(tp->req->in.hdr, HDR_MID) == SVAL(req->in.hdr, HDR_MID)) {
1642                         break;
1643                 }
1644         }
1645
1646         if (tp == NULL) {
1647                 req_reply_error(req, NT_STATUS_INVALID_PARAMETER);
1648                 return;
1649         }
1650
1651         trans = tp->trans;
1652
1653         /* parse request */
1654         if (req->in.wct < 8) {
1655                 req_reply_error(req, NT_STATUS_INVALID_PARAMETER);
1656                 return;
1657         }
1658
1659         param_total           = SVAL(req->in.vwv, VWV(0));
1660         data_total            = SVAL(req->in.vwv, VWV(1));
1661         param_count           = SVAL(req->in.vwv, VWV(2));
1662         param_ofs             = SVAL(req->in.vwv, VWV(3));
1663         param_disp            = SVAL(req->in.vwv, VWV(4));
1664         data_count            = SVAL(req->in.vwv, VWV(5));
1665         data_ofs              = SVAL(req->in.vwv, VWV(6));
1666         data_disp             = SVAL(req->in.vwv, VWV(7));
1667
1668         if (!req_pull_blob(req, req->in.hdr + param_ofs, param_count, &params) ||
1669             !req_pull_blob(req, req->in.hdr + data_ofs, data_count, &data)) {
1670                 req_reply_error(req, NT_STATUS_INVALID_PARAMETER);
1671                 return;
1672         }
1673
1674         /* only allow contiguous requests */
1675         if ((param_count != 0 &&
1676              param_disp != trans->in.params.length) ||
1677             (data_count != 0 && 
1678              data_disp != trans->in.data.length)) {
1679                 req_reply_error(req, NT_STATUS_INVALID_PARAMETER);
1680                 return;         
1681         }
1682
1683         /* add to the existing request */
1684         if (param_count != 0) {
1685                 trans->in.params.data = talloc_realloc_p(trans, 
1686                                                          trans->in.params.data, 
1687                                                          uint8_t, 
1688                                                          param_disp + param_count);
1689                 if (trans->in.params.data == NULL) {
1690                         goto failed;
1691                 }
1692                 trans->in.params.length = param_disp + param_count;
1693         }
1694
1695         if (data_count != 0) {
1696                 trans->in.data.data = talloc_realloc_p(trans, 
1697                                                        trans->in.data.data, 
1698                                                        uint8_t, 
1699                                                        data_disp + data_count);
1700                 if (trans->in.data.data == NULL) {
1701                         goto failed;
1702                 }
1703                 trans->in.data.length = data_disp + data_count;
1704         }
1705
1706         memcpy(trans->in.params.data + param_disp, params.data, params.length);
1707         memcpy(trans->in.data.data + data_disp, data.data, data.length);
1708
1709         /* the sequence number of the reply is taken from the last secondary
1710            response */
1711         tp->req->seq_num = req->seq_num;
1712
1713         /* we don't reply to Transs2 requests */
1714         talloc_free(req);
1715
1716         if (trans->in.params.length == param_total &&
1717             trans->in.data.length == data_total) {
1718                 /* its now complete */
1719                 reply_trans_complete(tp->req, command, trans);
1720                 DLIST_REMOVE(tp->req->smb_conn->trans_partial, tp);
1721                 talloc_free(tp);
1722         }
1723         return;
1724
1725 failed: 
1726         req_reply_error(tp->req, NT_STATUS_NO_MEMORY);
1727         DLIST_REMOVE(req->smb_conn->trans_partial, tp);
1728         talloc_free(req);
1729         talloc_free(tp);
1730 }
1731
1732
1733 /*
1734   Reply to an SMBtrans2
1735 */
1736 void reply_trans2(struct smbsrv_request *req)
1737 {
1738         reply_trans_generic(req, SMBtrans2);
1739 }
1740
1741 /*
1742   Reply to an SMBtrans
1743 */
1744 void reply_trans(struct smbsrv_request *req)
1745 {
1746         reply_trans_generic(req, SMBtrans);
1747 }
1748
1749 /*
1750   Reply to an SMBtranss request
1751 */
1752 void reply_transs(struct smbsrv_request *req)
1753 {
1754         reply_transs_generic(req, SMBtrans);
1755 }
1756
1757 /*
1758   Reply to an SMBtranss2 request
1759 */
1760 void reply_transs2(struct smbsrv_request *req)
1761 {
1762         reply_transs_generic(req, SMBtrans2);
1763 }
1764