In signoff assure that channel key is present before sending it.
[silc.git] / apps / silcd / server_util.c
index 4e1b2cb8f43b3c4b19ec6a4db53821dadf322449..92b7bd783f27f0e65fb44e7233cf5b3825ffda48 100644 (file)
@@ -176,7 +176,7 @@ bool silc_server_remove_clients_by_server(SilcServer server,
        client = (SilcClientEntry)id_cache->context;
 
        /* If client is not registered, is not originated from `router'
-          or is not owned by `entry', skip it. */
+          and is not owned by `entry', skip it. */
        if (!(client->data.status & SILC_IDLIST_STATUS_REGISTERED) ||
            client->router != router ||
            (router != entry && !SILC_ID_COMPARE(client->id, entry->id,
@@ -218,6 +218,7 @@ bool silc_server_remove_clients_by_server(SilcServer server,
          client->data.status &= ~SILC_IDLIST_STATUS_REGISTERED;
          id_cache->expire = SILC_ID_CACHE_EXPIRE_DEF;
        } else {
+         silc_idlist_del_data(client);
          silc_idlist_del_client(server->local_list, client);
        }
 
@@ -235,7 +236,7 @@ bool silc_server_remove_clients_by_server(SilcServer server,
        client = (SilcClientEntry)id_cache->context;
 
        /* If client is not registered, is not originated from `router'
-          or is not owned by `entry', skip it. */
+          and is not owned by `entry', skip it. */
        if (!(client->data.status & SILC_IDLIST_STATUS_REGISTERED) ||
            client->router != router ||
            (router != entry && !SILC_ID_COMPARE(client->id, entry->id,
@@ -277,6 +278,7 @@ bool silc_server_remove_clients_by_server(SilcServer server,
          client->data.status &= ~SILC_IDLIST_STATUS_REGISTERED;
          id_cache->expire = SILC_ID_CACHE_EXPIRE_DEF;
        } else {
+         silc_idlist_del_data(client);
          silc_idlist_del_client(server->global_list, client);
        }
 
@@ -287,6 +289,21 @@ bool silc_server_remove_clients_by_server(SilcServer server,
     silc_idcache_list_free(list);
   }
 
+  /* Return now if we are shutting down */
+  if (server->server_shutdown) {
+    silc_hash_table_free(channels);
+
+    if (server_signoff) {
+      for (i = 0; i < argc; i++)
+       silc_free(argv[i]);
+      silc_free(argv);
+      silc_free(argv_lens);
+      silc_free(argv_types);
+      silc_hash_table_free(clients);
+    }
+    return TRUE;
+  }
+
   /* Send the SERVER_SIGNOFF notify */
   if (server_signoff) {
     SilcBuffer args, not;
@@ -315,6 +332,10 @@ bool silc_server_remove_clients_by_server(SilcServer server,
                                    SILC_PACKET_NOTIFY, 0, FALSE,
                                    not->data, not->len, FALSE);
 
+    /* Send notify also to local backup routers */
+    silc_server_backup_send(server, NULL, SILC_PACKET_NOTIFY, 0,
+                           not->data, not->len, FALSE, TRUE);
+
     silc_buffer_free(args);
     silc_buffer_free(not);
     for (i = 0; i < argc; i++)
@@ -325,12 +346,6 @@ bool silc_server_remove_clients_by_server(SilcServer server,
     silc_hash_table_free(clients);
   }
 
-  /* Return now if we are shutting down */
-  if (server->server_shutdown) {
-    silc_hash_table_free(channels);
-    return TRUE;
-  }
-
   /* We must now re-generate the channel key for all channels that had
      this server's client(s) on the channel. As they left the channel we
      must re-generate the channel key. */
@@ -343,7 +358,7 @@ bool silc_server_remove_clients_by_server(SilcServer server,
     }
 
     /* Do not send the channel key if private channel key mode is set */
-    if (channel->mode & SILC_CHANNEL_MODE_PRIVKEY)
+    if (channel->mode & SILC_CHANNEL_MODE_PRIVKEY || !channel->channel_key)
       continue;
 
     silc_server_send_channel_key(server, NULL, channel, 
@@ -433,8 +448,7 @@ silc_server_update_clients_by_real_server(SilcServer server,
          if (local) {
            SILC_LOG_DEBUG(("Moving client to global list"));
            silc_idcache_add(server->global_list->clients, client_cache->name,
-                            client_cache->id, client_cache->context,
-                            client_cache->expire, NULL);
+                            client_cache->id, client_cache->context, 0, NULL);
            silc_idcache_del_by_context(server->local_list->clients, client);
          }
          server_entry = server_entry->router;
@@ -444,8 +458,7 @@ silc_server_update_clients_by_real_server(SilcServer server,
          if (server_entry->server_type != SILC_BACKUP_ROUTER && local) {
            SILC_LOG_DEBUG(("Moving client to global list"));
            silc_idcache_add(server->global_list->clients, client_cache->name,
-                            client_cache->id, client_cache->context,
-                            client_cache->expire, NULL);
+                            client_cache->id, client_cache->context, 0, NULL);
            silc_idcache_del_by_context(server->local_list->clients, client);
          }
        }
@@ -1518,6 +1531,7 @@ void silc_server_kill_client(SilcServer server,
     }
 
     /* Remove remote client */
+    silc_idlist_del_data(remote_client);
     if (!silc_idlist_del_client(server->global_list, remote_client)) {
       /* Remove this client from watcher list if it is */
       silc_server_del_from_watcher_list(server, remote_client);