1 /* gpgconf-comp.c - Configuration utility for GnuPG.
2 * Copyright (C) 2004, 2007 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GnuPG; if not, see <http://www.gnu.org/licenses/>.
28 #include <sys/types.h>
35 #ifdef HAVE_W32_SYSTEM
36 # define WIN32_LEAN_AND_MEAN 1
43 /* For log_logv(), asctimestamp(), gnupg_get_time (). */
44 #define JNLIB_NEED_LOG_LOGV
49 #include "gc-opt-flags.h"
53 /* There is a problem with gpg 1.4 under Windows: --gpgconf-list
54 returns a plain filename without escaping. As long as we have not
55 fixed that we need to use gpg2 - it might actually be better to use
57 #ifdef HAVE_W32_SYSTEM
58 #define GPGNAME "gpg2"
65 Components: Add more components and their options.
66 Robustness: Do more validation. Call programs to do validation for us.
67 Add options to change backend binary path.
68 Extract binary path for some backends from gpgsm/gpg config.
72 #if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 ))
73 void gc_error (int status
, int errnum
, const char *fmt
, ...) \
74 __attribute__ ((format (printf
, 3, 4)));
77 /* Output a diagnostic message. If ERRNUM is not 0, then the output
78 is followed by a colon, a white space, and the error string for the
79 error number ERRNUM. In any case the output is finished by a
80 newline. The message is prepended by the program name, a colon,
81 and a whitespace. The output may be further formatted or
82 redirected by the jnlib logging facility. */
84 gc_error (int status
, int errnum
, const char *fmt
, ...)
88 va_start (arg_ptr
, fmt
);
89 log_logv (JNLIB_LOG_ERROR
, fmt
, arg_ptr
);
93 log_printf (": %s\n", strerror (errnum
));
100 log_printf ("fatal error (exit status %i)\n", status
);
106 /* Forward declaration. */
107 void gpg_agent_runtime_change (void);
109 /* Backend configuration. Backends are used to decide how the default
110 and current value of an option can be determined, and how the
111 option can be changed. To every option in every component belongs
112 exactly one backend that controls and determines the option. Some
113 backends are programs from the GPG system. Others might be
114 implemented by GPGConf itself. If you change this enum, don't
115 forget to update GC_BACKEND below. */
118 /* Any backend, used for find_option (). */
121 /* The Gnu Privacy Guard. */
124 /* The Gnu Privacy Guard for S/MIME. */
128 GC_BACKEND_GPG_AGENT
,
130 /* The GnuPG SCDaemon. */
133 /* The Aegypten directory manager. */
136 /* The LDAP server list file for the Aegypten director manager. */
137 GC_BACKEND_DIRMNGR_LDAP_SERVER_LIST
,
139 /* The number of the above entries. */
144 /* To be able to implement generic algorithms for the various
145 backends, we collect all information about them in this struct. */
148 /* The name of the backend. */
151 /* The name of the program that acts as the backend. Some backends
152 don't have an associated program, but are implemented directly by
153 GPGConf. In this case, PROGRAM is NULL. */
156 /* The module name (GNUPG_MODULE_NAME_foo) as defined by
157 ../common/util.h. This value is used to get the actual installed
158 path of the program. 0 is used if no backedn program is
162 /* The runtime change callback. */
163 void (*runtime_change
) (void);
165 /* The option name for the configuration filename of this backend.
166 This must be an absolute pathname. It can be an option from a
167 different backend (but then ordering of the options might
169 const char *option_config_filename
;
171 /* If this is a file backend rather than a program backend, then
172 this is the name of the option associated with the file. */
173 const char *option_name
;
174 } gc_backend
[GC_BACKEND_NR
] =
176 { NULL
}, /* GC_BACKEND_ANY dummy entry. */
177 { "GnuPG", GPGNAME
, GNUPG_MODULE_NAME_GPG
,
178 NULL
, "gpgconf-gpg.conf" },
179 { "GPGSM", "gpgsm", GNUPG_MODULE_NAME_GPGSM
,
180 NULL
, "gpgconf-gpgsm.conf" },
181 { "GPG Agent", "gpg-agent", GNUPG_MODULE_NAME_AGENT
,
182 gpg_agent_runtime_change
, "gpgconf-gpg-agent.conf" },
183 { "SCDaemon", "scdaemon", GNUPG_MODULE_NAME_SCDAEMON
,
184 NULL
, "gpgconf-scdaemon.conf" },
185 { "DirMngr", "dirmngr", GNUPG_MODULE_NAME_DIRMNGR
,
186 NULL
, "gpgconf-dirmngr.conf" },
187 { "DirMngr LDAP Server List", NULL
, 0,
188 NULL
, "ldapserverlist-file", "LDAP Server" },
192 /* Option configuration. */
194 /* An option might take an argument, or not. Argument types can be
195 basic or complex. Basic types are generic and easy to validate.
196 Complex types provide more specific information about the intended
197 use, but can be difficult to validate. If you add to this enum,
198 don't forget to update GC_ARG_TYPE below. YOU MUST NOT CHANGE THE
199 NUMBERS OF THE EXISTING ENTRIES, AS THEY ARE PART OF THE EXTERNAL
203 /* Basic argument types. */
206 GC_ARG_TYPE_NONE
= 0,
208 /* A String argument. */
209 GC_ARG_TYPE_STRING
= 1,
211 /* A signed integer argument. */
212 GC_ARG_TYPE_INT32
= 2,
214 /* An unsigned integer argument. */
215 GC_ARG_TYPE_UINT32
= 3,
217 /* ADD NEW BASIC TYPE ENTRIES HERE. */
219 /* Complex argument types. */
221 /* A complete pathname. */
222 GC_ARG_TYPE_PATHNAME
= 32,
224 /* An LDAP server in the format
225 HOSTNAME:PORT:USERNAME:PASSWORD:BASE_DN. */
226 GC_ARG_TYPE_LDAP_SERVER
= 33,
228 /* A 40 character fingerprint. */
229 GC_ARG_TYPE_KEY_FPR
= 34,
231 /* ADD NEW COMPLEX TYPE ENTRIES HERE. */
233 /* The number of the above entries. */
238 /* For every argument, we record some information about it in the
242 /* For every argument type exists a basic argument type that can be
243 used as a fallback for input and validation purposes. */
244 gc_arg_type_t fallback
;
246 /* Human-readable name of the type. */
248 } gc_arg_type
[GC_ARG_TYPE_NR
] =
250 /* The basic argument types have their own types as fallback. */
251 { GC_ARG_TYPE_NONE
, "none" },
252 { GC_ARG_TYPE_STRING
, "string" },
253 { GC_ARG_TYPE_INT32
, "int32" },
254 { GC_ARG_TYPE_UINT32
, "uint32" },
256 /* Reserved basic type entries for future extension. */
257 { GC_ARG_TYPE_NR
, NULL
}, { GC_ARG_TYPE_NR
, NULL
},
258 { GC_ARG_TYPE_NR
, NULL
}, { GC_ARG_TYPE_NR
, NULL
},
259 { GC_ARG_TYPE_NR
, NULL
}, { GC_ARG_TYPE_NR
, NULL
},
260 { GC_ARG_TYPE_NR
, NULL
}, { GC_ARG_TYPE_NR
, NULL
},
261 { GC_ARG_TYPE_NR
, NULL
}, { GC_ARG_TYPE_NR
, NULL
},
262 { GC_ARG_TYPE_NR
, NULL
}, { GC_ARG_TYPE_NR
, NULL
},
263 { GC_ARG_TYPE_NR
, NULL
}, { GC_ARG_TYPE_NR
, NULL
},
264 { GC_ARG_TYPE_NR
, NULL
}, { GC_ARG_TYPE_NR
, NULL
},
265 { GC_ARG_TYPE_NR
, NULL
}, { GC_ARG_TYPE_NR
, NULL
},
266 { GC_ARG_TYPE_NR
, NULL
}, { GC_ARG_TYPE_NR
, NULL
},
267 { GC_ARG_TYPE_NR
, NULL
}, { GC_ARG_TYPE_NR
, NULL
},
268 { GC_ARG_TYPE_NR
, NULL
}, { GC_ARG_TYPE_NR
, NULL
},
269 { GC_ARG_TYPE_NR
, NULL
}, { GC_ARG_TYPE_NR
, NULL
},
270 { GC_ARG_TYPE_NR
, NULL
}, { GC_ARG_TYPE_NR
, NULL
},
272 /* The complex argument types have a basic type as fallback. */
273 { GC_ARG_TYPE_STRING
, "pathname" },
274 { GC_ARG_TYPE_STRING
, "ldap server" },
275 { GC_ARG_TYPE_STRING
, "key fpr" },
279 /* Every option has an associated expert level, than can be used to
280 hide advanced and expert options from beginners. If you add to
281 this list, don't forget to update GC_LEVEL below. YOU MUST NOT
282 CHANGE THE NUMBERS OF THE EXISTING ENTRIES, AS THEY ARE PART OF THE
283 EXTERNAL INTERFACE. */
286 /* The basic options should always be displayed. */
289 /* The advanced options may be hidden from beginners. */
292 /* The expert options should only be displayed to experts. */
295 /* The invisible options should normally never be displayed. */
298 /* The internal options are never exported, they mark options that
299 are recorded for internal use only. */
302 /* ADD NEW ENTRIES HERE. */
304 /* The number of the above entries. */
308 /* A description for each expert level. */
322 /* Option flags. The flags which are used by the backends are defined
323 by gc-opt-flags.h, included above.
325 YOU MUST NOT CHANGE THE NUMBERS OF THE EXISTING FLAGS, AS THEY ARE
326 PART OF THE EXTERNAL INTERFACE. */
328 /* Some entries in the option list are not options, but mark the
329 beginning of a new group of options. These entries have the GROUP
331 #define GC_OPT_FLAG_GROUP (1UL << 0)
332 /* The ARG_OPT flag for an option indicates that the argument is
333 optional. This is never set for GC_ARG_TYPE_NONE options. */
334 #define GC_OPT_FLAG_ARG_OPT (1UL << 1)
335 /* The LIST flag for an option indicates that the option can occur
336 several times. A comma separated list of arguments is used as the
338 #define GC_OPT_FLAG_LIST (1UL << 2)
339 /* The NO_CHANGE flag for an option indicates that the user should not
340 be allowed to change this option using the standard gpgconf method.
341 Frontends using gpgconf should grey out such options, so that only
342 the current value is displayed. */
343 #define GC_OPT_FLAG_NO_CHANGE (1UL <<7)
346 /* A human-readable description for each flag. */
363 /* To each option, or group marker, the information in the GC_OPTION
364 struct is provided. If you change this, don't forget to update the
365 option list of each component. */
368 /* If this is NULL, then this is a terminator in an array of unknown
369 length. Otherwise, if this entry is a group marker (see FLAGS),
370 then this is the name of the group described by this entry.
371 Otherwise it is the name of the option described by this
372 entry. The name must not contain a colon. */
375 /* The option flags. If the GROUP flag is set, then this entry is a
376 group marker, not an option, and only the fields LEVEL,
377 DESC_DOMAIN and DESC are valid. In all other cases, this entry
378 describes a new option and all fields are valid. */
381 /* The expert level. This field is valid for options and groups. A
382 group has the expert level of the lowest-level option in the
384 gc_expert_level_t level
;
386 /* A gettext domain in which the following description can be found.
387 If this is NULL, then DESC is not translated. Valid for groups
390 Note that we try to keep the description of groups within the
393 IMPORTANT: If you add a new domain please make sure to add a code
394 set switching call to the function my_dgettext further below. */
395 const char *desc_domain
;
397 /* A gettext description for this group or option. If it starts
398 with a '|', then the string up to the next '|' describes the
399 argument, and the description follows the second '|'.
401 In general enclosing these description in N_() is not required
402 because the description should be identical to the one in the
403 help menu of the respective program. */
406 /* The following fields are only valid for options. */
408 /* The type of the option argument. */
409 gc_arg_type_t arg_type
;
411 /* The backend that implements this option. */
412 gc_backend_t backend
;
414 /* The following fields are set to NULL at startup (because all
415 option's are declared as static variables). They are at the end
416 of the list so that they can be omitted from the option
419 /* This is true if the option is supported by this version of the
423 /* The default value for this option. This is NULL if the option is
424 not present in the backend, the empty string if no default is
425 available, and otherwise a quoted string. */
428 /* The default argument is only valid if the "optional arg" flag is
429 set, and specifies the default argument (value) that is used if
430 the argument is omitted. */
433 /* The current value of this option. */
436 /* The new flags for this option. The only defined flag is actually
437 GC_OPT_FLAG_DEFAULT, and it means that the option should be
438 deleted. In this case, NEW_VALUE is NULL. */
439 unsigned long new_flags
;
441 /* The new value of this option. */
444 typedef struct gc_option gc_option_t
;
446 /* Use this macro to terminate an option list. */
447 #define GC_OPTION_NULL { NULL }
450 /* The options of the GC_COMPONENT_GPG_AGENT component. */
451 static gc_option_t gc_options_gpg_agent
[] =
453 /* The configuration file to which we write the changes. */
454 { "gpgconf-gpg-agent.conf", GC_OPT_FLAG_NONE
, GC_LEVEL_INTERNAL
,
455 NULL
, NULL
, GC_ARG_TYPE_PATHNAME
, GC_BACKEND_GPG_AGENT
},
458 GC_OPT_FLAG_GROUP
, GC_LEVEL_BASIC
,
459 "gnupg", N_("Options controlling the diagnostic output") },
460 { "verbose", GC_OPT_FLAG_LIST
|GC_OPT_FLAG_RUNTIME
, GC_LEVEL_BASIC
,
462 GC_ARG_TYPE_NONE
, GC_BACKEND_GPG_AGENT
},
463 { "quiet", GC_OPT_FLAG_NONE
|GC_OPT_FLAG_RUNTIME
, GC_LEVEL_BASIC
,
464 "gnupg", "be somewhat more quiet",
465 GC_ARG_TYPE_NONE
, GC_BACKEND_GPG_AGENT
},
466 { "no-greeting", GC_OPT_FLAG_NONE
, GC_LEVEL_INVISIBLE
,
468 GC_ARG_TYPE_NONE
, GC_BACKEND_GPG_AGENT
},
471 GC_OPT_FLAG_GROUP
, GC_LEVEL_EXPERT
,
472 "gnupg", N_("Options controlling the configuration") },
473 { "options", GC_OPT_FLAG_NONE
, GC_LEVEL_EXPERT
,
474 "gnupg", "|FILE|read options from FILE",
475 GC_ARG_TYPE_PATHNAME
, GC_BACKEND_GPG_AGENT
},
476 { "disable-scdaemon", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
477 "gnupg", "do not use the SCdaemon",
478 GC_ARG_TYPE_NONE
, GC_BACKEND_GPG_AGENT
},
481 GC_OPT_FLAG_GROUP
, GC_LEVEL_ADVANCED
,
482 "gnupg", N_("Options useful for debugging") },
483 { "debug-level", GC_OPT_FLAG_ARG_OPT
|GC_OPT_FLAG_RUNTIME
, GC_LEVEL_ADVANCED
,
484 "gnupg", "|LEVEL|set the debugging level to LEVEL",
485 GC_ARG_TYPE_STRING
, GC_BACKEND_GPG_AGENT
},
486 { "log-file", GC_OPT_FLAG_RUNTIME
, GC_LEVEL_ADVANCED
,
487 "gnupg", N_("|FILE|write server mode logs to FILE"),
488 GC_ARG_TYPE_PATHNAME
, GC_BACKEND_GPG_AGENT
},
489 { "faked-system-time", GC_OPT_FLAG_NONE
, GC_LEVEL_INVISIBLE
,
491 GC_ARG_TYPE_UINT32
, GC_BACKEND_GPG_AGENT
},
494 GC_OPT_FLAG_GROUP
, GC_LEVEL_BASIC
,
495 "gnupg", N_("Options controlling the security") },
496 { "default-cache-ttl", GC_OPT_FLAG_RUNTIME
,
497 GC_LEVEL_BASIC
, "gnupg",
498 "|N|expire cached PINs after N seconds",
499 GC_ARG_TYPE_UINT32
, GC_BACKEND_GPG_AGENT
},
500 { "default-cache-ttl-ssh", GC_OPT_FLAG_RUNTIME
,
501 GC_LEVEL_ADVANCED
, "gnupg",
502 N_("|N|expire SSH keys after N seconds"),
503 GC_ARG_TYPE_UINT32
, GC_BACKEND_GPG_AGENT
},
504 { "max-cache-ttl", GC_OPT_FLAG_RUNTIME
,
505 GC_LEVEL_EXPERT
, "gnupg",
506 N_("|N|set maximum PIN cache lifetime to N seconds"),
507 GC_ARG_TYPE_UINT32
, GC_BACKEND_GPG_AGENT
},
508 { "max-cache-ttl-ssh", GC_OPT_FLAG_RUNTIME
,
509 GC_LEVEL_EXPERT
, "gnupg",
510 N_("|N|set maximum SSH key lifetime to N seconds"),
511 GC_ARG_TYPE_UINT32
, GC_BACKEND_GPG_AGENT
},
512 { "ignore-cache-for-signing", GC_OPT_FLAG_RUNTIME
,
513 GC_LEVEL_BASIC
, "gnupg", "do not use the PIN cache when signing",
514 GC_ARG_TYPE_NONE
, GC_BACKEND_GPG_AGENT
},
515 { "allow-mark-trusted", GC_OPT_FLAG_RUNTIME
,
516 GC_LEVEL_ADVANCED
, "gnupg", "allow clients to mark keys as \"trusted\"",
517 GC_ARG_TYPE_NONE
, GC_BACKEND_GPG_AGENT
},
518 { "no-grab", GC_OPT_FLAG_RUNTIME
, GC_LEVEL_EXPERT
,
519 "gnupg", "do not grab keyboard and mouse",
520 GC_ARG_TYPE_NONE
, GC_BACKEND_GPG_AGENT
},
522 { "Passphrase policy",
523 GC_OPT_FLAG_GROUP
, GC_LEVEL_ADVANCED
,
524 "gnupg", N_("Options enforcing a passphrase policy") },
525 { "enforce-passphrase-constraints", GC_OPT_FLAG_RUNTIME
,
526 GC_LEVEL_EXPERT
, "gnupg",
527 N_("do not allow to bypass the passphrase policy"),
528 GC_ARG_TYPE_NONE
, GC_BACKEND_GPG_AGENT
},
529 { "min-passphrase-len", GC_OPT_FLAG_RUNTIME
,
530 GC_LEVEL_ADVANCED
, "gnupg",
531 N_("|N|set minimal required length for new passphrases to N"),
532 GC_ARG_TYPE_UINT32
, GC_BACKEND_GPG_AGENT
},
533 { "min-passphrase-nonalpha", GC_OPT_FLAG_RUNTIME
,
534 GC_LEVEL_EXPERT
, "gnupg",
535 N_("|N|require at least N non-alpha characters for a new passphrase"),
536 GC_ARG_TYPE_UINT32
, GC_BACKEND_GPG_AGENT
},
537 { "check-passphrase-pattern", GC_OPT_FLAG_RUNTIME
,
539 "gnupg", N_("|FILE|check new passphrases against pattern in FILE"),
540 GC_ARG_TYPE_PATHNAME
, GC_BACKEND_GPG_AGENT
},
541 { "max-passphrase-days", GC_OPT_FLAG_RUNTIME
,
542 GC_LEVEL_EXPERT
, "gnupg",
543 N_("|N|expire the passphrase after N days"),
544 GC_ARG_TYPE_UINT32
, GC_BACKEND_GPG_AGENT
},
545 { "enable-passphrase-history", GC_OPT_FLAG_RUNTIME
,
546 GC_LEVEL_EXPERT
, "gnupg",
547 N_("do not allow the reuse of old passphrases"),
548 GC_ARG_TYPE_NONE
, GC_BACKEND_GPG_AGENT
},
554 /* The options of the GC_COMPONENT_SCDAEMON component. */
555 static gc_option_t gc_options_scdaemon
[] =
557 /* The configuration file to which we write the changes. */
558 { "gpgconf-scdaemon.conf", GC_OPT_FLAG_NONE
, GC_LEVEL_INTERNAL
,
559 NULL
, NULL
, GC_ARG_TYPE_PATHNAME
, GC_BACKEND_SCDAEMON
},
562 GC_OPT_FLAG_GROUP
, GC_LEVEL_BASIC
,
563 "gnupg", N_("Options controlling the diagnostic output") },
564 { "verbose", GC_OPT_FLAG_LIST
, GC_LEVEL_BASIC
,
566 GC_ARG_TYPE_NONE
, GC_BACKEND_SCDAEMON
},
567 { "quiet", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
568 "gnupg", "be somewhat more quiet",
569 GC_ARG_TYPE_NONE
, GC_BACKEND_SCDAEMON
},
570 { "no-greeting", GC_OPT_FLAG_NONE
, GC_LEVEL_INVISIBLE
,
572 GC_ARG_TYPE_NONE
, GC_BACKEND_SCDAEMON
},
575 GC_OPT_FLAG_GROUP
, GC_LEVEL_EXPERT
,
576 "gnupg", N_("Options controlling the configuration") },
577 { "options", GC_OPT_FLAG_NONE
, GC_LEVEL_EXPERT
,
578 "gnupg", "|FILE|read options from FILE",
579 GC_ARG_TYPE_PATHNAME
, GC_BACKEND_SCDAEMON
},
580 { "reader-port", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
581 "gnupg", "|N|connect to reader at port N",
582 GC_ARG_TYPE_STRING
, GC_BACKEND_SCDAEMON
},
583 { "ctapi-driver", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
584 "gnupg", "|NAME|use NAME as ct-API driver",
585 GC_ARG_TYPE_STRING
, GC_BACKEND_SCDAEMON
},
586 { "pcsc-driver", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
587 "gnupg", "|NAME|use NAME as PC/SC driver",
588 GC_ARG_TYPE_STRING
, GC_BACKEND_SCDAEMON
},
589 { "disable-opensc", GC_OPT_FLAG_NONE
, GC_LEVEL_EXPERT
,
590 "gnupg", "do not use the OpenSC layer",
591 GC_ARG_TYPE_NONE
, GC_BACKEND_SCDAEMON
},
592 { "disable-ccid", GC_OPT_FLAG_NONE
, GC_LEVEL_EXPERT
,
593 "gnupg", "do not use the internal CCID driver",
594 GC_ARG_TYPE_NONE
, GC_BACKEND_SCDAEMON
},
595 { "disable-keypad", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
596 "gnupg", "do not use a reader's keypad",
597 GC_ARG_TYPE_NONE
, GC_BACKEND_SCDAEMON
},
600 GC_OPT_FLAG_GROUP
, GC_LEVEL_ADVANCED
,
601 "gnupg", N_("Options useful for debugging") },
602 { "debug-level", GC_OPT_FLAG_ARG_OPT
, GC_LEVEL_ADVANCED
,
603 "gnupg", "|LEVEL|set the debugging level to LEVEL",
604 GC_ARG_TYPE_STRING
, GC_BACKEND_SCDAEMON
},
605 { "log-file", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
606 "gnupg", N_("|FILE|write server mode logs to FILE"),
607 GC_ARG_TYPE_PATHNAME
, GC_BACKEND_SCDAEMON
},
610 GC_OPT_FLAG_GROUP
, GC_LEVEL_BASIC
,
611 "gnupg", N_("Options controlling the security") },
612 { "allow-admin", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
613 "gnupg", "allow the use of admin card commands",
614 GC_ARG_TYPE_NONE
, GC_BACKEND_SCDAEMON
},
621 /* The options of the GC_COMPONENT_GPG component. */
622 static gc_option_t gc_options_gpg
[] =
624 /* The configuration file to which we write the changes. */
625 { "gpgconf-gpg.conf", GC_OPT_FLAG_NONE
, GC_LEVEL_INTERNAL
,
626 NULL
, NULL
, GC_ARG_TYPE_PATHNAME
, GC_BACKEND_GPG
},
629 GC_OPT_FLAG_GROUP
, GC_LEVEL_BASIC
,
630 "gnupg", N_("Options controlling the diagnostic output") },
631 { "verbose", GC_OPT_FLAG_LIST
, GC_LEVEL_BASIC
,
633 GC_ARG_TYPE_NONE
, GC_BACKEND_GPG
},
634 { "quiet", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
635 "gnupg", "be somewhat more quiet",
636 GC_ARG_TYPE_NONE
, GC_BACKEND_GPG
},
637 { "no-greeting", GC_OPT_FLAG_NONE
, GC_LEVEL_INVISIBLE
,
639 GC_ARG_TYPE_NONE
, GC_BACKEND_GPG
},
642 GC_OPT_FLAG_GROUP
, GC_LEVEL_EXPERT
,
643 "gnupg", N_("Options controlling the configuration") },
644 { "default-key", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
645 "gnupg", N_("|NAME|use NAME as default secret key"),
646 GC_ARG_TYPE_STRING
, GC_BACKEND_GPG
},
647 { "encrypt-to", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
648 "gnupg", N_("|NAME|encrypt to user ID NAME as well"),
649 GC_ARG_TYPE_STRING
, GC_BACKEND_GPG
},
650 { "options", GC_OPT_FLAG_NONE
, GC_LEVEL_EXPERT
,
651 "gnupg", "|FILE|read options from FILE",
652 GC_ARG_TYPE_PATHNAME
, GC_BACKEND_GPG
},
655 GC_OPT_FLAG_GROUP
, GC_LEVEL_ADVANCED
,
656 "gnupg", N_("Options useful for debugging") },
657 { "debug-level", GC_OPT_FLAG_ARG_OPT
, GC_LEVEL_ADVANCED
,
658 "gnupg", "|LEVEL|set the debugging level to LEVEL",
659 GC_ARG_TYPE_STRING
, GC_BACKEND_GPG
},
660 { "log-file", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
661 "gnupg", N_("|FILE|write server mode logs to FILE"),
662 GC_ARG_TYPE_PATHNAME
, GC_BACKEND_GPG
},
663 /* { "faked-system-time", GC_OPT_FLAG_NONE, GC_LEVEL_INVISIBLE, */
665 /* GC_ARG_TYPE_UINT32, GC_BACKEND_GPG }, */
668 GC_OPT_FLAG_GROUP
, GC_LEVEL_BASIC
,
669 "gnupg", N_("Configuration for Keyservers") },
670 { "keyserver", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
671 "gnupg", N_("|URL|use keyserver at URL"),
672 GC_ARG_TYPE_STRING
, GC_BACKEND_GPG
},
673 { "allow-pka-lookup", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
674 "gnupg", N_("allow PKA lookups (DNS requests)"),
675 GC_ARG_TYPE_NONE
, GC_BACKEND_GPG
},
683 /* The options of the GC_COMPONENT_GPGSM component. */
684 static gc_option_t gc_options_gpgsm
[] =
686 /* The configuration file to which we write the changes. */
687 { "gpgconf-gpgsm.conf", GC_OPT_FLAG_NONE
, GC_LEVEL_INTERNAL
,
688 NULL
, NULL
, GC_ARG_TYPE_PATHNAME
, GC_BACKEND_GPGSM
},
691 GC_OPT_FLAG_GROUP
, GC_LEVEL_BASIC
,
692 "gnupg", N_("Options controlling the diagnostic output") },
693 { "verbose", GC_OPT_FLAG_LIST
, GC_LEVEL_BASIC
,
695 GC_ARG_TYPE_NONE
, GC_BACKEND_GPGSM
},
696 { "quiet", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
697 "gnupg", "be somewhat more quiet",
698 GC_ARG_TYPE_NONE
, GC_BACKEND_GPGSM
},
699 { "no-greeting", GC_OPT_FLAG_NONE
, GC_LEVEL_INVISIBLE
,
701 GC_ARG_TYPE_NONE
, GC_BACKEND_GPGSM
},
704 GC_OPT_FLAG_GROUP
, GC_LEVEL_EXPERT
,
705 "gnupg", N_("Options controlling the configuration") },
706 { "default-key", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
707 "gnupg", N_("|NAME|use NAME as default secret key"),
708 GC_ARG_TYPE_STRING
, GC_BACKEND_GPGSM
},
709 { "encrypt-to", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
710 "gnupg", N_("|NAME|encrypt to user ID NAME as well"),
711 GC_ARG_TYPE_STRING
, GC_BACKEND_GPGSM
},
712 { "options", GC_OPT_FLAG_NONE
, GC_LEVEL_EXPERT
,
713 "gnupg", "|FILE|read options from FILE",
714 GC_ARG_TYPE_PATHNAME
, GC_BACKEND_GPGSM
},
715 { "prefer-system-dirmngr", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
716 "gnupg", "use system's dirmngr if available",
717 GC_ARG_TYPE_NONE
, GC_BACKEND_GPGSM
},
718 { "p12-charset", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
719 "gnupg", N_("|NAME|use encoding NAME for PKCS#12 passphrases"),
720 GC_ARG_TYPE_STRING
, GC_BACKEND_GPGSM
},
723 GC_OPT_FLAG_GROUP
, GC_LEVEL_ADVANCED
,
724 "gnupg", N_("Options useful for debugging") },
725 { "debug-level", GC_OPT_FLAG_ARG_OPT
, GC_LEVEL_ADVANCED
,
726 "gnupg", "|LEVEL|set the debugging level to LEVEL",
727 GC_ARG_TYPE_STRING
, GC_BACKEND_GPGSM
},
728 { "log-file", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
729 "gnupg", N_("|FILE|write server mode logs to FILE"),
730 GC_ARG_TYPE_PATHNAME
, GC_BACKEND_GPGSM
},
731 { "faked-system-time", GC_OPT_FLAG_NONE
, GC_LEVEL_INVISIBLE
,
733 GC_ARG_TYPE_UINT32
, GC_BACKEND_GPGSM
},
736 GC_OPT_FLAG_GROUP
, GC_LEVEL_BASIC
,
737 "gnupg", N_("Options controlling the security") },
738 { "disable-crl-checks", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
739 "gnupg", "never consult a CRL",
740 GC_ARG_TYPE_NONE
, GC_BACKEND_GPGSM
},
741 { "disable-trusted-cert-crl-check", GC_OPT_FLAG_NONE
, GC_LEVEL_EXPERT
,
742 "gnupg", N_("do not check CRLs for root certificates"),
743 GC_ARG_TYPE_NONE
, GC_BACKEND_GPGSM
},
744 { "enable-ocsp", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
745 "gnupg", "check validity using OCSP",
746 GC_ARG_TYPE_NONE
, GC_BACKEND_GPGSM
},
747 { "include-certs", GC_OPT_FLAG_NONE
, GC_LEVEL_EXPERT
,
748 "gnupg", "|N|number of certificates to include",
749 GC_ARG_TYPE_INT32
, GC_BACKEND_GPGSM
},
750 { "disable-policy-checks", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
751 "gnupg", "do not check certificate policies",
752 GC_ARG_TYPE_NONE
, GC_BACKEND_GPGSM
},
753 { "auto-issuer-key-retrieve", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
754 "gnupg", "fetch missing issuer certificates",
755 GC_ARG_TYPE_NONE
, GC_BACKEND_GPGSM
},
756 { "cipher-algo", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
757 "gnupg", "|NAME|use cipher algorithm NAME",
758 GC_ARG_TYPE_STRING
, GC_BACKEND_GPGSM
},
764 /* The options of the GC_COMPONENT_DIRMNGR component. */
765 static gc_option_t gc_options_dirmngr
[] =
767 /* The configuration file to which we write the changes. */
768 { "gpgconf-dirmngr.conf", GC_OPT_FLAG_NONE
, GC_LEVEL_INTERNAL
,
769 NULL
, NULL
, GC_ARG_TYPE_PATHNAME
, GC_BACKEND_DIRMNGR
},
772 GC_OPT_FLAG_GROUP
, GC_LEVEL_BASIC
,
773 "gnupg", N_("Options controlling the diagnostic output") },
774 { "verbose", GC_OPT_FLAG_LIST
, GC_LEVEL_BASIC
,
775 "dirmngr", "verbose",
776 GC_ARG_TYPE_NONE
, GC_BACKEND_DIRMNGR
},
777 { "quiet", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
778 "dirmngr", "be somewhat more quiet",
779 GC_ARG_TYPE_NONE
, GC_BACKEND_DIRMNGR
},
780 { "no-greeting", GC_OPT_FLAG_NONE
, GC_LEVEL_INVISIBLE
,
782 GC_ARG_TYPE_NONE
, GC_BACKEND_DIRMNGR
},
785 GC_OPT_FLAG_GROUP
, GC_LEVEL_BASIC
,
786 "gnupg", N_("Options controlling the format of the output") },
787 { "sh", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
788 "dirmngr", "sh-style command output",
789 GC_ARG_TYPE_NONE
, GC_BACKEND_DIRMNGR
},
790 { "csh", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
791 "dirmngr", "csh-style command output",
792 GC_ARG_TYPE_NONE
, GC_BACKEND_DIRMNGR
},
795 GC_OPT_FLAG_GROUP
, GC_LEVEL_EXPERT
,
796 "gnupg", N_("Options controlling the configuration") },
797 { "options", GC_OPT_FLAG_NONE
, GC_LEVEL_EXPERT
,
798 "dirmngr", "|FILE|read options from FILE",
799 GC_ARG_TYPE_PATHNAME
, GC_BACKEND_DIRMNGR
},
802 GC_OPT_FLAG_GROUP
, GC_LEVEL_ADVANCED
,
803 "gnupg", N_("Options useful for debugging") },
804 { "debug-level", GC_OPT_FLAG_ARG_OPT
, GC_LEVEL_ADVANCED
,
805 "dirmngr", "|LEVEL|set the debugging level to LEVEL",
806 GC_ARG_TYPE_STRING
, GC_BACKEND_DIRMNGR
},
807 { "no-detach", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
808 "dirmngr", "do not detach from the console",
809 GC_ARG_TYPE_NONE
, GC_BACKEND_DIRMNGR
},
810 { "log-file", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
811 "dirmngr", N_("|FILE|write server mode logs to FILE"),
812 GC_ARG_TYPE_PATHNAME
, GC_BACKEND_DIRMNGR
},
813 { "debug-wait", GC_OPT_FLAG_NONE
, GC_LEVEL_INVISIBLE
,
815 GC_ARG_TYPE_UINT32
, GC_BACKEND_DIRMNGR
},
816 { "faked-system-time", GC_OPT_FLAG_NONE
, GC_LEVEL_INVISIBLE
,
818 GC_ARG_TYPE_UINT32
, GC_BACKEND_DIRMNGR
},
821 GC_OPT_FLAG_GROUP
, GC_LEVEL_BASIC
,
822 "gnupg", N_("Options controlling the interactivity and enforcement") },
823 { "batch", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
824 "dirmngr", "run without asking a user",
825 GC_ARG_TYPE_NONE
, GC_BACKEND_DIRMNGR
},
826 { "force", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
827 "dirmngr", "force loading of outdated CRLs",
828 GC_ARG_TYPE_NONE
, GC_BACKEND_DIRMNGR
},
831 GC_OPT_FLAG_GROUP
, GC_LEVEL_ADVANCED
,
832 "gnupg", N_("Configuration for HTTP servers") },
833 { "disable-http", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
834 "dirmngr", "inhibit the use of HTTP",
835 GC_ARG_TYPE_NONE
, GC_BACKEND_DIRMNGR
},
836 { "ignore-http-dp", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
837 "dirmngr", "ignore HTTP CRL distribution points",
838 GC_ARG_TYPE_NONE
, GC_BACKEND_DIRMNGR
},
839 { "http-proxy", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
840 "dirmngr", "|URL|redirect all HTTP requests to URL",
841 GC_ARG_TYPE_STRING
, GC_BACKEND_DIRMNGR
},
842 { "honor-http-proxy", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
843 "dirmngr", N_("use system's HTTP proxy setting"),
844 GC_ARG_TYPE_NONE
, GC_BACKEND_DIRMNGR
},
847 GC_OPT_FLAG_GROUP
, GC_LEVEL_BASIC
,
848 "gnupg", N_("Configuration of LDAP servers to use") },
849 { "disable-ldap", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
850 "dirmngr", "inhibit the use of LDAP",
851 GC_ARG_TYPE_NONE
, GC_BACKEND_DIRMNGR
},
852 { "ignore-ldap-dp", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
853 "dirmngr", "ignore LDAP CRL distribution points",
854 GC_ARG_TYPE_NONE
, GC_BACKEND_DIRMNGR
},
855 { "ldap-proxy", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
856 "dirmngr", "|HOST|use HOST for LDAP queries",
857 GC_ARG_TYPE_STRING
, GC_BACKEND_DIRMNGR
},
858 { "only-ldap-proxy", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
859 "dirmngr", "do not use fallback hosts with --ldap-proxy",
860 GC_ARG_TYPE_NONE
, GC_BACKEND_DIRMNGR
},
861 { "add-servers", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
862 "dirmngr", "add new servers discovered in CRL distribution points"
863 " to serverlist", GC_ARG_TYPE_NONE
, GC_BACKEND_DIRMNGR
},
864 { "ldaptimeout", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
865 "dirmngr", "|N|set LDAP timeout to N seconds",
866 GC_ARG_TYPE_UINT32
, GC_BACKEND_DIRMNGR
},
867 /* The following entry must not be removed, as it is required for
868 the GC_BACKEND_DIRMNGR_LDAP_SERVER_LIST. */
869 { "ldapserverlist-file",
870 GC_OPT_FLAG_NONE
, GC_LEVEL_INTERNAL
,
871 "dirmngr", "|FILE|read LDAP server list from FILE",
872 GC_ARG_TYPE_PATHNAME
, GC_BACKEND_DIRMNGR
},
873 /* This entry must come after at least one entry for
874 GC_BACKEND_DIRMNGR in this component, so that the entry for
875 "ldapserverlist-file will be initialized before this one. */
876 { "LDAP Server", GC_OPT_FLAG_ARG_OPT
|GC_OPT_FLAG_LIST
, GC_LEVEL_BASIC
,
877 NULL
, "LDAP server list",
878 GC_ARG_TYPE_LDAP_SERVER
, GC_BACKEND_DIRMNGR_LDAP_SERVER_LIST
},
879 { "max-replies", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
880 "dirmngr", "|N|do not return more than N items in one query",
881 GC_ARG_TYPE_UINT32
, GC_BACKEND_DIRMNGR
},
884 GC_OPT_FLAG_GROUP
, GC_LEVEL_ADVANCED
,
885 "gnupg", N_("Configuration for OCSP") },
886 { "allow-ocsp", GC_OPT_FLAG_NONE
, GC_LEVEL_BASIC
,
887 "dirmngr", "allow sending OCSP requests",
888 GC_ARG_TYPE_NONE
, GC_BACKEND_DIRMNGR
},
889 { "ignore-ocsp-service-url", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
890 "dirmngr", "ignore certificate contained OCSP service URLs",
891 GC_ARG_TYPE_NONE
, GC_BACKEND_DIRMNGR
},
892 { "ocsp-responder", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
893 "dirmngr", "|URL|use OCSP responder at URL",
894 GC_ARG_TYPE_STRING
, GC_BACKEND_DIRMNGR
},
895 { "ocsp-signer", GC_OPT_FLAG_NONE
, GC_LEVEL_ADVANCED
,
896 "dirmngr", "|FPR|OCSP response signed by FPR",
897 GC_ARG_TYPE_STRING
, GC_BACKEND_DIRMNGR
},
904 /* Component system. Each component is a set of options that can be
905 configured at the same time. If you change this, don't forget to
906 update GC_COMPONENT below. */
909 /* The classic GPG for OpenPGP. */
913 GC_COMPONENT_GPG_AGENT
,
915 /* The Smardcard Daemon. */
916 GC_COMPONENT_SCDAEMON
,
918 /* GPG for S/MIME. */
921 /* The LDAP Directory Manager for CRLs. */
922 GC_COMPONENT_DIRMNGR
,
924 /* The number of components. */
929 /* The information associated with each component. */
932 /* The name of this component. Must not contain a colon (':')
936 /* The gettext domain for the description DESC. If this is NULL,
937 then the description is not translated. */
938 const char *desc_domain
;
940 /* The description for this domain. */
943 /* The list of options for this component, terminated by
945 gc_option_t
*options
;
948 { "gpg", NULL
, "GPG for OpenPGP", gc_options_gpg
},
949 { "gpg-agent", NULL
, "GPG Agent", gc_options_gpg_agent
},
950 { "scdaemon", NULL
, "Smartcard Daemon", gc_options_scdaemon
},
951 { "gpgsm", NULL
, "GPG for S/MIME", gc_options_gpgsm
},
952 { "dirmngr", NULL
, "Directory Manager", gc_options_dirmngr
}
957 /* Structure used to collect error output of the backend programs. */
959 typedef struct error_line_s
*error_line_t
;
962 error_line_t next
; /* Link to next item. */
963 const char *fname
; /* Name of the config file (points into BUFFER). */
964 unsigned int lineno
; /* Line number of the config file. */
965 const char *errtext
; /* Text of the error message (points into BUFFER). */
966 char buffer
[1]; /* Helper buffer. */
971 /* Engine specific support. */
973 gpg_agent_runtime_change (void)
975 #ifndef HAVE_W32_SYSTEM
976 char *agent
= getenv ("GPG_AGENT_INFO");
978 unsigned long pid_long
;
985 pid_str
= strchr (agent
, ':');
991 pid_long
= strtoul (pid_str
, &tail
, 0);
992 if (errno
|| (*tail
!= ':' && *tail
!= '\0'))
995 pid
= (pid_t
) pid_long
;
997 /* Check for overflow. */
998 if (pid_long
!= (unsigned long) pid
)
1001 /* Ignore any errors here. */
1003 #endif /*!HAVE_W32_SYSTEM*/
1007 /* More or less Robust version of dgettext. It has the side effect of
1008 switching the codeset to utf-8 because this is what we want to
1009 output. In theory it is posible to keep the orginal code set and
1010 switch back for regular disgnostic output (redefine "_(" for that)
1011 but given the natur of this tool, being something invoked from
1012 other pograms, it does not make much sense. */
1014 my_dgettext (const char *domain
, const char *msgid
)
1019 static int switched_codeset
;
1022 if (!switched_codeset
)
1024 switched_codeset
= 1;
1025 bind_textdomain_codeset (PACKAGE_GT
, "utf-8");
1027 bindtextdomain ("dirmngr", LOCALEDIR
);
1028 bind_textdomain_codeset ("dirmngr", "utf-8");
1032 /* Note: This is a hack to actually use the gnupg2 domain as
1033 long we are in a transition phase where gnupg 1.x and 1.9 may
1035 if (!strcmp (domain
, "gnupg"))
1036 domain
= PACKAGE_GT
;
1038 text
= dgettext (domain
, msgid
);
1039 return text
? text
: msgid
;
1047 /* Percent-Escape special characters. The string is valid until the
1048 next invocation of the function. */
1050 my_percent_escape (const char *src
)
1052 static char *esc_str
;
1053 static int esc_str_len
;
1054 int new_len
= 3 * strlen (src
) + 1;
1057 if (esc_str_len
< new_len
)
1059 char *new_esc_str
= realloc (esc_str
, new_len
);
1061 gc_error (1, errno
, "can not escape string");
1062 esc_str
= new_esc_str
;
1063 esc_str_len
= new_len
;
1075 else if (*src
== ':')
1077 /* The colon is used as field separator. */
1082 else if (*src
== ',')
1084 /* The comma is used as list separator. */
1099 /* Percent-Deescape special characters. The string is valid until the
1100 next invocation of the function. */
1102 percent_deescape (const char *src
)
1106 int new_len
= 3 * strlen (src
) + 1;
1109 if (str_len
< new_len
)
1111 char *new_str
= realloc (str
, new_len
);
1113 gc_error (1, errno
, "can not deescape string");
1123 int val
= hextobyte (src
+ 1);
1126 gc_error (1, 0, "malformed end of string %s", src
);
1128 *(dst
++) = (char) val
;
1132 *(dst
++) = *(src
++);
1139 /* List all components that are available. */
1141 gc_component_list_components (FILE *out
)
1143 gc_component_t component
;
1144 gc_option_t
*option
;
1145 gc_backend_t backend
;
1146 int backend_seen
[GC_BACKEND_NR
];
1148 const char *pgmname
;
1150 for (component
= 0; component
< GC_COMPONENT_NR
; component
++)
1152 option
= gc_component
[component
].options
;
1155 for (backend
= 0; backend
< GC_BACKEND_NR
; backend
++)
1156 backend_seen
[backend
] = 0;
1159 for (; option
&& option
->name
; option
++)
1161 if ((option
->flags
& GC_OPT_FLAG_GROUP
))
1163 backend
= option
->backend
;
1164 if (backend_seen
[backend
])
1166 backend_seen
[backend
] = 1;
1167 assert (backend
!= GC_BACKEND_ANY
);
1168 if (gc_backend
[backend
].program
1169 && !gc_backend
[backend
].module_name
)
1171 pgmname
= gnupg_module_name (gc_backend
[backend
].module_name
);
1175 desc
= gc_component
[component
].desc
;
1176 desc
= my_dgettext (gc_component
[component
].desc_domain
, desc
);
1177 fprintf (out
, "%s:%s:",
1178 gc_component
[component
].name
, my_percent_escape (desc
));
1179 fprintf (out
, "%s\n", my_percent_escape (pgmname
));
1187 all_digits_p (const char *p
, size_t len
)
1191 for (; len
; len
--, p
++)
1192 if (!isascii (*p
) || !isdigit (*p
))
1194 return 1; /* Yes. */
1198 /* Collect all error lines from file descriptor FD. Only lines
1199 prefixed with TAG are considered. Close that file descriptor
1200 then. Returns a list of error line items (which may be empty).
1201 There is no error return. */
1203 collect_error_output (int fd
, const char *tag
)
1210 error_line_t eitem
, errlines
, *errlines_tail
;
1211 size_t taglen
= strlen (tag
);
1213 fp
= fdopen (fd
, "r");
1215 gc_error (1, errno
, "can't fdopen pipe for reading");
1218 errlines_tail
= &errlines
;
1221 while ((c
=getc (fp
)) != EOF
)
1224 if (pos
>= sizeof buffer
- 5 || c
== '\n')
1226 buffer
[pos
- (c
== '\n')] = 0;
1228 ; /*Ignore continuations of previous line. */
1229 else if (!strncmp (buffer
, tag
, taglen
) && buffer
[taglen
] == ':')
1231 /* "gpgsm: foo:4: bla" */
1232 /* Yep, we are interested in this line. */
1233 p
= buffer
+ taglen
+ 1;
1234 while (*p
== ' ' || *p
== '\t')
1237 ; /* Empty lines are ignored. */
1238 else if ( (p2
= strchr (p
, ':')) && (p3
= strchr (p2
+1, ':'))
1239 && all_digits_p (p2
+1, p3
- (p2
+1)))
1241 /* Line in standard compiler format. */
1243 while (*p3
== ' ' || *p3
== '\t')
1245 eitem
= xmalloc (sizeof *eitem
+ strlen (p
));
1247 strcpy (eitem
->buffer
, p
);
1248 eitem
->fname
= eitem
->buffer
;
1249 eitem
->buffer
[p2
-p
] = 0;
1250 eitem
->errtext
= eitem
->buffer
+ (p3
- p
);
1251 /* (we already checked that there are only ascii
1252 digits followed by a colon) */
1254 for (p2
++; isdigit (*p2
); p2
++)
1255 eitem
->lineno
= eitem
->lineno
*10 + (*p2
- '0');
1256 *errlines_tail
= eitem
;
1257 errlines_tail
= &eitem
->next
;
1261 /* Other error output. */
1262 eitem
= xmalloc (sizeof *eitem
+ strlen (p
));
1264 strcpy (eitem
->buffer
, p
);
1265 eitem
->fname
= NULL
;
1266 eitem
->errtext
= eitem
->buffer
;
1268 *errlines_tail
= eitem
;
1269 errlines_tail
= &eitem
->next
;
1273 /* If this was not a complete line mark that we are in a
1275 cont_line
= (c
!= '\n');
1279 /* We ignore error lines not terminated by a LF. */
1287 /* Check all components that are available. */
1289 gc_component_check_programs (FILE *out
)
1292 gc_component_t component
;
1293 unsigned int result
;
1294 int backend_seen
[GC_BACKEND_NR
];
1295 gc_backend_t backend
;
1296 gc_option_t
*option
;
1298 const char *pgmname
;
1299 const char *argv
[2];
1303 error_line_t errlines
, errptr
;
1305 /* We use a temporary file to collect the error output. It would be
1306 better to use a pipe here but as of now we have no suitable
1307 fucntion to create a portable pipe outside of exechelp. Thus it
1308 is easier to use the tempfile approach. */
1309 for (component
= 0; component
< GC_COMPONENT_NR
; component
++)
1311 if (!gc_component
[component
].options
)
1314 for (backend
= 0; backend
< GC_BACKEND_NR
; backend
++)
1315 backend_seen
[backend
] = 0;
1317 option
= gc_component
[component
].options
;
1318 for (; option
&& option
->name
; option
++)
1320 if ((option
->flags
& GC_OPT_FLAG_GROUP
))
1322 backend
= option
->backend
;
1323 if (backend_seen
[backend
])
1325 backend_seen
[backend
] = 1;
1326 assert (backend
!= GC_BACKEND_ANY
);
1327 if (!gc_backend
[backend
].program
)
1329 if (!gc_backend
[backend
].module_name
)
1332 pgmname
= gnupg_module_name (gc_backend
[backend
].module_name
);
1333 argv
[0] = "--gpgconf-test";
1336 err
= gnupg_create_inbound_pipe (filedes
);
1338 gc_error (1, 0, _("error creating a pipe: %s\n"),
1339 gpg_strerror (err
));
1343 if (gnupg_spawn_process_fd (pgmname
, argv
, -1, -1, filedes
[1], &pid
))
1347 result
|= 1; /* Program could not be run. */
1352 errlines
= collect_error_output (filedes
[0],
1353 gc_component
[component
].name
);
1354 if (gnupg_wait_process (pgmname
, pid
, &exitcode
))
1357 result
|= 1; /* Program could not be run or it
1358 terminated abnormally. */
1359 result
|= 2; /* Program returned an error. */
1363 /* If the program could not be run, we can't tell whether
1364 the config file is good. */
1368 desc
= gc_component
[component
].desc
;
1369 desc
= my_dgettext (gc_component
[component
].desc_domain
, desc
);
1370 fprintf (out
, "%s:%s:",
1371 gc_component
[component
].name
, my_percent_escape (desc
));
1372 fputs (my_percent_escape (pgmname
), out
);
1373 fprintf (out
, ":%d:%d:", !(result
& 1), !(result
& 2));
1374 for (errptr
= errlines
; errptr
; errptr
= errptr
->next
)
1376 if (errptr
!= errlines
)
1377 fputs ("\n:::::", out
); /* Continuation line. */
1379 fputs (my_percent_escape (errptr
->fname
), out
);
1382 fprintf (out
, "%u", errptr
->lineno
);
1384 fputs (my_percent_escape (errptr
->errtext
), out
);
1391 error_line_t tmp
= errlines
->next
;
1395 break; /* Loop over options of this component */
1402 /* Find the component with the name NAME. Returns -1 if not
1405 gc_component_find (const char *name
)
1409 for (idx
= 0; idx
< GC_COMPONENT_NR
; idx
++)
1411 if (gc_component
[idx
].options
1412 && !strcmp (name
, gc_component
[idx
].name
))
1419 /* List the option OPTION. */
1421 list_one_option (const gc_option_t
*option
, FILE *out
)
1423 const char *desc
= NULL
;
1424 char *arg_name
= NULL
;
1428 desc
= my_dgettext (option
->desc_domain
, option
->desc
);
1432 const char *arg_tail
= strchr (&desc
[1], '|');
1436 int arg_len
= arg_tail
- &desc
[1];
1437 arg_name
= xmalloc (arg_len
+ 1);
1438 memcpy (arg_name
, &desc
[1], arg_len
);
1439 arg_name
[arg_len
] = '\0';
1440 desc
= arg_tail
+ 1;
1446 /* YOU MUST NOT REORDER THE FIELDS IN THIS OUTPUT, AS THEIR ORDER IS
1447 PART OF THE EXTERNAL INTERFACE. YOU MUST NOT REMOVE ANY
1450 /* The name field. */
1451 fprintf (out
, "%s", option
->name
);
1453 /* The flags field. */
1454 fprintf (out
, ":%lu", option
->flags
);
1460 fprintf (out
, "none");
1463 unsigned long flags
= option
->flags
;
1464 unsigned long flag
= 0;
1465 unsigned long first
= 1;
1475 fprintf (out
, "%s", gc_flag
[flag
].name
);
1483 /* The level field. */
1484 fprintf (out
, ":%u", option
->level
);
1486 fprintf (out
, " %s", gc_level
[option
->level
].name
);
1488 /* The description field. */
1489 fprintf (out
, ":%s", desc
? my_percent_escape (desc
) : "");
1491 /* The type field. */
1492 fprintf (out
, ":%u", option
->arg_type
);
1494 fprintf (out
, " %s", gc_arg_type
[option
->arg_type
].name
);
1496 /* The alternate type field. */
1497 fprintf (out
, ":%u", gc_arg_type
[option
->arg_type
].fallback
);
1499 fprintf (out
, " %s",
1500 gc_arg_type
[gc_arg_type
[option
->arg_type
].fallback
].name
);
1502 /* The argument name field. */
1503 fprintf (out
, ":%s", arg_name
? my_percent_escape (arg_name
) : "");
1507 /* The default value field. */
1508 fprintf (out
, ":%s", option
->default_value
? option
->default_value
: "");
1510 /* The default argument field. */
1511 fprintf (out
, ":%s", option
->default_arg
? option
->default_arg
: "");
1513 /* The value field. */
1514 if (gc_arg_type
[option
->arg_type
].fallback
== GC_ARG_TYPE_NONE
1515 && (option
->flags
& GC_OPT_FLAG_LIST
)
1517 /* The special format "1,1,1,1,...,1" is converted to a number
1519 fprintf (out
, ":%u", (unsigned int)((strlen (option
->value
) + 1) / 2));
1521 fprintf (out
, ":%s", option
->value
? option
->value
: "");
1523 /* ADD NEW FIELDS HERE. */
1529 /* List all options of the component COMPONENT. */
1531 gc_component_list_options (int component
, FILE *out
)
1533 const gc_option_t
*option
= gc_component
[component
].options
;
1534 const gc_option_t
*group_option
= NULL
;
1536 while (option
&& option
->name
)
1538 /* Do not output unknown or internal options. */
1539 if (!(option
->flags
& GC_OPT_FLAG_GROUP
)
1540 && (!option
->active
|| option
->level
== GC_LEVEL_INTERNAL
))
1546 if (option
->flags
& GC_OPT_FLAG_GROUP
)
1547 group_option
= option
;
1552 list_one_option (group_option
, out
);
1553 group_option
= NULL
;
1556 list_one_option (option
, out
);
1564 /* Find the option NAME in component COMPONENT, for the backend
1565 BACKEND. If BACKEND is GC_BACKEND_ANY, any backend will match. */
1566 static gc_option_t
*
1567 find_option (gc_component_t component
, const char *name
,
1568 gc_backend_t backend
)
1570 gc_option_t
*option
= gc_component
[component
].options
;
1571 while (option
->name
)
1573 if (!(option
->flags
& GC_OPT_FLAG_GROUP
)
1574 && !strcmp (option
->name
, name
)
1575 && (backend
== GC_BACKEND_ANY
|| option
->backend
== backend
))
1579 return option
->name
? option
: NULL
;
1583 /* Determine the configuration pathname for the component COMPONENT
1584 and backend BACKEND. */
1586 get_config_pathname (gc_component_t component
, gc_backend_t backend
)
1588 char *pathname
= NULL
;
1589 gc_option_t
*option
= find_option
1590 (component
, gc_backend
[backend
].option_config_filename
, GC_BACKEND_ANY
);
1592 assert (option
->arg_type
== GC_ARG_TYPE_PATHNAME
);
1593 assert (!(option
->flags
& GC_OPT_FLAG_LIST
));
1595 if (!option
->active
|| !option
->default_value
)
1596 gc_error (1, 0, "Option %s, needed by backend %s, was not initialized",
1597 gc_backend
[backend
].option_config_filename
,
1598 gc_backend
[backend
].name
);
1600 if (option
->value
&& *option
->value
)
1601 pathname
= percent_deescape (&option
->value
[1]);
1602 else if (option
->default_value
&& *option
->default_value
)
1603 pathname
= percent_deescape (&option
->default_value
[1]);
1607 #ifdef HAVE_DOSISH_SYSTEM
1609 && pathname
[1] == ':'
1610 && (pathname
[2] == '/' || pathname
[2] == '\\')))
1612 if (pathname
[0] != '/')
1614 gc_error (1, 0, "Option %s, needed by backend %s, is not absolute",
1615 gc_backend
[backend
].option_config_filename
,
1616 gc_backend
[backend
].name
);
1622 /* Retrieve the options for the component COMPONENT from backend
1623 BACKEND, which we already know is a program-type backend. */
1625 retrieve_options_from_program (gc_component_t component
, gc_backend_t backend
)
1629 const char *pgmname
;
1630 const char *argv
[2];
1634 size_t line_len
= 0;
1637 char *config_pathname
;
1639 err
= gnupg_create_inbound_pipe (filedes
);
1641 gc_error (1, 0, _("error creating a pipe: %s\n"), gpg_strerror (err
));
1643 pgmname
= (gc_backend
[backend
].module_name
1644 ? gnupg_module_name (gc_backend
[backend
].module_name
)
1645 : gc_backend
[backend
].program
);
1646 argv
[0] = "--gpgconf-list";
1649 err
= gnupg_spawn_process_fd (pgmname
, argv
, -1, filedes
[1], -1, &pid
);
1654 gc_error (1, 0, "could not gather active options from `%s': %s",
1655 pgmname
, gpg_strerror (err
));
1658 config
= fdopen (filedes
[0], "r");
1660 gc_error (1, errno
, "can't fdopen pipe for reading");
1662 while ((length
= read_line (config
, &line
, &line_len
, NULL
)) > 0)
1664 gc_option_t
*option
;
1666 unsigned long flags
= 0;
1667 char *default_value
= NULL
;
1669 /* Strip newline and carriage return, if present. */
1671 && (line
[length
- 1] == '\n' || line
[length
- 1] == '\r'))
1672 line
[--length
] = '\0';
1674 linep
= strchr (line
, ':');
1678 /* Extract additional flags. Default to none. */
1684 end
= strchr (linep
, ':');
1689 flags
= strtoul (linep
, &tail
, 0);
1691 gc_error (1, errno
, "malformed flags in option %s from %s",
1693 if (!(*tail
== '\0' || *tail
== ':' || *tail
== ' '))
1694 gc_error (1, 0, "garbage after flags in option %s from %s",
1700 /* Extract default value, if present. Default to empty if
1706 end
= strchr (linep
, ':');
1710 if (flags
& GC_OPT_FLAG_DEFAULT
)
1711 default_value
= linep
;
1716 /* Look up the option in the component and install the
1717 configuration data. */
1718 option
= find_option (component
, line
, backend
);
1722 gc_error (1, errno
, "option %s returned twice from %s",
1726 option
->flags
|= flags
;
1727 if (default_value
&& *default_value
)
1728 option
->default_value
= xstrdup (default_value
);
1731 if (length
< 0 || ferror (config
))
1732 gc_error (1, errno
, "error reading from %s",pgmname
);
1733 if (fclose (config
) && ferror (config
))
1734 gc_error (1, errno
, "error closing %s", pgmname
);
1736 err
= gnupg_wait_process (pgmname
, pid
, &exitcode
);
1738 gc_error (1, 0, "running %s failed (exitcode=%d): %s",
1739 pgmname
, exitcode
, gpg_strerror (err
));
1742 /* At this point, we can parse the configuration file. */
1743 config_pathname
= get_config_pathname (component
, backend
);
1745 config
= fopen (config_pathname
, "r");
1747 gc_error (0, errno
, "warning: can not open config file %s",
1751 while ((length
= read_line (config
, &line
, &line_len
, NULL
)) > 0)
1755 gc_option_t
*option
;
1758 while (*name
== ' ' || *name
== '\t')
1760 if (!*name
|| *name
== '#' || *name
== '\r' || *name
== '\n')
1764 while (*value
&& *value
!= ' ' && *value
!= '\t'
1765 && *value
!= '#' && *value
!= '\r' && *value
!= '\n')
1767 if (*value
== ' ' || *value
== '\t')
1772 while (*value
== ' ' || *value
== '\t')
1776 while (*end
&& *end
!= '#' && *end
!= '\r' && *end
!= '\n')
1778 while (end
> value
&& (end
[-1] == ' ' || end
[-1] == '\t'))
1785 /* Look up the option in the component and install the
1786 configuration data. */
1787 option
= find_option (component
, line
, backend
);
1792 if (gc_arg_type
[option
->arg_type
].fallback
== GC_ARG_TYPE_NONE
)
1796 "warning: ignoring argument %s for option %s",
1798 opt_value
= xstrdup ("1");
1800 else if (gc_arg_type
[option
->arg_type
].fallback
1801 == GC_ARG_TYPE_STRING
)
1802 opt_value
= xasprintf ("\"%s", my_percent_escape (value
));
1805 /* FIXME: Verify that the number is sane. */
1806 opt_value
= xstrdup (value
);
1809 /* Now enter the option into the table. */
1810 if (!(option
->flags
& GC_OPT_FLAG_LIST
))
1813 free (option
->value
);
1814 option
->value
= opt_value
;
1819 option
->value
= opt_value
;
1822 char *opt_val
= opt_value
;
1824 option
->value
= xasprintf ("%s,%s", option
->value
,
1832 if (length
< 0 || ferror (config
))
1833 gc_error (1, errno
, "error reading from %s", config_pathname
);
1834 if (fclose (config
) && ferror (config
))
1835 gc_error (1, errno
, "error closing %s", config_pathname
);
1842 /* Retrieve the options for the component COMPONENT from backend
1843 BACKEND, which we already know is of type file list. */
1845 retrieve_options_from_file (gc_component_t component
, gc_backend_t backend
)
1847 gc_option_t
*list_option
;
1848 char *list_pathname
;
1851 size_t line_len
= 0;
1855 list_option
= find_option (component
,
1856 gc_backend
[backend
].option_name
, GC_BACKEND_ANY
);
1857 assert (list_option
);
1858 assert (!list_option
->active
);
1860 list_pathname
= get_config_pathname (component
, backend
);
1861 list_file
= fopen (list_pathname
, "r");
1863 gc_error (0, errno
, "warning: can not open list file %s", list_pathname
);
1867 while ((length
= read_line (list_file
, &line
, &line_len
, NULL
)) > 0)
1874 while (*start
== ' ' || *start
== '\t')
1876 if (!*start
|| *start
== '#' || *start
== '\r' || *start
== '\n')
1880 while (*end
&& *end
!= '#' && *end
!= '\r' && *end
!= '\n')
1882 /* Walk back to skip trailing white spaces. Looks evil, but
1883 works because of the conditions on START and END imposed
1884 at this point (END is at least START + 1, and START is
1885 not a whitespace character). */
1886 while (*(end
- 1) == ' ' || *(end
- 1) == '\t')
1889 /* FIXME: Oh, no! This is so lame! Should use realloc and
1893 new_list
= xasprintf ("%s,\"%s", list
, my_percent_escape (start
));
1898 list
= xasprintf ("\"%s", my_percent_escape (start
));
1900 if (length
< 0 || ferror (list_file
))
1901 gc_error (1, errno
, "can not read list file %s", list_pathname
);
1904 list_option
->active
= 1;
1905 list_option
->value
= list
;
1907 if (list_file
&& fclose (list_file
) && ferror (list_file
))
1908 gc_error (1, errno
, "error closing %s", list_pathname
);
1913 /* Retrieve the currently active options and their defaults from all
1914 involved backends for this component. Using -1 for component will
1915 retrieve all options from all components. */
1917 gc_component_retrieve_options (int component
)
1919 int process_all
= 0;
1920 int backend_seen
[GC_BACKEND_NR
];
1921 gc_backend_t backend
;
1922 gc_option_t
*option
;
1924 for (backend
= 0; backend
< GC_BACKEND_NR
; backend
++)
1925 backend_seen
[backend
] = 0;
1927 if (component
== -1)
1931 assert (component
< GC_COMPONENT_NR
);
1936 option
= gc_component
[component
].options
;
1938 while (option
&& option
->name
)
1940 if (!(option
->flags
& GC_OPT_FLAG_GROUP
))
1942 backend
= option
->backend
;
1944 if (backend_seen
[backend
])
1949 backend_seen
[backend
] = 1;
1951 assert (backend
!= GC_BACKEND_ANY
);
1953 if (gc_backend
[backend
].program
)
1954 retrieve_options_from_program (component
, backend
);
1956 retrieve_options_from_file (component
, backend
);
1961 while (process_all
&& ++component
< GC_COMPONENT_NR
);
1967 /* Perform a simple validity check based on the type. Return in
1968 NEW_VALUE_NR the value of the number in NEW_VALUE if OPTION is of
1969 type GC_ARG_TYPE_NONE. */
1971 option_check_validity (gc_option_t
*option
, unsigned long flags
,
1972 char *new_value
, unsigned long *new_value_nr
)
1976 if (!option
->active
)
1977 gc_error (1, 0, "option %s not supported by backend %s",
1978 option
->name
, gc_backend
[option
->backend
].name
);
1980 if (option
->new_flags
|| option
->new_value
)
1981 gc_error (1, 0, "option %s already changed", option
->name
);
1983 if (flags
& GC_OPT_FLAG_DEFAULT
)
1986 gc_error (1, 0, "argument %s provided for deleted option %s",
1987 new_value
, option
->name
);
1992 /* GC_ARG_TYPE_NONE options have special list treatment. */
1993 if (gc_arg_type
[option
->arg_type
].fallback
== GC_ARG_TYPE_NONE
)
1998 *new_value_nr
= strtoul (new_value
, &tail
, 0);
2001 gc_error (1, errno
, "invalid argument for option %s",
2004 gc_error (1, 0, "garbage after argument for option %s",
2007 if (!(option
->flags
& GC_OPT_FLAG_LIST
))
2009 if (*new_value_nr
!= 1)
2010 gc_error (1, 0, "argument for non-list option %s of type 0 "
2011 "(none) must be 1", option
->name
);
2015 if (*new_value_nr
== 0)
2016 gc_error (1, 0, "argument for option %s of type 0 (none) "
2017 "must be positive", option
->name
);
2026 if (*arg
== '\0' || *arg
== ',')
2028 if (!(option
->flags
& GC_OPT_FLAG_ARG_OPT
))
2029 gc_error (1, 0, "argument required for option %s", option
->name
);
2031 if (*arg
== ',' && !(option
->flags
& GC_OPT_FLAG_LIST
))
2032 gc_error (1, 0, "list found for non-list option %s", option
->name
);
2034 else if (gc_arg_type
[option
->arg_type
].fallback
== GC_ARG_TYPE_STRING
)
2037 gc_error (1, 0, "string argument for option %s must begin "
2038 "with a quote (\") character", option
->name
);
2040 else if (gc_arg_type
[option
->arg_type
].fallback
== GC_ARG_TYPE_INT32
)
2043 (void) strtol (arg
, &arg
, 0);
2046 gc_error (1, errno
, "invalid argument for option %s",
2049 if (*arg
!= '\0' && *arg
!= ',')
2050 gc_error (1, 0, "garbage after argument for option %s",
2053 else if (gc_arg_type
[option
->arg_type
].fallback
== GC_ARG_TYPE_INT32
)
2056 (void) strtoul (arg
, &arg
, 0);
2059 gc_error (1, errno
, "invalid argument for option %s",
2062 if (*arg
!= '\0' && *arg
!= ',')
2063 gc_error (1, 0, "garbage after argument for option %s",
2066 arg
= strchr (arg
, ',');
2070 while (arg
&& *arg
);
2073 #ifdef HAVE_W32_SYSTEM
2075 copy_file (const char *src_name
, const char *dst_name
)
2077 #define BUF_LEN 4096
2078 char buffer
[BUF_LEN
];
2083 src
= fopen (src_name
, "r");
2087 dst
= fopen (dst_name
, "w");
2090 int saved_err
= errno
;
2100 len
= fread (buffer
, 1, BUF_LEN
, src
);
2103 written
= fwrite (buffer
, 1, len
, dst
);
2107 while (!feof (src
) && !ferror (src
) && !ferror (dst
));
2109 if (ferror (src
) || ferror (dst
) || !feof (src
))
2111 int saved_errno
= errno
;
2115 errno
= saved_errno
;
2119 if (fclose (dst
) && ferror (dst
))
2120 gc_error (1, errno
, "error closing %s", dst_name
);
2121 if (fclose (src
) && ferror (src
))
2122 gc_error (1, errno
, "error closing %s", src_name
);
2126 #endif /* HAVE_W32_SYSTEM */
2129 /* Create and verify the new configuration file for the specified
2130 backend and component. Returns 0 on success and -1 on error. */
2132 change_options_file (gc_component_t component
, gc_backend_t backend
,
2133 char **src_filenamep
, char **dest_filenamep
,
2134 char **orig_filenamep
)
2136 static const char marker
[] = "###+++--- GPGConf ---+++###";
2137 /* True if we are within the marker in the config file. */
2139 gc_option_t
*option
;
2145 FILE *src_file
= NULL
;
2146 FILE *dest_file
= NULL
;
2148 char *dest_filename
;
2149 char *orig_filename
;
2151 char *cur_arg
= NULL
;
2153 option
= find_option (component
,
2154 gc_backend
[backend
].option_name
, GC_BACKEND_ANY
);
2156 assert (option
->active
);
2157 assert (gc_arg_type
[option
->arg_type
].fallback
!= GC_ARG_TYPE_NONE
);
2159 /* FIXME. Throughout the function, do better error reporting. */
2160 /* Note that get_config_pathname() calls percent_deescape(), so we
2161 call this before processing the arguments. */
2162 dest_filename
= xstrdup (get_config_pathname (component
, backend
));
2163 src_filename
= xasprintf ("%s.gpgconf.%i.new", dest_filename
, getpid ());
2164 orig_filename
= xasprintf ("%s.gpgconf.%i.bak", dest_filename
, getpid ());
2166 arg
= option
->new_value
;
2167 if (arg
&& arg
[0] == '\0')
2174 end
= strchr (arg
, ',');
2178 cur_arg
= percent_deescape (arg
);
2188 #ifdef HAVE_W32_SYSTEM
2189 res
= copy_file (dest_filename
, orig_filename
);
2191 res
= link (dest_filename
, orig_filename
);
2193 if (res
< 0 && errno
!= ENOENT
)
2197 xfree (orig_filename
);
2198 orig_filename
= NULL
;
2201 /* We now initialize the return strings, so the caller can do the
2203 *src_filenamep
= src_filename
;
2204 *dest_filenamep
= dest_filename
;
2205 *orig_filenamep
= orig_filename
;
2207 /* Use open() so that we can use O_EXCL. */
2208 fd
= open (src_filename
, O_CREAT
| O_EXCL
| O_WRONLY
, 0644);
2211 src_file
= fdopen (fd
, "w");
2219 /* Only if ORIG_FILENAME is not NULL did the configuration file
2220 exist already. In this case, we will copy its content into the
2221 new configuration file, changing it to our liking in the
2225 dest_file
= fopen (dest_filename
, "r");
2227 goto change_file_one_err
;
2229 while ((length
= read_line (dest_file
, &line
, &line_len
, NULL
)) > 0)
2234 if (!strncmp (marker
, line
, sizeof (marker
) - 1))
2243 while (*start
== ' ' || *start
== '\t')
2245 if (*start
&& *start
!= '\r' && *start
!= '\n' && *start
!= '#')
2254 /* Search for the end of the line. */
2255 while (*endp
&& *endp
!= '#' && *endp
!= '\r' && *endp
!= '\n')
2258 if (*endp
&& *endp
!= ' ' && *endp
!= '\t'
2259 && *endp
!= '\r' && *endp
!= '\n' && *endp
!= '#')
2265 if ((option
->new_flags
& GC_OPT_FLAG_DEFAULT
)
2266 || !cur_arg
|| strcmp (start
, cur_arg
))
2270 /* Find next argument. */
2276 arg_end
= strchr (arg
, ',');
2280 cur_arg
= percent_deescape (arg
);
2301 "# GPGConf disabled this option here at %s\n",
2302 asctimestamp (gnupg_get_time ()));
2303 if (ferror (src_file
))
2304 goto change_file_one_err
;
2305 fprintf (src_file
, "# %s", line
);
2306 if (ferror (src_file
))
2307 goto change_file_one_err
;
2312 fprintf (src_file
, "%s", line
);
2313 if (ferror (src_file
))
2314 goto change_file_one_err
;
2317 if (length
< 0 || ferror (dest_file
))
2318 goto change_file_one_err
;
2323 /* There was no marker. This is the first time we edit the
2324 file. We add our own marker at the end of the file and
2325 proceed. Note that we first write a newline, this guards us
2326 against files which lack the newline at the end of the last
2327 line, while it doesn't hurt us in all other cases. */
2328 fprintf (src_file
, "\n%s\n", marker
);
2329 if (ferror (src_file
))
2330 goto change_file_one_err
;
2333 /* At this point, we have copied everything up to the end marker
2334 into the new file, except for the arguments we are going to add.
2335 Now, dump the new arguments and write the end marker, possibly
2336 followed by the rest of the original file. */
2339 fprintf (src_file
, "%s\n", cur_arg
);
2341 /* Find next argument. */
2347 end
= strchr (arg
, ',');
2351 cur_arg
= percent_deescape (arg
);
2364 fprintf (src_file
, "%s %s\n", marker
, asctimestamp (gnupg_get_time ()));
2365 if (ferror (src_file
))
2366 goto change_file_one_err
;
2370 fprintf (src_file
, "# GPGConf edited this configuration file.\n");
2371 if (ferror (src_file
))
2372 goto change_file_one_err
;
2373 fprintf (src_file
, "# It will disable options before this marked "
2374 "block, but it will\n");
2375 if (ferror (src_file
))
2376 goto change_file_one_err
;
2377 fprintf (src_file
, "# never change anything below these lines.\n");
2378 if (ferror (src_file
))
2379 goto change_file_one_err
;
2383 while ((length
= read_line (dest_file
, &line
, &line_len
, NULL
)) > 0)
2385 fprintf (src_file
, "%s", line
);
2386 if (ferror (src_file
))
2387 goto change_file_one_err
;
2389 if (length
< 0 || ferror (dest_file
))
2390 goto change_file_one_err
;
2395 res
= fclose (src_file
);
2408 res
= fclose (dest_file
);
2414 change_file_one_err
:
2429 /* Create and verify the new configuration file for the specified
2430 backend and component. Returns 0 on success and -1 on error. */
2432 change_options_program (gc_component_t component
, gc_backend_t backend
,
2433 char **src_filenamep
, char **dest_filenamep
,
2434 char **orig_filenamep
)
2436 static const char marker
[] = "###+++--- GPGConf ---+++###";
2437 /* True if we are within the marker in the config file. */
2439 gc_option_t
*option
;
2445 FILE *src_file
= NULL
;
2446 FILE *dest_file
= NULL
;
2448 char *dest_filename
;
2449 char *orig_filename
;
2451 /* FIXME. Throughout the function, do better error reporting. */
2452 dest_filename
= xstrdup (get_config_pathname (component
, backend
));
2453 src_filename
= xasprintf ("%s.gpgconf.%i.new", dest_filename
, getpid ());
2454 orig_filename
= xasprintf ("%s.gpgconf.%i.bak", dest_filename
, getpid ());
2456 #ifdef HAVE_W32_SYSTEM
2457 res
= copy_file (dest_filename
, orig_filename
);
2459 res
= link (dest_filename
, orig_filename
);
2461 if (res
< 0 && errno
!= ENOENT
)
2465 xfree (orig_filename
);
2466 orig_filename
= NULL
;
2469 /* We now initialize the return strings, so the caller can do the
2471 *src_filenamep
= src_filename
;
2472 *dest_filenamep
= dest_filename
;
2473 *orig_filenamep
= orig_filename
;
2475 /* Use open() so that we can use O_EXCL. */
2476 fd
= open (src_filename
, O_CREAT
| O_EXCL
| O_WRONLY
, 0644);
2479 src_file
= fdopen (fd
, "w");
2487 /* Only if ORIG_FILENAME is not NULL did the configuration file
2488 exist already. In this case, we will copy its content into the
2489 new configuration file, changing it to our liking in the
2493 dest_file
= fopen (dest_filename
, "r");
2495 goto change_one_err
;
2497 while ((length
= read_line (dest_file
, &line
, &line_len
, NULL
)) > 0)
2502 if (!strncmp (marker
, line
, sizeof (marker
) - 1))
2511 while (*start
== ' ' || *start
== '\t')
2513 if (*start
&& *start
!= '\r' && *start
!= '\n' && *start
!= '#')
2519 while (*end
&& *end
!= ' ' && *end
!= '\t'
2520 && *end
!= '\r' && *end
!= '\n' && *end
!= '#')
2525 option
= find_option (component
, start
, backend
);
2527 if (option
&& ((option
->new_flags
& GC_OPT_FLAG_DEFAULT
)
2528 || option
->new_value
))
2536 "# GPGConf disabled this option here at %s\n",
2537 asctimestamp (gnupg_get_time ()));
2538 if (ferror (src_file
))
2539 goto change_one_err
;
2540 fprintf (src_file
, "# %s", line
);
2541 if (ferror (src_file
))
2542 goto change_one_err
;
2547 fprintf (src_file
, "%s", line
);
2548 if (ferror (src_file
))
2549 goto change_one_err
;
2552 if (length
< 0 || ferror (dest_file
))
2553 goto change_one_err
;
2558 /* There was no marker. This is the first time we edit the
2559 file. We add our own marker at the end of the file and
2560 proceed. Note that we first write a newline, this guards us
2561 against files which lack the newline at the end of the last
2562 line, while it doesn't hurt us in all other cases. */
2563 fprintf (src_file
, "\n%s\n", marker
);
2564 if (ferror (src_file
))
2565 goto change_one_err
;
2567 /* At this point, we have copied everything up to the end marker
2568 into the new file, except for the options we are going to change.
2569 Now, dump the changed options (except for those we are going to
2570 revert to their default), and write the end marker, possibly
2571 followed by the rest of the original file. */
2573 /* We have to turn on UTF8 strings for GnuPG. */
2574 if (backend
== GC_BACKEND_GPG
)
2575 fprintf (src_file
, "utf8-strings\n");
2577 option
= gc_component
[component
].options
;
2578 while (option
->name
)
2580 if (!(option
->flags
& GC_OPT_FLAG_GROUP
)
2581 && option
->backend
== backend
2582 && option
->new_value
)
2584 char *arg
= option
->new_value
;
2588 if (*arg
== '\0' || *arg
== ',')
2590 fprintf (src_file
, "%s\n", option
->name
);
2591 if (ferror (src_file
))
2592 goto change_one_err
;
2594 else if (gc_arg_type
[option
->arg_type
].fallback
2595 == GC_ARG_TYPE_NONE
)
2597 assert (*arg
== '1');
2598 fprintf (src_file
, "%s\n", option
->name
);
2599 if (ferror (src_file
))
2600 goto change_one_err
;
2604 else if (gc_arg_type
[option
->arg_type
].fallback
2605 == GC_ARG_TYPE_STRING
)
2609 assert (*arg
== '"');
2612 end
= strchr (arg
, ',');
2616 fprintf (src_file
, "%s %s\n", option
->name
,
2617 percent_deescape (arg
));
2618 if (ferror (src_file
))
2619 goto change_one_err
;
2629 end
= strchr (arg
, ',');
2633 fprintf (src_file
, "%s %s\n", option
->name
, arg
);
2634 if (ferror (src_file
))
2635 goto change_one_err
;
2642 assert (arg
== NULL
|| *arg
== '\0' || *arg
== ',');
2643 if (arg
&& *arg
== ',')
2646 while (arg
&& *arg
);
2651 fprintf (src_file
, "%s %s\n", marker
, asctimestamp (gnupg_get_time ()));
2652 if (ferror (src_file
))
2653 goto change_one_err
;
2657 fprintf (src_file
, "# GPGConf edited this configuration file.\n");
2658 if (ferror (src_file
))
2659 goto change_one_err
;
2660 fprintf (src_file
, "# It will disable options before this marked "
2661 "block, but it will\n");
2662 if (ferror (src_file
))
2663 goto change_one_err
;
2664 fprintf (src_file
, "# never change anything below these lines.\n");
2665 if (ferror (src_file
))
2666 goto change_one_err
;
2670 while ((length
= read_line (dest_file
, &line
, &line_len
, NULL
)) > 0)
2672 fprintf (src_file
, "%s", line
);
2673 if (ferror (src_file
))
2674 goto change_one_err
;
2676 if (length
< 0 || ferror (dest_file
))
2677 goto change_one_err
;
2682 res
= fclose (src_file
);
2695 res
= fclose (dest_file
);
2716 /* Common code for gc_component_change_options and
2717 gc_process_gpgconf_conf. */
2719 change_one_value (gc_option_t
*option
, int *runtime
,
2720 unsigned long flags
, char *new_value
)
2722 unsigned long new_value_nr
= 0;
2724 option_check_validity (option
, flags
, new_value
, &new_value_nr
);
2726 if (option
->flags
& GC_OPT_FLAG_RUNTIME
)
2727 runtime
[option
->backend
] = 1;
2729 option
->new_flags
= flags
;
2730 if (!(flags
& GC_OPT_FLAG_DEFAULT
))
2732 if (gc_arg_type
[option
->arg_type
].fallback
== GC_ARG_TYPE_NONE
2733 && (option
->flags
& GC_OPT_FLAG_LIST
))
2737 /* We convert the number to a list of 1's for convenient
2739 assert (new_value_nr
> 0);
2740 option
->new_value
= xmalloc ((2 * (new_value_nr
- 1) + 1) + 1);
2741 str
= option
->new_value
;
2743 while (--new_value_nr
> 0)
2751 option
->new_value
= xstrdup (new_value
);
2756 /* Read the modifications from IN and apply them. If IN is NULL the
2757 modifications are expected to already have been set to the global
2760 gc_component_change_options (int component
, FILE *in
)
2763 int runtime
[GC_BACKEND_NR
];
2764 char *src_pathname
[GC_BACKEND_NR
];
2765 char *dest_pathname
[GC_BACKEND_NR
];
2766 char *orig_pathname
[GC_BACKEND_NR
];
2767 gc_backend_t backend
;
2768 gc_option_t
*option
;
2770 size_t line_len
= 0;
2773 for (backend
= 0; backend
< GC_BACKEND_NR
; backend
++)
2775 runtime
[backend
] = 0;
2776 src_pathname
[backend
] = NULL
;
2777 dest_pathname
[backend
] = NULL
;
2778 orig_pathname
[backend
] = NULL
;
2783 /* Read options from the file IN. */
2784 while ((length
= read_line (in
, &line
, &line_len
, NULL
)) > 0)
2787 unsigned long flags
= 0;
2788 char *new_value
= "";
2790 /* Strip newline and carriage return, if present. */
2792 && (line
[length
- 1] == '\n' || line
[length
- 1] == '\r'))
2793 line
[--length
] = '\0';
2795 linep
= strchr (line
, ':');
2799 /* Extract additional flags. Default to none. */
2805 end
= strchr (linep
, ':');
2810 flags
= strtoul (linep
, &tail
, 0);
2812 gc_error (1, errno
, "malformed flags in option %s", line
);
2813 if (!(*tail
== '\0' || *tail
== ':' || *tail
== ' '))
2814 gc_error (1, 0, "garbage after flags in option %s", line
);
2819 /* Don't allow setting of the no change flag. */
2820 flags
&= ~GC_OPT_FLAG_NO_CHANGE
;
2822 /* Extract default value, if present. Default to empty if not. */
2826 end
= strchr (linep
, ':');
2833 option
= find_option (component
, line
, GC_BACKEND_ANY
);
2835 gc_error (1, 0, "unknown option %s", line
);
2837 if ((option
->flags
& GC_OPT_FLAG_NO_CHANGE
))
2839 gc_error (0, 0, "ignoring new value for option %s",
2844 change_one_value (option
, runtime
, flags
, new_value
);
2848 /* Now that we have collected and locally verified the changes,
2849 write them out to new configuration files, verify them
2850 externally, and then commit them. */
2851 option
= gc_component
[component
].options
;
2852 while (option
&& option
->name
)
2854 /* Go on if we have already seen this backend, or if there is
2856 if (src_pathname
[option
->backend
]
2857 || !(option
->new_flags
|| option
->new_value
))
2863 if (gc_backend
[option
->backend
].program
)
2864 err
= change_options_program (component
, option
->backend
,
2865 &src_pathname
[option
->backend
],
2866 &dest_pathname
[option
->backend
],
2867 &orig_pathname
[option
->backend
]);
2869 err
= change_options_file (component
, option
->backend
,
2870 &src_pathname
[option
->backend
],
2871 &dest_pathname
[option
->backend
],
2872 &orig_pathname
[option
->backend
]);
2884 for (i
= 0; i
< GC_BACKEND_NR
; i
++)
2886 if (src_pathname
[i
])
2888 /* FIXME: Make a verification here. */
2890 assert (dest_pathname
[i
]);
2892 if (orig_pathname
[i
])
2894 #ifdef HAVE_W32_SYSTEM
2895 /* There is no atomic update on W32. */
2896 err
= unlink (dest_pathname
[i
]);
2897 #endif /* HAVE_W32_SYSTEM */
2899 err
= rename (src_pathname
[i
], dest_pathname
[i
]);
2903 #ifdef HAVE_W32_SYSTEM
2904 /* We skip the unlink if we expect the file not to
2906 err
= rename (src_pathname
[i
], dest_pathname
[i
]);
2907 #else /* HAVE_W32_SYSTEM */
2908 /* This is a bit safer than rename() because we
2909 expect DEST_PATHNAME not to be there. If it
2910 happens to be there, this will fail. */
2911 err
= link (src_pathname
[i
], dest_pathname
[i
]);
2913 err
= unlink (src_pathname
[i
]);
2914 #endif /* !HAVE_W32_SYSTEM */
2918 src_pathname
[i
] = NULL
;
2926 int saved_errno
= errno
;
2928 /* An error occured. */
2929 for (i
= 0; i
< GC_BACKEND_NR
; i
++)
2931 if (src_pathname
[i
])
2933 /* The change was not yet committed. */
2934 unlink (src_pathname
[i
]);
2935 if (orig_pathname
[i
])
2936 unlink (orig_pathname
[i
]);
2940 /* The changes were already committed. FIXME: This is a
2941 tad dangerous, as we don't know if we don't overwrite
2942 a version of the file that is even newer than the one
2943 we just installed. */
2944 if (orig_pathname
[i
])
2946 #ifdef HAVE_W32_SYSTEM
2947 /* There is no atomic update on W32. */
2948 unlink (dest_pathname
[i
]);
2949 #endif /* HAVE_W32_SYSTEM */
2950 rename (orig_pathname
[i
], dest_pathname
[i
]);
2953 unlink (dest_pathname
[i
]);
2956 gc_error (1, saved_errno
, "could not commit changes");
2959 /* If it all worked, notify the daemons of the changes. */
2961 for (backend
= 0; backend
< GC_BACKEND_NR
; backend
++)
2963 if (runtime
[backend
] && gc_backend
[backend
].runtime_change
)
2964 (*gc_backend
[backend
].runtime_change
) ();
2967 /* Move the per-process backup file into its place. */
2968 for (backend
= 0; backend
< GC_BACKEND_NR
; backend
++)
2969 if (orig_pathname
[backend
])
2971 char *backup_pathname
;
2973 assert (dest_pathname
[backend
]);
2975 backup_pathname
= xasprintf ("%s.gpgconf.bak", dest_pathname
[backend
]);
2977 #ifdef HAVE_W32_SYSTEM
2978 /* There is no atomic update on W32. */
2979 unlink (backup_pathname
);
2980 #endif /* HAVE_W32_SYSTEM */
2981 rename (orig_pathname
[backend
], backup_pathname
);
2988 /* Check whether USER matches the current user of one of its group.
2989 This function may change USER. Returns true is there is a
2992 key_matches_user_or_group (char *user
)
2996 if (*user
== '*' && user
[1] == 0)
2997 return 1; /* A single asterisk matches all users. */
2999 group
= strchr (user
, ':');
3003 #ifdef HAVE_W32_SYSTEM
3004 /* Under Windows we don't support groups. */
3005 if (group
&& *group
)
3006 gc_error (0, 0, _("Note that group specifications are ignored\n"));
3009 static char *my_name
;
3016 GetUserNameA (tmp
, &size
);
3017 my_name
= xmalloc (size
);
3018 if (!GetUserNameA (my_name
, &size
))
3019 gc_error (1,0, "error getting current user name: %s",
3023 if (!strcmp (user
, my_name
))
3024 return 1; /* Found. */
3026 #else /*!HAVE_W32_SYSTEM*/
3027 /* First check whether the user matches. */
3030 static char *my_name
;
3034 struct passwd
*pw
= getpwuid ( getuid () );
3036 gc_error (1, errno
, "getpwuid failed for current user");
3037 my_name
= xstrdup (pw
->pw_name
);
3039 if (!strcmp (user
, my_name
))
3040 return 1; /* Found. */
3043 /* If that failed, check whether a group matches. */
3044 if (group
&& *group
)
3046 static char *my_group
;
3047 static char **my_supgroups
;
3052 struct group
*gr
= getgrgid ( getgid () );
3054 gc_error (1, errno
, "getgrgid failed for current user");
3055 my_group
= xstrdup (gr
->gr_name
);
3057 if (!strcmp (group
, my_group
))
3058 return 1; /* Found. */
3065 ngids
= getgroups (0, NULL
);
3066 gids
= xcalloc (ngids
+1, sizeof *gids
);
3067 ngids
= getgroups (ngids
, gids
);
3069 gc_error (1, errno
, "getgroups failed for current user");
3070 my_supgroups
= xcalloc (ngids
+1, sizeof *my_supgroups
);
3071 for (n
=0; n
< ngids
; n
++)
3073 struct group
*gr
= getgrgid ( gids
[n
] );
3075 gc_error (1, errno
, "getgrgid failed for supplementary group");
3076 my_supgroups
[n
] = xstrdup (gr
->gr_name
);
3081 for (n
=0; my_supgroups
[n
]; n
++)
3082 if (!strcmp (group
, my_supgroups
[n
]))
3083 return 1; /* Found. */
3085 #endif /*!HAVE_W32_SYSTEM*/
3086 return 0; /* No match. */
3091 /* Read and process the global configuration file for gpgconf. This
3092 optional file is used to update our internal tables at runtime and
3093 may also be used to set new default values. If FNAME is NULL the
3094 default name will be used. With UPDATE set to true the internal
3095 tables are actually updated; if not set, only a syntax check is
3096 done. If DEFAULTS is true the global options are written to the
3097 configuration files. If LISTFP is set, no changes are done but the
3098 configuration file is printed to LISTFP in a colon separated format.
3100 Returns 0 on success or if the config file is not present; -1 is
3101 returned on error. */
3103 gc_process_gpgconf_conf (const char *fname_arg
, int update
, int defaults
,
3108 size_t line_len
= 0;
3114 int runtime
[GC_BACKEND_NR
];
3115 int used_components
[GC_COMPONENT_NR
];
3116 int backend_id
, component_id
;
3120 fname
= xstrdup (fname_arg
);
3122 fname
= make_filename (gnupg_sysconfdir (), "gpgconf.conf", NULL
);
3124 for (backend_id
= 0; backend_id
< GC_BACKEND_NR
; backend_id
++)
3125 runtime
[backend_id
] = 0;
3126 for (component_id
= 0; component_id
< GC_COMPONENT_NR
; component_id
++)
3127 used_components
[component_id
] = 0;
3129 config
= fopen (fname
, "r");
3132 /* Do not print an error if the file is not available, except
3133 when running in syntax check mode. */
3134 if (errno
!= ENOENT
|| !update
)
3136 gc_error (0, errno
, "can not open global config file `%s'", fname
);
3143 while ((length
= read_line (config
, &line
, &line_len
, NULL
)) > 0)
3145 char *key
, *component
, *option
, *flags
, *value
;
3147 gc_option_t
*option_info
= NULL
;
3149 int is_continuation
;
3153 while (*key
== ' ' || *key
== '\t')
3155 if (!*key
|| *key
== '#' || *key
== '\r' || *key
== '\n')
3158 is_continuation
= (key
!= line
);
3160 /* Parse the key field. */
3161 if (!is_continuation
&& got_match
)
3162 break; /* Finish after the first match. */
3163 else if (!is_continuation
)
3166 for (p
=key
+1; *p
&& !strchr (" \t\r\n", *p
); p
++)
3170 gc_error (0, 0, "missing rule at `%s', line %d", fname
, lineno
);
3179 gc_error (0, 0, "continuation but no rule at `%s', line %d",
3192 /* Parse the component. */
3193 while (*component
== ' ' || *component
== '\t')
3195 for (p
=component
; *p
&& !strchr (" \t\r\n", *p
); p
++)
3199 gc_error (0, 0, "missing component at `%s', line %d",
3207 component_id
= gc_component_find (component
);
3208 if (component_id
< 0)
3210 gc_error (0, 0, "unknown component at `%s', line %d",
3215 /* Parse the option name. */
3216 while (*option
== ' ' || *option
== '\t')
3218 for (p
=option
; *p
&& !strchr (" \t\r\n", *p
); p
++)
3222 gc_error (0, 0, "missing option at `%s', line %d",
3229 if ( component_id
!= -1)
3231 option_info
= find_option (component_id
, option
, GC_BACKEND_ANY
);
3234 gc_error (0, 0, "unknown option at `%s', line %d",
3241 /* Parse the optional flags. */
3242 while (*flags
== ' ' || *flags
== '\t')
3247 p
= strchr (flags
, ']');
3250 gc_error (0, 0, "syntax error in rule at `%s', line %d",
3258 else /* No flags given. */
3264 /* Parse the optional value. */
3265 while (*value
== ' ' || *value
== '\t')
3267 for (p
=value
; *p
&& !strchr ("\r\n", *p
); p
++)
3270 value
= empty
; /* No value given; let it point to an empty string. */
3273 /* Strip trailing white space. */
3275 for (p
--; p
> value
&& (*p
== ' ' || *p
== '\t'); p
--)
3279 /* Check flag combinations. */
3282 else if (!strcmp (flags
, "default"))
3286 gc_error (0, 0, "flag \"default\" may not be combined "
3287 "with a value at `%s', line %d",
3292 else if (!strcmp (flags
, "change"))
3294 else if (!strcmp (flags
, "no-change"))
3298 gc_error (0, 0, "unknown flag at `%s', line %d",
3303 /* In list mode we print out all records. */
3304 if (listfp
&& !result
)
3306 /* If this is a new ruleset, print a key record. */
3307 if (!is_continuation
)
3309 char *group
= strchr (key
, ':');
3313 if ((p
= strchr (group
, ':')))
3314 *p
= 0; /* We better strip any extra stuff. */
3317 fprintf (listfp
, "k:%s:", my_percent_escape (key
));
3318 fprintf (listfp
, "%s\n", group
? my_percent_escape (group
):"");
3321 /* All other lines are rule records. */
3322 fprintf (listfp
, "r:::%s:%s:%s:",
3323 gc_component
[component_id
].name
,
3324 option_info
->name
? option_info
->name
: "",
3327 fprintf (listfp
, "\"%s", my_percent_escape (value
));
3329 putc ('\n', listfp
);
3332 /* Check whether the key matches but do this only if we are not
3333 running in syntax check mode. */
3335 && !result
&& !listfp
3336 && (got_match
|| (key
&& key_matches_user_or_group (key
))) )
3342 /* Apply the flags from gpgconf.conf. */
3345 else if (!strcmp (flags
, "default"))
3346 newflags
|= GC_OPT_FLAG_DEFAULT
;
3347 else if (!strcmp (flags
, "no-change"))
3348 option_info
->flags
|= GC_OPT_FLAG_NO_CHANGE
;
3349 else if (!strcmp (flags
, "change"))
3350 option_info
->flags
&= ~GC_OPT_FLAG_NO_CHANGE
;
3354 assert (component_id
>= 0 && component_id
< GC_COMPONENT_NR
);
3355 used_components
[component_id
] = 1;
3357 /* Here we explicitly allow to update the value again. */
3360 option_info
->new_flags
= 0;
3364 xfree (option_info
->new_value
);
3365 option_info
->new_value
= NULL
;
3367 change_one_value (option_info
, runtime
, newflags
, value
);
3372 if (length
< 0 || ferror (config
))
3374 gc_error (0, errno
, "error reading from `%s'", fname
);
3377 if (fclose (config
) && ferror (config
))
3378 gc_error (0, errno
, "error closing `%s'", fname
);
3382 /* If it all worked, process the options. */
3383 if (!result
&& update
&& defaults
&& !listfp
)
3385 /* We need to switch off the runtime update, so that we can do
3386 it later all at once. */
3387 int save_opt_runtime
= opt
.runtime
;
3390 for (component_id
= 0; component_id
< GC_COMPONENT_NR
; component_id
++)
3392 gc_component_change_options (component_id
, NULL
);
3394 opt
.runtime
= save_opt_runtime
;
3398 for (backend_id
= 0; backend_id
< GC_BACKEND_NR
; backend_id
++)
3399 if (runtime
[backend_id
] && gc_backend
[backend_id
].runtime_change
)
3400 (*gc_backend
[backend_id
].runtime_change
) ();