[vinagre] Migrate from libgnome-keyring to libsecret



commit ff798d9f73c65ad507573a11aeffd552ec4f0261
Author: Stef Walter <stefw gnome org>
Date:   Fri Jul 13 16:46:41 2012 +0200

    Migrate from libgnome-keyring to libsecret
    
    See: https://live.gnome.org/GnomeGoals/LibsecretMigration

 configure.ac          |    2 +-
 vinagre/vinagre-ssh.c |   70 ++++++++++++++++--------------------
 vinagre/vinagre-tab.c |   94 ++++++++++++++++++++++--------------------------
 3 files changed, 75 insertions(+), 91 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 030f7ea..e287a62 100644
--- a/configure.ac
+++ b/configure.ac
@@ -165,7 +165,7 @@ AS_IF([test "x$have_telepathy" = "xyes"],
 AM_CONDITIONAL([VINAGRE_HAVE_TELEPATHY_GLIB], [test "x$have_telepathy" = "xyes"])
 
 # Check required libraries
-PKG_CHECK_MODULES([VINAGRE], [$GLIB_DEPS $GTHREAD_DEPS $GTK_DEPS gnome-keyring-1 $XML2_DEPS $AVAHI_DEPS $TELEPATHY_GLIB_DEPS $SSH_DEPS])
+PKG_CHECK_MODULES([VINAGRE], [$GLIB_DEPS $GTHREAD_DEPS $GTK_DEPS libsecret-1 $XML2_DEPS $AVAHI_DEPS $TELEPATHY_GLIB_DEPS $SSH_DEPS])
 
 PKG_CHECK_MODULES([VNC], [$GTK_VNC_DEPS $GTK_DEPS $XML2_DEPS])
 
diff --git a/vinagre/vinagre-ssh.c b/vinagre/vinagre-ssh.c
index 0e17f38..3a25e39 100644
--- a/vinagre/vinagre-ssh.c
+++ b/vinagre/vinagre-ssh.c
@@ -40,7 +40,7 @@
 #include <fcntl.h>
 
 #include <glib/gi18n.h>
-#include <gnome-keyring.h>
+#include <libsecret/secret.h>
 
 static const int SSH_READ_TIMEOUT = 40; /* seconds */
 
@@ -382,9 +382,8 @@ handle_login (GtkWindow *parent,
   gsize bytes_written;
   const gchar *authtype;
   gchar *object, *password;
-  GnomeKeyringResult result;
-  GList *matches;
-  GnomeKeyringNetworkPasswordData *found_item;
+  GError *secret_error = NULL;
+  gchar *label;
 
   object = password = NULL;
   authtype = NULL;
@@ -473,7 +472,7 @@ handle_login (GtkWindow *parent,
       if (strncmp (buffer, "\r\n", 2) == 0)
         continue;
 
-      g_free (password);
+      secret_password_free (password);
       password = NULL;
 
       if (g_str_has_suffix (buffer, "password: ") ||
@@ -487,17 +486,17 @@ handle_login (GtkWindow *parent,
 	  object = get_object_from_password_line (buffer);
 
 	  /* Search password in the keyring */
-	  result = gnome_keyring_find_network_password_sync (user,		/* username */
-							     NULL,		/* domain */
-							     host,	        /* server */
-							     object,		/* object */
-							     "ssh",		/* protocol */
-							     authtype,		/* authtype */
-							     port,		/* port */
-							     &matches);
+          password = secret_password_lookup_sync (SECRET_SCHEMA_COMPAT_NETWORK, NULL, NULL,
+                                                  "user", user,
+                                                  "server", host,
+                                                  "object", object,
+                                                  "protocol", "ssh",
+                                                  "authtype", authtype,
+                                                  "port", port,
+                                                  NULL);
 
 	  /* If the password was not found in keyring then ask for it */
-	  if (result != GNOME_KEYRING_RESULT_OK || matches == NULL || matches->data == NULL)
+          if (password == NULL)
 	    {
 	      gchar *full_host;
 	      gboolean res;
@@ -516,12 +515,6 @@ handle_login (GtkWindow *parent,
                   break;
                 }
             }
-	  else
-	    {
-	      found_item = (GnomeKeyringNetworkPasswordData *) matches->data;
-	      password = g_strdup (found_item->password);
-	      gnome_keyring_network_password_list_free (matches);
-	    }
 
           if (!g_output_stream_write_all (reply_stream,
                                           password, strlen (password),
@@ -609,29 +602,28 @@ handle_login (GtkWindow *parent,
   if (ret_val && save_in_keyring)
     {
       /* Login succeed, save password in keyring */
-      GnomeKeyringResult result;
-      guint32            keyring_item_id;
-
-      result = gnome_keyring_set_network_password_sync (
-                NULL,         /* default keyring */
-                user,         /* user            */
-                NULL,         /* domain          */
-                host,         /* server          */
-                object,       /* object          */
-                "ssh",        /* protocol        */
-                authtype,     /* authtype        */
-                port,         /* port            */
-                password,     /* password        */
-                &keyring_item_id);
-
-      if (result != GNOME_KEYRING_RESULT_OK)
+      label = g_strdup_printf (_("Secure shell password: %s"), host);
+      secret_password_store_sync (SECRET_SCHEMA_COMPAT_NETWORK, NULL, label,
+                                  password, NULL, &secret_error,
+                                  "user", user,
+                                  "server", host,
+                                  "object", object,
+                                  "protocol", "ssh",
+                                  "authtype", authtype,
+                                  "port", port,
+                                  NULL);
+      g_free (label);
+
+      if (secret_error != NULL) {
         vinagre_utils_show_error_dialog (_("Error saving the credentials on the keyring."),
-				  gnome_keyring_result_to_message (result),
-				  parent);
-
+                                         secret_error->message,
+                                         parent);
+        g_error_free (secret_error);
+      }
     }
 
   g_free (object);
+  secret_password_free (password);
   g_object_unref (prompt_stream);
   g_object_unref (stdout_stream);
   g_object_unref (reply_stream);
diff --git a/vinagre/vinagre-tab.c b/vinagre/vinagre-tab.c
index afc3f54..a941303 100644
--- a/vinagre/vinagre-tab.c
+++ b/vinagre/vinagre-tab.c
@@ -24,7 +24,7 @@
 #endif
 
 #include <glib/gi18n.h>
-#include <gnome-keyring.h>
+#include <libsecret/secret.h>
 
 #include "vinagre-tab.h"
 #include "vinagre-notebook.h"
@@ -43,7 +43,7 @@ struct _VinagreTabPrivate
   VinagreNotebook   *nb;
   VinagreWindow     *window;
   gboolean           save_credentials;
-  guint32            keyring_item_id;
+  gboolean           saved_credentials;
   VinagreTabState    state;
   GtkWidget         *layout;
   GtkWidget         *toolbar;
@@ -551,7 +551,6 @@ vinagre_tab_init (VinagreTab *tab)
 
   tab->priv = VINAGRE_TAB_GET_PRIVATE (tab);
   tab->priv->save_credentials = FALSE;
-  tab->priv->keyring_item_id = 0;
   tab->priv->state = VINAGRE_TAB_STATE_INITIALIZING;
 
   /* Create the scrolled window */
@@ -746,36 +745,19 @@ vinagre_tab_get_from_connection (VinagreConnection *conn)
 gboolean
 vinagre_tab_find_credentials_in_keyring (VinagreTab *tab, gchar **username, gchar **password)
 {
-  GnomeKeyringNetworkPasswordData *found_item;
-  GnomeKeyringResult               result;
-  GList                           *matches;
-  
-  matches   = NULL;
   *username = NULL;
-  *password = NULL;
-
-  result = gnome_keyring_find_network_password_sync (
-                vinagre_connection_get_username (tab->priv->conn),            /* user     */
-		NULL,                                                         /* domain   */
-		vinagre_connection_get_host (tab->priv->conn),                /* server   */
-		NULL,                                                         /* object   */
-		vinagre_connection_get_protocol (tab->priv->conn),            /* protocol */
-		NULL,                                                         /* authtype */
-		vinagre_connection_get_port (tab->priv->conn),                /* port     */
-		&matches);
-
-  if (result != GNOME_KEYRING_RESULT_OK || matches == NULL || matches->data == NULL)
-    return FALSE;
 
-  found_item = (GnomeKeyringNetworkPasswordData *) matches->data;
-
-  *username = g_strdup (found_item->user);
-  *password = g_strdup (found_item->password);
-  
-  tab->priv->keyring_item_id = found_item->item_id;
+  *password = secret_password_lookup_sync (SECRET_SCHEMA_COMPAT_NETWORK, NULL, NULL,
+                                           "user", vinagre_connection_get_username (tab->priv->conn),
+                                           "server", vinagre_connection_get_host (tab->priv->conn),
+                                           "protocol", vinagre_connection_get_protocol (tab->priv->conn),
+                                           "port", vinagre_connection_get_port (tab->priv->conn),
+                                           NULL);
 
-  gnome_keyring_network_password_list_free (matches);
+  if (*password == NULL)
+    return FALSE;
 
+  *username = g_strdup (vinagre_connection_get_username (tab->priv->conn));
   return TRUE;
 }
 
@@ -787,41 +769,51 @@ void vinagre_tab_set_save_credentials (VinagreTab *tab, gboolean value)
 void
 vinagre_tab_save_credentials_in_keyring (VinagreTab *tab)
 {
-  GnomeKeyringResult result;
+  GError *error = NULL;
+  gchar *label;
 
   if (!tab->priv->save_credentials)
     return;
 
-  result = gnome_keyring_set_network_password_sync (
-                NULL,                                                        /* default keyring */
-                vinagre_connection_get_username (tab->priv->conn),           /* user            */
-                NULL,                                                        /* domain          */
-                vinagre_connection_get_host (tab->priv->conn),               /* server          */
-                NULL,                                                        /* object          */
-                vinagre_connection_get_protocol (tab->priv->conn),           /* protocol        */
-                NULL,                                                        /* authtype        */
-                vinagre_connection_get_port (tab->priv->conn),               /* port            */
-                vinagre_connection_get_password (tab->priv->conn),           /* password        */
-                &tab->priv->keyring_item_id);
-
-  if (result != GNOME_KEYRING_RESULT_OK)
+  label = g_strdup_printf (_("Remote desktop password: %s"), vinagre_connection_get_host (tab->priv->conn));
+  secret_password_store_sync (SECRET_SCHEMA_COMPAT_NETWORK, NULL,
+                              label, vinagre_connection_get_password (tab->priv->conn),
+                              NULL, &error,
+                              "user", vinagre_connection_get_username (tab->priv->conn),
+                              "server", vinagre_connection_get_host (tab->priv->conn),
+                              "protocol", vinagre_connection_get_protocol (tab->priv->conn),
+                              "port", vinagre_connection_get_port (tab->priv->conn),
+                              NULL);
+  g_free (label);
+
+  if (error == NULL) {
+    tab->priv->saved_credentials = TRUE;
+
+  } else {
     vinagre_utils_show_error_dialog (_("Error saving the credentials on the keyring."),
-			      gnome_keyring_result_to_message (result),
-			      GTK_WINDOW (tab->priv->window));
+                                     error->message,
+                                     GTK_WINDOW (tab->priv->window));
+    g_error_free (error);
+  }
 
   tab->priv->save_credentials = FALSE;
 }
 
 void vinagre_tab_remove_credentials_from_keyring (VinagreTab *tab)
 {
-  vinagre_connection_set_username (tab->priv->conn, NULL);
-  vinagre_connection_set_password (tab->priv->conn, NULL);
-
-  if (tab->priv->keyring_item_id > 0)
+  if (tab->priv->saved_credentials)
     {
-      gnome_keyring_item_delete_sync (NULL, tab->priv->keyring_item_id);
-      tab->priv->keyring_item_id = 0;
+      secret_password_clear_sync (SECRET_SCHEMA_COMPAT_NETWORK, NULL, NULL,
+                                  "user", vinagre_connection_get_username (tab->priv->conn),
+                                  "server", vinagre_connection_get_host (tab->priv->conn),
+                                  "protocol", vinagre_connection_get_protocol (tab->priv->conn),
+                                  "port", vinagre_connection_get_port (tab->priv->conn),
+                                  NULL);
+      tab->priv->saved_credentials = FALSE;
     }
+
+  vinagre_connection_set_username (tab->priv->conn, NULL);
+  vinagre_connection_set_password (tab->priv->conn, NULL);
 }
 
 void



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