Added require_reverse_mapping for ServerParams.
authorPekka Riikonen <priikone@silcnet.org>
Sun, 17 Dec 2000 13:07:35 +0000 (13:07 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sun, 17 Dec 2000 13:07:35 +0000 (13:07 +0000)
CHANGES
apps/silcd/command.c
apps/silcd/packet_send.c
apps/silcd/protocol.c
apps/silcd/server.c
apps/silcd/server.h
lib/silcutil/silcnet.c

diff --git a/CHANGES b/CHANGES
index 426d317c50c6fccfb6891b0a78899b8e47db48e8..7163d0d6f5193911d3022aee60f0a7443bec4e44 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,9 +1,21 @@
+Sun Dec 17 14:40:08 EET 2000  Pekka Riikonen <priikone@poseidon.pspt.fi>
+
+       * Added `require_reverse_mapping' boolean value to ServerParams
+         structure. If TRUE (not default) the server will require that
+         the connecting host has fully qualified domain name.
+
+         If the reverse mapping is not required and hostname could not be
+         found the IP address is used as hostname.
+
 Sat Dec 16 17:39:54 EET 2000  Pekka Riikonen <priikone@poseidon.pspt.fi>
 
        * Implemented version string checking to both client and server.
          The check is incomplete currently due to the abnormal version 
          strings used in development version of SILC.
 
+       * Changed all command functions in server to use the new
+         CHECK_ARGS macro.
+
 Fri Dec 15 15:55:12 EET 2000  Pekka Riikonen <priikone@poseidon.pspt.fi>
 
        * Changed char *data to unsigned char *data in ID Cache system to
index 7373d1a50c81a44769ca55aa9560e53da6fa2035..361e3891ecf39e495c7a99044bb3a07a35cff9ed 100644 (file)
@@ -461,8 +461,8 @@ silc_server_command_whois_send_reply(SilcServerCommandContext cmd,
       if (!strchr(entry->username, '@')) {
        strncat(uh, "@", 1);
        hsock = (SilcSocketConnection)entry->connection;
-       len = hsock->hostname ? strlen(hsock->hostname) : strlen(hsock->ip);
-       strncat(uh, hsock->hostname ? hsock->hostname : hsock->ip, len);
+       len = strlen(hsock->hostname);
+       strncat(uh, hsock->hostname, len);
       }
       
       SILC_PUT32_MSB((time(NULL) - entry->data.last_receive), idle);
@@ -847,8 +847,8 @@ silc_server_command_identify_send_reply(SilcServerCommandContext cmd,
        if (!strchr(entry->username, '@')) {
          strncat(uh, "@", 1);
          hsock = (SilcSocketConnection)entry->connection;
-         len = hsock->hostname ? strlen(hsock->hostname) : strlen(hsock->ip);
-         strncat(uh, hsock->hostname ? hsock->hostname : hsock->ip, len);
+         len = strlen(hsock->hostname);
+         strncat(uh, hsock->hostname, len);
        }
       
        packet = silc_command_reply_payload_encode_va(SILC_COMMAND_IDENTIFY,
index 775ab48ef87305576550b805f30e554189d87269..c936583c992fa28b4a575076aeb4237c0c6a2c75 100644 (file)
@@ -587,8 +587,8 @@ void silc_server_packet_relay_to_channel(SilcServer server,
       sock = (SilcSocketConnection)client->connection;
       idata = (SilcIDListData)client;
 
-      SILC_LOG_DEBUG(("Sending packet to client %s", 
-                     sock->hostname ? sock->hostname : sock->ip));
+      SILC_LOG_DEBUG(("Sending packet to client %s (%s)", 
+                     sock->hostname, sock->ip));
 
       /* Send the packet */
       silc_server_packet_send_to_channel_real(server, sock, &packetdata,
index fbe1f566d0a15b8a24baea01817dfb488cc05e92..b7744da8ca64239c97e28793b0f325a850155f80 100644 (file)
@@ -514,9 +514,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth)
        unsigned short conn_type;
        unsigned char *auth_data;
 
-       SILC_LOG_INFO(("Performing authentication protocol for %s",
-                      ctx->sock->hostname ? ctx->sock->hostname :
-                      ctx->sock->ip));
+       SILC_LOG_INFO(("Performing authentication protocol for %s (%s)",
+                      ctx->sock->hostname, ctx->sock->ip));
 
        /* Parse the received authentication data packet. The received
           payload is Connection Auth Payload. */
index 286ac5b63db69107a29edca51002d05f53a2b4ca..047cca050b305d3cd994213bf0416aae16227ad8 100644 (file)
@@ -80,11 +80,13 @@ void silc_server_free(SilcServer server)
     if (server->rng)
       silc_rng_free(server->rng);
 
+#ifdef SILC_SIM
     while ((sim = silc_dlist_get(server->sim)) != SILC_LIST_END) {
       silc_dlist_del(server->sim, sim);
       silc_sim_free(sim);
     }
     silc_dlist_uninit(server->sim);
+#endif
 
     if (server->params)
       silc_free(server->params);
@@ -122,6 +124,7 @@ int silc_server_init(SilcServer server)
   server->params->retry_interval_max = SILC_SERVER_RETRY_INTERVAL_MAX;
   server->params->retry_keep_trying = FALSE;
   server->params->protocol_timeout = 60;
+  server->params->require_reverse_mapping = FALSE;
 
   /* Set log files where log message should be saved. */
   server->config->server = server;
@@ -219,11 +222,9 @@ int silc_server_init(SilcServer server)
   server->local_list->servers = silc_idcache_alloc(0);
   server->local_list->channels = silc_idcache_alloc(0);
 
-  /* XXX for now these are allocated for normal server as well as these
-     hold some global information that the server has fetched from its
-     router. For router these are used as they are supposed to be used
-     on router. The XXX can be remoevd later if this is the way we are
-     going to do this in the normal server as well. */
+  /* These are allocated for normal server as well as these hold some 
+     global information that the server has fetched from its router. For 
+     router these are used as they are supposed to be used on router. */
   server->global_list->clients = silc_idcache_alloc(0);
   server->global_list->servers = silc_idcache_alloc(0);
   server->global_list->channels = silc_idcache_alloc(0);
@@ -365,7 +366,9 @@ void silc_server_stop(SilcServer server)
   SILC_LOG_DEBUG(("Server stopped"));
 }
 
-/* The heart of the server. This runs the scheduler thus runs the server. */
+/* The heart of the server. This runs the scheduler thus runs the server. 
+   When this returns the server has been stopped and the program will
+   be terminated. */
 
 void silc_server_run(SilcServer server)
 {
@@ -722,8 +725,7 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router_final)
 
   /* Add the connected router to local server list */
   server->standalone = FALSE;
-  id_entry = silc_idlist_add_server(server->local_list, 
-                                   sock->hostname ? sock->hostname : sock->ip,
+  id_entry = silc_idlist_add_server(server->local_list, sock->hostname,
                                    SILC_ROUTER, ctx->dest_id, NULL, sock);
   if (!id_entry) {
     if (ctx->dest_id)
@@ -797,13 +799,15 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection)
   /* XXX This MUST be done async as this will block the entire server
      process. Either we have to do our own resolver stuff or in the future
      we can use threads. */
-  /* Perform mandatory name and address lookups for the remote host. */
+  /* Perform name and address lookups for the remote host. */
   silc_net_check_host_by_sock(sock, &newsocket->hostname, &newsocket->ip);
-  if (!newsocket->ip || !newsocket->hostname) {
-    SILC_LOG_DEBUG(("IP lookup/DNS lookup failed"));
-    SILC_LOG_ERROR(("IP lookup/DNS lookup failed"));
+  if ((server->params->require_reverse_mapping && !newsocket->hostname) ||
+      !newsocket->ip) {
+    SILC_LOG_ERROR(("IP/DNS lookup failed"));
     return;
   }
+  if (!newsocket->hostname)
+    newsocket->hostname = strdup(newsocket->ip);
 
   SILC_LOG_INFO(("Incoming connection from %s (%s)", newsocket->hostname,
                 newsocket->ip));
index dd952162e571b40f0704b49f3509c4773b71c4ab..7d38a7e71aeeb68152845f5fc867e22e329c9d03 100644 (file)
@@ -55,10 +55,12 @@ typedef struct {
   unsigned long retry_interval_min;
   unsigned long retry_interval_min_usec;
   unsigned long retry_interval_max;
-  unsigned int retry_keep_trying;
+  char retry_keep_trying;
 
   unsigned long protocol_timeout;
   unsigned long protocol_timeout_usec;
+
+  char require_reverse_mapping;
 } *SilcServerParams;
 
 /* Macros */
index c4d6d9d7a653a5f00575a4cefcc0daa9541b61f3..d06731d12a9597b4feeb655cf35008946b0fab9e 100644 (file)
@@ -20,6 +20,9 @@
 /*
  * $Id$
  * $Log$
+ * Revision 1.3  2000/12/17 13:07:35  priikone
+ *     Added require_reverse_mapping for ServerParams.
+ *
  * Revision 1.2  2000/10/31 19:48:32  priikone
  *     A LOT updates. Cannot separate. :)
  *
@@ -254,7 +257,8 @@ int silc_net_is_ip(const char *addr)
   return inet_aton(addr, &tmp);
 }
 
-/* Performs lookups for remote name and IP address. */
+/* Performs lookups for remote name and IP address. This peforms reverse
+   lookup as well to verify that the IP has FQDN. */
 
 void silc_net_check_host_by_sock(int sock, char **hostname, char **ip)
 {
@@ -282,7 +286,7 @@ void silc_net_check_host_by_sock(int sock, char **hostname, char **ip)
   if (!dest)
     return;
 
-  /* Get same hsot by name to see that the remote host really is
+  /* Get same host by name to see that the remote host really is
      the who it says it is */
   memset(host_name, 0, sizeof(host_name));
   memcpy(host_name, dest->h_name, strlen(dest->h_name));