diff options
author | Gilles Chehade <gilles@poolp.org> | 2019-10-03 07:11:40 +0200 |
---|---|---|
committer | Gilles Chehade <gilles@poolp.org> | 2019-10-03 07:11:40 +0200 |
commit | 695049695cd218a76a9971617eaed982bff9e439 (patch) | |
tree | 1966f56006261bb9e47c10e127a449f6a8d0f724 | |
parent | sync (diff) | |
download | OpenSMTPD-695049695cd218a76a9971617eaed982bff9e439.tar.xz OpenSMTPD-695049695cd218a76a9971617eaed982bff9e439.zip |
sync
-rw-r--r-- | smtpd/lka_proc.c | 3 | ||||
-rw-r--r-- | smtpd/mail.maildir.c | 32 | ||||
-rw-r--r-- | smtpd/mail.mboxfile.c | 9 | ||||
-rw-r--r-- | smtpd/smtp_session.c | 20 | ||||
-rw-r--r-- | smtpd/smtpd.h | 3 | ||||
-rw-r--r-- | smtpd/table_proc.c | 5 | ||||
-rw-r--r-- | smtpd/util.c | 62 |
7 files changed, 46 insertions, 88 deletions
diff --git a/smtpd/lka_proc.c b/smtpd/lka_proc.c index 1cee13aa..f90d006f 100644 --- a/smtpd/lka_proc.c +++ b/smtpd/lka_proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka_proc.c,v 1.11 2019/09/06 08:23:56 martijn Exp $ */ +/* $OpenBSD: lka_proc.c,v 1.12 2019/09/30 13:27:12 gilles Exp $ */ /* * Copyright (c) 2018 Gilles Chehade <gilles@poolp.org> @@ -65,6 +65,7 @@ lka_proc_ready(void) static void lka_proc_config(struct processor_instance *pi) { + io_printf(pi->io, "config|smtpd-version|%s\n", SMTPD_VERSION); io_printf(pi->io, "config|smtp-session-timeout|%d\n", SMTPD_SESSION_TIMEOUT); io_printf(pi->io, "config|ready\n"); } diff --git a/smtpd/mail.maildir.c b/smtpd/mail.maildir.c index a4956f1b..5e558884 100644 --- a/smtpd/mail.maildir.c +++ b/smtpd/mail.maildir.c @@ -31,6 +31,7 @@ #include <stdlib.h> #include <string.h> #include <time.h> +#include <sysexits.h> #include <unistd.h> #define MAILADDR_ESCAPE "!#$%&'*/?^`{|}~" @@ -93,8 +94,11 @@ maildir_mkdirs(const char *dirname) char pathname[PATH_MAX]; char *subdirs[] = { "cur", "tmp", "new" }; - if (mkdirs(dirname, 0700) == -1 && errno != EEXIST) - err(1, NULL); + if (mkdirs(dirname, 0700) == -1 && errno != EEXIST) { + if (errno == EINVAL || errno == ENAMETOOLONG) + err(1, NULL); + err(EX_TEMPFAIL, NULL); + } for (i = 0; i < nitems(subdirs); ++i) { ret = snprintf(pathname, sizeof pathname, "%s/%s", dirname, @@ -102,7 +106,7 @@ maildir_mkdirs(const char *dirname) if (ret < 0 || (size_t)ret >= sizeof pathname) errc(1, ENAMETOOLONG, "%s/%s", dirname, subdirs[i]); if (mkdir(pathname, 0700) == -1 && errno != EEXIST) - err(1, NULL); + err(EX_TEMPFAIL, NULL); } } @@ -178,9 +182,9 @@ maildir_engine(const char *dirname, int junk) fd = open(tmp, O_CREAT | O_EXCL | O_WRONLY, 0600); if (fd == -1) - err(1, NULL); + err(EX_TEMPFAIL, NULL); if ((fp = fdopen(fd, "w")) == NULL) - err(1, NULL); + err(EX_TEMPFAIL, NULL); while ((linelen = getline(&line, &linesize, stdin)) != -1) { line[strcspn(line, "\n")] = '\0'; @@ -194,19 +198,19 @@ maildir_engine(const char *dirname, int junk) } free(line); if (ferror(stdin)) - err(1, NULL); + err(EX_TEMPFAIL, NULL); if (fflush(fp) == EOF || ferror(fp) || fsync(fd) == -1 || fclose(fp) == EOF) - err(1, NULL); + err(EX_TEMPFAIL, NULL); (void)snprintf(new, sizeof new, "%s/new/%s", is_junk ? junkpath : dirname, filename); if (rename(tmp, new) == -1) - err(1, NULL); + err(EX_TEMPFAIL, NULL); exit(0); } @@ -223,8 +227,10 @@ mkdirs_component(const char *path, mode_t mode) if (mkdir(path, mode | S_IWUSR | S_IXUSR) == -1) return 0; } - else if (!S_ISDIR(sb.st_mode)) + else if (!S_ISDIR(sb.st_mode)) { + errno = ENOTDIR; return 0; + } return 1; } @@ -238,12 +244,16 @@ mkdirs(const char *path, mode_t mode) const char *p; /* absolute path required */ - if (*path != '/') + if (*path != '/') { + errno = EINVAL; return 0; + } /* make sure we don't exceed PATH_MAX */ - if (strlen(path) >= sizeof buf) + if (strlen(path) >= sizeof buf) { + errno = ENAMETOOLONG; return 0; + } memset(buf, 0, sizeof buf); for (p = path; *p; p++) { diff --git a/smtpd/mail.mboxfile.c b/smtpd/mail.mboxfile.c index 0cc1d742..96fa2e02 100644 --- a/smtpd/mail.mboxfile.c +++ b/smtpd/mail.mboxfile.c @@ -26,6 +26,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sysexits.h> #include <unistd.h> static void mboxfile_engine(const char *sender, const char *filename); @@ -73,10 +74,10 @@ mboxfile_engine(const char *sender, const char *filename) fd = open(filename, O_CREAT | O_APPEND | O_WRONLY | O_EXLOCK, 0600); if (fd == -1) - err(1, NULL); + err(EX_TEMPFAIL, NULL); if ((fp = fdopen(fd, "w")) == NULL) - err(1, NULL); + err(EX_TEMPFAIL, NULL); fprintf(fp, "From %s %s", sender, ctime(&now)); while ((linelen = getline(&line, &linesize, stdin)) != -1) { @@ -89,11 +90,11 @@ mboxfile_engine(const char *sender, const char *filename) fprintf(fp, "\n"); free(line); if (ferror(stdin)) - err(1, NULL); + err(EX_TEMPFAIL, NULL); if (fflush(fp) == EOF || ferror(fp) || fsync(fd) == -1 || fclose(fp) == EOF) - err(1, NULL); + err(EX_TEMPFAIL, NULL); } diff --git a/smtpd/smtp_session.c b/smtpd/smtp_session.c index 5df9476e..95db9099 100644 --- a/smtpd/smtp_session.c +++ b/smtpd/smtp_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtp_session.c,v 1.412 2019/09/21 09:01:52 semarie Exp $ */ +/* $OpenBSD: smtp_session.c,v 1.414 2019/10/03 05:08:21 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -782,9 +782,9 @@ smtp_session_imsg(struct mproc *p, struct imsg *imsg) smtp_reply(s, "250 %s Ok", esc_code(ESC_STATUS_OK, ESC_OTHER_STATUS)); } else { - smtp_tx_free(s->tx); smtp_reply(s, "421 %s Temporary Error", esc_code(ESC_STATUS_TEMPFAIL, ESC_OTHER_MAIL_SYSTEM_STATUS)); + smtp_tx_free(s->tx); smtp_enter_state(s, STATE_QUIT); } m_end(&m); @@ -2105,14 +2105,18 @@ smtp_reply(struct smtp_session *s, char *fmt, ...) switch (buf[0]) { case '2': - if (s->last_cmd == CMD_MAIL_FROM) - report_smtp_tx_mail("smtp-in", s->id, s->tx->msgid, s->cmd + 10, 1); - else if (s->last_cmd == CMD_RCPT_TO) - report_smtp_tx_rcpt("smtp-in", s->id, s->tx->msgid, s->cmd + 8, 1); + if (s->tx) { + if (s->last_cmd == CMD_MAIL_FROM) + report_smtp_tx_mail("smtp-in", s->id, s->tx->msgid, s->cmd + 10, 1); + else if (s->last_cmd == CMD_RCPT_TO) + report_smtp_tx_rcpt("smtp-in", s->id, s->tx->msgid, s->cmd + 8, 1); + } break; case '3': - if (s->last_cmd == CMD_DATA) - report_smtp_tx_data("smtp-in", s->id, s->tx->msgid, 1); + if (s->tx) { + if (s->last_cmd == CMD_DATA) + report_smtp_tx_data("smtp-in", s->id, s->tx->msgid, 1); + } break; case '5': case '4': diff --git a/smtpd/smtpd.h b/smtpd/smtpd.h index ceefa269..cbc7bd7f 100644 --- a/smtpd/smtpd.h +++ b/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.640 2019/09/29 10:03:49 gilles Exp $ */ +/* $OpenBSD: smtpd.h,v 1.641 2019/09/30 08:31:41 martijn Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -1673,7 +1673,6 @@ void addargs(arglist *, char *, ...) __attribute__((format(printf, 2, 3))); int bsnprintf(char *, size_t, const char *, ...) __attribute__((format (printf, 3, 4))); -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 *); diff --git a/smtpd/table_proc.c b/smtpd/table_proc.c index 50592a74..dad041a4 100644 --- a/smtpd/table_proc.c +++ b/smtpd/table_proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table_proc.c,v 1.15 2018/12/27 14:23:41 eric Exp $ */ +/* $OpenBSD: table_proc.c,v 1.16 2019/10/03 04:51:15 gilles Exp $ */ /* * Copyright (c) 2013 Eric Faurot <eric@openbsd.org> @@ -165,7 +165,8 @@ table_proc_close(struct table *table) struct table_proc_priv *priv = table->t_handle; imsg_compose(&priv->ibuf, PROC_TABLE_CLOSE, 0, 0, -1, NULL, 0); - imsg_flush(&priv->ibuf); + if (imsg_flush(&priv->ibuf) == -1) + fatal("imsg_flush"); table->t_handle = NULL; } diff --git a/smtpd/util.c b/smtpd/util.c index 2138d1a4..f59ad1e4 100644 --- a/smtpd/util.c +++ b/smtpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.148 2019/09/29 10:03:49 gilles Exp $ */ +/* $OpenBSD: util.c,v 1.150 2019/10/03 04:49:12 gilles Exp $ */ /* * Copyright (c) 2000,2001 Markus Friedl. All rights reserved. @@ -183,65 +183,6 @@ bsnprintf(char *str, size_t size, const char *format, ...) } -static int -mkdirs_component(char *path, mode_t mode) -{ - struct stat sb; - - if (stat(path, &sb) == -1) { - if (errno != ENOENT) - return 0; - if (mkdir(path, mode | S_IWUSR | S_IXUSR) == -1) - return 0; - } - else if (!S_ISDIR(sb.st_mode)) - return 0; - - return 1; -} - -int -mkdirs(char *path, mode_t mode) -{ - char buf[PATH_MAX]; - int i = 0; - int done = 0; - char *p; - - /* absolute path required */ - if (*path != '/') - return 0; - - /* make sure we don't exceed PATH_MAX */ - if (strlen(path) >= sizeof buf) - return 0; - - memset(buf, 0, sizeof buf); - for (p = path; *p; p++) { - if (*p == '/') { - if (buf[0] != '\0') - if (!mkdirs_component(buf, mode)) - return 0; - while (*p == '/') - p++; - buf[i++] = '/'; - buf[i++] = *p; - if (*p == '\0' && ++done) - break; - continue; - } - buf[i++] = *p; - } - if (!done) - if (!mkdirs_component(buf, mode)) - return 0; - - if (chmod(path, mode) == -1) - return 0; - - return 1; -} - int ckdir(const char *path, mode_t mode, uid_t owner, gid_t group, int create) { @@ -840,6 +781,7 @@ getmailname(char *hostname, size_t len) if (strlcpy(hostname, res->ai_canonname, len) >= len) { fprintf(stderr, "hostname too long"); + freeaddrinfo(res); return -1; } |