X-Git-Url: http://the.earth.li/gitweb/?a=blobdiff_plain;f=keydb_file.c;h=1ef81b473825818123d5c633cdeb10ae672383be;hb=be024aa68a513a2a85a7cddb28de4664b0b96144;hp=4a4322b5b88ff3460c8a97eab7add35c9edf7e6f;hpb=394938c479925750ffe56c28d281945ba4003a14;p=onak.git diff --git a/keydb_file.c b/keydb_file.c index 4a4322b..1ef81b4 100644 --- a/keydb_file.c +++ b/keydb_file.c @@ -3,11 +3,12 @@ * * Jonathan McDowell * - * Copyright 2002 Project Purple + * Copyright 2002-2004 Project Purple */ #include #include +#include #include #include #include @@ -20,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" @@ -167,6 +169,66 @@ int fetch_key_text(const char *search, struct openpgp_publickey **publickey) return 0; } +/** + * 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. + * + * Returns the number of keys we iterated over. + */ +int iterate_keys(void (*iterfunc)(void *ctx, struct openpgp_publickey *key), + void *ctx) +{ + 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; +} + + /** * dumpdb - dump the key database * @filenamebase: The base filename to use for the dump. @@ -188,4 +250,5 @@ int dumpdb(char *filenamebase) #define NEED_KEYID2UID 1 #define NEED_GETKEYSIGS 1 #define NEED_GETFULLKEYID 1 +#define NEED_UPDATEKEYS 1 #include "keydb.c"