mirror of
https://github.com/postgres/postgres.git
synced 2025-07-14 08:21:07 +03:00
Fix assorted issues in backend's GSSAPI encryption support.
Unrecoverable errors detected by GSSAPI encryption can't just be reported with elog(ERROR) or elog(FATAL), because attempting to send the error report to the client is likely to lead to infinite recursion or loss of protocol sync. Instead make this code do what the SSL encryption code has long done, which is to just report any such failure to the server log (with elevel COMMERROR), then pretend we've lost the connection by returning errno = ECONNRESET. Along the way, fix confusion about whether message translation is done by pg_GSS_error() or its callers (the latter should do it), and make the backend version of that function work more like the frontend version. Avoid allocating the port->gss struct until it's needed; we surely don't need to allocate it in the postmaster. Improve logging of "connection authorized" messages with GSS enabled. (As part of this, I back-patched the code changes from dc11f31a1.) Make BackendStatusShmemSize() account for the GSS-related space that will be allocated by CreateSharedBackendStatus(). This omission could possibly cause out-of-shared-memory problems with very high max_connections settings. Remove arbitrary, pointless restriction that only GSS authentication can be used on a GSS-encrypted connection. Improve documentation; notably, document the fact that libpq now prefers GSS encryption over SSL encryption if both are possible. Per report from Mikael Gustavsson. Back-patch to v12 where this code was introduced. Discussion: https://postgr.es/m/e5b0b6ed05764324a2f3fe7acfc766d5@smhi.se
This commit is contained in:
@ -256,30 +256,27 @@ socket_close(int code, Datum arg)
|
||||
/* Nothing to do in a standalone backend, where MyProcPort is NULL. */
|
||||
if (MyProcPort != NULL)
|
||||
{
|
||||
#if defined(ENABLE_GSS) || defined(ENABLE_SSPI)
|
||||
#ifdef ENABLE_GSS
|
||||
OM_uint32 min_s;
|
||||
|
||||
/*
|
||||
* Shutdown GSSAPI layer. This section does nothing when interrupting
|
||||
* BackendInitialize(), because pg_GSS_recvauth() makes first use of
|
||||
* "ctx" and "cred".
|
||||
*
|
||||
* Note that we don't bother to free MyProcPort->gss, since we're
|
||||
* about to exit anyway.
|
||||
*/
|
||||
if (MyProcPort->gss->ctx != GSS_C_NO_CONTEXT)
|
||||
gss_delete_sec_context(&min_s, &MyProcPort->gss->ctx, NULL);
|
||||
if (MyProcPort->gss)
|
||||
{
|
||||
OM_uint32 min_s;
|
||||
|
||||
if (MyProcPort->gss->cred != GSS_C_NO_CREDENTIAL)
|
||||
gss_release_cred(&min_s, &MyProcPort->gss->cred);
|
||||
if (MyProcPort->gss->ctx != GSS_C_NO_CONTEXT)
|
||||
gss_delete_sec_context(&min_s, &MyProcPort->gss->ctx, NULL);
|
||||
|
||||
if (MyProcPort->gss->cred != GSS_C_NO_CREDENTIAL)
|
||||
gss_release_cred(&min_s, &MyProcPort->gss->cred);
|
||||
}
|
||||
#endif /* ENABLE_GSS */
|
||||
|
||||
/*
|
||||
* GSS and SSPI share the port->gss struct. Since nowhere else does a
|
||||
* postmaster child free this, doing so is safe when interrupting
|
||||
* BackendInitialize().
|
||||
*/
|
||||
free(MyProcPort->gss);
|
||||
#endif /* ENABLE_GSS || ENABLE_SSPI */
|
||||
|
||||
/*
|
||||
* Cleanly shut down SSL layer. Nowhere else does a postmaster child
|
||||
* call this, so this is safe when interrupting BackendInitialize().
|
||||
|
Reference in New Issue
Block a user