gvfs r1520 - in trunk: . common daemon



Author: otte
Date: Tue Mar  4 10:56:43 2008
New Revision: 1520
URL: http://svn.gnome.org/viewvc/gvfs?rev=1520&view=rev

Log:
2008-03-04  Benjamin Otte  <otte gnome org>

        * common/gmountsource.c: (ask_password_reply),
	(g_mount_source_ask_password_finish),
	(g_mount_source_ask_password), (op_ask_password_reply):
	* common/gmountsource.h:
	add an anonymous_out parameter for anonymous logins.
	* daemon/gvfsbackenddav.c: (soup_authenticate_interactive):
	* daemon/gvfsbackendsftp.c: (handle_login):
	* daemon/gvfsbackendsmb.c: (auth_callback):
	make the backends compile with the new parameter. They don't use
	anonymous logins.
	* daemon/gvfsbackendftp.c: (do_mount):
	make login work as users would expect it with anonymous logins.
	Fixes bug #520131



Modified:
   trunk/ChangeLog
   trunk/common/gmountsource.c
   trunk/common/gmountsource.h
   trunk/daemon/gvfsbackenddav.c
   trunk/daemon/gvfsbackendftp.c
   trunk/daemon/gvfsbackendsftp.c
   trunk/daemon/gvfsbackendsmb.c

Modified: trunk/common/gmountsource.c
==============================================================================
--- trunk/common/gmountsource.c	(original)
+++ trunk/common/gmountsource.c	Tue Mar  4 10:56:43 2008
@@ -129,6 +129,7 @@
   char          *username;
   char          *domain;
   GPasswordSave  password_save;
+  gboolean	 anonymous;
 };
 
 typedef struct AskSyncData AskSyncData;
@@ -193,10 +194,14 @@
 	{
 	  data->aborted = aborted;
 
-	  data->password = *password == 0 ? NULL : g_strdup (password);
-	  data->username = *username == 0 ? NULL : g_strdup (username);
-	  data->domain = *domain == 0 ? NULL : g_strdup (domain);
+	  if (!anonymous)
+	    {
+	      data->password = *password == 0 ? NULL : g_strdup (password);
+	      data->username = *username == 0 ? NULL : g_strdup (username);
+	      data->domain = *domain == 0 ? NULL : g_strdup (domain);
+	    }
 	  data->password_save = (GPasswordSave)password_save;
+	  data->anonymous = anonymous;
 
 	  /* TODO: handle more args */
 	}
@@ -265,6 +270,27 @@
 
 }
 
+/**
+ * g_mount_source_ask_password_finish:
+ * @source: the source to query
+ * @result: the async result
+ * @aborted: set to %TRUE if the password dialog was aborted by the user
+ * @password_out: the to the password set by the user or to %NULL if none
+ * @user_out: set to the username set by the user or to %NULL if none
+ * @domain_out: set to the domain set by the user or to %NULL if none
+ * @anonymous_out: set to %TRUE if the user selected anonymous login. This
+ *                 should only happen if G_ASK_PASSWORD_ANONYMOUS_SUPPORTED
+ *                 was supplied whe querying the password.
+ * @password_save_out: set to the save flags to use when saving the password
+ *                     in the keyring.
+ *
+ * Requests the reply parameters from a g_mount_source_ask_password_async() 
+ * request. All out parameters can be set to %NULL to ignore them.
+ * <note><para>Please be aware that all string parameters can be set to %NULL,
+ * so make sure to check them.</para></note>
+ *
+ * Returns: %FALSE if the async reply contained an error.
+ **/
 gboolean
 g_mount_source_ask_password_finish (GMountSource  *source,
                                     GAsyncResult  *result,
@@ -272,6 +298,7 @@
                                     char         **password_out,
                                     char         **user_out,
                                     char         **domain_out,
+				    gboolean	  *anonymous_out,
 				    GPasswordSave *password_save_out)
 {
   AskPasswordData *data, def = { TRUE, };
@@ -305,6 +332,9 @@
       data->domain = NULL;
     }
 
+  if (anonymous_out)
+    *anonymous_out = data->anonymous;
+
   if (password_save_out)
     *password_save_out = data->password_save;  
   
@@ -339,20 +369,12 @@
 			     char **password_out,
 			     char **user_out,
 			     char **domain_out,
+			     gboolean *anonymous_out,
 			     GPasswordSave *password_save_out)
 {
-  char *password, *username, *domain;
-  GPasswordSave password_save;
-  gboolean handled, aborted;
+  gboolean handled;
   AskSyncData data = {NULL};
   
-  if (password_out)
-    *password_out = NULL;
-  if (user_out)
-    *user_out = NULL;
-  if (domain_out)
-    *domain_out = NULL;
-  
   data.mutex = g_mutex_new ();
   data.cond = g_cond_new ();
 
@@ -376,34 +398,14 @@
 
   handled = g_mount_source_ask_password_finish (source,
                                                 data.result,
-                                                &aborted,
-                                                &password,
-                                                &username,
-                                                &domain,
-						&password_save);
+                                                aborted_out,
+                                                password_out,
+                                                user_out,
+                                                domain_out,
+						anonymous_out,
+						password_save_out);
   g_object_unref (data.result);
 
-  if (aborted_out)
-    *aborted_out = aborted;
-
-  if (password_out)
-    *password_out = password;
-  else
-    g_free (password);
-
-  if (user_out)
-    *user_out = username;
-  else
-    g_free (username);
-
-  if (domain_out)
-    *domain_out = domain;
-  else
-    g_free (domain);
-
-  if (password_save_out)
-    *password_save_out = password_save;
-  
   return handled;
 }
 
@@ -433,6 +435,7 @@
                                                 &username,
                                                 &password,
                                                 &domain,
+						NULL,
 						&password_save);
 
   if (!handled)

Modified: trunk/common/gmountsource.h
==============================================================================
--- trunk/common/gmountsource.h	(original)
+++ trunk/common/gmountsource.h	Tue Mar  4 10:56:43 2008
@@ -65,6 +65,7 @@
 						       char                     **password_out,
 						       char                     **user_out,
 						       char                     **domain_out,
+						       gboolean			 *anonymous_out,
 						       GPasswordSave             *password_save_out);
 
 void          g_mount_source_ask_password_async       (GMountSource              *mount_source,
@@ -81,6 +82,7 @@
                                                        char                     **password_out,
                                                        char                     **user_out,
                                                        char                     **domain_out,
+						       gboolean			 *anonymous_out,
 						       GPasswordSave             *password_save_out);
 
 gboolean      g_mount_source_ask_question             (GMountSource              *mount_source,

Modified: trunk/daemon/gvfsbackenddav.c
==============================================================================
--- trunk/daemon/gvfsbackenddav.c	(original)
+++ trunk/daemon/gvfsbackenddav.c	Tue Mar  4 10:56:43 2008
@@ -1062,6 +1062,7 @@
                                      &new_password,
                                      &new_username,
                                      NULL,
+				     NULL,
                                      &pw_save);
 
   if (res && !aborted)

Modified: trunk/daemon/gvfsbackendftp.c
==============================================================================
--- trunk/daemon/gvfsbackendftp.c	(original)
+++ trunk/daemon/gvfsbackendftp.c	Tue Mar  4 10:56:43 2008
@@ -83,7 +83,7 @@
 
   SoupAddress *		addr;
   char *		user;
-  char *		password;
+  char *		password;	/* password or NULL for anonymous */
 
   /* connection collection */
   GQueue *		queue;
@@ -592,8 +592,20 @@
                                 "USER %s", username);
   
   if (STATUS_GROUP (status) == 3)
-    status = ftp_connection_send (conn, 0,
-				  "PASS %s", password);
+    {
+      /* rationale for choosing the default password:
+       * - some ftp servers expect something that looks like an email address
+       * - we don't want to send the user's name or address, as that would be
+       *   a privacy problem
+       * - we want to give ftp server administrators a chance to notify us of 
+       *   problems with our client.
+       * - we don't want to drown in spam.
+       */
+      if (password == NULL)
+	password = "gvfsd-ftp-" VERSION "@example.com";
+      status = ftp_connection_send (conn, 0,
+				    "PASS %s", password);
+    }
 
   return status;
 }
@@ -927,7 +939,7 @@
   char *username;
   char *password;
   char *display_name;
-  gboolean aborted;
+  gboolean aborted, anonymous;
   GError *error = NULL;
   GPasswordSave password_save = G_PASSWORD_SAVE_NEVER;
   guint port;
@@ -966,7 +978,7 @@
       if (!g_mount_source_ask_password (
 			mount_source,
 		        prompt,
-			ftp->user ? ftp->user : "anonymous",
+			ftp->user,
 		        NULL,
 		        G_ASK_PASSWORD_NEED_USERNAME |
 		        G_ASK_PASSWORD_NEED_PASSWORD |
@@ -976,6 +988,7 @@
 		        &password,
 		        &username,
 		        NULL,
+			&anonymous,
 		        &password_save) ||
 	  aborted) 
 	{
@@ -985,12 +998,27 @@
 	}
 
 try_login:
+      DEBUG ("user: %s\n", username);
       g_free (ftp->user);
-      ftp->user = username;
       g_free (ftp->password);
-      ftp->password = password;
-      if (ftp_connection_login (conn, username, password) != 0)
-	break;
+      if (anonymous)
+	{
+	  if (ftp_connection_login (conn, "anonymous", "") != 0)
+	    {
+	      ftp->user = g_strdup ("anonymous");
+	      ftp->password = g_strdup ("");
+	      break;
+	    }
+	  ftp->user = NULL;
+	  ftp->password = NULL;
+	}
+      else
+	{
+	  ftp->user = username ? username : g_strdup ("");
+	  ftp->password = password;
+	  if (ftp_connection_login (conn, username, password) != 0)
+	    break;
+	}
       if (!g_error_matches (conn->error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED))
 	break;
 

Modified: trunk/daemon/gvfsbackendsftp.c
==============================================================================
--- trunk/daemon/gvfsbackendsftp.c	(original)
+++ trunk/daemon/gvfsbackendsftp.c	Tue Mar  4 10:56:43 2008
@@ -826,6 +826,7 @@
                                                 &new_password,
                                                 &new_user,
                                                 NULL,
+						NULL,
                                                 &password_save) ||
                   aborted)
                 {

Modified: trunk/daemon/gvfsbackendsmb.c
==============================================================================
--- trunk/daemon/gvfsbackendsmb.c	(original)
+++ trunk/daemon/gvfsbackendsmb.c	Tue Mar  4 10:56:43 2008
@@ -222,6 +222,7 @@
 						 &ask_password,
 						 &ask_user,
 						 &ask_domain,
+						 NULL,
 						 &(backend->password_save));
 	  g_free (message);
 	  if (!handled)



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