Matheus Alcantara писал(а) 2025-01-16 16:07:
Em qua., 15 de jan. de 2025 às 14:03, Peter Eisentraut
<pe...@eisentraut.org> escreveu:
On 14.01.25 15:14, Matheus Alcantara wrote:
>> Attached is a fixup patch where I have tried to expand the documentation
>> a bit in an attempt to clarify how to use this. Maybe check that what I
>> wrote is correct.
>
> It looks good to me, it's much clearer now. Thanks.
>
> v4 attached with these fixes and also rebased with master.
Committed, after pgindent and pgperltidy.
Thanks!
Hi.
I've started to look at this feature and found an issue - MyProcPort can
be not set if connection is initiated
by some bgworker. (Internally we use one for statistics collection.) In
other places (for example, in be_gssapi_get_delegation())
there are checks that port is not NULL. Likely postgres_fdw and dblink
should do something similar.
--
Best regards,
Alexander Pyhalov,
Postgres Professional
From 58536182f301ab218d57fd40f298666359ec5757 Mon Sep 17 00:00:00 2001
From: Alexander Pyhalov <a.pyha...@postgrespro.ru>
Date: Wed, 25 Jun 2025 12:05:53 +0300
Subject: [PATCH] postgres_fdw and dblink should check if backend has
MyProcPort
---
contrib/dblink/dblink.c | 8 ++++----
contrib/postgres_fdw/connection.c | 8 ++++----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index 8a0b112a7ff..ec0c832e921 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -2665,7 +2665,7 @@ dblink_connstr_has_required_scram_options(const char *connstr)
PQconninfoFree(options);
}
- has_scram_keys = has_scram_client_key && has_scram_server_key && MyProcPort->has_scram_keys;
+ has_scram_keys = has_scram_client_key && has_scram_server_key && MyProcPort != NULL && MyProcPort->has_scram_keys;
return (has_scram_keys && has_require_auth);
}
@@ -2698,7 +2698,7 @@ dblink_security_check(PGconn *conn, const char *connname, const char *connstr)
* only added if UseScramPassthrough is set, and the user is not allowed
* to add the SCRAM keys on fdw and user mapping options.
*/
- if (MyProcPort->has_scram_keys && dblink_connstr_has_required_scram_options(connstr))
+ if (MyProcPort != NULL && MyProcPort->has_scram_keys && dblink_connstr_has_required_scram_options(connstr))
return;
#ifdef ENABLE_GSS
@@ -2771,7 +2771,7 @@ dblink_connstr_check(const char *connstr)
if (dblink_connstr_has_pw(connstr))
return;
- if (MyProcPort->has_scram_keys && dblink_connstr_has_required_scram_options(connstr))
+ if (MyProcPort != NULL && MyProcPort->has_scram_keys && dblink_connstr_has_required_scram_options(connstr))
return;
#ifdef ENABLE_GSS
@@ -2931,7 +2931,7 @@ get_connect_string(const char *servername)
* the user overwrites these options we can ereport on
* dblink_connstr_check and dblink_security_check.
*/
- if (MyProcPort->has_scram_keys && UseScramPassthrough(foreign_server, user_mapping))
+ if (MyProcPort != NULL && MyProcPort->has_scram_keys && UseScramPassthrough(foreign_server, user_mapping))
appendSCRAMKeysInfo(&buf);
foreach(cell, fdw->options)
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index 304f3c20f83..eb255e74d15 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -462,7 +462,7 @@ pgfdw_security_check(const char **keywords, const char **values, UserMapping *us
* assume that UseScramPassthrough is also true since SCRAM options are
* only set when UseScramPassthrough is enabled.
*/
- if (MyProcPort->has_scram_keys && pgfdw_has_required_scram_options(keywords, values))
+ if (MyProcPort != NULL && MyProcPort->has_scram_keys && pgfdw_has_required_scram_options(keywords, values))
return;
ereport(ERROR,
@@ -568,7 +568,7 @@ connect_pg_server(ForeignServer *server, UserMapping *user)
n++;
/* Add required SCRAM pass-through connection options if it's enabled. */
- if (MyProcPort->has_scram_keys && UseScramPassthrough(server, user))
+ if (MyProcPort != NULL && MyProcPort->has_scram_keys && UseScramPassthrough(server, user))
{
int len;
int encoded_len;
@@ -743,7 +743,7 @@ check_conn_params(const char **keywords, const char **values, UserMapping *user)
* assume that UseScramPassthrough is also true since SCRAM options are
* only set when UseScramPassthrough is enabled.
*/
- if (MyProcPort->has_scram_keys && pgfdw_has_required_scram_options(keywords, values))
+ if (MyProcPort != NULL && MyProcPort->has_scram_keys && pgfdw_has_required_scram_options(keywords, values))
return;
ereport(ERROR,
@@ -2557,7 +2557,7 @@ pgfdw_has_required_scram_options(const char **keywords, const char **values)
}
}
- has_scram_keys = has_scram_client_key && has_scram_server_key && MyProcPort->has_scram_keys;
+ has_scram_keys = has_scram_client_key && has_scram_server_key && MyProcPort != NULL && MyProcPort->has_scram_keys;
return (has_scram_keys && has_require_auth);
}
--
2.43.0