Merged from silc_1_0_branch.
[silc.git] / apps / silcd / command.c
index c053236d89e04fc73886ac5d8f8d727ce92a4305..78beef6f58c38c90c71ae045894c8c16000351e1 100644 (file)
@@ -1133,9 +1133,10 @@ SILC_SERVER_CMD_FUNC(invite)
 
     /* Allocate hash table for invite list if it doesn't exist yet */
     if (!channel->invite_list)
-      channel->invite_list = silc_hash_table_alloc(0, silc_hash_ptr,
-                                                  NULL, NULL, NULL,
-                                                  NULL, NULL, TRUE);
+      channel->invite_list =
+       silc_hash_table_alloc(0, silc_hash_ptr,
+                             NULL, NULL, NULL,
+                             silc_server_inviteban_destruct, channel, TRUE);
 
     /* Check if the ID is in the list already */
     silc_hash_table_list(channel->invite_list, &htl);
@@ -1173,7 +1174,7 @@ SILC_SERVER_CMD_FUNC(invite)
 
   /* Get the invite information */
   tmp = silc_argument_get_arg_type(cmd->args, 4, &len);
-  if (tmp) {
+  if (tmp && len > 2) {
     /* Parse the arguments to see they are constructed correctly */
     SILC_GET16_MSB(argc, tmp);
     args = silc_argument_payload_parse(tmp + 2, len - 2, argc);
@@ -1190,9 +1191,11 @@ SILC_SERVER_CMD_FUNC(invite)
       if (tmp[0] == 0x00) {
        /* Allocate hash table for invite list if it doesn't exist yet */
        if (!channel->invite_list)
-         channel->invite_list = silc_hash_table_alloc(0, silc_hash_ptr,
-                                                      NULL, NULL, NULL,
-                                                      NULL, NULL, TRUE);
+         channel->invite_list =
+           silc_hash_table_alloc(0, silc_hash_ptr,
+                                 NULL, NULL, NULL,
+                                 silc_server_inviteban_destruct, channel,
+                                 TRUE);
     
        /* Check for resource limit */
        if (silc_hash_table_count(channel->invite_list) > 64) {
@@ -1237,13 +1240,23 @@ SILC_SERVER_CMD_FUNC(invite)
                         silc_argument_get_arg_type(cmd->args, 3, NULL),
                         list);
 
+  /* Send invite list back only if the list was modified, or now arguments
+     was given. */
+  type = 0;
+  argc = silc_argument_get_arg_num(cmd->args);
+  if (argc == 1)
+    type = 1;
+  if (silc_argument_get_arg_type(cmd->args, 3, &len))
+    type = 1;
+
   /* Send command reply */
   tmp = silc_argument_get_arg_type(cmd->args, 1, &len);
   packet = silc_command_reply_payload_encode_va(SILC_COMMAND_INVITE,
                                                SILC_STATUS_OK, 0, ident, 2,
                                                2, tmp, len,
-                                               3, list ? list->data : NULL,
-                                               list ? list->len : 0);
+                                               3, type && list ? 
+                                               list->data : NULL,
+                                               type && list ? list->len : 0);
   silc_server_packet_send(server, cmd->sock, SILC_PACKET_COMMAND_REPLY, 0, 
                          packet->data, packet->len, FALSE);
   silc_buffer_free(packet);
@@ -1421,6 +1434,8 @@ SILC_SERVER_CMD_FUNC(kill)
 
     /* Do normal signoff for the destination client */
     sock = remote_client->connection;
+    silc_server_remove_from_channels(server, NULL, remote_client,
+                                    TRUE, (char *)"Killed", TRUE, TRUE);
     silc_server_free_client_data(server, NULL, remote_client, TRUE,
                                 comment ? comment :
                                 (unsigned char *)"Killed");
@@ -1922,10 +1937,10 @@ static void silc_server_command_join_channel(SilcServer server,
                                      3, client->id) ||
          silc_server_inviteban_match(server, channel->ban_list,
                                      2, client->data.public_key) ||
-         !silc_server_inviteban_match(server, channel->ban_list,
-                                      1, check) ||
-         !silc_server_inviteban_match(server, channel->ban_list,
-                                      1, check2)) {
+         silc_server_inviteban_match(server, channel->ban_list,
+                                     1, check) ||
+         silc_server_inviteban_match(server, channel->ban_list,
+                                     1, check2)) {
        silc_server_command_send_status_reply(
                                      cmd, SILC_COMMAND_JOIN,
                                      SILC_STATUS_ERR_BANNED_FROM_CHANNEL, 0);
@@ -2957,6 +2972,11 @@ SILC_SERVER_CMD_FUNC(cmode)
                                                0);
          goto out;
        }
+      } else {
+       /* If key was not sent and the channel mode has already founder
+          then the key was not to be changed. */
+       if (channel->mode & SILC_CHANNEL_MODE_FOUNDER_AUTH)
+         goto has_founder;
       }
 
       /* Set the founder authentication */
@@ -3001,6 +3021,7 @@ SILC_SERVER_CMD_FUNC(cmode)
        channel->founder_key = NULL;
        goto out;
       }
+    has_founder:
     }
   } else {
     if (chl->mode & SILC_CHANNEL_UMODE_CHANFO) {
@@ -3061,7 +3082,6 @@ SILC_SERVER_CMD_FUNC(cumode)
   SilcServerCommandContext cmd = (SilcServerCommandContext)context;
   SilcServer server = cmd->server;
   SilcClientEntry client = (SilcClientEntry)cmd->sock->user_data;
-  SilcIDListData idata = (SilcIDListData)client;
   SilcChannelID *channel_id = NULL;
   SilcClientID *client_id = NULL;
   SilcChannelEntry channel;
@@ -3193,9 +3213,7 @@ SILC_SERVER_CMD_FUNC(cumode)
       SilcHashTableList htl;
 
       if (!(channel->mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) ||
-         !channel->founder_key || !idata->public_key ||
-         !silc_pkcs_public_key_compare(channel->founder_key, 
-                                       idata->public_key)) {
+         !channel->founder_key) {
        silc_server_command_send_status_reply(cmd, SILC_COMMAND_CUMODE,
                                              SILC_STATUS_ERR_AUTH_FAILED, 0);
        goto out;
@@ -4148,7 +4166,7 @@ SILC_SERVER_CMD_FUNC(ban)
 
   /* Get the ban information */
   tmp = silc_argument_get_arg_type(cmd->args, 3, &len);
-  if (tmp) {
+  if (tmp && len > 2) {
     /* Parse the arguments to see they are constructed correctly */
     SILC_GET16_MSB(argc, tmp);
     args = silc_argument_payload_parse(tmp + 2, len - 2, argc);
@@ -4165,9 +4183,11 @@ SILC_SERVER_CMD_FUNC(ban)
       if (tmp[0] == 0x00) {
        /* Allocate hash table for ban list if it doesn't exist yet */
        if (!channel->ban_list)
-         channel->ban_list = silc_hash_table_alloc(0, silc_hash_ptr,
-                                                   NULL, NULL, NULL,
-                                                   NULL, NULL, TRUE);
+         channel->ban_list =
+           silc_hash_table_alloc(0, silc_hash_ptr,
+                                 NULL, NULL, NULL,
+                                 silc_server_inviteban_destruct, channel,
+                                 TRUE);
     
        /* Check for resource limit */
        if (silc_hash_table_count(channel->ban_list) > 64) {