From 0e269aa5354915477a4e1e0b705a9874f8186b74 Mon Sep 17 00:00:00 2001 From: Sharu Goel Date: Wed, 22 Jan 2025 08:48:13 +0000 Subject: [PATCH] Use different ownercheck func Signed-off-by: Sharu Goel --- contrib/babelfishpg_tsql/src/pl_handler.c | 2 +- contrib/babelfishpg_tsql/src/pltsql.h | 1 - contrib/babelfishpg_tsql/src/pltsql_utils.c | 17 ----------------- 3 files changed, 1 insertion(+), 19 deletions(-) diff --git a/contrib/babelfishpg_tsql/src/pl_handler.c b/contrib/babelfishpg_tsql/src/pl_handler.c index 05e3b47197d..5b0cde55efb 100644 --- a/contrib/babelfishpg_tsql/src/pl_handler.c +++ b/contrib/babelfishpg_tsql/src/pl_handler.c @@ -490,7 +490,7 @@ assign_identity_insert(const char *newval, void *extra) * 1. User is owner of object * 2. User is member of db_ddladmin or db_owner database role */ - if (!(has_privs_of_role(curr_user_id, get_pg_class_obj_owner_id(rel_oid)) || + if (!(object_ownercheck(RelationRelationId, rel_oid, curr_user_id) || has_privs_of_role(curr_user_id, get_db_ddladmin_oid(cur_db_name, false)) || has_privs_of_role(curr_user_id, get_db_owner_oid(cur_db_name, false)))) throw_error_for_identity_insert(catalog_name, logical_schema_name, rel_name); diff --git a/contrib/babelfishpg_tsql/src/pltsql.h b/contrib/babelfishpg_tsql/src/pltsql.h index 8e0a2710823..756f74840de 100644 --- a/contrib/babelfishpg_tsql/src/pltsql.h +++ b/contrib/babelfishpg_tsql/src/pltsql.h @@ -2100,7 +2100,6 @@ extern int get_insert_bulk_kilobytes_per_batch(void); extern char *get_original_query_string(void); extern AclMode string_to_privilege(const char *privname); extern const char *privilege_to_string(AclMode privilege); -extern Oid get_pg_class_obj_owner_id(Oid relation_oid); extern Oid get_owner_of_schema(const char *schema); extern void exec_database_roles_subcmds(const char *physical_schema); diff --git a/contrib/babelfishpg_tsql/src/pltsql_utils.c b/contrib/babelfishpg_tsql/src/pltsql_utils.c index 2186a508c6d..5bc8ff70039 100644 --- a/contrib/babelfishpg_tsql/src/pltsql_utils.c +++ b/contrib/babelfishpg_tsql/src/pltsql_utils.c @@ -2461,23 +2461,6 @@ privilege_to_string(AclMode privilege) return NULL; } -Oid -get_pg_class_obj_owner_id(Oid relation_oid) -{ - HeapTuple tuple; - Oid ownerId; - - tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relation_oid)); - if (!HeapTupleIsValid(tuple)) - ereport(ERROR, - (errcode(ERRCODE_UNDEFINED_TABLE), - errmsg("relation with OID %u does not exist", relation_oid))); - ownerId = ((Form_pg_class) GETSTRUCT(tuple))->relowner; - ReleaseSysCache(tuple); - - return ownerId; -} - AccessPriv * make_accesspriv_node(const char *priv_name) {