# HG changeset patch # User Daniel Atallah # Date 1189646722 0 # Node ID 6dcab2412c229db7f8e16767719cbece4310b555 # Parent 3023e0ba2fa686d6f5fc8b263c52fe85ee7a7f05 This is parts 1 and 2 of patch #2910 from Vladimir (thecrux) to improve NTLM proxy handling. Specifically, it specifies that we're using Unicode strings and uses the hostname of the local machine instead of incorrectly using the proxy server's hostname for authentication. References #2910. diff -r 3023e0ba2fa6 -r 6dcab2412c22 libpurple/ntlm.c --- a/libpurple/ntlm.c Wed Sep 12 20:32:09 2007 +0000 +++ b/libpurple/ntlm.c Thu Sep 13 01:25:22 2007 +0000 @@ -131,7 +131,7 @@ tmsg->protocol[6] = 'P'; tmsg->protocol[7] = '\0'; tmsg->type = 0x00000001; - tmsg->flags = 0x0000b202; + tmsg->flags = 0x0000b203; tmsg->dom_len1 = tmsg->dom_len2 = domainlen; tmsg->dom_off = sizeof(struct type1_message) + hostnamelen; tmsg->host_len1 = tmsg->host_len2 = hostnamelen; @@ -286,7 +286,7 @@ tmsg->sess_len1 = tmsg->sess_len2 = 0x0010; } - tmsg->flags = 0x00008200; + tmsg->flags = 0x00008201; tmp = (char *)tmsg + sizeof(struct type3_message); diff -r 3023e0ba2fa6 -r 6dcab2412c22 libpurple/proxy.c --- a/libpurple/proxy.c Wed Sep 12 20:32:09 2007 +0000 +++ b/libpurple/proxy.c Thu Sep 13 01:25:22 2007 +0000 @@ -668,6 +668,16 @@ if (status == 407 /* Proxy Auth */) { gchar *ntlm; + char hostname[256]; + int ret; + + ret = gethostname(hostname, sizeof(hostname)); + hostname[sizeof(hostname) - 1] = '\0'; + if (ret < 0 || hostname[0] == '\0') { + purple_debug_warning("proxy", "gethostname() failed -- is your hostname set?"); + strcpy(hostname, "localhost"); + } + ntlm = g_strrstr((const gchar *)connect_data->read_buffer, "Proxy-Authenticate: NTLM "); if (ntlm != NULL) @@ -679,6 +689,7 @@ gchar *username; gchar *request; gchar *response; + username = strchr(domain, '\\'); if (username == NULL) { @@ -694,7 +705,7 @@ nonce = purple_ntlm_parse_type2(ntlm, NULL); response = purple_ntlm_gen_type3(username, (gchar*) purple_proxy_info_get_password(connect_data->gpi), - (gchar*) purple_proxy_info_get_host(connect_data->gpi), + hostname, domain, nonce, NULL); username--; *username = '\\'; @@ -745,9 +756,7 @@ sizeof(request) - request_len, "Proxy-Authorization: NTLM %s\r\n" "Proxy-Connection: Keep-Alive\r\n\r\n", - purple_ntlm_gen_type1( - (gchar*) purple_proxy_info_get_host(connect_data->gpi), - domain)); + purple_ntlm_gen_type1(hostname, domain)); *username = '\\'; purple_input_remove(connect_data->inpa); @@ -832,6 +841,14 @@ if (purple_proxy_info_get_username(connect_data->gpi) != NULL) { char *t1, *t2; + char hostname[256]; + + ret = gethostname(hostname, sizeof(hostname)); + hostname[sizeof(hostname) - 1] = '\0'; + if (ret < 0 || hostname[0] == '\0') { + purple_debug_warning("proxy", "gethostname() failed -- is your hostname set?"); + strcpy(hostname, "localhost"); + } t1 = g_strdup_printf("%s:%s", purple_proxy_info_get_username(connect_data->gpi), @@ -844,8 +861,7 @@ "Proxy-Authorization: Basic %s\r\n" "Proxy-Authorization: NTLM %s\r\n" "Proxy-Connection: Keep-Alive\r\n", - t2, purple_ntlm_gen_type1( - purple_proxy_info_get_host(connect_data->gpi), "")); + t2, purple_ntlm_gen_type1(hostname, "")); g_free(t2); }