diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c index b0891e4c5f2b99aa90baee644c3385947ae25e9b..be29eff5a8e6d34335a0e5675bdd82565f0b1125 100644 --- a/src/backend/libpq/auth.c +++ b/src/backend/libpq/auth.c @@ -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. diff --git a/src/backend/libpq/crypt.c b/src/backend/libpq/crypt.c index 7a72275bc44a750e17167f2a2f83626bac20d68d..b87b05cd4265832eb74440a9824cd3bbf2f98b52 100644 --- a/src/backend/libpq/crypt.c +++ b/src/backend/libpq/crypt.c @@ -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); diff --git a/src/backend/libpq/pqpacket.c b/src/backend/libpq/pqpacket.c index 0a00a97ec6856c52dac54a95b566c4c12aabd018..66b7ea4393e73a2eb2f64e3a379ee4d7ebdaf9fd 100644 --- a/src/backend/libpq/pqpacket.c +++ b/src/backend/libpq/pqpacket.c @@ -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)); } diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 8b25be20df9b182f7d5c2e8dd50df91ca15a8c75..5f966532c42be0de5ff78cd19e977fc6384440de 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -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);