-/* $OpenBSD: smtpd.h,v 1.477 2015/10/14 22:16:38 gilles Exp $ */
+/* $OpenBSD: smtpd.h,v 1.478 2015/10/17 22:24:36 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
int mkdirs(char *, mode_t);
int safe_fclose(FILE *);
int hostname_match(const char *, const char *);
+int mailaddr_match(const struct mailaddr *, const struct mailaddr *);
int valid_localpart(const char *);
int valid_domainpart(const char *);
int secure_file(int, char *, char *, uid_t, int);
-/* $OpenBSD: util.c,v 1.121 2015/10/17 12:59:52 gilles Exp $ */
+/* $OpenBSD: util.c,v 1.122 2015/10/17 22:24:36 gilles Exp $ */
/*
* Copyright (c) 2000,2001 Markus Friedl. All rights reserved.
return 1;
}
-
int
ckdir(const char *path, mode_t mode, uid_t owner, gid_t group, int create)
{
return (*hostname == '\0' && *pattern == '\0');
}
+int
+mailaddr_match(const struct mailaddr *maddr1, const struct mailaddr *maddr2)
+{
+ struct mailaddr m1 = *maddr1;
+ struct mailaddr m2 = *maddr2;
+ char *p;
+
+ /* catchall */
+ if (m2.user[0] == '\0' && m2.domain[0] == '\0')
+ return 1;
+
+ if (! hostname_match(m1.domain, m2.domain))
+ return 0;
+
+ if (m2.user[0]) {
+ /* if address from table has a tag, we must respect it */
+ if (strchr(m2.user, '+') == NULL) {
+ /* otherwise, strip tag from session address if any */
+ p = strchr(m1.user, '+');
+ if (p)
+ *p = '\0';
+ }
+ if (strcasecmp(m1.user, m2.user))
+ return 0;
+ }
+ return 1;
+}
+
int
valid_localpart(const char *s)
{