? 344839.diff
? aaa
? server/cscope.out
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/vino/ChangeLog,v
retrieving revision 1.135
diff -u -p -r1.135 ChangeLog
--- ChangeLog	3 Jul 2006 15:00:02 -0000	1.135
+++ ChangeLog	7 Jul 2006 03:52:58 -0000
@@ -1,3 +1,23 @@
+2006-07-07  Steven Zhang <steven.zhang@sun.com>
+
+        Add support for Gnome-Keyring. This will enchance the
+        security. 
+        Fix bug #344839
+
+        * server/vino-util.h export vino_get_server_password() function
+        * server/vino-util.c add vino_get_server_password() function
+        to retrieve cleartext password.
+
+        * server/vino-prefs.c remove password_changed gconf client handler
+
+        * server/vino-server.c remove vnc_password property from VinoServerPrivate
+        and remove related set/get functions. In vino_server_auth_client(), call
+        vino_get_server_password() to get cleartext password when auth client.
+
+        * capplet/vino-preferences.c add vino_preferences_dialog_get_password
+        and vino_preferences_dialog_set_password function to get/save
+        password.
+
 2006-07-03  Runa Bhattacharjee <runabh@gmail.com>
 
         * configure.in: Added Bengali India (bn_IN) to ALL_LINGUAS.
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	7 Jul 2006 03:52:58 -0000
@@ -31,6 +31,7 @@
 #include <gconf/gconf-client.h>
 #include <libgnome/libgnome.h>
 #include <libgnomeui/libgnomeui.h>
+#include <gnome-keyring.h>
 #include "vino-url.h"
 
 #define VINO_PREFS_DIR                    "/desktop/gnome/remote_access"
@@ -237,6 +238,77 @@ vino_preferences_dialog_base64_unencode 
   return retval;
 }
 
+static char *
+vino_preferences_dialog_get_password (GConfClient *client)
+{
+  GnomeKeyringResult result;
+  GnomeKeyringNetworkPasswordData *found_item;
+  GList *matches = NULL;
+
+  char *password = NULL, *password_b64 = NULL;
+
+  result = gnome_keyring_find_network_password_sync (
+                NULL,           /* user */
+                NULL,           /* domain */
+                "vino.local",   /* server */
+                NULL,           /* object */
+                "rfb",          /* protocol */
+                "vnc-password", /* authtype */
+                5900,           /* port */
+                &matches);
+
+  if ( GNOME_KEYRING_RESULT_OK != result )
+    {
+      password_b64 = gconf_client_get_string (client,
+                                      VINO_PREFS_VNC_PASSWORD,
+                                      NULL);
+      if (password_b64)
+        {
+          password = vino_preferences_dialog_base64_unencode (password_b64);
+          g_free(password_b64);
+        }
+    }else {
+      found_item = (GnomeKeyringNetworkPasswordData *) matches->data;
+      password = g_strdup (found_item->password);
+
+      gnome_keyring_network_password_list_free (matches);
+    }
+
+  return password;
+}
+
+static void
+vino_preferences_dialog_set_password (VinoPreferencesDialog *dialog,
+                                     const char            *password)
+{
+  GnomeKeyringResult result;
+  guint32 item_id;
+
+  char *password_b64;
+
+  result = gnome_keyring_set_network_password_sync(
+                NULL,           /*default keyring*/
+                NULL,           /*user*/
+                NULL,           /*domain*/
+                "vino.local",   /*server*/
+                NULL,           /*object*/
+                "rfb",          /*protocol*/
+                "vnc-password", /*authtype*/
+                5900,           /*port*/
+                password,       /*password*/
+                &item_id);
+
+  if ( GNOME_KEYRING_RESULT_OK != result )
+    {
+      password_b64 =  vino_preferences_dialog_base64_encode(password);
+      gconf_client_set_string (dialog->client,
+                               VINO_PREFS_VNC_PASSWORD,
+                               password_b64,
+                               NULL);
+      g_free(password_b64);
+    }
+}
+
 static void
 vino_preferences_dialog_update_for_allowed (VinoPreferencesDialog *dialog,
 					    gboolean               allowed)
@@ -545,14 +617,12 @@ vino_preferences_vnc_password_notify (GC
 				      GConfEntry            *entry,
 				      VinoPreferencesDialog *dialog)
 {
-  const char *password_b64;
-  char       *password;
+  char *password = NULL;
 
   if (!entry->value || entry->value->type != GCONF_VALUE_STRING)
     return;
 
-  password_b64 = gconf_value_get_string (entry->value);
-  password = vino_preferences_dialog_base64_unencode (password_b64);
+  password = vino_preferences_dialog_get_password (client);
 
   if (!password || !password [0])
     {
@@ -586,21 +656,14 @@ vino_preferences_dialog_password_changed
     }
   else
     {
-      char *password_b64;
-
-      password_b64 = vino_preferences_dialog_base64_encode (password);
-
-      gconf_client_set_string (dialog->client, VINO_PREFS_VNC_PASSWORD, password_b64, NULL);
-
-      g_free (password_b64);
+      vino_preferences_dialog_set_password (dialog, password);
     }
 }
 
 static void
 vino_preferences_dialog_setup_password_entry (VinoPreferencesDialog *dialog)
 {
-  char *password_b64;
-  char *password;
+  char *password = NULL;
 
   dialog->password_entry = glade_xml_get_widget (dialog->xml, "password_entry");
   g_assert (dialog->password_entry != NULL);
@@ -608,19 +671,17 @@ vino_preferences_dialog_setup_password_e
   dialog->password_box = glade_xml_get_widget (dialog->xml, "password_box");
   g_assert (dialog->password_box != NULL);
 
-  password_b64 = gconf_client_get_string (dialog->client, VINO_PREFS_VNC_PASSWORD, NULL);
-  password = vino_preferences_dialog_base64_unencode (password_b64);
+  password = vino_preferences_dialog_get_password (dialog->client);
 
   if (password)
     {
       gtk_entry_set_text (GTK_ENTRY (dialog->password_entry), password);
     }
 
-  g_free (password_b64);
   g_free (password);
 
   g_signal_connect (dialog->password_entry, "changed",
-		    G_CALLBACK (vino_preferences_dialog_password_changed), dialog);
+                    G_CALLBACK (vino_preferences_dialog_password_changed), dialog);
 
   gtk_widget_set_sensitive (dialog->password_box, dialog->use_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	7 Jul 2006 03:52:58 -0000
@@ -36,7 +36,7 @@
 #define VINO_PREFS_AUTHENTICATION_METHODS VINO_PREFS_DIR "/authentication_methods"
 #define VINO_PREFS_VNC_PASSWORD           VINO_PREFS_DIR "/vnc_password"
 
-#define VINO_N_LISTENERS 6
+#define VINO_N_LISTENERS 5
 
 static GConfClient *vino_client  = NULL;
 static GSList      *vino_servers = NULL;
@@ -47,8 +47,6 @@ static gboolean        vino_prompt_enabl
 static gboolean        vino_view_only          = FALSE;
 static gboolean        vino_require_encryption = FALSE;
 static VinoAuthMethod  vino_auth_methods       = VINO_AUTH_VNC;
-static char           *vino_vnc_password       = NULL;
-
 
 static void
 vino_prefs_enabled_changed (GConfClient *client,
@@ -202,37 +200,6 @@ vino_prefs_authentication_methods_change
     vino_server_set_auth_methods (l->data, auth_methods);
 }
 
-static void
-vino_prefs_vnc_password_changed (GConfClient *client,
-				 guint        cnxn_id,
-				 GConfEntry  *entry)
-{
-  const char *vnc_password;
-  GSList     *l;
-
-  if (!entry->value || entry->value->type != GCONF_VALUE_STRING)
-    return;
-  
-  vnc_password = gconf_value_get_string (entry->value);
-
-  if (!vnc_password && !vino_vnc_password)
-    return;
-
-  if (vnc_password && vino_vnc_password &&
-      !strcmp (vnc_password, vino_vnc_password))
-    return;
-
-  if (vino_vnc_password)
-    g_free (vino_vnc_password);
-  vino_vnc_password = g_strdup (vnc_password);
-
-  dprintf (PREFS, "Encoded password changed: %s\n",
-	   vino_vnc_password ? vino_vnc_password : "(null)");
-
-  for (l = vino_servers; l; l = l->next)
-    vino_server_set_vnc_password (l->data, vnc_password);
-}
-
 void
 vino_prefs_create_server (GdkScreen *screen)
 {
@@ -244,7 +211,6 @@ vino_prefs_create_server (GdkScreen *scr
 			 "view-only",          vino_view_only,
 			 "auth-methods",       vino_auth_methods,
 			 "require-encryption", vino_require_encryption,
-			 "vnc-password",       vino_vnc_password,
 			 "on-hold",            !vino_enabled,
 			 NULL);
 
@@ -302,11 +268,6 @@ vino_prefs_init (gboolean view_only)
     g_free (l->data);
   g_slist_free (auth_methods_list);
 
-  vino_vnc_password = gconf_client_get_string (vino_client,
-					       VINO_PREFS_VNC_PASSWORD,
-					       NULL);
-  dprintf (PREFS, "Encoded password: %s\n", vino_vnc_password ? vino_vnc_password : "(null)");
-
   vino_listeners [i] =
     gconf_client_notify_add (vino_client,
 			     VINO_PREFS_ENABLED,
@@ -345,13 +306,6 @@ vino_prefs_init (gboolean view_only)
 			     NULL, NULL, NULL);
   i++;
 
-  vino_listeners [i] =
-    gconf_client_notify_add (vino_client,
-			     VINO_PREFS_VNC_PASSWORD,
-			     (GConfClientNotifyFunc) vino_prefs_vnc_password_changed,
-			     NULL, NULL, NULL);
-  i++;
-
   g_assert (i == VINO_N_LISTENERS);
 }
 
@@ -365,10 +319,6 @@ vino_prefs_shutdown (void)
     g_object_unref (l->data);
   g_slist_free (vino_servers);
   vino_servers = NULL;
-
-  if (vino_vnc_password)
-    g_free (vino_vnc_password);
-  vino_vnc_password = NULL;
       
   for (i = 0; i < VINO_N_LISTENERS; i++) {
     if (vino_listeners [i])
Index: server/vino-server.c
===================================================================
RCS file: /cvs/gnome/vino/server/vino-server.c,v
retrieving revision 1.9
diff -u -p -r1.9 vino-server.c
--- server/vino-server.c	13 Jan 2006 12:12:54 -0000	1.9
+++ server/vino-server.c	7 Jul 2006 03:52:58 -0000
@@ -57,7 +57,6 @@ struct _VinoServerPrivate
   GSList           *clients;
 
   VinoAuthMethod    auth_methods;
-  char             *vnc_password;
 
 #ifdef VINO_ENABLE_HTTP_SERVER
   VinoHTTP         *http;
@@ -92,7 +91,6 @@ enum
   PROP_VIEW_ONLY,
   PROP_REQUIRE_ENCRYPTION,
   PROP_AUTH_METHODS,
-  PROP_VNC_PASSWORD
 };
 
 static enum rfbNewClientAction vino_server_auth_client (VinoServer           *server,
@@ -444,12 +442,9 @@ vino_server_auth_client (VinoServer     
   if (!(server->priv->auth_methods & VINO_AUTH_VNC))
     goto auth_failed;
 
-  if (!server->priv->vnc_password)
-    goto auth_failed;
-
-  if (!(password = vino_base64_unencode (server->priv->vnc_password)))
+  if (!(password = vino_get_server_password()))
     {
-      g_warning ("Failed to base64 unencode VNC password\n");
+      g_warning ("Failed to get VNC password\n");
       goto auth_failed;
     }
 
@@ -733,10 +728,6 @@ vino_server_finalize (GObject *object)
    */
   g_assert (server->priv->clients == NULL);
 
-  if (server->priv->vnc_password)
-    g_free (server->priv->vnc_password);
-  server->priv->vnc_password = NULL;
-
   if (server->priv->prompt)
     g_object_unref (server->priv->prompt);
   server->priv->prompt = NULL;
@@ -784,9 +775,6 @@ vino_server_set_property (GObject      *
     case PROP_AUTH_METHODS:
       vino_server_set_auth_methods (server, g_value_get_flags (value));
       break;
-    case PROP_VNC_PASSWORD:
-      vino_server_set_vnc_password (server, g_value_get_string (value));
-      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -821,9 +809,6 @@ vino_server_get_property (GObject    *ob
     case PROP_AUTH_METHODS:
       g_value_set_flags (value, server->priv->auth_methods);
       break;
-    case PROP_VNC_PASSWORD:
-      g_value_set_string (value, server->priv->vnc_password);
-      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -895,14 +880,6 @@ vino_server_class_init (VinoServerClass 
 						       VINO_TYPE_AUTH_METHOD,
 						       VINO_AUTH_NONE,
 						       G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-  
-  g_object_class_install_property (gobject_class,
-				   PROP_VNC_PASSWORD,
-				   g_param_spec_string ("vnc-password",
-							_("VNC Password"),
-							_("The password (base64 encoded) used to authenticate types using the VncAuth method"),
-							NULL,
-							G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 }
 
 GType
@@ -1121,26 +1098,4 @@ vino_server_get_auth_methods (VinoServer
   g_return_val_if_fail (VINO_IS_SERVER (server), VINO_AUTH_INVALID);
 
   return server->priv->auth_methods;
-}
-
-void
-vino_server_set_vnc_password (VinoServer *server,
-			      const char *vnc_password)
-{
-  g_return_if_fail (VINO_IS_SERVER (server));
-
-  if (server->priv->vnc_password)
-    g_free (server->priv->vnc_password);
-
-  server->priv->vnc_password = g_strdup (vnc_password);
-
-  g_object_notify (G_OBJECT (server), "vnc-password");
-}
-
-G_CONST_RETURN char *
-vino_server_get_vnc_password (VinoServer *server)
-{
-  g_return_val_if_fail (VINO_IS_SERVER (server), NULL);
-
-  return server->priv->vnc_password;
 }
Index: server/vino-server.h
===================================================================
RCS file: /cvs/gnome/vino/server/vino-server.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 vino-server.h
--- server/vino-server.h	5 Feb 2004 08:55:02 -0000	1.1.1.1
+++ server/vino-server.h	7 Jul 2006 03:52:58 -0000
@@ -78,9 +78,6 @@ gboolean             vino_server_get_req
 void                 vino_server_set_auth_methods       (VinoServer     *server,
 							 VinoAuthMethod  auth_methods);
 VinoAuthMethod       vino_server_get_auth_methods       (VinoServer     *server);
-void                 vino_server_set_vnc_password       (VinoServer     *server,
-							 const char     *vnc_password);
-G_CONST_RETURN char *vino_server_get_vnc_password       (VinoServer     *server);
 
 G_END_DECLS
 
Index: server/vino-util.c
===================================================================
RCS file: /cvs/gnome/vino/server/vino-util.c,v
retrieving revision 1.3
diff -u -p -r1.3 vino-util.c
--- server/vino-util.c	13 Jan 2006 12:12:54 -0000	1.3
+++ server/vino-util.c	7 Jul 2006 03:52:59 -0000
@@ -25,6 +25,11 @@
 #include "vino-util.h"
 #include <gtk/gtk.h>
 #include <string.h>
+#include <gconf/gconf-client.h>
+#include <gnome-keyring.h>
+
+#define VINO_PREFS_DIR                    "/desktop/gnome/remote_access"
+#define VINO_PREFS_VNC_PASSWORD           VINO_PREFS_DIR "/vnc_password"
 
 #ifdef G_ENABLE_DEBUG
 VinoDebugFlags _vino_debug_flags = VINO_DEBUG_NONE;
@@ -211,3 +216,54 @@ vino_base64_unencode (const char *data)
 
   return retval;
 }
+
+char *
+vino_get_server_password()
+{
+  GConfClient *vino_client = NULL;
+
+  GnomeKeyringResult result;
+  GnomeKeyringNetworkPasswordData *found_item;
+  GList *matches = NULL;
+
+  char *password = NULL, *password_b64 = NULL;
+  
+  result = gnome_keyring_find_network_password_sync (
+                NULL,           /* user */
+                NULL,           /* domain */
+                "vino.local",   /* server */
+                NULL,           /* object */
+                "rfb",          /* protocol */
+                "vnc-password", /* authtype */
+                5900,           /* port */
+                &matches);
+
+  if ( GNOME_KEYRING_RESULT_OK != result )
+    {
+      vino_client = gconf_client_get_default ();
+      gconf_client_add_dir (vino_client,
+                            VINO_PREFS_DIR,
+                            GCONF_CLIENT_PRELOAD_ONELEVEL,
+                            NULL);
+
+      password_b64 = gconf_client_get_string (vino_client,
+                                      VINO_PREFS_VNC_PASSWORD,
+                                      NULL);
+      if (password_b64)
+        {
+          password = vino_base64_unencode (password_b64);
+          g_free(password_b64);
+        }
+
+      g_object_unref (vino_client);
+      vino_client = NULL;
+    } else {
+      found_item = (GnomeKeyringNetworkPasswordData *) matches->data;
+      password = g_strdup (found_item->password);
+
+      gnome_keyring_network_password_list_free (matches);
+    }
+
+  return password;
+}
+
Index: server/vino-util.h
===================================================================
RCS file: /cvs/gnome/vino/server/vino-util.h,v
retrieving revision 1.3
diff -u -p -r1.3 vino-util.h
--- server/vino-util.h	13 Jan 2006 12:12:54 -0000	1.3
+++ server/vino-util.h	7 Jul 2006 03:52:59 -0000
@@ -83,6 +83,7 @@ void vino_setup_debug_flags (void);
 
 char *vino_base64_unencode  (const char *data);
 void  vino_init_stock_items (void);
+char *vino_get_server_password();
 
 G_END_DECLS
 
