8296f7e94c17e54f39855f9e4b57b04d21ca4ac6
[sfrench/samba-autobuild/.git] / source / libsmb / clitrans.c
1 /* 
2    Unix SMB/CIFS implementation.
3    client transaction calls
4    Copyright (C) Andrew Tridgell 1994-1998
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 #include "includes.h"
22
23
24 /****************************************************************************
25  Send a SMB trans or trans2 request.
26 ****************************************************************************/
27
28 BOOL cli_send_trans(struct cli_state *cli, int trans, 
29                     const char *pipe_name, 
30                     int fid, int flags,
31                     uint16 *setup, unsigned int lsetup, unsigned int msetup,
32                     const char *param, unsigned int lparam, unsigned int mparam,
33                     const char *data, unsigned int ldata, unsigned int mdata)
34 {
35         unsigned int i;
36         unsigned int this_ldata,this_lparam;
37         unsigned int tot_data=0,tot_param=0;
38         char *outdata,*outparam;
39         char *p;
40         int pipe_name_len=0;
41         uint16 mid;
42
43         this_lparam = MIN(lparam,cli->max_xmit - (500+lsetup*2)); /* hack */
44         this_ldata = MIN(ldata,cli->max_xmit - (500+lsetup*2+this_lparam));
45
46         memset(cli->outbuf,'\0',smb_size);
47         set_message(cli->outbuf,14+lsetup,0,True);
48         SCVAL(cli->outbuf,smb_com,trans);
49         SSVAL(cli->outbuf,smb_tid, cli->cnum);
50         cli_setup_packet(cli);
51
52         /*
53          * Save the mid we're using. We need this for finding
54          * signing replies.
55          */
56
57         mid = cli->mid;
58
59         if (pipe_name) {
60                 pipe_name_len = clistr_push(cli, smb_buf(cli->outbuf), pipe_name, -1, STR_TERMINATE);
61         }
62
63         outparam = smb_buf(cli->outbuf)+(trans==SMBtrans ? pipe_name_len : 3);
64         outdata = outparam+this_lparam;
65
66         /* primary request */
67         SSVAL(cli->outbuf,smb_tpscnt,lparam);   /* tpscnt */
68         SSVAL(cli->outbuf,smb_tdscnt,ldata);    /* tdscnt */
69         SSVAL(cli->outbuf,smb_mprcnt,mparam);   /* mprcnt */
70         SSVAL(cli->outbuf,smb_mdrcnt,mdata);    /* mdrcnt */
71         SCVAL(cli->outbuf,smb_msrcnt,msetup);   /* msrcnt */
72         SSVAL(cli->outbuf,smb_flags,flags);     /* flags */
73         SIVAL(cli->outbuf,smb_timeout,0);               /* timeout */
74         SSVAL(cli->outbuf,smb_pscnt,this_lparam);       /* pscnt */
75         SSVAL(cli->outbuf,smb_psoff,smb_offset(outparam,cli->outbuf)); /* psoff */
76         SSVAL(cli->outbuf,smb_dscnt,this_ldata);        /* dscnt */
77         SSVAL(cli->outbuf,smb_dsoff,smb_offset(outdata,cli->outbuf)); /* dsoff */
78         SCVAL(cli->outbuf,smb_suwcnt,lsetup);   /* suwcnt */
79         for (i=0;i<lsetup;i++)          /* setup[] */
80                 SSVAL(cli->outbuf,smb_setup+i*2,setup[i]);
81         p = smb_buf(cli->outbuf);
82         if (trans != SMBtrans) {
83                 *p++ = 0;  /* put in a null smb_name */
84                 *p++ = 'D'; *p++ = ' '; /* observed in OS/2 */
85         }
86         if (this_lparam)                        /* param[] */
87                 memcpy(outparam,param,this_lparam);
88         if (this_ldata)                 /* data[] */
89                 memcpy(outdata,data,this_ldata);
90         cli_setup_bcc(cli, outdata+this_ldata);
91
92         show_msg(cli->outbuf);
93
94         if (!cli_send_smb(cli)) {
95                 return False;
96         }
97
98         if (this_ldata < ldata || this_lparam < lparam) {
99                 /* receive interim response */
100                 if (!cli_receive_smb(cli) || cli_is_error(cli)) {
101                         return(False);
102                 }
103
104                 tot_data = this_ldata;
105                 tot_param = this_lparam;
106                 
107                 while (tot_data < ldata || tot_param < lparam)  {
108                         this_lparam = MIN(lparam-tot_param,cli->max_xmit - 500); /* hack */
109                         this_ldata = MIN(ldata-tot_data,cli->max_xmit - (500+this_lparam));
110
111                         set_message(cli->outbuf,trans==SMBtrans?8:9,0,True);
112                         SCVAL(cli->outbuf,smb_com,(trans==SMBtrans ? SMBtranss : SMBtranss2));
113                         
114                         outparam = smb_buf(cli->outbuf);
115                         outdata = outparam+this_lparam;
116                         
117                         /* secondary request */
118                         SSVAL(cli->outbuf,smb_tpscnt,lparam);   /* tpscnt */
119                         SSVAL(cli->outbuf,smb_tdscnt,ldata);    /* tdscnt */
120                         SSVAL(cli->outbuf,smb_spscnt,this_lparam);      /* pscnt */
121                         SSVAL(cli->outbuf,smb_spsoff,smb_offset(outparam,cli->outbuf)); /* psoff */
122                         SSVAL(cli->outbuf,smb_spsdisp,tot_param);       /* psdisp */
123                         SSVAL(cli->outbuf,smb_sdscnt,this_ldata);       /* dscnt */
124                         SSVAL(cli->outbuf,smb_sdsoff,smb_offset(outdata,cli->outbuf)); /* dsoff */
125                         SSVAL(cli->outbuf,smb_sdsdisp,tot_data);        /* dsdisp */
126                         if (trans==SMBtrans2)
127                                 SSVALS(cli->outbuf,smb_sfid,fid);               /* fid */
128                         if (this_lparam)                        /* param[] */
129                                 memcpy(outparam,param+tot_param,this_lparam);
130                         if (this_ldata)                 /* data[] */
131                                 memcpy(outdata,data+tot_data,this_ldata);
132                         cli_setup_bcc(cli, outdata+this_ldata);
133                         
134                         /*
135                          * Save the mid we're using. We need this for finding
136                          * signing replies.
137                          */
138                         mid = cli->mid;
139
140                         show_msg(cli->outbuf);
141                         if (!cli_send_smb(cli)) {
142                                 return False;
143                         }
144
145                         /* Ensure we use the same mid for the secondaries. */
146                         cli->mid = mid;
147                         
148                         tot_data += this_ldata;
149                         tot_param += this_lparam;
150                 }
151         }
152
153         /* Note we're in a trans state. Save the sequence
154          * numbers for replies. */
155
156         cli_signing_trans_start(cli, mid);
157         return(True);
158 }
159
160 /****************************************************************************
161  Receive a SMB trans or trans2 response allocating the necessary memory.
162 ****************************************************************************/
163
164 BOOL cli_receive_trans(struct cli_state *cli,int trans,
165                               char **param, unsigned int *param_len,
166                               char **data, unsigned int *data_len)
167 {
168         unsigned int total_data=0;
169         unsigned int total_param=0;
170         unsigned int this_data,this_param;
171         NTSTATUS status;
172
173         *data_len = *param_len = 0;
174
175         if (!cli_receive_smb(cli)) {
176                 cli_signing_trans_stop(cli);
177                 return False;
178         }
179
180         show_msg(cli->inbuf);
181         
182         /* sanity check */
183         if (CVAL(cli->inbuf,smb_com) != trans) {
184                 DEBUG(0,("Expected %s response, got command 0x%02x\n",
185                          trans==SMBtrans?"SMBtrans":"SMBtrans2", 
186                          CVAL(cli->inbuf,smb_com)));
187                 cli_signing_trans_stop(cli);
188                 return(False);
189         }
190
191         /*
192          * An NT RPC pipe call can return ERRDOS, ERRmoredata
193          * to a trans call. This is not an error and should not
194          * be treated as such. Note that STATUS_NO_MORE_FILES is
195          * returned when a trans2 findfirst/next finishes.
196          */
197         status = cli_nt_error(cli);
198         
199         if (NT_STATUS_IS_ERR(status) || NT_STATUS_EQUAL(status,STATUS_NO_MORE_FILES)) {
200                 cli_signing_trans_stop(cli);
201                 return False;
202         }
203
204         /* parse out the lengths */
205         total_data = SVAL(cli->inbuf,smb_tdrcnt);
206         total_param = SVAL(cli->inbuf,smb_tprcnt);
207
208         /* allocate it */
209         if (total_data!=0) {
210                 *data = SMB_REALLOC(*data,total_data);
211                 if (!(*data)) {
212                         DEBUG(0,("cli_receive_trans: failed to enlarge data buffer\n"));
213                         cli_signing_trans_stop(cli);
214                         return False;
215                 }
216         }
217
218         if (total_param!=0) {
219                 *param = SMB_REALLOC(*param,total_param);
220                 if (!(*param)) {
221                         DEBUG(0,("cli_receive_trans: failed to enlarge param buffer\n"));
222                         cli_signing_trans_stop(cli);
223                         return False;
224                 }
225         }
226
227         for (;;)  {
228                 this_data = SVAL(cli->inbuf,smb_drcnt);
229                 this_param = SVAL(cli->inbuf,smb_prcnt);
230
231                 if (this_data + *data_len > total_data ||
232                     this_param + *param_len > total_param) {
233                         DEBUG(1,("Data overflow in cli_receive_trans\n"));
234                         cli_signing_trans_stop(cli);
235                         return False;
236                 }
237
238                 if (this_data + *data_len < this_data ||
239                                 this_data + *data_len < *data_len ||
240                                 this_param + *param_len < this_param ||
241                                 this_param + *param_len < *param_len) {
242                         DEBUG(1,("Data overflow in cli_receive_trans\n"));
243                         cli_signing_trans_stop(cli);
244                         return False;
245                 }
246
247                 if (this_data) {
248                         unsigned int data_offset_out = SVAL(cli->inbuf,smb_drdisp);
249                         unsigned int data_offset_in = SVAL(cli->inbuf,smb_droff);
250
251                         if (data_offset_out > total_data ||
252                                         data_offset_out + this_data > total_data ||
253                                         data_offset_out + this_data < data_offset_out ||
254                                         data_offset_out + this_data < this_data) {
255                                 DEBUG(1,("Data overflow in cli_receive_trans\n"));
256                                 cli_signing_trans_stop(cli);
257                                 return False;
258                         }
259                         if (data_offset_in > cli->bufsize ||
260                                         data_offset_in + this_data >  cli->bufsize ||
261                                         data_offset_in + this_data < data_offset_in ||
262                                         data_offset_in + this_data < this_data) {
263                                 DEBUG(1,("Data overflow in cli_receive_trans\n"));
264                                 cli_signing_trans_stop(cli);
265                                 return False;
266                         }
267
268                         memcpy(*data + data_offset_out, smb_base(cli->inbuf) + data_offset_in, this_data);
269                 }
270                 if (this_param) {
271                         unsigned int param_offset_out = SVAL(cli->inbuf,smb_prdisp);
272                         unsigned int param_offset_in = SVAL(cli->inbuf,smb_proff);
273
274                         if (param_offset_out > total_param ||
275                                         param_offset_out + this_param > total_param ||
276                                         param_offset_out + this_param < param_offset_out ||
277                                         param_offset_out + this_param < this_param) {
278                                 DEBUG(1,("Param overflow in cli_receive_trans\n"));
279                                 cli_signing_trans_stop(cli);
280                                 return False;
281                         }
282                         if (param_offset_in > cli->bufsize ||
283                                         param_offset_in + this_param >  cli->bufsize ||
284                                         param_offset_in + this_param < param_offset_in ||
285                                         param_offset_in + this_param < this_param) {
286                                 DEBUG(1,("Param overflow in cli_receive_trans\n"));
287                                 cli_signing_trans_stop(cli);
288                                 return False;
289                         }
290
291                         memcpy(*param + param_offset_out, smb_base(cli->inbuf) + param_offset_in, this_param);
292                 }
293                 *data_len += this_data;
294                 *param_len += this_param;
295
296                 if (total_data <= *data_len && total_param <= *param_len)
297                         break;
298                 
299                 if (!cli_receive_smb(cli)) {
300                         cli_signing_trans_stop(cli);
301                         return False;   
302                 }
303
304                 show_msg(cli->inbuf);
305                 
306                 /* sanity check */
307                 if (CVAL(cli->inbuf,smb_com) != trans) {
308                         DEBUG(0,("Expected %s response, got command 0x%02x\n",
309                                  trans==SMBtrans?"SMBtrans":"SMBtrans2", 
310                                  CVAL(cli->inbuf,smb_com)));
311                         cli_signing_trans_stop(cli);
312                         return(False);
313                 }
314                 if (NT_STATUS_IS_ERR(cli_nt_error(cli))) {
315                         cli_signing_trans_stop(cli);
316                         return(False);
317                 }
318
319                 /* parse out the total lengths again - they can shrink! */
320                 if (SVAL(cli->inbuf,smb_tdrcnt) < total_data)
321                         total_data = SVAL(cli->inbuf,smb_tdrcnt);
322                 if (SVAL(cli->inbuf,smb_tprcnt) < total_param)
323                         total_param = SVAL(cli->inbuf,smb_tprcnt);
324                 
325                 if (total_data <= *data_len && total_param <= *param_len)
326                         break;
327                 
328         }
329         
330         cli_signing_trans_stop(cli);
331         return(True);
332 }
333
334 /****************************************************************************
335  Send a SMB nttrans request.
336 ****************************************************************************/
337
338 BOOL cli_send_nt_trans(struct cli_state *cli, 
339                        int function, 
340                        int flags,
341                        uint16 *setup, unsigned int lsetup, unsigned int msetup,
342                        char *param, unsigned int lparam, unsigned int mparam,
343                        char *data, unsigned int ldata, unsigned int mdata)
344 {
345         unsigned int i;
346         unsigned int this_ldata,this_lparam;
347         unsigned int tot_data=0,tot_param=0;
348         uint16 mid;
349         char *outdata,*outparam;
350
351         this_lparam = MIN(lparam,cli->max_xmit - (500+lsetup*2)); /* hack */
352         this_ldata = MIN(ldata,cli->max_xmit - (500+lsetup*2+this_lparam));
353
354         memset(cli->outbuf,'\0',smb_size);
355         set_message(cli->outbuf,19+lsetup,0,True);
356         SCVAL(cli->outbuf,smb_com,SMBnttrans);
357         SSVAL(cli->outbuf,smb_tid, cli->cnum);
358         cli_setup_packet(cli);
359
360         /*
361          * Save the mid we're using. We need this for finding
362          * signing replies.
363          */
364
365         mid = cli->mid;
366
367         outparam = smb_buf(cli->outbuf)+3;
368         outdata = outparam+this_lparam;
369
370         /* primary request */
371         SCVAL(cli->outbuf,smb_nt_MaxSetupCount,msetup);
372         SCVAL(cli->outbuf,smb_nt_Flags,flags);
373         SIVAL(cli->outbuf,smb_nt_TotalParameterCount, lparam);
374         SIVAL(cli->outbuf,smb_nt_TotalDataCount, ldata);
375         SIVAL(cli->outbuf,smb_nt_MaxParameterCount, mparam);
376         SIVAL(cli->outbuf,smb_nt_MaxDataCount, mdata);
377         SIVAL(cli->outbuf,smb_nt_ParameterCount, this_lparam);
378         SIVAL(cli->outbuf,smb_nt_ParameterOffset, smb_offset(outparam,cli->outbuf));
379         SIVAL(cli->outbuf,smb_nt_DataCount, this_ldata);
380         SIVAL(cli->outbuf,smb_nt_DataOffset, smb_offset(outdata,cli->outbuf));
381         SIVAL(cli->outbuf,smb_nt_SetupCount, lsetup);
382         SIVAL(cli->outbuf,smb_nt_Function, function);
383         for (i=0;i<lsetup;i++)          /* setup[] */
384                 SSVAL(cli->outbuf,smb_nt_SetupStart+i*2,setup[i]);
385         
386         if (this_lparam)                        /* param[] */
387                 memcpy(outparam,param,this_lparam);
388         if (this_ldata)                 /* data[] */
389                 memcpy(outdata,data,this_ldata);
390
391         cli_setup_bcc(cli, outdata+this_ldata);
392
393         show_msg(cli->outbuf);
394         if (!cli_send_smb(cli)) {
395                 return False;
396         }       
397
398         if (this_ldata < ldata || this_lparam < lparam) {
399                 /* receive interim response */
400                 if (!cli_receive_smb(cli) || cli_is_error(cli)) {
401                         return(False);
402                 }
403
404                 tot_data = this_ldata;
405                 tot_param = this_lparam;
406                 
407                 while (tot_data < ldata || tot_param < lparam)  {
408                         this_lparam = MIN(lparam-tot_param,cli->max_xmit - 500); /* hack */
409                         this_ldata = MIN(ldata-tot_data,cli->max_xmit - (500+this_lparam));
410
411                         set_message(cli->outbuf,18,0,True);
412                         SCVAL(cli->outbuf,smb_com,SMBnttranss);
413
414                         /* XXX - these should probably be aligned */
415                         outparam = smb_buf(cli->outbuf);
416                         outdata = outparam+this_lparam;
417                         
418                         /* secondary request */
419                         SIVAL(cli->outbuf,smb_nts_TotalParameterCount,lparam);
420                         SIVAL(cli->outbuf,smb_nts_TotalDataCount,ldata);
421                         SIVAL(cli->outbuf,smb_nts_ParameterCount,this_lparam);
422                         SIVAL(cli->outbuf,smb_nts_ParameterOffset,smb_offset(outparam,cli->outbuf));
423                         SIVAL(cli->outbuf,smb_nts_ParameterDisplacement,tot_param);
424                         SIVAL(cli->outbuf,smb_nts_DataCount,this_ldata);
425                         SIVAL(cli->outbuf,smb_nts_DataOffset,smb_offset(outdata,cli->outbuf));
426                         SIVAL(cli->outbuf,smb_nts_DataDisplacement,tot_data);
427                         if (this_lparam)                        /* param[] */
428                                 memcpy(outparam,param+tot_param,this_lparam);
429                         if (this_ldata)                 /* data[] */
430                                 memcpy(outdata,data+tot_data,this_ldata);
431                         cli_setup_bcc(cli, outdata+this_ldata);
432                         
433                         /*
434                          * Save the mid we're using. We need this for finding
435                          * signing replies.
436                          */
437                         mid = cli->mid;
438
439                         show_msg(cli->outbuf);
440
441                         if (!cli_send_smb(cli)) {
442                                 return False;
443                         }
444                         
445                         /* Ensure we use the same mid for the secondaries. */
446                         cli->mid = mid;
447                         
448                         tot_data += this_ldata;
449                         tot_param += this_lparam;
450                 }
451         }
452
453         /* Note we're in a trans state. Save the sequence
454          * numbers for replies. */
455
456         cli_signing_trans_start(cli, mid);
457         return(True);
458 }
459
460 /****************************************************************************
461  Receive a SMB nttrans response allocating the necessary memory.
462 ****************************************************************************/
463
464 BOOL cli_receive_nt_trans(struct cli_state *cli,
465                           char **param, unsigned int *param_len,
466                           char **data, unsigned int *data_len)
467 {
468         unsigned int total_data=0;
469         unsigned int total_param=0;
470         unsigned int this_data,this_param;
471         uint8 eclass;
472         uint32 ecode;
473
474         *data_len = *param_len = 0;
475
476         if (!cli_receive_smb(cli)) {
477                 cli_signing_trans_stop(cli);
478                 return False;
479         }
480
481         show_msg(cli->inbuf);
482         
483         /* sanity check */
484         if (CVAL(cli->inbuf,smb_com) != SMBnttrans) {
485                 DEBUG(0,("Expected SMBnttrans response, got command 0x%02x\n",
486                          CVAL(cli->inbuf,smb_com)));
487                 cli_signing_trans_stop(cli);
488                 return(False);
489         }
490
491         /*
492          * An NT RPC pipe call can return ERRDOS, ERRmoredata
493          * to a trans call. This is not an error and should not
494          * be treated as such.
495          */
496         if (cli_is_dos_error(cli)) {
497                 cli_dos_error(cli, &eclass, &ecode);
498                 if (!(eclass == ERRDOS && ecode == ERRmoredata)) {
499                         cli_signing_trans_stop(cli);
500                         return(False);
501                 }
502         }
503
504         /*
505          * Likewise for NT_STATUS_BUFFER_TOO_SMALL
506          */
507         if (cli_is_nt_error(cli)) {
508                 if (!NT_STATUS_EQUAL(cli_nt_error(cli),
509                                      NT_STATUS_BUFFER_TOO_SMALL)) {
510                         cli_signing_trans_stop(cli);
511                         return(False);
512                 }
513         }
514
515         /* parse out the lengths */
516         total_data = SVAL(cli->inbuf,smb_ntr_TotalDataCount);
517         total_param = SVAL(cli->inbuf,smb_ntr_TotalParameterCount);
518
519         /* allocate it */
520         if (total_data) {
521                 *data = SMB_REALLOC(*data,total_data);
522                 if (!(*data)) {
523                         DEBUG(0,("cli_receive_nt_trans: failed to enlarge data buffer to %d\n",total_data));
524                         cli_signing_trans_stop(cli);
525                         return False;
526                 }
527         }
528
529         if (total_param) {
530                 *param = SMB_REALLOC(*param,total_param);
531                 if (!(*param)) {
532                         DEBUG(0,("cli_receive_nt_trans: failed to enlarge param buffer to %d\n", total_param));
533                         cli_signing_trans_stop(cli);
534                         return False;
535                 }
536         }
537
538         while (1)  {
539                 this_data = SVAL(cli->inbuf,smb_ntr_DataCount);
540                 this_param = SVAL(cli->inbuf,smb_ntr_ParameterCount);
541
542                 if (this_data + *data_len > total_data ||
543                     this_param + *param_len > total_param) {
544                         DEBUG(1,("Data overflow in cli_receive_nt_trans\n"));
545                         cli_signing_trans_stop(cli);
546                         return False;
547                 }
548
549                 if (this_data + *data_len < this_data ||
550                                 this_data + *data_len < *data_len ||
551                                 this_param + *param_len < this_param ||
552                                 this_param + *param_len < *param_len) {
553                         DEBUG(1,("Data overflow in cli_receive_nt_trans\n"));
554                         cli_signing_trans_stop(cli);
555                         return False;
556                 }
557
558                 if (this_data) {
559                         unsigned int data_offset_out = SVAL(cli->inbuf,smb_ntr_DataDisplacement);
560                         unsigned int data_offset_in = SVAL(cli->inbuf,smb_ntr_DataOffset);
561
562                         if (data_offset_out > total_data ||
563                                         data_offset_out + this_data > total_data ||
564                                         data_offset_out + this_data < data_offset_out ||
565                                         data_offset_out + this_data < this_data) {
566                                 DEBUG(1,("Data overflow in cli_receive_nt_trans\n"));
567                                 cli_signing_trans_stop(cli);
568                                 return False;
569                         }
570                         if (data_offset_in > cli->bufsize ||
571                                         data_offset_in + this_data >  cli->bufsize ||
572                                         data_offset_in + this_data < data_offset_in ||
573                                         data_offset_in + this_data < this_data) {
574                                 DEBUG(1,("Data overflow in cli_receive_nt_trans\n"));
575                                 cli_signing_trans_stop(cli);
576                                 return False;
577                         }
578
579                         memcpy(*data + data_offset_out, smb_base(cli->inbuf) + data_offset_in, this_data);
580                 }
581
582                 if (this_param) {
583                         unsigned int param_offset_out = SVAL(cli->inbuf,smb_ntr_ParameterDisplacement);
584                         unsigned int param_offset_in = SVAL(cli->inbuf,smb_ntr_ParameterOffset);
585
586                         if (param_offset_out > total_param ||
587                                         param_offset_out + this_param > total_param ||
588                                         param_offset_out + this_param < param_offset_out ||
589                                         param_offset_out + this_param < this_param) {
590                                 DEBUG(1,("Param overflow in cli_receive_nt_trans\n"));
591                                 cli_signing_trans_stop(cli);
592                                 return False;
593                         }
594                         if (param_offset_in > cli->bufsize ||
595                                         param_offset_in + this_param >  cli->bufsize ||
596                                         param_offset_in + this_param < param_offset_in ||
597                                         param_offset_in + this_param < this_param) {
598                                 DEBUG(1,("Param overflow in cli_receive_nt_trans\n"));
599                                 cli_signing_trans_stop(cli);
600                                 return False;
601                         }
602
603                         memcpy(*param + param_offset_out, smb_base(cli->inbuf) + param_offset_in, this_param);
604                 }
605
606                 *data_len += this_data;
607                 *param_len += this_param;
608
609                 if (total_data <= *data_len && total_param <= *param_len)
610                         break;
611                 
612                 if (!cli_receive_smb(cli)) {
613                         cli_signing_trans_stop(cli);
614                         return False;
615                 }
616
617                 show_msg(cli->inbuf);
618                 
619                 /* sanity check */
620                 if (CVAL(cli->inbuf,smb_com) != SMBnttrans) {
621                         DEBUG(0,("Expected SMBnttrans response, got command 0x%02x\n",
622                                  CVAL(cli->inbuf,smb_com)));
623                         cli_signing_trans_stop(cli);
624                         return(False);
625                 }
626                 if (cli_is_dos_error(cli)) {
627                         cli_dos_error(cli, &eclass, &ecode);
628                         if(!(eclass == ERRDOS && ecode == ERRmoredata)) {
629                                 cli_signing_trans_stop(cli);
630                                 return(False);
631                         }
632                 }
633                 /*
634                  * Likewise for NT_STATUS_BUFFER_TOO_SMALL
635                  */
636                 if (cli_is_nt_error(cli)) {
637                         if (!NT_STATUS_EQUAL(cli_nt_error(cli),
638                                              NT_STATUS_BUFFER_TOO_SMALL)) {
639                                 cli_signing_trans_stop(cli);
640                                 return(False);
641                         }
642                 }
643
644                 /* parse out the total lengths again - they can shrink! */
645                 if (SVAL(cli->inbuf,smb_ntr_TotalDataCount) < total_data)
646                         total_data = SVAL(cli->inbuf,smb_ntr_TotalDataCount);
647                 if (SVAL(cli->inbuf,smb_ntr_TotalParameterCount) < total_param)
648                         total_param = SVAL(cli->inbuf,smb_ntr_TotalParameterCount);
649                 
650                 if (total_data <= *data_len && total_param <= *param_len)
651                         break;
652         }
653         
654         cli_signing_trans_stop(cli);
655         return(True);
656 }