From bff92fa7e9583ebaa3de745aba04c66b132c849e Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:48 +0000 Subject: [PATCH 01/16] cscvs to tla changeset 86 Author: noodles Date: 2003/06/08 21:11:00 First attempt at supporting revoked keys. --- keydb.c | 15 +++++++++++---- keydb.h | 8 +++++--- keydb_pg.c | 15 +++++++++++++-- keyindex.c | 18 +++++++++++------- keystructs.h | 5 ++++- stats.c | 3 ++- 6 files changed, 46 insertions(+), 18 deletions(-) diff --git a/keydb.c b/keydb.c index 347b406..1eb9def 100644 --- a/keydb.c +++ b/keydb.c @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: keydb.c,v 1.9 2003/06/04 20:57:08 noodles Exp $ + * $Id: keydb.c,v 1.10 2003/06/08 21:11:00 noodles Exp $ */ /** @@ -63,11 +63,13 @@ char *keyid2uid(uint64_t keyid) /** * getkeysigs - Gets a linked list of the signatures on a key. * @keyid: The keyid to get the sigs for. + * @revoked: Is the key revoked? * * This function gets the list of signatures on a key. Used for key - * indexing and doing stats bits. + * indexing and doing stats bits. If revoked is non-NULL then if the key + * is revoked it's set to true. */ -struct ll *getkeysigs(uint64_t keyid) +struct ll *getkeysigs(uint64_t keyid, bool *revoked) { struct ll *sigs = NULL; struct openpgp_signedpacket_list *uids = NULL; @@ -79,6 +81,9 @@ struct ll *getkeysigs(uint64_t keyid) for (uids = publickey->uids; uids != NULL; uids = uids->next) { sigs = keysigs(sigs, uids->sigs); } + if (revoked != NULL) { + *revoked = (publickey->revocations != NULL); + } free_publickey(publickey); } @@ -99,6 +104,7 @@ struct ll *cached_getkeysigs(uint64_t keyid) struct stats_key *key = NULL; struct stats_key *signedkey = NULL; struct ll *cursig = NULL; + bool revoked = false; if (keyid == 0) { return NULL; @@ -107,7 +113,8 @@ struct ll *cached_getkeysigs(uint64_t keyid) key = createandaddtohash(keyid); if (key->gotsigs == false) { - key->sigs = getkeysigs(key->keyid); + key->sigs = getkeysigs(key->keyid, &revoked); + key->revoked = revoked; for (cursig = key->sigs; cursig != NULL; cursig = cursig->next) { signedkey = (struct stats_key *) cursig->object; diff --git a/keydb.h b/keydb.h index b356bb8..ea4a789 100644 --- a/keydb.h +++ b/keydb.h @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: keydb.h,v 1.8 2003/06/07 13:45:34 noodles Exp $ + * $Id: keydb.h,v 1.9 2003/06/08 21:11:00 noodles Exp $ */ #ifndef __KEYDB_H__ @@ -110,11 +110,13 @@ char *keyid2uid(uint64_t keyid); /** * getkeysigs - Gets a linked list of the signatures on a key. * @keyid: The keyid to get the sigs for. + * @revoked: Is the key revoked? * * This function gets the list of signatures on a key. Used for key - * indexing and doing stats bits. + * indexing and doing stats bits. If revoked is non-NULL then if the key + * is revoked it's set to true. */ -struct ll *getkeysigs(uint64_t keyid); +struct ll *getkeysigs(uint64_t keyid, bool *revoked); /** * cached_getkeysigs - Gets the signatures on a key. diff --git a/keydb_pg.c b/keydb_pg.c index c643a79..cdfbe63 100644 --- a/keydb_pg.c +++ b/keydb_pg.c @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: keydb_pg.c,v 1.11 2003/06/05 07:32:00 noodles Exp $ + * $Id: keydb_pg.c,v 1.12 2003/06/08 21:11:01 noodles Exp $ */ #include @@ -504,11 +504,12 @@ char *keyid2uid(uint64_t keyid) /** * getkeysigs - Gets a linked list of the signatures on a key. * @keyid: The keyid to get the sigs for. + * @revoked: If the key is revoked. * * This function gets the list of signatures on a key. Used for key * indexing and doing stats bits. */ -struct ll *getkeysigs(uint64_t keyid) +struct ll *getkeysigs(uint64_t keyid, bool *revoked) { struct ll *sigs = NULL; PGresult *result = NULL; @@ -556,6 +557,16 @@ struct ll *getkeysigs(uint64_t keyid) result = PQexec(dbconn, "COMMIT"); PQclear(result); } + + /* + * TODO: What do we do about revocations? We don't have the details + * stored in a separate table, so we'd have to grab the key and decode + * it, which we're trying to avoid by having a signers table. + */ + if (revoked != NULL) { + *revoked = false; + } + return sigs; } diff --git a/keyindex.c b/keyindex.c index 6593224..464a7ba 100644 --- a/keyindex.c +++ b/keyindex.c @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: keyindex.c,v 1.11 2003/06/08 19:04:32 noodles Exp $ + * $Id: keyindex.c,v 1.12 2003/06/08 21:11:01 noodles Exp $ */ #include @@ -227,7 +227,10 @@ int key_index(struct openpgp_publickey *keys, bool verbose, bool fingerprint, snprintf(buf, 1023, "%.*s", (int) curuid->packet->length, curuid->packet->data); - printf("%s\n", (html) ? txt2html(buf) : buf); + printf("%s%s\n", + (html) ? txt2html(buf) : buf, + (keys->revocations == NULL) ? "" : + " *** REVOKED ***"); if (fingerprint) { display_fingerprint(keys); } @@ -236,7 +239,9 @@ int key_index(struct openpgp_publickey *keys, bool verbose, bool fingerprint, } curuid = curuid->next; } else { - putchar('\n'); + printf("%s\n", + (keys->revocations == NULL) ? "" : + "*** REVOKED ***"); if (fingerprint) { display_fingerprint(keys); } @@ -272,8 +277,6 @@ int mrkey_index(struct openpgp_publickey *keys) size_t fplength = 0; unsigned char fp[20]; - - while (keys != NULL) { created_time = (keys->publickey->data[1] << 24) + (keys->publickey->data[2] << 16) + @@ -306,10 +309,11 @@ int mrkey_index(struct openpgp_publickey *keys) keys->publickey->data[0]); } - printf(":%d:%d:%ld::\n", + printf(":%d:%d:%ld::%s\n", type, length, - created_time); + created_time, + (keys->revocations == NULL) ? "" : "r"); for (curuid = keys->uids; curuid != NULL; curuid = curuid->next) { diff --git a/keystructs.h b/keystructs.h index 42f0971..24799eb 100644 --- a/keystructs.h +++ b/keystructs.h @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: keystructs.h,v 1.6 2003/06/04 20:57:09 noodles Exp $ + * $Id: keystructs.h,v 1.7 2003/06/08 21:11:01 noodles Exp $ */ #ifndef __KEYSTRUCTS_H__ @@ -90,6 +90,8 @@ struct openpgp_publickey { * @parent: The key that lead us to this one for DFS/BFS. * @sigs: A linked list of the signatures on this key. * @gotsigs: A bool indicating if we've initialized the sigs element yet. + * @disabled: If we shouldn't consider the key in calculations. + * @revoked: If the key is revoked (and shouldn't be considered). */ struct stats_key { uint64_t keyid; @@ -99,6 +101,7 @@ struct stats_key { struct ll *signs; bool gotsigs; bool disabled; + bool revoked; }; #endif /* __KEYSTRUCTS_H__ */ diff --git a/stats.c b/stats.c index 6a61879..108b8cc 100644 --- a/stats.c +++ b/stats.c @@ -5,7 +5,7 @@ * * Copyright 2000-2002 Project Purple * - * $Id: stats.c,v 1.11 2003/06/04 22:32:56 noodles Exp $ + * $Id: stats.c,v 1.12 2003/06/08 21:11:01 noodles Exp $ */ #include @@ -77,6 +77,7 @@ unsigned long findpath(struct stats_key *have, struct stats_key *want) * it and add its sigs to the list we want to look at. */ if (!((struct stats_key *)sigs->object)->disabled && + !((struct stats_key *)sigs->object)->revoked && ((struct stats_key *)sigs->object)->colour == 0) { count++; ((struct stats_key *)sigs->object)->colour = -- 2.39.2 From 39f70717750a0f0d07d218d1de07681bfeb1b588 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:49 +0000 Subject: [PATCH 02/16] cscvs to tla changeset 87 Author: noodles Date: 2003/06/08 21:18:43 0.2.0 release. Update HISTORY, TODO, bump version in onak-conf.h/README --- HISTORY | 19 +++++++++++++++++++ README | 4 ++-- TODO | 3 +-- onak-conf.h | 4 ++-- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/HISTORY b/HISTORY index 3154ebb..f1e6713 100644 --- a/HISTORY +++ b/HISTORY @@ -94,3 +94,22 @@ * Introduced transaction support to DB3 backend, along with deadlock detection. * Added keydb dumping ability. * Added logging infrastructure to help more easily track down problems. + +0.2.0 - 8th June 2003 + +* Output multiple paths in gpgwww (thanks to Simon Huggins). +* Allow a keyid on the command line for sixdegrees (Simon Huggins). +* Make db2 backend check for a num_keydb file to know how many db files to use. +* Add 0x to generated URLs as pks needs these. +* Add "Find Reverse Path" link to gpgwww output. +* Checkpoint the db3 database upon clean exit. +* Fix bug with logging where the month was one less than it should have been. +* Fall back to stderr if we can't open the logfile. +* Move dependancy list from Makefile to separate file. +* Checkpoint the DB on clean shutdown. +* First cut at MRHKP support. +* Clean up various compile warnings under gcc 3.3 +* Log a critical error when we can't handle a critical subpacket rather than + asserting. +* Make the Postgres backend compile again. +* First attempt at supporting revoked keys. diff --git a/README b/README index e82da12..e04bcaf 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -onak 0.1.2 +onak 0.2.0 Copyright 2003 Project Purple. Written by Jonathan McDowell http://www.earth.li/projectpurple/progs/onak.html @@ -130,4 +130,4 @@ License: onak is distributed under the GNU Public License, a copy of which should have been provided with this archive as LICENSE. -$Id: README,v 1.4 2003/06/04 20:57:06 noodles Exp $ +$Id: README,v 1.5 2003/06/08 21:18:43 noodles Exp $ diff --git a/TODO b/TODO index 267eab6..f59c083 100644 --- a/TODO +++ b/TODO @@ -7,7 +7,7 @@ * Better txt2html routine. * Remove bithelp.h (i386 only at present & inlined). - Build and test on non-i386. -* Pathfinder - graphical as well? Multiple paths? +* Pathfinder - graphical as well? * Do pathlengths for similar email addresses to help aide keysigning. (ie "Find me the keys furthest from mine that end ox.ac.uk'") Suggested by Jochen Voss . @@ -17,7 +17,6 @@ signedness for lo_read/write) * Test library? * autoconf -* logging framework so we can log debug/warning messages and so on. syslog? * Full email interface support (ADD, INDEX etc) * More comments. * Look at db2 backend - is it db2's fault? (Well, deadlock in that the library diff --git a/onak-conf.h b/onak-conf.h index 6afb43a..3f4a797 100644 --- a/onak-conf.h +++ b/onak-conf.h @@ -5,13 +5,13 @@ * * Copyright 2002 Project Purple * - * $Id: onak-conf.h,v 1.9 2003/06/04 20:57:11 noodles Exp $ + * $Id: onak-conf.h,v 1.10 2003/06/08 21:18:43 noodles Exp $ */ #ifndef __ONAK_CONF_H_ #define __ONAK_CONF_H_ -#define VERSION "0.1.2" +#define VERSION "0.2.0" #define CONFIGFILE "/home/noodles/projects/onak/onak.conf" /* -- 2.39.2 From ce1c3225e865ba5748cd855d17d477bda90b7652 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:50 +0000 Subject: [PATCH 03/16] cscvs to tla changeset 88 Author: noodles Date: 2003/09/28 14:54:57 Add support for multiple DB3 key database files. --- keydb_db3.c | 120 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 81 insertions(+), 39 deletions(-) diff --git a/keydb_db3.c b/keydb_db3.c index 1aba919..d3d35c8 100644 --- a/keydb_db3.c +++ b/keydb_db3.c @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: keydb_db3.c,v 1.16 2003/06/04 20:57:08 noodles Exp $ + * $Id: keydb_db3.c,v 1.17 2003/09/28 14:54:57 noodles Exp $ */ #include @@ -37,9 +37,14 @@ static DB_ENV *dbenv = NULL; /** - * dbconn - our connection to the key database. + * numdb - The number of database files we have. */ -static DB *dbconn = NULL; +static int numdbs = 16; + +/** + * dbconn - our connections to the key database files. + */ +static DB **dbconns = NULL; /** * worddb - our connection to the word database. @@ -51,6 +56,11 @@ static DB *worddb = NULL; */ static DB_TXN *txn = NULL; +DB *keydb(uint64_t keyid) +{ + return(dbconns[keyid % numdbs]); +} + /** * makewordlist - Takes a string and splits it into a set of unique words. * @wordlist: The current word list. @@ -110,7 +120,29 @@ struct ll *makewordlist(struct ll *wordlist, char *word) */ void initdb(void) { - int ret = 0; + char buf[1024]; + FILE *numdb = NULL; + int ret = 0; + int i = 0; + + snprintf(buf, sizeof(buf) - 1, "%s/num_keydb", config.db_dir); + numdb = fopen(buf, "r"); + if (numdb != NULL) { + if (fgets(buf, sizeof(buf), numdb) != NULL) { + numdbs = atoi(buf); + } + fclose(numdb); + } else { + logthing(LOGTHING_ERROR, "Couldn't open num_keydb: %s", + strerror(errno)); + } + + dbconns = malloc(sizeof (DB *) * numdbs); + if (dbconns == NULL) { + logthing(LOGTHING_CRITICAL, + "Couldn't allocate memory for dbconns"); + exit(1); + } ret = db_env_create(&dbenv, 0); if (ret != 0) { @@ -144,24 +176,27 @@ void initdb(void) exit(1); } - ret = db_create(&dbconn, dbenv, 0); - if (ret != 0) { - logthing(LOGTHING_CRITICAL, + for (i = 0; i < numdbs; i++) { + ret = db_create(&dbconns[i], dbenv, 0); + if (ret != 0) { + logthing(LOGTHING_CRITICAL, "db_create: %s", db_strerror(ret)); - exit(1); - } + exit(1); + } - ret = dbconn->open(dbconn, "keydb.db", + snprintf(buf, 1023, "keydb.%d.db", i); + ret = dbconns[i]->open(dbconns[i], buf, NULL, DB_HASH, DB_CREATE, 0664); - if (ret != 0) { - logthing(LOGTHING_CRITICAL, + if (ret != 0) { + logthing(LOGTHING_CRITICAL, "Error opening key database: %s (%s)", - "keydb.db", + buf, db_strerror(ret)); - exit(1); + exit(1); + } } ret = db_create(&worddb, dbenv, 0); @@ -193,11 +228,15 @@ void initdb(void) */ void cleanupdb(void) { + int i = 0; + txn_checkpoint(dbenv, 0, 0, 0); worddb->close(worddb, 0); worddb = NULL; - dbconn->close(dbconn, 0); - dbconn = NULL; + for (i = 0; i < numdbs; i++) { + dbconns[i]->close(dbconns[i], 0); + dbconns[i] = NULL; + } dbenv->close(dbenv, 0); dbenv = NULL; } @@ -290,7 +329,7 @@ int fetch_key(uint64_t keyid, struct openpgp_publickey **publickey, starttrans(); } - ret = dbconn->get(dbconn, + ret = keydb(keyid)->get(keydb(keyid), txn, &key, &data, @@ -505,7 +544,7 @@ int store_key(struct openpgp_publickey *publickey, bool intrans, bool update) data.size = storebuf.offset; data.data = storebuf.buffer; - ret = dbconn->put(dbconn, + ret = keydb(keyid)->put(keydb(keyid), txn, &key, &data, @@ -714,7 +753,7 @@ int delete_key(uint64_t keyid, bool intrans) key.data = &keyid; key.size = sizeof(keyid); - dbconn->del(dbconn, + keydb(keyid)->del(keydb(keyid), txn, &key, 0); /* flags */ @@ -743,35 +782,38 @@ int dumpdb(char *filenamebase) DBC *cursor = NULL; int ret = 0; int fd = -1; + int i; - starttrans(); + for (i = 0; i < numdbs; i++) { + starttrans(); - ret = dbconn->cursor(dbconn, - txn, - &cursor, - 0); /* flags */ + ret = dbconns[i]->cursor(dbconns[i], + NULL, + &cursor, + 0); /* flags */ - fd = open(filenamebase, O_CREAT | O_WRONLY | O_TRUNC, 0640); - memset(&key, 0, sizeof(key)); - memset(&data, 0, sizeof(data)); - ret = cursor->c_get(cursor, &key, &data, DB_NEXT); - while (ret == 0) { - write(fd, data.data, data.size); + fd = open(filenamebase, O_CREAT | O_WRONLY | O_TRUNC, 0640); memset(&key, 0, sizeof(key)); memset(&data, 0, sizeof(data)); ret = cursor->c_get(cursor, &key, &data, DB_NEXT); - } - if (ret != DB_NOTFOUND) { - logthing(LOGTHING_ERROR, "Problem reading key: %s", - db_strerror(ret)); - } + while (ret == 0) { + write(fd, data.data, data.size); + memset(&key, 0, sizeof(key)); + memset(&data, 0, sizeof(data)); + ret = cursor->c_get(cursor, &key, &data, DB_NEXT); + } + if (ret != DB_NOTFOUND) { + logthing(LOGTHING_ERROR, "Problem reading key: %s", + db_strerror(ret)); + } - close(fd); + close(fd); - ret = cursor->c_close(cursor); - cursor = NULL; + ret = cursor->c_close(cursor); + cursor = NULL; - endtrans(); + endtrans(); + } return 0; } -- 2.39.2 From 2ffd5444d8c7a73b12039f3a6cf336872f2558c4 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:51 +0000 Subject: [PATCH 04/16] cscvs to tla changeset 89 Author: noodles Date: 2003/09/28 14:56:32 Don't dump the DB3 database within a transaction as it gets too big for it to deal with, ending in ENOMEM. --- keydb_db3.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/keydb_db3.c b/keydb_db3.c index d3d35c8..a50643d 100644 --- a/keydb_db3.c +++ b/keydb_db3.c @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: keydb_db3.c,v 1.17 2003/09/28 14:54:57 noodles Exp $ + * $Id: keydb_db3.c,v 1.18 2003/09/28 14:56:32 noodles Exp $ */ #include @@ -785,8 +785,6 @@ int dumpdb(char *filenamebase) int i; for (i = 0; i < numdbs; i++) { - starttrans(); - ret = dbconns[i]->cursor(dbconns[i], NULL, &cursor, @@ -811,8 +809,6 @@ int dumpdb(char *filenamebase) ret = cursor->c_close(cursor); cursor = NULL; - - endtrans(); } return 0; -- 2.39.2 From 97b2d68b9debdeaec828c9000bcca60a4a3d5817 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:51 +0000 Subject: [PATCH 05/16] cscvs to tla changeset 90 Author: noodles Date: 2003/09/28 16:12:47 Fix DB3 key dump routine to dump a file for each key database. --- keydb_db3.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/keydb_db3.c b/keydb_db3.c index a50643d..f686770 100644 --- a/keydb_db3.c +++ b/keydb_db3.c @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: keydb_db3.c,v 1.18 2003/09/28 14:56:32 noodles Exp $ + * $Id: keydb_db3.c,v 1.19 2003/09/28 16:12:47 noodles Exp $ */ #include @@ -778,35 +778,46 @@ int delete_key(uint64_t keyid, bool intrans) */ int dumpdb(char *filenamebase) { - DBT key, data; - DBC *cursor = NULL; - int ret = 0; - int fd = -1; - int i; + DBT key, data; + DBC *cursor = NULL; + int ret = 0; + int fd = -1; + int i = 0; + char filename[1024]; + filename[1023] = 0; for (i = 0; i < numdbs; i++) { ret = dbconns[i]->cursor(dbconns[i], NULL, &cursor, 0); /* flags */ - fd = open(filenamebase, O_CREAT | O_WRONLY | O_TRUNC, 0640); - memset(&key, 0, sizeof(key)); - memset(&data, 0, sizeof(data)); - ret = cursor->c_get(cursor, &key, &data, DB_NEXT); - while (ret == 0) { - write(fd, data.data, data.size); + snprintf(filename, 1023, "%s.%d.pgp", filenamebase, i); + fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0640); + if (fd == -1) { + logthing(LOGTHING_ERROR, + "Error opening keydump file (%s): %s", + filename, + strerror(errno)); + } else { memset(&key, 0, sizeof(key)); memset(&data, 0, sizeof(data)); ret = cursor->c_get(cursor, &key, &data, DB_NEXT); - } - if (ret != DB_NOTFOUND) { - logthing(LOGTHING_ERROR, "Problem reading key: %s", + while (ret == 0) { + write(fd, data.data, data.size); + memset(&key, 0, sizeof(key)); + memset(&data, 0, sizeof(data)); + ret = cursor->c_get(cursor, &key, &data, + DB_NEXT); + } + if (ret != DB_NOTFOUND) { + logthing(LOGTHING_ERROR, + "Problem reading key: %s", db_strerror(ret)); + } + close(fd); } - close(fd); - ret = cursor->c_close(cursor); cursor = NULL; } -- 2.39.2 From 89b73506f3cfe1c0238c3fb5c1af2e696a115f4d Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:52 +0000 Subject: [PATCH 06/16] cscvs to tla changeset 91 Author: noodles Date: 2003/09/28 16:43:50 Removed the revoked keys todo entry as that was in 0.2.0 --- TODO | 1 - 1 file changed, 1 deletion(-) diff --git a/TODO b/TODO index f59c083..559e1f6 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,3 @@ -* Revoked keys on index. * Check keys on import? * Better signature subpacket parsing (primary UID for example). * Better merging of signatures; need to compare subpackets on Type 4 packets -- 2.39.2 From 38e51db0fc5b2cfb88a193e16a3f9a7c2246ac8a Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:53 +0000 Subject: [PATCH 07/16] cscvs to tla changeset 92 Author: noodles Date: 2003/09/28 17:25:40 Updating onak-mail.pl to use config file for more things and output logs in the same format as onak. --- onak-mail.pl | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/onak-mail.pl b/onak-mail.pl index 0c75db6..841d4ee 100755 --- a/onak-mail.pl +++ b/onak-mail.pl @@ -7,7 +7,7 @@ # Copyright 2002 Project Purple # Released under the GPL. # -# $Id: onak-mail.pl,v 1.6 2003/06/04 20:57:11 noodles Exp $ +# $Id: onak-mail.pl,v 1.7 2003/09/28 17:25:40 noodles Exp $ # use strict; @@ -31,10 +31,14 @@ sub readconfig { # Ignore; comment line. } elsif (/^this_site (.*)/) { $config{'thissite'} = $1; + } elsif (/^logfile (.*)/) { + $config{'logfile'} = $1; } elsif (/^maintainer_email (.*)/) { $config{'adminemail'} = $1; } elsif (/^mail_delivery_client (.*)/) { $config{'mta'} = $1; + } elsif (/^pks_bin_dir (.*)/) { + $config{'pks_bin_dir'} = $1; } elsif (/^syncsite (.*)/) { push @{$config{'syncsites'}}, $1; } @@ -57,17 +61,13 @@ sub submitupdate { my (@errors, @mergedata); open3(\*MERGEIN, \*MERGEOUT, \*MERGEERR, - "/home/noodles/onak-0.0.3/onak", "-u", "add"); + $config{'pks_bin_dir'}."/onak", "-u", "add"); print MERGEIN @data; close MERGEIN; @mergedata = ; @errors = ; - open (LOG, ">>/home/noodles/onak-0.0.3/keyadd.log"); - print LOG "[".localtime(time)."] ", @errors; - close LOG; - return @mergedata; } @@ -104,6 +104,7 @@ if ($subject =~ /^INCREMENTAL$/i) { my $count; my $i; my @newupdate = submitupdate(@body); + my @time; $count = 0; foreach $i (@{$config{'syncsites'}}) { @@ -112,13 +113,22 @@ if ($subject =~ /^INCREMENTAL$/i) { } } - open (LOG, ">>/home/noodles/logs/keyadd.log"); - print LOG "[".localtime(time)."] Syncing with $count sites.\n"; + open (LOG, ">>$config{'logfile'}"); + @time = localtime(time); + print LOG "["; + print LOG sprintf "%02d/%02d/%04d %02d:%02d:%02d", + $time[3], $time[4] + 1, $time[5] + 1900, + $time[2], $time[1], $time[0]; + print LOG "] onak-mail[$$]: Syncing with $count sites.\n"; close LOG; - if ($newupdate[0] eq '') { - open (LOG, ">>/home/noodles/logs/keyadd.log"); - print LOG "[".localtime(time)."] Nothing to sync.\n"; + if ((! defined($newupdate[0])) || $newupdate[0] eq '') { + open (LOG, ">>$config{'logfile'}"); + print LOG "["; + print LOG sprintf "%02d/%02d/%04d %02d:%02d:%02d", + $time[3], $time[4] + 1, $time[5] + 1900, + $time[2], $time[1], $time[0]; + print LOG "] onak-mail[$$]: Nothing to sync.\n"; close LOG; $count = 0; } -- 2.39.2 From 8b782f377eff7672249d66423d3ca792574931e2 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:53 +0000 Subject: [PATCH 08/16] cscvs to tla changeset 93 Author: noodles Date: 2003/09/28 20:33:34 Fix stupid bug where we always read at least one byte from stdin, even if we wanted none. --- onak.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/onak.c b/onak.c index bba213b..903c8f0 100644 --- a/onak.c +++ b/onak.c @@ -7,7 +7,7 @@ * * Copyright 2002 Project Purple * - * $Id: onak.c,v 1.14 2003/06/07 13:37:33 noodles Exp $ + * $Id: onak.c,v 1.15 2003/09/28 20:33:34 noodles Exp $ */ #include @@ -28,13 +28,15 @@ int stdin_getchar(void *ctx, size_t count, unsigned char *c) { - int ic; + int ic = 0; - do { + while ((count > 0) && (ic != EOF)) { ic = getchar(); *c = ic; c++; - } while ((ic != EOF) && (--count > 0)); + count--; + } + return (ic == EOF); } -- 2.39.2 From 32851537d44f08b08ed317cbc4281ce003f84fa4 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:54 +0000 Subject: [PATCH 09/16] cscvs to tla changeset 94 Author: noodles Date: 2003/09/28 21:07:49 Tighten up error checking in a couple of places to avoid crashing without cleaning up the db. --- decodekey.c | 16 +++++++++------- parsekey.c | 15 +++++++++++---- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/decodekey.c b/decodekey.c index 46c7583..fac501e 100644 --- a/decodekey.c +++ b/decodekey.c @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: decodekey.c,v 1.3 2003/06/08 10:45:44 noodles Exp $ + * $Id: decodekey.c,v 1.4 2003/09/28 21:07:50 noodles Exp $ */ #include @@ -213,6 +213,7 @@ char **keyuids(struct openpgp_publickey *key, char **primary) char **uids = NULL; int count = 0; + *primary = NULL; if (key != NULL && key->uids != NULL) { uids = malloc((spsize(key->uids) + 1) * sizeof (char *)); @@ -228,12 +229,13 @@ char **keyuids(struct openpgp_publickey *key, char **primary) curuid = curuid -> next; } uids[count] = NULL; - } - /* - * TODO: Parse subpackets for real primary ID (v4 keys) - */ - if (primary != NULL) { - *primary = uids[0]; + + /* + * TODO: Parse subpackets for real primary ID (v4 keys) + */ + if (primary != NULL) { + *primary = uids[0]; + } } return uids; diff --git a/parsekey.c b/parsekey.c index 0f02e8c..a98e8cc 100644 --- a/parsekey.c +++ b/parsekey.c @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: parsekey.c,v 1.8 2003/06/08 19:04:32 noodles Exp $ + * $Id: parsekey.c,v 1.9 2003/09/28 21:07:49 noodles Exp $ */ #include @@ -278,9 +278,16 @@ int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count, curpacket->packet->data = malloc(curpacket->packet->length * sizeof(unsigned char)); - rc = getchar_func(ctx, - curpacket->packet->length, - curpacket->packet->data); + if (curpacket->packet->data == NULL) { + logthing(LOGTHING_ERROR, + "Can't allocate memory for " + "packet!"); + rc = -1; + } else { + rc = getchar_func(ctx, + curpacket->packet->length, + curpacket->packet->data); + } } inpacket = false; } else { -- 2.39.2 From c2524e42992138f66a836d6c7ffe725a307c50d2 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:55 +0000 Subject: [PATCH 10/16] cscvs to tla changeset 95 Author: noodles Date: 2003/09/29 07:35:26 Fix printf usage for an error message to logthing. --- parsekey.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/parsekey.c b/parsekey.c index a98e8cc..4829e3e 100644 --- a/parsekey.c +++ b/parsekey.c @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: parsekey.c,v 1.9 2003/09/28 21:07:49 noodles Exp $ + * $Id: parsekey.c,v 1.10 2003/09/29 07:35:26 noodles Exp $ */ #include @@ -219,7 +219,9 @@ int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count, curpacket->packet->length += 192; } else if (curpacket->packet->length > 223 && curpacket->packet->length < 255) { - printf("Partial length; not supported.\n"); + logthing(LOGTHING_NOTICE, + "Partial length;" + " not supported.\n"); } else if (curpacket->packet->length == 255) { /* * 5 byte length; ie 255 followed by 3 -- 2.39.2 From c7f25997d3d36ac30b26f663e1d257e4625662a1 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:55 +0000 Subject: [PATCH 11/16] cscvs to tla changeset 96 Author: noodles Date: 2003/09/30 16:58:04 Allow read_openpgp_stream to append to an existing list of packets rather than only returning the new packets. --- parsekey.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/parsekey.c b/parsekey.c index 4829e3e..ea56f83 100644 --- a/parsekey.c +++ b/parsekey.c @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: parsekey.c,v 1.10 2003/09/29 07:35:26 noodles Exp $ + * $Id: parsekey.c,v 1.11 2003/09/30 16:58:04 noodles Exp $ */ #include @@ -179,6 +179,10 @@ int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count, bool inpacket = false; assert(packets != NULL); + curpacket = *packets; + while (curpacket->next != NULL) { + curpacket = curpacket->next; + } while (!rc && !getchar_func(ctx, 1, &curchar)) { if (!inpacket && (curchar & 0x80)) { -- 2.39.2 From 047b8ed75bbac19ef33690bd44746718a8261439 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:56 +0000 Subject: [PATCH 12/16] cscvs to tla changeset 97 Author: noodles Date: 2003/09/30 17:15:39 Move stdin/out character functions to charfuncs.c for easier reuse. --- charfuncs.c | 33 ++++++++++++++++++++++++++++++++- charfuncs.h | 11 ++++++++++- onak.c | 27 ++------------------------- 3 files changed, 44 insertions(+), 27 deletions(-) diff --git a/charfuncs.c b/charfuncs.c index 3bfc3cc..52f1155 100644 --- a/charfuncs.c +++ b/charfuncs.c @@ -5,9 +5,10 @@ * * Copyright 2002 Project Purple * - * $Id: charfuncs.c,v 1.2 2003/06/04 20:57:07 noodles Exp $ + * $Id: charfuncs.c,v 1.3 2003/09/30 17:15:39 noodles Exp $ */ +#include #include #include #include @@ -81,3 +82,33 @@ int file_putchar(void *fd, size_t count, unsigned char *c) { return !(write( *(int *) fd, c, count)); } + +/** + * stdin_getchar - Gets a char from stdin. + */ +int stdin_getchar(void *ctx, size_t count, unsigned char *c) +{ + int ic = 0; + + while ((count > 0) && (ic != EOF)) { + ic = getchar(); + *c = ic; + c++; + count--; + } + + return (ic == EOF); +} + +/** + * stdout_putchar - Puts a char to stdout. + */ +int stdout_putchar(void *ctx, size_t count, unsigned char *c) +{ + int i; + + for (i = 0; i < count; i++) { + putchar(c[i]); + } + return 0; +} diff --git a/charfuncs.h b/charfuncs.h index e350143..ffa7bf9 100644 --- a/charfuncs.h +++ b/charfuncs.h @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: charfuncs.h,v 1.2 2003/06/04 20:57:07 noodles Exp $ + * $Id: charfuncs.h,v 1.3 2003/09/30 17:15:39 noodles Exp $ */ #ifndef __CHARFUNCS_H__ @@ -55,5 +55,14 @@ int file_fetchchar(void *fd, size_t count, unsigned char *c); */ int file_putchar(void *fd, size_t count, unsigned char *c); +/** + * stdin_getchar - Gets a char from stdin. + */ +int stdin_getchar(void *ctx, size_t count, unsigned char *c); + +/** + * stdout_putchar - Puts a char to stdout. + */ +int stdout_putchar(void *ctx, size_t count, unsigned char *c); #endif /* __CHARFUNCS_H__ */ diff --git a/onak.c b/onak.c index 903c8f0..b69c594 100644 --- a/onak.c +++ b/onak.c @@ -7,7 +7,7 @@ * * Copyright 2002 Project Purple * - * $Id: onak.c,v 1.15 2003/09/28 20:33:34 noodles Exp $ + * $Id: onak.c,v 1.16 2003/09/30 17:15:39 noodles Exp $ */ #include @@ -16,6 +16,7 @@ #include #include "armor.h" +#include "charfuncs.h" #include "keydb.h" #include "keyid.h" #include "keyindex.h" @@ -26,30 +27,6 @@ #include "onak-conf.h" #include "parsekey.h" -int stdin_getchar(void *ctx, size_t count, unsigned char *c) -{ - int ic = 0; - - while ((count > 0) && (ic != EOF)) { - ic = getchar(); - *c = ic; - c++; - count--; - } - - return (ic == EOF); -} - -int stdout_putchar(void *ctx, size_t count, unsigned char *c) -{ - int i; - - for (i = 0; i < count; i++) { - putchar(c[i]); - } - return 0; -} - void find_keys(char *search, uint64_t keyid, bool ishex, bool fingerprint, bool exact, bool verbose) { -- 2.39.2 From 156fd1c31592b821c170b5567b2fc81060359232 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:57 +0000 Subject: [PATCH 13/16] cscvs to tla changeset 98 Author: noodles Date: 2003/09/30 17:40:41 Fix stupid bug with read_openpgp_stream and an empty packet list. --- parsekey.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/parsekey.c b/parsekey.c index ea56f83..9cdb90c 100644 --- a/parsekey.c +++ b/parsekey.c @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: parsekey.c,v 1.11 2003/09/30 16:58:04 noodles Exp $ + * $Id: parsekey.c,v 1.12 2003/09/30 17:40:41 noodles Exp $ */ #include @@ -180,8 +180,10 @@ int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count, assert(packets != NULL); curpacket = *packets; - while (curpacket->next != NULL) { - curpacket = curpacket->next; + if (curpacket != NULL) { + while (curpacket->next != NULL) { + curpacket = curpacket->next; + } } while (!rc && !getchar_func(ctx, 1, &curchar)) { -- 2.39.2 From ae384229c538b20b429ea640ec30071ae944c0e7 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:58 +0000 Subject: [PATCH 14/16] cscvs to tla changeset 99 Author: noodles Date: 2003/09/30 20:40:10 Allow a limit on the number of keys returned by read_openpgp_stream. --- armor.c | 5 +++-- keydb_db2.c | 4 ++-- keydb_db3.c | 4 ++-- keydb_file.c | 4 ++-- keydb_pg.c | 4 ++-- main.c | 2 +- onak.c | 4 ++-- parsekey.c | 13 ++++++++++--- parsekey.h | 11 ++++++++--- 9 files changed, 32 insertions(+), 19 deletions(-) diff --git a/armor.c b/armor.c index 3f47f64..f2e97fc 100644 --- a/armor.c +++ b/armor.c @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: armor.c,v 1.6 2003/06/07 13:45:34 noodles Exp $ + * $Id: armor.c,v 1.7 2003/09/30 20:40:10 noodles Exp $ */ #include @@ -396,7 +396,8 @@ int dearmor_openpgp_stream(int (*getchar_func)(void *ctx, size_t count, dearmor_init(&dearmor_ctx); dearmor_ctx.getchar_func = getchar_func; dearmor_ctx.ctx = ctx; - read_openpgp_stream(dearmor_getchar_c, &dearmor_ctx, packets); + read_openpgp_stream(dearmor_getchar_c, &dearmor_ctx, + packets, 0); dearmor_finish(&dearmor_ctx); /* * TODO: Look for armor footer diff --git a/keydb_db2.c b/keydb_db2.c index 0ff31cb..77a6f8b 100644 --- a/keydb_db2.c +++ b/keydb_db2.c @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: keydb_db2.c,v 1.9 2003/06/04 20:57:08 noodles Exp $ + * $Id: keydb_db2.c,v 1.10 2003/09/30 20:40:10 noodles Exp $ */ #include @@ -200,7 +200,7 @@ int fetch_key(uint64_t keyid, struct openpgp_publickey **publickey, fetchbuf.buffer = data.data; fetchbuf.offset = 0; fetchbuf.size = data.size; - read_openpgp_stream(buffer_fetchchar, &fetchbuf, &packets); + read_openpgp_stream(buffer_fetchchar, &fetchbuf, &packets, 0); parse_keys(packets, publickey); free_packet_list(packets); packets = NULL; diff --git a/keydb_db3.c b/keydb_db3.c index f686770..56f4bed 100644 --- a/keydb_db3.c +++ b/keydb_db3.c @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: keydb_db3.c,v 1.19 2003/09/28 16:12:47 noodles Exp $ + * $Id: keydb_db3.c,v 1.20 2003/09/30 20:40:10 noodles Exp $ */ #include @@ -340,7 +340,7 @@ int fetch_key(uint64_t keyid, struct openpgp_publickey **publickey, fetchbuf.offset = 0; fetchbuf.size = data.size; read_openpgp_stream(buffer_fetchchar, &fetchbuf, - &packets); + &packets, 0); parse_keys(packets, publickey); free_packet_list(packets); packets = NULL; diff --git a/keydb_file.c b/keydb_file.c index 0ca39ae..7426369 100644 --- a/keydb_file.c +++ b/keydb_file.c @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: keydb_file.c,v 1.9 2003/06/05 07:31:59 noodles Exp $ + * $Id: keydb_file.c,v 1.10 2003/09/30 20:40:10 noodles Exp $ */ #include @@ -88,7 +88,7 @@ int fetch_key(uint64_t keyid, struct openpgp_publickey **publickey, fd = open(keyfile, O_RDONLY); // | O_SHLOCK); if (fd > -1) { - read_openpgp_stream(file_fetchchar, &fd, &packets); + read_openpgp_stream(file_fetchchar, &fd, &packets, 0); parse_keys(packets, publickey); free_packet_list(packets); packets = NULL; diff --git a/keydb_pg.c b/keydb_pg.c index cdfbe63..b424b7f 100644 --- a/keydb_pg.c +++ b/keydb_pg.c @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: keydb_pg.c,v 1.12 2003/06/08 21:11:01 noodles Exp $ + * $Id: keydb_pg.c,v 1.13 2003/09/30 20:40:11 noodles Exp $ */ #include @@ -176,7 +176,7 @@ int fetch_key(uint64_t keyid, struct openpgp_publickey **publickey, "Can't open large object."); } else { read_openpgp_stream(keydb_fetchchar, &fd, - &packets); + &packets, 0); parse_keys(packets, publickey); lo_close(dbconn, fd); free_packet_list(packets); diff --git a/main.c b/main.c index b140c8e..9580e01 100644 --- a/main.c +++ b/main.c @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) void *ctx = NULL; fputs("Doing read_openpgp_stream():\n", stderr); - read_openpgp_stream(getnextchar, ctx, &packets); + read_openpgp_stream(getnextchar, ctx, &packets, 0); */ fputs("Doing dearmor_openpgp_stream():\n", stderr); dearmor_openpgp_stream(getnextchar, NULL, &packets); diff --git a/onak.c b/onak.c index b69c594..2da86c9 100644 --- a/onak.c +++ b/onak.c @@ -7,7 +7,7 @@ * * Copyright 2002 Project Purple * - * $Id: onak.c,v 1.16 2003/09/30 17:15:39 noodles Exp $ + * $Id: onak.c,v 1.17 2003/09/30 20:40:11 noodles Exp $ */ #include @@ -113,7 +113,7 @@ int main(int argc, char *argv[]) } else if (!strcmp("add", argv[optind])) { if (binary) { result = read_openpgp_stream(stdin_getchar, NULL, - &packets); + &packets, 0); logthing(LOGTHING_INFO, "read_openpgp_stream: %d", result); } else { diff --git a/parsekey.c b/parsekey.c index 9cdb90c..b921186 100644 --- a/parsekey.c +++ b/parsekey.c @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: parsekey.c,v 1.12 2003/09/30 17:40:41 noodles Exp $ + * $Id: parsekey.c,v 1.13 2003/09/30 20:40:11 noodles Exp $ */ #include @@ -162,6 +162,7 @@ int debug_packet(struct openpgp_packet *packet) * @getchar_func: The function to get the next character from the stream. * @ctx: A pointer to the context structure for getchar_func. * @packets: The outputted list of packets. + * @maxnum: The maximum number of keys to read. 0 means unlimited. * * This function uses getchar_func to read characters from an OpenPGP * packet stream and reads the packets into a linked list of packets @@ -170,12 +171,14 @@ int debug_packet(struct openpgp_packet *packet) int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count, unsigned char *c), void *ctx, - struct openpgp_packet_list **packets) + struct openpgp_packet_list **packets, + int maxnum) { unsigned char curchar = 0; unsigned long count = 0; struct openpgp_packet_list *curpacket = NULL; int rc = 0; + int keys = 0; bool inpacket = false; assert(packets != NULL); @@ -186,7 +189,8 @@ int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count, } } - while (!rc && !getchar_func(ctx, 1, &curchar)) { + while (!rc && !getchar_func(ctx, 1, &curchar) && + (maxnum == 0 || keys < maxnum)) { if (!inpacket && (curchar & 0x80)) { /* * New packet. Record the fact we're in a packet and @@ -283,6 +287,9 @@ int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count, } if (rc == 0) { + if (curpacket->packet->tag == 6) { + keys++; + } curpacket->packet->data = malloc(curpacket->packet->length * sizeof(unsigned char)); diff --git a/parsekey.h b/parsekey.h index 682629c..ed7e3a0 100644 --- a/parsekey.h +++ b/parsekey.h @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: parsekey.h,v 1.4 2003/06/04 20:57:12 noodles Exp $ + * $Id: parsekey.h,v 1.5 2003/09/30 20:40:11 noodles Exp $ */ #ifndef __PARSEKEY_H__ @@ -53,15 +53,20 @@ int debug_packet(struct openpgp_packet *packet); * @getchar_func: The function to get the next character from the stream. * @ctx: A pointer to the context structure for getchar_func. * @packets: The outputted list of packets. + * @maxnum: The maximum number of keys to read. 0 means unlimited. * * This function uses getchar_func to read characters from an OpenPGP * packet stream and reads the packets into a linked list of packets - * ready for parsing as a public key or whatever. + * ready for parsing as a public key or whatever. maxnum allows you to + * specify the maximum number of keys to read. Note that if this is used + * then only the public key component of the last key will be returned, + * none of the other packets of the key will be read. */ int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count, unsigned char *c), void *ctx, - struct openpgp_packet_list **packets); + struct openpgp_packet_list **packets, + int maxnum); /** * write_openpgp_stream - Reads a stream of OpenPGP packets. -- 2.39.2 From 4843e5290f2e7060ca5777c64b96e680080644f2 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:59 +0000 Subject: [PATCH 15/16] cscvs to tla changeset 100 Author: noodles Date: 2003/09/30 21:16:14 Adding splitkeys for spliting up keyrings. --- Makefile | 7 ++++-- splitkeys.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 splitkeys.c diff --git a/Makefile b/Makefile index 7917088..cd9de0f 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # # Makefile for onak. # -# $Id: Makefile,v 1.16 2003/06/06 14:02:39 noodles Exp $ +# $Id: Makefile,v 1.17 2003/09/30 21:16:14 noodles Exp $ # CC = gcc @@ -23,7 +23,10 @@ SRCS = armor.c parsekey.c merge.c keyid.c md5.c sha.c main.c getcgi.c stats.c \ keyindex.c mem.c lookup.c add.c keydb_$(DBTYPE).c ll.c hash.c \ gpgwww.c onak-conf.c charfuncs.c sendsync.c log.c -all: .depend $(PROGS) testparse maxpath sixdegrees +all: .depend $(PROGS) testparse maxpath sixdegrees splitkeys + +splitkeys: splitkeys.o $(CORE_OBJS) + $(LINK) -o splitkeys splitkeys.o $(CORE_OBJS) $(LIBS) testparse: main.o $(OBJS) $(LINK) -o testparse main.o $(OBJS) $(LIBS) diff --git a/splitkeys.c b/splitkeys.c new file mode 100644 index 0000000..a2daac6 --- /dev/null +++ b/splitkeys.c @@ -0,0 +1,69 @@ +/* + * splitkeys.c - Split a keyring into smaller chunks. + * + * Jonathan McDowell + * + * Copyright 2003 Project Purple + * + * $Id: splitkeys.c,v 1.1 2003/09/30 21:16:14 noodles Exp $ + */ + +#include +#include +#include +#include +#include + +#include "charfuncs.h" +#include "keystructs.h" +#include "mem.h" +#include "parsekey.h" + +int main(int argc, char *argv[]) +{ + struct openpgp_packet_list *packets = NULL; + struct openpgp_packet_list *list_end = NULL; + struct openpgp_packet_list *tmp = NULL; + int result = 0; + int maxkeys = 10000; + int outfd = -1; + int count = 0; + char splitfile[1024]; + + if (argc > 1) { + maxkeys = atoi(argv[1]); + if (maxkeys == 0) { + fprintf(stderr, + "Couldn't parse %s as a number of keys!\n", + argv[1]); + exit(1); + } + } + + do { + result = read_openpgp_stream(stdin_getchar, NULL, + &packets, maxkeys); + if (packets != NULL) { + list_end = packets; + while (list_end->next != NULL) { + tmp = list_end; + list_end = list_end->next; + if (list_end->next == NULL && + list_end->packet->tag == 6) { + tmp->next = NULL; + } + } + + snprintf(splitfile, 1023, "splitfile-%d.pgp", count); + outfd = open(splitfile, O_WRONLY | O_CREAT, 0664); + write_openpgp_stream(file_putchar, &outfd, + packets); + close(outfd); + free_packet_list(packets); + packets = list_end; + count++; + } + } while (packets != NULL); + + return 0; +} -- 2.39.2 From 836235113fd74ba178418530aa9eba4d452eb557 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:59 +0000 Subject: [PATCH 16/16] cscvs to tla changeset 101 Author: noodles Date: 2003/09/30 21:59:33 Remove trailing \n from Partial key error message. --- parsekey.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parsekey.c b/parsekey.c index b921186..b492937 100644 --- a/parsekey.c +++ b/parsekey.c @@ -5,7 +5,7 @@ * * Copyright 2002 Project Purple * - * $Id: parsekey.c,v 1.13 2003/09/30 20:40:11 noodles Exp $ + * $Id: parsekey.c,v 1.14 2003/09/30 21:59:33 noodles Exp $ */ #include @@ -231,7 +231,7 @@ int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count, curpacket->packet->length < 255) { logthing(LOGTHING_NOTICE, "Partial length;" - " not supported.\n"); + " not supported."); } else if (curpacket->packet->length == 255) { /* * 5 byte length; ie 255 followed by 3 -- 2.39.2