summaryrefslogtreecommitdiff
path: root/source3/libsmb/clientgen.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>1997-11-10 19:23:17 +0000
committerJeremy Allison <jra@samba.org>1997-11-10 19:23:17 +0000
commit77aec4ae6307c0ad0b843bbf23d64ccb1aaf7476 (patch)
tree92e15c7219e20ad5e58833b83f1387feb3e1125e /source3/libsmb/clientgen.c
parentcc512947c9e1744c5541252c7cc934ebcd2e6961 (diff)
downloadsamba-77aec4ae6307c0ad0b843bbf23d64ccb1aaf7476.tar.gz
samba-77aec4ae6307c0ad0b843bbf23d64ccb1aaf7476.tar.bz2
samba-77aec4ae6307c0ad0b843bbf23d64ccb1aaf7476.zip
Rolled back tree state to 11:59pm 8th November 1997 EST to
remove problems. Jeremy (This used to be commit 4a36ac236c2ad634f05efcd0179875d09988614a)
Diffstat (limited to 'source3/libsmb/clientgen.c')
-rw-r--r--source3/libsmb/clientgen.c146
1 files changed, 64 insertions, 82 deletions
diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c
index 78bbf8115f..b98f2fca69 100644
--- a/source3/libsmb/clientgen.c
+++ b/source3/libsmb/clientgen.c
@@ -104,7 +104,7 @@ static BOOL cli_send_trans(struct cli_state *cli,
if (this_ldata < ldata || this_lparam < lparam) {
/* receive interim response */
if (!receive_smb(cli->fd,cli->inbuf,cli->timeout) ||
- cli_error(cli,NULL, NULL)) {
+ CVAL(cli->inbuf,smb_rcls) != 0) {
return(False);
}
@@ -176,7 +176,8 @@ static BOOL cli_receive_trans(struct cli_state *cli,
CVAL(cli->inbuf,smb_com)));
return(False);
}
- if (cli_error(cli,NULL, NULL)) return(False);
+ if (CVAL(cli->inbuf,smb_rcls) != 0)
+ return(False);
/* parse out the lengths */
total_data = SVAL(cli->inbuf,smb_tdrcnt);
@@ -226,7 +227,8 @@ static BOOL cli_receive_trans(struct cli_state *cli,
CVAL(cli->inbuf,smb_com)));
return(False);
}
- if (cli_error(cli,NULL, NULL)) return(False);
+ if (CVAL(cli->inbuf,smb_rcls) != 0)
+ return(False);
}
return(True);
@@ -298,7 +300,7 @@ BOOL cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation)
if (cli->error == 0) {
DEBUG(4,("NetWkstaUserLogon success\n"));
- cli->privileges = SVAL(p, 24);
+ cli->privilages = SVAL(p, 24);
fstrcpy(cli->eff_name,p+2);
} else {
DEBUG(1,("NetwkstaUserLogon gave error %d\n", cli->error));
@@ -422,22 +424,15 @@ BOOL cli_session_setup(struct cli_state *cli,
return False;
}
- if ((cli->sec_mode & USE_CHALLENGE_RESPONSE) && *pass && passlen != 24)
- {
+ if ((cli->sec_mode & 2) && *pass && passlen != 24) {
passlen = 24;
SMBencrypt((uchar *)pass,(uchar *)cli->cryptkey,(uchar *)pword);
- }
- else
- {
+ } else {
memcpy(pword, pass, passlen);
}
/* if in share level security then don't send a password now */
- if (!(cli->sec_mode & USE_USER_LEVEL_SECURITY))
- {
- fstrcpy(pword, "");
- passlen=1;
- }
+ if (!(cli->sec_mode & 1)) {fstrcpy(pword, "");passlen=1;}
/* send a session setup command */
bzero(cli->outbuf,smb_size);
@@ -492,7 +487,9 @@ BOOL cli_session_setup(struct cli_state *cli,
show_msg(cli->inbuf);
- if (cli_error(cli,NULL, NULL)) return(False);
+ if (CVAL(cli->inbuf,smb_rcls) != 0) {
+ return False;
+ }
/* use the returned uid from now on */
cli->uid = SVAL(cli->inbuf,smb_uid);
@@ -512,19 +509,19 @@ BOOL cli_send_tconX(struct cli_state *cli,
bzero(cli->outbuf,smb_size);
bzero(cli->inbuf,smb_size);
- if (cli->sec_mode & USE_USER_LEVEL_SECURITY) {
+ if (cli->sec_mode & 1) {
passlen = 1;
pass = "";
}
- if ((cli->sec_mode & USE_CHALLENGE_RESPONSE) && *pass && passlen != 24) {
+ if ((cli->sec_mode & 2) && *pass && passlen != 24) {
passlen = 24;
SMBencrypt((uchar *)pass,(uchar *)cli->cryptkey,(uchar *)pword);
} else {
memcpy(pword, pass, passlen);
}
- sprintf(fullshare, "\\\\%s\\%s", cli->called_netbios_name, share);
+ sprintf(fullshare, "\\\\%s\\%s", cli->desthost, share);
set_message(cli->outbuf,4,
2 + strlen(fullshare) + passlen + strlen(dev),True);
@@ -547,7 +544,9 @@ BOOL cli_send_tconX(struct cli_state *cli,
if (!receive_smb(cli->fd,cli->inbuf,cli->timeout))
return False;
- if (cli_error(cli,NULL, NULL)) return(False);
+ if (CVAL(cli->inbuf,smb_rcls) != 0) {
+ return False;
+ }
cli->cnum = SVAL(cli->inbuf,smb_tid);
return True;
@@ -569,7 +568,7 @@ BOOL cli_tdis(struct cli_state *cli)
if (!receive_smb(cli->fd,cli->inbuf,cli->timeout))
return False;
- return !cli_error(cli,NULL, NULL);
+ return CVAL(cli->inbuf,smb_rcls) == 0;
}
/****************************************************************************
@@ -600,7 +599,9 @@ BOOL cli_unlink(struct cli_state *cli, char *fname)
return False;
}
- if (cli_error(cli,NULL, NULL)) return False;
+ if (CVAL(cli->inbuf,smb_rcls) != 0) {
+ return False;
+ }
return True;
}
@@ -658,7 +659,9 @@ int cli_open(struct cli_state *cli, char *fname, int flags, int share_mode)
return -1;
}
- if (cli_error(cli,NULL, NULL)) return -1;
+ if (CVAL(cli->inbuf,smb_rcls) != 0) {
+ return -1;
+ }
return SVAL(cli->inbuf,smb_vwv2);
}
@@ -689,7 +692,9 @@ BOOL cli_close(struct cli_state *cli, int fnum)
return False;
}
- if (cli_error(cli,NULL, NULL)) return False;
+ if (CVAL(cli->inbuf,smb_rcls) != 0) {
+ return False;
+ }
return True;
}
@@ -728,7 +733,9 @@ BOOL cli_lock(struct cli_state *cli, int fnum, uint32 offset, uint32 len, int ti
return False;
}
- if (cli_error(cli,NULL, NULL)) return False;
+ if (CVAL(cli->inbuf,smb_rcls) != 0) {
+ return False;
+ }
return True;
}
@@ -766,7 +773,9 @@ BOOL cli_unlock(struct cli_state *cli, int fnum, uint32 offset, uint32 len, int
return False;
}
- if (cli_error(cli,NULL, NULL)) return False;
+ if (CVAL(cli->inbuf,smb_rcls) != 0) {
+ return False;
+ }
return True;
}
@@ -799,7 +808,9 @@ int cli_read(struct cli_state *cli, int fnum, char *buf, uint32 offset, uint16 s
return -1;
}
- if (cli_error(cli,NULL, NULL)) return -1;
+ if (CVAL(cli->inbuf,smb_rcls) != 0) {
+ return -1;
+ }
size = SVAL(cli->inbuf, smb_vwv5);
p = smb_base(cli->inbuf) + SVAL(cli->inbuf,smb_vwv6);
@@ -841,7 +852,9 @@ int cli_write(struct cli_state *cli, int fnum, char *buf, uint32 offset, uint16
return -1;
}
- if (cli_error(cli,NULL, NULL)) return -1;
+ if (CVAL(cli->inbuf,smb_rcls) != 0) {
+ return -1;
+ }
return SVAL(cli->inbuf, smb_vwv2);
}
@@ -886,8 +899,10 @@ BOOL cli_negprot(struct cli_state *cli)
show_msg(cli->inbuf);
- if (cli_error(cli,NULL, NULL)) return False;
- if ((int)SVAL(cli->inbuf,smb_vwv0) >= numprots) return(False);
+ if (CVAL(cli->inbuf,smb_rcls) != 0 ||
+ ((int)SVAL(cli->inbuf,smb_vwv0) >= numprots)) {
+ return(False);
+ }
cli->protocol = prots[SVAL(cli->inbuf,smb_vwv0)].prot;
@@ -921,43 +936,33 @@ BOOL cli_negprot(struct cli_state *cli)
return True;
}
-#define TRUNCATE_NETBIOS_NAME 1
/****************************************************************************
- send a session request. see rfc1002.txt 4.3 and 4.3.2
+ send a session request
****************************************************************************/
-BOOL cli_session_request(struct cli_state *cli,
- char *called_host_name , int called_name_type,
- char calling_netbios_name[16], int calling_name_type)
+BOOL cli_session_request(struct cli_state *cli, char *host, int name_type,
+ char *myname)
{
+ fstring dest;
char *p;
int len = 4;
/* send a session request (RFC 1002) */
- strncpy(cli->called_netbios_name , called_host_name , sizeof(cli->called_netbios_name ));
- strncpy(cli->calling_netbios_name, calling_netbios_name, sizeof(cli->calling_netbios_name));
+ fstrcpy(dest,host);
- /* sorry, don't trust strncpy to null-terminate the string... */
- cli->called_netbios_name [sizeof(cli->called_netbios_name )-1] = 0;
- cli->calling_netbios_name[sizeof(cli->calling_netbios_name)-1] = 0;
-
-#ifdef TRUNCATE_NETBIOS_NAME
- /* ok. this is because of a stupid microsoft-ism. if the called host
- name contains a '.', microsoft clients expect you to truncate the
- netbios name up to and including the '.'
- */
- p = strchr(cli->called_netbios_name, '.');
+ p = strchr(dest,'.');
if (p) *p = 0;
-#endif /* TRUNCATE_NETBIOS_NAME */
+
+ fstrcpy(cli->desthost, dest);
/* put in the destination name */
p = cli->outbuf+len;
- name_mangle(cli->called_netbios_name, p, called_name_type);
+ name_mangle(dest,p,name_type);
len += name_len(p);
/* and my name */
p = cli->outbuf+len;
- name_mangle(cli->calling_netbios_name, p, calling_name_type);
+ name_mangle(myname,p,0);
len += name_len(p);
/* setup the packet length */
@@ -985,27 +990,26 @@ BOOL cli_connect(struct cli_state *cli, char *host, struct in_addr *ip)
{
struct in_addr dest_ip;
- fstrcpy(cli->full_dest_host_name, host);
+ fstrcpy(cli->desthost, host);
- if (!ip)
- {
- /* no ip specified - look up the name */
+ if (!ip) {
struct hostent *hp;
- if ((hp = Get_Hostbyname(host)) == 0) {
+ if ((hp = Get_Hostbyname(cli->desthost)) == 0) {
return False;
}
putip((char *)&dest_ip,(char *)hp->h_addr);
} else {
- /* use the given ip address */
dest_ip = *ip;
}
- /* open the socket */
+
cli->fd = open_socket_out(SOCK_STREAM, &dest_ip, 139, cli->timeout);
+ if (cli->fd == -1)
+ return False;
- return (cli->fd != -1);
+ return True;
}
@@ -1055,32 +1059,10 @@ char *cli_errstr(struct cli_state *cli)
/****************************************************************************
return error codes for the last packet
****************************************************************************/
-BOOL cli_error(struct cli_state *cli, uint8 *eclass, uint32 *num)
+void cli_error(struct cli_state *cli, int *eclass, int *num)
{
- int flgs2 = SVAL(cli->inbuf,smb_flg2);
-
- if (eclass) *eclass = 0;
- if (num ) *num = 0;
-
- if (flgs2 & FLAGS2_32_BIT_ERROR_CODES)
- {
- /* 32 bit error codes detected */
- uint32 nt_err = IVAL(cli->inbuf,smb_rcls);
- if (num) *num = nt_err;
- return (nt_err != 0);
- }
- else
- {
- /* dos 16 bit error codes detected */
- char rcls = CVAL(cli->inbuf,smb_rcls);
- if (rcls != 0)
- {
- if (eclass) *eclass = rcls;
- if (num ) *num = SVAL(cli->inbuf,smb_err);
- return True;
- }
- }
- return False;
+ *eclass = CVAL(cli->inbuf,smb_rcls);
+ *num = SVAL(cli->inbuf,smb_err);
}
/****************************************************************************