Skip to content
Snippets Groups Projects
Commit d4aa4914 authored by Tom Lane's avatar Tom Lane
Browse files

Make CREATE EXTENSION check schema creation permissions.

When creating a new schema for a non-relocatable extension, we neglected
to check whether the calling user has permission to create schemas.
That didn't matter in the original coding, since we had already checked
superuserness, but in the new dispensation where users need not be
superusers, we should check it.  Use CreateSchemaCommand() rather than
calling NamespaceCreate() directly, so that we also enforce the rules
about reserved schema names.

Per complaint from KaiGai Kohei, though this isn't the same as his patch.
parent 43f0c208
No related branches found
No related tags found
No related merge requests found
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "commands/alter.h" #include "commands/alter.h"
#include "commands/comment.h" #include "commands/comment.h"
#include "commands/extension.h" #include "commands/extension.h"
#include "commands/schemacmds.h"
#include "commands/trigger.h" #include "commands/trigger.h"
#include "executor/executor.h" #include "executor/executor.h"
#include "funcapi.h" #include "funcapi.h"
...@@ -1370,9 +1371,18 @@ CreateExtension(CreateExtensionStmt *stmt) ...@@ -1370,9 +1371,18 @@ CreateExtension(CreateExtensionStmt *stmt)
if (schemaOid == InvalidOid) if (schemaOid == InvalidOid)
{ {
schemaOid = NamespaceCreate(schemaName, extowner); CreateSchemaStmt *csstmt = makeNode(CreateSchemaStmt);
/* Advance cmd counter to make the namespace visible */
CommandCounterIncrement(); csstmt->schemaname = schemaName;
csstmt->authid = NULL; /* will be created by current user */
csstmt->schemaElts = NIL;
CreateSchemaCommand(csstmt, NULL);
/*
* CreateSchemaCommand includes CommandCounterIncrement, so new
* schema is now visible
*/
schemaOid = get_namespace_oid(schemaName, false);
} }
} }
else else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment