commit 22f0536: [Minor] Add more debugging to milter protocol output

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Mar 4 11:21:03 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-03-04 11:14:40 +0000
URL: https://github.com/rspamd/rspamd/commit/22f053689ae2c3bf6ca5f6b27410ac4413c4e7f8 (HEAD -> master)

[Minor] Add more debugging to milter protocol output

---
 src/libserver/milter.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/libserver/milter.c b/src/libserver/milter.c
index 6e4a03e4d..91e87c061 100644
--- a/src/libserver/milter.c
+++ b/src/libserver/milter.c
@@ -235,6 +235,7 @@ static void
 rspamd_milter_on_protocol_error (struct rspamd_milter_session *session,
 		struct rspamd_milter_private *priv, GError *err)
 {
+	msg_debug_milter ("protocol error: %e", err);
 	priv->state = RSPAMD_MILTER_WANNA_DIE;
 	REF_RETAIN (session);
 	priv->err_cb (priv->fd, session, priv->ud, err);
@@ -1189,6 +1190,7 @@ rspamd_milter_send_action (struct rspamd_milter_session *session,
 	case RSPAMD_MILTER_REJECT:
 	case RSPAMD_MILTER_TEMPFAIL:
 		/* No additional arguments */
+		msg_debug_milter ("send %c command", cmd);
 		SET_COMMAND (cmd, 0, reply, pos);
 		break;
 	case RSPAMD_MILTER_QUARANTINE:
@@ -1199,6 +1201,7 @@ rspamd_milter_send_action (struct rspamd_milter_session *session,
 		}
 
 		len = strlen (reason);
+		msg_debug_milter ("send quarantine action %s", reason);
 		SET_COMMAND (cmd, len + 1, reply, pos);
 		memcpy (pos, reason, len + 1);
 		break;
@@ -1207,6 +1210,7 @@ rspamd_milter_send_action (struct rspamd_milter_session *session,
 		value = va_arg (ap, GString *);
 
 		/* Name and value must be zero terminated */
+		msg_debug_milter ("add header command - \"%v\"=\"%v\"", name, value);
 		SET_COMMAND (cmd, name->len + value->len + 2, reply, pos);
 		memcpy (pos, name->str, name->len + 1);
 		pos += name->len + 1;
@@ -1214,13 +1218,16 @@ rspamd_milter_send_action (struct rspamd_milter_session *session,
 		break;
 	case RSPAMD_MILTER_CHGHEADER:
 	case RSPAMD_MILTER_INSHEADER:
-		idx = htonl (va_arg (ap, guint32));
+		idx = va_arg (ap, guint32);
 		name = va_arg (ap, GString *);
 		value = va_arg (ap, GString *);
 
+		msg_debug_milter ("change/insert header command pos = %d- \"%v\"=\"%v\"",
+				idx, name, value);
 		/* Name and value must be zero terminated */
 		SET_COMMAND (cmd, name->len + value->len + 2 + sizeof (guint32),
 				reply, pos);
+		idx = htonl (idx);
 		memcpy (pos, &idx, sizeof (idx));
 		pos += sizeof (idx);
 		memcpy (pos, name->str, name->len + 1);
@@ -1233,14 +1240,20 @@ rspamd_milter_send_action (struct rspamd_milter_session *session,
 	case RSPAMD_MILTER_CHGFROM:
 		/* Single GString * argument */
 		value = va_arg (ap, GString *);
+		msg_debug_milter ("command %c; value=%v", cmd, value);
 		SET_COMMAND (cmd, value->len + 1, reply, pos);
 		memcpy (pos, value->str, value->len + 1);
 		break;
 	case RSPAMD_MILTER_OPTNEG:
-		ver = htonl (va_arg (ap, guint32));
-		actions = htonl (va_arg (ap, guint32));
-		protocol = htonl (va_arg (ap, guint32));
-
+		ver = va_arg (ap, guint32);
+		actions = va_arg (ap, guint32);
+		protocol = va_arg (ap, guint32);
+
+		msg_debug_milter ("optneg reply: ver=%d, actions=%d, protocol=%d",
+				ver, actions, protocol);
+		ver = htonl (ver);
+		actions = htonl (actions);
+		protocol = htonl (protocol);
 		SET_COMMAND (cmd, sizeof (guint32) * 3, reply, pos);
 		memcpy (pos, &ver, sizeof (ver));
 		pos += sizeof (ver);


More information about the Commits mailing list