diff options
author | Ross Lagerwall <rosslagerwall@gmail.com> | 2015-01-01 10:15:46 +0200 |
---|---|---|
committer | Ross Lagerwall <rosslagerwall@gmail.com> | 2015-01-21 07:42:23 +0000 |
commit | 0803c0fdc5bfd6d9f188088643aa2bc078c4ca36 (patch) | |
tree | 6afabaa609229e0b00bfc94022f1aef23850b3bb /programs | |
parent | a0aec329939e198b6faea6b788df7278f6543436 (diff) | |
download | gvfs-0803c0fdc5bfd6d9f188088643aa2bc078c4ca36.tar.gz |
gvfs-mount: Allow mounting as an anonymous user
https://bugzilla.gnome.org/show_bug.cgi?id=742169
Diffstat (limited to 'programs')
-rw-r--r-- | programs/gvfs-mount.c | 76 |
1 files changed, 56 insertions, 20 deletions
diff --git a/programs/gvfs-mount.c b/programs/gvfs-mount.c index 96abaa24..dd31e307 100644 --- a/programs/gvfs-mount.c +++ b/programs/gvfs-mount.c @@ -38,6 +38,12 @@ #define STDIN_FILENO 0 +typedef enum { + MOUNT_OP_NONE, + MOUNT_OP_ASKED, + MOUNT_OP_ABORTED +} MountOpState; + static int outstanding_mounts = 0; static GMainLoop *main_loop; @@ -46,6 +52,7 @@ static gboolean mount_mountable = FALSE; static gboolean mount_unmount = FALSE; static gboolean mount_eject = FALSE; static gboolean force = FALSE; +static gboolean anonymous = FALSE; static gboolean mount_list = FALSE; static gboolean extra_detail = FALSE; static gboolean mount_monitor = FALSE; @@ -63,6 +70,7 @@ static const GOptionEntry entries[] = { "eject", 'e', 0, G_OPTION_ARG_NONE, &mount_eject, N_("Eject"), NULL}, { "unmount-scheme", 's', 0, G_OPTION_ARG_STRING, &unmount_scheme, N_("Unmount all mounts with the given scheme"), N_("SCHEME") }, { "force", 'f', 0, G_OPTION_ARG_NONE, &force, N_("Ignore outstanding file operations when unmounting or ejecting"), NULL }, + { "anonymous", 'a', 0, G_OPTION_ARG_NONE, &anonymous, N_("Use an anonymous user when authenticating"), NULL }, /* Translator: List here is a verb as in 'List all mounts' */ { "list", 'l', 0, G_OPTION_ARG_NONE, &mount_list, N_("List"), NULL}, { "monitor", 'o', 0, G_OPTION_ARG_NONE, &mount_monitor, N_("Monitor events"), NULL}, @@ -132,31 +140,49 @@ ask_password_cb (GMountOperation *op, const char *default_domain, GAskPasswordFlags flags) { - char *s; - g_print ("%s\n", message); - - if (flags & G_ASK_PASSWORD_NEED_USERNAME) + if ((flags & G_ASK_PASSWORD_ANONYMOUS_SUPPORTED) && anonymous) { - s = prompt_for ("User", default_user, TRUE); - g_mount_operation_set_username (op, s); - g_free (s); + g_mount_operation_set_anonymous (op, TRUE); } - - if (flags & G_ASK_PASSWORD_NEED_DOMAIN) + else { - s = prompt_for ("Domain", default_domain, TRUE); - g_mount_operation_set_domain (op, s); - g_free (s); + char *s; + g_print ("%s\n", message); + + if (flags & G_ASK_PASSWORD_NEED_USERNAME) + { + s = prompt_for ("User", default_user, TRUE); + g_mount_operation_set_username (op, s); + g_free (s); + } + + if (flags & G_ASK_PASSWORD_NEED_DOMAIN) + { + s = prompt_for ("Domain", default_domain, TRUE); + g_mount_operation_set_domain (op, s); + g_free (s); + } + + if (flags & G_ASK_PASSWORD_NEED_PASSWORD) + { + s = prompt_for ("Password", NULL, FALSE); + g_mount_operation_set_password (op, s); + g_free (s); + } } - if (flags & G_ASK_PASSWORD_NEED_PASSWORD) + /* Only try anonymous access once. */ + if (anonymous && + GPOINTER_TO_INT (g_object_get_data (G_OBJECT (op), "state")) == MOUNT_OP_ASKED) { - s = prompt_for ("Password", NULL, FALSE); - g_mount_operation_set_password (op, s); - g_free (s); + g_object_set_data (G_OBJECT (op), "state", GINT_TO_POINTER (MOUNT_OP_ABORTED)); + g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED); + } + else + { + g_object_set_data (G_OBJECT (op), "state", GINT_TO_POINTER (MOUNT_OP_ASKED)); + g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED); } - - g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED); } static void @@ -195,13 +221,17 @@ mount_mountable_done_cb (GObject *object, { GFile *target; GError *error = NULL; + GMountOperation *op = user_data; target = g_file_mount_mountable_finish (G_FILE (object), res, &error); if (target == NULL) { - g_printerr (_("Error mounting location: %s\n"), error->message); 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 + g_printerr (_("Error mounting location: %s\n"), error->message); } else g_object_unref (target); @@ -219,13 +249,17 @@ mount_done_cb (GObject *object, { gboolean succeeded; GError *error = NULL; + GMountOperation *op = user_data; succeeded = g_file_mount_enclosing_volume_finish (G_FILE (object), res, &error); if (!succeeded) { - g_printerr (_("Error mounting location: %s\n"), error->message); 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 + g_printerr (_("Error mounting location: %s\n"), error->message); } outstanding_mounts--; @@ -241,6 +275,8 @@ new_mount_op (void) op = g_mount_operation_new (); + g_object_set_data (G_OBJECT (op), "state", GINT_TO_POINTER (MOUNT_OP_NONE)); + g_signal_connect (op, "ask_password", G_CALLBACK (ask_password_cb), NULL); g_signal_connect (op, "ask_question", G_CALLBACK (ask_question_cb), NULL); |