forked from supabase/supautils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: execute event triggers under superuser
Closes supabase#110. superuser evtrigs now work as usual with the exception of `CREATE EXTENSION`. Which will now fire superuser evtrigs, but not regular user evtrigs. This is because how `CREATE EXTENSION` works under supautils (switchs to superuser before executing CREATE EXTENSION).
- Loading branch information
1 parent
f6228aa
commit 2fb6f0f
Showing
9 changed files
with
404 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "pg_prelude.h" | ||
#include "event_triggers.h" | ||
|
||
PG_FUNCTION_INFO_V1(noop); | ||
Datum noop(__attribute__ ((unused)) PG_FUNCTION_ARGS) { PG_RETURN_VOID();} | ||
|
||
void | ||
force_noop(FmgrInfo *finfo) | ||
{ | ||
finfo->fn_addr = (PGFunction) noop; | ||
finfo->fn_oid = InvalidOid; /* not a known function OID anymore */ | ||
finfo->fn_nargs = 0; /* no arguments for noop */ | ||
finfo->fn_strict = false; | ||
finfo->fn_retset = false; | ||
finfo->fn_stats = 0; /* no stats collection */ | ||
finfo->fn_extra = NULL; /* clear out old context data */ | ||
finfo->fn_mcxt = CurrentMemoryContext; | ||
finfo->fn_expr = NULL; /* no parse tree */ | ||
} | ||
|
||
Oid get_function_owner(func_owner_search search){ | ||
// Lookup function name OID. Note that for event trigger functions, there's no arguments. | ||
Oid func_oid = InvalidOid; | ||
|
||
switch(search.as){ | ||
case FO_SEARCH_NAME: | ||
func_oid = LookupFuncName(search.val.funcname, 0, NULL, false); | ||
break; | ||
case FO_SEARCH_FINFO: | ||
func_oid = search.val.finfo->fn_oid; | ||
break; | ||
} | ||
|
||
HeapTuple proc_tup = SearchSysCache1(PROCOID, ObjectIdGetDatum(func_oid)); | ||
if (!HeapTupleIsValid(proc_tup)) | ||
ereport(ERROR, | ||
(errmsg("cache lookup failed for function %u", func_oid))); | ||
|
||
Form_pg_proc procForm = (Form_pg_proc) GETSTRUCT(proc_tup); | ||
Oid func_owner = procForm->proowner; | ||
|
||
ReleaseSysCache(proc_tup); | ||
|
||
return func_owner; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef EVENT_TRIGGERS_H | ||
#define EVENT_TRIGGERS_H | ||
|
||
typedef enum { | ||
FO_SEARCH_NAME, | ||
FO_SEARCH_FINFO | ||
} func_owner_search_type; | ||
|
||
typedef struct { | ||
func_owner_search_type as; | ||
union { | ||
List *funcname; | ||
FmgrInfo *finfo; | ||
} val; | ||
} func_owner_search; | ||
|
||
extern Oid get_function_owner(func_owner_search search); | ||
|
||
extern void force_noop(FmgrInfo *finfo); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.