summary refs log tree commit diff
path: root/libnm-util
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 /libnm-util
parentc2de0d98ba39e0a1a970d066fd19be786092f376 (diff)
Imported Upstream version 1.1.92 upstream/1.1.92
Diffstat (limited to 'libnm-util')
-rw-r--r--libnm-util/Makefile.am2
-rw-r--r--libnm-util/Makefile.in38
-rw-r--r--libnm-util/libnm-util.ver2
-rw-r--r--libnm-util/nm-connection.c82
-rw-r--r--libnm-util/nm-setting-8021x.c28
-rw-r--r--libnm-util/nm-setting-private.h6
-rw-r--r--libnm-util/nm-setting.c18
-rw-r--r--libnm-util/nm-utils.c14
8 files changed, 113 insertions, 77 deletions
diff --git a/libnm-util/Makefile.am b/libnm-util/Makefile.am
index 6e637908..e9ccdae7 100644
--- a/libnm-util/Makefile.am
+++ b/libnm-util/Makefile.am
@@ -63,6 +63,7 @@ nodist_libnm_util_include_HEADERS = \
 	nm-utils-enum-types.h
 
 libnm_util_la_private_headers = \
+	$(top_builddir)/shared/nm-shared-utils.h \
 	crypto.h			\
 	nm-dbus-glib-types.h		\
 	nm-gvaluearray-compat.h		\
@@ -71,6 +72,7 @@ libnm_util_la_private_headers = \
 	nm-utils-private.h
 
 libnm_util_la_csources = \
+	$(top_builddir)/shared/nm-shared-utils.c \
 	crypto.c			\
 	nm-connection.c			\
 	nm-param-spec-specialized.c	\
diff --git a/libnm-util/Makefile.in b/libnm-util/Makefile.in
index d6085cca..9de83a6c 100644
--- a/libnm-util/Makefile.in
+++ b/libnm-util/Makefile.in
@@ -162,23 +162,25 @@ am__DEPENDENCIES_1 =
 libnm_util_la_DEPENDENCIES = $(am__DEPENDENCIES_1) \
 	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
 	$(am__DEPENDENCIES_2) $(am__DEPENDENCIES_3)
-am__libnm_util_la_SOURCES_DIST = crypto.c nm-connection.c \
-	nm-param-spec-specialized.c nm-setting.c nm-setting-8021x.c \
-	nm-setting-adsl.c nm-setting-bluetooth.c nm-setting-bond.c \
-	nm-setting-team.c nm-setting-team-port.c nm-setting-bridge.c \
-	nm-setting-bridge-port.c nm-setting-connection.c \
-	nm-setting-dcb.c nm-setting-infiniband.c \
-	nm-setting-ip4-config.c nm-setting-vlan.c \
-	nm-setting-ip6-config.c nm-setting-ppp.c nm-setting-pppoe.c \
-	nm-setting-serial.c nm-setting-generic.c nm-setting-gsm.c \
-	nm-setting-cdma.c nm-setting-olpc-mesh.c nm-setting-wimax.c \
-	nm-setting-wired.c nm-setting-wireless.c \
+am__libnm_util_la_SOURCES_DIST =  \
+	$(top_builddir)/shared/nm-shared-utils.c crypto.c \
+	nm-connection.c nm-param-spec-specialized.c nm-setting.c \
+	nm-setting-8021x.c nm-setting-adsl.c nm-setting-bluetooth.c \
+	nm-setting-bond.c nm-setting-team.c nm-setting-team-port.c \
+	nm-setting-bridge.c nm-setting-bridge-port.c \
+	nm-setting-connection.c nm-setting-dcb.c \
+	nm-setting-infiniband.c nm-setting-ip4-config.c \
+	nm-setting-vlan.c nm-setting-ip6-config.c nm-setting-ppp.c \
+	nm-setting-pppoe.c nm-setting-serial.c nm-setting-generic.c \
+	nm-setting-gsm.c nm-setting-cdma.c nm-setting-olpc-mesh.c \
+	nm-setting-wimax.c nm-setting-wired.c nm-setting-wireless.c \
 	nm-setting-wireless-security.c nm-setting-vpn.c \
 	nm-utils-enum-types.c nm-utils.c nm-value-transforms.c \
-	crypto.h nm-dbus-glib-types.h nm-gvaluearray-compat.h \
+	$(top_builddir)/shared/nm-shared-utils.h crypto.h \
+	nm-dbus-glib-types.h nm-gvaluearray-compat.h \
 	nm-param-spec-specialized.h nm-setting-private.h \
 	nm-utils-private.h crypto_gnutls.c crypto_nss.c
-am__objects_1 = crypto.lo nm-connection.lo \
+am__objects_1 = nm-shared-utils.lo crypto.lo nm-connection.lo \
 	nm-param-spec-specialized.lo nm-setting.lo nm-setting-8021x.lo \
 	nm-setting-adsl.lo nm-setting-bluetooth.lo nm-setting-bond.lo \
 	nm-setting-team.lo nm-setting-team-port.lo \
@@ -630,6 +632,7 @@ nodist_libnm_util_include_HEADERS = \
 	nm-utils-enum-types.h
 
 libnm_util_la_private_headers = \
+	$(top_builddir)/shared/nm-shared-utils.h \
 	crypto.h			\
 	nm-dbus-glib-types.h		\
 	nm-gvaluearray-compat.h		\
@@ -638,6 +641,7 @@ libnm_util_la_private_headers = \
 	nm-utils-private.h
 
 libnm_util_la_csources = \
+	$(top_builddir)/shared/nm-shared-utils.c \
 	crypto.c			\
 	nm-connection.c			\
 	nm-param-spec-specialized.c	\
@@ -842,6 +846,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nm-setting-wireless-security.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nm-setting-wireless.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nm-setting.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nm-shared-utils.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nm-utils-enum-types.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nm-utils.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nm-value-transforms.Plo@am__quote@
@@ -867,6 +872,13 @@ distclean-compile:
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
 
+nm-shared-utils.lo: $(top_builddir)/shared/nm-shared-utils.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT nm-shared-utils.lo -MD -MP -MF $(DEPDIR)/nm-shared-utils.Tpo -c -o nm-shared-utils.lo `test -f '$(top_builddir)/shared/nm-shared-utils.c' || echo '$(srcdir)/'`$(top_builddir)/shared/nm-shared-utils.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/nm-shared-utils.Tpo $(DEPDIR)/nm-shared-utils.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$(top_builddir)/shared/nm-shared-utils.c' object='nm-shared-utils.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o nm-shared-utils.lo `test -f '$(top_builddir)/shared/nm-shared-utils.c' || echo '$(srcdir)/'`$(top_builddir)/shared/nm-shared-utils.c
+
 mostlyclean-libtool:
 	-rm -f *.lo
 
diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver
index 1ad853f5..385cdb8e 100644
--- a/libnm-util/libnm-util.ver
+++ b/libnm-util/libnm-util.ver
@@ -1,5 +1,7 @@
 {
 global:
+	_nm_connection_new_from_hash;
+	_nm_connection_replace_settings;
 	nm_connection_add_setting;
 	nm_connection_clear_secrets;
 	nm_connection_clear_secrets_with_flags;
diff --git a/libnm-util/nm-connection.c b/libnm-util/nm-connection.c
index ea791c51..51c48028 100644
--- a/libnm-util/nm-connection.c
+++ b/libnm-util/nm-connection.c
@@ -327,19 +327,30 @@ validate_permissions_type (GHashTable *hash, GError **error)
 	return TRUE;
 }
 
-static gboolean
-hash_to_connection (NMConnection *connection, GHashTable *new, GError **error)
+/**
+ * _nm_connection_replace_settings:
+ * @connection: a #NMConnection
+ * @new_settings: (element-type utf8 GLib.HashTable): a #GHashTable of settings
+ **/
+void
+_nm_connection_replace_settings (NMConnection *connection,
+                                 GHashTable *new_settings)
 {
+	NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (connection);
 	GHashTableIter iter;
 	const char *setting_name;
 	GHashTable *setting_hash;
-	gboolean changed, valid;
-	NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (connection);
+	gboolean changed;
+
+	g_return_if_fail (NM_IS_CONNECTION (connection));
+	g_return_if_fail (new_settings != NULL);
+
+	priv = NM_CONNECTION_GET_PRIVATE (connection);
 
 	if ((changed = g_hash_table_size (priv->settings) > 0))
 		g_hash_table_foreach_remove (priv->settings, _setting_release, connection);
 
-	g_hash_table_iter_init (&iter, new);
+	g_hash_table_iter_init (&iter, new_settings);
 	while (g_hash_table_iter_next (&iter, (gpointer) &setting_name, (gpointer) &setting_hash)) {
 		GType type = nm_connection_lookup_setting_type (setting_name);
 
@@ -353,10 +364,8 @@ hash_to_connection (NMConnection *connection, GHashTable *new, GError **error)
 		}
 	}
 
-	valid = nm_connection_verify (connection, error);
 	if (changed)
 		g_signal_emit (connection, signals[CHANGED], 0);
-	return valid;
 }
 
 /**
@@ -373,16 +382,15 @@ nm_connection_replace_settings (NMConnection *connection,
                                 GHashTable *new_settings,
                                 GError **error)
 {
-	gboolean valid = FALSE;
-
 	g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
 	g_return_val_if_fail (new_settings != NULL, FALSE);
-	if (error)
-		g_return_val_if_fail (*error == NULL, FALSE);
+	g_return_val_if_fail (!error || !*error, FALSE);
 
-	if (validate_permissions_type (new_settings, error))
-		valid = hash_to_connection (connection, new_settings, error);
-	return valid;
+	if (!validate_permissions_type (new_settings, error))
+		return FALSE;
+
+	_nm_connection_replace_settings (connection, new_settings);
+	return nm_connection_verify (connection, error);
 }
 
 /**
@@ -394,8 +402,10 @@ nm_connection_replace_settings (NMConnection *connection,
  * Deep-copies the settings of @new_conenction and replaces the settings of @connection
  * with the copied settings.
  *
- * Returns: %TRUE if the settings were valid and added to the connection, %FALSE
- * if they were not
+ * Returns: %TRUE if the settings were valid after replacing the connection, %FALSE
+ * if they were not. Regardless of whether %TRUE or %FALSE is returned, the connection
+ * is successfully replaced. %FALSE only means, that the connection does not verify
+ * at the end of the operation.
  *
  * Since: 0.9.10
  **/
@@ -407,17 +417,17 @@ nm_connection_replace_settings_from_connection (NMConnection *connection,
 	NMConnectionPrivate *priv;
 	GHashTableIter iter;
 	NMSetting *setting;
-	gboolean changed, valid;
+	gboolean changed = FALSE;
+	gboolean valid;
 
 	g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
 	g_return_val_if_fail (NM_IS_CONNECTION (new_connection), FALSE);
-	if (error)
-		g_return_val_if_fail (*error == NULL, FALSE);
+	g_return_val_if_fail (!error || !*error, FALSE);
 
 	/* When 'connection' and 'new_connection' are the same object simply return
 	 * in order not to destroy 'connection' */
 	if (connection == new_connection)
-		return TRUE;
+		goto out;
 
 	/* No need to validate permissions like nm_connection_replace_settings()
 	 * since we're dealing with an NMConnection which has already done that.
@@ -434,6 +444,7 @@ nm_connection_replace_settings_from_connection (NMConnection *connection,
 		changed = TRUE;
 	}
 
+out:
 	valid =  nm_connection_verify (connection, error);
 	if (changed)
 		g_signal_emit (connection, signals[CHANGED], 0);
@@ -1440,6 +1451,29 @@ nm_connection_new (void)
 }
 
 /**
+ * _nm_connection_new_from_hash:
+ * @hash: (element-type utf8 GLib.HashTable): the #GHashTable describing
+ * the connection
+ *
+ * Creates a new #NMConnection from a hash table describing the connection.  See
+ * nm_connection_to_hash() for a description of the expected hash table.
+ *
+ * Returns: the new #NMConnection object, populated with settings created
+ * from the values in the hash table.
+ **/
+NMConnection *
+_nm_connection_new_from_hash (GHashTable *hash)
+{
+	NMConnection *connection;
+
+	g_return_val_if_fail (hash != NULL, NULL);
+
+	connection = nm_connection_new ();
+	_nm_connection_replace_settings (connection, hash);
+	return connection;
+}
+
+/**
  * nm_connection_new_from_hash:
  * @hash: (element-type utf8 GLib.HashTable): the #GHashTable describing
  * the connection
@@ -1462,11 +1496,9 @@ nm_connection_new_from_hash (GHashTable *hash, GError **error)
 	if (!validate_permissions_type (hash, error))
 		return NULL;
 
-	connection = nm_connection_new ();
-	if (!hash_to_connection (connection, hash, error)) {
-		g_object_unref (connection);
-		return NULL;
-	}
+	connection = _nm_connection_new_from_hash (hash);
+	if (!nm_connection_verify (connection, error))
+		g_clear_object (&connection);
 	return connection;
 }
 
diff --git a/libnm-util/nm-setting-8021x.c b/libnm-util/nm-setting-8021x.c
index f476b248..4f974a41 100644
--- a/libnm-util/nm-setting-8021x.c
+++ b/libnm-util/nm-setting-8021x.c
@@ -2878,8 +2878,8 @@ set_property (GObject *object, guint prop_id,
 		}
 		priv->ca_cert = set_cert_prop_helper (value, NM_SETTING_802_1X_CA_CERT, &error);
 		if (error) {
-			g_warning ("Error setting certificate (invalid data): (%d) %s",
-			           error->code, error->message);
+			g_warning ("Error setting certificate (invalid data): %s",
+			           error->message);
 			g_error_free (error);
 		}
 		break;
@@ -2902,8 +2902,8 @@ set_property (GObject *object, guint prop_id,
 		}
 		priv->client_cert = set_cert_prop_helper (value, NM_SETTING_802_1X_CLIENT_CERT, &error);
 		if (error) {
-			g_warning ("Error setting certificate (invalid data): (%d) %s",
-			           error->code, error->message);
+			g_warning ("Error setting certificate (invalid data): %s",
+			           error->message);
 			g_error_free (error);
 		}
 		break;
@@ -2934,8 +2934,8 @@ set_property (GObject *object, guint prop_id,
 		}
 		priv->phase2_ca_cert = set_cert_prop_helper (value, NM_SETTING_802_1X_PHASE2_CA_CERT, &error);
 		if (error) {
-			g_warning ("Error setting certificate (invalid data): (%d) %s",
-			           error->code, error->message);
+			g_warning ("Error setting certificate (invalid data): %s",
+			           error->message);
 			g_error_free (error);
 		}
 		break;
@@ -2958,8 +2958,8 @@ set_property (GObject *object, guint prop_id,
 		}
 		priv->phase2_client_cert = set_cert_prop_helper (value, NM_SETTING_802_1X_PHASE2_CLIENT_CERT, &error);
 		if (error) {
-			g_warning ("Error setting certificate (invalid data): (%d) %s",
-			           error->code, error->message);
+			g_warning ("Error setting certificate (invalid data): %s",
+			           error->message);
 			g_error_free (error);
 		}
 		break;
@@ -2985,8 +2985,8 @@ set_property (GObject *object, guint prop_id,
 		}
 		priv->private_key = set_cert_prop_helper (value, NM_SETTING_802_1X_PRIVATE_KEY, &error);
 		if (error) {
-			g_warning ("Error setting private key (invalid data): (%d) %s",
-			           error->code, error->message);
+			g_warning ("Error setting private key (invalid data): %s",
+			           error->message);
 			g_error_free (error);
 		}
 		break;
@@ -3004,8 +3004,8 @@ set_property (GObject *object, guint prop_id,
 		}
 		priv->phase2_private_key = set_cert_prop_helper (value, NM_SETTING_802_1X_PHASE2_PRIVATE_KEY, &error);
 		if (error) {
-			g_warning ("Error setting private key (invalid data): (%d) %s",
-			           error->code, error->message);
+			g_warning ("Error setting private key (invalid data): %s",
+			           error->message);
 			g_error_free (error);
 		}
 		break;
@@ -3726,8 +3726,8 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class)
 
 	/* Initialize crypto lbrary. */
 	if (!nm_utils_init (&error)) {
-		g_warning ("Couldn't initilize nm-utils/crypto system: %d %s",
-		           error->code, error->message);
+		g_warning ("Couldn't initilize nm-utils/crypto system: %s",
+		           error->message);
 		g_error_free (error);
 	}
 }
diff --git a/libnm-util/nm-setting-private.h b/libnm-util/nm-setting-private.h
index 6956463c..beb87484 100644
--- a/libnm-util/nm-setting-private.h
+++ b/libnm-util/nm-setting-private.h
@@ -23,6 +23,8 @@
 
 #include "nm-default.h"
 
+#include "nm-connection.h"
+
 #define NM_SETTING_SECRET_FLAGS_ALL \
 	(NM_SETTING_SECRET_FLAG_NONE | \
 	 NM_SETTING_SECRET_FLAG_AGENT_OWNED | \
@@ -62,6 +64,10 @@ gint _nm_setting_compare_priority (gconstpointer a, gconstpointer b);
 
 gboolean _nm_setting_get_property (NMSetting *setting, const char *name, GValue *value);
 
+NMConnection *_nm_connection_new_from_hash (GHashTable *hash);
+void          _nm_connection_replace_settings (NMConnection *connection,
+                                               GHashTable *new_settings);
+
 typedef enum NMSettingUpdateSecretResult {
 	NM_SETTING_UPDATE_SECRET_ERROR              = FALSE,
 	NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED   = TRUE,
diff --git a/libnm-util/nm-setting.c b/libnm-util/nm-setting.c
index add3ad97..990d6fe7 100644
--- a/libnm-util/nm-setting.c
+++ b/libnm-util/nm-setting.c
@@ -379,9 +379,6 @@ nm_setting_new_from_hash (GType setting_type, GHashTable *hash)
 	const char *prop_name;
 	GValue *src_value;
 	GObjectClass *class;
-	guint n_params = 0;
-	GParameter *params;
-	int i;
 
 	g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (setting_type), NULL);
 	g_return_val_if_fail (hash != NULL, NULL);
@@ -390,11 +387,11 @@ nm_setting_new_from_hash (GType setting_type, GHashTable *hash)
 	 * already been used.
 	 */
 	class = g_type_class_ref (setting_type);
-	params = g_new0 (GParameter, g_hash_table_size (hash));
+
+	setting = (NMSetting *) g_object_new (setting_type, NULL);
 
 	g_hash_table_iter_init (&iter, hash);
 	while (g_hash_table_iter_next (&iter, (gpointer) &prop_name, (gpointer) &src_value)) {
-		GValue *dst_value = &params[n_params].value;
 		GParamSpec *param_spec;
 
 		param_spec = g_object_class_find_property (class, prop_name);
@@ -402,21 +399,12 @@ nm_setting_new_from_hash (GType setting_type, GHashTable *hash)
 			/* Assume that any unrecognized property either can be ignored, or
 			 * else has a backward-compatibility equivalent.
 			 */
-			g_debug ("Ignoring unrecognized property '%s'", prop_name);
 			continue;
 		}
 
-		g_value_init (dst_value, G_VALUE_TYPE (src_value));
-		g_value_copy (src_value, dst_value);
-		params[n_params++].name = prop_name;
+		nm_g_object_set_property ((GObject *) setting, prop_name, src_value, NULL);
 	}
 
-	setting = (NMSetting *) g_object_newv (setting_type, n_params, params);
-
-	for (i = 0; i < n_params; i++)
-		g_value_unset (&params[i].value);
-
-	g_free (params);
 	g_type_class_unref (class);
 
 	return setting;
diff --git a/libnm-util/nm-utils.c b/libnm-util/nm-utils.c
index 7c9def1d..084f0f54 100644
--- a/libnm-util/nm-utils.c
+++ b/libnm-util/nm-utils.c
@@ -1514,20 +1514,14 @@ nm_utils_uuid_generate_from_string (const char *s)
 	g_return_val_if_fail (s && *s, NULL);
 
 	if (!nm_utils_init (&error)) {
-		g_warning ("error initializing crypto: (%d) %s",
-		           error ? error->code : 0,
-		           error ? error->message : "unknown");
-		if (error)
-			g_error_free (error);
+		g_warning ("error initializing crypto: %s", error->message);
+		g_error_free (error);
 		return NULL;
 	}
 
 	if (!crypto_md5_hash (NULL, 0, s, strlen (s), (char *) uuid, sizeof (uuid), &error)) {
-		g_warning ("error generating UUID: (%d) %s",
-		           error ? error->code : 0,
-		           error ? error->message : "unknown");
-		if (error)
-			g_error_free (error);
+		g_warning ("error generating UUID: %s", error->message);
+		g_error_free (error);
 		return NULL;
 	}