From bf431fbedb8119b392b071f903b63e0f9671ee49 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 12 Apr 2011 11:29:59 +1000 Subject: libcli/auth Use convert_string_error to check LM hash calculation. This allows us to know if the LM hash was built correctly or not. NOTE: talloc_tos() is not available in the common code at this time. Andrew Bartlett Signed-off-by: Andrew Tridgell --- libcli/auth/smbencrypt.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'libcli') diff --git a/libcli/auth/smbencrypt.c b/libcli/auth/smbencrypt.c index 825739ac4b..cbb2eb5c9c 100644 --- a/libcli/auth/smbencrypt.c +++ b/libcli/auth/smbencrypt.c @@ -116,22 +116,37 @@ void E_md5hash(const uint8_t salt[16], const uint8_t nthash[16], uint8_t hash_ou bool E_deshash(const char *passwd, uint8_t p16[16]) { - bool ret = true; - char dospwd[256]; - ZERO_STRUCT(dospwd); + bool ret; + uint8_t dospwd[14]; - /* Password must be converted to DOS charset - null terminated, uppercase. */ - push_string(dospwd, passwd, sizeof(dospwd), STR_ASCII|STR_UPPER|STR_TERMINATE); + size_t converted_size; - /* Only the first 14 chars are considered, password need not be null terminated. */ - E_P16((const uint8_t *)dospwd, p16); + char *tmpbuf; - if (strlen(dospwd) > 14) { - ret = false; + ZERO_STRUCT(dospwd); + + tmpbuf = strupper_talloc(NULL, passwd); + if (tmpbuf == NULL) { + /* Too many callers don't check this result, we need to fill in the buffer with something */ + safe_strcpy((char *)dospwd, passwd, sizeof(dospwd)-1); + E_P16(dospwd, p16); + return false; } ZERO_STRUCT(dospwd); + ret = convert_string_error(CH_UNIX, CH_DOS, tmpbuf, strlen(tmpbuf), dospwd, sizeof(dospwd), &converted_size); + talloc_free(tmpbuf); + + /* Only the first 14 chars are considered, password need not + * be null terminated. We do this in the error and success + * case to avoid returning a fixed 'password' buffer, but + * callers should not use it when E_deshash returns false */ + + E_P16((const uint8_t *)dospwd, p16); + + ZERO_STRUCT(dospwd); + return ret; } -- cgit