From d8db6a6096d1b901f2ad9077148a87cd95fb3e86 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Tue, 2 Feb 2010 18:52:33 +0000 Subject: [PATCH] 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 --- src/backend/catalog/namespace.c | 12 ++++++--- src/backend/catalog/pg_conversion.c | 37 +------------------------- src/include/catalog/pg_conversion_fn.h | 3 +-- 3 files changed, 11 insertions(+), 41 deletions(-) diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c index ac1b3e6e51..a345d98e64 100644 --- a/src/backend/catalog/namespace.c +++ b/src/backend/catalog/namespace.c @@ -13,7 +13,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.121 2010/01/02 16:57:36 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.122 2010/02/02 18:52:33 rhaas Exp $ * *------------------------------------------------------------------------- */ @@ -2836,7 +2836,10 @@ FindConversionByName(List *name) { /* use exact schema given */ namespaceId = LookupExplicitNamespace(schemaname); - return FindConversion(conversion_name, namespaceId); + return GetSysCacheOid(CONNAMENSP, + PointerGetDatum(conversion_name), + ObjectIdGetDatum(namespaceId), + 0, 0); } else { @@ -2850,7 +2853,10 @@ FindConversionByName(List *name) if (namespaceId == myTempNamespace) continue; /* do not look in temp namespace */ - conoid = FindConversion(conversion_name, namespaceId); + conoid = GetSysCacheOid(CONNAMENSP, + PointerGetDatum(conversion_name), + ObjectIdGetDatum(namespaceId), + 0, 0); if (OidIsValid(conoid)) return conoid; } diff --git a/src/backend/catalog/pg_conversion.c b/src/backend/catalog/pg_conversion.c index a795815e64..cb3654a893 100644 --- a/src/backend/catalog/pg_conversion.c +++ b/src/backend/catalog/pg_conversion.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/catalog/pg_conversion.c,v 1.48 2010/01/02 16:57:36 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/pg_conversion.c,v 1.49 2010/02/02 18:52:33 rhaas Exp $ * *------------------------------------------------------------------------- */ @@ -209,38 +209,3 @@ FindDefaultConversion(Oid name_space, int32 for_encoding, int32 to_encoding) ReleaseSysCacheList(catlist); return proc; } - -/* - * FindConversion - * - * Find conversion by namespace and conversion name. - * Returns conversion OID. - */ -Oid -FindConversion(const char *conname, Oid connamespace) -{ - HeapTuple tuple; - Oid procoid; - Oid conoid; - AclResult aclresult; - - /* search pg_conversion by connamespace and conversion name */ - tuple = SearchSysCache(CONNAMENSP, - PointerGetDatum(conname), - ObjectIdGetDatum(connamespace), - 0, 0); - if (!HeapTupleIsValid(tuple)) - return InvalidOid; - - procoid = ((Form_pg_conversion) GETSTRUCT(tuple))->conproc; - conoid = HeapTupleGetOid(tuple); - - ReleaseSysCache(tuple); - - /* Check we have execute rights for the function */ - aclresult = pg_proc_aclcheck(procoid, GetUserId(), ACL_EXECUTE); - if (aclresult != ACLCHECK_OK) - return InvalidOid; - - return conoid; -} diff --git a/src/include/catalog/pg_conversion_fn.h b/src/include/catalog/pg_conversion_fn.h index f6461ccd27..3086936496 100644 --- a/src/include/catalog/pg_conversion_fn.h +++ b/src/include/catalog/pg_conversion_fn.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/pg_conversion_fn.h,v 1.5 2010/01/02 16:58:01 momjian Exp $ + * $PostgreSQL: pgsql/src/include/catalog/pg_conversion_fn.h,v 1.6 2010/02/02 18:52:33 rhaas Exp $ * *------------------------------------------------------------------------- */ @@ -19,7 +19,6 @@ extern Oid ConversionCreate(const char *conname, Oid connamespace, int32 conforencoding, int32 contoencoding, Oid conproc, bool def); extern void RemoveConversionById(Oid conversionOid); -extern Oid FindConversion(const char *conname, Oid connamespace); extern Oid FindDefaultConversion(Oid connamespace, int32 for_encoding, int32 to_encoding); #endif /* PG_CONVERSION_FN_H */ -- 2.40.0