Commit 0cc7ad81 authored by Niels Möller's avatar Niels Möller
Browse files

Fixed compilation problems.

Rev: src/bignum.c:1.3
Rev: src/bignum.h:1.3
Rev: src/pad.c:1.4
Rev: src/pad.h:1.3
Rev: src/parse.c:1.4
Rev: src/parse.h:1.4
Rev: src/transport.c:1.2
Rev: src/unpad.c:1.2
Rev: src/unpad.h:1.3
Rev: src/void.c:1.2
parent 2be1a000
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "bignum.h" #include "bignum.h"
#include "werror.h" #include "werror.h"
void parse_bignum(bignum *n, UINT32 length, UINT8 *data) void bignum_parse(bignum *n, UINT32 length, UINT8 *data)
{ {
int negative = length && (*data & 0x80); int negative = length && (*data & 0x80);
int i; int i;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#define bignum MP_INT #define bignum MP_INT
void parse_bignum(bignum *n, UINT32 length, UINT8 *data); void bignum_parse(bignum *n, UINT32 length, UINT8 *data);
UINT32 bignum_format_length(bignum *n); UINT32 bignum_format_length(bignum *n);
UINT32 bignum_format(bignum *n, UINT8 *data); UINT32 bignum_format(bignum *n, UINT8 *data);
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
*/ */
#include "pad.h" #include "pad.h"
#include "xalloc.h"
#include <assert.h>
static int do_pad(struct pad_processor *closure, static int do_pad(struct pad_processor *closure,
struct simple_packet *packet) struct simple_packet *packet)
...@@ -20,7 +22,7 @@ static int do_pad(struct pad_processor *closure, ...@@ -20,7 +22,7 @@ static int do_pad(struct pad_processor *closure,
* ( (8 + packet->length) / closure->block_size); * ( (8 + packet->length) / closure->block_size);
padding = new_size - packet->length - 5; padding = new_size - packet->length - 5;
assert(ssh->padding_length >= 4); assert(padding >= 4);
new = simple_packet_alloc(new_size); new = simple_packet_alloc(new_size);
...@@ -30,7 +32,7 @@ static int do_pad(struct pad_processor *closure, ...@@ -30,7 +32,7 @@ static int do_pad(struct pad_processor *closure,
ssh->padding_length = padding; ssh->padding_length = padding;
#endif #endif
WRITE_INT32(new->data, new_size - 4); WRITE_UINT32(new->data, new_size - 4);
new->data[4] = padding; new->data[4] = padding;
memcpy(new->data + 5, packet->data, packet->length); memcpy(new->data + 5, packet->data, packet->length);
...@@ -38,19 +40,20 @@ static int do_pad(struct pad_processor *closure, ...@@ -38,19 +40,20 @@ static int do_pad(struct pad_processor *closure,
simple_packet_free(packet); simple_packet_free(packet);
return apply_processor(closure->c->next, new); return apply_processor(closure->c.next, new);
} }
struct packet_processor *make_pad_processor(packet_processor *continuation, struct packet_processor *
unsigned block_size, make_pad_processor(struct packet_processor *continuation,
random_function random, unsigned block_size,
void *state) random_function random,
void *state)
{ {
struct pad_processor *closure = xalloc(sizeof(struct pad_processor)); struct pad_processor *closure = xalloc(sizeof(struct pad_processor));
closure->c->p->f = (raw_processor_function) do_pad; closure->c.p.f = (raw_processor_function) do_pad;
closure->c->next = continuation; closure->c.next = continuation;
closure->block_size = block_size; closure->block_size = block_size;
closure->random = random; closure->random = random;
closure->state = state; closure->state = state;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "transport.h" #include "transport.h"
typedef (*random_function)(void *state, UINT32 length, UINT8 *dst); typedef void (*random_function)(void *state, UINT32 length, UINT8 *dst);
/* Input to the processor is a packet with the payload. Output is a /* Input to the processor is a packet with the payload. Output is a
* packet containing a formatted ssh packet (with correct byte order, * packet containing a formatted ssh packet (with correct byte order,
...@@ -23,10 +23,11 @@ struct pad_processor ...@@ -23,10 +23,11 @@ struct pad_processor
void *state; void *state;
}; };
struct packet_processor *make_pad_processor(packet_processor *continuation, struct packet_processor *
unsigned block_size, make_pad_processor(struct packet_processor *continuation,
random_function random, unsigned block_size,
void *state); random_function random,
void *state);
#if 0 #if 0
/* Input to the processor is a packet with the payload. Output is a /* Input to the processor is a packet with the payload. Output is a
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
*/ */
#include "parse.h" #include "parse.h"
#include "transport.h"
void simple_buffer_init(struct simple_buffer *buffer, void simple_buffer_init(struct simple_buffer *buffer,
UINT32 capacity, UINT8 *data) UINT32 capacity, UINT8 *data)
...@@ -12,16 +13,16 @@ void simple_buffer_init(struct simple_buffer *buffer, ...@@ -12,16 +13,16 @@ void simple_buffer_init(struct simple_buffer *buffer,
buffer->data = data; buffer->data = data;
} }
#define BUFFER_LEFT (buffer->capacity - buffer->pos) #define LEFT (buffer->capacity - buffer->pos)
#define HERE (buffer->data + buffer->pos) #define HERE (buffer->data + buffer->pos)
#define ADVANCE(n) (buffer->pos += (n)) #define ADVANCE(n) (buffer->pos += (n))
int parse_uint32(struct simple_buffer *buffer, UINT32 *result) int parse_uint32(struct simple_buffer *buffer, UINT32 *result)
{ {
if (BUFFER_LEFT < 4) if (LEFT < 4)
return 0; return 0;
*result = READ_INT32(HERE); *result = READ_UINT32(HERE);
ADVANCE(4); ADVANCE(4);
return 1; return 1;
} }
...@@ -34,12 +35,13 @@ int parse_string(struct simple_buffer *buffer, ...@@ -34,12 +35,13 @@ int parse_string(struct simple_buffer *buffer,
if (!parse_uint32(buffer, &l)) if (!parse_uint32(buffer, &l))
return 0; return 0;
if (BUFFER_LEFT < length) if (LEFT < l)
return 0; return 0;
*length = l; *length = l;
*start = HERE; *start = HERE;
ADVANCE(l); ADVANCE(l);
return 1;
} }
/* Initializes subbuffer to parse a string from buffer */ /* Initializes subbuffer to parse a string from buffer */
...@@ -56,7 +58,7 @@ int parse_sub_buffer(struct simple_buffer *buffer, ...@@ -56,7 +58,7 @@ int parse_sub_buffer(struct simple_buffer *buffer,
return 1; return 1;
} }
int parse_uint8(struct simple_buffer *buffer, uint8 *result) int parse_uint8(struct simple_buffer *buffer, UINT8 *result)
{ {
if (!LEFT) if (!LEFT)
return 0; return 0;
...@@ -74,7 +76,7 @@ int parse_bignum(struct simple_buffer *buffer, bignum *result) ...@@ -74,7 +76,7 @@ int parse_bignum(struct simple_buffer *buffer, bignum *result)
if (!parse_string(buffer, &length, &digits)) if (!parse_string(buffer, &length, &digits))
return 0; return 0;
parse_bignum(result, length, digits); bignum_parse(result, length, digits);
return 1; return 1;
} }
...@@ -92,21 +94,21 @@ int parse_next_atom(struct simple_buffer *buffer, int *result) ...@@ -92,21 +94,21 @@ int parse_next_atom(struct simple_buffer *buffer, int *result)
if (buffer->pos > buffer->capacity) if (buffer->pos > buffer->capacity)
return -1; return -1;
for(i = 0; i < left; i++) for(i = 0; i < LEFT; i++)
if (HERE[i] == ',') if (HERE[i] == ',')
{ {
*result = lookup_atom(HERE, i); *result = lookup_atom(HERE, i);
ADVANCE[i+1]; ADVANCE(i+1);
return 1; return 1;
} }
*result = lookup(HERE, i); *result = lookup_atom(HERE, i);
ADVANCE(i+1); /* Beyond end of buffer */ ADVANCE(i+1); /* Beyond end of buffer */
return 1; return 1;
} }
/* Returns success (i.e. 1) iff there is no data left */ /* Returns success (i.e. 1) iff there is no data left */
int parse_eod(struct simple_buffer *buffer); int parse_eod(struct simple_buffer *buffer)
{ {
return !LEFT; return !LEFT;
} }
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
/* Simple buffer */ /* Simple buffer */
struct simple_buffer struct simple_buffer
{ {
UNIT32 capacity; UINT32 capacity;
UINT32 pos; UINT32 pos;
UINT8 *data; UINT8 *data;
}; };
...@@ -27,7 +27,7 @@ int parse_string(struct simple_buffer *buffer, ...@@ -27,7 +27,7 @@ int parse_string(struct simple_buffer *buffer,
/* Initializes subbuffer to parse a string from buffer */ /* Initializes subbuffer to parse a string from buffer */
int parse_sub_buffer(struct simple_buffer *buffer, int parse_sub_buffer(struct simple_buffer *buffer,
struct simple_buffer *subbuffer); struct simple_buffer *subbuffer);
int parse_uint8(struct simple_buffer *buffer, uint8 *result); int parse_uint8(struct simple_buffer *buffer, UINT8 *result);
#define parse_boolean parse_uint8 #define parse_boolean parse_uint8
int parse_bignum(struct simple_buffer *buffer, bignum *result); int parse_bignum(struct simple_buffer *buffer, bignum *result);
......
/* transport.c /* transport.c
*
*/ */
#include "transport.h"
#include "xalloc.h"
struct simple_packet *simple_packet_alloc(UINT32 length) struct simple_packet *simple_packet_alloc(UINT32 length)
{ {
struct simple_packet *packet = xalloc(sizeof(struct simple_packet) - 1 + size); struct simple_packet *packet
packet->length = size; = xalloc(sizeof(struct simple_packet) - 1 + length);
packet->length = length;
return packet; return packet;
} }
void simple_packet_free(struct simple_packet *packet); void simple_packet_free(struct simple_packet *packet)
{ {
free(packet); free(packet);
} }
#if 0
void simple_buffer_init(struct simple_buffer *buffer, void simple_buffer_init(struct simple_buffer *buffer,
UINT32 capacity, UINT8 *data) UINT32 capacity, UINT8 *data)
{ {
...@@ -35,6 +41,7 @@ UINT32 simple_buffer_avail(struct simple_buffer *buffer) ...@@ -35,6 +41,7 @@ UINT32 simple_buffer_avail(struct simple_buffer *buffer)
{ {
return buffer->capacity - buffer->pos; return buffer->capacity - buffer->pos;
} }
#endif
int apply_processor(struct packet_processor *closure, int apply_processor(struct packet_processor *closure,
struct simple_packet *packet) struct simple_packet *packet)
......
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
* *
*/ */
static int do_unpad(struct pad_processor *closure, #include "unpad.h"
#include "xalloc.h"
static int do_unpad(struct unpad_processor *closure,
struct simple_packet *packet) struct simple_packet *packet)
{ {
UINT8 padding_length; UINT8 padding_length;
...@@ -26,15 +29,16 @@ static int do_unpad(struct pad_processor *closure, ...@@ -26,15 +29,16 @@ static int do_unpad(struct pad_processor *closure,
simple_packet_free(packet); simple_packet_free(packet);
return apply_continuation(closure->next, new); return apply_processor(closure->c.next, new);
} }
struct packet_processor *make_pad_processor(packet_processor *continuation) struct packet_processor *
make_unpad_processor(struct packet_processor *continuation)
{ {
struct pad_processor *closure = xalloc(sizeof(struct pad_processor)); struct unpad_processor *closure = xalloc(sizeof(struct unpad_processor));
closure->c->p->f = (raw_processor_function) do_unpad; closure->c.p.f = (raw_processor_function) do_unpad;
closure->c->next = continuation; closure->c.next = continuation;
return (struct packet_processor *) closure; return (struct packet_processor *) closure;
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#ifndef LSH_UNPAD_H_INCLUDED #ifndef LSH_UNPAD_H_INCLUDED
#define LSH_UNPAD_H_INCLUDED #define LSH_UNPAD_H_INCLUDED
#include "tranport.h" #include "transport.h"
/* Input to the processor is a padded payload. */ /* Input to the processor is a padded payload. */
struct unpad_processor struct unpad_processor
...@@ -14,6 +14,7 @@ struct unpad_processor ...@@ -14,6 +14,7 @@ struct unpad_processor
struct chained_processor c; struct chained_processor c;
}; };
struct packet_processor *make_unpad_processor(packet_processor *continuation); struct packet_processor *
make_unpad_processor(struct packet_processor *continuation);
#endif /* LSH_UNPAD_H_INCLUDED */ #endif /* LSH_UNPAD_H_INCLUDED */
...@@ -3,8 +3,9 @@ ...@@ -3,8 +3,9 @@
*/ */
#include "void.h" #include "void.h"
#include "xalloc.h"
static int do_ignore(struct pad_processor *closure, static int do_ignore(struct void_processor *closure,
struct simple_packet *packet) struct simple_packet *packet)
{ {
free(packet); free(packet);
...@@ -15,7 +16,7 @@ struct packet_processor *make_void_processor() ...@@ -15,7 +16,7 @@ struct packet_processor *make_void_processor()
{ {
struct void_processor *closure = xalloc(sizeof(struct void_processor)); struct void_processor *closure = xalloc(sizeof(struct void_processor));
closure->p->f = (raw_processor_function) do_ignore; closure->p.f = (raw_processor_function) do_ignore;
return (struct packet_processor *) closure; return (struct packet_processor *) closure;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment