From ebd36b634450ce9fdf0104052cca2b035ad3a22d Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 2 Aug 2007 18:12:43 +0000 Subject: [PATCH] Factored common gpgconf constants out Fixed W32 compare_filenames --- THANKS | 1 + TODO | 7 ++++ agent/ChangeLog | 5 +++ agent/gpg-agent.c | 19 +--------- common/ChangeLog | 4 ++ common/Makefile.am | 1 + common/gc-opt-flags.h | 40 ++++++++++++++++++++ doc/ChangeLog | 4 ++ doc/scdaemon.texi | 5 --- g10/ChangeLog | 4 ++ g10/gpg.c | 6 +-- jnlib/ChangeLog | 8 ++++ jnlib/stringhelp.c | 85 ++++++++++++++++++++++++++++--------------- jnlib/t-stringhelp.c | 37 +++++++++++++++++++ scd/ChangeLog | 5 +++ scd/scdaemon.c | 21 ++--------- sm/ChangeLog | 4 ++ sm/gpgsm.c | 40 ++++++-------------- tools/ChangeLog | 5 +++ tools/gpgconf-comp.c | 27 +++++--------- 20 files changed, 207 insertions(+), 121 deletions(-) create mode 100644 common/gc-opt-flags.h diff --git a/THANKS b/THANKS index 7ccfe0082..e0a486dac 100644 --- a/THANKS +++ b/THANKS @@ -214,6 +214,7 @@ Sean MacLennan seanm at netwinder.org Sebastian Klemke packet at convergence.de Serge Munhoven munhoven at mema.ucl.ac.be SL Baur steve at xemacs.org +Sten Lindgren ged at solace dot miun dot se Stefan Bellon sbellon at sbellon.de Dr.Stefan.Dalibor Dr.Stefan.Dalibor at bfa.de Stefan Karrmann S.Karrmann at gmx.net diff --git a/TODO b/TODO index f45dd83e9..7b1c1cfd6 100644 --- a/TODO +++ b/TODO @@ -125,3 +125,10 @@ ** Migrate OpenPGP keys to another system +* do_add_recipient + Prints wrong error message even when decrypting. + *Decrypt* does even not work in this case. + +* Duplicate certifciates + This may happen and lead to an Ambiguous Name error. Solution is to + check the certs for identity beforethorwin this error. diff --git a/agent/ChangeLog b/agent/ChangeLog index ebac90850..05dd9a830 100644 --- a/agent/ChangeLog +++ b/agent/ChangeLog @@ -1,3 +1,8 @@ +2007-08-02 Werner Koch + + * gpg-agent.c: Include gc-opt-flags.h and remove their definition + here. + 2007-07-13 Werner Koch * genkey.c (check_passphrase_constraints): Require a confirmation diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c index 626581779..cb0a67b73 100644 --- a/agent/gpg-agent.c +++ b/agent/gpg-agent.c @@ -48,6 +48,7 @@ # include "../jnlib/w32-afunix.h" #endif #include "setenv.h" +#include "gc-opt-flags.h" enum cmd_and_opt_values @@ -698,24 +699,6 @@ main (int argc, char **argv ) char *filename_esc; /* List options and default values in the GPG Conf format. */ - - /* The following list is taken from gnupg/tools/gpgconf-comp.c. */ - /* Option flags. YOU MUST NOT CHANGE THE NUMBERS OF THE EXISTING - FLAGS, AS THEY ARE PART OF THE EXTERNAL INTERFACE. */ -#define GC_OPT_FLAG_NONE 0UL - /* The RUNTIME flag for an option indicates that the option can be - changed at runtime. */ -#define GC_OPT_FLAG_RUNTIME (1UL << 3) - /* The DEFAULT flag for an option indicates that the option has a - default value. */ -#define GC_OPT_FLAG_DEFAULT (1UL << 4) - /* The DEF_DESC flag for an option indicates that the option has a - default, which is described by the value of the default field. */ -#define GC_OPT_FLAG_DEF_DESC (1UL << 5) - /* The NO_ARG_DESC flag for an option indicates that the argument has - a default, which is described by the value of the ARGDEF field. */ -#define GC_OPT_FLAG_NO_ARG_DESC (1UL << 6) - filename = make_filename (opt.homedir, "gpg-agent.conf", NULL ); filename_esc = percent_escape (filename, NULL); diff --git a/common/ChangeLog b/common/ChangeLog index 3542d6595..d3f55066d 100644 --- a/common/ChangeLog +++ b/common/ChangeLog @@ -1,3 +1,7 @@ +2007-08-02 Werner Koch + + * gc-opt-flags.h: New. + 2007-08-01 Werner Koch * estream-printf.c (read_dummy_value): Removed as it is useless now. diff --git a/common/Makefile.am b/common/Makefile.am index 08ead7996..0ce11f188 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -33,6 +33,7 @@ common_sources = \ util.h i18n.c i18n.h \ errors.h \ openpgpdefs.h \ + gc-opt-flags.h \ keyserver.h \ sexp-parse.h \ init.c init.h \ diff --git a/common/gc-opt-flags.h b/common/gc-opt-flags.h new file mode 100644 index 000000000..261fe8796 --- /dev/null +++ b/common/gc-opt-flags.h @@ -0,0 +1,40 @@ +/* gc-opt-flags.h - gpgconf constants used by the backends. + * Copyright (C) 2004, 2007 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. + */ + +#ifndef GNUPG_GC_OPT_FLAGS_H +#define GNUPG_GC_OPT_FLAGS_H + +/* Public option flags. YOU MUST NOT CHANGE THE NUMBERS OF THE + EXISTING FLAGS, AS THEY ARE PART OF THE EXTERNAL INTERFACE. See + gnupg/tools/gpgconf-comp.c for details. */ + +#define GC_OPT_FLAG_NONE 0UL + +/* The RUNTIME flag for an option indicates that the option can be + changed at runtime. */ +#define GC_OPT_FLAG_RUNTIME (1UL << 3) + +/* The DEFAULT flag for an option indicates that the option has a + default value. */ +#define GC_OPT_FLAG_DEFAULT (1UL << 4) + +/* The DEF_DESC flag for an option indicates that the option has a + default, which is described by the value of the default field. */ +#define GC_OPT_FLAG_DEF_DESC (1UL << 5) + +/* The NO_ARG_DESC flag for an option indicates that the argument has + a default, which is described by the value of the ARGDEF field. */ +#define GC_OPT_FLAG_NO_ARG_DESC (1UL << 6) + + +#endif /*GNUPG_GC_OPT_FLAGS_H*/ diff --git a/doc/ChangeLog b/doc/ChangeLog index b74589576..a176a04c4 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2007-07-23 Werner Koch + + * scdaemon.texi (Scdaemon Commands): Remove obsolete --print-atr. + 2007-07-17 Werner Koch * gpgsm.texi (Input and Output): Document --default-key. diff --git a/doc/scdaemon.texi b/doc/scdaemon.texi index f8bab803b..25e9d4938 100644 --- a/doc/scdaemon.texi +++ b/doc/scdaemon.texi @@ -93,11 +93,6 @@ may be used to get the name of that extra socket. Run the program in the background. This option is required to prevent it from being accidently running in the background. -@item --print-atr -@opindex print-atr -This is mainly a debugging command, used to print the ATR -(Answer-To-Reset) of a card and exit immediately. - @end table diff --git a/g10/ChangeLog b/g10/ChangeLog index 68b1eb1fb..3435f2915 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,7 @@ +2007-08-02 Werner Koch + + * gpg.c: Include gc-opt-flags.h and remove their definition here. + 2007-07-17 Werner Koch * gpg.c (gpgconf_list): Declare --encrypt-to and --default-key. diff --git a/g10/gpg.c b/g10/gpg.c index a0fc17694..bda2257ee 100644 --- a/g10/gpg.c +++ b/g10/gpg.c @@ -55,7 +55,7 @@ #include "status.h" #include "keyserver-internal.h" #include "exec.h" - +#include "gc-opt-flags.h" #if defined(HAVE_DOSISH_SYSTEM) || defined(__CYGWIN__) #define MY_O_BINARY O_BINARY @@ -1457,10 +1457,6 @@ gpgconf_list (const char *configfile) { char *configfile_esc = percent_escape (configfile, NULL); - /* The following definitions are taken from gnupg/tools/gpgconf-comp.c. */ -#define GC_OPT_FLAG_NONE 0UL -#define GC_OPT_FLAG_DEFAULT (1UL << 4) - printf ("gpgconf-gpg.conf:%lu:\"%s\n", GC_OPT_FLAG_DEFAULT, configfile_esc ? configfile_esc : "/dev/null"); printf ("verbose:%lu:\n", GC_OPT_FLAG_NONE); diff --git a/jnlib/ChangeLog b/jnlib/ChangeLog index 947e7ebd6..4fec67999 100644 --- a/jnlib/ChangeLog +++ b/jnlib/ChangeLog @@ -1,3 +1,11 @@ +2007-08-02 Werner Koch + + * t-stringhelp.c (test_compare_filenames): New. + + * stringhelp.c (compare_filenames) [HAVE_DRIVE_LETTERS]: Fixed + comparison to take slash and backslash in account. + (make_filename): Avoid mixing / and \. + 2007-07-04 Werner Koch * utf8conv.c (load_libiconv): Remove URL from translatble string. diff --git a/jnlib/stringhelp.c b/jnlib/stringhelp.c index c1c1e451b..b1f6f73db 100644 --- a/jnlib/stringhelp.c +++ b/jnlib/stringhelp.c @@ -271,10 +271,10 @@ make_dirname(const char *filepath) char *p; if ( !(p=strrchr(filepath, '/')) ) - #ifdef HAVE_DRIVE_LETTERS +#ifdef HAVE_DRIVE_LETTERS if ( !(p=strrchr(filepath, '\\')) ) if ( !(p=strrchr(filepath, ':')) ) - #endif +#endif { return jnlib_xstrdup("."); } @@ -296,42 +296,67 @@ make_dirname(const char *filepath) char * make_filename( const char *first_part, ... ) { - va_list arg_ptr ; - size_t n; - const char *s; - char *name, *home, *p; + va_list arg_ptr ; + size_t n; + const char *s; + char *name, *home, *p; + + va_start (arg_ptr, first_part); + n = strlen (first_part) + 1; + while ( (s = va_arg (arg_ptr, const char *)) ) + n += strlen(s) + 1; + va_end(arg_ptr); + + home = NULL; + if ( *first_part == '~' && first_part[1] == '/' + && (home = getenv("HOME")) && *home ) + n += strlen (home); + + name = jnlib_xmalloc (n); + p = (home + ? stpcpy (stpcpy (name,home), first_part + 1) + : stpcpy(name, first_part)); - va_start( arg_ptr, first_part ) ; - n = strlen(first_part)+1; - while( (s=va_arg(arg_ptr, const char *)) ) - n += strlen(s) + 1; - va_end(arg_ptr); + va_start (arg_ptr, first_part) ; + while ( (s = va_arg(arg_ptr, const char *)) ) + p = stpcpy (stpcpy (p,"/"), s); + va_end(arg_ptr); - home = NULL; - if( *first_part == '~' && first_part[1] == '/' - && (home = getenv("HOME")) && *home ) - n += strlen(home); - - name = jnlib_xmalloc(n); - p = home ? stpcpy(stpcpy(name,home), first_part+1) - : stpcpy(name, first_part); - va_start( arg_ptr, first_part ) ; - while( (s=va_arg(arg_ptr, const char *)) ) - p = stpcpy(stpcpy(p,"/"), s); - va_end(arg_ptr); - - return name; +#ifdef HAVE_DRIVE_LETTERS + /* We better avoid mixing slashes and backslashes and prefer + backslashes. There is usual no problem with mixing them, however + a very few W32 API calls can't grok plain slashes. Printing + filenames with mixed slashes also looks a bit strange. */ + if (strchr (name, '\\')) + { + for (p=name; *p; p++) + if (*p == '/') + *p = '\\'; + } +#endif /*HAVE_DRIVE_LETTERS*/ + return name; } int -compare_filenames( const char *a, const char *b ) +compare_filenames (const char *a, const char *b) { - /* ? check whether this is an absolute filename and - * resolve symlinks? - */ + /* ? check whether this is an absolute filename and resolve + symlinks? */ #ifdef HAVE_DRIVE_LETTERS - return stricmp(a,b); + for ( ; *a && *b; a++, b++ ) + { + if (*a != *b + && (toupper (*(const unsigned char*)a) + != toupper (*(const unsigned char*)b) ) + && !((*a == '/' && *b == '\\') || (*a == '\\' && *b == '/'))) + break; + } + if ((*a == '/' && *b == '\\') || (*a == '\\' && *b == '/')) + return 0; + else + return (toupper (*(const unsigned char*)a) + - toupper (*(const unsigned char*)b)); #else return strcmp(a,b); #endif diff --git a/jnlib/t-stringhelp.c b/jnlib/t-stringhelp.c index 89ba643bf..12331d241 100644 --- a/jnlib/t-stringhelp.c +++ b/jnlib/t-stringhelp.c @@ -80,12 +80,49 @@ test_percent_escape (void) } +static void +test_compare_filenames (void) +{ + struct { + const char *a; + const char *b; + int result; + } tests[] = { + { "", "", 0 }, + { "", "a", -1 }, + { "a", "", 1 }, + { "a", "a", 0 }, + { "a", "aa", -1 }, + { "aa", "a", 1 }, + { "a", "b", -1 }, + +#ifdef HAVE_W32_SYSTEM + { "a", "A", 0 }, + { "A", "a", 0 }, + { "foo/bar", "foo\\bar", 0 }, + { "foo\\bar", "foo/bar", 0 }, + { "foo\\", "foo/", 0 }, + { "foo/", "foo\\", 0 }, +#endif /*HAVE_W32_SYSTEM*/ + { NULL, NULL, 0} + }; + int testno, result; + + for (testno=0; tests[testno].a; testno++) + { + result = compare_filenames (tests[testno].a, tests[testno].b); + result = result < 0? -1 : result > 0? 1 : 0; + if (result != tests[testno].result) + fail (testno); + } +} int main (int argc, char **argv) { test_percent_escape (); + test_compare_filenames (); return 0; } diff --git a/scd/ChangeLog b/scd/ChangeLog index 371ed35ae..5bbfc2f59 100644 --- a/scd/ChangeLog +++ b/scd/ChangeLog @@ -1,3 +1,8 @@ +2007-08-02 Werner Koch + + * scdaemon.c: Include gc-opt-flags.h and remove their definition + here. + 2007-08-01 Werner Koch * apdu.c (send_le): Implement exact length hack. Suggested by diff --git a/scd/scdaemon.c b/scd/scdaemon.c index ea42f7cfa..34f6e70d2 100644 --- a/scd/scdaemon.c +++ b/scd/scdaemon.c @@ -1,5 +1,6 @@ /* scdaemon.c - The GnuPG Smartcard Daemon - * Copyright (C) 2001, 2002, 2004, 2005, 2007 Free Software Foundation, Inc. + * Copyright (C) 2001, 2002, 2004, 2005, + * 2007 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -51,6 +52,8 @@ #endif #include "ccid-driver.h" #include "mkdtemp.h" +#include "gc-opt-flags.h" + enum cmd_and_opt_values { aNull = 0, @@ -545,22 +548,6 @@ main (int argc, char **argv ) char *filename = NULL; char *filename_esc; - /* The following list is taken from gnupg/tools/gpgconf-comp.c. */ - /* Option flags. YOU MUST NOT CHANGE THE NUMBERS OF THE EXISTING - FLAGS, AS THEY ARE PART OF THE EXTERNAL INTERFACE. */ -#define GC_OPT_FLAG_NONE 0UL - /* The RUNTIME flag for an option indicates that the option can be - changed at runtime. */ -#define GC_OPT_FLAG_RUNTIME (1UL << 3) - /* The DEFAULT flag for an option indicates that the option has a - default value. */ -#define GC_OPT_FLAG_DEFAULT (1UL << 4) - /* The DEF_DESC flag for an option indicates that the option has a - default, which is described by the value of the default field. */ -#define GC_OPT_FLAG_DEF_DESC (1UL << 5) - /* The NO_ARG_DESC flag for an option indicates that the argument has - a default, which is described by the value of the ARGDEF field. */ -#define GC_OPT_FLAG_NO_ARG_DESC (1UL << 6) if (!config_filename) filename = make_filename (opt.homedir, "scdaemon.conf", NULL ); filename_esc = percent_escape (filename, NULL); diff --git a/sm/ChangeLog b/sm/ChangeLog index 7b64d47f7..910056a74 100644 --- a/sm/ChangeLog +++ b/sm/ChangeLog @@ -1,3 +1,7 @@ +2007-08-02 Werner Koch + + * gpgsm.c (main): Factored GC_OPT_FLAGS out to gc-opt-flags.h. + 2007-07-17 Werner Koch * gpgsm.c (main): Implement --default-key. diff --git a/sm/gpgsm.c b/sm/gpgsm.c index c00c01c9d..3a1c6d811 100644 --- a/sm/gpgsm.c +++ b/sm/gpgsm.c @@ -36,6 +36,7 @@ #include "i18n.h" #include "keydb.h" #include "sysutils.h" +#include "gc-opt-flags.h" #ifndef O_BINARY @@ -1292,17 +1293,18 @@ main ( int argc, char **argv) gpgsm_exit(2); /* Set the random seed file. */ - if (use_random_seed) { - char *p = make_filename (opt.homedir, "random_seed", NULL); - gcry_control (GCRYCTL_SET_RANDOM_SEED_FILE, p); - xfree(p); - } - - + if (use_random_seed) + { + char *p = make_filename (opt.homedir, "random_seed", NULL); + gcry_control (GCRYCTL_SET_RANDOM_SEED_FILE, p); + xfree(p); + } + if (!cmd && opt.fingerprint && !with_fpr) set_cmd (&cmd, aListKeys); - if (!nrings && default_keyring) /* Add default keybox. */ + /* Add default keybox. */ + if (!nrings && default_keyring) { int created; @@ -1353,7 +1355,7 @@ main ( int argc, char **argv) } /* Build the recipient list. We first add the regular ones and then - the encrypt-to ones because the underlying function will silenty + the encrypt-to ones because the underlying function will silently ignore duplicates and we can't allow to keep a duplicate which is flagged as encrypt-to as the actually encrypt function would then complain about no (regular) recipients. */ @@ -1369,7 +1371,7 @@ main ( int argc, char **argv) } if (log_get_errorcount(0)) - gpgsm_exit(1); /* must stop for invalid recipients */ + gpgsm_exit(1); /* Must stop for invalid recipients. */ fname = argc? *argv : NULL; @@ -1377,24 +1379,6 @@ main ( int argc, char **argv) { case aGPGConfList: { /* List options and default values in the GPG Conf format. */ - - /* The following list is taken from gnupg/tools/gpgconf-comp.c. */ - /* Option flags. YOU MUST NOT CHANGE THE NUMBERS OF THE EXISTING - FLAGS, AS THEY ARE PART OF THE EXTERNAL INTERFACE. */ -#define GC_OPT_FLAG_NONE 0UL - /* The RUNTIME flag for an option indicates that the option can be - changed at runtime. */ -#define GC_OPT_FLAG_RUNTIME (1UL << 3) - /* The DEFAULT flag for an option indicates that the option has a - default value. */ -#define GC_OPT_FLAG_DEFAULT (1UL << 4) - /* The DEF_DESC flag for an option indicates that the option has a - default, which is described by the value of the default field. */ -#define GC_OPT_FLAG_DEF_DESC (1UL << 5) - /* The NO_ARG_DESC flag for an option indicates that the argument has - a default, which is described by the value of the ARGDEF field. */ -#define GC_OPT_FLAG_NO_ARG_DESC (1UL << 6) - char *config_filename_esc = percent_escape (opt.config_filename, NULL); printf ("gpgconf-gpgsm.conf:%lu:\"%s\n", diff --git a/tools/ChangeLog b/tools/ChangeLog index c5acee5da..82fe5c74d 100644 --- a/tools/ChangeLog +++ b/tools/ChangeLog @@ -1,3 +1,8 @@ +2007-08-02 Werner Koch + + * gpgconf-comp.c: Factor the public GC_OPT_FLAG constants out and + include gc-opt-flags.h. + 2007-07-17 Werner Koch * gpgconf-comp.c: Add --encrypt-to and --default-key to gpg and diff --git a/tools/gpgconf-comp.c b/tools/gpgconf-comp.c index ae2902b94..096aa4dfb 100644 --- a/tools/gpgconf-comp.c +++ b/tools/gpgconf-comp.c @@ -44,6 +44,7 @@ #include "util.h" #include "i18n.h" +#include "gc-opt-flags.h" #include "gpgconf.h" @@ -308,9 +309,12 @@ static struct }; -/* Option flags. YOU MUST NOT CHANGE THE NUMBERS OF THE EXISTING - FLAGS, AS THEY ARE PART OF THE EXTERNAL INTERFACE. */ -#define GC_OPT_FLAG_NONE 0UL +/* Option flags. The flags which are used by the backends are defined + by gc-opt-flags.h, included above. + + YOU MUST NOT CHANGE THE NUMBERS OF THE EXISTING FLAGS, AS THEY ARE + PART OF THE EXTERNAL INTERFACE. */ + /* Some entries in the option list are not options, but mark the beginning of a new group of options. These entries have the GROUP flag set. */ @@ -322,26 +326,13 @@ static struct several times. A comma separated list of arguments is used as the argument value. */ #define GC_OPT_FLAG_LIST (1UL << 2) -/* The RUNTIME flag for an option indicates that the option can be - changed at runtime. */ -#define GC_OPT_FLAG_RUNTIME (1UL << 3) - -/* The following flags are incorporated from the backend. */ -/* The DEFAULT flag for an option indicates that the option has a - default value. */ -#define GC_OPT_FLAG_DEFAULT (1UL << 4) -/* The DEF_DESC flag for an option indicates that the option has a - default, which is described by the value of the default field. */ -#define GC_OPT_FLAG_DEF_DESC (1UL << 5) -/* The NO_ARG_DESC flag for an option indicates that the argument has - a default, which is described by the value of the ARGDEF field. */ -#define GC_OPT_FLAG_NO_ARG_DESC (1UL << 6) /* The NO_CHANGE flag for an option indicates that the user should not be allowed to chnage this option using the standard gpgconf method. - Frontends using gpgconf should grey out such otions, so that only + Frontends using gpgconf should grey out such options, so that only the current value is displayed. */ #define GC_OPT_FLAG_NO_CHANGE (1UL <<7) + /* A human-readable description for each flag. */ static struct {