1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-01-10 13:04:23 +01:00

Mainly changes to the pipe handling under W32

This commit is contained in:
Werner Koch 2000-12-06 12:06:19 +00:00
parent 41913b7f01
commit bb1bab488f
9 changed files with 143 additions and 108 deletions

1
THANKS
View File

@ -111,6 +111,7 @@ N J Doye nic@niss.ac.uk
Oliver Haakert haakert@hsp.de Oliver Haakert haakert@hsp.de
Oskari Jääskeläinen f33003a@cc.hut.fi Oskari Jääskeläinen f33003a@cc.hut.fi
Paul D. Smith psmith@baynetworks.com Paul D. Smith psmith@baynetworks.com
Per Cederqvist ceder@lysator.liu.se
Philippe Laliberte arsphl@oeil.qc.ca Philippe Laliberte arsphl@oeil.qc.ca
Peter Gutmann pgut001@cs.auckland.ac.nz Peter Gutmann pgut001@cs.auckland.ac.nz
Peter Marschall Peter.Marschall@gedos.de Peter Marschall Peter.Marschall@gedos.de

View File

@ -1,8 +1,25 @@
2000-12-05 Werner Koch <wk@gnupg.org>
* cipher.c (cipher_filter): Moved the end_encryption status ...
* encode.c (encode_simple,encode_crypt): to here
* sign.c (sign_file): and here.
* status.c (mywrite): Removed.
(get_status_string): Removed the LFs from the strings.
(set_status_fd,is_status_enabed,write_status_text,
write_status_buffer): Replaced all mywrite by stdio calls and use
fdopen to create a strem. This is needed to make things smoother
in the W32 version.
2000-12-04 Werner Koch <wk@gnupg.org>
* import.c (merge_blocks): Increment n_sigs for revocations.
2000-11-30 Werner Koch <wk@gnupg.org> 2000-11-30 Werner Koch <wk@gnupg.org>
* g10.c (main): Use iobuf_translate_file_handle for all options * g10.c (main): Use iobuf_translate_file_handle for all options
with filehandles as arguments. This is function does some magic with filehandles as arguments. This is function does some magic
some for the W32 API. for the W32 API.
* verify.c (verify_signatures): Add a comment rant about the * verify.c (verify_signatures): Add a comment rant about the
detached signature problem. detached signature problem.

View File

@ -141,7 +141,6 @@ cipher_filter( void *opaque, int control,
log_error("writing MDC packet failed\n" ); log_error("writing MDC packet failed\n" );
} }
cipher_close(cfx->cipher_hd); cipher_close(cfx->cipher_hd);
write_status( STATUS_END_ENCRYPTION );
} }
else if( control == IOBUFCTRL_DESC ) { else if( control == IOBUFCTRL_DESC ) {
*(char**)buf = "cipher_filter"; *(char**)buf = "cipher_filter";

View File

@ -36,7 +36,7 @@
#include "filter.h" #include "filter.h"
#include "trustdb.h" #include "trustdb.h"
#include "i18n.h" #include "i18n.h"
#include "status.h"
static int encode_simple( const char *filename, int mode ); static int encode_simple( const char *filename, int mode );
static int write_pubkey_enc_from_list( PK_LIST pk_list, DEK *dek, IOBUF out ); static int write_pubkey_enc_from_list( PK_LIST pk_list, DEK *dek, IOBUF out );
@ -221,8 +221,11 @@ encode_simple( const char *filename, int mode )
iobuf_close(inp); iobuf_close(inp);
if (rc) if (rc)
iobuf_cancel(out); iobuf_cancel(out);
else else {
iobuf_close(out); /* fixme: check returncode */ iobuf_close(out); /* fixme: check returncode */
if (mode)
write_status( STATUS_END_ENCRYPTION );
}
if (pt) if (pt)
pt->buf = NULL; pt->buf = NULL;
free_packet(&pkt); free_packet(&pkt);
@ -323,7 +326,7 @@ encode_crypt( const char *filename, STRLIST remusr )
if( !(filesize = iobuf_get_filelength(inp)) ) if( !(filesize = iobuf_get_filelength(inp)) )
log_info(_("%s: WARNING: empty file\n"), filename ); log_info(_("%s: WARNING: empty file\n"), filename );
/* we can't yet encode the length of very large files, /* we can't yet encode the length of very large files,
* so we switch to partial lengthn encoding in this case */ * so we switch to partial length encoding in this case */
if ( filesize >= IOBUF_FILELENGTH_LIMIT ) if ( filesize >= IOBUF_FILELENGTH_LIMIT )
filesize = 0; filesize = 0;
} }
@ -381,8 +384,10 @@ encode_crypt( const char *filename, STRLIST remusr )
iobuf_close(inp); iobuf_close(inp);
if( rc ) if( rc )
iobuf_cancel(out); iobuf_cancel(out);
else else {
iobuf_close(out); /* fixme: check returncode */ iobuf_close(out); /* fixme: check returncode */
write_status( STATUS_END_ENCRYPTION );
}
if( pt ) if( pt )
pt->buf = NULL; pt->buf = NULL;
free_packet(&pkt); free_packet(&pkt);

View File

@ -677,7 +677,7 @@ main( int argc, char **argv )
else if ( pargs.r_opt == oStatusFD ) { else if ( pargs.r_opt == oStatusFD ) {
/* this is needed to ensure that the status-fd filedescriptor is /* this is needed to ensure that the status-fd filedescriptor is
* initialized when init_shm_coprocessing() is called */ * initialized when init_shm_coprocessing() is called */
set_status_fd( pargs.r.ret_int ); set_status_fd( iobuf_translate_file_handle (pargs.r.ret_int, 1) );
} }
#endif #endif
} }
@ -1594,7 +1594,6 @@ g10_exit( int rc )
secmem_term(); secmem_term();
rc = rc? rc : log_get_errorcount(0)? 2 : rc = rc? rc : log_get_errorcount(0)? 2 :
g10_errors_seen? 1 : 0; g10_errors_seen? 1 : 0;
/*write_status( STATUS_LEAVE );*/
exit(rc ); exit(rc );
} }

View File

@ -1057,6 +1057,7 @@ merge_blocks( const char *fname, KBNODE keyblock_orig, KBNODE keyblock,
KBNODE n2 = clone_kbnode(node); KBNODE n2 = clone_kbnode(node);
insert_kbnode( keyblock_orig, n2, 0 ); insert_kbnode( keyblock_orig, n2, 0 );
n2->flag |= 1; n2->flag |= 1;
++*n_sigs;
log_info( _("key %08lX: revocation certificate added\n"), log_info( _("key %08lX: revocation certificate added\n"),
(ulong)keyid[1]); (ulong)keyid[1]);
} }

View File

@ -562,8 +562,11 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr,
leave: leave:
if( rc ) if( rc )
iobuf_cancel(out); iobuf_cancel(out);
else else {
iobuf_close(out); iobuf_close(out);
if (encrypt)
write_status( STATUS_END_ENCRYPTION );
}
iobuf_close(inp); iobuf_close(inp);
md_close( mfx.md ); md_close( mfx.md );
release_sk_list( sk_list ); release_sk_list( sk_list );

View File

@ -51,7 +51,8 @@
static int fd = -1; static FILE *statusfp;
#ifdef USE_SHM_COPROCESSING #ifdef USE_SHM_COPROCESSING
static int shm_id = -1; static int shm_id = -1;
static volatile char *shm_area; static volatile char *shm_area;
@ -78,81 +79,100 @@ get_status_string ( int no )
const char *s; const char *s;
switch( no ) { switch( no ) {
case STATUS_ENTER : s = "ENTER\n"; break; case STATUS_ENTER : s = "ENTER"; break;
case STATUS_LEAVE : s = "LEAVE\n"; break; case STATUS_LEAVE : s = "LEAVE"; break;
case STATUS_ABORT : s = "ABORT\n"; break; case STATUS_ABORT : s = "ABORT"; break;
case STATUS_GOODSIG: s = "GOODSIG\n"; break; case STATUS_GOODSIG: s = "GOODSIG"; break;
case STATUS_SIGEXPIRED: s = "SIGEXPIRED\n"; break; case STATUS_SIGEXPIRED: s = "SIGEXPIRED"; break;
case STATUS_KEYREVOKED: s = "KEYREVOKED\n"; break; case STATUS_KEYREVOKED: s = "KEYREVOKED"; break;
case STATUS_BADSIG : s = "BADSIG\n"; break; case STATUS_BADSIG : s = "BADSIG"; break;
case STATUS_ERRSIG : s = "ERRSIG\n"; break; case STATUS_ERRSIG : s = "ERRSIG"; break;
case STATUS_BADARMOR : s = "BADARMOR\n"; break; case STATUS_BADARMOR : s = "BADARMOR"; break;
case STATUS_RSA_OR_IDEA : s= "RSA_OR_IDEA\n"; break; case STATUS_RSA_OR_IDEA : s= "RSA_OR_IDEA"; break;
case STATUS_TRUST_UNDEFINED: s = "TRUST_UNDEFINED\n"; break; case STATUS_TRUST_UNDEFINED: s = "TRUST_UNDEFINED"; break;
case STATUS_TRUST_NEVER : s = "TRUST_NEVER\n"; break; case STATUS_TRUST_NEVER : s = "TRUST_NEVER"; break;
case STATUS_TRUST_MARGINAL : s = "TRUST_MARGINAL\n"; break; case STATUS_TRUST_MARGINAL : s = "TRUST_MARGINAL"; break;
case STATUS_TRUST_FULLY : s = "TRUST_FULLY\n"; break; case STATUS_TRUST_FULLY : s = "TRUST_FULLY"; break;
case STATUS_TRUST_ULTIMATE : s = "TRUST_ULTIMATE\n"; break; case STATUS_TRUST_ULTIMATE : s = "TRUST_ULTIMATE"; break;
case STATUS_GET_BOOL : s = "GET_BOOL\n"; break; case STATUS_GET_BOOL : s = "GET_BOOL"; break;
case STATUS_GET_LINE : s = "GET_LINE\n"; break; case STATUS_GET_LINE : s = "GET_LINE"; break;
case STATUS_GET_HIDDEN : s = "GET_HIDDEN\n"; break; case STATUS_GET_HIDDEN : s = "GET_HIDDEN"; break;
case STATUS_GOT_IT : s = "GOT_IT\n"; break; case STATUS_GOT_IT : s = "GOT_IT"; break;
case STATUS_SHM_INFO : s = "SHM_INFO\n"; break; case STATUS_SHM_INFO : s = "SHM_INFO"; break;
case STATUS_SHM_GET : s = "SHM_GET\n"; break; case STATUS_SHM_GET : s = "SHM_GET"; break;
case STATUS_SHM_GET_BOOL : s = "SHM_GET_BOOL\n"; break; case STATUS_SHM_GET_BOOL : s = "SHM_GET_BOOL"; break;
case STATUS_SHM_GET_HIDDEN : s = "SHM_GET_HIDDEN\n"; break; case STATUS_SHM_GET_HIDDEN : s = "SHM_GET_HIDDEN"; break;
case STATUS_NEED_PASSPHRASE: s = "NEED_PASSPHRASE\n"; break; case STATUS_NEED_PASSPHRASE: s = "NEED_PASSPHRASE"; break;
case STATUS_VALIDSIG : s = "VALIDSIG\n"; break; case STATUS_VALIDSIG : s = "VALIDSIG"; break;
case STATUS_SIG_ID : s = "SIG_ID\n"; break; case STATUS_SIG_ID : s = "SIG_ID"; break;
case STATUS_ENC_TO : s = "ENC_TO\n"; break; case STATUS_ENC_TO : s = "ENC_TO"; break;
case STATUS_NODATA : s = "NODATA\n"; break; case STATUS_NODATA : s = "NODATA"; break;
case STATUS_BAD_PASSPHRASE : s = "BAD_PASSPHRASE\n"; break; case STATUS_BAD_PASSPHRASE : s = "BAD_PASSPHRASE"; break;
case STATUS_NO_PUBKEY : s = "NO_PUBKEY\n"; break; case STATUS_NO_PUBKEY : s = "NO_PUBKEY"; break;
case STATUS_NO_SECKEY : s = "NO_SECKEY\n"; break; case STATUS_NO_SECKEY : s = "NO_SECKEY"; break;
case STATUS_NEED_PASSPHRASE_SYM: s = "NEED_PASSPHRASE_SYM\n"; break; case STATUS_NEED_PASSPHRASE_SYM: s = "NEED_PASSPHRASE_SYM"; break;
case STATUS_DECRYPTION_FAILED: s = "DECRYPTION_FAILED\n"; break; case STATUS_DECRYPTION_FAILED: s = "DECRYPTION_FAILED"; break;
case STATUS_DECRYPTION_OKAY: s = "DECRYPTION_OKAY\n"; break; case STATUS_DECRYPTION_OKAY: s = "DECRYPTION_OKAY"; break;
case STATUS_MISSING_PASSPHRASE: s = "MISSING_PASSPHRASE\n"; break; case STATUS_MISSING_PASSPHRASE: s = "MISSING_PASSPHRASE"; break;
case STATUS_GOOD_PASSPHRASE : s = "GOOD_PASSPHRASE\n"; break; case STATUS_GOOD_PASSPHRASE : s = "GOOD_PASSPHRASE"; break;
case STATUS_GOODMDC : s = "GOODMDC\n"; break; case STATUS_GOODMDC : s = "GOODMDC"; break;
case STATUS_BADMDC : s = "BADMDC\n"; break; case STATUS_BADMDC : s = "BADMDC"; break;
case STATUS_ERRMDC : s = "ERRMDC\n"; break; case STATUS_ERRMDC : s = "ERRMDC"; break;
case STATUS_IMPORTED : s = "IMPORTED\n"; break; case STATUS_IMPORTED : s = "IMPORTED"; break;
case STATUS_IMPORT_RES : s = "IMPORT_RES\n"; break; case STATUS_IMPORT_RES : s = "IMPORT_RES"; break;
case STATUS_FILE_START : s = "FILE_START\n"; break; case STATUS_FILE_START : s = "FILE_START"; break;
case STATUS_FILE_DONE : s = "FILE_DONE\n"; break; case STATUS_FILE_DONE : s = "FILE_DONE"; break;
case STATUS_FILE_ERROR : s = "FILE_ERROR\n"; break; case STATUS_FILE_ERROR : s = "FILE_ERROR"; break;
case STATUS_BEGIN_DECRYPTION:s = "BEGIN_DECRYPTION\n"; break; case STATUS_BEGIN_DECRYPTION:s = "BEGIN_DECRYPTION"; break;
case STATUS_END_DECRYPTION : s = "END_DECRYPTION\n"; break; case STATUS_END_DECRYPTION : s = "END_DECRYPTION"; break;
case STATUS_BEGIN_ENCRYPTION:s = "BEGIN_ENCRYPTION\n"; break; case STATUS_BEGIN_ENCRYPTION:s = "BEGIN_ENCRYPTION"; break;
case STATUS_END_ENCRYPTION : s = "END_ENCRYPTION\n"; break; case STATUS_END_ENCRYPTION : s = "END_ENCRYPTION"; break;
case STATUS_DELETE_PROBLEM : s = "DELETE_PROBLEM\n"; break; case STATUS_DELETE_PROBLEM : s = "DELETE_PROBLEM"; break;
case STATUS_PROGRESS : s = "PROGRESS\n"; break; case STATUS_PROGRESS : s = "PROGRESS"; break;
case STATUS_SIG_CREATED : s = "SIG_CREATED\n"; break; case STATUS_SIG_CREATED : s = "SIG_CREATED"; break;
case STATUS_SESSION_KEY : s = "SESSION_KEY\n"; break; case STATUS_SESSION_KEY : s = "SESSION_KEY"; break;
case STATUS_NOTATION_NAME : s = "NOTATION_NAME\n" ; break; case STATUS_NOTATION_NAME : s = "NOTATION_NAME" ; break;
case STATUS_NOTATION_DATA : s = "NOTATION_DATA\n" ; break; case STATUS_NOTATION_DATA : s = "NOTATION_DATA" ; break;
case STATUS_POLICY_URL : s = "POLICY_URL\n" ; break; case STATUS_POLICY_URL : s = "POLICY_URL" ; break;
default: s = "?\n"; break; default: s = "?"; break;
} }
return s; return s;
} }
void void
set_status_fd ( int newfd ) set_status_fd ( int fd )
{ {
fd = newfd; static int last_fd = -1;
if ( fd != -1 ) {
if ( fd != -1 && last_fd == fd )
return;
if ( statusfp && statusfp != stdout && statusfp != stderr )
fclose (statusfp);
statusfp = NULL;
if ( fd == -1 )
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));
}
last_fd = fd;
register_primegen_progress ( progress_cb, "primegen" ); register_primegen_progress ( progress_cb, "primegen" );
register_pk_dsa_progress ( progress_cb, "pk_dsa" ); register_pk_dsa_progress ( progress_cb, "pk_dsa" );
register_pk_elg_progress ( progress_cb, "pk_elg" ); register_pk_elg_progress ( progress_cb, "pk_elg" );
}
} }
int int
is_status_enabled() is_status_enabled()
{ {
return fd != -1; return !!statusfp;
} }
void void
@ -161,35 +181,20 @@ write_status ( int no )
write_status_text( no, NULL ); write_status_text( no, NULL );
} }
static void
mywrite ( int fd, const char *buffer, size_t len )
{
int nwritten;
do {
nwritten = write (fd, buffer, len );
} while (nwritten == -1 && errno == EINTR );
}
void void
write_status_text ( int no, const char *text) write_status_text ( int no, const char *text)
{ {
const char *s; if( !statusfp )
if( fd == -1 )
return; /* not enabled */ return; /* not enabled */
s = get_status_string (no); fputs ( "[GNUPG:] ", statusfp );
fputs ( get_status_string (no), statusfp );
mywrite( fd, "[GNUPG:] ", 9 );
if( text ) { if( text ) {
mywrite( fd, s, strlen(s)-1 ); putc ( ' ', statusfp );
mywrite( fd, " ", 1 ); fputs ( text, statusfp );
mywrite( fd, text, strlen(text) );
mywrite( fd, "\n", 1 );
} }
else putc ('\n',statusfp);
mywrite( fd, s, strlen(s) ); fflush (statusfp);
} }
@ -204,16 +209,14 @@ write_status_buffer ( int no, const char *buffer, size_t len, int wrap )
int esc; int esc;
size_t n, count, dowrap; size_t n, count, dowrap;
if( fd == -1 ) if( !statusfp )
return; /* not enabled */ return; /* not enabled */
text = get_status_string (no); text = get_status_string (no);
count = dowrap = 1; count = dowrap = 1;
do { do {
if (dowrap) { if (dowrap) {
mywrite( fd, "[GNUPG:] ", 9 ); fprintf (statusfp, "[GNUPG:] %s ", text );
mywrite( fd, text, strlen(text)-1 );
mywrite( fd, " ", 1 );
count = dowrap = 0; count = dowrap = 0;
} }
for (esc=0, s=buffer, n=len; n && !esc; s++, n-- ) { for (esc=0, s=buffer, n=len; n && !esc; s++, n-- ) {
@ -228,20 +231,19 @@ write_status_buffer ( int no, const char *buffer, size_t len, int wrap )
s--; n++; s--; n++;
} }
if (s != buffer) if (s != buffer)
mywrite ( fd, buffer, s-buffer ); fwrite (buffer, s-buffer, 1, statusfp );
if ( esc ) { if ( esc ) {
char buf[5]; fprintf (statusfp, "%%%02X", *(const byte*)s );
sprintf (buf, "%%%02X", *(const byte*)s );
mywrite (fd, buf, 3 );
s++; n--; s++; n--;
} }
buffer = s; buffer = s;
len = n; len = n;
if ( dowrap && len ) if ( dowrap && len )
mywrite( fd, "\n", 1 ); putc ( '\n', statusfp );
} while ( len ); } while ( len );
mywrite( fd, "\n", 1 ); putc ('\n',statusfp);
fflush (statusfp);
} }

View File

@ -107,8 +107,9 @@ file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
else { else {
clearerr( fp ); clearerr( fp );
nbytes = fread( buf, 1, size, fp ); nbytes = fread( buf, 1, size, fp );
if( feof(fp) && !nbytes ) if( feof(fp) && !nbytes ) {
rc = -1; /* okay: we can return EOF now. */ rc = -1; /* okay: we can return EOF now. */
}
else if( ferror(fp) && errno != EPIPE ) { else if( ferror(fp) && errno != EPIPE ) {
log_error("%s: read error: %s\n", log_error("%s: read error: %s\n",
a->fname, strerror(errno)); a->fname, strerror(errno));
@ -1626,14 +1627,21 @@ iobuf_translate_file_handle ( int fd, int for_write )
{ {
#ifdef __MINGW32__ #ifdef __MINGW32__
{ {
int x = _open_osfhandle ( (void*)fd, for_write? 1:0 ); int x;
if ( fd <= 2 )
return fd; /* do not do this for error, stdin, stdout, stderr */
x = _open_osfhandle ( (void*)fd, for_write? 1:0 );
if (x==-1 ) if (x==-1 )
log_error ("failed to translate osfhandle %p\n", (void*)fd ); log_error ("failed to translate osfhandle %p\n", (void*)fd );
else { else {
log_info ("_open_osfhandle %p yields %d\n", (void*)fd, x ); /*log_info ("_open_osfhandle %p yields %d%s\n",
(void*)fd, x, for_write? " for writing":"" );*/
fd = x; fd = x;
} }
} }
#endif #endif
return fd; return fd;
} }