-/* $OpenBSD: ruleset.c,v 1.40 2018/12/26 15:55:09 eric Exp $ */
+/* $OpenBSD: ruleset.c,v 1.41 2018/12/26 17:37:15 eric Exp $ */
/*
* Copyright (c) 2009 Gilles Chehade <gilles@poolp.org>
#include "smtpd.h"
#include "log.h"
+#define MATCH_RESULT(r, neg) ((r) == -1 ? -1 : ((neg) < 0 ? !(r) : (r)))
static int
ruleset_match_tag(struct rule *r, const struct envelope *evp)
service = K_REGEX;
table = table_find(env, r->table_tag, NULL);
- if ((ret = table_match(table, service, evp->tag)) < 0)
- return ret;
+ ret = table_match(table, service, evp->tag);
- return r->flag_tag < 0 ? !ret : ret;
+ return MATCH_RESULT(ret, r->flag_tag);
}
static int
service = K_REGEX;
table = table_find(env, r->table_from, NULL);
- if ((ret = table_match(table, service, key)) < 0)
- return -1;
+ ret = table_match(table, service, key);
- return r->flag_from < 0 ? !ret : ret;
+ return MATCH_RESULT(ret, r->flag_from);
}
static int
service = K_REGEX;
table = table_find(env, r->table_for, NULL);
- if ((ret = table_match(table, service, evp->dest.domain)) < 0)
- return -1;
+ ret = table_match(table, service, evp->dest.domain);
- return r->flag_for < 0 ? !ret : ret;
+ return MATCH_RESULT(ret, r->flag_for);
}
static int
service = K_REGEX;
table = table_find(env, r->table_smtp_helo, NULL);
- if ((ret = table_match(table, service, evp->helo)) < 0)
- return -1;
+ ret = table_match(table, service, evp->helo);
- return r->flag_smtp_helo < 0 ? !ret : ret;
+ return MATCH_RESULT(ret, r->flag_smtp_helo);
}
static int
else
ret = 1;
- return r->flag_smtp_auth < 0 ? !ret : ret;
+ return MATCH_RESULT(ret, r->flag_smtp_auth);
}
static int
return -1;
table = table_find(env, r->table_smtp_mail_from, NULL);
- if ((ret = table_match(table, service, key)) < 0)
- return -1;
+ ret = table_match(table, service, key);
- return r->flag_smtp_mail_from < 0 ? !ret : ret;
+ return MATCH_RESULT(ret, r->flag_smtp_mail_from);
}
static int
return -1;
table = table_find(env, r->table_smtp_rcpt_to, NULL);
- if ((ret = table_match(table, service, key)) < 0)
- return -1;
+ ret = table_match(table, service, key);
- return r->flag_smtp_rcpt_to < 0 ? !ret : ret;
+ return MATCH_RESULT(ret, r->flag_smtp_rcpt_to);
}
struct rule *