agora inbox for [email protected]  
help / color / mirror / Atom feed
From: Jelte Fennema-Nio <[email protected]>
Subject: [PATCH v3 7/8] libpq: Trace server Authentication messages in detail
Date: Thu, 13 Jun 2024 21:53:03 +0200

The tracing logic for Authentication messages comming from the server
was incomplete. It previously only listed the number in the
authentication type field of the message. This now starts to correctly
list the name of the message and its contents based on that type field.
---
 src/interfaces/libpq/fe-trace.c | 55 ++++++++++++++++++++++++++++++---
 1 file changed, 51 insertions(+), 4 deletions(-)

diff --git a/src/interfaces/libpq/fe-trace.c b/src/interfaces/libpq/fe-trace.c
index 3bb62397ec..5fee6580ed 100644
--- a/src/interfaces/libpq/fe-trace.c
+++ b/src/interfaces/libpq/fe-trace.c
@@ -472,10 +472,57 @@ pqTraceOutput_Query(FILE *f, const char *message, int *cursor)
 }
 
 static void
-pqTraceOutput_Authentication(FILE *f, const char *message, int *cursor)
+pqTraceOutput_Authentication(FILE *f, const char *message, int *cursor, int length, bool regress)
 {
-	fprintf(f, "Authentication\t");
-	pqTraceOutputInt32(f, message, cursor, false);
+	int			authType = 0;
+
+	memcpy(&authType, message + *cursor, 4);
+	authType = (int) pg_ntoh32(authType);
+	*cursor += 4;
+	switch (authType)
+	{
+		case AUTH_REQ_OK:
+			fprintf(f, "AuthenticationOk");
+			break;
+		case AUTH_REQ_KRB5:
+			fprintf(f, "AuthenticationKerberosV5");
+			break;
+		case AUTH_REQ_PASSWORD:
+			fprintf(f, "AuthenticationCleartextPassword");
+			break;
+		case AUTH_REQ_MD5:
+			fprintf(f, "AuthenticationMD5Password");
+			break;
+		case AUTH_REQ_GSS:
+			fprintf(f, "AuthenticationGSS");
+			break;
+		case AUTH_REQ_GSS_CONT:
+			fprintf(f, "AuthenticationGSSContinue");
+			pqTraceOutputNchar(f, length - *cursor + 1, message, cursor, regress);
+			break;
+		case AUTH_REQ_SSPI:
+			fprintf(f, "AuthenticationSSPI");
+			break;
+		case AUTH_REQ_SASL:
+			fprintf(f, "AuthenticationSASL");
+			while (message[*cursor] != '\0')
+			{
+				pqTraceOutputString(f, message, cursor, false);
+			}
+			pqTraceOutputString(f, message, cursor, false);
+
+			break;
+		case AUTH_REQ_SASL_CONT:
+			fprintf(f, "AuthenticationSASLContinue");
+			pqTraceOutputNchar(f, length - *cursor + 1, message, cursor, regress);
+			break;
+		case AUTH_REQ_SASL_FIN:
+			fprintf(f, "AuthenticationSASLFinal");
+			pqTraceOutputNchar(f, length - *cursor + 1, message, cursor, regress);
+			break;
+		default:
+			fprintf(f, "Unknown authentication message %d", authType);
+	}
 }
 
 static void
@@ -714,7 +761,7 @@ pqTraceOutputMessage(PGconn *conn, const char *message, bool toServer)
 			pqTraceOutput_Query(conn->Pfdebug, message, &logCursor);
 			break;
 		case PqMsg_AuthenticationRequest:
-			pqTraceOutput_Authentication(conn->Pfdebug, message, &logCursor);
+			pqTraceOutput_Authentication(conn->Pfdebug, message, &logCursor, length, regress);
 			break;
 		case PqMsg_PortalSuspended:
 			fprintf(conn->Pfdebug, "PortalSuspended");
-- 
2.39.2


--hqh5ifezvx5otzff
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
	filename="v3-0008-libpq-Trace-NegotiateProtocolVersion-correctly.patch"



view thread (2+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [PATCH v3 7/8] libpq: Trace server Authentication messages in detail
  In-Reply-To: <no-message-id-59020@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox