summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoss Lagerwall <rosslagerwall@gmail.com>2015-01-14 23:06:54 +0000
committerRoss Lagerwall <rosslagerwall@gmail.com>2015-01-21 17:25:54 +0000
commit2ddbf4d973effd7402f53a4f14798e5f945855df (patch)
tree6c334ea5c0c4163f634300e7e86ef416232dba9f
parent0803c0fdc5bfd6d9f188088643aa2bc078c4ca36 (diff)
downloadgvfs-2ddbf4d973effd7402f53a4f14798e5f945855df.tar.gz
gvfs-mount: Abort login if EOF is received
When reading a username, password or domain from the user, abort the login process if EOF is received. This eases scripting gvfs-mount and prevents an infinite loop with some backends. https://bugzilla.gnome.org/show_bug.cgi?id=742942
-rw-r--r--programs/gvfs-mount.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/programs/gvfs-mount.c b/programs/gvfs-mount.c
index dd31e307..961e2579 100644
--- a/programs/gvfs-mount.c
+++ b/programs/gvfs-mount.c
@@ -122,7 +122,12 @@ prompt_for (const char *prompt, const char *default_value, gboolean echo)
#endif
len = strlen (data);
- if (len > 0 && data[len-1] == '\n')
+ if (len == 0)
+ {
+ g_print ("\n");
+ return NULL;
+ }
+ if (data[len-1] == '\n')
data[len-1] = 0;
if (!echo)
@@ -152,6 +157,8 @@ ask_password_cb (GMountOperation *op,
if (flags & G_ASK_PASSWORD_NEED_USERNAME)
{
s = prompt_for ("User", default_user, TRUE);
+ if (!s)
+ goto error;
g_mount_operation_set_username (op, s);
g_free (s);
}
@@ -159,6 +166,8 @@ ask_password_cb (GMountOperation *op,
if (flags & G_ASK_PASSWORD_NEED_DOMAIN)
{
s = prompt_for ("Domain", default_domain, TRUE);
+ if (!s)
+ goto error;
g_mount_operation_set_domain (op, s);
g_free (s);
}
@@ -166,6 +175,8 @@ ask_password_cb (GMountOperation *op,
if (flags & G_ASK_PASSWORD_NEED_PASSWORD)
{
s = prompt_for ("Password", NULL, FALSE);
+ if (!s)
+ goto error;
g_mount_operation_set_password (op, s);
g_free (s);
}
@@ -183,6 +194,11 @@ ask_password_cb (GMountOperation *op,
g_object_set_data (G_OBJECT (op), "state", GINT_TO_POINTER (MOUNT_OP_ASKED));
g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
}
+
+ return;
+
+error:
+ g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
}
static void
@@ -205,6 +221,9 @@ ask_question_cb (GMountOperation *op,
}
s = prompt_for ("Choice", NULL, TRUE);
+ if (!s)
+ goto error;
+
choice = atoi (s);
if (choice > 0 && choice < i)
{
@@ -212,6 +231,11 @@ ask_question_cb (GMountOperation *op,
g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
}
g_free (s);
+
+ return;
+
+error:
+ g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
}
static void
@@ -230,7 +254,7 @@ mount_mountable_done_cb (GObject *object,
success = FALSE;
if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (op), "state")) == MOUNT_OP_ABORTED)
g_printerr (_("Error mounting location: Anonymous access denied\n"));
- else
+ else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED))
g_printerr (_("Error mounting location: %s\n"), error->message);
}
else
@@ -258,7 +282,7 @@ mount_done_cb (GObject *object,
success = FALSE;
if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (op), "state")) == MOUNT_OP_ABORTED)
g_printerr (_("Error mounting location: Anonymous access denied\n"));
- else
+ else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED))
g_printerr (_("Error mounting location: %s\n"), error->message);
}