=?UTF-8?q?=5BPATCH=203/7=5D=20Only=20store=20passwords=20in=20keyring=20upon=20success=20=28cherry=20picked=20from=20commit=20d9f4b023fd4211affdd5a1b69305a4de78ac60f3=29?=



Signed-off-by: Murilo Opsfelder Araujo <muriloo linux vnet ibm com>

Conflicts:
	auth-dialog/main.c
---
 auth-dialog/main.c | 72 +++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 58 insertions(+), 14 deletions(-)

diff --git a/auth-dialog/main.c b/auth-dialog/main.c
index fe1620b..e69b618 100644
--- a/auth-dialog/main.c
+++ b/auth-dialog/main.c
@@ -152,9 +152,50 @@ struct gconf_key {
 	struct gconf_key *next;
 };
 
+/* This struct holds all information we need to add a password to
+ * gnome-keyring. It’s used in success_passwords. */
+struct keyring_password {
+	char *description;
+	char *password;
+	char *vpn_uuid;
+	char *auth_id;
+	char *label;
+};
+
+static void keyring_password_free(gpointer data);
+static void keyring_store_passwords(gpointer key, gpointer value, gpointer user_data);
+
+static void keyring_password_free(gpointer data)
+{
+	struct keyring_password *kp = (struct keyring_password*)data;
+	g_free(kp->description);
+	g_free(kp->password);
+	g_free(kp->vpn_uuid);
+	g_free(kp->auth_id);
+	g_free(kp->label);
+	g_free(kp);
+}
+
+static void keyring_store_passwords(gpointer key, gpointer value, gpointer user_data)
+{
+	struct keyring_password *kp = (struct keyring_password*)value;
+	gnome_keyring_store_password_sync (
+			OPENCONNECT_SCHEMA,
+			GNOME_KEYRING_DEFAULT,
+			kp->description,
+			kp->password,
+			"vpn_uuid", kp->vpn_uuid,
+			"auth_id", kp->auth_id,
+			"label", kp->label,
+			NULL
+			);
+}
+
+
 typedef struct auth_ui_data {
 	char *vpn_name;
 	char *vpn_uuid;
+	GHashTable *success_passwords;
 	struct openconnect_info *vpninfo;
 	struct gconf_key *success_keys;
 	GtkWidget *dialog;
@@ -740,22 +781,16 @@ static int nm_process_auth_form (void *cbdata, struct oc_auth_form *form)
 
 				if (data->opt->type == OC_FORM_OPT_PASSWORD) {
 					/* store the password in gnome-keyring */
-					char *description;
 					//int result;
-					description = g_strdup_printf(_("OpenConnect: %s: %s:%s"), ui_data->vpn_name, form->auth_id, data->opt->name);
-					gnome_keyring_store_password_sync (
-							OPENCONNECT_SCHEMA,
-							GNOME_KEYRING_DEFAULT,
-							description,
-							data->entry_text, /* password */
-							"vpn_uuid", ui_data->vpn_uuid,
-							"auth_id", form->auth_id,
-							"label", data->opt->name,
-							NULL
-							);
-					// TODO: err
-					g_free(description);
+					struct keyring_password *kp = g_new(struct keyring_password, 1);
+					kp->description = g_strdup_printf(_("OpenConnect: %s: %s:%s"), ui_data->vpn_name, form->auth_id, data->opt->name);
+					kp->password = g_strdup(data->entry_text);
+					kp->vpn_uuid = g_strdup(ui_data->vpn_uuid);
+					kp->auth_id = g_strdup(form->auth_id);
+					kp->label = g_strdup(data->opt->name);
 
+					g_hash_table_insert (ui_data->success_passwords,
+							g_strdup(kp->description), kp);
 				}
 			}
 			g_slice_free (ui_fragment_data, data);
@@ -1287,6 +1322,7 @@ static gboolean cookie_obtained(auth_ui_data *ui_data)
 			g_free(k->value);
 			g_free(k);
 		}
+		g_hash_table_remove_all (ui_data->success_passwords);
 		connect_host(ui_data);
 		return FALSE;
 	}
@@ -1327,6 +1363,11 @@ static gboolean cookie_obtained(auth_ui_data *ui_data)
 		openconnect_clear_cookie(ui_data->vpninfo);
 		printf("\n\n");
 		fflush(stdout);
+		g_hash_table_foreach(
+			ui_data->success_passwords,
+			keyring_store_passwords,
+			NULL);
+
 		ui_data->retval = 0;
 
 		gtk_main_quit();
@@ -1344,6 +1385,7 @@ static gboolean cookie_obtained(auth_ui_data *ui_data)
 		g_free(k->value);
 		g_free(k);
 	}
+	g_hash_table_remove_all (ui_data->success_passwords);
 
 	return FALSE;
 }
@@ -1598,6 +1640,8 @@ static auth_ui_data *init_ui_data (char *vpn_name, char *vpn_uuid)
 	ui_data->cert_response_changed = g_cond_new();
 	ui_data->vpn_name = vpn_name;
 	ui_data->vpn_uuid = vpn_uuid;
+	ui_data->success_passwords = g_hash_table_new_full (g_str_hash, g_str_equal,
+							  g_free, keyring_password_free);
 	if (pipe(ui_data->cancel_pipes)) {
 		/* This should never happen, and the world is probably about
 		   to come crashing down around our ears. But attempt to cope
-- 
1.8.0



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