~ubuntu-branches/ubuntu/hardy/gnupg/hardy-updates

« back to all changes in this revision

Viewing changes to g10/keyserver.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-11-03 09:18:26 UTC
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: james.westby@ubuntu.com-20061103091826-89kwl8tk1xypbmtk
Tags: upstream-1.4.5
ImportĀ upstreamĀ versionĀ 1.4.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include <string.h>
27
27
#include <stdlib.h>
28
28
#include <assert.h>
29
 
#ifdef HAVE_LIBCURL
30
 
#include <curl/curl.h>
31
 
#endif
32
29
#include "filter.h"
33
30
#include "keydb.h"
34
31
#include "status.h"
44
41
#include "keyserver-internal.h"
45
42
#include "util.h"
46
43
 
47
 
#define GPGKEYS_PREFIX "gpgkeys_"
48
 
 
49
 
#if defined(HAVE_LIBCURL) || defined(FAKE_CURL)
50
 
#define GPGKEYS_CURL "gpgkeys_curl"
51
 
#endif
52
 
 
53
 
#ifdef GPGKEYS_CURL
54
 
#define GPGKEYS_PREFIX_LEN (strlen(GPGKEYS_PREFIX)+strlen(GPGKEYS_CURL))
55
 
#else
56
 
#define GPGKEYS_PREFIX_LEN (strlen(GPGKEYS_PREFIX))
57
 
#endif
58
 
 
59
44
struct keyrec
60
45
{
61
46
  KEYDB_SEARCH_DESC desc;
418
403
      else
419
404
        keyserver->path=xstrdup("/");
420
405
 
421
 
      if(keyserver->path[1]!='\0')
 
406
      if(keyserver->path[1])
422
407
        keyserver->flags.direct_uri=1;
423
408
    }
424
409
  else if(uri[0]!='/')
940
925
    return type;
941
926
}
942
927
 
943
 
#ifdef GPGKEYS_CURL
944
928
/* The PGP LDAP and the curl fetch-a-LDAP-object methodologies are
945
929
   sufficiently different that we can't use curl to do LDAP. */
946
930
static int
947
 
curl_cant_handle(const char *scheme,unsigned int direct_uri)
 
931
direct_uri_map(const char *scheme,unsigned int is_direct)
948
932
{
949
 
  if(!direct_uri && (strcmp(scheme,"ldap")==0 || strcmp(scheme,"ldaps")==0))
 
933
  if(is_direct && strcmp(scheme,"ldap")==0)
950
934
    return 1;
951
935
 
952
936
  return 0;
953
937
}
954
 
#endif
955
938
 
 
939
#define GPGKEYS_PREFIX "gpgkeys_"
 
940
#define GPGKEYS_CURL GPGKEYS_PREFIX "curl" EXEEXT
 
941
#define GPGKEYS_PREFIX_LEN (strlen(GPGKEYS_CURL))
956
942
#define KEYSERVER_ARGS_KEEP " -o \"%O\" \"%I\""
957
943
#define KEYSERVER_ARGS_NOKEEP " -o \"%o\" \"%i\""
958
944
 
1020
1006
 
1021
1007
  end=command+strlen(command);
1022
1008
 
 
1009
  /* Build a path for the keyserver helper.  If it is direct_uri
 
1010
     (i.e. an object fetch and not a keyserver), then add "_uri" to
 
1011
     the end to distinguish the keyserver helper from an object
 
1012
     fetcher that can speak that protocol (this is a problem for
 
1013
     LDAP). */
 
1014
 
1023
1015
  strcat(command,GPGKEYS_PREFIX); 
1024
1016
  strcat(command,scheme);
1025
1017
 
1026
 
  if(keyserver->flags.direct_uri)
1027
 
    strcat(command,"uri");
 
1018
  /* This "_uri" thing is in case we need to call a direct handler
 
1019
     instead of the keyserver handler.  This lets us use gpgkeys_curl
 
1020
     or gpgkeys_ldap_uri (we don't provide it, but a user might)
 
1021
     instead of gpgkeys_ldap to fetch things like
 
1022
     ldap://keyserver.pgp.com/o=PGP%20keys?pgpkey?sub?pgpkeyid=99242560 */
 
1023
 
 
1024
  if(direct_uri_map(scheme,keyserver->flags.direct_uri))
 
1025
    strcat(command,"_uri");
1028
1026
 
1029
1027
  strcat(command,EXEEXT);
1030
1028
 
1031
 
#ifdef GPGKEYS_CURL
1032
 
  if(!curl_cant_handle(scheme,keyserver->flags.direct_uri)
1033
 
     && path_access(command,X_OK)!=0)
 
1029
  /* Can we execute it?  If not, try curl as our catchall. */
 
1030
  if(path_access(command,X_OK)!=0)
1034
1031
    strcpy(end,GPGKEYS_CURL);
1035
 
#endif
1036
1032
 
1037
1033
  if(opt.keyserver_options.options&KEYSERVER_USE_TEMP_FILES)
1038
1034
    {
1949
1945
        {
1950
1946
          int rc;
1951
1947
 
1952
 
          /*
1953
 
            Set the direct_uri flag so we know later to call a direct
1954
 
            handler instead of the keyserver style.  This lets us use
1955
 
            gpgkeys_curl or gpgkeys_ldapuri instead of gpgkeys_ldap to
1956
 
            fetch things like
1957
 
            ldap://keyserver.pgp.com/o=PGP%20keys?pgpkey?sub?pgpkeyid=99242560
1958
 
          */
1959
 
          spec->flags.direct_uri=1;
1960
 
 
1961
1948
          rc=keyserver_work(KS_GET,NULL,&desc,1,NULL,NULL,spec);
1962
1949
          if(rc)
1963
1950
            log_info (_("WARNING: unable to fetch URI %s: %s\n"),
2037
2024
 
2038
2025
          rc=keyserver_import_fprint(*fpr,*fpr_len,opt.keyserver);
2039
2026
        }
 
2027
      else
 
2028
        log_info(_("no keyserver known (use option --keyserver)\n"));
 
2029
 
 
2030
      /* Give a better string here? "CERT fingerprint for \"%s\"
 
2031
         found, but no keyserver" " known (use option
 
2032
         --keyserver)\n" ? */
2040
2033
 
2041
2034
      xfree(url);
2042
2035
    }