From 9f37d3e6f307a9460c0a356afa1f8b991c527d6c Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 8 Jan 2021 14:09:59 +0100 Subject: [PATCH] gpg: Fix --gpgconf-list case with no conf files at all. * g10/gpg.c (get_default_configname): Remove unused function. (main): Provide a proper filename to gpgconf_list. -- With the new option pasrer we used "UNKOWN" in this case. The problem was that gpgconf --list-options chekcs that an absolute file is provided and thus bails out if no config file is in /etc/gnupg or in ~/.gnupg/. get_default_configname was not anymore in use because its function is part of the new option parser. --- g10/gpg.c | 65 ++++++------------------------------------------------- 1 file changed, 7 insertions(+), 58 deletions(-) diff --git a/g10/gpg.c b/g10/gpg.c index 431c516b9..6b44cfb0a 100644 --- a/g10/gpg.c +++ b/g10/gpg.c @@ -2231,63 +2231,6 @@ gpg_deinit_default_ctrl (ctrl_t ctrl) } -char * -get_default_configname (void) -{ - char *configname = NULL; - char *name = xstrdup (GPG_NAME EXTSEP_S "conf-" SAFE_VERSION); - char *ver = &name[strlen (GPG_NAME EXTSEP_S "conf-")]; - - do - { - if (configname) - { - char *tok; - - xfree (configname); - configname = NULL; - - if ((tok = strrchr (ver, SAFE_VERSION_DASH))) - *tok='\0'; - else if ((tok = strrchr (ver, SAFE_VERSION_DOT))) - *tok='\0'; - else - break; - } - - configname = make_filename (gnupg_homedir (), name, NULL); - } - while (access (configname, R_OK)); - - xfree(name); - - if (! configname) - configname = make_filename (gnupg_homedir (), - GPG_NAME EXTSEP_S "conf", NULL); - if (! access (configname, R_OK)) - { - /* Print a warning when both config files are present. */ - char *p = make_filename (gnupg_homedir (), "options", NULL); - if (! access (p, R_OK)) - log_info (_("Note: old default options file '%s' ignored\n"), p); - xfree (p); - } - else - { - /* Use the old default only if it exists. */ - char *p = make_filename (gnupg_homedir (), "options", NULL); - if (!access (p, R_OK)) - { - xfree (configname); - configname = p; - } - else - xfree (p); - } - - return configname; -} - int main (int argc, char **argv) { @@ -3643,7 +3586,13 @@ main (int argc, char **argv) directly after the option parsing. */ if (cmd == aGPGConfList) { - gpgconf_list (last_configname ? last_configname : "UNKNOWN"); + /* Note: Here in gpg 2.2 we need to provide a proper config + * file even if that file does not exist. This is because + * gpgconf checks that an absolute filename is provided. */ + if (!last_configname) + last_configname= make_filename (gnupg_homedir (), + GPG_NAME EXTSEP_S "conf", NULL); + gpgconf_list (last_configname); g10_exit (0); } xfree (last_configname);