pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Christoph Berg <cb@df7cb.de>
To: Bruce Momjian <bruce@momjian.us>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
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 11:41:54 +0100
Message-ID: <20140328104153.GB15310@msgid.df7cb.de> (raw )
In-Reply-To: <20131218171628.GA1690@momjian.us >
References: <E1UZk2V-0005oP-Eh@wrigleys.postgresql.org >
<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 >
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
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:
> > >
> > > > return STATUS_ERROR;
> > > > }
> > > >
> > > > ! user_name = get_user_name(&errstr);
> > > > ! if (!user_name)
> > > > {
> > > > ! ereport(LOG, (errmsg("%s\n", errstr)));
> > > > ! pfree(errstr);
> > > > return STATUS_ERROR;
> > > > }
> > >
> > > The message is already translated by get_user_name, so I think this
> > > should use errmsg_internal() instead of errmsg(). Also, why do you add
> > > a newline?
> >
> > OK, done.
> >
> > > Not clear whether the new file should be in src/port or src/common.
> >
> > Agreed. It isn't designed to add missing OS functionality, but it is
> > mostly OS-specific code.
> >
> > Updated patch attached, with Tom's requested changes.
>
> 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
--
cb@df7cb.de | http://www.df7cb.de/
Attachments:
peer-auth-broken (text/plain, 1.4K) download
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;
errno = 0;
if (getpeereid(port->sock, &uid, &gid) != 0)
--- 1560,1566 ----
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)
*************** auth_peer(hbaPort *port)
*** 1578,1592 ****
return STATUS_ERROR;
}
! user_name = get_user_name(&errstr);
! if (!user_name)
{
! ereport(LOG, (errmsg_internal("%s", errstr)));
! pfree(errstr);
return STATUS_ERROR;
}
! strlcpy(ident_user, user_name, IDENT_USERNAME_MAX + 1);
return check_usermap(port->hba->usermap, port->user_name, ident_user, false);
}
--- 1577,1593 ----
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);
}
signature.asc (application/pgp-signature, 818B) download
view thread (24+ messages) latest in thread
Message-ID: <20140328104153.GB15310@msgid.df7cb.de>
Permalink: ../20140328104153.GB15310@msgid.df7cb.de/
Also on: postgresql.org/message-id/20140328104153.GB15310@msgid.df7cb.de
copy link · copy postgr.es
reply 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: cb@df7cb.de, bruce@momjian.us, alvherre@2ndquadrant.com, tgl@sss.pgh.pa.us, nicolas@marchildon.net, david@fetter.org
Subject: Re: BUG #8139: initdb: Misleading error message when current user not in /etc/passwd
In-Reply-To: <20140328104153.GB15310@msgid.df7cb.de>
References: <E1UZk2V-0005oP-Eh@wrigleys.postgresql.org> <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> <20140328104153.GB15310@msgid.df7cb.de>
* 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