diff options
Diffstat (limited to 'agent')
-rw-r--r-- | agent/ChangeLog | 45 | ||||
-rw-r--r-- | agent/Makefile.am | 30 | ||||
-rw-r--r-- | agent/agent.h | 5 | ||||
-rw-r--r-- | agent/call-pinentry.c | 8 | ||||
-rw-r--r-- | agent/call-scd.c | 6 | ||||
-rw-r--r-- | agent/gpg-agent.c | 42 | ||||
-rw-r--r-- | agent/minip12.c | 31 | ||||
-rw-r--r-- | agent/preset-passphrase.c | 52 | ||||
-rw-r--r-- | agent/protect-tool.c | 14 | ||||
-rw-r--r-- | agent/trustlist.c | 24 |
10 files changed, 173 insertions, 84 deletions
diff --git a/agent/ChangeLog b/agent/ChangeLog index 94b7c5a3b..4a0077507 100644 --- a/agent/ChangeLog +++ b/agent/ChangeLog @@ -1,3 +1,48 @@ +2007-06-14 Werner Koch <[email protected]> + + * protect-tool.c (main): Setup default socket name for + simple-pwquery. + (MAP_SPWQ_ERROR_IMPL): New. Use map_spwq_error for spqw related + error codes. + * preset-passphrase.c (main): Setup default socket name for + simple-pwquery. + (map_spwq_error): Remove. + (MAP_SPWQ_ERROR_IMPL): New. + + * call-pinentry.c (start_pinentry): Use gnupg_module_name. + * call-scd.c (start_scd): Ditto. + +2007-06-12 Werner Koch <[email protected]> + + * taskbar.c: New. + + * trustlist.c (read_one_trustfile): Replace GNUPG_SYSCONFDIR by a + function call. + (read_trustfiles): Ditto. + + * gpg-agent.c (main): Replace some calls by init_common_subsystems. + * preset-passphrase.c (main): Ditto. + * protect-tool.c (main): Ditto. + +2007-06-11 Werner Koch <[email protected]> + + * Makefile.am (common_libs): Use libcommonstd macro. + (commonpth_libs): Use libcommonpth macro. + + * protect-tool.c (main) [W32]: Call pth_init. + + * preset-passphrase.c (main) [W32]: Repalce the explicit Winsocket + init by a call to pth_init. + + * trustlist.c (initialize_module_trustlist): New. + * gpg-agent.c (main): Call it. + + * call-pinentry.c (initialize_module_query): Rename to + initialize_module_call_pinentry. + + * minip12.c: Remove iconv.h. Add utf8conf.h. Changed all iconv + calss to use these jnlib wrappers. + 2007-06-06 Werner Koch <[email protected]> * minip12.c (enum): Rename CONTEXT to ASNCONTEXT as winnt.h diff --git a/agent/Makefile.am b/agent/Makefile.am index b79423a7c..34883ba20 100644 --- a/agent/Makefile.am +++ b/agent/Makefile.am @@ -23,6 +23,8 @@ bin_PROGRAMS = gpg-agent libexec_PROGRAMS = gpg-protect-tool gpg-preset-passphrase noinst_PROGRAMS = $(TESTS) +EXTRA_DIST = gpg-agent.ico gpg-agent-resource.rc + AM_CPPFLAGS = -I$(top_srcdir)/gl -I$(top_srcdir)/common -I$(top_srcdir)/intl include $(top_srcdir)/am/cmacros.am @@ -45,15 +47,33 @@ 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 ../common/libcommon.a ../gl/libgnu.a -commonpth_libs = ../jnlib/libjnlib.a ../common/libcommonpth.a ../gl/libgnu.a +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 +gpg_agent_res_deps = gpg-agent-resource.o +else +gpg_agent_res_ldflags = +gpg_agent_res_deps = +endif + + gpg_agent_CFLAGS = $(AM_CFLAGS) $(LIBASSUAN_PTH_CFLAGS) $(PTH_CFLAGS) gpg_agent_LDADD = $(commonpth_libs) \ $(LIBGCRYPT_LIBS) $(LIBASSUAN_PTH_LIBS) $(PTH_LIBS) \ $(GPG_ERROR_LIBS) $(LIBINTL) $(NETLIBS) $(LIBICONV) +gpg_agent_LDFLAGS = $(gpg_agent_res_ldflags) +gpg_agent_DEPENDENCIES = $(gpg_agent_res_deps) gpg_protect_tool_SOURCES = \ protect-tool.c \ @@ -61,14 +81,15 @@ gpg_protect_tool_SOURCES = \ minip12.c minip12.h # Needs $(NETLIBS) for libsimple-pwquery.la. -gpg_protect_tool_LDADD = $(pwquery_libs) $(common_libs) \ +gpg_protect_tool_LDADD = $(pwquery_libs) $(common_libs) \ $(LIBGCRYPT_LIBS) $(GPG_ERROR_LIBS) $(LIBINTL) $(NETLIBS) $(LIBICONV) gpg_preset_passphrase_SOURCES = \ preset-passphrase.c # Needs $(NETLIBS) for libsimple-pwquery.la. -gpg_preset_passphrase_LDADD = $(pwquery_libs) $(common_libs) \ +gpg_preset_passphrase_LDADD = \ + $(pwquery_libs) $(common_libs) \ $(LIBGCRYPT_LIBS) $(GPG_ERROR_LIBS) $(LIBINTL) $(NETLIBS) $(LIBICONV) @@ -77,6 +98,7 @@ gpg_preset_passphrase_LDADD = $(pwquery_libs) $(common_libs) \ $(PROGRAMS): $(common_libs) $(commonpth_libs) $(pwquery_libs) + # # Module tests # diff --git a/agent/agent.h b/agent/agent.h index 15830de27..b0d27823c 100644 --- a/agent/agent.h +++ b/agent/agent.h @@ -215,8 +215,8 @@ gpg_error_t agent_public_key_from_file (ctrl_t ctrl, gcry_sexp_t *result); int agent_key_available (const unsigned char *grip); -/*-- query.c --*/ -void initialize_module_query (void); +/*-- call-pinentry.c --*/ +void initialize_module_call_pinentry (void); void agent_query_dump_state (void); void agent_reset_query (ctrl_t ctrl); int pinentry_active_p (ctrl_t ctrl, int waitseconds); @@ -276,6 +276,7 @@ int agent_get_shadow_info (const unsigned char *shadowkey, /*-- trustlist.c --*/ +void initialize_module_trustlist (void); gpg_error_t agent_istrusted (ctrl_t ctrl, const char *fpr); gpg_error_t agent_listtrusted (void *assuan_context); gpg_error_t agent_marktrusted (ctrl_t ctrl, const char *name, diff --git a/agent/call-pinentry.c b/agent/call-pinentry.c index 099171c5e..8882e8d55 100644 --- a/agent/call-pinentry.c +++ b/agent/call-pinentry.c @@ -87,7 +87,7 @@ struct entry_parm_s static initialization because Pth emulation code might not be able to do a static init; in particular, it is not possible for W32. */ void -initialize_module_query (void) +initialize_module_call_pinentry (void) { static int initialized; @@ -217,7 +217,7 @@ start_pinentry (ctrl_t ctrl) } if (!opt.pinentry_program || !*opt.pinentry_program) - opt.pinentry_program = GNUPG_DEFAULT_PINENTRY; + opt.pinentry_program = gnupg_module_name (GNUPG_MODULE_NAME_PINENTRY); pgmname = opt.pinentry_program; if ( !(pgmname = strrchr (opt.pinentry_program, '/'))) pgmname = opt.pinentry_program; @@ -751,6 +751,9 @@ agent_popup_message_stop (ctrl_t ctrl) ; /* No pid available can't send a kill. */ else if (popup_finished) ; /* Already finished and ready for joining. */ +#ifdef HAVE_W32_SYSTEM +# warning need to implement a kill mechanism for pinentry +#else else if (pid && ((rc=waitpid (pid, NULL, WNOHANG))==-1 || (rc == pid)) ) { /* The daemon already died. No need to send a kill. However because we already waited for the process, we need to tell @@ -762,6 +765,7 @@ agent_popup_message_stop (ctrl_t ctrl) else if (pid > 0) kill (pid, SIGKILL); /* Need to use SIGKILL due to bad interaction of SIGINT with Pth. */ +#endif /* Now wait for the thread to terminate. */ rc = pth_join (popup_tid, NULL); diff --git a/agent/call-scd.c b/agent/call-scd.c index a2067a2cb..b62ab97ea 100644 --- a/agent/call-scd.c +++ b/agent/call-scd.c @@ -300,7 +300,7 @@ start_scd (ctrl_t ctrl) } if (!opt.scdaemon_program || !*opt.scdaemon_program) - opt.scdaemon_program = GNUPG_DEFAULT_SCDAEMON; + opt.scdaemon_program = gnupg_module_name (GNUPG_MODULE_NAME_SCDAEMON); if ( !(pgmname = strrchr (opt.scdaemon_program, '/'))) pgmname = opt.scdaemon_program; else @@ -424,6 +424,9 @@ agent_scd_check_aliveness (void) if (primary_scd_ctx) { pid = assuan_get_pid (primary_scd_ctx); +#ifdef HAVE_W32_SYSTEM +#warning Need to implement an alive test for scdaemon +#else if (pid != (pid_t)(-1) && pid && ((rc=waitpid (pid, NULL, WNOHANG))==-1 || (rc == pid)) ) { @@ -454,6 +457,7 @@ agent_scd_check_aliveness (void) xfree (socket_name); socket_name = NULL; } +#endif } if (!pth_mutex_release (&start_scd_lock)) diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c index 66b048815..ae878eb86 100644 --- a/agent/gpg-agent.c +++ b/agent/gpg-agent.c @@ -33,9 +33,9 @@ #include <fcntl.h> #include <sys/stat.h> #ifndef HAVE_W32_SYSTEM -#include <sys/socket.h> -#include <sys/un.h> -#endif /*HAVE_W32_SYSTEM*/ +# include <sys/socket.h> +# include <sys/un.h> +#endif /*!HAVE_W32_SYSTEM*/ #include <unistd.h> #include <signal.h> #include <pth.h> @@ -47,7 +47,8 @@ #include "i18n.h" #include "sysutils.h" #ifdef HAVE_W32_SYSTEM -#include "../jnlib/w32-afunix.h" +# include "../jnlib/w32-afunix.h" +# include "w32main.h" #endif #include "setenv.h" @@ -408,8 +409,16 @@ 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 int main (int argc, char **argv ) +#endif { ARGPARSE_ARGS pargs; int orig_argc; @@ -434,6 +443,7 @@ main (int argc, char **argv ) gpg_error_t err; const char *env_file_name = NULL; + set_strusage (my_strusage); gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN); /* Please note that we may running SUID(ROOT), so be very CAREFUL @@ -441,8 +451,8 @@ main (int argc, char **argv ) somewhere after the option parsing */ log_set_prefix ("gpg-agent", JNLIB_LOG_WITH_PREFIX|JNLIB_LOG_WITH_PID); - /* Try to auto set the character set. */ - set_native_charset (NULL); + /* Make sure that our subsystems are ready. */ + init_common_subsystems (); i18n_init (); @@ -663,8 +673,9 @@ main (int argc, char **argv ) exit (1); } - initialize_module_query (); + initialize_module_call_pinentry (); initialize_module_call_scd (); + initialize_module_trustlist (); /* Try to create missing directories. */ create_directories (); @@ -837,6 +848,7 @@ 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) @@ -1029,6 +1041,7 @@ main (int argc, char **argv ) return 0; } + void agent_exit (int rc) { @@ -1048,7 +1061,6 @@ agent_exit (int rc) exit (rc); } - static void agent_init_default_ctrl (ctrl_t ctrl) { @@ -1153,13 +1165,13 @@ get_agent_socket_name (void) /* Create a name for the socket. With USE_STANDARD_SOCKET given as - true using STANDARD_NAME in the home directory or if given has + true using STANDARD_NAME in the home directory or if given as false from the mkdir type name TEMPLATE. In the latter case a unique name in a unique new directory will be created. In both cases 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. Returns: Pointer to an - allcoated string with the absolute name of the socket used. */ + allocated string with the absolute name of the socket used. */ static char * create_socket_name (int use_standard_socket, char *standard_name, char *template) @@ -1303,6 +1315,9 @@ static void create_directories (void) { struct stat statbuf; +#ifdef HAVE_W32_SYSTEM +#warning change it so that it works like in gpg. +#endif const char *defhome = GNUPG_DEFAULT_HOMEDIR; char *home; @@ -1478,7 +1493,7 @@ start_connection_thread_ssh (void *arg) } -/* Connection handler loop. Wait for coecntion requests and spawn a +/* Connection handler loop. Wait for connection requests and spawn a thread after accepting a connection. */ static void handle_connections (int listen_fd, int listen_fd_ssh) @@ -1510,6 +1525,7 @@ handle_connections (int listen_fd, int listen_fd_ssh) ev = pth_event (PTH_EVENT_SIGS, &sigs, &signo); #else ev = NULL; + signo = 0; #endif time_ev = NULL; @@ -1522,6 +1538,10 @@ handle_connections (int listen_fd, int listen_fd_ssh) { sigset_t oldsigs; +#ifdef HAVE_W32_SYSTEM + w32_poll_events (); +#endif + if (shutdown_pending) { if (pth_ctrl (PTH_CTRL_GETTHREADS) == 1) diff --git a/agent/minip12.c b/agent/minip12.c index ec51aee85..a551a3cf9 100644 --- a/agent/minip12.c +++ b/agent/minip12.c @@ -27,7 +27,6 @@ #include <string.h> #include <assert.h> #include <gcrypt.h> -#include <iconv.h> #include <errno.h> #ifdef TEST @@ -36,17 +35,13 @@ #endif #include "../jnlib/logging.h" +#include "../jnlib/utf8conv.h" #include "minip12.h" #ifndef DIM #define DIM(v) (sizeof(v)/sizeof((v)[0])) #endif -#ifndef ICONV_CONST -#define ICONV_CONST -#endif - - enum { @@ -532,7 +527,7 @@ decrypt_block (const void *ciphertext, unsigned char *plaintext, size_t length, { if (*charsets[charsetidx]) { - iconv_t cd; + jnlib_iconv_t cd; const char *inptr; char *outptr; size_t inbytes, outbytes; @@ -553,22 +548,22 @@ decrypt_block (const void *ciphertext, unsigned char *plaintext, size_t length, } } - cd = iconv_open (charsets[charsetidx], "utf-8"); - if (cd == (iconv_t)(-1)) + cd = jnlib_iconv_open (charsets[charsetidx], "utf-8"); + if (cd == (jnlib_iconv_t)(-1)) continue; inptr = pw; inbytes = strlen (pw); outptr = convertedpw; outbytes = convertedpwsize - 1; - if ( iconv (cd, (ICONV_CONST char **)&inptr, &inbytes, + if ( jnlib_iconv (cd, (const char **)&inptr, &inbytes, &outptr, &outbytes) == (size_t)-1) { - iconv_close (cd); + jnlib_iconv_close (cd); continue; } *outptr = 0; - iconv_close (cd); + jnlib_iconv_close (cd); log_info ("decryption failed; trying charset `%s'\n", charsets[charsetidx]); } @@ -2167,7 +2162,7 @@ p12_build (gcry_mpi_t *kparms, unsigned char *cert, size_t certlen, if (charset && pw && *pw) { - iconv_t cd; + jnlib_iconv_t cd; const char *inptr; char *outptr; size_t inbytes, outbytes; @@ -2182,8 +2177,8 @@ p12_build (gcry_mpi_t *kparms, unsigned char *cert, size_t certlen, goto failure; } - cd = iconv_open (charset, "utf-8"); - if (cd == (iconv_t)(-1)) + cd = jnlib_iconv_open (charset, "utf-8"); + if (cd == (jnlib_iconv_t)(-1)) { log_error ("can't convert passphrase to" " requested charset `%s': %s\n", @@ -2196,18 +2191,18 @@ p12_build (gcry_mpi_t *kparms, unsigned char *cert, size_t certlen, inbytes = strlen (pw); outptr = pwbuf; outbytes = pwbufsize - 1; - if ( iconv (cd, (ICONV_CONST char **)&inptr, &inbytes, + if ( jnlib_iconv (cd, (const char **)&inptr, &inbytes, &outptr, &outbytes) == (size_t)-1) { log_error ("error converting passphrase to" " requested charset `%s': %s\n", charset, strerror (errno)); gcry_free (pwbuf); - iconv_close (cd); + jnlib_iconv_close (cd); goto failure; } *outptr = 0; - iconv_close (cd); + jnlib_iconv_close (cd); pw = pwbuf; } diff --git a/agent/preset-passphrase.c b/agent/preset-passphrase.c index 362591171..7ff842565 100644 --- a/agent/preset-passphrase.c +++ b/agent/preset-passphrase.c @@ -111,31 +111,9 @@ my_strusage (int level) -static gpg_error_t -map_spwq_error (int err) -{ - switch (err) - { - case 0: - return 0; - case SPWQ_OUT_OF_CORE: - return gpg_error_from_errno (ENOMEM); - case SPWQ_IO_ERROR: - return gpg_error_from_errno (EIO); - case SPWQ_PROTOCOL_ERROR: - return gpg_error (GPG_ERR_PROTOCOL_VIOLATION); - case SPWQ_ERR_RESPONSE: - return gpg_error (GPG_ERR_INV_RESPONSE); - case SPWQ_NO_AGENT: - return gpg_error (GPG_ERR_NO_AGENT); - case SPWQ_SYS_ERROR: - return gpg_error_from_syserror (); - case SPWQ_GENERAL_ERROR: - default: - return gpg_error (GPG_ERR_GENERAL); - } -} +/* Include the implementation of map_spwq_error. */ +MAP_SPWQ_ERROR_IMPL /* Convert the string SRC into HEX encoding. Caller needs to xfree the returned string. */ @@ -260,23 +238,8 @@ main (int argc, char **argv) set_strusage (my_strusage); log_set_prefix ("gpg-preset-passphrase", 1); - /* Try to auto set the character set. */ - set_native_charset (NULL); - -#ifdef HAVE_W32_SYSTEM - /* Fixme: Need to initialize the Windows sockets: This should be - moved to another place and we should make sure that it won't get - done twice, like when Pth is used too. */ - { - WSADATA wsadat; - if (WSAStartup (0x202, &wsadat) ) - { - log_error ("error initializing socket library: ec=%d\n", - (int)WSAGetLastError () ); - return 2; - } - } -#endif + /* Make sure that our subsystems are ready. */ + init_common_subsystems (); i18n_init (); @@ -307,6 +270,13 @@ main (int argc, char **argv) else usage (1); + /* Tell simple-pwquery about the the standard socket name. */ + { + char *tmp = make_filename (opt_homedir, "S.gpg-agent", NULL); + simple_pw_set_socket (tmp); + xfree (tmp); + } + if (cmd == oPreset) preset_passphrase (keygrip); else if (cmd == oForget) diff --git a/agent/protect-tool.c b/agent/protect-tool.c index d3bcc00b8..9154d4f81 100644 --- a/agent/protect-tool.c +++ b/agent/protect-tool.c @@ -160,6 +160,8 @@ my_strusage (int level) } +/* Include the implementation of map_spwq_error. */ +MAP_SPWQ_ERROR_IMPL /* static void */ /* print_mpi (const char *text, gcry_mpi_t a) */ @@ -1033,8 +1035,8 @@ main (int argc, char **argv ) gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN); log_set_prefix ("gpg-protect-tool", 1); - /* Try to auto set the character set. */ - set_native_charset (NULL); + /* Make sure that our subsystems are ready. */ + init_common_subsystems (); i18n_init (); @@ -1092,6 +1094,13 @@ main (int argc, char **argv ) else if (argc > 1) usage (1); + /* Tell simple-pwquery about the the standard socket name. */ + { + char *tmp = make_filename (opt_homedir, "S.gpg-agent", NULL); + simple_pw_set_socket (tmp); + xfree (tmp); + } + if (opt_prompt) opt_prompt = percent_plus_unescape_string (xstrdup (opt_prompt)); @@ -1194,6 +1203,7 @@ get_passphrase (int promptno, int opt_check) pw = simple_pwquery (NULL, error_msgno == 1? _("does not match - try again"):NULL, _("Passphrase:"), desc, opt_check, &err); + err = map_spwq_error (err); #ifdef ENABLE_NLS if (orig_codeset) diff --git a/agent/trustlist.c b/agent/trustlist.c index b5bafa9cb..10ef02847 100644 --- a/agent/trustlist.c +++ b/agent/trustlist.c @@ -53,7 +53,7 @@ typedef struct trustitem_s trustitem_t; static trustitem_t *trusttable; static size_t trusttablesize; /* A mutex used to protect the table. */ -static pth_mutex_t trusttable_lock = PTH_MUTEX_INIT; +static pth_mutex_t trusttable_lock; @@ -71,6 +71,24 @@ static const char headerblurb[] = "\n"; +/* This function must be called once to initialize this module. This + has to be done before a second thread is spawned. We can't do the + static initialization because Pth emulation code might not be able + to do a static init; in particular, it is not possible for W32. */ +void +initialize_module_trustlist (void) +{ + static int initialized; + + if (!initialized) + { + if (!pth_mutex_init (&trusttable_lock)) + log_fatal ("error initializing mutex: %s\n", strerror (errno)); + initialized = 1; + } +} + + static void @@ -153,7 +171,7 @@ read_one_trustfile (const char *fname, int allow_include, } /* fixme: Should check for trailing garbage. */ - etcname = make_filename (GNUPG_SYSCONFDIR, "trustlist.txt", NULL); + etcname = make_filename (gnupg_sysconfdir (), "trustlist.txt", NULL); if ( !strcmp (etcname, fname) ) /* Same file. */ log_info (_("statement \"%s\" ignored in `%s', line %d\n"), "include-default", fname, lnr); @@ -303,7 +321,7 @@ read_trustfiles (void) log_error (_("error opening `%s': %s\n"), fname, gpg_strerror (err)); } xfree (fname); - fname = make_filename (GNUPG_SYSCONFDIR, "trustlist.txt", NULL); + fname = make_filename (gnupg_sysconfdir (), "trustlist.txt", NULL); allow_include = 0; } err = read_one_trustfile (fname, allow_include, |