Commit 821e936a authored by Niels Möller's avatar Niels Möller

Changed the handling of return values.

Rev: src/client.c:1.22
Rev: src/client_keyexchange.c:1.14
Rev: src/keyexchange.c:1.22
Rev: src/read_line.c:1.10
Rev: src/read_packet.c:1.23
Rev: src/server.c:1.15
Rev: src/server_keyexchange.c:1.12
Rev: src/service.h:1.4
Rev: src/session.h:1.8
Rev: src/userauth.h:1.4
parent 07a2ed25
...@@ -80,12 +80,12 @@ static int client_initiate(struct fd_callback **c, ...@@ -80,12 +80,12 @@ static int client_initiate(struct fd_callback **c,
res = A_WRITE(connection->raw, res = A_WRITE(connection->raw,
ssh_format("%lS\r\n", connection->client_version)); ssh_format("%lS\r\n", connection->client_version));
if (LSH_PROBLEMP(res)) if (LSH_CLOSEDP(res))
return res; return res;
return initiate_keyexchange(connection, CONNECTION_CLIENT, return res | initiate_keyexchange(connection, CONNECTION_CLIENT,
MAKE_KEXINIT(closure->init), MAKE_KEXINIT(closure->init),
NULL); NULL);
} }
struct client_line_handler struct client_line_handler
...@@ -207,3 +207,4 @@ struct close_callback *make_client_close_handler(void) ...@@ -207,3 +207,4 @@ struct close_callback *make_client_close_handler(void)
return c; return c;
} }
...@@ -85,7 +85,7 @@ static int do_handle_dh_reply(struct packet_handler *c, ...@@ -85,7 +85,7 @@ static int do_handle_dh_reply(struct packet_handler *c,
* handler for recieving the newkeys message. */ * handler for recieving the newkeys message. */
res = A_WRITE(connection->write, ssh_format("%c", SSH_MSG_NEWKEYS)); res = A_WRITE(connection->write, ssh_format("%c", SSH_MSG_NEWKEYS));
if (LSH_PROBLEMP(res)) if (LSH_CLOSEDP(res))
return res; return res;
/* Record session id */ /* Record session id */
...@@ -110,11 +110,11 @@ static int do_handle_dh_reply(struct packet_handler *c, ...@@ -110,11 +110,11 @@ static int do_handle_dh_reply(struct packet_handler *c,
connection->dispatch[SSH_MSG_KEXDH_REPLY] = connection->fail; connection->dispatch[SSH_MSG_KEXDH_REPLY] = connection->fail;
connection->kex_state = KEX_STATE_NEWKEYS; connection->kex_state = KEX_STATE_NEWKEYS;
res = send_verbose(connection->write, "Key exchange successful!", 0); res |= send_verbose(connection->write, "Key exchange successful!", 0);
if (LSH_PROBLEMP(res)) if (LSH_CLOSEDP(res))
return res; return res;
return SERVICE_INIT(closure->finished, connection); return res | SERVICE_INIT(closure->finished, connection);
} }
static int do_init_dh(struct keyexchange_algorithm *c, static int do_init_dh(struct keyexchange_algorithm *c,
...@@ -148,15 +148,15 @@ static int do_init_dh(struct keyexchange_algorithm *c, ...@@ -148,15 +148,15 @@ static int do_init_dh(struct keyexchange_algorithm *c,
/* Send client's message */ /* Send client's message */
res = A_WRITE(connection->write, dh_make_client_msg(&dh->dh)); res = A_WRITE(connection->write, dh_make_client_msg(&dh->dh));
if (LSH_PROBLEMP(res)) if (LSH_CLOSEDP(res))
return res; return res | LSH_FAIL;
/* Install handler */ /* Install handler */
connection->dispatch[SSH_MSG_KEXDH_REPLY] = &dh->super; connection->dispatch[SSH_MSG_KEXDH_REPLY] = &dh->super;
connection->kex_state = KEX_STATE_IN_PROGRESS; connection->kex_state = KEX_STATE_IN_PROGRESS;
return LSH_OK | LSH_GOON; return res | LSH_OK | LSH_GOON;
} }
......
...@@ -150,8 +150,8 @@ int initiate_keyexchange(struct ssh_connection *connection, ...@@ -150,8 +150,8 @@ int initiate_keyexchange(struct ssh_connection *connection,
res = A_WRITE(connection->write, lsh_string_dup(s)); res = A_WRITE(connection->write, lsh_string_dup(s));
if (!LSH_PROBLEMP(res) && first_packet) if (!LSH_CLOSEDP(res) && first_packet)
return A_WRITE(connection->write, first_packet); return res | A_WRITE(connection->write, first_packet);
else else
return res; return res;
} }
...@@ -179,7 +179,7 @@ int disconnect_kex_failed(struct ssh_connection *connection, char *msg) ...@@ -179,7 +179,7 @@ int disconnect_kex_failed(struct ssh_connection *connection, char *msg)
{ {
return A_WRITE(connection->write, return A_WRITE(connection->write,
format_disconnect(SSH_DISCONNECT_KEY_EXCHANGE_FAILED, format_disconnect(SSH_DISCONNECT_KEY_EXCHANGE_FAILED,
msg)); msg, ""));
} }
static int do_handle_kexinit(struct packet_handler *c, static int do_handle_kexinit(struct packet_handler *c,
...@@ -196,12 +196,13 @@ static int do_handle_kexinit(struct packet_handler *c, ...@@ -196,12 +196,13 @@ static int do_handle_kexinit(struct packet_handler *c,
void **algorithms; void **algorithms;
int i; int i;
int res = 0;
MDEBUG(closure); MDEBUG(closure);
MDEBUG(msg); MDEBUG(msg);
if (!msg) if (!msg)
return 0; return LSH_FAIL | LSH_DIE;
/* Save value for later signing */ /* Save value for later signing */
connection->literal_kexinits[!closure->type] = packet; connection->literal_kexinits[!closure->type] = packet;
...@@ -211,7 +212,6 @@ static int do_handle_kexinit(struct packet_handler *c, ...@@ -211,7 +212,6 @@ static int do_handle_kexinit(struct packet_handler *c,
/* Have we sent a kexinit message? */ /* Have we sent a kexinit message? */
if (!connection->kexinits[closure->type]) if (!connection->kexinits[closure->type])
{ {
int res;
struct lsh_string *packet; struct lsh_string *packet;
struct kexinit *sent = MAKE_KEXINIT(closure->init); struct kexinit *sent = MAKE_KEXINIT(closure->init);
connection->kexinits[closure->type] = sent; connection->kexinits[closure->type] = sent;
...@@ -219,7 +219,7 @@ static int do_handle_kexinit(struct packet_handler *c, ...@@ -219,7 +219,7 @@ static int do_handle_kexinit(struct packet_handler *c,
connection->literal_kexinits[closure->type] = lsh_string_dup(packet); connection->literal_kexinits[closure->type] = lsh_string_dup(packet);
res = A_WRITE(connection->write, packet); res = A_WRITE(connection->write, packet);
if (LSH_PROBLEMP(res)) if (LSH_CLOSEDP(res))
return res; return res;
} }
...@@ -250,7 +250,7 @@ static int do_handle_kexinit(struct packet_handler *c, ...@@ -250,7 +250,7 @@ static int do_handle_kexinit(struct packet_handler *c,
disconnect_kex_failed(connection, disconnect_kex_failed(connection,
"No common key exchange method.\r\n"); "No common key exchange method.\r\n");
return LSH_FAIL | LSH_CLOSE; return res | LSH_FAIL | LSH_CLOSE;
} }
} }
hostkey_algorithm hostkey_algorithm
...@@ -266,7 +266,7 @@ static int do_handle_kexinit(struct packet_handler *c, ...@@ -266,7 +266,7 @@ static int do_handle_kexinit(struct packet_handler *c,
if (!parameters[i]) if (!parameters[i])
{ {
disconnect_kex_failed(connection, ""); disconnect_kex_failed(connection, "");
return LSH_FAIL | LSH_CLOSE; return res | LSH_FAIL | LSH_CLOSE;
} }
} }
...@@ -275,13 +275,14 @@ static int do_handle_kexinit(struct packet_handler *c, ...@@ -275,13 +275,14 @@ static int do_handle_kexinit(struct packet_handler *c,
for (i = 0; i<KEX_PARAMETERS; i++) for (i = 0; i<KEX_PARAMETERS; i++)
algorithms[i] = ALIST_GET(closure->algorithms, parameters[i]); algorithms[i] = ALIST_GET(closure->algorithms, parameters[i]);
return KEYEXCHANGE_INIT( (struct keyexchange_algorithm *) return res
ALIST_GET(closure->algorithms, kex_algorithm), | KEYEXCHANGE_INIT( (struct keyexchange_algorithm *)
connection, ALIST_GET(closure->algorithms, kex_algorithm),
closure->finished, connection,
hostkey_algorithm, closure->finished,
ALIST_GET(closure->algorithms, hostkey_algorithm), hostkey_algorithm,
algorithms); ALIST_GET(closure->algorithms, hostkey_algorithm),
algorithms);
} }
struct packet_handler *make_kexinit_handler(int type, struct packet_handler *make_kexinit_handler(int type,
......
...@@ -131,7 +131,7 @@ static int do_read_line(struct read_handler **h, ...@@ -131,7 +131,7 @@ static int do_read_line(struct read_handler **h,
while(next && (read.index < closure->pos)) while(next && (read.index < closure->pos))
{ {
res = READ_HANDLER(next, &read.super); res = READ_HANDLER(next, &read.super);
if (LSH_PROBLEMP(res)) if (LSH_CLOSEDP(res))
return res; return res;
} }
} }
......
...@@ -290,7 +290,7 @@ static int do_read_packet(struct read_handler **h, ...@@ -290,7 +290,7 @@ static int do_read_packet(struct read_handler **h,
closure->state = WAIT_START; closure->state = WAIT_START;
res = A_WRITE(closure->handler, packet); res = A_WRITE(closure->handler, packet);
if (LSH_PROBLEMP(res)) if (LSH_ACTIONP(res))
return res; return res;
break; break;
} }
......
...@@ -80,12 +80,12 @@ static int server_initiate(struct fd_callback **c, ...@@ -80,12 +80,12 @@ static int server_initiate(struct fd_callback **c,
res = A_WRITE(connection->raw, res = A_WRITE(connection->raw,
ssh_format("%lS\r\n", connection->server_version)); ssh_format("%lS\r\n", connection->server_version));
if (LSH_PROBLEMP(res)) if (LSH_CLOSEDP(res))
return res; return res;
return initiate_keyexchange(connection, CONNECTION_SERVER, return res | initiate_keyexchange(connection, CONNECTION_SERVER,
MAKE_KEXINIT(closure->init), MAKE_KEXINIT(closure->init),
NULL); NULL);
} }
struct server_line_handler struct server_line_handler
......
...@@ -73,14 +73,14 @@ static int do_handle_dh_init(struct packet_handler *c, ...@@ -73,14 +73,14 @@ static int do_handle_dh_init(struct packet_handler *c,
res = A_WRITE(connection->write, dh_make_server_msg(&closure->dh, res = A_WRITE(connection->write, dh_make_server_msg(&closure->dh,
closure->signer)); closure->signer));
if (LSH_PROBLEMP(res)) if (LSH_CLOSEDP(res))
return res; return res;
/* Send a newkeys message, and install a handler for recieving the /* Send a newkeys message, and install a handler for recieving the
* newkeys message. */ * newkeys message. */
res = A_WRITE(connection->write, ssh_format("%c", SSH_MSG_NEWKEYS)); res |= A_WRITE(connection->write, ssh_format("%c", SSH_MSG_NEWKEYS));
if (LSH_PROBLEMP(res)) if (LSH_CLOSEDP(res))
return res; return res;
/* Record session id */ /* Record session id */
...@@ -105,11 +105,11 @@ static int do_handle_dh_init(struct packet_handler *c, ...@@ -105,11 +105,11 @@ static int do_handle_dh_init(struct packet_handler *c,
connection->kex_state = KEX_STATE_NEWKEYS; connection->kex_state = KEX_STATE_NEWKEYS;
connection->dispatch[SSH_MSG_KEXDH_INIT] = connection->fail; connection->dispatch[SSH_MSG_KEXDH_INIT] = connection->fail;
res = send_verbose(connection->write, "Key exchange successful!", 0); res |= send_verbose(connection->write, "Key exchange successful!", 0);
if (LSH_PROBLEMP(res)) if (LSH_CLOSEDP(res))
return res; return res;
return SERVICE_INIT(closure->finished, connection); return res | SERVICE_INIT(closure->finished, connection);
} }
static int do_init_dh(struct keyexchange_algorithm *c, static int do_init_dh(struct keyexchange_algorithm *c,
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#ifndef LSH_SERVICE_H_INCLUDED #ifndef LSH_SERVICE_H_INCLUDED
#define LSH_SERVICE_H_INCLUDED #define LSH_SERVICE_H_INCLUDED
#include "alist.h"
#include "connection.h" #include "connection.h"
/* Used on both client and server side */ /* Used on both client and server side */
...@@ -43,4 +44,8 @@ struct lsh_string *format_service_request(int name); ...@@ -43,4 +44,8 @@ struct lsh_string *format_service_request(int name);
int request_service(int name, struct ssh_service * service); int request_service(int name, struct ssh_service * service);
struct lsh_string *format_service_accept(int name);
struct ssh_service *make_meta_service(struct alist *services);
#endif /* LSH_SERVICE_H_INCLUDED */ #endif /* LSH_SERVICE_H_INCLUDED */
/* session.h /* session.h
* *
* Manage the ssh-connection service. * Manage the ssh-connection service.
*
* $Id$
*/
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1998 Niels Möller
*
* 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.
*/ */
#ifndef LSH_SESSION_H_INCLUDED #ifndef LSH_SESSION_H_INCLUDED
#define LSH_SESSION_H_INCLUDED #define LSH_SESSION_H_INCLUDED
#include "alist.h"
#include "connection.h" #include "connection.h"
#include "channel.h" #include "channel.h"
#include "parse.h"
struct ssh_session
{
#if 0 #if 0
/* FIXME: This is relevant only for the server side. It's probably struct ssh_service *make_session_service(struct alist *global_requests,
* better to store this in the connection struct */ struct alist *channel_requests);
uid_t user; /* Authenticated user */
#endif #endif
/* Channels are indexed by local number */
struct channel **channels;
/* Allocation of local channel numbers is managed using the same *
* method as is traditionally used for allocation of unix file
* descriptors. */
UINT32 allocated_channels;
UINT32 next_channel;
UINT32 used_channels;
UINT32 max_channels; /* Max number of channels allowed */
};
/* SSH_MSG_GLOBAL_REQUEST */
struct global_request
{
struct lsh_object *header;
int (*handler)(struct global_request *closure,
int want_reply,
struct simple_buffer *args);
};
#define GLOBAL_REQUEST(c, w, a) ((c)->handler((c), (w), (a)))
/* SSH_MSG_CHANNEL_OPEN */
struct channel_open
{
struct lsh_object *header;
int (*handler)(struct channel_open *closure,
UINT32 channel_number, /* Remote channel number */
UINT32 rec_window_size,
UINT32 rec_max_packet,
struct simple_buffer *args);
};
#define CHANNEL_OPEN(c, n, w, m, a) \
((c)->handler((c), (n), (w), (m), (a)))
/* SSH_MSH_CHANNEL_REQUEST */
struct channel_request
{
struct lsh_object *header;
int (*handler)(struct channel_request *closure,
struct ssh_channel *channel,
int want_reply;
struct simple_buffer *args);
};
#define CHANNEL_REQUEST(s, c, w, a) \
((s)->handler((s), (c), (w), (a)))
#endif /* LSH_SESSION_H_INCLUDED */ #endif /* LSH_SESSION_H_INCLUDED */
...@@ -24,7 +24,8 @@ ...@@ -24,7 +24,8 @@
#ifndef LSH_USERAUTH_H_INCLUDED #ifndef LSH_USERAUTH_H_INCLUDED
#define LSH_USERAUTH_H_INCLUDED #define LSH_USERAUTH_H_INCLUDED
#include "lsh_types.h" #include "parse.h"
#include "service.h"
/* Returns 0 if the request is somehow invalid. Otheerwise, returns 1, /* Returns 0 if the request is somehow invalid. Otheerwise, returns 1,
* and sets SERVICE non-NULL iff access is granted. */ * and sets SERVICE non-NULL iff access is granted. */
...@@ -35,8 +36,9 @@ struct userauth ...@@ -35,8 +36,9 @@ struct userauth
{ {
struct lsh_object header; struct lsh_object header;
int (*authenticate)(struct userauth *self, int (*authenticate)(struct userauth *closure,
lsh_string *user, /* The name is consumed by this function */
struct lsh_string *username,
int requested_service, int requested_service,
struct simple_buffer *args, struct simple_buffer *args,
struct ssh_service **service); struct ssh_service **service);
...@@ -45,8 +47,8 @@ struct userauth ...@@ -45,8 +47,8 @@ struct userauth
#define AUTHENTICATE(s, u, r, a, g) \ #define AUTHENTICATE(s, u, r, a, g) \
((s)->authenticate((s), (u), (r), (a), (g))) ((s)->authenticate((s), (u), (r), (a), (g)))
struct ssh_service *make_client_userauth(struct lsh_string username, struct ssh_service *make_client_userauth(struct lsh_string *username,
int service_name, int service_name,
struct ssh_service *service); struct ssh_service *service);
#endif /* LSH_USERAUTH_H_INCLUDED */ #endif /* LSH_USERAUTH_H_INCLUDED */
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