Unix-domain socket support on Windows

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Unix-domain socket support on Windows

Peter Eisentraut-6
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

0001-Enable-Unix-domain-sockets-support-on-Windows.patch (6K) Download Attachment
0002-Sort-out-getpeereid-and-struct-passwd-handling-on-Wi.patch (7K) Download Attachment
0003-psql-Remove-one-use-of-HAVE_UNIX_SOCKETS.patch (1K) Download Attachment
0004-libpq-Remove-unnecessary-uses-of-HAVE_UNIX_SOCKETS.patch (2K) Download Attachment
0005-initdb-Detect-Unix-domain-socket-support-dynamically.patch (11K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Unix-domain socket support on Windows

Heikki Linnakangas
On 07/08/2019 16:56, Peter Eisentraut wrote:
> It works!

Cool!

Am I reading the patches correctly, that getpeereid() still doesn't work
on Windows? That means that peer authentication doesn't work, right?
That's a bit sad. One of the big advantages of unix domain sockets over
TCP is peer authentication.

- Heikki


Reply | Threaded
Open this post in threaded view
|

Re: Unix-domain socket support on Windows

Peter Eisentraut-6
On 2019-08-07 16:06, Heikki Linnakangas wrote:
> Am I reading the patches correctly, that getpeereid() still doesn't work
> on Windows? That means that peer authentication doesn't work, right?
> That's a bit sad. One of the big advantages of unix domain sockets over
> TCP is peer authentication.

Correct, it's not supported.  I think it's plausible that they will add
this in the future.

--
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


Reply | Threaded
Open this post in threaded view
|

Re: Unix-domain socket support on Windows

Magnus Hagander-2


On Wed, Aug 7, 2019 at 4:59 PM Peter Eisentraut <[hidden email]> wrote:
On 2019-08-07 16:06, Heikki Linnakangas wrote:
> Am I reading the patches correctly, that getpeereid() still doesn't work
> on Windows? That means that peer authentication doesn't work, right?
> That's a bit sad. One of the big advantages of unix domain sockets over
> TCP is peer authentication.

Correct, it's not supported.  I think it's plausible that they will add
this in the future.

Does it work well enough that SSPI auth can run over it? SSPI auth with the local provider gives you more or less the same results as peer, doesn't it? 

--
Reply | Threaded
Open this post in threaded view
|

Re: Unix-domain socket support on Windows

Peter Eisentraut-6
In reply to this post by Peter Eisentraut-6
On 2019-08-07 15:56, Peter Eisentraut wrote:
> 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.

Updated patches, which now also address that issue: There is no default
socket dir on Windows and it's disabled by default on both client and
server.

Some comments on the patches:

v2-0001-Enable-Unix-domain-sockets-support-on-Windows.patch

This is pretty straightforward, apart from maybe some comments, but it
would need to be committed last, because it would enable all the Unix
socket related code on Windows, which needs to be fixed up by the
subsequent patches first.

v2-0002-Sort-out-getpeereid-and-struct-passwd-handling-on.patch

Maybe a more elegant way with fewer #ifdef WIN32 can be found?

v2-0003-psql-Remove-one-use-of-HAVE_UNIX_SOCKETS.patch

This could be committed independently.

v2-0004-libpq-Remove-unnecessary-uses-of-HAVE_UNIX_SOCKET.patch

This one as well.

v2-0005-initdb-Detect-Unix-domain-socket-support-dynamica.patch

I think this patch contains some nice improvements in general.  How much
of that ends up being useful depends on how the subsequent patches (esp.
0007) end up, since with Unix-domain sockets disabled by default on
Windows, we won't need initdb doing any detection.

v2-0006-Fix-handling-of-Unix-domain-sockets-on-Windows-in.patch

This is a fairly independent and isolated change.

v2-0007-Disable-Unix-sockets-by-default-on-Windows.patch

This one is a bit complicated.  Since there is no good default location
for Unix sockets on Windows, and many systems won't support them for
some time, the default implemented here is to not use them by default on
the server or client.  This needs a fair amount of restructuring in the
to support the case of "supports Unix sockets but don't use them by
default", while maintaining the existing cases of "doesn't support Unix
sockets" and "use Unix sockets by default".  There is some room for
discussion here.


This patch set needs testers with various Windows versions to test
different configurations, combinations, and versions.

--
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

v2-0001-Enable-Unix-domain-sockets-support-on-Windows.patch (6K) Download Attachment
v2-0002-Sort-out-getpeereid-and-struct-passwd-handling-on.patch (7K) Download Attachment
v2-0003-psql-Remove-one-use-of-HAVE_UNIX_SOCKETS.patch (1K) Download Attachment
v2-0004-libpq-Remove-unnecessary-uses-of-HAVE_UNIX_SOCKET.patch (2K) Download Attachment
v2-0005-initdb-Detect-Unix-domain-socket-support-dynamica.patch (11K) Download Attachment
v2-0006-Fix-handling-of-Unix-domain-sockets-on-Windows-in.patch (7K) Download Attachment
v2-0007-Disable-Unix-sockets-by-default-on-Windows.patch (6K) Download Attachment