[PATCH] Saving only the group password in keyring



Hi,

First, my apologies for pushing for this, since I believe the
interested parties are probably already notified through bugzilla on
this...

Anyway, regarding bugzilla #363918
(http://bugzilla.gnome.org/show_bug.cgi?id=363918) "Only save group
password in keyring" for the VPNC plugin to NetworkManager; I looked
at Denis Leroy's initial patch submission, and also at the updated
patch that was posted for Fedora 8, and I've tried to apply the same
concepts and fixes to fix the problem in Ubuntu, since moving from
0.6.x to 0.7 the previous patches couldn't be applied.

I've attached my results. I'm taking much of the code changes that
initially came from Denis' patch, with some additional changes I had
to come up with to the get_secrets function, and two new functions in
keyring-helpers to allow retrieving, independently, the user password
or the group password from the keyring.

The patch was initially written against a svn snapshot from September
28th (coming from the Ubuntu package done by Alexander Sack), so I did
check against a snapshot from today and the patch seems to apply
cleanly (with -p1). I couldn't actually test it on the recent
snapshot, I seem to constantly have trouble understanding how to build
NetworkManager from SVN :) This is the exact same patch attached to
bug 363918.

Thanks,

--

diff -Nur -x '*.orig' -x '*~'
network-manager-vpnc-0.7~~svn20080928t225540/auth-dialog/gnome-two-password-dialog.c
network-manager-vpnc-0.7~~svn20080928t225540.new/auth-dialog/gnome-two-password-dialog.c
--- network-manager-vpnc-0.7~~svn20080928t225540/auth-dialog/gnome-two-password-dialog.c	2008-09-29
16:42:05.000000000 -0400
+++ network-manager-vpnc-0.7~~svn20080928t225540.new/auth-dialog/gnome-two-password-dialog.c	2008-10-07
23:28:46.000000000 -0400
@@ -70,6 +70,7 @@
 	
 	GtkWidget *remember_session_button;
 	GtkWidget *remember_forever_button;
+	GtkWidget *remember_group_forever_button;

 	GtkWidget *radio_vbox;
 	GtkWidget *connect_with_no_userpass_button;
@@ -466,11 +467,15 @@
 		gtk_check_button_new_with_mnemonic (_("_Remember passwords for this
session"));
 	password_dialog->details->remember_forever_button =
 		gtk_check_button_new_with_mnemonic (_("_Save passwords in keyring"));
+	password_dialog->details->remember_group_forever_button =
+		gtk_check_button_new_with_mnemonic (_("Sa_ve group password in keyring"));

 	gtk_box_pack_start (GTK_BOX (vbox),
password_dialog->details->remember_session_button,
 			    FALSE, FALSE, 0);
 	gtk_box_pack_start (GTK_BOX (vbox),
password_dialog->details->remember_forever_button,
 			    FALSE, FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (vbox),
password_dialog->details->remember_group_forever_button,
+			    FALSE, FALSE, 0);

 	gnome_two_password_dialog_set_username (password_dialog, username);
 	gnome_two_password_dialog_set_password (password_dialog, password);
@@ -689,9 +694,11 @@
 	if (show_remember) {
 		gtk_widget_show (password_dialog->details->remember_session_button);
 		gtk_widget_show (password_dialog->details->remember_forever_button);
+		gtk_widget_show (password_dialog->details->remember_group_forever_button);
 	} else {
 		gtk_widget_hide (password_dialog->details->remember_session_button);
 		gtk_widget_hide (password_dialog->details->remember_forever_button);
+		gtk_widget_hide (password_dialog->details->remember_group_forever_button);
 	}
 }

@@ -699,30 +706,38 @@
 gnome_two_password_dialog_set_remember      (GnomeTwoPasswordDialog
      *password_dialog,
 					 GnomeTwoPasswordDialogRemember  remember)
 {
-	gboolean session, forever;
+	gboolean session, forever, group;

 	session = FALSE;
 	forever = FALSE;
+	group = FALSE;
 	if (remember == GNOME_TWO_PASSWORD_DIALOG_REMEMBER_SESSION) {
 		session = TRUE;
 	} else if (remember == GNOME_TWO_PASSWORD_DIALOG_REMEMBER_FOREVER){
 		forever = TRUE;
+	} else if (remember == GNOME_TWO_PASSWORD_DIALOG_REMEMBER_GROUP){
+		group = TRUE;
 	}
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
(password_dialog->details->remember_session_button),
 				      session);
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
(password_dialog->details->remember_forever_button),
 				      forever);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
(password_dialog->details->remember_group_forever_button),
+				      group);
 }

 GnomeTwoPasswordDialogRemember
 gnome_two_password_dialog_get_remember (GnomeTwoPasswordDialog
 *password_dialog)
 {
-	gboolean session, forever;
+	gboolean session, forever, group;

 	session = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(password_dialog->details->remember_session_button));
 	forever = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(password_dialog->details->remember_forever_button));
+	group = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(password_dialog->details->remember_group_forever_button));
 	if (forever) {
 		return GNOME_TWO_PASSWORD_DIALOG_REMEMBER_FOREVER;
+	} else if (group) {
+		return GNOME_TWO_PASSWORD_DIALOG_REMEMBER_GROUP;
 	} else if (session) {
 		return GNOME_TWO_PASSWORD_DIALOG_REMEMBER_SESSION;
 	}
diff -Nur -x '*.orig' -x '*~'
network-manager-vpnc-0.7~~svn20080928t225540/auth-dialog/gnome-two-password-dialog.h
network-manager-vpnc-0.7~~svn20080928t225540.new/auth-dialog/gnome-two-password-dialog.h
--- network-manager-vpnc-0.7~~svn20080928t225540/auth-dialog/gnome-two-password-dialog.h	2008-09-29
16:42:05.000000000 -0400
+++ network-manager-vpnc-0.7~~svn20080928t225540.new/auth-dialog/gnome-two-password-dialog.h	2008-10-07
23:28:23.000000000 -0400
@@ -57,6 +57,7 @@
 typedef enum {
 	GNOME_TWO_PASSWORD_DIALOG_REMEMBER_NOTHING,
 	GNOME_TWO_PASSWORD_DIALOG_REMEMBER_SESSION,
+	GNOME_TWO_PASSWORD_DIALOG_REMEMBER_GROUP,
 	GNOME_TWO_PASSWORD_DIALOG_REMEMBER_FOREVER
 } GnomeTwoPasswordDialogRemember;

diff -Nur -x '*.orig' -x '*~'
network-manager-vpnc-0.7~~svn20080928t225540/auth-dialog/main.c
network-manager-vpnc-0.7~~svn20080928t225540.new/auth-dialog/main.c
--- network-manager-vpnc-0.7~~svn20080928t225540/auth-dialog/main.c	2008-09-29
16:42:05.000000000 -0400
+++ network-manager-vpnc-0.7~~svn20080928t225540.new/auth-dialog/main.c	2008-10-07
23:28:23.000000000 -0400
@@ -49,7 +49,8 @@
 {
 	GnomeTwoPasswordDialog *dialog;
 	gboolean is_session = TRUE;
-	gboolean found;
+	gboolean found_password;
+	gboolean found_grouppassword;
 	char *prompt;

 	g_return_val_if_fail (vpn_uuid != NULL, FALSE);
@@ -59,8 +60,9 @@
 	g_return_val_if_fail (group_password != NULL, FALSE);
 	g_return_val_if_fail (*group_password == NULL, FALSE);

-	found = keyring_helpers_lookup_secrets (vpn_uuid, password,
group_password, &is_session);
-	if (!retry && found && *password && *group_password)
+	found_password = keyring_helpers_get_user_secret (vpn_uuid,
password, &is_session);
+	found_grouppassword = keyring_helpers_get_group_secret (vpn_uuid,
group_password, &is_session);
+	if (!retry && found_password && found_grouppassword && *password &&
*group_password)
 		return TRUE;

 	prompt = g_strdup_printf (_("You need to authenticate to access the
Virtual Private Network '%s'."), vpn_name);
@@ -74,7 +76,7 @@
 	gnome_two_password_dialog_set_password_secondary_label (dialog,
_("_Group Password:"));

 	/* If nothing was found in the keyring, default to not remembering
any secrets */
-	if (found) {
+	if (found_password) {
 		/* Otherwise set default remember based on which keyring the
secrets were found in */
 		if (is_session)
 			gnome_two_password_dialog_set_remember (dialog,
GNOME_TWO_PASSWORD_DIALOG_REMEMBER_SESSION);
@@ -83,6 +85,9 @@
 	} else
 		gnome_two_password_dialog_set_remember (dialog,
GNOME_TWO_PASSWORD_DIALOG_REMEMBER_NOTHING);

+	if (found_grouppassword)
+		gnome_two_password_dialog_set_remember (dialog,
GNOME_TWO_PASSWORD_DIALOG_REMEMBER_GROUP);
+
 	/* if retrying, pre-fill dialog with the password */
 	if (*password) {
 		gnome_two_password_dialog_set_password (dialog, *password);
@@ -110,6 +115,9 @@
 			keyring_helpers_save_secret (vpn_uuid, vpn_name, NULL,
VPNC_USER_PASSWORD, *password);
 			keyring_helpers_save_secret (vpn_uuid, vpn_name, NULL,
VPNC_GROUP_PASSWORD, *group_password);
 			break;
+		case GNOME_TWO_PASSWORD_DIALOG_REMEMBER_GROUP:
+			keyring_helpers_save_secret (vpn_uuid, vpn_name, NULL,
VPNC_GROUP_PASSWORD, *group_password);
+			break;
 		default:
 			break;
 		}
diff -Nur -x '*.orig' -x '*~'
network-manager-vpnc-0.7~~svn20080928t225540/common-gnome/keyring-helpers.c
network-manager-vpnc-0.7~~svn20080928t225540.new/common-gnome/keyring-helpers.c
--- network-manager-vpnc-0.7~~svn20080928t225540/common-gnome/keyring-helpers.c	2008-09-29
16:42:05.000000000 -0400
+++ network-manager-vpnc-0.7~~svn20080928t225540.new/common-gnome/keyring-helpers.c	2008-10-07
23:28:23.000000000 -0400
@@ -98,6 +98,36 @@
 	return TRUE;
 }

+gboolean
+keyring_helpers_get_user_secret (const char *vpn_uuid,
+                                char **password,
+                                gboolean *is_session)
+{
+	g_return_val_if_fail (password != NULL, FALSE);
+	g_return_val_if_fail (*password == NULL, FALSE);
+
+	*password = find_one_password (vpn_uuid, VPNC_USER_PASSWORD, is_session);
+	if (!*password)
+		return FALSE;
+
+	return TRUE;
+}
+
+gboolean
+keyring_helpers_get_group_secret (const char *vpn_uuid,
+                                char **group_password,
+                                gboolean *is_session)
+{
+	g_return_val_if_fail (group_password != NULL, FALSE);
+	g_return_val_if_fail (*group_password == NULL, FALSE);
+
+	*group_password = find_one_password (vpn_uuid, VPNC_GROUP_PASSWORD,
is_session);
+	if (!*group_password)
+		return FALSE;
+
+	return TRUE;
+}
+
 GnomeKeyringResult
 keyring_helpers_save_secret (const char *vpn_uuid,
                              const char *vpn_name,
diff -Nur -x '*.orig' -x '*~'
network-manager-vpnc-0.7~~svn20080928t225540/common-gnome/keyring-helpers.h
network-manager-vpnc-0.7~~svn20080928t225540.new/common-gnome/keyring-helpers.h
--- network-manager-vpnc-0.7~~svn20080928t225540/common-gnome/keyring-helpers.h	2008-09-29
16:42:05.000000000 -0400
+++ network-manager-vpnc-0.7~~svn20080928t225540.new/common-gnome/keyring-helpers.h	2008-10-07
23:28:23.000000000 -0400
@@ -34,6 +34,14 @@
                                          char **group_password,
                                          gboolean *is_session);

+gboolean keyring_helpers_get_user_secret (const char *vpn_uuid,
+                                         char **password,
+                                         gboolean *is_session);
+
+gboolean keyring_helpers_get_group_secret (const char *vpn_uuid,
+                                         char **group_password,
+                                         gboolean *is_session);
+
 GnomeKeyringResult keyring_helpers_save_secret (const char *vpn_uuid,
                                                 const char *vpn_name,
                                                 const char *keyring,


-- 
Mathieu Trudel
mathieu tl gmail com
diff -Nur -x '*.orig' -x '*~' network-manager-vpnc-0.7~~svn20080928t225540/auth-dialog/gnome-two-password-dialog.c network-manager-vpnc-0.7~~svn20080928t225540.new/auth-dialog/gnome-two-password-dialog.c
--- network-manager-vpnc-0.7~~svn20080928t225540/auth-dialog/gnome-two-password-dialog.c	2008-09-29 16:42:05.000000000 -0400
+++ network-manager-vpnc-0.7~~svn20080928t225540.new/auth-dialog/gnome-two-password-dialog.c	2008-10-07 23:28:46.000000000 -0400
@@ -70,6 +70,7 @@
 	
 	GtkWidget *remember_session_button;
 	GtkWidget *remember_forever_button;
+	GtkWidget *remember_group_forever_button;
 
 	GtkWidget *radio_vbox;
 	GtkWidget *connect_with_no_userpass_button;
@@ -466,11 +467,15 @@
 		gtk_check_button_new_with_mnemonic (_("_Remember passwords for this session"));
 	password_dialog->details->remember_forever_button =
 		gtk_check_button_new_with_mnemonic (_("_Save passwords in keyring"));
+	password_dialog->details->remember_group_forever_button =
+		gtk_check_button_new_with_mnemonic (_("Sa_ve group password in keyring"));
 
 	gtk_box_pack_start (GTK_BOX (vbox), password_dialog->details->remember_session_button, 
 			    FALSE, FALSE, 0);
 	gtk_box_pack_start (GTK_BOX (vbox), password_dialog->details->remember_forever_button, 
 			    FALSE, FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (vbox), password_dialog->details->remember_group_forever_button, 
+			    FALSE, FALSE, 0);
 
 	gnome_two_password_dialog_set_username (password_dialog, username);
 	gnome_two_password_dialog_set_password (password_dialog, password);
@@ -689,9 +694,11 @@
 	if (show_remember) {
 		gtk_widget_show (password_dialog->details->remember_session_button);
 		gtk_widget_show (password_dialog->details->remember_forever_button);
+		gtk_widget_show (password_dialog->details->remember_group_forever_button);
 	} else {
 		gtk_widget_hide (password_dialog->details->remember_session_button);
 		gtk_widget_hide (password_dialog->details->remember_forever_button);
+		gtk_widget_hide (password_dialog->details->remember_group_forever_button);
 	}
 }
 
@@ -699,30 +706,38 @@
 gnome_two_password_dialog_set_remember      (GnomeTwoPasswordDialog         *password_dialog,
 					 GnomeTwoPasswordDialogRemember  remember)
 {
-	gboolean session, forever;
+	gboolean session, forever, group;
 
 	session = FALSE;
 	forever = FALSE;
+	group = FALSE;
 	if (remember == GNOME_TWO_PASSWORD_DIALOG_REMEMBER_SESSION) {
 		session = TRUE;
 	} else if (remember == GNOME_TWO_PASSWORD_DIALOG_REMEMBER_FOREVER){
 		forever = TRUE;
+	} else if (remember == GNOME_TWO_PASSWORD_DIALOG_REMEMBER_GROUP){
+		group = TRUE;
 	}
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (password_dialog->details->remember_session_button),
 				      session);
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (password_dialog->details->remember_forever_button),
 				      forever);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (password_dialog->details->remember_group_forever_button),
+				      group);
 }
 
 GnomeTwoPasswordDialogRemember
 gnome_two_password_dialog_get_remember (GnomeTwoPasswordDialog         *password_dialog)
 {
-	gboolean session, forever;
+	gboolean session, forever, group;
 
 	session = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (password_dialog->details->remember_session_button));
 	forever = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (password_dialog->details->remember_forever_button));
+	group = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (password_dialog->details->remember_group_forever_button));
 	if (forever) {
 		return GNOME_TWO_PASSWORD_DIALOG_REMEMBER_FOREVER;
+	} else if (group) {
+		return GNOME_TWO_PASSWORD_DIALOG_REMEMBER_GROUP;
 	} else if (session) {
 		return GNOME_TWO_PASSWORD_DIALOG_REMEMBER_SESSION;
 	}
diff -Nur -x '*.orig' -x '*~' network-manager-vpnc-0.7~~svn20080928t225540/auth-dialog/gnome-two-password-dialog.h network-manager-vpnc-0.7~~svn20080928t225540.new/auth-dialog/gnome-two-password-dialog.h
--- network-manager-vpnc-0.7~~svn20080928t225540/auth-dialog/gnome-two-password-dialog.h	2008-09-29 16:42:05.000000000 -0400
+++ network-manager-vpnc-0.7~~svn20080928t225540.new/auth-dialog/gnome-two-password-dialog.h	2008-10-07 23:28:23.000000000 -0400
@@ -57,6 +57,7 @@
 typedef enum {
 	GNOME_TWO_PASSWORD_DIALOG_REMEMBER_NOTHING,
 	GNOME_TWO_PASSWORD_DIALOG_REMEMBER_SESSION,
+	GNOME_TWO_PASSWORD_DIALOG_REMEMBER_GROUP,
 	GNOME_TWO_PASSWORD_DIALOG_REMEMBER_FOREVER
 } GnomeTwoPasswordDialogRemember;
 
diff -Nur -x '*.orig' -x '*~' network-manager-vpnc-0.7~~svn20080928t225540/auth-dialog/main.c network-manager-vpnc-0.7~~svn20080928t225540.new/auth-dialog/main.c
--- network-manager-vpnc-0.7~~svn20080928t225540/auth-dialog/main.c	2008-09-29 16:42:05.000000000 -0400
+++ network-manager-vpnc-0.7~~svn20080928t225540.new/auth-dialog/main.c	2008-10-07 23:28:23.000000000 -0400
@@ -49,7 +49,8 @@
 {
 	GnomeTwoPasswordDialog *dialog;
 	gboolean is_session = TRUE;
-	gboolean found;
+	gboolean found_password;
+	gboolean found_grouppassword;
 	char *prompt;
 
 	g_return_val_if_fail (vpn_uuid != NULL, FALSE);
@@ -59,8 +60,9 @@
 	g_return_val_if_fail (group_password != NULL, FALSE);
 	g_return_val_if_fail (*group_password == NULL, FALSE);
 
-	found = keyring_helpers_lookup_secrets (vpn_uuid, password, group_password, &is_session);
-	if (!retry && found && *password && *group_password)
+	found_password = keyring_helpers_get_user_secret (vpn_uuid, password, &is_session);
+	found_grouppassword = keyring_helpers_get_group_secret (vpn_uuid, group_password, &is_session);
+	if (!retry && found_password && found_grouppassword && *password && *group_password)
 		return TRUE;
 
 	prompt = g_strdup_printf (_("You need to authenticate to access the Virtual Private Network '%s'."), vpn_name);
@@ -74,7 +76,7 @@
 	gnome_two_password_dialog_set_password_secondary_label (dialog, _("_Group Password:"));
 
 	/* If nothing was found in the keyring, default to not remembering any secrets */
-	if (found) {
+	if (found_password) {
 		/* Otherwise set default remember based on which keyring the secrets were found in */
 		if (is_session)
 			gnome_two_password_dialog_set_remember (dialog, GNOME_TWO_PASSWORD_DIALOG_REMEMBER_SESSION);
@@ -83,6 +85,9 @@
 	} else
 		gnome_two_password_dialog_set_remember (dialog, GNOME_TWO_PASSWORD_DIALOG_REMEMBER_NOTHING);
 
+	if (found_grouppassword)
+		gnome_two_password_dialog_set_remember (dialog, GNOME_TWO_PASSWORD_DIALOG_REMEMBER_GROUP);
+
 	/* if retrying, pre-fill dialog with the password */
 	if (*password) {
 		gnome_two_password_dialog_set_password (dialog, *password);
@@ -110,6 +115,9 @@
 			keyring_helpers_save_secret (vpn_uuid, vpn_name, NULL, VPNC_USER_PASSWORD, *password);
 			keyring_helpers_save_secret (vpn_uuid, vpn_name, NULL, VPNC_GROUP_PASSWORD, *group_password);
 			break;
+		case GNOME_TWO_PASSWORD_DIALOG_REMEMBER_GROUP:
+			keyring_helpers_save_secret (vpn_uuid, vpn_name, NULL, VPNC_GROUP_PASSWORD, *group_password);
+			break;
 		default:
 			break;
 		}
diff -Nur -x '*.orig' -x '*~' network-manager-vpnc-0.7~~svn20080928t225540/common-gnome/keyring-helpers.c network-manager-vpnc-0.7~~svn20080928t225540.new/common-gnome/keyring-helpers.c
--- network-manager-vpnc-0.7~~svn20080928t225540/common-gnome/keyring-helpers.c	2008-09-29 16:42:05.000000000 -0400
+++ network-manager-vpnc-0.7~~svn20080928t225540.new/common-gnome/keyring-helpers.c	2008-10-07 23:28:23.000000000 -0400
@@ -98,6 +98,36 @@
 	return TRUE;
 }
 
+gboolean
+keyring_helpers_get_user_secret (const char *vpn_uuid,
+                                char **password,
+                                gboolean *is_session)
+{
+	g_return_val_if_fail (password != NULL, FALSE);
+	g_return_val_if_fail (*password == NULL, FALSE);
+
+	*password = find_one_password (vpn_uuid, VPNC_USER_PASSWORD, is_session);
+	if (!*password)
+		return FALSE;
+
+	return TRUE;
+}
+
+gboolean
+keyring_helpers_get_group_secret (const char *vpn_uuid,
+                                char **group_password,
+                                gboolean *is_session)
+{
+	g_return_val_if_fail (group_password != NULL, FALSE);
+	g_return_val_if_fail (*group_password == NULL, FALSE);
+
+	*group_password = find_one_password (vpn_uuid, VPNC_GROUP_PASSWORD, is_session);
+	if (!*group_password)
+		return FALSE;
+
+	return TRUE;
+}
+
 GnomeKeyringResult
 keyring_helpers_save_secret (const char *vpn_uuid,
                              const char *vpn_name,
diff -Nur -x '*.orig' -x '*~' network-manager-vpnc-0.7~~svn20080928t225540/common-gnome/keyring-helpers.h network-manager-vpnc-0.7~~svn20080928t225540.new/common-gnome/keyring-helpers.h
--- network-manager-vpnc-0.7~~svn20080928t225540/common-gnome/keyring-helpers.h	2008-09-29 16:42:05.000000000 -0400
+++ network-manager-vpnc-0.7~~svn20080928t225540.new/common-gnome/keyring-helpers.h	2008-10-07 23:28:23.000000000 -0400
@@ -34,6 +34,14 @@
                                          char **group_password,
                                          gboolean *is_session);
 
+gboolean keyring_helpers_get_user_secret (const char *vpn_uuid,
+                                         char **password,
+                                         gboolean *is_session);
+
+gboolean keyring_helpers_get_group_secret (const char *vpn_uuid,
+                                         char **group_password,
+                                         gboolean *is_session);
+
 GnomeKeyringResult keyring_helpers_save_secret (const char *vpn_uuid,
                                                 const char *vpn_name,
                                                 const char *keyring,


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