From 09a96e739da8baf329440847fd3544cd2a098d31 Mon Sep 17 00:00:00 2001 From: francisjodi Date: Wed, 13 Sep 2023 16:37:38 -0400 Subject: [PATCH] pg16 update grant...inhereit,set and revoke --- src/backend/distributed/commands/role.c | 18 ++++-- .../distributed/deparser/deparse_role_stmts.c | 59 ++++++++++--------- 2 files changed, 45 insertions(+), 32 deletions(-) diff --git a/src/backend/distributed/commands/role.c b/src/backend/distributed/commands/role.c index 7fdbfc4a6..0ea4569c6 100644 --- a/src/backend/distributed/commands/role.c +++ b/src/backend/distributed/commands/role.c @@ -877,10 +877,20 @@ GenerateGrantRoleStmtsOfRole(Oid roleid) #if PG_VERSION_NUM >= PG_VERSION_16 if (membership->admin_option) { - DefElem *opt = makeDefElem("admin", (Node *) makeBoolean(true), -1); - DefElem *inherit_opt = makeDefElem("inherit", (Node *) makeBoolean(true), -1); - DefElem *set_opt = makeDefElem("set", (Node *) makeBoolean(true), -1); - grantRoleStmt->opt = list_make3(opt, inherit_opt, set_opt); + DefElem *opt = makeDefElem("admin", (Node *) makeBoolean(true), -1); + grantRoleStmt->opt = list_make1(opt); + } + + if (membership->inherit_option) + { + DefElem *opt = makeDefElem("inherit", (Node *) makeBoolean(true), -1); + grantRoleStmt->opt = lappend(grantRoleStmt->opt, opt); + } + + if (membership->set_option) + { + DefElem *opt = makeDefElem("set", (Node *) makeBoolean(true), -1); + grantRoleStmt->opt = lappend(grantRoleStmt->opt, opt); } #else grantRoleStmt->admin_opt = membership->admin_option; diff --git a/src/backend/distributed/deparser/deparse_role_stmts.c b/src/backend/distributed/deparser/deparse_role_stmts.c index 9f6e63308..b62576c0c 100644 --- a/src/backend/distributed/deparser/deparse_role_stmts.c +++ b/src/backend/distributed/deparser/deparse_role_stmts.c @@ -354,36 +354,26 @@ AppendGrantRoleStmt(StringInfo buf, GrantRoleStmt *stmt) if (!stmt->is_grant) { DefElem *opt = NULL; - int opt_count = 0 ; foreach_ptr(opt, stmt->opt) { - switch (opt->defname) + + switch (opt->defname) { case "admin": appendStringInfo(buf, "ADMIN OPTION FOR "); - opt_count++; break; case "inherit": - if (opt_count > 0) - { - appendStringInfo(buf, ", "); - } appendStringInfo(buf, "INHERIT OPTION FOR "); - opt_count++; break; case "set": - if (opt_count > 0) - { - appendStringInfo(buf, ", "); - } appendStringInfo(buf, "SET OPTION FOR "); - opt_count++; break; } } } +} #else if (!stmt->is_grant && stmt->admin_opt) { @@ -412,26 +402,39 @@ AppendGrantRoleStmt(StringInfo buf, GrantRoleStmt *stmt) break; case "inherit": - if (opt_count > 0) + if (opt->arg && IsA(opt->arg, A_Const) && !((A_Const *) opt->arg)->val.val.ival) { - appendStringInfo(buf, ", "); - } - appendStringInfo(buf, "INHERIT OPTION "); - opt_count++; - break; - + appendStringInfo(buf, " INHERIT FALSE"); + } + else + { + if (opt_count > 0) + { + appendStringInfo(buf, ", "); + } + appendStringInfo(buf, " INHERIT OPTION"); + opt_count++; + } + break; case "set": - if (opt_count > 0) - { - appendStringInfo(buf, ", "); - } - appendStringInfo(buf, "SET OPTION "); - opt_count++; - break; + if (opt->arg && IsA(opt->arg, A_Const) && !(( *) opt->arg)->val.val.ival) + { + appendStringInfo(buf, " SET FALSE"); + } + else + { + if (opt_count > 0) + { + appendStringInfo(buf, ", "); + } + appendStringInfo(buf, " SET OPTION"); + opt_count++; + } + break; } - } } + } #else if (stmt->admin_opt) {