8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.121 2008/07/30 19:35:13 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.122 2008/07/31 16:27:16 tgl Exp $
12
12
*
13
13
* DESCRIPTION
14
14
* The "DefineFoo" routines take the parse tree and pick out the
@@ -92,14 +92,13 @@ static char *domainAddConstraint(Oid domainOid, Oid domainNamespace,
92
92
93
93
/*
94
94
* DefineType
95
- * Registers a new type.
95
+ * Registers a new base type.
96
96
*/
97
97
void
98
98
DefineType (List * names , List * parameters )
99
99
{
100
100
char * typeName ;
101
101
Oid typeNamespace ;
102
- AclResult aclresult ;
103
102
int16 internalLength = -1 ; /* default: variable-length */
104
103
Oid elemType = InvalidOid ;
105
104
List * inputName = NIL ;
@@ -130,14 +129,33 @@ DefineType(List *names, List *parameters)
130
129
Oid resulttype ;
131
130
Relation pg_type ;
132
131
132
+ /*
133
+ * As of Postgres 8.4, we require superuser privilege to create a base
134
+ * type. This is simple paranoia: there are too many ways to mess up the
135
+ * system with an incorrect type definition (for instance, representation
136
+ * parameters that don't match what the C code expects). In practice
137
+ * it takes superuser privilege to create the I/O functions, and so the
138
+ * former requirement that you own the I/O functions pretty much forced
139
+ * superuserness anyway. We're just making doubly sure here.
140
+ *
141
+ * XXX re-enable NOT_USED code sections below if you remove this test.
142
+ */
143
+ if (!superuser ())
144
+ ereport (ERROR ,
145
+ (errcode (ERRCODE_INSUFFICIENT_PRIVILEGE ),
146
+ errmsg ("must be superuser to create a base type" )));
147
+
133
148
/* Convert list of names to a name and namespace */
134
149
typeNamespace = QualifiedNameGetCreationNamespace (names , & typeName );
135
150
151
+ #ifdef NOT_USED
152
+ /* XXX this is unnecessary given the superuser check above */
136
153
/* Check we have creation rights in target namespace */
137
154
aclresult = pg_namespace_aclcheck (typeNamespace , GetUserId (), ACL_CREATE );
138
155
if (aclresult != ACLCHECK_OK )
139
156
aclcheck_error (aclresult , ACL_KIND_NAMESPACE ,
140
157
get_namespace_name (typeNamespace ));
158
+ #endif
141
159
142
160
/*
143
161
* Look to see if type already exists (presumably as a shell; if not,
@@ -398,6 +416,8 @@ DefineType(List *names, List *parameters)
398
416
* don't have a way to make the type go away if the grant option is
399
417
* revoked, so ownership seems better.
400
418
*/
419
+ #ifdef NOT_USED
420
+ /* XXX this is unnecessary given the superuser check above */
401
421
if (inputOid && !pg_proc_ownercheck (inputOid , GetUserId ()))
402
422
aclcheck_error (ACLCHECK_NOT_OWNER , ACL_KIND_PROC ,
403
423
NameListToString (inputName ));
@@ -419,6 +439,7 @@ DefineType(List *names, List *parameters)
419
439
if (analyzeOid && !pg_proc_ownercheck (analyzeOid , GetUserId ()))
420
440
aclcheck_error (ACLCHECK_NOT_OWNER , ACL_KIND_PROC ,
421
441
NameListToString (analyzeName ));
442
+ #endif
422
443
423
444
/* Preassign array type OID so we can insert it in pg_type.typarray */
424
445
pg_type = heap_open (TypeRelationId , AccessShareLock );
0 commit comments