diff options
Diffstat (limited to 'crypto/openssh/openbsd-compat')
-rw-r--r-- | crypto/openssh/openbsd-compat/arc4random.c | 12 | ||||
-rw-r--r-- | crypto/openssh/openbsd-compat/arc4random.h | 10 | ||||
-rw-r--r-- | crypto/openssh/openbsd-compat/bsd-getentropy.c | 7 | ||||
-rw-r--r-- | crypto/openssh/openbsd-compat/bsd-poll.c | 38 | ||||
-rw-r--r-- | crypto/openssh/openbsd-compat/bsd-poll.h | 25 | ||||
-rw-r--r-- | crypto/openssh/openbsd-compat/bsd-timegm.c | 52 | ||||
-rw-r--r-- | crypto/openssh/openbsd-compat/getrrsetbyname.c | 12 | ||||
-rw-r--r-- | crypto/openssh/openbsd-compat/openbsd-compat.h | 5 | ||||
-rw-r--r-- | crypto/openssh/openbsd-compat/regress/Makefile.in | 7 | ||||
-rw-r--r-- | crypto/openssh/openbsd-compat/regress/opensslvertest.c | 2 |
10 files changed, 94 insertions, 76 deletions
diff --git a/crypto/openssh/openbsd-compat/arc4random.c b/crypto/openssh/openbsd-compat/arc4random.c index 02f15f9c3bfa..ffd33734db56 100644 --- a/crypto/openssh/openbsd-compat/arc4random.c +++ b/crypto/openssh/openbsd-compat/arc4random.c @@ -44,13 +44,15 @@ #ifndef HAVE_ARC4RANDOM /* - * If we're not using a native getentropy, use the one from bsd-getentropy.c - * under a different name, so that if in future these binaries are run on - * a system that has a native getentropy OpenSSL cannot call the wrong one. + * Always use the getentropy implementation from bsd-getentropy.c, which + * will call a native getentropy if available then fall back as required. + * We use a different name so that OpenSSL cannot call the wrong getentropy. */ -#ifndef HAVE_GETENTROPY -# define getentropy(x, y) (_ssh_compat_getentropy((x), (y))) +int _ssh_compat_getentropy(void *, size_t); +#ifdef getentropy +# undef getentropy #endif +#define getentropy(x, y) (_ssh_compat_getentropy((x), (y))) #include "log.h" diff --git a/crypto/openssh/openbsd-compat/arc4random.h b/crypto/openssh/openbsd-compat/arc4random.h index 2b57611f060c..5af3a4492a82 100644 --- a/crypto/openssh/openbsd-compat/arc4random.h +++ b/crypto/openssh/openbsd-compat/arc4random.h @@ -63,6 +63,7 @@ _rs_forkdetect(void) static inline int _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) { +#if defined(MAP_ANON) && defined(MAP_PRIVATE) if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) return (-1); @@ -73,6 +74,15 @@ _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) *rsp = NULL; return (-1); } +#else + if ((*rsp = calloc(1, sizeof(**rsp))) == NULL) + return (-1); + if ((*rsxp = calloc(1, sizeof(**rsxp))) == NULL) { + free(*rsp); + *rsp = NULL; + return (-1); + } +#endif _ARC4_ATFORK(_rs_forkhandler); return (0); diff --git a/crypto/openssh/openbsd-compat/bsd-getentropy.c b/crypto/openssh/openbsd-compat/bsd-getentropy.c index bd4b6695acc6..554dfad70524 100644 --- a/crypto/openssh/openbsd-compat/bsd-getentropy.c +++ b/crypto/openssh/openbsd-compat/bsd-getentropy.c @@ -18,8 +18,6 @@ #include "includes.h" -#ifndef HAVE_GETENTROPY - #ifndef SSH_RANDOM_DEV # define SSH_RANDOM_DEV "/dev/urandom" #endif /* SSH_RANDOM_DEV */ @@ -52,6 +50,10 @@ _ssh_compat_getentropy(void *s, size_t len) ssize_t r; size_t o = 0; +#ifdef HAVE_GETENTROPY + if (r = getentropy(s, len) == 0) + return 0; +#endif /* HAVE_GETENTROPY */ #ifdef HAVE_GETRANDOM if ((r = getrandom(s, len, 0)) > 0 && (size_t)r == len) return 0; @@ -79,4 +81,3 @@ _ssh_compat_getentropy(void *s, size_t len) #endif /* WITH_OPENSSL */ return 0; } -#endif /* WITH_GETENTROPY */ diff --git a/crypto/openssh/openbsd-compat/bsd-poll.c b/crypto/openssh/openbsd-compat/bsd-poll.c index 9a9794f5863b..967f947b21fd 100644 --- a/crypto/openssh/openbsd-compat/bsd-poll.c +++ b/crypto/openssh/openbsd-compat/bsd-poll.c @@ -47,9 +47,8 @@ ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmoutp, const sigset_t *sigmask) { nfds_t i; - int saved_errno, ret, fd, maxfd = 0; - fd_set *readfds = NULL, *writefds = NULL, *exceptfds = NULL; - size_t nmemb; + int ret, fd, maxfd = 0; + fd_set readfds, writefds, exceptfds; for (i = 0; i < nfds; i++) { fd = fds[i].fd; @@ -60,30 +59,23 @@ ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmoutp, maxfd = MAX(maxfd, fd); } - nmemb = howmany(maxfd + 1 , NFDBITS); - if ((readfds = calloc(nmemb, sizeof(fd_mask))) == NULL || - (writefds = calloc(nmemb, sizeof(fd_mask))) == NULL || - (exceptfds = calloc(nmemb, sizeof(fd_mask))) == NULL) { - saved_errno = ENOMEM; - ret = -1; - goto out; - } - /* populate event bit vectors for the events we're interested in */ + FD_ZERO(&readfds); + FD_ZERO(&writefds); + FD_ZERO(&exceptfds); for (i = 0; i < nfds; i++) { fd = fds[i].fd; if (fd == -1) continue; if (fds[i].events & POLLIN) - FD_SET(fd, readfds); + FD_SET(fd, &readfds); if (fds[i].events & POLLOUT) - FD_SET(fd, writefds); + FD_SET(fd, &writefds); if (fds[i].events & POLLPRI) - FD_SET(fd, exceptfds); + FD_SET(fd, &exceptfds); } - ret = pselect(maxfd + 1, readfds, writefds, exceptfds, tmoutp, sigmask); - saved_errno = errno; + ret = pselect(maxfd + 1, &readfds, &writefds, &exceptfds, tmoutp, sigmask); /* scan through select results and set poll() flags */ for (i = 0; i < nfds; i++) { @@ -91,20 +83,14 @@ ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmoutp, fds[i].revents = 0; if (fd == -1) continue; - if ((fds[i].events & POLLIN) && FD_ISSET(fd, readfds)) + if ((fds[i].events & POLLIN) && FD_ISSET(fd, &readfds)) fds[i].revents |= POLLIN; - if ((fds[i].events & POLLOUT) && FD_ISSET(fd, writefds)) + if ((fds[i].events & POLLOUT) && FD_ISSET(fd, &writefds)) fds[i].revents |= POLLOUT; - if ((fds[i].events & POLLPRI) && FD_ISSET(fd, exceptfds)) + if ((fds[i].events & POLLPRI) && FD_ISSET(fd, &exceptfds)) fds[i].revents |= POLLPRI; } -out: - free(readfds); - free(writefds); - free(exceptfds); - if (ret == -1) - errno = saved_errno; return ret; } #endif /* !HAVE_PPOLL || BROKEN_POLL */ diff --git a/crypto/openssh/openbsd-compat/bsd-poll.h b/crypto/openssh/openbsd-compat/bsd-poll.h index 586647ee1aff..ae865a6e2622 100644 --- a/crypto/openssh/openbsd-compat/bsd-poll.h +++ b/crypto/openssh/openbsd-compat/bsd-poll.h @@ -44,12 +44,25 @@ typedef struct pollfd { short revents; } pollfd_t; -#define POLLIN 0x0001 -#define POLLPRI 0x0002 -#define POLLOUT 0x0004 -#define POLLERR 0x0008 -#define POLLHUP 0x0010 -#define POLLNVAL 0x0020 +#ifndef POLLIN +# define POLLIN 0x0001 +#endif +#ifndef POLLPRI +# define POLLPRI 0x0002 +#endif +#ifndef POLLOUT +# define POLLOUT 0x0004 +#endif +#ifndef POLLERR +# define POLLERR 0x0008 +#endif +#ifndef POLLHUP +# define POLLHUP 0x0010 +#endif +#ifndef POLLNVAL +# define POLLNVAL 0x0020 +#endif + #if 0 /* the following are currently not implemented */ #define POLLRDNORM 0x0040 diff --git a/crypto/openssh/openbsd-compat/bsd-timegm.c b/crypto/openssh/openbsd-compat/bsd-timegm.c index 14f6bbf14dad..246724bd6236 100644 --- a/crypto/openssh/openbsd-compat/bsd-timegm.c +++ b/crypto/openssh/openbsd-compat/bsd-timegm.c @@ -1,34 +1,34 @@ /* * Copyright (c) 1997 Kungliga Tekniska Högskolan - * (Royal Institute of Technology, Stockholm, Sweden). - * All rights reserved. + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * 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. + * 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. + * 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 Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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. */ /* @@ -64,10 +64,10 @@ time_t timegm(struct tm *tm) /* invalid tm structure */ return 0; } - + for (i = 70; i < tm->tm_year; ++i) res += is_leap(i) ? 366 : 365; - + for (i = 0; i < tm->tm_mon; ++i) res += ndays[is_leap(tm->tm_year)][i]; res += tm->tm_mday - 1; diff --git a/crypto/openssh/openbsd-compat/getrrsetbyname.c b/crypto/openssh/openbsd-compat/getrrsetbyname.c index cc1f8ae519eb..73de5e9482b8 100644 --- a/crypto/openssh/openbsd-compat/getrrsetbyname.c +++ b/crypto/openssh/openbsd-compat/getrrsetbyname.c @@ -116,8 +116,14 @@ struct __res_state _res; #if !defined(HAVE__GETSHORT) || !defined(HAVE__GETLONG) || \ !defined(HAVE_DECL__GETSHORT) || HAVE_DECL__GETSHORT == 0 || \ !defined(HAVE_DECL__GETLONG) || HAVE_DECL__GETLONG == 0 -#define _getshort(x) (_ssh_compat_getshort(x)) -#define _getlong(x) (_ssh_compat_getlong(x)) +# ifdef _getshort +# undef _getshort +# endif +# ifdef _getlong +# undef _getlong +# endif +# define _getshort(x) (_ssh_compat_getshort(x)) +# define _getlong(x) (_ssh_compat_getlong(x)) /* * Routines to insert/extract short/long's. */ @@ -138,7 +144,7 @@ _getlong(const u_char *msgp) GETLONG(u, msgp); return (u); } -#endif +#endif /* missing _getshort/_getlong */ /* ************** */ diff --git a/crypto/openssh/openbsd-compat/openbsd-compat.h b/crypto/openssh/openbsd-compat/openbsd-compat.h index 4af207cdd40f..895ecf9ea111 100644 --- a/crypto/openssh/openbsd-compat/openbsd-compat.h +++ b/crypto/openssh/openbsd-compat/openbsd-compat.h @@ -69,10 +69,6 @@ void closefrom(int); int ftruncate(int filedes, off_t length); #endif -#if defined(HAVE_DECL_GETENTROPY) && HAVE_DECL_GETENTROPY == 0 -int _ssh_compat_getentropy(void *, size_t); -#endif - #ifndef HAVE_GETLINE #include <stdio.h> ssize_t getline(char **, size_t *, FILE *); @@ -343,6 +339,7 @@ struct tm *localtime_r(const time_t *, struct tm *); #endif #ifndef HAVE_TIMEGM +#include <time.h> time_t timegm(struct tm *); #endif diff --git a/crypto/openssh/openbsd-compat/regress/Makefile.in b/crypto/openssh/openbsd-compat/regress/Makefile.in index dd8cdc4b7e7a..6fabca849e66 100644 --- a/crypto/openssh/openbsd-compat/regress/Makefile.in +++ b/crypto/openssh/openbsd-compat/regress/Makefile.in @@ -10,7 +10,8 @@ CFLAGS=@CFLAGS@ CPPFLAGS=-I. -I.. -I../.. -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../.. @CPPFLAGS@ @DEFS@ EXEEXT=@EXEEXT@ LIBCOMPAT=../libopenbsd-compat.a -LIBS=@LIBS@ +LIBSSH=../../libssh.a +LIBS=@LIBS@ @CHANNELLIBS@ LDFLAGS=@LDFLAGS@ $(LIBCOMPAT) TESTPROGS=closefromtest$(EXEEXT) snprintftest$(EXEEXT) strduptest$(EXEEXT) \ @@ -18,8 +19,8 @@ TESTPROGS=closefromtest$(EXEEXT) snprintftest$(EXEEXT) strduptest$(EXEEXT) \ all: t-exec ${OTHERTESTS} -%$(EXEEXT): %.c $(LIBCOMPAT) - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $< $(LIBCOMPAT) $(LIBS) +.c: $(LIBCOMPAT) $(LIBSSH) + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $< $(LIBCOMPAT) $(LIBSSH) $(LIBS) t-exec: $(TESTPROGS) @echo running compat regress tests diff --git a/crypto/openssh/openbsd-compat/regress/opensslvertest.c b/crypto/openssh/openbsd-compat/regress/opensslvertest.c index 43825b24c3eb..d50066609612 100644 --- a/crypto/openssh/openbsd-compat/regress/opensslvertest.c +++ b/crypto/openssh/openbsd-compat/regress/opensslvertest.c @@ -56,6 +56,7 @@ fail(long hver, long lver, int result) int main(void) { +#ifdef WITH_OPENSSL unsigned int i; int res; long hver, lver; @@ -67,5 +68,6 @@ main(void) if (ssh_compatible_openssl(hver, lver) != res) fail(hver, lver, res); } +#endif exit(0); } |