@@ -173,6 +173,7 @@ static void recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid
173
173
174
174
tsql_has_linked_srv_permissions_hook_type tsql_has_linked_srv_permissions_hook = NULL ;
175
175
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 ;
176
177
pltsql_allow_storing_init_privs_hook_type pltsql_allow_storing_init_privs_hook = NULL ;
177
178
/*
178
179
* If is_grant is true, adds the given privileges for the list of
@@ -2040,7 +2041,7 @@ ExecGrant_Relation(InternalGrant *istmt)
2040
2041
{
2041
2042
(* bbf_execute_grantstmt_as_dbsecadmin_hook ) (objtype , relOid , ownerId , this_privileges , & grantorId , & avail_goptions );
2042
2043
}
2043
-
2044
+
2044
2045
/*
2045
2046
* Restrict the privileges to what we can actually grant, and emit
2046
2047
* the standards-mandated warning and error messages.
@@ -2052,6 +2053,16 @@ ExecGrant_Relation(InternalGrant *istmt)
2052
2053
NameStr (pg_class_tuple -> relname ),
2053
2054
0 , NULL );
2054
2055
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
+ }
2055
2066
/*
2056
2067
* Generate new ACL.
2057
2068
*/
@@ -2258,6 +2269,7 @@ ExecGrant_common(InternalGrant *istmt, Oid classid, AclMode default_privs,
2258
2269
(* bbf_execute_grantstmt_as_dbsecadmin_hook ) (get_object_type (classid , objectid ), objectid , ownerId , istmt -> privileges , & grantorId , & avail_goptions );
2259
2270
}
2260
2271
2272
+
2261
2273
nameDatum = SysCacheGetAttrNotNull (cacheid , tuple ,
2262
2274
get_object_attnum_name (classid ));
2263
2275
@@ -2272,6 +2284,17 @@ ExecGrant_common(InternalGrant *istmt, Oid classid, AclMode default_privs,
2272
2284
NameStr (* DatumGetName (nameDatum )),
2273
2285
0 , NULL );
2274
2286
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
+
2275
2298
/*
2276
2299
* Generate new ACL.
2277
2300
*/
0 commit comments