summaryrefslogtreecommitdiff
path: root/source3/libsmb
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
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')
-rw-r--r--source3/libsmb/clientgen.c146
-rw-r--r--source3/libsmb/nterr.c30
-rw-r--r--source3/libsmb/smbencrypt.c22
-rw-r--r--source3/libsmb/smberr.c26
4 files changed, 75 insertions, 149 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);
}
/****************************************************************************
diff --git a/source3/libsmb/nterr.c b/source3/libsmb/nterr.c
index 7dd2234e1d..bda0f882a6 100644
--- a/source3/libsmb/nterr.c
+++ b/source3/libsmb/nterr.c
@@ -1,16 +1,12 @@
-/* NT error codes. please read nterr.h */
-#include "includes.h"
#include "nterr.h"
-typedef struct
+static struct
{
char *nt_errstr;
uint16 nt_errcode;
-} nt_err_code_struct;
-
-nt_err_code_struct nt_errs[] =
+} nt_errs[] =
{
{ "NT_STATUS_UNSUCCESSFUL", NT_STATUS_UNSUCCESSFUL },
{ "NT_STATUS_NOT_IMPLEMENTED", NT_STATUS_NOT_IMPLEMENTED },
@@ -516,25 +512,3 @@ nt_err_code_struct nt_errs[] =
{ NULL, 0 }
};
-/*****************************************************************************
- returns an NT error message. not amazingly helpful, but better than a number.
- *****************************************************************************/
-char *get_nt_error_msg(uint16 nt_code)
-{
- static pstring msg;
- int idx = 0;
-
- strcpy(msg, "Unknown NT error");
-
- while (nt_errs[idx].nt_errstr != NULL)
- {
- if (nt_errs[idx].nt_errcode == nt_code)
- {
- strcpy(msg, nt_errs[idx].nt_errstr);
- return msg;
- }
- idx++;
- }
- return NULL;
-}
-
diff --git a/source3/libsmb/smbencrypt.c b/source3/libsmb/smbencrypt.c
index 1bf0bcc8e6..38d414cf23 100644
--- a/source3/libsmb/smbencrypt.c
+++ b/source3/libsmb/smbencrypt.c
@@ -29,9 +29,8 @@ extern int DEBUGLEVEL;
/*
This implements the X/Open SMB password encryption
It takes a password, a 8 byte "crypt key" and puts 24 bytes of
- encrypted password into p24
- */
-void SMBencrypt(uchar *passwd, uchar *c8, uchar p24[24])
+ encrypted password into p24 */
+void SMBencrypt(uchar *passwd, uchar *c8, uchar *p24)
{
uchar p14[15], p21[21];
@@ -98,19 +97,9 @@ void E_md4hash(uchar *passwd, uchar *p16)
mdfour(p16, (unsigned char *)wpwd, len);
}
-/* Does the des encryption from the NT or LM MD4 hash. */
-void SMBOWFencrypt(char passwd[16], uchar *c8, uchar p24[24])
-{
- uchar p21[21];
-
- memset(p21,'\0',21);
-
- memcpy(p21, passwd, sizeof(passwd));
- E_P24(p21, c8, p24);
-}
-
/* Does the NT MD4 hash then des encryption. */
-void SMBNTencrypt(uchar *passwd, uchar *c8, uchar p24[24])
+
+void SMBNTencrypt(uchar *passwd, uchar *c8, uchar *p24)
{
uchar p21[21];
@@ -121,7 +110,8 @@ void SMBNTencrypt(uchar *passwd, uchar *c8, uchar p24[24])
}
/* Does both the NT and LM owfs of a user's password */
-void nt_lm_owf_gen(char *pwd, char nt_p16[16], char p16[16])
+
+void nt_lm_owf_gen(char *pwd, char *nt_p16, char *p16)
{
char passwd[130];
StrnCpy(passwd, pwd, sizeof(passwd)-1);
diff --git a/source3/libsmb/smberr.c b/source3/libsmb/smberr.c
index 35cd0bf88f..5149568c04 100644
--- a/source3/libsmb/smberr.c
+++ b/source3/libsmb/smberr.c
@@ -151,28 +151,9 @@ return a SMB error string from a SMB buffer
char *smb_errstr(char *inbuf)
{
static pstring ret;
- int i,j;
- BOOL nt_errors = (SVAL(inbuf,smb_flg2) & FLAGS2_32_BIT_ERROR_CODES) == FLAGS2_32_BIT_ERROR_CODES;
-
- if (nt_errors)
- {
- char *nt_errstr = NULL;
- uint32 nt_err = IVAL(inbuf, smb_rcls);
- uint16 nt_num = nt_err & 0x0000ffff;
- uint16 class = (nt_err & 0xffff0000) >> 16;
-
- /* maybe lookup the error message in the nt error codes... */
- if ((nt_errstr = get_nt_error_msg(nt_num)) != NULL)
- {
- sprintf(ret,"NT Error: (%4x, %s)", class, nt_errstr);
- return ret;
- }
- sprintf(ret,"NT Error: Unknown error (%4x %4x)", class, nt_num);
- }
- else
- {
int class = CVAL(inbuf,smb_rcls);
int num = SVAL(inbuf,smb_err);
+ int i,j;
for (i=0;err_classes[i].class;i++)
if (err_classes[i].code == class)
@@ -195,8 +176,7 @@ char *smb_errstr(char *inbuf)
sprintf(ret,"%s - %d",err_classes[i].class,num);
return ret;
}
- sprintf(ret,"Error: Unknown error (%4x,%d)", class, num);
- }
-
+
+ sprintf(ret,"Error: Unknown error (%d,%d)",class,num);
return(ret);
}