updates.
authorPekka Riikonen <priikone@silcnet.org>
Mon, 19 Feb 2001 18:32:56 +0000 (18:32 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Mon, 19 Feb 2001 18:32:56 +0000 (18:32 +0000)
CHANGES
apps/silcd/command.c
apps/silcd/command_reply.c
apps/silcd/command_reply.h
apps/silcd/server.c
apps/silcd/testi2.conf
lib/silcclient/client.c
lib/silccore/silcpacket.c
lib/silcutil/silcnet.c
lib/silcutil/silcnet.h

diff --git a/CHANGES b/CHANGES
index c5b8a54f84be56e9573031fb11b8ed52df87b048..9edaaa5a40870166b40b8491034f9d7ead1d67b4 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,16 @@
+Mon Feb 19 19:59:28 EET 2001  Pekka Riikonen <priikone@poseidon.pspt.fi>
+
+       * The client entry's userinfo pointer must be always valid. 
+         Otherwise the [<unknown>] 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 <priikone@poseidon.pspt.fi>
 
        * Changed SILC_SERVER_COMMAND_EXEC_PENDING macro to the name
index 94d172e427b3c4994606f50ccab3d6866c3cb60b..4f0749cb40c4ef61a82e47f3c6206d1ddeda80c1 100644 (file)
@@ -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);
index 5d6cd2991b8df4d5d0fb996619e233fd7bbe0238..e88a97f0809663d162f2e671d87410f7b298d315 100644 (file)
@@ -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;
   }
 
index 4c6b63eb399f66d80908507cdb176a78fa7f93df..23c1fe6b0a7c350b5ca13147ea76ae5b91df1ac3 100644 (file)
@@ -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);
index df72aeee8df403e9a98a8160a14a380552d3c71c..d349ec917cf0eece2fce75c3257f3519c57499f6 100644 (file)
@@ -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));
index fe6247a1d0a8b9ff75a693d83810e3924412a3a0..35f54730a3ecf478eca431e08f08df91aa359faf 100644 (file)
@@ -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]
index b931b51c7a2b89474d47c60c1ee6a9a66dda4ac1..bc7d8dfe363194265a001dd94c38440ab7a11e65 100644 (file)
@@ -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) {
index 4f003c668b52621d9e5620044c791ad22a325e82..52d60f4e622feae61b3ef2edab591437f74783db 100644 (file)
@@ -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;
 }
 
index 428f764ccaf206d0da33051d70880ddfc5c272db..78d7ce6b233d490864ff9b1cb24632f3701e5358 100644 (file)
@@ -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()
index 756f160448cb10760dad1651617263c7eaf25a2d..7cbda8c4a46ae57aa0e94c15e23bf88addd1111c 100644 (file)
@@ -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