updates.
authorPekka Riikonen <priikone@silcnet.org>
Fri, 29 Jun 2001 16:46:39 +0000 (16:46 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Fri, 29 Jun 2001 16:46:39 +0000 (16:46 +0000)
CHANGES
apps/silcd/packet_send.c
apps/silcd/protocol.c
apps/silcd/server.c
includes/silcwin32.h
lib/silccrypt/silcrng.c
lib/silccrypt/silcrng.h

diff --git a/CHANGES b/CHANGES
index eda8d82ef0dfe7874a41f4b192ee794b521bcd50..17073f9f2126a72b2fcea4d7c838b51a8445d2c2 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,26 @@
+Fri Jun 29 20:05:25 EEST 2001  Pekka Riikonen <priikone@silcnet.org>
+
+       * Assure that sock->user_data is not NULL in the function
+         silc_server_packet_send in silcd/packet_send.c.
+
+       * Disconnect the remote connection if it could not be added
+         to any ID lists in the server.  The affected file is
+         silcd/server.c.
+
+       * Check in silc_server_packet_send[_real/dest] that the
+         socket is not disconnecting and ignore the data if it is.
+         Affected file silcd/packet_send.c.
+
+       * Define inline to __inline on native WIN32 compilation.
+         Affected file includes/silcwin32.h.
+
+       * Added some explicit type casts for inline code since MSVC
+         require them.  Affected files lib/silcutil/silcbuffer.h,
+         lib/trq/silcdlist.h and lib/trq/silclist.h.
+
+       * Print warning in log files from now on if the packet
+         decryption fails.  Affected file silcd/server.c.
+
 Thu Jun 28 21:30:39 EEST 2001  Pekka Riikonen <priikone@silcnet.org>
 
        * Changed the `say' client operation's interface to accept
index 81cdce5259489f4fafba35d7c302a6718bc2a1fb..25fc39072879b4404894bb70ae5e8357cfd4b17c 100644 (file)
@@ -2,7 +2,7 @@
 
   packet_send.c
 
-  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+  Author: Pekka Riikonen <priikone@silcnet.org>
 
   Copyright (C) 1997 - 2001 Pekka Riikonen
 
@@ -35,6 +35,10 @@ int silc_server_packet_send_real(SilcServer server,
 {
   int ret;
 
+  /* If disconnecting, ignore the data */
+  if (SILC_IS_DISCONNECTING(sock))
+    return -1;
+
   /* If rekey protocol is active we must assure that all packets are
      sent through packet queue. */
   if (SILC_SERVER_IS_REKEY(sock))
@@ -79,16 +83,24 @@ void silc_server_packet_send(SilcServer server,
   if (!sock)
     return;
 
+  /* If disconnecting, ignore the data */
+  if (SILC_IS_DISCONNECTING(sock))
+    return;
+
   /* Get data used in the packet sending, keys and stuff */
   switch(sock->type) {
   case SILC_SOCKET_TYPE_CLIENT:
-    dst_id = ((SilcClientEntry)sock->user_data)->id;
-    dst_id_type = SILC_ID_CLIENT;
+    if (sock->user_data) {
+      dst_id = ((SilcClientEntry)sock->user_data)->id;
+      dst_id_type = SILC_ID_CLIENT;
+    }
     break;
   case SILC_SOCKET_TYPE_SERVER:
   case SILC_SOCKET_TYPE_ROUTER:
-    dst_id = ((SilcServerEntry)sock->user_data)->id;
-    dst_id_type = SILC_ID_SERVER;
+    if (sock->user_data) {
+      dst_id = ((SilcServerEntry)sock->user_data)->id;
+      dst_id_type = SILC_ID_SERVER;
+    }
     break;
   default:
     break;
@@ -122,6 +134,10 @@ void silc_server_packet_send_dest(SilcServer server,
   unsigned char *dst_id_data = NULL;
   uint32 dst_id_len = 0;
 
+  /* If disconnecting, ignore the data */
+  if (SILC_IS_DISCONNECTING(sock))
+    return;
+
   SILC_LOG_DEBUG(("Sending packet, type %d", type));
 
   /* Get data used in the packet sending, keys and stuff */
index 0299a5ade6f3ae09b7daf9d36a69c7bbf4295630..76b45942c181af39f42382afa64e5c7cf8eb3920 100644 (file)
@@ -2,7 +2,7 @@
 
   protocol.c
 
-  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+  Author: Pekka Riikonen <priikone@silcnet.org>
 
   Copyright (C) 1997 - 2001 Pekka Riikonen
 
index 4dde2b3669afbcfe10142922138560469e23b234..ea75773096a11ea98029697a732eaf5c0ac15713 100644 (file)
@@ -2,7 +2,7 @@
 
   server.c
 
-  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+  Author: Pekka Riikonen <priikone@silcnet.org>
 
   Copyright (C) 1997 - 2001 Pekka Riikonen
 
@@ -1224,8 +1224,7 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_final)
     return;
   }
 
-  sock->type = ctx->conn_type;
-  switch(sock->type) {
+  switch(ctx->conn_type) {
   case SILC_SOCKET_TYPE_CLIENT:
     {
       SilcClientEntry client;
@@ -1242,7 +1241,11 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_final)
       if (!client) {
        SILC_LOG_ERROR(("Could not add new client to cache"));
        silc_free(sock->user_data);
-       break;
+       silc_server_disconnect_remote(server, sock, 
+                                     "Server closed connection: "
+                                     "Authentication failed");
+       server->stat.auth_failures++;
+       goto out;
       }
 
       /* Statistics */
@@ -1259,13 +1262,14 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_final)
     {
       SilcServerEntry new_server;
       SilcServerConfigSectionServerConnection *conn = 
-       sock->type == SILC_SOCKET_TYPE_SERVER ? ctx->sconfig : ctx->rconfig;
+       ctx->conn_type == SILC_SOCKET_TYPE_SERVER ? 
+       ctx->sconfig : ctx->rconfig;
 
       SILC_LOG_DEBUG(("Remote host is %s", 
-                     sock->type == SILC_SOCKET_TYPE_SERVER ? 
+                     ctx->conn_type == SILC_SOCKET_TYPE_SERVER ? 
                      "server" : "router"));
       SILC_LOG_INFO(("Connection from %s (%s) is %s", sock->hostname,
-                    sock->ip, sock->type == SILC_SOCKET_TYPE_SERVER ? 
+                    sock->ip, ctx->conn_type == SILC_SOCKET_TYPE_SERVER ? 
                     "server" : "router"));
 
       /* Add the server into server cache. The server name and Server ID
@@ -1274,18 +1278,22 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_final)
         are router. */
       new_server = 
        silc_idlist_add_server(server->local_list, NULL,
-                              sock->type == SILC_SOCKET_TYPE_SERVER ?
+                              ctx->conn_type == SILC_SOCKET_TYPE_SERVER ?
                               SILC_SERVER : SILC_ROUTER, NULL, 
-                              sock->type == SILC_SOCKET_TYPE_SERVER ?
+                              ctx->conn_type == SILC_SOCKET_TYPE_SERVER ?
                               server->id_entry : NULL, sock);
       if (!new_server) {
        SILC_LOG_ERROR(("Could not add new server to cache"));
        silc_free(sock->user_data);
-       break;
+       silc_server_disconnect_remote(server, sock, 
+                                     "Server closed connection: "
+                                     "Authentication failed");
+       server->stat.auth_failures++;
+       goto out;
       }
 
       /* Statistics */
-      if (sock->type == SILC_SOCKET_TYPE_SERVER)
+      if (ctx->conn_type == SILC_SOCKET_TYPE_SERVER)
        server->stat.my_servers++;
       else
        server->stat.my_routers++;
@@ -1295,7 +1303,7 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_final)
 
       /* Check whether this connection is to be our primary router connection
         if we dont' already have the primary route. */
-      if (server->standalone && sock->type == SILC_SOCKET_TYPE_ROUTER) {
+      if (server->standalone && ctx->conn_type == SILC_SOCKET_TYPE_ROUTER) {
        if (silc_server_config_is_primary_route(server->config) &&
            !conn->initiator)
          break;
@@ -1314,6 +1322,8 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_final)
     break;
   }
 
+  sock->type = ctx->conn_type;
+
   /* Add the common data structure to the ID entry. */
   if (id_entry)
     silc_idlist_add_data(id_entry, (SilcIDListData)sock->user_data);
@@ -1334,6 +1344,7 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_final)
                            silc_server_perform_heartbeat,
                            server->timeout_queue);
 
+ out:
   silc_task_unregister_by_callback(server->timeout_queue,
                                   silc_server_failure_callback);
   silc_protocol_free(protocol);
@@ -1512,8 +1523,15 @@ SILC_TASK_CALLBACK(silc_server_packet_parse_real)
                            idata ? idata->hmac_receive : NULL, 
                            packet->buffer, packet,
                            silc_server_packet_decrypt_check, parse_ctx);
-  if (ret < 0)
+  if (ret < 0) {
+    SILC_LOG_WARNING(("Packet decryption failed for connection "
+                     "%s:%d [%s]", sock->hostname, sock->port,  
+                     (sock->type == SILC_SOCKET_TYPE_UNKNOWN ? "Unknown" :
+                      sock->type == SILC_SOCKET_TYPE_CLIENT ? "Client" :
+                      sock->type == SILC_SOCKET_TYPE_SERVER ? "Server" :
+                      "Router")));
     goto out;
+  }
 
   if (ret == 0) {
     /* Parse the packet. Packet type is returned. */
index dc3cbaec1f58b7f31a368fd429f2abf2a6e1b67e..bb8db71c26c45ca3559179707a2842a38e66ec16 100644 (file)
@@ -28,5 +28,8 @@
 #define snprintf _snprintf
 #define vsnprintf _vsnprintf
 
+#undef inline
+#define inline __inline
+
 #endif
 
index e6af9540a803cd2800fddf73f51d43019ae72f70..a9cd3595f8877564131d633d6b5dcaf3f5b8eb9a 100644 (file)
@@ -303,6 +303,7 @@ static void silc_rng_get_hard_noise(SilcRng rng)
 
 static void silc_rng_exec_command(SilcRng rng, char *command)
 {
+#ifndef SILC_WIN32
   char buf[1024];
   FILE *fd;
   int i;
@@ -329,6 +330,7 @@ static void silc_rng_exec_command(SilcRng rng, char *command)
   /* Add the buffer into random pool */
   silc_rng_add_noise(rng, buf, strlen(buf));
   memset(buf, 0, sizeof(buf));
+#endif
 }
 
 /* This function adds the contents of the buffer as noise into random 
index 9640b8b33fd211e2dd0d07e7abd1da0f523c4810..4751b70d9f691751188b0128cfc1fea4ed886689 100644 (file)
  * random data for future initializing. This is important and must be
  * implemented in the future.
  *
+ * The caller must be cautios when using this RNG with native WIN32 system.
+ * The RNG most likely is impossible to set in unguessable state just by
+ * using the RNG's input data sources.  On WIN32 it is stronly suggested
+ * that caller would add more random noise after the initialization of the
+ * RNG using the silc_rng_add_noise function.  For example, random mouse
+ * movements may be used.
+ *
  ***/
 
 #ifndef SILCRNG_H