2 Unix SMB/Netbios implementation.
4 SMB client generic functions
5 Copyright (C) Andrew Tridgell 1994-1998
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.
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.
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.
28 extern int DEBUGLEVEL;
30 /*****************************************************
31 RAP error codes - a small start but will be extended.
32 *******************************************************/
40 {5, "User has insufficient privilege" },
41 {86, "The specified password is invalid" },
42 {2226, "Operation only permitted on a Primary Domain Controller" },
43 {2242, "The password of this user has expired." },
44 {2243, "The password of this user cannot change." },
45 {2244, "This password cannot be used now (password history conflict)." },
46 {2245, "The password is shorter than required." },
47 {2246, "The password of this user is too recent to change."},
51 /****************************************************************************
52 return a description of an SMB error
53 ****************************************************************************/
54 char *cli_smb_errstr(struct cli_state *cli)
56 return smb_errstr(cli->inbuf);
59 /******************************************************
60 Return an error message - either an SMB error or a RAP
62 *******************************************************/
64 char *cli_errstr(struct cli_state *cli)
66 static fstring error_message;
72 * Errors are of three kinds - smb errors,
73 * dealt with by cli_smb_errstr, NT errors,
74 * whose code is in cli.nt_error, and rap
75 * errors, whose error code is in cli.rap_error.
78 cli_error(cli, &errclass, &errnum);
80 return cli_smb_errstr(cli);
83 * Was it an NT error ?
87 char *nt_msg = get_nt_error_msg(cli->nt_error);
90 slprintf(error_message, sizeof(fstring) - 1, "NT code %d", cli->nt_error);
92 fstrcpy(error_message, nt_msg);
98 * Must have been a rap error.
101 slprintf(error_message, sizeof(error_message) - 1, "code %d", cli->rap_error);
103 for(i = 0; rap_errmap[i].message != NULL; i++) {
104 if (rap_errmap[i].err == cli->rap_error) {
105 fstrcpy( error_message, rap_errmap[i].message);
110 return error_message;
113 /****************************************************************************
114 setup basics in a outgoing packet
115 ****************************************************************************/
116 static void cli_setup_packet(struct cli_state *cli)
120 SSVAL(cli->outbuf,smb_pid,cli->pid);
121 SSVAL(cli->outbuf,smb_uid,cli->uid);
122 SSVAL(cli->outbuf,smb_mid,cli->mid);
123 if (cli->protocol > PROTOCOL_CORE) {
124 SCVAL(cli->outbuf,smb_flg,0x8);
125 SSVAL(cli->outbuf,smb_flg2,0x1);
130 /****************************************************************************
131 send a SMB trans or trans2 request
132 ****************************************************************************/
133 static BOOL cli_send_trans(struct cli_state *cli, int trans,
134 char *name, int pipe_name_len,
136 uint16 *setup, int lsetup, int msetup,
137 char *param, int lparam, int mparam,
138 char *data, int ldata, int mdata)
141 int this_ldata,this_lparam;
142 int tot_data=0,tot_param=0;
143 char *outdata,*outparam;
146 this_lparam = MIN(lparam,cli->max_xmit - (500+lsetup*2)); /* hack */
147 this_ldata = MIN(ldata,cli->max_xmit - (500+lsetup*2+this_lparam));
149 bzero(cli->outbuf,smb_size);
150 set_message(cli->outbuf,14+lsetup,0,True);
151 CVAL(cli->outbuf,smb_com) = trans;
152 SSVAL(cli->outbuf,smb_tid, cli->cnum);
153 cli_setup_packet(cli);
155 outparam = smb_buf(cli->outbuf)+(trans==SMBtrans ? pipe_name_len+1 : 3);
156 outdata = outparam+this_lparam;
158 /* primary request */
159 SSVAL(cli->outbuf,smb_tpscnt,lparam); /* tpscnt */
160 SSVAL(cli->outbuf,smb_tdscnt,ldata); /* tdscnt */
161 SSVAL(cli->outbuf,smb_mprcnt,mparam); /* mprcnt */
162 SSVAL(cli->outbuf,smb_mdrcnt,mdata); /* mdrcnt */
163 SCVAL(cli->outbuf,smb_msrcnt,msetup); /* msrcnt */
164 SSVAL(cli->outbuf,smb_flags,flags); /* flags */
165 SIVAL(cli->outbuf,smb_timeout,0); /* timeout */
166 SSVAL(cli->outbuf,smb_pscnt,this_lparam); /* pscnt */
167 SSVAL(cli->outbuf,smb_psoff,smb_offset(outparam,cli->outbuf)); /* psoff */
168 SSVAL(cli->outbuf,smb_dscnt,this_ldata); /* dscnt */
169 SSVAL(cli->outbuf,smb_dsoff,smb_offset(outdata,cli->outbuf)); /* dsoff */
170 SCVAL(cli->outbuf,smb_suwcnt,lsetup); /* suwcnt */
171 for (i=0;i<lsetup;i++) /* setup[] */
172 SSVAL(cli->outbuf,smb_setup+i*2,setup[i]);
173 p = smb_buf(cli->outbuf);
174 if (trans==SMBtrans) {
175 memcpy(p,name, pipe_name_len + 1); /* name[] */
177 *p++ = 0; /* put in a null smb_name */
178 *p++ = 'D'; *p++ = ' '; /* observed in OS/2 */
180 if (this_lparam) /* param[] */
181 memcpy(outparam,param,this_lparam);
182 if (this_ldata) /* data[] */
183 memcpy(outdata,data,this_ldata);
184 set_message(cli->outbuf,14+lsetup, /* wcnt, bcc */
185 PTR_DIFF(outdata+this_ldata,smb_buf(cli->outbuf)),False);
187 show_msg(cli->outbuf);
188 send_smb(cli->fd,cli->outbuf);
190 if (this_ldata < ldata || this_lparam < lparam) {
191 /* receive interim response */
192 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout) ||
193 CVAL(cli->inbuf,smb_rcls) != 0) {
197 tot_data = this_ldata;
198 tot_param = this_lparam;
200 while (tot_data < ldata || tot_param < lparam) {
201 this_lparam = MIN(lparam-tot_param,cli->max_xmit - 500); /* hack */
202 this_ldata = MIN(ldata-tot_data,cli->max_xmit - (500+this_lparam));
204 set_message(cli->outbuf,trans==SMBtrans?8:9,0,True);
205 CVAL(cli->outbuf,smb_com) = trans==SMBtrans ? SMBtranss : SMBtranss2;
207 outparam = smb_buf(cli->outbuf);
208 outdata = outparam+this_lparam;
210 /* secondary request */
211 SSVAL(cli->outbuf,smb_tpscnt,lparam); /* tpscnt */
212 SSVAL(cli->outbuf,smb_tdscnt,ldata); /* tdscnt */
213 SSVAL(cli->outbuf,smb_spscnt,this_lparam); /* pscnt */
214 SSVAL(cli->outbuf,smb_spsoff,smb_offset(outparam,cli->outbuf)); /* psoff */
215 SSVAL(cli->outbuf,smb_spsdisp,tot_param); /* psdisp */
216 SSVAL(cli->outbuf,smb_sdscnt,this_ldata); /* dscnt */
217 SSVAL(cli->outbuf,smb_sdsoff,smb_offset(outdata,cli->outbuf)); /* dsoff */
218 SSVAL(cli->outbuf,smb_sdsdisp,tot_data); /* dsdisp */
219 if (trans==SMBtrans2)
220 SSVALS(cli->outbuf,smb_sfid,fid); /* fid */
221 if (this_lparam) /* param[] */
222 memcpy(outparam,param,this_lparam);
223 if (this_ldata) /* data[] */
224 memcpy(outdata,data,this_ldata);
225 set_message(cli->outbuf,trans==SMBtrans?8:9, /* wcnt, bcc */
226 PTR_DIFF(outdata+this_ldata,smb_buf(cli->outbuf)),False);
228 show_msg(cli->outbuf);
229 send_smb(cli->fd,cli->outbuf);
231 tot_data += this_ldata;
232 tot_param += this_lparam;
240 /****************************************************************************
241 receive a SMB trans or trans2 response allocating the necessary memory
242 ****************************************************************************/
243 static BOOL cli_receive_trans(struct cli_state *cli,int trans,
244 char **param, int *param_len,
245 char **data, int *data_len)
249 int this_data,this_param;
251 *data_len = *param_len = 0;
253 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout))
256 show_msg(cli->inbuf);
259 if (CVAL(cli->inbuf,smb_com) != trans) {
260 DEBUG(0,("Expected %s response, got command 0x%02x\n",
261 trans==SMBtrans?"SMBtrans":"SMBtrans2",
262 CVAL(cli->inbuf,smb_com)));
265 if (CVAL(cli->inbuf,smb_rcls) != 0)
268 /* parse out the lengths */
269 total_data = SVAL(cli->inbuf,smb_tdrcnt);
270 total_param = SVAL(cli->inbuf,smb_tprcnt);
273 *data = Realloc(*data,total_data);
274 *param = Realloc(*param,total_param);
277 this_data = SVAL(cli->inbuf,smb_drcnt);
278 this_param = SVAL(cli->inbuf,smb_prcnt);
280 if (this_data + *data_len > total_data ||
281 this_param + *param_len > total_param) {
282 DEBUG(1,("Data overflow in cli_receive_trans\n"));
287 memcpy(*data + SVAL(cli->inbuf,smb_drdisp),
288 smb_base(cli->inbuf) + SVAL(cli->inbuf,smb_droff),
291 memcpy(*param + SVAL(cli->inbuf,smb_prdisp),
292 smb_base(cli->inbuf) + SVAL(cli->inbuf,smb_proff),
294 *data_len += this_data;
295 *param_len += this_param;
297 /* parse out the total lengths again - they can shrink! */
298 total_data = SVAL(cli->inbuf,smb_tdrcnt);
299 total_param = SVAL(cli->inbuf,smb_tprcnt);
301 if (total_data <= *data_len && total_param <= *param_len)
304 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout))
307 show_msg(cli->inbuf);
310 if (CVAL(cli->inbuf,smb_com) != trans) {
311 DEBUG(0,("Expected %s response, got command 0x%02x\n",
312 trans==SMBtrans?"SMBtrans":"SMBtrans2",
313 CVAL(cli->inbuf,smb_com)));
316 if (CVAL(cli->inbuf,smb_rcls) != 0)
323 /****************************************************************************
324 Call a remote api on an arbitrary pipe. takes param, data and setup buffers.
325 ****************************************************************************/
326 BOOL cli_api_pipe(struct cli_state *cli, char *pipe_name, int pipe_name_len,
327 uint16 *setup, uint32 setup_count, uint32 max_setup_count,
328 char *params, uint32 param_count, uint32 max_param_count,
329 char *data, uint32 data_count, uint32 max_data_count,
330 char **rparam, uint32 *rparam_count,
331 char **rdata, uint32 *rdata_count)
333 if(pipe_name_len == 0)
334 pipe_name_len = strlen(pipe_name);
336 cli_send_trans(cli, SMBtrans,
337 pipe_name, pipe_name_len,
338 0,0, /* fid, flags */
339 setup, setup_count, max_setup_count,
340 params, param_count, max_param_count,
341 data, data_count, max_data_count);
343 return (cli_receive_trans(cli, SMBtrans,
344 rparam, (int *)rparam_count,
345 rdata, (int *)rdata_count));
348 /****************************************************************************
350 ****************************************************************************/
351 BOOL cli_api(struct cli_state *cli,
352 char *param, int prcnt, int mprcnt,
353 char *data, int drcnt, int mdrcnt,
354 char **rparam, int *rprcnt,
355 char **rdata, int *rdrcnt)
357 cli_send_trans(cli,SMBtrans,
358 PIPE_LANMAN,strlen(PIPE_LANMAN), /* Name, length */
359 0,0, /* fid, flags */
360 NULL,0,0, /* Setup, length, max */
361 param, prcnt, mprcnt, /* Params, length, max */
362 data, drcnt, mdrcnt /* Data, length, max */
365 return (cli_receive_trans(cli,SMBtrans,
371 /****************************************************************************
372 perform a NetWkstaUserLogon
373 ****************************************************************************/
374 BOOL cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation)
382 memset(param, 0, sizeof(param));
384 /* send a SMBtrans command with api NetWkstaUserLogon */
386 SSVAL(p,0,132); /* api number */
388 pstrcpy(p,"OOWb54WrLh");
389 p = skip_string(p,1);
390 pstrcpy(p,"WB21BWDWWDDDDDDDzzzD");
391 p = skip_string(p,1);
396 p += 21; p++; p += 15; p++;
397 pstrcpy(p, workstation);
400 SSVAL(p, 0, BUFFER_SIZE);
402 SSVAL(p, 0, BUFFER_SIZE);
406 param, PTR_DIFF(p,param),1024, /* param, length, max */
407 NULL, 0, BUFFER_SIZE, /* data, length, max */
408 &rparam, &rprcnt, /* return params, return size */
409 &rdata, &rdrcnt /* return data, return size */
411 cli->rap_error = SVAL(rparam,0);
414 if (cli->rap_error == 0) {
415 DEBUG(4,("NetWkstaUserLogon success\n"));
416 cli->privilages = SVAL(p, 24);
417 fstrcpy(cli->eff_name,p+2);
419 DEBUG(1,("NetwkstaUserLogon gave error %d\n", cli->rap_error));
423 if (rparam) free(rparam);
424 if (rdata) free(rdata);
425 return (cli->rap_error == 0);
428 /****************************************************************************
429 call a NetShareEnum - try and browse available connections on a host
430 ****************************************************************************/
431 BOOL cli_RNetShareEnum(struct cli_state *cli, void (*fn)(char *, uint32, char *))
440 /* now send a SMBtrans command with api RNetShareEnum */
442 SSVAL(p,0,0); /* api number */
445 p = skip_string(p,1);
447 p = skip_string(p,1);
449 SSVAL(p,2,BUFFER_SIZE);
453 param, PTR_DIFF(p,param), 1024, /* Param, length, maxlen */
454 NULL, 0, BUFFER_SIZE, /* data, length, maxlen */
455 &rparam, &rprcnt, /* return params, length */
456 &rdata, &rdrcnt)) /* return data, length */
458 int res = SVAL(rparam,0);
459 int converter=SVAL(rparam,2);
464 count=SVAL(rparam,4);
467 for (i=0;i<count;i++,p+=20)
470 int type = SVAL(p,14);
471 int comment_offset = IVAL(p,16) & 0xFFFF;
472 char *cmnt = comment_offset?(rdata+comment_offset-converter):"";
473 fn(sname, type, cmnt);
478 if (rparam) free(rparam);
479 if (rdata) free(rdata);
484 /****************************************************************************
485 call a NetServerEnum for the specified workgroup and servertype mask.
486 This function then calls the specified callback function for each name returned.
488 The callback function takes 3 arguments: the machine name, the server type and
490 ****************************************************************************/
491 BOOL cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
492 void (*fn)(char *, uint32, char *))
502 /* send a SMBtrans command with api NetServerEnum */
504 SSVAL(p,0,0x68); /* api number */
506 pstrcpy(p,"WrLehDz");
507 p = skip_string(p,1);
509 pstrcpy(p,"B16BBDz");
511 p = skip_string(p,1);
513 SSVAL(p,2,BUFFER_SIZE);
518 pstrcpy(p, workgroup);
519 p = skip_string(p,1);
522 param, PTR_DIFF(p,param), 8, /* params, length, max */
523 NULL, 0, BUFFER_SIZE, /* data, length, max */
524 &rparam, &rprcnt, /* return params, return size */
525 &rdata, &rdrcnt /* return data, return size */
527 int res = SVAL(rparam,0);
528 int converter=SVAL(rparam,2);
532 count=SVAL(rparam,4);
535 for (i = 0;i < count;i++, p += 26) {
537 int comment_offset = (IVAL(p,22) & 0xFFFF)-converter;
538 char *cmnt = comment_offset?(rdata+comment_offset):"";
539 if (comment_offset < 0 || comment_offset > rdrcnt) continue;
541 stype = IVAL(p,18) & ~SV_TYPE_LOCAL_LIST_ONLY;
543 fn(sname, stype, cmnt);
548 if (rparam) free(rparam);
549 if (rdata) free(rdata);
563 {PROTOCOL_CORE,"PC NETWORK PROGRAM 1.0"},
564 {PROTOCOL_COREPLUS,"MICROSOFT NETWORKS 1.03"},
565 {PROTOCOL_LANMAN1,"MICROSOFT NETWORKS 3.0"},
566 {PROTOCOL_LANMAN1,"LANMAN1.0"},
567 {PROTOCOL_LANMAN2,"LM1.2X002"},
568 {PROTOCOL_LANMAN2,"Samba"},
569 {PROTOCOL_NT1,"NT LM 0.12"},
570 {PROTOCOL_NT1,"NT LANMAN 1.0"},
575 /****************************************************************************
577 ****************************************************************************/
578 BOOL cli_session_setup(struct cli_state *cli,
580 char *pass, int passlen,
581 char *ntpass, int ntpasslen,
587 if (cli->protocol < PROTOCOL_LANMAN1)
590 if (passlen > sizeof(pword)-1) {
594 if(((passlen == 0) || (passlen == 1)) && (pass[0] == '\0')) {
595 /* Null session connect. */
598 if ((cli->sec_mode & 2) && passlen != 24) {
600 SMBencrypt((uchar *)pass,(uchar *)cli->cryptkey,(uchar *)pword);
602 memcpy(pword, pass, passlen);
606 /* if in share level security then don't send a password now */
607 if (!(cli->sec_mode & 1)) {fstrcpy(pword, "");passlen=1;}
609 /* send a session setup command */
610 bzero(cli->outbuf,smb_size);
612 if (cli->protocol < PROTOCOL_NT1) {
613 set_message(cli->outbuf,10,1 + strlen(user) + passlen,True);
614 CVAL(cli->outbuf,smb_com) = SMBsesssetupX;
615 cli_setup_packet(cli);
617 CVAL(cli->outbuf,smb_vwv0) = 0xFF;
618 SSVAL(cli->outbuf,smb_vwv2,cli->max_xmit);
619 SSVAL(cli->outbuf,smb_vwv3,2);
620 SSVAL(cli->outbuf,smb_vwv4,1);
621 SIVAL(cli->outbuf,smb_vwv5,cli->sesskey);
622 SSVAL(cli->outbuf,smb_vwv7,passlen);
623 p = smb_buf(cli->outbuf);
624 memcpy(p,pword,passlen);
629 set_message(cli->outbuf,13,0,True);
630 CVAL(cli->outbuf,smb_com) = SMBsesssetupX;
631 cli_setup_packet(cli);
633 CVAL(cli->outbuf,smb_vwv0) = 0xFF;
634 SSVAL(cli->outbuf,smb_vwv2,BUFFER_SIZE);
635 SSVAL(cli->outbuf,smb_vwv3,2);
636 SSVAL(cli->outbuf,smb_vwv4,cli->pid);
637 SIVAL(cli->outbuf,smb_vwv5,cli->sesskey);
638 SSVAL(cli->outbuf,smb_vwv7,passlen);
639 SSVAL(cli->outbuf,smb_vwv8,ntpasslen);
640 p = smb_buf(cli->outbuf);
641 memcpy(p,pword,passlen);
642 p += SVAL(cli->outbuf,smb_vwv7);
643 memcpy(p,ntpass,ntpasslen);
644 p += SVAL(cli->outbuf,smb_vwv8);
647 p = skip_string(p,1);
648 pstrcpy(p,workgroup);
650 p = skip_string(p,1);
651 pstrcpy(p,"Unix");p = skip_string(p,1);
652 pstrcpy(p,"Samba");p = skip_string(p,1);
653 set_message(cli->outbuf,13,PTR_DIFF(p,smb_buf(cli->outbuf)),False);
656 send_smb(cli->fd,cli->outbuf);
657 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout))
660 show_msg(cli->inbuf);
662 if (CVAL(cli->inbuf,smb_rcls) != 0) {
666 /* use the returned uid from now on */
667 cli->uid = SVAL(cli->inbuf,smb_uid);
672 /****************************************************************************
674 *****************************************************************************/
676 BOOL cli_ulogoff(struct cli_state *cli)
678 bzero(cli->outbuf,smb_size);
679 set_message(cli->outbuf,2,0,True);
680 CVAL(cli->outbuf,smb_com) = SMBulogoffX;
681 cli_setup_packet(cli);
682 SSVAL(cli->outbuf,smb_vwv0,0xFF);
683 SSVAL(cli->outbuf,smb_vwv2,0); /* no additional info */
685 send_smb(cli->fd,cli->outbuf);
686 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout))
689 return CVAL(cli->inbuf,smb_rcls) == 0;
692 /****************************************************************************
694 ****************************************************************************/
695 BOOL cli_send_tconX(struct cli_state *cli,
696 char *share, char *dev, char *pass, int passlen)
698 fstring fullshare, pword;
700 bzero(cli->outbuf,smb_size);
701 bzero(cli->inbuf,smb_size);
703 if (cli->sec_mode & 1) {
708 if ((cli->sec_mode & 2) && *pass && passlen != 24) {
710 SMBencrypt((uchar *)pass,(uchar *)cli->cryptkey,(uchar *)pword);
712 memcpy(pword, pass, passlen);
715 slprintf(fullshare, sizeof(fullshare)-1,
716 "\\\\%s\\%s", cli->desthost, share);
718 set_message(cli->outbuf,4,
719 2 + strlen(fullshare) + passlen + strlen(dev),True);
720 CVAL(cli->outbuf,smb_com) = SMBtconX;
721 cli_setup_packet(cli);
723 SSVAL(cli->outbuf,smb_vwv0,0xFF);
724 SSVAL(cli->outbuf,smb_vwv3,passlen);
726 p = smb_buf(cli->outbuf);
727 memcpy(p,pword,passlen);
729 fstrcpy(p,fullshare);
730 p = skip_string(p,1);
733 SCVAL(cli->inbuf,smb_rcls, 1);
735 send_smb(cli->fd,cli->outbuf);
736 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout))
739 if (CVAL(cli->inbuf,smb_rcls) != 0) {
743 cli->cnum = SVAL(cli->inbuf,smb_tid);
748 /****************************************************************************
749 send a tree disconnect
750 ****************************************************************************/
751 BOOL cli_tdis(struct cli_state *cli)
753 bzero(cli->outbuf,smb_size);
754 set_message(cli->outbuf,0,0,True);
755 CVAL(cli->outbuf,smb_com) = SMBtdis;
756 SSVAL(cli->outbuf,smb_tid,cli->cnum);
757 cli_setup_packet(cli);
759 send_smb(cli->fd,cli->outbuf);
760 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout))
763 return CVAL(cli->inbuf,smb_rcls) == 0;
766 /****************************************************************************
768 ****************************************************************************/
769 BOOL cli_mv(struct cli_state *cli, char *fname_src, char *fname_dst)
773 bzero(cli->outbuf,smb_size);
774 bzero(cli->inbuf,smb_size);
776 set_message(cli->outbuf,1, 4 + strlen(fname_src) + strlen(fname_dst), True);
778 CVAL(cli->outbuf,smb_com) = SMBmv;
779 SSVAL(cli->outbuf,smb_tid,cli->cnum);
780 cli_setup_packet(cli);
782 SSVAL(cli->outbuf,smb_vwv0,aSYSTEM | aHIDDEN);
784 p = smb_buf(cli->outbuf);
786 pstrcpy(p,fname_src);
787 p = skip_string(p,1);
789 pstrcpy(p,fname_dst);
791 send_smb(cli->fd,cli->outbuf);
792 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
796 if (CVAL(cli->inbuf,smb_rcls) != 0) {
803 /****************************************************************************
805 ****************************************************************************/
806 BOOL cli_unlink(struct cli_state *cli, char *fname)
810 bzero(cli->outbuf,smb_size);
811 bzero(cli->inbuf,smb_size);
813 set_message(cli->outbuf,1, 2 + strlen(fname),True);
815 CVAL(cli->outbuf,smb_com) = SMBunlink;
816 SSVAL(cli->outbuf,smb_tid,cli->cnum);
817 cli_setup_packet(cli);
819 SSVAL(cli->outbuf,smb_vwv0,aSYSTEM | aHIDDEN);
821 p = smb_buf(cli->outbuf);
825 send_smb(cli->fd,cli->outbuf);
826 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
830 if (CVAL(cli->inbuf,smb_rcls) != 0) {
838 /****************************************************************************
840 ****************************************************************************/
841 BOOL cli_mkdir(struct cli_state *cli, char *dname)
845 bzero(cli->outbuf,smb_size);
846 bzero(cli->inbuf,smb_size);
848 set_message(cli->outbuf,0, 2 + strlen(dname),True);
850 CVAL(cli->outbuf,smb_com) = SMBmkdir;
851 SSVAL(cli->outbuf,smb_tid,cli->cnum);
852 cli_setup_packet(cli);
854 p = smb_buf(cli->outbuf);
858 send_smb(cli->fd,cli->outbuf);
859 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
863 if (CVAL(cli->inbuf,smb_rcls) != 0) {
870 /****************************************************************************
872 ****************************************************************************/
873 BOOL cli_rmdir(struct cli_state *cli, char *dname)
877 bzero(cli->outbuf,smb_size);
878 bzero(cli->inbuf,smb_size);
880 set_message(cli->outbuf,0, 2 + strlen(dname),True);
882 CVAL(cli->outbuf,smb_com) = SMBrmdir;
883 SSVAL(cli->outbuf,smb_tid,cli->cnum);
884 cli_setup_packet(cli);
886 p = smb_buf(cli->outbuf);
890 send_smb(cli->fd,cli->outbuf);
891 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
895 if (CVAL(cli->inbuf,smb_rcls) != 0) {
904 /****************************************************************************
906 ****************************************************************************/
907 int cli_open(struct cli_state *cli, char *fname, int flags, int share_mode)
911 unsigned accessmode=0;
915 if (!(flags & O_EXCL)) {
922 accessmode = (share_mode<<4);
924 if ((flags & O_RDWR) == O_RDWR) {
926 } else if ((flags & O_WRONLY) == O_WRONLY) {
931 if ((flags & O_SYNC) == O_SYNC) {
932 accessmode |= (1<<14);
936 bzero(cli->outbuf,smb_size);
937 bzero(cli->inbuf,smb_size);
939 set_message(cli->outbuf,15,1 + strlen(fname),True);
941 CVAL(cli->outbuf,smb_com) = SMBopenX;
942 SSVAL(cli->outbuf,smb_tid,cli->cnum);
943 cli_setup_packet(cli);
945 SSVAL(cli->outbuf,smb_vwv0,0xFF);
946 SSVAL(cli->outbuf,smb_vwv2,0); /* no additional info */
947 SSVAL(cli->outbuf,smb_vwv3,accessmode);
948 SSVAL(cli->outbuf,smb_vwv4,aSYSTEM | aHIDDEN);
949 SSVAL(cli->outbuf,smb_vwv5,0);
950 SSVAL(cli->outbuf,smb_vwv8,openfn);
952 p = smb_buf(cli->outbuf);
954 p = skip_string(p,1);
956 send_smb(cli->fd,cli->outbuf);
957 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
961 if (CVAL(cli->inbuf,smb_rcls) != 0) {
965 return SVAL(cli->inbuf,smb_vwv2);
971 /****************************************************************************
973 ****************************************************************************/
974 BOOL cli_close(struct cli_state *cli, int fnum)
976 bzero(cli->outbuf,smb_size);
977 bzero(cli->inbuf,smb_size);
979 set_message(cli->outbuf,3,0,True);
981 CVAL(cli->outbuf,smb_com) = SMBclose;
982 SSVAL(cli->outbuf,smb_tid,cli->cnum);
983 cli_setup_packet(cli);
985 SSVAL(cli->outbuf,smb_vwv0,fnum);
986 SIVALS(cli->outbuf,smb_vwv1,-1);
988 send_smb(cli->fd,cli->outbuf);
989 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
993 if (CVAL(cli->inbuf,smb_rcls) != 0) {
1001 /****************************************************************************
1003 ****************************************************************************/
1004 BOOL cli_lock(struct cli_state *cli, int fnum, uint32 offset, uint32 len, int timeout)
1008 bzero(cli->outbuf,smb_size);
1009 bzero(cli->inbuf,smb_size);
1011 set_message(cli->outbuf,8,10,True);
1013 CVAL(cli->outbuf,smb_com) = SMBlockingX;
1014 SSVAL(cli->outbuf,smb_tid,cli->cnum);
1015 cli_setup_packet(cli);
1017 CVAL(cli->outbuf,smb_vwv0) = 0xFF;
1018 SSVAL(cli->outbuf,smb_vwv2,fnum);
1019 CVAL(cli->outbuf,smb_vwv3) = 0;
1020 SIVALS(cli->outbuf, smb_vwv4, timeout);
1021 SSVAL(cli->outbuf,smb_vwv6,0);
1022 SSVAL(cli->outbuf,smb_vwv7,1);
1024 p = smb_buf(cli->outbuf);
1025 SSVAL(p, 0, cli->pid);
1026 SIVAL(p, 2, offset);
1029 send_smb(cli->fd,cli->outbuf);
1030 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
1034 if (CVAL(cli->inbuf,smb_rcls) != 0) {
1041 /****************************************************************************
1043 ****************************************************************************/
1044 BOOL cli_unlock(struct cli_state *cli, int fnum, uint32 offset, uint32 len, int timeout)
1048 bzero(cli->outbuf,smb_size);
1049 bzero(cli->inbuf,smb_size);
1051 set_message(cli->outbuf,8,10,True);
1053 CVAL(cli->outbuf,smb_com) = SMBlockingX;
1054 SSVAL(cli->outbuf,smb_tid,cli->cnum);
1055 cli_setup_packet(cli);
1057 CVAL(cli->outbuf,smb_vwv0) = 0xFF;
1058 SSVAL(cli->outbuf,smb_vwv2,fnum);
1059 CVAL(cli->outbuf,smb_vwv3) = 0;
1060 SIVALS(cli->outbuf, smb_vwv4, timeout);
1061 SSVAL(cli->outbuf,smb_vwv6,1);
1062 SSVAL(cli->outbuf,smb_vwv7,0);
1064 p = smb_buf(cli->outbuf);
1065 SSVAL(p, 0, cli->pid);
1066 SIVAL(p, 2, offset);
1069 send_smb(cli->fd,cli->outbuf);
1070 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
1074 if (CVAL(cli->inbuf,smb_rcls) != 0) {
1082 /****************************************************************************
1084 ****************************************************************************/
1085 int cli_read(struct cli_state *cli, int fnum, char *buf, uint32 offset, uint16 size)
1089 bzero(cli->outbuf,smb_size);
1090 bzero(cli->inbuf,smb_size);
1092 set_message(cli->outbuf,10,0,True);
1094 CVAL(cli->outbuf,smb_com) = SMBreadX;
1095 SSVAL(cli->outbuf,smb_tid,cli->cnum);
1096 cli_setup_packet(cli);
1098 CVAL(cli->outbuf,smb_vwv0) = 0xFF;
1099 SSVAL(cli->outbuf,smb_vwv2,fnum);
1100 SIVAL(cli->outbuf,smb_vwv3,offset);
1101 SSVAL(cli->outbuf,smb_vwv5,size);
1102 SSVAL(cli->outbuf,smb_vwv6,size);
1104 send_smb(cli->fd,cli->outbuf);
1105 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
1109 if (CVAL(cli->inbuf,smb_rcls) != 0) {
1113 size = SVAL(cli->inbuf, smb_vwv5);
1114 p = smb_base(cli->inbuf) + SVAL(cli->inbuf,smb_vwv6);
1116 memcpy(buf, p, size);
1122 /****************************************************************************
1124 ****************************************************************************/
1125 int cli_write(struct cli_state *cli, int fnum, char *buf, uint32 offset, uint16 size)
1129 bzero(cli->outbuf,smb_size);
1130 bzero(cli->inbuf,smb_size);
1132 set_message(cli->outbuf,12,size,True);
1134 CVAL(cli->outbuf,smb_com) = SMBwriteX;
1135 SSVAL(cli->outbuf,smb_tid,cli->cnum);
1136 cli_setup_packet(cli);
1138 CVAL(cli->outbuf,smb_vwv0) = 0xFF;
1139 SSVAL(cli->outbuf,smb_vwv2,fnum);
1140 SIVAL(cli->outbuf,smb_vwv3,offset);
1142 SSVAL(cli->outbuf,smb_vwv10,size);
1143 SSVAL(cli->outbuf,smb_vwv11,smb_buf(cli->outbuf) - smb_base(cli->outbuf));
1145 p = smb_base(cli->outbuf) + SVAL(cli->outbuf,smb_vwv11);
1146 memcpy(p, buf, size);
1148 send_smb(cli->fd,cli->outbuf);
1149 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
1153 if (CVAL(cli->inbuf,smb_rcls) != 0) {
1157 return SVAL(cli->inbuf, smb_vwv2);
1161 /****************************************************************************
1163 ****************************************************************************/
1164 BOOL cli_getatr(struct cli_state *cli, char *fname,
1165 int *attr, uint32 *size, time_t *t)
1169 bzero(cli->outbuf,smb_size);
1170 bzero(cli->inbuf,smb_size);
1172 set_message(cli->outbuf,0,strlen(fname)+2,True);
1174 CVAL(cli->outbuf,smb_com) = SMBgetatr;
1175 SSVAL(cli->outbuf,smb_tid,cli->cnum);
1176 cli_setup_packet(cli);
1178 p = smb_buf(cli->outbuf);
1180 pstrcpy(p+1, fname);
1182 send_smb(cli->fd,cli->outbuf);
1183 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
1187 if (CVAL(cli->inbuf,smb_rcls) != 0) {
1192 *size = IVAL(cli->inbuf, smb_vwv3);
1196 *t = make_unix_date3(cli->inbuf+smb_vwv1);
1200 *attr = SVAL(cli->inbuf,smb_vwv0);
1208 /****************************************************************************
1210 ****************************************************************************/
1211 BOOL cli_setatr(struct cli_state *cli, char *fname, int attr, time_t t)
1215 bzero(cli->outbuf,smb_size);
1216 bzero(cli->inbuf,smb_size);
1218 set_message(cli->outbuf,8,strlen(fname)+4,True);
1220 CVAL(cli->outbuf,smb_com) = SMBsetatr;
1221 SSVAL(cli->outbuf,smb_tid,cli->cnum);
1222 cli_setup_packet(cli);
1224 SSVAL(cli->outbuf,smb_vwv0, attr);
1225 put_dos_date3(cli->outbuf,smb_vwv1, t);
1227 p = smb_buf(cli->outbuf);
1229 pstrcpy(p+1, fname);
1230 p = skip_string(p,1);
1233 send_smb(cli->fd,cli->outbuf);
1234 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
1238 if (CVAL(cli->inbuf,smb_rcls) != 0) {
1245 /****************************************************************************
1246 send a qpathinfo call
1247 ****************************************************************************/
1248 BOOL cli_qpathinfo(struct cli_state *cli, char *fname,
1249 time_t *c_time, time_t *a_time, time_t *m_time, uint32 *size)
1253 uint16 setup = TRANSACT2_QPATHINFO;
1255 char *rparam=NULL, *rdata=NULL;
1257 param_len = strlen(fname) + 7;
1259 memset(param, 0, param_len);
1260 SSVAL(param, 0, SMB_INFO_STANDARD);
1261 pstrcpy(¶m[6], fname);
1263 if (!cli_send_trans(cli, SMBtrans2,
1264 NULL, 0, /* Name, length */
1265 -1, 0, /* fid, flags */
1266 &setup, 1, 0, /* setup, length, max */
1267 param, param_len, 10, /* param, length, max */
1268 NULL, data_len, cli->max_xmit /* data, length, max */
1273 if (!cli_receive_trans(cli, SMBtrans2,
1274 &rparam, ¶m_len,
1275 &rdata, &data_len)) {
1279 if (!rdata || data_len < 22) {
1284 *c_time = make_unix_date2(rdata+0);
1287 *a_time = make_unix_date2(rdata+4);
1290 *m_time = make_unix_date2(rdata+8);
1293 *size = IVAL(rdata, 12);
1296 if (rdata) free(rdata);
1297 if (rparam) free(rparam);
1301 /****************************************************************************
1302 send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level
1303 ****************************************************************************/
1304 BOOL cli_qpathinfo2(struct cli_state *cli, char *fname,
1305 time_t *c_time, time_t *a_time, time_t *m_time,
1306 time_t *w_time, uint32 *size)
1310 uint16 setup = TRANSACT2_QPATHINFO;
1312 char *rparam=NULL, *rdata=NULL;
1314 param_len = strlen(fname) + 7;
1316 memset(param, 0, param_len);
1317 SSVAL(param, 0, SMB_QUERY_FILE_ALL_INFO);
1318 pstrcpy(¶m[6], fname);
1320 if (!cli_send_trans(cli, SMBtrans2,
1321 NULL, 0, /* name, length */
1322 -1, 0, /* fid, flags */
1323 &setup, 1, 0, /* setup, length, max */
1324 param, param_len, 10, /* param, length, max */
1325 NULL, data_len, cli->max_xmit /* data, length, max */
1330 if (!cli_receive_trans(cli, SMBtrans2,
1331 &rparam, ¶m_len,
1332 &rdata, &data_len)) {
1336 if (!rdata || data_len < 22) {
1341 *c_time = interpret_long_date(rdata+0) - cli->serverzone;
1344 *a_time = interpret_long_date(rdata+8) - cli->serverzone;
1347 *m_time = interpret_long_date(rdata+16) - cli->serverzone;
1350 *w_time = interpret_long_date(rdata+24) - cli->serverzone;
1353 *size = IVAL(rdata, 40);
1356 if (rdata) free(rdata);
1357 if (rparam) free(rparam);
1362 /****************************************************************************
1363 send a qfileinfo call
1364 ****************************************************************************/
1365 BOOL cli_qfileinfo(struct cli_state *cli, int fnum,
1366 time_t *c_time, time_t *a_time, time_t *m_time, uint32 *size)
1370 uint16 setup = TRANSACT2_QFILEINFO;
1372 char *rparam=NULL, *rdata=NULL;
1376 memset(param, 0, param_len);
1377 SSVAL(param, 0, fnum);
1378 SSVAL(param, 2, SMB_INFO_STANDARD);
1380 if (!cli_send_trans(cli, SMBtrans2,
1381 NULL, 0, /* name, length */
1382 -1, 0, /* fid, flags */
1383 &setup, 1, 0, /* setup, length, max */
1384 param, param_len, 2, /* param, length, max */
1385 NULL, data_len, cli->max_xmit /* data, length, max */
1390 if (!cli_receive_trans(cli, SMBtrans2,
1391 &rparam, ¶m_len,
1392 &rdata, &data_len)) {
1396 if (!rdata || data_len < 22) {
1401 *c_time = make_unix_date2(rdata+0);
1404 *a_time = make_unix_date2(rdata+4);
1407 *m_time = make_unix_date2(rdata+8);
1410 *size = IVAL(rdata, 12);
1413 if (rdata) free(rdata);
1414 if (rparam) free(rparam);
1418 /****************************************************************************
1419 Send a SamOEMChangePassword command
1420 ****************************************************************************/
1422 BOOL cli_oem_change_password(struct cli_state *cli, char *user, char *new_password,
1425 char param[16+sizeof(fstring)];
1428 fstring upper_case_old_pw;
1429 fstring upper_case_new_pw;
1430 unsigned char old_pw_hash[16];
1431 unsigned char new_pw_hash[16];
1434 int new_pw_len = strlen(new_password);
1435 char *rparam = NULL;
1439 if(strlen(user) >= sizeof(fstring)-1) {
1440 DEBUG(0,("cli_oem_change_password: user name %s is too long.\n", user));
1444 if(new_pw_len > 512) {
1445 DEBUG(0,("cli_oem_change_password: new password for user %s is too long.\n", user));
1449 SSVAL(p,0,214); /* SamOEMChangePassword command. */
1452 p = skip_string(p,1);
1453 pstrcpy(p, "B516B16");
1454 p = skip_string(p,1);
1456 p = skip_string(p,1);
1460 param_len = PTR_DIFF(p,param);
1463 * Now setup the data area.
1464 * We need to generate a random fill
1465 * for this area to make it harder to
1468 generate_random_buffer((unsigned char *)data, sizeof(data), False);
1469 fstrcpy( &data[512 - new_pw_len], new_password);
1470 SIVAL(data, 512, new_pw_len);
1473 * Get the Lanman hash of the old password, we
1474 * use this as the key to SamOEMHash().
1476 memset(upper_case_old_pw, '\0', sizeof(upper_case_old_pw));
1477 fstrcpy(upper_case_old_pw, old_password);
1478 strupper(upper_case_old_pw);
1479 E_P16((uchar *)upper_case_old_pw, old_pw_hash);
1481 SamOEMhash( (unsigned char *)data, (unsigned char *)old_pw_hash, True);
1484 * Now place the old password hash in the data.
1486 memset(upper_case_new_pw, '\0', sizeof(upper_case_new_pw));
1487 fstrcpy(upper_case_new_pw, new_password);
1488 strupper(upper_case_new_pw);
1490 E_P16((uchar *)upper_case_new_pw, new_pw_hash);
1492 E_old_pw_hash( new_pw_hash, old_pw_hash, (uchar *)&data[516]);
1496 if(cli_send_trans(cli,SMBtrans,
1497 PIPE_LANMAN,strlen(PIPE_LANMAN), /* name, length */
1498 0,0, /* fid, flags */
1499 NULL,0,0, /* setup, length, max */
1500 param,param_len,2, /* param, length, max */
1501 data,data_len,0 /* data, length, max */
1503 DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
1508 if(cli_receive_trans(cli,SMBtrans,
1512 cli->rap_error = SVAL(rparam,0);
1520 return (cli->rap_error == 0);
1523 /****************************************************************************
1524 send a negprot command
1525 ****************************************************************************/
1526 BOOL cli_negprot(struct cli_state *cli)
1532 bzero(cli->outbuf,smb_size);
1534 /* setup the protocol strings */
1535 for (plength=0,numprots=0;
1536 prots[numprots].name && prots[numprots].prot<=cli->protocol;
1538 plength += strlen(prots[numprots].name)+2;
1540 set_message(cli->outbuf,0,plength,True);
1542 p = smb_buf(cli->outbuf);
1544 prots[numprots].name && prots[numprots].prot<=cli->protocol;
1547 pstrcpy(p,prots[numprots].name);
1551 CVAL(cli->outbuf,smb_com) = SMBnegprot;
1552 cli_setup_packet(cli);
1554 CVAL(smb_buf(cli->outbuf),0) = 2;
1556 send_smb(cli->fd,cli->outbuf);
1557 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout))
1560 show_msg(cli->inbuf);
1562 if (CVAL(cli->inbuf,smb_rcls) != 0 ||
1563 ((int)SVAL(cli->inbuf,smb_vwv0) >= numprots)) {
1567 cli->protocol = prots[SVAL(cli->inbuf,smb_vwv0)].prot;
1570 if (cli->protocol >= PROTOCOL_NT1) {
1572 cli->sec_mode = CVAL(cli->inbuf,smb_vwv1);
1573 cli->max_xmit = IVAL(cli->inbuf,smb_vwv3+1);
1574 cli->sesskey = IVAL(cli->inbuf,smb_vwv7+1);
1575 cli->serverzone = SVALS(cli->inbuf,smb_vwv15+1)*60;
1576 /* this time arrives in real GMT */
1577 cli->servertime = interpret_long_date(cli->inbuf+smb_vwv11+1);
1578 memcpy(cli->cryptkey,smb_buf(cli->inbuf),8);
1579 if (IVAL(cli->inbuf,smb_vwv9+1) & 1)
1580 cli->readbraw_supported =
1581 cli->writebraw_supported = True;
1582 } else if (cli->protocol >= PROTOCOL_LANMAN1) {
1583 cli->sec_mode = SVAL(cli->inbuf,smb_vwv1);
1584 cli->max_xmit = SVAL(cli->inbuf,smb_vwv2);
1585 cli->sesskey = IVAL(cli->inbuf,smb_vwv6);
1586 cli->serverzone = SVALS(cli->inbuf,smb_vwv10)*60;
1587 /* this time is converted to GMT by make_unix_date */
1588 cli->servertime = make_unix_date(cli->inbuf+smb_vwv8);
1589 cli->readbraw_supported = ((SVAL(cli->inbuf,smb_vwv5) & 0x1) != 0);
1590 cli->writebraw_supported = ((SVAL(cli->inbuf,smb_vwv5) & 0x2) != 0);
1591 memcpy(cli->cryptkey,smb_buf(cli->inbuf),8);
1593 /* the old core protocol */
1595 cli->serverzone = TimeDiff(time(NULL));
1602 /****************************************************************************
1603 send a session request
1604 ****************************************************************************/
1605 BOOL cli_session_request(struct cli_state *cli, char *host, int name_type,
1611 /* send a session request (RFC 1002) */
1615 p = strchr(dest,'.');
1618 fstrcpy(cli->desthost, dest);
1620 /* put in the destination name */
1621 p = cli->outbuf+len;
1622 name_mangle(dest,p,name_type);
1626 p = cli->outbuf+len;
1627 name_mangle(myname,p,0);
1630 /* setup the packet length */
1631 _smb_setlen(cli->outbuf,len);
1632 CVAL(cli->outbuf,0) = 0x81;
1636 #endif /* WITH_SSL */
1638 send_smb(cli->fd,cli->outbuf);
1639 DEBUG(5,("Sent session request\n"));
1641 if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout))
1645 if(CVAL(cli->inbuf,0) == 0x83 && CVAL(cli->inbuf,4) == 0x8e){ /* use ssl */
1646 if(!sslutil_fd_is_ssl(cli->fd)){
1647 if(sslutil_connect(cli->fd) == 0)
1651 #endif /* WITH_SSL */
1653 if (CVAL(cli->inbuf,0) != 0x82) {
1654 /* This is the wrong place to put the error... JRA. */
1655 cli->rap_error = CVAL(cli->inbuf,0);
1662 /****************************************************************************
1663 open the client sockets
1664 ****************************************************************************/
1665 BOOL cli_connect(struct cli_state *cli, char *host, struct in_addr *ip)
1667 struct in_addr dest_ip;
1669 fstrcpy(cli->desthost, host);
1672 if(!resolve_name( cli->desthost, &dest_ip)) {
1680 cli->fd = open_socket_out(SOCK_STREAM, &dest_ip, 139, cli->timeout);
1688 /****************************************************************************
1689 initialise a client structure
1690 ****************************************************************************/
1691 BOOL cli_initialise(struct cli_state *cli)
1693 if (cli->initialised) cli_shutdown(cli);
1695 memset(cli, 0, sizeof(*cli));
1698 cli->pid = getpid();
1700 cli->uid = getuid();
1701 cli->protocol = PROTOCOL_NT1;
1702 cli->timeout = 20000;
1703 cli->bufsize = 0x10000;
1704 cli->max_xmit = cli->bufsize - 4;
1705 cli->outbuf = (char *)malloc(cli->bufsize);
1706 cli->inbuf = (char *)malloc(cli->bufsize);
1707 if (!cli->outbuf || !cli->inbuf) return False;
1708 cli->initialised = 1;
1712 /****************************************************************************
1713 shutdown a client structure
1714 ****************************************************************************/
1715 void cli_shutdown(struct cli_state *cli)
1717 if (cli->outbuf) free(cli->outbuf);
1718 if (cli->inbuf) free(cli->inbuf);
1720 if (cli->fd != -1) sslutil_disconnect(cli->fd);
1721 #endif /* WITH_SSL */
1722 if (cli->fd != -1) close(cli->fd);
1723 memset(cli, 0, sizeof(*cli));
1726 /****************************************************************************
1727 return error codes for the last packet
1728 ****************************************************************************/
1729 void cli_error(struct cli_state *cli, int *eclass, int *num)
1731 *eclass = CVAL(cli->inbuf,smb_rcls);
1732 *num = SVAL(cli->inbuf,smb_err);
1735 /****************************************************************************
1736 set socket options on a open connection
1737 ****************************************************************************/
1738 void cli_sockopt(struct cli_state *cli, char *options)
1740 set_socket_options(cli->fd, options);
1743 /****************************************************************************
1744 set the PID to use for smb messages. Return the old pid.
1745 ****************************************************************************/
1746 int cli_setpid(struct cli_state *cli, int pid)