diff -rub samba4-17234-orig/source/libcli/auth/smbencrypt.c samba4-17234/source/libcli/auth/smbencrypt.c --- samba4-17234-orig/source/libcli/auth/smbencrypt.c 2007-03-15 10:44:16.000000000 -0500 +++ samba4-17234/source/libcli/auth/smbencrypt.c 2007-03-15 11:03:41.000000000 -0500 @@ -31,6 +31,9 @@ #include "libcli/auth/libcli_auth.h" #include "pstring.h" +#define SMB_HASH_LM 1 +#define SMB_HASH_NTLM 2 + /* This implements the X/Open SMB password encryption It takes a password ('unix' string), a 8 byte "crypt key" @@ -58,6 +61,57 @@ return ret; } +/* + Support for using LM/NTLM hashes -- jmk@foofus.net 10/2006 + Greets: Foofus, Phenfen, Omi, Fizzgig, pMonkey +*/ +void E_set_hash(int type, unsigned char hash[16]) +{ + uint l; + pstring p; + int i, j; + char HexChar; + int HexValue; + + if ( (getenv("SMBHASH")) && (strlen(getenv("SMBHASH")) == 65) ) + { + pstrcpy(p, getenv("SMBHASH")); + + for (i=0; i<16; i++) { + HexValue = 0x0; + for (j=0; j<2; j++) { + if (type == SMB_HASH_LM) + HexChar = (char)p[2*i+j]; + else + HexChar = (char)p[2*i+j+33]; + + if (HexChar > 0x39) + HexChar = HexChar | 0x20; /* convert upper case to lower */ + + if (!(((HexChar >= 0x30) && (HexChar <= 0x39))|| /* 0 - 9 */ + ((HexChar >= 0x61) && (HexChar <= 0x66)))) { /* a - f */ + fprintf(stderr, "Error invalid char (%c) for hash.\n", HexChar); + exit(1); + } + + HexChar -= 0x30; + if (HexChar > 0x09) /* HexChar is "a" - "f" */ + HexChar -= 0x27; + + HexValue = (HexValue << 4) | (char)HexChar; + } + hash[i] = (unsigned char)HexValue; + } + } + else + { + fprintf(stderr, "Error reading SMB HASH.\n"); + fprintf(stderr, "\tEx: export SMBHASH=\"_LM_HASH_:_NTLM_HASH_\"\n"); + exit(1); + } +} +/* jmk */ + /** * Creates the MD4 Hash of the users password in NT UNICODE. * @param passwd password in 'unix' charset. @@ -69,6 +123,11 @@ int len; void *wpwd; + /* Support for using NTLM hashes -- jmk@foofus.net 03/2007 */ + if ( getenv("SMBHASH") ) { + fprintf(stderr, "HASH PASS: Substituting user supplied NTLM HASH...\n"); + E_set_hash(SMB_HASH_NTLM, p16); + } else { len = push_ucs2_talloc(NULL, &wpwd, passwd); SMB_ASSERT(len >= 2); @@ -76,6 +135,7 @@ mdfour(p16, wpwd, len); talloc_free(wpwd); + } } /** @@ -92,6 +152,11 @@ fstring dospwd; ZERO_STRUCT(dospwd); + /* Support for using LM hashes -- jmk@foofus.net 10/2006 */ + if ( getenv("SMBHASH") ) { + fprintf(stderr, "HASH PASS: Substituting user supplied LM HASH...\n"); + E_set_hash(SMB_HASH_LM, p16); + } else { /* Password must be converted to DOS charset - null terminated, uppercase. */ push_string(dospwd, passwd, sizeof(dospwd), STR_ASCII|STR_UPPER|STR_TERMINATE); @@ -103,6 +168,7 @@ } ZERO_STRUCT(dospwd); + } return ret; }