From 69cc23fe1422b57c2e91e1f379613a6892e12a08 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Mon, 2 Dec 2002 11:24:18 +0000 Subject: [PATCH] Fixed invite and ban list handling in command reply. --- CHANGES | 6 ++++++ apps/silcd/command.c | 23 ++++++++++++--------- apps/silcd/command_reply.c | 40 ++++++++++++++++++++++++++++++++----- apps/silcd/idlist.c | 25 ++--------------------- apps/silcd/packet_receive.c | 14 +++++++------ apps/silcd/server_util.c | 28 ++++++++++++++++++++------ apps/silcd/server_util.h | 4 ++++ 7 files changed, 91 insertions(+), 49 deletions(-) diff --git a/CHANGES b/CHANGES index 2efe070b..7cd2ef50 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ +Mon Dec 2 16:28:29 EET 2002 Pekka Riikonen + + * Fixed wrong invite and ban list handling in server command + reply. Affected files are silcd/command_reply.c, + silcd/server_util.[ch]. + Sun Dec 1 20:48:17 EET 2002 Pekka Riikonen * Fixed CMODE setting in server when founder mode was set. diff --git a/apps/silcd/command.c b/apps/silcd/command.c index 8cf36b6b..1dfc676a 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -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); @@ -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) { @@ -4183,9 +4186,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) { diff --git a/apps/silcd/command_reply.c b/apps/silcd/command_reply.c index 2711d02f..03f71b87 100644 --- a/apps/silcd/command_reply.c +++ b/apps/silcd/command_reply.c @@ -1001,15 +1001,45 @@ SILC_SERVER_CMD_REPLY_FUNC(join) /* Get the ban list */ tmp = silc_argument_get_arg_type(cmd->args, 8, &len); if (tmp) { - silc_free(entry->ban_list); - entry->ban_list = silc_memdup(tmp, len); + SilcArgumentPayload iargs; + SilcUInt16 iargc; + SILC_GET16_MSB(iargc, tmp); + iargs = silc_argument_payload_parse(tmp + 2, len - 2, iargc); + if (iargs) { + /* Delete old ban list */ + if (entry->ban_list) + silc_hash_table_free(entry->ban_list); + entry->ban_list = + silc_hash_table_alloc(0, silc_hash_ptr, + NULL, NULL, NULL, + silc_server_inviteban_destruct, entry, TRUE); + + /* Add new ban list */ + silc_server_inviteban_process(server, entry->ban_list, 0, iargs); + silc_argument_payload_free(iargs); + } } /* Get the invite list */ tmp = silc_argument_get_arg_type(cmd->args, 9, &len); - if (tmp) { - silc_free(entry->invite_list); - entry->invite_list = silc_memdup(tmp, len); + if (tmp && len > 2) { + SilcArgumentPayload iargs; + SilcUInt16 iargc; + SILC_GET16_MSB(iargc, tmp); + iargs = silc_argument_payload_parse(tmp + 2, len - 2, iargc); + if (iargs) { + /* Delete old invite list */ + if (entry->invite_list) + silc_hash_table_free(entry->invite_list); + entry->invite_list = + silc_hash_table_alloc(0, silc_hash_ptr, + NULL, NULL, NULL, + silc_server_inviteban_destruct, entry, TRUE); + + /* Add new invite list */ + silc_server_inviteban_process(server, entry->invite_list, 0, iargs); + silc_argument_payload_free(iargs); + } } /* Get the topic */ diff --git a/apps/silcd/idlist.c b/apps/silcd/idlist.c index 6a4d5f76..ae9e7949 100644 --- a/apps/silcd/idlist.c +++ b/apps/silcd/idlist.c @@ -676,31 +676,10 @@ int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry) silc_free(entry->id); silc_free(entry->topic); - if (entry->invite_list) { - silc_hash_table_list(entry->invite_list, &htl); - while (silc_hash_table_get(&htl, (void **)&type, (void **)&tmp)) { - if (type == 1) { - silc_free((char *)tmp); - continue; - } - silc_buffer_free(tmp); - } - silc_hash_table_list_reset(&htl); + if (entry->invite_list) silc_hash_table_free(entry->invite_list); - } - - if (entry->ban_list) { - silc_hash_table_list(entry->ban_list, &htl); - while (silc_hash_table_get(&htl, (void **)&type, (void **)&tmp)) { - if (type == 1) { - silc_free((char *)tmp); - continue; - } - silc_buffer_free(tmp); - } - silc_hash_table_list_reset(&htl); + if (entry->ban_list) silc_hash_table_free(entry->ban_list); - } if (entry->channel_key) silc_cipher_free(entry->channel_key); diff --git a/apps/silcd/packet_receive.c b/apps/silcd/packet_receive.c index 4b43fe58..29744f2c 100644 --- a/apps/silcd/packet_receive.c +++ b/apps/silcd/packet_receive.c @@ -1087,9 +1087,10 @@ void silc_server_notify(SilcServer server, goto out; if (action == 0 && !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); /* Proces the invite action */ silc_server_inviteban_process(server, channel->invite_list, action, @@ -1661,9 +1662,10 @@ void silc_server_notify(SilcServer server, goto out; if (action == 0 && !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); /* Proces the ban action */ silc_server_inviteban_process(server, channel->ban_list, action, diff --git a/apps/silcd/server_util.c b/apps/silcd/server_util.c index bc31cb6d..6e382e4e 100644 --- a/apps/silcd/server_util.c +++ b/apps/silcd/server_util.c @@ -1869,10 +1869,8 @@ void silc_server_inviteban_process(SilcServer server, SilcHashTable list, char *string = NULL, *start, *end, *n; if (silc_hash_table_find(list, (void *)1, NULL, (void **)&string)) { - silc_hash_table_del(list, (void *)1); - if (!strncmp(string, tmp, strlen(string) - 1)) { - silc_free(string); + silc_hash_table_del(list, (void *)1); string = NULL; } else { start = strstr(string, tmp); @@ -1881,7 +1879,7 @@ void silc_server_inviteban_process(SilcServer server, SilcHashTable list, n = silc_calloc(strlen(string) - len, sizeof(*n)); strncat(n, string, start - string); strncat(n, end + 1, ((string + strlen(string)) - end) - 1); - silc_free(string); + silc_hash_table_del(list, (void *)1); string = n; } } @@ -1899,7 +1897,6 @@ void silc_server_inviteban_process(SilcServer server, SilcHashTable list, while (silc_hash_table_get(&htl, (void **)&type, (void **)&tmp2)) { if (type == 2 && !memcmp(tmp2->data, tmp, len)) { silc_hash_table_del_by_context(list, (void *)2, tmp2); - silc_buffer_free(tmp2); break; } } @@ -1913,7 +1910,6 @@ void silc_server_inviteban_process(SilcServer server, SilcHashTable list, while (silc_hash_table_get(&htl, (void **)&type, (void **)&tmp2)) { if (type == 3 && !memcmp(tmp2->data, tmp, len)) { silc_hash_table_del_by_context(list, (void *)3, tmp2); - silc_buffer_free(tmp2); break; } } @@ -1924,3 +1920,23 @@ void silc_server_inviteban_process(SilcServer server, SilcHashTable list, } } } + +/* Destructor for invite or ban list entrys */ + +void silc_server_inviteban_destruct(void *key, void *context, + void *user_context) +{ + switch ((SilcUInt32)key) { + case 1: + /* Invite string */ + silc_free(context); + break; + case 2: + case 3: + /* Public key/Channel ID SilcBuffer */ + silc_buffer_free(context); + break; + default: + break; + } +} diff --git a/apps/silcd/server_util.h b/apps/silcd/server_util.h index e072df44..393f0900 100644 --- a/apps/silcd/server_util.h +++ b/apps/silcd/server_util.h @@ -203,4 +203,8 @@ bool silc_server_inviteban_match(SilcServer server, SilcHashTable list, void silc_server_inviteban_process(SilcServer server, SilcHashTable list, SilcUInt8 action, SilcArgumentPayload args); +/* Destructor for invite or ban list entrys */ +void silc_server_inviteban_destruct(void *key, void *context, + void *user_context); + #endif /* SERVER_UTIL_H */ -- 2.24.0