/* passphrase.c - GTK+ based passphrase callback
- * Copyright (C) 2001 Werner Koch (dd9jn)
+ * Copyright (C) 2001-2006 Werner Koch (dd9jn) and the Sylpheed-Claws team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <gtk/gtksignal.h>
#include <string.h>
#include <sys/types.h>
+#ifdef G_OS_WIN32
+#include <windows.h>
+#else
#include <sys/mman.h>
+#endif
#include "passphrase.h"
#include "prefs_common.h"
gtk_entry_set_visibility(GTK_ENTRY(pass_entry), FALSE);
gtk_widget_grab_focus(pass_entry);
- gtkut_stock_button_set_create(&confirm_box, &ok_button, GTK_STOCK_OK,
+ gtkut_stock_button_set_create(&confirm_box,
&cancel_button, GTK_STOCK_CANCEL,
+ &ok_button, GTK_STOCK_OK,
NULL, NULL);
gtk_box_pack_end(GTK_BOX(vbox), confirm_box, FALSE, FALSE, 0);
gtk_widget_grab_default(ok_button);
if (pass_ack) {
const gchar *entry_text;
entry_text = gtk_entry_get_text(GTK_ENTRY(pass_entry));
- if (entry_text) /* Hmmm: Do we really need this? */
+ the_passphrase = g_locale_from_utf8(entry_text, -1, NULL, NULL, NULL);
+ if (the_passphrase == NULL)
the_passphrase = g_strdup (entry_text);
}
gtk_widget_destroy (window);
label = gtk_label_new (buf);
gtk_label_set_use_markup(GTK_LABEL (label), TRUE);
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
+ gtk_label_set_line_wrap(GTK_LABEL (label), TRUE);
g_free (buf);
return label;
static int free_passphrase(gpointer _unused)
{
if (last_pass != NULL) {
+#ifndef G_PLATFORM_WIN32
munlock(last_pass, strlen(last_pass));
+#endif
g_free(last_pass);
last_pass = NULL;
- debug_print("%% passphrase removed");
+ debug_print("%% passphrase removed\n");
}
return FALSE;
{
const char *pass;
- if (prefs_gpg_get_config()->store_passphrase && last_pass != NULL && !prev_bad) {
- write(fd, last_pass, strlen(last_pass));
- write(fd, "\n", 1);
- return GPG_ERR_NO_ERROR;
- }
+ if (prefs_gpg_get_config()->store_passphrase && last_pass && !prev_bad)
+ pass = last_pass;
+ else {
gpgmegtk_set_passphrase_grab (prefs_gpg_get_config()->passphrase_grab);
- debug_print ("%% requesting passphrase for '%s': ", uid_hint);
+ debug_print ("%% requesting passphrase for '%s'\n ", uid_hint);
pass = passphrase_mbox (uid_hint, passphrase_hint, prev_bad);
gpgmegtk_free_passphrase();
if (!pass) {
- debug_print ("%% cancel passphrase entry");
+ debug_print ("%% cancel passphrase entry\n");
write(fd, "\n", 1);
return GPG_ERR_CANCELED;
}
else {
if (prefs_gpg_get_config()->store_passphrase) {
last_pass = g_strdup(pass);
+#ifndef G_PLATFORM_WIN32
if (mlock(last_pass, strlen(last_pass)) == -1)
- debug_print("%% locking passphrase failed");
-
+ debug_print("%% locking passphrase failed\n");
+#endif
if (prefs_gpg_get_config()->store_passphrase_timeout > 0) {
- gtk_timeout_add(prefs_gpg_get_config()->store_passphrase_timeout*60*1000,
+ gtk_timeout_add(prefs_gpg_get_config()
+ ->store_passphrase_timeout*60*1000,
free_passphrase, NULL);
}
}
- debug_print ("%% sending passphrase");
+ debug_print ("%% sending passphrase\n");
+ }
}
+
+#ifdef G_OS_WIN32
+ {
+ /* Under Windows FD is actually a System handle. */
+ DWORD nwritten;
+ WriteFile ((HANDLE)fd, pass, strlen (pass), &nwritten, NULL);
+ WriteFile ((HANDLE)fd, "\n", 1, &nwritten, NULL);
+ }
+#else
write(fd, pass, strlen(pass));
write(fd, "\n", 1);
+#endif
return GPG_ERR_NO_ERROR;
}