diff options
author | Andrew Tridgell <tridge@samba.org> | 2004-10-08 08:13:00 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:59:39 -0500 |
commit | 7d32679e9683c81aca538f0267684332a28a286f (patch) | |
tree | 445aecfad24e8dab1fe7a200904a712212fa7091 /source4/libcli/util/smbencrypt.c | |
parent | 48f960ab47707ca24898834da4da440d1f7fb0d9 (diff) | |
download | samba-7d32679e9683c81aca538f0267684332a28a286f.tar.gz samba-7d32679e9683c81aca538f0267684332a28a286f.tar.bz2 samba-7d32679e9683c81aca538f0267684332a28a286f.zip |
r2857: this commit gets rid of smb_ucs2_t, wpstring and fpstring, plus lots of associated functions.
The motivation for this change was to avoid having to convert to/from
ucs2 strings for so many operations. Doing that was slow, used many
static buffers, and was also incorrect as it didn't cope properly with
unicode codepoints above 65536 (which could not be represented
correctly as smb_ucs2_t chars)
The two core functions that allowed this change are next_codepoint()
and push_codepoint(). These functions allow you to correctly walk a
arbitrary multi-byte string a character at a time without converting
the whole string to ucs2.
While doing this cleanup I also fixed several ucs2 string handling
bugs. See the commit for details.
The following code (which counts the number of occuraces of 'c' in a
string) shows how to use the new interface:
size_t count_chars(const char *s, char c)
{
size_t count = 0;
while (*s) {
size_t size;
codepoint_t c2 = next_codepoint(s, &size);
if (c2 == c) count++;
s += size;
}
return count;
}
(This used to be commit 814881f0e50019196b3aa9fbe4aeadbb98172040)
Diffstat (limited to 'source4/libcli/util/smbencrypt.c')
-rw-r--r-- | source4/libcli/util/smbencrypt.c | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/source4/libcli/util/smbencrypt.c b/source4/libcli/util/smbencrypt.c index f0dba16a5a..1089c3a4cf 100644 --- a/source4/libcli/util/smbencrypt.c +++ b/source4/libcli/util/smbencrypt.c @@ -61,17 +61,15 @@ BOOL SMBencrypt(const char *passwd, const uint8_t *c8, uint8_t p24[24]) void E_md4hash(const char *passwd, uint8_t p16[16]) { int len; - smb_ucs2_t *wpwd; - - TALLOC_CTX *mem_ctx = talloc_init("E_md4hash"); - SMB_ASSERT(mem_ctx); + void *wpwd; - len = push_ucs2_talloc(mem_ctx, &wpwd, passwd); + len = push_ucs2_talloc(NULL, &wpwd, passwd); SMB_ASSERT(len >= 2); len -= 2; - mdfour(p16, (uint8_t *)wpwd, len); - talloc_free(mem_ctx); + mdfour(p16, wpwd, len); + + talloc_free(wpwd); } /** @@ -109,9 +107,8 @@ BOOL ntv2_owf_gen(const uint8_t owf[16], BOOL upper_case_domain, /* Transform the domain into UPPER case */ uint8_t kr_buf[16]) { - smb_ucs2_t *user; - smb_ucs2_t *domain; - + void *user; + void *domain; size_t user_byte_len; size_t domain_byte_len; @@ -121,6 +118,20 @@ BOOL ntv2_owf_gen(const uint8_t owf[16], return False; } + user_in = strupper_talloc(mem_ctx, user_in); + if (user_in == NULL) { + talloc_free(mem_ctx); + return False; + } + + if (upper_case_domain) { + domain_in = strupper_talloc(mem_ctx, domain_in); + if (domain_in == NULL) { + talloc_free(mem_ctx); + return False; + } + } + user_byte_len = push_ucs2_talloc(mem_ctx, &user, user_in); if (user_byte_len == (ssize_t)-1) { DEBUG(0, ("push_uss2_talloc() for user returned -1 (probably talloc() failure)\n")); @@ -135,11 +146,6 @@ BOOL ntv2_owf_gen(const uint8_t owf[16], return False; } - strupper_w(user); - - if (upper_case_domain) - strupper_w(domain); - SMB_ASSERT(user_byte_len >= 2); SMB_ASSERT(domain_byte_len >= 2); @@ -148,14 +154,14 @@ BOOL ntv2_owf_gen(const uint8_t owf[16], domain_byte_len = domain_byte_len - 2; hmac_md5_init_limK_to_64(owf, 16, &ctx); - hmac_md5_update((const uint8_t *)user, user_byte_len, &ctx); - hmac_md5_update((const uint8_t *)domain, domain_byte_len, &ctx); + hmac_md5_update(user, user_byte_len, &ctx); + hmac_md5_update(domain, domain_byte_len, &ctx); hmac_md5_final(kr_buf, &ctx); #ifdef DEBUG_PASSWORD DEBUG(100, ("ntv2_owf_gen: user, domain, owfkey, kr\n")); - dump_data(100, (const char *)user, user_byte_len); - dump_data(100, (const char *)domain, domain_byte_len); + dump_data(100, user, user_byte_len); + dump_data(100, domain, domain_byte_len); dump_data(100, owf, 16); dump_data(100, kr_buf, 16); #endif |