From 5241a6259ff0a4a12d7659b25310f0987b51f211 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 29 Aug 2002 03:22:01 +0000 Subject: [PATCH] Remove support for version-0 FE/BE protocol, per pghackers discussion. This breaks support for 6.2 or older client libraries. --- doc/src/sgml/release.sgml | 3 +- src/backend/libpq/auth.c | 182 +---------------------------------------- src/backend/libpq/pqformat.c | 47 ++--------- src/include/libpq/libpq-be.h | 13 +-- src/include/libpq/pqcomm.h | 17 ++-- src/interfaces/libpq/fe-auth.c | 7 +- 6 files changed, 21 insertions(+), 248 deletions(-) diff --git a/doc/src/sgml/release.sgml b/doc/src/sgml/release.sgml index 60c78d0588..50df580404 100644 --- a/doc/src/sgml/release.sgml +++ b/doc/src/sgml/release.sgml @@ -1,5 +1,5 @@ @@ -24,6 +24,7 @@ CDATA means the content is "SGML-free", so you can write without worries about funny characters. --> unused); - - cp = start = pp->data; - - while (len-- > 0) - if (*cp++ == '\0') - { - if (user == NULL) - user = start; - else - { - password = start; - break; - } - - start = cp; - } - - if (user == NULL || password == NULL) - { - elog(LOG, "pg_password_recvauth: badly formed password packet"); - status = STATUS_ERROR; - } - else - { - UserAuth saved; - - /* Check the password. */ - - saved = port->auth_method; - port->auth_method = uaPassword; - - status = md5_crypt_verify(port, user, password); - - port->auth_method = saved; - - /* Adjust the result if necessary. */ - if (map_old_to_new(port, uaPassword, status) != STATUS_OK) - status = STATUS_ERROR; - } - - pfree(buf); - - return status; -} - - -/* * Tell the user the authentication failed, but not (much about) why. * * There is a tradeoff here between security concerns and making life @@ -481,16 +398,6 @@ ClientAuthentication(Port *port) if (hba_getauthmethod(port) != STATUS_OK) elog(FATAL, "Missing or erroneous pg_hba.conf file, see postmaster log for details"); - /* Handle old style authentication. */ - if (PG_PROTOCOL_MAJOR(port->proto) == 0) - { - status = old_be_recvauth(port); - if (status != STATUS_OK) - auth_failed(port, status); - return; - } - - /* Handle new style authentication. */ switch (port->auth_method) { case uaReject: @@ -828,90 +735,3 @@ recv_and_check_password_packet(Port *port) pfree(buf.data); return result; } - - -/* - * Server demux routine for incoming authentication information for protocol - * version 0. - */ -static int -old_be_recvauth(Port *port) -{ - int status; - MsgType msgtype = (MsgType) port->proto; - - /* Handle the authentication that's offered. */ - switch (msgtype) - { - case STARTUP_KRB4_MSG: - status = map_old_to_new(port, uaKrb4, pg_krb4_recvauth(port)); - break; - - case STARTUP_KRB5_MSG: - status = map_old_to_new(port, uaKrb5, pg_krb5_recvauth(port)); - break; - - case STARTUP_MSG: - status = map_old_to_new(port, uaTrust, STATUS_OK); - break; - - case STARTUP_PASSWORD_MSG: - status = recv_and_check_passwordv0(port); - break; - - default: - elog(LOG, "Invalid startup message type: %u", msgtype); - - return STATUS_ERROR; - } - - return status; -} - - -/* - * The old style authentication has been done. Modify the result of this (eg. - * allow the connection anyway, disallow it anyway, or use the result) - * depending on what authentication we really want to use. - */ -static int -map_old_to_new(Port *port, UserAuth old, int status) -{ - switch (port->auth_method) - { - case uaMD5: - case uaCrypt: - case uaReject: -#ifdef USE_PAM - case uaPAM: -#endif /* USE_PAM */ - status = STATUS_ERROR; - break; - - case uaKrb4: - if (old != uaKrb4) - status = STATUS_ERROR; - break; - - case uaKrb5: - if (old != uaKrb5) - status = STATUS_ERROR; - break; - - case uaTrust: - status = STATUS_OK; - break; - - case uaIdent: - status = authident(port); - break; - - case uaPassword: - if (old != uaPassword) - status = STATUS_ERROR; - - break; - } - - return status; -} diff --git a/src/backend/libpq/pqformat.c b/src/backend/libpq/pqformat.c index 91c3669a1a..01f8914bdb 100644 --- a/src/backend/libpq/pqformat.c +++ b/src/backend/libpq/pqformat.c @@ -16,7 +16,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: pqformat.c,v 1.22 2002/08/08 06:32:26 ishii Exp $ + * $Id: pqformat.c,v 1.23 2002/08/29 03:22:01 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -57,41 +57,6 @@ #include #endif -#ifndef BYTE_ORDER -#error BYTE_ORDER must be defined as LITTLE_ENDIAN, BIG_ENDIAN or PDP_ENDIAN -#endif - -#if BYTE_ORDER == LITTLE_ENDIAN - -#define ntoh_s(n) n -#define ntoh_l(n) n -#define hton_s(n) n -#define hton_l(n) n - -#else -#if BYTE_ORDER == BIG_ENDIAN - -#define ntoh_s(n) (uint16)((((uint16)n & 0x00ff) << 8) | \ - (((uint16)n & 0xff00) >> 8)) -#define ntoh_l(n) (uint32)((((uint32)n & 0x000000ff) << 24) | \ - (((uint32)n & 0x0000ff00) << 8) | \ - (((uint32)n & 0x00ff0000) >> 8) | \ - (((uint32)n & 0xff000000) >> 24)) -#define hton_s(n) (ntoh_s(n)) -#define hton_l(n) (ntoh_l(n)) - -#else -#if BYTE_ORDER == PDP_ENDIAN - -#error PDP_ENDIAN macros not written yet - -#else - -#error BYTE_ORDER not defined as anything understood -#endif -#endif -#endif - /* -------------------------------- * pq_sendbyte - append a raw byte to a StringInfo buffer @@ -183,11 +148,11 @@ pq_sendint(StringInfo buf, int i, int b) appendBinaryStringInfo(buf, (char *) &n8, 1); break; case 2: - n16 = ((PG_PROTOCOL_MAJOR(FrontendProtocol) == 0) ? hton_s(i) : htons((uint16) i)); + n16 = htons((uint16) i); appendBinaryStringInfo(buf, (char *) &n16, 2); break; case 4: - n32 = ((PG_PROTOCOL_MAJOR(FrontendProtocol) == 0) ? hton_l(i) : htonl((uint32) i)); + n32 = htonl((uint32) i); appendBinaryStringInfo(buf, (char *) &n32, 4); break; default: @@ -261,13 +226,11 @@ pq_getint(int *result, int b) break; case 2: status = pq_getbytes((char *) &n16, 2); - *result = (int) ((PG_PROTOCOL_MAJOR(FrontendProtocol) == 0) ? - ntoh_s(n16) : ntohs(n16)); + *result = (int) (ntohs(n16)); break; case 4: status = pq_getbytes((char *) &n32, 4); - *result = (int) ((PG_PROTOCOL_MAJOR(FrontendProtocol) == 0) ? - ntoh_l(n32) : ntohl(n32)); + *result = (int) (ntohl(n32)); break; default: diff --git a/src/include/libpq/libpq-be.h b/src/include/libpq/libpq-be.h index 1a2382026c..e9d906d06a 100644 --- a/src/include/libpq/libpq-be.h +++ b/src/include/libpq/libpq-be.h @@ -11,7 +11,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: libpq-be.h,v 1.33 2002/08/18 03:03:26 momjian Exp $ + * $Id: libpq-be.h,v 1.34 2002/08/29 03:22:01 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -29,17 +29,8 @@ #endif -/* Protocol v0 password packet. */ - -typedef struct PasswordPacketV0 -{ - uint32 unused; - char data[288]; /* User and password as strings. */ -} PasswordPacketV0; - - /* - * This is used by the postmaster in its communication with frontends. It is + * This is used by the postmaster in its communication with frontends. It * contains all state information needed during this communication before the * backend is run. */ diff --git a/src/include/libpq/pqcomm.h b/src/include/libpq/pqcomm.h index a2b6961d5b..2bd0d3758e 100644 --- a/src/include/libpq/pqcomm.h +++ b/src/include/libpq/pqcomm.h @@ -9,7 +9,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: pqcomm.h,v 1.68 2002/08/27 16:21:51 momjian Exp $ + * $Id: pqcomm.h,v 1.69 2002/08/29 03:22:01 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -93,7 +93,7 @@ typedef union SockAddr /* The earliest and latest frontend/backend protocol version supported. */ -#define PG_PROTOCOL_EARLIEST PG_PROTOCOL(0,0) +#define PG_PROTOCOL_EARLIEST PG_PROTOCOL(1,0) #define PG_PROTOCOL_LATEST PG_PROTOCOL(2,0) /* @@ -127,6 +127,9 @@ typedef uint32 PacketLen; typedef uint32 ProtocolVersion; /* Fe/Be protocol version number */ +typedef ProtocolVersion MsgType; + + typedef struct StartupPacket { ProtocolVersion protoVersion; /* Protocol version */ @@ -153,16 +156,6 @@ extern bool Db_user_namespace; typedef uint32 AuthRequest; -/* This next section is to maintain compatibility with protocol v0.0. */ - -#define STARTUP_MSG 7 /* Initialise a connection */ -#define STARTUP_KRB4_MSG 10 /* krb4 session follows */ -#define STARTUP_KRB5_MSG 11 /* krb5 session follows */ -#define STARTUP_PASSWORD_MSG 14 /* Password follows */ - -typedef ProtocolVersion MsgType; - - /* A client can also send a cancel-current-operation request to the postmaster. * This is uglier than sending it directly to the client's backend, but it * avoids depending on out-of-band communication facilities. diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c index cd5cd7dce5..317cf772a7 100644 --- a/src/interfaces/libpq/fe-auth.c +++ b/src/interfaces/libpq/fe-auth.c @@ -10,7 +10,7 @@ * exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes). * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.68 2002/07/20 05:43:31 momjian Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.69 2002/08/29 03:22:01 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -63,6 +63,11 @@ * common definitions for generic fe/be routines */ +#define STARTUP_MSG 7 /* Initialise a connection */ +#define STARTUP_KRB4_MSG 10 /* krb4 session follows */ +#define STARTUP_KRB5_MSG 11 /* krb5 session follows */ +#define STARTUP_PASSWORD_MSG 14 /* Password follows */ + struct authsvc { const char *name; /* service nickname (for command line) */ -- 2.11.0