Page MenuHome GnuPG

No OneTemporary

This file is larger than 256 KB, so syntax highlighting was skipped.
diff --git a/ChangeLog b/ChangeLog
index 6c42443..f912424 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,388 +1,396 @@
+2010-11-01 Werner Koch <wk@g10code.com>
+
+ * configure.ac: Check for sys/types.h, sys/stat.h, sys/time and
+ unistd.h
+
+ * contrib/conf-w32ce-msc/build.mk: New.
+ * contrib/conf-w32ce-msc/config.h: New.
+
2010-08-19 Werner Koch <wk@g10code.com>
* configure.ac (AH_TOP, AH_BOTTOM): New. Define
GPG_ERR_ENABLE_ERRNO_MACROS.
2010-08-09 Werner Koch <wk@g10code.com>
Release 2.0.1
* configure.ac: Set LT version to C1/A1/R0.
2010-04-20 Werner Koch <wk@g10code.com>
* configure.ac: Change wording of the no-funopen warning.
2010-03-22 Werner Koch <wk@g10code.com>
* configure.ac (CC_FOR_BUILD): Add test.
2010-03-17 Werner Koch <wk@g10code.com>
* tests/ChangeLog: New. Move all relevant entries to there.
2010-02-25 Werner Koch <wk@g10code.com>
* m4/libtool.m4 (_LT_CHECK_MAGIC_METHOD): Fix for non x86 mingw
targets.
2010-02-11 Werner Koch <wk@g10code.com>
* configure.ac (inet_pton): Check for it.
2010-02-04 Werner Koch <wk@g10code.com>
* configure.ac (AC_TYPE_UINT16_T): New.
2010-01-26 Werner Koch <wk@g10code.com>
* configure.ac (NETLIBS) [W32CE]: Use -lws2.
2010-01-22 Werner Koch <wk@g10code.com>
* configure.ac: Require libgpg-error 1.8.
(HAVE_W32CE_SYSTEM): New am_defines and am_conditionals.
* ltmain.sh (wrappers_required): Don't set for mingw32ce.
* autogen.sh: Add option --build-w32ce. Remove --disable-shared
from --build-w32.
2010-01-08 Marcus Brinkmann <marcus@g10code.de>
Released 2.0.0.
2010-01-05 Marcus Brinkmann <marcus@g10code.de>
* configure.ac (_DARWIN_C_SOURCE): Define on frapple.
2009-12-22 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Do not use echo -n.
2009-12-15 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Bump version to 2.0.0.
2009-10-16 Marcus Brinkmann <marcus@g10code.de>
* autogen.sh: Remove --with-pth-prefix from configure invocation.
* configure.ac (_ASSUAN_IN_LIBASSUAN, PTH_SYSCALL_SOFT): Do not
set anymore.
(GNUPG_PATH_PTH): Don't invoke.
(HAVE_PTH): Remove conditional.
(LIBASSUAN_CONFIG_THREAD_MODULES): Removed.
2009-10-08 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: AC_REPLACE_FUNCS for vasprintf.
2009-09-19 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Check for stdint.h and inttypes.h. Invoke
AC_TYPE_UINTPTR_T.
2009-09-08 Marcus Brinkmann <marcus@g10code.de>
* m4/gpg-error.m4: New file.
2009-09-01 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Set BUILD_REVISION and update calculation of data
for build info. Update libtool macros. Set NETLIBS for W32
targets.
2009-08-26 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Test for versioned symbols support.
(LIBASSUAN_LT_CURRENT, LIBASSUAN_LT_AGE)
(LIBASSUAN_LT_REVISION): New, set to 0.
(LIBASSUAN_CONFIG_API_VERSION): Bump to 2.
(AC_CONFIG_MACRO_DIR, AC_DISABLE_STATIC, AC_LIBTOOL_WIN32_DLL)
(AC_LIBTOOL_RC, AC_PROG_LIBTOOL, AM_PATH_GPG_ERROR): Invoke.
(AC_PROG_RANLIB): Don't invoke.
(HAVE_W32_SYSTEM): New AM conditional.
(AC_CONFIG_FILES): Add src/versioninfo.rc.
* ltmain.sh, m4/libtool.m4, m4/ltoptions.m4, m4/ltsugar.m4,
m4/ltversion.m4, m4/lt~obsolete.m4: New files from libtool 2.2.6.
2009-01-22 Werner Koch <wk@g10code.com>
* configure.ac: Check for nanoleep only in libc.
2008-05-25 Werner Koch <wk@g10code.com>
Released 1.0.5.
2008-05-23 Werner Koch <wk@g10code.com>
* configure.ac: Use -fPIC with GCC under Linux.
2007-12-12 Werner Koch <wk@g10code.com>
Released 1.0.4.
* config.sub, config.guess: Update to version 2007-11-19.
2007-08-24 Werner Koch <wk@g10code.com>
Released 1.0.3.
Switched license of the library code back to LGPLv2.1. See NEWS.
* COPYING.LIB: Replaced by LPGLv2.1
2007-07-05 Werner Koch <wk@g10code.com>
Released 1.0.2.
Relicensed to LGPLv3.
* COPYING: Replaced by GPLv3.
* COPYING.LESSER: Removed.
* COPYING.LIB: New.
* Makefile.am (ACLOCAL_AMFLAGS): Do not create gzipped tarball.
2007-07-03 Werner Koch <wk@g10code.com>
* configure.ac (NETLIBS): Use ws2_32 instead of wsock32.
2007-06-15 Werner Koch <wk@g10code.com>
* autogen.sh: Use = and not == in test to be POSIXly correct.
Change shell back to /bin/sh.
2007-06-15 Marcus Brinkmann <marcus@g10code.de>
* autogen.sh: Require bash.
2007-05-30 Werner Koch <wk@g10code.com>
* autogen.sh <--build-w32>: Modernize.
2007-05-29 Werner Koch <wk@g10code.com>
* configure.ac: Require automake 1.10 and autoconf 2.61.
(AM_PROG_CC_C_O): New. Error out if no C-89 cc is installed.
(gl_HEADER_SYS_SOCKET): Explicitly add this for documentation.
2007-05-24 Werner Koch <wk@g10code.com>
* configure.ac: Use -Wpointer-arith is possible.
2006-11-22 Werner Koch <wk@g10code.com>
Released 1.0.1.
2006-11-21 Werner Koch <wk@g10code.com>
* configure.ac (AH_BOTTOM): Define PTH_SYSCALL_SOFT to 0.
(AC_INIT): Use the SVN magic.
* m4/gnupg-pth.m4 (GNUPG_PTH_VERSION_CHECK): Use --all with
pth-config.
2006-11-15 Werner Koch <wk@g10code.com>
* autogen.sh: Add convenience option --build-amd64.
2006-10-31 Werner Koch <wk@g10code.com>
Released 1.0.0.
2006-10-20 Werner Koch <wk@g10code.com>
* Makefile.am (stowinstall): New convenience target.
2006-10-10 Werner Koch <wk@g10code.com>
Released 0.9.3.
* configure.ac: Check for cmsghdr.
(USE_DESCRIPTOR_PASSING): Define it then.
2006-10-09 Werner Koch <wk@g10code.com>
* m4/gnupg-pth.m4: New. Taked from GnuPG.
2006-10-04 Werner Koch <wk@g10code.com>
Released 0.9.2.
2006-10-04 Werner Koch <wk@g10code.com>
Released 0.9.1.
* configure.ac (AB_INIT): New.
* m4/autobuild.m4: New.
2006-09-14 Werner Koch <wk@g10code.com>
Released 0.9.0.
* configure.ac: Check for S_PEERCRED. Include check for socklen_t.
* m4/sys_socket_h.m4, m4/onceonly.m4, m4/socklen.m4: New.
* m4/Makefile.am: New.
2006-09-05 Werner Koch <wk@g10code.com>
* configure.ac (AH_BOTTOM): Define _ASSUAN_IN_LIBASSUAN.
2005-10-24 Werner Koch <wk@g10code.com>
* COPYING.LESSER: Added.
* README.CVS: Renamed to ..
* README.SVN: .. this.
2005-10-08 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Check for socket library and add it to
LIBASSUAN_CONFIG_LIBS if necessary.
2005-10-07 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Invoke AC_CANONICAL_HOST. Define _XOPEN_SOURCE,
_XOPEN_SOURCE_EXTENDED and __EXTENSIONS__ on Solaris.
Add stpcy as replacement function.
Add setenv as replacement function (and check for unistd.h).
2005-06-20 Werner Koch <wk@g10code.com>
Released 0.6.10.
2004-12-22 Werner Koch <wk@g10code.com>
Released 0.6.9.
For security reasons switched to automake 1.9.
2004-12-18 Werner Koch <wk@g10code.com>
* autogen.sh: Add Option --build-w32.
2004-12-07 Werner Koch <wk@g10code.com>
* configure.ac: Define HAVE_W32_SYSTEM and HAVE_DOSISH_SYSTEM.
Add -lwsock2 to the config lib flags for W32.
2004-11-25 Werner Koch <wk@g10code.com>
Released 0.6.8.
2004-09-27 Werner Koch <wk@g10code.com>
* config.sub, config.guess: Updated.
2004-06-23 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Check for <sys/uio.h>.
2004-06-08 Werner Koch <wk@gnupg.org>
Released 0.6.6.
2004-04-02 Thomas Schwinge <schwinge@nic-nac-project.de>
* autogen.sh: Added ACLOCAL_FLAGS.
2004-02-20 Werner Koch <wk@gnupg.org>
Released 0.6.4.
2004-02-11 Werner Koch <wk@gnupg.org>
* autogen.sh (check_version): Removed bashism and simplified.
2004-01-29 Werner Koch <wk@gnupg.org>
Released 0.6.3.
2003-12-18 Werner Koch <wk@gnupg.org>
Released 0.6.2.
2003-12-08 Werner Koch <wk@gnupg.org>
* TODO: New.
* Makefile.am: Add README.CVS and autogen.sh. Removed m4/Makefile.
* README.CVS: New.
* autogen.sh: Revamped.
* configure.ac: Add automake version number for autogen.sh use.
2003-11-17 Werner Koch <wk@gnupg.org>
Released 0.6.1.
2003-08-06 Werner Koch <wk@gnupg.org>
Released 0.6.0.
2003-07-29 Werner Koch <wk@gnupg.org>
* configure.ac: Cleanups for newer autoconf.
2003-07-29 gettextize <bug-gnu-gettext@gnu.org>
* Makefile.am (EXTRA_DIST): Add config.rpath.
* configure.ac (AC_CONFIG_FILES): Add po/Makefile.in,
2003-04-28 gettextize <bug-gnu-gettext@gnu.org>
* Makefile.am (SUBDIRS): Add m4.
(ACLOCAL_AMFLAGS): New variable.
(EXTRA_DIST): New variable.
* configure.ac (AC_CONFIG_FILES): Add po/Makefile.in,
2003-02-18 Neal H. Walfield <neal@g10code.de>
* COPYING: New file.
2003-02-18 Neal H. Walfield <neal@g10code.de>
* configure.ac: Fix typo.
(AC_CONFIG_FILES): Remove common/Makefile.am.
* common: Remove directory.
2003-02-18 Neal H. Walfield <neal@g10code.de>
* common: New directory.
* Makefile.am (SUBDIRS): Add common.
* configure.ac: Check for funopen. If not present, check for
fopencookie and implement it in terms of that. Otherwise, fail.
(AC_CONFIG_FILES): Add common/Makefile.
2003-02-18 Neal H. Walfield <neal@g10code.de>
* configure.ac (AC_CONFIG_FILES): Add src/libassuan-config.
(LIBASSUAN_CONFIG_LIBS, LIBASSUAN_CONFIG_CFLAGS): New variables.
AC_SUBST them.
2003-02-17 Neal H. Walfield <neal@g10code.de>
* AUTHORS: New file.
* INSTALL: New file.
* Makefile.am: New file.
* NEWS: New file.
* README: New file.
* autogen.sh: New file, copied from newpg.
* configure.ac: New file, imported from newpg.
* depcomp: New file.
* install-sh: New file.
* missing: New file.
* mkinstalldirs: New file.
* doc: New directory.
* src: New directory.
* tests: New directory.
Copyright 2003, 2004, 2005, 2006, 2007, 2010 Free Software Foundation, Inc.
This file is free software; as a special exception the author gives
unlimited permission to copy and/or distribute it, with or without
modifications, as long as this notice is preserved.
This file is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/configure.ac b/configure.ac
index c1bdfc2..e3517e8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,365 +1,366 @@
# configure.ac - for libassuan
# Copyright (C) 2001-2003, 2006, 2007, 2009 Free Software Foundation, Inc.
#
# This file is part of Assuan.
#
# Assuan is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# Assuan 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, see <http://www.gnu.org/licenses/>.
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.61)
min_automake_version="1.10"
# Remember to change the version number immediately *after* a release.
# Set my_issvn to "yes" for non-released code. Remember to run an
# "svn up" and "autogen.sh" right before creating a distribution.
m4_define([my_version], [2.0.2])
m4_define([my_issvn], [yes])
m4_define([svn_revision], m4_esyscmd([printf "%d" $( (svn info 2>/dev/null \
|| echo 'Revision: 0')|sed -n '/^Revision:/ {s/[^0-9]//gp;q;}')]))
AC_INIT([libassuan], my_version[]m4_if(my_issvn,[yes],[-svn[]svn_revision]),
[bug-libassuan@gnupg.org])
# LT Version numbers, remember to change them just *before* a release.
# (Code changed: REVISION++)
# (Interfaces added/removed/changed: CURRENT++, REVISION=0)
# (Interfaces added: AGE++)
# (Interfaces removed/changed: AGE=0)
#
LIBASSUAN_LT_CURRENT=1
LIBASSUAN_LT_AGE=1
LIBASSUAN_LT_REVISION=0
# If the API is changed in an incompatible way: increment the next counter.
LIBASSUAN_CONFIG_API_VERSION=2
##############################################
AC_SUBST(LIBASSUAN_LT_CURRENT)
AC_SUBST(LIBASSUAN_LT_AGE)
AC_SUBST(LIBASSUAN_LT_REVISION)
BUILD_REVISION=svn_revision
PACKAGE=$PACKAGE_NAME
VERSION=$PACKAGE_VERSION
AM_INIT_AUTOMAKE
AM_MAINTAINER_MODE
AC_CONFIG_SRCDIR(src/assuan.h.in)
AC_CONFIG_MACRO_DIR(m4)
AM_CONFIG_HEADER(config.h)
AC_CANONICAL_HOST
AB_INIT
AC_GNU_SOURCE
AC_SUBST(PACKAGE)
AC_SUBST(VERSION)
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package])
AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package])
AC_DEFINE_UNQUOTED(PACKAGE_BUGREPORT, "$PACKAGE_BUGREPORT",
[Bug report address])
# Don't default to build static libs.
LT_PREREQ([2.2.6])
LT_INIT([win32-dll disable-static])
LT_LANG([Windows Resource])
# For now we hardcode the use of version scripts. It would be better
# to write a test for this or even implement this within libtool.
have_ld_version_script=no
case "${host}" in
*-*-linux*)
have_ld_version_script=yes
;;
*-*-gnu*)
have_ld_version_script=yes
;;
*-apple-darwin*)
AC_DEFINE(_XOPEN_SOURCE, 500, Activate POSIX interface on MacOS X)
AC_DEFINE(_DARWIN_C_SOURCE, 1, Activate CMSG_LEN/CMSG_SPACE on MacOS X)
;;
esac
AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
AH_TOP([
#ifndef _ASSUAN_CONFIG_H_INCLUDED
#define _ASSUAN_CONFIG_H_INCLUDED
/* Enable gpg-error's strerror macro under W32CE. */
#define GPG_ERR_ENABLE_ERRNO_MACROS 1
])
AH_BOTTOM([
#endif /*_ASSUAN_CONFIG_H_INCLUDED*/
])
# Checks for programs.
missing_dir=`cd $ac_aux_dir && pwd`
AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
AC_PROG_AWK
AC_PROG_CC
AC_PROG_CPP
AM_PROG_CC_C_O
if test "x$ac_cv_prog_cc_c89" = "xno" ; then
AC_MSG_ERROR([[No C-89 compiler found]])
fi
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
#AC_ARG_PROGRAM
# We need to compile and run a program on the build machine. A
# comment in libgpg-error says that the AC_PROG_CC_FOR_BUILD macro in
# the AC archive is broken for autoconf 2.57. Given that there is no
# newer version of that macro, we assume that it is also broken for
# autoconf 2.61 and thus we use a simple but usually sufficient
# approach.
AC_MSG_CHECKING(for cc for build)
if test "$cross_compiling" = "yes"; then
CC_FOR_BUILD="${CC_FOR_BUILD-cc}"
else
CC_FOR_BUILD="${CC_FOR_BUILD-$CC}"
fi
AC_MSG_RESULT($CC_FOR_BUILD)
AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler])
if test "$GCC" = yes; then
CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes"
AC_MSG_CHECKING([if gcc supports -Wpointer-arith])
_gcc_cflags_save=$CFLAGS
CFLAGS="-Wpointer-arith"
AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]),_gcc_wopt=yes,_gcc_wopt=no)
AC_MSG_RESULT($_gcc_wopt)
CFLAGS=$_gcc_cflags_save;
if test x"$_gcc_wopt" = xyes ; then
CFLAGS="$CFLAGS -Wpointer-arith"
fi
fi
#
# Options depending on the host OS.
#
have_dosish_system=no
have_w32_system=no
have_w32ce_system=no
case "${host}" in
*-linux*)
if test "$GCC" = yes; then
CFLAGS="$CFLAGS -fPIC -DPIC"
fi
;;
*-mingw32ce*)
have_dosish_system=yes
have_w32_system=yes
have_w32ce_system=yes
;;
*-mingw32*)
have_dosish_system=yes
have_w32_system=yes
;;
*-solaris*)
AC_DEFINE(_XOPEN_SOURCE, 500, Activate extensions on Solaris)
AC_DEFINE(_XOPEN_SOURCE_EXTENDED, 1, Activate extensions on Solaris)
AC_DEFINE(__EXTENSIONS__, 1, Activate extensions on Solaris)
;;
esac
if test "$have_dosish_system" = yes; then
AC_DEFINE(HAVE_DOSISH_SYSTEM,1,
[Defined if we run on some of the PCDOS like systems
(DOS, Windoze. OS/2) with special properties like
no file modes])
fi
dnl AM_CONDITIONAL(HAVE_DOSISH_SYSTEM, test "$have_dosish_system" = yes)
if test "$have_w32_system" = yes; then
AC_DEFINE(HAVE_W32_SYSTEM,1,[Defined if we run on a W32 API based system])
if test "$have_w32ce_system" = yes; then
AC_DEFINE(HAVE_W32CE_SYSTEM,1,[Defined if we run on WindowsCE])
fi
BUILD_TIMESTAMP=`date --iso-8601=minutes`
AC_SUBST(BUILD_TIMESTAMP)
changequote(,)dnl
BUILD_FILEVERSION=`echo "$VERSION" | sed 's/\([0-9.]*\).*/\1./;s/\./,/g'`
changequote([,])dnl
case "$VERSION" in
*-svn*) BUILD_FILEVERSION="${BUILD_FILEVERSION}0" ;;
*-cvs) BUILD_FILEVERSION="${BUILD_FILEVERSION}0" ;;
*-rc*) BUILD_FILEVERSION="${BUILD_FILEVERSION}1" ;;
*) BUILD_FILEVERSION="${BUILD_FILEVERSION}2" ;;
esac
fi
AC_SUBST(BUILD_REVISION)
AC_SUBST(BUILD_TIMESTAMP)
AC_SUBST(BUILD_FILEVERSION)
AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
AM_CONDITIONAL(HAVE_W32CE_SYSTEM, test "$have_w32ce_system" = yes)
# Check for network libraries. They are needed for tests.
AC_CHECK_FUNC(setsockopt, , AC_CHECK_LIB(socket, setsockopt,
[NETLIBS="-lsocket $NETLIBS"]))
AC_SUBST(NETLIBS)
if test "$have_w32_system" = yes; then
if test "$have_w32ce_system" = yes; then
NETLIBS="-lws2 $NETLIBS"
else
# FIXME: Check why we need to use ws2_32 and document that.
NETLIBS="-lws2_32 $NETLIBS"
fi
fi
# For src/libassuan-config.in
LIBASSUAN_CONFIG_LIB="-lassuan"
LIBASSUAN_CONFIG_CFLAGS=""
LIBASSUAN_CONFIG_EXTRA_LIBS=
if test x"$NETLIBS" != x; then
LIBASSUAN_CONFIG_EXTRA_LIBS="$LIBASSUAN_CONFIG_EXTRA_LIBS $NETLIBS"
fi
AC_SUBST(LIBASSUAN_CONFIG_LIB)
AC_SUBST(LIBASSUAN_CONFIG_CFLAGS)
AC_SUBST(LIBASSUAN_CONFIG_API_VERSION)
AC_SUBST(LIBASSUAN_CONFIG_EXTRA_LIBS)
# Checks for header files.
AC_HEADER_STDC
-AC_CHECK_HEADERS([string.h locale.h sys/uio.h stdint.h inttypes.h])
+AC_CHECK_HEADERS([string.h locale.h sys/uio.h stdint.h inttypes.h \
+ sys/types.h sys/stat.h unistd.h sys/time.h])
AC_TYPE_UINTPTR_T
AC_TYPE_UINT16_T
# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T
AC_TYPE_SIGNAL
AC_DECL_SYS_SIGLIST
gl_HEADER_SYS_SOCKET
gl_TYPE_SOCKLEN_T
AC_CHECK_MEMBER(struct cmsghdr.cmsg_len,
[use_descriptor_passing=yes],
[use_descriptor_passing=no
AC_MSG_WARN([
***
*** Data structure for sending ancillary data missing.
*** Descriptor passing won't work.
***])],[
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#if HAVE_SYS_UIO_H
#include <sys/uio.h>
#endif
#include <unistd.h>
])
if test "$use_descriptor_passing" = "yes"; then
AC_DEFINE(USE_DESCRIPTOR_PASSING, 1,
[Defined if descriptor passing is supported])
fi
AM_CONDITIONAL(USE_DESCRIPTOR_PASSING, test "$use_descriptor_passing" = "yes")
# Checking for libgpg-error.
AM_PATH_GPG_ERROR(1.8,, AC_MSG_ERROR([libgpg-error was not found]))
#
# Checks for library functions.
#
AC_CHECK_FUNCS([flockfile funlockfile inet_pton])
# On some systems (e.g. Solaris) nanosleep requires linking to librl.
# Given that we use nanosleep only as an optimization over a select
# based wait function we want it only if it is available in libc.
_save_libs="$LIBS"
AC_SEARCH_LIBS([nanosleep], [],
[AC_DEFINE(HAVE_NANOSLEEP,1,
[Define to 1 if you have the `nanosleep' function in libc.])])
LIBS="$_save_libs"
# Check for funopen
AC_CHECK_FUNCS(funopen)
if test $ac_cv_func_funopen != yes; then
# No funopen but we can implement that in terms of fopencookie.
AC_CHECK_FUNCS(fopencookie)
if test $ac_cv_func_fopencookie = yes; then
AC_LIBOBJ([funopen])
else
AC_MSG_WARN([
***
*** No implementation of fopencookie or funopen available.
*** The assuan_get_data_fp function won't work; see the
*** manual for details. GnuPG does not require this feature.
***])
fi
fi
AC_REPLACE_FUNCS(isascii)
AC_REPLACE_FUNCS(putc_unlocked)
AC_REPLACE_FUNCS(memrchr)
AC_REPLACE_FUNCS(stpcpy)
AC_CHECK_HEADERS(unistd.h)
AC_REPLACE_FUNCS(setenv)
AC_REPLACE_FUNCS(vasprintf)
#
# Check for the getsockopt SO_PEERCRED
#
AC_MSG_CHECKING(for SO_PEERCRED)
AC_CACHE_VAL(assuan_cv_sys_so_peercred,
[AC_TRY_COMPILE([#include <sys/socket.h>],
[struct ucred cr;
int cl = sizeof cr;
getsockopt (1, SOL_SOCKET, SO_PEERCRED, &cr, &cl);],
assuan_cv_sys_so_peercred=yes,
assuan_cv_sys_so_peercred=no)
])
AC_MSG_RESULT($assuan_cv_sys_so_peercred)
if test $assuan_cv_sys_so_peercred = yes; then
AC_DEFINE(HAVE_SO_PEERCRED, 1,
[Defined if SO_PEERCRED is supported (Linux specific)])
fi
# Create the config files.
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([m4/Makefile])
AC_CONFIG_FILES([src/Makefile])
AC_CONFIG_FILES([doc/Makefile])
AC_CONFIG_FILES([tests/Makefile])
AC_CONFIG_FILES([src/libassuan-config], [chmod +x src/libassuan-config])
AC_CONFIG_FILES([src/versioninfo.rc])
AC_OUTPUT
diff --git a/contrib/conf-w32ce-msc/build.mk b/contrib/conf-w32ce-msc/build.mk
new file mode 100755
index 0000000..b88ca43
--- /dev/null
+++ b/contrib/conf-w32ce-msc/build.mk
@@ -0,0 +1,158 @@
+# build.mk - Makefile to build libgpg-error using Visual-C
+# Copyright 2010 g10 Code GmbH
+#
+# This file is free software; as a special exception the author gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This file is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+# This is a helper make script to build libgpg-error for WindowsCE
+# using the Microsoft Visual C compiler.
+
+# The target build directry where we run the Visual C compiler/
+# This needs to be an absolute directory name.
+targetdir = /home/smb/xppro-gnu/src/libassuan
+
+
+help:
+ @echo "Run "
+ @echo " make -f ../contrib/conf-w32ce-msc/build.mk copy-source"
+ @echo "on the POSIX system and then"
+ @echo " nmake -f build.mk all"
+ @echo "on the Windows system"
+
+ce_defines = -DWINCE -D_WIN32_WCE=0x502 -DUNDER_CE \
+ -DWIN32_PLATFORM_PSPC -D_UNICODE -DUNICODE \
+ -D_CONSOLE -DARM -D_ARM_
+#-D_DEBUG -DDEBUG
+
+# Some options of Visual-C:
+# -W3 Set warning level 3
+# -Zi Generate debug info
+# -Od Disable optimization
+# -Gm Enable minimal rebuild (for C++)
+# -EHsc Exception handling model sc
+# -MTd Create a debug multithreaded executable
+# -fp: Floating point behaviour
+# -GR- Disable runtime type information
+# -Os Favor small code
+# -LD Create a DLL
+# -Fe Set executable output name (may be only a directory)
+CFLAGS = -nologo -W3 -fp:fast -Os $(ce_defines) \
+ -DHAVE_CONFIG_H -DDLL_EXPORT -D_CRT_SECURE_NO_WARNINGS \
+ -I. -Igpg-extra -I../libgpg-error
+
+LDFLAGS =
+
+# Standard source files
+sources = \
+ assuan.c \
+ context.c \
+ system.c \
+ debug.c \
+ conversion.c \
+ sysutils.c \
+ client.c \
+ server.c \
+ assuan-error.c \
+ assuan-buffer.c \
+ assuan-handler.c \
+ assuan-inquire.c \
+ assuan-listen.c \
+ assuan-pipe-server.c \
+ assuan-socket-server.c \
+ assuan-pipe-connect.c \
+ assuan-socket-connect.c \
+ assuan-uds.c \
+ assuan-logging.c \
+ assuan-socket.c \
+ system-w32ce.c \
+ assuan-io.c \
+ putc_unlocked.c \
+ memrchr.c \
+ stpcpy.c \
+ setenv.c \
+ vasprintf.c \
+ assuan-defs.h \
+ debug.h \
+ libassuan.def
+
+# The object files we need to create from sources.
+objs = \
+ assuan.obj \
+ context.obj \
+ system.obj \
+ debug.obj \
+ conversion.obj \
+ sysutils.obj \
+ client.obj \
+ server.obj \
+ assuan-error.obj \
+ assuan-buffer.obj \
+ assuan-handler.obj \
+ assuan-inquire.obj \
+ assuan-listen.obj \
+ assuan-pipe-server.obj \
+ assuan-socket-server.obj \
+ assuan-pipe-connect.obj \
+ assuan-socket-connect.obj \
+ assuan-uds.obj \
+ assuan-logging.obj \
+ assuan-socket.obj \
+ system-w32ce.obj \
+ assuan-io.obj \
+ putc_unlocked.obj \
+ memrchr.obj \
+ stpcpy.obj \
+ setenv.obj \
+ vasprintf.obj
+
+
+# Sources files in this directory inclduing this Makefile
+conf_sources = \
+ build.mk \
+ config.h
+
+# Source files built by running the standard build system.
+built_sources = \
+ assuan.h
+
+copy-static-source:
+ @if [ ! -f ./assuan-defs.h ]; then \
+ echo "Please cd to the src/ directory first"; \
+ exit 1; \
+ fi
+ cp -t $(targetdir) $(sources);
+ cd ../contrib/conf-w32ce-msc ; cp -t $(targetdir) $(conf_sources)
+
+
+copy-built-source:
+ @if [ ! -f ./assuan.h ]; then \
+ echo "Please build using ./autogen.sh --build-w32ce first"; \
+ exit 1; \
+ fi
+ cp -t $(targetdir) $(built_sources)
+
+copy-source: copy-static-source copy-built-source
+
+
+.c.obj:
+ $(CC) $(CFLAGS) -c $<
+
+all: $(sources) $(conf_sources) $(built_sources) $(objs)
+ link /DLL /IMPLIB:libassuan-0-msc.lib \
+ /OUT:libassuan-0-msc.dll \
+ /DEF:libassuan.def /NOLOGO /MANIFEST:NO \
+ /NODEFAULTLIB:"oldnames.lib" /DYNAMICBASE:NO \
+ $(objs) \
+ coredll.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib \
+ commctrl.lib /subsystem:windowsce,5.02
+
+# Note that install needs to be run on the POSIX platform and the all
+# is only to make sure we build everything; it won't compile anything
+# because Visual-C is probably not installed on that platform.
+install: all
+ @echo fixme Install the files
diff --git a/contrib/conf-w32ce-msc/config.h b/contrib/conf-w32ce-msc/config.h
new file mode 100644
index 0000000..e9b1f3e
--- /dev/null
+++ b/contrib/conf-w32ce-msc/config.h
@@ -0,0 +1,184 @@
+/* config.h for building with Visual-C for WindowsCE.
+ * Copyright 2010 g10 Code GmbH
+ *
+ * This file is free software; as a special exception the author gives
+ * unlimited permission to copy and/or distribute it, with or without
+ * modifications, as long as this notice is preserved.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+/* This file was originally created by running
+ * ./autogen.sh --build-w32ce
+ * on svn revision 389 (libassuan 2.0.2-svn389) and then adjusted to work
+ * with Visual-C.
+ */
+
+#ifndef _ASSUAN_CONFIG_H_INCLUDED
+#define _ASSUAN_CONFIG_H_INCLUDED
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "2.0.2-svn389-msc1"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "libassuan " PACKAGE_VERSION
+
+/* Name of this package */
+#define PACKAGE "libassuan"
+
+/* Bug report address */
+#define PACKAGE_BUGREPORT "bug-libassuan@gnupg.org"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "libassuan"
+
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "libassuan"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL ""
+
+/* Version of this package */
+#define VERSION PACKAGE_VERSION
+
+
+/* Enable gpg-error's strerror macro under W32CE. */
+#define GPG_ERR_ENABLE_ERRNO_MACROS 1
+
+
+/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you
+ don't. */
+#define HAVE_DECL_SYS_SIGLIST 0
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+/* #undef HAVE_DLFCN_H */
+
+/* Defined if we run on some of the PCDOS like systems (DOS, Windoze. OS/2)
+ with special properties like no file modes */
+#define HAVE_DOSISH_SYSTEM 1
+
+/* Define to 1 if you have the `flockfile' function. */
+/* #undef HAVE_FLOCKFILE */
+
+/* Define to 1 if you have the `fopencookie' function. */
+/* #undef HAVE_FOPENCOOKIE */
+
+/* Define to 1 if you have the `funlockfile' function. */
+/* #undef HAVE_FUNLOCKFILE */
+
+/* Define to 1 if you have the `funopen' function. */
+/* #undef HAVE_FUNOPEN */
+
+/* Define to 1 if you have the `inet_pton' function. */
+/* #undef HAVE_INET_PTON */
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+/* #undef HAVE_INTTYPES_H */
+
+/* Define to 1 if you have the `isascii' function. */
+#define HAVE_ISASCII 1
+
+/* Define to 1 if you have the <locale.h> header file. */
+/* #undef HAVE_LOCALE_H */
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the `memrchr' function. */
+/* #undef HAVE_MEMRCHR */
+
+/* Define to 1 if you have the `nanosleep' function in libc. */
+/* #undef HAVE_NANOSLEEP */
+
+/* Define to 1 if you have the `putc_unlocked' function. */
+/* #undef HAVE_PUTC_UNLOCKED */
+
+/* Define to 1 if you have the `setenv' function. */
+/* #undef HAVE_SETENV */
+
+/* Defined if SO_PEERCRED is supported (Linux specific) */
+/* #undef HAVE_SO_PEERCRED */
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the `stpcpy' function. */
+/* #undef HAVE_STPCPY */
+
+/* Define to 1 if you have the <strings.h> header file. */
+/* #undef HAVE_STRINGS_H */
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+/* #undef HAVE_SYS_SOCKET_H */
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+/* #undef HAVE_SYS_STAT_H */
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+/* #undef HAVE_SYS_TYPES_H */
+
+/* Define to 1 if you have the <sys/uio.h> header file. */
+/* #undef HAVE_SYS_UIO_H */
+
+/* Define to 1 if the system has the type `uintptr_t'. */
+#define HAVE_UINTPTR_T 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+/* #undef HAVE_UNISTD_H */
+
+/* Define to 1 if you have the `vasprintf' function. */
+/* #undef HAVE_VASPRINTF */
+
+/* Defined if we run on WindowsCE */
+#define HAVE_W32CE_SYSTEM 1
+
+/* Defined if we run on a W32 API based system */
+#define HAVE_W32_SYSTEM 1
+
+/* Define to 1 if you have the <winsock2.h> header file. */
+#define HAVE_WINSOCK2_H 1
+
+/* Define to 1 if you have the <ws2tcpip.h> header file. */
+#define HAVE_WS2TCPIP_H 1
+
+/* Define to 1 if your C compiler doesn't accept -c and -o together. */
+/* #undef NO_MINUS_C_MINUS_O */
+
+/* Define as the return type of signal handlers (`int' or `void'). */
+#define RETSIGTYPE void
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Defined if descriptor passing is supported */
+/* #undef USE_DESCRIPTOR_PASSING */
+
+/* Enable extensions on AIX 3, Interix. */
+#ifndef _ALL_SOURCE
+# define _ALL_SOURCE 1
+#endif
+/* Enable GNU extensions on systems that have them. */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+#endif
+/* Enable threading extensions on Solaris. */
+#ifndef _POSIX_PTHREAD_SEMANTICS
+# define _POSIX_PTHREAD_SEMANTICS 1
+#endif
+
+
+/* snprintf is not part of oldnames.lib thus we redefine it here. */
+#define snprintf _snprintf
+
+
+#endif /*_ASSUAN_CONFIG_H_INCLUDED*/
+
diff --git a/src/ChangeLog b/src/ChangeLog
index c84cc33..5a875a4 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,2183 +1,2211 @@
+2010-11-01 Werner Koch <wk@g10code.com>
+
+ * assuan-socket.c (S_IRUSR) [W32]: Define if not defined.
+
+ * sysutils.c: Remove include of devload.h.
+
+ * assuan-defs.h [HAVE_WINSOCK2_H]: Include winsock2.h prior to
+ windows.h.
+ * assuan-pipe-server.c: Ditto.
+ * sysutils.c: Ditto.
+ * assuan-socket-server.c: Ditto.
+ * assuan-pipe-connect.c: Ditto.
+ * assuan-socket-connect.c: Ditto.
+ * assuan-uds.c: Ditto.
+ * assuan-logging.c: Ditto.
+ * system-w32ce.c: Ditto.
+ * assuan-io.c: Ditto.
+
+ * w32-types.inc.h [_MSC_VER]: Define ssize_t and pid_t.
+
+ * w32ce-fd-t.inc.h, w32-fd-t.inc.h, posix-fd-t.inc.h, debug.h:
+ s/inline/GPG_ERR_INLINE/.
+ * assuan.h.in: Let mkheader write the sys/types.h and unistd.h
+ include lines.
+ * mkheader.c: Change accordingly.
+
+ Guard include of sys/types.h, sys/stat.h, sys/time.h and unistd.h.
+
2010-09-17 Werner Koch <wk@g10code.com>
* assuan-socket-connect.c (INADDR_NONE): New replacement. Fixes
bug#1282.
2010-09-01 Werner Koch <wk@g10code.com>
* assuan.h.in (ASSUAN_NO_LOGGING): New.
* assuan-defs.h (struct assuan_context_s): Add FLAGS.NO_LOGGING.
* context.c (assuan_set_flag, assuan_get_flag): Support new flag.
* assuan-logging.c (_assuan_log_control_channel): Implement new flag.
2010-08-11 Werner Koch <wk@g10code.com>
* assuan.h.in (ASSUAN_CONVEY_COMMENTS): New.
* assuan-defs.h (struct assuan_context_s): Add flags.CONVEY_COMMENTS.
* context.c (assuan_set_flag, assuan_get_flag): Support this flag.
(_assuan_read_from_server): Add arg CONVEY_COMMENTS. Change all
callers.
* client.c (assuan_transact): Implement new flags.
2010-08-09 Werner Koch <wk@g10code.com>
* assuan-socket-connect.c (assuan_socket_connect): Fix ipv6
literal IP case.
2010-08-03 Marcus Brinkmann <marcus@g10code.de>
* gpgcedev.c (GPGCEDEV_IOCTL_ASSIGN_RVID): New call ASSIGN_RVID.
(PIPE_FLAG_HALT_MONITOR): New flag.
(struct pipeimpl_s): New members monitor_proc, monitor_access.
(pipeimpl_new): Initialize them.
(assert_pipeimpl): New function.
(access_opnctx, make_pipe): Use it.
(make_pipe): If there is a monitor, halt it.
(monitor, assign_rvid): New functions.
(GPG_IOControl): Handle GPGCEDEV_IOCTL_ASSIGN_RVID.
* gpgcedev.c: Use index (between 1 and table size) into
opnctx_table as public context identifiers, instead using pointers
into the table directly (which are not stable under table resize).
(OPNCTX_TO_IDX, OPNCTX_FROM_IDX, OPNCTX_VALID_IDX_P): New macros.
2010-06-28 Werner Koch <wk@g10code.com>
* gpgcedev.c (GPG_IOControl) <IOCTL_PSL_NOTIFY>: Unblock threads.
2010-06-11 Marcus Brinkmann <marcus@g10code.de>
* assuan-handler.c (std_handler_input,
std_handler_output) [HAVE_W32CE_SYSTEM]: Finish the pipe. We must
do this here, because otherwise assuan_close_input_fd() and
assuan_close_output_fd() can't work.
* system-w32ce.c (_assuan_w32ce_finish_pipe): Call SetLastError in
error case.
(__assuan_close): Save WSAGetLastError before trashing it!
Otherwise handle is never closed and GPGME hangs.
2010-06-10 Marcus Brinkmann <marcus@g10code.de>
* w32ce-add.h (ASSUAN_STDIN, ASSUAN_STDOUT): Define magic handle values.
* system-w32ce.c (__assuan_read, __assuan_write): Handle magic
handle values differently.
* system-w32ce.c (_assuan_w32ce_finish_pipe): Return error on RVID 0.
2010-06-09 Marcus Brinkmann <marcus@g10code.de>
* gpgcedev.c (GPGCEDEV_IOCTL_UNBLOCK): New ioctl.
(PIPE_FLAG_UNBLOCK_READER, PIPE_FLAG_UNBLOCK_WRITER): New flags.
(GPG_Read): Check if PIPE_FLAG_UNBLOCK_READER is set and return
ERROR_BUSY in that case.
(GPG_Write): Likewise for PIPE_FLAG_UNBLOCK_WRITER.
(unblock_call): New function.
(GPG_IOControl): Implement GPGCEDEV_IOCTL_UNBLOCK.
2010-06-07 Marcus Brinkmann <marcus@g10code.de>
* gpgcedev.c: This rewrite does away with troublesome race
conditions (close vs everything else, for example) by simplifying
the locking model. It also handles EOF, EPIPE, but still assumes
that there is always only ever one reader and writer. Also, no
need to treat ERROR_PIPE_NOT_CONNECTED and ERROR_BUSY as EAGAIN
anymore.
(struct pipeimpl_s, pipeimpl_t): New types.
(PIPE_FLAG_NO_READER, PIPE_FLAG, NO_WRITER): New macros.
(struct opnctx_s): Remove everything that's now in struct
pipeimpl_s. Remove also assoc and locked. Add pipeimpl field.
(pipeimpl_new, pipeimpl_unref, allocate_opnctx, verify_opnctx,
access_opnctx): New functions.
(get_new_opnctx, find_and_lock_opnctx, validate_and_lock_opnctx,
unlock_opnctx): Removed.
(GPG_Init, GPG_Deinit): Improve debugging output.
(GPG_Open): Improve debugging output, use allocate_opnctx instead
of get_new_opnctx.
(GPG_Close): Improve debugging output. Rewrite to use reference
counting. Also check if reader or writer is closed and set flags
for triggering EOF or EPIPE.
(GPG_Read): Improve debugging output. Rewrite using pipeimpl.
Check for EOF.
(GPG_Write): Improve debugging output. Rewrite using pipeimpl.
Check for EPIPE.
(make_pipe): Rewrite using pipeimpl.
(GPG_IOControl): Improve debugging output.
2010-04-22 Werner Koch <wk@g10code.com>
* assuan-listen.c (assuan_accept): Show the PID with the default
hello message.
2010-04-19 Werner Koch <wk@g10code.com>
* system-w32.c (is_socket): New.
(__assuan_read, __assuan_write): Use is_socket.
2010-04-16 Marcus Brinkmann <marcus@g10code.de>
* assuan-uds.c (uds_reader, uds_sendfd): Don't break strict
aliasing rules.
2010-04-14 Werner Koch <wk@g10code.com>
* Makefile.am (install-exec-hook): Rename libgpgcedev-0.dll.
2010-04-14 Marcus Brinkmann <marcus@g10code.de>
* Makefile.am (EXTRA_DIST): Add gpgcedev.def.
2010-04-13 Werner Koch <wk@g10code.com>
* gpgcedev.c (get_new_opnctx): Always clear IS_WRITE.
2010-04-08 Werner Koch <wk@g10code.com>
* gpgcedev.c (GPG_Read, GPG_Write): If the context is not
associated return ERROR_PIPE_NOT_CONNECTED.
* system-w32ce.c (__assuan_read, __assuan_write): Return EAGAIN for
ERROR_PIPE_NOT_CONNECTED.
* assuan-pipe-connect.c (pipe_connect): Use
_assuan_close_inheritable also in the spawn error case.
2010-04-06 Werner Koch <wk@g10code.com>
* posix-includes.inc.h, w32-includes.inc.h: New.
* posix-types.inc.h, w32-types.inc.h: New.
* posix-fd-t.inc.h, w32-fd-t.inc.h, w32ce-fd-t.inc.h: New.
* posix-sock-nonce.inc.h, w32-sock-nonce.inc.h: New.
* mkheader.c (write_special): Support them.
* Makefile.am (common_sources, assuan.h): Ditto
(parts_of_assuan_h): New.
* w32-sys-pth-impl.h: Use gpg_err_set_errno.
* assuan.h.in (_ASSUAN_SYSTEM_PTH_IMPL): Factor code out to ..
* posix-sys-pth-impl.h, w32-sys-pth-impl.h: New
* mkheader.c (write_special): Support them.
* Makefile.am (common_sources, assuan.h): Ditto
2010-03-23 Werner Koch <wk@g10code.com>
* assuan-error.c (_assuan_w32_strerror) [W32CE]: Print only the code.
2010-03-22 Werner Koch <wk@g10code.com>
* Makefile.am (mkheader, assuan.h): Build header file.
(nodist_libassuan_la_SOURCES): New. Use it for assuan.h.
* mkheader.c: New.
* assuan.h: Rename to assuan.h.in.
2010-03-18 Werner Koch <wk@g10code.com>
* libassuan.def (_assuan_w32ce_prepare_pipe)
(_assuan_w32ce_finish_pipe): New
* gpgcedev.c (struct opnctx_s): Replace HD by RVID.
(GPGCEDEV_IOCTL_SET_HANDLE): Remove.
(GPGCEDEV_IOCTL_GET_RVID): New.
(create_rendezvous_id): New.
(get_new_opnctx): Init the RVID.
(set_handle): Remove.
(find_and_lock_opnctx, make_pipe, GPG_IOControl): Change to new
method.
* system-w32ce.c (_assuan_w32ce_prepare_pipe)
(_assuan_w32ce_finish_pipe): New.
(_assuan_w32ce_create_pipe): Re-implement using the new functions.
(__assuan_pipe): Create an inheritable pipe.
(build_w32_commandline): New arg FD2_ISNULL.
* system.c (_assuan_close_inheritable): New.
* assuan-pipe-connect.c (pipe_connect): Use the new function.
* sysutils.c (_assuan_w32ce_create_pipe): Move to system-w32ce.c.
2010-03-16 Werner Koch <wk@g10code.com>
* system-w32ce.c (build_w32_commandline): Add args to pass the
special options for the standard descriptors.
(utf8_to_wchar, free_wchar): New.
(__assuan_spawn): Adjust for changes. Convert strings for
CreateProcess to wchar_t.
* system.c: For better readability move platform dependend code to ..
* system-posix.c, system-w32.c, system-w32ce.c: .. New.
* Makefile.am (common_sources): Account for this change.
2010-03-11 Werner Koch <wk@g10code.com>
* assuan-defs.h [!HAVE_VASPRINTF]: Add macros vasprintf and asprintf.
* vasprintf.c (asprintf): Rename to _assuan_asprintf.
(vasprintf): Rename to _assuan_vasprintf.
* assuan.h (ASSUAN_LOG_CONTROL): New.
* assuan-logging.c (assuan_set_assuan_log_stream): Default to
ASSUAN_LOG_CONTROL.
(_assuan_log_print_buffer): Remove.
(_assuan_log_control_channel): New.
(assuan_set_assuan_log_stream): Factor envvar code out to ..
(_assuan_init_log_envvars): .. New.
* assuan.c (assuan_set_log_cb): Call _assuan_init_log_envvars.
* assuan-buffer.c (_assuan_read_line, _assuan_write_line)
(assuan_write_line, _assuan_cookie_write_data)
(_assuan_cookie_write_flush): Use _assuan_log_control_channel.
2010-03-05 Werner Koch <wk@g10code.com>
* gpgcemgr.c: Add options to register a device and activate it.
2010-02-24 Werner Koch <wk@g10code.com>
* gpgcemgr.c: New.
* gpgcedev.c: New.
* sysutils.c (_assuan_w32ce_create_pipe): Rewrote to make use of
the new driver.
2010-02-16 Werner Koch <wk@g10code.com>
* system.c (assuan_free): New.
* libassuan.vers (assuan_free): Add it.
* libassuan.def (assuan_free): Add it.
2010-02-11 Werner Koch <wk@g10code.com>
* assuan-inquire.c (assuan_inquire): Allow case insensitive
responses.
(_assuan_inquire_ext_cb): Ditto.
2010-02-10 Werner Koch <wk@g10code.com>
* assuan-handler.c (std_handler_input, std_handler_output): Make
the parsed FD available to the notification functions. This is
the documented behaviour.
2010-02-04 Werner Koch <wk@g10code.com>
* assuan-socket-connect.c: Include stdint.h and arpa/inet.h.
(parse_portno): New.
(assuan_socket_connect): Return a correct error code on failure.
Support assuan:// and file:// schemes.
2010-02-03 Marcus Brinkmann <marcus@g10code.de>
* libassuan.vers, libassuan.def: Add assuan_set_sock_nonce.
2010-02-01 Werner Koch <wk@g10code.com>
* sysutils.c (_assuan_w32ce_create_pipe): New.
* libassuan.def (_assuan_w32ce_create_pipe): New.
* assuan-defs.h (CreateFile) [W32CE]: New macro
* system.c (__assuan_pipe): Make it work for W32CE.
2010-01-28 Werner Koch <wk@g10code.com>
* assuan.h: Remove ranges in list of copyright years.
(getenv) [W32CE]: Provide macro.
* sysutils.c: New.
(_assuan_sysutils_blurb): New.
(_assuan_getenv): new.
* assuan-logging.c: Call _assuan_sysutils_blurb.
2010-01-27 Werner Koch <wk@g10code.com>
* assuan-socket.c (_assuan_sock_bind): Replace remove by DeleteFile.
* assuan-handler.c (assuan_get_active_fds) [W32CE]: Remove use of
_get_osfhandle.
* assuan.h (assuan_fd_from_posix_fd) [__MINGW32CE__]: Ditto.
* system.c (assuan_fdopen): Ditto.
(__assuan_spawn) [W32CE]: Do not use GetPriorityClass.
* assuan-defs.h (getpid) [W32CE]: New.
2010-01-22 Werner Koch <wk@g10code.com>
* setenv.c [W32CE]: Make it a dummy.
* assuan-pipe-connect.c: Remove signal.h.
* system.c (__assuan_spawn): Use CreateFileW.
(DETACHED_PROCESS) [W32CE]: Define to 0.
* assuan-socket.c (read_port_and_nonce): Replace ENOFILE by a
proper ENOENT.
Replace all assignments to ERRNO by a call to gpg_err_set_errno.
2010-01-14 Werner Koch <wk@g10code.com>
* debug.c (_assuan_debug, _assuan_debug_begin)
(_assuan_debug_buffer): Check CTX before dereferencing.
* assuan.c (assuan_release): Immediately leave on NULL CTX.
2010-01-05 Marcus Brinkmann <marcus@g10code.de>
* debug.h (TRACE_LOG5): Add macro.
* debug.c (_assuan_debug_buffer): Add newline
* system.c: Add more debug output (conditioned on the compile-time
DEBUG_SYSIO macro).
2009-12-14 Werner Koch <wk@g10code.com>
* assuan.h (ASSUAN_RESPONSE_COMMENT): New.
* client.c (assuan_client_read_response): Return comment lines.
(assuan_client_parse_response): Return ASSUAN_RESPONSE_COMMENT.
(_assuan_read_from_server): Skip comment lines.
2009-12-08 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (struct assuan_system_hooks): Don't use "namespace" as
argument name in declaration (C++ keyword).
* client.c (assuan_client_read_response): Fix linelen.
* assuan.h (ASSUAN_SPAWN_DETACHED): New macro.
* assuan-pipe-connect.c (pipe_connect): Calculate spawn_flags from
flags.
* assuan.h (assuan_fd_from_posix_fd): Handle invalid fd early.
* assuan-socket.c (get_nonce): Cast buffer to unsigned.
(_assuan_sock_connect) [HAVE_W32_SYSTEM]: Drop ctx argument from
read_port_and_nonce invocation.
* system.c (assuan_fdopen) [HAVE_W32_SYSTEM]: Fix typo in variable
name.
(__assuan_spawn) [HAVE_W32_SYSTEM]: Fix types of fd and fdp. Use
ASSUAN_INVALID_FD. Add missing context argument to _assuan_free,
and fix call to _assuan_w32_strerror. Set errno on error.
(__assuan_socketpair) [HAVE_W32_STRERROR]: Fix type of filedes
argument.
* assuan-pipe-connect.c (pipe_connect, assuan_pipe_connect,
socketpair_connect) [HAVE_W32_SYSTEM]: Fix type of fd_child_list.
* assuan-defs.h (_assuan_socketpair): Likewise for prototype.
* assuan.h (assuan_fd_from_posix_fd): New static inline function.
2009-12-03 Marcus Brinkmann <marcus@g10code.de>
* assuan-logging.c: (log_cats): New static variable.
(TEST_LOG_CAT): New macro.
(_assuan_log_handler): Check log category.
(assuan_set_assuan_log_stream): Check ASSUAN_DEBUG for logging
categories.
(assuan_set_log_stream): Call assuan_set_assuan_log_stream.
2009-12-02 Marcus Brinkmann <marcus@g10code.de>
* Makefile.am (common_sources): Remove assuan-client.c.
* assuan-client.c: File removed.
* assuan.h (ASSUAN_RESPONSE_ERROR, ASSUAN_RESPONSE_OK)
(ASSUAN_RESPONSE_STATUS, ASSUAN_RESPONSE_INQUIRE)
(ASSUAN_RESPONSE_STATUS): New macros.
(assuan_response_t): New type.
(assuan_client_read_response, assuan_client_parse_response): New
prototypes.
* libassuan.def, libassuan.vers: Add assuan_client_read_response,
assuan_client_parse_response.
* assuan-client.c (xtoi_1, xtoi_2, assuan_transact)
(_assuan_read_from_server): Moved to ...
* client.c: ... here, with updates to use new functions and types.
Include <stdlib.h>.
(assuan_client_read_response, assuan_client_parse_response): New
functions.
* assuan-defs.h (_assuan_read_from_server): Use assuan_response_t.
* assuan-pipe-connect.c (initial_handshake): Use assuan_response_t
and ASSUAN_RESPONSE_OK.
* assuan-socket-connect.c (assuan_socket_connect): Likewise.
2009-12-01 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-server.c (assuan_init_pipe_server): Fix debug output.
2009-11-27 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (assuan_set_assuan_log_stream): Add prototype.
* libassuan.def, libassuan.vers: Add back
assuan_set_assuan_log_stream.
* assuan-logging.c (assuan_set_assuan_log_stream): Add back.
* context.c (assuan_get_pointer): Don't output debug info here.
(assuan_get_peercred, assuan_get_pid): But do here.
* system.c: Improve debug output.
* assuan-defs.h (struct assuan_context_s): Rename pipe_mode to
max_accepts.
* assuan-listen.c (assuan_accept): Rework max accepts logic.
* assuan-socket-server.c (assuan_init_socket_server),
assuan-socket-connect.c (assuan_socket_connect),
assuan-pipe-server.c (assuan_init_pipe_server),
assuan-pipe-connect.c (socketpair_connect): Add debug output, set
max_accepts instead of pipe_mode.
2009-11-25 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (assuan_init_pipe_server): Change type of filedes to
assuan_fd_t.
(assuan_fdopen): New prototype.
* libassuan.vers, libassuan.def: Add assuan_fdopen.
* system.c (assuan_fdopen): New function.
* assuan-pipe-server.c (assuan_init_pipe_server): Change type of
filedes to assuan_fd_t. No longer translate fd to handle. Don't
set to binary either (that doesn't do anything for handles, it
only affects the libc fd).
2009-11-24 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (struct _assuan_peercred) [_WIN32]: Define dummy member
so struct is not empty.
* assuan-socket.c (assuan_sock_deinit): Set sock_ctx to NULL.
2009-11-19 Marcus Brinkmann <marcus@g10code.de>
* Makefile.am (common_sources): Remove assuan-connect.c and add
client.c.
* client.c, server.c: New file.
* assuan-defs.h (_assuan_disconnect): Remove.
(struct assuan_context_s): Remove members deinit_handler.
(_assuan_client_release, _assuan_client_finish)
(_assuan_server_finish, _assuan_server_release): New.
* assuan-socket-server.c (accept_connection_bottom): Use
ASSUAN_INVALID_PID, not -1.
(finish_connection, deinit_socket_server): Remove.
(assuan_init_socket_server): Use _assuan_server_release.
* assuan-socket-connect.c (do_finish, do_deinit): Remove.
(assuan_socket_connect): Use _assuan_client_release.
* assuan-pipe-connect.c (do_finish, do_deinit): Remove.
(pipe_connect): Update deinitialization.
(socketpair_connect): Here as well.
* context.c (assuan_get_pid): New from ...
* assuan-connect.c (assuan_get_pid): ... here. Remove this file.
* assuan-pipe-server.c (_assuan_deinit_server, accept_connection)
(deinit_pipe_server, finish_connection): Remove unused function.
* assuan-listen.c (assuan_accept): Check CTX->accept_handler
before calling. Initialize RC. Do not call finish handler for
pipe server.
* assuan-uds.c (_assuan_uds_deinit): Do not call finish handler.
2009-11-10 Marcus Brinkmann <marcus@g10code.de>
* assuan-defs.h (struct assuan_context_s): Rename
CTX->process_done to CTX->process_complete for clarity. Remove
buffer variables from UDS.
* assuan-pipe-connect.c (socketpair_connect): Allow FD_CHILD_LIST
to be NULL.
* assuan-handler.c: Rename CTX->process_done to
CTX->process_complete for clarity.
(process_request, process_next): Handle EOF.
* assuan-uds.c (uds_reader): Remove buffering, which breaks the
pending line algorithm in assuan-buffer.c.
(_assuan_init_uds_io, _assuan_uds_deinit): Remove buffering.
* assuan-buffer.c (_assuan_read_line): Add comment.
2009-11-05 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (struct _assuan_peercred, assuan_peercred_t): New.
(assuan_get_peercred): Define on all systems, return
assuan_peercred_t.
* assuan-defs.h (struct assuan_context_s): Move valid flag out of
peercred struct, use struct _assuan_peercred.
* libassuan.def: Add assuan_get_peercred.
* assuan-connect.c (assuan_get_peercred): Moved to ...
* context.c (assuan_get_peercred): ... here. Reimplement.
* assuan-socket-server.c (accept_connection_bottom): Adjust access
to peercred in context.
* assuan.h (ASSUAN_PIPE_CONNECT_FDPASSING)
(ASSUAN_PIPE_CONNECT_DETACHED, ASSUAN_SOCKET_SERVER_FDPASSING)
(ASSUAN_SOCKET_SERVER_ACCEPTED, ASSUAN_SOCKET_CONNECT_FDPASSING): New.
(assuan_pipe_connect_ext): Renamed to ...
(assuan_pipe_connect): ... this, overwriting old prototype.
(assuan_socket_connect_ext): Renamed to ...
(assuan_socket_connect): ... this, overwriting old prototype.
(assuan_init_socket_server_ext): Renamed to ...
(assuan_init_socket_server): ... this, overwriting old prototype.
* assuan-pipe-connect.c: Likewise for functions.
* assuan-socket-connect.c: Likewise.
* assuan-socket-server.c: Likewise.
* libassuan.def (assuan_init_socket_server_ext)
(assuan_pipe_connect_ext, assuan_socket_connect_ext): Removed.
* libassuan.vers: Likewise.
* assuan-defs.h (assuan_context_t): Add member PROCESS_DONE.
* assuan.h (assuan_process_next): Add argument DONE to prototype.
* assuan-handler.c (assuan_process_next): Likewise, handle it.
(std_handler_bye): Set PROCESS_DONE.
(assuan_process_done): Handle PROCESS_DONE in the no error case.
(assuan_process): Use PROCESS_DONE.
2009-11-04 Marcus Brinkmann <marcus@g10code.de>
* debug.c (_assuan_debug): Free MSG.
2009-11-04 Werner Koch <wk@g10code.com>
* Makefile.am (common_sources): Add debug.h.
* assuan-defs.h (cmdtbl_s): Add field HELPSTR.
* assuan-handler.c (assuan_register_command): Add arg HELP_STRING.
(std_handler_help): Print the help.
2009-11-02 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (assuan_handler_t): New type.
(assuan_register_bye_notify, assuan_register_reset_notify)
(assuan_register_cancel_notify, assuan_register_input_notify)
(assuan_register_output_notify, assuan_register_command): Use it.
* assuan-handler.c (std_handler_cancel, std_handler_bye): Pass
LINE argument to user handler.
(std_handler_reset): Likewise, and also abort RESET if error is
returned from user handler.
(std_handler_input, std_handler_output): Check return value from
user handler before assigning FD.
* assuan-defs.h (struct cmdtbl_s): Change type of member HANDLER
to assuan_handler_t.
(struct assuan_context_s): Change type of members
RESET_NOTIFY_FNC, CANCEL_NOTIFY_FNC, BYE_NOTIFY_FNC,
INPUT_NOTIFY_FNC and OUTPUT_NOTIFY_FNC to assuan_handler_t.
2009-10-30 Marcus Brinkmann <marcus@g10code.de>
* system.c (_assuan_spawn): Check fd_child_list before dumping it.
2009-10-20 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (__assuan_usleep): Add declaration.
* system.c (__assuan_usleep): Make non-static.
* libassuan.vers, libassuan.defs: Sort lexicographically.
2009-10-19 Marcus Brinkmann <marcus@g10code.com>
* system.c (__assuan_waitpid): Return something.
(_assuan_usleep): Don't return value in void function.
2009-10-16 Marcus Brinkmann <marcus@g10code.com>
* conversion.c: Do not include <sys/types.h> and <time.h>.
* debug.h (TRACE_BEG6, TRACE4): New macros.
(TRACE_SYSERR): Pass _assuan_trace_context to _assuan_debug.
* context.c (assuan_set_pointer, assuan_get_pointer,
assuan_set_flag, assuan_get_flag, assuan_set_io_monitor,
assuan_set_error): Add trace messages.
* libassuan-config.in, libassuan.m4, Makefile.am: Remove PTH support.
* assuan.h (assuan_msghdr_t): New type.
(ASSUAN_INVALID_PID): New macro.
(ASSUAN_NO_FIXSIGNALS): New flag macro.
(ASSUAN_SYSTEM_HOOKS_VERSION): New macro.
(struct assuan_system_hooks, assuan_system_hooks_t): New types.
(assuan_pipe_connect, assuan_pipe_connect_ext): Don't make ARGV
const for name==NULL operation. Make fd_child_list an array of
assuan_fd_t.
(assuan_sock_init, assuan_sock_deinit, assuan_set_system_hooks,
assuan_ctx_set_system_hooks, __assuan_pipe, __assuan_close,
__assuan_spawn, __assuan_socketpair): New function prototypes.
(_ASSUAN_SYSTEM_PTH_IMPL, ASSUAN_SYSTEM_PTH_DECL,
ASSUAN_SYSTEM_PTH): New macros.
(_assuan_system_pth): New declaration.
* libassuan.vers, libassuan.defs: Add assuan_sock_init,
assuan_sock_deinit, __assuan_pipe, __assuan_close, __assuan_spawn,
__assuan_socketpair, assuan_set_system_hooks,
assuan_ctx_set_system_hooks.
* assuan-defs.h (struct assuan_io): Removed, move members to ...
(struct assuan_context_s): ... this to ENGINE. New flag
no_fixsignals. New member SYSTEM. Remove member IO.
(_assuan_pipe, _assuan_read, _assuan_write, _assuan_recvmsg,
_assuan_sendmsg, _assuan_spawn, _assuan_socketpair,
_assuan_system_hooks, _assuan_system_hooks_copy): New
declarations.
(_assuan_error_is_eagain, _assuan_waitpid, _assuan_usleep,
_assuan_close, _assuan_sock_new, _assuan_sock_connect,
_assuan_sock_bind, _assuan_sock_get_nonce,
_assuan_sock_check_nonce): Add context argument.
(_assuan_io_read, _assuan_io_write, _assuan_simple_sendmsg,
_assuan_simple_recvmsg): Removed.
* context.c (assuan_ctx_set_system_hooks): New function.
* assuan.c (assuan_set_system_hooks): New function.
(assuan_new_ext): Initialize CTX->system.
(assuan_release): Always output trace message.
* assuan-error.c (_assuan_error_is_eagain): Add ctx argument, pass
along to _assuan_usleep.
* assuan-inquire.c assuan-listen.c, assuan-socket-server.c,
assuan-handler.c, assuan-socket-connect.c, assuan-client.c,
assuan-pipe-connect.c, assuan-socket.c: Pass CTX argument to
functions that need it
(_assuan_sock_new, _assuan_sock_check_none, _assuan_close,
_assuan_error_is_eagain and many more).
* assuan-socket-server.c (assuan_init_socket_server_ext): Update
fields in CTX->engine instead of CTX->io.
* assuan-socket-connect (assuan_socket_connect_ext): Likewise.
* assuan-uds.c (uds_reader, uds_writer, uds_sendfd): Use
_assuan_recvmsg and _assuan_sendmsg instead of
_assuan_simple_recvmsg and _assuan_simple_sendmsg respectively.
(_assuan_init_uds_io): Update fields in CTX->engine instead of
CTX->io.
* assuan-buffer.c: Use functions in CTX->engine instead of CTX->io.
* assuan-pipe-server.c (assuan_init_pipe_server): Update
fields in CTX->engine instead of CTX->io.
* system.c: Include <sys/types.h>, <time.h>, <fcntl.h>, and
<windows.h> resp. <sys/wait.h>. Define MAX_OPEN_FDS.
(_assuan_system_hooks_copy, __assuan_usleep, _assuan_usleep,
__assuan_pipe, _assuan_pipe, __assuan_close, _assuan_close,
__assuan_read, _assuan_read, __assuan_write, _assuan_write,
__assuan_recvmsg, _assuan_recvmsg, __assuan_sendmsg,
_assuan_sendmsg, __assuan_spawn, _assuan_spawn, __assuan_waitpid,
_assuan_waitpid, __assuan_socketpair, _assuan_socketpair): New
functions.
(_assuan_system_hooks): New singleton.
* assuan-io.c (_assuan_waitpid, do_io_read, _assuan_io_read,
do_io_write, _assuan_io_write, _assuan_simple_sendmsg,
_assuan_simple_recvmsg, _assuan_usleep): Removed.
* assuan-pipe-connect (writen, build_w32_commandline,
create_inheritable_pipe): Removed (actually moved to system.c).
(fix_signals) [_ASSUAN_NO_FIXED_SIGNALS]: Still fix signals.
(do_finish): Move waitpid logic to _assuan_waitpid, just call
that.
(struct at_pipe_fork, struct at_socketpair_fork): New types.
(at_pipe_fork_cb, at_socketpair_fork_cb): New callback functions.
(pipe_connect_unix, pipe_connect_w32): Replaced by ...
(pipe_connect): ... this new function using new system functions.
(socketpair_connect): Reimplement to use new system functions.
(assuan_pipe_connect, assuan_pipe_connect_ext): Add trace message.
* assuan-socket.c (_assuan_close): Removed (moved to system.c).
(_assuan_sock_new, _assuan_sock_connect, _assuan_sock_bind,
_assuan_sock_get_nonce, _assuan_sock_check_nonce): Add context
argument. Use new system interface.
(sock_ctx): New singleton.
(assuan_sock_init, assuan_sock_deinit): New functions to
initialize and deinitialize the singleton.
2009-10-14 Werner Koch <wk@g10code.com>
* assuan-defs.h (assuan_context_s): Add field CURRENT_CMD_NAME.
* assuan-handler.c (dispatch_command): Set this field.
(assuan_get_command_name): New.
* assuan.h, libassuan.vers, libassuan.def: Add new fucntion.
2009-10-08 Marcus Brinkmann <marcus@g10code.de>
* Makefile.am (libassuan_pth): Removed.
(lib_LTLIBRARIES): Remove $(libassuan_pth).
(libassuan_pth_la_SOURCES, libassuan_pth_la_CPPFLAGS)
(libassuan_pth_la_CFLAGS, libassuan_pth_la_LIBADD): Removed.
* libassuan.m4 (AM_PATH_LIBASSUAN_PTH, AM_PATH_LIBASSUAN_PTHREAD):
Removed.
* assuan-io-pth.c: Removed.
* libassuan-config.in (all_thread_modules): Removed. Also removed
option --thread.
2009-10-08 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (assuan_get_assuan_log_stream,
assuan_set_assuan_log_stream): Remove prototypes.
* libassuan.def: Remove assuan_get_assuan_log_stream,
assuan_set_assuan_log_stream.
* libassuan.vers: Likewise.
* assuan-defs.h (_assuan_w32_strerror): Fix prototype.
(w32_strerror): Remove macro.
* assuan-pipe-connect.c (build_w32_commandline): Add argument for
context. Use it for malloc routines. Use _assuan_w32_strerror
instead of w32_strerror.
* vasprintf.c: New file.
2009-09-29 Werner Koch <wk@g10code.com>
* assuan.h: Comment fix.
* assuan.c (assuan_release): Allow passing a NULL ctx.
2009-09-19 Marcus Brinkmann <marcus@g10code.de>
* src/libassuan.vers, src/libassuan.def: Update to new API.
* assuan.c, context.c, system.c, debug.c: New files.
* Makefile.am (common_sources): Add assuan.c, context.c, system.c
and debug.c.
* assuan.h: Include <stdarg.h>. Fix inclusion of <gpg-error.h>.
(_ASSUAN_EXT_SYM_PREFIX, _ASSUAN_PREFIX1, _ASSUAN_PREFIX2)
(_ASSUAN_PREFIX): Remove support for renaming the whole library,
now that we have a stable shared library interface that can evolve
to cover all needs (particularly those of GPGME).
(assuan_malloc_hooks, assuan_malloc_hooks_t, assuan_log_cb_t)
(assuan_io_monitor_t): New types.
(ASSUAN_LOG_INIT, ASSUAN_LOG_CTX, ASSUAN_LOG_ENGINE)
(ASSUAN_LOG_DATA, ASSUAN_LOG_SYSIO, ASSUAN_IO_FROM_PEER)
(ASSUAN_IO_TO_PEER, ASSUAN_IO_MONITOR_NOLOG)
(ASSUAN_IO_MONITOR_IGNORE): New symbols.
(assuan_set_gpg_err_source, assuan_get_gpg_err_source)
(assuan_get_malloc_hooks, assuan_set_log_cb, assuan_get_log_cb)
(assuan_new, assuan_new_ext, assuan_release): New function
prototypes.
(assuan_init_pipe_server, assuan_init_socket_server)
(assuan_init_socket_server_ext, assuan_pipe_connect)
(assuan_pipe_connect_ext, assuan_socket_connect)
(assuan_socket_connect_ext): Take a context argument instead of
pointer to context.
(assuan_deinit_server, assuan_disconnect)
(assuan_set_assuan_err_source): Remove function prototypes.
* assuan-defs.h (ASSUAN_GCC_A_PURE): Moved here from XXX
(_assuan_error): New macro.
(struct assuan_context_s): New members err_source, w32_strerror,
malloc_hooks, log_cb, log_cb_data: New members. Move confidential
into flags. New member engine.
(_assuan_log_handler, _assuan_error_default, _assuan_disconnect):
New prototypes.
(_assuan_new_context): Remove prototype.
(_assuan_malloc, _assuan_calloc, _assuan_realloc, _assuan_free):
Add context argument to prototype.
* assuan-util.c (alloc_func, realloc_func, free_func): Remove
global variables.
(assuan_set_malloc_hooks, _assuan_malloc, _assuan_realloc)
(_assuan_calloc, _assuan_free, assuan_set_pointer)
(assuan_get_pointer, assuan_begin_confidential)
(assuan_end_confidential, assuan_set_io_monitor, assuan_set_flag)
(assuan_get_flag): Move functions to ...
* assuan-client.c: Add ctx argument to all invocations of
_assuan_error.
* assuan-socket-server.c, assuan-socket-connect.c,
assuan-connect.c: Likewise.
* assuan-buffer.c: Likewise. Also update access to confidential
flag.
* assuan-uds.c: Add ctx argument to all invocations of
_assuan_malloc, _assuan_realloc, _assuan_calloc, _assuan_free and
_assuan_error.
* assuan_listen.c, assuan-inquire.c, assuan-handler.c: Likewise.
* assuan-error.c (err_source): Remove global variable.
(assuan_set_assuan_err_source): Removed function.
(_assuan_w32_strerror): Moved here from assuan-logging.c and made
thread-safe.
(_assuan_error): Removed function (is now macro).
* assuan-handler.c: Update access to confidential flag.
* assuan-socket-server.c (accept_connection_bottom): Update access
to confidential flag in context.
(assuan_init_socket_server, assuan_init_socket_server_ext): Take
ctx argument instead of pointer to ctx.
* assuan-inquire.c (init_membuf, put_membuf, get_membuf)
(free_membuf): Take context argument and change all callers.
* assuan-socket-server.c (assuan_socket_connect)
(assuan_socket_connect_ext): Take ctx argument instead of pointer
to ctx.
* assuan-pipe-connect.c (initial_handshake, pipe_connect_unix)
(socketpair_connect, assuan_pipe_connect)
(assuan_pipe_connect_ext): Likewise.
(socketpair_connect): Now that ctx is not a pointer argument
anymore, return if we are server or client in the argv argument.
* assuan-logging.c (_assuan_log_handler): New function.
(_assuan_w32_strerror): Move to assuan-error.c
* assuan-connect.c (assuan_disconnect): Renamed to ...
(_assuan_disconnect): ... this.
* assuan-pipe-server.c (_assuan_new_context): Removed function.
(assuan_init_pipe_server): Take ctx argument instead of pointer to
ctx.
(_assuan_release_context): Removed function.
(_assuan_deinit_server): Reimplement.
2009-09-01 Marcus Brinkmann <marcus@g10code.de>
* assuan.h: Change types in all functions from int to gpg_error_t
where relevant.
* assuan-listen.c (assuan_accept): Change type of RC from int to
gpg_error_t.
* assuan-pipe-server.c (accept_connection, finish_connection):
Change return type to gpg_error_t.
* assuan-socket-server.c (accept_connection_bottom)
(accept_connection, finish_connection): Likewise.
(assuan_init_connected_socket_server): Remove.
* assuan-defs.h (struct assuan_context_s): Change return type of
accept_handler and finish_handler to gpg_error_t. Add io_monitor_data.
* assuan-pipe-connect.c (do_finish): Change to void.
* assuan-inquire.c (_assuan_inquire_ext_cb): Change type of RC
from int to gpg_error_t.
* assuan-handler.c: Change return codes and RC variables from int
to gpg_error_t where appropriate.
* assuan-buffer.c (_assuan_read_line): Fix error code on EOF.
* assuan.h (ASSUAN_INT2FD, ASSUAN_FD2INT): Remove macros.
* assuan-defs.h (DIMof): Remove macro.
* setenv.c: Do not include "assuan-defs.h", instead redefine
setenv, unsetenv, clearenv in place.
* assuan-socket-server.c: Use _assuan_free instead of xfree.
* assuan-pipe-connect.c: Fix syntax error.
* assuan-defs.h: Remove some duplicated W32 stuff.
* Makefile.am (libassuan_la_LIBADD, libassuan_pth_la_LIBADD): Add
@NETLIBS@.
* versioninfo.rc.in (FILEVERSION): Set to @BUILD_FILEVERSION@.
("FileDescription", "FileVersion", "InternalName")
("LegalCopyright", "OriginalFilename", "ProductName"): Replace c&p
garbage.
* libassuan.def: Remove assuan_get_peercred.
2009-08-26 Marcus Brinkmann <marcus@g10code.de>
* libassuan-config.in: Add gpg-error.
* assuan-buffer.c, assuan-inquire.c, assuan-handler.c,
assuan-util.c, assuan-client.c, assuan-socket-connect.c,
assuan-pipe-connect.c, assuan-defs.h, assuan-socket.c,
assuan-connect.c, assuan-uds.c, assuan-socket-server.c,
assuan-listen.c, assuan-pipe-server.c: Return gpg_error_t instead
assuan_error_t everywhere. Return gpg error codes everywhere.
Replace xtrymalloc, xfree, etc with _assuan_malloc, _assuan_free
etc. Protect include <config.h> by HAVE_CONFIG_H where not done
so already.
* versioninfo.rc.in, libassuan.vers, libassuan.def,
assuan-error.c: New files.
* Makefile.am: Add libtool handling and gpg-error (also for W32).
(EXTRA_DIST): Remove mkerrors, add libassuan.vers,
versioninfo.rc.in and libassuan.def.
(BUILT_SOURCES, MOSTLYCLEANFILES): Removed.
(common_sources): Remove assuan-errors.c, add assuan-error.c.
* assuan.h: Include <gpg-error.h>.
[_ASSUAN_ONLY_GPG_ERRORS]: Feature removed.
(assuan_init_connected_socket_server, assuan_strerror)
(assuan_pipe_connect2): Removed obsolete interfaces.
(assuan_error_t): Removed type.
(assuan_flag_t): Changed from enum to unsigned int.
(ASSUAN_NO_WAITPID, ASSUAN_CONFIDENTIAL): Changed from enum to macro.
(assuan_process): Return gpg_error_t instead of int.
(assuan_set_assuan_err_source): Change argument type from int to
gpg_err_source_t.
* assuan-defs.h (_assuan_error): Change types to gpg_error_t.
(err_code, err_is_eof, xtrymalloc, xtrycalloc, xtryrealloc)
(xfree): Removed.
(set_error): Adjust for gpg-error codes.
(_assuan_gpg_strerror_r, _assuan_gpg_strsource): Removed.
(struct assuan_context_s): Remove member os_errno.
* assuan-socket-server.c (accept_connection): Don't set CTX->os_errno.
* mkerrors: Removed file.
* assuan-io-pth.c (_assuan_simple_sendmsg)
(_assuan_simple_recvmsg), assuan-io.c (_assuan_simple_sendmsg,
_assuan_simple_recvmsg): Set errno instead returning error
directly (and return -1).
* assuan-handler.c (assuan_process_done): Remove handling for old
style error values.
(process_request, assuan_process): Change return type from int to
gpg_error_t.
* assuan-client.c (assuan_transact): Remove support for old style
error values.
* assuan-pipe-connect.c (assuan_pipe_connect2): Removed.
* assuan-logging.c (my_strerror_r, my_strsource)
(load_libgpg_error, _assuan_gpg_strerror_r)
(_assuan_gpg_strsource): Removed.
2009-04-03 Werner Koch <wk@g10code.com>
* assuan-handler.c (std_cmd_table): Remove second OPTION entry.
2009-02-24 Werner Koch <wk@g10code.com>
* assuan-buffer.c (assuan_send_data): Add hack to optionally send
a final "CAN".
2008-11-03 Marcus Brinkmann <marcus@g10code.de>
* assuan-handler.c (std_handler_help): Make I unsigned to silence
gcc -W warning.
* assuan-logging.c (_assuan_log_print_buffer): Likewise for N.
* funopen.c (_assuan_funopen): Remove initializer to silence gcc
-W warning.
* assuan-handler.c (std_cmd_table): Add missing initializer to
silence gcc -W warning.
* assuan-socket-server.c (io): Likewise.
* assuan-socket-connect.c (assuan_socket_connect_ext): Likewise.
2008-10-29 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (assuan_error_t) (_ASSUAN_ONLY_GPG_ERRORS): Make
unsigned int.
(assuan_transact): Change return type of callback handlers to
assuan_error_t.
2008-10-15 Werner Koch <wk@g10code.com>
* assuan-logging.c (_assuan_log_printf): Flush if the format
string ends with a LF.
2008-09-01 Werner Koch <wk@g10code.com>
* assuan-io.c: Include time.h. Fixes bug#951.
(_assuan_usleep): Use nanosleep only is available.
2008-03-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-inquire.c (assuan_inquire): Loop over _assuan_read_line
for EAGAIN.
2008-03-21 Marcus Brinkmann <marcus@g10code.de>
* assuan-defs.h (_assuan_usleep): New prototype.
* assuan-io.c (_assuan_usleep): New function.
* assuan-io-pth.c (_assuan_usleep): New function.
* mkerrors: Do not incude <windows.h>, but assuan-defs.h.
(_assuan_error_is_eagain): Call _assuan_usleep.
* mkerrors [HAVE_W32_SYSTEM]: Include <windows.h>
(_assuan_error_is_eagain) [HAVE_W32_SYSTEM]: Wait the tenth of a
second.
2007-11-23 Marcus Brinkmann <marcus@g10code.de>
* assuan-inquire.c (_assuan_inquire_ext_cb): Pass through return
value from callback function.
Suggested by Ben Kibbey <bjk@luxsci.net>.
2007-11-14 Werner Koch <wk@g10code.com>
* assuan-pipe-connect.c (pipe_connect_unix): Add dummy arg FLAGS.
(pipe_connect_w32): Add arg FLAGS and start process detached if
requested. Changed callers to pass 0.
(assuan_pipe_connect_ext): Pass FLAG.
2007-11-12 Marcus Brinkmann <marcus@g10code.de>
* assuan-inquire.c (_assuan_inquire_ext_cb): Clear
CTX->inquire_membuf after deallocating it.
2007-10-18 Marcus Brinkmann <marcus@g10code.de>
* assuan-handler.c (std_handler_help): New function.
(std_cmd_table): Add new command HELP.
2007-10-08 Werner Koch <wk@g10code.com>
* assuan-util.c (assuan_set_io_hooks): New.
* assuan.h (struct assuan_io_hooks): New.
(assuan_set_io_hooks, _assuan_io_hooks): Add prefix macros.
* assuan-defs.h (_assuan_io_hooks): New.
* assuan-io.c (do_io_read): Take all code from _assuan_io_read.
(_assuan_io_read, _assuan_simple_read): Add hook feature.
(do_io_write): Take all code from _assuan_io_write.
(_assuan_io_write, _assuan_simple_write): Add hook feature.
* assuan-io-pth.c (_assuan_simple_read, _assuan_simple_write)
(_assuan_io_read, _assuan_io_write): Add hook feature.
2007-10-05 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (_assuan_error_is_eagain): Add prefix macro.
* assuan-defs.h (_assuan_error_is_eagain): New prototype.
* mkerrors (_assuan_error_is_eagain): New function.
* assuan-handler.c (process_next): Leave on EAGAIN.
* assuan-handler.c (process_request),
assuan-client.c (_assuan_read_from_server),
assuan-buffer.c (assuan_read_line): Busy loop over EAGAIN.
2007-10-05 Werner Koch <wk@g10code.com>
* assuan-socket.c (_assuan_sock_wsa2errno): Map WSANOTINITIALISED.
(_assuan_sock_new): Use assuan_fd_t.
* assuan.h (_assuan_sock_wsa2errno): Add prefix macro.
2007-10-05 Marcus Brinkmann <marcus@g10code.de>
* assuan-defs.h (_assuan_sock_wsa2errno) [HAVE_W32_SYSTEM]: Add prototype.
* assuan-uds.c (wsa2errno) [HAVE_W32_SYSTEM]: Move and rename to ...
* assuan-socket.c (_assuan_sock_wsa2errno) [HAVE_W32_SYSTEM]: ... this.
(_assuan_close, _assuan_sock_new, _assuan_sock_connect, _assuan_sock_bind):
Always set errno on error.
* assuan-uds.c (wsa2errno) [HAVE_W32_SYSTEM]: New function.
(uds_reader, uds_writer) [HAVE_W32_SYSTEM]: Set errno.
2007-10-04 Werner Koch <wk@g10code.com>
* mkerrors: Map EAGAIN to GPG_ERR_EAGAIN for read and write
errors.
2007-10-02 Werner Koch <wk@g10code.com>
* assuan-io.c (_assuan_io_read) [W32]: Map WSAEWOULDBLOCK to EAGAIN.
* assuan-socket.c (_assuan_sock_check_nonce): N needs to be signed.
* assuan-defs.h (struct assuan_context_s): Add LISTEN_NONCE.
* assuan-socket-server.c (assuan_set_sock_nonce): New.
(accept_connection): Check the nonce.
2007-10-01 Werner Koch <wk@g10code.com>
* assuan.h (ASSUAN_INT2FD, ASSUAN_FD2INT): New.
* assuan-socket.c: Rewritten.
(assuan_sock_new, assuan_sock_connect, assuan_sock_bind)
(assuan_sock_get_nonce, assuan_sock_check_nonce): New APIs.
* assuan-io.c (_assuan_simple_read, _assuan_simple_write):
Factored code out to ...
(_assuan_io_read, _assuan_io_write): .. new.
* assuan-io-pth.c (_assuan_io_read, _assuan_io_write): New.
2007-09-25 Werner Koch <wk@g10code.com>
* assuan.h (_assuan_gpg_strerror_r, _assuan_gpg_strsource): Add
wrappers for these new internal functions.
2007-09-24 Marcus Brinkmann <marcus@g10code.de>
* assuan-uds.c (uds_reader) [HAVE_W32_SYSTEM]: Do not touch the
UDS structure in the context. Reported by Frank Osterfeld.
(uds_writer): Clarify code.
2007-09-14 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (do_finish) [HAVE_W32_SYSTEM]: Close
ctx->pid as handle.
(pipe_connect_w32): Save the spawned processes handle.
2007-09-13 Werner Koch <wk@g10code.com>
* assuan-socket.c (_assuan_close): Add inactive debug outputs.
2007-09-11 Marcus Brinkmann <marcus@g10code.de>
* assuan.h: Use _WIN32 instead of HAVE_W32_SYSTEM.
2007-09-07 Marcus Brinkmann <marcus@g10code.de>
* assuan-inquire.c (assuan_inquire_ext): If MAXLEN is 0, still
initialize MEMBUF.
* assuan-inquire.c (_assuan_inquire_ext_cb): Clear CTX->in_inquire
before invoking callback and returning.
2007-09-05 Marcus Brinkmann <marcus@g10code.de>
* assuan-handler.c (dispatch_command): Return non-critical errors
with PROCESS_DONE ().
2007-09-03 Marcus Brinkmann <marcus@g10code.de>
* assuan.h [_ASSUAN_EXT_SYM_PREFIX]: Add missing symbol renames
with _ASSUAN_PREFIX.
2007-09-03 Marcus Brinkmann <marcus@g10code.de>
* assuan.h [_ASSUAN_EXT_SYM_PREFIX]: Add missing symbol renames
with _ASSUAN_PREFIX.
* assuan.h (assuan_inquire_ext): Move buffer and buffer_length
arguments callback in prototype.
* assuan-defs.h (struct assuan_context_s): Remove members
inquire_r_buffer and inquire_r_buffer_len. Add buffer and buffer
length arguments to inquire_cb.
* assuan-inquire.c (_assuan_inquire_ext_cb): Return buffer and
buffer length via callback.
(assuan_inquire_ext): Move buffer and buffer length arguments to
callback.
2007-08-24 Werner Koch <wk@g10code.com>
Switched license to back to LGPLv2.1.
2007-08-09 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (assuan_process_done, assuan_inquire_ext): New
prototypes.
* assuan-defs.h (struct assuan_context_s): New members
in_process_next, in_command, inquire_cb, inquire_cb_data,
inquire_r_buffer, inquire_r_buffer_len, inquire_membuf.
(_assuan_inquire_ext_cb, _assuan_inquire_release): New prototypes.
* assuan-handler.c (PROCESS_DONE): New macro.
(dummy_handler, std_handler_nop, std_handler_cancel)
(std_handler_option, std_handler_bye, std_handler_auth)
(std_handler_reset, std_handler_end): Use PROCESS_DONE to
optionally call assuan_process_done if CTX->in_process_next is
true.
(assuan_process_done, process_next): New functions.
(assuan_process_next): Rewritten to support external event
handling.
* mkerrors: Do not clear high bits of -1 for old style EOF.
* assuan-inquire.c (_assuan_inquire_release)
(_assuan_inquire_ext_cb, assuan_inquire_ext): New functions.
* assuan-pipe-server.c (_assuan_release_context): Call
_assuan_inquire_release.
2007-07-12 Werner Koch <wk@g10code.com>
* assuan.h (assuan_fd_t): New.
(ASSUAN_INVALID_FD): New. Use it everywhere.
* assuan-defs.h (SOCKET2HANDLE, HANDLE2SOCKET) [W32]: New. Use
them to cast descriptors for socket fucntions.
* assuan-pipe-connect.c (fd_to_handle, handle_to_fd): Remove
definition and all uses.
(pid_to_handle, handle_to_pid): Remove as they are ununsed.
* assuan-io.c (_assuan_simple_write, _assuan_simple_read) [W32]:
Make use of HANDLE2SOCKET.
* assuan-socket.c (_assuan_close) [W32]: Use CloseHandle and not
close.
* assuan-handler.c (assuan_get_active_fds) [W32]: Use
_get_osfhandle for the data fp.
* assuan-io.c (_assuan_simple_write): Return EPIPE on a closed pipe.
(_assuan_simple_read): Likewise
2007-07-08 Marcus Brinkmann <marcus@g10code.de>
* assuan-defs.h (struct assuan_context_s): Have full peercred
structure for HAVE_SO_PEERCRED.
* assuan-connect.c (assuan_get_peercred) [!HAVE_SO_PEERCRED]: Do
not try to set PID, UID and GID.
2007-07-05 Werner Koch <wk@g10code.com>
* assuan-defs.h (struct assuan_context_s): Have peercred.valid
even for Windows. This makes some other code cleaner.
* assuan.h (ASSUAN_CONFIDENTIAL): New flag.
* assuan-util.c (assuan_set_flag, assuan_get_flag): Support flag.
2007-07-04 Marcus Brinkmann <marcus@g10code.de>
Change _WIN32 to HAVE_W32_SYSTEM for consistency.
* assuan-defs.h (struct assuan_context_s): Have full peercred
structure even if not HAVE_SO_PEERCRED, but not if
HAVE_W32_SYSTEM.
2007-06-18 Werner Koch <wk@g10code.com>
* assuan-logging.c (load_libgpg_error, _assuan_gpg_strerror_r)
(_assuan_gpg_strsource): New.
* assuan-handler.c (process_request) [W32]: Use these new
functions for human understable error codes.
2007-06-12 Werner Koch <wk@g10code.com>
* assuan-io.c (_assuan_simple_read): Hack to allow reading from a
socket.
(_assuan_simple_write): Likewise.
2007-06-11 Werner Koch <wk@g10code.com>
* assuan-io-pth.c (_assuan_simple_read, _assuan_simple_write): Use
pth versions also for W32.
2007-05-29 Werner Koch <wk@g10code.com>
* assuan-io-pth.c: Include sys/socket.h only if available. Remove
double inclusion of sys/wait.h
* assuan-pipe-connect.c (build_w32_commandline): Make ARGV const.
* assuan-pipe-server.c (is_valid_socket) [W32]: Do not define.
* assuan-socket-server.c [W32]: Include ws2tcpip.h to define
socklen_t.
* assuan-defs.h (struct assuan_context_s): Define most peercred
members only if we can really set them.
(_assuan_simple_sendmsg, _assuan_simple_recvmsg) [W32]: Use a
different prototype.
* assuan.h (assuan_get_peercred) [W32]: Do not define.
* assuan-io.c (_assuan_simple_sendmsg, _assuan_simple_recvmsg)
[w32]: Use another prototype.
2007-05-09 Werner Koch <wk@g10code.com>
* libassuan.m4: Print found version on success.
2007-05-01 Werner Koch <wk@g10code.com>
* assuan-uds.c (uds_reader): Cast void ptr for arithmetics.
Reported by Peter O'Gorman.
2006-12-03 Marcus Brinkmann <marcus@g10code.de>
* assuan-handler.c (assuan_command_parse_fd): Also allow white
space after FD.
2006-12-02 Marcus Brinkmann <marcus@g10code.de>
* assuan-uds.c (uds_reader): Return 0 if recvmsg returns 0.
2006-12-01 Marcus Brinkmann <marcus@g10code.de>
* assuan-client.c (assuan_transact): Also translate some of the
legacy error codes.
2006-11-22 Werner Koch <wk@g10code.com>
* assuan-handler.c (fun1_cookie_write, fun2_cookie_write): New.
(assuan_get_data_fp) [HAVE_FUNOPEN]: Use it.
2006-11-21 Werner Koch <wk@g10code.com>
* Makefile.am (libassuan_pth_a_CFLAGS): New.
* assuan-pipe-server.c (_assuan_release_context): Free CMDTBL.
2006-11-14 Werner Koch <wk@g10code.com>
* libassuan.m4 (AM_CHECK_LIBASSUAN): New.
* assuan-handler.c (assuan_register_post_cmd_notify)
(assuan_register_post_cmd_notify): New.
* assuan-util.c (assuan_set_io_monitor): New.
* assuan-buffer.c (_assuan_read_line): Use it.
(_assuan_write_line): Ditto.
(_assuan_cookie_write_data): Ditto.
(_assuan_cookie_write_flush): Ditto.
2006-10-18 Werner Koch <wk@g10code.com>
* libassuan.m4: Pass "pthread" to the common macro. Reported by
Rex Dieter.
2006-10-16 Werner Koch <wk@g10code.com>
* mkerrors: Map ASSUAN_Not_Confirmed.
2006-10-10 Werner Koch <wk@g10code.com>
* libassuan.m4 (AM_PATH_LIBASSUAN_PTH)
(AM_PATH_LIBASSUAN_PTHREAD): Fixed.
* assuan-buffer.c (assuan_sendfd): Implement a runtime detection
of implemented descripotr passing.
* assuan-uds.c: Take care of USE_DESCRIPTOR_PASSING.
* assuan-defs.h: Add missing semicolon.
2006-10-09 Werner Koch <wk@g10code.com>
* assuan-handler.c (process_request): Use weak pragma for the sake
of old gcc's. Reported by Alain Guibert.
* assuan-io.c: Removed Pth support.
* assuan-io-pth.c: New. Based on assuan-io.c
2006-10-06 Werner Koch <wk@g10code.com>
* libassuan-config.in: New options --api-version and --thread.
2006-10-04 Werner Koch <wk@g10code.com>
* assuan-client.c (assuan_transact): Need to map old assuan status
codes so that for example CANCELED is correctly mapped.
2006-09-28 Marcus Brinkmann <marcus@g10code.de>
* assuan-client.c (assuan_transact): Do not convert error on
status line, it is already a gpg-error. Do convert
ASSUAN_Server_Fault.
2006-09-19 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (assuan_init_socket_server_ext)
[_ASSUAN_EXT_SYM_PREFIX]: Fix typo in macro.
2006-09-19 Werner Koch <wk@g10code.com>
* assuan-defs.h (putc_unlocked): Add prototype.
* assuan-socket-server.c (accept_connection): Made LEN a socklen_t.
* assuan.h: Replaced assuan error code enum by simple defines and
made assuan_error_t an int.
* mkerrors: Changed parser accordingly.
2006-09-19 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c: Add hacks for Slowaris.
* assuan-socket.c: Likewise here.
* assuan.h (enum): Avoid trailing comma in enumerator list. Ugh.
* mkerrors (_assuan_error): Change return type to assuan_error_t.
* assuan-buffer.c (_assuan_read_line): Change return type to
assuan_error_t. Map returned value of -1.
(_assuan_write_line): Change type of RC to assuan_error_t.
* assuan-defs.h (_assuan_read_line, _assuan_error): Likewise for
prototypes.
* assuan-defs.h (unsetenv): Define correctly.
2006-09-14 Werner Koch <wk@g10code.com>
* assuan-io.c (_assuan_waitpid): New. Changed all waitpid calls
to this.
* assuan.h (_ASSUAN_DEPRECATED): New internal macro.
(assuan_pipe_connect2): Declare deprecated.
(assuan_init_connected_socket_server): Declare deprecated.
* assuan-connect.c (assuan_get_peercred): New.
* assuan-socket-server.c (accept_connection_bottom): Save uid and gid.
2006-09-13 Werner Koch <wk@g10code.com>
* assuan-client.c (assuan_transact): Need to map the error code.
* mkerrors: Need to map ASSUAN_No_Secret_Key.
* assuan-pipe-server.c (is_valid_socket): New.
(assuan_init_pipe_server): Use UDS with the environmet variable is
set and a valid descriptor is given. Ignore FILEDES in this case.
* assuan-socket-server.c (assuan_init_socket_server_ext): New.
Changed other init fucntions to make use of it.
* assuan-handler.c (assuan_command_parse_fd): Allow for lowercase
"fd".
(std_handler_reset): Close pending fds.
* assuan-uds.c (uds_receivefd): Fixed.
(_assuan_uds_close_fds): New.
* assuan-socket-connect.c (assuan_socket_connect_ext): New. Takes
all code of assuan_socket_connect plus an option to use sendmsg.
* assuan-pipe-connect.c (assuan_pipe_connect_ext): New arg FLAGS.
2006-09-12 Werner Koch <wk@g10code.com>
* assuan-buffer.c (_assuan_write_line): Also log the prefix.
* assuan-defs.h (DIM, DIMof): New.
* assuan-domain-server.c: Removed.
* assuan-domain-connect.c: Renamed to ..
* assuan-uds.c: this.
(domain_reader, domain_writer, domain_sendfd, domain_receivefd)
(assuan_domain_connect, _assuan_domain_init): Removed.
(uds_reader, uds_writer, uds_sendfd, uds_receivefd)
(_assuan_init_uds_io): New.
(_assuan_uds_deinit): New.
* assuan-io.c (_assuan_simple_sendmsg, _assuan_simple_recvmsg): New.
(my_pth_fdmode, my_pth_select): New.
2006-09-11 Werner Koch <wk@g10code.com>
* assuan-pipe-server.c (assuan_init_pipe_server): Allow for
FILEDES to be NULL and try to start as a socketpair server in this
case.
* assuan-pipe-connect.c (assuan_pipe_connect2): Split up into two
functions (unix and w32) for clarity.
(pipe_connect_unix): This is the new fucntion. Add USE_CMSG flag.
(pipe_connect_w32): Ditto.
(initial_handshake): Factored out code.
(socketpair_connect): New.
(assuan_pipe_connect_ext): New.
(do_finish): Handle case if outbound and inbound fd are the same.
This is to support socketpairs.
2006-09-10 Werner Koch <wk@g10code.com>
* assuan-util.c (_assuan_log_print_buffer)
(_assuan_log_sanitized_string,assuan_set_log_stream): Moved to ..
* assuan-logging.c: .. here.
(_assuan_log_print_buffer): Only print the leading bytes in hex
log mode unless the new env variable ASSUAN_FULL_LOGGING has been
set.
(_assuan_set_default_log_stream): Test this env variable.
2006-09-06 Werner Koch <wk@g10code.com>
* assuan.h (_ASSUAN_ONLY_GPG_ERRORS): New.
* assuan-handler.c (dispatch_command): Use Syntax_Error instead of
Invalid_Command.
* assuan-domain-connect.c: Changed alloc malloc/free/realloc to
xtrymalloc et al.
(read_int, write_int): Make args void pointers.
(domain_receivefd): Take care of realloc shrinking failure.
* assuan-buffer.c (_assuan_read_line, _assuan_write_line)
(assuan_write_line, _assuan_cookie_write_data)
(_assuan_cookie_write_flush): Print the inbound fd instead of the
address of the context when logging I/0. This makes it more
readable.
2006-09-05 Werner Koch <wk@g10code.com>
* assuan-defs.h (err_code, err_is_eof): New.
* mkerrors (_assuan_error): New. Wrapped all error code
assignments in a call to this.
(assuan_strerror): Map gpg-style error codes back. Also print a
string for the old EOF code.
(assuan_set_assuan_err_source): New.
* assuan-logging.c (_assuan_log_printf): Do not change ERRNO and
print the pid.
* assuan-domain-connect.c (domain_reader): Replaced plain printf
by assuan_log function.
2005-10-24 Werner Koch <wk@g10code.com>
* putc_unlocked.c, memrchr.c, isascii.c, funopen.c: Changed
distribution terms to LGPL. This are small and trivial files so
there are no obstacles of doing so.
* assuan-socket.c: Likewise, the stated GPL was not intended.
2005-10-08 Marcus Brinkmann <marcus@g10code.de>
* assuan-defs.h (setenv, unsetenv, clearenv) [!HAVE_SETENV]:
Define to _assuan_*.
* setenv.c: Include "assuan-defs.h".
(__add_to_environ): Make static.
2005-10-07 Marcus Brinkmann <marcus@g10code.de>
* assuan-defs.h (memrchr) [!HAVE_MEMRCHR]: New prototype.
(stpcpy) [!HAVE_STPCPY]: Likewise.
* stpcpy.c: New LGPL'ed file from the GNU C Library.
* setenv.c: New file.
* assuan-domain-connect.c (read_int): New function.
(write_int): New function.
(domain_reader): Use read_int.
(domain_sendfd): Use write_int.
2005-10-01 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (assuan_pipe_connect, assuan_pipe_connect2): Make type
of ARGV parameter const in prototype.
* assuan-pipe-connect.c (assuan_pipe_connect,
assuan_pipe_connect2): Likewise in declaration.
(assuan_pipe_connect2): Add braindead cast to make execv happy.
* assuan-client.c (assuan_transact): Change LINE, S and D from
unsigned char * to char * to silence gcc warning.
* assuan-util.c (_assuan_log_sanitized_string): Add explicit cast
to silence gcc warning.
* assuan-inquire.c (assuan_inquire): Likewise.
2005-09-08 Marcus Brinkmann <marcus@g10code.com>
* assuan-pipe-connect.c (assuan_pipe_connect2): Add missing
declaration of PID.
2005-08-09 Werner Koch <wk@g10code.com>
* mkerrors: Include config.h into assuan-errors.c. This is
required so that assuan.h knows about the W32 macro.
* assuan.h [_ASSUAN_EXT_SYM_PREFIX]: New.
* assuan-io.c [_ASSUAN_NO_PTH]: New.
* assuan-pipe-connect.c (fix_signals) [_ASSUAN_NO_FIXED_SIGNALS]: New.
(assuan_pipe_connect2) [_ASSUAN_USE_DOUBLE_FORK]: Use double fork.
(fix_signals) [_ASSUAN_USE_DOUBLE_FORK]: Do not wait..
2005-05-21 Werner Koch <wk@g10code.com>
* assuan-util.c (assuan_set_flag, assuan_get_flag): New.
* assuan-defs.h (struct assuan_context_s): New field flags.
* assuan.h (assuan_flag_t): New with one flag value
ASSUAN_NO_WAITPID for now.
* assuan-pipe-connect.c (do_finish): Take care of the no_waitpid
flag.
2005-04-04 Werner Koch <wk@g10code.com>
* assuan-util.c (_assuan_calloc): Avoid integer overflow.
2005-03-22 Werner Koch <wk@g10code.com>
* assuan-defs.h (struct assuan_io): Renamed elements READ and
WRITE to READFNC and WRITEFNC to avoid problems with read defined
as macros. Changed callers. Noted by Ville Skyttä.
2005-02-24 Werner Koch <wk@g10code.com>
* assuan-client.c (assuan_transact): Handle empty and comment
commands correctly.
2004-12-20 Werner Koch <wk@g10code.com>
* assuan-socket-connect.c (assuan_socket_connect) [W32]: Allow for
a drive letter in the path.
2004-12-19 Werner Koch <wk@g10code.com>
* assuan-pipe-server.c (assuan_init_pipe_server) [W32]: Map file
descriptors using _get_osfhandle.
2004-12-19 Moritz Schulte <moritz@g10code.com>
* assuan-pipe-connect.c (assuan_pipe_connect2): Removed "`"
character at beginning of line 532.
2004-12-18 Werner Koch <wk@g10code.com>
* assuan-logging.c (_assuan_w32_strerror): New.
* assuan-defs.h (w32_strerror): new.
* assuan-pipe-connect.c (assuan_pipe_connect2, fix_signals):
Factored signal code out to new function.
(build_w32_commandline, create_inheritable_pipe): New. Taken
from gnupg 1.9.
(assuan_pipe_connect2) [W32]: Implemented for W32.
2004-12-14 Werner Koch <wk@g10code.com>
* assuan-socket-connect.c (assuan_socket_connect): Always allow
NAME to start with a froward slash.
2004-12-07 Werner Koch <wk@g10code.com>
* assuan-logging.c, assuan-io.c: Include config.h
Replaced all usages of _WIN32 by the new HAVE_W32_SYSTEM because
there is nothing winning in this API.
* assuan-pipe-connect.c (assuan_pipe_connect2) [_WIN32]: Return
error Not Imlemented.
2004-11-27 Werner Koch <wk@g10code.com>
* assuan-socket.c: Include sys/types.h. Noted by Michael
Nottebrock.
2004-11-26 Werner Koch <wk@g10code.com>
* assuan-io.c [_WIN32]: Avoid warnings about unknown pragmas.
2004-11-24 Werner Koch <wk@g10code.com>
* assuan-logging.c (_assuan_log_printf): New.
* assuan-domain-connect.c (LOG): Removed and replaced all callers
by _assuan_log_printf. This is needed for C89 and gcc 2.95 which
both don't have C99 style variable arg macros.
* assuan-pipe-connect.c (LOG): Ditto.
* assuan-socket-connect.c (LOG): Ditto.
* assuan-socket.c[!_WIN32]: Fixed includes.
2004-11-23 Timo Schulz <twoaday@g10code.com>
* assuan-socket.c (_assuan_sock_connect): Get local port from
the sun_path[] file.
(_assuan_sock_bind): Write local port to the sun_path[] file.
* assuan-socket-connect.c (assuan_socket_connect): Use DIRSEP_C
for a better portability.
(assuan-defs.h): Define DIRSEP_C.
2004-11-19 Werner Koch <wk@g10code.com>
* assuan-handler.c (assuan_write_status): Return an error code.
2004-11-22 Timo Schulz <twoaday@g10code.com>
* assuan-io.c (_assuan_simple_read, _assuan_simple_write): W32
support.
* assuan-socket.c (_assuan_close): New.
(_assuan_sock_new): New.
(_assuan_sock_bind): New.
2004-11-16 Werner Koch <wk@g10code.com>
* assuan-socket-connect.c (LOG): Fixed macro to print not only the
prefix.
* assuan-domain-connect.c, assuan-socket-connect.c (LOG): Ditto.
2004-10-02 Werner Koch <wk@g10code.com>
* assuan-socket-connect.c: Define SUN_LEN, AF_LOCAL and PF_LOCAL
if they are not available.
* assuan-domain-connect.c: Define PF_LOCAL and AF_LOCAL if needed.
2004-06-23 Marcus Brinkmann <marcus@g10code.de>
* assuan-domain-connect.c [HAVE_SYS_UIO_H]: Include <sys/uio.h>.
2004-05-11 Werner Koch <wk@gnupg.org>
* assuan-listen.c (assuan_set_hello_line, assuan_accept): Allow
for multi line hello strings.
* assuan-buffer.c (_assuan_write_line): New with parts of ..
(assuan_write_line): .. factored out.
2004-04-29 Werner Koch <wk@gnupg.org>
* assuan-socket-connect.c: Include string.h.
* assuan-logging.c: Ditto.
2004-04-22 Marcus Brinkmann <marcus@g10code.de>
* libassuan.m4: Quote first argument to AC_DEFUN.
2004-04-21 Werner Koch <wk@gnupg.org>
* assuan-socket-server.c (accept_connection_bottom): Save the pid
of the peer if it is available.
* assuan-socket-connect.c (assuan_socket_connect): Do not save the
dummy SERVED_PID arg.
* assuan-pipe-connect.c (do_finish): Don't wait if the pid is 0.
(assuan_pipe_connect2): Store the parents pid in the environment
of the child.
* assuan-pipe-server.c (assuan_init_pipe_server): Initialize the
peer's pid from the environment.
* assuan-connect.c (assuan_get_pid): Do not return 0 as a PID.
2004-04-19 Werner Koch <wk@gnupg.org>
* assuan-socket-server.c, assuan-socket-connect.c: Includes
sys/types.h. Reported by Michael Nottebrock.
* assuan-domain-connect.c: Ditto.
2004-04-13 Werner Koch <wk@gnupg.org>
* assuan-util.c (_assuan_log_print_buffer): Relaxed quoting.
(_assuan_log_sanitized_string): Ditto.
2004-03-14 Werner Koch <wk@gnupg.org>
* assuan-handler.c: Include <errno.h>. Reported by Bernd Kuhls.
2004-02-18 Werner Koch <wk@gnupg.org>
* libassuan-config.in: Ignore setting of --prefix.
* assuan-handler.c (assuan_get_data_fp): Fail with ENOSYS if we
can't implement this.
2004-02-15 Werner Koch <wk@gnupg.org>
* memrchr.c (memrchr): Fixed implementation. Taken from gpgme.
2004-02-13 Werner Koch <wk@gnupg.org>
* assuan-domain-connect.c: Removed the unneeded alloca.h.
2004-01-24 Werner Koch <wk@gnupg.org>
* assuan-pipe-connect.c (assuan_pipe_connect2): New as an
extension of assuan_pipe_connect. Made the latter call this one.
2004-01-14 Werner Koch <wk@gnupg.org>
* assuan-buffer.c (_assuan_cookie_write_data): Return the
requested size to indicate successful operation. Fixes a spurious
bug we previously fixed using fflush().
2003-12-22 Werner Koch <wk@gnupg.org>
* assuan.h (ASSUAN_Locale_Problem): Added.
* assuan-errors.c (assuan_strerror): Ditto.
2003-12-18 Werner Koch <wk@gnupg.org>
* assuan.h (AssuanCommand): Clarified that these are now
deprecated and actually useless.
(assuan_error_t): Clarified and added ASSUAN_USER_ERROR_FIRST,
ASSUAN_USER_ERROR_LAST.
2003-12-16 Werner Koch <wk@gnupg.org>
* assuan-buffer.c: Changed formatting of the debug output prefix.
* assuan-util.c (assuan_set_log_stream): Set global log stream if
it has not been done yet.
* assuan-logging.c (_assuan_set_default_log_stream): New.
(assuan_set_assuan_log_prefix): New.
2003-12-11 Werner Koch <wk@gnupg.org>
* funopen.c (_assuan_funopen): Renamed from funopen, to keep the
name space clean and avoid duplicate definitions if another
library uses the same replacement.
* assuan-defs.h (funopen): Renamed prototype and add a macro.
2003-12-08 Werner Koch <wk@gnupg.org>
* TODO: Removed.
2003-11-12 Werner Koch <wk@gnupg.org>
* assuan-handler.c (process_request): Kludge to print better error
messages for gpg-error enabled programs.
2003-11-06 Werner Koch <wk@gnupg.org>
* assuan.h (assuan_context_t): New. Should be used in favor of
ASSUAN_CONTEXT.
(assuan_error_t): New. To be used instead of AssuanError.
2003-11-11 Moritz Schulte <mo@g10code.com>
* assuan-socket-connect.c (assuan_socket_connect): Fix computation
of socket address length.
2003-08-13 Werner Koch <wk@gnupg.org>
* assuan-inquire.c (assuan_inquire): Increase length of cmdbuf to
the Assuan limit.
2003-06-24 Werner Koch <wk@gnupg.org>
* mkerrors: Kludge to print libgpg-error values in an easier
readable way.
2003-04-29 Werner Koch <wk@gnupg.org>
* libassuan.m4: New. Based on libgrypt.m4.
* Makefile.am (m4data_DATA): New.
* assuan.h (AssuanCommand): Removed.
* assuan-handler.c: Remove the cmd_id element,
(assuan_register_command): Likewise. Note that semantics changed.
(_assuan_register_std_commands): Adjusted.
2003-02-22 Neal H. Walfield <neal@g10code.de>
* Makefile.am (bin_SCRIPTS): Renamed from bin_PROGRAMS.
2003-02-18 Neal H. Walfield <neal@g10code.de>
* Makefile.am (libassuan_a_LIBADD): New variable.
* funopen.c: Move from ../common.
* isascii.c: Likewise.
* memrchr.c: Likewise.
* putc_unlocked.c: Likewise.
2003-02-18 Neal H. Walfield <neal@g10code.de>
* assuan-handler.c (_IO_cookie_io_functions_t): Remove.
(cookie_io_functions_t): Remove.
(fopencookie): Remove prototype.
(assuan_get_data_fp): Use funopen, not fopencookie.
2003-02-18 Neal H. Walfield <neal@g10code.de>
* libassuan-config.in: New file.
* Makefile.am (bin_PROGRAMS): New variable.
2003-02-17 Neal H. Walfield <neal@g10code.de>
* .cvsignore: New file.
2003-02-17 Neal H. Walfield <neal@g10code.de>
* Makefile.am (lib_LIBRARIES): Use this instead of . . .
(noinst_LIBRARIES): . . . this.
(include_HEADERS): New variable.
(libassuan_a_SOURCES): Remove assuan.h, add assuan-logging.c.
* assuan.h (assuan_set_assuan_log_stream): New prototype.
(assuan_get_assuan_log_stream): Likewise.
(assuan_get_assuan_log_prefix): Likewise.
* assuan-logging.c: New file.
* assuan-buffer.c [HAVE_JNLIB_LOGGIN]: Do not include
"../jnlib/logging.h".
(my_log_prefix): Remove function.
(_assuan_read_line): Use assuan_get_assuan_log_prefix in lieu of
my_log_prefix.
(assuan_write_line): Likewise.
(_assuan_cookie_write_data): Likewise.
(_assuan_cookie_write_flush): Likewise.
* assuan-domain-connect.c (LOGERROR, LOGERROR1, LOGERROR2,
LOGERRORX): Remove.
(LOG): New macro.
(domain_reader): Use it.
(domain_writer): Likewise.
(domain_sendfd): Likewise.
(domain_receivefd): Likewise.
(_assuan_domain_init): Likewise.
(assuan_domain_connect): Likewise.
* assuan-pipe-connect.c [HAVE_JNLIB_LOGGIN]: Do not include
"../jnlib/logging.h".
(LOGERROR, LOGERROR1, LOGERROR2, LOGERRORX): Remove.
(LOG): New macro.
(assuan_pipe_connect): Use it.
* assuan-socket-connect.c [HAVE_JNLIB_LOGGIN]: Do not include
"../jnlib/logging.h".
(LOGERROR, LOGERROR1, LOGERROR2, LOGERRORX): Remove.
(LOG): New macro.
(assuan_socket_connect): Use it.
(socket_reader): Remove dead code.
(socket_writer): Likewise.
* assuan-util.c [HAVE_JNLIB_LOGGIN]: Do not include
"../jnlib/logging.h".
(_assuan_log_sanitized_string): Use assuan_get_assuan_log_stream,
not jnlib.
2002-11-24 Neal H. Walfield <neal@g10code.de>
* assuan.h (assuan_command_parse_fd): New prototype.
* assuan-handler.c (assuan_command_parse_fd): Rename from
parse_cmd_input_output. Export.
(std_handler_input): Update to use assuan_command_parse_fd.
(std_handler_output): Likewise.
2002-11-24 Neal H. Walfield <neal@g10code.de>
* assuan.h (assuan_sendfd): New prototype.
(assuan_receivefd): New prototype.
* assuan-buffer.c (assuan_sendfd): New function.
(assuan_receivefd): New function.
* assuan-handler.c (parse_cmd_input_output): Recognize incoming
file descriptors and act appropriately.
* assuan-defs.h (struct assuan_io): Add fields sendfd and
receivefd.
(struct assuan_context_s): Add fields pendingfds and
pendingfdscount.
* assuan-pipe-server.c (_assuan_new_context): Update IO to reflect
new features.
* assuan-domain-connect.c (do_deinit): Cleanup any unreceived file
descriptors.
(domain_reader): Receive file descriptors.
(domain_sendfd): New function.
(domain_receivefd): New function.
(_assuan_domain_init): Update initialization code to reflect new
features.
2002-11-24 Neal H. Walfield <neal@g10code.de>
* assuan-domain-connect.c (do_finish): Remove.
(_assuan_domain_init): Use default handlers where possible.
Add an assert and update comments.
* assuan-domain-server.c (accept_connection): Remove.
(assuan_init_domain_server): Use default handlers where possible.
Put the server in pipe mode: it can only be used by a single
client.
2002-11-24 Neal H. Walfield <neal@g10code.de>
* assuan.h: Add prototype for assuan_domain_connect and
assuan_init_domain_server.
* assuan-defs.h: Include <unistd.h>.
Add prototype for _assuan_domain_init.
* assuan-domain-connect.c: New file.
* assuan-domain-server.c: New file.
* Makefile.am (libassuan_a_SOURCES): Add assuan-domain-connect.c
and assuan-domain-server.c
2002-11-23 Neal H. Walfield <neal@g10code.de>
* Makefile.am (libassuan_a_SOURCES): Add assuan-io.c.
* assuan-io.c: Restore.
(_assuan_simple_read): Rename from _assuan_read.
(_assuan_simple_write): Rename from _assuan_write.
* assuan-defs.h (_assuan_simple_read): New prototype.
(_assuan_simple_write): Likewise.
* assuan-pipe-server.c (pipe_reader): Remove.
(pipe_writer): Remove.
(_assuan_new_context): Initialize IO is with _assuan_simple_read
and _assuan_simple_write.
* assuan-socket-connect.c (socket_reader): Remove.
(socket_writer): Remove.
(assuan_socket_connect): Initialize IO is with _assuan_simple_read
and _assuan_simple_write.
* assuan-socket-server.c (io): New local variable.
(assuan_init_socket_server): Initialize CTX->io.
(assuan_init_connected_socket_server): Likewise.
2002-11-23 Neal H. Walfield <neal@g10code.de>
* assuan-buffer.c (readline): Use memrchr.
(_assuan_read_line): Rewritten to use the string functions.
2002-11-20 Neal H. Walfield <neal@g10code.de>
* assuan-socket-connect.c (assuan_socket_connect): Pass PF_LOCAL
to socket(), not AF_UNIX: it expects a PF_* macro and the former
is more portable.
(assuan_socket_connect): Use AF_LOCAL, not AF_UNIX which is more
POSIXy.
2002-11-20 Neal H. Walfield <neal@g10code.de>
* assuan-defs.h (struct assuan_io): New structure.
(struct assuan_context_s): New field, io.
(_assuan_read): Depreciated.
(_assuan_write): Likewise.
* assuan-pipe-server.c: Include <unistd.h>.
(pipe_reader): New function.
(pipe_writer): Likewise.
(_assuan_new_context.IO): New local static. Set to pipe_reader
and pipe_writer. Use it to initialize new context.
* assuan-socket-connect.c (socket_reader): New function.
(socket_writer): New function.
(assuan_socket_connect.IO): New local static. Set to socket_reader
and socket_writer. Use it to initialize new context.
* assuan-buffer.c (writen): Take an ASSUAN_CONTEXT rather than a
file descriptor. Do not use _assuan_write but the write method
in the supplied context.
(readline): Likewise for _assuan_read.
(assuan_write_line): When calling writen, pass CTX; not the file
descriptor directly.
(_assuan_cookie_write_data): Likewise.
(_assuan_cookie_write_flush): Likewise.
(_assuan_read_line): Likewise for readline.
* Makefile.am (libassuan_a_SOURCES): Remove assuan-io.c.
* assuan-io.c: Removed.
2002-11-10 Werner Koch <wk@gnupg.org>
* assuan-pipe-connect.c (assuan_pipe_connect): Changed the order
of the dups to handle cases where we have already used fd 2 for
other things.
2002-10-31 Neal H. Walfield <neal@g10code.de>
* assuan-util.c: Include <ctype.h>.
(_assuan_log_print_buffer): Elide the magic numbers preferring the
standard isfoo functions. Use putc_unlocked where possible.
(_assuan_log_sanitized_string): Rewrite to use putc_unlocked and
the isfoo functions.
2002-09-05 Neal H. Walfield <neal@g10code.de>
* assuan-defs.h (_assuan_read_wrapper): Depreciated.
* assuan-util.c (_assuan_read_wrapper): Removed.
* assuan-defs.h (_assuan_write_wrapper): Depreciated.
* assuan-util.c (_assuan_write_wrapper): Removed.
* assuan.h (assuan_set_io_fun): Depreciated.
* assuan-util.c (assuan_set_io_fun): Removed.
* assuan-defs.h (_assuan_read): New function.
(_assuan_write): Likewise.
* assuan-io.c: New file.
* assuan-buffer.c (writen): Use _assuan_write rather than doing
the work here.
(readline): Likewise for _assuan_read.
* Makefile.am (libassuan_a_SOURCES): Add assuan-io.c.
2002-08-16 Werner Koch <wk@gnupg.org>
* assuan.h: Renamed Bad_Certificate_Path to Bad_Certificate_Chain.
2002-07-30 Werner Koch <wk@gnupg.org>
Changed the license from GPL to LGPL.
2002-07-23 Werner Koch <wk@gnupg.org>
* assuan-handler.c (_IO_cookie_io_functions_t): Define it here if
it does not exists.
2002-06-27 Werner Koch <wk@gnupg.org>
* assuan-pipe-connect.c (assuan_pipe_connect): No special handling
for the log_fd and stderr. Connect stderr to /dev/null if it
should not be retained.
2002-06-26 Werner Koch <wk@gnupg.org>
* assuan-buffer.c (assuan_write_line): Make sure we never
accidently print an extra LF.
2002-05-23 Werner Koch <wk@gnupg.org>
* assuan-util.c (assuan_set_io_func): New.
* assuan-buffer.c (writen, readline): Use the new functions
instead of pth.
* assuan-socket-server.c (accept_connection): Don't use the
pth_accept - using the assuan included accept code would be a bad
idea within Pth so we don't need a replacement function.
2002-05-22 Werner Koch <wk@gnupg.org>
* assuan-socket-server.c (assuan_init_connected_socket_server): New.
(accept_connection): Factored most code out to..
(accept_connection_bottom): .. new function.
2002-04-04 Werner Koch <wk@gnupg.org>
* assuan-buffer.c (my_log_prefix): New. Use it for all i/o debug
output.
2002-03-06 Werner Koch <wk@gnupg.org>
* assuan-client.c (_assuan_read_from_server): Detect END.
(assuan_transact): Pass it to the data callback.
2002-02-27 Werner Koch <wk@gnupg.org>
* assuan-client.c (assuan_transact): Add 2 more arguments to
support status lines. Passing NULL yields the old behaviour.
* assuan-handler.c (process_request): Flush data lines send
without using the data fp.
2002-02-14 Werner Koch <wk@gnupg.org>
* assuan-inquire.c (assuan_inquire): Check for a cancel command
and return ASSUAN_Canceled. Allow for non-data inquiry.
* assuan.h: Add a few token specific error codes.
2002-02-13 Werner Koch <wk@gnupg.org>
* assuan-defs.h (assuan_context_s): New var CLIENT_PID.
* assuan-pipe-server.c (_assuan_new_context): set default value.
* assuan-socket-server.c (accept_connection): get the actual pid.
2002-02-12 Werner Koch <wk@gnupg.org>
* assuan-buffer.c (writen,readline) [USE_GNU_PT]: Use pth_read/write.
* assuan-socket-server.c (accept_connection) [USE_GNU_PTH]: Ditto.
2002-02-01 Marcus Brinkmann <marcus@g10code.de>
* Makefile.am (MOSTLYCLEANFILES): New variable.
2002-01-23 Werner Koch <wk@gnupg.org>
* assuan-socket-connect.c (LOGERRORX): and removed typo.
2002-01-22 Marcus Brinkmann <marcus@g10code.de>
* assuan-socket-connect.c (LOGERRORX): Reverse arguments to fputs.
2002-01-21 Werner Koch <wk@gnupg.org>
* assuan-connect.c: Move all except assuan_get_pid to...
* assuan-pipe-connect.c: this.
(assuan_pipe_disconnect): Removed.
(do_finish, do_deinit): New
(assuan_pipe_connect): and set them into the context.
* assuan-socket-connect.c: New.
* assuan-util.c (_assuan_log_sanitized_string): New.
* assuan-pipe-server.c (assuan_init_pipe_server): Factored most
code out to ...
(_assuan_new_context): new func.
(_assuan_release_context): New
* assuan-connect.c (assuan_pipe_connect): Use the new functions.
2002-01-20 Werner Koch <wk@gnupg.org>
* assuan.h: Added Invalid Option error code.
* assuan-handler.c (std_handler_option): New.
(std_cmd_tbl): Add OPTION as standard command.
(assuan_register_option_handler): New.
(dispatch_command): Use case insensitive matching as a fallback.
(my_strcasecmp): New.
2002-01-19 Werner Koch <wk@gnupg.org>
* assuan-buffer.c (_assuan_read_line): Add output logging.
(assuan_write_line): Ditto.
(_assuan_cookie_write_data): Ditto.
(_assuan_cookie_write_flush): Ditto.
* assuan-util.c (_assuan_log_print_buffer): New.
(assuan_set_log_stream): New.
(assuan_begin_confidential): New.
(assuan_end_confidential): New.
* assuan-defs.h: Add a few handler variables.
* assuan-pipe-server.c (assuan_deinit_pipe_server): Removed.
(deinit_pipe_server): New.
(assuan_deinit_server): New. Changed all callers to use this.
* assuan-listen.c (assuan_accept): Use the accept handler.
* assuan-handler.c (process_request): Use the close Handler.
* assuan-socket-server.c: New.
2002-01-14 Werner Koch <wk@gnupg.org>
* assuan-client.c (_assuan_read_from_server): Skip spaces after
the keyword.
2002-01-03 Werner Koch <wk@gnupg.org>
* assuan-handler.c (assuan_set_okay_line): New.
(process_request): And use it here.
2002-01-02 Werner Koch <wk@gnupg.org>
* assuan-inquire.c (init_membuf,put_membuf,get_membuf): Apply a
hidden 0 behind the buffer so that the buffer can be used as a
string in certain contexts.
2001-12-14 Marcus Brinkmann <marcus@g10code.de>
* assuan-connect.c (assuan_pipe_connect): New argument
FD_CHILD_LIST. Don't close those fds.
* assuan.h: Likewise for prototype.
2001-12-14 Werner Koch <wk@gnupg.org>
* assuan-listen.c (assuan_close_input_fd): New.
(assuan_close_output_fd): New.
* assuan-handler.c (std_handler_reset): Always close them after a
reset command.
(std_handler_bye): Likewise.
2001-12-14 Marcus Brinkmann <marcus@g10code.de>
* assuan-buffer.c (_assuan_read_line): New variable ATTICLEN, use
it to save the length of the attic line.
Rediddle the code a bit to make it more clear what happens.
2001-12-14 Marcus Brinkmann <marcus@g10code.de>
* assuan-defs.h (LINELENGTH): Define as ASSUAN_LINELENGTH.
assuan.h: Define ASSUAN_LINELENGTH.
2001-12-13 Marcus Brinkmann <marcus@g10code.de>
* assuan-buffer.c (assuan_read_line): Fix order of execution to
get correct return values.
2001-12-13 Werner Koch <wk@gnupg.org>
* assuan-handler.c (assuan_get_active_fds): Fixed silly bug,
pretty obvious that nobody ever tested this function.
2001-12-12 Werner Koch <wk@gnupg.org>
* assuan-connect.c (assuan_pipe_connect): Implemented the inital
handshake.
* assuan-client.c (read_from_server): Renamed to
(_assuan_read_from_server): this and made external.
* assuan-listen.c (assuan_set_hello_line): New.
(assuan_accept): Use a custom hello line is available.
* assuan-buffer.c (assuan_read_line): New.
(assuan_pending_line): New.
(_assuan_write_line): Renamed to ..
(assuan_write_line): this, made public and changed all callers.
2001-12-04 Werner Koch <wk@gnupg.org>
* assuan-connect.c (assuan_pipe_connect): Add more error reporting.
* assuan-client.c: New.
* assuan-inquire.c: New.
* assuan-handler.c (process_request): Check for nested invocations.
2001-11-27 Werner Koch <wk@gnupg.org>
* assuan-handler.c (assuan_register_input_notify): New.
(assuan_register_output_notify): New.
2001-11-26 Werner Koch <wk@gnupg.org>
* assuan.h: Added more status codes.
2001-11-25 Werner Koch <wk@gnupg.org>
* assuan-handler.c (assuan_register_bye_notify)
(assuan_register_reset_notify)
(assuan_register_cancel_notify): New and call them from the
standard handlers.
(assuan_process): Moved bulk of function to ..
(process_request): .. new.
(assuan_process_next): One shot version of above.
(assuan_get_active_fds): New.
2001-11-24 Werner Koch <wk@gnupg.org>
* assuan-connect.c (assuan_get_pid): New.
* assuan-buffer.c (_assuan_read_line): Deal with reads of more
than a line.
* assuan-defs.h: Add space in the context for this.
Copyright 2001, 2002, 2006, 2007, 2010 Free Software Foundation, Inc.
This file is free software; as a special exception the author gives
unlimited permission to copy and/or distribute it, with or without
modifications, as long as this notice is preserved.
This file is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/src/assuan-buffer.c b/src/assuan-buffer.c
index 45dc08c..3c2e7be 100644
--- a/src/assuan-buffer.c
+++ b/src/assuan-buffer.c
@@ -1,529 +1,531 @@
/* assuan-buffer.c - read and send data
Copyright (C) 2001-2004, 2006, 2009, 2010 Free Software Foundation, Inc.
This file is part of Assuan.
Assuan is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
Assuan 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
-#include <unistd.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
#include <assert.h>
#ifdef HAVE_W32_SYSTEM
-#include <process.h>
+# include <process.h>
#endif
#include "assuan-defs.h"
/* Extended version of write(2) to guarantee that all bytes are
written. Returns 0 on success or -1 and ERRNO on failure. NOTE:
This function does not return the number of bytes written, so any
error must be treated as fatal for this connection as the state of
the receiver is unknown. This works best if blocking is allowed
(so EAGAIN cannot occur). */
static int
writen (assuan_context_t ctx, const char *buffer, size_t length)
{
while (length)
{
ssize_t nwritten = ctx->engine.writefnc (ctx, buffer, length);
if (nwritten < 0)
{
if (errno == EINTR)
continue;
return -1; /* write error */
}
length -= nwritten;
buffer += nwritten;
}
return 0; /* okay */
}
/* Read an entire line. Returns 0 on success or -1 and ERRNO on
failure. EOF is indictated by setting the integer at address
R_EOF. Note: BUF, R_NREAD and R_EOF contain a valid result even if
an error is returned. */
static int
readline (assuan_context_t ctx, char *buf, size_t buflen,
int *r_nread, int *r_eof)
{
size_t nleft = buflen;
char *p;
*r_eof = 0;
*r_nread = 0;
while (nleft > 0)
{
ssize_t n = ctx->engine.readfnc (ctx, buf, nleft);
if (n < 0)
{
if (errno == EINTR)
continue;
return -1; /* read error */
}
else if (!n)
{
*r_eof = 1;
break; /* allow incomplete lines */
}
p = buf;
nleft -= n;
buf += n;
*r_nread += n;
p = memrchr (p, '\n', n);
if (p)
break; /* at least one full line available - that's enough for now */
}
return 0;
}
/* Read a line with buffering of partial lines. Function returns an
Assuan error. */
gpg_error_t
_assuan_read_line (assuan_context_t ctx)
{
gpg_error_t rc = 0;
char *line = ctx->inbound.line;
int nread, atticlen;
char *endp = 0;
if (ctx->inbound.eof)
return _assuan_error (ctx, GPG_ERR_EOF);
atticlen = ctx->inbound.attic.linelen;
if (atticlen)
{
memcpy (line, ctx->inbound.attic.line, atticlen);
ctx->inbound.attic.linelen = 0;
endp = memchr (line, '\n', atticlen);
if (endp)
{
/* Found another line in the attic. */
nread = atticlen;
atticlen = 0;
}
else
{
/* There is pending data but not a full line. */
assert (atticlen < LINELENGTH);
rc = readline (ctx, line + atticlen,
LINELENGTH - atticlen, &nread, &ctx->inbound.eof);
}
}
else
/* No pending data. */
rc = readline (ctx, line, LINELENGTH,
&nread, &ctx->inbound.eof);
if (rc)
{
int saved_errno = errno;
char buf[100];
snprintf (buf, sizeof buf, "error: %s", strerror (errno));
_assuan_log_control_channel (ctx, 0, buf, NULL, 0, NULL, 0);
if (saved_errno == EAGAIN)
{
/* We have to save a partial line. Due to readline's
behaviour, we know that this is not a complete line yet
(no newline). So we don't set PENDING to true. */
memcpy (ctx->inbound.attic.line, line, atticlen + nread);
ctx->inbound.attic.pending = 0;
ctx->inbound.attic.linelen = atticlen + nread;
}
gpg_err_set_errno (saved_errno);
return _assuan_error (ctx, gpg_err_code_from_syserror ());
}
if (!nread)
{
assert (ctx->inbound.eof);
_assuan_log_control_channel (ctx, 0, "eof", NULL, 0, NULL, 0);
return _assuan_error (ctx, GPG_ERR_EOF);
}
ctx->inbound.attic.pending = 0;
nread += atticlen;
if (! endp)
endp = memchr (line, '\n', nread);
if (endp)
{
unsigned monitor_result;
int n = endp - line + 1;
if (n < nread)
/* LINE contains more than one line. We copy it to the attic
now as handlers are allowed to modify the passed
buffer. */
{
int len = nread - n;
memcpy (ctx->inbound.attic.line, endp + 1, len);
ctx->inbound.attic.pending = memrchr (endp + 1, '\n', len) ? 1 : 0;
ctx->inbound.attic.linelen = len;
}
if (endp != line && endp[-1] == '\r')
endp --;
*endp = 0;
ctx->inbound.linelen = endp - line;
monitor_result = 0;
if (ctx->io_monitor)
monitor_result = ctx->io_monitor (ctx, ctx->io_monitor_data, 0,
ctx->inbound.line,
ctx->inbound.linelen);
if (monitor_result & ASSUAN_IO_MONITOR_IGNORE)
ctx->inbound.linelen = 0;
if ( !(monitor_result & ASSUAN_IO_MONITOR_NOLOG))
_assuan_log_control_channel (ctx, 0, NULL,
ctx->inbound.line, ctx->inbound.linelen,
NULL, 0);
return 0;
}
else
{
_assuan_log_control_channel (ctx, 0, "invalid line",
NULL, 0, NULL, 0);
*line = 0;
ctx->inbound.linelen = 0;
return _assuan_error (ctx, ctx->inbound.eof
? GPG_ERR_ASS_INCOMPLETE_LINE
: GPG_ERR_ASS_LINE_TOO_LONG);
}
}
/* Read the next line from the client or server and return a pointer
in *LINE to a buffer holding the line. LINELEN is the length of
*LINE. The buffer is valid until the next read operation on it.
The caller may modify the buffer. The buffer is invalid (i.e. must
not be used) if an error is returned.
Returns 0 on success or an assuan error code.
See also: assuan_pending_line().
*/
gpg_error_t
assuan_read_line (assuan_context_t ctx, char **line, size_t *linelen)
{
gpg_error_t err;
if (!ctx)
return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE);
do
{
err = _assuan_read_line (ctx);
}
while (_assuan_error_is_eagain (ctx, err));
*line = ctx->inbound.line;
*linelen = ctx->inbound.linelen;
return err;
}
/* Return true if a full line is buffered (i.e. an entire line may be
read without any I/O). */
int
assuan_pending_line (assuan_context_t ctx)
{
return ctx && ctx->inbound.attic.pending;
}
gpg_error_t
_assuan_write_line (assuan_context_t ctx, const char *prefix,
const char *line, size_t len)
{
gpg_error_t rc = 0;
size_t prefixlen = prefix? strlen (prefix):0;
unsigned int monitor_result;
/* Make sure that the line is short enough. */
if (len + prefixlen + 2 > ASSUAN_LINELENGTH)
{
_assuan_log_control_channel (ctx, 1,
"supplied line too long - truncated",
NULL, 0, NULL, 0);
if (prefixlen > 5)
prefixlen = 5;
if (len > ASSUAN_LINELENGTH - prefixlen - 2)
len = ASSUAN_LINELENGTH - prefixlen - 2 - 1;
}
monitor_result = 0;
if (ctx->io_monitor)
monitor_result = ctx->io_monitor (ctx, ctx->io_monitor_data, 1, line, len);
/* Fixme: we should do some kind of line buffering. */
if (!(monitor_result & ASSUAN_IO_MONITOR_NOLOG))
_assuan_log_control_channel (ctx, 1, NULL,
prefixlen? prefix:NULL, prefixlen,
line, len);
if (prefixlen && !(monitor_result & ASSUAN_IO_MONITOR_IGNORE))
{
rc = writen (ctx, prefix, prefixlen);
if (rc)
rc = _assuan_error (ctx, gpg_err_code_from_syserror ());
}
if (!rc && !(monitor_result & ASSUAN_IO_MONITOR_IGNORE))
{
rc = writen (ctx, line, len);
if (rc)
rc = _assuan_error (ctx, gpg_err_code_from_syserror ());
if (!rc)
{
rc = writen (ctx, "\n", 1);
if (rc)
rc = _assuan_error (ctx, gpg_err_code_from_syserror ());
}
}
return rc;
}
gpg_error_t
assuan_write_line (assuan_context_t ctx, const char *line)
{
size_t len;
const char *str;
if (! ctx)
return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE);
/* Make sure that we never take a LF from the user - this might
violate the protocol. */
str = strchr (line, '\n');
len = str ? (str - line) : strlen (line);
if (str)
_assuan_log_control_channel (ctx, 1,
"supplied line with LF - truncated",
NULL, 0, NULL, 0);
return _assuan_write_line (ctx, NULL, line, len);
}
/* Write out the data in buffer as datalines with line wrapping and
percent escaping. This function is used for GNU's custom streams. */
int
_assuan_cookie_write_data (void *cookie, const char *buffer, size_t orig_size)
{
assuan_context_t ctx = cookie;
size_t size = orig_size;
char *line;
size_t linelen;
if (ctx->outbound.data.error)
return 0;
line = ctx->outbound.data.line;
linelen = ctx->outbound.data.linelen;
line += linelen;
while (size)
{
unsigned int monitor_result;
/* Insert data line header. */
if (!linelen)
{
*line++ = 'D';
*line++ = ' ';
linelen += 2;
}
/* Copy data, keep space for the CRLF and to escape one character. */
while (size && linelen < LINELENGTH-2-2)
{
if (*buffer == '%' || *buffer == '\r' || *buffer == '\n')
{
sprintf (line, "%%%02X", *(unsigned char*)buffer);
line += 3;
linelen += 3;
buffer++;
}
else
{
*line++ = *buffer++;
linelen++;
}
size--;
}
monitor_result = 0;
if (ctx->io_monitor)
monitor_result = ctx->io_monitor (ctx, ctx->io_monitor_data, 1,
ctx->outbound.data.line, linelen);
if (linelen >= LINELENGTH-2-2)
{
if (!(monitor_result & ASSUAN_IO_MONITOR_NOLOG))
_assuan_log_control_channel (ctx, 1, NULL,
ctx->outbound.data.line, linelen,
NULL, 0);
*line++ = '\n';
linelen++;
if ( !(monitor_result & ASSUAN_IO_MONITOR_IGNORE)
&& writen (ctx, ctx->outbound.data.line, linelen))
{
ctx->outbound.data.error = gpg_err_code_from_syserror ();
return 0;
}
line = ctx->outbound.data.line;
linelen = 0;
}
}
ctx->outbound.data.linelen = linelen;
return (int) orig_size;
}
/* Write out any buffered data
This function is used for GNU's custom streams */
int
_assuan_cookie_write_flush (void *cookie)
{
assuan_context_t ctx = cookie;
char *line;
size_t linelen;
unsigned int monitor_result;
if (ctx->outbound.data.error)
return 0;
line = ctx->outbound.data.line;
linelen = ctx->outbound.data.linelen;
line += linelen;
monitor_result = 0;
if (ctx->io_monitor)
monitor_result = ctx->io_monitor (ctx, ctx->io_monitor_data, 1,
ctx->outbound.data.line, linelen);
if (linelen)
{
if (!(monitor_result & ASSUAN_IO_MONITOR_NOLOG))
_assuan_log_control_channel (ctx, 1, NULL,
ctx->outbound.data.line, linelen,
NULL, 0);
*line++ = '\n';
linelen++;
if (! (monitor_result & ASSUAN_IO_MONITOR_IGNORE)
&& writen (ctx, ctx->outbound.data.line, linelen))
{
ctx->outbound.data.error = gpg_err_code_from_syserror ();
return 0;
}
ctx->outbound.data.linelen = 0;
}
return 0;
}
/**
* assuan_send_data:
* @ctx: An assuan context
* @buffer: Data to send or NULL to flush
* @length: length of the data to send/
*
* This function may be used by the server or the client to send data
* lines. The data will be escaped as required by the Assuan protocol
* and may get buffered until a line is full. To force sending the
* data out @buffer may be passed as NULL (in which case @length must
* also be 0); however when used by a client this flush operation does
* also send the terminating "END" command to terminate the reponse on
* a INQUIRE response. However, when assuan_transact() is used, this
* function takes care of sending END itself.
*
* If BUFFER is NULL and LENGTH is 1 and we are a client, a "CAN" is
* send instead of an "END".
*
* Return value: 0 on success or an error code
**/
gpg_error_t
assuan_send_data (assuan_context_t ctx, const void *buffer, size_t length)
{
if (!ctx)
return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE);
if (!buffer && length > 1)
return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE);
if (!buffer)
{ /* flush what we have */
_assuan_cookie_write_flush (ctx);
if (ctx->outbound.data.error)
return ctx->outbound.data.error;
if (!ctx->is_server)
return assuan_write_line (ctx, length == 1? "CAN":"END");
}
else
{
_assuan_cookie_write_data (ctx, buffer, length);
if (ctx->outbound.data.error)
return ctx->outbound.data.error;
}
return 0;
}
gpg_error_t
assuan_sendfd (assuan_context_t ctx, assuan_fd_t fd)
{
/* It is explicitly allowed to use (NULL, -1) as a runtime test to
check whether descriptor passing is available. */
if (!ctx && fd == ASSUAN_INVALID_FD)
#ifdef USE_DESCRIPTOR_PASSING
return 0;
#else
return _assuan_error (ctx, GPG_ERR_NOT_IMPLEMENTED);
#endif
if (! ctx->engine.sendfd)
return set_error (ctx, GPG_ERR_NOT_IMPLEMENTED,
"server does not support sending and receiving "
"of file descriptors");
return ctx->engine.sendfd (ctx, fd);
}
gpg_error_t
assuan_receivefd (assuan_context_t ctx, assuan_fd_t *fd)
{
if (! ctx->engine.receivefd)
return set_error (ctx, GPG_ERR_NOT_IMPLEMENTED,
"server does not support sending and receiving "
"of file descriptors");
return ctx->engine.receivefd (ctx, fd);
}
diff --git a/src/assuan-defs.h b/src/assuan-defs.h
index 9c1e64e..4a25568 100644
--- a/src/assuan-defs.h
+++ b/src/assuan-defs.h
@@ -1,405 +1,413 @@
/* assuan-defs.h - Internal definitions to Assuan
Copyright (C) 2001, 2002, 2004, 2005, 2007, 2008,
2009, 2010 Free Software Foundation, Inc.
This file is part of Assuan.
Assuan is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
Assuan 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ASSUAN_DEFS_H
#define ASSUAN_DEFS_H
-#include <sys/types.h>
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
#ifndef HAVE_W32_SYSTEM
-#include <sys/socket.h>
-#include <sys/un.h>
+# include <sys/socket.h>
+# include <sys/un.h>
#else
-#include <windows.h>
+# ifdef HAVE_WINSOCK2_H
+# /* Avoid inclusion of winsock.h via windows.h. */
+# include <winsock2.h>
+# endif
+# include <windows.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
#endif
-#include <unistd.h>
#include "assuan.h"
#if __GNUC__ > 2
# define ASSUAN_GCC_A_PURE __attribute__ ((__pure__))
#else
# define ASSUAN_GCC_A_PURE
#endif
#ifndef HAVE_W32_SYSTEM
#define DIRSEP_C '/'
#else
#define DIRSEP_C '\\'
#endif
#define LINELENGTH ASSUAN_LINELENGTH
/* Generate an error code specific to a context. */
#define _assuan_error(ctx, errcode) gpg_err_make ((ctx)->err_source, errcode)
struct cmdtbl_s
{
const char *name;
assuan_handler_t handler;
const char *helpstr;
};
/* The context we use with most functions. */
struct assuan_context_s
{
/* Members managed by the generic routines in assuan.c. */
/* The error source for errors generated from this context. */
gpg_err_source_t err_source;
#ifdef HAVE_W32_SYSTEM
/* The per-context w32 error string. */
char w32_strerror[256];
#endif
/* The allocation hooks. */
struct assuan_malloc_hooks malloc_hooks;
/* Logging callback handler. */
assuan_log_cb_t log_cb;
void *log_cb_data;
void *user_pointer;
/* Context specific flags (cf. assuan_flag_t). */
struct
{
unsigned int no_waitpid : 1;
unsigned int confidential : 1;
unsigned int no_fixsignals : 1;
unsigned int convey_comments : 1;
unsigned int no_logging : 1;
} flags;
/* If set, this is called right before logging an I/O line. */
assuan_io_monitor_t io_monitor;
void *io_monitor_data;
/* Callback handlers replacing system I/O functions. */
struct assuan_system_hooks system;
int peercred_valid; /* Whether this structure has valid information. */
struct _assuan_peercred peercred;
/* Now come the members specific to subsystems or engines. FIXME:
This is not developed yet. See below for the legacy members. */
struct
{
void (*release) (assuan_context_t ctx);
/* Routine to read from input_fd. Sets errno on failure. */
ssize_t (*readfnc) (assuan_context_t, void *, size_t);
/* Routine to write to output_fd. Sets errno on failure. */
ssize_t (*writefnc) (assuan_context_t, const void *, size_t);
/* Send a file descriptor. */
gpg_error_t (*sendfd) (assuan_context_t, assuan_fd_t);
/* Receive a file descriptor. */
gpg_error_t (*receivefd) (assuan_context_t, assuan_fd_t *);
} engine;
/* Engine specific or other subsystem members. */
/* assuan-logging.c. Does not require deallocation from us. */
FILE *log_fp;
/* assuan-util.c */
gpg_error_t err_no;
const char *err_str;
int is_server; /* Set if this is context belongs to a server */
int in_inquire;
int in_process_next;
int process_complete;
int in_command;
/* The following members are used by assuan_inquire_ext. */
gpg_error_t (*inquire_cb) (void *cb_data, gpg_error_t rc,
unsigned char *buf, size_t len);
void *inquire_cb_data;
void *inquire_membuf;
char *hello_line;
char *okay_line; /* See assuan_set_okay_line() */
struct {
assuan_fd_t fd;
int eof;
char line[LINELENGTH];
int linelen; /* w/o CR, LF - might not be the same as
strlen(line) due to embedded nuls. However a nul
is always written at this pos. */
struct {
char line[LINELENGTH];
int linelen ;
int pending; /* i.e. at least one line is available in the attic */
} attic;
} inbound;
struct {
assuan_fd_t fd;
struct {
FILE *fp;
char line[LINELENGTH];
int linelen;
int error;
} data;
} outbound;
int max_accepts; /* If we can not handle more than one connection,
set this to 1, otherwise to -1. */
pid_t pid; /* The pid of the peer. */
assuan_fd_t listen_fd; /* The fd we are listening on (used by
socket servers) */
assuan_sock_nonce_t listen_nonce; /* Used with LISTEN_FD. */
assuan_fd_t connected_fd; /* helper */
/* Used for Unix domain sockets. */
struct sockaddr_un myaddr;
struct sockaddr_un serveraddr;
/* Structure used for unix domain sockets. */
struct {
assuan_fd_t pendingfds[5]; /* Array to save received descriptors. */
int pendingfdscount; /* Number of received descriptors. */
} uds;
gpg_error_t (*accept_handler)(assuan_context_t);
void (*finish_handler)(assuan_context_t);
struct cmdtbl_s *cmdtbl;
size_t cmdtbl_used; /* used entries */
size_t cmdtbl_size; /* allocated size of table */
/* The name of the command currently processed by a command handler.
This is a pointer into CMDTBL. NULL if not in a command
handler. */
const char *current_cmd_name;
assuan_handler_t bye_notify_fnc;
assuan_handler_t reset_notify_fnc;
assuan_handler_t cancel_notify_fnc;
gpg_error_t (*option_handler_fnc)(assuan_context_t,const char*, const char*);
assuan_handler_t input_notify_fnc;
assuan_handler_t output_notify_fnc;
/* This function is called right after a command has been processed.
It may be used to command related cleanup. */
void (*post_cmd_notify_fnc)(assuan_context_t, gpg_error_t);
assuan_fd_t input_fd; /* Set by the INPUT command. */
assuan_fd_t output_fd; /* Set by the OUTPUT command. */
};
/* Release all resources associated with an engine operation. */
void _assuan_reset (assuan_context_t ctx);
/* Default log handler. */
int _assuan_log_handler (assuan_context_t ctx, void *hook,
unsigned int cat, const char *msg);
/* Manage memory specific to a context. */
void *_assuan_malloc (assuan_context_t ctx, size_t cnt);
void *_assuan_realloc (assuan_context_t ctx, void *ptr, size_t cnt);
void *_assuan_calloc (assuan_context_t ctx, size_t cnt, size_t elsize);
void _assuan_free (assuan_context_t ctx, void *ptr);
/* System hooks. */
void _assuan_usleep (assuan_context_t ctx, unsigned int usec);
int _assuan_pipe (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx);
int _assuan_close (assuan_context_t ctx, assuan_fd_t fd);
int _assuan_close_inheritable (assuan_context_t ctx, assuan_fd_t fd);
ssize_t _assuan_read (assuan_context_t ctx, assuan_fd_t fd, void *buffer,
size_t size);
ssize_t _assuan_write (assuan_context_t ctx, assuan_fd_t fd, const void *buffer,
size_t size);
int _assuan_recvmsg (assuan_context_t ctx, assuan_fd_t fd,
assuan_msghdr_t msg, int flags);
int _assuan_sendmsg (assuan_context_t ctx, assuan_fd_t fd,
assuan_msghdr_t msg, int flags);
int _assuan_spawn (assuan_context_t ctx, pid_t *r_pid, const char *name,
const char *argv[],
assuan_fd_t fd_in, assuan_fd_t fd_out,
assuan_fd_t *fd_child_list,
void (*atfork) (void *opaque, int reserved),
void *atforkvalue, unsigned int flags);
pid_t _assuan_waitpid (assuan_context_t ctx, pid_t pid, int nowait,
int *status, int options);
int _assuan_socketpair (assuan_context_t ctx, int namespace, int style,
int protocol, assuan_fd_t filedes[2]);
extern struct assuan_system_hooks _assuan_system_hooks;
/* Copy the system hooks struct, paying attention to version
differences. SRC is usually from the user, DST MUST be from the
library. */
void
_assuan_system_hooks_copy (assuan_system_hooks_t dst,
assuan_system_hooks_t src);
/*-- assuan-pipe-server.c --*/
void _assuan_release_context (assuan_context_t ctx);
/*-- assuan-uds.c --*/
void _assuan_uds_close_fds (assuan_context_t ctx);
void _assuan_uds_deinit (assuan_context_t ctx);
void _assuan_init_uds_io (assuan_context_t ctx);
/*-- assuan-handler.c --*/
gpg_error_t _assuan_register_std_commands (assuan_context_t ctx);
/*-- assuan-buffer.c --*/
gpg_error_t _assuan_read_line (assuan_context_t ctx);
int _assuan_cookie_write_data (void *cookie, const char *buffer, size_t size);
int _assuan_cookie_write_flush (void *cookie);
gpg_error_t _assuan_write_line (assuan_context_t ctx, const char *prefix,
const char *line, size_t len);
/*-- client.c --*/
gpg_error_t _assuan_read_from_server (assuan_context_t ctx,
assuan_response_t *okay, int *off,
int convey_comments);
/*-- assuan-error.c --*/
/*-- assuan-inquire.c --*/
gpg_error_t _assuan_inquire_ext_cb (assuan_context_t ctx);
void _assuan_inquire_release (assuan_context_t ctx);
/* Check if ERR means EAGAIN. */
int _assuan_error_is_eagain (assuan_context_t ctx, gpg_error_t err);
#define set_error(c,e,t) \
assuan_set_error ((c), _assuan_error (c,e), (t))
#ifdef HAVE_W32_SYSTEM
char *_assuan_w32_strerror (assuan_context_t ctx, int ec);
#endif /*HAVE_W32_SYSTEM*/
/*-- assuan-logging.c --*/
void _assuan_init_log_envvars (void);
void _assuan_log_control_channel (assuan_context_t ctx, int outbound,
const char *string,
const void *buffer1, size_t length1,
const void *buffer2, size_t length2);
/*-- assuan-io.c --*/
ssize_t _assuan_simple_read (assuan_context_t ctx, void *buffer, size_t size);
ssize_t _assuan_simple_write (assuan_context_t ctx, const void *buffer,
size_t size);
/*-- assuan-socket.c --*/
assuan_fd_t _assuan_sock_new (assuan_context_t ctx, int domain, int type,
int proto);
int _assuan_sock_connect (assuan_context_t ctx, assuan_fd_t sockfd,
struct sockaddr *addr, int addrlen);
int _assuan_sock_bind (assuan_context_t ctx, assuan_fd_t sockfd,
struct sockaddr *addr, int addrlen);
int _assuan_sock_get_nonce (assuan_context_t ctx, struct sockaddr *addr,
int addrlen, assuan_sock_nonce_t *nonce);
int _assuan_sock_check_nonce (assuan_context_t ctx, assuan_fd_t fd,
assuan_sock_nonce_t *nonce);
#ifdef HAVE_W32_SYSTEM
int _assuan_sock_wsa2errno (int err);
#endif
#ifdef HAVE_FOPENCOOKIE
/* We have to implement funopen in terms of glibc's fopencookie. */
FILE *_assuan_funopen(void *cookie,
cookie_read_function_t *readfn,
cookie_write_function_t *writefn,
cookie_seek_function_t *seekfn,
cookie_close_function_t *closefn);
#define funopen(a,r,w,s,c) _assuan_funopen ((a), (r), (w), (s), (c))
#endif /*HAVE_FOPENCOOKIE*/
/*-- sysutils.c --*/
const char *_assuan_sysutils_blurb (void);
#ifdef HAVE_W32CE_SYSTEM
#define getpid() GetCurrentProcessId ()
char *_assuan_getenv (const char *name);
#define getenv(a) _assuan_getenv ((a))
#endif /*HAVE_W32CE_SYSTEM*/
/* Prototypes for replacement functions. */
#ifndef HAVE_MEMRCHR
void *memrchr (const void *block, int c, size_t size);
#endif
#ifndef HAVE_STPCPY
char *stpcpy (char *dest, const char *src);
#endif
#ifndef HAVE_SETENV
#define setenv _assuan_setenv
#define unsetenv _assuan_unsetenv
#define clearenv _assuan_clearenv
int setenv (const char *name, const char *value, int replace);
#endif
#ifndef HAVE_PUTC_UNLOCKED
int putc_unlocked (int c, FILE *stream);
#endif
#ifndef HAVE_VASPRINTF
int _assuan_vasprintf (char **result, const char *format, va_list args);
int _assuan_asprintf (char **buf, const char *fmt, ...);
#define vasprintf _assuan_vasprintf
#define asprintf _assuan_asprintf
#endif
#define DIM(v) (sizeof(v)/sizeof((v)[0]))
#if HAVE_W32_SYSTEM
#define SOCKET2HANDLE(s) ((void *)(s))
#define HANDLE2SOCKET(h) ((unsigned int)(h))
#else
#define SOCKET2HANDLE(s) (s)
#define HANDLE2SOCKET(h) (h)
#endif
void _assuan_client_finish (assuan_context_t ctx);
void _assuan_client_release (assuan_context_t ctx);
void _assuan_server_finish (assuan_context_t ctx);
void _assuan_server_release (assuan_context_t ctx);
/* Encode the C formatted string SRC and return the malloc'ed result. */
char *_assuan_encode_c_string (assuan_context_t ctx, const char *src);
#endif /*ASSUAN_DEFS_H*/
diff --git a/src/assuan-io.c b/src/assuan-io.c
index c5bbc99..8bb8ed9 100644
--- a/src/assuan-io.c
+++ b/src/assuan-io.c
@@ -1,52 +1,61 @@
/* assuan-io.c - Wraps the read and write functions.
Copyright (C) 2002, 2004, 2006-2009 Free Software Foundation, Inc.
This file is part of Assuan.
Assuan is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
Assuan 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <time.h>
-#include <sys/time.h>
-#include <sys/types.h>
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
-#include <unistd.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
#include <errno.h>
#ifdef HAVE_W32_SYSTEM
+# ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+# endif
# include <windows.h>
#else
# include <sys/wait.h>
#endif
#include "assuan-defs.h"
ssize_t
_assuan_simple_read (assuan_context_t ctx, void *buffer, size_t size)
{
return _assuan_read (ctx, ctx->inbound.fd, buffer, size);
}
ssize_t
_assuan_simple_write (assuan_context_t ctx, const void *buffer, size_t size)
{
return _assuan_write (ctx, ctx->outbound.fd, buffer, size);
}
diff --git a/src/assuan-listen.c b/src/assuan-listen.c
index 55ddd0a..2c589ab 100644
--- a/src/assuan-listen.c
+++ b/src/assuan-listen.c
@@ -1,173 +1,175 @@
/* assuan-listen.c - Wait for a connection (server)
Copyright (C) 2001, 2002, 2004, 2009 Free Software Foundation, Inc.
This file is part of Assuan.
Assuan is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
Assuan 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <unistd.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
#include <errno.h>
#include "assuan-defs.h"
gpg_error_t
assuan_set_hello_line (assuan_context_t ctx, const char *line)
{
if (!ctx)
return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE);
if (!line)
{
_assuan_free (ctx, ctx->hello_line);
ctx->hello_line = NULL;
}
else
{
char *buf = _assuan_malloc (ctx, 3 + strlen (line) + 1);
if (!buf)
return _assuan_error (ctx, gpg_err_code_from_syserror ());
if (strchr (line, '\n'))
strcpy (buf, line);
else
{
strcpy (buf, "OK ");
strcpy (buf+3, line);
}
_assuan_free (ctx, ctx->hello_line);
ctx->hello_line = buf;
}
return 0;
}
/**
* assuan_accept:
* @ctx: context
*
* Cancel any existing connection and wait for a connection from a
* client. The initial handshake is performed which may include an
* initial authentication or encryption negotiation.
*
* Return value: 0 on success or an error if the connection could for
* some reason not be established.
**/
gpg_error_t
assuan_accept (assuan_context_t ctx)
{
gpg_error_t rc = 0;
const char *p, *pend;
if (!ctx)
return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE);
if (ctx->max_accepts != -1)
{
if (ctx->max_accepts-- == 0)
return -1; /* second invocation for pipemode -> terminate */
}
if (ctx->accept_handler)
{
/* FIXME: This should be superfluous, if everything else is
correct. */
ctx->finish_handler (ctx);
rc = ctx->accept_handler (ctx);
if (rc)
return rc;
}
/* Send the hello. */
p = ctx->hello_line;
if (p && (pend = strchr (p, '\n')))
{ /* This is a multi line hello. Send all but the last line as
comments. */
do
{
rc = _assuan_write_line (ctx, "# ", p, pend - p);
if (rc)
return rc;
p = pend + 1;
pend = strchr (p, '\n');
}
while (pend);
rc = _assuan_write_line (ctx, "OK ", p, strlen (p));
}
else if (p)
rc = assuan_write_line (ctx, p);
else
{
static char const okstr[] = "OK Pleased to meet you";
pid_t apid = assuan_get_pid (ctx);
if (apid != ASSUAN_INVALID_PID)
{
char tmpbuf[50];
snprintf (tmpbuf, sizeof tmpbuf, "%s, process %i", okstr, (int)apid);
rc = assuan_write_line (ctx, tmpbuf);
}
else
rc = assuan_write_line (ctx, okstr);
}
if (rc)
return rc;
return 0;
}
assuan_fd_t
assuan_get_input_fd (assuan_context_t ctx)
{
return ctx ? ctx->input_fd : ASSUAN_INVALID_FD;
}
assuan_fd_t
assuan_get_output_fd (assuan_context_t ctx)
{
return ctx ? ctx->output_fd : ASSUAN_INVALID_FD;
}
/* Close the fd descriptor set by the command INPUT FD=n. We handle
this fd inside assuan so that we can do some initial checks */
gpg_error_t
assuan_close_input_fd (assuan_context_t ctx)
{
if (!ctx || ctx->input_fd == ASSUAN_INVALID_FD)
return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE);
_assuan_close (ctx, ctx->input_fd);
ctx->input_fd = ASSUAN_INVALID_FD;
return 0;
}
/* Close the fd descriptor set by the command OUTPUT FD=n. We handle
this fd inside assuan so that we can do some initial checks */
gpg_error_t
assuan_close_output_fd (assuan_context_t ctx)
{
if (!ctx || ctx->output_fd == ASSUAN_INVALID_FD)
return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE);
_assuan_close (ctx, ctx->output_fd);
ctx->output_fd = ASSUAN_INVALID_FD;
return 0;
}
diff --git a/src/assuan-logging.c b/src/assuan-logging.c
index dc2427e..d74e5d2 100644
--- a/src/assuan-logging.c
+++ b/src/assuan-logging.c
@@ -1,301 +1,304 @@
/* assuan-logging.c - Default logging function.
Copyright (C) 2002, 2003, 2004, 2007, 2009,
2010 Free Software Foundation, Inc.
This file is part of Assuan.
Assuan is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
Assuan 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#ifdef HAVE_W32_SYSTEM
-#include <windows.h>
+# ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+# endif
+# include <windows.h>
#endif /*HAVE_W32_SYSTEM*/
#include <errno.h>
#include <ctype.h>
#include "assuan-defs.h"
/* The default log handler is useful for global logging, but it should
only be used by one user of libassuan at a time. Libraries that
use libassuan can register their own log handler. */
/* A common prefix for all log messages. */
static char prefix_buffer[80];
/* A global flag read from the environment to check if to enable full
logging of buffer data. This is also used by custom log
handlers. */
static int full_logging;
/* A bitfield that specifies the categories to log. */
static int log_cats;
#define TEST_LOG_CAT(x) (!! (log_cats & (1 << (x - 1))))
static FILE *_assuan_log;
void
_assuan_init_log_envvars (void)
{
char *flagstr;
full_logging = !!getenv ("ASSUAN_FULL_LOGGING");
flagstr = getenv ("ASSUAN_DEBUG");
if (flagstr)
log_cats = atoi (flagstr);
else /* Default to log the control channel. */
log_cats = (1 << (ASSUAN_LOG_CONTROL - 1));
_assuan_sysutils_blurb (); /* Make sure this code gets linked in. */
}
void
assuan_set_assuan_log_stream (FILE *fp)
{
_assuan_log = fp;
_assuan_init_log_envvars ();
}
/* Set the per context log stream. Also enable the default log stream
if it has not been set. */
void
assuan_set_log_stream (assuan_context_t ctx, FILE *fp)
{
if (ctx)
{
if (ctx->log_fp)
fflush (ctx->log_fp);
ctx->log_fp = fp;
if (! _assuan_log)
assuan_set_assuan_log_stream (fp);
}
}
/* Set the prefix to be used for logging to TEXT or resets it to the
default if TEXT is NULL. */
void
assuan_set_assuan_log_prefix (const char *text)
{
if (text)
{
strncpy (prefix_buffer, text, sizeof (prefix_buffer)-1);
prefix_buffer[sizeof (prefix_buffer)-1] = 0;
}
else
*prefix_buffer = 0;
}
/* Get the prefix to be used for logging. */
const char *
assuan_get_assuan_log_prefix (void)
{
return prefix_buffer;
}
/* Default log handler. */
int
_assuan_log_handler (assuan_context_t ctx, void *hook, unsigned int cat,
const char *msg)
{
FILE *fp;
const char *prf;
int saved_errno = errno;
/* For now. */
if (msg == NULL)
return TEST_LOG_CAT (cat);
if (! TEST_LOG_CAT (cat))
return 0;
fp = ctx->log_fp ? ctx->log_fp : _assuan_log;
if (!fp)
return 0;
prf = assuan_get_assuan_log_prefix ();
if (*prf)
fprintf (fp, "%s[%u]: ", prf, (unsigned int)getpid ());
fprintf (fp, "%s", msg);
/* If the log stream is a file, the output would be buffered. This
is bad for debugging, thus we flush the stream if FORMAT ends
with a LF. */
if (msg && *msg && msg[strlen (msg) - 1] == '\n')
fflush (fp);
gpg_err_set_errno (saved_errno);
return 0;
}
/* Log a control channel message. This is either a STRING with a
diagnostic or actual data in (BUFFER1,LENGTH1) and
(BUFFER2,LENGTH2). If OUTBOUND is true the data is intended for
the peer. */
void
_assuan_log_control_channel (assuan_context_t ctx, int outbound,
const char *string,
const void *buffer1, size_t length1,
const void *buffer2, size_t length2)
{
int res;
char *outbuf;
int saved_errno;
/* Check whether logging is enabled and do a quick check to see
whether the callback supports our category. */
if (!ctx
|| !ctx->log_cb
|| ctx->flags.no_logging
|| !(*ctx->log_cb) (ctx, ctx->log_cb_data, ASSUAN_LOG_CONTROL, NULL))
return;
saved_errno = errno;
/* Note that we use the inbound channel fd as the printed channel
number for both directions. */
#ifdef HAVE_W32_SYSTEM
# define CHANNEL_FMT "%p"
#else
# define CHANNEL_FMT "%d"
#endif
#define TOHEX(val) (((val) < 10) ? ((val) + '0') : ((val) - 10 + 'a'))
if (!buffer1 && buffer2)
{
buffer1 = buffer2;
length1 = length2;
buffer2 = NULL;
length2 = 0;
}
if (ctx->flags.confidential && !string && buffer1)
string = "[Confidential data not shown]";
if (string)
{
/* Print the diagnostic. */
res = asprintf (&outbuf, "chan_" CHANNEL_FMT " %s [%s]\n",
ctx->inbound.fd, outbound? "->":"<-", string);
}
else if (buffer1)
{
/* Print the control channel data. */
const unsigned char *s;
unsigned int n, x;
for (n = length1, s = buffer1; n; n--, s++)
if ((!isascii (*s) || iscntrl (*s) || !isprint (*s) || !*s)
&& !(*s >= 0x80))
break;
if (!n && buffer2)
{
for (n = length2, s = buffer2; n; n--, s++)
if ((!isascii (*s) || iscntrl (*s) || !isprint (*s) || !*s)
&& !(*s >= 0x80))
break;
}
if (!buffer2)
length2 = 0;
if (!n && (length1 && *(const char*)buffer1 != '['))
{
/* No control characters and not starting with our error
message indicator. Log it verbatim. */
res = asprintf (&outbuf, "chan_" CHANNEL_FMT " %s %.*s%.*s\n",
ctx->inbound.fd, outbound? "->":"<-",
(int)length1, (const char*)buffer1,
(int)length2, buffer2? (const char*)buffer2:"");
}
else
{
/* The buffer contains control characters - do a hex dump.
Even in full logging mode we limit the line length -
however this is no real limit because the provided
buffers will never be larger than the maximum assuan line
length. */
char *hp;
unsigned int nbytes;
unsigned int maxbytes = full_logging? (2*LINELENGTH) : 16;
nbytes = length1 + length2;
if (nbytes > maxbytes)
nbytes = maxbytes;
if (!(outbuf = malloc (50 + 3*nbytes + 60 + 3 + 1)))
res = -1;
else
{
res = 0;
hp = outbuf;
snprintf (hp, 50, "chan_" CHANNEL_FMT " %s [",
ctx->inbound.fd, outbound? "->":"<-");
hp += strlen (hp);
n = 0;
for (s = buffer1, x = 0; x < length1 && n < nbytes; x++, n++)
{
*hp++ = ' ';
*hp++ = TOHEX (*s >> 4);
*hp++ = TOHEX (*s & 0x0f);
s++;
}
for (s = buffer2, x = 0; x < length2 && n < nbytes; x++, n++)
{
*hp++ = ' ';
*hp++ = TOHEX (*s >> 4);
*hp++ = TOHEX (*s & 0x0f);
s++;
}
if (nbytes < length1 + length2)
{
snprintf (hp, 60, " ...(%u byte(s) skipped)",
(unsigned int)((length1+length2) - nbytes));
hp += strlen (hp);
}
strcpy (hp, " ]\n");
}
}
}
else
{
res = 0;
outbuf = NULL;
}
if (res < 0)
ctx->log_cb (ctx, ctx->log_cb_data, ASSUAN_LOG_CONTROL,
"[libassuan failed to format the log message]");
else if (outbuf)
{
ctx->log_cb (ctx, ctx->log_cb_data, ASSUAN_LOG_CONTROL, outbuf);
free (outbuf);
}
#undef TOHEX
#undef CHANNEL_FMT
gpg_err_set_errno (saved_errno);
}
diff --git a/src/assuan-pipe-connect.c b/src/assuan-pipe-connect.c
index bdcedc1..ed23cb2 100644
--- a/src/assuan-pipe-connect.c
+++ b/src/assuan-pipe-connect.c
@@ -1,420 +1,427 @@
/* assuan-pipe-connect.c - Establish a pipe connection (client)
Copyright (C) 2001-2003, 2005-2007, 2009 Free Software Foundation, Inc.
This file is part of Assuan.
Assuan is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
Assuan 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/* On Windows systems signal.h is not needed and even not supported on
WindowsCE. */
#ifndef HAVE_DOSISH_SYSTEM
# include <signal.h>
#endif
-#include <unistd.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
#include <errno.h>
#include <fcntl.h>
-#include <sys/types.h>
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
#ifndef HAVE_W32_SYSTEM
-#include <sys/wait.h>
+# include <sys/wait.h>
#else
-#include <windows.h>
+# ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+# endif
+# include <windows.h>
#endif
#include "assuan-defs.h"
#include "debug.h"
/* Hacks for Slowaris. */
#ifndef PF_LOCAL
# ifdef PF_UNIX
# define PF_LOCAL PF_UNIX
# else
# define PF_LOCAL AF_UNIX
# endif
#endif
#ifndef AF_LOCAL
# define AF_LOCAL AF_UNIX
#endif
#ifdef _POSIX_OPEN_MAX
#define MAX_OPEN_FDS _POSIX_OPEN_MAX
#else
#define MAX_OPEN_FDS 20
#endif
/* This should be called to make sure that SIGPIPE gets ignored. */
static void
fix_signals (void)
{
#ifndef HAVE_DOSISH_SYSTEM /* No SIGPIPE for these systems. */
static int fixed_signals;
if (!fixed_signals)
{
struct sigaction act;
sigaction (SIGPIPE, NULL, &act);
if (act.sa_handler == SIG_DFL)
{
act.sa_handler = SIG_IGN;
sigemptyset (&act.sa_mask);
act.sa_flags = 0;
sigaction (SIGPIPE, &act, NULL);
}
fixed_signals = 1;
/* FIXME: This is not MT safe */
}
#endif /*HAVE_DOSISH_SYSTEM*/
}
/* Helper for pipe_connect. */
static gpg_error_t
initial_handshake (assuan_context_t ctx)
{
assuan_response_t response;
int off;
gpg_error_t err;
err = _assuan_read_from_server (ctx, &response, &off, 0);
if (err)
TRACE1 (ctx, ASSUAN_LOG_SYSIO, "initial_handshake", ctx,
"can't connect server: %s", gpg_strerror (err));
else if (response != ASSUAN_RESPONSE_OK)
{
TRACE1 (ctx, ASSUAN_LOG_SYSIO, "initial_handshake", ctx,
"can't connect server: `%s'", ctx->inbound.line);
err = _assuan_error (ctx, GPG_ERR_ASS_CONNECT_FAILED);
}
return err;
}
struct at_pipe_fork
{
void (*user_atfork) (void *opaque, int reserved);
void *user_atforkvalue;
};
static void
at_pipe_fork_cb (void *opaque, int reserved)
{
struct at_pipe_fork *atp = opaque;
if (atp->user_atfork)
atp->user_atfork (atp->user_atforkvalue, reserved);
#ifndef HAVE_W32_SYSTEM
{
char mypidstr[50];
/* We store our parents pid in the environment so that the execed
assuan server is able to read the actual pid of the client.
The server can't use getppid because it might have been double
forked before the assuan server has been initialized. */
sprintf (mypidstr, "%lu", (unsigned long) getpid ());
setenv ("_assuan_pipe_connect_pid", mypidstr, 1);
/* Make sure that we never pass a connection fd variable when
using a simple pipe. */
unsetenv ("_assuan_connection_fd");
}
#endif
}
static gpg_error_t
pipe_connect (assuan_context_t ctx,
const char *name, const char **argv,
assuan_fd_t *fd_child_list,
void (*atfork) (void *opaque, int reserved),
void *atforkvalue, unsigned int flags)
{
gpg_error_t rc;
assuan_fd_t rp[2];
assuan_fd_t wp[2];
pid_t pid;
int res;
struct at_pipe_fork atp;
unsigned int spawn_flags;
atp.user_atfork = atfork;
atp.user_atforkvalue = atforkvalue;
if (!ctx || !name || !argv || !argv[0])
return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE);
if (! ctx->flags.no_fixsignals)
fix_signals ();
if (_assuan_pipe (ctx, rp, 1) < 0)
return _assuan_error (ctx, gpg_err_code_from_syserror ());
if (_assuan_pipe (ctx, wp, 0) < 0)
{
_assuan_close (ctx, rp[0]);
_assuan_close_inheritable (ctx, rp[1]);
return _assuan_error (ctx, gpg_err_code_from_syserror ());
}
spawn_flags = 0;
if (flags & ASSUAN_PIPE_CONNECT_DETACHED)
spawn_flags |= ASSUAN_SPAWN_DETACHED;
/* FIXME: Use atfork handler that closes child fds on Unix. */
res = _assuan_spawn (ctx, &pid, name, argv, wp[0], rp[1],
fd_child_list, at_pipe_fork_cb, &atp, spawn_flags);
if (res < 0)
{
rc = gpg_err_code_from_syserror ();
_assuan_close (ctx, rp[0]);
_assuan_close_inheritable (ctx, rp[1]);
_assuan_close_inheritable (ctx, wp[0]);
_assuan_close (ctx, wp[1]);
return _assuan_error (ctx, rc);
}
/* Close the stdin/stdout child fds in the parent. */
_assuan_close_inheritable (ctx, rp[1]);
_assuan_close_inheritable (ctx, wp[0]);
ctx->engine.release = _assuan_client_release;
ctx->engine.readfnc = _assuan_simple_read;
ctx->engine.writefnc = _assuan_simple_write;
ctx->engine.sendfd = NULL;
ctx->engine.receivefd = NULL;
ctx->finish_handler = _assuan_client_finish;
ctx->max_accepts = 1;
ctx->accept_handler = NULL;
ctx->inbound.fd = rp[0]; /* Our inbound is read end of read pipe. */
ctx->outbound.fd = wp[1]; /* Our outbound is write end of write pipe. */
ctx->pid = pid;
rc = initial_handshake (ctx);
if (rc)
_assuan_reset (ctx);
return rc;
}
/* FIXME: For socketpair_connect, use spawn function and add atfork
handler to do the right thing. Instead of stdin and stdout, we
extend the fd_child_list by fds[1]. */
#ifndef HAVE_W32_SYSTEM
struct at_socketpair_fork
{
assuan_fd_t peer_fd;
void (*user_atfork) (void *opaque, int reserved);
void *user_atforkvalue;
};
static void
at_socketpair_fork_cb (void *opaque, int reserved)
{
struct at_socketpair_fork *atp = opaque;
if (atp->user_atfork)
atp->user_atfork (atp->user_atforkvalue, reserved);
#ifndef HAVE_W32_SYSTEM
{
char mypidstr[50];
/* We store our parents pid in the environment so that the execed
assuan server is able to read the actual pid of the client.
The server can't use getppid because it might have been double
forked before the assuan server has been initialized. */
sprintf (mypidstr, "%lu", (unsigned long) getpid ());
setenv ("_assuan_pipe_connect_pid", mypidstr, 1);
/* Now set the environment variable used to convey the
connection's file descriptor. */
sprintf (mypidstr, "%d", atp->peer_fd);
if (setenv ("_assuan_connection_fd", mypidstr, 1))
_exit (4);
}
#endif
}
/* This function is similar to pipe_connect but uses a socketpair and
sets the I/O up to use sendmsg/recvmsg. */
static gpg_error_t
socketpair_connect (assuan_context_t ctx,
const char *name, const char **argv,
assuan_fd_t *fd_child_list,
void (*atfork) (void *opaque, int reserved),
void *atforkvalue)
{
gpg_error_t err;
int idx;
int fds[2];
char mypidstr[50];
pid_t pid;
int *child_fds = NULL;
int child_fds_cnt = 0;
struct at_socketpair_fork atp;
int rc;
TRACE_BEG3 (ctx, ASSUAN_LOG_CTX, "socketpair_connect", ctx,
"name=%s,atfork=%p,atforkvalue=%p", name ? name : "(null)",
atfork, atforkvalue);
atp.user_atfork = atfork;
atp.user_atforkvalue = atforkvalue;
if (!ctx
|| (name && (!argv || !argv[0]))
|| (!name && !argv))
return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE);
if (! ctx->flags.no_fixsignals)
fix_signals ();
sprintf (mypidstr, "%lu", (unsigned long)getpid ());
if (fd_child_list)
while (fd_child_list[child_fds_cnt] != ASSUAN_INVALID_FD)
child_fds_cnt++;
child_fds = _assuan_malloc (ctx, (child_fds_cnt + 2) * sizeof (int));
if (! child_fds)
return TRACE_ERR (gpg_err_code_from_syserror ());
child_fds[1] = ASSUAN_INVALID_FD;
if (fd_child_list)
memcpy (&child_fds[1], fd_child_list, (child_fds_cnt + 1) * sizeof (int));
if (_assuan_socketpair (ctx, AF_LOCAL, SOCK_STREAM, 0, fds))
{
TRACE_LOG1 ("socketpair failed: %s", strerror (errno));
_assuan_free (ctx, child_fds);
return TRACE_ERR (GPG_ERR_ASS_GENERAL);
}
atp.peer_fd = fds[1];
child_fds[0] = fds[1];
rc = _assuan_spawn (ctx, &pid, name, argv, ASSUAN_INVALID_FD,
ASSUAN_INVALID_FD, child_fds, at_socketpair_fork_cb,
&atp, 0);
if (rc < 0)
{
err = gpg_err_code_from_syserror ();
_assuan_close (ctx, fds[0]);
_assuan_close (ctx, fds[1]);
_assuan_free (ctx, child_fds);
return TRACE_ERR (err);
}
/* For W32, the user needs to know the server-local names of the
inherited handles. Return them here. Note that the translation
of the peer socketpair fd (fd_child_list[0]) must be done by the
wrapper program based on the environment variable
_assuan_connection_fd. */
if (fd_child_list)
{
for (idx = 0; fd_child_list[idx] != -1; idx++)
/* We add 1 to skip over the socketpair end. */
fd_child_list[idx] = child_fds[idx + 1];
}
/* If this is the server child process, exit early. */
if (! name && (*argv)[0] == 's')
{
_assuan_free (ctx, child_fds);
_assuan_close (ctx, fds[0]);
return 0;
}
_assuan_close (ctx, fds[1]);
ctx->engine.release = _assuan_client_release;
ctx->finish_handler = _assuan_client_finish;
ctx->max_accepts = 1;
ctx->inbound.fd = fds[0];
ctx->outbound.fd = fds[0];
_assuan_init_uds_io (ctx);
err = initial_handshake (ctx);
if (err)
_assuan_reset (ctx);
return err;
}
#endif /*!HAVE_W32_SYSTEM*/
/* Connect to a server over a full-duplex socket (i.e. created by
socketpair), creating the assuan context and returning it in CTX.
The server filename is NAME, the argument vector in ARGV.
FD_CHILD_LIST is a -1 terminated list of file descriptors not to
close in the child. ATFORK is called in the child right after the
fork; ATFORKVALUE is passed as the first argument and 0 is passed
as the second argument. The ATFORK function should only act if the
second value is 0.
FLAGS is a bit vector and controls how the function acts:
Bit 0: If cleared a simple pipe based server is expected and the
function behaves similar to `assuan_pipe_connect'.
If set a server based on full-duplex pipes is expected. Such
pipes are usually created using the `socketpair' function.
It also enables features only available with such servers.
Bit 7: If set and there is a need to start the server it will be
started as a background process. This flag is useful under
W32 systems, so that no new console is created and pops up a
console window when starting the server
If NAME is NULL, no exec is done but the same process is continued.
However all file descriptors are closed and some special
environment variables are set. To let the caller detect whether the
child or the parent continues, the child returns "client" or
"server" in *ARGV (but it is sufficient to check only the first
character). This feature is only available on POSIX platforms. */
gpg_error_t
assuan_pipe_connect (assuan_context_t ctx,
const char *name, const char *argv[],
assuan_fd_t *fd_child_list,
void (*atfork) (void *opaque, int reserved),
void *atforkvalue, unsigned int flags)
{
TRACE2 (ctx, ASSUAN_LOG_CTX, "assuan_pipe_connect", ctx,
"name=%s, flags=0x%x", name ? name : "(null)", flags);
if (flags & ASSUAN_PIPE_CONNECT_FDPASSING)
{
#ifdef HAVE_W32_SYSTEM
return _assuan_error (ctx, GPG_ERR_NOT_IMPLEMENTED);
#else
return socketpair_connect (ctx, name, argv, fd_child_list,
atfork, atforkvalue);
#endif
}
else
return pipe_connect (ctx, name, argv, fd_child_list, atfork, atforkvalue,
flags);
}
diff --git a/src/assuan-pipe-server.c b/src/assuan-pipe-server.c
index f8c98d0..3304498 100644
--- a/src/assuan-pipe-server.c
+++ b/src/assuan-pipe-server.c
@@ -1,123 +1,132 @@
/* assuan-pipe-server.c - Assuan server working over a pipe
Copyright (C) 2001, 2002, 2009 Free Software Foundation, Inc.
This file is part of Assuan.
Assuan is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
Assuan 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
#ifdef HAVE_W32_SYSTEM
-#include <windows.h>
-#include <fcntl.h>
+# ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+# endif
+# include <windows.h>
+# include <fcntl.h>
#endif
#include "assuan-defs.h"
#include "debug.h"
/* Returns true if atoi(S) denotes a valid socket. */
#ifndef HAVE_W32_SYSTEM
static int
is_valid_socket (const char *s)
{
struct stat buf;
if ( fstat (atoi (s), &buf ) )
return 0;
return S_ISSOCK (buf.st_mode);
}
#endif /*!HAVE_W32_SYSTEM*/
/* This actually is a int file descriptor (and not assuan_fd_t) as
_get_osfhandle is called on W32 systems. */
gpg_error_t
assuan_init_pipe_server (assuan_context_t ctx, assuan_fd_t filedes[2])
{
const char *s;
unsigned long ul;
gpg_error_t rc;
assuan_fd_t infd = ASSUAN_INVALID_FD;
assuan_fd_t outfd = ASSUAN_INVALID_FD;
int is_usd = 0;
TRACE_BEG (ctx, ASSUAN_LOG_CTX, "assuan_init_pipe_server", ctx);
if (filedes)
{
TRACE_LOG2 ("fd[0]=0x%x, fd[1]=0x%x", filedes[0], filedes[1]);
}
rc = _assuan_register_std_commands (ctx);
if (rc)
return TRACE_ERR (rc);
#ifdef HAVE_W32_SYSTEM
infd = filedes[0];
outfd = filedes[1];
#else
s = getenv ("_assuan_connection_fd");
if (s && *s && is_valid_socket (s))
{
/* Well, we are called with an bi-directional file descriptor.
Prepare for using sendmsg/recvmsg. In this case we ignore
the passed file descriptors. */
infd = atoi (s);
outfd = atoi (s);
is_usd = 1;
}
else if (filedes && filedes[0] != ASSUAN_INVALID_FD
&& filedes[1] != ASSUAN_INVALID_FD )
{
/* Standard pipe server. */
infd = filedes[0];
outfd = filedes[1];
}
else
{
rc = _assuan_error (ctx, GPG_ERR_ASS_SERVER_START);
return TRACE_ERR (rc);
}
#endif
ctx->is_server = 1;
ctx->engine.release = _assuan_server_release;
ctx->engine.readfnc = _assuan_simple_read;
ctx->engine.writefnc = _assuan_simple_write;
ctx->engine.sendfd = NULL;
ctx->engine.receivefd = NULL;
ctx->max_accepts = 1;
s = getenv ("_assuan_pipe_connect_pid");
if (s && (ul=strtoul (s, NULL, 10)) && ul)
ctx->pid = (pid_t)ul;
else
ctx->pid = (pid_t)-1;
ctx->accept_handler = NULL;
ctx->finish_handler = _assuan_server_finish;
ctx->inbound.fd = infd;
ctx->outbound.fd = outfd;
if (is_usd)
_assuan_init_uds_io (ctx);
return TRACE_SUC();
}
diff --git a/src/assuan-socket-connect.c b/src/assuan-socket-connect.c
index b54d5e4..4ccaf1a 100644
--- a/src/assuan-socket-connect.c
+++ b/src/assuan-socket-connect.c
@@ -1,303 +1,310 @@
/* assuan-socket-connect.c - Assuan socket based client
Copyright (C) 2002, 2003, 2004, 2009 Free Software Foundation, Inc.
This file is part of Assuan.
Assuan is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
Assuan 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
-#include <unistd.h>
-#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
#ifdef HAVE_W32_SYSTEM
+# ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+# endif
# include <windows.h>
#else
# include <sys/socket.h>
# include <sys/un.h>
# include <netinet/in.h>
# include <arpa/inet.h>
#endif
#include "assuan-defs.h"
#include "debug.h"
/* Hacks for Slowaris. */
#ifndef PF_LOCAL
# ifdef PF_UNIX
# define PF_LOCAL PF_UNIX
# else
# define PF_LOCAL AF_UNIX
# endif
#endif
#ifndef AF_LOCAL
# define AF_LOCAL AF_UNIX
#endif
#ifndef INADDR_NONE
#define INADDR_NONE ((unsigned long)(-1))
#endif /*INADDR_NONE*/
#ifndef SUN_LEN
# define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \
+ strlen ((ptr)->sun_path))
#endif
#undef WITH_IPV6
#if defined (AF_INET6) && defined(PF_INET) \
&& defined (INET6_ADDRSTRLEN) && defined(HAVE_INET_PTON)
# define WITH_IPV6 1
#endif
/* Returns true if STR represents a valid port number in decimal
notation and no garbage is following. */
static int
parse_portno (const char *str, uint16_t *r_port)
{
unsigned int value;
for (value=0; *str && (*str >= '0' && *str <= '9'); str++)
{
value = value * 10 + (*str - '0');
if (value > 65535)
return 0;
}
if (*str || !value)
return 0;
*r_port = value;
return 1;
}
/* Make a connection to the Unix domain socket NAME and return a new
Assuan context in CTX. SERVER_PID is currently not used but may
become handy in the future. Defined flag bits are:
ASSUAN_SOCKET_CONNECT_FDPASSING
sendmsg and recvmsg are used.
NAME must either start with a slash and optional with a drive
prefix ("c:") or use one of these URL schemata:
file://<fname>
This is the same as the default just with an explicit schemata.
assuan://<ipaddr>:<port>
assuan://[<ip6addr>]:<port>
Connect using TCP to PORT of the server with the numerical
IPADDR. Not that the '[' and ']' are literal characters.
*/
gpg_error_t
assuan_socket_connect (assuan_context_t ctx, const char *name,
pid_t server_pid, unsigned int flags)
{
gpg_error_t err = 0;
assuan_fd_t fd;
#ifdef WITH_IPV6
struct sockaddr_in6 srvr_addr_in6;
#endif
struct sockaddr_un srvr_addr_un;
struct sockaddr_in srvr_addr_in;
struct sockaddr *srvr_addr = NULL;
uint16_t port = 0;
size_t len = 0;
const char *s;
int af = AF_LOCAL;
int pf = PF_LOCAL;
TRACE2 (ctx, ASSUAN_LOG_CTX, "assuan_socket_connect", ctx,
"name=%s, flags=0x%x", name ? name : "(null)", flags);
if (!ctx || !name)
return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE);
if (!strncmp (name, "file://", 7) && name[7])
name += 7;
else if (!strncmp (name, "assuan://", 9) && name[9])
{
name += 9;
af = AF_INET;
pf = PF_INET;
}
else /* Default. */
{
/* We require that the name starts with a slash if no URL
schemata is used. To make things easier we allow an optional
driver prefix. */
s = name;
if (*s && s[1] == ':')
s += 2;
if (*s != DIRSEP_C && *s != '/')
return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE);
}
if (af == AF_LOCAL)
{
if (strlen (name)+1 >= sizeof srvr_addr_un.sun_path)
return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE);
memset (&srvr_addr_un, 0, sizeof srvr_addr_un);
srvr_addr_un.sun_family = AF_LOCAL;
strncpy (srvr_addr_un.sun_path, name, sizeof (srvr_addr_un.sun_path) - 1);
srvr_addr_un.sun_path[sizeof (srvr_addr_un.sun_path) - 1] = 0;
len = SUN_LEN (&srvr_addr_un);
srvr_addr = (struct sockaddr *)&srvr_addr_un;
}
else
{
char *addrstr, *p;
void *addrbuf = NULL;
addrstr = _assuan_malloc (ctx, strlen (name) + 1);
if (!addrstr)
return _assuan_error (ctx, gpg_err_code_from_syserror ());
if (*name == '[')
{
strcpy (addrstr, name+1);
p = strchr (addrstr, ']');
if (!p || p[1] != ':' || !parse_portno (p+2, &port))
err = _assuan_error (ctx, GPG_ERR_BAD_URI);
else
{
*p = 0;
#ifdef WITH_IPV6
af = AF_INET6;
pf = PF_INET6;
memset (&srvr_addr_in6, 0, sizeof srvr_addr_in6);
srvr_addr_in6.sin6_family = af;
srvr_addr_in6.sin6_port = htons (port);
addrbuf = &srvr_addr_in6.sin6_addr;
srvr_addr = (struct sockaddr *)&srvr_addr_in6;
len = sizeof srvr_addr_in6;
#else
err = _assuan_error (ctx, GPG_ERR_EAFNOSUPPORT);
#endif
}
}
else
{
strcpy (addrstr, name);
p = strchr (addrstr, ':');
if (!p || !parse_portno (p+1, &port))
err = _assuan_error (ctx, GPG_ERR_BAD_URI);
else
{
*p = 0;
memset (&srvr_addr_in, 0, sizeof srvr_addr_in);
srvr_addr_in.sin_family = af;
srvr_addr_in.sin_port = htons (port);
addrbuf = &srvr_addr_in.sin_addr;
srvr_addr = (struct sockaddr *)&srvr_addr_in;
len = sizeof srvr_addr_in;
}
}
if (!err)
{
#ifdef HAVE_INET_PTON
switch (inet_pton (af, addrstr, addrbuf))
{
case 1: break;
case 0: err = _assuan_error (ctx, GPG_ERR_BAD_URI); break;
default: err = _assuan_error (ctx, gpg_err_code_from_syserror ());
}
#else /*!HAVE_INET_PTON*/
/* We need to use the old function. If we are here v6
support isn't enabled anyway and thus we can do fine
without. Note that Windows as a compatible inet_pton
function named inetPton, but only since Vista. */
srvr_addr_in.sin_addr.s_addr = inet_addr (addrstr);
if (srvr_addr_in.sin_addr.s_addr == INADDR_NONE)
err = _assuan_error (ctx, GPG_ERR_BAD_URI);
#endif /*!HAVE_INET_PTON*/
}
_assuan_free (ctx, addrstr);
if (err)
return err;
}
fd = _assuan_sock_new (ctx, pf, SOCK_STREAM, 0);
if (fd == ASSUAN_INVALID_FD)
{
err = _assuan_error (ctx, gpg_err_code_from_syserror ());
TRACE1 (ctx, ASSUAN_LOG_SYSIO, "assuan_socket_connect", ctx,
"can't create socket: %s", strerror (errno));
return err;
}
if (_assuan_sock_connect (ctx, fd, srvr_addr, len) == -1)
{
TRACE2 (ctx, ASSUAN_LOG_SYSIO, "assuan_socket_connect", ctx,
"can't connect to `%s': %s\n", name, strerror (errno));
_assuan_close (ctx, fd);
return _assuan_error (ctx, GPG_ERR_ASS_CONNECT_FAILED);
}
ctx->engine.release = _assuan_client_release;
ctx->engine.readfnc = _assuan_simple_read;
ctx->engine.writefnc = _assuan_simple_write;
ctx->engine.sendfd = NULL;
ctx->engine.receivefd = NULL;
ctx->finish_handler = _assuan_client_finish;
ctx->inbound.fd = fd;
ctx->outbound.fd = fd;
ctx->max_accepts = -1;
if (flags & ASSUAN_SOCKET_CONNECT_FDPASSING)
_assuan_init_uds_io (ctx);
/* initial handshake */
{
assuan_response_t response;
int off;
err = _assuan_read_from_server (ctx, &response, &off, 0);
if (err)
TRACE1 (ctx, ASSUAN_LOG_SYSIO, "assuan_socket_connect", ctx,
"can't connect to server: %s\n", gpg_strerror (err));
else if (response != ASSUAN_RESPONSE_OK)
{
char *sname = _assuan_encode_c_string (ctx, ctx->inbound.line);
if (sname)
{
TRACE1 (ctx, ASSUAN_LOG_SYSIO, "assuan_socket_connect", ctx,
"can't connect to server: %s", sname);
_assuan_free (ctx, sname);
}
err = _assuan_error (ctx, GPG_ERR_ASS_CONNECT_FAILED);
}
}
if (err)
_assuan_reset (ctx);
return err;
}
diff --git a/src/assuan-socket-server.c b/src/assuan-socket-server.c
index 031ee88..27994a2 100644
--- a/src/assuan-socket-server.c
+++ b/src/assuan-socket-server.c
@@ -1,183 +1,190 @@
/* assuan-socket-server.c - Assuan socket based server
Copyright (C) 2002, 2007, 2009 Free Software Foundation, Inc.
This file is part of Assuan.
Assuan is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
Assuan 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
-#include <unistd.h>
-#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
#ifdef HAVE_W32_SYSTEM
+# ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+# endif
# include <windows.h>
# if HAVE_SYS_SOCKET_H
# include <sys/socket.h>
# elif HAVE_WS2TCPIP_H
# include <ws2tcpip.h>
# endif
#else
# include <sys/socket.h>
# include <sys/un.h>
#endif
#include "debug.h"
#include "assuan-defs.h"
static gpg_error_t
accept_connection_bottom (assuan_context_t ctx)
{
assuan_fd_t fd = ctx->connected_fd;
TRACE (ctx, ASSUAN_LOG_SYSIO, "accept_connection_bottom", ctx);
ctx->peercred_valid = 0;
#ifdef HAVE_SO_PEERCRED
{
struct ucred cr;
socklen_t cl = sizeof cr;
if ( !getsockopt (fd, SOL_SOCKET, SO_PEERCRED, &cr, &cl))
{
ctx->peercred.pid = cr.pid;
ctx->peercred.uid = cr.uid;
ctx->peercred.gid = cr.gid;
ctx->peercred_valid = 1;
/* This overrides any already set PID if the function returns
a valid one. */
if (cr.pid != ASSUAN_INVALID_PID && cr.pid)
ctx->pid = cr.pid;
}
}
#endif
ctx->inbound.fd = fd;
ctx->inbound.eof = 0;
ctx->inbound.linelen = 0;
ctx->inbound.attic.linelen = 0;
ctx->inbound.attic.pending = 0;
ctx->outbound.fd = fd;
ctx->outbound.data.linelen = 0;
ctx->outbound.data.error = 0;
ctx->flags.confidential = 0;
return 0;
}
static gpg_error_t
accept_connection (assuan_context_t ctx)
{
assuan_fd_t fd;
struct sockaddr_un clnt_addr;
socklen_t len = sizeof clnt_addr;
TRACE1 (ctx, ASSUAN_LOG_SYSIO, "accept_connection", ctx,
"listen_fd=0x%x", ctx->listen_fd);
fd = SOCKET2HANDLE(accept (HANDLE2SOCKET(ctx->listen_fd),
(struct sockaddr*)&clnt_addr, &len ));
if (fd == ASSUAN_INVALID_FD)
{
return _assuan_error (ctx, gpg_err_code_from_syserror ());
}
TRACE1 (ctx, ASSUAN_LOG_SYSIO, "accept_connection", ctx,
"fd->0x%x", fd);
if (_assuan_sock_check_nonce (ctx, fd, &ctx->listen_nonce))
{
_assuan_close (ctx, fd);
return _assuan_error (ctx, GPG_ERR_ASS_ACCEPT_FAILED);
}
ctx->connected_fd = fd;
return accept_connection_bottom (ctx);
}
/*
Flag bits: 0 - use sendmsg/recvmsg to allow descriptor passing
1 - FD has already been accepted.
*/
gpg_error_t
assuan_init_socket_server (assuan_context_t ctx, assuan_fd_t fd,
unsigned int flags)
{
gpg_error_t rc;
TRACE_BEG2 (ctx, ASSUAN_LOG_CTX, "assuan_init_socket_server", ctx,
"fd=0x%x, flags=0x%x", fd, flags);
rc = _assuan_register_std_commands (ctx);
if (rc)
return TRACE_ERR (rc);
ctx->engine.release = _assuan_server_release;
ctx->engine.readfnc = _assuan_simple_read;
ctx->engine.writefnc = _assuan_simple_write;
ctx->engine.sendfd = NULL;
ctx->engine.receivefd = NULL;
ctx->is_server = 1;
if (flags & ASSUAN_SOCKET_SERVER_ACCEPTED)
/* We want a second accept to indicate EOF. */
ctx->max_accepts = 1;
else
ctx->max_accepts = -1;
ctx->input_fd = ASSUAN_INVALID_FD;
ctx->output_fd = ASSUAN_INVALID_FD;
ctx->inbound.fd = ASSUAN_INVALID_FD;
ctx->outbound.fd = ASSUAN_INVALID_FD;
if (flags & ASSUAN_SOCKET_SERVER_ACCEPTED)
{
ctx->listen_fd = ASSUAN_INVALID_FD;
ctx->connected_fd = fd;
}
else
{
ctx->listen_fd = fd;
ctx->connected_fd = ASSUAN_INVALID_FD;
}
ctx->accept_handler = ((flags & ASSUAN_SOCKET_SERVER_ACCEPTED)
? accept_connection_bottom
: accept_connection);
ctx->finish_handler = _assuan_server_finish;
if (flags & ASSUAN_SOCKET_SERVER_FDPASSING)
_assuan_init_uds_io (ctx);
rc = _assuan_register_std_commands (ctx);
if (rc)
_assuan_reset (ctx);
return TRACE_ERR (rc);
}
/* Save a copy of NONCE in context CTX. This should be used to
register the server's nonce with an context established by
assuan_init_socket_server. */
void
assuan_set_sock_nonce (assuan_context_t ctx, assuan_sock_nonce_t *nonce)
{
if (ctx && nonce)
ctx->listen_nonce = *nonce;
}
diff --git a/src/assuan-socket.c b/src/assuan-socket.c
index ca0609a..937ff56 100644
--- a/src/assuan-socket.c
+++ b/src/assuan-socket.c
@@ -1,469 +1,475 @@
/* assuan-socket.c
Copyright (C) 2004, 2005, 2009 Free Software Foundation, Inc.
This file is part of Assuan.
Assuan is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
Assuan 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_W32_SYSTEM
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#include <wincrypt.h>
-#include <io.h>
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+# include <wincrypt.h>
+# include <io.h>
#else
-#include <sys/types.h>
-#include <sys/socket.h>
+# include <sys/types.h>
+# include <sys/socket.h>
#endif
#include <errno.h>
-#include <sys/stat.h>
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
#include <fcntl.h>
#include <assert.h>
#include "assuan-defs.h"
#include "debug.h"
/* Hacks for Slowaris. */
#ifndef PF_LOCAL
# ifdef PF_UNIX
# define PF_LOCAL PF_UNIX
# else
# define PF_LOCAL AF_UNIX
# endif
#endif
#ifndef AF_LOCAL
# define AF_LOCAL AF_UNIX
#endif
#ifdef HAVE_W32_SYSTEM
+#ifndef S_IRUSR
+# define S_IRUSR 0
+# define S_IWUSR 0
+#endif
#ifndef S_IRGRP
# define S_IRGRP 0
# define S_IWGRP 0
#endif
#endif
#ifdef HAVE_W32_SYSTEM
int
_assuan_sock_wsa2errno (int err)
{
switch (err)
{
case WSAENOTSOCK:
return EINVAL;
case WSAEWOULDBLOCK:
return EAGAIN;
case ERROR_BROKEN_PIPE:
return EPIPE;
case WSANOTINITIALISED:
return ENOSYS;
default:
return EIO;
}
}
/* W32: Fill BUFFER with LENGTH bytes of random. Returns -1 on
failure, 0 on success. Sets errno on failure. */
static int
get_nonce (char *buffer, size_t nbytes)
{
HCRYPTPROV prov;
int ret = -1;
if (!CryptAcquireContext (&prov, NULL, NULL, PROV_RSA_FULL,
(CRYPT_VERIFYCONTEXT|CRYPT_SILENT)) )
gpg_err_set_errno (ENODEV);
else
{
if (!CryptGenRandom (prov, nbytes, (unsigned char *) buffer))
gpg_err_set_errno (ENODEV);
else
ret = 0;
CryptReleaseContext (prov, 0);
}
return ret;
}
/* W32: The buffer for NONCE needs to be at least 16 bytes. Returns 0 on
success and sets errno on failure. */
static int
read_port_and_nonce (const char *fname, unsigned short *port, char *nonce)
{
FILE *fp;
char buffer[50], *p;
size_t nread;
int aval;
fp = fopen (fname, "rb");
if (!fp)
return -1;
nread = fread (buffer, 1, sizeof buffer - 1, fp);
fclose (fp);
if (!nread)
{
gpg_err_set_errno (ENOENT);
return -1;
}
buffer[nread] = 0;
aval = atoi (buffer);
if (aval < 1 || aval > 65535)
{
gpg_err_set_errno (EINVAL);
return -1;
}
*port = (unsigned int)aval;
for (p=buffer; nread && *p != '\n'; p++, nread--)
;
if (*p != '\n' || nread != 17)
{
gpg_err_set_errno (EINVAL);
return -1;
}
p++; nread--;
memcpy (nonce, p, 16);
return 0;
}
#endif /*HAVE_W32_SYSTEM*/
/* Return a new socket. Note that under W32 we consider a socket the
same as an System Handle; all functions using such a handle know
about this dual use and act accordingly. */
assuan_fd_t
_assuan_sock_new (assuan_context_t ctx, int domain, int type, int proto)
{
#ifdef HAVE_W32_SYSTEM
assuan_fd_t res;
if (domain == AF_UNIX || domain == AF_LOCAL)
domain = AF_INET;
res = SOCKET2HANDLE(socket (domain, type, proto));
if (res == ASSUAN_INVALID_FD)
gpg_err_set_errno (_assuan_sock_wsa2errno (WSAGetLastError ()));
return res;
#else
return socket (domain, type, proto);
#endif
}
int
_assuan_sock_connect (assuan_context_t ctx, assuan_fd_t sockfd,
struct sockaddr *addr, int addrlen)
{
#ifdef HAVE_W32_SYSTEM
if (addr->sa_family == AF_LOCAL || addr->sa_family == AF_UNIX)
{
struct sockaddr_in myaddr;
struct sockaddr_un *unaddr;
unsigned short port;
char nonce[16];
int ret;
unaddr = (struct sockaddr_un *)addr;
if (read_port_and_nonce (unaddr->sun_path, &port, nonce))
return -1;
myaddr.sin_family = AF_INET;
myaddr.sin_port = htons (port);
myaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
/* Set return values. */
unaddr->sun_family = myaddr.sin_family;
unaddr->sun_port = myaddr.sin_port;
unaddr->sun_addr.s_addr = myaddr.sin_addr.s_addr;
ret = connect (HANDLE2SOCKET(sockfd),
(struct sockaddr *)&myaddr, sizeof myaddr);
if (!ret)
{
/* Send the nonce. */
ret = _assuan_write (ctx, sockfd, nonce, 16);
if (ret >= 0 && ret != 16)
{
gpg_err_set_errno (EIO);
ret = -1;
}
}
return ret;
}
else
{
int res;
res = connect (HANDLE2SOCKET (sockfd), addr, addrlen);
if (res < 0)
gpg_err_set_errno (_assuan_sock_wsa2errno (WSAGetLastError ()));
return res;
}
#else
return connect (sockfd, addr, addrlen);
#endif
}
int
_assuan_sock_bind (assuan_context_t ctx, assuan_fd_t sockfd,
struct sockaddr *addr, int addrlen)
{
#ifdef HAVE_W32_SYSTEM
if (addr->sa_family == AF_LOCAL || addr->sa_family == AF_UNIX)
{
struct sockaddr_in myaddr;
struct sockaddr_un *unaddr;
int filefd;
FILE *fp;
int len = sizeof myaddr;
int rc;
char nonce[16];
if (get_nonce (nonce, 16))
return -1;
unaddr = (struct sockaddr_un *)addr;
myaddr.sin_port = 0;
myaddr.sin_family = AF_INET;
myaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
filefd = open (unaddr->sun_path,
(O_WRONLY|O_CREAT|O_EXCL|O_BINARY),
(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP));
if (filefd == -1)
{
if (errno == EEXIST)
gpg_err_set_errno (WSAEADDRINUSE);
return -1;
}
fp = fdopen (filefd, "wb");
if (!fp)
{
int save_e = errno;
close (filefd);
gpg_err_set_errno (save_e);
return -1;
}
rc = bind (HANDLE2SOCKET (sockfd), (struct sockaddr *)&myaddr, len);
if (!rc)
rc = getsockname (HANDLE2SOCKET (sockfd),
(struct sockaddr *)&myaddr, &len);
if (rc)
{
int save_e = errno;
fclose (fp);
DeleteFile (unaddr->sun_path);
gpg_err_set_errno (save_e);
return rc;
}
fprintf (fp, "%d\n", ntohs (myaddr.sin_port));
fwrite (nonce, 16, 1, fp);
fclose (fp);
return 0;
}
else
{
int res = bind (HANDLE2SOCKET(sockfd), addr, addrlen);
if (res < 0)
gpg_err_set_errno ( _assuan_sock_wsa2errno (WSAGetLastError ()));
return res;
}
#else
return bind (sockfd, addr, addrlen);
#endif
}
int
_assuan_sock_get_nonce (assuan_context_t ctx, struct sockaddr *addr,
int addrlen, assuan_sock_nonce_t *nonce)
{
#ifdef HAVE_W32_SYSTEM
if (addr->sa_family == AF_LOCAL || addr->sa_family == AF_UNIX)
{
struct sockaddr_un *unaddr;
unsigned short port;
if (sizeof nonce->nonce != 16)
{
gpg_err_set_errno (EINVAL);
return -1;
}
nonce->length = 16;
unaddr = (struct sockaddr_un *)addr;
if (read_port_and_nonce (unaddr->sun_path, &port, nonce->nonce))
return -1;
}
else
{
nonce->length = 42; /* Arbitrary value to detect unitialized nonce. */
nonce->nonce[0] = 42;
}
#else
(void)addr;
(void)addrlen;
nonce->length = 0;
#endif
return 0;
}
int
_assuan_sock_check_nonce (assuan_context_t ctx, assuan_fd_t fd,
assuan_sock_nonce_t *nonce)
{
#ifdef HAVE_W32_SYSTEM
char buffer[16], *p;
size_t nleft;
int n;
if (sizeof nonce->nonce != 16)
{
gpg_err_set_errno (EINVAL);
return -1;
}
if (nonce->length == 42 && nonce->nonce[0] == 42)
return 0; /* Not a Unix domain socket. */
if (nonce->length != 16)
{
gpg_err_set_errno (EINVAL);
return -1;
}
p = buffer;
nleft = 16;
while (nleft)
{
n = _assuan_read (ctx, SOCKET2HANDLE(fd), p, nleft);
if (n < 0 && errno == EINTR)
;
else if (n < 0 && errno == EAGAIN)
Sleep (100);
else if (n < 0)
return -1;
else if (!n)
{
gpg_err_set_errno (EIO);
return -1;
}
else
{
p += n;
nleft -= n;
}
}
if (memcmp (buffer, nonce->nonce, 16))
{
gpg_err_set_errno (EACCES);
return -1;
}
#else
(void)fd;
(void)nonce;
#endif
return 0;
}
/* Public API. */
/* In the future, we can allow access to sock_ctx, if that context's
hook functions need to be overridden. There can only be one global
assuan_sock_* user (one library or one application) with this
convenience interface, if non-standard hook functions are
needed. */
static assuan_context_t sock_ctx;
gpg_error_t
assuan_sock_init ()
{
gpg_error_t err;
#ifdef HAVE_W32_SYSTEM
WSADATA wsadat;
#endif
if (sock_ctx != NULL)
return 0;
err = assuan_new (&sock_ctx);
#ifdef HAVE_W32_SYSTEM
if (! err)
WSAStartup (0x202, &wsadat);
#endif
return err;
}
void
assuan_sock_deinit ()
{
if (sock_ctx == NULL)
return;
#ifdef HAVE_W32_SYSTEM
WSACleanup ();
#endif
assuan_release (sock_ctx);
sock_ctx = NULL;
}
int
assuan_sock_close (assuan_fd_t fd)
{
return _assuan_close (sock_ctx, fd);
}
assuan_fd_t
assuan_sock_new (int domain, int type, int proto)
{
return _assuan_sock_new (sock_ctx, domain, type, proto);
}
int
assuan_sock_connect (assuan_fd_t sockfd, struct sockaddr *addr, int addrlen)
{
return _assuan_sock_connect (sock_ctx, sockfd, addr, addrlen);
}
int
assuan_sock_bind (assuan_fd_t sockfd, struct sockaddr *addr, int addrlen)
{
return _assuan_sock_bind (sock_ctx, sockfd, addr, addrlen);
}
int
assuan_sock_get_nonce (struct sockaddr *addr, int addrlen,
assuan_sock_nonce_t *nonce)
{
return _assuan_sock_get_nonce (sock_ctx, addr, addrlen, nonce);
}
int
assuan_sock_check_nonce (assuan_fd_t fd, assuan_sock_nonce_t *nonce)
{
return _assuan_sock_check_nonce (sock_ctx, fd, nonce);
}
diff --git a/src/assuan-uds.c b/src/assuan-uds.c
index 96cf683..93fa957 100644
--- a/src/assuan-uds.c
+++ b/src/assuan-uds.c
@@ -1,289 +1,296 @@
/* assuan-uds.c - Assuan unix domain socket utilities
Copyright (C) 2006, 2009 Free Software Foundation, Inc.
This file is part of Assuan.
Assuan is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
Assuan 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <errno.h>
-#include <sys/types.h>
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
#ifndef HAVE_W32_SYSTEM
-#include <sys/socket.h>
-#include <sys/un.h>
+# include <sys/socket.h>
+# include <sys/un.h>
#else
-#include <windows.h>
+# ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+# endif
+# include <windows.h>
#endif
#if HAVE_SYS_UIO_H
#include <sys/uio.h>
#endif
-#include <unistd.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
#include <fcntl.h>
#include <string.h>
#include <assert.h>
#include "assuan-defs.h"
#include "debug.h"
#ifdef USE_DESCRIPTOR_PASSING
/* Provide replacement for missing CMSG maccros. We assume that
size_t matches the alignment requirement. NOTE: This is not true
on Mac OS X, so be extra careful to define _DARWIN_C_SOURCE to get
those definitions instead of using these. */
#define MY_ALIGN(n) ((((n))+ sizeof(size_t)-1) & (size_t)~(sizeof(size_t)-1))
#ifndef CMSG_SPACE
#define CMSG_SPACE(n) (MY_ALIGN(sizeof(struct cmsghdr)) + MY_ALIGN((n)))
#endif
#ifndef CMSG_LEN
#define CMSG_LEN(n) (MY_ALIGN(sizeof(struct cmsghdr)) + (n))
#endif
#ifndef CMSG_FIRSTHDR
#define CMSG_FIRSTHDR(mhdr) \
((size_t)(mhdr)->msg_controllen >= sizeof (struct cmsghdr) \
? (struct cmsghdr*) (mhdr)->msg_control : (struct cmsghdr*)NULL)
#endif
#ifndef CMSG_DATA
#define CMSG_DATA(cmsg) ((unsigned char*)((struct cmsghdr*)(cmsg)+1))
#endif
#endif /*USE_DESCRIPTOR_PASSING*/
/* Read from a unix domain socket using sendmsg. */
static ssize_t
uds_reader (assuan_context_t ctx, void *buf, size_t buflen)
{
#ifndef HAVE_W32_SYSTEM
int len = 0;
/* This loop should be OK. As FDs are followed by data, the
readable status of the socket does not change and no new
select/event-loop round is necessary. */
while (!len) /* No data is buffered. */
{
struct msghdr msg;
struct iovec iovec;
#ifdef USE_DESCRIPTOR_PASSING
union {
struct cmsghdr cm;
char control[CMSG_SPACE(sizeof (int))];
} control_u;
struct cmsghdr *cmptr;
#endif /*USE_DESCRIPTOR_PASSING*/
memset (&msg, 0, sizeof (msg));
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = &iovec;
msg.msg_iovlen = 1;
iovec.iov_base = buf;
iovec.iov_len = buflen;
#ifdef USE_DESCRIPTOR_PASSING
msg.msg_control = control_u.control;
msg.msg_controllen = sizeof (control_u.control);
#endif
len = _assuan_recvmsg (ctx, ctx->inbound.fd, &msg, 0);
if (len < 0)
return -1;
if (len == 0)
return 0;
#ifdef USE_DESCRIPTOR_PASSING
cmptr = CMSG_FIRSTHDR (&msg);
if (cmptr && cmptr->cmsg_len == CMSG_LEN (sizeof(int)))
{
if (cmptr->cmsg_level != SOL_SOCKET
|| cmptr->cmsg_type != SCM_RIGHTS)
TRACE0 (ctx, ASSUAN_LOG_SYSIO, "uds_reader", ctx,
"unexpected ancillary data received");
else
{
int fd;
memcpy (&fd, CMSG_DATA (cmptr), sizeof (fd));
if (ctx->uds.pendingfdscount >= DIM (ctx->uds.pendingfds))
{
TRACE1 (ctx, ASSUAN_LOG_SYSIO, "uds_reader", ctx,
"too many descriptors pending - "
"closing received descriptor %d", fd);
_assuan_close (ctx, fd);
}
else
ctx->uds.pendingfds[ctx->uds.pendingfdscount++] = fd;
}
}
#endif /*USE_DESCRIPTOR_PASSING*/
}
return len;
#else /*HAVE_W32_SYSTEM*/
int res = recvfrom (HANDLE2SOCKET(ctx->inbound.fd), buf, buflen, 0, NULL, NULL);
if (res < 0)
gpg_err_set_errno (_assuan_sock_wsa2errno (WSAGetLastError ()));
return res;
#endif /*HAVE_W32_SYSTEM*/
}
/* Write to the domain server. */
static ssize_t
uds_writer (assuan_context_t ctx, const void *buf, size_t buflen)
{
#ifndef HAVE_W32_SYSTEM
struct msghdr msg;
struct iovec iovec;
ssize_t len;
memset (&msg, 0, sizeof (msg));
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iovlen = 1;
msg.msg_iov = &iovec;
iovec.iov_base = (void*)buf;
iovec.iov_len = buflen;
len = _assuan_sendmsg (ctx, ctx->outbound.fd, &msg, 0);
return len;
#else /*HAVE_W32_SYSTEM*/
int res = sendto (HANDLE2SOCKET(ctx->outbound.fd), buf, buflen, 0,
(struct sockaddr *)&ctx->serveraddr,
sizeof (struct sockaddr_in));
if (res < 0)
gpg_err_set_errno ( _assuan_sock_wsa2errno (WSAGetLastError ()));
return res;
#endif /*HAVE_W32_SYSTEM*/
}
static gpg_error_t
uds_sendfd (assuan_context_t ctx, assuan_fd_t fd)
{
#ifdef USE_DESCRIPTOR_PASSING
struct msghdr msg;
struct iovec iovec;
union {
struct cmsghdr cm;
char control[CMSG_SPACE(sizeof (int))];
} control_u;
struct cmsghdr *cmptr;
int len;
char buffer[80];
/* We need to send some real data so that a read won't return 0
which will be taken as an EOF. It also helps with debugging. */
snprintf (buffer, sizeof(buffer)-1, "# descriptor %d is in flight\n", fd);
buffer[sizeof(buffer)-1] = 0;
memset (&msg, 0, sizeof (msg));
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iovlen = 1;
msg.msg_iov = &iovec;
iovec.iov_base = buffer;
iovec.iov_len = strlen (buffer);
msg.msg_control = control_u.control;
msg.msg_controllen = sizeof (control_u.control);
cmptr = CMSG_FIRSTHDR (&msg);
cmptr->cmsg_len = CMSG_LEN(sizeof(int));
cmptr->cmsg_level = SOL_SOCKET;
cmptr->cmsg_type = SCM_RIGHTS;
memcpy (CMSG_DATA (cmptr), &fd, sizeof (fd));
len = _assuan_sendmsg (ctx, ctx->outbound.fd, &msg, 0);
if (len < 0)
{
int saved_errno = errno;
TRACE1 (ctx, ASSUAN_LOG_SYSIO, "uds_sendfd", ctx,
"uds_sendfd: %s", strerror (errno));
errno = saved_errno;
return _assuan_error (ctx, gpg_err_code_from_syserror ());
}
else
return 0;
#else
return _assuan_error (ctx, GPG_ERR_NOT_IMPLEMENTED);
#endif
}
static gpg_error_t
uds_receivefd (assuan_context_t ctx, assuan_fd_t *fd)
{
#ifdef USE_DESCRIPTOR_PASSING
int i;
if (!ctx->uds.pendingfdscount)
{
TRACE0 (ctx, ASSUAN_LOG_SYSIO, "uds_receivefd", ctx,
"no pending file descriptors");
return _assuan_error (ctx, GPG_ERR_ASS_GENERAL);
}
assert (ctx->uds.pendingfdscount <= DIM(ctx->uds.pendingfds));
*fd = ctx->uds.pendingfds[0];
for (i=1; i < ctx->uds.pendingfdscount; i++)
ctx->uds.pendingfds[i-1] = ctx->uds.pendingfds[i];
ctx->uds.pendingfdscount--;
return 0;
#else
return _assuan_error (ctx, GPG_ERR_NOT_IMPLEMENTED);
#endif
}
/* Close all pending fds. */
void
_assuan_uds_close_fds (assuan_context_t ctx)
{
int i;
for (i = 0; i < ctx->uds.pendingfdscount; i++)
_assuan_close (ctx, ctx->uds.pendingfds[i]);
ctx->uds.pendingfdscount = 0;
}
/* Deinitialize the unix domain socket I/O functions. */
void
_assuan_uds_deinit (assuan_context_t ctx)
{
_assuan_uds_close_fds (ctx);
}
/* Helper function to initialize a context for domain I/O. */
void
_assuan_init_uds_io (assuan_context_t ctx)
{
ctx->engine.readfnc = uds_reader;
ctx->engine.writefnc = uds_writer;
ctx->engine.sendfd = uds_sendfd;
ctx->engine.receivefd = uds_receivefd;
ctx->uds.pendingfdscount = 0;
}
diff --git a/src/assuan.h.in b/src/assuan.h.in
index 456e184..ea91973 100644
--- a/src/assuan.h.in
+++ b/src/assuan.h.in
@@ -1,505 +1,505 @@
/* assuan.h - Definitions for the Assuan IPC library -*- c -*-
Copyright (C) 2001, 2002, 2003, 2005, 2007, 2008, 2009,
2010 Free Software Foundation, Inc.
This file is part of Assuan.
Assuan is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
Assuan 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
@configure_input@
*/
#ifndef ASSUAN_H
#define ASSUAN_H
#include <stdio.h>
-#include <sys/types.h>
-#include <unistd.h>
+@include:sys/types.h@
+@include:unistd.h@
#include <stdarg.h>
#ifndef _ASSUAN_NO_SOCKET_WRAPPER
@include:includes@
#endif /*!_ASSUAN_NO_SOCKET_WRAPPER*/
@include:types@
#include <gpg-error.h>
/* Compile time configuration:
#define _ASSUAN_NO_SOCKET_WRAPPER
Do not include the definitions for the socket wrapper feature. */
#ifdef __cplusplus
extern "C"
{
#if 0
}
#endif
#endif
/* Check for compiler features. */
#if __GNUC__
#define _ASSUAN_GCC_VERSION (__GNUC__ * 10000 \
+ __GNUC_MINOR__ * 100 \
+ __GNUC_PATCHLEVEL__)
#if _ASSUAN_GCC_VERSION > 30100
#define _ASSUAN_DEPRECATED __attribute__ ((__deprecated__))
#endif
#endif
#ifndef _ASSUAN_DEPRECATED
#define _ASSUAN_DEPRECATED
#endif
#define ASSUAN_LINELENGTH 1002 /* 1000 + [CR,]LF */
struct assuan_context_s;
typedef struct assuan_context_s *assuan_context_t;
@include:fd-t@
assuan_fd_t assuan_fdopen (int fd);
@include:sock-nonce@
/* Global interface. */
struct assuan_malloc_hooks
{
void *(*malloc) (size_t cnt);
void *(*realloc) (void *ptr, size_t cnt);
void (*free) (void *ptr);
};
typedef struct assuan_malloc_hooks *assuan_malloc_hooks_t;
/* Categories for log messages. */
#define ASSUAN_LOG_INIT 1
#define ASSUAN_LOG_CTX 2
#define ASSUAN_LOG_ENGINE 3
#define ASSUAN_LOG_DATA 4
#define ASSUAN_LOG_SYSIO 5
#define ASSUAN_LOG_CONTROL 8
/* If MSG is NULL, return true/false depending on if this category is
logged. This is used to probe before expensive log message
generation (buffer dumps). */
typedef int (*assuan_log_cb_t) (assuan_context_t ctx, void *hook,
unsigned int cat, const char *msg);
/* Set the default gpg error source. */
void assuan_set_gpg_err_source (gpg_err_source_t errsource);
/* Get the default gpg error source. */
gpg_err_source_t assuan_get_gpg_err_source (void);
/* Set the default malloc hooks. */
void assuan_set_malloc_hooks (assuan_malloc_hooks_t malloc_hooks);
/* Get the default malloc hooks. */
assuan_malloc_hooks_t assuan_get_malloc_hooks (void);
/* Set the default log callback handler. */
void assuan_set_log_cb (assuan_log_cb_t log_cb, void *log_cb_data);
/* Get the default log callback handler. */
void assuan_get_log_cb (assuan_log_cb_t *log_cb, void **log_cb_data);
/* Create a new Assuan context. The initial parameters are all needed
in the creation of the context. */
gpg_error_t assuan_new_ext (assuan_context_t *ctx, gpg_err_source_t errsource,
assuan_malloc_hooks_t malloc_hooks,
assuan_log_cb_t log_cb, void *log_cb_data);
/* Create a new context with default arguments. */
gpg_error_t assuan_new (assuan_context_t *ctx);
/* Release all resources associated with the given context. */
void assuan_release (assuan_context_t ctx);
/* Release the memory at PTR using the allocation handler of the
context CTX. This is a convenience function. */
void assuan_free (assuan_context_t ctx, void *ptr);
/* Set user-data in a context. */
void assuan_set_pointer (assuan_context_t ctx, void *pointer);
/* Get user-data in a context. */
void *assuan_get_pointer (assuan_context_t ctx);
/* Definitions of flags for assuan_set_flag(). */
typedef unsigned int assuan_flag_t;
/* When using a pipe server, by default Assuan will wait for the
forked process to die in assuan_release. In certain cases this
is not desirable. By setting this flag, the waitpid will be
skipped and the caller is responsible to cleanup a forked
process. */
#define ASSUAN_NO_WAITPID 1
/* This flag indicates whether Assuan logging is in confidential mode.
You can use assuan_{begin,end}_condidential to change the mode. */
#define ASSUAN_CONFIDENTIAL 2
/* This flag suppresses fix up of signal handlers for pipes. */
#define ASSUAN_NO_FIXSIGNALS 3
/* This flag changes assuan_transact to return comment lines via the
status callback. The default is to skip comment lines. */
#define ASSUAN_CONVEY_COMMENTS 4
/* This flags disables logging for one context. */
#define ASSUAN_NO_LOGGING 5
/* For context CTX, set the flag FLAG to VALUE. Values for flags
are usually 1 or 0 but certain flags might allow for other values;
see the description of the type assuan_flag_t for details. */
void assuan_set_flag (assuan_context_t ctx, assuan_flag_t flag, int value);
/* Return the VALUE of FLAG in context CTX. */
int assuan_get_flag (assuan_context_t ctx, assuan_flag_t flag);
/* Same as assuan_set_flag (ctx, ASSUAN_CONFIDENTIAL, 1). */
void assuan_begin_confidential (assuan_context_t ctx);
/* Same as assuan_set_flag (ctx, ASSUAN_CONFIDENTIAL, 0). */
void assuan_end_confidential (assuan_context_t ctx);
/* Direction values for assuan_set_io_monitor. */
#define ASSUAN_IO_FROM_PEER 0
#define ASSUAN_IO_TO_PEER 1
/* Return flags of I/O monitor. */
#define ASSUAN_IO_MONITOR_NOLOG 1
#define ASSUAN_IO_MONITOR_IGNORE 2
/* The IO monitor gets to see all I/O on the context, and can return
ASSUAN_IO_MONITOR_* bits to control actions on it. */
typedef unsigned int (*assuan_io_monitor_t) (assuan_context_t ctx, void *hook,
int inout, const char *line,
size_t linelen);
/* Set the IO monitor function. */
void assuan_set_io_monitor (assuan_context_t ctx,
assuan_io_monitor_t io_monitor, void *hook_data);
#define ASSUAN_SYSTEM_HOOKS_VERSION 1
#define ASSUAN_SPAWN_DETACHED 128
struct assuan_system_hooks
{
/* Always set to ASSUAN_SYTEM_HOOKS_VERSION. */
int version;
/* Sleep for the given number of microseconds. */
void (*usleep) (assuan_context_t ctx, unsigned int usec);
/* Create a pipe with an inheritable end. */
int (*pipe) (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx);
/* Close the given file descriptor, created with _assuan_pipe or one
of the socket functions. */
int (*close) (assuan_context_t ctx, assuan_fd_t fd);
ssize_t (*read) (assuan_context_t ctx, assuan_fd_t fd, void *buffer,
size_t size);
ssize_t (*write) (assuan_context_t ctx, assuan_fd_t fd,
const void *buffer, size_t size);
int (*recvmsg) (assuan_context_t ctx, assuan_fd_t fd, assuan_msghdr_t msg,
int flags);
int (*sendmsg) (assuan_context_t ctx, assuan_fd_t fd,
const assuan_msghdr_t msg, int flags);
/* If NAME is NULL, don't exec, just fork. FD_CHILD_LIST is
modified to reflect the value of the FD in the peer process (on
Windows). */
int (*spawn) (assuan_context_t ctx, pid_t *r_pid, const char *name,
const char **argv,
assuan_fd_t fd_in, assuan_fd_t fd_out,
assuan_fd_t *fd_child_list,
void (*atfork) (void *opaque, int reserved),
void *atforkvalue, unsigned int flags);
/* If action is 0, like waitpid. If action is 1, just release the PID? */
pid_t (*waitpid) (assuan_context_t ctx, pid_t pid,
int action, int *status, int options);
int (*socketpair) (assuan_context_t ctx, int _namespace, int style,
int protocol, assuan_fd_t filedes[2]);
};
typedef struct assuan_system_hooks *assuan_system_hooks_t;
/* Configuration of the default log handler. */
/* Set the prefix to be used at the start of a line emitted by assuan
on the log stream. The default is the empty string. Note, that
this function is not thread-safe and should in general be used
right at startup. */
void assuan_set_assuan_log_prefix (const char *text);
/* Return a prefix to be used at the start of a line emitted by assuan
on the log stream. The default implementation returns the empty
string, i.e. "" */
const char *assuan_get_assuan_log_prefix (void);
/* Global default log stream. */
void assuan_set_assuan_log_stream (FILE *fp);
/* Set the per context log stream for the default log handler. */
void assuan_set_log_stream (assuan_context_t ctx, FILE *fp);
typedef gpg_error_t (*assuan_handler_t) (assuan_context_t, char *);
/*-- assuan-handler.c --*/
gpg_error_t assuan_register_command (assuan_context_t ctx,
const char *cmd_string,
assuan_handler_t handler,
const char *help_string);
gpg_error_t assuan_register_post_cmd_notify (assuan_context_t ctx,
void (*fnc)(assuan_context_t,
gpg_error_t));
gpg_error_t assuan_register_bye_notify (assuan_context_t ctx,
assuan_handler_t handler);
gpg_error_t assuan_register_reset_notify (assuan_context_t ctx,
assuan_handler_t handler);
gpg_error_t assuan_register_cancel_notify (assuan_context_t ctx,
assuan_handler_t handler);
gpg_error_t assuan_register_input_notify (assuan_context_t ctx,
assuan_handler_t handler);
gpg_error_t assuan_register_output_notify (assuan_context_t ctx,
assuan_handler_t handler);
gpg_error_t assuan_register_option_handler (assuan_context_t ctx,
gpg_error_t (*fnc)(assuan_context_t,
const char*,
const char*));
gpg_error_t assuan_process (assuan_context_t ctx);
gpg_error_t assuan_process_next (assuan_context_t ctx, int *done);
gpg_error_t assuan_process_done (assuan_context_t ctx, gpg_error_t rc);
int assuan_get_active_fds (assuan_context_t ctx, int what,
assuan_fd_t *fdarray, int fdarraysize);
const char *assuan_get_command_name (assuan_context_t ctx);
FILE *assuan_get_data_fp (assuan_context_t ctx);
gpg_error_t assuan_set_okay_line (assuan_context_t ctx, const char *line);
gpg_error_t assuan_write_status (assuan_context_t ctx,
const char *keyword, const char *text);
/* Negotiate a file descriptor. If LINE contains "FD=N", returns N
assuming a local file descriptor. If LINE contains "FD" reads a
file descriptor via CTX and stores it in *RDF (the CTX must be
capable of passing file descriptors). Under W32 the returned FD is
a libc-type one. */
gpg_error_t assuan_command_parse_fd (assuan_context_t ctx, char *line,
assuan_fd_t *rfd);
/*-- assuan-listen.c --*/
gpg_error_t assuan_set_hello_line (assuan_context_t ctx, const char *line);
gpg_error_t assuan_accept (assuan_context_t ctx);
assuan_fd_t assuan_get_input_fd (assuan_context_t ctx);
assuan_fd_t assuan_get_output_fd (assuan_context_t ctx);
gpg_error_t assuan_close_input_fd (assuan_context_t ctx);
gpg_error_t assuan_close_output_fd (assuan_context_t ctx);
/*-- assuan-pipe-server.c --*/
gpg_error_t assuan_init_pipe_server (assuan_context_t ctx,
assuan_fd_t filedes[2]);
/*-- assuan-socket-server.c --*/
#define ASSUAN_SOCKET_SERVER_FDPASSING 1
#define ASSUAN_SOCKET_SERVER_ACCEPTED 2
gpg_error_t assuan_init_socket_server (assuan_context_t ctx,
assuan_fd_t listen_fd,
unsigned int flags);
void assuan_set_sock_nonce (assuan_context_t ctx, assuan_sock_nonce_t *nonce);
/*-- assuan-pipe-connect.c --*/
#define ASSUAN_PIPE_CONNECT_FDPASSING 1
#define ASSUAN_PIPE_CONNECT_DETACHED 128
gpg_error_t assuan_pipe_connect (assuan_context_t ctx,
const char *name,
const char *argv[],
assuan_fd_t *fd_child_list,
void (*atfork) (void *, int),
void *atforkvalue,
unsigned int flags);
/*-- assuan-socket-connect.c --*/
#define ASSUAN_SOCKET_CONNECT_FDPASSING 1
gpg_error_t assuan_socket_connect (assuan_context_t ctx, const char *name,
pid_t server_pid, unsigned int flags);
/*-- context.c --*/
pid_t assuan_get_pid (assuan_context_t ctx);
struct _assuan_peercred
{
#ifdef _WIN32
/* Empty struct not allowed on some compilers. */
unsigned int _dummy;
#else
pid_t pid;
uid_t uid;
gid_t gid;
#endif
};
typedef struct _assuan_peercred *assuan_peercred_t;
gpg_error_t assuan_get_peercred (assuan_context_t ctx,
assuan_peercred_t *peercred);
/* Client interface. */
#define ASSUAN_RESPONSE_ERROR 0
#define ASSUAN_RESPONSE_OK 1
#define ASSUAN_RESPONSE_DATA 2
#define ASSUAN_RESPONSE_INQUIRE 3
#define ASSUAN_RESPONSE_STATUS 4
#define ASSUAN_RESPONSE_END 5
#define ASSUAN_RESPONSE_COMMENT 6
typedef int assuan_response_t;
/* This already de-escapes data lines. */
gpg_error_t assuan_client_read_response (assuan_context_t ctx,
char **line, int *linelen);
gpg_error_t assuan_client_parse_response (assuan_context_t ctx,
char *line, int linelen,
assuan_response_t *response,
int *off);
/*-- assuan-client.c --*/
gpg_error_t
assuan_transact (assuan_context_t ctx,
const char *command,
gpg_error_t (*data_cb)(void *, const void *, size_t),
void *data_cb_arg,
gpg_error_t (*inquire_cb)(void*, const char *),
void *inquire_cb_arg,
gpg_error_t (*status_cb)(void*, const char *),
void *status_cb_arg);
/*-- assuan-inquire.c --*/
gpg_error_t assuan_inquire (assuan_context_t ctx, const char *keyword,
unsigned char **r_buffer, size_t *r_length,
size_t maxlen);
gpg_error_t assuan_inquire_ext (assuan_context_t ctx, const char *keyword,
size_t maxlen,
gpg_error_t (*cb) (void *cb_data,
gpg_error_t rc,
unsigned char *buf,
size_t buf_len),
void *cb_data);
/*-- assuan-buffer.c --*/
gpg_error_t assuan_read_line (assuan_context_t ctx,
char **line, size_t *linelen);
int assuan_pending_line (assuan_context_t ctx);
gpg_error_t assuan_write_line (assuan_context_t ctx, const char *line);
gpg_error_t assuan_send_data (assuan_context_t ctx,
const void *buffer, size_t length);
/* The file descriptor must be pending before assuan_receivefd is
called. This means that assuan_sendfd should be called *before* the
trigger is sent (normally via assuan_write_line ("INPUT FD")). */
gpg_error_t assuan_sendfd (assuan_context_t ctx, assuan_fd_t fd);
gpg_error_t assuan_receivefd (assuan_context_t ctx, assuan_fd_t *fd);
/*-- assuan-util.c --*/
gpg_error_t assuan_set_error (assuan_context_t ctx, gpg_error_t err,
const char *text);
/*-- assuan-socket.c --*/
/* These are socket wrapper functions to support an emulation of Unix
domain sockets on Windows W32. */
gpg_error_t assuan_sock_init (void);
void assuan_sock_deinit (void);
int assuan_sock_close (assuan_fd_t fd);
assuan_fd_t assuan_sock_new (int domain, int type, int proto);
int assuan_sock_connect (assuan_fd_t sockfd,
struct sockaddr *addr, int addrlen);
int assuan_sock_bind (assuan_fd_t sockfd, struct sockaddr *addr, int addrlen);
int assuan_sock_get_nonce (struct sockaddr *addr, int addrlen,
assuan_sock_nonce_t *nonce);
int assuan_sock_check_nonce (assuan_fd_t fd, assuan_sock_nonce_t *nonce);
/* Set the default or per context system callbacks. This is
irreversible. */
void assuan_set_system_hooks (assuan_system_hooks_t system_hooks);
void assuan_ctx_set_system_hooks (assuan_context_t ctx,
assuan_system_hooks_t system_hooks);
void __assuan_usleep (assuan_context_t ctx, unsigned int usec);
int __assuan_pipe (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx);
int __assuan_close (assuan_context_t ctx, assuan_fd_t fd);
int __assuan_spawn (assuan_context_t ctx, pid_t *r_pid, const char *name,
const char **argv, assuan_fd_t fd_in, assuan_fd_t fd_out,
assuan_fd_t *fd_child_list,
void (*atfork) (void *opaque, int reserved),
void *atforkvalue, unsigned int flags);
int __assuan_socketpair (assuan_context_t ctx, int _namespace, int style,
int protocol, assuan_fd_t filedes[2]);
#define ASSUAN_SYSTEM_PTH_IMPL \
static void _assuan_pth_usleep (assuan_context_t ctx, unsigned int usec) \
{ (void) ctx; pth_usleep (usec); } \
static ssize_t _assuan_pth_read (assuan_context_t ctx, assuan_fd_t fd, \
void *buffer, size_t size) \
{ (void) ctx; return pth_read (fd, buffer, size); } \
static ssize_t _assuan_pth_write (assuan_context_t ctx, assuan_fd_t fd, \
const void *buffer, size_t size) \
{ (void) ctx; return pth_write (fd, buffer, size); } \
@include:sys-pth-impl@
static pid_t _assuan_pth_waitpid (assuan_context_t ctx, pid_t pid, \
int nowait, int *status, int options) \
{ (void) ctx; \
if (!nowait) return pth_waitpid (pid, status, options); \
else return 0; } \
\
struct assuan_system_hooks _assuan_system_pth = \
{ ASSUAN_SYSTEM_HOOKS_VERSION, _assuan_pth_usleep, __assuan_pipe, \
__assuan_close, _assuan_pth_read, _assuan_pth_write, \
_assuan_pth_recvmsg, _assuan_pth_sendmsg, \
__assuan_spawn, _assuan_pth_waitpid, __assuan_socketpair }
extern struct assuan_system_hooks _assuan_system_pth;
#define ASSUAN_SYSTEM_PTH &_assuan_system_pth
@include:w32ce-add@
#ifdef __cplusplus
}
#endif
#endif /* ASSUAN_H */
diff --git a/src/debug.c b/src/debug.c
index 6ebc179..5ed4d4d 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -1,183 +1,185 @@
/* debug.c - helpful output in desperate situations
Copyright (C) 2000 Werner Koch (dd9jn)
Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2009 g10 Code GmbH
This file is part of Assuan.
Assuan is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
Assuan 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
-#include <unistd.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
#include <ctype.h>
#include <errno.h>
#ifndef HAVE_DOSISH_SYSTEM
-# include <sys/types.h>
-# include <sys/stat.h>
-# include <fcntl.h>
+# include <sys/types.h>
+# include <sys/stat.h>
+# include <fcntl.h>
#endif
#include <assert.h>
#include "assuan-defs.h"
#include "debug.h"
/* Log the formatted string FORMAT at debug category CAT higher. */
void
_assuan_debug (assuan_context_t ctx, unsigned int cat, const char *format, ...)
{
va_list arg_ptr;
int saved_errno;
char *msg;
int res;
if (!ctx || !ctx->log_cb)
return;
saved_errno = errno;
va_start (arg_ptr, format);
res = vasprintf (&msg, format, arg_ptr);
va_end (arg_ptr);
if (res < 0)
return;
ctx->log_cb (ctx, ctx->log_cb_data, cat, msg);
free (msg);
gpg_err_set_errno (saved_errno);
}
/* Start a new debug line in *LINE, logged at level LEVEL or higher,
and starting with the formatted string FORMAT. */
void
_assuan_debug_begin (assuan_context_t ctx,
void **line, unsigned int cat, const char *format, ...)
{
va_list arg_ptr;
int res;
*line = NULL;
/* Probe if this wants to be logged based on category. */
if (! ctx
|| ! ctx->log_cb
|| ! (*ctx->log_cb) (ctx, ctx->log_cb_data, cat, NULL))
return;
va_start (arg_ptr, format);
res = vasprintf ((char **) line, format, arg_ptr);
va_end (arg_ptr);
if (res < 0)
*line = NULL;
}
/* Add the formatted string FORMAT to the debug line *LINE. */
void
_assuan_debug_add (assuan_context_t ctx, void **line, const char *format, ...)
{
va_list arg_ptr;
char *toadd;
char *result;
int res;
if (!*line)
return;
va_start (arg_ptr, format);
res = vasprintf (&toadd, format, arg_ptr);
va_end (arg_ptr);
if (res < 0)
{
free (*line);
*line = NULL;
}
res = asprintf (&result, "%s%s", *(char **) line, toadd);
free (toadd);
free (*line);
if (res < 0)
*line = NULL;
else
*line = result;
}
/* Finish construction of *LINE and send it to the debug output
stream. */
void
_assuan_debug_end (assuan_context_t ctx, void **line, unsigned int cat)
{
if (!*line)
return;
/* Force logging here by using category ~0. */
_assuan_debug (ctx, ~0, "%s", *line);
free (*line);
*line = NULL;
}
#define TOHEX(val) (((val) < 10) ? ((val) + '0') : ((val) - 10 + 'a'))
void
_assuan_debug_buffer (assuan_context_t ctx, unsigned int cat,
const char *const fmt, const char *const func,
const char *const tagname, void *tag,
const char *const buffer, size_t len)
{
int idx = 0;
int j;
/* Probe if this wants to be logged based on category. */
if (!ctx
|| ! ctx->log_cb
|| ! (*ctx->log_cb) (ctx, ctx->log_cb_data, cat, NULL))
return;
while (idx < len)
{
char str[51];
char *strp = str;
char *strp2 = &str[34];
for (j = 0; j < 16; j++)
{
unsigned char val;
if (idx < len)
{
val = buffer[idx++];
*(strp++) = TOHEX (val >> 4);
*(strp++) = TOHEX (val % 16);
*(strp2++) = isprint (val) ? val : '.';
}
else
{
*(strp++) = ' ';
*(strp++) = ' ';
}
if (j == 7)
*(strp++) = ' ';
}
*(strp++) = ' ';
*(strp2++) = '\n';
*(strp2) = '\0';
_assuan_debug (ctx, cat, fmt, func, tagname, tag, str);
}
}
diff --git a/src/debug.h b/src/debug.h
index 8d2771e..bd586c3 100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -1,275 +1,275 @@
/* debug.h - interface to debugging functions
Copyright (C) 2002, 2004, 2005, 2007 g10 Code GmbH
This file is part of Assuan.
Assuan is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
Assuan 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser 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. */
#ifndef DEBUG_H
#define DEBUG_H
#include <string.h>
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#include "assuan-defs.h"
/* Indirect stringification, requires __STDC__ to work. */
#define STRINGIFY(v) #v
#define XSTRINGIFY(v) STRINGIFY(v)
/* Remove path components from filenames (i.e. __FILE__) for cleaner
logs. */
-static inline const char *_assuan_debug_srcname (const char *file)
+static GPG_ERR_INLINE const char *_assuan_debug_srcname (const char *file)
ASSUAN_GCC_A_PURE;
-static inline const char *
+static GPG_ERR_INLINE const char *
_assuan_debug_srcname (const char *file)
{
const char *s = strrchr (file, '/');
return s ? s + 1 : file;
}
/* Called early to initialize the logging. */
void _assuan_debug_subsystem_init (void);
/* Log the formatted string FORMAT at debug level LEVEL or higher. */
void _assuan_debug (assuan_context_t ctx, unsigned int cat,
const char *format, ...);
/* Start a new debug line in *LINE, logged at level LEVEL or higher,
and starting with the formatted string FORMAT. */
void _assuan_debug_begin (assuan_context_t ctx,
void **helper, unsigned int cat,
const char *format, ...);
/* Add the formatted string FORMAT to the debug line *LINE. */
void _assuan_debug_add (assuan_context_t ctx,
void **helper, const char *format, ...);
/* Finish construction of *LINE and send it to the debug output
stream. */
void _assuan_debug_end (assuan_context_t ctx,
void **helper, unsigned int cat);
void _assuan_debug_buffer (assuan_context_t ctx, unsigned int cat,
const char *const fmt,
const char *const func, const char *const tagname,
void *tag, const char *const buffer, size_t len);
/* Trace support. */
#define _TRACE(ctx, lvl, name, tag) \
assuan_context_t _assuan_trace_context = ctx; \
int _assuan_trace_level = lvl; \
const char *const _assuan_trace_func = name; \
const char *const _assuan_trace_tagname = STRINGIFY (tag); \
void *_assuan_trace_tag = (void *) (uintptr_t) tag
#define TRACE_BEG(ctx,lvl, name, tag) \
_TRACE (ctx, lvl, name, tag); \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): enter\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag), 0
#define TRACE_BEG0(ctx, lvl, name, tag, fmt) \
_TRACE (ctx, lvl, name, tag); \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): enter: " fmt "\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag), 0
#define TRACE_BEG1(ctx, lvl, name, tag, fmt, arg1) \
_TRACE (ctx, lvl, name, tag); \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): enter: " fmt "\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag, arg1), 0
#define TRACE_BEG2(ctx, lvl, name, tag, fmt, arg1, arg2) \
_TRACE (ctx, lvl, name, tag); \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): enter: " fmt "\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag, arg1, arg2), 0
#define TRACE_BEG3(ctx, lvl, name, tag, fmt, arg1, arg2, arg3) \
_TRACE (ctx, lvl, name, tag); \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): enter: " fmt "\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag, arg1, arg2, arg3), 0
#define TRACE_BEG4(ctx, lvl, name, tag, fmt, arg1, arg2, arg3, arg4) \
_TRACE (ctx, lvl, name, tag); \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): enter: " fmt "\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag, arg1, arg2, arg3, arg4), 0
#define TRACE_BEG6(ctx, lvl, name, tag, fmt, arg1, arg2, arg3, arg4,arg5,arg6) \
_TRACE (ctx, lvl, name, tag); \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): enter: " fmt "\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag, arg1, arg2, arg3, arg4, arg5, arg6), 0
#define TRACE_BEG8(ctx, lvl, name, tag, fmt, arg1, arg2, arg3, arg4, \
arg5, arg6, arg7, arg8) \
_TRACE (ctx, lvl, name, tag); \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, "%s (%s=%p): enter: " fmt "\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag, arg1, arg2, arg3, arg4, \
arg5, arg6, arg7, arg8), 0
#define TRACE(ctx, lvl, name, tag) \
_assuan_debug (ctx, lvl, "%s (%s=%p): call\n", \
name, STRINGIFY (tag), (void *) (uintptr_t) tag), 0
#define TRACE0(ctx, lvl, name, tag, fmt) \
_assuan_debug (ctx, lvl, "%s (%s=%p): call: " fmt "\n", \
name, STRINGIFY (tag), (void *) (uintptr_t) tag), 0
#define TRACE1(ctx, lvl, name, tag, fmt, arg1) \
_assuan_debug (ctx, lvl, "%s (%s=%p): call: " fmt "\n", \
name, STRINGIFY (tag), (void *) (uintptr_t) tag, arg1), 0
#define TRACE2(ctx, lvl, name, tag, fmt, arg1, arg2) \
_assuan_debug (ctx, lvl, "%s (%s=%p): call: " fmt "\n", \
name, STRINGIFY (tag), (void *) (uintptr_t) tag, arg1, \
arg2), 0
#define TRACE3(ctx, lvl, name, tag, fmt, arg1, arg2, arg3) \
_assuan_debug (ctx, lvl, "%s (%s=%p): call: " fmt "\n", \
name, STRINGIFY (tag), (void *) (uintptr_t) tag, arg1, \
arg2, arg3), 0
#define TRACE4(ctx, lvl, name, tag, fmt, arg1, arg2, arg3, arg4) \
_assuan_debug (ctx, lvl, "%s (%s=%p): call: " fmt "\n", \
name, STRINGIFY (tag), (void *) (uintptr_t) tag, arg1, \
arg2, arg3, arg4), 0
#define TRACE6(ctx, lvl, name, tag, fmt, arg1, arg2, arg3, arg4, arg5, arg6) \
_assuan_debug (ctx, lvl, "%s (%s=%p): call: " fmt "\n", \
name, STRINGIFY (tag), (void *) (uintptr_t) tag, arg1, \
arg2, arg3, arg4, arg5, arg6), 0
#define TRACE_ERR(err) \
err == 0 ? (TRACE_SUC ()) : \
(_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): error: %s <%s>\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag, gpg_strerror (err), \
gpg_strsource (ctx->err_source)), \
_assuan_error (ctx, err))
/* The cast to void suppresses GCC warnings. */
#define TRACE_SYSRES(res) \
res >= 0 ? ((void) (TRACE_SUC1 ("result=%i", res)), (res)) : \
(_assuan_debug (_assuan_trace_context, _assuan_trace_level, "%s (%s=%p): error: %s\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag, strerror (errno)), (res))
#define TRACE_SYSERR(res) \
res == 0 ? ((void) (TRACE_SUC1 ("result=%i", res)), (res)) : \
(_assuan_debug (_assuan_trace_context, _assuan_trace_level, "%s (%s=%p): error: %s\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag, strerror (res)), (res))
#define TRACE_SUC() \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): leave\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag), 0
#define TRACE_SUC0(fmt) \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): leave: " fmt "\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag), 0
#define TRACE_SUC1(fmt, arg1) \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): leave: " fmt "\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag, arg1), 0
#define TRACE_SUC2(fmt, arg1, arg2) \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): leave: " fmt "\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag, arg1, arg2), 0
#define TRACE_SUC5(fmt, arg1, arg2, arg3, arg4, arg5) \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): leave: " fmt "\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag, arg1, arg2, arg3, arg4, arg5), 0
#define TRACE_LOG(fmt) \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): check: " fmt "\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag), 0
#define TRACE_LOG1(fmt, arg1) \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): check: " fmt "\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag, arg1), 0
#define TRACE_LOG2(fmt, arg1, arg2) \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): check: " fmt "\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag, arg1, arg2), 0
#define TRACE_LOG3(fmt, arg1, arg2, arg3) \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): check: " fmt "\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag, arg1, arg2, arg3), 0
#define TRACE_LOG4(fmt, arg1, arg2, arg3, arg4) \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): check: " fmt "\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag, arg1, arg2, arg3, arg4), 0
#define TRACE_LOG5(fmt, arg1, arg2, arg3, arg4, arg5) \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): check: " fmt "\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag, arg1, arg2, arg3, arg4, arg5), 0
#define TRACE_LOG6(fmt, arg1, arg2, arg3, arg4, arg5, arg6) \
_assuan_debug (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): check: " fmt "\n", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag, arg1, arg2, arg3, arg4, arg5, \
arg6), 0
#define TRACE_LOGBUF(buf, len) \
_assuan_debug_buffer (_assuan_trace_context, _assuan_trace_level, \
"%s (%s=%p): check: %s", \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag, buf, len)
#define TRACE_SEQ(hlp,fmt) \
_assuan_debug_begin (_assuan_trace_context, &(hlp), \
"%s (%s=%p): check: " fmt, \
_assuan_trace_func, _assuan_trace_tagname, \
_assuan_trace_tag)
#define TRACE_ADD0(hlp,fmt) \
_assuan_debug_add (_assuan_trace_context, &(hlp), fmt)
#define TRACE_ADD1(hlp,fmt,a) \
_assuan_debug_add (_assuan_trace_context, &(hlp), fmt, (a))
#define TRACE_ADD2(hlp,fmt,a,b) \
_assuan_debug_add (_assuan_trace_context, &(hlp), fmt, (a), (b))
#define TRACE_ADD3(hlp,fmt,a,b,c) \
_assuan_debug_add (_assuan_trace_context, &(hlp), fmt, (a), (b), (c))
#define TRACE_END(hlp,fmt) \
_assuan_debug_add (_assuan_trace_context, &(hlp), fmt); \
_assuan_debug_end (_assuan_trace_context, &(hlp), _assuan_trace_level)
#define TRACE_ENABLED(hlp) (!!(hlp))
#endif /* DEBUG_H */
diff --git a/src/mkheader.c b/src/mkheader.c
index 1b2e165..d44f6b4 100644
--- a/src/mkheader.c
+++ b/src/mkheader.c
@@ -1,235 +1,253 @@
/* mkheader.c - Create a header file for libassuan.
* Copyright (C) 2010 Free Software Foundation, Inc.
*
* This file is free software; as a special exception the author gives
* unlimited permission to copy and/or distribute it, with or without
* modifications, as long as this notice is preserved.
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define PGM "mkheader"
#define LINESIZE 1024
static const char *host_os;
static char *srcdir;
/* Include the file NAME form the source directory. The included file
is not further expanded. It may have comments indicated by a
double hash mark at the begin of a line. */
static void
include_file (const char *fname, int lnr, const char *name)
{
FILE *fp;
char *incfname;
char line[LINESIZE];
incfname = malloc (strlen (srcdir) + strlen (name) + 1);
if (!incfname)
{
fputs (PGM ": out of core\n", stderr);
exit (1);
}
strcpy (incfname, srcdir);
strcat (incfname, name);
fp = fopen (incfname, "r");
if (!fp)
{
fprintf (stderr, "%s:%d: error including `%s': %s\n",
fname, lnr, incfname, strerror (errno));
exit (1);
}
while (fgets (line, LINESIZE, fp))
{
if (line[0] == '#' && line[1] == '#')
{
if (!strncmp (line+2, "EOF##", 5))
break; /* Forced EOF. */
}
else
fputs (line, stdout);
}
if (ferror (fp))
{
fprintf (stderr, "%s:%d: error reading `%s': %s\n",
fname, lnr, incfname, strerror (errno));
exit (1);
}
fclose (fp);
free (incfname);
}
static int
write_special (const char *fname, int lnr, const char *tag)
{
if (!strcmp (tag, "include:includes"))
{
if (strstr (host_os, "mingw32"))
include_file (fname, lnr, "w32-includes.inc.h");
else
include_file (fname, lnr, "posix-includes.inc.h");
}
+ else if (!strcmp (tag, "include:sys/types.h"))
+ {
+ if (!strcmp (host_os, "mingw32ce"))
+ fputs ("#ifdef __MINGW32CE__\n"
+ "# include <sys/types.h>\n"
+ "#endif\n", stdout);
+ else
+ fputs ("#include <sys/types.h>\n", stdout);
+ }
+ else if (!strcmp (tag, "include:unistd.h"))
+ {
+ if (!strcmp (host_os, "mingw32ce"))
+ fputs ("#ifdef __MINGW32CE__\n"
+ "# include <unistd.h>\n"
+ "#endif\n", stdout);
+ else
+ fputs ("#include <unistd.h>\n", stdout);
+ }
else if (!strcmp (tag, "include:types"))
{
if (strstr (host_os, "mingw32"))
include_file (fname, lnr, "w32-types.inc.h");
else
include_file (fname, lnr, "posix-types.inc.h");
}
else if (!strcmp (tag, "include:fd-t"))
{
if (!strcmp (host_os, "mingw32ce"))
include_file (fname, lnr, "w32ce-fd-t.inc.h");
else if (strstr (host_os, "mingw32"))
include_file (fname, lnr, "w32-fd-t.inc.h");
else
include_file (fname, lnr, "posix-fd-t.inc.h");
}
else if (!strcmp (tag, "include:sock-nonce"))
{
if (strstr (host_os, "mingw32"))
include_file (fname, lnr, "w32-sock-nonce.inc.h");
else
include_file (fname, lnr, "posix-sock-nonce.inc.h");
}
else if (!strcmp (tag, "include:sys-pth-impl"))
{
if (strstr (host_os, "mingw32"))
include_file (fname, lnr, "w32-sys-pth-impl.h");
else
include_file (fname, lnr, "posix-sys-pth-impl.h");
}
else if (!strcmp (tag, "include:w32ce-add"))
{
if (!strcmp (host_os, "mingw32ce"))
include_file (fname, lnr, "w32ce-add.h");
}
else
return 0; /* Unknown tag. */
return 1; /* Tag processed. */
}
int
main (int argc, char **argv)
{
FILE *fp;
char line[LINESIZE];
int lnr = 0;
const char *fname, *s;
char *p1, *p2;
if (argc)
{
argc--; argv++;
}
if (argc != 2)
{
fputs ("usage: " PGM " host_os template.h\n", stderr);
return 1;
}
host_os = argv[0];
fname = argv[1];
srcdir = malloc (strlen (fname) + 2 + 1);
if (!srcdir)
{
fputs (PGM ": out of core\n", stderr);
return 1;
}
strcpy (srcdir, fname);
p1 = strrchr (srcdir, '/');
if (p1)
p1[1] = 0;
else
strcpy (srcdir, "./");
fp = fopen (fname, "r");
if (!fp)
{
fprintf (stderr, "%s:%d: can't open file: %s",
fname, lnr, strerror (errno));
return 1;
}
while (fgets (line, LINESIZE, fp))
{
size_t n = strlen (line);
lnr++;
if (!n || line[n-1] != '\n')
{
fprintf (stderr,
"%s:%d: trailing linefeed missing, line too long or "
"embedded Nul character", fname, lnr);
break;
}
line[--n] = 0;
p1 = strchr (line, '@');
p2 = p1? strchr (p1+1, '@') : NULL;
if (!p1 || !p2 || p2-p1 == 1)
{
puts (line);
continue;
}
*p1++ = 0;
*p2++ = 0;
fputs (line, stdout);
if (!strcmp (p1, "configure_input"))
{
s = strrchr (fname, '/');
printf ("Do not edit. Generated from %s by %s for %s.",
s? s+1 : fname, PGM, host_os);
fputs (p2, stdout);
putchar ('\n');
}
else if (!write_special (fname, lnr, p1))
{
putchar ('@');
fputs (p1, stdout);
putchar ('@');
fputs (p2, stdout);
putchar ('\n');
}
}
if (ferror (fp))
{
fprintf (stderr, "%s:%d: error reading file: %s\n",
fname, lnr, strerror (errno));
return 1;
}
fputs ("/*\n"
"Loc" "al Variables:\n"
"buffer-read-only: t\n"
"End:\n"
"*/\n", stdout);
if (ferror (stdout))
{
fprintf (stderr, PGM ": error writing stdout: %s\n", strerror (errno));
return 1;
}
fclose (fp);
return 0;
}
diff --git a/src/posix-fd-t.inc.h b/src/posix-fd-t.inc.h
index 35bf5ae..80aa5f0 100644
--- a/src/posix-fd-t.inc.h
+++ b/src/posix-fd-t.inc.h
@@ -1,32 +1,32 @@
## posix-fd-t.inc.h - Include fragment to build assuan.h.
## Copyright (C) 2010 Free Software Foundation, Inc.
##
## This file is part of Assuan.
##
## Assuan is free software; you can redistribute it and/or modify it
## under the terms of the GNU Lesser General Public License as
## published by the Free Software Foundation; either version 2.1 of
## the License, or (at your option) any later version.
##
## Assuan 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
## Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public
## License along with this program; if not, see <http://www.gnu.org/licenses/>.
##
##
## This file is included by the mkheader tool. Lines starting with
## a double hash mark are not copied to the destination file.
typedef int assuan_fd_t;
#define ASSUAN_INVALID_FD (-1)
#define ASSUAN_INVALID_PID ((pid_t) -1)
-static inline assuan_fd_t
+static GPG_ERR_INLINE assuan_fd_t
assuan_fd_from_posix_fd (int fd)
{
return fd;
}
##EOF##
diff --git a/src/system-w32ce.c b/src/system-w32ce.c
index c201c47..3061f45 100644
--- a/src/system-w32ce.c
+++ b/src/system-w32ce.c
@@ -1,676 +1,679 @@
/* system-w32ce.c - System support functions for WindowsCE.
Copyright (C) 2010 Free Software Foundation, Inc.
This file is part of Assuan.
Assuan is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
Assuan 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <fcntl.h>
+# ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+# endif
#include <windows.h>
#include <winioctl.h>
#include <devload.h>
#include "assuan-defs.h"
#include "debug.h"
#define GPGCEDEV_IOCTL_GET_RVID \
CTL_CODE (FILE_DEVICE_STREAMS, 2048, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define GPGCEDEV_IOCTL_MAKE_PIPE \
CTL_CODE (FILE_DEVICE_STREAMS, 2049, METHOD_BUFFERED, FILE_ANY_ACCESS)
static wchar_t *
utf8_to_wchar (const char *string)
{
int n;
size_t nbytes;
wchar_t *result;
if (!string)
return NULL;
n = MultiByteToWideChar (CP_UTF8, 0, string, -1, NULL, 0);
if (n < 0)
{
gpg_err_set_errno (EINVAL);
return NULL;
}
nbytes = (size_t)(n+1) * sizeof(*result);
if (nbytes / sizeof(*result) != (n+1))
{
gpg_err_set_errno (ENOMEM);
return NULL;
}
result = malloc (nbytes);
if (!result)
return NULL;
n = MultiByteToWideChar (CP_UTF8, 0, string, -1, result, n);
if (n < 0)
{
free (result);
gpg_err_set_errno (EINVAL);
result = NULL;
}
return result;
}
/* Convenience function. */
static void
free_wchar (wchar_t *string)
{
if (string)
free (string);
}
assuan_fd_t
assuan_fdopen (int fd)
{
return (assuan_fd_t)fd;
}
/* Sleep for the given number of microseconds. Default
implementation. */
void
__assuan_usleep (assuan_context_t ctx, unsigned int usec)
{
if (usec)
Sleep (usec / 1000);
}
/* Prepare a pipe. Returns a handle which is, depending on WRITE_END,
will either act the read or as the write end of the pipe. The
other value returned is a rendezvous id used to complete the pipe
creation with _assuan_w32ce_finish_pipe. The rendezvous id may be
passed to another process and that process may finish the pipe
creation. This creates the interprocess pipe. The rendezvous id
is not a handle but a plain number; there is no release function
and care should be taken not to pass it to a function expecting a
handle. */
HANDLE
_assuan_w32ce_prepare_pipe (int *r_rvid, int write_end)
{
HANDLE hd;
LONG rvid;
ActivateDevice (L"Drivers\\GnuPG_Device", 0);
/* Note: Using "\\$device\\GPG1" should be identical to "GPG1:".
However this returns an invalid parameter error without having
called GPG_Init in the driver. The docs mention something about
RegisterAFXEx but that API is not documented. */
hd = CreateFile (L"GPG1:", write_end? GENERIC_WRITE : GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hd != INVALID_HANDLE_VALUE)
{
if (!DeviceIoControl (hd, GPGCEDEV_IOCTL_GET_RVID,
NULL, 0, &rvid, sizeof rvid, NULL, NULL))
{
DWORD lastrc = GetLastError ();
CloseHandle (hd);
hd = INVALID_HANDLE_VALUE;
SetLastError (lastrc);
}
else
*r_rvid = rvid;
}
return hd;
}
/* Create a pipe. WRITE_END shall have the opposite value of the one
pssed to _assuan_w32ce_prepare_pipe; see there for more
details. */
HANDLE
_assuan_w32ce_finish_pipe (int rvid, int write_end)
{
HANDLE hd;
if (!rvid)
{
SetLastError (ERROR_INVALID_HANDLE);
return INVALID_HANDLE_VALUE;
}
hd = CreateFile (L"GPG1:", write_end? GENERIC_WRITE : GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);
if (hd != INVALID_HANDLE_VALUE)
{
if (!DeviceIoControl (hd, GPGCEDEV_IOCTL_MAKE_PIPE,
&rvid, sizeof rvid, NULL, 0, NULL, NULL))
{
DWORD lastrc = GetLastError ();
CloseHandle (hd);
hd = INVALID_HANDLE_VALUE;
SetLastError (lastrc);
}
}
return hd;
}
/* WindowsCE does not provide a pipe feature. However we need
something like a pipe to convey data between processes and in some
cases within a process. This replacement is not only used by
libassuan but exported and thus usable by gnupg and gpgme as well. */
DWORD
_assuan_w32ce_create_pipe (HANDLE *read_hd, HANDLE *write_hd,
LPSECURITY_ATTRIBUTES sec_attr, DWORD size)
{
HANDLE hd[2] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE};
int rvid;
int rc = 0;
hd[0] = _assuan_w32ce_prepare_pipe (&rvid, 0);
if (hd[0] != INVALID_HANDLE_VALUE)
{
hd[1] = _assuan_w32ce_finish_pipe (rvid, 1);
if (hd[1] != INVALID_HANDLE_VALUE)
rc = 1;
else
{
DWORD lastrc = GetLastError ();
CloseHandle (hd[0]);
hd[0] = INVALID_HANDLE_VALUE;
SetLastError (lastrc);
}
}
*read_hd = hd[0];
*write_hd = hd[1];
return rc;
}
/* Create a pipe with one inheritable end. Default implementation.
If INHERIT_IDX is 0, the read end of the pipe is made inheritable;
with INHERIT_IDX is 1 the write end will be inheritable. The
question now is how we create an inheritable pipe end under windows
CE were handles are process local objects? The trick we employ is
to defer the actual creation to the other end: We create an
incomplete pipe and pass a rendezvous id to the other end
(process). The other end now uses the rendezvous id to lookup the
pipe in our device driver, creates a new handle and uses that one
to finally establish the pipe. */
int
__assuan_pipe (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx)
{
HANDLE hd;
int rvid;
hd = _assuan_w32ce_prepare_pipe (&rvid, !inherit_idx);
if (hd == INVALID_HANDLE_VALUE)
{
TRACE1 (ctx, ASSUAN_LOG_SYSIO, "__assuan_pipe", ctx,
"CreatePipe failed: %s", _assuan_w32_strerror (ctx, -1));
gpg_err_set_errno (EIO);
return -1;
}
if (inherit_idx)
{
fd[0] = hd;
fd[1] = (void*)rvid;
}
else
{
fd[0] = (void*)rvid;
fd[1] = hd;
}
return 0;
}
/* Close the given file descriptor, created with _assuan_pipe or one
of the socket functions. Default implementation. */
int
__assuan_close (assuan_context_t ctx, assuan_fd_t fd)
{
int rc = closesocket (HANDLE2SOCKET(fd));
int err = WSAGetLastError ();
/* Note that gpg_err_set_errno on Windows CE overwrites
WSAGetLastError() (via SetLastError()). */
if (rc)
gpg_err_set_errno (_assuan_sock_wsa2errno (err));
if (rc && err == WSAENOTSOCK)
{
rc = CloseHandle (fd);
if (rc)
/* FIXME. */
gpg_err_set_errno (EIO);
}
return rc;
}
static ssize_t
__assuan_read (assuan_context_t ctx, assuan_fd_t fd, void *buffer, size_t size)
{
/* Due to the peculiarities of the W32 API we can't use read for a
network socket and thus we try to use recv first and fallback to
read if recv detects that it is not a network socket. */
int res;
TRACE_BEG3 (ctx, ASSUAN_LOG_SYSIO, "__assuan_read", ctx,
"fd=0x%x, buffer=%p, size=%i", fd, buffer, size);
#ifdef HAVE_W32CE_SYSTEM
/* This is a bit of a hack to support stdin over ssh. Note that
fread buffers fully while getchar is line buffered. Weird, but
that's the way it is. ASSUAN_STDIN and ASSUAN_STDOUT are
special handle values that shouldn't occur in the wild. */
if (fd == ASSUAN_STDIN)
{
int i = 0;
int chr;
while (i < size)
{
chr = getchar();
if (chr == EOF)
break;
((char*)buffer)[i++] = (char) chr;
if (chr == '\n')
break;
}
return TRACE_SYSRES (i);
}
#endif
res = recv (HANDLE2SOCKET (fd), buffer, size, 0);
if (res == -1)
{
TRACE_LOG1 ("recv failed: rc=%d", (int)WSAGetLastError ());
switch (WSAGetLastError ())
{
case WSAENOTSOCK:
{
DWORD nread = 0;
res = ReadFile (fd, buffer, size, &nread, NULL);
if (! res)
{
TRACE_LOG1 ("ReadFile failed: rc=%d", (int)GetLastError ());
switch (GetLastError ())
{
case ERROR_BROKEN_PIPE:
gpg_err_set_errno (EPIPE);
break;
case ERROR_PIPE_NOT_CONNECTED:
case ERROR_BUSY:
gpg_err_set_errno (EAGAIN);
break;
default:
gpg_err_set_errno (EIO);
}
res = -1;
}
else
res = (int) nread;
}
break;
case WSAEWOULDBLOCK:
gpg_err_set_errno (EAGAIN);
break;
case ERROR_BROKEN_PIPE:
gpg_err_set_errno (EPIPE);
break;
default:
gpg_err_set_errno (EIO);
break;
}
}
return TRACE_SYSRES (res);
}
static ssize_t
__assuan_write (assuan_context_t ctx, assuan_fd_t fd, const void *buffer,
size_t size)
{
/* Due to the peculiarities of the W32 API we can't use write for a
network socket and thus we try to use send first and fallback to
write if send detects that it is not a network socket. */
int res;
TRACE_BEG3 (ctx, ASSUAN_LOG_SYSIO, "__assuan_write", ctx,
"fd=0x%x, buffer=%p, size=%i", fd, buffer, size);
#ifdef HAVE_W32CE_SYSTEM
/* This is a bit of a hack to support stdout over ssh. Note that
fread buffers fully while getchar is line buffered. Weird, but
that's the way it is. ASSUAN_STDIN and ASSUAN_STDOUT are
special handle values that shouldn't occur in the wild. */
if (fd == ASSUAN_STDOUT)
{
res = fwrite (buffer, 1, size, stdout);
return TRACE_SYSRES (res);
}
#endif
res = send ((int)fd, buffer, size, 0);
if (res == -1 && WSAGetLastError () == WSAENOTSOCK)
{
DWORD nwrite;
TRACE_LOG ("send call failed - trying WriteFile");
res = WriteFile (fd, buffer, size, &nwrite, NULL);
if (! res)
{
TRACE_LOG1 ("WriteFile failed: rc=%d", (int)GetLastError ());
switch (GetLastError ())
{
case ERROR_BROKEN_PIPE:
case ERROR_NO_DATA:
gpg_err_set_errno (EPIPE);
break;
case ERROR_PIPE_NOT_CONNECTED:
case ERROR_BUSY:
gpg_err_set_errno (EAGAIN);
break;
default:
gpg_err_set_errno (EIO);
break;
}
res = -1;
}
else
res = (int) nwrite;
}
else if (res == -1)
TRACE_LOG1 ("send call failed: rc=%d", (int)GetLastError ());
return TRACE_SYSRES (res);
}
static int
__assuan_recvmsg (assuan_context_t ctx, assuan_fd_t fd, assuan_msghdr_t msg,
int flags)
{
gpg_err_set_errno (ENOSYS);
return -1;
}
static int
__assuan_sendmsg (assuan_context_t ctx, assuan_fd_t fd, assuan_msghdr_t msg,
int flags)
{
gpg_err_set_errno (ENOSYS);
return -1;
}
/* Build a command line for use with W32's CreateProcess. On success
CMDLINE gets the address of a newly allocated string. */
static int
build_w32_commandline (assuan_context_t ctx, const char * const *argv,
assuan_fd_t fd0, assuan_fd_t fd1, assuan_fd_t fd2,
int fd2_isnull,
char **cmdline)
{
int i, n;
const char *s;
char *buf, *p;
char fdbuf[3*30];
p = fdbuf;
*p = 0;
if (fd0 != ASSUAN_INVALID_FD)
{
snprintf (p, 25, "-&S0=%d ", (int)fd0);
p += strlen (p);
}
if (fd1 != ASSUAN_INVALID_FD)
{
snprintf (p, 25, "-&S1=%d ", (int)fd1);
p += strlen (p);
}
if (fd2 != ASSUAN_INVALID_FD)
{
if (fd2_isnull)
strcpy (p, "-&S2=null ");
else
snprintf (p, 25, "-&S2=%d ", (int)fd2);
p += strlen (p);
}
*cmdline = NULL;
n = strlen (fdbuf);
for (i=0; (s = argv[i]); i++)
{
if (!i)
continue; /* Ignore argv[0]. */
n += strlen (s) + 1 + 2; /* (1 space, 2 quoting) */
for (; *s; s++)
if (*s == '\"')
n++; /* Need to double inner quotes. */
}
n++;
buf = p = _assuan_malloc (ctx, n);
if (! buf)
return -1;
p = stpcpy (p, fdbuf);
for (i = 0; argv[i]; i++)
{
if (!i)
continue; /* Ignore argv[0]. */
if (i > 1)
p = stpcpy (p, " ");
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 (p, argv[i]);
}
*cmdline = buf;
return 0;
}
int
__assuan_spawn (assuan_context_t ctx, pid_t *r_pid, const char *name,
const char **argv,
assuan_fd_t fd_in, assuan_fd_t fd_out,
assuan_fd_t *fd_child_list,
void (*atfork) (void *opaque, int reserved),
void *atforkvalue, unsigned int flags)
{
PROCESS_INFORMATION pi =
{
NULL, /* Returns process handle. */
0, /* Returns primary thread handle. */
0, /* Returns pid. */
0 /* Returns tid. */
};
assuan_fd_t fd;
assuan_fd_t *fdp;
assuan_fd_t fd_err;
int fd_err_isnull = 0;
char *cmdline;
/* Dup stderr to /dev/null unless it is in the list of FDs to be
passed to the child. Well we don't actually open nul because
that is not available on Windows, but use our hack for it.
Because an RVID of 0 is an invalid value and HANDLES will never
have this value either, we test for this as well. */
/* FIXME: As long as we can't decide whether a handle is a real
handler or an rendezvous id we can't do anything with the
FD_CHILD_LIST. We can't do much with stderr either, thus we
better don't pass stderr to the child at all. If we would do so
and it is not a rendezvous id the client would run into
problems. */
fd = assuan_fd_from_posix_fd (fileno (stderr));
fdp = fd_child_list;
if (fdp)
{
for (; *fdp != ASSUAN_INVALID_FD && *fdp != 0 && *fdp != fd; fdp++)
;
}
if (!fdp || *fdp == ASSUAN_INVALID_FD)
fd_err_isnull = 1;
fd_err = ASSUAN_INVALID_FD;
if (build_w32_commandline (ctx, argv, fd_in, fd_out, fd_err, fd_err_isnull,
&cmdline))
{
return -1;
}
TRACE2 (ctx, ASSUAN_LOG_SYSIO, "__assuan_spawn", ctx,
"path=`%s' cmdline=`%s'", name, cmdline);
{
wchar_t *wcmdline, *wname;
wcmdline = utf8_to_wchar (cmdline);
_assuan_free (ctx, cmdline);
if (!wcmdline)
return -1;
wname = utf8_to_wchar (name);
if (!wname)
{
free_wchar (wcmdline);
return -1;
}
if (!CreateProcess (wname, /* Program to start. */
wcmdline, /* Command line arguments. */
NULL, /* (not supported) */
NULL, /* (not supported) */
FALSE, /* (not supported) */
(CREATE_SUSPENDED), /* Creation flags. */
NULL, /* (not supported) */
NULL, /* (not supported) */
NULL, /* (not supported) */
&pi /* Returns process information.*/
))
{
TRACE1 (ctx, ASSUAN_LOG_SYSIO, "__assuan_spawn", ctx,
"CreateProcess failed: %s", _assuan_w32_strerror (ctx, -1));
free_wchar (wname);
free_wchar (wcmdline);
gpg_err_set_errno (EIO);
return -1;
}
free_wchar (wname);
free_wchar (wcmdline);
}
ResumeThread (pi.hThread);
TRACE4 (ctx, ASSUAN_LOG_SYSIO, "__assuan_spawn", ctx,
"CreateProcess ready: hProcess=%p hThread=%p"
" dwProcessID=%d dwThreadId=%d\n",
pi.hProcess, pi.hThread, (int) pi.dwProcessId, (int) pi.dwThreadId);
CloseHandle (pi.hThread);
*r_pid = (pid_t) pi.hProcess;
return 0;
}
static pid_t
__assuan_waitpid (assuan_context_t ctx, pid_t pid, int nowait,
int *status, int options)
{
CloseHandle ((HANDLE) pid);
return 0;
}
int
__assuan_socketpair (assuan_context_t ctx, int namespace, int style,
int protocol, assuan_fd_t filedes[2])
{
gpg_err_set_errno (ENOSYS);
return -1;
}
/* The default system hooks for assuan contexts. */
struct assuan_system_hooks _assuan_system_hooks =
{
ASSUAN_SYSTEM_HOOKS_VERSION,
__assuan_usleep,
__assuan_pipe,
__assuan_close,
__assuan_read,
__assuan_write,
__assuan_recvmsg,
__assuan_sendmsg,
__assuan_spawn,
__assuan_waitpid,
__assuan_socketpair
};
diff --git a/src/system.c b/src/system.c
index 779b567..1c7d617 100644
--- a/src/system.c
+++ b/src/system.c
@@ -1,383 +1,385 @@
/* system.c - System support functions.
Copyright (C) 2009 Free Software Foundation, Inc.
This file is part of Assuan.
Assuan is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
Assuan 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <errno.h>
-/* Solaris 8 needs sys/types.h before time.h. */
-#include <sys/types.h>
+#ifdef HAVE_SYS_TYPES_H
+ /* Solaris 8 needs sys/types.h before time.h. */
+# include <sys/types.h>
+#endif
#include <time.h>
#include <fcntl.h>
#include "assuan-defs.h"
#include "debug.h"
#ifdef _POSIX_OPEN_MAX
#define MAX_OPEN_FDS _POSIX_OPEN_MAX
#else
#define MAX_OPEN_FDS 20
#endif
#define DEBUG_SYSIO 0
/* Manage memory specific to a context. */
void *
_assuan_malloc (assuan_context_t ctx, size_t cnt)
{
return ctx->malloc_hooks.malloc (cnt);
}
void *
_assuan_realloc (assuan_context_t ctx, void *ptr, size_t cnt)
{
return ctx->malloc_hooks.realloc (ptr, cnt);
}
void *
_assuan_calloc (assuan_context_t ctx, size_t cnt, size_t elsize)
{
void *ptr;
size_t nbytes;
nbytes = cnt * elsize;
/* Check for overflow. */
if (elsize && nbytes / elsize != cnt)
{
gpg_err_set_errno (ENOMEM);
return NULL;
}
ptr = ctx->malloc_hooks.malloc (nbytes);
if (ptr)
memset (ptr, 0, nbytes);
return ptr;
}
void
_assuan_free (assuan_context_t ctx, void *ptr)
{
if (ptr)
ctx->malloc_hooks.free (ptr);
}
/* Release the memory at PTR using the allocation handler of the
context CTX. This is a convenience function. */
void
assuan_free (assuan_context_t ctx, void *ptr)
{
_assuan_free (ctx, ptr);
}
/* Copy the system hooks struct, paying attention to version
differences. SRC is usually from the user, DST MUST be from the
library. */
void
_assuan_system_hooks_copy (assuan_system_hooks_t dst,
assuan_system_hooks_t src)
{
memset (dst, '\0', sizeof (*dst));
dst->version = ASSUAN_SYSTEM_HOOKS_VERSION;
if (src->version >= 1)
{
dst->usleep = src->usleep;
dst->pipe = src->pipe;
dst->close = src->close;
dst->read = src->read;
dst->write = src->write;
dst->sendmsg = src->sendmsg;
dst->recvmsg = src->recvmsg;
dst->spawn = src->spawn;
dst->waitpid = src->waitpid;
dst->socketpair = src->socketpair;
}
if (src->version > 1)
/* FIXME. Application uses newer version of the library. What to
do? */
;
}
/* Sleep for the given number of microseconds. */
void
_assuan_usleep (assuan_context_t ctx, unsigned int usec)
{
TRACE1 (ctx, ASSUAN_LOG_SYSIO, "_assuan_usleep", ctx,
"usec=%u", usec);
(ctx->system.usleep) (ctx, usec);
}
/* Create a pipe with one inheritable end. */
int
_assuan_pipe (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx)
{
int err;
TRACE_BEG2 (ctx, ASSUAN_LOG_SYSIO, "_assuan_pipe", ctx,
"inherit_idx=%i (Assuan uses it for %s)",
inherit_idx, inherit_idx ? "reading" : "writing");
err = (ctx->system.pipe) (ctx, fd, inherit_idx);
if (err)
return TRACE_SYSRES (err);
return TRACE_SUC2 ("read=0x%x, write=0x%x", fd[0], fd[1]);
}
/* Close the given file descriptor, created with _assuan_pipe or one
of the socket functions. */
int
_assuan_close (assuan_context_t ctx, assuan_fd_t fd)
{
TRACE1 (ctx, ASSUAN_LOG_SYSIO, "_assuan_close", ctx,
"fd=0x%x", fd);
return (ctx->system.close) (ctx, fd);
}
/* Same as assuan_close but used for the inheritable end of a
pipe. */
int
_assuan_close_inheritable (assuan_context_t ctx, assuan_fd_t fd)
{
TRACE1 (ctx, ASSUAN_LOG_SYSIO, "_assuan_close_inheritable", ctx,
"fd=0x%x", fd);
#ifdef HAVE_W32CE_SYSTEM
return 0; /* Nothing to do because it is a rendezvous id. */
#else
return (ctx->system.close) (ctx, fd);
#endif
}
ssize_t
_assuan_read (assuan_context_t ctx, assuan_fd_t fd, void *buffer, size_t size)
{
#if DEBUG_SYSIO
ssize_t res;
TRACE_BEG3 (ctx, ASSUAN_LOG_SYSIO, "_assuan_read", ctx,
"fd=0x%x, buffer=%p, size=%i", fd, buffer, size);
res = (ctx->system.read) (ctx, fd, buffer, size);
return TRACE_SYSRES (res);
#else
return (ctx->system.read) (ctx, fd, buffer, size);
#endif
}
ssize_t
_assuan_write (assuan_context_t ctx, assuan_fd_t fd, const void *buffer,
size_t size)
{
#if DEBUG_SYSIO
ssize_t res;
TRACE_BEG3 (ctx, ASSUAN_LOG_SYSIO, "_assuan_write", ctx,
"fd=0x%x, buffer=%p, size=%i", fd, buffer, size);
res = (ctx->system.write) (ctx, fd, buffer, size);
return TRACE_SYSRES (res);
#else
return (ctx->system.write) (ctx, fd, buffer, size);
#endif
}
int
_assuan_recvmsg (assuan_context_t ctx, assuan_fd_t fd, assuan_msghdr_t msg,
int flags)
{
#if DEBUG_SYSIO
ssize_t res;
TRACE_BEG3 (ctx, ASSUAN_LOG_SYSIO, "_assuan_recvmsg", ctx,
"fd=0x%x, msg=%p, flags=0x%x", fd, msg, flags);
res = (ctx->system.recvmsg) (ctx, fd, msg, flags);
if (res > 0)
{
struct cmsghdr *cmptr;
TRACE_LOG2 ("msg->msg_iov[0] = { iov_base=%p, iov_len=%i }",
msg->msg_iov[0].iov_base, msg->msg_iov[0].iov_len);
TRACE_LOGBUF (msg->msg_iov[0].iov_base, res);
cmptr = CMSG_FIRSTHDR (msg);
if (cmptr)
{
void *data = CMSG_DATA (cmptr);
TRACE_LOG5 ("cmsg_len=0x%x (0x%x data), cmsg_level=0x%x, "
"cmsg_type=0x%x, first data int=0x%x", cmptr->cmsg_len,
cmptr->cmsg_len - (((char *)data) - ((char *)cmptr)),
cmptr->cmsg_level, cmptr->cmsg_type, *(int *)data);
}
}
return TRACE_SYSRES (res);
#else
return (ctx->system.recvmsg) (ctx, fd, msg, flags);
#endif
}
int
_assuan_sendmsg (assuan_context_t ctx, assuan_fd_t fd, assuan_msghdr_t msg,
int flags)
{
#if DEBUG_SYSIO
ssize_t res;
TRACE_BEG3 (ctx, ASSUAN_LOG_SYSIO, "_assuan_sendmsg", ctx,
"fd=0x%x, msg=%p, flags=0x%x", fd, msg, flags);
{
struct cmsghdr *cmptr;
TRACE_LOG2 ("msg->iov[0] = { iov_base=%p, iov_len=%i }",
msg->msg_iov[0].iov_base, msg->msg_iov[0].iov_len);
TRACE_LOGBUF (msg->msg_iov[0].iov_base, msg->msg_iov[0].iov_len);
cmptr = CMSG_FIRSTHDR (msg);
if (cmptr)
{
void *data = CMSG_DATA (cmptr);
TRACE_LOG5 ("cmsg_len=0x%x (0x%x data), cmsg_level=0x%x, "
"cmsg_type=0x%x, first data int=0x%x", cmptr->cmsg_len,
cmptr->cmsg_len - (((char *)data) - ((char *)cmptr)),
cmptr->cmsg_level, cmptr->cmsg_type, *(int *)data);
}
}
res = (ctx->system.sendmsg) (ctx, fd, msg, flags);
return TRACE_SYSRES (res);
#else
return (ctx->system.sendmsg) (ctx, fd, msg, flags);
#endif
}
/* Create a new process from NAME and ARGV. Provide FD_IN and FD_OUT
as stdin and stdout. Inherit the ASSUAN_INVALID_FD-terminated
FD_CHILD_LIST as given (no remapping), which must be inheritable.
On Unix, call ATFORK with ATFORKVALUE after fork and before exec. */
int
_assuan_spawn (assuan_context_t ctx, pid_t *r_pid, const char *name,
const char **argv,
assuan_fd_t fd_in, assuan_fd_t fd_out,
assuan_fd_t *fd_child_list,
void (*atfork) (void *opaque, int reserved),
void *atforkvalue, unsigned int flags)
{
int res;
int i;
TRACE_BEG6 (ctx, ASSUAN_LOG_CTX, "_assuan_spawn", ctx,
"name=%s,fd_in=0x%x,fd_out=0x%x,"
"atfork=%p,atforkvalue=%p,flags=%i",
name ? name : "(null)", fd_in, fd_out,
atfork, atforkvalue, flags);
if (name)
{
i = 0;
while (argv[i])
{
TRACE_LOG2 ("argv[%2i] = %s", i, argv[i]);
i++;
}
}
i = 0;
if (fd_child_list)
{
while (fd_child_list[i] != ASSUAN_INVALID_FD)
{
TRACE_LOG2 ("fd_child_list[%2i] = 0x%x", i, fd_child_list[i]);
i++;
}
}
res = (ctx->system.spawn) (ctx, r_pid, name, argv, fd_in, fd_out,
fd_child_list, atfork, atforkvalue, flags);
if (name)
{
TRACE_LOG1 ("pid = 0x%x", *r_pid);
}
else
{
TRACE_LOG2 ("pid = 0x%x (%s)", *r_pid, *argv);
}
return TRACE_SYSERR (res);
}
/* FIXME: Add some sort of waitpid function that covers GPGME and
gpg-agent's use of assuan. */
pid_t
_assuan_waitpid (assuan_context_t ctx, pid_t pid, int action,
int *status, int options)
{
#if DEBUG_SYSIO
ssize_t res;
TRACE_BEG4 (ctx, ASSUAN_LOG_SYSIO, "_assuan_waitpid", ctx,
"pid=%i, action=%i, status=%p, options=%i",
pid, action, status, options);
res = (ctx->system.waitpid) (ctx, pid, action, status, options);
return TRACE_SYSRES (res);
#else
return (ctx->system.waitpid) (ctx, pid, action, status, options);
#endif
}
int
_assuan_socketpair (assuan_context_t ctx, int namespace, int style,
int protocol, assuan_fd_t filedes[2])
{
int res;
TRACE_BEG4 (ctx, ASSUAN_LOG_SYSIO, "_assuan_socketpair", ctx,
"namespace=%i,style=%i,protocol=%i,filedes=%p",
namespace, style, protocol, filedes);
res = (ctx->system.socketpair) (ctx, namespace, style, protocol, filedes);
if (res == 0)
TRACE_LOG2 ("filedes = { 0x%x, 0x%x }", filedes[0], filedes[1]);
return TRACE_SYSERR (res);
}
diff --git a/src/sysutils.c b/src/sysutils.c
index 1760f44..578e47d 100644
--- a/src/sysutils.c
+++ b/src/sysutils.c
@@ -1,135 +1,137 @@
/* sysutils.c - System utilities
Copyright (C) 2010 Free Software Foundation, Inc.
This file is part of Assuan.
Assuan is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
Assuan 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#ifdef HAVE_W32_SYSTEM
-#include <windows.h>
+# ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+# endif
+# include <windows.h>
# ifdef HAVE_W32CE_SYSTEM
# include <winioctl.h>
-# include <devload.h>
# endif /*HAVE_W32CE_SYSTEM*/
#endif /*HAVE_W32_SYSTEM*/
#include "assuan-defs.h"
/* This is actually a dummy function to make sure that is module is
not empty. Some compilers barf on empty modules. */
const char *
_assuan_sysutils_blurb (void)
{
static const char blurb[] =
"\n\n"
"This is Libassuan - The GnuPG IPC Library\n"
"Copyright 2000, 2002, 2003, 2004, 2007, 2008, 2009,\n"
" 2010 Free Software Foundation, Inc.\n"
"\n\n";
return blurb;
}
/* Return a string from the Win32 Registry or NULL in case of error.
The returned string is allocated using a plain malloc and thus the
caller needs to call the standard free(). The string is looked up
under HKEY_LOCAL_MACHINE. */
#ifdef HAVE_W32CE_SYSTEM
static char *
w32_read_registry (const wchar_t *dir, const wchar_t *name)
{
HKEY handle;
DWORD n, nbytes;
wchar_t *buffer = NULL;
char *result = NULL;
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, dir, 0, KEY_READ, &handle))
return NULL; /* No need for a RegClose, so return immediately. */
nbytes = 1;
if (RegQueryValueEx (handle, name, 0, NULL, NULL, &nbytes))
goto leave;
buffer = malloc ((n=nbytes+2));
if (!buffer)
goto leave;
if (RegQueryValueEx (handle, name, 0, NULL, (PBYTE)buffer, &n))
{
free (buffer);
buffer = NULL;
goto leave;
}
n = WideCharToMultiByte (CP_UTF8, 0, buffer, nbytes, NULL, 0, NULL, NULL);
if (n < 0 || (n+1) <= 0)
goto leave;
result = malloc (n+1);
if (!result)
goto leave;
n = WideCharToMultiByte (CP_UTF8, 0, buffer, nbytes, result, n, NULL, NULL);
if (n < 0)
{
free (result);
result = NULL;
goto leave;
}
result[n] = 0;
leave:
free (buffer);
RegCloseKey (handle);
return result;
}
#endif /*HAVE_W32CE_SYSTEM*/
#ifdef HAVE_W32CE_SYSTEM
/* Replacement for getenv which takes care of the our use of getenv.
The code is not thread safe but we expect it to work in all cases
because it is called for the first time early enough. */
char *
_assuan_getenv (const char *name)
{
static int initialized;
static char *val_debug;
static char *val_full_logging;
if (!initialized)
{
val_debug = w32_read_registry (L"\\Software\\GNU\\libassuan",
L"debug");
val_full_logging = w32_read_registry (L"\\Software\\GNU\\libassuan",
L"full_logging");
initialized = 1;
}
if (!strcmp (name, "ASSUAN_DEBUG"))
return val_debug;
else if (!strcmp (name, "ASSUAN_FULL_LOGGING"))
return val_full_logging;
else
return NULL;
}
#endif /*HAVE_W32CE_SYSTEM*/
diff --git a/src/w32-fd-t.inc.h b/src/w32-fd-t.inc.h
index 11cd511..37f20f4 100644
--- a/src/w32-fd-t.inc.h
+++ b/src/w32-fd-t.inc.h
@@ -1,39 +1,39 @@
## w32-fd-t.inc.h - Include fragment to build assuan.h.
## Copyright (C) 2010 Free Software Foundation, Inc.
##
## This file is part of Assuan.
##
## Assuan is free software; you can redistribute it and/or modify it
## under the terms of the GNU Lesser General Public License as
## published by the Free Software Foundation; either version 2.1 of
## the License, or (at your option) any later version.
##
## Assuan 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
## Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public
## License along with this program; if not, see <http://www.gnu.org/licenses/>.
##
##
## This file is included by the mkheader tool. Lines starting with
## a double hash mark are not copied to the destination file.
/* Because we use system handles and not libc low level file
descriptors on W32, we need to declare them as HANDLE (which
actually is a plain pointer). This is required to eventually
support 64 bit Windows systems. */
typedef void *assuan_fd_t;
#define ASSUAN_INVALID_FD ((void*)(-1))
#define ASSUAN_INVALID_PID ((pid_t) -1)
-static inline assuan_fd_t
+static GPG_ERR_INLINE assuan_fd_t
assuan_fd_from_posix_fd (int fd)
{
if (fd < 0)
return ASSUAN_INVALID_FD;
else
return (assuan_fd_t) _get_osfhandle (fd);
}
##EOF##
diff --git a/src/w32-types.inc.h b/src/w32-types.inc.h
index 56bc7b2..35aaec9 100644
--- a/src/w32-types.inc.h
+++ b/src/w32-types.inc.h
@@ -1,23 +1,29 @@
## w32-types.inc.h - Include fragment to build assuan.h.
## Copyright (C) 2010 Free Software Foundation, Inc.
##
## This file is part of Assuan.
##
## Assuan is free software; you can redistribute it and/or modify it
## under the terms of the GNU Lesser General Public License as
## published by the Free Software Foundation; either version 2.1 of
## the License, or (at your option) any later version.
##
## Assuan 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
## Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public
## License along with this program; if not, see <http://www.gnu.org/licenses/>.
##
##
## This file is included by the mkheader tool. Lines starting with
## a double hash mark are not copied to the destination file.
typedef void *assuan_msghdr_t;
+
+#ifdef _MSC_VER
+ typedef long ssize_t;
+ typedef int pid_t;
+#endif
+
##EOF##
diff --git a/src/w32ce-fd-t.inc.h b/src/w32ce-fd-t.inc.h
index df55f23..2de72e6 100644
--- a/src/w32ce-fd-t.inc.h
+++ b/src/w32ce-fd-t.inc.h
@@ -1,32 +1,32 @@
## w32ce-fd-t.inc.h - Include fragment to build assuan.h.
## Copyright (C) 2010 Free Software Foundation, Inc.
##
## This file is part of Assuan.
##
## Assuan is free software; you can redistribute it and/or modify it
## under the terms of the GNU Lesser General Public License as
## published by the Free Software Foundation; either version 2.1 of
## the License, or (at your option) any later version.
##
## Assuan 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
## Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public
## License along with this program; if not, see <http://www.gnu.org/licenses/>.
##
##
## This file is included by the mkheader tool. Lines starting with
## a double hash mark are not copied to the destination file.
typedef void *assuan_fd_t;
#define ASSUAN_INVALID_FD ((void*)(-1))
#define ASSUAN_INVALID_PID ((pid_t) -1)
-static inline assuan_fd_t
+static GPG_ERR_INLINE assuan_fd_t
assuan_fd_from_posix_fd (int fd)
{
return (assuan_fd_t)(fd);
}
##EOF##

File Metadata

Mime Type
text/x-diff
Expires
Sat, Feb 7, 7:39 AM (1 d, 18 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
15/8e/cb37f63f7c153d5857fdf11bf665

Event Timeline