Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 93211b9

Browse files
committed
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.
1 parent f1f01a7 commit 93211b9

File tree

4 files changed

+60
-39
lines changed

4 files changed

+60
-39
lines changed

src/backend/libpq/auth.c

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.24 1998/01/29 03:23:05 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.25 1998/01/31 20:12:06 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -47,6 +47,7 @@ static void handle_krb5_auth(Port *port);
4747
static void handle_password_auth(Port *port);
4848
static void readPasswordPacket(char *arg, PacketLen len, char *pkt);
4949
static void pg_passwordv0_recvauth(char *arg, PacketLen len, char *pkt);
50+
static int checkPassword(Port *port, char *user, char *password);
5051
static int old_be_recvauth(Port *port);
5152
static int map_old_to_new(Port *port, UserAuth old, int status);
5253

@@ -346,19 +347,19 @@ static void pg_passwordv0_recvauth(char *arg, PacketLen len, char *pkt)
346347

347348
cp = start = pp->data;
348349

349-
while (len > 0)
350-
if (*cp++ == '\0')
351-
{
352-
if (user == NULL)
353-
user = start;
354-
else
350+
while (len-- > 0)
351+
if (*cp++ == '\0')
355352
{
356-
password = start;
357-
break;
358-
}
353+
if (user == NULL)
354+
user = start;
355+
else
356+
{
357+
password = start;
358+
break;
359+
}
359360

360-
start = cp;
361-
}
361+
start = cp;
362+
}
362363

363364
if (user == NULL || password == NULL)
364365
{
@@ -369,9 +370,25 @@ static void pg_passwordv0_recvauth(char *arg, PacketLen len, char *pkt)
369370

370371
auth_failed(port);
371372
}
372-
else if (map_old_to_new(port, uaPassword,
373-
verify_password(port->auth_arg, user, password)) != STATUS_OK)
374-
auth_failed(port);
373+
else
374+
{
375+
int status;
376+
UserAuth saved;
377+
378+
/* Check the password. */
379+
380+
saved = port->auth_method;
381+
port->auth_method = uaPassword;
382+
383+
status = checkPassword(port, user, password);
384+
385+
port->auth_method = saved;
386+
387+
/* Adjust the result if necessary. */
388+
389+
if (map_old_to_new(port, uaPassword, status) != STATUS_OK)
390+
auth_failed(port);
391+
}
375392
}
376393

377394

@@ -579,24 +596,28 @@ static void readPasswordPacket(char *arg, PacketLen len, char *pkt)
579596

580597
StrNCpy(password, ((PasswordPacket *)pkt)->passwd, len);
581598

582-
/*
583-
* Use the local flat password file if clear passwords are used and the
584-
* file is specified. Otherwise use the password in the pg_user table,
585-
* encrypted or not.
586-
*/
587-
588-
if (port->auth_method == uaPassword && port->auth_arg[0] != '\0')
589-
{
590-
if (verify_password(port->auth_arg, port->user, password) != STATUS_OK)
591-
auth_failed(port);
592-
}
593-
else if (crypt_verify(port, port->user, password) != STATUS_OK)
599+
if (checkPassword(port, port->user, password) != STATUS_OK)
594600
auth_failed(port);
595601
else
596602
sendAuthRequest(port, AUTH_REQ_OK, handle_done_auth);
597603
}
598604

599605

606+
/*
607+
* Use the local flat password file if clear passwords are used and the file is
608+
* specified. Otherwise use the password in the pg_user table, encrypted or
609+
* not.
610+
*/
611+
612+
static int checkPassword(Port *port, char *user, char *password)
613+
{
614+
if (port->auth_method == uaPassword && port->auth_arg[0] != '\0')
615+
return verify_password(port->auth_arg, user, password);
616+
617+
return crypt_verify(port, user, password);
618+
}
619+
620+
600621
/*
601622
* Server demux routine for incoming authentication information for protocol
602623
* version 0.

src/backend/libpq/crypt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ int crypt_verify(Port* port, const char* user, const char* pgpass) {
271271
if (!strcmp(pgpass, crypt_pwd)) {
272272
/* check here to be sure we are not past valuntil
273273
*/
274-
if (!valuntil)
274+
if (!valuntil || strcmp(valuntil, "\\N") == 0)
275275
vuntil = INVALID_ABSTIME;
276276
else
277277
vuntil = nabstimein(valuntil);

src/backend/libpq/pqpacket.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/pqpacket.c,v 1.13 1998/01/26 01:41:12 scrappy Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/pqpacket.c,v 1.14 1998/01/31 20:12:09 scrappy Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -40,6 +40,10 @@ void PacketReceiveSetup(Packet *pkt, void (*iodone)(), char *arg)
4040
pkt->iodone = iodone;
4141
pkt->arg = arg;
4242
pkt->state = ReadingPacketLength;
43+
44+
/* Clear the destination. */
45+
46+
MemSet(&pkt->pkt, 0, sizeof (pkt->pkt));
4347
}
4448

4549

src/backend/postmaster/postmaster.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.72 1998/01/27 15:34:43 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.73 1998/01/31 20:14:15 scrappy Exp $
1414
*
1515
* NOTES
1616
*
@@ -719,15 +719,11 @@ static void readStartupPacket(char *arg, PacketLen len, char *pkt)
719719
port = (Port *)arg;
720720
si = (StartupPacket *)pkt;
721721

722-
/* At the moment the startup packet must be a fixed length. */
723-
724-
if (len != sizeof (StartupPacket))
725-
{
726-
PacketSendError(&port->pktInfo, "Invalid startup packet.");
727-
return;
728-
}
729-
730-
/* Get the parameters from the startup packet as C strings. */
722+
/*
723+
* Get the parameters from the startup packet as C strings. The packet
724+
* destination was cleared first so a short packet has zeros silently
725+
* added and a long packet is silently truncated.
726+
*/
731727

732728
StrNCpy(port->database, si->database, sizeof (port->database) - 1);
733729
StrNCpy(port->user, si->user, sizeof (port->user) - 1);

0 commit comments

Comments
 (0)