static void pw_dialog_got_response (GtkDialog *dialog, gint response_id, GtkMountOperation *mount_op) { GtkMountOperationPrivate *priv; GMountOperation *op; priv = mount_op->priv; op = G_MOUNT_OPERATION (mount_op); if (response_id == GTK_RESPONSE_OK) { const char *text; if (priv->ask_flags & G_ASK_PASSWORD_ANONYMOUS_SUPPORTED) g_mount_operation_set_anonymous (op, priv->anonymous); if (priv->username_entry) { text = gtk_entry_get_text (GTK_ENTRY (priv->username_entry)); g_mount_operation_set_username (op, text); } if (priv->domain_entry) { text = gtk_entry_get_text (GTK_ENTRY (priv->domain_entry)); g_mount_operation_set_domain (op, text); } if (priv->password_entry) { text = gtk_entry_get_text (GTK_ENTRY (priv->password_entry)); g_mount_operation_set_password (op, text); } if (priv->ask_flags & G_ASK_PASSWORD_SAVING_SUPPORTED) g_mount_operation_set_password_save (op, priv->password_save); g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED); } else g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED); priv->dialog = NULL; g_object_notify (G_OBJECT (op), "is-showing"); gtk_widget_destroy (GTK_WIDGET (dialog)); g_object_unref (op); }
static VALUE rg_reply(VALUE self, VALUE value) { g_mount_operation_reply(_SELF(self), RVAL2GMOUNTOPERATIONRESULT(value)); return self; }
static void ask_password_cb (GMountOperation *op, const char *message, const char *default_user, const char *default_domain, GAskPasswordFlags flags) { 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); } g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED); }
void MountOperationQuestionDialog::done(int r) { if(r != QDialog::Accepted) { GMountOperation* op = mountOperation->mountOperation(); g_mount_operation_reply(op, G_MOUNT_OPERATION_ABORTED); } QDialog::done(r); }
static gboolean reply_non_handled_in_idle (gpointer data) { GMountOperation *op = data; g_mount_operation_reply (op, G_MOUNT_OPERATION_UNHANDLED); return FALSE; }
void MountOperationQuestionDialog::onButtonClicked(QAbstractButton* button) { GMountOperation* op = mountOperation->mountOperation(); for(int i = 0; i < choiceCount; ++i) { if(choiceButtons[i] == button) { g_mount_operation_set_choice(op, i); g_mount_operation_reply(op, G_MOUNT_OPERATION_HANDLED); break; } } }
static void ask_question_cb (GMountOperation *op, char *message, char **choices, gpointer user_data) { char **ptr = choices; char *s; int i, choice; g_print ("%s\n", message); i = 1; while (*ptr) { g_print ("[%d] %s\n", i, *ptr++); i++; } s = prompt_for ("Choice", NULL, TRUE); if (!s) goto error; choice = atoi (s); if (choice > 0 && choice < i) { g_mount_operation_set_choice (op, choice - 1); 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 question_dialog_button_clicked (GtkDialog *dialog, gint button_number, GMountOperation *op) { GtkMountOperationPrivate *priv; GtkMountOperation *operation; operation = GTK_MOUNT_OPERATION (op); priv = operation->priv; if (button_number >= 0) { g_mount_operation_set_choice (op, button_number); g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED); } else g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED); priv->dialog = NULL; g_object_notify (G_OBJECT (operation), "is-showing"); gtk_widget_destroy (GTK_WIDGET (dialog)); g_object_unref (op); }
/** * This function is called when username or password are requested from user. * This function is called in main thread as async request from dbus. * @param mount_op mount operation * @param message message to show to user * @param default_user preffered user * @param default_domain domain name * @param flags what type of information is required * @param user_data nsIChannel */ static void mount_operation_ask_password (GMountOperation *mount_op, const char *message, const char *default_user, const char *default_domain, GAskPasswordFlags flags, gpointer user_data) { nsIChannel *channel = (nsIChannel *) user_data; if (!channel) { g_mount_operation_reply(mount_op, G_MOUNT_OPERATION_ABORTED); return; } // We can't handle request for domain if (flags & G_ASK_PASSWORD_NEED_DOMAIN) { g_mount_operation_reply(mount_op, G_MOUNT_OPERATION_ABORTED); return; } nsCOMPtr<nsIAuthPrompt> prompt; NS_QueryNotificationCallbacks(channel, prompt); // If no auth prompt, then give up. We could failover to using the // WindowWatcher service, but that might defeat a consumer's purposeful // attempt to disable authentication (for whatever reason). if (!prompt) { g_mount_operation_reply(mount_op, G_MOUNT_OPERATION_ABORTED); return; } // Parse out the host and port... nsCOMPtr<nsIURI> uri; channel->GetURI(getter_AddRefs(uri)); if (!uri) { g_mount_operation_reply(mount_op, G_MOUNT_OPERATION_ABORTED); return; } nsAutoCString scheme, hostPort; uri->GetScheme(scheme); uri->GetHostPort(hostPort); // It doesn't make sense for either of these strings to be empty. What kind // of funky URI is this? if (scheme.IsEmpty() || hostPort.IsEmpty()) { g_mount_operation_reply(mount_op, G_MOUNT_OPERATION_ABORTED); return; } // Construct the single signon key. Altering the value of this key will // cause people's remembered passwords to be forgotten. Think carefully // before changing the way this key is constructed. nsAutoString key, realm; NS_ConvertUTF8toUTF16 dispHost(scheme); dispHost.AppendLiteral("://"); dispHost.Append(NS_ConvertUTF8toUTF16(hostPort)); key = dispHost; if (*default_domain != '\0') { // We assume the realm string is ASCII. That might be a bogus assumption, // but we have no idea what encoding GnomeVFS is using, so for now we'll // limit ourselves to ISO-Latin-1. XXX What is a better solution? realm.Append('"'); realm.Append(NS_ConvertASCIItoUTF16(default_domain)); realm.Append('"'); key.Append(' '); key.Append(realm); } // Construct the message string... // // We use Necko's string bundle here. This code really should be encapsulated // behind some Necko API, after all this code is based closely on the code in // nsHttpChannel.cpp. nsCOMPtr<nsIStringBundleService> bundleSvc = do_GetService(NS_STRINGBUNDLE_CONTRACTID); if (!bundleSvc) { g_mount_operation_reply(mount_op, G_MOUNT_OPERATION_ABORTED); return; } nsCOMPtr<nsIStringBundle> bundle; bundleSvc->CreateBundle("chrome://global/locale/commonDialogs.properties", getter_AddRefs(bundle)); if (!bundle) { g_mount_operation_reply(mount_op, G_MOUNT_OPERATION_ABORTED); return; } nsAutoString nsmessage; if (flags & G_ASK_PASSWORD_NEED_PASSWORD) { if (flags & G_ASK_PASSWORD_NEED_USERNAME) { if (!realm.IsEmpty()) { const char16_t *strings[] = { realm.get(), dispHost.get() }; bundle->FormatStringFromName(MOZ_UTF16("EnterLoginForRealm2"), strings, 2, getter_Copies(nsmessage)); } else { const char16_t *strings[] = { dispHost.get() }; bundle->FormatStringFromName(MOZ_UTF16("EnterUserPasswordFor2"), strings, 1, getter_Copies(nsmessage)); } } else { NS_ConvertUTF8toUTF16 userName(default_user); const char16_t *strings[] = { userName.get(), dispHost.get() }; bundle->FormatStringFromName(MOZ_UTF16("EnterPasswordFor"), strings, 2, getter_Copies(nsmessage)); } } else { g_warning("Unknown mount operation request (flags: %x)", flags); } if (nsmessage.IsEmpty()) { g_mount_operation_reply(mount_op, G_MOUNT_OPERATION_ABORTED); return; } // Prompt the user... nsresult rv; bool retval = false; char16_t *user = nullptr, *pass = nullptr; if (default_user) { // user will be freed by PromptUsernameAndPassword user = ToNewUnicode(NS_ConvertUTF8toUTF16(default_user)); } if (flags & G_ASK_PASSWORD_NEED_USERNAME) { rv = prompt->PromptUsernameAndPassword(nullptr, nsmessage.get(), key.get(), nsIAuthPrompt::SAVE_PASSWORD_PERMANENTLY, &user, &pass, &retval); } else { rv = prompt->PromptPassword(nullptr, nsmessage.get(), key.get(), nsIAuthPrompt::SAVE_PASSWORD_PERMANENTLY, &pass, &retval); } if (NS_FAILED(rv) || !retval) { // was || user == '\0' || pass == '\0' g_mount_operation_reply(mount_op, G_MOUNT_OPERATION_ABORTED); free(user); free(pass); return; } /* GIO should accept UTF8 */ g_mount_operation_set_username(mount_op, NS_ConvertUTF16toUTF8(user).get()); g_mount_operation_set_password(mount_op, NS_ConvertUTF16toUTF8(pass).get()); free(user); free(pass); g_mount_operation_reply(mount_op, G_MOUNT_OPERATION_HANDLED); }
static void ask_password_cb (GMountOperation *op, const char *message, const char *default_user, const char *default_domain, GAskPasswordFlags flags) { if ((flags & G_ASK_PASSWORD_ANONYMOUS_SUPPORTED) && anonymous) { g_mount_operation_set_anonymous (op, TRUE); } else { char *s; g_print ("%s\n", message); 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); } 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); } 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); } } /* Only try anonymous access once. */ if (anonymous && GPOINTER_TO_INT (g_object_get_data (G_OBJECT (op), "state")) == MOUNT_OP_ASKED) { 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); } return; error: g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED); }