? 344839.diff
? aaa
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/vino/ChangeLog,v
retrieving revision 1.134
diff -u -p -r1.134 ChangeLog
--- ChangeLog	26 Apr 2006 20:59:08 -0000	1.134
+++ ChangeLog	30 Jun 2006 08:28:43 -0000
@@ -1,3 +1,21 @@
+2006-06-30  Steven Zhang <steven.zhang@sun.com>
+
+        Add support for Gnome-Keyring. This will enchance the
+        security. A configure option --enable-gnome-keyring is
+        used to specify if gnome-keyring is enabled.
+        Fix bug #344839
+
+        * configure.in: add --enable-gnome-keyring option
+
+        * config.h.in: add ENABLE_GNOME_KEYRING
+
+        * server/vino-prefs.c add vino_get_saved_password function
+        to retrieve password when Gnome Keyring is enabled.
+
+        * capplet/vino-preferences.c add vino_preferences_dialog_get_password
+        and vino_preferences_dialog_set_password function to get/save
+        password when Gnome-Keyring is enabled.
+
 2006-04-26  Gora Mohanty  <gmohanty@cvs.gnome.org>
 
         * configure.in: Added 'lv' (Latvian) to ALL_LINGUAS.
Index: configure.in
===================================================================
RCS file: /cvs/gnome/vino/configure.in,v
retrieving revision 1.106
diff -u -p -r1.106 configure.in
--- configure.in	26 Apr 2006 20:59:08 -0000	1.106
+++ configure.in	30 Jun 2006 08:28:43 -0000
@@ -70,6 +70,22 @@ fi
 AC_SUBST(VINO_HTTP_CFLAGS)
 AM_CONDITIONAL(HTTP_SERVER, [test "$enable_http_server" = "yes"])
 
+dnl --enable-gnome-keyring=(yes|no)
+AC_ARG_ENABLE(gnome_keyring,
+               [  --enable-gnome-keyring=[no/yes] use gnome keyring for storing
+password [default=no]],,
+               enable_gnome_keyring=no)
+if test "$enable_gnome_keyring" = "yes"; then
+  PKG_CHECK_MODULES(GNOME_KEYRING, gnome-keyring-1, with_gnome_keyring="yes", with_gnome_keyring="no");
+    if test "$with_gnome_keyring" = "yes"; then
+      AC_DEFINE(ENABLE_GNOME_KEYRING, 1, [Gnome Keyring enabled])
+    else
+      AC_DEFINE(ENABLE_GNOME_KEYRING, 0, [Gnome Keyring disabled])
+    fi
+else
+  AC_DEFINE(ENABLE_GNOME_KEYRING, 0, [Gnome Keyring disabled])
+fi
+
 #
 # If Pango included the shared library dependencies from X11 in
 # the pkg-config output, then we use that (to avoid duplicates).
Index: capplet/vino-preferences.c
===================================================================
RCS file: /cvs/gnome/vino/capplet/vino-preferences.c,v
retrieving revision 1.5
diff -u -p -r1.5 vino-preferences.c
--- capplet/vino-preferences.c	16 May 2005 13:14:57 -0000	1.5
+++ capplet/vino-preferences.c	30 Jun 2006 08:28:44 -0000
@@ -33,6 +33,10 @@
 #include <libgnomeui/libgnomeui.h>
 #include "vino-url.h"
 
+#if ENABLE_GNOME_KEYRING
+#include <gnome-keyring.h>
+#endif
+
 #define VINO_PREFS_DIR                    "/desktop/gnome/remote_access"
 #define VINO_PREFS_ENABLED                VINO_PREFS_DIR "/enabled"
 #define VINO_PREFS_PROMPT_ENABLED         VINO_PREFS_DIR "/prompt_enabled"
@@ -237,6 +241,80 @@ vino_preferences_dialog_base64_unencode 
   return retval;
 }
 
+#if ENABLE_GNOME_KEYRING
+static char *
+vino_preferences_dialog_get_password ()
+{
+  GnomeKeyringResult result;
+  GnomeKeyringNetworkPasswordData *found_item;
+
+  char *password;
+  GList *matches = NULL, *tmp;
+
+  result = gnome_keyring_find_network_password_sync (
+                NULL,           /* user */
+                NULL,           /* domain */
+                "vino.local",   /* server */
+                NULL,           /* object */
+                "rfb",          /* protocol */
+                "vnc-password", /* authtype */
+                5800,           /* port */
+                &matches);
+
+  if ( GNOME_KEYRING_RESULT_OK != result )
+    return NULL;
+  else {
+    for (tmp = matches; tmp; tmp = tmp->next){
+      found_item = (GnomeKeyringNetworkPasswordData *) tmp->data;
+      password = g_strdup (found_item->password);
+
+      return password;
+    }
+  }
+
+  return NULL;
+}
+
+static void
+vino_preferences_dialog_set_password (VinoPreferencesDialog *dialog,
+                                     const char            *password)
+{
+  GnomeKeyringResult result;
+  guint32 item_id;
+  time_t current;
+  char *buf;
+
+  result = gnome_keyring_set_network_password_sync(
+                NULL,           /*default keyring*/
+                NULL,           /*user*/
+                NULL,           /*domain*/
+                "vino.local",   /*server*/
+                NULL,           /*object*/
+                "rfb",          /*protocol*/
+                "vnc-password", /*authtype*/
+                5800,           /*port*/
+                password,       /*password*/
+                &item_id);
+
+  /* the gconf value for password will be changed to notify gconf client*/
+  buf = gconf_client_get_string (dialog->client, VINO_PREFS_VNC_PASSWORD, NULL);
+  if ('0' == buf[0])
+    buf[0] = '1';
+  else
+    buf[0] = '0'; 
+  gconf_client_set_string (dialog->client, VINO_PREFS_VNC_PASSWORD, buf, NULL);
+
+  g_free (buf);
+}
+#else
+static void
+vino_preferences_dialog_set_password (VinoPreferencesDialog *dialog,
+                                     const char            *password)
+{
+  gconf_client_set_string (dialog->client, VINO_PREFS_VNC_PASSWORD, password, NULL);
+}
+#endif /* ENABLE_GNOME_KEYRING */
+
 static void
 vino_preferences_dialog_update_for_allowed (VinoPreferencesDialog *dialog,
 					    gboolean               allowed)
@@ -551,7 +629,11 @@ vino_preferences_vnc_password_notify (GC
   if (!entry->value || entry->value->type != GCONF_VALUE_STRING)
     return;
 
+#if ENABLE_GNOME_KEYRING
+  password_b64 = vino_preferences_dialog_get_password ();
+#else
   password_b64 = gconf_value_get_string (entry->value);
+#endif
   password = vino_preferences_dialog_base64_unencode (password_b64);
 
   if (!password || !password [0])
@@ -590,8 +672,8 @@ vino_preferences_dialog_password_changed
 
       password_b64 = vino_preferences_dialog_base64_encode (password);
 
-      gconf_client_set_string (dialog->client, VINO_PREFS_VNC_PASSWORD, password_b64, NULL);
-
+      vino_preferences_dialog_set_password (dialog, password_b64);
+      
       g_free (password_b64);
     }
 }
@@ -608,7 +690,11 @@ vino_preferences_dialog_setup_password_e
   dialog->password_box = glade_xml_get_widget (dialog->xml, "password_box");
   g_assert (dialog->password_box != NULL);
 
+#if ENABLE_GNOME_KEYRING
+  password_b64 = vino_preferences_dialog_get_password ();
+#else
   password_b64 = gconf_client_get_string (dialog->client, VINO_PREFS_VNC_PASSWORD, NULL);
+#endif
   password = vino_preferences_dialog_base64_unencode (password_b64);
 
   if (password)
Index: server/vino-prefs.c
===================================================================
RCS file: /cvs/gnome/vino/server/vino-prefs.c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 vino-prefs.c
--- server/vino-prefs.c	5 Feb 2004 08:54:59 -0000	1.1.1.1
+++ server/vino-prefs.c	30 Jun 2006 08:28:44 -0000
@@ -28,6 +28,10 @@
 #include <gconf/gconf-client.h>
 #include "vino-util.h"
 
+#if ENABLE_GNOME_KEYRING
+#include <gnome-keyring.h>
+#endif
+
 #define VINO_PREFS_DIR                    "/desktop/gnome/remote_access"
 #define VINO_PREFS_ENABLED                VINO_PREFS_DIR "/enabled"
 #define VINO_PREFS_PROMPT_ENABLED         VINO_PREFS_DIR "/prompt_enabled"
@@ -49,6 +53,40 @@ static gboolean        vino_require_encr
 static VinoAuthMethod  vino_auth_methods       = VINO_AUTH_VNC;
 static char           *vino_vnc_password       = NULL;
 
+#if ENABLE_GNOME_KEYRING
+static char *
+vino_get_saved_password ()
+{
+  GnomeKeyringResult result;
+  GnomeKeyringNetworkPasswordData *found_item;
+
+  char *password;
+  GList *matches = NULL, *tmp;
+
+  result = gnome_keyring_find_network_password_sync (
+                NULL,           /* user */
+                NULL,           /* domain */
+                "vino.local",   /* server */
+                NULL,           /* object */
+                "rfb",          /* protocol */
+                "vnc-password", /* authtype */
+                5800,           /* port */
+                &matches);
+
+  if ( GNOME_KEYRING_RESULT_OK != result )
+    return NULL;
+  else {
+    for (tmp = matches; tmp; tmp = tmp->next){
+      found_item = (GnomeKeyringNetworkPasswordData *) tmp->data;
+      password = g_strdup (found_item->password);
+
+      return password;
+    }
+  }
+
+  return NULL;
+}
+#endif  /* ENABLE_GNOME_KEYRING */
 
 static void
 vino_prefs_enabled_changed (GConfClient *client,
@@ -213,7 +251,11 @@ vino_prefs_vnc_password_changed (GConfCl
   if (!entry->value || entry->value->type != GCONF_VALUE_STRING)
     return;
   
+#if ENABLE_GNOME_KEYRING
+  vnc_password = vino_get_saved_password();
+#else
   vnc_password = gconf_value_get_string (entry->value);
+#endif
 
   if (!vnc_password && !vino_vnc_password)
     return;
@@ -302,9 +344,13 @@ vino_prefs_init (gboolean view_only)
     g_free (l->data);
   g_slist_free (auth_methods_list);
 
+#if ENABLE_GNOME_KEYRING
+  vino_vnc_password = vino_get_saved_password ();
+#else
   vino_vnc_password = gconf_client_get_string (vino_client,
-					       VINO_PREFS_VNC_PASSWORD,
-					       NULL);
+                                               VINO_PREFS_VNC_PASSWORD,
+                                               NULL);
+#endif
   dprintf (PREFS, "Encoded password: %s\n", vino_vnc_password ? vino_vnc_password : "(null)");
 
   vino_listeners [i] =
