]> granicus.if.org Git - postgresql/commitdiff
Fold FindConversion() into FindConversionByName() and remove ACL check.
authorRobert Haas <rhaas@postgresql.org>
Tue, 2 Feb 2010 18:52:33 +0000 (18:52 +0000)
committerRobert Haas <rhaas@postgresql.org>
Tue, 2 Feb 2010 18:52:33 +0000 (18:52 +0000)
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
src/backend/catalog/pg_conversion.c
src/include/catalog/pg_conversion_fn.h

index ac1b3e6e51eee26a624f9e5fa807439f24076955..a345d98e644e7147de2b2b957976103004709558 100644 (file)
@@ -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;
                }
index a795815e64529f3ce76a6da9ea1273744913d01a..cb3654a89316ecdcfa6e0feef57157e11bf32f64 100644 (file)
@@ -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;
-}
index f6461ccd27f425400d06a0a9efad6e148c114bbf..3086936496f2668dd6a961ec0d6c1d544551713c 100644 (file)
@@ -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 */