1 /* comopt.c - Common options for GnUPG (common.conf)
2 * Copyright (C) 2021 g10 Code GmbH
4 * This file is part of GnuPG.
6 * This file is free software; you can redistribute it and/or modify
7 * it under the terms of either
9 * - the GNU Lesser General Public License as published by the Free
10 * Software Foundation; either version 3 of the License, or (at
11 * your option) any later version.
15 * - the GNU General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at
17 * your option) any later version.
19 * or both in parallel, as here.
21 * This file is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, see <https://www.gnu.org/licenses/>.
28 * SPDX-License-Identifier: (LGPL-3.0-or-later OR GPL-2.0-or-later)
52 static gpgrt_opt_t opts[] = {
53 ARGPARSE_s_s (oLogFile, "log-file", "@"),
54 ARGPARSE_s_n (oUseKeyboxd, "use-keyboxd", "@"),
55 ARGPARSE_s_s (oKeyboxdProgram, "keyboxd-program", "@"),
62 /* Parse the common options in the homedir and etc. This needs to be
63 * called after the gpgrt config directories are. MODULE_ID is one of
64 * the GNUPG_MODULE_NAME_ constants. If verbose is true info about
65 * the parsing is printed. Note that this function is not
68 parse_comopt (int module_id, int verbose)
71 gpgrt_argparse_t pargs;
75 /* Reset all options in case we are called a second time. */
76 xfree (comopt.logfile);
77 xfree (comopt.keyboxd_program);
78 memset (&comopt, 0, sizeof comopt);
80 /* Start the parser. */
83 pargs.flags = (ARGPARSE_FLAG_NOVERSION
87 while (gpgrt_argparser (&pargs, opts, "common" EXTSEP_S "conf" ))
91 case ARGPARSE_CONFFILE:
93 log_info (_("reading options from '%s'\n"),
94 pargs.r_type? pargs.r.ret_str: "[cmdline]");
98 comopt.logfile = pargs.r.ret_str;
102 comopt.use_keyboxd = 1;
105 case oKeyboxdProgram:
106 comopt.keyboxd_program = pargs.r.ret_str;
110 pargs.err = ARGPARSE_PRINT_WARNING;
111 err = gpg_error (GPG_ERR_GENERAL);
116 gpgrt_argparse (NULL, &pargs, NULL); /* Release internal state. */
118 if (comopt.logfile && !(!strncmp (comopt.logfile, "socket:", 7)
119 || !strncmp (comopt.logfile, "tcp:", 4)) )
121 /* Letting all modules write to the same log file is not a good
122 * idea. Append the module name. */
125 p = xstrconcat (comopt.logfile, "-", gnupg_module_name (module_id), NULL);
126 xfree (comopt.logfile);