Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qda7N-003zos-Hl for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Sep 2023 17:45:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qda7M-003oGf-EQ for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Sep 2023 17:45:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qda7M-003oGO-44 for pgsql-hackers@lists.postgresql.org; Tue, 05 Sep 2023 17:45:35 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qda7I-002uZy-F1 for pgsql-hackers@lists.postgresql.org; Tue, 05 Sep 2023 17:45:34 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 437D63200258 for ; Tue, 5 Sep 2023 13:45:31 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 05 Sep 2023 13:45:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1693935930; x=1694022330; bh=/ MzyPvXKIW4KC4yKhczsDNALoxADh4xL/ePCCLVmEKE=; b=N/OtZNRdAPDVDXKcN CGXsJ+229FQM4M8QNL8HlRXruDnBi4SMo84HMCdMvvhysn5VpfTdIdsipG+LYKEA UMcGooyo/uYTwpu2JYVqhVgmvpzFwXJeyU0K5K1674nAY4cjLwXReReiNjRY+rAu p04mg36j5W6wLn244K49FAKVLJW0zMs9xYQZSiNW/5mLVT0lKl9Cl664UVUZJ5Zn KynX8nkIvuIKjcHWYYdyQ/W0TyJAYLTgJOYgpk54oSRcQ7CcSiQl728YK3BhUX8O C3tW1F4cVjX9781DCZ2f1tbQ7eUF1Zt7Bbw8dCEtnbrH2+7JtDqoyGQun1uPlo4O BI4oA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudehuddgleefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfggtggugfgjsehmkeerredttdejnecuhfhrohhmpeetlhhvrghr ohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgqe enucggtffrrghtthgvrhhnpeetvdfhteeuueekfefhfedugeffhfehhfdvleffleetkeeg geefhffggeekjedtudenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtohhmne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhh vghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 5 Sep 2023 13:45:30 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id BDC59426; Tue, 5 Sep 2023 19:45:27 +0200 (CEST) Date: Tue, 5 Sep 2023 19:45:27 +0200 From: Alvaro Herrera To: Pg Hackers Subject: Re: missing privilege check after not-null constraint rework Message-ID: <202309051745.jk3bqxm26fbx@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="22fwpudqxyrxnub5" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <202309051744.y4mndw5gwzhh@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --22fwpudqxyrxnub5 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2023-Sep-05, Alvaro Herrera wrote: > Here's a fix to move the privilege check on constraint dropping from > ATExecDropConstraint to dropconstraint_internal. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "No renuncies a nada. No te aferres a nada." --22fwpudqxyrxnub5 Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="0001-Move-privilege-check-to-the-right-place.patch" From f58d4532d39bc39edc3841c1ee5c3e3e9e9d153a Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Tue, 5 Sep 2023 17:06:23 +0200 Subject: [PATCH] Move privilege check to the right place Now that ATExecDropConstraint doesn't recurse anymore, there's no point in testing the privileges during recursion there. Move the check to dropconstraint_internal, which is the place where recursion occurs. In passing, remove now-useless 'recursing' argument to ATExecDropConstraint. --- src/backend/commands/tablecmds.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 47c556669f..8a2c671b66 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -542,8 +542,7 @@ static void GetForeignKeyCheckTriggers(Relation trigrel, Oid *insertTriggerOid, Oid *updateTriggerOid); static void ATExecDropConstraint(Relation rel, const char *constrName, - DropBehavior behavior, - bool recurse, bool recursing, + DropBehavior behavior, bool recurse, bool missing_ok, LOCKMODE lockmode); static ObjectAddress dropconstraint_internal(Relation rel, HeapTuple constraintTup, DropBehavior behavior, @@ -5236,7 +5235,7 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab, break; case AT_DropConstraint: /* DROP CONSTRAINT */ ATExecDropConstraint(rel, cmd->name, cmd->behavior, - cmd->recurse, false, + cmd->recurse, cmd->missing_ok, lockmode); break; case AT_AlterColumnType: /* ALTER COLUMN TYPE */ @@ -12263,8 +12262,7 @@ createForeignKeyCheckTriggers(Oid myRelOid, Oid refRelOid, */ static void ATExecDropConstraint(Relation rel, const char *constrName, - DropBehavior behavior, - bool recurse, bool recursing, + DropBehavior behavior, bool recurse, bool missing_ok, LOCKMODE lockmode) { Relation conrel; @@ -12273,10 +12271,6 @@ ATExecDropConstraint(Relation rel, const char *constrName, HeapTuple tuple; bool found = false; - /* At top level, permission check was done in ATPrepCmd, else do it */ - if (recursing) - ATSimplePermissions(AT_DropConstraint, rel, ATT_TABLE | ATT_FOREIGN_TABLE); - conrel = table_open(ConstraintRelationId, RowExclusiveLock); /* @@ -12302,7 +12296,7 @@ ATExecDropConstraint(Relation rel, const char *constrName, { List *readyRels = NIL; - dropconstraint_internal(rel, tuple, behavior, recurse, recursing, + dropconstraint_internal(rel, tuple, behavior, recurse, false, missing_ok, &readyRels, lockmode); found = true; } @@ -12353,6 +12347,10 @@ dropconstraint_internal(Relation rel, HeapTuple constraintTup, DropBehavior beha return InvalidObjectAddress; *readyRels = lappend_oid(*readyRels, RelationGetRelid(rel)); + /* At top level, permission check was done in ATPrepCmd, else do it */ + if (recursing) + ATSimplePermissions(AT_DropConstraint, rel, ATT_TABLE | ATT_FOREIGN_TABLE); + conrel = table_open(ConstraintRelationId, RowExclusiveLock); con = (Form_pg_constraint) GETSTRUCT(constraintTup); -- 2.30.2 --22fwpudqxyrxnub5--