Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7f7fdd2

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 48f545a commit 7f7fdd2

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/backend/commands/extension.c

Lines changed: 13 additions & 3 deletions
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"
@@ -1369,9 +1370,18 @@ CreateExtension(CreateExtensionStmt *stmt)
13691370

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

0 commit comments

Comments
 (0)