From e71d6429654cca464f45bf07d2d2716f56a5a80f Mon Sep 17 00:00:00 2001 From: naisila Date: Mon, 7 Aug 2023 17:51:37 +0300 Subject: [PATCH] Fix with admin option in grants grantstmt->admin_opt no longer exists in PG16 instead, grantstmt has a list of options, one of them is admin option. Relevant PG commit: https://github.com/postgres/postgres/commit/e3ce2de09d814f8770b2e3b3c152b7671bcdb83f e3ce2de09d814f8770b2e3b3c152b7671bcdb83f --- src/backend/distributed/commands/role.c | 15 ++++++++-- .../distributed/deparser/deparse_role_stmts.c | 28 +++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/backend/distributed/commands/role.c b/src/backend/distributed/commands/role.c index 4e274d270..99ce4fb9f 100644 --- a/src/backend/distributed/commands/role.c +++ b/src/backend/distributed/commands/role.c @@ -819,12 +819,15 @@ GenerateGrantRoleStmtsFromOptions(RoleSpec *roleSpec, List *options) grantRoleStmt->grantee_roles = list_make1(roleSpec); } -#if PG_VERSION_NUM < PG_VERSION_16 if (strcmp(option->defname, "adminmembers") == 0) { +#if PG_VERSION_NUM >= PG_VERSION_16 + DefElem *opt = makeDefElem("admin", (Node *) makeBoolean(true), -1); + grantRoleStmt->opt = list_make1(opt); +#else grantRoleStmt->admin_opt = true; - } #endif + } stmts = lappend(stmts, grantRoleStmt); } @@ -871,7 +874,13 @@ GenerateGrantRoleStmtsOfRole(Oid roleid) grantRoleStmt->grantor = NULL; -#if PG_VERSION_NUM < PG_VERSION_16 +#if PG_VERSION_NUM >= PG_VERSION_16 + if (membership->admin_option) + { + DefElem *opt = makeDefElem("admin", (Node *) makeBoolean(true), -1); + grantRoleStmt->opt = list_make1(opt); + } +#else grantRoleStmt->admin_opt = membership->admin_option; #endif diff --git a/src/backend/distributed/deparser/deparse_role_stmts.c b/src/backend/distributed/deparser/deparse_role_stmts.c index 620e7606d..4ad4f4c7f 100644 --- a/src/backend/distributed/deparser/deparse_role_stmts.c +++ b/src/backend/distributed/deparser/deparse_role_stmts.c @@ -17,6 +17,7 @@ #include "distributed/citus_ruleutils.h" #include "distributed/deparser.h" +#include "distributed/listutils.h" #include "lib/stringinfo.h" #include "nodes/parsenodes.h" #include "utils/builtins.h" @@ -349,7 +350,20 @@ AppendGrantRoleStmt(StringInfo buf, GrantRoleStmt *stmt) { appendStringInfo(buf, "%s ", stmt->is_grant ? "GRANT" : "REVOKE"); -#if PG_VERSION_NUM < PG_VERSION_16 +#if PG_VERSION_NUM >= PG_VERSION_16 + if (!stmt->is_grant) + { + DefElem *opt = NULL; + foreach_ptr(opt, stmt->opt) + { + if (strcmp(opt->defname, "admin") == 0) + { + appendStringInfo(buf, "ADMIN OPTION FOR "); + break; + } + } + } +#else if (!stmt->is_grant && stmt->admin_opt) { appendStringInfo(buf, "ADMIN OPTION FOR "); @@ -364,7 +378,17 @@ AppendGrantRoleStmt(StringInfo buf, GrantRoleStmt *stmt) if (stmt->is_grant) { -#if PG_VERSION_NUM < PG_VERSION_16 +#if PG_VERSION_NUM >= PG_VERSION_16 + DefElem *opt = NULL; + foreach_ptr(opt, stmt->opt) + { + if (strcmp(opt->defname, "admin") == 0) + { + appendStringInfo(buf, " WITH ADMIN OPTION"); + break; + } + } +#else if (stmt->admin_opt) { appendStringInfo(buf, " WITH ADMIN OPTION");