Commit Diff


commit - b52f2785ca72c2a5e335e05fe50167f0cc149125
commit + 421c9a869ac123f10541b043bb90c9732c53a182
blob - 9466ccb87c208d397e9c01ec070331d586bc5321
blob + 058ec505a4fc0414c12fdbc283f639e34db14327
--- opensmtpd.c
+++ opensmtpd.c
@@ -67,6 +67,8 @@ static void osmtpd_onearg(struct osmtpd_callback *, st
     char *, char *);
 static void osmtpd_connect(struct osmtpd_callback *, struct osmtpd_ctx *,
     char *, char *);
+static void osmtpd_identify(struct osmtpd_callback *, struct osmtpd_ctx *,
+    char *, char *);
 static void osmtpd_link_connect(struct osmtpd_callback *, struct osmtpd_ctx *,
     char *, char *);
 static void osmtpd_link_disconnect(struct osmtpd_callback *,
@@ -113,7 +115,7 @@ static struct osmtpd_callback osmtpd_callbacks[] = {
 	    OSMTPD_TYPE_FILTER,
 	    OSMTPD_PHASE_HELO,
 	    1,
-	    osmtpd_onearg,
+	    osmtpd_identify,
 	    NULL,
 	    0,
 	    0
@@ -122,7 +124,7 @@ static struct osmtpd_callback osmtpd_callbacks[] = {
 	    OSMTPD_TYPE_FILTER,
 	    OSMTPD_PHASE_EHLO,
 	    1,
-	    osmtpd_onearg,
+	    osmtpd_identify,
 	    NULL,
 	    0,
 	    0
@@ -899,6 +901,7 @@ osmtpd_run(void)
 	int registered = 0;
 	/* Doesn't leak, since it needs to exists until the application ends. */
 	struct io *io_stdin;
+	struct osmtpd_callback *hidenity, *eidentity, *ridentity;
 
 	event_init();
 
@@ -928,8 +931,25 @@ osmtpd_run(void)
 				    OSMTPD_PHASE_TX_COMMIT,
 				    osmtpd_callbacks[i].incoming, 0, NULL);
 			}
+			if (osmtpd_callbacks[i].type == OSMTPD_TYPE_FILTER &&
+			    osmtpd_callbacks[i].phase == OSMTPD_PHASE_HELO)
+				hidenity = &(osmtpd_callbacks[i]);
+			if (osmtpd_callbacks[i].type == OSMTPD_TYPE_FILTER &&
+			    osmtpd_callbacks[i].phase == OSMTPD_PHASE_EHLO)
+				eidentity = &(osmtpd_callbacks[i]);
+			if (osmtpd_callbacks[i].type == OSMTPD_TYPE_REPORT &&
+			    osmtpd_callbacks[i].phase ==
+			    OSMTPD_PHASE_LINK_IDENTIFY &&
+			    osmtpd_callbacks[i].incoming == 1)
+				ridentity = &(osmtpd_callbacks[i]);
 		}
 	}
+	if (ridentity->storereport) {
+		if (hidenity->doregister)
+			hidenity->storereport = 1;
+		if (eidentity->doregister)
+			eidentity->storereport = 1;
+	}
 	for (i = 0; i < NITEMS(osmtpd_callbacks); i++) {
 		if (osmtpd_callbacks[i].doregister) {
 			if (osmtpd_callbacks[i].cb != NULL)
@@ -1205,6 +1225,22 @@ osmtpd_connect(struct osmtpd_callback *cb, struct osmt
 }
 
 static void
+osmtpd_identify(struct osmtpd_callback *cb, struct osmtpd_ctx *ctx,
+    char *identity, char *linedup)
+{
+	void (*f)(struct osmtpd_ctx *, const char *);
+
+	if (cb->storereport) {
+		free(ctx->identity);
+		if ((ctx->identity = strdup(identity)) == NULL)
+			osmtpd_err(1, "strdup");
+	}
+
+	f = cb->cb;
+	f(ctx, identity);
+}
+
+static void
 osmtpd_link_connect(struct osmtpd_callback *cb, struct osmtpd_ctx *ctx,
     char *params, char *linedup)
 {
@@ -1288,6 +1324,7 @@ osmtpd_link_greeting(struct osmtpd_callback *cb, struc
 	void (*f)(struct osmtpd_ctx *, const char *);
 
 	if (cb->storereport) {
+		free(ctx->greeting.identity);
 		if ((ctx->greeting.identity = strdup(identity)) == NULL)
 			osmtpd_err(1, NULL);
 	}
@@ -1303,6 +1340,7 @@ osmtpd_link_identify(struct osmtpd_callback *cb, struc
 	void (*f)(struct osmtpd_ctx *, const char *);
 
 	if (cb->storereport) {
+		free(ctx->identity);
 		if ((ctx->identity = strdup(identity)) == NULL)
 			osmtpd_err(1, NULL);
 	}