[evolution-patches] fix for bug #50485 - encode passphrase in locale charset before sending to gpg



might also be doable by passing --charset=UTF-8 to gpg, but the man page
isn't 100% clear on what that flag actually does...

this code works and isn't that complex.

Jeff

-- 
Jeffrey Stedfast
Evolution Hacker - Ximian, Inc.
fejj ximian com  - www.ximian.com
? 24026.patch
? 49357.patch
? 50485.patch
? charset-map.c
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/camel/ChangeLog,v
retrieving revision 1.1836.2.20
diff -u -r1.1836.2.20 ChangeLog
--- ChangeLog	4 Nov 2003 21:42:59 -0000	1.1836.2.20
+++ ChangeLog	4 Nov 2003 21:45:10 -0000
@@ -1,3 +1,9 @@
+2003-11-04  Jeffrey Stedfast  <fejj ximian com>
+
+	* camel-gpg-context.c (gpg_ctx_parse_status): We might need to
+	convert the passwd from UTF-8 into the locale charset. Fixes bug
+	#50485.
+
 2003-10-28  Frederic Crozat  <fcrozat mandrakesoft com>
 
 	* camel-mime-utils.c (header_decode_date): better detection of
Index: camel-gpg-context.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/camel-gpg-context.c,v
retrieving revision 1.34
diff -u -r1.34 camel-gpg-context.c
--- camel-gpg-context.c	22 Apr 2003 18:13:49 -0000	1.34
+++ camel-gpg-context.c	4 Nov 2003 21:45:20 -0000
@@ -284,7 +284,9 @@
 	
 	unsigned int diagflushed:1;
 	
-	unsigned int padding:17;
+	unsigned int utf8:1;
+	
+	unsigned int padding:16;
 };
 
 static struct _GpgCtx *
@@ -342,6 +344,8 @@
 		CamelMimeFilterCharset *filter;
 		CamelStreamFilter *fstream;
 		
+		gpg->utf8 = FALSE;
+		
 		if ((filter = camel_mime_filter_charset_new_convert (charset, "UTF-8"))) {
 			fstream = camel_stream_filter_new_with_stream (stream);
 			camel_stream_filter_add (fstream, (CamelMimeFilter *) filter);
@@ -350,6 +354,8 @@
 			
 			stream = (CamelStream *) fstream;
 		}
+	} else {
+		gpg->utf8 = TRUE;
 	}
 	
 	gpg->diagnostics = stream;
@@ -739,6 +745,7 @@
 {
 	register unsigned char *inptr;
 	const unsigned char *status;
+	size_t nread, nwritten;
 	int len;
 	
  parse:
@@ -767,7 +774,6 @@
 	status += 9;
 	
 	if (!strncmp (status, "USERID_HINT ", 12)) {
-		size_t nread, nwritten;
 		char *hint, *user;
 		
 		status += 12;
@@ -784,7 +790,7 @@
 			goto recycle;
 		}
 		
-		if (!(user = g_locale_to_utf8 (status, -1, &nread, &nwritten, NULL)))
+		if (gpg->utf8 || !(user = g_locale_to_utf8 (status, -1, &nread, &nwritten, NULL)))
 			user = g_strdup (status);
 		
 		g_strstrip (user);
@@ -810,7 +816,16 @@
 		prompt = g_strdup_printf (_("You need a passphrase to unlock the key for\n"
 					    "user: \"%s\""), name);
 		
-		passwd = camel_session_get_password (gpg->session, prompt, FALSE, TRUE, NULL, userid, ex);
+		if ((passwd = camel_session_get_password (gpg->session, prompt, FALSE, TRUE, NULL, userid, ex)) && !gpg->utf8) {
+			char *opasswd = passwd;
+			
+			if ((passwd = g_locale_to_utf8 (passwd, -1, &nread, &nwritten, NULL))) {
+				memset (opasswd, 0, strlen (opasswd));
+				g_free (opasswd);
+			} else {
+				passwd = opasswd;
+			}
+		}
 		g_free (prompt);
 		
 		g_free (gpg->userid);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]