v3-0002-Sort-out-getpeereid-and-struct-passwd-handling-on.patch
text/plain
Filename: v3-0002-Sort-out-getpeereid-and-struct-passwd-handling-on.patch
Type: text/plain
Part: 1
Patch
Format: format-patch
Series: patch v3-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 |
| src/tools/msvc/Mkvcbuild.pm | 1 | 1 |
From 16a4afffc28395d19b50c95dc79cd78cbf459a08 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Wed, 7 Aug 2019 15:44:19 +0200
Subject: [PATCH v3 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 ++++
src/tools/msvc/Mkvcbuild.pm | 2 +-
6 files changed, 29 insertions(+), 28 deletions(-)
diff --git a/configure b/configure
index da1ef11991..6726e6a5ec 100755
--- a/configure
+++ b/configure
@@ -15768,6 +15768,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
@@ -15948,17 +15961,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 :
@@ -15971,19 +15978,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 805cf8617b..eb574b764f 100644
--- a/configure.in
+++ b/configure.in
@@ -1693,6 +1693,7 @@ AC_REPLACE_FUNCS(m4_normalize([
dlopen
fls
getopt
+ getpeereid
getrusage
inet_aton
mkdtemp
@@ -1723,15 +1724,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 55619d893c..3f6b270d3c 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -354,7 +354,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 7f1fd2f45e..c013098982 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 */
diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm
index 2eab635898..dfd1d01ac3 100644
--- a/src/tools/msvc/Mkvcbuild.pm
+++ b/src/tools/msvc/Mkvcbuild.pm
@@ -93,7 +93,7 @@ sub mkvcbuild
$solution = CreateSolution($vsVersion, $config);
our @pgportfiles = qw(
- chklocale.c fls.c fseeko.c getrusage.c inet_aton.c random.c
+ chklocale.c fls.c fseeko.c getpeereid.c getrusage.c inet_aton.c random.c
srandom.c getaddrinfo.c gettimeofday.c inet_net_ntop.c kill.c open.c
erand48.c snprintf.c strlcat.c strlcpy.c dirmod.c noblock.c path.c
dirent.c dlopen.c getopt.c getopt_long.c
--
2.22.0