Open
Description
Problem
Right now the different modules logic are tangled per statement and the standard hook (run_process_utility_hook
) is scattered everywhere. This makes it hard to:
-
maintain the code and to disable modules according to the pg version (pg 16: granting BYPASSRLS doesn't require SUPERUSER anymore #78, PostgreSQL 16 fixes the CREATEROLE problem #50 (comment)).
-
properly review PRs, and we already had a consequence on fix: not allowing to alter schema on non-extension #100
- essentially, we have many case statements that have a
return
instead of abreak
. It's easy to do areturn
in some cases and miss hitting therun_process_utility_hook
.
- essentially, we have many case statements that have a
Solution
Refactor the codebase so each module has a single entrypoint and the standard hook is always invoked in one single place. Basically:
static void
supautils_hook(PROCESS_UTILITY_PARAMS)
{
Node *utility_stmt = pstmt->utilityStmt;
ret1 = privileged_role_setup(utility_stmt)
ret2 = reserved_roles_setup(utility_stmt)
ret3 = privileged_extensions_setup(utility_stmt)
ret4 = constrained_extensions_setup(utility_stmt)
run_process_utility_hook(prev_hook);
cleanup(ret1, ret2, ret3, ret4); // or have multiple cleanups depending on the module