Make CREATE EXTENSION check schema creation permissions.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 24 Aug 2011 01:49:07 +0000 (21:49 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 24 Aug 2011 01:49:16 +0000 (21:49 -0400)
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.

src/backend/commands/extension.c

index f6a03e16688ff7ccf4328ed79c9eb65ee26bfee7..278bbcfc988e1a11cc904c72d9649f81191be3c4 100644 (file)
@@ -40,6 +40,7 @@
 #include "commands/alter.h"
 #include "commands/comment.h"
 #include "commands/extension.h"
+#include "commands/schemacmds.h"
 #include "commands/trigger.h"
 #include "executor/executor.h"
 #include "funcapi.h"
@@ -1369,9 +1370,18 @@ CreateExtension(CreateExtensionStmt *stmt)
 
                if (schemaOid == InvalidOid)
                {
-                       schemaOid = NamespaceCreate(schemaName, extowner);
-                       /* Advance cmd counter to make the namespace visible */
-                       CommandCounterIncrement();
+                       CreateSchemaStmt *csstmt = makeNode(CreateSchemaStmt);
+
+                       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