Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Public role attributes #3450

Open
wants to merge 3 commits into
base: BABEL_4_X_DEV
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contrib/babelfishpg_tsql/sql/ownership.sql
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ WHERE (pg_has_role(suser_id(), 'sysadmin'::TEXT, 'MEMBER')
UNION ALL
SELECT
CAST('public' AS SYS.SYSNAME) AS name,
CAST(-1 AS INT) AS principal_id,
CAST(CAST(0 as INT) as sys.varbinary(85)) AS sid,
CAST(2 AS INT) AS principal_id,
CAST(CAST(2 as INT) as sys.varbinary(85)) AS sid,
CAST('R' AS CHAR(1)) as type,
CAST('SERVER_ROLE' AS NVARCHAR(60)) AS type_desc,
CAST(0 AS INT) AS is_disabled,
Expand Down
2 changes: 1 addition & 1 deletion contrib/babelfishpg_tsql/sql/sys_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ LANGUAGE SQL IMMUTABLE PARALLEL RESTRICTED;
CREATE OR REPLACE FUNCTION sys.suser_name()
RETURNS sys.NVARCHAR(128)
AS $$
SELECT sys.suser_name_internal(NULL);
SELECT sys.suser_name_internal(suser_id());
$$
LANGUAGE SQL IMMUTABLE PARALLEL RESTRICTED;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ LANGUAGE plpgsql;
* final behaviour.
*/

DO $$
DECLARE
exception_message text;
BEGIN
ALTER FUNCTION sys.suser_name() RENAME TO suser_name_deprecated_4_6_0;

EXCEPTION WHEN OTHERS THEN
GET STACKED DIAGNOSTICS
exception_message = MESSAGE_TEXT;
RAISE WARNING '%', exception_message;
END;
$$;

CALL sys.babelfish_drop_deprecated_object('function', 'sys', 'suser_name_deprecated_4_6_0');

CREATE OR REPLACE FUNCTION sys.suser_name()
RETURNS sys.NVARCHAR(128)
AS $$
SELECT sys.suser_name_internal(suser_id());
$$
LANGUAGE SQL IMMUTABLE PARALLEL RESTRICTED;

DO $$
DECLARE
exception_message text;
Expand Down Expand Up @@ -520,8 +542,8 @@ WHERE (pg_has_role(suser_id(), 'sysadmin'::TEXT, 'MEMBER')
UNION ALL
SELECT
CAST('public' AS SYS.SYSNAME) AS name,
CAST(-1 AS INT) AS principal_id,
CAST(CAST(0 as INT) as sys.varbinary(85)) AS sid,
CAST(2 AS INT) AS principal_id,
CAST(CAST(2 as INT) as sys.varbinary(85)) AS sid,
CAST('R' AS CHAR(1)) as type,
CAST('SERVER_ROLE' AS NVARCHAR(60)) AS type_desc,
CAST(0 AS INT) AS is_disabled,
Expand Down
13 changes: 11 additions & 2 deletions contrib/babelfishpg_tsql/src/rolecmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,12 @@ suser_name(PG_FUNCTION_ARGS)
server_user_id = PG_ARGISNULL(0) ? InvalidOid : PG_GETARG_OID(0);

if (server_user_id == InvalidOid)
server_user_id = GetSessionUserId();
PG_RETURN_NULL();

if (server_user_id == 0x02)
{
PG_RETURN_TEXT_P(cstring_to_text("public"));
}

ret = GetUserNameFromId(server_user_id, true);

Expand Down Expand Up @@ -1028,7 +1033,11 @@ suser_id(PG_FUNCTION_ARGS)
{
login[i] = tolower(login[i]);
}

/* Check if login is 'public' */
if (strcmp(login, "public") == 0)
{
PG_RETURN_OID(2);
}
/* Check if it is a role and get the oid */
auth_tuple = SearchSysCache1(AUTHNAME, CStringGetDatum(login));
if (!HeapTupleIsValid(auth_tuple))
Expand Down
12 changes: 6 additions & 6 deletions test/JDBC/expected/sys-suser_sname-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -43,46 +43,46 @@ SELECT * FROM sys_suser_sname_view_vu_prepare
GO
~~START~~
nvarchar
jdbc_user
<NULL>
~~END~~


EXEC sys_suser_sname_proc_vu_prepare
GO
~~START~~
nvarchar
jdbc_user
<NULL>
~~END~~


SELECT sys_suser_sname_func_vu_prepare()
GO
~~START~~
varchar
jdbc_user
<NULL>
~~END~~


SELECT * FROM sys_suser_name_view_vu_prepare
GO
~~START~~
nvarchar
jdbc_user
<NULL>
~~END~~


EXEC sys_suser_name_proc_vu_prepare
GO
~~START~~
nvarchar
jdbc_user
<NULL>
~~END~~


SELECT sys_suser_name_func_vu_prepare()
GO
~~START~~
varchar
jdbc_user
<NULL>
~~END~~