summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2009-01-04 17:45:59 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2009-01-04 17:45:59 +0000
commit6ee860c4bd48c14567735c4ee1f3ed6fd72c5dea (patch)
tree07cdb252294cffa7fc95d084833587f995afa131
parent2c7e82c1e33e892bdc6c60cc425339ce23723207 (diff)
When matching a recipient domain to a rule, do not use strcasecmp, but use
new hostname_match() function which recognizes * as a wildcard. We can now do: accept for domain "*.example.org" to match all subdomains. idea from Nicholas Marriott <nicholas.marriott@gmail.com>, hostname_match() from me in place of his fnmatch() calls. ok jacekm@
-rw-r--r--usr.sbin/smtpd/lka.c5
-rw-r--r--usr.sbin/smtpd/mfa.c5
-rw-r--r--usr.sbin/smtpd/smtpd.h3
-rw-r--r--usr.sbin/smtpd/util.c25
4 files changed, 30 insertions, 8 deletions
diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c
index c02722420b7..ee636ff6910 100644
--- a/usr.sbin/smtpd/lka.c
+++ b/usr.sbin/smtpd/lka.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lka.c,v 1.14 2009/01/04 14:46:14 jacekm Exp $ */
+/* $OpenBSD: lka.c,v 1.15 2009/01/04 17:45:58 gilles Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -592,8 +592,7 @@ lka_verify_mail(struct smtpd *env, struct path *path)
map = cond->c_match;
TAILQ_FOREACH(me, &map->m_contents, me_entry) {
- if (strcasecmp(me->me_key.med_string,
- path->domain) == 0) {
+ if (hostname_match(path->domain, me->me_key.med_string)) {
path->rule = *r;
if (r->r_action == A_MBOX ||
r->r_action == A_MAILDIR ||
diff --git a/usr.sbin/smtpd/mfa.c b/usr.sbin/smtpd/mfa.c
index 9b330002dea..f03cbe7084b 100644
--- a/usr.sbin/smtpd/mfa.c
+++ b/usr.sbin/smtpd/mfa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mfa.c,v 1.8 2009/01/04 16:40:58 gilles Exp $ */
+/* $OpenBSD: mfa.c,v 1.9 2009/01/04 17:45:58 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -396,8 +396,7 @@ mfa_check_rcpt(struct smtpd *env, struct path *path, struct sockaddr_storage *ss
map = cond->c_match;
TAILQ_FOREACH(me, &map->m_contents, me_entry) {
- if (strcasecmp(me->me_key.med_string,
- path->domain) == 0) {
+ if (hostname_match(path->domain, me->me_key.med_string)) {
path->rule = *r;
return 1;
}
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 40d295d099e..c70ed7e8dd8 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.40 2009/01/04 16:40:58 gilles Exp $ */
+/* $OpenBSD: smtpd.h,v 1.41 2009/01/04 17:45:58 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -786,3 +786,4 @@ struct map *map_findbyname(struct smtpd *, const char *);
int bsnprintf(char *, size_t, const char *, ...)
__attribute__ ((format (printf, 3, 4)));
int safe_fclose(FILE *);
+int hostname_match(char *, char *);
diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c
index d4be850fbd9..329e0bef443 100644
--- a/usr.sbin/smtpd/util.c
+++ b/usr.sbin/smtpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.4 2009/01/01 16:15:47 jacekm Exp $ */
+/* $OpenBSD: util.c,v 1.5 2009/01/04 17:45:58 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -22,6 +22,7 @@
#include <sys/tree.h>
#include <sys/socket.h>
+#include <ctype.h>
#include <errno.h>
#include <event.h>
#include <stdio.h>
@@ -64,3 +65,25 @@ safe_fclose(FILE *fp)
return 1;
}
+
+int
+hostname_match(char *hostname, char *pattern)
+{
+ while (*pattern != '\0' && *hostname != '\0') {
+ if (*pattern == '*') {
+ while (*pattern == '*')
+ pattern++;
+ while (*hostname != '\0' &&
+ tolower(*hostname) != tolower(*pattern))
+ hostname++;
+ continue;
+ }
+
+ if (tolower(*pattern) != tolower(*hostname))
+ return 0;
+ pattern++;
+ hostname++;
+ }
+
+ return (*hostname == '\0' && *pattern == '\0');
+}