Exemplo n.º 1
0
static gpgme_error_t
passphrase_get (gconstpointer dummy, const gchar *passphrase_hint,
                const char* passphrase_info, int flags, int fd)
{
	GtkDialog *dialog;
	gpgme_error_t err;
	gchar **split_uid = NULL;
	gchar *label = NULL;
	gchar *errmsg = NULL;
	const gchar *pass;
	gboolean confirm = FALSE;

	if (passphrase_info && strlen(passphrase_info) < 16) {
		flags |= SEAHORSE_PASS_NEW;
		confirm = TRUE;
	}

	if (passphrase_hint)
		split_uid = g_strsplit (passphrase_hint, " ", 2);

	if (flags & SEAHORSE_PASS_BAD)
		errmsg = g_strdup_printf (_("Wrong passphrase."));

	if (split_uid && split_uid[0] && split_uid[1]) {
		if (flags & SEAHORSE_PASS_NEW)
			label = g_strdup_printf (_("Enter new passphrase for '%s'"), split_uid[1]);
		else
			label = g_strdup_printf (_("Enter passphrase for '%s'"), split_uid[1]);
	} else {
		if (flags & SEAHORSE_PASS_NEW)
			label = g_strdup (_("Enter new passphrase"));
		else
			label = g_strdup (_("Enter passphrase"));
	}

	g_strfreev (split_uid);

	dialog = seahorse_passphrase_prompt_show (_("Passphrase"), errmsg ? errmsg : label,
	                                          NULL, NULL, confirm);
	g_free (label);
	g_free (errmsg);

	switch (gtk_dialog_run (dialog)) {
	case GTK_RESPONSE_ACCEPT:
		pass = seahorse_passphrase_prompt_get (dialog);
		seahorse_util_printf_fd (fd, "%s\n", pass);
		err = GPG_OK;
		break;
	default:
		err = GPG_E (GPG_ERR_CANCELED);
		break;
	};

	gtk_widget_destroy (GTK_WIDGET (dialog));
	return err;
}
Exemplo n.º 2
0
int
main (int argc, char* argv[])
{
	GdkWindow *transient_for = NULL;
	GtkDialog *dialog;
	const gchar *title;
	const gchar *argument;
	gchar *message;
	const gchar *flags;
	gint result;
	const gchar *pass;
	gulong xid;
	gssize len;

	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	gtk_init (&argc, &argv);

	/* Non buffered stdout */
	setvbuf (stdout, 0, _IONBF, 0);

#ifdef GDK_WINDOWING_X11
	argument = g_getenv ("SEAHORSE_SSH_ASKPASS_PARENT");
	if (argument) {
		GdkDisplay *display = gdk_display_get_default ();
		if (GDK_IS_X11_DISPLAY (display)) {
			xid = strtoul (argument, NULL, 10);
			if (xid != 0)
				transient_for = gdk_x11_window_foreign_new_for_display (display, xid);
			if (transient_for == NULL)
				g_warning ("Couldn't find window to be transient for: %s", argument);
		}
	}
#endif

	title = g_getenv ("SEAHORSE_SSH_ASKPASS_TITLE");
	if (!title || !title[0])
		title = _("Enter your Secure Shell passphrase:");

	message = (gchar *)g_getenv ("SEAHORSE_SSH_ASKPASS_MESSAGE");
	if (message && message[0])
		message = g_strdup (message);
	else if (argc > 1)
		message = g_strjoinv (" ", argv + 1);
	else
		message = g_strdup (_("Enter your Secure Shell passphrase:"));

	argument = g_getenv ("SEAHORSE_SSH_ASKPASS_ARGUMENT");
	if (!argument)
		argument = "";

	flags = g_getenv ("SEAHORSE_SSH_ASKPASS_FLAGS");
	if (!flags)
		flags = "";
	if (strstr (flags, "multiple")) {
		gchar *lower = g_ascii_strdown (message, -1);

		/* Need the old passphrase */
		if (strstr (lower, "old pass")) {
			title = _("Old Key Passphrase");
			message = g_strdup_printf (_("Enter the old passphrase for: %s"), argument);

		/* Look for the new passphrase thingy */
		} else if (strstr (lower, "new pass")) {
			title = _("New Key Passphrase");
			message = g_strdup_printf (_("Enter the new passphrase for: %s"), argument);

		/* Confirm the new passphrase, just send it again */
		} else if (strstr (lower, "again")) {
			title = _("New Key Passphrase");
			message = g_strdup_printf (_("Enter the new passphrase again: %s"), argument);
		}

		g_free (lower);
	}

	dialog = seahorse_passphrase_prompt_show (title, message, _("Password:"******"");
		if (write (1, pass, len) != len) {
			g_warning ("couldn't write out password properly");
			result = 1;
		} else {
			result = 0;
		}
	}

	if (transient_for)
		g_object_unref (transient_for);
	gtk_widget_destroy (GTK_WIDGET (dialog));
	return result;
}