2003-08-05 17:11:04 +00:00
|
|
|
|
/* scdaemon.c - The GnuPG Smartcard Daemon
|
2014-11-04 16:28:03 +01:00
|
|
|
|
* Copyright (C) 2001-2002, 2004-2005, 2007-2009 Free Software Foundation, Inc.
|
|
|
|
|
* Copyright (C) 2001-2002, 2004-2005, 2007-2014 Werner Koch
|
2003-08-05 17:11:04 +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
|
2003-08-05 17:11:04 +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
|
2016-11-05 12:02:19 +01:00
|
|
|
|
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
2003-08-05 17:11:04 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <fcntl.h>
|
2017-07-25 12:19:08 +02:00
|
|
|
|
#ifndef HAVE_W32_SYSTEM
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <sys/un.h>
|
2004-12-15 14:15:54 +00:00
|
|
|
|
#endif /*HAVE_W32_SYSTEM*/
|
2003-08-05 17:11:04 +00:00
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <signal.h>
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
#include <npth.h>
|
2003-08-05 17:11:04 +00:00
|
|
|
|
|
2015-04-24 16:10:15 +02:00
|
|
|
|
#define GNUPG_COMMON_NEED_AFLOCAL
|
2003-08-05 17:11:04 +00:00
|
|
|
|
#include "scdaemon.h"
|
|
|
|
|
#include <ksba.h>
|
|
|
|
|
#include <gcrypt.h>
|
|
|
|
|
|
|
|
|
|
#include <assuan.h> /* malloc hooks */
|
|
|
|
|
|
2017-03-07 20:21:23 +09:00
|
|
|
|
#include "../common/i18n.h"
|
|
|
|
|
#include "../common/sysutils.h"
|
2003-08-05 17:11:04 +00:00
|
|
|
|
#include "app-common.h"
|
SCD: API cleanup for keypad handling.
* scd/iso7816.h (struct pininfo_s): Rename from iso7816_pininfo_s.
Change meaning of MODE.
(pininfo_t): Rename from iso7816_pininfo_t.
* scd/sc-copykeys.c: Include "iso7816.h".
* scd/scdaemon.c, scd/command.c: Likewise.
* scd/ccid-driver.c: Include "scdaemon.h" and "iso7816.h".
(ccid_transceive_secure): Follow the change of PININFO_T.
* scd/app.c: Include "apdu.h" after "iso7816.h".
* scd/iso7816.c (iso7816_check_keypad, iso7816_verify_kp)
(iso7816_change_reference_data_kp): Follow the change of API.
* scd/apdu.c (struct reader_table_s): Change API of CHECK_KEYPAD,
KEYPAD_VERIFY, KEYPAD_MODIFY to have arg of PININFO_T.
(check_pcsc_keypad, check_ccid_keypad): Likewise.
(apdu_check_keypad, apdu_keypad_verify, apdu_keypad_modify): Likewise.
(pcsc_keypad_verify, pcsc_keypad_modify, ct_send_apdu)
(pcsc_send_apdu_direct, pcsc_send_apdu_wrapped, pcsc_send_apdu)
(send_apdu_ccid, ccid_keypad_operation, my_rapdu_send_apdu, send_apdu)
(send_le): Follow the change of API.
* scd/apdu.h (apdu_check_keypad, apdu_keypad_verify)
(apdu_keypad_modify): Change the API.
* scd/app-dinsig.c, scd/app-nks.c, scd/app-openpgp.c: Follow the
change.
2013-01-09 14:10:08 +09:00
|
|
|
|
#include "iso7816.h"
|
2009-07-16 15:54:59 +00:00
|
|
|
|
#include "apdu.h"
|
2005-05-20 20:39:36 +00:00
|
|
|
|
#include "ccid-driver.h"
|
2017-03-07 20:21:23 +09:00
|
|
|
|
#include "../common/gc-opt-flags.h"
|
|
|
|
|
#include "../common/asshelp.h"
|
|
|
|
|
#include "../common/exechelp.h"
|
2012-02-06 20:50:47 +01:00
|
|
|
|
#include "../common/init.h"
|
|
|
|
|
|
2014-12-01 10:45:06 +01:00
|
|
|
|
#ifndef ENAMETOOLONG
|
|
|
|
|
# define ENAMETOOLONG EINVAL
|
|
|
|
|
#endif
|
2007-08-02 18:12:43 +00:00
|
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
|
enum cmd_and_opt_values
|
2003-08-05 17:11:04 +00:00
|
|
|
|
{ aNull = 0,
|
2017-01-31 12:56:11 +09:00
|
|
|
|
oCsh = 'c',
|
|
|
|
|
oQuiet = 'q',
|
|
|
|
|
oSh = 's',
|
|
|
|
|
oVerbose = 'v',
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2003-08-05 17:11:04 +00:00
|
|
|
|
oNoVerbose = 500,
|
2004-02-18 17:00:11 +00:00
|
|
|
|
aGPGConfList,
|
2006-10-23 14:02:13 +00:00
|
|
|
|
aGPGConfTest,
|
2003-08-05 17:11:04 +00:00
|
|
|
|
oOptions,
|
|
|
|
|
oDebug,
|
|
|
|
|
oDebugAll,
|
2004-02-18 17:00:11 +00:00
|
|
|
|
oDebugLevel,
|
2003-08-05 17:11:04 +00:00
|
|
|
|
oDebugWait,
|
2005-06-07 19:09:18 +00:00
|
|
|
|
oDebugAllowCoreDump,
|
2005-05-20 20:39:36 +00:00
|
|
|
|
oDebugCCIDDriver,
|
2009-02-25 10:58:56 +00:00
|
|
|
|
oDebugLogTid,
|
2011-12-13 17:59:00 +01:00
|
|
|
|
oDebugAssuanLogCats,
|
2003-08-05 17:11:04 +00:00
|
|
|
|
oNoGreeting,
|
|
|
|
|
oNoOptions,
|
|
|
|
|
oHomedir,
|
|
|
|
|
oNoDetach,
|
|
|
|
|
oNoGrab,
|
|
|
|
|
oLogFile,
|
|
|
|
|
oServer,
|
2005-05-18 10:48:06 +00:00
|
|
|
|
oMultiServer,
|
2003-08-05 17:11:04 +00:00
|
|
|
|
oDaemon,
|
|
|
|
|
oBatch,
|
|
|
|
|
oReaderPort,
|
2008-12-05 12:01:01 +00:00
|
|
|
|
oCardTimeout,
|
2003-08-05 17:11:04 +00:00
|
|
|
|
octapiDriver,
|
2003-08-19 09:36:48 +00:00
|
|
|
|
opcscDriver,
|
2003-09-02 19:06:34 +00:00
|
|
|
|
oDisableCCID,
|
2003-08-18 17:34:28 +00:00
|
|
|
|
oDisableOpenSC,
|
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
|
|
|
|
oDisablePinpad,
|
2003-12-01 10:54:09 +00:00
|
|
|
|
oAllowAdmin,
|
|
|
|
|
oDenyAdmin,
|
2004-08-05 09:24:36 +00:00
|
|
|
|
oDisableApplication,
|
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
|
|
|
|
oEnablePinpadVarlen,
|
2017-12-12 14:14:40 +01:00
|
|
|
|
oListenBacklog
|
2005-05-20 20:39:36 +00:00
|
|
|
|
};
|
2003-08-05 17:11:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static ARGPARSE_OPTS opts[] = {
|
2008-12-05 12:01:01 +00:00
|
|
|
|
ARGPARSE_c (aGPGConfList, "gpgconf-list", "@"),
|
|
|
|
|
ARGPARSE_c (aGPGConfTest, "gpgconf-test", "@"),
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2008-12-05 12:01:01 +00:00
|
|
|
|
ARGPARSE_group (301, N_("@Options:\n ")),
|
|
|
|
|
|
|
|
|
|
ARGPARSE_s_n (oServer,"server", N_("run in server mode (foreground)")),
|
2011-02-04 12:57:53 +01:00
|
|
|
|
ARGPARSE_s_n (oMultiServer, "multi-server",
|
2008-12-05 12:01:01 +00:00
|
|
|
|
N_("run in multi server mode (foreground)")),
|
|
|
|
|
ARGPARSE_s_n (oDaemon, "daemon", N_("run in daemon mode (background)")),
|
|
|
|
|
ARGPARSE_s_n (oVerbose, "verbose", N_("verbose")),
|
2017-01-31 12:56:11 +09:00
|
|
|
|
ARGPARSE_s_n (oQuiet, "quiet", N_("be somewhat more quiet")),
|
|
|
|
|
ARGPARSE_s_n (oSh, "sh", N_("sh-style command output")),
|
|
|
|
|
ARGPARSE_s_n (oCsh, "csh", N_("csh-style command output")),
|
2008-12-05 12:01:01 +00:00
|
|
|
|
ARGPARSE_s_s (oOptions, "options", N_("|FILE|read options from FILE")),
|
2017-01-31 12:56:11 +09:00
|
|
|
|
ARGPARSE_s_s (oDebug, "debug", "@"),
|
2008-12-05 12:01:01 +00:00
|
|
|
|
ARGPARSE_s_n (oDebugAll, "debug-all", "@"),
|
|
|
|
|
ARGPARSE_s_s (oDebugLevel, "debug-level" ,
|
|
|
|
|
N_("|LEVEL|set the debugging level to LEVEL")),
|
|
|
|
|
ARGPARSE_s_i (oDebugWait, "debug-wait", "@"),
|
|
|
|
|
ARGPARSE_s_n (oDebugAllowCoreDump, "debug-allow-core-dump", "@"),
|
|
|
|
|
ARGPARSE_s_n (oDebugCCIDDriver, "debug-ccid-driver", "@"),
|
2009-02-25 10:58:56 +00:00
|
|
|
|
ARGPARSE_s_n (oDebugLogTid, "debug-log-tid", "@"),
|
2011-12-13 17:59:00 +01:00
|
|
|
|
ARGPARSE_p_u (oDebugAssuanLogCats, "debug-assuan-log-cats", "@"),
|
2008-12-05 12:01:01 +00:00
|
|
|
|
ARGPARSE_s_n (oNoDetach, "no-detach", N_("do not detach from the console")),
|
|
|
|
|
ARGPARSE_s_s (oLogFile, "log-file", N_("|FILE|write a log to FILE")),
|
2011-02-04 12:57:53 +01:00
|
|
|
|
ARGPARSE_s_s (oReaderPort, "reader-port",
|
2008-12-05 12:01:01 +00:00
|
|
|
|
N_("|N|connect to reader at port N")),
|
2011-02-04 12:57:53 +01:00
|
|
|
|
ARGPARSE_s_s (octapiDriver, "ctapi-driver",
|
2008-12-05 12:01:01 +00:00
|
|
|
|
N_("|NAME|use NAME as ct-API driver")),
|
2011-02-04 12:57:53 +01:00
|
|
|
|
ARGPARSE_s_s (opcscDriver, "pcsc-driver",
|
2008-12-05 12:01:01 +00:00
|
|
|
|
N_("|NAME|use NAME as PC/SC driver")),
|
|
|
|
|
ARGPARSE_s_n (oDisableCCID, "disable-ccid",
|
2003-09-02 19:06:34 +00:00
|
|
|
|
#ifdef HAVE_LIBUSB
|
|
|
|
|
N_("do not use the internal CCID driver")
|
|
|
|
|
#else
|
|
|
|
|
"@"
|
|
|
|
|
#endif
|
2008-12-05 12:01:01 +00:00
|
|
|
|
/* end --disable-ccid */),
|
2011-02-04 12:57:53 +01:00
|
|
|
|
ARGPARSE_s_u (oCardTimeout, "card-timeout",
|
2008-12-05 12:01:01 +00:00
|
|
|
|
N_("|N|disconnect the card after N seconds of inactivity")),
|
2013-04-18 14:40:43 +02:00
|
|
|
|
|
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
|
|
|
|
ARGPARSE_s_n (oDisablePinpad, "disable-pinpad",
|
|
|
|
|
N_("do not use a reader's pinpad")),
|
2013-04-18 14:40:43 +02:00
|
|
|
|
ARGPARSE_ignore (300, "disable-keypad"),
|
|
|
|
|
|
2009-01-28 14:18:40 +00:00
|
|
|
|
ARGPARSE_s_n (oAllowAdmin, "allow-admin", "@"),
|
2011-02-04 12:57:53 +01:00
|
|
|
|
ARGPARSE_s_n (oDenyAdmin, "deny-admin",
|
2009-01-28 14:18:40 +00:00
|
|
|
|
N_("deny the use of admin card commands")),
|
2008-12-05 12:01:01 +00:00
|
|
|
|
ARGPARSE_s_s (oDisableApplication, "disable-application", "@"),
|
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
|
|
|
|
ARGPARSE_s_n (oEnablePinpadVarlen, "enable-pinpad-varlen",
|
|
|
|
|
N_("use variable length input for pinpad")),
|
2016-06-17 08:36:07 +02:00
|
|
|
|
ARGPARSE_s_s (oHomedir, "homedir", "@"),
|
2017-12-12 14:14:40 +01:00
|
|
|
|
ARGPARSE_s_i (oListenBacklog, "listen-backlog", "@"),
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2008-12-05 12:01:01 +00:00
|
|
|
|
ARGPARSE_end ()
|
2003-08-05 17:11:04 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2015-06-23 09:12:44 +02:00
|
|
|
|
/* The list of supported debug flags. */
|
|
|
|
|
static struct debug_flags_s debug_flags [] =
|
|
|
|
|
{
|
|
|
|
|
{ DBG_MPI_VALUE , "mpi" },
|
|
|
|
|
{ DBG_CRYPTO_VALUE , "crypto" },
|
|
|
|
|
{ DBG_MEMORY_VALUE , "memory" },
|
|
|
|
|
{ DBG_CACHE_VALUE , "cache" },
|
|
|
|
|
{ DBG_MEMSTAT_VALUE, "memstat" },
|
|
|
|
|
{ DBG_HASHING_VALUE, "hashing" },
|
|
|
|
|
{ DBG_IPC_VALUE , "ipc" },
|
|
|
|
|
{ DBG_CARD_IO_VALUE, "cardio" },
|
|
|
|
|
{ DBG_READER_VALUE , "reader" },
|
|
|
|
|
{ 0, NULL }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2007-02-18 13:48:03 +00:00
|
|
|
|
/* The card driver we use by default for PC/SC. */
|
2005-11-28 11:52:25 +00:00
|
|
|
|
#if defined(HAVE_W32_SYSTEM) || defined(__CYGWIN__)
|
2004-12-15 14:15:54 +00:00
|
|
|
|
#define DEFAULT_PCSC_DRIVER "winscard.dll"
|
2007-02-18 13:48:03 +00:00
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
|
#define DEFAULT_PCSC_DRIVER "/System/Library/Frameworks/PCSC.framework/PCSC"
|
2006-04-11 13:53:21 +00:00
|
|
|
|
#elif defined(__GLIBC__)
|
|
|
|
|
#define DEFAULT_PCSC_DRIVER "libpcsclite.so.1"
|
2004-12-15 14:15:54 +00:00
|
|
|
|
#else
|
2004-03-16 18:59:21 +00:00
|
|
|
|
#define DEFAULT_PCSC_DRIVER "libpcsclite.so"
|
2004-12-15 14:15:54 +00:00
|
|
|
|
#endif
|
2004-03-16 18:59:21 +00:00
|
|
|
|
|
2017-01-31 15:29:08 +09:00
|
|
|
|
/* The timer tick used to check card removal.
|
|
|
|
|
|
|
|
|
|
We poll every 500ms to let the user immediately know a status
|
|
|
|
|
change.
|
|
|
|
|
|
|
|
|
|
For a card reader with an interrupt endpoint, this timer is not
|
|
|
|
|
used with the internal CCID driver.
|
2008-10-14 18:18:21 +00:00
|
|
|
|
|
|
|
|
|
This is not too good for power saving but given that there is no
|
|
|
|
|
easy way to block on card status changes it is the best we can do.
|
|
|
|
|
For PC/SC we could in theory use an extra thread to wait for status
|
|
|
|
|
changes but that requires a native thread because there is no way
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
to make the underlying PC/SC card change function block using a Npth
|
2008-10-14 18:18:21 +00:00
|
|
|
|
mechanism. Given that a native thread could only be used under W32
|
|
|
|
|
we don't do that at all. */
|
|
|
|
|
#define TIMERTICK_INTERVAL_SEC (0)
|
2008-12-08 19:10:42 +00:00
|
|
|
|
#define TIMERTICK_INTERVAL_USEC (500000)
|
2004-03-16 18:59:21 +00:00
|
|
|
|
|
2004-04-20 14:17:10 +00:00
|
|
|
|
/* Flag to indicate that a shutdown was requested. */
|
|
|
|
|
static int shutdown_pending;
|
|
|
|
|
|
2003-08-05 17:11:04 +00:00
|
|
|
|
/* It is possible that we are currently running under setuid permissions */
|
|
|
|
|
static int maybe_setuid = 1;
|
|
|
|
|
|
2008-10-15 13:23:10 +00:00
|
|
|
|
/* Flag telling whether we are running as a pipe server. */
|
|
|
|
|
static int pipe_server;
|
|
|
|
|
|
2003-08-05 17:11:04 +00:00
|
|
|
|
/* Name of the communication socket */
|
2005-05-18 10:48:06 +00:00
|
|
|
|
static char *socket_name;
|
2014-12-01 10:45:06 +01:00
|
|
|
|
/* Name of the redirected socket or NULL. */
|
|
|
|
|
static char *redir_socket_name;
|
2005-05-18 10:48:06 +00:00
|
|
|
|
|
2007-10-01 14:48:39 +00:00
|
|
|
|
/* We need to keep track of the server's nonces (these are dummies for
|
|
|
|
|
POSIX systems). */
|
|
|
|
|
static assuan_sock_nonce_t socket_nonce;
|
2005-05-20 20:39:36 +00:00
|
|
|
|
|
2017-12-12 14:14:40 +01:00
|
|
|
|
/* Value for the listen() backlog argument. Change at runtime with
|
|
|
|
|
* --listen-backlog. */
|
|
|
|
|
static int listen_backlog = 64;
|
|
|
|
|
|
2017-03-03 20:30:56 +09:00
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
|
static HANDLE the_event;
|
|
|
|
|
#else
|
|
|
|
|
/* PID to notify update of usb devices. */
|
|
|
|
|
static pid_t main_thread_pid;
|
|
|
|
|
#endif
|
2018-02-07 12:43:07 +09:00
|
|
|
|
#ifdef HAVE_PSELECT_NO_EINTR
|
|
|
|
|
/* FD to notify changes. */
|
|
|
|
|
static int notify_fd;
|
|
|
|
|
#endif
|
2005-05-18 10:48:06 +00:00
|
|
|
|
|
2014-10-03 11:58:58 +02:00
|
|
|
|
static char *create_socket_name (char *standard_name);
|
|
|
|
|
static gnupg_fd_t create_server_socket (const char *name,
|
2014-12-01 10:45:06 +01:00
|
|
|
|
char **r_redir_name,
|
2007-10-01 14:48:39 +00:00
|
|
|
|
assuan_sock_nonce_t *nonce);
|
2003-08-05 17:11:04 +00:00
|
|
|
|
|
2005-05-18 10:48:06 +00:00
|
|
|
|
static void *start_connection_thread (void *arg);
|
2017-01-28 00:18:11 +09:00
|
|
|
|
static void handle_connections (int listen_fd);
|
2004-04-20 14:17:10 +00:00
|
|
|
|
|
|
|
|
|
/* Pth wrapper function definitions. */
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
ASSUAN_SYSTEM_NPTH_IMPL;
|
2009-10-16 18:35:03 +00:00
|
|
|
|
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
static int active_connections;
|
2004-04-20 14:17:10 +00:00
|
|
|
|
|
2005-05-18 10:48:06 +00:00
|
|
|
|
|
2008-11-18 18:01:03 +00:00
|
|
|
|
static char *
|
|
|
|
|
make_libversion (const char *libname, const char *(*getfnc)(const char*))
|
|
|
|
|
{
|
|
|
|
|
const char *s;
|
|
|
|
|
char *result;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2008-11-18 18:01:03 +00:00
|
|
|
|
if (maybe_setuid)
|
|
|
|
|
{
|
|
|
|
|
gcry_control (GCRYCTL_INIT_SECMEM, 0, 0); /* Drop setuid. */
|
|
|
|
|
maybe_setuid = 0;
|
|
|
|
|
}
|
|
|
|
|
s = getfnc (NULL);
|
|
|
|
|
result = xmalloc (strlen (libname) + 1 + strlen (s) + 1);
|
|
|
|
|
strcpy (stpcpy (stpcpy (result, libname), " "), s);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-05 17:11:04 +00:00
|
|
|
|
static const char *
|
|
|
|
|
my_strusage (int level)
|
|
|
|
|
{
|
2008-11-18 18:01:03 +00:00
|
|
|
|
static char *ver_gcry, *ver_ksba;
|
2003-08-05 17:11:04 +00:00
|
|
|
|
const char *p;
|
2008-11-18 18:01:03 +00:00
|
|
|
|
|
2003-08-05 17:11:04 +00:00
|
|
|
|
switch (level)
|
|
|
|
|
{
|
2013-11-18 14:09:47 +01:00
|
|
|
|
case 11: p = "@SCDAEMON@ (@GNUPG@)";
|
2003-08-05 17:11:04 +00:00
|
|
|
|
break;
|
|
|
|
|
case 13: p = VERSION; break;
|
|
|
|
|
case 17: p = PRINTABLE_OS_NAME; break;
|
2009-07-21 14:21:05 +00:00
|
|
|
|
case 19: p = _("Please report bugs to <@EMAIL@>.\n"); break;
|
|
|
|
|
|
2008-11-18 18:01:03 +00:00
|
|
|
|
case 20:
|
|
|
|
|
if (!ver_gcry)
|
|
|
|
|
ver_gcry = make_libversion ("libgcrypt", gcry_check_version);
|
|
|
|
|
p = ver_gcry;
|
|
|
|
|
break;
|
|
|
|
|
case 21:
|
|
|
|
|
if (!ver_ksba)
|
|
|
|
|
ver_ksba = make_libversion ("libksba", ksba_check_version);
|
|
|
|
|
p = ver_ksba;
|
|
|
|
|
break;
|
2003-08-05 17:11:04 +00:00
|
|
|
|
case 1:
|
2013-11-18 14:09:47 +01:00
|
|
|
|
case 40: p = _("Usage: @SCDAEMON@ [options] (-h for help)");
|
2003-08-05 17:11:04 +00:00
|
|
|
|
break;
|
|
|
|
|
case 41: p = _("Syntax: scdaemon [options] [command [args]]\n"
|
2013-11-18 14:09:47 +01:00
|
|
|
|
"Smartcard daemon for @GNUPG@\n");
|
2003-08-05 17:11:04 +00:00
|
|
|
|
break;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2003-08-05 17:11:04 +00:00
|
|
|
|
default: p = NULL;
|
|
|
|
|
}
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-06-09 16:53:51 +00:00
|
|
|
|
static int
|
|
|
|
|
tid_log_callback (unsigned long *rvalue)
|
2009-02-25 10:58:56 +00:00
|
|
|
|
{
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
int len = sizeof (*rvalue);
|
|
|
|
|
npth_t thread;
|
2009-02-25 10:58:56 +00:00
|
|
|
|
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
thread = npth_self ();
|
|
|
|
|
if (sizeof (thread) < len)
|
|
|
|
|
len = sizeof (thread);
|
|
|
|
|
memcpy (rvalue, &thread, len);
|
2003-08-05 17:11:04 +00:00
|
|
|
|
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
return 2; /* Use use hex representation. */
|
|
|
|
|
}
|
2003-08-05 17:11:04 +00:00
|
|
|
|
|
|
|
|
|
|
2004-02-18 17:00:11 +00:00
|
|
|
|
/* Setup the debugging. With a LEVEL of NULL only the active debug
|
|
|
|
|
flags are propagated to the subsystems. With LEVEL set, a specific
|
|
|
|
|
set of debug flags is set; thus overriding all flags already
|
|
|
|
|
set. */
|
|
|
|
|
static void
|
|
|
|
|
set_debug (const char *level)
|
|
|
|
|
{
|
2009-12-03 18:04:40 +00:00
|
|
|
|
int numok = (level && digitp (level));
|
|
|
|
|
int numlvl = numok? atoi (level) : 0;
|
|
|
|
|
|
2004-02-18 17:00:11 +00:00
|
|
|
|
if (!level)
|
|
|
|
|
;
|
2009-12-03 18:04:40 +00:00
|
|
|
|
else if (!strcmp (level, "none") || (numok && numlvl < 1))
|
2004-02-18 17:00:11 +00:00
|
|
|
|
opt.debug = 0;
|
2009-12-03 18:04:40 +00:00
|
|
|
|
else if (!strcmp (level, "basic") || (numok && numlvl <= 2))
|
2015-04-06 13:42:17 +02:00
|
|
|
|
opt.debug = DBG_IPC_VALUE;
|
2009-12-03 18:04:40 +00:00
|
|
|
|
else if (!strcmp (level, "advanced") || (numok && numlvl <= 5))
|
2016-12-19 09:41:15 +01:00
|
|
|
|
opt.debug = DBG_IPC_VALUE;
|
2009-12-03 18:04:40 +00:00
|
|
|
|
else if (!strcmp (level, "expert") || (numok && numlvl <= 8))
|
2016-12-19 09:41:15 +01:00
|
|
|
|
opt.debug = (DBG_IPC_VALUE|DBG_CACHE_VALUE|DBG_CARD_IO_VALUE);
|
2009-12-03 18:04:40 +00:00
|
|
|
|
else if (!strcmp (level, "guru") || numok)
|
|
|
|
|
{
|
|
|
|
|
opt.debug = ~0;
|
|
|
|
|
/* Unless the "guru" string has been used we don't want to allow
|
|
|
|
|
hashing debugging. The rationale is that people tend to
|
|
|
|
|
select the highest debug value and would then clutter their
|
2011-02-04 12:57:53 +01:00
|
|
|
|
disk with debug files which may reveal confidential data. */
|
2009-12-03 18:04:40 +00:00
|
|
|
|
if (numok)
|
|
|
|
|
opt.debug &= ~(DBG_HASHING_VALUE);
|
|
|
|
|
}
|
2004-02-18 17:00:11 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2012-06-05 19:29:22 +02:00
|
|
|
|
log_error (_("invalid debug-level '%s' given\n"), level);
|
2004-02-18 17:00:11 +00:00
|
|
|
|
scd_exit(2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (opt.debug && !opt.verbose)
|
|
|
|
|
opt.verbose = 1;
|
|
|
|
|
if (opt.debug && opt.quiet)
|
|
|
|
|
opt.quiet = 0;
|
|
|
|
|
|
|
|
|
|
if (opt.debug & DBG_MPI_VALUE)
|
|
|
|
|
gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 2);
|
|
|
|
|
if (opt.debug & DBG_CRYPTO_VALUE )
|
|
|
|
|
gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1);
|
|
|
|
|
gcry_control (GCRYCTL_SET_VERBOSITY, (int)opt.verbose);
|
2009-12-03 18:04:40 +00:00
|
|
|
|
|
|
|
|
|
if (opt.debug)
|
2015-06-23 09:12:44 +02:00
|
|
|
|
parse_debug_flag (NULL, &opt.debug, debug_flags);
|
2004-02-18 17:00:11 +00:00
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2004-02-18 17:00:11 +00:00
|
|
|
|
|
|
|
|
|
|
2003-08-05 17:11:04 +00:00
|
|
|
|
static void
|
|
|
|
|
cleanup (void)
|
|
|
|
|
{
|
2005-05-18 10:48:06 +00:00
|
|
|
|
if (socket_name && *socket_name)
|
2003-08-05 17:11:04 +00:00
|
|
|
|
{
|
2014-12-01 10:45:06 +01:00
|
|
|
|
char *name;
|
2003-08-05 17:11:04 +00:00
|
|
|
|
|
2014-12-01 10:45:06 +01:00
|
|
|
|
name = redir_socket_name? redir_socket_name : socket_name;
|
|
|
|
|
|
|
|
|
|
gnupg_remove (name);
|
2003-08-05 17:11:04 +00:00
|
|
|
|
*socket_name = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-19 16:36:30 +09:00
|
|
|
|
static void
|
|
|
|
|
setup_signal_mask (void)
|
|
|
|
|
{
|
|
|
|
|
#ifndef HAVE_W32_SYSTEM
|
|
|
|
|
npth_sigev_init ();
|
|
|
|
|
npth_sigev_add (SIGHUP);
|
|
|
|
|
npth_sigev_add (SIGUSR1);
|
|
|
|
|
npth_sigev_add (SIGUSR2);
|
|
|
|
|
npth_sigev_add (SIGINT);
|
|
|
|
|
npth_sigev_add (SIGCONT);
|
|
|
|
|
npth_sigev_add (SIGTERM);
|
|
|
|
|
npth_sigev_fini ();
|
|
|
|
|
main_thread_pid = getpid ();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2003-08-05 17:11:04 +00:00
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (int argc, char **argv )
|
|
|
|
|
{
|
|
|
|
|
ARGPARSE_ARGS pargs;
|
|
|
|
|
int orig_argc;
|
|
|
|
|
char **orig_argv;
|
|
|
|
|
FILE *configfp = NULL;
|
|
|
|
|
char *configname = NULL;
|
|
|
|
|
const char *shell;
|
2007-07-04 09:34:28 +00:00
|
|
|
|
unsigned int configlineno;
|
2003-08-05 17:11:04 +00:00
|
|
|
|
int parse_debug = 0;
|
2004-02-18 17:00:11 +00:00
|
|
|
|
const char *debug_level = NULL;
|
2003-08-05 17:11:04 +00:00
|
|
|
|
int default_config =1;
|
|
|
|
|
int greeting = 0;
|
|
|
|
|
int nogreeting = 0;
|
2005-05-18 10:48:06 +00:00
|
|
|
|
int multi_server = 0;
|
2003-08-05 17:11:04 +00:00
|
|
|
|
int is_daemon = 0;
|
|
|
|
|
int nodetach = 0;
|
|
|
|
|
int csh_style = 0;
|
|
|
|
|
char *logfile = NULL;
|
|
|
|
|
int debug_wait = 0;
|
2004-02-18 17:00:11 +00:00
|
|
|
|
int gpgconf_list = 0;
|
2004-03-16 18:59:21 +00:00
|
|
|
|
const char *config_filename = NULL;
|
2005-06-07 19:09:18 +00:00
|
|
|
|
int allow_coredump = 0;
|
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* configure.ac (NEED_LIBASSUAN_API, NEED_LIBASSUAN_VERSION):
Update to new API (2, 1.1.0).
agent/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* gpg-agent.c (parse_rereadable_options): Don't set global assuan
log file (there ain't one anymore).
(main): Update to new API.
(check_own_socket_pid_cb): Return gpg_error_t instead of int.
(check_own_socket_thread, check_for_running_agent): Create assuan
context before connecting to server.
* command.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(write_and_clear_outbuf): Use gpg_error_t instead of
assuan_error_t.
(cmd_geteventcounter, cmd_istrusted, cmd_listtrusted)
(cmd_marktrusted, cmd_havekey, cmd_sigkey, cmd_setkeydesc)
(cmd_sethash, cmd_pksign, cmd_pkdecrypt, cmd_genkey, cmd_readkey)
(cmd_keyinfo, cmd_get_passphrase, cmd_clear_passphrase)
(cmd_get_confirmation, cmd_learn, cmd_passwd)
(cmd_preset_passphrase, cmd_scd, cmd_getval, cmd_putval)
(cmd_updatestartuptty, cmd_killagent, cmd_reloadagent)
(cmd_getinfo, option_handler): Return gpg_error_t instead of int.
(post_cmd_notify): Change type of ERR to gpg_error_t from int.
(io_monitor): Add hook argument. Use symbols for constants.
(register_commands): Change return type of HANDLER to gpg_error_t.
(start_command_handler): Allocate assuan context before starting
server.
* call-pinentry.c: Include "scdaemon.h" before <assuan.h> because
of GPG_ERR_SOURCE_DEFAULT check.
(unlock_pinentry): Call assuan_release instead of
assuan_disconnect.
(getinfo_pid_cb, getpin_cb): Return gpg_error_t instead of int.
(start_pinentry): Allocate assuan context before connecting to
server.
* call-scd.c (membuf_data_cb, learn_status_cb, get_serialno_cb)
(membuf_data_cb, inq_needpin, card_getattr_cb, pass_status_thru)
(pass_data_thru): Change return type to gpg_error_t.
(start_scd): Allocate assuan context before connecting to server.
common/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* asshelp.c (start_new_gpg_agent): Allocate assuan context before
starting server.
g10/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* call-agent.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(learn_status_cb, dummy_data_cb, get_serialno_cb, default_inq_cb)
(learn_status_cb, inq_writecert_parms, inq_writekey_parms)
(scd_genkey_cb, membuf_data_cb): Return gpg_error_t instead of
int.
* gpg.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(main): Update to new Assuan API.
* server.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(option_handler, cmd_recipient, cmd_signer, cmd_encrypt)
(cmd_decrypt, cmd_verify, cmd_sign, cmd_import, cmd_export)
(cmd_delkeys, cmd_message, do_listkeys, cmd_listkeys)
(cmd_listsecretkeys, cmd_genkey, cmd_getinfo): Return gpg_error_t
instead of int.
(register_commands): Allocate assuan context before starting
server.
(gpg_server): Allocate assuan_context before starting server.
scd/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* command.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(option_handler, open_card, cmd_serialno, cmd_lean, cmd_readcert)
(cmd_readkey, cmd_setdata, cmd_pksign, cmd_pkauth, cmd_pkdecrypt)
(cmd_getattr, cmd_setattr, cmd_writecert, cmd_writekey)
(cmd_genkey, cmd_random, cmd_passwd, cmd_checkpin, cmd_lock)
(cmd_unlock, cmd_getinfo, cmd_restart, cmd_disconnect, cmd_apdu)
(cmd_killscd): Return gpg_error_t instead of int.
(scd_command_handler): Allocate assuan context before starting server.
* scdaemon.c (main): Update to new Assuan API.
sm/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* gpgsm.c (main): Update to new assuan API.
* server.c: Include "gpgsm.h" before <assuan.h> due to check for
GPG_ERR_SOURCE_DEFAULT and assuan.h now including gpg-error.h.
(option_handler, cmd_recipient, cmd_signer, cmd_encrypt)
(cmd_decrypt, cmd_verify, cmd_sign, cmd_import, cmd_export)
(cmd_delkeys, cmd_message, cmd_listkeys, cmd_dumpkeys)
(cmd_listsecretkeys, cmd_dumpsecretkeys, cmd_genkey)
(cmd_getauditlog, cmd_getinfo): Return gpg_error_t instead of int.
(register_commands): Same for member HANDLER in table.
(gpgsm_server): Allocate assuan context before starting server.
* sm/call-dirmngr.c:
* call-dirmngr.c (prepare_dirmngr): Check for CTX and error before
setting LDAPSERVER.
(start_dirmngr_ext): Allocate assuan context before starting
server.
(inq_certificate, isvalid_status_cb, lookup_cb, lookup_status_cb)
(run_command_cb, run_command_inq_cb, run_command_status_cb):
Return gpg_error_t instead of int.
tools/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* gpg-connect-agent.c (getinfo_pid_cb, read_and_print_response)
(main): Update to new Assuan API.
2009-09-23 00:01:25 +00:00
|
|
|
|
struct assuan_malloc_hooks malloc_hooks;
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
int res;
|
|
|
|
|
npth_t pipecon_handler;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2015-01-28 19:57:22 +01:00
|
|
|
|
early_system_init ();
|
2003-08-05 17:11:04 +00:00
|
|
|
|
set_strusage (my_strusage);
|
|
|
|
|
gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN);
|
|
|
|
|
/* Please note that we may running SUID(ROOT), so be very CAREFUL
|
|
|
|
|
when adding any stuff between here and the call to INIT_SECMEM()
|
|
|
|
|
somewhere after the option parsing */
|
Call log_set_prefix() with human-readable labels.
* agent/preset-passphrase.c, agent/protect-tool.c, dirmngr/dirmngr.c
* dirmngr/t-http.c, g10/gpg.c, g10/gpgv.c, g13/g13-syshelp.c
* g13/g13.c, kbx/kbxutil.c, scd/scdaemon.c, sm/gpgsm.c
* tests/gpgscm/main.c, tools/gpg-check-pattern.c
* tools/gpg-connect-agent.c, tools/gpgconf.c, tools/gpgtar.c
* tools/symcryptrun.c: Invoke log_set_prefix() with
human-readable labels.
--
Some invocations of log_set_prefix() were done with raw numeric values
instead of values that humans can understand. Use symbolic
representations instead of numeric for better readability.
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2016-08-12 01:37:57 -04:00
|
|
|
|
log_set_prefix ("scdaemon", GPGRT_LOG_WITH_PREFIX | GPGRT_LOG_WITH_PID);
|
2007-06-14 17:05:07 +00:00
|
|
|
|
|
|
|
|
|
/* Make sure that our subsystems are ready. */
|
2008-12-09 08:58:02 +00:00
|
|
|
|
i18n_init ();
|
2010-03-22 12:46:05 +00:00
|
|
|
|
init_common_subsystems (&argc, &argv);
|
2004-02-18 17:00:11 +00:00
|
|
|
|
|
2003-08-05 17:11:04 +00:00
|
|
|
|
ksba_set_malloc_hooks (gcry_malloc, gcry_realloc, gcry_free);
|
2003-12-16 16:30:55 +00:00
|
|
|
|
|
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* configure.ac (NEED_LIBASSUAN_API, NEED_LIBASSUAN_VERSION):
Update to new API (2, 1.1.0).
agent/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* gpg-agent.c (parse_rereadable_options): Don't set global assuan
log file (there ain't one anymore).
(main): Update to new API.
(check_own_socket_pid_cb): Return gpg_error_t instead of int.
(check_own_socket_thread, check_for_running_agent): Create assuan
context before connecting to server.
* command.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(write_and_clear_outbuf): Use gpg_error_t instead of
assuan_error_t.
(cmd_geteventcounter, cmd_istrusted, cmd_listtrusted)
(cmd_marktrusted, cmd_havekey, cmd_sigkey, cmd_setkeydesc)
(cmd_sethash, cmd_pksign, cmd_pkdecrypt, cmd_genkey, cmd_readkey)
(cmd_keyinfo, cmd_get_passphrase, cmd_clear_passphrase)
(cmd_get_confirmation, cmd_learn, cmd_passwd)
(cmd_preset_passphrase, cmd_scd, cmd_getval, cmd_putval)
(cmd_updatestartuptty, cmd_killagent, cmd_reloadagent)
(cmd_getinfo, option_handler): Return gpg_error_t instead of int.
(post_cmd_notify): Change type of ERR to gpg_error_t from int.
(io_monitor): Add hook argument. Use symbols for constants.
(register_commands): Change return type of HANDLER to gpg_error_t.
(start_command_handler): Allocate assuan context before starting
server.
* call-pinentry.c: Include "scdaemon.h" before <assuan.h> because
of GPG_ERR_SOURCE_DEFAULT check.
(unlock_pinentry): Call assuan_release instead of
assuan_disconnect.
(getinfo_pid_cb, getpin_cb): Return gpg_error_t instead of int.
(start_pinentry): Allocate assuan context before connecting to
server.
* call-scd.c (membuf_data_cb, learn_status_cb, get_serialno_cb)
(membuf_data_cb, inq_needpin, card_getattr_cb, pass_status_thru)
(pass_data_thru): Change return type to gpg_error_t.
(start_scd): Allocate assuan context before connecting to server.
common/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* asshelp.c (start_new_gpg_agent): Allocate assuan context before
starting server.
g10/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* call-agent.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(learn_status_cb, dummy_data_cb, get_serialno_cb, default_inq_cb)
(learn_status_cb, inq_writecert_parms, inq_writekey_parms)
(scd_genkey_cb, membuf_data_cb): Return gpg_error_t instead of
int.
* gpg.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(main): Update to new Assuan API.
* server.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(option_handler, cmd_recipient, cmd_signer, cmd_encrypt)
(cmd_decrypt, cmd_verify, cmd_sign, cmd_import, cmd_export)
(cmd_delkeys, cmd_message, do_listkeys, cmd_listkeys)
(cmd_listsecretkeys, cmd_genkey, cmd_getinfo): Return gpg_error_t
instead of int.
(register_commands): Allocate assuan context before starting
server.
(gpg_server): Allocate assuan_context before starting server.
scd/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* command.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(option_handler, open_card, cmd_serialno, cmd_lean, cmd_readcert)
(cmd_readkey, cmd_setdata, cmd_pksign, cmd_pkauth, cmd_pkdecrypt)
(cmd_getattr, cmd_setattr, cmd_writecert, cmd_writekey)
(cmd_genkey, cmd_random, cmd_passwd, cmd_checkpin, cmd_lock)
(cmd_unlock, cmd_getinfo, cmd_restart, cmd_disconnect, cmd_apdu)
(cmd_killscd): Return gpg_error_t instead of int.
(scd_command_handler): Allocate assuan context before starting server.
* scdaemon.c (main): Update to new Assuan API.
sm/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* gpgsm.c (main): Update to new assuan API.
* server.c: Include "gpgsm.h" before <assuan.h> due to check for
GPG_ERR_SOURCE_DEFAULT and assuan.h now including gpg-error.h.
(option_handler, cmd_recipient, cmd_signer, cmd_encrypt)
(cmd_decrypt, cmd_verify, cmd_sign, cmd_import, cmd_export)
(cmd_delkeys, cmd_message, cmd_listkeys, cmd_dumpkeys)
(cmd_listsecretkeys, cmd_dumpsecretkeys, cmd_genkey)
(cmd_getauditlog, cmd_getinfo): Return gpg_error_t instead of int.
(register_commands): Same for member HANDLER in table.
(gpgsm_server): Allocate assuan context before starting server.
* sm/call-dirmngr.c:
* call-dirmngr.c (prepare_dirmngr): Check for CTX and error before
setting LDAPSERVER.
(start_dirmngr_ext): Allocate assuan context before starting
server.
(inq_certificate, isvalid_status_cb, lookup_cb, lookup_status_cb)
(run_command_cb, run_command_inq_cb, run_command_status_cb):
Return gpg_error_t instead of int.
tools/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* gpg-connect-agent.c (getinfo_pid_cb, read_and_print_response)
(main): Update to new Assuan API.
2009-09-23 00:01:25 +00:00
|
|
|
|
malloc_hooks.malloc = gcry_malloc;
|
|
|
|
|
malloc_hooks.realloc = gcry_realloc;
|
|
|
|
|
malloc_hooks.free = gcry_free;
|
|
|
|
|
assuan_set_malloc_hooks (&malloc_hooks);
|
|
|
|
|
assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
assuan_set_system_hooks (ASSUAN_SYSTEM_NPTH);
|
2009-10-16 18:35:03 +00:00
|
|
|
|
assuan_sock_init ();
|
2016-09-05 10:55:10 +02:00
|
|
|
|
setup_libassuan_logging (&opt.debug, NULL);
|
2006-09-06 16:35:52 +00:00
|
|
|
|
|
2007-04-20 16:59:37 +00:00
|
|
|
|
setup_libgcrypt_logging ();
|
2003-08-05 17:11:04 +00:00
|
|
|
|
gcry_control (GCRYCTL_USE_SECURE_RNDPOOL);
|
|
|
|
|
|
2011-08-10 14:11:30 +02:00
|
|
|
|
disable_core_dumps ();
|
2003-08-05 17:11:04 +00:00
|
|
|
|
|
2003-08-19 09:36:48 +00:00
|
|
|
|
/* Set default options. */
|
2009-01-28 14:18:40 +00:00
|
|
|
|
opt.allow_admin = 1;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
opt.pcsc_driver = DEFAULT_PCSC_DRIVER;
|
2003-08-19 09:36:48 +00:00
|
|
|
|
|
2003-08-05 17:11:04 +00:00
|
|
|
|
shell = getenv ("SHELL");
|
|
|
|
|
if (shell && strlen (shell) >= 3 && !strcmp (shell+strlen (shell)-3, "csh") )
|
|
|
|
|
csh_style = 1;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2004-12-21 10:03:00 +00:00
|
|
|
|
/* Check whether we have a config file on the commandline */
|
2003-08-05 17:11:04 +00:00
|
|
|
|
orig_argc = argc;
|
|
|
|
|
orig_argv = argv;
|
|
|
|
|
pargs.argc = &argc;
|
|
|
|
|
pargs.argv = &argv;
|
|
|
|
|
pargs.flags= 1|(1<<6); /* do not remove the args, ignore version */
|
|
|
|
|
while (arg_parse( &pargs, opts))
|
|
|
|
|
{
|
|
|
|
|
if (pargs.r_opt == oDebug || pargs.r_opt == oDebugAll)
|
|
|
|
|
parse_debug++;
|
|
|
|
|
else if (pargs.r_opt == oOptions)
|
|
|
|
|
{ /* yes there is one, so we do not try the default one, but
|
2017-01-31 12:56:11 +09:00
|
|
|
|
read the option file when it is encountered at the
|
|
|
|
|
commandline */
|
2003-08-05 17:11:04 +00:00
|
|
|
|
default_config = 0;
|
2017-01-31 12:56:11 +09:00
|
|
|
|
}
|
|
|
|
|
else if (pargs.r_opt == oNoOptions)
|
2003-08-05 17:11:04 +00:00
|
|
|
|
default_config = 0; /* --no-options */
|
2017-01-31 12:56:11 +09:00
|
|
|
|
else if (pargs.r_opt == oHomedir)
|
2016-06-07 10:59:46 +02:00
|
|
|
|
gnupg_set_homedir (pargs.r.ret_str);
|
2003-08-05 17:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* initialize the secure memory. */
|
|
|
|
|
gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0);
|
|
|
|
|
maybe_setuid = 0;
|
|
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
|
/*
|
|
|
|
|
Now we are working under our real uid
|
2003-08-05 17:11:04 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (default_config)
|
2016-06-07 10:59:46 +02:00
|
|
|
|
configname = make_filename (gnupg_homedir (), SCDAEMON_NAME EXTSEP_S "conf",
|
2014-05-07 18:18:27 +02:00
|
|
|
|
NULL );
|
2003-08-05 17:11:04 +00:00
|
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2003-08-05 17:11:04 +00:00
|
|
|
|
argc = orig_argc;
|
|
|
|
|
argv = orig_argv;
|
|
|
|
|
pargs.argc = &argc;
|
|
|
|
|
pargs.argv = &argv;
|
|
|
|
|
pargs.flags= 1; /* do not remove the args */
|
|
|
|
|
next_pass:
|
|
|
|
|
if (configname)
|
|
|
|
|
{
|
|
|
|
|
configlineno = 0;
|
|
|
|
|
configfp = fopen (configname, "r");
|
|
|
|
|
if (!configfp)
|
|
|
|
|
{
|
|
|
|
|
if (default_config)
|
|
|
|
|
{
|
|
|
|
|
if( parse_debug )
|
2014-10-10 15:29:42 +02:00
|
|
|
|
log_info (_("Note: no default option file '%s'\n"),
|
2003-08-05 17:11:04 +00:00
|
|
|
|
configname );
|
2017-01-31 12:56:11 +09:00
|
|
|
|
}
|
2003-08-05 17:11:04 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2012-06-05 19:29:22 +02:00
|
|
|
|
log_error (_("option file '%s': %s\n"),
|
2003-08-05 17:11:04 +00:00
|
|
|
|
configname, strerror(errno) );
|
|
|
|
|
exit(2);
|
2017-01-31 12:56:11 +09:00
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
xfree (configname);
|
2003-08-05 17:11:04 +00:00
|
|
|
|
configname = NULL;
|
2017-01-31 12:56:11 +09:00
|
|
|
|
}
|
2003-08-05 17:11:04 +00:00
|
|
|
|
if (parse_debug && configname )
|
2012-06-05 19:29:22 +02:00
|
|
|
|
log_info (_("reading options from '%s'\n"), configname );
|
2003-08-05 17:11:04 +00:00
|
|
|
|
default_config = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (optfile_parse( configfp, configname, &configlineno, &pargs, opts) )
|
|
|
|
|
{
|
|
|
|
|
switch (pargs.r_opt)
|
|
|
|
|
{
|
2004-02-18 17:00:11 +00:00
|
|
|
|
case aGPGConfList: gpgconf_list = 1; break;
|
2006-10-23 14:02:13 +00:00
|
|
|
|
case aGPGConfTest: gpgconf_list = 2; break;
|
2003-08-05 17:11:04 +00:00
|
|
|
|
case oQuiet: opt.quiet = 1; break;
|
|
|
|
|
case oVerbose: opt.verbose++; break;
|
|
|
|
|
case oBatch: opt.batch=1; break;
|
|
|
|
|
|
2015-06-23 09:12:44 +02:00
|
|
|
|
case oDebug:
|
|
|
|
|
if (parse_debug_flag (pargs.r.ret_str, &opt.debug, debug_flags))
|
|
|
|
|
{
|
|
|
|
|
pargs.r_opt = ARGPARSE_INVALID_ARG;
|
|
|
|
|
pargs.err = ARGPARSE_PRINT_ERROR;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2003-08-05 17:11:04 +00:00
|
|
|
|
case oDebugAll: opt.debug = ~0; break;
|
2004-02-18 17:00:11 +00:00
|
|
|
|
case oDebugLevel: debug_level = pargs.r.ret_str; break;
|
2003-08-05 17:11:04 +00:00
|
|
|
|
case oDebugWait: debug_wait = pargs.r.ret_int; break;
|
2005-06-07 19:09:18 +00:00
|
|
|
|
case oDebugAllowCoreDump:
|
|
|
|
|
enable_core_dumps ();
|
|
|
|
|
allow_coredump = 1;
|
|
|
|
|
break;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
case oDebugCCIDDriver:
|
2005-07-20 15:05:05 +00:00
|
|
|
|
#ifdef HAVE_LIBUSB
|
2005-05-20 20:39:36 +00:00
|
|
|
|
ccid_set_debug_level (ccid_set_debug_level (-1)+1);
|
2005-07-20 15:05:05 +00:00
|
|
|
|
#endif /*HAVE_LIBUSB*/
|
2005-05-20 20:39:36 +00:00
|
|
|
|
break;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
case oDebugLogTid:
|
2010-06-09 16:53:51 +00:00
|
|
|
|
log_set_pid_suffix_cb (tid_log_callback);
|
2009-02-25 10:58:56 +00:00
|
|
|
|
break;
|
2011-12-13 17:59:00 +01:00
|
|
|
|
case oDebugAssuanLogCats:
|
|
|
|
|
set_libassuan_log_cats (pargs.r.ret_ulong);
|
|
|
|
|
break;
|
2003-08-05 17:11:04 +00:00
|
|
|
|
|
|
|
|
|
case oOptions:
|
|
|
|
|
/* config files may not be nested (silently ignore them) */
|
|
|
|
|
if (!configfp)
|
|
|
|
|
{
|
2017-01-31 12:56:11 +09:00
|
|
|
|
xfree(configname);
|
|
|
|
|
configname = xstrdup(pargs.r.ret_str);
|
|
|
|
|
goto next_pass;
|
|
|
|
|
}
|
2003-08-05 17:11:04 +00:00
|
|
|
|
break;
|
|
|
|
|
case oNoGreeting: nogreeting = 1; break;
|
|
|
|
|
case oNoVerbose: opt.verbose = 0; break;
|
|
|
|
|
case oNoOptions: break; /* no-options */
|
2016-06-07 10:59:46 +02:00
|
|
|
|
case oHomedir: gnupg_set_homedir (pargs.r.ret_str); break;
|
2003-08-05 17:11:04 +00:00
|
|
|
|
case oNoDetach: nodetach = 1; break;
|
|
|
|
|
case oLogFile: logfile = pargs.r.ret_str; break;
|
|
|
|
|
case oCsh: csh_style = 1; break;
|
|
|
|
|
case oSh: csh_style = 0; break;
|
|
|
|
|
case oServer: pipe_server = 1; break;
|
2005-05-20 20:39:36 +00:00
|
|
|
|
case oMultiServer: pipe_server = 1; multi_server = 1; break;
|
2003-08-05 17:11:04 +00:00
|
|
|
|
case oDaemon: is_daemon = 1; break;
|
|
|
|
|
|
2004-01-27 16:40:42 +00:00
|
|
|
|
case oReaderPort: opt.reader_port = pargs.r.ret_str; break;
|
2003-08-05 17:11:04 +00:00
|
|
|
|
case octapiDriver: opt.ctapi_driver = pargs.r.ret_str; break;
|
2003-08-19 09:36:48 +00:00
|
|
|
|
case opcscDriver: opt.pcsc_driver = pargs.r.ret_str; break;
|
2003-09-02 19:06:34 +00:00
|
|
|
|
case oDisableCCID: opt.disable_ccid = 1; break;
|
2005-04-27 12:09:21 +00:00
|
|
|
|
case oDisableOpenSC: break;
|
2003-08-05 17:11:04 +00:00
|
|
|
|
|
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
|
|
|
|
case oDisablePinpad: opt.disable_pinpad = 1; break;
|
2005-11-28 11:52:25 +00:00
|
|
|
|
|
2009-01-28 14:18:40 +00:00
|
|
|
|
case oAllowAdmin: /* Dummy because allow is now the default. */
|
|
|
|
|
break;
|
2003-12-01 10:54:09 +00:00
|
|
|
|
case oDenyAdmin: opt.allow_admin = 0; break;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2008-12-05 12:01:01 +00:00
|
|
|
|
case oCardTimeout: opt.card_timeout = pargs.r.ret_ulong; break;
|
2003-12-01 10:54:09 +00:00
|
|
|
|
|
2004-08-05 09:24:36 +00:00
|
|
|
|
case oDisableApplication:
|
2011-02-04 12:57:53 +01:00
|
|
|
|
add_to_strlist (&opt.disabled_applications, pargs.r.ret_str);
|
2004-08-05 09:24:36 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2017-01-31 12:56:11 +09:00
|
|
|
|
case oEnablePinpadVarlen: opt.enable_pinpad_varlen = 1; break;
|
2013-01-09 13:24:57 +09:00
|
|
|
|
|
2017-12-12 14:14:40 +01:00
|
|
|
|
case oListenBacklog:
|
|
|
|
|
listen_backlog = pargs.r.ret_int;
|
|
|
|
|
break;
|
|
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
|
default:
|
|
|
|
|
pargs.err = configfp? ARGPARSE_PRINT_WARNING:ARGPARSE_PRINT_ERROR;
|
2008-12-05 12:01:01 +00:00
|
|
|
|
break;
|
2017-01-31 12:56:11 +09:00
|
|
|
|
}
|
2003-08-05 17:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
if (configfp)
|
|
|
|
|
{
|
|
|
|
|
fclose( configfp );
|
|
|
|
|
configfp = NULL;
|
2004-03-16 18:59:21 +00:00
|
|
|
|
/* Keep a copy of the config name for use by --gpgconf-list. */
|
|
|
|
|
config_filename = configname;
|
2003-08-05 17:11:04 +00:00
|
|
|
|
configname = NULL;
|
|
|
|
|
goto next_pass;
|
|
|
|
|
}
|
|
|
|
|
xfree (configname);
|
|
|
|
|
configname = NULL;
|
|
|
|
|
if (log_get_errorcount(0))
|
|
|
|
|
exit(2);
|
|
|
|
|
if (nogreeting )
|
|
|
|
|
greeting = 0;
|
|
|
|
|
|
|
|
|
|
if (greeting)
|
|
|
|
|
{
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_fprintf (es_stderr, "%s %s; %s\n",
|
|
|
|
|
strusage(11), strusage(13), strusage(14) );
|
|
|
|
|
es_fprintf (es_stderr, "%s\n", strusage(15) );
|
2003-08-05 17:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
#ifdef IS_DEVELOPMENT_VERSION
|
|
|
|
|
log_info ("NOTE: this is a development version!\n");
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-03-27 12:35:13 +02:00
|
|
|
|
/* Print a warning if an argument looks like an option. */
|
|
|
|
|
if (!opt.quiet && !(pargs.flags & ARGPARSE_FLAG_STOP_SEEN))
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i=0; i < argc; i++)
|
|
|
|
|
if (argv[i][0] == '-' && argv[i][1] == '-')
|
2014-10-10 15:29:42 +02:00
|
|
|
|
log_info (_("Note: '%s' is not considered an option\n"), argv[i]);
|
2012-03-27 12:35:13 +02:00
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2003-08-05 17:11:04 +00:00
|
|
|
|
if (atexit (cleanup))
|
|
|
|
|
{
|
|
|
|
|
log_error ("atexit failed\n");
|
|
|
|
|
cleanup ();
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-18 17:00:11 +00:00
|
|
|
|
set_debug (debug_level);
|
|
|
|
|
|
2016-12-29 10:07:43 +09:00
|
|
|
|
if (initialize_module_command ())
|
|
|
|
|
{
|
|
|
|
|
log_error ("initialization failed\n");
|
|
|
|
|
cleanup ();
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
2007-06-14 17:05:07 +00:00
|
|
|
|
|
2006-10-23 14:02:13 +00:00
|
|
|
|
if (gpgconf_list == 2)
|
|
|
|
|
scd_exit (0);
|
2004-02-18 17:00:11 +00:00
|
|
|
|
if (gpgconf_list)
|
2004-04-26 13:07:08 +00:00
|
|
|
|
{
|
|
|
|
|
/* List options and default values in the GPG Conf format. */
|
2007-06-18 20:15:01 +00:00
|
|
|
|
char *filename = NULL;
|
|
|
|
|
char *filename_esc;
|
2004-03-16 18:59:21 +00:00
|
|
|
|
|
2008-02-09 00:13:43 +00:00
|
|
|
|
if (config_filename)
|
2017-01-31 12:56:11 +09:00
|
|
|
|
filename = xstrdup (config_filename);
|
2008-02-09 00:13:43 +00:00
|
|
|
|
else
|
2016-06-07 10:59:46 +02:00
|
|
|
|
filename = make_filename (gnupg_homedir (),
|
|
|
|
|
SCDAEMON_NAME EXTSEP_S "conf", NULL);
|
2007-06-19 09:11:11 +00:00
|
|
|
|
filename_esc = percent_escape (filename, NULL);
|
2004-03-16 18:59:21 +00:00
|
|
|
|
|
2014-05-07 18:18:27 +02:00
|
|
|
|
es_printf ("%s-%s.conf:%lu:\"%s\n",
|
|
|
|
|
GPGCONF_NAME, SCDAEMON_NAME,
|
2010-08-18 19:25:15 +00:00
|
|
|
|
GC_OPT_FLAG_DEFAULT, filename_esc);
|
2007-06-18 20:15:01 +00:00
|
|
|
|
xfree (filename_esc);
|
|
|
|
|
xfree (filename);
|
|
|
|
|
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_printf ("verbose:%lu:\n"
|
|
|
|
|
"quiet:%lu:\n"
|
|
|
|
|
"debug-level:%lu:\"none:\n"
|
|
|
|
|
"log-file:%lu:\n",
|
|
|
|
|
GC_OPT_FLAG_NONE,
|
|
|
|
|
GC_OPT_FLAG_NONE,
|
|
|
|
|
GC_OPT_FLAG_DEFAULT,
|
|
|
|
|
GC_OPT_FLAG_NONE );
|
|
|
|
|
|
|
|
|
|
es_printf ("reader-port:%lu:\n", GC_OPT_FLAG_NONE );
|
|
|
|
|
es_printf ("ctapi-driver:%lu:\n", GC_OPT_FLAG_NONE );
|
|
|
|
|
es_printf ("pcsc-driver:%lu:\"%s:\n",
|
2004-03-16 18:59:21 +00:00
|
|
|
|
GC_OPT_FLAG_DEFAULT, DEFAULT_PCSC_DRIVER );
|
|
|
|
|
#ifdef HAVE_LIBUSB
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_printf ("disable-ccid:%lu:\n", GC_OPT_FLAG_NONE );
|
2004-03-16 18:59:21 +00:00
|
|
|
|
#endif
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_printf ("deny-admin:%lu:\n", GC_OPT_FLAG_NONE );
|
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
|
|
|
|
es_printf ("disable-pinpad:%lu:\n", GC_OPT_FLAG_NONE );
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_printf ("card-timeout:%lu:%d:\n", GC_OPT_FLAG_DEFAULT, 0);
|
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
|
|
|
|
es_printf ("enable-pinpad-varlen:%lu:\n", GC_OPT_FLAG_NONE );
|
2004-02-18 17:00:11 +00:00
|
|
|
|
|
|
|
|
|
scd_exit (0);
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-25 10:58:56 +00:00
|
|
|
|
/* Now start with logging to a file if this is desired. */
|
2003-08-05 17:11:04 +00:00
|
|
|
|
if (logfile)
|
|
|
|
|
{
|
|
|
|
|
log_set_file (logfile);
|
Call log_set_prefix() with human-readable labels.
* agent/preset-passphrase.c, agent/protect-tool.c, dirmngr/dirmngr.c
* dirmngr/t-http.c, g10/gpg.c, g10/gpgv.c, g13/g13-syshelp.c
* g13/g13.c, kbx/kbxutil.c, scd/scdaemon.c, sm/gpgsm.c
* tests/gpgscm/main.c, tools/gpg-check-pattern.c
* tools/gpg-connect-agent.c, tools/gpgconf.c, tools/gpgtar.c
* tools/symcryptrun.c: Invoke log_set_prefix() with
human-readable labels.
--
Some invocations of log_set_prefix() were done with raw numeric values
instead of values that humans can understand. Use symbolic
representations instead of numeric for better readability.
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2016-08-12 01:37:57 -04:00
|
|
|
|
log_set_prefix (NULL, GPGRT_LOG_WITH_PREFIX | GPGRT_LOG_WITH_TIME | GPGRT_LOG_WITH_PID);
|
2003-08-05 17:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-25 10:58:56 +00:00
|
|
|
|
if (debug_wait && pipe_server)
|
|
|
|
|
{
|
|
|
|
|
log_debug ("waiting for debugger - my pid is %u .....\n",
|
|
|
|
|
(unsigned int)getpid());
|
|
|
|
|
gnupg_sleep (debug_wait);
|
|
|
|
|
log_debug ("... okay\n");
|
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2003-08-05 17:11:04 +00:00
|
|
|
|
if (pipe_server)
|
2011-02-04 12:57:53 +01:00
|
|
|
|
{
|
2005-05-18 10:48:06 +00:00
|
|
|
|
/* This is the simple pipe based server */
|
2006-11-20 16:49:41 +00:00
|
|
|
|
ctrl_t ctrl;
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
npth_attr_t tattr;
|
2005-05-18 10:48:06 +00:00
|
|
|
|
int fd = -1;
|
|
|
|
|
|
2007-06-14 17:05:07 +00:00
|
|
|
|
#ifndef HAVE_W32_SYSTEM
|
2005-05-18 10:48:06 +00:00
|
|
|
|
{
|
|
|
|
|
struct sigaction sa;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2005-05-18 10:48:06 +00:00
|
|
|
|
sa.sa_handler = SIG_IGN;
|
|
|
|
|
sigemptyset (&sa.sa_mask);
|
|
|
|
|
sa.sa_flags = 0;
|
|
|
|
|
sigaction (SIGPIPE, &sa, NULL);
|
|
|
|
|
}
|
2007-06-14 17:05:07 +00:00
|
|
|
|
#endif
|
2005-05-18 10:48:06 +00:00
|
|
|
|
|
2016-10-04 09:01:13 +09:00
|
|
|
|
npth_init ();
|
2018-03-19 16:36:30 +09:00
|
|
|
|
setup_signal_mask ();
|
2016-10-07 10:45:22 +09:00
|
|
|
|
gpgrt_set_syscall_clamp (npth_unprotect, npth_protect);
|
2016-10-04 09:01:13 +09:00
|
|
|
|
|
2005-06-07 19:09:18 +00:00
|
|
|
|
/* If --debug-allow-core-dump has been given we also need to
|
|
|
|
|
switch the working directory to a place where we can actually
|
|
|
|
|
write. */
|
|
|
|
|
if (allow_coredump)
|
|
|
|
|
{
|
|
|
|
|
if (chdir("/tmp"))
|
2012-06-05 19:29:22 +02:00
|
|
|
|
log_debug ("chdir to '/tmp' failed: %s\n", strerror (errno));
|
2005-06-07 19:09:18 +00:00
|
|
|
|
else
|
2012-06-05 19:29:22 +02:00
|
|
|
|
log_debug ("changed working directory to '/tmp'\n");
|
2005-06-07 19:09:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-05-18 10:48:06 +00:00
|
|
|
|
/* In multi server mode we need to listen on an additional
|
|
|
|
|
socket. Create that socket now before starting the handler
|
|
|
|
|
for the pipe connection. This allows that handler to send
|
|
|
|
|
back the name of that socket. */
|
|
|
|
|
if (multi_server)
|
|
|
|
|
{
|
2014-10-03 11:58:58 +02:00
|
|
|
|
socket_name = create_socket_name (SCDAEMON_SOCK_NAME);
|
2014-12-01 10:45:06 +01:00
|
|
|
|
fd = FD2INT(create_server_socket (socket_name,
|
|
|
|
|
&redir_socket_name, &socket_nonce));
|
2005-05-18 10:48:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
res = npth_attr_init (&tattr);
|
|
|
|
|
if (res)
|
2017-01-27 14:34:21 +09:00
|
|
|
|
{
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
log_error ("error allocating thread attributes: %s\n",
|
|
|
|
|
strerror (res));
|
|
|
|
|
scd_exit (2);
|
|
|
|
|
}
|
|
|
|
|
npth_attr_setdetachstate (&tattr, NPTH_CREATE_DETACHED);
|
2004-04-20 14:17:10 +00:00
|
|
|
|
|
2006-11-20 16:49:41 +00:00
|
|
|
|
ctrl = xtrycalloc (1, sizeof *ctrl);
|
|
|
|
|
if ( !ctrl )
|
|
|
|
|
{
|
|
|
|
|
log_error ("error allocating connection control data: %s\n",
|
|
|
|
|
strerror (errno) );
|
|
|
|
|
scd_exit (2);
|
|
|
|
|
}
|
2007-10-01 14:48:39 +00:00
|
|
|
|
ctrl->thread_startup.fd = GNUPG_INVALID_FD;
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
res = npth_create (&pipecon_handler, &tattr, start_connection_thread, ctrl);
|
|
|
|
|
if (res)
|
2004-04-20 14:17:10 +00:00
|
|
|
|
{
|
2005-05-18 10:48:06 +00:00
|
|
|
|
log_error ("error spawning pipe connection handler: %s\n",
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
strerror (res) );
|
2006-11-20 16:49:41 +00:00
|
|
|
|
xfree (ctrl);
|
2004-04-20 14:17:10 +00:00
|
|
|
|
scd_exit (2);
|
|
|
|
|
}
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
npth_setname_np (pipecon_handler, "pipe-connection");
|
|
|
|
|
npth_attr_destroy (&tattr);
|
2005-05-18 10:48:06 +00:00
|
|
|
|
|
2007-11-19 16:03:50 +00:00
|
|
|
|
/* We run handle_connection to wait for the shutdown signal and
|
|
|
|
|
to run the ticker stuff. */
|
2017-01-28 00:18:11 +09:00
|
|
|
|
handle_connections (fd);
|
2005-05-18 10:48:06 +00:00
|
|
|
|
if (fd != -1)
|
|
|
|
|
close (fd);
|
2003-08-05 17:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
else if (!is_daemon)
|
|
|
|
|
{
|
2012-06-05 19:29:22 +02:00
|
|
|
|
log_info (_("please use the option '--daemon'"
|
2003-08-05 17:11:04 +00:00
|
|
|
|
" to run the program in the background\n"));
|
|
|
|
|
}
|
|
|
|
|
else
|
2005-05-18 10:48:06 +00:00
|
|
|
|
{ /* Regular server mode */
|
2003-08-05 17:11:04 +00:00
|
|
|
|
int fd;
|
2007-10-01 14:48:39 +00:00
|
|
|
|
#ifndef HAVE_W32_SYSTEM
|
2003-08-05 17:11:04 +00:00
|
|
|
|
pid_t pid;
|
|
|
|
|
int i;
|
2007-10-01 14:48:39 +00:00
|
|
|
|
#endif
|
2003-08-05 17:11:04 +00:00
|
|
|
|
|
2005-05-18 10:48:06 +00:00
|
|
|
|
/* Create the socket. */
|
2014-10-03 11:58:58 +02:00
|
|
|
|
socket_name = create_socket_name (SCDAEMON_SOCK_NAME);
|
2014-12-01 10:45:06 +01:00
|
|
|
|
fd = FD2INT (create_server_socket (socket_name,
|
|
|
|
|
&redir_socket_name, &socket_nonce));
|
2003-08-05 17:11:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fflush (NULL);
|
2014-03-07 09:46:44 +01:00
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
|
(void)csh_style;
|
|
|
|
|
(void)nodetach;
|
|
|
|
|
#else
|
2003-08-05 17:11:04 +00:00
|
|
|
|
pid = fork ();
|
2011-02-04 12:57:53 +01:00
|
|
|
|
if (pid == (pid_t)-1)
|
2003-08-05 17:11:04 +00:00
|
|
|
|
{
|
|
|
|
|
log_fatal ("fork failed: %s\n", strerror (errno) );
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
else if (pid)
|
2003-08-05 17:11:04 +00:00
|
|
|
|
{ /* we are the parent */
|
|
|
|
|
char *infostr;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2003-08-05 17:11:04 +00:00
|
|
|
|
close (fd);
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2003-08-05 17:11:04 +00:00
|
|
|
|
/* create the info string: <name>:<pid>:<protocol_version> */
|
2014-08-26 17:47:22 +02:00
|
|
|
|
if (gpgrt_asprintf (&infostr, "SCDAEMON_INFO=%s:%lu:1",
|
|
|
|
|
socket_name, (ulong) pid) < 0)
|
2003-08-05 17:11:04 +00:00
|
|
|
|
{
|
|
|
|
|
log_error ("out of core\n");
|
|
|
|
|
kill (pid, SIGTERM);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
*socket_name = 0; /* don't let cleanup() remove the socket -
|
|
|
|
|
the child should do this from now on */
|
2011-02-04 12:57:53 +01:00
|
|
|
|
if (argc)
|
2003-08-05 17:11:04 +00:00
|
|
|
|
{ /* run the program given on the commandline */
|
|
|
|
|
if (putenv (infostr))
|
|
|
|
|
{
|
|
|
|
|
log_error ("failed to set environment: %s\n",
|
|
|
|
|
strerror (errno) );
|
|
|
|
|
kill (pid, SIGTERM );
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
execvp (argv[0], argv);
|
|
|
|
|
log_error ("failed to run the command: %s\n", strerror (errno));
|
|
|
|
|
kill (pid, SIGTERM);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-05-18 10:48:06 +00:00
|
|
|
|
/* Print the environment string, so that the caller can use
|
2003-08-05 17:11:04 +00:00
|
|
|
|
shell's eval to set it */
|
|
|
|
|
if (csh_style)
|
|
|
|
|
{
|
|
|
|
|
*strchr (infostr, '=') = ' ';
|
2012-01-03 11:13:30 +01:00
|
|
|
|
es_printf ( "setenv %s;\n", infostr);
|
2003-08-05 17:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-08-18 19:25:15 +00:00
|
|
|
|
es_printf ( "%s; export SCDAEMON_INFO;\n", infostr);
|
2003-08-05 17:11:04 +00:00
|
|
|
|
}
|
2008-08-31 11:55:09 +00:00
|
|
|
|
xfree (infostr);
|
2011-02-04 12:57:53 +01:00
|
|
|
|
exit (0);
|
2003-08-05 17:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
/* NOTREACHED */
|
|
|
|
|
} /* end parent */
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2005-05-18 10:48:06 +00:00
|
|
|
|
/* This is the child. */
|
2003-08-05 17:11:04 +00:00
|
|
|
|
|
2016-10-04 09:01:13 +09:00
|
|
|
|
npth_init ();
|
2018-03-19 16:36:30 +09:00
|
|
|
|
setup_signal_mask ();
|
2016-10-07 10:45:22 +09:00
|
|
|
|
gpgrt_set_syscall_clamp (npth_unprotect, npth_protect);
|
2016-10-04 09:01:13 +09:00
|
|
|
|
|
2005-05-18 10:48:06 +00:00
|
|
|
|
/* Detach from tty and put process into a new session. */
|
2003-08-05 17:11:04 +00:00
|
|
|
|
if (!nodetach )
|
2011-02-04 12:57:53 +01:00
|
|
|
|
{
|
2005-05-18 10:48:06 +00:00
|
|
|
|
/* Close stdin, stdout and stderr unless it is the log stream. */
|
2011-02-04 12:57:53 +01:00
|
|
|
|
for (i=0; i <= 2; i++)
|
2003-08-05 17:11:04 +00:00
|
|
|
|
{
|
2016-11-16 21:17:47 +01:00
|
|
|
|
if (!log_test_fd (i) && i != fd )
|
|
|
|
|
{
|
|
|
|
|
if ( !close (i)
|
|
|
|
|
&& open ("/dev/null", i? O_WRONLY : O_RDONLY) == -1)
|
|
|
|
|
{
|
|
|
|
|
log_error ("failed to open '%s': %s\n",
|
|
|
|
|
"/dev/null", strerror (errno));
|
|
|
|
|
cleanup ();
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-08-05 17:11:04 +00:00
|
|
|
|
}
|
2016-11-16 21:17:47 +01:00
|
|
|
|
|
2003-08-05 17:11:04 +00:00
|
|
|
|
if (setsid() == -1)
|
|
|
|
|
{
|
|
|
|
|
log_error ("setsid() failed: %s\n", strerror(errno) );
|
|
|
|
|
cleanup ();
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2005-05-18 10:48:06 +00:00
|
|
|
|
struct sigaction sa;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2005-05-18 10:48:06 +00:00
|
|
|
|
sa.sa_handler = SIG_IGN;
|
|
|
|
|
sigemptyset (&sa.sa_mask);
|
|
|
|
|
sa.sa_flags = 0;
|
|
|
|
|
sigaction (SIGPIPE, &sa, NULL);
|
2003-08-05 17:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-25 12:52:33 +02:00
|
|
|
|
#endif /*!HAVE_W32_SYSTEM*/
|
|
|
|
|
|
2017-07-25 12:24:01 +02:00
|
|
|
|
if (gnupg_chdir (gnupg_daemon_rootdir ()))
|
2003-08-05 17:11:04 +00:00
|
|
|
|
{
|
2017-07-25 12:24:01 +02:00
|
|
|
|
log_error ("chdir to '%s' failed: %s\n",
|
|
|
|
|
gnupg_daemon_rootdir (), strerror (errno));
|
2003-08-05 17:11:04 +00:00
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-28 00:18:11 +09:00
|
|
|
|
handle_connections (fd);
|
2003-08-05 17:11:04 +00:00
|
|
|
|
|
|
|
|
|
close (fd);
|
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2003-08-05 17:11:04 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
scd_exit (int rc)
|
|
|
|
|
{
|
2009-07-16 15:54:59 +00:00
|
|
|
|
apdu_prepare_exit ();
|
2004-02-18 17:00:11 +00:00
|
|
|
|
#if 0
|
2003-08-05 17:11:04 +00:00
|
|
|
|
#warning no update_random_seed_file
|
|
|
|
|
update_random_seed_file();
|
2004-02-18 17:00:11 +00:00
|
|
|
|
#endif
|
2003-08-05 17:11:04 +00:00
|
|
|
|
#if 0
|
|
|
|
|
/* at this time a bit annoying */
|
|
|
|
|
if (opt.debug & DBG_MEMSTAT_VALUE)
|
|
|
|
|
{
|
|
|
|
|
gcry_control( GCRYCTL_DUMP_MEMORY_STATS );
|
|
|
|
|
gcry_control( GCRYCTL_DUMP_RANDOM_STATS );
|
|
|
|
|
}
|
|
|
|
|
if (opt.debug)
|
|
|
|
|
gcry_control (GCRYCTL_DUMP_SECMEM_STATS );
|
|
|
|
|
#endif
|
|
|
|
|
gcry_control (GCRYCTL_TERM_SECMEM );
|
|
|
|
|
rc = rc? rc : log_get_errorcount(0)? 2 : 0;
|
|
|
|
|
exit (rc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-20 16:49:41 +00:00
|
|
|
|
static void
|
2005-05-18 10:48:06 +00:00
|
|
|
|
scd_init_default_ctrl (ctrl_t ctrl)
|
2003-08-05 17:11:04 +00:00
|
|
|
|
{
|
2011-12-13 16:55:42 +01:00
|
|
|
|
(void)ctrl;
|
2004-04-20 14:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-11-20 16:49:41 +00:00
|
|
|
|
static void
|
|
|
|
|
scd_deinit_default_ctrl (ctrl_t ctrl)
|
|
|
|
|
{
|
2009-10-28 12:02:15 +00:00
|
|
|
|
if (!ctrl)
|
|
|
|
|
return;
|
|
|
|
|
xfree (ctrl->in_data.value);
|
|
|
|
|
ctrl->in_data.value = NULL;
|
|
|
|
|
ctrl->in_data.valuelen = 0;
|
2006-11-20 16:49:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-04-20 14:17:10 +00:00
|
|
|
|
|
2005-05-18 10:48:06 +00:00
|
|
|
|
/* Return the name of the socket to be used to connect to this
|
|
|
|
|
process. If no socket is available, return NULL. */
|
|
|
|
|
const char *
|
|
|
|
|
scd_get_socket_name ()
|
|
|
|
|
{
|
|
|
|
|
if (socket_name && *socket_name)
|
|
|
|
|
return socket_name;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-20 14:17:10 +00:00
|
|
|
|
|
2014-03-07 09:46:44 +01:00
|
|
|
|
#ifndef HAVE_W32_SYSTEM
|
2004-04-20 14:17:10 +00:00
|
|
|
|
static void
|
|
|
|
|
handle_signal (int signo)
|
|
|
|
|
{
|
|
|
|
|
switch (signo)
|
|
|
|
|
{
|
|
|
|
|
case SIGHUP:
|
|
|
|
|
log_info ("SIGHUP received - "
|
|
|
|
|
"re-reading configuration and resetting cards\n");
|
|
|
|
|
/* reread_configuration (); */
|
|
|
|
|
break;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2004-04-20 14:17:10 +00:00
|
|
|
|
case SIGUSR1:
|
2005-05-21 18:49:00 +00:00
|
|
|
|
log_info ("SIGUSR1 received - printing internal information:\n");
|
2010-03-11 12:34:11 +00:00
|
|
|
|
/* Fixme: We need to see how to integrate pth dumping into our
|
|
|
|
|
logging system. */
|
|
|
|
|
/* pth_ctrl (PTH_CTRL_DUMPSTATE, log_get_stream ()); */
|
2005-06-03 13:57:24 +00:00
|
|
|
|
app_dump_state ();
|
2004-04-20 14:17:10 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SIGUSR2:
|
2004-04-21 14:44:09 +00:00
|
|
|
|
log_info ("SIGUSR2 received - no action defined\n");
|
2004-04-20 14:17:10 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2017-03-03 20:30:56 +09:00
|
|
|
|
case SIGCONT:
|
|
|
|
|
/* Nothing. */
|
2017-11-21 11:52:54 +09:00
|
|
|
|
log_debug ("SIGCONT received - breaking select\n");
|
2017-03-03 20:30:56 +09:00
|
|
|
|
break;
|
|
|
|
|
|
2004-04-20 14:17:10 +00:00
|
|
|
|
case SIGTERM:
|
|
|
|
|
if (!shutdown_pending)
|
|
|
|
|
log_info ("SIGTERM received - shutting down ...\n");
|
|
|
|
|
else
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
log_info ("SIGTERM received - still %i running threads\n",
|
|
|
|
|
active_connections);
|
2004-04-20 14:17:10 +00:00
|
|
|
|
shutdown_pending++;
|
|
|
|
|
if (shutdown_pending > 2)
|
|
|
|
|
{
|
|
|
|
|
log_info ("shutdown forced\n");
|
|
|
|
|
log_info ("%s %s stopped\n", strusage(11), strusage(13) );
|
|
|
|
|
cleanup ();
|
|
|
|
|
scd_exit (0);
|
2017-01-28 00:18:11 +09:00
|
|
|
|
}
|
2004-04-20 14:17:10 +00:00
|
|
|
|
break;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2004-04-20 14:17:10 +00:00
|
|
|
|
case SIGINT:
|
|
|
|
|
log_info ("SIGINT received - immediate shutdown\n");
|
|
|
|
|
log_info( "%s %s stopped\n", strusage(11), strusage(13));
|
|
|
|
|
cleanup ();
|
|
|
|
|
scd_exit (0);
|
|
|
|
|
break;
|
2003-08-05 17:11:04 +00:00
|
|
|
|
|
2004-04-20 14:17:10 +00:00
|
|
|
|
default:
|
|
|
|
|
log_info ("signal %d received - no action defined\n", signo);
|
|
|
|
|
}
|
2003-08-05 17:11:04 +00:00
|
|
|
|
}
|
2014-03-07 09:46:44 +01:00
|
|
|
|
#endif /*!HAVE_W32_SYSTEM*/
|
2003-08-05 17:11:04 +00:00
|
|
|
|
|
2005-05-18 10:48:06 +00:00
|
|
|
|
|
2014-10-03 11:58:58 +02:00
|
|
|
|
/* Create a name for the socket. We check for valid characters as
|
|
|
|
|
well as against a maximum allowed length for a unix domain socket
|
|
|
|
|
is done. The function terminates the process in case of an error.
|
2018-10-24 15:56:18 -04:00
|
|
|
|
Returns: Pointer to an allcoated string with the absolute name of
|
2014-10-03 11:58:58 +02:00
|
|
|
|
the socket used. */
|
2005-05-18 10:48:06 +00:00
|
|
|
|
static char *
|
2014-10-03 11:58:58 +02:00
|
|
|
|
create_socket_name (char *standard_name)
|
2005-05-18 10:48:06 +00:00
|
|
|
|
{
|
2014-10-03 11:58:58 +02:00
|
|
|
|
char *name;
|
2005-05-18 10:48:06 +00:00
|
|
|
|
|
2016-06-07 13:48:46 +02:00
|
|
|
|
name = make_filename (gnupg_socketdir (), standard_name, NULL);
|
2005-05-18 10:48:06 +00:00
|
|
|
|
if (strchr (name, PATHSEP_C))
|
|
|
|
|
{
|
2012-06-05 19:29:22 +02:00
|
|
|
|
log_error (("'%s' are not allowed in the socket name\n"), PATHSEP_S);
|
2005-05-18 10:48:06 +00:00
|
|
|
|
scd_exit (2);
|
|
|
|
|
}
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-03 11:58:58 +02:00
|
|
|
|
/* Create a Unix domain socket with NAME. Returns the file descriptor
|
2014-12-01 10:45:06 +01:00
|
|
|
|
or terminates the process in case of an error. If the socket has
|
|
|
|
|
been redirected the name of the real socket is stored as a malloced
|
|
|
|
|
string at R_REDIR_NAME. */
|
2007-10-01 14:48:39 +00:00
|
|
|
|
static gnupg_fd_t
|
2014-12-01 10:45:06 +01:00
|
|
|
|
create_server_socket (const char *name, char **r_redir_name,
|
|
|
|
|
assuan_sock_nonce_t *nonce)
|
2005-05-18 10:48:06 +00:00
|
|
|
|
{
|
2014-12-01 10:45:06 +01:00
|
|
|
|
struct sockaddr *addr;
|
|
|
|
|
struct sockaddr_un *unaddr;
|
2005-05-18 10:48:06 +00:00
|
|
|
|
socklen_t len;
|
2007-10-01 14:48:39 +00:00
|
|
|
|
gnupg_fd_t fd;
|
2005-05-18 10:48:06 +00:00
|
|
|
|
int rc;
|
|
|
|
|
|
2014-12-01 10:45:06 +01:00
|
|
|
|
xfree (*r_redir_name);
|
|
|
|
|
*r_redir_name = NULL;
|
|
|
|
|
|
2007-10-01 14:48:39 +00:00
|
|
|
|
fd = assuan_sock_new (AF_UNIX, SOCK_STREAM, 0);
|
|
|
|
|
if (fd == GNUPG_INVALID_FD)
|
2005-05-18 10:48:06 +00:00
|
|
|
|
{
|
|
|
|
|
log_error (_("can't create socket: %s\n"), strerror (errno));
|
|
|
|
|
scd_exit (2);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-01 10:45:06 +01:00
|
|
|
|
unaddr = xmalloc (sizeof (*unaddr));
|
|
|
|
|
addr = (struct sockaddr*)unaddr;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
int redirected;
|
|
|
|
|
|
|
|
|
|
if (assuan_sock_set_sockaddr_un (name, addr, &redirected))
|
|
|
|
|
{
|
|
|
|
|
if (errno == ENAMETOOLONG)
|
|
|
|
|
log_error (_("socket name '%s' is too long\n"), name);
|
|
|
|
|
else
|
|
|
|
|
log_error ("error preparing socket '%s': %s\n",
|
|
|
|
|
name, gpg_strerror (gpg_error_from_syserror ()));
|
|
|
|
|
scd_exit (2);
|
|
|
|
|
}
|
|
|
|
|
if (redirected)
|
|
|
|
|
{
|
|
|
|
|
*r_redir_name = xstrdup (unaddr->sun_path);
|
|
|
|
|
if (opt.verbose)
|
|
|
|
|
log_info ("redirecting socket '%s' to '%s'\n", name, *r_redir_name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
len = SUN_LEN (unaddr);
|
2005-05-18 10:48:06 +00:00
|
|
|
|
|
2014-12-01 10:45:06 +01:00
|
|
|
|
rc = assuan_sock_bind (fd, addr, len);
|
2014-10-03 11:58:58 +02:00
|
|
|
|
if (rc == -1 && errno == EADDRINUSE)
|
2005-05-18 10:48:06 +00:00
|
|
|
|
{
|
2014-12-01 10:45:06 +01:00
|
|
|
|
gnupg_remove (unaddr->sun_path);
|
|
|
|
|
rc = assuan_sock_bind (fd, addr, len);
|
2005-05-18 10:48:06 +00:00
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
if (rc != -1
|
2014-12-01 10:45:06 +01:00
|
|
|
|
&& (rc=assuan_sock_get_nonce (addr, len, nonce)))
|
2007-10-01 14:48:39 +00:00
|
|
|
|
log_error (_("error getting nonce for the socket\n"));
|
|
|
|
|
if (rc == -1)
|
2005-05-18 10:48:06 +00:00
|
|
|
|
{
|
2012-06-05 19:29:22 +02:00
|
|
|
|
log_error (_("error binding socket to '%s': %s\n"),
|
2017-01-28 00:18:11 +09:00
|
|
|
|
unaddr->sun_path,
|
2007-11-19 16:03:50 +00:00
|
|
|
|
gpg_strerror (gpg_error_from_syserror ()));
|
2007-10-01 14:48:39 +00:00
|
|
|
|
assuan_sock_close (fd);
|
2005-05-18 10:48:06 +00:00
|
|
|
|
scd_exit (2);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-08 16:18:02 +02:00
|
|
|
|
if (gnupg_chmod (unaddr->sun_path, "-rwx"))
|
|
|
|
|
log_error (_("can't set permissions of '%s': %s\n"),
|
|
|
|
|
unaddr->sun_path, strerror (errno));
|
|
|
|
|
|
2017-12-12 14:14:40 +01:00
|
|
|
|
if (listen (FD2INT(fd), listen_backlog) == -1)
|
2005-05-18 10:48:06 +00:00
|
|
|
|
{
|
2017-12-12 14:14:40 +01:00
|
|
|
|
log_error ("listen(fd, %d) failed: %s\n",
|
|
|
|
|
listen_backlog, gpg_strerror (gpg_error_from_syserror ()));
|
2007-10-01 14:48:39 +00:00
|
|
|
|
assuan_sock_close (fd);
|
2005-05-18 10:48:06 +00:00
|
|
|
|
scd_exit (2);
|
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2005-05-18 10:48:06 +00:00
|
|
|
|
if (opt.verbose)
|
2014-12-01 10:45:06 +01:00
|
|
|
|
log_info (_("listening on socket '%s'\n"), unaddr->sun_path);
|
2005-05-18 10:48:06 +00:00
|
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* This is the standard connection thread's main function. */
|
2004-04-20 14:17:10 +00:00
|
|
|
|
static void *
|
2005-05-18 10:48:06 +00:00
|
|
|
|
start_connection_thread (void *arg)
|
2004-04-20 14:17:10 +00:00
|
|
|
|
{
|
2006-11-20 16:49:41 +00:00
|
|
|
|
ctrl_t ctrl = arg;
|
2005-05-18 10:48:06 +00:00
|
|
|
|
|
2007-11-19 16:03:50 +00:00
|
|
|
|
if (ctrl->thread_startup.fd != GNUPG_INVALID_FD
|
|
|
|
|
&& assuan_sock_check_nonce (ctrl->thread_startup.fd, &socket_nonce))
|
2007-10-01 14:48:39 +00:00
|
|
|
|
{
|
2011-02-04 12:57:53 +01:00
|
|
|
|
log_info (_("error reading nonce on fd %d: %s\n"),
|
2007-10-01 14:48:39 +00:00
|
|
|
|
FD2INT(ctrl->thread_startup.fd), strerror (errno));
|
|
|
|
|
assuan_sock_close (ctrl->thread_startup.fd);
|
|
|
|
|
xfree (ctrl);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-01 08:58:01 +09:00
|
|
|
|
active_connections++;
|
|
|
|
|
|
2006-11-20 16:49:41 +00:00
|
|
|
|
scd_init_default_ctrl (ctrl);
|
2005-05-18 10:48:06 +00:00
|
|
|
|
if (opt.verbose)
|
2007-10-01 14:48:39 +00:00
|
|
|
|
log_info (_("handler for fd %d started\n"),
|
|
|
|
|
FD2INT(ctrl->thread_startup.fd));
|
2005-05-18 10:48:06 +00:00
|
|
|
|
|
2008-10-15 13:23:10 +00:00
|
|
|
|
/* If this is a pipe server, we request a shutdown if the command
|
2009-02-19 16:19:16 +00:00
|
|
|
|
handler asked for it. With the next ticker event and given that
|
2008-10-15 13:23:10 +00:00
|
|
|
|
no other connections are running the shutdown will then
|
|
|
|
|
happen. */
|
|
|
|
|
if (scd_command_handler (ctrl, FD2INT(ctrl->thread_startup.fd))
|
|
|
|
|
&& pipe_server)
|
|
|
|
|
shutdown_pending = 1;
|
2005-05-18 10:48:06 +00:00
|
|
|
|
|
|
|
|
|
if (opt.verbose)
|
2007-10-01 14:48:39 +00:00
|
|
|
|
log_info (_("handler for fd %d terminated\n"),
|
|
|
|
|
FD2INT (ctrl->thread_startup.fd));
|
2005-05-18 10:48:06 +00:00
|
|
|
|
|
2006-11-20 16:49:41 +00:00
|
|
|
|
scd_deinit_default_ctrl (ctrl);
|
|
|
|
|
xfree (ctrl);
|
2017-02-01 08:58:01 +09:00
|
|
|
|
|
|
|
|
|
if (--active_connections == 0)
|
|
|
|
|
scd_kick_the_loop ();
|
|
|
|
|
|
2005-05-18 10:48:06 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-01-28 00:18:11 +09:00
|
|
|
|
void
|
|
|
|
|
scd_kick_the_loop (void)
|
|
|
|
|
{
|
2017-01-27 14:34:21 +09:00
|
|
|
|
/* Kick the select loop. */
|
2017-03-03 20:30:56 +09:00
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
2018-03-13 12:05:57 +09:00
|
|
|
|
int ret = SetEvent (the_event);
|
2017-03-03 20:30:56 +09:00
|
|
|
|
if (ret == 0)
|
|
|
|
|
log_error ("SetEvent for scd_kick_the_loop failed: %s\n",
|
|
|
|
|
w32_strerror (-1));
|
2018-02-07 12:43:07 +09:00
|
|
|
|
#elif defined(HAVE_PSELECT_NO_EINTR)
|
|
|
|
|
write (notify_fd, "", 1);
|
2017-03-03 20:30:56 +09:00
|
|
|
|
#else
|
2018-03-13 12:05:57 +09:00
|
|
|
|
int ret = kill (main_thread_pid, SIGCONT);
|
2017-03-03 20:30:56 +09:00
|
|
|
|
if (ret < 0)
|
|
|
|
|
log_error ("SetEvent for scd_kick_the_loop failed: %s\n",
|
|
|
|
|
gpg_strerror (gpg_error_from_syserror ()));
|
|
|
|
|
#endif
|
2017-01-26 22:02:41 +09:00
|
|
|
|
}
|
|
|
|
|
|
2005-05-18 10:48:06 +00:00
|
|
|
|
/* Connection handler loop. Wait for connection requests and spawn a
|
|
|
|
|
thread after accepting a connection. LISTEN_FD is allowed to be -1
|
|
|
|
|
in which case this code will only do regular timeouts and handle
|
|
|
|
|
signals. */
|
|
|
|
|
static void
|
2017-01-28 00:18:11 +09:00
|
|
|
|
handle_connections (int listen_fd)
|
2005-05-18 10:48:06 +00:00
|
|
|
|
{
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
npth_attr_t tattr;
|
2005-05-18 10:48:06 +00:00
|
|
|
|
struct sockaddr_un paddr;
|
|
|
|
|
socklen_t plen;
|
2017-01-28 00:18:11 +09:00
|
|
|
|
fd_set fdset, read_fdset;
|
|
|
|
|
int nfd;
|
2005-05-18 10:48:06 +00:00
|
|
|
|
int ret;
|
|
|
|
|
int fd;
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
struct timespec timeout;
|
2017-01-26 22:02:41 +09:00
|
|
|
|
struct timespec *t;
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
int saved_errno;
|
2017-03-03 20:30:56 +09:00
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
|
HANDLE events[2];
|
|
|
|
|
unsigned int events_set;
|
|
|
|
|
#else
|
2014-03-07 09:46:44 +01:00
|
|
|
|
int signo;
|
|
|
|
|
#endif
|
2018-02-07 12:43:07 +09:00
|
|
|
|
#ifdef HAVE_PSELECT_NO_EINTR
|
|
|
|
|
int pipe_fd[2];
|
|
|
|
|
|
|
|
|
|
ret = gnupg_create_pipe (pipe_fd);
|
|
|
|
|
if (ret)
|
|
|
|
|
{
|
|
|
|
|
log_error ("pipe creation failed: %s\n", gpg_strerror (ret));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
notify_fd = pipe_fd[1];
|
|
|
|
|
#endif
|
2005-05-18 10:48:06 +00:00
|
|
|
|
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
ret = npth_attr_init(&tattr);
|
2017-01-27 14:34:21 +09:00
|
|
|
|
if (ret)
|
|
|
|
|
{
|
|
|
|
|
log_error ("npth_attr_init failed: %s\n", strerror (ret));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
npth_attr_setdetachstate (&tattr, NPTH_CREATE_DETACHED);
|
|
|
|
|
|
2017-03-03 20:30:56 +09:00
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
|
{
|
|
|
|
|
HANDLE h, h2;
|
|
|
|
|
SECURITY_ATTRIBUTES sa = { sizeof (SECURITY_ATTRIBUTES), NULL, TRUE};
|
|
|
|
|
|
|
|
|
|
events[0] = the_event = INVALID_HANDLE_VALUE;
|
|
|
|
|
events[1] = INVALID_HANDLE_VALUE;
|
|
|
|
|
h = CreateEvent (&sa, TRUE, FALSE, NULL);
|
|
|
|
|
if (!h)
|
|
|
|
|
log_error ("can't create scd event: %s\n", w32_strerror (-1) );
|
|
|
|
|
else if (!DuplicateHandle (GetCurrentProcess(), h,
|
|
|
|
|
GetCurrentProcess(), &h2,
|
|
|
|
|
EVENT_MODIFY_STATE|SYNCHRONIZE, TRUE, 0))
|
|
|
|
|
{
|
|
|
|
|
log_error ("setting synchronize for scd_kick_the_loop failed: %s\n",
|
|
|
|
|
w32_strerror (-1) );
|
|
|
|
|
CloseHandle (h);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CloseHandle (h);
|
|
|
|
|
events[0] = the_event = h2;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-12-15 14:15:54 +00:00
|
|
|
|
#endif
|
2005-05-18 10:48:06 +00:00
|
|
|
|
|
|
|
|
|
FD_ZERO (&fdset);
|
2007-07-04 09:34:28 +00:00
|
|
|
|
nfd = 0;
|
2005-05-18 10:48:06 +00:00
|
|
|
|
if (listen_fd != -1)
|
2007-07-04 09:34:28 +00:00
|
|
|
|
{
|
|
|
|
|
FD_SET (listen_fd, &fdset);
|
|
|
|
|
nfd = listen_fd;
|
|
|
|
|
}
|
2005-05-18 10:48:06 +00:00
|
|
|
|
|
|
|
|
|
for (;;)
|
2004-04-20 14:17:10 +00:00
|
|
|
|
{
|
2017-01-31 15:29:08 +09:00
|
|
|
|
int periodical_check;
|
2018-02-07 12:43:07 +09:00
|
|
|
|
int max_fd = nfd;
|
2017-01-31 15:29:08 +09:00
|
|
|
|
|
2005-05-18 10:48:06 +00:00
|
|
|
|
if (shutdown_pending)
|
2004-04-20 14:17:10 +00:00
|
|
|
|
{
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
if (active_connections == 0)
|
2005-05-18 10:48:06 +00:00
|
|
|
|
break; /* ready */
|
|
|
|
|
|
|
|
|
|
/* Do not accept anymore connections but wait for existing
|
|
|
|
|
connections to terminate. We do this by clearing out all
|
|
|
|
|
file descriptors to wait for, so that the select will be
|
|
|
|
|
used to just wait on a signal or timeout event. */
|
|
|
|
|
FD_ZERO (&fdset);
|
2008-10-15 13:23:10 +00:00
|
|
|
|
listen_fd = -1;
|
2017-01-26 22:02:41 +09:00
|
|
|
|
}
|
2004-04-20 14:17:10 +00:00
|
|
|
|
|
2017-01-31 15:29:08 +09:00
|
|
|
|
periodical_check = scd_update_reader_status_file ();
|
2017-01-31 12:56:11 +09:00
|
|
|
|
|
|
|
|
|
timeout.tv_sec = TIMERTICK_INTERVAL_SEC;
|
|
|
|
|
timeout.tv_nsec = TIMERTICK_INTERVAL_USEC * 1000;
|
|
|
|
|
|
2017-01-31 15:29:08 +09:00
|
|
|
|
if (shutdown_pending || periodical_check)
|
2017-01-31 12:56:11 +09:00
|
|
|
|
t = &timeout;
|
2017-01-26 22:02:41 +09:00
|
|
|
|
else
|
|
|
|
|
t = NULL;
|
|
|
|
|
|
2005-05-18 10:48:06 +00:00
|
|
|
|
/* POSIX says that fd_set should be implemented as a structure,
|
|
|
|
|
thus a simple assignment is fine to copy the entire set. */
|
|
|
|
|
read_fdset = fdset;
|
|
|
|
|
|
2018-02-07 12:43:07 +09:00
|
|
|
|
#ifdef HAVE_PSELECT_NO_EINTR
|
|
|
|
|
FD_SET (pipe_fd[0], &read_fdset);
|
|
|
|
|
if (max_fd < pipe_fd[0])
|
|
|
|
|
max_fd = pipe_fd[0];
|
2018-03-08 16:51:51 +09:00
|
|
|
|
#else
|
|
|
|
|
(void)max_fd;
|
2018-02-07 12:43:07 +09:00
|
|
|
|
#endif
|
|
|
|
|
|
2012-01-19 22:27:44 +01:00
|
|
|
|
#ifndef HAVE_W32_SYSTEM
|
2018-02-07 12:43:07 +09:00
|
|
|
|
ret = npth_pselect (max_fd+1, &read_fdset, NULL, NULL, t,
|
2017-01-27 14:34:21 +09:00
|
|
|
|
npth_sigev_sigmask ());
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
saved_errno = errno;
|
|
|
|
|
|
|
|
|
|
while (npth_sigev_get_pending(&signo))
|
2017-01-26 22:02:41 +09:00
|
|
|
|
handle_signal (signo);
|
2012-01-19 22:27:44 +01:00
|
|
|
|
#else
|
2017-03-03 20:30:56 +09:00
|
|
|
|
ret = npth_eselect (nfd+1, &read_fdset, NULL, NULL, t,
|
|
|
|
|
events, &events_set);
|
2012-01-19 22:27:44 +01:00
|
|
|
|
saved_errno = errno;
|
2017-03-03 20:30:56 +09:00
|
|
|
|
if (events_set & 1)
|
|
|
|
|
continue;
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
#endif
|
2005-05-18 10:48:06 +00:00
|
|
|
|
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
if (ret == -1 && saved_errno != EINTR)
|
2017-01-26 22:02:41 +09:00
|
|
|
|
{
|
2012-01-19 22:27:44 +01:00
|
|
|
|
log_error (_("npth_pselect failed: %s - waiting 1s\n"),
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
strerror (saved_errno));
|
|
|
|
|
npth_sleep (1);
|
2017-01-26 22:02:41 +09:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2004-04-20 14:17:10 +00:00
|
|
|
|
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
if (ret <= 0)
|
2017-01-26 22:02:41 +09:00
|
|
|
|
/* Timeout. Will be handled when calculating the next timeout. */
|
|
|
|
|
continue;
|
2005-06-03 13:57:24 +00:00
|
|
|
|
|
2018-02-07 12:43:07 +09:00
|
|
|
|
#ifdef HAVE_PSELECT_NO_EINTR
|
|
|
|
|
if (FD_ISSET (pipe_fd[0], &read_fdset))
|
|
|
|
|
{
|
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
|
|
read (pipe_fd[0], buf, sizeof buf);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-05-18 10:48:06 +00:00
|
|
|
|
if (listen_fd != -1 && FD_ISSET (listen_fd, &read_fdset))
|
2017-01-26 22:02:41 +09:00
|
|
|
|
{
|
2006-11-20 16:49:41 +00:00
|
|
|
|
ctrl_t ctrl;
|
|
|
|
|
|
2005-05-18 10:48:06 +00:00
|
|
|
|
plen = sizeof paddr;
|
2017-01-26 22:02:41 +09:00
|
|
|
|
fd = npth_accept (listen_fd, (struct sockaddr *)&paddr, &plen);
|
|
|
|
|
if (fd == -1)
|
|
|
|
|
{
|
|
|
|
|
log_error ("accept failed: %s\n", strerror (errno));
|
|
|
|
|
}
|
2006-11-20 16:49:41 +00:00
|
|
|
|
else if ( !(ctrl = xtrycalloc (1, sizeof *ctrl)) )
|
|
|
|
|
{
|
|
|
|
|
log_error ("error allocating connection control data: %s\n",
|
|
|
|
|
strerror (errno) );
|
|
|
|
|
close (fd);
|
|
|
|
|
}
|
2005-06-03 13:57:24 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
char threadname[50];
|
2017-01-26 22:02:41 +09:00
|
|
|
|
npth_t thread;
|
2006-11-20 16:49:41 +00:00
|
|
|
|
|
Fix use cases of snprintf.
* agent/call-pinentry.c, agent/call-scd.c, agent/command.c,
build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c,
dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c,
g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c,
sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-10-21 12:04:46 +09:00
|
|
|
|
snprintf (threadname, sizeof threadname, "conn fd=%d", fd);
|
2007-10-01 14:48:39 +00:00
|
|
|
|
ctrl->thread_startup.fd = INT2FD (fd);
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
ret = npth_create (&thread, &tattr, start_connection_thread, ctrl);
|
2017-01-26 22:02:41 +09:00
|
|
|
|
if (ret)
|
2005-06-03 13:57:24 +00:00
|
|
|
|
{
|
|
|
|
|
log_error ("error spawning connection handler: %s\n",
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
strerror (ret));
|
2006-11-20 16:49:41 +00:00
|
|
|
|
xfree (ctrl);
|
2005-06-03 13:57:24 +00:00
|
|
|
|
close (fd);
|
|
|
|
|
}
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
else
|
2017-01-26 22:02:41 +09:00
|
|
|
|
npth_setname_np (thread, threadname);
|
2005-06-03 13:57:24 +00:00
|
|
|
|
}
|
2017-01-26 22:02:41 +09:00
|
|
|
|
}
|
2004-04-20 14:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 10:19:40 +09:00
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
|
if (the_event != INVALID_HANDLE_VALUE)
|
|
|
|
|
CloseHandle (the_event);
|
2018-02-07 12:43:07 +09:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAVE_PSELECT_NO_EINTR
|
|
|
|
|
close (pipe_fd[0]);
|
|
|
|
|
close (pipe_fd[1]);
|
2017-03-07 10:19:40 +09:00
|
|
|
|
#endif
|
2005-05-18 10:48:06 +00:00
|
|
|
|
cleanup ();
|
|
|
|
|
log_info (_("%s %s stopped\n"), strusage(11), strusage(13));
|
Port to npth.
* configure.ac: Don't check for PTH but for NPTH.
(AH_BOTTOM): Remove PTH_SYSCALL_SOFT.
(have_pth): Rename to ...
(have_npth): ... this.
(USE_GNU_NPTH): Rename to ...
(USE_GNU_PTH): ... this.
* m4/npth.m4: New file.
* agent/Makefile.am, agent/cache.c, agent/call-pinentry.c,
agent/call-scd.c, agent/findkey.c, agent/gpg-agent.c,
agent/trustlist.c, common/Makefile.am, common/estream.c,
common/exechelp-posix.c, common/exechelp-w32.c,
common/exechelp-w32ce.c, common/http.c, common/init.c,
common/sysutils.c, dirmngr/Makefile.am, dirmngr/crlfetch.c,
dirmngr/dirmngr.c, dirmngr/dirmngr_ldap.c, dirmngr/ldap-wrapper-ce.c,
dirmngr/ldap-wrapper.c, dirmngr/ldap.c, g13/Makefile.am,
g13/call-gpg.c, g13/g13.c, g13/runner.c, scd/Makefile.am,
scd/apdu.c, scd/app.c, scd/ccid-driver.c, scd/command.c,
scd/scdaemon.c, tools/Makefile.am: Port to npth.
2012-01-03 22:12:37 +01:00
|
|
|
|
npth_attr_destroy (&tattr);
|
2004-04-20 14:17:10 +00:00
|
|
|
|
}
|
2017-02-01 08:58:01 +09:00
|
|
|
|
|
|
|
|
|
/* Return the number of active connections. */
|
|
|
|
|
int
|
|
|
|
|
get_active_connection_count (void)
|
|
|
|
|
{
|
|
|
|
|
return active_connections;
|
|
|
|
|
}
|