If we're going to print unrecognized result codes from SSL_get_error

in open_client_SSL, surely we should do it everywhere.  Also make
message formatting conform to style guide.
This commit is contained in:
Tom Lane 2004-09-23 20:27:50 +00:00
parent fa6fa8e549
commit fb147dc30e
2 changed files with 29 additions and 13 deletions

View File

@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.49 2004/09/09 00:59:31 momjian Exp $ * $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.50 2004/09/23 20:27:50 tgl Exp $
* *
* Since the server static private key ($DataDir/server.key) * Since the server static private key ($DataDir/server.key)
* will normally be stored unencrypted so that the database * will normally be stored unencrypted so that the database
@ -257,9 +257,12 @@ secure_read(Port *port, void *ptr, size_t len)
#ifdef USE_SSL #ifdef USE_SSL
if (port->ssl) if (port->ssl)
{ {
int err;
rloop: rloop:
n = SSL_read(port->ssl, ptr, len); n = SSL_read(port->ssl, ptr, len);
switch (SSL_get_error(port->ssl, n)) err = SSL_get_error(port->ssl, n);
switch (err)
{ {
case SSL_ERROR_NONE: case SSL_ERROR_NONE:
port->count += n; port->count += n;
@ -293,8 +296,8 @@ rloop:
default: default:
ereport(COMMERROR, ereport(COMMERROR,
(errcode(ERRCODE_PROTOCOL_VIOLATION), (errcode(ERRCODE_PROTOCOL_VIOLATION),
errmsg("unrecognized SSL error code %d", errmsg("unrecognized SSL error code: %d",
SSL_get_error(port->ssl, n)))); err)));
n = -1; n = -1;
break; break;
} }
@ -317,6 +320,8 @@ secure_write(Port *port, void *ptr, size_t len)
#ifdef USE_SSL #ifdef USE_SSL
if (port->ssl) if (port->ssl)
{ {
int err;
if (port->count > RENEGOTIATION_LIMIT) if (port->count > RENEGOTIATION_LIMIT)
{ {
SSL_set_session_id_context(port->ssl, (void *) &SSL_context, SSL_set_session_id_context(port->ssl, (void *) &SSL_context,
@ -344,7 +349,8 @@ secure_write(Port *port, void *ptr, size_t len)
wloop: wloop:
n = SSL_write(port->ssl, ptr, len); n = SSL_write(port->ssl, ptr, len);
switch (SSL_get_error(port->ssl, n)) err = SSL_get_error(port->ssl, n);
switch (err)
{ {
case SSL_ERROR_NONE: case SSL_ERROR_NONE:
port->count += n; port->count += n;
@ -378,8 +384,8 @@ wloop:
default: default:
ereport(COMMERROR, ereport(COMMERROR,
(errcode(ERRCODE_PROTOCOL_VIOLATION), (errcode(ERRCODE_PROTOCOL_VIOLATION),
errmsg("unrecognized SSL error code %d", errmsg("unrecognized SSL error code: %d",
SSL_get_error(port->ssl, n)))); err)));
n = -1; n = -1;
break; break;
} }

View File

@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.50 2004/09/23 13:20:45 momjian Exp $ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.51 2004/09/23 20:27:43 tgl Exp $
* *
* NOTES * NOTES
* The client *requires* a valid server certificate. Since * The client *requires* a valid server certificate. Since
@ -297,9 +297,12 @@ pqsecure_read(PGconn *conn, void *ptr, size_t len)
#ifdef USE_SSL #ifdef USE_SSL
if (conn->ssl) if (conn->ssl)
{ {
int err;
rloop: rloop:
n = SSL_read(conn->ssl, ptr, len); n = SSL_read(conn->ssl, ptr, len);
switch (SSL_get_error(conn->ssl, n)) err = SSL_get_error(conn->ssl, n);
switch (err)
{ {
case SSL_ERROR_NONE: case SSL_ERROR_NONE:
break; break;
@ -349,7 +352,8 @@ rloop:
break; break;
default: default:
printfPQExpBuffer(&conn->errorMessage, printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("unrecognized SSL error code\n")); libpq_gettext("unrecognized SSL error code: %d\n"),
err);
n = -1; n = -1;
break; break;
} }
@ -380,8 +384,11 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
#ifdef USE_SSL #ifdef USE_SSL
if (conn->ssl) if (conn->ssl)
{ {
int err;
n = SSL_write(conn->ssl, ptr, len); n = SSL_write(conn->ssl, ptr, len);
switch (SSL_get_error(conn->ssl, n)) err = SSL_get_error(conn->ssl, n);
switch (err)
{ {
case SSL_ERROR_NONE: case SSL_ERROR_NONE:
break; break;
@ -429,7 +436,8 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
break; break;
default: default:
printfPQExpBuffer(&conn->errorMessage, printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("unrecognized SSL error code\n")); libpq_gettext("unrecognized SSL error code: %d\n"),
err);
n = -1; n = -1;
break; break;
} }
@ -1020,6 +1028,7 @@ open_client_SSL(PGconn *conn)
if (r <= 0) if (r <= 0)
{ {
int err = SSL_get_error(conn->ssl, r); int err = SSL_get_error(conn->ssl, r);
switch (err) switch (err)
{ {
case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_READ:
@ -1055,7 +1064,8 @@ open_client_SSL(PGconn *conn)
default: default:
printfPQExpBuffer(&conn->errorMessage, printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("unrecognized SSL error code (%d)\n"), err); libpq_gettext("unrecognized SSL error code: %d\n"),
err);
close_SSL(conn); close_SSL(conn);
return PGRES_POLLING_FAILED; return PGRES_POLLING_FAILED;
} }