Mercurial > pidgin.yaz
changeset 13698:6bee2e80e42c
[gaim-migrate @ 16101]
Additional constification, add some comments, remove some
superfluous whitespace, and changed gchar to guint8 in a
few places.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 28 Apr 2006 03:52:09 +0000 |
parents | 89ceef5203ac |
children | c8043f9a4ce2 |
files | src/ntlm.c src/ntlm.h src/protocols/simple/simple.c src/proxy.c |
diffstat | 4 files changed, 31 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ntlm.c Fri Apr 28 03:39:14 2006 +0000 +++ b/src/ntlm.c Fri Apr 28 03:52:09 2006 +0000 @@ -140,11 +140,11 @@ return gaim_base64_encode((guchar*)msg, sizeof(struct type1_message) + strlen(hostname) + strlen(domain)); } -gchar * +guint8 * gaim_ntlm_parse_type2(const gchar *type2, guint32 *flags) { gsize retlen; - static gchar nonce[8]; + static guint8 nonce[8]; struct type2_message *tmsg = (struct type2_message*)gaim_base64_decode((char*)type2, &retlen); memcpy(nonce, tmsg->nonce, 8); if(flags) *flags = tmsg->flags; @@ -169,7 +169,7 @@ * helper function for gaim cipher.c */ static void -des_ecb_encrypt(char *plaintext, char *result, char *key) +des_ecb_encrypt(const guint8 *plaintext, char *result, char *key) { GaimCipher *cipher; GaimCipherContext *context; @@ -188,17 +188,17 @@ * bytes are stored in the results array. */ static void -calc_resp(unsigned char *keys, unsigned char *plaintext, unsigned char *results) +calc_resp(unsigned char *keys, const guint8 *plaintext, unsigned char *results) { guchar key[8]; setup_des_key(keys, (char*)key); - des_ecb_encrypt((char*)plaintext, (char*)results, (char*)key); + des_ecb_encrypt(plaintext, (char*)results, (char*)key); setup_des_key(keys+7, (char*)key); - des_ecb_encrypt((char*)plaintext, (char*)(results+8), (char*)key); + des_ecb_encrypt(plaintext, (char*)(results+8), (char*)key); setup_des_key(keys+14, (char*)key); - des_ecb_encrypt((char*)plaintext, (char*)(results+16), (char*)key); + des_ecb_encrypt(plaintext, (char*)(results+16), (char*)key); } static void @@ -215,12 +215,11 @@ } gchar * -gaim_ntlm_gen_type3(const gchar *username, const gchar *passw, const gchar *hostname, const gchar *domain, gchar *nonce, guint32 *flags) +gaim_ntlm_gen_type3(const gchar *username, const gchar *passw, const gchar *hostname, const gchar *domain, const guint8 *nonce, guint32 *flags) { char lm_pw[14]; unsigned char lm_hpw[21]; char sesskey[16]; - gchar *sessionnonce = nonce; gchar key[8]; int msglen = sizeof(struct type3_message)+ strlen(domain) + strlen(username)+ @@ -284,13 +283,13 @@ lm_pw[idx] = 0; setup_des_key((unsigned char*)lm_pw, (char*)key); - des_ecb_encrypt((char*)magic, (char*)lm_hpw, (char*)key); + des_ecb_encrypt(magic, (char*)lm_hpw, (char*)key); setup_des_key((unsigned char*)(lm_pw+7), (char*)key); - des_ecb_encrypt((char*)magic, (char*)lm_hpw+8, (char*)key); + des_ecb_encrypt(magic, (char*)lm_hpw+8, (char*)key); memset(lm_hpw+16, 0, 5); - calc_resp(lm_hpw, (guchar*)sessionnonce, lm_resp); + calc_resp(lm_hpw, nonce, lm_resp); /* NTLM */ lennt = strlen(passw); @@ -309,7 +308,7 @@ memset(nt_hpw+16, 0, 5); - calc_resp(nt_hpw, (guchar*)sessionnonce, nt_resp); + calc_resp(nt_hpw, nonce, nt_resp); memcpy(tmp, lm_resp, 0x18); tmp += 0x18; memcpy(tmp, nt_resp, 0x18);
--- a/src/ntlm.h Fri Apr 28 03:39:14 2006 +0000 +++ b/src/ntlm.h Fri Apr 28 03:52:09 2006 +0000 @@ -1,13 +1,13 @@ /** * @file ntlm.h - * + * * gaim * * Copyright (C) 2005, Thomas Butter <butter@uni-mannheim.de> * - * ntlm structs are taken from NTLM description on - * http://www.innovation.ch/java/ntlm.html - * + * ntlm structs are taken from NTLM description on + * http://www.innovation.ch/java/ntlm.html + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -31,7 +31,8 @@ * * @param hostname Your hostname * @param domain The domain to authenticate to - * @return base64 encoded string to send to the server. has to be freed with g_free + * @return base64 encoded string to send to the server. This should + * be g_free'd by the caller. */ gchar *gaim_ntlm_gen_type1(const gchar *hostname, const gchar *domain); @@ -39,9 +40,10 @@ * Parses the ntlm type 2 message * * @param type2 String containing the base64 encoded type2 message - * @return The nonce for use in message type3 + * @return The nonce for use in message type3. This is a statically + * allocated 8 byte binary string. */ -gchar *gaim_ntlm_parse_type2(const gchar *type2, guint32 *flags); +guint8 *gaim_ntlm_parse_type2(const gchar *type2, guint32 *flags); /** * Generates a type3 message @@ -52,8 +54,9 @@ * @param domain The domain to authenticate against * @param nonce The nonce returned by gaim_ntlm_parse_type2 * @param flags Pointer to the flags returned by gaim_ntlm_parse_type2 - * @return A base64 encoded type3 message + * @return A base64 encoded type3 message. This should be g_free'd by + * the caller. */ -gchar *gaim_ntlm_gen_type3(const gchar *username, const gchar *passw, const gchar *hostname, const gchar *domain, gchar *nonce, guint32 *flags); +gchar *gaim_ntlm_gen_type3(const gchar *username, const gchar *passw, const gchar *hostname, const gchar *domain, const guint8 *nonce, guint32 *flags); #endif /* _GAIM_NTLM_H */
--- a/src/protocols/simple/simple.c Fri Apr 28 03:39:14 2006 +0000 +++ b/src/protocols/simple/simple.c Fri Apr 28 03:52:09 2006 +0000 @@ -278,7 +278,8 @@ return ret; } else if(auth->type == 2) { /* NTLM */ if(auth->nc == 3 && auth->nonce) { - ret = gaim_ntlm_gen_type3(authuser, sip->password, "gaim", authdomain, auth->nonce, &auth->flags); + /* TODO: Don't hardcode "gaim" as the hostname */ + ret = gaim_ntlm_gen_type3(authuser, sip->password, "gaim", authdomain, (const guint8 *)auth->nonce, &auth->flags); tmp = g_strdup_printf("NTLM qop=\"auth\", opaque=\"%s\", realm=\"%s\", targetname=\"%s\", gssapi-data=\"%s\"\r\n", auth->opaque, auth->realm, auth->target, ret); g_free(ret); return tmp; @@ -339,7 +340,7 @@ while(parts[i]) { gaim_debug_info("simple", "parts[i] %s\n", parts[i]); if((tmp = parse_attribute("gssapi-data=\"", parts[i]))) { - auth->nonce = g_strdup(gaim_ntlm_parse_type2(tmp, &auth->flags)); + auth->nonce = g_memdup(gaim_ntlm_parse_type2(tmp, &auth->flags), 8); g_free(tmp); } if((tmp = parse_attribute("targetname=\"",
--- a/src/proxy.c Fri Apr 28 03:39:14 2006 +0000 +++ b/src/proxy.c Fri Apr 28 03:52:09 2006 +0000 @@ -1207,7 +1207,8 @@ if(status == 407 /* Proxy Auth */) { gchar *ntlm; if((ntlm = g_strrstr((const gchar *)phb->read_buffer, "Proxy-Authenticate: NTLM "))) { /* Check for Type-2 */ - gchar *nonce = ntlm; + gchar *tmp = ntlm; + guint8 *nonce; gchar *domain = (gchar*)gaim_proxy_info_get_username(phb->gpi); gchar *username; gchar *request; @@ -1230,8 +1231,8 @@ *username = '\0'; username++; ntlm += strlen("Proxy-Authenticate: NTLM "); - while(*nonce != '\r' && *nonce != '\0') nonce ++; - *nonce = '\0'; + while(*tmp != '\r' && *tmp != '\0') tmp++; + *tmp = '\0'; nonce = gaim_ntlm_parse_type2(ntlm, NULL); response = gaim_ntlm_gen_type3(username, (gchar*) gaim_proxy_info_get_password(phb->gpi),