From: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Unix-domain socket support on Windows
Date: Wed, 7 Aug 2019 15:56:03 +0200
Message-ID: <54bde68c-d134-4eb8-5bd3-8af33b72a010@2ndquadrant.com> (raw)
It works!
(apparently as of Windows 10 version 1803)
Here are some patches to get a discussion rolling.
Basically, it just works, but you need to define your own struct
sockaddr_un. (This is what configure currently uses as a proxy for
HAVE_UNIX_SOCKETS, so (a) that needs a bit of tweaking, and (b) that is
the reason why builds haven't blown up already.)
But we'll now need to make things work so that binaries with Unix-domain
socket support work on systems without run-time support. We already did
that exercise with IPv6 support, so some of the framework is already in
place.
Depending on your Windows environment, there might not be a suitable
/tmp directory, so you'll need to specify a directory explicitly using
postgres -k or similar. This leads to the question what the default for
DEFAULT_PGSOCKET_DIR should be on Windows. I think it's probably best,
at least for now, to set it so that by default, neither server nor libpq
use Unix sockets unless explicitly selected. This can be done easily on
the server side by defining DEFAULT_PGSOCKET_DIR as "". But in libpq, I
don't think the code would handle that correctly everywhere, so it would
need some more analysis and restructuring possibly.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From 1f3575f38ca1321e0c5d71217cfb46f8efc35caa Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Wed, 7 Aug 2019 15:44:19 +0200
Subject: [PATCH 1/5] Enable Unix-domain sockets support on Windows
As of Windows 10 version 1803, Unix-domain sockets are supported on
Windows. But it's not automatically detected by configure because it
looks for struct sockaddr_un and Windows doesn't define that. So we
just make our own definition on Windows and override the configure
result.
---
config/c-library.m4 | 5 +++--
configure | 5 ++++-
src/include/c.h | 11 +++++++++++
src/include/pg_config.h.in | 6 +++---
src/include/pg_config.h.win32 | 6 +++---
src/include/pg_config_manual.h | 7 -------
6 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/config/c-library.m4 b/config/c-library.m4index 6f2b0fbb4e..1469b07d2f 100644--- a/config/c-library.m4+++ b/config/c-library.m4@@ -121,10 +121,11 @@ AC_DEFUN([PGAC_UNION_SEMUN],
# PGAC_STRUCT_SOCKADDR_UN
# -----------------------
-# If `struct sockaddr_un' exists, define HAVE_UNIX_SOCKETS.+# If `struct sockaddr_un' exists, define HAVE_STRUCT_SOCKADDR_UN.+# If it is missing then one could define it.
# (Requires test for <sys/un.h>!)
AC_DEFUN([PGAC_STRUCT_SOCKADDR_UN],
-[AC_CHECK_TYPE([struct sockaddr_un], [AC_DEFINE(HAVE_UNIX_SOCKETS, 1, [Define to 1 if you have unix sockets.])], [],+[AC_CHECK_TYPES([struct sockaddr_un], [], [],
[#include <sys/types.h>
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
diff --git a/configure b/configureindex 7a6bfc2339..6e87537be3 100755--- a/configure+++ b/configure@@ -14135,7 +14135,10 @@ ac_fn_c_check_type "$LINENO" "struct sockaddr_un" "ac_cv_type_struct_sockaddr_un
"
if test "x$ac_cv_type_struct_sockaddr_un" = xyes; then :
-$as_echo "#define HAVE_UNIX_SOCKETS 1" >>confdefs.h+cat >>confdefs.h <<_ACEOF+#define HAVE_STRUCT_SOCKADDR_UN 1+_ACEOF+
fi
diff --git a/src/include/c.h b/src/include/c.hindex 2a082afab1..434c403269 100644--- a/src/include/c.h+++ b/src/include/c.h@@ -1263,6 +1263,17 @@ extern unsigned long long strtoull(const char *str, char **endptr, int base);
#define NON_EXEC_STATIC static
#endif
+#ifdef HAVE_STRUCT_SOCKADDR_UN+#define HAVE_UNIX_SOCKETS 1+#elif defined(WIN32)+struct sockaddr_un+{+ unsigned short sun_family;+ char sun_path[108];+};+#define HAVE_UNIX_SOCKETS 1+#endif+
/* /port compatibility functions */
#include "port.h"
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.inindex 512213aa32..e75c090f85 100644--- a/src/include/pg_config.h.in+++ b/src/include/pg_config.h.in@@ -594,6 +594,9 @@
/* Define to 1 if `__ss_len' is a member of `struct sockaddr_storage'. */
#undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN
+/* Define to 1 if the system has the type `struct sockaddr_un'. */+#undef HAVE_STRUCT_SOCKADDR_UN+
/* Define to 1 if `tm_zone' is a member of `struct tm'. */
#undef HAVE_STRUCT_TM_TM_ZONE
@@ -682,9 +685,6 @@
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
-/* Define to 1 if you have unix sockets. */-#undef HAVE_UNIX_SOCKETS-
/* Define to 1 if you have the `unsetenv' function. */
#undef HAVE_UNSETENV
diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32index 2d903c82b8..b947a9fbde 100644--- a/src/include/pg_config.h.win32+++ b/src/include/pg_config.h.win32@@ -463,6 +463,9 @@
/* Define to 1 if `__ss_len' is member of `struct sockaddr_storage'. */
/* #undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN */
+/* Define to 1 if the system has the type `struct sockaddr_un'. */+/* #undef HAVE_STRUCT_SOCKADDR_UN */+
/* Define to 1 if `tm_zone' is member of `struct tm'. */
/* #undef HAVE_STRUCT_TM_TM_ZONE */
@@ -530,9 +533,6 @@
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
-/* Define to 1 if you have unix sockets. */-/* #undef HAVE_UNIX_SOCKETS */-
/* Define to 1 if you have the `unsetenv' function. */
/* #undef HAVE_UNSETENV */
diff --git a/src/include/pg_config_manual.h b/src/include/pg_config_manual.hindex 743401cb96..65d20d44b3 100644--- a/src/include/pg_config_manual.h+++ b/src/include/pg_config_manual.h@@ -109,13 +109,6 @@
*/
#define ALIGNOF_BUFFER 32
-/*- * Disable UNIX sockets for certain operating systems.- */-#if defined(WIN32)-#undef HAVE_UNIX_SOCKETS-#endif-
/*
* Define this if your operating system supports link()
*/
--
2.22.0
From 8bcbe1ab6786e746ac050f464c324c6e9aacdaa2 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Wed, 7 Aug 2019 15:44:19 +0200
Subject: [PATCH 2/5] Sort out getpeereid() and struct passwd handling on
Windows
The getpeereid() uses are protected by HAVE_UNIX_SOCKETS, so they
didn't ever care about Windows support. But that is required now, and
so we need to provide a getpeereid() stub for Windows. We can just
let configure do its usual thing of picking up the replacefrom from
libpgport instead of the custom overrides that it was doing before.
But then Windows doesn't have struct passwd, so all this code around
getpeereid() won't work anyway. This patch just sprinkles some #ifdef
WIN32 around to make it work. Perhaps a configure test for struct
passwd would be a better way to protect this code.
---
configure | 34 +++++++++++++------------------
configure.in | 9 +++-----
src/backend/libpq/auth.c | 6 ++++++
src/include/port.h | 2 +-
src/interfaces/libpq/fe-connect.c | 4 ++++
5 files changed, 28 insertions(+), 27 deletions(-)
diff --git a/configure b/configureindex 6e87537be3..8c48c6ce81 100755--- a/configure+++ b/configure@@ -15837,6 +15837,19 @@ esac
fi
+ac_fn_c_check_func "$LINENO" "getpeereid" "ac_cv_func_getpeereid"+if test "x$ac_cv_func_getpeereid" = xyes; then :+ $as_echo "#define HAVE_GETPEEREID 1" >>confdefs.h++else+ case " $LIBOBJS " in+ *" getpeereid.$ac_objext "* ) ;;+ *) LIBOBJS="$LIBOBJS getpeereid.$ac_objext"+ ;;+esac++fi+
ac_fn_c_check_func "$LINENO" "getrusage" "ac_cv_func_getrusage"
if test "x$ac_cv_func_getrusage" = xyes; then :
$as_echo "#define HAVE_GETRUSAGE 1" >>confdefs.h
@@ -16017,17 +16030,11 @@ esac
case $host_os in
# Windows uses a specialised env handler
- # and doesn't need a replacement getpeereid because it doesn't use- # Unix sockets.
mingw*)
$as_echo "#define HAVE_UNSETENV 1" >>confdefs.h
--$as_echo "#define HAVE_GETPEEREID 1" >>confdefs.h-- ac_cv_func_unsetenv=yes- ac_cv_func_getpeereid=yes;;+ ac_cv_func_unsetenv=yes;;
*)
ac_fn_c_check_func "$LINENO" "unsetenv" "ac_cv_func_unsetenv"
if test "x$ac_cv_func_unsetenv" = xyes; then :
@@ -16040,19 +16047,6 @@ else
;;
esac
-fi--ac_fn_c_check_func "$LINENO" "getpeereid" "ac_cv_func_getpeereid"-if test "x$ac_cv_func_getpeereid" = xyes; then :- $as_echo "#define HAVE_GETPEEREID 1" >>confdefs.h--else- case " $LIBOBJS " in- *" getpeereid.$ac_objext "* ) ;;- *) LIBOBJS="$LIBOBJS getpeereid.$ac_objext"- ;;-esac-
fi
diff --git a/configure.in b/configure.inindex dde3eec89f..03fd9b6a61 100644--- a/configure.in+++ b/configure.in@@ -1696,6 +1696,7 @@ AC_REPLACE_FUNCS(m4_normalize([
dlopen
fls
getopt
+ getpeereid
getrusage
inet_aton
mkdtemp
@@ -1726,15 +1727,11 @@ esac
case $host_os in
# Windows uses a specialised env handler
- # and doesn't need a replacement getpeereid because it doesn't use- # Unix sockets.
mingw*)
AC_DEFINE(HAVE_UNSETENV, 1, [Define to 1 because replacement version used.])
- AC_DEFINE(HAVE_GETPEEREID, 1, [Define to 1 because function not required.])- ac_cv_func_unsetenv=yes- ac_cv_func_getpeereid=yes;;+ ac_cv_func_unsetenv=yes;;
*)
- AC_REPLACE_FUNCS([unsetenv getpeereid])+ AC_REPLACE_FUNCS([unsetenv])
;;
esac
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.cindex 5fb1f1b7d7..8f49b457e4 100644--- a/src/backend/libpq/auth.c+++ b/src/backend/libpq/auth.c@@ -1999,7 +1999,11 @@ auth_peer(hbaPort *port)
}
errno = 0; /* clear errno before call */
+#ifndef WIN32
pw = getpwuid(uid);
+#else+ pw = NULL;+#endif
if (!pw)
{
int save_errno = errno;
@@ -2011,7 +2015,9 @@ auth_peer(hbaPort *port)
return STATUS_ERROR;
}
+#ifndef WIN32
strlcpy(ident_user, pw->pw_name, IDENT_USERNAME_MAX + 1);
+#endif
return check_usermap(port->hba->usermap, port->user_name, ident_user, false);
}
diff --git a/src/include/port.h b/src/include/port.hindex b5c03d912b..a3e7b5c03c 100644--- a/src/include/port.h+++ b/src/include/port.h@@ -357,7 +357,7 @@ extern int fls(int mask);
#define ftello(a) ftell(a)
#endif
-#if !defined(HAVE_GETPEEREID) && !defined(WIN32)+#ifndef HAVE_GETPEEREID
extern int getpeereid(int sock, uid_t *uid, gid_t *gid);
#endif
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.cindex d262b57021..b4fa7a259f 100644--- a/src/interfaces/libpq/fe-connect.c+++ b/src/interfaces/libpq/fe-connect.c@@ -2685,8 +2685,10 @@ PQconnectPoll(PGconn *conn)
IS_AF_UNIX(conn->raddr.addr.ss_family))
{
char pwdbuf[BUFSIZ];
+#ifndef WIN32
struct passwd pass_buf;
struct passwd *pass;
+#endif
int passerr;
uid_t uid;
gid_t gid;
@@ -2708,6 +2710,7 @@ PQconnectPoll(PGconn *conn)
goto error_return;
}
+#ifndef WIN32
passerr = pqGetpwuid(uid, &pass_buf, pwdbuf, sizeof(pwdbuf), &pass);
if (pass == NULL)
{
@@ -2730,6 +2733,7 @@ PQconnectPoll(PGconn *conn)
conn->requirepeer, pass->pw_name);
goto error_return;
}
+#endif /* WIN32 */
}
#endif /* HAVE_UNIX_SOCKETS */
--
2.22.0
From 6ab2c7c3adffe4a9e86068e8d05bd1f332a44368 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Wed, 7 Aug 2019 15:44:19 +0200
Subject: [PATCH 3/5] psql: Remove one use of HAVE_UNIX_SOCKETS
This use was not protecting any unportable code, it was just omitting
the code because it wouldn't be used. Remove the use to reduce code
complexity a bit.
---
src/bin/psql/prompt.c | 7 -------
1 file changed, 7 deletions(-)
diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.cindex 59afbc793a..0d6c1a5364 100644--- a/src/bin/psql/prompt.c+++ b/src/bin/psql/prompt.c@@ -12,11 +12,6 @@
#include <win32.h>
#endif
-#ifdef HAVE_UNIX_SOCKETS-#include <unistd.h>-#include <netdb.h>-#endif-
#include "common.h"
#include "input.h"
#include "prompt.h"
@@ -138,7 +133,6 @@ get_prompt(promptStatus_t status, ConditionalStack cstack)
if (*p == 'm')
buf[strcspn(buf, ".")] = '\0';
}
-#ifdef HAVE_UNIX_SOCKETS
/* UNIX socket */
else
{
@@ -149,7 +143,6 @@ get_prompt(promptStatus_t status, ConditionalStack cstack)
else
snprintf(buf, sizeof(buf), "[local:%s]", host);
}
-#endif
}
break;
/* DB server port number */
--
2.22.0
From 202758ed27915d0d4e1d430e24578d13f6a2412a Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Wed, 7 Aug 2019 15:44:19 +0200
Subject: [PATCH 4/5] libpq: Remove unnecessary uses of HAVE_UNIX_SOCKETS
These are not protecting any unportable code and they were not used
consistently anyway (other code uses IS_AF_UNIX without
HAVE_UNIX_SOCKETS).
---
src/interfaces/libpq/fe-connect.c | 7 -------
1 file changed, 7 deletions(-)
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.cindex b4fa7a259f..a2c1c3002b 100644--- a/src/interfaces/libpq/fe-connect.c+++ b/src/interfaces/libpq/fe-connect.c@@ -1057,10 +1057,8 @@ connectOptions2(PGconn *conn)
else if (ch->host != NULL && ch->host[0] != '\0')
{
ch->type = CHT_HOST_NAME;
-#ifdef HAVE_UNIX_SOCKETS
if (is_absolute_path(ch->host))
ch->type = CHT_UNIX_SOCKET;
-#endif
}
else
{
@@ -1568,7 +1566,6 @@ connectFailureMessage(PGconn *conn, int errorno)
{
char sebuf[PG_STRERROR_R_BUFLEN];
-#ifdef HAVE_UNIX_SOCKETS
if (IS_AF_UNIX(conn->raddr.addr.ss_family))
{
char service[NI_MAXHOST];
@@ -1585,7 +1582,6 @@ connectFailureMessage(PGconn *conn, int errorno)
service);
}
else
-#endif /* HAVE_UNIX_SOCKETS */
{
char host_addr[NI_MAXHOST];
const char *displayed_host;
@@ -2675,8 +2671,6 @@ PQconnectPoll(PGconn *conn)
char *startpacket;
int packetlen;
-#ifdef HAVE_UNIX_SOCKETS-
/*
* Implement requirepeer check, if requested and it's a
* Unix-domain socket.
@@ -2735,7 +2729,6 @@ PQconnectPoll(PGconn *conn)
}
#endif /* WIN32 */
}
-#endif /* HAVE_UNIX_SOCKETS */
if (IS_AF_UNIX(conn->raddr.addr.ss_family))
{
--
2.22.0
From 409e472821e726712cf673d6cea223c7d25d0fd1 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Wed, 7 Aug 2019 15:44:19 +0200
Subject: [PATCH 5/5] initdb: Detect Unix-domain socket support dynamically
On Windows we now have to support the situation where a binary built
with Unix-domain socket support could be used on a system that doesn't
support it at run time. So in initdb, for setting up the default
pg_hba.conf and postgresql.conf, do a run-time check for support
instead of relying on compile-time decisions. This is very similar to
what we already do for IPv6, so similar code can be used.
A change is that now if Unix-domain socket support is not found, the
"local" lines in pg_hba.conf are commented out instead of removed,
again similar to IPv6 support.
---
src/backend/libpq/pg_hba.conf.sample | 6 +-
src/bin/initdb/initdb.c | 170 +++++++++++++--------------
2 files changed, 84 insertions(+), 92 deletions(-)
diff --git a/src/backend/libpq/pg_hba.conf.sample b/src/backend/libpq/pg_hba.conf.sampleindex c853e36232..0c163d2c6d 100644--- a/src/backend/libpq/pg_hba.conf.sample+++ b/src/backend/libpq/pg_hba.conf.sample@@ -76,14 +76,14 @@
# TYPE DATABASE USER ADDRESS METHOD
-@remove-line-for-nolocal@# "local" is for Unix domain socket connections only-@remove-line-for-nolocal@local all all @authmethodlocal@+# "local" is for Unix domain socket connections only+local all all @authmethodlocal@
# IPv4 local connections:
host all all 127.0.0.1/32 @authmethodhost@
# IPv6 local connections:
host all all ::1/128 @authmethodhost@
# Allow replication connections from localhost, by a user with the
# replication privilege.
-@remove-line-for-nolocal@local replication all @authmethodlocal@+local replication all @authmethodlocal@
host replication all 127.0.0.1/32 @authmethodhost@
host replication all ::1/128 @authmethodhost@
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.cindex 9c303e9cc4..4788b75247 100644--- a/src/bin/initdb/initdb.c+++ b/src/bin/initdb/initdb.c@@ -233,9 +233,6 @@ static char backend_exec[MAXPGPATH];
static char **replace_token(char **lines,
const char *token, const char *replacement);
-#ifndef HAVE_UNIX_SOCKETS-static char **filter_lines_with_token(char **lines, const char *token);-#endif
static char **readfile(const char *path);
static void writefile(char *path, char **lines);
static FILE *popen_check(const char *command, const char *mode);
@@ -445,36 +442,6 @@ replace_token(char **lines, const char *token, const char *replacement)
return result;
}
-/*- * make a copy of lines without any that contain the token- *- * a sort of poor man's grep -v- */-#ifndef HAVE_UNIX_SOCKETS-static char **-filter_lines_with_token(char **lines, const char *token)-{- int numlines = 1;- int i,- src,- dst;- char **result;-- for (i = 0; lines[i]; i++)- numlines++;-- result = (char **) pg_malloc(numlines * sizeof(char *));-- for (src = 0, dst = 0; src < numlines; src++)- {- if (lines[src] == NULL || strstr(lines[src], token) == NULL)- result[dst++] = lines[src];- }-- return result;-}-#endif-
/*
* get the lines from a text file
*/
@@ -1084,10 +1051,70 @@ setup_config(void)
char repltok[MAXPGPATH];
char path[MAXPGPATH];
char *autoconflines[3];
+ bool unix_sockets_work = false;+ bool ipv6_works = false;
fputs(_("creating configuration files ... "), stdout);
fflush(stdout);
+#ifdef WIN32+ {+ /* need to call WSAStartup before calling socket or getaddrinfo */+ int err = 0;+ WSADATA wsaData;++ err = WSAStartup(MAKEWORD(2, 2), &wsaData);+ if (err != 0)+ {+ pg_log_error("WSAStartup failed: %d", err);+ exit(1);+ }+ }+#endif++#ifdef HAVE_UNIX_SOCKETS+ /*+ * Probe to see whether Unix-domain sockets are working.+ */+ {+ pgsocket tmpsock;++ tmpsock = socket(AF_UNIX, SOCK_STREAM, 0);+ if (tmpsock != PGINVALID_SOCKET)+ {+ unix_sockets_work = true;+ closesocket(tmpsock);+ }+ }+#endif++#ifdef HAVE_IPV6+ /*+ * Probe to see if there is really any platform support for IPv6, and+ * comment out the relevant pg_hba line if not. This avoids runtime+ * warnings if getaddrinfo doesn't actually cope with IPv6. Particularly+ * useful on Windows, where executables built on a machine with IPv6 may+ * have to run on a machine without.+ */+ {+ struct addrinfo *gai_result;+ struct addrinfo hints;++ /* for best results, this code should match parse_hba_line() */+ hints.ai_flags = AI_NUMERICHOST;+ hints.ai_family = AF_UNSPEC;+ hints.ai_socktype = 0;+ hints.ai_protocol = 0;+ hints.ai_addrlen = 0;+ hints.ai_canonname = NULL;+ hints.ai_addr = NULL;+ hints.ai_next = NULL;++ if (getaddrinfo("::1", NULL, &hints, &gai_result) == 0)+ ipv6_works = true;+ }+#endif /* !HAVE_IPV6 */+
/* postgresql.conf */
conflines = readfile(conf_file);
@@ -1104,8 +1131,11 @@ setup_config(void)
conflines = replace_token(conflines, "#shared_buffers = 32MB", repltok);
#ifdef HAVE_UNIX_SOCKETS
- snprintf(repltok, sizeof(repltok), "#unix_socket_directories = '%s'",- DEFAULT_PGSOCKET_DIR);+ if (unix_sockets_work)+ snprintf(repltok, sizeof(repltok), "#unix_socket_directories = '%s'",+ DEFAULT_PGSOCKET_DIR);+ else+ snprintf(repltok, sizeof(repltok), "unix_socket_directories = ''");
#else
snprintf(repltok, sizeof(repltok), "#unix_socket_directories = ''");
#endif
@@ -1268,63 +1298,25 @@ setup_config(void)
conflines = readfile(hba_file);
-#ifndef HAVE_UNIX_SOCKETS- conflines = filter_lines_with_token(conflines, "@remove-line-for-nolocal@");-#else- conflines = replace_token(conflines, "@remove-line-for-nolocal@", "");-#endif--#ifdef HAVE_IPV6-- /*- * Probe to see if there is really any platform support for IPv6, and- * comment out the relevant pg_hba line if not. This avoids runtime- * warnings if getaddrinfo doesn't actually cope with IPv6. Particularly- * useful on Windows, where executables built on a machine with IPv6 may- * have to run on a machine without.- */+ if (!unix_sockets_work)
{
- struct addrinfo *gai_result;- struct addrinfo hints;- int err = 0;--#ifdef WIN32- /* need to call WSAStartup before calling getaddrinfo */- WSADATA wsaData;-- err = WSAStartup(MAKEWORD(2, 2), &wsaData);-#endif-- /* for best results, this code should match parse_hba_line() */- hints.ai_flags = AI_NUMERICHOST;- hints.ai_family = AF_UNSPEC;- hints.ai_socktype = 0;- hints.ai_protocol = 0;- hints.ai_addrlen = 0;- hints.ai_canonname = NULL;- hints.ai_addr = NULL;- hints.ai_next = NULL;+ conflines = replace_token(conflines,+ "local all",+ "#local all");+ conflines = replace_token(conflines,+ "local replication",+ "#local replication");+ }- if (err != 0 ||- getaddrinfo("::1", NULL, &hints, &gai_result) != 0)- {- conflines = replace_token(conflines,- "host all all ::1",- "#host all all ::1");- conflines = replace_token(conflines,- "host replication all ::1",- "#host replication all ::1");- }+ if (!ipv6_works)+ {+ conflines = replace_token(conflines,+ "host all all ::1",+ "#host all all ::1");+ conflines = replace_token(conflines,+ "host replication all ::1",+ "#host replication all ::1");
}
-#else /* !HAVE_IPV6 */- /* If we didn't compile IPV6 support at all, always comment it out */- conflines = replace_token(conflines,- "host all all ::1",- "#host all all ::1");- conflines = replace_token(conflines,- "host replication all ::1",- "#host replication all ::1");-#endif /* HAVE_IPV6 */
/* Replace default authentication methods */
conflines = replace_token(conflines,
--
2.22.0
Attachments:
[text/plain] 0001-Enable-Unix-domain-sockets-support-on-Windows.patch (4.4K, ../54bde68c-d134-4eb8-5bd3-8af33b72a010@2ndquadrant.com/2-0001-Enable-Unix-domain-sockets-support-on-Windows.patch)
download | inline diff:
From 1f3575f38ca1321e0c5d71217cfb46f8efc35caa Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Wed, 7 Aug 2019 15:44:19 +0200
Subject: [PATCH 1/5] Enable Unix-domain sockets support on Windows
As of Windows 10 version 1803, Unix-domain sockets are supported on
Windows. But it's not automatically detected by configure because it
looks for struct sockaddr_un and Windows doesn't define that. So we
just make our own definition on Windows and override the configure
result.
---
config/c-library.m4 | 5 +++--
configure | 5 ++++-
src/include/c.h | 11 +++++++++++
src/include/pg_config.h.in | 6 +++---
src/include/pg_config.h.win32 | 6 +++---
src/include/pg_config_manual.h | 7 -------
6 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/config/c-library.m4 b/config/c-library.m4index 6f2b0fbb4e..1469b07d2f 100644--- a/config/c-library.m4+++ b/config/c-library.m4@@ -121,10 +121,11 @@ AC_DEFUN([PGAC_UNION_SEMUN],
# PGAC_STRUCT_SOCKADDR_UN
# -----------------------
-# If `struct sockaddr_un' exists, define HAVE_UNIX_SOCKETS.+# If `struct sockaddr_un' exists, define HAVE_STRUCT_SOCKADDR_UN.+# If it is missing then one could define it.
# (Requires test for <sys/un.h>!)
AC_DEFUN([PGAC_STRUCT_SOCKADDR_UN],
-[AC_CHECK_TYPE([struct sockaddr_un], [AC_DEFINE(HAVE_UNIX_SOCKETS, 1, [Define to 1 if you have unix sockets.])], [],+[AC_CHECK_TYPES([struct sockaddr_un], [], [],
[#include <sys/types.h>
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
diff --git a/configure b/configureindex 7a6bfc2339..6e87537be3 100755--- a/configure+++ b/configure@@ -14135,7 +14135,10 @@ ac_fn_c_check_type "$LINENO" "struct sockaddr_un" "ac_cv_type_struct_sockaddr_un
"
if test "x$ac_cv_type_struct_sockaddr_un" = xyes; then :
-$as_echo "#define HAVE_UNIX_SOCKETS 1" >>confdefs.h+cat >>confdefs.h <<_ACEOF+#define HAVE_STRUCT_SOCKADDR_UN 1+_ACEOF+
fi
diff --git a/src/include/c.h b/src/include/c.hindex 2a082afab1..434c403269 100644--- a/src/include/c.h+++ b/src/include/c.h@@ -1263,6 +1263,17 @@ extern unsigned long long strtoull(const char *str, char **endptr, int base);
#define NON_EXEC_STATIC static
#endif
+#ifdef HAVE_STRUCT_SOCKADDR_UN+#define HAVE_UNIX_SOCKETS 1+#elif defined(WIN32)+struct sockaddr_un+{+ unsigned short sun_family;+ char sun_path[108];+};+#define HAVE_UNIX_SOCKETS 1+#endif+
/* /port compatibility functions */
#include "port.h"
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.inindex 512213aa32..e75c090f85 100644--- a/src/include/pg_config.h.in+++ b/src/include/pg_config.h.in@@ -594,6 +594,9 @@
/* Define to 1 if `__ss_len' is a member of `struct sockaddr_storage'. */
#undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN
+/* Define to 1 if the system has the type `struct sockaddr_un'. */+#undef HAVE_STRUCT_SOCKADDR_UN+
/* Define to 1 if `tm_zone' is a member of `struct tm'. */
#undef HAVE_STRUCT_TM_TM_ZONE
@@ -682,9 +685,6 @@
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
-/* Define to 1 if you have unix sockets. */-#undef HAVE_UNIX_SOCKETS-
/* Define to 1 if you have the `unsetenv' function. */
#undef HAVE_UNSETENV
diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32index 2d903c82b8..b947a9fbde 100644--- a/src/include/pg_config.h.win32+++ b/src/include/pg_config.h.win32@@ -463,6 +463,9 @@
/* Define to 1 if `__ss_len' is member of `struct sockaddr_storage'. */
/* #undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN */
+/* Define to 1 if the system has the type `struct sockaddr_un'. */+/* #undef HAVE_STRUCT_SOCKADDR_UN */+
/* Define to 1 if `tm_zone' is member of `struct tm'. */
/* #undef HAVE_STRUCT_TM_TM_ZONE */
@@ -530,9 +533,6 @@
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
-/* Define to 1 if you have unix sockets. */-/* #undef HAVE_UNIX_SOCKETS */-
/* Define to 1 if you have the `unsetenv' function. */
/* #undef HAVE_UNSETENV */
diff --git a/src/include/pg_config_manual.h b/src/include/pg_config_manual.hindex 743401cb96..65d20d44b3 100644--- a/src/include/pg_config_manual.h+++ b/src/include/pg_config_manual.h@@ -109,13 +109,6 @@
*/
#define ALIGNOF_BUFFER 32
-/*- * Disable UNIX sockets for certain operating systems.- */-#if defined(WIN32)-#undef HAVE_UNIX_SOCKETS-#endif-
/*
* Define this if your operating system supports link()
*/
--
2.22.0
[text/plain] 0002-Sort-out-getpeereid-and-struct-passwd-handling-on-Wi.patch (5.4K, ../54bde68c-d134-4eb8-5bd3-8af33b72a010@2ndquadrant.com/3-0002-Sort-out-getpeereid-and-struct-passwd-handling-on-Wi.patch)
download | inline diff:
From 8bcbe1ab6786e746ac050f464c324c6e9aacdaa2 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Wed, 7 Aug 2019 15:44:19 +0200
Subject: [PATCH 2/5] Sort out getpeereid() and struct passwd handling on
Windows
The getpeereid() uses are protected by HAVE_UNIX_SOCKETS, so they
didn't ever care about Windows support. But that is required now, and
so we need to provide a getpeereid() stub for Windows. We can just
let configure do its usual thing of picking up the replacefrom from
libpgport instead of the custom overrides that it was doing before.
But then Windows doesn't have struct passwd, so all this code around
getpeereid() won't work anyway. This patch just sprinkles some #ifdef
WIN32 around to make it work. Perhaps a configure test for struct
passwd would be a better way to protect this code.
---
configure | 34 +++++++++++++------------------
configure.in | 9 +++-----
src/backend/libpq/auth.c | 6 ++++++
src/include/port.h | 2 +-
src/interfaces/libpq/fe-connect.c | 4 ++++
5 files changed, 28 insertions(+), 27 deletions(-)
diff --git a/configure b/configureindex 6e87537be3..8c48c6ce81 100755--- a/configure+++ b/configure@@ -15837,6 +15837,19 @@ esac
fi
+ac_fn_c_check_func "$LINENO" "getpeereid" "ac_cv_func_getpeereid"+if test "x$ac_cv_func_getpeereid" = xyes; then :+ $as_echo "#define HAVE_GETPEEREID 1" >>confdefs.h++else+ case " $LIBOBJS " in+ *" getpeereid.$ac_objext "* ) ;;+ *) LIBOBJS="$LIBOBJS getpeereid.$ac_objext"+ ;;+esac++fi+
ac_fn_c_check_func "$LINENO" "getrusage" "ac_cv_func_getrusage"
if test "x$ac_cv_func_getrusage" = xyes; then :
$as_echo "#define HAVE_GETRUSAGE 1" >>confdefs.h
@@ -16017,17 +16030,11 @@ esac
case $host_os in
# Windows uses a specialised env handler
- # and doesn't need a replacement getpeereid because it doesn't use- # Unix sockets.
mingw*)
$as_echo "#define HAVE_UNSETENV 1" >>confdefs.h
--$as_echo "#define HAVE_GETPEEREID 1" >>confdefs.h-- ac_cv_func_unsetenv=yes- ac_cv_func_getpeereid=yes;;+ ac_cv_func_unsetenv=yes;;
*)
ac_fn_c_check_func "$LINENO" "unsetenv" "ac_cv_func_unsetenv"
if test "x$ac_cv_func_unsetenv" = xyes; then :
@@ -16040,19 +16047,6 @@ else
;;
esac
-fi--ac_fn_c_check_func "$LINENO" "getpeereid" "ac_cv_func_getpeereid"-if test "x$ac_cv_func_getpeereid" = xyes; then :- $as_echo "#define HAVE_GETPEEREID 1" >>confdefs.h--else- case " $LIBOBJS " in- *" getpeereid.$ac_objext "* ) ;;- *) LIBOBJS="$LIBOBJS getpeereid.$ac_objext"- ;;-esac-
fi
diff --git a/configure.in b/configure.inindex dde3eec89f..03fd9b6a61 100644--- a/configure.in+++ b/configure.in@@ -1696,6 +1696,7 @@ AC_REPLACE_FUNCS(m4_normalize([
dlopen
fls
getopt
+ getpeereid
getrusage
inet_aton
mkdtemp
@@ -1726,15 +1727,11 @@ esac
case $host_os in
# Windows uses a specialised env handler
- # and doesn't need a replacement getpeereid because it doesn't use- # Unix sockets.
mingw*)
AC_DEFINE(HAVE_UNSETENV, 1, [Define to 1 because replacement version used.])
- AC_DEFINE(HAVE_GETPEEREID, 1, [Define to 1 because function not required.])- ac_cv_func_unsetenv=yes- ac_cv_func_getpeereid=yes;;+ ac_cv_func_unsetenv=yes;;
*)
- AC_REPLACE_FUNCS([unsetenv getpeereid])+ AC_REPLACE_FUNCS([unsetenv])
;;
esac
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.cindex 5fb1f1b7d7..8f49b457e4 100644--- a/src/backend/libpq/auth.c+++ b/src/backend/libpq/auth.c@@ -1999,7 +1999,11 @@ auth_peer(hbaPort *port)
}
errno = 0; /* clear errno before call */
+#ifndef WIN32
pw = getpwuid(uid);
+#else+ pw = NULL;+#endif
if (!pw)
{
int save_errno = errno;
@@ -2011,7 +2015,9 @@ auth_peer(hbaPort *port)
return STATUS_ERROR;
}
+#ifndef WIN32
strlcpy(ident_user, pw->pw_name, IDENT_USERNAME_MAX + 1);
+#endif
return check_usermap(port->hba->usermap, port->user_name, ident_user, false);
}
diff --git a/src/include/port.h b/src/include/port.hindex b5c03d912b..a3e7b5c03c 100644--- a/src/include/port.h+++ b/src/include/port.h@@ -357,7 +357,7 @@ extern int fls(int mask);
#define ftello(a) ftell(a)
#endif
-#if !defined(HAVE_GETPEEREID) && !defined(WIN32)+#ifndef HAVE_GETPEEREID
extern int getpeereid(int sock, uid_t *uid, gid_t *gid);
#endif
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.cindex d262b57021..b4fa7a259f 100644--- a/src/interfaces/libpq/fe-connect.c+++ b/src/interfaces/libpq/fe-connect.c@@ -2685,8 +2685,10 @@ PQconnectPoll(PGconn *conn)
IS_AF_UNIX(conn->raddr.addr.ss_family))
{
char pwdbuf[BUFSIZ];
+#ifndef WIN32
struct passwd pass_buf;
struct passwd *pass;
+#endif
int passerr;
uid_t uid;
gid_t gid;
@@ -2708,6 +2710,7 @@ PQconnectPoll(PGconn *conn)
goto error_return;
}
+#ifndef WIN32
passerr = pqGetpwuid(uid, &pass_buf, pwdbuf, sizeof(pwdbuf), &pass);
if (pass == NULL)
{
@@ -2730,6 +2733,7 @@ PQconnectPoll(PGconn *conn)
conn->requirepeer, pass->pw_name);
goto error_return;
}
+#endif /* WIN32 */
}
#endif /* HAVE_UNIX_SOCKETS */
--
2.22.0
[text/plain] 0003-psql-Remove-one-use-of-HAVE_UNIX_SOCKETS.patch (1.2K, ../54bde68c-d134-4eb8-5bd3-8af33b72a010@2ndquadrant.com/4-0003-psql-Remove-one-use-of-HAVE_UNIX_SOCKETS.patch)
download | inline diff:
From 6ab2c7c3adffe4a9e86068e8d05bd1f332a44368 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Wed, 7 Aug 2019 15:44:19 +0200
Subject: [PATCH 3/5] psql: Remove one use of HAVE_UNIX_SOCKETS
This use was not protecting any unportable code, it was just omitting
the code because it wouldn't be used. Remove the use to reduce code
complexity a bit.
---
src/bin/psql/prompt.c | 7 -------
1 file changed, 7 deletions(-)
diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.cindex 59afbc793a..0d6c1a5364 100644--- a/src/bin/psql/prompt.c+++ b/src/bin/psql/prompt.c@@ -12,11 +12,6 @@
#include <win32.h>
#endif
-#ifdef HAVE_UNIX_SOCKETS-#include <unistd.h>-#include <netdb.h>-#endif-
#include "common.h"
#include "input.h"
#include "prompt.h"
@@ -138,7 +133,6 @@ get_prompt(promptStatus_t status, ConditionalStack cstack)
if (*p == 'm')
buf[strcspn(buf, ".")] = '\0';
}
-#ifdef HAVE_UNIX_SOCKETS
/* UNIX socket */
else
{
@@ -149,7 +143,6 @@ get_prompt(promptStatus_t status, ConditionalStack cstack)
else
snprintf(buf, sizeof(buf), "[local:%s]", host);
}
-#endif
}
break;
/* DB server port number */
--
2.22.0
[text/plain] 0004-libpq-Remove-unnecessary-uses-of-HAVE_UNIX_SOCKETS.patch (1.7K, ../54bde68c-d134-4eb8-5bd3-8af33b72a010@2ndquadrant.com/5-0004-libpq-Remove-unnecessary-uses-of-HAVE_UNIX_SOCKETS.patch)
download | inline diff:
From 202758ed27915d0d4e1d430e24578d13f6a2412a Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Wed, 7 Aug 2019 15:44:19 +0200
Subject: [PATCH 4/5] libpq: Remove unnecessary uses of HAVE_UNIX_SOCKETS
These are not protecting any unportable code and they were not used
consistently anyway (other code uses IS_AF_UNIX without
HAVE_UNIX_SOCKETS).
---
src/interfaces/libpq/fe-connect.c | 7 -------
1 file changed, 7 deletions(-)
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.cindex b4fa7a259f..a2c1c3002b 100644--- a/src/interfaces/libpq/fe-connect.c+++ b/src/interfaces/libpq/fe-connect.c@@ -1057,10 +1057,8 @@ connectOptions2(PGconn *conn)
else if (ch->host != NULL && ch->host[0] != '\0')
{
ch->type = CHT_HOST_NAME;
-#ifdef HAVE_UNIX_SOCKETS
if (is_absolute_path(ch->host))
ch->type = CHT_UNIX_SOCKET;
-#endif
}
else
{
@@ -1568,7 +1566,6 @@ connectFailureMessage(PGconn *conn, int errorno)
{
char sebuf[PG_STRERROR_R_BUFLEN];
-#ifdef HAVE_UNIX_SOCKETS
if (IS_AF_UNIX(conn->raddr.addr.ss_family))
{
char service[NI_MAXHOST];
@@ -1585,7 +1582,6 @@ connectFailureMessage(PGconn *conn, int errorno)
service);
}
else
-#endif /* HAVE_UNIX_SOCKETS */
{
char host_addr[NI_MAXHOST];
const char *displayed_host;
@@ -2675,8 +2671,6 @@ PQconnectPoll(PGconn *conn)
char *startpacket;
int packetlen;
-#ifdef HAVE_UNIX_SOCKETS-
/*
* Implement requirepeer check, if requested and it's a
* Unix-domain socket.
@@ -2735,7 +2729,6 @@ PQconnectPoll(PGconn *conn)
}
#endif /* WIN32 */
}
-#endif /* HAVE_UNIX_SOCKETS */
if (IS_AF_UNIX(conn->raddr.addr.ss_family))
{
--
2.22.0
[text/plain] 0005-initdb-Detect-Unix-domain-socket-support-dynamically.patch (8.4K, ../54bde68c-d134-4eb8-5bd3-8af33b72a010@2ndquadrant.com/6-0005-initdb-Detect-Unix-domain-socket-support-dynamically.patch)
download | inline diff:
From 409e472821e726712cf673d6cea223c7d25d0fd1 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Wed, 7 Aug 2019 15:44:19 +0200
Subject: [PATCH 5/5] initdb: Detect Unix-domain socket support dynamically
On Windows we now have to support the situation where a binary built
with Unix-domain socket support could be used on a system that doesn't
support it at run time. So in initdb, for setting up the default
pg_hba.conf and postgresql.conf, do a run-time check for support
instead of relying on compile-time decisions. This is very similar to
what we already do for IPv6, so similar code can be used.
A change is that now if Unix-domain socket support is not found, the
"local" lines in pg_hba.conf are commented out instead of removed,
again similar to IPv6 support.
---
src/backend/libpq/pg_hba.conf.sample | 6 +-
src/bin/initdb/initdb.c | 170 +++++++++++++--------------
2 files changed, 84 insertions(+), 92 deletions(-)
diff --git a/src/backend/libpq/pg_hba.conf.sample b/src/backend/libpq/pg_hba.conf.sampleindex c853e36232..0c163d2c6d 100644--- a/src/backend/libpq/pg_hba.conf.sample+++ b/src/backend/libpq/pg_hba.conf.sample@@ -76,14 +76,14 @@
# TYPE DATABASE USER ADDRESS METHOD
-@remove-line-for-nolocal@# "local" is for Unix domain socket connections only-@remove-line-for-nolocal@local all all @authmethodlocal@+# "local" is for Unix domain socket connections only+local all all @authmethodlocal@
# IPv4 local connections:
host all all 127.0.0.1/32 @authmethodhost@
# IPv6 local connections:
host all all ::1/128 @authmethodhost@
# Allow replication connections from localhost, by a user with the
# replication privilege.
-@remove-line-for-nolocal@local replication all @authmethodlocal@+local replication all @authmethodlocal@
host replication all 127.0.0.1/32 @authmethodhost@
host replication all ::1/128 @authmethodhost@
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.cindex 9c303e9cc4..4788b75247 100644--- a/src/bin/initdb/initdb.c+++ b/src/bin/initdb/initdb.c@@ -233,9 +233,6 @@ static char backend_exec[MAXPGPATH];
static char **replace_token(char **lines,
const char *token, const char *replacement);
-#ifndef HAVE_UNIX_SOCKETS-static char **filter_lines_with_token(char **lines, const char *token);-#endif
static char **readfile(const char *path);
static void writefile(char *path, char **lines);
static FILE *popen_check(const char *command, const char *mode);
@@ -445,36 +442,6 @@ replace_token(char **lines, const char *token, const char *replacement)
return result;
}
-/*- * make a copy of lines without any that contain the token- *- * a sort of poor man's grep -v- */-#ifndef HAVE_UNIX_SOCKETS-static char **-filter_lines_with_token(char **lines, const char *token)-{- int numlines = 1;- int i,- src,- dst;- char **result;-- for (i = 0; lines[i]; i++)- numlines++;-- result = (char **) pg_malloc(numlines * sizeof(char *));-- for (src = 0, dst = 0; src < numlines; src++)- {- if (lines[src] == NULL || strstr(lines[src], token) == NULL)- result[dst++] = lines[src];- }-- return result;-}-#endif-
/*
* get the lines from a text file
*/
@@ -1084,10 +1051,70 @@ setup_config(void)
char repltok[MAXPGPATH];
char path[MAXPGPATH];
char *autoconflines[3];
+ bool unix_sockets_work = false;+ bool ipv6_works = false;
fputs(_("creating configuration files ... "), stdout);
fflush(stdout);
+#ifdef WIN32+ {+ /* need to call WSAStartup before calling socket or getaddrinfo */+ int err = 0;+ WSADATA wsaData;++ err = WSAStartup(MAKEWORD(2, 2), &wsaData);+ if (err != 0)+ {+ pg_log_error("WSAStartup failed: %d", err);+ exit(1);+ }+ }+#endif++#ifdef HAVE_UNIX_SOCKETS+ /*+ * Probe to see whether Unix-domain sockets are working.+ */+ {+ pgsocket tmpsock;++ tmpsock = socket(AF_UNIX, SOCK_STREAM, 0);+ if (tmpsock != PGINVALID_SOCKET)+ {+ unix_sockets_work = true;+ closesocket(tmpsock);+ }+ }+#endif++#ifdef HAVE_IPV6+ /*+ * Probe to see if there is really any platform support for IPv6, and+ * comment out the relevant pg_hba line if not. This avoids runtime+ * warnings if getaddrinfo doesn't actually cope with IPv6. Particularly+ * useful on Windows, where executables built on a machine with IPv6 may+ * have to run on a machine without.+ */+ {+ struct addrinfo *gai_result;+ struct addrinfo hints;++ /* for best results, this code should match parse_hba_line() */+ hints.ai_flags = AI_NUMERICHOST;+ hints.ai_family = AF_UNSPEC;+ hints.ai_socktype = 0;+ hints.ai_protocol = 0;+ hints.ai_addrlen = 0;+ hints.ai_canonname = NULL;+ hints.ai_addr = NULL;+ hints.ai_next = NULL;++ if (getaddrinfo("::1", NULL, &hints, &gai_result) == 0)+ ipv6_works = true;+ }+#endif /* !HAVE_IPV6 */+
/* postgresql.conf */
conflines = readfile(conf_file);
@@ -1104,8 +1131,11 @@ setup_config(void)
conflines = replace_token(conflines, "#shared_buffers = 32MB", repltok);
#ifdef HAVE_UNIX_SOCKETS
- snprintf(repltok, sizeof(repltok), "#unix_socket_directories = '%s'",- DEFAULT_PGSOCKET_DIR);+ if (unix_sockets_work)+ snprintf(repltok, sizeof(repltok), "#unix_socket_directories = '%s'",+ DEFAULT_PGSOCKET_DIR);+ else+ snprintf(repltok, sizeof(repltok), "unix_socket_directories = ''");
#else
snprintf(repltok, sizeof(repltok), "#unix_socket_directories = ''");
#endif
@@ -1268,63 +1298,25 @@ setup_config(void)
conflines = readfile(hba_file);
-#ifndef HAVE_UNIX_SOCKETS- conflines = filter_lines_with_token(conflines, "@remove-line-for-nolocal@");-#else- conflines = replace_token(conflines, "@remove-line-for-nolocal@", "");-#endif--#ifdef HAVE_IPV6-- /*- * Probe to see if there is really any platform support for IPv6, and- * comment out the relevant pg_hba line if not. This avoids runtime- * warnings if getaddrinfo doesn't actually cope with IPv6. Particularly- * useful on Windows, where executables built on a machine with IPv6 may- * have to run on a machine without.- */+ if (!unix_sockets_work)
{
- struct addrinfo *gai_result;- struct addrinfo hints;- int err = 0;--#ifdef WIN32- /* need to call WSAStartup before calling getaddrinfo */- WSADATA wsaData;-- err = WSAStartup(MAKEWORD(2, 2), &wsaData);-#endif-- /* for best results, this code should match parse_hba_line() */- hints.ai_flags = AI_NUMERICHOST;- hints.ai_family = AF_UNSPEC;- hints.ai_socktype = 0;- hints.ai_protocol = 0;- hints.ai_addrlen = 0;- hints.ai_canonname = NULL;- hints.ai_addr = NULL;- hints.ai_next = NULL;+ conflines = replace_token(conflines,+ "local all",+ "#local all");+ conflines = replace_token(conflines,+ "local replication",+ "#local replication");+ }- if (err != 0 ||- getaddrinfo("::1", NULL, &hints, &gai_result) != 0)- {- conflines = replace_token(conflines,- "host all all ::1",- "#host all all ::1");- conflines = replace_token(conflines,- "host replication all ::1",- "#host replication all ::1");- }+ if (!ipv6_works)+ {+ conflines = replace_token(conflines,+ "host all all ::1",+ "#host all all ::1");+ conflines = replace_token(conflines,+ "host replication all ::1",+ "#host replication all ::1");
}
-#else /* !HAVE_IPV6 */- /* If we didn't compile IPV6 support at all, always comment it out */- conflines = replace_token(conflines,- "host all all ::1",- "#host all all ::1");- conflines = replace_token(conflines,- "host replication all ::1",- "#host replication all ::1");-#endif /* HAVE_IPV6 */
/* Replace default authentication methods */
conflines = replace_token(conflines,
--
2.22.0
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: peter.eisentraut@2ndquadrant.com
Subject: Re: Unix-domain socket support on Windows
In-Reply-To: <54bde68c-d134-4eb8-5bd3-8af33b72a010@2ndquadrant.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox