summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/postmaster/pgstat.c6
-rw-r--r--src/backend/postmaster/postmaster.c4
-rw-r--r--src/include/port.h5
-rw-r--r--src/interfaces/libpq/Makefile4
-rw-r--r--src/interfaces/libpq/fe-auth.c21
-rw-r--r--src/interfaces/libpq/fe-connect.c4
-rw-r--r--src/port/noblock.c27
7 files changed, 49 insertions, 22 deletions
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index 9d418f9cd45..50c4971eec7 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -13,7 +13,7 @@
*
* Copyright (c) 2001-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.87 2005/01/01 05:43:07 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.87.4.1 2005/03/25 00:35:14 tgl Exp $
* ----------
*/
#include "postgres.h"
@@ -422,7 +422,7 @@ pgstat_init(void)
* messages will be discarded; backends won't block waiting to send
* messages to the collector.
*/
- if (!set_noblock(pgStatSock))
+ if (!pg_set_noblock(pgStatSock))
{
ereport(LOG,
(errcode_for_socket_access(),
@@ -1766,7 +1766,7 @@ pgstat_recvbuffer(void)
* Set the write pipe to nonblock mode, so that we cannot block when
* the collector falls behind.
*/
- if (!set_noblock(writePipe))
+ if (!pg_set_noblock(writePipe))
ereport(ERROR,
(errcode_for_socket_access(),
errmsg("could not set statistics collector pipe to nonblocking mode: %m")));
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 158546ba746..e5162680e43 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -37,7 +37,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.443.4.1 2005/03/18 03:49:17 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.443.4.2 2005/03/25 00:35:14 tgl Exp $
*
* NOTES
*
@@ -2531,7 +2531,7 @@ report_fork_failure_to_client(Port *port, int errnum)
strerror(errnum));
/* Set port to non-blocking. Don't do send() if this fails */
- if (!set_noblock(port->sock))
+ if (!pg_set_noblock(port->sock))
return;
send(port->sock, buffer, strlen(buffer) + 1, 0);
diff --git a/src/include/port.h b/src/include/port.h
index 6e5443294e9..efe42c64df8 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/port.h,v 1.69.4.1 2005/03/17 17:28:58 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/port.h,v 1.69.4.2 2005/03/25 00:35:15 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -20,7 +20,8 @@
#include <ctype.h>
/* non-blocking */
-extern bool set_noblock(int sock);
+extern bool pg_set_noblock(int sock);
+extern bool pg_set_block(int sock);
/* Portable path handling for Unix/Win32 */
diff --git a/src/interfaces/libpq/Makefile b/src/interfaces/libpq/Makefile
index 1bea808bb15..b8381ed492a 100644
--- a/src/interfaces/libpq/Makefile
+++ b/src/interfaces/libpq/Makefile
@@ -5,7 +5,7 @@
# Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California
#
-# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.126.4.2 2005/03/13 22:04:45 momjian Exp $
+# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.126.4.3 2005/03/25 00:35:19 tgl Exp $
#
#-------------------------------------------------------------------------
@@ -55,7 +55,7 @@ endif
# matter.)
SHLIB_LINK += $(filter -lcrypt -ldes -lkrb -lcom_err -lcrypto -lk5crypto -lkrb5 -lssl -lsocket -lnsl -lresolv -lintl, $(LIBS)) $(PTHREAD_LIBS)
ifeq ($(PORTNAME), win32)
-SHLIB_LINK += -lshfolder -lwsock32 -lws2_32 $(filter -leay32 -lssleay32, $(LIBS))
+SHLIB_LINK += -lshfolder -lwsock32 -lws2_32 $(filter -leay32 -lssleay32 -lcomerr32 -lkrb5_32, $(LIBS))
endif
diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c
index 065eba35814..ee01b42f56e 100644
--- a/src/interfaces/libpq/fe-auth.c
+++ b/src/interfaces/libpq/fe-auth.c
@@ -10,7 +10,7 @@
* exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.99 2005/01/12 21:37:54 tgl Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.99.4.1 2005/03/25 00:35:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -367,7 +367,13 @@ pg_krb5_sendauth(char *PQerrormsg, int sock, const char *hostname)
krb5_principal server;
krb5_auth_context auth_context = NULL;
krb5_error *err_ret = NULL;
- int flags;
+
+ if (!hostname)
+ {
+ snprintf(PQerrormsg, PQERRORMSG_LENGTH,
+ "pg_krb5_sendauth: hostname must be specified for Kerberos authentication\n");
+ return STATUS_ERROR;
+ }
ret = pg_krb5_init(PQerrormsg);
if (ret != STATUS_OK)
@@ -388,8 +394,7 @@ pg_krb5_sendauth(char *PQerrormsg, int sock, const char *hostname)
* socket, and we have to block somehow to do mutual authentication
* anyway. So we temporarily make it blocking.
*/
- flags = fcntl(sock, F_GETFL);
- if (flags < 0 || fcntl(sock, F_SETFL, (long) (flags & ~O_NONBLOCK)))
+ if (!pg_set_block(sock))
{
char sebuf[256];
@@ -436,7 +441,7 @@ pg_krb5_sendauth(char *PQerrormsg, int sock, const char *hostname)
krb5_free_principal(pg_krb5_context, server);
- if (fcntl(sock, F_SETFL, (long) flags))
+ if (!pg_set_noblock(sock))
{
char sebuf[256];
@@ -599,8 +604,7 @@ fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
(struct sockaddr_in *) & conn->raddr.addr,
hostname) != STATUS_OK)
{
- snprintf(PQerrormsg, PQERRORMSG_LENGTH,
- libpq_gettext("Kerberos 4 authentication failed\n"));
+ /* PQerrormsg already filled in */
pgunlock_thread();
return STATUS_ERROR;
}
@@ -618,8 +622,7 @@ fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
if (pg_krb5_sendauth(PQerrormsg, conn->sock,
hostname) != STATUS_OK)
{
- snprintf(PQerrormsg, PQERRORMSG_LENGTH,
- libpq_gettext("Kerberos 5 authentication failed\n"));
+ /* PQerrormsg already filled in */
pgunlock_thread();
return STATUS_ERROR;
}
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index db087e305c1..16efba74266 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.301.4.1 2005/01/26 19:24:20 tgl Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.301.4.2 2005/03/25 00:35:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1211,7 +1211,7 @@ keep_going: /* We will come back to here until there
continue;
}
}
- if (!set_noblock(conn->sock))
+ if (!pg_set_noblock(conn->sock))
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not set socket to non-blocking mode: %s\n"),
diff --git a/src/port/noblock.c b/src/port/noblock.c
index d1431545989..0e31b8f82e1 100644
--- a/src/port/noblock.c
+++ b/src/port/noblock.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/port/noblock.c,v 1.5 2004/12/31 22:03:53 pgsql Exp $
+ * $PostgreSQL: pgsql/src/port/noblock.c,v 1.5.4.1 2005/03/25 00:35:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -18,7 +18,7 @@
#include <fcntl.h>
bool
-set_noblock(int sock)
+pg_set_noblock(int sock)
{
#if !defined(WIN32) && !defined(__BEOS__)
return (fcntl(sock, F_SETFL, O_NONBLOCK) != -1);
@@ -34,3 +34,26 @@ set_noblock(int sock)
#endif
#endif
}
+
+
+bool
+pg_set_block(int sock)
+{
+#if !defined(WIN32) && !defined(__BEOS__)
+ int flags;
+ flags = fcntl(sock, F_GETFL);
+ if (flags < 0 || fcntl(sock, F_SETFL, (long) (flags & ~O_NONBLOCK)))
+ return false;
+ return true;
+#else
+ long ioctlsocket_ret = 0;
+
+ /* Returns non-0 on failure, while fcntl() returns -1 on failure */
+#ifdef WIN32
+ return (ioctlsocket(sock, FIONBIO, &ioctlsocket_ret) == 0);
+#endif
+#ifdef __BEOS__
+ return (ioctl(sock, FIONBIO, &ioctlsocket_ret) == 0);
+#endif
+#endif
+}