Skip to content

Commit 81e7708

Browse files
committed
Since GSSAPI and SSPI authentication don't work in protocol version 2,
issue a helpful error message instead of sending unparsable garbage. (It is clearly a design error that this doesn't work, but fixing it is not worth the trouble at this point.) Per discussion.
1 parent 9b43c24 commit 81e7708

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

src/backend/libpq/auth.c

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/libpq/auth.c,v 1.163 2008/01/30 04:11:19 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/libpq/auth.c,v 1.164 2008/02/08 17:58:46 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -307,12 +307,13 @@ pg_krb5_recvauth(Port *port)
307307
}
308308
#endif /* KRB5 */
309309

310-
#ifdef ENABLE_GSS
311310
/*----------------------------------------------------------------
312311
* GSSAPI authentication system
313312
*----------------------------------------------------------------
314313
*/
315314

315+
#ifdef ENABLE_GSS
316+
316317
#if defined(HAVE_GSSAPI_H)
317318
#include <gssapi.h>
318319
#else
@@ -389,6 +390,19 @@ pg_GSS_recvauth(Port *port)
389390
StringInfoData buf;
390391
gss_buffer_desc gbuf;
391392

393+
/*
394+
* GSS auth is not supported for protocol versions before 3, because it
395+
* relies on the overall message length word to determine the GSS payload
396+
* size in AuthenticationGSSContinue and PasswordMessage messages.
397+
* (This is, in fact, a design error in our GSS support, because protocol
398+
* messages are supposed to be parsable without relying on the length
399+
* word; but it's not worth changing it now.)
400+
*/
401+
if (PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
402+
ereport(FATAL,
403+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
404+
errmsg("GSSAPI is not supported in protocol version 2")));
405+
392406
if (pg_krb_server_keyfile && strlen(pg_krb_server_keyfile) > 0)
393407
{
394408
/*
@@ -594,7 +608,9 @@ pg_GSS_recvauth(Port *port)
594608

595609
return STATUS_OK;
596610
}
611+
597612
#else /* no ENABLE_GSS */
613+
598614
static int
599615
pg_GSS_recvauth(Port *port)
600616
{
@@ -603,9 +619,20 @@ pg_GSS_recvauth(Port *port)
603619
errmsg("GSSAPI not implemented on this server")));
604620
return STATUS_ERROR;
605621
}
622+
606623
#endif /* ENABLE_GSS */
607624

625+
/*----------------------------------------------------------------
626+
* SSPI authentication system
627+
*----------------------------------------------------------------
628+
*/
629+
608630
#ifdef ENABLE_SSPI
631+
632+
typedef SECURITY_STATUS
633+
(WINAPI * QUERY_SECURITY_CONTEXT_TOKEN_FN) (
634+
PCtxtHandle, void **);
635+
609636
static void
610637
pg_SSPI_error(int severity, char *errmsg, SECURITY_STATUS r)
611638
{
@@ -621,10 +648,6 @@ pg_SSPI_error(int severity, char *errmsg, SECURITY_STATUS r)
621648
errdetail("%s (%x)", sysmsg, (unsigned int) r)));
622649
}
623650

624-
typedef SECURITY_STATUS
625-
(WINAPI * QUERY_SECURITY_CONTEXT_TOKEN_FN) (
626-
PCtxtHandle, void **);
627-
628651
static int
629652
pg_SSPI_recvauth(Port *port)
630653
{
@@ -651,6 +674,18 @@ pg_SSPI_recvauth(Port *port)
651674
HMODULE secur32;
652675
QUERY_SECURITY_CONTEXT_TOKEN_FN _QuerySecurityContextToken;
653676

677+
/*
678+
* SSPI auth is not supported for protocol versions before 3, because it
679+
* relies on the overall message length word to determine the SSPI payload
680+
* size in AuthenticationGSSContinue and PasswordMessage messages.
681+
* (This is, in fact, a design error in our SSPI support, because protocol
682+
* messages are supposed to be parsable without relying on the length
683+
* word; but it's not worth changing it now.)
684+
*/
685+
if (PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
686+
ereport(FATAL,
687+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
688+
errmsg("SSPI is not supported in protocol version 2")));
654689

655690
/*
656691
* Acquire a handle to the server credentials.
@@ -878,7 +913,9 @@ pg_SSPI_recvauth(Port *port)
878913

879914
return STATUS_OK;
880915
}
916+
881917
#else /* no ENABLE_SSPI */
918+
882919
static int
883920
pg_SSPI_recvauth(Port *port)
884921
{
@@ -887,6 +924,7 @@ pg_SSPI_recvauth(Port *port)
887924
errmsg("SSPI not implemented on this server")));
888925
return STATUS_ERROR;
889926
}
927+
890928
#endif /* ENABLE_SSPI */
891929

892930

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy