[evolution-mapi/gnome-2-28] Bug #576738 - Crash on Authenticate with backslash in user name



commit 4bb696164ea4487bb22aabf8bf804f99d285640b
Author: Milan Crha <mcrha redhat com>
Date:   Tue Feb 23 18:04:50 2010 +0100

    Bug #576738 - Crash on Authenticate with backslash in user name

 .../exchange-mapi-account-listener.c               |    4 ++--
 .../exchange-mapi-account-setup.c                  |   13 ++++++++++++-
 src/libexchangemapi/exchange-mapi-connection.c     |    2 +-
 src/libexchangemapi/exchange-mapi-utils.c          |   17 +++++++++++++++++
 src/libexchangemapi/exchange-mapi-utils.h          |    2 ++
 5 files changed, 34 insertions(+), 4 deletions(-)
---
diff --git a/src/account-setup-eplugin/exchange-mapi-account-listener.c b/src/account-setup-eplugin/exchange-mapi-account-listener.c
index ab0a12a..1091cb4 100644
--- a/src/account-setup-eplugin/exchange-mapi-account-listener.c
+++ b/src/account-setup-eplugin/exchange-mapi-account-listener.c
@@ -686,7 +686,7 @@ mapi_account_changed (EAccountList *account_listener, EAccount *account)
 			gchar *profname = NULL, *uri = NULL; 
 			ExchangeMAPIAccountListener *config_listener = exchange_mapi_accounts_peek_config_listener();
 
-			profname = g_strdup_printf("%s %s", new_url->user, camel_url_get_param (new_url, "domain"));
+			profname = exchange_mapi_util_profile_name (new_url->user, camel_url_get_param (new_url, "domain"));
 			camel_url_set_param(new_url, "profile", profname);
 			g_free (profname);
 
@@ -719,7 +719,7 @@ mapi_account_changed (EAccountList *account_listener, EAccount *account)
 				gchar *profname = NULL, *uri = NULL; 
 				ExchangeMAPIAccountListener *config_listener = exchange_mapi_accounts_peek_config_listener();
 
-				profname = g_strdup_printf("%s %s", new_url->user, camel_url_get_param (new_url, "domain"));
+				profname = exchange_mapi_util_profile_name (new_url->user, camel_url_get_param (new_url, "domain"));
 				camel_url_set_param(new_url, "profile", profname);
 				g_free (profname);
 
diff --git a/src/account-setup-eplugin/exchange-mapi-account-setup.c b/src/account-setup-eplugin/exchange-mapi-account-setup.c
index 810b1fc..862c827 100644
--- a/src/account-setup-eplugin/exchange-mapi-account-setup.c
+++ b/src/account-setup-eplugin/exchange-mapi-account-setup.c
@@ -190,6 +190,17 @@ validate_credentials (GtkWidget *widget, EConfig *config)
 	url = camel_url_new (e_account_get_string (target_account->account, E_ACCOUNT_SOURCE_URL), NULL);
 	domain_name = camel_url_get_param (url, "domain");
 
+	/* Silently remove domain part from a user name when user enters it as such.
+	   This change will be visible in the UI on new edit open. */
+	if (url->user && strchr (url->user, '\\')) {
+		gchar *tmp, *at;
+
+		at = strrchr (url->user, '\\') + 1;
+		tmp = g_strdup (at);
+		camel_url_set_user (url, tmp);
+		g_free (tmp);
+	}
+
 	if (!url->user || !*url->user || !url->host || !*url->host || !domain_name || !*domain_name) {
 		e_notice (NULL, GTK_MESSAGE_ERROR, "%s", _("Server, username and domain name cannot be empty. Please fill them with correct values."));
 		return;
@@ -219,7 +230,7 @@ validate_credentials (GtkWidget *widget, EConfig *config)
 			/* Things are successful */
 			gchar *profname = NULL, *uri = NULL; 
 
-			profname = g_strdup_printf("%s %s", url->user, domain_name);
+			profname = exchange_mapi_util_profile_name (url->user, domain_name);
 			camel_url_set_param(url, "profile", profname);
 			g_free (profname);
 
diff --git a/src/libexchangemapi/exchange-mapi-connection.c b/src/libexchangemapi/exchange-mapi-connection.c
index c8556b7..d70ac9f 100644
--- a/src/libexchangemapi/exchange-mapi-connection.c
+++ b/src/libexchangemapi/exchange-mapi-connection.c
@@ -3073,7 +3073,7 @@ exchange_mapi_create_profile (const char *username, const char *password, const
 
 	LOCK ();
 
-	profname = g_strdup_printf("%s %s", username, domain);
+	profname = exchange_mapi_util_profile_name (username, domain);
 
 	if (!ensure_mapi_init_called ()) {
 		UNLOCK ();
diff --git a/src/libexchangemapi/exchange-mapi-utils.c b/src/libexchangemapi/exchange-mapi-utils.c
index 86cdb24..e355338 100644
--- a/src/libexchangemapi/exchange-mapi-utils.c
+++ b/src/libexchangemapi/exchange-mapi-utils.c
@@ -593,3 +593,20 @@ exchange_crlf_to_lf (const char *in)
 	return out;
 }
 
+/**
+ * exchange_mapi_util_profile_name:
+ * @username: User name of the profile
+ * @domain: Domain name of the profile
+ *
+ * Constructs profile name from given @username and @domain and
+ * returns it as a newly allocated string.
+ **/
+gchar *
+exchange_mapi_util_profile_name (const gchar *username, const gchar *domain)
+{
+	gchar *res;
+
+	res = g_strdup_printf ("%s %s", username, domain);
+
+	return g_strcanon (res, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@", '_');
+}
diff --git a/src/libexchangemapi/exchange-mapi-utils.h b/src/libexchangemapi/exchange-mapi-utils.h
index 4f82711..680b825 100644
--- a/src/libexchangemapi/exchange-mapi-utils.h
+++ b/src/libexchangemapi/exchange-mapi-utils.h
@@ -72,5 +72,7 @@ exchange_lf_to_crlf (const char *in);
 char *
 exchange_crlf_to_lf (const char *in);
 
+gchar *exchange_mapi_util_profile_name (const gchar *username, const gchar *domain);
+
 #endif
 



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