summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDavid Shaw <dshaw@jabberwocky.com>2002-06-29 15:46:34 +0200
committerDavid Shaw <dshaw@jabberwocky.com>2002-06-29 15:46:34 +0200
commit3f51f7db3de85574dc5d6efd8b54ef78c1cd3f37 (patch)
treedac7a3780fb4edf9ca89c93800230e88ab255434 /tools
parentUpdate head to match stable 1.0 (diff)
downloadgnupg2-3f51f7db3de85574dc5d6efd8b54ef78c1cd3f37.tar.xz
gnupg2-3f51f7db3de85574dc5d6efd8b54ef78c1cd3f37.zip
Update head to match stable 1.0
Diffstat (limited to 'tools')
-rw-r--r--tools/ChangeLog76
-rw-r--r--tools/Makefile.am40
-rw-r--r--tools/bftest.c70
-rw-r--r--tools/clean-sat.c9
-rw-r--r--tools/crlf.c9
-rw-r--r--tools/gpgsplit.c553
-rwxr-xr-xtools/lspgpot8
-rwxr-xr-xtools/mail-signed-keys105
-rw-r--r--tools/mk-tdata.c10
-rw-r--r--tools/mpicalc.c37
-rwxr-xr-xtools/ring-a-party21
-rw-r--r--tools/shmtest.c25
12 files changed, 813 insertions, 150 deletions
diff --git a/tools/ChangeLog b/tools/ChangeLog
index 2faf8de06..0cb89ae11 100644
--- a/tools/ChangeLog
+++ b/tools/ChangeLog
@@ -1,22 +1,61 @@
-2000-10-10 Werner Koch <wk@gnupg.org>
+2002-05-07 Stefan Bellon <sbellon@sbellon.de>
- * bftest.c (main): Allow selection of cipher mode.
+ * gpgsplit.c (create_filename): Use EXTSEP_S instead of ".".
-Mon Sep 18 16:35:45 CEST 2000 Werner Koch <wk@openit.de>
+2002-04-23 David Shaw <dshaw@jabberwocky.com>
- * ring-a-party: substr starts at offset 1 not 0. Many thanks to Mike
- for finding this bug. Flush the last key.
+ * Makefile.am: Do not list libraries in -lxxx format in a
+ dependency line.
-Mon Jul 17 16:35:47 CEST 2000 Werner Koch <wk@>
+2002-01-02 Stefan Bellon <sbellon@sbellon.de>
- * mail-signed-keys: New.
- * ring-a-party: New.
+ * gpgsplit.c [__riscos__]: Added RISC OS specific file name
+ code.
-Mon Jan 31 17:46:35 CET 2000 Werner Koch <wk@>
+ * gpgsplit.c (write_part): Introduced two explicit casts.
- * Makefile.am: Add libjnlib.
- * bftest.c: Some minor hacks to let it compile.
- * mpicalc.c: Ditto.
+2001-12-21 David Shaw <dshaw@jabberwocky.com>
+
+ * gpgsplit.c (pkttype_to_string): PKT_PHOTO_ID -> PKT_ATTRIBUTE
+
+2001-10-23 Werner Koch <wk@gnupg.org>
+
+ * Makefile.am (gpgsplit_LDADD): Add ZLIBS.
+
+2001-09-18 Werner Koch <wk@gnupg.org>
+
+ * gpgsplit.c: New option --uncompress.
+ (write_part): Handle old style uncompressing.
+
+2001-06-20 Werner Koch <wk@gnupg.org>
+
+ * gpgsplit.c: New.
+ * Makefile.am (bin_PROGRAMS): Install gpgsplit.
+
+2001-03-27 Werner Koch <wk@gnupg.org>
+
+ * mail-signed-keys: Add option --dry-run.
+
+2001-03-21 Werner Koch <wk@gnupg.org>
+
+ * shmtest.c: Add sys/types.h
+
+Fri Sep 15 18:40:36 CEST 2000 Werner Koch <wk@openit.de>
+
+ * ring-a-party: An array start at offset 1 no 0. Many thanks to Mike
+ for finding this bug.
+
+Thu Sep 14 14:20:38 CEST 2000 Werner Koch <wk@openit.de>
+
+ * ring-a-party: Flush the last key.
+
+Wed Jul 5 13:28:45 CEST 2000 Werner Koch <wk@>
+
+ * mail-signed-keys: New.
+
+Tue May 23 09:19:00 CEST 2000 Werner Koch <wk@openit.de>
+
+ * ring-a-party: New.
Thu Jul 8 16:21:27 CEST 1999 Werner Koch <wk@isil.d.shuttle.de>
@@ -43,3 +82,16 @@ Tue Apr 7 19:50:41 1998 Werner Koch (wk@isil.d.shuttle.de)
* bftest.c: Now supports all availabe ciphers.
+
+
+ Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+
+ This file is free software; as a special exception the author gives
+ unlimited permission to copy and/or distribute it, with or without
+ modifications, as long as this notice is preserved.
+
+ This file is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 4e261ca34..769e30c48 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,14 +1,28 @@
-## Process this file with automake to produce Makefile.in
+# Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+#
+# This file is part of GnuPG.
+#
+# GnuPG is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# GnuPG is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
-EXTRA_DIST = lspgpot mail-signed-keys ring-a-party
-INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/intl
-# we need to add libutil.la a second time because we have to resolve
-# gpg_log_ in some libjnlib modules. - very ugly - should be removed soon.
-needed_libs = ../util/libutil.a \
- ../jnlib/libjnlib.a ../util/libutil.a \
- @INTLLIBS@
+## Process this file with automake to produce Makefile.in
+EXTRA_DIST = lspgpot ring-a-party mail-signed-keys
+INCLUDES = -I.. -I$(top_srcdir)/include -I$(top_srcdir)/intl
+needed_libs = ../cipher/libcipher.a ../mpi/libmpi.a ../util/libutil.a
+bin_PROGRAMS = gpgsplit
noinst_PROGRAMS = mpicalc bftest clean-sat mk-tdata shmtest
mpicalc_SOURCES = mpicalc.c
@@ -19,11 +33,13 @@ clean_sat_SOURCES = clean-sat.c
mk_tdata_SOURCES = mk-tdata.c
shmtest_SOURCES = shmtest.c
+gpgsplit_SOURCES = gpgsplit.c
-mpicalc_LDADD = $(needed_libs) $(LIBGCRYPT_LIBS)
-bftest_LDADD = $(needed_libs) $(LIBGCRYPT_LIBS)
-shmtest_LDADD = $(needed_libs) $(LIBGCRYPT_LIBS)
+mpicalc_LDADD = $(needed_libs) @INTLLIBS@
+bftest_LDADD = $(needed_libs) @INTLLIBS@
-mpicalc bftest shmtest: $(needed_libs)
+shmtest_LDADD = $(needed_libs) @INTLLIBS@
+gpgsplit_LDADD = @ZLIBS@ $(needed_libs) @INTLLIBS@
+mpicalc bftest shmtest gpgsplit: $(needed_libs)
diff --git a/tools/bftest.c b/tools/bftest.c
index 6b1e09117..b15f4a1da 100644
--- a/tools/bftest.c
+++ b/tools/bftest.c
@@ -1,5 +1,5 @@
/* bftest.c - Blowfish test program
- * Copyright (C) 1998 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -27,17 +27,22 @@
#include <fcntl.h>
#endif
-#include <gcrypt.h>
#include "util.h"
+#include "cipher.h"
#include "i18n.h"
static void
my_usage(void)
{
- fprintf(stderr, "usage: bftest [-e][-d] algo mode key\n");
+ fprintf(stderr, "usage: bftest [-e][-d] algo key\n");
exit(1);
}
+const char *
+strusage( int level )
+{
+ return default_strusage(level);
+}
static void
i18n_init(void)
@@ -48,7 +53,7 @@ i18n_init(void)
#else
setlocale( LC_ALL, "" );
#endif
- bindtextdomain( PACKAGE, GNUPG_LOCALEDIR );
+ bindtextdomain( PACKAGE, G10_LOCALEDIR );
textdomain( PACKAGE );
#endif
}
@@ -57,12 +62,11 @@ int
main(int argc, char **argv)
{
int encode=0;
- GCRY_CIPHER_HD hd;
+ CIPHER_HANDLE hd;
char buf[4096];
- int rc, n, size=4096;
- int algo, mode;
- const char *s;
-
+ int n, size=4096;
+ int algo;
+
#ifdef HAVE_DOSISH_SYSTEM
setmode( fileno(stdin), O_BINARY );
setmode( fileno(stdout), O_BINARY );
@@ -85,56 +89,24 @@ main(int argc, char **argv)
argc--; argv++;
size = 10;
}
- if( argc != 4 )
+ if( argc != 3 )
my_usage();
argc--; argv++;
- algo = gcry_cipher_map_name( *argv );
+ algo = string_to_cipher_algo( *argv );
argc--; argv++;
- s = *argv; argc--; argv++;
- if ( !strcasecmp( s, "cfb" ) )
- mode = GCRY_CIPHER_MODE_CFB;
- else if ( !strcasecmp( s, "cbc" ) )
- mode = GCRY_CIPHER_MODE_CBC;
- else if ( !strcasecmp( s, "ebc" ) )
- mode = GCRY_CIPHER_MODE_ECB;
- else if ( !strcasecmp( s, "none" ) )
- mode = GCRY_CIPHER_MODE_NONE;
- else if ( !strcasecmp( s, "stream" ) )
- mode = GCRY_CIPHER_MODE_STREAM;
- else {
- fprintf( stderr,
- "wrong mode; use one of: none, ecb, cbc, cfb, stream\n");
- return 1;
- }
- hd = gcry_cipher_open( algo, mode, 0 );
- if (!hd )
- log_fatal("cipher open failed: %s\n", gcry_strerror(-1) );
- rc = gcry_cipher_setkey( hd, *argv, strlen(*argv) );
- if ( rc )
- log_fatal("setkey failed: %s\n", gcry_strerror(rc) );
- gcry_cipher_setiv( hd, NULL, 0 );
+ hd = cipher_open( algo, CIPHER_MODE_CFB, 0 );
+ cipher_setkey( hd, *argv, strlen(*argv) );
+ cipher_setiv( hd, NULL, 0 );
while( (n = fread( buf, 1, size, stdin )) > 0 ) {
if( encode )
- gcry_cipher_encrypt( hd, buf, n, buf, n );
+ cipher_encrypt( hd, buf, buf, n );
else
- gcry_cipher_decrypt( hd, buf, n, buf, n );
+ cipher_decrypt( hd, buf, buf, n );
if( fwrite( buf, 1, n, stdout) != n )
log_fatal("write error\n");
}
- gcry_cipher_close(hd);
+ cipher_close(hd);
return 0;
}
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tools/clean-sat.c b/tools/clean-sat.c
index b1edb2010..8b6bfd77a 100644
--- a/tools/clean-sat.c
+++ b/tools/clean-sat.c
@@ -1,4 +1,13 @@
/* clean-sat.c
+ * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ *
+ * This file is free software; as a special exception the author gives
+ * unlimited permission to copy and/or distribute it, with or without
+ * modifications, as long as this notice is preserved.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <stdio.h>
diff --git a/tools/crlf.c b/tools/crlf.c
index f81f77e69..e6ac8c70f 100644
--- a/tools/crlf.c
+++ b/tools/crlf.c
@@ -1,4 +1,13 @@
/* crlf.c
+ * Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+ *
+ * This file is free software; as a special exception the author gives
+ * unlimited permission to copy and/or distribute it, with or without
+ * modifications, as long as this notice is preserved.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <stdio.h>
diff --git a/tools/gpgsplit.c b/tools/gpgsplit.c
new file mode 100644
index 000000000..8d89b1b9d
--- /dev/null
+++ b/tools/gpgsplit.c
@@ -0,0 +1,553 @@
+/* gpgsplit.c - An OpenPGP packet splitting tool
+ * Copyright (C) 2001 Free Software Foundation, Inc.
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/*
+ * TODO: Add an option to uncompress packets. This should come quite handy.
+ */
+
+#include <config.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <assert.h>
+#ifdef HAVE_DOSISH_SYSTEM
+ #include <fcntl.h> /* for setmode() */
+#endif
+#include <zlib.h>
+#ifdef __riscos__
+#include <unixlib/local.h>
+#endif /* __riscos__ */
+
+#define INCLUDED_BY_MAIN_MODULE 1
+#include "../g10/packet.h"
+#include "util.h"
+
+static int opt_verbose;
+static const char *opt_prefix = "";
+static int opt_uncompress;
+
+static void g10_exit( int rc );
+static void split_packets (const char *fname);
+
+
+enum cmd_and_opt_values { aNull = 0,
+ oVerbose = 'v',
+ oPrefix = 'p',
+ oUncompress = 500,
+aTest };
+
+
+static ARGPARSE_OPTS opts[] = {
+
+ { 301, NULL, 0, "@Options:\n " },
+
+ { oVerbose, "verbose", 0, "verbose" },
+ { oPrefix, "prefix", 2, "|STRING|Prepend filenames with STRING" },
+ { oUncompress, "uncompress", 0, "uncompress a packet"},
+{0} };
+
+
+const char *
+strusage( int level )
+{
+ const char *p;
+ switch( level ) {
+ case 11: p = "gpgsplit (GnuPG)";
+ break;
+ case 13: p = VERSION; break;
+ case 17: p = PRINTABLE_OS_NAME; break;
+ case 19: p =
+ "Please report bugs to <bug-gnupg@gnu.org>.\n";
+ break;
+ case 1:
+ case 40: p =
+ "Usage: gpgsplit [options] [files] (-h for help)";
+ break;
+ case 41: p =
+ "Syntax: gpgsplit [options] [files]\n"
+ "Split an OpenPGP message into packets\n";
+ break;
+
+ default: p = default_strusage(level);
+ }
+ return p;
+}
+
+
+
+int
+main( int argc, char **argv )
+{
+ ARGPARSE_ARGS pargs;
+
+ #ifdef __riscos__
+ /* set global RISC OS specific properties */
+ __riscosify_control = __RISCOSIFY_NO_PROCESS;
+ #endif /* __riscos__ */
+ #ifdef HAVE_DOSISH_SYSTEM
+ setmode( fileno(stdin), O_BINARY );
+ setmode( fileno(stdout), O_BINARY );
+ #endif
+ log_set_name("gpgsplit");
+
+ pargs.argc = &argc;
+ pargs.argv = &argv;
+ pargs.flags= 1; /* do not remove the args */
+ while( optfile_parse( NULL, NULL, NULL, &pargs, opts) ) {
+ switch( pargs.r_opt ) {
+ case oVerbose: opt_verbose = 1; break;
+ case oPrefix: opt_prefix = pargs.r.ret_str; break;
+ case oUncompress: opt_uncompress = 1; break;
+ default : pargs.err = 2; break;
+ }
+ }
+
+ if( log_get_errorcount(0) )
+ g10_exit(2);
+
+ if (!argc)
+ split_packets (NULL);
+ else {
+ for ( ;argc; argc--, argv++)
+ split_packets (*argv);
+ }
+
+ g10_exit (0);
+ return 0;
+}
+
+
+static void
+g10_exit( int rc )
+{
+ rc = rc? rc : log_get_errorcount(0)? 2 : 0;
+ exit(rc );
+}
+
+static const char *
+pkttype_to_string (int pkttype)
+{
+ const char *s;
+ switch (pkttype) {
+ case PKT_PUBKEY_ENC : s = "pk_enc"; break;
+ case PKT_SIGNATURE : s = "sig"; break;
+ case PKT_SYMKEY_ENC : s = "sym_enc"; break;
+ case PKT_ONEPASS_SIG : s = "onepass_sig"; break;
+ case PKT_SECRET_KEY : s = "secret_key"; break;
+ case PKT_PUBLIC_KEY : s = "public_key"; break;
+ case PKT_SECRET_SUBKEY : s = "secret_subkey"; break;
+ case PKT_COMPRESSED :
+ s = opt_uncompress? "uncompressed":"compressed";
+ break;
+ case PKT_ENCRYPTED : s = "encrypted"; break;
+ case PKT_MARKER : s = "marker"; break;
+ case PKT_PLAINTEXT : s = "plaintext"; break;
+ case PKT_RING_TRUST : s = "ring_trust"; break;
+ case PKT_USER_ID : s = "user_id"; break;
+ case PKT_PUBLIC_SUBKEY : s = "public_subkey"; break;
+ case PKT_OLD_COMMENT : s = "old_comment"; break;
+ case PKT_ATTRIBUTE : s = "attribute"; break;
+ case PKT_ENCRYPTED_MDC : s = "encrypted_mdc"; break;
+ case PKT_MDC : s = "mdc"; break;
+ case PKT_COMMENT : s = "comment"; break;
+ case PKT_GPG_CONTROL : s = "gpg_control"; break;
+ default: s = "unknown"; break;
+ }
+ return s;
+}
+
+
+/*
+ * Create a new filename and a return a pointer to a statically
+ * allocated buffer
+ */
+static char *
+create_filename (int pkttype)
+{
+ static unsigned int partno = 0;
+ static char *name;
+
+ if (!name)
+ name = m_alloc (strlen (opt_prefix) + 100 );
+
+ assert (pkttype < 1000 && pkttype >= 0 );
+ partno++;
+ sprintf (name, "%s%06u-%03d" EXTSEP_S "%.40s",
+ opt_prefix, partno, pkttype, pkttype_to_string (pkttype));
+ return name;
+}
+
+static int
+read_u16 (FILE *fp, size_t *rn)
+{
+ int c;
+
+ if ( (c = getc (fp)) == EOF )
+ return -1;
+ *rn = c << 8;
+ if ( (c = getc (fp)) == EOF )
+ return -1;
+ *rn |= c;
+ return 0;
+}
+
+static int
+read_u32 (FILE *fp, unsigned long *rn)
+{
+ size_t tmp;
+
+ if (read_u16 (fp, &tmp))
+ return -1;
+ *rn = tmp << 16;
+ if (read_u16 (fp, &tmp))
+ return -1;
+ *rn |= tmp;
+ return 0;
+}
+
+
+/* hdr must pint to a buffer large enough to hold all header bytes */
+static int
+write_part ( const char *fname, FILE *fpin, unsigned long pktlen,
+ int pkttype, int partial, unsigned char *hdr, size_t hdrlen)
+{
+ FILE *fpout;
+ int c, first;
+ unsigned char *p;
+ const char *outname = create_filename (pkttype);
+
+ /* fixme: should we check that this file does not yet exist? */
+ if (opt_verbose)
+ log_info ("writing `%s'\n", outname);
+ fpout = fopen (outname, "wb");
+ if (!fpout) {
+ log_error ("error creating `%s': %s\n", outname, strerror(errno));
+ /* stop right now, otherwise we would mess up the sequence of
+ * the part numbers */
+ g10_exit (1);
+ }
+
+ if (!opt_uncompress) {
+ for (p=hdr; hdrlen; p++, hdrlen--) {
+ if ( putc (*p, fpout) == EOF )
+ goto write_error;
+ }
+ }
+
+ first = 1;
+ while (partial) {
+ size_t partlen;
+
+ if (partial == 1) { /* openpgp */
+ if( first ) {
+ c = pktlen;
+ assert( c >= 224 && c < 255 );
+ first = 0;
+ }
+ else if( (c = getc (fpin)) == EOF ) {
+ goto read_error;
+ }
+ else
+ hdr[hdrlen++] = c;
+
+ if( c < 192 ) {
+ pktlen = c;
+ partial = 0; /* (last segment may follow) */
+ }
+ else if( c < 224 ) {
+ pktlen = (c - 192) * 256;
+ if( (c = getc (fpin)) == EOF )
+ goto read_error;
+ hdr[hdrlen++] = c;
+ pktlen += c + 192;
+ partial = 0;
+ }
+ else if( c == 255 ) {
+ if (read_u32 (fpin, &pktlen))
+ goto read_error;
+ hdr[hdrlen++] = pktlen >> 24;
+ hdr[hdrlen++] = pktlen >> 16;
+ hdr[hdrlen++] = pktlen >> 8;
+ hdr[hdrlen++] = pktlen;
+ partial = 0;
+ }
+ else { /* next partial body length */
+ for (p=hdr; hdrlen; p++, hdrlen--) {
+ if ( putc (*p, fpout) == EOF )
+ goto write_error;
+ }
+ partlen = 1 << (c & 0x1f);
+ for (; partlen; partlen--) {
+ if ((c = getc (fpin)) == EOF)
+ goto read_error;
+ if ( putc (c, fpout) == EOF )
+ goto write_error;
+ }
+ }
+ }
+ else if (partial == 2) { /* old gnupg */
+ assert (!pktlen);
+ if ( read_u16 (fpin, &partlen) )
+ goto read_error;
+ hdr[hdrlen++] = partlen >> 8;
+ hdr[hdrlen++] = partlen;
+ for (p=hdr; hdrlen; p++, hdrlen--) {
+ if ( putc (*p, fpout) == EOF )
+ goto write_error;
+ }
+ if (!partlen)
+ partial = 0; /* end of packet */
+ for (; partlen; partlen--) {
+ c = getc (fpin);
+ if (c == EOF)
+ goto read_error;
+ if ( putc (c, fpout) == EOF )
+ goto write_error;
+ }
+ }
+ else { /* compressed: read to end */
+ pktlen = 0;
+ partial = 0;
+ hdrlen = 0;
+ if (opt_uncompress) {
+ z_stream zs;
+ byte *inbuf, *outbuf;
+ unsigned int inbufsize, outbufsize;
+ int algo, zinit_done, zrc, nread, count;
+ size_t n;
+
+ if ((c = getc (fpin)) == EOF)
+ goto read_error;
+ algo = c;
+
+ memset (&zs, 0, sizeof zs);
+ inbufsize = 2048;
+ inbuf = m_alloc (inbufsize);
+ outbufsize = 8192;
+ outbuf = m_alloc (outbufsize);
+ zs.avail_in = 0;
+ zinit_done = 0;
+
+ do {
+ if (zs.avail_in < inbufsize) {
+ n = zs.avail_in;
+ if (!n)
+ zs.next_in = (Bytef *) inbuf;
+ count = inbufsize - n;
+ for (nread=0;
+ nread < count && (c=getc (fpin)) != EOF;
+ nread++) {
+ inbuf[n+nread] = c;
+ }
+ n += nread;
+ if (nread < count && algo == 1) {
+ inbuf[n] = 0xFF; /* chew dummy byte */
+ n++;
+ }
+ zs.avail_in = n;
+ }
+ zs.next_out = (Bytef *) outbuf;
+ zs.avail_out = outbufsize;
+
+ if (!zinit_done) {
+ zrc = algo == 1? inflateInit2 ( &zs, -13)
+ : inflateInit ( &zs );
+ if (zrc != Z_OK) {
+ log_fatal ("zlib problem: %s\n", zs.msg? zs.msg :
+ zrc == Z_MEM_ERROR ? "out of core" :
+ zrc == Z_VERSION_ERROR ?
+ "invalid lib version" :
+ "unknown error" );
+ }
+ zinit_done = 1;
+ }
+ else {
+#ifdef Z_SYNC_FLUSH
+ zrc = inflate (&zs, Z_SYNC_FLUSH);
+#else
+ zrc = inflate (&zs, Z_PARTIAL_FLUSH);
+#endif
+ if (zrc == Z_STREAM_END)
+ ; /* eof */
+ else if (zrc != Z_OK && zrc != Z_BUF_ERROR) {
+ if (zs.msg)
+ log_fatal ("zlib inflate problem: %s\n", zs.msg );
+ else
+ log_fatal ("zlib inflate problem: rc=%d\n", zrc );
+ }
+ for (n=0; n < outbufsize - zs.avail_out; n++) {
+ if (putc (outbuf[n], fpout) == EOF )
+ goto write_error;
+ }
+ }
+ } while (zrc != Z_STREAM_END && zrc != Z_BUF_ERROR);
+ inflateEnd (&zs);
+ }
+ else {
+ while ( (c=getc (fpin)) != EOF ) {
+ if ( putc (c, fpout) == EOF )
+ goto write_error;
+ }
+ }
+ if (!feof (fpin))
+ goto read_error;
+ }
+
+ }
+
+ for (p=hdr; hdrlen; p++, hdrlen--) {
+ if ( putc (*p, fpout) == EOF )
+ goto write_error;
+ }
+ /* standard packet or last segment of partial length encoded packet */
+ for (; pktlen; pktlen--) {
+ c = getc (fpin);
+ if (c == EOF)
+ goto read_error;
+ if ( putc (c, fpout) == EOF )
+ goto write_error;
+ }
+
+
+ if ( fclose (fpout) )
+ log_error ("error closing `%s': %s\n", outname, strerror (errno));
+ return 0;
+
+ write_error:
+ log_error ("error writing `%s': %s\n", outname, strerror (errno));
+ fclose (fpout);
+ return 2;
+
+ read_error: {
+ int save = errno;
+ fclose (fpout);
+ errno = save;
+ }
+ return -1;
+}
+
+
+
+static int
+do_split (const char *fname, FILE *fp)
+{
+ int c, ctb, pkttype;
+ unsigned long pktlen = 0;
+ int partial = 0;
+ unsigned char header[20];
+ int header_idx = 0;
+
+ ctb = getc (fp);
+ if (ctb == EOF)
+ return 3; /* ready */
+ header[header_idx++] = ctb;
+
+ if( !(ctb & 0x80) ) {
+ log_error("invalid CTB %02x\n", ctb );
+ return 1;
+ }
+ if ( (ctb & 0x40) ) { /* new CTB */
+ pkttype = (ctb & 0x3f);
+ if( (c = getc (fp)) == EOF )
+ return -1;
+ header[header_idx++] = c;
+
+ if( c < 192 )
+ pktlen = c;
+ else if( c < 224 ) {
+ pktlen = (c - 192) * 256;
+ if( (c = getc (fp)) == EOF )
+ return -1;
+ header[header_idx++] = c;
+ pktlen += c + 192;
+ }
+ else if( c == 255 ) {
+ if (read_u32 (fp, &pktlen))
+ return -1;
+ header[header_idx++] = pktlen >> 24;
+ header[header_idx++] = pktlen >> 16;
+ header[header_idx++] = pktlen >> 8;
+ header[header_idx++] = pktlen;
+ }
+ else { /* partial body length */
+ pktlen = c;
+ partial = 1;
+ }
+ }
+ else {
+ int lenbytes;
+
+ pkttype = (ctb>>2)&0xf;
+ lenbytes = ((ctb&3)==3)? 0 : (1<<(ctb & 3));
+ if( !lenbytes ) {
+ pktlen = 0; /* don't know the value */
+ if( pkttype == PKT_COMPRESSED )
+ partial = 3;
+ else
+ partial = 2; /* the old GnuPG partial length encoding */
+ }
+ else {
+ for( ; lenbytes; lenbytes-- ) {
+ pktlen <<= 8;
+ if( (c = getc (fp)) == EOF )
+ return -1;
+ header[header_idx++] = c;
+
+ pktlen |= c;
+ }
+ }
+ }
+
+ return write_part (fname, fp, pktlen, pkttype, partial,
+ header, header_idx);
+}
+
+
+static void
+split_packets (const char *fname)
+{
+ FILE *fp;
+ int rc;
+
+ if (!fname || !strcmp (fname, "-")) {
+ fp = stdin;
+ fname = "-";
+ }
+ else if ( !(fp = fopen (fname,"rb")) ) {
+ log_error ("can't open `%s': %s\n", fname, strerror (errno));
+ return;
+ }
+
+ while ( !(rc = do_split (fname, fp)) )
+ ;
+ if ( rc > 0 )
+ ; /* error already handled */
+ else if ( ferror (fp) )
+ log_error ("error reading `%s': %s\n", fname, strerror (errno));
+ else
+ log_error ("premature EOF while reading `%s'\n", fname );
+
+ if ( fp != stdin )
+ fclose (fp);
+}
+
diff --git a/tools/lspgpot b/tools/lspgpot
index 585629b5b..8dc9c3047 100755
--- a/tools/lspgpot
+++ b/tools/lspgpot
@@ -1,6 +1,14 @@
#!/bin/sh
# lspgpot - script to extract the ownertrust values
# from PGP keyrings and list them in GnuPG ownertrust format.
+#
+# This file is free software; as a special exception the author gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
../g10/gpg --dry-run --with-fingerprint --with-colons $* | awk '
BEGIN { FS=":"
diff --git a/tools/mail-signed-keys b/tools/mail-signed-keys
index 3f9f01831..80fbb3481 100755
--- a/tools/mail-signed-keys
+++ b/tools/mail-signed-keys
@@ -1,19 +1,38 @@
#!/bin/sh
+# Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+#
+# This file is free software; as a special exception the author gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-if [ -z "$1" -o -z "$2" ]; then
- echo "usage: mail-signed-keys keyring signedby" >&2
+# FIXME: Add --dry-run, use only valid email addreses, extract only given keys
+
+dryrun=0
+if [ "$1" = "--dry-run" ]; then
+ dryrun=1
+ shift
+fi
+
+if [ -z "$1" -o -z "$2" -o -z "$3" ]; then
+ echo "usage: mail-signed-keys keyring signedby signame" >&2
exit 1
fi
+signame="$3"
+
if [ ! -f $1 ]; then
echo "mail-signed-keys: '$1': no such file" >&2
exit 1
fi
[ -f '.#tdb.tmp' ] && rm '.#tdb.tmp'
-ro="--trustdb-name=./.#tdb.tmp --dry-run --lock-never --no-default-keyring --keyring $1"
+ro="--homedir . --no-options --trustdb-name=./.#tdb.tmp --dry-run --lock-never --no-default-keyring --keyring $1"
-signedby=`gpg $ro --fast-list-mode --list-keys --with-colons $2 \
+signedby=`gpg $ro --list-keys --with-colons $2 \
2>/dev/null | awk -F: '$1=="pub" {print $5; exit 0}'`
if [ -z "$signedby" ]; then
@@ -21,14 +40,16 @@ if [ -z "$signedby" ]; then
exit 1
fi
-echo "About to send the the keys signed by $signedby" >&2
-echo -n "to their owners. Do you really want to do this? (y/N)" >&2
-read
-[ "$REPLY" != "y" -a "$REPLY" != "Y" ] && exit 0
-
+if [ "$dryrun" = "0" ]; then
+ echo "About to send the the keys signed by $signedby" >&2
+ echo -n "to their owners. Do you really want to do this? (y/N)" >&2
+ read
+ [ "$REPLY" != "y" -a "$REPLY" != "Y" ] && exit 0
+fi
gpg $ro --check-sigs --with-colons 2>/dev/null \
- | awk -F: -v signedby="$signedby" -v gpgopt="$ro" '
+ | awk -F: -v signedby="$signedby" -v gpgopt="$ro" \
+ -v dryrun="$dryrun" -v signame="$signame" '
BEGIN { sendmail="/usr/lib/sendmail -oi -t " }
$1 == "pub" { nextkid=$5; nextuid=$10
if( uidcount > 0 ) { myflush() }
@@ -42,34 +63,52 @@ function myflush()
{
if ( kid == signedby ) { uidcount=0; return }
print "sending key " substr(kid,9) " to" | "cat >&2"
- for(i=0; i < uidcount; i++ ) {
+ for(i=0; i < 1; i++ ) {
print " " uids[i] | "cat >&2"
- if( i == 0 ) {
- printf "To: %s", uids[i] | sendmail
- }
- else {
- printf ",\n %s", uids[i] | sendmail
- }
+ if( dryrun == 0 ) {
+ if( i == 0 ) {
+ printf "To: %s", uids[i] | sendmail
+ }
+ else {
+ printf ",\n %s", uids[i] | sendmail
+ }
+ }
}
- printf "\n" | sendmail
- print "Subject: I signed your key " substr(kid,9) | sendmail
- print "" | sendmail
- print "Hi," | sendmail
- print "" | sendmail
- print "Here you get back the signed key." | sendmail
- print "" | sendmail
- print "ciao," | sendmail
- print " your Key Signator" | sendmail
- print "" | sendmail
- cmd = "gpg " gpgopt " --export -a " kid " 2>/dev/null"
- while( (cmd | getline) > 0 ) {
- print | sendmail
+ if(dryrun == 0) {
+ printf "\n" | sendmail
+ print "Subject: I signed your key " substr(kid,9) | sendmail
+ print "" | sendmail
+ print "Hi," | sendmail
+ print "" | sendmail
+ print "Here you get back the signed key." | sendmail
+ print "Please send it yourself to a keyserver." | sendmail
+ print "" | sendmail
+ print "Peace," | sendmail
+ print " " signame | sendmail
+ print "" | sendmail
+ cmd = "gpg " gpgopt " --export -a " kid " 2>/dev/null"
+ while( (cmd | getline) > 0 ) {
+ print | sendmail
+ }
+ print "" | sendmail
+ close(cmd)
+ close( sendmail )
}
- print "" | sendmail
- close(cmd)
- close( sendmail )
uidcount=0
}
'
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tools/mk-tdata.c b/tools/mk-tdata.c
index 70358dc47..dcfa859f1 100644
--- a/tools/mk-tdata.c
+++ b/tools/mk-tdata.c
@@ -1,7 +1,13 @@
-/* mk-tdata.c
+/* mk-tdata.c - Create some simple random testdata
+ * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
*
- * Create some simple random testdata
+ * This file is free software; as a special exception the author gives
+ * unlimited permission to copy and/or distribute it, with or without
+ * modifications, as long as this notice is preserved.
*
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <config.h>
diff --git a/tools/mpicalc.c b/tools/mpicalc.c
index aedb27ecf..2817c9932 100644
--- a/tools/mpicalc.c
+++ b/tools/mpicalc.c
@@ -1,5 +1,5 @@
/* mpitest.c - test the mpi functions
- * Copyright (C) 1998 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
*
* This is an RPN calculator; values must be given in hex.
* Operation is like dc(1) except that the input/output radix is
@@ -28,9 +28,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
-#include <gcrypt.h>
#include "util.h"
+#include "mpi.h"
#include "i18n.h"
#define STACKSIZE 100
@@ -38,8 +38,8 @@ static MPI stack[STACKSIZE];
static int stackidx;
-static const char *
-my_strusage( int level )
+const char *
+strusage( int level )
{
const char *p;
switch( level ) {
@@ -56,7 +56,7 @@ my_strusage( int level )
"\nSyntax: mpicalc [options] [files]\n"
"MPI RPN calculator\n";
break;
- default: p = NULL;
+ default: p = default_strusage(level);
}
return p;
}
@@ -71,35 +71,11 @@ i18n_init(void)
#else
setlocale( LC_ALL, "" );
#endif
- bindtextdomain( PACKAGE, GNUPG_LOCALEDIR );
+ bindtextdomain( PACKAGE, G10_LOCALEDIR );
textdomain( PACKAGE );
#endif
}
-int
-mpi_print( FILE *fp, MPI a, int mode )
-{
- int n=0;
-
- if( !a )
- return fprintf(fp, "[MPI_NULL]");
- if( !mode ) {
- unsigned int n1;
- n1 = gcry_mpi_get_nbits(a);
- n += fprintf(fp, "[%u bits]", n1);
- }
- else {
- int rc;
- char *buffer;
-
- rc = gcry_mpi_aprint( GCRYMPI_FMT_HEX, (void **)&buffer, NULL, a );
- fputs( buffer, fp );
- n += strlen(buffer);
- gcry_free( buffer );
- }
- return n;
-}
-
static void
do_add(void)
@@ -257,7 +233,6 @@ main(int argc, char **argv)
pargs.argv = &argv;
pargs.flags = 0;
- set_strusage( my_strusage );
i18n_init();
while( arg_parse( &pargs, opts) ) {
switch( pargs.r_opt ) {
diff --git a/tools/ring-a-party b/tools/ring-a-party
index 7cf05d78d..1993e2732 100755
--- a/tools/ring-a-party
+++ b/tools/ring-a-party
@@ -1,5 +1,14 @@
#!/bin/sh
# ring-a-party - print a keyring suitable for a key signing party
+# Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+#
+# This file is free software; as a special exception the author gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
if [ $# -lt 1 ]; then
echo "usage: ring-a-party keyring [headerline]" >&2
@@ -54,20 +63,20 @@ $1 == "sub" { if( $4 != 17 && $4 != 3 ) signencrypt=1 }
function myflush()
{
# fixme: take lines to print here into account
- if( lines > 50 || lines == -1 ) {
+ if( lines > 45 || lines == -1 ) {
if( lines != -1 ) printf "\f";
page++;
printf "%s %-50.50s Page %d\n\n", now, KEYRING, page ;
- printf "Type Bits KeyID Created Expires Algorithm Use\n";
+ printf " Type Bits KeyID Created Expires Algorithm Use\n\n";
lines = 1;
}
- printf "pub %04d 0x%s %10s %10s %-10s %15s\n",
+ printf "[ ] pub %04d 0x%s %10s %10s %-10s %15s\n",
nbits, keyid, created, expires == ""? "----------":expires, algostr,
signencrypt == 1? "Sign & Encrypt":"Sign only";
length(fpr) == 40 ? printfpr20( fpr ) : printfpr16( fpr );
lnes += 2;
for( i=0; i < uidcount; i++ ) {
- printf "uid %s\n", uids[i];
+ printf "( ) uid %s\n", uids[i];
lines++;
}
printf "\n\n";
@@ -84,7 +93,7 @@ function mapalgo( no )
function printfpr16( s )
{
- printf "f16 Fingerprint16 =";
+ printf " f16 Fingerprint16 =";
for(i=0; i < 16; i++ ) {
if( i == 8 ) printf " ";
printf " %s", substr( s, i*2+1, 2 );
@@ -94,7 +103,7 @@ function printfpr16( s )
function printfpr20( s )
{
- printf "f20 Fingerprint20 =";
+ printf " f20 Fingerprint20 =";
for(i=0; i < 10; i++ ) {
if( i == 5 ) printf " ";
printf " %s", substr( s, i*4+1, 4 );
diff --git a/tools/shmtest.c b/tools/shmtest.c
index 956dec6c5..fceade1e1 100644
--- a/tools/shmtest.c
+++ b/tools/shmtest.c
@@ -1,7 +1,16 @@
/* shmtest.c
+ * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
*
+ * This file is free software; as a special exception the author gives
+ * unlimited permission to copy and/or distribute it, with or without
+ * modifications, as long as this notice is preserved.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
+
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
@@ -10,12 +19,12 @@
#include <signal.h>
#include <unistd.h>
#ifdef HAVE_SYS_IPC_H
+ #include <sys/types.h>
#include <sys/ipc.h>
#endif
#ifdef HAVE_SYS_SHM_H
#include <sys/shm.h>
#endif
-#include <gcrypt.h>
#include "util.h"
#include "ttyio.h"
#include "i18n.h"
@@ -37,6 +46,12 @@ my_usage(void)
exit(1);
}
+const char *
+strusage( int level )
+{
+ return default_strusage(level);
+}
+
static void
i18n_init(void)
{
@@ -46,7 +61,7 @@ i18n_init(void)
#else
setlocale( LC_ALL, "" );
#endif
- bindtextdomain( PACKAGE, GNUPG_LOCALEDIR );
+ bindtextdomain( PACKAGE, G10_LOCALEDIR );
textdomain( PACKAGE );
#endif
}
@@ -72,7 +87,7 @@ do_get_string( int mode, const char *keyword, byte *area, size_t areasize )
memcpy( area+n+2, p, len );
area[n] = len >> 8;
area[n+1] = len;
- gcry_free(p);
+ m_free(p);
}
else { /* bool */
area[n] = 0;
@@ -107,7 +122,7 @@ main(int argc, char **argv)
for(n=0,i=1; i < argc; i++ )
n += strlen(argv[i]) + 1;
- p = gcry_xmalloc( 100 + n );
+ p = m_alloc( 100 + n );
strcpy( p, "../g10/gpg --status-fd 1 --run-as-shm-coprocess 0");
for(i=1; i < argc; i++ ) {
strcat(p, " " );
@@ -115,7 +130,7 @@ main(int argc, char **argv)
}
fp = popen( p, "r" );
- gcry_free( p );
+ m_free( p );
if( !fp )
log_error("popen failed: %s\n", strerror(errno));