From 4de4ccac11c8738745dc8a2537a7de7a40c9693d Mon Sep 17 00:00:00 2001 From: WangXiuqiang Date: Mon, 13 Mar 2023 16:43:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=85=BC=E5=AE=B9=E6=80=A7B?= =?UTF-8?q?=E5=BA=93=E4=B8=8B=EF=BC=8Calter=20user=20password=E4=B8=8D?= =?UTF-8?q?=E6=94=AF=E6=8C=81'user'@'host'=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/libpq/crypt.cpp | 4 ++-- src/test/regress/input/user_host_test.source | 1 + src/test/regress/output/user_host_test.source | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/common/backend/libpq/crypt.cpp b/src/common/backend/libpq/crypt.cpp index 6ee768bf8..54f1a25eb 100644 --- a/src/common/backend/libpq/crypt.cpp +++ b/src/common/backend/libpq/crypt.cpp @@ -104,7 +104,7 @@ bool get_stored_password(const char* role, password_info* pass_info) t_thrd.int_cxt.ImmediateInterruptOK = false; /* Get role info from pg_authid */ - if (strchr(role, '@')) + if (strchr(role, '@') && !OidIsValid(u_sess->proc_cxt.MyDatabaseId)) ereport(ERROR,(errcode(ERRCODE_INVALID_NAME),errmsg("@ can't be allowed in username"))); roleTup = SearchUserHostName(role, NULL); @@ -167,7 +167,7 @@ static bool GetValidPeriod(const char *role, password_info *passInfo) t_thrd.int_cxt.ImmediateInterruptOK = false; /* Get role info from pg_authid */ - if (strchr(role, '@')) + if (strchr(role, '@') && !OidIsValid(u_sess->proc_cxt.MyDatabaseId)) ereport(ERROR,(errcode(ERRCODE_INVALID_NAME),errmsg("@ can't be allowed in username"))); HeapTuple roleTup = SearchUserHostName(role, NULL); if (!HeapTupleIsValid(roleTup)) { diff --git a/src/test/regress/input/user_host_test.source b/src/test/regress/input/user_host_test.source index 350ba2078..86f46030c 100644 --- a/src/test/regress/input/user_host_test.source +++ b/src/test/regress/input/user_host_test.source @@ -35,6 +35,7 @@ create table test1(a int); alter table test1 owner to 'test_user_host'@'%'; GRANT ALL PRIVILEGES TO 'test_user_host'@'%'; REVOKE ALL PRIVILEGES FROM 'test_user_host'@'%'; +ALTER USER 'test_user_host'@'%' password 'test@123'; ALTER USER 'test_user_host'@'%' RENAME TO 'test_user_host'@'1%'; CREATE DEFINER='test_user_host'@'127.0.%' FUNCTION test_func(integer, integer) RETURNS integer SECURITY INVOKER AS 'select $1 + $2;' diff --git a/src/test/regress/output/user_host_test.source b/src/test/regress/output/user_host_test.source index 7494878fa..e1c0fd885 100644 --- a/src/test/regress/output/user_host_test.source +++ b/src/test/regress/output/user_host_test.source @@ -71,6 +71,7 @@ create table test1(a int); alter table test1 owner to 'test_user_host'@'%'; GRANT ALL PRIVILEGES TO 'test_user_host'@'%'; REVOKE ALL PRIVILEGES FROM 'test_user_host'@'%'; +ALTER USER 'test_user_host'@'%' password 'test@123'; ALTER USER 'test_user_host'@'%' RENAME TO 'test_user_host'@'1%'; CREATE DEFINER='test_user_host'@'127.0.%' FUNCTION test_func(integer, integer) RETURNS integer SECURITY INVOKER AS 'select $1 + $2;'