[PATCH] nm-pptp saving password



Hi,

 This patch add the password entry in the configuration and save the
password into keyring like nm-openvpn, also add the callback function
like delete_connection and save_secrets which cause
nm-connection-editor crashing.


Sincerely Yours,

Bin Li

http://cn.opensuse.org
diff --git a/vpn-daemons/pptp/common-gnome/Makefile.am b/vpn-daemons/pptp/common-gnome/Makefile.am
new file mode 100644
index 0000000..4a5d6c7
--- /dev/null
+++ b/vpn-daemons/pptp/common-gnome/Makefile.am
@@ -0,0 +1,17 @@
+lib_LTLIBRARIES=libnm-pptp-common-gnome.la
+
+libnm_pptp_common_gnome_la_CPPFLAGS = \
+	$(NM_UTILS_CFLAGS) \
+	$(GLIB_CFLAGS) \
+	$(GNOMEKEYRING_CFLAGS) \
+	-DG_DISABLE_DEPRECATED
+
+libnm_pptp_common_gnome_la_SOURCES= \
+	keyring-helpers.c \
+	keyring-helpers.h
+
+libnm_pptp_common_gnome_la_LIBADD = \
+	$(NM_UTILS_LIBS) \
+	$(GLIB_LIBS) \
+	$(GNOMEKEYRING_LIBS)
+
diff --git a/vpn-daemons/pptp/common-gnome/keyring-helpers.c b/vpn-daemons/pptp/common-gnome/keyring-helpers.c
new file mode 100644
index 0000000..cfb10ef
--- /dev/null
+++ b/vpn-daemons/pptp/common-gnome/keyring-helpers.c
@@ -0,0 +1,158 @@
+/* -*- 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>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * (C) Copyright 2004 - 2008 Red Hat, Inc.
+ */
+
+#include <string.h>
+#include <gnome-keyring-memory.h>
+
+#include <nm-setting-vpn.h>
+
+#include "keyring-helpers.h"
+#include "src/nm-pptp-service.h"
+
+#define KEYRING_UUID_TAG "connection-uuid"
+#define KEYRING_SN_TAG "setting-name"
+#define KEYRING_SK_TAG "setting-key"
+
+char *
+keyring_helpers_lookup_secret (const char *vpn_uuid,
+                   const char *secret_name,
+                   gboolean *is_session)
+{
+	GList *found_list = NULL;
+	GnomeKeyringResult ret;
+	GnomeKeyringFound *found;
+	char *secret;
+
+	ret = gnome_keyring_find_itemsv_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
+	                                      &found_list,
+	                                      KEYRING_UUID_TAG,
+	                                      GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
+	                                      vpn_uuid,
+	                                      KEYRING_SN_TAG,
+	                                      GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
+	                                      NM_SETTING_VPN_SETTING_NAME,
+	                                      KEYRING_SK_TAG,
+	                                      GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
+	                                      secret_name,
+	                                      NULL);
+	if ((ret != GNOME_KEYRING_RESULT_OK) || (g_list_length (found_list) == 0))
+		return NULL;
+
+	found = (GnomeKeyringFound *) found_list->data;
+
+	if (is_session) {
+		if (strcmp (found->keyring, "session") == 0)
+			*is_session = TRUE;
+		else
+			*is_session = FALSE;
+	}
+
+	secret = found->secret ? gnome_keyring_memory_strdup (found->secret) : NULL;
+	gnome_keyring_found_list_free (found_list);
+
+	return secret;
+}
+
+GnomeKeyringResult
+keyring_helpers_save_secret (const char *vpn_uuid,
+                             const char *vpn_name,
+                             const char *keyring,
+                             const char *secret_name,
+                             const char *secret)
+{
+	char *display_name;
+	GnomeKeyringResult ret;
+	GnomeKeyringAttributeList *attrs = NULL;
+	guint32 id = 0;
+
+	display_name = g_strdup_printf ("VPN %s secret for %s/%s/" NM_SETTING_VPN_SETTING_NAME,
+	                                secret_name,
+	                                vpn_name,
+	                                NM_DBUS_SERVICE_PPTP);
+
+	attrs = gnome_keyring_attribute_list_new ();
+	gnome_keyring_attribute_list_append_string (attrs,
+	                                            KEYRING_UUID_TAG,
+	                                            vpn_uuid);
+	gnome_keyring_attribute_list_append_string (attrs,
+	                                            KEYRING_SN_TAG,
+	                                            NM_SETTING_VPN_SETTING_NAME);
+	gnome_keyring_attribute_list_append_string (attrs,
+	                                            KEYRING_SK_TAG,
+	                                            secret_name);
+
+	ret = gnome_keyring_item_create_sync (keyring,
+	                                      GNOME_KEYRING_ITEM_GENERIC_SECRET,
+	                                      display_name,
+	                                      attrs,
+	                                      secret,
+	                                      TRUE,
+	                                      &id);
+	gnome_keyring_attribute_list_free (attrs);
+	g_free (display_name);
+	return ret;
+}
+
+static void
+ignore_callback (GnomeKeyringResult result, gpointer data)
+{
+}
+
+gboolean
+keyring_helpers_delete_secret (const char *vpn_uuid,
+                               const char *secret_name)
+{
+	GList *found = NULL, *iter;
+	GnomeKeyringResult ret;
+
+	g_return_val_if_fail (vpn_uuid != NULL, FALSE);
+	g_return_val_if_fail (secret_name != NULL, FALSE);
+
+	ret = gnome_keyring_find_itemsv_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
+	                                      &found,
+	                                      KEYRING_UUID_TAG,
+	                                      GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
+	                                      vpn_uuid,
+	                                      KEYRING_SN_TAG,
+	                                      GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
+	                                      NM_SETTING_VPN_SETTING_NAME,
+	                                      KEYRING_SK_TAG,
+	                                      GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
+	                                      secret_name,
+	                                      NULL);
+	if (ret != GNOME_KEYRING_RESULT_OK && ret != GNOME_KEYRING_RESULT_NO_MATCH)
+		return FALSE;
+	if (g_list_length (found) == 0)
+		return TRUE;
+
+	/* delete them all */
+	for (iter = found; iter; iter = g_list_next (iter)) {
+		GnomeKeyringFound *item = (GnomeKeyringFound *) iter->data;
+
+		gnome_keyring_item_delete (item->keyring, item->item_id,
+		                           ignore_callback, NULL, NULL);
+	}
+
+	gnome_keyring_found_list_free (found);
+	return TRUE;
+}
+
diff --git a/vpn-daemons/pptp/common-gnome/keyring-helpers.h b/vpn-daemons/pptp/common-gnome/keyring-helpers.h
new file mode 100644
index 0000000..76040a3
--- /dev/null
+++ b/vpn-daemons/pptp/common-gnome/keyring-helpers.h
@@ -0,0 +1,47 @@
+/* -*- 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>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * (C) Copyright 2004 - 2008 Red Hat, Inc.
+ */
+
+#ifndef KEYRING_HELPERS_H
+#define KEYRING_HELPERS_H
+
+#include <glib.h>
+#include <gnome-keyring.h>
+#include <gnome-keyring-memory.h>
+
+char *keyring_helpers_lookup_secret (
+		const char *vpn_uuid,
+		const char *secret_name,
+		gboolean *is_session);
+
+GnomeKeyringResult keyring_helpers_save_secret (
+		const char *vpn_uuid,
+		const char *vpn_name,
+		const char *keyring,
+		const char *secret_name,
+		const char *secret);
+
+gboolean keyring_helpers_delete_secret (
+		const char *vpn_uuid,
+		const char *secret_name);
+
+#endif  /* KEYRING_HELPERS_H */
+
diff --git a/vpn-daemons/pptp/Makefile.am b/vpn-daemons/pptp/Makefile.am
index df8e8f5..685686f 100644
--- a/vpn-daemons/pptp/Makefile.am
+++ b/vpn-daemons/pptp/Makefile.am
@@ -1,7 +1,7 @@
 AUTOMAKE_OPTIONS = foreign
 
 if WITH_GNOME
-SUBDIRS = src auth-dialog properties po
+SUBDIRS = src common-gnome auth-dialog properties po
 else
 SUBDIRS = src
 endif
diff --git a/vpn-daemons/pptp/auth-dialog/Makefile.am b/vpn-daemons/pptp/auth-dialog/Makefile.am
index 1afa647..28aaf7f 100644
--- a/vpn-daemons/pptp/auth-dialog/Makefile.am
+++ b/vpn-daemons/pptp/auth-dialog/Makefile.am
@@ -28,7 +28,7 @@ nm_pptp_auth_dialog_SOURCES =			\
 nm_pptp_auth_dialog_LDADD =			\
 	$(GTK_LIBS)				\
 	$(LIBGNOMEUI_LIBS)			\
-	$(GNOMEKEYRING_LIBS)			\
+	$(top_builddir)/common-gnome/libnm-pptp-common-gnome.la  \
 	$(NULL)
 
 CLEANFILES = *~
diff --git a/vpn-daemons/pptp/auth-dialog/main.c b/vpn-daemons/pptp/auth-dialog/main.c
index 5cd1062..53d1019 100644
--- a/vpn-daemons/pptp/auth-dialog/main.c
+++ b/vpn-daemons/pptp/auth-dialog/main.c
@@ -28,95 +28,17 @@
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 #include <libgnomeui/libgnomeui.h>
-#include <gnome-keyring.h>
 
 #include <nm-setting-vpn.h>
 
-#include "../src/nm-pptp-service.h"
+#include "src/nm-pptp-service.h"
+#include "common-gnome/keyring-helpers.h"
 #include "gnome-two-password-dialog.h"
 
 #define KEYRING_UUID_TAG "connection-uuid"
 #define KEYRING_SN_TAG "setting-name"
 #define KEYRING_SK_TAG "setting-key"
 
-static char *
-find_one_secret (const char *vpn_uuid,
-                 const char *secret_name,
-                 gboolean *is_session)
-{
-	GList *found_list = NULL;
-	GnomeKeyringResult ret;
-	GnomeKeyringFound *found;
-	char *secret;
-
-	ret = gnome_keyring_find_itemsv_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
-	                                      &found_list,
-	                                      KEYRING_UUID_TAG,
-	                                      GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
-	                                      vpn_uuid,
-	                                      KEYRING_SN_TAG,
-	                                      GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
-	                                      NM_SETTING_VPN_SETTING_NAME,
-	                                      KEYRING_SK_TAG,
-	                                      GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
-	                                      secret_name,
-	                                      NULL);
-	if ((ret != GNOME_KEYRING_RESULT_OK) || (g_list_length (found_list) == 0))
-		return NULL;
-
-	found = (GnomeKeyringFound *) found_list->data;
-
-	if (strcmp (found->keyring, "session") == 0)
-		*is_session = TRUE;
-	else
-		*is_session = FALSE;
-
-	secret = found->secret ? g_strdup (found->secret) : NULL;
-	gnome_keyring_found_list_free (found_list);
-
-	return secret;
-}
-
-static void
-save_vpn_password (const char *vpn_uuid,
-                   const char *vpn_name,
-                   const char *vpn_service,
-                   const char *keyring,
-                   const char *secret_name,
-                   const char *secret)
-{
-	char *display_name;
-	GnomeKeyringResult ret;
-	GnomeKeyringAttributeList *attrs = NULL;
-	guint32 id = 0;
-
-	display_name = g_strdup_printf ("VPN %s secret for %s/%s/" NM_SETTING_VPN_SETTING_NAME,
-	                                secret_name,
-	                                vpn_name,
-	                                vpn_service);
-
-	attrs = gnome_keyring_attribute_list_new ();
-	gnome_keyring_attribute_list_append_string (attrs,
-	                                            KEYRING_UUID_TAG,
-	                                            vpn_uuid);
-	gnome_keyring_attribute_list_append_string (attrs,
-	                                            KEYRING_SN_TAG,
-	                                            NM_SETTING_VPN_SETTING_NAME);
-	gnome_keyring_attribute_list_append_string (attrs,
-	                                            KEYRING_SK_TAG,
-	                                            secret_name);
-
-	ret = gnome_keyring_item_create_sync (keyring,
-	                                      GNOME_KEYRING_ITEM_GENERIC_SECRET,
-	                                      display_name,
-	                                      attrs,
-	                                      secret,
-	                                      TRUE,
-	                                      &id);
-	gnome_keyring_attribute_list_free (attrs);
-	g_free (display_name);
-}
-
 static gboolean
 get_secrets (const char *vpn_uuid,
              const char *vpn_name,
@@ -133,7 +55,7 @@ get_secrets (const char *vpn_uuid,
 	g_return_val_if_fail (password != NULL, FALSE);
 	g_return_val_if_fail (*password == NULL, FALSE);
 
-	*password = find_one_secret (vpn_uuid, "password", &is_session);
+	*password = keyring_helpers_lookup_secret (vpn_uuid, NM_PPTP_KEY_PASSWORD, &is_session);
 	if (!retry && *password)
 		return TRUE;
 
@@ -167,19 +89,28 @@ get_secrets (const char *vpn_uuid,
 	gtk_widget_show (GTK_WIDGET (dialog));
 
 	if (gnome_two_password_dialog_run_and_block (dialog)) {
+		const char *keyring = NULL;
+		gboolean save = FALSE;
+
 		*password = gnome_two_password_dialog_get_password (dialog);
 
 		switch (gnome_two_password_dialog_get_remember (dialog)) {
 		case GNOME_TWO_PASSWORD_DIALOG_REMEMBER_SESSION:
-			save_vpn_password (vpn_uuid, vpn_name, vpn_service, "session", "password", *password);
-			break;
+			keyring = "session";
+			/* Fall through */
 		case GNOME_TWO_PASSWORD_DIALOG_REMEMBER_FOREVER:
-			save_vpn_password (vpn_uuid, vpn_name, vpn_service, NULL, "password", *password);
+			save = TRUE;
 			break;
 		default:
 			break;
 		}
 
+		if (save) {
+			if (*password) {
+				keyring_helpers_save_secret (vpn_uuid, vpn_name, keyring,
+					   	NM_PPTP_KEY_PASSWORD, *password);
+			}
+		}
 	}
 
 	gtk_widget_hide (GTK_WIDGET (dialog));
diff --git a/vpn-daemons/pptp/configure.in b/vpn-daemons/pptp/configure.in
index 2794893..85719e4 100644
--- a/vpn-daemons/pptp/configure.in
+++ b/vpn-daemons/pptp/configure.in
@@ -134,6 +134,7 @@ fi
 AC_OUTPUT([
 Makefile
 src/Makefile
+common-gnome/Makefile
 auth-dialog/Makefile
 properties/Makefile
 po/Makefile.in
diff --git a/vpn-daemons/pptp/properties/Makefile.am b/vpn-daemons/pptp/properties/Makefile.am
index 3cf7472..241bb8c 100644
--- a/vpn-daemons/pptp/properties/Makefile.am
+++ b/vpn-daemons/pptp/properties/Makefile.am
@@ -31,6 +31,7 @@ libnm_pptp_properties_la_LIBADD =    \
         $(GTK_LIBS)                     \
         $(GCONF_LIBS)                   \
         $(LIBGNOMEUI_LIBS)              \
+	$(top_builddir)/common-gnome/libnm-pptp-common-gnome.la	\
         $(NM_UTILS_LIBS)
 
 libnm_pptp_properties_la_LDFLAGS =   \
diff --git a/vpn-daemons/pptp/properties/nm-pptp-dialog.glade b/vpn-daemons/pptp/properties/nm-pptp-dialog.glade
index 3216bfe..a9268e5 100644
--- a/vpn-daemons/pptp/properties/nm-pptp-dialog.glade
+++ b/vpn-daemons/pptp/properties/nm-pptp-dialog.glade
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.4 on Tue Aug 12 07:11:36 2008 -->
+<!--Generated with glade3 3.4.3 on Fri Oct 10 11:08:40 2008 -->
 <glade-interface>
   <widget class="GtkWindow" id="pptp-widget">
     <property name="title" translatable="yes">window1</property>
@@ -94,11 +94,14 @@
                 <child>
                   <widget class="GtkTable" id="table3">
                     <property name="visible">True</property>
-                    <property name="n_rows">2</property>
+                    <property name="n_rows">4</property>
                     <property name="n_columns">2</property>
                     <property name="column_spacing">12</property>
                     <property name="row_spacing">6</property>
                     <child>
+                      <placeholder/>
+                    </child>
+                    <child>
                       <widget class="GtkLabel" id="label26">
                         <property name="visible">True</property>
                         <property name="xalign">0</property>
@@ -146,6 +149,49 @@
                         <property name="y_options"></property>
                       </packing>
                     </child>
+                    <child>
+                      <widget class="GtkLabel" id="label2">
+                        <property name="visible">True</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">User password:</property>
+                      </widget>
+                      <packing>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</property>
+                        <property name="x_options">GTK_SHRINK | GTK_FILL</property>
+                        <property name="y_options"></property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkEntry" id="user_password_entry">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="visibility">False</property>
+                      </widget>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</property>
+                        <property name="y_options"></property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkCheckButton" id="show_passwords_checkbutton">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="label" translatable="yes">Show password</property>
+                        <property name="response_id">0</property>
+                        <property name="draw_indicator">True</property>
+                      </widget>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">3</property>
+                        <property name="bottom_attach">4</property>
+                        <property name="y_options"></property>
+                      </packing>
+                    </child>
                   </widget>
                 </child>
               </widget>
diff --git a/vpn-daemons/pptp/properties/nm-pptp.c b/vpn-daemons/pptp/properties/nm-pptp.c
index 31df478..4cab72e 100644
--- a/vpn-daemons/pptp/properties/nm-pptp.c
+++ b/vpn-daemons/pptp/properties/nm-pptp.c
@@ -41,7 +41,8 @@
 #include <nm-setting-connection.h>
 #include <nm-setting-ip4-config.h>
 
-#include "../src/nm-pptp-service.h"
+#include "src/nm-pptp-service.h"
+#include "common-gnome/keyring-helpers.h"
 #include "nm-pptp.h"
 #include "import-export.h"
 #include "advanced-dialog.h"
@@ -51,6 +52,8 @@
 #define PPTP_PLUGIN_SERVICE NM_DBUS_SERVICE_PPTP
 
 
+typedef void (*ChangedCallback) (GtkWidget *widget, gpointer user_data);
+
 /************** plugin class **************/
 
 static void pptp_plugin_ui_interface_init (NMVpnPluginUiInterface *iface_class);
@@ -102,6 +105,8 @@ pptp_plugin_ui_error_get_type (void)
 		static const GEnumValue values[] = {
 			/* Unknown error. */
 			ENUM_ENTRY (PPTP_PLUGIN_UI_ERROR_UNKNOWN, "UnknownError"),
+			/* The connection was missing invalid. */
+			ENUM_ENTRY (PPTP_PLUGIN_UI_ERROR_INVALID_CONNECTION, "InvalidConnection"),
 			/* The specified property was invalid. */
 			ENUM_ENTRY (PPTP_PLUGIN_UI_ERROR_INVALID_PROPERTY, "InvalidProperty"),
 			/* The specified property was missing and is required. */
@@ -208,6 +213,85 @@ advanced_button_clicked_cb (GtkWidget *button, gpointer user_data)
 	gtk_widget_show_all (dialog);
 }
 
+static void
+show_toggled_cb (GtkCheckButton *button, PptpPluginUiWidget *self)
+{
+	PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
+	GtkWidget *widget;
+	gboolean visible;
+
+	visible = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+
+	widget = glade_xml_get_widget (priv->xml, "user_password_entry");
+	g_assert (widget);
+	gtk_entry_set_visibility (GTK_ENTRY (widget), visible);
+}
+
+static GtkWidget *
+fill_password (GladeXML *xml,
+        const char *widget_name,
+        NMConnection *connection,
+        const char *password_type)
+{
+	GtkWidget *widget = NULL;
+	gchar *password = NULL;
+
+	widget = glade_xml_get_widget (xml, widget_name);
+	g_assert (widget);
+
+	if (!connection)
+		return widget;
+
+	password = NULL;
+
+	if (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_SYSTEM) {
+		NMSettingVPN *s_vpn;
+
+		s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
+		if (s_vpn) {
+			const gchar *tmp = NULL;
+
+			tmp = g_hash_table_lookup (s_vpn->secrets, password_type);
+			if (tmp)
+				password = gnome_keyring_memory_strdup (tmp);
+		}
+	} else {
+		NMSettingConnection *s_con = NULL;
+		gboolean unused;
+
+		s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+
+		password = keyring_helpers_lookup_secret (s_con->uuid,
+				password_type,
+				&unused);
+	}
+
+	if (password) {
+		gtk_entry_set_text (GTK_ENTRY (widget), password);
+		gnome_keyring_memory_free (password);
+	}
+
+	return widget;
+}
+
+static void
+fill_vpn_passwords (GladeXML *xml,
+		GtkSizeGroup *group,
+		NMConnection *connection,
+		ChangedCallback changed_cb,
+		gpointer user_data)
+{
+	GtkWidget *w = NULL;
+
+	w = fill_password (xml, "user_password_entry", connection, NM_PPTP_KEY_PASSWORD);
+	if (w) {
+		gtk_size_group_add_widget (group, w);
+		g_signal_connect (w, "changed", G_CALLBACK (changed_cb), user_data);
+	} else {
+		nm_error ("No user_password_entry in glade file!");
+	}
+}
+
 static gboolean
 init_plugin_ui (PptpPluginUiWidget *self, NMConnection *connection, GError **error)
 {
@@ -259,6 +343,14 @@ init_plugin_ui (PptpPluginUiWidget *self, NMConnection *connection, GError **err
 	widget = glade_xml_get_widget (priv->xml, "advanced_button");
 	g_signal_connect (G_OBJECT (widget), "clicked", G_CALLBACK (advanced_button_clicked_cb), self);
 
+	widget = glade_xml_get_widget (priv->xml, "show_passwords_checkbutton");
+	g_return_val_if_fail (widget != NULL, FALSE);
+	g_signal_connect (G_OBJECT (widget), "toggled",
+			(GCallback) show_toggled_cb,
+			self);
+
+	fill_vpn_passwords (priv->xml, priv->group, connection, stuff_changed_cb, self);
+
 	return TRUE;
 }
 
@@ -327,6 +419,40 @@ done:
 	return valid;
 }
 
+static gboolean
+save_secrets (NMVpnPluginUiWidgetInterface *iface,
+		NMConnection *connection,
+		GError **error)
+{
+	PptpPluginUiWidget *self = PPTP_PLUGIN_UI_WIDGET (iface);
+	PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
+	GnomeKeyringResult ret;
+	NMSettingConnection *s_con;
+	GtkWidget *widget;
+	const char *str;
+
+	s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
+	if (!s_con) {
+		g_set_error (error,
+				PPTP_PLUGIN_UI_ERROR,
+				PPTP_PLUGIN_UI_ERROR_INVALID_CONNECTION,
+				"missing 'connection' setting");
+		return FALSE;
+	}
+
+    widget = glade_xml_get_widget (priv->xml, "user_password_entry");
+    g_assert (widget);
+    str = gtk_entry_get_text (GTK_ENTRY (widget));
+    if (str && strlen (str)) {
+        ret = keyring_helpers_save_secret (s_con->uuid, s_con->id, NULL, NM_PPTP_KEY_PASSWORD, str);
+        if (ret != GNOME_KEYRING_RESULT_OK)
+            g_warning ("%s: failed to save user password to keyring.", __func__);
+    } else
+        keyring_helpers_delete_secret (s_con->uuid, NM_PPTP_KEY_PASSWORD);
+
+	return TRUE;
+}
+
 static NMVpnPluginUiWidgetInterface *
 nm_vpn_plugin_ui_widget_interface_new (NMConnection *connection, GError **error)
 {
@@ -425,6 +551,30 @@ pptp_plugin_ui_widget_interface_init (NMVpnPluginUiWidgetInterface *iface_class)
 	/* interface implementation */
 	iface_class->get_widget = get_widget;
 	iface_class->update_connection = update_connection;
+	iface_class->save_secrets = save_secrets;
+}
+
+static gboolean
+delete_connection (NMVpnPluginUiInterface *iface,
+		NMConnection *connection,
+		GError **error)
+{
+	NMSettingConnection *s_con = NULL;
+
+	/* Remove any secrets in the keyring associated with this connection's UUID */
+	s_con = (NMSettingConnection *) nm_connection_get_setting (connection,
+			NM_TYPE_SETTING_CONNECTION);
+	if (!s_con) {
+		g_set_error (error,
+				PPTP_PLUGIN_UI_ERROR,
+				PPTP_PLUGIN_UI_ERROR_INVALID_CONNECTION,
+				"missing 'connection' setting");
+		return FALSE;
+	}
+
+	keyring_helpers_delete_secret (s_con->uuid, NM_PPTP_KEY_PASSWORD);
+
+	return TRUE;
 }
 
 static NMConnection *
@@ -562,6 +712,7 @@ pptp_plugin_ui_interface_init (NMVpnPluginUiInterface *iface_class)
 	iface_class->import = import;
 	iface_class->export = export;
 	iface_class->get_suggested_name = get_suggested_name;
+	iface_class->delete_connection = delete_connection;
 }
 
 
diff --git a/vpn-daemons/pptp/properties/nm-pptp.h b/vpn-daemons/pptp/properties/nm-pptp.h
index 5877f06..49b4a4a 100644
--- a/vpn-daemons/pptp/properties/nm-pptp.h
+++ b/vpn-daemons/pptp/properties/nm-pptp.h
@@ -28,6 +28,7 @@
 typedef enum
 {
 	PPTP_PLUGIN_UI_ERROR_UNKNOWN = 0,
+	PPTP_PLUGIN_UI_ERROR_INVALID_CONNECTION,
 	PPTP_PLUGIN_UI_ERROR_INVALID_PROPERTY,
 	PPTP_PLUGIN_UI_ERROR_MISSING_PROPERTY,
 	PPTP_PLUGIN_UI_ERROR_FILE_NOT_READABLE,


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