]> andersk Git - openssh.git/blobdiff - ssh-keyscan.c
NOTE: This update changes the RSA key generation. *NEW RSA KEYS
[openssh.git] / ssh-keyscan.c
index 26ea59eca6bfc10b8c533a4ca20df8307c63bd01..69b029b05a7549989118597c04e376e2c2627393 100644 (file)
@@ -8,14 +8,13 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: ssh-keyscan.c,v 1.1 2000/12/04 19:24:02 markus Exp $");
+RCSID("$OpenBSD: ssh-keyscan.c,v 1.9 2001/01/13 18:12:47 markus Exp $");
 
-#ifdef HAVE_SYS_QUEUE_H
+#if defined(HAVE_SYS_QUEUE_H)  &&  !defined(HAVE_BOGUS_SYS_QUEUE_H)
 #include <sys/queue.h>
 #else
 #include "bsd-queue.h"
 #endif
-#include <err.h>
 #include <errno.h>
 
 #include <openssl/bn.h>
@@ -32,7 +31,6 @@ static int argno = 1;         /* Number of argument currently being parsed */
 
 int family = AF_UNSPEC;                /* IPv4, IPv6 or both */
 
-#define PORT 22
 #define MAXMAXFD 256
 
 /* The number of seconds after which to give up on a TCP connection */
@@ -41,7 +39,11 @@ int timeout = 5;
 int maxfd;
 #define maxcon (maxfd - 10)
 
-char *prog;
+#ifdef HAVE___PROGNAME
+extern char *__progname;
+#else
+char *__progname;
+#endif
 fd_set read_wait;
 int ncon;
 
@@ -50,7 +52,7 @@ int ncon;
  * associated with file descriptor n is held in fdcon[n].
  */
 typedef struct Connection {
-       unsigned char c_status; /* State of connection on this file desc. */
+       u_char c_status;        /* State of connection on this file desc. */
 #define CS_UNUSED 0            /* File descriptor unused */
 #define CS_CON 1               /* Waiting to connect/read greeting */
 #define CS_SIZE 2              /* Waiting to read initial packet size */
@@ -80,7 +82,7 @@ con *fdcon;
 
 typedef struct {
        char *buf;
-       unsigned int size;
+       u_int size;
        int lineno;
        const char *filename;
        FILE *stream;
@@ -100,7 +102,7 @@ Linebuf_alloc(const char *filename, void (*errfun) (const char *,...))
        if (filename) {
                lb->filename = filename;
                if (!(lb->stream = fopen(filename, "r"))) {
-                       free(lb);
+                       xfree(lb);
                        if (errfun)
                                (*errfun) ("%s: %s\n", filename, strerror(errno));
                        return (NULL);
@@ -113,7 +115,7 @@ Linebuf_alloc(const char *filename, void (*errfun) (const char *,...))
        if (!(lb->buf = malloc(lb->size = LINEBUF_SIZE))) {
                if (errfun)
                        (*errfun) ("linebuf (%s): malloc failed\n", lb->filename);
-               free(lb);
+               xfree(lb);
                return (NULL);
        }
        lb->errfun = errfun;
@@ -125,8 +127,8 @@ static inline void
 Linebuf_free(Linebuf * lb)
 {
        fclose(lb->stream);
-       free(lb->buf);
-       free(lb);
+       xfree(lb->buf);
+       xfree(lb);
 }
 
 static inline void
@@ -180,6 +182,7 @@ getline(Linebuf * lb)
 static int
 fdlim_get(int hard)
 {
+#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)
        struct rlimit rlfd;
        if (getrlimit(RLIMIT_NOFILE, &rlfd) < 0)
                return (-1);
@@ -187,19 +190,30 @@ fdlim_get(int hard)
                return 10000;
        else
                return hard ? rlfd.rlim_max : rlfd.rlim_cur;
+#elif defined (HAVE_SYSCONF)
+       return sysconf (_SC_OPEN_MAX);
+#else
+       return 10000;
+#endif
 }
 
 static int
 fdlim_set(int lim)
 {
+#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE)
        struct rlimit rlfd;
+#endif
        if (lim <= 0)
                return (-1);
+#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE)
        if (getrlimit(RLIMIT_NOFILE, &rlfd) < 0)
                return (-1);
        rlfd.rlim_cur = lim;
        if (setrlimit(RLIMIT_NOFILE, &rlfd) < 0)
                return (-1);
+#elif defined (HAVE_SETDTABLESIZE)
+       setdtablesize (lim);
+#endif
        return (0);
 }
 
@@ -283,7 +297,7 @@ tcpconnect(char *host)
        char strport[NI_MAXSERV];
        int gaierr, s = -1;
 
-       snprintf(strport, sizeof strport, "%d", PORT);
+       snprintf(strport, sizeof strport, "%d", SSH_DEFAULT_PORT);
        memset(&hints, 0, sizeof(hints));
        hints.ai_family = family;
        hints.ai_socktype = SOCK_STREAM;
@@ -295,7 +309,7 @@ tcpconnect(char *host)
                        error("socket: %s", strerror(errno));
                        continue;
                }
-               if (fcntl(s, F_SETFL, O_NDELAY) < 0)
+               if (fcntl(s, F_SETFL, O_NONBLOCK) < 0)
                        fatal("F_SETFL: %s", strerror(errno));
                if (connect(s, ai->ai_addr, ai->ai_addrlen) < 0 &&
                    errno != EINPROGRESS)
@@ -320,15 +334,15 @@ conalloc(char *iname, char *oname)
        do {
                name = xstrsep(&namelist, ",");
                if (!name) {
-                       free(namebase);
+                       xfree(namebase);
                        return (-1);
                }
        } while ((s = tcpconnect(name)) < 0);
 
        if (s >= maxfd)
-               fatal("conalloc: fdno %d too high\n", s);
+               fatal("conalloc: fdno %d too high", s);
        if (fdcon[s].c_status)
-               fatal("conalloc: attempt to reuse fdno %d\n", s);
+               fatal("conalloc: attempt to reuse fdno %d", s);
 
        fdcon[s].c_fd = s;
        fdcon[s].c_status = CS_CON;
@@ -352,11 +366,11 @@ confree(int s)
 {
        close(s);
        if (s >= maxfd || fdcon[s].c_status == CS_UNUSED)
-               fatal("confree: attempt to free bad fdno %d\n", s);
-       free(fdcon[s].c_namebase);
-       free(fdcon[s].c_output_name);
+               fatal("confree: attempt to free bad fdno %d", s);
+       xfree(fdcon[s].c_namebase);
+       xfree(fdcon[s].c_output_name);
        if (fdcon[s].c_status == CS_KEYS)
-               free(fdcon[s].c_data);
+               xfree(fdcon[s].c_data);
        fdcon[s].c_status = CS_UNUSED;
        TAILQ_REMOVE(&tq, &fdcon[s], c_link);
        FD_CLR(s, &read_wait);
@@ -380,11 +394,11 @@ conrecycle(int s)
        char *iname, *oname;
 
        iname = xstrdup(c->c_namelist);
-       oname = c->c_output_name;
-       c->c_output_name = NULL;/* prevent it from being freed */
+       oname = xstrdup(c->c_output_name);
        confree(s);
        ret = conalloc(iname, oname);
-       free(iname);
+       xfree(iname);
+       xfree(oname);
        return (ret);
 }
 
@@ -452,7 +466,7 @@ conread(int s)
                        return;
                        break;
                default:
-                       fatal("conread: invalid status %d\n", c->c_status);
+                       fatal("conread: invalid status %d", c->c_status);
                        break;
                }
 
@@ -528,7 +542,7 @@ nexthost(int argc, char **argv)
                                        fname = argv[argno++];
                                if (!strcmp(fname, "-"))
                                        fname = NULL;
-                               lb = Linebuf_alloc(fname, warn);
+                               lb = Linebuf_alloc(fname, error);
                        } else
                                error("ignoring invalid/misplaced option `%s'", argv[argno++]);
                } else {
@@ -545,7 +559,7 @@ nexthost(int argc, char **argv)
 static void
 usage(void)
 {
-       fatal("usage: %s [-t timeout] { [--] host | -f file } ...\n", prog);
+       fatal("usage: %s [-t timeout] { [--] host | -f file } ...", __progname);
        return;
 }
 
@@ -554,13 +568,9 @@ main(int argc, char **argv)
 {
        char *host = NULL;
 
+       __progname = get_progname(argv[0]);
        TAILQ_INIT(&tq);
 
-       if ((prog = strrchr(argv[0], '/')))
-               prog++;
-       else
-               prog = argv[0];
-
        if (argc <= argno)
                usage();
 
@@ -581,11 +591,11 @@ main(int argc, char **argv)
 
        maxfd = fdlim_get(1);
        if (maxfd < 0)
-               fatal("%s: fdlim_get: bad value\n", prog);
+               fatal("%s: fdlim_get: bad value", __progname);
        if (maxfd > MAXMAXFD)
                maxfd = MAXMAXFD;
        if (maxcon <= 0)
-               fatal("%s: not enough file descriptors\n", prog);
+               fatal("%s: not enough file descriptors", __progname);
        if (maxfd > fdlim_get(0))
                fdlim_set(maxfd);
        fdcon = xmalloc(maxfd * sizeof(con));
This page took 0.342762 seconds and 4 git commands to generate.