2004-01-28 23:58:18 +00:00
|
|
|
|
/* gpgconf-comp.c - Configuration utility for GnuPG.
|
2011-02-23 10:15:34 +01:00
|
|
|
|
* Copyright (C) 2004, 2007, 2008, 2009, 2010,
|
|
|
|
|
* 2011 Free Software Foundation, Inc.
|
2006-06-20 17:21:37 +00: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 19:49:40 +00:00
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2006-06-20 17:21:37 +00: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
|
2007-07-04 19:49:40 +00:00
|
|
|
|
* along with GnuPG; if not, see <http://www.gnu.org/licenses/>.
|
2006-06-20 17:21:37 +00:00
|
|
|
|
*/
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
|
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <time.h>
|
2004-01-30 12:15:53 +00:00
|
|
|
|
#include <stdarg.h>
|
2010-03-29 12:57:11 +00:00
|
|
|
|
#ifdef HAVE_SIGNAL_H
|
|
|
|
|
# include <signal.h>
|
|
|
|
|
#endif
|
2007-08-29 16:59:20 +00:00
|
|
|
|
#include <ctype.h>
|
2007-06-26 13:48:44 +00:00
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
|
# define WIN32_LEAN_AND_MEAN 1
|
|
|
|
|
# include <windows.h>
|
|
|
|
|
#else
|
|
|
|
|
# include <pwd.h>
|
|
|
|
|
# include <grp.h>
|
2007-06-06 18:12:30 +00:00
|
|
|
|
#endif
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2004-01-30 12:15:53 +00:00
|
|
|
|
/* For log_logv(), asctimestamp(), gnupg_get_time (). */
|
2004-01-30 10:38:07 +00:00
|
|
|
|
#include "util.h"
|
2004-09-29 16:16:47 +00:00
|
|
|
|
#include "i18n.h"
|
2007-08-29 09:51:37 +00:00
|
|
|
|
#include "exechelp.h"
|
2004-01-30 10:38:07 +00:00
|
|
|
|
|
2007-08-02 18:12:43 +00:00
|
|
|
|
#include "gc-opt-flags.h"
|
2004-01-28 23:58:18 +00:00
|
|
|
|
#include "gpgconf.h"
|
|
|
|
|
|
2007-06-26 13:48:44 +00:00
|
|
|
|
/* There is a problem with gpg 1.4 under Windows: --gpgconf-list
|
|
|
|
|
returns a plain filename without escaping. As long as we have not
|
2010-08-23 19:26:05 +00:00
|
|
|
|
fixed that we need to use gpg2. */
|
|
|
|
|
#if defined(HAVE_W32_SYSTEM) && !defined(HAVE_W32CE_SYSTEM)
|
2007-06-26 13:48:44 +00:00
|
|
|
|
#define GPGNAME "gpg2"
|
|
|
|
|
#else
|
2013-11-18 14:09:47 +01:00
|
|
|
|
#define GPGNAME GPG_NAME
|
2007-06-26 13:48:44 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
|
Components: Add more components and their options.
|
|
|
|
|
Robustness: Do more validation. Call programs to do validation for us.
|
2004-01-30 12:15:53 +00:00
|
|
|
|
Add options to change backend binary path.
|
|
|
|
|
Extract binary path for some backends from gpgsm/gpg config.
|
2004-01-28 23:58:18 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2004-01-30 12:15:53 +00:00
|
|
|
|
|
2004-03-09 14:34:12 +00:00
|
|
|
|
#if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 ))
|
2004-01-30 12:15:53 +00:00
|
|
|
|
void gc_error (int status, int errnum, const char *fmt, ...) \
|
|
|
|
|
__attribute__ ((format (printf, 3, 4)));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Output a diagnostic message. If ERRNUM is not 0, then the output
|
|
|
|
|
is followed by a colon, a white space, and the error string for the
|
|
|
|
|
error number ERRNUM. In any case the output is finished by a
|
|
|
|
|
newline. The message is prepended by the program name, a colon,
|
|
|
|
|
and a whitespace. The output may be further formatted or
|
|
|
|
|
redirected by the jnlib logging facility. */
|
|
|
|
|
void
|
|
|
|
|
gc_error (int status, int errnum, const char *fmt, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list arg_ptr;
|
|
|
|
|
|
|
|
|
|
va_start (arg_ptr, fmt);
|
2015-04-24 15:49:18 +02:00
|
|
|
|
log_logv (GPGRT_LOG_ERROR, fmt, arg_ptr);
|
2004-01-30 12:15:53 +00:00
|
|
|
|
va_end (arg_ptr);
|
|
|
|
|
|
|
|
|
|
if (errnum)
|
|
|
|
|
log_printf (": %s\n", strerror (errnum));
|
|
|
|
|
else
|
|
|
|
|
log_printf ("\n");
|
|
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
|
{
|
|
|
|
|
log_printf (NULL);
|
|
|
|
|
log_printf ("fatal error (exit status %i)\n", status);
|
|
|
|
|
exit (status);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2004-03-23 12:21:48 +00:00
|
|
|
|
/* Forward declaration. */
|
2011-02-23 10:15:34 +01:00
|
|
|
|
static void gpg_agent_runtime_change (int killflag);
|
|
|
|
|
static void scdaemon_runtime_change (int killflag);
|
2014-11-19 10:31:34 +01:00
|
|
|
|
static void dirmngr_runtime_change (int killflag);
|
2004-03-23 12:21:48 +00:00
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* Backend configuration. Backends are used to decide how the default
|
|
|
|
|
and current value of an option can be determined, and how the
|
|
|
|
|
option can be changed. To every option in every component belongs
|
|
|
|
|
exactly one backend that controls and determines the option. Some
|
|
|
|
|
backends are programs from the GPG system. Others might be
|
|
|
|
|
implemented by GPGConf itself. If you change this enum, don't
|
|
|
|
|
forget to update GC_BACKEND below. */
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
/* Any backend, used for find_option (). */
|
|
|
|
|
GC_BACKEND_ANY,
|
|
|
|
|
|
|
|
|
|
/* The Gnu Privacy Guard. */
|
|
|
|
|
GC_BACKEND_GPG,
|
|
|
|
|
|
|
|
|
|
/* The Gnu Privacy Guard for S/MIME. */
|
|
|
|
|
GC_BACKEND_GPGSM,
|
|
|
|
|
|
|
|
|
|
/* The GPG Agent. */
|
|
|
|
|
GC_BACKEND_GPG_AGENT,
|
|
|
|
|
|
2004-03-16 19:00:25 +00:00
|
|
|
|
/* The GnuPG SCDaemon. */
|
|
|
|
|
GC_BACKEND_SCDAEMON,
|
|
|
|
|
|
2010-08-19 09:53:55 +00:00
|
|
|
|
/* The GnuPG directory manager. */
|
2004-01-28 23:58:18 +00:00
|
|
|
|
GC_BACKEND_DIRMNGR,
|
|
|
|
|
|
2010-08-19 09:53:55 +00:00
|
|
|
|
/* The LDAP server list file for the director manager. */
|
2004-01-28 23:58:18 +00:00
|
|
|
|
GC_BACKEND_DIRMNGR_LDAP_SERVER_LIST,
|
|
|
|
|
|
2010-08-19 09:53:55 +00:00
|
|
|
|
/* The Pinentry (not a part of GnuPG, proper). */
|
|
|
|
|
GC_BACKEND_PINENTRY,
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* The number of the above entries. */
|
|
|
|
|
GC_BACKEND_NR
|
|
|
|
|
} gc_backend_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* To be able to implement generic algorithms for the various
|
|
|
|
|
backends, we collect all information about them in this struct. */
|
|
|
|
|
static struct
|
|
|
|
|
{
|
|
|
|
|
/* The name of the backend. */
|
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
|
|
/* The name of the program that acts as the backend. Some backends
|
|
|
|
|
don't have an associated program, but are implemented directly by
|
|
|
|
|
GPGConf. In this case, PROGRAM is NULL. */
|
|
|
|
|
char *program;
|
|
|
|
|
|
2007-08-29 09:51:37 +00:00
|
|
|
|
/* The module name (GNUPG_MODULE_NAME_foo) as defined by
|
|
|
|
|
../common/util.h. This value is used to get the actual installed
|
2010-08-19 09:53:55 +00:00
|
|
|
|
path of the program. 0 is used if no backend program is
|
2007-08-29 09:51:37 +00:00
|
|
|
|
available. */
|
|
|
|
|
char module_name;
|
|
|
|
|
|
2011-02-23 10:15:34 +01:00
|
|
|
|
/* The runtime change callback. If KILLFLAG is true the component
|
|
|
|
|
is killed and not just reloaded. */
|
|
|
|
|
void (*runtime_change) (int killflag);
|
2004-03-23 12:21:48 +00:00
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* The option name for the configuration filename of this backend.
|
2008-05-26 15:05:31 +00:00
|
|
|
|
This must be an absolute filename. It can be an option from a
|
2004-01-28 23:58:18 +00:00
|
|
|
|
different backend (but then ordering of the options might
|
2008-08-06 11:48:23 +00:00
|
|
|
|
matter). Note: This must be unique among all components. */
|
2004-01-28 23:58:18 +00:00
|
|
|
|
const char *option_config_filename;
|
|
|
|
|
|
|
|
|
|
/* If this is a file backend rather than a program backend, then
|
|
|
|
|
this is the name of the option associated with the file. */
|
|
|
|
|
const char *option_name;
|
|
|
|
|
} gc_backend[GC_BACKEND_NR] =
|
|
|
|
|
{
|
2004-03-23 12:21:48 +00:00
|
|
|
|
{ NULL }, /* GC_BACKEND_ANY dummy entry. */
|
2014-05-07 18:18:27 +02:00
|
|
|
|
{ GPG_DISP_NAME, GPGNAME, GNUPG_MODULE_NAME_GPG,
|
|
|
|
|
NULL, GPGCONF_NAME "-" GPG_NAME ".conf" },
|
|
|
|
|
{ GPGSM_DISP_NAME, GPGSM_NAME, GNUPG_MODULE_NAME_GPGSM,
|
|
|
|
|
NULL, GPGCONF_NAME "-" GPGSM_NAME ".conf" },
|
|
|
|
|
{ GPG_AGENT_DISP_NAME, GPG_AGENT_NAME, GNUPG_MODULE_NAME_AGENT,
|
|
|
|
|
gpg_agent_runtime_change, GPGCONF_NAME"-" GPG_AGENT_NAME ".conf" },
|
|
|
|
|
{ SCDAEMON_DISP_NAME, SCDAEMON_NAME, GNUPG_MODULE_NAME_SCDAEMON,
|
|
|
|
|
scdaemon_runtime_change, GPGCONF_NAME"-" SCDAEMON_NAME ".conf" },
|
|
|
|
|
{ DIRMNGR_DISP_NAME, DIRMNGR_NAME, GNUPG_MODULE_NAME_DIRMNGR,
|
2014-11-19 10:31:34 +01:00
|
|
|
|
dirmngr_runtime_change, GPGCONF_NAME "-" DIRMNGR_NAME ".conf" },
|
2014-05-07 18:18:27 +02:00
|
|
|
|
{ DIRMNGR_DISP_NAME " LDAP Server List", NULL, 0,
|
2007-08-29 09:51:37 +00:00
|
|
|
|
NULL, "ldapserverlist-file", "LDAP Server" },
|
2010-08-19 09:53:55 +00:00
|
|
|
|
{ "Pinentry", "pinentry", GNUPG_MODULE_NAME_PINENTRY,
|
2014-05-07 18:18:27 +02:00
|
|
|
|
NULL, GPGCONF_NAME "-pinentry.conf" },
|
2004-01-28 23:58:18 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Option configuration. */
|
|
|
|
|
|
|
|
|
|
/* An option might take an argument, or not. Argument types can be
|
|
|
|
|
basic or complex. Basic types are generic and easy to validate.
|
|
|
|
|
Complex types provide more specific information about the intended
|
|
|
|
|
use, but can be difficult to validate. If you add to this enum,
|
|
|
|
|
don't forget to update GC_ARG_TYPE below. YOU MUST NOT CHANGE THE
|
|
|
|
|
NUMBERS OF THE EXISTING ENTRIES, AS THEY ARE PART OF THE EXTERNAL
|
|
|
|
|
INTERFACE. */
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
/* Basic argument types. */
|
|
|
|
|
|
|
|
|
|
/* No argument. */
|
|
|
|
|
GC_ARG_TYPE_NONE = 0,
|
|
|
|
|
|
|
|
|
|
/* A String argument. */
|
|
|
|
|
GC_ARG_TYPE_STRING = 1,
|
|
|
|
|
|
|
|
|
|
/* A signed integer argument. */
|
|
|
|
|
GC_ARG_TYPE_INT32 = 2,
|
|
|
|
|
|
|
|
|
|
/* An unsigned integer argument. */
|
|
|
|
|
GC_ARG_TYPE_UINT32 = 3,
|
|
|
|
|
|
2004-02-24 14:31:59 +00:00
|
|
|
|
/* ADD NEW BASIC TYPE ENTRIES HERE. */
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
|
|
|
|
/* Complex argument types. */
|
|
|
|
|
|
2008-05-26 15:05:31 +00:00
|
|
|
|
/* A complete filename. */
|
|
|
|
|
GC_ARG_TYPE_FILENAME = 32,
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
|
|
|
|
/* An LDAP server in the format
|
|
|
|
|
HOSTNAME:PORT:USERNAME:PASSWORD:BASE_DN. */
|
2004-02-24 14:31:59 +00:00
|
|
|
|
GC_ARG_TYPE_LDAP_SERVER = 33,
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
|
|
|
|
/* A 40 character fingerprint. */
|
2004-02-24 14:31:59 +00:00
|
|
|
|
GC_ARG_TYPE_KEY_FPR = 34,
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2008-02-27 17:32:47 +00:00
|
|
|
|
/* A user ID or key ID or fingerprint for a certificate. */
|
|
|
|
|
GC_ARG_TYPE_PUB_KEY = 35,
|
|
|
|
|
|
|
|
|
|
/* A user ID or key ID or fingerprint for a certificate with a key. */
|
|
|
|
|
GC_ARG_TYPE_SEC_KEY = 36,
|
|
|
|
|
|
2008-06-19 13:09:40 +00:00
|
|
|
|
/* A alias list made up of a key, an equal sign and a space
|
|
|
|
|
separated list of values. */
|
|
|
|
|
GC_ARG_TYPE_ALIAS_LIST = 37,
|
|
|
|
|
|
2004-02-24 14:31:59 +00:00
|
|
|
|
/* ADD NEW COMPLEX TYPE ENTRIES HERE. */
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
|
|
|
|
/* The number of the above entries. */
|
|
|
|
|
GC_ARG_TYPE_NR
|
|
|
|
|
} gc_arg_type_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* For every argument, we record some information about it in the
|
|
|
|
|
following struct. */
|
|
|
|
|
static struct
|
|
|
|
|
{
|
|
|
|
|
/* For every argument type exists a basic argument type that can be
|
|
|
|
|
used as a fallback for input and validation purposes. */
|
|
|
|
|
gc_arg_type_t fallback;
|
|
|
|
|
|
|
|
|
|
/* Human-readable name of the type. */
|
|
|
|
|
const char *name;
|
|
|
|
|
} gc_arg_type[GC_ARG_TYPE_NR] =
|
|
|
|
|
{
|
|
|
|
|
/* The basic argument types have their own types as fallback. */
|
|
|
|
|
{ GC_ARG_TYPE_NONE, "none" },
|
|
|
|
|
{ GC_ARG_TYPE_STRING, "string" },
|
|
|
|
|
{ GC_ARG_TYPE_INT32, "int32" },
|
|
|
|
|
{ GC_ARG_TYPE_UINT32, "uint32" },
|
|
|
|
|
|
2004-02-24 14:31:59 +00:00
|
|
|
|
/* Reserved basic type entries for future extension. */
|
|
|
|
|
{ GC_ARG_TYPE_NR, NULL }, { GC_ARG_TYPE_NR, NULL },
|
|
|
|
|
{ GC_ARG_TYPE_NR, NULL }, { GC_ARG_TYPE_NR, NULL },
|
|
|
|
|
{ GC_ARG_TYPE_NR, NULL }, { GC_ARG_TYPE_NR, NULL },
|
|
|
|
|
{ GC_ARG_TYPE_NR, NULL }, { GC_ARG_TYPE_NR, NULL },
|
|
|
|
|
{ GC_ARG_TYPE_NR, NULL }, { GC_ARG_TYPE_NR, NULL },
|
|
|
|
|
{ GC_ARG_TYPE_NR, NULL }, { GC_ARG_TYPE_NR, NULL },
|
|
|
|
|
{ GC_ARG_TYPE_NR, NULL }, { GC_ARG_TYPE_NR, NULL },
|
|
|
|
|
{ GC_ARG_TYPE_NR, NULL }, { GC_ARG_TYPE_NR, NULL },
|
|
|
|
|
{ GC_ARG_TYPE_NR, NULL }, { GC_ARG_TYPE_NR, NULL },
|
|
|
|
|
{ GC_ARG_TYPE_NR, NULL }, { GC_ARG_TYPE_NR, NULL },
|
|
|
|
|
{ GC_ARG_TYPE_NR, NULL }, { GC_ARG_TYPE_NR, NULL },
|
|
|
|
|
{ GC_ARG_TYPE_NR, NULL }, { GC_ARG_TYPE_NR, NULL },
|
|
|
|
|
{ GC_ARG_TYPE_NR, NULL }, { GC_ARG_TYPE_NR, NULL },
|
|
|
|
|
{ GC_ARG_TYPE_NR, NULL }, { GC_ARG_TYPE_NR, NULL },
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* The complex argument types have a basic type as fallback. */
|
2008-05-26 15:05:31 +00:00
|
|
|
|
{ GC_ARG_TYPE_STRING, "filename" },
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{ GC_ARG_TYPE_STRING, "ldap server" },
|
|
|
|
|
{ GC_ARG_TYPE_STRING, "key fpr" },
|
2008-02-27 17:32:47 +00:00
|
|
|
|
{ GC_ARG_TYPE_STRING, "pub key" },
|
|
|
|
|
{ GC_ARG_TYPE_STRING, "sec key" },
|
2008-06-19 13:09:40 +00:00
|
|
|
|
{ GC_ARG_TYPE_STRING, "alias list" },
|
2004-01-28 23:58:18 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Every option has an associated expert level, than can be used to
|
|
|
|
|
hide advanced and expert options from beginners. If you add to
|
|
|
|
|
this list, don't forget to update GC_LEVEL below. YOU MUST NOT
|
|
|
|
|
CHANGE THE NUMBERS OF THE EXISTING ENTRIES, AS THEY ARE PART OF THE
|
|
|
|
|
EXTERNAL INTERFACE. */
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
/* The basic options should always be displayed. */
|
|
|
|
|
GC_LEVEL_BASIC,
|
|
|
|
|
|
|
|
|
|
/* The advanced options may be hidden from beginners. */
|
|
|
|
|
GC_LEVEL_ADVANCED,
|
|
|
|
|
|
|
|
|
|
/* The expert options should only be displayed to experts. */
|
|
|
|
|
GC_LEVEL_EXPERT,
|
|
|
|
|
|
|
|
|
|
/* The invisible options should normally never be displayed. */
|
|
|
|
|
GC_LEVEL_INVISIBLE,
|
|
|
|
|
|
|
|
|
|
/* The internal options are never exported, they mark options that
|
|
|
|
|
are recorded for internal use only. */
|
|
|
|
|
GC_LEVEL_INTERNAL,
|
|
|
|
|
|
|
|
|
|
/* ADD NEW ENTRIES HERE. */
|
|
|
|
|
|
|
|
|
|
/* The number of the above entries. */
|
|
|
|
|
GC_LEVEL_NR
|
|
|
|
|
} gc_expert_level_t;
|
|
|
|
|
|
|
|
|
|
/* A description for each expert level. */
|
|
|
|
|
static struct
|
|
|
|
|
{
|
|
|
|
|
const char *name;
|
|
|
|
|
} gc_level[] =
|
|
|
|
|
{
|
|
|
|
|
{ "basic" },
|
|
|
|
|
{ "advanced" },
|
|
|
|
|
{ "expert" },
|
|
|
|
|
{ "invisible" },
|
|
|
|
|
{ "internal" }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2007-08-02 18:12:43 +00:00
|
|
|
|
/* Option flags. The flags which are used by the backends are defined
|
|
|
|
|
by gc-opt-flags.h, included above.
|
|
|
|
|
|
|
|
|
|
YOU MUST NOT CHANGE THE NUMBERS OF THE EXISTING FLAGS, AS THEY ARE
|
|
|
|
|
PART OF THE EXTERNAL INTERFACE. */
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* Some entries in the option list are not options, but mark the
|
|
|
|
|
beginning of a new group of options. These entries have the GROUP
|
|
|
|
|
flag set. */
|
2004-02-24 14:31:59 +00:00
|
|
|
|
#define GC_OPT_FLAG_GROUP (1UL << 0)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* The ARG_OPT flag for an option indicates that the argument is
|
2004-02-26 16:28:27 +00:00
|
|
|
|
optional. This is never set for GC_ARG_TYPE_NONE options. */
|
2004-02-24 14:31:59 +00:00
|
|
|
|
#define GC_OPT_FLAG_ARG_OPT (1UL << 1)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* The LIST flag for an option indicates that the option can occur
|
|
|
|
|
several times. A comma separated list of arguments is used as the
|
|
|
|
|
argument value. */
|
2004-02-24 14:31:59 +00:00
|
|
|
|
#define GC_OPT_FLAG_LIST (1UL << 2)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2007-08-02 18:12:43 +00:00
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* A human-readable description for each flag. */
|
|
|
|
|
static struct
|
|
|
|
|
{
|
|
|
|
|
const char *name;
|
|
|
|
|
} gc_flag[] =
|
|
|
|
|
{
|
|
|
|
|
{ "group" },
|
|
|
|
|
{ "optional arg" },
|
|
|
|
|
{ "list" },
|
2004-03-23 12:33:59 +00:00
|
|
|
|
{ "runtime" },
|
|
|
|
|
{ "default" },
|
|
|
|
|
{ "default desc" },
|
2007-03-06 20:44:41 +00:00
|
|
|
|
{ "no arg desc" },
|
|
|
|
|
{ "no change" }
|
2004-01-28 23:58:18 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* To each option, or group marker, the information in the GC_OPTION
|
|
|
|
|
struct is provided. If you change this, don't forget to update the
|
|
|
|
|
option list of each component. */
|
|
|
|
|
struct gc_option
|
|
|
|
|
{
|
|
|
|
|
/* If this is NULL, then this is a terminator in an array of unknown
|
|
|
|
|
length. Otherwise, if this entry is a group marker (see FLAGS),
|
|
|
|
|
then this is the name of the group described by this entry.
|
|
|
|
|
Otherwise it is the name of the option described by this
|
|
|
|
|
entry. The name must not contain a colon. */
|
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
|
|
/* The option flags. If the GROUP flag is set, then this entry is a
|
|
|
|
|
group marker, not an option, and only the fields LEVEL,
|
|
|
|
|
DESC_DOMAIN and DESC are valid. In all other cases, this entry
|
|
|
|
|
describes a new option and all fields are valid. */
|
2004-02-24 14:31:59 +00:00
|
|
|
|
unsigned long flags;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
|
|
|
|
/* The expert level. This field is valid for options and groups. A
|
|
|
|
|
group has the expert level of the lowest-level option in the
|
|
|
|
|
group. */
|
|
|
|
|
gc_expert_level_t level;
|
|
|
|
|
|
|
|
|
|
/* A gettext domain in which the following description can be found.
|
|
|
|
|
If this is NULL, then DESC is not translated. Valid for groups
|
2004-09-29 16:16:47 +00:00
|
|
|
|
and options.
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2004-09-29 16:16:47 +00:00
|
|
|
|
Note that we try to keep the description of groups within the
|
2011-02-23 10:15:34 +01:00
|
|
|
|
gnupg domain.
|
|
|
|
|
|
2004-10-01 12:53:09 +00:00
|
|
|
|
IMPORTANT: If you add a new domain please make sure to add a code
|
|
|
|
|
set switching call to the function my_dgettext further below. */
|
2004-01-28 23:58:18 +00:00
|
|
|
|
const char *desc_domain;
|
|
|
|
|
|
|
|
|
|
/* A gettext description for this group or option. If it starts
|
|
|
|
|
with a '|', then the string up to the next '|' describes the
|
2011-02-23 10:15:34 +01:00
|
|
|
|
argument, and the description follows the second '|'.
|
2004-09-29 16:16:47 +00:00
|
|
|
|
|
|
|
|
|
In general enclosing these description in N_() is not required
|
|
|
|
|
because the description should be identical to the one in the
|
|
|
|
|
help menu of the respective program. */
|
2004-01-28 23:58:18 +00:00
|
|
|
|
const char *desc;
|
|
|
|
|
|
|
|
|
|
/* The following fields are only valid for options. */
|
|
|
|
|
|
|
|
|
|
/* The type of the option argument. */
|
|
|
|
|
gc_arg_type_t arg_type;
|
|
|
|
|
|
|
|
|
|
/* The backend that implements this option. */
|
|
|
|
|
gc_backend_t backend;
|
|
|
|
|
|
|
|
|
|
/* The following fields are set to NULL at startup (because all
|
|
|
|
|
option's are declared as static variables). They are at the end
|
|
|
|
|
of the list so that they can be omitted from the option
|
|
|
|
|
declarations. */
|
|
|
|
|
|
2004-01-31 13:58:27 +00:00
|
|
|
|
/* This is true if the option is supported by this version of the
|
|
|
|
|
backend. */
|
|
|
|
|
int active;
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* The default value for this option. This is NULL if the option is
|
|
|
|
|
not present in the backend, the empty string if no default is
|
|
|
|
|
available, and otherwise a quoted string. */
|
|
|
|
|
char *default_value;
|
|
|
|
|
|
2004-02-24 14:31:59 +00:00
|
|
|
|
/* The default argument is only valid if the "optional arg" flag is
|
|
|
|
|
set, and specifies the default argument (value) that is used if
|
|
|
|
|
the argument is omitted. */
|
|
|
|
|
char *default_arg;
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* The current value of this option. */
|
|
|
|
|
char *value;
|
|
|
|
|
|
2004-02-25 20:24:53 +00:00
|
|
|
|
/* The new flags for this option. The only defined flag is actually
|
|
|
|
|
GC_OPT_FLAG_DEFAULT, and it means that the option should be
|
|
|
|
|
deleted. In this case, NEW_VALUE is NULL. */
|
|
|
|
|
unsigned long new_flags;
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* The new value of this option. */
|
|
|
|
|
char *new_value;
|
|
|
|
|
};
|
|
|
|
|
typedef struct gc_option gc_option_t;
|
|
|
|
|
|
|
|
|
|
/* Use this macro to terminate an option list. */
|
|
|
|
|
#define GC_OPTION_NULL { NULL }
|
|
|
|
|
|
|
|
|
|
|
2010-12-14 19:17:58 +00:00
|
|
|
|
#ifndef BUILD_WITH_AGENT
|
|
|
|
|
#define gc_options_gpg_agent NULL
|
|
|
|
|
#else
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* The options of the GC_COMPONENT_GPG_AGENT component. */
|
|
|
|
|
static gc_option_t gc_options_gpg_agent[] =
|
|
|
|
|
{
|
2004-03-16 10:48:13 +00:00
|
|
|
|
/* The configuration file to which we write the changes. */
|
2014-05-07 18:18:27 +02:00
|
|
|
|
{ GPGCONF_NAME"-" GPG_AGENT_NAME ".conf",
|
|
|
|
|
GC_OPT_FLAG_NONE, GC_LEVEL_INTERNAL,
|
2008-05-26 15:05:31 +00:00
|
|
|
|
NULL, NULL, GC_ARG_TYPE_FILENAME, GC_BACKEND_GPG_AGENT },
|
2004-03-16 10:48:13 +00:00
|
|
|
|
|
|
|
|
|
{ "Monitor",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_BASIC,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options controlling the diagnostic output") },
|
2004-04-30 03:03:34 +00:00
|
|
|
|
{ "verbose", GC_OPT_FLAG_LIST|GC_OPT_FLAG_RUNTIME, GC_LEVEL_BASIC,
|
2004-03-16 10:48:13 +00:00
|
|
|
|
"gnupg", "verbose",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPG_AGENT },
|
2004-04-30 03:03:34 +00:00
|
|
|
|
{ "quiet", GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_LEVEL_BASIC,
|
2004-03-16 10:48:13 +00:00
|
|
|
|
"gnupg", "be somewhat more quiet",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPG_AGENT },
|
|
|
|
|
{ "no-greeting", GC_OPT_FLAG_NONE, GC_LEVEL_INVISIBLE,
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPG_AGENT },
|
|
|
|
|
|
|
|
|
|
{ "Configuration",
|
2014-03-07 09:46:44 +01:00
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_BASIC,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options controlling the configuration") },
|
2004-03-16 10:48:13 +00:00
|
|
|
|
{ "options", GC_OPT_FLAG_NONE, GC_LEVEL_EXPERT,
|
|
|
|
|
"gnupg", "|FILE|read options from FILE",
|
2008-05-26 15:05:31 +00:00
|
|
|
|
GC_ARG_TYPE_FILENAME, GC_BACKEND_GPG_AGENT },
|
2005-04-21 09:33:07 +00:00
|
|
|
|
{ "disable-scdaemon", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
|
|
|
|
"gnupg", "do not use the SCdaemon",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPG_AGENT },
|
2014-03-07 09:46:44 +01:00
|
|
|
|
{ "enable-ssh-support", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"gnupg", "enable ssh support",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPG_AGENT },
|
|
|
|
|
{ "enable-putty-support", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"gnupg", "enable putty support",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPG_AGENT },
|
2004-03-16 10:48:13 +00:00
|
|
|
|
|
|
|
|
|
{ "Debug",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_ADVANCED,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options useful for debugging") },
|
2004-04-30 03:03:34 +00:00
|
|
|
|
{ "debug-level", GC_OPT_FLAG_ARG_OPT|GC_OPT_FLAG_RUNTIME, GC_LEVEL_ADVANCED,
|
2004-03-16 10:48:13 +00:00
|
|
|
|
"gnupg", "|LEVEL|set the debugging level to LEVEL",
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_GPG_AGENT },
|
2004-04-30 03:58:43 +00:00
|
|
|
|
{ "log-file", GC_OPT_FLAG_RUNTIME, GC_LEVEL_ADVANCED,
|
2004-10-01 12:53:09 +00:00
|
|
|
|
"gnupg", N_("|FILE|write server mode logs to FILE"),
|
2008-05-26 15:05:31 +00:00
|
|
|
|
GC_ARG_TYPE_FILENAME, GC_BACKEND_GPG_AGENT },
|
2004-03-16 10:48:13 +00:00
|
|
|
|
{ "faked-system-time", GC_OPT_FLAG_NONE, GC_LEVEL_INVISIBLE,
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
GC_ARG_TYPE_UINT32, GC_BACKEND_GPG_AGENT },
|
|
|
|
|
|
|
|
|
|
{ "Security",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_BASIC,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options controlling the security") },
|
2007-03-06 20:44:41 +00:00
|
|
|
|
{ "default-cache-ttl", GC_OPT_FLAG_RUNTIME,
|
2011-02-23 10:15:34 +01:00
|
|
|
|
GC_LEVEL_BASIC, "gnupg",
|
2007-03-06 20:44:41 +00:00
|
|
|
|
"|N|expire cached PINs after N seconds",
|
2004-03-16 10:48:13 +00:00
|
|
|
|
GC_ARG_TYPE_UINT32, GC_BACKEND_GPG_AGENT },
|
2007-03-06 20:44:41 +00:00
|
|
|
|
{ "default-cache-ttl-ssh", GC_OPT_FLAG_RUNTIME,
|
|
|
|
|
GC_LEVEL_ADVANCED, "gnupg",
|
|
|
|
|
N_("|N|expire SSH keys after N seconds"),
|
|
|
|
|
GC_ARG_TYPE_UINT32, GC_BACKEND_GPG_AGENT },
|
|
|
|
|
{ "max-cache-ttl", GC_OPT_FLAG_RUNTIME,
|
|
|
|
|
GC_LEVEL_EXPERT, "gnupg",
|
|
|
|
|
N_("|N|set maximum PIN cache lifetime to N seconds"),
|
|
|
|
|
GC_ARG_TYPE_UINT32, GC_BACKEND_GPG_AGENT },
|
|
|
|
|
{ "max-cache-ttl-ssh", GC_OPT_FLAG_RUNTIME,
|
2011-02-23 10:15:34 +01:00
|
|
|
|
GC_LEVEL_EXPERT, "gnupg",
|
2007-03-06 20:44:41 +00:00
|
|
|
|
N_("|N|set maximum SSH key lifetime to N seconds"),
|
|
|
|
|
GC_ARG_TYPE_UINT32, GC_BACKEND_GPG_AGENT },
|
|
|
|
|
{ "ignore-cache-for-signing", GC_OPT_FLAG_RUNTIME,
|
|
|
|
|
GC_LEVEL_BASIC, "gnupg", "do not use the PIN cache when signing",
|
2004-04-20 16:02:30 +00:00
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPG_AGENT },
|
2015-05-11 18:08:44 +02:00
|
|
|
|
{ "no-allow-external-cache", GC_OPT_FLAG_RUNTIME,
|
|
|
|
|
GC_LEVEL_BASIC, "gnupg", "disallow the use of an external password cache",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPG_AGENT },
|
2013-07-03 15:20:25 +02:00
|
|
|
|
{ "no-allow-mark-trusted", GC_OPT_FLAG_RUNTIME,
|
|
|
|
|
GC_LEVEL_ADVANCED, "gnupg", "disallow clients to mark keys as \"trusted\"",
|
2004-05-03 13:37:38 +00:00
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPG_AGENT },
|
2015-01-04 17:19:06 +01:00
|
|
|
|
{ "allow-loopback-pinentry", GC_OPT_FLAG_RUNTIME,
|
|
|
|
|
GC_LEVEL_EXPERT, "gnupg", "allow caller to override the pinentry",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPG_AGENT },
|
2004-04-30 03:03:34 +00:00
|
|
|
|
{ "no-grab", GC_OPT_FLAG_RUNTIME, GC_LEVEL_EXPERT,
|
2004-04-05 17:25:43 +00:00
|
|
|
|
"gnupg", "do not grab keyboard and mouse",
|
2004-03-16 10:48:13 +00:00
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPG_AGENT },
|
|
|
|
|
|
2007-08-27 18:10:27 +00:00
|
|
|
|
{ "Passphrase policy",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_ADVANCED,
|
|
|
|
|
"gnupg", N_("Options enforcing a passphrase policy") },
|
2011-02-23 10:15:34 +01:00
|
|
|
|
{ "enforce-passphrase-constraints", GC_OPT_FLAG_RUNTIME,
|
|
|
|
|
GC_LEVEL_EXPERT, "gnupg",
|
2007-08-27 18:10:27 +00:00
|
|
|
|
N_("do not allow to bypass the passphrase policy"),
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPG_AGENT },
|
|
|
|
|
{ "min-passphrase-len", GC_OPT_FLAG_RUNTIME,
|
2011-02-23 10:15:34 +01:00
|
|
|
|
GC_LEVEL_ADVANCED, "gnupg",
|
2007-08-27 18:10:27 +00:00
|
|
|
|
N_("|N|set minimal required length for new passphrases to N"),
|
|
|
|
|
GC_ARG_TYPE_UINT32, GC_BACKEND_GPG_AGENT },
|
|
|
|
|
{ "min-passphrase-nonalpha", GC_OPT_FLAG_RUNTIME,
|
2011-02-23 10:15:34 +01:00
|
|
|
|
GC_LEVEL_EXPERT, "gnupg",
|
2007-08-27 18:10:27 +00:00
|
|
|
|
N_("|N|require at least N non-alpha characters for a new passphrase"),
|
|
|
|
|
GC_ARG_TYPE_UINT32, GC_BACKEND_GPG_AGENT },
|
|
|
|
|
{ "check-passphrase-pattern", GC_OPT_FLAG_RUNTIME,
|
|
|
|
|
GC_LEVEL_EXPERT,
|
|
|
|
|
"gnupg", N_("|FILE|check new passphrases against pattern in FILE"),
|
2008-05-26 15:05:31 +00:00
|
|
|
|
GC_ARG_TYPE_FILENAME, GC_BACKEND_GPG_AGENT },
|
2007-08-28 17:48:13 +00:00
|
|
|
|
{ "max-passphrase-days", GC_OPT_FLAG_RUNTIME,
|
2011-02-23 10:15:34 +01:00
|
|
|
|
GC_LEVEL_EXPERT, "gnupg",
|
2007-08-28 17:48:13 +00:00
|
|
|
|
N_("|N|expire the passphrase after N days"),
|
|
|
|
|
GC_ARG_TYPE_UINT32, GC_BACKEND_GPG_AGENT },
|
2011-02-23 10:15:34 +01:00
|
|
|
|
{ "enable-passphrase-history", GC_OPT_FLAG_RUNTIME,
|
|
|
|
|
GC_LEVEL_EXPERT, "gnupg",
|
2007-08-28 17:48:13 +00:00
|
|
|
|
N_("do not allow the reuse of old passphrases"),
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPG_AGENT },
|
2007-08-27 18:10:27 +00:00
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
GC_OPTION_NULL
|
|
|
|
|
};
|
2010-12-14 19:17:58 +00:00
|
|
|
|
#endif /*BUILD_WITH_AGENT*/
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
|
|
|
|
|
2010-12-14 19:17:58 +00:00
|
|
|
|
#ifndef BUILD_WITH_SCDAEMON
|
|
|
|
|
#define gc_options_scdaemon NULL
|
|
|
|
|
#else
|
2004-02-18 17:00:56 +00:00
|
|
|
|
/* The options of the GC_COMPONENT_SCDAEMON component. */
|
|
|
|
|
static gc_option_t gc_options_scdaemon[] =
|
|
|
|
|
{
|
2004-03-16 19:00:25 +00:00
|
|
|
|
/* The configuration file to which we write the changes. */
|
2014-05-07 18:18:27 +02:00
|
|
|
|
{ GPGCONF_NAME"-"SCDAEMON_NAME".conf",
|
|
|
|
|
GC_OPT_FLAG_NONE, GC_LEVEL_INTERNAL,
|
2008-05-26 15:05:31 +00:00
|
|
|
|
NULL, NULL, GC_ARG_TYPE_FILENAME, GC_BACKEND_SCDAEMON },
|
2004-03-16 19:00:25 +00:00
|
|
|
|
|
|
|
|
|
{ "Monitor",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_BASIC,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options controlling the diagnostic output") },
|
2009-02-27 14:36:59 +00:00
|
|
|
|
{ "verbose", GC_OPT_FLAG_LIST|GC_OPT_FLAG_RUNTIME, GC_LEVEL_BASIC,
|
2004-03-16 19:00:25 +00:00
|
|
|
|
"gnupg", "verbose",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_SCDAEMON },
|
|
|
|
|
{ "quiet", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"gnupg", "be somewhat more quiet",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_SCDAEMON },
|
|
|
|
|
{ "no-greeting", GC_OPT_FLAG_NONE, GC_LEVEL_INVISIBLE,
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_SCDAEMON },
|
|
|
|
|
|
|
|
|
|
{ "Configuration",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_EXPERT,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options controlling the configuration") },
|
2004-03-16 19:00:25 +00:00
|
|
|
|
{ "options", GC_OPT_FLAG_NONE, GC_LEVEL_EXPERT,
|
|
|
|
|
"gnupg", "|FILE|read options from FILE",
|
2008-05-26 15:05:31 +00:00
|
|
|
|
GC_ARG_TYPE_FILENAME, GC_BACKEND_SCDAEMON },
|
2009-02-27 14:36:59 +00:00
|
|
|
|
{ "reader-port", GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_LEVEL_BASIC,
|
2004-03-16 19:00:25 +00:00
|
|
|
|
"gnupg", "|N|connect to reader at port N",
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_SCDAEMON },
|
2009-02-27 14:36:59 +00:00
|
|
|
|
{ "ctapi-driver", GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_LEVEL_ADVANCED,
|
2004-03-16 19:00:25 +00:00
|
|
|
|
"gnupg", "|NAME|use NAME as ct-API driver",
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_SCDAEMON },
|
2009-02-27 14:36:59 +00:00
|
|
|
|
{ "pcsc-driver", GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_LEVEL_ADVANCED,
|
2004-03-16 19:00:25 +00:00
|
|
|
|
"gnupg", "|NAME|use NAME as PC/SC driver",
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_SCDAEMON },
|
2009-02-27 14:36:59 +00:00
|
|
|
|
{ "disable-ccid", GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_LEVEL_EXPERT,
|
2004-03-16 19:00:25 +00:00
|
|
|
|
"gnupg", "do not use the internal CCID driver",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_SCDAEMON },
|
scd: Rename 'keypad' to 'pinpad'.
* NEWS: Mention scd changes.
* agent/divert-scd.c (getpin_cb): Change message.
* agent/call-scd.c (inq_needpin): Change the protocol to
POPUPPINPADPROMPT and DISMISSPINPADPROMPT.
* scd/command.c (pin_cb): Likewise.
* scd/apdu.c (struct reader_table_s): Rename member functions.
(check_pcsc_pinpad, pcsc_pinpad_verify, pcsc_pinpad_modify,
check_ccid_pinpad, ccid_pinpad_operation, apdu_check_pinpad
apdu_pinpad_verify, apdu_pinpad_modify): Rename.
* scd/apdu.h (SW_HOST_NO_PINPAD, apdu_check_pinpad)
(apdu_pinpad_verify, apdu_pinpad_modify): Rename.
* scd/iso7816.h (iso7816_check_pinpad): Rename.
* scd/iso7816.c (map_sw): Use SW_HOST_NO_PINPAD.
(iso7816_check_pinpad): Rename.
(iso7816_verify_kp, iso7816_change_reference_data_kp): Follow
the change.
* scd/ccid-driver.h (CCID_DRIVER_ERR_NO_PINPAD): Rename.
* scd/ccid-driver.c (ccid_transceive_secure): Use it.
* scd/app-dinsig.c (verify_pin): Follow the change.
* scd/app-nks.c (verify_pin): Follow the change.
* scd/app-openpgp.c (check_pinpad_request): Rename.
(parse_login_data, verify_a_chv, verify_chv3, do_change_pin): Follow
the change.
* scd/scdaemon.c (oDisablePinpad, oEnablePinpadVarlen): Rename.
* scd/scdaemon.h (opt): Rename to disable_pinpad,
enable_pinpad_varlen.
* tools/gpgconf-comp.c (gc_options_scdaemon): Rename to
disable-pinpad.
2013-02-07 10:07:51 +09:00
|
|
|
|
{ "disable-pinpad", GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_LEVEL_BASIC,
|
|
|
|
|
"gnupg", "do not use a reader's pinpad",
|
2013-08-21 15:44:52 +02:00
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_SCDAEMON },
|
|
|
|
|
{ "enable-pinpad-varlen",
|
|
|
|
|
GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_LEVEL_BASIC,
|
|
|
|
|
"gnupg", "use variable length input for pinpad",
|
2005-11-28 11:52:25 +00:00
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_SCDAEMON },
|
2009-02-27 14:36:59 +00:00
|
|
|
|
{ "card-timeout", GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_LEVEL_BASIC,
|
2008-12-05 12:01:01 +00:00
|
|
|
|
"gnupg", "|N|disconnect the card after N seconds of inactivity",
|
|
|
|
|
GC_ARG_TYPE_UINT32, GC_BACKEND_SCDAEMON },
|
2004-03-16 19:00:25 +00:00
|
|
|
|
|
|
|
|
|
{ "Debug",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_ADVANCED,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options useful for debugging") },
|
2009-02-27 14:36:59 +00:00
|
|
|
|
{ "debug-level", GC_OPT_FLAG_ARG_OPT|GC_OPT_FLAG_RUNTIME, GC_LEVEL_ADVANCED,
|
2004-03-16 19:00:25 +00:00
|
|
|
|
"gnupg", "|LEVEL|set the debugging level to LEVEL",
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_SCDAEMON },
|
2009-02-27 14:36:59 +00:00
|
|
|
|
{ "log-file", GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_LEVEL_ADVANCED,
|
2008-12-05 12:01:01 +00:00
|
|
|
|
"gnupg", N_("|FILE|write a log to FILE"),
|
2008-05-26 15:05:31 +00:00
|
|
|
|
GC_ARG_TYPE_FILENAME, GC_BACKEND_SCDAEMON },
|
2004-03-16 19:00:25 +00:00
|
|
|
|
|
|
|
|
|
{ "Security",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_BASIC,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options controlling the security") },
|
2009-02-27 14:36:59 +00:00
|
|
|
|
{ "deny-admin", GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_LEVEL_BASIC,
|
2009-01-28 14:18:40 +00:00
|
|
|
|
"gnupg", "deny the use of admin card commands",
|
2004-03-16 19:00:25 +00:00
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_SCDAEMON },
|
|
|
|
|
|
|
|
|
|
|
2004-02-18 17:00:56 +00:00
|
|
|
|
GC_OPTION_NULL
|
|
|
|
|
};
|
2010-12-14 19:17:58 +00:00
|
|
|
|
#endif /*BUILD_WITH_SCDAEMON*/
|
2004-02-18 17:00:56 +00:00
|
|
|
|
|
2010-12-14 19:17:58 +00:00
|
|
|
|
#ifndef BUILD_WITH_GPG
|
|
|
|
|
#define gc_options_gpg NULL
|
|
|
|
|
#else
|
2004-03-23 13:04:34 +00:00
|
|
|
|
/* The options of the GC_COMPONENT_GPG component. */
|
|
|
|
|
static gc_option_t gc_options_gpg[] =
|
|
|
|
|
{
|
|
|
|
|
/* The configuration file to which we write the changes. */
|
2014-05-07 18:18:27 +02:00
|
|
|
|
{ GPGCONF_NAME"-"GPG_NAME".conf",
|
|
|
|
|
GC_OPT_FLAG_NONE, GC_LEVEL_INTERNAL,
|
2008-05-26 15:05:31 +00:00
|
|
|
|
NULL, NULL, GC_ARG_TYPE_FILENAME, GC_BACKEND_GPG },
|
2004-03-23 13:04:34 +00:00
|
|
|
|
|
|
|
|
|
{ "Monitor",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_BASIC,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options controlling the diagnostic output") },
|
2004-03-23 13:04:34 +00:00
|
|
|
|
{ "verbose", GC_OPT_FLAG_LIST, GC_LEVEL_BASIC,
|
|
|
|
|
"gnupg", "verbose",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPG },
|
|
|
|
|
{ "quiet", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"gnupg", "be somewhat more quiet",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPG },
|
|
|
|
|
{ "no-greeting", GC_OPT_FLAG_NONE, GC_LEVEL_INVISIBLE,
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPG },
|
|
|
|
|
|
|
|
|
|
{ "Configuration",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_EXPERT,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options controlling the configuration") },
|
2007-07-17 18:11:24 +00:00
|
|
|
|
{ "default-key", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"gnupg", N_("|NAME|use NAME as default secret key"),
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_GPG },
|
|
|
|
|
{ "encrypt-to", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"gnupg", N_("|NAME|encrypt to user ID NAME as well"),
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_GPG },
|
2008-06-19 13:09:40 +00:00
|
|
|
|
{ "group", GC_OPT_FLAG_LIST, GC_LEVEL_ADVANCED,
|
|
|
|
|
"gnupg", N_("|SPEC|set up email aliases"),
|
|
|
|
|
GC_ARG_TYPE_ALIAS_LIST, GC_BACKEND_GPG },
|
2004-03-23 13:04:34 +00:00
|
|
|
|
{ "options", GC_OPT_FLAG_NONE, GC_LEVEL_EXPERT,
|
|
|
|
|
"gnupg", "|FILE|read options from FILE",
|
2008-05-26 15:05:31 +00:00
|
|
|
|
GC_ARG_TYPE_FILENAME, GC_BACKEND_GPG },
|
2009-11-23 19:18:04 +00:00
|
|
|
|
{ "default_pubkey_algo",
|
|
|
|
|
(GC_OPT_FLAG_ARG_OPT|GC_OPT_FLAG_NO_CHANGE), GC_LEVEL_INVISIBLE,
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_GPG },
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2004-03-23 13:04:34 +00:00
|
|
|
|
|
|
|
|
|
{ "Debug",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_ADVANCED,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options useful for debugging") },
|
2004-03-23 13:04:34 +00:00
|
|
|
|
{ "debug-level", GC_OPT_FLAG_ARG_OPT, GC_LEVEL_ADVANCED,
|
|
|
|
|
"gnupg", "|LEVEL|set the debugging level to LEVEL",
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_GPG },
|
|
|
|
|
{ "log-file", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
2004-10-01 16:51:18 +00:00
|
|
|
|
"gnupg", N_("|FILE|write server mode logs to FILE"),
|
2008-05-26 15:05:31 +00:00
|
|
|
|
GC_ARG_TYPE_FILENAME, GC_BACKEND_GPG },
|
2004-03-23 13:04:34 +00:00
|
|
|
|
/* { "faked-system-time", GC_OPT_FLAG_NONE, GC_LEVEL_INVISIBLE, */
|
|
|
|
|
/* NULL, NULL, */
|
|
|
|
|
/* GC_ARG_TYPE_UINT32, GC_BACKEND_GPG }, */
|
|
|
|
|
|
2004-03-23 13:48:46 +00:00
|
|
|
|
{ "Keyserver",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_BASIC,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Configuration for Keyservers") },
|
2004-03-23 13:48:46 +00:00
|
|
|
|
{ "keyserver", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
2007-09-14 11:41:14 +00:00
|
|
|
|
"gnupg", N_("|URL|use keyserver at URL"),
|
2004-03-23 13:48:46 +00:00
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_GPG },
|
2006-02-06 18:31:27 +00:00
|
|
|
|
{ "allow-pka-lookup", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"gnupg", N_("allow PKA lookups (DNS requests)"),
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPG },
|
2008-04-08 11:04:16 +00:00
|
|
|
|
{ "auto-key-locate", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
|
|
|
|
"gnupg", N_("|MECHANISMS|use MECHANISMS to locate keys by mail address"),
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_GPG },
|
2004-03-23 13:48:46 +00:00
|
|
|
|
|
2004-03-23 13:04:34 +00:00
|
|
|
|
|
2009-11-23 19:18:04 +00:00
|
|
|
|
|
|
|
|
|
|
2004-03-23 13:04:34 +00:00
|
|
|
|
GC_OPTION_NULL
|
|
|
|
|
};
|
2010-12-14 19:17:58 +00:00
|
|
|
|
#endif /*BUILD_WITH_GPG*/
|
2004-03-23 13:04:34 +00:00
|
|
|
|
|
|
|
|
|
|
2010-12-14 19:17:58 +00:00
|
|
|
|
#ifndef BUILD_WITH_GPGSM
|
|
|
|
|
#define gc_options_gpgsm NULL
|
|
|
|
|
#else
|
2004-02-18 17:00:56 +00:00
|
|
|
|
/* The options of the GC_COMPONENT_GPGSM component. */
|
|
|
|
|
static gc_option_t gc_options_gpgsm[] =
|
|
|
|
|
{
|
2004-03-16 19:00:25 +00:00
|
|
|
|
/* The configuration file to which we write the changes. */
|
2014-05-07 18:18:27 +02:00
|
|
|
|
{ GPGCONF_NAME"-"GPGSM_NAME".conf",
|
|
|
|
|
GC_OPT_FLAG_NONE, GC_LEVEL_INTERNAL,
|
2008-05-26 15:05:31 +00:00
|
|
|
|
NULL, NULL, GC_ARG_TYPE_FILENAME, GC_BACKEND_GPGSM },
|
2004-03-16 19:00:25 +00:00
|
|
|
|
|
|
|
|
|
{ "Monitor",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_BASIC,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options controlling the diagnostic output") },
|
2004-03-16 19:00:25 +00:00
|
|
|
|
{ "verbose", GC_OPT_FLAG_LIST, GC_LEVEL_BASIC,
|
|
|
|
|
"gnupg", "verbose",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPGSM },
|
|
|
|
|
{ "quiet", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"gnupg", "be somewhat more quiet",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPGSM },
|
|
|
|
|
{ "no-greeting", GC_OPT_FLAG_NONE, GC_LEVEL_INVISIBLE,
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPGSM },
|
|
|
|
|
|
|
|
|
|
{ "Configuration",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_EXPERT,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options controlling the configuration") },
|
2007-07-17 18:11:24 +00:00
|
|
|
|
{ "default-key", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"gnupg", N_("|NAME|use NAME as default secret key"),
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_GPGSM },
|
|
|
|
|
{ "encrypt-to", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"gnupg", N_("|NAME|encrypt to user ID NAME as well"),
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_GPGSM },
|
2004-03-16 19:00:25 +00:00
|
|
|
|
{ "options", GC_OPT_FLAG_NONE, GC_LEVEL_EXPERT,
|
|
|
|
|
"gnupg", "|FILE|read options from FILE",
|
2008-05-26 15:05:31 +00:00
|
|
|
|
GC_ARG_TYPE_FILENAME, GC_BACKEND_GPGSM },
|
2004-11-23 17:09:51 +00:00
|
|
|
|
{ "prefer-system-dirmngr", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
|
|
|
|
"gnupg", "use system's dirmngr if available",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPGSM },
|
2008-02-19 10:33:35 +00:00
|
|
|
|
{ "disable-dirmngr", GC_OPT_FLAG_NONE, GC_LEVEL_EXPERT,
|
|
|
|
|
"gnupg", N_("disable all access to the dirmngr"),
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPGSM },
|
2007-03-20 10:17:05 +00:00
|
|
|
|
{ "p12-charset", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
|
|
|
|
"gnupg", N_("|NAME|use encoding NAME for PKCS#12 passphrases"),
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_GPGSM },
|
2008-06-12 14:24:46 +00:00
|
|
|
|
{ "keyserver", GC_OPT_FLAG_LIST, GC_LEVEL_BASIC,
|
|
|
|
|
"gnupg", N_("|SPEC|use this keyserver to lookup keys"),
|
2008-08-06 14:38:41 +00:00
|
|
|
|
GC_ARG_TYPE_LDAP_SERVER, GC_BACKEND_GPGSM },
|
2009-11-23 19:18:04 +00:00
|
|
|
|
{ "default_pubkey_algo",
|
|
|
|
|
(GC_OPT_FLAG_ARG_OPT|GC_OPT_FLAG_NO_CHANGE), GC_LEVEL_INVISIBLE,
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_GPGSM },
|
2004-03-16 19:00:25 +00:00
|
|
|
|
|
|
|
|
|
{ "Debug",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_ADVANCED,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options useful for debugging") },
|
2004-03-16 19:00:25 +00:00
|
|
|
|
{ "debug-level", GC_OPT_FLAG_ARG_OPT, GC_LEVEL_ADVANCED,
|
|
|
|
|
"gnupg", "|LEVEL|set the debugging level to LEVEL",
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_GPGSM },
|
|
|
|
|
{ "log-file", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
2004-10-01 16:51:18 +00:00
|
|
|
|
"gnupg", N_("|FILE|write server mode logs to FILE"),
|
2008-05-26 15:05:31 +00:00
|
|
|
|
GC_ARG_TYPE_FILENAME, GC_BACKEND_GPGSM },
|
2004-03-16 19:00:25 +00:00
|
|
|
|
{ "faked-system-time", GC_OPT_FLAG_NONE, GC_LEVEL_INVISIBLE,
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
GC_ARG_TYPE_UINT32, GC_BACKEND_GPGSM },
|
|
|
|
|
|
|
|
|
|
{ "Security",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_BASIC,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options controlling the security") },
|
2004-03-16 19:00:25 +00:00
|
|
|
|
{ "disable-crl-checks", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"gnupg", "never consult a CRL",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPGSM },
|
2005-04-21 09:33:07 +00:00
|
|
|
|
{ "disable-trusted-cert-crl-check", GC_OPT_FLAG_NONE, GC_LEVEL_EXPERT,
|
|
|
|
|
"gnupg", N_("do not check CRLs for root certificates"),
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPGSM },
|
2004-03-16 19:00:25 +00:00
|
|
|
|
{ "enable-ocsp", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
|
|
|
|
"gnupg", "check validity using OCSP",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPGSM },
|
|
|
|
|
{ "include-certs", GC_OPT_FLAG_NONE, GC_LEVEL_EXPERT,
|
|
|
|
|
"gnupg", "|N|number of certificates to include",
|
|
|
|
|
GC_ARG_TYPE_INT32, GC_BACKEND_GPGSM },
|
|
|
|
|
{ "disable-policy-checks", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
|
|
|
|
"gnupg", "do not check certificate policies",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPGSM },
|
|
|
|
|
{ "auto-issuer-key-retrieve", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"gnupg", "fetch missing issuer certificates",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_GPGSM },
|
2006-10-23 14:02:13 +00:00
|
|
|
|
{ "cipher-algo", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
|
|
|
|
"gnupg", "|NAME|use cipher algorithm NAME",
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_GPGSM },
|
2004-03-16 19:00:25 +00:00
|
|
|
|
|
2004-02-18 17:00:56 +00:00
|
|
|
|
GC_OPTION_NULL
|
|
|
|
|
};
|
2010-12-14 19:17:58 +00:00
|
|
|
|
#endif /*BUILD_WITH_GPGSM*/
|
2004-02-18 17:00:56 +00:00
|
|
|
|
|
|
|
|
|
|
2010-12-14 19:17:58 +00:00
|
|
|
|
#ifndef BUILD_WITH_DIRMNGR
|
|
|
|
|
#define gc_options_dirmngr NULL
|
|
|
|
|
#else
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* The options of the GC_COMPONENT_DIRMNGR component. */
|
|
|
|
|
static gc_option_t gc_options_dirmngr[] =
|
|
|
|
|
{
|
|
|
|
|
/* The configuration file to which we write the changes. */
|
2014-05-07 18:18:27 +02:00
|
|
|
|
{ GPGCONF_NAME"-"DIRMNGR_NAME".conf",
|
|
|
|
|
GC_OPT_FLAG_NONE, GC_LEVEL_INTERNAL,
|
2008-05-26 15:05:31 +00:00
|
|
|
|
NULL, NULL, GC_ARG_TYPE_FILENAME, GC_BACKEND_DIRMNGR },
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
|
|
|
|
{ "Monitor",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_BASIC,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options controlling the diagnostic output") },
|
2004-01-31 13:58:27 +00:00
|
|
|
|
{ "verbose", GC_OPT_FLAG_LIST, GC_LEVEL_BASIC,
|
2004-01-28 23:58:18 +00:00
|
|
|
|
"dirmngr", "verbose",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_DIRMNGR },
|
|
|
|
|
{ "quiet", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"dirmngr", "be somewhat more quiet",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_DIRMNGR },
|
|
|
|
|
{ "no-greeting", GC_OPT_FLAG_NONE, GC_LEVEL_INVISIBLE,
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_DIRMNGR },
|
|
|
|
|
|
|
|
|
|
{ "Format",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_BASIC,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options controlling the format of the output") },
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{ "sh", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"dirmngr", "sh-style command output",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_DIRMNGR },
|
|
|
|
|
{ "csh", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"dirmngr", "csh-style command output",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_DIRMNGR },
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{ "Configuration",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_EXPERT,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options controlling the configuration") },
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{ "options", GC_OPT_FLAG_NONE, GC_LEVEL_EXPERT,
|
|
|
|
|
"dirmngr", "|FILE|read options from FILE",
|
2008-05-26 15:05:31 +00:00
|
|
|
|
GC_ARG_TYPE_FILENAME, GC_BACKEND_DIRMNGR },
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
|
|
|
|
{ "Debug",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_ADVANCED,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options useful for debugging") },
|
2004-03-16 19:00:25 +00:00
|
|
|
|
{ "debug-level", GC_OPT_FLAG_ARG_OPT, GC_LEVEL_ADVANCED,
|
|
|
|
|
"dirmngr", "|LEVEL|set the debugging level to LEVEL",
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_DIRMNGR },
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{ "no-detach", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
|
|
|
|
"dirmngr", "do not detach from the console",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_DIRMNGR },
|
|
|
|
|
{ "log-file", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
2004-10-01 16:51:18 +00:00
|
|
|
|
"dirmngr", N_("|FILE|write server mode logs to FILE"),
|
2008-05-26 15:05:31 +00:00
|
|
|
|
GC_ARG_TYPE_FILENAME, GC_BACKEND_DIRMNGR },
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{ "debug-wait", GC_OPT_FLAG_NONE, GC_LEVEL_INVISIBLE,
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
GC_ARG_TYPE_UINT32, GC_BACKEND_DIRMNGR },
|
|
|
|
|
{ "faked-system-time", GC_OPT_FLAG_NONE, GC_LEVEL_INVISIBLE,
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
GC_ARG_TYPE_UINT32, GC_BACKEND_DIRMNGR },
|
|
|
|
|
|
|
|
|
|
{ "Enforcement",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_BASIC,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Options controlling the interactivity and enforcement") },
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{ "batch", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"dirmngr", "run without asking a user",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_DIRMNGR },
|
|
|
|
|
{ "force", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"dirmngr", "force loading of outdated CRLs",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_DIRMNGR },
|
|
|
|
|
|
2004-11-23 17:09:51 +00:00
|
|
|
|
{ "HTTP",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_ADVANCED,
|
|
|
|
|
"gnupg", N_("Configuration for HTTP servers") },
|
|
|
|
|
{ "disable-http", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
|
|
|
|
"dirmngr", "inhibit the use of HTTP",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_DIRMNGR },
|
2004-11-24 10:43:53 +00:00
|
|
|
|
{ "ignore-http-dp", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
|
|
|
|
"dirmngr", "ignore HTTP CRL distribution points",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_DIRMNGR },
|
2004-11-23 17:09:51 +00:00
|
|
|
|
{ "http-proxy", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
|
|
|
|
"dirmngr", "|URL|redirect all HTTP requests to URL",
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_DIRMNGR },
|
2005-03-09 10:11:14 +00:00
|
|
|
|
{ "honor-http-proxy", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
2008-01-22 12:06:00 +00:00
|
|
|
|
"gnupg", N_("use system's HTTP proxy setting"),
|
2005-03-09 19:22:54 +00:00
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_DIRMNGR },
|
2004-11-23 17:09:51 +00:00
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{ "LDAP",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_BASIC,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Configuration of LDAP servers to use") },
|
2004-11-23 17:09:51 +00:00
|
|
|
|
{ "disable-ldap", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
|
|
|
|
"dirmngr", "inhibit the use of LDAP",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_DIRMNGR },
|
2004-11-24 10:43:53 +00:00
|
|
|
|
{ "ignore-ldap-dp", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
|
|
|
|
"dirmngr", "ignore LDAP CRL distribution points",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_DIRMNGR },
|
2004-11-23 17:09:51 +00:00
|
|
|
|
{ "ldap-proxy", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"dirmngr", "|HOST|use HOST for LDAP queries",
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_DIRMNGR },
|
|
|
|
|
{ "only-ldap-proxy", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
|
|
|
|
"dirmngr", "do not use fallback hosts with --ldap-proxy",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_DIRMNGR },
|
|
|
|
|
{ "add-servers", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
2004-01-28 23:58:18 +00:00
|
|
|
|
"dirmngr", "add new servers discovered in CRL distribution points"
|
|
|
|
|
" to serverlist", GC_ARG_TYPE_NONE, GC_BACKEND_DIRMNGR },
|
|
|
|
|
{ "ldaptimeout", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"dirmngr", "|N|set LDAP timeout to N seconds",
|
|
|
|
|
GC_ARG_TYPE_UINT32, GC_BACKEND_DIRMNGR },
|
|
|
|
|
/* The following entry must not be removed, as it is required for
|
|
|
|
|
the GC_BACKEND_DIRMNGR_LDAP_SERVER_LIST. */
|
|
|
|
|
{ "ldapserverlist-file",
|
|
|
|
|
GC_OPT_FLAG_NONE, GC_LEVEL_INTERNAL,
|
|
|
|
|
"dirmngr", "|FILE|read LDAP server list from FILE",
|
2008-05-26 15:05:31 +00:00
|
|
|
|
GC_ARG_TYPE_FILENAME, GC_BACKEND_DIRMNGR },
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* This entry must come after at least one entry for
|
|
|
|
|
GC_BACKEND_DIRMNGR in this component, so that the entry for
|
|
|
|
|
"ldapserverlist-file will be initialized before this one. */
|
2004-03-23 18:27:37 +00:00
|
|
|
|
{ "LDAP Server", GC_OPT_FLAG_ARG_OPT|GC_OPT_FLAG_LIST, GC_LEVEL_BASIC,
|
2008-01-22 12:06:00 +00:00
|
|
|
|
"gnupg", N_("LDAP server list"),
|
2004-01-28 23:58:18 +00:00
|
|
|
|
GC_ARG_TYPE_LDAP_SERVER, GC_BACKEND_DIRMNGR_LDAP_SERVER_LIST },
|
|
|
|
|
{ "max-replies", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"dirmngr", "|N|do not return more than N items in one query",
|
|
|
|
|
GC_ARG_TYPE_UINT32, GC_BACKEND_DIRMNGR },
|
|
|
|
|
|
2004-03-16 10:48:13 +00:00
|
|
|
|
{ "OCSP",
|
|
|
|
|
GC_OPT_FLAG_GROUP, GC_LEVEL_ADVANCED,
|
2004-09-29 16:16:47 +00:00
|
|
|
|
"gnupg", N_("Configuration for OCSP") },
|
2004-03-23 18:43:25 +00:00
|
|
|
|
{ "allow-ocsp", GC_OPT_FLAG_NONE, GC_LEVEL_BASIC,
|
|
|
|
|
"dirmngr", "allow sending OCSP requests",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_DIRMNGR },
|
2004-12-13 15:49:56 +00:00
|
|
|
|
{ "ignore-ocsp-service-url", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
2004-11-24 14:50:20 +00:00
|
|
|
|
"dirmngr", "ignore certificate contained OCSP service URLs",
|
|
|
|
|
GC_ARG_TYPE_NONE, GC_BACKEND_DIRMNGR },
|
2004-03-16 10:48:13 +00:00
|
|
|
|
{ "ocsp-responder", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
2004-10-01 12:53:09 +00:00
|
|
|
|
"dirmngr", "|URL|use OCSP responder at URL",
|
2004-03-16 10:48:13 +00:00
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_DIRMNGR },
|
2004-04-28 09:04:03 +00:00
|
|
|
|
{ "ocsp-signer", GC_OPT_FLAG_NONE, GC_LEVEL_ADVANCED,
|
|
|
|
|
"dirmngr", "|FPR|OCSP response signed by FPR",
|
|
|
|
|
GC_ARG_TYPE_STRING, GC_BACKEND_DIRMNGR },
|
2004-03-16 10:48:13 +00:00
|
|
|
|
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
GC_OPTION_NULL
|
|
|
|
|
};
|
2010-12-14 19:17:58 +00:00
|
|
|
|
#endif /*BUILD_WITH_DIRMNGR*/
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2010-08-19 09:53:55 +00:00
|
|
|
|
|
|
|
|
|
/* The options of the GC_COMPONENT_PINENTRY component. */
|
|
|
|
|
static gc_option_t gc_options_pinentry[] =
|
|
|
|
|
{
|
|
|
|
|
/* A dummy option to allow gc_component_list_components to find the
|
|
|
|
|
pinentry backend. Needs to be a conf file. */
|
2014-05-07 18:18:27 +02:00
|
|
|
|
{ GPGCONF_NAME"-pinentry.conf",
|
|
|
|
|
GC_OPT_FLAG_NONE, GC_LEVEL_INTERNAL,
|
2010-08-19 09:53:55 +00:00
|
|
|
|
NULL, NULL, GC_ARG_TYPE_FILENAME, GC_BACKEND_PINENTRY },
|
|
|
|
|
|
|
|
|
|
GC_OPTION_NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
|
|
|
|
/* Component system. Each component is a set of options that can be
|
|
|
|
|
configured at the same time. If you change this, don't forget to
|
|
|
|
|
update GC_COMPONENT below. */
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
2004-03-23 13:48:46 +00:00
|
|
|
|
/* The classic GPG for OpenPGP. */
|
|
|
|
|
GC_COMPONENT_GPG,
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* The GPG Agent. */
|
|
|
|
|
GC_COMPONENT_GPG_AGENT,
|
|
|
|
|
|
2004-02-18 17:00:56 +00:00
|
|
|
|
/* The Smardcard Daemon. */
|
|
|
|
|
GC_COMPONENT_SCDAEMON,
|
|
|
|
|
|
|
|
|
|
/* GPG for S/MIME. */
|
|
|
|
|
GC_COMPONENT_GPGSM,
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* The LDAP Directory Manager for CRLs. */
|
|
|
|
|
GC_COMPONENT_DIRMNGR,
|
|
|
|
|
|
2010-08-19 09:53:55 +00:00
|
|
|
|
/* The external Pinentry. */
|
|
|
|
|
GC_COMPONENT_PINENTRY,
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* The number of components. */
|
|
|
|
|
GC_COMPONENT_NR
|
|
|
|
|
} gc_component_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* The information associated with each component. */
|
|
|
|
|
static struct
|
|
|
|
|
{
|
|
|
|
|
/* The name of this component. Must not contain a colon (':')
|
|
|
|
|
character. */
|
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
|
|
/* The gettext domain for the description DESC. If this is NULL,
|
|
|
|
|
then the description is not translated. */
|
|
|
|
|
const char *desc_domain;
|
|
|
|
|
|
|
|
|
|
/* The description for this domain. */
|
|
|
|
|
const char *desc;
|
|
|
|
|
|
|
|
|
|
/* The list of options for this component, terminated by
|
|
|
|
|
GC_OPTION_NULL. */
|
|
|
|
|
gc_option_t *options;
|
|
|
|
|
} gc_component[] =
|
|
|
|
|
{
|
2011-08-26 15:20:41 +02:00
|
|
|
|
{ "gpg", "gnupg", N_("GPG for OpenPGP"), gc_options_gpg },
|
|
|
|
|
{ "gpg-agent","gnupg", N_("GPG Agent"), gc_options_gpg_agent },
|
|
|
|
|
{ "scdaemon", "gnupg", N_("Smartcard Daemon"), gc_options_scdaemon },
|
|
|
|
|
{ "gpgsm", "gnupg", N_("GPG for S/MIME"), gc_options_gpgsm },
|
|
|
|
|
{ "dirmngr", "gnupg", N_("Directory Manager"), gc_options_dirmngr },
|
|
|
|
|
{ "pinentry", "gnupg", N_("PIN and Passphrase Entry"), gc_options_pinentry }
|
2004-01-28 23:58:18 +00:00
|
|
|
|
};
|
|
|
|
|
|
2007-08-29 16:59:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Structure used to collect error output of the backend programs. */
|
|
|
|
|
struct error_line_s;
|
|
|
|
|
typedef struct error_line_s *error_line_t;
|
|
|
|
|
struct error_line_s
|
|
|
|
|
{
|
|
|
|
|
error_line_t next; /* Link to next item. */
|
|
|
|
|
const char *fname; /* Name of the config file (points into BUFFER). */
|
|
|
|
|
unsigned int lineno; /* Line number of the config file. */
|
|
|
|
|
const char *errtext; /* Text of the error message (points into BUFFER). */
|
|
|
|
|
char buffer[1]; /* Helper buffer. */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2004-03-23 12:21:48 +00:00
|
|
|
|
|
|
|
|
|
/* Engine specific support. */
|
2009-02-27 14:36:59 +00:00
|
|
|
|
static void
|
2011-02-23 10:15:34 +01:00
|
|
|
|
gpg_agent_runtime_change (int killflag)
|
2004-03-23 12:21:48 +00:00
|
|
|
|
{
|
2008-05-26 12:00:55 +00:00
|
|
|
|
gpg_error_t err;
|
|
|
|
|
const char *pgmname;
|
2014-11-19 10:31:34 +01:00
|
|
|
|
const char *argv[3];
|
2008-05-26 12:00:55 +00:00
|
|
|
|
pid_t pid;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2008-05-26 12:00:55 +00:00
|
|
|
|
pgmname = gnupg_module_name (GNUPG_MODULE_NAME_CONNECT_AGENT);
|
2014-11-19 10:31:34 +01:00
|
|
|
|
argv[0] = "--no-autostart";
|
|
|
|
|
argv[1] = killflag? "KILLAGENT" : "RELOADAGENT";
|
|
|
|
|
argv[2] = NULL;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2008-05-26 12:00:55 +00:00
|
|
|
|
err = gnupg_spawn_process_fd (pgmname, argv, -1, -1, -1, &pid);
|
|
|
|
|
if (!err)
|
2010-06-24 10:51:30 +00:00
|
|
|
|
err = gnupg_wait_process (pgmname, pid, 1, NULL);
|
2008-05-26 12:00:55 +00:00
|
|
|
|
if (err)
|
2014-11-19 10:31:34 +01:00
|
|
|
|
gc_error (0, 0, "error running '%s %s': %s",
|
|
|
|
|
pgmname, argv[1], gpg_strerror (err));
|
2010-06-09 16:53:51 +00:00
|
|
|
|
gnupg_release_process (pid);
|
2004-03-23 12:21:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-05-26 12:00:55 +00:00
|
|
|
|
|
2009-02-27 14:36:59 +00:00
|
|
|
|
static void
|
2011-02-23 10:15:34 +01:00
|
|
|
|
scdaemon_runtime_change (int killflag)
|
2009-02-27 14:36:59 +00:00
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
|
|
|
|
const char *pgmname;
|
2014-11-19 10:31:34 +01:00
|
|
|
|
const char *argv[7];
|
2009-02-27 14:36:59 +00:00
|
|
|
|
pid_t pid;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
|
|
|
|
(void)killflag; /* For scdaemon kill and reload are synonyms. */
|
|
|
|
|
|
2009-03-03 09:02:58 +00:00
|
|
|
|
/* We use "GETINFO app_running" to see whether the agent is already
|
|
|
|
|
running and kill it only in this case. This avoids an explicit
|
|
|
|
|
starting of the agent in case it is not yet running. There is
|
|
|
|
|
obviously a race condition but that should not harm too much. */
|
|
|
|
|
|
2009-02-27 14:36:59 +00:00
|
|
|
|
pgmname = gnupg_module_name (GNUPG_MODULE_NAME_CONNECT_AGENT);
|
2009-03-03 09:02:58 +00:00
|
|
|
|
argv[0] = "-s";
|
2014-11-19 10:31:34 +01:00
|
|
|
|
argv[1] = "--no-autostart";
|
|
|
|
|
argv[2] = "GETINFO scd_running";
|
|
|
|
|
argv[3] = "/if ${! $?}";
|
|
|
|
|
argv[4] = "scd killscd";
|
|
|
|
|
argv[5] = "/end";
|
|
|
|
|
argv[6] = NULL;
|
|
|
|
|
|
|
|
|
|
err = gnupg_spawn_process_fd (pgmname, argv, -1, -1, -1, &pid);
|
|
|
|
|
if (!err)
|
|
|
|
|
err = gnupg_wait_process (pgmname, pid, 1, NULL);
|
|
|
|
|
if (err)
|
|
|
|
|
gc_error (0, 0, "error running '%s %s': %s",
|
|
|
|
|
pgmname, argv[4], gpg_strerror (err));
|
|
|
|
|
gnupg_release_process (pid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
dirmngr_runtime_change (int killflag)
|
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
|
|
|
|
const char *pgmname;
|
|
|
|
|
const char *argv[4];
|
|
|
|
|
pid_t pid;
|
|
|
|
|
|
|
|
|
|
pgmname = gnupg_module_name (GNUPG_MODULE_NAME_CONNECT_AGENT);
|
|
|
|
|
argv[0] = "--no-autostart";
|
|
|
|
|
argv[1] = "--dirmngr";
|
|
|
|
|
argv[2] = killflag? "KILLDIRMNGR" : "RELOADDIRMNGR";
|
|
|
|
|
argv[3] = NULL;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2009-02-27 14:36:59 +00:00
|
|
|
|
err = gnupg_spawn_process_fd (pgmname, argv, -1, -1, -1, &pid);
|
|
|
|
|
if (!err)
|
2010-06-24 10:51:30 +00:00
|
|
|
|
err = gnupg_wait_process (pgmname, pid, 1, NULL);
|
2009-02-27 14:36:59 +00:00
|
|
|
|
if (err)
|
2014-11-19 10:31:34 +01:00
|
|
|
|
gc_error (0, 0, "error running '%s %s': %s",
|
|
|
|
|
pgmname, argv[2], gpg_strerror (err));
|
2010-06-09 16:53:51 +00:00
|
|
|
|
gnupg_release_process (pid);
|
2009-02-27 14:36:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-04-08 15:55:51 +02:00
|
|
|
|
/* Launch the gpg-agent or the dirmngr if not already running. */
|
2014-12-17 10:36:24 +01:00
|
|
|
|
gpg_error_t
|
2014-04-08 15:55:51 +02:00
|
|
|
|
gc_component_launch (int component)
|
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
|
|
|
|
const char *pgmname;
|
|
|
|
|
const char *argv[3];
|
|
|
|
|
int i;
|
|
|
|
|
pid_t pid;
|
|
|
|
|
|
|
|
|
|
if (!(component == GC_COMPONENT_GPG_AGENT
|
|
|
|
|
|| component == GC_COMPONENT_DIRMNGR))
|
|
|
|
|
{
|
|
|
|
|
es_fputs (_("Component not suitable for launching"), es_stderr);
|
|
|
|
|
es_putc ('\n', es_stderr);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pgmname = gnupg_module_name (GNUPG_MODULE_NAME_CONNECT_AGENT);
|
|
|
|
|
i = 0;
|
|
|
|
|
if (component == GC_COMPONENT_DIRMNGR)
|
|
|
|
|
argv[i++] = "--dirmngr";
|
|
|
|
|
argv[i++] = "NOP";
|
|
|
|
|
argv[i] = NULL;
|
|
|
|
|
|
|
|
|
|
err = gnupg_spawn_process_fd (pgmname, argv, -1, -1, -1, &pid);
|
|
|
|
|
if (!err)
|
|
|
|
|
err = gnupg_wait_process (pgmname, pid, 1, NULL);
|
|
|
|
|
if (err)
|
|
|
|
|
gc_error (0, 0, "error running '%s%s%s': %s",
|
|
|
|
|
pgmname,
|
|
|
|
|
component == GC_COMPONENT_DIRMNGR? " --dirmngr":"",
|
|
|
|
|
" NOP",
|
|
|
|
|
gpg_strerror (err));
|
|
|
|
|
gnupg_release_process (pid);
|
2014-12-17 10:36:24 +01:00
|
|
|
|
return err;
|
2014-04-08 15:55:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-02-23 10:15:34 +01:00
|
|
|
|
/* Unconditionally restart COMPONENT. */
|
|
|
|
|
void
|
|
|
|
|
gc_component_kill (int component)
|
|
|
|
|
{
|
|
|
|
|
int runtime[GC_BACKEND_NR];
|
|
|
|
|
gc_option_t *option;
|
|
|
|
|
gc_backend_t backend;
|
|
|
|
|
|
|
|
|
|
/* Set a flag for the backends to be reloaded. */
|
|
|
|
|
for (backend = 0; backend < GC_BACKEND_NR; backend++)
|
|
|
|
|
runtime[backend] = 0;
|
|
|
|
|
|
|
|
|
|
if (component >= 0)
|
|
|
|
|
{
|
|
|
|
|
assert (component < GC_COMPONENT_NR);
|
|
|
|
|
option = gc_component[component].options;
|
|
|
|
|
for (; option && option->name; option++)
|
|
|
|
|
runtime[option->backend] = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Do the restart for the selected backends. */
|
|
|
|
|
for (backend = 0; backend < GC_BACKEND_NR; backend++)
|
|
|
|
|
{
|
|
|
|
|
if (runtime[backend] && gc_backend[backend].runtime_change)
|
|
|
|
|
(*gc_backend[backend].runtime_change) (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-03-03 09:02:58 +00:00
|
|
|
|
/* Unconditionally reload COMPONENT or all components if COMPONENT is -1. */
|
|
|
|
|
void
|
|
|
|
|
gc_component_reload (int component)
|
|
|
|
|
{
|
|
|
|
|
int runtime[GC_BACKEND_NR];
|
|
|
|
|
gc_option_t *option;
|
|
|
|
|
gc_backend_t backend;
|
|
|
|
|
|
|
|
|
|
/* Set a flag for the backends to be reloaded. */
|
|
|
|
|
for (backend = 0; backend < GC_BACKEND_NR; backend++)
|
|
|
|
|
runtime[backend] = 0;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2009-03-03 09:02:58 +00:00
|
|
|
|
if (component == -1)
|
|
|
|
|
{
|
|
|
|
|
for (component = 0; component < GC_COMPONENT_NR; component++)
|
|
|
|
|
{
|
|
|
|
|
option = gc_component[component].options;
|
|
|
|
|
for (; option && option->name; option++)
|
|
|
|
|
runtime[option->backend] = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
assert (component < GC_COMPONENT_NR);
|
|
|
|
|
option = gc_component[component].options;
|
|
|
|
|
for (; option && option->name; option++)
|
|
|
|
|
runtime[option->backend] = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Do the reload for all selected backends. */
|
2011-02-23 10:15:34 +01:00
|
|
|
|
for (backend = 0; backend < GC_BACKEND_NR; backend++)
|
2009-03-03 09:02:58 +00:00
|
|
|
|
{
|
|
|
|
|
if (runtime[backend] && gc_backend[backend].runtime_change)
|
2011-02-23 10:15:34 +01:00
|
|
|
|
(*gc_backend[backend].runtime_change) (0);
|
2009-03-03 09:02:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2004-09-29 16:16:47 +00:00
|
|
|
|
/* More or less Robust version of dgettext. It has the side effect of
|
|
|
|
|
switching the codeset to utf-8 because this is what we want to
|
2004-04-07 16:53:55 +00:00
|
|
|
|
output. In theory it is posible to keep the orginal code set and
|
|
|
|
|
switch back for regular disgnostic output (redefine "_(" for that)
|
|
|
|
|
but given the natur of this tool, being something invoked from
|
|
|
|
|
other pograms, it does not make much sense. */
|
2004-01-28 23:58:18 +00:00
|
|
|
|
static const char *
|
|
|
|
|
my_dgettext (const char *domain, const char *msgid)
|
|
|
|
|
{
|
2008-05-09 09:54:35 +00:00
|
|
|
|
#ifdef USE_SIMPLE_GETTEXT
|
|
|
|
|
if (domain)
|
|
|
|
|
{
|
|
|
|
|
static int switched_codeset;
|
|
|
|
|
char *text;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2008-05-09 09:54:35 +00:00
|
|
|
|
if (!switched_codeset)
|
|
|
|
|
{
|
|
|
|
|
switched_codeset = 1;
|
2010-03-15 13:08:51 +00:00
|
|
|
|
gettext_use_utf8 (1);
|
2008-05-09 09:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp (domain, "gnupg"))
|
|
|
|
|
domain = PACKAGE_GT;
|
|
|
|
|
|
|
|
|
|
/* FIXME: we have no dgettext, thus we can't switch. */
|
|
|
|
|
|
2009-04-01 10:51:53 +00:00
|
|
|
|
text = (char*)gettext (msgid);
|
2008-05-09 09:54:35 +00:00
|
|
|
|
return text ? text : msgid;
|
|
|
|
|
}
|
2014-03-07 09:46:44 +01:00
|
|
|
|
else
|
|
|
|
|
return msgid;
|
2008-05-09 09:54:35 +00:00
|
|
|
|
#elif defined(ENABLE_NLS)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
if (domain)
|
|
|
|
|
{
|
2004-04-07 16:53:55 +00:00
|
|
|
|
static int switched_codeset;
|
|
|
|
|
char *text;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2004-04-07 16:53:55 +00:00
|
|
|
|
if (!switched_codeset)
|
|
|
|
|
{
|
|
|
|
|
switched_codeset = 1;
|
2004-10-01 12:53:09 +00:00
|
|
|
|
bind_textdomain_codeset (PACKAGE_GT, "utf-8");
|
|
|
|
|
|
2013-11-18 14:09:47 +01:00
|
|
|
|
bindtextdomain (DIRMNGR_NAME, LOCALEDIR);
|
|
|
|
|
bind_textdomain_codeset (DIRMNGR_NAME, "utf-8");
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2004-04-07 16:53:55 +00:00
|
|
|
|
}
|
2004-09-29 16:16:47 +00:00
|
|
|
|
|
|
|
|
|
/* Note: This is a hack to actually use the gnupg2 domain as
|
|
|
|
|
long we are in a transition phase where gnupg 1.x and 1.9 may
|
|
|
|
|
coexist. */
|
|
|
|
|
if (!strcmp (domain, "gnupg"))
|
|
|
|
|
domain = PACKAGE_GT;
|
|
|
|
|
|
2004-04-07 16:53:55 +00:00
|
|
|
|
text = dgettext (domain, msgid);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
return text ? text : msgid;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return msgid;
|
2014-02-10 19:48:42 +01:00
|
|
|
|
#else
|
|
|
|
|
(void)domain;
|
|
|
|
|
return msgid;
|
|
|
|
|
#endif
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Percent-Escape special characters. The string is valid until the
|
|
|
|
|
next invocation of the function. */
|
2008-05-26 13:43:20 +00:00
|
|
|
|
char *
|
|
|
|
|
gc_percent_escape (const char *src)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
|
|
|
|
static char *esc_str;
|
|
|
|
|
static int esc_str_len;
|
|
|
|
|
int new_len = 3 * strlen (src) + 1;
|
|
|
|
|
char *dst;
|
|
|
|
|
|
|
|
|
|
if (esc_str_len < new_len)
|
|
|
|
|
{
|
|
|
|
|
char *new_esc_str = realloc (esc_str, new_len);
|
|
|
|
|
if (!new_esc_str)
|
2004-01-30 12:15:53 +00:00
|
|
|
|
gc_error (1, errno, "can not escape string");
|
2004-01-28 23:58:18 +00:00
|
|
|
|
esc_str = new_esc_str;
|
|
|
|
|
esc_str_len = new_len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dst = esc_str;
|
|
|
|
|
while (*src)
|
|
|
|
|
{
|
|
|
|
|
if (*src == '%')
|
|
|
|
|
{
|
|
|
|
|
*(dst++) = '%';
|
|
|
|
|
*(dst++) = '2';
|
|
|
|
|
*(dst++) = '5';
|
2011-02-23 10:15:34 +01:00
|
|
|
|
}
|
2004-01-28 23:58:18 +00:00
|
|
|
|
else if (*src == ':')
|
|
|
|
|
{
|
|
|
|
|
/* The colon is used as field separator. */
|
|
|
|
|
*(dst++) = '%';
|
|
|
|
|
*(dst++) = '3';
|
|
|
|
|
*(dst++) = 'a';
|
|
|
|
|
}
|
|
|
|
|
else if (*src == ',')
|
|
|
|
|
{
|
|
|
|
|
/* The comma is used as list separator. */
|
|
|
|
|
*(dst++) = '%';
|
|
|
|
|
*(dst++) = '2';
|
|
|
|
|
*(dst++) = 'c';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
*(dst++) = *(src);
|
|
|
|
|
src++;
|
|
|
|
|
}
|
|
|
|
|
*dst = '\0';
|
|
|
|
|
return esc_str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-23 19:37:04 +00:00
|
|
|
|
|
|
|
|
|
/* Percent-Deescape special characters. The string is valid until the
|
|
|
|
|
next invocation of the function. */
|
|
|
|
|
static char *
|
|
|
|
|
percent_deescape (const char *src)
|
|
|
|
|
{
|
|
|
|
|
static char *str;
|
|
|
|
|
static int str_len;
|
|
|
|
|
int new_len = 3 * strlen (src) + 1;
|
|
|
|
|
char *dst;
|
|
|
|
|
|
|
|
|
|
if (str_len < new_len)
|
|
|
|
|
{
|
|
|
|
|
char *new_str = realloc (str, new_len);
|
|
|
|
|
if (!new_str)
|
|
|
|
|
gc_error (1, errno, "can not deescape string");
|
|
|
|
|
str = new_str;
|
|
|
|
|
str_len = new_len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dst = str;
|
|
|
|
|
while (*src)
|
|
|
|
|
{
|
|
|
|
|
if (*src == '%')
|
|
|
|
|
{
|
|
|
|
|
int val = hextobyte (src + 1);
|
|
|
|
|
|
|
|
|
|
if (val < 0)
|
|
|
|
|
gc_error (1, 0, "malformed end of string %s", src);
|
|
|
|
|
|
|
|
|
|
*(dst++) = (char) val;
|
|
|
|
|
src += 3;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
}
|
2004-02-23 19:37:04 +00:00
|
|
|
|
else
|
|
|
|
|
*(dst++) = *(src++);
|
|
|
|
|
}
|
|
|
|
|
*dst = '\0';
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
|
|
|
|
/* List all components that are available. */
|
|
|
|
|
void
|
2010-08-18 19:25:15 +00:00
|
|
|
|
gc_component_list_components (estream_t out)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
2007-08-31 08:24:52 +00:00
|
|
|
|
gc_component_t component;
|
|
|
|
|
gc_option_t *option;
|
|
|
|
|
gc_backend_t backend;
|
|
|
|
|
int backend_seen[GC_BACKEND_NR];
|
|
|
|
|
const char *desc;
|
|
|
|
|
const char *pgmname;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2007-08-31 08:24:52 +00:00
|
|
|
|
for (component = 0; component < GC_COMPONENT_NR; component++)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
2007-08-31 08:24:52 +00:00
|
|
|
|
option = gc_component[component].options;
|
|
|
|
|
if (option)
|
2007-06-26 13:48:44 +00:00
|
|
|
|
{
|
2007-08-31 08:24:52 +00:00
|
|
|
|
for (backend = 0; backend < GC_BACKEND_NR; backend++)
|
|
|
|
|
backend_seen[backend] = 0;
|
|
|
|
|
|
|
|
|
|
pgmname = "";
|
|
|
|
|
for (; option && option->name; option++)
|
|
|
|
|
{
|
|
|
|
|
if ((option->flags & GC_OPT_FLAG_GROUP))
|
|
|
|
|
continue;
|
|
|
|
|
backend = option->backend;
|
|
|
|
|
if (backend_seen[backend])
|
|
|
|
|
continue;
|
|
|
|
|
backend_seen[backend] = 1;
|
|
|
|
|
assert (backend != GC_BACKEND_ANY);
|
|
|
|
|
if (gc_backend[backend].program
|
|
|
|
|
&& !gc_backend[backend].module_name)
|
|
|
|
|
continue;
|
|
|
|
|
pgmname = gnupg_module_name (gc_backend[backend].module_name);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
desc = gc_component[component].desc;
|
|
|
|
|
desc = my_dgettext (gc_component[component].desc_domain, desc);
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (out, "%s:%s:",
|
|
|
|
|
gc_component[component].name, gc_percent_escape (desc));
|
|
|
|
|
es_fprintf (out, "%s\n", gc_percent_escape (pgmname));
|
2007-06-26 13:48:44 +00:00
|
|
|
|
}
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-29 09:51:37 +00:00
|
|
|
|
|
|
|
|
|
|
2007-08-29 16:59:20 +00:00
|
|
|
|
static int
|
|
|
|
|
all_digits_p (const char *p, size_t len)
|
|
|
|
|
{
|
|
|
|
|
if (!len)
|
|
|
|
|
return 0; /* No. */
|
|
|
|
|
for (; len; len--, p++)
|
|
|
|
|
if (!isascii (*p) || !isdigit (*p))
|
|
|
|
|
return 0; /* No. */
|
|
|
|
|
return 1; /* Yes. */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-08-20 12:18:38 +00:00
|
|
|
|
/* Collect all error lines from stream FP. Only lines prefixed with
|
|
|
|
|
TAG are considered. Returns a list of error line items (which may
|
|
|
|
|
be empty). There is no error return. */
|
2007-08-29 16:59:20 +00:00
|
|
|
|
static error_line_t
|
2010-08-20 12:18:38 +00:00
|
|
|
|
collect_error_output (estream_t fp, const char *tag)
|
2007-08-29 16:59:20 +00:00
|
|
|
|
{
|
|
|
|
|
char buffer[1024];
|
|
|
|
|
char *p, *p2, *p3;
|
|
|
|
|
int c, cont_line;
|
|
|
|
|
unsigned int pos;
|
|
|
|
|
error_line_t eitem, errlines, *errlines_tail;
|
|
|
|
|
size_t taglen = strlen (tag);
|
|
|
|
|
|
|
|
|
|
errlines = NULL;
|
|
|
|
|
errlines_tail = &errlines;
|
|
|
|
|
pos = 0;
|
|
|
|
|
cont_line = 0;
|
2010-08-20 12:18:38 +00:00
|
|
|
|
while ((c=es_getc (fp)) != EOF)
|
2007-08-29 16:59:20 +00:00
|
|
|
|
{
|
|
|
|
|
buffer[pos++] = c;
|
|
|
|
|
if (pos >= sizeof buffer - 5 || c == '\n')
|
|
|
|
|
{
|
|
|
|
|
buffer[pos - (c == '\n')] = 0;
|
|
|
|
|
if (cont_line)
|
|
|
|
|
; /*Ignore continuations of previous line. */
|
2011-02-23 10:15:34 +01:00
|
|
|
|
else if (!strncmp (buffer, tag, taglen) && buffer[taglen] == ':')
|
2007-08-29 16:59:20 +00:00
|
|
|
|
{
|
|
|
|
|
/* "gpgsm: foo:4: bla" */
|
|
|
|
|
/* Yep, we are interested in this line. */
|
|
|
|
|
p = buffer + taglen + 1;
|
|
|
|
|
while (*p == ' ' || *p == '\t')
|
|
|
|
|
p++;
|
2010-08-20 12:18:38 +00:00
|
|
|
|
trim_trailing_spaces (p); /* Get rid of extra CRs. */
|
2007-08-29 16:59:20 +00:00
|
|
|
|
if (!*p)
|
|
|
|
|
; /* Empty lines are ignored. */
|
|
|
|
|
else if ( (p2 = strchr (p, ':')) && (p3 = strchr (p2+1, ':'))
|
|
|
|
|
&& all_digits_p (p2+1, p3 - (p2+1)))
|
|
|
|
|
{
|
|
|
|
|
/* Line in standard compiler format. */
|
|
|
|
|
p3++;
|
|
|
|
|
while (*p3 == ' ' || *p3 == '\t')
|
|
|
|
|
p3++;
|
|
|
|
|
eitem = xmalloc (sizeof *eitem + strlen (p));
|
|
|
|
|
eitem->next = NULL;
|
|
|
|
|
strcpy (eitem->buffer, p);
|
|
|
|
|
eitem->fname = eitem->buffer;
|
|
|
|
|
eitem->buffer[p2-p] = 0;
|
|
|
|
|
eitem->errtext = eitem->buffer + (p3 - p);
|
|
|
|
|
/* (we already checked that there are only ascii
|
|
|
|
|
digits followed by a colon) */
|
|
|
|
|
eitem->lineno = 0;
|
|
|
|
|
for (p2++; isdigit (*p2); p2++)
|
|
|
|
|
eitem->lineno = eitem->lineno*10 + (*p2 - '0');
|
|
|
|
|
*errlines_tail = eitem;
|
|
|
|
|
errlines_tail = &eitem->next;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Other error output. */
|
|
|
|
|
eitem = xmalloc (sizeof *eitem + strlen (p));
|
|
|
|
|
eitem->next = NULL;
|
|
|
|
|
strcpy (eitem->buffer, p);
|
|
|
|
|
eitem->fname = NULL;
|
|
|
|
|
eitem->errtext = eitem->buffer;
|
|
|
|
|
eitem->lineno = 0;
|
|
|
|
|
*errlines_tail = eitem;
|
|
|
|
|
errlines_tail = &eitem->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pos = 0;
|
|
|
|
|
/* If this was not a complete line mark that we are in a
|
|
|
|
|
continuation. */
|
|
|
|
|
cont_line = (c != '\n');
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2007-08-29 16:59:20 +00:00
|
|
|
|
/* We ignore error lines not terminated by a LF. */
|
|
|
|
|
return errlines;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-05-19 22:46:41 +00:00
|
|
|
|
/* Check the options of a single component. Returns 0 if everything
|
|
|
|
|
is OK. */
|
|
|
|
|
int
|
2010-08-18 19:25:15 +00:00
|
|
|
|
gc_component_check_options (int component, estream_t out, const char *conf_file)
|
2007-08-29 09:51:37 +00:00
|
|
|
|
{
|
2007-08-29 16:59:20 +00:00
|
|
|
|
gpg_error_t err;
|
2007-08-29 09:51:37 +00:00
|
|
|
|
unsigned int result;
|
|
|
|
|
int backend_seen[GC_BACKEND_NR];
|
|
|
|
|
gc_backend_t backend;
|
|
|
|
|
gc_option_t *option;
|
|
|
|
|
const char *pgmname;
|
2008-05-19 22:46:41 +00:00
|
|
|
|
const char *argv[4];
|
|
|
|
|
int i;
|
2007-08-29 09:51:37 +00:00
|
|
|
|
pid_t pid;
|
|
|
|
|
int exitcode;
|
2010-08-20 12:18:38 +00:00
|
|
|
|
estream_t errfp;
|
2008-05-19 22:46:41 +00:00
|
|
|
|
error_line_t errlines;
|
2007-08-29 09:51:37 +00:00
|
|
|
|
|
2008-05-19 22:46:41 +00:00
|
|
|
|
for (backend = 0; backend < GC_BACKEND_NR; backend++)
|
|
|
|
|
backend_seen[backend] = 0;
|
|
|
|
|
|
|
|
|
|
option = gc_component[component].options;
|
|
|
|
|
for (; option && option->name; option++)
|
2007-08-29 09:51:37 +00:00
|
|
|
|
{
|
2008-05-19 22:46:41 +00:00
|
|
|
|
if ((option->flags & GC_OPT_FLAG_GROUP))
|
|
|
|
|
continue;
|
|
|
|
|
backend = option->backend;
|
|
|
|
|
if (backend_seen[backend])
|
|
|
|
|
continue;
|
|
|
|
|
backend_seen[backend] = 1;
|
|
|
|
|
assert (backend != GC_BACKEND_ANY);
|
|
|
|
|
if (!gc_backend[backend].program)
|
|
|
|
|
continue;
|
|
|
|
|
if (!gc_backend[backend].module_name)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (! option || ! option->name)
|
|
|
|
|
return 0;
|
2007-08-29 09:51:37 +00:00
|
|
|
|
|
2008-05-19 22:46:41 +00:00
|
|
|
|
pgmname = gnupg_module_name (gc_backend[backend].module_name);
|
|
|
|
|
i = 0;
|
|
|
|
|
if (conf_file)
|
|
|
|
|
{
|
|
|
|
|
argv[i++] = "--options";
|
|
|
|
|
argv[i++] = conf_file;
|
|
|
|
|
}
|
2010-08-19 09:53:55 +00:00
|
|
|
|
if (component == GC_COMPONENT_PINENTRY)
|
|
|
|
|
argv[i++] = "--version";
|
|
|
|
|
else
|
|
|
|
|
argv[i++] = "--gpgconf-test";
|
2008-05-19 22:46:41 +00:00
|
|
|
|
argv[i++] = NULL;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2008-05-19 22:46:41 +00:00
|
|
|
|
result = 0;
|
|
|
|
|
errlines = NULL;
|
2010-08-20 12:18:38 +00:00
|
|
|
|
err = gnupg_spawn_process (pgmname, argv, GPG_ERR_SOURCE_DEFAULT, NULL, 0,
|
|
|
|
|
NULL, NULL, &errfp, &pid);
|
|
|
|
|
if (err)
|
|
|
|
|
result |= 1; /* Program could not be run. */
|
2011-02-23 10:15:34 +01:00
|
|
|
|
else
|
2008-05-19 22:46:41 +00:00
|
|
|
|
{
|
2011-02-23 10:15:34 +01:00
|
|
|
|
errlines = collect_error_output (errfp,
|
2008-05-19 22:46:41 +00:00
|
|
|
|
gc_component[component].name);
|
2010-06-24 10:51:30 +00:00
|
|
|
|
if (gnupg_wait_process (pgmname, pid, 1, &exitcode))
|
2008-05-19 22:46:41 +00:00
|
|
|
|
{
|
|
|
|
|
if (exitcode == -1)
|
|
|
|
|
result |= 1; /* Program could not be run or it
|
|
|
|
|
terminated abnormally. */
|
|
|
|
|
result |= 2; /* Program returned an error. */
|
|
|
|
|
}
|
2010-06-09 16:53:51 +00:00
|
|
|
|
gnupg_release_process (pid);
|
2010-08-20 12:18:38 +00:00
|
|
|
|
es_fclose (errfp);
|
2008-05-19 22:46:41 +00:00
|
|
|
|
}
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2008-05-19 22:46:41 +00:00
|
|
|
|
/* If the program could not be run, we can't tell whether
|
|
|
|
|
the config file is good. */
|
|
|
|
|
if (result & 1)
|
2011-02-23 10:15:34 +01:00
|
|
|
|
result |= 2;
|
|
|
|
|
|
2008-05-19 22:46:41 +00:00
|
|
|
|
if (out)
|
|
|
|
|
{
|
|
|
|
|
const char *desc;
|
|
|
|
|
error_line_t errptr;
|
|
|
|
|
|
|
|
|
|
desc = gc_component[component].desc;
|
|
|
|
|
desc = my_dgettext (gc_component[component].desc_domain, desc);
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (out, "%s:%s:",
|
|
|
|
|
gc_component[component].name, gc_percent_escape (desc));
|
|
|
|
|
es_fputs (gc_percent_escape (pgmname), out);
|
|
|
|
|
es_fprintf (out, ":%d:%d:", !(result & 1), !(result & 2));
|
2008-05-19 22:46:41 +00:00
|
|
|
|
for (errptr = errlines; errptr; errptr = errptr->next)
|
|
|
|
|
{
|
|
|
|
|
if (errptr != errlines)
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fputs ("\n:::::", out); /* Continuation line. */
|
2008-05-19 22:46:41 +00:00
|
|
|
|
if (errptr->fname)
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fputs (gc_percent_escape (errptr->fname), out);
|
|
|
|
|
es_putc (':', out);
|
2008-05-19 22:46:41 +00:00
|
|
|
|
if (errptr->fname)
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (out, "%u", errptr->lineno);
|
|
|
|
|
es_putc (':', out);
|
|
|
|
|
es_fputs (gc_percent_escape (errptr->errtext), out);
|
|
|
|
|
es_putc (':', out);
|
2008-05-19 22:46:41 +00:00
|
|
|
|
}
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_putc ('\n', out);
|
2008-05-19 22:46:41 +00:00
|
|
|
|
}
|
2007-08-29 09:51:37 +00:00
|
|
|
|
|
2008-05-19 22:46:41 +00:00
|
|
|
|
while (errlines)
|
|
|
|
|
{
|
|
|
|
|
error_line_t tmp = errlines->next;
|
|
|
|
|
xfree (errlines);
|
|
|
|
|
errlines = tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-08-19 09:53:55 +00:00
|
|
|
|
|
2008-05-19 22:46:41 +00:00
|
|
|
|
/* Check all components that are available. */
|
|
|
|
|
void
|
2010-08-18 19:25:15 +00:00
|
|
|
|
gc_check_programs (estream_t out)
|
2008-05-19 22:46:41 +00:00
|
|
|
|
{
|
|
|
|
|
gc_component_t component;
|
|
|
|
|
|
|
|
|
|
for (component = 0; component < GC_COMPONENT_NR; component++)
|
|
|
|
|
gc_component_check_options (component, out, NULL);
|
2007-08-29 09:51:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
|
|
|
|
/* Find the component with the name NAME. Returns -1 if not
|
|
|
|
|
found. */
|
|
|
|
|
int
|
|
|
|
|
gc_component_find (const char *name)
|
|
|
|
|
{
|
|
|
|
|
gc_component_t idx;
|
|
|
|
|
|
|
|
|
|
for (idx = 0; idx < GC_COMPONENT_NR; idx++)
|
|
|
|
|
{
|
2007-06-26 13:48:44 +00:00
|
|
|
|
if (gc_component[idx].options
|
|
|
|
|
&& !strcmp (name, gc_component[idx].name))
|
2004-01-28 23:58:18 +00:00
|
|
|
|
return idx;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-26 22:45:19 +00:00
|
|
|
|
/* List the option OPTION. */
|
|
|
|
|
static void
|
2010-08-18 19:25:15 +00:00
|
|
|
|
list_one_option (const gc_option_t *option, estream_t out)
|
2004-02-26 22:45:19 +00:00
|
|
|
|
{
|
|
|
|
|
const char *desc = NULL;
|
|
|
|
|
char *arg_name = NULL;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2004-02-26 22:45:19 +00:00
|
|
|
|
if (option->desc)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
2004-02-26 22:45:19 +00:00
|
|
|
|
desc = my_dgettext (option->desc_domain, option->desc);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2004-02-26 22:45:19 +00:00
|
|
|
|
if (*desc == '|')
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
2004-02-26 22:45:19 +00:00
|
|
|
|
const char *arg_tail = strchr (&desc[1], '|');
|
|
|
|
|
|
|
|
|
|
if (arg_tail)
|
|
|
|
|
{
|
|
|
|
|
int arg_len = arg_tail - &desc[1];
|
|
|
|
|
arg_name = xmalloc (arg_len + 1);
|
|
|
|
|
memcpy (arg_name, &desc[1], arg_len);
|
|
|
|
|
arg_name[arg_len] = '\0';
|
|
|
|
|
desc = arg_tail + 1;
|
|
|
|
|
}
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
2004-02-26 22:45:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2004-02-26 22:45:19 +00:00
|
|
|
|
/* YOU MUST NOT REORDER THE FIELDS IN THIS OUTPUT, AS THEIR ORDER IS
|
|
|
|
|
PART OF THE EXTERNAL INTERFACE. YOU MUST NOT REMOVE ANY
|
|
|
|
|
FIELDS. */
|
|
|
|
|
|
|
|
|
|
/* The name field. */
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (out, "%s", option->name);
|
2004-02-26 22:45:19 +00:00
|
|
|
|
|
|
|
|
|
/* The flags field. */
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (out, ":%lu", option->flags);
|
2004-02-26 22:45:19 +00:00
|
|
|
|
if (opt.verbose)
|
|
|
|
|
{
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_putc (' ', out);
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2004-02-26 22:45:19 +00:00
|
|
|
|
if (!option->flags)
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (out, "none");
|
2004-02-26 22:45:19 +00:00
|
|
|
|
else
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
2004-02-26 22:45:19 +00:00
|
|
|
|
unsigned long flags = option->flags;
|
|
|
|
|
unsigned long flag = 0;
|
|
|
|
|
unsigned long first = 1;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2004-02-26 22:45:19 +00:00
|
|
|
|
while (flags)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
2004-02-26 22:45:19 +00:00
|
|
|
|
if (flags & 1)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
2004-02-26 22:45:19 +00:00
|
|
|
|
if (first)
|
|
|
|
|
first = 0;
|
|
|
|
|
else
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_putc (',', out);
|
|
|
|
|
es_fprintf (out, "%s", gc_flag[flag].name);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
2004-02-26 22:45:19 +00:00
|
|
|
|
flags >>= 1;
|
|
|
|
|
flag++;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2004-02-26 22:45:19 +00:00
|
|
|
|
}
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2004-02-26 22:45:19 +00:00
|
|
|
|
/* The level field. */
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (out, ":%u", option->level);
|
2004-02-26 22:45:19 +00:00
|
|
|
|
if (opt.verbose)
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (out, " %s", gc_level[option->level].name);
|
2004-02-26 22:45:19 +00:00
|
|
|
|
|
|
|
|
|
/* The description field. */
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (out, ":%s", desc ? gc_percent_escape (desc) : "");
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2004-02-26 22:45:19 +00:00
|
|
|
|
/* The type field. */
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (out, ":%u", option->arg_type);
|
2004-02-26 22:45:19 +00:00
|
|
|
|
if (opt.verbose)
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (out, " %s", gc_arg_type[option->arg_type].name);
|
2004-02-26 22:45:19 +00:00
|
|
|
|
|
|
|
|
|
/* The alternate type field. */
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (out, ":%u", gc_arg_type[option->arg_type].fallback);
|
2004-02-26 22:45:19 +00:00
|
|
|
|
if (opt.verbose)
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (out, " %s",
|
|
|
|
|
gc_arg_type[gc_arg_type[option->arg_type].fallback].name);
|
2004-02-26 22:45:19 +00:00
|
|
|
|
|
|
|
|
|
/* The argument name field. */
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (out, ":%s", arg_name ? gc_percent_escape (arg_name) : "");
|
|
|
|
|
xfree (arg_name);
|
2004-02-26 22:45:19 +00:00
|
|
|
|
|
|
|
|
|
/* The default value field. */
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (out, ":%s", option->default_value ? option->default_value : "");
|
2004-02-26 22:45:19 +00:00
|
|
|
|
|
|
|
|
|
/* The default argument field. */
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (out, ":%s", option->default_arg ? option->default_arg : "");
|
2004-02-26 22:45:19 +00:00
|
|
|
|
|
|
|
|
|
/* The value field. */
|
|
|
|
|
if (gc_arg_type[option->arg_type].fallback == GC_ARG_TYPE_NONE
|
|
|
|
|
&& (option->flags & GC_OPT_FLAG_LIST)
|
|
|
|
|
&& option->value)
|
|
|
|
|
/* The special format "1,1,1,1,...,1" is converted to a number
|
|
|
|
|
here. */
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (out, ":%u", (unsigned int)((strlen (option->value) + 1) / 2));
|
2004-02-26 22:45:19 +00:00
|
|
|
|
else
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (out, ":%s", option->value ? option->value : "");
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2004-02-26 22:45:19 +00:00
|
|
|
|
/* ADD NEW FIELDS HERE. */
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_putc ('\n', out);
|
2004-02-26 22:45:19 +00:00
|
|
|
|
}
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2004-02-26 22:45:19 +00:00
|
|
|
|
|
|
|
|
|
/* List all options of the component COMPONENT. */
|
|
|
|
|
void
|
2010-08-18 19:25:15 +00:00
|
|
|
|
gc_component_list_options (int component, estream_t out)
|
2011-02-23 10:15:34 +01:00
|
|
|
|
{
|
2004-02-26 22:45:19 +00:00
|
|
|
|
const gc_option_t *option = gc_component[component].options;
|
|
|
|
|
|
2007-06-26 13:48:44 +00:00
|
|
|
|
while (option && option->name)
|
2004-02-26 22:45:19 +00:00
|
|
|
|
{
|
|
|
|
|
/* Do not output unknown or internal options. */
|
|
|
|
|
if (!(option->flags & GC_OPT_FLAG_GROUP)
|
|
|
|
|
&& (!option->active || option->level == GC_LEVEL_INTERNAL))
|
|
|
|
|
{
|
|
|
|
|
option++;
|
|
|
|
|
continue;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-02-26 22:45:19 +00:00
|
|
|
|
if (option->flags & GC_OPT_FLAG_GROUP)
|
|
|
|
|
{
|
2007-12-10 16:44:38 +00:00
|
|
|
|
const gc_option_t *group_option = option + 1;
|
|
|
|
|
gc_expert_level_t level = GC_LEVEL_NR;
|
|
|
|
|
|
|
|
|
|
/* The manual states that the group level is always the
|
|
|
|
|
minimum of the levels of all contained options. Due to
|
|
|
|
|
different active options, and because it is hard to
|
|
|
|
|
maintain manually, we calculate it here. The value in
|
|
|
|
|
the global static table is ignored. */
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2007-12-10 16:44:38 +00:00
|
|
|
|
while (group_option->name)
|
2004-02-26 22:45:19 +00:00
|
|
|
|
{
|
2007-12-10 16:44:38 +00:00
|
|
|
|
if (group_option->flags & GC_OPT_FLAG_GROUP)
|
|
|
|
|
break;
|
|
|
|
|
if (group_option->level < level)
|
|
|
|
|
level = group_option->level;
|
|
|
|
|
group_option++;
|
2004-02-26 22:45:19 +00:00
|
|
|
|
}
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2007-12-10 16:44:38 +00:00
|
|
|
|
/* Check if group is empty. */
|
|
|
|
|
if (level != GC_LEVEL_NR)
|
|
|
|
|
{
|
|
|
|
|
gc_option_t opt_copy;
|
|
|
|
|
|
|
|
|
|
/* Fix up the group level. */
|
2008-02-01 20:26:24 +00:00
|
|
|
|
memcpy (&opt_copy, option, sizeof (opt_copy));
|
2007-12-10 16:44:38 +00:00
|
|
|
|
opt_copy.level = level;
|
|
|
|
|
list_one_option (&opt_copy, out);
|
|
|
|
|
}
|
2004-02-26 22:45:19 +00:00
|
|
|
|
}
|
2007-12-10 16:44:38 +00:00
|
|
|
|
else
|
|
|
|
|
list_one_option (option, out);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
|
|
|
|
option++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Find the option NAME in component COMPONENT, for the backend
|
|
|
|
|
BACKEND. If BACKEND is GC_BACKEND_ANY, any backend will match. */
|
|
|
|
|
static gc_option_t *
|
|
|
|
|
find_option (gc_component_t component, const char *name,
|
|
|
|
|
gc_backend_t backend)
|
|
|
|
|
{
|
|
|
|
|
gc_option_t *option = gc_component[component].options;
|
|
|
|
|
while (option->name)
|
|
|
|
|
{
|
|
|
|
|
if (!(option->flags & GC_OPT_FLAG_GROUP)
|
|
|
|
|
&& !strcmp (option->name, name)
|
|
|
|
|
&& (backend == GC_BACKEND_ANY || option->backend == backend))
|
|
|
|
|
break;
|
|
|
|
|
option++;
|
|
|
|
|
}
|
|
|
|
|
return option->name ? option : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-05-26 15:05:31 +00:00
|
|
|
|
/* Determine the configuration filename for the component COMPONENT
|
2004-01-28 23:58:18 +00:00
|
|
|
|
and backend BACKEND. */
|
|
|
|
|
static char *
|
2008-05-26 15:05:31 +00:00
|
|
|
|
get_config_filename (gc_component_t component, gc_backend_t backend)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
2008-05-26 15:05:31 +00:00
|
|
|
|
char *filename = NULL;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
gc_option_t *option = find_option
|
|
|
|
|
(component, gc_backend[backend].option_config_filename, GC_BACKEND_ANY);
|
|
|
|
|
assert (option);
|
2008-05-26 15:05:31 +00:00
|
|
|
|
assert (option->arg_type == GC_ARG_TYPE_FILENAME);
|
2004-01-31 13:58:27 +00:00
|
|
|
|
assert (!(option->flags & GC_OPT_FLAG_LIST));
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2004-01-31 13:58:27 +00:00
|
|
|
|
if (!option->active || !option->default_value)
|
|
|
|
|
gc_error (1, 0, "Option %s, needed by backend %s, was not initialized",
|
2004-01-30 12:15:53 +00:00
|
|
|
|
gc_backend[backend].option_config_filename,
|
|
|
|
|
gc_backend[backend].name);
|
2004-01-31 13:58:27 +00:00
|
|
|
|
|
|
|
|
|
if (option->value && *option->value)
|
2008-05-26 15:05:31 +00:00
|
|
|
|
filename = percent_deescape (&option->value[1]);
|
2004-02-23 19:37:04 +00:00
|
|
|
|
else if (option->default_value && *option->default_value)
|
2008-05-26 15:05:31 +00:00
|
|
|
|
filename = percent_deescape (&option->default_value[1]);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
else
|
2008-05-26 15:05:31 +00:00
|
|
|
|
filename = "";
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2010-08-23 19:26:05 +00:00
|
|
|
|
#if HAVE_W32CE_SYSTEM
|
|
|
|
|
if (!(filename[0] == '/' || filename[0] == '\\'))
|
|
|
|
|
#elif defined(HAVE_DOSISH_SYSTEM)
|
2011-02-23 10:15:34 +01:00
|
|
|
|
if (!(filename[0]
|
2008-05-26 15:05:31 +00:00
|
|
|
|
&& filename[1] == ':'
|
|
|
|
|
&& (filename[2] == '/' || filename[2] == '\\')))
|
2004-12-21 19:05:15 +00:00
|
|
|
|
#else
|
2008-05-26 15:05:31 +00:00
|
|
|
|
if (filename[0] != '/')
|
2004-12-21 19:05:15 +00:00
|
|
|
|
#endif
|
2004-01-31 13:58:27 +00:00
|
|
|
|
gc_error (1, 0, "Option %s, needed by backend %s, is not absolute",
|
2004-01-30 12:15:53 +00:00
|
|
|
|
gc_backend[backend].option_config_filename,
|
|
|
|
|
gc_backend[backend].name);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2008-05-26 15:05:31 +00:00
|
|
|
|
return filename;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Retrieve the options for the component COMPONENT from backend
|
|
|
|
|
BACKEND, which we already know is a program-type backend. */
|
|
|
|
|
static void
|
|
|
|
|
retrieve_options_from_program (gc_component_t component, gc_backend_t backend)
|
|
|
|
|
{
|
2007-10-22 19:07:56 +00:00
|
|
|
|
gpg_error_t err;
|
|
|
|
|
const char *pgmname;
|
|
|
|
|
const char *argv[2];
|
2010-08-20 12:18:38 +00:00
|
|
|
|
estream_t outfp;
|
2007-10-22 19:07:56 +00:00
|
|
|
|
int exitcode;
|
|
|
|
|
pid_t pid;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
char *line = NULL;
|
|
|
|
|
size_t line_len = 0;
|
|
|
|
|
ssize_t length;
|
2010-08-20 12:18:38 +00:00
|
|
|
|
estream_t config;
|
2008-05-26 15:05:31 +00:00
|
|
|
|
char *config_filename;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2011-02-23 10:15:34 +01:00
|
|
|
|
pgmname = (gc_backend[backend].module_name
|
|
|
|
|
? gnupg_module_name (gc_backend[backend].module_name)
|
2007-10-22 19:07:56 +00:00
|
|
|
|
: gc_backend[backend].program );
|
|
|
|
|
argv[0] = "--gpgconf-list";
|
|
|
|
|
argv[1] = NULL;
|
|
|
|
|
|
2010-08-20 12:18:38 +00:00
|
|
|
|
err = gnupg_spawn_process (pgmname, argv, GPG_ERR_SOURCE_DEFAULT, NULL, 0,
|
|
|
|
|
NULL, &outfp, NULL, &pid);
|
2007-10-22 19:07:56 +00:00
|
|
|
|
if (err)
|
|
|
|
|
{
|
2012-06-05 19:29:22 +02:00
|
|
|
|
gc_error (1, 0, "could not gather active options from '%s': %s",
|
2007-10-22 19:07:56 +00:00
|
|
|
|
pgmname, gpg_strerror (err));
|
|
|
|
|
}
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2010-08-20 12:18:38 +00:00
|
|
|
|
while ((length = es_read_line (outfp, &line, &line_len, NULL)) > 0)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
|
|
|
|
gc_option_t *option;
|
2004-02-24 14:31:59 +00:00
|
|
|
|
char *linep;
|
|
|
|
|
unsigned long flags = 0;
|
|
|
|
|
char *default_value = NULL;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* Strip newline and carriage return, if present. */
|
|
|
|
|
while (length > 0
|
|
|
|
|
&& (line[length - 1] == '\n' || line[length - 1] == '\r'))
|
|
|
|
|
line[--length] = '\0';
|
|
|
|
|
|
2004-02-24 14:31:59 +00:00
|
|
|
|
linep = strchr (line, ':');
|
|
|
|
|
if (linep)
|
|
|
|
|
*(linep++) = '\0';
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2004-02-24 14:31:59 +00:00
|
|
|
|
/* Extract additional flags. Default to none. */
|
|
|
|
|
if (linep)
|
|
|
|
|
{
|
|
|
|
|
char *end;
|
|
|
|
|
char *tail;
|
|
|
|
|
|
|
|
|
|
end = strchr (linep, ':');
|
|
|
|
|
if (end)
|
|
|
|
|
*(end++) = '\0';
|
|
|
|
|
|
2010-03-29 12:57:11 +00:00
|
|
|
|
gpg_err_set_errno (0);
|
2004-02-24 14:31:59 +00:00
|
|
|
|
flags = strtoul (linep, &tail, 0);
|
|
|
|
|
if (errno)
|
2007-10-22 19:07:56 +00:00
|
|
|
|
gc_error (1, errno, "malformed flags in option %s from %s",
|
|
|
|
|
line, pgmname);
|
2004-02-24 14:31:59 +00:00
|
|
|
|
if (!(*tail == '\0' || *tail == ':' || *tail == ' '))
|
2007-10-22 19:07:56 +00:00
|
|
|
|
gc_error (1, 0, "garbage after flags in option %s from %s",
|
|
|
|
|
line, pgmname);
|
2004-02-24 14:31:59 +00:00
|
|
|
|
|
|
|
|
|
linep = end;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-31 13:58:27 +00:00
|
|
|
|
/* Extract default value, if present. Default to empty if
|
|
|
|
|
not. */
|
2004-02-24 14:31:59 +00:00
|
|
|
|
if (linep)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
2004-01-31 13:58:27 +00:00
|
|
|
|
char *end;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2004-02-24 14:31:59 +00:00
|
|
|
|
end = strchr (linep, ':');
|
2004-01-31 13:58:27 +00:00
|
|
|
|
if (end)
|
2004-02-24 14:31:59 +00:00
|
|
|
|
*(end++) = '\0';
|
|
|
|
|
|
|
|
|
|
if (flags & GC_OPT_FLAG_DEFAULT)
|
|
|
|
|
default_value = linep;
|
|
|
|
|
|
|
|
|
|
linep = end;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Look up the option in the component and install the
|
|
|
|
|
configuration data. */
|
|
|
|
|
option = find_option (component, line, backend);
|
|
|
|
|
if (option)
|
|
|
|
|
{
|
2004-01-31 13:58:27 +00:00
|
|
|
|
if (option->active)
|
2004-01-30 12:15:53 +00:00
|
|
|
|
gc_error (1, errno, "option %s returned twice from %s",
|
2007-10-22 19:07:56 +00:00
|
|
|
|
line, pgmname);
|
2004-01-31 13:58:27 +00:00
|
|
|
|
option->active = 1;
|
2004-02-24 14:31:59 +00:00
|
|
|
|
|
|
|
|
|
option->flags |= flags;
|
|
|
|
|
if (default_value && *default_value)
|
|
|
|
|
option->default_value = xstrdup (default_value);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-20 12:18:38 +00:00
|
|
|
|
if (length < 0 || es_ferror (outfp))
|
|
|
|
|
gc_error (1, errno, "error reading from %s", pgmname);
|
2010-08-23 19:26:05 +00:00
|
|
|
|
if (es_fclose (outfp))
|
2007-10-22 19:07:56 +00:00
|
|
|
|
gc_error (1, errno, "error closing %s", pgmname);
|
|
|
|
|
|
2010-06-24 10:51:30 +00:00
|
|
|
|
err = gnupg_wait_process (pgmname, pid, 1, &exitcode);
|
2007-10-22 19:07:56 +00:00
|
|
|
|
if (err)
|
|
|
|
|
gc_error (1, 0, "running %s failed (exitcode=%d): %s",
|
|
|
|
|
pgmname, exitcode, gpg_strerror (err));
|
2010-06-09 16:53:51 +00:00
|
|
|
|
gnupg_release_process (pid);
|
2007-10-22 19:07:56 +00:00
|
|
|
|
|
2004-01-31 13:58:27 +00:00
|
|
|
|
|
|
|
|
|
/* At this point, we can parse the configuration file. */
|
2008-05-26 15:05:31 +00:00
|
|
|
|
config_filename = get_config_filename (component, backend);
|
2004-01-31 13:58:27 +00:00
|
|
|
|
|
2010-08-20 12:18:38 +00:00
|
|
|
|
config = es_fopen (config_filename, "r");
|
2004-01-31 13:58:27 +00:00
|
|
|
|
if (!config)
|
|
|
|
|
gc_error (0, errno, "warning: can not open config file %s",
|
2008-05-26 15:05:31 +00:00
|
|
|
|
config_filename);
|
2004-01-31 13:58:27 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2010-08-20 12:18:38 +00:00
|
|
|
|
while ((length = es_read_line (config, &line, &line_len, NULL)) > 0)
|
2004-01-31 13:58:27 +00:00
|
|
|
|
{
|
|
|
|
|
char *name;
|
|
|
|
|
char *value;
|
|
|
|
|
gc_option_t *option;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2004-01-31 13:58:27 +00:00
|
|
|
|
name = line;
|
|
|
|
|
while (*name == ' ' || *name == '\t')
|
|
|
|
|
name++;
|
|
|
|
|
if (!*name || *name == '#' || *name == '\r' || *name == '\n')
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
value = name;
|
|
|
|
|
while (*value && *value != ' ' && *value != '\t'
|
|
|
|
|
&& *value != '#' && *value != '\r' && *value != '\n')
|
|
|
|
|
value++;
|
|
|
|
|
if (*value == ' ' || *value == '\t')
|
|
|
|
|
{
|
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
|
|
*(value++) = '\0';
|
|
|
|
|
while (*value == ' ' || *value == '\t')
|
|
|
|
|
value++;
|
|
|
|
|
|
|
|
|
|
end = value;
|
|
|
|
|
while (*end && *end != '#' && *end != '\r' && *end != '\n')
|
|
|
|
|
end++;
|
|
|
|
|
while (end > value && (end[-1] == ' ' || end[-1] == '\t'))
|
|
|
|
|
end--;
|
|
|
|
|
*end = '\0';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
*value = '\0';
|
|
|
|
|
|
|
|
|
|
/* Look up the option in the component and install the
|
|
|
|
|
configuration data. */
|
|
|
|
|
option = find_option (component, line, backend);
|
|
|
|
|
if (option)
|
|
|
|
|
{
|
|
|
|
|
char *opt_value;
|
|
|
|
|
|
|
|
|
|
if (gc_arg_type[option->arg_type].fallback == GC_ARG_TYPE_NONE)
|
|
|
|
|
{
|
|
|
|
|
if (*value)
|
|
|
|
|
gc_error (0, 0,
|
|
|
|
|
"warning: ignoring argument %s for option %s",
|
|
|
|
|
value, name);
|
2004-02-24 14:31:59 +00:00
|
|
|
|
opt_value = xstrdup ("1");
|
2004-01-31 13:58:27 +00:00
|
|
|
|
}
|
|
|
|
|
else if (gc_arg_type[option->arg_type].fallback
|
|
|
|
|
== GC_ARG_TYPE_STRING)
|
2008-05-26 13:43:20 +00:00
|
|
|
|
opt_value = xasprintf ("\"%s", gc_percent_escape (value));
|
2004-01-31 13:58:27 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* FIXME: Verify that the number is sane. */
|
|
|
|
|
opt_value = xstrdup (value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now enter the option into the table. */
|
|
|
|
|
if (!(option->flags & GC_OPT_FLAG_LIST))
|
|
|
|
|
{
|
|
|
|
|
if (option->value)
|
|
|
|
|
free (option->value);
|
|
|
|
|
option->value = opt_value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!option->value)
|
|
|
|
|
option->value = opt_value;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
char *opt_val = opt_value;
|
|
|
|
|
|
|
|
|
|
option->value = xasprintf ("%s,%s", option->value,
|
|
|
|
|
opt_val);
|
|
|
|
|
xfree (opt_value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-20 12:18:38 +00:00
|
|
|
|
if (length < 0 || es_ferror (config))
|
2008-05-26 15:05:31 +00:00
|
|
|
|
gc_error (1, errno, "error reading from %s", config_filename);
|
2010-08-23 19:26:05 +00:00
|
|
|
|
if (es_fclose (config))
|
2008-05-26 15:05:31 +00:00
|
|
|
|
gc_error (1, errno, "error closing %s", config_filename);
|
2004-01-31 13:58:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-06-14 08:32:07 +00:00
|
|
|
|
xfree (line);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Retrieve the options for the component COMPONENT from backend
|
2011-02-23 10:15:34 +01:00
|
|
|
|
BACKEND, which we already know is of type file list. */
|
2004-01-28 23:58:18 +00:00
|
|
|
|
static void
|
|
|
|
|
retrieve_options_from_file (gc_component_t component, gc_backend_t backend)
|
|
|
|
|
{
|
|
|
|
|
gc_option_t *list_option;
|
2008-08-06 11:48:23 +00:00
|
|
|
|
gc_option_t *config_option;
|
2008-05-26 15:05:31 +00:00
|
|
|
|
char *list_filename;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
FILE *list_file;
|
|
|
|
|
char *line = NULL;
|
|
|
|
|
size_t line_len = 0;
|
|
|
|
|
ssize_t length;
|
2004-01-31 13:58:27 +00:00
|
|
|
|
char *list = NULL;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
|
|
|
|
list_option = find_option (component,
|
|
|
|
|
gc_backend[backend].option_name, GC_BACKEND_ANY);
|
|
|
|
|
assert (list_option);
|
2004-01-31 13:58:27 +00:00
|
|
|
|
assert (!list_option->active);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2008-05-26 15:05:31 +00:00
|
|
|
|
list_filename = get_config_filename (component, backend);
|
|
|
|
|
list_file = fopen (list_filename, "r");
|
2004-01-31 13:58:27 +00:00
|
|
|
|
if (!list_file)
|
2008-05-26 15:05:31 +00:00
|
|
|
|
gc_error (0, errno, "warning: can not open list file %s", list_filename);
|
2004-01-31 13:58:27 +00:00
|
|
|
|
else
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
2004-01-31 13:58:27 +00:00
|
|
|
|
|
2004-06-14 08:32:07 +00:00
|
|
|
|
while ((length = read_line (list_file, &line, &line_len, NULL)) > 0)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
2004-01-31 13:58:27 +00:00
|
|
|
|
char *start;
|
|
|
|
|
char *end;
|
|
|
|
|
char *new_list;
|
|
|
|
|
|
|
|
|
|
start = line;
|
|
|
|
|
while (*start == ' ' || *start == '\t')
|
|
|
|
|
start++;
|
|
|
|
|
if (!*start || *start == '#' || *start == '\r' || *start == '\n')
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
end = start;
|
|
|
|
|
while (*end && *end != '#' && *end != '\r' && *end != '\n')
|
|
|
|
|
end++;
|
|
|
|
|
/* Walk back to skip trailing white spaces. Looks evil, but
|
|
|
|
|
works because of the conditions on START and END imposed
|
|
|
|
|
at this point (END is at least START + 1, and START is
|
|
|
|
|
not a whitespace character). */
|
|
|
|
|
while (*(end - 1) == ' ' || *(end - 1) == '\t')
|
|
|
|
|
end--;
|
|
|
|
|
*end = '\0';
|
2004-03-08 17:59:24 +00:00
|
|
|
|
/* FIXME: Oh, no! This is so lame! Should use realloc and
|
|
|
|
|
really append. */
|
2004-01-31 13:58:27 +00:00
|
|
|
|
if (list)
|
|
|
|
|
{
|
2008-05-26 13:43:20 +00:00
|
|
|
|
new_list = xasprintf ("%s,\"%s", list, gc_percent_escape (start));
|
2004-01-31 13:58:27 +00:00
|
|
|
|
xfree (list);
|
|
|
|
|
list = new_list;
|
|
|
|
|
}
|
|
|
|
|
else
|
2008-05-26 13:43:20 +00:00
|
|
|
|
list = xasprintf ("\"%s", gc_percent_escape (start));
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
2004-06-14 08:32:07 +00:00
|
|
|
|
if (length < 0 || ferror (list_file))
|
2008-05-26 15:05:31 +00:00
|
|
|
|
gc_error (1, errno, "can not read list file %s", list_filename);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
2004-01-31 13:58:27 +00:00
|
|
|
|
|
|
|
|
|
list_option->active = 1;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
list_option->value = list;
|
2004-01-31 13:58:27 +00:00
|
|
|
|
|
2008-08-06 11:48:23 +00:00
|
|
|
|
/* Fix up the read-only flag. */
|
|
|
|
|
config_option = find_option
|
|
|
|
|
(component, gc_backend[backend].option_config_filename, GC_BACKEND_ANY);
|
|
|
|
|
if (config_option->flags & GC_OPT_FLAG_NO_CHANGE)
|
|
|
|
|
list_option->flags |= GC_OPT_FLAG_NO_CHANGE;
|
|
|
|
|
|
2010-08-23 19:26:05 +00:00
|
|
|
|
if (list_file && fclose (list_file))
|
2008-05-26 15:05:31 +00:00
|
|
|
|
gc_error (1, errno, "error closing %s", list_filename);
|
2004-06-14 08:32:07 +00:00
|
|
|
|
xfree (line);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Retrieve the currently active options and their defaults from all
|
2007-03-06 20:44:41 +00:00
|
|
|
|
involved backends for this component. Using -1 for component will
|
|
|
|
|
retrieve all options from all components. */
|
2004-01-28 23:58:18 +00:00
|
|
|
|
void
|
|
|
|
|
gc_component_retrieve_options (int component)
|
|
|
|
|
{
|
2007-03-06 20:44:41 +00:00
|
|
|
|
int process_all = 0;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
int backend_seen[GC_BACKEND_NR];
|
|
|
|
|
gc_backend_t backend;
|
2007-03-06 20:44:41 +00:00
|
|
|
|
gc_option_t *option;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2010-08-19 09:53:55 +00:00
|
|
|
|
if (component == GC_COMPONENT_PINENTRY)
|
|
|
|
|
return; /* Dummy module for now. */
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
for (backend = 0; backend < GC_BACKEND_NR; backend++)
|
|
|
|
|
backend_seen[backend] = 0;
|
|
|
|
|
|
2007-03-06 20:44:41 +00:00
|
|
|
|
if (component == -1)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
2007-03-06 20:44:41 +00:00
|
|
|
|
process_all = 1;
|
|
|
|
|
component = 0;
|
|
|
|
|
assert (component < GC_COMPONENT_NR);
|
|
|
|
|
}
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2007-03-06 20:44:41 +00:00
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
option = gc_component[component].options;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2007-06-26 13:48:44 +00:00
|
|
|
|
while (option && option->name)
|
2007-03-06 20:44:41 +00:00
|
|
|
|
{
|
|
|
|
|
if (!(option->flags & GC_OPT_FLAG_GROUP))
|
|
|
|
|
{
|
|
|
|
|
backend = option->backend;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2007-03-06 20:44:41 +00:00
|
|
|
|
if (backend_seen[backend])
|
|
|
|
|
{
|
|
|
|
|
option++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
backend_seen[backend] = 1;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2007-03-06 20:44:41 +00:00
|
|
|
|
assert (backend != GC_BACKEND_ANY);
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2007-03-06 20:44:41 +00:00
|
|
|
|
if (gc_backend[backend].program)
|
|
|
|
|
retrieve_options_from_program (component, backend);
|
|
|
|
|
else
|
|
|
|
|
retrieve_options_from_file (component, backend);
|
|
|
|
|
}
|
|
|
|
|
option++;
|
|
|
|
|
}
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
2007-03-06 20:44:41 +00:00
|
|
|
|
while (process_all && ++component < GC_COMPONENT_NR);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2007-03-06 20:44:41 +00:00
|
|
|
|
}
|
2007-08-29 09:51:37 +00:00
|
|
|
|
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2004-02-26 16:28:27 +00:00
|
|
|
|
/* Perform a simple validity check based on the type. Return in
|
|
|
|
|
NEW_VALUE_NR the value of the number in NEW_VALUE if OPTION is of
|
|
|
|
|
type GC_ARG_TYPE_NONE. */
|
2004-01-28 23:58:18 +00:00
|
|
|
|
static void
|
2004-02-25 20:24:53 +00:00
|
|
|
|
option_check_validity (gc_option_t *option, unsigned long flags,
|
2004-02-26 16:28:27 +00:00
|
|
|
|
char *new_value, unsigned long *new_value_nr)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
2004-02-26 18:22:02 +00:00
|
|
|
|
char *arg;
|
|
|
|
|
|
2004-02-26 22:18:36 +00:00
|
|
|
|
if (!option->active)
|
2007-03-06 20:44:41 +00:00
|
|
|
|
gc_error (1, 0, "option %s not supported by backend %s",
|
|
|
|
|
option->name, gc_backend[option->backend].name);
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2004-02-25 20:24:53 +00:00
|
|
|
|
if (option->new_flags || option->new_value)
|
2004-01-30 12:15:53 +00:00
|
|
|
|
gc_error (1, 0, "option %s already changed", option->name);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2004-02-26 16:28:27 +00:00
|
|
|
|
if (flags & GC_OPT_FLAG_DEFAULT)
|
|
|
|
|
{
|
|
|
|
|
if (*new_value)
|
|
|
|
|
gc_error (1, 0, "argument %s provided for deleted option %s",
|
|
|
|
|
new_value, option->name);
|
2004-02-26 18:22:02 +00:00
|
|
|
|
|
|
|
|
|
return;
|
2004-02-26 16:28:27 +00:00
|
|
|
|
}
|
2004-02-26 18:22:02 +00:00
|
|
|
|
|
|
|
|
|
/* GC_ARG_TYPE_NONE options have special list treatment. */
|
|
|
|
|
if (gc_arg_type[option->arg_type].fallback == GC_ARG_TYPE_NONE)
|
2004-02-26 16:28:27 +00:00
|
|
|
|
{
|
2004-02-26 18:22:02 +00:00
|
|
|
|
char *tail;
|
2004-02-26 16:28:27 +00:00
|
|
|
|
|
2010-03-29 12:57:11 +00:00
|
|
|
|
gpg_err_set_errno (0);
|
2004-02-26 18:22:02 +00:00
|
|
|
|
*new_value_nr = strtoul (new_value, &tail, 0);
|
|
|
|
|
|
|
|
|
|
if (errno)
|
|
|
|
|
gc_error (1, errno, "invalid argument for option %s",
|
|
|
|
|
option->name);
|
|
|
|
|
if (*tail)
|
|
|
|
|
gc_error (1, 0, "garbage after argument for option %s",
|
|
|
|
|
option->name);
|
|
|
|
|
|
|
|
|
|
if (!(option->flags & GC_OPT_FLAG_LIST))
|
2004-02-26 16:28:27 +00:00
|
|
|
|
{
|
2004-02-26 18:22:02 +00:00
|
|
|
|
if (*new_value_nr != 1)
|
|
|
|
|
gc_error (1, 0, "argument for non-list option %s of type 0 "
|
|
|
|
|
"(none) must be 1", option->name);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (*new_value_nr == 0)
|
|
|
|
|
gc_error (1, 0, "argument for option %s of type 0 (none) "
|
|
|
|
|
"must be positive", option->name);
|
|
|
|
|
}
|
2004-02-26 16:28:27 +00:00
|
|
|
|
|
2004-02-26 18:22:02 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2004-02-26 16:28:27 +00:00
|
|
|
|
|
2004-02-26 18:22:02 +00:00
|
|
|
|
arg = new_value;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
if (*arg == '\0' || *arg == ',')
|
|
|
|
|
{
|
|
|
|
|
if (!(option->flags & GC_OPT_FLAG_ARG_OPT))
|
|
|
|
|
gc_error (1, 0, "argument required for option %s", option->name);
|
2004-02-26 16:28:27 +00:00
|
|
|
|
|
2004-02-26 18:22:02 +00:00
|
|
|
|
if (*arg == ',' && !(option->flags & GC_OPT_FLAG_LIST))
|
|
|
|
|
gc_error (1, 0, "list found for non-list option %s", option->name);
|
|
|
|
|
}
|
|
|
|
|
else if (gc_arg_type[option->arg_type].fallback == GC_ARG_TYPE_STRING)
|
|
|
|
|
{
|
|
|
|
|
if (*arg != '"')
|
|
|
|
|
gc_error (1, 0, "string argument for option %s must begin "
|
|
|
|
|
"with a quote (\") character", option->name);
|
2008-02-27 17:32:47 +00:00
|
|
|
|
|
|
|
|
|
/* FIXME: We do not allow empty string arguments for now, as
|
|
|
|
|
we do not quote arguments in configuration files, and
|
|
|
|
|
thus no argument is indistinguishable from the empty
|
|
|
|
|
string. */
|
|
|
|
|
if (arg[1] == '\0' || arg[1] == ',')
|
|
|
|
|
gc_error (1, 0, "empty string argument for option %s is "
|
|
|
|
|
"currently not allowed. Please report this!",
|
|
|
|
|
option->name);
|
2004-02-26 18:22:02 +00:00
|
|
|
|
}
|
|
|
|
|
else if (gc_arg_type[option->arg_type].fallback == GC_ARG_TYPE_INT32)
|
|
|
|
|
{
|
2010-04-20 01:11:35 +00:00
|
|
|
|
long res;
|
|
|
|
|
|
2010-03-29 12:57:11 +00:00
|
|
|
|
gpg_err_set_errno (0);
|
2010-04-20 01:11:35 +00:00
|
|
|
|
res = strtol (arg, &arg, 0);
|
|
|
|
|
(void) res;
|
2004-02-26 16:28:27 +00:00
|
|
|
|
|
2004-02-26 18:22:02 +00:00
|
|
|
|
if (errno)
|
|
|
|
|
gc_error (1, errno, "invalid argument for option %s",
|
|
|
|
|
option->name);
|
2004-02-25 20:24:53 +00:00
|
|
|
|
|
2004-02-26 18:22:02 +00:00
|
|
|
|
if (*arg != '\0' && *arg != ',')
|
|
|
|
|
gc_error (1, 0, "garbage after argument for option %s",
|
|
|
|
|
option->name);
|
|
|
|
|
}
|
2015-01-23 15:37:51 +01:00
|
|
|
|
else if (gc_arg_type[option->arg_type].fallback == GC_ARG_TYPE_UINT32)
|
2004-02-26 18:22:02 +00:00
|
|
|
|
{
|
2010-04-20 01:11:35 +00:00
|
|
|
|
unsigned long res;
|
|
|
|
|
|
2010-03-29 12:57:11 +00:00
|
|
|
|
gpg_err_set_errno (0);
|
2010-04-20 01:11:35 +00:00
|
|
|
|
res = strtoul (arg, &arg, 0);
|
|
|
|
|
(void) res;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2004-02-26 18:22:02 +00:00
|
|
|
|
if (errno)
|
|
|
|
|
gc_error (1, errno, "invalid argument for option %s",
|
|
|
|
|
option->name);
|
2004-02-26 16:28:27 +00:00
|
|
|
|
|
2004-02-26 18:22:02 +00:00
|
|
|
|
if (*arg != '\0' && *arg != ',')
|
|
|
|
|
gc_error (1, 0, "garbage after argument for option %s",
|
|
|
|
|
option->name);
|
2004-02-26 16:28:27 +00:00
|
|
|
|
}
|
2004-02-26 18:22:02 +00:00
|
|
|
|
arg = strchr (arg, ',');
|
|
|
|
|
if (arg)
|
|
|
|
|
arg++;
|
2004-02-26 16:28:27 +00:00
|
|
|
|
}
|
2004-02-26 18:22:02 +00:00
|
|
|
|
while (arg && *arg);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-06-15 14:46:23 +00:00
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
|
int
|
|
|
|
|
copy_file (const char *src_name, const char *dst_name)
|
|
|
|
|
{
|
|
|
|
|
#define BUF_LEN 4096
|
|
|
|
|
char buffer[BUF_LEN];
|
|
|
|
|
int len;
|
|
|
|
|
FILE *src;
|
|
|
|
|
FILE *dst;
|
|
|
|
|
|
|
|
|
|
src = fopen (src_name, "r");
|
|
|
|
|
if (src == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
dst = fopen (dst_name, "w");
|
|
|
|
|
if (dst == NULL)
|
|
|
|
|
{
|
|
|
|
|
int saved_err = errno;
|
|
|
|
|
fclose (src);
|
2010-03-29 12:57:11 +00:00
|
|
|
|
gpg_err_set_errno (saved_err);
|
2007-06-15 14:46:23 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
int written;
|
|
|
|
|
|
|
|
|
|
len = fread (buffer, 1, BUF_LEN, src);
|
|
|
|
|
if (len == 0)
|
|
|
|
|
break;
|
|
|
|
|
written = fwrite (buffer, 1, len, dst);
|
|
|
|
|
if (written != len)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
while (!feof (src) && !ferror (src) && !ferror (dst));
|
|
|
|
|
|
|
|
|
|
if (ferror (src) || ferror (dst) || !feof (src))
|
|
|
|
|
{
|
2007-06-18 20:07:33 +00:00
|
|
|
|
int saved_errno = errno;
|
|
|
|
|
fclose (src);
|
|
|
|
|
fclose (dst);
|
2007-06-15 14:46:23 +00:00
|
|
|
|
unlink (dst_name);
|
2010-03-29 12:57:11 +00:00
|
|
|
|
gpg_err_set_errno (saved_errno);
|
2007-06-15 14:46:23 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-23 19:26:05 +00:00
|
|
|
|
if (fclose (dst))
|
2007-06-18 20:07:33 +00:00
|
|
|
|
gc_error (1, errno, "error closing %s", dst_name);
|
2010-08-23 19:26:05 +00:00
|
|
|
|
if (fclose (src))
|
2007-06-18 20:07:33 +00:00
|
|
|
|
gc_error (1, errno, "error closing %s", src_name);
|
|
|
|
|
|
2007-06-15 14:46:23 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#endif /* HAVE_W32_SYSTEM */
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2007-06-18 20:07:33 +00:00
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* Create and verify the new configuration file for the specified
|
|
|
|
|
backend and component. Returns 0 on success and -1 on error. */
|
|
|
|
|
static int
|
|
|
|
|
change_options_file (gc_component_t component, gc_backend_t backend,
|
|
|
|
|
char **src_filenamep, char **dest_filenamep,
|
|
|
|
|
char **orig_filenamep)
|
|
|
|
|
{
|
2014-05-07 18:18:27 +02:00
|
|
|
|
static const char marker[] = "###+++--- " GPGCONF_DISP_NAME " ---+++###";
|
2004-02-26 22:18:36 +00:00
|
|
|
|
/* True if we are within the marker in the config file. */
|
|
|
|
|
int in_marker = 0;
|
|
|
|
|
gc_option_t *option;
|
|
|
|
|
char *line = NULL;
|
|
|
|
|
size_t line_len;
|
|
|
|
|
ssize_t length;
|
|
|
|
|
int res;
|
|
|
|
|
int fd;
|
|
|
|
|
FILE *src_file = NULL;
|
|
|
|
|
FILE *dest_file = NULL;
|
|
|
|
|
char *src_filename;
|
|
|
|
|
char *dest_filename;
|
|
|
|
|
char *orig_filename;
|
|
|
|
|
char *arg;
|
|
|
|
|
char *cur_arg = NULL;
|
|
|
|
|
|
|
|
|
|
option = find_option (component,
|
|
|
|
|
gc_backend[backend].option_name, GC_BACKEND_ANY);
|
|
|
|
|
assert (option);
|
|
|
|
|
assert (option->active);
|
|
|
|
|
assert (gc_arg_type[option->arg_type].fallback != GC_ARG_TYPE_NONE);
|
|
|
|
|
|
|
|
|
|
/* FIXME. Throughout the function, do better error reporting. */
|
2008-05-26 15:05:31 +00:00
|
|
|
|
/* Note that get_config_filename() calls percent_deescape(), so we
|
2004-02-26 22:18:36 +00:00
|
|
|
|
call this before processing the arguments. */
|
2008-05-26 15:05:31 +00:00
|
|
|
|
dest_filename = xstrdup (get_config_filename (component, backend));
|
2014-05-07 18:18:27 +02:00
|
|
|
|
src_filename = xasprintf ("%s.%s.%i.new",
|
|
|
|
|
dest_filename, GPGCONF_NAME, (int)getpid ());
|
|
|
|
|
orig_filename = xasprintf ("%s.%s.%i.bak",
|
|
|
|
|
dest_filename, GPGCONF_NAME, (int)getpid ());
|
2004-02-26 22:18:36 +00:00
|
|
|
|
|
|
|
|
|
arg = option->new_value;
|
2004-03-23 18:27:37 +00:00
|
|
|
|
if (arg && arg[0] == '\0')
|
|
|
|
|
arg = NULL;
|
|
|
|
|
else if (arg)
|
2004-02-26 22:18:36 +00:00
|
|
|
|
{
|
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
|
|
arg++;
|
|
|
|
|
end = strchr (arg, ',');
|
|
|
|
|
if (end)
|
|
|
|
|
*end = '\0';
|
|
|
|
|
|
|
|
|
|
cur_arg = percent_deescape (arg);
|
|
|
|
|
if (end)
|
|
|
|
|
{
|
|
|
|
|
*end = ',';
|
|
|
|
|
arg = end + 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
arg = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-15 14:46:23 +00:00
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
|
res = copy_file (dest_filename, orig_filename);
|
2004-12-15 14:15:54 +00:00
|
|
|
|
#else
|
2004-02-26 22:18:36 +00:00
|
|
|
|
res = link (dest_filename, orig_filename);
|
2004-12-15 14:15:54 +00:00
|
|
|
|
#endif
|
2004-02-26 22:18:36 +00:00
|
|
|
|
if (res < 0 && errno != ENOENT)
|
2014-12-23 00:47:50 +11:00
|
|
|
|
{
|
|
|
|
|
xfree (dest_filename);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2004-02-26 22:18:36 +00:00
|
|
|
|
if (res < 0)
|
|
|
|
|
{
|
|
|
|
|
xfree (orig_filename);
|
|
|
|
|
orig_filename = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* We now initialize the return strings, so the caller can do the
|
|
|
|
|
cleanup for us. */
|
|
|
|
|
*src_filenamep = src_filename;
|
|
|
|
|
*dest_filenamep = dest_filename;
|
|
|
|
|
*orig_filenamep = orig_filename;
|
|
|
|
|
|
|
|
|
|
/* Use open() so that we can use O_EXCL. */
|
|
|
|
|
fd = open (src_filename, O_CREAT | O_EXCL | O_WRONLY, 0644);
|
|
|
|
|
if (fd < 0)
|
|
|
|
|
return -1;
|
|
|
|
|
src_file = fdopen (fd, "w");
|
|
|
|
|
res = errno;
|
|
|
|
|
if (!src_file)
|
|
|
|
|
{
|
2010-03-29 12:57:11 +00:00
|
|
|
|
gpg_err_set_errno (res);
|
2004-02-26 22:18:36 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Only if ORIG_FILENAME is not NULL did the configuration file
|
|
|
|
|
exist already. In this case, we will copy its content into the
|
|
|
|
|
new configuration file, changing it to our liking in the
|
|
|
|
|
process. */
|
|
|
|
|
if (orig_filename)
|
|
|
|
|
{
|
|
|
|
|
dest_file = fopen (dest_filename, "r");
|
|
|
|
|
if (!dest_file)
|
|
|
|
|
goto change_file_one_err;
|
|
|
|
|
|
2004-06-14 08:32:07 +00:00
|
|
|
|
while ((length = read_line (dest_file, &line, &line_len, NULL)) > 0)
|
2004-02-26 22:18:36 +00:00
|
|
|
|
{
|
|
|
|
|
int disable = 0;
|
|
|
|
|
char *start;
|
|
|
|
|
|
|
|
|
|
if (!strncmp (marker, line, sizeof (marker) - 1))
|
|
|
|
|
{
|
|
|
|
|
if (!in_marker)
|
|
|
|
|
in_marker = 1;
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
start = line;
|
|
|
|
|
while (*start == ' ' || *start == '\t')
|
|
|
|
|
start++;
|
|
|
|
|
if (*start && *start != '\r' && *start != '\n' && *start != '#')
|
|
|
|
|
{
|
|
|
|
|
char *end;
|
|
|
|
|
char *endp;
|
|
|
|
|
char saved_end;
|
|
|
|
|
|
|
|
|
|
endp = start;
|
|
|
|
|
end = endp;
|
|
|
|
|
|
|
|
|
|
/* Search for the end of the line. */
|
|
|
|
|
while (*endp && *endp != '#' && *endp != '\r' && *endp != '\n')
|
|
|
|
|
{
|
|
|
|
|
endp++;
|
|
|
|
|
if (*endp && *endp != ' ' && *endp != '\t'
|
|
|
|
|
&& *endp != '\r' && *endp != '\n' && *endp != '#')
|
|
|
|
|
end = endp + 1;
|
|
|
|
|
}
|
|
|
|
|
saved_end = *end;
|
|
|
|
|
*end = '\0';
|
|
|
|
|
|
|
|
|
|
if ((option->new_flags & GC_OPT_FLAG_DEFAULT)
|
|
|
|
|
|| !cur_arg || strcmp (start, cur_arg))
|
|
|
|
|
disable = 1;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Find next argument. */
|
|
|
|
|
if (arg)
|
|
|
|
|
{
|
|
|
|
|
char *arg_end;
|
|
|
|
|
|
|
|
|
|
arg++;
|
|
|
|
|
arg_end = strchr (arg, ',');
|
|
|
|
|
if (arg_end)
|
|
|
|
|
*arg_end = '\0';
|
|
|
|
|
|
|
|
|
|
cur_arg = percent_deescape (arg);
|
|
|
|
|
if (arg_end)
|
|
|
|
|
{
|
|
|
|
|
*arg_end = ',';
|
|
|
|
|
arg = arg_end + 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
arg = NULL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
cur_arg = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*end = saved_end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (disable)
|
|
|
|
|
{
|
|
|
|
|
if (!in_marker)
|
|
|
|
|
{
|
|
|
|
|
fprintf (src_file,
|
2014-05-07 18:18:27 +02:00
|
|
|
|
"# %s disabled this option here at %s\n",
|
|
|
|
|
GPGCONF_DISP_NAME, asctimestamp (gnupg_get_time ()));
|
2004-02-26 22:18:36 +00:00
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_file_one_err;
|
|
|
|
|
fprintf (src_file, "# %s", line);
|
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_file_one_err;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fprintf (src_file, "%s", line);
|
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_file_one_err;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-06-14 08:32:07 +00:00
|
|
|
|
if (length < 0 || ferror (dest_file))
|
2004-02-26 22:18:36 +00:00
|
|
|
|
goto change_file_one_err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!in_marker)
|
|
|
|
|
{
|
|
|
|
|
/* There was no marker. This is the first time we edit the
|
|
|
|
|
file. We add our own marker at the end of the file and
|
|
|
|
|
proceed. Note that we first write a newline, this guards us
|
|
|
|
|
against files which lack the newline at the end of the last
|
|
|
|
|
line, while it doesn't hurt us in all other cases. */
|
|
|
|
|
fprintf (src_file, "\n%s\n", marker);
|
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_file_one_err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* At this point, we have copied everything up to the end marker
|
|
|
|
|
into the new file, except for the arguments we are going to add.
|
|
|
|
|
Now, dump the new arguments and write the end marker, possibly
|
|
|
|
|
followed by the rest of the original file. */
|
|
|
|
|
while (cur_arg)
|
|
|
|
|
{
|
|
|
|
|
fprintf (src_file, "%s\n", cur_arg);
|
|
|
|
|
|
|
|
|
|
/* Find next argument. */
|
|
|
|
|
if (arg)
|
|
|
|
|
{
|
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
|
|
arg++;
|
|
|
|
|
end = strchr (arg, ',');
|
|
|
|
|
if (end)
|
|
|
|
|
*end = '\0';
|
|
|
|
|
|
|
|
|
|
cur_arg = percent_deescape (arg);
|
|
|
|
|
if (end)
|
|
|
|
|
{
|
|
|
|
|
*end = ',';
|
|
|
|
|
arg = end + 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
arg = NULL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
cur_arg = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf (src_file, "%s %s\n", marker, asctimestamp (gnupg_get_time ()));
|
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_file_one_err;
|
|
|
|
|
|
|
|
|
|
if (!in_marker)
|
|
|
|
|
{
|
2014-05-07 18:18:27 +02:00
|
|
|
|
fprintf (src_file, "# %s edited this configuration file.\n",
|
|
|
|
|
GPGCONF_DISP_NAME);
|
2004-02-26 22:18:36 +00:00
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_file_one_err;
|
|
|
|
|
fprintf (src_file, "# It will disable options before this marked "
|
|
|
|
|
"block, but it will\n");
|
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_file_one_err;
|
|
|
|
|
fprintf (src_file, "# never change anything below these lines.\n");
|
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_file_one_err;
|
|
|
|
|
}
|
|
|
|
|
if (dest_file)
|
|
|
|
|
{
|
2004-06-14 08:32:07 +00:00
|
|
|
|
while ((length = read_line (dest_file, &line, &line_len, NULL)) > 0)
|
2004-02-26 22:18:36 +00:00
|
|
|
|
{
|
|
|
|
|
fprintf (src_file, "%s", line);
|
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_file_one_err;
|
|
|
|
|
}
|
2004-06-14 08:32:07 +00:00
|
|
|
|
if (length < 0 || ferror (dest_file))
|
2004-02-26 22:18:36 +00:00
|
|
|
|
goto change_file_one_err;
|
|
|
|
|
}
|
2004-06-14 08:32:07 +00:00
|
|
|
|
xfree (line);
|
|
|
|
|
line = NULL;
|
|
|
|
|
|
2004-02-26 22:18:36 +00:00
|
|
|
|
res = fclose (src_file);
|
|
|
|
|
if (res)
|
|
|
|
|
{
|
|
|
|
|
res = errno;
|
|
|
|
|
close (fd);
|
|
|
|
|
if (dest_file)
|
|
|
|
|
fclose (dest_file);
|
2010-03-29 12:57:11 +00:00
|
|
|
|
gpg_err_set_errno (res);
|
2004-02-26 22:18:36 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
close (fd);
|
|
|
|
|
if (dest_file)
|
|
|
|
|
{
|
|
|
|
|
res = fclose (dest_file);
|
|
|
|
|
if (res)
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
change_file_one_err:
|
2004-06-14 08:32:07 +00:00
|
|
|
|
xfree (line);
|
2004-02-26 22:18:36 +00:00
|
|
|
|
res = errno;
|
|
|
|
|
if (src_file)
|
|
|
|
|
{
|
|
|
|
|
fclose (src_file);
|
|
|
|
|
close (fd);
|
|
|
|
|
}
|
|
|
|
|
if (dest_file)
|
|
|
|
|
fclose (dest_file);
|
2010-03-29 12:57:11 +00:00
|
|
|
|
gpg_err_set_errno (res);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Create and verify the new configuration file for the specified
|
|
|
|
|
backend and component. Returns 0 on success and -1 on error. */
|
|
|
|
|
static int
|
|
|
|
|
change_options_program (gc_component_t component, gc_backend_t backend,
|
|
|
|
|
char **src_filenamep, char **dest_filenamep,
|
|
|
|
|
char **orig_filenamep)
|
|
|
|
|
{
|
2014-05-07 18:18:27 +02:00
|
|
|
|
static const char marker[] = "###+++--- " GPGCONF_DISP_NAME " ---+++###";
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* True if we are within the marker in the config file. */
|
|
|
|
|
int in_marker = 0;
|
|
|
|
|
gc_option_t *option;
|
2004-01-31 13:58:27 +00:00
|
|
|
|
char *line = NULL;
|
2004-01-30 10:38:07 +00:00
|
|
|
|
size_t line_len;
|
|
|
|
|
ssize_t length;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
int res;
|
|
|
|
|
int fd;
|
|
|
|
|
FILE *src_file = NULL;
|
|
|
|
|
FILE *dest_file = NULL;
|
|
|
|
|
char *src_filename;
|
|
|
|
|
char *dest_filename;
|
|
|
|
|
char *orig_filename;
|
2008-01-17 22:42:58 +00:00
|
|
|
|
/* Special hack for gpg, see below. */
|
|
|
|
|
int utf8strings_seen = 0;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
|
|
|
|
/* FIXME. Throughout the function, do better error reporting. */
|
2008-05-26 15:05:31 +00:00
|
|
|
|
dest_filename = xstrdup (get_config_filename (component, backend));
|
2014-05-07 18:18:27 +02:00
|
|
|
|
src_filename = xasprintf ("%s.%s.%i.new",
|
|
|
|
|
dest_filename, GPGCONF_NAME, (int)getpid ());
|
|
|
|
|
orig_filename = xasprintf ("%s.%s.%i.bak",
|
|
|
|
|
dest_filename, GPGCONF_NAME, (int)getpid ());
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2007-06-15 14:46:23 +00:00
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
|
res = copy_file (dest_filename, orig_filename);
|
2004-12-15 14:15:54 +00:00
|
|
|
|
#else
|
2004-01-28 23:58:18 +00:00
|
|
|
|
res = link (dest_filename, orig_filename);
|
2004-12-15 14:15:54 +00:00
|
|
|
|
#endif
|
2004-01-28 23:58:18 +00:00
|
|
|
|
if (res < 0 && errno != ENOENT)
|
|
|
|
|
return -1;
|
|
|
|
|
if (res < 0)
|
|
|
|
|
{
|
2004-01-31 13:58:27 +00:00
|
|
|
|
xfree (orig_filename);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
orig_filename = NULL;
|
|
|
|
|
}
|
2004-02-26 18:22:02 +00:00
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* We now initialize the return strings, so the caller can do the
|
|
|
|
|
cleanup for us. */
|
|
|
|
|
*src_filenamep = src_filename;
|
|
|
|
|
*dest_filenamep = dest_filename;
|
|
|
|
|
*orig_filenamep = orig_filename;
|
|
|
|
|
|
|
|
|
|
/* Use open() so that we can use O_EXCL. */
|
|
|
|
|
fd = open (src_filename, O_CREAT | O_EXCL | O_WRONLY, 0644);
|
|
|
|
|
if (fd < 0)
|
|
|
|
|
return -1;
|
|
|
|
|
src_file = fdopen (fd, "w");
|
|
|
|
|
res = errno;
|
|
|
|
|
if (!src_file)
|
|
|
|
|
{
|
2010-03-29 12:57:11 +00:00
|
|
|
|
gpg_err_set_errno (res);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Only if ORIG_FILENAME is not NULL did the configuration file
|
|
|
|
|
exist already. In this case, we will copy its content into the
|
|
|
|
|
new configuration file, changing it to our liking in the
|
|
|
|
|
process. */
|
|
|
|
|
if (orig_filename)
|
|
|
|
|
{
|
|
|
|
|
dest_file = fopen (dest_filename, "r");
|
|
|
|
|
if (!dest_file)
|
|
|
|
|
goto change_one_err;
|
|
|
|
|
|
2004-06-14 08:32:07 +00:00
|
|
|
|
while ((length = read_line (dest_file, &line, &line_len, NULL)) > 0)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
|
|
|
|
int disable = 0;
|
|
|
|
|
char *start;
|
|
|
|
|
|
|
|
|
|
if (!strncmp (marker, line, sizeof (marker) - 1))
|
|
|
|
|
{
|
|
|
|
|
if (!in_marker)
|
|
|
|
|
in_marker = 1;
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-01-17 22:42:58 +00:00
|
|
|
|
else if (backend == GC_BACKEND_GPG && in_marker
|
|
|
|
|
&& ! strcmp ("utf8-strings\n", line))
|
|
|
|
|
{
|
|
|
|
|
/* Strip duplicated entries. */
|
|
|
|
|
if (utf8strings_seen)
|
|
|
|
|
disable = 1;
|
|
|
|
|
else
|
|
|
|
|
utf8strings_seen = 1;
|
|
|
|
|
}
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
|
|
|
|
start = line;
|
|
|
|
|
while (*start == ' ' || *start == '\t')
|
|
|
|
|
start++;
|
|
|
|
|
if (*start && *start != '\r' && *start != '\n' && *start != '#')
|
|
|
|
|
{
|
2004-02-26 22:18:36 +00:00
|
|
|
|
char *end;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
char saved_end;
|
|
|
|
|
|
|
|
|
|
end = start;
|
|
|
|
|
while (*end && *end != ' ' && *end != '\t'
|
|
|
|
|
&& *end != '\r' && *end != '\n' && *end != '#')
|
|
|
|
|
end++;
|
|
|
|
|
saved_end = *end;
|
|
|
|
|
*end = '\0';
|
|
|
|
|
|
|
|
|
|
option = find_option (component, start, backend);
|
|
|
|
|
*end = saved_end;
|
2004-02-26 16:28:27 +00:00
|
|
|
|
if (option && ((option->new_flags & GC_OPT_FLAG_DEFAULT)
|
|
|
|
|
|| option->new_value))
|
2004-01-28 23:58:18 +00:00
|
|
|
|
disable = 1;
|
|
|
|
|
}
|
|
|
|
|
if (disable)
|
|
|
|
|
{
|
|
|
|
|
if (!in_marker)
|
|
|
|
|
{
|
|
|
|
|
fprintf (src_file,
|
2014-05-07 18:18:27 +02:00
|
|
|
|
"# %s disabled this option here at %s\n",
|
|
|
|
|
GPGCONF_DISP_NAME, asctimestamp (gnupg_get_time ()));
|
2004-01-28 23:58:18 +00:00
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_one_err;
|
|
|
|
|
fprintf (src_file, "# %s", line);
|
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_one_err;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fprintf (src_file, "%s", line);
|
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_one_err;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-06-14 08:32:07 +00:00
|
|
|
|
if (length < 0 || ferror (dest_file))
|
2004-01-28 23:58:18 +00:00
|
|
|
|
goto change_one_err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!in_marker)
|
|
|
|
|
{
|
|
|
|
|
/* There was no marker. This is the first time we edit the
|
|
|
|
|
file. We add our own marker at the end of the file and
|
|
|
|
|
proceed. Note that we first write a newline, this guards us
|
|
|
|
|
against files which lack the newline at the end of the last
|
|
|
|
|
line, while it doesn't hurt us in all other cases. */
|
|
|
|
|
fprintf (src_file, "\n%s\n", marker);
|
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_one_err;
|
|
|
|
|
}
|
|
|
|
|
/* At this point, we have copied everything up to the end marker
|
|
|
|
|
into the new file, except for the options we are going to change.
|
|
|
|
|
Now, dump the changed options (except for those we are going to
|
|
|
|
|
revert to their default), and write the end marker, possibly
|
|
|
|
|
followed by the rest of the original file. */
|
2004-04-29 19:00:37 +00:00
|
|
|
|
|
|
|
|
|
/* We have to turn on UTF8 strings for GnuPG. */
|
2008-01-17 22:42:58 +00:00
|
|
|
|
if (backend == GC_BACKEND_GPG && ! utf8strings_seen)
|
2004-04-29 19:00:37 +00:00
|
|
|
|
fprintf (src_file, "utf8-strings\n");
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
option = gc_component[component].options;
|
|
|
|
|
while (option->name)
|
|
|
|
|
{
|
|
|
|
|
if (!(option->flags & GC_OPT_FLAG_GROUP)
|
|
|
|
|
&& option->backend == backend
|
2004-02-26 18:39:34 +00:00
|
|
|
|
&& option->new_value)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
2004-02-26 18:39:34 +00:00
|
|
|
|
char *arg = option->new_value;
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
if (*arg == '\0' || *arg == ',')
|
|
|
|
|
{
|
|
|
|
|
fprintf (src_file, "%s\n", option->name);
|
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_one_err;
|
|
|
|
|
}
|
|
|
|
|
else if (gc_arg_type[option->arg_type].fallback
|
|
|
|
|
== GC_ARG_TYPE_NONE)
|
|
|
|
|
{
|
|
|
|
|
assert (*arg == '1');
|
|
|
|
|
fprintf (src_file, "%s\n", option->name);
|
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_one_err;
|
|
|
|
|
|
|
|
|
|
arg++;
|
|
|
|
|
}
|
|
|
|
|
else if (gc_arg_type[option->arg_type].fallback
|
|
|
|
|
== GC_ARG_TYPE_STRING)
|
|
|
|
|
{
|
|
|
|
|
char *end;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2004-02-26 18:39:34 +00:00
|
|
|
|
assert (*arg == '"');
|
|
|
|
|
arg++;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2004-02-26 18:39:34 +00:00
|
|
|
|
end = strchr (arg, ',');
|
|
|
|
|
if (end)
|
|
|
|
|
*end = '\0';
|
|
|
|
|
|
|
|
|
|
fprintf (src_file, "%s %s\n", option->name,
|
|
|
|
|
percent_deescape (arg));
|
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_one_err;
|
|
|
|
|
|
|
|
|
|
if (end)
|
|
|
|
|
*end = ',';
|
|
|
|
|
arg = end;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
|
|
end = strchr (arg, ',');
|
|
|
|
|
if (end)
|
|
|
|
|
*end = '\0';
|
|
|
|
|
|
|
|
|
|
fprintf (src_file, "%s %s\n", option->name, arg);
|
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_one_err;
|
|
|
|
|
|
|
|
|
|
if (end)
|
|
|
|
|
*end = ',';
|
|
|
|
|
arg = end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert (arg == NULL || *arg == '\0' || *arg == ',');
|
|
|
|
|
if (arg && *arg == ',')
|
|
|
|
|
arg++;
|
|
|
|
|
}
|
|
|
|
|
while (arg && *arg);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
option++;
|
|
|
|
|
}
|
2004-02-23 19:37:04 +00:00
|
|
|
|
|
|
|
|
|
fprintf (src_file, "%s %s\n", marker, asctimestamp (gnupg_get_time ()));
|
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_one_err;
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
if (!in_marker)
|
|
|
|
|
{
|
2014-05-07 18:18:27 +02:00
|
|
|
|
fprintf (src_file, "# %s edited this configuration file.\n",
|
|
|
|
|
GPGCONF_DISP_NAME);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_one_err;
|
|
|
|
|
fprintf (src_file, "# It will disable options before this marked "
|
|
|
|
|
"block, but it will\n");
|
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_one_err;
|
|
|
|
|
fprintf (src_file, "# never change anything below these lines.\n");
|
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_one_err;
|
|
|
|
|
}
|
|
|
|
|
if (dest_file)
|
|
|
|
|
{
|
2004-06-14 08:32:07 +00:00
|
|
|
|
while ((length = read_line (dest_file, &line, &line_len, NULL)) > 0)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
|
|
|
|
fprintf (src_file, "%s", line);
|
|
|
|
|
if (ferror (src_file))
|
|
|
|
|
goto change_one_err;
|
|
|
|
|
}
|
2004-06-14 08:32:07 +00:00
|
|
|
|
if (length < 0 || ferror (dest_file))
|
2004-01-28 23:58:18 +00:00
|
|
|
|
goto change_one_err;
|
|
|
|
|
}
|
2004-06-14 08:32:07 +00:00
|
|
|
|
xfree (line);
|
|
|
|
|
line = NULL;
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
res = fclose (src_file);
|
|
|
|
|
if (res)
|
|
|
|
|
{
|
|
|
|
|
res = errno;
|
|
|
|
|
close (fd);
|
|
|
|
|
if (dest_file)
|
|
|
|
|
fclose (dest_file);
|
2010-03-29 12:57:11 +00:00
|
|
|
|
gpg_err_set_errno (res);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
close (fd);
|
|
|
|
|
if (dest_file)
|
|
|
|
|
{
|
|
|
|
|
res = fclose (dest_file);
|
|
|
|
|
if (res)
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
change_one_err:
|
2004-06-14 08:32:07 +00:00
|
|
|
|
xfree (line);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
res = errno;
|
|
|
|
|
if (src_file)
|
|
|
|
|
{
|
|
|
|
|
fclose (src_file);
|
|
|
|
|
close (fd);
|
|
|
|
|
}
|
|
|
|
|
if (dest_file)
|
|
|
|
|
fclose (dest_file);
|
2010-03-29 12:57:11 +00:00
|
|
|
|
gpg_err_set_errno (res);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-26 16:28:27 +00:00
|
|
|
|
|
2007-03-06 20:44:41 +00:00
|
|
|
|
/* Common code for gc_component_change_options and
|
|
|
|
|
gc_process_gpgconf_conf. */
|
|
|
|
|
static void
|
|
|
|
|
change_one_value (gc_option_t *option, int *runtime,
|
|
|
|
|
unsigned long flags, char *new_value)
|
|
|
|
|
{
|
|
|
|
|
unsigned long new_value_nr = 0;
|
|
|
|
|
|
|
|
|
|
option_check_validity (option, flags, new_value, &new_value_nr);
|
|
|
|
|
|
|
|
|
|
if (option->flags & GC_OPT_FLAG_RUNTIME)
|
|
|
|
|
runtime[option->backend] = 1;
|
|
|
|
|
|
|
|
|
|
option->new_flags = flags;
|
|
|
|
|
if (!(flags & GC_OPT_FLAG_DEFAULT))
|
|
|
|
|
{
|
|
|
|
|
if (gc_arg_type[option->arg_type].fallback == GC_ARG_TYPE_NONE
|
|
|
|
|
&& (option->flags & GC_OPT_FLAG_LIST))
|
|
|
|
|
{
|
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
|
|
/* We convert the number to a list of 1's for convenient
|
|
|
|
|
list handling. */
|
|
|
|
|
assert (new_value_nr > 0);
|
|
|
|
|
option->new_value = xmalloc ((2 * (new_value_nr - 1) + 1) + 1);
|
|
|
|
|
str = option->new_value;
|
|
|
|
|
*(str++) = '1';
|
|
|
|
|
while (--new_value_nr > 0)
|
|
|
|
|
{
|
|
|
|
|
*(str++) = ',';
|
|
|
|
|
*(str++) = '1';
|
|
|
|
|
}
|
|
|
|
|
*(str++) = '\0';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
option->new_value = xstrdup (new_value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Read the modifications from IN and apply them. If IN is NULL the
|
|
|
|
|
modifications are expected to already have been set to the global
|
|
|
|
|
table. */
|
2004-01-28 23:58:18 +00:00
|
|
|
|
void
|
2010-08-18 19:25:15 +00:00
|
|
|
|
gc_component_change_options (int component, estream_t in, estream_t out)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
|
|
|
|
int err = 0;
|
2004-03-23 12:21:48 +00:00
|
|
|
|
int runtime[GC_BACKEND_NR];
|
2008-05-26 15:05:31 +00:00
|
|
|
|
char *src_filename[GC_BACKEND_NR];
|
|
|
|
|
char *dest_filename[GC_BACKEND_NR];
|
|
|
|
|
char *orig_filename[GC_BACKEND_NR];
|
2004-01-28 23:58:18 +00:00
|
|
|
|
gc_backend_t backend;
|
|
|
|
|
gc_option_t *option;
|
|
|
|
|
char *line = NULL;
|
|
|
|
|
size_t line_len = 0;
|
|
|
|
|
ssize_t length;
|
|
|
|
|
|
2010-08-19 09:53:55 +00:00
|
|
|
|
if (component == GC_COMPONENT_PINENTRY)
|
|
|
|
|
return; /* Dummy component for now. */
|
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
for (backend = 0; backend < GC_BACKEND_NR; backend++)
|
|
|
|
|
{
|
2004-03-23 12:21:48 +00:00
|
|
|
|
runtime[backend] = 0;
|
2008-05-26 15:05:31 +00:00
|
|
|
|
src_filename[backend] = NULL;
|
|
|
|
|
dest_filename[backend] = NULL;
|
|
|
|
|
orig_filename[backend] = NULL;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-03-06 20:44:41 +00:00
|
|
|
|
if (in)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
2007-03-06 20:44:41 +00:00
|
|
|
|
/* Read options from the file IN. */
|
2010-08-18 19:25:15 +00:00
|
|
|
|
while ((length = es_read_line (in, &line, &line_len, NULL)) > 0)
|
2007-03-06 20:44:41 +00:00
|
|
|
|
{
|
|
|
|
|
char *linep;
|
|
|
|
|
unsigned long flags = 0;
|
|
|
|
|
char *new_value = "";
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2007-03-06 20:44:41 +00:00
|
|
|
|
/* Strip newline and carriage return, if present. */
|
|
|
|
|
while (length > 0
|
|
|
|
|
&& (line[length - 1] == '\n' || line[length - 1] == '\r'))
|
|
|
|
|
line[--length] = '\0';
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2007-03-06 20:44:41 +00:00
|
|
|
|
linep = strchr (line, ':');
|
|
|
|
|
if (linep)
|
|
|
|
|
*(linep++) = '\0';
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2007-03-06 20:44:41 +00:00
|
|
|
|
/* Extract additional flags. Default to none. */
|
|
|
|
|
if (linep)
|
|
|
|
|
{
|
|
|
|
|
char *end;
|
|
|
|
|
char *tail;
|
|
|
|
|
|
|
|
|
|
end = strchr (linep, ':');
|
|
|
|
|
if (end)
|
|
|
|
|
*(end++) = '\0';
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2010-03-29 12:57:11 +00:00
|
|
|
|
gpg_err_set_errno (0);
|
2007-03-06 20:44:41 +00:00
|
|
|
|
flags = strtoul (linep, &tail, 0);
|
|
|
|
|
if (errno)
|
|
|
|
|
gc_error (1, errno, "malformed flags in option %s", line);
|
|
|
|
|
if (!(*tail == '\0' || *tail == ':' || *tail == ' '))
|
|
|
|
|
gc_error (1, 0, "garbage after flags in option %s", line);
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2007-03-06 20:44:41 +00:00
|
|
|
|
linep = end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Don't allow setting of the no change flag. */
|
|
|
|
|
flags &= ~GC_OPT_FLAG_NO_CHANGE;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2007-03-06 20:44:41 +00:00
|
|
|
|
/* Extract default value, if present. Default to empty if not. */
|
|
|
|
|
if (linep)
|
|
|
|
|
{
|
|
|
|
|
char *end;
|
|
|
|
|
end = strchr (linep, ':');
|
|
|
|
|
if (end)
|
|
|
|
|
*(end++) = '\0';
|
|
|
|
|
new_value = linep;
|
|
|
|
|
linep = end;
|
|
|
|
|
}
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2007-03-06 20:44:41 +00:00
|
|
|
|
option = find_option (component, line, GC_BACKEND_ANY);
|
|
|
|
|
if (!option)
|
|
|
|
|
gc_error (1, 0, "unknown option %s", line);
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2007-03-06 20:44:41 +00:00
|
|
|
|
if ((option->flags & GC_OPT_FLAG_NO_CHANGE))
|
|
|
|
|
{
|
|
|
|
|
gc_error (0, 0, "ignoring new value for option %s",
|
|
|
|
|
option->name);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2007-03-06 20:44:41 +00:00
|
|
|
|
change_one_value (option, runtime, flags, new_value);
|
|
|
|
|
}
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now that we have collected and locally verified the changes,
|
|
|
|
|
write them out to new configuration files, verify them
|
|
|
|
|
externally, and then commit them. */
|
|
|
|
|
option = gc_component[component].options;
|
2007-06-26 13:48:44 +00:00
|
|
|
|
while (option && option->name)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
|
|
|
|
/* Go on if we have already seen this backend, or if there is
|
|
|
|
|
nothing to do. */
|
2008-05-26 15:05:31 +00:00
|
|
|
|
if (src_filename[option->backend]
|
2004-03-12 14:29:40 +00:00
|
|
|
|
|| !(option->new_flags || option->new_value))
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
|
|
|
|
option++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gc_backend[option->backend].program)
|
2008-05-19 22:46:41 +00:00
|
|
|
|
{
|
|
|
|
|
err = change_options_program (component, option->backend,
|
2008-05-26 15:05:31 +00:00
|
|
|
|
&src_filename[option->backend],
|
|
|
|
|
&dest_filename[option->backend],
|
|
|
|
|
&orig_filename[option->backend]);
|
2008-05-19 22:46:41 +00:00
|
|
|
|
if (! err)
|
|
|
|
|
{
|
|
|
|
|
/* External verification. */
|
|
|
|
|
err = gc_component_check_options (component, out,
|
2008-05-26 15:05:31 +00:00
|
|
|
|
src_filename[option->backend]);
|
2008-05-19 22:46:41 +00:00
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
gc_error (0, 0,
|
|
|
|
|
_("External verification of component %s failed"),
|
|
|
|
|
gc_component[component].name);
|
2010-03-29 12:57:11 +00:00
|
|
|
|
gpg_err_set_errno (EINVAL);
|
2008-05-19 22:46:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2004-01-28 23:58:18 +00:00
|
|
|
|
else
|
|
|
|
|
err = change_options_file (component, option->backend,
|
2008-05-26 15:05:31 +00:00
|
|
|
|
&src_filename[option->backend],
|
|
|
|
|
&dest_filename[option->backend],
|
|
|
|
|
&orig_filename[option->backend]);
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
if (err)
|
|
|
|
|
break;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
|
option++;
|
|
|
|
|
}
|
2004-02-26 18:39:34 +00:00
|
|
|
|
|
2008-05-19 22:46:41 +00:00
|
|
|
|
if (! err && ! opt.dry_run)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
2004-03-12 14:42:31 +00:00
|
|
|
|
for (i = 0; i < GC_BACKEND_NR; i++)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
2008-05-26 15:05:31 +00:00
|
|
|
|
if (src_filename[i])
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
|
|
|
|
/* FIXME: Make a verification here. */
|
|
|
|
|
|
2008-05-26 15:05:31 +00:00
|
|
|
|
assert (dest_filename[i]);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2008-05-26 15:05:31 +00:00
|
|
|
|
if (orig_filename[i])
|
2007-06-15 14:46:23 +00:00
|
|
|
|
{
|
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
|
/* There is no atomic update on W32. */
|
2008-05-26 15:05:31 +00:00
|
|
|
|
err = unlink (dest_filename[i]);
|
2007-06-15 14:46:23 +00:00
|
|
|
|
#endif /* HAVE_W32_SYSTEM */
|
2007-06-18 20:07:33 +00:00
|
|
|
|
if (!err)
|
2008-05-26 15:05:31 +00:00
|
|
|
|
err = rename (src_filename[i], dest_filename[i]);
|
2007-06-15 14:46:23 +00:00
|
|
|
|
}
|
2004-01-28 23:58:18 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2004-12-15 14:15:54 +00:00
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
2007-06-18 20:07:33 +00:00
|
|
|
|
/* We skip the unlink if we expect the file not to
|
|
|
|
|
be there. */
|
2008-05-26 15:05:31 +00:00
|
|
|
|
err = rename (src_filename[i], dest_filename[i]);
|
2007-06-15 14:46:23 +00:00
|
|
|
|
#else /* HAVE_W32_SYSTEM */
|
2004-01-28 23:58:18 +00:00
|
|
|
|
/* This is a bit safer than rename() because we
|
2008-05-26 15:05:31 +00:00
|
|
|
|
expect DEST_FILENAME not to be there. If it
|
2004-01-28 23:58:18 +00:00
|
|
|
|
happens to be there, this will fail. */
|
2008-05-26 15:05:31 +00:00
|
|
|
|
err = link (src_filename[i], dest_filename[i]);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
if (!err)
|
2008-05-26 15:05:31 +00:00
|
|
|
|
err = unlink (src_filename[i]);
|
2007-06-15 14:46:23 +00:00
|
|
|
|
#endif /* !HAVE_W32_SYSTEM */
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
if (err)
|
|
|
|
|
break;
|
2008-05-26 15:05:31 +00:00
|
|
|
|
src_filename[i] = NULL;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-19 22:46:41 +00:00
|
|
|
|
if (err || opt.dry_run)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
2004-01-30 10:38:07 +00:00
|
|
|
|
int saved_errno = errno;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
2008-05-19 22:46:41 +00:00
|
|
|
|
/* An error occured or a dry-run is requested. */
|
2004-03-12 14:42:31 +00:00
|
|
|
|
for (i = 0; i < GC_BACKEND_NR; i++)
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
2008-05-26 15:05:31 +00:00
|
|
|
|
if (src_filename[i])
|
2004-01-28 23:58:18 +00:00
|
|
|
|
{
|
|
|
|
|
/* The change was not yet committed. */
|
2008-05-26 15:05:31 +00:00
|
|
|
|
unlink (src_filename[i]);
|
|
|
|
|
if (orig_filename[i])
|
|
|
|
|
unlink (orig_filename[i]);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* The changes were already committed. FIXME: This is a
|
|
|
|
|
tad dangerous, as we don't know if we don't overwrite
|
|
|
|
|
a version of the file that is even newer than the one
|
|
|
|
|
we just installed. */
|
2008-05-26 15:05:31 +00:00
|
|
|
|
if (orig_filename[i])
|
2007-06-15 14:46:23 +00:00
|
|
|
|
{
|
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
|
/* There is no atomic update on W32. */
|
2008-05-26 15:05:31 +00:00
|
|
|
|
unlink (dest_filename[i]);
|
2007-06-15 14:46:23 +00:00
|
|
|
|
#endif /* HAVE_W32_SYSTEM */
|
2008-05-26 15:05:31 +00:00
|
|
|
|
rename (orig_filename[i], dest_filename[i]);
|
2007-06-15 14:46:23 +00:00
|
|
|
|
}
|
2004-01-28 23:58:18 +00:00
|
|
|
|
else
|
2008-05-26 15:05:31 +00:00
|
|
|
|
unlink (dest_filename[i]);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-05-19 22:46:41 +00:00
|
|
|
|
if (err)
|
|
|
|
|
gc_error (1, saved_errno, "could not commit changes");
|
|
|
|
|
|
|
|
|
|
/* Fall-through for dry run. */
|
|
|
|
|
goto leave;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
2004-03-23 12:21:48 +00:00
|
|
|
|
|
|
|
|
|
/* If it all worked, notify the daemons of the changes. */
|
|
|
|
|
if (opt.runtime)
|
2011-02-23 10:15:34 +01:00
|
|
|
|
for (backend = 0; backend < GC_BACKEND_NR; backend++)
|
2004-03-23 12:21:48 +00:00
|
|
|
|
{
|
|
|
|
|
if (runtime[backend] && gc_backend[backend].runtime_change)
|
2011-02-23 10:15:34 +01:00
|
|
|
|
(*gc_backend[backend].runtime_change) (0);
|
2004-03-23 12:21:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-05-21 13:46:13 +00:00
|
|
|
|
/* Move the per-process backup file into its place. */
|
2011-02-23 10:15:34 +01:00
|
|
|
|
for (backend = 0; backend < GC_BACKEND_NR; backend++)
|
2008-05-26 15:05:31 +00:00
|
|
|
|
if (orig_filename[backend])
|
2004-05-21 13:46:13 +00:00
|
|
|
|
{
|
2008-05-26 15:05:31 +00:00
|
|
|
|
char *backup_filename;
|
2004-05-21 13:46:13 +00:00
|
|
|
|
|
2008-05-26 15:05:31 +00:00
|
|
|
|
assert (dest_filename[backend]);
|
2004-05-21 13:46:13 +00:00
|
|
|
|
|
2014-05-07 18:18:27 +02:00
|
|
|
|
backup_filename = xasprintf ("%s.%s.bak",
|
|
|
|
|
dest_filename[backend], GPGCONF_NAME);
|
2007-06-18 20:07:33 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
|
/* There is no atomic update on W32. */
|
2008-05-26 15:05:31 +00:00
|
|
|
|
unlink (backup_filename);
|
2007-06-18 20:07:33 +00:00
|
|
|
|
#endif /* HAVE_W32_SYSTEM */
|
2008-05-26 15:05:31 +00:00
|
|
|
|
rename (orig_filename[backend], backup_filename);
|
2004-05-21 13:46:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-05-19 22:46:41 +00:00
|
|
|
|
leave:
|
2004-06-14 08:32:07 +00:00
|
|
|
|
xfree (line);
|
2004-01-28 23:58:18 +00:00
|
|
|
|
}
|
2007-03-06 20:44:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Check whether USER matches the current user of one of its group.
|
|
|
|
|
This function may change USER. Returns true is there is a
|
|
|
|
|
match. */
|
|
|
|
|
static int
|
|
|
|
|
key_matches_user_or_group (char *user)
|
|
|
|
|
{
|
|
|
|
|
char *group;
|
|
|
|
|
|
|
|
|
|
if (*user == '*' && user[1] == 0)
|
|
|
|
|
return 1; /* A single asterisk matches all users. */
|
|
|
|
|
|
|
|
|
|
group = strchr (user, ':');
|
|
|
|
|
if (group)
|
|
|
|
|
*group++ = 0;
|
|
|
|
|
|
2007-06-26 13:48:44 +00:00
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
2011-02-23 10:15:34 +01:00
|
|
|
|
/* Under Windows we don't support groups. */
|
2007-06-26 13:48:44 +00:00
|
|
|
|
if (group && *group)
|
|
|
|
|
gc_error (0, 0, _("Note that group specifications are ignored\n"));
|
2010-03-29 12:57:11 +00:00
|
|
|
|
#ifndef HAVE_W32CE_SYSTEM
|
2007-06-26 13:48:44 +00:00
|
|
|
|
if (*user)
|
|
|
|
|
{
|
|
|
|
|
static char *my_name;
|
|
|
|
|
|
|
|
|
|
if (!my_name)
|
|
|
|
|
{
|
|
|
|
|
char tmp[1];
|
|
|
|
|
DWORD size = 1;
|
|
|
|
|
|
|
|
|
|
GetUserNameA (tmp, &size);
|
|
|
|
|
my_name = xmalloc (size);
|
|
|
|
|
if (!GetUserNameA (my_name, &size))
|
|
|
|
|
gc_error (1,0, "error getting current user name: %s",
|
|
|
|
|
w32_strerror (-1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp (user, my_name))
|
|
|
|
|
return 1; /* Found. */
|
|
|
|
|
}
|
2010-03-29 12:57:11 +00:00
|
|
|
|
#endif /*HAVE_W32CE_SYSTEM*/
|
2007-06-26 13:48:44 +00:00
|
|
|
|
#else /*!HAVE_W32_SYSTEM*/
|
2007-03-06 20:44:41 +00:00
|
|
|
|
/* First check whether the user matches. */
|
|
|
|
|
if (*user)
|
|
|
|
|
{
|
|
|
|
|
static char *my_name;
|
|
|
|
|
|
|
|
|
|
if (!my_name)
|
|
|
|
|
{
|
|
|
|
|
struct passwd *pw = getpwuid ( getuid () );
|
|
|
|
|
if (!pw)
|
|
|
|
|
gc_error (1, errno, "getpwuid failed for current user");
|
|
|
|
|
my_name = xstrdup (pw->pw_name);
|
|
|
|
|
}
|
|
|
|
|
if (!strcmp (user, my_name))
|
|
|
|
|
return 1; /* Found. */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If that failed, check whether a group matches. */
|
|
|
|
|
if (group && *group)
|
|
|
|
|
{
|
|
|
|
|
static char *my_group;
|
|
|
|
|
static char **my_supgroups;
|
2007-06-26 13:48:44 +00:00
|
|
|
|
int n;
|
2007-03-06 20:44:41 +00:00
|
|
|
|
|
|
|
|
|
if (!my_group)
|
|
|
|
|
{
|
|
|
|
|
struct group *gr = getgrgid ( getgid () );
|
|
|
|
|
if (!gr)
|
|
|
|
|
gc_error (1, errno, "getgrgid failed for current user");
|
|
|
|
|
my_group = xstrdup (gr->gr_name);
|
|
|
|
|
}
|
|
|
|
|
if (!strcmp (group, my_group))
|
|
|
|
|
return 1; /* Found. */
|
|
|
|
|
|
|
|
|
|
if (!my_supgroups)
|
|
|
|
|
{
|
|
|
|
|
int ngids;
|
|
|
|
|
gid_t *gids;
|
|
|
|
|
|
|
|
|
|
ngids = getgroups (0, NULL);
|
|
|
|
|
gids = xcalloc (ngids+1, sizeof *gids);
|
|
|
|
|
ngids = getgroups (ngids, gids);
|
|
|
|
|
if (ngids < 0)
|
|
|
|
|
gc_error (1, errno, "getgroups failed for current user");
|
|
|
|
|
my_supgroups = xcalloc (ngids+1, sizeof *my_supgroups);
|
|
|
|
|
for (n=0; n < ngids; n++)
|
|
|
|
|
{
|
|
|
|
|
struct group *gr = getgrgid ( gids[n] );
|
|
|
|
|
if (!gr)
|
|
|
|
|
gc_error (1, errno, "getgrgid failed for supplementary group");
|
|
|
|
|
my_supgroups[n] = xstrdup (gr->gr_name);
|
|
|
|
|
}
|
|
|
|
|
xfree (gids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (n=0; my_supgroups[n]; n++)
|
|
|
|
|
if (!strcmp (group, my_supgroups[n]))
|
|
|
|
|
return 1; /* Found. */
|
|
|
|
|
}
|
2007-06-26 13:48:44 +00:00
|
|
|
|
#endif /*!HAVE_W32_SYSTEM*/
|
2007-03-06 20:44:41 +00:00
|
|
|
|
return 0; /* No match. */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Read and process the global configuration file for gpgconf. This
|
|
|
|
|
optional file is used to update our internal tables at runtime and
|
|
|
|
|
may also be used to set new default values. If FNAME is NULL the
|
|
|
|
|
default name will be used. With UPDATE set to true the internal
|
|
|
|
|
tables are actually updated; if not set, only a syntax check is
|
|
|
|
|
done. If DEFAULTS is true the global options are written to the
|
2007-10-23 18:13:27 +00:00
|
|
|
|
configuration files. If LISTFP is set, no changes are done but the
|
|
|
|
|
configuration file is printed to LISTFP in a colon separated format.
|
2007-03-06 20:44:41 +00:00
|
|
|
|
|
|
|
|
|
Returns 0 on success or if the config file is not present; -1 is
|
|
|
|
|
returned on error. */
|
|
|
|
|
int
|
2007-10-23 18:13:27 +00:00
|
|
|
|
gc_process_gpgconf_conf (const char *fname_arg, int update, int defaults,
|
2010-08-18 19:25:15 +00:00
|
|
|
|
estream_t listfp)
|
2007-03-06 20:44:41 +00:00
|
|
|
|
{
|
|
|
|
|
int result = 0;
|
|
|
|
|
char *line = NULL;
|
|
|
|
|
size_t line_len = 0;
|
|
|
|
|
ssize_t length;
|
|
|
|
|
FILE *config;
|
|
|
|
|
int lineno = 0;
|
|
|
|
|
int in_rule = 0;
|
|
|
|
|
int got_match = 0;
|
|
|
|
|
int runtime[GC_BACKEND_NR];
|
|
|
|
|
int backend_id, component_id;
|
2007-10-23 18:13:27 +00:00
|
|
|
|
char *fname;
|
2007-03-06 20:44:41 +00:00
|
|
|
|
|
2007-10-23 18:13:27 +00:00
|
|
|
|
if (fname_arg)
|
|
|
|
|
fname = xstrdup (fname_arg);
|
|
|
|
|
else
|
2014-05-07 18:18:27 +02:00
|
|
|
|
fname = make_filename (gnupg_sysconfdir (), GPGCONF_NAME EXTSEP_S "conf",
|
|
|
|
|
NULL);
|
2007-03-06 20:44:41 +00:00
|
|
|
|
|
|
|
|
|
for (backend_id = 0; backend_id < GC_BACKEND_NR; backend_id++)
|
|
|
|
|
runtime[backend_id] = 0;
|
|
|
|
|
|
|
|
|
|
config = fopen (fname, "r");
|
|
|
|
|
if (!config)
|
|
|
|
|
{
|
|
|
|
|
/* Do not print an error if the file is not available, except
|
2007-10-23 18:13:27 +00:00
|
|
|
|
when running in syntax check mode. */
|
2007-03-06 20:44:41 +00:00
|
|
|
|
if (errno != ENOENT || !update)
|
|
|
|
|
{
|
2012-06-05 19:29:22 +02:00
|
|
|
|
gc_error (0, errno, "can not open global config file '%s'", fname);
|
2007-03-06 20:44:41 +00:00
|
|
|
|
result = -1;
|
|
|
|
|
}
|
2007-06-15 14:46:23 +00:00
|
|
|
|
xfree (fname);
|
2007-03-06 20:44:41 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while ((length = read_line (config, &line, &line_len, NULL)) > 0)
|
|
|
|
|
{
|
|
|
|
|
char *key, *component, *option, *flags, *value;
|
|
|
|
|
char *empty;
|
|
|
|
|
gc_option_t *option_info = NULL;
|
|
|
|
|
char *p;
|
|
|
|
|
int is_continuation;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2007-03-06 20:44:41 +00:00
|
|
|
|
lineno++;
|
|
|
|
|
key = line;
|
|
|
|
|
while (*key == ' ' || *key == '\t')
|
|
|
|
|
key++;
|
|
|
|
|
if (!*key || *key == '#' || *key == '\r' || *key == '\n')
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
is_continuation = (key != line);
|
|
|
|
|
|
|
|
|
|
/* Parse the key field. */
|
|
|
|
|
if (!is_continuation && got_match)
|
|
|
|
|
break; /* Finish after the first match. */
|
|
|
|
|
else if (!is_continuation)
|
|
|
|
|
{
|
|
|
|
|
in_rule = 0;
|
|
|
|
|
for (p=key+1; *p && !strchr (" \t\r\n", *p); p++)
|
|
|
|
|
;
|
|
|
|
|
if (!*p)
|
|
|
|
|
{
|
2012-06-05 19:29:22 +02:00
|
|
|
|
gc_error (0, 0, "missing rule at '%s', line %d", fname, lineno);
|
2007-03-06 20:44:41 +00:00
|
|
|
|
result = -1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
*p++ = 0;
|
|
|
|
|
component = p;
|
|
|
|
|
}
|
|
|
|
|
else if (!in_rule)
|
|
|
|
|
{
|
2012-06-05 19:29:22 +02:00
|
|
|
|
gc_error (0, 0, "continuation but no rule at '%s', line %d",
|
2007-03-06 20:44:41 +00:00
|
|
|
|
fname, lineno);
|
|
|
|
|
result = -1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
component = key;
|
|
|
|
|
key = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
in_rule = 1;
|
|
|
|
|
|
|
|
|
|
/* Parse the component. */
|
|
|
|
|
while (*component == ' ' || *component == '\t')
|
|
|
|
|
component++;
|
|
|
|
|
for (p=component; *p && !strchr (" \t\r\n", *p); p++)
|
|
|
|
|
;
|
|
|
|
|
if (p == component)
|
|
|
|
|
{
|
2012-06-05 19:29:22 +02:00
|
|
|
|
gc_error (0, 0, "missing component at '%s', line %d",
|
2007-03-06 20:44:41 +00:00
|
|
|
|
fname, lineno);
|
|
|
|
|
result = -1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
empty = p;
|
|
|
|
|
*p++ = 0;
|
|
|
|
|
option = p;
|
|
|
|
|
component_id = gc_component_find (component);
|
|
|
|
|
if (component_id < 0)
|
|
|
|
|
{
|
2012-06-05 19:29:22 +02:00
|
|
|
|
gc_error (0, 0, "unknown component at '%s', line %d",
|
2007-03-06 20:44:41 +00:00
|
|
|
|
fname, lineno);
|
|
|
|
|
result = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Parse the option name. */
|
|
|
|
|
while (*option == ' ' || *option == '\t')
|
|
|
|
|
option++;
|
|
|
|
|
for (p=option; *p && !strchr (" \t\r\n", *p); p++)
|
|
|
|
|
;
|
|
|
|
|
if (p == option)
|
|
|
|
|
{
|
2012-06-05 19:29:22 +02:00
|
|
|
|
gc_error (0, 0, "missing option at '%s', line %d",
|
2007-03-06 20:44:41 +00:00
|
|
|
|
fname, lineno);
|
|
|
|
|
result = -1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
*p++ = 0;
|
|
|
|
|
flags = p;
|
|
|
|
|
if ( component_id != -1)
|
|
|
|
|
{
|
|
|
|
|
option_info = find_option (component_id, option, GC_BACKEND_ANY);
|
|
|
|
|
if (!option_info)
|
|
|
|
|
{
|
2012-06-05 19:29:22 +02:00
|
|
|
|
gc_error (0, 0, "unknown option at '%s', line %d",
|
2007-03-06 20:44:41 +00:00
|
|
|
|
fname, lineno);
|
|
|
|
|
result = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Parse the optional flags. */
|
|
|
|
|
while (*flags == ' ' || *flags == '\t')
|
|
|
|
|
flags++;
|
|
|
|
|
if (*flags == '[')
|
|
|
|
|
{
|
|
|
|
|
flags++;
|
|
|
|
|
p = strchr (flags, ']');
|
|
|
|
|
if (!p)
|
|
|
|
|
{
|
2012-06-05 19:29:22 +02:00
|
|
|
|
gc_error (0, 0, "syntax error in rule at '%s', line %d",
|
2007-03-06 20:44:41 +00:00
|
|
|
|
fname, lineno);
|
|
|
|
|
result = -1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
*p++ = 0;
|
|
|
|
|
value = p;
|
|
|
|
|
}
|
|
|
|
|
else /* No flags given. */
|
|
|
|
|
{
|
|
|
|
|
value = flags;
|
|
|
|
|
flags = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Parse the optional value. */
|
|
|
|
|
while (*value == ' ' || *value == '\t')
|
|
|
|
|
value++;
|
|
|
|
|
for (p=value; *p && !strchr ("\r\n", *p); p++)
|
|
|
|
|
;
|
|
|
|
|
if (p == value)
|
|
|
|
|
value = empty; /* No value given; let it point to an empty string. */
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Strip trailing white space. */
|
|
|
|
|
*p = 0;
|
|
|
|
|
for (p--; p > value && (*p == ' ' || *p == '\t'); p--)
|
|
|
|
|
*p = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check flag combinations. */
|
|
|
|
|
if (!flags)
|
|
|
|
|
;
|
|
|
|
|
else if (!strcmp (flags, "default"))
|
|
|
|
|
{
|
|
|
|
|
if (*value)
|
|
|
|
|
{
|
|
|
|
|
gc_error (0, 0, "flag \"default\" may not be combined "
|
2012-06-05 19:29:22 +02:00
|
|
|
|
"with a value at '%s', line %d",
|
2007-03-06 20:44:41 +00:00
|
|
|
|
fname, lineno);
|
|
|
|
|
result = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (!strcmp (flags, "change"))
|
|
|
|
|
;
|
|
|
|
|
else if (!strcmp (flags, "no-change"))
|
|
|
|
|
;
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-06-05 19:29:22 +02:00
|
|
|
|
gc_error (0, 0, "unknown flag at '%s', line %d",
|
2007-03-06 20:44:41 +00:00
|
|
|
|
fname, lineno);
|
|
|
|
|
result = -1;
|
|
|
|
|
}
|
2007-10-23 18:13:27 +00:00
|
|
|
|
|
|
|
|
|
/* In list mode we print out all records. */
|
|
|
|
|
if (listfp && !result)
|
|
|
|
|
{
|
|
|
|
|
/* If this is a new ruleset, print a key record. */
|
|
|
|
|
if (!is_continuation)
|
|
|
|
|
{
|
|
|
|
|
char *group = strchr (key, ':');
|
|
|
|
|
if (group)
|
|
|
|
|
{
|
|
|
|
|
*group++ = 0;
|
|
|
|
|
if ((p = strchr (group, ':')))
|
|
|
|
|
*p = 0; /* We better strip any extra stuff. */
|
2011-02-23 10:15:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (listfp, "k:%s:", gc_percent_escape (key));
|
|
|
|
|
es_fprintf (listfp, "%s\n", group? gc_percent_escape (group):"");
|
2007-10-23 18:13:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* All other lines are rule records. */
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (listfp, "r:::%s:%s:%s:",
|
2011-02-23 10:15:34 +01:00
|
|
|
|
gc_component[component_id].name,
|
2010-08-18 19:25:15 +00:00
|
|
|
|
option_info->name? option_info->name : "",
|
|
|
|
|
flags? flags : "");
|
2007-10-23 18:13:27 +00:00
|
|
|
|
if (value != empty)
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (listfp, "\"%s", gc_percent_escape (value));
|
2011-02-23 10:15:34 +01:00
|
|
|
|
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_putc ('\n', listfp);
|
2007-10-23 18:13:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-03-06 20:44:41 +00:00
|
|
|
|
/* Check whether the key matches but do this only if we are not
|
|
|
|
|
running in syntax check mode. */
|
2011-02-23 10:15:34 +01:00
|
|
|
|
if ( update
|
2007-10-23 18:13:27 +00:00
|
|
|
|
&& !result && !listfp
|
2007-03-06 20:44:41 +00:00
|
|
|
|
&& (got_match || (key && key_matches_user_or_group (key))) )
|
|
|
|
|
{
|
|
|
|
|
int newflags = 0;
|
|
|
|
|
|
|
|
|
|
got_match = 1;
|
|
|
|
|
|
|
|
|
|
/* Apply the flags from gpgconf.conf. */
|
|
|
|
|
if (!flags)
|
|
|
|
|
;
|
|
|
|
|
else if (!strcmp (flags, "default"))
|
|
|
|
|
newflags |= GC_OPT_FLAG_DEFAULT;
|
|
|
|
|
else if (!strcmp (flags, "no-change"))
|
|
|
|
|
option_info->flags |= GC_OPT_FLAG_NO_CHANGE;
|
|
|
|
|
else if (!strcmp (flags, "change"))
|
|
|
|
|
option_info->flags &= ~GC_OPT_FLAG_NO_CHANGE;
|
|
|
|
|
|
|
|
|
|
if (defaults)
|
|
|
|
|
{
|
|
|
|
|
/* Here we explicitly allow to update the value again. */
|
|
|
|
|
if (newflags)
|
|
|
|
|
{
|
|
|
|
|
option_info->new_flags = 0;
|
|
|
|
|
}
|
|
|
|
|
if (*value)
|
|
|
|
|
{
|
|
|
|
|
xfree (option_info->new_value);
|
|
|
|
|
option_info->new_value = NULL;
|
|
|
|
|
}
|
|
|
|
|
change_one_value (option_info, runtime, newflags, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (length < 0 || ferror (config))
|
|
|
|
|
{
|
2012-06-05 19:29:22 +02:00
|
|
|
|
gc_error (0, errno, "error reading from '%s'", fname);
|
2007-03-06 20:44:41 +00:00
|
|
|
|
result = -1;
|
|
|
|
|
}
|
2010-08-23 19:26:05 +00:00
|
|
|
|
if (fclose (config))
|
2012-06-05 19:29:22 +02:00
|
|
|
|
gc_error (0, errno, "error closing '%s'", fname);
|
2007-03-06 20:44:41 +00:00
|
|
|
|
|
|
|
|
|
xfree (line);
|
|
|
|
|
|
|
|
|
|
/* If it all worked, process the options. */
|
2007-10-23 18:13:27 +00:00
|
|
|
|
if (!result && update && defaults && !listfp)
|
2007-03-06 20:44:41 +00:00
|
|
|
|
{
|
|
|
|
|
/* We need to switch off the runtime update, so that we can do
|
|
|
|
|
it later all at once. */
|
|
|
|
|
int save_opt_runtime = opt.runtime;
|
|
|
|
|
opt.runtime = 0;
|
|
|
|
|
|
|
|
|
|
for (component_id = 0; component_id < GC_COMPONENT_NR; component_id++)
|
|
|
|
|
{
|
2008-05-19 22:46:41 +00:00
|
|
|
|
gc_component_change_options (component_id, NULL, NULL);
|
2007-03-06 20:44:41 +00:00
|
|
|
|
}
|
|
|
|
|
opt.runtime = save_opt_runtime;
|
|
|
|
|
|
|
|
|
|
if (opt.runtime)
|
|
|
|
|
{
|
2011-02-23 10:15:34 +01:00
|
|
|
|
for (backend_id = 0; backend_id < GC_BACKEND_NR; backend_id++)
|
2007-03-06 20:44:41 +00:00
|
|
|
|
if (runtime[backend_id] && gc_backend[backend_id].runtime_change)
|
2011-02-23 10:15:34 +01:00
|
|
|
|
(*gc_backend[backend_id].runtime_change) (0);
|
2007-03-06 20:44:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-15 14:46:23 +00:00
|
|
|
|
xfree (fname);
|
2007-03-06 20:44:41 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|