diff libpurple/proxy.c @ 19781:6dcab2412c22

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.
author Daniel Atallah <daniel.atallah@gmail.com>
date Thu, 13 Sep 2007 01:25:22 +0000
parents 44b4e8bd759b
children 1846fd2da2b4
line wrap: on
line diff
--- 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);
 	}