From dab511835c26a5fabd5ae6e793d9ef584b670c06 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Mon, 19 Feb 2007 20:36:52 +0000 Subject: [PATCH] Fixed connection authentication protocol aborting. --- lib/silcclient/client_connect.c | 2 +- lib/silccore/silcpacket.c | 5 +++-- lib/silcske/silcconnauth.c | 29 +++++++++++++++++++---------- lib/silcske/silcske.c | 5 +++++ lib/silcske/silcske_i.h | 1 + 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/lib/silcclient/client_connect.c b/lib/silcclient/client_connect.c index 95b0bff1..765eba24 100644 --- a/lib/silcclient/client_connect.c +++ b/lib/silcclient/client_connect.c @@ -316,7 +316,7 @@ static void silc_client_connect_auth_completion(SilcConnAuth connauth, silc_fsm_next(fsm, silc_client_st_connect_error); } - SILC_FSM_CALL_CONTINUE(fsm); + SILC_FSM_CALL_CONTINUE_SYNC(fsm); } /********************** CONNECTION_AUTH_REQUEST packet **********************/ diff --git a/lib/silccore/silcpacket.c b/lib/silccore/silcpacket.c index ff6fdee6..8f1bded4 100644 --- a/lib/silccore/silcpacket.c +++ b/lib/silccore/silcpacket.c @@ -862,8 +862,9 @@ void silc_packet_stream_destroy(SilcPacketStream stream) /* Delete from UDP remote hash table */ char tuple[64]; engine = stream->sc->engine; - silc_snprintf(tuple, sizeof(tuple), "%d%s", stream->remote_udp->remote_port, - stream->remote_udp->remote_ip); + silc_snprintf(tuple, sizeof(tuple), "%d%s", + stream->remote_udp->remote_port + stream->remote_udp->remote_ip); silc_mutex_lock(engine->lock); silc_hash_table_del(engine->udp_remote, tuple); silc_mutex_unlock(engine->lock); diff --git a/lib/silcske/silcconnauth.c b/lib/silcske/silcconnauth.c index b5e59ab5..ecd515f0 100644 --- a/lib/silcske/silcconnauth.c +++ b/lib/silcske/silcconnauth.c @@ -227,6 +227,7 @@ SilcConnAuth silc_connauth_alloc(SilcSchedule schedule, connauth->timeout_secs = timeout_secs; connauth->ske = ske; + ske->refcnt++; return connauth; } @@ -237,6 +238,10 @@ void silc_connauth_free(SilcConnAuth connauth) { if (connauth->public_keys) silc_dlist_uninit(connauth->public_keys); + + /* Free reference */ + silc_ske_free(connauth->ske); + silc_free(connauth); } @@ -374,12 +379,14 @@ SILC_FSM_STATE(silc_connauth_st_initiator_failure) SILC_LOG_DEBUG(("Start")); - /* Send FAILURE packet */ - SILC_PUT32_MSB(SILC_AUTH_FAILED, error); - silc_packet_send(connauth->ske->stream, SILC_PACKET_FAILURE, 0, error, 4); + if (!connauth->aborted) { + /* Send FAILURE packet */ + SILC_PUT32_MSB(SILC_AUTH_FAILED, error); + silc_packet_send(connauth->ske->stream, SILC_PACKET_FAILURE, 0, error, 4); - /* Call completion callback */ - connauth->completion(connauth, FALSE, connauth->context); + /* Call completion callback */ + connauth->completion(connauth, FALSE, connauth->context); + } silc_packet_stream_unlink(connauth->ske->stream, &silc_connauth_stream_cbs, connauth); @@ -663,12 +670,14 @@ SILC_FSM_STATE(silc_connauth_st_responder_failure) SILC_LOG_ERROR(("Authentication failed")); - /* Send FAILURE packet */ - SILC_PUT32_MSB(SILC_AUTH_FAILED, error); - silc_packet_send(connauth->ske->stream, SILC_PACKET_FAILURE, 0, error, 4); + if (!connauth->aborted) { + /* Send FAILURE packet */ + SILC_PUT32_MSB(SILC_AUTH_FAILED, error); + silc_packet_send(connauth->ske->stream, SILC_PACKET_FAILURE, 0, error, 4); - /* Call completion callback */ - connauth->completion(connauth, FALSE, connauth->context); + /* Call completion callback */ + connauth->completion(connauth, FALSE, connauth->context); + } silc_packet_stream_unlink(connauth->ske->stream, &silc_connauth_stream_cbs, connauth); diff --git a/lib/silcske/silcske.c b/lib/silcske/silcske.c index a7261743..cf97428e 100644 --- a/lib/silcske/silcske.c +++ b/lib/silcske/silcske.c @@ -1035,6 +1035,7 @@ SilcSKE silc_ske_alloc(SilcRng rng, SilcSchedule schedule, ske->public_key = public_key; ske->private_key = private_key; ske->retry_timer = SILC_SKE_RETRY_MIN; + ske->refcnt = 1; return ske; } @@ -1064,6 +1065,10 @@ void silc_ske_free(SilcSKE ske) return; } + ske->refcnt--; + if (ske->refcnt > 0) + return; + /* Free start payload */ if (ske->start_payload) silc_ske_payload_start_free(ske->start_payload); diff --git a/lib/silcske/silcske_i.h b/lib/silcske/silcske_i.h index ba75050a..05132455 100644 --- a/lib/silcske/silcske_i.h +++ b/lib/silcske/silcske_i.h @@ -88,6 +88,7 @@ struct SilcSKEStruct { } retrans; SilcUInt16 timeout; /* SKE timeout */ + SilcUInt16 refcnt; /* Reference counter */ unsigned int aborted : 1; /* Set when SKE aborted */ unsigned int freed : 1; /* Set when freed during session */ -- 2.24.0