diff options
author | Gilles Chehade <gilles@poolp.org> | 2020-01-31 22:25:54 +0100 |
---|---|---|
committer | Gilles Chehade <gilles@poolp.org> | 2020-01-31 22:25:54 +0100 |
commit | f77fd406e86a04fa6834d4e2b30361ea374f20f9 (patch) | |
tree | 11c66dd7ed5396943e9884f19552a38b9a889b19 /contrib | |
parent | Merge branch 'master' into portable (diff) | |
download | OpenSMTPD-f77fd406e86a04fa6834d4e2b30361ea374f20f9.tar.xz OpenSMTPD-f77fd406e86a04fa6834d4e2b30361ea374f20f9.zip |
synchronize mail.local with -current
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/libexec/mail.local/CVS/Entries | 8 | ||||
-rw-r--r-- | contrib/libexec/mail.local/locking.c | 16 | ||||
-rw-r--r-- | contrib/libexec/mail.local/mail.local.8 | 26 | ||||
-rw-r--r-- | contrib/libexec/mail.local/mail.local.c | 89 |
4 files changed, 80 insertions, 59 deletions
diff --git a/contrib/libexec/mail.local/CVS/Entries b/contrib/libexec/mail.local/CVS/Entries index e02ca255..d4e29f84 100644 --- a/contrib/libexec/mail.local/CVS/Entries +++ b/contrib/libexec/mail.local/CVS/Entries @@ -1,7 +1,7 @@ -/locking.c/1.10/Mon Jan 10 21:00:50 2011// -/mail.local.c/1.32/Tue Oct 27 23:59:31 2009// /Makefile/1.3/Mon Jul 9 11:41:26 2012// -/mail.local.8/1.29/Mon Jul 9 11:36:35 2012// -/mail.local.h/1.5/Mon Jul 9 11:36:35 2012// /pathnames.h/1.5/Mon Jul 9 11:36:35 2012// +/locking.c/1.12/Result of merge+Fri Jan 31 21:09:44 2020// +/mail.local.8/1.31/Fri Jan 31 21:09:45 2020// +/mail.local.c/1.36/Result of merge+Fri Jan 31 21:09:45 2020// +/mail.local.h/1.5/Thu Jan 9 23:34:12 2020// D diff --git a/contrib/libexec/mail.local/locking.c b/contrib/libexec/mail.local/locking.c index ab6eb1a8..db2e2091 100644 --- a/contrib/libexec/mail.local/locking.c +++ b/contrib/libexec/mail.local/locking.c @@ -1,4 +1,4 @@ -/* $OpenBSD: locking.c,v 1.10 2011/01/10 21:00:50 millert Exp $ */ +/* $OpenBSD: locking.c,v 1.12 2015/01/16 06:39:50 deraadt Exp $ */ /* * Copyright (c) 1996-1998 Theo de Raadt <deraadt@theos.com> @@ -30,13 +30,15 @@ #include "includes.h" -#include <sys/param.h> +#include <sys/types.h> + #include <sys/stat.h> #include <fcntl.h> #include <pwd.h> #include <syslog.h> #include <time.h> #include <unistd.h> +#include <limits.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> @@ -45,7 +47,7 @@ #include "pathnames.h" #include "mail.local.h" -static char lpath[MAXPATHLEN]; +static char lpath[PATH_MAX]; void rellock(void) @@ -66,9 +68,8 @@ getlock(char *name, struct passwd *pw) (void)snprintf(lpath, sizeof lpath, "%s/%s.lock", _PATH_MAILDIR, name); - if (stat(_PATH_MAILDIR, &sb) == -1) - merr(FATAL, "%s: %s", _PATH_MAILDIR, strerror(errno)); - if ((sb.st_mode & S_IWOTH) == S_IWOTH) { + if (stat(_PATH_MAILDIR, &sb) != -1 && + (sb.st_mode & S_IWOTH) == S_IWOTH) { /* * We have a writeable spool, deal with it as * securely as possible. @@ -121,6 +122,7 @@ again: seteuid(pw->pw_uid); } } + close(lfd); } sleep(1U << tries); tries++; @@ -149,7 +151,7 @@ again: void baditem(char *path) { - char npath[MAXPATHLEN]; + char npath[PATH_MAX]; int fd; if (unlink(path) == 0) diff --git a/contrib/libexec/mail.local/mail.local.8 b/contrib/libexec/mail.local/mail.local.8 index f77fa6da..330a4473 100644 --- a/contrib/libexec/mail.local/mail.local.8 +++ b/contrib/libexec/mail.local/mail.local.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: mail.local.8,v 1.29 2010/09/03 11:35:08 jmc Exp $ +.\" $OpenBSD: mail.local.8,v 1.31 2014/09/16 21:28:51 jmc Exp $ .\" Copyright (c) 1990 The Regents of the University of California. .\" All rights reserved. .\" @@ -28,7 +28,7 @@ .\" .\" from: @(#)mail.local.8 6.8 (Berkeley) 4/27/91 .\" -.Dd $Mdocdate: September 3 2010 $ +.Dd $Mdocdate: September 16 2014 $ .Dt MAIL.LOCAL 8 .Os .Sh NAME @@ -125,7 +125,7 @@ user's mailbox directory .Xr flock 2 , .Xr getservbyname 3 , .Xr comsat 8 , -.Xr sendmail 8 +.Xr smtpd 8 .Sh HISTORY A superset of .Nm @@ -134,17 +134,12 @@ A superset of as the program .Xr mail 1 . .Sh BUGS -Since -.Xr sendmail 8 -bases its idea of whether a message has been delivered or not -on the return value from -.Nm mail.local , -using quotas in +Using quotas in .Pa /var/mail -can be problematic. -By default, +can be problematic if using .Xr sendmail 8 -will ask +as an MTA, +since it asks .Nm to deliver a message to multiple recipients if possible. This causes problems in a quota environment since a message may be @@ -157,8 +152,13 @@ to attempt redelivery later. That means that some users will keep getting the same message every time .Xr sendmail 8 runs its queue. +This problem does not exist for +.Xr smtpd 8 +users. .Pp -If you are running with disk quotas on +If you are running +.Xr sendmail 8 +and have disk quotas on .Pa /var/mail it is imperative that you unset the .Dq m diff --git a/contrib/libexec/mail.local/mail.local.c b/contrib/libexec/mail.local/mail.local.c index d1f7d2f2..c11ea907 100644 --- a/contrib/libexec/mail.local/mail.local.c +++ b/contrib/libexec/mail.local/mail.local.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mail.local.c,v 1.32 2009/10/27 23:59:31 deraadt Exp $ */ +/* $OpenBSD: mail.local.c,v 1.36 2019/06/28 13:32:53 deraadt Exp $ */ /*- * Copyright (c) 1996-1998 Theo de Raadt <deraadt@theos.com> @@ -33,7 +33,8 @@ #include "includes.h" -#include <sys/param.h> +#include <sys/types.h> + #include <sys/stat.h> #include <sys/socket.h> #include <netinet/in.h> @@ -43,6 +44,7 @@ #include <pwd.h> #include <time.h> #include <unistd.h> +#include <limits.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> @@ -119,8 +121,7 @@ storemail(char *from) FILE *fp = NULL; time_t tval; int fd, eline; - ssize_t len; - size_t linesz; + size_t len; char *line, *tbuf; if ((tbuf = strdup(_PATH_LOCTMP)) == NULL) @@ -133,10 +134,18 @@ storemail(char *from) (void)time(&tval); (void)fprintf(fp, "From %s %s", from, ctime(&tval)); - for (eline = 1, line = NULL, linesz = 0; - (len = getline(&line, &linesz, stdin)) != -1;) { + for (eline = 1, tbuf = NULL; (line = fgetln(stdin, &len));) { + /* We have to NUL-terminate the line since fgetln does not */ if (line[len - 1] == '\n') - line[--len] = '\0'; + line[len - 1] = '\0'; + else { + /* No trailing newline, so alloc space and copy */ + if ((tbuf = malloc(len + 1)) == NULL) + merr(FATAL, "unable to allocate memory"); + memcpy(tbuf, line, len); + tbuf[len] = '\0'; + line = tbuf; + } if (line[0] == '\0') eline = 1; else { @@ -149,7 +158,7 @@ storemail(char *from) if (ferror(fp)) break; } - free(line); + free(tbuf); /* Output a newline; note, empty messages are allowed. */ (void)putc('\n', fp); @@ -165,7 +174,7 @@ deliver(int fd, char *name, int lockfile) struct stat sb, fsb; struct passwd *pw; int mbfd=-1, rval=1, lfd=-1; - char biffmsg[100], buf[8*1024], path[MAXPATHLEN]; + char biffmsg[100], buf[8*1024], path[PATH_MAX]; off_t curoff; size_t off; ssize_t nr, nw; @@ -198,7 +207,7 @@ retry: #define O_EXLOCK 0 #endif if ((mbfd = open(path, O_APPEND|O_CREAT|O_EXCL|O_WRONLY|O_EXLOCK, - S_IRUSR|S_IWUSR)) < 0) { + S_IRUSR|S_IWUSR)) == -1) { #ifndef HAVE_O_EXLOCK /* XXX : do something! */ #endif @@ -216,7 +225,7 @@ retry: * that if the ownership or permissions were changed there * was a reason for doing so. */ - if (fchown(mbfd, pw->pw_uid, pw->pw_gid) < 0) { + if (fchown(mbfd, pw->pw_uid, pw->pw_gid) == -1) { merr(NOTFATAL, "chown %u:%u: %s", pw->pw_uid, pw->pw_gid, name); goto bad; @@ -227,11 +236,11 @@ retry: goto bad; } if ((mbfd = open(path, O_APPEND|O_WRONLY|O_EXLOCK, - S_IRUSR|S_IWUSR)) < 0) { + S_IRUSR|S_IWUSR)) == -1) { merr(NOTFATAL, "%s: %s", path, strerror(errno)); goto bad; } - if (fstat(mbfd, &fsb)) { + if (fstat(mbfd, &fsb) == -1) { /* relating error to path may be bad style */ merr(NOTFATAL, "%s: %s", path, strerror(errno)); goto bad; @@ -248,8 +257,7 @@ retry: } curoff = lseek(mbfd, 0, SEEK_END); - (void)snprintf(biffmsg, sizeof biffmsg, "%s@%qd\n", name, - (long long int) curoff); + (void)snprintf(biffmsg, sizeof biffmsg, "%s@%lld\n", name, curoff); if (lseek(fd, 0, SEEK_SET) == (off_t)-1) { merr(NOTFATAL, "temporary file: %s", strerror(errno)); goto bad; @@ -257,7 +265,7 @@ retry: while ((nr = read(fd, buf, sizeof(buf))) > 0) for (off = 0; off < (size_t)nr; off += nw) - if ((nw = write(mbfd, buf + off, nr - off)) < 0) { + if ((nw = write(mbfd, buf + off, nr - off)) == -1) { merr(NOTFATAL, "%s: %s", path, strerror(errno)); (void)ftruncate(mbfd, curoff); goto bad; @@ -289,34 +297,45 @@ bad: void notifybiff(char *msg) { - static struct sockaddr_in addr; + static struct addrinfo *res0; + struct addrinfo hints, *res; static int f = -1; - struct hostent *hp; - struct servent *sp; size_t len; + ssize_t slen; + int error; - if (!addr.sin_family) { - /* Be silent if biff service not available. */ - if (!(sp = getservbyname("biff", "udp"))) - return; - if (!(hp = gethostbyname("localhost"))) { - merr(NOTFATAL, "localhost: %s", strerror(errno)); + if (res0 == NULL) { + memset(&hints, 0, sizeof(hints)); + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_DGRAM; + + error = getaddrinfo("localhost", "biff", &hints, &res0); + if (error) { + /* Be silent if biff service not available. */ + if (error != EAI_SERVICE) { + merr(NOTFATAL, "localhost: %s", + gai_strerror(error)); + } return; } -#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN - addr.sin_len = sizeof(struct sockaddr_in); -#endif - addr.sin_family = hp->h_addrtype; - addr.sin_port = sp->s_port; - bcopy(hp->h_addr, &addr.sin_addr, (size_t)hp->h_length); } - if (f < 0 && (f = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { + + if (f == -1) { + for (res = res0; res != NULL; res = res->ai_next) { + f = socket(res->ai_family, res->ai_socktype, + res->ai_protocol); + if (f != -1) + break; + } + } + if (f == -1) { merr(NOTFATAL, "socket: %s", strerror(errno)); return; } - len = strlen(msg) + 1; - if (sendto(f, msg, len, 0, (struct sockaddr *)&addr, sizeof(addr)) - != (ssize_t)len) + + len = strlen(msg) + 1; /* XXX */ + slen = sendto(f, msg, len, 0, res->ai_addr, res->ai_addrlen); + if (slen == -1 || (size_t)slen != len) merr(NOTFATAL, "sendto biff: %s", strerror(errno)); } |