Hi.
SunOS 4 is one system that relies on the strerror() in bsd-misc.[ch].
However, that replacement function does not have the right prototype.
This is fixed in the patch below. There was also an error with
sys_errlist not being explicitely declared. Also fixed.
There was another weird link-time problem with bsd-misc.o being at the
same time used by some *.o in libssh.a and using itself entropy.o in
libssh.a. This only showed up in linking scp which doesn't need
libssh.a. The only solution to this is to separate those functions
(the rc4 stuff) that exhibit this property in their own file so that
programs like scp that attempt to use other functions in bsd-misc.o
link correctly. I tried all other potential solutions of removing
bsd-misc.o and placing it separately on the command line, or leaving
it where it is, in all possible orders, and those don't work. So, I
placed the rc4 stuff in bsd-rc4.[ch].
Here is the patch, as well as the error lines if you are curious about
those.
Charles
=======================================================================---
Makefile.in.orig-2.1.1p4 Tue Jul 11 07:34:34 2000
+++ Makefile.in Mon Jul 17 02:55:46 2000
@@ -36,7 +36,7 @@
LIBSSH_OBJS=atomicio.o authfd.o authfile.o aux.o bufaux.o buffer.o canohost.o
channels.o cipher.o compat.o compress.o crc32.o deattack.o dispatch.o dsa.o
fingerprint.o hmac.o hostfile.o key.o kex.o log.o match.o mpaux.o nchan.o
packet.o radix.o entropy.o readpass.o rsa.o tildexpand.o ttymodes.o uidswap.o
uuencode.o xmalloc.o
-LIBOPENBSD_COMPAT_OBJS=bsd-base64.o bsd-bindresvport.o bsd-daemon.o
bsd-inet_aton.o bsd-misc.o bsd-mktemp.o bsd-rresvport.o bsd-setenv.o
bsd-sigaction.o bsd-snprintf.o bsd-strlcat.o bsd-strlcpy.o bsd-strsep.o
fake-getaddrinfo.o fake-getnameinfo.o next-posix.o
+LIBOPENBSD_COMPAT_OBJS=bsd-base64.o bsd-bindresvport.o bsd-daemon.o
bsd-inet_aton.o bsd-misc.o bsd-mktemp.o bsd-rc4.o bsd-rresvport.o bsd-setenv.o
bsd-sigaction.o bsd-snprintf.o bsd-strlcat.o bsd-strlcpy.o bsd-strsep.o
fake-getaddrinfo.o fake-getnameinfo.o next-posix.o
SSHOBJS= ssh.o sshconnect.o sshconnect1.o sshconnect2.o log-client.o readconf.o
clientloop.o
--- bsd-misc.c.orig-2.1.1p4 Sat Jul 15 00:59:14 2000
+++ bsd-misc.c Mon Jul 17 02:03:59 2000
@@ -45,90 +45,9 @@
#include "xmalloc.h"
#include "ssh.h"
#include "bsd-misc.h"
-#include "entropy.h"
#include <openssl/rand.h>
-#ifndef HAVE_ARC4RANDOM
-
-typedef struct
-{
- unsigned int s[256];
- int i;
- int j;
-} rc4_t;
-
-void rc4_key(rc4_t *r, unsigned char *key, int len);
-void rc4_getbytes(rc4_t *r, unsigned char *buffer, int len);
-
-static rc4_t *rc4 = NULL;
-
-void rc4_key(rc4_t *r, unsigned char *key, int len)
-{
- int t;
-
- for(r->i = 0; r->i < 256; r->i++)
- r->s[r->i] = r->i;
-
- r->j = 0;
- for(r->i = 0; r->i < 256; r->i++)
- {
- r->j = (r->j + r->s[r->i] + key[r->i % len]) % 256;
- t = r->s[r->i];
- r->s[r->i] = r->s[r->j];
- r->s[r->j] = t;
- }
- r->i = r->j = 0;
-}
-
-void rc4_getbytes(rc4_t *r, unsigned char *buffer, int len)
-{
- int t;
- int c;
-
- c = 0;
- while(c < len)
- {
- r->i = (r->i + 1) % 256;
- r->j = (r->j + r->s[r->i]) % 256;
- t = r->s[r->i];
- r->s[r->i] = r->s[r->j];
- r->s[r->j] = t;
-
- t = (r->s[r->i] + r->s[r->j]) % 256;
-
- buffer[c] = r->s[t];
- c++;
- }
-}
-
-unsigned int arc4random(void)
-{
- unsigned int r;
-
- if (rc4 == NULL)
- arc4random_stir();
-
- rc4_getbytes(rc4, (unsigned char *)&r, sizeof(r));
-
- return(r);
-}
-
-void arc4random_stir(void)
-{
- unsigned char rand_buf[32];
-
- if (rc4 == NULL)
- rc4 = xmalloc(sizeof(*rc4));
-
- seed_rng();
- RAND_bytes(rand_buf, sizeof(rand_buf));
-
- rc4_key(rc4, rand_buf, sizeof(rand_buf));
- memset(rand_buf, 0, sizeof(rand_buf));
-}
-#endif /* !HAVE_ARC4RANDOM */
-
#ifndef HAVE_SETPROCTITLE
void setproctitle(const char *fmt, ...)
{
@@ -159,8 +78,13 @@
#endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) */
#if !defined(HAVE_STRERROR) && defined(HAVE_SYS_ERRLIST)
-const char *strerror(void)
+const char *strerror(int e)
{
- return(sys_errlist[errno]);
+ extern int sys_nerr;
+ extern char *sys_errlist[];
+
+ return (e >= 0 && e < sys_nerr)
+ ? sys_errlist[e]
+ : "unlisted error" ;
}
#endif /* !defined(HAVE_STRERROR) && defined(HAVE_SYS_ERRLIST) */
--- bsd-misc.h.orig-2.1.1p4 Sat Jul 15 00:59:14 2000
+++ bsd-misc.h Mon Jul 17 02:04:17 2000
@@ -32,11 +32,6 @@
#include "config.h"
-#ifndef HAVE_ARC4RANDOM
-unsigned int arc4random(void);
-void arc4random_stir(void);
-#endif /* !HAVE_ARC4RANDOM */
-
#ifndef HAVE_SETPROCTITLE
void setproctitle(const char *fmt, ...);
#endif /* !HAVE_SETPROCTITLE */
@@ -59,7 +54,7 @@
#endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) */
#if !defined(HAVE_STRERROR) && defined(HAVE_SYS_ERRLIST)
-const char *strerror(void);
+const char *strerror(int e);
#endif /* !defined(HAVE_STRERROR) && defined(HAVE_SYS_ERRLIST) */
#endif /* _BSD_MISC_H */
--- bsd-rc4.c.orig-2.1.1p4 Mon Jul 17 03:03:30 2000
+++ bsd-rc4.c Mon Jul 17 01:52:31 2000
@@ -0,0 +1,118 @@
+/*
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Markus Friedl.
+ * 4. 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 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 "config.h"
+
+#include <string.h>
+
+#include "xmalloc.h"
+#include "bsd-rc4.h"
+#include "entropy.h"
+
+#include <openssl/rand.h>
+
+#ifndef HAVE_ARC4RANDOM
+
+typedef struct
+{
+ unsigned int s[256];
+ int i;
+ int j;
+} rc4_t;
+
+void rc4_key(rc4_t *r, unsigned char *key, int len);
+void rc4_getbytes(rc4_t *r, unsigned char *buffer, int len);
+
+static rc4_t *rc4 = NULL;
+
+void rc4_key(rc4_t *r, unsigned char *key, int len)
+{
+ int t;
+
+ for(r->i = 0; r->i < 256; r->i++)
+ r->s[r->i] = r->i;
+
+ r->j = 0;
+ for(r->i = 0; r->i < 256; r->i++)
+ {
+ r->j = (r->j + r->s[r->i] + key[r->i % len]) % 256;
+ t = r->s[r->i];
+ r->s[r->i] = r->s[r->j];
+ r->s[r->j] = t;
+ }
+ r->i = r->j = 0;
+}
+
+void rc4_getbytes(rc4_t *r, unsigned char *buffer, int len)
+{
+ int t;
+ int c;
+
+ c = 0;
+ while(c < len)
+ {
+ r->i = (r->i + 1) % 256;
+ r->j = (r->j + r->s[r->i]) % 256;
+ t = r->s[r->i];
+ r->s[r->i] = r->s[r->j];
+ r->s[r->j] = t;
+
+ t = (r->s[r->i] + r->s[r->j]) % 256;
+
+ buffer[c] = r->s[t];
+ c++;
+ }
+}
+
+unsigned int arc4random(void)
+{
+ unsigned int r;
+
+ if (rc4 == NULL)
+ arc4random_stir();
+
+ rc4_getbytes(rc4, (unsigned char *)&r, sizeof(r));
+
+ return(r);
+}
+
+void arc4random_stir(void)
+{
+ unsigned char rand_buf[32];
+
+ if (rc4 == NULL)
+ rc4 = xmalloc(sizeof(*rc4));
+
+ seed_rng();
+ RAND_bytes(rand_buf, sizeof(rand_buf));
+
+ rc4_key(rc4, rand_buf, sizeof(rand_buf));
+ memset(rand_buf, 0, sizeof(rand_buf));
+}
+#endif /* !HAVE_ARC4RANDOM */
--- bsd-rc4.h.orig-2.1.1p4 Mon Jul 17 03:03:35 2000
+++ bsd-rc4.h Mon Jul 17 01:55:18 2000
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Markus Friedl.
+ * 4. 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 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.
+ */
+
+#ifndef _BSD_RC4_H
+#define _BSD_RC4_H
+
+#include "config.h"
+
+#ifndef HAVE_ARC4RANDOM
+unsigned int arc4random(void);
+void arc4random_stir(void);
+#endif /* !HAVE_ARC4RANDOM */
+
+#endif /* _BSD_RC4_H */
=======================================================================bsd-misc.c:
In function `strerror':
bsd-misc.c:164: `sys_errlist' undeclared (first use this function)
bsd-misc.c:164: (Each undeclared identifier is reported only once
bsd-misc.c:164: for each function it appears in.)
bsd-misc.c:165: warning: control reaches end of non-void function
=======================================================================authfd.c:
In function `ssh_get_first_identity':
authfd.c:147: too many arguments to function `strerror'
authfd.c:155: too many arguments to function `strerror'
=======================================================================gcc -o
scp scp.o -L. -lssh -lopenbsd-compat -lnsl -lz -lcrypto -lwrap
collect2: ld returned 2 exit status
ld: Undefined symbol
_seed_rng
========================================================================