8000 libpq: Trace responses to SSLRequest and GSSENCRequest · macdice/postgres@a5c6b8f · GitHub
[go: up one dir, main page]

Skip to content

Commit a5c6b8f

Browse files
committed
libpq: Trace responses to SSLRequest and GSSENCRequest
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
1 parent 5304fec commit a5c6b8f

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3493,11 +3493,17 @@ PQconnectPoll(PGconn *conn)
34933493
}
34943494
if (SSLok == 'S')
34953495
{
3496+
if (conn->Pfdebug)
3497+
pqTraceOutputCharResponse(conn, "SSLResponse",
3498+
SSLok);
34963499
/* mark byte consumed */
34973500
conn->inStart = conn->inCursor;
34983501
}
34993502
else if (SSLok == 'N')
35003503
{
3504+
if (conn->Pfdebug)
3505+
pqTraceOutputCharResponse(conn, "SSLResponse",
3506+
SSLok);
35013507
/* mark byte consumed */
35023508
conn->inStart = conn->inCursor;
35033509

@@ -3635,6 +3641,10 @@ PQconnectPoll(PGconn *conn)
36353641

36363642
if (gss_ok == 'N')
36373643
{
3644+
if (conn->Pfdebug)
3645+
pqTraceOutputCharResponse(conn, "GSSENCResponse",
3646+
gss_ok);
3647+
36383648
/*
36393649
* The connection is still valid, so if it's OK to
36403650
* continue without GSS, we can proceed using this
@@ -3648,6 +3658,10 @@ PQconnectPoll(PGconn *conn)
36483658
gss_ok);
36493659
goto error_return;
36503660
}
3661+
3662+
if (conn->Pfdebug)
3663+
pqTraceOutputCharResponse(conn, "GSSENCResponse",
3664+
gss_ok);
36513665
}
36523666

36533667
/* Begin or continue GSSAPI negotiation */

src/interfaces/libpq/fe-trace.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,3 +840,23 @@ pqTraceOutputNoTypeByteMessage(PGconn *conn, const char *message)
840840

841841
fputc('\n', conn->Pfdebug);
842842
}
843+
844+
/*
845+
* Trace a single-byte backend response received for a known request
846+
* type the frontend previously sent. Only useful for the simplest of
847+
* FE/BE interaction workflows such as SSL/GSS encryption requests.
848+
*/
849+
void
850+
pqTraceOutputCharResponse(PGconn *conn, const char *responseType,
851+
char response)
852+
{
853+
if ((conn->traceFlags & PQTRACE_SUPPRESS_TIMESTAMPS) == 0)
854+
{
855+
char timestr[128];
856+
857+
pqTraceFormatTimestamp(timestr, sizeof(timestr));
858+
fprintf(conn->Pfdebug, "%s\t", timestr);
859+
}
860+
861+
fprintf(conn->Pfdebug, "B\t1\t%s\t %c\n", responseType, response);
862+
}

src/interfaces/libpq/libpq-int.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,8 @@ extern ssize_t pg_GSS_read(PGconn *conn, void *ptr, size_t len);
889889
extern void pqTraceOutputMessage(PGconn *conn, const char *message,
890890
bool toServer);
891891
extern void pqTraceOutputNoTypeByteMessage(PGconn *conn, const char *message);
892+
extern void pqTraceOutputCharResponse(PGconn *conn, const char *responseType,
893+
char response);
892894

893895
/* === miscellaneous macros === */
894896

0 commit comments

Comments
 (0)
0