summaryrefslogtreecommitdiffstats
path: root/crypto/openssh/openbsd-compat
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2003-04-23 16:53:02 +0000
committerdes <des@FreeBSD.org>2003-04-23 16:53:02 +0000
commit6d34992e86f885f08b7df6e18a0b6af25ec2d664 (patch)
tree1a380064758bab3bc985ef1cc15a7b6633825c0f /crypto/openssh/openbsd-compat
parentdf96ff7f3774ba5a36cf1c6729762872945cc60a (diff)
parent85b37b9574631df0f7e774dda373514195c74b29 (diff)
downloadFreeBSD-src-6d34992e86f885f08b7df6e18a0b6af25ec2d664.zip
FreeBSD-src-6d34992e86f885f08b7df6e18a0b6af25ec2d664.tar.gz
This commit was generated by cvs2svn to compensate for changes in r113908,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'crypto/openssh/openbsd-compat')
-rw-r--r--crypto/openssh/openbsd-compat/Makefile.in4
-rw-r--r--crypto/openssh/openbsd-compat/base64.c9
-rw-r--r--crypto/openssh/openbsd-compat/base64.h11
-rw-r--r--crypto/openssh/openbsd-compat/basename.c73
-rw-r--r--crypto/openssh/openbsd-compat/basename.h12
-rw-r--r--crypto/openssh/openbsd-compat/bsd-arc4random.c4
-rw-r--r--crypto/openssh/openbsd-compat/bsd-cray.h6
-rw-r--r--crypto/openssh/openbsd-compat/bsd-cygwin_util.c72
-rw-r--r--crypto/openssh/openbsd-compat/bsd-getpeereid.c4
-rw-r--r--crypto/openssh/openbsd-compat/bsd-misc.c43
-rw-r--r--crypto/openssh/openbsd-compat/bsd-misc.h11
-rw-r--r--crypto/openssh/openbsd-compat/bsd-snprintf.c9
-rw-r--r--crypto/openssh/openbsd-compat/fake-getaddrinfo.c28
-rw-r--r--crypto/openssh/openbsd-compat/fake-getaddrinfo.h2
-rw-r--r--crypto/openssh/openbsd-compat/getcwd.c4
-rw-r--r--crypto/openssh/openbsd-compat/getopt.c5
-rw-r--r--crypto/openssh/openbsd-compat/mktemp.c4
-rw-r--r--crypto/openssh/openbsd-compat/mktemp.h6
-rw-r--r--crypto/openssh/openbsd-compat/openbsd-compat.h4
-rw-r--r--crypto/openssh/openbsd-compat/port-aix.h11
-rw-r--r--crypto/openssh/openbsd-compat/setenv.c5
-rw-r--r--crypto/openssh/openbsd-compat/setproctitle.c281
-rw-r--r--crypto/openssh/openbsd-compat/setproctitle.h3
-rw-r--r--crypto/openssh/openbsd-compat/sys-tree.h8
-rw-r--r--crypto/openssh/openbsd-compat/vis.c232
-rw-r--r--crypto/openssh/openbsd-compat/vis.h91
26 files changed, 820 insertions, 122 deletions
diff --git a/crypto/openssh/openbsd-compat/Makefile.in b/crypto/openssh/openbsd-compat/Makefile.in
index 5229e7e..8615e36 100644
--- a/crypto/openssh/openbsd-compat/Makefile.in
+++ b/crypto/openssh/openbsd-compat/Makefile.in
@@ -1,4 +1,4 @@
-# $Id: Makefile.in,v 1.23 2002/09/12 00:33:02 djm Exp $
+# $Id: Makefile.in,v 1.25 2003/02/24 01:55:56 djm Exp $
sysconfdir=@sysconfdir@
piddir=@piddir@
@@ -16,7 +16,7 @@ RANLIB=@RANLIB@
INSTALL=@INSTALL@
LDFLAGS=-L. @LDFLAGS@
-OPENBSD=base64.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o
+OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o vis.o
COMPAT=bsd-arc4random.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-snprintf.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o xmmap.o
diff --git a/crypto/openssh/openbsd-compat/base64.c b/crypto/openssh/openbsd-compat/base64.c
index 005170b..91a5ab0 100644
--- a/crypto/openssh/openbsd-compat/base64.c
+++ b/crypto/openssh/openbsd-compat/base64.c
@@ -44,7 +44,7 @@
#include "includes.h"
-#if !defined(HAVE_B64_NTOP) && !defined(HAVE___B64_NTOP)
+#if (!defined(HAVE_B64_NTOP) && !defined(HAVE___B64_NTOP)) || (!defined(HAVE_B64_PTON) && !defined(HAVE___B64_PTON))
#include <sys/types.h>
#include <sys/param.h>
@@ -130,6 +130,7 @@ static const char Pad64 = '=';
characters followed by one "=" padding character.
*/
+#if !defined(HAVE_B64_NTOP) && !defined(HAVE___B64_NTOP)
int
b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize)
{
@@ -190,6 +191,9 @@ b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize)
target[datalength] = '\0'; /* Returned value doesn't count \0. */
return (datalength);
}
+#endif /* !defined(HAVE_B64_NTOP) && !defined(HAVE___B64_NTOP) */
+
+#if !defined(HAVE_B64_PTON) && !defined(HAVE___B64_PTON)
/* skips all whitespace anywhere.
converts characters, four at a time, starting at (or after)
@@ -314,4 +318,5 @@ b64_pton(char const *src, u_char *target, size_t targsize)
return (tarindex);
}
-#endif /* !defined(HAVE_B64_NTOP) && !defined(HAVE___B64_NTOP) */
+#endif /* !defined(HAVE_B64_PTON) && !defined(HAVE___B64_PTON) */
+#endif
diff --git a/crypto/openssh/openbsd-compat/base64.h b/crypto/openssh/openbsd-compat/base64.h
index c92e70e..72db3ff 100644
--- a/crypto/openssh/openbsd-compat/base64.h
+++ b/crypto/openssh/openbsd-compat/base64.h
@@ -1,4 +1,4 @@
-/* $Id: base64.h,v 1.3 2002/02/26 16:59:59 stevesk Exp $ */
+/* $Id: base64.h,v 1.4 2003/02/24 04:45:43 djm Exp $ */
#ifndef _BSD_BASE64_H
#define _BSD_BASE64_H
@@ -9,10 +9,15 @@
# ifndef HAVE_B64_NTOP
int b64_ntop(u_char const *src, size_t srclength, char *target,
size_t targsize);
-int b64_pton(char const *src, u_char *target, size_t targsize);
# endif /* !HAVE_B64_NTOP */
# define __b64_ntop b64_ntop
-# define __b64_pton b64_pton
#endif /* HAVE___B64_NTOP */
+#ifndef HAVE___B64_PTON
+# ifndef HAVE_B64_PTON
+int b64_pton(char const *src, u_char *target, size_t targsize);
+# endif /* !HAVE_B64_PTON */
+# define __b64_pton b64_pton
+#endif /* HAVE___B64_PTON */
+
#endif /* _BSD_BASE64_H */
diff --git a/crypto/openssh/openbsd-compat/basename.c b/crypto/openssh/openbsd-compat/basename.c
new file mode 100644
index 0000000..5a3823b
--- /dev/null
+++ b/crypto/openssh/openbsd-compat/basename.c
@@ -0,0 +1,73 @@
+/* $OpenBSD: basename.c,v 1.8 2002/06/09 05:03:59 deraadt Exp $ */
+
+/*
+ * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
+ * 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 "includes.h"
+
+#if !defined(HAVE_BASENAME)
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: basename.c,v 1.8 2002/06/09 05:03:59 deraadt Exp $";
+#endif /* not lint */
+
+char *
+basename(const char *path)
+{
+ static char bname[MAXPATHLEN];
+ register const char *endp, *startp;
+
+ /* Empty or NULL string gets treated as "." */
+ if (path == NULL || *path == '\0') {
+ (void)strlcpy(bname, ".", sizeof bname);
+ return(bname);
+ }
+
+ /* Strip trailing slashes */
+ endp = path + strlen(path) - 1;
+ while (endp > path && *endp == '/')
+ endp--;
+
+ /* All slashes become "/" */
+ if (endp == path && *endp == '/') {
+ (void)strlcpy(bname, "/", sizeof bname);
+ return(bname);
+ }
+
+ /* Find the start of the base */
+ startp = endp;
+ while (startp > path && *(startp - 1) != '/')
+ startp--;
+
+ if (endp - startp + 2 > sizeof(bname)) {
+ errno = ENAMETOOLONG;
+ return(NULL);
+ }
+ strlcpy(bname, startp, endp - startp + 2);
+ return(bname);
+}
+
+#endif /* !defined(HAVE_BASENAME) */
diff --git a/crypto/openssh/openbsd-compat/basename.h b/crypto/openssh/openbsd-compat/basename.h
new file mode 100644
index 0000000..a8bd6c1
--- /dev/null
+++ b/crypto/openssh/openbsd-compat/basename.h
@@ -0,0 +1,12 @@
+/* $Id: basename.h,v 1.3 2003/02/25 03:32:16 djm Exp $ */
+
+#ifndef _BASENAME_H
+#define _BASENAME_H
+#include "config.h"
+
+#if !defined(HAVE_BASENAME)
+
+char *basename(const char *path);
+
+#endif /* !defined(HAVE_BASENAME) */
+#endif /* _BASENAME_H */
diff --git a/crypto/openssh/openbsd-compat/bsd-arc4random.c b/crypto/openssh/openbsd-compat/bsd-arc4random.c
index ab4e143..dd08130 100644
--- a/crypto/openssh/openbsd-compat/bsd-arc4random.c
+++ b/crypto/openssh/openbsd-compat/bsd-arc4random.c
@@ -25,7 +25,7 @@
#include "includes.h"
#include "log.h"
-RCSID("$Id: bsd-arc4random.c,v 1.5 2002/05/08 22:57:18 tim Exp $");
+RCSID("$Id: bsd-arc4random.c,v 1.6 2003/03/17 05:13:53 djm Exp $");
#ifndef HAVE_ARC4RANDOM
@@ -66,7 +66,7 @@ void arc4random_stir(void)
unsigned char rand_buf[SEED_SIZE];
memset(&rc4, 0, sizeof(rc4));
- if (!RAND_bytes(rand_buf, sizeof(rand_buf)))
+ if (RAND_bytes(rand_buf, sizeof(rand_buf)) <= 0)
fatal("Couldn't obtain random bytes (error %ld)",
ERR_get_error());
RC4_set_key(&rc4, sizeof(rand_buf), rand_buf);
diff --git a/crypto/openssh/openbsd-compat/bsd-cray.h b/crypto/openssh/openbsd-compat/bsd-cray.h
index 8868b43..a09954f 100644
--- a/crypto/openssh/openbsd-compat/bsd-cray.h
+++ b/crypto/openssh/openbsd-compat/bsd-cray.h
@@ -1,5 +1,5 @@
/*
- * $Id: bsd-cray.h,v 1.5 2002/09/26 00:38:51 tim Exp $
+ * $Id: bsd-cray.h,v 1.7 2003/03/21 01:05:38 mouring Exp $
*
* bsd-cray.h
*
@@ -49,6 +49,10 @@ extern char cray_tmpdir[]; /* cray tmpdir */
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 64
#endif
+#ifndef _CRAYT3E
+#include <sys/ttold.h>
+#define TIOCGPGRP (tIOC|20)
+#endif
#endif
#endif /* _BSD_CRAY_H */
diff --git a/crypto/openssh/openbsd-compat/bsd-cygwin_util.c b/crypto/openssh/openbsd-compat/bsd-cygwin_util.c
index 2396a6e..0fa5964 100644
--- a/crypto/openssh/openbsd-compat/bsd-cygwin_util.c
+++ b/crypto/openssh/openbsd-compat/bsd-cygwin_util.c
@@ -31,7 +31,7 @@
#include "includes.h"
-RCSID("$Id: bsd-cygwin_util.c,v 1.8 2002/04/15 22:00:52 stevesk Exp $");
+RCSID("$Id: bsd-cygwin_util.c,v 1.9 2002/11/09 15:59:29 mouring Exp $");
#ifdef HAVE_CYGWIN
@@ -43,6 +43,7 @@ RCSID("$Id: bsd-cygwin_util.c,v 1.8 2002/04/15 22:00:52 stevesk Exp $");
#define is_winnt (GetVersion() < 0x80000000)
#define ntsec_on(c) ((c) && strstr((c),"ntsec") && !strstr((c),"nontsec"))
+#define ntsec_off(c) ((c) && strstr((c),"nontsec"))
#define ntea_on(c) ((c) && strstr((c),"ntea") && !strstr((c),"nontea"))
#if defined(open) && open == binary_open
@@ -74,6 +75,56 @@ int binary_pipe(int fd[2])
return ret;
}
+#define HAS_CREATE_TOKEN 1
+#define HAS_NTSEC_BY_DEFAULT 2
+
+static int has_capability(int what)
+{
+ /* has_capability() basically calls uname() and checks if
+ specific capabilities of Cygwin can be evaluated from that.
+ This simplifies the calling functions which only have to ask
+ for a capability using has_capability() instead of having
+ to figure that out by themselves. */
+ static int inited;
+ static int has_create_token;
+ static int has_ntsec_by_default;
+
+ if (!inited) {
+ struct utsname uts;
+ char *c;
+
+ if (!uname(&uts)) {
+ int major_high = 0;
+ int major_low = 0;
+ int minor = 0;
+ int api_major_version = 0;
+ int api_minor_version = 0;
+ char *c;
+
+ sscanf(uts.release, "%d.%d.%d", &major_high,
+ &major_low, &minor);
+ c = strchr(uts.release, '(');
+ if (c)
+ sscanf(c + 1, "%d.%d", &api_major_version,
+ &api_minor_version);
+ if (major_high > 1 ||
+ (major_high == 1 && (major_low > 3 ||
+ (major_low == 3 && minor >= 2))))
+ has_create_token = 1;
+ if (api_major_version > 0 || api_minor_version >= 56)
+ has_ntsec_by_default = 1;
+ inited = 1;
+ }
+ }
+ switch (what) {
+ case HAS_CREATE_TOKEN:
+ return has_create_token;
+ case HAS_NTSEC_BY_DEFAULT:
+ return has_ntsec_by_default;
+ }
+ return 0;
+}
+
int check_nt_auth(int pwd_authenticated, struct passwd *pw)
{
/*
@@ -93,19 +144,14 @@ int check_nt_auth(int pwd_authenticated, struct passwd *pw)
return 0;
if (is_winnt) {
if (has_create_token < 0) {
- struct utsname uts;
- int major_high = 0, major_low = 0, minor = 0;
char *cygwin = getenv("CYGWIN");
has_create_token = 0;
- if (ntsec_on(cygwin) && !uname(&uts)) {
- sscanf(uts.release, "%d.%d.%d",
- &major_high, &major_low, &minor);
- if (major_high > 1 ||
- (major_high == 1 && (major_low > 3 ||
- (major_low == 3 && minor >= 2))))
- has_create_token = 1;
- }
+ if (has_capability(HAS_CREATE_TOKEN) &&
+ (ntsec_on(cygwin) ||
+ (has_capability(HAS_NTSEC_BY_DEFAULT) &&
+ !ntsec_off(cygwin))))
+ has_create_token = 1;
}
if (has_create_token < 1 &&
!pwd_authenticated && geteuid() != pw->pw_uid)
@@ -128,7 +174,9 @@ int check_ntsec(const char *filename)
/* Evaluate current CYGWIN settings. */
cygwin = getenv("CYGWIN");
allow_ntea = ntea_on(cygwin);
- allow_ntsec = ntsec_on(cygwin);
+ allow_ntsec = ntsec_on(cygwin) ||
+ (has_capability(HAS_NTSEC_BY_DEFAULT) &&
+ !ntsec_off(cygwin));
/*
* `ntea' is an emulation of POSIX attributes. It doesn't support
diff --git a/crypto/openssh/openbsd-compat/bsd-getpeereid.c b/crypto/openssh/openbsd-compat/bsd-getpeereid.c
index c787682..bcda2c1 100644
--- a/crypto/openssh/openbsd-compat/bsd-getpeereid.c
+++ b/crypto/openssh/openbsd-compat/bsd-getpeereid.c
@@ -24,7 +24,7 @@
#include "includes.h"
-RCSID("$Id: bsd-getpeereid.c,v 1.1 2002/09/12 00:33:02 djm Exp $");
+RCSID("$Id: bsd-getpeereid.c,v 1.2 2003/03/24 22:07:52 djm Exp $");
#if !defined(HAVE_GETPEEREID)
@@ -33,7 +33,7 @@ int
getpeereid(int s, uid_t *euid, gid_t *gid)
{
struct ucred cred;
- size_t len = sizeof(cred);
+ socklen_t len = sizeof(cred);
if (getsockopt(s, SOL_SOCKET, SO_PEERCRED, &cred, &len) < 0)
return (-1);
diff --git a/crypto/openssh/openbsd-compat/bsd-misc.c b/crypto/openssh/openbsd-compat/bsd-misc.c
index 1c1e43a..b8e9996 100644
--- a/crypto/openssh/openbsd-compat/bsd-misc.c
+++ b/crypto/openssh/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.12 2003/03/18 18:21:41 tim 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
}
@@ -129,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
+
diff --git a/crypto/openssh/openbsd-compat/bsd-misc.h b/crypto/openssh/openbsd-compat/bsd-misc.h
index 9811960..78d9ccd 100644
--- a/crypto/openssh/openbsd-compat/bsd-misc.h
+++ b/crypto/openssh/openbsd-compat/bsd-misc.h
@@ -22,7 +22,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-/* $Id: bsd-misc.h,v 1.6 2002/06/13 21:34:58 mouring Exp $ */
+/* $Id: bsd-misc.h,v 1.7 2003/03/18 18:21:41 tim Exp $ */
#ifndef _BSD_MISC_H
#define _BSD_MISC_H
@@ -80,5 +80,14 @@ int truncate (const char *path, off_t length);
int setgroups(size_t size, const gid_t *list);
#endif
+#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP)
+#ifndef HAVE_STRUCT_TIMESPEC
+struct timespec {
+ time_t tv_sec;
+ long tv_nsec;
+};
+#endif
+int nanosleep(const struct timespec *req, struct timespec *rem);
+#endif
#endif /* _BSD_MISC_H */
diff --git a/crypto/openssh/openbsd-compat/bsd-snprintf.c b/crypto/openssh/openbsd-compat/bsd-snprintf.c
index 1c72ea6..2f82180 100644
--- a/crypto/openssh/openbsd-compat/bsd-snprintf.c
+++ b/crypto/openssh/openbsd-compat/bsd-snprintf.c
@@ -1,3 +1,10 @@
+/*
+ * Copyright Patrick Powell 1995
+ * This code is based on code written by Patrick Powell (papowell@astart.com)
+ * It may be used for any purpose as long as this notice remains intact
+ * on all source code distributions
+ */
+
/**************************************************************
* Original:
* Patrick Powell Tue Apr 11 09:48:21 PDT 1995
@@ -51,7 +58,7 @@
#include "includes.h"
-RCSID("$Id: bsd-snprintf.c,v 1.5 2001/02/25 23:20:41 mouring Exp $");
+RCSID("$Id: bsd-snprintf.c,v 1.6 2003/04/01 11:31:56 djm Exp $");
#if defined(BROKEN_SNPRINTF) /* For those with broken snprintf() */
# undef HAVE_SNPRINTF
diff --git a/crypto/openssh/openbsd-compat/fake-getaddrinfo.c b/crypto/openssh/openbsd-compat/fake-getaddrinfo.c
index 67e9eb7..e63bda9 100644
--- a/crypto/openssh/openbsd-compat/fake-getaddrinfo.c
+++ b/crypto/openssh/openbsd-compat/fake-getaddrinfo.c
@@ -12,7 +12,7 @@
#include "includes.h"
#include "ssh.h"
-RCSID("$Id: fake-getaddrinfo.c,v 1.2 2001/02/09 01:55:36 djm Exp $");
+RCSID("$Id: fake-getaddrinfo.c,v 1.5 2003/03/24 02:35:59 djm Exp $");
#ifndef HAVE_GAI_STRERROR
char *gai_strerror(int ecode)
@@ -67,16 +67,30 @@ int getaddrinfo(const char *hostname, const char *servname,
{
struct addrinfo *cur, *prev = NULL;
struct hostent *hp;
+ struct servent *sp;
struct in_addr in;
- int i, port;
+ int i;
+ long int port;
+ u_long addr;
- if (servname)
- port = htons(atoi(servname));
- else
- port = 0;
+ port = 0;
+ if (servname != NULL) {
+ char *cp;
+
+ port = strtol(servname, &cp, 10);
+ if (port > 0 && port <= 65535 && *cp == '\0')
+ port = htons(port);
+ else if ((sp = getservbyname(servname, NULL)) != NULL)
+ port = sp->s_port;
+ else
+ port = 0;
+ }
if (hints && hints->ai_flags & AI_PASSIVE) {
- if (NULL != (*res = malloc_ai(port, htonl(0x00000000))))
+ addr = htonl(0x00000000);
+ if (hostname && inet_aton(hostname, &in) != 0)
+ addr = in.s_addr;
+ if (NULL != (*res = malloc_ai(port, addr)))
return 0;
else
return EAI_MEMORY;
diff --git a/crypto/openssh/openbsd-compat/fake-getaddrinfo.h b/crypto/openssh/openbsd-compat/fake-getaddrinfo.h
index afd0226..6943378 100644
--- a/crypto/openssh/openbsd-compat/fake-getaddrinfo.h
+++ b/crypto/openssh/openbsd-compat/fake-getaddrinfo.h
@@ -1,4 +1,4 @@
-/* $Id: fake-getaddrinfo.h,v 1.2 2001/02/09 01:55:36 djm Exp $ */
+/* $Id: fake-getaddrinfo.h,v 1.4 2003/02/24 01:35:09 djm Exp $ */
#ifndef _FAKE_GETADDRINFO_H
#define _FAKE_GETADDRINFO_H
diff --git a/crypto/openssh/openbsd-compat/getcwd.c b/crypto/openssh/openbsd-compat/getcwd.c
index 6fd8543..f4b98e8 100644
--- a/crypto/openssh/openbsd-compat/getcwd.c
+++ b/crypto/openssh/openbsd-compat/getcwd.c
@@ -29,7 +29,7 @@
#if !defined(HAVE_GETCWD)
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: getcwd.c,v 1.6 2000/07/19 15:25:13 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: getcwd.c,v 1.7 2002/11/24 01:52:27 cloder Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -127,7 +127,7 @@ getcwd(char *pt,size_t size)
/*
* Build pointer to the parent directory, allocating memory
* as necessary. Max length is 3 for "../", the largest
- * possible component name, plus a trailing NULL.
+ * possible component name, plus a trailing NUL.
*/
if (bup + 3 + MAXNAMLEN + 1 >= eup) {
char *nup;
diff --git a/crypto/openssh/openbsd-compat/getopt.c b/crypto/openssh/openbsd-compat/getopt.c
index 4a5cfe5..a3fe807 100644
--- a/crypto/openssh/openbsd-compat/getopt.c
+++ b/crypto/openssh/openbsd-compat/getopt.c
@@ -35,7 +35,7 @@
#if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_OPTRESET)
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: getopt.c,v 1.2 1996/08/19 08:33:32 tholo Exp $";
+static char *rcsid = "$OpenBSD: getopt.c,v 1.4 2002/12/08 22:57:14 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -66,6 +66,9 @@ BSDgetopt(nargc, nargv, ostr)
static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
+ if (ostr == NULL)
+ return (-1);
+
if (BSDoptreset || !*place) { /* update scanning pointer */
BSDoptreset = 0;
if (BSDoptind >= nargc || *(place = nargv[BSDoptind]) != '-') {
diff --git a/crypto/openssh/openbsd-compat/mktemp.c b/crypto/openssh/openbsd-compat/mktemp.c
index d256ee4..c951050 100644
--- a/crypto/openssh/openbsd-compat/mktemp.c
+++ b/crypto/openssh/openbsd-compat/mktemp.c
@@ -36,7 +36,7 @@
#include "includes.h"
-#ifndef HAVE_MKDTEMP
+#if !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP)
#if defined(LIBC_SCCS) && !defined(lint)
static char rcsid[] = "$OpenBSD: mktemp.c,v 1.16 2002/05/27 18:20:45 millert Exp $";
@@ -181,4 +181,4 @@ _gettemp(path, doopen, domkdir, slen)
/*NOTREACHED*/
}
-#endif /* !HAVE_MKDTEMP */
+#endif /* !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP) */
diff --git a/crypto/openssh/openbsd-compat/mktemp.h b/crypto/openssh/openbsd-compat/mktemp.h
index 6a96f6f..505ca6a 100644
--- a/crypto/openssh/openbsd-compat/mktemp.h
+++ b/crypto/openssh/openbsd-compat/mktemp.h
@@ -1,13 +1,13 @@
-/* $Id: mktemp.h,v 1.2 2001/02/09 01:55:36 djm Exp $ */
+/* $Id: mktemp.h,v 1.3 2003/01/07 04:18:33 djm Exp $ */
#ifndef _BSD_MKTEMP_H
#define _BSD_MKTEMP_H
#include "config.h"
-#ifndef HAVE_MKDTEMP
+#if !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP)
int mkstemps(char *path, int slen);
int mkstemp(char *path);
char *mkdtemp(char *path);
-#endif /* !HAVE_MKDTEMP */
+#endif /* !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP) */
#endif /* _BSD_MKTEMP_H */
diff --git a/crypto/openssh/openbsd-compat/openbsd-compat.h b/crypto/openssh/openbsd-compat/openbsd-compat.h
index ae18afd..c3e19b9 100644
--- a/crypto/openssh/openbsd-compat/openbsd-compat.h
+++ b/crypto/openssh/openbsd-compat/openbsd-compat.h
@@ -1,4 +1,4 @@
-/* $Id: openbsd-compat.h,v 1.17 2002/09/12 00:33:02 djm Exp $ */
+/* $Id: openbsd-compat.h,v 1.19 2003/02/24 01:55:56 djm Exp $ */
#ifndef _OPENBSD_H
#define _OPENBSD_H
@@ -6,6 +6,7 @@
#include "config.h"
/* OpenBSD function replacements */
+#include "basename.h"
#include "bindresvport.h"
#include "getcwd.h"
#include "realpath.h"
@@ -26,6 +27,7 @@
#include "glob.h"
#include "readpassphrase.h"
#include "getopt.h"
+#include "vis.h"
/* Home grown routines */
#include "bsd-arc4random.h"
diff --git a/crypto/openssh/openbsd-compat/port-aix.h b/crypto/openssh/openbsd-compat/port-aix.h
index 79570a2..4abe003 100644
--- a/crypto/openssh/openbsd-compat/port-aix.h
+++ b/crypto/openssh/openbsd-compat/port-aix.h
@@ -25,5 +25,16 @@
*/
#ifdef _AIX
+
+/* AIX 4.2.x doesn't have nanosleep but does have nsleep which is equivalent */
+#if !defined(HAVE_NANOSLEEP) && defined(HAVE_NSLEEP)
+# define nanosleep(a,b) nsleep(a,b)
+#endif
+
+/* For struct timespec on AIX 4.2.x */
+#ifdef HAVE_SYS_TIMERS_H
+# include <sys/timers.h>
+#endif
+
void aix_usrinfo(struct passwd *pw);
#endif /* _AIX */
diff --git a/crypto/openssh/openbsd-compat/setenv.c b/crypto/openssh/openbsd-compat/setenv.c
index 1dff15c..e5c5de6 100644
--- a/crypto/openssh/openbsd-compat/setenv.c
+++ b/crypto/openssh/openbsd-compat/setenv.c
@@ -35,12 +35,14 @@
#ifndef HAVE_SETENV
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: setenv.c,v 1.4 2001/07/09 06:57:45 deraadt Exp $";
+static char *rcsid = "$OpenBSD: setenv.c,v 1.5 2002/12/10 22:44:13 mickey Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdlib.h>
#include <string.h>
+char *__findenv(const char *name, int *offset);
+
/*
* __findenv --
* Returns pointer to value associated with name, if any, else NULL.
@@ -92,7 +94,6 @@ setenv(name, value, rewrite)
static int alloced; /* if allocated space before */
register char *C;
int l_value, offset;
- char *__findenv();
if (*value == '=') /* no `=' in value */
++value;
diff --git a/crypto/openssh/openbsd-compat/setproctitle.c b/crypto/openssh/openbsd-compat/setproctitle.c
index e165dd1..07af7e9 100644
--- a/crypto/openssh/openbsd-compat/setproctitle.c
+++ b/crypto/openssh/openbsd-compat/setproctitle.c
@@ -1,102 +1,243 @@
/*
- * Modified for OpenSSH by Kevin Steves
- * October 2000
+ * Based on src/backend/utils/misc/pg_status.c from
+ * PostgreSQL Database Management System
+ *
+ * Portions Copyright (c) 1996-2001, The PostgreSQL Global Development Group
+ *
+ * Portions Copyright (c) 1994, The Regents of the University of California
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without a written agreement
+ * is hereby granted, provided that the above copyright notice and this
+ * paragraph and the following two paragraphs appear in all copies.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
+ * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
+ * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*/
-/*
- * Copyright (c) 1994, 1995 Christopher G. Demetriou
- * All rights reserved.
+/*--------------------------------------------------------------------
+ * ps_status.c
+ *
+ * Routines to support changing the ps display of PostgreSQL backends
+ * to contain some useful information. Mechanism differs wildly across
+ * platforms.
*
- * 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 Christopher G. Demetriou
- * for the NetBSD Project.
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission
+ * $Header: /var/cvs/openssh/openbsd-compat/setproctitle.c,v 1.5 2003/01/20 02:15:11 djm Exp $
*
- * 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.
+ * Copyright 2000 by PostgreSQL Global Development Group
+ * various details abducted from various places
+ *--------------------------------------------------------------------
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: setproctitle.c,v 1.8 2001/11/06 19:21:40 art Exp $";
-#endif /* LIBC_SCCS and not lint */
-
#include "includes.h"
#ifndef HAVE_SETPROCTITLE
-#define SPT_NONE 0
-#define SPT_PSTAT 1
+#include <unistd.h>
+#ifdef HAVE_SYS_PSTAT_H
+#include <sys/pstat.h> /* for HP-UX */
+#endif
+#ifdef HAVE_PS_STRINGS
+#include <machine/vmparam.h> /* for old BSD */
+#include <sys/exec.h>
+#endif
+
+/*------
+ * Alternative ways of updating ps display:
+ *
+ * SETPROCTITLE_STRATEGY == PS_USE_PSTAT
+ * use the pstat(PSTAT_SETCMD, )
+ * (HPUX)
+ * SETPROCTITLE_STRATEGY == PS_USE_PS_STRINGS
+ * assign PS_STRINGS->ps_argvstr = "string"
+ * (some BSD systems)
+ * SETPROCTITLE_STRATEGY == PS_USE_CHANGE_ARGV
+ * assign argv[0] = "string"
+ * (some other BSD systems)
+ * SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
+ * write over the argv and environment area
+ * (most SysV-like systems)
+ * SETPROCTITLE_STRATEGY == PS_USE_NONE
+ * don't update ps display
+ * (This is the default, as it is safest.)
+ */
+
+#define PS_USE_NONE 0
+#define PS_USE_PSTAT 1
+#define PS_USE_PS_STRINGS 2
+#define PS_USE_CHANGE_ARGV 3
+#define PS_USE_CLOBBER_ARGV 4
-#ifndef SPT_TYPE
-#define SPT_TYPE SPT_NONE
+#ifndef SETPROCTITLE_STRATEGY
+# define SETPROCTITLE_STRATEGY PS_USE_NONE
#endif
-#if SPT_TYPE == SPT_PSTAT
-#include <sys/param.h>
-#include <sys/pstat.h>
-#endif /* SPT_TYPE == SPT_PSTAT */
+#ifndef SETPROCTITLE_PS_PADDING
+# define SETPROCTITLE_PS_PADDING ' '
+#endif
+#endif /* HAVE_SETPROCTITLE */
-#define MAX_PROCTITLE 2048
+extern char **environ;
+
+/*
+ * argv clobbering uses existing argv space, all other methods need a buffer
+ */
+#if SETPROCTITLE_STRATEGY != PS_USE_CLOBBER_ARGV
+static char ps_buffer[256];
+static const size_t ps_buffer_size = sizeof(ps_buffer);
+#else
+static char *ps_buffer; /* will point to argv area */
+static size_t ps_buffer_size; /* space determined at run time */
+#endif
+
+/* save the original argv[] location here */
+static int save_argc;
+static char **save_argv;
extern char *__progname;
+#ifndef HAVE_SETPROCTITLE
/*
- * Set Process Title (SPT) defines. Modeled after sendmail's
- * SPT type definition strategy.
- *
- * SPT_TYPE:
- *
- * SPT_NONE: Don't set the process title. Default.
- * SPT_PSTAT: Use pstat(PSTAT_SETCMD). HP-UX specific.
+ * Call this to update the ps status display to a fixed prefix plus an
+ * indication of what you're currently doing passed in the argument.
*/
-
void
setproctitle(const char *fmt, ...)
{
-#if SPT_TYPE != SPT_NONE
+#if SETPROCTITLE_STRATEGY == PS_USE_PSTAT
+ union pstun pst;
+#endif
+#if SETPROCTITLE_STRATEGY != PS_USE_NONE
+ ssize_t used;
va_list ap;
-
- char buf[MAX_PROCTITLE];
- size_t used;
-#if SPT_TYPE == SPT_PSTAT
- union pstun pst;
-#endif /* SPT_TYPE == SPT_PSTAT */
+ /* no ps display if you didn't call save_ps_display_args() */
+ if (save_argv == NULL)
+ return;
+#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
+ /* If ps_buffer is a pointer, it might still be null */
+ if (ps_buffer == NULL)
+ return;
+#endif /* PS_USE_CLOBBER_ARGV */
+
+ /*
+ * Overwrite argv[] to point at appropriate space, if needed
+ */
+#if SETPROCTITLE_STRATEGY == PS_USE_CHANGE_ARGV
+ save_argv[0] = ps_buffer;
+ save_argv[1] = NULL;
+#endif /* PS_USE_CHANGE_ARGV */
+
+#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
+ save_argv[1] = NULL;
+#endif /* PS_USE_CLOBBER_ARGV */
+
+ /*
+ * Make fixed prefix of ps display.
+ */
va_start(ap, fmt);
- if (fmt != NULL) {
- used = snprintf(buf, MAX_PROCTITLE, "%s: ", __progname);
- if (used >= MAX_PROCTITLE)
- used = MAX_PROCTITLE - 1;
- (void)vsnprintf(buf + used, MAX_PROCTITLE - used, fmt, ap);
- } else
- (void)snprintf(buf, MAX_PROCTITLE, "%s", __progname);
+ if (fmt == NULL)
+ snprintf(ps_buffer, ps_buffer_size, "%s", __progname);
+ else {
+ used = snprintf(ps_buffer, ps_buffer_size, "%s: ", __progname);
+ if (used == -1 || used >= ps_buffer_size)
+ used = ps_buffer_size;
+ vsnprintf(ps_buffer + used, ps_buffer_size - used, fmt, ap);
+ }
va_end(ap);
- used = strlen(buf);
-#if SPT_TYPE == SPT_PSTAT
- pst.pst_command = buf;
- pstat(PSTAT_SETCMD, pst, used, 0, 0);
-#endif /* SPT_TYPE == SPT_PSTAT */
+#if SETPROCTITLE_STRATEGY == PS_USE_PSTAT
+ pst.pst_command = ps_buffer;
+ pstat(PSTAT_SETCMD, pst, strlen(ps_buffer), 0, 0);
+#endif /* PS_USE_PSTAT */
-#endif /* SPT_TYPE != SPT_NONE */
+#if SETPROCTITLE_STRATEGY == PS_USE_PS_STRINGS
+ PS_STRINGS->ps_nargvstr = 1;
+ PS_STRINGS->ps_argvstr = ps_buffer;
+#endif /* PS_USE_PS_STRINGS */
+
+#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
+ /* pad unused memory */
+ used = strlen(ps_buffer);
+ memset(ps_buffer + used, SETPROCTITLE_PS_PADDING,
+ ps_buffer_size - used);
+#endif /* PS_USE_CLOBBER_ARGV */
+
+#endif /* PS_USE_NONE */
}
+
#endif /* HAVE_SETPROCTITLE */
+
+/*
+ * Call this early in startup to save the original argc/argv values.
+ *
+ * argv[] will not be overwritten by this routine, but may be overwritten
+ * during setproctitle. Also, the physical location of the environment
+ * strings may be moved, so this should be called before any code that
+ * might try to hang onto a getenv() result.
+ */
+void
+compat_init_setproctitle(int argc, char *argv[])
+{
+#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
+ char *end_of_area = NULL;
+ char **new_environ;
+ int i;
+#endif
+
+ save_argc = argc;
+ save_argv = argv;
+
+#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
+ /*
+ * If we're going to overwrite the argv area, count the available
+ * space. Also move the environment to make additional room.
+ */
+
+ /*
+ * check for contiguous argv strings
+ */
+ for (i = 0; i < argc; i++) {
+ if (i == 0 || end_of_area + 1 == argv[i])
+ end_of_area = argv[i] + strlen(argv[i]);
+ }
+
+ /* probably can't happen? */
+ if (end_of_area == NULL) {
+ ps_buffer = NULL;
+ ps_buffer_size = 0;
+ return;
+ }
+
+ /*
+ * check for contiguous environ strings following argv
+ */
+ for (i = 0; environ[i] != NULL; i++) {
+ if (end_of_area + 1 == environ[i])
+ end_of_area = environ[i] + strlen(environ[i]);
+ }
+
+ ps_buffer = argv[0];
+ ps_buffer_size = end_of_area - argv[0] - 1;
+
+ /*
+ * Duplicate and move the environment out of the way
+ */
+ new_environ = malloc(sizeof(char *) * (i + 1));
+ for (i = 0; environ[i] != NULL; i++)
+ new_environ[i] = strdup(environ[i]);
+ new_environ[i] = NULL;
+ environ = new_environ;
+#endif /* PS_USE_CLOBBER_ARGV */
+}
+
diff --git a/crypto/openssh/openbsd-compat/setproctitle.h b/crypto/openssh/openbsd-compat/setproctitle.h
index 8261bd0..48d26c6 100644
--- a/crypto/openssh/openbsd-compat/setproctitle.h
+++ b/crypto/openssh/openbsd-compat/setproctitle.h
@@ -1,4 +1,4 @@
-/* $Id: setproctitle.h,v 1.2 2001/02/09 01:55:36 djm Exp $ */
+/* $Id: setproctitle.h,v 1.3 2003/01/09 22:53:13 djm Exp $ */
#ifndef _BSD_SETPROCTITLE_H
#define _BSD_SETPROCTITLE_H
@@ -7,6 +7,7 @@
#ifndef HAVE_SETPROCTITLE
void setproctitle(const char *fmt, ...);
+void compat_init_setproctitle(int argc, char *argv[]);
#endif
#endif /* _BSD_SETPROCTITLE_H */
diff --git a/crypto/openssh/openbsd-compat/sys-tree.h b/crypto/openssh/openbsd-compat/sys-tree.h
index 0a58710..927ca04 100644
--- a/crypto/openssh/openbsd-compat/sys-tree.h
+++ b/crypto/openssh/openbsd-compat/sys-tree.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tree.h,v 1.6 2002/06/11 22:09:52 provos Exp $ */
+/* $OpenBSD: tree.h,v 1.7 2002/10/17 21:51:54 art Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -343,12 +343,13 @@ struct { \
RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \
else \
RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \
- RB_AUGMENT(RB_PARENT(elm, field)); \
} else \
(head)->rbh_root = (tmp); \
RB_LEFT(tmp, field) = (elm); \
RB_PARENT(elm, field) = (tmp); \
RB_AUGMENT(tmp); \
+ if ((RB_PARENT(tmp, field))) \
+ RB_AUGMENT(RB_PARENT(tmp, field)); \
} while (0)
#define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \
@@ -362,12 +363,13 @@ struct { \
RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \
else \
RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \
- RB_AUGMENT(RB_PARENT(elm, field)); \
} else \
(head)->rbh_root = (tmp); \
RB_RIGHT(tmp, field) = (elm); \
RB_PARENT(elm, field) = (tmp); \
RB_AUGMENT(tmp); \
+ if ((RB_PARENT(tmp, field))) \
+ RB_AUGMENT(RB_PARENT(tmp, field)); \
} while (0)
/* Generates prototypes and inline functions */
diff --git a/crypto/openssh/openbsd-compat/vis.c b/crypto/openssh/openbsd-compat/vis.c
new file mode 100644
index 0000000..fc57413
--- /dev/null
+++ b/crypto/openssh/openbsd-compat/vis.c
@@ -0,0 +1,232 @@
+/*-
+ * Copyright (c) 1989, 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"
+#if !defined(HAVE_STRNVIS)
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$OpenBSD: vis.c,v 1.8 2002/02/19 19:39:36 millert Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <ctype.h>
+
+#include "vis.h"
+
+#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
+#define isvisible(c) (((u_int)(c) <= UCHAR_MAX && isascii((u_char)(c)) && \
+ isgraph((u_char)(c))) || \
+ ((flag & VIS_SP) == 0 && (c) == ' ') || \
+ ((flag & VIS_TAB) == 0 && (c) == '\t') || \
+ ((flag & VIS_NL) == 0 && (c) == '\n') || \
+ ((flag & VIS_SAFE) && \
+ ((c) == '\b' || (c) == '\007' || (c) == '\r')))
+
+/*
+ * vis - visually encode characters
+ */
+char *
+vis(dst, c, flag, nextc)
+ register char *dst;
+ int c, nextc;
+ register int flag;
+{
+ if (isvisible(c)) {
+ *dst++ = c;
+ if (c == '\\' && (flag & VIS_NOSLASH) == 0)
+ *dst++ = '\\';
+ *dst = '\0';
+ return (dst);
+ }
+
+ if (flag & VIS_CSTYLE) {
+ switch(c) {
+ case '\n':
+ *dst++ = '\\';
+ *dst++ = 'n';
+ goto done;
+ case '\r':
+ *dst++ = '\\';
+ *dst++ = 'r';
+ goto done;
+ case '\b':
+ *dst++ = '\\';
+ *dst++ = 'b';
+ goto done;
+ case '\a':
+ *dst++ = '\\';
+ *dst++ = 'a';
+ goto done;
+ case '\v':
+ *dst++ = '\\';
+ *dst++ = 'v';
+ goto done;
+ case '\t':
+ *dst++ = '\\';
+ *dst++ = 't';
+ goto done;
+ case '\f':
+ *dst++ = '\\';
+ *dst++ = 'f';
+ goto done;
+ case ' ':
+ *dst++ = '\\';
+ *dst++ = 's';
+ goto done;
+ case '\0':
+ *dst++ = '\\';
+ *dst++ = '0';
+ if (isoctal(nextc)) {
+ *dst++ = '0';
+ *dst++ = '0';
+ }
+ goto done;
+ }
+ }
+ if (((c & 0177) == ' ') || (flag & VIS_OCTAL)) {
+ *dst++ = '\\';
+ *dst++ = ((u_char)c >> 6 & 07) + '0';
+ *dst++ = ((u_char)c >> 3 & 07) + '0';
+ *dst++ = ((u_char)c & 07) + '0';
+ goto done;
+ }
+ if ((flag & VIS_NOSLASH) == 0)
+ *dst++ = '\\';
+ if (c & 0200) {
+ c &= 0177;
+ *dst++ = 'M';
+ }
+ if (iscntrl(c)) {
+ *dst++ = '^';
+ if (c == 0177)
+ *dst++ = '?';
+ else
+ *dst++ = c + '@';
+ } else {
+ *dst++ = '-';
+ *dst++ = c;
+ }
+done:
+ *dst = '\0';
+ return (dst);
+}
+
+/*
+ * strvis, strnvis, strvisx - visually encode characters from src into dst
+ *
+ * Dst must be 4 times the size of src to account for possible
+ * expansion. The length of dst, not including the trailing NULL,
+ * is returned.
+ *
+ * Strnvis will write no more than siz-1 bytes (and will NULL terminate).
+ * The number of bytes needed to fully encode the string is returned.
+ *
+ * Strvisx encodes exactly len bytes from src into dst.
+ * This is useful for encoding a block of data.
+ */
+int
+strvis(dst, src, flag)
+ register char *dst;
+ register const char *src;
+ int flag;
+{
+ register char c;
+ char *start;
+
+ for (start = dst; (c = *src);)
+ dst = vis(dst, c, flag, *++src);
+ *dst = '\0';
+ return (dst - start);
+}
+
+int
+strnvis(dst, src, siz, flag)
+ register char *dst;
+ register const char *src;
+ size_t siz;
+ int flag;
+{
+ register char c;
+ char *start, *end;
+
+ for (start = dst, end = start + siz - 1; (c = *src) && dst < end; ) {
+ if (isvisible(c)) {
+ *dst++ = c;
+ if (c == '\\' && (flag & VIS_NOSLASH) == 0) {
+ /* need space for the extra '\\' */
+ if (dst < end)
+ *dst++ = '\\';
+ else {
+ dst--;
+ break;
+ }
+ }
+ src++;
+ } else {
+ /* vis(3) requires up to 4 chars */
+ if (dst + 3 < end)
+ dst = vis(dst, c, flag, *++src);
+ else
+ break;
+ }
+ }
+ *dst = '\0';
+ if (dst >= end) {
+ char tbuf[5];
+
+ /* adjust return value for truncation */
+ while ((c = *src))
+ dst += vis(tbuf, c, flag, *++src) - tbuf;
+ }
+ return (dst - start);
+}
+
+int
+strvisx(dst, src, len, flag)
+ register char *dst;
+ register const char *src;
+ register size_t len;
+ int flag;
+{
+ register char c;
+ char *start;
+
+ for (start = dst; len > 1; len--) {
+ c = *src;
+ dst = vis(dst, c, flag, *++src);
+ }
+ if (len)
+ dst = vis(dst, *src, flag, '\0');
+ *dst = '\0';
+ return (dst - start);
+}
+
+#endif
diff --git a/crypto/openssh/openbsd-compat/vis.h b/crypto/openssh/openbsd-compat/vis.h
new file mode 100644
index 0000000..5df6f36
--- /dev/null
+++ b/crypto/openssh/openbsd-compat/vis.h
@@ -0,0 +1,91 @@
+/* $OpenBSD: vis.h,v 1.5 2002/02/16 21:27:17 millert Exp $ */
+/* $NetBSD: vis.h,v 1.4 1994/10/26 00:56:41 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1990 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.
+ *
+ * @(#)vis.h 5.9 (Berkeley) 4/3/91
+ */
+#include "config.h"
+#if !defined(HAVE_STRNVIS)
+
+#ifndef _VIS_H_
+#define _VIS_H_
+
+#include <sys/types.h>
+#include <limits.h>
+
+/*
+ * to select alternate encoding format
+ */
+#define VIS_OCTAL 0x01 /* use octal \ddd format */
+#define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropriate */
+
+/*
+ * to alter set of characters encoded (default is to encode all
+ * non-graphic except space, tab, and newline).
+ */
+#define VIS_SP 0x04 /* also encode space */
+#define VIS_TAB 0x08 /* also encode tab */
+#define VIS_NL 0x10 /* also encode newline */
+#define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL)
+#define VIS_SAFE 0x20 /* only encode "unsafe" characters */
+
+/*
+ * other
+ */
+#define VIS_NOSLASH 0x40 /* inhibit printing '\' */
+
+/*
+ * unvis return codes
+ */
+#define UNVIS_VALID 1 /* character valid */
+#define UNVIS_VALIDPUSH 2 /* character valid, push back passed char */
+#define UNVIS_NOCHAR 3 /* valid sequence, no character produced */
+#define UNVIS_SYNBAD -1 /* unrecognized escape sequence */
+#define UNVIS_ERROR -2 /* decoder in unknown state (unrecoverable) */
+
+/*
+ * unvis flags
+ */
+#define UNVIS_END 1 /* no more characters */
+
+char *vis(char *, int, int, int);
+int strvis(char *, const char *, int);
+int strnvis(char *, const char *, size_t, int);
+int strvisx(char *, const char *, size_t, int);
+int strunvis(char *, const char *);
+int unvis(char *, char, int *, int);
+
+#endif /* !_VIS_H_ */
+
+#endif /* !HAVE_STRNVIS */
OpenPOWER on IntegriCloud