diff options
author | Luke Leighton <lkcl@samba.org> | 1999-12-01 02:15:14 +0000 |
---|---|---|
committer | Luke Leighton <lkcl@samba.org> | 1999-12-01 02:15:14 +0000 |
commit | 6ddfc68e0496dc41f8c9a022a0b04a2066b43c9d (patch) | |
tree | 2f8a0996fe269f79e86d6336e4520d3278b442ed /source3/libsmb | |
parent | 7e42174792298c8815acd1ebf34c357aff0de7c3 (diff) | |
download | samba-6ddfc68e0496dc41f8c9a022a0b04a2066b43c9d.tar.gz samba-6ddfc68e0496dc41f8c9a022a0b04a2066b43c9d.tar.bz2 samba-6ddfc68e0496dc41f8c9a022a0b04a2066b43c9d.zip |
sys_select added one more argument (read, write selectors).
(This used to be commit e4d92ff9dfc51735e6932748f66a7c20b2c1cb6a)
Diffstat (limited to 'source3/libsmb')
-rw-r--r-- | source3/libsmb/clientgen.c | 72 | ||||
-rw-r--r-- | source3/libsmb/nmblib.c | 2 | ||||
-rw-r--r-- | source3/libsmb/smbencrypt.c | 102 |
3 files changed, 71 insertions, 105 deletions
diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c index 06fa97df0c..f3bd08895d 100644 --- a/source3/libsmb/clientgen.c +++ b/source3/libsmb/clientgen.c @@ -918,9 +918,11 @@ BOOL cli_session_setup_x(struct cli_state *cli, } static BOOL cli_calc_session_pwds(struct cli_state *cli, + char *myhostname, char *pword, char *ntpword, char *pass, int *passlen, char *ntpass, int *ntpasslen, + char *sess_key, BOOL ntlmv2) { BOOL ntpass_ok = ntpass != NULL && ntpasslen != NULL; @@ -998,59 +1000,23 @@ static BOOL cli_calc_session_pwds(struct cli_state *cli, } else if (ntpasslen != NULL) { - /* passlen != 0, ntpasslen != 0 && server supports encryption */ - if (ntlmv2) + if (cli->use_ntlmv2 != False) { - /* plain-text password requesting to be encrypted */ - uchar *srv_key = (uchar *)cli->cryptkey; - uchar nt_owf[16]; - uchar kr[16]; - HMACMD5Context ctx; - - SMBgenclientchals(cli->lm_cli_chal, - cli->nt_cli_chal, - &cli->nt_cli_chal_len, - cli->calling.name, - cli->usr.domain); - - nt_owf_gen(pword, nt_owf); - ntv2_owf_gen(nt_owf, cli->usr.user_name, cli->usr.domain, kr); - - /* lm # */ - memcpy(pword, cli->lm_cli_chal, 8); - SMBOWFencrypt_ntv2(kr, - srv_key, 8, - cli->lm_cli_chal, 8, - &pword[8]); - *passlen = 24; - - /* nt # */ - memcpy(ntpword, cli->lm_cli_chal, cli->nt_cli_chal_len); - SMBOWFencrypt_ntv2(kr, - srv_key, 8, - cli->nt_cli_chal, cli->nt_cli_chal_len, - &ntpword[cli->nt_cli_chal_len]); - *ntpasslen = cli->nt_cli_chal_len + 16; - - hmac_md5_init_limK_to_64(kr, 16, &ctx); - hmac_md5_update(cli->nt_cli_chal, cli->nt_cli_chal_len, - &ctx); - hmac_md5_final(cli->sess_key, &ctx); -#if DEBUG_PASSWORD - DEBUG(100,("session key:\n")); - dump_data(100, cli->sess_key, sizeof(cli->sess_key)); -#endif - + DEBUG(10,("cli_establish_connection: NTLMv2\n")); + pwd_make_lm_nt_owf2(&(cli->usr.pwd), cli->cryptkey, + cli->usr.user_name, myhostname, + cli->usr.domain); } else { - /* plain-text password requesting to be encrypted */ - uchar *key = (uchar *)cli->cryptkey; - SMBencrypt ((uchar *)pass , key,(uchar *)pword ); - SMBNTencrypt((uchar *)ntpass, key,(uchar *)ntpword); - *passlen = 24; - *ntpasslen = 24; + DEBUG(10,("cli_establish_connection: NTLMv1\n")); + pwd_make_lm_nt_owf(&(cli->usr.pwd), cli->cryptkey); } + + pwd_get_lm_nt_owf(&(cli->usr.pwd), pass, ntpass, + ntpasslen, sess_key); + + *passlen = 24; } return True; } @@ -1059,7 +1025,7 @@ static BOOL cli_calc_session_pwds(struct cli_state *cli, send a session setup ****************************************************************************/ BOOL cli_session_setup(struct cli_state *cli, - char *user, + char *myhostname, char *user, char *pass, int passlen, char *ntpass, int ntpasslen, char *user_domain) @@ -1073,9 +1039,10 @@ BOOL cli_session_setup(struct cli_state *cli, fstrcpy(cli->usr.user_name, user); - return cli_calc_session_pwds(cli, pword, ntpword, + return cli_calc_session_pwds(cli, myhostname, pword, ntpword, pass, &passlen, - ntpass, &ntpasslen, cli->use_ntlmv2) && + ntpass, &ntpasslen, cli->sess_key, + cli->use_ntlmv2) && cli_session_setup_x(cli, user, pass, passlen, ntpass, ntpasslen, user_domain); } @@ -3238,7 +3205,8 @@ BOOL cli_establish_connection(struct cli_state *cli, } /* attempt clear-text session */ - if (!cli_session_setup(cli, cli->usr.user_name, + if (!cli_session_setup(cli, calling->name, + cli->usr.user_name, passwd, pass_len, ntpasswd, ntpass_len, cli->usr.domain)) diff --git a/source3/libsmb/nmblib.c b/source3/libsmb/nmblib.c index 9dca4731ad..ba951a809a 100644 --- a/source3/libsmb/nmblib.c +++ b/source3/libsmb/nmblib.c @@ -908,7 +908,7 @@ struct packet_struct *receive_packet(int fd,enum packet_type type,int t) timeout.tv_sec = t/1000; timeout.tv_usec = 1000*(t%1000); - sys_select(fd+1,&fds,&timeout); + sys_select(fd+1,&fds,NULL, &timeout); if (FD_ISSET(fd,&fds)) return(read_packet(fd,type)); diff --git a/source3/libsmb/smbencrypt.c b/source3/libsmb/smbencrypt.c index ace6cdc300..34e6f43975 100644 --- a/source3/libsmb/smbencrypt.c +++ b/source3/libsmb/smbencrypt.c @@ -24,17 +24,15 @@ extern int DEBUGLEVEL; -#include "byteorder.h" - /* 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) +void SMBencrypt(uchar *pwrd, uchar *c8, uchar *p24) { uchar p21[21]; - lm_owf_gen(passwd, p21); + lm_owf_gen(pwrd, p21); SMBOWFencrypt(p21, c8, p24); #ifdef DEBUG_PASSWORD @@ -45,13 +43,13 @@ void SMBencrypt(uchar *passwd, uchar *c8, uchar *p24) #endif } -void SMBNTencrypt(uchar *passwd, uchar *c8, uchar *p24) +void SMBNTencrypt(uchar *pwrd, uchar *c8, uchar *p24) { uchar p21[21]; memset(p21,'\0',21); - nt_owf_gen(passwd, p21); + nt_owf_gen(pwrd, p21); SMBOWFencrypt(p21, c8, p24); #ifdef DEBUG_PASSWORD @@ -114,17 +112,17 @@ static int _my_mbstowcs(int16 *dst, const uchar *src, int len) * Creates the MD4 Hash of the users password in NT UNICODE. */ -void E_md4hash(uchar *passwd, uchar *p16) +void E_md4hash(uchar *pwrd, uchar *p16) { int len; int16 wpwd[129]; /* Password cannot be longer than 128 characters */ - len = strlen((char *)passwd); + len = strlen((char *)pwrd); if(len > 128) len = 128; /* Password must be converted to NT unicode */ - _my_mbstowcs(wpwd, passwd, len); + _my_mbstowcs(wpwd, pwrd, len); wpwd[len] = 0; /* Ensure string is null terminated */ /* Calculate length in bytes */ len = _my_wcslen(wpwd) * sizeof(int16); @@ -135,107 +133,107 @@ void E_md4hash(uchar *passwd, uchar *p16) /* Does the LM owf of a user's password */ void lm_owf_genW(const UNISTR2 *pwd, uchar p16[16]) { - char passwd[15]; + char pwrd[15]; - memset(passwd,'\0',15); + memset(pwrd,'\0',15); if (pwd != NULL) { - unistr2_to_ascii( passwd, pwd, sizeof(passwd)-1); + unistr2_to_ascii( pwrd, pwd, sizeof(pwrd)-1); } /* Mangle the passwords into Lanman format */ - passwd[14] = '\0'; - strupper(passwd); + pwrd[14] = '\0'; + strupper(pwrd); /* Calculate the SMB (lanman) hash functions of the password */ memset(p16, '\0', 16); - E_P16((uchar *) passwd, (uchar *)p16); + E_P16((uchar *) pwrd, (uchar *)p16); #ifdef DEBUG_PASSWORD DEBUG(100,("nt_lm_owf_gen: pwd, lm#\n")); - dump_data(120, passwd, strlen(passwd)); + dump_data(120, pwrd, strlen(pwrd)); dump_data(100, p16, 16); #endif /* clear out local copy of user's password (just being paranoid). */ - bzero(passwd, sizeof(passwd)); + bzero(pwrd, sizeof(pwrd)); } /* Does the LM owf of a user's password */ void lm_owf_gen(const char *pwd, uchar p16[16]) { - char passwd[15]; + char pwrd[15]; - memset(passwd,'\0',15); + memset(pwrd,'\0',15); if (pwd != NULL) { - safe_strcpy( passwd, pwd, sizeof(passwd)-1); + safe_strcpy( pwrd, pwd, sizeof(pwrd)-1); } /* Mangle the passwords into Lanman format */ - passwd[14] = '\0'; - strupper(passwd); + pwrd[14] = '\0'; + strupper(pwrd); /* Calculate the SMB (lanman) hash functions of the password */ memset(p16, '\0', 16); - E_P16((uchar *) passwd, (uchar *)p16); + E_P16((uchar *) pwrd, (uchar *)p16); #ifdef DEBUG_PASSWORD DEBUG(100,("nt_lm_owf_gen: pwd, lm#\n")); - dump_data(120, passwd, strlen(passwd)); + dump_data(120, pwrd, strlen(pwrd)); dump_data(100, p16, 16); #endif /* clear out local copy of user's password (just being paranoid). */ - bzero(passwd, sizeof(passwd)); + bzero(pwrd, sizeof(pwrd)); } /* Does both the NT and LM owfs of a user's password */ void nt_owf_genW(const UNISTR2 *pwd, uchar nt_p16[16]) { - UNISTR2 passwd; + UNISTR2 pwrd; - memset(&passwd,'\0',sizeof(passwd)); + memset(&pwrd,'\0',sizeof(pwrd)); if (pwd != NULL) { - copy_unistr2(&passwd, pwd); + copy_unistr2(&pwrd, pwd); } /* Calculate the MD4 hash (NT compatible) of the password */ memset(nt_p16, '\0', 16); - mdfour(nt_p16, (unsigned char *)passwd.buffer, passwd.uni_str_len * 2); + mdfour(nt_p16, (unsigned char *)pwrd.buffer, pwrd.uni_str_len * 2); #ifdef DEBUG_PASSWORD DEBUG(100,("nt_owf_gen: pwd, nt#\n")); - dump_data(120, (const char*)passwd.buffer, passwd.uni_str_len * 2); + dump_data(120, (const char*)pwrd.buffer, pwrd.uni_str_len * 2); dump_data(100, nt_p16, 16); #endif /* clear out local copy of user's password (just being paranoid). */ - memset(&passwd, 0, sizeof(passwd)); + memset(&pwrd, 0, sizeof(pwrd)); } /* Does both the NT and LM owfs of a user's password */ void nt_owf_gen(const char *pwd, uchar nt_p16[16]) { - char passwd[130]; + char pwrd[130]; - memset(passwd,'\0',130); + memset(pwrd,'\0',130); if (pwd != NULL) { - safe_strcpy( passwd, pwd, sizeof(passwd)-1); + safe_strcpy( pwrd, pwd, sizeof(pwrd)-1); } /* Calculate the MD4 hash (NT compatible) of the password */ memset(nt_p16, '\0', 16); - E_md4hash((uchar *)passwd, nt_p16); + E_md4hash((uchar *)pwrd, nt_p16); #ifdef DEBUG_PASSWORD DEBUG(100,("nt_owf_gen: pwd, nt#\n")); - dump_data(120, passwd, strlen(passwd)); + dump_data(120, pwrd, strlen(pwrd)); dump_data(100, nt_p16, 16); #endif /* clear out local copy of user's password (just being paranoid). */ - bzero(passwd, sizeof(passwd)); + bzero(pwrd, sizeof(pwrd)); } /* Does both the NT and LM owfs of a user's UNICODE password */ @@ -253,13 +251,13 @@ void nt_lm_owf_gen(const char *pwd, uchar nt_p16[16], uchar lm_p16[16]) } /* Does the des encryption from the NT or LM MD4 hash. */ -void SMBOWFencrypt(uchar passwd[16], uchar *c8, uchar p24[24]) +void SMBOWFencrypt(uchar pwrd[16], uchar *c8, uchar p24[24]) { uchar p21[21]; memset(p21,'\0',21); - memcpy(p21, passwd, 16); + memcpy(p21, pwrd, 16); E_P24(p21, c8, p24); } @@ -391,12 +389,12 @@ void ntv2_owf_gen(const uchar owf[16], } /* Does the des encryption from the FIRST 8 BYTES of the NT or LM MD4 hash. */ -void NTLMSSPOWFencrypt(uchar passwd[8], uchar *ntlmchalresp, uchar p24[24]) +void NTLMSSPOWFencrypt(uchar pwrd[8], uchar *ntlmchalresp, uchar p24[24]) { uchar p21[21]; memset(p21,'\0',21); - memcpy(p21, passwd, 8); + memcpy(p21, pwrd, 8); memset(p21 + 8, 0xbd, 8); E_P24(p21, ntlmchalresp, p24); @@ -408,13 +406,13 @@ void NTLMSSPOWFencrypt(uchar passwd[8], uchar *ntlmchalresp, uchar p24[24]) #endif } -BOOL make_oem_passwd_hash(char data[516], const char *passwd, uchar old_pw_hash[16], BOOL unicode) +BOOL make_oem_passwd_hash(char data[516], const char *pwrd, uchar old_pw_hash[16], BOOL unicode) { - int new_pw_len = strlen(passwd) * (unicode ? 2 : 1); + int new_pw_len = strlen(pwrd) * (unicode ? 2 : 1); if (new_pw_len > 512) { - DEBUG(0,("make_oem_passwd_hash: new password is too long.\n")); + DEBUG(0,("make_oem_pwrd_hash: new password is too long.\n")); return False; } @@ -427,16 +425,16 @@ BOOL make_oem_passwd_hash(char data[516], const char *passwd, uchar old_pw_hash[ generate_random_buffer((unsigned char *)data, 516, False); if (unicode) { - ascii_to_unibuf(&data[512 - new_pw_len], passwd, new_pw_len); + ascii_to_unibuf(&data[512 - new_pw_len], pwrd, new_pw_len); } else { - fstrcpy( &data[512 - new_pw_len], passwd); + fstrcpy( &data[512 - new_pw_len], pwrd); } SIVAL(data, 512, new_pw_len); #ifdef DEBUG_PASSWORD - DEBUG(100,("make_oem_passwd_hash\n")); + DEBUG(100,("make_oem_pwrd_hash\n")); dump_data(100, data, 516); #endif SamOEMhash( (unsigned char *)data, (unsigned char *)old_pw_hash, True); @@ -518,8 +516,8 @@ void create_ntlmssp_resp(struct pwd_info *pwd, /*********************************************************** decode a password buffer ************************************************************/ -BOOL decode_pw_buffer(const char buffer[516], char *new_passwd, - int new_passwd_size, uint32 *new_pw_len) +BOOL decode_pw_buffer(const char buffer[516], char *new_pwrd, + int new_pwrd_size, uint32 *new_pw_len) { /* * The length of the new password is in the last 4 bytes of @@ -532,14 +530,14 @@ BOOL decode_pw_buffer(const char buffer[516], char *new_passwd, dump_data(100, buffer, 516); #endif - if ((*new_pw_len) < 0 || (*new_pw_len) > new_passwd_size - 1) + if ((*new_pw_len) < 0 || (*new_pw_len) > new_pwrd_size - 1) { DEBUG(0,("check_oem_password: incorrect password length (%d).\n", (*new_pw_len))); return False; } - memcpy(new_passwd, &buffer[512-(*new_pw_len)], (*new_pw_len)); - new_passwd[(*new_pw_len)] = '\0'; + memcpy(new_pwrd, &buffer[512-(*new_pw_len)], (*new_pw_len)); + new_pwrd[(*new_pw_len)] = '\0'; return True; } |