Skip to content

Commit 9bccdf1

Browse files
committed
Create/drop cast now requires ownership of at least one of the types.
1 parent 014a86a commit 9bccdf1

File tree

3 files changed

+19
-47
lines changed

3 files changed

+19
-47
lines changed

doc/src/sgml/ref/create_cast.sgml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_cast.sgml,v 1.1 2002/07/18 23:11:27 petere Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_cast.sgml,v 1.2 2002/08/11 17:44:12 petere Exp $ -->
22

33
<refentry id="SQL-CREATECAST">
44
<refmeta>
@@ -81,9 +81,8 @@ INSERT INTO foo(f1) VALUES(42);
8181
</para>
8282

8383
<para>
84-
To be able to create a cast, you must own the underlying function.
85-
To be able to create a binary compatible cast, you must own both
86-
the source and the target data type.
84+
To be able to create a cast, you must own the source or the target
85+
data type.
8786
</para>
8887

8988
<variablelist>
@@ -154,11 +153,6 @@ INSERT INTO foo(f1) VALUES(42);
154153
Use <command>DROP CAST</command> to remove user-defined casts.
155154
</para>
156155

157-
<para>
158-
The privileges required to create a cast may be changed in a future
159-
release.
160-
</para>
161-
162156
<para>
163157
Remember that if you want to be able to convert types both ways you
164158
need to declare casts both ways explicitly.

doc/src/sgml/ref/drop_cast.sgml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_cast.sgml,v 1.1 2002/07/18 23:11:27 petere Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_cast.sgml,v 1.2 2002/08/11 17:44:12 petere Exp $ -->
22

33
<refentry id="SQL-DROPCAST">
44
<refmeta>
@@ -26,10 +26,9 @@ DROP CAST (<replaceable>sourcetype</replaceable> AS <replaceable>targettype</rep
2626
</para>
2727

2828
<para>
29-
To be able to drop a cast, you must own the underlying function.
30-
To be able to drop a binary compatible cast, you must own both the
31-
source and the target data type. These are the same privileges
32-
that are required to create a cast.
29+
To be able to drop a cast, you must own the source or the target
30+
data type. These are the same privileges that are required to
31+
create a cast.
3332
</para>
3433

3534
<variablelist>
@@ -76,11 +75,6 @@ DROP CAST (<replaceable>sourcetype</replaceable> AS <replaceable>targettype</rep
7675
<para>
7776
Use <command>CREATE CAST</command> to create user-defined casts.
7877
</para>
79-
80-
<para>
81-
The privileges required to drop a cast may be changed in a future
82-
release.
83-
</para>
8478
</refsect1>
8579

8680

src/backend/commands/functioncmds.c

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.16 2002/08/05 03:29:16 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.17 2002/08/11 17:44:12 petere Exp $
1313
*
1414
* DESCRIPTION
1515
* These routines take the parse tree and pick out the
@@ -621,6 +621,12 @@ CreateCast(CreateCastStmt *stmt)
621621
if (sourcetypeid == targettypeid)
622622
elog(ERROR, "source data type and target data type are the same");
623623

624+
if (!pg_type_ownercheck(sourcetypeid, GetUserId())
625+
&& !pg_type_ownercheck(targettypeid, GetUserId()))
626+
elog(ERROR, "must be owner of type %s or type %s",
627+
TypeNameToString(stmt->sourcetype),
628+
TypeNameToString(stmt->targettype));
629+
624630
relation = heap_openr(CastRelationName, RowExclusiveLock);
625631

626632
tuple = SearchSysCache(CASTSOURCETARGET,
@@ -639,10 +645,6 @@ CreateCast(CreateCastStmt *stmt)
639645
false,
640646
"CreateCast");
641647

642-
if (!pg_proc_ownercheck(funcid, GetUserId()))
643-
aclcheck_error(ACLCHECK_NOT_OWNER,
644-
NameListToString(stmt->func->funcname));
645-
646648
tuple = SearchSysCache(PROCOID, ObjectIdGetDatum(funcid), 0, 0, 0);
647649
if (!HeapTupleIsValid(tuple))
648650
elog(ERROR, "cache lookup of function %u failed", funcid);
@@ -666,12 +668,6 @@ CreateCast(CreateCastStmt *stmt)
666668
else
667669
{
668670
/* indicates binary compatibility */
669-
if (!pg_type_ownercheck(sourcetypeid, GetUserId()))
670-
aclcheck_error(ACLCHECK_NOT_OWNER,
671-
TypeNameToString(stmt->sourcetype));
672-
if (!pg_type_ownercheck(targettypeid, GetUserId()))
673-
aclcheck_error(ACLCHECK_NOT_OWNER,
674-
TypeNameToString(stmt->targettype));
675671
funcid = InvalidOid;
676672
}
677673

@@ -730,7 +726,6 @@ DropCast(DropCastStmt *stmt)
730726
Oid sourcetypeid;
731727
Oid targettypeid;
732728
HeapTuple tuple;
733-
Form_pg_cast caststruct;
734729
ObjectAddress object;
735730

736731
sourcetypeid = LookupTypeName(stmt->sourcetype);
@@ -753,22 +748,11 @@ DropCast(DropCastStmt *stmt)
753748
TypeNameToString(stmt->targettype));
754749

755750
/* Permission check */
756-
caststruct = (Form_pg_cast) GETSTRUCT(tuple);
757-
if (caststruct->castfunc != InvalidOid)
758-
{
759-
if (!pg_proc_ownercheck(caststruct->castfunc, GetUserId()))
760-
aclcheck_error(ACLCHECK_NOT_OWNER,
761-
get_func_name(caststruct->castfunc));
762-
}
763-
else
764-
{
765-
if (!pg_type_ownercheck(sourcetypeid, GetUserId()))
766-
aclcheck_error(ACLCHECK_NOT_OWNER,
767-
format_type_be(sourcetypeid));
768-
if (!pg_type_ownercheck(targettypeid, GetUserId()))
769-
aclcheck_error(ACLCHECK_NOT_OWNER,
770-
format_type_be(targettypeid));
771-
}
751+
if (!pg_type_ownercheck(sourcetypeid, GetUserId())
752+
&& !pg_type_ownercheck(targettypeid, GetUserId()))
753+
elog(ERROR, "must be owner of type %s or type %s",
754+
TypeNameToString(stmt->sourcetype),
755+
TypeNameToString(stmt->targettype));
772756

773757
/*
774758
* Do the deletion

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy