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,10 +80,10 @@ static int client_initiate(struct fd_callback **c,
res = A_WRITE(connection->raw,
ssh_format("%lS\r\n", connection->client_version));
if (LSH_PROBLEMP(res))
if (LSH_CLOSEDP(res))
return res;
return initiate_keyexchange(connection, CONNECTION_CLIENT,
return res | initiate_keyexchange(connection, CONNECTION_CLIENT,
MAKE_KEXINIT(closure->init),
NULL);
}
......@@ -207,3 +207,4 @@ struct close_callback *make_client_close_handler(void)
return c;
}
......@@ -85,7 +85,7 @@ static int do_handle_dh_reply(struct packet_handler *c,
* handler for recieving the newkeys message. */
res = A_WRITE(connection->write, ssh_format("%c", SSH_MSG_NEWKEYS));
if (LSH_PROBLEMP(res))
if (LSH_CLOSEDP(res))
return res;
/* Record session id */
......@@ -110,11 +110,11 @@ static int do_handle_dh_reply(struct packet_handler *c,
connection->dispatch[SSH_MSG_KEXDH_REPLY] = connection->fail;
connection->kex_state = KEX_STATE_NEWKEYS;
res = send_verbose(connection->write, "Key exchange successful!", 0);
if (LSH_PROBLEMP(res))
res |= send_verbose(connection->write, "Key exchange successful!", 0);
if (LSH_CLOSEDP(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,
......@@ -148,15 +148,15 @@ static int do_init_dh(struct keyexchange_algorithm *c,
/* Send client's message */
res = A_WRITE(connection->write, dh_make_client_msg(&dh->dh));
if (LSH_PROBLEMP(res))
return res;
if (LSH_CLOSEDP(res))
return res | LSH_FAIL;
/* Install handler */
connection->dispatch[SSH_MSG_KEXDH_REPLY] = &dh->super;
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,
res = A_WRITE(connection->write, lsh_string_dup(s));
if (!LSH_PROBLEMP(res) && first_packet)
return A_WRITE(connection->write, first_packet);
if (!LSH_CLOSEDP(res) && first_packet)
return res | A_WRITE(connection->write, first_packet);
else
return res;
}
......@@ -179,7 +179,7 @@ int disconnect_kex_failed(struct ssh_connection *connection, char *msg)
{
return A_WRITE(connection->write,
format_disconnect(SSH_DISCONNECT_KEY_EXCHANGE_FAILED,
msg));
msg, ""));
}
static int do_handle_kexinit(struct packet_handler *c,
......@@ -196,12 +196,13 @@ static int do_handle_kexinit(struct packet_handler *c,
void **algorithms;
int i;
int res = 0;
MDEBUG(closure);
MDEBUG(msg);
if (!msg)
return 0;
return LSH_FAIL | LSH_DIE;
/* Save value for later signing */
connection->literal_kexinits[!closure->type] = packet;
......@@ -211,7 +212,6 @@ static int do_handle_kexinit(struct packet_handler *c,
/* Have we sent a kexinit message? */
if (!connection->kexinits[closure->type])
{
int res;
struct lsh_string *packet;
struct kexinit *sent = MAKE_KEXINIT(closure->init);
connection->kexinits[closure->type] = sent;
......@@ -219,7 +219,7 @@ static int do_handle_kexinit(struct packet_handler *c,
connection->literal_kexinits[closure->type] = lsh_string_dup(packet);
res = A_WRITE(connection->write, packet);
if (LSH_PROBLEMP(res))
if (LSH_CLOSEDP(res))
return res;
}
......@@ -250,7 +250,7 @@ static int do_handle_kexinit(struct packet_handler *c,
disconnect_kex_failed(connection,
"No common key exchange method.\r\n");
return LSH_FAIL | LSH_CLOSE;
return res | LSH_FAIL | LSH_CLOSE;
}
}
hostkey_algorithm
......@@ -266,7 +266,7 @@ static int do_handle_kexinit(struct packet_handler *c,
if (!parameters[i])
{
disconnect_kex_failed(connection, "");
return LSH_FAIL | LSH_CLOSE;
return res | LSH_FAIL | LSH_CLOSE;
}
}
......@@ -275,7 +275,8 @@ static int do_handle_kexinit(struct packet_handler *c,
for (i = 0; i<KEX_PARAMETERS; i++)
algorithms[i] = ALIST_GET(closure->algorithms, parameters[i]);
return KEYEXCHANGE_INIT( (struct keyexchange_algorithm *)
return res
| KEYEXCHANGE_INIT( (struct keyexchange_algorithm *)
ALIST_GET(closure->algorithms, kex_algorithm),
connection,
closure->finished,
......
......@@ -131,7 +131,7 @@ static int do_read_line(struct read_handler **h,
while(next && (read.index < closure->pos))
{
res = READ_HANDLER(next, &read.super);
if (LSH_PROBLEMP(res))
if (LSH_CLOSEDP(res))
return res;
}
}
......
......@@ -290,7 +290,7 @@ static int do_read_packet(struct read_handler **h,
closure->state = WAIT_START;
res = A_WRITE(closure->handler, packet);
if (LSH_PROBLEMP(res))
if (LSH_ACTIONP(res))
return res;
break;
}
......
......@@ -80,10 +80,10 @@ static int server_initiate(struct fd_callback **c,
res = A_WRITE(connection->raw,
ssh_format("%lS\r\n", connection->server_version));
if (LSH_PROBLEMP(res))
if (LSH_CLOSEDP(res))
return res;
return initiate_keyexchange(connection, CONNECTION_SERVER,
return res | initiate_keyexchange(connection, CONNECTION_SERVER,
MAKE_KEXINIT(closure->init),
NULL);
}
......
......@@ -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,
closure->signer));
if (LSH_PROBLEMP(res))
if (LSH_CLOSEDP(res))
return res;
/* Send a newkeys message, and install a handler for recieving the
* newkeys message. */
res = A_WRITE(connection->write, ssh_format("%c", SSH_MSG_NEWKEYS));
if (LSH_PROBLEMP(res))
res |= A_WRITE(connection->write, ssh_format("%c", SSH_MSG_NEWKEYS));
if (LSH_CLOSEDP(res))
return res;
/* Record session id */
......@@ -105,11 +105,11 @@ static int do_handle_dh_init(struct packet_handler *c,
connection->kex_state = KEX_STATE_NEWKEYS;
connection->dispatch[SSH_MSG_KEXDH_INIT] = connection->fail;
res = send_verbose(connection->write, "Key exchange successful!", 0);
if (LSH_PROBLEMP(res))
res |= send_verbose(connection->write, "Key exchange successful!", 0);
if (LSH_CLOSEDP(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,
......
......@@ -24,6 +24,7 @@
#ifndef LSH_SERVICE_H_INCLUDED
#define LSH_SERVICE_H_INCLUDED
#include "alist.h"
#include "connection.h"
/* Used on both client and server side */
......@@ -43,4 +44,8 @@ struct lsh_string *format_service_request(int name);
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 */
/* session.h
*
* 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
#define LSH_SESSION_H_INCLUDED
#include "alist.h"
#include "connection.h"
#include "channel.h"
#include "parse.h"
struct ssh_session
{
#if 0
/* FIXME: This is relevant only for the server side. It's probably
* better to store this in the connection struct */
uid_t user; /* Authenticated user */
struct ssh_service *make_session_service(struct alist *global_requests,
struct alist *channel_requests);
#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 */
......@@ -24,7 +24,8 @@
#ifndef 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,
* and sets SERVICE non-NULL iff access is granted. */
......@@ -35,8 +36,9 @@ struct userauth
{
struct lsh_object header;
int (*authenticate)(struct userauth *self,
lsh_string *user,
int (*authenticate)(struct userauth *closure,
/* The name is consumed by this function */
struct lsh_string *username,
int requested_service,
struct simple_buffer *args,
struct ssh_service **service);
......@@ -45,7 +47,7 @@ struct userauth
#define 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,
struct ssh_service *service);
......
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