summary refs log tree commit diff
path: root/libnm-util
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2011-10-16 08:47:38 +0200
committerMichael Biebl <biebl@debian.org>2011-10-16 08:47:38 +0200
commitdcc310e31af7fa88eb51fabe90de7edd374aecc5 (patch)
treea517abb10b0f0be34e511ca0cb2a78a2e0074362 /libnm-util
parent263bf4c0c89bb88dc995acd9a6a2de9095fbd461 (diff)
Imported Upstream version 0.9.1.90 upstream/0.9.1.90
Diffstat (limited to 'libnm-util')
-rw-r--r--libnm-util/Makefile.am2
-rw-r--r--libnm-util/Makefile.in8
-rw-r--r--libnm-util/libnm-util.ver2
-rw-r--r--libnm-util/nm-connection.c59
-rw-r--r--libnm-util/nm-connection.h4
-rw-r--r--libnm-util/nm-setting-vpn.c25
-rw-r--r--libnm-util/nm-setting.c55
-rw-r--r--libnm-util/nm-setting.h26
-rw-r--r--libnm-util/tests/Makefile.in6
-rw-r--r--libnm-util/tests/certs/Makefile.in6
10 files changed, 180 insertions, 13 deletions
diff --git a/libnm-util/Makefile.am b/libnm-util/Makefile.am
index 0a29e9c5..1529b4ad 100644
--- a/libnm-util/Makefile.am
+++ b/libnm-util/Makefile.am
@@ -69,7 +69,7 @@ libnm_util_la_LIBADD = $(GLIB_LIBS) $(DBUS_LIBS) $(UUID_LIBS)
 SYMBOL_VIS_FILE=$(srcdir)/libnm-util.ver
 
 libnm_util_la_LDFLAGS = -Wl,--version-script=$(SYMBOL_VIS_FILE) \
-	-version-info "2:0:0"
+	-version-info "3:0:1"
 
 if WITH_GNUTLS
 libnm_util_la_SOURCES += crypto_gnutls.c
diff --git a/libnm-util/Makefile.in b/libnm-util/Makefile.in
index d251ea8c..a67c544d 100644
--- a/libnm-util/Makefile.in
+++ b/libnm-util/Makefile.in
@@ -314,6 +314,12 @@ LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@
 LIBICONV = @LIBICONV@
 LIBINTL = @LIBINTL@
 LIBM = @LIBM@
+LIBNL1_CFLAGS = @LIBNL1_CFLAGS@
+LIBNL1_LIBS = @LIBNL1_LIBS@
+LIBNL2_CFLAGS = @LIBNL2_CFLAGS@
+LIBNL2_LIBS = @LIBNL2_LIBS@
+LIBNL3_CFLAGS = @LIBNL3_CFLAGS@
+LIBNL3_LIBS = @LIBNL3_LIBS@
 LIBNL_CFLAGS = @LIBNL_CFLAGS@
 LIBNL_LIBS = @LIBNL_LIBS@
 LIBOBJS = @LIBOBJS@
@@ -492,7 +498,7 @@ libnm_util_la_LIBADD = $(GLIB_LIBS) $(DBUS_LIBS) $(UUID_LIBS) \
 	$(am__append_3) $(am__append_6)
 SYMBOL_VIS_FILE = $(srcdir)/libnm-util.ver
 libnm_util_la_LDFLAGS = -Wl,--version-script=$(SYMBOL_VIS_FILE) \
-	-version-info "2:0:0"
+	-version-info "3:0:1"
 
 libnm_util_includedir = $(includedir)/NetworkManager
 
diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver
index 6052c275..edf5d292 100644
--- a/libnm-util/libnm-util.ver
+++ b/libnm-util/libnm-util.ver
@@ -2,6 +2,7 @@
 global:
 	nm_connection_add_setting;
 	nm_connection_clear_secrets;
+	nm_connection_clear_secrets_with_flags;
 	nm_connection_compare;
 	nm_connection_create_setting;
 	nm_connection_diff;
@@ -174,6 +175,7 @@ global:
 	nm_setting_cdma_get_username;
 	nm_setting_cdma_new;
 	nm_setting_clear_secrets;
+	nm_setting_clear_secrets_with_flags;
 	nm_setting_compare;
 	nm_setting_connection_add_permission;
 	nm_setting_connection_error_get_type;
diff --git a/libnm-util/nm-connection.c b/libnm-util/nm-connection.c
index 91fc3afa..d59c8b47 100644
--- a/libnm-util/nm-connection.c
+++ b/libnm-util/nm-connection.c
@@ -127,7 +127,7 @@ enum {
 
 enum {
 	SECRETS_UPDATED,
-
+	SECRETS_CLEARED,
 	LAST_SIGNAL
 };
 
@@ -950,12 +950,6 @@ nm_connection_need_secrets (NMConnection *connection,
 	return name;
 }
 
-static void
-clear_setting_secrets (gpointer key, gpointer data, gpointer user_data)
-{
-	nm_setting_clear_secrets (NM_SETTING (data));
-}
-
 /**
  * nm_connection_clear_secrets:
  * @connection: the #NMConnection
@@ -966,12 +960,42 @@ clear_setting_secrets (gpointer key, gpointer data, gpointer user_data)
 void
 nm_connection_clear_secrets (NMConnection *connection)
 {
-	NMConnectionPrivate *priv;
+	GHashTableIter iter;
+	NMSetting *setting;
 
 	g_return_if_fail (NM_IS_CONNECTION (connection));
 
-	priv = NM_CONNECTION_GET_PRIVATE (connection);
-	g_hash_table_foreach (priv->settings, clear_setting_secrets, NULL);
+	g_hash_table_iter_init (&iter, NM_CONNECTION_GET_PRIVATE (connection)->settings);
+	while (g_hash_table_iter_next (&iter, NULL, (gpointer) &setting))
+		nm_setting_clear_secrets (setting);
+
+	g_signal_emit (connection, signals[SECRETS_CLEARED], 0);
+}
+
+/**
+ * nm_connection_clear_secrets_with_flags:
+ * @connection: the #NMConnection
+ * @func: function to be called to determine whether a specific secret should be
+ *  cleared or not
+ * @user_data: caller-supplied data passed to @func
+ *
+ * Clears and frees secrets determined by @func.
+ **/
+void
+nm_connection_clear_secrets_with_flags (NMConnection *connection,
+                                        NMSettingClearSecretsWithFlagsFn func,
+                                        gpointer user_data)
+{
+	GHashTableIter iter;
+	NMSetting *setting;
+
+	g_return_if_fail (NM_IS_CONNECTION (connection));
+
+	g_hash_table_iter_init (&iter, NM_CONNECTION_GET_PRIVATE (connection)->settings);
+	while (g_hash_table_iter_next (&iter, NULL, (gpointer) &setting))
+		nm_setting_clear_secrets_with_flags (setting, func, user_data);
+
+	g_signal_emit (connection, signals[SECRETS_CLEARED], 0);
 }
 
 /**
@@ -1609,5 +1633,20 @@ nm_connection_class_init (NMConnectionClass *klass)
 					  g_cclosure_marshal_VOID__STRING,
 					  G_TYPE_NONE, 1,
 					  G_TYPE_STRING);
+
+	/**
+	* NMConnection::secrets-cleared:
+	* @connection: the object on which the signal is emitted
+	*
+	* The ::secrets-cleared signal is emitted when the secrets of a connection
+	* are cleared.
+	*/
+	signals[SECRETS_CLEARED] =
+		g_signal_new ("secrets-cleared",
+		              G_OBJECT_CLASS_TYPE (object_class),
+		              G_SIGNAL_RUN_FIRST,
+		              0, NULL, NULL,
+		              g_cclosure_marshal_VOID__VOID,
+		              G_TYPE_NONE, 0);
 }
 
diff --git a/libnm-util/nm-connection.h b/libnm-util/nm-connection.h
index 3cd18747..3245f7e6 100644
--- a/libnm-util/nm-connection.h
+++ b/libnm-util/nm-connection.h
@@ -147,6 +147,10 @@ const char *  nm_connection_need_secrets  (NMConnection *connection,
 
 void          nm_connection_clear_secrets (NMConnection *connection);
 
+void          nm_connection_clear_secrets_with_flags (NMConnection *connection,
+                                                      NMSettingClearSecretsWithFlagsFn func,
+                                                      gpointer user_data);
+
 gboolean      nm_connection_update_secrets (NMConnection *connection,
                                             const char *setting_name,
                                             GHashTable *secrets,
diff --git a/libnm-util/nm-setting-vpn.c b/libnm-util/nm-setting-vpn.c
index 50091cb9..755c1a45 100644
--- a/libnm-util/nm-setting-vpn.c
+++ b/libnm-util/nm-setting-vpn.c
@@ -612,6 +612,30 @@ compare_property (NMSetting *setting,
 }
 
 static void
+clear_secrets_with_flags (NMSetting *setting,
+	                      GParamSpec *pspec,
+	                      NMSettingClearSecretsWithFlagsFn func,
+	                      gpointer user_data)
+{
+	NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
+	GHashTableIter iter;
+	const char *secret;
+
+	if (priv->secrets == NULL)
+		return;
+
+	/* Iterate through secrets hash and check each entry */
+	g_hash_table_iter_init (&iter, priv->secrets);
+	while (g_hash_table_iter_next (&iter, (gpointer) &secret, NULL)) {
+		NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE;
+
+		nm_setting_get_secret_flags (setting, secret, &flags, NULL);
+		if (func (setting, pspec->name, flags, user_data) == TRUE)
+			g_hash_table_iter_remove (&iter);
+	}
+}
+
+static void
 destroy_one_secret (gpointer data)
 {
 	char *secret = (char *) data;
@@ -733,6 +757,7 @@ nm_setting_vpn_class_init (NMSettingVPNClass *setting_class)
 	parent_class->set_secret_flags  = set_secret_flags;
 	parent_class->need_secrets      = need_secrets;
 	parent_class->compare_property  = compare_property;
+	parent_class->clear_secrets_with_flags = clear_secrets_with_flags;
 
 	/* Properties */
 	/**
diff --git a/libnm-util/nm-setting.c b/libnm-util/nm-setting.c
index 3573f888..7ec4278f 100644
--- a/libnm-util/nm-setting.c
+++ b/libnm-util/nm-setting.c
@@ -648,6 +648,60 @@ nm_setting_clear_secrets (NMSetting *setting)
 	g_free (property_specs);
 }
 
+static void
+clear_secrets_with_flags (NMSetting *setting,
+	                      GParamSpec *pspec,
+	                      NMSettingClearSecretsWithFlagsFn func,
+	                      gpointer user_data)
+{
+	GValue value = { 0 };
+	NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE;
+
+	/* Clear the secret if the user function says to do so */
+	nm_setting_get_secret_flags (setting, pspec->name, &flags, NULL);
+	if (func (setting, pspec->name, flags, user_data) == TRUE) {
+		g_value_init (&value, pspec->value_type);
+		g_param_value_set_default (pspec, &value);
+		g_object_set_property (G_OBJECT (setting), pspec->name, &value);
+		g_value_unset (&value);
+	}
+}
+
+/**
+ * nm_setting_clear_secrets_with_flags:
+ * @setting: the #NMSetting
+ * @func: function to be called to determine whether a specific secret should be
+ *  cleared or not
+ * @user_data: caller-supplied data passed to @func
+ *
+ * Clears and frees secrets determined by @func.
+ **/
+void
+nm_setting_clear_secrets_with_flags (NMSetting *setting,
+                                     NMSettingClearSecretsWithFlagsFn func,
+                                     gpointer user_data)
+{
+	GParamSpec **property_specs;
+	guint n_property_specs;
+	guint i;
+
+	g_return_if_fail (setting);
+	g_return_if_fail (NM_IS_SETTING (setting));
+	g_return_if_fail (func != NULL);
+
+	property_specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (setting), &n_property_specs);
+	for (i = 0; i < n_property_specs; i++) {
+		if (property_specs[i]->flags & NM_SETTING_PARAM_SECRET) {
+			NM_SETTING_GET_CLASS (setting)->clear_secrets_with_flags (setting,
+			                                                          property_specs[i],
+			                                                          func,
+			                                                          user_data);
+		}
+	}
+
+	g_free (property_specs);
+}
+
 /**
  * nm_setting_need_secrets:
  * @setting: the #NMSetting
@@ -1029,6 +1083,7 @@ nm_setting_class_init (NMSettingClass *setting_class)
 	setting_class->get_secret_flags = get_secret_flags;
 	setting_class->set_secret_flags = set_secret_flags;
 	setting_class->compare_property = compare_property;
+	setting_class->clear_secrets_with_flags = clear_secrets_with_flags;
 
 	/* Properties */
 
diff --git a/libnm-util/nm-setting.h b/libnm-util/nm-setting.h
index e21efd81..3edf2a1f 100644
--- a/libnm-util/nm-setting.h
+++ b/libnm-util/nm-setting.h
@@ -150,6 +150,21 @@ typedef struct {
 	GObject parent;
 } NMSetting;
 
+
+/**
+ * NMSettingClearSecretsWithFlagsFn:
+ * @setting: The setting for which secrets are being iterated
+ * @secret: The secret's name
+ * @flags: The secret's flags, eg %NM_SETTING_SECRET_FLAG_AGENT_OWNED
+ * @user_data: User data passed to nm_connection_clear_secrets_with_flags()
+ *
+ * Returns: %TRUE to clear the secret, %FALSE to not clear the secret
+ */
+typedef gboolean (*NMSettingClearSecretsWithFlagsFn) (NMSetting *setting,
+                                                      const char *secret,
+                                                      NMSettingSecretFlags flags,
+                                                      gpointer user_data);
+
 typedef struct {
 	GObjectClass parent;
 
@@ -183,10 +198,14 @@ typedef struct {
 	                                  const GParamSpec *prop_spec,
 	                                  NMSettingCompareFlags flags);
 
+	void        (*clear_secrets_with_flags) (NMSetting *setting,
+	                                         GParamSpec *pspec,
+	                                         NMSettingClearSecretsWithFlagsFn func,
+	                                         gpointer user_data);
+
 	/* Padding for future expansion */
 	void (*_reserved1) (void);
 	void (*_reserved2) (void);
-	void (*_reserved3) (void);
 } NMSettingClass;
 
 /**
@@ -269,6 +288,11 @@ char       *nm_setting_to_string      (NMSetting *setting);
 
 /* Secrets */
 void        nm_setting_clear_secrets  (NMSetting *setting);
+
+void        nm_setting_clear_secrets_with_flags (NMSetting *setting,
+                                                 NMSettingClearSecretsWithFlagsFn func,
+                                                 gpointer user_data);
+
 GPtrArray  *nm_setting_need_secrets   (NMSetting *setting);
 gboolean    nm_setting_update_secrets (NMSetting *setting,
                                        GHashTable *secrets,
diff --git a/libnm-util/tests/Makefile.in b/libnm-util/tests/Makefile.in
index c4919ffc..df8fec77 100644
--- a/libnm-util/tests/Makefile.in
+++ b/libnm-util/tests/Makefile.in
@@ -250,6 +250,12 @@ LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@
 LIBICONV = @LIBICONV@
 LIBINTL = @LIBINTL@
 LIBM = @LIBM@
+LIBNL1_CFLAGS = @LIBNL1_CFLAGS@
+LIBNL1_LIBS = @LIBNL1_LIBS@
+LIBNL2_CFLAGS = @LIBNL2_CFLAGS@
+LIBNL2_LIBS = @LIBNL2_LIBS@
+LIBNL3_CFLAGS = @LIBNL3_CFLAGS@
+LIBNL3_LIBS = @LIBNL3_LIBS@
 LIBNL_CFLAGS = @LIBNL_CFLAGS@
 LIBNL_LIBS = @LIBNL_LIBS@
 LIBOBJS = @LIBOBJS@
diff --git a/libnm-util/tests/certs/Makefile.in b/libnm-util/tests/certs/Makefile.in
index 5149078b..14abf272 100644
--- a/libnm-util/tests/certs/Makefile.in
+++ b/libnm-util/tests/certs/Makefile.in
@@ -161,6 +161,12 @@ LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@
 LIBICONV = @LIBICONV@
 LIBINTL = @LIBINTL@
 LIBM = @LIBM@
+LIBNL1_CFLAGS = @LIBNL1_CFLAGS@
+LIBNL1_LIBS = @LIBNL1_LIBS@
+LIBNL2_CFLAGS = @LIBNL2_CFLAGS@
+LIBNL2_LIBS = @LIBNL2_LIBS@
+LIBNL3_CFLAGS = @LIBNL3_CFLAGS@
+LIBNL3_LIBS = @LIBNL3_LIBS@
 LIBNL_CFLAGS = @LIBNL_CFLAGS@
 LIBNL_LIBS = @LIBNL_LIBS@
 LIBOBJS = @LIBOBJS@