From beb43d315bfc692a8646c5b6dacf409f6141b289 Mon Sep 17 00:00:00 2001 From: damien Date: Fri, 19 Nov 1999 04:32:34 +0000 Subject: [PATCH] - Renamed BSD helper function files to bsd-* - Added tests for login and daemon and OpenBSD replacements for when they are absent. --- ChangeLog | 3 ++ Makefile.in | 6 +-- README | 17 ++++---- acconfig.h | 6 +++ bsd-daemon.c | 78 +++++++++++++++++++++++++++++++++++ bsd-daemon.h | 9 +++++ bsd-login.c | 83 ++++++++++++++++++++++++++++++++++++++ bsd-login.h | 13 ++++++ mktemp.c => bsd-mktemp.c | 7 ++-- mktemp.h => bsd-mktemp.h | 6 +-- strlcpy.c => bsd-strlcpy.c | 6 +-- strlcpy.h => bsd-strlcpy.h | 7 ++-- configure.in | 12 +++++- includes.h | 6 +-- 14 files changed, 232 insertions(+), 27 deletions(-) create mode 100644 bsd-daemon.c create mode 100644 bsd-daemon.h create mode 100644 bsd-login.c create mode 100644 bsd-login.h rename mktemp.c => bsd-mktemp.c (99%) rename mktemp.h => bsd-mktemp.h (68%) rename strlcpy.c => bsd-strlcpy.c (100%) rename strlcpy.h => bsd-strlcpy.h (56%) diff --git a/ChangeLog b/ChangeLog index 6b02ba1a..b92f9bfa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,9 @@ - Added autoconf option to enable AFS support (untested) - Added autoconf option to enable S/Key support (untested) - Added autoconf option to enable TCP wrappers support (compiles OK) + - Renamed BSD helper function files to bsd-* + - Added tests for login and daemon and OpenBSD replacements for when they + are absent. 19991118 - Merged OpenBSD CVS changes diff --git a/Makefile.in b/Makefile.in index 4daa810e..fec1d130 100644 --- a/Makefile.in +++ b/Makefile.in @@ -27,18 +27,18 @@ 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 mktemp.o strlcpy.o rc4.o + helper.o bsd-mktemp.o bsd-strlcpy.o bsd-daemon.o bsd-login.o rc4.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 mktemp.o 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 log.o fingerprint.o $(AR) rv $@ $^ $(RANLIB) $@ ssh: ssh.o sshconnect.o log-client.o readconf.o clientloop.o libssh.a $(CC) -o $@ $^ $(LFLAGS) $(LIBS) -sshd: sshd.o auth-rhosts.o auth-passwd.o auth-rsa.o auth-rh-rsa.o pty.o log-server.o login.o servconf.o serverloop.o libssh.a +sshd: sshd.o auth-rhosts.o auth-passwd.o auth-rsa.o auth-rh-rsa.o pty.o log-server.o login.o servconf.o serverloop.o bsd-login.o bsd-daemon.o libssh.a $(CC) -o $@ $^ $(LFLAGS) $(LIBS) scp: scp.o libssh.a diff --git a/README b/README index c9427da2..f6dbcdd5 100644 --- a/README +++ b/README @@ -10,9 +10,9 @@ Niels Provos, Theo de Raadt, and Dug Song. It has a homepage at http://www.openssh.com/ This port consists of the re-introduction of autoconf support, PAM -support (for Linux and Solaris), EGD[1] support, and replacements for -OpenBSD library functions that are (regrettably) absent from most -other unices. This patch has been best tested on Linux, though some +support (for Linux and Solaris), EGD[1] support, and replacements +for OpenBSD library functions that are (regrettably) absent from +other unices. This port has been best tested on Linux, though some Solaris support is beginning to filter in. This version actively tracks changes in the OpenBSD CVS repository. @@ -22,8 +22,8 @@ all logins, not just when using password authentication. All new code is released under a XFree style license, which is very liberal. Please refer to the source files for details. The code in -strlcpy.c and mktemp.c is from the OpenBSD project and has its own -license (again, see source file for details). +bsd-*.[ch] is from the OpenBSD project and has its own license (again, +see the source files for details). OpenSSH depends on Zlib[2], OpenSSL[3] and optionally PAM[4]. To build the GNOME[5] pass-phrase requester (--with-gnome-askpass), you will @@ -52,13 +52,14 @@ Credits - Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo de Raadt, and Dug Song - Creators of OpenSSH 'jonchen' - the original author of PAM support of SSH +Chip Salzenberg - Assorted patches Dan Brosemer - Autoconf and build fixes & Debian scripts +Jim Knoble - RPM spec file fixes +Marc G. Fournier - Solaris patches Nalin Dahyabhai - PAM environment patch -Phil Hands - Debian scripts, assorted patches Niels Kristian Bech Jensen - Assorted patches -Marc G. Fournier - Solaris patches +Phil Hands - Debian scripts, assorted patches Thomas Neumann - Shadow passwords -Jim Knoble - RPM spec file fixes Miscellania - diff --git a/acconfig.h b/acconfig.h index 44c5c1a1..2732c26c 100644 --- a/acconfig.h +++ b/acconfig.h @@ -42,6 +42,12 @@ /* Define if you want TCP Wrappers support */ #undef LIBWRAP +/* Define if your libraries define login() */ +#undef HAVE_LOGIN + +/* Define if your libraries define daemon() */ +#undef HAVE_DAEMON + @BOTTOM@ /* ******************* Shouldn't need to edit below this line ************** */ diff --git a/bsd-daemon.c b/bsd-daemon.c new file mode 100644 index 00000000..7b292c12 --- /dev/null +++ b/bsd-daemon.c @@ -0,0 +1,78 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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. + */ + +#include "config.h" + +#ifndef HAVE_DAEMON + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: daemon.c,v 1.2 1996/08/19 08:22:13 tholo Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include + +int +daemon(nochdir, noclose) + int nochdir, noclose; +{ + int fd; + + switch (fork()) { + case -1: + return (-1); + case 0: + break; + default: + _exit(0); + } + + if (setsid() == -1) + return (-1); + + if (!nochdir) + (void)chdir("/"); + + if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { + (void)dup2(fd, STDIN_FILENO); + (void)dup2(fd, STDOUT_FILENO); + (void)dup2(fd, STDERR_FILENO); + if (fd > 2) + (void)close (fd); + } + return (0); +} + +#endif /* !HAVE_DAEMON */ + diff --git a/bsd-daemon.h b/bsd-daemon.h new file mode 100644 index 00000000..cd91ea07 --- /dev/null +++ b/bsd-daemon.h @@ -0,0 +1,9 @@ +#ifndef _BSD_DAEMON_H +#define _BSD_DAEMON_H + +#include "config.h" +#ifndef HAVE_DAEMON +int daemon(int nochdir, int noclose); +#endif /* !HAVE_DAEMON */ + +#endif /* _BSD_DAEMON_H */ diff --git a/bsd-login.c b/bsd-login.c new file mode 100644 index 00000000..4b6ebf14 --- /dev/null +++ b/bsd-login.c @@ -0,0 +1,83 @@ +/* $OpenBSD: login.c,v 1.5 1998/07/13 02:11:12 millert Exp $ */ +/* + * Copyright (c) 1988, 1993 + * The Regents of the University of California. 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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. + */ + +#include "config.h" +#ifndef HAVE_LOGIN + +#if defined(LIBC_SCCS) && !defined(lint) +/* from: static char sccsid[] = "@(#)login.c 8.1 (Berkeley) 6/4/93"; */ +static char *rcsid = "$Id$"; +#endif /* LIBC_SCCS and not lint */ + +#include + +#include +#include +#include +#include +#include + +void +login(utp) + struct utmp *utp; +{ + struct utmp old_ut; + register int fd; + int tty; + + tty = ttyslot(); + if (tty > 0 && (fd = open(_PATH_UTMP, O_RDWR|O_CREAT, 0644)) >= 0) { + (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET); + /* + * Prevent luser from zero'ing out ut_host. + * If the new ut_line is empty but the old one is not + * and ut_line and ut_name match, preserve the old ut_line. + */ + if (read(fd, &old_ut, sizeof(struct utmp)) == + sizeof(struct utmp) && utp->ut_host[0] == '\0' && + old_ut.ut_host[0] != '\0' && + strncmp(old_ut.ut_line, utp->ut_line, UT_LINESIZE) == 0 && + strncmp(old_ut.ut_name, utp->ut_name, UT_NAMESIZE) == 0) + (void)memcpy(utp->ut_host, old_ut.ut_host, UT_HOSTSIZE); + (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET); + (void)write(fd, utp, sizeof(struct utmp)); + (void)close(fd); + } + if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) >= 0) { + (void)write(fd, utp, sizeof(struct utmp)); + (void)close(fd); + } +} + +#endif /* HAVE_LOGIN */ diff --git a/bsd-login.h b/bsd-login.h new file mode 100644 index 00000000..26a8505b --- /dev/null +++ b/bsd-login.h @@ -0,0 +1,13 @@ +#ifndef _BSD_LOGIN_H +#define _BSD_LOGIN_H + +#include "config.h" +#ifndef HAVE_LOGIN + +#include + +void login(struct utmp *utp); + +#endif /* !HAVE_LOGIN */ + +#endif /* _BSD_LOGIN_H */ diff --git a/mktemp.c b/bsd-mktemp.c similarity index 99% rename from mktemp.c rename to bsd-mktemp.c index be03ac90..cdef62da 100644 --- a/mktemp.c +++ b/bsd-mktemp.c @@ -34,6 +34,10 @@ * SUCH DAMAGE. */ +#include "config.h" + +#ifndef HAVE_MKDTEMP + #if defined(LIBC_SCCS) && !defined(lint) static char rcsid[] = "$OpenBSD: mktemp.c,v 1.13 1998/06/30 23:03:13 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ @@ -47,11 +51,8 @@ static char rcsid[] = "$OpenBSD: mktemp.c,v 1.13 1998/06/30 23:03:13 deraadt Exp #include #include -#include "config.h" #include "helper.h" -#ifndef HAVE_MKDTEMP - static int _gettemp(char *, int *, int, int); int diff --git a/mktemp.h b/bsd-mktemp.h similarity index 68% rename from mktemp.h rename to bsd-mktemp.h index ac92cbae..faddc916 100644 --- a/mktemp.h +++ b/bsd-mktemp.h @@ -1,5 +1,5 @@ -#ifndef _MKTEMP_H -#define _MKTEMP_H +#ifndef _BSD_MKTEMP_H +#define _BSD_MKTEMP_H #include "config.h" #ifndef HAVE_MKDTEMP @@ -8,4 +8,4 @@ int mkstemp(char *path); char *mkdtemp(char *path); #endif /* !HAVE_MKDTEMP */ -#endif /* _MKTEMP_H */ +#endif /* _BSD_MKTEMP_H */ diff --git a/strlcpy.c b/bsd-strlcpy.c similarity index 100% rename from strlcpy.c rename to bsd-strlcpy.c index 4df4080d..276c25c3 100644 --- a/strlcpy.c +++ b/bsd-strlcpy.c @@ -27,6 +27,9 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" +#ifndef HAVE_STRLCPY + #if defined(LIBC_SCCS) && !defined(lint) static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $"; #endif /* LIBC_SCCS and not lint */ @@ -34,9 +37,6 @@ static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp #include #include -#include "config.h" -#ifndef HAVE_STRLCPY - /* * Copy src to string dst of size siz. At most siz-1 characters * will be copied. Always NUL terminates (unless siz == 0). diff --git a/strlcpy.h b/bsd-strlcpy.h similarity index 56% rename from strlcpy.h rename to bsd-strlcpy.h index 9afbd39c..dafa44af 100644 --- a/strlcpy.h +++ b/bsd-strlcpy.h @@ -1,9 +1,10 @@ -#ifndef _STRLCPY_H -#define _STRLCPY_H +#ifndef _BSD_STRLCPY_H +#define _BSD_STRLCPY_H #include "config.h" #ifndef HAVE_STRLCPY +#include size_t strlcpy(char *dst, const char *src, size_t siz); #endif /* !HAVE_STRLCPY */ -#endif /* _STRLCPY_H */ +#endif /* _BSD_STRLCPY_H */ diff --git a/configure.in b/configure.in index 0b54fd58..dd74b3b4 100644 --- a/configure.in +++ b/configure.in @@ -60,6 +60,16 @@ AC_CHECK_HEADERS(pty.h endian.h paths.h lastlog.h shadow.h netgroup.h maillock.h dnl Checks for library functions. AC_CHECK_FUNCS(openpty strlcpy mkdtemp arc4random setproctitle setlogin) +AC_CHECK_FUNC(login, + [AC_DEFINE(HAVE_LOGIN)], + [AC_CHECK_LIB(bsd, login, [LIBS="$LIBS -lbsd"; AC_DEFINE(HAVE_LOGIN)])] +) + +AC_CHECK_FUNC(daemon, + [AC_DEFINE(HAVE_DAEMON)], + [AC_CHECK_LIB(bsd, daemon, [LIBS="$LIBS -lbsd"; AC_DEFINE(HAVE_DAEMON)])] +) + dnl Check whether use wants to disable the external ssh-askpass INSTALL_ASKPASS="yes" AC_MSG_CHECKING([whether to enable external ssh-askpass support]) @@ -156,7 +166,7 @@ done AC_MSG_CHECKING([whether libc defines __progname]) AC_TRY_LINK([], - [extern char *__progname;], + [extern char *__progname; printf("%s", __progname);], [ AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes) diff --git a/includes.h b/includes.h index 75349cf3..06245fdc 100644 --- a/includes.h +++ b/includes.h @@ -67,12 +67,12 @@ static /**/const char *const rcsid[] = { (char *)rcsid, "\100(#)" msg } #endif #ifdef HAVE_LIBPAM # include -#endif /* HAVE_PAM */ +#endif #include "version.h" #include "helper.h" -#include "mktemp.h" -#include "strlcpy.h" +#include "bsd-strlcpy.h" +#include "bsd-mktemp.h" /* Define this to be the path of the xauth program. */ #ifndef XAUTH_PATH -- 2.45.2