commit - 04c09316bee33648590a27c3c0d9ecdbfa9a0ba9
commit + 79ef769fe9b996ba9e1c27eaa688876757e101dc
blob - bec9941fd8c17a41dac272e1b0042f669a8e5577
blob + 9341020157c935717ea17bb4a8f7fee78fc277db
--- main.c
+++ main.c
struct admd_message {
int foundmatch;
- int err;
int inheader;
int parsing_headers;
char **cache;
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 *);
osmtpd_err(1, "malloc");
msg->foundmatch = 0;
- msg->err = 0;
msg->inheader = 0;
msg->parsing_headers = 1;
msg->cache = NULL;
free(msg);
}
-void
+int
admd_dataline(struct osmtpd_ctx *ctx, const char *orig)
{
struct admd_message *msg = ctx->local_message;
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] == '.')
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;
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'",
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);
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
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 *
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';