+++ /dev/null
-/*
- Unix SMB/Netbios implementation.
- Version 1.9.
- SMB client
- Copyright (C) Andrew Tridgell 1994-1997
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#ifdef SYSLOG
-#undef SYSLOG
-#endif
-
-#include "includes.h"
-
-#ifndef REGISTER
-#define REGISTER 0
-#endif
-
-pstring service="";
-pstring desthost="";
-extern pstring myname;
-pstring password = "";
-pstring username="";
-pstring workgroup=WORKGROUP;
-BOOL got_pass = False;
-BOOL connect_as_printer = False;
-BOOL connect_as_ipc = False;
-
-char cryptkey[8];
-BOOL doencrypt=False;
-
-extern pstring user_socket_options;
-
-/* 30 second timeout on most commands */
-#define CLIENT_TIMEOUT (30*1000)
-#define SHORT_TIMEOUT (5*1000)
-
-int name_type = 0x20;
-
-int max_protocol = PROTOCOL_NT1;
-
-BOOL readbraw_supported = False;
-BOOL writebraw_supported = False;
-
-extern int DEBUGLEVEL;
-
-int cnum = 0;
-int pid = 0;
-int gid = 0;
-int uid = 0;
-int mid = 0;
-
-int max_xmit = BUFFER_SIZE;
-
-BOOL have_ip = False;
-
-extern struct in_addr dest_ip;
-
-extern int Protocol;
-
-extern int Client;
-
-
-/****************************************************************************
-setup basics in a outgoing packet
-****************************************************************************/
-void cli_setup_pkt(char *outbuf)
-{
- SSVAL(outbuf,smb_pid,pid);
- SSVAL(outbuf,smb_uid,uid);
- SSVAL(outbuf,smb_mid,mid);
- if (Protocol > PROTOCOL_COREPLUS)
- {
- SCVAL(outbuf,smb_flg,0x8);
- SSVAL(outbuf,smb_flg2,0x1);
- }
-}
-
-/****************************************************************************
-call a remote api
-****************************************************************************/
-BOOL cli_call_api(char *pipe_name, int pipe_name_len,
- int prcnt,int drcnt, int srcnt,
- int mprcnt,int mdrcnt,
- int *rprcnt,int *rdrcnt,
- char *param,char *data, uint16 *setup,
- char **rparam,char **rdata)
-{
- static char *inbuf=NULL;
- static char *outbuf=NULL;
-
- if (!inbuf) inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN);
- if (!outbuf) outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN);
-
- if (pipe_name_len == 0) pipe_name_len = strlen(pipe_name);
-
- cli_send_trans_request(outbuf,SMBtrans,pipe_name, pipe_name_len, 0,0,
- data, param, setup,
- drcnt, prcnt, srcnt,
- mdrcnt, mprcnt, 0);
-
- return (cli_receive_trans_response(inbuf,SMBtrans,
- rdrcnt,rprcnt,
- rdata,rparam));
-}
-
-
-/****************************************************************************
- receive a SMB trans or trans2 response allocating the necessary memory
- ****************************************************************************/
-BOOL cli_receive_trans_response(char *inbuf,int trans,
- int *data_len,int *param_len,
- char **data,char **param)
-{
- int total_data=0;
- int total_param=0;
- int this_data,this_param;
-
- *data_len = *param_len = 0;
-
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
- show_msg(inbuf);
-
- /* sanity check */
- if (CVAL(inbuf,smb_com) != trans)
- {
- DEBUG(0,("Expected %s response, got command 0x%02x\n",
- trans==SMBtrans?"SMBtrans":"SMBtrans2", CVAL(inbuf,smb_com)));
- return(False);
- }
- if (CVAL(inbuf,smb_rcls) != 0)
- return(False);
-
- /* parse out the lengths */
- total_data = SVAL(inbuf,smb_tdrcnt);
- total_param = SVAL(inbuf,smb_tprcnt);
-
- /* allocate it */
- *data = Realloc(*data,total_data);
- *param = Realloc(*param,total_param);
-
- while (1)
- {
- this_data = SVAL(inbuf,smb_drcnt);
- this_param = SVAL(inbuf,smb_prcnt);
- if (this_data)
- memcpy(*data + SVAL(inbuf,smb_drdisp),
- smb_base(inbuf) + SVAL(inbuf,smb_droff),
- this_data);
- if (this_param)
- memcpy(*param + SVAL(inbuf,smb_prdisp),
- smb_base(inbuf) + SVAL(inbuf,smb_proff),
- this_param);
- *data_len += this_data;
- *param_len += this_param;
-
- /* parse out the total lengths again - they can shrink! */
- total_data = SVAL(inbuf,smb_tdrcnt);
- total_param = SVAL(inbuf,smb_tprcnt);
-
- if (total_data <= *data_len && total_param <= *param_len)
- break;
-
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
- show_msg(inbuf);
-
- /* sanity check */
- if (CVAL(inbuf,smb_com) != trans)
- {
- DEBUG(0,("Expected %s response, got command 0x%02x\n",
- trans==SMBtrans?"SMBtrans":"SMBtrans2", CVAL(inbuf,smb_com)));
- return(False);
- }
- if (CVAL(inbuf,smb_rcls) != 0)
- return(False);
- }
-
- return(True);
-}
-
-
-
-/****************************************************************************
- send a SMB trans or trans2 request
- ****************************************************************************/
-BOOL cli_send_trans_request(char *outbuf,int trans,
- char *name,int namelen, int fid,int flags,
- char *data,char *param,uint16 *setup,
- int ldata,int lparam,int lsetup,
- int mdata,int mparam,int msetup)
-{
- int i;
- int this_ldata,this_lparam;
- int tot_data=0,tot_param=0;
- char *outdata,*outparam;
- pstring inbuf;
- char *p;
-
- this_lparam = MIN(lparam,max_xmit - (500+lsetup*SIZEOFWORD)); /* hack */
- this_ldata = MIN(ldata,max_xmit - (500+lsetup*SIZEOFWORD+this_lparam));
-
- bzero(outbuf,smb_size);
- set_message(outbuf,14+lsetup,0,True);
- CVAL(outbuf,smb_com) = trans;
- SSVAL(outbuf,smb_tid,cnum);
- cli_setup_pkt(outbuf);
-
- outparam = smb_buf(outbuf)+(trans==SMBtrans ? namelen+1 : 3);
- outdata = outparam+this_lparam;
-
- /* primary request */
- SSVAL(outbuf,smb_tpscnt,lparam); /* tpscnt */
- SSVAL(outbuf,smb_tdscnt,ldata); /* tdscnt */
- SSVAL(outbuf,smb_mprcnt,mparam); /* mprcnt */
- SSVAL(outbuf,smb_mdrcnt,mdata); /* mdrcnt */
- SCVAL(outbuf,smb_msrcnt,msetup); /* msrcnt */
- SSVAL(outbuf,smb_flags,flags); /* flags */
- SIVAL(outbuf,smb_timeout,0); /* timeout */
- SSVAL(outbuf,smb_pscnt,this_lparam); /* pscnt */
- SSVAL(outbuf,smb_psoff,smb_offset(outparam,outbuf)); /* psoff */
- SSVAL(outbuf,smb_dscnt,this_ldata); /* dscnt */
- SSVAL(outbuf,smb_dsoff,smb_offset(outdata,outbuf)); /* dsoff */
- SCVAL(outbuf,smb_suwcnt,lsetup); /* suwcnt */
- for (i=0;i<lsetup;i++) /* setup[] */
- SSVAL(outbuf,smb_setup+i*SIZEOFWORD,setup[i]);
- p = smb_buf(outbuf);
- if (trans==SMBtrans)
- memcpy(p,name, namelen+1); /* name[] */
- else
- {
- *p++ = 0; /* put in a null smb_name */
- *p++ = 'D'; *p++ = ' '; /* this was added because OS/2 does it */
- }
- if (this_lparam) /* param[] */
- memcpy(outparam,param,this_lparam);
- if (this_ldata) /* data[] */
- memcpy(outdata,data,this_ldata);
- set_message(outbuf,14+lsetup, /* wcnt, bcc */
- PTR_DIFF(outdata+this_ldata,smb_buf(outbuf)),False);
-
- show_msg(outbuf);
- send_smb(Client,outbuf);
-
- if (this_ldata < ldata || this_lparam < lparam)
- {
- /* receive interim response */
- if (!receive_smb(Client,inbuf,SHORT_TIMEOUT) || CVAL(inbuf,smb_rcls) != 0)
- {
- DEBUG(0,("%s request failed (%s)\n",
- trans==SMBtrans?"SMBtrans":"SMBtrans2", smb_errstr(inbuf)));
- return(False);
- }
-
- tot_data = this_ldata;
- tot_param = this_lparam;
-
- while (tot_data < ldata || tot_param < lparam)
- {
- this_lparam = MIN(lparam-tot_param,max_xmit - 500); /* hack */
- this_ldata = MIN(ldata-tot_data,max_xmit - (500+this_lparam));
-
- set_message(outbuf,trans==SMBtrans?8:9,0,True);
- CVAL(outbuf,smb_com) = trans==SMBtrans ? SMBtranss : SMBtranss2;
-
- outparam = smb_buf(outbuf);
- outdata = outparam+this_lparam;
-
- /* secondary request */
- SSVAL(outbuf,smb_tpscnt,lparam); /* tpscnt */
- SSVAL(outbuf,smb_tdscnt,ldata); /* tdscnt */
- SSVAL(outbuf,smb_spscnt,this_lparam); /* pscnt */
- SSVAL(outbuf,smb_spsoff,smb_offset(outparam,outbuf)); /* psoff */
- SSVAL(outbuf,smb_spsdisp,tot_param); /* psdisp */
- SSVAL(outbuf,smb_sdscnt,this_ldata); /* dscnt */
- SSVAL(outbuf,smb_sdsoff,smb_offset(outdata,outbuf)); /* dsoff */
- SSVAL(outbuf,smb_sdsdisp,tot_data); /* dsdisp */
- if (trans==SMBtrans2)
- SSVAL(outbuf,smb_sfid,fid); /* fid */
- if (this_lparam) /* param[] */
- memcpy(outparam,param,this_lparam);
- if (this_ldata) /* data[] */
- memcpy(outdata,data,this_ldata);
- set_message(outbuf,trans==SMBtrans?8:9, /* wcnt, bcc */
- PTR_DIFF(outdata+this_ldata,smb_buf(outbuf)),False);
-
- show_msg(outbuf);
- send_smb(Client,outbuf);
-
- tot_data += this_ldata;
- tot_param += this_lparam;
- }
- }
-
- return(True);
-}
-
-
-/****************************************************************************
-send a session request
-****************************************************************************/
-BOOL cli_send_session_request(char *inbuf,char *outbuf)
-{
- fstring dest;
- char *p;
- int len = 4;
- /* send a session request (RFC 8002) */
-
- strcpy(dest,desthost);
- p = strchr(dest,'.');
- if (p) *p = 0;
-
- /* put in the destination name */
- p = outbuf+len;
- name_mangle(dest,p,name_type); /* 0x20 is the SMB server NetBIOS type. */
- len += name_len(p);
-
- /* and my name */
- p = outbuf+len;
- name_mangle(myname,p,0);
- len += name_len(p);
-
- /* setup the packet length */
- _smb_setlen(outbuf,len);
- CVAL(outbuf,0) = 0x81;
-
- send_smb(Client,outbuf);
- DEBUG(5,("Sent session request\n"));
-
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
-
- if (CVAL(inbuf,0) == 0x84) /* C. Hoch 9/14/95 Start */
- {
- /* For information, here is the response structure.
- * We do the byte-twiddling to for portability.
- struct RetargetResponse{
- unsigned char type;
- unsigned char flags;
- int16 length;
- int32 ip_addr;
- int16 port;
- };
- */
- extern int Client;
- int port = (CVAL(inbuf,8)<<8)+CVAL(inbuf,9);
- /* SESSION RETARGET */
- putip((char *)&dest_ip,inbuf+4);
-
- close_sockets();
- Client = open_socket_out(SOCK_STREAM, &dest_ip, port, LONG_CONNECT_TIMEOUT);
- if (Client == -1)
- return False;
-
- DEBUG(3,("Retargeted\n"));
-
- set_socket_options(Client,user_socket_options);
-
- /* Try again */
- return cli_send_session_request(inbuf,outbuf);
- } /* C. Hoch 9/14/95 End */
-
-
- if (CVAL(inbuf,0) != 0x82)
- {
- int ecode = CVAL(inbuf,4);
- DEBUG(0,("Session request failed (%d,%d) with myname=%s destname=%s\n",
- CVAL(inbuf,0),ecode,myname,desthost));
- switch (ecode)
- {
- case 0x80:
- DEBUG(0,("Not listening on called name\n"));
- DEBUG(0,("Try to connect to another name (instead of %s)\n",desthost));
- DEBUG(0,("You may find the -I option useful for this\n"));
- break;
- case 0x81:
- DEBUG(0,("Not listening for calling name\n"));
- DEBUG(0,("Try to connect as another name (instead of %s)\n",myname));
- DEBUG(0,("You may find the -n option useful for this\n"));
- break;
- case 0x82:
- DEBUG(0,("Called name not present\n"));
- DEBUG(0,("Try to connect to another name (instead of %s)\n",desthost));
- DEBUG(0,("You may find the -I option useful for this\n"));
- break;
- case 0x83:
- DEBUG(0,("Called name present, but insufficient resources\n"));
- DEBUG(0,("Perhaps you should try again later?\n"));
- break;
- default:
- DEBUG(0,("Unspecified error 0x%X\n",ecode));
- DEBUG(0,("Your server software is being unfriendly\n"));
- break;
- }
- return(False);
- }
- return(True);
-}
-
-static struct {
- int prot;
- char *name;
-} prots[] = {
- {PROTOCOL_CORE,"PC NETWORK PROGRAM 1.0"},
- {PROTOCOL_COREPLUS,"MICROSOFT NETWORKS 1.03"},
- {PROTOCOL_LANMAN1,"MICROSOFT NETWORKS 3.0"},
- {PROTOCOL_LANMAN1,"LANMAN1.0"},
- {PROTOCOL_LANMAN2,"LM1.2X002"},
- {PROTOCOL_LANMAN2,"Samba"},
- {PROTOCOL_NT1,"NT LM 0.12"},
- {PROTOCOL_NT1,"NT LANMAN 1.0"},
- {-1,NULL}
-};
-
-
-/****************************************************************************
-send a login command.
-****************************************************************************/
-BOOL cli_send_login(char *inbuf,char *outbuf,BOOL start_session,BOOL use_setup)
-{
- BOOL was_null = (!inbuf && !outbuf);
- int sesskey=0;
- time_t servertime = 0;
- extern int serverzone;
- int sec_mode=0;
- int crypt_len;
- int max_vcs=0;
- char *pass = NULL;
- pstring dev;
- char *p;
- int numprots;
- int tries=0;
-
- if (was_null)
- {
- inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN);
- outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN);
- }
-
-#if AJT
- if (strstr(service,"IPC$")) connect_as_ipc = True;
-#endif
-
- strcpy(dev,"A:");
- if (connect_as_printer)
- strcpy(dev,"LPT1:");
- if (connect_as_ipc)
- strcpy(dev,"IPC");
-
-
- if (start_session && !cli_send_session_request(inbuf,outbuf))
- {
- if (was_null)
- {
- free(inbuf);
- free(outbuf);
- }
- return(False);
- }
-
- bzero(outbuf,smb_size);
-
- /* setup the protocol strings */
- {
- int plength;
-
- for (plength=0,numprots=0;
- prots[numprots].name && prots[numprots].prot<=max_protocol;
- numprots++)
- plength += strlen(prots[numprots].name)+2;
-
- set_message(outbuf,0,plength,True);
-
- p = smb_buf(outbuf);
- for (numprots=0;
- prots[numprots].name && prots[numprots].prot<=max_protocol;
- numprots++)
- {
- *p++ = 2;
- strcpy(p,prots[numprots].name);
- p += strlen(p) + 1;
- }
- }
-
- CVAL(outbuf,smb_com) = SMBnegprot;
- cli_setup_pkt(outbuf);
-
- CVAL(smb_buf(outbuf),0) = 2;
-
- send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
-
- show_msg(inbuf);
-
- if (CVAL(inbuf,smb_rcls) != 0 || ((int)SVAL(inbuf,smb_vwv0) >= numprots))
- {
- DEBUG(0,("SMBnegprot failed. myname=%s destname=%s - %s \n",
- myname,desthost,smb_errstr(inbuf)));
- if (was_null)
- {
- free(inbuf);
- free(outbuf);
- }
- return(False);
- }
-
- Protocol = prots[SVAL(inbuf,smb_vwv0)].prot;
-
-
- if (Protocol < PROTOCOL_NT1) {
- sec_mode = SVAL(inbuf,smb_vwv1);
- max_xmit = SVAL(inbuf,smb_vwv2);
- sesskey = IVAL(inbuf,smb_vwv6);
- serverzone = SVALS(inbuf,smb_vwv10)*60;
- /* this time is converted to GMT by make_unix_date */
- servertime = make_unix_date(inbuf+smb_vwv8);
- if (Protocol >= PROTOCOL_COREPLUS) {
- readbraw_supported = ((SVAL(inbuf,smb_vwv5) & 0x1) != 0);
- writebraw_supported = ((SVAL(inbuf,smb_vwv5) & 0x2) != 0);
- }
- crypt_len = smb_buflen(inbuf);
- memcpy(cryptkey,smb_buf(inbuf),8);
- DEBUG(3,("max mux %d\n",SVAL(inbuf,smb_vwv3)));
- max_vcs = SVAL(inbuf,smb_vwv4);
- DEBUG(3,("max vcs %d\n",max_vcs));
- DEBUG(3,("max blk %d\n",SVAL(inbuf,smb_vwv5)));
- } else {
- /* NT protocol */
- sec_mode = CVAL(inbuf,smb_vwv1);
- max_xmit = IVAL(inbuf,smb_vwv3+1);
- sesskey = IVAL(inbuf,smb_vwv7+1);
- serverzone = SVALS(inbuf,smb_vwv15+1)*60;
- /* this time arrives in real GMT */
- servertime = interpret_long_date(inbuf+smb_vwv11+1);
- crypt_len = CVAL(inbuf,smb_vwv16+1);
- memcpy(cryptkey,smb_buf(inbuf),8);
- if (IVAL(inbuf,smb_vwv9+1) & 1)
- readbraw_supported = writebraw_supported = True;
- DEBUG(3,("max mux %d\n",SVAL(inbuf,smb_vwv1+1)));
- max_vcs = SVAL(inbuf,smb_vwv2+1);
- DEBUG(3,("max vcs %d\n",max_vcs));
- DEBUG(3,("max raw %d\n",IVAL(inbuf,smb_vwv5+1)));
- DEBUG(3,("capabilities 0x%x\n",IVAL(inbuf,smb_vwv9+1)));
- }
-
- DEBUG(3,("Sec mode %d\n",SVAL(inbuf,smb_vwv1)));
- DEBUG(3,("max xmt %d\n",max_xmit));
- DEBUG(3,("Got %d byte crypt key\n",crypt_len));
- DEBUG(3,("Chose protocol [%s]\n",prots[SVAL(inbuf,smb_vwv0)].name));
-
- doencrypt = ((sec_mode & 2) != 0);
-
- if (servertime) {
- static BOOL done_time = False;
- if (!done_time) {
- DEBUG(1,("Server time is %sTimezone is UTC%+02.1f\n",
- asctime(LocalTime(&servertime)),
- -(double)(serverzone/3600.0)));
- done_time = True;
- }
- }
-
- get_pass:
-
- if (got_pass)
- pass = password;
- else
- pass = (char *)getpass("Password: ");
-
- /* use a blank username for the 2nd try with a blank password */
- if (tries++ && !*pass)
- *username = 0;
-
- if (Protocol >= PROTOCOL_LANMAN1 && use_setup)
- {
- fstring pword;
- char ntpword[24];
- int passlen = strlen(pass)+1;
- int ntpasslen = 0;
- strcpy(pword,pass);
-
- if (doencrypt && *pass)
- {
- DEBUG(3,("Using encrypted passwords\n"));
- passlen = 24;
- SMBencrypt ((uchar *)pass,(uchar *)cryptkey,(uchar *)pword);
-
- ntpasslen = 24;
- SMBNTencrypt((uchar *)pass,(uchar *)cryptkey,(uchar *)ntpword);
- }
-
- /* if in share level security then don't send a password now */
- if (!(sec_mode & 1)) {strcpy(pword, "");passlen=1;}
-
- /* send a session setup command */
- bzero(outbuf,smb_size);
-
- if (Protocol < PROTOCOL_NT1) {
- set_message(outbuf,10,1 + strlen(username) + passlen,True);
- CVAL(outbuf,smb_com) = SMBsesssetupX;
- cli_setup_pkt(outbuf);
-
- CVAL(outbuf,smb_vwv0) = 0xFF;
- SSVAL(outbuf,smb_vwv2,max_xmit);
- SSVAL(outbuf,smb_vwv3,2);
- SSVAL(outbuf,smb_vwv4,max_vcs-1);
- SIVAL(outbuf,smb_vwv5,sesskey);
- SSVAL(outbuf,smb_vwv7,passlen);
- p = smb_buf(outbuf);
- memcpy(p,pword,passlen);
- p += passlen;
- strcpy(p,username);
- } else {
- if (!doencrypt) passlen--;
- /* for Win95 */
- set_message(outbuf,13,0,True);
- CVAL(outbuf,smb_com) = SMBsesssetupX;
- cli_setup_pkt(outbuf);
-
- CVAL(outbuf,smb_vwv0) = 0xFF;
- SSVAL(outbuf,smb_vwv2,BUFFER_SIZE);
- SSVAL(outbuf,smb_vwv3,2);
- SSVAL(outbuf,smb_vwv4,getpid());
- SIVAL(outbuf,smb_vwv5,sesskey);
- SSVAL(outbuf,smb_vwv7,passlen);
- SSVAL(outbuf,smb_vwv8,ntpasslen);
-
- p = smb_buf(outbuf);
-
- memcpy(p,pword ,passlen); p += passlen;
- if (ntpasslen == 24)
- {
- memcpy(p,ntpword,passlen); p += passlen;
- }
- strcpy(p,username);p = skip_string(p,1);
- strcpy(p,workgroup);p = skip_string(p,1);
- strcpy(p,"Unix");p = skip_string(p,1);
- strcpy(p,"Samba");p = skip_string(p,1);
- set_message(outbuf,13,PTR_DIFF(p,smb_buf(outbuf)),False);
- }
-
- send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
-
- show_msg(inbuf);
-
- if (CVAL(inbuf,smb_rcls) != 0)
- {
- if (! *pass &&
- ((CVAL(inbuf,smb_rcls) == ERRDOS &&
- SVAL(inbuf,smb_err) == ERRnoaccess) ||
- (CVAL(inbuf,smb_rcls) == ERRSRV &&
- SVAL(inbuf,smb_err) == ERRbadpw)))
- {
- got_pass = False;
- DEBUG(3,("resending login\n"));
- goto get_pass;
- }
-
- DEBUG(0,("Session setup failed for username=%s myname=%s destname=%s %s\n",
- username,myname,desthost,smb_errstr(inbuf)));
- DEBUG(0,("You might find the -U, -W or -n options useful\n"));
- DEBUG(0,("Sometimes you have to use `-n USERNAME' (particularly with OS/2)\n"));
- DEBUG(0,("Some servers also insist on uppercase-only passwords\n"));
- if (was_null)
- {
- free(inbuf);
- free(outbuf);
- }
- return(False);
- }
-
- if (Protocol >= PROTOCOL_NT1) {
- char *domain,*os,*lanman;
- p = smb_buf(inbuf);
- os = p;
- lanman = skip_string(os,1);
- domain = skip_string(lanman,1);
- if (*domain || *os || *lanman)
- DEBUG(1,("Domain=[%s] OS=[%s] Server=[%s]\n",domain,os,lanman));
- }
-
- /* use the returned uid from now on */
- if (SVAL(inbuf,smb_uid) != uid)
- DEBUG(3,("Server gave us a UID of %d. We gave %d\n",
- SVAL(inbuf,smb_uid),uid));
- uid = SVAL(inbuf,smb_uid);
- }
-
- if (sec_mode & 1) {
- if (SVAL(inbuf, smb_vwv2) & 1)
- DEBUG(1,("connected as guest "));
- DEBUG(1,("security=user\n"));
- } else {
- DEBUG(1,("security=share\n"));
- }
-
- /* now we've got a connection - send a tcon message */
- bzero(outbuf,smb_size);
-
- if (strncmp(service,"\\\\",2) != 0)
- {
- DEBUG(0,("\nWarning: Your service name doesn't start with \\\\. This is probably incorrect.\n"));
- DEBUG(0,("Perhaps try replacing each \\ with \\\\ on the command line?\n\n"));
- }
-
-
- again2:
-
- {
- int passlen = strlen(pass)+1;
- fstring pword;
- strcpy(pword,pass);
-
- if (doencrypt && *pass) {
- passlen=24;
- SMBencrypt((uchar *)pass,(uchar *)cryptkey,(uchar *)pword);
- }
-
- /* if in user level security then don't send a password now */
- if ((sec_mode & 1)) {
- strcpy(pword, ""); passlen=1;
- }
-
- if (Protocol <= PROTOCOL_COREPLUS) {
- set_message(outbuf,0,6 + strlen(service) + passlen + strlen(dev),True);
- CVAL(outbuf,smb_com) = SMBtcon;
- cli_setup_pkt(outbuf);
-
- p = smb_buf(outbuf);
- *p++ = 0x04;
- strcpy(p, service);
- p = skip_string(p,1);
- *p++ = 0x04;
- memcpy(p,pword,passlen);
- p += passlen;
- *p++ = 0x04;
- strcpy(p, dev);
- }
- else {
- set_message(outbuf,4,2 + strlen(service) + passlen + strlen(dev),True);
- CVAL(outbuf,smb_com) = SMBtconX;
- cli_setup_pkt(outbuf);
-
- SSVAL(outbuf,smb_vwv0,0xFF);
- SSVAL(outbuf,smb_vwv3,passlen);
-
- p = smb_buf(outbuf);
- memcpy(p,pword,passlen);
- p += passlen;
- strcpy(p,service);
- p = skip_string(p,1);
- strcpy(p,dev);
- }
- }
-
- send_smb(Client,outbuf);
- receive_smb(Client,inbuf,CLIENT_TIMEOUT);
-
- /* trying again with a blank password */
- if (CVAL(inbuf,smb_rcls) != 0 &&
- (int)strlen(pass) > 0 &&
- !doencrypt &&
- Protocol >= PROTOCOL_LANMAN1)
- {
- DEBUG(2,("first SMBtconX failed, trying again. %s\n",smb_errstr(inbuf)));
- strcpy(pass,"");
- goto again2;
- }
-
- if (CVAL(inbuf,smb_rcls) != 0)
- {
- DEBUG(0,("SMBtconX failed. %s\n",smb_errstr(inbuf)));
- DEBUG(0,("Perhaps you are using the wrong sharename, username or password?\n"));
- DEBUG(0,("Some servers insist that these be in uppercase\n"));
- if (was_null)
- {
- free(inbuf);
- free(outbuf);
- }
- return(False);
- }
-
-
- if (Protocol <= PROTOCOL_COREPLUS) {
- max_xmit = SVAL(inbuf,smb_vwv0);
-
- cnum = SVAL(inbuf,smb_vwv1);
- }
- else {
- max_xmit = MIN(max_xmit,BUFFER_SIZE-4);
- if (max_xmit <= 0)
- max_xmit = BUFFER_SIZE - 4;
-
- cnum = SVAL(inbuf,smb_tid);
- }
-
- DEBUG(3,("Connected with cnum=%d max_xmit=%d\n",cnum,max_xmit));
-
- if (was_null)
- {
- free(inbuf);
- free(outbuf);
- }
-
- return True;
-}
-
-
-/****************************************************************************
-send a logout command
-****************************************************************************/
-void cli_send_logout(void )
-{
- pstring inbuf,outbuf;
-
- DEBUG(5,("cli_send_logout\n"));
-
- bzero(outbuf,smb_size);
- set_message(outbuf,0,0,True);
- CVAL(outbuf,smb_com) = SMBtdis;
- SSVAL(outbuf,smb_tid,cnum);
- cli_setup_pkt(outbuf);
-
- send_smb(Client,outbuf);
- receive_smb(Client,inbuf,SHORT_TIMEOUT);
-
- if (CVAL(inbuf,smb_rcls) != 0)
- {
- DEBUG(0,("SMBtdis failed %s\n",smb_errstr(inbuf)));
- }
-
-
-#ifdef STATS
- stats_report();
-#endif
- exit(0);
-}
-
-
-/****************************************************************************
-open the client sockets
-****************************************************************************/
-BOOL cli_open_sockets(int port )
-{
- static int last_port;
- char *host;
- pstring service2;
- extern int Client;
- BOOL failed = True;
-
- if (port == 0) port=last_port;
- last_port=port;
-
- strupper(service);
-
- if (*desthost)
- {
- host = desthost;
- }
- else
- {
- strcpy(service2,service);
- host = strtok(service2,"\\/");
- if (!host) {
- DEBUG(0,("Badly formed host name\n"));
- return(False);
- }
- strcpy(desthost,host);
- }
-
- if (!(*myname)) {
- get_myname(myname,NULL);
- }
- strupper(myname);
-
- DEBUG(3,("Opening sockets\n"));
-
- if (!have_ip)
- {
- struct hostent *hp;
-
- if ((hp = Get_Hostbyname(host)))
- {
- putip((char *)&dest_ip,(char *)hp->h_addr);
- failed = False;
- }
- else
- {
-#ifdef USENMB
- /* Try and resolve the name with the netbios server */
- int bcast;
-
- if ((bcast = open_socket_in(SOCK_DGRAM, 0, 3,
- interpret_addr(lp_socket_address()))) != -1) {
- set_socket_options(bcast, "SO_BROADCAST");
-
- if (name_query(bcast, host, name_type, True, True, *iface_bcast(dest_ip),
- &dest_ip,0)) {
- failed = False;
- }
- close (bcast);
- }
-#endif
- if (failed) {
- DEBUG(0,("Get_Hostbyname: Unknown host %s.\n",host));
- return False;
- }
- }
- }
-
- Client = open_socket_out(SOCK_STREAM, &dest_ip, port, LONG_CONNECT_TIMEOUT);
- if (Client == -1)
- return False;
-
- DEBUG(3,("Connected\n"));
-
- set_socket_options(Client,user_socket_options);
-
- return True;
-}
-
-/****************************************************************************
-close and open the connection again
-****************************************************************************/
-BOOL cli_reopen_connection(char *inbuf,char *outbuf)
-{
- static int open_count=0;
-
- open_count++;
-
- if (open_count>5) return(False);
-
- DEBUG(1,("Trying to re-open connection\n"));
-
- set_message(outbuf,0,0,True);
- SCVAL(outbuf,smb_com,SMBtdis);
- SSVAL(outbuf,smb_tid,cnum);
- cli_setup_pkt(outbuf);
-
- send_smb(Client,outbuf);
- receive_smb(Client,inbuf,SHORT_TIMEOUT);
-
- close_sockets();
- if (!cli_open_sockets(0)) return(False);
-
- return(cli_send_login(inbuf,outbuf,True,True));
-}
-
extern file_info def_finfo;
+extern struct cli_state smb_cli;
+extern int smb_tidx;
+
/****************************************************************************
Convert from UNIX to DOS file names
/****************************************************************************
Read a tar header into a hblock structure, and validate
***************************************************************************/
-static long read_tar_hdr(struct cli_state *cli, int t_idx, struct client_info *info,
+static long read_tar_hdr(struct cli_state *cli, int smb_tidx, struct client_info *info,
union hblock *hb, file_info *finfo, char *prefix)
{
long chk, fchk;
static void do_atar(struct cli_state *cli, int t_idx, struct client_info *info,
char *rname,char *lname,file_info *finfo1)
{
- uint32 nread = cli_get(cli, t_idx, info, rname, lname, finfo1, info->tar.handle,
+ cli_get(cli, t_idx, info,
+ rname, lname, finfo1, info->tar.handle,
tar_write_check, do_tar_buf, tar_pad_check);
/* reset the archive bit */
* samba interactive commands
*/
-/****************************************************************************
-Blocksize command
-***************************************************************************/
-void cmd_block(struct cli_state *cli, int t_idx, struct client_info *info)
-{
- fstring buf;
- int block;
-
- if (!next_token(NULL,buf,NULL))
- {
- DEBUG(0, ("blocksize <n>\n"));
- return;
- }
-
- block=atoi(buf);
- if (block < 0 || block > 65535)
- {
- DEBUG(0, ("blocksize out of range"));
- return;
- }
-
- info->tar.blocksize=block;
- DEBUG(1,("blocksize is now %d\n", info->tar.blocksize));
-}
-
-/****************************************************************************
-command to set incremental / reset mode
-***************************************************************************/
-void cmd_tarmode(struct cli_state *cli, int t_idx, struct client_info *info)
-{
- fstring buf;
-
- while (next_token(NULL,buf,NULL)) {
- if (strequal(buf, "full"))
- info->tar.inc=False;
- else if (strequal(buf, "inc"))
- info->tar.inc=True;
- else if (strequal(buf, "reset"))
- info->tar.reset=True;
- else if (strequal(buf, "noreset"))
- info->tar.reset=False;
- else DEBUG(0, ("tarmode: unrecognised option %s\n", buf));
- }
-
- DEBUG(0, ("tarmode is now %s, %s\n",
- info->tar.inc ? "incremental" : "full",
- info->tar.reset ? "reset" : "noreset"));
-}
-
/****************************************************************************
Feeble attrib command
***************************************************************************/
-void cmd_setmode(struct cli_state *cli, int t_idx, struct client_info *info)
+void cmd_setmode(struct client_info *info)
{
char *q;
fstring buf;
}
DEBUG(1, ("\nperm set %d %d\n", attra[ATTRSET], attra[ATTRRESET]));
- do_setrattr(cli, t_idx, info, fname, attra[ATTRSET], ATTRSET);
- do_setrattr(cli, t_idx, info, fname, attra[ATTRRESET], ATTRRESET);
+ do_setrattr(&smb_cli, smb_tidx, info, fname, attra[ATTRSET], ATTRSET);
+ do_setrattr(&smb_cli, smb_tidx, info, fname, attra[ATTRRESET], ATTRRESET);
}
/****************************************************************************
Principal command for creating / extracting
***************************************************************************/
-void cmd_tar(struct cli_state *cli, int t_idx, struct client_info *info)
+void cmd_tar(struct client_info *info)
{
fstring buf;
char **argl;
return;
}
- process_tar(cli, t_idx, info);
+ process_tar(info);
free(argl);
}
/****************************************************************************
Command line (option) version
***************************************************************************/
-int process_tar(struct cli_state *cli, int t_idx, struct client_info *info)
+int process_tar(struct client_info *info)
{
- init_tar_buf(info);
- switch(info->tar.type) {
- case 'x':
- do_tarput(cli, t_idx, info);
- free(info->tar.buf);
- close(info->tar.handle);
- break;
- case 'r':
- case 'c':
- if (info->tar.clipn && info->tar.excl) {
- int i;
- pstring tarmac;
-
- for (i=0; i<info->tar.clipn; i++) {
- DEBUG(0,("arg %d = %s\n", i, info->tar.cliplist[i]));
-
- if (*(info->tar.cliplist[i]+strlen(info->tar.cliplist[i])-1)=='\\') {
- *(info->tar.cliplist[i]+strlen(info->tar.cliplist[i])-1)='\0';
- }
-
- if (strrchr(info->tar.cliplist[i], '\\')) {
- pstring saved_dir;
-
- strcpy(saved_dir, info->cur_dir);
-
- if (*info->tar.cliplist[i]=='\\') {
- strcpy(tarmac, info->tar.cliplist[i]);
- } else {
- strcpy(tarmac, info->cur_dir);
- strcat(tarmac, info->tar.cliplist[i]);
- }
- strcpy(info->cur_dir, tarmac);
- *(strrchr(info->cur_dir, '\\')+1)='\0';
+ init_tar_buf(info);
- cli_dir(cli, t_idx, info, tarmac, info->tar.attrib, info->recurse_dir, do_tar);
- strcpy(info->cur_dir,saved_dir);
- } else {
- strcpy(tarmac, info->cur_dir);
- strcat(tarmac, info->tar.cliplist[i]);
- cli_dir(cli, t_idx, info, tarmac, info->tar.attrib, info->recurse_dir, do_tar);
+ switch(info->tar.type)
+ {
+ case 'x':
+ {
+ do_tarput(&smb_cli, smb_tidx, info);
+ free(info->tar.buf);
+ close(info->tar.handle);
+ break;
+ }
+
+ case 'r':
+ case 'c':
+ {
+ if (info->tar.clipn && info->tar.excl)
+ {
+ int i;
+ pstring tarmac;
+
+ for (i = 0; i < info->tar.clipn; i++)
+ {
+ DEBUG(0,("arg %d = %s\n", i, info->tar.cliplist[i]));
+
+ if (*(info->tar.cliplist[i]+strlen(info->tar.cliplist[i])-1)=='\\')
+ {
+ *(info->tar.cliplist[i]+strlen(info->tar.cliplist[i])-1)='\0';
+ }
+
+ if (strrchr(info->tar.cliplist[i], '\\'))
+ {
+ pstring saved_dir;
+
+ strcpy(saved_dir, info->cur_dir);
+
+ if (*info->tar.cliplist[i]=='\\')
+ {
+ strcpy(tarmac, info->tar.cliplist[i]);
+ }
+ else
+ {
+ strcpy(tarmac, info->cur_dir);
+ strcat(tarmac, info->tar.cliplist[i]);
+ }
+
+ strcpy(info->cur_dir, tarmac);
+ *(strrchr(info->cur_dir, '\\')+1)='\0';
+
+ cli_dir(&smb_cli, smb_tidx, info, tarmac, info->tar.attrib, info->recurse_dir, do_tar);
+ strcpy(info->cur_dir,saved_dir);
+ }
+ else
+ {
+ strcpy(tarmac, info->cur_dir);
+ strcat(tarmac, info->tar.cliplist[i]);
+ cli_dir(&smb_cli, smb_tidx, info, tarmac, info->tar.attrib, info->recurse_dir, do_tar);
+ }
+ }
+ }
+ else
+ {
+ pstring mask;
+ strcpy(mask,info->cur_dir);
+ strcat(mask,"\\*");
+ cli_dir(&smb_cli, smb_tidx, info, mask, info->tar.attrib, info->recurse_dir, do_tar);
+ }
+
+ if (info->tar.num_files)
+ {
+ do_tar_eof(info, info->tar.handle);
+ }
+
+ close(info->tar.handle);
+ free(info->tar.buf);
+
+ DEBUG(0, ("tar: dumped %d tar files\n", info->tar.num_files));
+ DEBUG(0, ("Total bytes written: %d\n", info->tar.bytes_written));
+ break;
+ }
}
- }
- } else {
- pstring mask;
- strcpy(mask,info->cur_dir);
- strcat(mask,"\\*");
- cli_dir(cli, t_idx, info, mask, info->tar.attrib, info->recurse_dir, do_tar);
- }
-
- if (info->tar.num_files) do_tar_eof(info, info->tar.handle);
- close(info->tar.handle);
- free(info->tar.buf);
-
- DEBUG(0, ("tar: dumped %d tar files\n", info->tar.num_files));
- DEBUG(0, ("Total bytes written: %d\n", info->tar.bytes_written));
- break;
- }
- return(0);
+ return(0);
}
/****************************************************************************
int tar_parseargs(struct client_info *info,
int argc, char *argv[], char *Optarg, int Optind)
{
- char tar_clipfl='\0';
+ char smb_clipfl='\0';
/* Reset back to defaults - could be from interactive version
* reset mode and archive mode left as they are though
info->tar.reset=True;
break;
case 'I':
- if (tar_clipfl) {
+ if (smb_clipfl) {
DEBUG(0,("Only one of I,X must be specified\n"));
return 0;
}
- tar_clipfl='I';
+ smb_clipfl='I';
break;
case 'X':
- if (tar_clipfl) {
+ if (smb_clipfl) {
DEBUG(0,("Only one of I,X must be specified\n"));
return 0;
}
- tar_clipfl='X';
+ smb_clipfl='X';
break;
default:
DEBUG(0,("Unknown tar option\n"));
return 0;
}
- info->tar.excl=tar_clipfl!='X';
+ info->tar.excl=smb_clipfl!='X';
if (Optind+1<argc) {
info->tar.cliplist=argv+Optind+1;
info->tar.clipn=argc-Optind-1;
#ifdef NTDOMAIN
+static struct cli_state nt_cli;
+static int nt_tidx;
+
+extern struct cli_state ipc_cli;
+static int ipc_tidx;
+
+
/****************************************************************************
-experimental nt login.
+nt lsa query
+
+use the anon IPC$ for this one
****************************************************************************/
-void cmd_lsa_query_info(struct cli_state *cli, struct client_info *info)
+void cmd_lsa_query_info(struct client_info *info)
{
fstring srv_name;
DEBUG(4,("cmd_lsa_query_info: server:%s\n", srv_name));
/* open LSARPC session. */
- res = res ? do_lsa_session_open(cli, info) : False;
+ res = res ? do_lsa_session_open(&ipc_cli, ipc_tidx, info) : False;
/* lookup domain controller; receive a policy handle */
- res = res ? do_lsa_open_policy(cli, info->dom.lsarpc_fnum,
+ res = res ? do_lsa_open_policy(&ipc_cli, ipc_tidx, info->dom.lsarpc_fnum,
srv_name,
&info->dom.lsa_info_pol) : False;
/* send client info query, level 3. receive domain name and sid */
- res = res ? do_lsa_query_info_pol(cli, info->dom.lsarpc_fnum,
+ res = res ? do_lsa_query_info_pol(&ipc_cli, ipc_tidx, info->dom.lsarpc_fnum,
&info->dom.lsa_info_pol, 0x03,
info->dom.level3_dom,
info->dom.level3_sid) : False;
/* send client info query, level 5. receive domain name and sid */
- res = res ? do_lsa_query_info_pol(cli, info->dom.lsarpc_fnum,
+ res = res ? do_lsa_query_info_pol(&ipc_cli, ipc_tidx, info->dom.lsarpc_fnum,
&info->dom.lsa_info_pol, 0x05,
info->dom.level5_dom,
info->dom.level5_sid) : False;
- res = res ? do_lsa_close(cli, info->dom.lsarpc_fnum,
+ res = res ? do_lsa_close(&ipc_cli, ipc_tidx, info->dom.lsarpc_fnum,
&info->dom.lsa_info_pol) : False;
/* close the session */
- do_lsa_session_close(cli, info);
+ do_lsa_session_close(&ipc_cli, ipc_tidx, info);
if (res)
{
/****************************************************************************
experimental SAM user query.
+
+use the nt IPC$ connection for this one.
****************************************************************************/
-void cmd_sam_query_users(struct cli_state *cli, struct client_info *info)
+void cmd_sam_query_users(struct client_info *info)
{
fstring srv_name;
fstring sid;
DEBUG(0,("Account Information for %s, SID: %s\n", srv_name, sid));
/* open SAMR session. negotiate credentials */
- res = res ? do_samr_session_open(cli, info) : False;
+ res = res ? do_samr_session_open(&nt_cli, nt_tidx, info) : False;
/* lookup domain controller; receive a policy handle */
- res = res ? do_samr_open_policy(cli, info->dom.samr_fnum,
+ res = res ? do_samr_open_policy(&nt_cli, nt_tidx, info->dom.samr_fnum,
srv_name, 0x00000020,
&info->dom.samr_pol_open) : False;
- res = res ? do_samr_enum_sam_db(cli, info->dom.samr_fnum,
+ res = res ? do_samr_enum_sam_db(&nt_cli, nt_tidx, info->dom.samr_fnum,
&info->dom.samr_pol_open, 0xffff,
info->dom.sam, &info->dom.num_sam_entries) : False;
info->dom.sam[user_idx].acct_name));
/* send client open secret; receive a client policy handle */
- res = res ? do_samr_open_secret(cli, info->dom.samr_fnum,
+ res = res ? do_samr_open_secret(&nt_cli, nt_tidx, info->dom.samr_fnum,
&info->dom.samr_pol_open,
info->dom.sam[user_idx].smb_userid, sid,
&(info->dom.sam[user_idx].acct_pol)) : False;
}
/* close the session */
- do_samr_session_close(cli, info);
+ do_samr_session_close(&nt_cli, nt_tidx, info);
if (res)
{
/****************************************************************************
experimental nt login.
+
+use the anon IPC$ for this one
****************************************************************************/
-void cmd_nt_login_test(struct cli_state *cli, struct client_info *info)
+void cmd_nt_login_test(struct client_info *info)
{
fstring username;
info->mach_acct, new_mach_pwd) : False;
#endif
/* open NETLOGON session. negotiate credentials */
- res = res ? do_nt_session_open(cli, &info->dom.lsarpc_fnum,
+ res = res ? do_nt_session_open(&ipc_cli, ipc_tidx, &info->dom.lsarpc_fnum,
info->dest_host, info->myhostname,
info->mach_acct,
username, info->workgroup,
/* change the machine password? */
if (new_mach_pwd != NULL && new_mach_pwd[0] != 0)
{
- res = res ? do_nt_srv_pwset(cli, info->dom.lsarpc_fnum,
+ res = res ? do_nt_srv_pwset(&ipc_cli, ipc_tidx, info->dom.lsarpc_fnum,
info->dom.sess_key, &info->dom.clnt_cred, &info->dom.rtn_cred,
new_mach_pwd,
info->dest_host, info->mach_acct, info->myhostname) : False;
getuid(), username);
/* do an NT login */
- res = res ? do_nt_login(cli, info->dom.lsarpc_fnum,
+ res = res ? do_nt_login(&ipc_cli, ipc_tidx, info->dom.lsarpc_fnum,
info->dom.sess_key, &info->dom.clnt_cred, &info->dom.rtn_cred,
&info->dom.id1, info->dest_host, info->myhostname, &info->dom.user_info1) : False;
/* ok! you're logged in! do anything you like, then... */
/* do an NT logout */
- res = res ? do_nt_logoff(cli, info->dom.lsarpc_fnum,
+ res = res ? do_nt_logoff(&ipc_cli, ipc_tidx, info->dom.lsarpc_fnum,
info->dom.sess_key, &info->dom.clnt_cred, &info->dom.rtn_cred,
&info->dom.id1, info->dest_host, info->myhostname) : False;
/* close the session */
- do_nt_session_close(cli, info->dom.lsarpc_fnum);
+ do_nt_session_close(&ipc_cli, ipc_tidx, info->dom.lsarpc_fnum);
if (res)
{
- DEBUG(5,("cmd_nt_login_test: login test succeeded\n"));
+ DEBUG(5,("cmd_nt_login: login test succeeded\n"));
}
else
{
- DEBUG(5,("cmd_nt_login_test: login test failed\n"));
+ DEBUG(5,("cmd_nt_login: login test failed\n"));
}
}
/****************************************************************************
experimental net login test.
+
+use the nt IPC$ connection for this one.
****************************************************************************/
-void cmd_nltest(struct cli_state *cli, struct client_info *info)
+void cmd_nltest(struct client_info *info)
{
BOOL res = True;
fstring username;
DEBUG(5,("do_nltest: %d\n", __LINE__));
/* open NETLOGON session. negotiate credentials */
- res = res ? do_nt_session_open(cli, &info->dom.lsarpc_fnum,
+ res = res ? do_nt_session_open(&nt_cli, nt_tidx, &info->dom.lsarpc_fnum,
info->dest_host, info->myhostname,
info->mach_acct,
username, info->workgroup,
&info->dom.clnt_cred) : False;
/* close the session */
- do_nt_session_close(cli, info->dom.lsarpc_fnum);
+ do_nt_session_close(&nt_cli, nt_tidx, info->dom.lsarpc_fnum);
if (res)
{
- DEBUG(5,("cmd_nt_login_test: nltest succeeded\n"));
+ DEBUG(5,("cmd_nltest: nltest succeeded\n"));
}
else
{
- DEBUG(5,("cmd_nt_login_test: nltest failed\n"));
+ DEBUG(5,("cmd_nltest: nltest failed\n"));
}
}
+/****************************************************************************
+initialise nt client structure
+****************************************************************************/
+void client_nt_init(void)
+{
+ bzero(&nt_cli, sizeof(nt_cli));
+}
+
+/****************************************************************************
+make nt client connection
+****************************************************************************/
+void client_nt_connect(struct client_info *info,
+ char *username, char *password, char *workgroup)
+{
+ BOOL anonymous = !username || username[0] == 0;
+ BOOL got_pass = password && password[0] == 0;
+
+ if (!cli_establish_connection(&nt_cli, &nt_tidx,
+ info->dest_host, 0x20, &info->dest_ip,
+ info->myhostname,
+ (got_pass || anonymous) ? NULL : "Enter Password:",
+ username, !anonymous ? password : NULL, workgroup,
+ "IPC$", "IPC",
+ False, True, !anonymous))
+ {
+ DEBUG(0,("client_nt_connect: connection failed\n"));
+ cli_shutdown(&nt_cli);
+ }
+}
+
+/****************************************************************************
+stop the nt connection(s?)
+****************************************************************************/
+void client_nt_stop(void)
+{
+ cli_shutdown(&nt_cli);
+}
+
#endif /* NTDOMAIN */
--- /dev/null
+/*
+ Unix SMB/Netbios implementation.
+ Version 1.9.
+ SMB client
+ Copyright (C) Andrew Tridgell 1994-1997
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifdef SYSLOG
+#undef SYSLOG
+#endif
+
+#include "includes.h"
+
+#ifndef REGISTER
+#define REGISTER 0
+#endif
+
+extern pstring debugf;
+extern int DEBUGLEVEL;
+
+
+#define CNV_LANG(s) dos2unix_format(s,False)
+#define CNV_INPUT(s) unix2dos_format(s,True)
+
+/****************************************************************************
+ smb client interactive commands
+ ****************************************************************************/
+
+
+
+/****************************************************************************
+ set the file selection mask
+ ****************************************************************************/
+void cmd_select(struct client_info*info)
+{
+ strcpy(info->file_sel,"");
+ next_token(NULL,info->file_sel,NULL);
+}
+
+
+/****************************************************************************
+toggle the prompt flag
+****************************************************************************/
+void cmd_prompt(struct client_info*info)
+{
+ info->prompt = !info->prompt;
+ DEBUG(2,("prompting is now %s\n", BOOLSTR(info->prompt)));
+}
+
+
+/****************************************************************************
+set the newer than time
+****************************************************************************/
+void cmd_newer(struct client_info*info)
+{
+ fstring buf;
+ BOOL ok;
+ struct stat sbuf;
+
+ ok = next_token(NULL,buf,NULL);
+ if (ok && (sys_stat(buf,&sbuf) == 0))
+ {
+ info->newer_than = sbuf.st_mtime;
+ DEBUG(1,("Getting files newer than %s",
+ asctime(LocalTime(&info->newer_than))));
+ }
+ else
+ info->newer_than = 0;
+
+ if (ok && info->newer_than == 0)
+ DEBUG(0,("Error setting newer-than time\n"));
+}
+
+/****************************************************************************
+set the archive level
+****************************************************************************/
+void cmd_archive(struct client_info*info)
+{
+ fstring buf;
+
+ if (next_token(NULL,buf,NULL)) {
+ info->archive_level = atoi(buf);
+ } else
+ DEBUG(0,("Archive level is %d\n",info->archive_level));
+}
+
+/****************************************************************************
+toggle the info->lowercaseflag
+****************************************************************************/
+void cmd_lowercase(struct client_info*info)
+{
+ info->lowercase = !info->lowercase;
+ DEBUG(2,("filename lowercasing is now %s\n",info->lowercase?"on":"off"));
+}
+
+
+
+
+/****************************************************************************
+toggle the info->recurse flag
+****************************************************************************/
+void cmd_recurse(struct client_info*info)
+{
+ info->recurse_dir = !info->recurse_dir;
+ DEBUG(2,("directory recursion is now %s\n", BOOLSTR(info->recurse_dir)));
+}
+
+/****************************************************************************
+toggle the translate flag
+****************************************************************************/
+void cmd_translate(struct client_info*info)
+{
+ info->translation = !info->translation;
+ DEBUG(2,("CR/LF<->LF and print text info->translation now %s\n",
+ info->translation?"on":"off"));
+}
+
+
+/****************************************************************************
+do a print_mode command
+****************************************************************************/
+void cmd_printmode(struct client_info*info)
+{
+ fstring buf;
+ fstring mode;
+
+ if (next_token(NULL,buf,NULL))
+ {
+ if (strequal(buf,"text"))
+ info->print_mode = 0;
+ else
+ {
+ if (strequal(buf,"graphics"))
+ info->print_mode = 1;
+ else
+ info->print_mode = atoi(buf);
+ }
+ }
+
+ switch(info->print_mode)
+ {
+ case 0:
+ strcpy(mode,"text");
+ break;
+ case 1:
+ strcpy(mode,"graphics");
+ break;
+ default:
+ sprintf(mode,"%d", info->print_mode);
+ break;
+ }
+
+ DEBUG(2,("the print_mode is now %s\n",mode));
+}
+
+/****************************************************************************
+do the lcd command
+****************************************************************************/
+void cmd_lcd(struct client_info *info)
+{
+ fstring buf;
+ pstring d;
+
+ if (next_token(NULL,buf,NULL))
+ sys_chdir(buf);
+ DEBUG(2,("the local directory is now %s\n", GetWd(d)));
+}
+
+
+
+/****************************************************************************
+ smb tar interactive commands
+ ****************************************************************************/
+
+
+/****************************************************************************
+Blocksize command
+***************************************************************************/
+void cmd_block(struct client_info *info)
+{
+ fstring buf;
+ int block;
+
+ if (!next_token(NULL,buf,NULL))
+ {
+ DEBUG(0, ("blocksize <n>\n"));
+ return;
+ }
+
+ block=atoi(buf);
+ if (block < 0 || block > 65535)
+ {
+ DEBUG(0, ("blocksize out of range"));
+ return;
+ }
+
+ info->tar.blocksize=block;
+ DEBUG(1,("blocksize is now %d\n", info->tar.blocksize));
+}
+
+/****************************************************************************
+command to set incremental / reset mode
+***************************************************************************/
+void cmd_tarmode(struct client_info *info)
+{
+ fstring buf;
+
+ while (next_token(NULL,buf,NULL)) {
+ if (strequal(buf, "full"))
+ info->tar.inc=False;
+ else if (strequal(buf, "inc"))
+ info->tar.inc=True;
+ else if (strequal(buf, "reset"))
+ info->tar.reset=True;
+ else if (strequal(buf, "noreset"))
+ info->tar.reset=False;
+ else DEBUG(0, ("tarmode: unrecognised option %s\n", buf));
+ }
+
+ DEBUG(0, ("tarmode is now %s, %s\n",
+ info->tar.inc ? "incremental" : "full",
+ info->tar.reset ? "reset" : "noreset"));
+}
+
--- /dev/null
+/*
+ Unix SMB/Netbios implementation.
+ Version 1.9.
+ SMB client
+ Copyright (C) Andrew Tridgell 1994-1997
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifdef SYSLOG
+#undef SYSLOG
+#endif
+
+#include "includes.h"
+
+extern pstring debugf;
+extern int DEBUGLEVEL;
+
+
+struct cli_state ipc_cli;
+int ipc_tidx = -1;
+
+
+
+/****************************************************************************
+ print browse connection on a host
+ ****************************************************************************/
+static void print_server(char *sname, uint32 type, char *comment)
+{
+ fstring typestr;
+ *typestr=0;
+
+ if (type == SV_TYPE_ALL)
+ {
+ strcpy(typestr, "All");
+ }
+ else
+ {
+ int i;
+ typestr[0] = 0;
+ for (i = 0; i < 32; i++)
+ {
+ if (IS_BITS_SET_ALL(type, 1 << i))
+ {
+ switch (1 << i)
+ {
+ case SV_TYPE_WORKSTATION : strcat(typestr, "Wk " ); break;
+ case SV_TYPE_SERVER : strcat(typestr, "Sv " ); break;
+ case SV_TYPE_SQLSERVER : strcat(typestr, "Sql "); break;
+ case SV_TYPE_DOMAIN_CTRL : strcat(typestr, "PDC "); break;
+ case SV_TYPE_DOMAIN_BAKCTRL : strcat(typestr, "BDC "); break;
+ case SV_TYPE_TIME_SOURCE : strcat(typestr, "Tim "); break;
+ case SV_TYPE_AFP : strcat(typestr, "AFP "); break;
+ case SV_TYPE_NOVELL : strcat(typestr, "Nov "); break;
+ case SV_TYPE_DOMAIN_MEMBER : strcat(typestr, "Dom "); break;
+ case SV_TYPE_PRINTQ_SERVER : strcat(typestr, "PrQ "); break;
+ case SV_TYPE_DIALIN_SERVER : strcat(typestr, "Din "); break;
+ case SV_TYPE_SERVER_UNIX : strcat(typestr, "Unx "); break;
+ case SV_TYPE_NT : strcat(typestr, "NT " ); break;
+ case SV_TYPE_WFW : strcat(typestr, "Wfw "); break;
+ case SV_TYPE_SERVER_MFPN : strcat(typestr, "Mfp "); break;
+ case SV_TYPE_SERVER_NT : strcat(typestr, "SNT "); break;
+ case SV_TYPE_POTENTIAL_BROWSER: strcat(typestr, "PtB "); break;
+ case SV_TYPE_BACKUP_BROWSER : strcat(typestr, "BMB "); break;
+ case SV_TYPE_MASTER_BROWSER : strcat(typestr, "LMB "); break;
+ case SV_TYPE_DOMAIN_MASTER : strcat(typestr, "DMB "); break;
+ case SV_TYPE_SERVER_OSF : strcat(typestr, "OSF "); break;
+ case SV_TYPE_SERVER_VMS : strcat(typestr, "VMS "); break;
+ case SV_TYPE_WIN95_PLUS : strcat(typestr, "W95 "); break;
+ case SV_TYPE_ALTERNATE_XPORT : strcat(typestr, "Xpt "); break;
+ case SV_TYPE_LOCAL_LIST_ONLY : strcat(typestr, "Dom "); break;
+ case SV_TYPE_DOMAIN_ENUM : strcat(typestr, "Loc "); break;
+ }
+ }
+ }
+ i = strlen(typestr)-1;
+ if (typestr[i] == ' ') typestr[i] = 0;
+
+ }
+
+ printf("\t%-15.15s%-20s %s\n", sname, typestr, comment);
+}
+
+
+/****************************************************************************
+print browse connection on a host
+****************************************************************************/
+static void print_share(char *sname, uint32 type, char *comment)
+{
+ fstring typestr;
+ *typestr=0;
+
+ switch (type)
+ {
+ case STYPE_DISKTREE: strcpy(typestr,"Disk"); break;
+ case STYPE_PRINTQ : strcpy(typestr,"Printer"); break;
+ case STYPE_DEVICE : strcpy(typestr,"Device"); break;
+ case STYPE_IPC : strcpy(typestr,"IPC"); break;
+ default : strcpy(typestr,"????"); break;
+ }
+
+ printf("\t%-15.15s%-10.10s%s\n", sname, typestr, comment);
+}
+
+
+/****************************************************************************
+try and browse available connections on a host
+****************************************************************************/
+void client_browse_host(struct cli_state *cli, int t_idx, char *workgroup, BOOL sort)
+{
+ int count = 0;
+ BOOL long_share_name = False;
+
+ printf("\n\tSharename Type Comment\n");
+ printf( "\t--------- ---- -------\n");
+
+ count = cli_NetShareEnum(cli, t_idx, sort, &long_share_name, print_share);
+
+ if (count == 0)
+ {
+ printf("\tNo shares available on this host\n");
+ }
+
+ if (long_share_name)
+ {
+ printf("\nNOTE: There were share names longer than 8 chars.\nOn older clients these may not be accessible or may give browsing errors\n");
+ }
+
+ printf("\n");
+ printf("\tWorkgroup Type Master\n");
+ printf("\t--------- ---- ------\n");
+
+ cli_NetServerEnum(cli, t_idx, workgroup, SV_TYPE_DOMAIN_ENUM, print_server);
+
+ printf("\n");
+ printf("\tServer Type Comment\n");
+ printf("\t------ ---- -------\n");
+
+ cli_NetServerEnum(cli, t_idx, workgroup, SV_TYPE_ALL, print_server);
+}
+
+
+/****************************************************************************
+show shares
+****************************************************************************/
+void cmd_list_shares(struct client_info *info)
+{
+ int count = 0;
+ BOOL long_share_name = False;
+
+ printf("\n\tSharename Type Comment\n");
+ printf( "\t--------- ---- -------\n");
+
+ count = cli_NetShareEnum(&ipc_cli, ipc_tidx, True, &long_share_name, print_share);
+
+ if (count == 0)
+ {
+ printf("\tNo shares available on this host\n");
+ }
+
+ if (long_share_name)
+ {
+ printf("\nNOTE: There were share names longer than 8 chars.\nOn older clients these may not be accessible or may give browsing errors\n");
+ }
+}
+
+
+/****************************************************************************
+show browse workgroup
+****************************************************************************/
+void cmd_list_wgps(struct client_info *info)
+{
+ fstring workgroup;
+ fstring type;
+ uint32 svc_type = 0;
+
+ if (!next_token(NULL, workgroup,NULL))
+ {
+ fstrcpy(workgroup, info->workgroup);
+ }
+
+ if (next_token(NULL, type,NULL))
+ {
+ svc_type = strtoul(type, (char**)NULL, 16);
+ }
+ else
+ {
+ svc_type = SV_TYPE_ALL;
+ }
+
+ printf("\n");
+ printf("\tServer Type Comment\n");
+ printf("\t------ ---- -------\n");
+
+ cli_NetServerEnum(&ipc_cli, ipc_tidx, workgroup, svc_type, print_server);
+}
+
+
+/****************************************************************************
+show browse servers
+****************************************************************************/
+void cmd_list_servers(struct client_info *info)
+{
+ fstring workgroup;
+ fstring type;
+ uint32 svc_type = 0;
+
+ if (!next_token(NULL, workgroup,NULL))
+ {
+ fstrcpy(workgroup, info->workgroup);
+ }
+
+ if (next_token(NULL, type,NULL))
+ {
+ svc_type = strtoul(type, (char**)NULL, 16);
+ }
+ else
+ {
+ svc_type = SV_TYPE_DOMAIN_ENUM;
+ }
+
+ printf("\n");
+ printf("\tWorkgroup Type Master\n");
+ printf("\t--------- ---- ------\n");
+
+ cli_NetServerEnum(&ipc_cli, ipc_tidx, workgroup, svc_type, print_server);
+}
+
+
+/****************************************************************************
+initialise anon ipc client structure
+****************************************************************************/
+void client_ipc_init(void)
+{
+ bzero(&ipc_cli, sizeof(ipc_cli));
+}
+
+/****************************************************************************
+make anon ipc client connection
+****************************************************************************/
+void client_ipc_connect(struct client_info *info,
+ char *username, char *password, char *workgroup)
+{
+ BOOL anonymous = !username || username[0] == 0;
+ BOOL got_pass = password && password[0] != 0;
+
+ if (!cli_establish_connection(&ipc_cli, &ipc_tidx,
+ info->dest_host, 0x20, &info->dest_ip,
+ info->myhostname,
+ (got_pass || anonymous) ? NULL : "Enter Password:",
+ username, !anonymous ? password : NULL, workgroup,
+ info->share, info->svc_type,
+ False, True, !anonymous))
+ {
+ DEBUG(0,("client_ipc_init: connection failed\n"));
+ cli_shutdown(&ipc_cli);
+ }
+}
+
+/****************************************************************************
+stop the ipc client connection
+****************************************************************************/
+void client_ipc_stop(void)
+{
+ cli_shutdown(&ipc_cli);
+}
--- /dev/null
+/*
+ Unix SMB/Netbios implementation.
+ Version 1.9.
+ SMB client
+ Copyright (C) Andrew Tridgell 1994-1997
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifdef SYSLOG
+#undef SYSLOG
+#endif
+
+#include "includes.h"
+
+
+extern pstring debugf;
+extern int DEBUGLEVEL;
+
+
+extern struct cli_state smb_cli;
+extern int smb_tidx;
+
+/****************************************************************************
+ cancel a print job
+ ****************************************************************************/
+void cmd_cancel(struct client_info*info)
+{
+ fstring buf;
+ int job;
+
+ if (!strequal(smb_cli.con[smb_tidx].dev,"LPT1:"))
+ {
+ DEBUG(0,("WARNING: You didn't use the -P option to smbclient.\n"));
+ DEBUG(0,("Trying to cancel print jobs without -P may fail\n"));
+ }
+
+ if (!next_token(NULL,buf,NULL))
+ {
+ printf("cancel <jobid> ...\n");
+ return;
+ }
+
+ do
+ {
+ uint16 cancelled_job;
+ job = atoi(buf);
+ if (cli_cancel(&smb_cli, smb_tidx, (uint16)job, &cancelled_job))
+ {
+ DEBUG(0, ("Job %d cancelled\n", cancelled_job));
+ }
+ else
+ {
+ DEBUG(0, ("Server refused cancel request\n"));
+ }
+
+ } while (next_token(NULL,buf,NULL));
+}
+
+
+/****************************************************************************
+ print a file
+ ****************************************************************************/
+void cmd_print(struct client_info*info)
+{
+ FILE *f = NULL;
+ pstring lname;
+ pstring rname;
+ char *p;
+
+ if (!strequal(smb_cli.con[smb_tidx].dev,"LPT1:"))
+ {
+ DEBUG(0,("WARNING: You didn't use the -P option to smbclient.\n"));
+ DEBUG(0,("Trying to print without -P may fail\n"));
+ }
+
+ if (!next_token(NULL,lname,NULL))
+ {
+ DEBUG(0,("print <filename>\n"));
+ return;
+ }
+
+ strcpy(rname,lname);
+ p = strrchr(rname,'/');
+ if (p)
+ {
+ pstring tname;
+ strcpy(tname,p+1);
+ strcpy(rname,tname);
+ }
+
+ if ((int)strlen(rname) > 14)
+ rname[14] = 0;
+
+ if (strequal(lname,"-"))
+ {
+ f = stdin;
+ strcpy(rname,"stdin");
+ }
+
+ dos_clean_name(rname);
+
+ cli_print(&smb_cli, smb_tidx, info, f, lname, rname);
+}
+
+
+/****************************************************************************
+ display print_q info
+ ****************************************************************************/
+static void print_q(uint16 job, char *name, uint32 size, uint8 status)
+{
+ fstring status_str;
+
+ switch (status)
+ {
+ case 0x01: sprintf(status_str,"held or stopped"); break;
+ case 0x02: sprintf(status_str,"printing"); break;
+ case 0x03: sprintf(status_str,"awaiting print"); break;
+ case 0x04: sprintf(status_str,"in intercept"); break;
+ case 0x05: sprintf(status_str,"file had error"); break;
+ case 0x06: sprintf(status_str,"printer error"); break;
+ default: sprintf(status_str,"unknown"); break;
+ }
+
+ DEBUG(0,("%-6d %-16.16s %-9d %s\n", job, name, size, status_str));
+}
+
+
+/****************************************************************************
+show a print queue - this is deprecated as it uses the old smb that
+has limited support - the correct call is the cmd_p_queue_2() after this.
+****************************************************************************/
+void cmd_queue(struct client_info*info)
+{
+ int count;
+
+ if (!strequal(smb_cli.con[smb_tidx].dev,"LPT1:"))
+ {
+ DEBUG(0,("WARNING: You didn't use the -P option to smbclient.\n"));
+ DEBUG(0,("Trying to print without -P may fail\n"));
+ }
+
+ DEBUG(0,("Job Name Size Status\n"));
+
+ count = cli_queue(&smb_cli, smb_tidx, info, print_q);
+
+ if (count <= 0)
+ {
+ DEBUG(0,("No entries in the print queue\n"));
+ return;
+ }
+}
+
+/****************************************************************************
+display print_queue_2 info
+****************************************************************************/
+static void print_q2( char *PrinterName, uint16 JobId, uint16 Priority,
+ char *UserName, time_t JobTime, uint32 Size, char *JobName)
+{
+ char *JobTimeStr;
+
+
+ JobTimeStr = asctime(LocalTime( &JobTime));
+
+ printf("%s-%u %s priority %u %s %s %u bytes\n",
+ PrinterName, JobId, UserName,
+ Priority, JobTimeStr, JobName, Size);
+}
+
+/****************************************************************************
+show information about a print queue
+****************************************************************************/
+void cmd_p_queue_2(struct client_info*info)
+{
+ if (!strequal(smb_cli.con[smb_tidx].dev,"LPT1:"))
+ {
+ DEBUG(0,("WARNING: You didn't use the -P option to smbclient.\n"));
+ DEBUG(0,("Trying to print without -P may fail\n"));
+ }
+ cli_pqueue_2(&smb_cli, smb_tidx, info, print_q2);
+}
+
+/****************************************************************************
+show information about a print queue
+****************************************************************************/
+void cmd_qinfo(struct client_info*info)
+{
+ fstring params, comment, printers, driver_name;
+ fstring name, separator_file, print_processor;
+ uint16 priority, start_time, until_time, status, jobs;
+ int driver_count;
+ char *driver_data;
+
+ if (!cli_printq_info(&smb_cli, smb_tidx, info,
+ name, &priority,
+ &start_time, &until_time,
+ separator_file, print_processor,
+ params, comment,
+ &status, &jobs,
+ printers, driver_name,
+ &driver_data, &driver_count))
+ {
+ return;
+ }
+
+ DEBUG(0, ("Name: \"%s\"\n", name));
+ DEBUG(0, ("Priority: %u\n", priority));
+ DEBUG(0, ("Start time: %u\n", start_time));
+ DEBUG(0, ("Until time: %u\n", until_time));
+ DEBUG(0, ("Separator file: \"%s\"\n", separator_file));
+ DEBUG(0, ("Print processor: \"%s\"\n", print_processor));
+ DEBUG(0, ("Parameters: \"%s\"\n", params));
+ DEBUG(0, ("Comment: \"%s\"\n", comment));
+ DEBUG(0, ("Status: %u\n", status));
+ DEBUG(0, ("Jobs: %u\n", jobs));
+ DEBUG(0, ("Printers: \"%s\"\n", printers));
+ DEBUG(0, ("Drivername: \"%s\"\n", driver_name));
+
+ DEBUG(0, ("Driverdata: size=%d, version=%u\n",
+ driver_count, IVAL(driver_data,4) ));
+
+ dump_data(0, driver_data, driver_count);
+}
#include "includes.h"
-#ifndef REGISTER
-#define REGISTER 0
-#endif
-
-pstring cd_path = "";
-extern pstring myname;
-extern pstring scope;
-
-extern pstring user_socket_options;
-
extern pstring debugf;
extern int DEBUGLEVEL;
-
-#define SEPARATORS " \t\n\r"
-
extern file_info def_finfo;
-#define USENMB
+static pstring cd_path="";
+
+struct cli_state smb_cli;
+int smb_tidx = -1;
#define CNV_LANG(s) dos2unix_format(s,False)
#define CNV_INPUT(s) unix2dos_format(s,True)
/***************************************************************************
- write a file
- ****************************************************************************/
+ checks that the smb connection is still open
+ ****************************************************************************/
+void client_check_connection(void)
+{
+#ifdef CLIX
+ static int delay = 0;
+ delay++;
+ if (delay > 100000)
+ {
+ delay = 0;
+ cli_chkpath(&smb_cli, smb_tidx, "\\");
+ }
+#else
+ cli_chkpath(&smb_cli, smb_tidx, "\\");
+#endif
+}
+
+/***************************************************************************
+ write a file
+ ****************************************************************************/
static int write_trans_file(struct client_info *info,
int f, char *b, int n)
{
}
/***************************************************************************
- read a file
- ****************************************************************************/
+ read a file
+ ****************************************************************************/
static int read_trans_file(struct client_info *info,
char *b, int size, int n, FILE *f)
{
/****************************************************************************
-send a message
-****************************************************************************/
+ send a message
+ ****************************************************************************/
void client_send_message(struct cli_state *cli, int t_idx,
char *username, char *dest_host)
{
-/****************************************************************************
-print browse connection on a host
-****************************************************************************/
-static void print_server(char *sname, uint32 type, char *comment)
-{
- fstring typestr;
- *typestr=0;
-
- if (type == SV_TYPE_ALL)
- {
- strcpy(typestr, "All");
- }
- else
- {
- int i;
- typestr[0] = 0;
- for (i = 0; i < 32; i++)
- {
- if (IS_BITS_SET(type, 1 << i))
- {
- switch (1 << i)
- {
- case SV_TYPE_WORKSTATION : strcat(typestr, "Wk " ); break;
- case SV_TYPE_SERVER : strcat(typestr, "Sv " ); break;
- case SV_TYPE_SQLSERVER : strcat(typestr, "Sql "); break;
- case SV_TYPE_DOMAIN_CTRL : strcat(typestr, "PDC "); break;
- case SV_TYPE_DOMAIN_BAKCTRL : strcat(typestr, "BDC "); break;
- case SV_TYPE_TIME_SOURCE : strcat(typestr, "Tim "); break;
- case SV_TYPE_AFP : strcat(typestr, "AFP "); break;
- case SV_TYPE_NOVELL : strcat(typestr, "Nov "); break;
- case SV_TYPE_DOMAIN_MEMBER : strcat(typestr, "Dom "); break;
- case SV_TYPE_PRINTQ_SERVER : strcat(typestr, "PrQ "); break;
- case SV_TYPE_DIALIN_SERVER : strcat(typestr, "Din "); break;
- case SV_TYPE_SERVER_UNIX : strcat(typestr, "Unx "); break;
- case SV_TYPE_NT : strcat(typestr, "NT " ); break;
- case SV_TYPE_WFW : strcat(typestr, "Wfw "); break;
- case SV_TYPE_SERVER_MFPN : strcat(typestr, "Mfp "); break;
- case SV_TYPE_SERVER_NT : strcat(typestr, "SNT "); break;
- case SV_TYPE_POTENTIAL_BROWSER: strcat(typestr, "PtB "); break;
- case SV_TYPE_BACKUP_BROWSER : strcat(typestr, "BMB "); break;
- case SV_TYPE_MASTER_BROWSER : strcat(typestr, "LMB "); break;
- case SV_TYPE_DOMAIN_MASTER : strcat(typestr, "DMB "); break;
- case SV_TYPE_SERVER_OSF : strcat(typestr, "OSF "); break;
- case SV_TYPE_SERVER_VMS : strcat(typestr, "VMS "); break;
- case SV_TYPE_WIN95_PLUS : strcat(typestr, "W95 "); break;
- case SV_TYPE_ALTERNATE_XPORT : strcat(typestr, "Xpt "); break;
- case SV_TYPE_LOCAL_LIST_ONLY : strcat(typestr, "Dom "); break;
- case SV_TYPE_DOMAIN_ENUM : strcat(typestr, "Loc "); break;
- }
- }
- }
- i = strlen(typestr)-1;
- if (typestr[i] == ' ') typestr[i] = 0;
-
- }
-
- printf("\t%-15.15s%-20s %s\n", sname, typestr, comment);
-}
-
-
-/****************************************************************************
-print browse connection on a host
-****************************************************************************/
-static void print_share(char *sname, uint32 type, char *comment)
-{
- fstring typestr;
- *typestr=0;
-
- switch (type)
- {
- case STYPE_DISKTREE: strcpy(typestr,"Disk"); break;
- case STYPE_PRINTQ : strcpy(typestr,"Printer"); break;
- case STYPE_DEVICE : strcpy(typestr,"Device"); break;
- case STYPE_IPC : strcpy(typestr,"IPC"); break;
- default : strcpy(typestr,"????"); break;
- }
-
- printf("\t%-15.15s%-10.10s%s\n", sname, typestr, comment);
-}
-
-
-/****************************************************************************
-try and browse available connections on a host
-****************************************************************************/
-void client_browse_host(struct cli_state *cli, int t_idx, char *workgroup, BOOL sort)
-{
- int count = 0;
- BOOL long_share_name = False;
-
- printf("\n\tSharename Type Comment\n");
- printf( "\t--------- ---- -------\n");
-
- count = cli_NetShareEnum(cli, t_idx, sort, &long_share_name, print_share);
-
- if (count == 0)
- {
- printf("\tNo shares available on this host\n");
- }
-
- if (long_share_name)
- {
- printf("\nNOTE: There were share names longer than 8 chars.\nOn older clients these may not be accessible or may give browsing errors\n");
- }
-
- printf("\n");
- printf("\tWorkgroup Type Master\n");
- printf("\t--------- ---- ------\n");
-
- cli_NetServerEnum(cli, t_idx, workgroup, SV_TYPE_DOMAIN_ENUM, print_server);
-
- printf("\n");
- printf("\tServer Type Comment\n");
- printf("\t------ ---- -------\n");
-
- cli_NetServerEnum(cli, t_idx, workgroup, SV_TYPE_ALL, print_server);
-}
-
/****************************************************************************
send message
****************************************************************************/
-void cmd_send_message(struct cli_state *cli, int t_idx, struct client_info*info)
+void cmd_send_message(struct client_info *info)
{
fstring username;
DEBUG(0,("message <username/workgroup>\n"));
}
- client_send_message(cli, t_idx, username, info->dest_host);
-}
-
-
-/****************************************************************************
-show shares
-****************************************************************************/
-void cmd_list_shares(struct cli_state *cli, int t_idx, struct client_info*info)
-{
- int count = 0;
- BOOL long_share_name = False;
-
- printf("\n\tSharename Type Comment\n");
- printf( "\t--------- ---- -------\n");
-
- count = cli_NetShareEnum(cli, t_idx, True, &long_share_name, print_share);
-
- if (count == 0)
- {
- printf("\tNo shares available on this host\n");
- }
-
- if (long_share_name)
- {
- printf("\nNOTE: There were share names longer than 8 chars.\nOn older clients these may not be accessible or may give browsing errors\n");
- }
-}
-
-
-/****************************************************************************
-show browse workgroup
-****************************************************************************/
-void cmd_list_wgps(struct cli_state *cli, int t_idx, struct client_info*info)
-{
- fstring workgroup;
- fstring type;
- uint32 svc_type = 0;
-
- if (!next_token(NULL, workgroup,NULL))
- {
- fstrcpy(workgroup, info->workgroup);
- }
-
- if (next_token(NULL, type,NULL))
- {
- svc_type = strtoul(type, (char**)NULL, 16);
- }
- else
- {
- svc_type = SV_TYPE_ALL;
- }
-
- printf("\n");
- printf("\tServer Type Comment\n");
- printf("\t------ ---- -------\n");
-
- cli_NetServerEnum(cli, t_idx, workgroup, svc_type, print_server);
-}
-
-
-/****************************************************************************
-show browse servers
-****************************************************************************/
-void cmd_list_servers(struct cli_state *cli, int t_idx, struct client_info*info)
-{
- fstring workgroup;
- fstring type;
- uint32 svc_type = 0;
-
- if (!next_token(NULL, workgroup,NULL))
- {
- fstrcpy(workgroup, info->workgroup);
- }
-
- if (next_token(NULL, type,NULL))
- {
- svc_type = strtoul(type, (char**)NULL, 16);
- }
- else
- {
- svc_type = SV_TYPE_DOMAIN_ENUM;
- }
-
- printf("\n");
- printf("\tWorkgroup Type Master\n");
- printf("\t--------- ---- ------\n");
-
- cli_NetServerEnum(cli, t_idx, workgroup, svc_type, print_server);
+ client_send_message(&smb_cli, smb_tidx, username, info->dest_host);
}
}
-/****************************************************************************
-show cd/pwd
-****************************************************************************/
-void cmd_pwd(struct cli_state *cli, int t_idx, struct client_info*info)
-{
- DEBUG(0,("Current directory for connection %d is %s",
- CNV_LANG(cli->con[t_idx].full_share)));
- DEBUG(0,("%s\n", CNV_LANG(info->cur_dir)));
-}
-
-
/****************************************************************************
change directory - inner section
****************************************************************************/
/****************************************************************************
change directory
****************************************************************************/
-void cmd_cd(struct cli_state *cli, int t_idx, struct client_info*info)
+void cmd_cd(struct client_info*info)
{
fstring buf;
if (next_token(NULL,buf,NULL))
- do_cd(cli, t_idx, info, buf);
+ do_cd(&smb_cli, smb_tidx, info, buf);
else
DEBUG(0,("Current directory is %s\n", CNV_LANG(info->cur_dir)));
}
/****************************************************************************
get a directory listing
****************************************************************************/
-void cmd_dir(struct cli_state *cli, int t_idx, struct client_info*info)
+void cmd_dir(struct client_info*info)
{
int attribute = aDIR | aSYSTEM | aHIDDEN;
pstring mask;
strcat(mask,"*");
}
- cli_do_dir(cli, t_idx, info, mask, attribute, info->recurse_dir, NULL);
+ cli_do_dir(&smb_cli, smb_tidx, info, mask, attribute, info->recurse_dir, NULL);
- do_dskattr(cli, t_idx);
+ do_dskattr(&smb_cli, smb_tidx);
DEBUG(3, ("Total bytes listed: %d\n", info->dir_total));
}
/****************************************************************************
get a file
****************************************************************************/
-void cmd_get(struct cli_state *cli, int t_idx, struct client_info*info)
+void cmd_get(struct client_info*info)
{
pstring lname;
pstring rname;
return;
}
- cli_get(cli, t_idx, info, rname,lname, NULL, handle,
+ cli_get(&smb_cli, smb_tidx, info, rname,lname, NULL, handle,
NULL, write_trans_file, NULL);
if(newhandle)
/****************************************************************************
view the file using the pager
****************************************************************************/
-void cmd_more(struct cli_state *cli, int t_idx, struct client_info*info)
+void cmd_more(struct client_info*info)
{
fstring rname,lname,tmpname,pager_cmd;
char *pager;
return;
}
- cli_get(cli, t_idx, info, rname,lname, NULL, handle,
+ cli_get(&smb_cli, smb_tidx, info, rname,lname, NULL, handle,
NULL, write_trans_file, NULL);
pager=getenv("PAGER");
/****************************************************************************
do a mget command
****************************************************************************/
-void cmd_mget(struct cli_state *cli, int t_idx, struct client_info*info)
+void cmd_mget(struct client_info*info)
{
int attribute = aSYSTEM | aHIDDEN;
pstring mget_mask;
strcpy(mget_mask,p);
else
strcat(mget_mask,p);
- cli_do_dir(cli, t_idx, info, mget_mask, attribute, False, do_mget);
+ cli_do_dir(&smb_cli, smb_tidx, info, mget_mask, attribute, False, do_mget);
}
if (! *mget_mask)
if(mget_mask[strlen(mget_mask)-1]!='\\')
strcat(mget_mask,"\\");
strcat(mget_mask,"*");
- cli_do_dir(cli, t_idx, info, mget_mask, attribute, False, do_mget);
+ cli_do_dir(&smb_cli, smb_tidx, info, mget_mask, attribute, False, do_mget);
}
}
/****************************************************************************
make a directory
****************************************************************************/
-void cmd_mkdir(struct cli_state *cli, int t_idx, struct client_info*info)
+void cmd_mkdir(struct client_info*info)
{
pstring mask;
fstring buf;
while (p)
{
strcat(ddir2,p);
- if (!cli_chkpath(cli, t_idx, ddir2))
+ if (!cli_chkpath(&smb_cli, smb_tidx, ddir2))
{
- cli_mkdir(cli, t_idx, ddir2);
+ cli_mkdir(&smb_cli, smb_tidx, ddir2);
}
strcat(ddir2,"\\");
p = strtok(NULL,"/\\");
}
}
else
- cli_mkdir(cli, t_idx, mask);
+ cli_mkdir(&smb_cli, smb_tidx, mask);
}
/****************************************************************************
put a file
****************************************************************************/
-void cmd_put(struct cli_state *cli, int t_idx, struct client_info*info)
+void cmd_put(struct client_info*info)
{
pstring lname;
pstring rname;
GetTimeOfDay(&tp_start);
- nread = cli_put(cli, t_idx, info, rname, lname, &finfo, read_trans_file);
+ nread = cli_put(&smb_cli, smb_tidx, info, rname, lname, &finfo, read_trans_file);
if (info->archive_level >= 2 && (finfo.mode & aARCH))
{
- if (!cli_setatr(cli, t_idx, rname, finfo.mode & ~(aARCH), 0)) return;
+ if (!cli_setatr(&smb_cli, smb_tidx, rname, finfo.mode & ~(aARCH), 0)) return;
}
{
}
-/****************************************************************************
- set the file selection mask
- ****************************************************************************/
-void cmd_select(struct cli_state *cli, int t_idx, struct client_info*info)
-{
- strcpy(info->file_sel,"");
- next_token(NULL,info->file_sel,NULL);
-}
-
-
/****************************************************************************
mput some files
****************************************************************************/
-void cmd_mput(struct cli_state *cli, int t_idx, struct client_info*info)
+void cmd_mput(struct client_info*info)
{
pstring lname;
pstring rname;
strcpy(rname,info->cur_dir);
strcat(rname,lname);
- if (!cli_chkpath(cli, t_idx, rname) && !cli_mkdir(cli, t_idx, rname)) {
+ if (!cli_chkpath(&smb_cli, smb_tidx, rname) && !cli_mkdir(&smb_cli, smb_tidx, rname)) {
strcat(lname,"/");
if (!seek_list(f,lname))
break;
/* set the date on the file */
finfo.mtime = st.st_mtime;
- cli_put(cli, t_idx, info, rname,lname,&finfo, read_trans_file);
+ cli_put(&smb_cli, smb_tidx, info, rname,lname,&finfo, read_trans_file);
}
fclose(f);
unlink(tmpname);
}
}
-/****************************************************************************
- cancel a print job
- ****************************************************************************/
-void cmd_cancel(struct cli_state *cli, int t_idx, struct client_info*info)
-{
- fstring buf;
- int job;
-
- if (!strequal(cli->con[t_idx].dev,"LPT1:"))
- {
- DEBUG(0,("WARNING: You didn't use the -P option to smbclient.\n"));
- DEBUG(0,("Trying to cancel print jobs without -P may fail\n"));
- }
-
- if (!next_token(NULL,buf,NULL))
- {
- printf("cancel <jobid> ...\n");
- return;
- }
-
- do
- {
- uint16 cancelled_job;
- job = atoi(buf);
- if (cli_cancel(cli, t_idx, (uint16)job, &cancelled_job))
- {
- DEBUG(0, ("Job %d cancelled\n", cancelled_job));
- }
- else
- {
- DEBUG(0, ("Server refused cancel request\n"));
- }
-
- } while (next_token(NULL,buf,NULL));
-}
-
-
/****************************************************************************
get info on a file
****************************************************************************/
-void cmd_stat(struct cli_state *cli, int t_idx, struct client_info*info)
+void cmd_stat(struct client_info*info)
{
fstring buf;
fstring fname;
strcpy(fname, info->cur_dir);
strcat(fname, buf);
- cli_stat(cli, t_idx, fname);
-}
-
-
-/****************************************************************************
- print a file
- ****************************************************************************/
-void cmd_print(struct cli_state *cli, int t_idx, struct client_info*info)
-{
- FILE *f = NULL;
- pstring lname;
- pstring rname;
- char *p;
-
- if (!strequal(cli->con[t_idx].dev,"LPT1:"))
- {
- DEBUG(0,("WARNING: You didn't use the -P option to smbclient.\n"));
- DEBUG(0,("Trying to print without -P may fail\n"));
- }
-
- if (!next_token(NULL,lname,NULL))
- {
- DEBUG(0,("print <filename>\n"));
- return;
- }
-
- strcpy(rname,lname);
- p = strrchr(rname,'/');
- if (p)
- {
- pstring tname;
- strcpy(tname,p+1);
- strcpy(rname,tname);
- }
-
- if ((int)strlen(rname) > 14)
- rname[14] = 0;
-
- if (strequal(lname,"-"))
- {
- f = stdin;
- strcpy(rname,"stdin");
- }
-
- dos_clean_name(rname);
-
- cli_print(cli, t_idx, info, f, lname, rname);
-}
-
-/****************************************************************************
-display print_q info
-****************************************************************************/
-static void print_q(uint16 job, char *name, uint32 size, uint8 status)
-{
- fstring status_str;
-
- switch (status)
- {
- case 0x01: sprintf(status_str,"held or stopped"); break;
- case 0x02: sprintf(status_str,"printing"); break;
- case 0x03: sprintf(status_str,"awaiting print"); break;
- case 0x04: sprintf(status_str,"in intercept"); break;
- case 0x05: sprintf(status_str,"file had error"); break;
- case 0x06: sprintf(status_str,"printer error"); break;
- default: sprintf(status_str,"unknown"); break;
- }
-
- DEBUG(0,("%-6d %-16.16s %-9d %s\n", job, name, size, status_str));
-}
-
-
-/****************************************************************************
-show a print queue - this is deprecated as it uses the old smb that
-has limited support - the correct call is the cmd_p_queue_2() after this.
-****************************************************************************/
-void cmd_queue(struct cli_state *cli, int t_idx, struct client_info*info)
-{
- int count;
-
- if (!strequal(cli->con[t_idx].dev,"LPT1:"))
- {
- DEBUG(0,("WARNING: You didn't use the -P option to smbclient.\n"));
- DEBUG(0,("Trying to print without -P may fail\n"));
- }
-
- DEBUG(0,("Job Name Size Status\n"));
-
- count = cli_queue(cli, t_idx, info, print_q);
-
- if (count <= 0)
- {
- DEBUG(0,("No entries in the print queue\n"));
- return;
- }
-}
-
-/****************************************************************************
-display print_queue_2 info
-****************************************************************************/
-static void print_q2( char *PrinterName, uint16 JobId, uint16 Priority,
- char *UserName, time_t JobTime, uint32 Size, char *JobName)
-{
- char *JobTimeStr;
-
-
- JobTimeStr = asctime(LocalTime( &JobTime));
-
- printf("%s-%u %s priority %u %s %s %u bytes\n",
- PrinterName, JobId, UserName,
- Priority, JobTimeStr, JobName, Size);
-}
-
-/****************************************************************************
-show information about a print queue
-****************************************************************************/
-void cmd_p_queue_2(struct cli_state *cli, int t_idx, struct client_info*info)
-{
- if (!strequal(cli->con[t_idx].dev,"LPT1:"))
- {
- DEBUG(0,("WARNING: You didn't use the -P option to smbclient.\n"));
- DEBUG(0,("Trying to print without -P may fail\n"));
- }
- cli_pqueue_2(cli, t_idx, info, print_q2);
+ cli_stat(&smb_cli, smb_tidx, fname);
}
-/****************************************************************************
-show information about a print queue
-****************************************************************************/
-void cmd_qinfo(struct cli_state *cli, int t_idx, struct client_info*info)
-{
- fstring params, comment, printers, driver_name;
- fstring name, separator_file, print_processor;
- uint16 priority, start_time, until_time, status, jobs;
- int driver_count;
- char *driver_data;
-
- if (!cli_printq_info(cli, t_idx, info,
- name, &priority,
- &start_time, &until_time,
- separator_file, print_processor,
- params, comment,
- &status, &jobs,
- printers, driver_name,
- &driver_data, &driver_count))
- {
- return;
- }
-
- DEBUG(0, ("Name: \"%s\"\n", name));
- DEBUG(0, ("Priority: %u\n", priority));
- DEBUG(0, ("Start time: %u\n", start_time));
- DEBUG(0, ("Until time: %u\n", until_time));
- DEBUG(0, ("Separator file: \"%s\"\n", separator_file));
- DEBUG(0, ("Print processor: \"%s\"\n", print_processor));
- DEBUG(0, ("Parameters: \"%s\"\n", params));
- DEBUG(0, ("Comment: \"%s\"\n", comment));
- DEBUG(0, ("Status: %u\n", status));
- DEBUG(0, ("Jobs: %u\n", jobs));
- DEBUG(0, ("Printers: \"%s\"\n", printers));
- DEBUG(0, ("Drivername: \"%s\"\n", driver_name));
-
- DEBUG(0, ("Driverdata: size=%d, version=%u\n",
- driver_count, IVAL(driver_data,4) ));
-
- dump_data(0, driver_data, driver_count);
-}
/****************************************************************************
delete some files
/****************************************************************************
delete some files
****************************************************************************/
-void cmd_del(struct cli_state *cli, int t_idx, struct client_info*info)
+void cmd_del(struct client_info*info)
{
pstring mask;
fstring buf;
}
strcat(mask,buf);
- cli_do_dir(cli, t_idx, info, mask, attribute, info->recurse_dir, do_del);
+ cli_do_dir(&smb_cli, smb_tidx, info, mask, attribute, info->recurse_dir, do_del);
}
/****************************************************************************
remove a directory
****************************************************************************/
-void cmd_rmdir(struct cli_state *cli, int t_idx, struct client_info*info)
+void cmd_rmdir(struct client_info*info)
{
pstring mask;
fstring buf;
}
strcat(mask,buf);
- if (!cli_rmdir(cli, t_idx, mask))
+ if (!cli_rmdir(&smb_cli, smb_tidx, mask))
{
- DEBUG(0,("%s removing remote directory file %s\n", cli_errstr(cli), CNV_LANG(mask)));
+ DEBUG(0,("%s removing remote directory file %s\n", cli_errstr(&smb_cli), CNV_LANG(mask)));
return;
}
}
/****************************************************************************
rename some files
****************************************************************************/
-void cmd_rename(struct cli_state *cli, int t_idx, struct client_info*info)
+void cmd_rename(struct client_info*info)
{
pstring src,dest;
fstring buf,buf2;
strcat(src,buf);
strcat(dest,buf2);
- cli_move(cli, t_idx, src, dest);
+ cli_move(&smb_cli, smb_tidx, src, dest);
}
/****************************************************************************
-toggle the prompt flag
-****************************************************************************/
-void cmd_prompt(struct cli_state *cli, int t_idx, struct client_info*info)
-{
- info->prompt = !info->prompt;
- DEBUG(2,("prompting is now %s\n", BOOLSTR(info->prompt)));
-}
-
-
-/****************************************************************************
-set the newer than time
-****************************************************************************/
-void cmd_newer(struct cli_state *cli, int t_idx, struct client_info*info)
-{
- fstring buf;
- BOOL ok;
- struct stat sbuf;
-
- ok = next_token(NULL,buf,NULL);
- if (ok && (sys_stat(buf,&sbuf) == 0))
- {
- info->newer_than = sbuf.st_mtime;
- DEBUG(1,("Getting files newer than %s",
- asctime(LocalTime(&info->newer_than))));
- }
- else
- info->newer_than = 0;
-
- if (ok && info->newer_than == 0)
- DEBUG(0,("Error setting newer-than time\n"));
-}
-
-/****************************************************************************
-set the archive level
-****************************************************************************/
-void cmd_archive(struct cli_state *cli, int t_idx, struct client_info*info)
-{
- fstring buf;
-
- if (next_token(NULL,buf,NULL)) {
- info->archive_level = atoi(buf);
- } else
- DEBUG(0,("Archive level is %d\n",info->archive_level));
-}
-
-/****************************************************************************
-toggle the info->lowercaseflag
+show cd/pwd
****************************************************************************/
-void cmd_lowercase(struct cli_state *cli, int t_idx, struct client_info*info)
+void cmd_pwd(struct client_info *info)
{
- info->lowercase = !info->lowercase;
- DEBUG(2,("filename lowercasing is now %s\n",info->lowercase?"on":"off"));
+ DEBUG(0,("Current directory for SMB connection %d is %s",
+ CNV_LANG(smb_cli.con[smb_tidx].full_share)));
+ DEBUG(0,("%s\n", CNV_LANG(info->cur_dir)));
}
-
-
/****************************************************************************
-toggle the info->recurse flag
+initialise smb client structure
****************************************************************************/
-void cmd_recurse(struct cli_state *cli, int t_idx, struct client_info*info)
+void client_smb_init(void)
{
- info->recurse_dir = !info->recurse_dir;
- DEBUG(2,("directory recursion is now %s\n", BOOLSTR(info->recurse_dir)));
+ bzero(&smb_cli, sizeof(smb_cli));
}
/****************************************************************************
-toggle the translate flag
+make smb client connection
****************************************************************************/
-void cmd_translate(struct cli_state *cli, int t_idx, struct client_info*info)
+void client_smb_connect(struct client_info *info,
+ char *username, char *password, char *workgroup)
{
- info->translation = !info->translation;
- DEBUG(2,("CR/LF<->LF and print text info->translation now %s\n",
- info->translation?"on":"off"));
-}
+ BOOL anonymous = !username || username[0] == 0;
+ BOOL got_pass = password && password[0] != 0;
-
-/****************************************************************************
-do a print_mode command
-****************************************************************************/
-void cmd_printmode(struct cli_state *cli, int t_idx, struct client_info*info)
-{
- fstring buf;
- fstring mode;
-
- if (next_token(NULL,buf,NULL))
- {
- if (strequal(buf,"text"))
- info->print_mode = 0;
- else
+ if (!cli_establish_connection(&smb_cli, &smb_tidx,
+ info->dest_host, info->name_type, &info->dest_ip,
+ info->myhostname,
+ (got_pass || anonymous) ? NULL : "Enter Password:",
+ username, !anonymous ? password : NULL, workgroup,
+ info->share, info->svc_type,
+ False, True, !anonymous))
{
- if (strequal(buf,"graphics"))
- info->print_mode = 1;
- else
- info->print_mode = atoi(buf);
+ DEBUG(0,("client_smb_init: connection failed\n"));
+ cli_shutdown(&smb_cli);
}
- }
-
- switch(info->print_mode)
- {
- case 0:
- strcpy(mode,"text");
- break;
- case 1:
- strcpy(mode,"graphics");
- break;
- default:
- sprintf(mode,"%d", info->print_mode);
- break;
- }
-
- DEBUG(2,("the print_mode is now %s\n",mode));
-}
-
-/****************************************************************************
-do the lcd command
-****************************************************************************/
-void cmd_lcd(struct cli_state *cli, int t_idx, struct client_info*info)
-{
- fstring buf;
- pstring d;
-
- if (next_token(NULL,buf,NULL))
- sys_chdir(buf);
- DEBUG(2,("the local directory is now %s\n",GetWd(d)));
}
/****************************************************************************
-do a (presumably graceful) quit...
+stop the smb connection(s?)
****************************************************************************/
-void cmd_quit(struct cli_state *cli, int t_idx, struct client_info*info)
+void client_smb_stop(void)
{
- cli_shutdown(cli);
- exit(0);
+ cli_shutdown(&smb_cli);
}
-
#define REG_INFO 0x11
#define REG_CLOSE 0x05
+/*******************************************************************
+ the following information comes from a QuickView on samsrv.dll,
+ and gives an idea of exactly what is needed:
+
+SamrAddMemberToAlias
+SamrAddMemberToGroup
+SamrAddMultipleMembersToAlias
+SamrChangePasswordUser
+SamrCloseHandle
+SamrConnect
+SamrCreateAliasInDomain
+SamrCreateGroupInDomain
+SamrCreateUserInDomain
+SamrDeleteAlias
+SamrDeleteGroup
+SamrDeleteUser
+SamrEnumerateAliasesInDomain
+SamrEnumerateDomainsInSamServer
+SamrEnumerateGroupsInDomain
+SamrEnumerateUsersInDomain
+SamrGetUserDomainPasswordInformation
+SamrLookupDomainInSamServer
+SamrLookupIdsInDomain
+SamrLookupNamesInDomain
+SamrOpenAlias
+SamrOpenDomain
+SamrOpenGroup
+SamrOpenUser
+SamrQueryDisplayInformation
+SamrQUeryInformationAlias
+SamrQueryInformationDomain
+SamrQueryInformationUser
+SamrQuerySecurityObject
+SamrRemoveMemberFromAlias
+SamrRemoveMemberFromForiegnDomain
+SamrRemoveMemberFromGroup
+SamrRemoveMultipleMembersFromAlias
+SamrSetInformationAlias
+SamrSetInformationDOmain
+SamrSetInformationGroup
+SamrSetInformationUser
+SamrSetMemberAttributesOfGroup
+SamrSetSecurityObject
+SamrShutdownSamServer
+SamrTestPrivateFunctionsDomain
+SamrTestPrivateFunctionsUser
+
+********************************************************************/
+
#define SAMR_CLOSE 0x01
#define SAMR_OPEN_SECRET 0x07
#define SAMR_LOOKUP_RIDS 0x11
#define SAMR_UNKNOWN_3 0x03
+#define SAMR_QUERY_DISPINFO 0x28
#define SAMR_ENUM_SAM_DB 0x0d
#define SAMR_UNKNOWN_22 0x22
#define SAMR_UNKNOWN_24 0x24
#define SAMR_UNKNOWN_32 0x32
#define SAMR_UNKNOWN_34 0x34
#define SAMR_OPEN_POLICY 0x39
+#define SAMR_ENUM_DOM_GRPS 0x0f
#define LSA_OPENPOLICY 0x2c
#define LSA_QUERYINFOPOLICY 0x07
} SAMR_R_OPEN_SECRET;
+#define MAX_SAM_ENTRIES 250
+
+typedef struct samr_entry_info
+{
+ uint32 rid;
+ UNIHDR hdr_acct_name;
+
+} SAM_ENTRY;
+
/* SAMR_Q_ENUM_SAM_DB - SAM rids and names */
typedef struct q_samr_sam_db_info
{
} SAMR_Q_ENUM_SAM_DB;
-#define MAX_SAM_ENTRIES 250
-
-typedef struct samr_entry_info
-{
- uint32 rid;
- UNIHDR hdr_acct_name;
-
-} SAM_ENTRY;
-
/* SAMR_R_ENUM_SAM_DB - SAM rids and names */
typedef struct q_samr_unknown_d_info
{
+/* SAMR_Q_QUERY_DISPINFO - SAM rids, names and descriptions */
+typedef struct q_samr_enum_dom_user_info
+{
+ LSA_POL_HND pol; /* policy handle */
+
+ uint16 switch_level; /* 0x0001 */
+ uint16 unknown_0; /* 0x0000 and 0x2000 seen */
+ uint32 start_idx; /* presumably the start enumeration index */
+ uint32 unknown_1; /* 0x0000 07d0, 0x0000 0400 and 0x0000 0200 seen */
+
+ uint32 max_size; /* 0x0000 7fff, 0x0000 7ffe and 0x0000 3fff seen*/
+
+} SAMR_Q_QUERY_DISPINFO;
+
+typedef struct samr_entry_info2
+{
+ uint32 user_idx;
+
+ uint32 rid_user;
+ uint16 acb_info;
+ uint16 pad;
+
+ UNIHDR hdr_acct_name;
+ UNIHDR hdr_user_name;
+ UNIHDR hdr_user_desc;
+
+} SAM_ENTRY2;
+
+typedef struct samr_str_entry_info2
+{
+ UNISTR2 uni_acct_name;
+ UNISTR2 uni_full_name;
+ UNISTR2 uni_acct_desc;
+
+} SAM_STR2;
+
+/* SAMR_R_QUERY_DISPINFO - SAM rids, names and descriptions */
+typedef struct r_samr_query_dispinfo_info
+{
+ uint32 unknown_0; /* 0x0000 0492 */
+ uint32 unknown_1; /* 0x0000 049a */
+ uint32 switch_level; /* 0x0000 0001 */
+
+ uint32 num_entries;
+ uint32 ptr_entries;
+
+ uint32 num_entries2;
+
+ SAM_ENTRY2 sam[MAX_SAM_ENTRIES];
+ SAM_STR2 str[MAX_SAM_ENTRIES];
+
+ uint32 status;
+
+} SAMR_R_QUERY_DISPINFO;
+
+
+
/****************************************************************************
SAMR_Q_LOOKUP_RIDS - do a conversion (only one!) from name to RID.
/* This file is automatically generated with "make proto". DO NOT EDIT */
+/*The following definitions come from /usr/local/src/arcfour/arcfour.c */
+
+void arcfour(unsigned char data[16], unsigned char data_out[16], unsigned char data_in[16]);
+
/*The following definitions come from access.c */
BOOL check_access(int snum);
/*The following definitions come from client.c */
-void cmd_help(struct cli_state *cli, struct client_info *info);
/*The following definitions come from clientgen.c */
char *service, char *service_type,
BOOL do_shutdown, BOOL do_tcon, BOOL encrypted);
+/*The following definitions come from clientinfo.c */
+
+void cmd_select(struct client_info*info);
+void cmd_prompt(struct client_info*info);
+void cmd_newer(struct client_info*info);
+void cmd_archive(struct client_info*info);
+void cmd_lowercase(struct client_info*info);
+void cmd_recurse(struct client_info*info);
+void cmd_translate(struct client_info*info);
+void cmd_printmode(struct client_info*info);
+void cmd_lcd(struct client_info *info);
+void cmd_block(struct client_info *info);
+void cmd_tarmode(struct client_info *info);
+
+/*The following definitions come from clientipc.c */
+
+void client_browse_host(struct cli_state *cli, int t_idx, char *workgroup, BOOL sort);
+void cmd_list_shares(struct client_info *info);
+void cmd_list_wgps(struct client_info *info);
+void cmd_list_servers(struct client_info *info);
+void client_ipc_init(void);
+void client_ipc_connect(struct client_info *info,
+ char *username, char *password, char *workgroup);
+void client_ipc_stop(void);
+
+/*The following definitions come from clientprint.c */
+
+void cmd_cancel(struct client_info*info);
+void cmd_print(struct client_info*info);
+void cmd_queue(struct client_info*info);
+void cmd_p_queue_2(struct client_info*info);
+void cmd_qinfo(struct client_info*info);
+
/*The following definitions come from clientsmb.c */
+void client_check_connection(void);
void client_send_message(struct cli_state *cli, int t_idx,
char *username, char *dest_host);
-void client_browse_host(struct cli_state *cli, int t_idx, char *workgroup, BOOL sort);
-void cmd_send_message(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_list_shares(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_list_wgps(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_list_servers(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_pwd(struct cli_state *cli, int t_idx, struct client_info*info);
+void cmd_send_message(struct client_info *info);
void do_cd(struct cli_state *cli, int t_idx, struct client_info*info, char *newdir);
-void cmd_cd(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_dir(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_get(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_more(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_mget(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_mkdir(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_put(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_select(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_mput(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_cancel(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_stat(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_print(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_queue(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_p_queue_2(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_qinfo(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_del(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_rmdir(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_rename(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_prompt(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_newer(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_archive(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_lowercase(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_recurse(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_translate(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_printmode(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_lcd(struct cli_state *cli, int t_idx, struct client_info*info);
-void cmd_quit(struct cli_state *cli, int t_idx, struct client_info*info);
+void cmd_cd(struct client_info*info);
+void cmd_dir(struct client_info*info);
+void cmd_get(struct client_info*info);
+void cmd_more(struct client_info*info);
+void cmd_mget(struct client_info*info);
+void cmd_mkdir(struct client_info*info);
+void cmd_put(struct client_info*info);
+void cmd_mput(struct client_info*info);
+void cmd_stat(struct client_info*info);
+void cmd_del(struct client_info*info);
+void cmd_rmdir(struct client_info*info);
+void cmd_rename(struct client_info*info);
+void cmd_pwd(struct client_info *info);
+void client_smb_init(void);
+void client_smb_connect(struct client_info *info,
+ char *username, char *password, char *workgroup);
+void client_smb_stop(void);
/*The following definitions come from clitar.c */
-void cmd_block(struct cli_state *cli, int t_idx, struct client_info *info);
-void cmd_tarmode(struct cli_state *cli, int t_idx, struct client_info *info);
-void cmd_setmode(struct cli_state *cli, int t_idx, struct client_info *info);
-void cmd_tar(struct cli_state *cli, int t_idx, struct client_info *info);
-int process_tar(struct cli_state *cli, int t_idx, struct client_info *info);
+void cmd_setmode(struct client_info *info);
+void cmd_tar(struct client_info *info);
+int process_tar(struct client_info *info);
int clipfind(char **aret, int ret, char *tok);
int tar_parseargs(struct client_info *info,
int argc, char *argv[], char *Optarg, int Optind);
/*The following definitions come from ntclient.c */
-void cmd_lsa_query_info(struct cli_state *cli, struct client_info *info);
-void cmd_sam_query_users(struct cli_state *cli, struct client_info *info);
-void cmd_nt_login_test(struct cli_state *cli, struct client_info *info);
-void cmd_nltest(struct cli_state *cli, struct client_info *info);
+void cmd_lsa_query_info(struct client_info *info);
+void cmd_sam_query_users(struct client_info *info);
+void cmd_nt_login_test(struct client_info *info);
+void cmd_nltest(struct client_info *info);
+void client_nt_init(void);
+void client_nt_connect(struct client_info *info,
+ char *username, char *password, char *workgroup);
+void client_nt_stop(void);
/*The following definitions come from nterr.c */
void make_samr_r_enum_sam_db(SAMR_R_ENUM_SAM_DB *r_u,
uint32 num_sam_entries, struct smb_passwd pass[MAX_SAM_ENTRIES], uint32 status);
char* samr_io_r_enum_sam_db(BOOL io, SAMR_R_ENUM_SAM_DB *r_u, char *q, char *base, int align, int depth);
+void make_samr_q_query_dispinfo(SAMR_Q_QUERY_DISPINFO *q_e, LSA_POL_HND *pol,
+ uint16 switch_level, uint32 start_idx, uint32 size);
+char* samr_io_q_query_dispinfo(BOOL io, SAMR_Q_QUERY_DISPINFO *q_e, char *q, char *base, int align, int depth);
+void make_samr_r_query_dispinfo(SAMR_R_QUERY_DISPINFO *r_u,
+ uint32 start_idx, uint32 num_sam_entries,
+ struct smb_passwd pass[MAX_SAM_ENTRIES],
+ uint32 status);
+char* samr_io_r_query_dispinfo(BOOL io, SAMR_R_QUERY_DISPINFO *r_u, char *q, char *base, int align, int depth);
char* samr_io_q_lookup_rids(BOOL io, SAMR_Q_LOOKUP_RIDS *q_u, char *q, char *base, int align, int depth);
void make_samr_r_lookup_rids(SAMR_R_LOOKUP_RIDS *r_u,
uint32 num_rids, uint32 rid, uint32 status);
char* smb_io_dom_rid3(BOOL io, DOM_RID3 *rid3, char *q, char *base, int align, int depth);
void make_dom_rid4(DOM_RID4 *rid4, uint16 unknown, uint16 attr, uint32 rid);
char* smb_io_dom_rid4(BOOL io, DOM_RID4 *rid4, char *q, char *base, int align, int depth);
+void make_sam_str2(SAM_STR2 *sam, char *sam_acct, char *sam_name, char *sam_desc);
+char* smb_io_sam_str2(BOOL io, SAM_STR2 *sam, uint32 acct_buf, uint32 name_buf, uint32 desc_buf, char *q, char *base, int align, int depth);
+void make_sam_entry2(SAM_ENTRY2 *sam, uint32 user_idx, struct smb_passwd *pass);
+char* smb_io_sam_entry2(BOOL io, SAM_ENTRY2 *sam, char *q, char *base, int align, int depth);
void make_sam_entry(SAM_ENTRY *sam, char *sam_name, uint32 rid);
char* smb_io_sam_entry(BOOL io, SAM_ENTRY *sam, char *q, char *base, int align, int depth);
void make_clnt_srv(DOM_CLNT_SRV *log, char *logon_srv, char *comp_name);
#define BOOLSTR(b) ((b) ? "Yes" : "No")
#define BITSETB(ptr,bit) ((((char *)ptr)[0] & (1<<(bit)))!=0)
#define BITSETW(ptr,bit) ((SVAL(ptr,0) & (1<<(bit)))!=0)
-#define IS_BITS_SET(var,bit) (((var)&(bit))==(bit))
-#define IS_BITS_CLR(var,bit) (((var)&(~(bit)))==0)
+
+#define IS_BITS_SET_ALL(var,bit) (((var)&(bit))==(bit))
+#define IS_BITS_SET_SOME(var,bit) (((var)&(bit))!=0)
+#define IS_BITS_CLR_ALL(var,bit) (((var)&(~(bit)))==0)
#define PTR_DIFF(p1,p2) ((ptrdiff_t)(((char *)(p1)) - (char *)(p2)))
struct in_addr dest_ip;
fstring dest_host;
fstring query_host;
+ uint8 name_type;
fstring myhostname;
fstring username;
pstring cur_dir;
pstring base_dir;
pstring file_sel;
+
+ fstring service;
+ fstring share;
+ fstring svc_type;
+
time_t newer_than;
int archive_level;
int dir_total;
if (mode == 0)
{
- des_encrypt(sess_key , pwd_c , pwd);
- des_encrypt(sess_key+8, pwd_c+8, pwd);
+ des_encrypt8(sess_key , pwd_c , pwd);
+ des_encrypt8(sess_key+8, pwd_c+8, pwd);
}
else
{
- des_decrypt(sess_key , pwd_c , pwd, 8);
- des_decrypt(sess_key+8, pwd_c+8, pwd, 8);
+ des_decrypt8(sess_key , pwd_c , pwd);
+ des_decrypt8(sess_key+8, pwd_c+8, pwd);
}
#else
{
extern fstring local_machine;
static struct cli_state cli;
+ int t_idx;
uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0;
bzero(&cli, sizeof(cli));
return;
}
- if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) {
+ if (!cli_send_tconX(&cli, &t_idx, "IPC$", "IPC", "", 1)) {
DEBUG(1,("%s refused browse sync IPC$ connect\n", name));
cli_shutdown(&cli);
return;
call_w = work;
call_d = d;
- cli_NetServerEnum(&cli, work->work_group,
+ cli_NetServerEnum(&cli, t_idx, work->work_group,
local_type|SV_TYPE_DOMAIN_ENUM,
callback);
- cli_NetServerEnum(&cli, work->work_group,
+ cli_NetServerEnum(&cli, t_idx, work->work_group,
local?SV_TYPE_LOCAL_LIST_ONLY:SV_TYPE_ALL,
callback);
return False;
}
- if (!(IS_BITS_SET(SVAL(clnt->inbuf,smb_vwv2), SESSION_LOGGED_ON_AS_USER)))
+ if (!(IS_BITS_SET_ALL(SVAL(clnt->inbuf,smb_vwv2), SESSION_LOGGED_ON_AS_USER)))
{
DEBUG(1,("server %s gave us guest access only\n", clnt->full_dest_host_name));
}
return(ERROR(0, 0xc0000000|NT_STATUS_LOGON_FAILURE));
}
- if (IS_BITS_SET(smb_trust_acct->acct_ctrl, ACB_DOMTRUST))
+ if (IS_BITS_SET_ALL(smb_trust_acct->acct_ctrl, ACB_DOMTRUST))
{
DEBUG(4,("Domain trust account %s denied by server\n",user));
SSVAL(outbuf, smb_flg2, FLAGS2_32_BIT_ERROR_CODES);
return(ERROR(0, 0xc0000000|NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT));
}
- if (IS_BITS_SET(smb_trust_acct->acct_ctrl, ACB_SVRTRUST))
+ if (IS_BITS_SET_ALL(smb_trust_acct->acct_ctrl, ACB_SVRTRUST))
{
DEBUG(4,("Server trust account %s denied by server\n",user));
SSVAL(outbuf, smb_flg2, FLAGS2_32_BIT_ERROR_CODES);
return(ERROR(0, 0xc0000000|NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT));
}
- if (IS_BITS_SET(smb_trust_acct->acct_ctrl, ACB_WSTRUST))
+ if (IS_BITS_SET_ALL(smb_trust_acct->acct_ctrl, ACB_WSTRUST))
{
DEBUG(4,("Wksta trust account %s denied by server\n", user));
SSVAL(outbuf, smb_flg2, FLAGS2_32_BIT_ERROR_CODES);
if (lp_security() == SEC_SERVER && server_cryptkey(&pwd_srv, local_machine))
{
DEBUG(3,("using password server validation\n"));
- doencrypt = IS_BITS_SET(pwd_srv.sec_mode, USE_CHALLENGE_RESPONSE);
+ doencrypt = IS_BITS_SET_ALL(pwd_srv.sec_mode, USE_CHALLENGE_RESPONSE);
}
if (doencrypt)
}
-static BOOL open_connection(struct cli_state *c)
+static BOOL open_connection(struct cli_state *c, t_idx,int *t_idx)
{
- if (!cli_initialise(c) || !cli_connect(c, host, NULL))
+ if (!cli_initialise(c) || !cli_connect(c, t_idx,host, NULL))
{
printf("Failed to connect with %s\n", host);
return False;
}
- if (!cli_session_request(c, host, 0x20, myname, 0x0))
+ if (!cli_session_request(c, t_idx,host, 0x20, myname, 0x0))
{
printf("%s rejected the session\n",host);
cli_shutdown(c);
return False;
}
- if (!cli_session_setup(c, username, password, strlen(password),
+ if (!cli_session_setup(c, t_idx,username, password, strlen(password),
"", 0, workgroup)) {
printf("%s rejected the sessionsetup (%s)\n", host, cli_errstr(c));
cli_shutdown(c);
return False;
}
- if (!cli_send_tconX(c, share, "A:", password, strlen(password)+1)) {
+ if (!cli_send_tconX(c, t_idx,t_idx, share, "A:", password, strlen(password)+1)) {
printf("%s refused tree connect (%s)\n", host, cli_errstr(c));
cli_shutdown(c);
return False;
}
-static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
+static BOOL wait_lock(struct cli_state *c, t_idx,int fnum, uint32 offset, uint32 len)
{
- while (!cli_lock(c, fnum, offset, len, -1)) {
+ while (!cli_lock(c, t_idx,fnum, offset, len, -1)) {
int eclass, num;
- cli_error(c, &eclass, &num);
+ cli_error(c, t_idx,&eclass, &num);
if (eclass != ERRDOS || num != ERRlock) {
printf("lock failed (%s)\n",
cli_errstr(c));
}
-static BOOL rw_torture(struct cli_state *c, int numops)
+static BOOL rw_torture(struct cli_state *c, t_idx,int t_idx, int numops)
{
char *lockfname = "\\torture.lck";
fstring fname;
int pid2, pid = getpid();
int i;
- fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
+ fnum2 = cli_open(c, t_idx,lockfname, O_RDWR | O_CREAT | O_EXCL,
DENY_NONE);
if (fnum2 == -1)
- fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
+ fnum2 = cli_open(c, t_idx,t_idx, lockfname, O_RDWR, DENY_NONE);
if (fnum2 == -1) {
printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
return False;
}
sprintf(fname,"\\torture.%u", n);
- if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
+ if (!wait_lock(c, t_idx,fnum2, n*sizeof(int), sizeof(int))) {
return False;
}
- fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
+ fnum = cli_open(c, t_idx,fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
if (fnum == -1) {
printf("open failed (%s)\n", cli_errstr(c));
break;
}
- if (cli_write_x(c, fnum, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
+ if (cli_write_x(c, t_idx,fnum, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
printf("write failed (%s)\n", cli_errstr(c));
}
pid2 = 0;
- if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
+ if (cli_read(c, t_idx,fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
printf("read failed (%s)\n", cli_errstr(c));
}
printf("data corruption!\n");
}
- if (!cli_close(c, fnum, 0)) {
+ if (!cli_close(c, t_idx,fnum, 0)) {
printf("close failed (%s)\n", cli_errstr(c));
}
- if (!cli_unlink(c, fname)) {
+ if (!cli_unlink(c, t_idx,fname)) {
printf("unlink failed (%s)\n", cli_errstr(c));
}
- if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int), -1)) {
+ if (!cli_unlock(c, t_idx,fnum2, n*sizeof(int), sizeof(int), -1)) {
printf("unlock failed (%s)\n", cli_errstr(c));
}
}
static void run_torture(int numops)
{
static struct cli_state cli;
+ int t_idx;
- if (open_connection(&cli)) {
+ if (open_connection(&cli, &t_idx))
+ {
cli_sockopt(&cli, sockops);
printf("pid %d OK\n", getpid());
- rw_torture(&cli, numops);
+ rw_torture(&cli, t_idx, numops);
close_connection(&cli);
}