From: Pekka Riikonen Date: Fri, 10 Aug 2001 22:50:45 +0000 (+0000) Subject: updates. X-Git-Tag: silcertest~171 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=e7bb7daaa8a471ddafbd3774c6aed541a5ecdb41 updates. --- diff --git a/CHANGES b/CHANGES index be73f8da..738a2b20 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,31 @@ +Sat Aug 11 00:29:57 EEST 2001 Pekka Riikonen + + * Added some SILC_LOG_ERROR's to various error conditions + if client could not be added to ID cache. Affected files + silcd/packet_receive.c and silcd/server.c. + + * When client's sock->user_data is freed, NULL also the + client->router and client->connection pointers. Added check + for these pointers being NULL to various places around the + code. Affected file silcd/server.c. + + * Added client->data.registered == TRUE checks to various + places around the code to assure that unregistered client's + are not handled when it is not allowed. Affected file + silcd/server.c. + + * Added `bool registered' fields to all + silc_idlist_[server|client]_get_* routines to indicate whether + the fetched client needs to be registered or not. Affected + file silcd/idlist.[ch]. + + * Add your own entry as registered to the ID cache in the + server. Affected file server.c. + + * Fixed a bug in silc_server_new_server. The SilcServer was + set as the new server's context instead of SilcServerEntry. + This naturally caused some weird bugs. + Thu Aug 9 18:28:37 EEST 2001 Pekka Riikonen * Do not delete the channel rekey task when adding it diff --git a/apps/silcd/command.c b/apps/silcd/command.c index 249e941a..921eeec8 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -2595,6 +2595,10 @@ SILC_SERVER_CMD_FUNC(info) } } + /* Some buggy servers has sent request to router about themselves. */ + if (server->server_type == SILC_ROUTER && cmd->sock->user_data == entry) + goto out; + if ((!dest_server && !server_id && !entry) || (entry && entry == server->id_entry) || (dest_server && !cmd->pending && diff --git a/apps/silcd/command_reply.c b/apps/silcd/command_reply.c index 557a857f..6ecc3ad0 100644 --- a/apps/silcd/command_reply.c +++ b/apps/silcd/command_reply.c @@ -158,10 +158,11 @@ silc_server_command_reply_whois_save(SilcServerCommandReplyContext cmd) /* Check if we have this client cached already. */ - client = silc_idlist_find_client_by_id(server->local_list, client_id, NULL); + client = silc_idlist_find_client_by_id(server->local_list, client_id, + FALSE, NULL); if (!client) { client = silc_idlist_find_client_by_id(server->global_list, client_id, - NULL); + FALSE, NULL); global = TRUE; } @@ -189,8 +190,10 @@ silc_server_command_reply_whois_save(SilcServerCommandReplyContext cmd) strdup(username), strdup(realname), client_id, cmd->sock->user_data, NULL); - if (!client) + if (!client) { + SILC_LOG_ERROR(("Could not add new client to the ID Cache")); return FALSE; + } client->data.registered = TRUE; client->mode = mode; @@ -295,10 +298,10 @@ silc_server_command_reply_whowas_save(SilcServerCommandReplyContext cmd) /* Check if we have this client cached already. */ client = silc_idlist_find_client_by_id(server->local_list, client_id, - &cache); + FALSE, &cache); if (!client) { client = silc_idlist_find_client_by_id(server->global_list, - client_id, &cache); + client_id, FALSE, &cache); global = TRUE; } @@ -326,12 +329,14 @@ silc_server_command_reply_whowas_save(SilcServerCommandReplyContext cmd) strdup(username), strdup(realname), silc_id_dup(client_id, SILC_ID_CLIENT), cmd->sock->user_data, NULL); - if (!client) + if (!client) { + SILC_LOG_ERROR(("Could not add new client to the ID Cache")); return FALSE; + } client->data.registered = FALSE; client = silc_idlist_find_client_by_id(server->global_list, - client_id, &cache); + client_id, TRUE, &cache); cache->expire = SILC_ID_CACHE_EXPIRE_DEF; client->servername = servername; } else { @@ -437,10 +442,10 @@ silc_server_command_reply_identify_save(SilcServerCommandReplyContext cmd) SILC_LOG_DEBUG(("Received client information")); client = silc_idlist_find_client_by_id(server->local_list, - client_id, NULL); + client_id, FALSE, NULL); if (!client) { client = silc_idlist_find_client_by_id(server->global_list, client_id, - NULL); + FALSE, NULL); global = TRUE; } if (!client) { @@ -466,6 +471,10 @@ silc_server_command_reply_identify_save(SilcServerCommandReplyContext cmd) client = silc_idlist_add_client(server->global_list, nick, info ? strdup(info) : NULL, NULL, client_id, cmd->sock->user_data, NULL); + if (!client) { + SILC_LOG_ERROR(("Could not add new client to the ID Cache")); + goto error; + } client->data.registered = TRUE; } else { /* We have the client already, update the data */ @@ -516,10 +525,10 @@ silc_server_command_reply_identify_save(SilcServerCommandReplyContext cmd) SILC_LOG_DEBUG(("Received server information")); server_entry = silc_idlist_find_server_by_id(server->local_list, - server_id, NULL); + server_id, FALSE, NULL); if (!server_entry) server_entry = silc_idlist_find_server_by_id(server->global_list, - server_id, NULL); + server_id, FALSE, NULL); if (!server_entry) { /* If router did not find such Server ID in its lists then this must be bogus client or some router in the net is buggy. */ @@ -534,6 +543,7 @@ silc_server_command_reply_identify_save(SilcServerCommandReplyContext cmd) silc_free(server_id); goto error; } + server_entry->data.registered = TRUE; server_id = NULL; } @@ -637,10 +647,11 @@ SILC_SERVER_CMD_REPLY_FUNC(info) if (tmp_len > 256) goto out; - entry = silc_idlist_find_server_by_id(server->local_list, server_id, NULL); + entry = silc_idlist_find_server_by_id(server->local_list, server_id, + FALSE, NULL); if (!entry) { entry = silc_idlist_find_server_by_id(server->global_list, server_id, - NULL); + FALSE, NULL); if (!entry) { /* Add the server to global list */ server_id = silc_id_dup(server_id, SILC_ID_SERVER); @@ -650,6 +661,7 @@ SILC_SERVER_CMD_REPLY_FUNC(info) silc_free(server_id); goto out; } + entry->data.registered = TRUE; } } @@ -688,10 +700,11 @@ SILC_SERVER_CMD_REPLY_FUNC(motd) if (!server_id) goto out; - entry = silc_idlist_find_server_by_id(server->local_list, server_id, NULL); + entry = silc_idlist_find_server_by_id(server->local_list, server_id, + TRUE, NULL); if (!entry) { entry = silc_idlist_find_server_by_id(server->global_list, server_id, - NULL); + TRUE, NULL); if (!entry) goto out; } @@ -1052,10 +1065,10 @@ SILC_SERVER_CMD_REPLY_FUNC(getkey) client_id = silc_id_payload_get_id(idp); client = silc_idlist_find_client_by_id(server->local_list, client_id, - NULL); + TRUE, NULL); if (!client) { client = silc_idlist_find_client_by_id(server->global_list, - client_id, NULL); + client_id, TRUE, NULL); if (!client) goto out; } @@ -1065,10 +1078,10 @@ SILC_SERVER_CMD_REPLY_FUNC(getkey) server_id = silc_id_payload_get_id(idp); server_entry = silc_idlist_find_server_by_id(server->local_list, server_id, - NULL); + TRUE, NULL); if (!server_entry) { server_entry = silc_idlist_find_server_by_id(server->global_list, - server_id, NULL); + server_id, TRUE, NULL); if (!server_entry) goto out; } diff --git a/apps/silcd/idlist.c b/apps/silcd/idlist.c index 3a004632..cb18b18b 100644 --- a/apps/silcd/idlist.c +++ b/apps/silcd/idlist.c @@ -124,7 +124,7 @@ silc_idlist_add_server(SilcIDList id_list, SilcServerEntry silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id, - SilcIDCacheEntry *ret_entry) + bool registered, SilcIDCacheEntry *ret_entry) { SilcIDCacheEntry id_cache = NULL; SilcServerEntry server; @@ -144,6 +144,9 @@ silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id, if (ret_entry) *ret_entry = id_cache; + if (server && registered && !server->data.registered) + return NULL; + SILC_LOG_DEBUG(("Found")); return server; @@ -153,7 +156,7 @@ silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id, SilcServerEntry silc_idlist_find_server_by_name(SilcIDList id_list, char *name, - SilcIDCacheEntry *ret_entry) + bool registered, SilcIDCacheEntry *ret_entry) { SilcIDCacheEntry id_cache = NULL; SilcServerEntry server; @@ -168,6 +171,9 @@ silc_idlist_find_server_by_name(SilcIDList id_list, char *name, if (ret_entry) *ret_entry = id_cache; + if (server && registered && !server->data.registered) + return NULL; + SILC_LOG_DEBUG(("Found")); return server; @@ -177,7 +183,8 @@ silc_idlist_find_server_by_name(SilcIDList id_list, char *name, SilcServerEntry silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname, - int port, SilcIDCacheEntry *ret_entry) + int port, bool registered, + SilcIDCacheEntry *ret_entry) { SilcIDCacheList list = NULL; SilcIDCacheEntry id_cache = NULL; @@ -215,6 +222,9 @@ silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname, if (ret_entry) *ret_entry = id_cache; + if (server && registered && !server->data.registered) + return NULL; + SILC_LOG_DEBUG(("Found")); return server; @@ -445,7 +455,7 @@ int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname, SilcClientEntry silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id, - SilcIDCacheEntry *ret_entry) + bool registered, SilcIDCacheEntry *ret_entry) { SilcIDCacheEntry id_cache = NULL; SilcClientEntry client; @@ -471,6 +481,9 @@ silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id, if (ret_entry) *ret_entry = id_cache; + if (client && registered && !client->data.registered) + return NULL; + SILC_LOG_DEBUG(("Found")); return client; diff --git a/apps/silcd/idlist.h b/apps/silcd/idlist.h index 0f0cb3e7..5a11125d 100644 --- a/apps/silcd/idlist.h +++ b/apps/silcd/idlist.h @@ -531,13 +531,14 @@ silc_idlist_add_server(SilcIDList id_list, void *connection); SilcServerEntry silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id, - SilcIDCacheEntry *ret_entry); + bool registered, SilcIDCacheEntry *ret_entry); SilcServerEntry silc_idlist_find_server_by_name(SilcIDList id_list, char *name, - SilcIDCacheEntry *ret_entry); + bool registered, SilcIDCacheEntry *ret_entry); SilcServerEntry silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname, - int port, SilcIDCacheEntry *ret_entry); + int port, bool registered, + SilcIDCacheEntry *ret_entry); SilcServerEntry silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id, SilcServerID *new_id); @@ -557,7 +558,7 @@ int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname, uint32 *clients_count); SilcClientEntry silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id, - SilcIDCacheEntry *ret_entry); + bool registered, SilcIDCacheEntry *ret_entry); SilcClientEntry silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id, SilcClientID *new_id); diff --git a/apps/silcd/packet_receive.c b/apps/silcd/packet_receive.c index 92e8b64e..89f25754 100644 --- a/apps/silcd/packet_receive.c +++ b/apps/silcd/packet_receive.c @@ -141,10 +141,12 @@ void silc_server_notify(SilcServer server, channel will be global channel) and if it does not exist then create entry for the client. */ client = silc_idlist_find_client_by_id(server->global_list, - client_id, NULL); + client_id, server->server_type, + NULL); if (!client) { client = silc_idlist_find_client_by_id(server->local_list, - client_id, NULL); + client_id, server->server_type, + NULL); if (!client) { /* If router did not find the client the it is bogus */ if (server->server_type == SILC_ROUTER) @@ -155,6 +157,7 @@ void silc_server_notify(SilcServer server, silc_id_dup(client_id, SILC_ID_CLIENT), sock->user_data, NULL); if (!client) { + SILC_LOG_ERROR(("Could not add new client to the ID Cache")); silc_free(client_id); goto out; } @@ -229,10 +232,10 @@ void silc_server_notify(SilcServer server, /* Get client entry */ client = silc_idlist_find_client_by_id(server->global_list, - client_id, NULL); + client_id, TRUE, NULL); if (!client) { client = silc_idlist_find_client_by_id(server->local_list, - client_id, NULL); + client_id, TRUE, NULL); if (!client) { silc_free(client_id); silc_free(channel_id); @@ -261,10 +264,10 @@ void silc_server_notify(SilcServer server, /* Get client entry */ client = silc_idlist_find_client_by_id(server->global_list, - client_id, &cache); + client_id, TRUE, &cache); if (!client) { client = silc_idlist_find_client_by_id(server->local_list, - client_id, &cache); + client_id, TRUE, &cache); if (!client) { silc_free(client_id); goto out; @@ -512,10 +515,10 @@ void silc_server_notify(SilcServer server, /* Get client entry */ client = silc_idlist_find_client_by_id(server->global_list, - client_id, NULL); + client_id, TRUE, NULL); if (!client) { client = silc_idlist_find_client_by_id(server->local_list, - client_id, NULL); + client_id, TRUE, NULL); if (!client) { silc_free(client_id); goto out; @@ -755,10 +758,10 @@ void silc_server_notify(SilcServer server, /* Get server entry */ server_entry = silc_idlist_find_server_by_id(server->global_list, - server_id, NULL); + server_id, TRUE, NULL); if (!server_entry) { server_entry = silc_idlist_find_server_by_id(server->local_list, - server_id, NULL); + server_id, TRUE, NULL); if (!server_entry) { silc_free(server_id); goto out; @@ -818,10 +821,10 @@ void silc_server_notify(SilcServer server, /* If the the client is not in local list we check global list */ client = silc_idlist_find_client_by_id(server->global_list, - client_id, NULL); + client_id, TRUE, NULL); if (!client) { client = silc_idlist_find_client_by_id(server->local_list, - client_id, NULL); + client_id, TRUE, NULL); if (!client) { silc_free(client_id); goto out; @@ -853,10 +856,10 @@ void silc_server_notify(SilcServer server, /* If the the client is not in local list we check global list */ client = silc_idlist_find_client_by_id(server->global_list, - client_id, NULL); + client_id, TRUE, NULL); if (!client) { client = silc_idlist_find_client_by_id(server->local_list, - client_id, NULL); + client_id, TRUE, NULL); if (!client) { silc_free(client_id); goto out; @@ -911,10 +914,10 @@ void silc_server_notify(SilcServer server, /* Get client entry */ client = silc_idlist_find_client_by_id(server->global_list, - client_id, NULL); + client_id, TRUE, NULL); if (!client) { client = silc_idlist_find_client_by_id(server->local_list, - client_id, NULL); + client_id, TRUE, NULL); if (!client) { silc_free(client_id); goto out; @@ -1158,7 +1161,7 @@ void silc_server_command_reply(SilcServer server, id = silc_id_str2id(packet->dst_id, packet->dst_id_len, SILC_ID_CLIENT); if (!id) return; - client = silc_idlist_find_client_by_id(server->local_list, id, NULL); + client = silc_idlist_find_client_by_id(server->local_list, id, TRUE, NULL); if (!client) { SILC_LOG_ERROR(("Cannot process command reply to unknown client")); silc_free(id); @@ -1241,10 +1244,10 @@ void silc_server_channel_message(SilcServer server, goto out; if (packet->src_id_type == SILC_ID_CLIENT) { sender_entry = silc_idlist_find_client_by_id(server->local_list, - sender, NULL); + sender, TRUE, NULL); if (!sender_entry) sender_entry = silc_idlist_find_client_by_id(server->global_list, - sender, NULL); + sender, TRUE, NULL); if (!sender_entry || !silc_server_client_on_channel(sender_entry, channel)) { SILC_LOG_DEBUG(("Client not on channel")); @@ -1600,7 +1603,7 @@ SilcServerEntry silc_server_new_server(SilcServer server, /* Add again the entry to the ID cache. */ silc_idcache_add(server->local_list->servers, server_name, server_id, - server, FALSE); + new_server, FALSE); /* Distribute the information about new server in the SILC network to our router. If we are normal server we won't send anything @@ -1681,10 +1684,10 @@ static void silc_server_new_id_real(SilcServer server, void *sender_id = silc_id_str2id(packet->src_id, packet->src_id_len, packet->src_id_type); router = silc_idlist_find_server_by_id(server->global_list, - sender_id, NULL); + sender_id, TRUE, NULL); if (!router) router = silc_idlist_find_server_by_id(server->local_list, - sender_id, NULL); + sender_id, TRUE, NULL); silc_free(sender_id); if (!router) goto out; @@ -1706,6 +1709,10 @@ static void silc_server_new_id_real(SilcServer server, list. */ entry = silc_idlist_add_client(id_list, NULL, NULL, NULL, id, router, NULL); + if (!entry) { + SILC_LOG_ERROR(("Could not add new client to the ID Cache")); + goto out; + } entry->nickname = NULL; entry->data.registered = TRUE; @@ -1716,24 +1723,35 @@ static void silc_server_new_id_real(SilcServer server, break; case SILC_ID_SERVER: - /* If the ID is mine, ignore it. */ - if (SILC_ID_SERVER_COMPARE(id, server->id)) { - SILC_LOG_DEBUG(("Ignoring my own ID as new ID")); - break; - } - - SILC_LOG_DEBUG(("New server id(%s) from [%s] %s", - silc_id_render(id, SILC_ID_SERVER), - sock->type == SILC_SOCKET_TYPE_SERVER ? - "Server" : "Router", sock->hostname)); - - /* As a router we keep information of all global information in our global - list. Cell wide information however is kept in the local list. */ - silc_idlist_add_server(id_list, NULL, 0, id, router, router_sock); + { + SilcServerEntry entry; - if (sock->type == SILC_SOCKET_TYPE_SERVER) - server->stat.cell_servers++; - server->stat.servers++; + /* If the ID is mine, ignore it. */ + if (SILC_ID_SERVER_COMPARE(id, server->id)) { + SILC_LOG_DEBUG(("Ignoring my own ID as new ID")); + break; + } + + SILC_LOG_DEBUG(("New server id(%s) from [%s] %s", + silc_id_render(id, SILC_ID_SERVER), + sock->type == SILC_SOCKET_TYPE_SERVER ? + "Server" : "Router", sock->hostname)); + + /* As a router we keep information of all global information in our + global list. Cell wide information however is kept in the local + list. */ + entry = silc_idlist_add_server(id_list, NULL, 0, id, router, + router_sock); + if (!entry) { + SILC_LOG_ERROR(("Could not add new server to the ID Cache")); + goto out; + } + entry->data.registered = TRUE; + + if (sock->type == SILC_SOCKET_TYPE_SERVER) + server->stat.cell_servers++; + server->stat.servers++; + } break; case SILC_ID_CHANNEL: diff --git a/apps/silcd/server.c b/apps/silcd/server.c index c4f9f48f..b9f9c284 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -236,6 +236,7 @@ int silc_server_init(SilcServer server) SILC_LOG_ERROR(("Could not add ourselves to cache")); goto err0; } + id_entry->data.registered = TRUE; /* Add ourselves also to the socket table. The entry allocated above is sent as argument for fast referencing in the future. */ @@ -2230,6 +2231,8 @@ void silc_server_free_client_data(SilcServer server, (void *)i, 300, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_LOW); client->data.registered = FALSE; + client->router = NULL; + client->connection = NULL; /* Free the client entry and everything in it */ server->stat.my_clients--; @@ -3732,10 +3735,11 @@ void silc_server_save_users_on_channel(SilcServer server, /* Check if we have this client cached already. */ client = silc_idlist_find_client_by_id(server->local_list, client_id, - NULL); + server->server_type, NULL); if (!client) client = silc_idlist_find_client_by_id(server->global_list, - client_id, NULL); + client_id, server->server_type, + NULL); if (!client) { /* If router did not find such Client ID in its lists then this must be bogus client or some router in the net is buggy. */ @@ -3751,6 +3755,7 @@ void silc_server_save_users_on_channel(SilcServer server, silc_id_dup(client_id, SILC_ID_CLIENT), sock->user_data, NULL); if (!client) { + SILC_LOG_ERROR(("Could not add new client to the ID Cache")); silc_free(client_id); continue; } @@ -3801,13 +3806,10 @@ SilcSocketConnection silc_server_get_client_route(SilcServer server, /* If the destination belongs to our server we don't have to route the packet anywhere but to send it to the local destination. */ - client = silc_idlist_find_client_by_id(server->local_list, id, NULL); + client = silc_idlist_find_client_by_id(server->local_list, id, TRUE, NULL); if (client) { silc_free(id); - if (client->data.registered == FALSE) - return NULL; - /* If we are router and the client has router then the client is in our cell but not directly connected to us. */ if (server->server_type == SILC_ROUTER && client->router) { @@ -3838,7 +3840,8 @@ SilcSocketConnection silc_server_get_client_route(SilcServer server, and send the packet to fastest route. */ if (server->server_type == SILC_ROUTER && !server->standalone) { /* Check first that the ID is valid */ - client = silc_idlist_find_client_by_id(server->global_list, id, NULL); + client = silc_idlist_find_client_by_id(server->global_list, id, + TRUE, NULL); if (client) { SilcSocketConnection dst_sock; @@ -3911,10 +3914,11 @@ SilcClientEntry silc_server_get_client_resolve(SilcServer server, { SilcClientEntry client; - client = silc_idlist_find_client_by_id(server->local_list, client_id, NULL); + client = silc_idlist_find_client_by_id(server->local_list, client_id, + TRUE, NULL); if (!client) { client = silc_idlist_find_client_by_id(server->global_list, - client_id, NULL); + client_id, TRUE, NULL); if (!client && server->server_type == SILC_ROUTER) return NULL; } @@ -3922,9 +3926,6 @@ SilcClientEntry silc_server_get_client_resolve(SilcServer server, if (!client && server->standalone) return NULL; - if (!client->data.registered) - return NULL; - if (!client || !client->nickname || !client->username) { SilcBuffer buffer, idp;