aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
Diffstat (limited to 'mail')
-rw-r--r--mail/ChangeLog9
-rw-r--r--mail/mail-session.h6
-rw-r--r--mail/openpgp-utils.c95
-rw-r--r--mail/session.c11
4 files changed, 82 insertions, 39 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 5b06e15d96..7434ea30e2 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,5 +1,14 @@
2001-02-25 Jeffrey Stedfast <fejj@ximian.com>
+ * session.c (mail_session_forget_password): New function to force
+ the removal of a given password.
+
+ * openpgp-utils.c (openpgp_decrypt): On failure, forget the
+ passphrase.
+ (openpgp_encrypt): Here too. (cleaned this up a bit too)
+ (openpgp_clearsign): And here.
+ (openpgp_sign): Again...
+
* mail-callbacks.c (composer_postpone_cb): Abort if the message is
NULL (which is valid if an error occured).
(composer_send_cb): Same.
diff --git a/mail/mail-session.h b/mail/mail-session.h
index a2ce0b1a10..bde6c8d186 100644
--- a/mail/mail-session.h
+++ b/mail/mail-session.h
@@ -25,12 +25,12 @@
#include <gnome.h>
#include <bonobo.h>
-#include <camel/camel.h>
+#include <camel/camel-session.h>
#ifdef __cplusplus
extern "C" {
#pragma }
-#endif /* __cplusplus }*/
+#endif /* __cplusplus */
void mail_session_init (void);
void mail_session_enable_interaction (gboolean enable);
@@ -40,6 +40,8 @@ void mail_session_forget_passwords (BonoboUIComponent *uih, void *user_data,
const char *path);
void mail_session_remember_password (const char *url);
+void mail_session_forget_password (const char *key);
+
void mail_session_set_password (const char *url, const char *password);
extern CamelSession *session;
diff --git a/mail/openpgp-utils.c b/mail/openpgp-utils.c
index bb57036e60..d5ab123e09 100644
--- a/mail/openpgp-utils.c
+++ b/mail/openpgp-utils.c
@@ -61,24 +61,29 @@ static const gchar *pgp_path = NULL;
static PgpType pgp_type = PGP_TYPE_NONE;
-static gchar *
-pgp_get_passphrase (const gchar *userid)
+static const gchar *
+pgp_get_type_as_string (PgpType type)
{
- gchar *passphrase, *prompt, *type = NULL;
-
switch (pgp_type) {
case PGP_TYPE_GPG:
- type = "GnuPG";
- break;
+ return "GnuPG";
case PGP_TYPE_PGP5:
- type = "PGP5";
- break;
+ return "PGP5";
case PGP_TYPE_PGP2:
- type = "PGP2.x";
- break;
+ return "PGP2.x";
default:
g_assert_not_reached ();
+ return NULL;
}
+}
+
+static gchar *
+pgp_get_passphrase (const gchar *userid)
+{
+ gchar *passphrase, *prompt;
+ const char *type;
+
+ type = pgp_get_type_as_string (pgp_type);
if (userid)
prompt = g_strdup_printf (_("Please enter your %s passphrase for %s"),
@@ -87,13 +92,22 @@ pgp_get_passphrase (const gchar *userid)
prompt = g_strdup_printf (_("Please enter your %s passphrase"),
type);
- /* User the userid as a key if possible, else be generic and use the type */
+ /* Use the userid as a key if possible, else be generic and use the type */
passphrase = mail_session_request_dialog (prompt, TRUE, userid ? userid : type, FALSE);
g_free (prompt);
return passphrase;
}
+static void
+pgp_forget_passphrase (const char *key)
+{
+ if (!key)
+ key = pgp_get_type_as_string (pgp_type);
+
+ mail_session_forget_password (key);
+}
+
/**
* openpgp_init:
@@ -447,6 +461,8 @@ openpgp_decrypt (const gchar *ciphertext, gint cipherlen, gint *outlen, CamelExc
}
if (pipe (passwd_fds) < 0) {
+ g_free (passphrase);
+ pgp_forget_passphrase (NULL);
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
_("Couldn't create pipe to GPG/PGP: %s"),
g_strerror (errno));
@@ -503,6 +519,7 @@ openpgp_decrypt (const gchar *ciphertext, gint cipherlen, gint *outlen, CamelExc
"%s", diagnostics);
g_free (plaintext);
g_free (diagnostics);
+ pgp_forget_passphrase (NULL);
return NULL;
}
@@ -553,24 +570,36 @@ openpgp_encrypt (const gchar *in, gint inlen, const GPtrArray *recipients,
}
if (pipe (passwd_fds) < 0) {
- g_free (passphrase);
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
_("Couldn't create pipe to GPG/PGP: %s"),
g_strerror (errno));
+
+ if (sign) {
+ g_free (passphrase);
+ pgp_forget_passphrase (NULL);
+ }
+
return NULL;
}
- argv = g_ptr_array_new ();
- switch (pgp_type) {
- case PGP_TYPE_GPG:
- if (recipients->len == 0) {
+ /* check to make sure we have recipients */
+ if (recipients->len == 0) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("No recipients specified"));
+
+ if (sign) {
g_free (passphrase);
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- _("No recipients specified"));
- return NULL;
+ pgp_forget_passphrase (NULL);
}
- recipient_list = g_ptr_array_new ();
+ return NULL;
+ }
+
+ argv = g_ptr_array_new ();
+ recipient_list = g_ptr_array_new ();
+
+ switch (pgp_type) {
+ case PGP_TYPE_GPG:
for (r = 0; r < recipients->len; r++) {
char *buf, *recipient;
@@ -608,14 +637,6 @@ openpgp_encrypt (const gchar *in, gint inlen, const GPtrArray *recipients,
}
break;
case PGP_TYPE_PGP5:
- if (recipients->len == 0) {
- g_free (passphrase);
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- _("No recipients specified"));
- return NULL;
- }
-
- recipient_list = g_ptr_array_new ();
for (r = 0; r < recipients->len; r++) {
char *buf, *recipient;
@@ -647,14 +668,6 @@ openpgp_encrypt (const gchar *in, gint inlen, const GPtrArray *recipients,
}
break;
case PGP_TYPE_PGP2:
- if (recipients->len == 0) {
- g_free (passphrase);
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- _("No recipients specified"));
- return NULL;
- }
-
- recipient_list = g_ptr_array_new ();
for (r = 0; r < recipients->len; r++) {
char *buf, *recipient;
@@ -703,6 +716,8 @@ openpgp_encrypt (const gchar *in, gint inlen, const GPtrArray *recipients,
"%s", diagnostics);
g_free (ciphertext);
ciphertext = NULL;
+ if (sign)
+ pgp_forget_passphrase (NULL);
}
if (recipient_list) {
@@ -754,10 +769,13 @@ openpgp_clearsign (const gchar *plaintext, const gchar *userid,
}
if (pipe (passwd_fds) < 0) {
- g_free (passphrase);
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
_("Couldn't create pipe to GPG/PGP: %s"),
g_strerror (errno));
+
+ g_free (passphrase);
+ pgp_forget_passphrase (userid);
+
return NULL;
}
@@ -857,6 +875,7 @@ openpgp_clearsign (const gchar *plaintext, const gchar *userid,
"%s", diagnostics);
g_free (ciphertext);
ciphertext = NULL;
+ pgp_forget_passphrase (userid);
}
g_free (diagnostics);
@@ -904,6 +923,7 @@ openpgp_sign (const gchar *in, gint inlen, const gchar *userid,
if (pipe (passwd_fds) < 0) {
g_free (passphrase);
+ pgp_forget_passphrase (userid);
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
_("Couldn't create pipe to GPG/PGP: %s"),
g_strerror (errno));
@@ -1007,6 +1027,7 @@ openpgp_sign (const gchar *in, gint inlen, const gchar *userid,
"%s", diagnostics);
g_free (ciphertext);
ciphertext = NULL;
+ pgp_forget_passphrase (userid);
}
g_free (diagnostics);
diff --git a/mail/session.c b/mail/session.c
index 53c694206b..d8aeaa30ba 100644
--- a/mail/session.c
+++ b/mail/session.c
@@ -169,6 +169,17 @@ mail_session_remember_password (const char *url)
g_hash_table_foreach (passwords, maybe_remember_password, (void *) url);
}
+void
+mail_session_forget_password (const char *key)
+{
+ gpointer okey, value;
+
+ if (g_hash_table_lookup_extended (passwords, key, &okey, &value)) {
+ g_hash_table_remove (passwords, key);
+ g_free (okey);
+ g_free (value);
+ }
+}
/* ******************** */