From d1c651aa9e5718afcd379e2bc982ed0a593f49ac Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Fri, 29 Jun 2001 16:46:39 +0000 Subject: [PATCH] updates. --- CHANGES | 23 +++++++++++++++++++++ apps/silcd/packet_send.c | 26 +++++++++++++++++++----- apps/silcd/protocol.c | 2 +- apps/silcd/server.c | 44 ++++++++++++++++++++++++++++------------ includes/silcwin32.h | 3 +++ lib/silccrypt/silcrng.c | 2 ++ lib/silccrypt/silcrng.h | 7 +++++++ 7 files changed, 88 insertions(+), 19 deletions(-) diff --git a/CHANGES b/CHANGES index eda8d82e..17073f9f 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,26 @@ +Fri Jun 29 20:05:25 EEST 2001 Pekka Riikonen + + * 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 * Changed the `say' client operation's interface to accept diff --git a/apps/silcd/packet_send.c b/apps/silcd/packet_send.c index 81cdce52..25fc3907 100644 --- a/apps/silcd/packet_send.c +++ b/apps/silcd/packet_send.c @@ -2,7 +2,7 @@ packet_send.c - Author: Pekka Riikonen + Author: Pekka Riikonen 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 */ diff --git a/apps/silcd/protocol.c b/apps/silcd/protocol.c index 0299a5ad..76b45942 100644 --- a/apps/silcd/protocol.c +++ b/apps/silcd/protocol.c @@ -2,7 +2,7 @@ protocol.c - Author: Pekka Riikonen + Author: Pekka Riikonen Copyright (C) 1997 - 2001 Pekka Riikonen diff --git a/apps/silcd/server.c b/apps/silcd/server.c index 4dde2b36..ea757730 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -2,7 +2,7 @@ server.c - Author: Pekka Riikonen + Author: Pekka Riikonen 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. */ diff --git a/includes/silcwin32.h b/includes/silcwin32.h index dc3cbaec..bb8db71c 100644 --- a/includes/silcwin32.h +++ b/includes/silcwin32.h @@ -28,5 +28,8 @@ #define snprintf _snprintf #define vsnprintf _vsnprintf +#undef inline +#define inline __inline + #endif diff --git a/lib/silccrypt/silcrng.c b/lib/silccrypt/silcrng.c index e6af9540..a9cd3595 100644 --- a/lib/silccrypt/silcrng.c +++ b/lib/silccrypt/silcrng.c @@ -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 diff --git a/lib/silccrypt/silcrng.h b/lib/silccrypt/silcrng.h index 9640b8b3..4751b70d 100644 --- a/lib/silccrypt/silcrng.h +++ b/lib/silccrypt/silcrng.h @@ -160,6 +160,13 @@ * 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 -- 2.24.0