1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-10 17:42:29 +03:00

Further work on elog cleanup: fix some bogosities in elog's logic about

when to send what to which, prevent recursion by introducing new COMMERROR
elog level for client-communication problems, get rid of direct writes
to stderr in backend/libpq files, prevent non-error elogs from going to
client during the authentication cycle.
This commit is contained in:
Tom Lane
2002-03-04 01:46:04 +00:00
parent 5ab02fd123
commit 36f693ec69
14 changed files with 299 additions and 489 deletions

View File

@@ -4,7 +4,7 @@
# Makefile for libpq subsystem (backend half of libpq interface)
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/libpq/Makefile,v 1.28 2001/11/13 22:06:58 momjian Exp $
# $Header: /cvsroot/pgsql/src/backend/libpq/Makefile,v 1.29 2002/03/04 01:46:02 tgl Exp $
#
#-------------------------------------------------------------------------
@@ -16,7 +16,7 @@ include $(top_builddir)/src/Makefile.global
OBJS = be-fsstubs.o \
auth.o crypt.o hba.o md5.o password.o \
pqcomm.o pqformat.o pqsignal.o util.o
pqcomm.o pqformat.o pqsignal.o
all: SUBSYS.o

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.76 2002/03/02 21:39:25 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.77 2002/03/04 01:46:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -105,45 +105,34 @@ pg_krb4_recvauth(Port *port)
version);
if (status != KSUCCESS)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"pg_krb4_recvauth: kerberos error: %s\n",
krb_err_txt[status]);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "pg_krb4_recvauth: kerberos error: %s",
krb_err_txt[status]);
return STATUS_ERROR;
}
if (strncmp(version, PG_KRB4_VERSION, KRB_SENDAUTH_VLEN))
if (strncmp(version, PG_KRB4_VERSION, KRB_SENDAUTH_VLEN) != 0)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"pg_krb4_recvauth: protocol version != \"%s\"\n",
PG_KRB4_VERSION);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "pg_krb4_recvauth: protocol version \"%s\" != \"%s\"",
version, PG_KRB4_VERSION);
return STATUS_ERROR;
}
if (strncmp(port->user, auth_data.pname, SM_USER))
if (strncmp(port->user, auth_data.pname, SM_USER) != 0)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"pg_krb4_recvauth: name \"%s\" != \"%s\"\n",
port->user, auth_data.pname);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "pg_krb4_recvauth: name \"%s\" != \"%s\"",
port->user, auth_data.pname);
return STATUS_ERROR;
}
return STATUS_OK;
}
#else
static int
pg_krb4_recvauth(Port *port)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"pg_krb4_recvauth: Kerberos not implemented on this server.\n");
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "pg_krb4_recvauth: Kerberos not implemented on this server");
return STATUS_ERROR;
}
#endif /* KRB4 */
@@ -201,9 +190,8 @@ pg_krb5_init(void)
retval = krb5_init_context(&pg_krb5_context);
if (retval)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"pg_krb5_init: krb5_init_context returned"
" Kerberos error %d\n", retval);
elog(LOG, "pg_krb5_init: krb5_init_context returned Kerberos error %d",
retval);
com_err("postgres", retval, "while initializing krb5");
return STATUS_ERROR;
}
@@ -211,9 +199,8 @@ pg_krb5_init(void)
retval = krb5_kt_resolve(pg_krb5_context, pg_krb_server_keyfile, &pg_krb5_keytab);
if (retval)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"pg_krb5_init: krb5_kt_resolve returned"
" Kerberos error %d\n", retval);
elog(LOG, "pg_krb5_init: krb5_kt_resolve returned Kerberos error %d",
retval);
com_err("postgres", retval, "while resolving keytab file %s",
pg_krb_server_keyfile);
krb5_free_context(pg_krb5_context);
@@ -224,9 +211,8 @@ pg_krb5_init(void)
KRB5_NT_SRV_HST, &pg_krb5_server);
if (retval)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"pg_krb5_init: krb5_sname_to_principal returned"
" Kerberos error %d\n", retval);
elog(LOG, "pg_krb5_init: krb5_sname_to_principal returned Kerberos error %d",
retval);
com_err("postgres", retval,
"while getting server principal for service %s",
PG_KRB_SRVNAM);
@@ -269,9 +255,8 @@ pg_krb5_recvauth(Port *port)
pg_krb5_server, 0, pg_krb5_keytab, &ticket);
if (retval)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"pg_krb5_recvauth: krb5_recvauth returned"
" Kerberos error %d\n", retval);
elog(LOG, "pg_krb5_recvauth: krb5_recvauth returned Kerberos error %d",
retval);
com_err("postgres", retval, "from krb5_recvauth");
return STATUS_ERROR;
}
@@ -294,9 +279,8 @@ pg_krb5_recvauth(Port *port)
#endif
if (retval)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"pg_krb5_recvauth: krb5_unparse_name returned"
" Kerberos error %d\n", retval);
elog(LOG, "pg_krb5_recvauth: krb5_unparse_name returned Kerberos error %d",
retval);
com_err("postgres", retval, "while unparsing client name");
krb5_free_ticket(pg_krb5_context, ticket);
krb5_auth_con_free(pg_krb5_context, auth_context);
@@ -306,9 +290,8 @@ pg_krb5_recvauth(Port *port)
kusername = pg_an_to_ln(kusername);
if (strncmp(port->user, kusername, SM_USER))
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"pg_krb5_recvauth: user name \"%s\" != krb5 name \"%s\"\n",
port->user, kusername);
elog(LOG, "pg_krb5_recvauth: user name \"%s\" != krb5 name \"%s\"",
port->user, kusername);
ret = STATUS_ERROR;
}
else
@@ -322,16 +305,14 @@ pg_krb5_recvauth(Port *port)
}
#else
static int
pg_krb5_recvauth(Port *port)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"pg_krb5_recvauth: Kerberos not implemented on this server.\n");
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "pg_krb5_recvauth: Kerberos not implemented on this server");
return STATUS_ERROR;
}
#endif /* KRB5 */
@@ -388,10 +369,7 @@ recv_and_check_passwordv0(Port *port)
if (user == NULL || password == NULL)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"pg_password_recvauth: badly formed password packet.\n");
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "pg_password_recvauth: badly formed password packet");
status = STATUS_ERROR;
}
else
@@ -530,7 +508,7 @@ ClientAuthentication(Port *port)
if (port->raddr.sa.sa_family == AF_INET)
hostinfo = inet_ntoa(port->raddr.in.sin_addr);
elog(FATAL,
"No pg_hba.conf entry for host %s, user %s, database %s",
"No pg_hba.conf entry for host %s, user %s, database %s",
hostinfo, port->user, port->database);
break;
}
@@ -563,8 +541,7 @@ ClientAuthentication(Port *port)
int on = 1;
if (setsockopt(port->sock, 0, LOCAL_CREDS, &on, sizeof(on)) < 0)
elog(FATAL,
"pg_local_sendauth: can't do setsockopt: %s\n", strerror(errno));
elog(FATAL, "pg_local_sendauth: can't do setsockopt: %m");
}
#endif
if (port->raddr.sa.sa_family == AF_UNIX)
@@ -653,17 +630,12 @@ pam_passwd_conv_proc(int num_msg, const struct pam_message ** msg, struct pam_re
switch (msg[0]->msg_style)
{
case PAM_ERROR_MSG:
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"pam_passwd_conv_proc: Error from underlying PAM layer: '%s'\n", msg[0]->msg);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "pam_passwd_conv_proc: Error from underlying PAM layer: '%s'",
msg[0]->msg);
return PAM_CONV_ERR;
default:
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"pam_passwd_conv_proc: Unexpected PAM conversation %d/'%s'\n",
msg[0]->msg_style, msg[0]->msg);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "pam_passwd_conv_proc: Unexpected PAM conversation %d/'%s'",
msg[0]->msg_style, msg[0]->msg);
return PAM_CONV_ERR;
}
}
@@ -691,12 +663,11 @@ pam_passwd_conv_proc(int num_msg, const struct pam_message ** msg, struct pam_re
initStringInfo(&buf);
pq_getstr(&buf);
elog(DEBUG5, "received PAM packet with len=%d, pw=%s\n", len, buf.data);
elog(DEBUG5, "received PAM packet with len=%d, pw=%s", len, buf.data);
if (strlen(buf.data) == 0)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH, "pam_passwd_conv_proc: no password\n");
fputs(PQerrormsg, stderr);
elog(LOG, "pam_passwd_conv_proc: no password");
return PAM_CONV_ERR;
}
appdata_ptr = buf.data;
@@ -709,9 +680,7 @@ pam_passwd_conv_proc(int num_msg, const struct pam_message ** msg, struct pam_re
*resp = calloc(num_msg, sizeof(struct pam_response));
if (!*resp)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH, "pam_passwd_conv_proc: Out of memory!\n");
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "pam_passwd_conv_proc: Out of memory!");
if (buf.data)
pfree(buf.data);
return PAM_CONV_ERR;
@@ -755,11 +724,8 @@ CheckPAMAuth(Port *port, char *user, char *password)
if (retval != PAM_SUCCESS)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"CheckPAMAuth: Failed to create PAM authenticator: '%s'\n",
pam_strerror(pamh, retval));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "CheckPAMAuth: Failed to create PAM authenticator: '%s'",
pam_strerror(pamh, retval));
pam_passwd = NULL; /* Unset pam_passwd */
return STATUS_ERROR;
}
@@ -768,11 +734,8 @@ CheckPAMAuth(Port *port, char *user, char *password)
if (retval != PAM_SUCCESS)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"CheckPAMAuth: pam_set_item(PAM_USER) failed: '%s'\n",
pam_strerror(pamh, retval));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "CheckPAMAuth: pam_set_item(PAM_USER) failed: '%s'",
pam_strerror(pamh, retval));
pam_passwd = NULL; /* Unset pam_passwd */
return STATUS_ERROR;
}
@@ -781,11 +744,8 @@ CheckPAMAuth(Port *port, char *user, char *password)
if (retval != PAM_SUCCESS)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"CheckPAMAuth: pam_set_item(PAM_CONV) failed: '%s'\n",
pam_strerror(pamh, retval));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "CheckPAMAuth: pam_set_item(PAM_CONV) failed: '%s'",
pam_strerror(pamh, retval));
pam_passwd = NULL; /* Unset pam_passwd */
return STATUS_ERROR;
}
@@ -794,11 +754,8 @@ CheckPAMAuth(Port *port, char *user, char *password)
if (retval != PAM_SUCCESS)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"CheckPAMAuth: pam_authenticate failed: '%s'\n",
pam_strerror(pamh, retval));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "CheckPAMAuth: pam_authenticate failed: '%s'",
pam_strerror(pamh, retval));
pam_passwd = NULL; /* Unset pam_passwd */
return STATUS_ERROR;
}
@@ -807,11 +764,8 @@ CheckPAMAuth(Port *port, char *user, char *password)
if (retval != PAM_SUCCESS)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"CheckPAMAuth: pam_acct_mgmt failed: '%s'\n",
pam_strerror(pamh, retval));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "CheckPAMAuth: pam_acct_mgmt failed: '%s'",
pam_strerror(pamh, retval));
pam_passwd = NULL; /* Unset pam_passwd */
return STATUS_ERROR;
}
@@ -820,11 +774,8 @@ CheckPAMAuth(Port *port, char *user, char *password)
if (retval != PAM_SUCCESS)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"CheckPAMAuth: Failed to release PAM authenticator: '%s'\n",
pam_strerror(pamh, retval));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "CheckPAMAuth: Failed to release PAM authenticator: '%s'",
pam_strerror(pamh, retval));
}
pam_passwd = NULL; /* Unset pam_passwd */
@@ -854,8 +805,8 @@ recv_and_check_password_packet(Port *port)
return STATUS_EOF;
}
elog(DEBUG5, "received password packet with len=%d, pw=%s\n",
len, buf.data);
elog(DEBUG5, "received password packet with len=%d, pw=%s",
len, buf.data);
result = checkPassword(port, port->user, buf.data);
pfree(buf.data);
@@ -907,7 +858,7 @@ old_be_recvauth(Port *port)
break;
default:
fprintf(stderr, "Invalid startup message type: %u\n", msgtype);
elog(LOG, "Invalid startup message type: %u", msgtype);
return STATUS_ERROR;
}

View File

@@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/backend/libpq/crypt.c,v 1.43 2002/03/02 21:39:26 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/crypt.c,v 1.44 2002/03/04 01:46:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -273,11 +273,8 @@ md5_crypt_verify(const Port *port, const char *user, const char *pgpass)
/* If they encrypt their password, force MD5 */
if (isMD5(passwd) && port->auth_method != uaMD5)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"Password is stored MD5 encrypted. "
"'password' and 'crypt' auth methods cannot be used.\n");
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "Password is stored MD5 encrypted. "
"'password' and 'crypt' auth methods cannot be used.");
return STATUS_ERROR;
}

View File

@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.79 2002/01/09 19:13:40 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.80 2002/03/04 01:46:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -269,7 +269,7 @@ parse_hba_auth(List *line, UserAuth *userauth_p, char *auth_arg,
* to a database named port->database. If so, return *found_p true
* and fill in the auth arguments into the appropriate port fields.
* If not, leave *found_p as it was. If the record has a syntax error,
* return *error_p true, after issuing a message to stderr. If no error,
* return *error_p true, after issuing a message to the log. If no error,
* leave *error_p as it was.
*/
static void
@@ -391,12 +391,9 @@ parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p)
return;
hba_syntax:
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"parse_hba: invalid syntax in pg_hba.conf file at line %d, token \"%s\"\n",
line_number,
line ? (const char *) lfirst(line) : "(end of line)");
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "parse_hba: invalid syntax in pg_hba.conf file at line %d, token \"%s\"",
line_number,
line ? (const char *) lfirst(line) : "(end of line)");
*error_p = true;
return;
@@ -464,13 +461,10 @@ load_hba(void)
{
/* Old config file exists. Tell this guy he needs to upgrade. */
close(fd);
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"A file exists by the name used for host-based authentication "
"in prior releases of Postgres (%s). The name and format of "
"the configuration file have changed, so this file should be "
"converted.\n", old_conf_file);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "A file exists by the name used for host-based authentication "
"in prior releases of Postgres (%s). The name and format of "
"the configuration file have changed, so this file should be "
"converted.", old_conf_file);
}
else
{
@@ -486,11 +480,8 @@ load_hba(void)
if (file == NULL)
{
/* The open of the config file failed. */
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"load_hba: Unable to open authentication config file \"%s\": %s\n",
conf_file, strerror(errno));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "load_hba: Unable to open authentication config file \"%s\": %m",
conf_file);
}
else
{
@@ -553,12 +544,9 @@ parse_ident_usermap(List *line, const char *usermap_name, const char *pg_user,
return;
ident_syntax:
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"parse_ident_usermap: invalid syntax in pg_ident.conf file at line %d, token \"%s\"\n",
line_number,
line ? (const char *) lfirst(line) : "(end of line)");
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "parse_ident_usermap: invalid syntax in pg_ident.conf file at line %d, token \"%s\"",
line_number,
line ? (const char *) lfirst(line) : "(end of line)");
*error_p = true;
return;
@@ -588,13 +576,10 @@ check_ident_usermap(const char *usermap_name,
if (usermap_name[0] == '\0')
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"check_ident_usermap: hba configuration file does not "
"have the usermap field filled in in the entry that pertains "
"to this connection. That field is essential for Ident-based "
"authentication.\n");
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "check_ident_usermap: hba configuration file does not "
"have the usermap field filled in in the entry that pertains "
"to this connection. That field is essential for Ident-based "
"authentication.");
found_entry = false;
}
else if (strcmp(usermap_name, "sameuser") == 0)
@@ -641,11 +626,8 @@ load_ident(void)
if (file == NULL)
{
/* The open of the map file failed. */
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"load_ident: Unable to open usermap file \"%s\": %s\n",
map_file, strerror(errno));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "load_ident: Unable to open usermap file \"%s\": %m",
map_file);
}
else
{
@@ -766,11 +748,7 @@ ident_inet(const struct in_addr remote_ip_addr,
sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
if (sock_fd == -1)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"Failed to create socket on which to talk to Ident server. "
"socket() returned errno = %s (%d)\n", strerror(errno), errno);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "Failed to create socket on which to talk to Ident server: %m");
ident_return = false;
}
else
@@ -803,14 +781,14 @@ ident_inet(const struct in_addr remote_ip_addr,
}
if (rc != 0)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"Unable to connect to Ident server on the host which is "
"trying to connect to Postgres "
"(IP address %s, Port %d). "
"errno = %s (%d)\n",
inet_ntoa(remote_ip_addr), IDENT_PORT, strerror(errno), errno);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
/* save_errno is in case inet_ntoa changes errno */
int save_errno = errno;
elog(LOG, "Unable to connect to Ident server on the host which is "
"trying to connect to Postgres "
"(IP address %s, Port %d): %s",
inet_ntoa(remote_ip_addr), IDENT_PORT,
strerror(save_errno));
ident_return = false;
}
else
@@ -826,15 +804,13 @@ ident_inet(const struct in_addr remote_ip_addr,
} while (rc < 0 && errno == EINTR);
if (rc < 0)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"Unable to send query to Ident server on the host which is "
"trying to connect to Postgres (Host %s, Port %d),"
"even though we successfully connected to it. "
"errno = %s (%d)\n",
inet_ntoa(remote_ip_addr), IDENT_PORT,
strerror(errno), errno);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
int save_errno = errno;
elog(LOG, "Unable to send query to Ident server on the host which is "
"trying to connect to Postgres (Host %s, Port %d), "
"even though we successfully connected to it: %s",
inet_ntoa(remote_ip_addr), IDENT_PORT,
strerror(save_errno));
ident_return = false;
}
else
@@ -845,16 +821,14 @@ ident_inet(const struct in_addr remote_ip_addr,
sizeof(ident_response) - 1, 0);
if (rc < 0)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"Unable to receive response from Ident server "
"on the host which is "
"trying to connect to Postgres (Host %s, Port %d),"
"even though we successfully sent our query to it. "
"errno = %s (%d)\n",
inet_ntoa(remote_ip_addr), IDENT_PORT,
strerror(errno), errno);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
int save_errno = errno;
elog(LOG, "Unable to receive response from Ident server "
"on the host which is "
"trying to connect to Postgres (Host %s, Port %d), "
"even though we successfully sent our query to it: %s",
inet_ntoa(remote_ip_addr), IDENT_PORT,
strerror(save_errno));
ident_return = false;
}
else
@@ -891,11 +865,7 @@ ident_unix(int sock, char *ident_user)
so_len != sizeof(peercred))
{
/* We didn't get a valid credentials struct. */
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"ident_unix: error receiving credentials: %s\n",
strerror(errno));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "ident_unix: error receiving credentials: %m");
return false;
}
@@ -903,10 +873,8 @@ ident_unix(int sock, char *ident_user)
if (pass == NULL)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"ident_unix: unknown local user with uid %d\n", peercred.uid);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "ident_unix: unknown local user with uid %d",
(int) peercred.uid);
return false;
}
@@ -962,11 +930,7 @@ ident_unix(int sock, char *ident_user)
cmsg->cmsg_len < sizeof(cmsgmem) ||
cmsg->cmsg_type != SCM_CREDS)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"ident_unix: error receiving credentials: %s\n",
strerror(errno));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "ident_unix: error receiving credentials: %m");
return false;
}
@@ -975,11 +939,8 @@ ident_unix(int sock, char *ident_user)
pw = getpwuid(cred->cruid);
if (pw == NULL)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"ident_unix: unknown local user with uid %d\n",
cred->cruid);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "ident_unix: unknown local user with uid %d",
(int) cred->cruid);
return false;
}
@@ -988,10 +949,7 @@ ident_unix(int sock, char *ident_user)
return true;
#else
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"'ident' auth is not supported on local connections on this platform\n");
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "'ident' auth is not supported on local connections on this platform");
return false;
#endif

View File

@@ -2,7 +2,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: password.c,v 1.40 2001/10/25 05:49:30 momjian Exp $
* $Id: password.c,v 1.41 2002/03/04 01:46:03 tgl Exp $
*
*/
@@ -36,11 +36,8 @@ verify_password(const Port *port, const char *user, const char *password)
pw_file = AllocateFile(pw_file_fullname, PG_BINARY_R);
if (!pw_file)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"verify_password: Unable to open password file \"%s\": %s\n",
pw_file_fullname, strerror(errno));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "verify_password: Unable to open password file \"%s\": %m",
pw_file_fullname);
pfree(pw_file_fullname);
@@ -96,11 +93,8 @@ verify_password(const Port *port, const char *user, const char *password)
return STATUS_OK;
}
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"verify_password: password mismatch for '%s'.\n",
user);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "verify_password: password mismatch for '%s'",
user);
return STATUS_ERROR;
}
@@ -108,11 +102,8 @@ verify_password(const Port *port, const char *user, const char *password)
FreeFile(pw_file);
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"verify_password: user '%s' not found in password file.\n",
user);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "verify_password: user '%s' not found in password file",
user);
return STATUS_ERROR;
}

View File

@@ -29,7 +29,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: pqcomm.c,v 1.127 2002/03/02 21:39:26 momjian Exp $
* $Id: pqcomm.c,v 1.128 2002/03/04 01:46:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -189,11 +189,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
if ((fd = socket(family, SOCK_STREAM, 0)) < 0)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"FATAL: StreamServerPort: socket() failed: %s\n",
strerror(errno));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "StreamServerPort: socket() failed: %m");
return STATUS_ERROR;
}
@@ -202,11 +198,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
if ((setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &one,
sizeof(one))) == -1)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"FATAL: StreamServerPort: setsockopt(SO_REUSEADDR) failed: %s\n",
strerror(errno));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "StreamServerPort: setsockopt(SO_REUSEADDR) failed: %m");
return STATUS_ERROR;
}
}
@@ -247,11 +239,8 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
hp = gethostbyname(hostName);
if ((hp == NULL) || (hp->h_addrtype != AF_INET))
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"FATAL: StreamServerPort: gethostbyname(%s) failed\n",
hostName);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "StreamServerPort: gethostbyname(%s) failed",
hostName);
return STATUS_ERROR;
}
memmove((char *) &(saddr.in.sin_addr), (char *) hp->h_addr,
@@ -265,21 +254,16 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
err = bind(fd, (struct sockaddr *) & saddr.sa, len);
if (err < 0)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"FATAL: StreamServerPort: bind() failed: %s\n"
"\tIs another postmaster already running on port %d?\n",
strerror(errno), (int) portNumber);
if (family == AF_UNIX)
snprintf(PQerrormsg + strlen(PQerrormsg),
PQERRORMSG_LENGTH - strlen(PQerrormsg),
"\tIf not, remove socket node (%s) and retry.\n",
sock_path);
elog(LOG, "StreamServerPort: bind() failed: %m\n"
"\tIs another postmaster already running on port %d?\n"
"\tIf not, remove socket node (%s) and retry.",
(int) portNumber, sock_path);
else
snprintf(PQerrormsg + strlen(PQerrormsg),
PQERRORMSG_LENGTH - strlen(PQerrormsg),
"\tIf not, wait a few seconds and retry.\n");
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "StreamServerPort: bind() failed: %m\n"
"\tIs another postmaster already running on port %d?\n"
"\tIf not, wait a few seconds and retry.",
(int) portNumber);
return STATUS_ERROR;
}
@@ -315,33 +299,24 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
gr = getgrnam(Unix_socket_group);
if (!gr)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"FATAL: no such group '%s'\n",
Unix_socket_group);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "No such group as '%s'",
Unix_socket_group);
return STATUS_ERROR;
}
gid = gr->gr_gid;
}
if (chown(sock_path, -1, gid) == -1)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"FATAL: could not set group of %s: %s\n",
sock_path, strerror(errno));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "Could not set group of %s: %m",
sock_path);
return STATUS_ERROR;
}
}
if (chmod(sock_path, Unix_socket_permissions) == -1)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"FATAL: could not set permissions on %s: %s\n",
sock_path, strerror(errno));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "Could not set permissions on %s: %m",
sock_path);
return STATUS_ERROR;
}
}
@@ -359,11 +334,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
err = listen(fd, maxconn);
if (err < 0)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"FATAL: StreamServerPort: listen() failed: %s\n",
strerror(errno));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
elog(LOG, "StreamServerPort: listen() failed: %m");
return STATUS_ERROR;
}
@@ -380,10 +351,6 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
* the Postmaster uses select() to tell when the server master
* socket is ready for accept().
*
* NB: this can NOT call elog() because it is invoked in the postmaster,
* not in standard backend context. If we get an error, the best we can do
* is log it to stderr.
*
* RETURNS: STATUS_OK or STATUS_ERROR
*/
int
@@ -507,15 +474,15 @@ pq_recvbuf(void)
* Careful: an elog() that tries to write to the client
* would cause recursion to here, leading to stack overflow
* and core dump! This message must go *only* to the postmaster
* log. elog(LOG) is presently safe.
* log.
*/
elog(LOG, "pq_recvbuf: recv() failed: %m");
elog(COMMERROR, "pq_recvbuf: recv() failed: %m");
return EOF;
}
if (r == 0)
{
/* as above, only write to postmaster log */
elog(LOG, "pq_recvbuf: unexpected EOF on client connection");
elog(COMMERROR, "pq_recvbuf: unexpected EOF on client connection");
return EOF;
}
/* r contains number of bytes read, so just incr length */
@@ -680,7 +647,7 @@ pq_flush(void)
* Careful: an elog() that tries to write to the client
* would cause recursion to here, leading to stack overflow
* and core dump! This message must go *only* to the postmaster
* log. elog(LOG) is presently safe.
* log.
*
* If a client disconnects while we're in the midst of output,
* we might write quite a bit of data before we get to a safe
@@ -689,7 +656,7 @@ pq_flush(void)
if (errno != last_reported_send_errno)
{
last_reported_send_errno = errno;
elog(LOG, "pq_flush: send() failed: %m");
elog(COMMERROR, "pq_flush: send() failed: %m");
}
/*
@@ -723,7 +690,7 @@ pq_eof(void)
if (res < 0)
{
/* can log to postmaster log only */
elog(LOG, "pq_eof: recv() failed: %m");
elog(COMMERROR, "pq_eof: recv() failed: %m");
return EOF;
}
if (res == 0)

View File

@@ -16,7 +16,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: pqformat.c,v 1.19 2001/12/04 20:57:22 tgl Exp $
* $Id: pqformat.c,v 1.20 2002/03/04 01:46:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -284,7 +284,7 @@ pq_getint(int *result, int b)
* if we elog(ERROR) here, we will lose sync with the
* frontend, so just complain to postmaster log instead...
*/
fprintf(stderr, "pq_getint: unsupported size %d\n", b);
elog(COMMERROR, "pq_getint: unsupported size %d", b);
status = EOF;
*result = 0;
break;

View File

@@ -1,77 +0,0 @@
/*-------------------------------------------------------------------------
*
* util.c
* general routines for backend libpq modules
*
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/util.c,v 1.18 2001/10/25 05:49:30 momjian Exp $
*
*-------------------------------------------------------------------------
*/
/*
* UTILITY ROUTINES
* pqdebug - send a string to the debugging output port
* PQtrace - turn on pqdebug() tracing
* PQuntrace - turn off pqdebug() tracing
*/
#include "postgres.h"
#include "libpq/libpq.h"
/* ----------------
* global variables for backend libpq
* ----------------
*/
char PQerrormsg[PQERRORMSG_LENGTH];
/*
* These are not really global --- they are referred to nowhere else.
* We declare them as global symbols to make them easier to set in a debugger.
*/
int PQtracep = 0; /* 1 to print out debugging messages */
FILE *debug_port = (FILE *) NULL;
/* ----------------------------------------------------------------
* PQ utility routines
* ----------------------------------------------------------------
*/
void
pqdebug(char *fmt, char *msg)
{
if (!fmt)
return;
if (PQtracep)
{
/*
* if nothing else was suggested default to stderr
*/
if (!debug_port)
debug_port = stderr;
fprintf(debug_port, fmt, msg);
fprintf(debug_port, "\n");
}
}
/* --------------------------------
* PQtrace() / PQuntrace()
* --------------------------------
*/
void
PQtrace()
{
PQtracep = 1;
}
void
PQuntrace()
{
PQtracep = 0;
}