Skip to content

Commit 821c072

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 dea11bd commit 821c072

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
@@ -807,16 +807,22 @@ pg_SSPI_recvauth(Port *port)
807807
gettext_noop("could not accept SSPI security context"), r);
808808
}
809809

810+
/*
811+
* Overwrite the current context with the one we just received.
812+
* If sspictx is NULL it was the first loop and we need to allocate
813+
* a buffer for it. On subsequent runs, we can just overwrite the
814+
* buffer contents since the size does not change.
815+
*/
810816
if (sspictx == NULL)
811817
{
812818
sspictx = malloc(sizeof(CtxtHandle));
813819
if (sspictx == NULL)
814820
ereport(ERROR,
815821
(errmsg("out of memory")));
816-
817-
memcpy(sspictx, &newctx, sizeof(CtxtHandle));
818822
}
819823

824+
memcpy(sspictx, &newctx, sizeof(CtxtHandle));
825+
820826
if (r == SEC_I_CONTINUE_NEEDED)
821827
elog(DEBUG4, "SSPI continue needed");
822828

0 commit comments

Comments
 (0)