summary refs log tree commit diff
path: root/src/settings/plugins/ifnet
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2016-03-30 00:56:30 +0200
committerMichael Biebl <biebl@debian.org>2016-03-30 00:56:30 +0200
commitd9c99a29a0d3384c9c3d2adce430f5cb1134ab6a (patch)
treefa41baf72753961e71dd8d5bdbe2b89c9109e4f1 /src/settings/plugins/ifnet
parentc2de0d98ba39e0a1a970d066fd19be786092f376 (diff)
Imported Upstream version 1.1.92 upstream/1.1.92
Diffstat (limited to 'src/settings/plugins/ifnet')
-rw-r--r--src/settings/plugins/ifnet/connection_parser.c166
-rw-r--r--src/settings/plugins/ifnet/net_parser.c64
-rw-r--r--src/settings/plugins/ifnet/net_utils.c17
-rw-r--r--src/settings/plugins/ifnet/nm-ifnet-connection.c15
-rw-r--r--src/settings/plugins/ifnet/tests/test-ifnet.c18
-rw-r--r--src/settings/plugins/ifnet/wpa_parser.c45
6 files changed, 154 insertions, 171 deletions
diff --git a/src/settings/plugins/ifnet/connection_parser.c b/src/settings/plugins/ifnet/connection_parser.c
index bf8b9a42..d9ff97dc 100644
--- a/src/settings/plugins/ifnet/connection_parser.c
+++ b/src/settings/plugins/ifnet/connection_parser.c
@@ -362,11 +362,17 @@ eap_peap_reader (const char *eap_method,
 		}
 
 		pos = strchr (*iter, '=');
-		pos++;
-		lower = g_ascii_strdown (pos, -1);
-		g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, lower,
-			      NULL);
-		g_free (lower);
+		if (pos && *pos) {
+			pos++;
+			lower = g_ascii_strdown (pos, -1);
+			g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, lower,
+				      NULL);
+			g_free (lower);
+		} else {
+			g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
+				     "No IEEE_8021X_INNER_AUTH_METHOD.");
+			goto done;
+		}
 		break;
 	}
 
@@ -513,7 +519,7 @@ read_mac_address (const char *conn_name, const char **mac, GError **error)
 	return TRUE;
 }
 
-static void
+static gboolean
 make_wired_connection_setting (NMConnection *connection,
                                const char *conn_name,
                                GError **error)
@@ -538,22 +544,21 @@ make_wired_connection_setting (NMConnection *connection,
 				      (guint32) mtu, NULL);
 	}
 
-	if (read_mac_address (conn_name, &mac, error)) {
-		if (mac) {
-			g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS,
-				      mac, NULL);
-		}
-	} else {
+	if (!read_mac_address (conn_name, &mac, error)) {
 		g_object_unref (s_wired);
-		s_wired = NULL;
+		return FALSE;
 	}
-	if (s_wired)
-		nm_connection_add_setting (connection, NM_SETTING (s_wired));
+
+	if (mac)
+		g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL);
+	nm_connection_add_setting (connection, NM_SETTING (s_wired));
+
+	return TRUE;
 }
 
 /* add NM_SETTING_IP_CONFIG_DHCP_HOSTNAME,
  * NM_SETTING_IP_CONFIG_DHCP_CLIENT_ID in future*/
-static void
+static gboolean
 make_ip4_setting (NMConnection *connection,
                   const char *conn_name,
                   GError **error)
@@ -578,7 +583,7 @@ make_ip4_setting (NMConnection *connection,
 			g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
 						 "Unknown config for %s", conn_name);
 			g_object_unref (ip4_setting);
-			return;
+			return FALSE;
 		}
 		if (strstr (method, "dhcp"))
 			g_object_set (ip4_setting,
@@ -591,19 +596,19 @@ make_ip4_setting (NMConnection *connection,
 						  NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL,
 						  NM_SETTING_IP_CONFIG_NEVER_DEFAULT, FALSE, NULL);
 			nm_connection_add_setting (connection, NM_SETTING (ip4_setting));
-			return;
+			return TRUE;
 		} else if (strstr (method, "shared")) {
 			g_object_set (ip4_setting,
 						  NM_SETTING_IP_CONFIG_METHOD,
 						  NM_SETTING_IP4_CONFIG_METHOD_SHARED,
 						  NM_SETTING_IP_CONFIG_NEVER_DEFAULT, FALSE, NULL);
 			nm_connection_add_setting (connection, NM_SETTING (ip4_setting));
-			return;
+			return TRUE;
 		} else {
 			g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
 						 "Unknown config for %s", conn_name);
 			g_object_unref (ip4_setting);
-			return;
+			return FALSE;
 		}
 		nm_log_info (LOGD_SETTINGS, "Using %s method for %s", method, conn_name);
 	}else {
@@ -613,7 +618,7 @@ make_ip4_setting (NMConnection *connection,
 				     "Ifnet plugin: can't aquire ip configuration for %s",
 				     conn_name);
 			g_object_unref (ip4_setting);
-			return;
+			return FALSE;
 		}
 		/************** add all ip settings to the connection**********/
 		while (iblock) {
@@ -735,9 +740,11 @@ make_ip4_setting (NMConnection *connection,
 
 	/* Finally add setting to connection */
 	nm_connection_add_setting (connection, NM_SETTING (ip4_setting));
+
+	return TRUE;
 }
 
-static void
+static gboolean
 make_ip6_setting (NMConnection *connection,
                   const char *conn_name,
                   GError **error)
@@ -875,12 +882,12 @@ make_ip6_setting (NMConnection *connection,
 
 done:
 	nm_connection_add_setting (connection, NM_SETTING (s_ip6));
-	return;
+	return TRUE;
 
 error:
 	g_object_unref (s_ip6);
 	nm_log_warn (LOGD_SETTINGS, "    Ignore IPv6 for %s", conn_name);
-	return;
+	return FALSE;
 }
 
 static NMSetting *
@@ -1018,14 +1025,6 @@ make_leap_setting (const char *ssid, GError **error)
 	wsec =
 	    NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ());
 
-	value = wpa_get_value (ssid, "key_mgmt");
-	if (!value || strcmp (value, "IEEE8021X"))
-		goto error;	/* Not LEAP */
-
-	value = wpa_get_value (ssid, "eap");
-	if (!value || strcasecmp (value, "LEAP"))
-		goto error;	/* Not LEAP */
-
 	value = wpa_get_value (ssid, "password");
 	if (value && strlen (value))
 		g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD,
@@ -1444,12 +1443,6 @@ make_wpa_setting (const char *ssid,
 	if (value)
 		adhoc = strcmp (value, "1") == 0 ? TRUE : FALSE;
 
-	value = wpa_get_value (ssid, "key_mgmt");
-	/* Not WPA or Dynamic WEP */
-	if (!value)
-		goto error;
-	if (strcmp (value, "WPA-PSK") && strcmp (value, "WPA-EAP"))
-		goto error;
 	/* Pairwise and Group ciphers */
 	fill_wpa_ciphers (ssid, wsec, FALSE, adhoc);
 	fill_wpa_ciphers (ssid, wsec, TRUE, adhoc);
@@ -1464,6 +1457,7 @@ make_wpa_setting (const char *ssid,
 
 	}
 
+	value = wpa_get_value (ssid, "key_mgmt");
 	if (!strcmp (value, "WPA-PSK")) {
 		char *psk = parse_wpa_psk (wpa_get_value (ssid, "psk"), error);
 
@@ -1522,8 +1516,6 @@ make_wireless_security_setting (const char *conn_name,
 	g_return_val_if_fail (conn_name != NULL
 			      && strcmp (ifnet_get_data (conn_name, "type"),
 					 "ppp") != 0, NULL);
-	if (!wpa_get_value (conn_name, "ssid"))
-		return NULL;
 	nm_log_info (LOGD_SETTINGS, "updating wireless security settings (%s).", conn_name);
 
 	ssid = conn_name;
@@ -1531,19 +1523,22 @@ make_wireless_security_setting (const char *conn_name,
 	if (value)
 		adhoc = strcmp (value, "1") == 0 ? TRUE : FALSE;
 
-	if (!adhoc) {
-		wsec = make_leap_setting (ssid, error);
-		if (error && *error)
-			goto error;
-	}
-	if (!wsec) {
+	value = wpa_get_value (ssid, "key_mgmt");
+	if (!adhoc && g_strcmp0 (value, "IEEE8021X") == 0) {
+		value = wpa_get_value (ssid, "eap");
+		if (value && strcasecmp (value, "LEAP") == 0) {
+			wsec = make_leap_setting (ssid, error);
+			if (wsec == NULL)
+				goto error;
+		}
+	} else if (g_strcmp0 (value, "WPA-PSK") == 0 || g_strcmp0 (value, "WPA-EAP") == 0) {
 		wsec = make_wpa_setting (ssid, basepath, s_8021x, error);
-		if (error && *error)
+		if (wsec == NULL)
 			goto error;
 	}
 	if (!wsec) {
 		wsec = make_wep_setting (ssid, error);
-		if (error && *error)
+		if (wsec == NULL)
 			goto error;
 	}
 
@@ -1559,7 +1554,7 @@ error:
 }
 
 /* Currently only support username and password */
-static void
+static gboolean
 make_pppoe_connection_setting (NMConnection *connection,
                                const char *conn_name,
                                GError **error)
@@ -1575,7 +1570,7 @@ make_pppoe_connection_setting (NMConnection *connection,
 	if (!value) {
 		g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
 			     "ppp requires at lease a username");
-		return;
+		return FALSE;
 	}
 	g_object_set (s_pppoe, NM_SETTING_PPPOE_USERNAME, value, NULL);
 
@@ -1591,6 +1586,8 @@ make_pppoe_connection_setting (NMConnection *connection,
 	/* PPP setting */
 	s_ppp = (NMSettingPpp *) nm_setting_ppp_new ();
 	nm_connection_add_setting (connection, NM_SETTING (s_ppp));
+
+	return TRUE;
 }
 
 NMConnection *
@@ -1644,18 +1641,13 @@ ifnet_update_connection_from_config_block (const char *conn_name,
 	if (!strcmp (NM_SETTING_WIRED_SETTING_NAME, type)
 	    || !strcmp (NM_SETTING_PPPOE_SETTING_NAME, type)) {
 		/* wired setting */
-		make_wired_connection_setting (connection, conn_name, error);
-		if (error && *error) {
-			nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message);
+		if (!make_wired_connection_setting (connection, conn_name, error))
 			goto error;
-		}
+
 		/* pppoe setting */
-		if (!strcmp (NM_SETTING_PPPOE_SETTING_NAME, type))
-			make_pppoe_connection_setting (connection, conn_name,
-						       error);
-		if (error && *error) {
-			nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message);
-			goto error;
+		if (!strcmp (NM_SETTING_PPPOE_SETTING_NAME, type)) {
+			if (!make_pppoe_connection_setting (connection, conn_name, error))
+				goto error;
 		}
 	} else if (!strcmp (NM_SETTING_WIRELESS_SETTING_NAME, type)) {
 		/* wireless setting */
@@ -1666,50 +1658,33 @@ ifnet_update_connection_from_config_block (const char *conn_name,
 			goto error;
 		nm_connection_add_setting (connection, wireless_setting);
 
-		if (error && *error) {
-			nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message);
-			goto error;
-		}
-
 		/* wireless security setting */
-		wsec = make_wireless_security_setting (conn_name, basepath, &s_8021x, error);
-		if (wsec) {
+		if (wpa_get_value (conn_name, "ssid")) {
+			wsec = make_wireless_security_setting (conn_name, basepath, &s_8021x, error);
+			if (!wsec)
+				goto error;
 			nm_connection_add_setting (connection, NM_SETTING (wsec));
 			if (s_8021x)
 				nm_connection_add_setting (connection, NM_SETTING (s_8021x));
 		}
-
-		if (error && *error) {
-			nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message);
-			goto error;
-		}
-
 	} else
 		goto error;
 
 	/* IPv4 setting */
-	make_ip4_setting (connection, conn_name, error);
-	if (error && *error) {
-		nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message);
+	if (!make_ip4_setting (connection, conn_name, error))
 		goto error;
-	}
 
 	/* IPv6 setting */
-	make_ip6_setting (connection, conn_name, error);
-	if (error && *error) {
-		nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message);
+	if (!make_ip6_setting (connection, conn_name, error))
 		goto error;
-	}
 
-	success = nm_connection_verify (connection, error);
-	if (error && *error)
-		nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message);
-	else
+	if (nm_connection_verify (connection, error)) {
 		nm_log_info (LOGD_SETTINGS, "Connection verified %s:%d", conn_name, success);
-	if (!success)
+	} else {
 		goto error;
-	return connection;
+	}
 
+	return connection;
 error:
 	g_object_unref (connection);
 	return NULL;
@@ -2493,8 +2468,8 @@ write_ip4_setting (NMConnection *connection, const char *conn_name, GError **err
 	return success;
 }
 
-static gboolean
-write_route6_file (NMSettingIPConfig *s_ip6, const char *conn_name, GError **error)
+static void
+write_route6_file (NMSettingIPConfig *s_ip6, const char *conn_name)
 {
 	NMIPRoute *route;
 	const char *next_hop;
@@ -2502,11 +2477,10 @@ write_route6_file (NMSettingIPConfig *s_ip6, const char *conn_name, GError **err
 	GString *routes_string;
 	const char *old_routes;
 
-	g_return_val_if_fail (s_ip6 != NULL, FALSE);
+	g_return_if_fail (s_ip6 != NULL);
 	num = nm_setting_ip_config_get_num_routes (s_ip6);
-	if (num == 0) {
-		return TRUE;
-	}
+	if (num == 0)
+		return;
 
 	old_routes = ifnet_get_data (conn_name, "routes");
 	routes_string = g_string_new (old_routes);
@@ -2527,8 +2501,6 @@ write_route6_file (NMSettingIPConfig *s_ip6, const char *conn_name, GError **err
 	if (num > 0)
 		ifnet_set_data (conn_name, "routes", routes_string->str);
 	g_string_free (routes_string, TRUE);
-
-	return TRUE;
 }
 
 static gboolean
@@ -2645,9 +2617,7 @@ write_ip6_setting (NMConnection *connection, const char *conn_name, GError **err
 		g_string_free (searches, TRUE);
 	}
 
-	write_route6_file (s_ip6, conn_name, error);
-	if (error && *error)
-		return FALSE;
+	write_route6_file (s_ip6, conn_name);
 	return TRUE;
 }
 
diff --git a/src/settings/plugins/ifnet/net_parser.c b/src/settings/plugins/ifnet/net_parser.c
index cad34f06..6e1061c6 100644
--- a/src/settings/plugins/ifnet/net_parser.c
+++ b/src/settings/plugins/ifnet/net_parser.c
@@ -552,7 +552,7 @@ gboolean
 ifnet_flush_to_file (const char *config_file, gchar **out_backup)
 {
 	GIOChannel *channel;
-	GError **error = NULL;
+	GError *error = NULL;
 	gpointer key, value, name, network;
 	GHashTableIter iter, iter_network;
 	GList *list_iter;
@@ -579,32 +579,36 @@ ifnet_flush_to_file (const char *config_file, gchar **out_backup)
 	g_io_channel_write_chars (channel,
 				  "#Generated by NetworkManager\n"
 				  "###### Global Configuration ######\n",
-				  -1, &bytes_written, error);
+				  -1, &bytes_written, &error);
+	if (error)
+		goto done;
+
 	/* Writing global data */
 	while (g_hash_table_iter_next (&iter, &key, &value)) {
 		out_line =
 		    g_strdup_printf ("%s=\"%s\"\n", (gchar *) key, (gchar *) value);
 		g_io_channel_write_chars (channel, out_line, -1,
-					  &bytes_written, error);
-		if (bytes_written == 0 || (error && *error))
-			break;
+					  &bytes_written, &error);
+		if (bytes_written == 0 || error)
+			goto done;
 		g_free (out_line);
 	}
-	if (error && *error) {
-		nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message);
-		goto done;
-	}
 
 	/* Writing connection data */
 	g_io_channel_write_chars (channel,
 				  "\n###### Connection Configuration ######\n",
-				  -1, &bytes_written, error);
+				  -1, &bytes_written, &error);
+	if (error)
+		goto done;
+
 	g_hash_table_iter_init (&iter, conn_table);
 	while (g_hash_table_iter_next (&iter, &name, &network)) {
 		g_hash_table_iter_init (&iter_network, (GHashTable *) network);
 		g_io_channel_write_chars (channel,
 					  "#----------------------------------\n",
-					  -1, &bytes_written, error);
+					  -1, &bytes_written, &error);
+		if (error)
+			goto done;
 
 		while (g_hash_table_iter_next (&iter_network, &key, &value)) {
 			if (!g_str_has_prefix ((gchar *) key, "name")
@@ -627,51 +631,47 @@ ifnet_flush_to_file (const char *config_file, gchar **out_backup)
 					    ("%s_%s=\"%s\"\n",
 					     (gchar *) key,
 					     (gchar *) name, (gchar *) value);
-				g_io_channel_write_chars
-				    (channel, out_line, -1,
-				     &bytes_written, error);
-				if (bytes_written == 0 || (error && *error))
-					break;
+				g_io_channel_write_chars (channel, out_line, -1, &bytes_written, &error);
+				if (bytes_written == 0 || error)
+					goto done;
 				g_free (out_line);
 			}
 		}
 	}
-	if (error && *error) {
-		nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message);
-		goto done;
-	}
 
 	/* Writing reserved functions */
 	if (functions_list) {
 		g_io_channel_write_chars (channel,
 					  "\n###### Reserved Functions ######\n",
-					  -1, &bytes_written, error);
+					  -1, &bytes_written, &error);
+		if (error)
+			goto done;
+
 		/* Writing functions */
 		for (list_iter = functions_list; list_iter;
 		     list_iter = g_list_next (list_iter)) {
 			out_line =
 			    g_strdup_printf ("%s\n", (gchar *) list_iter->data);
 			g_io_channel_write_chars (channel, out_line, -1,
-						  &bytes_written, error);
-			if (bytes_written == 0 || (error && *error))
-				break;
+						  &bytes_written, &error);
+			if (bytes_written == 0 || error)
+				goto done;
 			g_free (out_line);
 		}
-		if (error && *error) {
-			nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message);
-			goto done;
-		}
 	}
 
-	g_io_channel_flush (channel, error);
-	if (error && *error) {
-		nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message);
+	g_io_channel_flush (channel, &error);
+	if (error)
 		goto done;
-	}
 	result = TRUE;
 	net_parser_data_changed = FALSE;
 
 done:
+	if (error) {
+		nm_log_warn (LOGD_SETTINGS, "Error writing the configuration file: %s", error->message);
+		g_error_free (error);
+	}
+
 	if (result && out_backup)
 		*out_backup = backup;
 	else
diff --git a/src/settings/plugins/ifnet/net_utils.c b/src/settings/plugins/ifnet/net_utils.c
index 1944e478..bd5d65d5 100644
--- a/src/settings/plugins/ifnet/net_utils.c
+++ b/src/settings/plugins/ifnet/net_utils.c
@@ -800,18 +800,27 @@ gchar *backup_file (const gchar* target)
 {
 	GFile *source, *backup;
 	gchar* backup_path;
-	GError **error = NULL;
+	GError *error = NULL;
 
 	source = g_file_new_for_path (target);
+
+	if (!g_file_query_exists (source, NULL)) {
+		g_object_unref (source);
+		return NULL;
+	}
+
 	backup_path = g_strdup_printf ("%s.bak", target);
 	backup = g_file_new_for_path (backup_path);
 
-	g_file_copy (source, backup, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, error);
-	if (error && *error) {
-		nm_log_warn (LOGD_SETTINGS, "Backup failed: %s", (*error)->message);
+	if (!g_file_copy (source, backup, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error)) {
+		nm_log_warn (LOGD_SETTINGS, "Backup failed: %s", error->message);
 		g_free (backup_path);
 		backup_path = NULL;
+		g_error_free (error);
 	}
 
+	g_object_unref (source);
+	g_object_unref (backup);
+
 	return backup_path;
 }
diff --git a/src/settings/plugins/ifnet/nm-ifnet-connection.c b/src/settings/plugins/ifnet/nm-ifnet-connection.c
index 84515519..b661b03e 100644
--- a/src/settings/plugins/ifnet/nm-ifnet-connection.c
+++ b/src/settings/plugins/ifnet/nm-ifnet-connection.c
@@ -68,6 +68,8 @@ nm_ifnet_connection_new (NMConnection *source, const char *conn_name)
 	else {
 		tmp = ifnet_update_connection_from_config_block (conn_name, NULL, &error);
 		if (!tmp) {
+			nm_log_warn (LOGD_SETTINGS, "Could not read connection '%s': %s",
+			             conn_name, error->message);
 			g_error_free (error);
 			return NULL;
 		}
@@ -79,11 +81,14 @@ nm_ifnet_connection_new (NMConnection *source, const char *conn_name)
 	object = (GObject *) g_object_new (NM_TYPE_IFNET_CONNECTION, NULL);
 	g_assert (object);
 	NM_IFNET_CONNECTION_GET_PRIVATE (object)->conn_name = g_strdup (conn_name);
-	nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object),
-	                                         tmp,
-	                                         update_unsaved,
-	                                         NULL,
-	                                         NULL);
+	if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object),
+	                                              tmp,
+	                                              update_unsaved,
+	                                              NULL,
+	                                              NULL)) {
+		g_object_unref (object);
+		return NULL;
+	}
 	g_object_unref (tmp);
 
 	return NM_IFNET_CONNECTION (object);
diff --git a/src/settings/plugins/ifnet/tests/test-ifnet.c b/src/settings/plugins/ifnet/tests/test-ifnet.c
index c870152b..3035fdb1 100644
--- a/src/settings/plugins/ifnet/tests/test-ifnet.c
+++ b/src/settings/plugins/ifnet/tests/test-ifnet.c
@@ -134,7 +134,7 @@ test_convert_ipv4_config_block (void)
 	check_ip_block (iblock, "192.168.4.121", 24, "202.117.16.1");
 	destroy_ip_block (iblock);
 
-	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE,
 	                       "*Can't handle IPv4 address*202.117.16.1211*");
 	iblock = convert_ip4_config_block ("eth2");
 	g_test_assert_expected_messages ();
@@ -142,7 +142,7 @@ test_convert_ipv4_config_block (void)
 	check_ip_block (iblock, "192.168.4.121", 24, NULL);
 	destroy_ip_block (iblock);
 
-	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE,
 	                       "*missing netmask or prefix*");
 	iblock = convert_ip4_config_block ("eth3");
 	g_assert (iblock == NULL);
@@ -216,9 +216,9 @@ test_new_connection (void)
 	GError *error = NULL;
 	NMConnection *connection;
 
-	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE,
 	                       "*Can't handle IPv4 address*202.117.16.1211*");
-	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE,
 	                       "*Can't handle IPv6 address*202.117.16.1211*");
 	connection = ifnet_update_connection_from_config_block ("eth2", NULL, &error);
 	g_test_assert_expected_messages ();
@@ -245,7 +245,7 @@ test_new_connection (void)
 static void
 kill_backup (char **path)
 {
-	if (path) {
+	if (*path) {
 		unlink (*path);
 		g_free (*path);
 		*path = NULL;
@@ -306,9 +306,9 @@ test_add_connection (void)
 	kill_backup (&backup);
 	g_object_unref (connection);
 
-	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE,
 	                       "*Can't handle ipv4 address: brd, missing netmask or prefix*");
-	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE,
 	                       "*Can't handle ipv4 address: 202.117.16.255, missing netmask or prefix*");
 	connection = ifnet_update_connection_from_config_block ("myxjtu2", basepath, NULL);
 	g_test_assert_expected_messages ();
@@ -349,10 +349,8 @@ test_missing_config (void)
 	GError *error = NULL;
 	NMConnection *connection;
 
-	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
-	                       "*Unknown config for eth8*");
 	connection = ifnet_update_connection_from_config_block ("eth8", NULL, &error);
-	g_test_assert_expected_messages ();
+	g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION);
 	g_assert (connection == NULL && error != NULL);
 }
 
diff --git a/src/settings/plugins/ifnet/wpa_parser.c b/src/settings/plugins/ifnet/wpa_parser.c
index 501bca7a..8e2559b3 100644
--- a/src/settings/plugins/ifnet/wpa_parser.c
+++ b/src/settings/plugins/ifnet/wpa_parser.c
@@ -365,7 +365,7 @@ gboolean
 wpa_flush_to_file (const char *config_file)
 {
 	GIOChannel *channel;
-	GError **error = NULL;
+	GError *error = NULL;
 	gpointer key, value, ssid, security;
 	GHashTableIter iter, iter_security;
 	gchar *out_line;
@@ -389,25 +389,27 @@ wpa_flush_to_file (const char *config_file)
 	g_io_channel_write_chars (channel,
 				  "#Generated by NetworkManager\n"
 				  "###### Global Configuration ######\n",
-				  -1, &bytes_written, error);
+				  -1, &bytes_written, &error);
+	if (error)
+		goto done;
 
 	/* Writing global information */
 	while (g_hash_table_iter_next (&iter, &key, &value)) {
 		out_line =
 		    g_strdup_printf ("%s=%s\n", (gchar *) key, (gchar *) value);
 		g_io_channel_write_chars (channel, out_line, -1, &bytes_written,
-					  error);
-		if (bytes_written == 0 || (error && *error))
+					  &error);
+		if (bytes_written == 0 || error)
 			break;
 		g_free (out_line);
 	}
-	if (error && *error) {
-		nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message);
+	if (error)
 		goto done;
-	}
 	g_io_channel_write_chars (channel,
 				  "\n###### Security Configuration ######\n",
-				  -1, &bytes_written, error);
+				  -1, &bytes_written, &error);
+	if (error)
+		goto done;
 
 	g_hash_table_iter_init (&iter, wsec_table);
 	/* Writing security */
@@ -415,35 +417,34 @@ wpa_flush_to_file (const char *config_file)
 		g_hash_table_iter_init (&iter_security,
 					(GHashTable *) security);
 		g_io_channel_write_chars (channel, "network={\n", -1,
-					  &bytes_written, error);
+					  &bytes_written, &error);
+		if (error)
+			goto done;
 		while (g_hash_table_iter_next (&iter_security, &key, &value)) {
 			out_line =
 			    g_strdup_printf (need_quote ((gchar *) key) ?
 					     "\t%s=\"%s\"\n" : "\t%s=%s\n",
 					     (gchar *) key, (gchar *) value);
 			g_io_channel_write_chars (channel, out_line, -1,
-						  &bytes_written, error);
-			if (bytes_written == 0 || (error && *error))
-				break;
+						  &bytes_written, &error);
+			if (bytes_written == 0 || error)
+				goto done;
 			g_free (out_line);
 		}
-		g_io_channel_write_chars (channel,
-					  "}\n\n", -1, &bytes_written, error);
+		g_io_channel_write_chars (channel, "}\n\n", -1, &bytes_written, &error);
 
 	}
-	if (error && *error) {
-		nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message);
+	g_io_channel_flush (channel, &error);
+	if (error)
 		goto done;
-	}
-	g_io_channel_flush (channel, error);
 
-	if (error && *error) {
-		nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message);
-		goto done;
-	}
 	wpa_parser_data_changed = FALSE;
 	result = TRUE;
 done:
+	if (error) {
+		nm_log_warn (LOGD_SETTINGS, "Error writing WPA configuration: %s", error->message);
+		g_error_free (error);
+	}
 	g_io_channel_shutdown (channel, FALSE, NULL);
 	g_io_channel_unref (channel);
 	return result;