lsh.c 2.31 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1 2 3
/* lsh.c
 *
 * client main program
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * $Id$ */

/* lsh, an implementation of the ssh protocol
 *
 * Copyright (C) 1998 Niels Mller
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Niels Möller's avatar
Niels Möller committed
24 25
 */

Niels Möller's avatar
Niels Möller committed
26
#include <errno.h>
Niels Möller's avatar
Niels Möller committed
27
#include <locale.h>
Niels Möller's avatar
Niels Möller committed
28 29
#include <stdio.h>
#include <string.h>
Niels Möller's avatar
Niels Möller committed
30 31

#include "getopt.h"
Niels Möller's avatar
Niels Möller committed
32 33 34 35

#include "io.h"
#include "werror.h"
#include "client.h"
Niels Möller's avatar
Niels Möller committed
36 37 38
#include "format.h"
#include "crypto.h"
#include "xalloc.h"
Niels Möller's avatar
Niels Möller committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

#define BLOCK_SIZE 32768

/* Global variable */
struct io_backend backend;

void usage() NORETURN;

void usage()
{
  exit(1);
}

int main(int argc, char **argv)
{
  char *host = NULL;
  char *port = "ssh";
  int option;

Niels Möller's avatar
Niels Möller committed
58 59
  struct lsh_string *random_seed;
  
Niels Möller's avatar
Niels Möller committed
60
  struct sockaddr_in remote;
Niels Möller's avatar
Niels Möller committed
61 62 63 64

  /* For filtering messages. Could perhaps also be used when converting
   * strings to and from UTF8. */
  setlocale(LC_CTYPE, "");
Niels Möller's avatar
Niels Möller committed
65
  
Niels Möller's avatar
Niels Möller committed
66
  while((option = getopt(argc, argv, "dp:qv")) != -1)
Niels Möller's avatar
Niels Möller committed
67 68 69 70 71 72 73 74 75 76 77
    switch(option)
      {
      case 'p':
	port = optarg;
	break;
      case 'q':
	quiet_flag = 1;
	break;
      case 'd':
	debug_flag = 1;
	break;
Niels Möller's avatar
Niels Möller committed
78 79 80
      case 'v':
	verbose_flag = 1;
	break;
Niels Möller's avatar
Niels Möller committed
81 82 83 84 85 86 87 88 89 90 91
      default:
	usage();
      }

  if ( (argc - optind) < 1)
    usage();

  host = argv[optind];

  if (!get_inaddr(&remote, host, port, "tcp"))
    {
Niels Möller's avatar
Niels Möller committed
92
      fprintf(stderr, "No such host or service\n");
Niels Möller's avatar
Niels Möller committed
93 94 95
      exit(1);
    }

Niels Möller's avatar
Niels Möller committed
96 97
  random_seed = ssh_format("%z", "gazonk");
  
Niels Möller's avatar
Niels Möller committed
98 99 100 101 102 103 104 105 106 107 108
  if (!io_connect(&backend, &remote, NULL,
		  make_client_callback(&backend,
				       "lsh - a free ssh",
				       BLOCK_SIZE,
				       make_poor_random(&sha_algorithm,
							random_seed))))
    {
      werror("lsh: Connection failed: %s\n", strerror(errno));
      return 1;
    }
  
Niels Möller's avatar
Niels Möller committed
109
  lsh_string_free(random_seed);
Niels Möller's avatar
Niels Möller committed
110
  
Niels Möller's avatar
Niels Möller committed
111
  io_run(&backend);
Niels Möller's avatar
Niels Möller committed
112 113 114 115 116

  return 0;
}