summaryrefslogtreecommitdiff
path: root/ssh-keyscan.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2001-03-05 07:01:18 +0000
committerBen Lindstrom <mouring@eviladmin.org>2001-03-05 07:01:18 +0000
commitd20b855bc6b7634575beeec572cdbdc57504d6a8 (patch)
tree5285776e5cbe66ff68c0eaf8638de634bbac25ea /ssh-keyscan.c
parent92a2e38f8e71b2d7b97df1f7a5ade9efaefdb184 (diff)
- deraadt@cvs.openbsd.org 2001/03/03 06:53:12
[ssh-keyscan.c] standard theo sweep
Diffstat (limited to 'ssh-keyscan.c')
-rw-r--r--ssh-keyscan.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/ssh-keyscan.c b/ssh-keyscan.c
index a8fb028d8..fe03c145c 100644
--- a/ssh-keyscan.c
+++ b/ssh-keyscan.c
@@ -8,7 +8,7 @@
8 */ 8 */
9 9
10#include "includes.h" 10#include "includes.h"
11RCSID("$OpenBSD: ssh-keyscan.c,v 1.17 2001/02/21 07:37:04 deraadt Exp $"); 11RCSID("$OpenBSD: ssh-keyscan.c,v 1.18 2001/03/03 06:53:12 deraadt Exp $");
12 12
13#if defined(HAVE_SYS_QUEUE_H) && !defined(HAVE_BOGUS_SYS_QUEUE_H) 13#if defined(HAVE_SYS_QUEUE_H) && !defined(HAVE_BOGUS_SYS_QUEUE_H)
14#include <sys/queue.h> 14#include <sys/queue.h>
@@ -26,6 +26,7 @@ RCSID("$OpenBSD: ssh-keyscan.c,v 1.17 2001/02/21 07:37:04 deraadt Exp $");
26#include "buffer.h" 26#include "buffer.h"
27#include "bufaux.h" 27#include "bufaux.h"
28#include "log.h" 28#include "log.h"
29#include "atomicio.h"
29 30
30static int argno = 1; /* Number of argument currently being parsed */ 31static int argno = 1; /* Number of argument currently being parsed */
31 32
@@ -37,7 +38,7 @@ int family = AF_UNSPEC; /* IPv4, IPv6 or both */
37int timeout = 5; 38int timeout = 5;
38 39
39int maxfd; 40int maxfd;
40#define maxcon (maxfd - 10) 41#define MAXCON (maxfd - 10)
41 42
42#ifdef HAVE___PROGNAME 43#ifdef HAVE___PROGNAME
43extern char *__progname; 44extern char *__progname;
@@ -368,9 +369,9 @@ conalloc(char *iname, char *oname)
368void 369void
369confree(int s) 370confree(int s)
370{ 371{
371 close(s);
372 if (s >= maxfd || fdcon[s].c_status == CS_UNUSED) 372 if (s >= maxfd || fdcon[s].c_status == CS_UNUSED)
373 fatal("confree: attempt to free bad fdno %d", s); 373 fatal("confree: attempt to free bad fdno %d", s);
374 close(s);
374 xfree(fdcon[s].c_namebase); 375 xfree(fdcon[s].c_namebase);
375 xfree(fdcon[s].c_output_name); 376 xfree(fdcon[s].c_output_name);
376 if (fdcon[s].c_status == CS_KEYS) 377 if (fdcon[s].c_status == CS_KEYS)
@@ -428,7 +429,7 @@ congreet(int s)
428 buf[n - 1] = '\0'; 429 buf[n - 1] = '\0';
429 fprintf(stderr, "# %s %s\n", c->c_name, buf); 430 fprintf(stderr, "# %s %s\n", c->c_name, buf);
430 n = snprintf(buf, sizeof buf, "SSH-1.5-OpenSSH-keyscan\r\n"); 431 n = snprintf(buf, sizeof buf, "SSH-1.5-OpenSSH-keyscan\r\n");
431 if (write(s, buf, n) != n) { 432 if (atomicio(write, s, buf, n) != n) {
432 error("write (%s): %s", c->c_name, strerror(errno)); 433 error("write (%s): %s", c->c_name, strerror(errno));
433 confree(s); 434 confree(s);
434 return; 435 return;
@@ -488,9 +489,8 @@ conloop(void)
488 gettimeofday(&now, NULL); 489 gettimeofday(&now, NULL);
489 c = tq.tqh_first; 490 c = tq.tqh_first;
490 491
491 if (c && 492 if (c && (c->c_tv.tv_sec > now.tv_sec ||
492 (c->c_tv.tv_sec > now.tv_sec || 493 (c->c_tv.tv_sec == now.tv_sec && c->c_tv.tv_usec > now.tv_usec))) {
493 (c->c_tv.tv_sec == now.tv_sec && c->c_tv.tv_usec > now.tv_usec))) {
494 seltime = c->c_tv; 494 seltime = c->c_tv;
495 seltime.tv_sec -= now.tv_sec; 495 seltime.tv_sec -= now.tv_sec;
496 seltime.tv_usec -= now.tv_usec; 496 seltime.tv_usec -= now.tv_usec;
@@ -506,18 +506,19 @@ conloop(void)
506 (errno == EAGAIN || errno == EINTR)) 506 (errno == EAGAIN || errno == EINTR))
507 ; 507 ;
508 508
509 for (i = 0; i < maxfd; i++) 509 for (i = 0; i < maxfd; i++) {
510 if (FD_ISSET(i, &e)) { 510 if (FD_ISSET(i, &e)) {
511 error("%s: exception!", fdcon[i].c_name); 511 error("%s: exception!", fdcon[i].c_name);
512 confree(i); 512 confree(i);
513 } else if (FD_ISSET(i, &r)) 513 } else if (FD_ISSET(i, &r))
514 conread(i); 514 conread(i);
515 }
515 516
516 c = tq.tqh_first; 517 c = tq.tqh_first;
517 while (c && 518 while (c && (c->c_tv.tv_sec < now.tv_sec ||
518 (c->c_tv.tv_sec < now.tv_sec || 519 (c->c_tv.tv_sec == now.tv_sec && c->c_tv.tv_usec < now.tv_usec))) {
519 (c->c_tv.tv_sec == now.tv_sec && c->c_tv.tv_usec < now.tv_usec))) {
520 int s = c->c_fd; 520 int s = c->c_fd;
521
521 c = c->c_link.tqe_next; 522 c = c->c_link.tqe_next;
522 conrecycle(s); 523 conrecycle(s);
523 } 524 }
@@ -540,6 +541,7 @@ nexthost(int argc, char **argv)
540 return (argv[argno++]); 541 return (argv[argno++]);
541 } else if (!strncmp(argv[argno], "-f", 2)) { 542 } else if (!strncmp(argv[argno], "-f", 2)) {
542 char *fname; 543 char *fname;
544
543 if (argv[argno][2]) 545 if (argv[argno][2])
544 fname = &argv[argno++][2]; 546 fname = &argv[argno++][2];
545 else if (++argno >= argc) { 547 else if (++argno >= argc) {
@@ -551,9 +553,11 @@ nexthost(int argc, char **argv)
551 fname = NULL; 553 fname = NULL;
552 lb = Linebuf_alloc(fname, error); 554 lb = Linebuf_alloc(fname, error);
553 } else 555 } else
554 error("ignoring invalid/misplaced option `%s'", argv[argno++]); 556 error("ignoring invalid/misplaced option `%s'",
557 argv[argno++]);
555 } else { 558 } else {
556 char *line; 559 char *line;
560
557 line = Linebuf_getline(lb); 561 line = Linebuf_getline(lb);
558 if (line) 562 if (line)
559 return (line); 563 return (line);
@@ -601,7 +605,7 @@ main(int argc, char **argv)
601 fatal("%s: fdlim_get: bad value", __progname); 605 fatal("%s: fdlim_get: bad value", __progname);
602 if (maxfd > MAXMAXFD) 606 if (maxfd > MAXMAXFD)
603 maxfd = MAXMAXFD; 607 maxfd = MAXMAXFD;
604 if (maxcon <= 0) 608 if (MAXCON <= 0)
605 fatal("%s: not enough file descriptors", __progname); 609 fatal("%s: not enough file descriptors", __progname);
606 if (maxfd > fdlim_get(0)) 610 if (maxfd > fdlim_get(0))
607 fdlim_set(maxfd); 611 fdlim_set(maxfd);
@@ -609,7 +613,7 @@ main(int argc, char **argv)
609 memset(fdcon, 0, maxfd * sizeof(con)); 613 memset(fdcon, 0, maxfd * sizeof(con));
610 614
611 do { 615 do {
612 while (ncon < maxcon) { 616 while (ncon < MAXCON) {
613 char *name; 617 char *name;
614 618
615 host = nexthost(argc, argv); 619 host = nexthost(argc, argv);