diff options
author | Gilles Chehade <gilles@poolp.org> | 2017-02-13 09:35:42 +0100 |
---|---|---|
committer | Gilles Chehade <gilles@poolp.org> | 2017-02-13 09:35:42 +0100 |
commit | bb804c370cefd7b28ba875a63e3253c4e3e7a936 (patch) | |
tree | 1c202e8c04b54c24ed476aec253b77dfa4cb9fa5 | |
parent | Merge branch 'master' into portable (diff) | |
parent | Merge pull request #763 from smaeul/fix-libressl (diff) | |
download | OpenSMTPD-bb804c370cefd7b28ba875a63e3253c4e3e7a936.tar.xz OpenSMTPD-bb804c370cefd7b28ba875a63e3253c4e3e7a936.zip |
Merge branch 'portable' of ssh://ssh.github.com/OpenSMTPD/OpenSMTPD into portableopensmtpd-201702130941p1
-rw-r--r-- | configure.ac | 63 | ||||
-rw-r--r-- | openbsd-compat/Makefile.am | 26 | ||||
-rw-r--r-- | openbsd-compat/defines.h | 13 | ||||
-rw-r--r-- | openbsd-compat/errc.c | 3 | ||||
-rw-r--r-- | openbsd-compat/explicit_bzero.c | 18 | ||||
-rw-r--r-- | openbsd-compat/openbsd-compat.h | 37 | ||||
-rw-r--r-- | smtpd/smtpd.c | 5 | ||||
-rw-r--r-- | smtpd/smtpd.h | 2 | ||||
-rw-r--r-- | smtpd/util.c | 11 |
9 files changed, 130 insertions, 48 deletions
diff --git a/configure.ac b/configure.ac index bf53b32c..e27c514d 100644 --- a/configure.ac +++ b/configure.ac @@ -362,6 +362,10 @@ AC_CHECK_DECLS([writev], [], [], [ #include <unistd.h> ]) +AC_CHECK_DECLS([LOG_PERROR], [], [], [ +#include <syslog.h> +]) + # # CHECKS FOR COMPILER CHARACTERISTICS @@ -390,6 +394,23 @@ AC_SEARCH_LIBS([basename], ]) AM_CONDITIONAL([SUPPORT_BASENAME], [test $BASENAME_SUPPORT = yes]) + +CLOSEFROM_SUPPORT=no +AC_SEARCH_LIBS([closefrom], + [gen], + [ + AC_DEFINE([HAVE_CLOSEFROM], [1], + [Define if you have the closefrom() function.]) + CLOSEFROM_SUPPORT=yes + AC_COMPILE_IFELSE( + [ + AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [[int res = closefrom(0);]]) + ], + AC_DEFINE(HAVE_CLOSEFROM_INT, 1, [closefrom return int]) + ) + ]) +AM_CONDITIONAL([SUPPORT_CLOSEFROM], [test $CLOSEFROM_SUPPORT = yes]) + UTIMES_SUPPORT=no AC_SEARCH_LIBS([utimes], [c89], @@ -420,6 +441,15 @@ AC_SEARCH_LIBS([dirname], ]) AM_CONDITIONAL([SUPPORT_DIRNAME], [test $DIRNAME_SUPPORT = yes]) +ERRC_SUPPORT=no +AC_CHECK_FUNC([errc], + [ + AC_DEFINE([HAVE_ERRC], [1], + [Define if you have the errc() function.]) + ERRC_SUPPORT=yes + ]) +AM_CONDITIONAL([SUPPORT_ERRC], [test $ERRC_SUPPORT = yes]) + INET_NET_PTON_SUPPORT=no AC_SEARCH_LIBS([inet_net_pton], [resolv], @@ -450,6 +480,16 @@ AC_SEARCH_LIBS([fts_open], ]) AM_CONDITIONAL([SUPPORT_FTS_OPEN], [test $FTS_OPEN_SUPPORT = yes]) +FLOCK_SUPPORT=no +AC_SEARCH_LIBS([flock], + [], + [ + AC_DEFINE([HAVE_FLOCK], [1], + [Define if you have the flock() function.]) + FLOCK_SUPPORT=yes + ]) +AM_CONDITIONAL([SUPPORT_FLOCK], [test $FLOCK_SUPPORT = yes]) + AC_SEARCH_LIBS([arc4random], [crypto], [ @@ -507,6 +547,23 @@ AC_SEARCH_LIBS([crypt], ]) AM_CONDITIONAL([SUPPORT_CRYPT], [test $CRYPT_SUPPORT = yes]) +GETLINE_SUPPORT=no +AC_CHECK_FUNC([getline], + [ + AC_DEFINE([HAVE_GETLINE], [1], + [Define if you have the getline() function.]) + GETLINE_SUPPORT=yes + ]) +AM_CONDITIONAL([SUPPORT_GETLINE], [test $GETLINE_SUPPORT = yes]) + +EXPLICIT_BZERO_SUPPORT=no +AC_CHECK_FUNC([explicit_bzero], + [ + AC_DEFINE([HAVE_EXPLICIT_BZERO], [1], + [Define if you have the explicit_bzero() function.]) + EXPLICIT_BZERO_SUPPORT=yes + ]) +AM_CONDITIONAL([SUPPORT_EXPLICIT_BZERO], [test $EXPLICIT_BZERO_SUPPORT = yes]) AC_CHECK_FUNCS([ \ asprintf \ @@ -516,14 +573,10 @@ AC_CHECK_FUNCS([ \ __b64_pton \ bcopy \ chflags \ - closefrom \ dirfd \ - dirname \ endgrent \ - explicit_bzero \ fchflags \ fgetln \ - flock \ freeaddrinfo \ getaddrinfo \ getnameinfo \ @@ -532,7 +585,6 @@ AC_CHECK_FUNCS([ \ getpeereid \ getspnam \ inet_aton \ - inet_net_pton \ inet_ntoa \ inet_ntop \ isblank \ @@ -542,6 +594,7 @@ AC_CHECK_FUNCS([ \ pledge \ pw_dup \ reallocarray \ + res_hnok \ setenv \ setlinebuf \ setproctitle \ diff --git a/openbsd-compat/Makefile.am b/openbsd-compat/Makefile.am index ea004171..3a461820 100644 --- a/openbsd-compat/Makefile.am +++ b/openbsd-compat/Makefile.am @@ -1,10 +1,10 @@ noinst_LIBRARIES = libopenbsd-compat.a libopenbsd_compat_a_SOURCES = \ - arc4random.c base64.c bsd-closefrom.c \ + arc4random.c base64.c \ bsd-getpeereid.c bsd-misc.c bsd-waitpid.c \ - entropy.c errc.c event_asr_run.c explicit_bzero.c \ - fgetln.c flock.c getopt.c imsg.c imsg-buffer.c \ + entropy.c errc.c event_asr_run.c \ + fgetln.c getopt.c imsg.c imsg-buffer.c \ libressl.c pidfile.c pw_dup.c reallocarray.c setresguid.c \ setproctitle.c strlcat.c strlcpy.c strmode.c strtonum.c \ strsep.c vis.c xmalloc.c @@ -17,6 +17,10 @@ if !SUPPORT_CLOCK_GETTIME libopenbsd_compat_a_SOURCES += clock_gettime.c endif +if !SUPPORT_CLOSEFROM +libopenbsd_compat_a_SOURCES += bsd-closefrom.c +endif + if !SUPPORT_DAEMON libopenbsd_compat_a_SOURCES += daemon.c endif @@ -25,14 +29,30 @@ if !SUPPORT_DIRNAME libopenbsd_compat_a_SOURCES += dirname.c endif +if !SUPPORT_ERRC +libopenbsd_compat_a_SOURCES += errc.c +endif + +if !SUPPORT_EXPLICIT_BZERO +libopenbsd_compat_a_SOURCES += explicit_bzero.c +endif + if !SUPPORT_FMT_SCALED libopenbsd_compat_a_SOURCES += fmt_scaled.c endif +if !SUPPORT_FLOCK +libopenbsd_compat_a_SOURCES += flock.c +endif + if !SUPPORT_FPARSELN libopenbsd_compat_a_SOURCES += fparseln.c endif +if !SUPPORT_GETLINE +libopenbsd_compat_a_SOURCES += getline.c +endif + if !SUPPORT_INET_NET_PTON libopenbsd_compat_a_SOURCES += inet_net_pton.c endif diff --git a/openbsd-compat/defines.h b/openbsd-compat/defines.h index bda39e99..3ffcc81c 100644 --- a/openbsd-compat/defines.h +++ b/openbsd-compat/defines.h @@ -422,15 +422,6 @@ typedef uint16_t in_port_t; #define INET6_ADDRSTRLEN 46 #endif -/* - * Platforms that have arc4random_uniform() and not arc4random_stir() - * shouldn't need the latter. - */ -#if defined(HAVE_ARC4RANDOM) && defined(HAVE_ARC4RANDOM_UNIFORM) && \ - !defined(HAVE_ARC4RANDOM_STIR) -# define arc4random_stir() -#endif - #ifndef HAVE_VA_COPY # ifdef HAVE___VA_COPY # define va_copy(dest, src) __va_copy(dest, src) @@ -512,4 +503,8 @@ typedef uint16_t in_port_t; #define LOCK_UN 0x08 /* unlock file */ #endif +#if !HAVE_DECL_LOG_PERROR +#define LOG_PERROR 0 +#endif + #endif /* _DEFINES_H */ diff --git a/openbsd-compat/errc.c b/openbsd-compat/errc.c index 13617772..985101dc 100644 --- a/openbsd-compat/errc.c +++ b/openbsd-compat/errc.c @@ -19,7 +19,6 @@ /* OPENBSD ORIGINAL: lib/libc/gen/errc.c */ #include "includes.h" -#ifndef HAVE_ERRC #include <errno.h> #include <stdarg.h> #include <stdio.h> @@ -49,5 +48,3 @@ errc(int eval, int code, const char *fmt, ...) _verrc(eval, code, fmt, ap); va_end(ap); } - -#endif /* !defined(HAVE_ERRC) */ diff --git a/openbsd-compat/explicit_bzero.c b/openbsd-compat/explicit_bzero.c index 7abb7bf1..22efe18b 100644 --- a/openbsd-compat/explicit_bzero.c +++ b/openbsd-compat/explicit_bzero.c @@ -1,21 +1,13 @@ -/* OPENBSD ORIGINAL: lib/libc/string/explicit_bzero.c */ -/* $OpenBSD: explicit_bzero.c,v 1.1 2014/01/22 21:06:45 tedu Exp $ */ +/* $OpenBSD: explicit_bzero.c,v 1.4 2015/08/31 02:53:57 guenther Exp $ */ /* * Public domain. - * Written by Ted Unangst + * Written by Matthew Dempsky. */ -#include "includes.h" +#include <string.h> -#ifndef HAVE_EXPLICIT_BZERO -#include <strings.h> - -/* - * explicit_bzero - don't let the compiler optimize away bzero - */ void -explicit_bzero(void *p, size_t n) +explicit_bzero(void *buf, size_t len) { - bzero(p, n); + memset(buf, 0, len); } -#endif diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h index 693bc0cb..1627d5c8 100644 --- a/openbsd-compat/openbsd-compat.h +++ b/openbsd-compat/openbsd-compat.h @@ -119,20 +119,25 @@ int BSDoptind; /* index into parent argv vector */ int getpeereid(int , uid_t *, gid_t *); #endif -#ifdef HAVE_ARC4RANDOM -# ifndef HAVE_ARC4RANDOM_STIR -# define arc4random_stir() -# endif -#else +#if !defined(HAVE_ARC4RANDOM) || defined(LIBRESSL_VERSION_NUMBER) unsigned int arc4random(void); +#endif + +#if defined(HAVE_ARC4RANDOM_STIR) void arc4random_stir(void); -#endif /* !HAVE_ARC4RANDOM */ +#elif defined(HAVE_ARC4RANDOM) || defined(LIBRESSL_VERSION_NUMBER) +/* Recent system/libressl implementation; no need for explicit stir */ +# define arc4random_stir() +#else +/* openbsd-compat/arc4random.c provides arc4random_stir() */ +void arc4random_stir(void); +#endif -#ifndef HAVE_ARC4RANDOM_BUF +#if !defined(HAVE_ARC4RANDOM_BUF) || defined(LIBRESSL_VERSION_NUMBER) void arc4random_buf(void *, size_t); #endif -#ifndef HAVE_ARC4RANDOM_UNIFORM +#if !defined(HAVE_ARC4RANDOM_UNIFORM) || defined(LIBRESSL_VERSION_NUMBER) uint32_t arc4random_uniform(uint32_t); #endif @@ -174,7 +179,7 @@ int vasprintf(char **, const char *, va_list); int vsnprintf(char *, size_t, const char *, va_list); #endif -#ifndef HAVE_EXPLICIT_BZERO +#if !defined(HAVE_EXPLICIT_BZERO) || defined(LIBRESSL_VERSION_NUMBER) void explicit_bzero(void *p, size_t n); #endif @@ -200,7 +205,7 @@ int pidfile(const char *basename); struct passwd *pw_dup(const struct passwd *); #endif -#ifndef HAVE_REALLOCARRAY +#if !defined(HAVE_REALLOCARRAY) || defined(LIBRESSL_VERSION_NUMBER) void *reallocarray(void *, size_t, size_t); #endif @@ -208,10 +213,18 @@ void *reallocarray(void *, size_t, size_t); void errc(int, int, const char *, ...); #endif +#ifndef HAVE_INET_NET_PTON +int inet_net_pton(int, const char *, void *, size_t); +#endif + #ifndef HAVE_PLEDGE #define pledge(promises, paths) 0 #endif +#ifndef HAVE_RES_HNOK +int res_hnok(const char *); +#endif + #if !HAVE_DECL_AF_LOCAL #define AF_LOCAL AF_UNIX #endif @@ -235,4 +248,8 @@ int setresgid(uid_t, uid_t, uid_t); #ifndef HAVE_SETRESUID int setresuid(uid_t, uid_t, uid_t); #endif + +#ifndef HAVE_GETLINE +ssize_t getline(char **, size_t *, FILE *); +#endif #endif /* _OPENBSD_COMPAT_H */ diff --git a/smtpd/smtpd.c b/smtpd/smtpd.c index 92df3cc6..78d234a9 100644 --- a/smtpd/smtpd.c +++ b/smtpd/smtpd.c @@ -864,8 +864,7 @@ start_child(int save_argc, char **save_argv, char *rexec) if (dup2(sp[0], 3) == -1) fatal("%s: dup2", rexec); - if (closefrom(4) == -1) - fatal("%s: closefrom", rexec); + xclosefrom(4); for (argc = 0; argc < save_argc; argc++) argv[argc] = save_argv[argc]; @@ -1514,8 +1513,6 @@ offline_enqueue(char *name) setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid)) _exit(1); - closefrom(STDERR_FILENO + 1); - if ((fp = fdopen(fd, "r")) == NULL) _exit(1); diff --git a/smtpd/smtpd.h b/smtpd/smtpd.h index 4617361e..79491913 100644 --- a/smtpd/smtpd.h +++ b/smtpd/smtpd.h @@ -1529,7 +1529,7 @@ int session_socket_error(int); int getmailname(char *, size_t); int base64_encode(unsigned char const *, size_t, char *, size_t); int base64_decode(char const *, unsigned char *, size_t); - +void xclosefrom(int); /* waitq.c */ int waitq_wait(void *, void (*)(void *, void *, void *), void *); diff --git a/smtpd/util.c b/smtpd/util.c index 1ce04dfa..d57239cd 100644 --- a/smtpd/util.c +++ b/smtpd/util.c @@ -816,3 +816,14 @@ log_trace_verbose(int v) /* Set debug logging in log.c */ log_setverbose(v & TRACE_DEBUG ? 2 : foreground_log); } + +void +xclosefrom(int lowfd) +{ +#if defined HAVE_CLOSEFROM_INT + if (closefrom(lowfd) == -1) + err(1, "closefrom"); +#else + closefrom(lowfd); +#endif +} |