mirror of
git://git.gnupg.org/gnupg.git
synced 2025-02-21 19:48:05 +01:00
Removed old keyserver (daemon) code.
This commit is contained in:
parent
d208cd749b
commit
4b0497a2a9
309
g10/gpgd.c
309
g10/gpgd.c
@ -1,309 +0,0 @@
|
||||
/* gpd.c - The GnuPG daemon (keyserver)
|
||||
* Copyright (C) 1998, 1999 Free Software Foundation, Inc.
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
* GnuPG is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GnuPG is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
|
||||
/****************
|
||||
* This is a spinning server for most purposes, the server does only
|
||||
* fork for updates (which may require signature checks and lengthy DB
|
||||
* operations).
|
||||
*
|
||||
* see ks-proto.c for the used protocol.
|
||||
* see ks-db.c for the layout of the database.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "cipher.h"
|
||||
#include "options.h"
|
||||
#include "main.h"
|
||||
|
||||
|
||||
static ARGPARSE_OPTS opts[] = {
|
||||
{ 'v', "verbose", 0, "verbose" },
|
||||
{ 501, "options" ,2, "read options from file"},
|
||||
{ 502, "no-daemon", 0, "do not operate as a daemon" },
|
||||
{ 510, "debug" ,4|16, "set debugging flags"},
|
||||
{ 511, "debug-all" ,0, "enable full debugging"},
|
||||
{0} };
|
||||
|
||||
|
||||
|
||||
static char *build_list( const char *text,
|
||||
const char * (*mapf)(int), int (*chkf)(int) );
|
||||
static void become_daemon(void);
|
||||
|
||||
const char *
|
||||
strusage( int level )
|
||||
{
|
||||
static char *digests, *pubkeys, *ciphers;
|
||||
const char *p;
|
||||
switch( level ) {
|
||||
case 11: p = "gpgd (GNUPG)"; break;
|
||||
case 13: p = VERSION; break;
|
||||
case 17: p = PRINTABLE_OS_NAME; break;
|
||||
case 19: p =
|
||||
"Please report bugs to <gnupg-bugs@gnu.org>.\n";
|
||||
break;
|
||||
case 1:
|
||||
case 40: p = "Usage: gpgd [options] (-h for help)";
|
||||
break;
|
||||
case 41: p = "Syntax: gpgd [options] [files]\n"
|
||||
"GNUPG keyserver\n";
|
||||
break;
|
||||
case 31: p = "\n"; break;
|
||||
case 32:
|
||||
if( !ciphers )
|
||||
ciphers = build_list("Supported ciphers: ", cipher_algo_to_string,
|
||||
check_cipher_algo );
|
||||
p = ciphers;
|
||||
break;
|
||||
case 33:
|
||||
if( !pubkeys )
|
||||
pubkeys = build_list("Supported pubkeys: ", pubkey_algo_to_string,
|
||||
check_pubkey_algo );
|
||||
p = pubkeys;
|
||||
break;
|
||||
case 34:
|
||||
if( !digests )
|
||||
digests = build_list("Supported digests: ", digest_algo_to_string,
|
||||
check_digest_algo );
|
||||
p = digests;
|
||||
break;
|
||||
|
||||
default: p = default_strusage(level);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
build_list( const char *text, const char * (*mapf)(int), int (*chkf)(int) )
|
||||
{
|
||||
int i;
|
||||
const char *s;
|
||||
size_t n=strlen(text)+2;
|
||||
char *list, *p;
|
||||
|
||||
for(i=1; i < 100; i++ )
|
||||
if( !chkf(i) && (s=mapf(i)) )
|
||||
n += strlen(s) + 2;
|
||||
list = m_alloc( 21 + n ); *list = 0;
|
||||
for(p=NULL, i=1; i < 100; i++ ) {
|
||||
if( !chkf(i) && (s=mapf(i)) ) {
|
||||
if( !p )
|
||||
p = stpcpy( list, text );
|
||||
else
|
||||
p = stpcpy( p, ", ");
|
||||
p = stpcpy(p, s );
|
||||
}
|
||||
}
|
||||
if( p )
|
||||
p = stpcpy(p, "\n" );
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
set_debug(void)
|
||||
{
|
||||
if( opt.debug & DBG_MEMORY_VALUE )
|
||||
memory_debug_mode = 1;
|
||||
if( opt.debug & DBG_MEMSTAT_VALUE )
|
||||
memory_stat_debug_mode = 1;
|
||||
if( opt.debug & DBG_MPI_VALUE )
|
||||
mpi_debug_mode = 1;
|
||||
if( opt.debug & DBG_CIPHER_VALUE )
|
||||
g10c_debug_mode = 1;
|
||||
if( opt.debug & DBG_IOBUF_VALUE )
|
||||
iobuf_debug_mode = 1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main( int argc, char **argv )
|
||||
{
|
||||
ARGPARSE_ARGS pargs;
|
||||
int orig_argc;
|
||||
char **orig_argv;
|
||||
FILE *configfp = NULL;
|
||||
char *configname = NULL;
|
||||
unsigned configlineno;
|
||||
int parse_debug = 0;
|
||||
int default_config =1;
|
||||
int daemon = 1;
|
||||
|
||||
secmem_init( 0 ); /* disable use of secmem */
|
||||
log_set_name("gpgd");
|
||||
log_set_pid( getpid() );
|
||||
opt.compress = -1; /* defaults to standard compress level */
|
||||
opt.batch = 1;
|
||||
|
||||
/* check whether we have a config file on the commandline */
|
||||
orig_argc = argc;
|
||||
orig_argv = argv;
|
||||
pargs.argc = &argc;
|
||||
pargs.argv = &argv;
|
||||
pargs.flags= 1; /* do not remove the args */
|
||||
while( arg_parse( &pargs, opts) ) {
|
||||
if( pargs.r_opt == 510 || pargs.r_opt == 511 )
|
||||
parse_debug++;
|
||||
else if( pargs.r_opt == 501 ) {
|
||||
/* yes there is one, so we do not try the default one, but
|
||||
* read the option file when it is encountered at the commandline
|
||||
*/
|
||||
default_config = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if( default_config )
|
||||
configname = make_filename("/etc/gpgd.conf", NULL );
|
||||
|
||||
argc = orig_argc;
|
||||
argv = orig_argv;
|
||||
pargs.argc = &argc;
|
||||
pargs.argv = &argv;
|
||||
pargs.flags= 1; /* do not remove the args */
|
||||
next_pass:
|
||||
if( configname ) {
|
||||
configlineno = 0;
|
||||
configfp = fopen( configname, "r" );
|
||||
if( !configfp ) {
|
||||
if( default_config ) {
|
||||
if( parse_debug )
|
||||
log_info("note: no default option file `%s'\n",
|
||||
configname );
|
||||
}
|
||||
else {
|
||||
log_error("option file `%s': %s\n",
|
||||
configname, strerror(errno) );
|
||||
g10_exit(1);
|
||||
}
|
||||
m_free(configname); configname = NULL;
|
||||
}
|
||||
if( parse_debug && configname )
|
||||
log_info("reading options from `%s'\n", configname );
|
||||
default_config = 0;
|
||||
}
|
||||
|
||||
while( optfile_parse( configfp, configname, &configlineno,
|
||||
&pargs, opts) ) {
|
||||
switch( pargs.r_opt ) {
|
||||
case 'v': opt.verbose++; break;
|
||||
case 501:
|
||||
if( !configfp ) {
|
||||
m_free(configname);
|
||||
configname = m_strdup(pargs.r.ret_str);
|
||||
goto next_pass;
|
||||
}
|
||||
break;
|
||||
case 502: daemon = 0; break;
|
||||
case 510: opt.debug |= pargs.r.ret_ulong; break;
|
||||
case 511: opt.debug = ~0; break;
|
||||
default : pargs.err = configfp? 1:2; break;
|
||||
}
|
||||
}
|
||||
if( configfp ) {
|
||||
fclose( configfp );
|
||||
configfp = NULL;
|
||||
m_free(configname); configname = NULL;
|
||||
goto next_pass;
|
||||
}
|
||||
m_free( configname ); configname = NULL;
|
||||
if( log_get_errorcount(0) )
|
||||
g10_exit(2);
|
||||
|
||||
fprintf(stderr, "%s %s; %s\n", strusage(11), strusage(13), strusage(14) );
|
||||
fprintf(stderr, "%s\n", strusage(15) );
|
||||
|
||||
set_debug();
|
||||
if( daemon )
|
||||
become_daemon();
|
||||
|
||||
|
||||
g10_exit(0);
|
||||
return 8; /*NEVER REACHED*/
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
g10_exit( int rc )
|
||||
{
|
||||
secmem_term();
|
||||
rc = rc? rc : log_get_errorcount(0)? 2:0;
|
||||
exit(rc );
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
become_daemon()
|
||||
{
|
||||
long nfile;
|
||||
int i, n;
|
||||
int childpid;
|
||||
|
||||
if( opt.verbose )
|
||||
log_info("becoming a daemon ...\n");
|
||||
fflush(NULL);
|
||||
|
||||
/* FIXME: handle the TTY signals */
|
||||
|
||||
if( (childpid = fork()) == -1 )
|
||||
log_fatal("can't fork first child: %s\n", strerror(errno));
|
||||
else if( childpid > 0 )
|
||||
exit(0); /* terminate parent */
|
||||
|
||||
/* Disassociate from controlling terminal etc. */
|
||||
if( setsid() == -1 )
|
||||
log_fatal("setsid() failed: %s\n", strerror(errno) );
|
||||
|
||||
log_set_pid( getpid() );
|
||||
/* close all files but not the log files */
|
||||
if( (nfile=sysconf( _SC_OPEN_MAX )) < 0 )
|
||||
#ifdef _POSIX_OPEN_MAX
|
||||
nfile = _POSIX_OPEN_MAX;
|
||||
#else
|
||||
nfile = 20; /* assume a common value */
|
||||
#endif
|
||||
n = fileno( stderr );
|
||||
for(i=0; i < nfile; i++ )
|
||||
if( i != n )
|
||||
close(i);
|
||||
errno = 0;
|
||||
|
||||
if( chdir("/") )
|
||||
log_fatal("chdir to root failed: %s\n", strerror(errno) );
|
||||
umask(0);
|
||||
|
||||
/* do not let possible children become zombies */
|
||||
signal(SIGCHLD, SIG_IGN);
|
||||
if( opt.verbose )
|
||||
log_info("now running as daemon\n");
|
||||
}
|
||||
|
||||
|
||||
|
155
g10/ks-proto.c
155
g10/ks-proto.c
@ -1,155 +0,0 @@
|
||||
/* ks-proto.c keyserver protocol handling
|
||||
* Copyright (C) 1998 Free Software Foundation, Inc.
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
* GnuPG is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GnuPG is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
|
||||
/****************
|
||||
* The extended HKP protocol:
|
||||
*
|
||||
* GET /pks/lookup[/<gnupg_user_id>][?[op=<cmd>][&armor=0][&search=<keywords>]]
|
||||
*
|
||||
* Default is: "armor=1", "op=get". "search" is only allowed if gnupg_user_id
|
||||
* is not present. GET maybe replaced by HEAD in which case only some status
|
||||
* information is returned.
|
||||
*
|
||||
* Hmmm, I don't like it, the better solution is to use:
|
||||
*
|
||||
* /pks/gnupg/get for binary lookups
|
||||
* /pks/gnupg/upd to update a key
|
||||
* /pks/gnupg/ins to insert a new key
|
||||
*
|
||||
* Optional a version string can be inserted as in:
|
||||
*
|
||||
* /pks/gnupg/v1.0/get
|
||||
*
|
||||
* Returned HTTP options:
|
||||
* X-Key-Hash: <rmd160 hash value of the keyblock>
|
||||
* X-Key-MTime: <last modification time>
|
||||
* X-Key-LID: <local_key_id_used_for_update_etc>
|
||||
* [fixme: is X-.... allowed?]
|
||||
*
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include "util.h"
|
||||
#include "ks-proto.h"
|
||||
|
||||
|
||||
static int
|
||||
do_read( int fd, char *buffer, size_t bufsize, int *ret_nread )
|
||||
{
|
||||
int n;
|
||||
fd_set rfds;
|
||||
struct timeval tv;
|
||||
int rc;
|
||||
|
||||
*ret_nread = 0;
|
||||
do {
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(fd, &rfds);
|
||||
tv.tv_sec = 1;
|
||||
tv.tv_usec = 0;
|
||||
if( !(rc=select(fd+1, &rfds, NULL, NULL, &tv)) )
|
||||
return 0; /* timeout */
|
||||
if( rc == -1 ) {
|
||||
log_error("select() error: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
do {
|
||||
n = read(fd, buffer, bufsize );
|
||||
if( n >= 0 && n > bufsize )
|
||||
log_bug("bogus read from fd %d (n=%d)\n", fd, n );
|
||||
} while( n == -1 && errno == EINTR );
|
||||
if( n == -1 ) {
|
||||
log_error("read error on fd %d: %s\n", fd, strerror(errno) );
|
||||
return -1;
|
||||
}
|
||||
} while( !n );
|
||||
*ret_nread = n;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
ks_get_request( int fd, KS_TRANS *req )
|
||||
{
|
||||
char *p, *p2, buf[500];
|
||||
int nread, n;
|
||||
int state = 0;
|
||||
|
||||
req->err = 0;
|
||||
req->data = NULL;
|
||||
while( !do_read( fd, buf, DIM(buf)-1, &nread ) {
|
||||
p = buf;
|
||||
if( !state ) {
|
||||
/* replace the trailing LF with a 0 */
|
||||
for(p2=p,n=0; n < nread && *p2 != '\n'; p2++ )
|
||||
;
|
||||
if( *p2 != '\n' ) {
|
||||
req->err = KS_ERR_REQ_TOO_LONG;
|
||||
break;
|
||||
}
|
||||
*p2++ = 0;
|
||||
n++;
|
||||
|
||||
/* now look at the request. Note that the isspace() will work
|
||||
* because there is still a CR before the 0 */
|
||||
if( (p[0] == 'G' || p[0] == 'g')
|
||||
&& (p[1] == 'E' || p[1] == 'e')
|
||||
&& (p[2] == 'T' || p[2] == 't') && isspace( p[3] ) ) {
|
||||
req->cmd = KS_REQ_GET;
|
||||
p += 4;
|
||||
}
|
||||
else if( (p[0] == 'H' || p[0] == 'h')
|
||||
&& (p[1] == 'E' || p[1] == 'e')
|
||||
&& (p[2] == 'A' || p[2] == 'a')
|
||||
&& (p[3] == 'D' || p[3] == 'd') && isspace( p[4] ) ) {
|
||||
req->cmd = KS_REQ_HEAD;
|
||||
p += 5;
|
||||
}
|
||||
else if( (p[0] == 'H' || p[0] == 'h')
|
||||
&& (p[1] == 'E' || p[1] == 'e')
|
||||
&& (p[2] == 'L' || p[2] == 'l')
|
||||
&& (p[3] == 'P' || p[3] == 'p') && isspace( p[4] ) ) {
|
||||
req->cmd = KS_REQ_HELP;
|
||||
p += 5;
|
||||
}
|
||||
else
|
||||
req->cmd = KS_REQ_UNKNOWN;
|
||||
/* skip spaces, store args and remaining data */
|
||||
while( *p == ' ' || *p == '\t' )
|
||||
p++;
|
||||
/* fixme: remove trailing blanks from args */
|
||||
req->args = p;
|
||||
p = p2; /* p now points to the remaining n bytes in the buffer */
|
||||
state = 1;
|
||||
}
|
||||
if( state == 1 ) {
|
||||
/* read the option lines */
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,23 +0,0 @@
|
||||
/* ks-proto.h
|
||||
* Copyright (C) 1998 Free Software Foundation, Inc.
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
* GnuPG is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GnuPG is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#ifndef G10_KS_PROTO_H
|
||||
#define G10_KS_PROTO_H
|
||||
|
||||
#endif /*G10_KS_PROTO_H*/
|
Loading…
x
Reference in New Issue
Block a user