Merge v4.0-test
[kai/samba.git] / source4 / smb_server / smb / nttrans.c
1 /* 
2    Unix SMB/CIFS implementation.
3    NT transaction handling
4    Copyright (C) Andrew Tridgell 2003
5    Copyright (C) James J Myers 2003 <myersjj@samba.org>
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 "smb_server/smb_server.h"
26 #include "ntvfs/ntvfs.h"
27 #include "libcli/raw/libcliraw.h"
28 #include "librpc/gen_ndr/ndr_security.h"
29 #include "param/param.h"
30
31 /*
32   hold the state of a nttrans op while in progress. Needed to allow for async backend
33   functions.
34 */
35 struct nttrans_op {
36         struct smb_nttrans *trans;
37         NTSTATUS (*send_fn)(struct nttrans_op *);
38         void *op_info;
39 };
40
41
42 /* setup a nttrans reply, given the data and params sizes */
43 static NTSTATUS nttrans_setup_reply(struct nttrans_op *op, 
44                                     struct smb_nttrans *trans,
45                                     uint32_t param_size, uint32_t data_size,
46                                     uint8_t setup_count)
47 {
48         trans->out.setup_count = setup_count;
49         if (setup_count != 0) {
50                 trans->out.setup = talloc_zero_array(op, uint8_t, setup_count*2);
51                 NT_STATUS_HAVE_NO_MEMORY(trans->out.setup);
52         }
53         trans->out.params = data_blob_talloc(op, NULL, param_size);
54         if (param_size != 0) {
55                 NT_STATUS_HAVE_NO_MEMORY(trans->out.params.data);
56         }
57         trans->out.data = data_blob_talloc(op, NULL, data_size);
58         if (data_size != 0) {
59                 NT_STATUS_HAVE_NO_MEMORY(trans->out.data.data);
60         }
61         return NT_STATUS_OK;
62 }
63
64 /*
65   send a nttrans create reply
66 */
67 static NTSTATUS nttrans_create_send(struct nttrans_op *op)
68 {
69         union smb_open *io = talloc_get_type(op->op_info, union smb_open);
70         uint8_t *params;
71         NTSTATUS status;
72
73         status = nttrans_setup_reply(op, op->trans, 69, 0, 0);
74         NT_STATUS_NOT_OK_RETURN(status);
75         params = op->trans->out.params.data;
76
77         SSVAL(params,        0, io->ntcreatex.out.oplock_level);
78         smbsrv_push_fnum(params, 2, io->ntcreatex.out.file.ntvfs);
79         SIVAL(params,        4, io->ntcreatex.out.create_action);
80         SIVAL(params,        8, 0); /* ea error offset */
81         push_nttime(params, 12, io->ntcreatex.out.create_time);
82         push_nttime(params, 20, io->ntcreatex.out.access_time);
83         push_nttime(params, 28, io->ntcreatex.out.write_time);
84         push_nttime(params, 36, io->ntcreatex.out.change_time);
85         SIVAL(params,       44, io->ntcreatex.out.attrib);
86         SBVAL(params,       48, io->ntcreatex.out.alloc_size);
87         SBVAL(params,       56, io->ntcreatex.out.size);
88         SSVAL(params,       64, io->ntcreatex.out.file_type);
89         SSVAL(params,       66, io->ntcreatex.out.ipc_state);
90         SCVAL(params,       68, io->ntcreatex.out.is_directory);
91
92         return NT_STATUS_OK;
93 }
94
95 /* 
96    parse NTTRANS_CREATE request
97  */
98 static NTSTATUS nttrans_create(struct smbsrv_request *req, 
99                                struct nttrans_op *op)
100 {
101         struct smb_nttrans *trans = op->trans;
102         union smb_open *io;
103         uint16_t fname_len;
104         uint32_t sd_length, ea_length;
105         NTSTATUS status;
106         uint8_t *params;
107         enum ndr_err_code ndr_err;
108
109         if (trans->in.params.length < 54) {
110                 return NT_STATUS_INVALID_PARAMETER;
111         }
112
113         /* parse the request */
114         io = talloc(op, union smb_open);
115         NT_STATUS_HAVE_NO_MEMORY(io);
116
117         io->ntcreatex.level = RAW_OPEN_NTTRANS_CREATE;
118
119         params = trans->in.params.data;
120
121         io->ntcreatex.in.flags            = IVAL(params,  0);
122         io->ntcreatex.in.root_fid         = IVAL(params,  4);
123         io->ntcreatex.in.access_mask      = IVAL(params,  8);
124         io->ntcreatex.in.alloc_size       = BVAL(params, 12);
125         io->ntcreatex.in.file_attr        = IVAL(params, 20);
126         io->ntcreatex.in.share_access     = IVAL(params, 24);
127         io->ntcreatex.in.open_disposition = IVAL(params, 28);
128         io->ntcreatex.in.create_options   = IVAL(params, 32);
129         sd_length                         = IVAL(params, 36);
130         ea_length                         = IVAL(params, 40);
131         fname_len                         = IVAL(params, 44);
132         io->ntcreatex.in.impersonation    = IVAL(params, 48);
133         io->ntcreatex.in.security_flags   = CVAL(params, 52);
134         io->ntcreatex.in.sec_desc         = NULL;
135         io->ntcreatex.in.ea_list          = NULL;
136
137         req_pull_string(&req->in.bufinfo, &io->ntcreatex.in.fname, 
138                         params + 53, 
139                         MIN(fname_len+1, trans->in.params.length - 53),
140                         STR_NO_RANGE_CHECK | STR_TERMINATE);
141         if (!io->ntcreatex.in.fname) {
142                 return NT_STATUS_INVALID_PARAMETER;
143         }
144
145         if (sd_length > trans->in.data.length ||
146             ea_length > trans->in.data.length ||
147             (sd_length+ea_length) > trans->in.data.length) {
148                 return NT_STATUS_INVALID_PARAMETER;
149         }
150
151         /* this call has an optional security descriptor */
152         if (sd_length != 0) {
153                 DATA_BLOB blob;
154                 blob.data = trans->in.data.data;
155                 blob.length = sd_length;
156                 io->ntcreatex.in.sec_desc = talloc(io, struct security_descriptor);
157                 if (io->ntcreatex.in.sec_desc == NULL) {
158                         return NT_STATUS_NO_MEMORY;
159                 }
160                 ndr_err = ndr_pull_struct_blob(&blob, io, NULL,
161                                                io->ntcreatex.in.sec_desc,
162                                                (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
163                 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
164                         return ndr_map_error2ntstatus(ndr_err);
165                 }
166         }
167
168         /* and an optional ea_list */
169         if (ea_length > 4) {
170                 DATA_BLOB blob;
171                 blob.data = trans->in.data.data + sd_length;
172                 blob.length = ea_length;
173                 io->ntcreatex.in.ea_list = talloc(io, struct smb_ea_list);
174                 if (io->ntcreatex.in.ea_list == NULL) {
175                         return NT_STATUS_NO_MEMORY;
176                 }
177
178                 status = ea_pull_list_chained(&blob, io, 
179                                               &io->ntcreatex.in.ea_list->num_eas,
180                                               &io->ntcreatex.in.ea_list->eas);
181                 if (!NT_STATUS_IS_OK(status)) {
182                         return status;
183                 }
184         }
185
186         op->send_fn = nttrans_create_send;
187         op->op_info = io;
188
189         return ntvfs_open(req->ntvfs, io);
190 }
191
192
193 /* 
194    send NTTRANS_QUERY_SEC_DESC reply
195  */
196 static NTSTATUS nttrans_query_sec_desc_send(struct nttrans_op *op)
197 {
198         union smb_fileinfo *io = talloc_get_type(op->op_info, union smb_fileinfo);
199         uint8_t *params;
200         NTSTATUS status;
201         enum ndr_err_code ndr_err;
202
203         status = nttrans_setup_reply(op, op->trans, 4, 0, 0);
204         NT_STATUS_NOT_OK_RETURN(status);
205         params = op->trans->out.params.data;
206
207         ndr_err = ndr_push_struct_blob(&op->trans->out.data, op, NULL,
208                                        io->query_secdesc.out.sd,
209                                        (ndr_push_flags_fn_t)ndr_push_security_descriptor);
210         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
211                 return ndr_map_error2ntstatus(ndr_err);
212         }
213
214         SIVAL(params, 0, op->trans->out.data.length);
215
216         return NT_STATUS_OK;
217 }
218
219 /* 
220    parse NTTRANS_QUERY_SEC_DESC request
221  */
222 static NTSTATUS nttrans_query_sec_desc(struct smbsrv_request *req, 
223                                        struct nttrans_op *op)
224 {
225         struct smb_nttrans *trans = op->trans;
226         union smb_fileinfo *io;
227
228         if (trans->in.params.length < 8) {
229                 return NT_STATUS_INVALID_PARAMETER;
230         }
231
232         /* parse the request */
233         io = talloc(op, union smb_fileinfo);
234         NT_STATUS_HAVE_NO_MEMORY(io);
235
236         io->query_secdesc.level            = RAW_FILEINFO_SEC_DESC;
237         io->query_secdesc.in.file.ntvfs    = smbsrv_pull_fnum(req, trans->in.params.data, 0);
238         io->query_secdesc.in.secinfo_flags = IVAL(trans->in.params.data, 4);
239
240         op->op_info = io;
241         op->send_fn = nttrans_query_sec_desc_send;
242
243         SMBSRV_CHECK_FILE_HANDLE_NTSTATUS(io->query_secdesc.in.file.ntvfs);
244         return ntvfs_qfileinfo(req->ntvfs, io);
245 }
246
247
248 /* 
249    parse NTTRANS_SET_SEC_DESC request
250  */
251 static NTSTATUS nttrans_set_sec_desc(struct smbsrv_request *req, 
252                                      struct nttrans_op *op)
253 {
254         struct smb_nttrans *trans = op->trans;
255         union smb_setfileinfo *io;
256         enum ndr_err_code ndr_err;
257
258         if (trans->in.params.length < 8) {
259                 return NT_STATUS_INVALID_PARAMETER;
260         }
261
262         /* parse the request */
263         io = talloc(req, union smb_setfileinfo);
264         NT_STATUS_HAVE_NO_MEMORY(io);
265
266         io->set_secdesc.level            = RAW_SFILEINFO_SEC_DESC;
267         io->set_secdesc.in.file.ntvfs    = smbsrv_pull_fnum(req, trans->in.params.data, 0);
268         io->set_secdesc.in.secinfo_flags = IVAL(trans->in.params.data, 4);
269
270         io->set_secdesc.in.sd = talloc(io, struct security_descriptor);
271         NT_STATUS_HAVE_NO_MEMORY(io->set_secdesc.in.sd);
272
273         ndr_err = ndr_pull_struct_blob(&trans->in.data, req, NULL,
274                                        io->set_secdesc.in.sd,
275                                        (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
276         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
277                 return ndr_map_error2ntstatus(ndr_err);
278         }
279
280         SMBSRV_CHECK_FILE_HANDLE_NTSTATUS(io->set_secdesc.in.file.ntvfs);
281         return ntvfs_setfileinfo(req->ntvfs, io);
282 }
283
284
285 /* parse NTTRANS_RENAME request
286  */
287 static NTSTATUS nttrans_rename(struct smbsrv_request *req, 
288                                struct nttrans_op *op)
289 {
290         struct smb_nttrans *trans = op->trans;
291         union smb_rename *io;
292
293         if (trans->in.params.length < 5) {
294                 return NT_STATUS_INVALID_PARAMETER;
295         }
296
297         /* parse the request */
298         io = talloc(req, union smb_rename);
299         NT_STATUS_HAVE_NO_MEMORY(io);
300
301         io->nttrans.level               = RAW_RENAME_NTTRANS;
302         io->nttrans.in.file.ntvfs       = smbsrv_pull_fnum(req, trans->in.params.data, 0);
303         io->nttrans.in.flags            = SVAL(trans->in.params.data, 2);
304
305         smbsrv_blob_pull_string(&req->in.bufinfo, &trans->in.params, 4,
306                                 &io->nttrans.in.new_name,
307                                 STR_TERMINATE);
308         if (!io->nttrans.in.new_name) {
309                 return NT_STATUS_INVALID_PARAMETER;
310         }
311
312         SMBSRV_CHECK_FILE_HANDLE_NTSTATUS(io->nttrans.in.file.ntvfs);
313         return ntvfs_rename(req->ntvfs, io);
314 }
315
316 /* 
317    parse NTTRANS_IOCTL send
318  */
319 static NTSTATUS nttrans_ioctl_send(struct nttrans_op *op)
320 {
321         union smb_ioctl *info = talloc_get_type(op->op_info, union smb_ioctl);
322         NTSTATUS status;
323
324         /* 
325          * we pass 0 as data_count here,
326          * because we reuse the DATA_BLOB from the smb_ioctl
327          * struct
328          */
329         status = nttrans_setup_reply(op, op->trans, 0, 0, 1);
330         NT_STATUS_NOT_OK_RETURN(status);
331
332         op->trans->out.setup[0]         = 0;
333         op->trans->out.data             = info->ntioctl.out.blob;
334
335         return NT_STATUS_OK;
336 }
337
338
339 /* 
340    parse NTTRANS_IOCTL request
341  */
342 static NTSTATUS nttrans_ioctl(struct smbsrv_request *req, 
343                               struct nttrans_op *op)
344 {
345         struct smb_nttrans *trans = op->trans;
346         union smb_ioctl *nt;
347
348         /* should have at least 4 setup words */
349         if (trans->in.setup_count != 4) {
350                 return NT_STATUS_INVALID_PARAMETER;
351         }
352
353         nt = talloc(op, union smb_ioctl);
354         NT_STATUS_HAVE_NO_MEMORY(nt);
355         
356         nt->ntioctl.level               = RAW_IOCTL_NTIOCTL;
357         nt->ntioctl.in.function         = IVAL(trans->in.setup, 0);
358         nt->ntioctl.in.file.ntvfs       = smbsrv_pull_fnum(req, (uint8_t *)trans->in.setup, 4);
359         nt->ntioctl.in.fsctl            = CVAL(trans->in.setup, 6);
360         nt->ntioctl.in.filter           = CVAL(trans->in.setup, 7);
361         nt->ntioctl.in.max_data         = trans->in.max_data;
362         nt->ntioctl.in.blob             = trans->in.data;
363
364         op->op_info = nt;
365         op->send_fn = nttrans_ioctl_send;
366
367         SMBSRV_CHECK_FILE_HANDLE_NTSTATUS(nt->ntioctl.in.file.ntvfs);
368         return ntvfs_ioctl(req->ntvfs, nt);
369 }
370
371
372 /* 
373    send NTTRANS_NOTIFY_CHANGE reply
374  */
375 static NTSTATUS nttrans_notify_change_send(struct nttrans_op *op)
376 {
377         union smb_notify *info = talloc_get_type(op->op_info, union smb_notify);
378         size_t size = 0;
379         int i;
380         NTSTATUS status;
381         uint8_t *p;
382 #define MAX_BYTES_PER_CHAR 3
383         
384         /* work out how big the reply buffer could be */
385         for (i=0;i<info->nttrans.out.num_changes;i++) {
386                 size += 12 + 3 + (1+strlen(info->nttrans.out.changes[i].name.s)) * MAX_BYTES_PER_CHAR;
387         }
388
389         status = nttrans_setup_reply(op, op->trans, size, 0, 0);
390         NT_STATUS_NOT_OK_RETURN(status);
391         p = op->trans->out.params.data;
392
393         /* construct the changes buffer */
394         for (i=0;i<info->nttrans.out.num_changes;i++) {
395                 uint32_t ofs;
396                 ssize_t len;
397
398                 SIVAL(p, 4, info->nttrans.out.changes[i].action);
399                 len = push_string(lp_iconv_convenience(global_loadparm), p + 12, info->nttrans.out.changes[i].name.s, 
400                                   op->trans->out.params.length - 
401                                   (p+12 - op->trans->out.params.data), STR_UNICODE);
402                 SIVAL(p, 8, len);
403
404                 ofs = len + 12;
405
406                 if (ofs & 3) {
407                         int pad = 4 - (ofs & 3);
408                         memset(p+ofs, 0, pad);
409                         ofs += pad;
410                 }
411
412                 if (i == info->nttrans.out.num_changes-1) {
413                         SIVAL(p, 0, 0);
414                 } else {
415                         SIVAL(p, 0, ofs);
416                 }
417
418                 p += ofs;
419         }
420
421         op->trans->out.params.length = p - op->trans->out.params.data;
422
423         return NT_STATUS_OK;
424 }
425
426 /* 
427    parse NTTRANS_NOTIFY_CHANGE request
428  */
429 static NTSTATUS nttrans_notify_change(struct smbsrv_request *req, 
430                                       struct nttrans_op *op)
431 {
432         struct smb_nttrans *trans = op->trans;
433         union smb_notify *info;
434
435         /* should have at least 4 setup words */
436         if (trans->in.setup_count != 4) {
437                 return NT_STATUS_INVALID_PARAMETER;
438         }
439
440         info = talloc(op, union smb_notify);
441         NT_STATUS_HAVE_NO_MEMORY(info);
442
443         info->nttrans.level                     = RAW_NOTIFY_NTTRANS;
444         info->nttrans.in.completion_filter      = IVAL(trans->in.setup, 0);
445         info->nttrans.in.file.ntvfs             = smbsrv_pull_fnum(req, (uint8_t *)trans->in.setup, 4);
446         info->nttrans.in.recursive              = SVAL(trans->in.setup, 6);
447         info->nttrans.in.buffer_size            = trans->in.max_param;
448
449         op->op_info = info;
450         op->send_fn = nttrans_notify_change_send;
451
452         SMBSRV_CHECK_FILE_HANDLE_NTSTATUS(info->nttrans.in.file.ntvfs);
453         return ntvfs_notify(req->ntvfs, info);
454 }
455
456 /*
457   backend for nttrans requests
458 */
459 static NTSTATUS nttrans_backend(struct smbsrv_request *req, 
460                                 struct nttrans_op *op)
461 {
462         /* the nttrans command is in function */
463         switch (op->trans->in.function) {
464         case NT_TRANSACT_CREATE:
465                 return nttrans_create(req, op);
466         case NT_TRANSACT_IOCTL:
467                 return nttrans_ioctl(req, op);
468         case NT_TRANSACT_RENAME:
469                 return nttrans_rename(req, op);
470         case NT_TRANSACT_QUERY_SECURITY_DESC:
471                 return nttrans_query_sec_desc(req, op);
472         case NT_TRANSACT_SET_SECURITY_DESC:
473                 return nttrans_set_sec_desc(req, op);
474         case NT_TRANSACT_NOTIFY_CHANGE:
475                 return nttrans_notify_change(req, op);
476         }
477
478         /* an unknown nttrans command */
479         return NT_STATUS_DOS(ERRSRV, ERRerror);
480 }
481
482
483 static void reply_nttrans_send(struct ntvfs_request *ntvfs)
484 {
485         struct smbsrv_request *req;
486         uint32_t params_left, data_left;
487         uint8_t *params, *data;
488         struct smb_nttrans *trans;
489         struct nttrans_op *op;
490
491         SMBSRV_CHECK_ASYNC_STATUS(op, struct nttrans_op);
492
493         trans = op->trans;
494
495         /* if this function needs work to form the nttrans reply buffer, then
496            call that now */
497         if (op->send_fn != NULL) {
498                 NTSTATUS status;
499                 status = op->send_fn(op);
500                 if (!NT_STATUS_IS_OK(status)) {
501                         smbsrv_send_error(req, status);
502                         return;
503                 }
504         }
505
506         smbsrv_setup_reply(req, 18 + trans->out.setup_count, 0);
507
508         /* note that we don't check the max_setup count (matching w2k3
509            behaviour) */
510
511         if (trans->out.params.length > trans->in.max_param) {
512                 smbsrv_setup_error(req, NT_STATUS_BUFFER_TOO_SMALL);
513                 trans->out.params.length = trans->in.max_param;
514         }
515         if (trans->out.data.length > trans->in.max_data) {
516                 smbsrv_setup_error(req, NT_STATUS_BUFFER_TOO_SMALL);
517                 trans->out.data.length = trans->in.max_data;
518         }
519
520         params_left = trans->out.params.length;
521         data_left   = trans->out.data.length;
522         params      = trans->out.params.data;
523         data        = trans->out.data.data;
524
525         /* we need to divide up the reply into chunks that fit into
526            the negotiated buffer size */
527         do {
528                 uint32_t this_data, this_param, max_bytes;
529                 uint_t align1 = 1, align2 = (params_left ? 2 : 0);
530                 struct smbsrv_request *this_req;
531
532                 max_bytes = req_max_data(req) - (align1 + align2);
533
534                 this_param = params_left;
535                 if (this_param > max_bytes) {
536                         this_param = max_bytes;
537                 }
538                 max_bytes -= this_param;
539
540                 this_data = data_left;
541                 if (this_data > max_bytes) {
542                         this_data = max_bytes;
543                 }
544
545                 /* don't destroy unless this is the last chunk */
546                 if (params_left - this_param != 0 || 
547                     data_left - this_data != 0) {
548                         this_req = smbsrv_setup_secondary_request(req);
549                 } else {
550                         this_req = req;
551                 }
552
553                 req_grow_data(this_req, this_param + this_data + (align1 + align2));
554
555                 SSVAL(this_req->out.vwv, 0, 0); /* reserved */
556                 SCVAL(this_req->out.vwv, 2, 0); /* reserved */
557                 SIVAL(this_req->out.vwv, 3, trans->out.params.length);
558                 SIVAL(this_req->out.vwv, 7, trans->out.data.length);
559
560                 SIVAL(this_req->out.vwv, 11, this_param);
561                 SIVAL(this_req->out.vwv, 15, align1 + PTR_DIFF(this_req->out.data, this_req->out.hdr));
562                 SIVAL(this_req->out.vwv, 19, PTR_DIFF(params, trans->out.params.data));
563
564                 SIVAL(this_req->out.vwv, 23, this_data);
565                 SIVAL(this_req->out.vwv, 27, align1 + align2 + 
566                       PTR_DIFF(this_req->out.data + this_param, this_req->out.hdr));
567                 SIVAL(this_req->out.vwv, 31, PTR_DIFF(data, trans->out.data.data));
568
569                 SCVAL(this_req->out.vwv, 35, trans->out.setup_count);
570                 memcpy((char *)(this_req->out.vwv) + VWV(18), trans->out.setup,
571                        sizeof(uint16_t) * trans->out.setup_count);
572                 memset(this_req->out.data, 0, align1);
573                 if (this_param != 0) {
574                         memcpy(this_req->out.data + align1, params, this_param);
575                 }
576                 memset(this_req->out.data+this_param+align1, 0, align2);
577                 if (this_data != 0) {
578                         memcpy(this_req->out.data+this_param+align1+align2, 
579                                data, this_data);
580                 }
581
582                 params_left -= this_param;
583                 data_left -= this_data;
584                 params += this_param;
585                 data += this_data;
586
587                 smbsrv_send_reply(this_req);
588         } while (params_left != 0 || data_left != 0);
589 }
590
591
592 /****************************************************************************
593  Reply to an SMBnttrans request
594 ****************************************************************************/
595 void smbsrv_reply_nttrans(struct smbsrv_request *req)
596 {
597         struct nttrans_op *op;
598         struct smb_nttrans *trans;
599         uint32_t param_ofs, data_ofs;
600         uint32_t param_count, data_count;
601         uint32_t param_total, data_total;
602
603         /* parse request */
604         if (req->in.wct < 19) {
605                 smbsrv_send_error(req, NT_STATUS_FOOBAR);
606                 return;
607         }
608
609         SMBSRV_TALLOC_IO_PTR(op, struct nttrans_op);
610         SMBSRV_SETUP_NTVFS_REQUEST(reply_nttrans_send, NTVFS_ASYNC_STATE_MAY_ASYNC);
611
612         trans = talloc(op, struct smb_nttrans);
613         if (trans == NULL) {
614                 smbsrv_send_error(req, NT_STATUS_NO_MEMORY);
615                 return;
616         }
617
618         op->trans = trans;
619         op->op_info = NULL;
620         op->send_fn = NULL;
621
622         trans->in.max_setup  = CVAL(req->in.vwv, 0);
623         param_total          = IVAL(req->in.vwv, 3);
624         data_total           = IVAL(req->in.vwv, 7);
625         trans->in.max_param  = IVAL(req->in.vwv, 11);
626         trans->in.max_data   = IVAL(req->in.vwv, 15);
627         param_count          = IVAL(req->in.vwv, 19);
628         param_ofs            = IVAL(req->in.vwv, 23);
629         data_count           = IVAL(req->in.vwv, 27);
630         data_ofs             = IVAL(req->in.vwv, 31);
631         trans->in.setup_count= CVAL(req->in.vwv, 35);
632         trans->in.function   = SVAL(req->in.vwv, 36);
633
634         if (req->in.wct != 19 + trans->in.setup_count) {
635                 smbsrv_send_error(req, NT_STATUS_DOS(ERRSRV, ERRerror));
636                 return;
637         }
638
639         /* parse out the setup words */
640         trans->in.setup = talloc_array(req, uint8_t, trans->in.setup_count*2);
641         if (!trans->in.setup) {
642                 smbsrv_send_error(req, NT_STATUS_NO_MEMORY);
643                 return;
644         }
645         memcpy(trans->in.setup, (char *)(req->in.vwv) + VWV(19),
646                sizeof(uint16_t) * trans->in.setup_count);
647
648         if (!req_pull_blob(&req->in.bufinfo, req->in.hdr + param_ofs, param_count, &trans->in.params) ||
649             !req_pull_blob(&req->in.bufinfo, req->in.hdr + data_ofs, data_count, &trans->in.data)) {
650                 smbsrv_send_error(req, NT_STATUS_FOOBAR);
651                 return;
652         }
653
654         /* is it a partial request? if so, then send a 'send more' message */
655         if (param_total > param_count ||
656             data_total > data_count) {
657                 DEBUG(0,("REWRITE: not handling partial nttrans requests!\n"));
658                 smbsrv_send_error(req, NT_STATUS_FOOBAR);
659                 return;
660         }
661
662         ZERO_STRUCT(trans->out);
663         SMBSRV_CALL_NTVFS_BACKEND(nttrans_backend(req, op));
664 }
665
666
667 /****************************************************************************
668  Reply to an SMBnttranss request
669 ****************************************************************************/
670 void smbsrv_reply_nttranss(struct smbsrv_request *req)
671 {
672         smbsrv_send_error(req, NT_STATUS_FOOBAR);
673 }