diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/argparse.c | 1 | ||||
-rw-r--r-- | util/errors.c | 7 | ||||
-rw-r--r-- | util/iobuf.c | 106 | ||||
-rw-r--r-- | util/logger.c | 16 | ||||
-rw-r--r-- | util/ttyio.c | 2 |
5 files changed, 106 insertions, 26 deletions
diff --git a/util/argparse.c b/util/argparse.c index 80b7fcd3d..c6c0302b9 100644 --- a/util/argparse.c +++ b/util/argparse.c @@ -188,7 +188,6 @@ int optfile_parse( FILE *fp, const char *filename, unsigned *lineno, ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts) { - char *s, *s2; int state, i, c; int index=0; char keyword[100]; diff --git a/util/errors.c b/util/errors.c index 46797df3b..9b8848f4c 100644 --- a/util/errors.c +++ b/util/errors.c @@ -33,6 +33,8 @@ g10_errstr( int err ) #define X(n,s) case G10ERR_##n : p = s; break; switch( err ) { + case -1: p = "eof"; break; + case 0: p = "okay"; break; X(GENERAL, "General error") X(UNKNOWN_PACKET, "Unknown packet type") X(UNKNOWN_VERSION,"Unknown version") @@ -46,6 +48,7 @@ g10_errstr( int err ) X(NO_PUBKEY ,"Public key not found") X(CIPHER_ALGO ,"Unknown cipher algorithm") X(KEYRING_OPEN ,"Can't open the keyring") + X(INVALID_PACKET ,"Invalid packet") X(BAD_RING ,"Broken keyring") X(NO_USER_ID ,"No such user id found") X(NO_SECKEY ,"Secret key not available") @@ -61,8 +64,10 @@ g10_errstr( int err ) X(NI_PUBKEY ,"Unimplemented pubkey algorithm") X(NI_CIPHER ,"Unimplemented cipher algorithm") X(SIG_CLASS ,"Unknown signature class") + X(TRUSTDB ,"TrustDB error") + X(BAD_CERT ,"Bad certificate") - default: p = buf; sprintf(buf, "Error code %d", err); break; + default: p = buf; sprintf(buf, "g10err=%d", err); break; } #undef X return p; diff --git a/util/iobuf.c b/util/iobuf.c index ad9821972..72a14f503 100644 --- a/util/iobuf.c +++ b/util/iobuf.c @@ -40,6 +40,7 @@ typedef struct { int usage; size_t size; size_t count; + int partial; /* 1 = partial header, 2 in last partial packet */ int eof; } block_filter_ctx_t; @@ -143,20 +144,64 @@ block_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len) rc = -1; while( !rc && size ) { if( !a->size ) { /* get the length bytes */ - c = iobuf_get(chain); - a->size = c << 8; - c = iobuf_get(chain); - a->size |= c; - if( c == -1 ) { - log_error("block_filter: error reading length info\n"); - rc = G10ERR_READ_FILE; - } - if( !a->size ) { + if( a->partial == 2 ) { a->eof = 1; if( !n ) rc = -1; break; } + else if( a->partial ) { + if( (c = iobuf_get(chain)) == -1 ) { + log_error("block_filter: 1st length byte missing\n"); + rc = G10ERR_READ_FILE; + break; + } + if( c < 192 ) { + a->size = c; + a->partial = 2; + if( !a->size ) { + a->eof = 1; + if( !n ) + rc = -1; + break; + } + } + else if( c < 224 ) { + a->size = (c - 192) * 256; + if( (c = iobuf_get(chain)) == -1 ) { + log_error("block_filter: 2nd length byte missing\n"); + rc = G10ERR_READ_FILE; + break; + } + a->size += c + 192; + a->partial = 2; + if( !a->size ) { + a->eof = 1; + if( !n ) + rc = -1; + break; + } + } + else { /* next partial body length */ + a->size = 1 << (c & 0x1f); + } + } + else { + c = iobuf_get(chain); + a->size = c << 8; + c = iobuf_get(chain); + a->size |= c; + if( c == -1 ) { + log_error("block_filter: error reading length info\n"); + rc = G10ERR_READ_FILE; + } + if( !a->size ) { + a->eof = 1; + if( !n ) + rc = -1; + break; + } + } } for(; !rc && size && a->size; size--, a->size-- ) { @@ -176,6 +221,7 @@ block_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len) else if( control == IOBUFCTRL_FLUSH ) { size_t avail, n; + assert( !a->partial ); for(p=buf; !rc && size; ) { n = size; avail = a->size - a->count; @@ -205,7 +251,9 @@ block_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len) else if( control == IOBUFCTRL_INIT ) { if( DBG_IOBUF ) log_debug("init block_filter %p\n", a ); - if( a->usage == 1 ) + if( a->partial ) + a->count = 0; + else if( a->usage == 1 ) a->count = a->size = 0; else a->count = a->size; /* force first length bytes */ @@ -216,8 +264,12 @@ block_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len) } else if( control == IOBUFCTRL_FREE ) { if( a->usage == 2 ) { /* write the end markers */ - iobuf_writebyte(chain, 0); - iobuf_writebyte(chain, 0); + if( a->partial ) { + } + else { + iobuf_writebyte(chain, 0); + iobuf_writebyte(chain, 0); + } } else if( a->size ) { log_error("block_filter: pending bytes!\n"); @@ -784,7 +836,10 @@ iobuf_seek( IOBUF a, ulong newpos ) return -1; } a->ntotal = newpos; - /* FIXME: flush all buffers (and remove filters?)*/ + /* remove filters, but the last */ + while( a->chain ) + iobuf_pop_filter( a, a->filter, NULL ); + return 0; } @@ -800,8 +855,6 @@ iobuf_seek( IOBUF a, ulong newpos ) const char * iobuf_get_fname( IOBUF a ) { - struct stat st; - for( ; a; a = a->chain ) if( !a->chain && a->filter == file_filter ) { file_filter_ctx_t *b = a->filter_ov; @@ -832,6 +885,27 @@ iobuf_set_block_mode( IOBUF a, size_t n ) } } +/**************** + * enable patial block mode as descriped in the OpenPGP draft. + * LEN is the first length + */ +void +iobuf_set_partial_block_mode( IOBUF a, size_t len ) +{ + block_filter_ctx_t *ctx = m_alloc_clear( sizeof *ctx ); + + assert( a->usage == 1 || a->usage == 2 ); + ctx->usage = a->usage; + if( !len ) { + iobuf_pop_filter(a, block_filter, NULL ); + } + else { + ctx->partial = 1; + ctx->size = len; + iobuf_push_filter(a, block_filter, ctx ); + } +} + /**************** * Checks wether the stream is in block mode @@ -841,7 +915,7 @@ int iobuf_in_block_mode( IOBUF a ) { if( a && a->filter == block_filter ) - return 1; /* yes */ + return 1; /* yes */ return 0; /* no */ } diff --git a/util/logger.c b/util/logger.c index c32332b48..2355b6267 100644 --- a/util/logger.c +++ b/util/logger.c @@ -120,18 +120,20 @@ log_bug( const char *fmt, ... ) va_list arg_ptr ; fprintf(stderr, "\nInternal Error%s: ", pidstring ) ; - if( fmt ) { - va_start( arg_ptr, fmt ) ; - vfprintf(stderr,fmt,arg_ptr) ; - va_end(arg_ptr); - } - else - fputs("Ohhh jeeee ...\n", stderr); + va_start( arg_ptr, fmt ) ; + vfprintf(stderr,fmt,arg_ptr) ; + va_end(arg_ptr); fflush(stderr); abort(); } void +log_bug0() +{ + log_bug("Ohhhh jeeee ...\n"); +} + +void log_debug( const char *fmt, ... ) { va_list arg_ptr ; diff --git a/util/ttyio.c b/util/ttyio.c index 2cb52448c..ec7b6502b 100644 --- a/util/ttyio.c +++ b/util/ttyio.c @@ -23,6 +23,7 @@ #include <stdlib.h> #include <string.h> #include <stdarg.h> +#include <unistd.h> #ifdef HAVE_TCGETATTR #include <termios.h> #endif @@ -99,7 +100,6 @@ do_get( const char *prompt, int hidden ) char *buf; byte cbuf[1]; int c, n, i; - FILE *fp; #ifdef HAVE_TCGETATTR struct termios termsave; #endif |