Thread: Re: pgsql/php3/apache authentication

Re: pgsql/php3/apache authentication

From
Malcolm Beattie
Date:
Peter Eisentraut writes:
> On Thu, 27 Apr 2000, Malcolm Beattie wrote:
>
> > > There's no way for the server to determine the system user name of the
> > > other end of a domain socket; at least no one has implemented one yet. So
> > > essentially this isn't going to work.
> >
> > The client can pass an SCM_CREDENTIALS (Linux) or SCM_CREDS (BSDish)
> > socket control message down the Unix domain socket and the kernel will
> > fill in the client's credentials (including PID, uid and gid) for the
> > receiver to read. Some Unices don't support this though.
>
> This might be doable but I think I'd like to see exactly how many Unices
> support this. I wouldn't be too excited about a solution that only works
> on Linux and ???BSD (or any other combination). Is there any way one can
> check?

An autoconf test of the various ways would be possible. Since my
previous message, I've found that Linux has another way of getting
peer credentials too. The disadvantage is that it's Linux-only (as
far as I know). The big advantage is that it doesn't need any changes
to the client side at all: the server simply does
    struct ucred peercred;
    int solen = sizeof(peercred);
    getsockopt(port->sock, SOL_SOCKET, SO_PEERCRED, &peercred, &solen);
and you then have peercred.uid (and gid and pid) telling you who bound
the client socket.

I've done a small patch (it only touches backend/libpq/auth.c,
backend/libpq/hba.c and include/libpq/hba.h) against 7.0RC1 (though I
guess it would probably work against pretty much any version). It
only affects the build of postmaster. It lets you use the keyword
"ident" in pg_hba.conf on Unix domain connections as well as the
normal use for just TCP connections (with a usermap, just the same).
For TCP, ident means "ask the peer's ident server for username
information"; for Unix domain the patch makes ident mean "ask the
kernel about the peer's uid information and look username up with
getpwuid". I've tested it here and it seems to work fine: you have
compile postmaster (at least) with -DHAVE_SO_PEERCRED since I didn't
want to get into messing with autoconf at this stage. For example,
    make COPT="-DHAVE_SO_PEERCRED"
works for me. I've made the patch available as
    http://users.ox.ac.uk/~mbeattie/postgresql-peercred.patch
since I'm not subscribed to pgsql-patches. It's Linux-only (until or
unless other O/Ses pick up SO_PEERCRED) so it may well not be
considered portable enough to include in the main distribution
(except as a separate patch maybe?) but some people might like to
apply it for the added security themselves.

--Malcolm

--
Malcolm Beattie <mbeattie@sable.ox.ac.uk>
Unix Systems Programmer
Oxford University Computing Services

Re: pgsql/php3/apache authentication

From
"Ross J. Reedstrom"
Date:
On Wed, May 10, 2000 at 10:22:30AM +0100, Malcolm Beattie wrote:
> 
> I've done a small patch (it only touches backend/libpq/auth.c,
> backend/libpq/hba.c and include/libpq/hba.h) against 7.0RC1 (though I
> guess it would probably work against pretty much any version). It
> works for me. I've made the patch available as
>     http://users.ox.ac.uk/~mbeattie/postgresql-peercred.patch
> since I'm not subscribed to pgsql-patches. It's Linux-only (until or

Take a look at subscribing to pgsql-loophole: That'll let you post to
the pgsql lists without receiving traffic from them directly: most useful
for pgsql-patches.

Ross
-- 
Ross J. Reedstrom, Ph.D., <reedstrm@rice.edu> 
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St.,  Houston, TX 77005


Re: pgsql/php3/apache authentication

From
The Hermit Hacker
Date:
On Wed, 10 May 2000, Ross J. Reedstrom wrote:

> On Wed, May 10, 2000 at 10:22:30AM +0100, Malcolm Beattie wrote:
> > 
> > I've done a small patch (it only touches backend/libpq/auth.c,
> > backend/libpq/hba.c and include/libpq/hba.h) against 7.0RC1 (though I
> > guess it would probably work against pretty much any version). It
> > works for me. I've made the patch available as
> >     http://users.ox.ac.uk/~mbeattie/postgresql-peercred.patch
> > since I'm not subscribed to pgsql-patches. It's Linux-only (until or
> 
> Take a look at subscribing to pgsql-loophole: That'll let you post to
> the pgsql lists without receiving traffic from them directly: most useful
> for pgsql-patches.

actually, do a 'subscribe-nomail' to any one of the lists will also give
you that ability ... 

This new majordomo2 has features up the wazoo ...