X-Git-Url: http://the.earth.li/gitweb/?a=blobdiff_plain;f=keydb_file.c;h=a0c90327bf9a978525e17ab6860a430e2a227de9;hb=0d2a5aeeb4120999afc79d06619d90e26e2fec5c;hp=f7351225622e65074f434a77527b2cd890ac27c3;hpb=cd002cef518222c140de94b8817874b072b2d918;p=onak.git diff --git a/keydb_file.c b/keydb_file.c index f735122..a0c9032 100644 --- a/keydb_file.c +++ b/keydb_file.c @@ -3,13 +3,12 @@ * * Jonathan McDowell * - * Copyright 2002 Project Purple - * - * $Id: keydb_file.c,v 1.11 2004/03/23 12:33:46 noodles Exp $ + * Copyright 2002-2004 Project Purple */ #include #include +#include #include #include #include @@ -22,6 +21,7 @@ #include "keyid.h" #include "keystructs.h" #include "ll.h" +#include "log.h" #include "mem.h" #include "onak-conf.h" #include "parsekey.h" @@ -170,18 +170,62 @@ int fetch_key_text(const char *search, struct openpgp_publickey **publickey) } /** - * dumpdb - dump the key database - * @filenamebase: The base filename to use for the dump. + * iterate_keys - call a function once for each key in the db. + * @iterfunc: The function to call. + * @ctx: A context pointer + * + * Calls iterfunc once for each key in the database. ctx is passed + * unaltered to iterfunc. This function is intended to aid database dumps + * and statistic calculations. * - * Dumps the database into one or more files, which contain pure OpenPGP - * that can be reimported into onak or gpg. filenamebase provides a base - * file name for the dump; several files may be created, all of which will - * begin with this string and then have a unique number and a .pgp - * extension. - * */ -int dumpdb(char *filenamebase) + * Returns the number of keys we iterated over. + */ +int iterate_keys(void (*iterfunc)(void *ctx, struct openpgp_publickey *key), + void *ctx) { - return 0; + int numkeys = 0; + struct openpgp_packet_list *packets = NULL; + struct openpgp_publickey *key = NULL; + DIR *dir; + char keyfile[1024]; + int fd = -1; + struct dirent *curfile = NULL; + + dir = opendir(config.db_dir); + + if (dir != NULL) { + while ((curfile = readdir(dir)) != NULL) { + if (curfile->d_name[0] == '0' && + curfile->d_name[1] == 'x') { + snprintf(keyfile, 1023, "%s/%s", + config.db_dir, + curfile->d_name); + fd = open(keyfile, O_RDONLY); + + if (fd > -1) { + read_openpgp_stream(file_fetchchar, + &fd, + &packets, + 0); + parse_keys(packets, &key); + + iterfunc(ctx, key); + + free_publickey(key); + key = NULL; + free_packet_list(packets); + packets = NULL; + close(fd); + } + numkeys++; + } + } + + closedir(dir); + dir = NULL; + } + + return numkeys; } /* @@ -190,4 +234,5 @@ int dumpdb(char *filenamebase) #define NEED_KEYID2UID 1 #define NEED_GETKEYSIGS 1 #define NEED_GETFULLKEYID 1 +#define NEED_UPDATEKEYS 1 #include "keydb.c"