├── m4 ├── Makefile.am ├── ltversion.m4 ├── autobuild.m4 ├── ax_cc_for_build.m4 ├── socklen.m4 ├── ltsugar.m4 ├── lt~obsolete.m4 └── gpg-error.m4 ├── src ├── versioninfo.rc.in ├── libassuan.pc.in ├── isascii.c ├── posix-includes.inc.h ├── w32-includes.inc.h ├── posix-types.inc.h ├── memrchr.c ├── posix-fd-t.inc.h ├── w32-types.inc.h ├── posix-sock-nonce.inc.h ├── stpcpy.c ├── sysutils.c ├── w32-fd-t.inc.h ├── assuan-io.c ├── assuan-error.c ├── w32-sock-nonce.inc.h ├── server.c ├── funopen.c ├── conversion.c ├── libassuan-config.in ├── libassuan.vers ├── assuan-pipe-server.c ├── Makefile.am ├── libassuan.def ├── debug.c ├── assuan-listen.c ├── mkheader.c ├── context.c ├── assuan-socket-server.c ├── assuan-uds.c ├── assuan-logging.c ├── setenv.c ├── libassuan.m4 └── assuan.c ├── autogen.rc ├── tests ├── fdpassing-socket.sh ├── motd ├── Makefile.am ├── ChangeLog-2011 ├── version.c └── common.h ├── THANKS ├── ChangeLog ├── .gitignore ├── TODO ├── README ├── doc ├── DCO ├── Makefile.am ├── README.apichanges ├── HACKING └── ChangeLog-2011 ├── AUTHORS ├── README.GIT ├── mkinstalldirs ├── Makefile.am └── INSTALL /m4/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = autobuild.m4 ax_cc_for_build.m4 gpg-error.m4 socklen.m4 2 | -------------------------------------------------------------------------------- /src/versioninfo.rc.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libassuan/master/src/versioninfo.rc.in -------------------------------------------------------------------------------- /autogen.rc: -------------------------------------------------------------------------------- 1 | # autogen.sh configuration for Libassuan -*- sh -*- 2 | 3 | case "$myhost" in 4 | w32) 5 | configure_opts="" 6 | ;; 7 | 8 | amd64) 9 | configure_opts="" 10 | ;; 11 | esac 12 | 13 | final_info="./configure --enable-maintainer-mode && make" 14 | -------------------------------------------------------------------------------- /tests/fdpassing-socket.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if test -e a.sock; then 4 | rm -f a.sock 5 | fi 6 | 7 | ./fdpassing$EXEEXT --server --socketname a.sock 2>/dev/null & 8 | SERVER_PID=$! 9 | 10 | # Wait for server starts up 11 | sleep 1 12 | 13 | ./fdpassing$EXEEXT --socketname file://a.sock 14 | STATUS=$? 15 | 16 | if test $STATUS -eq 0; then 17 | exit 0 18 | else 19 | kill $SERVER_PID 20 | exit $STATUS 21 | fi 22 | rm -f a.sock 23 | -------------------------------------------------------------------------------- /tests/motd: -------------------------------------------------------------------------------- 1 | Big Brother trust@unlimited.com 0.4.2-TC #1 PREEMPT Thu Aug 3 02:52:00 UTC 2006 TC Lockinos 2 | 3 | The programs included monitor each and every keystroke by its users 4 | and report them back for evaluation. Use of this software is entirely 5 | voluntary, but non-compliance results in reducing the machine to an 6 | expensive paper-weight. 7 | 8 | There is no warranty whatsoever, and should we have made a mistake, we will 9 | come and sue you for taking advantage of that. 10 | -------------------------------------------------------------------------------- /src/libassuan.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | includedir=@includedir@ 4 | libdir=@libdir@ 5 | host=@LIBASSUAN_CONFIG_HOST@ 6 | api_version=@LIBASSUAN_CONFIG_API_VERSION@ 7 | 8 | Name: libassuan 9 | Description: IPC library for the GnuPG components 10 | Requires.private: gpg-error 11 | Version: @PACKAGE_VERSION@ 12 | Cflags: -I${includedir} @LIBASSUAN_CONFIG_CFLAGS@ 13 | Libs: -L${libdir} @LIBASSUAN_CONFIG_LIBS@ 14 | Libs.private: @NETLIBS@ 15 | URL: https://www.gnupg.org/related_software/libassuan/index.html 16 | -------------------------------------------------------------------------------- /THANKS: -------------------------------------------------------------------------------- 1 | Alain Guibert alguibert+gpd at free dot fr 2 | Ben Kibbey bjk at luxsci dot net 3 | Frank Osterfeld frank at kdab dot net 4 | Marc Mutz mutz at kde dot org 5 | Michael Nottebrock michaelnottebrock at gmx dot net 6 | Nelson H. F. Beebe beebe at math dot utah dot edu 7 | Peter O'Gorman gnupg-devel at mlists dot thewrittenword dot com 8 | Rex Dieter rdieter at math dot unl dot edu 9 | Ville Skyttä ville dot skytta at iki dot fi 10 | 11 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | No more ChangeLog files 2 | ======================== 3 | 4 | Do not modify any of the ChangeLog files in Libassuan. Starting on 5 | December 1st, 2011 we put change information only in the GIT commit 6 | log, and generate a top-level ChangeLog file from logs at "make dist" 7 | time. As such, there are strict requirements on the form of the 8 | commit log messages. See doc/HACKING for details. The old ChangeLog 9 | files have all be renamed to ChangeLog-2011. 10 | 11 | 12 | 13 | Local Variables: 14 | buffer-read-only: t 15 | mode: text 16 | End: 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.lo 2 | *.o 3 | .deps/ 4 | .libs/ 5 | /aclocal.m4 6 | /autom4te.cache 7 | /config.h.in 8 | /config.h 9 | /config.log 10 | /config.status 11 | /configure 12 | /libtool 13 | /stamp-h1 14 | /Makefile.in 15 | /Makefile 16 | m4/Makefile.in 17 | m4/Makefile 18 | src/Makefile.in 19 | src/Makefile 20 | src/assuan.h 21 | src/libassuan-config 22 | src/libassuan.la 23 | src/mkheader 24 | src/versioninfo.rc 25 | doc/Makefile.in 26 | doc/Makefile 27 | doc/assuan.info 28 | doc/stamp-vti 29 | doc/version.texi 30 | tests/Makefile.in 31 | tests/Makefile 32 | tests/fdpassing 33 | tests/pipeconnect 34 | /VERSION 35 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | -*- outline -*- 2 | * More tests. 3 | * Check that we have Pth-ed all blocking fucntions. 4 | * Introduce a spawn wrapper program as gpgme has to not leak fds under W32. 5 | * assuan_transact returns immediately on an error in the callback 6 | function. It might be better to return the error to the caller. As 7 | an example see dirmngr-client, where we need to send empty responses 8 | for unknown inquiries, albeit dirmngr itself would handle the 9 | returns for assuan_inquire gracefully. We need to check all 10 | applications whether it is safe to change this. 11 | * XOPEN_SOURCE and snprintf 12 | See Peter O'Gorman's mail. 13 | 14 | * W32 15 | ** Check what kind of fd we use with inbound.fd etc. 16 | 17 | -------------------------------------------------------------------------------- /m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # @configure_input@ 11 | 12 | # serial 3337 ltversion.m4 13 | # This file is part of GNU Libtool 14 | 15 | m4_define([LT_PACKAGE_VERSION], [2.4.2]) 16 | m4_define([LT_PACKAGE_REVISION], [1.3337]) 17 | 18 | AC_DEFUN([LTVERSION_VERSION], 19 | [macro_version='2.4.2' 20 | macro_revision='1.3337' 21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 22 | _LT_DECL(, macro_revision, 0) 23 | ]) 24 | -------------------------------------------------------------------------------- /src/isascii.c: -------------------------------------------------------------------------------- 1 | /* isascii.c - Replacement for isascii. 2 | * Copyright (C) 2002, 2005 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Assuan. 5 | * 6 | * Assuan is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Assuan is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1+ 19 | */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | int 26 | isascii (int c) 27 | { 28 | return (((c) & ~0x7f) == 0); 29 | } 30 | -------------------------------------------------------------------------------- /src/posix-includes.inc.h: -------------------------------------------------------------------------------- 1 | ## posix-includes.inc.h - Include fragment to build assuan.h. 2 | ## Copyright (C) 2010 Free Software Foundation, Inc. 3 | ## 4 | ## This file is part of Assuan. 5 | ## 6 | ## Assuan is free software; you can redistribute it and/or modify it 7 | ## under the terms of the GNU Lesser General Public License as 8 | ## published by the Free Software Foundation; either version 2.1 of 9 | ## the License, or (at your option) any later version. 10 | ## 11 | ## Assuan is distributed in the hope that it will be useful, but 12 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | ## Lesser General Public License for more details. 15 | ## 16 | ## You should have received a copy of the GNU Lesser General Public 17 | ## License along with this program; if not, see . 18 | ## SPDX-License-Identifier: LGPL-2.1+ 19 | ## 20 | ## 21 | ## This file is included by the mkheader tool. Lines starting with 22 | ## a double hash mark are not copied to the destination file. 23 | #include 24 | ##EOF## 25 | -------------------------------------------------------------------------------- /src/w32-includes.inc.h: -------------------------------------------------------------------------------- 1 | ## w32-includes.inc.h - Include fragment to build assuan.h. 2 | ## Copyright (C) 2010 Free Software Foundation, Inc. 3 | ## 4 | ## This file is part of Assuan. 5 | ## 6 | ## Assuan is free software; you can redistribute it and/or modify it 7 | ## under the terms of the GNU Lesser General Public License as 8 | ## published by the Free Software Foundation; either version 2.1 of 9 | ## the License, or (at your option) any later version. 10 | ## 11 | ## Assuan is distributed in the hope that it will be useful, but 12 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | ## Lesser General Public License for more details. 15 | ## 16 | ## You should have received a copy of the GNU Lesser General Public 17 | ## License along with this program; if not, see . 18 | ## SPDX-License-Identifier: LGPL-2.1+ 19 | ## 20 | ## 21 | ## This file is included by the mkheader tool. Lines starting with 22 | ## a double hash mark are not copied to the destination file. 23 | #include 24 | #include 25 | ##EOF## 26 | -------------------------------------------------------------------------------- /src/posix-types.inc.h: -------------------------------------------------------------------------------- 1 | ## posix-types.inc.h - Include fragment to build assuan.h. 2 | ## Copyright (C) 2010 Free Software Foundation, Inc. 3 | ## 4 | ## This file is part of Assuan. 5 | ## 6 | ## Assuan is free software; you can redistribute it and/or modify it 7 | ## under the terms of the GNU Lesser General Public License as 8 | ## published by the Free Software Foundation; either version 2.1 of 9 | ## the License, or (at your option) any later version. 10 | ## 11 | ## Assuan is distributed in the hope that it will be useful, but 12 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | ## Lesser General Public License for more details. 15 | ## 16 | ## You should have received a copy of the GNU Lesser General Public 17 | ## License along with this program; if not, see . 18 | ## SPDX-License-Identifier: LGPL-2.1+ 19 | ## 20 | ## 21 | ## This file is included by the mkheader tool. Lines starting with 22 | ## a double hash mark are not copied to the destination file. 23 | typedef struct msghdr *assuan_msghdr_t; 24 | typedef pid_t assuan_pid_t; 25 | ##EOF## 26 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Libassuan 2 | =========== 3 | 4 | Copyright (C) 2001-2013 Free Software Foundation, Inc. 5 | Copyright (C) 2001-2021,2023-2025 g10 Code GmbH 6 | 7 | 8 | This is a general purpose IPC library which is for example used 9 | GnuPG, GPGME and some other software. 10 | 11 | See COPYING.LIB on how to share, modify and distribute the 12 | software itself (LGPLv2.1+) and COPYING for the documentation 13 | (GPLv3+). 14 | 15 | Please send bug report to the gnupg-devel mailing list or enter 16 | them into the gnupg bug tracker at https://bugs.gnupg.org using the 17 | tag "libassuan". 18 | 19 | The primary FTP site is https://gnupg.org/ftp/gcrypt/libassuan. 20 | 21 | 22 | Contact 23 | ------- 24 | 25 | See the file AUTHORS. 26 | 27 | Commercial grade support for Libassuan and GnuPG is available; for 28 | a listing of offers see https://www.gnupg.org/service.html . 29 | Maintaining and improving this software is costly. Since 2001, 30 | g10 Code GmbH, a German company owned and headed by GnuPG's 31 | principal author Werner Koch, is bearing the majority of these 32 | costs. To help them carry on this work, they need your support. 33 | See https://gnupg.org/donate/ . 34 | -------------------------------------------------------------------------------- /src/memrchr.c: -------------------------------------------------------------------------------- 1 | /* memrchr.c - Replacement for memrchr. 2 | * Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Assuan. 5 | * 6 | * Assuan is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Assuan is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1+ 19 | */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include 26 | 27 | void * 28 | memrchr (const void *block, int c, size_t size) 29 | { 30 | const unsigned char *p = block; 31 | 32 | if (size) 33 | { 34 | for (p += size - 1; size; p--, size--) 35 | if (*p == c) 36 | return (void *)p; 37 | } 38 | return NULL; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /src/posix-fd-t.inc.h: -------------------------------------------------------------------------------- 1 | ## posix-fd-t.inc.h - Include fragment to build assuan.h. 2 | ## Copyright (C) 2010 Free Software Foundation, Inc. 3 | ## 4 | ## This file is part of Assuan. 5 | ## 6 | ## Assuan is free software; you can redistribute it and/or modify it 7 | ## under the terms of the GNU Lesser General Public License as 8 | ## published by the Free Software Foundation; either version 2.1 of 9 | ## the License, or (at your option) any later version. 10 | ## 11 | ## Assuan is distributed in the hope that it will be useful, but 12 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | ## Lesser General Public License for more details. 15 | ## 16 | ## You should have received a copy of the GNU Lesser General Public 17 | ## License along with this program; if not, see . 18 | ## SPDX-License-Identifier: LGPL-2.1+ 19 | ## 20 | ## 21 | ## This file is included by the mkheader tool. Lines starting with 22 | ## a double hash mark are not copied to the destination file. 23 | 24 | typedef int assuan_fd_t; 25 | #define ASSUAN_INVALID_FD (-1) 26 | #define ASSUAN_INVALID_PID ((pid_t) -1) 27 | static GPG_ERR_INLINE assuan_fd_t 28 | assuan_fd_from_posix_fd (int fd) 29 | { 30 | return fd; 31 | } 32 | 33 | ##EOF## 34 | -------------------------------------------------------------------------------- /m4/autobuild.m4: -------------------------------------------------------------------------------- 1 | # autobuild.m4 serial 2 (autobuild-3.3) 2 | # Copyright (C) 2004 Simon Josefsson 3 | # 4 | # This file is free software, distributed under the terms of the GNU 5 | # General Public License. As a special exception to the GNU General 6 | # Public License, this file may be distributed as part of a program 7 | # that contains a configuration script generated by Autoconf, under 8 | # the same distribution terms as the rest of that program. 9 | # 10 | # This file can can be used in projects which are not available under 11 | # the GNU General Public License or the GNU Library General Public 12 | # License but which still want to provide support for Autobuild. 13 | 14 | # Usage: AB_INIT([MODE]). 15 | AC_DEFUN([AB_INIT], 16 | [ 17 | AC_REQUIRE([AC_CANONICAL_BUILD]) 18 | AC_REQUIRE([AC_CANONICAL_HOST]) 19 | 20 | AC_MSG_NOTICE([autobuild project... ${PACKAGE_NAME:-$PACKAGE}]) 21 | AC_MSG_NOTICE([autobuild revision... ${PACKAGE_VERSION:-$VERSION}]) 22 | hostname=`hostname` 23 | if test "$hostname"; then 24 | AC_MSG_NOTICE([autobuild hostname... $hostname]) 25 | fi 26 | ifelse([$1],[],,[AC_MSG_NOTICE([autobuild mode... $1])]) 27 | date=`date +%Y%m%d-%H%M%S` 28 | if test "$?" != 0; then 29 | date=`date` 30 | fi 31 | if test "$date"; then 32 | AC_MSG_NOTICE([autobuild timestamp... $date]) 33 | fi 34 | ]) 35 | -------------------------------------------------------------------------------- /doc/DCO: -------------------------------------------------------------------------------- 1 | Libassuan Developer's Certificate of Origin. Version 1.0 2 | ========================================================= 3 | 4 | By making a contribution to the Libassuan project, I certify that: 5 | 6 | (a) The contribution was created in whole or in part by me and I 7 | have the right to submit it under the free software license 8 | indicated in the file; or 9 | 10 | (b) The contribution is based upon previous work that, to the 11 | best of my knowledge, is covered under an appropriate free 12 | software license and I have the right under that license to 13 | submit that work with modifications, whether created in whole 14 | or in part by me, under the same free software license 15 | (unless I am permitted to submit under a different license), 16 | as indicated in the file; or 17 | 18 | (c) The contribution was provided directly to me by some other 19 | person who certified (a), (b) or (c) and I have not modified 20 | it. 21 | 22 | (d) I understand and agree that this project and the contribution 23 | are public and that a record of the contribution (including 24 | all personal information I submit with it, including my 25 | sign-off) is maintained indefinitely and may be redistributed 26 | consistent with this project or the free software license(s) 27 | involved. 28 | 29 | Signed-off-by: [Your name and mail address] 30 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | # Assuan Makefile 2 | # Copyright (C) 2003 Free Software Foundation, Inc. 3 | # 4 | # This file is part of Assuan. 5 | # 6 | # Assuan is free software; you can redistribute it and/or modify it 7 | # under the terms of the GNU Lesser General Public License as 8 | # published by the Free Software Foundation; either version 3 of 9 | # the License, or (at your option) any later version. 10 | # 11 | # Assuan is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public 17 | # License along with this program; if not, see . 18 | 19 | ## Process this file with automake to produce Makefile.in 20 | 21 | EXTRA_DIST = README.apichanges HACKING DCO 22 | 23 | info_TEXINFOS = assuan.texi 24 | 25 | assuan_TEXINFOS = lgpl.texi gpl.texi 26 | 27 | 28 | online: assuan.html assuan.pdf 29 | set -e; \ 30 | echo "Uploading current manuals to www.gnupg.org ..."; \ 31 | user=werner ; webhost="ftp.gnupg.org"; \ 32 | (cd assuan.html && rsync -vr --exclude='.svn' . \ 33 | $${user}@$${webhost}:webspace/manuals/assuan/ ); \ 34 | rsync -v assuan.pdf $${user}@$${webhost}:webspace/manuals/ 35 | -------------------------------------------------------------------------------- /src/w32-types.inc.h: -------------------------------------------------------------------------------- 1 | ## w32-types.inc.h - Include fragment to build assuan.h. 2 | ## Copyright (C) 2010 Free Software Foundation, Inc. 3 | ## 4 | ## This file is part of Assuan. 5 | ## 6 | ## Assuan is free software; you can redistribute it and/or modify it 7 | ## under the terms of the GNU Lesser General Public License as 8 | ## published by the Free Software Foundation; either version 2.1 of 9 | ## the License, or (at your option) any later version. 10 | ## 11 | ## Assuan is distributed in the hope that it will be useful, but 12 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | ## Lesser General Public License for more details. 15 | ## 16 | ## You should have received a copy of the GNU Lesser General Public 17 | ## License along with this program; if not, see . 18 | ## SPDX-License-Identifier: LGPL-2.1+ 19 | ## 20 | ## 21 | ## This file is included by the mkheader tool. Lines starting with 22 | ## a double hash mark are not copied to the destination file. 23 | typedef void *assuan_msghdr_t; 24 | 25 | #ifdef _MSC_VER 26 | # ifdef _WIN64 27 | typedef long long ssize_t; 28 | typedef long long pid_t; 29 | #else 30 | typedef long ssize_t; 31 | typedef int pid_t; 32 | # endif 33 | #endif 34 | 35 | #ifdef _WIN64 36 | typedef unsigned long long assuan_pid_t; 37 | #else 38 | typedef unsigned long assuan_pid_t; 39 | #endif 40 | 41 | ##EOF## 42 | -------------------------------------------------------------------------------- /src/posix-sock-nonce.inc.h: -------------------------------------------------------------------------------- 1 | ## posix-sock-nonce.inc.h - Include fragment to build assuan.h. 2 | ## Copyright (C) 2010 Free Software Foundation, Inc. 3 | ## 4 | ## This file is part of Assuan. 5 | ## 6 | ## Assuan is free software; you can redistribute it and/or modify it 7 | ## under the terms of the GNU Lesser General Public License as 8 | ## published by the Free Software Foundation; either version 2.1 of 9 | ## the License, or (at your option) any later version. 10 | ## 11 | ## Assuan is distributed in the hope that it will be useful, but 12 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | ## Lesser General Public License for more details. 15 | ## 16 | ## You should have received a copy of the GNU Lesser General Public 17 | ## License along with this program; if not, see . 18 | ## SPDX-License-Identifier: LGPL-2.1+ 19 | ## 20 | ## 21 | ## This file is included by the mkheader tool. Lines starting with 22 | ## a double hash mark are not copied to the destination file. 23 | /* Under Windows Assuan features an emulation of Unix domain sockets 24 | based on a local TCP connections. To implement access permissions 25 | based on file permissions a nonce is used which is expected by the 26 | server as the first bytes received. On POSIX systems this is a 27 | dummy structure. */ 28 | struct assuan_sock_nonce_s 29 | { 30 | size_t length; 31 | }; 32 | typedef struct assuan_sock_nonce_s assuan_sock_nonce_t; 33 | ##EOF## 34 | -------------------------------------------------------------------------------- /doc/README.apichanges: -------------------------------------------------------------------------------- 1 | README.apichanges -*- text -*- 2 | 3 | API changes between 1.0.5 and 2.0.0: 4 | ==================================== 5 | 6 | While allowing to build libassuan as a DSO we decided to clean up the 7 | API. The changes are straightforward and it should only take a few 8 | minutes to fix your code. 9 | 10 | See the NEWS file for functions that have been renamed or replaced by 11 | alternatives that are used in the same way (but may have extra 12 | arguments with suitable default values or similar). The rest of this 13 | document lists significant changes only. 14 | 15 | There have been many macros provided now for fixed constants, you may 16 | consider using them (but the old hard-coded values will continue to 17 | work where applicable). Particularly noteworthy is ASSUAN_INVALID_PID 18 | and all flags values. 19 | 20 | Use of libgpg-error is mandatory. 21 | 22 | assuan_pipe_connect child fds are now of assuan_fd_t type, not of int 23 | type. Use assuan_fd_from_posix_fd() for conversion. If you use 24 | assuan_pipe_connect with NAME of NULL, you have to provide a non-NULL 25 | ARGV argument and check that against "server" or "client" to determine 26 | which end you got after fork(). 27 | 28 | assuan_init_pipe_server closes the provided fds after terminating the 29 | connection now. Use assuan_fdopen to duplicate them first. 30 | 31 | If you use the assuan sock interface, you must call assuan_sock_init after 32 | setting global context defaults. 33 | 34 | Pth support has changed. This now follows the same style as libgcrypt 35 | by setting system hook callbacks. 36 | -------------------------------------------------------------------------------- /src/stpcpy.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1992, 1995, 1997, 2002, 2004 Free Software Foundation, Inc. 2 | * This file is part of the GNU C Library. 3 | * 4 | * The GNU C Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * The GNU C Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with the GNU C Library; if not, 16 | * see . 17 | * SPDX-License-Identifier: LGPL-2.1+ 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | # include 22 | #endif 23 | 24 | #include 25 | 26 | #undef __stpcpy 27 | #undef stpcpy 28 | 29 | #ifndef weak_alias 30 | # define __stpcpy stpcpy 31 | #endif 32 | 33 | /* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */ 34 | char * 35 | __stpcpy (char *dest, const char *src) 36 | { 37 | register char *d = dest; 38 | register const char *s = src; 39 | 40 | do 41 | *d++ = *s; 42 | while (*s++ != '\0'); 43 | 44 | return d - 1; 45 | } 46 | #ifdef libc_hidden_def 47 | libc_hidden_def (__stpcpy) 48 | #endif 49 | #ifdef weak_alias 50 | weak_alias (__stpcpy, stpcpy) 51 | #endif 52 | #ifdef libc_hidden_builtin_def 53 | libc_hidden_builtin_def (stpcpy) 54 | #endif 55 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | # Makefile for Assuan regression tests 2 | # Copyright (C) 2006 Free Software Foundation, Inc. 3 | # 4 | # This file is part of Assuan. 5 | # 6 | # Assuan is free software; you can redistribute it and/or modify it 7 | # under the terms of the GNU Lesser General Public License as 8 | # published by the Free Software Foundation; either version 3 of 9 | # the License, or (at your option) any later version. 10 | # 11 | # Assuan is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public 17 | # License along with this program; if not, see . 18 | 19 | ## Process this file with automake to produce Makefile.in 20 | 21 | TESTS_ENVIRONMENT = EXEEXT=$(EXEEXT); export EXEEXT; 22 | 23 | EXTRA_DIST = motd fdpassing-socket.sh 24 | 25 | BUILT_SOURCES = 26 | CLEANFILES = 27 | 28 | test_programs = version 29 | test_programs += pipeconnect 30 | 31 | if HAVE_W32_SYSTEM 32 | test_programs += fdpassing 33 | check_SCRIPTS = fdpassing-socket.sh 34 | testtools = 35 | else 36 | testtools = socks5 37 | endif 38 | 39 | if USE_DESCRIPTOR_PASSING 40 | test_programs += fdpassing 41 | check_SCRIPTS = fdpassing-socket.sh 42 | endif 43 | 44 | TESTS = $(test_programs) $(check_SCRIPTS) 45 | 46 | AM_CFLAGS = $(GPG_ERROR_CFLAGS) 47 | if HAVE_W32_SYSTEM 48 | AM_LDFLAGS = -no-fast-install 49 | else 50 | AM_LDFLAGS = -no-install 51 | endif 52 | 53 | noinst_HEADERS = common.h 54 | noinst_PROGRAMS = $(test_programs) $(testtools) 55 | LDADD = ../src/libassuan.la $(GPG_ERROR_LIBS) @LDADD_FOR_TESTS_KLUDGE@ 56 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Package: libassuan 2 | Maintainer: Werner Koch 3 | Bug reports: gnupg-devel@gnupg.org 4 | Security related bug reports: security@gnupg.org 5 | License (library): LGPLv2.1+ 6 | License (manual): GPLv3+ 7 | 8 | Libassuan is free software. See below for details. License copyright 9 | years may be listed using range notation, e.g., 2000-2013, indicating 10 | that every year in the range, inclusive, is a copyrightable year that 11 | would otherwise be listed individually. 12 | 13 | 14 | Authors with a FSF copyright assignment 15 | ======================================= 16 | 17 | Werner Koch 18 | - Initial code. 19 | 20 | Neal H. Walfield 21 | - Code cleanup, descriptor passing and bug fixes. 22 | 23 | Marcus Brinkmann 24 | - Shared library version, bug fixes. 25 | 26 | g10 Code GmbH 27 | - all work indicated by mail addresses in ChangeLogs 28 | 29 | Ben Kibbey Assigns Past and Future Changes For GnuPG. 30 | - Fixes and new features 31 | 32 | 33 | Authors with a DCO 34 | ================== 35 | 36 | 37 | 38 | Notes: 39 | ====== 40 | 41 | Libassuan was orginally part of NewPG, a temporary fork of GnuPG, and 42 | later split of into a separate library. 43 | 44 | 45 | Copyright 46 | ========= 47 | 48 | The Libassuan code is distributed under the GNU Lesser General Public 49 | License, version 2.1 or later. The manual is distributed under the 50 | GNU General Public License, Version 3 or later. 51 | 52 | List of Copyright holders 53 | ========================= 54 | 55 | Copyright (C) 1992-2013 Free Software Foundation, Inc. 56 | Copyright (C) 1994 X Consortium 57 | Copyright (C) 2000 Werner Koch (dd9jn) 58 | Copyright (C) 2001-2021,2023-2025 g10 Code GmbH 59 | Copyright (C) 2004 Simon Josefsson 60 | -------------------------------------------------------------------------------- /src/sysutils.c: -------------------------------------------------------------------------------- 1 | /* sysutils.c - System utilities 2 | * Copyright (C) 2010 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Assuan. 5 | * 6 | * Assuan is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Assuan is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1+ 19 | */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include 23 | #endif 24 | #include 25 | #include 26 | #include 27 | #include 28 | #ifdef HAVE_W32_SYSTEM 29 | # ifdef HAVE_WINSOCK2_H 30 | # include 31 | # endif 32 | # include 33 | #endif /*HAVE_W32_SYSTEM*/ 34 | 35 | #include "assuan-defs.h" 36 | 37 | 38 | /* This is actually a dummy function to make sure that is module is 39 | not empty. Some compilers barf on empty modules. */ 40 | const char * 41 | _assuan_sysutils_blurb (void) 42 | { 43 | static const char blurb[] = 44 | "\n\n" 45 | "This is Libassuan " PACKAGE_VERSION " - The GnuPG IPC Library\n" 46 | "Copyright 2001-2013 Free Software Foundation, Inc.\n" 47 | "Copyright 2001-2021,2023-2025 g10 Code GmbH\n" 48 | "\n" 49 | "SPDX-License-Identifier: LGPL-2.1-or-later\n" 50 | "(" BUILD_COMMITID " " BUILD_TIMESTAMP ")\n" 51 | "\n\n"; 52 | return blurb; 53 | } 54 | -------------------------------------------------------------------------------- /src/w32-fd-t.inc.h: -------------------------------------------------------------------------------- 1 | ## w32-fd-t.inc.h - Include fragment to build assuan.h. 2 | ## Copyright (C) 2010 Free Software Foundation, Inc. 3 | ## 4 | ## This file is part of Assuan. 5 | ## 6 | ## Assuan is free software; you can redistribute it and/or modify it 7 | ## under the terms of the GNU Lesser General Public License as 8 | ## published by the Free Software Foundation; either version 2.1 of 9 | ## the License, or (at your option) any later version. 10 | ## 11 | ## Assuan is distributed in the hope that it will be useful, but 12 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | ## Lesser General Public License for more details. 15 | ## 16 | ## You should have received a copy of the GNU Lesser General Public 17 | ## License along with this program; if not, see . 18 | ## SPDX-License-Identifier: LGPL-2.1+ 19 | ## 20 | ## 21 | ## This file is included by the mkheader tool. Lines starting with 22 | ## a double hash mark are not copied to the destination file. 23 | 24 | /* Because we use system handles and not libc low level file 25 | descriptors on W32, we need to declare them as HANDLE (which 26 | actually is a plain pointer). This is required to eventually 27 | support 64 bit Windows systems. */ 28 | typedef void *assuan_fd_t; 29 | #define ASSUAN_INVALID_FD ((void*)(-1)) 30 | #define ASSUAN_INVALID_PID ((pid_t) -1) 31 | #if GPGRT_HAVE_PRAGMA_GCC_PUSH 32 | # pragma GCC push_options 33 | # pragma GCC diagnostic ignored "-Wbad-function-cast" 34 | #endif 35 | static GPG_ERR_INLINE assuan_fd_t 36 | assuan_fd_from_posix_fd (int fd) 37 | { 38 | if (fd < 0) 39 | return ASSUAN_INVALID_FD; 40 | else 41 | return (assuan_fd_t) _get_osfhandle (fd); 42 | } 43 | #if GPGRT_HAVE_PRAGMA_GCC_PUSH 44 | # pragma GCC pop_options 45 | #endif 46 | 47 | ##EOF## 48 | -------------------------------------------------------------------------------- /src/assuan-io.c: -------------------------------------------------------------------------------- 1 | /* assuan-io.c - Wraps the read and write functions. 2 | * Copyright (C) 2002, 2004, 2006-2009 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Assuan. 5 | * 6 | * Assuan is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Assuan is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1+ 19 | */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include 26 | #ifdef HAVE_SYS_TIME_H 27 | # include 28 | #endif 29 | #ifdef HAVE_SYS_TYPES_H 30 | # include 31 | #endif 32 | #ifdef HAVE_SYS_SOCKET_H 33 | # include 34 | #endif 35 | #ifdef HAVE_UNISTD_H 36 | # include 37 | #endif 38 | #include 39 | #ifdef HAVE_W32_SYSTEM 40 | # ifdef HAVE_WINSOCK2_H 41 | # include 42 | # endif 43 | # include 44 | #else 45 | # include 46 | #endif 47 | 48 | #include "assuan-defs.h" 49 | 50 | 51 | ssize_t 52 | _assuan_simple_read (assuan_context_t ctx, void *buffer, size_t size) 53 | { 54 | return _assuan_read (ctx, ctx->inbound.fd, buffer, size); 55 | } 56 | 57 | 58 | ssize_t 59 | _assuan_simple_write (assuan_context_t ctx, const void *buffer, size_t size) 60 | { 61 | return _assuan_write (ctx, ctx->outbound.fd, buffer, size); 62 | } 63 | -------------------------------------------------------------------------------- /src/assuan-error.c: -------------------------------------------------------------------------------- 1 | /* assuan-error.c 2 | * Copyright (C) 2009 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Assuan. 5 | * 6 | * Assuan is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Assuan is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1+ 19 | */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #undef _ASSUAN_IN_LIBASSUAN /* undef to get all error codes. */ 30 | #include "assuan.h" 31 | #include "assuan-defs.h" 32 | 33 | 34 | /* A small helper function to treat EAGAIN transparently to the 35 | caller. */ 36 | int 37 | _assuan_error_is_eagain (assuan_context_t ctx, gpg_error_t err) 38 | { 39 | if (gpg_err_code (err) == GPG_ERR_EAGAIN) 40 | { 41 | /* Avoid spinning by sleeping for one tenth of a second. */ 42 | _assuan_usleep (ctx, 100000); 43 | return 1; 44 | } 45 | else 46 | return 0; 47 | } 48 | 49 | 50 | 51 | #ifdef HAVE_W32_SYSTEM 52 | char * 53 | _assuan_w32_strerror (assuan_context_t ctx, int ec) 54 | { 55 | if (ec == -1) 56 | ec = (int)GetLastError (); 57 | FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, ec, 58 | MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), 59 | ctx->w32_strerror, sizeof (ctx->w32_strerror) - 1, NULL); 60 | return ctx->w32_strerror; 61 | } 62 | #endif 63 | 64 | -------------------------------------------------------------------------------- /src/w32-sock-nonce.inc.h: -------------------------------------------------------------------------------- 1 | ## w32-sock-nonce.inc.h - Include fragment to build assuan.h. 2 | ## Copyright (C) 2010 Free Software Foundation, Inc. 3 | ## 4 | ## This file is part of Assuan. 5 | ## 6 | ## Assuan is free software; you can redistribute it and/or modify it 7 | ## under the terms of the GNU Lesser General Public License as 8 | ## published by the Free Software Foundation; either version 2.1 of 9 | ## the License, or (at your option) any later version. 10 | ## 11 | ## Assuan is distributed in the hope that it will be useful, but 12 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | ## Lesser General Public License for more details. 15 | ## 16 | ## You should have received a copy of the GNU Lesser General Public 17 | ## License along with this program; if not, see . 18 | ## SPDX-License-Identifier: LGPL-2.1+ 19 | ## 20 | ## 21 | ## This file is included by the mkheader tool. Lines starting with 22 | ## a double hash mark are not copied to the destination file. 23 | 24 | /* Assuan features an emulation of Unix domain sockets based on local 25 | TCP connections. To implement access permissions based on file 26 | permissions a nonce is used which is expected by the server as the 27 | first bytes received. This structure is used by the server to save 28 | the nonce created initially by bind. */ 29 | struct assuan_sock_nonce_s 30 | { 31 | size_t length; 32 | char nonce[16]; 33 | }; 34 | typedef struct assuan_sock_nonce_s assuan_sock_nonce_t; 35 | 36 | /* Define the Unix domain socket structure for Windows. */ 37 | #ifndef _ASSUAN_NO_SOCKET_WRAPPER 38 | # ifndef AF_LOCAL 39 | # define AF_LOCAL AF_UNIX 40 | # endif 41 | # ifndef EADDRINUSE 42 | # define EADDRINUSE WSAEADDRINUSE 43 | # endif 44 | struct sockaddr_un 45 | { 46 | short sun_family; 47 | unsigned short sun_port; 48 | struct in_addr sun_addr; 49 | char sun_path[108-2-4]; 50 | }; 51 | #endif 52 | 53 | ##EOF## 54 | -------------------------------------------------------------------------------- /src/server.c: -------------------------------------------------------------------------------- 1 | /* server.c - Interfaces for all assuan servers. 2 | * Copyright (C) 2009 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Assuan. 5 | * 6 | * Assuan is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Assuan is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1+ 19 | */ 20 | 21 | 22 | #ifdef HAVE_CONFIG_H 23 | #include 24 | #endif 25 | 26 | #include "assuan-defs.h" 27 | #include "debug.h" 28 | 29 | 30 | 31 | /* Disconnect and release the context CTX. */ 32 | void 33 | _assuan_server_finish (assuan_context_t ctx) 34 | { 35 | if (ctx->inbound.fd != ASSUAN_INVALID_FD) 36 | { 37 | _assuan_close (ctx, ctx->inbound.fd); 38 | if (ctx->inbound.fd == ctx->outbound.fd) 39 | ctx->outbound.fd = ASSUAN_INVALID_FD; 40 | ctx->inbound.fd = ASSUAN_INVALID_FD; 41 | } 42 | if (ctx->outbound.fd != ASSUAN_INVALID_FD) 43 | { 44 | _assuan_close (ctx, ctx->outbound.fd); 45 | ctx->outbound.fd = ASSUAN_INVALID_FD; 46 | } 47 | 48 | #if defined(HAVE_W32_SYSTEM) 49 | ctx->process_id = -1; 50 | #else 51 | ctx->pid = ASSUAN_INVALID_PID; 52 | #endif 53 | 54 | _assuan_uds_deinit (ctx); 55 | 56 | _assuan_inquire_release (ctx); 57 | } 58 | 59 | 60 | void 61 | _assuan_server_release (assuan_context_t ctx) 62 | { 63 | _assuan_server_finish (ctx); 64 | 65 | _assuan_free (ctx, ctx->hello_line); 66 | ctx->hello_line = NULL; 67 | _assuan_free (ctx, ctx->okay_line); 68 | ctx->okay_line = NULL; 69 | _assuan_free (ctx, ctx->cmdtbl); 70 | ctx->cmdtbl = NULL; 71 | } 72 | -------------------------------------------------------------------------------- /src/funopen.c: -------------------------------------------------------------------------------- 1 | /* funopen.c - Replacement for funopen. 2 | * Copyright (C) 2003, 2005 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Assuan. 5 | * 6 | * Assuan is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Assuan is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1+ 19 | */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include 26 | 27 | 28 | /* Replacement for the *BSD function: 29 | 30 | FILE *funopen (void *cookie, 31 | int (*readfn)(void *, char *, int), 32 | int (*writefn)(void *, const char *, int), 33 | fpos_t (*seekfn)(void *, fpos_t, int), 34 | int (*closefn)(void *)); 35 | 36 | The functions to provide my either be NULL if not required or 37 | similar to the unistd function with the exception of using the 38 | cookie instead of the file descriptor. 39 | */ 40 | 41 | 42 | #ifdef HAVE_FOPENCOOKIE 43 | FILE * 44 | _assuan_funopen(void *cookie, 45 | cookie_read_function_t *readfn, 46 | cookie_write_function_t *writefn, 47 | cookie_seek_function_t *seekfn, 48 | cookie_close_function_t *closefn) 49 | { 50 | cookie_io_functions_t io; 51 | 52 | io.read = readfn; 53 | io.write = writefn; 54 | io.seek = seekfn; 55 | io.close = closefn; 56 | 57 | return fopencookie (cookie, 58 | readfn ? ( writefn ? "rw" : "r" ) 59 | : ( writefn ? "w" : ""), io); 60 | } 61 | #else 62 | #error No known way to implement funopen. 63 | #endif 64 | -------------------------------------------------------------------------------- /README.GIT: -------------------------------------------------------------------------------- 1 | If you are building from GIT, run the script 2 | 3 | ./autogen.sh 4 | 5 | first, to make sure that you have all the necessary maintainer tools 6 | are installed and to build the actual configuration files. If you 7 | have just checked out from GIT, you should add the option "--force" to 8 | autogen.sh so that meta data is noticed by autom4te.cache. Then run 9 | 10 | ./configure --enable-maintainer-mode 11 | 12 | followed by the usual make. 13 | 14 | If autogen.sh complains about insufficient versions of the required 15 | tools, or the tools are not installed, you may use environment 16 | variables to override the default tool names: 17 | 18 | AUTOMAKE_SUFFIX is used as a suffix for all tools from the automake 19 | package. For example 20 | AUTOMAKE_SUFFIX="-1.7" ./autogen.sh 21 | uses "automake-1.7" and "aclocal-1.7. 22 | AUTOMAKE_PREFIX is used as a prefix for all tools from the automake 23 | page and may be combined with AUTOMAKE_SUFFIX. e.g.: 24 | AUTOMAKE_PREFIX=/usr/foo/bin ./autogen.sh 25 | uses "automake" and "aclocal" in the /usr/foo/bin 26 | directory. 27 | AUTOCONF_SUFFIX is used as a suffix for all tools from the automake 28 | package 29 | AUTOCONF_PREFIX is used as a prefix for all tools from the automake 30 | package 31 | GETTEXT_SUFFIX is used as a suffix for all tools from the gettext 32 | package 33 | GETTEXT_PREFIX is used as a prefix for all tools from the gettext 34 | package 35 | 36 | It is also possible to use the variable name AUTOMAKE, AUTOCONF, 37 | ACLOCAL, AUTOHEADER, GETTEXT and MSGMERGE to directly specify the name 38 | of the programs to run. It is however better to use the suffix and 39 | prefix forms as described above because that does not require 40 | knowledge about the actual tools used by autogen.sh. 41 | 42 | 43 | Please don't use autopoint, libtoolize or autoreconf unless you are 44 | the current maintainer and want to update the standard configuration 45 | files. All those files should be in GIT and only updated manually 46 | if the maintainer decides that newer versions are required. The 47 | maintainer should also make sure that the required version of automake 48 | et al. are properly indicated at the top of configure.ac and take care 49 | to copy the files and not merely use symlinks. 50 | -------------------------------------------------------------------------------- /tests/ChangeLog-2011: -------------------------------------------------------------------------------- 1 | 2011-12-01 Werner Koch 2 | 3 | NB: ChangeLog files are no longer manually maintained. Starting 4 | on December 1st, 2011 we put change information only in the GIT 5 | commit log, and generate a top-level ChangeLog file from logs at 6 | "make dist". See doc/HACKING for details. 7 | 8 | 2011-03-28 Werner Koch 9 | 10 | * ce-server.c: Include sys/select.h if needed. Fixes bug#1328. 11 | 12 | 2010-10-11 Werner Koch 13 | 14 | * Makefile.am (w32cetools): Move ce-server to here. 15 | 16 | 2010-03-17 Werner Koch 17 | 18 | * pipeconnect.c: New. Based on fdpassing.c 19 | 20 | 2010-02-24 Werner Koch 21 | 22 | * ce-server.c: New. 23 | 24 | * ce-createpipe.c [W32CE]: New. 25 | 26 | 2010-01-27 Werner Koch 27 | 28 | * common.h (SOCKET2HANDLE, HANDLE2SOCKET): New. 29 | 30 | 2009-11-05 Marcus Brinkmann 31 | 32 | * fdpassing.c (main): Call assuan_pipe_connect instead 33 | of assuan_pipe_connect_ext. 34 | 35 | 2009-11-04 Werner Koch 36 | 37 | * fdpassing.c (register_commands): Add NULL arg to 38 | assuan_register_command. 39 | 40 | 2009-09-19 Marcus Brinkmann 41 | 42 | * fdpassing.c: Update to new API. 43 | 44 | 2009-08-26 Marcus Brinkmann 45 | 46 | * Makefile.am (AM_CFLAGS, LDADD): Add gpg-error. 47 | * fdpassing.c: Change error values to gpg-error ones. 48 | 49 | 2008-11-03 Marcus Brinkmann 50 | 51 | * fdpassing.c (register_commands): Add missing initializer 52 | to silence gcc -W warning. 53 | 54 | 2006-10-10 Werner Koch 55 | 56 | * Makefile.am (LDADD): Add NETLIBS. 57 | 58 | 2006-09-19 Werner Koch 59 | 60 | * fdpassing.c: Reverted Marcus changes. 61 | (client): New arg FNAME to replace hardwired file name. 62 | (main): Pass motd to client. 63 | * Makefile.am (AM_CPPFLAGS): Removed. 64 | (EXTRA_DIST): Add motd. 65 | 66 | 2006-09-19 Marcus Brinkmann 67 | 68 | * fdpassing.c (MOTD): New macro. 69 | * Makefile.am (AM_CPPFLAGS): New variable. 70 | * motd: New file. 71 | 72 | 73 | Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. 74 | 75 | This file is free software; as a special exception the author gives 76 | unlimited permission to copy and/or distribute it, with or without 77 | modifications, as long as this notice is preserved. 78 | 79 | This file is distributed in the hope that it will be useful, but 80 | WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 81 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 82 | -------------------------------------------------------------------------------- /tests/version.c: -------------------------------------------------------------------------------- 1 | /* version.c - Check the version info fucntions 2 | Copyright (C) 2013 g10 Code GmbH 3 | 4 | This file is part of Assuan. 5 | 6 | Assuan is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU Lesser General Public License as 8 | published by the Free Software Foundation; either version 2.1 of 9 | the License, or (at your option) any later version. 10 | 11 | Assuan is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this program; if not, see . 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include 22 | #endif 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "../src/assuan.h" 30 | #include "common.h" 31 | 32 | 33 | /* 34 | 35 | M A I N 36 | 37 | */ 38 | int 39 | main (int argc, char **argv) 40 | { 41 | int last_argc = -1; 42 | 43 | if (argc) 44 | { 45 | log_set_prefix (*argv); 46 | argc--; argv++; 47 | } 48 | while (argc && last_argc != argc ) 49 | { 50 | last_argc = argc; 51 | if (!strcmp (*argv, "--help")) 52 | { 53 | puts ( 54 | "usage: ./version [options]\n" 55 | "\n" 56 | "Options:\n" 57 | " --verbose Show what is going on\n" 58 | ); 59 | exit (0); 60 | } 61 | if (!strcmp (*argv, "--verbose")) 62 | { 63 | verbose = 1; 64 | argc--; argv++; 65 | } 66 | else if (!strcmp (*argv, "--debug")) 67 | { 68 | verbose = debug = 1; 69 | argc--; argv++; 70 | } 71 | } 72 | 73 | assuan_set_assuan_log_prefix (log_prefix); 74 | 75 | if (!assuan_check_version (ASSUAN_VERSION)) 76 | log_error ("assuan_check_version returned an error\n"); 77 | if (!assuan_check_version ("2.0.99")) 78 | log_error ("assuan_check_version returned an error for an old version\n"); 79 | if (assuan_check_version ("15")) 80 | log_error ("assuan_check_version did not returned an error" 81 | " for a newer version\n"); 82 | if (verbose || errorcount) 83 | { 84 | log_info ("Version from header: %s (0x%06x)\n", 85 | ASSUAN_VERSION, ASSUAN_VERSION_NUMBER); 86 | log_info ("Version from binary: %s \n", assuan_check_version (NULL)); 87 | log_info ("Copyright blurb ...:%s\n", assuan_check_version ("\001\001")); 88 | } 89 | 90 | return errorcount ? 1 : 0; 91 | } 92 | -------------------------------------------------------------------------------- /src/conversion.c: -------------------------------------------------------------------------------- 1 | /* conversion.c - String conversion helper functions. 2 | * Copyright (C) 2000 Werner Koch (dd9jn) 3 | * Copyright (C) 2001, 2002, 2003, 2004, 2007, 2009 g10 Code GmbH 4 | * 5 | * This file is part of Assuan. 6 | * 7 | * Assuan is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Assuan is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | * SPDX-License-Identifier: LGPL-2.1+ 20 | */ 21 | 22 | #if HAVE_CONFIG_H 23 | #include 24 | #endif 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "assuan-defs.h" 32 | #include "debug.h" 33 | 34 | 35 | /* Convert the number NR to a hexadecimal string. Returns the tail 36 | pointer. */ 37 | static char * 38 | _assuan_bytetohex (int nr, char *str) 39 | { 40 | static char hexdigits[] = "0123456789abcdef"; 41 | int i; 42 | 43 | #define NROFHEXDIGITS 2 44 | for (i = 0; i < NROFHEXDIGITS; i++) 45 | { 46 | int digit = (nr >> (i << 2)) & 0xf; 47 | *(str++) = hexdigits[digit]; 48 | } 49 | return str; 50 | } 51 | 52 | 53 | /* Encode the C formatted string SRC and return the malloc'ed result. */ 54 | char * 55 | _assuan_encode_c_string (assuan_context_t ctx, const char *src) 56 | { 57 | const unsigned char *istr; 58 | char *res; 59 | char *ostr; 60 | 61 | ostr = _assuan_malloc (ctx, 4 * strlen (src) + 1); 62 | if (! *ostr) 63 | return NULL; 64 | 65 | res = ostr; 66 | 67 | for (istr = (const unsigned char *) src; *istr; istr++) 68 | { 69 | int c = 0; 70 | 71 | switch (*istr) 72 | { 73 | case '\r': 74 | c = 'r'; 75 | break; 76 | 77 | case '\n': 78 | c = 'n'; 79 | break; 80 | 81 | case '\f': 82 | c = 'f'; 83 | break; 84 | 85 | case '\v': 86 | c = 'v'; 87 | break; 88 | 89 | case '\b': 90 | c = 'b'; 91 | break; 92 | 93 | default: 94 | if ((isascii (*istr) && isprint (*istr)) || (*istr >= 0x80)) 95 | *(ostr++) = *istr; 96 | else 97 | { 98 | *(ostr++) = '\\'; 99 | *(ostr++) = 'x'; 100 | ostr = _assuan_bytetohex (*istr, ostr); 101 | } 102 | } 103 | 104 | if (c) 105 | { 106 | *(ostr++) = '\\'; 107 | *(ostr++) = c; 108 | } 109 | } 110 | *(ostr) = '\0'; 111 | 112 | return res; 113 | } 114 | -------------------------------------------------------------------------------- /m4/ax_cc_for_build.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_cc_for_build.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CC_FOR_BUILD 8 | # 9 | # DESCRIPTION 10 | # 11 | # Find a build-time compiler. Sets CC_FOR_BUILD and EXEEXT_FOR_BUILD. 12 | # 13 | # LICENSE 14 | # 15 | # Copyright (c) 2010 Reuben Thomas 16 | # Copyright (c) 1999 Richard Henderson 17 | # 18 | # This program is free software: you can redistribute it and/or modify it 19 | # under the terms of the GNU General Public License as published by the 20 | # Free Software Foundation, either version 3 of the License, or (at your 21 | # option) any later version. 22 | # 23 | # This program is distributed in the hope that it will be useful, but 24 | # WITHOUT ANY WARRANTY; without even the implied warranty of 25 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 26 | # Public License for more details. 27 | # 28 | # You should have received a copy of the GNU General Public License along 29 | # with this program. If not, see . 30 | # 31 | # As a special exception, the respective Autoconf Macro's copyright owner 32 | # gives unlimited permission to copy, distribute and modify the configure 33 | # scripts that are the output of Autoconf when processing the Macro. You 34 | # need not follow the terms of the GNU General Public License when using 35 | # or distributing such scripts, even though portions of the text of the 36 | # Macro appear in them. The GNU General Public License (GPL) does govern 37 | # all other use of the material that constitutes the Autoconf Macro. 38 | # 39 | # This special exception to the GPL applies to versions of the Autoconf 40 | # Macro released by the Autoconf Archive. When you make and distribute a 41 | # modified version of the Autoconf Macro, you may extend this special 42 | # exception to the GPL to apply to your modified version as well. 43 | 44 | #serial 3 45 | 46 | dnl Get a default for CC_FOR_BUILD to put into Makefile. 47 | AC_DEFUN([AX_CC_FOR_BUILD], 48 | [# Put a plausible default for CC_FOR_BUILD in Makefile. 49 | if test -z "$CC_FOR_BUILD"; then 50 | if test "x$cross_compiling" = "xno"; then 51 | CC_FOR_BUILD='$(CC)' 52 | else 53 | CC_FOR_BUILD=gcc 54 | fi 55 | fi 56 | AC_SUBST(CC_FOR_BUILD) 57 | # Also set EXEEXT_FOR_BUILD. 58 | if test "x$cross_compiling" = "xno"; then 59 | EXEEXT_FOR_BUILD='$(EXEEXT)' 60 | else 61 | AC_CACHE_CHECK([for build system executable suffix], bfd_cv_build_exeext, 62 | [rm -f conftest* 63 | echo 'int main () { return 0; }' > conftest.c 64 | bfd_cv_build_exeext= 65 | ${CC_FOR_BUILD} -o conftest conftest.c 1>&5 2>&5 66 | for file in conftest.*; do 67 | case $file in 68 | *.c | *.o | *.obj | *.ilk | *.pdb) ;; 69 | *) bfd_cv_build_exeext=`echo $file | sed -e s/conftest//` ;; 70 | esac 71 | done 72 | rm -f conftest* 73 | test x"${bfd_cv_build_exeext}" = x && bfd_cv_build_exeext=no]) 74 | EXEEXT_FOR_BUILD="" 75 | test x"${bfd_cv_build_exeext}" != xno && EXEEXT_FOR_BUILD=${bfd_cv_build_exeext} 76 | fi 77 | AC_SUBST(EXEEXT_FOR_BUILD)])dnl 78 | -------------------------------------------------------------------------------- /m4/socklen.m4: -------------------------------------------------------------------------------- 1 | # socklen.m4 serial 11 2 | dnl Copyright (C) 2005-2007, 2009-2020 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Albert Chin, Windows fixes from Simon Josefsson. 8 | 9 | dnl Check for socklen_t: historically on BSD it is an int, and in 10 | dnl POSIX 1g it is a type of its own, but some platforms use different 11 | dnl types for the argument to getsockopt, getpeername, etc.: 12 | dnl HP-UX 10.20, IRIX 6.5, OSF/1 4.0, Interix 3.5, BeOS. 13 | dnl So we have to test to find something that will work. 14 | 15 | AC_DEFUN([gl_TYPE_SOCKLEN_T], 16 | [AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])dnl 17 | AC_CHECK_TYPE([socklen_t], , 18 | [AC_CACHE_CHECK([for socklen_t equivalent], 19 | [gl_cv_socklen_t_equiv], 20 | [# Systems have either "struct sockaddr *" or 21 | # "void *" as the second argument to getpeername 22 | gl_cv_socklen_t_equiv= 23 | for arg2 in "struct sockaddr" void; do 24 | for t in int size_t "unsigned int" "long int" "unsigned long int"; do 25 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM( 26 | [[#include 27 | #include 28 | 29 | int getpeername (int, $arg2 *, $t *);]], 30 | [[$t len; 31 | getpeername (0, 0, &len);]])], 32 | [gl_cv_socklen_t_equiv="$t"]) 33 | test "$gl_cv_socklen_t_equiv" != "" && break 34 | done 35 | test "$gl_cv_socklen_t_equiv" != "" && break 36 | done 37 | if test "$gl_cv_socklen_t_equiv" = ""; then 38 | AC_MSG_ERROR([Cannot find a type to use in place of socklen_t]) 39 | fi 40 | ]) 41 | AC_DEFINE_UNQUOTED([socklen_t], [$gl_cv_socklen_t_equiv], 42 | [type to use in place of socklen_t if not defined])], 43 | [gl_SOCKET_HEADERS])]) 44 | 45 | dnl On mingw32, socklen_t is in ws2tcpip.h ('int'), so we try to find 46 | dnl it there too. But on Cygwin, wc2tcpip.h must not be included. Users 47 | dnl of this module should use the same include pattern as gl_SOCKET_HEADERS. 48 | dnl When you change this macro, keep also in sync: 49 | dnl - gl_CHECK_SOCKET_HEADERS, 50 | dnl - the Include section of modules/socklen. 51 | AC_DEFUN([gl_SOCKET_HEADERS], 52 | [ 53 | /* is not needed according to POSIX, but the 54 | in i386-unknown-freebsd4.10 and 55 | powerpc-apple-darwin5.5 required it. */ 56 | #include 57 | #if HAVE_SYS_SOCKET_H 58 | # include 59 | #elif HAVE_WS2TCPIP_H 60 | # include 61 | #endif 62 | ]) 63 | 64 | dnl Tests for the existence of the header for socket facilities. 65 | dnl Defines the C macros HAVE_SYS_SOCKET_H, HAVE_WS2TCPIP_H. 66 | dnl This macro must match gl_SOCKET_HEADERS. 67 | AC_DEFUN([gl_CHECK_SOCKET_HEADERS], 68 | [AC_CHECK_HEADERS_ONCE([sys/socket.h]) 69 | if test $ac_cv_header_sys_socket_h = no; then 70 | dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make 71 | dnl the check for those headers unconditional; yet cygwin reports 72 | dnl that the headers are present but cannot be compiled (since on 73 | dnl cygwin, all socket information should come from sys/socket.h). 74 | AC_CHECK_HEADERS([ws2tcpip.h]) 75 | fi 76 | ]) 77 | -------------------------------------------------------------------------------- /src/libassuan-config.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc. 3 | # 4 | # This file is free software; as a special exception the author gives 5 | # unlimited permission to copy and/or distribute it, with or without 6 | # modifications, as long as this notice is preserved. 7 | # 8 | # This file is distributed in the hope that it will be useful, but 9 | # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 10 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 | # SPDX-License-Identifier: FSFULLR 12 | 13 | # Configure libgpg-error. 14 | gpg_error_cflags="@GPG_ERROR_CFLAGS@" 15 | gpg_error_libs="@GPG_ERROR_LIBS@" 16 | 17 | PGM=libassuan-config 18 | lib="@LIBASSUAN_CONFIG_LIBS@" 19 | extralibs="$gpg_error_libs" 20 | cflags="@LIBASSUAN_CONFIG_CFLAGS@ $gpg_error_cflags" 21 | api_version="@LIBASSUAN_CONFIG_API_VERSION@" 22 | my_host="@LIBASSUAN_CONFIG_HOST@" 23 | prefix=@prefix@ 24 | exec_prefix=@exec_prefix@ 25 | includes="" 26 | libdirs="" 27 | echo_libs=no 28 | echo_cflags=no 29 | echo_prefix=no 30 | echo_exec_prefix=no 31 | echo_host=no 32 | 33 | 34 | usage() 35 | { 36 | cat <&2 51 | fi 52 | 53 | while test $# -gt 0; do 54 | case "$1" in 55 | -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; 56 | *) optarg= ;; 57 | esac 58 | 59 | case $1 in 60 | --prefix=*) 61 | # Dummy 62 | ;; 63 | --prefix) 64 | echo_prefix=yes 65 | ;; 66 | --exec-prefix=*) 67 | # Dummy 68 | ;; 69 | --exec-prefix) 70 | echo_exec_prefix=yes 71 | ;; 72 | --variable=*) 73 | case "${1#*=}" in 74 | prefix) echo "$prefix" ;; 75 | exec_prefix) echo "$exec_prefix" ;; 76 | host) echo "$my_host" ;; 77 | api_version) echo "$api_version" ;; 78 | esac 79 | exit 0 80 | ;; 81 | --modversion|--version) 82 | echo "@PACKAGE_VERSION@" 83 | exit 0 84 | ;; 85 | --api-version) 86 | echo_api_version=yes 87 | ;; 88 | --cflags) 89 | echo_cflags=yes 90 | ;; 91 | --libs) 92 | echo_libs=yes 93 | ;; 94 | --host) 95 | echo_host=yes 96 | ;; 97 | *) 98 | usage 1 1>&2 99 | ;; 100 | esac 101 | shift 102 | done 103 | 104 | if test "$echo_prefix" = "yes"; then 105 | echo $prefix 106 | fi 107 | 108 | if test "$echo_exec_prefix" = "yes"; then 109 | echo $exec_prefix 110 | fi 111 | 112 | if test "$echo_api_version" = "yes"; then 113 | echo $api_version 114 | fi 115 | 116 | if test "$echo_host" = "yes"; then 117 | echo "$my_host" 118 | fi 119 | 120 | if test "$echo_cflags" = "yes"; then 121 | if test "@includedir@" != "/usr/include" ; then 122 | includes="-I@includedir@" 123 | for i in $cflags ; do 124 | if test "$i" = "-I@includedir@" ; then 125 | includes="" 126 | fi 127 | done 128 | fi 129 | echo $includes $cflags 130 | fi 131 | 132 | if test "$echo_libs" = "yes"; then 133 | if test "@libdir@" != "/usr/lib" ; then 134 | libdirs="-L@libdir@" 135 | for i in $lib $extralibs ; do 136 | if test "$i" = "-L@libdir@" ; then 137 | libdirs="" 138 | fi 139 | done 140 | fi 141 | echo $libdirs $lib $extralibs 142 | fi 143 | -------------------------------------------------------------------------------- /src/libassuan.vers: -------------------------------------------------------------------------------- 1 | # libassuan.vers - List of symbols to export. 2 | # Copyright (C) 2009 g10 Code GmbH 3 | # 4 | # This file is part of LIBASSUAN. 5 | # 6 | # LIBASSUAN is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser general Public License as 8 | # published by the Free Software Foundation; either version 2.1 of 9 | # the License, or (at your option) any later version. 10 | # 11 | # LIBASSUAN is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public 17 | # License along with this program; if not, see . 18 | # SPDX-License-Identifier: LGPL-2.1+ 19 | 20 | #----------------------------------------------------------- 21 | # Please remember to add new functions also to libassuan.def 22 | #----------------------------------------------------------- 23 | 24 | LIBASSUAN_2.0 { 25 | global: 26 | assuan_accept; 27 | assuan_begin_confidential; 28 | assuan_client_read_response; 29 | assuan_client_parse_response; 30 | assuan_close_input_fd; 31 | assuan_close_output_fd; 32 | assuan_command_parse_fd; 33 | assuan_ctx_set_system_hooks; 34 | assuan_end_confidential; 35 | assuan_fdopen; 36 | assuan_get_active_fds; 37 | assuan_get_assuan_log_prefix; 38 | assuan_get_command_name; 39 | assuan_get_data_fp; 40 | assuan_get_flag; 41 | assuan_get_gpg_err_source; 42 | assuan_get_input_fd; 43 | assuan_get_log_cb; 44 | assuan_get_malloc_hooks; 45 | assuan_get_output_fd; 46 | assuan_get_peercred; 47 | assuan_get_pid; 48 | assuan_get_pointer; 49 | assuan_init_pipe_server; 50 | assuan_init_socket_server; 51 | assuan_inquire; 52 | assuan_inquire_ext; 53 | assuan_new; 54 | assuan_new_ext; 55 | assuan_pending_line; 56 | assuan_pipe_connect; 57 | assuan_process; 58 | assuan_process_done; 59 | assuan_process_next; 60 | assuan_read_line; 61 | assuan_receivefd; 62 | assuan_register_bye_notify; 63 | assuan_register_cancel_notify; 64 | assuan_register_command; 65 | assuan_register_input_notify; 66 | assuan_register_option_handler; 67 | assuan_register_output_notify; 68 | assuan_register_pre_cmd_notify; 69 | assuan_register_post_cmd_notify; 70 | assuan_register_reset_notify; 71 | assuan_release; 72 | assuan_send_data; 73 | assuan_sendfd; 74 | assuan_set_assuan_log_prefix; 75 | assuan_set_assuan_log_stream; 76 | assuan_set_error; 77 | assuan_set_flag; 78 | assuan_set_gpg_err_source; 79 | assuan_set_hello_line; 80 | assuan_set_io_monitor; 81 | assuan_set_log_cb; 82 | assuan_set_log_stream; 83 | assuan_set_malloc_hooks; 84 | assuan_set_okay_line; 85 | assuan_set_pointer; 86 | assuan_set_sock_nonce; 87 | assuan_set_system_hooks; 88 | assuan_sock_bind; 89 | assuan_sock_check_nonce; 90 | assuan_sock_close; 91 | assuan_sock_connect; 92 | assuan_sock_deinit; 93 | assuan_sock_get_nonce; 94 | assuan_sock_init; 95 | assuan_sock_new; 96 | assuan_socket_connect; 97 | assuan_transact; 98 | assuan_write_line; 99 | assuan_write_status; 100 | assuan_free; 101 | assuan_socket_connect_fd; 102 | assuan_check_version; 103 | assuan_sock_set_sockaddr_un; 104 | assuan_sock_set_flag; 105 | assuan_sock_get_flag; 106 | assuan_sock_connect_byname; 107 | assuan_sock_set_system_hooks; 108 | assuan_sock_accept; 109 | assuan_pipe_wait_server_termination; 110 | assuan_pipe_kill_server; 111 | assuan_control; 112 | 113 | __assuan_close; 114 | __assuan_pipe; 115 | __assuan_socketpair; 116 | __assuan_spawn; 117 | __assuan_usleep; 118 | __assuan_socket; 119 | __assuan_connect; 120 | __assuan_read; 121 | __assuan_write; 122 | __assuan_recvmsg; 123 | __assuan_sendmsg; 124 | __assuan_waitpid; 125 | 126 | local: 127 | *; 128 | 129 | }; 130 | -------------------------------------------------------------------------------- /mkinstalldirs: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # mkinstalldirs --- make directory hierarchy 3 | 4 | scriptversion=2009-04-28.21; # UTC 5 | 6 | # Original author: Noah Friedman 7 | # Created: 1993-05-16 8 | # Public domain. 9 | # 10 | # This file is maintained in Automake, please report 11 | # bugs to or send patches to 12 | # . 13 | 14 | nl=' 15 | ' 16 | IFS=" "" $nl" 17 | errstatus=0 18 | dirmode= 19 | 20 | usage="\ 21 | Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ... 22 | 23 | Create each directory DIR (with mode MODE, if specified), including all 24 | leading file name components. 25 | 26 | Report bugs to ." 27 | 28 | # process command line arguments 29 | while test $# -gt 0 ; do 30 | case $1 in 31 | -h | --help | --h*) # -h for help 32 | echo "$usage" 33 | exit $? 34 | ;; 35 | -m) # -m PERM arg 36 | shift 37 | test $# -eq 0 && { echo "$usage" 1>&2; exit 1; } 38 | dirmode=$1 39 | shift 40 | ;; 41 | --version) 42 | echo "$0 $scriptversion" 43 | exit $? 44 | ;; 45 | --) # stop option processing 46 | shift 47 | break 48 | ;; 49 | -*) # unknown option 50 | echo "$usage" 1>&2 51 | exit 1 52 | ;; 53 | *) # first non-opt arg 54 | break 55 | ;; 56 | esac 57 | done 58 | 59 | for file 60 | do 61 | if test -d "$file"; then 62 | shift 63 | else 64 | break 65 | fi 66 | done 67 | 68 | case $# in 69 | 0) exit 0 ;; 70 | esac 71 | 72 | # Solaris 8's mkdir -p isn't thread-safe. If you mkdir -p a/b and 73 | # mkdir -p a/c at the same time, both will detect that a is missing, 74 | # one will create a, then the other will try to create a and die with 75 | # a "File exists" error. This is a problem when calling mkinstalldirs 76 | # from a parallel make. We use --version in the probe to restrict 77 | # ourselves to GNU mkdir, which is thread-safe. 78 | case $dirmode in 79 | '') 80 | if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then 81 | echo "mkdir -p -- $*" 82 | exec mkdir -p -- "$@" 83 | else 84 | # On NextStep and OpenStep, the 'mkdir' command does not 85 | # recognize any option. It will interpret all options as 86 | # directories to create, and then abort because '.' already 87 | # exists. 88 | test -d ./-p && rmdir ./-p 89 | test -d ./--version && rmdir ./--version 90 | fi 91 | ;; 92 | *) 93 | if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 && 94 | test ! -d ./--version; then 95 | echo "mkdir -m $dirmode -p -- $*" 96 | exec mkdir -m "$dirmode" -p -- "$@" 97 | else 98 | # Clean up after NextStep and OpenStep mkdir. 99 | for d in ./-m ./-p ./--version "./$dirmode"; 100 | do 101 | test -d $d && rmdir $d 102 | done 103 | fi 104 | ;; 105 | esac 106 | 107 | for file 108 | do 109 | case $file in 110 | /*) pathcomp=/ ;; 111 | *) pathcomp= ;; 112 | esac 113 | oIFS=$IFS 114 | IFS=/ 115 | set fnord $file 116 | shift 117 | IFS=$oIFS 118 | 119 | for d 120 | do 121 | test "x$d" = x && continue 122 | 123 | pathcomp=$pathcomp$d 124 | case $pathcomp in 125 | -*) pathcomp=./$pathcomp ;; 126 | esac 127 | 128 | if test ! -d "$pathcomp"; then 129 | echo "mkdir $pathcomp" 130 | 131 | mkdir "$pathcomp" || lasterr=$? 132 | 133 | if test ! -d "$pathcomp"; then 134 | errstatus=$lasterr 135 | else 136 | if test ! -z "$dirmode"; then 137 | echo "chmod $dirmode $pathcomp" 138 | lasterr= 139 | chmod "$dirmode" "$pathcomp" || lasterr=$? 140 | 141 | if test ! -z "$lasterr"; then 142 | errstatus=$lasterr 143 | fi 144 | fi 145 | fi 146 | fi 147 | 148 | pathcomp=$pathcomp/ 149 | done 150 | done 151 | 152 | exit $errstatus 153 | 154 | # Local Variables: 155 | # mode: shell-script 156 | # sh-indentation: 2 157 | # eval: (add-hook 'write-file-hooks 'time-stamp) 158 | # time-stamp-start: "scriptversion=" 159 | # time-stamp-format: "%:y-%02m-%02d.%02H" 160 | # time-stamp-time-zone: "UTC" 161 | # time-stamp-end: "; # UTC" 162 | # End: 163 | -------------------------------------------------------------------------------- /src/assuan-pipe-server.c: -------------------------------------------------------------------------------- 1 | /* assuan-pipe-server.c - Assuan server working over a pipe 2 | * Copyright (C) 2001, 2002, 2009 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Assuan. 5 | * 6 | * Assuan is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Assuan is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1+ 19 | */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include 26 | #include 27 | #ifdef HAVE_SYS_TYPES_H 28 | # include 29 | #endif 30 | #ifdef HAVE_SYS_STAT_H 31 | # include 32 | #endif 33 | #ifdef HAVE_UNISTD_H 34 | # include 35 | #endif 36 | #ifdef HAVE_W32_SYSTEM 37 | # ifdef HAVE_WINSOCK2_H 38 | # include 39 | # endif 40 | # include 41 | #ifdef HAVE_FCNTL_H 42 | # include 43 | #endif 44 | #endif 45 | 46 | #include "assuan-defs.h" 47 | #include "debug.h" 48 | 49 | /* Returns true if atoi(S) denotes a valid socket. */ 50 | #ifndef HAVE_W32_SYSTEM 51 | static int 52 | is_valid_socket (const char *s) 53 | { 54 | struct stat buf; 55 | 56 | if ( fstat (atoi (s), &buf ) ) 57 | return 0; 58 | return S_ISSOCK (buf.st_mode); 59 | } 60 | #endif /*!HAVE_W32_SYSTEM*/ 61 | 62 | 63 | /* This actually is a int file descriptor (and not assuan_fd_t) as 64 | _get_osfhandle is called on W32 systems. */ 65 | gpg_error_t 66 | assuan_init_pipe_server (assuan_context_t ctx, assuan_fd_t filedes[2]) 67 | { 68 | #if !defined(HAVE_W32_SYSTEM) 69 | const char *s; 70 | unsigned long ul; 71 | #endif 72 | gpg_error_t rc; 73 | assuan_fd_t infd = ASSUAN_INVALID_FD; 74 | assuan_fd_t outfd = ASSUAN_INVALID_FD; 75 | int is_usd = 0; 76 | TRACE_BEG (ctx, ASSUAN_LOG_CTX, "assuan_init_pipe_server", ctx); 77 | if (filedes) 78 | { 79 | TRACE_LOG2 ("fd[0]=0x%x, fd[1]=0x%x", filedes[0], filedes[1]); 80 | } 81 | 82 | rc = _assuan_register_std_commands (ctx); 83 | if (rc) 84 | return TRACE_ERR (rc); 85 | 86 | #ifdef HAVE_W32_SYSTEM 87 | if (filedes) 88 | { 89 | infd = filedes[0]; 90 | outfd = filedes[1]; 91 | } 92 | else 93 | { 94 | infd = assuan_fd_from_posix_fd (0); 95 | outfd = assuan_fd_from_posix_fd (1); 96 | } 97 | #else 98 | s = getenv ("_assuan_connection_fd"); 99 | if (s && *s && is_valid_socket (s)) 100 | { 101 | /* Well, we are called with an bi-directional file descriptor. 102 | Prepare for using sendmsg/recvmsg. In this case we ignore 103 | the passed file descriptors. */ 104 | infd = atoi (s); 105 | outfd = atoi (s); 106 | is_usd = 1; 107 | 108 | } 109 | else if (filedes && filedes[0] != ASSUAN_INVALID_FD 110 | && filedes[1] != ASSUAN_INVALID_FD ) 111 | { 112 | /* Standard pipe server. */ 113 | infd = filedes[0]; 114 | outfd = filedes[1]; 115 | } 116 | else 117 | { 118 | rc = _assuan_error (ctx, GPG_ERR_ASS_SERVER_START); 119 | return TRACE_ERR (rc); 120 | } 121 | #endif 122 | 123 | ctx->flags.is_server = 1; 124 | ctx->engine.release = _assuan_server_release; 125 | ctx->engine.readfnc = _assuan_simple_read; 126 | ctx->engine.writefnc = _assuan_simple_write; 127 | ctx->engine.sendfd = NULL; 128 | #ifdef HAVE_W32_SYSTEM 129 | ctx->engine.receivefd = w32_fdpass_recv; 130 | #else 131 | ctx->engine.receivefd = NULL; 132 | #endif 133 | ctx->max_accepts = 1; 134 | 135 | #if !defined(HAVE_W32_SYSTEM) 136 | s = getenv ("_assuan_pipe_connect_pid"); 137 | if (s && (ul=strtoul (s, NULL, 10)) && ul) 138 | ctx->pid = (pid_t)ul; 139 | else 140 | ctx->pid = (pid_t)-1; 141 | #endif 142 | ctx->accept_handler = NULL; 143 | ctx->finish_handler = _assuan_server_finish; 144 | ctx->inbound.fd = infd; 145 | ctx->outbound.fd = outfd; 146 | 147 | if (is_usd) 148 | _assuan_init_uds_io (ctx); 149 | 150 | return TRACE_SUC(); 151 | } 152 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | # Assuan Makefile 2 | # Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc. 3 | # 4 | # This file is part of Assuan. 5 | # 6 | # Assuan is free software; you can redistribute it and/or modify it 7 | # under the terms of the GNU Lesser General Public License as 8 | # published by the Free Software Foundation; either version 2.1 of 9 | # the License, or (at your option) any later version. 10 | # 11 | # Assuan is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public 17 | # License along with this program; if not, see . 18 | # 19 | # SPDX-License-Identifier: LGPL-2.1+ 20 | ## Process this file with automake to produce Makefile.in 21 | 22 | pkgconfigdir = $(libdir)/pkgconfig 23 | pkgconfig_DATA = libassuan.pc 24 | 25 | EXTRA_DIST = libassuan-config.in libassuan.m4 libassuan.vers \ 26 | versioninfo.rc.in libassuan.def mkheader.c \ 27 | libassuan.pc.in 28 | AM_CPPFLAGS = -I.. 29 | 30 | if USE_GPGRT_CONFIG 31 | noinst_SCRIPTS = libassuan-config 32 | else 33 | bin_SCRIPTS = libassuan-config 34 | endif 35 | m4datadir = $(datadir)/aclocal 36 | m4data_DATA = libassuan.m4 37 | lib_LTLIBRARIES = libassuan.la 38 | nodist_include_HEADERS = assuan.h 39 | 40 | if HAVE_LD_VERSION_SCRIPT 41 | libassuan_version_script_cmd = -Wl,--version-script=$(srcdir)/libassuan.vers 42 | else 43 | libassuan_version_script_cmd = 44 | endif 45 | 46 | CLEANFILES = mkheader assuan.h 47 | 48 | BUILT_SOURCES = assuan.h 49 | 50 | parts_of_assuan_h = \ 51 | posix-includes.inc.h w32-includes.inc.h \ 52 | posix-types.inc.h w32-types.inc.h \ 53 | posix-fd-t.inc.h w32-fd-t.inc.h \ 54 | posix-sock-nonce.inc.h w32-sock-nonce.inc.h 55 | 56 | common_sources = \ 57 | assuan.h.in $(parts_of_assuan_h) \ 58 | assuan-defs.h \ 59 | assuan.c context.c system.c \ 60 | debug.c debug.h conversion.c sysutils.c \ 61 | client.c server.c \ 62 | assuan-error.c \ 63 | assuan-buffer.c \ 64 | assuan-handler.c \ 65 | assuan-inquire.c \ 66 | assuan-listen.c \ 67 | assuan-pipe-server.c \ 68 | assuan-socket-server.c \ 69 | assuan-pipe-connect.c \ 70 | assuan-socket-connect.c \ 71 | assuan-uds.c \ 72 | assuan-logging.c \ 73 | assuan-socket.c 74 | 75 | if HAVE_W32_SYSTEM 76 | common_sources += system-w32.c 77 | else 78 | common_sources += system-posix.c 79 | endif 80 | 81 | 82 | if HAVE_W32_SYSTEM 83 | 84 | LTRCCOMPILE = $(LIBTOOL) --mode=compile $(RC) \ 85 | `echo $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) | \ 86 | sed -e 's/-I/--include-dir /g;s/-D/--define /g'` 87 | 88 | SUFFIXES: .rc .lo 89 | 90 | .rc.lo: 91 | $(LTRCCOMPILE) -i $< -o $@ 92 | 93 | libassuan_res = versioninfo.lo 94 | libassuan_res_ldflag = -Wl,.libs/versioninfo.o 95 | 96 | no_undefined = -no-undefined 97 | export_symbols = -export-symbols $(srcdir)/libassuan.def 98 | extra_ltoptions = -XCClinker -static-libgcc 99 | 100 | install-def-file: 101 | $(INSTALL) $(srcdir)/libassuan.def $(DESTDIR)$(libdir)/libassuan.def 102 | 103 | uninstall-def-file: 104 | -rm $(DESTDIR)$(libdir)/libassuan.def 105 | 106 | libassuan_deps = $(libassuan_res) libassuan.def 107 | 108 | else 109 | libassuan_res = 110 | libassuan_res_ldflag = 111 | no_undefined = 112 | export_symbols = 113 | extra_ltoptions = 114 | 115 | install-def-file: 116 | uninstall-def-file: 117 | 118 | libassuan_deps = 119 | endif 120 | 121 | 122 | libassuan_la_SOURCES = $(common_sources) assuan-io.c 123 | nodist_libassuan_la_SOURCES = assuan.h 124 | libassuan_la_CPPFLAGS = $(AM_CPPFLAGS) @GPG_ERROR_CFLAGS@ 125 | libassuan_la_LDFLAGS = $(libassuan_res_ldflag) $(no_undefined) \ 126 | $(extra_ltoptions) \ 127 | $(export_symbols) $(libassuan_version_script_cmd) -version-info \ 128 | @LIBASSUAN_LT_CURRENT@:@LIBASSUAN_LT_REVISION@:@LIBASSUAN_LT_AGE@ 129 | libassuan_la_DEPENDENCIES = @LTLIBOBJS@ \ 130 | $(srcdir)/libassuan.vers $(libassuan_deps) 131 | libassuan_la_LIBADD = @LTLIBOBJS@ @NETLIBS@ @GPG_ERROR_LIBS@ 132 | 133 | mkheader$(EXEEXT_FOR_BUILD): mkheader.c Makefile 134 | $(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) \ 135 | $(LDFLAGS_FOR_BUILD) -I. -I$(srcdir) -o $@ $(srcdir)/mkheader.c 136 | 137 | assuan.h: assuan.h.in mkheader$(EXEEXT_FOR_BUILD) $(parts_of_assuan_h) 138 | ./mkheader$(EXEEXT_FOR_BUILD) $(host_os) $(srcdir)/assuan.h.in \ 139 | $(PACKAGE_VERSION) $(VERSION_NUMBER) >$@ 140 | -------------------------------------------------------------------------------- /src/libassuan.def: -------------------------------------------------------------------------------- 1 | ; assuan.def - List of symbols to export. 2 | ; Copyright (C) 2005, 2009 g10 Code GmbH 3 | ; 4 | ; This file is part of ASSUAN. 5 | ; 6 | ; ASSUAN is free software; you can redistribute it and/or modify 7 | ; it under the terms of the GNU Lesser general Public License as 8 | ; published by the Free Software Foundation; either version 2.1 of 9 | ; the License, or (at your option) any later version. 10 | ; 11 | ; ASSUAN is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU Lesser General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU Lesser General Public 17 | ; License along with this program; if not, see . 18 | ; SPDX-License-Identifier: LGPL-2.1+ 19 | 20 | 21 | EXPORTS 22 | assuan_accept @1 23 | assuan_begin_confidential @2 24 | assuan_close_input_fd @3 25 | assuan_close_output_fd @4 26 | assuan_command_parse_fd @5 27 | assuan_ctx_set_system_hooks @6 28 | assuan_end_confidential @7 29 | assuan_get_active_fds @8 30 | assuan_get_assuan_log_prefix @9 31 | assuan_get_command_name @10 32 | assuan_get_data_fp @11 33 | assuan_get_flag @12 34 | assuan_get_gpg_err_source @13 35 | assuan_get_input_fd @14 36 | assuan_get_log_cb @15 37 | assuan_get_malloc_hooks @16 38 | assuan_get_output_fd @17 39 | assuan_get_peercred @18 40 | assuan_get_pid @19 41 | assuan_get_pointer @20 42 | assuan_init_pipe_server @21 43 | assuan_init_socket_server @22 44 | assuan_inquire @23 45 | assuan_inquire_ext @24 46 | assuan_new @25 47 | assuan_new_ext @26 48 | assuan_pending_line @27 49 | assuan_pipe_connect @28 50 | assuan_process @29 51 | assuan_process_done @30 52 | assuan_process_next @31 53 | assuan_read_line @32 54 | assuan_receivefd @33 55 | assuan_register_bye_notify @34 56 | assuan_register_cancel_notify @35 57 | assuan_register_command @36 58 | assuan_register_input_notify @37 59 | assuan_register_option_handler @38 60 | assuan_register_output_notify @39 61 | assuan_register_post_cmd_notify @40 62 | assuan_register_reset_notify @41 63 | assuan_release @42 64 | assuan_send_data @43 65 | assuan_sendfd @44 66 | assuan_set_assuan_log_prefix @45 67 | assuan_set_assuan_log_stream @46 68 | assuan_set_error @47 69 | assuan_set_flag @48 70 | assuan_set_gpg_err_source @49 71 | assuan_set_hello_line @50 72 | assuan_set_io_monitor @51 73 | assuan_set_log_cb @52 74 | assuan_set_log_stream @53 75 | assuan_set_malloc_hooks @54 76 | assuan_set_okay_line @55 77 | assuan_set_pointer @56 78 | assuan_set_system_hooks @57 79 | assuan_sock_bind @58 80 | assuan_sock_check_nonce @59 81 | assuan_sock_close @60 82 | assuan_sock_connect @61 83 | assuan_sock_deinit @62 84 | assuan_sock_get_nonce @63 85 | assuan_sock_init @64 86 | assuan_sock_new @65 87 | assuan_socket_connect @66 88 | assuan_transact @67 89 | assuan_write_line @68 90 | assuan_write_status @69 91 | __assuan_close @70 92 | __assuan_pipe @71 93 | __assuan_socketpair @72 94 | __assuan_spawn @73 95 | __assuan_usleep @74 96 | assuan_fdopen @75 97 | assuan_client_read_response @76 98 | assuan_client_parse_response @77 99 | assuan_set_sock_nonce @78 100 | _assuan_w32ce_create_pipe @79 101 | assuan_free @80 102 | _assuan_w32ce_prepare_pipe @81 103 | _assuan_w32ce_finish_pipe @82 104 | __assuan_socket @83 105 | __assuan_connect @84 106 | assuan_register_pre_cmd_notify @85 107 | assuan_socket_connect_fd @86 108 | __assuan_read @87 109 | __assuan_write @88 110 | __assuan_recvmsg @89 111 | __assuan_sendmsg @90 112 | __assuan_waitpid @91 113 | assuan_check_version @92 114 | assuan_sock_set_sockaddr_un @93 115 | assuan_sock_set_flag @94 116 | assuan_sock_get_flag @95 117 | assuan_sock_connect_byname @96 118 | assuan_sock_set_system_hooks @97 119 | assuan_sock_accept @98 120 | assuan_pipe_wait_server_termination @99 121 | assuan_pipe_kill_server @100 122 | assuan_control @101 123 | 124 | ; END 125 | 126 | -------------------------------------------------------------------------------- /m4/ltsugar.m4: -------------------------------------------------------------------------------- 1 | # ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- 2 | # 3 | # Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. 4 | # Written by Gary V. Vaughan, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # serial 6 ltsugar.m4 11 | 12 | # This is to help aclocal find these macros, as it can't see m4_define. 13 | AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) 14 | 15 | 16 | # lt_join(SEP, ARG1, [ARG2...]) 17 | # ----------------------------- 18 | # Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their 19 | # associated separator. 20 | # Needed until we can rely on m4_join from Autoconf 2.62, since all earlier 21 | # versions in m4sugar had bugs. 22 | m4_define([lt_join], 23 | [m4_if([$#], [1], [], 24 | [$#], [2], [[$2]], 25 | [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])]) 26 | m4_define([_lt_join], 27 | [m4_if([$#$2], [2], [], 28 | [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])]) 29 | 30 | 31 | # lt_car(LIST) 32 | # lt_cdr(LIST) 33 | # ------------ 34 | # Manipulate m4 lists. 35 | # These macros are necessary as long as will still need to support 36 | # Autoconf-2.59 which quotes differently. 37 | m4_define([lt_car], [[$1]]) 38 | m4_define([lt_cdr], 39 | [m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], 40 | [$#], 1, [], 41 | [m4_dquote(m4_shift($@))])]) 42 | m4_define([lt_unquote], $1) 43 | 44 | 45 | # lt_append(MACRO-NAME, STRING, [SEPARATOR]) 46 | # ------------------------------------------ 47 | # Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'. 48 | # Note that neither SEPARATOR nor STRING are expanded; they are appended 49 | # to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked). 50 | # No SEPARATOR is output if MACRO-NAME was previously undefined (different 51 | # than defined and empty). 52 | # 53 | # This macro is needed until we can rely on Autoconf 2.62, since earlier 54 | # versions of m4sugar mistakenly expanded SEPARATOR but not STRING. 55 | m4_define([lt_append], 56 | [m4_define([$1], 57 | m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])]) 58 | 59 | 60 | 61 | # lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...]) 62 | # ---------------------------------------------------------- 63 | # Produce a SEP delimited list of all paired combinations of elements of 64 | # PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list 65 | # has the form PREFIXmINFIXSUFFIXn. 66 | # Needed until we can rely on m4_combine added in Autoconf 2.62. 67 | m4_define([lt_combine], 68 | [m4_if(m4_eval([$# > 3]), [1], 69 | [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl 70 | [[m4_foreach([_Lt_prefix], [$2], 71 | [m4_foreach([_Lt_suffix], 72 | ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[, 73 | [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])]) 74 | 75 | 76 | # lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ]) 77 | # ----------------------------------------------------------------------- 78 | # Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited 79 | # by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ. 80 | m4_define([lt_if_append_uniq], 81 | [m4_ifdef([$1], 82 | [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1], 83 | [lt_append([$1], [$2], [$3])$4], 84 | [$5])], 85 | [lt_append([$1], [$2], [$3])$4])]) 86 | 87 | 88 | # lt_dict_add(DICT, KEY, VALUE) 89 | # ----------------------------- 90 | m4_define([lt_dict_add], 91 | [m4_define([$1($2)], [$3])]) 92 | 93 | 94 | # lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE) 95 | # -------------------------------------------- 96 | m4_define([lt_dict_add_subkey], 97 | [m4_define([$1($2:$3)], [$4])]) 98 | 99 | 100 | # lt_dict_fetch(DICT, KEY, [SUBKEY]) 101 | # ---------------------------------- 102 | m4_define([lt_dict_fetch], 103 | [m4_ifval([$3], 104 | m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]), 105 | m4_ifdef([$1($2)], [m4_defn([$1($2)])]))]) 106 | 107 | 108 | # lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE]) 109 | # ----------------------------------------------------------------- 110 | m4_define([lt_if_dict_fetch], 111 | [m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4], 112 | [$5], 113 | [$6])]) 114 | 115 | 116 | # lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...]) 117 | # -------------------------------------------------------------- 118 | m4_define([lt_dict_filter], 119 | [m4_if([$5], [], [], 120 | [lt_join(m4_quote(m4_default([$4], [[, ]])), 121 | lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]), 122 | [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl 123 | ]) 124 | -------------------------------------------------------------------------------- /doc/HACKING: -------------------------------------------------------------------------------- 1 | # HACKING -*- org -*- 2 | #+TITLE: Hacking notes for Libassuan 3 | #+STARTUP: showall 4 | 5 | * How to contribute 6 | 7 | The following stuff explains some basic procedures you need to 8 | follow if you want to contribute code or documentation. 9 | 10 | ** No more ChangeLog files 11 | 12 | Do not modify any of the ChangeLog files in Libassuan. Starting 13 | on December 1st, 2011 we put change information only in the GIT 14 | commit log, and generate a top-level ChangeLog file from logs at 15 | "make dist" time. As such, there are strict requirements on the 16 | form of the commit log messages. The old ChangeLog files have all 17 | be renamed to ChangeLog-2011 18 | 19 | 20 | ** Coding standards 21 | 22 | Please follow the GNU coding standards. If you are in doubt consult 23 | the existing code as an example. Do no re-indent code without a 24 | need. If you really need to do it, use a separate commit for such a 25 | change. See below for the required commit log format. 26 | 27 | ** Commit log requirements 28 | 29 | Your commit log should always start with a one-line summary, the 30 | second line should be blank, and the remaining lines are usually 31 | ChangeLog-style entries for all affected files. However, it's fine 32 | -- even recommended -- to write a few lines of prose describing the 33 | change, when the summary and ChangeLog entries don't give enough of 34 | the big picture. Omit the leading TABs that you're used to seeing 35 | in a "real" ChangeLog file, but keep the maximum line length at 72 36 | or smaller, so that the generated ChangeLog lines, each with its 37 | leading TAB, will not exceed 80 columns. 38 | 39 | Here is an example of a commit message: 40 | #+begin_example 41 | Make new functions also visible on non-W32. 42 | 43 | * src/system-posix.c (__assuan_read, __assuan_write, __assuan_recvmsg) 44 | (__assuan_sendmsg, __assuan_waitpid): Make functions global. 45 | * src/libassuan.vers: Add above functions. 46 | * configure.ac: Set version to 2.1.0-git. 47 | -- 48 | Note that everything after the above tear off marker will not be 49 | copied to the ChangeLog during a "make dist". You may use this to add 50 | extra information about this commit which are mostly relevant for your 51 | co-hackers. Recall that the ChangeLog itself fulfills requirements of 52 | the GPL and is useful for quick history checks of a released version. 53 | Developers will use the git log. 54 | #+end_example 55 | 56 | If you don't want a ChangeLog entry at all, use this: 57 | #+begin_example 58 | Give examples for commit logs. 59 | 60 | -- 61 | Because the tear off line is the first line of the body, not even the 62 | summary line will be copied to the ChangeLog. Using only the tear off 63 | line without any text is often useful for commits like "Typo and 64 | grammar fixes." 65 | #+end_example 66 | 67 | 68 | ** License policy 69 | 70 | Libassuan is currently licensed under the LGPLv2+ with tools and the 71 | manual being under the GPLv3+. We may eventually update to a newer 72 | version of the licenses or a combination of them. It is thus 73 | important, that all contributed code allows for an update of the 74 | license; in particular we can't accept code under the GPL or LGPL 75 | without the "or any later version" term. 76 | 77 | Being developed as part of GnuPG-2, Libassuan used to have a strict 78 | policy of requiring copyright assignments to the FSF. To avoid this 79 | major organizational overhead and to allow inclusion of code, not 80 | copyrighted by the FSF, this policy has been relaxed. It is now 81 | also possible to contribute code by asserting that the contribution 82 | is in accordance to the "Libassuan Developer's Certificate of 83 | Origin" as found in the file "DCO". (Except for a slight wording 84 | change, this DCO is identical to the one used by the Linux kernel.) 85 | 86 | If your want to contribute code or documentation to Libassuan and 87 | you didn't signed a copyright assignment with the FSF in the past, 88 | you need to take these simple steps: 89 | 90 | - Decide which mail address you want to use. Please have your real 91 | name in the address and not a pseudonym. Anonymous contributions 92 | can only be done if you find a proxy who certifies for you. 93 | 94 | - If your employer or school might claim ownership of code written 95 | by you; you need to talk to them to make sure that you have the 96 | right to contribute under the DCO. 97 | 98 | - Send an OpenPGP signed mail to the gnupg-devel@gnupg.org mailing 99 | list from your mail address. Include a copy of the DCO as found 100 | in the official master branch. Insert your name and email address 101 | into the DCO in the same way you want to use it later. Example: 102 | 103 | Signed-off-by: Joe R. Hacker 104 | 105 | (If you really need it, you may perform simple transformations of 106 | the mail address: Replacing "@" by " at " or "." by " dot ".) 107 | 108 | - That's it. From now on you only need to add a "Signed-off-by:" 109 | line with your name and mail address to the commit message. It is 110 | recommended to send the patches using a PGP/MIME signed mail. 111 | -------------------------------------------------------------------------------- /doc/ChangeLog-2011: -------------------------------------------------------------------------------- 1 | 2011-12-01 Werner Koch 2 | 3 | NB: ChangeLog files are no longer manually maintained. Starting 4 | on December 1st, 2011 we put change information only in the GIT 5 | commit log, and generate a top-level ChangeLog file from logs at 6 | "make dist". See doc/HACKING for details. 7 | 8 | 2009-12-08 Marcus Brinkmann 9 | 10 | * assuan.texi: Use our own copy of the setfont macro, as it takes 11 | an extra argument since texinfo 4.13. 12 | 13 | * assuan.texi (Contexts): Document ASSUAN_SPAWN_DETACHED. 14 | 15 | 2009-11-25 Marcus Brinkmann 16 | 17 | * assuan.texi (Data Types): Document assuan_fdopen. 18 | 19 | 2009-11-24 Marcus Brinkmann 20 | 21 | * assuan.texi: Remove assuan_disconnect, assuan_deinit_server. 22 | Many smaller API fixes. 23 | 24 | 2009-11-10 Marcus Brinkmann 25 | 26 | * assuan.texi: Various fixes and updates for the new interface. 27 | 28 | 2009-11-05 Marcus Brinkmann 29 | 30 | * assuan.texi: Update assuan_pipe_connect, assuan_socket_connect 31 | and assuan_init_socket_connect. 32 | (Client code): Document ASSUAN_PIPE_CONNECT_FDPASSING and 33 | ASSUAN_PIPE_CONNECT_DETACHED. 34 | (Server code): Document ASSUAN_SOCKET_SERVER_FDPASSING and 35 | ASSUAN_SOCKET_SERVER_ACCEPTED. 36 | (Utilities): Update documentation of assuan_get_peercred. 37 | 38 | * assuan.texi (External I/O Loop Server): Document change to 39 | assuan_process_next. 40 | 41 | 2009-10-16 Marcus Brinkmann 42 | 43 | * assuan.texi: Remove documentation for thread support. 44 | (assuan_pipe_connect_ext): Update prototype. 45 | 46 | 2009-10-14 Werner Koch 47 | 48 | * assuan.texi (Utilities): Describe assuan_get_command_name. 49 | 50 | 2009-09-21 Marcus Brinkmann 51 | 52 | * assuan.texi: Update to new API. 53 | 54 | 2009-09-01 Marcus Brinkmann 55 | 56 | * assuan.texi: (External I/O Loop Server): Document 57 | assuan_process_done. 58 | (assuan_register_post_cmd_notify): Change type of ERR from int to 59 | gpg_error_t. 60 | (assuan_set_error): Likewise. 61 | (assuan_register_option_handler): Change types in callback handler 62 | from int to gpg_error_t. 63 | (assuan_inquire_ext): Likewise. 64 | 65 | 2009-08-28 Marcus Brinkmann 66 | 67 | * assuan.texi: Update to API changes. 68 | (Data Types): Remove assuan_error_t. 69 | (Utilities): Remove assuan_strerror. 70 | 71 | 2008-10-29 Marcus Brinkmann 72 | 73 | * assuan.texi: Change return type of callback handlers in 74 | assuan_transact. 75 | 76 | 2007-11-14 Werner Koch 77 | 78 | * assuan.texi (Client code): Describe the new flag bit 7 of the 79 | pipe_server_connect_ext function. 80 | 81 | 2007-10-18 Marcus Brinkmann 82 | 83 | * assuan.texi (Client requests): Document HELP. 84 | 85 | 2007-09-07 Moritz Schulte 86 | 87 | * assuan.texi (Client code): mention assuan_send_data() instead of 88 | assuan_write_data(). 89 | 90 | 2007-09-03 Marcus Brinkmann 91 | 92 | * assuan.texi: Fix prototype and documentation for 93 | assuan_inquire_ext. 94 | 95 | 2007-08-24 Werner Koch 96 | 97 | * lgpl.texi: Replace by LGPLv2.1 version. 98 | 99 | 2007-08-09 Marcus Brinkmann 100 | 101 | * assuan.texi (External I/O Loop): New chapter. 102 | 103 | 2007-07-12 Werner Koch 104 | 105 | * assuan.texi (Utilities): Document that under W32 we return a 106 | system handle. 107 | 108 | 2007-07-05 Werner Koch 109 | 110 | * lgpl.texi: New. Taken from COPYING.LIB and reformatted. 111 | * gpl.texi: Updated to v3. 112 | 113 | * assuan.texi (Utilities): Explain ASSUAN_CONFIDENTIAL. 114 | 115 | 2007-05-06 Marcus Brinkmann 116 | 117 | * assuan.texi: Clean up typos. 118 | 119 | 2006-10-31 Werner Koch 120 | 121 | * assuan.texi: Finished. 122 | 123 | 2003-12-18 Werner Koch 124 | 125 | * assuan.texi: Changed copyright to GPL because this is not a book 126 | but useful documentation in other software too. Reworked 127 | sectioning, updated list of error codes. 128 | * gpl.texi: Added. 129 | * fdl.texi: Removed. 130 | 131 | 2003-08-06 Werner Koch 132 | 133 | * lgpl.texi: New. 134 | * gpl.texi: Removed. 135 | * assuan.texi: Dropped requirement vor invariant sections, 136 | front- and back-cover texts. Include lgpg.texi. 137 | 138 | 2003-02-18 Neal H. Walfield 139 | 140 | * Makefile.am: New file. 141 | * fdl.texi: New file. 142 | * gpl.texi: New file. 143 | * assuan.texi: Imported from newpg. 144 | 145 | 146 | Copyright 2003, 2006, 2007 Free Software Foundation, Inc. 147 | 148 | This file is free software; as a special exception the author gives 149 | unlimited permission to copy and/or distribute it, with or without 150 | modifications, as long as this notice is preserved. 151 | 152 | This file is distributed in the hope that it will be useful, but 153 | WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 154 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 155 | -------------------------------------------------------------------------------- /src/debug.c: -------------------------------------------------------------------------------- 1 | /* debug.c - helpful output in desperate situations 2 | Copyright (C) 2000 Werner Koch (dd9jn) 3 | Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2009 g10 Code GmbH 4 | 5 | This file is part of Assuan. 6 | 7 | Assuan is free software; you can redistribute it and/or modify it 8 | under the terms of the GNU Lesser General Public License as 9 | published by the Free Software Foundation; either version 2.1 of 10 | the License, or (at your option) any later version. 11 | 12 | Assuan is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this program; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 20 | MA 02110-1301, USA. */ 21 | 22 | #if HAVE_CONFIG_H 23 | #include 24 | #endif 25 | #include 26 | #include 27 | #include 28 | #include 29 | #ifdef HAVE_UNISTD_H 30 | # include 31 | #endif 32 | #include 33 | #include 34 | #ifndef HAVE_DOSISH_SYSTEM 35 | # include 36 | # include 37 | # include 38 | #endif 39 | #include 40 | 41 | #include "assuan-defs.h" 42 | #include "debug.h" 43 | 44 | 45 | /* Log the formatted string FORMAT at debug category CAT higher. */ 46 | void 47 | _assuan_debug (assuan_context_t ctx, unsigned int cat, const char *format, ...) 48 | { 49 | va_list arg_ptr; 50 | int saved_errno; 51 | char *msg; 52 | int res; 53 | 54 | /* vasprintf is an expensive operation thus we first check whether 55 | the callback has enabled CAT for logging. */ 56 | if (!ctx 57 | || !ctx->log_cb 58 | || !(*ctx->log_cb) (ctx, ctx->log_cb_data, cat, NULL)) 59 | return; 60 | 61 | saved_errno = errno; 62 | va_start (arg_ptr, format); 63 | res = gpgrt_vasprintf (&msg, format, arg_ptr); 64 | va_end (arg_ptr); 65 | if (res < 0) 66 | return; 67 | ctx->log_cb (ctx, ctx->log_cb_data, cat, msg); 68 | gpgrt_free (msg); 69 | gpg_err_set_errno (saved_errno); 70 | } 71 | 72 | 73 | /* Start a new debug line in *LINE, logged at level LEVEL or higher, 74 | and starting with the formatted string FORMAT. */ 75 | void 76 | _assuan_debug_begin (assuan_context_t ctx, 77 | void **line, unsigned int cat, const char *format, ...) 78 | { 79 | va_list arg_ptr; 80 | int res; 81 | 82 | *line = NULL; 83 | /* Probe if this wants to be logged based on category. */ 84 | if (! ctx 85 | || ! ctx->log_cb 86 | || ! (*ctx->log_cb) (ctx, ctx->log_cb_data, cat, NULL)) 87 | return; 88 | 89 | va_start (arg_ptr, format); 90 | res = gpgrt_vasprintf ((char **) line, format, arg_ptr); 91 | va_end (arg_ptr); 92 | if (res < 0) 93 | *line = NULL; 94 | } 95 | 96 | 97 | /* Add the formatted string FORMAT to the debug line *LINE. */ 98 | void 99 | _assuan_debug_add (assuan_context_t ctx, void **line, const char *format, ...) 100 | { 101 | va_list arg_ptr; 102 | char *toadd; 103 | char *result; 104 | int res; 105 | 106 | if (!*line) 107 | return; 108 | 109 | va_start (arg_ptr, format); 110 | res = gpgrt_vasprintf (&toadd, format, arg_ptr); 111 | va_end (arg_ptr); 112 | if (res < 0) 113 | { 114 | gpgrt_free (*line); 115 | *line = NULL; 116 | } 117 | res = gpgrt_asprintf (&result, "%s%s", *(char **) line, toadd); 118 | gpgrt_free (toadd); 119 | gpgrt_free (*line); 120 | if (res < 0) 121 | *line = NULL; 122 | else 123 | *line = result; 124 | } 125 | 126 | 127 | /* Finish construction of *LINE and send it to the debug output 128 | stream. */ 129 | void 130 | _assuan_debug_end (assuan_context_t ctx, void **line, unsigned int cat) 131 | { 132 | if (!*line) 133 | return; 134 | 135 | /* Force logging here by using category ~0. */ 136 | _assuan_debug (ctx, ~0, "%s", *line); 137 | gpgrt_free (*line); 138 | *line = NULL; 139 | } 140 | 141 | 142 | #define TOHEX(val) (((val) < 10) ? ((val) + '0') : ((val) - 10 + 'a')) 143 | 144 | void 145 | _assuan_debug_buffer (assuan_context_t ctx, unsigned int cat, 146 | const char *const fmt, const char *const func, 147 | const char *const tagname, void *tag, 148 | const char *const buffer, size_t len) 149 | { 150 | int idx = 0; 151 | int j; 152 | 153 | /* Probe if this wants to be logged based on category. */ 154 | if (!ctx 155 | || ! ctx->log_cb 156 | || ! (*ctx->log_cb) (ctx, ctx->log_cb_data, cat, NULL)) 157 | return; 158 | 159 | while (idx < len) 160 | { 161 | char str[51]; 162 | char *strp = str; 163 | char *strp2 = &str[34]; 164 | 165 | for (j = 0; j < 16; j++) 166 | { 167 | unsigned char val; 168 | if (idx < len) 169 | { 170 | val = buffer[idx++]; 171 | *(strp++) = TOHEX (val >> 4); 172 | *(strp++) = TOHEX (val % 16); 173 | *(strp2++) = isprint (val) ? val : '.'; 174 | } 175 | else 176 | { 177 | *(strp++) = ' '; 178 | *(strp++) = ' '; 179 | } 180 | if (j == 7) 181 | *(strp++) = ' '; 182 | } 183 | *(strp++) = ' '; 184 | *(strp2++) = '\n'; 185 | *(strp2) = '\0'; 186 | 187 | _assuan_debug (ctx, cat, fmt, func, tagname, tag, str); 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # Assuan top level Makefile 2 | # Copyright (C) 2001, 2002, 2003, 2007, 2011 Free Software Foundation, Inc. 3 | # 4 | # This file is part of Assuan. 5 | # 6 | # Assuan is free software; you can redistribute it and/or modify it 7 | # under the terms of the GNU Lesser General Public License as 8 | # published by the Free Software Foundation; either version 2.1 of 9 | # the License, or (at your option) any later version. 10 | # 11 | # Assuan is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public 17 | # License along with this program; if not, see . 18 | # SPDX-License-Identifier: LGPL-2.1+ 19 | ## Process this file with automake to produce Makefile.in 20 | 21 | # Location of the released tarball archives. This is prefixed by the 22 | # variable RELEASE_ARCHIVE in ~/.gnupg-autogen.rc. The variable 23 | # RELEASE_SIGNKEY is used to specify the key for signing. Use 24 | # gpg-authcode-sign-sh --template 25 | # to create a template for ~/.gnupg-autogen.rc 26 | 27 | # Rhe suffix used in the rrelease archive. 28 | RELEASE_ARCHIVE_SUFFIX = libassuan 29 | 30 | # Macro to help the release target. 31 | RELEASE_NAME = $(PACKAGE_TARNAME)-$(PACKAGE_VERSION) 32 | 33 | ACLOCAL_AMFLAGS = -I m4 34 | DISTCHECK_CONFIGURE_FLAGS = --enable-doc 35 | 36 | # (A suitable gitlog-to-changelog script can be found in GnuPG master.) 37 | GITLOG_TO_CHANGELOG=gitlog-to-changelog 38 | 39 | EXTRA_DIST = autogen.sh autogen.rc README.GIT VERSION \ 40 | ChangeLog-2011 doc/ChangeLog-2011 src/ChangeLog-2011 \ 41 | tests/ChangeLog-2011 build-aux/libtool-patch.sed \ 42 | build-aux/git-log-footer build-aux/git-log-fix 43 | 44 | if BUILD_DOC 45 | doc = doc 46 | else 47 | doc = 48 | endif 49 | 50 | SUBDIRS = m4 src $(doc) tests 51 | 52 | 53 | dist-hook: gen-ChangeLog 54 | 55 | 56 | distcheck-hook: 57 | set -e; ( \ 58 | pref="#+macro: $$(echo $(PACKAGE_NAME)|tr '-' '_')_" ;\ 59 | reldate="$$(date -u +%Y-%m-%d)" ;\ 60 | echo "$${pref}ver $(PACKAGE_VERSION)" ;\ 61 | echo "$${pref}date $${reldate}" ;\ 62 | list='$(DIST_ARCHIVES)'; for i in $$list; do \ 63 | case "$$i" in *.tar.bz2) \ 64 | echo "$${pref}size $$(wc -c <$$i|awk '{print int($$1/1024)}')k" ;\ 65 | echo "$${pref}sha1 $$(sha1sum <$$i|cut -d' ' -f1)" ;\ 66 | echo "$${pref}sha2 $$(sha256sum <$$i|cut -d' ' -f1)" ;;\ 67 | esac;\ 68 | done ) | tee $(distdir).swdb 69 | 70 | 71 | gen_start_date = 2011-12-01T00:00:00 72 | .PHONY: gen-ChangeLog release sign-release 73 | gen-ChangeLog: 74 | set -e; \ 75 | if test -d $(top_srcdir)/.git; then \ 76 | (cd $(top_srcdir) && \ 77 | $(GITLOG_TO_CHANGELOG) --append-dot --tear-off \ 78 | --amend=build-aux/git-log-fix --tear-off \ 79 | --since=$(gen_start_date) ) > $(distdir)/cl-t; \ 80 | cat $(top_srcdir)/build-aux/git-log-footer >> $(distdir)/cl-t;\ 81 | rm -f $(distdir)/ChangeLog; \ 82 | mv $(distdir)/cl-t $(distdir)/ChangeLog; \ 83 | fi 84 | 85 | 86 | stowinstall: 87 | $(MAKE) $(AM_MAKEFLAGS) install prefix=/usr/local/stow/libassuan 88 | 89 | release: 90 | +(set -e;\ 91 | if [ "$(abs_top_builddir)" = "$(abs_top_srcdir)" ]; then \ 92 | echo "error: build directory must not be the source directory" >&2;\ 93 | exit 2;\ 94 | fi ;\ 95 | echo "/* Build started at $$(date -uIseconds) */" ;\ 96 | cd $(top_srcdir); \ 97 | ./autogen.sh --force; \ 98 | cd $(abs_top_builddir); \ 99 | rm -rf dist; mkdir dist ; cd dist ; \ 100 | $(abs_top_srcdir)/configure --enable-maintainer-mode; \ 101 | $(MAKE) distcheck; \ 102 | echo "/* Build finished at $$(date -uIseconds) */" ;\ 103 | echo "/*" ;\ 104 | echo " * Please run the final step interactivly:" ;\ 105 | echo " * make sign-release" ;\ 106 | echo " */" ;\ 107 | ) 2>&1 | tee "$(RELEASE_NAME).buildlog" 108 | 109 | sign-release: 110 | +(set -e; \ 111 | test $$(pwd | sed 's,.*/,,') = dist || cd dist; \ 112 | x=$$(grep '^[[:blank:]]*RELEASE_ARCHIVE[[:blank:]]*=' \ 113 | $$HOME/.gnupg-autogen.rc|cut -d= -f2|xargs);\ 114 | if [ -z "$$x" ]; then \ 115 | echo "error: RELEASE_ARCHIVE missing in ~/.gnupg-autogen.rc">&2; \ 116 | exit 2;\ 117 | fi;\ 118 | myarchive="$$x/$(RELEASE_ARCHIVE_SUFFIX)";\ 119 | x=$$(grep '^[[:blank:]]*RELEASE_SIGNKEY[[:blank:]]*=' \ 120 | $$HOME/.gnupg-autogen.rc|cut -d= -f2|xargs);\ 121 | if [ -z "$$x" ]; then \ 122 | echo "error: RELEASE_SIGNKEY missing in ~/.gnupg-autogen.rc">&2; \ 123 | exit 2;\ 124 | fi;\ 125 | mysignkey="$$x";\ 126 | files1="$(RELEASE_NAME).tar.bz2" ;\ 127 | files2="$(RELEASE_NAME).tar.bz2.sig \ 128 | $(RELEASE_NAME).swdb \ 129 | $(RELEASE_NAME).buildlog" ;\ 130 | echo "/* Signing the source tarball ..." ;\ 131 | gpg -sbu $$mysignkey $(RELEASE_NAME).tar.bz2 ;\ 132 | cat $(RELEASE_NAME).swdb >swdb.snippet;\ 133 | echo >>swdb.snippet ;\ 134 | sha1sum $${files1} >>swdb.snippet ;\ 135 | cat "../$(RELEASE_NAME).buildlog" swdb.snippet \ 136 | | gzip >$(RELEASE_NAME).buildlog ;\ 137 | echo "Copying to archive $$myarchive ..." ;\ 138 | scp -p $${files1} $${files2} $${myarchive}/ || true;\ 139 | echo '/*' ;\ 140 | echo ' * All done; for checksums see dist/swdb.snippet' ;\ 141 | echo ' */' ;\ 142 | ) 143 | -------------------------------------------------------------------------------- /src/assuan-listen.c: -------------------------------------------------------------------------------- 1 | /* assuan-listen.c - Wait for a connection (server) 2 | * Copyright (C) 2001, 2002, 2004, 2009 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Assuan. 5 | * 6 | * Assuan is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Assuan is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1+ 19 | */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include 26 | #include 27 | #include 28 | #ifdef HAVE_UNISTD_H 29 | # include 30 | #endif 31 | #include 32 | 33 | #include "assuan-defs.h" 34 | 35 | gpg_error_t 36 | assuan_set_hello_line (assuan_context_t ctx, const char *line) 37 | { 38 | if (!ctx) 39 | return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE); 40 | if (!line) 41 | { 42 | _assuan_free (ctx, ctx->hello_line); 43 | ctx->hello_line = NULL; 44 | } 45 | else 46 | { 47 | char *buf = _assuan_malloc (ctx, 3 + strlen (line) + 1); 48 | if (!buf) 49 | return _assuan_error (ctx, gpg_err_code_from_syserror ()); 50 | if (strchr (line, '\n')) 51 | strcpy (buf, line); 52 | else 53 | { 54 | strcpy (buf, "OK "); 55 | strcpy (buf+3, line); 56 | } 57 | _assuan_free (ctx, ctx->hello_line); 58 | ctx->hello_line = buf; 59 | } 60 | return 0; 61 | } 62 | 63 | 64 | /** 65 | * assuan_accept: 66 | * @ctx: context 67 | * 68 | * Cancel any existing connection and wait for a connection from a 69 | * client. The initial handshake is performed which may include an 70 | * initial authentication or encryption negotiation. 71 | * 72 | * Return value: 0 on success or an error if the connection could for 73 | * some reason not be established. 74 | **/ 75 | gpg_error_t 76 | assuan_accept (assuan_context_t ctx) 77 | { 78 | gpg_error_t rc = 0; 79 | const char *p, *pend; 80 | pid_t apid = getpid (); 81 | char tmpbuf[256]; 82 | 83 | if (!ctx) 84 | return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE); 85 | 86 | if (ctx->max_accepts != -1) 87 | { 88 | if (ctx->max_accepts-- == 0) 89 | return -1; /* second invocation for pipemode -> terminate */ 90 | } 91 | if (ctx->accept_handler) 92 | { 93 | /* FIXME: This should be superfluous, if everything else is 94 | correct. */ 95 | ctx->finish_handler (ctx); 96 | rc = ctx->accept_handler (ctx); 97 | if (rc) 98 | return rc; 99 | } 100 | 101 | /* Send the hello. */ 102 | p = ctx->hello_line; 103 | if (p && (pend = strchr (p, '\n'))) 104 | { /* This is a multi line hello. Send all but the last line as 105 | comments. */ 106 | do 107 | { 108 | rc = _assuan_write_line (ctx, "# ", p, pend - p); 109 | if (rc) 110 | return rc; 111 | p = pend + 1; 112 | pend = strchr (p, '\n'); 113 | } 114 | while (pend); 115 | if (apid != ASSUAN_INVALID_PID) 116 | { 117 | snprintf (tmpbuf, sizeof tmpbuf, "%s, process %i", p, (int)apid); 118 | rc = _assuan_write_line (ctx, "OK ", tmpbuf, strlen (tmpbuf)); 119 | } 120 | else 121 | rc = _assuan_write_line (ctx, "OK ", p, strlen (p)); 122 | 123 | } 124 | else if (p) 125 | { 126 | if (apid != ASSUAN_INVALID_PID) 127 | { 128 | snprintf (tmpbuf, sizeof tmpbuf, "%s, process %i", p, (int)apid); 129 | rc = assuan_write_line (ctx, tmpbuf); 130 | } 131 | else 132 | rc = assuan_write_line (ctx, p); 133 | } 134 | else 135 | { 136 | static char const okstr[] = "OK Pleased to meet you"; 137 | if (apid != ASSUAN_INVALID_PID) 138 | { 139 | snprintf (tmpbuf, sizeof tmpbuf, "%s, process %i", okstr, (int)apid); 140 | rc = assuan_write_line (ctx, tmpbuf); 141 | } 142 | else 143 | rc = assuan_write_line (ctx, okstr); 144 | } 145 | if (rc) 146 | return rc; 147 | 148 | return 0; 149 | } 150 | 151 | 152 | 153 | assuan_fd_t 154 | assuan_get_input_fd (assuan_context_t ctx) 155 | { 156 | return ctx ? ctx->input_fd : ASSUAN_INVALID_FD; 157 | } 158 | 159 | 160 | assuan_fd_t 161 | assuan_get_output_fd (assuan_context_t ctx) 162 | { 163 | return ctx ? ctx->output_fd : ASSUAN_INVALID_FD; 164 | } 165 | 166 | 167 | /* Close the fd descriptor set by the command INPUT FD=n. We handle 168 | this fd inside assuan so that we can do some initial checks */ 169 | gpg_error_t 170 | assuan_close_input_fd (assuan_context_t ctx) 171 | { 172 | if (!ctx || ctx->input_fd == ASSUAN_INVALID_FD) 173 | return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE); 174 | _assuan_close (ctx, ctx->input_fd); 175 | ctx->input_fd = ASSUAN_INVALID_FD; 176 | return 0; 177 | } 178 | 179 | /* Close the fd descriptor set by the command OUTPUT FD=n. We handle 180 | this fd inside assuan so that we can do some initial checks */ 181 | gpg_error_t 182 | assuan_close_output_fd (assuan_context_t ctx) 183 | { 184 | if (!ctx || ctx->output_fd == ASSUAN_INVALID_FD) 185 | return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE); 186 | 187 | _assuan_close (ctx, ctx->output_fd); 188 | ctx->output_fd = ASSUAN_INVALID_FD; 189 | return 0; 190 | } 191 | -------------------------------------------------------------------------------- /m4/lt~obsolete.m4: -------------------------------------------------------------------------------- 1 | # lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- 2 | # 3 | # Copyright (C) 2004, 2005, 2007, 2009 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004. 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # serial 5 lt~obsolete.m4 11 | 12 | # These exist entirely to fool aclocal when bootstrapping libtool. 13 | # 14 | # In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN) 15 | # which have later been changed to m4_define as they aren't part of the 16 | # exported API, or moved to Autoconf or Automake where they belong. 17 | # 18 | # The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN 19 | # in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us 20 | # using a macro with the same name in our local m4/libtool.m4 it'll 21 | # pull the old libtool.m4 in (it doesn't see our shiny new m4_define 22 | # and doesn't know about Autoconf macros at all.) 23 | # 24 | # So we provide this file, which has a silly filename so it's always 25 | # included after everything else. This provides aclocal with the 26 | # AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything 27 | # because those macros already exist, or will be overwritten later. 28 | # We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. 29 | # 30 | # Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here. 31 | # Yes, that means every name once taken will need to remain here until 32 | # we give up compatibility with versions before 1.7, at which point 33 | # we need to keep only those names which we still refer to. 34 | 35 | # This is to help aclocal find these macros, as it can't see m4_define. 36 | AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])]) 37 | 38 | m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])]) 39 | m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])]) 40 | m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])]) 41 | m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])]) 42 | m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])]) 43 | m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])]) 44 | m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])]) 45 | m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])]) 46 | m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])]) 47 | m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])]) 48 | m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])]) 49 | m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])]) 50 | m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])]) 51 | m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])]) 52 | m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])]) 53 | m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])]) 54 | m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])]) 55 | m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])]) 56 | m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])]) 57 | m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])]) 58 | m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])]) 59 | m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])]) 60 | m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])]) 61 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])]) 62 | m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])]) 63 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])]) 64 | m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])]) 65 | m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])]) 66 | m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])]) 67 | m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])]) 68 | m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])]) 69 | m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])]) 70 | m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])]) 71 | m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])]) 72 | m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])]) 73 | m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])]) 74 | m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])]) 75 | m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])]) 76 | m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])]) 77 | m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])]) 78 | m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])]) 79 | m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])]) 80 | m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])]) 81 | m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])]) 82 | m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])]) 83 | m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])]) 84 | m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])]) 85 | m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])]) 86 | m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])]) 87 | m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])]) 88 | m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])]) 89 | m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])]) 90 | m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])]) 91 | m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])]) 92 | m4_ifndef([_LT_REQUIRED_DARWIN_CHECKS], [AC_DEFUN([_LT_REQUIRED_DARWIN_CHECKS])]) 93 | m4_ifndef([_LT_AC_PROG_CXXCPP], [AC_DEFUN([_LT_AC_PROG_CXXCPP])]) 94 | m4_ifndef([_LT_PREPARE_SED_QUOTE_VARS], [AC_DEFUN([_LT_PREPARE_SED_QUOTE_VARS])]) 95 | m4_ifndef([_LT_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_PROG_ECHO_BACKSLASH])]) 96 | m4_ifndef([_LT_PROG_F77], [AC_DEFUN([_LT_PROG_F77])]) 97 | m4_ifndef([_LT_PROG_FC], [AC_DEFUN([_LT_PROG_FC])]) 98 | m4_ifndef([_LT_PROG_CXX], [AC_DEFUN([_LT_PROG_CXX])]) 99 | -------------------------------------------------------------------------------- /src/mkheader.c: -------------------------------------------------------------------------------- 1 | /* mkheader.c - Create a header file for libassuan. 2 | * Copyright (C) 2010 Free Software Foundation, Inc. 3 | * 4 | * This file is free software; as a special exception the author gives 5 | * unlimited permission to copy and/or distribute it, with or without 6 | * modifications, as long as this notice is preserved. 7 | * 8 | * This file is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 10 | * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 | * SPDX-License-Identifier: FSFULLR 12 | */ 13 | 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #define PGM "mkheader" 21 | 22 | #define LINESIZE 1024 23 | 24 | static const char *host_os; 25 | static char *srcdir; 26 | static const char *hdr_version; 27 | static const char *hdr_version_number; 28 | 29 | /* Include the file NAME form the source directory. The included file 30 | is not further expanded. It may have comments indicated by a 31 | double hash mark at the begin of a line. */ 32 | static void 33 | include_file (const char *fname, int lnr, const char *name) 34 | { 35 | FILE *fp; 36 | char *incfname; 37 | char line[LINESIZE]; 38 | 39 | incfname = malloc (strlen (srcdir) + strlen (name) + 1); 40 | if (!incfname) 41 | { 42 | fputs (PGM ": out of core\n", stderr); 43 | exit (1); 44 | } 45 | strcpy (incfname, srcdir); 46 | strcat (incfname, name); 47 | 48 | fp = fopen (incfname, "r"); 49 | if (!fp) 50 | { 51 | fprintf (stderr, "%s:%d: error including `%s': %s\n", 52 | fname, lnr, incfname, strerror (errno)); 53 | exit (1); 54 | } 55 | 56 | while (fgets (line, LINESIZE, fp)) 57 | { 58 | if (line[0] == '#' && line[1] == '#') 59 | { 60 | if (!strncmp (line+2, "EOF##", 5)) 61 | break; /* Forced EOF. */ 62 | } 63 | else 64 | fputs (line, stdout); 65 | } 66 | if (ferror (fp)) 67 | { 68 | fprintf (stderr, "%s:%d: error reading `%s': %s\n", 69 | fname, lnr, incfname, strerror (errno)); 70 | exit (1); 71 | } 72 | fclose (fp); 73 | free (incfname); 74 | } 75 | 76 | 77 | static int 78 | write_special (const char *fname, int lnr, const char *tag) 79 | { 80 | if (!strcmp (tag, "include:includes")) 81 | { 82 | if (strstr (host_os, "mingw32")) 83 | include_file (fname, lnr, "w32-includes.inc.h"); 84 | else 85 | include_file (fname, lnr, "posix-includes.inc.h"); 86 | } 87 | else if (!strcmp (tag, "include:types")) 88 | { 89 | if (strstr (host_os, "mingw32")) 90 | include_file (fname, lnr, "w32-types.inc.h"); 91 | else 92 | include_file (fname, lnr, "posix-types.inc.h"); 93 | } 94 | else if (!strcmp (tag, "include:fd-t")) 95 | { 96 | if (strstr (host_os, "mingw32")) 97 | include_file (fname, lnr, "w32-fd-t.inc.h"); 98 | else 99 | include_file (fname, lnr, "posix-fd-t.inc.h"); 100 | } 101 | else if (!strcmp (tag, "include:sock-nonce")) 102 | { 103 | if (strstr (host_os, "mingw32")) 104 | include_file (fname, lnr, "w32-sock-nonce.inc.h"); 105 | else 106 | include_file (fname, lnr, "posix-sock-nonce.inc.h"); 107 | } 108 | else if (!strcmp (tag, "version")) 109 | { 110 | putchar ('\"'); 111 | fputs (hdr_version, stdout); 112 | putchar ('\"'); 113 | putchar ('\n'); 114 | } 115 | else if (!strcmp (tag, "version-number")) 116 | { 117 | fputs (hdr_version_number, stdout); 118 | putchar ('\n'); 119 | } 120 | else 121 | return 0; /* Unknown tag. */ 122 | 123 | return 1; /* Tag processed. */ 124 | } 125 | 126 | 127 | int 128 | main (int argc, char **argv) 129 | { 130 | FILE *fp; 131 | char line[LINESIZE]; 132 | int lnr = 0; 133 | const char *fname, *s; 134 | char *p1, *p2; 135 | 136 | if (argc) 137 | { 138 | argc--; argv++; 139 | } 140 | 141 | if (argc != 4) 142 | { 143 | fputs ("usage: " PGM " host_os template.h version version_number\n", 144 | stderr); 145 | return 1; 146 | } 147 | host_os = argv[0]; 148 | fname = argv[1]; 149 | hdr_version = argv[2]; 150 | hdr_version_number = argv[3]; 151 | 152 | srcdir = malloc (strlen (fname) + 2 + 1); 153 | if (!srcdir) 154 | { 155 | fputs (PGM ": out of core\n", stderr); 156 | return 1; 157 | } 158 | strcpy (srcdir, fname); 159 | p1 = strrchr (srcdir, '/'); 160 | if (p1) 161 | p1[1] = 0; 162 | else 163 | strcpy (srcdir, "./"); 164 | 165 | fp = fopen (fname, "r"); 166 | if (!fp) 167 | { 168 | fprintf (stderr, "%s:%d: can't open file: %s", 169 | fname, lnr, strerror (errno)); 170 | return 1; 171 | } 172 | 173 | while (fgets (line, LINESIZE, fp)) 174 | { 175 | size_t n = strlen (line); 176 | 177 | lnr++; 178 | if (!n || line[n-1] != '\n') 179 | { 180 | fprintf (stderr, 181 | "%s:%d: trailing linefeed missing, line too long or " 182 | "embedded Nul character", fname, lnr); 183 | break; 184 | } 185 | line[--n] = 0; 186 | 187 | p1 = strchr (line, '@'); 188 | p2 = p1? strchr (p1+1, '@') : NULL; 189 | if (!p1 || !p2 || p2-p1 == 1) 190 | { 191 | puts (line); 192 | continue; 193 | } 194 | *p1++ = 0; 195 | *p2++ = 0; 196 | fputs (line, stdout); 197 | 198 | if (!strcmp (p1, "configure_input")) 199 | { 200 | s = strrchr (fname, '/'); 201 | printf ("Do not edit. Generated from %s by %s for %s.", 202 | s? s+1 : fname, PGM, host_os); 203 | fputs (p2, stdout); 204 | putchar ('\n'); 205 | } 206 | else if (!write_special (fname, lnr, p1)) 207 | { 208 | putchar ('@'); 209 | fputs (p1, stdout); 210 | putchar ('@'); 211 | fputs (p2, stdout); 212 | putchar ('\n'); 213 | } 214 | } 215 | 216 | if (ferror (fp)) 217 | { 218 | fprintf (stderr, "%s:%d: error reading file: %s\n", 219 | fname, lnr, strerror (errno)); 220 | return 1; 221 | } 222 | 223 | fputs ("/*\n" 224 | "Loc" "al Variables:\n" 225 | "buffer-read-only: t\n" 226 | "End:\n" 227 | "*/\n", stdout); 228 | 229 | if (ferror (stdout)) 230 | { 231 | fprintf (stderr, PGM ": error writing stdout: %s\n", strerror (errno)); 232 | return 1; 233 | } 234 | 235 | fclose (fp); 236 | 237 | return 0; 238 | } 239 | -------------------------------------------------------------------------------- /src/context.c: -------------------------------------------------------------------------------- 1 | /* context.c - Context specific interface. 2 | * Copyright (C) 2009 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Assuan. 5 | * 6 | * Assuan is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Assuan is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1+ 19 | */ 20 | 21 | 22 | #ifdef HAVE_CONFIG_H 23 | #include 24 | #endif 25 | 26 | #include "assuan-defs.h" 27 | #include "debug.h" 28 | 29 | 30 | /* Set user-data in a context. */ 31 | void 32 | assuan_set_pointer (assuan_context_t ctx, void *user_pointer) 33 | { 34 | TRACE1 (ctx, ASSUAN_LOG_CTX, "assuan_set_pointer", ctx, 35 | "user_pointer=%p", user_pointer); 36 | 37 | if (ctx) 38 | ctx->user_pointer = user_pointer; 39 | } 40 | 41 | 42 | /* Get user-data in a context. */ 43 | void * 44 | assuan_get_pointer (assuan_context_t ctx) 45 | { 46 | #if 0 47 | /* This is called often. */ 48 | TRACE1 (ctx, ASSUAN_LOG_CTX, "assuan_get_pointer", ctx, 49 | "ctx->user_pointer=%p", ctx ? ctx->user_pointer : NULL); 50 | #endif 51 | 52 | if (! ctx) 53 | return NULL; 54 | 55 | return ctx->user_pointer; 56 | } 57 | 58 | 59 | /* For context CTX, set the flag FLAG to VALUE. Values for flags 60 | are usually 1 or 0 but certain flags might allow for other values; 61 | see the description of the type assuan_flag_t for details. */ 62 | void 63 | assuan_set_flag (assuan_context_t ctx, assuan_flag_t flag, int value) 64 | { 65 | TRACE2 (ctx, ASSUAN_LOG_CTX, "assuan_set_flag", ctx, 66 | "flag=%i,value=%i", flag, value); 67 | 68 | if (!ctx) 69 | return; 70 | 71 | switch (flag) 72 | { 73 | case ASSUAN_NO_WAITPID: 74 | ctx->flags.no_waitpid = value; 75 | break; 76 | 77 | case ASSUAN_CONFIDENTIAL: 78 | ctx->flags.confidential = value; 79 | if (ctx->flags.in_inq_cb && value) 80 | ctx->flags.confidential_inquiry = value; 81 | break; 82 | 83 | case ASSUAN_NO_FIXSIGNALS: 84 | ctx->flags.no_fixsignals = value; 85 | break; 86 | 87 | case ASSUAN_CONVEY_COMMENTS: 88 | ctx->flags.convey_comments = value; 89 | break; 90 | 91 | case ASSUAN_NO_LOGGING: 92 | ctx->flags.no_logging = value; 93 | break; 94 | 95 | case ASSUAN_FORCE_CLOSE: 96 | ctx->flags.force_close = 1; 97 | break; 98 | } 99 | } 100 | 101 | 102 | /* Return the VALUE of FLAG in context CTX. */ 103 | int 104 | assuan_get_flag (assuan_context_t ctx, assuan_flag_t flag) 105 | { 106 | int res = 0; 107 | TRACE_BEG1 (ctx, ASSUAN_LOG_CTX, "assuan_get_flag", ctx, 108 | "flag=%i", flag); 109 | 110 | if (! ctx) 111 | return 0; 112 | 113 | switch (flag) 114 | { 115 | case ASSUAN_NO_WAITPID: 116 | res = ctx->flags.no_waitpid; 117 | break; 118 | 119 | case ASSUAN_CONFIDENTIAL: 120 | res = ctx->flags.confidential; 121 | break; 122 | 123 | case ASSUAN_NO_FIXSIGNALS: 124 | res = ctx->flags.no_fixsignals; 125 | break; 126 | 127 | case ASSUAN_CONVEY_COMMENTS: 128 | res = ctx->flags.convey_comments; 129 | break; 130 | 131 | case ASSUAN_NO_LOGGING: 132 | res = ctx->flags.no_logging; 133 | break; 134 | 135 | case ASSUAN_FORCE_CLOSE: 136 | res = ctx->flags.force_close; 137 | break; 138 | } 139 | 140 | return TRACE_SUC1 ("flag_value=%i", res); 141 | } 142 | 143 | 144 | /* Same as assuan_set_flag (ctx, ASSUAN_CONFIDENTIAL, 1). */ 145 | void 146 | assuan_begin_confidential (assuan_context_t ctx) 147 | { 148 | assuan_set_flag (ctx, ASSUAN_CONFIDENTIAL, 1); 149 | } 150 | 151 | 152 | /* Same as assuan_set_flag (ctx, ASSUAN_CONFIDENTIAL, 0) but first 153 | * flushes pending data. */ 154 | void 155 | assuan_end_confidential (assuan_context_t ctx) 156 | { 157 | _assuan_cookie_write_flush (ctx); 158 | assuan_set_flag (ctx, ASSUAN_CONFIDENTIAL, 0); 159 | } 160 | 161 | 162 | /* Set the system callbacks. */ 163 | void 164 | assuan_ctx_set_system_hooks (assuan_context_t ctx, 165 | assuan_system_hooks_t system_hooks) 166 | { 167 | TRACE2 (ctx, ASSUAN_LOG_CTX, "assuan_set_system_hooks", ctx, 168 | "system_hooks=%p (version %i)", system_hooks, 169 | system_hooks->version); 170 | 171 | _assuan_system_hooks_copy (&ctx->system, system_hooks); 172 | } 173 | 174 | 175 | /* Set the IO monitor function. */ 176 | void assuan_set_io_monitor (assuan_context_t ctx, 177 | assuan_io_monitor_t io_monitor, void *hook_data) 178 | { 179 | TRACE2 (ctx, ASSUAN_LOG_CTX, "assuan_set_io_monitor", ctx, 180 | "io_monitor=%p,hook_data=%p", io_monitor, hook_data); 181 | 182 | if (! ctx) 183 | return; 184 | 185 | ctx->io_monitor = io_monitor; 186 | ctx->io_monitor_data = hook_data; 187 | } 188 | 189 | 190 | /* Store the error in the context so that the error sending function 191 | can take out a descriptive text. Inside the assuan code, use the 192 | macro set_error instead of this function. */ 193 | gpg_error_t 194 | assuan_set_error (assuan_context_t ctx, gpg_error_t err, const char *text) 195 | { 196 | TRACE4 (ctx, ASSUAN_LOG_CTX, "assuan_set_error", ctx, 197 | "err=%i (%s,%s),text=%s", err, gpg_strsource (err), 198 | gpg_strerror (err), text?text:"(none)"); 199 | 200 | ctx->err_no = err; 201 | ctx->err_str = text; 202 | return err; 203 | } 204 | 205 | 206 | /* Return the PID of the peer or ASSUAN_INVALID_PID if not known. 207 | This function works in some situations where assuan_get_peercred 208 | fails. */ 209 | pid_t 210 | assuan_get_pid (assuan_context_t ctx) 211 | { 212 | #if defined(HAVE_W32_SYSTEM) 213 | TRACE1 (ctx, ASSUAN_LOG_CTX, "assuan_get_pid", ctx, 214 | "pid=%i", ctx ? ctx->process_id : -1); 215 | #else 216 | TRACE1 (ctx, ASSUAN_LOG_CTX, "assuan_get_pid", ctx, 217 | "pid=%i", ctx ? ctx->pid : -1); 218 | #endif 219 | 220 | if (!ctx) 221 | return ASSUAN_INVALID_PID; 222 | 223 | if (ctx->flags.is_server) 224 | #if defined(HAVE_W32_SYSTEM) 225 | return ctx->process_id; 226 | #else 227 | return ctx->pid; 228 | #endif 229 | else 230 | /* 231 | * This use case of getting internal process reference by the 232 | * application should be fixed. It's here, only for backward 233 | * compatibility. 234 | */ 235 | return ctx->server_proc; 236 | } 237 | 238 | 239 | /* Return user credentials. For getting the pid of the peer the 240 | assuan_get_pid is usually better suited. */ 241 | gpg_error_t 242 | assuan_get_peercred (assuan_context_t ctx, assuan_peercred_t *peercred) 243 | { 244 | TRACE (ctx, ASSUAN_LOG_CTX, "assuan_get_peercred", ctx); 245 | 246 | if (!ctx) 247 | return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE); 248 | if (!ctx->peercred_valid) 249 | return _assuan_error (ctx, GPG_ERR_ASS_GENERAL); 250 | 251 | *peercred = &ctx->peercred; 252 | 253 | return 0; 254 | } 255 | -------------------------------------------------------------------------------- /tests/common.h: -------------------------------------------------------------------------------- 1 | /* common.h - Common functions for the tests. 2 | * Copyright (C) 2006 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Assuan. 5 | * 6 | * Assuan is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 3 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Assuan is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | 22 | #if __GNUC__ >= 4 23 | # define MY_GCC_A_SENTINEL(a) __attribute__ ((sentinel(a))) 24 | #else 25 | # define MY_GCC_A_SENTINEL(a) 26 | #endif 27 | 28 | 29 | #if HAVE_W64_SYSTEM 30 | #define SOCKET2HANDLE(s) ((void *)(s)) 31 | #define HANDLE2SOCKET(h) ((uintptr_t)(h)) 32 | CRITICAL_SECTION _log_critsect; 33 | #define _log_enter() do { EnterCriticalSection (&_log_critsect); } while (0) 34 | #define _log_leave() do { LeaveCriticalSection (&_log_critsect); } while (0) 35 | #elif HAVE_W32_SYSTEM 36 | #define SOCKET2HANDLE(s) ((void *)(s)) 37 | #define HANDLE2SOCKET(h) ((unsigned int)(h)) 38 | CRITICAL_SECTION _log_critsect; 39 | #define _log_enter() do { EnterCriticalSection (&_log_critsect); } while (0) 40 | #define _log_leave() do { LeaveCriticalSection (&_log_critsect); } while (0) 41 | #else 42 | #define SOCKET2HANDLE(s) (s) 43 | #define HANDLE2SOCKET(h) (h) 44 | #define _log_enter() do { } while (0) 45 | #define _log_leave() do { } while (0) 46 | #endif 47 | 48 | #define DIM(v) (sizeof(v)/sizeof((v)[0])) 49 | #define DIMof(type,member) DIM(((type *)0)->member) 50 | 51 | 52 | char *xstrconcat (const char *s1, ...) MY_GCC_A_SENTINEL(0); 53 | 54 | 55 | static const char *log_prefix; 56 | static int errorcount; 57 | static int verbose; 58 | static int debug; 59 | 60 | void * 61 | xmalloc (size_t n) 62 | { 63 | char *p = malloc (n); 64 | if (!p) 65 | { 66 | if (log_prefix) 67 | fprintf (stderr, "%s[%u]: ", log_prefix, (unsigned int)getpid ()); 68 | fprintf (stderr, "out of core\n"); 69 | exit (1); 70 | } 71 | return p; 72 | } 73 | 74 | void * 75 | xcalloc (size_t n, size_t m) 76 | { 77 | char *p = calloc (n, m); 78 | if (!p) 79 | { 80 | _log_enter (); 81 | if (log_prefix) 82 | fprintf (stderr, "%s[%u]: ", log_prefix, (unsigned int)getpid ()); 83 | fprintf (stderr, "out of core\n"); 84 | _log_leave (); 85 | exit (1); 86 | } 87 | return p; 88 | } 89 | 90 | void 91 | xfree (void *a) 92 | { 93 | if (a) 94 | free (a); 95 | } 96 | 97 | void * 98 | xstrdup (const char *string) 99 | { 100 | char *p = xmalloc (strlen (string) + 1); 101 | strcpy (p, string); 102 | return p; 103 | } 104 | 105 | 106 | void 107 | log_set_prefix (const char *s) 108 | { 109 | #ifdef HAVE_W32_SYSTEM 110 | InitializeCriticalSection (&_log_critsect); 111 | log_prefix = strrchr (s, '\\'); 112 | #else 113 | log_prefix = strrchr (s, '/'); 114 | #endif 115 | if (log_prefix) 116 | log_prefix++; 117 | else 118 | log_prefix = s; 119 | } 120 | 121 | 122 | const char * 123 | log_get_prefix (void) 124 | { 125 | return log_prefix? log_prefix:""; 126 | } 127 | 128 | 129 | void 130 | log_info (const char *format, ...) 131 | { 132 | va_list arg_ptr ; 133 | 134 | if (!verbose) 135 | return; 136 | 137 | va_start (arg_ptr, format) ; 138 | _log_enter (); 139 | if (log_prefix) 140 | fprintf (stderr, "%s[%u]: ", log_prefix, (unsigned int)getpid ()); 141 | vfprintf (stderr, format, arg_ptr ); 142 | _log_leave (); 143 | va_end (arg_ptr); 144 | } 145 | 146 | 147 | void 148 | log_error (const char *format, ...) 149 | { 150 | va_list arg_ptr ; 151 | 152 | va_start (arg_ptr, format) ; 153 | _log_enter (); 154 | if (log_prefix) 155 | fprintf (stderr, "%s[%u]: ", log_prefix, (unsigned int)getpid ()); 156 | vfprintf (stderr, format, arg_ptr ); 157 | _log_leave (); 158 | va_end (arg_ptr); 159 | errorcount++; 160 | } 161 | 162 | 163 | void 164 | log_fatal (const char *format, ...) 165 | { 166 | va_list arg_ptr ; 167 | 168 | va_start (arg_ptr, format) ; 169 | _log_enter (); 170 | if (log_prefix) 171 | fprintf (stderr, "%s[%u]: ", log_prefix, (unsigned int)getpid ()); 172 | vfprintf (stderr, format, arg_ptr ); 173 | _log_leave (); 174 | va_end (arg_ptr); 175 | exit (2); 176 | } 177 | 178 | 179 | void 180 | log_printhex (const char *text, const void *buffer, size_t length) 181 | { 182 | const unsigned char *s; 183 | 184 | _log_enter (); 185 | if (log_prefix) 186 | fprintf (stderr, "%s[%u]: ", log_prefix, (unsigned int)getpid ()); 187 | fputs (text, stderr); 188 | for (s=buffer; length; s++, length--) 189 | fprintf (stderr, "%02X", *s); 190 | putc ('\n', stderr); 191 | _log_leave (); 192 | } 193 | 194 | 195 | /* Prepend FNAME with the srcdir environment variable's value and 196 | return an allocated filename. */ 197 | char * 198 | prepend_srcdir (const char *fname) 199 | { 200 | static const char *srcdir; 201 | char *result; 202 | 203 | if (!srcdir && !(srcdir = getenv ("srcdir"))) 204 | srcdir = "."; 205 | 206 | result = xmalloc (strlen (srcdir) + 1 + strlen (fname) + 1); 207 | strcpy (result, srcdir); 208 | strcat (result, "/"); 209 | strcat (result, fname); 210 | return result; 211 | } 212 | 213 | 214 | #ifndef HAVE_STPCPY 215 | #undef __stpcpy 216 | #undef stpcpy 217 | #ifndef weak_alias 218 | # define __stpcpy stpcpy 219 | #endif 220 | char * 221 | __stpcpy (char *a,const char *b) 222 | { 223 | while (*b) 224 | *a++ = *b++; 225 | *a = 0; 226 | return (char*)a; 227 | } 228 | #ifdef libc_hidden_def 229 | libc_hidden_def (__stpcpy) 230 | #endif 231 | #ifdef weak_alias 232 | weak_alias (__stpcpy, stpcpy) 233 | #endif 234 | #ifdef libc_hidden_builtin_def 235 | libc_hidden_builtin_def (stpcpy) 236 | #endif 237 | #endif 238 | 239 | 240 | static char * 241 | do_strconcat (const char *s1, va_list arg_ptr) 242 | { 243 | const char *argv[48]; 244 | size_t argc; 245 | size_t needed; 246 | char *buffer, *p; 247 | 248 | argc = 0; 249 | argv[argc++] = s1; 250 | needed = strlen (s1); 251 | while (((argv[argc] = va_arg (arg_ptr, const char *)))) 252 | { 253 | needed += strlen (argv[argc]); 254 | if (argc >= DIM (argv)-1) 255 | { 256 | fprintf (stderr, "too many args in strconcat\n"); 257 | exit (1); 258 | } 259 | argc++; 260 | } 261 | needed++; 262 | buffer = xmalloc (needed); 263 | if (buffer) 264 | { 265 | for (p = buffer, argc=0; argv[argc]; argc++) 266 | p = stpcpy (p, argv[argc]); 267 | } 268 | return buffer; 269 | } 270 | 271 | 272 | /* Concatenate the string S1 with all the following strings up to a 273 | NULL. Returns a malloced buffer or dies on malloc error. */ 274 | char * 275 | xstrconcat (const char *s1, ...) 276 | { 277 | va_list arg_ptr; 278 | char *result; 279 | 280 | if (!s1) 281 | result = xstrdup (""); 282 | else 283 | { 284 | va_start (arg_ptr, s1); 285 | result = do_strconcat (s1, arg_ptr); 286 | va_end (arg_ptr); 287 | } 288 | return result; 289 | } 290 | 291 | -------------------------------------------------------------------------------- /src/assuan-socket-server.c: -------------------------------------------------------------------------------- 1 | /* assuan-socket-server.c - Assuan socket based server 2 | * Copyright (C) 2002, 2007, 2009 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Assuan. 5 | * 6 | * Assuan is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Assuan is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1+ 19 | */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include 26 | #include 27 | #include 28 | #ifdef HAVE_UNISTD_H 29 | # include 30 | #endif 31 | #ifdef HAVE_SYS_TYPES_H 32 | # include 33 | #endif 34 | #ifdef HAVE_W32_SYSTEM 35 | # ifdef HAVE_WINSOCK2_H 36 | # include 37 | # endif 38 | # include 39 | # if HAVE_SYS_SOCKET_H 40 | # include 41 | # elif HAVE_WS2TCPIP_H 42 | # include 43 | # endif 44 | #else 45 | # include 46 | # include 47 | #endif 48 | #ifdef HAVE_SYS_UCRED_H 49 | #include 50 | #endif 51 | #ifdef HAVE_UCRED_H 52 | #include 53 | #endif 54 | 55 | #include "debug.h" 56 | #include "assuan-defs.h" 57 | 58 | /* Missing declaration on AIX. */ 59 | #if HAVE_GETPEEREID && !HAVE_DECL_GETPEEREID 60 | int getpeereid (int fd, uid_t *euid, gid_t *egid); 61 | #endif 62 | 63 | static gpg_error_t 64 | accept_connection_bottom (assuan_context_t ctx) 65 | { 66 | assuan_fd_t fd = ctx->connected_fd; 67 | 68 | TRACE (ctx, ASSUAN_LOG_SYSIO, "accept_connection_bottom", ctx); 69 | 70 | ctx->peercred_valid = 0; 71 | #ifdef SO_PEERCRED 72 | { 73 | #ifdef HAVE_STRUCT_SOCKPEERCRED_PID 74 | struct sockpeercred cr; /* OpenBSD */ 75 | #else 76 | struct ucred cr; /* GNU/Linux */ 77 | #endif 78 | socklen_t cl = sizeof cr; 79 | 80 | if (!getsockopt (fd, SOL_SOCKET, SO_PEERCRED, &cr, &cl)) 81 | { 82 | ctx->peercred_valid = 1; 83 | ctx->peercred.pid = cr.pid; 84 | ctx->peercred.uid = cr.uid; 85 | ctx->peercred.gid = cr.gid; 86 | } 87 | } 88 | #elif defined (LOCAL_PEERPID) 89 | { /* macOS */ 90 | socklen_t len = sizeof (pid_t); 91 | 92 | if (!getsockopt (fd, SOL_LOCAL, LOCAL_PEERPID, &ctx->peercred.pid, &len)) 93 | { 94 | ctx->peercred_valid = 1; 95 | 96 | #if defined (LOCAL_PEERCRED) 97 | { 98 | struct xucred cr; 99 | len = sizeof (struct xucred); 100 | 101 | if (!getsockopt (fd, SOL_LOCAL, LOCAL_PEERCRED, &cr, &len)) 102 | { 103 | ctx->peercred.uid = cr.cr_uid; 104 | ctx->peercred.gid = cr.cr_gid; 105 | } 106 | } 107 | #endif 108 | } 109 | } 110 | #elif defined (LOCAL_PEEREID) 111 | { /* NetBSD */ 112 | struct unpcbid unp; 113 | socklen_t unpl = sizeof unp; 114 | 115 | if (getsockopt (fd, 0, LOCAL_PEEREID, &unp, &unpl) != -1) 116 | { 117 | ctx->peercred_valid = 1; 118 | ctx->peercred.pid = unp.unp_pid; 119 | ctx->peercred.uid = unp.unp_euid; 120 | ctx->peercred.gid = unp.unp_egid; 121 | } 122 | } 123 | #elif defined (HAVE_GETPEERUCRED) 124 | { /* Solaris */ 125 | ucred_t *ucred = NULL; 126 | 127 | if (getpeerucred (fd, &ucred) != -1) 128 | { 129 | ctx->peercred_valid = 1; 130 | ctx->peercred.pid = ucred_getpid (ucred); 131 | ctx->peercred.uid = ucred_geteuid (ucred); 132 | ctx->peercred.gid = ucred_getegid (ucred); 133 | 134 | ucred_free (ucred); 135 | } 136 | } 137 | #elif defined(HAVE_GETPEEREID) 138 | { /* FreeBSD and AIX */ 139 | if (getpeereid (fd, &ctx->peercred.uid, &ctx->peercred.gid) != -1) 140 | { 141 | ctx->peercred_valid = 1; 142 | ctx->peercred.pid = ASSUAN_INVALID_PID; 143 | #if defined (HAVE_XUCRED_CR_PID) 144 | { 145 | struct xucred cr; 146 | socklen_t len = sizeof (struct xucred); 147 | 148 | if (!getsockopt (fd, SOL_LOCAL, LOCAL_PEERCRED, &cr, &len)) 149 | ctx->peercred.pid = cr.cr_pid; 150 | } 151 | #endif 152 | } 153 | } 154 | #endif 155 | 156 | #if !defined(HAVE_W32_SYSTEM) 157 | /* This overrides any already set PID if the function returns 158 | a valid one. */ 159 | if (ctx->peercred_valid && ctx->peercred.pid != ASSUAN_INVALID_PID) 160 | ctx->pid = ctx->peercred.pid; 161 | #endif 162 | 163 | ctx->inbound.fd = fd; 164 | ctx->inbound.eof = 0; 165 | ctx->inbound.linelen = 0; 166 | ctx->inbound.attic.linelen = 0; 167 | ctx->inbound.attic.pending = 0; 168 | 169 | ctx->outbound.fd = fd; 170 | ctx->outbound.data.linelen = 0; 171 | ctx->outbound.data.error = 0; 172 | 173 | ctx->flags.confidential = 0; 174 | 175 | return 0; 176 | } 177 | 178 | 179 | static gpg_error_t 180 | accept_connection (assuan_context_t ctx) 181 | { 182 | assuan_fd_t fd; 183 | struct sockaddr_un clnt_addr; 184 | socklen_t len = sizeof clnt_addr; 185 | 186 | TRACE1 (ctx, ASSUAN_LOG_SYSIO, "accept_connection", ctx, 187 | "listen_fd=0x%x", ctx->listen_fd); 188 | 189 | fd = SOCKET2HANDLE(accept (HANDLE2SOCKET(ctx->listen_fd), 190 | (struct sockaddr*)&clnt_addr, &len )); 191 | if (fd == ASSUAN_INVALID_FD) 192 | { 193 | return _assuan_error (ctx, gpg_err_code_from_syserror ()); 194 | } 195 | TRACE1 (ctx, ASSUAN_LOG_SYSIO, "accept_connection", ctx, 196 | "fd->0x%x", fd); 197 | if (_assuan_sock_check_nonce (ctx, fd, &ctx->listen_nonce)) 198 | { 199 | _assuan_close (ctx, fd); 200 | return _assuan_error (ctx, GPG_ERR_ASS_ACCEPT_FAILED); 201 | } 202 | 203 | ctx->connected_fd = fd; 204 | return accept_connection_bottom (ctx); 205 | } 206 | 207 | 208 | /* 209 | Flag bits: 0 - use sendmsg/recvmsg to allow descriptor passing 210 | 1 - FD has already been accepted. 211 | */ 212 | gpg_error_t 213 | assuan_init_socket_server (assuan_context_t ctx, assuan_fd_t fd, 214 | unsigned int flags) 215 | { 216 | gpg_error_t rc; 217 | TRACE_BEG2 (ctx, ASSUAN_LOG_CTX, "assuan_init_socket_server", ctx, 218 | "fd=0x%x, flags=0x%x", fd, flags); 219 | 220 | ctx->flags.is_socket = 1; 221 | rc = _assuan_register_std_commands (ctx); 222 | if (rc) 223 | return TRACE_ERR (rc); 224 | 225 | ctx->engine.release = _assuan_server_release; 226 | ctx->engine.readfnc = _assuan_simple_read; 227 | ctx->engine.writefnc = _assuan_simple_write; 228 | ctx->engine.sendfd = NULL; 229 | ctx->engine.receivefd = NULL; 230 | ctx->flags.is_server = 1; 231 | if (flags & ASSUAN_SOCKET_SERVER_ACCEPTED) 232 | /* We want a second accept to indicate EOF. */ 233 | ctx->max_accepts = 1; 234 | else 235 | ctx->max_accepts = -1; 236 | ctx->input_fd = ASSUAN_INVALID_FD; 237 | ctx->output_fd = ASSUAN_INVALID_FD; 238 | 239 | ctx->inbound.fd = ASSUAN_INVALID_FD; 240 | ctx->outbound.fd = ASSUAN_INVALID_FD; 241 | 242 | if (flags & ASSUAN_SOCKET_SERVER_ACCEPTED) 243 | { 244 | ctx->listen_fd = ASSUAN_INVALID_FD; 245 | ctx->connected_fd = fd; 246 | } 247 | else 248 | { 249 | ctx->listen_fd = fd; 250 | ctx->connected_fd = ASSUAN_INVALID_FD; 251 | } 252 | ctx->accept_handler = ((flags & ASSUAN_SOCKET_SERVER_ACCEPTED) 253 | ? accept_connection_bottom 254 | : accept_connection); 255 | ctx->finish_handler = _assuan_server_finish; 256 | 257 | #ifdef HAVE_W32_SYSTEM 258 | ctx->engine.receivefd = w32_fdpass_recv; 259 | #else 260 | if (flags & ASSUAN_SOCKET_SERVER_FDPASSING) 261 | _assuan_init_uds_io (ctx); 262 | #endif 263 | 264 | rc = _assuan_register_std_commands (ctx); 265 | if (rc) 266 | _assuan_reset (ctx); 267 | return TRACE_ERR (rc); 268 | } 269 | 270 | 271 | /* Save a copy of NONCE in context CTX. This should be used to 272 | register the server's nonce with an context established by 273 | assuan_init_socket_server. */ 274 | void 275 | assuan_set_sock_nonce (assuan_context_t ctx, assuan_sock_nonce_t *nonce) 276 | { 277 | if (ctx && nonce) 278 | ctx->listen_nonce = *nonce; 279 | } 280 | -------------------------------------------------------------------------------- /src/assuan-uds.c: -------------------------------------------------------------------------------- 1 | /* assuan-uds.c - Assuan unix domain socket utilities 2 | * Copyright (C) 2006, 2009 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Assuan. 5 | * 6 | * Assuan is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Assuan is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1+ 19 | */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #ifdef HAVE_SYS_TYPES_H 30 | # include 31 | #endif 32 | #ifndef HAVE_W32_SYSTEM 33 | # include 34 | # include 35 | #else 36 | # ifdef HAVE_WINSOCK2_H 37 | # include 38 | # endif 39 | # include 40 | #endif 41 | #if HAVE_SYS_UIO_H 42 | #include 43 | #endif 44 | #ifdef HAVE_UNISTD_H 45 | # include 46 | #endif 47 | #ifdef HAVE_FCNTL_H 48 | #include 49 | #endif 50 | #include 51 | #include 52 | 53 | #include "assuan-defs.h" 54 | #include "debug.h" 55 | 56 | #ifdef USE_DESCRIPTOR_PASSING 57 | /* Provide replacement for missing CMSG maccros. We assume that 58 | size_t matches the alignment requirement. NOTE: This is not true 59 | on Mac OS X, so be extra careful to define _DARWIN_C_SOURCE to get 60 | those definitions instead of using these. */ 61 | #define MY_ALIGN(n) ((((n))+ sizeof(size_t)-1) & (size_t)~(sizeof(size_t)-1)) 62 | #ifndef CMSG_SPACE 63 | #define CMSG_SPACE(n) (MY_ALIGN(sizeof(struct cmsghdr)) + MY_ALIGN((n))) 64 | #endif 65 | #ifndef CMSG_LEN 66 | #define CMSG_LEN(n) (MY_ALIGN(sizeof(struct cmsghdr)) + (n)) 67 | #endif 68 | #ifndef CMSG_FIRSTHDR 69 | #define CMSG_FIRSTHDR(mhdr) \ 70 | ((size_t)(mhdr)->msg_controllen >= sizeof (struct cmsghdr) \ 71 | ? (struct cmsghdr*) (mhdr)->msg_control : (struct cmsghdr*)NULL) 72 | #endif 73 | #ifndef CMSG_DATA 74 | #define CMSG_DATA(cmsg) ((unsigned char*)((struct cmsghdr*)(cmsg)+1)) 75 | #endif 76 | #endif /*USE_DESCRIPTOR_PASSING*/ 77 | 78 | 79 | /* Read from a unix domain socket using sendmsg. */ 80 | static ssize_t 81 | uds_reader (assuan_context_t ctx, void *buf, size_t buflen) 82 | { 83 | #ifndef HAVE_W32_SYSTEM 84 | int len = 0; 85 | /* This loop should be OK. As FDs are followed by data, the 86 | readable status of the socket does not change and no new 87 | select/event-loop round is necessary. */ 88 | while (!len) /* No data is buffered. */ 89 | { 90 | struct msghdr msg; 91 | struct iovec iovec; 92 | #ifdef USE_DESCRIPTOR_PASSING 93 | union { 94 | struct cmsghdr cm; 95 | char control[CMSG_SPACE(sizeof (int))]; 96 | } control_u; 97 | struct cmsghdr *cmptr; 98 | #endif /*USE_DESCRIPTOR_PASSING*/ 99 | 100 | memset (&msg, 0, sizeof (msg)); 101 | 102 | msg.msg_name = NULL; 103 | msg.msg_namelen = 0; 104 | msg.msg_iov = &iovec; 105 | msg.msg_iovlen = 1; 106 | iovec.iov_base = buf; 107 | iovec.iov_len = buflen; 108 | #ifdef USE_DESCRIPTOR_PASSING 109 | msg.msg_control = control_u.control; 110 | msg.msg_controllen = sizeof (control_u.control); 111 | #endif 112 | 113 | len = _assuan_recvmsg (ctx, ctx->inbound.fd, &msg, 0); 114 | if (len < 0) 115 | return -1; 116 | if (len == 0) 117 | return 0; 118 | 119 | #ifdef USE_DESCRIPTOR_PASSING 120 | cmptr = CMSG_FIRSTHDR (&msg); 121 | if (cmptr && cmptr->cmsg_len == CMSG_LEN (sizeof(int))) 122 | { 123 | if (cmptr->cmsg_level != SOL_SOCKET 124 | || cmptr->cmsg_type != SCM_RIGHTS) 125 | TRACE0 (ctx, ASSUAN_LOG_SYSIO, "uds_reader", ctx, 126 | "unexpected ancillary data received"); 127 | else 128 | { 129 | int fd; 130 | 131 | memcpy (&fd, CMSG_DATA (cmptr), sizeof (fd)); 132 | 133 | if (ctx->uds.pendingfdscount >= DIM (ctx->uds.pendingfds)) 134 | { 135 | TRACE1 (ctx, ASSUAN_LOG_SYSIO, "uds_reader", ctx, 136 | "too many descriptors pending - " 137 | "closing received descriptor %d", fd); 138 | _assuan_close (ctx, fd); 139 | } 140 | else 141 | ctx->uds.pendingfds[ctx->uds.pendingfdscount++] = fd; 142 | } 143 | } 144 | #endif /*USE_DESCRIPTOR_PASSING*/ 145 | } 146 | 147 | return len; 148 | #else /*HAVE_W32_SYSTEM*/ 149 | int res = recvfrom (HANDLE2SOCKET(ctx->inbound.fd), buf, buflen, 0, NULL, NULL); 150 | if (res < 0) 151 | gpg_err_set_errno (_assuan_sock_wsa2errno (ctx, WSAGetLastError ())); 152 | return res; 153 | #endif /*HAVE_W32_SYSTEM*/ 154 | } 155 | 156 | 157 | /* Write to the domain server. */ 158 | static ssize_t 159 | uds_writer (assuan_context_t ctx, const void *buf, size_t buflen) 160 | { 161 | #ifndef HAVE_W32_SYSTEM 162 | struct msghdr msg; 163 | struct iovec iovec; 164 | ssize_t len; 165 | 166 | memset (&msg, 0, sizeof (msg)); 167 | 168 | msg.msg_name = NULL; 169 | msg.msg_namelen = 0; 170 | msg.msg_iovlen = 1; 171 | msg.msg_iov = &iovec; 172 | iovec.iov_base = (void*)buf; 173 | iovec.iov_len = buflen; 174 | 175 | len = _assuan_sendmsg (ctx, ctx->outbound.fd, &msg, 0); 176 | 177 | return len; 178 | #else /*HAVE_W32_SYSTEM*/ 179 | int res = sendto (HANDLE2SOCKET(ctx->outbound.fd), buf, buflen, 0, 180 | (struct sockaddr *)&ctx->serveraddr, 181 | sizeof (struct sockaddr_in)); 182 | if (res < 0) 183 | gpg_err_set_errno ( _assuan_sock_wsa2errno (ctx, WSAGetLastError ())); 184 | return res; 185 | #endif /*HAVE_W32_SYSTEM*/ 186 | } 187 | 188 | 189 | static gpg_error_t 190 | uds_sendfd (assuan_context_t ctx, assuan_fd_t fd) 191 | { 192 | #ifdef USE_DESCRIPTOR_PASSING 193 | struct msghdr msg; 194 | struct iovec iovec; 195 | union { 196 | struct cmsghdr cm; 197 | char control[CMSG_SPACE(sizeof (int))]; 198 | } control_u; 199 | struct cmsghdr *cmptr; 200 | int len; 201 | char buffer[80]; 202 | 203 | /* We need to send some real data so that a read won't return 0 204 | which will be taken as an EOF. It also helps with debugging. */ 205 | snprintf (buffer, sizeof(buffer)-1, "# descriptor %d is in flight\n", fd); 206 | buffer[sizeof(buffer)-1] = 0; 207 | 208 | memset (&msg, 0, sizeof (msg)); 209 | 210 | memset (&control_u, 0, sizeof (control_u)); 211 | 212 | msg.msg_name = NULL; 213 | msg.msg_namelen = 0; 214 | msg.msg_iovlen = 1; 215 | msg.msg_iov = &iovec; 216 | iovec.iov_base = buffer; 217 | iovec.iov_len = strlen (buffer); 218 | 219 | msg.msg_control = control_u.control; 220 | msg.msg_controllen = sizeof (control_u.control); 221 | cmptr = CMSG_FIRSTHDR (&msg); 222 | cmptr->cmsg_len = CMSG_LEN(sizeof(int)); 223 | cmptr->cmsg_level = SOL_SOCKET; 224 | cmptr->cmsg_type = SCM_RIGHTS; 225 | 226 | memcpy (CMSG_DATA (cmptr), &fd, sizeof (fd)); 227 | 228 | len = _assuan_sendmsg (ctx, ctx->outbound.fd, &msg, 0); 229 | if (len < 0) 230 | { 231 | int saved_errno = errno; 232 | TRACE1 (ctx, ASSUAN_LOG_SYSIO, "uds_sendfd", ctx, 233 | "uds_sendfd: %s", strerror (errno)); 234 | errno = saved_errno; 235 | return _assuan_error (ctx, gpg_err_code_from_syserror ()); 236 | } 237 | else 238 | return 0; 239 | #else 240 | return _assuan_error (ctx, GPG_ERR_NOT_IMPLEMENTED); 241 | #endif 242 | } 243 | 244 | 245 | static gpg_error_t 246 | uds_receivefd (assuan_context_t ctx, assuan_fd_t *fd) 247 | { 248 | #ifdef USE_DESCRIPTOR_PASSING 249 | int i; 250 | 251 | if (!ctx->uds.pendingfdscount) 252 | { 253 | TRACE0 (ctx, ASSUAN_LOG_SYSIO, "uds_receivefd", ctx, 254 | "no pending file descriptors"); 255 | return _assuan_error (ctx, GPG_ERR_ASS_GENERAL); 256 | } 257 | assert (ctx->uds.pendingfdscount <= DIM(ctx->uds.pendingfds)); 258 | 259 | *fd = ctx->uds.pendingfds[0]; 260 | for (i=1; i < ctx->uds.pendingfdscount; i++) 261 | ctx->uds.pendingfds[i-1] = ctx->uds.pendingfds[i]; 262 | ctx->uds.pendingfdscount--; 263 | 264 | return 0; 265 | #else 266 | return _assuan_error (ctx, GPG_ERR_NOT_IMPLEMENTED); 267 | #endif 268 | } 269 | 270 | 271 | /* Close all pending fds. */ 272 | void 273 | _assuan_uds_close_fds (assuan_context_t ctx) 274 | { 275 | int i; 276 | 277 | for (i = 0; i < ctx->uds.pendingfdscount; i++) 278 | _assuan_close (ctx, ctx->uds.pendingfds[i]); 279 | ctx->uds.pendingfdscount = 0; 280 | } 281 | 282 | /* Deinitialize the unix domain socket I/O functions. */ 283 | void 284 | _assuan_uds_deinit (assuan_context_t ctx) 285 | { 286 | _assuan_uds_close_fds (ctx); 287 | } 288 | 289 | 290 | /* Helper function to initialize a context for domain I/O. */ 291 | void 292 | _assuan_init_uds_io (assuan_context_t ctx) 293 | { 294 | ctx->engine.readfnc = uds_reader; 295 | ctx->engine.writefnc = uds_writer; 296 | ctx->engine.sendfd = uds_sendfd; 297 | ctx->engine.receivefd = uds_receivefd; 298 | 299 | ctx->uds.pendingfdscount = 0; 300 | } 301 | 302 | -------------------------------------------------------------------------------- /src/assuan-logging.c: -------------------------------------------------------------------------------- 1 | /* assuan-logging.c - Default logging function. 2 | * Copyright (C) 2002, 2003, 2004, 2007, 2009, 3 | * 2010 Free Software Foundation, Inc. 4 | * 5 | * This file is part of Assuan. 6 | * 7 | * Assuan is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Assuan is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | * SPDX-License-Identifier: LGPL-2.1+ 20 | */ 21 | 22 | #ifdef HAVE_CONFIG_H 23 | #include 24 | #endif 25 | #include 26 | #include 27 | #include 28 | #include 29 | #ifdef HAVE_W32_SYSTEM 30 | # ifdef HAVE_WINSOCK2_H 31 | # include 32 | # endif 33 | # include 34 | #endif /*HAVE_W32_SYSTEM*/ 35 | #include 36 | #include 37 | 38 | #include "assuan-defs.h" 39 | 40 | 41 | /* The default log handler is useful for global logging, but it should 42 | only be used by one user of libassuan at a time. Libraries that 43 | use libassuan can register their own log handler. */ 44 | 45 | /* A common prefix for all log messages. */ 46 | static char prefix_buffer[80]; 47 | 48 | /* A global flag read from the environment to check if to enable full 49 | logging of buffer data. This is also used by custom log 50 | handlers. */ 51 | static int full_logging; 52 | 53 | /* A bitfield that specifies the categories to log. */ 54 | static int log_cats; 55 | #define TEST_LOG_CAT(x) (!! (log_cats & (1 << (x - 1)))) 56 | 57 | static FILE *_assuan_log; 58 | 59 | 60 | void 61 | _assuan_init_log_envvars (void) 62 | { 63 | char *flagstr; 64 | 65 | full_logging = !!getenv ("ASSUAN_FULL_LOGGING"); 66 | flagstr = getenv ("ASSUAN_DEBUG"); 67 | if (flagstr) 68 | log_cats = atoi (flagstr); 69 | else /* Default to log the control channel. */ 70 | log_cats = (1 << (ASSUAN_LOG_CONTROL - 1)); 71 | 72 | _assuan_sysutils_blurb (); /* Make sure this code gets linked in. */ 73 | } 74 | 75 | 76 | void 77 | assuan_set_assuan_log_stream (FILE *fp) 78 | { 79 | _assuan_log = fp; 80 | 81 | _assuan_init_log_envvars (); 82 | } 83 | 84 | 85 | /* Set the per context log stream. Also enable the default log stream 86 | if it has not been set. */ 87 | void 88 | assuan_set_log_stream (assuan_context_t ctx, FILE *fp) 89 | { 90 | if (ctx) 91 | { 92 | if (ctx->log_fp) 93 | fflush (ctx->log_fp); 94 | ctx->log_fp = fp; 95 | if (! _assuan_log) 96 | assuan_set_assuan_log_stream (fp); 97 | } 98 | } 99 | 100 | 101 | /* Set the prefix to be used for logging to TEXT or resets it to the 102 | default if TEXT is NULL. */ 103 | void 104 | assuan_set_assuan_log_prefix (const char *text) 105 | { 106 | if (text) 107 | { 108 | strncpy (prefix_buffer, text, sizeof (prefix_buffer)-1); 109 | prefix_buffer[sizeof (prefix_buffer)-1] = 0; 110 | } 111 | else 112 | *prefix_buffer = 0; 113 | } 114 | 115 | 116 | /* Get the prefix to be used for logging. */ 117 | const char * 118 | assuan_get_assuan_log_prefix (void) 119 | { 120 | return prefix_buffer; 121 | } 122 | 123 | 124 | /* Default log handler. */ 125 | int 126 | _assuan_log_handler (assuan_context_t ctx, void *hook, unsigned int cat, 127 | const char *msg) 128 | { 129 | FILE *fp; 130 | const char *prf; 131 | int saved_errno = errno; 132 | 133 | /* For now. */ 134 | if (msg == NULL) 135 | return TEST_LOG_CAT (cat); 136 | 137 | if (! TEST_LOG_CAT (cat)) 138 | return 0; 139 | 140 | fp = ctx->log_fp ? ctx->log_fp : _assuan_log; 141 | if (!fp) 142 | return 0; 143 | 144 | prf = assuan_get_assuan_log_prefix (); 145 | if (*prf) 146 | fprintf (fp, "%s[%u]: ", prf, (unsigned int)getpid ()); 147 | 148 | fprintf (fp, "%s", msg); 149 | /* If the log stream is a file, the output would be buffered. This 150 | is bad for debugging, thus we flush the stream if FORMAT ends 151 | with a LF. */ 152 | if (msg && *msg && msg[strlen (msg) - 1] == '\n') 153 | fflush (fp); 154 | gpg_err_set_errno (saved_errno); 155 | 156 | return 0; 157 | } 158 | 159 | 160 | 161 | /* Log a control channel message. This is either a STRING with a 162 | diagnostic or actual data in (BUFFER1,LENGTH1) and 163 | (BUFFER2,LENGTH2). If OUTBOUND is true the data is intended for 164 | the peer. */ 165 | void 166 | _assuan_log_control_channel (assuan_context_t ctx, int outbound, 167 | const char *string, 168 | const void *buffer1, size_t length1, 169 | const void *buffer2, size_t length2) 170 | { 171 | int res; 172 | char *outbuf; 173 | int saved_errno; 174 | 175 | /* Check whether logging is enabled and do a quick check to see 176 | whether the callback supports our category. */ 177 | if (!ctx 178 | || !ctx->log_cb 179 | || ctx->flags.no_logging 180 | || !(*ctx->log_cb) (ctx, ctx->log_cb_data, ASSUAN_LOG_CONTROL, NULL)) 181 | return; 182 | 183 | saved_errno = errno; 184 | 185 | /* Note that we use the inbound channel fd as the printed channel 186 | number for both directions. */ 187 | #ifdef HAVE_W32_SYSTEM 188 | # define CHANNEL_FMT "%p" 189 | #else 190 | # define CHANNEL_FMT "%d" 191 | #endif 192 | #define TOHEX(val) (((val) < 10) ? ((val) + '0') : ((val) - 10 + 'a')) 193 | 194 | if (!buffer1 && buffer2) 195 | { 196 | buffer1 = buffer2; 197 | length1 = length2; 198 | buffer2 = NULL; 199 | length2 = 0; 200 | } 201 | 202 | if (ctx->flags.confidential && !string && buffer1) 203 | string = "[Confidential data not shown]"; 204 | 205 | if (string) 206 | { 207 | /* Print the diagnostic. */ 208 | res = gpgrt_asprintf (&outbuf, "chan_" CHANNEL_FMT " %s [%s]\n", 209 | ctx->inbound.fd, outbound? "->":"<-", string); 210 | } 211 | else if (buffer1) 212 | { 213 | /* Print the control channel data. */ 214 | const unsigned char *s; 215 | unsigned int n, x; 216 | 217 | for (n = length1, s = buffer1; n; n--, s++) 218 | if ((!isascii (*s) || iscntrl (*s) || !isprint (*s) || !*s) 219 | && !(*s >= 0x80)) 220 | break; 221 | if (!n && buffer2) 222 | { 223 | for (n = length2, s = buffer2; n; n--, s++) 224 | if ((!isascii (*s) || iscntrl (*s) || !isprint (*s) || !*s) 225 | && !(*s >= 0x80)) 226 | break; 227 | } 228 | if (!buffer2) 229 | length2 = 0; 230 | 231 | if (!n && (length1 && *(const char*)buffer1 != '[')) 232 | { 233 | /* No control characters and not starting with our error 234 | message indicator. Log it verbatim. */ 235 | res = gpgrt_asprintf (&outbuf, "chan_" CHANNEL_FMT " %s %.*s%.*s\n", 236 | ctx->inbound.fd, outbound? "->":"<-", 237 | (int)length1, (const char*)buffer1, 238 | (int)length2, buffer2? (const char*)buffer2:""); 239 | } 240 | else 241 | { 242 | /* The buffer contains control characters - do a hex dump. 243 | Even in full logging mode we limit the line length - 244 | however this is no real limit because the provided 245 | buffers will never be larger than the maximum assuan line 246 | length. */ 247 | char *hp; 248 | unsigned int nbytes; 249 | unsigned int maxbytes = full_logging? (2*LINELENGTH) : 16; 250 | 251 | nbytes = length1 + length2; 252 | if (nbytes > maxbytes) 253 | nbytes = maxbytes; 254 | 255 | if (!(outbuf = gpgrt_malloc (50 + 3*nbytes + 60 + 3 + 1))) 256 | res = -1; 257 | else 258 | { 259 | res = 0; 260 | hp = outbuf; 261 | snprintf (hp, 50, "chan_" CHANNEL_FMT " %s [", 262 | ctx->inbound.fd, outbound? "->":"<-"); 263 | hp += strlen (hp); 264 | n = 0; 265 | for (s = buffer1, x = 0; x < length1 && n < nbytes; x++, n++) 266 | { 267 | *hp++ = ' '; 268 | *hp++ = TOHEX (*s >> 4); 269 | *hp++ = TOHEX (*s & 0x0f); 270 | s++; 271 | } 272 | for (s = buffer2, x = 0; x < length2 && n < nbytes; x++, n++) 273 | { 274 | *hp++ = ' '; 275 | *hp++ = TOHEX (*s >> 4); 276 | *hp++ = TOHEX (*s & 0x0f); 277 | s++; 278 | } 279 | if (nbytes < length1 + length2) 280 | { 281 | snprintf (hp, 60, " ...(%u byte(s) skipped)", 282 | (unsigned int)((length1+length2) - nbytes)); 283 | hp += strlen (hp); 284 | } 285 | strcpy (hp, " ]\n"); 286 | } 287 | } 288 | } 289 | else 290 | { 291 | res = 0; 292 | outbuf = NULL; 293 | } 294 | if (res < 0) 295 | ctx->log_cb (ctx, ctx->log_cb_data, ASSUAN_LOG_CONTROL, 296 | "[libassuan failed to format the log message]"); 297 | else if (outbuf) 298 | { 299 | ctx->log_cb (ctx, ctx->log_cb_data, ASSUAN_LOG_CONTROL, outbuf); 300 | gpgrt_free (outbuf); 301 | } 302 | #undef TOHEX 303 | #undef CHANNEL_FMT 304 | gpg_err_set_errno (saved_errno); 305 | } 306 | -------------------------------------------------------------------------------- /m4/gpg-error.m4: -------------------------------------------------------------------------------- 1 | # gpg-error.m4 - autoconf macro to detect libgpg-error. 2 | # Copyright (C) 2002, 2003, 2004, 2011, 2014, 2018, 2020, 2021, 2022, 2024 3 | # g10 Code GmbH 4 | # 5 | # This file is free software; as a special exception the author gives 6 | # unlimited permission to copy and/or distribute it, with or without 7 | # modifications, as long as this notice is preserved. 8 | # 9 | # This file is distributed in the hope that it will be useful, but 10 | # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 11 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | # 13 | # Last-changed: 2024-06-13 14 | 15 | dnl 16 | dnl Find gpg-error-config, for backward compatibility 17 | dnl 18 | dnl _AM_PATH_POSSIBLE_GPG_ERROR_CONFIG 19 | AC_DEFUN([_AM_PATH_POSSIBLE_GPG_ERROR_CONFIG],[dnl 20 | gpg_error_config_prefix="" 21 | dnl --with-libgpg-error-prefix=PFX is the preferred name for this option, 22 | dnl since that is consistent with how our three siblings use the directory/ 23 | dnl package name in --with-$dir_name-prefix=PFX. 24 | AC_ARG_WITH(libgpg-error-prefix, 25 | AS_HELP_STRING([--with-libgpg-error-prefix=PFX], 26 | [prefix where GPG Error is installed (optional)]), 27 | [gpg_error_config_prefix="$withval"]) 28 | 29 | dnl Accept --with-gpg-error-prefix and make it work the same as 30 | dnl --with-libgpg-error-prefix above, for backwards compatibility, 31 | dnl but do not document this old, inconsistently-named option. 32 | AC_ARG_WITH(gpg-error-prefix,, 33 | [gpg_error_config_prefix="$withval"]) 34 | 35 | if test x"${GPG_ERROR_CONFIG}" = x ; then 36 | if test x"${gpg_error_config_prefix}" != x ; then 37 | GPG_ERROR_CONFIG="${gpg_error_config_prefix}/bin/gpg-error-config" 38 | else 39 | case "${SYSROOT}" in 40 | /*) 41 | if test -x "${SYSROOT}/bin/gpg-error-config" ; then 42 | GPG_ERROR_CONFIG="${SYSROOT}/bin/gpg-error-config" 43 | fi 44 | ;; 45 | '') 46 | ;; 47 | *) 48 | AC_MSG_WARN([Ignoring \$SYSROOT as it is not an absolute path.]) 49 | ;; 50 | esac 51 | fi 52 | fi 53 | 54 | AC_PATH_PROG(GPG_ERROR_CONFIG, gpg-error-config, no) 55 | ]) 56 | 57 | dnl 58 | dnl Find gpgrt-config, which uses .pc file 59 | dnl (minimum pkg-config functionality, supporting cross build) 60 | dnl 61 | dnl _AM_PATH_GPGRT_CONFIG 62 | AC_DEFUN([_AM_PATH_GPGRT_CONFIG],[dnl 63 | AC_PATH_PROG(GPGRT_CONFIG, gpgrt-config, no, [$prefix/bin:$PATH]) 64 | if test "$GPGRT_CONFIG" != "no"; then 65 | # Determine gpgrt_libdir 66 | # 67 | # Get the prefix of gpgrt-config assuming it's something like: 68 | # /bin/gpgrt-config 69 | gpgrt_prefix=${GPGRT_CONFIG%/*/*} 70 | possible_libdir1=${gpgrt_prefix}/lib 71 | # Determine by using system libdir-format with CC, it's like: 72 | # Normal style: /usr/lib 73 | # GNU cross style: /usr//lib 74 | # Debian style: /usr/lib/ 75 | # Fedora/openSUSE style: /usr/lib, /usr/lib32 or /usr/lib64 76 | # It is assumed that CC is specified to the one of host on cross build. 77 | if libdir_candidates=$(${CC:-cc} -print-search-dirs | \ 78 | sed -n -e "/^libraries/{s/libraries: =//;s/:/\\ 79 | /g;p;}"); then 80 | # From the output of -print-search-dirs, select valid pkgconfig dirs. 81 | libdir_candidates=$(for dir in $libdir_candidates; do 82 | if p=$(cd $dir 2>/dev/null && pwd); then 83 | test -d "$p/pkgconfig" && echo $p; 84 | fi 85 | done) 86 | 87 | for possible_libdir0 in $libdir_candidates; do 88 | # possible_libdir0: 89 | # Fallback candidate, the one of system-installed (by $CC) 90 | # (/usr//lib, /usr/lib/ or /usr/lib32) 91 | # possible_libdir1: 92 | # Another candidate, user-locally-installed 93 | # (/lib) 94 | # possible_libdir2 95 | # Most preferred 96 | # (//lib, 97 | # /lib/ or /lib32) 98 | if test "${possible_libdir0##*/}" = "lib"; then 99 | possible_prefix0=${possible_libdir0%/lib} 100 | possible_prefix0_triplet=${possible_prefix0##*/} 101 | if test -z "$possible_prefix0_triplet"; then 102 | continue 103 | fi 104 | possible_libdir2=${gpgrt_prefix}/$possible_prefix0_triplet/lib 105 | else 106 | possible_prefix0=${possible_libdir0%%/lib*} 107 | possible_libdir2=${gpgrt_prefix}${possible_libdir0#$possible_prefix0} 108 | fi 109 | if test -f ${possible_libdir2}/pkgconfig/gpg-error.pc; then 110 | gpgrt_libdir=${possible_libdir2} 111 | elif test -f ${possible_libdir1}/pkgconfig/gpg-error.pc; then 112 | gpgrt_libdir=${possible_libdir1} 113 | elif test -f ${possible_libdir0}/pkgconfig/gpg-error.pc; then 114 | gpgrt_libdir=${possible_libdir0} 115 | fi 116 | if test -n "$gpgrt_libdir"; then break; fi 117 | done 118 | fi 119 | if test -z "$gpgrt_libdir"; then 120 | # No valid pkgconfig dir in any of the system directories, fallback 121 | gpgrt_libdir=${possible_libdir1} 122 | fi 123 | else 124 | unset GPGRT_CONFIG 125 | fi 126 | 127 | if test -n "$gpgrt_libdir"; then 128 | # Add the --libdir option to GPGRT_CONFIG 129 | GPGRT_CONFIG="$GPGRT_CONFIG --libdir=$gpgrt_libdir" 130 | # Make sure if gpgrt-config really works, by testing config gpg-error 131 | if ! $GPGRT_CONFIG gpg-error --exists; then 132 | # If it doesn't work, clear the GPGRT_CONFIG variable. 133 | unset GPGRT_CONFIG 134 | fi 135 | else 136 | # GPGRT_CONFIG found but no suitable dir for --libdir found. 137 | # This is a failure. Clear the GPGRT_CONFIG variable. 138 | unset GPGRT_CONFIG 139 | fi 140 | ]) 141 | 142 | dnl AM_PATH_GPG_ERROR([MINIMUM-VERSION, 143 | dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]]) 144 | dnl 145 | dnl Test for libgpg-error and define GPG_ERROR_CFLAGS, GPG_ERROR_LIBS, 146 | dnl GPG_ERROR_MT_CFLAGS, and GPG_ERROR_MT_LIBS. The _MT_ variants are 147 | dnl used for programs requiring real multi thread support. 148 | dnl 149 | dnl If a prefix option is not used, the config script is first 150 | dnl searched in $SYSROOT/bin and then along $PATH. If the used 151 | dnl config script does not match the host specification the script 152 | dnl is added to the gpg_config_script_warn variable. 153 | dnl 154 | AC_DEFUN([AM_PATH_GPG_ERROR], 155 | [ AC_REQUIRE([AC_CANONICAL_HOST])dnl 156 | AC_REQUIRE([_AM_PATH_POSSIBLE_GPG_ERROR_CONFIG])dnl 157 | AC_REQUIRE([_AM_PATH_GPGRT_CONFIG])dnl 158 | if test x"$GPGRT_CONFIG" != x && test "$GPGRT_CONFIG" != "no"; then 159 | GPG_ERROR_CONFIG="$GPGRT_CONFIG gpg-error" 160 | AC_MSG_NOTICE([Use gpgrt-config with $gpgrt_libdir as gpg-error-config]) 161 | gpg_error_config_version=`$GPG_ERROR_CONFIG --modversion` 162 | elif test x"$GPG_ERROR_CONFIG" != x && test "$GPG_ERROR_CONFIG" != "no"; then 163 | gpg_error_config_version=`$GPG_ERROR_CONFIG --version` 164 | else 165 | gpg_error_config_version="0.0" 166 | fi 167 | 168 | min_gpg_error_version=ifelse([$1], ,1.33,$1) 169 | ok=no 170 | if test "$GPG_ERROR_CONFIG" != "no"; then 171 | req_major=`echo $min_gpg_error_version | \ 172 | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\1/'` 173 | req_minor=`echo $min_gpg_error_version | \ 174 | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\2/'` 175 | major=`echo $gpg_error_config_version | \ 176 | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'` 177 | minor=`echo $gpg_error_config_version | \ 178 | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'` 179 | if test "$major" -gt "$req_major"; then 180 | ok=yes 181 | else 182 | if test "$major" -eq "$req_major"; then 183 | if test "$minor" -ge "$req_minor"; then 184 | ok=yes 185 | fi 186 | fi 187 | fi 188 | fi 189 | AC_MSG_CHECKING(for GPG Error - version >= $min_gpg_error_version) 190 | if test $ok = yes; then 191 | GPG_ERROR_CFLAGS=`$GPG_ERROR_CONFIG --cflags` 192 | GPG_ERROR_LIBS=`$GPG_ERROR_CONFIG --libs` 193 | if test -z "$GPGRT_CONFIG"; then 194 | GPG_ERROR_MT_CFLAGS=`$GPG_ERROR_CONFIG --mt --cflags 2>/dev/null` 195 | GPG_ERROR_MT_LIBS=`$GPG_ERROR_CONFIG --mt --libs 2>/dev/null` 196 | else 197 | GPG_ERROR_MT_CFLAGS=`$GPG_ERROR_CONFIG --variable=mtcflags 2>/dev/null` 198 | GPG_ERROR_MT_CFLAGS="$GPG_ERROR_CFLAGS${GPG_ERROR_CFLAGS:+ }$GPG_ERROR_MT_CFLAGS" 199 | GPG_ERROR_MT_LIBS=`$GPG_ERROR_CONFIG --variable=mtlibs 2>/dev/null` 200 | GPG_ERROR_MT_LIBS="$GPG_ERROR_LIBS${GPG_ERROR_LIBS:+ }$GPG_ERROR_MT_LIBS" 201 | fi 202 | AC_MSG_RESULT([yes ($gpg_error_config_version)]) 203 | ifelse([$2], , :, [$2]) 204 | if test -z "$GPGRT_CONFIG"; then 205 | gpg_error_config_host=`$GPG_ERROR_CONFIG --host 2>/dev/null || echo none` 206 | else 207 | gpg_error_config_host=`$GPG_ERROR_CONFIG --variable=host 2>/dev/null || echo none` 208 | fi 209 | if test x"$gpg_error_config_host" != xnone ; then 210 | if test x"$gpg_error_config_host" != x"$host" ; then 211 | AC_MSG_WARN([[ 212 | *** 213 | *** The config script "$GPG_ERROR_CONFIG" was 214 | *** built for $gpg_error_config_host and thus may not match the 215 | *** used host $host. 216 | *** You may want to use the configure option --with-libgpg-error-prefix 217 | *** to specify a matching config script or use \$SYSROOT. 218 | ***]]) 219 | gpg_config_script_warn="$gpg_config_script_warn libgpg-error" 220 | fi 221 | fi 222 | else 223 | GPG_ERROR_CFLAGS="" 224 | GPG_ERROR_LIBS="" 225 | GPG_ERROR_MT_CFLAGS="" 226 | GPG_ERROR_MT_LIBS="" 227 | AC_MSG_RESULT(no) 228 | ifelse([$3], , :, [$3]) 229 | fi 230 | AC_SUBST(GPG_ERROR_CFLAGS) 231 | AC_SUBST(GPG_ERROR_LIBS) 232 | AC_SUBST(GPG_ERROR_MT_CFLAGS) 233 | AC_SUBST(GPG_ERROR_MT_LIBS) 234 | ]) 235 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | Installation Instructions 2 | ************************* 3 | 4 | Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004 Free 5 | Software Foundation, Inc. 6 | 7 | This file is free documentation; the Free Software Foundation gives 8 | unlimited permission to copy, distribute and modify it. 9 | 10 | Basic Installation 11 | ================== 12 | 13 | These are generic installation instructions. 14 | 15 | The `configure' shell script attempts to guess correct values for 16 | various system-dependent variables used during compilation. It uses 17 | those values to create a `Makefile' in each directory of the package. 18 | It may also create one or more `.h' files containing system-dependent 19 | definitions. Finally, it creates a shell script `config.status' that 20 | you can run in the future to recreate the current configuration, and a 21 | file `config.log' containing compiler output (useful mainly for 22 | debugging `configure'). 23 | 24 | It can also use an optional file (typically called `config.cache' 25 | and enabled with `--cache-file=config.cache' or simply `-C') that saves 26 | the results of its tests to speed up reconfiguring. (Caching is 27 | disabled by default to prevent problems with accidental use of stale 28 | cache files.) 29 | 30 | If you need to do unusual things to compile the package, please try 31 | to figure out how `configure' could check whether to do them, and mail 32 | diffs or instructions to the address given in the `README' so they can 33 | be considered for the next release. If you are using the cache, and at 34 | some point `config.cache' contains results you don't want to keep, you 35 | may remove or edit it. 36 | 37 | The file `configure.ac' (or `configure.in') is used to create 38 | `configure' by a program called `autoconf'. You only need 39 | `configure.ac' if you want to change it or regenerate `configure' using 40 | a newer version of `autoconf'. 41 | 42 | The simplest way to compile this package is: 43 | 44 | 1. `cd' to the directory containing the package's source code and type 45 | `./configure' to configure the package for your system. If you're 46 | using `csh' on an old version of System V, you might need to type 47 | `sh ./configure' instead to prevent `csh' from trying to execute 48 | `configure' itself. 49 | 50 | Running `configure' takes awhile. While running, it prints some 51 | messages telling which features it is checking for. 52 | 53 | 2. Type `make' to compile the package. 54 | 55 | 3. Optionally, type `make check' to run any self-tests that come with 56 | the package. 57 | 58 | 4. Type `make install' to install the programs and any data files and 59 | documentation. 60 | 61 | 5. You can remove the program binaries and object files from the 62 | source code directory by typing `make clean'. To also remove the 63 | files that `configure' created (so you can compile the package for 64 | a different kind of computer), type `make distclean'. There is 65 | also a `make maintainer-clean' target, but that is intended mainly 66 | for the package's developers. If you use it, you may have to get 67 | all sorts of other programs in order to regenerate files that came 68 | with the distribution. 69 | 70 | Compilers and Options 71 | ===================== 72 | 73 | Some systems require unusual options for compilation or linking that the 74 | `configure' script does not know about. Run `./configure --help' for 75 | details on some of the pertinent environment variables. 76 | 77 | You can give `configure' initial values for configuration parameters 78 | by setting variables in the command line or in the environment. Here 79 | is an example: 80 | 81 | ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix 82 | 83 | *Note Defining Variables::, for more details. 84 | 85 | Compiling For Multiple Architectures 86 | ==================================== 87 | 88 | You can compile the package for more than one kind of computer at the 89 | same time, by placing the object files for each architecture in their 90 | own directory. To do this, you must use a version of `make' that 91 | supports the `VPATH' variable, such as GNU `make'. `cd' to the 92 | directory where you want the object files and executables to go and run 93 | the `configure' script. `configure' automatically checks for the 94 | source code in the directory that `configure' is in and in `..'. 95 | 96 | If you have to use a `make' that does not support the `VPATH' 97 | variable, you have to compile the package for one architecture at a 98 | time in the source code directory. After you have installed the 99 | package for one architecture, use `make distclean' before reconfiguring 100 | for another architecture. 101 | 102 | Installation Names 103 | ================== 104 | 105 | By default, `make install' will install the package's files in 106 | `/usr/local/bin', `/usr/local/man', etc. You can specify an 107 | installation prefix other than `/usr/local' by giving `configure' the 108 | option `--prefix=PREFIX'. 109 | 110 | You can specify separate installation prefixes for 111 | architecture-specific files and architecture-independent files. If you 112 | give `configure' the option `--exec-prefix=PREFIX', the package will 113 | use PREFIX as the prefix for installing programs and libraries. 114 | Documentation and other data files will still use the regular prefix. 115 | 116 | In addition, if you use an unusual directory layout you can give 117 | options like `--bindir=DIR' to specify different values for particular 118 | kinds of files. Run `configure --help' for a list of the directories 119 | you can set and what kinds of files go in them. 120 | 121 | If the package supports it, you can cause programs to be installed 122 | with an extra prefix or suffix on their names by giving `configure' the 123 | option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. 124 | 125 | Optional Features 126 | ================= 127 | 128 | Some packages pay attention to `--enable-FEATURE' options to 129 | `configure', where FEATURE indicates an optional part of the package. 130 | They may also pay attention to `--with-PACKAGE' options, where PACKAGE 131 | is something like `gnu-as' or `x' (for the X Window System). The 132 | `README' should mention any `--enable-' and `--with-' options that the 133 | package recognizes. 134 | 135 | For packages that use the X Window System, `configure' can usually 136 | find the X include and library files automatically, but if it doesn't, 137 | you can use the `configure' options `--x-includes=DIR' and 138 | `--x-libraries=DIR' to specify their locations. 139 | 140 | Specifying the System Type 141 | ========================== 142 | 143 | There may be some features `configure' cannot figure out automatically, 144 | but needs to determine by the type of machine the package will run on. 145 | Usually, assuming the package is built to be run on the _same_ 146 | architectures, `configure' can figure that out, but if it prints a 147 | message saying it cannot guess the machine type, give it the 148 | `--build=TYPE' option. TYPE can either be a short name for the system 149 | type, such as `sun4', or a canonical name which has the form: 150 | 151 | CPU-COMPANY-SYSTEM 152 | 153 | where SYSTEM can have one of these forms: 154 | 155 | OS KERNEL-OS 156 | 157 | See the file `config.sub' for the possible values of each field. If 158 | `config.sub' isn't included in this package, then this package doesn't 159 | need to know the machine type. 160 | 161 | If you are _building_ compiler tools for cross-compiling, you should 162 | use the `--target=TYPE' option to select the type of system they will 163 | produce code for. 164 | 165 | If you want to _use_ a cross compiler, that generates code for a 166 | platform different from the build platform, you should specify the 167 | "host" platform (i.e., that on which the generated programs will 168 | eventually be run) with `--host=TYPE'. 169 | 170 | Sharing Defaults 171 | ================ 172 | 173 | If you want to set default values for `configure' scripts to share, you 174 | can create a site shell script called `config.site' that gives default 175 | values for variables like `CC', `cache_file', and `prefix'. 176 | `configure' looks for `PREFIX/share/config.site' if it exists, then 177 | `PREFIX/etc/config.site' if it exists. Or, you can set the 178 | `CONFIG_SITE' environment variable to the location of the site script. 179 | A warning: not all `configure' scripts look for a site script. 180 | 181 | Defining Variables 182 | ================== 183 | 184 | Variables not defined in a site shell script can be set in the 185 | environment passed to `configure'. However, some packages may run 186 | configure again during the build, and the customized values of these 187 | variables may be lost. In order to avoid this problem, you should set 188 | them in the `configure' command line, using `VAR=value'. For example: 189 | 190 | ./configure CC=/usr/local2/bin/gcc 191 | 192 | will cause the specified gcc to be used as the C compiler (unless it is 193 | overridden in the site shell script). 194 | 195 | `configure' Invocation 196 | ====================== 197 | 198 | `configure' recognizes the following options to control how it operates. 199 | 200 | `--help' 201 | `-h' 202 | Print a summary of the options to `configure', and exit. 203 | 204 | `--version' 205 | `-V' 206 | Print the version of Autoconf used to generate the `configure' 207 | script, and exit. 208 | 209 | `--cache-file=FILE' 210 | Enable the cache: use and save the results of the tests in FILE, 211 | traditionally `config.cache'. FILE defaults to `/dev/null' to 212 | disable caching. 213 | 214 | `--config-cache' 215 | `-C' 216 | Alias for `--cache-file=config.cache'. 217 | 218 | `--quiet' 219 | `--silent' 220 | `-q' 221 | Do not print messages saying which checks are being made. To 222 | suppress all normal output, redirect it to `/dev/null' (any error 223 | messages will still be shown). 224 | 225 | `--srcdir=DIR' 226 | Look for the package's source code in directory DIR. Usually 227 | `configure' can determine that directory automatically. 228 | 229 | `configure' also accepts some other, not widely useful, options. Run 230 | `configure --help' for more details. 231 | 232 | -------------------------------------------------------------------------------- /src/setenv.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1992,1995-2001,2004 Free Software Foundation, Inc. 2 | * This file is part of the GNU C Library. 3 | * 4 | * The GNU C Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * The GNU C Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with the GNU C Library; if not, 16 | * see . 17 | * SPDX-License-Identifier: LGPL-2.1+ 18 | */ 19 | 20 | #if HAVE_CONFIG_H 21 | # include 22 | #endif 23 | 24 | #define setenv _assuan_setenv 25 | #define unsetenv _assuan_unsetenv 26 | #define clearenv _assuan_clearenv 27 | 28 | 29 | #define __builtin_expect(cond,val) (cond) 30 | 31 | #include 32 | #if !_LIBC 33 | # if !defined errno && !defined HAVE_ERRNO_DECL 34 | extern int errno; 35 | # endif 36 | # define __set_errno(ev) ((errno) = (ev)) 37 | #endif 38 | 39 | #if _LIBC || HAVE_STDLIB_H 40 | # include 41 | #endif 42 | #if _LIBC || HAVE_STRING_H 43 | # include 44 | #endif 45 | #if _LIBC || HAVE_UNISTD_H 46 | # include 47 | #endif 48 | 49 | #if !_LIBC 50 | # define __environ environ 51 | # ifndef HAVE_ENVIRON_DECL 52 | extern char **environ; 53 | # endif 54 | #endif 55 | 56 | #if _LIBC 57 | /* This lock protects against simultaneous modifications of `environ'. */ 58 | # include 59 | __libc_lock_define_initialized (static, envlock) 60 | # define LOCK __libc_lock_lock (envlock) 61 | # define UNLOCK __libc_lock_unlock (envlock) 62 | #else 63 | # define LOCK 64 | # define UNLOCK 65 | #endif 66 | 67 | /* In the GNU C library we must keep the namespace clean. */ 68 | #ifdef _LIBC 69 | # define setenv __setenv 70 | # define unsetenv __unsetenv 71 | # define clearenv __clearenv 72 | # define tfind __tfind 73 | # define tsearch __tsearch 74 | #endif 75 | 76 | /* In the GNU C library implementation we try to be more clever and 77 | allow arbitrarily many changes of the environment given that the used 78 | values are from a small set. Outside glibc this will eat up all 79 | memory after a while. */ 80 | #if defined _LIBC || (defined HAVE_SEARCH_H && defined HAVE_TSEARCH \ 81 | && defined __GNUC__) 82 | # define USE_TSEARCH 1 83 | # include 84 | 85 | /* This is a pointer to the root of the search tree with the known 86 | values. */ 87 | static void *known_values; 88 | 89 | # define KNOWN_VALUE(Str) \ 90 | ({ \ 91 | void *value = tfind (Str, &known_values, (__compar_fn_t) strcmp); \ 92 | value != NULL ? *(char **) value : NULL; \ 93 | }) 94 | # define STORE_VALUE(Str) \ 95 | tsearch (Str, &known_values, (__compar_fn_t) strcmp) 96 | 97 | #else 98 | # undef USE_TSEARCH 99 | 100 | # define KNOWN_VALUE(Str) NULL 101 | # define STORE_VALUE(Str) do { } while (0) 102 | 103 | #endif 104 | 105 | 106 | /* If this variable is not a null pointer we allocated the current 107 | environment. */ 108 | static char **last_environ; 109 | 110 | 111 | /* This function is used by `setenv' and `putenv'. The difference between 112 | the two functions is that for the former must create a new string which 113 | is then placed in the environment, while the argument of `putenv' 114 | must be used directly. This is all complicated by the fact that we try 115 | to reuse values once generated for a `setenv' call since we can never 116 | free the strings. */ 117 | static int 118 | __add_to_environ (const char *name, const char *value, const char *combined, 119 | int replace) 120 | { 121 | register char **ep; 122 | register size_t size; 123 | const size_t namelen = strlen (name); 124 | const size_t vallen = value != NULL ? strlen (value) + 1 : 0; 125 | 126 | LOCK; 127 | 128 | /* We have to get the pointer now that we have the lock and not earlier 129 | since another thread might have created a new environment. */ 130 | ep = __environ; 131 | 132 | size = 0; 133 | if (ep != NULL) 134 | { 135 | for (; *ep != NULL; ++ep) 136 | if (!strncmp (*ep, name, namelen) && (*ep)[namelen] == '=') 137 | break; 138 | else 139 | ++size; 140 | } 141 | 142 | if (ep == NULL || __builtin_expect (*ep == NULL, 1)) 143 | { 144 | char **new_environ; 145 | 146 | /* We allocated this space; we can extend it. */ 147 | new_environ = (char **) realloc (last_environ, 148 | (size + 2) * sizeof (char *)); 149 | if (new_environ == NULL) 150 | { 151 | UNLOCK; 152 | return -1; 153 | } 154 | 155 | /* If the whole entry is given add it. */ 156 | if (combined != NULL) 157 | /* We must not add the string to the search tree since it belongs 158 | to the user. */ 159 | new_environ[size] = (char *) combined; 160 | else 161 | { 162 | /* See whether the value is already known. */ 163 | #ifdef USE_TSEARCH 164 | # ifdef __GNUC__ 165 | char new_value[namelen + 1 + vallen]; 166 | # else 167 | char *new_value = (char *) alloca (namelen + 1 + vallen); 168 | # endif 169 | # ifdef _LIBC 170 | __mempcpy (__mempcpy (__mempcpy (new_value, name, namelen), "=", 1), 171 | value, vallen); 172 | # else 173 | memcpy (new_value, name, namelen); 174 | new_value[namelen] = '='; 175 | memcpy (&new_value[namelen + 1], value, vallen); 176 | # endif 177 | 178 | new_environ[size] = KNOWN_VALUE (new_value); 179 | if (__builtin_expect (new_environ[size] == NULL, 1)) 180 | #endif 181 | { 182 | new_environ[size] = (char *) malloc (namelen + 1 + vallen); 183 | if (__builtin_expect (new_environ[size] == NULL, 0)) 184 | { 185 | __set_errno (ENOMEM); 186 | UNLOCK; 187 | return -1; 188 | } 189 | 190 | #ifdef USE_TSEARCH 191 | memcpy (new_environ[size], new_value, namelen + 1 + vallen); 192 | #else 193 | memcpy (new_environ[size], name, namelen); 194 | new_environ[size][namelen] = '='; 195 | memcpy (&new_environ[size][namelen + 1], value, vallen); 196 | #endif 197 | /* And save the value now. We cannot do this when we remove 198 | the string since then we cannot decide whether it is a 199 | user string or not. */ 200 | STORE_VALUE (new_environ[size]); 201 | } 202 | } 203 | 204 | if (__environ != last_environ) 205 | memcpy ((char *) new_environ, (char *) __environ, 206 | size * sizeof (char *)); 207 | 208 | new_environ[size + 1] = NULL; 209 | 210 | last_environ = __environ = new_environ; 211 | } 212 | else if (replace) 213 | { 214 | char *np; 215 | 216 | /* Use the user string if given. */ 217 | if (combined != NULL) 218 | np = (char *) combined; 219 | else 220 | { 221 | #ifdef USE_TSEARCH 222 | # ifdef __GNUC__ 223 | char new_value[namelen + 1 + vallen]; 224 | # else 225 | char *new_value = (char *) alloca (namelen + 1 + vallen); 226 | # endif 227 | # ifdef _LIBC 228 | __mempcpy (__mempcpy (__mempcpy (new_value, name, namelen), "=", 1), 229 | value, vallen); 230 | # else 231 | memcpy (new_value, name, namelen); 232 | new_value[namelen] = '='; 233 | memcpy (&new_value[namelen + 1], value, vallen); 234 | # endif 235 | 236 | np = KNOWN_VALUE (new_value); 237 | if (__builtin_expect (np == NULL, 1)) 238 | #endif 239 | { 240 | np = malloc (namelen + 1 + vallen); 241 | if (__builtin_expect (np == NULL, 0)) 242 | { 243 | UNLOCK; 244 | return -1; 245 | } 246 | 247 | #ifdef USE_TSEARCH 248 | memcpy (np, new_value, namelen + 1 + vallen); 249 | #else 250 | memcpy (np, name, namelen); 251 | np[namelen] = '='; 252 | memcpy (&np[namelen + 1], value, vallen); 253 | #endif 254 | /* And remember the value. */ 255 | STORE_VALUE (np); 256 | } 257 | } 258 | 259 | *ep = np; 260 | } 261 | 262 | UNLOCK; 263 | 264 | return 0; 265 | } 266 | 267 | int 268 | setenv (const char *name, const char *value, int replace) 269 | { 270 | if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) 271 | { 272 | __set_errno (EINVAL); 273 | return -1; 274 | } 275 | 276 | return __add_to_environ (name, value, NULL, replace); 277 | } 278 | 279 | int 280 | unsetenv (const char *name) 281 | { 282 | size_t len; 283 | char **ep; 284 | 285 | if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) 286 | { 287 | __set_errno (EINVAL); 288 | return -1; 289 | } 290 | 291 | len = strlen (name); 292 | 293 | LOCK; 294 | 295 | ep = __environ; 296 | while (*ep != NULL) 297 | if (!strncmp (*ep, name, len) && (*ep)[len] == '=') 298 | { 299 | /* Found it. Remove this pointer by moving later ones back. */ 300 | char **dp = ep; 301 | 302 | do 303 | dp[0] = dp[1]; 304 | while (*dp++); 305 | /* Continue the loop in case NAME appears again. */ 306 | } 307 | else 308 | ++ep; 309 | 310 | UNLOCK; 311 | 312 | return 0; 313 | } 314 | 315 | /* The `clearenv' was planned to be added to POSIX.1 but probably 316 | never made it. Nevertheless the POSIX.9 standard (POSIX bindings 317 | for Fortran 77) requires this function. */ 318 | int 319 | clearenv (void) 320 | { 321 | LOCK; 322 | 323 | if (__environ == last_environ && __environ != NULL) 324 | { 325 | /* We allocated this environment so we can free it. */ 326 | free (__environ); 327 | last_environ = NULL; 328 | } 329 | 330 | /* Clear the environment pointer removes the whole environment. */ 331 | __environ = NULL; 332 | 333 | UNLOCK; 334 | 335 | return 0; 336 | } 337 | #ifdef _LIBC 338 | libc_freeres_fn (free_mem) 339 | { 340 | /* Remove all traces. */ 341 | clearenv (); 342 | 343 | /* Now remove the search tree. */ 344 | __tdestroy (known_values, free); 345 | known_values = NULL; 346 | } 347 | 348 | # undef setenv 349 | # undef unsetenv 350 | # undef clearenv 351 | weak_alias (__setenv, setenv) 352 | weak_alias (__unsetenv, unsetenv) 353 | weak_alias (__clearenv, clearenv) 354 | #endif 355 | -------------------------------------------------------------------------------- /src/libassuan.m4: -------------------------------------------------------------------------------- 1 | dnl Autoconf macros for libassuan 2 | dnl Copyright (C) 2002, 2003, 2011 Free Software Foundation, Inc. 3 | dnl 4 | dnl This file is free software; as a special exception the author gives 5 | dnl unlimited permission to copy and/or distribute it, with or without 6 | dnl modifications, as long as this notice is preserved. 7 | dnl 8 | dnl This file is distributed in the hope that it will be useful, but 9 | dnl WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 10 | dnl implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 | dnl SPDX-License-Identifier: FSFULLR 12 | # Last-changed: 2025-09-24 13 | 14 | dnl 15 | dnl Find gpgrt-config, which uses .pc file 16 | dnl (minimum pkg-config functionality, supporting cross build) 17 | dnl 18 | dnl _AM_PATH_GPGRT_CONFIG 19 | AC_DEFUN([_AM_PATH_GPGRT_CONFIG],[dnl 20 | AC_PATH_PROG(GPGRT_CONFIG, gpgrt-config, no, [$prefix/bin:$PATH]) 21 | if test "$GPGRT_CONFIG" != "no"; then 22 | # Determine gpgrt_libdir 23 | # 24 | # Get the prefix of gpgrt-config assuming it's something like: 25 | # /bin/gpgrt-config 26 | gpgrt_prefix=${GPGRT_CONFIG%/*/*} 27 | possible_libdir1=${gpgrt_prefix}/lib 28 | # Determine by using system libdir-format with CC, it's like: 29 | # Normal style: /usr/lib 30 | # GNU cross style: /usr//lib 31 | # Debian style: /usr/lib/ 32 | # Fedora/openSUSE style: /usr/lib, /usr/lib32 or /usr/lib64 33 | # It is assumed that CC is specified to the one of host on cross build. 34 | if libdir_candidates=$(${CC:-cc} -print-search-dirs | \ 35 | sed -n -e "/^libraries/{s/libraries: =//;s/:/\\ 36 | /g;p;}"); then 37 | # From the output of -print-search-dirs, select valid pkgconfig dirs. 38 | libdir_candidates=$(for dir in $libdir_candidates; do 39 | if p=$(cd $dir 2>/dev/null && pwd); then 40 | test -d "$p/pkgconfig" && echo $p; 41 | fi 42 | done) 43 | 44 | for possible_libdir0 in $libdir_candidates; do 45 | # possible_libdir0: 46 | # Fallback candidate, the one of system-installed (by $CC) 47 | # (/usr//lib, /usr/lib/ or /usr/lib32) 48 | # possible_libdir1: 49 | # Another candidate, user-locally-installed 50 | # (/lib) 51 | # possible_libdir2 52 | # Most preferred 53 | # (//lib, 54 | # /lib/ or /lib32) 55 | if test "${possible_libdir0##*/}" = "lib"; then 56 | possible_prefix0=${possible_libdir0%/lib} 57 | possible_prefix0_triplet=${possible_prefix0##*/} 58 | if test -z "$possible_prefix0_triplet"; then 59 | continue 60 | fi 61 | possible_libdir2=${gpgrt_prefix}/$possible_prefix0_triplet/lib 62 | else 63 | possible_prefix0=${possible_libdir0%%/lib*} 64 | possible_libdir2=${gpgrt_prefix}${possible_libdir0#$possible_prefix0} 65 | fi 66 | if test -f ${possible_libdir2}/pkgconfig/gpg-error.pc; then 67 | gpgrt_libdir=${possible_libdir2} 68 | elif test -f ${possible_libdir1}/pkgconfig/gpg-error.pc; then 69 | gpgrt_libdir=${possible_libdir1} 70 | elif test -f ${possible_libdir0}/pkgconfig/gpg-error.pc; then 71 | gpgrt_libdir=${possible_libdir0} 72 | fi 73 | if test -n "$gpgrt_libdir"; then break; fi 74 | done 75 | fi 76 | if test -z "$gpgrt_libdir"; then 77 | # No valid pkgconfig dir in any of the system directories, fallback 78 | gpgrt_libdir=${possible_libdir1} 79 | fi 80 | else 81 | unset GPGRT_CONFIG 82 | fi 83 | 84 | if test -n "$gpgrt_libdir"; then 85 | # Add the --libdir option to GPGRT_CONFIG 86 | GPGRT_CONFIG="$GPGRT_CONFIG --libdir=$gpgrt_libdir" 87 | # Make sure if gpgrt-config really works, by testing config gpg-error 88 | if ! $GPGRT_CONFIG gpg-error --exists; then 89 | # If it doesn't work, clear the GPGRT_CONFIG variable. 90 | unset GPGRT_CONFIG 91 | fi 92 | else 93 | # GPGRT_CONFIG found but no suitable dir for --libdir found. 94 | # This is a failure. Clear the GPGRT_CONFIG variable. 95 | unset GPGRT_CONFIG 96 | fi 97 | ]) 98 | 99 | dnl 100 | dnl Common code used for libassuan detection [internal] 101 | dnl Returns ok set to yes or no. 102 | dnl 103 | AC_DEFUN([_AM_PATH_LIBASSUAN_COMMON], 104 | [ AC_REQUIRE([AC_CANONICAL_HOST])dnl 105 | AC_REQUIRE([_AM_PATH_GPGRT_CONFIG])dnl 106 | AC_ARG_WITH(libassuan-prefix, 107 | AS_HELP_STRING([--with-libassuan-prefix=PFX], 108 | [prefix where LIBASSUAN is installed (optional)]), 109 | libassuan_config_prefix="$withval", libassuan_config_prefix="") 110 | if test x$libassuan_config_prefix != x ; then 111 | if test x${LIBASSUAN_CONFIG+set} != xset ; then 112 | LIBASSUAN_CONFIG=$libassuan_config_prefix/bin/libassuan-config 113 | fi 114 | fi 115 | 116 | use_gpgrt_config="" 117 | if test x"$GPGRT_CONFIG" != x && test "$GPGRT_CONFIG" != "no"; then 118 | if $GPGRT_CONFIG libassuan --exists; then 119 | LIBASSUAN_CONFIG="$GPGRT_CONFIG libassuan" 120 | AC_MSG_NOTICE([Use gpgrt-config as libassuan-config]) 121 | use_gpgrt_config=yes 122 | fi 123 | fi 124 | if test -z "$use_gpgrt_config"; then 125 | AC_PATH_PROG(LIBASSUAN_CONFIG, libassuan-config, no) 126 | fi 127 | 128 | tmp=ifelse([$1], ,1:0.9.2,$1) 129 | if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then 130 | req_libassuan_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'` 131 | min_libassuan_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'` 132 | else 133 | req_libassuan_api=0 134 | min_libassuan_version="$tmp" 135 | fi 136 | 137 | AC_MSG_CHECKING(for LIBASSUAN - version >= $min_libassuan_version) 138 | ok=no 139 | if test "$LIBASSUAN_CONFIG" != "no"; then 140 | req_major=`echo $min_libassuan_version | \ 141 | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'` 142 | req_minor=`echo $min_libassuan_version | \ 143 | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'` 144 | req_micro=`echo $min_libassuan_version | \ 145 | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'` 146 | 147 | if test -z "$use_gpgrt_config"; then 148 | libassuan_config_version=`$LIBASSUAN_CONFIG --version` 149 | else 150 | libassuan_config_version=`$LIBASSUAN_CONFIG --modversion` 151 | fi 152 | major=`echo $libassuan_config_version | \ 153 | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'` 154 | minor=`echo $libassuan_config_version | \ 155 | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'` 156 | micro=`echo $libassuan_config_version | \ 157 | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'` 158 | 159 | if test "$major" -gt "$req_major"; then 160 | ok=yes 161 | else 162 | if test "$major" -eq "$req_major"; then 163 | if test "$minor" -gt "$req_minor"; then 164 | ok=yes 165 | else 166 | if test "$minor" -eq "$req_minor"; then 167 | if test "$micro" -ge "$req_micro"; then 168 | ok=yes 169 | fi 170 | fi 171 | fi 172 | fi 173 | fi 174 | fi 175 | 176 | if test $ok = yes; then 177 | AC_MSG_RESULT([yes ($libassuan_config_version)]) 178 | AC_DEFINE_UNQUOTED(LIBASSUAN_API_REQUESTED, $req_libassuan_api, [Requested API version for libassuan]) 179 | else 180 | AC_MSG_RESULT(no) 181 | fi 182 | 183 | if test $ok = yes; then 184 | if test "$req_libassuan_api" -gt 0 ; then 185 | if test -z "$use_gpgrt_config"; then 186 | tmp=`$LIBASSUAN_CONFIG --api-version 2>/dev/null || echo 0` 187 | else 188 | tmp=`$LIBASSUAN_CONFIG --variable=api_version 2>/dev/null || echo 0` 189 | fi 190 | if test "$tmp" -gt 0 ; then 191 | AC_MSG_CHECKING([LIBASSUAN API version]) 192 | if test "$req_libassuan_api" -eq "$tmp" ; then 193 | AC_MSG_RESULT(okay) 194 | elif test "$req_libassuan_api" -eq 2 && test "$tmp" -eq 3; then 195 | AC_MSG_RESULT(okay) 196 | else 197 | ok=no 198 | AC_MSG_RESULT([does not match. want=$req_libassuan_api got=$tmp.]) 199 | fi 200 | fi 201 | fi 202 | fi 203 | 204 | if test $ok = yes; then 205 | if test x"$host" != x ; then 206 | if test -z "$use_gpgrt_config"; then 207 | libassuan_config_host=`$LIBASSUAN_CONFIG --host 2>/dev/null || echo none` 208 | else 209 | libassuan_config_host=`$LIBASSUAN_CONFIG --variable=host 2>/dev/null || echo none` 210 | fi 211 | if test x"$libassuan_config_host" != xnone ; then 212 | if test x"$libassuan_config_host" != x"$host" ; then 213 | AC_MSG_WARN([[ 214 | *** 215 | *** The config script "$LIBASSUAN_CONFIG" was 216 | *** built for $libassuan_config_host and thus may not match the 217 | *** used host $host. 218 | *** You may want to use the configure option --with-libassuan-prefix 219 | *** to specify a matching config script. 220 | ***]]) 221 | fi 222 | fi 223 | fi 224 | fi 225 | ]) 226 | 227 | dnl AM_CHECK_LIBASSUAN([MINIMUM-VERSION, 228 | dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]]) 229 | dnl Test whether libassuan has at least MINIMUM-VERSION. This is 230 | dnl used to test for features only available in newer versions. 231 | dnl 232 | AC_DEFUN([AM_CHECK_LIBASSUAN], 233 | [ _AM_PATH_LIBASSUAN_COMMON($1) 234 | if test $ok = yes; then 235 | ifelse([$2], , :, [$2]) 236 | else 237 | ifelse([$3], , :, [$3]) 238 | fi 239 | ]) 240 | 241 | 242 | 243 | 244 | dnl AM_PATH_LIBASSUAN([MINIMUM-VERSION, 245 | dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]]) 246 | dnl Test for libassuan and define LIBASSUAN_CFLAGS and LIBASSUAN_LIBS 247 | dnl 248 | AC_DEFUN([AM_PATH_LIBASSUAN], 249 | [ _AM_PATH_LIBASSUAN_COMMON($1) 250 | if test $ok = yes; then 251 | LIBASSUAN_CFLAGS=`$LIBASSUAN_CONFIG --cflags` 252 | LIBASSUAN_LIBS=`$LIBASSUAN_CONFIG --libs` 253 | ifelse([$2], , :, [$2]) 254 | else 255 | LIBASSUAN_CFLAGS="" 256 | LIBASSUAN_LIBS="" 257 | ifelse([$3], , :, [$3]) 258 | fi 259 | AC_SUBST(LIBASSUAN_CFLAGS) 260 | AC_SUBST(LIBASSUAN_LIBS) 261 | ]) 262 | -------------------------------------------------------------------------------- /src/assuan.c: -------------------------------------------------------------------------------- 1 | /* assuan.c - Global interface (not specific to context). 2 | * Copyright (C) 2009 Free Software Foundation, Inc. 3 | * Copyright (C) 2001, 2002, 2012, 2013 g10 Code GmbH 4 | * 5 | * This file is part of Assuan. 6 | * 7 | * Assuan is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Assuan is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | * SPDX-License-Identifier: LGPL-2.1+ 20 | */ 21 | 22 | 23 | #ifdef HAVE_CONFIG_H 24 | #include 25 | #endif 26 | 27 | #include 28 | 29 | #include "assuan-defs.h" 30 | #include "debug.h" 31 | 32 | 33 | #define digitp(a) ((a) >= '0' && (a) <= '9') 34 | 35 | 36 | 37 | /* Global default state. */ 38 | 39 | /* Functions called before and after blocking syscalls. */ 40 | static void (*pre_syscall_func) (void); 41 | static void (*post_syscall_func) (void); 42 | 43 | /* Variable to see if functions above are initialized. */ 44 | static int _assuan_syscall_func_initialized; 45 | 46 | 47 | /* The default error source gor generated error codes. */ 48 | static gpg_err_source_t _assuan_default_err_source = GPG_ERR_SOURCE_USER_1; 49 | 50 | /* The default memory management functions. */ 51 | static struct assuan_malloc_hooks _assuan_default_malloc_hooks = 52 | { malloc, realloc, free }; 53 | 54 | /* The default logging handler. */ 55 | static assuan_log_cb_t _assuan_default_log_cb = _assuan_log_handler; 56 | static void *_assuan_default_log_cb_data = NULL; 57 | 58 | 59 | /* Set the default gpg error source. */ 60 | void 61 | assuan_set_gpg_err_source (gpg_err_source_t errsource) 62 | { 63 | _assuan_default_err_source = errsource; 64 | } 65 | 66 | 67 | /* Get the default gpg error source. */ 68 | gpg_err_source_t 69 | assuan_get_gpg_err_source (void) 70 | { 71 | return _assuan_default_err_source; 72 | } 73 | 74 | 75 | /* Set the default malloc hooks. */ 76 | void 77 | assuan_set_malloc_hooks (assuan_malloc_hooks_t malloc_hooks) 78 | { 79 | _assuan_default_malloc_hooks = *malloc_hooks; 80 | } 81 | 82 | 83 | /* Get the default malloc hooks. */ 84 | assuan_malloc_hooks_t 85 | assuan_get_malloc_hooks (void) 86 | { 87 | return &_assuan_default_malloc_hooks; 88 | } 89 | 90 | 91 | /* Set the default log callback handler. */ 92 | void 93 | assuan_set_log_cb (assuan_log_cb_t log_cb, void *log_cb_data) 94 | { 95 | _assuan_default_log_cb = log_cb; 96 | _assuan_default_log_cb_data = log_cb_data; 97 | _assuan_init_log_envvars (); 98 | } 99 | 100 | 101 | /* Get the default log callback handler. */ 102 | void 103 | assuan_get_log_cb (assuan_log_cb_t *log_cb, void **log_cb_data) 104 | { 105 | *log_cb = _assuan_default_log_cb; 106 | *log_cb_data = _assuan_default_log_cb_data; 107 | } 108 | 109 | 110 | void 111 | assuan_set_system_hooks (assuan_system_hooks_t system_hooks) 112 | { 113 | _assuan_system_hooks_copy (&_assuan_system_hooks, system_hooks); 114 | } 115 | 116 | 117 | gpg_error_t 118 | assuan_control (enum assuan_ctl_cmds cmd, void *arg) 119 | { 120 | gpg_error_t err = 0; 121 | 122 | (void)arg; 123 | switch (cmd) 124 | { 125 | case ASSUAN_CONTROL_NOP: 126 | default: 127 | /* Nothing to do. */ 128 | break; 129 | case ASSUAN_CONTROL_REINIT_SYSCALL_CLAMP: 130 | gpgrt_get_syscall_clamp (&pre_syscall_func, &post_syscall_func); 131 | _assuan_syscall_func_initialized = 1; 132 | break; 133 | } 134 | 135 | return err; 136 | } 137 | 138 | /* Used before blocking system calls. */ 139 | void 140 | _assuan_pre_syscall (void) 141 | { 142 | again: 143 | if (pre_syscall_func) 144 | pre_syscall_func (); 145 | else if (!_assuan_syscall_func_initialized) 146 | { 147 | gpgrt_get_syscall_clamp (&pre_syscall_func, &post_syscall_func); 148 | _assuan_syscall_func_initialized = 1; 149 | goto again; 150 | } 151 | } 152 | 153 | 154 | /* Used after blocking system calls. */ 155 | void 156 | _assuan_post_syscall (void) 157 | { 158 | if (post_syscall_func) 159 | post_syscall_func (); 160 | } 161 | 162 | /* Create a new Assuan context. The initial parameters are all needed 163 | in the creation of the context. */ 164 | gpg_error_t 165 | assuan_new_ext (assuan_context_t *r_ctx, gpg_err_source_t err_source, 166 | assuan_malloc_hooks_t malloc_hooks, assuan_log_cb_t log_cb, 167 | void *log_cb_data) 168 | { 169 | struct assuan_context_s wctx; 170 | assuan_context_t ctx; 171 | 172 | /* Set up a working context so we can use standard functions. */ 173 | memset (&wctx, 0, sizeof (wctx)); 174 | wctx.err_source = err_source; 175 | if (malloc_hooks == NULL) 176 | wctx.malloc_hooks = _assuan_default_malloc_hooks; 177 | else 178 | wctx.malloc_hooks = *malloc_hooks; 179 | wctx.log_cb = log_cb; 180 | wctx.log_cb_data = log_cb_data; 181 | 182 | /* Need a new block for the trace macros to work. */ 183 | { 184 | TRACE_BEG8 (&wctx, ASSUAN_LOG_CTX, "assuan_new_ext", r_ctx, 185 | "err_source = %i (%s), malloc_hooks = %p (%p, %p, %p), " 186 | "log_cb = %p, log_cb_data = %p", err_source, 187 | gpg_strsource (err_source), malloc_hooks, 188 | malloc_hooks ? malloc_hooks->malloc : NULL, 189 | malloc_hooks ? malloc_hooks->realloc : NULL, 190 | malloc_hooks ? malloc_hooks->free : NULL, 191 | log_cb, log_cb_data); 192 | 193 | *r_ctx = NULL; 194 | ctx = _assuan_malloc (&wctx, sizeof (*ctx)); 195 | if (!ctx) 196 | return TRACE_ERR (gpg_err_code_from_syserror ()); 197 | 198 | memcpy (ctx, &wctx, sizeof (*ctx)); 199 | ctx->system = _assuan_system_hooks; 200 | 201 | /* FIXME: Delegate to subsystems/engines, as the FDs are not our 202 | responsibility (we don't deallocate them, for example). */ 203 | ctx->input_fd = ASSUAN_INVALID_FD; 204 | ctx->output_fd = ASSUAN_INVALID_FD; 205 | ctx->inbound.fd = ASSUAN_INVALID_FD; 206 | ctx->outbound.fd = ASSUAN_INVALID_FD; 207 | ctx->listen_fd = ASSUAN_INVALID_FD; 208 | 209 | #if defined(HAVE_W32_SYSTEM) 210 | ctx->process_id = -1; 211 | #else 212 | ctx->pid = ASSUAN_INVALID_PID; 213 | #endif 214 | ctx->server_proc = -1; 215 | 216 | *r_ctx = ctx; 217 | 218 | return TRACE_SUC1 ("ctx=%p", ctx); 219 | } 220 | } 221 | 222 | 223 | /* Create a new context with default arguments. */ 224 | gpg_error_t 225 | assuan_new (assuan_context_t *r_ctx) 226 | { 227 | return assuan_new_ext (r_ctx, _assuan_default_err_source, 228 | &_assuan_default_malloc_hooks, 229 | _assuan_default_log_cb, 230 | _assuan_default_log_cb_data); 231 | } 232 | 233 | 234 | /* Release all resources associated with an engine operation. */ 235 | void 236 | _assuan_reset (assuan_context_t ctx) 237 | { 238 | if (ctx->engine.release) 239 | { 240 | (*ctx->engine.release) (ctx); 241 | ctx->engine.release = NULL; 242 | } 243 | 244 | /* FIXME: Clean standard commands */ 245 | } 246 | 247 | 248 | /* Release all resources associated with the given context. */ 249 | void 250 | assuan_release (assuan_context_t ctx) 251 | { 252 | if (! ctx) 253 | return; 254 | 255 | TRACE (ctx, ASSUAN_LOG_CTX, "assuan_release", ctx); 256 | 257 | _assuan_reset (ctx); 258 | /* None of the members that are our responsibility requires 259 | deallocation. To avoid sensitive data in the line buffers we 260 | wipe them out, though. Note that we can't wipe the entire 261 | context because it also has a pointer to the actual free(). */ 262 | wipememory (&ctx->inbound, sizeof ctx->inbound); 263 | wipememory (&ctx->outbound, sizeof ctx->outbound); 264 | _assuan_free (ctx, ctx); 265 | } 266 | 267 | 268 | 269 | /* 270 | Version number stuff. 271 | */ 272 | 273 | static const char* 274 | parse_version_number (const char *s, int *number) 275 | { 276 | int val = 0; 277 | 278 | if (*s == '0' && digitp (s[1])) 279 | return NULL; /* Leading zeros are not allowed. */ 280 | for (; digitp (*s); s++) 281 | { 282 | val *= 10; 283 | val += *s - '0'; 284 | } 285 | *number = val; 286 | return val < 0 ? NULL : s; 287 | } 288 | 289 | 290 | static const char * 291 | parse_version_string (const char *s, int *major, int *minor, int *micro) 292 | { 293 | s = parse_version_number (s, major); 294 | if (!s || *s != '.') 295 | return NULL; 296 | s++; 297 | s = parse_version_number (s, minor); 298 | if (!s || *s != '.') 299 | return NULL; 300 | s++; 301 | s = parse_version_number (s, micro); 302 | if (!s) 303 | return NULL; 304 | return s; /* Patchlevel. */ 305 | } 306 | 307 | 308 | static const char * 309 | compare_versions (const char *my_version, const char *req_version) 310 | { 311 | int my_major, my_minor, my_micro; 312 | int rq_major, rq_minor, rq_micro; 313 | const char *my_plvl, *rq_plvl; 314 | 315 | if (!req_version) 316 | return my_version; 317 | if (!my_version) 318 | return NULL; 319 | 320 | my_plvl = parse_version_string (my_version, &my_major, &my_minor, &my_micro); 321 | if (!my_plvl) 322 | return NULL; /* Very strange: our own version is bogus. */ 323 | rq_plvl = parse_version_string(req_version, 324 | &rq_major, &rq_minor, &rq_micro); 325 | if (!rq_plvl) 326 | return NULL; /* Requested version string is invalid. */ 327 | 328 | if (my_major > rq_major 329 | || (my_major == rq_major && my_minor > rq_minor) 330 | || (my_major == rq_major && my_minor == rq_minor 331 | && my_micro > rq_micro) 332 | || (my_major == rq_major && my_minor == rq_minor 333 | && my_micro == rq_micro)) 334 | { 335 | return my_version; 336 | } 337 | return NULL; 338 | } 339 | 340 | 341 | /* 342 | * Check that the the version of the library is at minimum REQ_VERSION 343 | * and return the actual version string; return NULL if the condition 344 | * is not met. If NULL is passed to this function, no check is done 345 | * and the version string is simply returned. 346 | */ 347 | const char * 348 | assuan_check_version (const char *req_version) 349 | { 350 | if (req_version && req_version[0] == 1 && req_version[1] == 1) 351 | return _assuan_sysutils_blurb (); 352 | return compare_versions (PACKAGE_VERSION, req_version); 353 | } 354 | --------------------------------------------------------------------------------