From 62039d815eef5a699cb7d78a36a0a5e9eb5910c8 Mon Sep 17 00:00:00 2001 From: Moritz Schulte Date: Thu, 16 Aug 2007 12:44:17 +0000 Subject: Implemented the STATUSFD mechanism. 2007-08-16 Moritz Schulte * command.c: Include "statusfd.h". (cmd_statusfd): New function. (register_commands): New entry for STATUSFD command. (update_reader_status_file): Call statusfd_event_card_inserted and statusfd_event_card_removed on events. (scd_command_handler): Pass flags=3 to assuan_init_socket_server_ext (enabling fd passing). * statusfd.c, statusfd.h: New files. * Makefile.am (scdaemon_SOURCES): Added statusfd.c, statusfd.h. * NOTES-STATUSFD: New file. --- scd/command.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'scd/command.c') diff --git a/scd/command.c b/scd/command.c index e65262d06..2ac0abe71 100644 --- a/scd/command.c +++ b/scd/command.c @@ -40,6 +40,7 @@ #ifdef HAVE_LIBUSB #include "ccid-driver.h" #endif +#include "statusfd.h" /* Maximum length allowed as a PIN; used for INQUIRE NEEDPIN */ #define MAXLEN_PIN 100 @@ -1649,6 +1650,34 @@ cmd_apdu (assuan_context_t ctx, char *line) return rc; } +/* STATUSFD + */ +static int +cmd_statusfd (assuan_context_t ctx, char *line) +{ + ctrl_t ctrl = assuan_get_pointer (ctx); + int rc; + int fd; + + /* FIXME, moritz, locking? */ + if ( IS_LOCKED (ctrl) ) + return gpg_error (GPG_ERR_LOCKED); + + rc = assuan_receivefd (ctx, &fd); + if (rc) + /* FIXME, moritz, proper error message for client? */ + goto leave; + + rc = statusfd_register (fd); + + leave: + + if (rc) + close (fd); + + return rc; +} + @@ -1683,6 +1712,7 @@ register_commands (assuan_context_t ctx) { "GETINFO", cmd_getinfo }, { "RESTART", cmd_restart }, { "APDU", cmd_apdu }, + { "STATUSFD", cmd_statusfd }, { NULL } }; int i, rc; @@ -1719,7 +1749,7 @@ scd_command_handler (ctrl_t ctrl, int fd) } else { - rc = assuan_init_socket_server_ext (&ctx, fd, 2); + rc = assuan_init_socket_server_ext (&ctx, fd, 3); } if (rc) { @@ -1880,6 +1910,15 @@ update_reader_status_file (void) log_info ("updating status of slot %d to 0x%04X\n", ss->slot, status); + { + /* Broadcast on statusfds. */ + + if ((! (ss->status & 2)) && (status & 2)) + statusfd_event_card_inserted (0); + if ((ss->status & 2) && (! (status & 2))) + statusfd_event_card_removed (0); + } + /* FIXME: Should this be IDX instead of ss->slot? This depends on how client sessions will associate the reader status with their session. */ -- cgit v1.2.3