Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WTa3y-0000TV-Fy for pgsql-bugs@arkaria.postgresql.org; Fri, 28 Mar 2014 16:55:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WTa3x-0003Ca-TO for pgsql-bugs@arkaria.postgresql.org; Fri, 28 Mar 2014 16:55:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WTa3w-0003CL-Pd for pgsql-bugs@postgresql.org; Fri, 28 Mar 2014 16:55:24 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WTa3p-0002fB-Df for pgsql-bugs@postgresql.org; Fri, 28 Mar 2014 16:55:24 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1WTa3k-0007tX-QI; Fri, 28 Mar 2014 12:55:12 -0400 Date: Fri, 28 Mar 2014 12:55:12 -0400 From: Bruce Momjian To: Tom Lane Cc: Christoph Berg , Alvaro Herrera , nicolas@marchildon.net, Bugs for PostgreSQL , David Fetter Subject: Re: BUG #8139: initdb: Misleading error message when current user not in /etc/passwd Message-ID: <20140328165512.GC18523@momjian.us> References: <20130507181904.GA26800@eldon.alvh.no-ip.org> <20131204155257.GD17114@momjian.us> <20131204190338.GP5158@eldon.alvh.no-ip.org> <20131209210532.GA2119@momjian.us> <20131209214539.GL6777@eldon.alvh.no-ip.org> <20131210004734.GE2119@momjian.us> <20131218171628.GA1690@momjian.us> <20140328104153.GB15310@msgid.df7cb.de> <17137.1396017066@sss.pgh.pa.us> <20140328143348.GB18523@momjian.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="XsQoSWH+UP9D9v3l" Content-Disposition: inline In-Reply-To: <20140328143348.GB18523@momjian.us> User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -2.3 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --XsQoSWH+UP9D9v3l Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Mar 28, 2014 at 10:33:48AM -0400, Bruce Momjian wrote: > On Fri, Mar 28, 2014 at 10:31:06AM -0400, Tom Lane wrote: > > Christoph Berg writes: > > > the quoted code bit above in src/backend/libpq/auth.c is utterly > > > broken: for peer authentication, it uses get_user_name(), which yields > > > the *server* user name, not the client's. For that reason, peer > > > authentication in 9.4devel is broken - you can't log in with your user > > > name, but you can just say -U postgres (or what the initdb user was), > > > and it will let you in. > > > > > The attached patch reverts the src/backend/libpq/auth.c portion of > > > 613c6d26bd42dd8c2dd0664315be9551475b8864 and fixes peer auth. > > > > Applied, thanks! > > I guess I should have said I was working on an updated patch. I will > merge my changes in. I have applied the attached patch to make the code more closely match what is done in src/common/username.c, particularly to display the errno string on failure. Christoph, thanks so much for finding this error now, rather than later. I looked over the original patch that introduced this bug and auth_peer() is the only place where we were passing in a user id, rather than passing geteuid() directly to getpwuid, e.g.: getpwuid(geteuid()) I think we are good now. My apologies for introducing this bug. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + Everyone has their own god. + --XsQoSWH+UP9D9v3l Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="peer.diff" diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c new file mode 100644 index a2f1c96..31ade0b *** a/src/backend/libpq/auth.c --- b/src/backend/libpq/auth.c *************** auth_peer(hbaPort *port) *** 1559,1567 **** char ident_user[IDENT_USERNAME_MAX + 1]; uid_t uid; gid_t gid; ! struct passwd *pass; - errno = 0; if (getpeereid(port->sock, &uid, &gid) != 0) { /* Provide special error message if getpeereid is a stub */ --- 1559,1566 ---- char ident_user[IDENT_USERNAME_MAX + 1]; uid_t uid; gid_t gid; ! struct passwd *pw; if (getpeereid(port->sock, &uid, &gid) != 0) { /* Provide special error message if getpeereid is a stub */ *************** auth_peer(hbaPort *port) *** 1576,1592 **** return STATUS_ERROR; } ! pass = getpwuid(uid); ! ! if (pass == NULL) { ereport(LOG, ! (errmsg("local user with ID %d does not exist", ! (int) uid))); return STATUS_ERROR; } ! strlcpy(ident_user, pass->pw_name, IDENT_USERNAME_MAX + 1); return check_usermap(port->hba->usermap, port->user_name, ident_user, false); } --- 1575,1591 ---- return STATUS_ERROR; } ! errno = 0; /* clear errno before call */ ! pw = getpwuid(uid); ! if (!pw) { ereport(LOG, ! (errmsg("failed to look up local user id %ld: %s", ! (long) uid, errno ? strerror(errno) : _("user does not exist")))); return STATUS_ERROR; } ! strlcpy(ident_user, pw->pw_name, IDENT_USERNAME_MAX + 1); return check_usermap(port->hba->usermap, port->user_name, ident_user, false); } --XsQoSWH+UP9D9v3l Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --XsQoSWH+UP9D9v3l--