+Sat Aug 11 00:29:57 EEST 2001 Pekka Riikonen <priikone@silcnet.org>
+
+ * 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 <priikone@silcnet.org>
* Do not delete the channel rekey task when adding it
}
}
+ /* 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 &&
/* 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;
}
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;
/* 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;
}
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 {
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) {
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 */
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. */
silc_free(server_id);
goto error;
}
+ server_entry->data.registered = TRUE;
server_id = NULL;
}
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);
silc_free(server_id);
goto out;
}
+ entry->data.registered = TRUE;
}
}
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;
}
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;
}
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;
}
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;
if (ret_entry)
*ret_entry = id_cache;
+ if (server && registered && !server->data.registered)
+ return NULL;
+
SILC_LOG_DEBUG(("Found"));
return server;
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;
if (ret_entry)
*ret_entry = id_cache;
+ if (server && registered && !server->data.registered)
+ return NULL;
+
SILC_LOG_DEBUG(("Found"));
return server;
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;
if (ret_entry)
*ret_entry = id_cache;
+ if (server && registered && !server->data.registered)
+ return NULL;
+
SILC_LOG_DEBUG(("Found"));
return server;
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;
if (ret_entry)
*ret_entry = id_cache;
+ if (client && registered && !client->data.registered)
+ return NULL;
+
SILC_LOG_DEBUG(("Found"));
return client;
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);
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);
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)
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;
}
/* 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);
/* 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;
/* 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;
/* 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;
/* 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;
/* 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;
/* 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;
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);
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"));
/* 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
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;
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;
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:
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. */
(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--;
/* 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. */
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;
}
/* 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) {
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;
{
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;
}
if (!client && server->standalone)
return NULL;
- if (!client->data.registered)
- return NULL;
-
if (!client || !client->nickname || !client->username) {
SilcBuffer buffer, idp;