mirror of
https://github.com/postgres/postgres.git
synced 2025-06-27 23:21:58 +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:
@ -21,6 +21,7 @@
|
||||
#include "catalog/dependency.h"
|
||||
#include "catalog/indexing.h"
|
||||
#include "catalog/namespace.h"
|
||||
#include "catalog/pg_authid.h"
|
||||
#include "catalog/objectaccess.h"
|
||||
#include "catalog/pg_namespace.h"
|
||||
#include "commands/dbcommands.h"
|
||||
@ -42,8 +43,7 @@ static void AlterSchemaOwner_internal(HeapTuple tup, Relation rel, Oid newOwnerI
|
||||
Oid
|
||||
CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString)
|
||||
{
|
||||
const char *schemaName = stmt->schemaname;
|
||||
const char *authId = stmt->authid;
|
||||
const char *schemaName = stmt->schemaname;
|
||||
Oid namespaceId;
|
||||
OverrideSearchPath *overridePath;
|
||||
List *parsetree_list;
|
||||
@ -58,11 +58,24 @@ CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString)
|
||||
/*
|
||||
* Who is supposed to own the new schema?
|
||||
*/
|
||||
if (authId)
|
||||
owner_uid = get_role_oid(authId, false);
|
||||
if (stmt->authrole)
|
||||
owner_uid = get_rolespec_oid(stmt->authrole, false);
|
||||
else
|
||||
owner_uid = saved_uid;
|
||||
|
||||
/* fill schema name with the user name if not specified */
|
||||
if (!schemaName)
|
||||
{
|
||||
HeapTuple tuple;
|
||||
|
||||
tuple = SearchSysCache1(AUTHOID, ObjectIdGetDatum(owner_uid));
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "cache lookup failed for role %u", owner_uid);
|
||||
schemaName =
|
||||
pstrdup(NameStr(((Form_pg_authid) GETSTRUCT(tuple))->rolname));
|
||||
ReleaseSysCache(tuple);
|
||||
}
|
||||
|
||||
/*
|
||||
* To create a schema, must have schema-create privilege on the current
|
||||
* database and must be able to become the target role (this does not
|
||||
|
Reference in New Issue
Block a user