From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:58 +0000 (+0000) Subject: cscvs to tla changeset 99 X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/commitdiff_plain/ae384229c538b20b429ea640ec30071ae944c0e7 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. --- 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.