bug-anubis
[Top][All Lists]
Advanced

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

[bug-anubis] [patch] fix passphrase callback for gpgme


From: Brian Dessent
Subject: [bug-anubis] [patch] fix passphrase callback for gpgme
Date: Wed, 06 Apr 2005 01:11:54 -0700

I have been pulling my hair out for a while trying to figure out why I
kept getting "GPGME: Unknown Error" when trying to sign messages.  After
deugging deep in the guts of gpgme I finally figured out that the
passphrase callback function that anubis is supplying to gpgme is
completely wrong.

The current function is prototyped as "static const char *passphrase_cb
(void *hook, const char *desc, void **r_hd)", and returns a pointer to
the passphrase.  The current versions of gpgme pass 5 arguments, the
last of which is a file descriptor to which the callback is supposed to
write the passphrase, and is to return a gpgme_error_t.  Since the old
function was returning a pointer where current gpgme expects an error,
it was interpreting it as a random undefined error and thus the "Unknown
error."

I don't know when the gpgme API changed, but I use 1.0.2.

Brian

----

2005-04-06  Brian Dessent  address@hidden

        * gpg.c (passphrase_cb): Redefine arguments to match current
        gpgme spec.  Write password to 'fd' and return appropriate
        gpg_error_t value.
--- gpg.orig    2005-04-06 00:35:23.265625000 -0700
+++ gpg.c       2005-04-06 00:40:16.046875000 -0700
@@ -118,12 +118,20 @@
   return 0;
 }
 
-static const char *
-passphrase_cb (void *hook, const char *desc, void **r_hd)
+gpgme_error_t
+passphrase_cb (void *hook, const char *uid_hint, const char *passphrase_info, 
+   int prev_was_bad, int fd)
 {
-  if (!desc)
+  if (!passphrase_info)
     return 0;
-  return gpg.passphrase;
+
+  size_t len = strlen(gpg.passphrase);
+  if(write (fd, gpg.passphrase, len) != len)
+    return gpg_error(GPG_ERR_CANCELED);
+  if(write (fd, "\n", 1) != 1)
+    return gpg_error(GPG_ERR_CANCELED);
+        
+  return 0;
 }
 
 static char *

reply via email to

[Prev in Thread] Current Thread [Next in Thread]