Remove hack in pg_tablespace_aclmask() that disallowed permissions
authorTom Lane
Fri, 12 Oct 2007 18:55:12 +0000 (18:55 +0000)
committerTom Lane
Fri, 12 Oct 2007 18:55:12 +0000 (18:55 +0000)
on pg_global even to superusers, and replace it with checks in various
other places to complain about invalid uses of pg_global.  This ends
up being a bit more code but it allows a more specific error message
to be given, and it un-breaks pg_tablespace_size() on pg_global.
Per discussion.

src/backend/catalog/aclchk.c
src/backend/catalog/heap.c
src/backend/catalog/index.c
src/backend/commands/dbcommands.c
src/backend/commands/tablecmds.c

index 96d238c7242972077daf90e78be417a42575a726..622901a69d5265e9d819560dfb7529e3ea5bd542 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.140 2007/08/21 01:11:13 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.141 2007/10/12 18:55:11 tgl Exp $
  *
  * NOTES
  *   See acl.h.
@@ -1905,14 +1905,7 @@ pg_tablespace_aclmask(Oid spc_oid, Oid roleid,
    Acl        *acl;
    Oid         ownerId;
 
-   /*
-    * Only shared relations can be stored in global space; don't let even
-    * superusers override this
-    */
-   if (spc_oid == GLOBALTABLESPACE_OID && !IsBootstrapProcessingMode())
-       return 0;
-
-   /* Otherwise, superusers bypass all permission checking. */
+   /* Superusers bypass all permission checking. */
    if (superuser_arg(roleid))
        return mask;
 
index cbf05acfb8353b7666e2b0bf67c906106381ea6c..ea985a635ddcca93f00231fe3e4b47e50c253380 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.323 2007/09/08 20:31:14 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.324 2007/10/12 18:55:11 tgl Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -43,6 +43,7 @@
 #include "catalog/pg_inherits.h"
 #include "catalog/pg_namespace.h"
 #include "catalog/pg_statistic.h"
+#include "catalog/pg_tablespace.h"
 #include "catalog/pg_type.h"
 #include "commands/tablecmds.h"
 #include "commands/typecmds.h"
@@ -833,6 +834,25 @@ heap_create_with_catalog(const char *relname,
                             "with any existing type.")));
    }
 
+   /*
+    * Validate shared/non-shared tablespace (must check this before doing
+    * GetNewRelFileNode, to prevent Assert therein)
+    */
+   if (shared_relation)
+   {
+       if (reltablespace != GLOBALTABLESPACE_OID)
+           /* elog since this is not a user-facing error */
+           elog(ERROR,
+                "shared relations must be placed in pg_global tablespace");
+   }
+   else
+   {
+       if (reltablespace == GLOBALTABLESPACE_OID)
+           ereport(ERROR,
+                   (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                    errmsg("only shared relations can be placed in pg_global tablespace")));
+   }
+
    /*
     * Allocate an OID for the relation, unless we were told what to use.
     *
index 8137377e7a57eba5b4e6117e9f2798ce53a00606..0e76bc9800d066806954ea08bf228bc3468a77c0 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.285 2007/09/20 17:56:30 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.286 2007/10/12 18:55:12 tgl Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -36,6 +36,7 @@
 #include "catalog/pg_constraint.h"
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opclass.h"
+#include "catalog/pg_tablespace.h"
 #include "catalog/pg_type.h"
 #include "executor/executor.h"
 #include "miscadmin.h"
@@ -539,6 +540,25 @@ index_create(Oid heapRelationId,
                (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
                 errmsg("shared indexes cannot be created after initdb")));
 
+   /*
+    * Validate shared/non-shared tablespace (must check this before doing
+    * GetNewRelFileNode, to prevent Assert therein)
+    */
+   if (shared_relation)
+   {
+       if (tableSpaceId != GLOBALTABLESPACE_OID)
+           /* elog since this is not a user-facing error */
+           elog(ERROR,
+                "shared relations must be placed in pg_global tablespace");
+   }
+   else
+   {
+       if (tableSpaceId == GLOBALTABLESPACE_OID)
+           ereport(ERROR,
+                   (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                    errmsg("only shared relations can be placed in pg_global tablespace")));
+   }
+
    if (get_relname_relid(indexRelationName, namespaceId))
        ereport(ERROR,
                (errcode(ERRCODE_DUPLICATE_TABLE),
index 094f51b5cc99c37f1b2201008b3b3c85e995014b..434e9838947a573f4151c96fb0c25a362c2e5868 100644 (file)
@@ -13,7 +13,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.199 2007/09/28 22:25:49 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.200 2007/10/12 18:55:12 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -302,6 +302,12 @@ createdb(const CreatedbStmt *stmt)
            aclcheck_error(aclresult, ACL_KIND_TABLESPACE,
                           tablespacename);
 
+       /* pg_global must never be the default tablespace */
+       if (dst_deftablespace == GLOBALTABLESPACE_OID)
+           ereport(ERROR,
+                   (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                    errmsg("pg_global cannot be used as default tablespace")));
+
        /*
         * If we are trying to change the default tablespace of the template,
         * we require that the template not have any files in the new default
index ea8d7f608988eede467729a4f7c26c3c3a48615e..0af90cb4ac64f88a2b3c7e4d0fc739a833d1028d 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.233 2007/09/29 17:18:58 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.234 2007/10/12 18:55:12 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -29,6 +29,7 @@
 #include "catalog/pg_inherits.h"
 #include "catalog/pg_namespace.h"
 #include "catalog/pg_opclass.h"
+#include "catalog/pg_tablespace.h"
 #include "catalog/pg_trigger.h"
 #include "catalog/pg_type.h"
 #include "catalog/toasting.h"
@@ -5824,6 +5825,12 @@ ATExecSetTableSpace(Oid tableOid, Oid newTableSpace)
                 errmsg("cannot move system relation \"%s\"",
                        RelationGetRelationName(rel))));
 
+   /* Can't move a non-shared relation into pg_global */
+   if (newTableSpace == GLOBALTABLESPACE_OID)
+       ereport(ERROR,
+               (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                errmsg("only shared relations can be placed in pg_global tablespace")));
+
    /*
     * Don't allow moving temp tables of other backends ... their local buffer
     * manager is not going to cope.