aboutsummaryrefslogtreecommitdiffstats
path: root/scd
diff options
context:
space:
mode:
Diffstat (limited to 'scd')
-rw-r--r--scd/app.c21
-rw-r--r--scd/command.c44
-rw-r--r--scd/scdaemon.c20
3 files changed, 51 insertions, 34 deletions
diff --git a/scd/app.c b/scd/app.c
index 2c92201cf..a9591a12c 100644
--- a/scd/app.c
+++ b/scd/app.c
@@ -2385,6 +2385,18 @@ app_check_pin (card_t card, ctrl_t ctrl, const char *keyidstr,
static void
+setup_env (struct spawn_cb_arg *sca)
+{
+#ifdef HAVE_W32_SYSTEM
+ (void)sca; /* Not supported on Windows. */
+#else
+ char *v = sca->arg;
+
+ putenv (v);
+#endif
+}
+
+static void
report_change (int slot, int old_status, int cur_status)
{
char *homestr, *envstr;
@@ -2411,12 +2423,9 @@ report_change (int slot, int old_status, int cur_status)
else
{
gpg_error_t err;
- const char *args[9], *envs[2];
+ const char *args[9];
char numbuf1[30], numbuf2[30], numbuf3[30];
- envs[0] = envstr;
- envs[1] = NULL;
-
sprintf (numbuf1, "%d", slot);
sprintf (numbuf2, "0x%04X", old_status);
sprintf (numbuf3, "0x%04X", cur_status);
@@ -2433,7 +2442,9 @@ report_change (int slot, int old_status, int cur_status)
args[8] = NULL;
fname = make_filename (gnupg_homedir (), "scd-event", NULL);
- err = gnupg_spawn_process_detached (fname, args, envs);
+ err = gnupg_process_spawn (fname, args,
+ GNUPG_PROCESS_DETACHED,
+ setup_env, envstr, NULL);
if (err && gpg_err_code (err) != GPG_ERR_ENOENT)
log_error ("failed to run event handler '%s': %s\n",
fname, gpg_strerror (err));
diff --git a/scd/command.c b/scd/command.c
index 0cf66d08c..a2274f15a 100644
--- a/scd/command.c
+++ b/scd/command.c
@@ -957,7 +957,8 @@ pin_cb (void *opaque, const char *info, char **retstr)
We ignore any value returned. */
if (info)
{
- log_debug ("prompting for pinpad entry '%s'\n", info);
+ if (DBG_IPC)
+ log_debug ("prompting for pinpad entry '%s'\n", info);
rc = gpgrt_asprintf (&command, "POPUPPINPADPROMPT %s", info);
if (rc < 0)
return gpg_error (gpg_err_code_from_errno (errno));
@@ -966,7 +967,8 @@ pin_cb (void *opaque, const char *info, char **retstr)
}
else
{
- log_debug ("dismiss pinpad entry prompt\n");
+ if (DBG_IPC)
+ log_debug ("dismiss pinpad entry prompt\n");
rc = assuan_inquire (ctx, "DISMISSPINPADPROMPT",
&value, &valuelen, MAXLEN_PIN);
}
@@ -976,7 +978,8 @@ pin_cb (void *opaque, const char *info, char **retstr)
}
*retstr = NULL;
- log_debug ("asking for PIN '%s'\n", info);
+ if (DBG_IPC)
+ log_debug ("asking for PIN '%s'\n", info);
rc = gpgrt_asprintf (&command, "NEEDPIN %s", info);
if (rc < 0)
@@ -2942,10 +2945,10 @@ void
send_client_notifications (card_t card, int removal)
{
struct {
- pid_t pid;
#ifdef HAVE_W32_SYSTEM
HANDLE handle;
#else
+ pid_t pid;
int signo;
#endif
} killed[50];
@@ -2965,10 +2968,10 @@ send_client_notifications (card_t card, int removal)
if (sl->ctrl_backlink && sl->ctrl_backlink->card_ctx == card)
{
- pid_t pid;
#ifdef HAVE_W32_SYSTEM
HANDLE handle;
#else
+ pid_t pid;
int signo;
#endif
@@ -2983,32 +2986,33 @@ send_client_notifications (card_t card, int removal)
if (!sl->event_signal || !sl->assuan_ctx)
continue;
- pid = assuan_get_pid (sl->assuan_ctx);
-
#ifdef HAVE_W32_SYSTEM
handle = sl->event_signal;
for (kidx=0; kidx < killidx; kidx++)
- if (killed[kidx].pid == pid
- && killed[kidx].handle == handle)
+ if (killed[kidx].handle == handle)
break;
if (kidx < killidx)
- log_info ("event %p (%p) already triggered for client %d\n",
- sl->event_signal, handle, (int)pid);
+ {
+ if (opt.verbose)
+ log_info ("event %p already triggered for client\n",
+ sl->event_signal);
+ }
else
{
- log_info ("triggering event %p (%p) for client %d\n",
- sl->event_signal, handle, (int)pid);
+ if (opt.verbose)
+ log_info ("triggering event %p for client\n",
+ sl->event_signal);
if (!SetEvent (handle))
log_error ("SetEvent(%p) failed: %s\n",
sl->event_signal, w32_strerror (-1));
if (killidx < DIM (killed))
{
- killed[killidx].pid = pid;
killed[killidx].handle = handle;
killidx++;
}
}
#else /*!HAVE_W32_SYSTEM*/
+ pid = assuan_get_pid (sl->assuan_ctx);
signo = sl->event_signal;
if (pid != (pid_t)(-1) && pid && signo > 0)
@@ -3018,12 +3022,16 @@ send_client_notifications (card_t card, int removal)
&& killed[kidx].signo == signo)
break;
if (kidx < killidx)
- log_info ("signal %d already sent to client %d\n",
- signo, (int)pid);
+ {
+ if (opt.verbose)
+ log_info ("signal %d already sent to client %d\n",
+ signo, (int)pid);
+ }
else
{
- log_info ("sending signal %d to client %d\n",
- signo, (int)pid);
+ if (opt.verbose)
+ log_info ("sending signal %d to client %d\n",
+ signo, (int)pid);
kill (pid, signo);
if (killidx < DIM (killed))
{
diff --git a/scd/scdaemon.c b/scd/scdaemon.c
index ed7fdc03a..e49b2ce42 100644
--- a/scd/scdaemon.c
+++ b/scd/scdaemon.c
@@ -274,9 +274,6 @@ static gnupg_fd_t create_server_socket (const char *name,
static void *start_connection_thread (void *arg);
static void handle_connections (gnupg_fd_t listen_fd);
-/* Pth wrapper function definitions. */
-ASSUAN_SYSTEM_NPTH_IMPL;
-
static int active_connections;
@@ -482,7 +479,6 @@ main (int argc, char **argv )
malloc_hooks.free = gcry_free;
assuan_set_malloc_hooks (&malloc_hooks);
assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
- assuan_set_system_hooks (ASSUAN_SYSTEM_NPTH);
assuan_sock_init ();
setup_libassuan_logging (&opt.debug, NULL);
@@ -763,6 +759,7 @@ main (int argc, char **argv )
npth_init ();
setup_signal_mask ();
gpgrt_set_syscall_clamp (npth_unprotect, npth_protect);
+ assuan_control (ASSUAN_CONTROL_REINIT_SYSCALL_CLAMP, NULL);
/* If --debug-allow-core-dump has been given we also need to
switch the working directory to a place where we can actually
@@ -904,6 +901,7 @@ main (int argc, char **argv )
npth_init ();
setup_signal_mask ();
gpgrt_set_syscall_clamp (npth_unprotect, npth_protect);
+ assuan_control (ASSUAN_CONTROL_REINIT_SYSCALL_CLAMP, NULL);
/* Detach from tty and put process into a new session. */
if (!nodetach )
@@ -1188,7 +1186,7 @@ start_connection_thread (void *arg)
&& assuan_sock_check_nonce (ctrl->thread_startup.fd, &socket_nonce))
{
log_info (_("error reading nonce on fd %d: %s\n"),
- FD2INT(ctrl->thread_startup.fd), strerror (errno));
+ FD_DBG (ctrl->thread_startup.fd), strerror (errno));
assuan_sock_close (ctrl->thread_startup.fd);
xfree (ctrl);
return NULL;
@@ -1199,7 +1197,7 @@ start_connection_thread (void *arg)
scd_init_default_ctrl (ctrl);
if (opt.verbose)
log_info (_("handler for fd %d started\n"),
- FD2INT(ctrl->thread_startup.fd));
+ FD_DBG (ctrl->thread_startup.fd));
/* If this is a pipe server, we request a shutdown if the command
handler asked for it. With the next ticker event and given that
@@ -1211,7 +1209,7 @@ start_connection_thread (void *arg)
if (opt.verbose)
log_info (_("handler for fd %d terminated\n"),
- FD2INT (ctrl->thread_startup.fd));
+ FD_DBG (ctrl->thread_startup.fd));
scd_deinit_default_ctrl (ctrl);
xfree (ctrl);
@@ -1318,7 +1316,7 @@ handle_connections (gnupg_fd_t listen_fd)
if (listen_fd != GNUPG_INVALID_FD)
{
FD_SET (FD2INT (listen_fd), &fdset);
- nfd = FD2INT (listen_fd);
+ nfd = FD2NUM (listen_fd);
}
for (;;)
@@ -1404,8 +1402,8 @@ handle_connections (gnupg_fd_t listen_fd)
gnupg_fd_t fd;
plen = sizeof paddr;
- fd = INT2FD (npth_accept (FD2INT (listen_fd),
- (struct sockaddr *)&paddr, &plen));
+ fd = assuan_sock_accept (listen_fd,
+ (struct sockaddr *)&paddr, &plen);
if (fd == GNUPG_INVALID_FD)
{
log_error ("accept failed: %s\n", strerror (errno));
@@ -1422,7 +1420,7 @@ handle_connections (gnupg_fd_t listen_fd)
npth_t thread;
snprintf (threadname, sizeof threadname, "conn fd=%d",
- FD2INT (fd));
+ FD_DBG (fd));
ctrl->thread_startup.fd = fd;
ret = npth_create (&thread, &tattr, start_connection_thread, ctrl);
if (ret)