Blob Blame History Raw
diff -up evolution-data-server-3.8.5/addressbook/backends/webdav/e-book-backend-webdav.c.claim-missing-username evolution-data-server-3.8.5/addressbook/backends/webdav/e-book-backend-webdav.c
--- evolution-data-server-3.8.5/addressbook/backends/webdav/e-book-backend-webdav.c.claim-missing-username	2013-07-28 15:54:19.000000000 +0200
+++ evolution-data-server-3.8.5/addressbook/backends/webdav/e-book-backend-webdav.c	2014-10-08 15:33:51.567159217 +0200
@@ -1089,7 +1089,9 @@ download_contacts (EBookBackendWebdav *w
 	message = send_propfind (webdav, cancellable);
 	status  = message->status_code;
 
-	if (status == 401 || status == 407) {
+	if (status == SOUP_STATUS_UNAUTHORIZED ||
+	    status == SOUP_STATUS_PROXY_UNAUTHORIZED ||
+	    status == SOUP_STATUS_FORBIDDEN) {
 		g_object_unref (message);
 		g_free (new_ctag);
 		if (book_view)
@@ -1422,9 +1424,10 @@ soup_authenticate (SoupSession *session,
 	if (retrying)
 		return;
 
-	if (priv->username != NULL) {
+	if (!priv->username || !*priv->username)
+		soup_message_set_status (message, SOUP_STATUS_FORBIDDEN);
+	else
 		soup_auth_authenticate (auth, priv->username, priv->password);
-	}
 }
 
 static void
@@ -1445,6 +1448,57 @@ proxy_settings_changed (EProxy *proxy,
 	g_object_set (priv->session, SOUP_SESSION_PROXY_URI, proxy_uri, NULL);
 }
 
+static gboolean
+book_backend_webdav_test_can_connect (EBookBackendWebdav *webdav,
+				      GCancellable *cancellable,
+				      GError **error)
+{
+	SoupMessage *message;
+	gboolean res = FALSE;
+
+	g_return_val_if_fail (E_IS_BOOK_BACKEND_WEBDAV (webdav), FALSE);
+
+	/* Send a PROPFIND to test whether user/password is correct. */
+	message = send_propfind (webdav, cancellable);
+
+	switch (message->status_code) {
+		case SOUP_STATUS_OK:
+		case SOUP_STATUS_MULTI_STATUS:
+			res = TRUE;
+			break;
+
+		case SOUP_STATUS_UNAUTHORIZED:
+		case SOUP_STATUS_PROXY_UNAUTHORIZED:
+			g_free (webdav->priv->username);
+			webdav->priv->username = NULL;
+			g_free (webdav->priv->password);
+			webdav->priv->password = NULL;
+			g_set_error_literal (error, E_CLIENT_ERROR, E_CLIENT_ERROR_AUTHENTICATION_FAILED,
+				e_client_error_to_string (E_CLIENT_ERROR_AUTHENTICATION_FAILED));
+			break;
+
+		case SOUP_STATUS_FORBIDDEN:
+			g_free (webdav->priv->username);
+			webdav->priv->username = NULL;
+			g_free (webdav->priv->password);
+			webdav->priv->password = NULL;
+			g_set_error_literal (error, E_CLIENT_ERROR, E_CLIENT_ERROR_AUTHENTICATION_REQUIRED,
+				e_client_error_to_string (E_CLIENT_ERROR_AUTHENTICATION_REQUIRED));
+			break;
+
+		default:
+			g_set_error (
+				error, SOUP_HTTP_ERROR,
+				message->status_code,
+				"%s", message->reason_phrase);
+			break;
+	}
+
+	g_object_unref (message);
+
+	return res;
+}
+
 static void
 e_book_backend_webdav_open (EBookBackend *backend,
                             EDataBook *book,
@@ -1546,6 +1600,8 @@ e_book_backend_webdav_open (EBookBackend
 			E_BACKEND (backend),
 			E_SOURCE_AUTHENTICATOR (backend),
 			cancellable, &error);
+	else
+		book_backend_webdav_test_can_connect (webdav, cancellable, &error);
 
 	soup_uri_free (suri);
 
@@ -1647,8 +1703,8 @@ book_backend_webdav_try_password_sync (E
 	ESourceAuthentication *auth_extension;
 	ESourceAuthenticationResult result;
 	ESource *source;
-	SoupMessage *message;
 	const gchar *extension_name;
+	GError *local_error = NULL;
 
 	source = e_backend_get_source (E_BACKEND (authenticator));
 	extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
@@ -1658,35 +1714,16 @@ book_backend_webdav_try_password_sync (E
 		e_source_authentication_dup_user (auth_extension);
 	webdav->priv->password = g_strdup (password->str);
 
-	/* Send a PROPFIND to test whether user/password is correct. */
-	message = send_propfind (webdav, cancellable);
-
-	switch (message->status_code) {
-		case SOUP_STATUS_OK:
-		case SOUP_STATUS_MULTI_STATUS:
-			result = E_SOURCE_AUTHENTICATION_ACCEPTED;
-			break;
-
-		case SOUP_STATUS_UNAUTHORIZED:
-		case SOUP_STATUS_PROXY_UNAUTHORIZED:  /* XXX really? */
-			g_free (webdav->priv->username);
-			webdav->priv->username = NULL;
-			g_free (webdav->priv->password);
-			webdav->priv->password = NULL;
-			result = E_SOURCE_AUTHENTICATION_REJECTED;
-			break;
-
-		default:
-			g_set_error (
-				error, SOUP_HTTP_ERROR,
-				message->status_code,
-				"%s", message->reason_phrase);
-			result = E_SOURCE_AUTHENTICATION_ERROR;
-			break;
+	if (book_backend_webdav_test_can_connect (webdav, cancellable, &local_error)) {
+		result = E_SOURCE_AUTHENTICATION_ACCEPTED;
+	} else if (g_error_matches (local_error, E_CLIENT_ERROR, E_CLIENT_ERROR_AUTHENTICATION_FAILED)) {
+		result = E_SOURCE_AUTHENTICATION_REJECTED;
+		g_clear_error (&local_error);
+	} else {
+		result = E_SOURCE_AUTHENTICATION_ERROR;
+		g_propagate_error (error, local_error);
 	}
 
-	g_object_unref (message);
-
 	return result;
 }
 
diff -up evolution-data-server-3.8.5/calendar/backends/caldav/e-cal-backend-caldav.c.claim-missing-username evolution-data-server-3.8.5/calendar/backends/caldav/e-cal-backend-caldav.c
--- evolution-data-server-3.8.5/calendar/backends/caldav/e-cal-backend-caldav.c.claim-missing-username	2014-10-08 15:33:51.561159274 +0200
+++ evolution-data-server-3.8.5/calendar/backends/caldav/e-cal-backend-caldav.c	2014-10-08 15:33:51.568159208 +0200
@@ -565,18 +565,18 @@ status_code_to_result (SoupMessage *mess
 			priv->read_only = TRUE;
 		}
 		break;
-	case 404:
+	case SOUP_STATUS_NOT_FOUND:
 		if (is_opening)
 			g_propagate_error (perror, EDC_ERROR (NoSuchCal));
 		else
 			g_propagate_error (perror, EDC_ERROR (ObjectNotFound));
 		break;
 
-	case 403:
-		g_propagate_error (perror, EDC_ERROR (AuthenticationFailed));
+	case SOUP_STATUS_FORBIDDEN:
+		g_propagate_error (perror, EDC_ERROR (AuthenticationRequired));
 		break;
 
-	case 401:
+	case SOUP_STATUS_UNAUTHORIZED:
 		if (priv && priv->auth_required)
 			g_propagate_error (perror, EDC_ERROR (AuthenticationFailed));
 		else
@@ -1012,7 +1012,10 @@ soup_authenticate (SoupSession *session,
 		gchar *user;
 
 		user = e_source_authentication_dup_user (auth_extension);
-		soup_auth_authenticate (auth, user, cbdav->priv->password);
+		if (!user || !*user)
+			soup_message_set_status (msg, SOUP_STATUS_FORBIDDEN);
+		else
+			soup_auth_authenticate (auth, user, cbdav->priv->password);
 		g_free (user);
 	}
 }
@@ -2931,7 +2934,7 @@ caldav_do_open (ECalBackendSync *backend
 
 		open_calendar (cbdav, cancellable, &local_error);
 
-		if (g_error_matches (local_error, E_DATA_CAL_ERROR, AuthenticationRequired) || g_error_matches (local_error, E_DATA_CAL_ERROR, AuthenticationFailed)) {
+		if (g_error_matches (local_error, E_DATA_CAL_ERROR, AuthenticationFailed)) {
 			g_clear_error (&local_error);
 			caldav_authenticate (
 				cbdav, FALSE, cancellable, perror);
diff -up evolution-data-server-3.8.5/calendar/backends/http/e-cal-backend-http.c.claim-missing-username evolution-data-server-3.8.5/calendar/backends/http/e-cal-backend-http.c
--- evolution-data-server-3.8.5/calendar/backends/http/e-cal-backend-http.c.claim-missing-username	2013-08-11 00:00:52.000000000 +0200
+++ evolution-data-server-3.8.5/calendar/backends/http/e-cal-backend-http.c	2014-10-08 15:33:51.568159208 +0200
@@ -91,6 +91,10 @@ soup_authenticate (SoupSession *session,
 	ESourceAuthentication *auth_extension;
 	ESource *source;
 	const gchar *extension_name;
+	gchar *user;
+
+	if (retrying)
+		return;
 
 	cbhttp = E_CAL_BACKEND_HTTP (data);
 
@@ -98,13 +102,14 @@ soup_authenticate (SoupSession *session,
 	extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
 	auth_extension = e_source_get_extension (source, extension_name);
 
-	if (!retrying && cbhttp->priv->password != NULL) {
-		gchar *user;
+	user = e_source_authentication_dup_user (auth_extension);
 
-		user = e_source_authentication_dup_user (auth_extension);
+	if (!user || !*user)
+		soup_message_set_status (msg, SOUP_STATUS_FORBIDDEN);
+	else if (cbhttp->priv->password != NULL)
 		soup_auth_authenticate (auth, user, cbhttp->priv->password);
-		g_free (user);
-	}
+
+	g_free (user);
 }
 
 /* Dispose handler for the file backend */
@@ -790,6 +795,9 @@ begin_retrieval_cb (GIOSchedulerJob *job
 			E_BACKEND (backend),
 			E_SOURCE_AUTHENTICATOR (backend),
 			cancellable, &error);
+	} else if (g_error_matches (error, SOUP_HTTP_ERROR, SOUP_STATUS_FORBIDDEN)) {
+		g_clear_error (&error);
+		error = EDC_ERROR (AuthenticationRequired);
 	}
 
 	backend->priv->is_loading = FALSE;
@@ -948,8 +956,12 @@ e_cal_backend_http_open (ECalBackendSync
 				registry, source,
 				E_SOURCE_AUTHENTICATOR (backend),
 				cancellable, &local_error);
+		} else if (g_error_matches (local_error, SOUP_HTTP_ERROR, SOUP_STATUS_FORBIDDEN)) {
+			g_clear_error (&local_error);
+			local_error = EDC_ERROR (AuthenticationRequired);
 		}
 
+
 		if (local_error != NULL)
 			g_propagate_error (perror, g_error_copy (local_error));
 	}