Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pL8PM-0002kX-4W for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Jan 2023 19:59:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pL8PL-0004cL-3L for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Jan 2023 19:59:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pL8PK-0004cC-P9 for pgsql-hackers@lists.postgresql.org; Thu, 26 Jan 2023 19:59:38 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pL8PG-0004K7-D7 for pgsql-hackers@postgresql.org; Thu, 26 Jan 2023 19:59:38 +0000 Received: by mail-pl1-x629.google.com with SMTP id p24so2826377plw.11 for ; Thu, 26 Jan 2023 11:59:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=sev3xPnXdgfKUbI4lTGYFtBW6lPtLivel+y4ptjn5HI=; b=fuuukF2BHpjYkVeZ/atSI2xU6XFXVNiO1jU9GYqHoMh5FI8XQXVRvKKTioigqdElwi 7xlrYUBU8h9oqO00WhYU4TD9oNyzvkuVXYIK7LnmfETvwK/rN0uepvjQC8OID0NaDG0u icqxNp+4iNwM395daTeNG2RvJCnz0F6uanSOZ7hEO7XfMIs68fpG/FrBA0OtYwMuuTsz sUMI0Urj/a4+dtFtRoEskaDsCipBE+fv/1WElw6r1/c0Up2NxLwfejt8RXJoA3q45B3a aaO9OoPBiFVkaVhcVkGOZuDTJs143io0Zygw+EZh8o6Y6htPCjOWx6fnOMwl75VnVIC3 KkFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=sev3xPnXdgfKUbI4lTGYFtBW6lPtLivel+y4ptjn5HI=; b=MW7bOFuY6JWP080Mu6YuyokgpQWFUdPT3vDgEf6uasQrwj6xwL1Fvlfzn0qL48afpr vM9dpCZRwLpWBzA0Vl/pailnaxTx5tVpqH9g5BsumnMB76FfKOnJFFbmvewIATitbBZS XkTU4Jj8mqonjlezZqP2A20nI7IwDz90Fox5auTimJpHsgQmQ4GC1pSTl4/AHI53tAcr /uG/GHUsQGaljrU9EPxoaSZJUM7q1m7YLYs9XfrfmVSQ08Nxi4eOkvspLmC5YewonMlu /XXVSBWSyr6vja7lVm5BcfBvobzfHlFSiwJeHp/0reIuX4cy8I2/1Fco/bQ7OSQZA1A3 iJHQ== X-Gm-Message-State: AFqh2kolvPzYVVd1pHfWRBqp2zd9doErW2kLgXOZBiT9Bm5RdFYuWcQZ iJ/Xum8mllrxsSaH89oCA7c= X-Google-Smtp-Source: AMrXdXsUmyBMMc5ZSkKXbHBFm+YuaVbTF0bNDmavEnNWZApsFjfX3PiPxbQKReETg9E4R40wfFB3Kg== X-Received: by 2002:a17:902:9888:b0:194:7f24:54d0 with SMTP id s8-20020a170902988800b001947f2454d0mr33649845plp.2.1674763172372; Thu, 26 Jan 2023 11:59:32 -0800 (PST) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id t7-20020a170902b20700b00192e1590349sm1332545plr.216.2023.01.26.11.59.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 11:59:31 -0800 (PST) Date: Thu, 26 Jan 2023 11:59:29 -0800 From: Nathan Bossart To: Robert Haas Cc: Alvaro Herrera , "pgsql-hackers@postgresql.org" , tgl@sss.pgh.pa.us Subject: Re: improving user.c error messages Message-ID: <20230126195929.GB1702315@nathanxps13> References: <20230126002251.GA1506128@nathanxps13> <20230126090739.nspznasnb4x3v5l4@alvherre.pgsql> <20230126191358.GA1660026@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jan 26, 2023 at 02:42:05PM -0500, Robert Haas wrote: > @@ -758,16 +776,13 @@ AlterRole(ParseState *pstate, AlterRoleStmt *stmt) > { > /* things an unprivileged user certainly can't do */ > if (dinherit || dcreaterole || dcreatedb || dcanlogin || dconnlimit || > - dvalidUntil || disreplication || dbypassRLS) > + dvalidUntil || disreplication || dbypassRLS || > + (dpassword && roleid != currentUserId)) > ereport(ERROR, > (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), > - errmsg("permission denied"))); > - > - /* an unprivileged user can change their own password */ > - if (dpassword && roleid != currentUserId) > - ereport(ERROR, > - (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), > - errmsg("must have CREATEROLE privilege to change another user's password"))); > + errmsg("permission denied to alter role"), > + errdetail("You must have %s privilege and %s on role \"%s\".", > + "CREATEROLE", "ADMIN OPTION", rolename))); > } > else if (!superuser()) > { > > Basically my question is whether having one error message for all of > those cases is good enough, or whether we should be trying harder. I > don't mind if the conclusion is that it's OK as-is, and I'm not > entirely sure what would be better. But when I was working on this > code, all of those cases OR'd together feeding into a single error > message seemed a little sketchy to me, so I am wondering what others > think. I wondered the same thing, but I hesitated because I didn't want to change too much in a patch for error messaging. I can give it a try. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com