From: Bruce Momjian <bruce@momjian.us>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Christoph Berg <cb@df7cb.de>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: nicolas@marchildon.net
Cc: Bugs for PostgreSQL <pgsql-bugs@postgresql.org>
Cc: David Fetter <david@fetter.org>
Subject: Re: BUG #8139: initdb: Misleading error message when current user not in /etc/passwd
Date: Fri, 28 Mar 2014 12:55:12 -0400
Message-ID: <20140328165512.GC18523@momjian.us> (raw)
In-Reply-To: <20140328143348.GB18523@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>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
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 <cb@df7cb.de> 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 <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ Everyone has their own god. +
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:peer.diff (text/x-diff, 1.6K) downloaddiff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.cnew file mode 100644index 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);
}
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: bruce@momjian.us, tgl@sss.pgh.pa.us, cb@df7cb.de, alvherre@2ndquadrant.com, nicolas@marchildon.net, david@fetter.org
Subject: Re: BUG #8139: initdb: Misleading error message when current user not in /etc/passwd
In-Reply-To: <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> <20140328165512.GC18523@momjian.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox