[evolution-data-server/email-factory] Infer NTLM domain from username; don't assume it matches the server's domain (cherry picked from com



commit fdeb213ca25e0b0057506e95fccc570ab0f022d6
Author: David Woodhouse <David Woodhouse intel com>
Date:   Fri Apr 1 21:53:04 2011 +0100

    Infer NTLM domain from username; don't assume it matches the server's domain
    (cherry picked from commit d331e6f04c69b306d21b9ce6ca530dd6d3e1f213)

 camel/camel-sasl-ntlm.c |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)
---
diff --git a/camel/camel-sasl-ntlm.c b/camel/camel-sasl-ntlm.c
index 0d9a837..6d2313a 100644
--- a/camel/camel-sasl-ntlm.c
+++ b/camel/camel-sasl-ntlm.c
@@ -666,8 +666,9 @@ sasl_ntlm_challenge (CamelSasl *sasl,
 {
 	CamelService *service;
 	GByteArray *ret;
+	gchar *user;
 	guchar nonce[8], hash[21], lm_resp[24], nt_resp[24];
-	GString *domain;
+	GString *domain = NULL;
 
 	service = camel_sasl_get_service (sasl);
 
@@ -717,8 +718,18 @@ sasl_ntlm_challenge (CamelSasl *sasl,
 		ntlm_calc_response (hash, nonce, nt_resp);
 	}
 
-	/* FIXME: The server domain doesn't always match the user's domain */
-	domain = ntlm_get_string (token, NTLM_CHALLENGE_DOMAIN_OFFSET);
+	/* If a domain is supplied as part of the username, use it */
+	user = strchr (service->url->user, '\\');
+	if (user) {
+		domain = g_string_new_len (service->url->user,
+					   user - service->url->user);
+		user++;
+	} else
+		user = service->url->user;
+
+	/* Otherwise, fall back to the domain of the server, if possible */
+	if (domain == NULL)
+		domain = ntlm_get_string (token, NTLM_CHALLENGE_DOMAIN_OFFSET);
 	if (domain == NULL)
 		goto fail;
 
@@ -736,8 +747,7 @@ sasl_ntlm_challenge (CamelSasl *sasl,
 	ntlm_set_string (ret, NTLM_RESPONSE_DOMAIN_OFFSET,
 			 domain->str, domain->len);
 	ntlm_set_string (ret, NTLM_RESPONSE_USER_OFFSET,
-			 service->url->user,
-			 strlen (service->url->user));
+			 user, strlen (user));
 	ntlm_set_string (ret, NTLM_RESPONSE_HOST_OFFSET,
 			 "UNKNOWN", sizeof ("UNKNOWN") - 1);
 	ntlm_set_string (ret, NTLM_RESPONSE_LM_RESP_OFFSET,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]