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

Commit 6daef2b

Browse files
committed
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.
1 parent 2b0c86b commit 6daef2b

File tree

5 files changed

+59
-13
lines changed

5 files changed

+59
-13
lines changed

src/backend/catalog/aclchk.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.140 2007/08/21 01:11:13 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.141 2007/10/12 18:55:11 tgl Exp $
1212
*
1313
* NOTES
1414
* See acl.h.
@@ -1905,14 +1905,7 @@ pg_tablespace_aclmask(Oid spc_oid, Oid roleid,
19051905
Acl *acl;
19061906
Oid ownerId;
19071907

1908-
/*
1909-
* Only shared relations can be stored in global space; don't let even
1910-
* superusers override this
1911-
*/
1912-
if (spc_oid == GLOBALTABLESPACE_OID && !IsBootstrapProcessingMode())
1913-
return 0;
1914-
1915-
/* Otherwise, superusers bypass all permission checking. */
1908+
/* Superusers bypass all permission checking. */
19161909
if (superuser_arg(roleid))
19171910
return mask;
19181911

src/backend/catalog/heap.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.323 2007/09/08 20:31:14 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.324 2007/10/12 18:55:11 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -43,6 +43,7 @@
4343
#include "catalog/pg_inherits.h"
4444
#include "catalog/pg_namespace.h"
4545
#include "catalog/pg_statistic.h"
46+
#include "catalog/pg_tablespace.h"
4647
#include "catalog/pg_type.h"
4748
#include "commands/tablecmds.h"
4849
#include "commands/typecmds.h"
@@ -833,6 +834,25 @@ heap_create_with_catalog(const char *relname,
833834
"with any existing type.")));
834835
}
835836

837+
/*
838+
* Validate shared/non-shared tablespace (must check this before doing
839+
* GetNewRelFileNode, to prevent Assert therein)
840+
*/
841+
if (shared_relation)
842+
{
843+
if (reltablespace != GLOBALTABLESPACE_OID)
844+
/* elog since this is not a user-facing error */
845+
elog(ERROR,
846+
"shared relations must be placed in pg_global tablespace");
847+
}
848+
else
849+
{
850+
if (reltablespace == GLOBALTABLESPACE_OID)
851+
ereport(ERROR,
852+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
853+
errmsg("only shared relations can be placed in pg_global tablespace")));
854+
}
855+
836856
/*
837857
* Allocate an OID for the relation, unless we were told what to use.
838858
*

src/backend/catalog/index.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.285 2007/09/20 17:56:30 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.286 2007/10/12 18:55:12 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -36,6 +36,7 @@
3636
#include "catalog/pg_constraint.h"
3737
#include "catalog/pg_operator.h"
3838
#include "catalog/pg_opclass.h"
39+
#include "catalog/pg_tablespace.h"
3940
#include "catalog/pg_type.h"
4041
#include "executor/executor.h"
4142
#include "miscadmin.h"
@@ -539,6 +540,25 @@ index_create(Oid heapRelationId,
539540
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
540541
errmsg("shared indexes cannot be created after initdb")));
541542

543+
/*
544+
* Validate shared/non-shared tablespace (must check this before doing
545+
* GetNewRelFileNode, to prevent Assert therein)
546+
*/
547+
if (shared_relation)
548+
{
549+
if (tableSpaceId != GLOBALTABLESPACE_OID)
550+
/* elog since this is not a user-facing error */
551+
elog(ERROR,
552+
"shared relations must be placed in pg_global tablespace");
553+
}
554+
else
555+
{
556+
if (tableSpaceId == GLOBALTABLESPACE_OID)
557+
ereport(ERROR,
558+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
559+
errmsg("only shared relations can be placed in pg_global tablespace")));
560+
}
561+
542562
if (get_relname_relid(indexRelationName, namespaceId))
543563
ereport(ERROR,
544564
(errcode(ERRCODE_DUPLICATE_TABLE),

src/backend/commands/dbcommands.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.199 2007/09/28 22:25:49 tgl Exp $
16+
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.200 2007/10/12 18:55:12 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -302,6 +302,12 @@ createdb(const CreatedbStmt *stmt)
302302
aclcheck_error(aclresult, ACL_KIND_TABLESPACE,
303303
tablespacename);
304304

305+
/* pg_global must never be the default tablespace */
306+
if (dst_deftablespace == GLOBALTABLESPACE_OID)
307+
ereport(ERROR,
308+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
309+
errmsg("pg_global cannot be used as default tablespace")));
310+
305311
/*
306312
* If we are trying to change the default tablespace of the template,
307313
* we require that the template not have any files in the new default

src/backend/commands/tablecmds.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.233 2007/09/29 17:18:58 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.234 2007/10/12 18:55:12 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -29,6 +29,7 @@
2929
#include "catalog/pg_inherits.h"
3030
#include "catalog/pg_namespace.h"
3131
#include "catalog/pg_opclass.h"
32+
#include "catalog/pg_tablespace.h"
3233
#include "catalog/pg_trigger.h"
3334
#include "catalog/pg_type.h"
3435
#include "catalog/toasting.h"
@@ -5824,6 +5825,12 @@ ATExecSetTableSpace(Oid tableOid, Oid newTableSpace)
58245825
errmsg("cannot move system relation \"%s\"",
58255826
RelationGetRelationName(rel))));
58265827

5828+
/* Can't move a non-shared relation into pg_global */
5829+
if (newTableSpace == GLOBALTABLESPACE_OID)
5830+
ereport(ERROR,
5831+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5832+
errmsg("only shared relations can be placed in pg_global tablespace")));
5833+
58275834
/*
58285835
* Don't allow moving temp tables of other backends ... their local buffer
58295836
* manager is not going to cope.

0 commit comments

Comments
 (0)