aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2013-07-14 13:31:24 +0200
committerAndreas Schneider <asn@cryptomilk.org>2013-07-14 13:31:24 +0200
commitc64ec43eef8ec5a8b8a8f4c4c3216043aea8e08a (patch)
tree33131e402f35d800cf923f837ae4c72166703b27
parent0d3deeec101b0d6568d7c04eda833bde47c7329c (diff)
downloadlibssh-c64ec43eef8ec5a8b8a8f4c4c3216043aea8e08a.tar.gz
libssh-c64ec43eef8ec5a8b8a8f4c4c3216043aea8e08a.tar.xz
libssh-c64ec43eef8ec5a8b8a8f4c4c3216043aea8e08a.zip
src: Remove enter_function() and leave_function().
-rw-r--r--include/libssh/priv.h3
-rw-r--r--include/libssh/session.h1
-rw-r--r--src/auth.c35
-rw-r--r--src/auth1.c20
-rw-r--r--src/callbacks.c18
-rw-r--r--src/channels.c182
-rw-r--r--src/client.c72
-rw-r--r--src/connect.c24
-rw-r--r--src/dh.c10
-rw-r--r--src/kex.c20
-rw-r--r--src/kex1.c22
-rw-r--r--src/known_hosts.c47
-rw-r--r--src/legacy.c5
-rw-r--r--src/messages.c106
-rw-r--r--src/packet.c30
-rw-r--r--src/packet1.c10
-rw-r--r--src/packet_cb.c4
-rw-r--r--src/server.c19
-rw-r--r--src/session.c38
-rw-r--r--src/sftp.c18
-rw-r--r--src/socket.c24
-rw-r--r--src/wrapper.c55
22 files changed, 268 insertions, 495 deletions
diff --git a/include/libssh/priv.h b/include/libssh/priv.h
index 15855ff8..64a07451 100644
--- a/include/libssh/priv.h
+++ b/include/libssh/priv.h
@@ -138,9 +138,6 @@ int gettimeofday(struct timeval *__p, void *__t);
# define LIBSSH_THREAD
#endif
-#define enter_function() (void)session
-#define leave_function() (void)session
-
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
diff --git a/include/libssh/session.h b/include/libssh/session.h
index dd1091bf..f0d580dc 100644
--- a/include/libssh/session.h
+++ b/include/libssh/session.h
@@ -84,7 +84,6 @@ struct ssh_common_struct {
struct error_struct error;
ssh_callbacks callbacks; /* Callbacks to user functions */
int log_verbosity; /* verbosity of the log functions */
- int log_indent; /* indentation level in enter_function logs */
};
struct ssh_session_struct {
diff --git a/src/auth.c b/src/auth.c
index 32059dfc..c48546d5 100644
--- a/src/auth.c
+++ b/src/auth.c
@@ -110,11 +110,9 @@ static int ssh_userauth_get_response(ssh_session session) {
rc = ssh_handle_packets_termination(session, SSH_TIMEOUT_USER,
ssh_auth_response_termination, session);
if (rc == SSH_ERROR) {
- leave_function();
return SSH_AUTH_ERROR;
}
if (!ssh_auth_response_termination(session)){
- leave_function();
return SSH_AUTH_AGAIN;
}
@@ -159,7 +157,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_banner){
ssh_string banner;
(void)type;
(void)user;
- enter_function();
+
banner = buffer_get_ssh_string(packet);
if (banner == NULL) {
SSH_LOG(SSH_LOG_WARN,
@@ -171,7 +169,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_banner){
ssh_string_free(session->banner);
session->banner = banner;
}
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -188,7 +186,6 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_failure){
uint8_t partial = 0;
(void) type;
(void) user;
- enter_function();
auth = buffer_get_ssh_string(packet);
if (auth == NULL || buffer_get_u8(packet, &partial) != 1) {
@@ -239,7 +236,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_failure){
end:
ssh_string_free(auth);
SAFE_FREE(auth_methods);
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -251,7 +248,6 @@ end:
* It is also used to communicate the new to the upper levels.
*/
SSH_PACKET_CALLBACK(ssh_packet_userauth_success){
- enter_function();
(void)packet;
(void)type;
(void)user;
@@ -271,7 +267,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_success){
SSH_LOG(SSH_LOG_DEBUG, "Enabling delayed compression IN");
session->current_crypto->do_compress_in=1;
}
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -285,7 +281,6 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_success){
*/
SSH_PACKET_CALLBACK(ssh_packet_userauth_pk_ok){
int rc;
- enter_function();
SSH_LOG(SSH_LOG_TRACE, "Received SSH_USERAUTH_PK_OK/INFO_REQUEST/GSSAPI_RESPONSE");
@@ -303,7 +298,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_pk_ok){
SSH_LOG(SSH_LOG_TRACE, "Assuming SSH_USERAUTH_PK_OK");
rc=SSH_PACKET_USED;
}
- leave_function();
+
return rc;
}
@@ -1740,7 +1735,6 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_info_request) {
uint32_t i;
(void)user;
(void)type;
- enter_function();
name = buffer_get_ssh_string(packet);
instruction = buffer_get_ssh_string(packet);
@@ -1754,7 +1748,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_info_request) {
ssh_string_free(name);
ssh_string_free(instruction);
ssh_set_error(session, SSH_FATAL, "Invalid USERAUTH_INFO_REQUEST msg");
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -1765,7 +1759,6 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_info_request) {
ssh_string_free(name);
ssh_string_free(instruction);
- leave_function();
return SSH_PACKET_USED;
}
} else {
@@ -1778,7 +1771,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_info_request) {
ssh_set_error_oom(session);
ssh_kbdint_free(session->kbdint);
ssh_string_free(instruction);
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -1788,7 +1781,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_info_request) {
ssh_set_error_oom(session);
ssh_kbdint_free(session->kbdint);
session->kbdint = NULL;
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -1801,7 +1794,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_info_request) {
nprompts, nprompts);
ssh_kbdint_free(session->kbdint);
session->kbdint = NULL;
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -1813,7 +1806,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_info_request) {
ssh_set_error_oom(session);
ssh_kbdint_free(session->kbdint);
session->kbdint = NULL;
- leave_function();
+
return SSH_PACKET_USED;
}
memset(session->kbdint->prompts, 0, nprompts * sizeof(char *));
@@ -1824,7 +1817,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_info_request) {
ssh_set_error_oom(session);
ssh_kbdint_free(session->kbdint);
session->kbdint = NULL;
- leave_function();
+
return SSH_PACKET_USED;
}
memset(session->kbdint->echo, 0, nprompts);
@@ -1836,7 +1829,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_info_request) {
ssh_set_error(session, SSH_FATAL, "Short INFO_REQUEST packet");
ssh_kbdint_free(session->kbdint);
session->kbdint = NULL;
- leave_function();
+
return SSH_PACKET_USED;
}
session->kbdint->prompts[i] = ssh_string_to_char(tmp);
@@ -1846,12 +1839,12 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_info_request) {
session->kbdint->nprompts = i;
ssh_kbdint_free(session->kbdint);
session->kbdint = NULL;
- leave_function();
+
return SSH_PACKET_USED;
}
}
session->auth_state=SSH_AUTH_STATE_INFO;
- leave_function();
+
return SSH_PACKET_USED;
}
diff --git a/src/auth1.c b/src/auth1.c
index 20306087..a65c4475 100644
--- a/src/auth1.c
+++ b/src/auth1.c
@@ -44,15 +44,14 @@ static int ssh_auth_status_termination(void *s){
}
static int wait_auth1_status(ssh_session session) {
- enter_function();
/* wait for a packet */
if (ssh_handle_packets_termination(session,SSH_TIMEOUT_USER,
ssh_auth_status_termination, session) != SSH_OK){
- leave_function();
+
return SSH_AUTH_ERROR;
}
SSH_LOG(SSH_LOG_PROTOCOL,"Auth state : %d",session->auth_state);
- leave_function();
+
switch(session->auth_state) {
case SSH_AUTH_STATE_SUCCESS:
return SSH_AUTH_SUCCESS;
@@ -153,8 +152,7 @@ int ssh_userauth1_offer_pubkey(ssh_session session, const char *username,
(void) username;
(void) type;
(void) pubkey;
- enter_function();
- leave_function();
+
return SSH_AUTH_DENIED;
}
@@ -162,10 +160,9 @@ int ssh_userauth1_password(ssh_session session, const char *username,
const char *password) {
ssh_string pwd = NULL;
int rc;
- enter_function();
+
rc = send_username(session, username);
if (rc != SSH_AUTH_DENIED) {
- leave_function();
return rc;
}
if (session->pending_call_state == SSH_PENDING_CALL_AUTH_PASSWORD)
@@ -181,7 +178,6 @@ int ssh_userauth1_password(ssh_session session, const char *username,
/* not risky to disclose the size of such a big password .. */
pwd = ssh_string_from_char(password);
if (pwd == NULL) {
- leave_function();
return SSH_AUTH_ERROR;
}
} else {
@@ -194,7 +190,6 @@ int ssh_userauth1_password(ssh_session session, const char *username,
*/
pwd = ssh_string_new(sizeof(buf));
if (pwd == NULL) {
- leave_function();
return SSH_AUTH_ERROR;
}
ssh_get_random(buf, sizeof(buf), 0);
@@ -205,13 +200,13 @@ int ssh_userauth1_password(ssh_session session, const char *username,
if (buffer_add_u8(session->out_buffer, SSH_CMSG_AUTH_PASSWORD) < 0) {
ssh_string_burn(pwd);
ssh_string_free(pwd);
- leave_function();
+
return SSH_AUTH_ERROR;
}
if (buffer_add_ssh_string(session->out_buffer, pwd) < 0) {
ssh_string_burn(pwd);
ssh_string_free(pwd);
- leave_function();
+
return SSH_AUTH_ERROR;
}
@@ -220,14 +215,13 @@ int ssh_userauth1_password(ssh_session session, const char *username,
session->auth_state=SSH_AUTH_STATE_NONE;
session->pending_call_state = SSH_PENDING_CALL_AUTH_PASSWORD;
if (packet_send(session) == SSH_ERROR) {
- leave_function();
return SSH_AUTH_ERROR;
}
pending:
rc = wait_auth1_status(session);
if (rc != SSH_AUTH_AGAIN)
session->pending_call_state = SSH_PENDING_CALL_NONE;
- leave_function();
+
return rc;
}
diff --git a/src/callbacks.c b/src/callbacks.c
index f524aba3..51747d32 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -30,15 +30,15 @@ int ssh_set_callbacks(ssh_session session, ssh_callbacks cb) {
if (session == NULL || cb == NULL) {
return SSH_ERROR;
}
- enter_function();
+
if(cb->size <= 0 || cb->size > 1024 * sizeof(void *)){
ssh_set_error(session,SSH_FATAL,
"Invalid callback passed in (badly initialized)");
- leave_function();
+
return SSH_ERROR;
}
session->common.callbacks = cb;
- leave_function();
+
return 0;
}
@@ -48,15 +48,15 @@ int ssh_set_channel_callbacks(ssh_channel channel, ssh_channel_callbacks cb) {
return SSH_ERROR;
}
session = channel->session;
- enter_function();
+
if(cb->size <= 0 || cb->size > 1024 * sizeof(void *)){
ssh_set_error(session,SSH_FATAL,
"Invalid channel callback passed in (badly initialized)");
- leave_function();
+
return SSH_ERROR;
}
channel->callbacks = cb;
- leave_function();
+
return 0;
}
@@ -64,14 +64,14 @@ int ssh_set_server_callbacks(ssh_session session, ssh_server_callbacks cb){
if (session == NULL || cb == NULL) {
return SSH_ERROR;
}
- enter_function();
+
if(cb->size <= 0 || cb->size > 1024 * sizeof(void *)){
ssh_set_error(session,SSH_FATAL,
"Invalid callback passed in (badly initialized)");
- leave_function();
+
return SSH_ERROR;
}
session->server_callbacks = cb;
- leave_function();
+
return 0;
}
diff --git a/src/channels.c b/src/channels.c
index 333c26ee..ca92ff65 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -143,7 +143,7 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_open_conf){
ssh_channel channel;
(void)type;
(void)user;
- enter_function();
+
SSH_LOG(SSH_LOG_PACKET,"Received SSH2_MSG_CHANNEL_OPEN_CONFIRMATION");
buffer_get_u32(packet, &channelid);
@@ -154,7 +154,7 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_open_conf){
"Unknown channel id %lu",
(long unsigned int) channelid);
/* TODO: Set error marking in channel object */
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -178,7 +178,7 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_open_conf){
channel->state = SSH_CHANNEL_STATE_OPEN;
channel->flags = channel->flags & ~SSH_CHANNEL_FLAG_NOT_BOUND;
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -254,7 +254,6 @@ static int channel_open(ssh_channel channel, const char *type_c, int window,
ssh_string type = NULL;
int err=SSH_ERROR;
- enter_function();
switch(channel->state){
case SSH_CHANNEL_STATE_NOT_OPEN:
break;
@@ -278,7 +277,7 @@ static int channel_open(ssh_channel channel, const char *type_c, int window,
type = ssh_string_from_char(type_c);
if (type == NULL) {
ssh_set_error_oom(session);
- leave_function();
+
return err;
}
@@ -289,7 +288,7 @@ static int channel_open(ssh_channel channel, const char *type_c, int window,
buffer_add_u32(session->out_buffer, htonl(channel->local_maxpacket)) < 0) {
ssh_set_error_oom(session);
ssh_string_free(type);
- leave_function();
+
return err;
}
@@ -298,13 +297,13 @@ static int channel_open(ssh_channel channel, const char *type_c, int window,
if (payload != NULL) {
if (buffer_add_buffer(session->out_buffer, payload) < 0) {
ssh_set_error_oom(session);
- leave_function();
+
return err;
}
}
channel->state = SSH_CHANNEL_STATE_OPENING;
if (packet_send(session) == SSH_ERROR) {
- leave_function();
+
return err;
}
@@ -319,7 +318,7 @@ pending:
end:
if(channel->state == SSH_CHANNEL_STATE_OPEN)
err=SSH_OK;
- leave_function();
+
return err;
}
@@ -351,11 +350,10 @@ ssh_channel ssh_channel_from_local(ssh_session session, uint32_t id) {
static int grow_window(ssh_session session, ssh_channel channel, int minimumsize) {
uint32_t new_window = minimumsize > WINDOWBASE ? minimumsize : WINDOWBASE;
- enter_function();
#ifdef WITH_SSH1
if (session->version == 1){
channel->remote_window = new_window;
- leave_function();
+
return SSH_OK;
}
#endif
@@ -364,7 +362,7 @@ static int grow_window(ssh_session session, ssh_channel channel, int minimumsize
"growing window (channel %d:%d) to %d bytes : not needed (%d bytes)",
channel->local_channel, channel->remote_channel, new_window,
channel->local_window);
- leave_function();
+
return SSH_OK;
}
/* WINDOW_ADJUST packet needs a relative increment rather than an absolute
@@ -389,12 +387,10 @@ static int grow_window(ssh_session session, ssh_channel channel, int minimumsize
channel->local_window = new_window;
- leave_function();
return SSH_OK;
error:
buffer_reinit(session->out_buffer);
- leave_function();
return SSH_ERROR;
}
@@ -443,7 +439,6 @@ SSH_PACKET_CALLBACK(channel_rcv_change_window) {
int rc;
(void)user;
(void)type;
- enter_function();
channel = channel_from_msg(session,packet);
if (channel == NULL) {
@@ -454,7 +449,7 @@ SSH_PACKET_CALLBACK(channel_rcv_change_window) {
if (channel == NULL || rc != sizeof(uint32_t)) {
SSH_LOG(SSH_LOG_PACKET,
"Error getting a window adjust message: invalid packet");
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -468,7 +463,6 @@ SSH_PACKET_CALLBACK(channel_rcv_change_window) {
channel->remote_window += bytes;
- leave_function();
return SSH_PACKET_USED;
}
@@ -481,7 +475,7 @@ SSH_PACKET_CALLBACK(channel_rcv_data){
int is_stderr;
int rest;
(void)user;
- enter_function();
+
if(type==SSH2_MSG_CHANNEL_DATA)
is_stderr=0;
else
@@ -491,7 +485,7 @@ SSH_PACKET_CALLBACK(channel_rcv_data){
if (channel == NULL) {
SSH_LOG(SSH_LOG_FUNCTIONS,
"%s", ssh_get_error(session));
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -504,7 +498,7 @@ SSH_PACKET_CALLBACK(channel_rcv_data){
str = buffer_get_ssh_string(packet);
if (str == NULL) {
SSH_LOG(SSH_LOG_PACKET, "Invalid data packet!");
- leave_function();
+
return SSH_PACKET_USED;
}
len = ssh_string_len(str);
@@ -527,7 +521,7 @@ SSH_PACKET_CALLBACK(channel_rcv_data){
if (channel_default_bufferize(channel, ssh_string_data(str), len,
is_stderr) < 0) {
ssh_string_free(str);
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -561,13 +555,11 @@ SSH_PACKET_CALLBACK(channel_rcv_data){
}
if (channel->local_window + buffer_get_rest_len(buf) < WINDOWLIMIT) {
if (grow_window(session, channel, 0) < 0) {
- leave_function();
return -1;
}
}
}
- leave_function();
return SSH_PACKET_USED;
}
@@ -575,12 +567,11 @@ SSH_PACKET_CALLBACK(channel_rcv_eof) {
ssh_channel channel;
(void)user;
(void)type;
- enter_function();
channel = channel_from_msg(session,packet);
if (channel == NULL) {
SSH_LOG(SSH_LOG_FUNCTIONS, "%s", ssh_get_error(session));
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -597,7 +588,6 @@ SSH_PACKET_CALLBACK(channel_rcv_eof) {
channel->callbacks->userdata);
}
- leave_function();
return SSH_PACKET_USED;
}
@@ -605,12 +595,11 @@ SSH_PACKET_CALLBACK(channel_rcv_close) {
ssh_channel channel;
(void)user;
(void)type;
- enter_function();
channel = channel_from_msg(session,packet);
if (channel == NULL) {
SSH_LOG(SSH_LOG_FUNCTIONS, "%s", ssh_get_error(session));
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -645,7 +634,7 @@ SSH_PACKET_CALLBACK(channel_rcv_close) {
channel->flags &= SSH_CHANNEL_FLAG_CLOSED_REMOTE;
if(channel->flags & SSH_CHANNEL_FLAG_FREED_LOCAL)
ssh_channel_do_free(channel);
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -658,26 +647,24 @@ SSH_PACKET_CALLBACK(channel_rcv_request) {
(void)user;
(void)type;
- enter_function();
-
channel = channel_from_msg(session,packet);
if (channel == NULL) {
SSH_LOG(SSH_LOG_FUNCTIONS,"%s", ssh_get_error(session));
- leave_function();
+
return SSH_PACKET_USED;
}
request_s = buffer_get_ssh_string(packet);
if (request_s == NULL) {
SSH_LOG(SSH_LOG_PACKET, "Invalid MSG_CHANNEL_REQUEST");
- leave_function();
+
return SSH_PACKET_USED;
}
request = ssh_string_to_char(request_s);
ssh_string_free(request_s);
if (request == NULL) {
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -698,7 +685,6 @@ SSH_PACKET_CALLBACK(channel_rcv_request) {
channel->callbacks->userdata);
}
- leave_function();
return SSH_PACKET_USED;
}
@@ -712,14 +698,14 @@ SSH_PACKET_CALLBACK(channel_rcv_request) {
signal_str = buffer_get_ssh_string(packet);
if (signal_str == NULL) {
SSH_LOG(SSH_LOG_PACKET, "Invalid MSG_CHANNEL_REQUEST");
- leave_function();
+
return SSH_PACKET_USED;
}
sig = ssh_string_to_char(signal_str);
ssh_string_free(signal_str);
if (sig == NULL) {
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -734,7 +720,6 @@ SSH_PACKET_CALLBACK(channel_rcv_request) {
}
SAFE_FREE(sig);
- leave_function();
return SSH_PACKET_USED;
}
@@ -751,14 +736,14 @@ SSH_PACKET_CALLBACK(channel_rcv_request) {
tmp = buffer_get_ssh_string(packet);
if (tmp == NULL) {
SSH_LOG(SSH_LOG_PACKET, "Invalid MSG_CHANNEL_REQUEST");
- leave_function();
+
return SSH_PACKET_USED;
}
sig = ssh_string_to_char(tmp);
ssh_string_free(tmp);
if (sig == NULL) {
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -771,7 +756,7 @@ SSH_PACKET_CALLBACK(channel_rcv_request) {
if (tmp == NULL) {
SSH_LOG(SSH_LOG_PACKET, "Invalid MSG_CHANNEL_REQUEST");
SAFE_FREE(sig);
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -779,7 +764,7 @@ SSH_PACKET_CALLBACK(channel_rcv_request) {
ssh_string_free(tmp);
if (errmsg == NULL) {
SAFE_FREE(sig);
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -788,7 +773,7 @@ SSH_PACKET_CALLBACK(channel_rcv_request) {
SSH_LOG(SSH_LOG_PACKET, "Invalid MSG_CHANNEL_REQUEST");
SAFE_FREE(errmsg);
SAFE_FREE(sig);
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -797,7 +782,7 @@ SSH_PACKET_CALLBACK(channel_rcv_request) {
if (lang == NULL) {
SAFE_FREE(errmsg);
SAFE_FREE(sig);
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -814,7 +799,6 @@ SSH_PACKET_CALLBACK(channel_rcv_request) {
SAFE_FREE(errmsg);
SAFE_FREE(sig);
- leave_function();
return SSH_PACKET_USED;
}
if(strcmp(request,"keepalive@openssh.com")==0){
@@ -829,7 +813,7 @@ SSH_PACKET_CALLBACK(channel_rcv_request) {
return SSH_PACKET_USED;
}
packet_send(session);
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -840,7 +824,7 @@ SSH_PACKET_CALLBACK(channel_rcv_request) {
channel->callbacks->channel_auth_agent_req_function(channel->session, channel,
channel->callbacks->userdata);
}
- leave_function();
+
return SSH_PACKET_USED;
}
#ifdef WITH_SERVER
@@ -855,7 +839,6 @@ SSH_PACKET_CALLBACK(channel_rcv_request) {
SAFE_FREE(request);
- leave_function();
return SSH_PACKET_USED;
}
@@ -1029,8 +1012,6 @@ int ssh_channel_open_forward(ssh_channel channel, const char *remotehost,
return rc;
}
- enter_function();
-
payload = ssh_buffer_new();
if (payload == NULL) {
ssh_set_error_oom(session);
@@ -1071,7 +1052,6 @@ error:
ssh_buffer_free(payload);
ssh_string_free(str);
- leave_function();
return rc;
}
@@ -1091,8 +1071,6 @@ void ssh_channel_free(ssh_channel channel) {
}
session = channel->session;
- enter_function();
-
if (session->alive && channel->state == SSH_CHANNEL_STATE_OPEN) {
ssh_channel_close(channel);
}
@@ -1107,7 +1085,6 @@ void ssh_channel_free(ssh_channel channel) {
|| (channel->flags & SSH_CHANNEL_FLAG_NOT_BOUND)){
ssh_channel_do_free(channel);
}
- leave_function();
}
/**
@@ -1151,7 +1128,6 @@ int ssh_channel_send_eof(ssh_channel channel){
}
session = channel->session;
- enter_function();
if (buffer_add_u8(session->out_buffer, SSH2_MSG_CHANNEL_EOF) < 0) {
ssh_set_error_oom(session);
@@ -1169,12 +1145,10 @@ int ssh_channel_send_eof(ssh_channel channel){
channel->local_eof = 1;
- leave_function();
return rc;
error:
buffer_reinit(session->out_buffer);
- leave_function();
return rc;
}
@@ -1200,14 +1174,12 @@ int ssh_channel_close(ssh_channel channel){
}
session = channel->session;
- enter_function();
if (channel->local_eof == 0) {
rc = ssh_channel_send_eof(channel);
}
if (rc != SSH_OK) {
- leave_function();
return rc;
}
@@ -1227,12 +1199,10 @@ int ssh_channel_close(ssh_channel channel){
channel->state=SSH_CHANNEL_STATE_CLOSED;
}
- leave_function();
return rc;
error:
buffer_reinit(session->out_buffer);
- leave_function();
return rc;
}
@@ -1296,8 +1266,6 @@ int channel_write_common(ssh_channel channel, const void *data,
return SSH_ERROR;
}
- enter_function();
-
/*
* Handle the max packet len from remote side, be nice
* 10 bytes for the headers
@@ -1309,23 +1277,22 @@ int channel_write_common(ssh_channel channel, const void *data,
"Can't write to channel %d:%d after EOF was sent",
channel->local_channel,
channel->remote_channel);
- leave_function();
return -1;
}
if (channel->state != SSH_CHANNEL_STATE_OPEN || channel->delayed_close != 0) {
ssh_set_error(session, SSH_REQUEST_DENIED, "Remote channel is closed");
- leave_function();
+
return -1;
}
if (channel->session->session_state == SSH_SESSION_STATE_ERROR){
- leave_function();
+
return SSH_ERROR;
}
#ifdef WITH_SSH1
if (channel->version == 1) {
rc = channel_write1(channel, data, len);
- leave_function();
+
return rc;
}
#endif
@@ -1378,7 +1345,6 @@ int channel_write_common(ssh_channel channel, const void *data,
}
if (packet_send(session) == SSH_ERROR) {
- leave_function();
return SSH_ERROR;
}
@@ -1394,13 +1360,11 @@ int channel_write_common(ssh_channel channel, const void *data,
if(rc == SSH_ERROR)
goto error;
out:
- leave_function();
return (int)(origlen - len);
error:
buffer_reinit(session->out_buffer);
- leave_function();
return SSH_ERROR;
}
@@ -1507,11 +1471,10 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_success){
ssh_channel channel;
(void)type;
(void)user;
- enter_function();
+
channel=channel_from_msg(session,packet);
if (channel == NULL) {
SSH_LOG(SSH_LOG_FUNCTIONS, "%s", ssh_get_error(session));
- leave_function();
return SSH_PACKET_USED;
}
@@ -1526,7 +1489,6 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_success){
channel->request_state=SSH_CHANNEL_REQ_STATE_ACCEPTED;
}
- leave_function();
return SSH_PACKET_USED;
}
@@ -1541,11 +1503,11 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_failure){
ssh_channel channel;
(void)type;
(void)user;
- enter_function();
+
channel=channel_from_msg(session,packet);
if (channel == NULL) {
SSH_LOG(SSH_LOG_FUNCTIONS, "%s", ssh_get_error(session));
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -1559,7 +1521,7 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_failure){
} else {
channel->request_state=SSH_CHANNEL_REQ_STATE_DENIED;
}
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -1578,7 +1540,6 @@ static int channel_request(ssh_channel channel, const char *request,
ssh_string req = NULL;
int rc = SSH_ERROR;
- enter_function();
switch(channel->request_state){
case SSH_CHANNEL_REQ_STATE_NONE:
break;
@@ -1611,7 +1572,6 @@ static int channel_request(ssh_channel channel, const char *request,
}
channel->request_state = SSH_CHANNEL_REQ_STATE_PENDING;
if (packet_send(session) == SSH_ERROR) {
- leave_function();
return rc;
}
@@ -1619,7 +1579,6 @@ static int channel_request(ssh_channel channel, const char *request,
"Sent a SSH_MSG_CHANNEL_REQUEST %s", request);
if (reply == 0) {
channel->request_state = SSH_CHANNEL_REQ_STATE_NONE;
- leave_function();
return SSH_OK;
}
pending:
@@ -1644,7 +1603,6 @@ pending:
break;
case SSH_CHANNEL_REQ_STATE_PENDING:
rc = SSH_AGAIN;
- leave_function();
return rc;
case SSH_CHANNEL_REQ_STATE_NONE:
/* Never reached */
@@ -1653,12 +1611,11 @@ pending:
break;
}
channel->request_state=SSH_CHANNEL_REQ_STATE_NONE;
- leave_function();
+
return rc;
error:
buffer_reinit(session->out_buffer);
- leave_function();
return rc;
}
@@ -1695,11 +1652,10 @@ int ssh_channel_request_pty_size(ssh_channel channel, const char *terminal,
return rc;
}
- enter_function();
#ifdef WITH_SSH1
if (channel->version==1) {
rc = channel_request_pty_size1(channel,terminal, col, row);
- leave_function();
+
return rc;
}
#endif
@@ -1738,7 +1694,6 @@ error:
ssh_buffer_free(buffer);
ssh_string_free(term);
- leave_function();
return rc;
}
@@ -1778,12 +1733,10 @@ int ssh_channel_change_pty_size(ssh_channel channel, int cols, int rows) {
ssh_buffer buffer = NULL;
int rc = SSH_ERROR;
- enter_function();
-
#ifdef WITH_SSH1
if (channel->version == 1) {
rc = channel_change_pty_size1(channel,cols,rows);
- leave_function();
+
return rc;
}
#endif
@@ -1806,7 +1759,6 @@ int ssh_channel_change_pty_size(ssh_channel channel, int cols, int rows) {
error:
ssh_buffer_free(buffer);
- leave_function();
return rc;
}
@@ -2061,7 +2013,6 @@ SSH_PACKET_CALLBACK(ssh_request_success){
(void)type;
(void)user;
(void)packet;
- enter_function();
SSH_LOG(SSH_LOG_PACKET,
"Received SSH_REQUEST_SUCCESS");
@@ -2072,7 +2023,6 @@ SSH_PACKET_CALLBACK(ssh_request_success){
session->global_req_state=SSH_CHANNEL_REQ_STATE_ACCEPTED;
}
- leave_function();
return SSH_PACKET_USED;
}
@@ -2086,7 +2036,6 @@ SSH_PACKET_CALLBACK(ssh_request_denied){
(void)type;
(void)user;
(void)packet;
- enter_function();
SSH_LOG(SSH_LOG_PACKET,
"Received SSH_REQUEST_FAILURE");
@@ -2097,7 +2046,6 @@ SSH_PACKET_CALLBACK(ssh_request_denied){
session->global_req_state=SSH_CHANNEL_REQ_STATE_DENIED;
}
- leave_function();
return SSH_PACKET_USED;
}
@@ -2135,7 +2083,6 @@ static int global_request(ssh_session session, const char *request,
ssh_string req = NULL;
int rc = SSH_ERROR;
- enter_function();
if(session->global_req_state != SSH_CHANNEL_REQ_STATE_NONE)
goto pending;
req = ssh_string_from_char(request);
@@ -2162,7 +2109,6 @@ static int global_request(ssh_session session, const char *request,
}
session->global_req_state = SSH_CHANNEL_REQ_STATE_PENDING;
if (packet_send(session) == SSH_ERROR) {
- leave_function();
return rc;
}
@@ -2170,7 +2116,7 @@ static int global_request(ssh_session session, const char *request,
"Sent a SSH_MSG_GLOBAL_REQUEST %s", request);
if (reply == 0) {
session->global_req_state=SSH_CHANNEL_REQ_STATE_NONE;
- leave_function();
+
return SSH_OK;
}
pending:
@@ -2200,11 +2146,10 @@ pending:
break;
}
- leave_function();
return rc;
error:
ssh_string_free(req);
- leave_function();
+
return rc;
}
@@ -2595,30 +2540,26 @@ int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count,
return SSH_ERROR;
}
- enter_function();
buffer_reinit(buffer);
if(count==0){
do {
r=ssh_channel_poll(channel, is_stderr);
if(r < 0){
- leave_function();
return r;
}
if(r > 0){
r=ssh_channel_read(channel, buffer_tmp, r, is_stderr);
if(r < 0){
- leave_function();
return r;
}
if(buffer_add_data(buffer,buffer_tmp,r) < 0){
ssh_set_error_oom(session);
r = SSH_ERROR;
}
- leave_function();
+
return r;
}
if(ssh_channel_is_eof(channel)){
- leave_function();
return 0;
}
ssh_handle_packets(channel->session, SSH_TIMEOUT_INFINITE);
@@ -2627,21 +2568,19 @@ int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count,
while(total < count){
r=ssh_channel_read(channel, buffer_tmp, sizeof(buffer_tmp), is_stderr);
if(r<0){
- leave_function();
return r;
}
if(r==0){
- leave_function();
return total;
}
if(buffer_add_data(buffer,buffer_tmp,r) < 0){
ssh_set_error_oom(session);
- leave_function();
+
return SSH_ERROR;
}
total += r;
}
- leave_function();
+
return total;
}
@@ -2701,10 +2640,8 @@ int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_std
session = channel->session;
stdbuf = channel->stdout_buffer;
- enter_function();
if (count == 0) {
- leave_function();
return 0;
}
@@ -2724,7 +2661,6 @@ int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_std
if (count > buffer_get_rest_len(stdbuf) + channel->local_window) {
if (grow_window(session, channel, count - buffer_get_rest_len(stdbuf)) < 0) {
- leave_function();
return -1;
}
}
@@ -2738,15 +2674,12 @@ int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_std
rc = ssh_handle_packets_termination(session, SSH_TIMEOUT_DEFAULT,
ssh_channel_read_termination, &ctx);
if (rc == SSH_ERROR){
- leave_function();
return rc;
}
if (channel->session->session_state == SSH_SESSION_STATE_ERROR){
- leave_function();
return SSH_ERROR;
}
if (channel->remote_eof && buffer_get_rest_len(stdbuf) == 0) {
- leave_function();
return 0;
}
len = buffer_get_rest_len(stdbuf);
@@ -2757,12 +2690,10 @@ int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_std
/* Authorize some buffering while userapp is busy */
if (channel->local_window < WINDOWLIMIT) {
if (grow_window(session, channel, 0) < 0) {
- leave_function();
return -1;
}
}
- leave_function();
return len;
}
@@ -2803,16 +2734,14 @@ int ssh_channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count
}
session = channel->session;
- enter_function();
to_read = ssh_channel_poll(channel, is_stderr);
if (to_read <= 0) {
if (channel->session->session_state == SSH_SESSION_STATE_ERROR){
- leave_function();
return SSH_ERROR;
}
- leave_function();
+
return to_read; /* may be an error code */
}
@@ -2823,7 +2752,7 @@ int ssh_channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count
ssh_set_blocking(session, 0);
rc = ssh_channel_read(channel, dest, to_read, is_stderr);
ssh_set_blocking(session,blocking);
- leave_function();
+
return rc;
}
@@ -2842,16 +2771,13 @@ int ssh_channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count
* @see channel_is_eof()
*/
int ssh_channel_poll(ssh_channel channel, int is_stderr){
- ssh_session session;
ssh_buffer stdbuf;
if(channel == NULL) {
return SSH_ERROR;
}
- session = channel->session;
stdbuf = channel->stdout_buffer;
- enter_function();
if (is_stderr) {
stdbuf = channel->stderr_buffer;
@@ -2859,26 +2785,21 @@ int ssh_channel_poll(ssh_channel channel, int is_stderr){
if (buffer_get_rest_len(stdbuf) == 0 && channel->remote_eof == 0) {
if (channel->session->session_state == SSH_SESSION_STATE_ERROR){
- leave_function();
return SSH_ERROR;
}
if (ssh_handle_packets(channel->session, SSH_TIMEOUT_NONBLOCKING)==SSH_ERROR) {
- leave_function();
return SSH_ERROR;
}
}
if (buffer_get_rest_len(stdbuf) > 0){
- leave_function();
return buffer_get_rest_len(stdbuf);
}
if (channel->remote_eof) {
- leave_function();
return SSH_EOF;
}
- leave_function();
return buffer_get_rest_len(stdbuf);
}
@@ -2913,7 +2834,6 @@ int ssh_channel_poll_timeout(ssh_channel channel, int timeout, int is_stderr){
session = channel->session;
stdbuf = channel->stdout_buffer;
- enter_function();
if (is_stderr) {
stdbuf = channel->stderr_buffer;
@@ -2933,7 +2853,6 @@ int ssh_channel_poll_timeout(ssh_channel channel, int timeout, int is_stderr){
if (channel->remote_eof)
rc = SSH_EOF;
end:
- leave_function();
return rc;
}
@@ -3252,7 +3171,6 @@ int ssh_channel_open_reverse_forward(ssh_channel channel, const char *remotehost
session = channel->session;
- enter_function();
if(channel->state != SSH_CHANNEL_STATE_NOT_OPEN)
goto pending;
payload = ssh_buffer_new();
@@ -3295,7 +3213,6 @@ error:
ssh_buffer_free(payload);
ssh_string_free(str);
- leave_function();
return rc;
}
@@ -3332,8 +3249,6 @@ int ssh_channel_open_x11(ssh_channel channel,
}
session = channel->session;
- enter_function();
-
if(channel->state != SSH_CHANNEL_STATE_NOT_OPEN)
goto pending;
@@ -3365,7 +3280,6 @@ error:
ssh_buffer_free(payload);
ssh_string_free(str);
- leave_function();
return rc;
}
diff --git a/src/client.c b/src/client.c
index 1879bf93..99a300b1 100644
--- a/src/client.c
+++ b/src/client.c
@@ -59,11 +59,11 @@
*/
static void socket_callback_connected(int code, int errno_code, void *user){
ssh_session session=(ssh_session)user;
- enter_function();
+
if(session->session_state != SSH_SESSION_STATE_CONNECTING){
ssh_set_error(session,SSH_FATAL, "Wrong state in socket_callback_connected : %d",
session->session_state);
- leave_function();
+
return;
}
SSH_LOG(SSH_LOG_RARE,"Socket connection callback: %d (%d)",code, errno_code);
@@ -74,7 +74,6 @@ static void socket_callback_connected(int code, int errno_code, void *user){
ssh_set_error(session,SSH_FATAL,"%s",strerror(errno_code));
}
session->ssh_connection_callback(session);
- leave_function();
}
/**
@@ -94,10 +93,10 @@ static int callback_receive_banner(const void *data, size_t len, void *user) {
char *str = NULL;
size_t i;
int ret=0;
- enter_function();
+
if(session->session_state != SSH_SESSION_STATE_SOCKET_CONNECTED){
ssh_set_error(session,SSH_FATAL,"Wrong state in callback_receive_banner : %d",session->session_state);
- leave_function();
+
return SSH_ERROR;
}
for(i=0;i<len;++i){
@@ -117,18 +116,18 @@ static int callback_receive_banner(const void *data, size_t len, void *user) {
session->session_state=SSH_SESSION_STATE_BANNER_RECEIVED;
SSH_LOG(SSH_LOG_PACKET,"Received banner: %s",str);
session->ssh_connection_callback(session);
- leave_function();
+
return ret;
}
if(i>127){
/* Too big banner */
session->session_state=SSH_SESSION_STATE_ERROR;
ssh_set_error(session,SSH_FATAL,"Receiving banner: too large banner");
- leave_function();
+
return 0;
}
}
- leave_function();
+
return ret;
}
@@ -146,8 +145,6 @@ int ssh_send_banner(ssh_session session, int server) {
char buffer[128] = {0};
int err=SSH_ERROR;
- enter_function();
-
banner = session->version == 1 ? CLIENTBANNER1 : CLIENTBANNER2;
if (server) {
@@ -173,7 +170,7 @@ int ssh_send_banner(ssh_session session, int server) {
#endif
err=SSH_OK;
end:
- leave_function();
+
return err;
}
@@ -188,8 +185,6 @@ static int dh_handshake(ssh_session session) {
int rc = SSH_AGAIN;
- enter_function();
-
switch (session->dh_handshake_state) {
case DH_STATE_INIT:
switch(session->next_crypto->kex_type){
@@ -203,12 +198,11 @@ static int dh_handshake(ssh_session session) {
break;
#endif
default:
- rc=SSH_ERROR;
- goto error;
+ rc = SSH_ERROR;
}
if (rc == SSH_ERROR) {
- goto error;
+ return SSH_ERROR;
}
session->dh_handshake_state = DH_STATE_INIT_SENT;
@@ -219,16 +213,14 @@ static int dh_handshake(ssh_session session) {
/* wait until ssh_packet_newkeys is called */
break;
case DH_STATE_FINISHED:
- leave_function();
return SSH_OK;
default:
ssh_set_error(session, SSH_FATAL, "Invalid state in dh_handshake(): %d",
session->dh_handshake_state);
- leave_function();
+
return SSH_ERROR;
}
-error:
- leave_function();
+
return rc;
}
@@ -259,27 +251,27 @@ static int ssh_service_request_termination(void *s){
int ssh_service_request(ssh_session session, const char *service) {
ssh_string service_s = NULL;
int rc=SSH_ERROR;
- enter_function();
+
if(session->auth_service_state != SSH_AUTH_SERVICE_NONE)
goto pending;
if (buffer_add_u8(session->out_buffer, SSH2_MSG_SERVICE_REQUEST) < 0) {
- goto error;
+ return SSH_ERROR;
}
service_s = ssh_string_from_char(service);
if (service_s == NULL) {
- goto error;
+ return SSH_ERROR;
}
if (buffer_add_ssh_string(session->out_buffer,service_s) < 0) {
ssh_string_free(service_s);
- goto error;
+ return SSH_ERROR;
}
ssh_string_free(service_s);
session->auth_service_state=SSH_AUTH_SERVICE_SENT;
if (packet_send(session) == SSH_ERROR) {
ssh_set_error(session, SSH_FATAL,
"Sending SSH2_MSG_SERVICE_REQUEST failed.");
- goto error;
+ return SSH_ERROR;
}
SSH_LOG(SSH_LOG_PACKET,
@@ -287,8 +279,9 @@ int ssh_service_request(ssh_session session, const char *service) {
pending:
rc=ssh_handle_packets_termination(session,SSH_TIMEOUT_USER,
ssh_service_request_termination, session);
- if(rc == SSH_ERROR)
- goto error;
+ if (rc == SSH_ERROR) {
+ return SSH_ERROR;
+ }
switch(session->auth_service_state){
case SSH_AUTH_SERVICE_DENIED:
ssh_set_error(session,SSH_FATAL,"ssh_auth_service request denied");
@@ -305,8 +298,7 @@ pending:
rc=SSH_ERROR;
break;
}
-error:
- leave_function();
+
return rc;
}
@@ -324,7 +316,7 @@ error:
*/
static void ssh_client_connection_callback(ssh_session session){
int ssh1,ssh2;
- enter_function();
+
switch(session->session_state){
case SSH_SESSION_STATE_NONE:
case SSH_SESSION_STATE_CONNECTING:
@@ -423,13 +415,13 @@ static void ssh_client_connection_callback(ssh_session session){
default:
ssh_set_error(session,SSH_FATAL,"Invalid state %d",session->session_state);
}
- leave_function();
+
return;
- error:
+error:
ssh_socket_close(session->socket);
session->alive = 0;
session->session_state=SSH_SESSION_STATE_ERROR;
- leave_function();
+
}
/** @internal
@@ -466,7 +458,6 @@ int ssh_connect(ssh_session session) {
return SSH_ERROR;
}
- enter_function();
switch(session->pending_call_state){
case SSH_PENDING_CALL_NONE:
break;
@@ -474,28 +465,25 @@ int ssh_connect(ssh_session session) {
goto pending;
default:
ssh_set_error(session,SSH_FATAL,"Bad call during pending SSH call in ssh_connect");
- leave_function();
+
return SSH_ERROR;
}
session->alive = 0;
session->client = 1;
if (ssh_init() < 0) {
- leave_function();
return SSH_ERROR;
}
if (session->opts.fd == SSH_INVALID_SOCKET &&
session->opts.host == NULL &&
session->opts.ProxyCommand == NULL) {
ssh_set_error(session, SSH_FATAL, "Hostname required");
- leave_function();
return SSH_ERROR;
}
ret = ssh_options_apply(session);
if (ret < 0) {
ssh_set_error(session, SSH_FATAL, "Couldn't apply options");
- leave_function();
return SSH_ERROR;
}
SSH_LOG(SSH_LOG_RARE,"libssh %s, using threading %s", ssh_copyright(), ssh_threads_get_type());
@@ -521,7 +509,6 @@ int ssh_connect(ssh_session session) {
session->opts.bindaddr);
}
if (ret == SSH_ERROR) {
- leave_function();
return SSH_ERROR;
}
@@ -556,10 +543,9 @@ pending:
}
SSH_LOG(SSH_LOG_PACKET,"ssh_connect: Actual state : %d",session->session_state);
if(!ssh_is_blocking(session) && !ssh_connect_termination(session)){
- leave_function();
return SSH_AGAIN;
}
- leave_function();
+
session->pending_call_state=SSH_PENDING_CALL_NONE;
if(session->session_state == SSH_SESSION_STATE_ERROR || session->session_state == SSH_SESSION_STATE_DISCONNECTED)
return SSH_ERROR;
@@ -616,8 +602,6 @@ void ssh_disconnect(ssh_session session) {
return;
}
- enter_function();
-
if (session->socket != NULL && ssh_socket_is_open(session->socket)) {
if (buffer_add_u8(session->out_buffer, SSH2_MSG_DISCONNECT) < 0) {
goto error;
@@ -683,8 +667,6 @@ error:
ssh_list_free(session->packet_callbacks);
session->packet_callbacks=NULL;
}
-
- leave_function();
}
const char *ssh_copyright(void) {
diff --git a/src/connect.c b/src/connect.c
index 7086b5f4..c4ae7b93 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -142,8 +142,6 @@ static int ssh_connect_ai_timeout(ssh_session session, const char *host,
int ret;
socklen_t len = sizeof(rc);
- enter_function();
-
/* I know we're losing some precision. But it's not like poll-like family
* type of mechanisms are precise up to the microsecond.
*/
@@ -177,7 +175,7 @@ static int ssh_connect_ai_timeout(ssh_session session, const char *host,
ssh_set_error(session, SSH_FATAL,
"Timeout while connecting to %s:%d", host, port);
ssh_connect_socket_close(s);
- leave_function();
+
return -1;
}
@@ -185,7 +183,7 @@ static int ssh_connect_ai_timeout(ssh_session session, const char *host,
ssh_set_error(session, SSH_FATAL,
"poll error: %s", strerror(errno));
ssh_connect_socket_close(s);
- leave_function();
+
return -1;
}
rc = -1;
@@ -196,7 +194,7 @@ static int ssh_connect_ai_timeout(ssh_session session, const char *host,
ssh_set_error(session, SSH_FATAL,
"Connect to %s:%d failed: %s", host, port, strerror(rc));
ssh_connect_socket_close(s);
- leave_function();
+
return -1;
}
@@ -211,7 +209,6 @@ static int ssh_connect_ai_timeout(ssh_session session, const char *host,
return -1;
}
- leave_function();
return s;
}
@@ -230,13 +227,11 @@ socket_t ssh_connect_host(ssh_session session, const char *host,
struct addrinfo *ai;
struct addrinfo *itr;
- enter_function();
-
rc = getai(host, port, &ai);
if (rc != 0) {
ssh_set_error(session, SSH_FATAL,
"Failed to resolve hostname %s (%s)", host, gai_strerror(rc));
- leave_function();
+
return -1;
}
@@ -263,7 +258,7 @@ socket_t ssh_connect_host(ssh_session session, const char *host,
gai_strerror(rc));
freeaddrinfo(ai);
close(s);
- leave_function();
+
return -1;
}
@@ -289,7 +284,7 @@ socket_t ssh_connect_host(ssh_session session, const char *host,
if (timeout || usec) {
socket_t ret = ssh_connect_ai_timeout(session, host, port, itr,
timeout, usec, s);
- leave_function();
+
return ret;
}
@@ -297,7 +292,6 @@ socket_t ssh_connect_host(ssh_session session, const char *host,
ssh_set_error(session, SSH_FATAL, "Connect failed: %s", strerror(errno));
ssh_connect_socket_close(s);
s = -1;
- leave_function();
continue;
} else {
/* We are connected */
@@ -306,7 +300,6 @@ socket_t ssh_connect_host(ssh_session session, const char *host,
}
freeaddrinfo(ai);
- leave_function();
return s;
}
@@ -327,13 +320,11 @@ socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host,
struct addrinfo *ai;
struct addrinfo *itr;
- enter_function();
-
rc = getai(host, port, &ai);
if (rc != 0) {
ssh_set_error(session, SSH_FATAL,
"Failed to resolve hostname %s (%s)", host, gai_strerror(rc));
- leave_function();
+
return -1;
}
@@ -396,7 +387,6 @@ socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host,
}
freeaddrinfo(ai);
- leave_function();
return s;
}
diff --git a/src/dh.c b/src/dh.c
index 97456cf5..aa01c198 100644
--- a/src/dh.c
+++ b/src/dh.c
@@ -560,7 +560,7 @@ int dh_build_k(ssh_session session) {
int ssh_client_dh_init(ssh_session session){
ssh_string e = NULL;
int rc;
- enter_function();
+
if (buffer_add_u8(session->out_buffer, SSH2_MSG_KEXDH_INIT) < 0) {
goto error;
}
@@ -592,7 +592,6 @@ int ssh_client_dh_init(ssh_session session){
ssh_string_free(e);
}
- leave_function();
return SSH_ERROR;
}
@@ -664,8 +663,6 @@ int make_sessionid(ssh_session session) {
uint32_t len;
int rc = SSH_ERROR;
- enter_function();
-
buf = ssh_buffer_new();
if (buf == NULL) {
return rc;
@@ -845,8 +842,6 @@ error:
ssh_string_free(str);
ssh_string_free(num);
- leave_function();
-
return rc;
}
@@ -920,8 +915,6 @@ int generate_session_keys(ssh_session session) {
struct ssh_crypto_struct *crypto = session->next_crypto;
int rc = -1;
- enter_function();
-
k_string = make_bignum_string(crypto->k);
if (k_string == NULL) {
ssh_set_error_oom(session);
@@ -1030,7 +1023,6 @@ int generate_session_keys(ssh_session session) {
rc = 0;
error:
ssh_string_free(k_string);
- leave_function();
return rc;
}
diff --git a/src/kex.c b/src/kex.c
index a5dcd7f8..4de5a658 100644
--- a/src/kex.c
+++ b/src/kex.c
@@ -272,7 +272,6 @@ SSH_PACKET_CALLBACK(ssh_packet_kexinit){
char *strings[KEX_METHODS_SIZE];
int i;
- enter_function();
(void)type;
(void)user;
memset(strings, 0, sizeof(strings));
@@ -335,7 +334,6 @@ SSH_PACKET_CALLBACK(ssh_packet_kexinit){
}
}
- leave_function();
session->session_state=SSH_SESSION_STATE_KEXINIT_RECEIVED;
session->dh_handshake_state=DH_STATE_INIT;
session->ssh_connection_callback(session);
@@ -347,7 +345,7 @@ error:
}
session->session_state = SSH_SESSION_STATE_ERROR;
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -395,17 +393,14 @@ int set_client_kex(ssh_session session){
int ssh_kex_select_methods (ssh_session session){
struct ssh_kex_struct *server = &session->next_crypto->server_kex;
struct ssh_kex_struct *client = &session->next_crypto->client_kex;
- int rc = SSH_ERROR;
int i;
- enter_function();
-
for (i = 0; i < KEX_METHODS_SIZE; i++) {
session->next_crypto->kex_methods[i]=ssh_find_matching(server->methods[i],client->methods[i]);
if(session->next_crypto->kex_methods[i] == NULL && i < SSH_LANG_C_S){
ssh_set_error(session,SSH_FATAL,"kex error : no match for method %s: server [%s], client [%s]",
ssh_kex_descriptions[i],server->methods[i],client->methods[i]);
- goto error;
+ return SSH_ERROR;
} else if ((i >= SSH_LANG_C_S) && (session->next_crypto->kex_methods[i] == NULL)) {
/* we can safely do that for languages */
session->next_crypto->kex_methods[i] = strdup("");
@@ -418,10 +413,8 @@ int ssh_kex_select_methods (ssh_session session){
} else if(strcmp(session->next_crypto->kex_methods[SSH_KEX], "ecdh-sha2-nistp256") == 0){
session->next_crypto->kex_type=SSH_KEX_ECDH_SHA2_NISTP256;
}
- rc = SSH_OK;
-error:
- leave_function();
- return rc;
+
+ return SSH_OK;
}
@@ -432,8 +425,6 @@ int ssh_send_kex(ssh_session session, int server_kex) {
ssh_string str = NULL;
int i;
- enter_function();
-
if (buffer_add_u8(session->out_buffer, SSH2_MSG_KEXINIT) < 0) {
goto error;
}
@@ -471,18 +462,15 @@ int ssh_send_kex(ssh_session session, int server_kex) {
}
if (packet_send(session) == SSH_ERROR) {
- leave_function();
return -1;
}
- leave_function();
return 0;
error:
buffer_reinit(session->out_buffer);
buffer_reinit(session->out_hashbuf);
ssh_string_free(str);
- leave_function();
return -1;
}
diff --git a/src/kex1.c b/src/kex1.c
index cbbf810b..22899429 100644
--- a/src/kex1.c
+++ b/src/kex1.c
@@ -317,7 +317,7 @@ SSH_PACKET_CALLBACK(ssh_packet_publickey1){
int ko;
uint32_t support_3DES = 0;
uint32_t support_DES = 0;
- enter_function();
+
(void)type;
(void)user;
SSH_LOG(SSH_LOG_PROTOCOL, "Got a SSH_SMSG_PUBLIC_KEY");
@@ -470,30 +470,28 @@ end:
publickey_free(srv);
publickey_free(host);
- leave_function();
return SSH_PACKET_USED;
}
int ssh_get_kex1(ssh_session session) {
- int ret=SSH_ERROR;
- enter_function();
SSH_LOG(SSH_LOG_PROTOCOL, "Waiting for a SSH_SMSG_PUBLIC_KEY");
+
/* Here the callback is called */
while(session->session_state==SSH_SESSION_STATE_INITIAL_KEX){
ssh_handle_packets(session, SSH_TIMEOUT_USER);
}
- if(session->session_state==SSH_SESSION_STATE_ERROR)
- goto error;
+ if (session->session_state==SSH_SESSION_STATE_ERROR) {
+ return SSH_ERROR;
+ }
SSH_LOG(SSH_LOG_PROTOCOL, "Waiting for a SSH_SMSG_SUCCESS");
/* Waiting for SSH_SMSG_SUCCESS */
while(session->session_state==SSH_SESSION_STATE_KEXINIT_RECEIVED){
ssh_handle_packets(session, SSH_TIMEOUT_USER);
}
- if(session->session_state==SSH_SESSION_STATE_ERROR)
- goto error;
+ if(session->session_state==SSH_SESSION_STATE_ERROR) {
+ return SSH_ERROR;
+ }
SSH_LOG(SSH_LOG_PROTOCOL, "received SSH_SMSG_SUCCESS\n");
- ret=SSH_OK;
-error:
- leave_function();
- return ret;
+
+ return SSH_OK;
}
diff --git a/src/known_hosts.c b/src/known_hosts.c
index 185ac157..6e9eb915 100644
--- a/src/known_hosts.c
+++ b/src/known_hosts.c
@@ -106,18 +106,15 @@ static void tokens_free(char **tokens) {
* free that value. NULL if no match was found or the file
* was not found.
*/
-static char **ssh_get_knownhost_line(ssh_session session, FILE **file,
- const char *filename, const char **found_type) {
+static char **ssh_get_knownhost_line(FILE **file, const char *filename,
+ const char **found_type) {
char buffer[4096] = {0};
char *ptr;
char **tokens;
- enter_function();
-
if(*file == NULL){
*file = fopen(filename,"r");
if (*file == NULL) {
- leave_function();
return NULL;
}
}
@@ -141,7 +138,7 @@ static char **ssh_get_knownhost_line(ssh_session session, FILE **file,
if (tokens == NULL) {
fclose(*file);
*file = NULL;
- leave_function();
+
return NULL;
}
@@ -168,7 +165,7 @@ static char **ssh_get_knownhost_line(ssh_session session, FILE **file,
continue;
}
}
- leave_function();
+
return tokens;
}
@@ -176,7 +173,6 @@ static char **ssh_get_knownhost_line(ssh_session session, FILE **file,
*file = NULL;
/* we did not find anything, end of file*/
- leave_function();
return NULL;
}
@@ -293,8 +289,8 @@ static int check_public_key(ssh_session session, char **tokens) {
*
* @returns 1 if it matches, 0 otherwise.
*/
-static int match_hashed_host(ssh_session session, const char *host,
- const char *sourcehash) {
+static int match_hashed_host(const char *host, const char *sourcehash)
+{
/* Openssh hash structure :
* |1|base64 encoded salt|base64 encoded hash
* hash is produced that way :
@@ -309,16 +305,12 @@ static int match_hashed_host(ssh_session session, const char *host,
int match;
unsigned int size;
- enter_function();
-
if (strncmp(sourcehash, "|1|", 3) != 0) {
- leave_function();
return 0;
}
source = strdup(sourcehash + 3);
if (source == NULL) {
- leave_function();
return 0;
}
@@ -326,7 +318,7 @@ static int match_hashed_host(ssh_session session, const char *host,
if (b64hash == NULL) {
/* Invalid hash */
SAFE_FREE(source);
- leave_function();
+
return 0;
}
@@ -336,7 +328,7 @@ static int match_hashed_host(ssh_session session, const char *host,
salt = base64_to_bin(source);
if (salt == NULL) {
SAFE_FREE(source);
- leave_function();
+
return 0;
}
@@ -344,7 +336,7 @@ static int match_hashed_host(ssh_session session, const char *host,
SAFE_FREE(source);
if (hash == NULL) {
ssh_buffer_free(salt);
- leave_function();
+
return 0;
}
@@ -352,7 +344,7 @@ static int match_hashed_host(ssh_session session, const char *host,
if (mac == NULL) {
ssh_buffer_free(salt);
ssh_buffer_free(hash);
- leave_function();
+
return 0;
}
size = sizeof(buffer);
@@ -372,7 +364,6 @@ static int match_hashed_host(ssh_session session, const char *host,
SSH_LOG(SSH_LOG_PACKET,
"Matching a hashed host: %s match=%d", host, match);
- leave_function();
return match;
}
@@ -421,13 +412,11 @@ int ssh_is_server_known(ssh_session session) {
int match;
int ret = SSH_SERVER_NOT_KNOWN;
- enter_function();
-
if (session->opts.knownhosts == NULL) {
if (ssh_options_apply(session) < 0) {
ssh_set_error(session, SSH_REQUEST_DENIED,
"Can't find a known_hosts file");
- leave_function();
+
return SSH_SERVER_FILE_NOT_FOUND;
}
}
@@ -435,14 +424,14 @@ int ssh_is_server_known(ssh_session session) {
if (session->opts.host == NULL) {
ssh_set_error(session, SSH_FATAL,
"Can't verify host in known hosts if the hostname isn't known");
- leave_function();
+
return SSH_SERVER_ERROR;
}
if (session->current_crypto == NULL){
ssh_set_error(session, SSH_FATAL,
"ssh_is_host_known called without cryptographic context");
- leave_function();
+
return SSH_SERVER_ERROR;
}
host = ssh_lowercase(session->opts.host);
@@ -451,13 +440,12 @@ int ssh_is_server_known(ssh_session session) {
ssh_set_error_oom(session);
SAFE_FREE(host);
SAFE_FREE(hostport);
- leave_function();
+
return SSH_SERVER_ERROR;
}
do {
- tokens = ssh_get_knownhost_line(session,
- &file,
+ tokens = ssh_get_knownhost_line(&file,
session->opts.knownhosts,
&type);
@@ -465,7 +453,7 @@ int ssh_is_server_known(ssh_session session) {
if (tokens == NULL) {
break;
}
- match = match_hashed_host(session, host, tokens[0]);
+ match = match_hashed_host(host, tokens[0]);
if (match == 0){
match = match_hostname(hostport, tokens[0], strlen(tokens[0]));
}
@@ -473,7 +461,7 @@ int ssh_is_server_known(ssh_session session) {
match = match_hostname(host, tokens[0], strlen(tokens[0]));
}
if (match == 0) {
- match = match_hashed_host(session, hostport, tokens[0]);
+ match = match_hashed_host(hostport, tokens[0]);
}
if (match) {
/* We got a match. Now check the key type */
@@ -522,7 +510,6 @@ int ssh_is_server_known(ssh_session session) {
}
/* Return the current state at end of file */
- leave_function();
return ret;
}
diff --git a/src/legacy.c b/src/legacy.c
index 7f2bb4d0..6e7bfffc 100644
--- a/src/legacy.c
+++ b/src/legacy.c
@@ -108,12 +108,10 @@ int ssh_userauth_privatekey_file(ssh_session session,
int rc = SSH_AUTH_ERROR;
size_t klen = strlen(filename) + 4 + 1;
- enter_function();
-
pubkeyfile = malloc(klen);
if (pubkeyfile == NULL) {
ssh_set_error_oom(session);
- leave_function();
+
return SSH_AUTH_ERROR;
}
snprintf(pubkeyfile, klen, "%s.pub", filename);
@@ -138,7 +136,6 @@ error:
SAFE_FREE(pubkeyfile);
ssh_string_free(pubkey);
- leave_function();
return rc;
}
diff --git a/src/messages.c b/src/messages.c
index bd925256..8a6be009 100644
--- a/src/messages.c
+++ b/src/messages.c
@@ -378,11 +378,9 @@ static int ssh_message_termination(void *s){
ssh_message ssh_message_get(ssh_session session) {
ssh_message msg = NULL;
int rc;
- enter_function();
msg=ssh_message_pop_head(session);
if(msg) {
- leave_function();
return msg;
}
if(session->ssh_message_list == NULL) {
@@ -393,7 +391,7 @@ ssh_message ssh_message_get(ssh_session session) {
if(rc || session->session_state == SSH_SESSION_STATE_ERROR)
return NULL;
msg=ssh_list_pop_head(ssh_message, session->ssh_message_list);
- leave_function();
+
return msg;
}
@@ -488,7 +486,6 @@ SSH_PACKET_CALLBACK(ssh_packet_service_request){
char *service_c = NULL;
ssh_message msg=NULL;
- enter_function();
(void)type;
(void)user;
service = buffer_get_ssh_string(packet);
@@ -514,7 +511,7 @@ error:
ssh_string_free(service);
if(msg != NULL)
ssh_message_queue(session,msg);
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -649,8 +646,6 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
char *method = NULL;
uint32_t method_size = 0;
- enter_function();
-
(void)user;
(void)type;
@@ -869,7 +864,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
SAFE_FREE(service);
SAFE_FREE(method);
ssh_message_free(msg);
- leave_function();
+
return SSH_PACKET_USED;
}
#endif
@@ -883,14 +878,13 @@ error:
ssh_message_free(msg);
- leave_function();
return SSH_PACKET_USED;
end:
SAFE_FREE(service);
SAFE_FREE(method);
ssh_message_queue(session,msg);
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -923,8 +917,6 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_info_response){
return ssh_packet_userauth_gssapi_token(session, type, packet, user);
}
#endif
- enter_function();
-
(void)user;
(void)type;
@@ -1009,13 +1001,12 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_info_response){
}
ssh_message_queue(session,msg);
- leave_function();
+
return SSH_PACKET_USED;
error:
ssh_message_free(msg);
- leave_function();
return SSH_PACKET_USED;
}
#endif /* WITH_SERVER */
@@ -1026,7 +1017,6 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_open){
char *type_c = NULL;
uint32_t sender, window, packet_size, originator_port, destination_port;
- enter_function();
(void)type;
(void)user;
msg = ssh_message_new(session);
@@ -1179,59 +1169,60 @@ end:
SAFE_FREE(type_c);
if(msg != NULL)
ssh_message_queue(session,msg);
- leave_function();
+
return SSH_PACKET_USED;
}
int ssh_message_channel_request_open_reply_accept_channel(ssh_message msg, ssh_channel chan) {
- ssh_session session;
+ ssh_session session;
+ int rc;
- enter_function();
+ if (msg == NULL) {
+ return SSH_ERROR;
+ }
- if (msg == NULL) {
- leave_function();
- return SSH_ERROR;
- }
+ session = msg->session;
- session = msg->session;
+ chan->local_channel = ssh_channel_new_id(session);
+ chan->local_maxpacket = 35000;
+ chan->local_window = 32000;
+ chan->remote_channel = msg->channel_request_open.sender;
+ chan->remote_maxpacket = msg->channel_request_open.packet_size;
+ chan->remote_window = msg->channel_request_open.window;
+ chan->state = SSH_CHANNEL_STATE_OPEN;
- chan->local_channel = ssh_channel_new_id(session);
- chan->local_maxpacket = 35000;
- chan->local_window = 32000;
- chan->remote_channel = msg->channel_request_open.sender;
- chan->remote_maxpacket = msg->channel_request_open.packet_size;
- chan->remote_window = msg->channel_request_open.window;
- chan->state = SSH_CHANNEL_STATE_OPEN;
+ rc = buffer_add_u8(session->out_buffer, SSH2_MSG_CHANNEL_OPEN_CONFIRMATION);
+ if (rc < 0) {
+ return SSH_ERROR;
+ }
- if (buffer_add_u8(session->out_buffer, SSH2_MSG_CHANNEL_OPEN_CONFIRMATION) < 0) {
- goto error;
- }
- if (buffer_add_u32(session->out_buffer, htonl(chan->remote_channel)) < 0) {
- goto error;
- }
- if (buffer_add_u32(session->out_buffer, htonl(chan->local_channel)) < 0) {
- goto error;
- }
- if (buffer_add_u32(session->out_buffer, htonl(chan->local_window)) < 0) {
- goto error;
- }
- if (buffer_add_u32(session->out_buffer, htonl(chan->local_maxpacket)) < 0) {
- goto error;
- }
+ rc = buffer_add_u32(session->out_buffer, htonl(chan->remote_channel));
+ if (rc < 0) {
+ return SSH_ERROR;
+ }
- SSH_LOG(SSH_LOG_PACKET,
- "Accepting a channel request_open for chan %d", chan->remote_channel);
+ rc =buffer_add_u32(session->out_buffer, htonl(chan->local_channel));
+ if (rc < 0) {
+ return SSH_ERROR;
+ }
- if (packet_send(session) == SSH_ERROR) {
- goto error;
- }
+ rc = buffer_add_u32(session->out_buffer, htonl(chan->local_window));
+ if (rc < 0) {
+ return SSH_ERROR;
+ }
- leave_function();
- return SSH_OK;
- error:
+ rc = buffer_add_u32(session->out_buffer, htonl(chan->local_maxpacket));
+ if (rc < 0) {
+ return SSH_ERROR;
+ }
- leave_function();
- return SSH_ERROR;
+ SSH_LOG(SSH_LOG_PACKET,
+ "Accepting a channel request_open for chan %d",
+ chan->remote_channel);
+
+ rc = packet_send(session);
+
+ return rc;
}
@@ -1278,7 +1269,7 @@ ssh_channel ssh_message_channel_request_open_reply_accept(ssh_message msg) {
int ssh_message_handle_channel_request(ssh_session session, ssh_channel channel, ssh_buffer packet,
const char *request, uint8_t want_reply) {
ssh_message msg = NULL;
- enter_function();
+
msg = ssh_message_new(session);
if (msg == NULL) {
ssh_set_error_oom(session);
@@ -1456,12 +1447,11 @@ int ssh_message_handle_channel_request(ssh_session session, ssh_channel channel,
msg->channel_request.type = SSH_CHANNEL_REQUEST_UNKNOWN;
end:
ssh_message_queue(session,msg);
- leave_function();
+
return SSH_OK;
error:
ssh_message_free(msg);
- leave_function();
return SSH_ERROR;
}
diff --git a/src/packet.c b/src/packet.c
index a47efbd7..c4b4a9a1 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -159,14 +159,12 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
goto error;
}
- enter_function();
if (session->session_state == SSH_SESSION_STATE_ERROR)
goto error;
switch(session->packet_state) {
case PACKET_STATE_INIT:
if(receivedlen < blocksize){
/* We didn't receive enough data to read at least one block size, give up */
- leave_function();
return 0;
}
memset(&session->in_packet, 0, sizeof(PACKET));
@@ -296,7 +294,7 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
receivedlen - processed,user);
processed += rc;
}
- leave_function();
+
return processed;
case PACKET_STATE_PROCESSING:
SSH_LOG(SSH_LOG_RARE, "Nested packet processing. Delaying.");
@@ -309,7 +307,7 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
error:
session->session_state= SSH_SESSION_STATE_ERROR;
- leave_function();
+
return processed;
}
@@ -359,11 +357,12 @@ void ssh_packet_process(ssh_session session, uint8_t type){
struct ssh_iterator *i;
int r=SSH_PACKET_NOT_USED;
ssh_packet_callbacks cb;
- enter_function();
+
SSH_LOG(SSH_LOG_PACKET, "Dispatching handler for packet type %d",type);
if(session->packet_callbacks == NULL){
SSH_LOG(SSH_LOG_RARE,"Packet callback is not initialized !");
- goto error;
+
+ return;
}
i=ssh_list_get_iterator(session->packet_callbacks);
while(i != NULL){
@@ -385,8 +384,6 @@ void ssh_packet_process(ssh_session session, uint8_t type){
SSH_LOG(SSH_LOG_RARE,"Couldn't do anything with packet type %d",type);
ssh_packet_send_unimplemented(session, session->recv_seq-1);
}
-error:
- leave_function();
}
/** @internal
@@ -397,7 +394,7 @@ error:
*/
int ssh_packet_send_unimplemented(ssh_session session, uint32_t seqnum){
int r;
- enter_function();
+
r = buffer_add_u8(session->out_buffer, SSH2_MSG_UNIMPLEMENTED);
if (r < 0) {
return SSH_ERROR;
@@ -407,7 +404,7 @@ int ssh_packet_send_unimplemented(ssh_session session, uint32_t seqnum){
return SSH_ERROR;
}
r = packet_send(session);
- leave_function();
+
return r;
}
@@ -430,23 +427,18 @@ SSH_PACKET_CALLBACK(ssh_packet_unimplemented){
* @parse the "Type" header field of a packet and updates the session
*/
int ssh_packet_parse_type(ssh_session session) {
- enter_function();
-
memset(&session->in_packet, 0, sizeof(PACKET));
if(session->in_buffer == NULL) {
- leave_function();
return SSH_ERROR;
}
if(buffer_get_u8(session->in_buffer, &session->in_packet.type) == 0) {
ssh_set_error(session, SSH_FATAL, "Packet too short to read type");
- leave_function();
return SSH_ERROR;
}
session->in_packet.valid = 1;
- leave_function();
return SSH_OK;
}
@@ -457,12 +449,10 @@ int ssh_packet_parse_type(ssh_session session) {
static int ssh_packet_write(ssh_session session) {
int rc = SSH_ERROR;
- enter_function();
-
rc=ssh_socket_write(session->socket,
buffer_get_rest(session->out_buffer),
buffer_get_rest_len(session->out_buffer));
- leave_function();
+
return rc;
}
@@ -476,8 +466,6 @@ static int packet_send2(ssh_session session) {
uint32_t finallen,payloadsize,compsize;
uint8_t padding;
- enter_function();
-
payloadsize = currentlen;
#ifdef WITH_ZLIB
if (session->current_crypto
@@ -537,7 +525,7 @@ static int packet_send2(ssh_session session) {
rc = SSH_ERROR;
}
error:
- leave_function();
+
return rc; /* SSH_OK, AGAIN or ERROR */
}
diff --git a/src/packet1.c b/src/packet1.c
index 1c3efbaa..7ac8318d 100644
--- a/src/packet1.c
+++ b/src/packet1.c
@@ -108,7 +108,6 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
uint32_t crc;
uint32_t len;
ssh_session session=(ssh_session)user;
- enter_function();
switch (session->packet_state){
case PACKET_STATE_INIT:
@@ -126,7 +125,6 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
}
/* must have at least enough bytes for size */
if(receivedlen < sizeof(uint32_t)){
- leave_function();
return 0;
}
memcpy(&len,data,sizeof(uint32_t));
@@ -152,7 +150,6 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
to_be_read = len + padding;
if(to_be_read + processed > receivedlen){
/* wait for rest of packet */
- leave_function();
return processed;
}
/* it is _not_ possible that to_be_read be < 8. */
@@ -236,7 +233,7 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
receivedlen - processed,user);
processed += rc;
}
- leave_function();
+
return processed;
case PACKET_STATE_PROCESSING:
SSH_LOG(SSH_LOG_RARE, "Nested packet processing. Delaying.");
@@ -245,7 +242,7 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
error:
session->session_state=SSH_SESSION_STATE_ERROR;
- leave_function();
+
return processed;
}
@@ -260,7 +257,6 @@ int packet_send1(ssh_session session) {
uint32_t crc;
uint8_t padding;
- enter_function();
SSH_LOG(SSH_LOG_PACKET,"Sending a %d bytes long packet",currentlen);
/* TODO FIXME
@@ -323,7 +319,7 @@ int packet_send1(ssh_session session) {
rc = SSH_ERROR;
}
error:
- leave_function();
+
return rc; /* SSH_OK, AGAIN or ERROR */
}
diff --git a/src/packet_cb.c b/src/packet_cb.c
index 75f91947..4a8beb54 100644
--- a/src/packet_cb.c
+++ b/src/packet_cb.c
@@ -236,10 +236,10 @@ SSH_PACKET_CALLBACK(ssh_packet_service_accept){
(void)packet;
(void)type;
(void)user;
- enter_function();
+
session->auth_service_state=SSH_AUTH_SERVICE_ACCEPTED;
SSH_LOG(SSH_LOG_PACKET,
"Received SSH_MSG_SERVICE_ACCEPT");
- leave_function();
+
return SSH_PACKET_USED;
}
diff --git a/src/server.c b/src/server.c
index 59581ec1..3ea2841b 100644
--- a/src/server.c
+++ b/src/server.c
@@ -167,7 +167,7 @@ SSH_PACKET_CALLBACK(ssh_packet_kexdh_init){
int rc;
(void)type;
(void)user;
- enter_function();
+
SSH_LOG(SSH_LOG_PACKET,"Received SSH_MSG_KEXDH_INIT");
if(session->dh_handshake_state != DH_STATE_INIT){
SSH_LOG(SSH_LOG_RARE,"Invalid state for SSH_MSG_KEXDH_INIT");
@@ -190,7 +190,7 @@ SSH_PACKET_CALLBACK(ssh_packet_kexdh_init){
if (rc == SSH_ERROR)
session->session_state = SSH_SESSION_STATE_ERROR;
error:
- leave_function();
+
return SSH_PACKET_USED;
}
@@ -317,7 +317,7 @@ static int dh_handshake_server(ssh_session session) {
*/
static void ssh_server_connection_callback(ssh_session session){
int ssh1,ssh2;
- enter_function();
+
switch(session->session_state){
case SSH_SESSION_STATE_NONE:
case SSH_SESSION_STATE_CONNECTING:
@@ -442,13 +442,12 @@ static void ssh_server_connection_callback(ssh_session session){
default:
ssh_set_error(session,SSH_FATAL,"Invalid state %d",session->session_state);
}
- leave_function();
+
return;
- error:
+error:
ssh_socket_close(session->socket);
session->alive = 0;
session->session_state=SSH_SESSION_STATE_ERROR;
- leave_function();
}
/**
@@ -469,8 +468,6 @@ static int callback_receive_banner(const void *data, size_t len, void *user) {
size_t i;
int ret=0;
- enter_function();
-
for (i = 0; i < len; i++) {
#ifdef WITH_PCAP
if(session->pcap_ctx && buffer[i] == '\n') {
@@ -496,7 +493,6 @@ static int callback_receive_banner(const void *data, size_t len, void *user) {
SSH_LOG(SSH_LOG_PACKET, "Received banner: %s", str);
session->ssh_connection_callback(session);
- leave_function();
return ret;
}
@@ -505,12 +501,10 @@ static int callback_receive_banner(const void *data, size_t len, void *user) {
session->session_state = SSH_SESSION_STATE_ERROR;
ssh_set_error(session, SSH_FATAL, "Receiving banner: too large banner");
- leave_function();
return 0;
}
}
- leave_function();
return ret;
}
@@ -584,8 +578,6 @@ int ssh_auth_reply_default(ssh_session session,int partial) {
ssh_string methods = NULL;
int rc = SSH_ERROR;
- enter_function();
-
if (buffer_add_u8(session->out_buffer, SSH2_MSG_USERAUTH_FAILURE) < 0) {
return rc;
}
@@ -647,7 +639,6 @@ int ssh_auth_reply_default(ssh_session session,int partial) {
error:
ssh_string_free(methods);
- leave_function();
return rc;
}
diff --git a/src/session.c b/src/session.c
index 61e14320..db7e0f99 100644
--- a/src/session.c
+++ b/src/session.c
@@ -89,7 +89,6 @@ ssh_session ssh_new(void) {
session->alive = 0;
session->auth_methods = 0;
ssh_set_blocking(session, 1);
- session->common.log_indent = 0;
session->maxchannel = FIRST_CHANNEL;
#ifndef _WIN32
@@ -286,8 +285,6 @@ const char* ssh_get_serverbanner(ssh_session session) {
* @param[in] session The SSH session to disconnect.
*/
void ssh_silent_disconnect(ssh_session session) {
- enter_function();
-
if (session == NULL) {
return;
}
@@ -295,7 +292,6 @@ void ssh_silent_disconnect(ssh_session session) {
ssh_socket_close(session->socket);
session->alive = 0;
ssh_disconnect(session);
- leave_function();
}
/**
@@ -347,20 +343,21 @@ static int ssh_flush_termination(void *c){
*/
int ssh_blocking_flush(ssh_session session, int timeout){
- int rc;
- if(!session)
- return SSH_ERROR;
- enter_function();
-
- rc = ssh_handle_packets_termination(session, timeout,
- ssh_flush_termination, session);
- if (rc == SSH_ERROR)
- goto end;
- if (!ssh_flush_termination(session))
- rc = SSH_AGAIN;
-end:
- leave_function();
- return rc;
+ int rc;
+ if (session == NULL) {
+ return SSH_ERROR;
+ }
+
+ rc = ssh_handle_packets_termination(session, timeout,
+ ssh_flush_termination, session);
+ if (rc == SSH_ERROR) {
+ return rc;
+ }
+ if (!ssh_flush_termination(session)) {
+ rc = SSH_AGAIN;
+ }
+
+ return rc;
}
/**
@@ -464,7 +461,6 @@ int ssh_handle_packets(ssh_session session, int timeout) {
if (session == NULL || session->socket == NULL) {
return SSH_ERROR;
}
- enter_function();
spoll_in = ssh_socket_get_poll_handle_in(session->socket);
spoll_out = ssh_socket_get_poll_handle_out(session->socket);
@@ -493,7 +489,6 @@ int ssh_handle_packets(ssh_session session, int timeout) {
session->session_state = SSH_SESSION_STATE_ERROR;
}
- leave_function();
return rc;
}
@@ -640,12 +635,11 @@ int ssh_get_version(ssh_session session) {
*/
void ssh_socket_exception_callback(int code, int errno_code, void *user){
ssh_session session=(ssh_session)user;
- enter_function();
+
SSH_LOG(SSH_LOG_RARE,"Socket exception callback: %d (%d)",code, errno_code);
session->session_state=SSH_SESSION_STATE_ERROR;
ssh_set_error(session,SSH_FATAL,"Socket error: %s",strerror(errno_code));
session->ssh_connection_callback(session);
- leave_function();
}
/**
diff --git a/src/sftp.c b/src/sftp.c
index a4670384..62460b4d 100644
--- a/src/sftp.c
+++ b/src/sftp.c
@@ -106,12 +106,11 @@ sftp_session sftp_new(ssh_session session){
if (session == NULL) {
return NULL;
}
- enter_function();
sftp = malloc(sizeof(struct sftp_session_struct));
if (sftp == NULL) {
ssh_set_error_oom(session);
- leave_function();
+
return NULL;
}
ZERO_STRUCTP(sftp);
@@ -120,7 +119,7 @@ sftp_session sftp_new(ssh_session session){
if (sftp->ext == NULL) {
ssh_set_error_oom(session);
SAFE_FREE(sftp);
- leave_function();
+
return NULL;
}
@@ -128,24 +127,23 @@ sftp_session sftp_new(ssh_session session){
sftp->channel = ssh_channel_new(session);
if (sftp->channel == NULL) {
SAFE_FREE(sftp);
- leave_function();
+
return NULL;
}
if (ssh_channel_open_session(sftp->channel)) {
ssh_channel_free(sftp->channel);
SAFE_FREE(sftp);
- leave_function();
+
return NULL;
}
if (ssh_channel_request_sftp(sftp->channel)) {
sftp_free(sftp);
- leave_function();
+
return NULL;
}
- leave_function();
return sftp;
}
@@ -155,12 +153,11 @@ sftp_session sftp_new_channel(ssh_session session, ssh_channel channel){
if (session == NULL) {
return NULL;
}
- enter_function();
sftp = malloc(sizeof(struct sftp_session_struct));
if (sftp == NULL) {
ssh_set_error_oom(session);
- leave_function();
+
return NULL;
}
ZERO_STRUCTP(sftp);
@@ -169,14 +166,13 @@ sftp_session sftp_new_channel(ssh_session session, ssh_channel channel){
if (sftp->ext == NULL) {
ssh_set_error_oom(session);
SAFE_FREE(sftp);
- leave_function();
+
return NULL;
}
sftp->session = session;
sftp->channel = channel;
- leave_function();
return sftp;
}
diff --git a/src/socket.c b/src/socket.c
index 5f7e754a..0dbbe2bc 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -593,8 +593,6 @@ void ssh_socket_fd_set(ssh_socket s, fd_set *set, socket_t *max_fd) {
* \warning has no effect on socket before a flush
*/
int ssh_socket_write(ssh_socket s, const void *buffer, int len) {
- ssh_session session = s->session;
- enter_function();
if(len > 0) {
if (buffer_add_data(s->out_buffer, buffer, len) < 0) {
ssh_set_error_oom(s->session);
@@ -602,7 +600,7 @@ int ssh_socket_write(ssh_socket s, const void *buffer, int len) {
}
ssh_socket_nonblocking_flush(s);
}
- leave_function();
+
return SSH_OK;
}
@@ -616,8 +614,6 @@ int ssh_socket_nonblocking_flush(ssh_socket s) {
uint32_t len;
int w;
- enter_function();
-
if (!ssh_socket_is_open(s)) {
session->alive = 0;
/* FIXME use ssh_socket_get_errno */
@@ -625,7 +621,6 @@ int ssh_socket_nonblocking_flush(ssh_socket s) {
"Writing packet: error on socket (or connection closed): %s",
strerror(s->last_errno));
- leave_function();
return SSH_ERROR;
}
@@ -633,7 +628,7 @@ int ssh_socket_nonblocking_flush(ssh_socket s) {
if (!s->write_wontblock && s->poll_out && len > 0) {
/* force the poll system to catch pollout events */
ssh_poll_add_events(s->poll_out, POLLOUT);
- leave_function();
+
return SSH_AGAIN;
}
if (s->write_wontblock && len > 0) {
@@ -646,7 +641,7 @@ int ssh_socket_nonblocking_flush(ssh_socket s) {
ssh_set_error(session, SSH_FATAL,
"Writing packet: error on socket (or connection closed): %s",
strerror(s->last_errno));
- leave_function();
+
return SSH_ERROR;
}
buffer_pass_bytes(s->out_buffer, w);
@@ -657,12 +652,11 @@ int ssh_socket_nonblocking_flush(ssh_socket s) {
if (s->poll_out && len > 0) {
/* force the poll system to catch pollout events */
ssh_poll_add_events(s->poll_out, POLLOUT);
- leave_function();
+
return SSH_AGAIN;
}
/* all data written */
- leave_function();
return SSH_OK;
}
@@ -754,8 +748,7 @@ int ssh_socket_set_blocking(socket_t fd) {
int ssh_socket_connect(ssh_socket s, const char *host, int port, const char *bind_addr){
socket_t fd;
- ssh_session session=s->session;
- enter_function();
+
if(s->state != SSH_SOCKET_NONE) {
ssh_set_error(s->session, SSH_FATAL,
"ssh_socket_connect called on socket not unconnected");
@@ -772,7 +765,7 @@ int ssh_socket_connect(ssh_socket s, const char *host, int port, const char *bin
#ifdef _WIN32
ssh_poll_add_events(ssh_socket_get_poll_handle_in(s),POLLWRNORM);
#endif
- leave_function();
+
return SSH_OK;
}
@@ -811,8 +804,7 @@ int ssh_socket_connect_proxycommand(ssh_socket s, const char *command){
socket_t out_pipe[2];
int pid;
int rc;
- ssh_session session=s->session;
- enter_function();
+
if(s->state != SSH_SOCKET_NONE)
return SSH_ERROR;
@@ -842,7 +834,7 @@ int ssh_socket_connect_proxycommand(ssh_socket s, const char *command){
ssh_poll_set_events(ssh_socket_get_poll_handle_out(s),POLLOUT);
if(s->callbacks && s->callbacks->connected)
s->callbacks->connected(SSH_SOCKET_CONNECTED_OK,0,s->callbacks->userdata);
- leave_function();
+
return SSH_OK;
}
diff --git a/src/wrapper.c b/src/wrapper.c
index c5260a25..0b26178a 100644
--- a/src/wrapper.c
+++ b/src/wrapper.c
@@ -166,10 +166,8 @@ void crypto_free(struct ssh_crypto_struct *crypto){
static int crypt_set_algorithms2(ssh_session session){
const char *wanted;
int i = 0;
- int rc = SSH_ERROR;
struct ssh_cipher_struct *ssh_ciphertab=ssh_get_ciphertab();
- enter_function();
/* we must scan the kex entries to find crypto algorithms and set their appropriate structure */
/* out */
wanted = session->next_crypto->kex_methods[SSH_CRYPT_C_S];
@@ -181,14 +179,14 @@ static int crypt_set_algorithms2(ssh_session session){
ssh_set_error(session, SSH_FATAL,
"crypt_set_algorithms2: no crypto algorithm function found for %s",
wanted);
- goto error;
+ return SSH_ERROR;
}
SSH_LOG(SSH_LOG_PACKET, "Set output algorithm to %s", wanted);
session->next_crypto->out_cipher = cipher_new(i);
if (session->next_crypto->out_cipher == NULL) {
- ssh_set_error_oom(session);
- goto error;
+ ssh_set_error_oom(session);
+ return SSH_ERROR;
}
i = 0;
@@ -199,17 +197,17 @@ static int crypt_set_algorithms2(ssh_session session){
}
if (ssh_ciphertab[i].name == NULL) {
- ssh_set_error(session, SSH_FATAL,
- "Crypt_set_algorithms: no crypto algorithm function found for %s",
- wanted);
- goto error;
+ ssh_set_error(session, SSH_FATAL,
+ "Crypt_set_algorithms: no crypto algorithm function found for %s",
+ wanted);
+ return SSH_ERROR;
}
SSH_LOG(SSH_LOG_PACKET, "Set input algorithm to %s", wanted);
session->next_crypto->in_cipher = cipher_new(i);
if (session->next_crypto->in_cipher == NULL) {
- ssh_set_error_oom(session);
- goto error;
+ ssh_set_error_oom(session);
+ return SSH_ERROR;
}
/* compression */
@@ -225,10 +223,8 @@ static int crypt_set_algorithms2(ssh_session session){
if (strcmp(session->next_crypto->kex_methods[SSH_COMP_S_C], "zlib@openssh.com") == 0) {
session->next_crypto->delayed_compress_in = 1;
}
- rc = SSH_OK;
-error:
- leave_function();
- return rc;
+
+ return SSH_OK;
}
static int crypt_set_algorithms1(ssh_session session, enum ssh_des_e des_type) {
@@ -270,15 +266,16 @@ int crypt_set_algorithms(ssh_session session, enum ssh_des_e des_type) {
int crypt_set_algorithms_server(ssh_session session){
char *method = NULL;
int i = 0;
- int rc = SSH_ERROR;
struct ssh_cipher_struct *ssh_ciphertab=ssh_get_ciphertab();
if (session == NULL) {
return SSH_ERROR;
}
- /* we must scan the kex entries to find crypto algorithms and set their appropriate structure */
- enter_function();
+ /*
+ * We must scan the kex entries to find crypto algorithms and set their
+ * appropriate structure
+ */
/* out */
method = session->next_crypto->kex_methods[SSH_CRYPT_S_C];
while(ssh_ciphertab[i].name && strcmp(method,ssh_ciphertab[i].name))
@@ -286,14 +283,14 @@ int crypt_set_algorithms_server(ssh_session session){
if(!ssh_ciphertab[i].name){
ssh_set_error(session,SSH_FATAL,"crypt_set_algorithms_server : "
"no crypto algorithm function found for %s",method);
- goto error;
+ return SSH_ERROR;
}
SSH_LOG(SSH_LOG_PACKET,"Set output algorithm %s",method);
session->next_crypto->out_cipher = cipher_new(i);
if (session->next_crypto->out_cipher == NULL) {
- ssh_set_error_oom(session);
- goto error;
+ ssh_set_error_oom(session);
+ return SSH_ERROR;
}
i=0;
/* in */
@@ -303,14 +300,14 @@ int crypt_set_algorithms_server(ssh_session session){
if(!ssh_ciphertab[i].name){
ssh_set_error(session,SSH_FATAL,"Crypt_set_algorithms_server :"
"no crypto algorithm function found for %s",method);
- goto error;
+ return SSH_ERROR;
}
SSH_LOG(SSH_LOG_PACKET,"Set input algorithm %s",method);
session->next_crypto->in_cipher = cipher_new(i);
if (session->next_crypto->in_cipher == NULL) {
- ssh_set_error_oom(session);
- goto error;
+ ssh_set_error_oom(session);
+ return SSH_ERROR;
}
/* compression */
@@ -321,7 +318,7 @@ int crypt_set_algorithms_server(ssh_session session){
}
if(strcmp(method,"zlib@openssh.com") == 0){
ssh_set_error(session,SSH_FATAL,"zlib@openssh.com not supported");
- goto error;
+ return SSH_ERROR;
}
method = session->next_crypto->kex_methods[SSH_CRYPT_S_C];
if(strcmp(method,"zlib") == 0){
@@ -330,15 +327,13 @@ int crypt_set_algorithms_server(ssh_session session){
}
if(strcmp(method,"zlib@openssh.com") == 0){
ssh_set_error(session,SSH_FATAL,"zlib@openssh.com not supported");
- goto error;
+ return SSH_ERROR;
}
method = session->next_crypto->kex_methods[SSH_HOSTKEYS];
session->srv.hostkey = ssh_key_type_from_name(method);
- rc = SSH_OK;
- error:
- leave_function();
- return rc;
+
+ return SSH_OK;
}
#endif /* WITH_SERVER */