Skip to content

Commit f5c15e2

Browse files
committed
Added full support for sys.database_permissions view
Signed-off-by: Shreya Rai <[email protected]>
1 parent 5e62ffa commit f5c15e2

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/backend/catalog/aclchk.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ static void recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid
173173

174174
tsql_has_linked_srv_permissions_hook_type tsql_has_linked_srv_permissions_hook = NULL;
175175
bbf_execute_grantstmt_as_dbsecadmin_hook_type bbf_execute_grantstmt_as_dbsecadmin_hook = NULL;
176+
update_bbf_schema_permissions_catalog_hook_type update_bbf_schema_permissions_catalog_hook = NULL;
176177
pltsql_allow_storing_init_privs_hook_type pltsql_allow_storing_init_privs_hook = NULL;
177178
/*
178179
* If is_grant is true, adds the given privileges for the list of
@@ -2040,7 +2041,7 @@ ExecGrant_Relation(InternalGrant *istmt)
20402041
{
20412042
(*bbf_execute_grantstmt_as_dbsecadmin_hook) (objtype, relOid, ownerId, this_privileges, &grantorId, &avail_goptions);
20422043
}
2043-
2044+
20442045
/*
20452046
* Restrict the privileges to what we can actually grant, and emit
20462047
* the standards-mandated warning and error messages.
@@ -2052,6 +2053,16 @@ ExecGrant_Relation(InternalGrant *istmt)
20522053
NameStr(pg_class_tuple->relname),
20532054
0, NULL);
20542055

2056+
/* Call the hook to add the permission in bbf_schema_permissions catalog
2057+
* If the hook returns false, indicates that object-level and schema-level grants both are present and schema-level grant is revoked.
2058+
* In such case we remove schema-level entry from the bbf_schema_permissions catalog but skip the execution of revoke as object-level grants exist.
2059+
*/
2060+
if (update_bbf_schema_permissions_catalog_hook && !(*update_bbf_schema_permissions_catalog_hook) (this_privileges, istmt->is_grant, istmt->grantees,
2061+
istmt->col_privs, pg_class_tuple->oid, GetUserNameFromId(grantorId, false),
2062+
istmt->grant_option, GetUserNameFromId(ownerId, false), istmt->objtype))
2063+
{
2064+
return;
2065+
}
20552066
/*
20562067
* Generate new ACL.
20572068
*/
@@ -2258,6 +2269,7 @@ ExecGrant_common(InternalGrant *istmt, Oid classid, AclMode default_privs,
22582269
(*bbf_execute_grantstmt_as_dbsecadmin_hook) (get_object_type(classid, objectid), objectid, ownerId, istmt->privileges, &grantorId, &avail_goptions);
22592270
}
22602271

2272+
22612273
nameDatum = SysCacheGetAttrNotNull(cacheid, tuple,
22622274
get_object_attnum_name(classid));
22632275

@@ -2272,6 +2284,17 @@ ExecGrant_common(InternalGrant *istmt, Oid classid, AclMode default_privs,
22722284
NameStr(*DatumGetName(nameDatum)),
22732285
0, NULL);
22742286

2287+
/* Call the hook to add the permission in bbf_schema_permissions catalog
2288+
* If the hook returns false, indicates that object-level and schema-level grants both are present and schema-level grant is revoked.
2289+
* In such case we remove schema-level entry from the bbf_schema_permissions catalog but skip the execution of revoke as object-level grants exist.
2290+
*/
2291+
if ((istmt->objtype == OBJECT_PROCEDURE || istmt->objtype == OBJECT_FUNCTION) && update_bbf_schema_permissions_catalog_hook && !(*update_bbf_schema_permissions_catalog_hook) (this_privileges, istmt->is_grant, istmt->grantees,
2292+
istmt->col_privs, objectid, GetUserNameFromId(grantorId, false),
2293+
istmt->grant_option, GetUserNameFromId(ownerId, false), istmt->objtype))
2294+
{
2295+
return;
2296+
}
2297+
22752298
/*
22762299
* Generate new ACL.
22772300
*/

src/include/utils/acl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ extern PGDLLEXPORT pltsql_allow_storing_init_privs_hook_type pltsql_allow_storin
312312
typedef bool (*bbf_check_member_has_direct_priv_to_grant_role_hook_type) (Oid, Oid);
313313
extern PGDLLEXPORT bbf_check_member_has_direct_priv_to_grant_role_hook_type bbf_check_member_has_direct_priv_to_grant_role_hook;
314314

315+
typedef bool (*update_bbf_schema_permissions_catalog_hook_type) (AclMode , bool, List*, List*, Oid, const char*, bool, const char*, ObjectType);
316+
extern PGDLLEXPORT update_bbf_schema_permissions_catalog_hook_type update_bbf_schema_permissions_catalog_hook;
317+
315318
#define IS_BBF_DB_DDLADMIN(namespaceId) \
316319
(is_bbf_db_ddladmin_operation_hook && \
317320
is_bbf_db_ddladmin_operation_hook(namespaceId))

0 commit comments

Comments
 (0)