summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/smtpd/delivery_maildir.c4
-rw-r--r--usr.sbin/smtpd/lka_session.c20
-rw-r--r--usr.sbin/smtpd/smtpd.h5
-rw-r--r--usr.sbin/smtpd/util.c86
4 files changed, 105 insertions, 10 deletions
diff --git a/usr.sbin/smtpd/delivery_maildir.c b/usr.sbin/smtpd/delivery_maildir.c
index 501a72ebc92..946b3636ad4 100644
--- a/usr.sbin/smtpd/delivery_maildir.c
+++ b/usr.sbin/smtpd/delivery_maildir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: delivery_maildir.c,v 1.6 2012/05/25 13:51:42 chl Exp $ */
+/* $OpenBSD: delivery_maildir.c,v 1.7 2012/07/12 08:51:43 chl Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -62,7 +62,7 @@ delivery_maildir_open(struct deliver *deliver)
#define error2(m) { msg = m; goto err2; }
setproctitle("maildir delivery");
- if (mkdir(deliver->to, 0700) < 0 && errno != EEXIST)
+ if (mkdir_p(deliver->to, 0700) < 0 && errno != EEXIST)
error("cannot mkdir maildir");
if (chdir(deliver->to) < 0)
error("cannot cd to maildir");
diff --git a/usr.sbin/smtpd/lka_session.c b/usr.sbin/smtpd/lka_session.c
index 5c7398c988c..87fc63f8f76 100644
--- a/usr.sbin/smtpd/lka_session.c
+++ b/usr.sbin/smtpd/lka_session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lka_session.c,v 1.16 2011/12/13 22:04:35 eric Exp $ */
+/* $OpenBSD: lka_session.c,v 1.17 2012/07/12 08:51:43 chl Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -75,7 +75,7 @@ int
lka_session_envelope_expand(struct lka_session *lks, struct envelope *ep)
{
char *user;
- char *sep;
+ char *tag;
struct user_backend *ub;
struct mta_user u;
char username[MAX_LOCALPART_SIZE];
@@ -97,8 +97,13 @@ lka_session_envelope_expand(struct lka_session *lks, struct envelope *ep)
lowercase(username, user, sizeof(username));
/* gilles+hackers@ -> gilles@ */
- if ((sep = strchr(username, '+')) != NULL)
- *sep = '\0';
+ if ((tag = strchr(username, '+')) != NULL) {
+ *tag++ = '\0';
+
+ /* skip dots after the '+' */
+ while (*tag == '.')
+ tag++;
+ }
if (aliases_exist(ep->rule.r_amap, username)) {
if (! aliases_get(ep->rule.r_amap,
@@ -131,6 +136,13 @@ lka_session_envelope_expand(struct lka_session *lks, struct envelope *ep)
(void)strlcpy(ep->agent.mda.to.buffer,
ep->rule.r_value.buffer,
sizeof (ep->agent.mda.to.buffer));
+
+ if (tag && *tag) {
+ (void)strlcat(ep->agent.mda.to.buffer, "/.",
+ sizeof (ep->agent.mda.to.buffer));
+ (void)strlcat(ep->agent.mda.to.buffer, tag,
+ sizeof (ep->agent.mda.to.buffer));
+ }
break;
default:
fatalx("lka_session_envelope_expand: unexpected rule action");
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index d900a833544..d1aa6834037 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.309 2012/07/10 23:21:34 chl Exp $ */
+/* $OpenBSD: smtpd.h,v 1.310 2012/07/12 08:51:43 chl Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -1207,14 +1207,13 @@ void addargs(arglist *, char *, ...)
__attribute__((format(printf, 2, 3)));
int bsnprintf(char *, size_t, const char *, ...)
__attribute__ ((format (printf, 3, 4)));
+int mkdir_p(char *, mode_t);
int safe_fclose(FILE *);
int hostname_match(char *, char *);
int email_to_mailaddr(struct mailaddr *, char *);
int valid_localpart(const char *);
int valid_domainpart(const char *);
char *ss_to_text(struct sockaddr_storage *);
-int valid_message_id(char *);
-int valid_message_uid(char *);
char *time_to_text(time_t);
int secure_file(int, char *, char *, uid_t, int);
void lowercase(char *, char *, size_t);
diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c
index e53a2d8d0f9..96e8350264e 100644
--- a/usr.sbin/smtpd/util.c
+++ b/usr.sbin/smtpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.65 2012/07/11 22:16:45 chl Exp $ */
+/* $OpenBSD: util.c,v 1.66 2012/07/12 08:51:43 chl Exp $ */
/*
* Copyright (c) 2000,2001 Markus Friedl. All rights reserved.
@@ -18,6 +18,37 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+/* the mkdir_p() function is based on bin/mkdir/mkdir.c that is covered
+ * by the following license: */
+/*
+ * Copyright (c) 1983, 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
#include <sys/types.h>
#include <sys/param.h>
#include <sys/queue.h>
@@ -69,6 +100,59 @@ bsnprintf(char *str, size_t size, const char *format, ...)
return 1;
}
+/*
+ * mkdir -p. Based on bin/mkdir/mkdir.c:mkpath()
+ */
+int
+mkdir_p(char *path, mode_t mode)
+{
+ struct stat sb;
+ char *slash;
+ int done, exists;
+ mode_t dir_mode;
+
+ dir_mode = mode | S_IWUSR | S_IXUSR;
+
+ slash = path;
+
+ for (;;) {
+ slash += strspn(slash, "/");
+ slash += strcspn(slash, "/");
+
+ done = (*slash == '\0');
+ *slash = '\0';
+
+ /* skip existing path components */
+ exists = !stat(path, &sb);
+ if (!done && exists && S_ISDIR(sb.st_mode)) {
+ *slash = '/';
+ continue;
+ }
+
+ if (mkdir(path, done ? mode : dir_mode) == 0) {
+ if (mode > 0777 && chmod(path, mode) < 0)
+ return (-1);
+ } else {
+ if (!exists) {
+ /* Not there */
+ return (-1);
+ }
+ if (!S_ISDIR(sb.st_mode)) {
+ /* Is there, but isn't a directory */
+ errno = ENOTDIR;
+ return (-1);
+ }
+ }
+
+ if (done)
+ break;
+
+ *slash = '/';
+ }
+
+ return (0);
+}
+
int
ckdir(const char *path, mode_t mode, uid_t owner, gid_t group, int create)
{