From 3c06f6a0b234822c7b2d6c63ef1aaf554af7167b Mon Sep 17 00:00:00 2001 From: Ben Lindstrom Date: Wed, 31 Jan 2001 21:52:01 +0000 Subject: - (bal) Reorder. Move all bsd-*, fake-*, next-*, and cygwin* stuff to openbsd-compat/. And resolve all ./configure and Makefile.in issues assocated. Logic: * All OpenBSD functions should have the same filename as in the OpenBSD tree * All 'home brew' functions have bsd-* infront of them. * All 'not really implemented' functions have fake-* infront of them. --- openbsd-compat/bsd-misc.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 openbsd-compat/bsd-misc.c (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c new file mode 100644 index 00000000..2e59019b --- /dev/null +++ b/openbsd-compat/bsd-misc.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 1999-2000 Damien 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 "includes.h" +#include "xmalloc.h" +#include "ssh.h" + +char *get_progname(char *argv0) +{ +#ifdef HAVE___PROGNAME + extern char *__progname; + + return __progname; +#else + char *p; + + if (argv0 == NULL) + return "unknown"; /* XXX */ + p = strrchr(argv0, '/'); + if (p == NULL) + p = argv0; + else + p++; + return p; +#endif +} + +#ifndef HAVE_SETLOGIN +int setlogin(const char *name) +{ + return(0); +} +#endif /* !HAVE_SETLOGIN */ + +#ifndef HAVE_INNETGR +int innetgr(const char *netgroup, const char *host, + const char *user, const char *domain) +{ + return(0); +} +#endif /* HAVE_INNETGR */ + +#if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) +int seteuid(uid_t euid) +{ + return(setreuid(-1,euid)); +} +#endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) */ + +#if !defined(HAVE_STRERROR) && defined(HAVE_SYS_ERRLIST) && defined(HAVE_SYS_NERR) +const char *strerror(int e) +{ + extern int sys_nerr; + extern char *sys_errlist[]; + + if ((e >= 0) || (e < sys_nerr)) + return("unlisted error"); + else + return(sys_errlist[e]); +} +#endif + +#ifndef HAVE_UTIMES +int utimes(char *filename, struct timeval *tvp) +{ + struct utimbuf ub; + + ub.actime = tvp->tv_sec; + ub.modtime = tvp->tv_usec; + + return(utime(filename, &ub)); +} +#endif -- cgit v1.2.3 From e9cf357a99dcd2db14635974289e04f5f0808123 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Fri, 9 Feb 2001 12:55:35 +1100 Subject: - (djm) Add CVS Id's to files that we have missed --- openbsd-compat/bsd-misc.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 2e59019b..c0d2d65e 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -26,6 +26,8 @@ #include "xmalloc.h" #include "ssh.h" +RCSID("$Id: bsd-misc.c,v 1.2 2001/02/09 01:55:36 djm Exp $"); + char *get_progname(char *argv0) { #ifdef HAVE___PROGNAME -- cgit v1.2.3 From 46e55aaabc33549b91a85052aa048dffaf061761 Mon Sep 17 00:00:00 2001 From: Ben Lindstrom Date: Tue, 13 Mar 2001 23:38:20 +0000 Subject: - Fix strerror() in bsd-misc.c --- openbsd-compat/bsd-misc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index c0d2d65e..6f92e064 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -26,7 +26,7 @@ #include "xmalloc.h" #include "ssh.h" -RCSID("$Id: bsd-misc.c,v 1.2 2001/02/09 01:55:36 djm Exp $"); +RCSID("$Id: bsd-misc.c,v 1.3 2001/03/13 23:38:20 mouring Exp $"); char *get_progname(char *argv0) { @@ -76,10 +76,10 @@ const char *strerror(int e) extern int sys_nerr; extern char *sys_errlist[]; - if ((e >= 0) || (e < sys_nerr)) - return("unlisted error"); - else + if ((e >= 0) && (e < sys_nerr)) return(sys_errlist[e]); + else + return("unlisted error"); } #endif -- cgit v1.2.3 From cb17e99faeea6823a630b9769a1c8906ea0766b3 Mon Sep 17 00:00:00 2001 From: Kevin Steves Date: Mon, 9 Apr 2001 14:50:52 +0000 Subject: - (stevesk) use setresgid() for setegid() if needed --- openbsd-compat/bsd-misc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 6f92e064..eb3a5407 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -26,7 +26,7 @@ #include "xmalloc.h" #include "ssh.h" -RCSID("$Id: bsd-misc.c,v 1.3 2001/03/13 23:38:20 mouring Exp $"); +RCSID("$Id: bsd-misc.c,v 1.4 2001/04/09 14:50:56 stevesk Exp $"); char *get_progname(char *argv0) { @@ -70,6 +70,13 @@ int seteuid(uid_t euid) } #endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) */ +#if !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) +int setegid(uid_t egid) +{ + return(setresgid(-1,egid,-1)); +} +#endif /* !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) */ + #if !defined(HAVE_STRERROR) && defined(HAVE_SYS_ERRLIST) && defined(HAVE_SYS_NERR) const char *strerror(int e) { -- cgit v1.2.3 From 926ce58d3be975754faff4c8accde5034de4983e Mon Sep 17 00:00:00 2001 From: Ben Lindstrom Date: Wed, 10 Oct 2001 20:38:55 +0000 Subject: - (bal) removed two unsed headers in openbsd-compat/bsd-misc.c --- openbsd-compat/bsd-misc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index eb3a5407..7bf46dd7 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -23,10 +23,8 @@ */ #include "includes.h" -#include "xmalloc.h" -#include "ssh.h" -RCSID("$Id: bsd-misc.c,v 1.4 2001/04/09 14:50:56 stevesk Exp $"); +RCSID("$Id: bsd-misc.c,v 1.5 2001/10/10 20:38:56 mouring Exp $"); char *get_progname(char *argv0) { -- cgit v1.2.3 From 4bd2a1989073dcf353e8e4801029f9b6873158df Mon Sep 17 00:00:00 2001 From: Tim Rice Date: Tue, 7 May 2002 19:51:31 -0700 Subject: Add truncate() emulation to address Bug 208 --- openbsd-compat/bsd-misc.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 7bf46dd7..237f9393 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -24,7 +24,7 @@ #include "includes.h" -RCSID("$Id: bsd-misc.c,v 1.5 2001/10/10 20:38:56 mouring Exp $"); +RCSID("$Id: bsd-misc.c,v 1.6 2002/05/08 02:51:32 tim Exp $"); char *get_progname(char *argv0) { @@ -99,3 +99,22 @@ int utimes(char *filename, struct timeval *tvp) return(utime(filename, &ub)); } #endif + +#ifndef HAVE_TRUNCATE +int truncate (const char *path, off_t length) +{ + int fd, ret, saverrno; + + fd = open(path, O_WRONLY); + if (fd < 0) + return -1; + + ret = ftruncate(fd, length); + saverrno = errno; + (void) close (fd); + if (ret == -1) + errno = saverrno; + return(ret); +} +#endif /* HAVE_TRUNCATE */ + -- cgit v1.2.3 From 837461bf9a8f71b96a522bf6f51d6fdcb5b2a8cd Mon Sep 17 00:00:00 2001 From: Ben Lindstrom Date: Wed, 12 Jun 2002 16:57:14 +0000 Subject: - (bal) Build noop setgroups() for cygwin to clean up code (For other platforms without the setgroups() requirement, you MUST define SETGROUPS_NOOP in the configure.ac) Based on patch by vinschen@redhat.com --- openbsd-compat/bsd-misc.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 237f9393..680375ce 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -24,7 +24,7 @@ #include "includes.h" -RCSID("$Id: bsd-misc.c,v 1.6 2002/05/08 02:51:32 tim Exp $"); +RCSID("$Id: bsd-misc.c,v 1.7 2002/06/12 16:57:15 mouring Exp $"); char *get_progname(char *argv0) { @@ -118,3 +118,14 @@ int truncate (const char *path, off_t length) } #endif /* HAVE_TRUNCATE */ +#if !defined(HAVE_SETGROUPS) && defined(SETGROUPS_NOOP) +/* + * Cygwin setgroups should be a noop. + */ +int +setgroups(size_t size, const git_t *list) +{ + return 0; +} +#endif + -- cgit v1.2.3 From 0e23ebcc8b022710a266982694f3e10e3f19e20b Mon Sep 17 00:00:00 2001 From: Ben Lindstrom Date: Thu, 13 Jun 2002 21:34:57 +0000 Subject: - (bal) typo of setgroup for cygwin. Patch by vinschen@redhat.com --- openbsd-compat/bsd-misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 680375ce..fa48afea 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -24,7 +24,7 @@ #include "includes.h" -RCSID("$Id: bsd-misc.c,v 1.7 2002/06/12 16:57:15 mouring Exp $"); +RCSID("$Id: bsd-misc.c,v 1.8 2002/06/13 21:34:58 mouring Exp $"); char *get_progname(char *argv0) { @@ -123,7 +123,7 @@ int truncate (const char *path, off_t length) * Cygwin setgroups should be a noop. */ int -setgroups(size_t size, const git_t *list) +setgroups(size_t size, const gid_t *list) { return 0; } -- cgit v1.2.3 From 723e29aa20cdd59c12ff02c4a7d7d7f45bc07a08 Mon Sep 17 00:00:00 2001 From: Ben Lindstrom Date: Wed, 3 Jul 2002 23:50:00 +0000 Subject: - (bal) minor correction to utimes() replacement. Patch by onoe@sm.sony.co.jp --- openbsd-compat/bsd-misc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index fa48afea..60526be9 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -24,7 +24,7 @@ #include "includes.h" -RCSID("$Id: bsd-misc.c,v 1.8 2002/06/13 21:34:58 mouring Exp $"); +RCSID("$Id: bsd-misc.c,v 1.9 2002/07/03 23:50:00 mouring Exp $"); char *get_progname(char *argv0) { @@ -93,8 +93,8 @@ int utimes(char *filename, struct timeval *tvp) { struct utimbuf ub; - ub.actime = tvp->tv_sec; - ub.modtime = tvp->tv_usec; + ub.actime = tvp[0]->tv_sec; + ub.modtime = tvp[1]->tv_usec; return(utime(filename, &ub)); } -- cgit v1.2.3 From 100d586df2b5a5aadfc52cca5bb29682eac1b9b6 Mon Sep 17 00:00:00 2001 From: Ben Lindstrom Date: Mon, 8 Jul 2002 21:09:41 +0000 Subject: - (bal) Correction to utimes() again. --- openbsd-compat/bsd-misc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 60526be9..1c1e43a5 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -24,7 +24,7 @@ #include "includes.h" -RCSID("$Id: bsd-misc.c,v 1.9 2002/07/03 23:50:00 mouring Exp $"); +RCSID("$Id: bsd-misc.c,v 1.10 2002/07/08 21:09:41 mouring Exp $"); char *get_progname(char *argv0) { @@ -93,8 +93,8 @@ int utimes(char *filename, struct timeval *tvp) { struct utimbuf ub; - ub.actime = tvp[0]->tv_sec; - ub.modtime = tvp[1]->tv_usec; + ub.actime = tvp[0].tv_sec; + ub.modtime = tvp[1].tv_sec; return(utime(filename, &ub)); } -- cgit v1.2.3 From a8ed44b79e6dd78d7871b0fb8149951b54662ef5 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Fri, 10 Jan 2003 09:53:12 +1100 Subject: - (djm) Enable new setproctitle emulation for Linux, AIX and HP/UX. More systems may be added later. --- openbsd-compat/bsd-misc.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 1c1e43a5..d7180d42 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -23,15 +23,20 @@ */ #include "includes.h" +#include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.10 2002/07/08 21:09:41 mouring Exp $"); +RCSID("$Id: bsd-misc.c,v 1.11 2003/01/09 22:53:13 djm Exp $"); +/* + * NB. duplicate __progname in case it is an alias for argv[0] + * Otherwise it may get clobbered by setproctitle() + */ char *get_progname(char *argv0) { #ifdef HAVE___PROGNAME extern char *__progname; - return __progname; + return xstrdup(__progname); #else char *p; @@ -42,7 +47,8 @@ char *get_progname(char *argv0) p = argv0; else p++; - return p; + + return xstrdup(p); #endif } -- cgit v1.2.3 From 4e4dc561ae948a410fb82fd8b0960ec2cf8e2e70 Mon Sep 17 00:00:00 2001 From: Tim Rice Date: Tue, 18 Mar 2003 10:21:40 -0800 Subject: [configure.ac openbsd-compat/bsd-misc.c openbsd-compat/bsd-misc.h] add nanosleep(). testing/corrections by Darren Tucker --- openbsd-compat/bsd-misc.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index d7180d42..b8e9996d 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -25,7 +25,7 @@ #include "includes.h" #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.11 2003/01/09 22:53:13 djm Exp $"); +RCSID("$Id: bsd-misc.c,v 1.12 2003/03/18 18:21:41 tim Exp $"); /* * NB. duplicate __progname in case it is an alias for argv[0] @@ -135,3 +135,34 @@ setgroups(size_t size, const gid_t *list) } #endif +#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP) +int nanosleep(const struct timespec *req, struct timespec *rem) +{ + int rc, saverrno; + extern int errno; + struct timeval tstart, tstop, tremain, time2wait; + + TIMESPEC_TO_TIMEVAL(&time2wait, req) + (void) gettimeofday(&tstart, NULL); + rc = select(0, NULL, NULL, NULL, &time2wait); + if (rc == -1) { + saverrno = errno; + (void) gettimeofday (&tstop, NULL); + errno = saverrno; + tremain.tv_sec = time2wait.tv_sec - + (tstop.tv_sec - tstart.tv_sec); + tremain.tv_usec = time2wait.tv_usec - + (tstop.tv_usec - tstart.tv_usec); + tremain.tv_sec += tremain.tv_usec / 1000000L; + tremain.tv_usec %= 1000000L; + } else { + tremain.tv_sec = 0; + tremain.tv_usec = 0; + } + TIMEVAL_TO_TIMESPEC(&tremain, rem) + + return(rc); +} + +#endif + -- cgit v1.2.3 From 317412502b900ddecdafdfa171da99271846478b Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Mon, 19 May 2003 00:13:38 +1000 Subject: - (djm) Big KNF on openbsd-compat/ --- openbsd-compat/bsd-misc.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index b8e9996d..cdc63c24 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2000 Damien Miller. All rights reserved. + * Copyright (c) 1999-2003 Damien Miller. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -25,7 +25,7 @@ #include "includes.h" #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.12 2003/03/18 18:21:41 tim Exp $"); +RCSID("$Id: bsd-misc.c,v 1.13 2003/05/18 14:13:39 djm Exp $"); /* * NB. duplicate __progname in case it is an alias for argv[0] @@ -41,21 +41,21 @@ char *get_progname(char *argv0) char *p; if (argv0 == NULL) - return "unknown"; /* XXX */ + return ("unknown"); /* XXX */ p = strrchr(argv0, '/'); if (p == NULL) p = argv0; else p++; - return xstrdup(p); + return (xstrdup(p)); #endif } #ifndef HAVE_SETLOGIN int setlogin(const char *name) { - return(0); + return (0); } #endif /* !HAVE_SETLOGIN */ @@ -63,21 +63,21 @@ int setlogin(const char *name) int innetgr(const char *netgroup, const char *host, const char *user, const char *domain) { - return(0); + return (0); } #endif /* HAVE_INNETGR */ #if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) int seteuid(uid_t euid) { - return(setreuid(-1,euid)); + return (setreuid(-1, euid)); } #endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) */ #if !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) int setegid(uid_t egid) { - return(setresgid(-1,egid,-1)); + return(setresgid(-1, egid, -1)); } #endif /* !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) */ @@ -88,9 +88,9 @@ const char *strerror(int e) extern char *sys_errlist[]; if ((e >= 0) && (e < sys_nerr)) - return(sys_errlist[e]); - else - return("unlisted error"); + return (sys_errlist[e]); + + return ("unlisted error"); } #endif @@ -102,24 +102,25 @@ int utimes(char *filename, struct timeval *tvp) ub.actime = tvp[0].tv_sec; ub.modtime = tvp[1].tv_sec; - return(utime(filename, &ub)); + return (utime(filename, &ub)); } #endif #ifndef HAVE_TRUNCATE -int truncate (const char *path, off_t length) +int truncate(const char *path, off_t length) { int fd, ret, saverrno; fd = open(path, O_WRONLY); if (fd < 0) - return -1; + return (-1); ret = ftruncate(fd, length); saverrno = errno; - (void) close (fd); + close(fd); if (ret == -1) errno = saverrno; + return(ret); } #endif /* HAVE_TRUNCATE */ @@ -131,7 +132,7 @@ int truncate (const char *path, off_t length) int setgroups(size_t size, const gid_t *list) { - return 0; + return (0); } #endif -- cgit v1.2.3 From 2e9c9cf702d8e90809d901ec51358406be6f810a Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sat, 2 Aug 2003 23:31:42 +1000 Subject: - (dtucker) [openbsd-compat/bsd-misc.c openbsd-compat/bsd-misc.h] Add a tcgetpgrp function. --- openbsd-compat/bsd-misc.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index cdc63c24..64de6945 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -25,7 +25,7 @@ #include "includes.h" #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.13 2003/05/18 14:13:39 djm Exp $"); +RCSID("$Id: bsd-misc.c,v 1.14 2003/08/02 13:31:42 dtucker Exp $"); /* * NB. duplicate __progname in case it is an alias for argv[0] @@ -167,3 +167,16 @@ int nanosleep(const struct timespec *req, struct timespec *rem) #endif +#ifndef HAVE_TCGETPGRP +pid_t +tcgetpgrp(int fd) +{ + int result, ctty_pgrp; + + if (ioctl(STDOUT_FILENO, TIOCGPGRP, &ctty_pgrp) == -1) + return(-1); + else + return(ctty_pgrp); +} +#endif /* HAVE_TCGETPGRP */ + -- cgit v1.2.3 From 048737c9bcf25a02932d17b74398082930ee817e Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sat, 2 Aug 2003 23:33:48 +1000 Subject: Remove unused variable. --- openbsd-compat/bsd-misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 64de6945..474aae1a 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -25,7 +25,7 @@ #include "includes.h" #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.14 2003/08/02 13:31:42 dtucker Exp $"); +RCSID("$Id: bsd-misc.c,v 1.15 2003/08/02 13:33:48 dtucker Exp $"); /* * NB. duplicate __progname in case it is an alias for argv[0] @@ -171,7 +171,7 @@ int nanosleep(const struct timespec *req, struct timespec *rem) pid_t tcgetpgrp(int fd) { - int result, ctty_pgrp; + int ctty_pgrp; if (ioctl(STDOUT_FILENO, TIOCGPGRP, &ctty_pgrp) == -1) return(-1); -- cgit v1.2.3 From bdf571b0dc29efdec02c8a56f102077bf49aeb7c Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sun, 3 Aug 2003 00:36:16 +1000 Subject: - (dtucker) [openbsd-compat/bsd-misc.c] Fix cut-and-paste bug in tcgetpgrp. --- openbsd-compat/bsd-misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 474aae1a..da8f7704 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -25,7 +25,7 @@ #include "includes.h" #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.15 2003/08/02 13:33:48 dtucker Exp $"); +RCSID("$Id: bsd-misc.c,v 1.16 2003/08/02 14:36:16 dtucker Exp $"); /* * NB. duplicate __progname in case it is an alias for argv[0] @@ -173,7 +173,7 @@ tcgetpgrp(int fd) { int ctty_pgrp; - if (ioctl(STDOUT_FILENO, TIOCGPGRP, &ctty_pgrp) == -1) + if (ioctl(fd, TIOCGPGRP, &ctty_pgrp) == -1) return(-1); else return(ctty_pgrp); -- cgit v1.2.3 From f38ea77c03a5473ec43fe07ec24cfb1ca7f27034 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Wed, 13 Aug 2003 20:48:07 +1000 Subject: - (dtucker) [configure.ac openbsd-compat/bsd-misc.c openbsd-compat/bsd-misc.h] Add a tcsendbreak function for platforms that don't have one, based on the one from OpenBSD. Any more of these and I'll split them out into bsd-termio.[ch]. --- openbsd-compat/bsd-misc.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index da8f7704..d4c79372 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -25,7 +25,7 @@ #include "includes.h" #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.16 2003/08/02 14:36:16 dtucker Exp $"); +RCSID("$Id: bsd-misc.c,v 1.17 2003/08/13 10:48:07 dtucker Exp $"); /* * NB. duplicate __progname in case it is an alias for argv[0] @@ -180,3 +180,23 @@ tcgetpgrp(int fd) } #endif /* HAVE_TCGETPGRP */ +#ifndef HAVE_TCSENDBREAK +int +tcsendbreak(int fd, int duration) +{ +# if defined(TIOCSBRK) && defined(TIOCCBRK) + struct timeval sleepytime; + + sleepytime.tv_sec = 0; + sleepytime.tv_usec = 400000; + if (ioctl(fd, TIOCSBRK, 0) == -1) + return (-1); + (void)select(0, 0, 0, 0, &sleepytime); + if (ioctl(fd, TIOCCBRK, 0) == -1) + return (-1); + return (0); +# else + return -1; +# endif +} +#endif /* HAVE_TCSENDBREAK */ -- cgit v1.2.3 From 59d3d5b8b4813bdd1d4518d6839bd392ff6d21f7 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Fri, 22 Aug 2003 09:34:41 +1000 Subject: - (djm) s/get_progname/ssh_get_progname/g to avoid conflict with Heimdal -lbroken; ok dtucker --- openbsd-compat/bsd-misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index d4c79372..56cb45ad 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -25,13 +25,13 @@ #include "includes.h" #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.17 2003/08/13 10:48:07 dtucker Exp $"); +RCSID("$Id: bsd-misc.c,v 1.18 2003/08/21 23:34:42 djm Exp $"); /* * NB. duplicate __progname in case it is an alias for argv[0] * Otherwise it may get clobbered by setproctitle() */ -char *get_progname(char *argv0) +char *ssh_get_progname(char *argv0) { #ifdef HAVE___PROGNAME extern char *__progname; -- cgit v1.2.3 From 5ade9abc37df3dacacbe20104877ca6dab61082a Mon Sep 17 00:00:00 2001 From: Ben Lindstrom Date: Mon, 25 Aug 2003 01:16:21 +0000 Subject: - (bal) redo how we handle 'mysignal()'. Move it to openbsd-compat/bsd-misc.c, s/mysignal/signal/ and #define signal to be our 'mysignal' by default. OK djm@ --- openbsd-compat/bsd-misc.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 56cb45ad..08b089bd 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -25,7 +25,7 @@ #include "includes.h" #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.18 2003/08/21 23:34:42 djm Exp $"); +RCSID("$Id: bsd-misc.c,v 1.19 2003/08/25 01:16:21 mouring Exp $"); /* * NB. duplicate __progname in case it is an alias for argv[0] @@ -200,3 +200,29 @@ tcsendbreak(int fd, int duration) # endif } #endif /* HAVE_TCSENDBREAK */ + +mysig_t +mysignal(int sig, mysig_t act) +{ +#ifdef HAVE_SIGACTION + struct sigaction sa, osa; + + if (sigaction(sig, NULL, &osa) == -1) + return (mysig_t) -1; + if (osa.sa_handler != act) { + memset(&sa, 0, sizeof(sa)); + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; +#ifdef SA_INTERRUPT + if (sig == SIGALRM) + sa.sa_flags |= SA_INTERRUPT; +#endif + sa.sa_handler = act; + if (sigaction(sig, &sa, NULL) == -1) + return (mysig_t) -1; + } + return (osa.sa_handler); +#else + return (signal(sig, act)); +#endif +} -- cgit v1.2.3 From 563eb99711026601974115e7d2084ad9b676a188 Mon Sep 17 00:00:00 2001 From: Ben Lindstrom Date: Thu, 18 Dec 2003 00:34:06 +0000 Subject: - (bal) [openbsd-compat/bsd-misc.c] unset 'signal' defined if we are using a real 'signal()' (Noticed by a NeXT Compile) --- openbsd-compat/bsd-misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 08b089bd..44f4fcc1 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -25,7 +25,7 @@ #include "includes.h" #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.19 2003/08/25 01:16:21 mouring Exp $"); +RCSID("$Id: bsd-misc.c,v 1.20 2003/12/18 00:34:07 mouring Exp $"); /* * NB. duplicate __progname in case it is an alias for argv[0] @@ -164,7 +164,6 @@ int nanosleep(const struct timespec *req, struct timespec *rem) return(rc); } - #endif #ifndef HAVE_TCGETPGRP @@ -223,6 +222,7 @@ mysignal(int sig, mysig_t act) } return (osa.sa_handler); #else + #undef signal return (signal(sig, act)); #endif } -- cgit v1.2.3 From 98225c2950f30aaab75eb649dbe5c667ea2fda04 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Tue, 17 Feb 2004 16:49:41 +1100 Subject: - (djm) Simplify the license on code I have written. No code changes. --- openbsd-compat/bsd-misc.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 44f4fcc1..7b06786f 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -1,31 +1,23 @@ /* - * Copyright (c) 1999-2003 Damien Miller. All rights reserved. + * Copyright (c) 1999-2004 Damien Miller * - * 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. + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include "includes.h" #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.20 2003/12/18 00:34:07 mouring Exp $"); +RCSID("$Id: bsd-misc.c,v 1.21 2004/02/17 05:49:55 djm Exp $"); /* * NB. duplicate __progname in case it is an alias for argv[0] -- cgit v1.2.3 From 60bd4098f64fd0fbbd9b6b4de2562623318141a0 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Fri, 25 Jun 2004 14:03:34 +1000 Subject: - (dtucker) [configure.ac openbsd-compat/misc.c [openbsd-compat/misc.h] Add closefrom() for platforms that don't have it. (might need some tuning later, but I want to be able to test reexec). --- openbsd-compat/bsd-misc.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 7b06786f..c58cce0f 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -17,7 +17,7 @@ #include "includes.h" #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.21 2004/02/17 05:49:55 djm Exp $"); +RCSID("$Id: bsd-misc.c,v 1.22 2004/06/25 04:03:34 dtucker Exp $"); /* * NB. duplicate __progname in case it is an alias for argv[0] @@ -192,6 +192,22 @@ tcsendbreak(int fd, int duration) } #endif /* HAVE_TCSENDBREAK */ +#ifndef HAVE_CLOSEFROM +int +closefrom(int fd) +{ + int i, result = 0, err = 0; + + for (i = fd; i < 128; i++) + if (close(i) != 0) { + err = errno; + result = -1; + } + errno = err; + return result; +} +#endif /* HAVE_CLOSEFROM */ + mysig_t mysignal(int sig, mysig_t act) { -- cgit v1.2.3 From ba6de952a00558e6d93b8c9edd81806a99716411 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sat, 17 Jul 2004 14:07:42 +1000 Subject: - (dtucker) [logintest.c scp.c sftp-server.c sftp.c ssh-add.c ssh-agent.c ssh-keygen.c ssh-keyscan.c ssh-keysign.c ssh-rand-helper.c ssh.c sshd.c openbsd-compat/bsd-misc.c] Move "char *__progname" to bsd-misc.c. Reduces diff vs OpenBSD; ok mouring@, tested by tim@ too. --- openbsd-compat/bsd-misc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index c58cce0f..07b7c075 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -17,7 +17,11 @@ #include "includes.h" #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.22 2004/06/25 04:03:34 dtucker Exp $"); +RCSID("$Id: bsd-misc.c,v 1.23 2004/07/17 04:07:42 dtucker Exp $"); + +#ifndef HAVE__PROGNAME +char *__progname; +#endif /* * NB. duplicate __progname in case it is an alias for argv[0] -- cgit v1.2.3 From 03669a363eb8c76f460a75adc11d0eb933e4af49 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Fri, 13 Aug 2004 18:37:21 +1000 Subject: - (dtucker) [openbsd-compat/bsd-misc.c] Typo in #ifdef; from vinschen at redhat.com --- openbsd-compat/bsd-misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 07b7c075..3a30b6e4 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -17,9 +17,9 @@ #include "includes.h" #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.23 2004/07/17 04:07:42 dtucker Exp $"); +RCSID("$Id: bsd-misc.c,v 1.24 2004/08/13 08:37:21 dtucker Exp $"); -#ifndef HAVE__PROGNAME +#ifndef HAVE___PROGNAME char *__progname; #endif -- cgit v1.2.3 From 36f496502072d82dbb202b41a199eb6032557710 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Sun, 15 Aug 2004 18:40:59 +1000 Subject: - (djm) [acconfig.h configure.ac openbsd-compat/Makefile.in openbsd-compat/bsd-closefrom.c openbsd-compat/bsd-misc.c openbsd-compat/bsd-misc.h openbsd-compat/openbsd-compat.h] Use smarter closefrom() replacement from sudo; ok dtucker@ --- openbsd-compat/bsd-misc.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 3a30b6e4..1b276b4f 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -1,3 +1,4 @@ + /* * Copyright (c) 1999-2004 Damien Miller * @@ -17,7 +18,7 @@ #include "includes.h" #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.24 2004/08/13 08:37:21 dtucker Exp $"); +RCSID("$Id: bsd-misc.c,v 1.25 2004/08/15 08:41:00 djm Exp $"); #ifndef HAVE___PROGNAME char *__progname; @@ -196,22 +197,6 @@ tcsendbreak(int fd, int duration) } #endif /* HAVE_TCSENDBREAK */ -#ifndef HAVE_CLOSEFROM -int -closefrom(int fd) -{ - int i, result = 0, err = 0; - - for (i = fd; i < 128; i++) - if (close(i) != 0) { - err = errno; - result = -1; - } - errno = err; - return result; -} -#endif /* HAVE_CLOSEFROM */ - mysig_t mysignal(int sig, mysig_t act) { -- cgit v1.2.3 From 3804903a094f41d09e8b294dbd69a846dcf7fe94 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sat, 26 Feb 2005 10:07:37 +1100 Subject: - (dtucker) [acconfig.h configure.ac openbsd-compat/bsd-misc.{c,h}] Remove SETGROUPS_NOOP, was only used by Cygwin, which doesn't need it any more. Patch from vinschen at redhat.com. --- openbsd-compat/bsd-misc.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 1b276b4f..41f92cce 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -18,7 +18,7 @@ #include "includes.h" #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.25 2004/08/15 08:41:00 djm Exp $"); +RCSID("$Id: bsd-misc.c,v 1.26 2005/02/25 23:07:38 dtucker Exp $"); #ifndef HAVE___PROGNAME char *__progname; @@ -122,17 +122,6 @@ int truncate(const char *path, off_t length) } #endif /* HAVE_TRUNCATE */ -#if !defined(HAVE_SETGROUPS) && defined(SETGROUPS_NOOP) -/* - * Cygwin setgroups should be a noop. - */ -int -setgroups(size_t size, const gid_t *list) -{ - return (0); -} -#endif - #if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP) int nanosleep(const struct timespec *req, struct timespec *rem) { -- cgit v1.2.3 From 2be1cbb7be25d32bc5741c96cc4d6951bd91fc30 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Fri, 27 May 2005 21:13:40 +1000 Subject: - (dtucker) [acconfig.h configure.ac defines.h includes.h sshpty.c openbsd-compat/bsd-misc.c] Add support for Ultrix. No, that's not a typo. Required changes from Bernhard Simon, integrated by me. ok djm@ --- openbsd-compat/bsd-misc.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 41f92cce..6ba9bd98 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -18,7 +18,7 @@ #include "includes.h" #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.26 2005/02/25 23:07:38 dtucker Exp $"); +RCSID("$Id: bsd-misc.c,v 1.27 2005/05/27 11:13:41 dtucker Exp $"); #ifndef HAVE___PROGNAME char *__progname; @@ -212,3 +212,21 @@ mysignal(int sig, mysig_t act) return (signal(sig, act)); #endif } + +#ifndef HAVE_STRDUP +char * +strdup(const char *str) +{ + size_t len; + char *cp; + + len = strlen(str) + 1; + cp = malloc(len); + if (cp != NULL) + if (strlcpy(cp, str, len) != len) { + free(cp); + return NULL; + } + return cp; +} +#endif -- cgit v1.2.3 From d32e293c045025b80892e8b05285ca9617d83ef6 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Wed, 2 Nov 2005 09:07:31 +1100 Subject: - (dtucker) [openbsd-compat/bsd-misc.c] Bug #1108: fix broken strdup(). Reported by olavi at ipunplugged.com and antoine.brodin at laposte.net via FreeBSD. --- openbsd-compat/bsd-misc.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 6ba9bd98..d32b054d 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -18,7 +18,7 @@ #include "includes.h" #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.27 2005/05/27 11:13:41 dtucker Exp $"); +RCSID("$Id: bsd-misc.c,v 1.28 2005/11/01 22:07:31 dtucker Exp $"); #ifndef HAVE___PROGNAME char *__progname; @@ -223,10 +223,7 @@ strdup(const char *str) len = strlen(str) + 1; cp = malloc(len); if (cp != NULL) - if (strlcpy(cp, str, len) != len) { - free(cp); - return NULL; - } - return cp; + return(memcpy(cp, str, len)); + return NULL; } #endif -- cgit v1.2.3 From 6645e7a70d1b46b2cb408e1a13755c300a0d47c2 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Wed, 15 Mar 2006 14:42:54 +1100 Subject: - (djm) [auth-pam.c clientloop.c includes.h monitor.c session.c] [sftp-client.c ssh-keysign.c ssh.c sshconnect.c sshconnect2.c] [sshd.c openbsd-compat/bsd-misc.c openbsd-compat/bsd-openpty.c] [openbsd-compat/glob.c openbsd-compat/mktemp.c] [openbsd-compat/readpassphrase.c] Lots of include fixes for OpenSolaris --- openbsd-compat/bsd-misc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index d32b054d..00482616 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -16,9 +16,12 @@ */ #include "includes.h" + +#include + #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.28 2005/11/01 22:07:31 dtucker Exp $"); +RCSID("$Id: bsd-misc.c,v 1.29 2006/03/15 03:42:57 djm Exp $"); #ifndef HAVE___PROGNAME char *__progname; -- cgit v1.2.3 From b0fb6872ed2efe3a116083e43dd4f5f47cd4882b Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Sun, 26 Mar 2006 00:03:21 +1100 Subject: - deraadt@cvs.openbsd.org 2006/03/19 18:51:18 [atomicio.c auth-bsdauth.c auth-chall.c auth-krb5.c auth-options.c] [auth-pam.c auth-passwd.c auth-rh-rsa.c auth-rhosts.c auth-rsa.c] [auth-shadow.c auth-skey.c auth.c auth1.c auth2-chall.c] [auth2-hostbased.c auth2-kbdint.c auth2-none.c auth2-passwd.c] [auth2-pubkey.c auth2.c authfd.c authfile.c bufaux.c buffer.c] [canohost.c channels.c cipher-3des1.c cipher-acss.c cipher-aes.c] [cipher-bf1.c cipher-ctr.c cipher.c cleanup.c clientloop.c compat.c] [compress.c deattack.c dh.c dispatch.c dns.c entropy.c fatal.c] [groupaccess.c hostfile.c includes.h kex.c kexdh.c kexdhc.c] [kexdhs.c kexgex.c kexgexc.c kexgexs.c key.c log.c loginrec.c] [loginrec.h logintest.c mac.c match.c md-sha256.c md5crypt.c misc.c] [monitor.c monitor_fdpass.c monitor_mm.c monitor_wrap.c msg.c] [nchan.c packet.c progressmeter.c readconf.c readpass.c rsa.c] [scard.c scp.c servconf.c serverloop.c session.c sftp-client.c] [sftp-common.c sftp-glob.c sftp-server.c sftp.c ssh-add.c] [ssh-agent.c ssh-dss.c ssh-keygen.c ssh-keyscan.c ssh-keysign.c] [ssh-rand-helper.c ssh-rsa.c ssh.c sshconnect.c sshconnect1.c] [sshconnect2.c sshd.c sshlogin.c sshpty.c sshtty.c ttymodes.c] [uidswap.c uuencode.c xmalloc.c openbsd-compat/bsd-arc4random.c] [openbsd-compat/bsd-closefrom.c openbsd-compat/bsd-cygwin_util.c] [openbsd-compat/bsd-getpeereid.c openbsd-compat/bsd-misc.c] [openbsd-compat/bsd-nextstep.c openbsd-compat/bsd-snprintf.c] [openbsd-compat/bsd-waitpid.c openbsd-compat/fake-rfc2553.c] RCSID() can die --- openbsd-compat/bsd-misc.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 00482616..d2d9ad77 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -21,8 +21,6 @@ #include "xmalloc.h" -RCSID("$Id: bsd-misc.c,v 1.29 2006/03/15 03:42:57 djm Exp $"); - #ifndef HAVE___PROGNAME char *__progname; #endif -- cgit v1.2.3 From b8fe89c4d97ea9a5d7efb2c60108b8a7644f6a49 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Mon, 24 Jul 2006 14:51:00 +1000 Subject: - (djm) [acss.c auth-krb5.c auth-options.c auth-pam.c auth-shadow.c] [canohost.c channels.c cipher-acss.c defines.h dns.c gss-genr.c] [gss-serv-krb5.c gss-serv.c log.h loginrec.c logintest.c readconf.c] [servconf.c ssh-keygen.c ssh-keyscan.c ssh-keysign.c ssh-rand-helper.c] [ssh.c sshconnect.c sshd.c openbsd-compat/bindresvport.c] [openbsd-compat/bsd-arc4random.c openbsd-compat/bsd-misc.c] [openbsd-compat/getrrsetbyname.c openbsd-compat/glob.c] [openbsd-compat/mktemp.c openbsd-compat/port-linux.c] [openbsd-compat/port-tun.c openbsd-compat/readpassphrase.c] [openbsd-compat/setproctitle.c openbsd-compat/xmmap.c] make the portable tree compile again - sprinkle unistd.h and string.h back in. Don't redefine __unused, as it turned out to be used in headers on Linux, and replace its use in auth-pam.c with ARGSUSED --- openbsd-compat/bsd-misc.c | 1 + 1 file changed, 1 insertion(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index d2d9ad77..e6128f9a 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -17,6 +17,7 @@ #include "includes.h" +#include #include #include "xmalloc.h" -- cgit v1.2.3 From e086955531ffef96bc15d51a07f25ae65804dc1c Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Thu, 24 Aug 2006 19:43:16 +1000 Subject: - (dtucker) [openbsd-compat/bsd-misc.c] Add includes needed for select(2) on older systems. --- openbsd-compat/bsd-misc.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index e6128f9a..c6b80365 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -17,8 +17,13 @@ #include "includes.h" +#ifdef HAVE_SYS_TIME_H +# include +#endif + #include #include +#include #include "xmalloc.h" -- cgit v1.2.3 From 450d2af2a3f07e46cc1490a0029a9f669dd60108 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Thu, 24 Aug 2006 19:45:33 +1000 Subject: - (dtucker) [openbsd-compat/bsd-misc.c] Include for select(2) on POSIX systems. --- openbsd-compat/bsd-misc.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index c6b80365..17d731bd 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -17,6 +17,9 @@ #include "includes.h" +#ifdef HAVE_SYS_SELECT_H +# include +#endif #ifdef HAVE_SYS_TIME_H # include #endif -- cgit v1.2.3 From 781e7a28d0376af76bae27495bac5054510688b1 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sun, 29 Apr 2007 12:06:55 +1000 Subject: - (dtucker) [openbsd-compat/bsd-misc.c] Include unistd.h and sys/types.h for select(2) prototype. --- openbsd-compat/bsd-misc.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 17d731bd..bea3144b 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -17,6 +17,7 @@ #include "includes.h" +#include #ifdef HAVE_SYS_SELECT_H # include #endif @@ -27,6 +28,7 @@ #include #include #include +#include #include "xmalloc.h" -- cgit v1.2.3 From 1534fa41e07283acf83a50e6c2bbc8ca2f71ab97 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Mon, 11 Jun 2007 14:34:53 +1000 Subject: - (dtucker) [openbsd-compat/bsd-misc.c] According to the spec the "remainder" argument to nanosleep may be NULL. Currently this never happens in OpenSSH, but check anyway in case this changes or the code gets used elsewhere. --- openbsd-compat/bsd-misc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index bea3144b..55f100ac 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -158,7 +158,8 @@ int nanosleep(const struct timespec *req, struct timespec *rem) tremain.tv_sec = 0; tremain.tv_usec = 0; } - TIMEVAL_TO_TIMESPEC(&tremain, rem) + if (rem != NULL) + TIMEVAL_TO_TIMESPEC(&tremain, rem) return(rc); } -- cgit v1.2.3 From c7a8af03a022e8ab52422b6ce26fdbcb729031fd Mon Sep 17 00:00:00 2001 From: Tim Rice Date: Mon, 8 Nov 2010 14:26:23 -0800 Subject: - (tim) [configure.ac openbsd-compat/bsd-misc.h openbsd-compat/bsd-misc.c] Add support for platforms missing isblank(). ok djm@ --- openbsd-compat/bsd-misc.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 55f100ac..3ef373f5 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -240,3 +240,10 @@ strdup(const char *str) return NULL; } #endif + +#ifndef HAVE_ISBLANK +int isblank(int c) +{ + return (c == ' ' || c == '\t'); +} +#endif -- cgit v1.2.3 From 3c4a24c3e329ccca86629ed694b9756309b00113 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Fri, 15 Feb 2013 11:41:35 +1100 Subject: - (dtucker) [configure.ac openbsd-compat/bsd-misc.c openbsd-compat/bsd-misc.h] Use getpgrp() if we don't have getpgid() (old BSDs, maybe others). --- openbsd-compat/bsd-misc.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 3ef373f5..0cff2e42 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -247,3 +247,16 @@ int isblank(int c) return (c == ' ' || c == '\t'); } #endif + +#ifndef HAVE_GETPGID +pid_t +getpgid(pid_t pid) +{ +#ifdef HAVE_GETPGRP + if (pid == 0) + return getpgrp(); +#endif + errno = ESRCH; + return -1; +} +#endif -- cgit v1.2.3 From 62e4edc797a284f551e7faa616af06f8c3c24015 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Fri, 15 Feb 2013 11:50:03 +1100 Subject: spacing --- openbsd-compat/bsd-misc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 0cff2e42..ad524b8b 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -242,7 +242,8 @@ strdup(const char *str) #endif #ifndef HAVE_ISBLANK -int isblank(int c) +int +isblank(int c) { return (c == ' ' || c == '\t'); } -- cgit v1.2.3 From 2991d288db4355a54f0860be184c31343cb2c139 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Fri, 15 Feb 2013 14:55:38 +1100 Subject: - (dtucker) [openbsd-compat/bsd-misc.c] Handle the case where setpgrp() takes an argument. Pointed out by djm. --- openbsd-compat/bsd-misc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index ad524b8b..8dc7d02d 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -253,10 +253,13 @@ isblank(int c) pid_t getpgid(pid_t pid) { -#ifdef HAVE_GETPGRP +#if defined(HAVE_GETPGRP) && !defined(GETPGRP_VOID) + return getpgrp(pid); +#elif defined(HAVE_GETPGRP) if (pid == 0) return getpgrp(); #endif + errno = ESRCH; return -1; } -- cgit v1.2.3 From f4db77d7668104c1237636781cfbd59ef30f79b0 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Fri, 15 Mar 2013 10:34:25 +1100 Subject: - (djm) [configure.ac openbsd-compat/bsd-misc.c openbsd-compat/bsd-misc.h] Add a usleep replacement for platforms that lack it; ok dtucker --- openbsd-compat/bsd-misc.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 8dc7d02d..d75854e8 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -165,6 +165,17 @@ int nanosleep(const struct timespec *req, struct timespec *rem) } #endif +#if !defined(HAVE_USLEEP) +int usleep(unsigned int useconds) +{ + struct timespec ts; + + ts.tv_sec = useconds / 1000000; + ts.tv_nsec = (useconds % 1000000) * 1000; + return nanosleep(&ts, NULL); +} +#endif + #ifndef HAVE_TCGETPGRP pid_t tcgetpgrp(int fd) -- cgit v1.2.3 From d52770452308e5c2e99f4da6edaaa77ef078b610 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sun, 3 Nov 2013 16:30:46 +1100 Subject: - (dtucker) [openbsd-compat/bsd-misc.c] Include time.h for nanosleep. From OpenSMTPD where it prevents "implicit declaration" warnings (it's a no-op in OpenSSH). From chl at openbsd. --- openbsd-compat/bsd-misc.c | 1 + 1 file changed, 1 insertion(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index d75854e8..65e80039 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "xmalloc.h" -- cgit v1.2.3 From 678e473e2af2e4802f24dd913985864d9ead7fb3 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Thu, 26 Feb 2015 04:12:58 +1100 Subject: Remove dependency on xmalloc. Remove ssh_get_progname's dependency on xmalloc, which should reduce link order problems. ok djm@ --- openbsd-compat/bsd-misc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 65e80039..f7be415e 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -31,8 +31,6 @@ #include #include -#include "xmalloc.h" - #ifndef HAVE___PROGNAME char *__progname; #endif @@ -43,13 +41,12 @@ char *__progname; */ char *ssh_get_progname(char *argv0) { + char *p, *q; #ifdef HAVE___PROGNAME extern char *__progname; - return xstrdup(__progname); + p = __progname; #else - char *p; - if (argv0 == NULL) return ("unknown"); /* XXX */ p = strrchr(argv0, '/'); @@ -57,9 +54,12 @@ char *ssh_get_progname(char *argv0) p = argv0; else p++; - - return (xstrdup(p)); #endif + if ((q = strdup(p)) == NULL) { + perror("strdup"); + exit(1); + } + return q; } #ifndef HAVE_SETLOGIN -- cgit v1.2.3 From 3ddd15e1b63a4d4f06c8ab16fbdd8a5a61764f16 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Mon, 30 Nov 2015 07:23:53 +1100 Subject: Add a null implementation of pledge. Fixes builds on almost everything. --- openbsd-compat/bsd-misc.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index f7be415e..2a788e47 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -276,3 +276,11 @@ getpgid(pid_t pid) return -1; } #endif + +#ifndef HAVE_PLEDGE +int +pledge(const char *promises, const char *paths[]) +{ + return 0; +} +#endif -- cgit v1.2.3 From a2333584170a565adf4f209586772ef8053b10b8 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Thu, 14 Jul 2016 10:59:09 +1000 Subject: Add compat code for missing wcwidth. If we don't have wcwidth force fallback implementations of nl_langinfo and mbtowc. Based on advice from Ingo Schwarze. --- openbsd-compat/bsd-misc.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 2a788e47..18bf62dd 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -284,3 +284,20 @@ pledge(const char *promises, const char *paths[]) return 0; } #endif + +#ifndef HAVE_MBTOWC +/* a mbtowc that only supports ASCII */ +int +mbtowc(wchar_t *pwc, const char *s, size_t n) +{ + if (s == NULL || *s == '\0') + return 0; /* ASCII is not state-dependent */ + if (*s < 0 || *s > 0x7f || n < 1) { + errno = EOPNOTSUPP; + return -1; + } + if (pwc != NULL) + *pwc = *s; + return 1; +} +#endif -- cgit v1.2.3 From c20dccb5614c5714f4155dda01bcdebf97cfae7e Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Tue, 2 Aug 2016 09:44:25 +1000 Subject: Strip trailing whitespace. Mechanically strip trailing whitespace on files not synced with OpenBSD (or in the case of bsd-snprint.c, rsync). --- openbsd-compat/bsd-misc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 18bf62dd..f1173163 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -70,7 +70,7 @@ int setlogin(const char *name) #endif /* !HAVE_SETLOGIN */ #ifndef HAVE_INNETGR -int innetgr(const char *netgroup, const char *host, +int innetgr(const char *netgroup, const char *host, const char *user, const char *domain) { return (0); @@ -96,7 +96,7 @@ const char *strerror(int e) { extern int sys_nerr; extern char *sys_errlist[]; - + if ((e >= 0) && (e < sys_nerr)) return (sys_errlist[e]); @@ -111,10 +111,10 @@ int utimes(char *filename, struct timeval *tvp) ub.actime = tvp[0].tv_sec; ub.modtime = tvp[1].tv_sec; - + return (utime(filename, &ub)); } -#endif +#endif #ifndef HAVE_TRUNCATE int truncate(const char *path, off_t length) @@ -149,9 +149,9 @@ int nanosleep(const struct timespec *req, struct timespec *rem) saverrno = errno; (void) gettimeofday (&tstop, NULL); errno = saverrno; - tremain.tv_sec = time2wait.tv_sec - + tremain.tv_sec = time2wait.tv_sec - (tstop.tv_sec - tstart.tv_sec); - tremain.tv_usec = time2wait.tv_usec - + tremain.tv_usec = time2wait.tv_usec - (tstop.tv_usec - tstart.tv_usec); tremain.tv_sec += tremain.tv_usec / 1000000L; tremain.tv_usec %= 1000000L; -- cgit v1.2.3 From dd1031b78b83083615b68d7163c44f4408635be2 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Tue, 2 Aug 2016 10:01:52 +1000 Subject: Replace spaces with tabs. Mechanically replace spaces with tabs in compat files not synced with OpenBSD. --- openbsd-compat/bsd-misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index f1173163..6f3bc8f1 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -71,7 +71,7 @@ int setlogin(const char *name) #ifndef HAVE_INNETGR int innetgr(const char *netgroup, const char *host, - const char *user, const char *domain) + const char *user, const char *domain) { return (0); } -- cgit v1.2.3 From d38f05dbdd291212bc95ea80648b72b7177e9f4e Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Mon, 20 Mar 2017 13:38:27 +1100 Subject: Add llabs() implementation. --- openbsd-compat/bsd-misc.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 6f3bc8f1..cfd73260 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -301,3 +301,11 @@ mbtowc(wchar_t *pwc, const char *s, size_t n) return 1; } #endif + +#ifndef HAVE_LLABS +long long +llabs(long long j) +{ + return (j < 0 ? -j : j); +} +#endif -- cgit v1.2.3 From 44fc334c7a9ebdd08addb6d5fa005369897fddeb Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Mon, 25 Sep 2017 09:48:10 +1000 Subject: Add minimal strsignal for platforms without it. --- openbsd-compat/bsd-misc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index cfd73260..29f6ad38 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -104,6 +104,16 @@ const char *strerror(int e) } #endif +#if !defined(HAVE_STRSIGNAL) +char *strsignal(int sig) +{ + static char buf[16]; + + (void)snprintf(buf, sizeof(buf), "%d", sig); + return buf; +} +#endif + #ifndef HAVE_UTIMES int utimes(char *filename, struct timeval *tvp) { -- cgit v1.2.3 From fbfa6f980d7460b3e12b0ce88ed3b6018edf4711 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sun, 11 Feb 2018 21:25:11 +1300 Subject: Move signal compat code into bsd-signal.{c,h} --- openbsd-compat/bsd-misc.c | 37 ------------------------------------- 1 file changed, 37 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 29f6ad38..9f6dc8af 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -104,16 +104,6 @@ const char *strerror(int e) } #endif -#if !defined(HAVE_STRSIGNAL) -char *strsignal(int sig) -{ - static char buf[16]; - - (void)snprintf(buf, sizeof(buf), "%d", sig); - return buf; -} -#endif - #ifndef HAVE_UTIMES int utimes(char *filename, struct timeval *tvp) { @@ -221,33 +211,6 @@ tcsendbreak(int fd, int duration) } #endif /* HAVE_TCSENDBREAK */ -mysig_t -mysignal(int sig, mysig_t act) -{ -#ifdef HAVE_SIGACTION - struct sigaction sa, osa; - - if (sigaction(sig, NULL, &osa) == -1) - return (mysig_t) -1; - if (osa.sa_handler != act) { - memset(&sa, 0, sizeof(sa)); - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; -#ifdef SA_INTERRUPT - if (sig == SIGALRM) - sa.sa_flags |= SA_INTERRUPT; -#endif - sa.sa_handler = act; - if (sigaction(sig, &sa, NULL) == -1) - return (mysig_t) -1; - } - return (osa.sa_handler); -#else - #undef signal - return (signal(sig, act)); -#endif -} - #ifndef HAVE_STRDUP char * strdup(const char *str) -- cgit v1.2.3 From a9004425a032d7a7141a5437cfabfd02431e2a74 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sat, 24 Feb 2018 20:25:22 +1100 Subject: Check for bzero and supply if needed. Since explicit_bzero uses it via an indirect it needs to be a function not just a macro. --- openbsd-compat/bsd-misc.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 9f6dc8af..3e8f74b7 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -282,3 +282,11 @@ llabs(long long j) return (j < 0 ? -j : j); } #endif + +#ifndef HAVE_BZERO +void +bzero(void *b, size_t n) +{ + (void)memset(b, 0, n); +} +#endif -- cgit v1.2.3 From 6c8c9a615b6d31db8a87bc25033f053d5b0a831e Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sat, 24 Feb 2018 20:46:37 +1100 Subject: Check for raise and supply if needed. --- openbsd-compat/bsd-misc.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 3e8f74b7..af58f3bd 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -290,3 +290,11 @@ bzero(void *b, size_t n) (void)memset(b, 0, n); } #endif + +#ifndef HAVE_RAISE +int +raise(int sig) +{ + kill(getpid(), sig); +} +#endif -- cgit v1.2.3 From b39593a6de5290650a01adf8699c6460570403c2 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sun, 25 Feb 2018 13:25:15 +1100 Subject: Add no-op getsid implmentation. --- openbsd-compat/bsd-misc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index af58f3bd..a2f75055 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -298,3 +298,13 @@ raise(int sig) kill(getpid(), sig); } #endif + +#ifndef HAVE_GETSID +pid_t +getsid(pid_t pid) +{ + errno = ENOSYS; + return -1; +} +#endif + -- cgit v1.2.3 From c7b5a47e3b9db9a0f0198f9c90c705f6307afc2b Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sun, 25 Feb 2018 23:55:41 +1100 Subject: Invert sense of getpgrp test. AC_FUNC_GETPGRP tests if getpgrp(0) works, which it does if it's not declared. Instead, test if the zero-arg version we want to use works. --- openbsd-compat/bsd-misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index a2f75055..f7187daf 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -238,7 +238,7 @@ isblank(int c) pid_t getpgid(pid_t pid) { -#if defined(HAVE_GETPGRP) && !defined(GETPGRP_VOID) +#if defined(HAVE_GETPGRP) && !defined(GETPGRP_VOID) && GETPGRP_VOID == 0 return getpgrp(pid); #elif defined(HAVE_GETPGRP) if (pid == 0) -- cgit v1.2.3 From 58fd4c5c0140f6636227ca7acbb149ab0c2509b9 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Mon, 5 Mar 2018 19:28:08 +1100 Subject: Check for and work around buggy fflush(NULL). Some really old platforms (eg SunOS4) segfault on fflush(NULL) so check for and work around. With klausz at haus-gisela.de. --- openbsd-compat/bsd-misc.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index f7187daf..3daf6107 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -308,3 +308,19 @@ getsid(pid_t pid) } #endif +#ifdef FFLUSH_NULL_BUG +#undef fflush +int _ssh_compat_fflush(FILE *f) +{ + int r1, r2, r3; + + if (f == NULL) { + r2 = fflush(stdout); + r3 = fflush(stderr); + if (r1 == -1 || r2 == -1 || r3 == -1) + return -1; + return 0; + } + return fflush(f); +} +#endif -- cgit v1.2.3 From 120a1ec74e8d9d29f4eb9a27972ddd22351ddef9 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Tue, 10 Jul 2018 19:39:52 +1000 Subject: Adapt portable to legacy buffer API removal --- openbsd-compat/bsd-misc.c | 1 + 1 file changed, 1 insertion(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 3daf6107..b6893e17 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include -- cgit v1.2.3 From c2fa53cd6462da82d3a851dc3a4a3f6b920337c8 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sat, 22 Sep 2018 14:41:24 +1000 Subject: Remove unused variable in _ssh_compat_fflush. --- openbsd-compat/bsd-misc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index b6893e17..5d7540a7 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -313,12 +313,12 @@ getsid(pid_t pid) #undef fflush int _ssh_compat_fflush(FILE *f) { - int r1, r2, r3; + int r1, r2; if (f == NULL) { - r2 = fflush(stdout); - r3 = fflush(stderr); - if (r1 == -1 || r2 == -1 || r3 == -1) + r1 = fflush(stdout); + r2 = fflush(stderr); + if (r1 == -1 || r2 == -1) return -1; return 0; } -- cgit v1.2.3 From 091093d25802b87d3b2b09f2c88d9f33e1ae5562 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Fri, 18 Jan 2019 12:11:42 +1300 Subject: Add a minimal implementation of utimensat(). Some systems (eg older OS X) do not have utimensat, so provide minimal implementation in compat layer. Fixes build on at least El Capitan. --- openbsd-compat/bsd-misc.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 5d7540a7..4bae9654 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -25,6 +25,7 @@ # include #endif +#include #include #include #include @@ -117,6 +118,42 @@ int utimes(char *filename, struct timeval *tvp) } #endif +#ifndef HAVE_UTIMENSAT +/* + * A limited implementation of utimensat() that only implements the + * functionality used by OpenSSH, currently only AT_FDCWD and + * AT_SYMLINK_NOFOLLOW. + */ +int +utimensat(int fd, const char *path, const struct timespec times[2], + int flag) +{ + struct timeval tv[2]; + int ret, oflags = O_WRONLY; + + tv[0].tv_sec = times[0].tv_sec; + tv[0].tv_usec = times[0].tv_nsec / 1000; + tv[1].tv_sec = times[1].tv_sec; + tv[1].tv_usec = times[1].tv_nsec / 1000; + + if (fd != AT_FDCWD) { + errno = ENOSYS; + return -1; + } +# ifndef HAVE_FUTIMES + return utimes(path, tv); +# else + if (flag & AT_SYMLINK_NOFOLLOW) + oflags |= O_NOFOLLOW; + if ((fd = open(path, oflags)) == -1) + return -1; + ret = futimes(fd, tv); + close(fd); + return ret; +# endif +} +#endif + #ifndef HAVE_TRUNCATE int truncate(const char *path, off_t length) { -- cgit v1.2.3 From a6258e5dc314c7d504ac9f0fbc3be96475581dbe Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Fri, 18 Jan 2019 11:09:01 +1100 Subject: Add minimal fchownat and fchmodat implementations. Fixes builds on at least OS X Lion, NetBSD 6 and Solaris 10. --- openbsd-compat/bsd-misc.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 4bae9654..d3a41df5 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -154,6 +154,64 @@ utimensat(int fd, const char *path, const struct timespec times[2], } #endif +#ifndef HAVE_FCHOWNAT +/* + * A limited implementation of fchownat() that only implements the + * functionality used by OpenSSH, currently only AT_FDCWD and + * AT_SYMLINK_NOFOLLOW. + */ +int +fchownat(int fd, const char *path, uid_t owner, gid_t group, int flag) +{ + int ret, oflags = O_WRONLY; + + if (fd != AT_FDCWD) { + errno = ENOSYS; + return -1; + } +# ifndef HAVE_FCHOWN + return chown(pathname, owner, group); +# else + if (flag & AT_SYMLINK_NOFOLLOW) + oflags |= O_NOFOLLOW; + if ((fd = open(path, oflags)) == -1) + return -1; + ret = fchown(fd, owner, group); + close(fd); + return ret; +# endif +} +#endif + +#ifndef HAVE_FCHMODAT +/* + * A limited implementation of fchmodat() that only implements the + * functionality used by OpenSSH, currently only AT_FDCWD and + * AT_SYMLINK_NOFOLLOW. + */ +int +fchmodat(int fd, const char *path, mode_t mode, int flag) +{ + int ret, oflags = O_WRONLY; + + if (fd != AT_FDCWD) { + errno = ENOSYS; + return -1; + } +# ifndef HAVE_FCHMOD + return chown(pathname, owner, group); +# else + if (flag & AT_SYMLINK_NOFOLLOW) + oflags |= O_NOFOLLOW; + if ((fd = open(path, oflags)) == -1) + return -1; + ret = fchmod(fd, mode); + close(fd); + return ret; +# endif +} +#endif + #ifndef HAVE_TRUNCATE int truncate(const char *path, off_t length) { -- cgit v1.2.3 From f5abb05f8c7358dacdcb866fe2813f6d8efd5830 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Thu, 28 Mar 2019 09:26:14 +1100 Subject: Only use O_NOFOLLOW in utimensat if defined. Fixes build on systems that don't have it (Solaris <=9) Found by Tom G. Christensen. --- openbsd-compat/bsd-misc.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index d3a41df5..3c85a12a 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -143,8 +143,10 @@ utimensat(int fd, const char *path, const struct timespec times[2], # ifndef HAVE_FUTIMES return utimes(path, tv); # else +# ifdef O_NOFOLLOW if (flag & AT_SYMLINK_NOFOLLOW) oflags |= O_NOFOLLOW; +# endif /* O_NOFOLLOW */ if ((fd = open(path, oflags)) == -1) return -1; ret = futimes(fd, tv); -- cgit v1.2.3 From 43f47ebbdd4037b569c23b8f4f7981f53b567f1d Mon Sep 17 00:00:00 2001 From: Tim Rice Date: Sun, 31 Mar 2019 19:22:19 -0700 Subject: Only use O_NOFOLLOW in fchownat and fchmodat if defined --- openbsd-compat/bsd-misc.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 3c85a12a..aa1c7d7a 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -174,8 +174,10 @@ fchownat(int fd, const char *path, uid_t owner, gid_t group, int flag) # ifndef HAVE_FCHOWN return chown(pathname, owner, group); # else +# ifdef O_NOFOLLOW if (flag & AT_SYMLINK_NOFOLLOW) oflags |= O_NOFOLLOW; +# endif /* O_NOFOLLOW */ if ((fd = open(path, oflags)) == -1) return -1; ret = fchown(fd, owner, group); @@ -203,8 +205,10 @@ fchmodat(int fd, const char *path, mode_t mode, int flag) # ifndef HAVE_FCHMOD return chown(pathname, owner, group); # else +# ifdef O_NOFOLLOW if (flag & AT_SYMLINK_NOFOLLOW) oflags |= O_NOFOLLOW; +# endif /* O_NOFOLLOW */ if ((fd = open(path, oflags)) == -1) return -1; ret = fchmod(fd, mode); -- cgit v1.2.3 From d0e51810f332fe44ebdba41113aacf319d35f5a5 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sat, 24 Aug 2019 15:12:11 +1000 Subject: Fix pasto in fallback code. There is no parameter called "pathname", it should simply be "path". bz#3059, patch from samuel at cendio.se. --- openbsd-compat/bsd-misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index aa1c7d7a..7a26ee40 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -172,7 +172,7 @@ fchownat(int fd, const char *path, uid_t owner, gid_t group, int flag) return -1; } # ifndef HAVE_FCHOWN - return chown(pathname, owner, group); + return chown(path, owner, group); # else # ifdef O_NOFOLLOW if (flag & AT_SYMLINK_NOFOLLOW) @@ -203,7 +203,7 @@ fchmodat(int fd, const char *path, mode_t mode, int flag) return -1; } # ifndef HAVE_FCHMOD - return chown(pathname, owner, group); + return chmod(path, mode); # else # ifdef O_NOFOLLOW if (flag & AT_SYMLINK_NOFOLLOW) -- cgit v1.2.3 From 1bcd1169c5221688418fa38606e9c69055b72451 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Tue, 29 Oct 2019 19:45:03 +1100 Subject: Add implementation of localtime_r. --- openbsd-compat/bsd-misc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 7a26ee40..829e0c07 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -426,3 +426,13 @@ int _ssh_compat_fflush(FILE *f) return fflush(f); } #endif + +#ifndef HAVE_LOCALTIME_R +struct tm * +localtime_r(const time_t *timep, struct tm *result) +{ + struct tm *tm = localtime(timep); + *result = *tm; + return result; +} +#endif -- cgit v1.2.3 From 41a2e64ae480eda73ee0e809bbe743d203890938 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Mon, 17 Feb 2020 22:51:00 +1100 Subject: Prevent unused variable warning. --- openbsd-compat/bsd-misc.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'openbsd-compat/bsd-misc.c') diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 829e0c07..059b6d3b 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -129,7 +129,9 @@ utimensat(int fd, const char *path, const struct timespec times[2], int flag) { struct timeval tv[2]; +# ifdef HAVE_FUTIMES int ret, oflags = O_WRONLY; +# endif tv[0].tv_sec = times[0].tv_sec; tv[0].tv_usec = times[0].tv_nsec / 1000; -- cgit v1.2.3