mirror of
https://github.com/postgres/postgres.git
synced 2025-08-31 17:02:12 +03:00
Allow CURRENT/SESSION_USER to be used in certain commands
Commands such as ALTER USER, ALTER GROUP, ALTER ROLE, GRANT, and the various ALTER OBJECT / OWNER TO, as well as ad-hoc clauses related to roles such as the AUTHORIZATION clause of CREATE SCHEMA, the FOR clause of CREATE USER MAPPING, and the FOR ROLE clause of ALTER DEFAULT PRIVILEGES can now take the keywords CURRENT_USER and SESSION_USER as user specifiers in place of an explicit user name. This commit also fixes some quite ugly handling of special standards- mandated syntax in CREATE USER MAPPING, which in particular would fail to work in presence of a role named "current_user". The special role specifiers PUBLIC and NONE also have more consistent handling now. Also take the opportunity to add location tracking to user specifiers. Authors: Kyotaro Horiguchi. Heavily reworked by Álvaro Herrera. Reviewed by: Rushabh Lathia, Adam Brightwell, Marti Raudsepp.
This commit is contained in:
@@ -2504,6 +2504,18 @@ _copyXmlSerialize(const XmlSerialize *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
static RoleSpec *
|
||||
_copyRoleSpec(const RoleSpec *from)
|
||||
{
|
||||
RoleSpec *newnode = makeNode(RoleSpec);
|
||||
|
||||
COPY_SCALAR_FIELD(roletype);
|
||||
COPY_STRING_FIELD(rolename);
|
||||
COPY_LOCATION_FIELD(location);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
static Query *
|
||||
_copyQuery(const Query *from)
|
||||
{
|
||||
@@ -2650,6 +2662,7 @@ _copyAlterTableCmd(const AlterTableCmd *from)
|
||||
|
||||
COPY_SCALAR_FIELD(subtype);
|
||||
COPY_STRING_FIELD(name);
|
||||
COPY_NODE_FIELD(newowner);
|
||||
COPY_NODE_FIELD(def);
|
||||
COPY_SCALAR_FIELD(behavior);
|
||||
COPY_SCALAR_FIELD(missing_ok);
|
||||
@@ -2689,16 +2702,6 @@ _copyGrantStmt(const GrantStmt *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
static PrivGrantee *
|
||||
_copyPrivGrantee(const PrivGrantee *from)
|
||||
{
|
||||
PrivGrantee *newnode = makeNode(PrivGrantee);
|
||||
|
||||
COPY_STRING_FIELD(rolname);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
static FuncWithArgs *
|
||||
_copyFuncWithArgs(const FuncWithArgs *from)
|
||||
{
|
||||
@@ -2730,7 +2733,7 @@ _copyGrantRoleStmt(const GrantRoleStmt *from)
|
||||
COPY_NODE_FIELD(grantee_roles);
|
||||
COPY_SCALAR_FIELD(is_grant);
|
||||
COPY_SCALAR_FIELD(admin_opt);
|
||||
COPY_STRING_FIELD(grantor);
|
||||
COPY_NODE_FIELD(grantor);
|
||||
COPY_SCALAR_FIELD(behavior);
|
||||
|
||||
return newnode;
|
||||
@@ -3038,7 +3041,7 @@ _copyAlterOwnerStmt(const AlterOwnerStmt *from)
|
||||
COPY_NODE_FIELD(relation);
|
||||
COPY_NODE_FIELD(object);
|
||||
COPY_NODE_FIELD(objarg);
|
||||
COPY_STRING_FIELD(newowner);
|
||||
COPY_NODE_FIELD(newowner);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
@@ -3424,7 +3427,7 @@ _copyCreateTableSpaceStmt(const CreateTableSpaceStmt *from)
|
||||
CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);
|
||||
|
||||
COPY_STRING_FIELD(tablespacename);
|
||||
COPY_STRING_FIELD(owner);
|
||||
COPY_NODE_FIELD(owner);
|
||||
COPY_STRING_FIELD(location);
|
||||
COPY_NODE_FIELD(options);
|
||||
|
||||
@@ -3561,7 +3564,7 @@ _copyCreateUserMappingStmt(const CreateUserMappingStmt *from)
|
||||
{
|
||||
CreateUserMappingStmt *newnode = makeNode(CreateUserMappingStmt);
|
||||
|
||||
COPY_STRING_FIELD(username);
|
||||
COPY_NODE_FIELD(user);
|
||||
COPY_STRING_FIELD(servername);
|
||||
COPY_NODE_FIELD(options);
|
||||
|
||||
@@ -3573,7 +3576,7 @@ _copyAlterUserMappingStmt(const AlterUserMappingStmt *from)
|
||||
{
|
||||
AlterUserMappingStmt *newnode = makeNode(AlterUserMappingStmt);
|
||||
|
||||
COPY_STRING_FIELD(username);
|
||||
COPY_NODE_FIELD(user);
|
||||
COPY_STRING_FIELD(servername);
|
||||
COPY_NODE_FIELD(options);
|
||||
|
||||
@@ -3585,7 +3588,7 @@ _copyDropUserMappingStmt(const DropUserMappingStmt *from)
|
||||
{
|
||||
DropUserMappingStmt *newnode = makeNode(DropUserMappingStmt);
|
||||
|
||||
COPY_STRING_FIELD(username);
|
||||
COPY_NODE_FIELD(user);
|
||||
COPY_STRING_FIELD(servername);
|
||||
COPY_SCALAR_FIELD(missing_ok);
|
||||
|
||||
@@ -3698,7 +3701,7 @@ _copyAlterRoleStmt(const AlterRoleStmt *from)
|
||||
{
|
||||
AlterRoleStmt *newnode = makeNode(AlterRoleStmt);
|
||||
|
||||
COPY_STRING_FIELD(role);
|
||||
COPY_NODE_FIELD(role);
|
||||
COPY_NODE_FIELD(options);
|
||||
COPY_SCALAR_FIELD(action);
|
||||
|
||||
@@ -3710,7 +3713,7 @@ _copyAlterRoleSetStmt(const AlterRoleSetStmt *from)
|
||||
{
|
||||
AlterRoleSetStmt *newnode = makeNode(AlterRoleSetStmt);
|
||||
|
||||
COPY_STRING_FIELD(role);
|
||||
COPY_NODE_FIELD(role);
|
||||
COPY_STRING_FIELD(database);
|
||||
COPY_NODE_FIELD(setstmt);
|
||||
|
||||
@@ -3769,7 +3772,7 @@ _copyCreateSchemaStmt(const CreateSchemaStmt *from)
|
||||
CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
|
||||
|
||||
COPY_STRING_FIELD(schemaname);
|
||||
COPY_STRING_FIELD(authid);
|
||||
COPY_NODE_FIELD(authrole);
|
||||
COPY_NODE_FIELD(schemaElts);
|
||||
COPY_SCALAR_FIELD(if_not_exists);
|
||||
|
||||
@@ -3854,7 +3857,7 @@ _copyReassignOwnedStmt(const ReassignOwnedStmt *from)
|
||||
ReassignOwnedStmt *newnode = makeNode(ReassignOwnedStmt);
|
||||
|
||||
COPY_NODE_FIELD(roles);
|
||||
COPY_STRING_FIELD(newrole);
|
||||
COPY_NODE_FIELD(newrole);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
@@ -4728,9 +4731,6 @@ copyObject(const void *from)
|
||||
case T_CommonTableExpr:
|
||||
retval = _copyCommonTableExpr(from);
|
||||
break;
|
||||
case T_PrivGrantee:
|
||||
retval = _copyPrivGrantee(from);
|
||||
break;
|
||||
case T_FuncWithArgs:
|
||||
retval = _copyFuncWithArgs(from);
|
||||
break;
|
||||
@@ -4740,6 +4740,9 @@ copyObject(const void *from)
|
||||
case T_XmlSerialize:
|
||||
retval = _copyXmlSerialize(from);
|
||||
break;
|
||||
case T_RoleSpec:
|
||||
retval = _copyRoleSpec(from);
|
||||
break;
|
||||
|
||||
default:
|
||||
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
|
||||
|
@@ -973,6 +973,7 @@ _equalAlterTableCmd(const AlterTableCmd *a, const AlterTableCmd *b)
|
||||
{
|
||||
COMPARE_SCALAR_FIELD(subtype);
|
||||
COMPARE_STRING_FIELD(name);
|
||||
COMPARE_NODE_FIELD(newowner);
|
||||
COMPARE_NODE_FIELD(def);
|
||||
COMPARE_SCALAR_FIELD(behavior);
|
||||
COMPARE_SCALAR_FIELD(missing_ok);
|
||||
@@ -1008,14 +1009,6 @@ _equalGrantStmt(const GrantStmt *a, const GrantStmt *b)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalPrivGrantee(const PrivGrantee *a, const PrivGrantee *b)
|
||||
{
|
||||
COMPARE_STRING_FIELD(rolname);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalFuncWithArgs(const FuncWithArgs *a, const FuncWithArgs *b)
|
||||
{
|
||||
@@ -1041,7 +1034,7 @@ _equalGrantRoleStmt(const GrantRoleStmt *a, const GrantRoleStmt *b)
|
||||
COMPARE_NODE_FIELD(grantee_roles);
|
||||
COMPARE_SCALAR_FIELD(is_grant);
|
||||
COMPARE_SCALAR_FIELD(admin_opt);
|
||||
COMPARE_STRING_FIELD(grantor);
|
||||
COMPARE_NODE_FIELD(grantor);
|
||||
COMPARE_SCALAR_FIELD(behavior);
|
||||
|
||||
return true;
|
||||
@@ -1295,7 +1288,7 @@ _equalAlterOwnerStmt(const AlterOwnerStmt *a, const AlterOwnerStmt *b)
|
||||
COMPARE_NODE_FIELD(relation);
|
||||
COMPARE_NODE_FIELD(object);
|
||||
COMPARE_NODE_FIELD(objarg);
|
||||
COMPARE_STRING_FIELD(newowner);
|
||||
COMPARE_NODE_FIELD(newowner);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1618,7 +1611,7 @@ static bool
|
||||
_equalCreateTableSpaceStmt(const CreateTableSpaceStmt *a, const CreateTableSpaceStmt *b)
|
||||
{
|
||||
COMPARE_STRING_FIELD(tablespacename);
|
||||
COMPARE_STRING_FIELD(owner);
|
||||
COMPARE_NODE_FIELD(owner);
|
||||
COMPARE_STRING_FIELD(location);
|
||||
COMPARE_NODE_FIELD(options);
|
||||
|
||||
@@ -1735,7 +1728,7 @@ _equalAlterForeignServerStmt(const AlterForeignServerStmt *a, const AlterForeign
|
||||
static bool
|
||||
_equalCreateUserMappingStmt(const CreateUserMappingStmt *a, const CreateUserMappingStmt *b)
|
||||
{
|
||||
COMPARE_STRING_FIELD(username);
|
||||
COMPARE_NODE_FIELD(user);
|
||||
COMPARE_STRING_FIELD(servername);
|
||||
COMPARE_NODE_FIELD(options);
|
||||
|
||||
@@ -1745,7 +1738,7 @@ _equalCreateUserMappingStmt(const CreateUserMappingStmt *a, const CreateUserMapp
|
||||
static bool
|
||||
_equalAlterUserMappingStmt(const AlterUserMappingStmt *a, const AlterUserMappingStmt *b)
|
||||
{
|
||||
COMPARE_STRING_FIELD(username);
|
||||
COMPARE_NODE_FIELD(user);
|
||||
COMPARE_STRING_FIELD(servername);
|
||||
COMPARE_NODE_FIELD(options);
|
||||
|
||||
@@ -1755,7 +1748,7 @@ _equalAlterUserMappingStmt(const AlterUserMappingStmt *a, const AlterUserMapping
|
||||
static bool
|
||||
_equalDropUserMappingStmt(const DropUserMappingStmt *a, const DropUserMappingStmt *b)
|
||||
{
|
||||
COMPARE_STRING_FIELD(username);
|
||||
COMPARE_NODE_FIELD(user);
|
||||
COMPARE_STRING_FIELD(servername);
|
||||
COMPARE_SCALAR_FIELD(missing_ok);
|
||||
|
||||
@@ -1853,7 +1846,7 @@ _equalCreateRoleStmt(const CreateRoleStmt *a, const CreateRoleStmt *b)
|
||||
static bool
|
||||
_equalAlterRoleStmt(const AlterRoleStmt *a, const AlterRoleStmt *b)
|
||||
{
|
||||
COMPARE_STRING_FIELD(role);
|
||||
COMPARE_NODE_FIELD(role);
|
||||
COMPARE_NODE_FIELD(options);
|
||||
COMPARE_SCALAR_FIELD(action);
|
||||
|
||||
@@ -1863,7 +1856,7 @@ _equalAlterRoleStmt(const AlterRoleStmt *a, const AlterRoleStmt *b)
|
||||
static bool
|
||||
_equalAlterRoleSetStmt(const AlterRoleSetStmt *a, const AlterRoleSetStmt *b)
|
||||
{
|
||||
COMPARE_STRING_FIELD(role);
|
||||
COMPARE_NODE_FIELD(role);
|
||||
COMPARE_STRING_FIELD(database);
|
||||
COMPARE_NODE_FIELD(setstmt);
|
||||
|
||||
@@ -1912,7 +1905,7 @@ static bool
|
||||
_equalCreateSchemaStmt(const CreateSchemaStmt *a, const CreateSchemaStmt *b)
|
||||
{
|
||||
COMPARE_STRING_FIELD(schemaname);
|
||||
COMPARE_STRING_FIELD(authid);
|
||||
COMPARE_NODE_FIELD(authrole);
|
||||
COMPARE_NODE_FIELD(schemaElts);
|
||||
COMPARE_SCALAR_FIELD(if_not_exists);
|
||||
|
||||
@@ -1983,7 +1976,7 @@ static bool
|
||||
_equalReassignOwnedStmt(const ReassignOwnedStmt *a, const ReassignOwnedStmt *b)
|
||||
{
|
||||
COMPARE_NODE_FIELD(roles);
|
||||
COMPARE_STRING_FIELD(newrole);
|
||||
COMPARE_NODE_FIELD(newrole);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -2455,6 +2448,16 @@ _equalXmlSerialize(const XmlSerialize *a, const XmlSerialize *b)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalRoleSpec(const RoleSpec *a, const RoleSpec *b)
|
||||
{
|
||||
COMPARE_SCALAR_FIELD(roletype);
|
||||
COMPARE_STRING_FIELD(rolename);
|
||||
COMPARE_LOCATION_FIELD(location);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Stuff from pg_list.h
|
||||
*/
|
||||
@@ -3153,9 +3156,6 @@ equal(const void *a, const void *b)
|
||||
case T_CommonTableExpr:
|
||||
retval = _equalCommonTableExpr(a, b);
|
||||
break;
|
||||
case T_PrivGrantee:
|
||||
retval = _equalPrivGrantee(a, b);
|
||||
break;
|
||||
case T_FuncWithArgs:
|
||||
retval = _equalFuncWithArgs(a, b);
|
||||
break;
|
||||
@@ -3165,6 +3165,9 @@ equal(const void *a, const void *b)
|
||||
case T_XmlSerialize:
|
||||
retval = _equalXmlSerialize(a, b);
|
||||
break;
|
||||
case T_RoleSpec:
|
||||
retval = _equalRoleSpec(a, b);
|
||||
break;
|
||||
|
||||
default:
|
||||
elog(ERROR, "unrecognized node type: %d",
|
||||
|
Reference in New Issue
Block a user