Pinentry linking to libassuan? (was: Add inside-Emacs mode to GUI pinentry programs)
Neal H. Walfield
neal at walfield.org
Sat Jun 13 22:02:38 CEST 2015
Hi,
At Fri, 05 Jun 2015 11:31:23 +0200,
Werner Koch wrote:
> given that pinentry gets more and more complicated it does not anymore
> fulfill its original goal to be small enough to be easily audited. One
> of the main problem here has been the major changes to Gtk+ over the
> last decade. And now of Emacs socket code is added as well.
>
> Originally Pinentry should be mostly self-standing but today this is
> only true for the plain curses, tty and Windows versions. Most users
> however build one of the real GUI versions with all their large
> dependencies.
>
> The question is whether we should keep on using our much stripped down
> versions of libassuan and libgpg-error or switch over to use libassuan
> and libgpg-error directly. In fact, both libraries are required by
> GnuPG itself and also be any software using GPGME. Thus we can expect
> that such a change won't introduce any new platform problems.
The attached patch does exactly this. Let me know if you have any
objections to applying it.
:) Neal
From 524818b7d344c470a5072a43e977524554f1a249 Mon Sep 17 00:00:00 2001
From: "Neal H. Walfield" <neal at gnu.org>
Date: Sat, 13 Jun 2015 21:43:33 +0200
Subject: [PATCH] Remove internal mini-libassuan implementation and link to libassuan.
* assuan/ChangeLog-old: Remove file.
* assuan/Makefile.am: Remove file.
* assuan/README.1st: Remove file.
* assuan/assuan-buffer.c: Remove file.
* assuan/assuan-defs.h: Remove file.
* assuan/assuan-handler.c: Remove file.
* assuan/assuan-listen.c: Remove file.
* assuan/assuan-pipe-server.c: Remove file.
* assuan/assuan-util.c: Remove file.
* assuan/assuan.h: Remove file.
* assuan/mkerrors: Remove file.
* configure.ac: Check for libgpg-error and libassuan.
(COMMON_CFLAGS): Add $GPG_ERROR_CFLAGS and $LIBASSUAN_CFLAGS.
(COMMAND_LIBS): Add $GPG_ERROR_LIBS and $LIBASSUAN_LIBS.
(GPG_ERR_ENABLE_GETTEXT_MACROS): Define this macro.
(GPG_ERR_ENABLE_ERRNO_MACROS): Likewise.
(GNUPG_LIBASSUAN_VERSION): Likewise.
(AC_CONFIG_FILES): Don't generate assuan/Makefile.
* Makefile.am (SUBDIRS): Remove assuan.
* curses/Makefile.am (LDADD): Remove ../assuan/libassuan.a.
* gnome3/Makefile.am (AM_CPPFLAGS): Remove -I$(top_srcdir)/assuan.
(LDADD): Remove ../assuan/libassuan.a.
* gtk+-2/Makefile.am (LDADD): Remove ../assuan/libassuan.a.
* pinentry/Makefile.am: Remove -I$(top_srcdir)/assuan.
* qt4/Makefile.am (AM_CPPFLAGS): Remove -I$(top_srcdir)/assuan.
(pinentry_qt4_LDADD): Remove $(top_builddir)/assuan/libassuan.a.
* tty/Makefile.am (LDADD): Remove ../assuan/libassuan.a.
* gnome3/pinentry-gnome3.c: Include <assuan.h>, not "assuan.h".
Replace ASSUAN_General_Error with
gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ASS_GENERAL), etc.
* pinentry/pinentry-curses.c: Likewise.
* pinentry/pinentry.c: Likewise.
(pinentry_assuan_reset_handler): Change return type to gpg_error_t.
Change type of argument CTX from ASSUAN_CONTEXT to assuan_context_t.
Return 0.
(pinentry_inq_quality): Change variable CTX's type from ASSUAN_CONTEXT
to assuan_context_t.
(assuan_malloc_hooks): New variable.
(pinentry_init): Call gpgrt_check_version. Change use of
assuan_set_malloc_hooks to match libassuan's semantics.
(option_handler): Return a gpg_error_t, not an int. Replace use of
ASSUAN_Out_Of_Core with gpg_err_make (GPG_ERR_SOURCE_PINENTRY,
GPG_ERR_ENOMEM), etc.
(cmd_setdesc): Return a gpg_error_t, not an int. Change argument
CTX's type from ASSUAN_CONTEXT to assuan_context_t. Replace use of
ASSUAN_Out_Of_Core with gpg_err_make (GPG_ERR_SOURCE_PINENTRY,
GPG_ERR_ENOMEM), etc.
(cmd_setprompt): Likewise.
(cmd_setkeyinfo): Likewise.
(cmd_setrepeat): Likewise.
(cmd_setrepeaterror): Likewise.
(cmd_seterror): Likewise.
(cmd_setok): Likewise.
(cmd_setnotok): Likewise.
(cmd_setcancel): Likewise.
(cmd_settimeout): Likewise.
(cmd_settitle): Likewise.
(cmd_setqualitybar): Likewise.
(cmd_setqualitybar_tt): Likewise.
(cmd_getpin): Likewise.
(cmd_confirm): Likewise.
(cmd_message): Likewise.
(cmd_getinfo): Likewise.
(cmd_clear_passphrase): Likewise.
(register_commands): Likewise. Change use of assuan_register_command
to match libassuan's semantics.
(pinentry_loop2): Change variable RC's type from int to gpg_error_t.
Change variable CTX's type from ASSUAN_CONTEXT to assuan_context_t.
Use assuan_new to initialize CTX. Change use of
assuan_init_pipe_server to match libassuan's semantics. Replace use
of assuan_strerror with gpg_strerror. Call assuan_release instead of
assuan_deinit_server.
Conflicts:
Makefile.am
gnome3/Makefile.am
gtk+-2/Makefile.am
qt4/Makefile.am
---
Makefile.am | 2 +-
assuan/ChangeLog-old | 254 -----------------
assuan/Makefile.am | 43 ---
assuan/README.1st | 1 -
assuan/assuan-buffer.c | 474 -------------------------------
assuan/assuan-defs.h | 139 ---------
assuan/assuan-handler.c | 672 --------------------------------------------
assuan/assuan-listen.c | 132 ---------
assuan/assuan-pipe-server.c | 127 ---------
assuan/assuan-util.c | 196 -------------
assuan/assuan.h | 202 -------------
assuan/mkerrors | 71 -----
configure.ac | 77 ++++-
curses/Makefile.am | 3 +-
gnome3/Makefile.am | 5 +-
gnome3/pinentry-gnome3.c | 8 +-
gtk+-2/Makefile.am | 2 +-
pinentry/Makefile.am | 2 +-
pinentry/pinentry-curses.c | 27 +-
pinentry/pinentry.c | 234 ++++++++-------
qt4/Makefile.am | 5 +-
tty/Makefile.am | 3 +-
22 files changed, 231 insertions(+), 2448 deletions(-)
delete mode 100644 assuan/ChangeLog-old
delete mode 100644 assuan/Makefile.am
delete mode 100644 assuan/README.1st
delete mode 100644 assuan/assuan-buffer.c
delete mode 100644 assuan/assuan-defs.h
delete mode 100644 assuan/assuan-handler.c
delete mode 100644 assuan/assuan-listen.c
delete mode 100644 assuan/assuan-pipe-server.c
delete mode 100644 assuan/assuan-util.c
delete mode 100644 assuan/assuan.h
delete mode 100755 assuan/mkerrors
diff --git a/Makefile.am b/Makefile.am
index 177f37e..71f8541 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -64,7 +64,7 @@ else
pinentry_w32 =
endif
-SUBDIRS = assuan secmem pinentry ${pinentry_curses} ${pinentry_tty} \
+SUBDIRS = secmem pinentry ${pinentry_curses} ${pinentry_tty} \
${pinentry_gtk_2} ${pinentry_gnome_3} ${pinentry_qt4} \
${pinentry_w32} doc
diff --git a/assuan/ChangeLog-old b/assuan/ChangeLog-old
deleted file mode 100644
index 077831d..0000000
--- a/assuan/ChangeLog-old
+++ /dev/null
@@ -1,254 +0,0 @@
-2012-08-08 Werner Koch <wk at gnupg.org>
-
- NB: ChangeLog files are no longer manually maintained. Starting
- on August 8, 2012 we put change information only in the GIT commit
- log, and generate a top-level ChangeLog file from logs at "make
- dist". See doc/HACKING for details.
-
-2008-02-14 Werner Koch <wk at g10code.com>
-
- * assuan.h (ASSUAN_Parameter_Error): Add new alias.
-
-2008-01-10 Marcus Brinkmann <marcus at g10code.de>
-
- * assuan-handler.c (dispatch_command): Use Syntax_Error instead of
- Invalid_Command.
- * assuan.h (assuan_error_t): Change all error codes to gpg-error
- codes.
-
-2004-12-22 Werner Koch <wk at g10code.com>
-
- * assuan.h (assuan_error_t, assuan_context_t): New aliases.
- * assuan-buffer.c (readline): Renamed EOF to ISEOF to avoid
- compiler warnings.
-
-2004-04-20 Werner Koch <wk at gnupg.org>
-
- * mkerrors: Add missing last LF.
-
-2004-01-30 Werner Koch <wk at gnupg.org>
-
- * assuan-inquire.c, assuan-connect.c, assuan-client.c
- * assuan-socket-server.c, assuan-pipe-connect.c
- * assuan-socket-connect.c: Removed.
- * assuan-handler.c (assuan_get_data_fp): Removed.
-
-2003-12-23 Werner Koch <wk at gnupg.org>
-
- * Makefile.am (EXTRA_DIST): Added Manifest.
- * Manifest: Added.
-
-2003-12-22 Werner Koch <wk at gnupg.org>
-
- * assuan.h (ASSUAN_Locale_Problem): Added.
-
-2002-04-04 Werner Koch <wk at gnupg.org>
-
- * assuan-buffer.c (my_log_prefix): New. Use it for all i/o debug
- output.
-
-2002-03-06 Werner Koch <wk at gnupg.org>
-
- * assuan-client.c (_assuan_read_from_server): Detect END.
- (assuan_transact): Pass it to the data callback.
-
-2002-02-27 Werner Koch <wk at gnupg.org>
-
- * assuan-client.c (assuan_transact): Add 2 more arguments to
- support status lines. Passing NULL yields the old behaviour.
-
- * assuan-handler.c (process_request): Flush data lines send
- without using the data fp.
-
-2002-02-14 Werner Koch <wk at gnupg.org>
-
- * assuan-inquire.c (assuan_inquire): Check for a cancel command
- and return ASSUAN_Canceled. Allow for non-data inquiry.
-
- * assuan.h: Add a few token specific error codes.
-
-2002-02-13 Werner Koch <wk at gnupg.org>
-
- * assuan-defs.h (assuan_context_s): New var CLIENT_PID.
- * assuan-pipe-server.c (_assuan_new_context): set default value.
- * assuan-socket-server.c (accept_connection): get the actual pid.
-
-2002-02-12 Werner Koch <wk at gnupg.org>
-
- * assuan-buffer.c (writen,readline) [USE_GNU_PT]: Use pth_read/write.
- * assuan-socket-server.c (accept_connection) [USE_GNU_PTH]: Ditto.
-
-2002-02-01 Marcus Brinkmann <marcus at g10code.de>
-
- * Makefile.am (MOSTLYCLEANFILES): New variable.
-
-2002-01-23 Werner Koch <wk at gnupg.org>
-
- * assuan-socket-connect.c (LOGERRORX): and removed typo.
-
-2002-01-22 Marcus Brinkmann <marcus at g10code.de>
-
- * assuan-socket-connect.c (LOGERRORX): Reverse arguments to fputs.
-
-2002-01-21 Werner Koch <wk at gnupg.org>
-
- * assuan-connect.c: Move all except assuan_get_pid to...
- * assuan-pipe-connect.c: this.
- (assuan_pipe_disconnect): Removed.
- (do_finish, do_deinit): New
- (assuan_pipe_connect): and set them into the context.
- * assuan-socket-connect.c: New.
-
- * assuan-util.c (_assuan_log_sanitized_string): New.
-
- * assuan-pipe-server.c (assuan_init_pipe_server): Factored most
- code out to ...
- (_assuan_new_context): new func.
- (_assuan_release_context): New
- * assuan-connect.c (assuan_pipe_connect): Use the new functions.
-
-2002-01-20 Werner Koch <wk at gnupg.org>
-
- * assuan.h: Added Invalid Option error code.
-
- * assuan-handler.c (std_handler_option): New.
- (std_cmd_tbl): Add OPTION as standard command.
- (assuan_register_option_handler): New.
- (dispatch_command): Use case insensitive matching as a fallback.
- (my_strcasecmp): New.
-
-2002-01-19 Werner Koch <wk at gnupg.org>
-
- * assuan-buffer.c (_assuan_read_line): Add output logging.
- (assuan_write_line): Ditto.
- (_assuan_cookie_write_data): Ditto.
- (_assuan_cookie_write_flush): Ditto.
- * assuan-util.c (_assuan_log_print_buffer): New.
- (assuan_set_log_stream): New.
- (assuan_begin_confidential): New.
- (assuan_end_confidential): New.
-
- * assuan-defs.h: Add a few handler variables.
- * assuan-pipe-server.c (assuan_deinit_pipe_server): Removed.
- (deinit_pipe_server): New.
- (assuan_deinit_server): New. Changed all callers to use this.
- * assuan-listen.c (assuan_accept): Use the accept handler.
- * assuan-handler.c (process_request): Use the close Handler.
- * assuan-socket-server.c: New.
-
-2002-01-14 Werner Koch <wk at gnupg.org>
-
- * assuan-client.c (_assuan_read_from_server): Skip spaces after
- the keyword.
-
-2002-01-03 Werner Koch <wk at gnupg.org>
-
- * assuan-handler.c (assuan_set_okay_line): New.
- (process_request): And use it here.
-
-2002-01-02 Werner Koch <wk at gnupg.org>
-
- * assuan-inquire.c (init_membuf,put_membuf,get_membuf): Apply a
- hidden 0 behind the buffer so that the buffer can be used as a
- string in certain contexts.
-
-2001-12-14 Marcus Brinkmann <marcus at g10code.de>
-
- * assuan-connect.c (assuan_pipe_connect): New argument
- FD_CHILD_LIST. Don't close those fds.
- * assuan.h: Likewise for prototype.
-
-2001-12-14 Werner Koch <wk at gnupg.org>
-
- * assuan-listen.c (assuan_close_input_fd): New.
- (assuan_close_output_fd): New.
- * assuan-handler.c (std_handler_reset): Always close them after a
- reset command.
- (std_handler_bye): Likewise.
-
-2001-12-14 Marcus Brinkmann <marcus at g10code.de>
-
- * assuan-buffer.c (_assuan_read_line): New variable ATTICLEN, use
- it to save the length of the attic line.
- Rediddle the code a bit to make it more clear what happens.
-
-2001-12-14 Marcus Brinkmann <marcus at g10code.de>
-
- * assuan-defs.h (LINELENGTH): Define as ASSUAN_LINELENGTH.
- assuan.h: Define ASSUAN_LINELENGTH.
-
-2001-12-13 Marcus Brinkmann <marcus at g10code.de>
-
- * assuan-buffer.c (assuan_read_line): Fix order of execution to
- get correct return values.
-
-2001-12-13 Werner Koch <wk at gnupg.org>
-
- * assuan-handler.c (assuan_get_active_fds): Fixed silly bug,
- pretty obvious that nobody ever tested this function.
-
-2001-12-12 Werner Koch <wk at gnupg.org>
-
- * assuan-connect.c (assuan_pipe_connect): Implemented the inital
- handshake.
- * assuan-client.c (read_from_server): Renamed to
- (_assuan_read_from_server): this and made external.
-
- * assuan-listen.c (assuan_set_hello_line): New.
- (assuan_accept): Use a custom hello line is available.
-
- * assuan-buffer.c (assuan_read_line): New.
- (assuan_pending_line): New.
- (_assuan_write_line): Renamed to ..
- (assuan_write_line): this, made public and changed all callers.
-
-2001-12-04 Werner Koch <wk at gnupg.org>
-
- * assuan-connect.c (assuan_pipe_connect): Add more error reporting.
- * assuan-client.c: New.
-
- * assuan-inquire.c: New.
- * assuan-handler.c (process_request): Check for nested invocations.
-
-2001-11-27 Werner Koch <wk at gnupg.org>
-
- * assuan-handler.c (assuan_register_input_notify): New.
- (assuan_register_output_notify): New.
-
-2001-11-26 Werner Koch <wk at gnupg.org>
-
- * assuan.h: Added more status codes.
-
-2001-11-25 Werner Koch <wk at gnupg.org>
-
- * assuan-handler.c (assuan_register_bye_notify)
- (assuan_register_reset_notify)
- (assuan_register_cancel_notify): New and call them from the
- standard handlers.
- (assuan_process): Moved bulk of function to ..
- (process_request): .. new.
- (assuan_process_next): One shot version of above.
- (assuan_get_active_fds): New.
-
-2001-11-24 Werner Koch <wk at gnupg.org>
-
- * assuan-connect.c (assuan_get_pid): New.
-
- * assuan-buffer.c (_assuan_read_line): Deal with reads of more
- than a line.
- * assuan-defs.h: Add space in the context for this.
-
-
- ************************************************************
- * Please note that this is a stripped down Assuan version. *
- ************************************************************
-
- Copyright 2001, 2002, 2004 Free Software Foundation, Inc.
-
- This file is free software; as a special exception the author gives
- unlimited permission to copy and/or distribute it, with or without
- modifications, as long as this notice is preserved.
-
- This file is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
- implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/assuan/Makefile.am b/assuan/Makefile.am
deleted file mode 100644
index 2553f3e..0000000
--- a/assuan/Makefile.am
+++ /dev/null
@@ -1,43 +0,0 @@
-# Assuan Makefile for test purposes
-# Copyright (C) 2001 Free Software Foundation, Inc.
-#
-# This file is part of GnuPG.
-#
-# GnuPG is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# GnuPG is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
-
-## Process this file with automake to produce Makefile.in
-
-EXTRA_DIST = mkerrors ChangeLog-old
-AM_CPPFLAGS = -I.. -I$(top_srcdir)/include
-BUILT_SOURCES = assuan-errors.c
-MOSTLYCLEANFILES = assuan-errors.c
-
-noinst_LIBRARIES = libassuan.a
-
-
-#libassuan_a_LDFLAGS =
-libassuan_a_SOURCES = \
- assuan.h \
- assuan-defs.h \
- assuan-util.c \
- assuan-errors.c \
- assuan-buffer.c \
- assuan-handler.c \
- assuan-listen.c \
- assuan-pipe-server.c
-
-
-assuan-errors.c : assuan.h
- $(srcdir)/mkerrors < $(srcdir)/assuan.h > assuan-errors.c
diff --git a/assuan/README.1st b/assuan/README.1st
deleted file mode 100644
index bb52959..0000000
--- a/assuan/README.1st
+++ /dev/null
@@ -1 +0,0 @@
-Please don't modify it here but in the copy which comes with GnuPG.
\ No newline at end of file
diff --git a/assuan/assuan-buffer.c b/assuan/assuan-buffer.c
deleted file mode 100644
index 363d6cf..0000000
--- a/assuan/assuan-buffer.c
+++ /dev/null
@@ -1,474 +0,0 @@
-/* assuan-buffer.c - read and send data
- * Copyright (C) 2001 Free Software Foundation, Inc.
- *
- * This file is part of GnuPG.
- *
- * GnuPG is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * GnuPG is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-#include <config.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#ifndef HAVE_W32CE_SYSTEM
-# include <errno.h>
-#endif
-#include <unistd.h>
-#include <assert.h>
-#ifdef USE_GNU_PTH
-# include <pth.h>
-#endif
-#ifdef HAVE_W32CE_SYSTEM
-# include <windows.h>
-#endif
-
-#include "assuan-defs.h"
-
-#ifdef HAVE_JNLIB_LOGGING
-#include "../jnlib/logging.h"
-#endif
-
-#ifdef HAVE_W32CE_SYSTEM
-const char *
-strerror (int e)
-{
- return "error";
-}
-static int errno;
-#endif
-
-
-static const char *
-my_log_prefix (void)
-{
-#ifdef HAVE_JNLIB_LOGGING
- return log_get_prefix (NULL);
-#else
- return "";
-#endif
-}
-
-
-static int
-writen ( int fd, const char *buffer, size_t length )
-{
- while (length)
- {
- int nwritten;
-#ifdef HAVE_W32CE_SYSTEM
- do
- {
- if (!WriteFile ((HANDLE)fd, buffer, length, &nwritten, NULL))
- nwritten = -1;
- }
- while (nwritten == -1 && GetLastError () == ERROR_PIPE_NOT_CONNECTED);
-#elif defined(USE_GNU_PTH)
- nwritten = pth_write (fd, buffer, length);
-#else
- nwritten = write (fd, buffer, length);
-#endif
- if (nwritten < 0)
- {
-#ifndef HAVE_W32CE_SYSTEM
- if (errno == EINTR)
- continue;
-#endif
- return -1; /* write error */
- }
- length -= nwritten;
- buffer += nwritten;
- }
- return 0; /* okay */
-}
-
-/* read an entire line */
-static int
-readline (int fd, char *buf, size_t buflen, int *r_nread, int *iseof)
-{
- size_t nleft = buflen; char *p;
-
- *iseof = 0;
- *r_nread = 0;
- while (nleft > 0)
- {
- int n;
-#ifdef HAVE_W32CE_SYSTEM
- do
- {
- if (!ReadFile ((HANDLE)fd, buf, nleft, &n, NULL))
- n = -1;
- }
- while (n == -1 && GetLastError () == ERROR_PIPE_NOT_CONNECTED);
-#elif defined(USE_GNU_PTH)
- n = pth_read (fd, buf, nleft);
-#else
- n = read (fd, buf, nleft);
-#endif
- if (n < 0)
- {
-#ifndef HAVE_W32CE_SYSTEM
- if (errno == EINTR)
- continue;
-#endif
- return -1; /* read error */
- }
- else if (!n)
- {
- *iseof = 1;
- break; /* allow incomplete lines */
- }
- p = buf;
- nleft -= n;
- buf += n;
- *r_nread += n;
-
- for (; n && *p != '\n'; n--, p++)
- ;
- if (n)
- break; /* at least one full line available - that's enough for now */
- }
-
- return 0;
-}
-
-
-int
-_assuan_read_line (ASSUAN_CONTEXT ctx)
-{
- char *line = ctx->inbound.line;
- int n, nread, atticlen;
- int rc;
-
- if (ctx->inbound.eof)
- return -1;
-
- atticlen = ctx->inbound.attic.linelen;
- if (atticlen)
- {
- memcpy (line, ctx->inbound.attic.line, atticlen);
- ctx->inbound.attic.linelen = 0;
- for (n=0; n < atticlen && line[n] != '\n'; n++)
- ;
- if (n < atticlen)
- {
- rc = 0; /* found another line in the attic */
- nread = atticlen;
- atticlen = 0;
- }
- else
- { /* read the rest */
- assert (atticlen < LINELENGTH);
- rc = readline (ctx->inbound.fd, line + atticlen,
- LINELENGTH - atticlen, &nread, &ctx->inbound.eof);
- }
- }
- else
- rc = readline (ctx->inbound.fd, line, LINELENGTH,
- &nread, &ctx->inbound.eof);
- if (rc)
- {
- if (ctx->log_fp)
- fprintf (ctx->log_fp, "%s[%p] <- [Error: %s]\n",
- my_log_prefix (), ctx, strerror (errno));
- return ASSUAN_Read_Error;
- }
- if (!nread)
- {
- assert (ctx->inbound.eof);
- if (ctx->log_fp)
- fprintf (ctx->log_fp, "%s[%p] <- [EOF]\n", my_log_prefix (),ctx);
- return -1;
- }
-
- ctx->inbound.attic.pending = 0;
- nread += atticlen;
- for (n=0; n < nread; n++)
- {
- if (line[n] == '\n')
- {
- if (n+1 < nread)
- {
- char *s, *d;
- int i;
-
- n++;
- /* we have to copy the rest because the handlers are
- allowed to modify the passed buffer */
- for (d=ctx->inbound.attic.line, s=line+n, i=nread-n; i; i--)
- {
- if (*s=='\n')
- ctx->inbound.attic.pending = 1;
- *d++ = *s++;
- }
- ctx->inbound.attic.linelen = nread-n;
- n--;
- }
- if (n && line[n-1] == '\r')
- n--;
- line[n] = 0;
- ctx->inbound.linelen = n;
- if (ctx->log_fp)
- {
- fprintf (ctx->log_fp, "%s[%p] <- ", my_log_prefix (), ctx);
- if (ctx->confidential)
- fputs ("[Confidential data not shown]", ctx->log_fp);
- else
- _assuan_log_print_buffer (ctx->log_fp,
- ctx->inbound.line,
- ctx->inbound.linelen);
- putc ('\n', ctx->log_fp);
- }
- return 0;
- }
- }
-
- if (ctx->log_fp)
- fprintf (ctx->log_fp, "%s[%p] <- [Invalid line]\n", my_log_prefix (), ctx);
- *line = 0;
- ctx->inbound.linelen = 0;
- return ctx->inbound.eof? ASSUAN_Line_Not_Terminated : ASSUAN_Line_Too_Long;
-}
-
-
-/* Read the next line from the client or server and return a pointer
- to a buffer with holding that line. linelen returns the length of
- the line. This buffer is valid until another read operation is
- done on this buffer. The caller is allowed to modify this buffer.
- He should only use the buffer if the function returns without an
- error.
-
- Returns: 0 on success or an assuan error code
- See also: assuan_pending_line().
-*/
-AssuanError
-assuan_read_line (ASSUAN_CONTEXT ctx, char **line, size_t *linelen)
-{
- AssuanError err;
-
- if (!ctx)
- return ASSUAN_Invalid_Value;
-
- err = _assuan_read_line (ctx);
- *line = ctx->inbound.line;
- *linelen = ctx->inbound.linelen;
- return err;
-}
-
-
-/* Return true when a full line is pending for a read, without the need
- for actual IO */
-int
-assuan_pending_line (ASSUAN_CONTEXT ctx)
-{
- return ctx && ctx->inbound.attic.pending;
-}
-
-
-AssuanError
-assuan_write_line (ASSUAN_CONTEXT ctx, const char *line )
-{
- int rc;
-
- if (!ctx)
- return ASSUAN_Invalid_Value;
-
- /* fixme: we should do some kind of line buffering */
- if (ctx->log_fp)
- {
- fprintf (ctx->log_fp, "%s[%p] -> ", my_log_prefix (), ctx);
- if (ctx->confidential)
- fputs ("[Confidential data not shown]", ctx->log_fp);
- else
- _assuan_log_print_buffer (ctx->log_fp,
- line, strlen (line));
- putc ('\n', ctx->log_fp);
- }
-
- rc = writen (ctx->outbound.fd, line, strlen(line));
- if (rc)
- rc = ASSUAN_Write_Error;
- if (!rc)
- {
- rc = writen (ctx->outbound.fd, "\n", 1);
- if (rc)
- rc = ASSUAN_Write_Error;
- }
-
- return rc;
-}
-
-
-
-/* Write out the data in buffer as datalines with line wrapping and
- percent escaping. This fucntion is used for GNU's custom streams */
-int
-_assuan_cookie_write_data (void *cookie, const char *buffer, size_t size)
-{
- ASSUAN_CONTEXT ctx = cookie;
- char *line;
- size_t linelen;
-
- if (ctx->outbound.data.error)
- return 0;
-
- line = ctx->outbound.data.line;
- linelen = ctx->outbound.data.linelen;
- line += linelen;
- while (size)
- {
- /* insert data line header */
- if (!linelen)
- {
- *line++ = 'D';
- *line++ = ' ';
- linelen += 2;
- }
-
- /* copy data, keep some space for the CRLF and to escape one character */
- while (size && linelen < LINELENGTH-2-2)
- {
- if (*buffer == '%' || *buffer == '\r' || *buffer == '\n')
- {
- sprintf (line, "%%%02X", *(unsigned char*)buffer);
- line += 3;
- linelen += 3;
- buffer++;
- }
- else
- {
- *line++ = *buffer++;
- linelen++;
- }
- size--;
- }
-
- if (linelen >= LINELENGTH-2-2)
- {
- if (ctx->log_fp)
- {
- fprintf (ctx->log_fp, "%s[%p] -> ", my_log_prefix (), ctx);
- if (ctx->confidential)
- fputs ("[Confidential data not shown]", ctx->log_fp);
- else
- _assuan_log_print_buffer (ctx->log_fp,
- ctx->outbound.data.line,
- linelen);
- putc ('\n', ctx->log_fp);
- }
- *line++ = '\n';
- linelen++;
- if (writen (ctx->outbound.fd, ctx->outbound.data.line, linelen))
- {
- ctx->outbound.data.error = ASSUAN_Write_Error;
- return 0;
- }
- line = ctx->outbound.data.line;
- linelen = 0;
- }
- }
-
- ctx->outbound.data.linelen = linelen;
- return 0;
-}
-
-
-/* Write out any buffered data
- This fucntion is used for GNU's custom streams */
-int
-_assuan_cookie_write_flush (void *cookie)
-{
- ASSUAN_CONTEXT ctx = cookie;
- char *line;
- size_t linelen;
-
- if (ctx->outbound.data.error)
- return 0;
-
- line = ctx->outbound.data.line;
- linelen = ctx->outbound.data.linelen;
- line += linelen;
- if (linelen)
- {
- if (ctx->log_fp)
- {
- fprintf (ctx->log_fp, "%s[%p] -> ", my_log_prefix (), ctx);
- if (ctx->confidential)
- fputs ("[Confidential data not shown]", ctx->log_fp);
- else
- _assuan_log_print_buffer (ctx->log_fp,
- ctx->outbound.data.line,
- linelen);
- putc ('\n', ctx->log_fp);
- }
- *line++ = '\n';
- linelen++;
- if (writen (ctx->outbound.fd, ctx->outbound.data.line, linelen))
- {
- ctx->outbound.data.error = ASSUAN_Write_Error;
- return 0;
- }
- ctx->outbound.data.linelen = 0;
- }
- return 0;
-}
-
-
-/**
- * assuan_send_data:
- * @ctx: An assuan context
- * @buffer: Data to send or NULL to flush
- * @length: length of the data to send/
- *
- * This function may be used by the server or the client to send data
- * lines. The data will be escaped as required by the Assuan protocol
- * and may get buffered until a line is full. To force sending the
- * data out @buffer may be passed as NULL (in which case @length must
- * also be 0); however when used by a client this flush operation does
- * also send the terminating "END" command to terminate the reponse on
- * a INQUIRE response. However, when assuan_transact() is used, this
- * function takes care of sending END itself.
- *
- * Return value: 0 on success or an error code
- **/
-
-AssuanError
-assuan_send_data (ASSUAN_CONTEXT ctx, const void *buffer, size_t length)
-{
- if (!ctx)
- return ASSUAN_Invalid_Value;
- if (!buffer && length)
- return ASSUAN_Invalid_Value;
-
- if (!buffer)
- { /* flush what we have */
- _assuan_cookie_write_flush (ctx);
- if (ctx->outbound.data.error)
- return ctx->outbound.data.error;
- if (!ctx->is_server)
- return assuan_write_line (ctx, "END");
- }
- else
- {
- _assuan_cookie_write_data (ctx, buffer, length);
- if (ctx->outbound.data.error)
- return ctx->outbound.data.error;
- }
-
- return 0;
-}
-
-
-
-
diff --git a/assuan/assuan-defs.h b/assuan/assuan-defs.h
deleted file mode 100644
index 6c502bf..0000000
--- a/assuan/assuan-defs.h
+++ /dev/null
@@ -1,139 +0,0 @@
-/* assuan-defs.c - Internal definitions to Assuan
- * Copyright (C) 2001 Free Software Foundation, Inc.
- *
- * This file is part of GnuPG.
- *
- * GnuPG is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * GnuPG is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-#ifndef ASSUAN_DEFS_H
-#define ASSUAN_DEFS_H
-
-#include <sys/types.h>
-#include "assuan.h"
-
-#define LINELENGTH ASSUAN_LINELENGTH
-
-struct cmdtbl_s {
- const char *name;
- int cmd_id;
- int (*handler)(ASSUAN_CONTEXT, char *line);
-};
-
-struct assuan_context_s {
- AssuanError err_no;
- const char *err_str;
- int os_errno; /* last system error number used with certain error codes*/
-
- int confidential;
- int is_server; /* set if this is context belongs to a server */
- int in_inquire;
- char *hello_line;
- char *okay_line; /* see assan_set_okay_line() */
-
- void *user_pointer; /* for assuan_[gs]et_pointer () */
-
- FILE *log_fp;
-
- struct {
- int fd;
- int eof;
- char line[LINELENGTH];
- int linelen; /* w/o CR, LF - might not be the same as
- strlen(line) due to embedded nuls. However a nul
- is always written at this pos */
- struct {
- char line[LINELENGTH];
- int linelen ;
- int pending; /* i.e. at least one line is available in the attic */
- } attic;
- } inbound;
-
- struct {
- int fd;
- struct {
- FILE *fp;
- char line[LINELENGTH];
- int linelen;
- int error;
- } data;
- } outbound;
-
- int pipe_mode; /* We are in pipe mode, i.e. we can handle just one
- connection and must terminate then */
- pid_t pid; /* In pipe mode, the pid of the child server process.
- In socket mode, the pid of the server */
- int listen_fd; /* The fd we are listening on (used by socket servers) */
-
- pid_t client_pid; /* for a socket server the PID of the client or -1
- if not available */
-
- void (*deinit_handler)(ASSUAN_CONTEXT);
- int (*accept_handler)(ASSUAN_CONTEXT);
- int (*finish_handler)(ASSUAN_CONTEXT);
-
- struct cmdtbl_s *cmdtbl;
- size_t cmdtbl_used; /* used entries */
- size_t cmdtbl_size; /* allocated size of table */
-
- void (*bye_notify_fnc)(ASSUAN_CONTEXT);
- void (*reset_notify_fnc)(ASSUAN_CONTEXT);
- void (*cancel_notify_fnc)(ASSUAN_CONTEXT);
- int (*option_handler_fnc)(ASSUAN_CONTEXT,const char*, const char*);
- void (*input_notify_fnc)(ASSUAN_CONTEXT, const char *);
- void (*output_notify_fnc)(ASSUAN_CONTEXT, const char *);
-
- int input_fd; /* set by INPUT command */
- int output_fd; /* set by OUTPUT command */
-
-};
-
-
-/*-- assuan-pipe-server.c --*/
-int _assuan_new_context (ASSUAN_CONTEXT *r_ctx);
-void _assuan_release_context (ASSUAN_CONTEXT ctx);
-
-
-/*-- assuan-handler.c --*/
-int _assuan_register_std_commands (ASSUAN_CONTEXT ctx);
-
-/*-- assuan-buffer.c --*/
-int _assuan_read_line (ASSUAN_CONTEXT ctx);
-int _assuan_cookie_write_data (void *cookie, const char *buffer, size_t size);
-int _assuan_cookie_write_flush (void *cookie);
-
-/*-- assuan-client.c --*/
-AssuanError _assuan_read_from_server (ASSUAN_CONTEXT ctx, int *okay, int *off);
-
-
-/*-- assuan-util.c --*/
-void *_assuan_malloc (size_t n);
-void *_assuan_calloc (size_t n, size_t m);
-void *_assuan_realloc (void *p, size_t n);
-void _assuan_free (void *p);
-
-#define xtrymalloc(a) _assuan_malloc ((a))
-#define xtrycalloc(a,b) _assuan_calloc ((a),(b))
-#define xtryrealloc(a,b) _assuan_realloc((a),(b))
-#define xfree(a) _assuan_free ((a))
-
-#define set_error(c,e,t) assuan_set_error ((c), ASSUAN_ ## e, (t))
-
-void _assuan_log_print_buffer (FILE *fp, const void *buffer, size_t length);
-void _assuan_log_sanitized_string (const char *string);
-
-
-#endif /*ASSUAN_DEFS_H*/
-
diff --git a/assuan/assuan-handler.c b/assuan/assuan-handler.c
deleted file mode 100644
index aadad21..0000000
--- a/assuan/assuan-handler.c
+++ /dev/null
@@ -1,672 +0,0 @@
-/* assuan-handler.c - dispatch commands
- * Copyright (C) 2001 Free Software Foundation, Inc.
- *
- * This file is part of GnuPG.
- *
- * GnuPG is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * GnuPG is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-#include <config.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "assuan-defs.h"
-
-#define spacep(p) (*(p) == ' ' || *(p) == '\t')
-#define digitp(a) ((a) >= '0' && (a) <= '9')
-
-
-static int
-dummy_handler (ASSUAN_CONTEXT ctx, char *line)
-{
- (void)line;
- return set_error (ctx, Server_Fault, "no handler registered");
-}
-
-
-static int
-std_handler_nop (ASSUAN_CONTEXT ctx, char *line)
-{
- (void)ctx;
- (void)line;
- return 0; /* okay */
-}
-
-static int
-std_handler_cancel (ASSUAN_CONTEXT ctx, char *line)
-{
- (void)line;
- if (ctx->cancel_notify_fnc)
- ctx->cancel_notify_fnc (ctx);
- return set_error (ctx, Not_Implemented, NULL);
-}
-
-static int
-std_handler_option (ASSUAN_CONTEXT ctx, char *line)
-{
- char *key, *value, *p;
-
- for (key=line; spacep (key); key++)
- ;
- if (!*key)
- return set_error (ctx, Syntax_Error, "argument required");
- if (*key == '=')
- return set_error (ctx, Syntax_Error, "no option name given");
- for (value=key; *value && !spacep (value) && *value != '='; value++)
- ;
- if (*value)
- {
- if (spacep (value))
- *value++ = 0; /* terminate key */
- for (; spacep (value); value++)
- ;
- if (*value == '=')
- {
- *value++ = 0; /* terminate key */
- for (; spacep (value); value++)
- ;
- if (!*value)
- return set_error (ctx, Syntax_Error, "option argument expected");
- }
- if (*value)
- {
- for (p = value + strlen(value) - 1; p > value && spacep (p); p--)
- ;
- if (p > value)
- *++p = 0; /* strip trailing spaces */
- }
- }
-
- if (*key == '-' && key[1] == '-' && key[2])
- key += 2; /* the double dashes are optional */
- if (*key == '-')
- return set_error (ctx, Syntax_Error,
- "option should not begin with one dash");
-
- if (ctx->option_handler_fnc)
- return ctx->option_handler_fnc (ctx, key, value);
- return 0;
-}
-
-static int
-std_handler_bye (ASSUAN_CONTEXT ctx, char *line)
-{
- (void)line;
- if (ctx->bye_notify_fnc)
- ctx->bye_notify_fnc (ctx);
- assuan_close_input_fd (ctx);
- assuan_close_output_fd (ctx);
- return -1; /* pretty simple :-) */
-}
-
-static int
-std_handler_auth (ASSUAN_CONTEXT ctx, char *line)
-{
- (void)line;
- return set_error (ctx, Not_Implemented, NULL);
-}
-
-static int
-std_handler_reset (ASSUAN_CONTEXT ctx, char *line)
-{
- (void)line;
- if (ctx->reset_notify_fnc)
- ctx->reset_notify_fnc (ctx);
- assuan_close_input_fd (ctx);
- assuan_close_output_fd (ctx);
- return 0;
-}
-
-static int
-std_handler_end (ASSUAN_CONTEXT ctx, char *line)
-{
- (void)line;
- return set_error (ctx, Not_Implemented, NULL);
-}
-
-static int
-parse_cmd_input_output (ASSUAN_CONTEXT ctx, char *line, int *rfd)
-{
- char *endp;
-
- if (strncmp (line, "FD=", 3))
- return set_error (ctx, Syntax_Error, "FD=<n> expected");
- line += 3;
- if (!digitp (*line))
- return set_error (ctx, Syntax_Error, "number required");
- *rfd = strtoul (line, &endp, 10);
- /* remove that argument so that a notify handler won't see it */
- memset (line, ' ', endp? (endp-line):strlen(line));
-
- if (*rfd == ctx->inbound.fd)
- return set_error (ctx, Parameter_Conflict, "fd same as inbound fd");
- if (*rfd == ctx->outbound.fd)
- return set_error (ctx, Parameter_Conflict, "fd same as outbound fd");
- return 0;
-}
-
-/* Format is INPUT FD=<n> */
-static int
-std_handler_input (ASSUAN_CONTEXT ctx, char *line)
-{
- int rc, fd;
-
- rc = parse_cmd_input_output (ctx, line, &fd);
- if (rc)
- return rc;
- ctx->input_fd = fd;
- if (ctx->input_notify_fnc)
- ctx->input_notify_fnc (ctx, line);
- return 0;
-}
-
-/* Format is OUTPUT FD=<n> */
-static int
-std_handler_output (ASSUAN_CONTEXT ctx, char *line)
-{
- int rc, fd;
-
- rc = parse_cmd_input_output (ctx, line, &fd);
- if (rc)
- return rc;
- ctx->output_fd = fd;
- if (ctx->output_notify_fnc)
- ctx->output_notify_fnc (ctx, line);
- return 0;
-}
-
-
-
-
-
-/* This is a table with the standard commands and handler for them.
- The table is used to initialize a new context and assuciate strings
- and handlers with cmd_ids */
-static struct {
- const char *name;
- int cmd_id;
- int (*handler)(ASSUAN_CONTEXT, char *line);
- int always; /* always initialize this command */
-} std_cmd_table[] = {
- { "NOP", ASSUAN_CMD_NOP, std_handler_nop, 1 },
- { "CANCEL", ASSUAN_CMD_CANCEL, std_handler_cancel, 1 },
- { "OPTION", ASSUAN_CMD_OPTION, std_handler_option, 1 },
- { "BYE", ASSUAN_CMD_BYE, std_handler_bye, 1 },
- { "AUTH", ASSUAN_CMD_AUTH, std_handler_auth, 1 },
- { "RESET", ASSUAN_CMD_RESET, std_handler_reset, 1 },
- { "END", ASSUAN_CMD_END, std_handler_end, 1 },
-
- { "INPUT", ASSUAN_CMD_INPUT, std_handler_input },
- { "OUTPUT", ASSUAN_CMD_OUTPUT, std_handler_output },
- { "OPTION", ASSUAN_CMD_OPTION, std_handler_option, 1 },
- { NULL }
-};
-
-
-/**
- * assuan_register_command:
- * @ctx: the server context
- * @cmd_id: An ID value for the command
- * @cmd_name: A string with the command name
- * @handler: The handler function to be called
- *
- * Register a handler to be used for a given command.
- *
- * The @cmd_name must be %NULL or an empty string for all @cmd_ids
- * below %ASSUAN_CMD_USER because predefined values are used.
- *
- * Return value:
- **/
-int
-assuan_register_command (ASSUAN_CONTEXT ctx,
- int cmd_id, const char *cmd_name,
- int (*handler)(ASSUAN_CONTEXT, char *))
-{
- int i;
-
- if (cmd_name && !*cmd_name)
- cmd_name = NULL;
-
- if (cmd_id < ASSUAN_CMD_USER)
- {
- if (cmd_name)
- return ASSUAN_Invalid_Value; /* must be NULL for these values*/
-
- for (i=0; std_cmd_table[i].name; i++)
- {
- if (std_cmd_table[i].cmd_id == cmd_id)
- {
- cmd_name = std_cmd_table[i].name;
- if (!handler)
- handler = std_cmd_table[i].handler;
- break;
- }
- }
- if (!std_cmd_table[i].name)
- return ASSUAN_Invalid_Value; /* not a pre-registered one */
- }
-
- if (!handler)
- handler = dummy_handler;
-
- if (!cmd_name)
- return ASSUAN_Invalid_Value;
-
-/* fprintf (stderr, "DBG-assuan: registering %d as `%s'\n", cmd_id, cmd_name); */
-
- if (!ctx->cmdtbl)
- {
- ctx->cmdtbl_size = 50;
- ctx->cmdtbl = xtrycalloc ( ctx->cmdtbl_size, sizeof *ctx->cmdtbl);
- if (!ctx->cmdtbl)
- return ASSUAN_Out_Of_Core;
- ctx->cmdtbl_used = 0;
- }
- else if (ctx->cmdtbl_used >= ctx->cmdtbl_size)
- {
- struct cmdtbl_s *x;
-
- x = xtryrealloc ( ctx->cmdtbl, (ctx->cmdtbl_size+10) * sizeof *x);
- if (!x)
- return ASSUAN_Out_Of_Core;
- ctx->cmdtbl = x;
- ctx->cmdtbl_size += 50;
- }
-
- ctx->cmdtbl[ctx->cmdtbl_used].name = cmd_name;
- ctx->cmdtbl[ctx->cmdtbl_used].cmd_id = cmd_id;
- ctx->cmdtbl[ctx->cmdtbl_used].handler = handler;
- ctx->cmdtbl_used++;
- return 0;
-}
-
-int
-assuan_register_bye_notify (ASSUAN_CONTEXT ctx, void (*fnc)(ASSUAN_CONTEXT))
-{
- if (!ctx)
- return ASSUAN_Invalid_Value;
- ctx->bye_notify_fnc = fnc;
- return 0;
-}
-
-int
-assuan_register_reset_notify (ASSUAN_CONTEXT ctx, void (*fnc)(ASSUAN_CONTEXT))
-{
- if (!ctx)
- return ASSUAN_Invalid_Value;
- ctx->reset_notify_fnc = fnc;
- return 0;
-}
-
-int
-assuan_register_cancel_notify (ASSUAN_CONTEXT ctx, void (*fnc)(ASSUAN_CONTEXT))
-{
- if (!ctx)
- return ASSUAN_Invalid_Value;
- ctx->cancel_notify_fnc = fnc;
- return 0;
-}
-
-int
-assuan_register_option_handler (ASSUAN_CONTEXT ctx,
- int (*fnc)(ASSUAN_CONTEXT,
- const char*, const char*))
-{
- if (!ctx)
- return ASSUAN_Invalid_Value;
- ctx->option_handler_fnc = fnc;
- return 0;
-}
-
-int
-assuan_register_input_notify (ASSUAN_CONTEXT ctx,
- void (*fnc)(ASSUAN_CONTEXT, const char *))
-{
- if (!ctx)
- return ASSUAN_Invalid_Value;
- ctx->input_notify_fnc = fnc;
- return 0;
-}
-
-int
-assuan_register_output_notify (ASSUAN_CONTEXT ctx,
- void (*fnc)(ASSUAN_CONTEXT, const char *))
-{
- if (!ctx)
- return ASSUAN_Invalid_Value;
- ctx->output_notify_fnc = fnc;
- return 0;
-}
-
-
-/* Helper to register the standards commands */
-int
-_assuan_register_std_commands (ASSUAN_CONTEXT ctx)
-{
- int i, rc;
-
- for (i=0; std_cmd_table[i].name; i++)
- {
- if (std_cmd_table[i].always)
- {
- rc = assuan_register_command (ctx, std_cmd_table[i].cmd_id,
- NULL, NULL);
- if (rc)
- return rc;
- }
- }
- return 0;
-}
-
-
-
-/* Process the special data lines. The "D " has already been removed
- from the line. As all handlers this function may modify the line. */
-static int
-handle_data_line (ASSUAN_CONTEXT ctx, char *line, int linelen)
-{
- (void)line;
- (void)linelen;
- return set_error (ctx, Not_Implemented, NULL);
-}
-
-/* like ascii_strcasecmp but assume that B is already uppercase */
-static int
-my_strcasecmp (const char *a, const char *b)
-{
- if (a == b)
- return 0;
-
- for (; *a && *b; a++, b++)
- {
- if (((*a >= 'a' && *a <= 'z')? (*a&~0x20):*a) != *b)
- break;
- }
- return *a == *b? 0 : (((*a >= 'a' && *a <= 'z')? (*a&~0x20):*a) - *b);
-}
-
-/* Parse the line, break out the command, find it in the command
- table, remove leading and white spaces from the arguments, all the
- handler with the argument line and return the error */
-static int
-dispatch_command (ASSUAN_CONTEXT ctx, char *line, int linelen)
-{
- char *p;
- const char *s;
- int shift, i;
-
- if (*line == 'D' && line[1] == ' ') /* divert to special handler */
- return handle_data_line (ctx, line+2, linelen-2);
-
- for (p=line; *p && *p != ' ' && *p != '\t'; p++)
- ;
- if (p==line)
- return set_error (ctx, Syntax_Error, "leading white-space");
- if (*p)
- { /* Skip over leading WS after the keyword */
- *p++ = 0;
- while ( *p == ' ' || *p == '\t')
- p++;
- }
- shift = p - line;
-
- for (i=0; (s=ctx->cmdtbl[i].name); i++)
- {
- if (!strcmp (line, s))
- break;
- }
- if (!s)
- { /* and try case insensitive */
- for (i=0; (s=ctx->cmdtbl[i].name); i++)
- {
- if (!my_strcasecmp (line, s))
- break;
- }
- }
- if (!s)
- return set_error (ctx, Unknown_Command, NULL);
- line += shift;
- linelen -= shift;
-
-/* fprintf (stderr, "DBG-assuan: processing %s `%s'\n", s, line); */
- return ctx->cmdtbl[i].handler (ctx, line);
-}
-
-
-
-
-static int
-process_request (ASSUAN_CONTEXT ctx)
-{
- int rc;
-
- if (ctx->in_inquire)
- return ASSUAN_Nested_Commands;
-
- rc = _assuan_read_line (ctx);
- if (rc)
- return rc;
- if (*ctx->inbound.line == '#' || !ctx->inbound.linelen)
- return 0; /* comment line - ignore */
-
- ctx->outbound.data.error = 0;
- ctx->outbound.data.linelen = 0;
- /* dispatch command and return reply */
- rc = dispatch_command (ctx, ctx->inbound.line, ctx->inbound.linelen);
- /* check from data write errors */
- if (ctx->outbound.data.fp)
- { /* Flush the data lines */
- fclose (ctx->outbound.data.fp);
- ctx->outbound.data.fp = NULL;
- if (!rc && ctx->outbound.data.error)
- rc = ctx->outbound.data.error;
- }
- else /* flush any data send w/o using the data fp */
- {
- assuan_send_data (ctx, NULL, 0);
- if (!rc && ctx->outbound.data.error)
- rc = ctx->outbound.data.error;
- }
- /* Error handling */
- if (!rc)
- {
- rc = assuan_write_line (ctx, ctx->okay_line? ctx->okay_line : "OK");
- }
- else if (rc == -1)
- { /* No error checking because the peer may have already disconnect */
- assuan_write_line (ctx, "OK closing connection");
- ctx->finish_handler (ctx);
- }
- else
- {
- char errline[256];
-
- if (rc < 100)
- sprintf (errline, "ERR %d server fault (%.50s)",
- ASSUAN_Server_Fault, assuan_strerror (rc));
- else
- {
- const char *text = ctx->err_no == rc? ctx->err_str:NULL;
-
- sprintf (errline, "ERR %d %.50s%s%.100s",
- rc, assuan_strerror (rc), text? " - ":"", text?text:"");
- }
- rc = assuan_write_line (ctx, errline);
- }
-
- ctx->confidential = 0;
- if (ctx->okay_line)
- {
- xfree (ctx->okay_line);
- ctx->okay_line = NULL;
- }
- return rc;
-}
-
-/**
- * assuan_process:
- * @ctx: assuan context
- *
- * This fucntion is used to handle the assuan protocol after a
- * connection has been established using assuan_accept(). This is the
- * main protocol handler.
- *
- * Return value: 0 on success or an error code if the assuan operation
- * failed. Note, that no error is returned for operational errors.
- **/
-int
-assuan_process (ASSUAN_CONTEXT ctx)
-{
- int rc;
-
- do {
- rc = process_request (ctx);
- } while (!rc);
-
- if (rc == -1)
- rc = 0;
-
- return rc;
-}
-
-
-/**
- * assuan_process_next:
- * @ctx: Assuan context
- *
- * Same as assuan_process() but the user has to provide the outer
- * loop. He should loop as long as the return code is zero and stop
- * otherwise; -1 is regular end.
- *
- * See also: assuan_get_active_fds()
- * Return value: -1 for end of server, 0 on success or an error code
- **/
-int
-assuan_process_next (ASSUAN_CONTEXT ctx)
-{
- return process_request (ctx);
-}
-
-
-/**
- * assuan_get_active_fds:
- * @ctx: Assuan context
- * @what: 0 for read fds, 1 for write fds
- * @fdarray: Caller supplied array to store the FDs
- * @fdarraysize: size of that array
- *
- * Return all active filedescriptors for the given context. This
- * function can be used to select on the fds and call
- * assuan_process_next() if there is an active one. The first fd in
- * the array is the one used for the command connection.
- *
- * Note, that write FDs are not yet supported.
- *
- * Return value: number of FDs active and put into @fdarray or -1 on
- * error which is most likely a too small fdarray.
- **/
-int
-assuan_get_active_fds (ASSUAN_CONTEXT ctx, int what,
- int *fdarray, int fdarraysize)
-{
- int n = 0;
-
- if (!ctx || fdarraysize < 2 || what < 0 || what > 1)
- return -1;
-
- if (!what)
- {
- if (ctx->inbound.fd != -1)
- fdarray[n++] = ctx->inbound.fd;
- }
- else
- {
- if (ctx->outbound.fd != -1)
- fdarray[n++] = ctx->outbound.fd;
- if (ctx->outbound.data.fp)
- fdarray[n++] = fileno (ctx->outbound.data.fp);
- }
-
- return n;
-}
-
-
-/* Set the text used for the next OK reponse. This string is
- automatically reset to NULL after the next command. */
-AssuanError
-assuan_set_okay_line (ASSUAN_CONTEXT ctx, const char *line)
-{
- if (!ctx)
- return ASSUAN_Invalid_Value;
- if (!line)
- {
- xfree (ctx->okay_line);
- ctx->okay_line = NULL;
- }
- else
- {
- /* FIXME: we need to use gcry_is_secure() to test whether
- we should allocate the entire line in secure memory */
- char *buf = xtrymalloc (3+strlen(line)+1);
- if (!buf)
- return ASSUAN_Out_Of_Core;
- strcpy (buf, "OK ");
- strcpy (buf+3, line);
- xfree (ctx->okay_line);
- ctx->okay_line = buf;
- }
- return 0;
-}
-
-
-
-void
-assuan_write_status (ASSUAN_CONTEXT ctx, const char *keyword, const char *text)
-{
- char buffer[256];
- char *helpbuf;
- size_t n;
-
- if ( !ctx || !keyword)
- return;
- if (!text)
- text = "";
-
- n = 2 + strlen (keyword) + 1 + strlen (text) + 1;
- if (n < sizeof (buffer))
- {
- strcpy (buffer, "S ");
- strcat (buffer, keyword);
- if (*text)
- {
- strcat (buffer, " ");
- strcat (buffer, text);
- }
- assuan_write_line (ctx, buffer);
- }
- else if ( (helpbuf = xtrymalloc (n)) )
- {
- strcpy (helpbuf, "S ");
- strcat (helpbuf, keyword);
- if (*text)
- {
- strcat (helpbuf, " ");
- strcat (helpbuf, text);
- }
- assuan_write_line (ctx, helpbuf);
- xfree (helpbuf);
- }
-}
diff --git a/assuan/assuan-listen.c b/assuan/assuan-listen.c
deleted file mode 100644
index db63ad2..0000000
--- a/assuan/assuan-listen.c
+++ /dev/null
@@ -1,132 +0,0 @@
-/* assuan-listen.c - Wait for a connection (server)
- * Copyright (C) 2001 Free Software Foundation, Inc.
- *
- * This file is part of GnuPG.
- *
- * GnuPG is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * GnuPG is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-#include <config.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "assuan-defs.h"
-
-AssuanError
-assuan_set_hello_line (ASSUAN_CONTEXT ctx, const char *line)
-{
- if (!ctx)
- return ASSUAN_Invalid_Value;
- if (!line)
- {
- xfree (ctx->hello_line);
- ctx->hello_line = NULL;
- }
- else
- {
- char *buf = xtrymalloc (3+strlen(line)+1);
- if (!buf)
- return ASSUAN_Out_Of_Core;
- strcpy (buf, "OK ");
- strcpy (buf+3, line);
- xfree (ctx->hello_line);
- ctx->hello_line = buf;
- }
- return 0;
-}
-
-
-/**
- * assuan_accept:
- * @ctx: context
- *
- * Cancel any existing connectiion and wait for a connection from a
- * client. The initial handshake is performed which may include an
- * initial authentication or encryption negotiation.
- *
- * Return value: 0 on success or an error if the connection could for
- * some reason not be established.
- **/
-AssuanError
-assuan_accept (ASSUAN_CONTEXT ctx)
-{
- int rc;
-
- if (!ctx)
- return ASSUAN_Invalid_Value;
-
- if (ctx->pipe_mode > 1)
- return -1; /* second invocation for pipemode -> terminate */
- ctx->finish_handler (ctx);
-
- rc = ctx->accept_handler (ctx);
- if (rc)
- return rc;
-
- /* send the hello */
- rc = assuan_write_line (ctx, ctx->hello_line? ctx->hello_line
- : "OK Your orders please");
- if (rc)
- return rc;
-
- if (ctx->pipe_mode)
- ctx->pipe_mode = 2;
-
- return 0;
-}
-
-
-
-int
-assuan_get_input_fd (ASSUAN_CONTEXT ctx)
-{
- return ctx? ctx->input_fd : -1;
-}
-
-
-int
-assuan_get_output_fd (ASSUAN_CONTEXT ctx)
-{
- return ctx? ctx->output_fd : -1;
-}
-
-
-/* Close the fd descriptor set by the command INPUT FD=n. We handle
- this fd inside assuan so that we can do some initial checks */
-AssuanError
-assuan_close_input_fd (ASSUAN_CONTEXT ctx)
-{
- if (!ctx || ctx->input_fd == -1)
- return ASSUAN_Invalid_Value;
- close (ctx->input_fd);
- ctx->input_fd = -1;
- return 0;
-}
-
-/* Close the fd descriptor set by the command OUTPUT FD=n. We handle
- this fd inside assuan so that we can do some initial checks */
-AssuanError
-assuan_close_output_fd (ASSUAN_CONTEXT ctx)
-{
- if (!ctx || ctx->output_fd == -1)
- return ASSUAN_Invalid_Value;
-
- close (ctx->output_fd);
- ctx->output_fd = -1;
- return 0;
-}
-
diff --git a/assuan/assuan-pipe-server.c b/assuan/assuan-pipe-server.c
deleted file mode 100644
index c0d464f..0000000
--- a/assuan/assuan-pipe-server.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/* assuan-pipe-server.c - Assuan server working over a pipe
- * Copyright (C) 2001 Free Software Foundation, Inc.
- *
- * This file is part of GnuPG.
- *
- * GnuPG is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * GnuPG is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-#include <config.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "assuan-defs.h"
-
-static void
-deinit_pipe_server (ASSUAN_CONTEXT ctx)
-{
- (void)ctx;
- /* nothing to do for this simple server */
-}
-
-static int
-accept_connection (ASSUAN_CONTEXT ctx)
-{
- (void)ctx;
- /* This is a NOP for a pipe server */
- return 0;
-}
-
-static int
-finish_connection (ASSUAN_CONTEXT ctx)
-{
- (void)ctx;
- /* This is a NOP for a pipe server */
- return 0;
-}
-
-
-/* Create a new context. Note that the handlers are set up for a pipe
- server/client - this way we don't need extra dummy functions */
-int
-_assuan_new_context (ASSUAN_CONTEXT *r_ctx)
-{
- ASSUAN_CONTEXT ctx;
- int rc;
-
- *r_ctx = NULL;
- ctx = xtrycalloc (1, sizeof *ctx);
- if (!ctx)
- return ASSUAN_Out_Of_Core;
- ctx->input_fd = -1;
- ctx->output_fd = -1;
-
- ctx->inbound.fd = -1;
- ctx->outbound.fd = -1;
-
- ctx->listen_fd = -1;
- ctx->client_pid = (pid_t)-1;
- /* use the pipe server handler as a default */
- ctx->deinit_handler = deinit_pipe_server;
- ctx->accept_handler = accept_connection;
- ctx->finish_handler = finish_connection;
-
- rc = _assuan_register_std_commands (ctx);
- if (rc)
- xfree (ctx);
- else
- *r_ctx = ctx;
- return rc;
-}
-
-
-
-int
-assuan_init_pipe_server (ASSUAN_CONTEXT *r_ctx, int filedes[2])
-{
- int rc;
-
- rc = _assuan_new_context (r_ctx);
- if (!rc)
- {
- ASSUAN_CONTEXT ctx = *r_ctx;
-
- ctx->is_server = 1;
- ctx->inbound.fd = filedes[0];
- ctx->outbound.fd = filedes[1];
- ctx->pipe_mode = 1;
- }
- return rc;
-}
-
-
-void
-_assuan_release_context (ASSUAN_CONTEXT ctx)
-{
- if (ctx)
- {
- xfree (ctx->hello_line);
- xfree (ctx->okay_line);
- xfree (ctx);
- }
-}
-
-void
-assuan_deinit_server (ASSUAN_CONTEXT ctx)
-{
- if (ctx)
- {
- /* We use this function pointer to avoid linking other server
- when not needed but still allow for a generic deinit function */
- ctx->deinit_handler (ctx);
- ctx->deinit_handler = NULL;
- _assuan_release_context (ctx);
- }
-}
diff --git a/assuan/assuan-util.c b/assuan/assuan-util.c
deleted file mode 100644
index c2c899f..0000000
--- a/assuan/assuan-util.c
+++ /dev/null
@@ -1,196 +0,0 @@
-/* assuan-util.c - Utility functions for Assuan
- * Copyright (C) 2001 Free Software Foundation, Inc.
- *
- * This file is part of GnuPG.
- *
- * GnuPG is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * GnuPG is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-#include <config.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "assuan-defs.h"
-
-#ifdef HAVE_JNLIB_LOGGING
-#include "../jnlib/logging.h"
-#endif
-
-
-static void *(*alloc_func)(size_t n) = malloc;
-static void *(*realloc_func)(void *p, size_t n) = realloc;
-static void (*free_func)(void*) = free;
-
-
-
-void
-assuan_set_malloc_hooks ( void *(*new_alloc_func)(size_t n),
- void *(*new_realloc_func)(void *p, size_t n),
- void (*new_free_func)(void*) )
-{
- alloc_func = new_alloc_func;
- realloc_func = new_realloc_func;
- free_func = new_free_func;
-}
-
-void *
-_assuan_malloc (size_t n)
-{
- return alloc_func (n);
-}
-
-void *
-_assuan_realloc (void *a, size_t n)
-{
- return realloc_func (a, n);
-}
-
-void *
-_assuan_calloc (size_t n, size_t m)
-{
- void *p = _assuan_malloc (n*m);
- if (p)
- memset (p, 0, n* m);
- return p;
-}
-
-void
-_assuan_free (void *p)
-{
- if (p)
- free_func (p);
-}
-
-
-
-/* Store the error in the context so that the error sending function
- can take out a descriptive text. Inside the assuan code, use the
- macro set_error instead of this function. */
-int
-assuan_set_error (ASSUAN_CONTEXT ctx, int err, const char *text)
-{
- ctx->err_no = err;
- ctx->err_str = text;
- return err;
-}
-
-void
-assuan_set_pointer (ASSUAN_CONTEXT ctx, void *pointer)
-{
- if (ctx)
- ctx->user_pointer = pointer;
-}
-
-void *
-assuan_get_pointer (ASSUAN_CONTEXT ctx)
-{
- return ctx? ctx->user_pointer : NULL;
-}
-
-
-void
-assuan_set_log_stream (ASSUAN_CONTEXT ctx, FILE *fp)
-{
- if (ctx)
- {
- if (ctx->log_fp)
- fflush (ctx->log_fp);
- ctx->log_fp = fp;
- }
-}
-
-
-void
-assuan_begin_confidential (ASSUAN_CONTEXT ctx)
-{
- if (ctx)
- {
- ctx->confidential = 1;
- }
-}
-
-void
-assuan_end_confidential (ASSUAN_CONTEXT ctx)
-{
- if (ctx)
- {
- ctx->confidential = 0;
- }
-}
-
-void
-_assuan_log_print_buffer (FILE *fp, const void *buffer, size_t length)
-{
- const unsigned char *s;
- int n;
-
- for (n=length,s=buffer; n; n--, s++)
- {
- if (*s < ' ' || (*s >= 0x7f && *s <= 0xa0))
- break;
- }
- s = buffer;
- if (!n && *s != '[')
- fwrite (buffer, length, 1, fp);
- else
- {
- putc ('[', fp);
- for (n=0; n < length; n++, s++)
- fprintf (fp, " %02x", *s);
- putc (' ', fp);
- putc (']', fp);
- }
-}
-
-
-/* print a user supplied string after filtering out potential bad
- characters*/
-void
-_assuan_log_sanitized_string (const char *string)
-{
- const unsigned char *s = (const unsigned char*)string;
-#ifdef HAVE_JNLIB_LOGGING
- FILE *fp = log_get_stream ();
-#else
- FILE *fp = stderr;
-#endif
-
- for (; *s; s++)
- {
- if (*s < 0x20 || (*s >= 0x7f && *s <= 0xa0))
- {
- putc ('\\', fp);
- if (*s == '\n')
- putc ('n', fp);
- else if (*s == '\r')
- putc ('r', fp);
- else if (*s == '\f')
- putc ('f', fp);
- else if (*s == '\v')
- putc ('v', fp);
- else if (*s == '\b')
- putc ('b', fp);
- else if (!*s)
- putc ('0', fp);
- else
- fprintf (fp, "x%02x", *s );
- }
- else
- putc (*s, fp);
- }
-}
-
-
diff --git a/assuan/assuan.h b/assuan/assuan.h
deleted file mode 100644
index 7087d7b..0000000
--- a/assuan/assuan.h
+++ /dev/null
@@ -1,202 +0,0 @@
-/* assuan.c - Definitions for the Assuna protocol
- * Copyright (C) 2001, 2002 Free Software Foundation, Inc.
- *
- * This file is part of GnuPG.
- *
- * GnuPG is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * GnuPG is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-#ifndef ASSUAN_H
-#define ASSUAN_H
-
-#include <stdio.h>
-#include <sys/types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#if 0
- }
-#endif
-#endif
-
-/* 5 is pinentry. */
-#define ASSUAN_ERROR(code) ((5 << 24) | code)
-
-typedef enum {
- ASSUAN_No_Error = 0,
- ASSUAN_General_Error = ASSUAN_ERROR (257),
- ASSUAN_Out_Of_Core = ASSUAN_ERROR (86 | (1 << 15)),
- ASSUAN_Invalid_Value = ASSUAN_ERROR (261),
- ASSUAN_Timeout = ASSUAN_ERROR (62),
- ASSUAN_Read_Error = ASSUAN_ERROR (270), /* Not 100%, but sufficient here. */
- ASSUAN_Write_Error = ASSUAN_ERROR (271), /* Not 100%, but sufficient here. */
- ASSUAN_Problem_Starting_Server = ASSUAN_ERROR (269),
- ASSUAN_Not_A_Server = ASSUAN_ERROR (267),
- ASSUAN_Not_A_Client = ASSUAN_ERROR (268),
- ASSUAN_Nested_Commands = ASSUAN_ERROR (264),
- ASSUAN_Invalid_Response = ASSUAN_ERROR (260),
- ASSUAN_No_Data_Callback = ASSUAN_ERROR (265),
- ASSUAN_No_Inquire_Callback = ASSUAN_ERROR (266),
- ASSUAN_Connect_Failed = ASSUAN_ERROR (259),
- ASSUAN_Accept_Failed = ASSUAN_ERROR (258),
-
- /* error codes above 99 are meant as status codes */
- ASSUAN_Not_Implemented = ASSUAN_ERROR (69),
- ASSUAN_Server_Fault = ASSUAN_ERROR (80),
- ASSUAN_Unknown_Command = ASSUAN_ERROR (275),
- ASSUAN_Syntax_Error = ASSUAN_ERROR (276),
- ASSUAN_Parameter_Conflict = ASSUAN_ERROR (280),
- ASSUAN_Line_Too_Long = ASSUAN_ERROR (263),
- ASSUAN_Line_Not_Terminated = ASSUAN_ERROR (262),
- ASSUAN_Canceled = ASSUAN_ERROR (99),
- ASSUAN_Invalid_Option = ASSUAN_ERROR (174), /* GPG_ERR_UNKNOWN_OPTION */
- ASSUAN_Locale_Problem = ASSUAN_ERROR (166),
- ASSUAN_Not_Confirmed = ASSUAN_ERROR (114),
- ASSUAN_Too_Short = ASSUAN_ERROR (66),
- ASSUAN_ENOENT = ASSUAN_ERROR (81 | (1 << 15)),
- ASSUAN_ENOTTY = ASSUAN_ERROR (102 | (1 << 15)),
-
-} assuan_error_t;
-
-#define ASSUAN_Parameter_Error ASSUAN_Parameter_Conflict
-
-
-typedef assuan_error_t AssuanError; /* Deprecated. */
-
-/* This is a list of pre-registered ASSUAN commands */
-typedef enum {
- ASSUAN_CMD_NOP = 0,
- ASSUAN_CMD_CANCEL, /* cancel the current request */
- ASSUAN_CMD_BYE,
- ASSUAN_CMD_AUTH,
- ASSUAN_CMD_RESET,
- ASSUAN_CMD_OPTION,
- ASSUAN_CMD_DATA,
- ASSUAN_CMD_END,
- ASSUAN_CMD_INPUT,
- ASSUAN_CMD_OUTPUT,
-
- ASSUAN_CMD_USER = 256 /* Other commands should be used with this offset*/
-} AssuanCommand;
-
-#define ASSUAN_LINELENGTH 1002 /* 1000 + [CR,]LF */
-
-struct assuan_context_s;
-typedef struct assuan_context_s *assuan_context_t;
-typedef struct assuan_context_s *ASSUAN_CONTEXT; /* Deprecated. */
-
-/*-- assuan-handler.c --*/
-int assuan_register_command (ASSUAN_CONTEXT ctx,
- int cmd_id, const char *cmd_string,
- int (*handler)(ASSUAN_CONTEXT, char *));
-int assuan_register_bye_notify (ASSUAN_CONTEXT ctx,
- void (*fnc)(ASSUAN_CONTEXT));
-int assuan_register_reset_notify (ASSUAN_CONTEXT ctx,
- void (*fnc)(ASSUAN_CONTEXT));
-int assuan_register_cancel_notify (ASSUAN_CONTEXT ctx,
- void (*fnc)(ASSUAN_CONTEXT));
-int assuan_register_input_notify (ASSUAN_CONTEXT ctx,
- void (*fnc)(ASSUAN_CONTEXT, const char *));
-int assuan_register_output_notify (ASSUAN_CONTEXT ctx,
- void (*fnc)(ASSUAN_CONTEXT, const char *));
-
-int assuan_register_option_handler (ASSUAN_CONTEXT ctx,
- int (*fnc)(ASSUAN_CONTEXT,
- const char*, const char*));
-
-int assuan_process (ASSUAN_CONTEXT ctx);
-int assuan_process_next (ASSUAN_CONTEXT ctx);
-int assuan_get_active_fds (ASSUAN_CONTEXT ctx, int what,
- int *fdarray, int fdarraysize);
-
-
-AssuanError assuan_set_okay_line (ASSUAN_CONTEXT ctx, const char *line);
-void assuan_write_status (ASSUAN_CONTEXT ctx,
- const char *keyword, const char *text);
-
-
-/*-- assuan-listen.c --*/
-AssuanError assuan_set_hello_line (ASSUAN_CONTEXT ctx, const char *line);
-AssuanError assuan_accept (ASSUAN_CONTEXT ctx);
-int assuan_get_input_fd (ASSUAN_CONTEXT ctx);
-int assuan_get_output_fd (ASSUAN_CONTEXT ctx);
-AssuanError assuan_close_input_fd (ASSUAN_CONTEXT ctx);
-AssuanError assuan_close_output_fd (ASSUAN_CONTEXT ctx);
-
-
-/*-- assuan-pipe-server.c --*/
-int assuan_init_pipe_server (ASSUAN_CONTEXT *r_ctx, int filedes[2]);
-void assuan_deinit_server (ASSUAN_CONTEXT ctx);
-
-/*-- assuan-socket-server.c --*/
-int assuan_init_socket_server (ASSUAN_CONTEXT *r_ctx, int listen_fd);
-
-
-/*-- assuan-pipe-connect.c --*/
-AssuanError assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name,
- char *const argv[], int *fd_child_list);
-/*-- assuan-socket-connect.c --*/
-AssuanError assuan_socket_connect (ASSUAN_CONTEXT *ctx, const char *name,
- pid_t server_pid);
-
-/*-- assuan-connect.c --*/
-void assuan_disconnect (ASSUAN_CONTEXT ctx);
-pid_t assuan_get_pid (ASSUAN_CONTEXT ctx);
-
-/*-- assuan-client.c --*/
-AssuanError
-assuan_transact (ASSUAN_CONTEXT ctx,
- const char *command,
- AssuanError (*data_cb)(void *, const void *, size_t),
- void *data_cb_arg,
- AssuanError (*inquire_cb)(void*, const char *),
- void *inquire_cb_arg,
- AssuanError (*status_cb)(void*, const char *),
- void *status_cb_arg);
-
-
-/*-- assuan-inquire.c --*/
-AssuanError assuan_inquire (ASSUAN_CONTEXT ctx, const char *keyword,
- char **r_buffer, size_t *r_length, size_t maxlen);
-
-/*-- assuan-buffer.c --*/
-AssuanError assuan_read_line (ASSUAN_CONTEXT ctx,
- char **line, size_t *linelen);
-int assuan_pending_line (ASSUAN_CONTEXT ctx);
-AssuanError assuan_write_line (ASSUAN_CONTEXT ctx, const char *line );
-AssuanError assuan_send_data (ASSUAN_CONTEXT ctx,
- const void *buffer, size_t length);
-
-
-/*-- assuan-util.c --*/
-void assuan_set_malloc_hooks ( void *(*new_alloc_func)(size_t n),
- void *(*new_realloc_func)(void *p, size_t n),
- void (*new_free_func)(void*) );
-void assuan_set_log_stream (ASSUAN_CONTEXT ctx, FILE *fp);
-int assuan_set_error (ASSUAN_CONTEXT ctx, int err, const char *text);
-void assuan_set_pointer (ASSUAN_CONTEXT ctx, void *pointer);
-void *assuan_get_pointer (ASSUAN_CONTEXT ctx);
-
-void assuan_begin_confidential (ASSUAN_CONTEXT ctx);
-void assuan_end_confidential (ASSUAN_CONTEXT ctx);
-
-/*-- assuan-errors.c (built) --*/
-const char *assuan_strerror (AssuanError err);
-
-
-#ifdef __cplusplus
-}
-#endif
-#endif /*ASSUAN_H*/
diff --git a/assuan/mkerrors b/assuan/mkerrors
deleted file mode 100755
index 91902bf..0000000
--- a/assuan/mkerrors
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/bin/sh
-# mkerrors - Extract error strings from assuan.h
-# and create C source for assuan_strerror
-# Copyright (C) 2001 Free Software Foundation, Inc.
-#
-# This file is part of GnuPG.
-#
-# GnuPG is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# GnuPG is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
-
-cat <<EOF
-/* Generated automatically by mkerrors */
-/* Do not edit! */
-
-#include <stdio.h>
-#include "assuan.h"
-
-/**
- * assuan_strerror:
- * @err: Error code
- *
- * This function returns a textual representaion of the given
- * errorcode. If this is an unknown value, a string with the value
- * is returned (Beware: it is hold in a static buffer).
- *
- * Return value: String with the error description.
- **/
-const char *
-assuan_strerror (AssuanError err)
-{
- const char *s;
- static char buf[25];
-
- switch (err)
- {
-EOF
-
-awk '
-/ASSUAN_No_Error/ { okay=1 }
-!okay {next}
-/}/ { exit 0 }
-/ASSUAN_[A-Za-z_]*/ { print_code($1) }
-
-
-function print_code( s )
-{
-printf " case %s: s=\"", s ;
-gsub(/_/, " ", s );
-printf "%s\"; break;\n", tolower(substr(s,8));
-}
-'
-
-cat <<EOF
- default: sprintf (buf, "ec=%d", err ); s=buf; break;
- }
-
- return s;
-}
-
-EOF
diff --git a/configure.ac b/configure.ac
index 084a160..a03ad79 100644
--- a/configure.ac
+++ b/configure.ac
@@ -229,8 +229,42 @@ COMMON_LIBS=
AC_SUBST(COMMON_CFLAGS)
AC_SUBST(COMMON_LIBS)
+dnl Checks for libgpg-error
+#
+# libgpg-error is a library with error codes shared between GnuPG
+# related projects.
+#
+NEED_GPG_ERROR_VERSION=1.16
+have_gpg_error=no
+
+AM_PATH_GPG_ERROR("$NEED_GPG_ERROR_VERSION",
+ have_gpg_error=yes,have_gpg_error=no)
+COMMON_CFLAGS="$GPG_ERROR_CFLAGS $COMMON_CFLAGS"
+COMMON_LIBS="$GPG_ERROR_LIBS $COMMON_LIBS"
+
+AC_DEFINE_UNQUOTED(GPG_ERR_ENABLE_GETTEXT_MACROS, 1,
+ [Under Windows we use the gettext code from libgpg-error])
+
+AC_DEFINE_UNQUOTED(GPG_ERR_ENABLE_ERRNO_MACROS, 1,
+ [Under WindowsCE we use the strerror replacement from libgpg-error.])
+
+
dnl Checks for libassuan.
-dnl -> None required because we use a stripped down version of libassuan.
+#
+# libassuan is used for IPC
+#
+NEED_LIBASSUAN_API=2
+NEED_LIBASSUAN_VERSION=2.1.0
+have_libassuan=no
+AM_PATH_LIBASSUAN("$NEED_LIBASSUAN_API:$NEED_LIBASSUAN_VERSION",
+ have_libassuan=yes,have_libassuan=no)
+if test "$have_libassuan" = "yes"; then
+ AC_DEFINE_UNQUOTED(GNUPG_LIBASSUAN_VERSION, "$libassuan_version",
+ [version of the libassuan library])
+fi
+
+COMMON_CFLAGS="$LIBASSUAN_CFLAGS $COMMON_CFLAGS"
+COMMON_LIBS="$LIBASSUAN_LIBS $COMMON_LIBS"
dnl Checks for libsecmem.
@@ -442,8 +476,8 @@ if test "$libsecret" = "yes"; then
AC_DEFINE(HAVE_LIBSECRET, 1,
[The pinentries should optionally cache the passphrase using libsecret.])
- COMMON_CFLAGS="$COMMON_CFLAGS $LIBSECRET_CFLAGS"
- COMMON_LIBS="$COMMON_LIBS $LIBSECRET_LIBS"
+ COMMON_CFLAGS="$LIBSECRET_CFLAGS $COMMON_CFLAGS"
+ COMMON_LIBS="$LIBSECRET_LIBS $COMMON_LIBS"
fi
dnl
@@ -561,9 +595,44 @@ else
fi
AC_SUBST(PINENTRY_DEFAULT)
+#
+# Print errors here so that they are visible all
+# together and the user can acquire them all together.
+#
+die=no
+if test "$have_gpg_error" = "no"; then
+ die=yes
+ AC_MSG_NOTICE([[
+***
+*** You need libgpg-error to build this program.
+** This library is for example available at
+*** ftp://ftp.gnupg.org/gcrypt/libgpg-error
+*** (at least version $NEED_GPG_ERROR_VERSION is required.)
+***]])
+fi
+
+if test "$have_libassuan" = "no"; then
+ die=yes
+ AC_MSG_NOTICE([[
+***
+*** You need libassuan to build this program.
+*** This library is for example available at
+*** ftp://ftp.gnupg.org/gcrypt/libassuan/
+*** (at least version $NEED_LIBASSUAN_VERSION (API $NEED_LIBASSUAN_API) is required).
+***]])
+fi
+
+if test "$die" = "yes"; then
+ AC_MSG_ERROR([[
+***
+*** Required libraries not found. Please consult the above messages
+*** and install them before running configure again.
+***]])
+fi
+
+
AC_CONFIG_FILES([
-assuan/Makefile
secmem/Makefile
pinentry/Makefile
curses/Makefile
diff --git a/curses/Makefile.am b/curses/Makefile.am
index 4d764c7..915f8a8 100644
--- a/curses/Makefile.am
+++ b/curses/Makefile.am
@@ -23,7 +23,6 @@ bin_PROGRAMS = pinentry-curses
AM_CPPFLAGS = $(COMMON_CFLAGS) $(NCURSES_INCLUDE) -I$(top_srcdir)/pinentry
LDADD = ../pinentry/libpinentry.a ../pinentry/libpinentry-curses.a \
- ../assuan/libassuan.a ../secmem/libsecmem.a \
- $(COMMON_LIBS) $(LIBCAP) $(LIBCURSES) $(LIBICONV)
+ ../secmem/libsecmem.a $(COMMON_LIBS) $(LIBCAP) $(LIBCURSES) $(LIBICONV)
pinentry_curses_SOURCES = pinentry-curses.c
diff --git a/gnome3/Makefile.am b/gnome3/Makefile.am
index 46639de..71c0732 100644
--- a/gnome3/Makefile.am
+++ b/gnome3/Makefile.am
@@ -30,9 +30,8 @@ libcurses =
endif
AM_CPPFLAGS = $(COMMON_CFLAGS) $(GNOME3CFLAGS) \
- $(ncurses_include) -I$(top_srcdir)/assuan \
- -I$(top_srcdir)/secmem -I$(top_srcdir)/pinentry
-LDADD = ../pinentry/libpinentry.a ../assuan/libassuan.a ../secmem/libsecmem.a \
+ $(ncurses_include) -I$(top_srcdir)/secmem -I$(top_srcdir)/pinentry
+LDADD = ../pinentry/libpinentry.a ../secmem/libsecmem.a \
$(COMMON_LIBS) $(LIBCAP) $(GNOME3LIBS) $(libcurses)
pinentry_gnome3_SOURCES = pinentry-gnome3.c
diff --git a/gnome3/pinentry-gnome3.c b/gnome3/pinentry-gnome3.c
index 0fea8f0..73d5f6d 100644
--- a/gnome3/pinentry-gnome3.c
+++ b/gnome3/pinentry-gnome3.c
@@ -27,7 +27,7 @@
#include <string.h>
-#include "assuan.h"
+#include <assuan.h>
#include "memory.h"
@@ -189,7 +189,8 @@ gnome3_cmd_handler (pinentry_t pe)
if (error)
/* Error. */
{
- pe->specific_err = ASSUAN_General_Error;
+ pe->specific_err =
+ gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ASS_GENERAL);
g_error_free (error);
ret = -1;
}
@@ -231,7 +232,8 @@ gnome3_cmd_handler (pinentry_t pe)
reply = gcr_prompt_confirm_run (prompt, NULL, &error);
if (error)
{
- pe->specific_err = ASSUAN_General_Error;
+ pe->specific_err =
+ gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ASS_GENERAL);
ret = 0;
}
else if (reply == GCR_PROMPT_REPLY_CONTINUE
diff --git a/gtk+-2/Makefile.am b/gtk+-2/Makefile.am
index 7e37469..88f245e 100644
--- a/gtk+-2/Makefile.am
+++ b/gtk+-2/Makefile.am
@@ -31,7 +31,7 @@ endif
AM_CPPFLAGS = $(COMMON_CFLAGS) $(GTK2CFLAGS) $(ncurses_include) \
-I$(top_srcdir)/secmem -I$(top_srcdir)/pinentry
-LDADD = ../pinentry/libpinentry.a ../assuan/libassuan.a ../secmem/libsecmem.a \
+LDADD = ../pinentry/libpinentry.a ../secmem/libsecmem.a \
$(COMMON_LIBS) $(LIBCAP) $(GTK2LIBS) $(libcurses)
pinentry_gtk_2_SOURCES = pinentry-gtk-2.c \
diff --git a/pinentry/Makefile.am b/pinentry/Makefile.am
index 7fbbab6..d24581b 100644
--- a/pinentry/Makefile.am
+++ b/pinentry/Makefile.am
@@ -30,7 +30,7 @@ endif
noinst_LIBRARIES = libpinentry.a $(pinentry_curses)
LDADD = $(COMMON_LIBS)
-AM_CPPFLAGS = $(COMMON_CFLAGS) -I$(top_srcdir)/assuan -I$(top_srcdir)/secmem
+AM_CPPFLAGS = $(COMMON_CFLAGS) -I$(top_srcdir)/secmem
libpinentry_a_SOURCES = pinentry.h pinentry.c argparse.c argparse.h \
password-cache.h password-cache.c
diff --git a/pinentry/pinentry-curses.c b/pinentry/pinentry-curses.c
index d25ab2e..f130817 100644
--- a/pinentry/pinentry-curses.c
+++ b/pinentry/pinentry-curses.c
@@ -50,8 +50,9 @@
#include <wchar.h>
#endif /*HAVE_WCHAR_H*/
+#include <assuan.h>
+
#include "pinentry.h"
-#include "assuan.h"
/* FIXME: We should allow configuration of these button labels and in
any case use the default_ok, default_cancel values if available.
@@ -250,7 +251,8 @@ dialog_create (pinentry_t pinentry, dialog_t dialog)
if (!what) \
{ \
err = 1; \
- pinentry->specific_err = ASSUAN_Locale_Problem; \
+ pinentry->specific_err = \
+ gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_LOCALE_PROBLEM); \
goto out; \
} \
} \
@@ -282,7 +284,8 @@ dialog_create (pinentry_t pinentry, dialog_t dialog)
if (!new) \
{ \
err = 1; \
- pinentry->specific_err = ASSUAN_Out_Of_Core; \
+ pinentry->specific_err = \
+ gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM); \
goto out; \
} \
\
@@ -307,7 +310,8 @@ dialog_create (pinentry_t pinentry, dialog_t dialog)
if (!dialog->which) \
{ \
err = 1; \
- pinentry->specific_err = ASSUAN_Locale_Problem; \
+ pinentry->specific_err = \
+ gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_LOCALE_PROBLEM); \
goto out; \
} \
} \
@@ -373,7 +377,8 @@ dialog_create (pinentry_t pinentry, dialog_t dialog)
if (y > size_y)
{
err = 1;
- pinentry->specific_err = ASSUAN_Too_Short;
+ pinentry->specific_err =
+ gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ASS_LINE_TOO_LONG);
goto out;
}
@@ -428,7 +433,8 @@ dialog_create (pinentry_t pinentry, dialog_t dialog)
if (x > size_x)
{
err = 1;
- pinentry->specific_err = ASSUAN_Too_Short;
+ pinentry->specific_err =
+ gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ASS_LINE_TOO_LONG);
goto out;
}
@@ -833,7 +839,8 @@ dialog_run (pinentry_t pinentry, const char *tty_name, const char *tty_type)
ttyfi = fopen (tty_name, "r");
if (!ttyfi)
{
- pinentry->specific_err = ASSUAN_ENOENT;
+ pinentry->specific_err =
+ gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOENT);
return -1;
}
ttyfo = fopen (tty_name, "w");
@@ -842,7 +849,8 @@ dialog_run (pinentry_t pinentry, const char *tty_name, const char *tty_type)
int err = errno;
fclose (ttyfi);
errno = err;
- pinentry->specific_err = ASSUAN_ENOENT;
+ pinentry->specific_err =
+ gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOENT);
return -1;
}
screen = newterm (tty_type, ttyfo, ttyfi);
@@ -855,7 +863,8 @@ dialog_run (pinentry_t pinentry, const char *tty_name, const char *tty_type)
if (!(isatty(fileno(stdin)) && isatty(fileno(stdout))))
{
errno = ENOTTY;
- pinentry->specific_err = ASSUAN_ENOTTY;
+ pinentry->specific_err =
+ gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOTTY);
return -1;
}
init_screen = 1;
diff --git a/pinentry/pinentry.c b/pinentry/pinentry.c
index 6f7a62c..c440d08 100644
--- a/pinentry/pinentry.c
+++ b/pinentry/pinentry.c
@@ -43,7 +43,8 @@
#include <iconv.h>
#endif
-#include "assuan.h"
+#include <assuan.h>
+
#include "memory.h"
#include "secmem-util.h"
#include "argparse.h"
@@ -165,11 +166,15 @@ pinentry_reset (int use_defaults)
}
}
-static void
-pinentry_assuan_reset_handler (ASSUAN_CONTEXT ctx)
+static gpg_error_t
+pinentry_assuan_reset_handler (assuan_context_t ctx, char *line)
{
(void)ctx;
+ (void)line;
+
pinentry_reset (0);
+
+ return 0;
}
@@ -356,7 +361,7 @@ copy_and_escape (char *buffer, const void *text, size_t textlen)
int
pinentry_inq_quality (pinentry_t pin, const char *passphrase, size_t length)
{
- ASSUAN_CONTEXT ctx = pin->ctx_assuan;
+ assuan_context_t ctx = pin->ctx_assuan;
const char prefix[] = "INQUIRE QUALITY ";
char *command;
char *line;
@@ -500,6 +505,10 @@ pinentry_setbuffer_use (pinentry_t pin, char *passphrase, int len)
pin->pin_len = len;
}
+static struct assuan_malloc_hooks assuan_malloc_hooks = {
+ secmem_malloc, secmem_realloc, secmem_free
+};
+
/* Initialize the secure memory subsystem, drop privileges and return.
Must be called early. */
void
@@ -510,6 +519,8 @@ pinentry_init (const char *pgmname)
abort ();
strcpy (this_pgmname, pgmname);
+ gpgrt_check_version (NULL);
+
/* Initialize secure memory. 1 is too small, so the default size
will be used. */
secmem_init (1);
@@ -521,7 +532,7 @@ pinentry_init (const char *pgmname)
/* FIXME: Could not register at-exit function, bail out. */
}
- assuan_set_malloc_hooks (secmem_malloc, secmem_realloc, secmem_free);
+ assuan_set_malloc_hooks (&assuan_malloc_hooks);
}
/* Simple test to check whether DISPLAY is set or the option --display
@@ -755,8 +766,8 @@ pinentry_parse_opts (int argc, char *argv[])
}
-static int
-option_handler (ASSUAN_CONTEXT ctx, const char *key, const char *value)
+static gpg_error_t
+option_handler (assuan_context_t ctx, const char *key, const char *value)
{
(void)ctx;
@@ -779,7 +790,7 @@ option_handler (ASSUAN_CONTEXT ctx, const char *key, const char *value)
free (pinentry.display);
pinentry.display = strdup (value);
if (!pinentry.display)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
}
else if (!strcmp (key, "ttyname"))
{
@@ -787,7 +798,7 @@ option_handler (ASSUAN_CONTEXT ctx, const char *key, const char *value)
free (pinentry.ttyname);
pinentry.ttyname = strdup (value);
if (!pinentry.ttyname)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
}
else if (!strcmp (key, "ttytype"))
{
@@ -795,7 +806,7 @@ option_handler (ASSUAN_CONTEXT ctx, const char *key, const char *value)
free (pinentry.ttytype);
pinentry.ttytype = strdup (value);
if (!pinentry.ttytype)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
}
else if (!strcmp (key, "lc-ctype"))
{
@@ -803,7 +814,7 @@ option_handler (ASSUAN_CONTEXT ctx, const char *key, const char *value)
free (pinentry.lc_ctype);
pinentry.lc_ctype = strdup (value);
if (!pinentry.lc_ctype)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
}
else if (!strcmp (key, "lc-messages"))
{
@@ -811,7 +822,7 @@ option_handler (ASSUAN_CONTEXT ctx, const char *key, const char *value)
free (pinentry.lc_messages);
pinentry.lc_messages = strdup (value);
if (!pinentry.lc_messages)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
}
else if (!strcmp (key, "parent-wid"))
{
@@ -824,31 +835,31 @@ option_handler (ASSUAN_CONTEXT ctx, const char *key, const char *value)
free (pinentry.touch_file);
pinentry.touch_file = strdup (value);
if (!pinentry.touch_file)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
}
else if (!strcmp (key, "default-ok"))
{
pinentry.default_ok = strdup (value);
if (!pinentry.default_ok)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
}
else if (!strcmp (key, "default-cancel"))
{
pinentry.default_cancel = strdup (value);
if (!pinentry.default_cancel)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
}
else if (!strcmp (key, "default-prompt"))
{
pinentry.default_prompt = strdup (value);
if (!pinentry.default_prompt)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
}
else if (!strcmp (key, "default-pwmngr"))
{
pinentry.default_pwmngr = strdup (value);
if (!pinentry.default_pwmngr)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
}
else if (!strcmp (key, "allow-external-password-cache") && !*value)
{
@@ -856,7 +867,7 @@ option_handler (ASSUAN_CONTEXT ctx, const char *key, const char *value)
pinentry.tried_password_cache = 0;
}
else
- return ASSUAN_Invalid_Option;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_UNKNOWN_OPTION);
return 0;
}
@@ -881,8 +892,8 @@ strcpy_escaped (char *d, const char *s)
}
-static int
-cmd_setdesc (ASSUAN_CONTEXT ctx, char *line)
+static gpg_error_t
+cmd_setdesc (assuan_context_t ctx, char *line)
{
char *newd;
@@ -890,7 +901,7 @@ cmd_setdesc (ASSUAN_CONTEXT ctx, char *line)
newd = malloc (strlen (line) + 1);
if (!newd)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
strcpy_escaped (newd, line);
if (pinentry.description)
@@ -900,8 +911,8 @@ cmd_setdesc (ASSUAN_CONTEXT ctx, char *line)
}
-static int
-cmd_setprompt (ASSUAN_CONTEXT ctx, char *line)
+static gpg_error_t
+cmd_setprompt (assuan_context_t ctx, char *line)
{
char *newp;
@@ -909,7 +920,7 @@ cmd_setprompt (ASSUAN_CONTEXT ctx, char *line)
newp = malloc (strlen (line) + 1);
if (!newp)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
strcpy_escaped (newp, line);
if (pinentry.prompt)
@@ -923,8 +934,8 @@ cmd_setprompt (ASSUAN_CONTEXT ctx, char *line)
to identify a key for caching strategies of its own. The empty
string and --clear mean that the key does not have a stable
identifier. */
-static int
-cmd_setkeyinfo (ASSUAN_CONTEXT ctx, char *line)
+static gpg_error_t
+cmd_setkeyinfo (assuan_context_t ctx, char *line)
{
(void)ctx;
@@ -940,8 +951,8 @@ cmd_setkeyinfo (ASSUAN_CONTEXT ctx, char *line)
}
-static int
-cmd_setrepeat (ASSUAN_CONTEXT ctx, char *line)
+static gpg_error_t
+cmd_setrepeat (assuan_context_t ctx, char *line)
{
char *p;
@@ -949,7 +960,7 @@ cmd_setrepeat (ASSUAN_CONTEXT ctx, char *line)
p = malloc (strlen (line) + 1);
if (!p)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
strcpy_escaped (p, line);
free (pinentry.repeat_passphrase);
@@ -958,8 +969,8 @@ cmd_setrepeat (ASSUAN_CONTEXT ctx, char *line)
}
-static int
-cmd_setrepeaterror (ASSUAN_CONTEXT ctx, char *line)
+static gpg_error_t
+cmd_setrepeaterror (assuan_context_t ctx, char *line)
{
char *p;
@@ -967,7 +978,7 @@ cmd_setrepeaterror (ASSUAN_CONTEXT ctx, char *line)
p = malloc (strlen (line) + 1);
if (!p)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
strcpy_escaped (p, line);
free (pinentry.repeat_error_string);
@@ -976,8 +987,8 @@ cmd_setrepeaterror (ASSUAN_CONTEXT ctx, char *line)
}
-static int
-cmd_seterror (ASSUAN_CONTEXT ctx, char *line)
+static gpg_error_t
+cmd_seterror (assuan_context_t ctx, char *line)
{
char *newe;
@@ -985,7 +996,7 @@ cmd_seterror (ASSUAN_CONTEXT ctx, char *line)
newe = malloc (strlen (line) + 1);
if (!newe)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
strcpy_escaped (newe, line);
if (pinentry.error)
@@ -995,8 +1006,8 @@ cmd_seterror (ASSUAN_CONTEXT ctx, char *line)
}
-static int
-cmd_setok (ASSUAN_CONTEXT ctx, char *line)
+static gpg_error_t
+cmd_setok (assuan_context_t ctx, char *line)
{
char *newo;
@@ -1004,7 +1015,7 @@ cmd_setok (ASSUAN_CONTEXT ctx, char *line)
newo = malloc (strlen (line) + 1);
if (!newo)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
strcpy_escaped (newo, line);
if (pinentry.ok)
@@ -1014,8 +1025,8 @@ cmd_setok (ASSUAN_CONTEXT ctx, char *line)
}
-static int
-cmd_setnotok (ASSUAN_CONTEXT ctx, char *line)
+static gpg_error_t
+cmd_setnotok (assuan_context_t ctx, char *line)
{
char *newo;
@@ -1023,7 +1034,7 @@ cmd_setnotok (ASSUAN_CONTEXT ctx, char *line)
newo = malloc (strlen (line) + 1);
if (!newo)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
strcpy_escaped (newo, line);
if (pinentry.notok)
@@ -1033,8 +1044,8 @@ cmd_setnotok (ASSUAN_CONTEXT ctx, char *line)
}
-static int
-cmd_setcancel (ASSUAN_CONTEXT ctx, char *line)
+static gpg_error_t
+cmd_setcancel (assuan_context_t ctx, char *line)
{
char *newc;
@@ -1042,7 +1053,7 @@ cmd_setcancel (ASSUAN_CONTEXT ctx, char *line)
newc = malloc (strlen (line) + 1);
if (!newc)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
strcpy_escaped (newc, line);
if (pinentry.cancel)
@@ -1052,8 +1063,8 @@ cmd_setcancel (ASSUAN_CONTEXT ctx, char *line)
}
-static int
-cmd_settimeout (ASSUAN_CONTEXT ctx, char *line)
+static gpg_error_t
+cmd_settimeout (assuan_context_t ctx, char *line)
{
(void)ctx;
@@ -1063,8 +1074,8 @@ cmd_settimeout (ASSUAN_CONTEXT ctx, char *line)
return 0;
}
-static int
-cmd_settitle (ASSUAN_CONTEXT ctx, char *line)
+static gpg_error_t
+cmd_settitle (assuan_context_t ctx, char *line)
{
char *newt;
@@ -1072,7 +1083,7 @@ cmd_settitle (ASSUAN_CONTEXT ctx, char *line)
newt = malloc (strlen (line) + 1);
if (!newt)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
strcpy_escaped (newt, line);
if (pinentry.title)
@@ -1081,8 +1092,8 @@ cmd_settitle (ASSUAN_CONTEXT ctx, char *line)
return 0;
}
-static int
-cmd_setqualitybar (ASSUAN_CONTEXT ctx, char *line)
+static gpg_error_t
+cmd_setqualitybar (assuan_context_t ctx, char *line)
{
char *newval;
@@ -1093,7 +1104,7 @@ cmd_setqualitybar (ASSUAN_CONTEXT ctx, char *line)
newval = malloc (strlen (line) + 1);
if (!newval)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
strcpy_escaped (newval, line);
if (pinentry.quality_bar)
@@ -1103,8 +1114,8 @@ cmd_setqualitybar (ASSUAN_CONTEXT ctx, char *line)
}
/* Set the tooltip to be used for a quality bar. */
-static int
-cmd_setqualitybar_tt (ASSUAN_CONTEXT ctx, char *line)
+static gpg_error_t
+cmd_setqualitybar_tt (assuan_context_t ctx, char *line)
{
char *newval;
@@ -1114,7 +1125,7 @@ cmd_setqualitybar_tt (ASSUAN_CONTEXT ctx, char *line)
{
newval = malloc (strlen (line) + 1);
if (!newval)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
strcpy_escaped (newval, line);
}
@@ -1127,8 +1138,8 @@ cmd_setqualitybar_tt (ASSUAN_CONTEXT ctx, char *line)
}
-static int
-cmd_getpin (ASSUAN_CONTEXT ctx, char *line)
+static gpg_error_t
+cmd_getpin (assuan_context_t ctx, char *line)
{
int result;
int set_prompt = 0;
@@ -1138,7 +1149,7 @@ cmd_getpin (ASSUAN_CONTEXT ctx, char *line)
pinentry_setbuffer_init (&pinentry);
if (!pinentry.pin)
- return ASSUAN_Out_Of_Core;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ENOMEM);
/* Try reading from the password cache. */
if (/* If repeat passphrase is set, then we don't want to read from
@@ -1224,7 +1235,9 @@ cmd_getpin (ASSUAN_CONTEXT ctx, char *line)
pinentry_setbuffer_clear (&pinentry);
if (pinentry.specific_err)
return pinentry.specific_err;
- return pinentry.locale_err? ASSUAN_Locale_Problem: ASSUAN_Canceled;
+ return (pinentry.locale_err
+ ? gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_LOCALE_PROBLEM)
+ : gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_CANCELED));
}
out:
@@ -1259,8 +1272,8 @@ cmd_getpin (ASSUAN_CONTEXT ctx, char *line)
update pinentry or to have the caller test for the message
command. New applications which are free to require an updated
pinentry should use MESSAGE instead. */
-static int
-cmd_confirm (ASSUAN_CONTEXT ctx, char *line)
+static gpg_error_t
+cmd_confirm (assuan_context_t ctx, char *line)
{
int result;
@@ -1288,19 +1301,19 @@ cmd_confirm (ASSUAN_CONTEXT ctx, char *line)
return pinentry.specific_err;
if (pinentry.locale_err)
- return ASSUAN_Locale_Problem;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_LOCALE_PROBLEM);
if (pinentry.one_button)
return 0;
if (pinentry.canceled)
- return ASSUAN_Canceled;
- return ASSUAN_Not_Confirmed;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_CANCELED);
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_NOT_CONFIRMED);
}
-static int
-cmd_message (ASSUAN_CONTEXT ctx, char *line)
+static gpg_error_t
+cmd_message (assuan_context_t ctx, char *line)
{
(void)line;
@@ -1315,7 +1328,7 @@ cmd_message (ASSUAN_CONTEXT ctx, char *line)
version - Return the version of the program.
pid - Return the process id of the server.
*/
-static int
+static gpg_error_t
cmd_getinfo (assuan_context_t ctx, char *line)
{
int rc;
@@ -1333,7 +1346,7 @@ cmd_getinfo (assuan_context_t ctx, char *line)
rc = assuan_send_data (ctx, numbuf, strlen (numbuf));
}
else
- rc = ASSUAN_Parameter_Error;
+ rc = gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ASS_PARAMETER);
return rc;
}
@@ -1342,13 +1355,13 @@ cmd_getinfo (assuan_context_t ctx, char *line)
Clear the cache passphrase associated with the key identified by
cacheid.
*/
-static int
-cmd_clear_passphrase (ASSUAN_CONTEXT ctx, char *line)
+static gpg_error_t
+cmd_clear_passphrase (assuan_context_t ctx, char *line)
{
(void)ctx;
if (! line)
- return ASSUAN_Invalid_Value;
+ return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ASS_INV_VALUE);
/* Remove leading and trailing white space. */
while (*line == ' ')
@@ -1359,50 +1372,47 @@ cmd_clear_passphrase (ASSUAN_CONTEXT ctx, char *line)
switch (password_cache_clear (line))
{
case 1: return 0;
- case 0: return ASSUAN_Invalid_Value;
- default: return ASSUAN_General_Error;
+ case 0: return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ASS_INV_VALUE);
+ default: return gpg_err_make (GPG_ERR_SOURCE_PINENTRY, GPG_ERR_ASS_GENERAL);
}
}
/* Tell the assuan library about our commands. */
-static int
-register_commands (ASSUAN_CONTEXT ctx)
+static gpg_error_t
+register_commands (assuan_context_t ctx)
{
static struct
{
const char *name;
- int cmd_id;
- int (*handler) (ASSUAN_CONTEXT, char *line);
+ gpg_error_t (*handler) (assuan_context_t, char *line);
} table[] =
{
- { "SETDESC", 0, cmd_setdesc },
- { "SETPROMPT", 0, cmd_setprompt },
- { "SETKEYINFO", 0, cmd_setkeyinfo },
- { "SETREPEAT", 0, cmd_setrepeat },
- { "SETREPEATERROR",0, cmd_setrepeaterror },
- { "SETERROR", 0, cmd_seterror },
- { "SETOK", 0, cmd_setok },
- { "SETNOTOK", 0, cmd_setnotok },
- { "SETCANCEL", 0, cmd_setcancel },
- { "GETPIN", 0, cmd_getpin },
- { "CONFIRM", 0, cmd_confirm },
- { "MESSAGE", 0, cmd_message },
- { "SETQUALITYBAR", 0, cmd_setqualitybar },
- { "SETQUALITYBAR_TT", 0, cmd_setqualitybar_tt },
- { "GETINFO", 0, cmd_getinfo },
- { "SETTITLE", 0, cmd_settitle },
- { "SETTIMEOUT", 0, cmd_settimeout },
- { "CLEARPASSPHRASE", 0, cmd_clear_passphrase },
+ { "SETDESC", cmd_setdesc },
+ { "SETPROMPT", cmd_setprompt },
+ { "SETKEYINFO", cmd_setkeyinfo },
+ { "SETREPEAT", cmd_setrepeat },
+ { "SETREPEATERROR", cmd_setrepeaterror },
+ { "SETERROR", cmd_seterror },
+ { "SETOK", cmd_setok },
+ { "SETNOTOK", cmd_setnotok },
+ { "SETCANCEL", cmd_setcancel },
+ { "GETPIN", cmd_getpin },
+ { "CONFIRM", cmd_confirm },
+ { "MESSAGE", cmd_message },
+ { "SETQUALITYBAR", cmd_setqualitybar },
+ { "SETQUALITYBAR_TT", cmd_setqualitybar_tt },
+ { "GETINFO", cmd_getinfo },
+ { "SETTITLE", cmd_settitle },
+ { "SETTIMEOUT", cmd_settimeout },
+ { "CLEARPASSPHRASE", cmd_clear_passphrase },
{ NULL }
};
- int i, j, rc;
+ int i, j;
+ gpg_error_t rc;
for (i = j = 0; table[i].name; i++)
{
- rc = assuan_register_command (ctx,
- table[i].cmd_id ? table[i].cmd_id
- : (ASSUAN_CMD_USER + j++),
- table[i].name, table[i].handler);
+ rc = assuan_register_command (ctx, table[i].name, table[i].handler, NULL);
if (rc)
return rc;
}
@@ -1413,9 +1423,9 @@ register_commands (ASSUAN_CONTEXT ctx)
int
pinentry_loop2 (int infd, int outfd)
{
- int rc;
+ gpg_error_t rc;
int filedes[2];
- ASSUAN_CONTEXT ctx;
+ assuan_context_t ctx;
/* Extra check to make sure we have dropped privs. */
#ifndef HAVE_DOSISH_SYSTEM
@@ -1423,23 +1433,31 @@ pinentry_loop2 (int infd, int outfd)
abort ();
#endif
+ rc = assuan_new (&ctx);
+ if (rc)
+ {
+ fprintf (stderr, "server context creation failed: %s\n",
+ gpg_strerror(rc));
+ return -1;
+ }
+
/* For now we use a simple pipe based server so that we can work
from scripts. We will later add options to run as a daemon and
wait for requests on a Unix domain socket. */
filedes[0] = infd;
filedes[1] = outfd;
- rc = assuan_init_pipe_server (&ctx, filedes);
+ rc = assuan_init_pipe_server (ctx, filedes);
if (rc)
{
fprintf (stderr, "%s: failed to initialize the server: %s\n",
- this_pgmname, assuan_strerror(rc));
+ this_pgmname, gpg_strerror (rc));
return -1;
}
rc = register_commands (ctx);
if (rc)
{
fprintf (stderr, "%s: failed to the register commands with Assuan: %s\n",
- this_pgmname, assuan_strerror(rc));
+ this_pgmname, gpg_strerror (rc));
return -1;
}
@@ -1457,7 +1475,7 @@ pinentry_loop2 (int infd, int outfd)
else if (rc)
{
fprintf (stderr, "%s: Assuan accept problem: %s\n",
- this_pgmname, assuan_strerror (rc));
+ this_pgmname, gpg_strerror (rc));
break;
}
@@ -1465,12 +1483,12 @@ pinentry_loop2 (int infd, int outfd)
if (rc)
{
fprintf (stderr, "%s: Assuan processing failed: %s\n",
- this_pgmname, assuan_strerror (rc));
+ this_pgmname, gpg_strerror (rc));
continue;
}
}
- assuan_deinit_server (ctx);
+ assuan_release (ctx);
return 0;
}
diff --git a/qt4/Makefile.am b/qt4/Makefile.am
index 816aade..e2014e3 100644
--- a/qt4/Makefile.am
+++ b/qt4/Makefile.am
@@ -35,12 +35,11 @@ endif
AM_CPPFLAGS = $(COMMON_CFLAGS) \
- -I$(top_srcdir) -I$(top_srcdir)/assuan -I$(top_srcdir)/secmem \
+ -I$(top_srcdir) -I$(top_srcdir)/secmem \
$(ncurses_include) -I$(top_srcdir)/pinentry
AM_CXXFLAGS = $(QT4_CORE_CFLAGS) $(QT4_GUI_CFLAGS)
pinentry_qt4_LDADD = \
- ../pinentry/libpinentry.a $(top_builddir)/assuan/libassuan.a \
- $(top_builddir)/secmem/libsecmem.a \
+ ../pinentry/libpinentry.a $(top_builddir)/secmem/libsecmem.a \
$(COMMON_LIBS) $(QT4_CORE_LIBS) $(QT4_GUI_LIBS) $(libcurses) $(LIBCAP)
BUILT_SOURCES = \
diff --git a/tty/Makefile.am b/tty/Makefile.am
index ca6406f..e232473 100644
--- a/tty/Makefile.am
+++ b/tty/Makefile.am
@@ -21,8 +21,7 @@
bin_PROGRAMS = pinentry-tty
AM_CPPFLAGS = $(COMMON_CFLAGS) -I$(top_srcdir)/secmem -I$(top_srcdir)/pinentry
-LDADD = ../pinentry/libpinentry.a \
- ../assuan/libassuan.a ../secmem/libsecmem.a \
+LDADD = ../pinentry/libpinentry.a ../secmem/libsecmem.a \
$(COMMON_LIBS) $(LIBCAP) $(LIBICONV)
pinentry_tty_SOURCES = pinentry-tty.c
--
2.1.4
More information about the Gnupg-devel
mailing list