r22929: Attempt to fix some build farm failures: On port 139 the first
[samba.git] / source3 / libsmb / clientgen.c
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB client generic functions
4    Copyright (C) Andrew Tridgell 1994-1998
5    Copyright (C) Jeremy Allison 2007.
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 2 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, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23
24 extern int smb_read_error;
25
26 /****************************************************************************
27  Change the timeout (in milliseconds).
28 ****************************************************************************/
29
30 unsigned int cli_set_timeout(struct cli_state *cli, unsigned int timeout)
31 {
32         unsigned int old_timeout = cli->timeout;
33         cli->timeout = timeout;
34         return old_timeout;
35 }
36
37 /****************************************************************************
38  Change the port number used to call on.
39 ****************************************************************************/
40
41 int cli_set_port(struct cli_state *cli, int port)
42 {
43         cli->port = port;
44         return port;
45 }
46
47 /****************************************************************************
48  Read an smb from a fd ignoring all keepalive packets. Note that the buffer 
49  *MUST* be of size BUFFER_SIZE+SAFETY_MARGIN.
50  The timeout is in milliseconds
51
52  This is exactly the same as receive_smb except that it can be set to never return
53  a session keepalive packet (just as receive_smb used to do).
54  receive_smb was changed to return keepalives as the oplock processing means this call
55  should never go into a blocking read.
56 ****************************************************************************/
57
58 static ssize_t client_receive_smb(struct cli_state *cli, BOOL eat_keepalives, size_t maxlen)
59 {
60         ssize_t len;
61         int fd = cli->fd;
62         char *buffer = cli->inbuf;
63         unsigned int timeout = cli->timeout;
64
65         for(;;) {
66                 len = receive_smb_raw(fd, buffer, timeout, maxlen);
67
68                 if (len < 0) {
69                         DEBUG(10,("client_receive_smb failed\n"));
70                         show_msg(buffer);
71                         return len;
72                 }
73
74                 /* Ignore session keepalive packets. */
75                 if (eat_keepalives && (CVAL(buffer,0) == SMBkeepalive)) {
76                         continue;
77                 }
78                 break;
79         }
80
81         if (cli_encryption_on(cli)) {
82                 NTSTATUS status = cli_decrypt_message(cli);
83                 if (!NT_STATUS_IS_OK(status)) {
84                         DEBUG(0, ("SMB decryption failed on incoming packet! Error %s\n",
85                                 nt_errstr(status)));
86                         cli->smb_rw_error = READ_BAD_DECRYPT;
87                         close(cli->fd);
88                         cli->fd = -1;
89                         return -1;
90                 }
91         }
92         show_msg(buffer);
93         return len;
94 }
95
96 /****************************************************************************
97  Recv an smb.
98 ****************************************************************************/
99
100 BOOL cli_receive_smb_internal(struct cli_state *cli, BOOL eat_keepalives)
101 {
102         ssize_t len;
103
104         /* fd == -1 causes segfaults -- Tom (tom@ninja.nl) */
105         if (cli->fd == -1)
106                 return False; 
107
108  again:
109         len = client_receive_smb(cli, eat_keepalives, 0);
110
111         if (len >= 0 && !eat_keepalives && (CVAL(cli->inbuf,0) == SMBkeepalive)) {
112                 /* Give back the keepalive. */
113                 return True;
114         }
115         
116         if (len > 0) {
117                 /* it might be an oplock break request */
118                 if (!(CVAL(cli->inbuf, smb_flg) & FLAG_REPLY) &&
119                     CVAL(cli->inbuf,smb_com) == SMBlockingX &&
120                     SVAL(cli->inbuf,smb_vwv6) == 0 &&
121                     SVAL(cli->inbuf,smb_vwv7) == 0) {
122                         if (cli->oplock_handler) {
123                                 int fnum = SVAL(cli->inbuf,smb_vwv2);
124                                 unsigned char level = CVAL(cli->inbuf,smb_vwv3+1);
125                                 if (!cli->oplock_handler(cli, fnum, level)) {
126                                         return False;
127                                 }
128                         }
129                         /* try to prevent loops */
130                         SCVAL(cli->inbuf,smb_com,0xFF);
131                         goto again;
132                 }
133         }
134
135         /* If the server is not responding, note that now */
136         if (len <= 0) {
137                 DEBUG(0, ("Receiving SMB: Server stopped responding\n"));
138                 cli->smb_rw_error = smb_read_error;
139                 close(cli->fd);
140                 cli->fd = -1;
141                 return False;
142         }
143
144         if (!cli_check_sign_mac(cli)) {
145                 /*
146                  * If we get a signature failure in sessionsetup, then
147                  * the server sometimes just reflects the sent signature
148                  * back to us. Detect this and allow the upper layer to
149                  * retrieve the correct Windows error message.
150                  */
151                 if (CVAL(cli->outbuf,smb_com) == SMBsesssetupX &&
152                         (smb_len(cli->inbuf) > (smb_ss_field + 8 - 4)) &&
153                         (SVAL(cli->inbuf,smb_flg2) & FLAGS2_SMB_SECURITY_SIGNATURES) &&
154                         memcmp(&cli->outbuf[smb_ss_field],&cli->inbuf[smb_ss_field],8) == 0 &&
155                         cli_is_error(cli)) {
156
157                         /*
158                          * Reflected signature on login error. 
159                          * Set bad sig but don't close fd.
160                          */
161                         cli->smb_rw_error = READ_BAD_SIG;
162                         return True;
163                 }
164
165                 DEBUG(0, ("SMB Signature verification failed on incoming packet!\n"));
166                 cli->smb_rw_error = READ_BAD_SIG;
167                 close(cli->fd);
168                 cli->fd = -1;
169                 return False;
170         }
171
172         return True;
173 }
174
175 /****************************************************************************
176  Recv an smb - eat keepalives.
177 ****************************************************************************/
178
179 BOOL cli_receive_smb(struct cli_state *cli)
180 {
181         return cli_receive_smb_internal(cli, True);
182 }
183
184 /****************************************************************************
185  Recv an smb - return keepalives.
186 ****************************************************************************/
187
188 BOOL cli_receive_smb_return_keepalive(struct cli_state *cli)
189 {
190         return cli_receive_smb_internal(cli, False);
191 }
192
193 /****************************************************************************
194  Recv an smb session reply
195 ****************************************************************************/
196
197 BOOL cli_receive_sessionreply(struct cli_state *cli)
198 {
199         ssize_t len;
200
201         /* fd == -1 causes segfaults -- Tom (tom@ninja.nl) */
202         if (cli->fd == -1)
203                 return False; 
204
205         len = client_receive_smb(cli, False, 0);
206
207         /* If the server is not responding, note that now */
208         if (len < 0) {
209                 DEBUG(0, ("Receiving SMB: Server stopped responding\n"));
210                 cli->smb_rw_error = smb_read_error;
211                 close(cli->fd);
212                 cli->fd = -1;
213                 return False;
214         }
215
216         return True;
217 }
218
219 /****************************************************************************
220  Read the data portion of a readX smb.
221  The timeout is in milliseconds
222 ****************************************************************************/
223
224 ssize_t cli_receive_smb_data(struct cli_state *cli, char *buffer, size_t len)
225 {
226         if (cli->timeout > 0) {
227                 return read_socket_with_timeout(cli->fd, buffer, len, len, cli->timeout);
228         } else {
229                 return read_data(cli->fd, buffer, len);
230         }
231 }
232
233 /****************************************************************************
234  Read a smb readX header.
235  We can only use this if encryption and signing are off.
236 ****************************************************************************/
237
238 BOOL cli_receive_smb_readX_header(struct cli_state *cli)
239 {
240         ssize_t len, offset;
241
242         if (cli->fd == -1)
243                 return False; 
244
245  again:
246
247         /* Read up to the size of a readX header reply. */
248         len = client_receive_smb(cli, True, (smb_size - 4) + 24);
249         
250         if (len > 0) {
251                 /* it might be an oplock break request */
252                 if (!(CVAL(cli->inbuf, smb_flg) & FLAG_REPLY) &&
253                     CVAL(cli->inbuf,smb_com) == SMBlockingX &&
254                     SVAL(cli->inbuf,smb_vwv6) == 0 &&
255                     SVAL(cli->inbuf,smb_vwv7) == 0) {
256                         ssize_t total_len = smb_len(cli->inbuf);
257
258                         if (total_len > CLI_SAMBA_MAX_LARGE_READX_SIZE+SAFETY_MARGIN) {
259                                 goto read_err;
260                         }
261
262                         /* Read the rest of the data. */
263                         if (!cli_receive_smb_data(cli,cli->inbuf+len,total_len - len)) {
264                                 goto read_err;
265                         }
266
267                         if (cli->oplock_handler) {
268                                 int fnum = SVAL(cli->inbuf,smb_vwv2);
269                                 unsigned char level = CVAL(cli->inbuf,smb_vwv3+1);
270                                 if (!cli->oplock_handler(cli, fnum, level)) return False;
271                         }
272                         /* try to prevent loops */
273                         SCVAL(cli->inbuf,smb_com,0xFF);
274                         goto again;
275                 }
276         }
277
278         /* If it's not the above size it probably was an error packet. */
279
280         if ((len == (smb_size - 4) + 24) && !cli_is_error(cli)) {
281                 /* Check it's a non-chained readX reply. */
282                 if (!(CVAL(cli->inbuf, smb_flg) & FLAG_REPLY) ||
283                         (CVAL(cli->inbuf,smb_vwv0) != 0xFF) ||
284                         (CVAL(cli->inbuf,smb_com) != SMBreadX)) {
285                         /* 
286                          * We're not coping here with asnyc replies to
287                          * other calls. Punt here - we need async client
288                          * libs for this.
289                          */
290                         goto read_err;
291                 }
292
293                 /* 
294                  * We know it's a readX reply - ensure we've read the
295                  * padding bytes also.
296                  */
297
298                 offset = SVAL(cli->inbuf,smb_vwv6);
299                 if (offset > len) {
300                         ssize_t ret;
301                         size_t padbytes = offset - len;
302                         ret = cli_receive_smb_data(cli,smb_buf(cli->inbuf),padbytes);
303                         if (ret != padbytes) {
304                                 goto read_err;
305                         }
306                 }
307         }
308
309         return True;
310
311   read_err:
312
313         cli->smb_rw_error = smb_read_error = READ_ERROR;
314         close(cli->fd);
315         cli->fd = -1;
316         return False;
317 }
318
319 static ssize_t write_socket(int fd, const char *buf, size_t len)
320 {
321         ssize_t ret=0;
322                                                                                                                                             
323         DEBUG(6,("write_socket(%d,%d)\n",fd,(int)len));
324         ret = write_data(fd,buf,len);
325
326         DEBUG(6,("write_socket(%d,%d) wrote %d\n",fd,(int)len,(int)ret));
327         if(ret <= 0)
328                 DEBUG(0,("write_socket: Error writing %d bytes to socket %d: ERRNO = %s\n",
329                         (int)len, fd, strerror(errno) ));
330                                                                                                                                             
331         return(ret);
332 }
333
334 /****************************************************************************
335  Send an smb to a fd.
336 ****************************************************************************/
337
338 BOOL cli_send_smb(struct cli_state *cli)
339 {
340         size_t len;
341         size_t nwritten=0;
342         ssize_t ret;
343         char *buf_out = cli->outbuf;
344         BOOL enc_on = cli_encryption_on(cli);
345
346         /* fd == -1 causes segfaults -- Tom (tom@ninja.nl) */
347         if (cli->fd == -1) {
348                 return False;
349         }
350
351         cli_calculate_sign_mac(cli);
352
353         if (enc_on) {
354                 NTSTATUS status = cli_encrypt_message(cli, &buf_out);
355                 if (!NT_STATUS_IS_OK(status)) {
356                         close(cli->fd);
357                         cli->fd = -1;
358                         cli->smb_rw_error = WRITE_ERROR;
359                         DEBUG(0,("Error in encrypting client message. Error %s\n",
360                                 nt_errstr(status) ));
361                         return False;
362                 }
363         }
364
365         len = smb_len(buf_out) + 4;
366
367         while (nwritten < len) {
368                 ret = write_socket(cli->fd,buf_out+nwritten,len - nwritten);
369                 if (ret <= 0) {
370                         if (enc_on) {
371                                 cli_free_enc_buffer(cli, buf_out);
372                         }
373                         close(cli->fd);
374                         cli->fd = -1;
375                         cli->smb_rw_error = WRITE_ERROR;
376                         DEBUG(0,("Error writing %d bytes to client. %d (%s)\n",
377                                 (int)len,(int)ret, strerror(errno) ));
378                         return False;
379                 }
380                 nwritten += ret;
381         }
382
383         cli_free_enc_buffer(cli, buf_out);
384
385         /* Increment the mid so we can tell between responses. */
386         cli->mid++;
387         if (!cli->mid) {
388                 cli->mid++;
389         }
390         return True;
391 }
392
393 /****************************************************************************
394  Setup basics in a outgoing packet.
395 ****************************************************************************/
396
397 void cli_setup_packet(struct cli_state *cli)
398 {
399         cli->rap_error = 0;
400         SSVAL(cli->outbuf,smb_pid,cli->pid);
401         SSVAL(cli->outbuf,smb_uid,cli->vuid);
402         SSVAL(cli->outbuf,smb_mid,cli->mid);
403         if (cli->protocol > PROTOCOL_CORE) {
404                 uint16 flags2;
405                 if (cli->case_sensitive) {
406                         SCVAL(cli->outbuf,smb_flg,0x0);
407                 } else {
408                         /* Default setting, case insensitive. */
409                         SCVAL(cli->outbuf,smb_flg,0x8);
410                 }
411                 flags2 = FLAGS2_LONG_PATH_COMPONENTS;
412                 if (cli->capabilities & CAP_UNICODE)
413                         flags2 |= FLAGS2_UNICODE_STRINGS;
414                 if ((cli->capabilities & CAP_DFS) && cli->dfsroot)
415                         flags2 |= FLAGS2_DFS_PATHNAMES;
416                 if (cli->capabilities & CAP_STATUS32)
417                         flags2 |= FLAGS2_32_BIT_ERROR_CODES;
418                 if (cli->use_spnego)
419                         flags2 |= FLAGS2_EXTENDED_SECURITY;
420                 SSVAL(cli->outbuf,smb_flg2, flags2);
421         }
422 }
423
424 /****************************************************************************
425  Setup the bcc length of the packet from a pointer to the end of the data.
426 ****************************************************************************/
427
428 void cli_setup_bcc(struct cli_state *cli, void *p)
429 {
430         set_message_bcc(NULL,cli->outbuf, PTR_DIFF(p, smb_buf(cli->outbuf)));
431 }
432
433 /****************************************************************************
434  Initialise credentials of a client structure.
435 ****************************************************************************/
436
437 void cli_init_creds(struct cli_state *cli, const char *username, const char *domain, const char *password)
438 {
439         fstrcpy(cli->domain, domain);
440         fstrcpy(cli->user_name, username);
441         pwd_set_cleartext(&cli->pwd, password);
442         if (!*username) {
443                 cli->pwd.null_pwd = True;
444         }
445
446         DEBUG(10,("cli_init_creds: user %s domain %s\n", cli->user_name, cli->domain));
447 }
448
449 /****************************************************************************
450  Set the signing state (used from the command line).
451 ****************************************************************************/
452
453 void cli_setup_signing_state(struct cli_state *cli, int signing_state)
454 {
455         if (signing_state == Undefined)
456                 return;
457
458         if (signing_state == False) {
459                 cli->sign_info.allow_smb_signing = False;
460                 cli->sign_info.mandatory_signing = False;
461                 return;
462         }
463
464         cli->sign_info.allow_smb_signing = True;
465
466         if (signing_state == Required) 
467                 cli->sign_info.mandatory_signing = True;
468 }
469
470 /****************************************************************************
471  Initialise a client structure. Always returns a malloc'ed struct.
472 ****************************************************************************/
473
474 struct cli_state *cli_initialise(void)
475 {
476         struct cli_state *cli = NULL;
477
478         /* Check the effective uid - make sure we are not setuid */
479         if (is_setuid_root()) {
480                 DEBUG(0,("libsmb based programs must *NOT* be setuid root.\n"));
481                 return NULL;
482         }
483
484         cli = SMB_MALLOC_P(struct cli_state);
485         if (!cli) {
486                 return NULL;
487         }
488
489         ZERO_STRUCTP(cli);
490
491         cli->port = 0;
492         cli->fd = -1;
493         cli->cnum = -1;
494         cli->pid = (uint16)sys_getpid();
495         cli->mid = 1;
496         cli->vuid = UID_FIELD_INVALID;
497         cli->protocol = PROTOCOL_NT1;
498         cli->timeout = 20000; /* Timeout is in milliseconds. */
499         cli->bufsize = CLI_BUFFER_SIZE+4;
500         cli->max_xmit = cli->bufsize;
501         cli->outbuf = (char *)SMB_MALLOC(cli->bufsize+SAFETY_MARGIN);
502         cli->inbuf = (char *)SMB_MALLOC(cli->bufsize+SAFETY_MARGIN);
503         cli->oplock_handler = cli_oplock_ack;
504         cli->case_sensitive = False;
505         cli->smb_rw_error = 0;
506
507         cli->use_spnego = lp_client_use_spnego();
508
509         cli->capabilities = CAP_UNICODE | CAP_STATUS32 | CAP_DFS;
510
511         /* Set the CLI_FORCE_DOSERR environment variable to test
512            client routines using DOS errors instead of STATUS32
513            ones.  This intended only as a temporary hack. */    
514         if (getenv("CLI_FORCE_DOSERR"))
515                 cli->force_dos_errors = True;
516
517         if (lp_client_signing()) 
518                 cli->sign_info.allow_smb_signing = True;
519
520         if (lp_client_signing() == Required) 
521                 cli->sign_info.mandatory_signing = True;
522                                    
523         if (!cli->outbuf || !cli->inbuf)
524                 goto error;
525
526         if ((cli->mem_ctx = talloc_init("cli based talloc")) == NULL)
527                 goto error;
528
529         memset(cli->outbuf, 0, cli->bufsize);
530         memset(cli->inbuf, 0, cli->bufsize);
531
532
533 #if defined(DEVELOPER)
534         /* just because we over-allocate, doesn't mean it's right to use it */
535         clobber_region(FUNCTION_MACRO, __LINE__, cli->outbuf+cli->bufsize, SAFETY_MARGIN);
536         clobber_region(FUNCTION_MACRO, __LINE__, cli->inbuf+cli->bufsize, SAFETY_MARGIN);
537 #endif
538
539         /* initialise signing */
540         cli_null_set_signing(cli);
541
542         cli->initialised = 1;
543
544         return cli;
545
546         /* Clean up after malloc() error */
547
548  error:
549
550         SAFE_FREE(cli->inbuf);
551         SAFE_FREE(cli->outbuf);
552         SAFE_FREE(cli);
553         return NULL;
554 }
555
556 /****************************************************************************
557  External interface.
558  Close an open named pipe over SMB. Free any authentication data.
559  Returns False if the cli_close call failed.
560  ****************************************************************************/
561
562 BOOL cli_rpc_pipe_close(struct rpc_pipe_client *cli)
563 {
564         BOOL ret;
565
566         if (!cli) {
567                 return False;
568         }
569
570         ret = cli_close(cli->cli, cli->fnum);
571
572         if (!ret) {
573                 DEBUG(1,("cli_rpc_pipe_close: cli_close failed on pipe %s, "
574                          "fnum 0x%x "
575                          "to machine %s.  Error was %s\n",
576                          cli->pipe_name,
577                          (int) cli->fnum,
578                          cli->cli->desthost,
579                          cli_errstr(cli->cli)));
580         }
581
582         if (cli->auth.cli_auth_data_free_func) {
583                 (*cli->auth.cli_auth_data_free_func)(&cli->auth);
584         }
585
586         DEBUG(10,("cli_rpc_pipe_close: closed pipe %s to machine %s\n",
587                 cli->pipe_name, cli->cli->desthost ));
588
589         DLIST_REMOVE(cli->cli->pipe_list, cli);
590         talloc_destroy(cli->mem_ctx);
591         return ret;
592 }
593
594 /****************************************************************************
595  Close all pipes open on this session.
596 ****************************************************************************/
597
598 void cli_nt_pipes_close(struct cli_state *cli)
599 {
600         struct rpc_pipe_client *cp, *next;
601
602         for (cp = cli->pipe_list; cp; cp = next) {
603                 next = cp->next;
604                 cli_rpc_pipe_close(cp);
605         }
606 }
607
608 /****************************************************************************
609  Shutdown a client structure.
610 ****************************************************************************/
611
612 void cli_shutdown(struct cli_state *cli)
613 {
614         cli_nt_pipes_close(cli);
615
616         /*
617          * tell our peer to free his resources.  Wihtout this, when an
618          * application attempts to do a graceful shutdown and calls
619          * smbc_free_context() to clean up all connections, some connections
620          * can remain active on the peer end, until some (long) timeout period
621          * later.  This tree disconnect forces the peer to clean up, since the
622          * connection will be going away.
623          *
624          * Also, do not do tree disconnect when cli->smb_rw_error is DO_NOT_DO_TDIS
625          * the only user for this so far is smbmount which passes opened connection
626          * down to kernel's smbfs module.
627          */
628         if ( (cli->cnum != (uint16)-1) && (cli->smb_rw_error != DO_NOT_DO_TDIS ) ) {
629                 cli_tdis(cli);
630         }
631         
632         SAFE_FREE(cli->outbuf);
633         SAFE_FREE(cli->inbuf);
634
635         cli_free_signing_context(cli);
636         cli_free_encryption_context(cli);
637
638         data_blob_free(&cli->secblob);
639         data_blob_free(&cli->user_session_key);
640
641         if (cli->mem_ctx) {
642                 talloc_destroy(cli->mem_ctx);
643                 cli->mem_ctx = NULL;
644         }
645
646         if (cli->fd != -1) {
647                 close(cli->fd);
648         }
649         cli->fd = -1;
650         cli->smb_rw_error = 0;
651
652         SAFE_FREE(cli);
653 }
654
655 /****************************************************************************
656  Set socket options on a open connection.
657 ****************************************************************************/
658
659 void cli_sockopt(struct cli_state *cli, const char *options)
660 {
661         set_socket_options(cli->fd, options);
662 }
663
664 /****************************************************************************
665  Set the PID to use for smb messages. Return the old pid.
666 ****************************************************************************/
667
668 uint16 cli_setpid(struct cli_state *cli, uint16 pid)
669 {
670         uint16 ret = cli->pid;
671         cli->pid = pid;
672         return ret;
673 }
674
675 /****************************************************************************
676  Set the case sensitivity flag on the packets. Returns old state.
677 ****************************************************************************/
678
679 BOOL cli_set_case_sensitive(struct cli_state *cli, BOOL case_sensitive)
680 {
681         BOOL ret = cli->case_sensitive;
682         cli->case_sensitive = case_sensitive;
683         return ret;
684 }
685
686 /****************************************************************************
687 Send a keepalive packet to the server
688 ****************************************************************************/
689
690 BOOL cli_send_keepalive(struct cli_state *cli)
691 {
692         if (cli->fd == -1) {
693                 DEBUG(3, ("cli_send_keepalive: fd == -1\n"));
694                 return False;
695         }
696         if (!send_keepalive(cli->fd)) {
697                 close(cli->fd);
698                 cli->fd = -1;
699                 DEBUG(0,("Error sending keepalive packet to client.\n"));
700                 return False;
701         }
702         return True;
703 }
704
705 /****************************************************************************
706  Send/receive a SMBecho command: ping the server
707 ****************************************************************************/
708
709 BOOL cli_echo(struct cli_state *cli, unsigned char *data, size_t length)
710 {
711         char *p;
712
713         SMB_ASSERT(length < 1024);
714
715         memset(cli->outbuf,'\0',smb_size);
716         set_message(NULL,cli->outbuf,1,length,True);
717         SCVAL(cli->outbuf,smb_com,SMBecho);
718         SSVAL(cli->outbuf,smb_tid,65535);
719         SSVAL(cli->outbuf,smb_vwv0,1);
720         cli_setup_packet(cli);
721         p = smb_buf(cli->outbuf);
722         memcpy(p, data, length);
723         p += length;
724
725         cli_setup_bcc(cli, p);
726
727         cli_send_smb(cli);
728         if (!cli_receive_smb(cli)) {
729                 return False;
730         }
731
732         if (cli_is_error(cli)) {
733                 return False;
734         }
735         return True;
736 }