Skip to content

Commit d662e39

Browse files
committed
Fix SSPI login when multiple roundtrips are required
This fixes SSPI login failures showing "The function requested is not supported", often showing up when connecting to localhost. The reason was not properly updating the SSPI handle when multiple roundtrips were required to complete the authentication sequence. Report and analysis by Ahmed Shinwari, patch by Magnus Hagander
1 parent 75f386d commit d662e39

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/backend/libpq/auth.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,16 +1366,22 @@ pg_SSPI_recvauth(Port *port)
13661366
_("could not accept SSPI security context"), r);
13671367
}
13681368

1369+
/*
1370+
* Overwrite the current context with the one we just received.
1371+
* If sspictx is NULL it was the first loop and we need to allocate
1372+
* a buffer for it. On subsequent runs, we can just overwrite the
1373+
* buffer contents since the size does not change.
1374+
*/
13691375
if (sspictx == NULL)
13701376
{
13711377
sspictx = malloc(sizeof(CtxtHandle));
13721378
if (sspictx == NULL)
13731379
ereport(ERROR,
13741380
(errmsg("out of memory")));
1375-
1376-
memcpy(sspictx, &newctx, sizeof(CtxtHandle));
13771381
}
13781382

1383+
memcpy(sspictx, &newctx, sizeof(CtxtHandle));
1384+
13791385
if (r == SEC_I_CONTINUE_NEEDED)
13801386
elog(DEBUG4, "SSPI continue needed");
13811387

0 commit comments

Comments
 (0)