Commit Diff


commit - 04c09316bee33648590a27c3c0d9ecdbfa9a0ba9
commit + 79ef769fe9b996ba9e1c27eaa688876757e101dc
blob - bec9941fd8c17a41dac272e1b0042f669a8e5577
blob + 9341020157c935717ea17bb4a8f7fee78fc277db
--- main.c
+++ main.c
@@ -28,7 +28,6 @@
 
 struct admd_message {
 	int foundmatch;
-	int err;
 	int inheader;
 	int parsing_headers;
 	char **cache;
@@ -40,9 +39,8 @@ void usage(void);
 void admd_conf(const char *, const char *);
 void *admd_message_new(struct osmtpd_ctx *);
 void admd_message_free(struct osmtpd_ctx *, void *);
-void admd_dataline(struct osmtpd_ctx *, const char *);
-void admd_commit(struct osmtpd_ctx *);
-void admd_err(struct admd_message *, const char *);
+int admd_dataline(struct osmtpd_ctx *, const char *);
+int admd_commit(struct osmtpd_ctx *);
 void admd_cache(struct admd_message *, const char *);
 const char *admd_authservid(struct admd_message *);
 void admd_freecache(struct admd_message *);
@@ -110,7 +108,6 @@ admd_message_new(struct osmtpd_ctx *ctx)
 		osmtpd_err(1, "malloc");
 
 	msg->foundmatch = 0;
-	msg->err = 0;
 	msg->inheader = 0;
 	msg->parsing_headers = 1;
 	msg->cache = NULL;
@@ -129,7 +126,7 @@ admd_message_free(struct osmtpd_ctx *ctx, void *data)
 	free(msg);
 }
 
-void
+int
 admd_dataline(struct osmtpd_ctx *ctx, const char *orig)
 {
 	struct admd_message *msg = ctx->local_message;
@@ -137,12 +134,6 @@ admd_dataline(struct osmtpd_ctx *ctx, const char *orig
 	const char *msgauthid;
 	size_t i;
 
-	if (msg->err) {
-		if (line[0] == '.' && line[1] =='\0')
-			osmtpd_filter_dataline(ctx, ".");
-		return;
-	}
-		
 	if (line[0] == '\0')
 		msg->parsing_headers = 0;
 	if (line[0] == '.')
@@ -152,7 +143,7 @@ admd_dataline(struct osmtpd_ctx *ctx, const char *orig
 			if (msg->inheader) {
 				msgauthid = admd_authservid(msg);
 				if (msgauthid == NULL && errno != EINVAL)
-					return;
+					return 0;
 				if (msgauthid != NULL &&
 				    strcmp(msgauthid, authservid) == 0)
 					msg->foundmatch = 1;
@@ -172,28 +163,24 @@ admd_dataline(struct osmtpd_ctx *ctx, const char *orig
 			if (line++[0] == ':') {
 				msg->inheader = 1;
 				admd_cache(msg, orig);
-				return;
+				return 0;
 			}
 		} else if (msg->inheader &&
 		    (line[0] == ' ' || line[0] == '\t')) {
 			admd_cache(msg, orig);
-			return;
+			return 0;
 		}
 	}
 
 	osmtpd_filter_dataline(ctx, "%s", orig);
-	return;
+	return 0;
 }
 
-void
+int
 admd_commit(struct osmtpd_ctx *ctx)
 {
 	struct admd_message *msg = ctx->local_message;
 
-	if (msg->err) {
-		osmtpd_filter_disconnect(ctx, "Internal server error");
-		return;
-	}
 	if (reject && msg->foundmatch) {
 		osmtpd_filter_disconnect(ctx, "Message contains "
 		    "Authentication-Results header for authserv-id '%s'",
@@ -201,7 +188,7 @@ admd_commit(struct osmtpd_ctx *ctx)
 		fprintf(stderr, "%016"PRIx64" Message contains "
 		    "Authentication-Results header for authserv-id '%s': "
 		    "rejected\n", ctx->reqid, authservid);
-		return;
+		return 0;
 	}
 
 	osmtpd_filter_proceed(ctx);
@@ -213,13 +200,8 @@ admd_commit(struct osmtpd_ctx *ctx)
 		fprintf(stderr, "%016"PRIx64" Message contains no "
 		   "Authentication-Results header for authserv-id '%s'\n",
 		    ctx->reqid, authservid);
-}
 
-void
-admd_err(struct admd_message *message, const char *msg)
-{
-	message->err = 1;
-	fprintf(stderr, "%s: %s\n", msg, strerror(errno));
+	return 0;
 }
 
 void
@@ -230,17 +212,16 @@ admd_cache(struct admd_message *msg, const char *line)
 	if ((tcache = reallocarray(msg->cache, msg->cachelen + 1,
 	    sizeof(*(msg->cache)))) == NULL) {
 		admd_freecache(msg);
-		admd_err(msg, "malloc");
+		osmtpd_err(1, "malloc");
 	}
 	msg->cache = tcache;
 	msg->cache[msg->cachelen] = strdup(line);
 	if (msg->cache[msg->cachelen] == NULL) {
 		admd_freecache(msg);
-		admd_err(msg, "strdup");
+		osmtpd_err(1, "strdup");
 	}
 	msg->cachelen++;
 	msg->headerlen += strlen(line[0] == '.' ? line + 1 : line);
-	return;
 }
 
 const char *
@@ -253,7 +234,7 @@ admd_authservid(struct admd_message *msg)
 	headerlen = msg->headerlen + (msg->cachelen * 2) + 1;
 	header0 = header = malloc(headerlen);
 	if (header == NULL) {
-		admd_err(msg, "malloc");
+		osmtpd_err(1, "malloc");
 		return NULL;
 	}
 	header[0] = '\0';