[Gpa-commits] r725 - in trunk: . m4 src

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Fri Nov 18 17:23:17 CET 2005


Author: werner
Date: 2005-11-18 17:23:16 +0100 (Fri, 18 Nov 2005)
New Revision: 725

Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/m4/ChangeLog
   trunk/m4/gpgme.m4
   trunk/src/ChangeLog
   trunk/src/gpacontext.c
   trunk/src/gpgmetools.c
   trunk/src/keylist.c
   trunk/src/keyring.c
Log:
Now uses the new glib version of gpgme.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2005-11-17 17:51:09 UTC (rev 724)
+++ trunk/ChangeLog	2005-11-18 16:23:16 UTC (rev 725)
@@ -1,3 +1,7 @@
+2005-11-18  Werner Koch  <wk at g10code.com>
+
+	* configure.ac (AM_PATH_GPGME_GLIB): New; replaces AM_PATH_GPGME.
+
 2005-11-15  Werner Koch  <wk at g10code.com>
 
 	* autogen.sh <build-w32>:  Updated to support Debian's mingw kit.

Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2005-11-17 17:51:09 UTC (rev 724)
+++ trunk/configure.ac	2005-11-18 16:23:16 UTC (rev 725)
@@ -159,9 +159,9 @@
             CFLAGS="$CFLAGS $GTK_CFLAGS"],
             AC_MSG_ERROR(Cannot find GTK+ 2.0))
 
-AM_PATH_GPGME(0.4.5,
-            [LIBS="$LIBS $GPGME_LIBS"
-            CFLAGS="$CFLAGS $GPGME_CFLAGS"],
+AM_PATH_GPGME_GLIB(1.2.0,
+            [LIBS="$LIBS $GPGME_GLIB_LIBS"
+            CFLAGS="$CFLAGS $GPGME_GLIB_CFLAGS"],
             AC_MSG_ERROR(Cannot find an up to date GPGME))
 
 dnl

Modified: trunk/m4/ChangeLog
===================================================================
--- trunk/m4/ChangeLog	2005-11-17 17:51:09 UTC (rev 724)
+++ trunk/m4/ChangeLog	2005-11-18 16:23:16 UTC (rev 725)
@@ -1,3 +1,7 @@
+2005-11-18  Werner Koch  <wk at g10code.com>
+
+	* gpgme.m4: Updated.
+
 2005-10-21  Werner Koch  <wk at g10code.com>
 
 	* Makefile.am: Add check_zlib.m4 and gpgme.m4.

Modified: trunk/m4/gpgme.m4
===================================================================
--- trunk/m4/gpgme.m4	2005-11-17 17:51:09 UTC (rev 724)
+++ trunk/m4/gpgme.m4	2005-11-18 16:23:16 UTC (rev 725)
@@ -236,3 +236,72 @@
   AC_SUBST(GPGME_PTHREAD_CFLAGS)
   AC_SUBST(GPGME_PTHREAD_LIBS)
 ])
+
+
+dnl AM_PATH_GPGME_GLIB([MINIMUM-VERSION,
+dnl               [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
+dnl Test for libgpgme-glib and define GPGME_GLIB_CFLAGS and GPGME_GLIB_LIBS.
+dnl
+AC_DEFUN([AM_PATH_GPGME_GLIB],
+[ AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
+  tmp=ifelse([$1], ,1:0.4.2,$1)
+  if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
+     req_gpgme_api=`echo "$tmp"     | sed 's/\(.*\):\(.*\)/\1/'`
+     min_gpgme_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
+  else
+     req_gpgme_api=0
+     min_gpgme_version="$tmp"
+  fi
+
+  AC_MSG_CHECKING(for GPGME - version >= $min_gpgme_version)
+  ok=no
+  if test "$GPGME_CONFIG" != "no" ; then
+    req_major=`echo $min_gpgme_version | \
+               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
+    req_minor=`echo $min_gpgme_version | \
+               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
+    req_micro=`echo $min_gpgme_version | \
+               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
+    if test "$gpgme_version_major" -gt "$req_major"; then
+        ok=yes
+    else 
+        if test "$gpgme_version_major" -eq "$req_major"; then
+            if test "$gpgme_version_minor" -gt "$req_minor"; then
+               ok=yes
+            else
+               if test "$gpgme_version_minor" -eq "$req_minor"; then
+                   if test "$gpgme_version_micro" -ge "$req_micro"; then
+                     ok=yes
+                   fi
+               fi
+            fi
+        fi
+    fi
+  fi
+  if test $ok = yes; then
+     # If we have a recent GPGME, we should also check that the
+     # API is compatible.
+     if test "$req_gpgme_api" -gt 0 ; then
+        tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
+        if test "$tmp" -gt 0 ; then
+           if test "$req_gpgme_api" -ne "$tmp" ; then
+             ok=no
+           fi
+        fi
+     fi
+  fi
+  if test $ok = yes; then
+    GPGME_GLIB_CFLAGS=`$GPGME_CONFIG --glib --cflags`
+    GPGME_GLIB_LIBS=`$GPGME_CONFIG --glib --libs`
+    AC_MSG_RESULT(yes)
+    ifelse([$2], , :, [$2])
+  else
+    GPGME_GLIB_CFLAGS=""
+    GPGME_GLIB_LIBS=""
+    AC_MSG_RESULT(no)
+    ifelse([$3], , :, [$3])
+  fi
+  AC_SUBST(GPGME_GLIB_CFLAGS)
+  AC_SUBST(GPGME_GLIB_LIBS)
+])
+

Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2005-11-17 17:51:09 UTC (rev 724)
+++ trunk/src/ChangeLog	2005-11-18 16:23:16 UTC (rev 725)
@@ -1,5 +1,11 @@
 2005-11-16  Werner Koch  <wk at g10code.com>
 
+	* gpgmetools.c (gpa_key_validity_string): Handle case of missing UID.
+	(gpa_gpgme_key_get_userid): Ditto.
+	* keyring.c (keyring_details_page_fill_key): Ditto.
+	* keylist.c (gpa_keylist_next): Check for zero fingerprints.
+	(is_zero_fpr): New.
+
 	* gpacontext.c (gpa_context_register_cb) [W32]: Translate file
 	descriptor.
 	(gpa_context_passphrase_cb) [W32]: Ditto.

Modified: trunk/src/gpacontext.c
===================================================================
--- trunk/src/gpacontext.c	2005-11-17 17:51:09 UTC (rev 724)
+++ trunk/src/gpacontext.c	2005-11-18 16:23:16 UTC (rev 725)
@@ -20,9 +20,6 @@
 
 #include <glib.h>
 #include <gpgme.h>
-#ifdef G_OS_WIN32
-#include <io.h>
-#endif
 #include "gpgmetools.h"
 #include "gpacontext.h"
 
@@ -262,7 +259,9 @@
 {
   struct gpa_io_cb_data *cb =  data;
 
-  cb->fnc (cb->fnc_data, g_io_channel_unix_get_fd (source));
+  /* We have to use the GPGME provided "file descriptor" here.  It may
+     not be a system file descriptor after all.  */
+  cb->fnc (cb->fnc_data, cb->fd);
 
   return TRUE;
 }
@@ -274,13 +273,25 @@
 {
   GIOChannel *channel;
  
+#ifdef G_OS_WIN32
+  /* We have to ask GPGME for the GIOChannel to use.  The "file
+     descriptor" may not be a system file descriptor.  */
+  channel = gpgme_get_giochannel (cb->fd);
+  g_assert (channel);
+#else
   channel = g_io_channel_unix_new (cb->fd);
+#endif
+
   cb->watch = g_io_add_watch_full (channel, G_PRIORITY_DEFAULT, 
 				   cb->dir ? READ_CONDITION : WRITE_CONDITION,
 				   gpa_io_cb, cb, NULL);
   cb->registered = TRUE;
-  
+
+#ifdef G_OS_WIN32
+  /* Nothing do to here.  */
+#else
   g_io_channel_unref (channel);
+#endif
 }
 
 /* Queuing callbacks until the START event arrives */
@@ -339,20 +350,6 @@
   GpaContext *context = data;
   struct gpa_io_cb_data *cb = g_malloc (sizeof (struct gpa_io_cb_data));
 
-#ifdef G_OS_WIN32
-  /* GPGME uses system file descriptors (those used with CreateFile
-     WriteFile, etc.) and not the C library ones.  glib requires a
-     C-lib one, so we have to open and associate a C library one. */ 
-  int tmp = _open_osfhandle ( fd, 0 );
-  if (tmp == -1)
-    {
-      g_warning (G_STRLOC ": _open_osfhandle (%d, 0) failed\n", fd );
-      return gpg_error (GPG_ERR_GENERAL);
-    }
-  g_print (G_STRLOC ": adding context CB at %p (fd=%d) (osf=%d)\n",
-           cb, tmp, fd);
-  fd = tmp;
-#endif
 
   cb->registered = FALSE;
   cb->fd = fd;
@@ -382,10 +379,6 @@
 {
   struct gpa_io_cb_data *cb = tag;
 
-#ifdef G_OS_WIN32
-  g_print (G_STRLOC ": removing context for CB at %p (fd=%d)\n",
-           cb, cb?cb->fd:-1);
-#endif
   if (cb->registered)
     {
       g_source_remove (cb->watch);
@@ -468,19 +461,6 @@
   GpaContext *context = hook;
   gpg_error_t err;
 
-#ifdef G_OS_WIN32
-  /* GPGME uses system file descriptors (those used with CreateFile
-     WriteFile, etc.) and not the C library ones.  glib requires a
-     C-lib one, so we have to open and associate a C library one. */ 
-  int tmp = _open_osfhandle ( fd, 1 );
-  if (tmp == -1)
-    {
-      g_warning (G_STRLOC ": _open_osfhandle (%d, 1) failed\n", fd );
-      return gpg_error (GPG_ERR_GENERAL);
-    }
-  fd = tmp;
-#endif
-
   unregister_all_callbacks (context);
   err = gpa_passphrase_cb (NULL, uid_hint, passphrase_info, prev_was_bad, fd);
   register_all_callbacks (context);

Modified: trunk/src/gpgmetools.c
===================================================================
--- trunk/src/gpgmetools.c	2005-11-17 17:51:09 UTC (rev 724)
+++ trunk/src/gpgmetools.c	2005-11-18 16:23:16 UTC (rev 725)
@@ -552,6 +552,8 @@
 const gchar *
 gpa_key_validity_string (gpgme_key_t key)
 {
+  if (!key->uids)
+    return _("Unknown");
   switch (key->uids->validity) 
     {
     case GPGME_VALIDITY_UNKNOWN:
@@ -720,6 +722,9 @@
 {
   gchar *uid_utf8;
 
+  if (!uid)
+    return g_strdup (_("[None]"));
+
   uid_utf8 = string_to_utf8 (uid->uid);
 
   /* Tag revoked UID's*/

Modified: trunk/src/keylist.c
===================================================================
--- trunk/src/keylist.c	2005-11-17 17:51:09 UTC (rev 724)
+++ trunk/src/keylist.c	2005-11-18 16:23:16 UTC (rev 725)
@@ -529,6 +529,18 @@
   return window;
 }
 
+
+/* For keys, gpg can't cope with, the fingerprint is set to all
+   zero. This helper function returns true for such a FPR. */
+static int
+is_zero_fpr (const char *fpr)
+{
+  for (; *fpr; fpr++)
+    if (*fpr != '0')
+      return 0;
+  return 1;
+}
+
 static void gpa_keylist_next (gpgme_key_t key, gpointer data)
 {
   GpaKeyList *list = data;
@@ -550,11 +562,15 @@
   ownertrust = gpa_key_ownertrust_string (key);
   validity = gpa_key_validity_string (key);
   userid = gpa_gpgme_key_get_userid (key->uids);
-  has_secret = (gpa_keytable_lookup_key (gpa_keytable_get_secret_instance(), 
-					 key->subkeys->fpr) != NULL);
-  /* Check for ElGamal signing keys and warn the user.
-   * See http://lists.gnupg.org/pipermail/gnupg-announce/2003q4/000276.html
-   * for details.
+  has_secret = (!is_zero_fpr (key->subkeys->fpr)
+                && gpa_keytable_lookup_key (gpa_keytable_get_secret_instance(),
+                                            key->subkeys->fpr));
+
+  /* Check for ElGamal signing keys and warn the user.  See
+   * http://lists.gnupg.org/pipermail/gnupg-announce/2003q4/000276.html
+   * for details. Fixme: We should remove this as current GnuPG
+   * versions dropped all support for theses keys and revoking a key
+   * is not possble anymore.
    */
   if (has_secret)
     {
@@ -585,8 +601,10 @@
       val_value = GPGME_VALIDITY_UNKNOWN-2;
   else if (key->subkeys->expired)
       val_value = GPGME_VALIDITY_UNKNOWN-1;
+  else if (key->uids)
+      val_value = key->uids->validity;
   else
-      val_value = key->uids->validity;
+      val_value = GPGME_VALIDITY_UNKNOWN;
 
   gtk_list_store_set (store, &iter,
 		      GPA_KEYLIST_COLUMN_IMAGE, get_key_pixbuf (key),

Modified: trunk/src/keyring.c
===================================================================
--- trunk/src/keyring.c	2005-11-17 17:51:09 UTC (rev 724)
+++ trunk/src/keyring.c	2005-11-18 16:23:16 UTC (rev 725)
@@ -1238,16 +1238,16 @@
 
   /* One user ID on each line.  */
   text = gpa_gpgme_key_get_userid (key->uids);
-  uid = key->uids->next;
-  while (uid)
+  if (key->uids)
     {
-      gchar *uid_string = gpa_gpgme_key_get_userid (uid);
-      gchar *tmp = text;
-      text = g_strconcat (text, "\n", uid_string, NULL);
-      g_free (tmp);
-      g_free (uid_string);
-
-      uid = uid->next;
+      for (uid = key->uids->next; uid; uid = uid->next)
+        {
+          gchar *uid_string = gpa_gpgme_key_get_userid (uid);
+          gchar *tmp = text;
+          text = g_strconcat (text, "\n", uid_string, NULL);
+          g_free (tmp);
+          g_free (uid_string);
+        }
     }
   gtk_label_set_text (GTK_LABEL (editor->detail_name), text);
   g_free (text);



More information about the Gpa-commits mailing list