aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2003-12-12 01:30:31 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2003-12-12 01:30:31 +0800
commiteb8d8f6bc042e34349e2937d2dfdd5d80664a70e (patch)
treea8dcc080b936c6b26ac1e33184d648bc4a33201f /camel
parentb44064edaa3ea4e0019faf90a05dbfb531505ac9 (diff)
downloadgsoc2013-evolution-eb8d8f6bc042e34349e2937d2dfdd5d80664a70e.tar.gz
gsoc2013-evolution-eb8d8f6bc042e34349e2937d2dfdd5d80664a70e.tar.zst
gsoc2013-evolution-eb8d8f6bc042e34349e2937d2dfdd5d80664a70e.zip
Don't immediately prompt for a passwd after receiving the NEED_PASSPHRASE
2003-12-11 Jeffrey Stedfast <fejj@ximian.com> * camel-gpg-context.c (gpg_ctx_parse_status): Don't immediately prompt for a passwd after receiving the NEED_PASSPHRASE status message. Instead, parse the userid that gpg needs a passwd for and store it on our context. Wait for a GET_HIDDEN status message before prompting, this way if the user has their gpg configured to use gpg-agent, the user won't get 2 passwd prompts. (gpg_sign): Fixed to not free a gpg context that we have not allocated (could happen in a fail case). svn path=/trunk/; revision=23925
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog11
-rw-r--r--camel/camel-gpg-context.c36
2 files changed, 34 insertions, 13 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 2dcb06243d..bdaf6f19b6 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,14 @@
+2003-12-11 Jeffrey Stedfast <fejj@ximian.com>
+
+ * camel-gpg-context.c (gpg_ctx_parse_status): Don't immediately
+ prompt for a passwd after receiving the NEED_PASSPHRASE status
+ message. Instead, parse the userid that gpg needs a passwd for and
+ store it on our context. Wait for a GET_HIDDEN status message
+ before prompting, this way if the user has their gpg configured to
+ use gpg-agent, the user won't get 2 passwd prompts.
+ (gpg_sign): Fixed to not free a gpg context that we have not
+ allocated (could happen in a fail case).
+
2003-12-10 Jeffrey Stedfast <fejj@ximian.com>
* providers/local/camel-mbox-store.c (get_folder_info): Use
diff --git a/camel/camel-gpg-context.c b/camel/camel-gpg-context.c
index f7f52fd7fd..f596dfe519 100644
--- a/camel/camel-gpg-context.c
+++ b/camel/camel-gpg-context.c
@@ -185,6 +185,7 @@ struct _GpgCtx {
unsigned char *statusptr;
unsigned int statusleft;
+ char *need_id;
char *passwd;
CamelStream *istream;
@@ -255,6 +256,7 @@ gpg_ctx_new (CamelSession *session)
gpg->bad_passwds = 0;
gpg->need_passwd = FALSE;
gpg->send_passwd = FALSE;
+ gpg->need_id = NULL;
gpg->passwd = NULL;
gpg->validsig = FALSE;
@@ -420,8 +422,12 @@ gpg_ctx_free (struct _GpgCtx *gpg)
g_free (gpg->statusbuf);
- if (gpg->passwd)
+ g_free (gpg->need_id);
+
+ if (gpg->passwd) {
+ memset (gpg->passwd, 0, strlen (gpg->passwd));
g_free (gpg->passwd);
+ }
if (gpg->istream)
camel_object_unref (gpg->istream);
@@ -731,8 +737,7 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
g_hash_table_insert (gpg->userid_hint, hint, user);
} else if (!strncmp (status, "NEED_PASSPHRASE ", 16)) {
- char *prompt, *userid, *passwd;
- const char *name;
+ char *userid;
status += 16;
@@ -743,14 +748,20 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
return -1;
}
- name = g_hash_table_lookup (gpg->userid_hint, userid);
+ g_free (gpg->need_id);
+ gpg->need_id = userid;
+ } else if (!strncmp (status, "GET_HIDDEN passphrase.enter", 27)) {
+ char *prompt, *passwd;
+ const char *name;
+
+ name = g_hash_table_lookup (gpg->userid_hint, gpg->need_id);
if (!name)
- name = userid;
+ name = gpg->need_id;
prompt = g_strdup_printf (_("You need a passphrase to unlock the key for\n"
"user: \"%s\""), name);
- if ((passwd = camel_session_get_password (gpg->session, prompt, FALSE, TRUE, NULL, userid, ex)) && !gpg->utf8) {
+ if ((passwd = camel_session_get_password (gpg->session, prompt, FALSE, TRUE, NULL, gpg->userid, ex)) && !gpg->utf8) {
char *opasswd = passwd;
if ((passwd = g_locale_to_utf8 (passwd, -1, &nread, &nwritten, NULL))) {
@@ -762,9 +773,6 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
}
g_free (prompt);
- g_free (gpg->userid);
- gpg->userid = userid;
-
if (passwd == NULL) {
if (!camel_exception_is_set (ex))
camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL, _("Cancelled."));
@@ -1221,16 +1229,16 @@ gpg_ctx_op_wait (struct _GpgCtx *gpg)
static int
gpg_sign (CamelCipherContext *context, const char *userid, CamelCipherHash hash, CamelMimePart *ipart, CamelMimePart *opart, CamelException *ex)
{
- struct _GpgCtx *gpg;
+ struct _GpgCtx *gpg = NULL;
CamelStream *ostream = camel_stream_mem_new(), *istream;
CamelDataWrapper *dw;
CamelContentType *ct;
int res = -1;
CamelMimePart *sigpart;
CamelMultipartSigned *mps;
-
+
/* Note: see rfc2015 or rfc3156, section 5 */
-
+
/* FIXME: stream this, we stream output at least */
istream = camel_stream_mem_new();
if (camel_cipher_canonical_to_stream(ipart, CAMEL_MIME_FILTER_CANON_STRIP|CAMEL_MIME_FILTER_CANON_CRLF|CAMEL_MIME_FILTER_CANON_FROM,
@@ -1311,7 +1319,9 @@ gpg_sign (CamelCipherContext *context, const char *userid, CamelCipherHash hash,
camel_medium_set_content_object((CamelMedium *)opart, (CamelDataWrapper *)mps);
fail:
camel_object_unref(ostream);
- gpg_ctx_free (gpg);
+
+ if (gpg)
+ gpg_ctx_free (gpg);
return res;
}