pgsql: More use of getpwuid_r() directly

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: More use of getpwuid_r() directly
Date: 2024-09-02 07:09:49
Message-ID: E1sl1C9-000EDx-1x@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

More use of getpwuid_r() directly

Remove src/port/user.c, call getpwuid_r() directly. This reduces some
complexity and allows better control of the error behavior. For
example, the old code would in some circumstances silently truncate
the result string, or produce error message strings that the caller
wouldn't use.

src/port/user.c used to be called src/port/thread.c and contained
various portability complications to support thread-safety. These are
all obsolete, and all but the user-lookup functions have already been
removed. This patch completes this by also removing the user-lookup
functions.

Also convert src/backend/libpq/auth.c to use getpwuid_r() for
thread-safety.

Originally, I tried to be overly correct by using
sysconf(_SC_GETPW_R_SIZE_MAX) to get the buffer size for getpwuid_r(),
but that doesn't work on FreeBSD. All the OS where I could find the
source code internally use 1024 as the suggested buffer size, so I
just ended up hardcoding that. The previous code used BUFSIZ, which
is an unrelated constant from stdio.h, so its use seemed
inappropriate.

Reviewed-by: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Discussion: https://www.postgresql.org/message-id/flat/5f293da9-ceb4-4937-8e52-82c25db8e4d3%40eisentraut.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/4d5111b3f1a151faf8129e38f8424898588e606d

Modified Files
--------------
src/backend/libpq/auth.c | 21 +++++----
src/bin/psql/nls.mk | 3 +-
src/include/port.h | 6 ---
src/interfaces/libpq/fe-auth.c | 23 +++++++---
src/interfaces/libpq/fe-connect.c | 23 ++++++++--
src/interfaces/libpq/nls.mk | 3 +-
src/port/Makefile | 3 +-
src/port/meson.build | 1 -
src/port/path.c | 23 ++++++++--
src/port/user.c | 89 ---------------------------------------
10 files changed, 72 insertions(+), 123 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Daniel Gustafsson 2024-09-02 08:46:50 pgsql: Cache typarray for fast lookups in binary upgrade mode
Previous Message Michael Paquier 2024-09-02 00:24:55 Re: pgsql: Implement pg_wal_replay_wait() stored procedure