* keyserver.c (path_makes_direct): New. (keyserver_spawn): Used here
authorDavid Shaw <dshaw@jabberwocky.com>
Thu, 27 Apr 2006 03:14:17 +0000 (03:14 +0000)
committerDavid Shaw <dshaw@jabberwocky.com>
Thu, 27 Apr 2006 03:14:17 +0000 (03:14 +0000)
to add "_uri" to certain gpgkeys_xxx helpers when the meaning is
different if a path is provided (i.e. ldap).

g10/ChangeLog
g10/keyserver.c

index eb16eba..a3ba904 100644 (file)
@@ -1,3 +1,10 @@
+2006-04-26  David Shaw  <dshaw@jabberwocky.com>
+
+       * keyserver.c (path_makes_direct): New.
+       (keyserver_spawn): Used here to add "_uri" to certain gpgkeys_xxx
+       helpers when the meaning is different if a path is provided
+       (i.e. ldap).
+
 2006-04-22  David Shaw  <dshaw@jabberwocky.com>
 
        * keyserver.c: Fix build problem with platforms that stick libcurl
index a4e890c..f5044f7 100644 (file)
 #include "keyserver-internal.h"
 #include "util.h"
 
-#define GPGKEYS_PREFIX "gpgkeys_"
-
-#if defined(HAVE_LIBCURL) || defined(FAKE_CURL)
-#define GPGKEYS_CURL "gpgkeys_curl"
-#endif
-
-#ifdef GPGKEYS_CURL
-#define GPGKEYS_PREFIX_LEN (strlen(GPGKEYS_PREFIX)+strlen(GPGKEYS_CURL))
-#else
-#define GPGKEYS_PREFIX_LEN (strlen(GPGKEYS_PREFIX))
-#endif
-
 struct keyrec
 {
   KEYDB_SEARCH_DESC desc;
@@ -415,7 +403,7 @@ parse_keyserver_uri(const char *string,int require_scheme,
       else
        keyserver->path=xstrdup("/");
 
-      if(keyserver->path[1]!='\0')
+      if(keyserver->path[1])
        keyserver->flags.direct_uri=1;
     }
   else if(uri[0]!='/')
@@ -937,19 +925,20 @@ keyserver_typemap(const char *type)
     return type;
 }
 
-#ifdef GPGKEYS_CURL
 /* The PGP LDAP and the curl fetch-a-LDAP-object methodologies are
    sufficiently different that we can't use curl to do LDAP. */
 static int
-curl_cant_handle(const char *scheme,unsigned int direct_uri)
+direct_uri_map(const char *scheme,unsigned int is_direct)
 {
-  if(!direct_uri && (strcmp(scheme,"ldap")==0 || strcmp(scheme,"ldaps")==0))
+  if(is_direct && strcmp(scheme,"ldap")==0)
     return 1;
 
   return 0;
 }
-#endif
 
+#define GPGKEYS_PREFIX "gpgkeys_"
+#define GPGKEYS_CURL GPGKEYS_PREFIX "curl" EXEEXT
+#define GPGKEYS_PREFIX_LEN (strlen(GPGKEYS_CURL))
 #define KEYSERVER_ARGS_KEEP " -o \"%O\" \"%I\""
 #define KEYSERVER_ARGS_NOKEEP " -o \"%o\" \"%i\""
 
@@ -1017,19 +1006,29 @@ keyserver_spawn(enum ks_action action,STRLIST list,KEYDB_SEARCH_DESC *desc,
 
   end=command+strlen(command);
 
+  /* Build a path for the keyserver helper.  If it is direct_uri
+     (i.e. an object fetch and not a keyserver), then add "_uri" to
+     the end to distinguish the keyserver helper from an object
+     fetcher that can speak that protocol (this is a problem for
+     LDAP). */
+
   strcat(command,GPGKEYS_PREFIX); 
   strcat(command,scheme);
 
-  if(keyserver->flags.direct_uri)
-    strcat(command,"uri");
+  /* This "_uri" thing is in case we need to call a direct handler
+     instead of the keyserver handler.  This lets us use gpgkeys_curl
+     or gpgkeys_ldap_uri (we don't provide it, but a user might)
+     instead of gpgkeys_ldap to fetch things like
+     ldap://keyserver.pgp.com/o=PGP%20keys?pgpkey?sub?pgpkeyid=99242560 */
+
+  if(direct_uri_map(scheme,keyserver->flags.direct_uri))
+    strcat(command,"_uri");
 
   strcat(command,EXEEXT);
 
-#ifdef GPGKEYS_CURL
-  if(!curl_cant_handle(scheme,keyserver->flags.direct_uri)
-     && path_access(command,X_OK)!=0)
+  /* Can we execute it?  If not, try curl as our catchall. */
+  if(path_access(command,X_OK)!=0)
     strcpy(end,GPGKEYS_CURL);
-#endif
 
   if(opt.keyserver_options.options&KEYSERVER_USE_TEMP_FILES)
     {
@@ -1946,15 +1945,6 @@ keyserver_fetch(STRLIST urilist)
        {
          int rc;
 
-         /*
-           Set the direct_uri flag so we know later to call a direct
-           handler instead of the keyserver style.  This lets us use
-           gpgkeys_curl or gpgkeys_ldapuri instead of gpgkeys_ldap to
-           fetch things like
-           ldap://keyserver.pgp.com/o=PGP%20keys?pgpkey?sub?pgpkeyid=99242560
-         */
-         spec->flags.direct_uri=1;
-
          rc=keyserver_work(KS_GET,NULL,&desc,1,NULL,NULL,spec);
          if(rc)
            log_info (_("WARNING: unable to fetch URI %s: %s\n"),