1
/* gpg.c - The GnuPG utility (main for gpg)
2
* Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
4
* This file is part of GnuPG.
6
* GnuPG is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* GnuPG is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
40
#include "gnupg-defs.h"
44
enum cmd_and_opt_values { aNull = 0,
151
oUseEmbeddedFilename,
173
oAllowNonSelfsignedUID,
184
static ARGPARSE_OPTS opts[] = {
186
{ 300, NULL, 0, N_("@Commands:\n ") },
188
{ aFindByFpr, "find-by-fpr", 0, "|FPR| find key using it's fingerprnt" },
189
{ aFindByKid, "find-by-kid", 0, "|KID| find key using it's keyid" },
190
{ aFindByUid, "find-by-uid", 0, "|NAME| find key by user name" },
192
{ 301, NULL, 0, N_("@\nOptions:\n ") },
194
{ oArmor, "armor", 0, N_("create ascii armored output")},
195
{ oArmor, "armour", 0, "@" },
196
{ oCompress, NULL, 1, N_("|N|set compress level N (0 disables)") },
197
{ oOutput, "output", 2, N_("use as output file")},
198
{ oVerbose, "verbose", 0, N_("verbose") },
199
{ oQuiet, "quiet", 0, N_("be somewhat more quiet") },
200
{ oDryRun, "dry-run", 0, N_("do not make any changes") },
201
{ oOptions, "options" , 2, N_("read options from file")},
203
{ oDebug, "debug" ,4|16, N_("set debugging flags")},
204
{ oDebugAll, "debug-all" ,0, N_("enable full debugging")},
211
int gpg_errors_seen = 0;
215
my_strusage( int level )
219
case 11: p = "kbxutil (GnuPG)";
221
case 13: p = VERSION; break;
222
case 17: p = PRINTABLE_OS_NAME; break;
224
_("Please report bugs to <gnupg-bugs@gnu.org>.\n");
228
_("Usage: kbxutil [options] [files] (-h for help)");
231
_("Syntax: kbxutil [options] [files]\n"
232
"list, export, import KBX data\n");
245
#ifdef USE_SIMPLE_GETTEXT
246
set_gettext_file( PACKAGE );
249
#ifdef HAVE_LC_MESSAGES
250
setlocale( LC_TIME, "" );
251
setlocale( LC_MESSAGES, "" );
253
setlocale( LC_ALL, "" );
255
bindtextdomain( PACKAGE, GNUPG_LOCALEDIR );
256
textdomain( PACKAGE );
263
wrong_args( const char *text )
265
log_error("usage: kbxutil %s\n", text);
271
hextobyte( const byte *s )
275
if( *s >= '0' && *s <= '9' )
277
else if( *s >= 'A' && *s <= 'F' )
278
c = 16 * (10 + *s - 'A');
279
else if( *s >= 'a' && *s <= 'f' )
280
c = 16 * (10 + *s - 'a');
284
if( *s >= '0' && *s <= '9' )
286
else if( *s >= 'A' && *s <= 'F' )
288
else if( *s >= 'a' && *s <= 'f' )
296
format_fingerprint ( const char *s )
301
for (i=0; i < 20 && *s; ) {
302
if ( *s == ' ' || *s == '\t' ) {
313
return gcry_xstrdup ( fpr );
317
format_keyid ( const char *s, u32 *kid )
320
switch ( strlen ( s ) ) {
323
kid[1] = strtoul( s, NULL, 16 );
327
mem2str( helpbuf, s, 9 );
328
kid[0] = strtoul( helpbuf, NULL, 16 );
329
kid[1] = strtoul( s+8, NULL, 16 );
332
return 0; /* error */
338
main( int argc, char **argv )
341
enum cmd_and_opt_values cmd = 0;
343
set_strusage( my_strusage );
344
log_set_name("kbxutil");
345
/* check that the libraries are suitable. Do it here because
346
* the option parse may need services of the library */
347
if ( !gcry_check_version ( "1.1.0a" ) ) {
348
log_fatal(_("libgcrypt is too old (need %s, have %s)\n"),
349
VERSION, gcry_check_version(NULL) );
352
create_dotlock(NULL); /* register locking cleanup */
358
pargs.flags= 1; /* do not remove the args */
359
while( arg_parse( &pargs, opts) ) {
360
switch( pargs.r_opt ) {
363
gcry_control( GCRYCTL_SET_VERBOSITY, (int)opt.verbose );
365
case oDebug: opt.debug |= pargs.r.ret_ulong; break;
366
case oDebugAll: opt.debug = ~0; break;
374
default : pargs.err = 2; break;
377
if( log_get_errorcount(0) )
380
if ( !cmd ) { /* default is to list a KBX file */
382
print_kbxfile( NULL );
385
for ( ; argc; argc--, argv++ ) {
386
print_kbxfile( *argv );
390
else if ( cmd == aFindByFpr ) {
393
wrong_args ("kbxfile foingerprint");
394
fpr = format_fingerprint ( argv[1] );
396
log_error ("invalid formatted fingerprint\n");
398
kbxfile_search_by_fpr ( argv[0], fpr );
402
else if ( cmd == aFindByKid ) {
407
wrong_args ("kbxfile short-or-long-keyid");
408
mode = format_keyid ( argv[1], kid );
410
log_error ("invalid formatted keyID\n");
412
kbxfile_search_by_kid ( argv[0], kid, mode );
415
else if ( cmd == aFindByUid ) {
417
wrong_args ("kbxfile userID");
418
kbxfile_search_by_uid ( argv[0], argv[1] );
421
log_error ("unsupported action\n");
424
return 8; /*NEVER REACHED*/
431
if( opt.debug & DBG_MEMSTAT_VALUE ) {
432
gcry_control( GCRYCTL_DUMP_MEMORY_STATS );
433
gcry_control( GCRYCTL_DUMP_RANDOM_STATS );
436
gcry_control( GCRYCTL_DUMP_SECMEM_STATS );
437
rc = rc? rc : log_get_errorcount(0)? 2 :
438
gpg_errors_seen? 1 : 0;