Commit 49d7f3d5 authored by Niels Möller's avatar Niels Möller
Browse files

*** empty log message ***

Rev: src/
Rev: src/abstract_crypto.h:1.2
Rev: src/abstract_io.h:1.4
Rev: src/blocking_write.h:1.2
Rev: src/client.h:1.2
Rev: src/
Rev: src/crypto_common.h:1.2(DEAD)
Rev: src/debug.c:1.5
Rev: src/debug.h:1.4
Rev: src/encrypt.c:1.5
Rev: src/encrypt.h:1.4
Rev: src/getopt.c:1.1
Rev: src/getopt.h:1.1
Rev: src/keyexchange.h:1.2
Rev: src/lsh.c:1.3
Rev: src/packet_dispatch.h:1.3
Rev: src/pad.h:1.5
Rev: src/read_line.c:1.2
Rev: src/read_line.h:1.3
Rev: src/read_packet.c:1.2
Rev: src/read_packet.h:1.3
Rev: src/session.h:1.3
Rev: src/unpad.c:1.4
Rev: src/unpad.h:1.5
Rev: src/void.c:1.4
Rev: src/void.h:1.2
Rev: src/werror.c:1.3
Rev: src/werror.h:1.3
Rev: src/write_buffer.h:1.2
Rev: src/xalloc.c:1.2
Rev: src/xalloc.h:1.2
Rev: src/zlib.c:1.4
parent d45c80b3
......@@ -32,9 +32,11 @@ binprefix =
#### End of system configuration section. ####
SRCS = atoms.c atoms_bignum.c debug.c encrypt.c format.c packet_dispatch.c \
pad.c parse.c server_keyexchange.c transport.c unpad.c void.c werror.c \
SRCS = atoms.c atoms_gperf.c atoms_table.c bignum.c client.c debug.c \
encrypt.c format.c io.c lsh.c packet_dispatch.c \
pad.c parse.c read_data.c read_line.c read_packet.c \
server_keyexchange.c session.c transport.c unpad.c void.c \
werror.c write_buffer.c xalloc.c
OBJS = $(SRCS:.c=.o)
all: lsh
......@@ -43,7 +45,10 @@ all: lsh
$(CC) -c $(CPPFLAGS) $(DEFS) $(CFLAGS) $<
lsh: lsh.o client.o read_packet.o read_line.o
lsh: lsh.o client.o read_packet.o read_line.o debug.o werror.o \
xalloc.o io.o void.o write_buffer.o
# $(CC) -o lsh $(CFLAGS) $<
atoms_defines.h: process_atoms
bash process_atoms header < >atoms_defines.h
......@@ -21,10 +21,10 @@ struct crypto_algorithm
UINT32 block_size;
UINT32 key_size;
struct crypto_instance *make_encrypt(struct crypto_algorithm *self,
UINT8 *key);
struct crypto_instance *make_decrypt(struct crypto_algorithm *self,
UINT8 *key);
struct crypto_instance * (*make_encrypt)(struct crypto_algorithm *self,
UINT8 *key);
struct crypto_instance * (*make_decrypt)(struct crypto_algorithm *self,
UINT8 *key);
struct hash_instance
......@@ -28,13 +28,15 @@ struct abstract_read
#define A_READ(f, buffer, length) (f)->read((f), (buffer), (length))
struct read_handler;
typedef struct read_handler * (*read_handler_f)(struct read_handler *closure,
struct abstract_read *read);
struct read_handler
struct read_handler (*handler)(struct read_handler *closure,
struct abstract_read *read);
read_handler_f handler;
#define READ_HANDLER(handler, read) ((handler)->handler((handler), (read)))
#define READ_HANDLER(h, read) ((h)->handler((h), (read)))
/* FIXME: What should writers return? Perhaps a new writer,
* analogous to read-handlers? */
......@@ -48,4 +50,13 @@ struct abstract_write
abstract_write_f write;
#define A_WRITE(f, packet) ((f)->write((f), (packet)))
/* A processor that passes its result on to another processor */
struct abstract_write_pipe
struct abstract_write super;
struct abstract_write *next;
......@@ -7,10 +7,10 @@
struct blocking_write_processor
struct packet_processor p;
struct abstract_write w;
int fd;
struct packet_processor *make_blocking_write_procesor(int fd);
struct abstract_write *make_blocking_write_procesor(int fd);
......@@ -12,13 +12,17 @@ struct client_callback
struct fd_callback c;
struct io_backend *backend;
UINT32 block_size;
struct lsh_string *id_comment;
struct fd_callback *make_client_callback(struct io_backend *b,
UINT32 block_size);
#if 0
struct client_session
struct read_handler handler;
UINT32 *
dnl Process this file with autoconf to produce a configure script.
dnl AC_INIT_AUTOMAKE(lsh, 1.0)
dnl Checks for programs.
/* crypto_common.h
/* FIXME: Perhaps cryptographic algoritms should be encapsulated into
* objects, to avoid passing a lot of extra state parameters? */
typedef void (*transform_function)(void *state,
UINT32 size, UINT8 *src, UINT8 *dst);
......@@ -23,16 +23,16 @@ static int do_debug(struct debug_processor *closure,
fprintf(closure->output, "\n");
return apply_processor(closure->, packet);
return A_WRITE(closure->, packet);
struct abstract_write *make_debug_processor(FILE *output,
struct abstract_write *continuation)
struct abstract_write *
make_debug_processor(struct abstract_write *continuation, FILE *output)
struct debug_processor *closure = xalloc(sizeof(struct debug_processor));
closure->c.p.f = (abstract_write_f) do_debug;
closure-> = continuation;
closure->super.super.write = (abstract_write_f) do_debug;
closure-> = continuation;
closure->output = output;
return (struct abstract_write *) closure;
......@@ -7,16 +7,16 @@
#include <stdio.h>
#include "transport.h"
#include "abstract_io.h"
struct debug_processor
struct abstract_write_pipe c;
struct abstract_write_pipe super;
FILE *output;
struct packet_processor *make_debug_processor(FILE *output,
struct packet_processor *continuation);
struct abstract_write *
make_debug_processor(struct abstract_write *continuation, FILE *output);
......@@ -26,8 +26,8 @@ static int do_encrypt(struct encrypt_processor *closure,
return apply_processor(closure->, new);
struct packet_processor *
make_encrypt_processor(struct packet_processor *continuation,
struct abstract_write *
make_packet_encrypt(struct abstract_write *continuation,
unsigned mac_size,
transform_function mac_function,
void *mac_state,
......@@ -44,7 +44,7 @@ make_encrypt_processor(struct packet_processor *continuation,
closure->encrypt_function = encrypt_function;
closure->encrypt_state = encrypt_state;
return (struct packet_processor *) closure;
return (struct abstract_write *) closure;
......@@ -7,23 +7,18 @@
#include "transport.h"
#include "crypto_common.h"
#include "abstract_crypto.h"
struct encrypt_processor
struct abstract_write_pipe c;
unsigned mac_size;
transform_function mac_function;
void *mac_state;
transform_function encrypt_function;
void *encrypt_state;
struct mac_instance *mac;
stryct crypto_instance *crypto;
struct packet_processor *
make_encrypt_processor(struct packet_processor *containing,
struct abstract_write *
make_encrypt_processor(struct abstract_write *continue,
unsigned mac_size,
transform_function mac_function,
void *mac_state,
This diff is collapsed.
/* Declarations for getopt.
Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef _GETOPT_H
#define _GETOPT_H 1
#ifdef __cplusplus
extern "C" {
/* For communication from `getopt' to the caller.
When `getopt' finds an option that takes an argument,
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
extern char *optarg;
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
and for communication between successive calls to `getopt'.
On entry to `getopt', zero means this is the first call; initialize.
When `getopt' returns -1, this is the index of the first of the
non-option elements that the caller should itself scan.
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
extern int optind;
/* Callers store zero here to inhibit the error message `getopt' prints
for unrecognized options. */
extern int opterr;
/* Set to an option character which was unrecognized. */
extern int optopt;
/* Describe the long-named options requested by the application.
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
of `struct option' terminated by an element containing a name which is
The field `has_arg' is:
no_argument (or 0) if the option does not take an argument,
required_argument (or 1) if the option requires an argument,
optional_argument (or 2) if the option takes an optional argument.
If the field `flag' is not NULL, it points to a variable that is set
to the value given in the field `val' when the option is found, but
left unchanged if the option is not found.
To have a long-named option do something other than set an `int' to
a compiled-in constant, such as set a value from `optarg', set the
option's `flag' field to zero and its `val' field to a nonzero
value (the equivalent single-letter option character, if there is
one). For long options that have a zero `flag' field, `getopt'
returns the contents of the `val' field. */
struct option
#if defined (__STDC__) && __STDC__
const char *name;
char *name;
/* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */
int has_arg;
int *flag;
int val;
/* Names for the values of the `has_arg' field of `struct option'. */
#define no_argument 0
#define required_argument 1
#define optional_argument 2
#if (defined (__STDC__) && __STDC__) || defined (__cplusplus)
#ifdef __cplusplus
/* SunOS4 declares getopt with the following prototype:
extern int getopt (int argc, const char *const *argv, const char *shortopts);
We cannot redeclare it when compiling C++ code. */
#define getopt(x,y,z) getopt_long(x, y, z, (const struct option *) 0, (int *) 0)
#else /* not __cplusplus */
#ifdef __GNU_LIBRARY__
/* Many other libraries have conflicting prototypes for getopt, with
differences in the consts, in stdlib.h. To avoid compilation
errors, only prototype getopt for the GNU C library. */
extern int getopt (int argc, char *const *argv, const char *shortopts);
#else /* not __GNU_LIBRARY__ */
extern int getopt ();
#endif /* __GNU_LIBRARY__ */
#endif /* __cplusplus */
extern int getopt_long (int argc, char *const *argv, const char *shortopts,
const struct option *longopts, int *longind);
extern int getopt_long_only (int argc, char *const *argv,
const char *shortopts,
const struct option *longopts, int *longind);
/* Internal only. Users should not call this directly. */
extern int _getopt_internal (int argc, char *const *argv,
const char *shortopts,
const struct option *longopts, int *longind,
int long_only);
#else /* not __STDC__ */
extern int getopt ();
extern int getopt_long ();
extern int getopt_long_only ();
extern int _getopt_internal ();
#endif /* __STDC__ */
#ifdef __cplusplus
#endif /* getopt.h */
......@@ -8,7 +8,7 @@
struct server_keyexchange
struct packet_processor p;
struct abstract_write p;
......@@ -3,7 +3,10 @@
* client main program
#include <getopt.h>
#include <stdio.h>
#include <locale.h>
#include "getopt.h"
#include "io.h"
#include "werror.h"
......@@ -25,7 +28,7 @@ int main(int argc, char **argv)
char *host = NULL;
char *port = "ssh";
int verbose;
/* int verbose; */
int option;
struct sockaddr_in remote;
......@@ -61,18 +64,10 @@ int main(int argc, char **argv)
struct client_callback connected = {
{ (fd_callback_f) client_initiate },
io_connect(&backend, &remote, NULL,
make_client_callback(backend, BLOCK_SIZE));
io_connect(&backend, &remote, NULL,
make_client_callback(&backend, BLOCK_SIZE));
return 0;
......@@ -11,21 +11,21 @@
struct dispatch_assoc
int msg;
struct packet_processor *f;
struct abstract_write *f;
struct dispatch_processor
struct packet_dispatch
struct packet_processor p;
struct packet_processor *other;
struct abstract_write p;
struct abstract_write *other;
unsigned table_size;
/* Should be sorted by message number */
struct dispatch_assoc *dispatch_table;
struct packet_processor *
make_dispatch_processor(unsigned size,
struct dispatch_assoc *table,
struct packet_processor *other);
struct abstract_write *
make_packet_dispatch(unsigned size,
struct dispatch_assoc *table,
struct abstract_write *other);
......@@ -13,7 +13,7 @@ typedef void (*random_function)(void *state, UINT32 length, UINT8 *dst);
/* Input to the processor is a packet with the payload. Output is a
* packet containing a formatted ssh packet (with correct byte order,
* etc). */
struct pad_processor
struct packet_pad
struct abstract_write_pipe c;
......@@ -23,8 +23,8 @@ struct pad_processor
void *state;
struct packet_processor *
make_pad_processor(struct packet_processor *continuation,
struct abstract_write *
make_pad_processor(struct abstract_write *continuation,
unsigned block_size,
random_function random,
void *state);
......@@ -38,7 +38,7 @@ struct format_processor
struct abstract_write_pipe c;
struct packet_processor *make_pad_processor(packet_processor *continuation);
struct abstract_write *make_packet_pad(abstract_write *continuation);
......@@ -2,11 +2,15 @@
#include <string.h>
#include "read_line.h"
#include "werror.h"
#include "xalloc.h"
struct string_read
struct abstract_read a;
struct abstract_read super;
struct read_line *line;
UINT32 index;
......@@ -17,7 +21,7 @@ static int do_string_read(struct string_read *closure,
UINT32 left = closure->line->pos - closure->index;
UINT32 to_read = MIN(length, left);
memcpy(buffer, closure->buffer + index, to_read);
memcpy(buffer, closure->line->buffer + closure->index, to_read);
closure->index += to_read;
return to_read;
......@@ -26,14 +30,13 @@ static int do_string_read(struct string_read *closure,
static struct read_handler *do_read_line(struct read_line *closure,
struct abstract_read *read)
int n = A_READ(read, closure->line, MAX_LINE - closure->pos);
int n = A_READ(read, closure->buffer, MAX_LINE - closure->pos);
UINT8 *eol;
UINT32 length;
struct read_handler *next;
if (n<0)
werror("do_read_line: read() failed, %s\n", strerror(errno));
return 0;
closure->pos += n;
......@@ -45,9 +48,11 @@ static struct read_handler *do_read_line(struct read_line *closure,
/* eol points at the newline character. end points at the
* character terminating the line, which may be a carriage
* return preceeding the newline. */
UINT8 *end = ( (eol > closure->buffer)
&& (eol[-1] == '\r'))
? eol - 1 : eol;
UINT8 *end = eol;
if ( (eol > closure->buffer)
&& (eol[-1] == '\r'))
length = end - closure->buffer;
......@@ -58,9 +63,9 @@ static struct read_handler *do_read_line(struct read_line *closure,
/* Read another line */
/* Number of characters that have been processed */
UINT32 done = eol - closure->buffer + 1;
UINT32 left = buffer->pos - done;
UINT32 left = closure->pos - done;
memcpy(closure->buffer, buffer + done, left);
memcpy(closure->buffer, closure->buffer + done, left);
closure->pos = left;
......@@ -73,8 +78,8 @@ static struct read_handler *do_read_line(struct read_line *closure,
{ { (abstract_read_f) do_string_read },
0 };
while(next && (read->index < buffer->pos))
next = READ_HANDLER(next, &read);
while(next && (read.index < closure->pos))
next = READ_HANDLER(next, &read.super);
/* No data left */
......@@ -90,3 +95,17 @@ static struct read_handler *do_read_line(struct read_line *closure,
return &(closure->super);
struct read_handler *make_read_line(struct line_handler *handler)
struct read_line *closure = xalloc(sizeof(struct read_line));
closure->super.handler = (read_handler_f) do_read_line;
closure->pos = 0;
closure->handler = handler;
return (struct read_handler *) closure;
......@@ -13,16 +13,16 @@
struct line_handler;
typedef (struct read_handler *line_handler_f)(struct line_handler *closure,
UINT32 length,
UINT8 *line);
typedef struct read_handler * (*line_handler_f)(struct line_handler *closure,
UINT32 length,
UINT8 *line);
struct line_handler
line_handler_f handler;
#define PROCESS_LINE(handler, length, line) \
((handler)->handler((handler), (length), (line)))
#define PROCESS_LINE(h, length, line) \
((h)->handler((h), (length), (line)))
struct read_line
......@@ -34,4 +34,6 @@ struct read_line
struct line_handler *handler;
struct read_handler *make_read_line(struct line_handler *handler);
......@@ -2,15 +2,24 @@
#include <errno.h>
#include <string.h>
#include "read_packet.h"
#include "werror.h"
#include "format.h"
#include "xalloc.h"
#include "io.h"
#include "crypto.h"
#define WAIT_HEADER 0
#define WAIT_MAC 2
static struct read_handler *do_read_packet(struct read_packet *closure,
static struct read_handler *do_read_packet(struct read_handler *c,
struct abstract_read *read)
struct read_packet *closure = (struct read_packet *) c;
......@@ -22,14 +31,15 @@ static struct read_handler *do_read_packet(struct read_packet *closure,
if (!closure->buffer)
closure->buffer = lsh_string_alloc(crypt->block_size);
= lsh_string_alloc(closure->crypto->block_size);
closure->pos = 0;