]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
libpq: Trace responses to SSLRequest and GSSENCRequest
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 14 Aug 2024 18:53:55 +0000 (14:53 -0400)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 14 Aug 2024 18:53:55 +0000 (14:53 -0400)
Since these are single bytes instead of v2 or v3 messages they need
custom tracing logic.  These "messages" don't even have official names
in the protocol specification, so I (Jelte) called them SSLResponse and
GSSENCResponse here.

Author: Jelte Fennema-Nio <postgres@jeltef.nl>
Discussion: https://postgr.es/m/CAGECzQSoPHtZ4xe0raJ6FYSEiPPS+YWXBhOGo+Y1YecLgknF3g@mail.gmail.com

src/interfaces/libpq/fe-connect.c
src/interfaces/libpq/fe-trace.c
src/interfaces/libpq/libpq-int.h

index 360d9a454760ffe2a1fed1b3451586ef6bc08e71..a5055271ae37eba1478a1153febeea1c72855511 100644 (file)
@@ -3493,11 +3493,17 @@ keep_going:                                             /* We will come back to here until there is
                                        }
                                        if (SSLok == 'S')
                                        {
+                                               if (conn->Pfdebug)
+                                                       pqTraceOutputCharResponse(conn, "SSLResponse",
+                                                                                                         SSLok);
                                                /* mark byte consumed */
                                                conn->inStart = conn->inCursor;
                                        }
                                        else if (SSLok == 'N')
                                        {
+                                               if (conn->Pfdebug)
+                                                       pqTraceOutputCharResponse(conn, "SSLResponse",
+                                                                                                         SSLok);
                                                /* mark byte consumed */
                                                conn->inStart = conn->inCursor;
 
@@ -3635,6 +3641,10 @@ keep_going:                                              /* We will come back to here until there is
 
                                        if (gss_ok == 'N')
                                        {
+                                               if (conn->Pfdebug)
+                                                       pqTraceOutputCharResponse(conn, "GSSENCResponse",
+                                                                                                         gss_ok);
+
                                                /*
                                                 * The connection is still valid, so if it's OK to
                                                 * continue without GSS, we can proceed using this
@@ -3648,6 +3658,10 @@ keep_going:                                              /* We will come back to here until there is
                                                                                                gss_ok);
                                                goto error_return;
                                        }
+
+                                       if (conn->Pfdebug)
+                                               pqTraceOutputCharResponse(conn, "GSSENCResponse",
+                                                                                                 gss_ok);
                                }
 
                                /* Begin or continue GSSAPI negotiation */
index 367b322b992f0ef34de45e1f47ebe43e59b6f547..3527b9f0f5dff6f8587791cb15c34c2c9ccffb8c 100644 (file)
@@ -840,3 +840,23 @@ pqTraceOutputNoTypeByteMessage(PGconn *conn, const char *message)
 
        fputc('\n', conn->Pfdebug);
 }
+
+/*
+ * Trace a single-byte backend response received for a known request
+ * type the frontend previously sent.  Only useful for the simplest of
+ * FE/BE interaction workflows such as SSL/GSS encryption requests.
+ */
+void
+pqTraceOutputCharResponse(PGconn *conn, const char *responseType,
+                                                 char response)
+{
+       if ((conn->traceFlags & PQTRACE_SUPPRESS_TIMESTAMPS) == 0)
+       {
+               char            timestr[128];
+
+               pqTraceFormatTimestamp(timestr, sizeof(timestr));
+               fprintf(conn->Pfdebug, "%s\t", timestr);
+       }
+
+       fprintf(conn->Pfdebug, "B\t1\t%s\t %c\n", responseType, response);
+}
index 03e4da40ba1d98c79c77e3c7fc2e29aaf29c3f48..d97b595c97f3f41a62fce9a01fe8796fc1a6a35e 100644 (file)
@@ -889,6 +889,8 @@ extern ssize_t pg_GSS_read(PGconn *conn, void *ptr, size_t len);
 extern void pqTraceOutputMessage(PGconn *conn, const char *message,
                                                                 bool toServer);
 extern void pqTraceOutputNoTypeByteMessage(PGconn *conn, const char *message);
+extern void pqTraceOutputCharResponse(PGconn *conn, const char *responseType,
+                                                                         char response);
 
 /* === miscellaneous macros === */