updates.
[silc.git] / apps / silcd / command_reply.c
index 37c2838d8001511c1fc0e6722f9d56e140f84f2d..79eb2bbeabebbc518b25719608d2e336f2e17d5f 100644 (file)
@@ -122,9 +122,7 @@ void silc_server_command_reply_free(SilcServerCommandReplyContext cmd)
   }
 }
 
-/* Caches the received WHOIS information. If we are normal server currently
-   we cache global information only for short period of time.  */
-/* XXX cache expirying not implemented yet! */
+/* Caches the received WHOIS information. */
 
 static char
 silc_server_command_reply_whois_save(SilcServerCommandReplyContext cmd)
@@ -615,6 +613,7 @@ SILC_SERVER_CMD_REPLY_FUNC(join)
 {
   SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
   SilcServer server = cmd->server;
+  SilcIDCacheEntry cache = NULL;
   SilcCommandStatus status;
   SilcChannelID *id;
   SilcClientID *client_id = NULL;
@@ -624,7 +623,7 @@ SILC_SERVER_CMD_REPLY_FUNC(join)
   unsigned char *id_string;
   char *channel_name, *tmp;
   unsigned int mode, created;
-  SilcBuffer keyp, client_id_list, client_mode_list;
+  SilcBuffer keyp = NULL, client_id_list, client_mode_list;
 
   COMMAND_CHECK_STATUS;
 
@@ -662,11 +661,11 @@ SILC_SERVER_CMD_REPLY_FUNC(join)
 
   /* Get channel key */
   tmp = silc_argument_get_arg_type(cmd->args, 7, &len);
-  if (!tmp)
-    goto out;
-  keyp = silc_buffer_alloc(len);
-  silc_buffer_pull_tail(keyp, SILC_BUFFER_END(keyp));
-  silc_buffer_put(keyp, tmp, len);
+  if (tmp) {
+    keyp = silc_buffer_alloc(len);
+    silc_buffer_pull_tail(keyp, SILC_BUFFER_END(keyp));
+    silc_buffer_put(keyp, tmp, len);
+  }
 
   id = silc_id_payload_parse_id(id_string, id_len);
   if (!id)
@@ -704,7 +703,8 @@ SILC_SERVER_CMD_REPLY_FUNC(join)
   silc_buffer_put(client_mode_list, tmp, len);
 
   /* See whether we already have the channel. */
-  entry = silc_idlist_find_channel_by_id(server->local_list, id, NULL);
+  entry = silc_idlist_find_channel_by_name(server->local_list, 
+                                          channel_name, &cache);
   if (!entry) {
     /* Add new channel */
 
@@ -721,7 +721,26 @@ SILC_SERVER_CMD_REPLY_FUNC(join)
       goto out;
     }
   } else {
-    silc_free(id);
+    /* The entry exists. */
+    if (entry->id)
+      silc_free(entry->id);
+    entry->id = id;
+    cache->id = entry->id;
+
+    /* Remove the founder auth data if the mode is not set but we have
+       them in the entry */
+    if (!(mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) && entry->founder_key) {
+      silc_pkcs_public_key_free(entry->founder_key);
+      if (entry->founder_passwd) {
+       silc_free(entry->founder_passwd);
+       entry->founder_passwd = NULL;
+      }
+    }
+  }
+
+  if (entry->hmac_name && hmac) {
+    silc_free(entry->hmac_name);
+    entry->hmac_name = strdup(hmac->hmac->name);
   }
 
   /* Get the ban list */
@@ -765,8 +784,11 @@ SILC_SERVER_CMD_REPLY_FUNC(join)
   entry->mode = mode;
 
   /* Save channel key */
-  silc_server_save_channel_key(server, keyp, entry);
-  silc_buffer_free(keyp);
+  if (!(entry->mode & SILC_CHANNEL_MODE_PRIVKEY)) {
+    silc_server_save_channel_key(server, keyp, entry);
+  }
+  if (keyp)
+    silc_buffer_free(keyp);
 
   /* Save the users to the channel */
   silc_server_save_users_on_channel(server, cmd->sock, entry,