Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WTUEd-0003XP-8B for pgsql-bugs@arkaria.postgresql.org; Fri, 28 Mar 2014 10:42:03 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WTUEc-0000mg-I1 for pgsql-bugs@arkaria.postgresql.org; Fri, 28 Mar 2014 10:42:02 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WTUEb-0000mZ-96 for pgsql-bugs@postgresql.org; Fri, 28 Mar 2014 10:42:01 +0000 Received: from feynman.df7cb.de ([195.49.152.168]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WTUEX-0005Iy-Dc for pgsql-bugs@postgresql.org; Fri, 28 Mar 2014 10:42:00 +0000 Received: from msgid.df7cb.de (kref-4db68087.pool.mediaWays.net [77.182.128.135]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (Client did not present a certificate) by feynman.df7cb.de (Postfix) with ESMTPSA id 147336971E; Fri, 28 Mar 2014 11:41:55 +0100 (CET) Date: Fri, 28 Mar 2014 11:41:54 +0100 From: Christoph Berg To: Bruce Momjian Cc: Alvaro Herrera , Tom Lane , 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: <20140328104153.GB15310@msgid.df7cb.de> Mail-Followup-To: Christoph Berg , Bruce Momjian , Alvaro Herrera , Tom Lane , nicolas@marchildon.net, Bugs for PostgreSQL , David Fetter References: <296.1367950228@sss.pgh.pa.us> <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> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="iFRdW5/EC4oqxDHL" Content-Disposition: inline In-Reply-To: <20131218171628.GA1690@momjian.us> User-Agent: Mutt/1.5.21 (2010-09-15) 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 --iFRdW5/EC4oqxDHL Content-Type: multipart/mixed; boundary="KFztAG8eRSV9hGtP" Content-Disposition: inline --KFztAG8eRSV9hGtP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Re: Bruce Momjian 2013-12-18 <20131218171628.GA1690@momjian.us> > On Mon, Dec 9, 2013 at 07:47:34PM -0500, Bruce Momjian wrote: > > On Mon, Dec 9, 2013 at 06:45:39PM -0300, Alvaro Herrera wrote: > > > Bruce Momjian wrote: > > >=20 > > > > return STATUS_ERROR; > > > > } > > > > =20 > > > > ! user_name =3D get_user_name(&errstr); > > > > ! if (!user_name) > > > > { > > > > ! ereport(LOG, (errmsg("%s\n", errstr))); > > > > ! pfree(errstr); > > > > return STATUS_ERROR; > > > > } > > >=20 > > > The message is already translated by get_user_name, so I think this > > > should use errmsg_internal() instead of errmsg(). Also, why do you a= dd > > > a newline? > >=20 > > OK, done. > >=20 > > > Not clear whether the new file should be in src/port or src/common. > >=20 > > Agreed. It isn't designed to add missing OS functionality, but it is > > mostly OS-specific code. > >=20 > > Updated patch attached, with Tom's requested changes. >=20 > Patch applied. Hi, 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. Christoph --=20 cb@df7cb.de | http://www.df7cb.de/ --KFztAG8eRSV9hGtP Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=peer-auth-broken Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c new file mode 100644 index 2a46f7b..d5f15b0 *** a/src/backend/libpq/auth.c --- b/src/backend/libpq/auth.c *************** auth_peer(hbaPort *port) *** 1560,1567 **** char ident_user[IDENT_USERNAME_MAX + 1]; uid_t uid; gid_t gid; ! const char *user_name; ! char *errstr; =20 errno =3D 0; if (getpeereid(port->sock, &uid, &gid) !=3D 0) --- 1560,1566 ---- char ident_user[IDENT_USERNAME_MAX + 1]; uid_t uid; gid_t gid; ! struct passwd *pass; =20 errno =3D 0; if (getpeereid(port->sock, &uid, &gid) !=3D 0) *************** auth_peer(hbaPort *port) *** 1578,1592 **** return STATUS_ERROR; } =20 ! user_name =3D get_user_name(&errstr); ! if (!user_name) { ! ereport(LOG, (errmsg_internal("%s", errstr))); ! pfree(errstr); return STATUS_ERROR; } =20 ! strlcpy(ident_user, user_name, IDENT_USERNAME_MAX + 1); =20 return check_usermap(port->hba->usermap, port->user_name, ident_user, fa= lse); } --- 1577,1593 ---- return STATUS_ERROR; } =20 ! pass =3D getpwuid(uid); !=20 ! if (pass =3D=3D NULL) { ! ereport(LOG, ! (errmsg("local user with ID %d does not exist", ! (int) uid))); return STATUS_ERROR; } =20 ! strlcpy(ident_user, pass->pw_name, IDENT_USERNAME_MAX + 1); =20 return check_usermap(port->hba->usermap, port->user_name, ident_user, fa= lse); } --KFztAG8eRSV9hGtP-- --iFRdW5/EC4oqxDHL Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCAAGBQJTNVHqAAoJEExaa6sS0qeuTSIP/3FOMotL1MQsiJ8xcVjIs43D Z4b8g1GenWQmioYN+in6W/NIEykWsOWp8RgfZn3bYlkoAPw/opquVJo1tO0hPiEL GJHuaPJJtoH1LfZdgpo27PJRJVLIv1wlfhspdXnwxcKWvl0PWBfz9HnuAAiGegLH hZw9gzNWnLGOEREKB9bDcCSYFSVVsGqZu5J4knecRx0gCaAoGo95c8mYTFu/dXhl Lk9qMXWf9PXWc+2Vhlfz3Avk9xFFwPAivC5LwfVgRls4ABRY1b6dN30qlKPJxg98 CXTQ1wOlzT/ccaPagdO5qlaK8no8LUr+AZiQ8lbAvsP9st+rBsSk2bDao7f9JAta 5cevkSRYEK/TBWnI46qnM3BVwIJMRQqhTgQ39gRSvvj8Bqj1z/DG+E2pzu+KlVCH tneMBogh8/4h6RyWf/9N2iL/FT78ta/fA9SL/29FsxqZ1X9hA4MlpXtRxyQiicaC Yk/MXm5d39an7nT5ZiId0EBLj0IimXOdtHo2sbKEvK69lDW87dJfel+WyXFdYwLC 7N48eB/Fa/3Od3+59HHh/TCEu4PSNVeKUkkeNfWtkAnSoLNA8v6962dyjh3M5sZi Q1QG/rCYno5JJWJQg24ISnqyimcCNanNTTC8cp0lLGiZOH9f8NaLdBjDo9SbnOQ/ Yo/XJscm06zdK3jB0tyx =ETrA -----END PGP SIGNATURE----- --iFRdW5/EC4oqxDHL--