Skip to content

Commit

Permalink
Update the oid in the view database_role_members
Browse files Browse the repository at this point in the history
  • Loading branch information
lohia-shalini committed Jan 6, 2025
1 parent b5320fb commit 2841820
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
24 changes: 20 additions & 4 deletions contrib/babelfishpg_tsql/sql/ownership.sql
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,6 @@ SELECT
CAST(Ext.orig_username AS SYS.SYSNAME) AS name,
CAST(
CASE Ext.orig_username
WHEN 'dbo' THEN 1
WHEN 'guest' THEN 2
WHEN 'db_owner' THEN 16384
WHEN 'db_accessadmin' THEN 16385
WHEN 'db_securityadmin' THEN 16386
Expand Down Expand Up @@ -623,8 +621,26 @@ GRANT SELECT ON sys.sysusers TO PUBLIC;
-- DATABASE_ROLE_MEMBERS
CREATE OR REPLACE VIEW sys.database_role_members AS
SELECT
CAST(Auth1.oid AS INT) AS role_principal_id,
CAST(Auth2.oid AS INT) AS member_principal_id
CAST(
CASE Ext1.orig_username
WHEN 'db_owner' THEN 16384
WHEN 'db_accessadmin' THEN 16385
WHEN 'db_securityadmin' THEN 16386
WHEN 'db_ddladmin' THEN 16387
WHEN 'db_datareader' THEN 16390
WHEN 'db_datawriter' THEN 16390
ELSE Auth1.oid
END AS INT) AS role_principal_id,
CAST(
CASE Ext2.orig_username
WHEN 'db_owner' THEN 16384
WHEN 'db_accessadmin' THEN 16385
WHEN 'db_securityadmin' THEN 16386
WHEN 'db_ddladmin' THEN 16387
WHEN 'db_datareader' THEN 16390
WHEN 'db_datawriter' THEN 16390
ELSE Auth2.oid
END AS INT) AS member_principal_id
FROM pg_catalog.pg_auth_members AS Authmbr
INNER JOIN pg_catalog.pg_roles AS Auth1 ON Auth1.oid = Authmbr.roleid
INNER JOIN pg_catalog.pg_roles AS Auth2 ON Auth2.oid = Authmbr.member
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,41 @@ FROM (VALUES ('public', 'R'), ('sys', 'S'), ('INFORMATION_SCHEMA', 'S')) as dumm

GRANT SELECT ON sys.database_principals TO PUBLIC;

-- DATABASE_ROLE_MEMBERS
CREATE OR REPLACE VIEW sys.database_role_members AS
SELECT
CAST(
CASE Ext1.orig_username
WHEN 'db_owner' THEN 16384
WHEN 'db_accessadmin' THEN 16385
WHEN 'db_securityadmin' THEN 16386
WHEN 'db_ddladmin' THEN 16387
WHEN 'db_datareader' THEN 16390
WHEN 'db_datawriter' THEN 16390
ELSE Auth1.oid
END AS INT) AS role_principal_id,
CAST(
CASE Ext2.orig_username
WHEN 'db_owner' THEN 16384
WHEN 'db_accessadmin' THEN 16385
WHEN 'db_securityadmin' THEN 16386
WHEN 'db_ddladmin' THEN 16387
WHEN 'db_datareader' THEN 16390
WHEN 'db_datawriter' THEN 16390
ELSE Auth2.oid
END AS INT) AS member_principal_id
FROM pg_catalog.pg_auth_members AS Authmbr
INNER JOIN pg_catalog.pg_roles AS Auth1 ON Auth1.oid = Authmbr.roleid
INNER JOIN pg_catalog.pg_roles AS Auth2 ON Auth2.oid = Authmbr.member
INNER JOIN sys.babelfish_authid_user_ext AS Ext1 ON Auth1.rolname = Ext1.rolname
INNER JOIN sys.babelfish_authid_user_ext AS Ext2 ON Auth2.rolname = Ext2.rolname
WHERE Ext1.database_name = DB_NAME()
AND Ext2.database_name = DB_NAME()
AND Ext1.type = 'R'
AND Ext2.orig_username != 'db_owner';

GRANT SELECT ON sys.database_role_members TO PUBLIC;

CREATE OR REPLACE PROCEDURE sys.sp_helpuser("@name_in_db" sys.SYSNAME = NULL) AS
$$
BEGIN
Expand Down

0 comments on commit 2841820

Please sign in to comment.