GNUPG-1-9-BRANCH gnupg (31 files)
cvs user wk
cvs at cvs.gnupg.org
Wed Dec 15 15:10:48 CET 2004
Date: Wednesday, December 15, 2004 @ 15:15:09
Author: wk
Path: /cvs/gnupg/gnupg
Tag: GNUPG-1-9-BRANCH
Added: common/ttyname.c
Modified: ChangeLog Makefile.am acinclude.m4 agent/ChangeLog
agent/call-scd.c agent/gpg-agent.c agent/protect-tool.c
common/ChangeLog common/asshelp.c common/exechelp.c
common/iobuf.c common/simple-pwquery.c common/sysutils.h
common/util.h common/w32reg.c configure.ac g10/call-agent.c
jnlib/ChangeLog jnlib/logging.c m4/ksba.m4 scd/ChangeLog
scd/Makefile.am scd/apdu.c scd/command.c scd/scdaemon.c
sm/Makefile.am sm/gpgsm.c tools/ChangeLog tools/Makefile.am
tools/gpgconf-comp.c
A whole bunch of changes to allow building for W32.
-------------------------+
ChangeLog | 10 +
Makefile.am | 8 +
acinclude.m4 | 22 +--
agent/ChangeLog | 13 ++
agent/call-scd.c | 2
agent/gpg-agent.c | 16 +-
agent/protect-tool.c | 20 ++-
common/ChangeLog | 15 ++
common/asshelp.c | 119 +++++++++----------
common/exechelp.c | 276 ++++++++++++++++++++++++++++++++++++++++++++--
common/iobuf.c | 4
common/simple-pwquery.c | 6 -
common/sysutils.h | 7 +
common/ttyname.c | 32 +++++
common/util.h | 4
common/w32reg.c | 5
configure.ac | 30 -----
g10/call-agent.c | 2
jnlib/ChangeLog | 4
jnlib/logging.c | 7 -
m4/ksba.m4 | 2
scd/ChangeLog | 11 +
scd/Makefile.am | 14 +-
scd/apdu.c | 9 +
scd/command.c | 5
scd/scdaemon.c | 40 ++++++
sm/Makefile.am | 8 -
sm/gpgsm.c | 15 ++
tools/ChangeLog | 10 +
tools/Makefile.am | 5
tools/gpgconf-comp.c | 18 +++
31 files changed, 580 insertions(+), 159 deletions(-)
Index: gnupg/ChangeLog
diff -u gnupg/ChangeLog:1.131.2.60 gnupg/ChangeLog:1.131.2.61
--- gnupg/ChangeLog:1.131.2.60 Mon Dec 6 14:49:14 2004
+++ gnupg/ChangeLog Wed Dec 15 15:15:09 2004
@@ -1,3 +1,13 @@
+2004-12-15 Werner Koch <wk at g10code.com>
+
+ * Makefile.am (SUBDIRS) [W32]: Do not build in tests/.
+
+ * acinclude.m4: Add proper macro name quoting for use with
+ automake 1.9.
+
+ * configure.ac: Add replacement check for ttyname.
+ Removed support for a included zlib.
+
2004-12-06 Werner Koch <wk at g10code.com>
* configure.ac (have_w32_system): New. Disable Pth checks for W32.
Index: gnupg/Makefile.am
diff -u gnupg/Makefile.am:1.46.4.11 gnupg/Makefile.am:1.46.4.12
--- gnupg/Makefile.am:1.46.4.11 Fri Oct 22 18:03:04 2004
+++ gnupg/Makefile.am Wed Dec 15 15:15:09 2004
@@ -53,8 +53,14 @@
scd =
endif
+if HAVE_W32_SYSTEM
+tests =
+else
+tests = tests
+endif
+
SUBDIRS = m4 intl jnlib common ${kbx} \
- ${gpg} ${sm} ${agent} ${scd} tools po doc tests
+ ${gpg} ${sm} ${agent} ${scd} tools po doc ${tests}
dist-hook:
@set -e; \
Index: gnupg/acinclude.m4
diff -u gnupg/acinclude.m4:1.34.4.6 gnupg/acinclude.m4:1.34.4.7
--- gnupg/acinclude.m4:1.34.4.6 Wed Feb 18 19:38:50 2004
+++ gnupg/acinclude.m4 Wed Dec 15 15:15:09 2004
@@ -20,7 +20,7 @@
dnl GNUPG_CHECK_TYPEDEF(TYPE, HAVE_NAME)
dnl Check whether a typedef exists and create a #define $2 if it exists
dnl
-AC_DEFUN(GNUPG_CHECK_TYPEDEF,
+AC_DEFUN([GNUPG_CHECK_TYPEDEF],
[ AC_MSG_CHECKING(for $1 typedef)
AC_CACHE_VAL(gnupg_cv_typedef_$1,
[AC_TRY_COMPILE([#define _GNU_SOURCE 1
@@ -38,7 +38,7 @@
dnl GNUPG_CHECK_GNUMAKE
dnl
-AC_DEFUN(GNUPG_CHECK_GNUMAKE,
+AC_DEFUN([GNUPG_CHECK_GNUMAKE],
[
if ${MAKE-make} --version 2>/dev/null | grep '^GNU ' >/dev/null 2>&1; then
:
@@ -55,7 +55,7 @@
dnl GNUPG_CHECK_FAQPROG
dnl
-AC_DEFUN(GNUPG_CHECK_FAQPROG,
+AC_DEFUN([GNUPG_CHECK_FAQPROG],
[ AC_MSG_CHECKING(for faqprog.pl)
if faqprog.pl -V 2>/dev/null | grep '^faqprog.pl ' >/dev/null 2>&1; then
working_faqprog=yes
@@ -82,7 +82,7 @@
dnl GNUPG_CHECK_DOCBOOK_TO_TEXI
dnl
-AC_DEFUN(GNUPG_CHECK_DOCBOOK_TO_TEXI,
+AC_DEFUN([GNUPG_CHECK_DOCBOOK_TO_TEXI],
[
AC_CHECK_PROG(DOCBOOK_TO_TEXI, docbook2texi, yes, no)
AC_MSG_CHECKING(for sgml to texi tools)
@@ -101,7 +101,7 @@
dnl GNUPG_CHECK_ENDIAN
dnl define either LITTLE_ENDIAN_HOST or BIG_ENDIAN_HOST
dnl
-define(GNUPG_CHECK_ENDIAN,
+AC_DEFUN([GNUPG_CHECK_ENDIAN],
[
tmp_assumed_endian=big
if test "$cross_compiling" = yes; then
@@ -158,7 +158,7 @@
# Check for the getsockopt SO_PEERCRED
-AC_DEFUN(GNUPG_SYS_SO_PEERCRED,
+AC_DEFUN([GNUPG_SYS_SO_PEERCRED],
[ AC_MSG_CHECKING(for SO_PEERCRED)
AC_CACHE_VAL(gnupg_cv_sys_so_peercred,
[AC_TRY_COMPILE([#include <sys/socket.h>],
@@ -183,7 +183,7 @@
# either be "yes" or "no" and decided on the default value for
# build_NAME and whether --enable-NAME or --disable-NAME is shown with
# ./configure --help
-AC_DEFUN(GNUPG_BUILD_PROGRAM,
+AC_DEFUN([GNUPG_BUILD_PROGRAM],
[build_$1=$2
m4_if([$2],[yes],[
AC_ARG_ENABLE([$1], AC_HELP_STRING([--disable-$1],
@@ -210,7 +210,7 @@
# If the version is sufficient, HAVE_PTH will be set to yes.
#
# Taken form the m4 macros which come with Pth
-AC_DEFUN(GNUPG_PTH_VERSION_CHECK,
+AC_DEFUN([GNUPG_PTH_VERSION_CHECK],
[
_pth_version=`$PTH_CONFIG --version | awk 'NR==1 {print [$]3}'`
_req_version="ifelse([$1],,1.2.0,$1)"
@@ -253,7 +253,7 @@
# mlock is there a macro using memlk()
dnl GNUPG_CHECK_MLOCK
dnl
-define(GNUPG_CHECK_MLOCK,
+AC_DEFUN([GNUPG_CHECK_MLOCK],
[ AC_CHECK_FUNCS(mlock)
if test "$ac_cv_func_mlock" = "no"; then
AC_CHECK_HEADERS(sys/mman.h)
@@ -343,7 +343,7 @@
dnl Stolen from gcc
dnl Define MKDIR_TAKES_ONE_ARG if mkdir accepts only one argument instead
dnl of the usual 2.
-AC_DEFUN(GNUPG_FUNC_MKDIR_TAKES_ONE_ARG,
+AC_DEFUN([GNUPG_FUNC_MKDIR_TAKES_ONE_ARG],
[AC_CHECK_HEADERS(sys/stat.h unistd.h direct.h)
AC_CACHE_CHECK([if mkdir takes one argument], gnupg_cv_mkdir_takes_one_arg,
[AC_TRY_COMPILE([
@@ -371,7 +371,7 @@
dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
dnl Test for OpenSC and define OPENSC_CFLAGS and OPENSC_LIBS
dnl
-AC_DEFUN(AM_PATH_OPENSC,
+AC_DEFUN([AM_PATH_OPENSC],
[ AC_ARG_WITH(opensc-prefix,
AC_HELP_STRING([--with-opensc-prefix=PFX],
[prefix where OpenSC is installed (optional)]),
Index: gnupg/agent/ChangeLog
diff -u gnupg/agent/ChangeLog:1.59.2.44 gnupg/agent/ChangeLog:1.59.2.45
--- gnupg/agent/ChangeLog:1.59.2.44 Sun Dec 5 16:36:49 2004
+++ gnupg/agent/ChangeLog Wed Dec 15 15:15:09 2004
@@ -1,3 +1,16 @@
+2004-12-15 Werner Koch <wk at g10code.com>
+
+ * gpg-agent.c [W32]: Various hacks to make it work.
+
+ * findkey.c (agent_write_private_key) [W32]: Adjust open call.
+
+ * call-scd.c (start_scd) [W32]: Don't check whether the daemon
+ didn't died. To hard to do under Windows.
+ (start_scd) [W32]: Disable sending of the event signal option.
+
+ * protect-tool.c (read_file, export_p12_file) [W32]: Use setmode
+ to get stdout and stin into binary mode.
+
2004-12-05 Moritz Schulte <moritz at g10code.com>
* query.c (start_pinentry): Allow CTRL be NULL.
Index: gnupg/agent/call-scd.c
diff -u gnupg/agent/call-scd.c:1.13.2.5 gnupg/agent/call-scd.c:1.13.2.6
--- gnupg/agent/call-scd.c:1.13.2.5 Mon Dec 13 16:49:56 2004
+++ gnupg/agent/call-scd.c Wed Dec 15 15:15:09 2004
@@ -215,7 +215,7 @@
/* We better do a sanity check now to see whether it has
accidently died. */
-#ifndef HAVE_W32_SYSTEM /* fixme */
+#ifndef HAVE_W32_SYSTEM
pid = assuan_get_pid (scd_ctx);
if (pid != (pid_t)(-1) && pid
&& ((rc=waitpid (pid, NULL, WNOHANG))==-1 || (rc == pid)) )
Index: gnupg/agent/gpg-agent.c
diff -u gnupg/agent/gpg-agent.c:1.31.2.23 gnupg/agent/gpg-agent.c:1.31.2.24
--- gnupg/agent/gpg-agent.c:1.31.2.23 Tue Dec 14 20:20:36 2004
+++ gnupg/agent/gpg-agent.c Wed Dec 15 15:15:09 2004
@@ -33,7 +33,7 @@
#ifndef HAVE_W32_SYSTEM
#include <sys/socket.h>
#include <sys/un.h>
-#endif
+#endif /*HAVE_W32_SYSTEM*/
#include <unistd.h>
#include <signal.h>
#ifdef USE_GNU_PTH
@@ -438,17 +438,18 @@
/* Libgcrypt requires us to register the threading model first.
Note that this will also do the pth_init. */
-#if defined(USE_GNU_PTH) && !defined(HAVE_W32_SYSTEM)
+#ifdef USE_GNU_PTH
+# ifdef HAVE_W32_SYSTEM
+ pth_init ();
+# else /*!HAVE_W32_SYSTEM*/
err = gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pth);
if (err)
{
log_fatal ("can't register GNU Pth with Libgcrypt: %s\n",
gpg_strerror (err));
}
-#endif /*USE_GNU_PTH && !HAVE_W32_SYSTEM*/
-#ifdef HAVE_W32_SYSTEM
- pth_init ();
-#endif
+# endif/*!HAVE_W32_SYSTEM*/
+#endif /*USE_GNU_PTH*/
/* Check that the libraries are suitable. Do it here because
the option parsing may need services of the library. */
@@ -716,12 +717,11 @@
}
/* Make sure that we have a default ttyname. */
-#ifndef HAVE_W32_SYSTEM
if (!default_ttyname && ttyname (1))
default_ttyname = xstrdup (ttyname (1));
if (!default_ttytype && getenv ("TERM"))
default_ttytype = xstrdup (getenv ("TERM"));
-#endif
+
if (pipe_server)
{ /* this is the simple pipe based server */
Index: gnupg/agent/protect-tool.c
diff -u gnupg/agent/protect-tool.c:1.15.2.10 gnupg/agent/protect-tool.c:1.15.2.11
--- gnupg/agent/protect-tool.c:1.15.2.10 Wed Sep 29 15:50:31 2004
+++ gnupg/agent/protect-tool.c Wed Dec 15 15:15:09 2004
@@ -35,6 +35,9 @@
#ifdef HAVE_LANGINFO_CODESET
#include <langinfo.h>
#endif
+#ifdef HAVE_DOSISH_SYSTEM
+#include <fcntl.h> /* for setmode() */
+#endif
#define JNLIB_NEED_LOG_LOGV
#include "agent.h"
@@ -262,6 +265,9 @@
size_t nread, bufsize = 0;
fp = stdin;
+#ifdef HAVE_DOSISH_SYSTEM
+ setmode ( fileno(fp) , O_BINARY );
+#endif
buf = NULL;
buflen = 0;
#define NCHUNK 8192
@@ -975,6 +981,9 @@
if (!key)
return;
+#ifdef HAVE_DOSISH_SYSTEM
+ setmode ( fileno (stdout) , O_BINARY );
+#endif
fwrite (key, keylen, 1, stdout);
xfree (key);
}
@@ -1056,12 +1065,12 @@
gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0);
-#ifdef __MINGW32__
+#ifdef HAVE_W32_SYSTEM
opt_homedir = read_w32_registry_string ( NULL,
"Software\\GNU\\GnuPG", "HomeDir" );
-#else
+#else /*!HAVE_W32_SYSTEM*/
opt_homedir = getenv ("GNUPGHOME");
-#endif
+#endif /*!HAVE_W32_SYSTEM*/
if (!opt_homedir || !*opt_homedir)
opt_homedir = GNUPG_DEFAULT_HOMEDIR;
@@ -1213,9 +1222,10 @@
if (!pw)
{
if (err)
- log_error ("error while asking for the passphrase\n");
+ log_error (_("error while asking for the passphrase: %s\n"),
+ gpg_strerror (err));
else
- log_info ("cancelled\n");
+ log_info (_("cancelled\n"));
agent_exit (0);
}
Index: gnupg/common/ChangeLog
diff -u gnupg/common/ChangeLog:1.30.2.33 gnupg/common/ChangeLog:1.30.2.34
--- gnupg/common/ChangeLog:1.30.2.33 Tue Dec 7 12:21:40 2004
+++ gnupg/common/ChangeLog Wed Dec 15 15:15:09 2004
@@ -1,3 +1,18 @@
+2004-12-15 Werner Koch <wk at g10code.com>
+
+ * sysutils.h [W32]: Prototypes for registry functions.
+ * w32reg.c: Include sysutils.h
+
+ * simple-pwquery.c [W32]: Dummy code to allow a build.
+
+ * exechelp.c [W32]: Implemented for W32 .
+
+ * ttyname.c: New.
+
+ * asshelp.c (send_one_option): New.
+ (send_pinentry_environment): Cleaned up and made sure that empty
+ values are not send.
+
2004-12-07 Werner Koch <wk at g10code.com>
* asshelp.c (send_pinentry_environment) [W32]: Do not use ttyname.
Index: gnupg/common/asshelp.c
diff -u gnupg/common/asshelp.c:1.1.2.2 gnupg/common/asshelp.c:1.1.2.3
--- gnupg/common/asshelp.c:1.1.2.2 Tue Dec 7 12:21:40 2004
+++ gnupg/common/asshelp.c Wed Dec 15 15:15:09 2004
@@ -32,8 +32,32 @@
#include "asshelp.h"
-/* Send the assuan command pertaining to the pinenry environment. The
- OPT_* arguments are optional and may be used to overide the
+
+static gpg_error_t
+send_one_option (assuan_context_t ctx, const char *name, const char *value)
+{
+ gpg_error_t err;
+ char *optstr;
+
+ if (!value || !*value)
+ err = 0; /* Avoid sending empty strings. */
+ else if (asprintf (&optstr, "OPTION %s=%s", name, value ) < 0)
+ err = gpg_error_from_errno (errno);
+ else
+ {
+ assuan_error_t ae;
+
+ ae = assuan_transact (ctx, optstr, NULL, NULL, NULL, NULL, NULL, NULL);
+ err = ae? map_assuan_err (ae) : 0;
+ free (optstr);
+ }
+
+ return err;
+}
+
+
+/* Send the assuan commands pertaining to the pinenry environment. The
+ OPT_* arguments are optional and may be used to override the
defaults taken from the current locale. */
gpg_error_t
send_pinentry_environment (assuan_context_t ctx,
@@ -43,62 +67,49 @@
const char *opt_lc_ctype,
const char *opt_lc_messages)
{
- int rc = 0;
+ gpg_error_t err = 0;
char *dft_display = NULL;
char *dft_ttyname = NULL;
char *dft_ttytype = NULL;
char *old_lc = NULL;
char *dft_lc = NULL;
+ /* Send the DISPLAY variable. */
dft_display = getenv ("DISPLAY");
if (opt_display || dft_display)
{
- char *optstr;
- if (asprintf (&optstr, "OPTION display=%s",
- opt_display ? opt_display : dft_display) < 0)
- return gpg_error_from_errno (errno);
- rc = assuan_transact (ctx, optstr, NULL, NULL, NULL, NULL, NULL,
- NULL);
- free (optstr);
- if (rc)
- return map_assuan_err (rc);
+ err = send_one_option (ctx, "display",
+ opt_display ? opt_display : dft_display);
+ if (err)
+ return err;
}
+
+ /* Send the name of the TTY. */
if (!opt_ttyname)
{
dft_ttyname = getenv ("GPG_TTY");
-#ifdef HAVE_DOSISH_SYSTEM
- if (!dft_ttyname || !*dft_ttyname )
- dft_ttyname = "/dev/tty"; /* Use a fake. */
-#else
if ((!dft_ttyname || !*dft_ttyname) && ttyname (0))
dft_ttyname = ttyname (0);
-#endif
}
if (opt_ttyname || dft_ttyname)
{
- char *optstr;
- if (asprintf (&optstr, "OPTION ttyname=%s",
- opt_ttyname ? opt_ttyname : dft_ttyname) < 0)
- return gpg_error_from_errno (errno);
- rc = assuan_transact (ctx, optstr, NULL, NULL, NULL, NULL, NULL,
- NULL);
- free (optstr);
- if (rc)
- return map_assuan_err (rc);
+ err = send_one_option (ctx, "ttyname",
+ opt_ttyname ? opt_ttyname : dft_ttyname);
+ if (err)
+ return err;
}
+
+ /* Send the type of the TTY. */
dft_ttytype = getenv ("TERM");
if (opt_ttytype || (dft_ttyname && dft_ttytype))
{
- char *optstr;
- if (asprintf (&optstr, "OPTION ttytype=%s",
- opt_ttyname ? opt_ttytype : dft_ttytype) < 0)
- return gpg_error_from_errno (errno);
- rc = assuan_transact (ctx, optstr, NULL, NULL, NULL, NULL, NULL,
- NULL);
- free (optstr);
- if (rc)
- return map_assuan_err (rc);
+ err = send_one_option (ctx, "ttytype",
+ opt_ttyname ? opt_ttytype : dft_ttytype);
+ if (err)
+ return err;
}
+
+ /* Send the value for LC_CTYPE. */
#if defined(HAVE_SETLOCALE) && defined(LC_CTYPE)
old_lc = setlocale (LC_CTYPE, NULL);
if (old_lc)
@@ -111,18 +122,8 @@
#endif
if (opt_lc_ctype || (dft_ttyname && dft_lc))
{
- char *optstr;
- if (asprintf (&optstr, "OPTION lc-ctype=%s",
- opt_lc_ctype ? opt_lc_ctype : dft_lc) < 0)
- rc = gpg_error_from_errno (errno);
- else
- {
- rc = assuan_transact (ctx, optstr, NULL, NULL, NULL, NULL, NULL,
- NULL);
- free (optstr);
- if (rc)
- rc = map_assuan_err (rc);
- }
+ err = send_one_option (ctx, "lc-ctype",
+ opt_lc_ctype ? opt_lc_ctype : dft_lc);
}
#if defined(HAVE_SETLOCALE) && defined(LC_CTYPE)
if (old_lc)
@@ -131,8 +132,10 @@
free (old_lc);
}
#endif
- if (rc)
- return rc;
+ if (err)
+ return err;
+
+ /* Send the value for LC_MESSAGES. */
#if defined(HAVE_SETLOCALE) && defined(LC_MESSAGES)
old_lc = setlocale (LC_MESSAGES, NULL);
if (old_lc)
@@ -145,18 +148,8 @@
#endif
if (opt_lc_messages || (dft_ttyname && dft_lc))
{
- char *optstr;
- if (asprintf (&optstr, "OPTION lc-messages=%s",
- opt_lc_messages ? opt_lc_messages : dft_lc) < 0)
- rc = gpg_error_from_errno (errno);
- else
- {
- rc = assuan_transact (ctx, optstr, NULL, NULL, NULL, NULL, NULL,
- NULL);
- free (optstr);
- if (rc)
- rc = map_assuan_err (rc);
- }
+ err = send_one_option (ctx, "display",
+ opt_lc_messages ? opt_lc_messages : dft_lc);
}
#if defined(HAVE_SETLOCALE) && defined(LC_MESSAGES)
if (old_lc)
@@ -165,7 +158,9 @@
free (old_lc);
}
#endif
+ if (err)
+ return err;
- return rc;
+ return 0;
}
Index: gnupg/common/exechelp.c
diff -u gnupg/common/exechelp.c:1.1.2.1 gnupg/common/exechelp.c:1.1.2.2
--- gnupg/common/exechelp.c:1.1.2.1 Mon Dec 6 19:28:56 2004
+++ gnupg/common/exechelp.c Wed Dec 15 15:15:09 2004
@@ -30,8 +30,7 @@
#ifdef USE_GNU_PTH
#include <pth.h>
#endif
-#ifdef _WIN32
-#else
+#ifndef HAVE_W32_SYSTEM
#include <sys/wait.h>
#endif
@@ -39,6 +38,9 @@
#include "i18n.h"
#include "exechelp.h"
+/* Define to 1 do enable debugging. */
+#define DEBUG_W32_SPAWN 1
+
#ifdef _POSIX_OPEN_MAX
#define MAX_OPEN_FDS _POSIX_OPEN_MAX
@@ -57,6 +59,105 @@
#endif
+#ifdef HAVE_W32_SYSTEM
+/* We assume that a HANDLE can be represented by an int which should
+ be true for all i386 systems (HANDLE is defined as void *) and
+ these are the only systems for which Windows is available. Further
+ we assume that -1 denotes an invalid handle. */
+# define fd_to_handle(a) ((HANDLE)(a))
+# define handle_to_fd(a) ((int)(a))
+# define pid_to_handle(a) ((HANDLE)(a))
+# define handle_to_pid(a) ((int)(a))
+#endif
+
+
+#ifdef HAVE_W32_SYSTEM
+/* Build a command line for use with W32's CreateProcess. On success
+ CMDLINE gets the address of a newly allocated string. */
+static gpg_error_t
+build_w32_commandline (const char *pgmname, const char **argv, char **cmdline)
+{
+ int i, n;
+ const char *s;
+ char *buf, *p;
+
+ *cmdline = NULL;
+ n = strlen (pgmname);
+ for (i=0; (s=argv[i]); i++)
+ {
+ n += strlen (s) + 1 + 2; /* (1 space, 2 quoting */
+ for (; *s; s++)
+ if (*s == '\"')
+ n++; /* Need to double inner quotes. */
+ }
+ n++;
+
+ buf = p = xtrymalloc (n);
+ if (!buf)
+ return gpg_error_from_errno (errno);
+
+ /* fixme: PGMNAME may not contain spaces etc. */
+ p = stpcpy (p, pgmname);
+ for (i=0; argv[i]; i++)
+ {
+ if (!*argv[i]) /* Empty string. */
+ p = stpcpy (p, " \"\"");
+ else if (strpbrk (argv[i], " \t\n\v\f\""))
+ {
+ p = stpcpy (p, " \"");
+ for (s=argv[i]; *s; s++)
+ {
+ *p++ = *s;
+ if (*s == '\"')
+ *p++ = *s;
+ }
+ *p++ = '\"';
+ *p = 0;
+ }
+ else
+ p = stpcpy (stpcpy (p, " "), argv[i]);
+ }
+
+ *cmdline= buf;
+ return 0;
+}
+#endif /*HAVE_W32_SYSTEM*/
+
+
+#ifdef HAVE_W32_SYSTEM
+/* Create pipe where the write end is inheritable. */
+static int
+create_inheritable_pipe (int filedes[2])
+{
+ HANDLE r, w, h;
+ SECURITY_ATTRIBUTES sec_attr;
+
+ memset (&sec_attr, 0, sizeof sec_attr );
+ sec_attr.nLength = sizeof sec_attr;
+ sec_attr.bInheritHandle = FALSE;
+
+ if (!CreatePipe (&r, &w, &sec_attr, 0))
+ return -1;
+
+ if (!DuplicateHandle (GetCurrentProcess(), w,
+ GetCurrentProcess(), &h, 0,
+ TRUE, DUPLICATE_SAME_ACCESS ))
+ {
+ log_error ("DuplicateHandle failed: %s\n", w32_strerror (-1));
+ CloseHandle (r);
+ CloseHandle (w);
+ return -1;
+ }
+ CloseHandle (w);
+ w = h;
+
+ filedes[0] = handle_to_fd (r);
+ filedes[1] = handle_to_fd (w);
+ return 0;
+}
+#endif /*HAVE_W32_SYSTEM*/
+
+
/* Fork and exec the PGMNAME, connect the file descriptor of INFILE to
stdin, write the output to OUTFILE, return a new stream in
@@ -73,10 +174,121 @@
void (*preexec)(void),
FILE **statusfile, pid_t *pid)
{
-#ifdef _WIN32
- return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
+#ifdef HAVE_W32_SYSTEM
+ gpg_error_t err;
+ SECURITY_ATTRIBUTES sec_attr;
+ PROCESS_INFORMATION pi =
+ {
+ NULL, /* Returns process handle. */
+ 0, /* Returns primary thread handle. */
+ 0, /* Returns pid. */
+ 0 /* Returns tid. */
+ };
+ STARTUPINFO si;
+ int cr_flags;
+ char *cmdline;
+ int fd, fdout, rp[2];
+
+ /* Setup return values. */
+ *statusfile = NULL;
+ *pid = (pid_t)(-1);
+ fflush (infile);
+ rewind (infile);
+ fd = _get_osfhandle (fileno (infile));
+ fdout = _get_osfhandle (fileno (outfile));
+ if (fd == -1 || fdout == -1)
+ log_fatal ("no file descriptor for file passed to gnupg_spawn_process\n");
+
+ /* Prepare security attributes. */
+ memset (&sec_attr, 0, sizeof sec_attr );
+ sec_attr.nLength = sizeof sec_attr;
+ sec_attr.bInheritHandle = FALSE;
+
+ /* Build the command line. */
+ err = build_w32_commandline (pgmname, argv, &cmdline);
+ if (err)
+ return err;
+
+ /* Create a pipe. */
+ if (create_inheritable_pipe (rp))
+ {
+ err = gpg_error (GPG_ERR_GENERAL);
+ log_error (_("error creating a pipe: %s\n"), gpg_strerror (err));
+ xfree (cmdline);
+ return err;
+ }
+
+ /* Start the process. Note that we can't run the PREEXEC function
+ because this would change our own environment. */
+ memset (&si, 0, sizeof si);
+ si.cb = sizeof (si);
+ si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
+ si.wShowWindow = DEBUG_W32_SPAWN? SW_SHOW : SW_MINIMIZE;
+ si.hStdInput = fd_to_handle (fd);
+ si.hStdOutput = fd_to_handle (fdout);
+ si.hStdError = fd_to_handle (rp[1]);
+
+ cr_flags = (CREATE_DEFAULT_ERROR_MODE
+ | GetPriorityClass (GetCurrentProcess ())
+ | CREATE_SUSPENDED);
+ log_debug ("CreateProcess, path=`%s' cmdline=`%s'", pgmname, cmdline);
+ if (!CreateProcess (pgmname, /* Program to start. */
+ cmdline, /* Command line arguments. */
+ &sec_attr, /* Process security attributes. */
+ &sec_attr, /* Thread security attributes. */
+ TRUE, /* Inherit handles. */
+ cr_flags, /* Creation flags. */
+ NULL, /* Environment. */
+ NULL, /* Use current drive/directory. */
+ &si, /* Startup information. */
+ &pi /* Returns process information. */
+ ))
+ {
+ log_error ("CreateProcess failed: %s\n", w32_strerror (-1));
+ xfree (cmdline);
+ CloseHandle (fd_to_handle (rp[0]));
+ CloseHandle (fd_to_handle (rp[1]));
+ return gpg_error (GPG_ERR_GENERAL);
+ }
+ xfree (cmdline);
+ cmdline = NULL;
-#else /* !_WIN32 */
+ /* Close the other end of the pipe. */
+ CloseHandle (fd_to_handle (rp[1]));
+
+ log_debug ("CreateProcess ready: hProcess=%p hThread=%p"
+ " dwProcessID=%d dwThreadId=%d\n",
+ pi.hProcess, pi.hThread,
+ (int) pi.dwProcessId, (int) pi.dwThreadId);
+
+ /* Process ha been created suspended; resume it now. */
+ ResumeThread (pi.hThread);
+ CloseHandle (pi.hThread);
+
+ {
+ int x;
+
+ x = _open_osfhandle (rp[0], 0);
+ if (x == -1)
+ log_error ("failed to translate osfhandle %p\n", (void*)rp[0] );
+ else
+ {
+ log_debug ("_open_osfhandle %p yields %d\n", (void*)fd, x );
+ *statusfile = fdopen (x, "r");
+ }
+ }
+ if (!*statusfile)
+ {
+ err = gpg_error_from_errno (errno);
+ log_error (_("can't fdopen pipe for reading: %s\n"), gpg_strerror (err));
+ CloseHandle (pi.hProcess);
+ return err;
+ }
+
+ *pid = handle_to_pid (pi.hProcess);
+ return 0;
+
+#else /* !HAVE_W32_SYSTEM */
gpg_error_t err;
int fd, fdout, rp[2];
@@ -87,8 +299,7 @@
fd = fileno (infile);
fdout = fileno (outfile);
if (fd == -1 || fdout == -1)
- log_fatal ("no file descriptor for file passed"
- " to gnupg_spawn_process: %s\n", strerror (errno) );
+ log_fatal ("no file descriptor for file passed to gnupg_spawn_process\n");
if (pipe (rp) == -1)
{
@@ -170,7 +381,7 @@
}
return 0;
-#endif /* !_WIN32 */
+#endif /* !HAVE_W32_SYSTEM */
}
@@ -183,10 +394,51 @@
{
gpg_err_code_t ec;
-#ifdef _WIN32
- ec = GPG_ERR_NOT_IMPLEMENTED;
+#ifdef HAVE_W32_SYSTEM
+ HANDLE proc = fd_to_handle (pid);
+ int code;
+ DWORD exc;
+
+ if (pid == (pid_t)(-1))
+ return gpg_error (GPG_ERR_INV_VALUE);
+
+ /* FIXME: We should do a pth_waitpid here. However this has not yet
+ been implemented. A special W32 pth system call would even be
+ better. */
+ code = WaitForSingleObject (proc, INFINITE);
+ switch (code)
+ {
+ case WAIT_FAILED:
+ log_error (_("waiting for process %d to terminate failed: %s\n"),
+ (int)pid, w32_strerror (-1));
+ ec = GPG_ERR_GENERAL;
+ break;
+
+ case WAIT_OBJECT_0:
+ if (!GetExitCodeProcess (proc, &exc))
+ {
+ log_error (_("error getting exit code of process %d: %s\n"),
+ (int)pid, w32_strerror (-1) );
+ ec = GPG_ERR_GENERAL;
+ }
+ else if (exc)
+ {
+ log_error (_("error running `%s': exit status %d\n"),
+ pgmname, (int)exc );
+ ec = GPG_ERR_GENERAL;
+ }
+ else
+ ec = 0;
+ break;
+
+ default:
+ log_error ("WaitForSingleObject returned unexpected "
+ "code %d for pid %d\n", code, (int)pid );
+ ec = GPG_ERR_GENERAL;
+ break;
+ }
-#else /* !_WIN32 */
+#else /* !HAVE_W32_SYSTEM */
int i, status;
if (pid == (pid_t)(-1))
@@ -222,7 +474,7 @@
}
else
ec = 0;
-#endif /* !_WIN32 */
+#endif /* !HAVE_W32_SYSTEM */
return gpg_err_make (GPG_ERR_SOURCE_DEFAULT, ec);
Index: gnupg/common/iobuf.c
diff -u gnupg/common/iobuf.c:1.1.2.1 gnupg/common/iobuf.c:1.1.2.2
--- gnupg/common/iobuf.c:1.1.2.1 Tue Sep 23 19:48:32 2003
+++ gnupg/common/iobuf.c Wed Dec 15 15:15:09 2004
@@ -1096,7 +1096,7 @@
if (s && *s)
{
#if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__)
- remove_name = m_strdup (s);
+ remove_name = xstrdup (s);
#else
remove (s);
#endif
@@ -1267,7 +1267,7 @@
size_t len;
a = iobuf_alloc (strchr (mode, 'w') ? 2 : 1, 8192);
- scx = m_alloc (sizeof *scx + 25);
+ scx = xmalloc (sizeof *scx + 25);
scx->sock = fd;
scx->print_only_name = 1;
sprintf (scx->fname, "[sock %d]", fd);
Index: gnupg/common/simple-pwquery.c
diff -u gnupg/common/simple-pwquery.c:1.1.2.6 gnupg/common/simple-pwquery.c:1.1.2.7
--- gnupg/common/simple-pwquery.c:1.1.2.6 Mon Dec 13 16:49:56 2004
+++ gnupg/common/simple-pwquery.c Wed Dec 15 15:15:09 2004
@@ -31,7 +31,7 @@
#include <string.h>
#include <errno.h>
#include <unistd.h>
-#ifdef _WIN32
+#ifdef HAVE_W32_SYSTEM
#include <winsock2.h>
#else
#include <sys/socket.h>
@@ -182,10 +182,8 @@
}
dft_ttyname = getenv ("GPG_TTY");
-#ifndef HAVE_W32_SYSTEM
if ((!dft_ttyname || !*dft_ttyname) && ttyname (0))
dft_ttyname = ttyname (0);
-#endif
if (dft_ttyname && *dft_ttyname)
{
if ((rc=agent_send_option (fd, "ttyname", dft_ttyname)))
@@ -261,7 +259,7 @@
static int
agent_open (int *rfd)
{
-#ifdef _WIN32
+#ifdef HAVE_W32_SYSTEM
return SPWQ_NO_AGENT; /* FIXME */
#else
int rc;
Index: gnupg/common/sysutils.h
diff -u gnupg/common/sysutils.h:1.1.2.1 gnupg/common/sysutils.h:1.1.2.2
--- gnupg/common/sysutils.h:1.1.2.1 Tue May 11 11:54:52 2004
+++ gnupg/common/sysutils.h Wed Dec 15 15:15:09 2004
@@ -27,5 +27,12 @@
const unsigned char *get_session_marker (size_t *rlen);
int check_permissions (const char *path,int extension,int checkonly);
+#ifdef HAVE_W32_SYSTEM
+/*-- w32reg.c --*/
+char *read_w32_registry_string( const char *root,
+ const char *dir, const char *name );
+int write_w32_registry_string(const char *root, const char *dir,
+ const char *name, const char *value);
+#endif /*HAVE_W32_SYSTEM*/
#endif /*GNUPG_COMMON_SYSUTILS_H*/
Index: gnupg/common/ttyname.c
diff -u /dev/null gnupg/common/ttyname.c:1.1.2.1
--- /dev/null Wed Dec 15 15:15:09 2004
+++ gnupg/common/ttyname.c Wed Dec 15 15:15:09 2004
@@ -0,0 +1,32 @@
+/* ttyname.c - Replacement for ttyname.
+ * Copyright (C) 2004 Free Software Foundation, Inc.
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (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
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/* This one is a simple dummy and suitable for Dosish systems. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+
+char *
+ttyname (int fd)
+{
+ return NULL;
+}
Index: gnupg/common/util.h
diff -u gnupg/common/util.h:1.12.2.10 gnupg/common/util.h:1.12.2.11
--- gnupg/common/util.h:1.12.2.10 Thu Dec 2 08:48:09 2004
+++ gnupg/common/util.h Wed Dec 15 15:15:09 2004
@@ -147,7 +147,9 @@
#ifndef HAVE_STRSEP
char *strsep (char **stringp, const char *delim);
#endif
-
+#ifndef HAVE_TTYNAME
+char *ttyname (int fd);
+#endif
/*-- some macros to replace ctype ones and avoid locale problems --*/
#define spacep(p) (*(p) == ' ' || *(p) == '\t')
Index: gnupg/common/w32reg.c
diff -u gnupg/common/w32reg.c:1.1.2.1 gnupg/common/w32reg.c:1.1.2.2
--- gnupg/common/w32reg.c:1.1.2.1 Thu Dec 2 08:48:09 2004
+++ gnupg/common/w32reg.c Wed Dec 15 15:15:09 2004
@@ -19,7 +19,7 @@
*/
#include <config.h>
-#if defined (_WIN32) || defined (__CYGWIN32__)
+#ifdef HAVE_W32_SYSTEM
/* This module is only used in this environment */
#include <stdio.h>
@@ -29,6 +29,7 @@
#include <windows.h>
#include "util.h"
+#include "sysutils.h"
static HKEY
get_root_key(const char *root)
@@ -169,4 +170,4 @@
return 0;
}
-#endif /* __MINGW32__ || __CYGWIN32__ */
+#endif /*HAVE_W32_SYSTEM*/
Index: gnupg/configure.ac
diff -u gnupg/configure.ac:1.36.2.72 gnupg/configure.ac:1.36.2.73
--- gnupg/configure.ac:1.36.2.72 Tue Dec 7 12:21:40 2004
+++ gnupg/configure.ac Wed Dec 15 15:15:09 2004
@@ -218,12 +218,6 @@
AC_MSG_RESULT($enableval)
fi
-AC_MSG_CHECKING([whether the included zlib is requested])
-AC_ARG_WITH(included-zlib,
- [ --with-included-zlib use the zlib code included here],
-[g10_force_zlib=yes], [g10_force_zlib=no] )
-AC_MSG_RESULT($g10_force_zlib)
-
dnl
dnl Check whether we want to use Linux capabilities
dnl
@@ -799,6 +793,7 @@
AC_REPLACE_FUNCS(isascii)
AC_REPLACE_FUNCS(putc_unlocked)
AC_REPLACE_FUNCS(strsep)
+AC_REPLACE_FUNCS(ttyname)
@@ -923,14 +918,10 @@
dnl Do we have zlib? Must do it here because Solaris failed
dnl when compiling a conftest (due to the "-lz" from LIBS).
-use_local_zlib=yes
-if test "$g10_force_zlib" = "yes"; then
- :
-else
- _cppflags="${CPPFLAGS}"
- _ldflags="${LDFLAGS}"
+_cppflags="${CPPFLAGS}"
+_ldflags="${LDFLAGS}"
- AC_ARG_WITH(zlib,
+AC_ARG_WITH(zlib,
[ --with-zlib=DIR use libz in DIR],[
if test -d "$withval"; then
CPPFLAGS="${CPPFLAGS} -I$withval/include"
@@ -938,23 +929,12 @@
fi
])
- AC_CHECK_HEADER(zlib.h,
+AC_CHECK_HEADER(zlib.h,
AC_CHECK_LIB(z, deflateInit2_,
- use_local_zlib=no
LIBS="$LIBS -lz",
CPPFLAGS=${_cppflags} LDFLAGS=${_ldflags}),
CPPFLAGS=${_cppflags} LDFLAGS=${_ldflags})
-fi
-if test "$use_local_zlib" = yes ; then
- AM_CONDITIONAL(ENABLE_LOCAL_ZLIB, true)
- AC_CONFIG_LINKS(zlib.h:zlib/zlib.h zconf.h:zlib/zconf.h )
- ZLIBS="../zlib/libzlib.a"
-else
- AM_CONDITIONAL(ENABLE_LOCAL_ZLIB, false)
- ZLIBS=
-fi
-AC_SUBST(ZLIBS)
# See wether we want to run the long test suite.
Index: gnupg/g10/call-agent.c
diff -u gnupg/g10/call-agent.c:1.1.2.15 gnupg/g10/call-agent.c:1.1.2.16
--- gnupg/g10/call-agent.c:1.1.2.15 Thu Jul 1 19:42:09 2004
+++ gnupg/g10/call-agent.c Wed Dec 15 15:15:08 2004
@@ -171,6 +171,8 @@
if (rc)
return map_assuan_err (rc);
+#warning put this code into common/asshelp.c
+
dft_display = getenv ("DISPLAY");
if (opt.display || dft_display)
{
Index: gnupg/jnlib/ChangeLog
diff -u gnupg/jnlib/ChangeLog:1.3.2.26 gnupg/jnlib/ChangeLog:1.3.2.27
--- gnupg/jnlib/ChangeLog:1.3.2.26 Tue Dec 14 20:20:36 2004
+++ gnupg/jnlib/ChangeLog Wed Dec 15 15:15:08 2004
@@ -1,3 +1,7 @@
+2004-12-15 Werner Koch <wk at g10code.com>
+
+ * logging.c [W32]: Don't include unavailable headers.
+
2004-12-14 Werner Koch <wk at g10code.com>
* w32-pth.c (_pth_strerror): Renamed to ...
Index: gnupg/jnlib/logging.c
diff -u gnupg/jnlib/logging.c:1.2.2.11 gnupg/jnlib/logging.c:1.2.2.12
--- gnupg/jnlib/logging.c:1.2.2.11 Thu Dec 2 08:48:09 2004
+++ gnupg/jnlib/logging.c Wed Dec 15 15:15:08 2004
@@ -35,16 +35,13 @@
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
-#ifndef _WIN32
+#ifndef HAVE_W32_SYSTEM
#include <sys/socket.h>
#include <sys/un.h>
-#endif
+#endif /*!HAVE_W32_SYSTEM*/
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
-#ifdef __MINGW32__
-# include <io.h>
-#endif
#define JNLIB_NEED_LOG_LOGV 1
Index: gnupg/m4/ksba.m4
diff -u gnupg/m4/ksba.m4:1.1.2.1 gnupg/m4/ksba.m4:1.1.2.2
--- gnupg/m4/ksba.m4:1.1.2.1 Wed Feb 18 19:38:49 2004
+++ gnupg/m4/ksba.m4 Wed Dec 15 15:15:08 2004
@@ -14,7 +14,7 @@
dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
dnl Test for libksba and define KSBA_CFLAGS and KSBA_LIBS
dnl
-AC_DEFUN(AM_PATH_KSBA,
+AC_DEFUN([AM_PATH_KSBA],
[ AC_ARG_WITH(ksba-prefix,
AC_HELP_STRING([--with-ksba-prefix=PFX],
[prefix where KSBA is installed (optional)]),
Index: gnupg/scd/ChangeLog
diff -u gnupg/scd/ChangeLog:1.25.2.59 gnupg/scd/ChangeLog:1.25.2.60
--- gnupg/scd/ChangeLog:1.25.2.59 Mon Dec 6 14:49:14 2004
+++ gnupg/scd/ChangeLog Wed Dec 15 15:15:08 2004
@@ -1,3 +1,14 @@
+2004-12-15 Werner Koch <wk at g10code.com>
+
+ * scdaemon.c [W32]: Various hacks to make it run under W32.
+
+ * command.c (scd_update_reader_status_file) [W32]: Don't use kill.
+
+ * apdu.c [W32]: Disable use of pcsc_wrapper.
+
+ * Makefile.am (scdaemon_LDADD): Reorder libs.
+ (sc_copykeys_LDADD): Add libassuan because it is needed for W32.
+
2004-12-06 Werner Koch <wk at g10code.com>
* Makefile.am (pkglib_PROGRAMS): Build only for W32.
Index: gnupg/scd/Makefile.am
diff -u gnupg/scd/Makefile.am:1.15.2.11 gnupg/scd/Makefile.am:1.15.2.12
--- gnupg/scd/Makefile.am:1.15.2.11 Mon Dec 6 14:49:14 2004
+++ gnupg/scd/Makefile.am Wed Dec 15 15:15:08 2004
@@ -19,7 +19,7 @@
## Process this file with automake to produce Makefile.in
bin_PROGRAMS = scdaemon sc-copykeys
-if HAVE_W32_SYSTEM
+if ! HAVE_W32_SYSTEM
pkglib_PROGRAMS = pcsc-wrapper
endif
@@ -53,10 +53,8 @@
scdaemon_LDADD = ../jnlib/libjnlib.a ../common/libcommon.a \
- $(LIBGCRYPT_LIBS) $(pth_libs) \
- $(KSBA_LIBS) $(LIBASSUAN_LIBS) \
- $(LIBUSB_LIBS) $(OPENSC_LIBS) -lgpg-error @LIBINTL@ \
- @DL_LIBS@
+ $(LIBGCRYPT_LIBS) $(KSBA_LIBS) $(pth_libs) $(LIBASSUAN_LIBS) \
+ $(LIBUSB_LIBS) $(OPENSC_LIBS) -lgpg-error $(LIBINTL) $(DL_LIBS)
sc_copykeys_SOURCES = \
sc-copykeys.c scdaemon.h \
@@ -70,10 +68,10 @@
sc_copykeys_LDADD = \
../jnlib/libjnlib.a ../common/libcommon.a \
../common/libsimple-pwquery.a \
- $(LIBGCRYPT_LIBS) $(pth_libs) \
- $(KSBA_LIBS) $(LIBUSB_LIBS) $(OPENSC_LIBS) \
+ $(LIBGCRYPT_LIBS) $(pth_libs) $(KSBA_LIBS) $(LIBASSUAN_LIBS) \
+ $(LIBUSB_LIBS) $(OPENSC_LIBS) \
-lgpg-error @LIBINTL@ @DL_LIBS@
pcsc_wrapper_SOURCES = pcsc-wrapper.c
-pcsc_wrapper_LDADD = @DL_LIBS@
+pcsc_wrapper_LDADD = $(DL_LIBS)
pcsc_wrapper_CFLAGS =
Index: gnupg/scd/apdu.c
diff -u gnupg/scd/apdu.c:1.4.2.24 gnupg/scd/apdu.c:1.4.2.25
--- gnupg/scd/apdu.c:1.4.2.24 Wed Oct 20 10:54:45 2004
+++ gnupg/scd/apdu.c Wed Dec 15 15:15:08 2004
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: apdu.c,v 1.4.2.24 2004/10/20 08:54:45 wk Exp $
+ * $Id: apdu.c,v 1.4.2.25 2004/12/15 14:15:08 wk Exp $
*/
#include <config.h>
@@ -65,11 +65,16 @@
#include "dynload.h"
#include "ccid-driver.h"
+
+/* To to conflicting use of threading libraries we usually can't link
+ against libpcsclite. Instead we use a wrapper program. */
#ifdef USE_GNU_PTH
+#ifndef HAVE_W32_SYSTEM
#define NEED_PCSC_WRAPPER 1
#endif
+#endif
-
+
#define MAX_READER 4 /* Number of readers we support concurrently. */
Index: gnupg/scd/command.c
diff -u gnupg/scd/command.c:1.19.2.13 gnupg/scd/command.c:1.19.2.14
--- gnupg/scd/command.c:1.19.2.13 Wed Apr 21 16:44:09 2004
+++ gnupg/scd/command.c Wed Dec 15 15:15:08 2004
@@ -1260,8 +1260,13 @@
int signo = primary_connection->server_local->event_signal;
log_info ("client pid is %d, sending signal %d\n", pid, signo);
+
+#ifdef HAVE_W32_SYSTEM
+#warning Need to implement a notification service
+#else
if (pid != (pid_t)(-1) && pid && signo > 0)
kill (pid, signo);
+#endif
}
}
}
Index: gnupg/scd/scdaemon.c
diff -u gnupg/scd/scdaemon.c:1.12.2.20 gnupg/scd/scdaemon.c:1.12.2.21
--- gnupg/scd/scdaemon.c:1.12.2.20 Thu Aug 5 11:24:35 2004
+++ gnupg/scd/scdaemon.c Wed Dec 15 15:15:08 2004
@@ -29,8 +29,10 @@
#include <assert.h>
#include <time.h>
#include <fcntl.h>
+#ifndef HAVE_W32_SYSTEM
#include <sys/socket.h>
#include <sys/un.h>
+#endif /*HAVE_W32_SYSTEM*/
#include <unistd.h>
#include <signal.h>
#ifdef USE_GNU_PTH
@@ -47,6 +49,9 @@
#include "i18n.h"
#include "sysutils.h"
#include "app-common.h"
+#ifdef HAVE_W32_SYSTEM
+#include "../jnlib/w32-afunix.h"
+#endif
enum cmd_and_opt_values
@@ -131,7 +136,12 @@
};
+/* The card dirver we use by default for PC/SC. */
+#ifdef HAVE_W32_SYSTEM
+#define DEFAULT_PCSC_DRIVER "winscard.dll"
+#else
#define DEFAULT_PCSC_DRIVER "libpcsclite.so"
+#endif
static volatile int caught_fatal_sig = 0;
@@ -148,8 +158,10 @@
#ifndef HAVE_OPENSC
#ifdef USE_GNU_PTH
+#ifndef HAVE_W32_SYSTEM
/* Pth wrapper function definitions. */
GCRY_THREAD_OPTION_PTH_IMPL;
+#endif
static void *ticker_thread (void *arg);
#endif /*USE_GNU_PTH*/
@@ -341,12 +353,16 @@
Note that this will also do the pth_init. */
#ifndef HAVE_OPENSC
#ifdef USE_GNU_PTH
+# ifdef HAVE_W32_SYSTEM
+ pth_init ();
+# else /*!HAVE_W32_SYSTEM*/
err = gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pth);
if (err)
{
log_fatal ("can't register GNU Pth with Libgcrypt: %s\n",
gpg_strerror (err));
}
+# endif /*!HAVE_W32_SYSTEM*/
#endif /*USE_GNU_PTH*/
#endif /*!HAVE_OPENSC*/
@@ -649,12 +665,15 @@
if (!p)
BUG ();
*p = 0;;
+
+#ifndef HAVE_W32_SYSTEM
if (!mkdtemp(socket_name))
{
log_error ("can't create directory `%s': %s\n",
socket_name, strerror(errno) );
exit (1);
}
+#endif
*p = '/';
if (strchr (socket_name, ':') )
@@ -669,7 +688,11 @@
}
+#ifdef HAVE_W32_SYSTEM
+ fd = _w32_sock_new (AF_UNIX, SOCK_STREAM, 0);
+#else
fd = socket (AF_UNIX, SOCK_STREAM, 0);
+#endif
if (fd == -1)
{
log_error ("can't create socket: %s\n", strerror(errno) );
@@ -682,7 +705,13 @@
len = (offsetof (struct sockaddr_un, sun_path)
+ strlen(serv_addr.sun_path) + 1);
- if (bind (fd, (struct sockaddr*)&serv_addr, len) == -1)
+ if (
+#ifdef HAVE_W32_SYSTEM
+ _w32_sock_bind
+#else
+ bind
+#endif
+ (fd, (struct sockaddr*)&serv_addr, len) == -1)
{
log_error ("error binding socket to `%s': %s\n",
serv_addr.sun_path, strerror (errno) );
@@ -702,6 +731,7 @@
fflush (NULL);
+#ifndef HAVE_W32_SYSTEM
pid = fork ();
if (pid == (pid_t)-1)
{
@@ -800,6 +830,8 @@
exit (1);
}
+#endif /*!HAVE_W32_SYSTEM*/
+
scd_command_handler (fd);
close (fd);
@@ -846,6 +878,7 @@
{
switch (signo)
{
+#ifndef HAVE_W32_SYSTEM
case SIGHUP:
log_info ("SIGHUP received - "
"re-reading configuration and resetting cards\n");
@@ -882,6 +915,7 @@
cleanup ();
scd_exit (0);
break;
+#endif /*!HAVE_W32_SYSTEM*/
default:
log_info ("signal %d received - no action defined\n", signo);
@@ -901,6 +935,7 @@
sigset_t sigs;
int signo;
+#ifndef HAVE_W32_SYSTEM /* fixme */
sigemptyset (&sigs );
sigaddset (&sigs, SIGHUP);
sigaddset (&sigs, SIGUSR1);
@@ -908,6 +943,9 @@
sigaddset (&sigs, SIGINT);
sigaddset (&sigs, SIGTERM);
sigs_ev = pth_event (PTH_EVENT_SIGS, &sigs, &signo);
+#else
+ sigs_ev = NULL;
+#endif
for (;;)
{
Index: gnupg/sm/Makefile.am
diff -u gnupg/sm/Makefile.am:1.27.2.3 gnupg/sm/Makefile.am:1.27.2.4
--- gnupg/sm/Makefile.am:1.27.2.3 Tue Dec 7 12:21:40 2004
+++ gnupg/sm/Makefile.am Wed Dec 15 15:15:08 2004
@@ -51,9 +51,9 @@
certreqgen.c
-gpgsm_LDADD = $(LIBASSUAN_LIBS) ../jnlib/libjnlib.a ../kbx/libkeybox.a \
- ../common/libcommon.a \
- $(LIBGCRYPT_LIBS) $(KSBA_LIBS) -lgpg-error \
- $(LIBINTL)
+gpgsm_LDADD = ../jnlib/libjnlib.a ../kbx/libkeybox.a \
+ ../common/libcommon.a \
+ $(LIBGCRYPT_LIBS) $(KSBA_LIBS) $(LIBASSUAN_LIBS) -lgpg-error \
+ $(LIBINTL)
Index: gnupg/sm/gpgsm.c
diff -u gnupg/sm/gpgsm.c:1.67.2.33 gnupg/sm/gpgsm.c:1.67.2.34
--- gnupg/sm/gpgsm.c:1.67.2.33 Mon Dec 6 19:28:56 2004
+++ gnupg/sm/gpgsm.c Wed Dec 15 15:15:08 2004
@@ -26,6 +26,9 @@
#include <ctype.h>
#include <unistd.h>
#include <fcntl.h>
+#ifdef USE_GNU_PTH
+# include <pth.h>
+#endif
#include "gpgsm.h"
#include <gcrypt.h>
@@ -736,6 +739,11 @@
NEED_KSBA_VERSION, ksba_check_version (NULL) );
}
+#ifdef HAVE_W32_SYSTEM
+ pth_init ();
+#endif
+
+
gcry_control (GCRYCTL_USE_SECURE_RNDPOOL);
may_coredump = disable_core_dumps ();
@@ -746,7 +754,8 @@
i18n_init();
opt.def_cipher_algoid = "1.2.840.113549.3.7"; /*des-EDE3-CBC*/
-#ifdef __MINGW32__
+
+#ifdef HAVE_W32_SYSTEM
opt.homedir = read_w32_registry_string ( NULL,
"Software\\GNU\\GnuPG", "HomeDir" );
#else
@@ -1688,7 +1697,7 @@
static void
run_protect_tool (int argc, char **argv)
{
-#ifndef _WIN32
+#ifndef HAVE_W32_SYSTEM
const char *pgm;
char **av;
int i;
@@ -1707,6 +1716,6 @@
av[i] = NULL;
execv (pgm, av);
log_error ("error executing `%s': %s\n", pgm, strerror (errno));
-#endif
+#endif /*HAVE_W32_SYSTEM*/
gpgsm_exit (2);
}
Index: gnupg/tools/ChangeLog
diff -u gnupg/tools/ChangeLog:1.25.2.59 gnupg/tools/ChangeLog:1.25.2.60
--- gnupg/tools/ChangeLog:1.25.2.59 Mon Dec 13 16:49:56 2004
+++ gnupg/tools/ChangeLog Wed Dec 15 15:15:08 2004
@@ -1,3 +1,13 @@
+2004-12-15 Werner Koch <wk at g10code.com>
+
+ * Makefile.am (bin_PROGRAMS) [W32]: Do not build watchgnupg.
+
+ * gpgconf-comp.c (gpg_agent_runtime_change) [W32]: No way yet to
+ send a signal. Disable.
+ (change_options_file, change_options_program) [W32]: No link(2),
+ so we disable it.
+ (gc_component_change_options): Use rename instead of link.
+
2004-12-13 Werner Koch <wk at g10code.com>
* gpgconf-comp.c <ignore-ocsp-service-url>: Fixed typo.
Index: gnupg/tools/Makefile.am
diff -u gnupg/tools/Makefile.am:1.31.2.10 gnupg/tools/Makefile.am:1.31.2.11
--- gnupg/tools/Makefile.am:1.31.2.10 Fri Oct 22 18:03:02 2004
+++ gnupg/tools/Makefile.am Wed Dec 15 15:15:08 2004
@@ -32,7 +32,10 @@
bin_SCRIPTS = gpgsm-gencert.sh
-bin_PROGRAMS = gpgconf watchgnupg
+bin_PROGRAMS = gpgconf
+if !HAVE_W32_SYSTEM
+bin_PROGRAMS += watchgnupg
+endif
gpgconf_SOURCES = gpgconf.c gpgconf.h gpgconf-comp.c no-libgcrypt.c
Index: gnupg/tools/gpgconf-comp.c
diff -u gnupg/tools/gpgconf-comp.c:1.1.2.47 gnupg/tools/gpgconf-comp.c:1.1.2.48
--- gnupg/tools/gpgconf-comp.c:1.1.2.47 Mon Dec 13 16:49:56 2004
+++ gnupg/tools/gpgconf-comp.c Wed Dec 15 15:15:08 2004
@@ -861,6 +861,7 @@
void
gpg_agent_runtime_change (void)
{
+#ifndef HAVE_W32_SYSTEM
char *agent = getenv ("GPG_AGENT_INFO");
char *pid_str;
unsigned long pid_long;
@@ -888,6 +889,7 @@
/* Ignore any errors here. */
kill (pid, SIGHUP);
+#endif /*!HAVE_W32_SYSTEM*/
}
@@ -1741,7 +1743,12 @@
arg = NULL;
}
+#if HAVE_W32_SYSTEM
+ res = 0;
+#warning no backups for W32 yet - need to write a copy function
+#else
res = link (dest_filename, orig_filename);
+#endif
if (res < 0 && errno != ENOENT)
return -1;
if (res < 0)
@@ -2005,7 +2012,12 @@
src_filename = xasprintf ("%s.gpgconf.%i.new", dest_filename, getpid ());
orig_filename = xasprintf ("%s.gpgconf.%i.bak", dest_filename, getpid ());
+#if HAVE_W32_SYSTEM
+ res = 0;
+#warning no backups for W32 yet - need to write a copy function
+#else
res = link (dest_filename, orig_filename);
+#endif
if (res < 0 && errno != ENOENT)
return -1;
if (res < 0)
@@ -2418,12 +2430,18 @@
err = rename (src_pathname[i], dest_pathname[i]);
else
{
+#ifdef HAVE_W32_SYSTEM
+ /* FIXME: Won't work becuase W32 doesn't silently
+ overwrite. */
+ err = rename (src_pathname[i], dest_pathname[i]);
+#else /*!HAVE_W32_SYSTEM*/
/* This is a bit safer than rename() because we
expect DEST_PATHNAME not to be there. If it
happens to be there, this will fail. */
err = link (src_pathname[i], dest_pathname[i]);
if (!err)
unlink (src_pathname[i]);
+#endif /*!HAVE_W32_SYSTEM*/
}
if (err)
break;
More information about the Gnupg-commits
mailing list