updates.
authorPekka Riikonen <priikone@silcnet.org>
Thu, 7 Jun 2001 14:24:11 +0000 (14:24 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Thu, 7 Jun 2001 14:24:11 +0000 (14:24 +0000)
CHANGES
apps/silcd/packet_receive.c

diff --git a/CHANGES b/CHANGES
index 94e8cae074dc3c046185c574711f7a9d817c7ce2..379377b403af13d83cf1542718871cc94fd25113 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,11 @@
+Thu Jun  7 16:29:56 EEST 2001  Pekka Riikonen <priikone@poseidon.pspt.fi>
+
+       * Added sanity check to the silc_server_new_client. If the hostname
+         is provided inside username then check that the provided hostname
+         really is the same as the resolved one.  If the hostname was not
+         resolved then check it from the public key.  Affected file is
+         silcd/packet_receive.c.
+
 Thu Jun  7 08:57:16 CEST 2001  Pekka Riikonen <priikone@poseidon.pspt.fi>
 
        * Close log file after open.  Affected file 
index 5a378df872df397d85a68f4e37ef819f5f634c92..340a20a945a2aa8325487febd4a5af2efbc59e7f 100644 (file)
@@ -1280,6 +1280,7 @@ SilcClientEntry silc_server_new_client(SilcServer server,
   char *username = NULL, *realname = NULL, *id_string;
   uint32 id_len;
   int ret;
+  char *hostname, *nickname;
 
   SILC_LOG_DEBUG(("Creating new client"));
 
@@ -1322,6 +1323,86 @@ SilcClientEntry silc_server_new_client(SilcServer server,
     return NULL;
   }
 
+  nickname = strdup(username);
+
+  /* Make sanity checks for the hostname of the client. If the hostname
+     is provided in the `username' check that it is the same than the
+     resolved hostname, or if not resolved the hostname that appears in
+     the client's public key. If the hostname is not present then put
+     it from the resolved name or from the public key. */
+  if (strchr(username, '@')) {
+    SilcPublicKeyIdentifier pident;
+    int tlen = strcspn(username, "@");
+    char *phostname = NULL;
+
+    hostname = silc_calloc((strlen(username) - tlen) + 1, sizeof(char));
+    memcpy(hostname, username + tlen + 1, strlen(username) - tlen - 1);
+
+    pident = silc_pkcs_decode_identifier(client->data.public_key->identifier);
+    if (pident) {
+      phostname = strdup(pident->host);
+      silc_pkcs_free_identifier(pident);
+    }
+
+    if (strcmp(sock->hostname, sock->ip) && 
+       strcmp(sock->hostname, hostname)) {
+      silc_free(username);
+      silc_free(phostname);
+      silc_free(hostname);
+      if (realname)
+       silc_free(realname);
+      silc_server_disconnect_remote(server, sock, 
+                                   "Server closed connection: "
+                                   "Incomplete client information");
+      return NULL;
+    }
+    
+    if (!strcmp(sock->hostname, sock->ip) && 
+       phostname && strcmp(phostname, hostname)) {
+      silc_free(username);
+      silc_free(phostname);
+      silc_free(hostname);
+      if (realname)
+       silc_free(realname);
+      silc_server_disconnect_remote(server, sock, 
+                                   "Server closed connection: "
+                                   "Incomplete client information");
+      return NULL;
+    }
+    
+    if (phostname)
+      silc_free(phostname);
+  } else {
+    /* The hostname is not present, add it. */
+    char *newusername;
+    
+    if (strcmp(sock->hostname, sock->ip)) {
+      newusername = silc_calloc(strlen(username) + 
+                               strlen(sock->hostname) + 2,
+                               sizeof(*newusername));
+      strncat(newusername, username, strlen(username));
+      strncat(newusername, "@", 1);
+      strncat(newusername, sock->hostname, strlen(sock->hostname));
+      silc_free(username);
+      username = newusername;
+    } else {
+      SilcPublicKeyIdentifier pident = 
+       silc_pkcs_decode_identifier(client->data.public_key->identifier);
+      
+      if (pident) {
+       newusername = silc_calloc(strlen(username) + 
+                                 strlen(pident->host) + 2,
+                                 sizeof(*newusername));
+       strncat(newusername, username, strlen(username));
+       strncat(newusername, "@", 1);
+       strncat(newusername, pident->host, strlen(pident->host));
+       silc_free(username);
+       username = newusername;
+       silc_pkcs_free_identifier(pident);
+      }
+    }
+  }
+
   /* Create Client ID */
   silc_id_create_client_id(server->id, server->rng, server->md5hash,
                           username, &client_id);
@@ -1331,7 +1412,7 @@ SilcClientEntry silc_server_new_client(SilcServer server,
 
   /* Update client entry */
   idata->registered = TRUE;
-  client->nickname = strdup(username);
+  client->nickname = nickname;
   client->username = username;
   client->userinfo = realname ? realname : strdup(" ");
   client->id = client_id;