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)
{
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);
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;

View File

@ -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)
{
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,22 +402,35 @@ AppendGrantRoleStmt(StringInfo buf, GrantRoleStmt *stmt)
break;
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)
{
appendStringInfo(buf, ", ");
}
appendStringInfo(buf, " INHERIT OPTION");
opt_count++;
}
break;
case "set":
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;
}
}