From 0e8f6e2aa98c212442001036fb5178cd6cd8af59 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 20 Feb 2020 10:03:11 +0100 Subject: [PATCH] gpg: Use gpgrt's new option parser to provide a global conf file. * common/util.h: Remove argparse.h. * common/argparse.c: Undef GPGRT_ENABLE_ARGPARSE_MACROS. * configure.ac (GPGRT_ENABLE_ARGPARSE_MACROS): Define. * agent/gpg-agent.c: Undef GPGRT_ENABLE_ARGPARSE_MACROS and include argparse.h. Do this also for all main modules which use our option parser except for gpg. Replace calls to strusage by calls to gpgrt_strusage everywhere. * g10/gpg.c (opts): Change type to gpgrt_opt_t. Flag oOptions and oNoOptions with ARGPARSE_conffile and ARGPARSE_no_conffile. (main): Change type of pargs to gpgrt_argparse_t. Rework the option parser to make use of the new gpgrt_argparser. -- This is not yet finished but a make check works. gpg has the most complex and oldest option handling and thus this is the first migration target. SE-Linux checks and version-ed config files are missing and will be added later. GnuPG-bug-id: 4788 Signed-off-by: Werner Koch --- agent/gpg-agent.c | 4 + agent/preset-passphrase.c | 4 + agent/protect-tool.c | 4 + common/argparse.c | 3 + common/util.h | 1 - configure.ac | 5 +- dirmngr/dirmngr-client.c | 4 + dirmngr/dirmngr.c | 4 + dirmngr/dirmngr_ldap.c | 4 + g10/call-agent.c | 2 +- g10/call-dirmngr.c | 2 +- g10/call-keyboxd.c | 2 +- g10/gpg.c | 321 ++++++++++++++++++++------------------ g10/gpgv.c | 6 +- g13/g13-syshelp.c | 4 + g13/g13.c | 4 + kbx/kbxutil.c | 4 + scd/scdaemon.c | 4 + sm/call-agent.c | 2 +- sm/call-dirmngr.c | 2 +- sm/gpgsm.c | 4 + tests/gpgscm/main.c | 4 + tools/card-call-scd.c | 2 +- tools/gpg-card.c | 4 + tools/gpg-check-pattern.c | 5 +- tools/gpg-connect-agent.c | 4 + tools/gpg-pair-tool.c | 5 +- tools/gpg-wks-client.c | 4 + tools/gpg-wks-server.c | 4 + tools/gpgconf.c | 4 + tools/gpgsplit.c | 4 + tools/gpgtar.c | 4 + 32 files changed, 268 insertions(+), 166 deletions(-) diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c index 4678cf359..d5fe939db 100644 --- a/agent/gpg-agent.c +++ b/agent/gpg-agent.c @@ -19,6 +19,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include @@ -52,6 +55,7 @@ #define GNUPG_COMMON_NEED_AFLOCAL #include "agent.h" #include /* Malloc hooks and socket wrappers. */ +#include "../common/argparse.h" /* temporary hack. */ #include "../common/i18n.h" #include "../common/sysutils.h" diff --git a/agent/preset-passphrase.c b/agent/preset-passphrase.c index 7b322a0b7..496cee73d 100644 --- a/agent/preset-passphrase.c +++ b/agent/preset-passphrase.c @@ -18,6 +18,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include @@ -49,6 +52,7 @@ #include "../common/i18n.h" #include "../common/sysutils.h" #include "../common/init.h" +#include "../common/argparse.h" /* temporary hack. */ enum cmd_and_opt_values diff --git a/agent/protect-tool.c b/agent/protect-tool.c index 4a307abc2..798c50e78 100644 --- a/agent/protect-tool.c +++ b/agent/protect-tool.c @@ -18,6 +18,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include @@ -43,6 +46,7 @@ #include "../common/get-passphrase.h" #include "../common/sysutils.h" #include "../common/init.h" +#include "../common/argparse.h" /* temporary hack. */ enum cmd_and_opt_values diff --git a/common/argparse.c b/common/argparse.c index c2ba52e3f..b30499bcc 100644 --- a/common/argparse.c +++ b/common/argparse.c @@ -28,6 +28,9 @@ #ifdef HAVE_CONFIG_H #include #endif +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include diff --git a/common/util.h b/common/util.h index 756f32c03..e1d9fa6fd 100644 --- a/common/util.h +++ b/common/util.h @@ -62,7 +62,6 @@ /* Get all the stuff from jnlib. */ #include "../common/logging.h" -#include "../common/argparse.h" #include "../common/stringhelp.h" #include "../common/mischelp.h" #include "../common/strlist.h" diff --git a/configure.ac b/configure.ac index 5fcbcd7e4..0815927ae 100644 --- a/configure.ac +++ b/configure.ac @@ -522,7 +522,7 @@ AH_BOTTOM([ #define GNUPG_CACHE_DIR "cache.d" #define GNUPG_DEF_COPYRIGHT_LINE \ - "Copyright (C) 2018 Free Software Foundation, Inc." + "Copyright (C) 2020 Free Software Foundation, Inc." /* For some systems (DOS currently), we hardcode the path here. For POSIX systems the values are constructed by the Makefiles, so that @@ -580,6 +580,9 @@ AH_BOTTOM([ /* Enable the log_ macros from gpgrt. */ #define GPGRT_ENABLE_LOG_MACROS 1 +/* We want the argparse macros from gpgrt. */ +#define GPGRT_ENABLE_ARGPARSE_MACROS 1 + /* Tell libgcrypt not to use its own libgpg-error implementation. */ #define USE_LIBGPG_ERROR 1 diff --git a/dirmngr/dirmngr-client.c b/dirmngr/dirmngr-client.c index 53b405ea2..e0bc80fcf 100644 --- a/dirmngr/dirmngr-client.c +++ b/dirmngr/dirmngr-client.c @@ -19,6 +19,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include @@ -41,6 +44,7 @@ #include "../common/i18n.h" #include "../common/util.h" #include "../common/init.h" +#include "../common/argparse.h" /* temporary hack. */ /* Constants for the options. */ diff --git a/dirmngr/dirmngr.c b/dirmngr/dirmngr.c index 9b80a20ba..9838b1c7b 100644 --- a/dirmngr/dirmngr.c +++ b/dirmngr/dirmngr.c @@ -22,6 +22,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include @@ -76,6 +79,7 @@ #include "../common/gc-opt-flags.h" #include "dns-stuff.h" #include "http-common.h" +#include "../common/argparse.h" /* temporary hack. */ #ifndef ENAMETOOLONG # define ENAMETOOLONG EINVAL diff --git a/dirmngr/dirmngr_ldap.c b/dirmngr/dirmngr_ldap.c index 82d4a6ebc..a96722619 100644 --- a/dirmngr/dirmngr_ldap.c +++ b/dirmngr/dirmngr_ldap.c @@ -19,6 +19,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include @@ -55,6 +58,7 @@ #include "../common/i18n.h" #include "../common/util.h" #include "../common/init.h" +#include "../common/argparse.h" /* temporary hack. */ /* There is no need for the npth_unprotect and leave functions here; * thus we redefine them to nops. We keep them in the code just for diff --git a/g10/call-agent.c b/g10/call-agent.c index e638b83eb..98d965cbe 100644 --- a/g10/call-agent.c +++ b/g10/call-agent.c @@ -222,7 +222,7 @@ warn_version_mismatch (assuan_context_t ctx, const char *servername, int mode) { gpg_error_t err; char *serverversion; - const char *myversion = strusage (13); + const char *myversion = gpgrt_strusage (13); err = get_assuan_server_version (ctx, mode, &serverversion); if (err) diff --git a/g10/call-dirmngr.c b/g10/call-dirmngr.c index 4180589fa..02d1edb9f 100644 --- a/g10/call-dirmngr.c +++ b/g10/call-dirmngr.c @@ -146,7 +146,7 @@ warn_version_mismatch (assuan_context_t ctx, const char *servername) { gpg_error_t err; char *serverversion; - const char *myversion = strusage (13); + const char *myversion = gpgrt_strusage (13); err = get_assuan_server_version (ctx, 0, &serverversion); if (err) diff --git a/g10/call-keyboxd.c b/g10/call-keyboxd.c index d7d9e2da4..181f33fed 100644 --- a/g10/call-keyboxd.c +++ b/g10/call-keyboxd.c @@ -144,7 +144,7 @@ warn_version_mismatch (assuan_context_t ctx, const char *servername) { gpg_error_t err; char *serverversion; - const char *myversion = strusage (13); + const char *myversion = gpgrt_strusage (13); err = get_assuan_server_version (ctx, 0, &serverversion); if (err) diff --git a/g10/gpg.c b/g10/gpg.c index 89e29fea2..0c0e3a2d6 100644 --- a/g10/gpg.c +++ b/g10/gpg.c @@ -1,7 +1,7 @@ -/* gpg.c - The GnuPG utility (main for gpg) - * Copyright (C) 1998-2011 Free Software Foundation, Inc. - * Copyright (C) 1997-2017 Werner Koch - * Copyright (C) 2015-2017 g10 Code GmbH +/* gpg.c - The GnuPG OpenPGP tool + * Copyright (C) 1998-2020 Free Software Foundation, Inc. + * Copyright (C) 1997-2019 Werner Koch + * Copyright (C) 2015-2020 g10 Code GmbH * * This file is part of GnuPG. * @@ -17,6 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, see . + * SPDX-License-Identifier: GPL-3.0-or-later */ #include @@ -437,7 +438,7 @@ enum cmd_and_opt_values }; -static ARGPARSE_OPTS opts[] = { +static gpgrt_opt_t opts[] = { ARGPARSE_group (300, N_("@Commands:\n ")), @@ -638,7 +639,7 @@ static ARGPARSE_OPTS opts[] = { ARGPARSE_s_s (oDisplayCharset, "display-charset", "@"), ARGPARSE_s_s (oDisplayCharset, "charset", "@"), - ARGPARSE_s_s (oOptions, "options", "@"), + ARGPARSE_conffile (oOptions, "options", "@"), ARGPARSE_s_s (oDebug, "debug", "@"), ARGPARSE_s_s (oDebugLevel, "debug-level", "@"), @@ -744,7 +745,7 @@ static ARGPARSE_OPTS opts[] = { ARGPARSE_s_n (oNoDefKeyring, "no-default-keyring", "@"), ARGPARSE_s_n (oNoKeyring, "no-keyring", "@"), ARGPARSE_s_n (oNoGreeting, "no-greeting", "@"), - ARGPARSE_s_n (oNoOptions, "no-options", "@"), + ARGPARSE_noconffile (oNoOptions, "no-options", "@"), ARGPARSE_s_s (oHomedir, "homedir", "@"), ARGPARSE_s_n (oNoBatch, "no-batch", "@"), ARGPARSE_s_n (oWithColons, "with-colons", "@"), @@ -1082,10 +1083,13 @@ my_strusage( int level ) static char *digests, *pubkeys, *ciphers, *zips, *aeads, *ver_gcry; const char *p; - switch( level ) { + switch( level ) { + case 9: p = "GPL-3.0-or-later"; break; case 11: p = "@GPG@ (@GNUPG@)"; break; case 13: p = VERSION; break; + case 14: p = GNUPG_DEF_COPYRIGHT_LINE; break; + case 17: p = PRINTABLE_OS_NAME; break; case 19: p = _("Please report bugs to <@EMAIL@>.\n"); break; @@ -2325,10 +2329,11 @@ get_default_configname (void) return configname; } + int main (int argc, char **argv) { - ARGPARSE_ARGS pargs; + gpgrt_argparse_t pargs; IOBUF a; int rc=0; int orig_argc; @@ -2342,13 +2347,11 @@ main (int argc, char **argv) strlist_t nrings = NULL; armor_filter_context_t *afx = NULL; int detached_sig = 0; - FILE *configfp = NULL; - char *configname = NULL; - char *save_configname = NULL; - char *default_configname = NULL; - unsigned configlineno; - int parse_debug = 0; - int default_config = 1; + char *last_configname = NULL; + const char *configname = NULL; /* NULL or points to last_configname. + * NULL also indicates that we are + * processing options from the cmdline. */ + int debug_argparser = 0; int default_keyring = 1; int greeting = 0; int nogreeting = 0; @@ -2398,7 +2401,7 @@ main (int argc, char **argv) gnupg_reopen_std (GPG_NAME); trap_unaligned (); gnupg_rl_initialize (); - set_strusage (my_strusage); + gpgrt_set_strusage (my_strusage); gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN); log_set_prefix (GPG_NAME, GPGRT_LOG_WITH_PREFIX); @@ -2477,43 +2480,47 @@ main (int argc, char **argv) opt.compliance = CO_GNUPG; opt.flags.rfc4880bis = 1; - /* Check whether we have a config file on the command line. */ + /* Check special options given on the command line. */ orig_argc = argc; orig_argv = argv; pargs.argc = &argc; pargs.argv = &argv; pargs.flags= (ARGPARSE_FLAG_KEEP | ARGPARSE_FLAG_NOVERSION); - while( arg_parse( &pargs, opts) ) { - if( pargs.r_opt == oDebug || pargs.r_opt == oDebugAll ) - parse_debug++; - else if (pargs.r_opt == oDebugIOLBF) - es_setvbuf (es_stdout, NULL, _IOLBF, 0); - else if( pargs.r_opt == oOptions ) { - /* yes there is one, so we do not try the default one, but - * read the option file when it is encountered at the commandline - */ - default_config = 0; - } - else if( pargs.r_opt == oNoOptions ) + while (gpgrt_argparse (NULL, &pargs, opts)) + { + switch (pargs.r_opt) { - default_config = 0; /* --no-options */ + case oDebug: + case oDebugAll: + debug_argparser++; + break; + + case oDebugIOLBF: + es_setvbuf (es_stdout, NULL, _IOLBF, 0); + break; + + case oNoOptions: + /* Set here here because the homedir would otherwise be + * created before main option parsing starts. */ opt.no_homedir_creation = 1; + break; + + case oHomedir: + gnupg_set_homedir (pargs.r.ret_str); + break; + + case oNoPermissionWarn: + opt.no_perm_warn = 1; + break; } - else if( pargs.r_opt == oHomedir ) - gnupg_set_homedir (pargs.r.ret_str); - else if( pargs.r_opt == oNoPermissionWarn ) - opt.no_perm_warn=1; - else if (pargs.r_opt == oStrict ) - { - /* Not used */ - } - else if (pargs.r_opt == oNoStrict ) - { - /* Not used */ - } - } + } + /* Reset the flags. */ + pargs.flags &= ~(ARGPARSE_FLAG_KEEP | ARGPARSE_FLAG_NOVERSION); #ifdef HAVE_DOSISH_SYSTEM + /* FIXME: Do we still need this? No: gnupg_homedir calls + * make_filename which changes the slashed anyway. IsDBCSLeadByte still + * needed? See bug #561. */ if ( strchr (gnupg_homedir (), '\\') ) { char *d, *buf = xmalloc (strlen (gnupg_homedir ())+1); const char *s; @@ -2555,64 +2562,89 @@ main (int argc, char **argv) additional_weak_digest ("MD5"); parse_auto_key_locate (DEFAULT_AKL_LIST); - /* Try for a version specific config file first */ - default_configname = get_default_configname (); - if (default_config) - configname = xstrdup (default_configname); - argc = orig_argc; argv = orig_argv; pargs.argc = &argc; pargs.argv = &argv; - pargs.flags= ARGPARSE_FLAG_KEEP; + /* We are re-using the struct, thus the reset flag. We OR the + * flags so that the internal intialized flag won't be cleared. */ + pargs.flags |= (ARGPARSE_FLAG_RESET + | ARGPARSE_FLAG_KEEP + | ARGPARSE_FLAG_SYS + | ARGPARSE_FLAG_USER); + /* FIXME: Add an option to allow for version specific config files. */ /* By this point we have a homedir, and cannot change it. */ check_permissions (gnupg_homedir (), 0); - next_pass: - if( configname ) { - if(check_permissions(configname,1)) - { - /* If any options file is unsafe, then disable any external - programs for keyserver calls or photo IDs. Since the - external program to call is set in the options file, a - unsafe options file can lead to an arbitrary program - being run. */ + /* The configuraton directories for use by gpgrt_argparser. */ + gpgrt_set_confdir (GPGRT_CONFDIR_SYS, gnupg_sysconfdir ()); + gpgrt_set_confdir (GPGRT_CONFDIR_USER, gnupg_homedir ()); - opt.exec_disable=1; - } - configlineno = 0; - configfp = fopen( configname, "r" ); - if (configfp && is_secured_file (fileno (configfp))) - { - fclose (configfp); - configfp = NULL; - gpg_err_set_errno (EPERM); - } - if( !configfp ) { - if( default_config ) { - if( parse_debug ) - log_info(_("Note: no default option file '%s'\n"), - configname ); - } - else { - log_error(_("option file '%s': %s\n"), - configname, strerror(errno) ); - g10_exit(2); - } - xfree(configname); configname = NULL; - } - if( parse_debug && configname ) - log_info(_("reading options from '%s'\n"), configname ); - default_config = 0; - } + /* if( configname ) { */ + /* FIXME: Add callback to check config file permissions. */ + /* if(check_permissions(configname,1)) */ + /* { */ + /* /\* If any options file is unsafe, then disable any external */ + /* programs for keyserver calls or photo IDs. Since the */ + /* external program to call is set in the options file, a */ + /* unsafe options file can lead to an arbitrary program */ + /* being run. *\/ */ - while( optfile_parse( configfp, configname, &configlineno, - &pargs, opts) ) + /* opt.exec_disable=1; */ + /* } */ + + /* configlineno = 0; */ + /* configfp = fopen( configname, "r" ); */ + /* if (configfp && is_secured_file (fileno (configfp))) */ + /* { */ + /* fclose (configfp); */ + /* configfp = NULL; */ + /* gpg_err_set_errno (EPERM); */ + /* } */ + /* if( !configfp ) { */ + /* if( default_config ) { */ + /* if( parse_debug ) */ + /* log_info(_("Note: no default option file '%s'\n"), */ + /* configname ); */ + /* } */ + /* else { */ + /* log_error(_("option file '%s': %s\n"), */ + /* configname, strerror(errno) ); */ + /* g10_exit(2); */ + /* } */ + /* xfree(configname); configname = NULL; */ + /* } */ + /* if( parse_debug && configname ) */ + /* log_info(_("reading options from '%s'\n"), configname ); */ + /* default_config = 0; */ + /* } */ + + while (gpgrt_argparser (&pargs, opts, GPG_NAME EXTSEP_S "conf" )) { - switch( pargs.r_opt ) + switch (pargs.r_opt) { + case ARGPARSE_CONFFILE: + if (debug_argparser) + log_info (_("reading options from '%s'\n"), + pargs.r_type? pargs.r.ret_str: "[cmdline]"); + if (pargs.r_type) + { + xfree (last_configname); + last_configname = xstrdup (pargs.r.ret_str); + configname = last_configname; + } + else + configname = NULL; + break; + + /* case oOptions: */ + /* case oNoOptions: */ + /* We will never see these options here because + * gpgrt_argparse handles them for us. */ + /* break */ + case aListConfig: case aListGcryptConfig: case aGPGConfList: @@ -2752,10 +2784,10 @@ main (int argc, char **argv) break; case oNoUseAgent: - obsolete_option (configname, configlineno, "no-use-agent"); + obsolete_option (configname, pargs.lineno, "no-use-agent"); break; case oGpgAgentInfo: - obsolete_option (configname, configlineno, "gpg-agent-info"); + obsolete_option (configname, pargs.lineno, "gpg-agent-info"); break; case oUseKeyboxd: @@ -2763,19 +2795,19 @@ main (int argc, char **argv) break; case oReaderPort: - obsolete_scdaemon_option (configname, configlineno, "reader-port"); + obsolete_scdaemon_option (configname, pargs.lineno, "reader-port"); break; case octapiDriver: - obsolete_scdaemon_option (configname, configlineno, "ctapi-driver"); + obsolete_scdaemon_option (configname, pargs.lineno, "ctapi-driver"); break; case opcscDriver: - obsolete_scdaemon_option (configname, configlineno, "pcsc-driver"); + obsolete_scdaemon_option (configname, pargs.lineno, "pcsc-driver"); break; case oDisableCCID: - obsolete_scdaemon_option (configname, configlineno, "disable-ccid"); + obsolete_scdaemon_option (configname, pargs.lineno, "disable-ccid"); break; case oHonorHttpProxy: - obsolete_option (configname, configlineno, "honor-http-proxy"); + obsolete_option (configname, pargs.lineno, "honor-http-proxy"); break; case oAnswerYes: opt.answer_yes = 1; break; @@ -2786,7 +2818,7 @@ main (int argc, char **argv) sl->flags = KEYDB_RESOURCE_FLAG_PRIMARY; break; case oShowKeyring: - deprecated_warning(configname,configlineno,"--show-keyring", + deprecated_warning(configname,pargs.lineno,"--show-keyring", "--list-options ","show-keyring"); opt.list_options|=LIST_SHOW_KEYRING; break; @@ -2871,14 +2903,6 @@ main (int argc, char **argv) /* Ignore this old option. */ break; - case oOptions: - /* config files may not be nested (silently ignore them) */ - if( !configfp ) { - xfree(configname); - configname = xstrdup(pargs.r.ret_str); - goto next_pass; - } - break; case oNoArmor: opt.no_armor=1; opt.armor=0; break; case oNoDefKeyring: @@ -2911,7 +2935,7 @@ main (int argc, char **argv) case oDefaultKey: sl = add_to_strlist (&opt.def_secret_key, pargs.r.ret_str); sl->flags = (pargs.r_opt << PK_LIST_SHIFT); - if (configfp) + if (configname) sl->flags |= PK_LIST_CONFIG; break; case oDefRecipient: @@ -2929,7 +2953,6 @@ main (int argc, char **argv) xfree(opt.def_recipient); opt.def_recipient = NULL; opt.def_recipient_self = 0; break; - case oNoOptions: opt.no_homedir_creation = 1; break; /* no-options */ case oHomedir: break; case oNoBatch: opt.batch = 0; break; @@ -2961,7 +2984,7 @@ main (int argc, char **argv) opt.tofu_default_policy = parse_tofu_policy (pargs.r.ret_str); break; case oTOFUDBFormat: - obsolete_option (configname, configlineno, "tofu-db-format"); + obsolete_option (configname, pargs.lineno, "tofu-db-format"); break; case oForceOwnertrust: @@ -3018,17 +3041,17 @@ main (int argc, char **argv) case oSigPolicyURL: add_policy_url(pargs.r.ret_str,0); break; case oCertPolicyURL: add_policy_url(pargs.r.ret_str,1); break; case oShowPolicyURL: - deprecated_warning(configname,configlineno,"--show-policy-url", + deprecated_warning(configname,pargs.lineno,"--show-policy-url", "--list-options ","show-policy-urls"); - deprecated_warning(configname,configlineno,"--show-policy-url", + deprecated_warning(configname,pargs.lineno,"--show-policy-url", "--verify-options ","show-policy-urls"); opt.list_options|=LIST_SHOW_POLICY_URLS; opt.verify_options|=VERIFY_SHOW_POLICY_URLS; break; case oNoShowPolicyURL: - deprecated_warning(configname,configlineno,"--no-show-policy-url", + deprecated_warning(configname,pargs.lineno,"--no-show-policy-url", "--list-options ","no-show-policy-urls"); - deprecated_warning(configname,configlineno,"--no-show-policy-url", + deprecated_warning(configname,pargs.lineno,"--no-show-policy-url", "--verify-options ","no-show-policy-urls"); opt.list_options&=~LIST_SHOW_POLICY_URLS; opt.verify_options&=~VERIFY_SHOW_POLICY_URLS; @@ -3045,7 +3068,7 @@ main (int argc, char **argv) append_to_strlist(&opt.comments,pargs.r.ret_str); break; case oDefaultComment: - deprecated_warning(configname,configlineno, + deprecated_warning(configname,pargs.lineno, "--default-comment","--no-comments",""); /* fall through */ case oNoComments: @@ -3055,17 +3078,17 @@ main (int argc, char **argv) case oThrowKeyids: opt.throw_keyids = 1; break; case oNoThrowKeyids: opt.throw_keyids = 0; break; case oShowPhotos: - deprecated_warning(configname,configlineno,"--show-photos", + deprecated_warning(configname,pargs.lineno,"--show-photos", "--list-options ","show-photos"); - deprecated_warning(configname,configlineno,"--show-photos", + deprecated_warning(configname,pargs.lineno,"--show-photos", "--verify-options ","show-photos"); opt.list_options|=LIST_SHOW_PHOTOS; opt.verify_options|=VERIFY_SHOW_PHOTOS; break; case oNoShowPhotos: - deprecated_warning(configname,configlineno,"--no-show-photos", + deprecated_warning(configname,pargs.lineno,"--no-show-photos", "--list-options ","no-show-photos"); - deprecated_warning(configname,configlineno,"--no-show-photos", + deprecated_warning(configname,pargs.lineno,"--no-show-photos", "--verify-options ","no-show-photos"); opt.list_options&=~LIST_SHOW_PHOTOS; opt.verify_options&=~VERIFY_SHOW_PHOTOS; @@ -3096,7 +3119,7 @@ main (int argc, char **argv) * enough space for the flags. */ sl = add_to_strlist2( &remusr, pargs.r.ret_str, utf8_strings ); sl->flags = (pargs.r_opt << PK_LIST_SHIFT); - if (configfp) + if (configname) sl->flags |= PK_LIST_CONFIG; if (pargs.r_opt == oHiddenRecipient || pargs.r_opt == oHiddenRecipientFile) @@ -3112,7 +3135,7 @@ main (int argc, char **argv) /* Store an additional recipient. */ sl = add_to_strlist2( &remusr, pargs.r.ret_str, utf8_strings ); sl->flags = ((pargs.r_opt << PK_LIST_SHIFT) | PK_LIST_ENCRYPT_TO); - if (configfp) + if (configname) sl->flags |= PK_LIST_CONFIG; if (pargs.r_opt == oHiddenEncryptTo) sl->flags |= PK_LIST_HIDDEN; @@ -3122,7 +3145,7 @@ main (int argc, char **argv) opt.no_encrypt_to = 1; break; case oEncryptToDefaultKey: - opt.encrypt_to_default_key = configfp ? 2 : 1; + opt.encrypt_to_default_key = configname ? 2 : 1; break; case oTrySecretKey: @@ -3168,7 +3191,7 @@ main (int argc, char **argv) case oLocalUser: /* store the local users */ sl = add_to_strlist2( &locusr, pargs.r.ret_str, utf8_strings ); sl->flags = (pargs.r_opt << PK_LIST_SHIFT); - if (configfp) + if (configname) sl->flags |= PK_LIST_CONFIG; break; case oSender: @@ -3311,7 +3334,7 @@ main (int argc, char **argv) { if(configname) log_error(_("%s:%d: invalid keyserver options\n"), - configname,configlineno); + configname,pargs.lineno); else log_error(_("invalid keyserver options\n")); } @@ -3321,7 +3344,7 @@ main (int argc, char **argv) { if(configname) log_error(_("%s:%d: invalid import options\n"), - configname,configlineno); + configname,pargs.lineno); else log_error(_("invalid import options\n")); } @@ -3336,7 +3359,7 @@ main (int argc, char **argv) { if(configname) log_error(_("%s:%d: invalid export options\n"), - configname,configlineno); + configname,pargs.lineno); else log_error(_("invalid export options\n")); } @@ -3351,7 +3374,7 @@ main (int argc, char **argv) { if(configname) log_error(_("%s:%d: invalid list options\n"), - configname,configlineno); + configname,pargs.lineno); else log_error(_("invalid list options\n")); } @@ -3391,7 +3414,7 @@ main (int argc, char **argv) { if(configname) log_error(_("%s:%d: invalid verify options\n"), - configname,configlineno); + configname,pargs.lineno); else log_error(_("invalid verify options\n")); } @@ -3412,17 +3435,17 @@ main (int argc, char **argv) case oCertNotation: add_notation_data( pargs.r.ret_str, 1 ); break; case oKnownNotation: register_known_notation (pargs.r.ret_str); break; case oShowNotation: - deprecated_warning(configname,configlineno,"--show-notation", + deprecated_warning(configname,pargs.lineno,"--show-notation", "--list-options ","show-notations"); - deprecated_warning(configname,configlineno,"--show-notation", + deprecated_warning(configname,pargs.lineno,"--show-notation", "--verify-options ","show-notations"); opt.list_options|=LIST_SHOW_NOTATIONS; opt.verify_options|=VERIFY_SHOW_NOTATIONS; break; case oNoShowNotation: - deprecated_warning(configname,configlineno,"--no-show-notation", + deprecated_warning(configname,pargs.lineno,"--no-show-notation", "--list-options ","no-show-notations"); - deprecated_warning(configname,configlineno,"--no-show-notation", + deprecated_warning(configname,pargs.lineno,"--no-show-notation", "--verify-options ","no-show-notations"); opt.list_options&=~LIST_SHOW_NOTATIONS; opt.verify_options&=~VERIFY_SHOW_NOTATIONS; @@ -3475,7 +3498,7 @@ main (int argc, char **argv) ovrseskeyfd = translate_sys2libc_fd_int (pargs.r.ret_int, 0); break; case oMergeOnly: - deprecated_warning(configname,configlineno,"--merge-only", + deprecated_warning(configname,pargs.lineno,"--merge-only", "--import-options ","merge-only"); opt.import_options|=IMPORT_MERGE_ONLY; break; @@ -3607,7 +3630,7 @@ main (int argc, char **argv) { if(configname) log_error(_("%s:%d: invalid auto-key-locate list\n"), - configname,configlineno); + configname,pargs.lineno); else log_error(_("invalid auto-key-locate list\n")); } @@ -3629,7 +3652,7 @@ main (int argc, char **argv) if (configname) log_info("%s:%d: WARNING: gpg not built with large secure " "memory buffer. Ignoring enable-large-rsa\n", - configname,configlineno); + configname,pargs.lineno); else log_info("WARNING: gpg not built with large secure " "memory buffer. Ignoring --enable-large-rsa\n"); @@ -3686,7 +3709,7 @@ main (int argc, char **argv) case oNoop: break; default: - if (configfp) + if (configname) pargs.err = ARGPARSE_PRINT_WARNING; else { @@ -3700,19 +3723,8 @@ main (int argc, char **argv) } } - if (configfp) - { - fclose( configfp ); - configfp = NULL; - /* Remember the first config file name. */ - if (!save_configname) - save_configname = configname; - else - xfree(configname); - configname = NULL; - goto next_pass; - } - xfree(configname); configname = NULL; + gpgrt_argparse (NULL, &pargs, NULL); /* Release internal state. */ + if (log_get_errorcount (0)) { write_status_failure ("option-parser", gpg_error(GPG_ERR_GENERAL)); @@ -3723,11 +3735,10 @@ main (int argc, char **argv) directly after the option parsing. */ if (cmd == aGPGConfList) { - gpgconf_list (save_configname ? save_configname : default_configname); + gpgconf_list (last_configname ? last_configname : "UNKNOWN"); g10_exit (0); } - xfree (save_configname); - xfree (default_configname); + xfree (last_configname); if (print_dane_records) log_error ("invalid option \"%s\"; use \"%s\" instead\n", @@ -3750,19 +3761,19 @@ main (int argc, char **argv) if( greeting ) { es_fprintf (es_stderr, "%s %s; %s\n", - strusage(11), strusage(13), strusage(14) ); - es_fprintf (es_stderr, "%s\n", strusage(15) ); + gpgrt_strusage(11), gpgrt_strusage(13), gpgrt_strusage(14)); + es_fprintf (es_stderr, "%s\n", gpgrt_strusage(15) ); } #ifdef IS_DEVELOPMENT_VERSION if (!opt.batch) { const char *s; - if((s=strusage(25))) + if((s=gpgrt_strusage(25))) log_info("%s\n",s); - if((s=strusage(26))) + if((s=gpgrt_strusage(26))) log_info("%s\n",s); - if((s=strusage(27))) + if((s=gpgrt_strusage(27))) log_info("%s\n",s); } #endif diff --git a/g10/gpgv.c b/g10/gpgv.c index 88b348125..f2f14a676 100644 --- a/g10/gpgv.c +++ b/g10/gpgv.c @@ -19,6 +19,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include #include @@ -36,6 +39,7 @@ #define INCLUDED_BY_MAIN_MODULE 1 #include "gpg.h" #include "../common/util.h" +#include "../common/argparse.h" /* temporary hack. */ #include "packet.h" #include "../common/iobuf.h" #include "main.h" @@ -176,7 +180,7 @@ main( int argc, char **argv ) ctrl_t ctrl; early_system_init (); - set_strusage (my_strusage); + gpgrt_set_strusage (my_strusage); log_set_prefix ("gpgv", GPGRT_LOG_WITH_PREFIX); /* Make sure that our subsystems are ready. */ diff --git a/g13/g13-syshelp.c b/g13/g13-syshelp.c index 4ce74ee4c..205456568 100644 --- a/g13/g13-syshelp.c +++ b/g13/g13-syshelp.c @@ -18,6 +18,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include #include @@ -42,6 +45,7 @@ #include "../common/asshelp.h" #include "../common/init.h" #include "keyblob.h" +#include "../common/argparse.h" /* temporary hack. */ enum cmd_and_opt_values { diff --git a/g13/g13.c b/g13/g13.c index 6265b9f24..385ba0f9b 100644 --- a/g13/g13.c +++ b/g13/g13.c @@ -18,6 +18,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include #include @@ -47,6 +50,7 @@ #include "mountinfo.h" #include "backend.h" #include "call-syshelp.h" +#include "../common/argparse.h" /* temporary hack. */ enum cmd_and_opt_values { diff --git a/kbx/kbxutil.c b/kbx/kbxutil.c index 35f92ab6e..7769b834e 100644 --- a/kbx/kbxutil.c +++ b/kbx/kbxutil.c @@ -18,6 +18,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include #include @@ -37,6 +40,7 @@ #include "keybox-defs.h" #include "../common/init.h" #include +#include "../common/argparse.h" /* temporary hack. */ enum cmd_and_opt_values { diff --git a/scd/scdaemon.c b/scd/scdaemon.c index e64bb004e..507266532 100644 --- a/scd/scdaemon.c +++ b/scd/scdaemon.c @@ -19,6 +19,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include @@ -45,6 +48,7 @@ #include /* malloc hooks */ +#include "../common/argparse.h" /* temporary hack. */ #include "../common/i18n.h" #include "../common/sysutils.h" #include "iso7816.h" diff --git a/sm/call-agent.c b/sm/call-agent.c index 7ee728b74..31f7206d3 100644 --- a/sm/call-agent.c +++ b/sm/call-agent.c @@ -91,7 +91,7 @@ warn_version_mismatch (ctrl_t ctrl, assuan_context_t ctx, { gpg_error_t err; char *serverversion; - const char *myversion = strusage (13); + const char *myversion = gpgrt_strusage (13); err = get_assuan_server_version (ctx, mode, &serverversion); if (err) diff --git a/sm/call-dirmngr.c b/sm/call-dirmngr.c index f3fe1d663..4c764ea2c 100644 --- a/sm/call-dirmngr.c +++ b/sm/call-dirmngr.c @@ -158,7 +158,7 @@ warn_version_mismatch (ctrl_t ctrl, assuan_context_t ctx, { gpg_error_t err; char *serverversion; - const char *myversion = strusage (13); + const char *myversion = gpgrt_strusage (13); err = get_assuan_server_version (ctx, mode, &serverversion); if (err) diff --git a/sm/gpgsm.c b/sm/gpgsm.c index 8b4c9631d..96e14b59d 100644 --- a/sm/gpgsm.c +++ b/sm/gpgsm.c @@ -19,6 +19,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include #include @@ -33,6 +36,7 @@ #include "gpgsm.h" #include #include /* malloc hooks */ +#include "../common/argparse.h" /* temporary hack. */ #include "passphrase.h" #include "../common/shareddefs.h" diff --git a/tests/gpgscm/main.c b/tests/gpgscm/main.c index 5540ac365..dc176c302 100644 --- a/tests/gpgscm/main.c +++ b/tests/gpgscm/main.c @@ -19,6 +19,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include @@ -48,6 +51,7 @@ #include "../../common/strlist.h" #include "../../common/sysutils.h" #include "../../common/util.h" +#include "../common/argparse.h" /* temporary hack. */ /* The TinyScheme banner. Unfortunately, it isn't in the header file. */ diff --git a/tools/card-call-scd.c b/tools/card-call-scd.c index 62c1d1b2f..bcf630a28 100644 --- a/tools/card-call-scd.c +++ b/tools/card-call-scd.c @@ -269,7 +269,7 @@ warn_version_mismatch (assuan_context_t ctx, const char *servername, int mode) { gpg_error_t err; char *serverversion; - const char *myversion = strusage (13); + const char *myversion = gpgrt_strusage (13); err = get_assuan_server_version (ctx, mode, &serverversion); if (err) diff --git a/tools/gpg-card.c b/tools/gpg-card.c index 84bbd7ec1..1967d4915 100644 --- a/tools/gpg-card.c +++ b/tools/gpg-card.c @@ -19,6 +19,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include #include @@ -41,6 +44,7 @@ #include "../common/ttyio.h" #include "../common/server-help.h" #include "../common/openpgpdefs.h" +#include "../common/argparse.h" /* temporary hack. */ #include "gpg-card.h" diff --git a/tools/gpg-check-pattern.c b/tools/gpg-check-pattern.c index 43cea1dd1..be1832217 100644 --- a/tools/gpg-check-pattern.c +++ b/tools/gpg-check-pattern.c @@ -18,6 +18,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include @@ -44,6 +47,7 @@ #include "../common/i18n.h" #include "../common/sysutils.h" #include "../common/init.h" +#include "../common/argparse.h" /* temporary hack. */ enum cmd_and_opt_values @@ -491,4 +495,3 @@ process (FILE *fp, pattern_t *patarray) if (opt.verbose) log_info ("no input line matches the pattern - accepted\n"); } - diff --git a/tools/gpg-connect-agent.c b/tools/gpg-connect-agent.c index 564b3007f..ae044dcc4 100644 --- a/tools/gpg-connect-agent.c +++ b/tools/gpg-connect-agent.c @@ -19,6 +19,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include @@ -31,6 +34,7 @@ #include "../common/i18n.h" #include "../common/util.h" +#include "../common/argparse.h" /* temporary hack. */ #include "../common/asshelp.h" #include "../common/sysutils.h" #include "../common/membuf.h" diff --git a/tools/gpg-pair-tool.c b/tools/gpg-pair-tool.c index 61877b171..a41d99031 100644 --- a/tools/gpg-pair-tool.c +++ b/tools/gpg-pair-tool.c @@ -119,8 +119,10 @@ * */ - #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include #include @@ -136,6 +138,7 @@ #include "../common/sysutils.h" #include "../common/init.h" #include "../common/name-value.h" +#include "../common/argparse.h" /* temporary hack. */ /* Constants to identify the commands and options. */ diff --git a/tools/gpg-wks-client.c b/tools/gpg-wks-client.c index 98ca2fb38..8c13be7e2 100644 --- a/tools/gpg-wks-client.c +++ b/tools/gpg-wks-client.c @@ -19,6 +19,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include #include @@ -41,6 +44,7 @@ #include "mime-maker.h" #include "send-mail.h" #include "gpg-wks.h" +#include "../common/argparse.h" /* temporary hack. */ /* Constants to identify the commands and options. */ diff --git a/tools/gpg-wks-server.c b/tools/gpg-wks-server.c index 8cdbfaf36..bd0dfd641 100644 --- a/tools/gpg-wks-server.c +++ b/tools/gpg-wks-server.c @@ -24,6 +24,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include #include @@ -45,6 +48,7 @@ #include "mime-maker.h" #include "send-mail.h" #include "gpg-wks.h" +#include "../common/argparse.h" /* temporary hack. */ /* The time we wait for a confirmation response. */ diff --git a/tools/gpgconf.c b/tools/gpgconf.c index 44d916bc2..a6094400b 100644 --- a/tools/gpgconf.c +++ b/tools/gpgconf.c @@ -19,6 +19,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include #include @@ -31,6 +34,7 @@ #include "../common/sysutils.h" #include "../common/init.h" #include "../common/status.h" +#include "../common/argparse.h" /* temporary hack. */ /* Constants to identify the commands and options. */ diff --git a/tools/gpgsplit.c b/tools/gpgsplit.c index 674be6271..8b65c89c5 100644 --- a/tools/gpgsplit.c +++ b/tools/gpgsplit.c @@ -18,6 +18,9 @@ */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include #include @@ -39,6 +42,7 @@ #define INCLUDED_BY_MAIN_MODULE 1 #include "../common/util.h" #include "../common/openpgpdefs.h" +#include "../common/argparse.h" /* temporary hack. */ #ifdef HAVE_BZIP2 # include diff --git a/tools/gpgtar.c b/tools/gpgtar.c index e5cbde4af..363510ecf 100644 --- a/tools/gpgtar.c +++ b/tools/gpgtar.c @@ -27,6 +27,9 @@ gpg. So here we go. */ #include +/* We don't want to have the macros from gpgrt here until we have + * completely replaced this module by the one from gpgrt. */ +#undef GPGRT_ENABLE_ARGPARSE_MACROS #include #include #include @@ -41,6 +44,7 @@ #include "../common/openpgpdefs.h" #include "../common/init.h" #include "../common/strlist.h" +#include "../common/argparse.h" /* temporary hack. */ #include "gpgtar.h"