mirror of
https://github.com/postgres/postgres.git
synced 2025-07-26 01:22:12 +03:00
Sort out getpeereid() and peer auth handling on Windows
The getpeereid() uses have so far been protected by HAVE_UNIX_SOCKETS, so they didn't ever care about Windows support. But in anticipation of Unix-domain socket support on Windows, that needs to be handled differently. Windows doesn't support getpeereid() at this time, so we use the existing not-supported code path. We let configure do its usual thing of picking up the replacement from libpgport, instead of the custom overrides that it was doing before. But then Windows doesn't have struct passwd, so this patch sprinkles some additional #ifdef WIN32 around to make it work. This is similar to existing code that deals with this issue. Reviewed-by: Andrew Dunstan <andrew.dunstan@2ndquadrant.com> Discussion: https://www.postgresql.org/message-id/5974caea-1267-7708-40f2-6009a9d653b0@2ndquadrant.com
This commit is contained in:
@ -77,9 +77,7 @@ static int ident_inet(hbaPort *port);
|
||||
* Peer authentication
|
||||
*----------------------------------------------------------------
|
||||
*/
|
||||
#ifdef HAVE_UNIX_SOCKETS
|
||||
static int auth_peer(hbaPort *port);
|
||||
#endif
|
||||
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
@ -559,11 +557,7 @@ ClientAuthentication(Port *port)
|
||||
break;
|
||||
|
||||
case uaPeer:
|
||||
#ifdef HAVE_UNIX_SOCKETS
|
||||
status = auth_peer(port);
|
||||
#else
|
||||
Assert(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case uaIdent:
|
||||
@ -1984,16 +1978,16 @@ ident_inet_done:
|
||||
*
|
||||
* Iff authorized, return STATUS_OK, otherwise return STATUS_ERROR.
|
||||
*/
|
||||
#ifdef HAVE_UNIX_SOCKETS
|
||||
|
||||
static int
|
||||
auth_peer(hbaPort *port)
|
||||
{
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
#ifndef WIN32
|
||||
struct passwd *pw;
|
||||
char *peer_user;
|
||||
int ret;
|
||||
#endif
|
||||
|
||||
if (getpeereid(port->sock, &uid, &gid) != 0)
|
||||
{
|
||||
@ -2009,6 +2003,7 @@ auth_peer(hbaPort *port)
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
errno = 0; /* clear errno before call */
|
||||
pw = getpwuid(uid);
|
||||
if (!pw)
|
||||
@ -2030,8 +2025,12 @@ auth_peer(hbaPort *port)
|
||||
pfree(peer_user);
|
||||
|
||||
return ret;
|
||||
#else
|
||||
/* should have failed with ENOSYS above */
|
||||
Assert(false);
|
||||
return STATUS_ERROR;
|
||||
#endif
|
||||
}
|
||||
#endif /* HAVE_UNIX_SOCKETS */
|
||||
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user