Remove hack in pg_tablespace_aclmask() that disallowed permissions

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.
This commit is contained in:
Tom Lane 2007-10-12 18:55:12 +00:00
parent 2b0c86b665
commit 6daef2bca4
5 changed files with 59 additions and 13 deletions

View 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;

View 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.
*

View 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),

View 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

View 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.