From 7b970bc1bcd63b840a307ae96318b9472d730b52 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 29 Jul 2002 23:44:44 +0000 Subject: [PATCH] Use aclcheck_error() in place of ad-hoc permissions complaints. --- src/backend/commands/functioncmds.c | 38 +++++++++++++++++++---------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index d957af2d40..ea858d5571 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.14 2002/07/29 20:45:44 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.15 2002/07/29 23:44:44 tgl Exp $ * * DESCRIPTION * These routines take the parse tree and pick out the @@ -47,6 +47,7 @@ #include "parser/parse_func.h" #include "parser/parse_type.h" #include "utils/acl.h" +#include "utils/builtins.h" #include "utils/fmgroids.h" #include "utils/lsyscache.h" #include "utils/syscache.h" @@ -633,10 +634,14 @@ CreateCast(CreateCastStmt *stmt) if (stmt->func != NULL) { - funcid = LookupFuncNameTypeNames(stmt->func->funcname, stmt->func->funcargs, false, "CreateCast"); + funcid = LookupFuncNameTypeNames(stmt->func->funcname, + stmt->func->funcargs, + false, + "CreateCast"); - if(!pg_proc_ownercheck(funcid, GetUserId())) - elog(ERROR, "permission denied"); + 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)) @@ -661,10 +666,13 @@ CreateCast(CreateCastStmt *stmt) else { /* indicates binary compatibility */ - if (!pg_type_ownercheck(sourcetypeid, GetUserId()) - || !pg_type_ownercheck(targettypeid, GetUserId())) - elog(ERROR, "permission denied"); - funcid = 0; + 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; } /* ready to go */ @@ -754,14 +762,18 @@ DropCast(DropCastStmt *stmt) caststruct = (Form_pg_cast) GETSTRUCT(tuple); if (caststruct->castfunc != InvalidOid) { - if(!pg_proc_ownercheck(caststruct->castfunc, GetUserId())) - elog(ERROR, "permission denied"); + if (!pg_proc_ownercheck(caststruct->castfunc, GetUserId())) + aclcheck_error(ACLCHECK_NOT_OWNER, + get_func_name(caststruct->castfunc)); } else { - if (!pg_type_ownercheck(sourcetypeid, GetUserId()) - || !pg_type_ownercheck(targettypeid, GetUserId())) - elog(ERROR, "permission denied"); + 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)); } /*