From: Phil Thompson <phil@river-bank.demon.co.uk>

I haven't had final confirmation from Peter yet, but the attached patch
needs to be applied for the Beta otherwise password and crypt
authentication just won't work.

It puts back the loop in libpq and also fixes a couple of problems with
maintaining compatability with pre-6.3 drivers.
This commit is contained in:
Marc G. Fournier 1998-01-31 20:14:15 +00:00
parent f1f01a70f9
commit 93211b9170
4 changed files with 60 additions and 39 deletions

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.24 1998/01/29 03:23:05 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.25 1998/01/31 20:12:06 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@ -47,6 +47,7 @@ static void handle_krb5_auth(Port *port);
static void handle_password_auth(Port *port);
static void readPasswordPacket(char *arg, PacketLen len, char *pkt);
static void pg_passwordv0_recvauth(char *arg, PacketLen len, char *pkt);
static int checkPassword(Port *port, char *user, char *password);
static int old_be_recvauth(Port *port);
static int map_old_to_new(Port *port, UserAuth old, int status);
@ -346,19 +347,19 @@ static void pg_passwordv0_recvauth(char *arg, PacketLen len, char *pkt)
cp = start = pp->data;
while (len > 0)
if (*cp++ == '\0')
{
if (user == NULL)
user = start;
else
while (len-- > 0)
if (*cp++ == '\0')
{
password = start;
break;
}
if (user == NULL)
user = start;
else
{
password = start;
break;
}
start = cp;
}
start = cp;
}
if (user == NULL || password == NULL)
{
@ -369,9 +370,25 @@ static void pg_passwordv0_recvauth(char *arg, PacketLen len, char *pkt)
auth_failed(port);
}
else if (map_old_to_new(port, uaPassword,
verify_password(port->auth_arg, user, password)) != STATUS_OK)
auth_failed(port);
else
{
int status;
UserAuth saved;
/* Check the password. */
saved = port->auth_method;
port->auth_method = uaPassword;
status = checkPassword(port, user, password);
port->auth_method = saved;
/* Adjust the result if necessary. */
if (map_old_to_new(port, uaPassword, status) != STATUS_OK)
auth_failed(port);
}
}
@ -579,24 +596,28 @@ static void readPasswordPacket(char *arg, PacketLen len, char *pkt)
StrNCpy(password, ((PasswordPacket *)pkt)->passwd, len);
/*
* Use the local flat password file if clear passwords are used and the
* file is specified. Otherwise use the password in the pg_user table,
* encrypted or not.
*/
if (port->auth_method == uaPassword && port->auth_arg[0] != '\0')
{
if (verify_password(port->auth_arg, port->user, password) != STATUS_OK)
auth_failed(port);
}
else if (crypt_verify(port, port->user, password) != STATUS_OK)
if (checkPassword(port, port->user, password) != STATUS_OK)
auth_failed(port);
else
sendAuthRequest(port, AUTH_REQ_OK, handle_done_auth);
}
/*
* Use the local flat password file if clear passwords are used and the file is
* specified. Otherwise use the password in the pg_user table, encrypted or
* not.
*/
static int checkPassword(Port *port, char *user, char *password)
{
if (port->auth_method == uaPassword && port->auth_arg[0] != '\0')
return verify_password(port->auth_arg, user, password);
return crypt_verify(port, user, password);
}
/*
* Server demux routine for incoming authentication information for protocol
* version 0.

View File

@ -271,7 +271,7 @@ int crypt_verify(Port* port, const char* user, const char* pgpass) {
if (!strcmp(pgpass, crypt_pwd)) {
/* check here to be sure we are not past valuntil
*/
if (!valuntil)
if (!valuntil || strcmp(valuntil, "\\N") == 0)
vuntil = INVALID_ABSTIME;
else
vuntil = nabstimein(valuntil);

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/pqpacket.c,v 1.13 1998/01/26 01:41:12 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/pqpacket.c,v 1.14 1998/01/31 20:12:09 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@ -40,6 +40,10 @@ void PacketReceiveSetup(Packet *pkt, void (*iodone)(), char *arg)
pkt->iodone = iodone;
pkt->arg = arg;
pkt->state = ReadingPacketLength;
/* Clear the destination. */
MemSet(&pkt->pkt, 0, sizeof (pkt->pkt));
}

View File

@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.72 1998/01/27 15:34:43 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.73 1998/01/31 20:14:15 scrappy Exp $
*
* NOTES
*
@ -719,15 +719,11 @@ static void readStartupPacket(char *arg, PacketLen len, char *pkt)
port = (Port *)arg;
si = (StartupPacket *)pkt;
/* At the moment the startup packet must be a fixed length. */
if (len != sizeof (StartupPacket))
{
PacketSendError(&port->pktInfo, "Invalid startup packet.");
return;
}
/* Get the parameters from the startup packet as C strings. */
/*
* Get the parameters from the startup packet as C strings. The packet
* destination was cleared first so a short packet has zeros silently
* added and a long packet is silently truncated.
*/
StrNCpy(port->database, si->database, sizeof (port->database) - 1);
StrNCpy(port->user, si->user, sizeof (port->user) - 1);