Skip to content

Commit

Permalink
Merge pull request #25 from Aiven-Open/packi-pg16-compat
Browse files Browse the repository at this point in the history
Ensure compatibility with PG16
  • Loading branch information
staaldraad authored Nov 17, 2023
2 parents e3d2233 + 390d234 commit b3449ea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
max-parallel: 3
matrix:
pg-version: [11, 12, 13, 14, 15]
pg-version: [11, 12, 13, 14, 15, 16]
steps:
- id: install
run: |
Expand Down
26 changes: 24 additions & 2 deletions src/aiven_gatekeeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "nodes/value.h"
#include "fmgr.h"
#include "miscadmin.h"
#include "parser/parse_relation.h"
#include "tcop/utility.h"
#include "utils/acl.h"
#include "utils/builtins.h"
Expand Down Expand Up @@ -627,20 +628,31 @@ pg_proc_guard_checks(QueryDesc *queryDesc, int eflags)
RangeTblEntry *rt;
Bitmapset *colset;
int index;

#if PG16_GTE
List *permInfos;
RTEPermissionInfo *permInfo;
#endif
/* only check function if security agent is enabled */
if (pg_security_agent_enabled && !BUG_01)
{
switch (queryDesc->operation)
{
case CMD_SELECT:
#if PG16_GTE
permInfos = queryDesc->plannedstmt->permInfos;
#endif
foreach (resultRelations, queryDesc->plannedstmt->rtable)
{
rt = lfirst(resultRelations);
switch (rt->relid)
{
case 1260: // pg_authid
#if PG16_GTE
permInfo = getRTEPermissionInfo(permInfos, rt);
colset = permInfo->selectedCols;
#else
colset = rt->selectedCols;
#endif
index = -1;
while ((index = bms_next_member(colset, index)) >= 0)
{
Expand Down Expand Up @@ -673,6 +685,9 @@ pg_proc_guard_checks(QueryDesc *queryDesc, int eflags)
case CMD_INSERT:
case CMD_UPDATE:
case CMD_DELETE:
#if PG16_GTE
permInfos = queryDesc->plannedstmt->permInfos;
#endif
foreach (resultRelations, queryDesc->plannedstmt->rtable)
{
rt = lfirst(resultRelations);
Expand All @@ -692,11 +707,18 @@ pg_proc_guard_checks(QueryDesc *queryDesc, int eflags)
* actually alter pg_proc directly during install/upgrade.
* block changes to proowner, prolang, prosecdef, proacl, prosrc
*/
#if PG16_GTE
permInfo = getRTEPermissionInfo(permInfos, rt);
if (queryDesc->operation == CMD_INSERT)
colset = permInfo->insertedCols;
else
colset = permInfo->updatedCols;
#else
if (queryDesc->operation == CMD_INSERT)
colset = rt->insertedCols;
else
colset = rt->updatedCols;

#endif
index = -1;
while ((index = bms_next_member(colset, index)) >= 0)
{
Expand Down
1 change: 1 addition & 0 deletions src/aiven_gatekeeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define PG11_GTE (PG_VERSION_NUM >= 110000)
#define PG13_GTE (PG_VERSION_NUM >= 130000)
#define PG14_GTE (PG_VERSION_NUM >= 140000)
#define PG16_GTE (PG_VERSION_NUM >= 160000)

/* The process_utility_hook function changed in PG13 and again in PG14
* versions from introduction (PG9) through PG12 have the same 7 argument structure
Expand Down

0 comments on commit b3449ea

Please sign in to comment.