Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d4aa491

Browse files
committed
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.
1 parent 43f0c20 commit d4aa491

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/backend/commands/extension.c

+13-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "commands/alter.h"
4141
#include "commands/comment.h"
4242
#include "commands/extension.h"
43+
#include "commands/schemacmds.h"
4344
#include "commands/trigger.h"
4445
#include "executor/executor.h"
4546
#include "funcapi.h"
@@ -1370,9 +1371,18 @@ CreateExtension(CreateExtensionStmt *stmt)
13701371

13711372
if (schemaOid == InvalidOid)
13721373
{
1373-
schemaOid = NamespaceCreate(schemaName, extowner);
1374-
/* Advance cmd counter to make the namespace visible */
1375-
CommandCounterIncrement();
1374+
CreateSchemaStmt *csstmt = makeNode(CreateSchemaStmt);
1375+
1376+
csstmt->schemaname = schemaName;
1377+
csstmt->authid = NULL; /* will be created by current user */
1378+
csstmt->schemaElts = NIL;
1379+
CreateSchemaCommand(csstmt, NULL);
1380+
1381+
/*
1382+
* CreateSchemaCommand includes CommandCounterIncrement, so new
1383+
* schema is now visible
1384+
*/
1385+
schemaOid = get_namespace_oid(schemaName, false);
13761386
}
13771387
}
13781388
else

0 commit comments

Comments
 (0)