aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2002-08-11 17:44:12 +0000
committerPeter Eisentraut <peter_e@gmx.net>2002-08-11 17:44:12 +0000
commit9bccdf17f725550e463fbc9fddf0acf2ed3a8e66 (patch)
tree9d63659d933d5fe784af86107ee2272cb2406c5b
parent014a86ac479272868c677b979b6049dedbf3bb33 (diff)
downloadpostgresql-9bccdf17f725550e463fbc9fddf0acf2ed3a8e66.tar.gz
postgresql-9bccdf17f725550e463fbc9fddf0acf2ed3a8e66.zip
Create/drop cast now requires ownership of at least one of the types.
-rw-r--r--doc/src/sgml/ref/create_cast.sgml12
-rw-r--r--doc/src/sgml/ref/drop_cast.sgml14
-rw-r--r--src/backend/commands/functioncmds.c40
3 files changed, 19 insertions, 47 deletions
diff --git a/doc/src/sgml/ref/create_cast.sgml b/doc/src/sgml/ref/create_cast.sgml
index 81259949f1e..7fd5ba0d470 100644
--- a/doc/src/sgml/ref/create_cast.sgml
+++ b/doc/src/sgml/ref/create_cast.sgml
@@ -1,4 +1,4 @@
-<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_cast.sgml,v 1.1 2002/07/18 23:11:27 petere Exp $ -->
+<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_cast.sgml,v 1.2 2002/08/11 17:44:12 petere Exp $ -->
<refentry id="SQL-CREATECAST">
<refmeta>
@@ -81,9 +81,8 @@ INSERT INTO foo(f1) VALUES(42);
</para>
<para>
- To be able to create a cast, you must own the underlying function.
- To be able to create a binary compatible cast, you must own both
- the source and the target data type.
+ To be able to create a cast, you must own the source or the target
+ data type.
</para>
<variablelist>
@@ -155,11 +154,6 @@ INSERT INTO foo(f1) VALUES(42);
</para>
<para>
- The privileges required to create a cast may be changed in a future
- release.
- </para>
-
- <para>
Remember that if you want to be able to convert types both ways you
need to declare casts both ways explicitly.
</para>
diff --git a/doc/src/sgml/ref/drop_cast.sgml b/doc/src/sgml/ref/drop_cast.sgml
index 37152114bca..2f2cec02e14 100644
--- a/doc/src/sgml/ref/drop_cast.sgml
+++ b/doc/src/sgml/ref/drop_cast.sgml
@@ -1,4 +1,4 @@
-<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_cast.sgml,v 1.1 2002/07/18 23:11:27 petere Exp $ -->
+<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_cast.sgml,v 1.2 2002/08/11 17:44:12 petere Exp $ -->
<refentry id="SQL-DROPCAST">
<refmeta>
@@ -26,10 +26,9 @@ DROP CAST (<replaceable>sourcetype</replaceable> AS <replaceable>targettype</rep
</para>
<para>
- To be able to drop a cast, you must own the underlying function.
- To be able to drop a binary compatible cast, you must own both the
- source and the target data type. These are the same privileges
- that are required to create a cast.
+ To be able to drop a cast, you must own the source or the target
+ data type. These are the same privileges that are required to
+ create a cast.
</para>
<variablelist>
@@ -76,11 +75,6 @@ DROP CAST (<replaceable>sourcetype</replaceable> AS <replaceable>targettype</rep
<para>
Use <command>CREATE CAST</command> to create user-defined casts.
</para>
-
- <para>
- The privileges required to drop a cast may be changed in a future
- release.
- </para>
</refsect1>
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index 944ae192a0d..51d003600bb 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.16 2002/08/05 03:29:16 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.17 2002/08/11 17:44:12 petere Exp $
*
* DESCRIPTION
* These routines take the parse tree and pick out the
@@ -621,6 +621,12 @@ CreateCast(CreateCastStmt *stmt)
if (sourcetypeid == targettypeid)
elog(ERROR, "source data type and target data type are the same");
+ if (!pg_type_ownercheck(sourcetypeid, GetUserId())
+ && !pg_type_ownercheck(targettypeid, GetUserId()))
+ elog(ERROR, "must be owner of type %s or type %s",
+ TypeNameToString(stmt->sourcetype),
+ TypeNameToString(stmt->targettype));
+
relation = heap_openr(CastRelationName, RowExclusiveLock);
tuple = SearchSysCache(CASTSOURCETARGET,
@@ -639,10 +645,6 @@ CreateCast(CreateCastStmt *stmt)
false,
"CreateCast");
- if (!pg_proc_ownercheck(funcid, GetUserId()))
- aclcheck_error(ACLCHECK_NOT_OWNER,
- NameListToString(stmt->func->funcname));
-
tuple = SearchSysCache(PROCOID, ObjectIdGetDatum(funcid), 0, 0, 0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup of function %u failed", funcid);
@@ -666,12 +668,6 @@ CreateCast(CreateCastStmt *stmt)
else
{
/* indicates binary compatibility */
- if (!pg_type_ownercheck(sourcetypeid, GetUserId()))
- aclcheck_error(ACLCHECK_NOT_OWNER,
- TypeNameToString(stmt->sourcetype));
- if (!pg_type_ownercheck(targettypeid, GetUserId()))
- aclcheck_error(ACLCHECK_NOT_OWNER,
- TypeNameToString(stmt->targettype));
funcid = InvalidOid;
}
@@ -730,7 +726,6 @@ DropCast(DropCastStmt *stmt)
Oid sourcetypeid;
Oid targettypeid;
HeapTuple tuple;
- Form_pg_cast caststruct;
ObjectAddress object;
sourcetypeid = LookupTypeName(stmt->sourcetype);
@@ -753,22 +748,11 @@ DropCast(DropCastStmt *stmt)
TypeNameToString(stmt->targettype));
/* Permission check */
- caststruct = (Form_pg_cast) GETSTRUCT(tuple);
- if (caststruct->castfunc != InvalidOid)
- {
- if (!pg_proc_ownercheck(caststruct->castfunc, GetUserId()))
- aclcheck_error(ACLCHECK_NOT_OWNER,
- get_func_name(caststruct->castfunc));
- }
- else
- {
- if (!pg_type_ownercheck(sourcetypeid, GetUserId()))
- aclcheck_error(ACLCHECK_NOT_OWNER,
- format_type_be(sourcetypeid));
- if (!pg_type_ownercheck(targettypeid, GetUserId()))
- aclcheck_error(ACLCHECK_NOT_OWNER,
- format_type_be(targettypeid));
- }
+ if (!pg_type_ownercheck(sourcetypeid, GetUserId())
+ && !pg_type_ownercheck(targettypeid, GetUserId()))
+ elog(ERROR, "must be owner of type %s or type %s",
+ TypeNameToString(stmt->sourcetype),
+ TypeNameToString(stmt->targettype));
/*
* Do the deletion