updates.
[silc.git] / apps / silcd / packet_receive.c
index 340a20a945a2aa8325487febd4a5af2efbc59e7f..0c010bdfe97d377dd98ecf46207aaf7ac4143bfa 100644 (file)
@@ -316,7 +316,7 @@ void silc_server_notify(SilcServer server,
 
     if (channel->topic)
       silc_free(channel->topic);
-    channel->topic = silc_calloc(tmp_len, sizeof(*channel->topic));
+    channel->topic = silc_calloc(tmp_len + 1, sizeof(*channel->topic));
     memcpy(channel->topic, tmp, tmp_len);
 
     /* Send the same notify to the channel */
@@ -1323,6 +1323,9 @@ SilcClientEntry silc_server_new_client(SilcServer server,
     return NULL;
   }
 
+  if (strlen(username) > 128)
+    username[127] = '\0';
+
   nickname = strdup(username);
 
   /* Make sanity checks for the hostname of the client. If the hostname
@@ -1338,16 +1341,9 @@ SilcClientEntry silc_server_new_client(SilcServer server,
     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);
@@ -1357,11 +1353,18 @@ SilcClientEntry silc_server_new_client(SilcServer server,
       return NULL;
     }
     
+    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) && 
        phostname && strcmp(phostname, hostname)) {
       silc_free(username);
-      silc_free(phostname);
       silc_free(hostname);
+      if (phostname)
+       silc_free(phostname);
       if (realname)
        silc_free(realname);
       silc_server_disconnect_remote(server, sock, 
@@ -1375,8 +1378,12 @@ SilcClientEntry silc_server_new_client(SilcServer server,
   } else {
     /* The hostname is not present, add it. */
     char *newusername;
-    
+    /* XXX For now we cannot take the host name from the public key since
+       they are not trusted or we cannot verify them as trusted. Just take
+       what the resolved name or address is. */
+#if 0
     if (strcmp(sock->hostname, sock->ip)) {
+#endif
       newusername = silc_calloc(strlen(username) + 
                                strlen(sock->hostname) + 2,
                                sizeof(*newusername));
@@ -1385,6 +1392,7 @@ SilcClientEntry silc_server_new_client(SilcServer server,
       strncat(newusername, sock->hostname, strlen(sock->hostname));
       silc_free(username);
       username = newusername;
+#if 0
     } else {
       SilcPublicKeyIdentifier pident = 
        silc_pkcs_decode_identifier(client->data.public_key->identifier);
@@ -1401,15 +1409,13 @@ SilcClientEntry silc_server_new_client(SilcServer server,
        silc_pkcs_free_identifier(pident);
       }
     }
+#endif
   }
 
   /* Create Client ID */
   silc_id_create_client_id(server->id, server->rng, server->md5hash,
                           username, &client_id);
 
-  if (strlen(username) > 128)
-    username[127] = '\0';
-
   /* Update client entry */
   idata->registered = TRUE;
   client->nickname = nickname;
@@ -1445,8 +1451,8 @@ SilcClientEntry silc_server_new_client(SilcServer server,
 
   /* Send some nice info to the client */
   SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
-                         ("Welcome to the SILC Network %s@%s",
-                          username, sock->hostname));
+                         ("Welcome to the SILC Network %s",
+                          username));
   SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
                          ("Your host is %s, running version %s",
                           server->config->server_info->server_name,
@@ -1875,6 +1881,9 @@ void silc_server_new_channel(SilcServer server,
        return;
       }
 
+      /* Get the mode and set it to the channel */
+      channel->mode = silc_channel_get_mode(payload);
+
       /* Send the new channel key to the server */
       chk = silc_channel_key_payload_encode(id_len, id,
                                            strlen(channel->channel_key->