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)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("malformed SCRAM message (empty message)\n"));
libpq_append_conn_error(conn, "malformed SCRAM message (empty message)");
goto error;
}
if (inputlen != strlen(input))
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("malformed SCRAM message (length mismatch)\n"));
libpq_append_conn_error(conn, "malformed SCRAM message (length mismatch)");
goto error;
}
}
@ -268,15 +266,13 @@ scram_exchange(void *opaq, char *input, int inputlen,
*/
if (!verify_server_signature(state, success, &errstr))
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not verify server signature: %s\n"), errstr);
libpq_append_conn_error(conn, "could not verify server signature: %s", errstr);
goto error;
}
if (!*success)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("incorrect server signature\n"));
libpq_append_conn_error(conn, "incorrect server signature");
}
*done = true;
state->state = FE_SCRAM_FINISHED;
@ -284,8 +280,7 @@ scram_exchange(void *opaq, char *input, int inputlen,
default:
/* shouldn't happen */
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("invalid SCRAM exchange state\n"));
libpq_append_conn_error(conn, "invalid SCRAM exchange state");
goto error;
}
return;
@ -311,18 +306,18 @@ read_attr_value(char **input, char attr, PQExpBuffer errorMessage)
if (*begin != attr)
{
appendPQExpBuffer(errorMessage,
libpq_gettext("malformed SCRAM message (attribute \"%c\" expected)\n"),
attr);
libpq_append_error(errorMessage,
"malformed SCRAM message (attribute \"%c\" expected)",
attr);
return NULL;
}
begin++;
if (*begin != '=')
{
appendPQExpBuffer(errorMessage,
libpq_gettext("malformed SCRAM message (expected character \"=\" for attribute \"%c\")\n"),
attr);
libpq_append_error(errorMessage,
"malformed SCRAM message (expected character \"=\" for attribute \"%c\")",
attr);
return NULL;
}
begin++;
@ -361,8 +356,7 @@ build_client_first_message(fe_scram_state *state)
*/
if (!pg_strong_random(raw_nonce, SCRAM_RAW_NONCE_LEN))
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("could not generate nonce\n"));
libpq_append_conn_error(conn, "could not generate nonce");
return NULL;
}
@ -371,16 +365,14 @@ build_client_first_message(fe_scram_state *state)
state->client_nonce = malloc(encoded_len + 1);
if (state->client_nonce == NULL)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
return NULL;
}
encoded_len = pg_b64_encode(raw_nonce, SCRAM_RAW_NONCE_LEN,
state->client_nonce, encoded_len);
if (encoded_len < 0)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("could not encode nonce\n"));
libpq_append_conn_error(conn, "could not encode nonce");
return NULL;
}
state->client_nonce[encoded_len] = '\0';
@ -446,8 +438,7 @@ build_client_first_message(fe_scram_state *state)
oom_error:
termPQExpBuffer(&buf);
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
return NULL;
}
@ -569,9 +560,7 @@ build_client_final_message(fe_scram_state *state)
client_proof, &errstr))
{
termPQExpBuffer(&buf);
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not calculate client proof: %s\n"),
errstr);
libpq_append_conn_error(conn, "could not calculate client proof: %s", errstr);
return NULL;
}
@ -586,8 +575,7 @@ build_client_final_message(fe_scram_state *state)
if (encoded_len < 0)
{
termPQExpBuffer(&buf);
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("could not encode client proof\n"));
libpq_append_conn_error(conn, "could not encode client proof");
return NULL;
}
buf.len += encoded_len;
@ -602,8 +590,7 @@ build_client_final_message(fe_scram_state *state)
oom_error:
termPQExpBuffer(&buf);
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
return NULL;
}
@ -623,8 +610,7 @@ read_server_first_message(fe_scram_state *state, char *input)
state->server_first_message = strdup(input);
if (state->server_first_message == NULL)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
return false;
}
@ -641,16 +627,14 @@ read_server_first_message(fe_scram_state *state, char *input)
if (strlen(nonce) < strlen(state->client_nonce) ||
memcmp(nonce, state->client_nonce, strlen(state->client_nonce)) != 0)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("invalid SCRAM response (nonce mismatch)\n"));
libpq_append_conn_error(conn, "invalid SCRAM response (nonce mismatch)");
return false;
}
state->nonce = strdup(nonce);
if (state->nonce == NULL)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
return false;
}
@ -664,8 +648,7 @@ read_server_first_message(fe_scram_state *state, char *input)
state->salt = malloc(decoded_salt_len);
if (state->salt == NULL)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
return false;
}
state->saltlen = pg_b64_decode(encoded_salt,
@ -674,8 +657,7 @@ read_server_first_message(fe_scram_state *state, char *input)
decoded_salt_len);
if (state->saltlen < 0)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("malformed SCRAM message (invalid salt)\n"));
libpq_append_conn_error(conn, "malformed SCRAM message (invalid salt)");
return false;
}
@ -688,14 +670,12 @@ read_server_first_message(fe_scram_state *state, char *input)
state->iterations = strtol(iterations_str, &endptr, 10);
if (*endptr != '\0' || state->iterations < 1)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("malformed SCRAM message (invalid iteration count)\n"));
libpq_append_conn_error(conn, "malformed SCRAM message (invalid iteration count)");
return false;
}
if (*input != '\0')
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("malformed SCRAM message (garbage at end of server-first-message)\n"));
libpq_append_conn_error(conn, "malformed SCRAM message (garbage at end of server-first-message)");
return true;
}
@ -714,8 +694,7 @@ read_server_final_message(fe_scram_state *state, char *input)
state->server_final_message = strdup(input);
if (!state->server_final_message)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
return false;
}
@ -730,9 +709,8 @@ read_server_final_message(fe_scram_state *state, char *input)
/* read_attr_value() has appended an error message */
return false;
}
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("error received from server in SCRAM exchange: %s\n"),
errmsg);
libpq_append_conn_error(conn, "error received from server in SCRAM exchange: %s",
errmsg);
return false;
}
@ -746,15 +724,13 @@ read_server_final_message(fe_scram_state *state, char *input)
}
if (*input != '\0')
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("malformed SCRAM message (garbage at end of server-final-message)\n"));
libpq_append_conn_error(conn, "malformed SCRAM message (garbage at end of server-final-message)");
server_signature_len = pg_b64_dec_len(strlen(encoded_server_signature));
decoded_server_signature = malloc(server_signature_len);
if (!decoded_server_signature)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
return false;
}
@ -765,8 +741,7 @@ read_server_final_message(fe_scram_state *state, char *input)
if (server_signature_len != SCRAM_KEY_LEN)
{
free(decoded_server_signature);
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("malformed SCRAM message (invalid server signature)\n"));
libpq_append_conn_error(conn, "malformed SCRAM message (invalid server signature)");
return false;
}
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);
if (!ginbuf.value)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("out of memory allocating GSSAPI buffer (%d)\n"),
libpq_append_conn_error(conn, "out of memory allocating GSSAPI buffer (%d)",
payloadlen);
return STATUS_ERROR;
}
@ -153,15 +152,13 @@ pg_GSS_startup(PGconn *conn, int payloadlen)
if (!(host && host[0] != '\0'))
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("host name must be specified\n"));
libpq_append_conn_error(conn, "host name must be specified");
return STATUS_ERROR;
}
if (conn->gctx)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("duplicate GSS authentication request\n"));
libpq_append_conn_error(conn, "duplicate GSS authentication request");
return STATUS_ERROR;
}
@ -225,8 +222,7 @@ pg_SSPI_continue(PGconn *conn, int payloadlen)
inputbuf = malloc(payloadlen);
if (!inputbuf)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("out of memory allocating SSPI buffer (%d)\n"),
libpq_append_conn_error(conn, "out of memory allocating SSPI buffer (%d)",
payloadlen);
return STATUS_ERROR;
}
@ -284,8 +280,7 @@ pg_SSPI_continue(PGconn *conn, int payloadlen)
conn->sspictx = malloc(sizeof(CtxtHandle));
if (conn->sspictx == NULL)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
return STATUS_ERROR;
}
memcpy(conn->sspictx, &newContext, sizeof(CtxtHandle));
@ -345,8 +340,7 @@ pg_SSPI_startup(PGconn *conn, int use_negotiate, int payloadlen)
if (conn->sspictx)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("duplicate SSPI authentication request\n"));
libpq_append_conn_error(conn, "duplicate SSPI authentication request");
return STATUS_ERROR;
}
@ -356,8 +350,7 @@ pg_SSPI_startup(PGconn *conn, int use_negotiate, int payloadlen)
conn->sspicred = malloc(sizeof(CredHandle));
if (conn->sspicred == NULL)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
return STATUS_ERROR;
}
@ -385,15 +378,13 @@ pg_SSPI_startup(PGconn *conn, int use_negotiate, int payloadlen)
*/
if (!(host && host[0] != '\0'))
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("host name must be specified\n"));
libpq_append_conn_error(conn, "host name must be specified");
return STATUS_ERROR;
}
conn->sspitarget = malloc(strlen(conn->krbsrvname) + strlen(host) + 2);
if (!conn->sspitarget)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
return STATUS_ERROR;
}
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 */
!conn->ssl_in_use)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("channel binding required, but SSL not in use\n"));
libpq_append_conn_error(conn, "channel binding required, but SSL not in use");
goto error;
}
if (conn->sasl_state)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("duplicate SASL authentication request\n"));
libpq_append_conn_error(conn, "duplicate SASL authentication request");
goto error;
}
@ -493,8 +482,7 @@ pg_SASL_init(PGconn *conn, int payloadlen)
*/
if (conn->channel_binding[0] == 'r') /* require */
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("channel binding is required, but client does not support it\n"));
libpq_append_conn_error(conn, "channel binding is required, but client does not support it");
goto error;
}
#endif
@ -510,8 +498,7 @@ pg_SASL_init(PGconn *conn, int payloadlen)
* the client and server supported it. The SCRAM exchange
* checks for that, to prevent downgrade attacks.
*/
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("server offered SCRAM-SHA-256-PLUS authentication over a non-SSL connection\n"));
libpq_append_conn_error(conn, "server offered SCRAM-SHA-256-PLUS authentication over a non-SSL connection");
goto error;
}
}
@ -525,16 +512,14 @@ pg_SASL_init(PGconn *conn, int payloadlen)
if (!selected_mechanism)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("none of the server's SASL authentication mechanisms are supported\n"));
libpq_append_conn_error(conn, "none of the server's SASL authentication mechanisms are supported");
goto error;
}
if (conn->channel_binding[0] == 'r' && /* require */
strcmp(selected_mechanism, SCRAM_SHA_256_PLUS_NAME) != 0)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("channel binding is required, but server did not offer an authentication method that supports channel binding\n"));
libpq_append_conn_error(conn, "channel binding is required, but server did not offer an authentication method that supports channel binding");
goto error;
}
@ -614,8 +599,7 @@ error:
oom_error:
termPQExpBuffer(&mechanism_buf);
free(initialresponse);
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
return STATUS_ERROR;
}
@ -638,8 +622,7 @@ pg_SASL_continue(PGconn *conn, int payloadlen, bool final)
challenge = malloc(payloadlen + 1);
if (!challenge)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("out of memory allocating SASL buffer (%d)\n"),
libpq_append_conn_error(conn, "out of memory allocating SASL buffer (%d)",
payloadlen);
return STATUS_ERROR;
}
@ -663,8 +646,7 @@ pg_SASL_continue(PGconn *conn, int payloadlen, bool final)
if (outputlen != 0)
free(output);
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("AuthenticationSASLFinal received from server, but SASL authentication was not completed\n"));
libpq_append_conn_error(conn, "AuthenticationSASLFinal received from server, but SASL authentication was not completed");
return STATUS_ERROR;
}
@ -674,8 +656,7 @@ pg_SASL_continue(PGconn *conn, int payloadlen, bool final)
*/
if (output == NULL && !done)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("no client response found after SASL exchange success\n"));
libpq_append_conn_error(conn, "no client response found after SASL exchange success");
return STATUS_ERROR;
}
@ -756,8 +737,7 @@ pg_local_sendauth(PGconn *conn)
}
return STATUS_OK;
#else
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("SCM_CRED authentication method not supported\n"));
libpq_append_conn_error(conn, "SCM_CRED authentication method not supported");
return STATUS_ERROR;
#endif
}
@ -790,8 +770,7 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
crypt_pwd = malloc(2 * (MD5_PASSWD_LEN + 1));
if (!crypt_pwd)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
return STATUS_ERROR;
}
@ -800,18 +779,14 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
strlen(conn->pguser), crypt_pwd2,
&errstr))
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not encrypt password: %s\n"),
errstr);
libpq_append_conn_error(conn, "could not encrypt password: %s", errstr);
free(crypt_pwd);
return STATUS_ERROR;
}
if (!pg_md5_encrypt(crypt_pwd2 + strlen("md5"), md5Salt,
4, crypt_pwd, &errstr))
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not encrypt password: %s\n"),
errstr);
libpq_append_conn_error(conn, "could not encrypt password: %s", errstr);
free(crypt_pwd);
return STATUS_ERROR;
}
@ -858,14 +833,12 @@ check_expected_areq(AuthRequest areq, PGconn *conn)
case AUTH_REQ_OK:
if (!conn->sasl || !conn->sasl->channel_bound(conn->sasl_state))
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("channel binding required, but server authenticated client without channel binding\n"));
libpq_append_conn_error(conn, "channel binding required, but server authenticated client without channel binding");
result = false;
}
break;
default:
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("channel binding required but not supported by server's authentication request\n"));
libpq_append_conn_error(conn, "channel binding required but not supported by server's authentication request");
result = false;
break;
}
@ -899,13 +872,11 @@ pg_fe_sendauth(AuthRequest areq, int payloadlen, PGconn *conn)
break;
case AUTH_REQ_KRB4:
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("Kerberos 4 authentication not supported\n"));
libpq_append_conn_error(conn, "Kerberos 4 authentication not supported");
return STATUS_ERROR;
case AUTH_REQ_KRB5:
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("Kerberos 5 authentication not supported\n"));
libpq_append_conn_error(conn, "Kerberos 5 authentication not supported");
return STATUS_ERROR;
#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 */
case AUTH_REQ_GSS:
case AUTH_REQ_GSS_CONT:
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("GSSAPI authentication not supported\n"));
libpq_append_conn_error(conn, "GSSAPI authentication not supported");
return STATUS_ERROR;
#endif /* defined(ENABLE_GSS) || defined(ENABLE_SSPI) */
@ -1007,16 +977,14 @@ pg_fe_sendauth(AuthRequest areq, int payloadlen, PGconn *conn)
*/
#if !defined(ENABLE_GSS)
case AUTH_REQ_SSPI:
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("SSPI authentication not supported\n"));
libpq_append_conn_error(conn, "SSPI authentication not supported");
return STATUS_ERROR;
#endif /* !define(ENABLE_GSS) */
#endif /* ENABLE_SSPI */
case AUTH_REQ_CRYPT:
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("Crypt authentication not supported\n"));
libpq_append_conn_error(conn, "Crypt authentication not supported");
return STATUS_ERROR;
case AUTH_REQ_MD5:
@ -1082,8 +1050,7 @@ pg_fe_sendauth(AuthRequest areq, int payloadlen, PGconn *conn)
break;
default:
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("authentication method %u not supported\n"), areq);
libpq_append_conn_error(conn, "authentication method %u not supported", areq);
return STATUS_ERROR;
}
@ -1128,9 +1095,9 @@ pg_fe_getusername(uid_t user_id, PQExpBuffer errorMessage)
if (GetUserName(username, &namesize))
name = username;
else if (errorMessage)
appendPQExpBuffer(errorMessage,
libpq_gettext("user name lookup failure: error code %lu\n"),
GetLastError());
libpq_append_error(errorMessage,
"user name lookup failure: error code %lu",
GetLastError());
#else
if (pg_get_user_name(user_id, pwdbuf, sizeof(pwdbuf)))
name = pwdbuf;
@ -1142,8 +1109,7 @@ pg_fe_getusername(uid_t user_id, PQExpBuffer errorMessage)
{
result = strdup(name);
if (result == NULL && errorMessage)
appendPQExpBufferStr(errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_error(errorMessage, "out of memory");
}
pgunlock_thread();
@ -1254,8 +1220,7 @@ PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user,
if (PQntuples(res) != 1 || PQnfields(res) != 1)
{
PQclear(res);
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("unexpected shape of result set returned for SHOW\n"));
libpq_append_conn_error(conn, "unexpected shape of result set returned for SHOW");
return NULL;
}
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)
{
PQclear(res);
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("password_encryption value too long\n"));
libpq_append_conn_error(conn, "password_encryption value too long");
return NULL;
}
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);
if (!crypt_pwd)
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not encrypt password: %s\n"),
errstr);
libpq_append_conn_error(conn, "could not encrypt password: %s", errstr);
}
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))
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not encrypt password: %s\n"),
errstr);
libpq_append_conn_error(conn, "could not encrypt password: %s", errstr);
free(crypt_pwd);
crypt_pwd = NULL;
}
}
else
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
}
else
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("unrecognized password encryption algorithm \"%s\"\n"),
libpq_append_conn_error(conn, "unrecognized password encryption algorithm \"%s\"",
algorithm);
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';
}
else
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("write to server failed\n"));
libpq_append_conn_error(conn, "write to server failed");
pqSaveErrorResult(conn);
}
@ -867,8 +866,7 @@ pqPrepareAsyncResult(PGconn *conn)
* text.
*/
if (!conn->error_result)
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("no error text available\n"));
libpq_append_conn_error(conn, "no error text available");
/* Paranoia: be sure errorReported offset is sane */
if (conn->errorReported < 0 ||
@ -1316,8 +1314,7 @@ pqAllocCmdQueueEntry(PGconn *conn)
entry = (PGcmdQueueEntry *) malloc(sizeof(PGcmdQueueEntry));
if (entry == NULL)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
return NULL;
}
}
@ -1440,15 +1437,13 @@ PQsendQueryInternal(PGconn *conn, const char *query, bool newQuery)
/* check the argument */
if (!query)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("command string is a null pointer\n"));
libpq_append_conn_error(conn, "command string is a null pointer");
return 0;
}
if (conn->pipelineStatus != PQ_PIPELINE_OFF)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("%s not allowed in pipeline mode\n"),
libpq_append_conn_error(conn, "%s not allowed in pipeline mode",
"PQsendQuery");
return 0;
}
@ -1511,15 +1506,13 @@ PQsendQueryParams(PGconn *conn,
/* check the arguments */
if (!command)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("command string is a null pointer\n"));
libpq_append_conn_error(conn, "command string is a null pointer");
return 0;
}
if (nParams < 0 || nParams > PQ_QUERY_PARAM_MAX_LIMIT)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("number of parameters must be between 0 and %d\n"),
PQ_QUERY_PARAM_MAX_LIMIT);
libpq_append_conn_error(conn, "number of parameters must be between 0 and %d",
PQ_QUERY_PARAM_MAX_LIMIT);
return 0;
}
@ -1554,21 +1547,18 @@ PQsendPrepare(PGconn *conn,
/* check the arguments */
if (!stmtName)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("statement name is a null pointer\n"));
libpq_append_conn_error(conn, "statement name is a null pointer");
return 0;
}
if (!query)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("command string is a null pointer\n"));
libpq_append_conn_error(conn, "command string is a null pointer");
return 0;
}
if (nParams < 0 || nParams > PQ_QUERY_PARAM_MAX_LIMIT)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("number of parameters must be between 0 and %d\n"),
PQ_QUERY_PARAM_MAX_LIMIT);
libpq_append_conn_error(conn, "number of parameters must be between 0 and %d",
PQ_QUERY_PARAM_MAX_LIMIT);
return 0;
}
@ -1656,15 +1646,13 @@ PQsendQueryPrepared(PGconn *conn,
/* check the arguments */
if (!stmtName)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("statement name is a null pointer\n"));
libpq_append_conn_error(conn, "statement name is a null pointer");
return 0;
}
if (nParams < 0 || nParams > PQ_QUERY_PARAM_MAX_LIMIT)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("number of parameters must be between 0 and %d\n"),
PQ_QUERY_PARAM_MAX_LIMIT);
libpq_append_conn_error(conn, "number of parameters must be between 0 and %d",
PQ_QUERY_PARAM_MAX_LIMIT);
return 0;
}
@ -1700,8 +1688,7 @@ PQsendQueryStart(PGconn *conn, bool newQuery)
/* Don't try to send if we know there's no live connection. */
if (conn->status != CONNECTION_OK)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("no connection to the server\n"));
libpq_append_conn_error(conn, "no connection to the server");
return false;
}
@ -1709,8 +1696,7 @@ PQsendQueryStart(PGconn *conn, bool newQuery)
if (conn->asyncStatus != PGASYNC_IDLE &&
conn->pipelineStatus == PQ_PIPELINE_OFF)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("another command is already in progress\n"));
libpq_append_conn_error(conn, "another command is already in progress");
return false;
}
@ -1740,8 +1726,7 @@ PQsendQueryStart(PGconn *conn, bool newQuery)
case PGASYNC_COPY_IN:
case PGASYNC_COPY_OUT:
case PGASYNC_COPY_BOTH:
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("cannot queue commands during COPY\n"));
libpq_append_conn_error(conn, "cannot queue commands during COPY");
return false;
}
}
@ -1858,8 +1843,7 @@ PQsendQueryGuts(PGconn *conn,
nbytes = paramLengths[i];
else
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("length must be given for binary parameter\n"));
libpq_append_conn_error(conn, "length must be given for binary parameter");
goto sendFailed;
}
}
@ -2181,9 +2165,7 @@ PQgetResult(PGconn *conn)
res = getCopyResult(conn, PGRES_COPY_BOTH);
break;
default:
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("unexpected asyncStatus: %d\n"),
(int) conn->asyncStatus);
libpq_append_conn_error(conn, "unexpected asyncStatus: %d", (int) conn->asyncStatus);
pqSaveErrorResult(conn);
conn->asyncStatus = PGASYNC_IDLE; /* try to restore valid state */
res = pqPrepareAsyncResult(conn);
@ -2339,8 +2321,7 @@ PQexecStart(PGconn *conn)
if (conn->pipelineStatus != PQ_PIPELINE_OFF)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("synchronous command execution functions are not allowed in pipeline mode\n"));
libpq_append_conn_error(conn, "synchronous command execution functions are not allowed in pipeline mode");
return false;
}
@ -2373,8 +2354,7 @@ PQexecStart(PGconn *conn)
else if (resultStatus == PGRES_COPY_BOTH)
{
/* We don't allow PQexec during COPY BOTH */
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("PQexec not allowed during COPY BOTH\n"));
libpq_append_conn_error(conn, "PQexec not allowed during COPY BOTH");
return false;
}
/* check for loss of connection, too */
@ -2600,8 +2580,7 @@ PQputCopyData(PGconn *conn, const char *buffer, int nbytes)
if (conn->asyncStatus != PGASYNC_COPY_IN &&
conn->asyncStatus != PGASYNC_COPY_BOTH)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("no COPY in progress\n"));
libpq_append_conn_error(conn, "no COPY in progress");
return -1;
}
@ -2656,8 +2635,7 @@ PQputCopyEnd(PGconn *conn, const char *errormsg)
if (conn->asyncStatus != PGASYNC_COPY_IN &&
conn->asyncStatus != PGASYNC_COPY_BOTH)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("no COPY in progress\n"));
libpq_append_conn_error(conn, "no COPY in progress");
return -1;
}
@ -2725,8 +2703,7 @@ PQgetCopyData(PGconn *conn, char **buffer, int async)
if (conn->asyncStatus != PGASYNC_COPY_OUT &&
conn->asyncStatus != PGASYNC_COPY_BOTH)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("no COPY in progress\n"));
libpq_append_conn_error(conn, "no COPY in progress");
return -2;
}
return pqGetCopyData3(conn, buffer, async);
@ -2905,17 +2882,14 @@ PQfn(PGconn *conn,
if (conn->pipelineStatus != PQ_PIPELINE_OFF)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("%s not allowed in pipeline mode\n"),
"PQfn");
libpq_append_conn_error(conn, "%s not allowed in pipeline mode", "PQfn");
return NULL;
}
if (conn->sock == PGINVALID_SOCKET || conn->asyncStatus != PGASYNC_IDLE ||
pgHavePendingResult(conn))
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("connection in wrong state\n"));
libpq_append_conn_error(conn, "connection in wrong state");
return NULL;
}
@ -2958,8 +2932,7 @@ PQenterPipelineMode(PGconn *conn)
if (conn->asyncStatus != PGASYNC_IDLE)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("cannot enter pipeline mode, connection not idle\n"));
libpq_append_conn_error(conn, "cannot enter pipeline mode, connection not idle");
return 0;
}
@ -2995,13 +2968,11 @@ PQexitPipelineMode(PGconn *conn)
case PGASYNC_READY:
case PGASYNC_READY_MORE:
/* there are some uncollected results */
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("cannot exit pipeline mode with uncollected results\n"));
libpq_append_conn_error(conn, "cannot exit pipeline mode with uncollected results");
return 0;
case PGASYNC_BUSY:
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("cannot exit pipeline mode while busy\n"));
libpq_append_conn_error(conn, "cannot exit pipeline mode while busy");
return 0;
case PGASYNC_IDLE:
@ -3012,15 +2983,13 @@ PQexitPipelineMode(PGconn *conn)
case PGASYNC_COPY_IN:
case PGASYNC_COPY_OUT:
case PGASYNC_COPY_BOTH:
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("cannot exit pipeline mode while in COPY\n"));
libpq_append_conn_error(conn, "cannot exit pipeline mode while in COPY");
}
/* still work to process */
if (conn->cmd_queue_head != NULL)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("cannot exit pipeline mode with uncollected results\n"));
libpq_append_conn_error(conn, "cannot exit pipeline mode with uncollected results");
return 0;
}
@ -3135,8 +3104,7 @@ pqPipelineProcessQueue(PGconn *conn)
conn->result = PQmakeEmptyPGresult(conn, PGRES_PIPELINE_ABORTED);
if (!conn->result)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
pqSaveErrorResult(conn);
return;
}
@ -3179,8 +3147,7 @@ PQpipelineSync(PGconn *conn)
if (conn->pipelineStatus == PQ_PIPELINE_OFF)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("cannot send pipeline when not in pipeline mode\n"));
libpq_append_conn_error(conn, "cannot send pipeline when not in pipeline mode");
return 0;
}
@ -3246,8 +3213,7 @@ PQsendFlushRequest(PGconn *conn)
/* Don't try to send if we know there's no live connection. */
if (conn->status != CONNECTION_OK)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("no connection to the server\n"));
libpq_append_conn_error(conn, "no connection to the server");
return 0;
}
@ -3255,8 +3221,7 @@ PQsendFlushRequest(PGconn *conn)
if (conn->asyncStatus != PGASYNC_IDLE &&
conn->pipelineStatus == PQ_PIPELINE_OFF)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("another command is already in progress\n"));
libpq_append_conn_error(conn, "another command is already in progress");
return 0;
}
@ -3992,8 +3957,7 @@ PQescapeStringInternal(PGconn *conn,
if (error)
*error = 1;
if (conn)
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("incomplete multibyte character\n"));
libpq_append_conn_error(conn, "incomplete multibyte character");
for (; i < len; i++)
{
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. */
if ((s - str) + charlen > len || memchr(s, 0, charlen) != NULL)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("incomplete multibyte character\n"));
libpq_append_conn_error(conn, "incomplete multibyte character");
return NULL;
}
@ -4101,8 +4064,7 @@ PQescapeInternal(PGconn *conn, const char *str, size_t len, bool as_ident)
result = rp = (char *) malloc(result_size);
if (rp == NULL)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
return NULL;
}
@ -4266,8 +4228,7 @@ PQescapeByteaInternal(PGconn *conn,
if (rp == NULL)
{
if (conn)
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
return NULL;
}

View File

@ -94,8 +94,7 @@ pg_GSS_load_servicename(PGconn *conn)
host = PQhost(conn);
if (!(host && host[0] != '\0'))
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("host name must be specified\n"));
libpq_append_conn_error(conn, "host name must be specified");
return STATUS_ERROR;
}
@ -107,8 +106,7 @@ pg_GSS_load_servicename(PGconn *conn)
temp_gbuf.value = (char *) malloc(maxlen);
if (!temp_gbuf.value)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
return STATUS_ERROR;
}
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 */
if (conn->lobjfuncs->fn_lo_truncate == 0)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("cannot determine OID of function %s\n"),
libpq_append_conn_error(conn, "cannot determine OID of function %s",
"lo_truncate");
return -1;
}
@ -158,8 +157,7 @@ lo_truncate(PGconn *conn, int fd, size_t len)
*/
if (len > (size_t) INT_MAX)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("argument of lo_truncate exceeds integer range\n"));
libpq_append_conn_error(conn, "argument of lo_truncate exceeds integer range");
return -1;
}
@ -206,8 +204,7 @@ lo_truncate64(PGconn *conn, int fd, pg_int64 len)
if (conn->lobjfuncs->fn_lo_truncate64 == 0)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("cannot determine OID of function %s\n"),
libpq_append_conn_error(conn, "cannot determine OID of function %s",
"lo_truncate64");
return -1;
}
@ -262,8 +259,7 @@ lo_read(PGconn *conn, int fd, char *buf, size_t len)
*/
if (len > (size_t) INT_MAX)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("argument of lo_read exceeds integer range\n"));
libpq_append_conn_error(conn, "argument of lo_read exceeds integer range");
return -1;
}
@ -314,8 +310,7 @@ lo_write(PGconn *conn, int fd, const char *buf, size_t len)
*/
if (len > (size_t) INT_MAX)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("argument of lo_write exceeds integer range\n"));
libpq_append_conn_error(conn, "argument of lo_write exceeds integer range");
return -1;
}
@ -399,8 +394,7 @@ lo_lseek64(PGconn *conn, int fd, pg_int64 offset, int whence)
if (conn->lobjfuncs->fn_lo_lseek64 == 0)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("cannot determine OID of function %s\n"),
libpq_append_conn_error(conn, "cannot determine OID of function %s",
"lo_lseek64");
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 */
if (conn->lobjfuncs->fn_lo_create == 0)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("cannot determine OID of function %s\n"),
libpq_append_conn_error(conn, "cannot determine OID of function %s",
"lo_create");
return InvalidOid;
}
@ -564,8 +557,7 @@ lo_tell64(PGconn *conn, int fd)
if (conn->lobjfuncs->fn_lo_tell64 == 0)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("cannot determine OID of function %s\n"),
libpq_append_conn_error(conn, "cannot determine OID of function %s",
"lo_tell64");
return -1;
}
@ -674,8 +666,7 @@ lo_import_internal(PGconn *conn, const char *filename, Oid oid)
fd = open(filename, O_RDONLY | PG_BINARY, 0666);
if (fd < 0)
{ /* error */
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not open file \"%s\": %s\n"),
libpq_append_conn_error(conn, "could not open file \"%s\": %s",
filename, strerror_r(errno, sebuf, sizeof(sebuf)));
return InvalidOid;
}
@ -731,8 +722,7 @@ lo_import_internal(PGconn *conn, const char *filename, Oid oid)
(void) close(fd);
/* deliberately overwrite any error from lo_close */
pqClearConnErrorState(conn);
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not read from file \"%s\": %s\n"),
libpq_append_conn_error(conn, "could not read from file \"%s\": %s",
filename,
strerror_r(save_errno, sebuf, sizeof(sebuf)));
return InvalidOid;
@ -787,8 +777,7 @@ lo_export(PGconn *conn, Oid lobjId, const char *filename)
(void) lo_close(conn, lobj);
/* deliberately overwrite any error from lo_close */
pqClearConnErrorState(conn);
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not open file \"%s\": %s\n"),
libpq_append_conn_error(conn, "could not open file \"%s\": %s",
filename,
strerror_r(save_errno, sebuf, sizeof(sebuf)));
return -1;
@ -809,8 +798,7 @@ lo_export(PGconn *conn, Oid lobjId, const char *filename)
(void) close(fd);
/* deliberately overwrite any error from lo_close */
pqClearConnErrorState(conn);
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not write to file \"%s\": %s\n"),
libpq_append_conn_error(conn, "could not write to file \"%s\": %s",
filename,
strerror_r(save_errno, sebuf, sizeof(sebuf)));
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 (close(fd) != 0 && result >= 0)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not write to file \"%s\": %s\n"),
libpq_append_conn_error(conn, "could not write to file \"%s\": %s",
filename, strerror_r(errno, sebuf, sizeof(sebuf)));
result = -1;
}
@ -880,8 +867,7 @@ lo_initialize(PGconn *conn)
lobjfuncs = (PGlobjfuncs *) malloc(sizeof(PGlobjfuncs));
if (lobjfuncs == NULL)
{
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("out of memory\n"));
libpq_append_conn_error(conn, "out of memory");
return -1;
}
MemSet((char *) lobjfuncs, 0, sizeof(PGlobjfuncs));
@ -919,8 +905,7 @@ lo_initialize(PGconn *conn)
{
free(lobjfuncs);
PQclear(res);
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("query to initialize large object functions did not return data\n"));
libpq_append_conn_error(conn, "query to initialize large object functions did not return data");
return -1;
}
@ -968,64 +953,56 @@ lo_initialize(PGconn *conn)
*/
if (lobjfuncs->fn_lo_open == 0)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("cannot determine OID of function %s\n"),
libpq_append_conn_error(conn, "cannot determine OID of function %s",
"lo_open");
free(lobjfuncs);
return -1;
}
if (lobjfuncs->fn_lo_close == 0)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("cannot determine OID of function %s\n"),
libpq_append_conn_error(conn, "cannot determine OID of function %s",
"lo_close");
free(lobjfuncs);
return -1;
}
if (lobjfuncs->fn_lo_creat == 0)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("cannot determine OID of function %s\n"),
libpq_append_conn_error(conn, "cannot determine OID of function %s",
"lo_creat");
free(lobjfuncs);
return -1;
}
if (lobjfuncs->fn_lo_unlink == 0)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("cannot determine OID of function %s\n"),
libpq_append_conn_error(conn, "cannot determine OID of function %s",
"lo_unlink");
free(lobjfuncs);
return -1;
}
if (lobjfuncs->fn_lo_lseek == 0)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("cannot determine OID of function %s\n"),
libpq_append_conn_error(conn, "cannot determine OID of function %s",
"lo_lseek");
free(lobjfuncs);
return -1;
}
if (lobjfuncs->fn_lo_tell == 0)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("cannot determine OID of function %s\n"),
libpq_append_conn_error(conn, "cannot determine OID of function %s",
"lo_tell");
free(lobjfuncs);
return -1;
}
if (lobjfuncs->fn_lo_read == 0)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("cannot determine OID of function %s\n"),
libpq_append_conn_error(conn, "cannot determine OID of function %s",
"loread");
free(lobjfuncs);
return -1;
}
if (lobjfuncs->fn_lo_write == 0)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("cannot determine OID of function %s\n"),
libpq_append_conn_error(conn, "cannot determine OID of function %s",
"lowrite");
free(lobjfuncs);
return -1;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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