aboutsummaryrefslogtreecommitdiffstats
path: root/g10
diff options
context:
space:
mode:
Diffstat (limited to 'g10')
-rw-r--r--g10/ChangeLog17
-rw-r--r--g10/armor.c44
-rw-r--r--g10/plaintext.c14
-rw-r--r--g10/sign.c8
-rw-r--r--g10/signal.c15
-rw-r--r--g10/textfilter.c19
6 files changed, 88 insertions, 29 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog
index 70e3e17ba..3b8c6a0fb 100644
--- a/g10/ChangeLog
+++ b/g10/ChangeLog
@@ -1,3 +1,20 @@
+Sun Dec 19 15:22:26 CET 1999 Werner Koch <[email protected]>
+
+ * armor.c (LF): Use this new macro at all places where a line LF
+ is needed. This way DOSish textfiles should be created when the
+ input data is also in dos mode.
+ * sign.c (LF): Ditto.
+ * textfilter.c (LF): Ditto.
+ (copy_clearsig_text): Disabled the forcing of CR,LF sequences
+ for DOS systems.
+
+ * plaintext.c (handle_plaintext): Fixes for line endings on DOS.
+ and react on a LF in cleartext.
+ * armor.c (fake_packet): Restore the original line ending after
+ removing trailing spaces.
+
+ * signal.c (got_fatal_signal): DOS fix.
+
Thu Dec 16 10:07:58 CET 1999 Werner Koch <[email protected]>
* mainproc.c (print_failed_pkenc): Fix for unknown algorithm.
diff --git a/g10/armor.c b/g10/armor.c
index 3fa52e617..7ef8f336d 100644
--- a/g10/armor.c
+++ b/g10/armor.c
@@ -37,6 +37,11 @@
#include "status.h"
#include "i18n.h"
+#ifdef HAVE_DOSISH_SYSTEM
+ #define LF "\r\n"
+#else
+ #define LF "\n"
+#endif
#define MAX_LINELEN 20000
@@ -485,13 +490,26 @@ fake_packet( armor_filter_context_t *afx, IOBUF a,
if( !maxlen )
afx->truncated++;
if( !afx->not_dash_escaped ) {
+ int crlf;
+ p = afx->buffer;
+ n = afx->buffer_len;
+ crlf = n > 1 && p[n-2] == '\r' && p[n-1]=='\n';
+
/* PGP2 does not treat a tab as white space character */
- afx->buffer_len =
- trim_trailing_chars( afx->buffer, afx->buffer_len,
+ afx->buffer_len = trim_trailing_chars( p, n,
afx->pgp2mode ? " \r\n" : " \t\r\n");
/* the buffer is always allocated with enough space to append
- * a CR, LF, Nul */
- afx->buffer[afx->buffer_len++] = '\r';
+ * the removed [CR], LF and a Nul
+ * The reason for this complicated procedure is to keep at least
+ * the original tupe of lineending - handling of the removed
+ * trailing spaces seems to be impossible in our method
+ * of faking a packet; either we have to use a temporary file
+ * or calculate the hash here in this module and somehow find
+ * a way to send the hash down the processing line (well, a special
+ * faked packet could do the job).
+ */
+ if( crlf )
+ afx->buffer[afx->buffer_len++] = '\r';
afx->buffer[afx->buffer_len++] = '\n';
afx->buffer[afx->buffer_len] = 0;
}
@@ -880,10 +898,10 @@ armor_filter( void *opaque, int control,
log_bug("afx->what=%d", afx->what);
iobuf_writestr(a, "-----");
iobuf_writestr(a, head_strings[afx->what] );
- iobuf_writestr(a, "-----\n");
+ iobuf_writestr(a, "-----" LF );
if( !opt.no_version )
iobuf_writestr(a, "Version: GnuPG v" VERSION " ("
- PRINTABLE_OS_NAME ")\n");
+ PRINTABLE_OS_NAME ")" LF );
if( opt.comment_string ) {
const char *s = opt.comment_string;
@@ -899,15 +917,15 @@ armor_filter( void *opaque, int control,
else
iobuf_put(a, *s );
}
- iobuf_put(a, '\n' );
+ iobuf_writestr(a, LF );
}
}
else
iobuf_writestr(a,
- "Comment: For info see http://www.gnupg.org\n");
+ "Comment: For info see http://www.gnupg.org" LF);
if( afx->hdrlines )
iobuf_writestr(a, afx->hdrlines);
- iobuf_put(a, '\n');
+ iobuf_writestr(a, LF );
afx->status++;
afx->idx = 0;
afx->idx2 = 0;
@@ -936,7 +954,7 @@ armor_filter( void *opaque, int control,
c = bintoasc[radbuf[2]&077];
iobuf_put(a, c);
if( ++idx2 >= (64/4) ) { /* pgp doesn't like 72 here */
- iobuf_put(a, '\n');
+ iobuf_writestr(a, LF );
idx2=0;
}
}
@@ -980,13 +998,13 @@ armor_filter( void *opaque, int control,
iobuf_put(a, '=');
}
if( ++idx2 >= (64/4) ) { /* pgp doesn't like 72 here */
- iobuf_put(a, '\n');
+ iobuf_writestr(a, LF );
idx2=0;
}
}
/* may need a linefeed */
if( idx2 )
- iobuf_put(a, '\n');
+ iobuf_writestr(a, LF );
/* write the CRC */
iobuf_put(a, '=');
radbuf[0] = crc >>16;
@@ -1006,7 +1024,7 @@ armor_filter( void *opaque, int control,
log_bug("afx->what=%d", afx->what);
iobuf_writestr(a, "-----");
iobuf_writestr(a, tail_strings[afx->what] );
- iobuf_writestr(a, "-----\n");
+ iobuf_writestr(a, "-----" LF );
}
else if( !afx->any_data && !afx->inp_bypass ) {
log_error(_("no valid OpenPGP data found.\n"));
diff --git a/g10/plaintext.c b/g10/plaintext.c
index 9deda8652..eb74da3d3 100644
--- a/g10/plaintext.c
+++ b/g10/plaintext.c
@@ -107,8 +107,10 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
}
if( mfx->md )
md_putc(mfx->md, c );
- if( c == '\r' )
- continue; /* fixme: this hack might be too simple */
+ #ifndef HAVE_DOSISH_SYSTEM
+ if( c == '\r' ) /* convert to native line ending */
+ continue; /* fixme: this hack might be too simple */
+ #endif
if( fp ) {
if( putc( c, fp ) == EOF ) {
log_error("Error writing to `%s': %s\n",
@@ -152,8 +154,10 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
while( (c = iobuf_get(pt->buf)) != -1 ) {
if( mfx->md )
md_putc(mfx->md, c );
+ #ifndef HAVE_DOSISH_SYSTEM
if( convert && c == '\r' )
continue; /* fixme: this hack might be too simple */
+ #endif
if( fp ) {
if( putc( c, fp ) == EOF ) {
log_error("Error writing to `%s': %s\n",
@@ -169,10 +173,10 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
int eof;
for( eof=0; !eof; ) {
/* Why do we check for len < 32768:
- * If we won� we would practically read 2 EOFS but
+ * If we won't, we would practically read 2 EOFs but
* the first one has already popped the block_filter
* off and therefore we don't catch the boundary.
- * Always assume EOF if iobuf_read returns less bytes
+ * So, always assume EOF if iobuf_read returns less bytes
* then requested */
int len = iobuf_read( pt->buf, buffer, 32768 );
if( len == -1 )
@@ -217,6 +221,8 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
if( !state ) {
if( c == '\r' )
state = 1;
+ else if( c == '\n' )
+ state = 2;
else
md_putc(mfx->md, c );
}
diff --git a/g10/sign.c b/g10/sign.c
index 3b7183677..0d3e50372 100644
--- a/g10/sign.c
+++ b/g10/sign.c
@@ -39,6 +39,12 @@
#include "i18n.h"
+#ifdef HAVE_DOSISH_SYSTEM
+ #define LF "\r\n"
+#else
+ #define LF "\n"
+#endif
+
/****************
* Create a notation. It is assumed that the stings in STRLIST
@@ -582,7 +588,7 @@ clearsign_file( const char *fname, STRLIST locusr, const char *outfile )
else if( (rc = open_outfile( fname, 1, &out )) )
goto leave;
- iobuf_writestr(out, "-----BEGIN PGP SIGNED MESSAGE-----\n" );
+ iobuf_writestr(out, "-----BEGIN PGP SIGNED MESSAGE-----" LF );
for( sk_rover = sk_list; sk_rover; sk_rover = sk_rover->next ) {
PKT_secret_key *sk = sk_rover->sk;
diff --git a/g10/signal.c b/g10/signal.c
index ea837c3e7..5397f076d 100644
--- a/g10/signal.c
+++ b/g10/signal.c
@@ -53,7 +53,6 @@ static RETSIGTYPE
got_fatal_signal( int sig )
{
const char *s;
- struct sigaction nact;
if( caught_fatal_sig )
raise( sig );
@@ -67,11 +66,15 @@ got_fatal_signal( int sig )
s = get_signal_name(sig); write(2, s, strlen(s) );
write(2, " caught ... exiting\n", 21 );
- /* reset action to default action and raise signal again */
- nact.sa_handler = SIG_DFL;
- sigemptyset( &nact.sa_mask );
- nact.sa_flags = 0;
- sigaction( sig, &nact, NULL);
+ #ifndef HAVE_DOSISH_SYSTEM
+ { /* reset action to default action and raise signal again */
+ struct sigaction nact;
+ nact.sa_handler = SIG_DFL;
+ sigemptyset( &nact.sa_mask );
+ nact.sa_flags = 0;
+ sigaction( sig, &nact, NULL);
+ }
+ #endif
raise( sig );
}
diff --git a/g10/textfilter.c b/g10/textfilter.c
index dc143b354..9280680e5 100644
--- a/g10/textfilter.c
+++ b/g10/textfilter.c
@@ -32,6 +32,11 @@
#include "filter.h"
#include "i18n.h"
+#ifdef HAVE_DOSISH_SYSTEM
+ #define LF "\r\n"
+#else
+ #define LF "\n"
+#endif
#define MAX_LINELEN 19995 /* a little bit smaller than in armor.c */
/* to make sure that a warning is displayed while */
@@ -183,7 +188,14 @@ copy_clearsig_text( IOBUF out, IOBUF inp, MD_HANDLE md,
iobuf_put( out, '-' );
iobuf_put( out, ' ' );
}
- #ifdef __MINGW32__
+
+ #if 0 /*defined(HAVE_DOSISH_SYSTEM)*/
+ /* We don't use this anymore because my interpretation of rfc2440 7.1
+ * is that there is no conversion needed. If one decides to
+ * clearsign a unix file on a DOS box he will get a mixed line endings.
+ * If at some point it turns out, that a conversion is a nice feature
+ * we can make an option out of it.
+ */
/* make sure the lines do end in CR,LF */
if( n > 1 && ( (buffer[n-2] == '\r' && buffer[n-1] == '\n' )
|| (buffer[n-2] == '\n' && buffer[n-1] == '\r'))) {
@@ -206,10 +218,7 @@ copy_clearsig_text( IOBUF out, IOBUF inp, MD_HANDLE md,
/* at eof */
if( !pending_lf ) { /* make sure that the file ends with a LF */
- #ifndef __MINGW32__
- iobuf_put( out, '\r');
- #endif
- iobuf_put( out, '\n');
+ iobuf_writestr( out, LF );
if( !escape_dash )
md_putc( md, '\n' );
}