1998-01-30 16:23:16 +00:00
|
|
|
/* status.c
|
2004-07-15 21:00:35 +00:00
|
|
|
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003,
|
2005-03-14 19:19:21 +00:00
|
|
|
* 2004, 2005 Free Software Foundation, Inc.
|
1998-01-30 16:23:16 +00:00
|
|
|
*
|
1998-12-23 12:41:40 +00:00
|
|
|
* This file is part of GnuPG.
|
1998-01-30 16:23:16 +00:00
|
|
|
*
|
1998-12-23 12:41:40 +00:00
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
1998-01-30 16:23:16 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-10-23 10:48:09 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1998-01-30 16:23:16 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
1998-12-23 12:41:40 +00:00
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
1998-01-30 16:23:16 +00:00
|
|
|
* 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
|
2007-10-23 10:48:09 +00:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
1998-01-30 16:23:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1998-02-03 12:09:20 +00:00
|
|
|
#include <string.h>
|
1998-07-31 16:45:58 +00:00
|
|
|
#include <errno.h>
|
1998-01-30 16:23:16 +00:00
|
|
|
#include <unistd.h>
|
2002-06-29 13:46:34 +00:00
|
|
|
#include <signal.h>
|
1998-07-31 16:45:58 +00:00
|
|
|
#ifdef USE_SHM_COPROCESSING
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#ifdef USE_CAPABILITIES
|
|
|
|
#include <sys/capability.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_IPC_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_SHM_H
|
|
|
|
#include <sys/shm.h>
|
|
|
|
#endif
|
|
|
|
#if defined(HAVE_MLOCK)
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#endif
|
1998-07-31 16:45:58 +00:00
|
|
|
#endif
|
|
|
|
#include "util.h"
|
1998-01-30 16:23:16 +00:00
|
|
|
#include "status.h"
|
1998-07-31 16:45:58 +00:00
|
|
|
#include "ttyio.h"
|
|
|
|
#include "options.h"
|
|
|
|
#include "main.h"
|
1998-08-08 19:27:00 +00:00
|
|
|
#include "i18n.h"
|
2002-06-29 13:46:34 +00:00
|
|
|
#include "cipher.h" /* for progress functions */
|
|
|
|
|
|
|
|
#define CONTROL_D ('D' - 'A' + 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static FILE *statusfp;
|
1998-01-30 16:23:16 +00:00
|
|
|
|
1998-07-31 16:45:58 +00:00
|
|
|
#ifdef USE_SHM_COPROCESSING
|
|
|
|
static int shm_id = -1;
|
|
|
|
static volatile char *shm_area;
|
|
|
|
static size_t shm_size;
|
|
|
|
static int shm_is_locked;
|
|
|
|
#endif /*USE_SHM_COPROCESSING*/
|
1998-01-30 16:23:16 +00:00
|
|
|
|
2000-07-14 17:34:53 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
progress_cb ( void *ctx, int c )
|
|
|
|
{
|
|
|
|
char buf[50];
|
|
|
|
|
|
|
|
if ( c == '\n' )
|
|
|
|
sprintf ( buf, "%.20s X 100 100", (char*)ctx );
|
|
|
|
else
|
|
|
|
sprintf ( buf, "%.20s %c 0 0", (char*)ctx, c );
|
|
|
|
write_status_text ( STATUS_PROGRESS, buf );
|
|
|
|
}
|
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
static const char *
|
2012-01-13 16:20:53 +01:00
|
|
|
get_status_string ( int no )
|
2002-06-29 13:46:34 +00:00
|
|
|
{
|
2004-10-28 03:14:55 +00:00
|
|
|
const char *s;
|
|
|
|
|
|
|
|
switch( no )
|
|
|
|
{
|
|
|
|
case STATUS_ENTER : s = "ENTER"; break;
|
|
|
|
case STATUS_LEAVE : s = "LEAVE"; break;
|
|
|
|
case STATUS_ABORT : s = "ABORT"; break;
|
|
|
|
case STATUS_NEWSIG : s = "NEWSIG"; break;
|
|
|
|
case STATUS_GOODSIG: s = "GOODSIG"; break;
|
|
|
|
case STATUS_KEYEXPIRED: s = "KEYEXPIRED"; break;
|
|
|
|
case STATUS_KEYREVOKED: s = "KEYREVOKED"; break;
|
|
|
|
case STATUS_BADSIG : s = "BADSIG"; break;
|
|
|
|
case STATUS_ERRSIG : s = "ERRSIG"; break;
|
|
|
|
case STATUS_BADARMOR : s = "BADARMOR"; break;
|
|
|
|
case STATUS_TRUST_UNDEFINED: s = "TRUST_UNDEFINED"; break;
|
|
|
|
case STATUS_TRUST_NEVER : s = "TRUST_NEVER"; break;
|
|
|
|
case STATUS_TRUST_MARGINAL : s = "TRUST_MARGINAL"; break;
|
|
|
|
case STATUS_TRUST_FULLY : s = "TRUST_FULLY"; break;
|
|
|
|
case STATUS_TRUST_ULTIMATE : s = "TRUST_ULTIMATE"; break;
|
|
|
|
case STATUS_GET_BOOL : s = "GET_BOOL"; break;
|
|
|
|
case STATUS_GET_LINE : s = "GET_LINE"; break;
|
|
|
|
case STATUS_GET_HIDDEN : s = "GET_HIDDEN"; break;
|
|
|
|
case STATUS_GOT_IT : s = "GOT_IT"; break;
|
|
|
|
case STATUS_SHM_INFO : s = "SHM_INFO"; break;
|
|
|
|
case STATUS_SHM_GET : s = "SHM_GET"; break;
|
|
|
|
case STATUS_SHM_GET_BOOL : s = "SHM_GET_BOOL"; break;
|
|
|
|
case STATUS_SHM_GET_HIDDEN : s = "SHM_GET_HIDDEN"; break;
|
|
|
|
case STATUS_NEED_PASSPHRASE: s = "NEED_PASSPHRASE"; break;
|
|
|
|
case STATUS_VALIDSIG : s = "VALIDSIG"; break;
|
|
|
|
case STATUS_SIG_ID : s = "SIG_ID"; break;
|
|
|
|
case STATUS_ENC_TO : s = "ENC_TO"; break;
|
|
|
|
case STATUS_NODATA : s = "NODATA"; break;
|
|
|
|
case STATUS_BAD_PASSPHRASE : s = "BAD_PASSPHRASE"; break;
|
|
|
|
case STATUS_NO_PUBKEY : s = "NO_PUBKEY"; break;
|
|
|
|
case STATUS_NO_SECKEY : s = "NO_SECKEY"; break;
|
|
|
|
case STATUS_NEED_PASSPHRASE_SYM: s = "NEED_PASSPHRASE_SYM"; break;
|
|
|
|
case STATUS_NEED_PASSPHRASE_PIN: s = "NEED_PASSPHRASE_PIN"; break;
|
|
|
|
case STATUS_DECRYPTION_FAILED: s = "DECRYPTION_FAILED"; break;
|
|
|
|
case STATUS_DECRYPTION_OKAY: s = "DECRYPTION_OKAY"; break;
|
|
|
|
case STATUS_MISSING_PASSPHRASE: s = "MISSING_PASSPHRASE"; break;
|
|
|
|
case STATUS_GOOD_PASSPHRASE : s = "GOOD_PASSPHRASE"; break;
|
|
|
|
case STATUS_GOODMDC : s = "GOODMDC"; break;
|
|
|
|
case STATUS_BADMDC : s = "BADMDC"; break;
|
|
|
|
case STATUS_ERRMDC : s = "ERRMDC"; break;
|
|
|
|
case STATUS_IMPORTED : s = "IMPORTED"; break;
|
|
|
|
case STATUS_IMPORT_OK : s = "IMPORT_OK"; break;
|
|
|
|
case STATUS_IMPORT_CHECK : s = "IMPORT_CHECK"; break;
|
|
|
|
case STATUS_IMPORT_RES : s = "IMPORT_RES"; break;
|
|
|
|
case STATUS_FILE_START : s = "FILE_START"; break;
|
|
|
|
case STATUS_FILE_DONE : s = "FILE_DONE"; break;
|
|
|
|
case STATUS_FILE_ERROR : s = "FILE_ERROR"; break;
|
|
|
|
case STATUS_BEGIN_DECRYPTION:s = "BEGIN_DECRYPTION"; break;
|
|
|
|
case STATUS_END_DECRYPTION : s = "END_DECRYPTION"; break;
|
|
|
|
case STATUS_BEGIN_ENCRYPTION:s = "BEGIN_ENCRYPTION"; break;
|
|
|
|
case STATUS_END_ENCRYPTION : s = "END_ENCRYPTION"; break;
|
|
|
|
case STATUS_DELETE_PROBLEM : s = "DELETE_PROBLEM"; break;
|
|
|
|
case STATUS_PROGRESS : s = "PROGRESS"; break;
|
|
|
|
case STATUS_SIG_CREATED : s = "SIG_CREATED"; break;
|
|
|
|
case STATUS_SESSION_KEY : s = "SESSION_KEY"; break;
|
|
|
|
case STATUS_NOTATION_NAME : s = "NOTATION_NAME" ; break;
|
|
|
|
case STATUS_NOTATION_DATA : s = "NOTATION_DATA" ; break;
|
|
|
|
case STATUS_POLICY_URL : s = "POLICY_URL" ; break;
|
|
|
|
case STATUS_BEGIN_STREAM : s = "BEGIN_STREAM"; break;
|
|
|
|
case STATUS_END_STREAM : s = "END_STREAM"; break;
|
|
|
|
case STATUS_KEY_CREATED : s = "KEY_CREATED"; break;
|
|
|
|
case STATUS_KEY_NOT_CREATED: s = "KEY_NOT_CREATED"; break;
|
|
|
|
case STATUS_USERID_HINT : s = "USERID_HINT"; break;
|
|
|
|
case STATUS_UNEXPECTED : s = "UNEXPECTED"; break;
|
|
|
|
case STATUS_INV_RECP : s = "INV_RECP"; break;
|
|
|
|
case STATUS_NO_RECP : s = "NO_RECP"; break;
|
|
|
|
case STATUS_ALREADY_SIGNED : s = "ALREADY_SIGNED"; break;
|
|
|
|
case STATUS_SIGEXPIRED : s = "SIGEXPIRED deprecated-use-keyexpired-instead"; break;
|
|
|
|
case STATUS_EXPSIG : s = "EXPSIG"; break;
|
|
|
|
case STATUS_EXPKEYSIG : s = "EXPKEYSIG"; break;
|
|
|
|
case STATUS_REVKEYSIG : s = "REVKEYSIG"; break;
|
|
|
|
case STATUS_ATTRIBUTE : s = "ATTRIBUTE"; break;
|
|
|
|
case STATUS_CARDCTRL : s = "CARDCTRL"; break;
|
|
|
|
case STATUS_PLAINTEXT : s = "PLAINTEXT"; break;
|
|
|
|
case STATUS_PLAINTEXT_LENGTH:s = "PLAINTEXT_LENGTH"; break;
|
|
|
|
case STATUS_SIG_SUBPACKET : s = "SIG_SUBPACKET"; break;
|
2005-03-07 13:59:59 +00:00
|
|
|
case STATUS_SC_OP_SUCCESS : s = "SC_OP_SUCCESS"; break;
|
|
|
|
case STATUS_SC_OP_FAILURE : s = "SC_OP_FAILURE"; break;
|
2005-03-14 19:19:21 +00:00
|
|
|
case STATUS_BACKUP_KEY_CREATED:s="BACKUP_KEY_CREATED"; break;
|
2005-12-20 20:19:16 +00:00
|
|
|
case STATUS_PKA_TRUST_BAD : s = "PKA_TRUST_BAD"; break;
|
|
|
|
case STATUS_PKA_TRUST_GOOD : s = "PKA_TRUST_GOOD"; break;
|
2006-04-03 10:13:23 +00:00
|
|
|
case STATUS_BEGIN_SIGNING : s = "BEGIN_SIGNING"; break;
|
2007-03-05 10:22:56 +00:00
|
|
|
case STATUS_ERROR : s = "ERROR"; break;
|
2012-01-13 16:20:53 +01:00
|
|
|
case STATUS_DECRYPTION_INFO: s = "DECRYPTION_INFO"; break;
|
2004-10-28 03:14:55 +00:00
|
|
|
default: s = "?"; break;
|
2002-06-29 13:46:34 +00:00
|
|
|
}
|
2004-10-28 03:14:55 +00:00
|
|
|
return s;
|
2002-06-29 13:46:34 +00:00
|
|
|
}
|
2000-07-14 17:34:53 +00:00
|
|
|
|
2004-05-20 18:04:33 +00:00
|
|
|
|
|
|
|
/* Return true if the status message NO may currently be issued. We
|
|
|
|
need this to avoid syncronisation problem while auto retrieving a
|
|
|
|
key. There it may happen that a status NODATA is issued for a non
|
|
|
|
available key and the user may falsely interpret this has a missing
|
|
|
|
signature. */
|
|
|
|
static int
|
|
|
|
status_currently_allowed (int no)
|
|
|
|
{
|
2004-05-22 11:33:47 +00:00
|
|
|
if (!glo_ctrl.in_auto_key_retrieve)
|
2004-05-20 18:04:33 +00:00
|
|
|
return 1; /* Yes. */
|
|
|
|
|
|
|
|
/* We allow some statis anyway, so that import statistics are
|
|
|
|
correct and to avoid problems if the retriebval subsystem will
|
|
|
|
prompt the user. */
|
|
|
|
switch (no)
|
|
|
|
{
|
2012-01-13 16:20:53 +01:00
|
|
|
case STATUS_GET_BOOL:
|
|
|
|
case STATUS_GET_LINE:
|
|
|
|
case STATUS_GET_HIDDEN:
|
|
|
|
case STATUS_GOT_IT:
|
2004-05-20 18:04:33 +00:00
|
|
|
case STATUS_IMPORTED:
|
2012-01-13 16:20:53 +01:00
|
|
|
case STATUS_IMPORT_OK:
|
|
|
|
case STATUS_IMPORT_CHECK:
|
2004-05-20 18:04:33 +00:00
|
|
|
case STATUS_IMPORT_RES:
|
|
|
|
return 1; /* Yes. */
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0; /* No. */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-01-30 16:23:16 +00:00
|
|
|
void
|
2002-06-29 13:46:34 +00:00
|
|
|
set_status_fd ( int fd )
|
1998-01-30 16:23:16 +00:00
|
|
|
{
|
2002-06-29 13:46:34 +00:00
|
|
|
static int last_fd = -1;
|
|
|
|
|
|
|
|
if ( fd != -1 && last_fd == fd )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( statusfp && statusfp != stdout && statusfp != stderr )
|
|
|
|
fclose (statusfp);
|
|
|
|
statusfp = NULL;
|
2012-01-13 16:20:53 +01:00
|
|
|
if ( fd == -1 )
|
2002-06-29 13:46:34 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if( fd == 1 )
|
|
|
|
statusfp = stdout;
|
|
|
|
else if( fd == 2 )
|
|
|
|
statusfp = stderr;
|
|
|
|
else
|
|
|
|
statusfp = fdopen( fd, "w" );
|
|
|
|
if( !statusfp ) {
|
|
|
|
log_fatal("can't open fd %d for status output: %s\n",
|
|
|
|
fd, strerror(errno));
|
2000-07-14 17:34:53 +00:00
|
|
|
}
|
2002-06-29 13:46:34 +00:00
|
|
|
last_fd = fd;
|
|
|
|
register_primegen_progress ( progress_cb, "primegen" );
|
|
|
|
register_pk_dsa_progress ( progress_cb, "pk_dsa" );
|
|
|
|
register_pk_elg_progress ( progress_cb, "pk_elg" );
|
1998-01-30 16:23:16 +00:00
|
|
|
}
|
|
|
|
|
1999-01-09 15:06:59 +00:00
|
|
|
int
|
|
|
|
is_status_enabled()
|
|
|
|
{
|
2002-06-29 13:46:34 +00:00
|
|
|
return !!statusfp;
|
1999-01-09 15:06:59 +00:00
|
|
|
}
|
1998-01-30 16:23:16 +00:00
|
|
|
|
|
|
|
void
|
1998-07-31 16:45:58 +00:00
|
|
|
write_status ( int no )
|
1998-03-09 21:44:06 +00:00
|
|
|
{
|
|
|
|
write_status_text( no, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-07-31 16:45:58 +00:00
|
|
|
write_status_text ( int no, const char *text)
|
1998-01-30 16:23:16 +00:00
|
|
|
{
|
2004-05-20 18:04:33 +00:00
|
|
|
if( !statusfp || !status_currently_allowed (no) )
|
|
|
|
return; /* Not enabled or allowed. */
|
1998-01-30 16:23:16 +00:00
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
fputs ( "[GNUPG:] ", statusfp );
|
|
|
|
fputs ( get_status_string (no), statusfp );
|
|
|
|
if( text ) {
|
|
|
|
putc ( ' ', statusfp );
|
|
|
|
for (; *text; text++) {
|
|
|
|
if (*text == '\n')
|
|
|
|
fputs ( "\\n", statusfp );
|
|
|
|
else if (*text == '\r')
|
|
|
|
fputs ( "\\r", statusfp );
|
2012-01-13 16:20:53 +01:00
|
|
|
else
|
2002-06-29 13:46:34 +00:00
|
|
|
putc ( *(const byte *)text, statusfp );
|
|
|
|
}
|
1998-01-30 16:23:16 +00:00
|
|
|
}
|
2002-06-29 13:46:34 +00:00
|
|
|
putc ('\n',statusfp);
|
2005-07-22 16:28:40 +00:00
|
|
|
if ( fflush (statusfp) && opt.exit_on_status_write_error )
|
|
|
|
g10_exit (0);
|
2002-06-29 13:46:34 +00:00
|
|
|
}
|
1998-01-30 16:23:16 +00:00
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write a status line with a buffer using %XX escapes. If WRAP is >
|
|
|
|
* 0 wrap the line after this length. If STRING is not NULL it will
|
|
|
|
* be prepended to the buffer, no escaping is done for string.
|
|
|
|
* A wrap of -1 forces spaces not to be encoded as %20.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
write_status_text_and_buffer ( int no, const char *string,
|
|
|
|
const char *buffer, size_t len, int wrap )
|
|
|
|
{
|
|
|
|
const char *s, *text;
|
|
|
|
int esc, first;
|
|
|
|
int lower_limit = ' ';
|
|
|
|
size_t n, count, dowrap;
|
|
|
|
|
2004-05-20 18:04:33 +00:00
|
|
|
if( !statusfp || !status_currently_allowed (no) )
|
|
|
|
return; /* Not enabled or allowed. */
|
2012-01-13 16:20:53 +01:00
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
if (wrap == -1) {
|
|
|
|
lower_limit--;
|
|
|
|
wrap = 0;
|
1998-03-09 21:44:06 +00:00
|
|
|
}
|
2002-06-29 13:46:34 +00:00
|
|
|
|
|
|
|
text = get_status_string (no);
|
|
|
|
count = dowrap = first = 1;
|
|
|
|
do {
|
|
|
|
if (dowrap) {
|
|
|
|
fprintf (statusfp, "[GNUPG:] %s ", text );
|
|
|
|
count = dowrap = 0;
|
|
|
|
if (first && string) {
|
|
|
|
fputs (string, statusfp);
|
|
|
|
count += strlen (string);
|
|
|
|
}
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
for (esc=0, s=buffer, n=len; n && !esc; s++, n-- ) {
|
2012-01-13 16:20:53 +01:00
|
|
|
if ( *s == '%' || *(const byte*)s <= lower_limit
|
|
|
|
|| *(const byte*)s == 127 )
|
2002-06-29 13:46:34 +00:00
|
|
|
esc = 1;
|
|
|
|
if ( wrap && ++count > wrap ) {
|
|
|
|
dowrap=1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (esc) {
|
|
|
|
s--; n++;
|
|
|
|
}
|
2012-01-13 16:20:53 +01:00
|
|
|
if (s != buffer)
|
2002-06-29 13:46:34 +00:00
|
|
|
fwrite (buffer, s-buffer, 1, statusfp );
|
|
|
|
if ( esc ) {
|
|
|
|
fprintf (statusfp, "%%%02X", *(const byte*)s );
|
|
|
|
s++; n--;
|
|
|
|
}
|
|
|
|
buffer = s;
|
|
|
|
len = n;
|
|
|
|
if ( dowrap && len )
|
|
|
|
putc ( '\n', statusfp );
|
|
|
|
} while ( len );
|
|
|
|
|
|
|
|
putc ('\n',statusfp);
|
2005-07-22 16:28:40 +00:00
|
|
|
if ( fflush (statusfp) && opt.exit_on_status_write_error )
|
|
|
|
g10_exit (0);
|
1998-01-30 16:23:16 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
void
|
|
|
|
write_status_buffer ( int no, const char *buffer, size_t len, int wrap )
|
|
|
|
{
|
|
|
|
write_status_text_and_buffer (no, NULL, buffer, len, wrap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-07-31 16:45:58 +00:00
|
|
|
#ifdef USE_SHM_COPROCESSING
|
1998-09-14 15:49:56 +00:00
|
|
|
|
|
|
|
#ifndef IPC_RMID_DEFERRED_RELEASE
|
|
|
|
static void
|
|
|
|
remove_shmid( void )
|
|
|
|
{
|
|
|
|
if( shm_id != -1 ) {
|
|
|
|
shmctl ( shm_id, IPC_RMID, 0);
|
|
|
|
shm_id = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-07-31 16:45:58 +00:00
|
|
|
void
|
|
|
|
init_shm_coprocessing ( ulong requested_shm_size, int lock_mem )
|
|
|
|
{
|
|
|
|
char buf[100];
|
1998-09-14 15:49:56 +00:00
|
|
|
struct shmid_ds shmds;
|
1998-07-31 16:45:58 +00:00
|
|
|
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#ifndef IPC_RMID_DEFERRED_RELEASE
|
1998-09-14 15:49:56 +00:00
|
|
|
atexit( remove_shmid );
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#endif
|
1998-07-31 16:45:58 +00:00
|
|
|
requested_shm_size = (requested_shm_size + 4095) & ~4095;
|
|
|
|
if ( requested_shm_size > 2 * 4096 )
|
|
|
|
log_fatal("too much shared memory requested; only 8k are allowed\n");
|
|
|
|
shm_size = 4096 /* one page for us */ + requested_shm_size;
|
|
|
|
|
1998-08-05 16:51:59 +00:00
|
|
|
shm_id = shmget( IPC_PRIVATE, shm_size, IPC_CREAT | 0700 );
|
1998-07-31 16:45:58 +00:00
|
|
|
if ( shm_id == -1 )
|
|
|
|
log_fatal("can't get %uk of shared memory: %s\n",
|
|
|
|
(unsigned)shm_size/1024, strerror(errno));
|
2000-07-14 17:34:53 +00:00
|
|
|
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#if !defined(IPC_HAVE_SHM_LOCK) \
|
2000-07-14 17:34:53 +00:00
|
|
|
&& defined(HAVE_MLOCK) && !defined(HAVE_BROKEN_MLOCK)
|
|
|
|
/* part of the old code which uses mlock */
|
1998-07-31 16:45:58 +00:00
|
|
|
shm_area = shmat( shm_id, 0, 0 );
|
|
|
|
if ( shm_area == (char*)-1 )
|
|
|
|
log_fatal("can't attach %uk shared memory: %s\n",
|
|
|
|
(unsigned)shm_size/1024, strerror(errno));
|
1998-11-10 12:59:59 +00:00
|
|
|
log_debug("mapped %uk shared memory at %p, id=%d\n",
|
1998-07-31 16:45:58 +00:00
|
|
|
(unsigned)shm_size/1024, shm_area, shm_id );
|
|
|
|
if( lock_mem ) {
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#ifdef USE_CAPABILITIES
|
1999-06-29 19:50:54 +00:00
|
|
|
cap_set_proc( cap_from_text("cap_ipc_lock+ep") );
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#endif
|
1998-12-10 19:20:47 +00:00
|
|
|
/* (need the cast for Solaris with Sun's workshop compilers) */
|
|
|
|
if ( mlock ( (char*)shm_area, shm_size) )
|
1998-09-28 19:25:31 +00:00
|
|
|
log_info("locking shared memory %d failed: %s\n",
|
|
|
|
shm_id, strerror(errno));
|
|
|
|
else
|
|
|
|
shm_is_locked = 1;
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#ifdef USE_CAPABILITIES
|
1999-06-29 19:50:54 +00:00
|
|
|
cap_set_proc( cap_from_text("cap_ipc_lock+p") );
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#endif
|
1998-07-31 16:45:58 +00:00
|
|
|
}
|
|
|
|
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#ifdef IPC_RMID_DEFERRED_RELEASE
|
1998-09-14 15:49:56 +00:00
|
|
|
if( shmctl( shm_id, IPC_RMID, 0) )
|
1998-07-31 16:45:58 +00:00
|
|
|
log_fatal("shmctl IPC_RMDID of %d failed: %s\n",
|
|
|
|
shm_id, strerror(errno));
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#endif
|
1998-07-31 16:45:58 +00:00
|
|
|
|
1998-09-14 15:49:56 +00:00
|
|
|
if( shmctl( shm_id, IPC_STAT, &shmds ) )
|
|
|
|
log_fatal("shmctl IPC_STAT of %d failed: %s\n",
|
|
|
|
shm_id, strerror(errno));
|
|
|
|
if( shmds.shm_perm.uid != getuid() ) {
|
|
|
|
shmds.shm_perm.uid = getuid();
|
|
|
|
if( shmctl( shm_id, IPC_SET, &shmds ) )
|
|
|
|
log_fatal("shmctl IPC_SET of %d failed: %s\n",
|
|
|
|
shm_id, strerror(errno));
|
|
|
|
}
|
|
|
|
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#else /* this is the new code which handles the changes in the SHM
|
|
|
|
* semantics introduced with Linux 2.4. The changes is that we
|
|
|
|
* now change the permissions and then attach to the memory.
|
|
|
|
*/
|
2000-07-14 17:34:53 +00:00
|
|
|
|
|
|
|
if( lock_mem ) {
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#ifdef USE_CAPABILITIES
|
2000-07-14 17:34:53 +00:00
|
|
|
cap_set_proc( cap_from_text("cap_ipc_lock+ep") );
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef IPC_HAVE_SHM_LOCK
|
2000-07-14 17:34:53 +00:00
|
|
|
if ( shmctl (shm_id, SHM_LOCK, 0) )
|
|
|
|
log_info("locking shared memory %d failed: %s\n",
|
|
|
|
shm_id, strerror(errno));
|
|
|
|
else
|
|
|
|
shm_is_locked = 1;
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#else
|
2000-07-14 17:34:53 +00:00
|
|
|
log_info("Locking shared memory %d failed: No way to do it\n", shm_id );
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USE_CAPABILITIES
|
2000-07-14 17:34:53 +00:00
|
|
|
cap_set_proc( cap_from_text("cap_ipc_lock+p") );
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#endif
|
2000-07-14 17:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( shmctl( shm_id, IPC_STAT, &shmds ) )
|
|
|
|
log_fatal("shmctl IPC_STAT of %d failed: %s\n",
|
|
|
|
shm_id, strerror(errno));
|
|
|
|
if( shmds.shm_perm.uid != getuid() ) {
|
|
|
|
shmds.shm_perm.uid = getuid();
|
|
|
|
if( shmctl( shm_id, IPC_SET, &shmds ) )
|
|
|
|
log_fatal("shmctl IPC_SET of %d failed: %s\n",
|
|
|
|
shm_id, strerror(errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
shm_area = shmat( shm_id, 0, 0 );
|
|
|
|
if ( shm_area == (char*)-1 )
|
|
|
|
log_fatal("can't attach %uk shared memory: %s\n",
|
|
|
|
(unsigned)shm_size/1024, strerror(errno));
|
|
|
|
log_debug("mapped %uk shared memory at %p, id=%d\n",
|
|
|
|
(unsigned)shm_size/1024, shm_area, shm_id );
|
|
|
|
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#ifdef IPC_RMID_DEFERRED_RELEASE
|
2000-07-14 17:34:53 +00:00
|
|
|
if( shmctl( shm_id, IPC_RMID, 0) )
|
|
|
|
log_fatal("shmctl IPC_RMDID of %d failed: %s\n",
|
|
|
|
shm_id, strerror(errno));
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#endif
|
2000-07-14 17:34:53 +00:00
|
|
|
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#endif
|
1998-07-31 16:45:58 +00:00
|
|
|
/* write info; Protocol version, id, size, locked size */
|
|
|
|
sprintf( buf, "pv=1 pid=%d shmid=%d sz=%u lz=%u", (int)getpid(),
|
|
|
|
shm_id, (unsigned)shm_size, shm_is_locked? (unsigned)shm_size:0 );
|
|
|
|
write_status_text( STATUS_SHM_INFO, buf );
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************
|
|
|
|
* Request a string from client
|
2007-11-12 15:52:01 +00:00
|
|
|
* If GETBOOL, returns static string on true (do not free) or NULL for false
|
1998-07-31 16:45:58 +00:00
|
|
|
*/
|
|
|
|
static char *
|
2007-11-12 15:52:01 +00:00
|
|
|
do_shm_get( const char *keyword, int hidden, int getbool )
|
1998-07-31 16:45:58 +00:00
|
|
|
{
|
|
|
|
size_t n;
|
|
|
|
byte *p;
|
|
|
|
char *string;
|
|
|
|
|
|
|
|
if( !shm_area )
|
|
|
|
BUG();
|
|
|
|
|
|
|
|
shm_area[0] = 0; /* msb of length of control block */
|
|
|
|
shm_area[1] = 32; /* and lsb */
|
|
|
|
shm_area[2] = 1; /* indicate that we are waiting on a reply */
|
|
|
|
shm_area[3] = 0; /* clear data available flag */
|
|
|
|
|
2007-11-12 15:52:01 +00:00
|
|
|
write_status_text( getbool? STATUS_SHM_GET_BOOL :
|
1998-07-31 16:45:58 +00:00
|
|
|
hidden? STATUS_SHM_GET_HIDDEN : STATUS_SHM_GET, keyword );
|
|
|
|
|
|
|
|
do {
|
|
|
|
pause_on_sigusr(1);
|
|
|
|
if( shm_area[0] || shm_area[1] != 32 || shm_area[2] != 1 )
|
|
|
|
log_fatal("client modified shm control block - abort\n");
|
|
|
|
} while( !shm_area[3] );
|
|
|
|
shm_area[2] = 0; /* reset request flag */
|
|
|
|
p = (byte*)shm_area+32;
|
|
|
|
n = p[0] << 8 | p[1];
|
|
|
|
p += 2;
|
|
|
|
if( n+32+2+1 > 4095 )
|
|
|
|
log_fatal("client returns too large data (%u bytes)\n", (unsigned)n );
|
|
|
|
|
2007-11-12 15:52:01 +00:00
|
|
|
if( getbool )
|
1998-07-31 16:45:58 +00:00
|
|
|
return p[0]? "" : NULL;
|
|
|
|
|
2005-07-27 18:10:56 +00:00
|
|
|
string = hidden? xmalloc_secure( n+1 ) : xmalloc( n+1 );
|
1998-07-31 16:45:58 +00:00
|
|
|
memcpy(string, p, n );
|
|
|
|
string[n] = 0; /* make sure it is a string */
|
|
|
|
if( hidden ) /* invalidate the memory */
|
|
|
|
memset( p, 0, n );
|
|
|
|
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* USE_SHM_COPROCESSING */
|
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
static int
|
|
|
|
myread(int fd, void *buf, size_t count)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
do {
|
|
|
|
rc = read( fd, buf, count );
|
|
|
|
} while ( rc == -1 && errno == EINTR );
|
|
|
|
if ( !rc && count ) {
|
|
|
|
static int eof_emmited=0;
|
|
|
|
if ( eof_emmited < 3 ) {
|
|
|
|
*(char*)buf = CONTROL_D;
|
|
|
|
rc = 1;
|
|
|
|
eof_emmited++;
|
|
|
|
}
|
|
|
|
else { /* Ctrl-D not caught - do something reasonable */
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#ifdef HAVE_DOSISH_SYSTEM
|
2002-06-29 13:46:34 +00:00
|
|
|
raise (SIGINT); /* nothing to hangup under DOS */
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#else
|
2002-06-29 13:46:34 +00:00
|
|
|
raise (SIGHUP); /* no more input data */
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#endif
|
2002-06-29 13:46:34 +00:00
|
|
|
}
|
2012-01-13 16:20:53 +01:00
|
|
|
}
|
2002-06-29 13:46:34 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-08 19:27:00 +00:00
|
|
|
|
2000-07-14 17:34:53 +00:00
|
|
|
/****************
|
|
|
|
* Request a string from the client over the command-fd
|
2007-11-12 15:52:01 +00:00
|
|
|
* If getbool, returns static string on true (do not free) or NULL for false
|
2000-07-14 17:34:53 +00:00
|
|
|
*/
|
|
|
|
static char *
|
2007-11-12 15:52:01 +00:00
|
|
|
do_get_from_fd( const char *keyword, int hidden, int getbool )
|
2000-07-14 17:34:53 +00:00
|
|
|
{
|
|
|
|
int i, len;
|
|
|
|
char *string;
|
|
|
|
|
2004-08-08 13:28:04 +00:00
|
|
|
if(statusfp!=stdout)
|
|
|
|
fflush(stdout);
|
|
|
|
|
2007-11-12 15:52:01 +00:00
|
|
|
write_status_text( getbool? STATUS_GET_BOOL :
|
2000-07-14 17:34:53 +00:00
|
|
|
hidden? STATUS_GET_HIDDEN : STATUS_GET_LINE, keyword );
|
|
|
|
|
|
|
|
for( string = NULL, i = len = 200; ; i++ ) {
|
|
|
|
if( i >= len-1 ) {
|
|
|
|
char *save = string;
|
|
|
|
len += 100;
|
2005-07-27 18:10:56 +00:00
|
|
|
string = hidden? xmalloc_secure ( len ) : xmalloc ( len );
|
2000-07-14 17:34:53 +00:00
|
|
|
if( save )
|
|
|
|
memcpy(string, save, i );
|
|
|
|
else
|
|
|
|
i=0;
|
|
|
|
}
|
|
|
|
/* Hmmm: why not use our read_line function here */
|
2002-06-29 13:46:34 +00:00
|
|
|
if( myread( opt.command_fd, string+i, 1) != 1 || string[i] == '\n' )
|
|
|
|
break;
|
|
|
|
else if ( string[i] == CONTROL_D ) {
|
|
|
|
/* found ETX - cancel the line and return a sole ETX */
|
|
|
|
string[0] = CONTROL_D;
|
|
|
|
i=1;
|
|
|
|
break;
|
|
|
|
}
|
2000-07-14 17:34:53 +00:00
|
|
|
}
|
|
|
|
string[i] = 0;
|
|
|
|
|
|
|
|
write_status( STATUS_GOT_IT );
|
|
|
|
|
2007-11-12 15:52:01 +00:00
|
|
|
if( getbool ) /* Fixme: is this correct??? */
|
2003-03-24 20:05:53 +00:00
|
|
|
return (string[0] == 'Y' || string[0] == 'y') ? "" : NULL;
|
2000-07-14 17:34:53 +00:00
|
|
|
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-07-31 16:45:58 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
cpr_enabled()
|
|
|
|
{
|
2000-07-14 17:34:53 +00:00
|
|
|
if( opt.command_fd != -1 )
|
|
|
|
return 1;
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#ifdef USE_SHM_COPROCESSING
|
1998-07-31 16:45:58 +00:00
|
|
|
if( opt.shm_coprocess )
|
|
|
|
return 1;
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#endif
|
1998-07-31 16:45:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
char *
|
|
|
|
cpr_get_no_help( const char *keyword, const char *prompt )
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if( opt.command_fd != -1 )
|
|
|
|
return do_get_from_fd ( keyword, 0, 0 );
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#ifdef USE_SHM_COPROCESSING
|
2002-06-29 13:46:34 +00:00
|
|
|
if( opt.shm_coprocess )
|
|
|
|
return do_shm_get( keyword, 0, 0 );
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#endif
|
2002-06-29 13:46:34 +00:00
|
|
|
for(;;) {
|
|
|
|
p = tty_get( prompt );
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-31 16:45:58 +00:00
|
|
|
char *
|
|
|
|
cpr_get( const char *keyword, const char *prompt )
|
|
|
|
{
|
1998-08-08 19:27:00 +00:00
|
|
|
char *p;
|
|
|
|
|
2000-07-14 17:34:53 +00:00
|
|
|
if( opt.command_fd != -1 )
|
|
|
|
return do_get_from_fd ( keyword, 0, 0 );
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#ifdef USE_SHM_COPROCESSING
|
1998-07-31 16:45:58 +00:00
|
|
|
if( opt.shm_coprocess )
|
|
|
|
return do_shm_get( keyword, 0, 0 );
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#endif
|
1998-08-08 19:27:00 +00:00
|
|
|
for(;;) {
|
|
|
|
p = tty_get( prompt );
|
1999-06-29 19:50:54 +00:00
|
|
|
if( *p=='?' && !p[1] && !(keyword && !*keyword)) {
|
2005-07-27 18:10:56 +00:00
|
|
|
xfree(p);
|
1998-11-27 11:42:49 +00:00
|
|
|
display_online_help( keyword );
|
1998-08-08 19:27:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return p;
|
|
|
|
}
|
1998-07-31 16:45:58 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 13:46:34 +00:00
|
|
|
|
1998-11-10 12:59:59 +00:00
|
|
|
char *
|
|
|
|
cpr_get_utf8( const char *keyword, const char *prompt )
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
p = cpr_get( keyword, prompt );
|
|
|
|
if( p ) {
|
|
|
|
char *utf8 = native_to_utf8( p );
|
2005-07-27 18:10:56 +00:00
|
|
|
xfree( p );
|
1998-11-10 12:59:59 +00:00
|
|
|
p = utf8;
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
1998-07-31 16:45:58 +00:00
|
|
|
char *
|
|
|
|
cpr_get_hidden( const char *keyword, const char *prompt )
|
|
|
|
{
|
1998-08-08 19:27:00 +00:00
|
|
|
char *p;
|
|
|
|
|
2000-07-14 17:34:53 +00:00
|
|
|
if( opt.command_fd != -1 )
|
|
|
|
return do_get_from_fd ( keyword, 1, 0 );
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#ifdef USE_SHM_COPROCESSING
|
1998-07-31 16:45:58 +00:00
|
|
|
if( opt.shm_coprocess )
|
|
|
|
return do_shm_get( keyword, 1, 0 );
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#endif
|
1998-08-08 19:27:00 +00:00
|
|
|
for(;;) {
|
|
|
|
p = tty_get_hidden( prompt );
|
|
|
|
if( *p == '?' && !p[1] ) {
|
2005-07-27 18:10:56 +00:00
|
|
|
xfree(p);
|
1998-11-27 11:42:49 +00:00
|
|
|
display_online_help( keyword );
|
1998-08-08 19:27:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return p;
|
|
|
|
}
|
1998-07-31 16:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cpr_kill_prompt(void)
|
|
|
|
{
|
2000-07-14 17:34:53 +00:00
|
|
|
if( opt.command_fd != -1 )
|
|
|
|
return;
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#ifdef USE_SHM_COPROCESSING
|
1998-07-31 16:45:58 +00:00
|
|
|
if( opt.shm_coprocess )
|
|
|
|
return;
|
* armor.c, g10.c, kbnode.c, misc.c, pkclist.c, sign.c, build-packet.c,
getkey.c, keydb.c, openfile.c, plaintext.c, status.c, gpgv.c, keygen.c,
options.h, sig-check.c, tdbio.h, encode.c, mainproc.c, parse-packet.c,
signal.c, textfilter.c: Edit all preprocessor instructions to remove
whitespace before the '#'. This is not required by C89, but there are some
compilers out there that don't like it.
2003-05-24 21:50:33 +00:00
|
|
|
#endif
|
1998-12-10 19:20:47 +00:00
|
|
|
tty_kill_prompt();
|
|
|
|
return;
|
1998-07-31 16:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cpr_get_answer_is_yes( const char *keyword, const char *prompt )
|
|
|
|
{
|
1998-08-11 17:29:34 +00:00
|
|
|
int yes;
|
|
|
|
char *p;
|
|
|
|
|
2000-07-14 17:34:53 +00:00
|
|
|
if( opt.command_fd != -1 )
|
|
|
|
return !!do_get_from_fd ( keyword, 0, 1 );
|
2002-08-19 08:28:00 +00:00
|
|
|
#ifdef USE_SHM_COPROCESSING
|
1998-07-31 16:45:58 +00:00
|
|
|
if( opt.shm_coprocess )
|
|
|
|
return !!do_shm_get( keyword, 0, 1 );
|
2002-08-19 08:28:00 +00:00
|
|
|
#endif
|
1998-08-11 17:29:34 +00:00
|
|
|
for(;;) {
|
|
|
|
p = tty_get( prompt );
|
|
|
|
trim_spaces(p); /* it is okay to do this here */
|
|
|
|
if( *p == '?' && !p[1] ) {
|
2005-07-27 18:10:56 +00:00
|
|
|
xfree(p);
|
1998-11-27 11:42:49 +00:00
|
|
|
display_online_help( keyword );
|
1998-08-11 17:29:34 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
tty_kill_prompt();
|
|
|
|
yes = answer_is_yes(p);
|
2005-07-27 18:10:56 +00:00
|
|
|
xfree(p);
|
1998-08-11 17:29:34 +00:00
|
|
|
return yes;
|
|
|
|
}
|
|
|
|
}
|
1998-07-31 16:45:58 +00:00
|
|
|
}
|
|
|
|
|
1999-05-27 07:45:46 +00:00
|
|
|
int
|
|
|
|
cpr_get_answer_yes_no_quit( const char *keyword, const char *prompt )
|
|
|
|
{
|
|
|
|
int yes;
|
|
|
|
char *p;
|
|
|
|
|
2000-07-14 17:34:53 +00:00
|
|
|
if( opt.command_fd != -1 )
|
|
|
|
return !!do_get_from_fd ( keyword, 0, 1 );
|
2002-08-19 08:28:00 +00:00
|
|
|
#ifdef USE_SHM_COPROCESSING
|
1999-05-27 07:45:46 +00:00
|
|
|
if( opt.shm_coprocess )
|
|
|
|
return !!do_shm_get( keyword, 0, 1 );
|
2002-08-19 08:28:00 +00:00
|
|
|
#endif
|
1999-05-27 07:45:46 +00:00
|
|
|
for(;;) {
|
|
|
|
p = tty_get( prompt );
|
|
|
|
trim_spaces(p); /* it is okay to do this here */
|
|
|
|
if( *p == '?' && !p[1] ) {
|
2005-07-27 18:10:56 +00:00
|
|
|
xfree(p);
|
1999-05-27 07:45:46 +00:00
|
|
|
display_online_help( keyword );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tty_kill_prompt();
|
|
|
|
yes = answer_is_yes_no_quit(p);
|
2005-07-27 18:10:56 +00:00
|
|
|
xfree(p);
|
1999-05-27 07:45:46 +00:00
|
|
|
return yes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-10-29 10:07:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
cpr_get_answer_okay_cancel (const char *keyword,
|
|
|
|
const char *prompt,
|
|
|
|
int def_answer)
|
|
|
|
{
|
|
|
|
int yes;
|
|
|
|
char *answer = NULL;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if( opt.command_fd != -1 )
|
|
|
|
answer = do_get_from_fd ( keyword, 0, 0 );
|
|
|
|
#ifdef USE_SHM_COPROCESSING
|
|
|
|
else if( opt.shm_coprocess )
|
|
|
|
answer = do_shm_get( keyword, 0, 0 );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (answer)
|
|
|
|
{
|
|
|
|
yes = answer_is_okay_cancel (answer, def_answer);
|
2005-07-27 18:10:56 +00:00
|
|
|
xfree (answer);
|
2003-10-29 10:07:44 +00:00
|
|
|
return yes;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
p = tty_get( prompt );
|
|
|
|
trim_spaces(p); /* it is okay to do this here */
|
|
|
|
if (*p == '?' && !p[1])
|
|
|
|
{
|
2005-07-27 18:10:56 +00:00
|
|
|
xfree(p);
|
2003-10-29 10:07:44 +00:00
|
|
|
display_online_help (keyword);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tty_kill_prompt();
|
|
|
|
yes = answer_is_okay_cancel (p, def_answer);
|
2005-07-27 18:10:56 +00:00
|
|
|
xfree(p);
|
2003-10-29 10:07:44 +00:00
|
|
|
return yes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|