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/>.
|
2004-01-05 10:28:27 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#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
|
|
|
|
|
|
|
#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"
|
2012-02-06 20:50:47 +01:00
|
|
|
|
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',
|
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,
|
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,
|
2009-03-03 10:02:58 +01:00
|
|
|
aListDirs,
|
2014-04-08 15:55:51 +02:00
|
|
|
aLaunch,
|
2011-02-23 10:15:34 +01:00
|
|
|
aKill,
|
2016-06-08 14:04:47 +02:00
|
|
|
aCreateSocketDir,
|
|
|
|
aRemoveSocketDir,
|
2016-12-16 16:00:15 +01:00
|
|
|
aApplyProfile,
|
2009-03-03 10:02:58 +01:00
|
|
|
aReload
|
2004-01-05 10:28:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* The list of commands and options. */
|
|
|
|
static ARGPARSE_OPTS opts[] =
|
|
|
|
{
|
|
|
|
{ 300, NULL, 0, N_("@Commands:\n ") },
|
2011-02-23 10:15:34 +01:00
|
|
|
|
2004-01-29 00:58:18 +01:00
|
|
|
{ aListComponents, "list-components", 256, N_("list all components") },
|
2007-08-29 11:51:37 +02:00
|
|
|
{ aCheckPrograms, "check-programs", 256, N_("check all programs") },
|
2004-01-29 00:58:18 +01:00
|
|
|
{ aListOptions, "list-options", 256, N_("|COMPONENT|list options") },
|
|
|
|
{ aChangeOptions, "change-options", 256, N_("|COMPONENT|change options") },
|
2008-05-20 00:46:41 +02:00
|
|
|
{ aCheckOptions, "check-options", 256, N_("|COMPONENT|check options") },
|
2007-03-06 21:44:41 +01:00
|
|
|
{ aApplyDefaults, "apply-defaults", 256,
|
|
|
|
N_("apply global default values") },
|
2016-12-16 16:00:15 +01:00
|
|
|
{ aApplyProfile, "apply-profile", 256,
|
|
|
|
N_("|FILE|update configuration files using FILE") },
|
2008-05-26 15:43:20 +02:00
|
|
|
{ aListDirs, "list-dirs", 256,
|
2014-05-07 18:18:27 +02:00
|
|
|
N_("get the configuration directories for @GPGCONF@") },
|
2007-10-23 20:13:27 +02:00
|
|
|
{ aListConfig, "list-config", 256,
|
|
|
|
N_("list global configuration file") },
|
2007-03-06 21:44:41 +01:00
|
|
|
{ aCheckConfig, "check-config", 256,
|
|
|
|
N_("check global configuration file") },
|
2016-11-02 17:54:32 +01:00
|
|
|
{ aQuerySWDB, "query-swdb", 256,
|
|
|
|
N_("query the software version database") },
|
2010-10-14 10:32:55 +02:00
|
|
|
{ aReload, "reload", 256, N_("reload all or a given component")},
|
2014-04-08 15:55:51 +02:00
|
|
|
{ aLaunch, "launch", 256, N_("launch a given component")},
|
2011-02-23 10:15:34 +01:00
|
|
|
{ aKill, "kill", 256, N_("kill a given component")},
|
2016-06-08 14:04:47 +02:00
|
|
|
{ aCreateSocketDir, "create-socketdir", 256, "@"},
|
|
|
|
{ aRemoveSocketDir, "remove-socketdir", 256, "@"},
|
2004-01-29 00:58:18 +01:00
|
|
|
|
2004-01-05 10:28:27 +01:00
|
|
|
{ 301, NULL, 0, N_("@\nOptions:\n ") },
|
2011-02-23 10:15:34 +01:00
|
|
|
|
2004-01-29 00:58:18 +01:00
|
|
|
{ oOutput, "output", 2, N_("use as output file") },
|
2004-01-05 10:28:27 +01:00
|
|
|
{ oVerbose, "verbose", 0, N_("verbose") },
|
2004-01-29 00:58:18 +01:00
|
|
|
{ oQuiet, "quiet", 0, N_("quiet") },
|
2004-01-05 10:28:27 +01:00
|
|
|
{ oDryRun, "dry-run", 0, N_("do not make any changes") },
|
2004-02-23 21:31:35 +01:00
|
|
|
{ oRuntime, "runtime", 0, N_("activate changes at runtime, if possible") },
|
2017-12-18 17:46:05 +01:00
|
|
|
ARGPARSE_s_i (oStatusFD, "status-fd", N_("|FD|write status info to this FD")),
|
2004-01-05 10:28:27 +01:00
|
|
|
/* hidden options */
|
2016-06-08 09:54:09 +02:00
|
|
|
{ oHomedir, "homedir", 2, "@" },
|
2016-12-14 14:18:22 +01:00
|
|
|
{ oBuilddir, "build-prefix", 2, "@" },
|
2016-08-04 13:02:37 +02:00
|
|
|
{ oNull, "null", 0, "@" },
|
2004-01-05 10:28:27 +01:00
|
|
|
{ oNoVerbose, "no-verbose", 0, "@"},
|
2019-02-25 15:55:13 +01:00
|
|
|
ARGPARSE_s_n (oShowSocket, "show-socket", "@"),
|
2017-07-19 06:41:18 +02:00
|
|
|
|
|
|
|
ARGPARSE_end(),
|
2004-01-05 10:28:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
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;
|
|
|
|
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
|
|
|
|
list_dirs (estream_t fp, char **names)
|
|
|
|
{
|
|
|
|
static struct {
|
|
|
|
const char *name;
|
|
|
|
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,},
|
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 },
|
|
|
|
{ "homedir", gnupg_homedir, NULL }
|
|
|
|
};
|
|
|
|
int idx, j;
|
|
|
|
char *tmp;
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
if (!names)
|
|
|
|
es_fprintf (fp, "%s:%s\n", list[idx].name, gc_percent_escape (s));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (j=0; names[j]; j++)
|
|
|
|
if (!strcmp (names[j], list[idx].name))
|
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
|
|
|
}
|
|
|
|
|
|
|
|
xfree (tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
* GPG_ERR_BAD_SIGNATURE :: Currupted SWDB file.
|
|
|
|
* 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;
|
|
|
|
char *fields[2];
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2004-01-05 10:28:27 +01:00
|
|
|
ARGPARSE_ARGS pargs;
|
|
|
|
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;
|
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);
|
2004-01-05 10:28:27 +01:00
|
|
|
set_strusage (my_strusage);
|
Call log_set_prefix() with human-readable labels.
* agent/preset-passphrase.c, agent/protect-tool.c, dirmngr/dirmngr.c
* dirmngr/t-http.c, g10/gpg.c, g10/gpgv.c, g13/g13-syshelp.c
* g13/g13.c, kbx/kbxutil.c, scd/scdaemon.c, sm/gpgsm.c
* tests/gpgscm/main.c, tools/gpg-check-pattern.c
* tools/gpg-connect-agent.c, tools/gpgconf.c, tools/gpgtar.c
* tools/symcryptrun.c: Invoke log_set_prefix() with
human-readable labels.
--
Some invocations of log_set_prefix() were done with raw numeric values
instead of values that humans can understand. Use symbolic
representations instead of numeric for better readability.
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2016-08-12 07:37:57 +02:00
|
|
|
log_set_prefix (GPGCONF_NAME, GPGRT_LOG_WITH_PREFIX);
|
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;
|
2004-02-23 21:31:35 +01:00
|
|
|
pargs.flags = 1; /* Do not remove the args. */
|
2004-01-05 10:28:27 +01:00
|
|
|
while (!no_more_options && optfile_parse (NULL, NULL, NULL, &pargs, opts))
|
|
|
|
{
|
|
|
|
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;
|
2004-02-23 21:31:35 +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:
|
|
|
|
set_status_fd (translate_sys2libc_fd_int (pargs.r.ret_int, 1));
|
|
|
|
break;
|
2019-02-25 15:55:13 +01:00
|
|
|
case oShowSocket: show_socket = 1; 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:
|
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
|
|
|
|
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
|
|
|
|
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";
|
|
|
|
else
|
|
|
|
names[0] = NULL;
|
|
|
|
names[1] = NULL;
|
|
|
|
get_outfp (&outfp);
|
|
|
|
list_dirs (outfp, names);
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
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:
|
|
|
|
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);
|
2016-07-11 13:05:37 +02:00
|
|
|
list_dirs (outfp, argc? argv : NULL);
|
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)
|
|
|
|
;
|
|
|
|
else if (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,
|
|
|
|
DIRMNGR_SOCK_NAME
|
|
|
|
};
|
|
|
|
int i;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
for (i=0; i < DIM(names); i++)
|
|
|
|
{
|
|
|
|
p = strconcat (socketdir , "/", names[i], NULL);
|
|
|
|
if (p)
|
|
|
|
gnupg_remove (p);
|
|
|
|
xfree (p);
|
|
|
|
}
|
|
|
|
if (rmdir (socketdir))
|
|
|
|
gc_error (1, 0, "error removing '%s': %s",
|
|
|
|
socketdir, gpg_strerror (err));
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
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);
|
|
|
|
}
|