mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-22 14:57:02 +01:00
* Makefile.am: Build gpgkeys_http or gpgkeys_curl as needed.
* gpgkeys_curl.c (main, get_key): Minor tweaks to work with either FTP or HTTP. * gpgkeys_ftp.c: renamed to gpgkeys_curl.c.
This commit is contained in:
parent
034b095f31
commit
52595e06f6
@ -1,5 +1,12 @@
|
|||||||
2004-12-22 David Shaw <dshaw@jabberwocky.com>
|
2004-12-22 David Shaw <dshaw@jabberwocky.com>
|
||||||
|
|
||||||
|
* Makefile.am: Build gpgkeys_http or gpgkeys_curl as needed.
|
||||||
|
|
||||||
|
* gpgkeys_curl.c (main, get_key): Minor tweaks to work with either
|
||||||
|
FTP or HTTP.
|
||||||
|
|
||||||
|
* gpgkeys_ftp.c: renamed to gpgkeys_curl.c.
|
||||||
|
|
||||||
* gpgkeys_ftp.c (main, get_key): Use auth data as passed by gpg.
|
* gpgkeys_ftp.c (main, get_key): Use auth data as passed by gpg.
|
||||||
Use CURLOPT_FILE instead of CURLOPT_WRITEDATA (same option, but
|
Use CURLOPT_FILE instead of CURLOPT_WRITEDATA (same option, but
|
||||||
backwards compatible).
|
backwards compatible).
|
||||||
|
@ -19,19 +19,25 @@
|
|||||||
## Process this file with automake to produce Makefile.in
|
## Process this file with automake to produce Makefile.in
|
||||||
|
|
||||||
INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/intl
|
INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/intl
|
||||||
EXTRA_PROGRAMS = gpgkeys_ldap gpgkeys_hkp gpgkeys_http gpgkeys_finger gpgkeys_ftp
|
EXTRA_PROGRAMS = gpgkeys_ldap gpgkeys_hkp gpgkeys_http gpgkeys_finger gpgkeys_curl
|
||||||
EXTRA_SCRIPTS = gpgkeys_mailto
|
EXTRA_SCRIPTS = gpgkeys_mailto
|
||||||
libexecdir = @libexecdir@/@PACKAGE@
|
libexecdir = @libexecdir@/@PACKAGE@
|
||||||
|
|
||||||
libexec_PROGRAMS = @GPGKEYS_LDAP@ @GPGKEYS_HKP@ @GPGKEYS_HTTP@ @GPGKEYS_FINGER@ @GPGKEYS_FTP@
|
libexec_PROGRAMS = @GPGKEYS_LDAP@ @GPGKEYS_HKP@ @GPGKEYS_FINGER@
|
||||||
libexec_SCRIPTS = @GPGKEYS_MAILTO@
|
libexec_SCRIPTS = @GPGKEYS_MAILTO@
|
||||||
noinst_SCRIPTS = gpgkeys_test
|
noinst_SCRIPTS = gpgkeys_test
|
||||||
|
|
||||||
|
if HAVE_LIBCURL
|
||||||
|
libexec_PROGRAMS += @GPGKEYS_CURL@
|
||||||
|
else
|
||||||
|
libexec_PROGRAMS += @GPGKEYS_HTTP@
|
||||||
|
endif
|
||||||
|
|
||||||
gpgkeys_ldap_SOURCES = gpgkeys_ldap.c ksutil.c ksutil.h
|
gpgkeys_ldap_SOURCES = gpgkeys_ldap.c ksutil.c ksutil.h
|
||||||
gpgkeys_hkp_SOURCES = gpgkeys_hkp.c ksutil.c ksutil.h
|
gpgkeys_hkp_SOURCES = gpgkeys_hkp.c ksutil.c ksutil.h
|
||||||
gpgkeys_http_SOURCES = gpgkeys_http.c ksutil.c ksutil.h
|
gpgkeys_http_SOURCES = gpgkeys_http.c ksutil.c ksutil.h
|
||||||
gpgkeys_finger_SOURCES = gpgkeys_finger.c ksutil.c ksutil.h
|
gpgkeys_finger_SOURCES = gpgkeys_finger.c ksutil.c ksutil.h
|
||||||
gpgkeys_ftp_SOURCES = gpgkeys_ftp.c ksutil.c ksutil.h
|
gpgkeys_curl_SOURCES = gpgkeys_curl.c ksutil.c ksutil.h
|
||||||
|
|
||||||
other_libs = $(LIBICONV) $(LIBINTL) $(CAPLIBS)
|
other_libs = $(LIBICONV) $(LIBINTL) $(CAPLIBS)
|
||||||
|
|
||||||
@ -39,5 +45,5 @@ gpgkeys_ldap_LDADD = ../util/libutil.a @LDAPLIBS@ @NETLIBS@ $(other_libs) @GETOP
|
|||||||
gpgkeys_hkp_LDADD = ../util/libutil.a @NETLIBS@ @SRVLIBS@ $(other_libs) @GETOPT@ @W32LIBS@
|
gpgkeys_hkp_LDADD = ../util/libutil.a @NETLIBS@ @SRVLIBS@ $(other_libs) @GETOPT@ @W32LIBS@
|
||||||
gpgkeys_http_LDADD = ../util/libutil.a @NETLIBS@ @SRVLIBS@ $(other_libs) @GETOPT@ @W32LIBS@
|
gpgkeys_http_LDADD = ../util/libutil.a @NETLIBS@ @SRVLIBS@ $(other_libs) @GETOPT@ @W32LIBS@
|
||||||
gpgkeys_finger_LDADD = ../util/libutil.a @NETLIBS@ $(other_libs) @GETOPT@ @W32LIBS@
|
gpgkeys_finger_LDADD = ../util/libutil.a @NETLIBS@ $(other_libs) @GETOPT@ @W32LIBS@
|
||||||
gpgkeys_ftp_CPPFLAGS = @LIBCURL_INCLUDES@
|
gpgkeys_curl_CPPFLAGS = @LIBCURL_INCLUDES@
|
||||||
gpgkeys_ftp_LDADD = @LIBCURL@ @GETOPT@
|
gpgkeys_curl_LDADD = @LIBCURL@ @GETOPT@
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* gpgkeys_ftp.c - fetch a key via FTP
|
/* gpgkeys_curl.c - fetch a key via libcurl
|
||||||
* Copyright (C) 2004 Free Software Foundation, Inc.
|
* Copyright (C) 2004 Free Software Foundation, Inc.
|
||||||
*
|
*
|
||||||
* This file is part of GnuPG.
|
* This file is part of GnuPG.
|
||||||
@ -35,22 +35,33 @@ extern char *optarg;
|
|||||||
extern int optind;
|
extern int optind;
|
||||||
|
|
||||||
#define GET 0
|
#define GET 0
|
||||||
|
#define MAX_SCHEME 20
|
||||||
#define MAX_LINE 80
|
#define MAX_LINE 80
|
||||||
#define MAX_PATH 1023
|
#define MAX_PATH 1023
|
||||||
#define MAX_AUTH 127
|
#define MAX_AUTH 127
|
||||||
#define MAX_HOST 79
|
#define MAX_HOST 79
|
||||||
#define MAX_PORT 9
|
#define MAX_PORT 9
|
||||||
#define MAX_URL (3+3+MAX_AUTH+1+MAX_HOST+1+1+MAX_PORT+1+1+MAX_PATH+1+50)
|
#define MAX_URL (MAX_SCHEME+3+MAX_AUTH+1+1+MAX_HOST+1+1+MAX_PORT+1+1+MAX_PATH+1+50)
|
||||||
|
|
||||||
#define STRINGIFY(x) #x
|
#define STRINGIFY(x) #x
|
||||||
#define MKSTRING(x) STRINGIFY(x)
|
#define MKSTRING(x) STRINGIFY(x)
|
||||||
|
|
||||||
static int verbose=0;
|
static int verbose=0;
|
||||||
static char auth[MAX_AUTH+1],host[MAX_HOST+1]={'\0'},port[MAX_PORT+1]={'\0'},path[MAX_PATH+1]={'\0'};
|
static char scheme[MAX_SCHEME+1],auth[MAX_AUTH+1],host[MAX_HOST+1]={'\0'},port[MAX_PORT+1]={'\0'},path[MAX_PATH+1]={'\0'};
|
||||||
static FILE *input=NULL,*output=NULL,*console=NULL;
|
static FILE *input=NULL,*output=NULL,*console=NULL;
|
||||||
static CURL *curl;
|
static CURL *curl;
|
||||||
static char request[MAX_URL]={'\0'};
|
static char request[MAX_URL]={'\0'};
|
||||||
|
|
||||||
|
static int
|
||||||
|
curl_err_to_gpg_err(CURLcode error)
|
||||||
|
{
|
||||||
|
switch(error)
|
||||||
|
{
|
||||||
|
case CURLE_FTP_COULDNT_RETR_FILE: return KEYSERVER_KEY_NOT_FOUND;
|
||||||
|
default: return KEYSERVER_INTERNAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
get_key(char *getkey)
|
get_key(char *getkey)
|
||||||
{
|
{
|
||||||
@ -62,7 +73,7 @@ get_key(char *getkey)
|
|||||||
|
|
||||||
fprintf(output,"KEY 0x%s BEGIN\n",getkey);
|
fprintf(output,"KEY 0x%s BEGIN\n",getkey);
|
||||||
|
|
||||||
sprintf(request,"ftp://%s%s%s%s%s%s%s",auth[0]?auth:"",auth[0]?"@":"",
|
sprintf(request,"%s://%s%s%s%s%s%s%s",scheme,auth[0]?auth:"",auth[0]?"@":"",
|
||||||
host,port[0]?":":"",port[0]?port:"",path[0]?"":"/",path);
|
host,port[0]?":":"",port[0]?port:"",path[0]?"":"/",path);
|
||||||
|
|
||||||
curl_easy_setopt(curl,CURLOPT_URL,request);
|
curl_easy_setopt(curl,CURLOPT_URL,request);
|
||||||
@ -70,7 +81,7 @@ get_key(char *getkey)
|
|||||||
curl_easy_setopt(curl,CURLOPT_FILE,output);
|
curl_easy_setopt(curl,CURLOPT_FILE,output);
|
||||||
curl_easy_setopt(curl,CURLOPT_ERRORBUFFER,errorbuffer);
|
curl_easy_setopt(curl,CURLOPT_ERRORBUFFER,errorbuffer);
|
||||||
|
|
||||||
if(verbose>2)
|
if(verbose>1)
|
||||||
{
|
{
|
||||||
curl_easy_setopt(curl,CURLOPT_STDERR,console);
|
curl_easy_setopt(curl,CURLOPT_STDERR,console);
|
||||||
curl_easy_setopt(curl,CURLOPT_VERBOSE,TRUE);
|
curl_easy_setopt(curl,CURLOPT_VERBOSE,TRUE);
|
||||||
@ -79,10 +90,9 @@ get_key(char *getkey)
|
|||||||
res=curl_easy_perform(curl);
|
res=curl_easy_perform(curl);
|
||||||
if(res!=0)
|
if(res!=0)
|
||||||
{
|
{
|
||||||
fprintf(console,"gpgkeys: FTP fetch error %d: %s\n",res,errorbuffer);
|
fprintf(console,"gpgkeys: %s fetch error %d: %s\n",scheme,
|
||||||
fprintf(output,"KEY 0x%s FAILED %d\n",getkey,
|
res,errorbuffer);
|
||||||
(res==CURLE_FTP_COULDNT_RETR_FILE)?KEYSERVER_KEY_NOT_FOUND:
|
fprintf(output,"KEY 0x%s FAILED %d\n",getkey,curl_err_to_gpg_err(res));
|
||||||
KEYSERVER_INTERNAL_ERROR);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fprintf(output,"KEY 0x%s END\n",getkey);
|
fprintf(output,"KEY 0x%s END\n",getkey);
|
||||||
@ -111,7 +121,7 @@ main(int argc,char *argv[])
|
|||||||
/* Kludge to implement standard GNU options. */
|
/* Kludge to implement standard GNU options. */
|
||||||
if (argc > 1 && !strcmp (argv[1], "--version"))
|
if (argc > 1 && !strcmp (argv[1], "--version"))
|
||||||
{
|
{
|
||||||
fputs ("gpgkeys_ftp (GnuPG) " VERSION"\n", stdout);
|
fputs ("gpgkeys_curl (GnuPG) " VERSION"\n", stdout);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if (argc > 1 && !strcmp (argv[1], "--help"))
|
else if (argc > 1 && !strcmp (argv[1], "--help"))
|
||||||
@ -186,9 +196,15 @@ main(int argc,char *argv[])
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(sscanf(line,"SCHEME %" MKSTRING(MAX_SCHEME) "s\n",scheme)==1)
|
||||||
|
{
|
||||||
|
scheme[MAX_SCHEME]='\0';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if(sscanf(line,"AUTH %" MKSTRING(MAX_AUTH) "s\n",auth)==1)
|
if(sscanf(line,"AUTH %" MKSTRING(MAX_AUTH) "s\n",auth)==1)
|
||||||
{
|
{
|
||||||
host[MAX_AUTH]='\0';
|
auth[MAX_AUTH]='\0';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,6 +269,26 @@ main(int argc,char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(scheme[0]=='\0')
|
||||||
|
{
|
||||||
|
fprintf(console,"gpgkeys: no scheme supplied!\n");
|
||||||
|
return KEYSERVER_SCHEME_NOT_FOUND;
|
||||||
|
}
|
||||||
|
#ifndef HTTP_SUPPORT
|
||||||
|
else if(strcasecmp(scheme,"http")==0)
|
||||||
|
{
|
||||||
|
fprintf(console,"gpgkeys: scheme `%s' not supported\n",scheme);
|
||||||
|
return KEYSERVER_SCHEME_NOT_FOUND;
|
||||||
|
}
|
||||||
|
#endif /* HTTP_SUPPORT */
|
||||||
|
#ifndef FTP_SUPPORT
|
||||||
|
else if(strcasecmp(scheme,"ftp")==0)
|
||||||
|
{
|
||||||
|
fprintf(console,"gpgkeys: scheme `%s' not supported\n",scheme);
|
||||||
|
return KEYSERVER_SCHEME_NOT_FOUND;
|
||||||
|
}
|
||||||
|
#endif /* FTP_SUPPORT */
|
||||||
|
|
||||||
if(timeout && register_timeout()==-1)
|
if(timeout && register_timeout()==-1)
|
||||||
{
|
{
|
||||||
fprintf(console,"gpgkeys: unable to register timeout handler\n");
|
fprintf(console,"gpgkeys: unable to register timeout handler\n");
|
||||||
@ -318,8 +354,9 @@ main(int argc,char *argv[])
|
|||||||
fprintf(output,"VERSION %d\n",KEYSERVER_PROTO_VERSION);
|
fprintf(output,"VERSION %d\n",KEYSERVER_PROTO_VERSION);
|
||||||
fprintf(output,"PROGRAM %s\n\n",VERSION);
|
fprintf(output,"PROGRAM %s\n\n",VERSION);
|
||||||
|
|
||||||
if(verbose>1)
|
if(verbose)
|
||||||
{
|
{
|
||||||
|
fprintf(console,"Scheme:\t\t%s\n",scheme);
|
||||||
fprintf(console,"Host:\t\t%s\n",host);
|
fprintf(console,"Host:\t\t%s\n",host);
|
||||||
if(port[0])
|
if(port[0])
|
||||||
fprintf(console,"Port:\t\t%s\n",port);
|
fprintf(console,"Port:\t\t%s\n",port);
|
Loading…
x
Reference in New Issue
Block a user