2004-01-05 10:28:27 +01:00
|
|
|
/* gpgconf.c - Configuration utility for GnuPG
|
2011-02-23 10:15:34 +01:00
|
|
|
* Copyright (C) 2003, 2007, 2009, 2011 Free Software Foundation, Inc.
|
2016-11-02 17:54:32 +01:00
|
|
|
* Copyright (C) 2016 g10 Code GmbH.
|
2004-01-05 10:28:27 +01:00
|
|
|
*
|
|
|
|
* 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
|
2007-07-04 21:49:40 +02:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-01-05 10:28:27 +01:00
|
|
|
* (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
|
2016-11-05 12:02:19 +01:00
|
|
|
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
2020-02-21 20:28:47 +01:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2004-01-05 10:28:27 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2020-02-21 20:28:47 +01:00
|
|
|
|
2004-01-05 10:28:27 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2016-06-08 14:04:47 +02:00
|
|
|
#include <unistd.h>
|
2004-01-05 10:28:27 +01:00
|
|
|
|
2020-02-10 16:37:34 +01:00
|
|
|
#define INCLUDED_BY_MAIN_MODULE 1
|
2004-01-05 10:28:27 +01:00
|
|
|
#include "gpgconf.h"
|
2017-03-07 12:21:23 +01:00
|
|
|
#include "../common/i18n.h"
|
|
|
|
#include "../common/sysutils.h"
|
2012-02-06 20:50:47 +01:00
|
|
|
#include "../common/init.h"
|
2017-12-18 17:46:05 +01:00
|
|
|
#include "../common/status.h"
|
2023-12-20 03:00:22 +01:00
|
|
|
#include "../common/dotlock.h"
|
2012-02-06 20:50:47 +01:00
|
|
|
|
2021-12-17 05:28:42 +01:00
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
2004-01-05 10:28:27 +01:00
|
|
|
|
|
|
|
/* Constants to identify the commands and options. */
|
|
|
|
enum cmd_and_opt_values
|
|
|
|
{
|
|
|
|
aNull = 0,
|
|
|
|
oDryRun = 'n',
|
|
|
|
oOutput = 'o',
|
2004-01-29 00:58:18 +01:00
|
|
|
oQuiet = 'q',
|
2004-01-05 10:28:27 +01:00
|
|
|
oVerbose = 'v',
|
2004-02-23 21:31:35 +01:00
|
|
|
oRuntime = 'r',
|
2004-01-29 00:58:18 +01:00
|
|
|
oComponent = 'c',
|
2016-08-04 13:02:37 +02:00
|
|
|
oNull = '0',
|
2022-01-12 20:26:19 +01:00
|
|
|
aListDirs = 'L',
|
|
|
|
aKill = 'K',
|
|
|
|
aReload = 'R',
|
2022-06-29 13:14:35 +02:00
|
|
|
aShowVersions = 'V',
|
|
|
|
aShowConfigs = 'X',
|
2022-01-12 20:26:19 +01:00
|
|
|
|
2004-01-05 10:28:27 +01:00
|
|
|
oNoVerbose = 500,
|
|
|
|
oHomedir,
|
2016-12-14 14:18:22 +01:00
|
|
|
oBuilddir,
|
2017-12-18 17:46:05 +01:00
|
|
|
oStatusFD,
|
2019-02-25 15:55:13 +01:00
|
|
|
oShowSocket,
|
2020-08-06 15:32:43 +02:00
|
|
|
oChUid,
|
2004-01-29 00:58:18 +01:00
|
|
|
|
|
|
|
aListComponents,
|
2007-08-29 11:51:37 +02:00
|
|
|
aCheckPrograms,
|
2004-01-29 00:58:18 +01:00
|
|
|
aListOptions,
|
|
|
|
aChangeOptions,
|
2008-05-20 00:46:41 +02:00
|
|
|
aCheckOptions,
|
2007-03-06 21:44:41 +01:00
|
|
|
aApplyDefaults,
|
2007-10-23 20:13:27 +02:00
|
|
|
aListConfig,
|
2008-05-26 15:43:20 +02:00
|
|
|
aCheckConfig,
|
2016-11-02 17:54:32 +01:00
|
|
|
aQuerySWDB,
|
2014-04-08 15:55:51 +02:00
|
|
|
aLaunch,
|
2016-06-08 14:04:47 +02:00
|
|
|
aCreateSocketDir,
|
|
|
|
aRemoveSocketDir,
|
2016-12-16 16:00:15 +01:00
|
|
|
aApplyProfile,
|
2023-12-20 03:00:22 +01:00
|
|
|
aShowCodepages,
|
|
|
|
aDotlockLock,
|
|
|
|
aDotlockUnlock
|
2004-01-05 10:28:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* The list of commands and options. */
|
2020-02-21 20:28:47 +01:00
|
|
|
static gpgrt_opt_t opts[] =
|
2004-01-05 10:28:27 +01:00
|
|
|
{
|
2023-12-25 02:07:07 +01:00
|
|
|
ARGPARSE_group (300, N_("@Commands:\n ")),
|
|
|
|
|
|
|
|
ARGPARSE_c (aListComponents, "list-components", N_("list all components")),
|
|
|
|
ARGPARSE_c (aCheckPrograms, "check-programs", N_("check all programs")),
|
|
|
|
ARGPARSE_c (aListOptions, "list-options", N_("|COMPONENT|list options")),
|
|
|
|
ARGPARSE_c (aChangeOptions, "change-options",
|
|
|
|
N_("|COMPONENT|change options")),
|
|
|
|
ARGPARSE_c (aCheckOptions, "check-options", N_("|COMPONENT|check options")),
|
|
|
|
ARGPARSE_c (aApplyDefaults, "apply-defaults",
|
|
|
|
N_("apply global default values")),
|
|
|
|
ARGPARSE_c (aApplyProfile, "apply-profile",
|
|
|
|
N_("|FILE|update configuration files using FILE")),
|
|
|
|
ARGPARSE_c (aListDirs, "list-dirs",
|
|
|
|
N_("get the configuration directories for @GPGCONF@")),
|
|
|
|
ARGPARSE_c (aListConfig, "list-config",
|
|
|
|
N_("list global configuration file")),
|
|
|
|
ARGPARSE_c (aCheckConfig, "check-config",
|
|
|
|
N_("check global configuration file")),
|
|
|
|
ARGPARSE_c (aQuerySWDB, "query-swdb",
|
|
|
|
N_("query the software version database")),
|
|
|
|
ARGPARSE_c (aReload, "reload", N_("reload all or a given component")),
|
|
|
|
ARGPARSE_c (aLaunch, "launch", N_("launch a given component")),
|
|
|
|
ARGPARSE_c (aKill, "kill", N_("kill a given component")),
|
|
|
|
ARGPARSE_c (aCreateSocketDir, "create-socketdir", "@"),
|
|
|
|
ARGPARSE_c (aRemoveSocketDir, "remove-socketdir", "@"),
|
2022-06-29 13:14:35 +02:00
|
|
|
ARGPARSE_c (aShowVersions, "show-versions", ""),
|
|
|
|
ARGPARSE_c (aShowConfigs, "show-configs", ""),
|
2023-12-20 03:00:22 +01:00
|
|
|
/* hidden commands: for debugging */
|
2020-08-25 10:38:29 +02:00
|
|
|
ARGPARSE_c (aShowCodepages, "show-codepages", "@"),
|
2023-12-20 03:00:22 +01:00
|
|
|
ARGPARSE_c (aDotlockLock, "lock", "@"),
|
|
|
|
ARGPARSE_c (aDotlockUnlock, "unlock", "@"),
|
2004-01-29 00:58:18 +01:00
|
|
|
|
2023-12-25 02:07:07 +01:00
|
|
|
ARGPARSE_header (NULL, N_("@\nOptions:\n ")),
|
2011-02-23 10:15:34 +01:00
|
|
|
|
2023-12-25 02:07:07 +01:00
|
|
|
ARGPARSE_s_s (oOutput, "output", N_("use as output file")),
|
|
|
|
ARGPARSE_s_n (oVerbose, "verbose", N_("verbose")),
|
|
|
|
ARGPARSE_s_n (oQuiet, "quiet", N_("quiet")),
|
|
|
|
ARGPARSE_s_n (oDryRun, "dry-run", N_("do not make any changes")),
|
|
|
|
ARGPARSE_s_n (oRuntime, "runtime",
|
|
|
|
N_("activate changes at runtime, if possible")),
|
2023-06-27 07:44:01 +02:00
|
|
|
ARGPARSE_s_i (oStatusFD, "status-fd",
|
2020-08-25 10:38:29 +02:00
|
|
|
N_("|FD|write status info to this FD")),
|
2004-01-05 10:28:27 +01:00
|
|
|
/* hidden options */
|
2023-12-25 02:07:07 +01:00
|
|
|
ARGPARSE_s_s (oHomedir, "homedir", "@"),
|
|
|
|
ARGPARSE_s_s (oBuilddir, "build-prefix", "@"),
|
|
|
|
ARGPARSE_s_n (oNull, "null", "@"),
|
|
|
|
ARGPARSE_s_n (oNoVerbose, "no-verbose", "@"),
|
2019-02-25 15:55:13 +01:00
|
|
|
ARGPARSE_s_n (oShowSocket, "show-socket", "@"),
|
2020-08-06 15:32:43 +02:00
|
|
|
ARGPARSE_s_s (oChUid, "chuid", "@"),
|
2017-07-19 06:41:18 +02:00
|
|
|
|
2023-12-25 02:07:07 +01:00
|
|
|
ARGPARSE_end ()
|
2004-01-05 10:28:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-11-04 16:34:26 +01:00
|
|
|
|
|
|
|
#define CUTLINE_FMT \
|
|
|
|
"--8<---------------cut here---------------%s------------->8---\n"
|
|
|
|
|
|
|
|
|
2017-12-18 17:46:05 +01:00
|
|
|
/* The stream to output the status information. Status Output is disabled if
|
|
|
|
* this is NULL. */
|
|
|
|
static estream_t statusfp;
|
|
|
|
|
2020-10-02 12:26:02 +02:00
|
|
|
static void show_versions (estream_t fp);
|
2021-11-04 16:34:26 +01:00
|
|
|
static void show_configs (estream_t fp);
|
2020-10-02 12:26:02 +02:00
|
|
|
|
|
|
|
|
2017-12-18 17:46:05 +01:00
|
|
|
|
2017-02-20 22:19:50 +01:00
|
|
|
/* Print usage information and provide strings for help. */
|
2004-01-05 10:28:27 +01:00
|
|
|
static const char *
|
|
|
|
my_strusage( int level )
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
switch (level)
|
|
|
|
{
|
2020-02-21 20:28:47 +01:00
|
|
|
case 9: p = "GPL-3.0-or-later"; break;
|
2013-11-18 14:09:47 +01:00
|
|
|
case 11: p = "@GPGCONF@ (@GNUPG@)";
|
2004-01-05 10:28:27 +01:00
|
|
|
break;
|
|
|
|
case 13: p = VERSION; break;
|
2020-02-21 20:28:47 +01:00
|
|
|
case 14: p = GNUPG_DEF_COPYRIGHT_LINE; break;
|
2004-01-05 10:28:27 +01:00
|
|
|
case 17: p = PRINTABLE_OS_NAME; break;
|
2009-07-21 16:21:05 +02:00
|
|
|
case 19: p = _("Please report bugs to <@EMAIL@>.\n"); break;
|
|
|
|
|
2004-01-05 10:28:27 +01:00
|
|
|
case 1:
|
2013-11-18 14:09:47 +01:00
|
|
|
case 40: p = _("Usage: @GPGCONF@ [options] (-h for help)");
|
2004-01-05 10:28:27 +01:00
|
|
|
break;
|
|
|
|
case 41:
|
2013-11-18 14:09:47 +01:00
|
|
|
p = _("Syntax: @GPGCONF@ [options]\n"
|
|
|
|
"Manage configuration options for tools of the @GNUPG@ system\n");
|
2004-01-05 10:28:27 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: p = NULL; break;
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-23 20:13:27 +02:00
|
|
|
/* Return the fp for the output. This is usually stdout unless
|
|
|
|
--output has been used. In the latter case this function opens
|
|
|
|
that file. */
|
2010-08-18 21:25:15 +02:00
|
|
|
static estream_t
|
|
|
|
get_outfp (estream_t *fp)
|
2007-10-23 20:13:27 +02:00
|
|
|
{
|
|
|
|
if (!*fp)
|
|
|
|
{
|
|
|
|
if (opt.outfile)
|
|
|
|
{
|
2010-08-18 21:25:15 +02:00
|
|
|
*fp = es_fopen (opt.outfile, "w");
|
2007-10-23 20:13:27 +02:00
|
|
|
if (!*fp)
|
2012-06-05 19:29:22 +02:00
|
|
|
gc_error (1, errno, "can not open '%s'", opt.outfile);
|
2007-10-23 20:13:27 +02:00
|
|
|
}
|
|
|
|
else
|
2010-08-18 21:25:15 +02:00
|
|
|
*fp = es_stdout;
|
2007-10-23 20:13:27 +02:00
|
|
|
}
|
|
|
|
return *fp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-18 17:46:05 +01:00
|
|
|
/* Set the status FD. */
|
|
|
|
static void
|
|
|
|
set_status_fd (int fd)
|
|
|
|
{
|
|
|
|
static int last_fd = -1;
|
|
|
|
|
|
|
|
if (fd != -1 && last_fd == fd)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (statusfp && statusfp != es_stdout && statusfp != es_stderr)
|
|
|
|
es_fclose (statusfp);
|
|
|
|
statusfp = NULL;
|
|
|
|
if (fd == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (fd == 1)
|
|
|
|
statusfp = es_stdout;
|
|
|
|
else if (fd == 2)
|
|
|
|
statusfp = es_stderr;
|
|
|
|
else
|
|
|
|
statusfp = es_fdopen (fd, "w");
|
|
|
|
if (!statusfp)
|
|
|
|
{
|
|
|
|
log_fatal ("can't open fd %d for status output: %s\n",
|
|
|
|
fd, gpg_strerror (gpg_error_from_syserror ()));
|
|
|
|
}
|
|
|
|
last_fd = fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Write a status line with code NO followed by the output of the
|
|
|
|
* printf style FORMAT. The caller needs to make sure that LFs and
|
|
|
|
* CRs are not printed. */
|
|
|
|
void
|
|
|
|
gpgconf_write_status (int no, const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list arg_ptr;
|
|
|
|
|
|
|
|
if (!statusfp)
|
|
|
|
return; /* Not enabled. */
|
|
|
|
|
|
|
|
es_fputs ("[GNUPG:] ", statusfp);
|
|
|
|
es_fputs (get_status_string (no), statusfp);
|
|
|
|
if (format)
|
|
|
|
{
|
|
|
|
es_putc (' ', statusfp);
|
|
|
|
va_start (arg_ptr, format);
|
|
|
|
es_vfprintf (statusfp, format, arg_ptr);
|
|
|
|
va_end (arg_ptr);
|
|
|
|
}
|
|
|
|
es_putc ('\n', statusfp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-11 13:05:37 +02:00
|
|
|
static void
|
2024-03-18 11:14:19 +01:00
|
|
|
list_dirs (estream_t fp, char **names, int show_config_mode)
|
2016-07-11 13:05:37 +02:00
|
|
|
{
|
|
|
|
static struct {
|
2024-03-18 11:14:19 +01:00
|
|
|
const char *name; /* If NULL only a file check will be done. */
|
2016-07-11 13:05:37 +02:00
|
|
|
const char *(*fnc)(void);
|
|
|
|
const char *extra;
|
|
|
|
} list[] = {
|
|
|
|
{ "sysconfdir", gnupg_sysconfdir, NULL },
|
|
|
|
{ "bindir", gnupg_bindir, NULL },
|
|
|
|
{ "libexecdir", gnupg_libexecdir, NULL },
|
|
|
|
{ "libdir", gnupg_libdir, NULL },
|
|
|
|
{ "datadir", gnupg_datadir, NULL },
|
|
|
|
{ "localedir", gnupg_localedir, NULL },
|
2016-08-29 11:53:06 +02:00
|
|
|
{ "socketdir", gnupg_socketdir, NULL },
|
2016-08-18 11:23:40 +02:00
|
|
|
{ "dirmngr-socket", dirmngr_socket_name, NULL,},
|
2020-09-23 12:02:50 +02:00
|
|
|
{ "keyboxd-socket", keyboxd_socket_name, NULL,},
|
2016-07-11 13:05:37 +02:00
|
|
|
{ "agent-ssh-socket", gnupg_socketdir, GPG_AGENT_SSH_SOCK_NAME },
|
2016-09-30 19:21:51 +02:00
|
|
|
{ "agent-extra-socket", gnupg_socketdir, GPG_AGENT_EXTRA_SOCK_NAME },
|
|
|
|
{ "agent-browser-socket",gnupg_socketdir, GPG_AGENT_BROWSER_SOCK_NAME },
|
2016-07-11 13:05:37 +02:00
|
|
|
{ "agent-socket", gnupg_socketdir, GPG_AGENT_SOCK_NAME },
|
2024-03-18 11:14:19 +01:00
|
|
|
{ NULL, gnupg_socketdir, "S.uiserver" },
|
2016-07-11 13:05:37 +02:00
|
|
|
{ "homedir", gnupg_homedir, NULL }
|
|
|
|
};
|
|
|
|
int idx, j;
|
|
|
|
char *tmp;
|
|
|
|
const char *s;
|
2024-03-18 11:14:19 +01:00
|
|
|
gpg_error_t err;
|
2016-07-11 13:05:37 +02:00
|
|
|
|
2024-04-04 15:09:12 +02:00
|
|
|
if (show_config_mode)
|
|
|
|
es_fprintf (fp, "#+begin_example\n");
|
2016-07-11 13:05:37 +02:00
|
|
|
for (idx = 0; idx < DIM (list); idx++)
|
|
|
|
{
|
|
|
|
s = list[idx].fnc ();
|
|
|
|
if (list[idx].extra)
|
|
|
|
{
|
|
|
|
tmp = make_filename (s, list[idx].extra, NULL);
|
|
|
|
s = tmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tmp = NULL;
|
2024-03-18 11:14:19 +01:00
|
|
|
|
|
|
|
if (!list[idx].name)
|
|
|
|
;
|
|
|
|
else if (!names)
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (fp, "%s%s:%s\n", show_config_mode? " ":"",
|
|
|
|
list[idx].name, gc_percent_escape (s));
|
2016-07-11 13:05:37 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for (j=0; names[j]; j++)
|
|
|
|
if (!strcmp (names[j], list[idx].name))
|
2016-08-04 13:02:37 +02:00
|
|
|
{
|
2024-04-04 15:09:12 +02:00
|
|
|
if (show_config_mode)
|
|
|
|
es_fputs (" ", fp);
|
2016-08-04 13:02:37 +02:00
|
|
|
es_fputs (s, fp);
|
|
|
|
es_putc (opt.null? '\0':'\n', fp);
|
|
|
|
}
|
2016-07-11 13:05:37 +02:00
|
|
|
}
|
|
|
|
|
2024-03-18 11:14:19 +01:00
|
|
|
/* In show config mode check that the socket files are accessible. */
|
|
|
|
if (list[idx].extra && show_config_mode)
|
|
|
|
{
|
|
|
|
estream_t tmpfp;
|
|
|
|
|
|
|
|
tmpfp = es_fopen (s, "rb");
|
|
|
|
if (tmpfp)
|
|
|
|
es_fclose (tmpfp); /* All fine - we can read that file. */
|
|
|
|
else if ((err=gpg_error_from_syserror ()) == GPG_ERR_ENOENT
|
|
|
|
|| err == GPG_ERR_ENXIO)
|
|
|
|
; /* No such file/ No such device or address - this is okay. */
|
|
|
|
else
|
|
|
|
es_fprintf (fp,
|
2024-04-04 15:09:12 +02:00
|
|
|
"# Warning: error reading existing file '%s': %s\n",
|
2024-03-18 11:14:19 +01:00
|
|
|
s, gpg_strerror (err));
|
|
|
|
}
|
|
|
|
|
2016-07-11 13:05:37 +02:00
|
|
|
xfree (tmp);
|
|
|
|
}
|
2024-04-04 15:09:12 +02:00
|
|
|
if (show_config_mode)
|
|
|
|
es_fprintf (fp, "#+end_example\n");
|
2020-01-17 14:23:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
tmp = read_w32_registry_string (NULL,
|
2024-03-21 17:41:10 +01:00
|
|
|
gnupg_registry_dir (),
|
2020-01-17 14:23:13 +01:00
|
|
|
"HomeDir");
|
|
|
|
if (tmp)
|
|
|
|
{
|
2021-08-11 11:38:37 +02:00
|
|
|
int hkcu = 0;
|
|
|
|
int hklm = 0;
|
|
|
|
|
|
|
|
xfree (tmp);
|
|
|
|
if ((tmp = read_w32_registry_string ("HKEY_CURRENT_USER",
|
2024-03-21 17:41:10 +01:00
|
|
|
gnupg_registry_dir (),
|
2021-08-11 11:38:37 +02:00
|
|
|
"HomeDir")))
|
|
|
|
{
|
|
|
|
xfree (tmp);
|
|
|
|
hkcu = 1;
|
|
|
|
}
|
|
|
|
if ((tmp = read_w32_registry_string ("HKEY_LOCAL_MACHINE",
|
2024-03-21 17:41:10 +01:00
|
|
|
gnupg_registry_dir (),
|
2021-08-11 11:38:37 +02:00
|
|
|
"HomeDir")))
|
|
|
|
{
|
|
|
|
xfree (tmp);
|
|
|
|
hklm = 1;
|
|
|
|
}
|
|
|
|
|
2020-01-17 14:23:13 +01:00
|
|
|
es_fflush (fp);
|
2024-03-18 11:14:19 +01:00
|
|
|
if (show_config_mode)
|
2021-11-19 09:29:37 +01:00
|
|
|
es_fprintf (fp, "\n"
|
2024-04-04 15:09:12 +02:00
|
|
|
"Note: homedir taken from registry key %s%s\\%s:%s\n"
|
2021-11-19 09:29:37 +01:00
|
|
|
"\n",
|
2021-11-19 09:38:07 +01:00
|
|
|
hkcu?"HKCU":"", hklm?"HKLM":"",
|
2024-03-21 17:41:10 +01:00
|
|
|
gnupg_registry_dir (), "HomeDir");
|
2021-11-19 09:29:37 +01:00
|
|
|
else
|
|
|
|
log_info ("Warning: homedir taken from registry key (%s:%s) in%s%s\n",
|
2024-03-21 17:41:10 +01:00
|
|
|
gnupg_registry_dir (), "HomeDir",
|
2021-11-19 09:29:37 +01:00
|
|
|
hkcu?" HKCU":"",
|
|
|
|
hklm?" HKLM":"");
|
2021-08-11 11:38:37 +02:00
|
|
|
}
|
|
|
|
else if ((tmp = read_w32_registry_string (NULL,
|
2024-03-21 17:41:10 +01:00
|
|
|
gnupg_registry_dir (),
|
2021-08-11 11:38:37 +02:00
|
|
|
NULL)))
|
|
|
|
{
|
2020-01-17 14:23:13 +01:00
|
|
|
xfree (tmp);
|
2021-08-11 11:38:37 +02:00
|
|
|
es_fflush (fp);
|
2024-03-18 11:14:19 +01:00
|
|
|
if (show_config_mode)
|
2021-11-19 09:29:37 +01:00
|
|
|
es_fprintf (fp, "\n"
|
2024-04-04 15:09:12 +02:00
|
|
|
"Note: registry %s without value in HKCU or HKLM\n"
|
2021-11-19 09:29:37 +01:00
|
|
|
"\n", GNUPG_REGISTRY_DIR);
|
|
|
|
else
|
|
|
|
log_info ("Warning: registry key (%s) without value in HKCU or HKLM\n",
|
2024-03-21 17:41:10 +01:00
|
|
|
gnupg_registry_dir ());
|
2020-01-17 14:23:13 +01:00
|
|
|
}
|
2021-08-11 11:38:37 +02:00
|
|
|
|
2021-11-19 09:29:37 +01:00
|
|
|
#else /*!HAVE_W32_SYSTEM*/
|
2024-03-18 11:14:19 +01:00
|
|
|
(void)show_config_mode;
|
2021-11-19 09:29:37 +01:00
|
|
|
#endif /*!HAVE_W32_SYSTEM*/
|
2016-07-11 13:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-02 17:54:32 +01:00
|
|
|
|
|
|
|
/* Check whether NAME is valid argument for query_swdb(). Valid names
|
|
|
|
* start with a letter and contain only alphanumeric characters or an
|
|
|
|
* underscore. */
|
|
|
|
static int
|
|
|
|
valid_swdb_name_p (const char *name)
|
|
|
|
{
|
|
|
|
if (!name || !*name || !alphap (name))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (name++; *name; name++)
|
|
|
|
if (!alnump (name) && *name != '_')
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Query the SWDB file. If necessary and possible this functions asks
|
|
|
|
* the dirmngr to load an updated version of that file. The caller
|
|
|
|
* needs to provide the NAME to query (e.g. "gnupg", "libgcrypt") and
|
|
|
|
* optional the currently installed version in CURRENT_VERSION. The
|
|
|
|
* output written to OUT is a colon delimited line with these fields:
|
|
|
|
*
|
|
|
|
* name :: The name of the package
|
2016-11-03 10:58:19 +01:00
|
|
|
* curvers:: The installed version if given.
|
2016-11-02 17:54:32 +01:00
|
|
|
* status :: This value tells the status of the software package
|
|
|
|
* '-' :: No information available
|
|
|
|
* (error or CURRENT_VERSION not given)
|
|
|
|
* '?' :: Unknown NAME
|
|
|
|
* 'u' :: Update available
|
|
|
|
* 'c' :: The version is Current
|
|
|
|
* 'n' :: The current version is already Newer than the
|
|
|
|
* available one.
|
|
|
|
* urgency :: If the value is greater than zero an urgent update is required.
|
|
|
|
* error :: 0 on success or an gpg_err_code_t
|
|
|
|
* Common codes seen:
|
|
|
|
* GPG_ERR_TOO_OLD :: The SWDB file is to old to be used.
|
|
|
|
* GPG_ERR_ENOENT :: The SWDB file is not available.
|
Spelling cleanup.
No functional changes, just fixing minor spelling issues.
---
Most of these were identified from the command line by running:
codespell \
--ignore-words-list fpr,stati,keyserver,keyservers,asign,cas,iff,ifset \
--skip '*.po,ChangeLog*,help.*.txt,*.jpg,*.eps,*.pdf,*.png,*.gpg,*.asc' \
doc g13 g10 kbx agent artwork scd tests tools am common dirmngr sm \
NEWS README README.maint TODO
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2020-02-18 15:34:42 +01:00
|
|
|
* GPG_ERR_BAD_SIGNATURE :: Corrupted SWDB file.
|
2016-11-02 17:54:32 +01:00
|
|
|
* filedate:: Date of the swdb file (yyyymmddThhmmss)
|
|
|
|
* verified:: Date we checked the validity of the file (yyyyymmddThhmmss)
|
|
|
|
* version :: The version string from the swdb.
|
|
|
|
* reldate :: Release date of that version (yyyymmddThhmmss)
|
|
|
|
* size :: Size of the package in bytes.
|
|
|
|
* hash :: SHA-2 hash of the package.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
query_swdb (estream_t out, const char *name, const char *current_version)
|
|
|
|
{
|
|
|
|
gpg_error_t err;
|
|
|
|
const char *search_name;
|
|
|
|
char *fname = NULL;
|
|
|
|
estream_t fp = NULL;
|
|
|
|
char *line = NULL;
|
|
|
|
char *self_version = NULL;
|
|
|
|
size_t length_of_line = 0;
|
|
|
|
size_t maxlen;
|
|
|
|
ssize_t len;
|
common,agent,dirmngr,g10,tools: Fix split_fields API.
* common/stringhelp.h (split_fields): Use const * for the strings in
the ARRAY.
(split_fields_colon): Likewise.
* common/stringhelp.c (split_fields, split_fields_colon): Fix
the implementation.
* agent/call-scd.c, agent/command.c: Follow the change.
* common/t-stringhelp.c, dirmngr/loadswdb.c: Likewise.
* g10/call-agent.c, tools/card-call-scd.c: Likewise.
* tools/card-yubikey.c, tools/gpg-card.c: Likewise.
* tools/gpg-card.h, tools/gpg-wks-client.c: Likewise.
* tools/gpgconf-comp.c, tools/gpgconf.c: Likewise.
* tools/wks-util.c: Likewise.
--
The strings in the ARRAY don't need to be released by caller, as those
are references. It's easier to follow the code when it's explicitly
const *.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2020-09-18 03:20:23 +02:00
|
|
|
const char *fields[2];
|
2016-11-02 17:54:32 +01:00
|
|
|
char *p;
|
|
|
|
gnupg_isotime_t filedate = {0};
|
|
|
|
gnupg_isotime_t verified = {0};
|
|
|
|
char *value_ver = NULL;
|
|
|
|
gnupg_isotime_t value_date = {0};
|
|
|
|
char *value_size = NULL;
|
|
|
|
char *value_sha2 = NULL;
|
2017-01-23 16:32:44 +01:00
|
|
|
unsigned long value_size_ul = 0;
|
2016-11-02 17:54:32 +01:00
|
|
|
int status, i;
|
|
|
|
|
|
|
|
|
|
|
|
if (!valid_swdb_name_p (name))
|
|
|
|
{
|
|
|
|
log_error ("error in package name '%s': %s\n",
|
|
|
|
name, gpg_strerror (GPG_ERR_INV_NAME));
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
if (!strcmp (name, "gnupg"))
|
2017-08-23 14:50:03 +02:00
|
|
|
search_name = GNUPG_SWDB_TAG;
|
2016-11-02 17:54:32 +01:00
|
|
|
else if (!strcmp (name, "gnupg1"))
|
|
|
|
search_name = "gnupg1";
|
|
|
|
else
|
|
|
|
search_name = name;
|
|
|
|
|
|
|
|
if (!current_version && !strcmp (name, "gnupg"))
|
|
|
|
{
|
|
|
|
/* Use our own version but string a possible beta string. */
|
|
|
|
self_version = xstrdup (PACKAGE_VERSION);
|
|
|
|
p = strchr (self_version, '-');
|
|
|
|
if (p)
|
|
|
|
*p = 0;
|
|
|
|
current_version = self_version;
|
|
|
|
}
|
|
|
|
|
2016-11-03 10:58:19 +01:00
|
|
|
if (current_version && (strchr (current_version, ':')
|
|
|
|
|| compare_version_strings (current_version, NULL)))
|
2016-11-02 17:54:32 +01:00
|
|
|
{
|
|
|
|
log_error ("error in version string '%s': %s\n",
|
|
|
|
current_version, gpg_strerror (GPG_ERR_INV_ARG));
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
|
|
|
fname = make_filename (gnupg_homedir (), "swdb.lst", NULL);
|
|
|
|
fp = es_fopen (fname, "r");
|
|
|
|
if (!fp)
|
|
|
|
{
|
|
|
|
err = gpg_error_from_syserror ();
|
2016-11-03 10:58:19 +01:00
|
|
|
es_fprintf (out, "%s:%s:-::%u:::::::\n",
|
|
|
|
name,
|
|
|
|
current_version? current_version : "",
|
|
|
|
gpg_err_code (err));
|
2016-11-02 17:54:32 +01:00
|
|
|
if (gpg_err_code (err) != GPG_ERR_ENOENT)
|
|
|
|
log_error (_("error opening '%s': %s\n"), fname, gpg_strerror (err));
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
2017-04-28 03:06:33 +02:00
|
|
|
/* Note that the parser uses the first occurrence of a matching
|
2016-11-02 17:54:32 +01:00
|
|
|
* values and ignores possible duplicated values. */
|
|
|
|
|
|
|
|
maxlen = 2048; /* Set limit. */
|
|
|
|
while ((len = es_read_line (fp, &line, &length_of_line, &maxlen)) > 0)
|
|
|
|
{
|
|
|
|
if (!maxlen)
|
|
|
|
{
|
|
|
|
err = gpg_error (GPG_ERR_LINE_TOO_LONG);
|
|
|
|
log_error (_("error reading '%s': %s\n"), fname, gpg_strerror (err));
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
/* Strip newline and carriage return, if present. */
|
|
|
|
while (len > 0 && (line[len - 1] == '\n' || line[len - 1] == '\r'))
|
|
|
|
line[--len] = '\0';
|
|
|
|
|
|
|
|
if (split_fields (line, fields, DIM (fields)) < DIM(fields))
|
|
|
|
continue; /* Skip empty lines and names w/o a value. */
|
|
|
|
if (*fields[0] == '#')
|
|
|
|
continue; /* Skip comments. */
|
|
|
|
|
|
|
|
/* Record the meta data. */
|
|
|
|
if (!*filedate && !strcmp (fields[0], ".filedate"))
|
|
|
|
{
|
|
|
|
string2isotime (filedate, fields[1]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!*verified && !strcmp (fields[0], ".verified"))
|
|
|
|
{
|
|
|
|
string2isotime (verified, fields[1]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Tokenize the name. */
|
|
|
|
p = strrchr (fields[0], '_');
|
|
|
|
if (!p)
|
|
|
|
continue; /* Name w/o an underscore. */
|
|
|
|
*p++ = 0;
|
|
|
|
|
|
|
|
/* Wait for the requested name. */
|
|
|
|
if (!strcmp (fields[0], search_name))
|
|
|
|
{
|
|
|
|
if (!strcmp (p, "ver") && !value_ver)
|
|
|
|
value_ver = xstrdup (fields[1]);
|
|
|
|
else if (!strcmp (p, "date") && !*value_date)
|
|
|
|
string2isotime (value_date, fields[1]);
|
|
|
|
else if (!strcmp (p, "size") && !value_size)
|
|
|
|
value_size = xstrdup (fields[1]);
|
|
|
|
else if (!strcmp (p, "sha2") && !value_sha2)
|
|
|
|
value_sha2 = xstrdup (fields[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (len < 0 || es_ferror (fp))
|
|
|
|
{
|
|
|
|
err = gpg_error_from_syserror ();
|
|
|
|
log_error (_("error reading '%s': %s\n"), fname, gpg_strerror (err));
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*filedate || !*verified)
|
|
|
|
{
|
|
|
|
err = gpg_error (GPG_ERR_INV_TIME);
|
2016-11-03 10:58:19 +01:00
|
|
|
es_fprintf (out, "%s:%s:-::%u:::::::\n",
|
|
|
|
name,
|
|
|
|
current_version? current_version : "",
|
|
|
|
gpg_err_code (err));
|
2016-11-02 17:54:32 +01:00
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!value_ver)
|
|
|
|
{
|
2016-11-03 10:58:19 +01:00
|
|
|
es_fprintf (out, "%s:%s:?:::::::::\n",
|
|
|
|
name,
|
|
|
|
current_version? current_version : "");
|
2016-11-02 17:54:32 +01:00
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value_size)
|
|
|
|
{
|
|
|
|
gpg_err_set_errno (0);
|
|
|
|
value_size_ul = strtoul (value_size, &p, 10);
|
|
|
|
if (errno)
|
|
|
|
value_size_ul = 0;
|
|
|
|
else if (*p == 'k')
|
|
|
|
value_size_ul *= 1024;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
status = '-';
|
|
|
|
if (compare_version_strings (value_ver, NULL))
|
|
|
|
err = gpg_error (GPG_ERR_INV_VALUE);
|
|
|
|
else if (!current_version)
|
|
|
|
;
|
|
|
|
else if (!(i = compare_version_strings (value_ver, current_version)))
|
|
|
|
status = 'c';
|
|
|
|
else if (i > 0)
|
|
|
|
status = 'u';
|
|
|
|
else
|
|
|
|
status = 'n';
|
|
|
|
|
2016-11-03 10:58:19 +01:00
|
|
|
es_fprintf (out, "%s:%s:%c::%d:%s:%s:%s:%s:%lu:%s:\n",
|
2016-11-02 17:54:32 +01:00
|
|
|
name,
|
2016-11-03 10:58:19 +01:00
|
|
|
current_version? current_version : "",
|
2016-11-02 17:54:32 +01:00
|
|
|
status,
|
|
|
|
err,
|
|
|
|
filedate,
|
|
|
|
verified,
|
|
|
|
value_ver,
|
|
|
|
value_date,
|
|
|
|
value_size_ul,
|
|
|
|
value_sha2? value_sha2 : "");
|
|
|
|
|
|
|
|
leave:
|
|
|
|
xfree (value_ver);
|
|
|
|
xfree (value_size);
|
|
|
|
xfree (value_sha2);
|
|
|
|
xfree (line);
|
|
|
|
es_fclose (fp);
|
|
|
|
xfree (fname);
|
|
|
|
xfree (self_version);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-20 03:00:22 +01:00
|
|
|
#if !defined(HAVE_W32_SYSTEM)
|
|
|
|
/* dotlock tool to handle dotlock by command line
|
|
|
|
DO_LOCK: 1 for to lock, 0 for unlock
|
|
|
|
FILENAME: filename for the dotlock */
|
|
|
|
static void
|
|
|
|
dotlock_tool (int do_lock, const char *filename)
|
|
|
|
{
|
|
|
|
dotlock_t h;
|
|
|
|
unsigned int flags = DOTLOCK_LOCK_BY_PARENT;
|
|
|
|
|
|
|
|
if (!do_lock)
|
|
|
|
flags |= DOTLOCK_LOCKED;
|
|
|
|
|
|
|
|
h = dotlock_create (filename, flags);
|
|
|
|
if (!h)
|
|
|
|
{
|
|
|
|
if (do_lock)
|
|
|
|
log_error ("error creating the lock file\n");
|
|
|
|
else
|
|
|
|
log_error ("no lock file found\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_lock)
|
|
|
|
{
|
|
|
|
if (dotlock_take (h, 0))
|
|
|
|
log_error ("error taking the lock\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dotlock_release (h);
|
|
|
|
|
|
|
|
dotlock_destroy (h);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-01-05 10:28:27 +01:00
|
|
|
/* gpgconf main. */
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2017-03-23 11:45:17 +01:00
|
|
|
gpg_error_t err;
|
2020-02-21 20:28:47 +01:00
|
|
|
gpgrt_argparse_t pargs;
|
2004-01-05 10:28:27 +01:00
|
|
|
const char *fname;
|
|
|
|
int no_more_options = 0;
|
|
|
|
enum cmd_and_opt_values cmd = 0;
|
2010-08-18 21:25:15 +02:00
|
|
|
estream_t outfp = NULL;
|
2019-02-25 15:55:13 +01:00
|
|
|
int show_socket = 0;
|
2020-08-06 15:32:43 +02:00
|
|
|
const char *changeuser = NULL;
|
2004-01-05 10:28:27 +01:00
|
|
|
|
2015-01-28 19:57:22 +01:00
|
|
|
early_system_init ();
|
2014-05-07 18:18:27 +02:00
|
|
|
gnupg_reopen_std (GPGCONF_NAME);
|
2020-02-21 20:28:47 +01:00
|
|
|
gpgrt_set_strusage (my_strusage);
|
2022-04-20 09:20:35 +02:00
|
|
|
log_set_prefix (GPGCONF_NAME, GPGRT_LOG_WITH_PREFIX|GPGRT_LOG_NO_REGISTRY);
|
2004-01-05 10:28:27 +01:00
|
|
|
|
2007-06-14 19:05:07 +02:00
|
|
|
/* Make sure that our subsystems are ready. */
|
2004-01-05 10:28:27 +01:00
|
|
|
i18n_init();
|
2010-03-22 13:46:05 +01:00
|
|
|
init_common_subsystems (&argc, &argv);
|
2017-01-10 15:42:27 +01:00
|
|
|
gc_components_init ();
|
2004-01-05 10:28:27 +01:00
|
|
|
|
2004-02-23 21:31:35 +01:00
|
|
|
/* Parse the command line. */
|
2004-01-05 10:28:27 +01:00
|
|
|
pargs.argc = &argc;
|
|
|
|
pargs.argv = &argv;
|
2020-02-21 20:28:47 +01:00
|
|
|
pargs.flags = ARGPARSE_FLAG_KEEP;
|
|
|
|
while (!no_more_options && gpgrt_argparse (NULL, &pargs, opts))
|
2004-01-05 10:28:27 +01:00
|
|
|
{
|
|
|
|
switch (pargs.r_opt)
|
|
|
|
{
|
|
|
|
case oOutput: opt.outfile = pargs.r.ret_str; break;
|
2004-01-29 00:58:18 +01:00
|
|
|
case oQuiet: opt.quiet = 1; break;
|
2004-01-05 10:28:27 +01:00
|
|
|
case oDryRun: opt.dry_run = 1; break;
|
2020-02-21 20:28:47 +01:00
|
|
|
case oRuntime: opt.runtime = 1; break;
|
2004-01-05 10:28:27 +01:00
|
|
|
case oVerbose: opt.verbose++; break;
|
|
|
|
case oNoVerbose: opt.verbose = 0; break;
|
2016-06-08 09:54:09 +02:00
|
|
|
case oHomedir: gnupg_set_homedir (pargs.r.ret_str); break;
|
2016-12-14 14:18:22 +01:00
|
|
|
case oBuilddir: gnupg_set_builddir (pargs.r.ret_str); break;
|
2016-08-04 13:02:37 +02:00
|
|
|
case oNull: opt.null = 1; break;
|
2017-12-18 17:46:05 +01:00
|
|
|
case oStatusFD:
|
2023-06-27 07:44:01 +02:00
|
|
|
set_status_fd (translate_sys2libc_fd_int (pargs.r.ret_int, 1));
|
2017-12-18 17:46:05 +01:00
|
|
|
break;
|
2019-02-25 15:55:13 +01:00
|
|
|
case oShowSocket: show_socket = 1; break;
|
2020-08-06 15:32:43 +02:00
|
|
|
case oChUid: changeuser = pargs.r.ret_str; break;
|
2004-01-05 10:28:27 +01:00
|
|
|
|
2008-05-26 15:43:20 +02:00
|
|
|
case aListDirs:
|
2004-01-29 00:58:18 +01:00
|
|
|
case aListComponents:
|
2007-08-29 11:51:37 +02:00
|
|
|
case aCheckPrograms:
|
2004-01-29 00:58:18 +01:00
|
|
|
case aListOptions:
|
|
|
|
case aChangeOptions:
|
2008-05-20 00:46:41 +02:00
|
|
|
case aCheckOptions:
|
2007-03-06 21:44:41 +01:00
|
|
|
case aApplyDefaults:
|
2016-12-16 16:00:15 +01:00
|
|
|
case aApplyProfile:
|
2007-10-23 20:13:27 +02:00
|
|
|
case aListConfig:
|
2007-03-06 21:44:41 +01:00
|
|
|
case aCheckConfig:
|
2016-11-02 17:54:32 +01:00
|
|
|
case aQuerySWDB:
|
2009-03-03 10:02:58 +01:00
|
|
|
case aReload:
|
2014-04-08 15:55:51 +02:00
|
|
|
case aLaunch:
|
2011-02-23 10:15:34 +01:00
|
|
|
case aKill:
|
2016-06-08 14:04:47 +02:00
|
|
|
case aCreateSocketDir:
|
|
|
|
case aRemoveSocketDir:
|
2020-10-02 12:26:02 +02:00
|
|
|
case aShowVersions:
|
2021-11-04 16:34:26 +01:00
|
|
|
case aShowConfigs:
|
2020-08-25 10:38:29 +02:00
|
|
|
case aShowCodepages:
|
2023-12-20 03:00:22 +01:00
|
|
|
case aDotlockLock:
|
|
|
|
case aDotlockUnlock:
|
2004-01-29 00:58:18 +01:00
|
|
|
cmd = pargs.r_opt;
|
|
|
|
break;
|
|
|
|
|
2004-01-05 10:28:27 +01:00
|
|
|
default: pargs.err = 2; break;
|
|
|
|
}
|
|
|
|
}
|
2004-02-23 21:31:35 +01:00
|
|
|
|
2020-02-21 20:28:47 +01:00
|
|
|
gpgrt_argparse (NULL, &pargs, NULL); /* Release internal state. */
|
|
|
|
|
2004-01-05 10:28:27 +01:00
|
|
|
if (log_get_errorcount (0))
|
2017-12-18 17:46:05 +01:00
|
|
|
gpgconf_failure (GPG_ERR_USER_2);
|
2011-02-23 10:15:34 +01:00
|
|
|
|
2012-03-27 12:35:13 +02:00
|
|
|
/* Print a warning if an argument looks like an option. */
|
|
|
|
if (!opt.quiet && !(pargs.flags & ARGPARSE_FLAG_STOP_SEEN))
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i < argc; i++)
|
|
|
|
if (argv[i][0] == '-' && argv[i][1] == '-')
|
2014-10-10 15:29:42 +02:00
|
|
|
log_info (_("Note: '%s' is not considered an option\n"), argv[i]);
|
2012-03-27 12:35:13 +02:00
|
|
|
}
|
|
|
|
|
2004-01-29 00:58:18 +01:00
|
|
|
fname = argc ? *argv : NULL;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
2020-08-06 15:32:43 +02:00
|
|
|
/* If requested switch to the requested user or die. */
|
|
|
|
if (changeuser && (err = gnupg_chuid (changeuser, 0)))
|
|
|
|
gpgconf_failure (err);
|
|
|
|
|
2024-05-13 00:09:23 +02:00
|
|
|
/* Set the configuration directories for use by gpgrt_argparser. We
|
2020-03-05 16:23:52 +01:00
|
|
|
* don't have a configuration file for this program but we have code
|
|
|
|
* which reads the component's config files. */
|
|
|
|
gpgrt_set_confdir (GPGRT_CONFDIR_SYS, gnupg_sysconfdir ());
|
|
|
|
gpgrt_set_confdir (GPGRT_CONFDIR_USER, gnupg_homedir ());
|
|
|
|
|
2004-01-05 10:28:27 +01:00
|
|
|
switch (cmd)
|
|
|
|
{
|
2004-01-29 00:58:18 +01:00
|
|
|
case aListComponents:
|
2004-01-05 10:28:27 +01:00
|
|
|
default:
|
2004-01-29 00:58:18 +01:00
|
|
|
/* List all components. */
|
2007-10-23 20:13:27 +02:00
|
|
|
gc_component_list_components (get_outfp (&outfp));
|
2004-01-05 10:28:27 +01:00
|
|
|
break;
|
2004-01-29 00:58:18 +01:00
|
|
|
|
2007-08-29 11:51:37 +02:00
|
|
|
case aCheckPrograms:
|
|
|
|
/* Check all programs. */
|
2008-05-20 00:46:41 +02:00
|
|
|
gc_check_programs (get_outfp (&outfp));
|
2007-08-29 11:51:37 +02:00
|
|
|
break;
|
|
|
|
|
2004-01-29 00:58:18 +01:00
|
|
|
case aListOptions:
|
|
|
|
case aChangeOptions:
|
2008-05-20 00:46:41 +02:00
|
|
|
case aCheckOptions:
|
2004-01-29 00:58:18 +01:00
|
|
|
if (!fname)
|
|
|
|
{
|
2014-05-07 18:18:27 +02:00
|
|
|
es_fprintf (es_stderr, _("usage: %s [options] "), GPGCONF_NAME);
|
2010-08-18 21:25:15 +02:00
|
|
|
es_putc ('\n', es_stderr);
|
|
|
|
es_fputs (_("Need one component argument"), es_stderr);
|
|
|
|
es_putc ('\n', es_stderr);
|
2017-12-18 17:46:05 +01:00
|
|
|
gpgconf_failure (GPG_ERR_USER_2);
|
2004-01-29 00:58:18 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int idx = gc_component_find (fname);
|
|
|
|
if (idx < 0)
|
|
|
|
{
|
2010-08-18 21:25:15 +02:00
|
|
|
es_fputs (_("Component not found"), es_stderr);
|
|
|
|
es_putc ('\n', es_stderr);
|
2017-12-18 17:46:05 +01:00
|
|
|
gpgconf_failure (0);
|
2004-01-29 00:58:18 +01:00
|
|
|
}
|
2010-08-20 14:18:38 +02:00
|
|
|
if (cmd == aCheckOptions)
|
2008-05-20 00:46:41 +02:00
|
|
|
gc_component_check_options (idx, get_outfp (&outfp), NULL);
|
2010-08-20 14:18:38 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
gc_component_retrieve_options (idx);
|
|
|
|
if (gc_process_gpgconf_conf (NULL, 1, 0, NULL))
|
2017-12-18 17:46:05 +01:00
|
|
|
gpgconf_failure (0);
|
2010-08-20 14:18:38 +02:00
|
|
|
if (cmd == aListOptions)
|
|
|
|
gc_component_list_options (idx, get_outfp (&outfp));
|
|
|
|
else if (cmd == aChangeOptions)
|
2016-12-16 16:00:15 +01:00
|
|
|
gc_component_change_options (idx, es_stdin,
|
|
|
|
get_outfp (&outfp), 0);
|
2010-08-20 14:18:38 +02:00
|
|
|
}
|
2004-01-29 00:58:18 +01:00
|
|
|
}
|
2007-03-06 21:44:41 +01:00
|
|
|
break;
|
|
|
|
|
2014-04-08 15:55:51 +02:00
|
|
|
case aLaunch:
|
2011-02-23 10:15:34 +01:00
|
|
|
case aKill:
|
|
|
|
if (!fname)
|
|
|
|
{
|
2014-05-07 18:18:27 +02:00
|
|
|
es_fprintf (es_stderr, _("usage: %s [options] "), GPGCONF_NAME);
|
2011-02-23 10:15:34 +01:00
|
|
|
es_putc ('\n', es_stderr);
|
|
|
|
es_fputs (_("Need one component argument"), es_stderr);
|
|
|
|
es_putc ('\n', es_stderr);
|
2017-12-18 17:46:05 +01:00
|
|
|
gpgconf_failure (GPG_ERR_USER_2);
|
2011-02-23 10:15:34 +01:00
|
|
|
}
|
2017-01-18 10:01:55 +01:00
|
|
|
else if (!strcmp (fname, "all"))
|
|
|
|
{
|
|
|
|
if (cmd == aLaunch)
|
|
|
|
{
|
|
|
|
if (gc_component_launch (-1))
|
2017-12-18 17:46:05 +01:00
|
|
|
gpgconf_failure (0);
|
2017-01-18 10:01:55 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gc_component_kill (-1);
|
|
|
|
}
|
|
|
|
}
|
2011-02-23 10:15:34 +01:00
|
|
|
else
|
|
|
|
{
|
2014-04-08 15:55:51 +02:00
|
|
|
/* Launch/Kill a given component. */
|
2011-02-23 10:15:34 +01:00
|
|
|
int idx;
|
|
|
|
|
|
|
|
idx = gc_component_find (fname);
|
|
|
|
if (idx < 0)
|
|
|
|
{
|
|
|
|
es_fputs (_("Component not found"), es_stderr);
|
|
|
|
es_putc ('\n', es_stderr);
|
2017-12-18 17:46:05 +01:00
|
|
|
gpgconf_failure (0);
|
2011-02-23 10:15:34 +01:00
|
|
|
}
|
2014-04-08 15:55:51 +02:00
|
|
|
else if (cmd == aLaunch)
|
2014-12-17 10:36:24 +01:00
|
|
|
{
|
2019-02-25 15:55:13 +01:00
|
|
|
err = gc_component_launch (idx);
|
|
|
|
if (show_socket)
|
|
|
|
{
|
|
|
|
char *names[2];
|
|
|
|
|
|
|
|
if (idx == GC_COMPONENT_GPG_AGENT)
|
|
|
|
names[0] = "agent-socket";
|
|
|
|
else if (idx == GC_COMPONENT_DIRMNGR)
|
|
|
|
names[0] = "dirmngr-socket";
|
2020-09-23 12:02:50 +02:00
|
|
|
else if (idx == GC_COMPONENT_KEYBOXD)
|
|
|
|
names[0] = "keyboxd-socket";
|
2019-02-25 15:55:13 +01:00
|
|
|
else
|
|
|
|
names[0] = NULL;
|
|
|
|
names[1] = NULL;
|
|
|
|
get_outfp (&outfp);
|
2021-11-19 09:29:37 +01:00
|
|
|
list_dirs (outfp, names, 0);
|
2019-02-25 15:55:13 +01:00
|
|
|
}
|
|
|
|
if (err)
|
2017-12-18 17:46:05 +01:00
|
|
|
gpgconf_failure (0);
|
2014-12-17 10:36:24 +01:00
|
|
|
}
|
2011-02-23 10:15:34 +01:00
|
|
|
else
|
2014-12-17 10:36:24 +01:00
|
|
|
{
|
|
|
|
/* We don't error out if the kill failed because this
|
|
|
|
command should do nothing if the component is not
|
|
|
|
running. */
|
|
|
|
gc_component_kill (idx);
|
|
|
|
}
|
2011-02-23 10:15:34 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-03-03 10:02:58 +01:00
|
|
|
case aReload:
|
2017-01-18 10:01:55 +01:00
|
|
|
if (!fname || !strcmp (fname, "all"))
|
2009-03-03 10:02:58 +01:00
|
|
|
{
|
|
|
|
/* Reload all. */
|
|
|
|
gc_component_reload (-1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Reload given component. */
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
idx = gc_component_find (fname);
|
|
|
|
if (idx < 0)
|
|
|
|
{
|
2010-08-18 21:25:15 +02:00
|
|
|
es_fputs (_("Component not found"), es_stderr);
|
|
|
|
es_putc ('\n', es_stderr);
|
2017-12-18 17:46:05 +01:00
|
|
|
gpgconf_failure (0);
|
2009-03-03 10:02:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gc_component_reload (idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-10-23 20:13:27 +02:00
|
|
|
case aListConfig:
|
|
|
|
if (gc_process_gpgconf_conf (fname, 0, 0, get_outfp (&outfp)))
|
2017-12-18 17:46:05 +01:00
|
|
|
gpgconf_failure (0);
|
2007-10-23 20:13:27 +02:00
|
|
|
break;
|
|
|
|
|
2007-03-06 21:44:41 +01:00
|
|
|
case aCheckConfig:
|
2007-10-23 20:13:27 +02:00
|
|
|
if (gc_process_gpgconf_conf (fname, 0, 0, NULL))
|
2017-12-18 17:46:05 +01:00
|
|
|
gpgconf_failure (0);
|
2007-03-06 21:44:41 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case aApplyDefaults:
|
|
|
|
if (fname)
|
|
|
|
{
|
2014-05-07 18:18:27 +02:00
|
|
|
es_fprintf (es_stderr, _("usage: %s [options] "), GPGCONF_NAME);
|
2010-08-18 21:25:15 +02:00
|
|
|
es_putc ('\n', es_stderr);
|
|
|
|
es_fputs (_("No argument allowed"), es_stderr);
|
|
|
|
es_putc ('\n', es_stderr);
|
2017-12-18 17:46:05 +01:00
|
|
|
gpgconf_failure (GPG_ERR_USER_2);
|
2007-03-06 21:44:41 +01:00
|
|
|
}
|
2020-11-12 13:09:32 +01:00
|
|
|
if (!opt.dry_run && gnupg_access (gnupg_homedir (), F_OK))
|
|
|
|
gnupg_maybe_make_homedir (gnupg_homedir (), opt.quiet);
|
2007-03-06 21:44:41 +01:00
|
|
|
gc_component_retrieve_options (-1);
|
2007-10-23 20:13:27 +02:00
|
|
|
if (gc_process_gpgconf_conf (NULL, 1, 1, NULL))
|
2017-12-18 17:46:05 +01:00
|
|
|
gpgconf_failure (0);
|
2007-03-06 21:44:41 +01:00
|
|
|
break;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
2016-12-16 16:00:15 +01:00
|
|
|
case aApplyProfile:
|
2020-11-12 13:09:32 +01:00
|
|
|
if (!opt.dry_run && gnupg_access (gnupg_homedir (), F_OK))
|
|
|
|
gnupg_maybe_make_homedir (gnupg_homedir (), opt.quiet);
|
2016-12-16 16:00:15 +01:00
|
|
|
gc_component_retrieve_options (-1);
|
|
|
|
if (gc_apply_profile (fname))
|
2017-12-18 17:46:05 +01:00
|
|
|
gpgconf_failure (0);
|
2016-12-16 16:00:15 +01:00
|
|
|
break;
|
|
|
|
|
2008-05-26 15:43:20 +02:00
|
|
|
case aListDirs:
|
2009-01-20 20:24:24 +01:00
|
|
|
/* Show the system configuration directories for gpgconf. */
|
2008-05-26 15:43:20 +02:00
|
|
|
get_outfp (&outfp);
|
2021-11-19 09:29:37 +01:00
|
|
|
list_dirs (outfp, argc? argv : NULL, 0);
|
2008-05-26 15:43:20 +02:00
|
|
|
break;
|
2016-06-08 14:04:47 +02:00
|
|
|
|
2016-11-02 17:54:32 +01:00
|
|
|
case aQuerySWDB:
|
|
|
|
/* Query the software version database. */
|
|
|
|
if (!fname || argc > 2)
|
|
|
|
{
|
|
|
|
es_fprintf (es_stderr, "usage: %s --query-swdb NAME [VERSION]\n",
|
|
|
|
GPGCONF_NAME);
|
2017-12-18 17:46:05 +01:00
|
|
|
gpgconf_failure (GPG_ERR_USER_2);
|
2016-11-02 17:54:32 +01:00
|
|
|
}
|
|
|
|
get_outfp (&outfp);
|
|
|
|
query_swdb (outfp, fname, argc > 1? argv[1] : NULL);
|
|
|
|
break;
|
|
|
|
|
2016-06-08 14:04:47 +02:00
|
|
|
case aCreateSocketDir:
|
|
|
|
{
|
|
|
|
char *socketdir;
|
|
|
|
unsigned int flags;
|
|
|
|
|
|
|
|
/* Make sure that the top /run/user/UID/gnupg dir has been
|
|
|
|
* created. */
|
|
|
|
gnupg_socketdir ();
|
|
|
|
|
|
|
|
/* Check the /var/run dir. */
|
|
|
|
socketdir = _gnupg_socketdir_internal (1, &flags);
|
|
|
|
if ((flags & 64) && !opt.dry_run)
|
|
|
|
{
|
|
|
|
/* No sub dir - create it. */
|
|
|
|
if (gnupg_mkdir (socketdir, "-rwx"))
|
|
|
|
gc_error (1, errno, "error creating '%s'", socketdir);
|
|
|
|
/* Try again. */
|
2016-12-08 13:02:37 +01:00
|
|
|
xfree (socketdir);
|
2016-06-08 14:04:47 +02:00
|
|
|
socketdir = _gnupg_socketdir_internal (1, &flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Give some info. */
|
|
|
|
if ( (flags & ~32) || opt.verbose || opt.dry_run)
|
|
|
|
{
|
|
|
|
log_info ("socketdir is '%s'\n", socketdir);
|
|
|
|
if ((flags & 1)) log_info ("\tgeneral error\n");
|
|
|
|
if ((flags & 2)) log_info ("\tno /run/user dir\n");
|
|
|
|
if ((flags & 4)) log_info ("\tbad permissions\n");
|
|
|
|
if ((flags & 8)) log_info ("\tbad permissions (subdir)\n");
|
|
|
|
if ((flags & 16)) log_info ("\tmkdir failed\n");
|
|
|
|
if ((flags & 32)) log_info ("\tnon-default homedir\n");
|
|
|
|
if ((flags & 64)) log_info ("\tno such subdir\n");
|
|
|
|
if ((flags & 128)) log_info ("\tusing homedir as fallback\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((flags & ~32) && !opt.dry_run)
|
|
|
|
gc_error (1, 0, "error creating socket directory");
|
|
|
|
|
|
|
|
xfree (socketdir);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case aRemoveSocketDir:
|
|
|
|
{
|
|
|
|
char *socketdir;
|
|
|
|
unsigned int flags;
|
|
|
|
|
|
|
|
/* Check the /var/run dir. */
|
|
|
|
socketdir = _gnupg_socketdir_internal (1, &flags);
|
|
|
|
if ((flags & 128))
|
|
|
|
log_info ("ignoring request to remove non /run/user socket dir\n");
|
|
|
|
else if (opt.dry_run)
|
|
|
|
;
|
2021-08-11 11:50:41 +02:00
|
|
|
else if (gnupg_rmdir (socketdir))
|
2017-03-23 11:45:17 +01:00
|
|
|
{
|
2018-10-24 21:56:18 +02:00
|
|
|
/* If the director is not empty we first try to delete
|
2017-03-23 11:45:17 +01:00
|
|
|
* socket files. */
|
|
|
|
err = gpg_error_from_syserror ();
|
|
|
|
if (gpg_err_code (err) == GPG_ERR_ENOTEMPTY
|
|
|
|
|| gpg_err_code (err) == GPG_ERR_EEXIST)
|
|
|
|
{
|
|
|
|
static const char * const names[] = {
|
|
|
|
GPG_AGENT_SOCK_NAME,
|
|
|
|
GPG_AGENT_EXTRA_SOCK_NAME,
|
|
|
|
GPG_AGENT_BROWSER_SOCK_NAME,
|
|
|
|
GPG_AGENT_SSH_SOCK_NAME,
|
|
|
|
SCDAEMON_SOCK_NAME,
|
2020-09-23 12:02:50 +02:00
|
|
|
KEYBOXD_SOCK_NAME,
|
2023-10-03 09:51:46 +02:00
|
|
|
DIRMNGR_SOCK_NAME,
|
|
|
|
TPM2DAEMON_SOCK_NAME
|
2017-03-23 11:45:17 +01:00
|
|
|
};
|
|
|
|
int i;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
for (i=0; i < DIM(names); i++)
|
|
|
|
{
|
|
|
|
p = strconcat (socketdir , "/", names[i], NULL);
|
|
|
|
if (p)
|
|
|
|
gnupg_remove (p);
|
|
|
|
xfree (p);
|
|
|
|
}
|
2021-08-11 11:50:41 +02:00
|
|
|
if (gnupg_rmdir (socketdir))
|
2023-10-03 09:51:46 +02:00
|
|
|
{
|
|
|
|
err = gpg_error_from_syserror ();
|
|
|
|
gc_error (1, 0, "error removing '%s': %s",
|
|
|
|
socketdir, gpg_strerror (err));
|
|
|
|
}
|
2017-03-23 11:45:17 +01:00
|
|
|
}
|
|
|
|
else if (gpg_err_code (err) == GPG_ERR_ENOENT)
|
|
|
|
gc_error (0, 0, "warning: removing '%s' failed: %s",
|
|
|
|
socketdir, gpg_strerror (err));
|
|
|
|
else
|
|
|
|
gc_error (1, 0, "error removing '%s': %s",
|
|
|
|
socketdir, gpg_strerror (err));
|
|
|
|
}
|
2016-06-08 14:04:47 +02:00
|
|
|
|
|
|
|
xfree (socketdir);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-10-02 12:26:02 +02:00
|
|
|
case aShowVersions:
|
|
|
|
{
|
|
|
|
get_outfp (&outfp);
|
|
|
|
show_versions (outfp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-11-04 16:34:26 +01:00
|
|
|
case aShowConfigs:
|
|
|
|
{
|
|
|
|
get_outfp (&outfp);
|
|
|
|
show_configs (outfp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-08-25 10:38:29 +02:00
|
|
|
case aShowCodepages:
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
{
|
|
|
|
get_outfp (&outfp);
|
2021-03-05 15:33:40 +01:00
|
|
|
if (GetConsoleCP () != GetConsoleOutputCP ())
|
|
|
|
es_fprintf (outfp, "Console: CP%u/CP%u\n",
|
|
|
|
GetConsoleCP (), GetConsoleOutputCP ());
|
|
|
|
else
|
|
|
|
es_fprintf (outfp, "Console: CP%u\n", GetConsoleCP ());
|
2020-08-25 10:38:29 +02:00
|
|
|
es_fprintf (outfp, "ANSI: CP%u\n", GetACP ());
|
|
|
|
es_fprintf (outfp, "OEM: CP%u\n", GetOEMCP ());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2023-12-20 03:00:22 +01:00
|
|
|
case aDotlockLock:
|
|
|
|
case aDotlockUnlock:
|
|
|
|
#if !defined(HAVE_W32_SYSTEM)
|
|
|
|
if (!fname)
|
|
|
|
{
|
2024-01-11 15:28:33 +01:00
|
|
|
es_fprintf (es_stderr, "usage: %s --%slock NAME",
|
|
|
|
GPGCONF_NAME, cmd==aDotlockUnlock?"un":"");
|
2023-12-20 03:00:22 +01:00
|
|
|
es_putc ('\n', es_stderr);
|
2024-01-11 15:28:33 +01:00
|
|
|
es_fputs ("Need name of file protected by the lock", es_stderr);
|
2023-12-20 03:00:22 +01:00
|
|
|
es_putc ('\n', es_stderr);
|
2024-01-11 15:28:33 +01:00
|
|
|
gpgconf_failure (GPG_ERR_SYNTAX);
|
2023-12-20 03:00:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
|
|
|
|
/* Keybox pubring.db lock is under public-keys.d. */
|
|
|
|
if (!strcmp (fname, "pubring.db"))
|
|
|
|
fname = "public-keys.d/pubring.db";
|
2020-08-25 10:38:29 +02:00
|
|
|
|
2023-12-20 03:00:22 +01:00
|
|
|
filename = make_absfilename (gnupg_homedir (), fname, NULL);
|
|
|
|
dotlock_tool (cmd == aDotlockLock, filename);
|
|
|
|
xfree (filename);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
2004-01-05 10:28:27 +01:00
|
|
|
}
|
|
|
|
|
2010-08-18 21:25:15 +02:00
|
|
|
if (outfp != es_stdout)
|
|
|
|
if (es_fclose (outfp))
|
2012-06-05 19:29:22 +02:00
|
|
|
gc_error (1, errno, "error closing '%s'", opt.outfile);
|
2004-01-05 10:28:27 +01:00
|
|
|
|
2017-12-18 17:46:05 +01:00
|
|
|
|
|
|
|
if (log_get_errorcount (0))
|
|
|
|
gpgconf_failure (0);
|
|
|
|
else
|
|
|
|
gpgconf_write_status (STATUS_SUCCESS, NULL);
|
2011-02-23 10:15:34 +01:00
|
|
|
return 0;
|
2007-10-23 20:13:27 +02:00
|
|
|
}
|
2017-12-18 17:46:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
gpgconf_failure (gpg_error_t err)
|
|
|
|
{
|
2019-05-16 12:24:08 +02:00
|
|
|
log_flush ();
|
2017-12-18 17:46:05 +01:00
|
|
|
if (!err)
|
|
|
|
err = gpg_error (GPG_ERR_GENERAL);
|
|
|
|
gpgconf_write_status
|
|
|
|
(STATUS_FAILURE, "- %u",
|
|
|
|
gpg_err_code (err) == GPG_ERR_USER_2? GPG_ERR_EINVAL : err);
|
|
|
|
exit (gpg_err_code (err) == GPG_ERR_USER_2? 2 : 1);
|
|
|
|
}
|
2020-10-02 12:26:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Parse the revision part from the extended version blurb. */
|
|
|
|
static const char *
|
|
|
|
get_revision_from_blurb (const char *blurb, int *r_len)
|
|
|
|
{
|
|
|
|
const char *s = blurb? blurb : "";
|
|
|
|
int n;
|
|
|
|
|
|
|
|
for (; *s; s++)
|
|
|
|
if (*s == '\n' && s[1] == '(')
|
|
|
|
break;
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
s += 2;
|
|
|
|
for (n=0; s[n] && s[n] != ' '; n++)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s = "?";
|
|
|
|
n = 1;
|
|
|
|
}
|
|
|
|
*r_len = n;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2021-11-04 16:34:26 +01:00
|
|
|
show_version_gnupg (estream_t fp, const char *prefix)
|
2020-10-02 12:26:02 +02:00
|
|
|
{
|
2024-01-09 12:51:34 +01:00
|
|
|
char *fname, *p, *p0;
|
2022-06-29 13:14:35 +02:00
|
|
|
size_t n;
|
|
|
|
estream_t verfp;
|
2024-01-09 12:51:34 +01:00
|
|
|
char *line = NULL;
|
|
|
|
size_t line_len = 0;
|
|
|
|
ssize_t length;
|
2022-06-29 13:14:35 +02:00
|
|
|
|
2021-11-04 16:34:26 +01:00
|
|
|
es_fprintf (fp, "%s%sGnuPG %s (%s)\n%s%s\n", prefix, *prefix?"":"* ",
|
2024-07-04 17:17:13 +02:00
|
|
|
gpgrt_strusage (13), BUILD_COMMITID, prefix, gpgrt_strusage (17));
|
2022-06-29 13:14:35 +02:00
|
|
|
|
|
|
|
/* Show the GnuPG VS-Desktop version in --show-configs mode */
|
2024-04-04 15:09:12 +02:00
|
|
|
if (prefix && *prefix)
|
2022-06-29 13:14:35 +02:00
|
|
|
{
|
|
|
|
fname = make_filename (gnupg_bindir (), NULL);
|
|
|
|
n = strlen (fname);
|
|
|
|
if (n > 10 && (!ascii_strcasecmp (fname + n - 10, "/GnuPG/bin")
|
|
|
|
|| !ascii_strcasecmp (fname + n - 10, "\\GnuPG\\bin")))
|
|
|
|
{
|
2024-04-04 15:09:12 +02:00
|
|
|
/* Append VERSION to the ../../ directory. Note that VERSION
|
2022-06-29 13:14:35 +02:00
|
|
|
* is only 7 bytes and thus fits. */
|
|
|
|
strcpy (fname + n - 9, "VERSION");
|
|
|
|
verfp = es_fopen (fname, "r");
|
|
|
|
if (!verfp)
|
|
|
|
es_fprintf (fp, "%s[VERSION file not found]\n", prefix);
|
|
|
|
else
|
|
|
|
{
|
2024-01-09 12:51:34 +01:00
|
|
|
int lnr = 0;
|
|
|
|
|
|
|
|
p0 = NULL;
|
|
|
|
while ((length = es_read_line (verfp, &line, &line_len, NULL))>0)
|
|
|
|
{
|
|
|
|
lnr++;
|
|
|
|
trim_spaces (line);
|
|
|
|
if (lnr == 1 && *line != '[')
|
|
|
|
{
|
|
|
|
/* Old file format where we look only at the
|
|
|
|
* first line. */
|
|
|
|
p0 = line;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (!strncmp (line, "version=", 8))
|
|
|
|
{
|
|
|
|
p0 = line + 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (length < 0 || es_ferror (verfp))
|
|
|
|
es_fprintf (fp, "%s[VERSION file read error]\n", prefix);
|
|
|
|
else if (p0)
|
|
|
|
{
|
|
|
|
for (p=p0; *p; p++)
|
|
|
|
if (*p < ' ' || *p > '~' || *p == '[')
|
|
|
|
*p = '?';
|
|
|
|
es_fprintf (fp, "%s%s\n", prefix, p0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
es_fprintf (fp, "%s[VERSION file is empty]\n", prefix);
|
|
|
|
|
|
|
|
es_fclose (verfp);
|
2022-06-29 13:14:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
xfree (fname);
|
|
|
|
}
|
2024-01-09 12:51:34 +01:00
|
|
|
xfree (line);
|
2022-06-29 13:14:35 +02:00
|
|
|
|
2020-10-02 12:26:02 +02:00
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
{
|
|
|
|
OSVERSIONINFO osvi = { sizeof (osvi) };
|
|
|
|
|
|
|
|
GetVersionEx (&osvi);
|
2021-11-04 16:34:26 +01:00
|
|
|
es_fprintf (fp, "%sWindows %lu.%lu build %lu%s%s%s\n",
|
|
|
|
prefix,
|
2020-10-02 12:26:02 +02:00
|
|
|
(unsigned long)osvi.dwMajorVersion,
|
|
|
|
(unsigned long)osvi.dwMinorVersion,
|
|
|
|
(unsigned long)osvi.dwBuildNumber,
|
|
|
|
*osvi.szCSDVersion? " (":"",
|
|
|
|
osvi.szCSDVersion,
|
|
|
|
*osvi.szCSDVersion? ")":""
|
|
|
|
);
|
|
|
|
}
|
|
|
|
#endif /*HAVE_W32_SYSTEM*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_version_libgcrypt (estream_t fp)
|
|
|
|
{
|
|
|
|
const char *s;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
s = get_revision_from_blurb (gcry_check_version ("\x01\x01"), &n);
|
|
|
|
es_fprintf (fp, "* Libgcrypt %s (%.*s)\n",
|
|
|
|
gcry_check_version (NULL), n, s);
|
|
|
|
s = gcry_get_config (0, NULL);
|
|
|
|
if (s)
|
|
|
|
es_fputs (s, fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_version_gpgrt (estream_t fp)
|
|
|
|
{
|
|
|
|
const char *s;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
s = get_revision_from_blurb (gpg_error_check_version ("\x01\x01"), &n);
|
|
|
|
es_fprintf (fp, "* GpgRT %s (%.*s)\n",
|
|
|
|
gpg_error_check_version (NULL), n, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Printing version information for other libraries is problematic
|
|
|
|
* because we don't want to link gpgconf to all these libraries. The
|
|
|
|
* best solution is delegating this to dirmngr which uses libassuan,
|
|
|
|
* libksba, libnpth and ntbtls anyway. */
|
|
|
|
static void
|
|
|
|
show_versions_via_dirmngr (estream_t fp)
|
|
|
|
{
|
|
|
|
gpg_error_t err;
|
|
|
|
const char *pgmname;
|
|
|
|
const char *argv[2];
|
|
|
|
estream_t outfp;
|
Use gpgrt_process_spawn API from libgpg-error.
* agent/genkey.c (do_check_passphrase_pattern): Use the gpgrt API.
* common/asshelp.c (start_new_service): Ditto.
* common/exechelp.h: Remove gnupg_process_spawn API.
* common/exechelp-posix.c: Remove gnupg_process_spawn implementation.
* common/exechelp-w32.c: Likewise.
* common/exectool.c (gnupg_exec_tool_stream): Use the gpgrt API.
* common/t-exechelp.c (test_pipe_stream): Remove.
* dirmngr/ldap-wrapper.c (destroy_wrapper, ldap_reaper_thread): Use
the gpgrt API.
(ldap_wrapper_connection_cleanup, ldap_wrapper): Ditto.
* dirmngr/ldap.c, g10/call-keyboxd.c: No need to include exechelp.h.
* g10/photoid.c (run_with_pipe, show_photo): Use the gpgrt API.
* g13/be-encfs.c (run_umount_helper, run_encfs_tool): Ditto.
* g13/g13.c, g13/mount.c, g13/runner.c: No need to include exechelp.h.
* scd/apdu.c: No need to include exechelp.h.
* scd/app.c (report_change): Use the gpgrt API.
* sm/export.c, sm/import.c: No need to include exechelp.h.
* tests/gpgscm/ffi.c (proc_object_finalize, proc_wrap)
(do_process_spawn_io, do_process_spawn_fd, do_process_wait): Use the
gpgrt API.
* tools/gpg-auth.c: No need to include exechelp.h.
* tools/gpg-card.c (cmd_gpg): Use the gpgrt API.
* tools/gpg-connect-agent.c: No need to include exechelp.h.
* tools/gpg-mail-tube.c (mail_tube_encrypt, prepare_for_appimage)
(start_gpg_encrypt): Use the gpgrt API.
* tools/gpgconf-comp.c (gpg_agent_runtime_change)
(scdaemon_runtime_change, tpm2daemon_runtime_change)
(dirmngr_runtime_change, keyboxd_runtime_change)
(gc_component_launch, gc_component_check_options)
(retrieve_options_from_program): Ditto.
* tools/gpgconf.c (show_versions_via_dirmngr): Ditto.
* tools/gpgtar-create.c (gpgtar_create): Ditto.
* tools/gpgtar-extract.c (gpgtar_extract): Ditto.
* tools/gpgtar-list.c (gpgtar_list): Ditto.
--
GnuPG-bug-id: 7192
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2024-07-09 02:39:15 +02:00
|
|
|
gpgrt_process_t proc;
|
2020-10-02 12:26:02 +02:00
|
|
|
char *line = NULL;
|
|
|
|
size_t line_len = 0;
|
|
|
|
ssize_t length;
|
|
|
|
|
|
|
|
pgmname = gnupg_module_name (GNUPG_MODULE_NAME_DIRMNGR);
|
|
|
|
argv[0] = "--gpgconf-versions";
|
|
|
|
argv[1] = NULL;
|
Use gpgrt_process_spawn API from libgpg-error.
* agent/genkey.c (do_check_passphrase_pattern): Use the gpgrt API.
* common/asshelp.c (start_new_service): Ditto.
* common/exechelp.h: Remove gnupg_process_spawn API.
* common/exechelp-posix.c: Remove gnupg_process_spawn implementation.
* common/exechelp-w32.c: Likewise.
* common/exectool.c (gnupg_exec_tool_stream): Use the gpgrt API.
* common/t-exechelp.c (test_pipe_stream): Remove.
* dirmngr/ldap-wrapper.c (destroy_wrapper, ldap_reaper_thread): Use
the gpgrt API.
(ldap_wrapper_connection_cleanup, ldap_wrapper): Ditto.
* dirmngr/ldap.c, g10/call-keyboxd.c: No need to include exechelp.h.
* g10/photoid.c (run_with_pipe, show_photo): Use the gpgrt API.
* g13/be-encfs.c (run_umount_helper, run_encfs_tool): Ditto.
* g13/g13.c, g13/mount.c, g13/runner.c: No need to include exechelp.h.
* scd/apdu.c: No need to include exechelp.h.
* scd/app.c (report_change): Use the gpgrt API.
* sm/export.c, sm/import.c: No need to include exechelp.h.
* tests/gpgscm/ffi.c (proc_object_finalize, proc_wrap)
(do_process_spawn_io, do_process_spawn_fd, do_process_wait): Use the
gpgrt API.
* tools/gpg-auth.c: No need to include exechelp.h.
* tools/gpg-card.c (cmd_gpg): Use the gpgrt API.
* tools/gpg-connect-agent.c: No need to include exechelp.h.
* tools/gpg-mail-tube.c (mail_tube_encrypt, prepare_for_appimage)
(start_gpg_encrypt): Use the gpgrt API.
* tools/gpgconf-comp.c (gpg_agent_runtime_change)
(scdaemon_runtime_change, tpm2daemon_runtime_change)
(dirmngr_runtime_change, keyboxd_runtime_change)
(gc_component_launch, gc_component_check_options)
(retrieve_options_from_program): Ditto.
* tools/gpgconf.c (show_versions_via_dirmngr): Ditto.
* tools/gpgtar-create.c (gpgtar_create): Ditto.
* tools/gpgtar-extract.c (gpgtar_extract): Ditto.
* tools/gpgtar-list.c (gpgtar_list): Ditto.
--
GnuPG-bug-id: 7192
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2024-07-09 02:39:15 +02:00
|
|
|
err = gpgrt_process_spawn (pgmname, argv, GPGRT_PROCESS_STDOUT_PIPE,
|
2024-05-31 08:36:39 +02:00
|
|
|
NULL, &proc);
|
2020-10-02 12:26:02 +02:00
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
log_error ("error spawning %s: %s", pgmname, gpg_strerror (err));
|
|
|
|
es_fprintf (fp, "[error: can't get further info]\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Use gpgrt_process_spawn API from libgpg-error.
* agent/genkey.c (do_check_passphrase_pattern): Use the gpgrt API.
* common/asshelp.c (start_new_service): Ditto.
* common/exechelp.h: Remove gnupg_process_spawn API.
* common/exechelp-posix.c: Remove gnupg_process_spawn implementation.
* common/exechelp-w32.c: Likewise.
* common/exectool.c (gnupg_exec_tool_stream): Use the gpgrt API.
* common/t-exechelp.c (test_pipe_stream): Remove.
* dirmngr/ldap-wrapper.c (destroy_wrapper, ldap_reaper_thread): Use
the gpgrt API.
(ldap_wrapper_connection_cleanup, ldap_wrapper): Ditto.
* dirmngr/ldap.c, g10/call-keyboxd.c: No need to include exechelp.h.
* g10/photoid.c (run_with_pipe, show_photo): Use the gpgrt API.
* g13/be-encfs.c (run_umount_helper, run_encfs_tool): Ditto.
* g13/g13.c, g13/mount.c, g13/runner.c: No need to include exechelp.h.
* scd/apdu.c: No need to include exechelp.h.
* scd/app.c (report_change): Use the gpgrt API.
* sm/export.c, sm/import.c: No need to include exechelp.h.
* tests/gpgscm/ffi.c (proc_object_finalize, proc_wrap)
(do_process_spawn_io, do_process_spawn_fd, do_process_wait): Use the
gpgrt API.
* tools/gpg-auth.c: No need to include exechelp.h.
* tools/gpg-card.c (cmd_gpg): Use the gpgrt API.
* tools/gpg-connect-agent.c: No need to include exechelp.h.
* tools/gpg-mail-tube.c (mail_tube_encrypt, prepare_for_appimage)
(start_gpg_encrypt): Use the gpgrt API.
* tools/gpgconf-comp.c (gpg_agent_runtime_change)
(scdaemon_runtime_change, tpm2daemon_runtime_change)
(dirmngr_runtime_change, keyboxd_runtime_change)
(gc_component_launch, gc_component_check_options)
(retrieve_options_from_program): Ditto.
* tools/gpgconf.c (show_versions_via_dirmngr): Ditto.
* tools/gpgtar-create.c (gpgtar_create): Ditto.
* tools/gpgtar-extract.c (gpgtar_extract): Ditto.
* tools/gpgtar-list.c (gpgtar_list): Ditto.
--
GnuPG-bug-id: 7192
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2024-07-09 02:39:15 +02:00
|
|
|
gpgrt_process_get_streams (proc, 0, NULL, &outfp, NULL);
|
2020-10-02 12:26:02 +02:00
|
|
|
while ((length = es_read_line (outfp, &line, &line_len, NULL)) > 0)
|
|
|
|
{
|
|
|
|
/* Strip newline and carriage return, if present. */
|
|
|
|
while (length > 0
|
|
|
|
&& (line[length - 1] == '\n' || line[length - 1] == '\r'))
|
|
|
|
line[--length] = '\0';
|
|
|
|
es_fprintf (fp, "%s\n", line);
|
|
|
|
}
|
|
|
|
if (length < 0 || es_ferror (outfp))
|
|
|
|
{
|
|
|
|
err = gpg_error_from_syserror ();
|
|
|
|
log_error ("error reading from %s: %s\n", pgmname, gpg_strerror (err));
|
|
|
|
}
|
|
|
|
if (es_fclose (outfp))
|
|
|
|
{
|
|
|
|
err = gpg_error_from_syserror ();
|
|
|
|
log_error ("error closing output stream of %s: %s\n",
|
|
|
|
pgmname, gpg_strerror (err));
|
|
|
|
}
|
|
|
|
|
Use gpgrt_process_spawn API from libgpg-error.
* agent/genkey.c (do_check_passphrase_pattern): Use the gpgrt API.
* common/asshelp.c (start_new_service): Ditto.
* common/exechelp.h: Remove gnupg_process_spawn API.
* common/exechelp-posix.c: Remove gnupg_process_spawn implementation.
* common/exechelp-w32.c: Likewise.
* common/exectool.c (gnupg_exec_tool_stream): Use the gpgrt API.
* common/t-exechelp.c (test_pipe_stream): Remove.
* dirmngr/ldap-wrapper.c (destroy_wrapper, ldap_reaper_thread): Use
the gpgrt API.
(ldap_wrapper_connection_cleanup, ldap_wrapper): Ditto.
* dirmngr/ldap.c, g10/call-keyboxd.c: No need to include exechelp.h.
* g10/photoid.c (run_with_pipe, show_photo): Use the gpgrt API.
* g13/be-encfs.c (run_umount_helper, run_encfs_tool): Ditto.
* g13/g13.c, g13/mount.c, g13/runner.c: No need to include exechelp.h.
* scd/apdu.c: No need to include exechelp.h.
* scd/app.c (report_change): Use the gpgrt API.
* sm/export.c, sm/import.c: No need to include exechelp.h.
* tests/gpgscm/ffi.c (proc_object_finalize, proc_wrap)
(do_process_spawn_io, do_process_spawn_fd, do_process_wait): Use the
gpgrt API.
* tools/gpg-auth.c: No need to include exechelp.h.
* tools/gpg-card.c (cmd_gpg): Use the gpgrt API.
* tools/gpg-connect-agent.c: No need to include exechelp.h.
* tools/gpg-mail-tube.c (mail_tube_encrypt, prepare_for_appimage)
(start_gpg_encrypt): Use the gpgrt API.
* tools/gpgconf-comp.c (gpg_agent_runtime_change)
(scdaemon_runtime_change, tpm2daemon_runtime_change)
(dirmngr_runtime_change, keyboxd_runtime_change)
(gc_component_launch, gc_component_check_options)
(retrieve_options_from_program): Ditto.
* tools/gpgconf.c (show_versions_via_dirmngr): Ditto.
* tools/gpgtar-create.c (gpgtar_create): Ditto.
* tools/gpgtar-extract.c (gpgtar_extract): Ditto.
* tools/gpgtar-list.c (gpgtar_list): Ditto.
--
GnuPG-bug-id: 7192
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2024-07-09 02:39:15 +02:00
|
|
|
err = gpgrt_process_wait (proc, 1);
|
common,agent,gpg,dirmngr,g13,scd,tests,tools: New spawn function.
* common/exechelp-posix.c (do_exec, gnupg_spawn_process): Remove.
(check_syscall_func, pre_syscall, post_syscall) : New.
(do_create_socketpair, posix_open_null, call_spawn_cb): New.
(my_exec, spawn_detached, gnupg_spawn_helper): New.
(gnupg_process_spawn, process_kill, gnupg_process_terminate): New.
(gnupg_process_get_fds, gnupg_process_get_streams): New.
(process_vctl, gnupg_process_ctl): New.
(gnupg_process_wait, gnupg_process_release): New.
(gnupg_process_wait_list): New.
* common/exechelp-w32.c: Add definition of _WIN32_WINNT as 0x600.
(check_syscall_func, pre_syscall, post_syscall): New.
(gnupg_spawn_process): Remove.
(check_windows_version): New.
(spawn_detached, gnupg_spawn_helper, gnupg_process_spawn): New.
(gnupg_process_get_fds, gnupg_process_get_streams): New.
(process_kill, process_vctl, gnupg_process_ctl): New.
(gnupg_process_wait, gnupg_process_terminate): New.
(gnupg_process_release, gnupg_process_wait_list): New.
* common/exechelp.h: Re-write for new API.
* common/exectool.c (gnupg_exec_tool_stream): Follow the change.
* common/asshelp.c (start_new_service): Likewise.
* agent/genkey.c (do_check_passphrase_pattern): Likewise.
* dirmngr/ldap-wrapper.c (struct wrapper_context_s): Use PROC.
(destroy_wrapper): Follow the change of API.
(read_log_data): Follow the change of API, use printable_pid.
(ldap_reaper_thread, ldap_wrapper_release_context): Likewise.
(ldap_wrapper_connection_cleanup, ldap_wrapper): Likewise.
* g10/photoid.c (run_with_pipe): Follow the change of API.
(show_photo): Likewise.
* g13/be-encfs.c (run_umount_helper): Likewise.
(run_encfs_tool): Likewise.
* g13/g13.c: Add including ./common/exechelp.h.
* g13/mount.c: Likewise.
* g13/runner.c: Follow the change of API.
* g13/runner.h: Follow the change of API.
* scd/app.c (setup_env): New.
(report_change): Follow the change of API.
* tests/gpgscm/ffi.c (proc_object_finalize): New.
(proc_object_to_string): New.
(proc_wrap, proc_unwrap): New.
(do_spawn_process): Remove.
(do_process_spawn): New.
(setup_std_fds): New.
(do_spawn_process_fd): Remove.
(do_process_spawn_fd): New.
(do_wait_process): Remove.
(do_process_wait): New.
(do_wait_processes): Remove.
* tests/gpgscm/t-child.scm: Follow the change of API.
* tests/gpgscm/tests.scm: Likewise.
* tests/openpgp/defs.scm: Likewise.
* tests/tpm2dtests/defs.scm: Likewise.
* tools/gpg-card.c: Likewise.
* tools/gpgconf-comp.c: Likewise.
* tools/gpgconf.c: Likewise.
* tools/gpgtar-create.c: Likewise.
* tools/gpgtar-extract.c: Likewise.
* tools/gpgtar-list.c: Likewise.
--
GnuPG-bug-id: 6275
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2023-05-11 12:18:21 +02:00
|
|
|
if (!err)
|
2020-10-02 12:26:02 +02:00
|
|
|
{
|
common,agent,gpg,dirmngr,g13,scd,tests,tools: New spawn function.
* common/exechelp-posix.c (do_exec, gnupg_spawn_process): Remove.
(check_syscall_func, pre_syscall, post_syscall) : New.
(do_create_socketpair, posix_open_null, call_spawn_cb): New.
(my_exec, spawn_detached, gnupg_spawn_helper): New.
(gnupg_process_spawn, process_kill, gnupg_process_terminate): New.
(gnupg_process_get_fds, gnupg_process_get_streams): New.
(process_vctl, gnupg_process_ctl): New.
(gnupg_process_wait, gnupg_process_release): New.
(gnupg_process_wait_list): New.
* common/exechelp-w32.c: Add definition of _WIN32_WINNT as 0x600.
(check_syscall_func, pre_syscall, post_syscall): New.
(gnupg_spawn_process): Remove.
(check_windows_version): New.
(spawn_detached, gnupg_spawn_helper, gnupg_process_spawn): New.
(gnupg_process_get_fds, gnupg_process_get_streams): New.
(process_kill, process_vctl, gnupg_process_ctl): New.
(gnupg_process_wait, gnupg_process_terminate): New.
(gnupg_process_release, gnupg_process_wait_list): New.
* common/exechelp.h: Re-write for new API.
* common/exectool.c (gnupg_exec_tool_stream): Follow the change.
* common/asshelp.c (start_new_service): Likewise.
* agent/genkey.c (do_check_passphrase_pattern): Likewise.
* dirmngr/ldap-wrapper.c (struct wrapper_context_s): Use PROC.
(destroy_wrapper): Follow the change of API.
(read_log_data): Follow the change of API, use printable_pid.
(ldap_reaper_thread, ldap_wrapper_release_context): Likewise.
(ldap_wrapper_connection_cleanup, ldap_wrapper): Likewise.
* g10/photoid.c (run_with_pipe): Follow the change of API.
(show_photo): Likewise.
* g13/be-encfs.c (run_umount_helper): Likewise.
(run_encfs_tool): Likewise.
* g13/g13.c: Add including ./common/exechelp.h.
* g13/mount.c: Likewise.
* g13/runner.c: Follow the change of API.
* g13/runner.h: Follow the change of API.
* scd/app.c (setup_env): New.
(report_change): Follow the change of API.
* tests/gpgscm/ffi.c (proc_object_finalize): New.
(proc_object_to_string): New.
(proc_wrap, proc_unwrap): New.
(do_spawn_process): Remove.
(do_process_spawn): New.
(setup_std_fds): New.
(do_spawn_process_fd): Remove.
(do_process_spawn_fd): New.
(do_wait_process): Remove.
(do_process_wait): New.
(do_wait_processes): Remove.
* tests/gpgscm/t-child.scm: Follow the change of API.
* tests/gpgscm/tests.scm: Likewise.
* tests/openpgp/defs.scm: Likewise.
* tests/tpm2dtests/defs.scm: Likewise.
* tools/gpg-card.c: Likewise.
* tools/gpgconf-comp.c: Likewise.
* tools/gpgconf.c: Likewise.
* tools/gpgtar-create.c: Likewise.
* tools/gpgtar-extract.c: Likewise.
* tools/gpgtar-list.c: Likewise.
--
GnuPG-bug-id: 6275
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2023-05-11 12:18:21 +02:00
|
|
|
int exitcode;
|
|
|
|
|
Use gpgrt_process_spawn API from libgpg-error.
* agent/genkey.c (do_check_passphrase_pattern): Use the gpgrt API.
* common/asshelp.c (start_new_service): Ditto.
* common/exechelp.h: Remove gnupg_process_spawn API.
* common/exechelp-posix.c: Remove gnupg_process_spawn implementation.
* common/exechelp-w32.c: Likewise.
* common/exectool.c (gnupg_exec_tool_stream): Use the gpgrt API.
* common/t-exechelp.c (test_pipe_stream): Remove.
* dirmngr/ldap-wrapper.c (destroy_wrapper, ldap_reaper_thread): Use
the gpgrt API.
(ldap_wrapper_connection_cleanup, ldap_wrapper): Ditto.
* dirmngr/ldap.c, g10/call-keyboxd.c: No need to include exechelp.h.
* g10/photoid.c (run_with_pipe, show_photo): Use the gpgrt API.
* g13/be-encfs.c (run_umount_helper, run_encfs_tool): Ditto.
* g13/g13.c, g13/mount.c, g13/runner.c: No need to include exechelp.h.
* scd/apdu.c: No need to include exechelp.h.
* scd/app.c (report_change): Use the gpgrt API.
* sm/export.c, sm/import.c: No need to include exechelp.h.
* tests/gpgscm/ffi.c (proc_object_finalize, proc_wrap)
(do_process_spawn_io, do_process_spawn_fd, do_process_wait): Use the
gpgrt API.
* tools/gpg-auth.c: No need to include exechelp.h.
* tools/gpg-card.c (cmd_gpg): Use the gpgrt API.
* tools/gpg-connect-agent.c: No need to include exechelp.h.
* tools/gpg-mail-tube.c (mail_tube_encrypt, prepare_for_appimage)
(start_gpg_encrypt): Use the gpgrt API.
* tools/gpgconf-comp.c (gpg_agent_runtime_change)
(scdaemon_runtime_change, tpm2daemon_runtime_change)
(dirmngr_runtime_change, keyboxd_runtime_change)
(gc_component_launch, gc_component_check_options)
(retrieve_options_from_program): Ditto.
* tools/gpgconf.c (show_versions_via_dirmngr): Ditto.
* tools/gpgtar-create.c (gpgtar_create): Ditto.
* tools/gpgtar-extract.c (gpgtar_extract): Ditto.
* tools/gpgtar-list.c (gpgtar_list): Ditto.
--
GnuPG-bug-id: 7192
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2024-07-09 02:39:15 +02:00
|
|
|
gpgrt_process_ctl (proc, GPGRT_PROCESS_GET_EXIT_ID, &exitcode);
|
2024-07-05 09:14:47 +02:00
|
|
|
if (exitcode)
|
|
|
|
{
|
|
|
|
log_error ("running %s failed (exitcode=%d): %s\n",
|
|
|
|
pgmname, exitcode, gpg_strerror (err));
|
|
|
|
es_fprintf (fp, "[error: can't get further info]\n");
|
|
|
|
}
|
2020-10-02 12:26:02 +02:00
|
|
|
}
|
Use gpgrt_process_spawn API from libgpg-error.
* agent/genkey.c (do_check_passphrase_pattern): Use the gpgrt API.
* common/asshelp.c (start_new_service): Ditto.
* common/exechelp.h: Remove gnupg_process_spawn API.
* common/exechelp-posix.c: Remove gnupg_process_spawn implementation.
* common/exechelp-w32.c: Likewise.
* common/exectool.c (gnupg_exec_tool_stream): Use the gpgrt API.
* common/t-exechelp.c (test_pipe_stream): Remove.
* dirmngr/ldap-wrapper.c (destroy_wrapper, ldap_reaper_thread): Use
the gpgrt API.
(ldap_wrapper_connection_cleanup, ldap_wrapper): Ditto.
* dirmngr/ldap.c, g10/call-keyboxd.c: No need to include exechelp.h.
* g10/photoid.c (run_with_pipe, show_photo): Use the gpgrt API.
* g13/be-encfs.c (run_umount_helper, run_encfs_tool): Ditto.
* g13/g13.c, g13/mount.c, g13/runner.c: No need to include exechelp.h.
* scd/apdu.c: No need to include exechelp.h.
* scd/app.c (report_change): Use the gpgrt API.
* sm/export.c, sm/import.c: No need to include exechelp.h.
* tests/gpgscm/ffi.c (proc_object_finalize, proc_wrap)
(do_process_spawn_io, do_process_spawn_fd, do_process_wait): Use the
gpgrt API.
* tools/gpg-auth.c: No need to include exechelp.h.
* tools/gpg-card.c (cmd_gpg): Use the gpgrt API.
* tools/gpg-connect-agent.c: No need to include exechelp.h.
* tools/gpg-mail-tube.c (mail_tube_encrypt, prepare_for_appimage)
(start_gpg_encrypt): Use the gpgrt API.
* tools/gpgconf-comp.c (gpg_agent_runtime_change)
(scdaemon_runtime_change, tpm2daemon_runtime_change)
(dirmngr_runtime_change, keyboxd_runtime_change)
(gc_component_launch, gc_component_check_options)
(retrieve_options_from_program): Ditto.
* tools/gpgconf.c (show_versions_via_dirmngr): Ditto.
* tools/gpgtar-create.c (gpgtar_create): Ditto.
* tools/gpgtar-extract.c (gpgtar_extract): Ditto.
* tools/gpgtar-list.c (gpgtar_list): Ditto.
--
GnuPG-bug-id: 7192
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2024-07-09 02:39:15 +02:00
|
|
|
gpgrt_process_release (proc);
|
2020-10-02 12:26:02 +02:00
|
|
|
xfree (line);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Show all kind of version information. */
|
|
|
|
static void
|
|
|
|
show_versions (estream_t fp)
|
|
|
|
{
|
2021-11-04 16:34:26 +01:00
|
|
|
show_version_gnupg (fp, "");
|
2020-10-02 12:26:02 +02:00
|
|
|
es_fputc ('\n', fp);
|
|
|
|
show_version_libgcrypt (fp);
|
|
|
|
es_fputc ('\n', fp);
|
|
|
|
show_version_gpgrt (fp);
|
|
|
|
es_fputc ('\n', fp);
|
|
|
|
show_versions_via_dirmngr (fp);
|
|
|
|
}
|
2021-11-04 16:34:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Copy data from file SRC to DST. Returns 0 on success or an error
|
2021-11-17 09:53:05 +01:00
|
|
|
* code on failure. If LISTP is not NULL, that strlist is updated
|
2024-03-18 11:14:19 +01:00
|
|
|
* with the variable or registry key names detected. Flag bit 0
|
2021-11-17 09:53:05 +01:00
|
|
|
* indicates a registry entry. */
|
2021-11-04 16:34:26 +01:00
|
|
|
static gpg_error_t
|
2021-11-17 09:53:05 +01:00
|
|
|
my_copy_file (estream_t src, estream_t dst, strlist_t *listp)
|
2021-11-04 16:34:26 +01:00
|
|
|
{
|
2021-11-17 09:53:05 +01:00
|
|
|
gpg_error_t err;
|
|
|
|
char *line = NULL;
|
|
|
|
size_t line_len = 0;
|
|
|
|
ssize_t length;
|
2021-11-04 16:34:26 +01:00
|
|
|
int written;
|
|
|
|
|
2021-11-17 09:53:05 +01:00
|
|
|
while ((length = es_read_line (src, &line, &line_len, NULL)) > 0)
|
2021-11-04 16:34:26 +01:00
|
|
|
{
|
2024-04-04 15:09:12 +02:00
|
|
|
/* Prefix each line with two spaces but use a comma if the line
|
|
|
|
* starts with a special org-mode character. */
|
|
|
|
if (*line == '*' || (*line == '#' && line[1] == '+'))
|
|
|
|
es_fputc (',', dst);
|
|
|
|
else
|
|
|
|
es_fputc (' ', dst);
|
|
|
|
es_fputc (' ', dst);
|
|
|
|
|
2021-11-17 09:53:05 +01:00
|
|
|
written = gpgrt_fwrite (line, 1, length, dst);
|
|
|
|
if (written != length)
|
|
|
|
return gpg_error_from_syserror ();
|
|
|
|
trim_spaces (line);
|
|
|
|
if (*line == '[' && listp)
|
|
|
|
{
|
|
|
|
char **tokens;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
for (p=line+1; *p; p++)
|
|
|
|
if (*p != ' ' && *p != '\t')
|
|
|
|
break;
|
|
|
|
if (*p && p[strlen (p)-1] == ']')
|
|
|
|
p[strlen (p)-1] = 0;
|
|
|
|
tokens = strtokenize (p, " \t");
|
|
|
|
if (!tokens)
|
|
|
|
{
|
|
|
|
err = gpg_error_from_syserror ();
|
|
|
|
log_error ("strtokenize failed: %s\n", gpg_strerror (err));
|
|
|
|
return err;
|
|
|
|
}
|
2021-11-04 16:34:26 +01:00
|
|
|
|
2021-11-17 09:53:05 +01:00
|
|
|
/* Check whether we have a getreg or getenv statement and
|
|
|
|
* store the third token to later retrieval. */
|
|
|
|
if (tokens[0] && tokens[1] && tokens[2]
|
|
|
|
&& (!strcmp (tokens[0], "getreg")
|
|
|
|
|| !strcmp (tokens[0], "getenv")))
|
|
|
|
{
|
|
|
|
int isreg = (tokens[0][3] == 'r');
|
|
|
|
strlist_t sl = *listp;
|
|
|
|
|
|
|
|
for (sl = *listp; sl; sl = sl->next)
|
|
|
|
if (!strcmp (sl->d, tokens[2]) && (sl->flags & 1) == isreg)
|
|
|
|
break;
|
|
|
|
if (!sl) /* Not yet in the respective list. */
|
|
|
|
{
|
|
|
|
sl = add_to_strlist (listp, tokens[2]);
|
|
|
|
if (isreg)
|
|
|
|
sl->flags = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xfree (tokens);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (length < 0 || es_ferror (src))
|
2021-11-04 16:34:26 +01:00
|
|
|
return gpg_error_from_syserror ();
|
|
|
|
|
|
|
|
if (gpgrt_fflush (dst))
|
|
|
|
return gpg_error_from_syserror ();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Helper for show_configs */
|
|
|
|
static void
|
2021-11-17 09:53:05 +01:00
|
|
|
show_configs_one_file (const char *fname, int global, estream_t outfp,
|
|
|
|
strlist_t *listp)
|
2021-11-04 16:34:26 +01:00
|
|
|
{
|
|
|
|
gpg_error_t err;
|
|
|
|
estream_t fp;
|
|
|
|
|
|
|
|
fp = es_fopen (fname, "r");
|
|
|
|
if (!fp)
|
|
|
|
{
|
|
|
|
err = gpg_error_from_syserror ();
|
2024-04-04 15:09:12 +02:00
|
|
|
if (gpg_err_code (err) != GPG_ERR_ENOENT)
|
|
|
|
es_fprintf (outfp, "** %s config \"%s\": %s\n",
|
|
|
|
global? "global":"local", fname, gpg_strerror (err));
|
2021-11-04 16:34:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, "** %s config \"%s\"\n#+begin_src\n",
|
2021-11-04 16:34:26 +01:00
|
|
|
global? "global":"local", fname);
|
2021-11-17 09:53:05 +01:00
|
|
|
err = my_copy_file (fp, outfp, listp);
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, "\n#+end_src\n");
|
2021-11-04 16:34:26 +01:00
|
|
|
if (err)
|
2024-04-04 15:09:12 +02:00
|
|
|
log_error ("Error copying file \"%s\": %s\n",
|
2021-11-04 16:34:26 +01:00
|
|
|
fname, gpg_strerror (err));
|
|
|
|
es_fclose (fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-17 18:15:55 +01:00
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
/* Print registry entries relevant to the GnuPG system and related
|
|
|
|
* software. */
|
|
|
|
static void
|
|
|
|
show_other_registry_entries (estream_t outfp)
|
|
|
|
{
|
|
|
|
static struct {
|
|
|
|
int group;
|
|
|
|
const char *name;
|
2024-03-21 17:41:10 +01:00
|
|
|
unsigned int prependregkey:1;
|
2021-11-17 18:15:55 +01:00
|
|
|
} names[] =
|
|
|
|
{
|
|
|
|
{ 1, "HKLM\\Software\\Gpg4win:Install Directory" },
|
|
|
|
{ 1, "HKLM\\Software\\Gpg4win:Desktop-Version" },
|
|
|
|
{ 1, "HKLM\\Software\\Gpg4win:VS-Desktop-Version" },
|
2024-03-21 17:41:10 +01:00
|
|
|
{ 1, ":HomeDir", 1 },
|
|
|
|
{ 1, ":DefaultLogFile", 1 },
|
2022-08-02 12:25:23 +02:00
|
|
|
{ 2, "\\Software\\Microsoft\\Office\\Outlook\\Addins\\GNU.GpgOL"
|
2021-11-17 18:15:55 +01:00
|
|
|
":LoadBehavior" },
|
|
|
|
{ 2, "HKCU\\Software\\Microsoft\\Office\\16.0\\Outlook\\Options\\Mail:"
|
|
|
|
"ReadAsPlain" },
|
|
|
|
{ 2, "HKCU\\Software\\Policies\\Microsoft\\Office\\16.0\\Outlook\\"
|
|
|
|
"Options\\Mail:ReadAsPlain" },
|
|
|
|
{ 3, "logFile" },
|
|
|
|
{ 3, "enableDebug" },
|
|
|
|
{ 3, "searchSmimeServers" },
|
|
|
|
{ 3, "smimeInsecureReplyAllowed" },
|
|
|
|
{ 3, "enableSmime" },
|
|
|
|
{ 3, "preferSmime" },
|
|
|
|
{ 3, "encryptDefault" },
|
|
|
|
{ 3, "signDefault" },
|
|
|
|
{ 3, "inlinePGP" },
|
|
|
|
{ 3, "replyCrypt" },
|
|
|
|
{ 3, "autoresolve" },
|
|
|
|
{ 3, "autoretrieve" },
|
|
|
|
{ 3, "automation" },
|
|
|
|
{ 3, "autosecure" },
|
|
|
|
{ 3, "autotrust" },
|
|
|
|
{ 3, "autoencryptUntrusted" },
|
|
|
|
{ 3, "autoimport" },
|
|
|
|
{ 3, "splitBCCMails" },
|
|
|
|
{ 3, "combinedOpsEnabled" },
|
|
|
|
{ 3, "encryptSubject" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
int idx;
|
|
|
|
int group = 0;
|
|
|
|
char *namebuf = NULL;
|
|
|
|
const char *name;
|
2022-08-02 12:25:23 +02:00
|
|
|
int from_hklm;
|
2021-11-17 18:15:55 +01:00
|
|
|
|
|
|
|
for (idx=0; (name = names[idx].name); idx++)
|
|
|
|
{
|
|
|
|
char *value;
|
|
|
|
|
|
|
|
if (names[idx].group == 3)
|
|
|
|
{
|
|
|
|
xfree (namebuf);
|
|
|
|
namebuf = xstrconcat ("\\Software\\GNU\\GpgOL", ":",
|
|
|
|
names[idx].name, NULL);
|
|
|
|
name = namebuf;
|
|
|
|
}
|
2024-03-21 17:41:10 +01:00
|
|
|
else if (names[idx].prependregkey)
|
|
|
|
{
|
|
|
|
xfree (namebuf);
|
|
|
|
namebuf = xstrconcat ("\\", gnupg_registry_dir (),
|
|
|
|
names[idx].name, NULL);
|
|
|
|
name = namebuf;
|
|
|
|
}
|
2021-11-17 18:15:55 +01:00
|
|
|
|
2022-08-02 12:25:23 +02:00
|
|
|
value = read_w32_reg_string (name, &from_hklm);
|
2021-11-17 18:15:55 +01:00
|
|
|
if (!value)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (names[idx].group != group)
|
|
|
|
{
|
|
|
|
group = names[idx].group;
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, "\n%s related:\n",
|
2021-11-17 18:15:55 +01:00
|
|
|
group == 1 ? "GnuPG Desktop" :
|
|
|
|
group == 2 ? "Outlook" :
|
|
|
|
group == 3 ? "\\Software\\GNU\\GpgOL"
|
|
|
|
: "System" );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (group == 3)
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, " %s=%s%s\n", names[idx].name, value,
|
2022-08-02 12:25:23 +02:00
|
|
|
from_hklm? " [hklm]":"");
|
2021-11-17 18:15:55 +01:00
|
|
|
else
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, " %s\n ->%s<-%s\n", name, value,
|
2022-08-02 12:25:23 +02:00
|
|
|
from_hklm? " [hklm]":"");
|
2021-11-17 18:15:55 +01:00
|
|
|
|
|
|
|
xfree (value);
|
|
|
|
}
|
|
|
|
|
|
|
|
xfree (namebuf);
|
|
|
|
}
|
2022-08-03 09:26:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Print registry entries take from a configuration file. */
|
|
|
|
static void
|
|
|
|
show_registry_entries_from_file (estream_t outfp)
|
|
|
|
{
|
|
|
|
gpg_error_t err;
|
|
|
|
char *fname;
|
|
|
|
estream_t fp;
|
|
|
|
char *line = NULL;
|
|
|
|
size_t length_of_line = 0;
|
|
|
|
size_t maxlen;
|
|
|
|
ssize_t len;
|
|
|
|
char *value = NULL;
|
|
|
|
int from_hklm;
|
|
|
|
int any = 0;
|
|
|
|
|
|
|
|
fname = make_filename (gnupg_datadir (), "gpgconf.rnames", NULL);
|
|
|
|
fp = es_fopen (fname, "r");
|
|
|
|
if (!fp)
|
|
|
|
{
|
|
|
|
err = gpg_error_from_syserror ();
|
|
|
|
if (gpg_err_code (err) != GPG_ERR_ENOENT)
|
|
|
|
log_error ("error opening '%s': %s\n", fname, gpg_strerror (err));
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
|
|
|
maxlen = 2048; /* Set limit. */
|
|
|
|
while ((len = es_read_line (fp, &line, &length_of_line, &maxlen)) > 0)
|
|
|
|
{
|
|
|
|
if (!maxlen)
|
|
|
|
{
|
|
|
|
err = gpg_error (GPG_ERR_LINE_TOO_LONG);
|
|
|
|
log_error ("error reading '%s': %s\n", fname, gpg_strerror (err));
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
trim_spaces (line);
|
|
|
|
if (*line == '#')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
xfree (value);
|
|
|
|
value = read_w32_reg_string (line, &from_hklm);
|
|
|
|
if (!value)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!any)
|
|
|
|
{
|
|
|
|
any = 1;
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, "Taken from gpgconf.rnames:\n");
|
2022-08-03 09:26:44 +02:00
|
|
|
}
|
|
|
|
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, " %s\n ->%s<-%s\n", line, value,
|
2022-08-03 09:26:44 +02:00
|
|
|
from_hklm? " [hklm]":"");
|
|
|
|
|
|
|
|
}
|
|
|
|
if (len < 0 || es_ferror (fp))
|
|
|
|
{
|
|
|
|
err = gpg_error_from_syserror ();
|
|
|
|
log_error ("error reading '%s': %s\n", fname, gpg_strerror (err));
|
|
|
|
}
|
|
|
|
|
|
|
|
leave:
|
|
|
|
xfree (value);
|
|
|
|
xfree (line);
|
|
|
|
es_fclose (fp);
|
|
|
|
xfree (fname);
|
|
|
|
}
|
2021-11-17 18:15:55 +01:00
|
|
|
#endif /*HAVE_W32_SYSTEM*/
|
|
|
|
|
2022-08-03 09:26:44 +02:00
|
|
|
|
2021-11-04 16:34:26 +01:00
|
|
|
/* Show all config files. */
|
|
|
|
static void
|
|
|
|
show_configs (estream_t outfp)
|
|
|
|
{
|
|
|
|
static const char *names[] = { "common.conf", "gpg-agent.conf",
|
|
|
|
"scdaemon.conf", "dirmngr.conf",
|
|
|
|
"gpg.conf", "gpgsm.conf" };
|
2023-02-28 14:41:04 +01:00
|
|
|
static const char *envvars[] = { "PATH",
|
|
|
|
"http_proxy", "HTTP_PROXY",
|
|
|
|
"https_proxy", "HTTPS_PROXY",
|
|
|
|
"LD_LIBRARY_PATH", "LD_PRELOAD",
|
|
|
|
"LD_AUDIT", "LD_ORIGIN_PATH" };
|
2021-11-04 16:34:26 +01:00
|
|
|
gpg_error_t err;
|
|
|
|
int idx;
|
|
|
|
char *fname;
|
|
|
|
gnupg_dir_t dir;
|
|
|
|
gnupg_dirent_t dir_entry;
|
|
|
|
size_t n;
|
2024-04-04 15:09:12 +02:00
|
|
|
int any, anywarn;
|
2021-11-17 09:53:05 +01:00
|
|
|
strlist_t list = NULL;
|
2021-11-17 18:15:55 +01:00
|
|
|
strlist_t sl;
|
|
|
|
const char *s;
|
2022-01-27 14:41:38 +01:00
|
|
|
int got_gpgconfconf = 0;
|
2021-11-04 16:34:26 +01:00
|
|
|
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, "# gpgconf -X invoked %s%*s-*- org -*-\n\n",
|
|
|
|
isotimestamp (time (NULL)), 28, "");
|
|
|
|
es_fprintf (outfp, "* General information\n");
|
|
|
|
es_fprintf (outfp, "** Versions\n");
|
|
|
|
show_version_gnupg (outfp, " ");
|
|
|
|
es_fprintf (outfp, " Libgcrypt %s\n", gcry_check_version (NULL));
|
|
|
|
es_fprintf (outfp, " GpgRT %s\n", gpg_error_check_version (NULL));
|
2022-02-21 12:16:17 +01:00
|
|
|
#ifdef HAVE_W32_SYSTEM
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, " Codepages:");
|
2022-02-21 12:16:17 +01:00
|
|
|
if (GetConsoleCP () != GetConsoleOutputCP ())
|
|
|
|
es_fprintf (outfp, " %u/%u", GetConsoleCP (), GetConsoleOutputCP ());
|
|
|
|
else
|
|
|
|
es_fprintf (outfp, " %u", GetConsoleCP ());
|
|
|
|
es_fprintf (outfp, " %u", GetACP ());
|
|
|
|
es_fprintf (outfp, " %u\n", GetOEMCP ());
|
|
|
|
#endif
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, "\n\n");
|
2021-11-04 16:34:26 +01:00
|
|
|
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, "** Directories\n");
|
2021-11-19 09:29:37 +01:00
|
|
|
list_dirs (outfp, NULL, 1);
|
|
|
|
es_fprintf (outfp, "\n");
|
|
|
|
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, "** Environment\n#+begin_example\n");
|
2023-02-28 14:41:04 +01:00
|
|
|
for (idx=0; idx < DIM(envvars); idx++)
|
|
|
|
if ((s = getenv (envvars[idx])))
|
|
|
|
es_fprintf (outfp, "%s=%s\n", envvars[idx], s);
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, "#+end_example\n");
|
2023-02-28 14:41:04 +01:00
|
|
|
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, "* Config files\n");
|
2022-01-27 14:41:38 +01:00
|
|
|
fname = make_filename (gnupg_sysconfdir (), "gpgconf.conf", NULL);
|
|
|
|
if (!gnupg_access (fname, F_OK))
|
|
|
|
{
|
|
|
|
got_gpgconfconf = 1;
|
|
|
|
show_configs_one_file (fname, 1, outfp, &list);
|
|
|
|
es_fprintf (outfp, "\n");
|
|
|
|
}
|
|
|
|
xfree (fname);
|
|
|
|
|
2021-11-04 16:34:26 +01:00
|
|
|
for (idx = 0; idx < DIM (names); idx++)
|
|
|
|
{
|
|
|
|
fname = make_filename (gnupg_sysconfdir (), names[idx], NULL);
|
2021-11-17 09:53:05 +01:00
|
|
|
show_configs_one_file (fname, 1, outfp, &list);
|
2021-11-04 16:34:26 +01:00
|
|
|
xfree (fname);
|
|
|
|
fname = make_filename (gnupg_homedir (), names[idx], NULL);
|
2021-11-17 09:53:05 +01:00
|
|
|
show_configs_one_file (fname, 0, outfp, &list);
|
2021-11-04 16:34:26 +01:00
|
|
|
xfree (fname);
|
|
|
|
es_fprintf (outfp, "\n");
|
|
|
|
}
|
|
|
|
|
2021-11-17 09:53:05 +01:00
|
|
|
/* Print the encountered registry values and envvars. */
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, "* Other info\n");
|
2021-11-17 09:53:05 +01:00
|
|
|
if (list)
|
|
|
|
{
|
|
|
|
any = 0;
|
|
|
|
for (sl = list; sl; sl = sl->next)
|
|
|
|
if (!(sl->flags & 1))
|
|
|
|
{
|
|
|
|
if (!any)
|
|
|
|
{
|
|
|
|
any = 1;
|
|
|
|
es_fprintf (outfp,
|
2024-04-04 15:09:12 +02:00
|
|
|
"** List of encountered environment variables\n"
|
|
|
|
"#+begin_example\n");
|
2021-11-17 09:53:05 +01:00
|
|
|
}
|
|
|
|
if ((s = getenv (sl->d)))
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, " %-12s ->%s<-\n", sl->d, s);
|
2021-11-17 09:53:05 +01:00
|
|
|
else
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, " %-12s [not set]\n", sl->d);
|
2021-11-17 09:53:05 +01:00
|
|
|
}
|
|
|
|
if (any)
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, "#+end_example\n");
|
2021-11-17 18:15:55 +01:00
|
|
|
}
|
|
|
|
|
2021-11-17 09:53:05 +01:00
|
|
|
#ifdef HAVE_W32_SYSTEM
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, "** Registry entries\n");
|
|
|
|
es_fprintf (outfp, "#+begin_example\n");
|
2021-11-17 18:15:55 +01:00
|
|
|
any = 0;
|
|
|
|
if (list)
|
|
|
|
{
|
2021-11-17 09:53:05 +01:00
|
|
|
for (sl = list; sl; sl = sl->next)
|
|
|
|
if ((sl->flags & 1))
|
|
|
|
{
|
|
|
|
char *p;
|
2022-08-02 12:25:23 +02:00
|
|
|
int from_hklm;
|
2021-11-17 09:53:05 +01:00
|
|
|
|
|
|
|
if (!any)
|
|
|
|
{
|
|
|
|
any = 1;
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, "Encountered in config files:\n");
|
2021-11-17 09:53:05 +01:00
|
|
|
}
|
2022-08-02 12:25:23 +02:00
|
|
|
if ((p = read_w32_reg_string (sl->d, &from_hklm)))
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, " %s ->%s<-%s\n", sl->d, p,
|
2022-08-02 12:25:23 +02:00
|
|
|
from_hklm? " [hklm]":"");
|
2021-11-17 09:53:05 +01:00
|
|
|
else
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, " %s [not set]\n", sl->d);
|
2021-11-17 09:53:05 +01:00
|
|
|
xfree (p);
|
|
|
|
}
|
|
|
|
}
|
2021-11-17 18:15:55 +01:00
|
|
|
show_other_registry_entries (outfp);
|
2022-08-03 09:26:44 +02:00
|
|
|
show_registry_entries_from_file (outfp);
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, "#+end_example\n");
|
2021-11-17 18:15:55 +01:00
|
|
|
#endif /*HAVE_W32_SYSTEM*/
|
2021-11-17 09:53:05 +01:00
|
|
|
|
2021-11-17 18:15:55 +01:00
|
|
|
free_strlist (list);
|
2021-11-17 09:53:05 +01:00
|
|
|
|
2022-01-27 14:41:38 +01:00
|
|
|
/* Additional warning. */
|
2024-04-04 15:09:12 +02:00
|
|
|
anywarn = 0;
|
2022-01-27 14:41:38 +01:00
|
|
|
if (got_gpgconfconf)
|
|
|
|
{
|
2024-04-04 15:09:12 +02:00
|
|
|
anywarn = 1;
|
|
|
|
es_fprintf (outfp, "* Warnings\n");
|
2022-01-27 14:41:38 +01:00
|
|
|
es_fprintf (outfp,
|
2024-04-04 15:09:12 +02:00
|
|
|
"- Legacy config file \"gpgconf.conf\" found\n");
|
2022-01-27 14:41:38 +01:00
|
|
|
}
|
|
|
|
|
2021-11-04 16:34:26 +01:00
|
|
|
/* Check for uncommon files in the home directory. */
|
|
|
|
dir = gnupg_opendir (gnupg_homedir ());
|
|
|
|
if (!dir)
|
|
|
|
{
|
|
|
|
err = gpg_error_from_syserror ();
|
|
|
|
log_error ("error reading directory \"%s\": %s\n",
|
|
|
|
gnupg_homedir (), gpg_strerror (err));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-04-04 15:09:12 +02:00
|
|
|
any = 0;
|
2021-11-04 16:34:26 +01:00
|
|
|
while ((dir_entry = gnupg_readdir (dir)))
|
|
|
|
{
|
|
|
|
for (idx = 0; idx < DIM (names); idx++)
|
|
|
|
{
|
|
|
|
n = strlen (names[idx]);
|
|
|
|
if (!ascii_strncasecmp (dir_entry->d_name, names[idx], n)
|
|
|
|
&& dir_entry->d_name[n] == '-'
|
|
|
|
&& ascii_strncasecmp (dir_entry->d_name, "gpg.conf-1", 10))
|
|
|
|
{
|
2024-04-04 15:09:12 +02:00
|
|
|
if (!anywarn)
|
|
|
|
{
|
|
|
|
anywarn = 1;
|
|
|
|
es_fprintf (outfp, "* Warnings\n");
|
|
|
|
}
|
2021-11-04 16:34:26 +01:00
|
|
|
if (!any)
|
|
|
|
{
|
|
|
|
any = 1;
|
|
|
|
es_fprintf (outfp,
|
2024-04-04 15:09:12 +02:00
|
|
|
"- Suspicious files in \"%s\":\n",
|
2021-11-04 16:34:26 +01:00
|
|
|
gnupg_homedir ());
|
|
|
|
}
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, " - %s\n", dir_entry->d_name);
|
2021-11-04 16:34:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gnupg_closedir (dir);
|
2024-04-04 15:09:12 +02:00
|
|
|
es_fprintf (outfp, "# eof #\n");
|
2021-11-04 16:34:26 +01:00
|
|
|
}
|