libpq error message refactoring, part 2

This applies the new APIs to the code.

Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://www.postgresql.org/message-id/flat/7c0232ef-7b44-68db-599d-b327d0640a77@enterprisedb.com
This commit is contained in:
Peter Eisentraut 2022-11-15 11:50:04 +01:00
parent 0873b2d354
commit a9e9a9f32b
12 changed files with 463 additions and 774 deletions

View File

@ -218,14 +218,12 @@ scram_exchange(void *opaq, char *input, int inputlen,
{ {
if (inputlen == 0) if (inputlen == 0)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "malformed SCRAM message (empty message)");
libpq_gettext("malformed SCRAM message (empty message)\n"));
goto error; goto error;
} }
if (inputlen != strlen(input)) if (inputlen != strlen(input))
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "malformed SCRAM message (length mismatch)");
libpq_gettext("malformed SCRAM message (length mismatch)\n"));
goto error; goto error;
} }
} }
@ -268,15 +266,13 @@ scram_exchange(void *opaq, char *input, int inputlen,
*/ */
if (!verify_server_signature(state, success, &errstr)) if (!verify_server_signature(state, success, &errstr))
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not verify server signature: %s", errstr);
libpq_gettext("could not verify server signature: %s\n"), errstr);
goto error; goto error;
} }
if (!*success) if (!*success)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "incorrect server signature");
libpq_gettext("incorrect server signature\n"));
} }
*done = true; *done = true;
state->state = FE_SCRAM_FINISHED; state->state = FE_SCRAM_FINISHED;
@ -284,8 +280,7 @@ scram_exchange(void *opaq, char *input, int inputlen,
default: default:
/* shouldn't happen */ /* shouldn't happen */
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "invalid SCRAM exchange state");
libpq_gettext("invalid SCRAM exchange state\n"));
goto error; goto error;
} }
return; return;
@ -311,18 +306,18 @@ read_attr_value(char **input, char attr, PQExpBuffer errorMessage)
if (*begin != attr) if (*begin != attr)
{ {
appendPQExpBuffer(errorMessage, libpq_append_error(errorMessage,
libpq_gettext("malformed SCRAM message (attribute \"%c\" expected)\n"), "malformed SCRAM message (attribute \"%c\" expected)",
attr); attr);
return NULL; return NULL;
} }
begin++; begin++;
if (*begin != '=') if (*begin != '=')
{ {
appendPQExpBuffer(errorMessage, libpq_append_error(errorMessage,
libpq_gettext("malformed SCRAM message (expected character \"=\" for attribute \"%c\")\n"), "malformed SCRAM message (expected character \"=\" for attribute \"%c\")",
attr); attr);
return NULL; return NULL;
} }
begin++; begin++;
@ -361,8 +356,7 @@ build_client_first_message(fe_scram_state *state)
*/ */
if (!pg_strong_random(raw_nonce, SCRAM_RAW_NONCE_LEN)) if (!pg_strong_random(raw_nonce, SCRAM_RAW_NONCE_LEN))
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "could not generate nonce");
libpq_gettext("could not generate nonce\n"));
return NULL; return NULL;
} }
@ -371,16 +365,14 @@ build_client_first_message(fe_scram_state *state)
state->client_nonce = malloc(encoded_len + 1); state->client_nonce = malloc(encoded_len + 1);
if (state->client_nonce == NULL) if (state->client_nonce == NULL)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return NULL; return NULL;
} }
encoded_len = pg_b64_encode(raw_nonce, SCRAM_RAW_NONCE_LEN, encoded_len = pg_b64_encode(raw_nonce, SCRAM_RAW_NONCE_LEN,
state->client_nonce, encoded_len); state->client_nonce, encoded_len);
if (encoded_len < 0) if (encoded_len < 0)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "could not encode nonce");
libpq_gettext("could not encode nonce\n"));
return NULL; return NULL;
} }
state->client_nonce[encoded_len] = '\0'; state->client_nonce[encoded_len] = '\0';
@ -446,8 +438,7 @@ build_client_first_message(fe_scram_state *state)
oom_error: oom_error:
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return NULL; return NULL;
} }
@ -569,9 +560,7 @@ build_client_final_message(fe_scram_state *state)
client_proof, &errstr)) client_proof, &errstr))
{ {
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not calculate client proof: %s", errstr);
libpq_gettext("could not calculate client proof: %s\n"),
errstr);
return NULL; return NULL;
} }
@ -586,8 +575,7 @@ build_client_final_message(fe_scram_state *state)
if (encoded_len < 0) if (encoded_len < 0)
{ {
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "could not encode client proof");
libpq_gettext("could not encode client proof\n"));
return NULL; return NULL;
} }
buf.len += encoded_len; buf.len += encoded_len;
@ -602,8 +590,7 @@ build_client_final_message(fe_scram_state *state)
oom_error: oom_error:
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return NULL; return NULL;
} }
@ -623,8 +610,7 @@ read_server_first_message(fe_scram_state *state, char *input)
state->server_first_message = strdup(input); state->server_first_message = strdup(input);
if (state->server_first_message == NULL) if (state->server_first_message == NULL)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return false; return false;
} }
@ -641,16 +627,14 @@ read_server_first_message(fe_scram_state *state, char *input)
if (strlen(nonce) < strlen(state->client_nonce) || if (strlen(nonce) < strlen(state->client_nonce) ||
memcmp(nonce, state->client_nonce, strlen(state->client_nonce)) != 0) memcmp(nonce, state->client_nonce, strlen(state->client_nonce)) != 0)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "invalid SCRAM response (nonce mismatch)");
libpq_gettext("invalid SCRAM response (nonce mismatch)\n"));
return false; return false;
} }
state->nonce = strdup(nonce); state->nonce = strdup(nonce);
if (state->nonce == NULL) if (state->nonce == NULL)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return false; return false;
} }
@ -664,8 +648,7 @@ read_server_first_message(fe_scram_state *state, char *input)
state->salt = malloc(decoded_salt_len); state->salt = malloc(decoded_salt_len);
if (state->salt == NULL) if (state->salt == NULL)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return false; return false;
} }
state->saltlen = pg_b64_decode(encoded_salt, state->saltlen = pg_b64_decode(encoded_salt,
@ -674,8 +657,7 @@ read_server_first_message(fe_scram_state *state, char *input)
decoded_salt_len); decoded_salt_len);
if (state->saltlen < 0) if (state->saltlen < 0)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "malformed SCRAM message (invalid salt)");
libpq_gettext("malformed SCRAM message (invalid salt)\n"));
return false; return false;
} }
@ -688,14 +670,12 @@ read_server_first_message(fe_scram_state *state, char *input)
state->iterations = strtol(iterations_str, &endptr, 10); state->iterations = strtol(iterations_str, &endptr, 10);
if (*endptr != '\0' || state->iterations < 1) if (*endptr != '\0' || state->iterations < 1)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "malformed SCRAM message (invalid iteration count)");
libpq_gettext("malformed SCRAM message (invalid iteration count)\n"));
return false; return false;
} }
if (*input != '\0') if (*input != '\0')
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "malformed SCRAM message (garbage at end of server-first-message)");
libpq_gettext("malformed SCRAM message (garbage at end of server-first-message)\n"));
return true; return true;
} }
@ -714,8 +694,7 @@ read_server_final_message(fe_scram_state *state, char *input)
state->server_final_message = strdup(input); state->server_final_message = strdup(input);
if (!state->server_final_message) if (!state->server_final_message)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return false; return false;
} }
@ -730,9 +709,8 @@ read_server_final_message(fe_scram_state *state, char *input)
/* read_attr_value() has appended an error message */ /* read_attr_value() has appended an error message */
return false; return false;
} }
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "error received from server in SCRAM exchange: %s",
libpq_gettext("error received from server in SCRAM exchange: %s\n"), errmsg);
errmsg);
return false; return false;
} }
@ -746,15 +724,13 @@ read_server_final_message(fe_scram_state *state, char *input)
} }
if (*input != '\0') if (*input != '\0')
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "malformed SCRAM message (garbage at end of server-final-message)");
libpq_gettext("malformed SCRAM message (garbage at end of server-final-message)\n"));
server_signature_len = pg_b64_dec_len(strlen(encoded_server_signature)); server_signature_len = pg_b64_dec_len(strlen(encoded_server_signature));
decoded_server_signature = malloc(server_signature_len); decoded_server_signature = malloc(server_signature_len);
if (!decoded_server_signature) if (!decoded_server_signature)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return false; return false;
} }
@ -765,8 +741,7 @@ read_server_final_message(fe_scram_state *state, char *input)
if (server_signature_len != SCRAM_KEY_LEN) if (server_signature_len != SCRAM_KEY_LEN)
{ {
free(decoded_server_signature); free(decoded_server_signature);
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "malformed SCRAM message (invalid server signature)");
libpq_gettext("malformed SCRAM message (invalid server signature)\n"));
return false; return false;
} }
memcpy(state->ServerSignature, decoded_server_signature, SCRAM_KEY_LEN); memcpy(state->ServerSignature, decoded_server_signature, SCRAM_KEY_LEN);

View File

@ -72,8 +72,7 @@ pg_GSS_continue(PGconn *conn, int payloadlen)
ginbuf.value = malloc(payloadlen); ginbuf.value = malloc(payloadlen);
if (!ginbuf.value) if (!ginbuf.value)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory allocating GSSAPI buffer (%d)",
libpq_gettext("out of memory allocating GSSAPI buffer (%d)\n"),
payloadlen); payloadlen);
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -153,15 +152,13 @@ pg_GSS_startup(PGconn *conn, int payloadlen)
if (!(host && host[0] != '\0')) if (!(host && host[0] != '\0'))
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "host name must be specified");
libpq_gettext("host name must be specified\n"));
return STATUS_ERROR; return STATUS_ERROR;
} }
if (conn->gctx) if (conn->gctx)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "duplicate GSS authentication request");
libpq_gettext("duplicate GSS authentication request\n"));
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -225,8 +222,7 @@ pg_SSPI_continue(PGconn *conn, int payloadlen)
inputbuf = malloc(payloadlen); inputbuf = malloc(payloadlen);
if (!inputbuf) if (!inputbuf)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory allocating SSPI buffer (%d)",
libpq_gettext("out of memory allocating SSPI buffer (%d)\n"),
payloadlen); payloadlen);
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -284,8 +280,7 @@ pg_SSPI_continue(PGconn *conn, int payloadlen)
conn->sspictx = malloc(sizeof(CtxtHandle)); conn->sspictx = malloc(sizeof(CtxtHandle));
if (conn->sspictx == NULL) if (conn->sspictx == NULL)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return STATUS_ERROR; return STATUS_ERROR;
} }
memcpy(conn->sspictx, &newContext, sizeof(CtxtHandle)); memcpy(conn->sspictx, &newContext, sizeof(CtxtHandle));
@ -345,8 +340,7 @@ pg_SSPI_startup(PGconn *conn, int use_negotiate, int payloadlen)
if (conn->sspictx) if (conn->sspictx)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "duplicate SSPI authentication request");
libpq_gettext("duplicate SSPI authentication request\n"));
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -356,8 +350,7 @@ pg_SSPI_startup(PGconn *conn, int use_negotiate, int payloadlen)
conn->sspicred = malloc(sizeof(CredHandle)); conn->sspicred = malloc(sizeof(CredHandle));
if (conn->sspicred == NULL) if (conn->sspicred == NULL)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -385,15 +378,13 @@ pg_SSPI_startup(PGconn *conn, int use_negotiate, int payloadlen)
*/ */
if (!(host && host[0] != '\0')) if (!(host && host[0] != '\0'))
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "host name must be specified");
libpq_gettext("host name must be specified\n"));
return STATUS_ERROR; return STATUS_ERROR;
} }
conn->sspitarget = malloc(strlen(conn->krbsrvname) + strlen(host) + 2); conn->sspitarget = malloc(strlen(conn->krbsrvname) + strlen(host) + 2);
if (!conn->sspitarget) if (!conn->sspitarget)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return STATUS_ERROR; return STATUS_ERROR;
} }
sprintf(conn->sspitarget, "%s/%s", conn->krbsrvname, host); sprintf(conn->sspitarget, "%s/%s", conn->krbsrvname, host);
@ -427,15 +418,13 @@ pg_SASL_init(PGconn *conn, int payloadlen)
if (conn->channel_binding[0] == 'r' && /* require */ if (conn->channel_binding[0] == 'r' && /* require */
!conn->ssl_in_use) !conn->ssl_in_use)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "channel binding required, but SSL not in use");
libpq_gettext("channel binding required, but SSL not in use\n"));
goto error; goto error;
} }
if (conn->sasl_state) if (conn->sasl_state)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "duplicate SASL authentication request");
libpq_gettext("duplicate SASL authentication request\n"));
goto error; goto error;
} }
@ -493,8 +482,7 @@ pg_SASL_init(PGconn *conn, int payloadlen)
*/ */
if (conn->channel_binding[0] == 'r') /* require */ if (conn->channel_binding[0] == 'r') /* require */
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "channel binding is required, but client does not support it");
libpq_gettext("channel binding is required, but client does not support it\n"));
goto error; goto error;
} }
#endif #endif
@ -510,8 +498,7 @@ pg_SASL_init(PGconn *conn, int payloadlen)
* the client and server supported it. The SCRAM exchange * the client and server supported it. The SCRAM exchange
* checks for that, to prevent downgrade attacks. * checks for that, to prevent downgrade attacks.
*/ */
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "server offered SCRAM-SHA-256-PLUS authentication over a non-SSL connection");
libpq_gettext("server offered SCRAM-SHA-256-PLUS authentication over a non-SSL connection\n"));
goto error; goto error;
} }
} }
@ -525,16 +512,14 @@ pg_SASL_init(PGconn *conn, int payloadlen)
if (!selected_mechanism) if (!selected_mechanism)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "none of the server's SASL authentication mechanisms are supported");
libpq_gettext("none of the server's SASL authentication mechanisms are supported\n"));
goto error; goto error;
} }
if (conn->channel_binding[0] == 'r' && /* require */ if (conn->channel_binding[0] == 'r' && /* require */
strcmp(selected_mechanism, SCRAM_SHA_256_PLUS_NAME) != 0) strcmp(selected_mechanism, SCRAM_SHA_256_PLUS_NAME) != 0)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "channel binding is required, but server did not offer an authentication method that supports channel binding");
libpq_gettext("channel binding is required, but server did not offer an authentication method that supports channel binding\n"));
goto error; goto error;
} }
@ -614,8 +599,7 @@ error:
oom_error: oom_error:
termPQExpBuffer(&mechanism_buf); termPQExpBuffer(&mechanism_buf);
free(initialresponse); free(initialresponse);
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -638,8 +622,7 @@ pg_SASL_continue(PGconn *conn, int payloadlen, bool final)
challenge = malloc(payloadlen + 1); challenge = malloc(payloadlen + 1);
if (!challenge) if (!challenge)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory allocating SASL buffer (%d)",
libpq_gettext("out of memory allocating SASL buffer (%d)\n"),
payloadlen); payloadlen);
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -663,8 +646,7 @@ pg_SASL_continue(PGconn *conn, int payloadlen, bool final)
if (outputlen != 0) if (outputlen != 0)
free(output); free(output);
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "AuthenticationSASLFinal received from server, but SASL authentication was not completed");
libpq_gettext("AuthenticationSASLFinal received from server, but SASL authentication was not completed\n"));
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -674,8 +656,7 @@ pg_SASL_continue(PGconn *conn, int payloadlen, bool final)
*/ */
if (output == NULL && !done) if (output == NULL && !done)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "no client response found after SASL exchange success");
libpq_gettext("no client response found after SASL exchange success\n"));
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -756,8 +737,7 @@ pg_local_sendauth(PGconn *conn)
} }
return STATUS_OK; return STATUS_OK;
#else #else
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "SCM_CRED authentication method not supported");
libpq_gettext("SCM_CRED authentication method not supported\n"));
return STATUS_ERROR; return STATUS_ERROR;
#endif #endif
} }
@ -790,8 +770,7 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
crypt_pwd = malloc(2 * (MD5_PASSWD_LEN + 1)); crypt_pwd = malloc(2 * (MD5_PASSWD_LEN + 1));
if (!crypt_pwd) if (!crypt_pwd)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -800,18 +779,14 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
strlen(conn->pguser), crypt_pwd2, strlen(conn->pguser), crypt_pwd2,
&errstr)) &errstr))
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not encrypt password: %s", errstr);
libpq_gettext("could not encrypt password: %s\n"),
errstr);
free(crypt_pwd); free(crypt_pwd);
return STATUS_ERROR; return STATUS_ERROR;
} }
if (!pg_md5_encrypt(crypt_pwd2 + strlen("md5"), md5Salt, if (!pg_md5_encrypt(crypt_pwd2 + strlen("md5"), md5Salt,
4, crypt_pwd, &errstr)) 4, crypt_pwd, &errstr))
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not encrypt password: %s", errstr);
libpq_gettext("could not encrypt password: %s\n"),
errstr);
free(crypt_pwd); free(crypt_pwd);
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -858,14 +833,12 @@ check_expected_areq(AuthRequest areq, PGconn *conn)
case AUTH_REQ_OK: case AUTH_REQ_OK:
if (!conn->sasl || !conn->sasl->channel_bound(conn->sasl_state)) if (!conn->sasl || !conn->sasl->channel_bound(conn->sasl_state))
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "channel binding required, but server authenticated client without channel binding");
libpq_gettext("channel binding required, but server authenticated client without channel binding\n"));
result = false; result = false;
} }
break; break;
default: default:
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "channel binding required but not supported by server's authentication request");
libpq_gettext("channel binding required but not supported by server's authentication request\n"));
result = false; result = false;
break; break;
} }
@ -899,13 +872,11 @@ pg_fe_sendauth(AuthRequest areq, int payloadlen, PGconn *conn)
break; break;
case AUTH_REQ_KRB4: case AUTH_REQ_KRB4:
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "Kerberos 4 authentication not supported");
libpq_gettext("Kerberos 4 authentication not supported\n"));
return STATUS_ERROR; return STATUS_ERROR;
case AUTH_REQ_KRB5: case AUTH_REQ_KRB5:
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "Kerberos 5 authentication not supported");
libpq_gettext("Kerberos 5 authentication not supported\n"));
return STATUS_ERROR; return STATUS_ERROR;
#if defined(ENABLE_GSS) || defined(ENABLE_SSPI) #if defined(ENABLE_GSS) || defined(ENABLE_SSPI)
@ -975,8 +946,7 @@ pg_fe_sendauth(AuthRequest areq, int payloadlen, PGconn *conn)
/* No GSSAPI *or* SSPI support */ /* No GSSAPI *or* SSPI support */
case AUTH_REQ_GSS: case AUTH_REQ_GSS:
case AUTH_REQ_GSS_CONT: case AUTH_REQ_GSS_CONT:
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "GSSAPI authentication not supported");
libpq_gettext("GSSAPI authentication not supported\n"));
return STATUS_ERROR; return STATUS_ERROR;
#endif /* defined(ENABLE_GSS) || defined(ENABLE_SSPI) */ #endif /* defined(ENABLE_GSS) || defined(ENABLE_SSPI) */
@ -1007,16 +977,14 @@ pg_fe_sendauth(AuthRequest areq, int payloadlen, PGconn *conn)
*/ */
#if !defined(ENABLE_GSS) #if !defined(ENABLE_GSS)
case AUTH_REQ_SSPI: case AUTH_REQ_SSPI:
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "SSPI authentication not supported");
libpq_gettext("SSPI authentication not supported\n"));
return STATUS_ERROR; return STATUS_ERROR;
#endif /* !define(ENABLE_GSS) */ #endif /* !define(ENABLE_GSS) */
#endif /* ENABLE_SSPI */ #endif /* ENABLE_SSPI */
case AUTH_REQ_CRYPT: case AUTH_REQ_CRYPT:
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "Crypt authentication not supported");
libpq_gettext("Crypt authentication not supported\n"));
return STATUS_ERROR; return STATUS_ERROR;
case AUTH_REQ_MD5: case AUTH_REQ_MD5:
@ -1082,8 +1050,7 @@ pg_fe_sendauth(AuthRequest areq, int payloadlen, PGconn *conn)
break; break;
default: default:
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "authentication method %u not supported", areq);
libpq_gettext("authentication method %u not supported\n"), areq);
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -1128,9 +1095,9 @@ pg_fe_getusername(uid_t user_id, PQExpBuffer errorMessage)
if (GetUserName(username, &namesize)) if (GetUserName(username, &namesize))
name = username; name = username;
else if (errorMessage) else if (errorMessage)
appendPQExpBuffer(errorMessage, libpq_append_error(errorMessage,
libpq_gettext("user name lookup failure: error code %lu\n"), "user name lookup failure: error code %lu",
GetLastError()); GetLastError());
#else #else
if (pg_get_user_name(user_id, pwdbuf, sizeof(pwdbuf))) if (pg_get_user_name(user_id, pwdbuf, sizeof(pwdbuf)))
name = pwdbuf; name = pwdbuf;
@ -1142,8 +1109,7 @@ pg_fe_getusername(uid_t user_id, PQExpBuffer errorMessage)
{ {
result = strdup(name); result = strdup(name);
if (result == NULL && errorMessage) if (result == NULL && errorMessage)
appendPQExpBufferStr(errorMessage, libpq_append_error(errorMessage, "out of memory");
libpq_gettext("out of memory\n"));
} }
pgunlock_thread(); pgunlock_thread();
@ -1254,8 +1220,7 @@ PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user,
if (PQntuples(res) != 1 || PQnfields(res) != 1) if (PQntuples(res) != 1 || PQnfields(res) != 1)
{ {
PQclear(res); PQclear(res);
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "unexpected shape of result set returned for SHOW");
libpq_gettext("unexpected shape of result set returned for SHOW\n"));
return NULL; return NULL;
} }
val = PQgetvalue(res, 0, 0); val = PQgetvalue(res, 0, 0);
@ -1263,8 +1228,7 @@ PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user,
if (strlen(val) > MAX_ALGORITHM_NAME_LEN) if (strlen(val) > MAX_ALGORITHM_NAME_LEN)
{ {
PQclear(res); PQclear(res);
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "password_encryption value too long");
libpq_gettext("password_encryption value too long\n"));
return NULL; return NULL;
} }
strcpy(algobuf, val); strcpy(algobuf, val);
@ -1291,9 +1255,7 @@ PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user,
crypt_pwd = pg_fe_scram_build_secret(passwd, &errstr); crypt_pwd = pg_fe_scram_build_secret(passwd, &errstr);
if (!crypt_pwd) if (!crypt_pwd)
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not encrypt password: %s", errstr);
libpq_gettext("could not encrypt password: %s\n"),
errstr);
} }
else if (strcmp(algorithm, "md5") == 0) else if (strcmp(algorithm, "md5") == 0)
{ {
@ -1304,21 +1266,17 @@ PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user,
if (!pg_md5_encrypt(passwd, user, strlen(user), crypt_pwd, &errstr)) if (!pg_md5_encrypt(passwd, user, strlen(user), crypt_pwd, &errstr))
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not encrypt password: %s", errstr);
libpq_gettext("could not encrypt password: %s\n"),
errstr);
free(crypt_pwd); free(crypt_pwd);
crypt_pwd = NULL; crypt_pwd = NULL;
} }
} }
else else
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
} }
else else
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "unrecognized password encryption algorithm \"%s\"",
libpq_gettext("unrecognized password encryption algorithm \"%s\"\n"),
algorithm); algorithm);
return NULL; return NULL;
} }

File diff suppressed because it is too large Load Diff

View File

@ -828,8 +828,7 @@ pqSaveWriteError(PGconn *conn)
conn->write_err_msg[0] = '\0'; conn->write_err_msg[0] = '\0';
} }
else else
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "write to server failed");
libpq_gettext("write to server failed\n"));
pqSaveErrorResult(conn); pqSaveErrorResult(conn);
} }
@ -867,8 +866,7 @@ pqPrepareAsyncResult(PGconn *conn)
* text. * text.
*/ */
if (!conn->error_result) if (!conn->error_result)
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "no error text available");
libpq_gettext("no error text available\n"));
/* Paranoia: be sure errorReported offset is sane */ /* Paranoia: be sure errorReported offset is sane */
if (conn->errorReported < 0 || if (conn->errorReported < 0 ||
@ -1316,8 +1314,7 @@ pqAllocCmdQueueEntry(PGconn *conn)
entry = (PGcmdQueueEntry *) malloc(sizeof(PGcmdQueueEntry)); entry = (PGcmdQueueEntry *) malloc(sizeof(PGcmdQueueEntry));
if (entry == NULL) if (entry == NULL)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return NULL; return NULL;
} }
} }
@ -1440,15 +1437,13 @@ PQsendQueryInternal(PGconn *conn, const char *query, bool newQuery)
/* check the argument */ /* check the argument */
if (!query) if (!query)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "command string is a null pointer");
libpq_gettext("command string is a null pointer\n"));
return 0; return 0;
} }
if (conn->pipelineStatus != PQ_PIPELINE_OFF) if (conn->pipelineStatus != PQ_PIPELINE_OFF)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "%s not allowed in pipeline mode",
libpq_gettext("%s not allowed in pipeline mode\n"),
"PQsendQuery"); "PQsendQuery");
return 0; return 0;
} }
@ -1511,15 +1506,13 @@ PQsendQueryParams(PGconn *conn,
/* check the arguments */ /* check the arguments */
if (!command) if (!command)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "command string is a null pointer");
libpq_gettext("command string is a null pointer\n"));
return 0; return 0;
} }
if (nParams < 0 || nParams > PQ_QUERY_PARAM_MAX_LIMIT) if (nParams < 0 || nParams > PQ_QUERY_PARAM_MAX_LIMIT)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "number of parameters must be between 0 and %d",
libpq_gettext("number of parameters must be between 0 and %d\n"), PQ_QUERY_PARAM_MAX_LIMIT);
PQ_QUERY_PARAM_MAX_LIMIT);
return 0; return 0;
} }
@ -1554,21 +1547,18 @@ PQsendPrepare(PGconn *conn,
/* check the arguments */ /* check the arguments */
if (!stmtName) if (!stmtName)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "statement name is a null pointer");
libpq_gettext("statement name is a null pointer\n"));
return 0; return 0;
} }
if (!query) if (!query)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "command string is a null pointer");
libpq_gettext("command string is a null pointer\n"));
return 0; return 0;
} }
if (nParams < 0 || nParams > PQ_QUERY_PARAM_MAX_LIMIT) if (nParams < 0 || nParams > PQ_QUERY_PARAM_MAX_LIMIT)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "number of parameters must be between 0 and %d",
libpq_gettext("number of parameters must be between 0 and %d\n"), PQ_QUERY_PARAM_MAX_LIMIT);
PQ_QUERY_PARAM_MAX_LIMIT);
return 0; return 0;
} }
@ -1656,15 +1646,13 @@ PQsendQueryPrepared(PGconn *conn,
/* check the arguments */ /* check the arguments */
if (!stmtName) if (!stmtName)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "statement name is a null pointer");
libpq_gettext("statement name is a null pointer\n"));
return 0; return 0;
} }
if (nParams < 0 || nParams > PQ_QUERY_PARAM_MAX_LIMIT) if (nParams < 0 || nParams > PQ_QUERY_PARAM_MAX_LIMIT)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "number of parameters must be between 0 and %d",
libpq_gettext("number of parameters must be between 0 and %d\n"), PQ_QUERY_PARAM_MAX_LIMIT);
PQ_QUERY_PARAM_MAX_LIMIT);
return 0; return 0;
} }
@ -1700,8 +1688,7 @@ PQsendQueryStart(PGconn *conn, bool newQuery)
/* Don't try to send if we know there's no live connection. */ /* Don't try to send if we know there's no live connection. */
if (conn->status != CONNECTION_OK) if (conn->status != CONNECTION_OK)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "no connection to the server");
libpq_gettext("no connection to the server\n"));
return false; return false;
} }
@ -1709,8 +1696,7 @@ PQsendQueryStart(PGconn *conn, bool newQuery)
if (conn->asyncStatus != PGASYNC_IDLE && if (conn->asyncStatus != PGASYNC_IDLE &&
conn->pipelineStatus == PQ_PIPELINE_OFF) conn->pipelineStatus == PQ_PIPELINE_OFF)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "another command is already in progress");
libpq_gettext("another command is already in progress\n"));
return false; return false;
} }
@ -1740,8 +1726,7 @@ PQsendQueryStart(PGconn *conn, bool newQuery)
case PGASYNC_COPY_IN: case PGASYNC_COPY_IN:
case PGASYNC_COPY_OUT: case PGASYNC_COPY_OUT:
case PGASYNC_COPY_BOTH: case PGASYNC_COPY_BOTH:
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "cannot queue commands during COPY");
libpq_gettext("cannot queue commands during COPY\n"));
return false; return false;
} }
} }
@ -1858,8 +1843,7 @@ PQsendQueryGuts(PGconn *conn,
nbytes = paramLengths[i]; nbytes = paramLengths[i];
else else
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "length must be given for binary parameter");
libpq_gettext("length must be given for binary parameter\n"));
goto sendFailed; goto sendFailed;
} }
} }
@ -2181,9 +2165,7 @@ PQgetResult(PGconn *conn)
res = getCopyResult(conn, PGRES_COPY_BOTH); res = getCopyResult(conn, PGRES_COPY_BOTH);
break; break;
default: default:
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "unexpected asyncStatus: %d", (int) conn->asyncStatus);
libpq_gettext("unexpected asyncStatus: %d\n"),
(int) conn->asyncStatus);
pqSaveErrorResult(conn); pqSaveErrorResult(conn);
conn->asyncStatus = PGASYNC_IDLE; /* try to restore valid state */ conn->asyncStatus = PGASYNC_IDLE; /* try to restore valid state */
res = pqPrepareAsyncResult(conn); res = pqPrepareAsyncResult(conn);
@ -2339,8 +2321,7 @@ PQexecStart(PGconn *conn)
if (conn->pipelineStatus != PQ_PIPELINE_OFF) if (conn->pipelineStatus != PQ_PIPELINE_OFF)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "synchronous command execution functions are not allowed in pipeline mode");
libpq_gettext("synchronous command execution functions are not allowed in pipeline mode\n"));
return false; return false;
} }
@ -2373,8 +2354,7 @@ PQexecStart(PGconn *conn)
else if (resultStatus == PGRES_COPY_BOTH) else if (resultStatus == PGRES_COPY_BOTH)
{ {
/* We don't allow PQexec during COPY BOTH */ /* We don't allow PQexec during COPY BOTH */
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "PQexec not allowed during COPY BOTH");
libpq_gettext("PQexec not allowed during COPY BOTH\n"));
return false; return false;
} }
/* check for loss of connection, too */ /* check for loss of connection, too */
@ -2600,8 +2580,7 @@ PQputCopyData(PGconn *conn, const char *buffer, int nbytes)
if (conn->asyncStatus != PGASYNC_COPY_IN && if (conn->asyncStatus != PGASYNC_COPY_IN &&
conn->asyncStatus != PGASYNC_COPY_BOTH) conn->asyncStatus != PGASYNC_COPY_BOTH)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "no COPY in progress");
libpq_gettext("no COPY in progress\n"));
return -1; return -1;
} }
@ -2656,8 +2635,7 @@ PQputCopyEnd(PGconn *conn, const char *errormsg)
if (conn->asyncStatus != PGASYNC_COPY_IN && if (conn->asyncStatus != PGASYNC_COPY_IN &&
conn->asyncStatus != PGASYNC_COPY_BOTH) conn->asyncStatus != PGASYNC_COPY_BOTH)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "no COPY in progress");
libpq_gettext("no COPY in progress\n"));
return -1; return -1;
} }
@ -2725,8 +2703,7 @@ PQgetCopyData(PGconn *conn, char **buffer, int async)
if (conn->asyncStatus != PGASYNC_COPY_OUT && if (conn->asyncStatus != PGASYNC_COPY_OUT &&
conn->asyncStatus != PGASYNC_COPY_BOTH) conn->asyncStatus != PGASYNC_COPY_BOTH)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "no COPY in progress");
libpq_gettext("no COPY in progress\n"));
return -2; return -2;
} }
return pqGetCopyData3(conn, buffer, async); return pqGetCopyData3(conn, buffer, async);
@ -2905,17 +2882,14 @@ PQfn(PGconn *conn,
if (conn->pipelineStatus != PQ_PIPELINE_OFF) if (conn->pipelineStatus != PQ_PIPELINE_OFF)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "%s not allowed in pipeline mode", "PQfn");
libpq_gettext("%s not allowed in pipeline mode\n"),
"PQfn");
return NULL; return NULL;
} }
if (conn->sock == PGINVALID_SOCKET || conn->asyncStatus != PGASYNC_IDLE || if (conn->sock == PGINVALID_SOCKET || conn->asyncStatus != PGASYNC_IDLE ||
pgHavePendingResult(conn)) pgHavePendingResult(conn))
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "connection in wrong state");
libpq_gettext("connection in wrong state\n"));
return NULL; return NULL;
} }
@ -2958,8 +2932,7 @@ PQenterPipelineMode(PGconn *conn)
if (conn->asyncStatus != PGASYNC_IDLE) if (conn->asyncStatus != PGASYNC_IDLE)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "cannot enter pipeline mode, connection not idle");
libpq_gettext("cannot enter pipeline mode, connection not idle\n"));
return 0; return 0;
} }
@ -2995,13 +2968,11 @@ PQexitPipelineMode(PGconn *conn)
case PGASYNC_READY: case PGASYNC_READY:
case PGASYNC_READY_MORE: case PGASYNC_READY_MORE:
/* there are some uncollected results */ /* there are some uncollected results */
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "cannot exit pipeline mode with uncollected results");
libpq_gettext("cannot exit pipeline mode with uncollected results\n"));
return 0; return 0;
case PGASYNC_BUSY: case PGASYNC_BUSY:
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "cannot exit pipeline mode while busy");
libpq_gettext("cannot exit pipeline mode while busy\n"));
return 0; return 0;
case PGASYNC_IDLE: case PGASYNC_IDLE:
@ -3012,15 +2983,13 @@ PQexitPipelineMode(PGconn *conn)
case PGASYNC_COPY_IN: case PGASYNC_COPY_IN:
case PGASYNC_COPY_OUT: case PGASYNC_COPY_OUT:
case PGASYNC_COPY_BOTH: case PGASYNC_COPY_BOTH:
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "cannot exit pipeline mode while in COPY");
libpq_gettext("cannot exit pipeline mode while in COPY\n"));
} }
/* still work to process */ /* still work to process */
if (conn->cmd_queue_head != NULL) if (conn->cmd_queue_head != NULL)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "cannot exit pipeline mode with uncollected results");
libpq_gettext("cannot exit pipeline mode with uncollected results\n"));
return 0; return 0;
} }
@ -3135,8 +3104,7 @@ pqPipelineProcessQueue(PGconn *conn)
conn->result = PQmakeEmptyPGresult(conn, PGRES_PIPELINE_ABORTED); conn->result = PQmakeEmptyPGresult(conn, PGRES_PIPELINE_ABORTED);
if (!conn->result) if (!conn->result)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
pqSaveErrorResult(conn); pqSaveErrorResult(conn);
return; return;
} }
@ -3179,8 +3147,7 @@ PQpipelineSync(PGconn *conn)
if (conn->pipelineStatus == PQ_PIPELINE_OFF) if (conn->pipelineStatus == PQ_PIPELINE_OFF)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "cannot send pipeline when not in pipeline mode");
libpq_gettext("cannot send pipeline when not in pipeline mode\n"));
return 0; return 0;
} }
@ -3246,8 +3213,7 @@ PQsendFlushRequest(PGconn *conn)
/* Don't try to send if we know there's no live connection. */ /* Don't try to send if we know there's no live connection. */
if (conn->status != CONNECTION_OK) if (conn->status != CONNECTION_OK)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "no connection to the server");
libpq_gettext("no connection to the server\n"));
return 0; return 0;
} }
@ -3255,8 +3221,7 @@ PQsendFlushRequest(PGconn *conn)
if (conn->asyncStatus != PGASYNC_IDLE && if (conn->asyncStatus != PGASYNC_IDLE &&
conn->pipelineStatus == PQ_PIPELINE_OFF) conn->pipelineStatus == PQ_PIPELINE_OFF)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "another command is already in progress");
libpq_gettext("another command is already in progress\n"));
return 0; return 0;
} }
@ -3992,8 +3957,7 @@ PQescapeStringInternal(PGconn *conn,
if (error) if (error)
*error = 1; *error = 1;
if (conn) if (conn)
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "incomplete multibyte character");
libpq_gettext("incomplete multibyte character\n"));
for (; i < len; i++) for (; i < len; i++)
{ {
if (((size_t) (target - to)) / 2 >= length) if (((size_t) (target - to)) / 2 >= length)
@ -4083,8 +4047,7 @@ PQescapeInternal(PGconn *conn, const char *str, size_t len, bool as_ident)
/* Multibyte character overruns allowable length. */ /* Multibyte character overruns allowable length. */
if ((s - str) + charlen > len || memchr(s, 0, charlen) != NULL) if ((s - str) + charlen > len || memchr(s, 0, charlen) != NULL)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "incomplete multibyte character");
libpq_gettext("incomplete multibyte character\n"));
return NULL; return NULL;
} }
@ -4101,8 +4064,7 @@ PQescapeInternal(PGconn *conn, const char *str, size_t len, bool as_ident)
result = rp = (char *) malloc(result_size); result = rp = (char *) malloc(result_size);
if (rp == NULL) if (rp == NULL)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return NULL; return NULL;
} }
@ -4266,8 +4228,7 @@ PQescapeByteaInternal(PGconn *conn,
if (rp == NULL) if (rp == NULL)
{ {
if (conn) if (conn)
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return NULL; return NULL;
} }

View File

@ -94,8 +94,7 @@ pg_GSS_load_servicename(PGconn *conn)
host = PQhost(conn); host = PQhost(conn);
if (!(host && host[0] != '\0')) if (!(host && host[0] != '\0'))
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "host name must be specified");
libpq_gettext("host name must be specified\n"));
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -107,8 +106,7 @@ pg_GSS_load_servicename(PGconn *conn)
temp_gbuf.value = (char *) malloc(maxlen); temp_gbuf.value = (char *) malloc(maxlen);
if (!temp_gbuf.value) if (!temp_gbuf.value)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return STATUS_ERROR; return STATUS_ERROR;
} }
snprintf(temp_gbuf.value, maxlen, "%s@%s", snprintf(temp_gbuf.value, maxlen, "%s@%s",

View File

@ -141,8 +141,7 @@ lo_truncate(PGconn *conn, int fd, size_t len)
/* Must check this on-the-fly because it's not there pre-8.3 */ /* Must check this on-the-fly because it's not there pre-8.3 */
if (conn->lobjfuncs->fn_lo_truncate == 0) if (conn->lobjfuncs->fn_lo_truncate == 0)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "cannot determine OID of function %s",
libpq_gettext("cannot determine OID of function %s\n"),
"lo_truncate"); "lo_truncate");
return -1; return -1;
} }
@ -158,8 +157,7 @@ lo_truncate(PGconn *conn, int fd, size_t len)
*/ */
if (len > (size_t) INT_MAX) if (len > (size_t) INT_MAX)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "argument of lo_truncate exceeds integer range");
libpq_gettext("argument of lo_truncate exceeds integer range\n"));
return -1; return -1;
} }
@ -206,8 +204,7 @@ lo_truncate64(PGconn *conn, int fd, pg_int64 len)
if (conn->lobjfuncs->fn_lo_truncate64 == 0) if (conn->lobjfuncs->fn_lo_truncate64 == 0)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "cannot determine OID of function %s",
libpq_gettext("cannot determine OID of function %s\n"),
"lo_truncate64"); "lo_truncate64");
return -1; return -1;
} }
@ -262,8 +259,7 @@ lo_read(PGconn *conn, int fd, char *buf, size_t len)
*/ */
if (len > (size_t) INT_MAX) if (len > (size_t) INT_MAX)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "argument of lo_read exceeds integer range");
libpq_gettext("argument of lo_read exceeds integer range\n"));
return -1; return -1;
} }
@ -314,8 +310,7 @@ lo_write(PGconn *conn, int fd, const char *buf, size_t len)
*/ */
if (len > (size_t) INT_MAX) if (len > (size_t) INT_MAX)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "argument of lo_write exceeds integer range");
libpq_gettext("argument of lo_write exceeds integer range\n"));
return -1; return -1;
} }
@ -399,8 +394,7 @@ lo_lseek64(PGconn *conn, int fd, pg_int64 offset, int whence)
if (conn->lobjfuncs->fn_lo_lseek64 == 0) if (conn->lobjfuncs->fn_lo_lseek64 == 0)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "cannot determine OID of function %s",
libpq_gettext("cannot determine OID of function %s\n"),
"lo_lseek64"); "lo_lseek64");
return -1; return -1;
} }
@ -490,8 +484,7 @@ lo_create(PGconn *conn, Oid lobjId)
/* Must check this on-the-fly because it's not there pre-8.1 */ /* Must check this on-the-fly because it's not there pre-8.1 */
if (conn->lobjfuncs->fn_lo_create == 0) if (conn->lobjfuncs->fn_lo_create == 0)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "cannot determine OID of function %s",
libpq_gettext("cannot determine OID of function %s\n"),
"lo_create"); "lo_create");
return InvalidOid; return InvalidOid;
} }
@ -564,8 +557,7 @@ lo_tell64(PGconn *conn, int fd)
if (conn->lobjfuncs->fn_lo_tell64 == 0) if (conn->lobjfuncs->fn_lo_tell64 == 0)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "cannot determine OID of function %s",
libpq_gettext("cannot determine OID of function %s\n"),
"lo_tell64"); "lo_tell64");
return -1; return -1;
} }
@ -674,8 +666,7 @@ lo_import_internal(PGconn *conn, const char *filename, Oid oid)
fd = open(filename, O_RDONLY | PG_BINARY, 0666); fd = open(filename, O_RDONLY | PG_BINARY, 0666);
if (fd < 0) if (fd < 0)
{ /* error */ { /* error */
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not open file \"%s\": %s",
libpq_gettext("could not open file \"%s\": %s\n"),
filename, strerror_r(errno, sebuf, sizeof(sebuf))); filename, strerror_r(errno, sebuf, sizeof(sebuf)));
return InvalidOid; return InvalidOid;
} }
@ -731,8 +722,7 @@ lo_import_internal(PGconn *conn, const char *filename, Oid oid)
(void) close(fd); (void) close(fd);
/* deliberately overwrite any error from lo_close */ /* deliberately overwrite any error from lo_close */
pqClearConnErrorState(conn); pqClearConnErrorState(conn);
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not read from file \"%s\": %s",
libpq_gettext("could not read from file \"%s\": %s\n"),
filename, filename,
strerror_r(save_errno, sebuf, sizeof(sebuf))); strerror_r(save_errno, sebuf, sizeof(sebuf)));
return InvalidOid; return InvalidOid;
@ -787,8 +777,7 @@ lo_export(PGconn *conn, Oid lobjId, const char *filename)
(void) lo_close(conn, lobj); (void) lo_close(conn, lobj);
/* deliberately overwrite any error from lo_close */ /* deliberately overwrite any error from lo_close */
pqClearConnErrorState(conn); pqClearConnErrorState(conn);
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not open file \"%s\": %s",
libpq_gettext("could not open file \"%s\": %s\n"),
filename, filename,
strerror_r(save_errno, sebuf, sizeof(sebuf))); strerror_r(save_errno, sebuf, sizeof(sebuf)));
return -1; return -1;
@ -809,8 +798,7 @@ lo_export(PGconn *conn, Oid lobjId, const char *filename)
(void) close(fd); (void) close(fd);
/* deliberately overwrite any error from lo_close */ /* deliberately overwrite any error from lo_close */
pqClearConnErrorState(conn); pqClearConnErrorState(conn);
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not write to file \"%s\": %s",
libpq_gettext("could not write to file \"%s\": %s\n"),
filename, filename,
strerror_r(save_errno, sebuf, sizeof(sebuf))); strerror_r(save_errno, sebuf, sizeof(sebuf)));
return -1; return -1;
@ -833,8 +821,7 @@ lo_export(PGconn *conn, Oid lobjId, const char *filename)
/* if we already failed, don't overwrite that msg with a close error */ /* if we already failed, don't overwrite that msg with a close error */
if (close(fd) != 0 && result >= 0) if (close(fd) != 0 && result >= 0)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not write to file \"%s\": %s",
libpq_gettext("could not write to file \"%s\": %s\n"),
filename, strerror_r(errno, sebuf, sizeof(sebuf))); filename, strerror_r(errno, sebuf, sizeof(sebuf)));
result = -1; result = -1;
} }
@ -880,8 +867,7 @@ lo_initialize(PGconn *conn)
lobjfuncs = (PGlobjfuncs *) malloc(sizeof(PGlobjfuncs)); lobjfuncs = (PGlobjfuncs *) malloc(sizeof(PGlobjfuncs));
if (lobjfuncs == NULL) if (lobjfuncs == NULL)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return -1; return -1;
} }
MemSet((char *) lobjfuncs, 0, sizeof(PGlobjfuncs)); MemSet((char *) lobjfuncs, 0, sizeof(PGlobjfuncs));
@ -919,8 +905,7 @@ lo_initialize(PGconn *conn)
{ {
free(lobjfuncs); free(lobjfuncs);
PQclear(res); PQclear(res);
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "query to initialize large object functions did not return data");
libpq_gettext("query to initialize large object functions did not return data\n"));
return -1; return -1;
} }
@ -968,64 +953,56 @@ lo_initialize(PGconn *conn)
*/ */
if (lobjfuncs->fn_lo_open == 0) if (lobjfuncs->fn_lo_open == 0)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "cannot determine OID of function %s",
libpq_gettext("cannot determine OID of function %s\n"),
"lo_open"); "lo_open");
free(lobjfuncs); free(lobjfuncs);
return -1; return -1;
} }
if (lobjfuncs->fn_lo_close == 0) if (lobjfuncs->fn_lo_close == 0)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "cannot determine OID of function %s",
libpq_gettext("cannot determine OID of function %s\n"),
"lo_close"); "lo_close");
free(lobjfuncs); free(lobjfuncs);
return -1; return -1;
} }
if (lobjfuncs->fn_lo_creat == 0) if (lobjfuncs->fn_lo_creat == 0)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "cannot determine OID of function %s",
libpq_gettext("cannot determine OID of function %s\n"),
"lo_creat"); "lo_creat");
free(lobjfuncs); free(lobjfuncs);
return -1; return -1;
} }
if (lobjfuncs->fn_lo_unlink == 0) if (lobjfuncs->fn_lo_unlink == 0)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "cannot determine OID of function %s",
libpq_gettext("cannot determine OID of function %s\n"),
"lo_unlink"); "lo_unlink");
free(lobjfuncs); free(lobjfuncs);
return -1; return -1;
} }
if (lobjfuncs->fn_lo_lseek == 0) if (lobjfuncs->fn_lo_lseek == 0)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "cannot determine OID of function %s",
libpq_gettext("cannot determine OID of function %s\n"),
"lo_lseek"); "lo_lseek");
free(lobjfuncs); free(lobjfuncs);
return -1; return -1;
} }
if (lobjfuncs->fn_lo_tell == 0) if (lobjfuncs->fn_lo_tell == 0)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "cannot determine OID of function %s",
libpq_gettext("cannot determine OID of function %s\n"),
"lo_tell"); "lo_tell");
free(lobjfuncs); free(lobjfuncs);
return -1; return -1;
} }
if (lobjfuncs->fn_lo_read == 0) if (lobjfuncs->fn_lo_read == 0)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "cannot determine OID of function %s",
libpq_gettext("cannot determine OID of function %s\n"),
"loread"); "loread");
free(lobjfuncs); free(lobjfuncs);
return -1; return -1;
} }
if (lobjfuncs->fn_lo_write == 0) if (lobjfuncs->fn_lo_write == 0)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "cannot determine OID of function %s",
libpq_gettext("cannot determine OID of function %s\n"),
"lowrite"); "lowrite");
free(lobjfuncs); free(lobjfuncs);
return -1; return -1;

View File

@ -570,8 +570,7 @@ pqReadData(PGconn *conn)
if (conn->sock == PGINVALID_SOCKET) if (conn->sock == PGINVALID_SOCKET)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "connection not open");
libpq_gettext("connection not open\n"));
return -1; return -1;
} }
@ -749,10 +748,9 @@ retry4:
* means the connection has been closed. Cope. * means the connection has been closed. Cope.
*/ */
definitelyEOF: definitelyEOF:
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "server closed the connection unexpectedly\n"
libpq_gettext("server closed the connection unexpectedly\n" "\tThis probably means the server terminated abnormally\n"
"\tThis probably means the server terminated abnormally\n" "\tbefore or while processing the request.");
"\tbefore or while processing the request.\n"));
/* Come here if lower-level code already set a suitable errorMessage */ /* Come here if lower-level code already set a suitable errorMessage */
definitelyFailed: definitelyFailed:
@ -1002,8 +1000,7 @@ pqWaitTimed(int forRead, int forWrite, PGconn *conn, time_t finish_time)
if (result == 0) if (result == 0)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "timeout expired");
libpq_gettext("timeout expired\n"));
return 1; return 1;
} }
@ -1047,8 +1044,7 @@ pqSocketCheck(PGconn *conn, int forRead, int forWrite, time_t end_time)
return -1; return -1;
if (conn->sock == PGINVALID_SOCKET) if (conn->sock == PGINVALID_SOCKET)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "invalid socket");
libpq_gettext("invalid socket\n"));
return -1; return -1;
} }
@ -1070,9 +1066,7 @@ pqSocketCheck(PGconn *conn, int forRead, int forWrite, time_t end_time)
{ {
char sebuf[PG_STRERROR_R_BUFLEN]; char sebuf[PG_STRERROR_R_BUFLEN];
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "%s() failed: %s", "select",
libpq_gettext("%s() failed: %s\n"),
"select",
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
} }

View File

@ -201,8 +201,7 @@ pqParseInput3(PGconn *conn)
PGRES_COMMAND_OK); PGRES_COMMAND_OK);
if (!conn->result) if (!conn->result)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
pqSaveErrorResult(conn); pqSaveErrorResult(conn);
} }
} }
@ -226,8 +225,7 @@ pqParseInput3(PGconn *conn)
PGRES_PIPELINE_SYNC); PGRES_PIPELINE_SYNC);
if (!conn->result) if (!conn->result)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
pqSaveErrorResult(conn); pqSaveErrorResult(conn);
} }
else else
@ -255,8 +253,7 @@ pqParseInput3(PGconn *conn)
PGRES_EMPTY_QUERY); PGRES_EMPTY_QUERY);
if (!conn->result) if (!conn->result)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
pqSaveErrorResult(conn); pqSaveErrorResult(conn);
} }
} }
@ -273,8 +270,7 @@ pqParseInput3(PGconn *conn)
PGRES_COMMAND_OK); PGRES_COMMAND_OK);
if (!conn->result) if (!conn->result)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
pqSaveErrorResult(conn); pqSaveErrorResult(conn);
} }
} }
@ -354,8 +350,7 @@ pqParseInput3(PGconn *conn)
PGRES_COMMAND_OK); PGRES_COMMAND_OK);
if (!conn->result) if (!conn->result)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
pqSaveErrorResult(conn); pqSaveErrorResult(conn);
} }
} }
@ -387,8 +382,7 @@ pqParseInput3(PGconn *conn)
else else
{ {
/* Set up to report error at end of query */ /* Set up to report error at end of query */
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "server sent data (\"D\" message) without prior row description (\"T\" message)");
libpq_gettext("server sent data (\"D\" message) without prior row description (\"T\" message)\n"));
pqSaveErrorResult(conn); pqSaveErrorResult(conn);
/* Discard the unexpected message */ /* Discard the unexpected message */
conn->inCursor += msgLength; conn->inCursor += msgLength;
@ -430,9 +424,7 @@ pqParseInput3(PGconn *conn)
*/ */
break; break;
default: default:
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "unexpected response from server; first received character was \"%c\"", id);
libpq_gettext("unexpected response from server; first received character was \"%c\"\n"),
id);
/* build an error result holding the error message */ /* build an error result holding the error message */
pqSaveErrorResult(conn); pqSaveErrorResult(conn);
/* not sure if we will see more, so go to ready state */ /* not sure if we will see more, so go to ready state */
@ -455,9 +447,7 @@ pqParseInput3(PGconn *conn)
else else
{ {
/* Trouble --- report it */ /* Trouble --- report it */
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "message contents do not agree with length in message type \"%c\"", id);
libpq_gettext("message contents do not agree with length in message type \"%c\"\n"),
id);
/* build an error result holding the error message */ /* build an error result holding the error message */
pqSaveErrorResult(conn); pqSaveErrorResult(conn);
conn->asyncStatus = PGASYNC_READY; conn->asyncStatus = PGASYNC_READY;
@ -475,8 +465,7 @@ pqParseInput3(PGconn *conn)
static void static void
handleSyncLoss(PGconn *conn, char id, int msgLength) handleSyncLoss(PGconn *conn, char id, int msgLength)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "lost synchronization with server: got message type \"%c\", length %d",
libpq_gettext("lost synchronization with server: got message type \"%c\", length %d\n"),
id, msgLength); id, msgLength);
/* build an error result holding the error message */ /* build an error result holding the error message */
pqSaveErrorResult(conn); pqSaveErrorResult(conn);
@ -967,8 +956,7 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
} }
if (PQExpBufferDataBroken(workBuf)) if (PQExpBufferDataBroken(workBuf))
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
else else
appendPQExpBufferStr(&conn->errorMessage, workBuf.data); appendPQExpBufferStr(&conn->errorMessage, workBuf.data);
} }
@ -1723,8 +1711,7 @@ pqGetCopyData3(PGconn *conn, char **buffer, int async)
*buffer = (char *) malloc(msgLength + 1); *buffer = (char *) malloc(msgLength + 1);
if (*buffer == NULL) if (*buffer == NULL)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return -2; return -2;
} }
memcpy(*buffer, &conn->inBuffer[conn->inCursor], msgLength); memcpy(*buffer, &conn->inBuffer[conn->inCursor], msgLength);
@ -1756,8 +1743,7 @@ pqGetline3(PGconn *conn, char *s, int maxlen)
conn->asyncStatus != PGASYNC_COPY_BOTH) || conn->asyncStatus != PGASYNC_COPY_BOTH) ||
conn->copy_is_binary) conn->copy_is_binary)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "PQgetline: not doing text COPY OUT");
libpq_gettext("PQgetline: not doing text COPY OUT\n"));
*s = '\0'; *s = '\0';
return EOF; return EOF;
} }
@ -1862,8 +1848,7 @@ pqEndcopy3(PGconn *conn)
conn->asyncStatus != PGASYNC_COPY_OUT && conn->asyncStatus != PGASYNC_COPY_OUT &&
conn->asyncStatus != PGASYNC_COPY_BOTH) conn->asyncStatus != PGASYNC_COPY_BOTH)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "no COPY in progress");
libpq_gettext("no COPY in progress\n"));
return 1; return 1;
} }
@ -2126,15 +2111,13 @@ pqFunctionCall3(PGconn *conn, Oid fnid,
conn->result = PQmakeEmptyPGresult(conn, status); conn->result = PQmakeEmptyPGresult(conn, status);
if (!conn->result) if (!conn->result)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
pqSaveErrorResult(conn); pqSaveErrorResult(conn);
} }
} }
else else
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "protocol error: no function result");
libpq_gettext("protocol error: no function result\n"));
pqSaveErrorResult(conn); pqSaveErrorResult(conn);
} }
} }
@ -2145,9 +2128,7 @@ pqFunctionCall3(PGconn *conn, Oid fnid,
break; break;
default: default:
/* The backend violates the protocol. */ /* The backend violates the protocol. */
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "protocol error: id=0x%x", id);
libpq_gettext("protocol error: id=0x%x\n"),
id);
pqSaveErrorResult(conn); pqSaveErrorResult(conn);
/* trust the specified message length as what to skip */ /* trust the specified message length as what to skip */
conn->inStart += 5 + msgLength; conn->inStart += 5 + msgLength;

View File

@ -96,8 +96,7 @@ pq_verify_peer_name_matches_certificate_name(PGconn *conn,
if (!(host && host[0] != '\0')) if (!(host && host[0] != '\0'))
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "host name must be specified");
libpq_gettext("host name must be specified\n"));
return -1; return -1;
} }
@ -108,8 +107,7 @@ pq_verify_peer_name_matches_certificate_name(PGconn *conn,
name = malloc(namelen + 1); name = malloc(namelen + 1);
if (name == NULL) if (name == NULL)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return -1; return -1;
} }
memcpy(name, namedata, namelen); memcpy(name, namedata, namelen);
@ -122,8 +120,7 @@ pq_verify_peer_name_matches_certificate_name(PGconn *conn,
if (namelen != strlen(name)) if (namelen != strlen(name))
{ {
free(name); free(name);
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "SSL certificate's name contains embedded null");
libpq_gettext("SSL certificate's name contains embedded null\n"));
return -1; return -1;
} }
@ -173,8 +170,7 @@ pq_verify_peer_name_matches_certificate_ip(PGconn *conn,
if (!(host && host[0] != '\0')) if (!(host && host[0] != '\0'))
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "host name must be specified");
libpq_gettext("host name must be specified\n"));
return -1; return -1;
} }
@ -229,8 +225,7 @@ pq_verify_peer_name_matches_certificate_ip(PGconn *conn,
* Not IPv4 or IPv6. We could ignore the field, but leniency seems * Not IPv4 or IPv6. We could ignore the field, but leniency seems
* wrong given the subject matter. * wrong given the subject matter.
*/ */
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "certificate contains IP address with invalid length %zu",
libpq_gettext("certificate contains IP address with invalid length %zu\n"),
iplen); iplen);
return -1; return -1;
} }
@ -239,8 +234,7 @@ pq_verify_peer_name_matches_certificate_ip(PGconn *conn,
addrstr = pg_inet_net_ntop(family, ipdata, 8 * iplen, tmp, sizeof(tmp)); addrstr = pg_inet_net_ntop(family, ipdata, 8 * iplen, tmp, sizeof(tmp));
if (!addrstr) if (!addrstr)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not convert certificate's IP address to string: %s",
libpq_gettext("could not convert certificate's IP address to string: %s\n"),
strerror_r(errno, sebuf, sizeof(sebuf))); strerror_r(errno, sebuf, sizeof(sebuf)));
return -1; return -1;
} }
@ -272,8 +266,7 @@ pq_verify_peer_name_matches_certificate(PGconn *conn)
/* Check that we have a hostname to compare with. */ /* Check that we have a hostname to compare with. */
if (!(host && host[0] != '\0')) if (!(host && host[0] != '\0'))
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "host name must be specified for a verified SSL connection");
libpq_gettext("host name must be specified for a verified SSL connection\n"));
return false; return false;
} }
@ -290,21 +283,20 @@ pq_verify_peer_name_matches_certificate(PGconn *conn)
if (names_examined > 1) if (names_examined > 1)
{ {
appendPQExpBuffer(&conn->errorMessage, appendPQExpBuffer(&conn->errorMessage,
libpq_ngettext("server certificate for \"%s\" (and %d other name) does not match host name \"%s\"\n", libpq_ngettext("server certificate for \"%s\" (and %d other name) does not match host name \"%s\"",
"server certificate for \"%s\" (and %d other names) does not match host name \"%s\"\n", "server certificate for \"%s\" (and %d other names) does not match host name \"%s\"",
names_examined - 1), names_examined - 1),
first_name, names_examined - 1, host); first_name, names_examined - 1, host);
appendPQExpBufferChar(&conn->errorMessage, '\n');
} }
else if (names_examined == 1) else if (names_examined == 1)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "server certificate for \"%s\" does not match host name \"%s\"",
libpq_gettext("server certificate for \"%s\" does not match host name \"%s\"\n"),
first_name, host); first_name, host);
} }
else else
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "could not get server's host name from server certificate");
libpq_gettext("could not get server's host name from server certificate\n"));
} }
} }

View File

@ -205,16 +205,14 @@ pg_GSS_write(PGconn *conn, const void *ptr, size_t len)
if (conf_state == 0) if (conf_state == 0)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "outgoing GSSAPI message would not use confidentiality");
libpq_gettext("outgoing GSSAPI message would not use confidentiality\n"));
errno = EIO; /* for lack of a better idea */ errno = EIO; /* for lack of a better idea */
goto cleanup; goto cleanup;
} }
if (output.length > PQ_GSS_SEND_BUFFER_SIZE - sizeof(uint32)) if (output.length > PQ_GSS_SEND_BUFFER_SIZE - sizeof(uint32))
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "client tried to send oversize GSSAPI packet (%zu > %zu)",
libpq_gettext("client tried to send oversize GSSAPI packet (%zu > %zu)\n"),
(size_t) output.length, (size_t) output.length,
PQ_GSS_SEND_BUFFER_SIZE - sizeof(uint32)); PQ_GSS_SEND_BUFFER_SIZE - sizeof(uint32));
errno = EIO; /* for lack of a better idea */ errno = EIO; /* for lack of a better idea */
@ -350,8 +348,7 @@ pg_GSS_read(PGconn *conn, void *ptr, size_t len)
if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32)) if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32))
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "oversize GSSAPI packet sent by the server (%zu > %zu)",
libpq_gettext("oversize GSSAPI packet sent by the server (%zu > %zu)\n"),
(size_t) input.length, (size_t) input.length,
PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32)); PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32));
errno = EIO; /* for lack of a better idea */ errno = EIO; /* for lack of a better idea */
@ -399,8 +396,7 @@ pg_GSS_read(PGconn *conn, void *ptr, size_t len)
if (conf_state == 0) if (conf_state == 0)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "incoming GSSAPI message did not use confidentiality");
libpq_gettext("incoming GSSAPI message did not use confidentiality\n"));
ret = -1; ret = -1;
errno = EIO; /* for lack of a better idea */ errno = EIO; /* for lack of a better idea */
goto cleanup; goto cleanup;
@ -500,8 +496,7 @@ pqsecure_open_gss(PGconn *conn)
PqGSSResultBuffer = malloc(PQ_GSS_RECV_BUFFER_SIZE); PqGSSResultBuffer = malloc(PQ_GSS_RECV_BUFFER_SIZE);
if (!PqGSSSendBuffer || !PqGSSRecvBuffer || !PqGSSResultBuffer) if (!PqGSSSendBuffer || !PqGSSRecvBuffer || !PqGSSResultBuffer)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return PGRES_POLLING_FAILED; return PGRES_POLLING_FAILED;
} }
PqGSSSendLength = PqGSSSendNext = PqGSSSendConsumed = 0; PqGSSSendLength = PqGSSSendNext = PqGSSSendConsumed = 0;
@ -592,8 +587,7 @@ pqsecure_open_gss(PGconn *conn)
input.length = pg_ntoh32(*(uint32 *) PqGSSRecvBuffer); input.length = pg_ntoh32(*(uint32 *) PqGSSRecvBuffer);
if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32)) if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32))
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "oversize GSSAPI packet sent by the server (%zu > %zu)",
libpq_gettext("oversize GSSAPI packet sent by the server (%zu > %zu)\n"),
(size_t) input.length, (size_t) input.length,
PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32)); PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32));
return PGRES_POLLING_FAILED; return PGRES_POLLING_FAILED;

View File

@ -212,20 +212,17 @@ rloop:
result_errno = SOCK_ERRNO; result_errno = SOCK_ERRNO;
if (result_errno == EPIPE || if (result_errno == EPIPE ||
result_errno == ECONNRESET) result_errno == ECONNRESET)
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "server closed the connection unexpectedly\n"
libpq_gettext("server closed the connection unexpectedly\n" "\tThis probably means the server terminated abnormally\n"
"\tThis probably means the server terminated abnormally\n" "\tbefore or while processing the request.");
"\tbefore or while processing the request.\n"));
else else
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "SSL SYSCALL error: %s",
libpq_gettext("SSL SYSCALL error: %s\n"),
SOCK_STRERROR(result_errno, SOCK_STRERROR(result_errno,
sebuf, sizeof(sebuf))); sebuf, sizeof(sebuf)));
} }
else else
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "SSL SYSCALL error: EOF detected");
libpq_gettext("SSL SYSCALL error: EOF detected\n"));
/* assume the connection is broken */ /* assume the connection is broken */
result_errno = ECONNRESET; result_errno = ECONNRESET;
n = -1; n = -1;
@ -235,8 +232,7 @@ rloop:
{ {
char *errm = SSLerrmessage(ecode); char *errm = SSLerrmessage(ecode);
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "SSL error: %s", errm);
libpq_gettext("SSL error: %s\n"), errm);
SSLerrfree(errm); SSLerrfree(errm);
/* assume the connection is broken */ /* assume the connection is broken */
result_errno = ECONNRESET; result_errno = ECONNRESET;
@ -250,15 +246,12 @@ rloop:
* a clean connection closure, so we should not report it as a * a clean connection closure, so we should not report it as a
* server crash. * server crash.
*/ */
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "SSL connection has been closed unexpectedly");
libpq_gettext("SSL connection has been closed unexpectedly\n"));
result_errno = ECONNRESET; result_errno = ECONNRESET;
n = -1; n = -1;
break; break;
default: default:
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "unrecognized SSL error code: %d", err);
libpq_gettext("unrecognized SSL error code: %d\n"),
err);
/* assume the connection is broken */ /* assume the connection is broken */
result_errno = ECONNRESET; result_errno = ECONNRESET;
n = -1; n = -1;
@ -319,20 +312,17 @@ pgtls_write(PGconn *conn, const void *ptr, size_t len)
{ {
result_errno = SOCK_ERRNO; result_errno = SOCK_ERRNO;
if (result_errno == EPIPE || result_errno == ECONNRESET) if (result_errno == EPIPE || result_errno == ECONNRESET)
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "server closed the connection unexpectedly\n"
libpq_gettext("server closed the connection unexpectedly\n" "\tThis probably means the server terminated abnormally\n"
"\tThis probably means the server terminated abnormally\n" "\tbefore or while processing the request.");
"\tbefore or while processing the request.\n"));
else else
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "SSL SYSCALL error: %s",
libpq_gettext("SSL SYSCALL error: %s\n"),
SOCK_STRERROR(result_errno, SOCK_STRERROR(result_errno,
sebuf, sizeof(sebuf))); sebuf, sizeof(sebuf)));
} }
else else
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "SSL SYSCALL error: EOF detected");
libpq_gettext("SSL SYSCALL error: EOF detected\n"));
/* assume the connection is broken */ /* assume the connection is broken */
result_errno = ECONNRESET; result_errno = ECONNRESET;
n = -1; n = -1;
@ -342,8 +332,7 @@ pgtls_write(PGconn *conn, const void *ptr, size_t len)
{ {
char *errm = SSLerrmessage(ecode); char *errm = SSLerrmessage(ecode);
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "SSL error: %s", errm);
libpq_gettext("SSL error: %s\n"), errm);
SSLerrfree(errm); SSLerrfree(errm);
/* assume the connection is broken */ /* assume the connection is broken */
result_errno = ECONNRESET; result_errno = ECONNRESET;
@ -357,15 +346,12 @@ pgtls_write(PGconn *conn, const void *ptr, size_t len)
* a clean connection closure, so we should not report it as a * a clean connection closure, so we should not report it as a
* server crash. * server crash.
*/ */
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "SSL connection has been closed unexpectedly");
libpq_gettext("SSL connection has been closed unexpectedly\n"));
result_errno = ECONNRESET; result_errno = ECONNRESET;
n = -1; n = -1;
break; break;
default: default:
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "unrecognized SSL error code: %d", err);
libpq_gettext("unrecognized SSL error code: %d\n"),
err);
/* assume the connection is broken */ /* assume the connection is broken */
result_errno = ECONNRESET; result_errno = ECONNRESET;
n = -1; n = -1;
@ -403,8 +389,7 @@ pgtls_get_peer_certificate_hash(PGconn *conn, size_t *len)
if (!OBJ_find_sigid_algs(X509_get_signature_nid(peer_cert), if (!OBJ_find_sigid_algs(X509_get_signature_nid(peer_cert),
&algo_nid, NULL)) &algo_nid, NULL))
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "could not determine server certificate signature algorithm");
libpq_gettext("could not determine server certificate signature algorithm\n"));
return NULL; return NULL;
} }
@ -424,8 +409,7 @@ pgtls_get_peer_certificate_hash(PGconn *conn, size_t *len)
algo_type = EVP_get_digestbynid(algo_nid); algo_type = EVP_get_digestbynid(algo_nid);
if (algo_type == NULL) if (algo_type == NULL)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not find digest for NID %s",
libpq_gettext("could not find digest for NID %s\n"),
OBJ_nid2sn(algo_nid)); OBJ_nid2sn(algo_nid));
return NULL; return NULL;
} }
@ -434,8 +418,7 @@ pgtls_get_peer_certificate_hash(PGconn *conn, size_t *len)
if (!X509_digest(peer_cert, algo_type, hash, &hash_size)) if (!X509_digest(peer_cert, algo_type, hash, &hash_size))
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "could not generate peer certificate hash");
libpq_gettext("could not generate peer certificate hash\n"));
return NULL; return NULL;
} }
@ -443,8 +426,7 @@ pgtls_get_peer_certificate_hash(PGconn *conn, size_t *len)
cert_hash = malloc(hash_size); cert_hash = malloc(hash_size);
if (cert_hash == NULL) if (cert_hash == NULL)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return NULL; return NULL;
} }
memcpy(cert_hash, hash, hash_size); memcpy(cert_hash, hash, hash_size);
@ -491,8 +473,7 @@ openssl_verify_peer_name_matches_certificate_name(PGconn *conn, ASN1_STRING *nam
/* Should not happen... */ /* Should not happen... */
if (name_entry == NULL) if (name_entry == NULL)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "SSL certificate's name entry is missing");
libpq_gettext("SSL certificate's name entry is missing\n"));
return -1; return -1;
} }
@ -526,8 +507,7 @@ openssl_verify_peer_name_matches_certificate_ip(PGconn *conn,
/* Should not happen... */ /* Should not happen... */
if (addr_entry == NULL) if (addr_entry == NULL)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "SSL certificate's address entry is missing");
libpq_gettext("SSL certificate's address entry is missing\n"));
return -1; return -1;
} }
@ -944,9 +924,7 @@ initialize_SSL(PGconn *conn)
{ {
char *err = SSLerrmessage(ERR_get_error()); char *err = SSLerrmessage(ERR_get_error());
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not create SSL context: %s", err);
libpq_gettext("could not create SSL context: %s\n"),
err);
SSLerrfree(err); SSLerrfree(err);
return -1; return -1;
} }
@ -983,8 +961,7 @@ initialize_SSL(PGconn *conn)
if (ssl_min_ver == -1) if (ssl_min_ver == -1)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "invalid value \"%s\" for minimum SSL protocol version",
libpq_gettext("invalid value \"%s\" for minimum SSL protocol version\n"),
conn->ssl_min_protocol_version); conn->ssl_min_protocol_version);
SSL_CTX_free(SSL_context); SSL_CTX_free(SSL_context);
return -1; return -1;
@ -994,9 +971,7 @@ initialize_SSL(PGconn *conn)
{ {
char *err = SSLerrmessage(ERR_get_error()); char *err = SSLerrmessage(ERR_get_error());
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not set minimum SSL protocol version: %s", err);
libpq_gettext("could not set minimum SSL protocol version: %s\n"),
err);
SSLerrfree(err); SSLerrfree(err);
SSL_CTX_free(SSL_context); SSL_CTX_free(SSL_context);
return -1; return -1;
@ -1012,8 +987,7 @@ initialize_SSL(PGconn *conn)
if (ssl_max_ver == -1) if (ssl_max_ver == -1)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "invalid value \"%s\" for maximum SSL protocol version",
libpq_gettext("invalid value \"%s\" for maximum SSL protocol version\n"),
conn->ssl_max_protocol_version); conn->ssl_max_protocol_version);
SSL_CTX_free(SSL_context); SSL_CTX_free(SSL_context);
return -1; return -1;
@ -1023,9 +997,7 @@ initialize_SSL(PGconn *conn)
{ {
char *err = SSLerrmessage(ERR_get_error()); char *err = SSLerrmessage(ERR_get_error());
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not set maximum SSL protocol version: %s", err);
libpq_gettext("could not set maximum SSL protocol version: %s\n"),
err);
SSLerrfree(err); SSLerrfree(err);
SSL_CTX_free(SSL_context); SSL_CTX_free(SSL_context);
return -1; return -1;
@ -1059,8 +1031,7 @@ initialize_SSL(PGconn *conn)
{ {
char *err = SSLerrmessage(ERR_get_error()); char *err = SSLerrmessage(ERR_get_error());
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not read root certificate file \"%s\": %s",
libpq_gettext("could not read root certificate file \"%s\": %s\n"),
fnbuf, err); fnbuf, err);
SSLerrfree(err); SSLerrfree(err);
SSL_CTX_free(SSL_context); SSL_CTX_free(SSL_context);
@ -1112,13 +1083,11 @@ initialize_SSL(PGconn *conn)
* that it seems worth having a specialized error message for it. * that it seems worth having a specialized error message for it.
*/ */
if (fnbuf[0] == '\0') if (fnbuf[0] == '\0')
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not get home directory to locate root certificate file\n"
libpq_gettext("could not get home directory to locate root certificate file\n" "Either provide the file or change sslmode to disable server certificate verification.");
"Either provide the file or change sslmode to disable server certificate verification.\n"));
else else
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "root certificate file \"%s\" does not exist\n"
libpq_gettext("root certificate file \"%s\" does not exist\n" "Either provide the file or change sslmode to disable server certificate verification.", fnbuf);
"Either provide the file or change sslmode to disable server certificate verification.\n"), fnbuf);
SSL_CTX_free(SSL_context); SSL_CTX_free(SSL_context);
return -1; return -1;
} }
@ -1147,8 +1116,7 @@ initialize_SSL(PGconn *conn)
*/ */
if (errno != ENOENT && errno != ENOTDIR) if (errno != ENOENT && errno != ENOTDIR)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not open certificate file \"%s\": %s",
libpq_gettext("could not open certificate file \"%s\": %s\n"),
fnbuf, strerror_r(errno, sebuf, sizeof(sebuf))); fnbuf, strerror_r(errno, sebuf, sizeof(sebuf)));
SSL_CTX_free(SSL_context); SSL_CTX_free(SSL_context);
return -1; return -1;
@ -1166,8 +1134,7 @@ initialize_SSL(PGconn *conn)
{ {
char *err = SSLerrmessage(ERR_get_error()); char *err = SSLerrmessage(ERR_get_error());
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not read certificate file \"%s\": %s",
libpq_gettext("could not read certificate file \"%s\": %s\n"),
fnbuf, err); fnbuf, err);
SSLerrfree(err); SSLerrfree(err);
SSL_CTX_free(SSL_context); SSL_CTX_free(SSL_context);
@ -1191,9 +1158,7 @@ initialize_SSL(PGconn *conn)
{ {
char *err = SSLerrmessage(ERR_get_error()); char *err = SSLerrmessage(ERR_get_error());
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not establish SSL connection: %s", err);
libpq_gettext("could not establish SSL connection: %s\n"),
err);
SSLerrfree(err); SSLerrfree(err);
SSL_CTX_free(SSL_context); SSL_CTX_free(SSL_context);
return -1; return -1;
@ -1225,9 +1190,7 @@ initialize_SSL(PGconn *conn)
{ {
char *err = SSLerrmessage(ERR_get_error()); char *err = SSLerrmessage(ERR_get_error());
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not set SSL Server Name Indication (SNI): %s", err);
libpq_gettext("could not set SSL Server Name Indication (SNI): %s\n"),
err);
SSLerrfree(err); SSLerrfree(err);
return -1; return -1;
} }
@ -1255,8 +1218,7 @@ initialize_SSL(PGconn *conn)
if (engine_str == NULL) if (engine_str == NULL)
{ {
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "out of memory");
libpq_gettext("out of memory\n"));
return -1; return -1;
} }
@ -1271,8 +1233,7 @@ initialize_SSL(PGconn *conn)
{ {
char *err = SSLerrmessage(ERR_get_error()); char *err = SSLerrmessage(ERR_get_error());
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not load SSL engine \"%s\": %s",
libpq_gettext("could not load SSL engine \"%s\": %s\n"),
engine_str, err); engine_str, err);
SSLerrfree(err); SSLerrfree(err);
free(engine_str); free(engine_str);
@ -1283,8 +1244,7 @@ initialize_SSL(PGconn *conn)
{ {
char *err = SSLerrmessage(ERR_get_error()); char *err = SSLerrmessage(ERR_get_error());
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not initialize SSL engine \"%s\": %s",
libpq_gettext("could not initialize SSL engine \"%s\": %s\n"),
engine_str, err); engine_str, err);
SSLerrfree(err); SSLerrfree(err);
ENGINE_free(conn->engine); ENGINE_free(conn->engine);
@ -1299,8 +1259,7 @@ initialize_SSL(PGconn *conn)
{ {
char *err = SSLerrmessage(ERR_get_error()); char *err = SSLerrmessage(ERR_get_error());
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not read private SSL key \"%s\" from engine \"%s\": %s",
libpq_gettext("could not read private SSL key \"%s\" from engine \"%s\": %s\n"),
engine_colon, engine_str, err); engine_colon, engine_str, err);
SSLerrfree(err); SSLerrfree(err);
ENGINE_finish(conn->engine); ENGINE_finish(conn->engine);
@ -1313,8 +1272,7 @@ initialize_SSL(PGconn *conn)
{ {
char *err = SSLerrmessage(ERR_get_error()); char *err = SSLerrmessage(ERR_get_error());
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not load private SSL key \"%s\" from engine \"%s\": %s",
libpq_gettext("could not load private SSL key \"%s\" from engine \"%s\": %s\n"),
engine_colon, engine_str, err); engine_colon, engine_str, err);
SSLerrfree(err); SSLerrfree(err);
ENGINE_finish(conn->engine); ENGINE_finish(conn->engine);
@ -1351,12 +1309,10 @@ initialize_SSL(PGconn *conn)
if (stat(fnbuf, &buf) != 0) if (stat(fnbuf, &buf) != 0)
{ {
if (errno == ENOENT) if (errno == ENOENT)
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "certificate present, but not private key file \"%s\"",
libpq_gettext("certificate present, but not private key file \"%s\"\n"),
fnbuf); fnbuf);
else else
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not stat private key file \"%s\": %m",
libpq_gettext("could not stat private key file \"%s\": %m\n"),
fnbuf); fnbuf);
return -1; return -1;
} }
@ -1364,8 +1320,7 @@ initialize_SSL(PGconn *conn)
/* Key file must be a regular file */ /* Key file must be a regular file */
if (!S_ISREG(buf.st_mode)) if (!S_ISREG(buf.st_mode))
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "private key file \"%s\" is not a regular file",
libpq_gettext("private key file \"%s\" is not a regular file\n"),
fnbuf); fnbuf);
return -1; return -1;
} }
@ -1397,9 +1352,9 @@ initialize_SSL(PGconn *conn)
buf.st_mode & (S_IWGRP | S_IXGRP | S_IRWXO) : buf.st_mode & (S_IWGRP | S_IXGRP | S_IRWXO) :
buf.st_mode & (S_IRWXG | S_IRWXO)) buf.st_mode & (S_IRWXG | S_IRWXO))
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn,
libpq_gettext("private key file \"%s\" has group or world access; file must have permissions u=rw (0600) or less if owned by the current user, or permissions u=rw,g=r (0640) or less if owned by root\n"), "private key file \"%s\" has group or world access; file must have permissions u=rw (0600) or less if owned by the current user, or permissions u=rw,g=r (0640) or less if owned by root",
fnbuf); fnbuf);
return -1; return -1;
} }
#endif #endif
@ -1422,8 +1377,7 @@ initialize_SSL(PGconn *conn)
*/ */
if (SSL_use_PrivateKey_file(conn->ssl, fnbuf, SSL_FILETYPE_ASN1) != 1) if (SSL_use_PrivateKey_file(conn->ssl, fnbuf, SSL_FILETYPE_ASN1) != 1)
{ {
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not load private key file \"%s\": %s",
libpq_gettext("could not load private key file \"%s\": %s\n"),
fnbuf, err); fnbuf, err);
SSLerrfree(err); SSLerrfree(err);
return -1; return -1;
@ -1439,8 +1393,7 @@ initialize_SSL(PGconn *conn)
{ {
char *err = SSLerrmessage(ERR_get_error()); char *err = SSLerrmessage(ERR_get_error());
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "certificate does not match private key file \"%s\": %s",
libpq_gettext("certificate does not match private key file \"%s\": %s\n"),
fnbuf, err); fnbuf, err);
SSLerrfree(err); SSLerrfree(err);
return -1; return -1;
@ -1493,12 +1446,10 @@ open_client_SSL(PGconn *conn)
char sebuf[PG_STRERROR_R_BUFLEN]; char sebuf[PG_STRERROR_R_BUFLEN];
if (r == -1) if (r == -1)
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "SSL SYSCALL error: %s",
libpq_gettext("SSL SYSCALL error: %s\n"),
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
else else
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "SSL SYSCALL error: EOF detected");
libpq_gettext("SSL SYSCALL error: EOF detected\n"));
pgtls_close(conn); pgtls_close(conn);
return PGRES_POLLING_FAILED; return PGRES_POLLING_FAILED;
} }
@ -1506,9 +1457,7 @@ open_client_SSL(PGconn *conn)
{ {
char *err = SSLerrmessage(ecode); char *err = SSLerrmessage(ecode);
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "SSL error: %s", err);
libpq_gettext("SSL error: %s\n"),
err);
SSLerrfree(err); SSLerrfree(err);
switch (ERR_GET_REASON(ecode)) switch (ERR_GET_REASON(ecode))
{ {
@ -1539,8 +1488,7 @@ open_client_SSL(PGconn *conn)
case SSL_R_VERSION_TOO_HIGH: case SSL_R_VERSION_TOO_HIGH:
case SSL_R_VERSION_TOO_LOW: case SSL_R_VERSION_TOO_LOW:
#endif #endif
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "This may indicate that the server does not support any SSL protocol version between %s and %s.",
libpq_gettext("This may indicate that the server does not support any SSL protocol version between %s and %s.\n"),
conn->ssl_min_protocol_version ? conn->ssl_min_protocol_version ?
conn->ssl_min_protocol_version : conn->ssl_min_protocol_version :
MIN_OPENSSL_TLS_VERSION, MIN_OPENSSL_TLS_VERSION,
@ -1556,9 +1504,7 @@ open_client_SSL(PGconn *conn)
} }
default: default:
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "unrecognized SSL error code: %d", err);
libpq_gettext("unrecognized SSL error code: %d\n"),
err);
pgtls_close(conn); pgtls_close(conn);
return PGRES_POLLING_FAILED; return PGRES_POLLING_FAILED;
} }
@ -1575,9 +1521,7 @@ open_client_SSL(PGconn *conn)
{ {
char *err = SSLerrmessage(ERR_get_error()); char *err = SSLerrmessage(ERR_get_error());
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "certificate could not be obtained: %s", err);
libpq_gettext("certificate could not be obtained: %s\n"),
err);
SSLerrfree(err); SSLerrfree(err);
pgtls_close(conn); pgtls_close(conn);
return PGRES_POLLING_FAILED; return PGRES_POLLING_FAILED;

View File

@ -254,15 +254,13 @@ pqsecure_raw_read(PGconn *conn, void *ptr, size_t len)
case EPIPE: case EPIPE:
case ECONNRESET: case ECONNRESET:
appendPQExpBufferStr(&conn->errorMessage, libpq_append_conn_error(conn, "server closed the connection unexpectedly\n"
libpq_gettext("server closed the connection unexpectedly\n" "\tThis probably means the server terminated abnormally\n"
"\tThis probably means the server terminated abnormally\n" "\tbefore or while processing the request.");
"\tbefore or while processing the request.\n"));
break; break;
default: default:
appendPQExpBuffer(&conn->errorMessage, libpq_append_conn_error(conn, "could not receive data from server: %s",
libpq_gettext("could not receive data from server: %s\n"),
SOCK_STRERROR(result_errno, SOCK_STRERROR(result_errno,
sebuf, sizeof(sebuf))); sebuf, sizeof(sebuf)));
break; break;
@ -420,7 +418,9 @@ retry_masked:
snprintf(msgbuf, sizeof(msgbuf), snprintf(msgbuf, sizeof(msgbuf),
libpq_gettext("server closed the connection unexpectedly\n" libpq_gettext("server closed the connection unexpectedly\n"
"\tThis probably means the server terminated abnormally\n" "\tThis probably means the server terminated abnormally\n"
"\tbefore or while processing the request.\n")); "\tbefore or while processing the request."));
/* keep newline out of translated string */
strlcat(msgbuf, "\n", sizeof(msgbuf));
conn->write_err_msg = strdup(msgbuf); conn->write_err_msg = strdup(msgbuf);
/* Now claim the write succeeded */ /* Now claim the write succeeded */
n = len; n = len;
@ -431,9 +431,11 @@ retry_masked:
/* Store error message in conn->write_err_msg, if possible */ /* Store error message in conn->write_err_msg, if possible */
/* (strdup failure is OK, we'll cope later) */ /* (strdup failure is OK, we'll cope later) */
snprintf(msgbuf, sizeof(msgbuf), snprintf(msgbuf, sizeof(msgbuf),
libpq_gettext("could not send data to server: %s\n"), libpq_gettext("could not send data to server: %s"),
SOCK_STRERROR(result_errno, SOCK_STRERROR(result_errno,
sebuf, sizeof(sebuf))); sebuf, sizeof(sebuf)));
/* keep newline out of translated string */
strlcat(msgbuf, "\n", sizeof(msgbuf));
conn->write_err_msg = strdup(msgbuf); conn->write_err_msg = strdup(msgbuf);
/* Now claim the write succeeded */ /* Now claim the write succeeded */
n = len; n = len;