blob: 70154084111fe4159ed35ed60c2e1c33cfdfb997 [file] [log] [blame]
Damien Millera7a73ee2006-08-05 11:37:59 +10001/* $OpenBSD: ssh-keyscan.c,v 1.72 2006/08/01 23:22:47 stevesk Exp $ */
Ben Lindstromb6434ae2000-12-05 01:15:09 +00002/*
3 * Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>.
4 *
5 * Modification and redistribution in source and binary forms is
6 * permitted provided that due credit is given to the author and the
Ben Lindstroma238f6e2001-06-09 01:30:39 +00007 * OpenBSD project by leaving this copyright notice intact.
Ben Lindstromb6434ae2000-12-05 01:15:09 +00008 */
9
10#include "includes.h"
Damien Millercd4223c2006-03-15 11:22:47 +110011
Damien Miller9b481512002-09-12 10:43:29 +100012#include "openbsd-compat/sys-queue.h"
Damien Millercd4223c2006-03-15 11:22:47 +110013#include <sys/resource.h>
Damien Miller9aec9192006-08-05 10:57:45 +100014#ifdef HAVE_SYS_TIME_H
15# include <sys/time.h>
16#endif
Damien Millere3476ed2006-07-24 14:13:33 +100017
18#include <openssl/bn.h>
19
Damien Millerb8fe89c2006-07-24 14:51:00 +100020#include <netdb.h>
Darren Tuckerdeecec92006-07-12 22:44:34 +100021#include <errno.h>
Damien Millerbe43ebf2006-07-24 13:51:51 +100022#include <setjmp.h>
Damien Millere7a1e5c2006-08-05 11:34:19 +100023#include <stdarg.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100024#include <stdio.h>
Damien Millere7a1e5c2006-08-05 11:34:19 +100025#include <stdlib.h>
Damien Millere3476ed2006-07-24 14:13:33 +100026#include <string.h>
Damien Millere6b3b612006-07-24 14:01:23 +100027#include <unistd.h>
Ben Lindstromb6434ae2000-12-05 01:15:09 +000028
Ben Lindstromb6434ae2000-12-05 01:15:09 +000029#include "xmalloc.h"
30#include "ssh.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000031#include "ssh1.h"
Ben Lindstromb6434ae2000-12-05 01:15:09 +000032#include "key.h"
Ben Lindstrom325e70c2001-08-06 22:41:30 +000033#include "kex.h"
34#include "compat.h"
35#include "myproposal.h"
36#include "packet.h"
37#include "dispatch.h"
Ben Lindstromb6434ae2000-12-05 01:15:09 +000038#include "buffer.h"
39#include "bufaux.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000040#include "log.h"
Ben Lindstromd20b8552001-03-05 07:01:18 +000041#include "atomicio.h"
Ben Lindstrom325e70c2001-08-06 22:41:30 +000042#include "misc.h"
Damien Millerdb7b8172005-03-01 21:48:03 +110043#include "hostfile.h"
Ben Lindstromb6434ae2000-12-05 01:15:09 +000044
Ben Lindstrom325e70c2001-08-06 22:41:30 +000045/* Flag indicating whether IPv4 or IPv6. This can be set on the command line.
46 Default value is AF_UNSPEC means both IPv4 and IPv6. */
Ben Lindstrom325e70c2001-08-06 22:41:30 +000047int IPv4or6 = AF_UNSPEC;
Ben Lindstromb6434ae2000-12-05 01:15:09 +000048
Ben Lindstrom325e70c2001-08-06 22:41:30 +000049int ssh_port = SSH_DEFAULT_PORT;
Kevin Steves76e7d9b2001-09-20 20:30:09 +000050
51#define KT_RSA1 1
52#define KT_DSA 2
53#define KT_RSA 4
54
55int get_keytypes = KT_RSA1; /* Get only RSA1 keys by default */
Ben Lindstromb6434ae2000-12-05 01:15:09 +000056
Damien Millerdb7b8172005-03-01 21:48:03 +110057int hash_hosts = 0; /* Hash hostname on output */
58
Ben Lindstromb6434ae2000-12-05 01:15:09 +000059#define MAXMAXFD 256
60
61/* The number of seconds after which to give up on a TCP connection */
62int timeout = 5;
63
64int maxfd;
Ben Lindstromd20b8552001-03-05 07:01:18 +000065#define MAXCON (maxfd - 10)
Ben Lindstromb6434ae2000-12-05 01:15:09 +000066
Kevin Stevesec84dc12000-12-13 17:45:15 +000067extern char *__progname;
Ben Lindstromc1e04212001-03-05 07:04:38 +000068fd_set *read_wait;
Damien Miller07d86be2006-03-26 14:19:21 +110069size_t read_wait_nfdset;
Ben Lindstromb6434ae2000-12-05 01:15:09 +000070int ncon;
Ben Lindstrom325e70c2001-08-06 22:41:30 +000071int nonfatal_fatal = 0;
72jmp_buf kexjmp;
Ben Lindstrom520b55c2001-09-12 18:05:05 +000073Key *kexjmp_key;
Ben Lindstromb6434ae2000-12-05 01:15:09 +000074
75/*
76 * Keep a connection structure for each file descriptor. The state
77 * associated with file descriptor n is held in fdcon[n].
78 */
79typedef struct Connection {
Ben Lindstrom46c16222000-12-22 01:43:59 +000080 u_char c_status; /* State of connection on this file desc. */
Ben Lindstromb6434ae2000-12-05 01:15:09 +000081#define CS_UNUSED 0 /* File descriptor unused */
82#define CS_CON 1 /* Waiting to connect/read greeting */
83#define CS_SIZE 2 /* Waiting to read initial packet size */
84#define CS_KEYS 3 /* Waiting to read public key packet */
85 int c_fd; /* Quick lookup: c->c_fd == c - fdcon */
86 int c_plen; /* Packet length field for ssh packet */
87 int c_len; /* Total bytes which must be read. */
88 int c_off; /* Length of data read so far. */
Ben Lindstrom325e70c2001-08-06 22:41:30 +000089 int c_keytype; /* Only one of KT_RSA1, KT_DSA, or KT_RSA */
Ben Lindstromb6434ae2000-12-05 01:15:09 +000090 char *c_namebase; /* Address to free for c_name and c_namelist */
91 char *c_name; /* Hostname of connection for errors */
92 char *c_namelist; /* Pointer to other possible addresses */
93 char *c_output_name; /* Hostname of connection for output */
94 char *c_data; /* Data read from this fd */
Ben Lindstrom325e70c2001-08-06 22:41:30 +000095 Kex *c_kex; /* The key-exchange struct for ssh2 */
Ben Lindstromb6434ae2000-12-05 01:15:09 +000096 struct timeval c_tv; /* Time at which connection gets aborted */
97 TAILQ_ENTRY(Connection) c_link; /* List of connections in timeout order. */
98} con;
99
100TAILQ_HEAD(conlist, Connection) tq; /* Timeout Queue */
101con *fdcon;
102
103/*
104 * This is just a wrapper around fgets() to make it usable.
105 */
106
107/* Stress-test. Increase this later. */
108#define LINEBUF_SIZE 16
109
110typedef struct {
111 char *buf;
Ben Lindstrom46c16222000-12-22 01:43:59 +0000112 u_int size;
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000113 int lineno;
114 const char *filename;
115 FILE *stream;
116 void (*errfun) (const char *,...);
117} Linebuf;
118
Ben Lindstrombba81212001-06-25 05:01:22 +0000119static Linebuf *
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000120Linebuf_alloc(const char *filename, void (*errfun) (const char *,...))
121{
122 Linebuf *lb;
123
124 if (!(lb = malloc(sizeof(*lb)))) {
125 if (errfun)
Ben Lindstrom04f9af72002-07-04 00:03:56 +0000126 (*errfun) ("linebuf (%s): malloc failed\n",
127 filename ? filename : "(stdin)");
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000128 return (NULL);
129 }
130 if (filename) {
131 lb->filename = filename;
132 if (!(lb->stream = fopen(filename, "r"))) {
Ben Lindstrombf555ba2001-01-18 02:04:35 +0000133 xfree(lb);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000134 if (errfun)
135 (*errfun) ("%s: %s\n", filename, strerror(errno));
136 return (NULL);
137 }
138 } else {
139 lb->filename = "(stdin)";
140 lb->stream = stdin;
141 }
142
Damien Miller3bbaba62006-03-26 13:59:38 +1100143 if (!(lb->buf = malloc((lb->size = LINEBUF_SIZE)))) {
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000144 if (errfun)
145 (*errfun) ("linebuf (%s): malloc failed\n", lb->filename);
Ben Lindstrombf555ba2001-01-18 02:04:35 +0000146 xfree(lb);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000147 return (NULL);
148 }
149 lb->errfun = errfun;
150 lb->lineno = 0;
151 return (lb);
152}
153
Ben Lindstrombba81212001-06-25 05:01:22 +0000154static void
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000155Linebuf_free(Linebuf * lb)
156{
157 fclose(lb->stream);
Ben Lindstrombf555ba2001-01-18 02:04:35 +0000158 xfree(lb->buf);
159 xfree(lb);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000160}
161
Ben Lindstrombba81212001-06-25 05:01:22 +0000162#if 0
163static void
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000164Linebuf_restart(Linebuf * lb)
165{
166 clearerr(lb->stream);
167 rewind(lb->stream);
168 lb->lineno = 0;
169}
170
Ben Lindstrombba81212001-06-25 05:01:22 +0000171static int
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000172Linebuf_lineno(Linebuf * lb)
173{
174 return (lb->lineno);
175}
Ben Lindstrombba81212001-06-25 05:01:22 +0000176#endif
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000177
Ben Lindstrombba81212001-06-25 05:01:22 +0000178static char *
Ben Lindstromc791beb2001-02-10 23:18:11 +0000179Linebuf_getline(Linebuf * lb)
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000180{
Damien Millereccb9de2005-06-17 12:59:34 +1000181 size_t n = 0;
Ben Lindstrom965710f2002-07-07 22:17:22 +0000182 void *p;
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000183
184 lb->lineno++;
185 for (;;) {
186 /* Read a line */
187 if (!fgets(&lb->buf[n], lb->size - n, lb->stream)) {
188 if (ferror(lb->stream) && lb->errfun)
Ben Lindstrom965710f2002-07-07 22:17:22 +0000189 (*lb->errfun)("%s: %s\n", lb->filename,
Ben Lindstromb0a4cd82001-03-05 04:54:49 +0000190 strerror(errno));
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000191 return (NULL);
192 }
193 n = strlen(lb->buf);
194
195 /* Return it or an error if it fits */
196 if (n > 0 && lb->buf[n - 1] == '\n') {
197 lb->buf[n - 1] = '\0';
198 return (lb->buf);
199 }
200 if (n != lb->size - 1) {
201 if (lb->errfun)
Ben Lindstrom965710f2002-07-07 22:17:22 +0000202 (*lb->errfun)("%s: skipping incomplete last line\n",
Ben Lindstromb0a4cd82001-03-05 04:54:49 +0000203 lb->filename);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000204 return (NULL);
205 }
206 /* Double the buffer if we need more space */
Ben Lindstrom965710f2002-07-07 22:17:22 +0000207 lb->size *= 2;
208 if ((p = realloc(lb->buf, lb->size)) == NULL) {
209 lb->size /= 2;
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000210 if (lb->errfun)
Ben Lindstrom965710f2002-07-07 22:17:22 +0000211 (*lb->errfun)("linebuf (%s): realloc failed\n",
Ben Lindstromb0a4cd82001-03-05 04:54:49 +0000212 lb->filename);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000213 return (NULL);
214 }
Ben Lindstrom965710f2002-07-07 22:17:22 +0000215 lb->buf = p;
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000216 }
217}
218
Ben Lindstrombba81212001-06-25 05:01:22 +0000219static int
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000220fdlim_get(int hard)
221{
Ben Lindstrom5adbad22000-12-27 07:06:21 +0000222#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000223 struct rlimit rlfd;
Ben Lindstromb0a4cd82001-03-05 04:54:49 +0000224
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000225 if (getrlimit(RLIMIT_NOFILE, &rlfd) < 0)
226 return (-1);
227 if ((hard ? rlfd.rlim_max : rlfd.rlim_cur) == RLIM_INFINITY)
Damien Millere00074a2003-11-24 13:07:45 +1100228 return SSH_SYSFDMAX;
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000229 else
230 return hard ? rlfd.rlim_max : rlfd.rlim_cur;
Ben Lindstrom2c467a22000-12-27 04:57:41 +0000231#else
Damien Millere00074a2003-11-24 13:07:45 +1100232 return SSH_SYSFDMAX;
Ben Lindstrom2c467a22000-12-27 04:57:41 +0000233#endif
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000234}
235
Ben Lindstrombba81212001-06-25 05:01:22 +0000236static int
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000237fdlim_set(int lim)
238{
Ben Lindstrom5adbad22000-12-27 07:06:21 +0000239#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE)
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000240 struct rlimit rlfd;
Ben Lindstrom2c467a22000-12-27 04:57:41 +0000241#endif
Ben Lindstrom5c98db52002-07-07 22:25:29 +0000242
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000243 if (lim <= 0)
244 return (-1);
Ben Lindstrom5adbad22000-12-27 07:06:21 +0000245#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE)
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000246 if (getrlimit(RLIMIT_NOFILE, &rlfd) < 0)
247 return (-1);
248 rlfd.rlim_cur = lim;
249 if (setrlimit(RLIMIT_NOFILE, &rlfd) < 0)
250 return (-1);
Ben Lindstrom2c467a22000-12-27 04:57:41 +0000251#elif defined (HAVE_SETDTABLESIZE)
Kevin Steves28a7f262001-02-05 15:43:59 +0000252 setdtablesize(lim);
Ben Lindstrom2c467a22000-12-27 04:57:41 +0000253#endif
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000254 return (0);
255}
256
257/*
258 * This is an strsep function that returns a null field for adjacent
259 * separators. This is the same as the 4.4BSD strsep, but different from the
260 * one in the GNU libc.
261 */
Ben Lindstrombba81212001-06-25 05:01:22 +0000262static char *
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000263xstrsep(char **str, const char *delim)
264{
265 char *s, *e;
266
267 if (!**str)
268 return (NULL);
269
270 s = *str;
271 e = s + strcspn(s, delim);
272
273 if (*e != '\0')
274 *e++ = '\0';
275 *str = e;
276
277 return (s);
278}
279
280/*
281 * Get the next non-null token (like GNU strsep). Strsep() will return a
282 * null token for two adjacent separators, so we may have to loop.
283 */
Ben Lindstrombba81212001-06-25 05:01:22 +0000284static char *
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000285strnnsep(char **stringp, char *delim)
286{
287 char *tok;
288
289 do {
290 tok = xstrsep(stringp, delim);
291 } while (tok && *tok == '\0');
292 return (tok);
293}
294
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000295static Key *
296keygrab_ssh1(con *c)
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000297{
298 static Key *rsa;
299 static Buffer msg;
300
301 if (rsa == NULL) {
302 buffer_init(&msg);
303 rsa = key_new(KEY_RSA1);
304 }
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000305 buffer_append(&msg, c->c_data, c->c_plen);
306 buffer_consume(&msg, 8 - (c->c_plen & 7)); /* padding */
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000307 if (buffer_get_char(&msg) != (int) SSH_SMSG_PUBLIC_KEY) {
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000308 error("%s: invalid packet type", c->c_name);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000309 buffer_clear(&msg);
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000310 return NULL;
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000311 }
312 buffer_consume(&msg, 8); /* cookie */
313
314 /* server key */
315 (void) buffer_get_int(&msg);
316 buffer_get_bignum(&msg, rsa->rsa->e);
317 buffer_get_bignum(&msg, rsa->rsa->n);
318
319 /* host key */
320 (void) buffer_get_int(&msg);
321 buffer_get_bignum(&msg, rsa->rsa->e);
322 buffer_get_bignum(&msg, rsa->rsa->n);
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000323
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000324 buffer_clear(&msg);
325
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000326 return (rsa);
327}
328
329static int
330hostjump(Key *hostkey)
331{
Ben Lindstrom520b55c2001-09-12 18:05:05 +0000332 kexjmp_key = hostkey;
333 longjmp(kexjmp, 1);
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000334}
335
336static int
337ssh2_capable(int remote_major, int remote_minor)
338{
339 switch (remote_major) {
340 case 1:
341 if (remote_minor == 99)
342 return 1;
343 break;
344 case 2:
345 return 1;
346 default:
347 break;
348 }
349 return 0;
350}
351
352static Key *
353keygrab_ssh2(con *c)
354{
355 int j;
356
357 packet_set_connection(c->c_fd, c->c_fd);
358 enable_compat20();
359 myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = c->c_keytype == KT_DSA?
360 "ssh-dss": "ssh-rsa";
361 c->c_kex = kex_setup(myproposal);
Damien Miller8e7fb332003-02-24 12:03:03 +1100362 c->c_kex->kex[KEX_DH_GRP1_SHA1] = kexdh_client;
Damien Millerf675fc42004-06-15 10:30:09 +1000363 c->c_kex->kex[KEX_DH_GRP14_SHA1] = kexdh_client;
Damien Miller8e7fb332003-02-24 12:03:03 +1100364 c->c_kex->kex[KEX_DH_GEX_SHA1] = kexgex_client;
Damien Millera63128d2006-03-15 12:08:28 +1100365 c->c_kex->kex[KEX_DH_GEX_SHA256] = kexgex_client;
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000366 c->c_kex->verify_host_key = hostjump;
367
368 if (!(j = setjmp(kexjmp))) {
369 nonfatal_fatal = 1;
370 dispatch_run(DISPATCH_BLOCK, &c->c_kex->done, c->c_kex);
371 fprintf(stderr, "Impossible! dispatch_run() returned!\n");
372 exit(1);
373 }
374 nonfatal_fatal = 0;
375 xfree(c->c_kex);
376 c->c_kex = NULL;
377 packet_close();
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000378
Ben Lindstrom520b55c2001-09-12 18:05:05 +0000379 return j < 0? NULL : kexjmp_key;
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000380}
381
382static void
383keyprint(con *c, Key *key)
384{
Damien Millerdb7b8172005-03-01 21:48:03 +1100385 char *host = c->c_output_name ? c->c_output_name : c->c_name;
386
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000387 if (!key)
388 return;
Damien Millerdb7b8172005-03-01 21:48:03 +1100389 if (hash_hosts && (host = host_hash(host, NULL, 0)) == NULL)
390 fatal("host_hash failed");
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000391
Damien Millerdb7b8172005-03-01 21:48:03 +1100392 fprintf(stdout, "%s ", host);
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000393 key_write(key, stdout);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000394 fputs("\n", stdout);
395}
396
Ben Lindstrombba81212001-06-25 05:01:22 +0000397static int
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000398tcpconnect(char *host)
399{
400 struct addrinfo hints, *ai, *aitop;
401 char strport[NI_MAXSERV];
402 int gaierr, s = -1;
403
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000404 snprintf(strport, sizeof strport, "%d", ssh_port);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000405 memset(&hints, 0, sizeof(hints));
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000406 hints.ai_family = IPv4or6;
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000407 hints.ai_socktype = SOCK_STREAM;
408 if ((gaierr = getaddrinfo(host, strport, &hints, &aitop)) != 0)
409 fatal("getaddrinfo %s: %s", host, gai_strerror(gaierr));
410 for (ai = aitop; ai; ai = ai->ai_next) {
Damien Miller2372ace2003-05-14 13:42:23 +1000411 s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000412 if (s < 0) {
413 error("socket: %s", strerror(errno));
414 continue;
415 }
Damien Miller232711f2004-06-15 10:35:30 +1000416 if (set_nonblock(s) == -1)
417 fatal("%s: set_nonblock(%d)", __func__, s);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000418 if (connect(s, ai->ai_addr, ai->ai_addrlen) < 0 &&
419 errno != EINPROGRESS)
420 error("connect (`%s'): %s", host, strerror(errno));
421 else
422 break;
423 close(s);
424 s = -1;
425 }
426 freeaddrinfo(aitop);
427 return s;
428}
429
Ben Lindstrombba81212001-06-25 05:01:22 +0000430static int
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000431conalloc(char *iname, char *oname, int keytype)
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000432{
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000433 char *namebase, *name, *namelist;
Ben Lindstrom965710f2002-07-07 22:17:22 +0000434 int s;
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000435
436 namebase = namelist = xstrdup(iname);
437
438 do {
439 name = xstrsep(&namelist, ",");
440 if (!name) {
Ben Lindstrombf555ba2001-01-18 02:04:35 +0000441 xfree(namebase);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000442 return (-1);
443 }
444 } while ((s = tcpconnect(name)) < 0);
445
446 if (s >= maxfd)
Kevin Stevesfa72dda2000-12-15 18:39:12 +0000447 fatal("conalloc: fdno %d too high", s);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000448 if (fdcon[s].c_status)
Kevin Stevesfa72dda2000-12-15 18:39:12 +0000449 fatal("conalloc: attempt to reuse fdno %d", s);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000450
451 fdcon[s].c_fd = s;
452 fdcon[s].c_status = CS_CON;
453 fdcon[s].c_namebase = namebase;
454 fdcon[s].c_name = name;
455 fdcon[s].c_namelist = namelist;
456 fdcon[s].c_output_name = xstrdup(oname);
457 fdcon[s].c_data = (char *) &fdcon[s].c_plen;
458 fdcon[s].c_len = 4;
459 fdcon[s].c_off = 0;
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000460 fdcon[s].c_keytype = keytype;
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000461 gettimeofday(&fdcon[s].c_tv, NULL);
462 fdcon[s].c_tv.tv_sec += timeout;
463 TAILQ_INSERT_TAIL(&tq, &fdcon[s], c_link);
Ben Lindstromc1e04212001-03-05 07:04:38 +0000464 FD_SET(s, read_wait);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000465 ncon++;
466 return (s);
467}
468
Ben Lindstrombba81212001-06-25 05:01:22 +0000469static void
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000470confree(int s)
471{
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000472 if (s >= maxfd || fdcon[s].c_status == CS_UNUSED)
Kevin Stevesfa72dda2000-12-15 18:39:12 +0000473 fatal("confree: attempt to free bad fdno %d", s);
Ben Lindstromd20b8552001-03-05 07:01:18 +0000474 close(s);
Ben Lindstrombf555ba2001-01-18 02:04:35 +0000475 xfree(fdcon[s].c_namebase);
476 xfree(fdcon[s].c_output_name);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000477 if (fdcon[s].c_status == CS_KEYS)
Ben Lindstrombf555ba2001-01-18 02:04:35 +0000478 xfree(fdcon[s].c_data);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000479 fdcon[s].c_status = CS_UNUSED;
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000480 fdcon[s].c_keytype = 0;
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000481 TAILQ_REMOVE(&tq, &fdcon[s], c_link);
Ben Lindstromc1e04212001-03-05 07:04:38 +0000482 FD_CLR(s, read_wait);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000483 ncon--;
484}
485
Ben Lindstrombba81212001-06-25 05:01:22 +0000486static void
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000487contouch(int s)
488{
489 TAILQ_REMOVE(&tq, &fdcon[s], c_link);
490 gettimeofday(&fdcon[s].c_tv, NULL);
491 fdcon[s].c_tv.tv_sec += timeout;
492 TAILQ_INSERT_TAIL(&tq, &fdcon[s], c_link);
493}
494
Ben Lindstrombba81212001-06-25 05:01:22 +0000495static int
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000496conrecycle(int s)
497{
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000498 con *c = &fdcon[s];
Ben Lindstrom965710f2002-07-07 22:17:22 +0000499 int ret;
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000500
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000501 ret = conalloc(c->c_namelist, c->c_output_name, c->c_keytype);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000502 confree(s);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000503 return (ret);
504}
505
Ben Lindstrombba81212001-06-25 05:01:22 +0000506static void
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000507congreet(int s)
508{
Damien Millereccb9de2005-06-17 12:59:34 +1000509 int n = 0, remote_major = 0, remote_minor = 0;
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000510 char buf[256], *cp;
Damien Miller83c02ef2001-12-21 12:45:43 +1100511 char remote_version[sizeof buf];
Damien Millereccb9de2005-06-17 12:59:34 +1000512 size_t bufsiz;
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000513 con *c = &fdcon[s];
514
Damien Miller4bbacb72005-11-05 15:12:28 +1100515 for (;;) {
516 memset(buf, '\0', sizeof(buf));
517 bufsiz = sizeof(buf);
518 cp = buf;
519 while (bufsiz-- &&
520 (n = atomicio(read, s, cp, 1)) == 1 && *cp != '\n') {
521 if (*cp == '\r')
522 *cp = '\n';
523 cp++;
524 }
525 if (n != 1 || strncmp(buf, "SSH-", 4) == 0)
526 break;
Ben Lindstromde8fc6f2001-08-06 22:43:50 +0000527 }
Ben Lindstrom6b28c352002-03-05 01:54:52 +0000528 if (n == 0) {
Damien Millerb253cc42005-05-26 12:23:44 +1000529 switch (errno) {
530 case EPIPE:
531 error("%s: Connection closed by remote host", c->c_name);
532 break;
533 case ECONNREFUSED:
534 break;
535 default:
536 error("read (%s): %s", c->c_name, strerror(errno));
537 break;
538 }
Ben Lindstrom6b28c352002-03-05 01:54:52 +0000539 conrecycle(s);
540 return;
541 }
Ben Lindstrom884a4ac2001-03-06 03:33:04 +0000542 if (*cp != '\n' && *cp != '\r') {
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000543 error("%s: bad greeting", c->c_name);
544 confree(s);
545 return;
546 }
Ben Lindstrom884a4ac2001-03-06 03:33:04 +0000547 *cp = '\0';
Damien Miller83c02ef2001-12-21 12:45:43 +1100548 if (sscanf(buf, "SSH-%d.%d-%[^\n]\n",
549 &remote_major, &remote_minor, remote_version) == 3)
550 compat_datafellows(remote_version);
551 else
552 datafellows = 0;
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000553 if (c->c_keytype != KT_RSA1) {
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000554 if (!ssh2_capable(remote_major, remote_minor)) {
555 debug("%s doesn't support ssh2", c->c_name);
556 confree(s);
557 return;
558 }
Damien Miller83c02ef2001-12-21 12:45:43 +1100559 } else if (remote_major != 1) {
560 debug("%s doesn't support ssh1", c->c_name);
561 confree(s);
562 return;
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000563 }
Ben Lindstromde8fc6f2001-08-06 22:43:50 +0000564 fprintf(stderr, "# %s %s\n", c->c_name, chop(buf));
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000565 n = snprintf(buf, sizeof buf, "SSH-%d.%d-OpenSSH-keyscan\r\n",
566 c->c_keytype == KT_RSA1? PROTOCOL_MAJOR_1 : PROTOCOL_MAJOR_2,
567 c->c_keytype == KT_RSA1? PROTOCOL_MINOR_1 : PROTOCOL_MINOR_2);
Damien Millereccb9de2005-06-17 12:59:34 +1000568 if (n < 0 || (size_t)n >= sizeof(buf)) {
Damien Miller41bfc292005-05-26 12:07:32 +1000569 error("snprintf: buffer too small");
570 confree(s);
571 return;
572 }
Damien Millereccb9de2005-06-17 12:59:34 +1000573 if (atomicio(vwrite, s, buf, n) != (size_t)n) {
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000574 error("write (%s): %s", c->c_name, strerror(errno));
575 confree(s);
576 return;
577 }
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000578 if (c->c_keytype != KT_RSA1) {
579 keyprint(c, keygrab_ssh2(c));
580 confree(s);
581 return;
582 }
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000583 c->c_status = CS_SIZE;
584 contouch(s);
585}
586
Ben Lindstrombba81212001-06-25 05:01:22 +0000587static void
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000588conread(int s)
589{
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000590 con *c = &fdcon[s];
Damien Millerb253cc42005-05-26 12:23:44 +1000591 size_t n;
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000592
593 if (c->c_status == CS_CON) {
594 congreet(s);
595 return;
596 }
Darren Tuckerfe6649d2004-08-13 21:19:37 +1000597 n = atomicio(read, s, c->c_data + c->c_off, c->c_len - c->c_off);
Damien Millerb253cc42005-05-26 12:23:44 +1000598 if (n == 0) {
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000599 error("read (%s): %s", c->c_name, strerror(errno));
600 confree(s);
601 return;
602 }
603 c->c_off += n;
604
605 if (c->c_off == c->c_len)
606 switch (c->c_status) {
607 case CS_SIZE:
608 c->c_plen = htonl(c->c_plen);
609 c->c_len = c->c_plen + 8 - (c->c_plen & 7);
610 c->c_off = 0;
611 c->c_data = xmalloc(c->c_len);
612 c->c_status = CS_KEYS;
613 break;
614 case CS_KEYS:
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000615 keyprint(c, keygrab_ssh1(c));
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000616 confree(s);
617 return;
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000618 default:
Kevin Stevesfa72dda2000-12-15 18:39:12 +0000619 fatal("conread: invalid status %d", c->c_status);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000620 break;
621 }
622
623 contouch(s);
624}
625
Ben Lindstrombba81212001-06-25 05:01:22 +0000626static void
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000627conloop(void)
628{
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000629 struct timeval seltime, now;
Ben Lindstrom965710f2002-07-07 22:17:22 +0000630 fd_set *r, *e;
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000631 con *c;
Ben Lindstrom965710f2002-07-07 22:17:22 +0000632 int i;
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000633
634 gettimeofday(&now, NULL);
Ben Lindstrom61c183b2002-06-21 00:09:54 +0000635 c = TAILQ_FIRST(&tq);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000636
Ben Lindstromd20b8552001-03-05 07:01:18 +0000637 if (c && (c->c_tv.tv_sec > now.tv_sec ||
638 (c->c_tv.tv_sec == now.tv_sec && c->c_tv.tv_usec > now.tv_usec))) {
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000639 seltime = c->c_tv;
640 seltime.tv_sec -= now.tv_sec;
641 seltime.tv_usec -= now.tv_usec;
Ben Lindstromc791beb2001-02-10 23:18:11 +0000642 if (seltime.tv_usec < 0) {
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000643 seltime.tv_usec += 1000000;
644 seltime.tv_sec--;
645 }
646 } else
647 seltime.tv_sec = seltime.tv_usec = 0;
648
Damien Miller07d86be2006-03-26 14:19:21 +1100649 r = xcalloc(read_wait_nfdset, sizeof(fd_mask));
650 e = xcalloc(read_wait_nfdset, sizeof(fd_mask));
651 memcpy(r, read_wait, read_wait_nfdset * sizeof(fd_mask));
652 memcpy(e, read_wait, read_wait_nfdset * sizeof(fd_mask));
Ben Lindstromc1e04212001-03-05 07:04:38 +0000653
654 while (select(maxfd, r, NULL, e, &seltime) == -1 &&
Ben Lindstromf9452512001-02-15 03:12:08 +0000655 (errno == EAGAIN || errno == EINTR))
656 ;
657
Ben Lindstromd20b8552001-03-05 07:01:18 +0000658 for (i = 0; i < maxfd; i++) {
Ben Lindstromc1e04212001-03-05 07:04:38 +0000659 if (FD_ISSET(i, e)) {
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000660 error("%s: exception!", fdcon[i].c_name);
661 confree(i);
Ben Lindstromc1e04212001-03-05 07:04:38 +0000662 } else if (FD_ISSET(i, r))
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000663 conread(i);
Ben Lindstromd20b8552001-03-05 07:01:18 +0000664 }
Ben Lindstromc1e04212001-03-05 07:04:38 +0000665 xfree(r);
666 xfree(e);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000667
Ben Lindstrom61c183b2002-06-21 00:09:54 +0000668 c = TAILQ_FIRST(&tq);
Ben Lindstromd20b8552001-03-05 07:01:18 +0000669 while (c && (c->c_tv.tv_sec < now.tv_sec ||
670 (c->c_tv.tv_sec == now.tv_sec && c->c_tv.tv_usec < now.tv_usec))) {
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000671 int s = c->c_fd;
Ben Lindstromd20b8552001-03-05 07:01:18 +0000672
Ben Lindstrom61c183b2002-06-21 00:09:54 +0000673 c = TAILQ_NEXT(c, c_link);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000674 conrecycle(s);
675 }
676}
677
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000678static void
679do_host(char *host)
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000680{
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000681 char *name = strnnsep(&host, " \t\n");
682 int j;
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000683
Ben Lindstromeaffb9d2001-12-06 16:28:19 +0000684 if (name == NULL)
685 return;
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000686 for (j = KT_RSA1; j <= KT_RSA; j *= 2) {
687 if (get_keytypes & j) {
688 while (ncon >= MAXCON)
689 conloop();
690 conalloc(name, *host ? host : name, j);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000691 }
692 }
693}
694
Ben Lindstrom9c8edc92002-02-26 17:52:14 +0000695void
696fatal(const char *fmt,...)
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000697{
Ben Lindstrom9c8edc92002-02-26 17:52:14 +0000698 va_list args;
Ben Lindstrom965710f2002-07-07 22:17:22 +0000699
Ben Lindstrom9c8edc92002-02-26 17:52:14 +0000700 va_start(args, fmt);
701 do_log(SYSLOG_LEVEL_FATAL, fmt, args);
702 va_end(args);
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000703 if (nonfatal_fatal)
704 longjmp(kexjmp, -1);
Ben Lindstrom9c8edc92002-02-26 17:52:14 +0000705 else
Darren Tucker3d326222003-09-22 21:11:20 +1000706 exit(255);
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000707}
708
709static void
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000710usage(void)
711{
Damien Miller9a2fdbd2005-03-02 12:04:01 +1100712 fprintf(stderr, "usage: %s [-46Hv] [-f file] [-p port] [-T timeout] [-t type]\n"
Ben Lindstrom965710f2002-07-07 22:17:22 +0000713 "\t\t [host | addrlist namelist] [...]\n",
Ben Lindstromddfb1e32001-08-06 22:06:35 +0000714 __progname);
Ben Lindstromddfb1e32001-08-06 22:06:35 +0000715 exit(1);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000716}
717
718int
719main(int argc, char **argv)
720{
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000721 int debug_flag = 0, log_level = SYSLOG_LEVEL_INFO;
722 int opt, fopt_count = 0;
723 char *tname;
Kevin Steves76e7d9b2001-09-20 20:30:09 +0000724
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000725 extern int optind;
726 extern char *optarg;
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000727
Damien Miller59d3d5b2003-08-22 09:34:41 +1000728 __progname = ssh_get_progname(argv[0]);
Ben Lindstrom4e088e42001-10-10 20:45:43 +0000729 init_rng();
730 seed_rng();
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000731 TAILQ_INIT(&tq);
732
Darren Tuckerce321d82005-10-03 18:11:24 +1000733 /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
734 sanitise_stdfd();
735
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000736 if (argc <= 1)
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000737 usage();
738
Damien Millerdb7b8172005-03-01 21:48:03 +1100739 while ((opt = getopt(argc, argv, "Hv46p:T:t:f:")) != -1) {
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000740 switch (opt) {
Damien Millerdb7b8172005-03-01 21:48:03 +1100741 case 'H':
742 hash_hosts = 1;
743 break;
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000744 case 'p':
745 ssh_port = a2port(optarg);
746 if (ssh_port == 0) {
747 fprintf(stderr, "Bad port '%s'\n", optarg);
748 exit(1);
749 }
750 break;
751 case 'T':
Ben Lindstromedd098b2002-07-04 00:07:13 +0000752 timeout = convtime(optarg);
753 if (timeout == -1 || timeout == 0) {
754 fprintf(stderr, "Bad timeout '%s'\n", optarg);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000755 usage();
Ben Lindstromedd098b2002-07-04 00:07:13 +0000756 }
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000757 break;
758 case 'v':
759 if (!debug_flag) {
760 debug_flag = 1;
761 log_level = SYSLOG_LEVEL_DEBUG1;
762 }
763 else if (log_level < SYSLOG_LEVEL_DEBUG3)
764 log_level++;
765 else
766 fatal("Too high debugging level.");
767 break;
Kevin Steves76e7d9b2001-09-20 20:30:09 +0000768 case 'f':
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000769 if (strcmp(optarg, "-") == 0)
770 optarg = NULL;
771 argv[fopt_count++] = optarg;
772 break;
773 case 't':
774 get_keytypes = 0;
775 tname = strtok(optarg, ",");
776 while (tname) {
777 int type = key_type_from_name(tname);
778 switch (type) {
779 case KEY_RSA1:
780 get_keytypes |= KT_RSA1;
781 break;
782 case KEY_DSA:
783 get_keytypes |= KT_DSA;
784 break;
785 case KEY_RSA:
786 get_keytypes |= KT_RSA;
787 break;
788 case KEY_UNSPEC:
Ben Lindstrom28c603b2001-12-06 16:45:10 +0000789 fatal("unknown key type %s", tname);
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000790 }
791 tname = strtok(NULL, ",");
792 }
793 break;
794 case '4':
795 IPv4or6 = AF_INET;
796 break;
797 case '6':
798 IPv4or6 = AF_INET6;
799 break;
800 case '?':
801 default:
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000802 usage();
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000803 }
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000804 }
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000805 if (optind == argc && !fopt_count)
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000806 usage();
807
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000808 log_init("ssh-keyscan", log_level, SYSLOG_FACILITY_USER, 1);
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000809
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000810 maxfd = fdlim_get(1);
811 if (maxfd < 0)
Kevin Stevesfa72dda2000-12-15 18:39:12 +0000812 fatal("%s: fdlim_get: bad value", __progname);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000813 if (maxfd > MAXMAXFD)
814 maxfd = MAXMAXFD;
Ben Lindstromd20b8552001-03-05 07:01:18 +0000815 if (MAXCON <= 0)
Kevin Stevesfa72dda2000-12-15 18:39:12 +0000816 fatal("%s: not enough file descriptors", __progname);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000817 if (maxfd > fdlim_get(0))
818 fdlim_set(maxfd);
Damien Miller07d86be2006-03-26 14:19:21 +1100819 fdcon = xcalloc(maxfd, sizeof(con));
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000820
Damien Miller07d86be2006-03-26 14:19:21 +1100821 read_wait_nfdset = howmany(maxfd, NFDBITS);
822 read_wait = xcalloc(read_wait_nfdset, sizeof(fd_mask));
Ben Lindstromc1e04212001-03-05 07:04:38 +0000823
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000824 if (fopt_count) {
825 Linebuf *lb;
826 char *line;
827 int j;
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000828
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000829 for (j = 0; j < fopt_count; j++) {
830 lb = Linebuf_alloc(argv[j], error);
Ben Lindstrom78bbd9e2001-09-12 17:10:40 +0000831 if (!lb)
832 continue;
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000833 while ((line = Linebuf_getline(lb)) != NULL)
834 do_host(line);
835 Linebuf_free(lb);
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000836 }
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000837 }
838
839 while (optind < argc)
840 do_host(argv[optind++]);
841
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000842 while (ncon > 0)
843 conloop();
844
845 return (0);
846}