pg16 update grant...inhereit,set and revoke

pg16_grant_inherit_set
francisjodi 2023-09-13 16:37:38 -04:00
parent 1bfef9d5c5
commit 09a96e739d
2 changed files with 45 additions and 32 deletions

View File

@ -878,9 +878,19 @@ GenerateGrantRoleStmtsOfRole(Oid roleid)
if (membership->admin_option) if (membership->admin_option)
{ {
DefElem *opt = makeDefElem("admin", (Node *) makeBoolean(true), -1); DefElem *opt = makeDefElem("admin", (Node *) makeBoolean(true), -1);
DefElem *inherit_opt = makeDefElem("inherit", (Node *) makeBoolean(true), -1); grantRoleStmt->opt = list_make1(opt);
DefElem *set_opt = makeDefElem("set", (Node *) makeBoolean(true), -1); }
grantRoleStmt->opt = list_make3(opt, inherit_opt, set_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 #else
grantRoleStmt->admin_opt = membership->admin_option; grantRoleStmt->admin_opt = membership->admin_option;

View File

@ -354,36 +354,26 @@ AppendGrantRoleStmt(StringInfo buf, GrantRoleStmt *stmt)
if (!stmt->is_grant) if (!stmt->is_grant)
{ {
DefElem *opt = NULL; DefElem *opt = NULL;
int opt_count = 0 ;
foreach_ptr(opt, stmt->opt) foreach_ptr(opt, stmt->opt)
{ {
switch (opt->defname) switch (opt->defname)
{ {
case "admin": case "admin":
appendStringInfo(buf, "ADMIN OPTION FOR "); appendStringInfo(buf, "ADMIN OPTION FOR ");
opt_count++;
break; break;
case "inherit": case "inherit":
if (opt_count > 0)
{
appendStringInfo(buf, ", ");
}
appendStringInfo(buf, "INHERIT OPTION FOR "); appendStringInfo(buf, "INHERIT OPTION FOR ");
opt_count++;
break; break;
case "set": case "set":
if (opt_count > 0)
{
appendStringInfo(buf, ", ");
}
appendStringInfo(buf, "SET OPTION FOR "); appendStringInfo(buf, "SET OPTION FOR ");
opt_count++;
break; break;
} }
} }
} }
}
#else #else
if (!stmt->is_grant && stmt->admin_opt) if (!stmt->is_grant && stmt->admin_opt)
{ {
@ -412,22 +402,35 @@ AppendGrantRoleStmt(StringInfo buf, GrantRoleStmt *stmt)
break; break;
case "inherit": case "inherit":
if (opt->arg && IsA(opt->arg, A_Const) && !((A_Const *) opt->arg)->val.val.ival)
{
appendStringInfo(buf, " INHERIT FALSE");
}
else
{
if (opt_count > 0) if (opt_count > 0)
{ {
appendStringInfo(buf, ", "); appendStringInfo(buf, ", ");
} }
appendStringInfo(buf, " INHERIT OPTION"); appendStringInfo(buf, " INHERIT OPTION");
opt_count++; opt_count++;
}
break; break;
case "set": case "set":
if (opt->arg && IsA(opt->arg, A_Const) && !(( *) opt->arg)->val.val.ival)
{
appendStringInfo(buf, " SET FALSE");
}
else
{
if (opt_count > 0) if (opt_count > 0)
{ {
appendStringInfo(buf, ", "); appendStringInfo(buf, ", ");
} }
appendStringInfo(buf, " SET OPTION"); appendStringInfo(buf, " SET OPTION");
opt_count++; opt_count++;
}
break; break;
} }
} }