From b3ca3aa12f8248c2d9e23f15a46e0f3c97397e54 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Mon, 22 Nov 1999 13:57:07 +1100 Subject: - Added OpenBSD bsd-strlcat.c, created bsd-strlcat.h - Added timersum() macro - Tidy RCSIDs of bsd-*.c --- ChangeLog | 3 +++ Makefile.in | 6 ++--- acconfig.h | 17 +++++++++++++ bsd-login.c | 2 +- bsd-strlcat.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ bsd-strlcat.h | 10 ++++++++ configure.in | 4 ++-- includes.h | 5 +++- 8 files changed, 116 insertions(+), 7 deletions(-) create mode 100644 bsd-strlcat.c create mode 100644 bsd-strlcat.h diff --git a/ChangeLog b/ChangeLog index 980331711..4c016a32b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ don't create ~/.ssh only if the user wants to store the private key there. show fingerprint instead of public-key after keygeneration. ok niels@ + - Added OpenBSD bsd-strlcat.c, created bsd-strlcat.h + - Added timersum() macro + - Tidy RCSIDs of bsd-*.c 19991121 - OpenBSD CVS Changes: diff --git a/Makefile.in b/Makefile.in index b338c9ca8..4400c258c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -28,12 +28,12 @@ OBJS= authfd.o authfile.o auth-passwd.o auth-rhosts.o auth-rh-rsa.o \ hostfile.o log-client.o login.o log-server.o match.o mpaux.o \ packet.o pty.o readconf.o readpass.o rsa.o servconf.o serverloop.o \ sshconnect.o tildexpand.o ttymodes.o uidswap.o xmalloc.o \ - helper.o bsd-mktemp.o bsd-strlcpy.o bsd-daemon.o bsd-login.o rc4.o \ - md5crypt.o + helper.o bsd-mktemp.o bsd-strlcpy.o bsd-strlcat.o bsd-daemon.o \ + bsd-login.o rc4.o md5crypt.o all: $(OBJS) $(TARGETS) -libssh.a: authfd.o authfile.o bufaux.o buffer.o canohost.o channels.o cipher.o compat.o compress.o crc32.o deattack.o hostfile.o match.o mpaux.o nchan.o packet.o readpass.o rsa.o tildexpand.o ttymodes.o uidswap.o xmalloc.o helper.o rc4.o bsd-mktemp.o bsd-strlcpy.o log.o fingerprint.o +libssh.a: authfd.o authfile.o bufaux.o buffer.o canohost.o channels.o cipher.o compat.o compress.o crc32.o deattack.o hostfile.o match.o mpaux.o nchan.o packet.o readpass.o rsa.o tildexpand.o ttymodes.o uidswap.o xmalloc.o helper.o rc4.o bsd-mktemp.o bsd-strlcpy.o bsd-strlcat.o log.o fingerprint.o $(AR) rv $@ $^ $(RANLIB) $@ diff --git a/acconfig.h b/acconfig.h index a37c0823c..db7fd18b1 100644 --- a/acconfig.h +++ b/acconfig.h @@ -71,6 +71,10 @@ # include /* For _PATH_XXX */ #endif +#ifdef HAVE_SYS_TIME_H +# include /* For timersub */ +#endif + #ifndef SHUT_RDWR enum { @@ -178,3 +182,16 @@ enum # define MAX(a,b) (((a)>(b))?(a):(b)) # define MIN(a,b) (((a)<(b))?(a):(b)) #endif + +#ifndef timersub +#define timersub(a, b, result) \ + do { \ + (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ + (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ + if ((result)->tv_usec < 0) { \ + --(result)->tv_sec; \ + (result)->tv_usec += 1000000; \ + } \ + } while (0) + +#endif diff --git a/bsd-login.c b/bsd-login.c index 98010ec3c..93f230266 100644 --- a/bsd-login.c +++ b/bsd-login.c @@ -37,7 +37,7 @@ #if defined(LIBC_SCCS) && !defined(lint) /* from: static char sccsid[] = "@(#)login.c 8.1 (Berkeley) 6/4/93"; */ -static char *rcsid = "$Id: bsd-login.c,v 1.2 1999/11/20 01:18:40 damien Exp $"; +static char *rcsid = "$OpenBSD: login.c,v 1.5 1998/07/13 02:11:12 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include diff --git a/bsd-strlcat.c b/bsd-strlcat.c new file mode 100644 index 000000000..10ad9e71a --- /dev/null +++ b/bsd-strlcat.c @@ -0,0 +1,76 @@ +/* $OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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 "config.h" +#ifndef HAVE_STRLCAT + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t strlcat(dst, src, siz) + char *dst; + const char *src; + size_t siz; +{ + register char *d = dst; + register const char *s = src; + register size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (*d != '\0' && n-- != 0) + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} + +#endif /* !HAVE_STRLCAT */ diff --git a/bsd-strlcat.h b/bsd-strlcat.h new file mode 100644 index 000000000..562dc7045 --- /dev/null +++ b/bsd-strlcat.h @@ -0,0 +1,10 @@ +#ifndef _BSD_STRLCAT_H +#define _BSD_STRLCAT_H + +#include "config.h" +#ifndef HAVE_STRLCAT +#include +size_t strlcat(char *dst, const char *src, size_t siz); +#endif /* !HAVE_STRLCAT */ + +#endif /* _BSD_STRLCAT_H */ diff --git a/configure.in b/configure.in index 2a4a2c7de..1fe0c30b4 100644 --- a/configure.in +++ b/configure.in @@ -55,10 +55,10 @@ AC_CHECK_LIB(dl, dlopen, , ) AC_CHECK_LIB(pam, pam_authenticate, , ) dnl Checks for header files. -AC_CHECK_HEADERS(pty.h endian.h paths.h lastlog.h shadow.h netgroup.h maillock.h sys/select.h) +AC_CHECK_HEADERS(pty.h endian.h paths.h lastlog.h shadow.h netgroup.h maillock.h sys/select.h sys/time.h) dnl Checks for library functions. -AC_CHECK_FUNCS(openpty strlcpy mkdtemp arc4random setproctitle setlogin) +AC_CHECK_FUNCS(openpty strlcpy strlcat mkdtemp arc4random setproctitle setlogin) AC_CHECK_FUNC(login, [AC_DEFINE(HAVE_LOGIN)], diff --git a/includes.h b/includes.h index 06245fdce..722c6b3bd 100644 --- a/includes.h +++ b/includes.h @@ -27,7 +27,6 @@ static /**/const char *const rcsid[] = { (char *)rcsid, "\100(#)" msg } #include #include #include -#include #include #include @@ -65,6 +64,9 @@ static /**/const char *const rcsid[] = { (char *)rcsid, "\100(#)" msg } #ifdef HAVE_SYS_SELECT_H # include #endif +#ifdef HAVE_SYS_TIME_H +# include +#endif #ifdef HAVE_LIBPAM # include #endif @@ -72,6 +74,7 @@ static /**/const char *const rcsid[] = { (char *)rcsid, "\100(#)" msg } #include "version.h" #include "helper.h" #include "bsd-strlcpy.h" +#include "bsd-strlcat.h" #include "bsd-mktemp.h" /* Define this to be the path of the xauth program. */ -- cgit v1.2.3