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

Commit d8db6a6

Browse files
committed
Fold FindConversion() into FindConversionByName() and remove ACL check.
All callers of FindConversionByName() already do suitable permissions checking already apart from this function, but this is not just dead code removal: the unnecessary permissions check can actually lead to spurious failures - there's no reason why inability to execute the underlying function should prohibit renaming the conversion, for example. (The error messages in these cases were also rather poor: FindConversion would return InvalidOid, eventually leading to a complaint that the conversion "did not exist", which was not correct.) KaiGai Kohei
1 parent 4d32f6d commit d8db6a6

File tree

3 files changed

+11
-41
lines changed

3 files changed

+11
-41
lines changed

src/backend/catalog/namespace.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.121 2010/01/02 16:57:36 momjian Exp $
16+
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.122 2010/02/02 18:52:33 rhaas Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -2836,7 +2836,10 @@ FindConversionByName(List *name)
28362836
{
28372837
/* use exact schema given */
28382838
namespaceId = LookupExplicitNamespace(schemaname);
2839-
return FindConversion(conversion_name, namespaceId);
2839+
return GetSysCacheOid(CONNAMENSP,
2840+
PointerGetDatum(conversion_name),
2841+
ObjectIdGetDatum(namespaceId),
2842+
0, 0);
28402843
}
28412844
else
28422845
{
@@ -2850,7 +2853,10 @@ FindConversionByName(List *name)
28502853
if (namespaceId == myTempNamespace)
28512854
continue; /* do not look in temp namespace */
28522855

2853-
conoid = FindConversion(conversion_name, namespaceId);
2856+
conoid = GetSysCacheOid(CONNAMENSP,
2857+
PointerGetDatum(conversion_name),
2858+
ObjectIdGetDatum(namespaceId),
2859+
0, 0);
28542860
if (OidIsValid(conoid))
28552861
return conoid;
28562862
}

src/backend/catalog/pg_conversion.c

+1-36
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/pg_conversion.c,v 1.48 2010/01/02 16:57:36 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/pg_conversion.c,v 1.49 2010/02/02 18:52:33 rhaas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -209,38 +209,3 @@ FindDefaultConversion(Oid name_space, int32 for_encoding, int32 to_encoding)
209209
ReleaseSysCacheList(catlist);
210210
return proc;
211211
}
212-
213-
/*
214-
* FindConversion
215-
*
216-
* Find conversion by namespace and conversion name.
217-
* Returns conversion OID.
218-
*/
219-
Oid
220-
FindConversion(const char *conname, Oid connamespace)
221-
{
222-
HeapTuple tuple;
223-
Oid procoid;
224-
Oid conoid;
225-
AclResult aclresult;
226-
227-
/* search pg_conversion by connamespace and conversion name */
228-
tuple = SearchSysCache(CONNAMENSP,
229-
PointerGetDatum(conname),
230-
ObjectIdGetDatum(connamespace),
231-
0, 0);
232-
if (!HeapTupleIsValid(tuple))
233-
return InvalidOid;
234-
235-
procoid = ((Form_pg_conversion) GETSTRUCT(tuple))->conproc;
236-
conoid = HeapTupleGetOid(tuple);
237-
238-
ReleaseSysCache(tuple);
239-
240-
/* Check we have execute rights for the function */
241-
aclresult = pg_proc_aclcheck(procoid, GetUserId(), ACL_EXECUTE);
242-
if (aclresult != ACLCHECK_OK)
243-
return InvalidOid;
244-
245-
return conoid;
246-
}

src/include/catalog/pg_conversion_fn.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_conversion_fn.h,v 1.5 2010/01/02 16:58:01 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_conversion_fn.h,v 1.6 2010/02/02 18:52:33 rhaas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -19,7 +19,6 @@ extern Oid ConversionCreate(const char *conname, Oid connamespace,
1919
int32 conforencoding, int32 contoencoding,
2020
Oid conproc, bool def);
2121
extern void RemoveConversionById(Oid conversionOid);
22-
extern Oid FindConversion(const char *conname, Oid connamespace);
2322
extern Oid FindDefaultConversion(Oid connamespace, int32 for_encoding, int32 to_encoding);
2423

2524
#endif /* PG_CONVERSION_FN_H */

0 commit comments

Comments
 (0)