Skip to content

Commit

Permalink
Add hook has_bbf_role_direct_membership_with_admin_true
Browse files Browse the repository at this point in the history
Signed-off-by: ANJU BHARTI <[email protected]>
  • Loading branch information
ANJU BHARTI committed Dec 31, 2024
1 parent e5a62d9 commit c96f5ca
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
34 changes: 34 additions & 0 deletions contrib/babelfishpg_tsql/src/catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "catalog/catalog.h"
#include "catalog/heap.h"
#include "catalog/indexing.h"
#include "catalog/pg_auth_members.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_proc.h"
Expand Down Expand Up @@ -6287,3 +6288,36 @@ get_tvp_typename_typeschemaname(char *proc_name, char *target_arg_name, char **t
if(!xactStarted)
CommitTransactionCommand();
}

/*
* Returns true if given role has direct member bbf_role_admin
* whose admin_option is true, else returns false.
*/
bool
has_bbf_role_direct_membership_with_admin_true(Oid role)
{
CatCList *memlist;

/*
* Find all existing tuples for given role
* whose member is bbf_role_admin
*/
memlist = SearchSysCacheList2(AUTHMEMROLEMEM,
ObjectIdGetDatum(role),
ObjectIdGetDatum(get_bbf_role_admin_oid()));
for (int i = 0; i < memlist->n_members; i++)
{
HeapTuple tup = &memlist->members[i]->tuple;
Form_pg_auth_members form = (Form_pg_auth_members) GETSTRUCT(tup);

/* Return true if admin_option is true */
if (form->admin_option)
{
ReleaseSysCacheList(memlist);
return true;
}
}

ReleaseSysCacheList(memlist);
return false;
}
1 change: 1 addition & 0 deletions contrib/babelfishpg_tsql/src/catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern bool IsPLtsqlExtendedCatalog(Oid relationId);
extern bool IsPltsqlToastRelationHook(Relation relation);
extern bool IsPltsqlToastClassHook(Form_pg_class pg_class_tup);
extern void pltsql_drop_relation_refcnt_hook(Relation relation);
extern bool has_bbf_role_direct_membership_with_admin_true(Oid role);

/*****************************************
* SYS schema
Expand Down
6 changes: 6 additions & 0 deletions contrib/babelfishpg_tsql/src/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ static pltsql_replace_non_determinstic_hook_type prev_pltsql_replace_non_determi
static pltsql_is_partitioned_table_reloptions_allowed_hook_type prev_pltsql_is_partitioned_table_reloptions_allowed_hook = NULL;
static ExecFuncProc_AclCheck_hook_type prev_ExecFuncProc_AclCheck_hook = NULL;
static bbf_execute_grantstmt_as_dbsecadmin_hook_type prev_bbf_execute_grantstmt_as_dbsecadmin_hook = NULL;
static has_bbf_role_direct_membership_with_admin_true_hook_type prev_has_bbf_role_direct_membership_with_admin_true_hook = NULL;

/*****************************************
* Install / Uninstall
Expand Down Expand Up @@ -517,6 +518,9 @@ InstallExtendedHooks(void)

prev_bbf_execute_grantstmt_as_dbsecadmin_hook = bbf_execute_grantstmt_as_dbsecadmin_hook;
bbf_execute_grantstmt_as_dbsecadmin_hook = handle_grantstmt_for_dbsecadmin;

prev_has_bbf_role_direct_membership_with_admin_true_hook = has_bbf_role_direct_membership_with_admin_true_hook;
has_bbf_role_direct_membership_with_admin_true_hook = has_bbf_role_direct_membership_with_admin_true;

pltsql_get_object_identity_event_trigger_hook = pltsql_get_object_identity_event_trigger;

Expand Down Expand Up @@ -594,6 +598,8 @@ UninstallExtendedHooks(void)
pltsql_is_partitioned_table_reloptions_allowed_hook = prev_pltsql_is_partitioned_table_reloptions_allowed_hook;
ExecFuncProc_AclCheck_hook = prev_ExecFuncProc_AclCheck_hook;
bbf_execute_grantstmt_as_dbsecadmin_hook = prev_bbf_execute_grantstmt_as_dbsecadmin_hook;
has_bbf_role_direct_membership_with_admin_true_hook = prev_has_bbf_role_direct_membership_with_admin_true_hook;


bbf_InitializeParallelDSM_hook = NULL;
bbf_ParallelWorkerMain_hook = NULL;
Expand Down

0 comments on commit c96f5ca

Please sign in to comment.