1 /* 2 * Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>. 3 * 4 * Modification and redistribution in source and binary forms is 5 * permitted provided that due credit is given to the author and the 6 * OpenBSD project by leaving this copyright notice intact. 7 */ 8 9 #include "includes.h" 10 RCSID("$OpenBSD: ssh-keyscan.c,v 1.47 2004/03/08 09:38:05 djm Exp $"); 11 12 #include <sys/queue.h> 13 #include <errno.h> 14 15 #include <openssl/bn.h> 16 17 #include <setjmp.h> 18 #include "xmalloc.h" 19 #include "ssh.h" 20 #include "ssh1.h" 21 #include "key.h" 22 #include "kex.h" 23 #include "compat.h" 24 #include "myproposal.h" 25 #include "packet.h" 26 #include "dispatch.h" 27 #include "buffer.h" 28 #include "bufaux.h" 29 #include "log.h" 30 #include "atomicio.h" 31 #include "misc.h" 32 33 /* Flag indicating whether IPv4 or IPv6. This can be set on the command line. 34 Default value is AF_UNSPEC means both IPv4 and IPv6. */ 35 int IPv4or6 = AF_UNSPEC; 36 37 int ssh_port = SSH_DEFAULT_PORT; 38 39 #define KT_RSA1 1 40 #define KT_DSA 2 41 #define KT_RSA 4 42 43 int get_keytypes = KT_RSA1; /* Get only RSA1 keys by default */ 44 45 #define MAXMAXFD 256 46 47 /* The number of seconds after which to give up on a TCP connection */ 48 int timeout = 5; 49 50 int maxfd; 51 #define MAXCON (maxfd - 10) 52 53 extern char *__progname; 54 fd_set *read_wait; 55 size_t read_wait_size; 56 int ncon; 57 int nonfatal_fatal = 0; 58 jmp_buf kexjmp; 59 Key *kexjmp_key; 60 61 /* 62 * Keep a connection structure for each file descriptor. The state 63 * associated with file descriptor n is held in fdcon[n]. 64 */ 65 typedef struct Connection { 66 u_char c_status; /* State of connection on this file desc. */ 67 #define CS_UNUSED 0 /* File descriptor unused */ 68 #define CS_CON 1 /* Waiting to connect/read greeting */ 69 #define CS_SIZE 2 /* Waiting to read initial packet size */ 70 #define CS_KEYS 3 /* Waiting to read public key packet */ 71 int c_fd; /* Quick lookup: c->c_fd == c - fdcon */ 72 int c_plen; /* Packet length field for ssh packet */ 73 int c_len; /* Total bytes which must be read. */ 74 int c_off; /* Length of data read so far. */ 75 int c_keytype; /* Only one of KT_RSA1, KT_DSA, or KT_RSA */ 76 char *c_namebase; /* Address to free for c_name and c_namelist */ 77 char *c_name; /* Hostname of connection for errors */ 78 char *c_namelist; /* Pointer to other possible addresses */ 79 char *c_output_name; /* Hostname of connection for output */ 80 char *c_data; /* Data read from this fd */ 81 Kex *c_kex; /* The key-exchange struct for ssh2 */ 82 struct timeval c_tv; /* Time at which connection gets aborted */ 83 TAILQ_ENTRY(Connection) c_link; /* List of connections in timeout order. */ 84 } con; 85 86 TAILQ_HEAD(conlist, Connection) tq; /* Timeout Queue */ 87 con *fdcon; 88 89 /* 90 * This is just a wrapper around fgets() to make it usable. 91 */ 92 93 /* Stress-test. Increase this later. */ 94 #define LINEBUF_SIZE 16 95 96 typedef struct { 97 char *buf; 98 u_int size; 99 int lineno; 100 const char *filename; 101 FILE *stream; 102 void (*errfun) (const char *,...); 103 } Linebuf; 104 105 static Linebuf * 106 Linebuf_alloc(const char *filename, void (*errfun) (const char *,...)) 107 { 108 Linebuf *lb; 109 110 if (!(lb = malloc(sizeof(*lb)))) { 111 if (errfun) 112 (*errfun) ("linebuf (%s): malloc failed\n", 113 filename ? filename : "(stdin)"); 114 return (NULL); 115 } 116 if (filename) { 117 lb->filename = filename; 118 if (!(lb->stream = fopen(filename, "r"))) { 119 xfree(lb); 120 if (errfun) 121 (*errfun) ("%s: %s\n", filename, strerror(errno)); 122 return (NULL); 123 } 124 } else { 125 lb->filename = "(stdin)"; 126 lb->stream = stdin; 127 } 128 129 if (!(lb->buf = malloc(lb->size = LINEBUF_SIZE))) { 130 if (errfun) 131 (*errfun) ("linebuf (%s): malloc failed\n", lb->filename); 132 xfree(lb); 133 return (NULL); 134 } 135 lb->errfun = errfun; 136 lb->lineno = 0; 137 return (lb); 138 } 139 140 static void 141 Linebuf_free(Linebuf * lb) 142 { 143 fclose(lb->stream); 144 xfree(lb->buf); 145 xfree(lb); 146 } 147 148 #if 0 149 static void 150 Linebuf_restart(Linebuf * lb) 151 { 152 clearerr(lb->stream); 153 rewind(lb->stream); 154 lb->lineno = 0; 155 } 156 157 static int 158 Linebuf_lineno(Linebuf * lb) 159 { 160 return (lb->lineno); 161 } 162 #endif 163 164 static char * 165 Linebuf_getline(Linebuf * lb) 166 { 167 int n = 0; 168 void *p; 169 170 lb->lineno++; 171 for (;;) { 172 /* Read a line */ 173 if (!fgets(&lb->buf[n], lb->size - n, lb->stream)) { 174 if (ferror(lb->stream) && lb->errfun) 175 (*lb->errfun)("%s: %s\n", lb->filename, 176 strerror(errno)); 177 return (NULL); 178 } 179 n = strlen(lb->buf); 180 181 /* Return it or an error if it fits */ 182 if (n > 0 && lb->buf[n - 1] == '\n') { 183 lb->buf[n - 1] = '\0'; 184 return (lb->buf); 185 } 186 if (n != lb->size - 1) { 187 if (lb->errfun) 188 (*lb->errfun)("%s: skipping incomplete last line\n", 189 lb->filename); 190 return (NULL); 191 } 192 /* Double the buffer if we need more space */ 193 lb->size *= 2; 194 if ((p = realloc(lb->buf, lb->size)) == NULL) { 195 lb->size /= 2; 196 if (lb->errfun) 197 (*lb->errfun)("linebuf (%s): realloc failed\n", 198 lb->filename); 199 return (NULL); 200 } 201 lb->buf = p; 202 } 203 } 204 205 static int 206 fdlim_get(int hard) 207 { 208 struct rlimit rlfd; 209 210 if (getrlimit(RLIMIT_NOFILE, &rlfd) < 0) 211 return (-1); 212 if ((hard ? rlfd.rlim_max : rlfd.rlim_cur) == RLIM_INFINITY) 213 return sysconf(_SC_OPEN_MAX); 214 else 215 return hard ? rlfd.rlim_max : rlfd.rlim_cur; 216 } 217 218 static int 219 fdlim_set(int lim) 220 { 221 struct rlimit rlfd; 222 223 if (lim <= 0) 224 return (-1); 225 if (getrlimit(RLIMIT_NOFILE, &rlfd) < 0) 226 return (-1); 227 rlfd.rlim_cur = lim; 228 if (setrlimit(RLIMIT_NOFILE, &rlfd) < 0) 229 return (-1); 230 return (0); 231 } 232 233 /* 234 * This is an strsep function that returns a null field for adjacent 235 * separators. This is the same as the 4.4BSD strsep, but different from the 236 * one in the GNU libc. 237 */ 238 static char * 239 xstrsep(char **str, const char *delim) 240 { 241 char *s, *e; 242 243 if (!**str) 244 return (NULL); 245 246 s = *str; 247 e = s + strcspn(s, delim); 248 249 if (*e != '\0') 250 *e++ = '\0'; 251 *str = e; 252 253 return (s); 254 } 255 256 /* 257 * Get the next non-null token (like GNU strsep). Strsep() will return a 258 * null token for two adjacent separators, so we may have to loop. 259 */ 260 static char * 261 strnnsep(char **stringp, char *delim) 262 { 263 char *tok; 264 265 do { 266 tok = xstrsep(stringp, delim); 267 } while (tok && *tok == '\0'); 268 return (tok); 269 } 270 271 static Key * 272 keygrab_ssh1(con *c) 273 { 274 static Key *rsa; 275 static Buffer msg; 276 277 if (rsa == NULL) { 278 buffer_init(&msg); 279 rsa = key_new(KEY_RSA1); 280 } 281 buffer_append(&msg, c->c_data, c->c_plen); 282 buffer_consume(&msg, 8 - (c->c_plen & 7)); /* padding */ 283 if (buffer_get_char(&msg) != (int) SSH_SMSG_PUBLIC_KEY) { 284 error("%s: invalid packet type", c->c_name); 285 buffer_clear(&msg); 286 return NULL; 287 } 288 buffer_consume(&msg, 8); /* cookie */ 289 290 /* server key */ 291 (void) buffer_get_int(&msg); 292 buffer_get_bignum(&msg, rsa->rsa->e); 293 buffer_get_bignum(&msg, rsa->rsa->n); 294 295 /* host key */ 296 (void) buffer_get_int(&msg); 297 buffer_get_bignum(&msg, rsa->rsa->e); 298 buffer_get_bignum(&msg, rsa->rsa->n); 299 300 buffer_clear(&msg); 301 302 return (rsa); 303 } 304 305 static int 306 hostjump(Key *hostkey) 307 { 308 kexjmp_key = hostkey; 309 longjmp(kexjmp, 1); 310 } 311 312 static int 313 ssh2_capable(int remote_major, int remote_minor) 314 { 315 switch (remote_major) { 316 case 1: 317 if (remote_minor == 99) 318 return 1; 319 break; 320 case 2: 321 return 1; 322 default: 323 break; 324 } 325 return 0; 326 } 327 328 static Key * 329 keygrab_ssh2(con *c) 330 { 331 int j; 332 333 packet_set_connection(c->c_fd, c->c_fd); 334 enable_compat20(); 335 myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = c->c_keytype == KT_DSA? 336 "ssh-dss": "ssh-rsa"; 337 c->c_kex = kex_setup(myproposal); 338 c->c_kex->kex[KEX_DH_GRP1_SHA1] = kexdh_client; 339 c->c_kex->kex[KEX_DH_GEX_SHA1] = kexgex_client; 340 c->c_kex->verify_host_key = hostjump; 341 342 if (!(j = setjmp(kexjmp))) { 343 nonfatal_fatal = 1; 344 dispatch_run(DISPATCH_BLOCK, &c->c_kex->done, c->c_kex); 345 fprintf(stderr, "Impossible! dispatch_run() returned!\n"); 346 exit(1); 347 } 348 nonfatal_fatal = 0; 349 xfree(c->c_kex); 350 c->c_kex = NULL; 351 packet_close(); 352 353 return j < 0? NULL : kexjmp_key; 354 } 355 356 static void 357 keyprint(con *c, Key *key) 358 { 359 if (!key) 360 return; 361 362 fprintf(stdout, "%s ", c->c_output_name ? c->c_output_name : c->c_name); 363 key_write(key, stdout); 364 fputs("\n", stdout); 365 } 366 367 static int 368 tcpconnect(char *host) 369 { 370 struct addrinfo hints, *ai, *aitop; 371 char strport[NI_MAXSERV]; 372 int gaierr, s = -1; 373 374 snprintf(strport, sizeof strport, "%d", ssh_port); 375 memset(&hints, 0, sizeof(hints)); 376 hints.ai_family = IPv4or6; 377 hints.ai_socktype = SOCK_STREAM; 378 if ((gaierr = getaddrinfo(host, strport, &hints, &aitop)) != 0) 379 fatal("getaddrinfo %s: %s", host, gai_strerror(gaierr)); 380 for (ai = aitop; ai; ai = ai->ai_next) { 381 s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); 382 if (s < 0) { 383 error("socket: %s", strerror(errno)); 384 continue; 385 } 386 if (fcntl(s, F_SETFL, O_NONBLOCK) < 0) 387 fatal("F_SETFL: %s", strerror(errno)); 388 if (connect(s, ai->ai_addr, ai->ai_addrlen) < 0 && 389 errno != EINPROGRESS) 390 error("connect (`%s'): %s", host, strerror(errno)); 391 else 392 break; 393 close(s); 394 s = -1; 395 } 396 freeaddrinfo(aitop); 397 return s; 398 } 399 400 static int 401 conalloc(char *iname, char *oname, int keytype) 402 { 403 char *namebase, *name, *namelist; 404 int s; 405 406 namebase = namelist = xstrdup(iname); 407 408 do { 409 name = xstrsep(&namelist, ","); 410 if (!name) { 411 xfree(namebase); 412 return (-1); 413 } 414 } while ((s = tcpconnect(name)) < 0); 415 416 if (s >= maxfd) 417 fatal("conalloc: fdno %d too high", s); 418 if (fdcon[s].c_status) 419 fatal("conalloc: attempt to reuse fdno %d", s); 420 421 fdcon[s].c_fd = s; 422 fdcon[s].c_status = CS_CON; 423 fdcon[s].c_namebase = namebase; 424 fdcon[s].c_name = name; 425 fdcon[s].c_namelist = namelist; 426 fdcon[s].c_output_name = xstrdup(oname); 427 fdcon[s].c_data = (char *) &fdcon[s].c_plen; 428 fdcon[s].c_len = 4; 429 fdcon[s].c_off = 0; 430 fdcon[s].c_keytype = keytype; 431 gettimeofday(&fdcon[s].c_tv, NULL); 432 fdcon[s].c_tv.tv_sec += timeout; 433 TAILQ_INSERT_TAIL(&tq, &fdcon[s], c_link); 434 FD_SET(s, read_wait); 435 ncon++; 436 return (s); 437 } 438 439 static void 440 confree(int s) 441 { 442 if (s >= maxfd || fdcon[s].c_status == CS_UNUSED) 443 fatal("confree: attempt to free bad fdno %d", s); 444 close(s); 445 xfree(fdcon[s].c_namebase); 446 xfree(fdcon[s].c_output_name); 447 if (fdcon[s].c_status == CS_KEYS) 448 xfree(fdcon[s].c_data); 449 fdcon[s].c_status = CS_UNUSED; 450 fdcon[s].c_keytype = 0; 451 TAILQ_REMOVE(&tq, &fdcon[s], c_link); 452 FD_CLR(s, read_wait); 453 ncon--; 454 } 455 456 static void 457 contouch(int s) 458 { 459 TAILQ_REMOVE(&tq, &fdcon[s], c_link); 460 gettimeofday(&fdcon[s].c_tv, NULL); 461 fdcon[s].c_tv.tv_sec += timeout; 462 TAILQ_INSERT_TAIL(&tq, &fdcon[s], c_link); 463 } 464 465 static int 466 conrecycle(int s) 467 { 468 con *c = &fdcon[s]; 469 int ret; 470 471 ret = conalloc(c->c_namelist, c->c_output_name, c->c_keytype); 472 confree(s); 473 return (ret); 474 } 475 476 static void 477 congreet(int s) 478 { 479 int remote_major = 0, remote_minor = 0, n = 0; 480 char buf[256], *cp; 481 char remote_version[sizeof buf]; 482 size_t bufsiz; 483 con *c = &fdcon[s]; 484 485 bufsiz = sizeof(buf); 486 cp = buf; 487 while (bufsiz-- && (n = read(s, cp, 1)) == 1 && *cp != '\n') { 488 if (*cp == '\r') 489 *cp = '\n'; 490 cp++; 491 } 492 if (n < 0) { 493 if (errno != ECONNREFUSED) 494 error("read (%s): %s", c->c_name, strerror(errno)); 495 conrecycle(s); 496 return; 497 } 498 if (n == 0) { 499 error("%s: Connection closed by remote host", c->c_name); 500 conrecycle(s); 501 return; 502 } 503 if (*cp != '\n' && *cp != '\r') { 504 error("%s: bad greeting", c->c_name); 505 confree(s); 506 return; 507 } 508 *cp = '\0'; 509 if (sscanf(buf, "SSH-%d.%d-%[^\n]\n", 510 &remote_major, &remote_minor, remote_version) == 3) 511 compat_datafellows(remote_version); 512 else 513 datafellows = 0; 514 if (c->c_keytype != KT_RSA1) { 515 if (!ssh2_capable(remote_major, remote_minor)) { 516 debug("%s doesn't support ssh2", c->c_name); 517 confree(s); 518 return; 519 } 520 } else if (remote_major != 1) { 521 debug("%s doesn't support ssh1", c->c_name); 522 confree(s); 523 return; 524 } 525 fprintf(stderr, "# %s %s\n", c->c_name, chop(buf)); 526 n = snprintf(buf, sizeof buf, "SSH-%d.%d-OpenSSH-keyscan\r\n", 527 c->c_keytype == KT_RSA1? PROTOCOL_MAJOR_1 : PROTOCOL_MAJOR_2, 528 c->c_keytype == KT_RSA1? PROTOCOL_MINOR_1 : PROTOCOL_MINOR_2); 529 if (atomicio(vwrite, s, buf, n) != n) { 530 error("write (%s): %s", c->c_name, strerror(errno)); 531 confree(s); 532 return; 533 } 534 if (c->c_keytype != KT_RSA1) { 535 keyprint(c, keygrab_ssh2(c)); 536 confree(s); 537 return; 538 } 539 c->c_status = CS_SIZE; 540 contouch(s); 541 } 542 543 static void 544 conread(int s) 545 { 546 con *c = &fdcon[s]; 547 int n; 548 549 if (c->c_status == CS_CON) { 550 congreet(s); 551 return; 552 } 553 n = read(s, c->c_data + c->c_off, c->c_len - c->c_off); 554 if (n < 0) { 555 error("read (%s): %s", c->c_name, strerror(errno)); 556 confree(s); 557 return; 558 } 559 c->c_off += n; 560 561 if (c->c_off == c->c_len) 562 switch (c->c_status) { 563 case CS_SIZE: 564 c->c_plen = htonl(c->c_plen); 565 c->c_len = c->c_plen + 8 - (c->c_plen & 7); 566 c->c_off = 0; 567 c->c_data = xmalloc(c->c_len); 568 c->c_status = CS_KEYS; 569 break; 570 case CS_KEYS: 571 keyprint(c, keygrab_ssh1(c)); 572 confree(s); 573 return; 574 break; 575 default: 576 fatal("conread: invalid status %d", c->c_status); 577 break; 578 } 579 580 contouch(s); 581 } 582 583 static void 584 conloop(void) 585 { 586 struct timeval seltime, now; 587 fd_set *r, *e; 588 con *c; 589 int i; 590 591 gettimeofday(&now, NULL); 592 c = TAILQ_FIRST(&tq); 593 594 if (c && (c->c_tv.tv_sec > now.tv_sec || 595 (c->c_tv.tv_sec == now.tv_sec && c->c_tv.tv_usec > now.tv_usec))) { 596 seltime = c->c_tv; 597 seltime.tv_sec -= now.tv_sec; 598 seltime.tv_usec -= now.tv_usec; 599 if (seltime.tv_usec < 0) { 600 seltime.tv_usec += 1000000; 601 seltime.tv_sec--; 602 } 603 } else 604 seltime.tv_sec = seltime.tv_usec = 0; 605 606 r = xmalloc(read_wait_size); 607 memcpy(r, read_wait, read_wait_size); 608 e = xmalloc(read_wait_size); 609 memcpy(e, read_wait, read_wait_size); 610 611 while (select(maxfd, r, NULL, e, &seltime) == -1 && 612 (errno == EAGAIN || errno == EINTR)) 613 ; 614 615 for (i = 0; i < maxfd; i++) { 616 if (FD_ISSET(i, e)) { 617 error("%s: exception!", fdcon[i].c_name); 618 confree(i); 619 } else if (FD_ISSET(i, r)) 620 conread(i); 621 } 622 xfree(r); 623 xfree(e); 624 625 c = TAILQ_FIRST(&tq); 626 while (c && (c->c_tv.tv_sec < now.tv_sec || 627 (c->c_tv.tv_sec == now.tv_sec && c->c_tv.tv_usec < now.tv_usec))) { 628 int s = c->c_fd; 629 630 c = TAILQ_NEXT(c, c_link); 631 conrecycle(s); 632 } 633 } 634 635 static void 636 do_host(char *host) 637 { 638 char *name = strnnsep(&host, " \t\n"); 639 int j; 640 641 if (name == NULL) 642 return; 643 for (j = KT_RSA1; j <= KT_RSA; j *= 2) { 644 if (get_keytypes & j) { 645 while (ncon >= MAXCON) 646 conloop(); 647 conalloc(name, *host ? host : name, j); 648 } 649 } 650 } 651 652 void 653 fatal(const char *fmt,...) 654 { 655 va_list args; 656 657 va_start(args, fmt); 658 do_log(SYSLOG_LEVEL_FATAL, fmt, args); 659 va_end(args); 660 if (nonfatal_fatal) 661 longjmp(kexjmp, -1); 662 else 663 exit(255); 664 } 665 666 static void 667 usage(void) 668 { 669 fprintf(stderr, "usage: %s [-v46] [-p port] [-T timeout] [-t type] [-f file]\n" 670 "\t\t [host | addrlist namelist] [...]\n", 671 __progname); 672 exit(1); 673 } 674 675 int 676 main(int argc, char **argv) 677 { 678 int debug_flag = 0, log_level = SYSLOG_LEVEL_INFO; 679 int opt, fopt_count = 0; 680 char *tname; 681 682 extern int optind; 683 extern char *optarg; 684 685 TAILQ_INIT(&tq); 686 687 if (argc <= 1) 688 usage(); 689 690 while ((opt = getopt(argc, argv, "v46p:T:t:f:")) != -1) { 691 switch (opt) { 692 case 'p': 693 ssh_port = a2port(optarg); 694 if (ssh_port == 0) { 695 fprintf(stderr, "Bad port '%s'\n", optarg); 696 exit(1); 697 } 698 break; 699 case 'T': 700 timeout = convtime(optarg); 701 if (timeout == -1 || timeout == 0) { 702 fprintf(stderr, "Bad timeout '%s'\n", optarg); 703 usage(); 704 } 705 break; 706 case 'v': 707 if (!debug_flag) { 708 debug_flag = 1; 709 log_level = SYSLOG_LEVEL_DEBUG1; 710 } 711 else if (log_level < SYSLOG_LEVEL_DEBUG3) 712 log_level++; 713 else 714 fatal("Too high debugging level."); 715 break; 716 case 'f': 717 if (strcmp(optarg, "-") == 0) 718 optarg = NULL; 719 argv[fopt_count++] = optarg; 720 break; 721 case 't': 722 get_keytypes = 0; 723 tname = strtok(optarg, ","); 724 while (tname) { 725 int type = key_type_from_name(tname); 726 switch (type) { 727 case KEY_RSA1: 728 get_keytypes |= KT_RSA1; 729 break; 730 case KEY_DSA: 731 get_keytypes |= KT_DSA; 732 break; 733 case KEY_RSA: 734 get_keytypes |= KT_RSA; 735 break; 736 case KEY_UNSPEC: 737 fatal("unknown key type %s", tname); 738 } 739 tname = strtok(NULL, ","); 740 } 741 break; 742 case '4': 743 IPv4or6 = AF_INET; 744 break; 745 case '6': 746 IPv4or6 = AF_INET6; 747 break; 748 case '?': 749 default: 750 usage(); 751 } 752 } 753 if (optind == argc && !fopt_count) 754 usage(); 755 756 log_init("ssh-keyscan", log_level, SYSLOG_FACILITY_USER, 1); 757 758 maxfd = fdlim_get(1); 759 if (maxfd < 0) 760 fatal("%s: fdlim_get: bad value", __progname); 761 if (maxfd > MAXMAXFD) 762 maxfd = MAXMAXFD; 763 if (MAXCON <= 0) 764 fatal("%s: not enough file descriptors", __progname); 765 if (maxfd > fdlim_get(0)) 766 fdlim_set(maxfd); 767 fdcon = xmalloc(maxfd * sizeof(con)); 768 memset(fdcon, 0, maxfd * sizeof(con)); 769 770 read_wait_size = howmany(maxfd, NFDBITS) * sizeof(fd_mask); 771 read_wait = xmalloc(read_wait_size); 772 memset(read_wait, 0, read_wait_size); 773 774 if (fopt_count) { 775 Linebuf *lb; 776 char *line; 777 int j; 778 779 for (j = 0; j < fopt_count; j++) { 780 lb = Linebuf_alloc(argv[j], error); 781 if (!lb) 782 continue; 783 while ((line = Linebuf_getline(lb)) != NULL) 784 do_host(line); 785 Linebuf_free(lb); 786 } 787 } 788 789 while (optind < argc) 790 do_host(argv[optind++]); 791 792 while (ncon > 0) 793 conloop(); 794 795 return (0); 796 } 797