Fixed connection authentication protocol aborting.
authorPekka Riikonen <priikone@silcnet.org>
Mon, 19 Feb 2007 20:36:52 +0000 (20:36 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Mon, 19 Feb 2007 20:36:52 +0000 (20:36 +0000)
lib/silcclient/client_connect.c
lib/silccore/silcpacket.c
lib/silcske/silcconnauth.c
lib/silcske/silcske.c
lib/silcske/silcske_i.h

index 95b0bff1dffc5dcf04ca49c3a30df2510d747ec6..765eba24d629094210fb6a3f756465ee5b702538 100644 (file)
@@ -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 **********************/
index ff6fdee6e8aa9ad526d2501b0a2db3c8a66c8c4f..8f1bded4ebaa69fb9ae6ccb8f94b810e3cc7f195 100644 (file)
@@ -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);
index b5e59ab53af9cf37539b2763d1471f2555f23b0d..ecd515f084363d3f097dcfa442e60fba27a19132 100644 (file)
@@ -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);
index a726174339bde711d2108432905668a7fbc5fb37..cf97428eeed0d291334d2db4c2c778d619035939 100644 (file)
@@ -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);
index ba75050a2fb9372ade1320e7b80c4ae5f9271dd9..051324550b66727f0f413281fae1b8466df22b40 100644 (file)
@@ -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 */