summaryrefslogtreecommitdiff
path: root/source3/client/clientutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/client/clientutil.c')
-rw-r--r--source3/client/clientutil.c533
1 files changed, 292 insertions, 241 deletions
diff --git a/source3/client/clientutil.c b/source3/client/clientutil.c
index 9dd1dc040e..142b95df79 100644
--- a/source3/client/clientutil.c
+++ b/source3/client/clientutil.c
@@ -77,26 +77,50 @@ extern int Client;
/****************************************************************************
setup basics in a outgoing packet
****************************************************************************/
-static void cli_setup_pkt(char *outbuf)
+void cli_setup_pkt(char *outbuf)
{
SSVAL(outbuf,smb_pid,pid);
SSVAL(outbuf,smb_uid,uid);
SSVAL(outbuf,smb_mid,mid);
- if (Protocol > PROTOCOL_CORE)
+ 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 prcnt,int drcnt,
+ int mprcnt,int mdrcnt,
+ int *rprcnt,int *rdrcnt,
+ char *param,char *data,
+ 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);
+
+ cli_send_trans_request(outbuf,SMBtrans,pipe_name, 0,0,
+ data,param,NULL,
+ drcnt,prcnt,0,
+ 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
****************************************************************************/
-static BOOL cli_receive_trans_response(char *inbuf,int trans,int *data_len,
- int *param_len, char **data,
- char **param)
+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;
@@ -129,13 +153,6 @@ static BOOL cli_receive_trans_response(char *inbuf,int trans,int *data_len,
{
this_data = SVAL(inbuf,smb_drcnt);
this_param = SVAL(inbuf,smb_prcnt);
-
- if (this_data + *data_len > total_data ||
- this_param + *param_len > total_param) {
- DEBUG(1,("Data overflow in cli_receive_trans_response\n"));
- return False;
- }
-
if (this_data)
memcpy(*data + SVAL(inbuf,smb_drdisp),
smb_base(inbuf) + SVAL(inbuf,smb_droff),
@@ -171,24 +188,140 @@ static BOOL cli_receive_trans_response(char *inbuf,int trans,int *data_len,
return(True);
}
+
+
+/****************************************************************************
+ send a SMB trans or trans2 request
+ ****************************************************************************/
+BOOL cli_send_trans_request(char *outbuf,int trans,
+ char *name,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 ? strlen(name)+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)
+ strcpy(p,name); /* 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
****************************************************************************/
-static BOOL cli_send_session_request(char *inbuf, char *outbuf)
+BOOL cli_send_session_request(char *inbuf,char *outbuf)
{
fstring dest;
char *p;
int len = 4;
/* send a session request (RFC 8002) */
- fstrcpy(dest,desthost);
-
+ strcpy(dest,desthost);
p = strchr(dest,'.');
if (p) *p = 0;
/* put in the destination name */
p = outbuf+len;
- name_mangle(dest,p,name_type);
+ name_mangle(dest,p,name_type); /* 0x20 is the SMB server NetBIOS type. */
len += name_len(p);
/* and my name */
@@ -223,11 +356,11 @@ static BOOL cli_send_session_request(char *inbuf, char *outbuf)
putip((char *)&dest_ip,inbuf+4);
close_sockets();
- Client = open_socket_out(SOCK_STREAM, &dest_ip, port, SHORT_CONNECT_TIMEOUT);
+ Client = open_socket_out(SOCK_STREAM, &dest_ip, port, LONG_CONNECT_TIMEOUT);
if (Client == -1)
return False;
- DEBUG(5,("Retargeted\n"));
+ DEBUG(3,("Retargeted\n"));
set_socket_options(Client,user_socket_options);
@@ -272,28 +405,26 @@ static BOOL cli_send_session_request(char *inbuf, char *outbuf)
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}
+};
-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 cli_send_login(char *inbuf,char *outbuf,BOOL start_session,BOOL use_setup)
{
BOOL was_null = (!inbuf && !outbuf);
int sesskey=0;
@@ -306,6 +437,7 @@ BOOL cli_send_login(char *inbuf, char *outbuf, BOOL start_session, BOOL use_setu
pstring dev;
char *p;
int numprots;
+ int tries=0;
if (was_null)
{
@@ -313,11 +445,15 @@ BOOL cli_send_login(char *inbuf, char *outbuf, BOOL start_session, BOOL use_setu
outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN);
}
- pstrcpy(dev,"A:");
+#if AJT
+ if (strstr(service,"IPC$")) connect_as_ipc = True;
+#endif
+
+ strcpy(dev,"A:");
if (connect_as_printer)
- pstrcpy(dev,"LPT1:");
+ strcpy(dev,"LPT1:");
if (connect_as_ipc)
- pstrcpy(dev,"IPC");
+ strcpy(dev,"IPC");
if (start_session && !cli_send_session_request(inbuf,outbuf))
@@ -392,10 +528,10 @@ BOOL cli_send_login(char *inbuf, char *outbuf, BOOL start_session, BOOL use_setu
}
crypt_len = smb_buflen(inbuf);
memcpy(cryptkey,smb_buf(inbuf),8);
- DEBUG(5,("max mux %d\n",SVAL(inbuf,smb_vwv3)));
+ DEBUG(3,("max mux %d\n",SVAL(inbuf,smb_vwv3)));
max_vcs = SVAL(inbuf,smb_vwv4);
- DEBUG(5,("max vcs %d\n",max_vcs));
- DEBUG(5,("max blk %d\n",SVAL(inbuf,smb_vwv5)));
+ 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);
@@ -408,17 +544,17 @@ BOOL cli_send_login(char *inbuf, char *outbuf, BOOL start_session, BOOL use_setu
memcpy(cryptkey,smb_buf(inbuf),8);
if (IVAL(inbuf,smb_vwv9+1) & 1)
readbraw_supported = writebraw_supported = True;
- DEBUG(5,("max mux %d\n",SVAL(inbuf,smb_vwv1+1)));
+ DEBUG(3,("max mux %d\n",SVAL(inbuf,smb_vwv1+1)));
max_vcs = SVAL(inbuf,smb_vwv2+1);
- DEBUG(5,("max vcs %d\n",max_vcs));
- DEBUG(5,("max raw %d\n",IVAL(inbuf,smb_vwv5+1)));
- DEBUG(5,("capabilities 0x%x\n",IVAL(inbuf,smb_vwv9+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(5,("Sec mode %d\n",SVAL(inbuf,smb_vwv1)));
- DEBUG(5,("max xmt %d\n",max_xmit));
- DEBUG(5,("Got %d byte crypt key\n",crypt_len));
- DEBUG(5,("Chose protocol [%s]\n",prots[SVAL(inbuf,smb_vwv0)].name));
+ 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);
@@ -439,35 +575,28 @@ BOOL cli_send_login(char *inbuf, char *outbuf, BOOL start_session, BOOL use_setu
else
pass = (char *)getpass("Password: ");
- if(pass == NULL)
- {
- DEBUG(0, ("cli_send_login : no password available - logon failed.\n"));
- return False;
- }
+ /* 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;
int passlen = strlen(pass)+1;
- fstrcpy(pword,pass);
+ strcpy(pword,pass);
if (doencrypt && *pass) {
- DEBUG(5,("Using encrypted passwords\n"));
+ DEBUG(3,("Using encrypted passwords\n"));
passlen = 24;
SMBencrypt((uchar *)pass,(uchar *)cryptkey,(uchar *)pword);
}
/* if in share level security then don't send a password now */
- if (!(sec_mode & 1)) {fstrcpy(pword, "");passlen=1;}
+ if (!(sec_mode & 1)) {strcpy(pword, "");passlen=1;}
/* send a session setup command */
bzero(outbuf,smb_size);
- if (passlen > MAX_PASS_LEN) {
- DEBUG(1,("password too long %d\n", passlen));
- return False;
- }
-
if (Protocol < PROTOCOL_NT1) {
set_message(outbuf,10,1 + strlen(username) + passlen,True);
CVAL(outbuf,smb_com) = SMBsesssetupX;
@@ -520,13 +649,13 @@ BOOL cli_send_login(char *inbuf, char *outbuf, BOOL start_session, BOOL use_setu
SVAL(inbuf,smb_err) == ERRbadpw)))
{
got_pass = False;
- DEBUG(5,("resending login\n"));
+ 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 or -n options useful\n"));
+ 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)
@@ -549,11 +678,18 @@ BOOL cli_send_login(char *inbuf, char *outbuf, BOOL start_session, BOOL use_setu
/* use the returned uid from now on */
if (SVAL(inbuf,smb_uid) != uid)
- DEBUG(5,("Server gave us a UID of %d. We gave %d\n",
+ DEBUG(3,("Server gave us a UID of %d. We gave %d\n",
SVAL(inbuf,smb_uid),uid));
uid = SVAL(inbuf,smb_uid);
}
+ if (SVAL(inbuf, smb_vwv2) & 1)
+ DEBUG(1,("connected as guest "));
+ if (sec_mode & 1)
+ 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);
@@ -569,7 +705,7 @@ BOOL cli_send_login(char *inbuf, char *outbuf, BOOL start_session, BOOL use_setu
{
int passlen = strlen(pass)+1;
fstring pword;
- fstrcpy(pword,pass);
+ strcpy(pword,pass);
if (doencrypt && *pass) {
passlen=24;
@@ -578,22 +714,39 @@ BOOL cli_send_login(char *inbuf, char *outbuf, BOOL start_session, BOOL use_setu
/* if in user level security then don't send a password now */
if ((sec_mode & 1)) {
- fstrcpy(pword, ""); passlen=1;
+ strcpy(pword, ""); passlen=1;
}
- 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);
+ 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);
@@ -624,19 +777,27 @@ BOOL cli_send_login(char *inbuf, char *outbuf, BOOL start_session, BOOL use_setu
}
- max_xmit = MIN(max_xmit,BUFFER_SIZE-4);
- if (max_xmit <= 0)
- max_xmit = BUFFER_SIZE - 4;
+ if (Protocol <= PROTOCOL_COREPLUS) {
+ max_xmit = SVAL(inbuf,smb_vwv0);
- cnum = SVAL(inbuf,smb_tid);
+ cnum = SVAL(inbuf,smb_vwv1);
+ }
+ else {
+ max_xmit = MIN(max_xmit,BUFFER_SIZE-4);
+ if (max_xmit <= 0)
+ max_xmit = BUFFER_SIZE - 4;
- DEBUG(5,("Connected with cnum=%d max_xmit=%d\n",cnum,max_xmit));
+ 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;
}
@@ -644,7 +805,7 @@ BOOL cli_send_login(char *inbuf, char *outbuf, BOOL start_session, BOOL use_setu
/****************************************************************************
send a logout command
****************************************************************************/
-void cli_send_logout(void)
+void cli_send_logout(void )
{
pstring inbuf,outbuf;
@@ -671,152 +832,15 @@ void cli_send_logout(void)
/****************************************************************************
- send a SMB trans or trans2 request
- ****************************************************************************/
-static BOOL cli_send_trans_request(char *outbuf, int trans, char *name, 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 ? strlen(name)+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)
- strcpy(p,name); /* 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);
-}
-
-
-
-/****************************************************************************
-call a remote api
-****************************************************************************/
-BOOL cli_call_api(int prcnt,int drcnt,int mprcnt,int mdrcnt,int *rprcnt,
- int *rdrcnt, char *param,char *data,
- 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);
-
- cli_send_trans_request(outbuf,SMBtrans,"\\PIPE\\LANMAN",0,0,
- data,param,NULL,
- drcnt,prcnt,0,
- mdrcnt,mprcnt,0);
-
- return (cli_receive_trans_response(inbuf,SMBtrans,
- rdrcnt,rprcnt,
- rdata,rparam));
-}
-
-
-/****************************************************************************
open the client sockets
****************************************************************************/
-BOOL cli_open_sockets(int port)
+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;
@@ -829,38 +853,63 @@ BOOL cli_open_sockets(int port)
}
else
{
- pstrcpy(service2,service);
+ strcpy(service2,service);
host = strtok(service2,"\\/");
- pstrcpy(desthost,host);
+ if (!host) {
+ DEBUG(0,("Badly formed host name\n"));
+ return(False);
+ }
+ strcpy(desthost,host);
}
- DEBUG(5,("Opening sockets\n"));
-
- if (*myname == 0)
- get_myname(myname,NULL);
+ if (!(*myname)) {
+ get_myname(myname,NULL);
+ }
strupper(myname);
+ DEBUG(3,("Opening sockets\n"));
+
if (!have_ip)
{
struct hostent *hp;
- if ((hp = Get_Hostbyname(host)) == 0)
- {
+ 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;
}
-
- putip((char *)&dest_ip,(char *)hp->h_addr);
+ }
}
- Client = open_socket_out(SOCK_STREAM, &dest_ip, port, SHORT_CONNECT_TIMEOUT);
+ Client = open_socket_out(SOCK_STREAM, &dest_ip, port, LONG_CONNECT_TIMEOUT);
if (Client == -1)
return False;
- DEBUG(5,("Connected\n"));
-
+ DEBUG(3,("Connected\n"));
+
set_socket_options(Client,user_socket_options);
-
+
return True;
}
@@ -923,12 +972,14 @@ err_code_struct dos_msgs[] = {
{"ERRnofiles",18,"A File Search command can find no more files matching the specified criteria."},
{"ERRbadshare",32,"The sharing mode specified for an Open conflicts with existing FIDs on the file."},
{"ERRlock",33,"A Lock request conflicted with an existing lock or specified an invalid mode, or an Unlock requested attempted to remove a lock held by another process."},
+ {"ERRnosuchshare", 67, "You specified an invalid share name"},
{"ERRfilexists",80,"The file named in a Create Directory, Make New File or Link request already exists."},
{"ERRbadpipe",230,"Pipe invalid."},
{"ERRpipebusy",231,"All instances of the requested pipe are busy."},
{"ERRpipeclosing",232,"Pipe close in progress."},
{"ERRnotconnected",233,"No process on other end of pipe."},
{"ERRmoredata",234,"There is more data to be returned."},
+ {"ERRinvgroup",2455,"Invalid workgroup (try the -W option)"},
{NULL,-1,NULL}};
/* Server Error Messages */
@@ -982,7 +1033,7 @@ err_code_struct hard_msgs[] = {
{"ERRwrite",29,"Write fault."},
{"ERRread",30,"Read fault."},
{"ERRgeneral",31,"General failure."},
- {"ERRbadshare",32,"A open conflicts with an existing open."},
+ {"ERRbadshare",32,"An open conflicts with an existing open."},
{"ERRlock",33,"A Lock request conflicted with an existing lock or specified an invalid mode, or an Unlock requested attempted to remove a lock held by another process."},
{"ERRwrongdisk",34,"The wrong disk was found in a drive."},
{"ERRFCBUnavail",35,"No FCBs are available to process request."},
@@ -1040,6 +1091,6 @@ char *smb_errstr(char *inbuf)
return ret;
}
- sprintf(ret,"ERROR: Unknown error (%d,%d)",class,num);
+ sprintf(ret,"Error: Unknown error (%d,%d)",class,num);
return(ret);
}