network-manager-applet r606 - in trunk: . src



Author: tambeti
Date: Tue Mar 18 22:22:18 2008
New Revision: 606
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=606&view=rev

Log:
2008-03-18  Tambet Ingo  <tambet gmail com>

	Implement wired 802.1x authentication.

	* src/applet-device-wired.c (get_secrets_dialog_response_cb): Implement.
	(wired_get_secrets): Implement.

	* src/wired-dialog.[ch]: Implement.

	* src/Makefile.am: Add wired-dialog.[ch] to build.


Added:
   trunk/src/wired-dialog.c
   trunk/src/wired-dialog.h
Modified:
   trunk/ChangeLog
   trunk/src/Makefile.am
   trunk/src/applet-device-wired.c

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Tue Mar 18 22:22:18 2008
@@ -36,6 +36,8 @@
 	vpn-connection-info.h		\
 	vpn-password-dialog.c	\
 	vpn-password-dialog.h	\
+	wired-dialog.h \
+	wired-dialog.c \
 	wireless-dialog.h \
 	wireless-dialog.c \
 	applet-dialogs.h \

Modified: trunk/src/applet-device-wired.c
==============================================================================
--- trunk/src/applet-device-wired.c	(original)
+++ trunk/src/applet-device-wired.c	Tue Mar 18 22:22:18 2008
@@ -1,3 +1,5 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
 /* NetworkManager Wireless Applet -- Display wireless access points and allow user control
  *
  * Dan Williams <dcbw redhat com>
@@ -31,11 +33,13 @@
 #include <nm-device.h>
 #include <nm-setting-connection.h>
 #include <nm-setting-wired.h>
+#include <nm-setting-8021x.h>
 #include <nm-device-802-3-ethernet.h>
 
 #include "applet.h"
 #include "applet-dbus-settings.h"
 #include "applet-device-wired.h"
+#include "wired-dialog.h"
 #include "utils.h"
 
 typedef struct {
@@ -270,6 +274,137 @@
 	return pixbuf;
 }
 
+
+
+static void
+get_secrets_dialog_response_cb (GtkDialog *dialog,
+                                gint response,
+                                gpointer user_data)
+{
+	NMApplet *applet = NM_APPLET (user_data);
+	DBusGMethodInvocation *context;
+	AppletExportedConnection *exported;
+	NMConnection *connection = NULL;
+	NMSetting *setting;
+	GHashTable *settings_hash;
+	GHashTable *secrets;
+	GError *err = NULL;
+
+	context = g_object_get_data (G_OBJECT (dialog), "dbus-context");
+	if (!context) {
+		g_set_error (&err, NM_SETTINGS_ERROR, 1,
+		             "%s.%d (%s): couldn't get dialog data",
+		             __FILE__, __LINE__, __func__);
+		goto done;
+	}
+
+	if (response != GTK_RESPONSE_OK) {
+		g_set_error (&err, NM_SETTINGS_ERROR, 1,
+		             "%s.%d (%s): canceled",
+		             __FILE__, __LINE__, __func__);
+		goto done;
+	}
+
+	connection = nma_wired_dialog_get_connection (GTK_WIDGET (dialog));
+	if (!connection) {
+		g_set_error (&err, NM_SETTINGS_ERROR, 1,
+		             "%s.%d (%s): couldn't get connection from wired dialog.",
+		             __FILE__, __LINE__, __func__);
+		goto done;
+	}
+
+	setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_802_1X);
+	if (!setting) {
+		g_set_error (&err, NM_SETTINGS_ERROR, 1,
+					 "%s.%d (%s): requested setting '802-1x' didn't"
+					 " exist in the connection.",
+					 __FILE__, __LINE__, __func__);
+		goto done;
+	}
+
+	secrets = nm_setting_to_hash (setting);
+	if (!secrets) {
+		g_set_error (&err, NM_SETTINGS_ERROR, 1,
+					 "%s.%d (%s): failed to hash setting '%s'.",
+					 __FILE__, __LINE__, __func__, setting->name);
+		goto done;
+	}
+
+	utils_fill_connection_certs (connection);
+	utils_clear_filled_connection_certs (connection);
+
+	/* Returned secrets are a{sa{sv}}; this is the outer a{s...} hash that
+	 * will contain all the individual settings hashes.
+	 */
+	settings_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
+										   g_free, (GDestroyNotify) g_hash_table_destroy);
+
+	g_hash_table_insert (settings_hash, g_strdup (setting->name), secrets);
+	dbus_g_method_return (context, settings_hash);
+	g_hash_table_destroy (settings_hash);
+
+	/* Save the connection back to GConf _after_ hashing it, because
+	 * saving to GConf might trigger the GConf change notifiers, resulting
+	 * in the connection being read back in from GConf which clears secrets.
+	 */
+	exported = applet_dbus_settings_user_get_by_connection (applet->settings, connection);
+	if (exported)
+		applet_exported_connection_save (exported);
+
+done:
+	if (err) {
+		g_warning (err->message);
+
+		if (context)
+			dbus_g_method_return_error (context, err);
+
+		g_error_free (err);
+	}
+
+	if (connection)
+		nm_connection_clear_secrets (connection);
+	gtk_widget_hide (GTK_WIDGET (dialog));
+	gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+static gboolean
+wired_get_secrets (NMDevice *device,
+				   NMConnection *connection,
+				   const char *specific_object,
+				   const char *setting_name,
+				   DBusGMethodInvocation *context,
+				   NMApplet *applet,
+				   GError **error)
+{
+	GtkWidget *dialog;
+
+	dialog = nma_wired_dialog_new (applet->glade_file,
+								   applet->nm_client,
+								   g_object_ref (connection),
+								   device);
+	if (!dialog) {
+		g_set_error (error, NM_SETTINGS_ERROR, 1,
+		             "%s.%d (%s): couldn't display secrets UI",
+		             __FILE__, __LINE__, __func__);
+		return FALSE;
+	}
+
+	g_object_set_data (G_OBJECT (dialog), "dbus-context", context);
+	g_object_set_data_full (G_OBJECT (dialog),
+	                        "setting-name", g_strdup (setting_name),
+	                        (GDestroyNotify) g_free);
+
+	g_signal_connect (dialog, "response",
+	                  G_CALLBACK (get_secrets_dialog_response_cb),
+	                  applet);
+
+	gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ALWAYS);
+	gtk_widget_realize (dialog);
+	gtk_window_present (GTK_WINDOW (dialog));
+
+	return TRUE;
+}
+
 NMADeviceClass *
 applet_device_wired_get_class (NMApplet *applet)
 {
@@ -283,7 +418,7 @@
 	dclass->add_menu_item = wired_add_menu_item;
 	dclass->device_state_changed = wired_device_state_changed;
 	dclass->get_icon = wired_get_icon;
+	dclass->get_secrets = wired_get_secrets;
 
 	return dclass;
 }
-

Added: trunk/src/wired-dialog.c
==============================================================================
--- (empty file)
+++ trunk/src/wired-dialog.c	Tue Mar 18 22:22:18 2008
@@ -0,0 +1,146 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n.h>
+#include <nm-setting-connection.h>
+#include <nm-setting-8021x.h>
+#include <nm-setting-wireless.h>
+#include <nm-utils.h>
+#include "wired-dialog.h"
+#include "wireless-security.h"
+#include "applet-dialogs.h"
+
+static void
+stuff_changed_cb (WirelessSecurity *sec, gpointer user_data)
+{
+	GtkWidget *button = GTK_WIDGET (user_data);
+	
+	gtk_widget_set_sensitive (button, wireless_security_validate (sec, NULL));
+}
+
+static void
+dialog_set_network_name (NMConnection *connection, GtkEntry *entry)
+{
+	NMSettingConnection *setting;
+
+	setting = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+
+	gtk_widget_set_sensitive (GTK_WIDGET (entry), FALSE);
+	gtk_entry_set_text (entry, setting->id);
+}
+
+static WirelessSecurity *
+dialog_set_security (NMConnection *connection,
+					 const char *glade_file,
+					 GtkBox *box)
+{
+	GList *children;
+	GList *iter;
+	WirelessSecurity *security;
+
+	security = (WirelessSecurity *) ws_wpa_eap_new (glade_file, connection);
+
+	/* Remove any previous wireless security widgets */
+	children = gtk_container_get_children (GTK_CONTAINER (box));
+	for (iter = children; iter; iter = iter->next)
+		gtk_container_remove (GTK_CONTAINER (box), GTK_WIDGET (iter->data));
+
+	gtk_box_pack_start_defaults (box, wireless_security_get_widget (security));
+
+	return security;
+}
+
+static gboolean
+dialog_init (GtkWidget *dialog,
+			 GladeXML *xml,
+			 NMClient *nm_client,
+			 const char *glade_file,
+			 NMConnection *connection)
+{
+	WirelessSecurity *security;
+
+	/* Hide bunch of wireless specific widgets */
+	gtk_widget_hide (glade_xml_get_widget (xml, "device_label"));
+	gtk_widget_hide (glade_xml_get_widget (xml, "device_combo"));
+	gtk_widget_hide (glade_xml_get_widget (xml, "security_combo_label"));
+	gtk_widget_hide (glade_xml_get_widget (xml, "security_combo"));
+
+	gtk_window_set_title (GTK_WINDOW (glade_xml_get_widget (xml, "wireless_dialog")),
+						  _("Wired 802.1X authentication"));
+
+	dialog_set_network_name (connection, GTK_ENTRY (glade_xml_get_widget (xml, "network_name_entry")));
+	security = dialog_set_security (connection, glade_file, GTK_BOX (glade_xml_get_widget (xml, "security_vbox")));
+	wireless_security_set_changed_notify (security, stuff_changed_cb, glade_xml_get_widget (xml, "ok_button"));
+
+	g_object_set_data_full (G_OBJECT (dialog),
+							"security", security,
+							(GDestroyNotify) wireless_security_unref);
+
+	return TRUE;
+}
+
+GtkWidget *
+nma_wired_dialog_new (const char *glade_file,
+					  NMClient *nm_client,
+					  NMConnection *connection,
+					  NMDevice *device)
+{
+	GladeXML *xml;
+	GtkWidget *dialog;
+	gboolean success;
+
+	xml = glade_xml_new (glade_file, "wireless_dialog", NULL);
+	if (!xml) {
+		applet_warning_dialog_show (_("The NetworkManager Applet could not find some required resources (the glade file was not found)."));
+		return NULL;
+	}
+
+	dialog = glade_xml_get_widget (xml, "wireless_dialog");
+	if (!dialog) {
+		nm_warning ("Couldn't find glade wireless_dialog widget.");
+		g_object_unref (xml);
+		return NULL;
+	}
+
+	success = dialog_init (dialog, xml, nm_client, glade_file, connection);
+	if (!success) {
+		nm_warning ("Couldn't create wired security dialog.");
+		gtk_widget_destroy (dialog);
+		return NULL;
+	}
+
+	g_object_set_data_full (G_OBJECT (dialog),
+							"connection", g_object_ref (connection),
+							(GDestroyNotify) g_object_unref);
+
+	return dialog;
+}
+					  
+NMConnection *
+nma_wired_dialog_get_connection (GtkWidget *dialog)
+{
+	NMConnection *connection;
+	WirelessSecurity *security;
+	NMConnection *tmp_connection;
+	NMSetting *s_8021x;
+
+	g_return_val_if_fail (dialog != NULL, NULL);
+
+	connection = g_object_get_data (G_OBJECT (dialog), "connection");
+	security = g_object_get_data (G_OBJECT (dialog), "security");
+
+	/* Here's a nice hack to work around the fact that ws_802_1x_fill_connection needs wireless setting. */
+	tmp_connection = nm_connection_new ();
+	nm_connection_add_setting (tmp_connection, nm_setting_wireless_new ());
+	ws_802_1x_fill_connection (security, "wpa_eap_auth_combo", tmp_connection);
+
+	s_8021x = nm_connection_get_setting (tmp_connection, NM_TYPE_SETTING_802_1X);
+	nm_connection_add_setting (connection, NM_SETTING (g_object_ref (s_8021x)));
+
+	g_object_unref (tmp_connection);
+
+	return connection;
+}

Added: trunk/src/wired-dialog.h
==============================================================================
--- (empty file)
+++ trunk/src/wired-dialog.h	Tue Mar 18 22:22:18 2008
@@ -0,0 +1,18 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+#ifndef WIRED_DIALOG_H
+#define WIRED_DIALOG_H
+
+#include <gtk/gtk.h>
+#include <nm-client.h>
+#include <nm-connection.h>
+#include <nm-device.h>
+
+GtkWidget *nma_wired_dialog_new (const char *glade_file,
+								 NMClient *nm_client,
+								 NMConnection *connection,
+								 NMDevice *device);
+
+NMConnection *nma_wired_dialog_get_connection (GtkWidget *dialog);
+
+#endif /* WIRED_DIALOG_H */



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