From ebe9bb6e946469f5e8a01a865287bfca521242d2 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Mon, 19 Feb 2001 18:32:56 +0000 Subject: [PATCH] updates. --- CHANGES | 13 +++++++++++++ apps/silcd/command.c | 9 ++++----- apps/silcd/command_reply.c | 2 +- apps/silcd/command_reply.h | 1 + apps/silcd/server.c | 1 + apps/silcd/testi2.conf | 8 ++++---- lib/silcclient/client.c | 4 ++-- lib/silccore/silcpacket.c | 21 +++++++++++++++------ lib/silcutil/silcnet.c | 15 +++++++++++++++ lib/silcutil/silcnet.h | 1 + 10 files changed, 57 insertions(+), 18 deletions(-) diff --git a/CHANGES b/CHANGES index c5b8a54f..9edaaa5a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,16 @@ +Mon Feb 19 19:59:28 EET 2001 Pekka Riikonen + + * The client entry's userinfo pointer must be always valid. + Otherwise the [] bug will surface beacuse the WHOIS + will fail since it requires the userinfo. Now, the userinfo + is allocated as "" if actual userinfo does not exist. Actually, + it must exist and it is totally Ok to drop client connections + that does not announce the userinfo. However, we will make + this workaround for now. + + * Added silc_net_get_remote_port into lib/silcutil/silcnet.[ch] + to return the remote port by socket. + Mon Feb 19 14:26:49 EET 2001 Pekka Riikonen * Changed SILC_SERVER_COMMAND_EXEC_PENDING macro to the name diff --git a/apps/silcd/command.c b/apps/silcd/command.c index 94d172e4..4f0749cb 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -161,6 +161,7 @@ void silc_server_command_process(SilcServer server, SILC_LOG_ERROR(("Bad command payload, packet dropped")); silc_buffer_free(packet->buffer); silc_packet_context_free(packet); + silc_socket_free(ctx->sock); silc_free(ctx); return; } @@ -1752,11 +1753,9 @@ void silc_server_command_send_users(SilcServer server, /* If this function was called from pending command then instead of processing the command now, register a pending command callback which will process it after we've received the automatic USERS command - reply. */ - silc_server_command_pending(server, SILC_COMMAND_USERS, 0, - silc_server_command_destructor, - silc_server_command_users, - silc_server_command_dup(cmd)); + reply which server will send in JOIN. */ + silc_server_command_pending(server, SILC_COMMAND_USERS, 0, NULL, + silc_server_command_users, cmd); cmd->pending = TRUE; silc_buffer_free(buffer); silc_buffer_free(idp); diff --git a/apps/silcd/command_reply.c b/apps/silcd/command_reply.c index 5d6cd299..e88a97f0 100644 --- a/apps/silcd/command_reply.c +++ b/apps/silcd/command_reply.c @@ -100,7 +100,7 @@ void silc_server_command_reply_process(SilcServer server, break; if (cmd == NULL || !cmd->cb) { - silc_free(ctx); + silc_server_command_reply_free(ctx); return; } diff --git a/apps/silcd/command_reply.h b/apps/silcd/command_reply.h index 4c6b63eb..23c1fe6b 100644 --- a/apps/silcd/command_reply.h +++ b/apps/silcd/command_reply.h @@ -57,6 +57,7 @@ typedef struct { void silc_server_command_reply_##func(void *context) /* Prototypes */ +void silc_server_command_reply_free(SilcServerCommandReplyContext cmd); void silc_server_command_reply_process(SilcServer server, SilcSocketConnection sock, SilcBuffer buffer); diff --git a/apps/silcd/server.c b/apps/silcd/server.c index df72aeee..d349ec91 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -938,6 +938,7 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection) } if (!newsocket->hostname) newsocket->hostname = strdup(newsocket->ip); + newsocket->port = silc_net_get_remote_port(sock); SILC_LOG_INFO(("Incoming connection from %s (%s)", newsocket->hostname, newsocket->ip)); diff --git a/apps/silcd/testi2.conf b/apps/silcd/testi2.conf index fe6247a1..35f54730 100644 --- a/apps/silcd/testi2.conf +++ b/apps/silcd/testi2.conf @@ -19,10 +19,10 @@ nobody:nobody Mun huone:Mun servo:Pekka Riikonen:priikone@poseidon.pspt.fi [ServerInfo] -lassi.kuo.fi.ssh.com:10.2.1.7:Kuopio, Finland:1334 +lassi.kuo.fi.ssh.com:212.146.8.245:Kuopio, Finland:1334 [ListenPort] -10.2.1.7:10.2.1.7:1334 +212.146.8.245:212.146.8.245:1334 [Logging] infologfile:silcd2.log:10000 @@ -43,10 +43,10 @@ errorlogfile:silcd2.log:10000 [AdminConnection] [ServerConnection] -10.2.1.7:passwd:priikone:1333:1:1 +212.146.8.245:passwd:priikone:1333:1:1 [RouterConnection] -10.2.1.7:passwd:priikone:1335:1:1:0 +212.146.8.245:passwd:priikone:1335:1:1:0 [DenyConnection] [RedirectClient] diff --git a/lib/silcclient/client.c b/lib/silcclient/client.c index b931b51c..bc7d8dfe 100644 --- a/lib/silcclient/client.c +++ b/lib/silcclient/client.c @@ -271,6 +271,7 @@ int silc_client_start_key_exchange(SilcClient client, conn->nickname = strdup(client->username); conn->sock->hostname = conn->remote_host; + conn->sock->ip = strdup(conn->remote_host); conn->sock->port = conn->remote_port; /* Allocate internal Key Exchange context. This is sent to the @@ -1180,8 +1181,7 @@ void silc_client_close_connection(SilcClient client, silc_net_close_connection(sock->sock); client->ops->say(client, sock->user_data, - "Closed connection to host %s", sock->hostname ? - sock->hostname : sock->ip); + "Closed connection to host %s", sock->hostname); /* Free everything */ if (sock->user_data) { diff --git a/lib/silccore/silcpacket.c b/lib/silccore/silcpacket.c index 4f003c66..52d60f4e 100644 --- a/lib/silccore/silcpacket.c +++ b/lib/silccore/silcpacket.c @@ -71,6 +71,13 @@ int silc_packet_write(int sock, SilcBuffer src) int silc_packet_send(SilcSocketConnection sock, int force_send) { + SILC_LOG_DEBUG(("Sending packet to %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"))); + /* Send now if forced to do so */ if (force_send == TRUE) { int ret; @@ -433,18 +440,20 @@ int silc_packet_receive(SilcSocketConnection sock) { int ret; + SILC_LOG_DEBUG(("Receiving packet from %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"))); + /* Allocate the incoming data buffer if not done already. */ if (!sock->inbuf) sock->inbuf = silc_buffer_alloc(SILC_PACKET_DEFAULT_SIZE); - + /* Read some data from connection */ ret = silc_packet_read(sock->sock, sock->inbuf); - /* Error */ - if (ret == -1) { - SILC_LOG_ERROR(("Error reading packet, dropped")); - } - return ret; } diff --git a/lib/silcutil/silcnet.c b/lib/silcutil/silcnet.c index 428f764c..78d7ce6b 100644 --- a/lib/silcutil/silcnet.c +++ b/lib/silcutil/silcnet.c @@ -290,6 +290,21 @@ void silc_net_check_host_by_sock(int sock, char **hostname, char **ip) SILC_LOG_DEBUG(("Resolved IP address `%s'", *ip)); } +/* Return remote port by socket. */ + +unsigned short silc_net_get_remote_port(int sock) +{ + struct sockaddr_in remote; + int len; + + memset(&remote, 0, sizeof(remote)); + len = sizeof(remote); + if (getpeername(sock, (struct sockaddr *)&remote, &len) < 0) + return 0; + + return ntohs(remote.sin_port); +} + /* Return name of localhost. */ char *silc_net_localhost() diff --git a/lib/silcutil/silcnet.h b/lib/silcutil/silcnet.h index 756f1604..7cbda8c4 100644 --- a/lib/silcutil/silcnet.h +++ b/lib/silcutil/silcnet.h @@ -32,6 +32,7 @@ int silc_net_set_socket_nonblock(int sock); int silc_net_set_socket_opt(int sock, int level, int option, int on); int silc_net_is_ip(const char *addr); void silc_net_check_host_by_sock(int sock, char **hostname, char **ip); +unsigned short silc_net_get_remote_port(int sock); char *silc_net_localhost(); #endif -- 2.24.0