Fix build breakage on Solaris-alikes with late-model GCC. REL_13_STABLE github/REL_13_STABLE
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 23 Jul 2025 19:44:29 +0000 (15:44 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 23 Jul 2025 19:44:29 +0000 (15:44 -0400)
Solaris has never bothered to add "const" to the second argument
of PAM conversation procs, as all other Unixen did decades ago.
This resulted in an "incompatible pointer" compiler warning when
building --with-pam, but had no more serious effect than that,
so we never did anything about it.  However, as of GCC 14 the
case is an error not warning by default.

To complicate matters, recent OpenIndiana (and maybe illumos
in general?) *does* supply the "const" by default, so we can't
just assume that platforms using our solaris template need help.

What we can do, short of building a configure-time probe,
is to make solaris.h #define _PAM_LEGACY_NONCONST, which
causes OpenIndiana's pam_appl.h to revert to the traditional
definition, and hopefully will have no effect anywhere else.
Then we can use that same symbol to control whether we include
"const" in the declaration of pam_passwd_conv_proc().

Bug: #18995
Reported-by: Andrew Watkins <awatkins1966@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: http://postgr.es/m/18995-82058da9ab4337a7@postgresql.org
Backpatch-through: 13

src/backend/libpq/auth.c
src/include/port/solaris.h

index 66366a5257f3f838ba06083a4c0a39b55440e878..8b63217787050b1a793e1d7a1f202e1c9ff04375 100644 (file)
@@ -94,8 +94,16 @@ static int   auth_peer(hbaPort *port);
 
 #define PGSQL_PAM_SERVICE "postgresql" /* Service name passed to PAM */
 
+/* Work around original Solaris' lack of "const" in the conv_proc signature */
+#ifdef _PAM_LEGACY_NONCONST
+#define PG_PAM_CONST
+#else
+#define PG_PAM_CONST const
+#endif
+
 static int CheckPAMAuth(Port *port, const char *user, const char *password);
-static int pam_passwd_conv_proc(int num_msg, const struct pam_message **msg,
+static int pam_passwd_conv_proc(int num_msg,
+                                PG_PAM_CONST struct pam_message **msg,
                                 struct pam_response **resp, void *appdata_ptr);
 
 static struct pam_conv pam_passw_conv = {
@@ -2041,7 +2049,7 @@ auth_peer(hbaPort *port)
  */
 
 static int
-pam_passwd_conv_proc(int num_msg, const struct pam_message **msg,
+pam_passwd_conv_proc(int num_msg, PG_PAM_CONST struct pam_message **msg,
                     struct pam_response **resp, void *appdata_ptr)
 {
    const char *passwd;
index eeb1a320bd5b75b3589d8c3241897f1034ce7cf7..519aca3e9859e74db16f93caf51f9b3aa50e4da4 100644 (file)
 #include <sys/isa_defs.h>
 #endif
 
+/*
+ * On original Solaris, PAM conversation procs lack a "const" in their
+ * declaration; but recent OpenIndiana versions put it there by default.
+ * The least messy way to deal with this is to define _PAM_LEGACY_NONCONST,
+ * which causes OpenIndiana to declare pam_conv per the Solaris tradition,
+ * and also use that symbol to control omitting the "const" in our own code.
+ */
+#define _PAM_LEGACY_NONCONST 1
+
 /*
  * Many versions of Solaris have broken strtod() --- see bug #4751182.
  * This has been fixed in current versions of Solaris: