v2-0002-Sort-out-getpeereid-and-struct-passwd-handling-on.patch
text/plain
Filename: v2-0002-Sort-out-getpeereid-and-struct-passwd-handling-on.patch
Type: text/plain
Part: 1
Patch
Format: format-patch
Series: patch v2-0002
Subject: Sort out getpeereid() and struct passwd handling on Windows
| File | + | − |
|---|---|---|
| configure | 14 | 20 |
| configure.in | 3 | 6 |
| src/backend/libpq/auth.c | 6 | 0 |
| src/include/port.h | 1 | 1 |
| src/interfaces/libpq/fe-connect.c | 4 | 0 |
From 66a8cba64515da97b6614fde23d52bc1f0a6ecd2 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Wed, 7 Aug 2019 15:44:19 +0200
Subject: [PATCH v2 2/7] 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/configure
index 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.in
index 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.c
index 0e0a6d8752..67bf82c898 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.h
index 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.c
index fa5af18ffa..ec456725dd 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -2686,8 +2686,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;
@@ -2709,6 +2711,7 @@ PQconnectPoll(PGconn *conn)
goto error_return;
}
+#ifndef WIN32
passerr = pqGetpwuid(uid, &pass_buf, pwdbuf, sizeof(pwdbuf), &pass);
if (pass == NULL)
{
@@ -2731,6 +2734,7 @@ PQconnectPoll(PGconn *conn)
conn->requirepeer, pass->pw_name);
goto error_return;
}
+#endif /* WIN32 */
}
#endif /* HAVE_UNIX_SOCKETS */
--
2.22.0