public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: Daniel Gustafsson <[email protected]>
Cc: Zsolt Parragi <[email protected]>
Cc: Michael Banck <[email protected]>
Cc: Jacob Champion <[email protected]>
Cc: Jelte Fennema-Nio <[email protected]>
Cc: Heikki Linnakangas <[email protected]>
Cc: li.evan.chao <[email protected]>
Cc: Michael Paquier <[email protected]>
Cc: Andres Freund <[email protected]>
Cc: Pgsql Hackers <[email protected]>
Subject: Re: Serverside SNI support in libpq
Date: Mon, 04 May 2026 15:22:37 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <CAOYmi+nsqYiXLxN7G4A5edBJWXZ8qD=zFnaE2bEzuMj2_xBT7Q@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<CAN4CZFOGiKAX_gD4Ck+o79n5hAVr3UmuTbYwaABcCuhWA3UehQ@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<CAN4CZFOFAgfyjO7MtCajmtErL1uSzDrSEmxGHOwMFYY3J4Qp+A@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<CAN4CZFMo_AfSSAfa=0EaC1ARYuQk774R6kcZz6WJZH3oXvn4fw@mail.gmail.com>
	<[email protected]>

In preparation for our annual pgindent update, I checked what happens
when I install the buildfarm's version of typedefs.list, and I found
that the typedef HostsFileLoadResult (from 4f433025f) gets
misformatted because it's not in the buildfarm's list.  That's because
the buildfarm mechanism only captures typedefs that are used to
declare some object (variable, function, field) and this one isn't.

It seems quite odd to me that load_host(), which in fact returns
HostsFileLoadResult codes, is declared to return int.  That seems
to have been done because HostsFileLoadResult wasn't declared in
the same header, but there is no visible reason why it shouldn't be.
Any objection to the attached fixup?

As a side matter, "load_host" seems like a remarkably generic name
that conveys little about what it actually does, and to the extent
that it does convey anything the implication is wrong: it returns
(potentially) info about multiple hosts not just one.  Can't we do
better?

			regards, tom lane



Attachments:

  [text/x-diff] declare-load_host-more-honestly.patch (2.4K, 2-declare-load_host-more-honestly.patch)
  download | inline diff:
diff --git a/src/backend/libpq/be-secure-common.c b/src/backend/libpq/be-secure-common.c
index ad04bedaa1d..6ec887b8a47 100644
--- a/src/backend/libpq/be-secure-common.c
+++ b/src/backend/libpq/be-secure-common.c
@@ -361,7 +361,7 @@ parse_hosts_line(TokenizedAuthLine *tok_line, int elevel)
  * the hosts configuration failed to load, the err_msg variable may have more
  * information in case it was passed as non-NULL.
  */
-int
+HostsFileLoadResult
 load_hosts(List **hosts, char **err_msg)
 {
 	FILE	   *file;
diff --git a/src/backend/libpq/be-secure-openssl.c b/src/backend/libpq/be-secure-openssl.c
index f64b2787f66..b978497b5d4 100644
--- a/src/backend/libpq/be-secure-openssl.c
+++ b/src/backend/libpq/be-secure-openssl.c
@@ -156,7 +156,7 @@ be_tls_init(bool isServerStart)
 	MemoryContext host_memcxt = NULL;
 	MemoryContextCallback *host_memcxt_cb;
 	char	   *err_msg = NULL;
-	int			res;
+	HostsFileLoadResult res;
 	struct hosts *new_hosts;
 	SSL_CTX    *context = NULL;
 	int			ssl_ver_min = -1;
diff --git a/src/include/libpq/hba.h b/src/include/libpq/hba.h
index 29e2a6c5b3d..4aa6258a345 100644
--- a/src/include/libpq/hba.h
+++ b/src/include/libpq/hba.h
@@ -165,15 +165,6 @@ typedef struct HostsLine
 	void	   *ssl_ctx;		/* associated SSL_CTX* for the above settings */
 } HostsLine;
 
-typedef enum HostsFileLoadResult
-{
-	HOSTSFILE_LOAD_OK = 0,
-	HOSTSFILE_LOAD_FAILED,
-	HOSTSFILE_EMPTY,
-	HOSTSFILE_MISSING,
-	HOSTSFILE_DISABLED,
-} HostsFileLoadResult;
-
 /*
  * TokenizedAuthLine represents one line lexed from an authentication
  * configuration file.  Each item in the "fields" list is a sub-list of
diff --git a/src/include/libpq/libpq.h b/src/include/libpq/libpq.h
index c9b934d2321..d15073a0a93 100644
--- a/src/include/libpq/libpq.h
+++ b/src/include/libpq/libpq.h
@@ -156,6 +156,15 @@ enum ssl_protocol_versions
 	PG_TLS1_3_VERSION,
 };
 
+typedef enum HostsFileLoadResult
+{
+	HOSTSFILE_LOAD_OK = 0,
+	HOSTSFILE_LOAD_FAILED,
+	HOSTSFILE_EMPTY,
+	HOSTSFILE_MISSING,
+	HOSTSFILE_DISABLED,
+} HostsFileLoadResult;
+
 /*
  * prototypes for functions in be-secure-common.c
  */
@@ -164,6 +173,6 @@ extern int	run_ssl_passphrase_command(const char *cmd, const char *prompt,
 									   char *buf, int size);
 extern bool check_ssl_key_file_permissions(const char *ssl_key_file,
 										   bool isServerStart);
-extern int	load_hosts(List **hosts, char **err_msg);
+extern HostsFileLoadResult load_hosts(List **hosts, char **err_msg);
 
 #endif							/* LIBPQ_H */


view thread (58+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Serverside SNI support in libpq
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox