summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@gnome.org>2008-03-04 10:56:43 +0000
committerBenjamin Otte <otte@src.gnome.org>2008-03-04 10:56:43 +0000
commit13a1cd21fe5bbeb50c16b0a3cc68a0acb1af90b2 (patch)
tree0ea0e4ba78709e476499c5f7387edf3a963df544
parent3cd81d08a157eb3723ed105f770b8da042d9bb54 (diff)
downloadgvfs-13a1cd21fe5bbeb50c16b0a3cc68a0acb1af90b2.tar.gz
add an anonymous_out parameter for anonymous logins.
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 svn path=/trunk/; revision=1520
-rw-r--r--ChangeLog16
-rw-r--r--common/gmountsource.c81
-rw-r--r--common/gmountsource.h2
-rw-r--r--daemon/gvfsbackenddav.c1
-rw-r--r--daemon/gvfsbackendftp.c46
-rw-r--r--daemon/gvfsbackendsftp.c1
-rw-r--r--daemon/gvfsbackendsmb.c1
7 files changed, 100 insertions, 48 deletions
diff --git a/ChangeLog b/ChangeLog
index 5cea6b8d..f8e15966 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+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
+
2008-03-04 Carlos Garcia Campos <carlosgc@gnome.org>
* common/gmountspec.c: (g_mount_spec_copy):
diff --git a/common/gmountsource.c b/common/gmountsource.c
index d7bfbb18..8e9ed961 100644
--- a/common/gmountsource.c
+++ b/common/gmountsource.c
@@ -129,6 +129,7 @@ struct AskPasswordData {
char *username;
char *domain;
GPasswordSave password_save;
+ gboolean anonymous;
};
typedef struct AskSyncData AskSyncData;
@@ -193,10 +194,14 @@ ask_password_reply (DBusMessage *reply,
{
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_async (GMountSource *source,
}
+/**
+ * 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 @@ g_mount_source_ask_password_finish (GMountSource *source,
char **password_out,
char **user_out,
char **domain_out,
+ gboolean *anonymous_out,
GPasswordSave *password_save_out)
{
AskPasswordData *data, def = { TRUE, };
@@ -305,6 +332,9 @@ g_mount_source_ask_password_finish (GMountSource *source,
data->domain = NULL;
}
+ if (anonymous_out)
+ *anonymous_out = data->anonymous;
+
if (password_save_out)
*password_save_out = data->password_save;
@@ -339,20 +369,12 @@ g_mount_source_ask_password (GMountSource *source,
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 @@ g_mount_source_ask_password (GMountSource *source,
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 @@ op_ask_password_reply (GObject *source_object,
&username,
&password,
&domain,
+ NULL,
&password_save);
if (!handled)
diff --git a/common/gmountsource.h b/common/gmountsource.h
index 676595ff..e4298357 100644
--- a/common/gmountsource.h
+++ b/common/gmountsource.h
@@ -65,6 +65,7 @@ gboolean g_mount_source_ask_password (GMountSource
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 @@ gboolean g_mount_source_ask_password_finish (GMountSource
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,
diff --git a/daemon/gvfsbackenddav.c b/daemon/gvfsbackenddav.c
index a12841f9..a528b133 100644
--- a/daemon/gvfsbackenddav.c
+++ b/daemon/gvfsbackenddav.c
@@ -1062,6 +1062,7 @@ soup_authenticate_interactive (SoupSession *session,
&new_password,
&new_username,
NULL,
+ NULL,
&pw_save);
if (res && !aborted)
diff --git a/daemon/gvfsbackendftp.c b/daemon/gvfsbackendftp.c
index 927bc821..e689ff78 100644
--- a/daemon/gvfsbackendftp.c
+++ b/daemon/gvfsbackendftp.c
@@ -83,7 +83,7 @@ struct _GVfsBackendFtp
SoupAddress * addr;
char * user;
- char * password;
+ char * password; /* password or NULL for anonymous */
/* connection collection */
GQueue * queue;
@@ -592,8 +592,20 @@ ftp_connection_login (FtpConnection *conn,
"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 @@ do_mount (GVfsBackend *backend,
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 @@ do_mount (GVfsBackend *backend,
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 @@ do_mount (GVfsBackend *backend,
&password,
&username,
NULL,
+ &anonymous,
&password_save) ||
aborted)
{
@@ -985,12 +998,27 @@ do_mount (GVfsBackend *backend,
}
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;
diff --git a/daemon/gvfsbackendsftp.c b/daemon/gvfsbackendsftp.c
index 4c33e818..e2b77cea 100644
--- a/daemon/gvfsbackendsftp.c
+++ b/daemon/gvfsbackendsftp.c
@@ -826,6 +826,7 @@ handle_login (GVfsBackend *backend,
&new_password,
&new_user,
NULL,
+ NULL,
&password_save) ||
aborted)
{
diff --git a/daemon/gvfsbackendsmb.c b/daemon/gvfsbackendsmb.c
index ba91effa..5b0c302d 100644
--- a/daemon/gvfsbackendsmb.c
+++ b/daemon/gvfsbackendsmb.c
@@ -222,6 +222,7 @@ auth_callback (SMBCCTX *context,
&ask_password,
&ask_user,
&ask_domain,
+ NULL,
&(backend->password_save));
g_free (message);
if (!handled)