Browse Source

z/OS support: Charsets for I/O

Mainframes... -.-
master
David Lanzendörfer 2 weeks ago
parent
commit
2755a7cf5a
2 changed files with 53 additions and 79 deletions
  1. +53
    -78
      src/reader.c
  2. +0
    -1
      src/writer.c

+ 53
- 78
src/reader.c View File

@ -151,6 +151,14 @@ __RCSID("$NetBSD$");
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
inline char A(char c)
{
#if defined(NETPGP_EBCDIC)
__e2a_l(&c,1);
#endif
return c;
}
/* get a pass phrase from the user */
int
pgp_getpassphrase(void *in, char *phrase, size_t size)
@ -446,7 +454,7 @@ read_char(pgp_stream_t *stream, dearmour_t *dearmour,
unsigned skip)
{
//printf("%s\n",__FUNCTION__);
uint8_t c;
uint8_t c;
do {
if (dearmour->pushbackc) {
@ -458,8 +466,7 @@ read_char(pgp_stream_t *stream, dearmour_t *dearmour,
free(dearmour->pushback);
dearmour->pushback = NULL;
}
} else if (pgp_stacked_read(stream, &c, 1, errors, readinfo,
cbinfo) != 1) {
} else if (pgp_stacked_read(stream, &c, 1, errors, readinfo, cbinfo) != 1) {
return -1;
}
} while (skip && c == '\r');
@ -519,7 +526,7 @@ unarmoured_read_char(pgp_stream_t *stream, dearmour_t *dearmour,
pgp_cbdata_t *cbinfo,
unsigned skip)
{
printf("%s\n",__FUNCTION__);
//printf("%s\n",__FUNCTION__);
int c;
do {
@ -845,14 +852,6 @@ end:
return ret;
}
inline char A(char c)
{
#if defined(NETPGP_EBCDIC)
__e2a_l(&c,1);
#endif
return c;
}
static int
read4(pgp_stream_t *stream, dearmour_t *dearmour, pgp_error_t **errors,
pgp_reader_t *readinfo, pgp_cbdata_t *cbinfo,
@ -863,7 +862,7 @@ read4(pgp_stream_t *stream, dearmour_t *dearmour, pgp_error_t **errors,
uint32_t l = 0;
for (n = 0; n < 4; ++n) {
c = A(read_char(stream, dearmour, errors, readinfo, cbinfo, 1));
c = read_char(stream, dearmour, errors, readinfo, cbinfo, 1);
if (c < 0) {
dearmour->eof64 = 1;
return -1;
@ -872,15 +871,15 @@ read4(pgp_stream_t *stream, dearmour_t *dearmour, pgp_error_t **errors,
break;
}
l <<= 6;
if (c >= A('A') && c <= A('Z')) {
if (A(c) >= A('A') && A(c) <= A('Z')) {
l += (uint32_t)(c - A('A'));
} else if (c >= A('a') && c <= A('z')) {
l += (uint32_t)(c - A('a')) + 26;
} else if (c >= A('0') && c <= A('9')) {
l += (uint32_t)(c - A('0')) + 52;
} else if (c == A('+')) {
} else if (A(c) >= A('a') && A(c) <= A('z')) {
l += (uint32_t)(A(c) - A('a')) + 26;
} else if (A(c) >= A('0') && A(c) <= A('9')) {
l += (uint32_t)(A(c) - A('0')) + 52;
} else if (A(c) == A('+')) {
l += 62;
} else if (c == A('/')) {
} else if (A(c) == A('/')) {
l += 63;
} else {
--n;
@ -1070,7 +1069,6 @@ armoured_data_reader(pgp_stream_t *stream, void *dest_, size_t length, pgp_error
pgp_reader_t *readinfo,
pgp_cbdata_t *cbinfo)
{
printf("%s\n",__FUNCTION__);
pgp_packet_t content;
dearmour_t *dearmour;
unsigned first;
@ -1084,8 +1082,7 @@ armoured_data_reader(pgp_stream_t *stream, void *dest_, size_t length, pgp_error
if (dearmour->eof64 && !dearmour->buffered) {
if (dearmour->state != OUTSIDE_BLOCK &&
dearmour->state != AT_TRAILER_NAME) {
(void) fprintf(stderr,
"armoured_data_reader: bad dearmour state\n");
(void) fprintf(stderr, "armoured_data_reader: bad dearmour state\n");
return 0;
}
}
@ -1122,9 +1119,9 @@ armoured_data_reader(pgp_stream_t *stream, void *dest_, size_t length, pgp_error
readinfo, cbinfo, 0)) < 0) {
return 0;
}
if (c != '-') {
goto reloop;
}
//if (c != '-') {
// goto reloop;
//}
}
/* Now find the block type */
@ -1142,18 +1139,18 @@ armoured_data_reader(pgp_stream_t *stream, void *dest_, size_t length, pgp_error
break;
got_minus:
printf("%s: tag got_minus\n",__FUNCTION__);
buf[n] = '\0';
/* Consume trailing '-' */
for (count = 1; count < 5; ++count) {
if ((c = unarmoured_read_char(stream, dearmour, errors,
readinfo, cbinfo, 0)) < 0) {
if ((c = unarmoured_read_char(stream, dearmour, errors, readinfo, cbinfo, 0)) < 0) {
return 0;
}
if (c != '-') {
/* wasn't a header after all */
goto reloop;
}
/* wasn't a header after all */
//if (c != '-') {
// goto reloop;
//}
}
/* Consume final NL */
@ -1162,8 +1159,7 @@ got_minus:
return 0;
}
if (dearmour->allow_trailing_whitespace) {
if ((c = eat_whitespace(stream, c, dearmour, errors,
readinfo, cbinfo, 1)) < 0) {
if ((c = eat_whitespace(stream, c, dearmour, errors, readinfo, cbinfo, 1)) < 0) {
return 0;
}
}
@ -1182,8 +1178,7 @@ got_minus:
* But now we've seen a header line, then errors are
* EARLY_EOF
*/
if ((ret = parse_headers(stream, dearmour, errors, readinfo,
cbinfo)) <= 0) {
if ((ret = parse_headers(stream, dearmour, errors, readinfo, cbinfo)) <= 0) {
return -1;
}
@ -1192,24 +1187,17 @@ got_minus:
}
if (strcmp(buf, "BEGIN PGP SIGNED MESSAGE") == 0) {
dup_headers(&content.u.cleartext_head,
&dearmour->headers);
CALLBACK(PGP_PTAG_CT_SIGNED_CLEARTEXT_HEADER,
cbinfo,
&content);
ret = process_dash_escaped(stream, dearmour, errors,
readinfo, cbinfo);
dup_headers(&content.u.cleartext_head, &dearmour->headers);
CALLBACK(PGP_PTAG_CT_SIGNED_CLEARTEXT_HEADER, cbinfo, &content);
ret = process_dash_escaped(stream, dearmour, errors, readinfo, cbinfo);
if (ret <= 0) {
return ret;
}
} else {
content.u.armour_header.type = buf;
content.u.armour_header.headers =
dearmour->headers;
(void) memset(&dearmour->headers, 0x0,
sizeof(dearmour->headers));
CALLBACK(PGP_PTAG_CT_ARMOUR_HEADER, cbinfo,
&content);
content.u.armour_header.headers = dearmour->headers;
(void) memset(&dearmour->headers, 0x0, sizeof(dearmour->headers));
CALLBACK(PGP_PTAG_CT_ARMOUR_HEADER, cbinfo, &content);
base64(dearmour);
}
break;
@ -1219,16 +1207,14 @@ got_minus:
while (length > 0) {
if (!dearmour->buffered) {
if (!dearmour->eof64) {
ret = decode64(stream, dearmour,
errors, readinfo, cbinfo);
ret = decode64(stream, dearmour, errors, readinfo, cbinfo);
if (ret <= 0) {
return ret;
}
}
if (!dearmour->buffered) {
if (!dearmour->eof64) {
(void) fprintf(stderr,
"armoured_data_reader: bad dearmour eof64\n");
(void) fprintf(stderr, "armoured_data_reader: bad dearmour eof64\n");
return 0;
}
if (first) {
@ -1240,8 +1226,7 @@ got_minus:
}
}
if (!dearmour->buffered) {
(void) fprintf(stderr,
"armoured_data_reader: bad dearmour buffered\n");
(void) fprintf(stderr, "armoured_data_reader: bad dearmour buffered\n");
return 0;
}
*dest = dearmour->buffer[--dearmour->buffered];
@ -1256,8 +1241,7 @@ got_minus:
case AT_TRAILER_NAME:
for (n = 0; n < sizeof(buf) - 1;) {
if ((c = read_char(stream, dearmour, errors, readinfo,
cbinfo, 0)) < 0) {
if ((c = read_char(stream, dearmour, errors, readinfo, cbinfo, 0)) < 0) {
return -1;
}
if (c == '-') {
@ -1271,6 +1255,7 @@ got_minus:
break;
got_minus2:
printf("%s: tag got_minus2\n",__FUNCTION__);
buf[n] = '\0';
if (!set_lastseen_headerline(dearmour, buf, errors)) {
@ -1279,8 +1264,7 @@ got_minus2:
/* Consume trailing '-' */
for (count = 1; count < 5; ++count) {
if ((c = read_char(stream, dearmour, errors, readinfo,
cbinfo, 0)) < 0) {
if ((c = read_char(stream, dearmour, errors, readinfo, cbinfo, 0)) < 0) {
return -1;
}
if (c != '-') {
@ -1292,48 +1276,40 @@ got_minus2:
}
/* Consume final NL */
if ((c = read_char(stream, dearmour, errors, readinfo, cbinfo,
1)) < 0) {
if ((c = read_char(stream, dearmour, errors, readinfo, cbinfo, 1)) < 0) {
return -1;
}
if (dearmour->allow_trailing_whitespace) {
if ((c = eat_whitespace(stream, c, dearmour, errors,
readinfo, cbinfo, 1)) < 0) {
if ((c = eat_whitespace(stream, c, dearmour, errors, readinfo, cbinfo, 1)) < 0) {
return 0;
}
}
if (c != '\n') {
/* wasn't a trailer line after all */
PGP_ERROR_1(errors, PGP_E_R_BAD_FORMAT,
"%s", "Bad ASCII armour trailer (3)");
PGP_ERROR_1(errors, PGP_E_R_BAD_FORMAT, "%s", "Bad ASCII armour trailer (3)");
}
if (strncmp(buf, "BEGIN ", 6) == 0) {
if (!set_lastseen_headerline(dearmour, buf,
errors)) {
if (!set_lastseen_headerline(dearmour, buf, errors)) {
return -1;
}
if ((ret = parse_headers(stream, dearmour, errors,
readinfo, cbinfo)) <= 0) {
if ((ret = parse_headers(stream, dearmour, errors, readinfo, cbinfo)) <= 0) {
return ret;
}
content.u.armour_header.type = buf;
content.u.armour_header.headers =
dearmour->headers;
(void) memset(&dearmour->headers, 0x0,
sizeof(dearmour->headers));
CALLBACK(PGP_PTAG_CT_ARMOUR_HEADER, cbinfo,
&content);
content.u.armour_header.headers = dearmour->headers;
(void) memset(&dearmour->headers, 0x0, sizeof(dearmour->headers));
CALLBACK(PGP_PTAG_CT_ARMOUR_HEADER, cbinfo, &content);
base64(dearmour);
} else {
content.u.armour_trailer = buf;
CALLBACK(PGP_PTAG_CT_ARMOUR_TRAILER, cbinfo,
&content);
CALLBACK(PGP_PTAG_CT_ARMOUR_TRAILER, cbinfo, &content);
dearmour->state = OUTSIDE_BLOCK;
}
break;
}
reloop:
printf("%s: tag reloop\n",__FUNCTION__);
continue;
}
@ -1807,7 +1783,6 @@ fd_reader(pgp_stream_t *stream, void *dest, size_t length, pgp_error_t **errors,
reader = pgp_reader_get_arg(readinfo);
n = (int)read(reader->fd, dest, length);
hexdump(stderr, "fd_reader", dest, length);
if (n == 0) {
return 0;


+ 0
- 1
src/writer.c View File

@ -1266,7 +1266,6 @@ fd_writer(const uint8_t *src, unsigned len,
writerfd = pgp_writer_get_arg(writer);
n = (int)write(writerfd->fd, src, len);
hexdump(stderr, "fd_writer", src, len);
if (n == -1) {
PGP_SYSTEM_ERROR_1(errors, PGP_E_W_WRITE_FAILED, "write",


Loading…
Cancel
Save