From f54b85bc2d9b80f40ee025f74857fb3bb1436f9a Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 4 Jul 2007 09:34:28 +0000 Subject: [PATCH] A bunch of minor changes for Windows. --- ChangeLog | 4 ++ agent/ChangeLog | 22 +++++++++ agent/Makefile.am | 24 ++++------ agent/agent.h | 1 + agent/call-pinentry.c | 2 +- agent/command.c | 12 +++++ agent/gpg-agent.c | 59 +++++++++++++---------- configure.ac | 2 +- jnlib/ChangeLog | 6 +++ jnlib/argparse.c | 106 +++++++++++++++++++++++------------------- scd/ChangeLog | 9 ++++ scd/command.c | 9 +++- scd/scdaemon.c | 26 +++++++++-- 13 files changed, 187 insertions(+), 95 deletions(-) diff --git a/ChangeLog b/ChangeLog index b375edf43..a7f7ac7f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-07-03 Werner Koch + + * configure.ac [W32]: Use ws2_32 instead of wsock32. + 2007-06-25 Werner Koch * gl/mkdtemp.c (gen_tempname) [MKDIR_TAKES_ONE_ARG]: Avoid diff --git a/agent/ChangeLog b/agent/ChangeLog index 607a02282..73bcfe10a 100644 --- a/agent/ChangeLog +++ b/agent/ChangeLog @@ -1,3 +1,25 @@ +2007-07-04 Werner Koch + + * gpg-agent.c (TIMERTICK_INTERVAL): New. + +2007-07-03 Werner Koch + + * gpg-agent.c (handle_connections): Do not use FD_SETSIZE for + select but compute the correct number. + +2007-07-02 Werner Koch + + * command.c (cmd_reloadagent) [W32]: New. + (register_commands) [W32]: New command RELOADAGENT. + + * Makefile.am (gpg_agent_SOURCES): Remove w32main.c and w32main.h. + (gpg_agent_res_ldflags): Remove icon file as we don't have a + proper icon yet. + * gpg-agent.c (main): do not include w32main.h. Remove all calls + to w32main.c. + (agent_sighup_action): New. + (handle_signal): Use it. + 2007-06-26 Werner Koch * gpg-agent.c (create_directories) [W32]: Made it work. diff --git a/agent/Makefile.am b/agent/Makefile.am index 1a8047856..74c1cf810 100644 --- a/agent/Makefile.am +++ b/agent/Makefile.am @@ -23,7 +23,7 @@ bin_PROGRAMS = gpg-agent libexec_PROGRAMS = gpg-protect-tool gpg-preset-passphrase noinst_PROGRAMS = $(TESTS) -EXTRA_DIST = gpg-agent.ico gpg-agent-resource.rc +# EXTRA_DIST = gpg-agent.ico gpg-agent-resource.rc AM_CPPFLAGS = -I$(top_srcdir)/gl -I$(top_srcdir)/common -I$(top_srcdir)/intl @@ -47,25 +47,21 @@ gpg_agent_SOURCES = \ call-scd.c \ learncard.c -if HAVE_W32_SYSTEM -gpg_agent_SOURCES += w32main.c w32main.h -endif - common_libs = ../jnlib/libjnlib.a $(libcommon) ../gl/libgnu.a commonpth_libs = ../jnlib/libjnlib.a $(libcommonpth) ../gl/libgnu.a pwquery_libs = ../common/libsimple-pwquery.a -if HAVE_W32_SYSTEM -.rc.o: - $(WINDRES) `echo $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) | \ - sed -e 's/-I/--include-dir /g;s/-D/--define /g'` -i $< -o $@ - -gpg_agent_res_ldflags = -Wl,gpg-agent-resource.o -Wl,--subsystem,windows -gpg_agent_res_deps = gpg-agent-resource.o -else +#if HAVE_W32_SYSTEM +#.rc.o: +# $(WINDRES) `echo $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) | \ +# sed -e 's/-I/--include-dir /g;s/-D/--define /g'` -i $< -o $@ +# +#gpg_agent_res_ldflags = -Wl,gpg-agent-resource.o -Wl,--subsystem,windows +#gpg_agent_res_deps = gpg-agent-resource.o +#else gpg_agent_res_ldflags = gpg_agent_res_deps = -endif +#endif gpg_agent_CFLAGS = $(AM_CFLAGS) $(LIBASSUAN_PTH_CFLAGS) $(PTH_CFLAGS) diff --git a/agent/agent.h b/agent/agent.h index 690a86df5..17c7eed56 100644 --- a/agent/agent.h +++ b/agent/agent.h @@ -190,6 +190,7 @@ cache_mode_t; void agent_exit (int rc) JNLIB_GCC_A_NR; /* Also implemented in other tools */ const char *get_agent_socket_name (void); const char *get_agent_ssh_socket_name (void); +void agent_sighup_action (void); /*-- command.c --*/ gpg_error_t agent_write_status (ctrl_t ctrl, const char *keyword, ...); diff --git a/agent/call-pinentry.c b/agent/call-pinentry.c index 8882e8d55..e995c4f1c 100644 --- a/agent/call-pinentry.c +++ b/agent/call-pinentry.c @@ -225,7 +225,7 @@ start_pinentry (ctrl_t ctrl) pgmname++; /* OS X needs the entire file name in argv[0], so that it can locate - the resource bundle. For other systems we stick to the the usual + the resource bundle. For other systems we stick to the usual convention of supplying only the name of the program. */ #ifdef __APPLE__ argv[0] = opt.pinentry_program; diff --git a/agent/command.c b/agent/command.c index 011ed580d..0c0cb54ed 100644 --- a/agent/command.c +++ b/agent/command.c @@ -1323,6 +1323,17 @@ cmd_killagent (assuan_context_t ctx, char *line) ctrl->server_local->stopme = 1; return 0; } + +/* RELOADAGENT + + As signals are inconvenient under Windows, we provide this command + to allow reloading of the configuration. */ +static int +cmd_reloadagent (assuan_context_t ctx, char *line) +{ + agent_sighup_action (); + return 0; +} #endif /*HAVE_W32_SYSTEM*/ @@ -1506,6 +1517,7 @@ register_commands (assuan_context_t ctx) { "UPDATESTARTUPTTY", cmd_updatestartuptty }, #ifdef HAVE_W32_SYSTEM { "KILLAGENT", cmd_killagent }, + { "RELOADAGENT", cmd_reloadagent }, #endif { "GETINFO", cmd_getinfo }, { NULL } diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c index b69142825..a75acec94 100644 --- a/agent/gpg-agent.c +++ b/agent/gpg-agent.c @@ -48,7 +48,6 @@ #include "sysutils.h" #ifdef HAVE_W32_SYSTEM # include "../jnlib/w32-afunix.h" -# include "w32main.h" #endif #include "setenv.h" @@ -171,6 +170,14 @@ static ARGPARSE_OPTS opts[] = { #define MAX_CACHE_TTL_SSH (120*60) /* 2 hours */ #define MIN_PASSPHRASE_LEN (8) +/* The timer tick used for housekeeping stuff. For Windows we use a + longer period as the SetWaitableTimer seems to signal earlier than + the 2 seconds. */ +#ifdef HAVE_W32_SYSTEM +#define TIMERTICK_INTERVAL (4) +#else +#define TIMERTICK_INTERVAL (2) /* Seconds. */ +#endif /* flag to indicate that a shutdown was requested */ static int shutdown_pending; @@ -408,16 +415,9 @@ parse_rereadable_options (ARGPARSE_ARGS *pargs, int reread) } -/* The main entry point. For W32 another name is used as the real - entry points needs to be named WinMain and is defined in - w32main.c. */ -#ifdef HAVE_W32_SYSTEM -int -w32_main (int argc, char **argv ) -#else +/* The main entry point. */ int main (int argc, char **argv ) -#endif { ARGPARSE_ARGS pargs; int orig_argc; @@ -851,7 +851,6 @@ main (int argc, char **argv ) #ifdef HAVE_W32_SYSTEM pid = getpid (); printf ("set GPG_AGENT_INFO=%s;%lu;1\n", socket_name, (ulong)pid); - w32_setup_taskbar (); #else /*!HAVE_W32_SYSTEM*/ pid = fork (); if (pid == (pid_t)-1) @@ -1430,6 +1429,17 @@ handle_tick (void) } +/* A global fucntion which allows us to call the reload stuff from + other palces too. This is only used when build for W32. */ +void +agent_sighup_action (void) +{ + agent_flush_cache (); + reread_configuration (); + agent_reload_trustlist (); +} + + static void handle_signal (int signo) { @@ -1439,9 +1449,7 @@ handle_signal (int signo) case SIGHUP: log_info ("SIGHUP received - " "re-reading configuration and flushing cache\n"); - agent_flush_cache (); - reread_configuration (); - agent_reload_trustlist (); + agent_sighup_action (); break; case SIGUSR1: @@ -1545,6 +1553,7 @@ handle_connections (int listen_fd, int listen_fd_ssh) fd_set fdset, read_fdset; int ret; int fd; + int nfd; tattr = pth_attr_new(); pth_attr_set (tattr, PTH_ATTR_JOINABLE, 0); @@ -1562,24 +1571,25 @@ handle_connections (int listen_fd, int listen_fd_ssh) pth_sigmask (SIG_UNBLOCK, &sigs, NULL); ev = pth_event (PTH_EVENT_SIGS, &sigs, &signo); #else - ev = NULL; - signo = 0; + sigs = 0; + ev = pth_event (PTH_EVENT_SIGS, &sigs, &signo); #endif time_ev = NULL; FD_ZERO (&fdset); FD_SET (listen_fd, &fdset); + nfd = listen_fd; if (listen_fd_ssh != -1) - FD_SET (listen_fd_ssh, &fdset); + { + FD_SET (listen_fd_ssh, &fdset); + if (listen_fd_ssh > nfd) + nfd = listen_fd_ssh; + } for (;;) { sigset_t oldsigs; -#ifdef HAVE_W32_SYSTEM - w32_poll_events (); -#endif - if (shutdown_pending) { if (pth_ctrl (PTH_CTRL_GETTHREADS) == 1) @@ -1596,7 +1606,8 @@ handle_connections (int listen_fd, int listen_fd_ssh) /* Create a timeout event if needed. */ if (!time_ev) - time_ev = pth_event (PTH_EVENT_TIME, pth_timeout (2, 0)); + time_ev = pth_event (PTH_EVENT_TIME, + pth_timeout (TIMERTICK_INTERVAL, 0)); /* POSIX says that fd_set should be implemented as a structure, thus a simple assignment is fine to copy the entire set. */ @@ -1604,7 +1615,7 @@ handle_connections (int listen_fd, int listen_fd_ssh) if (time_ev) pth_event_concat (ev, time_ev, NULL); - ret = pth_select_ev (FD_SETSIZE, &read_fdset, NULL, NULL, NULL, ev); + ret = pth_select_ev (nfd+1, &read_fdset, NULL, NULL, NULL, ev); if (time_ev) pth_event_isolate (time_ev); @@ -1643,8 +1654,8 @@ handle_connections (int listen_fd, int listen_fd_ssh) /* We now might create new threads and because we don't want any - signals - we are handling here - to be delivered to a new - thread. Thus we need to block those signals. */ + signals (as we are handling them here) to be delivered to a + new thread. Thus we need to block those signals. */ pth_sigmask (SIG_BLOCK, &sigs, &oldsigs); if (FD_ISSET (listen_fd, &read_fdset)) diff --git a/configure.ac b/configure.ac index b46c8e33d..2a1dd8263 100644 --- a/configure.ac +++ b/configure.ac @@ -1160,7 +1160,7 @@ GNUPG_CHECK_GNUMAKE # requiring any network stuff but linking to code in libcommon which # tracks in winsock stuff (e.g. init_common_subsystems. if test "$have_w32_system" = yes; then - W32SOCKLIBS="-lwsock32" + W32SOCKLIBS="-lws2_32" NETLIBS="${NETLIBS} ${W32SOCKLIBS}" fi diff --git a/jnlib/ChangeLog b/jnlib/ChangeLog index 4826ce4cd..37ae48ed9 100644 --- a/jnlib/ChangeLog +++ b/jnlib/ChangeLog @@ -1,3 +1,9 @@ +2007-07-01 Werner Koch + + * argparse.c (strusage): Use id 10 for the license string; + default to GPL3+. Change long note to version 3 or later. + (show_version): Print the license info. + 2007-06-19 Werner Koch * Makefile.am: Add support for regression tests. diff --git a/jnlib/argparse.c b/jnlib/argparse.c index 348a803a9..54dd24e2d 100644 --- a/jnlib/argparse.c +++ b/jnlib/argparse.c @@ -844,64 +844,71 @@ show_help( ARGPARSE_OPTS *opts, unsigned flags ) static void show_version() { - const char *s; - int i; - /* version line */ - fputs(strusage(11), stdout); - if( (s=strusage(12)) ) - printf(" (%s)", s ); - printf(" %s\n", strusage(13) ); - /* additional version lines */ - for(i=20; i < 30; i++ ) - if( (s=strusage(i)) ) - printf("%s\n", s ); - /* copyright string */ - if( (s=strusage(14)) ) - printf("%s\n", s ); - /* copying conditions */ - if( (s=strusage(15)) ) - fputs(s, stdout); - /* thanks */ - if( (s=strusage(18)) ) - fputs(s, stdout); - /* additional program info */ - for(i=30; i < 40; i++ ) - if( (s=strusage(i)) ) - fputs (s, stdout); - fflush(stdout); + const char *s; + int i; + + /* Version line. */ + fputs (strusage (11), stdout); + if ((s=strusage (12))) + printf (" (%s)", s ); + printf (" %s\n", strusage (13) ); + /* Additional version lines. */ + for (i=20; i < 30; i++) + if ((s=strusage (i))) + printf ("%s\n", s ); + /* Copyright string. */ + if( (s=strusage (14)) ) + printf("%s\n", s ); + /* Licence string. */ + if( (s=strusage (10)) ) + printf("%s\n", s ); + /* Copying conditions. */ + if ( (s=strusage(15)) ) + fputs (s, stdout); + /* Thanks. */ + if ((s=strusage(18))) + fputs (s, stdout); + /* Additional program info. */ + for (i=30; i < 40; i++ ) + if ( (s=strusage (i)) ) + fputs (s, stdout); + fflush(stdout); } void -usage( int level ) +usage (int level) { - if( !level ) { - fprintf(stderr,"%s %s; %s\n", strusage(11), strusage(13), - strusage(14) ); - fflush(stderr); + if (!level) + { + fprintf(stderr,"%s %s; %s\n", strusage(11), strusage(13), strusage (14)); + fflush (stderr); } - else if( level == 1 ) { - fputs(strusage(40),stderr); - exit(2); + else if (level == 1) + { + fputs (strusage (40), stderr); + exit (2); } - else if( level == 2 ) { - puts(strusage(41)); - exit(0); + else if (level == 2) + { + puts (strusage(41)); + exit (0); } } /* Level - * 0: Copyright String auf stderr ausgeben - * 1: Kurzusage auf stderr ausgeben und beenden - * 2: Langusage auf stdout ausgeben und beenden - * 11: name of program - * 12: optional name of package which includes this program. + * 0: Print copyright string to stderr + * 1: Print a short usage hint to stderr and terminate + * 2: Print a long usage hint to stdout and terminate + * 10: Return license info string + * 11: Return the name of the program + * 12: Return optional name of package which includes this program. * 13: version string * 14: copyright string * 15: Short copying conditions (with LFs) * 16: Long copying conditions (with LFs) * 17: Optional printable OS name - * 18: Optional thanks list (with LFs) + * 18: Optional thanks list (with LFs) * 19: Bug report info *20..29: Additional lib version strings. *30..39: Additional program info (with LFs) @@ -917,26 +924,27 @@ strusage( int level ) return p; switch( level ) { + case 10: p = ("License GPLv2+: GNU GPL version 2 or later " + ""); + break; case 11: p = "foo"; break; case 13: p = "0.0"; break; case 14: p = "Copyright (C) 2007 Free Software Foundation, Inc."; break; case 15: p = -"This program comes with ABSOLUTELY NO WARRANTY.\n" -"This is free software, and you are welcome to redistribute it\n" -"under certain conditions. See the file COPYING for details.\n"; break; +"This is free software: you are free to change and redistribute it.\n" +"There is NO WARRANTY, to the extent permitted by law.\n"; + break; case 16: p = "This is free software; you can redistribute it and/or modify\n" "it under the terms of the GNU General Public License as published by\n" -"the Free Software Foundation; either version 2 of the License, or\n" +"the Free Software Foundation; either version 3 of the License, or\n" "(at your option) any later version.\n\n" "It is distributed in the hope that it will be useful,\n" "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" "GNU General Public License for more details.\n\n" "You should have received a copy of the GNU General Public License\n" -"along with this program; if not, write to the Free Software\n" -"Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,\n" -"USA.\n"; +"along with this software. If not, see .\n"; break; case 40: /* short and long usage */ case 41: p = ""; break; diff --git a/scd/ChangeLog b/scd/ChangeLog index 3db91a0f7..5880d8e25 100644 --- a/scd/ChangeLog +++ b/scd/ChangeLog @@ -1,3 +1,12 @@ +2007-07-04 Werner Koch + + * command.c (cmd_getinfo): New subcommand "version". + + * scdaemon.c (TIMERTICK_INTERVAL): New. + (handle_connections) [W32]: Enable a dummy sigs event. + (handle_connections): Use a proper count for select and not + FD_SETSIZE. + 2007-06-21 Werner Koch * scdaemon.h (ctrl_t): Remove. It is now declared in ../common/util.h. diff --git a/scd/command.c b/scd/command.c index 3ffa5afb6..fa5a18977 100644 --- a/scd/command.c +++ b/scd/command.c @@ -1402,6 +1402,8 @@ cmd_unlock (assuan_context_t ctx, char *line) Multi purpose command to return certain information. Supported values of WHAT are: + version - Return the version of the program. + socket_name - Return the name of the socket. status - Return the status of the current slot (in the future, may @@ -1420,7 +1422,12 @@ cmd_getinfo (assuan_context_t ctx, char *line) { int rc = 0; - if (!strcmp (line, "socket_name")) + if (!strcmp (line, "version")) + { + const char *s = VERSION; + rc = assuan_send_data (ctx, s, strlen (s)); + } + else if (!strcmp (line, "socket_name")) { const char *s = scd_get_socket_name (); diff --git a/scd/scdaemon.c b/scd/scdaemon.c index b2508943d..8b86f8b7f 100644 --- a/scd/scdaemon.c +++ b/scd/scdaemon.c @@ -150,6 +150,15 @@ static ARGPARSE_OPTS opts[] = { #define DEFAULT_PCSC_DRIVER "libpcsclite.so" #endif +/* The timer tick used for housekeeping stuff. For Windows we use a + longer period as the SetWaitableTimer seems to signal earlier than + the 2 seconds. */ +#ifdef HAVE_W32_SYSTEM +#define TIMERTICK_INTERVAL (4) +#else +#define TIMERTICK_INTERVAL (2) /* Seconds. */ +#endif + /* Flag to indicate that a shutdown was requested. */ static int shutdown_pending; @@ -280,7 +289,7 @@ main (int argc, char **argv ) FILE *configfp = NULL; char *configname = NULL; const char *shell; - unsigned configlineno; + unsigned int configlineno; int parse_debug = 0; const char *debug_level = NULL; int default_config =1; @@ -1040,6 +1049,7 @@ handle_connections (int listen_fd) fd_set fdset, read_fdset; int ret; int fd; + int nfd; tattr = pth_attr_new(); pth_attr_set (tattr, PTH_ATTR_JOINABLE, 0); @@ -1055,13 +1065,18 @@ handle_connections (int listen_fd) pth_sigmask (SIG_UNBLOCK, &sigs, NULL); ev = pth_event (PTH_EVENT_SIGS, &sigs, &signo); #else - ev = NULL; + sigs = 0; + ev = pth_event (PTH_EVENT_SIGS, &sigs, &signo); #endif time_ev = NULL; FD_ZERO (&fdset); + nfd = 0; if (listen_fd != -1) - FD_SET (listen_fd, &fdset); + { + FD_SET (listen_fd, &fdset); + nfd = listen_fd; + } for (;;) { @@ -1081,7 +1096,8 @@ handle_connections (int listen_fd) /* Create a timeout event if needed. */ if (!time_ev) - time_ev = pth_event (PTH_EVENT_TIME, pth_timeout (2, 0)); + time_ev = pth_event (PTH_EVENT_TIME, + pth_timeout (TIMERTICK_INTERVAL, 0)); /* POSIX says that fd_set should be implemented as a structure, thus a simple assignment is fine to copy the entire set. */ @@ -1089,7 +1105,7 @@ handle_connections (int listen_fd) if (time_ev) pth_event_concat (ev, time_ev, NULL); - ret = pth_select_ev (FD_SETSIZE, &read_fdset, NULL, NULL, NULL, ev); + ret = pth_select_ev (nfd+1, &read_fdset, NULL, NULL, NULL, ev); if (time_ev) pth_event_isolate (time_ev);