we will broadcast it. The sending socket really cannot be router or
the router is buggy. If this packet is coming from router then it must
have the broadcast flag set already and we won't do anything. */
- if (!server->standalone && server->server_type == SILC_ROUTER &&
+ if (server->server_type == SILC_ROUTER &&
sock->type == SILC_SOCKET_TYPE_SERVER &&
!(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
SILC_LOG_DEBUG(("Broadcasting received Notify packet"));
if (!channel_id)
goto out;
- silc_server_packet_send_dest(server, server->router->connection,
- packet->type,
- packet->flags | SILC_PACKET_FLAG_BROADCAST,
- channel_id, SILC_ID_CHANNEL,
- packet->buffer->data, packet->buffer->len,
- FALSE);
+ if (!server->standalone)
+ silc_server_packet_send_dest(server, server->router->connection,
+ packet->type, packet->flags |
+ SILC_PACKET_FLAG_BROADCAST,
+ channel_id, SILC_ID_CHANNEL,
+ packet->buffer->data,
+ packet->buffer->len, FALSE);
silc_server_backup_send_dest(server, (SilcServerEntry)sock->user_data,
packet->type, packet->flags,
channel_id, SILC_ID_CHANNEL,
FALSE, TRUE);
} else {
/* Packet is destined to client or server */
- silc_server_packet_send(server, server->router->connection,
- packet->type,
- packet->flags | SILC_PACKET_FLAG_BROADCAST,
- packet->buffer->data, packet->buffer->len,
- FALSE);
+ if (!server->standalone)
+ silc_server_packet_send(server, server->router->connection,
+ packet->type,
+ packet->flags | SILC_PACKET_FLAG_BROADCAST,
+ packet->buffer->data, packet->buffer->len,
+ FALSE);
silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
packet->type, packet->flags,
packet->buffer->data, packet->buffer->len,
silc_hash_table_add(client->channels, channel, chl);
silc_free(client_id);
channel->user_count++;
+ channel->disabled = FALSE;
+
+ /* Update statistics */
+ if (server->server_type == SILC_ROUTER) {
+ if (sock->type != SILC_SOCKET_TYPE_ROUTER)
+ server->stat.cell_chanclients++;
+ server->stat.chanclients++;
+ }
break;
SILC_LOG_DEBUG(("CMODE change is not allowed"));
goto out;
}
+ } else {
+ if (server->server_type == SILC_ROUTER &&
+ channel->mode & SILC_CHANNEL_MODE_FOUNDER_AUTH &&
+ !(mode & SILC_CHANNEL_MODE_FOUNDER_AUTH)) {
+ SILC_LOG_DEBUG(("Enforcing sender to change channel mode"));
+ silc_server_send_notify_cmode(server, sock, FALSE, channel,
+ channel->mode, server->id,
+ SILC_ID_SERVER,
+ channel->cipher,
+ channel->hmac_name,
+ channel->passphrase,
+ channel->founder_key);
+ goto out;
+ }
}
/* Send the same notify to the channel */
if (channel->founder_key)
silc_pkcs_public_key_free(channel->founder_key);
channel->founder_key = NULL;
- } else if (!client->data.public_key) {
+ } else if (client && !client->data.public_key) {
client->data.public_key =
silc_pkcs_public_key_copy(channel->founder_key);
}
}
+ if (mode & SILC_CHANNEL_MODE_FOUNDER_AUTH && !channel->founder_key &&
+ server->server_type == SILC_ROUTER) {
+ SILC_LOG_DEBUG(("Enforcing sender to change channel mode"));
+ mode &= ~SILC_CHANNEL_MODE_FOUNDER_AUTH;
+ silc_server_send_notify_cmode(server, sock, FALSE, channel,
+ mode, server->id, SILC_ID_SERVER,
+ channel->cipher,
+ channel->hmac_name,
+ channel->passphrase, NULL);
+ }
+
/* Change mode */
channel->mode = mode;
if (!silc_server_client_on_channel(client, channel, &chl))
goto out;
- if (client != client2) {
+ if (client != client2 && server->server_type == SILC_ROUTER) {
/* Sender must be operator */
if (!(chl->mode & SILC_CHANNEL_UMODE_CHANOP) &&
!(chl->mode & SILC_CHANNEL_UMODE_CHANFO)) {
goto out;
}
- /* Check that target is on channel */
if (!silc_server_client_on_channel(client2, channel, &chl))
goto out;
}
}
+ /* Get target channel entry */
+ if (!silc_server_client_on_channel(client2, channel, &chl))
+ goto out;
+
if (mode & SILC_CHANNEL_UMODE_CHANFO &&
+ !(channel->mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) && !client &&
+ server->server_type == SILC_ROUTER) {
+ /* Get the founder of the channel and if found then this client
+ cannot be the founder since there already is one. */
+ silc_hash_table_list(channel->user_list, &htl);
+ while (silc_hash_table_get(&htl, NULL, (void *)&chl2))
+ if (chl2->mode & SILC_CHANNEL_UMODE_CHANFO) {
+ mode &= ~SILC_CHANNEL_UMODE_CHANFO;
+ silc_server_force_cumode_change(server, sock, channel, chl, mode);
+ notify_sent = TRUE;
+ break;
+ }
+ silc_hash_table_list_reset(&htl);
+ if (!(mode & SILC_CHANNEL_UMODE_CHANFO))
+ break;
+ }
+
+ if (client && mode & SILC_CHANNEL_UMODE_CHANFO &&
!(chl->mode & SILC_CHANNEL_UMODE_CHANFO) &&
server->server_type == SILC_ROUTER) {
/* Check whether this client is allowed to be channel founder on
this channel. */
- SilcPublicKey founder_key;
+ SilcPublicKey founder_key = NULL;
/* If channel doesn't have founder auth mode then it's impossible
that someone would be getting founder rights with CUMODE command.
break;
}
- /* Now match the public key we have cached and publick key sent.
+ /* Now match the public key we have cached and public key sent.
They must match. */
- if (!silc_pkcs_public_key_compare(channel->founder_key,
+ if (client->data.public_key &&
+ !silc_pkcs_public_key_compare(channel->founder_key,
client->data.public_key)) {
mode &= ~SILC_CHANNEL_UMODE_CHANFO;
silc_server_force_cumode_change(server, sock, channel, chl, mode);
notify_sent = TRUE;
break;
}
+ if (!silc_pkcs_public_key_compare(channel->founder_key,
+ founder_key)) {
+ mode &= ~SILC_CHANNEL_UMODE_CHANFO;
+ silc_server_force_cumode_change(server, sock, channel, chl, mode);
+ notify_sent = TRUE;
+ break;
+ }
+
+ if (founder_key)
+ silc_pkcs_public_key_free(founder_key);
}
SILC_LOG_DEBUG(("Changing the channel user mode"));
}
if (channel_id2) {
- SilcBuffer users = NULL, users_modes = NULL;
+ SilcBuffer modes = NULL, users = NULL, users_modes = NULL;
/* Re-announce this channel which ID was changed. */
silc_server_send_new_channel(server, sock, FALSE, channel->channel_name,
channel->mode);
/* Re-announce our clients on the channel as the ID has changed now */
- silc_server_announce_get_channel_users(server, channel, &users,
+ silc_server_announce_get_channel_users(server, channel, &modes, &users,
&users_modes);
+ if (modes) {
+ silc_buffer_push(modes, modes->data - modes->head);
+ silc_server_packet_send_dest(server, sock,
+ SILC_PACKET_NOTIFY, SILC_PACKET_FLAG_LIST,
+ channel->id, SILC_ID_CHANNEL,
+ modes->data, modes->len, FALSE);
+ silc_buffer_free(modes);
+ }
if (users) {
silc_buffer_push(users, users->data - users->head);
silc_server_packet_send(server, sock,
silc_idlist_del_server(local ? server->local_list :
server->global_list, server_entry);
- /* XXX update statistics */
+ /* Update statistics */
+ if (server->server_type == SILC_ROUTER)
+ server->stat.servers--;
break;
if (mode & SILC_UMODE_DETACHED)
client->data.status &= ~SILC_IDLIST_STATUS_RESUMED;
+ /* Update statistics */
+ if (server->server_type == SILC_ROUTER) {
+ if (mode & SILC_UMODE_GONE) {
+ if (!client->mode & SILC_UMODE_GONE)
+ server->stat.aways++;
+ } else {
+ if (client->mode & SILC_UMODE_GONE)
+ server->stat.aways--;
+ }
+ if (mode & SILC_UMODE_DETACHED) {
+ if (!client->mode & SILC_UMODE_DETACHED)
+ server->stat.detached++;
+ } else {
+ if (client->mode & SILC_UMODE_DETACHED)
+ server->stat.detached--;
+ }
+ }
+
/* Change the mode */
client->mode = mode;
SILC_LOG_DEBUG(("Channel is silenced from operators"));
goto out;
}
+ if (chl->mode & SILC_CHANNEL_UMODE_QUIET) {
+ SILC_LOG_DEBUG(("Sender is quieted on the channel"));
+ goto out;
+ }
/* If the packet is coming from router, but the client entry is local
entry to us then some router is rerouting this to us and it is not
server->router->connection,
server->server_type == SILC_ROUTER ? TRUE : FALSE,
client->id, SILC_ID_CLIENT, id_len);
-
+
+ /* Distribute to backup routers */
+ if (server->server_type == SILC_ROUTER) {
+ SilcBuffer idp = silc_id_payload_encode(client->id, SILC_ID_CLIENT);
+ silc_server_backup_send(server, NULL, SILC_PACKET_NEW_ID, 0,
+ idp->data, idp->len, FALSE, TRUE);
+ silc_buffer_free(idp);
+ }
+
/* Send the new client ID to the client. */
silc_server_send_new_id(server, sock, FALSE, client->id, SILC_ID_CLIENT,
silc_id_get_len(client->id, SILC_ID_CLIENT));
TRUE, new_server->id, SILC_ID_SERVER,
silc_id_get_len(server_id, SILC_ID_SERVER));
- if (server->server_type == SILC_ROUTER)
+ if (server->server_type == SILC_ROUTER) {
+ /* Distribute to backup routers */
+ SilcBuffer idp = silc_id_payload_encode(new_server->id, SILC_ID_SERVER);
+ silc_server_backup_send(server, NULL, SILC_PACKET_NEW_ID, 0,
+ idp->data, idp->len, FALSE, TRUE);
+ silc_buffer_free(idp);
+
+ /* Statistics */
server->stat.cell_servers++;
+ }
/* Check whether this router connection has been replaced by an
backup router. If it has been then we'll disable the server and will
/* If the sender of this packet is server and we are router we need to
broadcast this packet to other routers in the network. */
- if (broadcast && !server->standalone && server->server_type == SILC_ROUTER &&
+ if (broadcast && server->server_type == SILC_ROUTER &&
sock->type == SILC_SOCKET_TYPE_SERVER &&
!(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
SILC_LOG_DEBUG(("Broadcasting received New ID packet"));
- silc_server_packet_send(server, server->router->connection,
- packet->type,
- packet->flags | SILC_PACKET_FLAG_BROADCAST,
- buffer->data, buffer->len, FALSE);
+ if (!server->standalone)
+ silc_server_packet_send(server, server->router->connection,
+ packet->type,
+ packet->flags | SILC_PACKET_FLAG_BROADCAST,
+ buffer->data, buffer->len, FALSE);
silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
packet->type, packet->flags,
packet->buffer->data, packet->buffer->len,
/* If the sender of this packet is server and we are router we need to
broadcast this packet to other routers in the network. Broadcast
this list packet instead of multiple New ID packets. */
- if (!server->standalone && server->server_type == SILC_ROUTER &&
+ if (server->server_type == SILC_ROUTER &&
sock->type == SILC_SOCKET_TYPE_SERVER &&
!(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
SILC_LOG_DEBUG(("Broadcasting received New ID List packet"));
- silc_server_packet_send(server, server->router->connection,
- packet->type,
- packet->flags | SILC_PACKET_FLAG_BROADCAST,
- packet->buffer->data, packet->buffer->len, FALSE);
+ if (!server->standalone)
+ silc_server_packet_send(server, server->router->connection,
+ packet->type,
+ packet->flags | SILC_PACKET_FLAG_BROADCAST,
+ packet->buffer->data,
+ packet->buffer->len, FALSE);
silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
packet->type, packet->flags,
packet->buffer->data, packet->buffer->len,
0, channel_id, sock->user_data, NULL, NULL, 0);
if (!channel)
return;
+ channel->disabled = TRUE;
server->stat.channels++;
if (server->server_type == SILC_ROUTER)
silc_free(channel_id);
return;
}
-
- /* Get the mode and set it to the channel */
- channel->mode = silc_channel_get_mode(payload);
+ channel->disabled = TRUE;
/* Send the new channel key to the server */
id = silc_id_id2str(channel->id, SILC_ID_CHANNEL);
silc_server_packet_send(server, sock, SILC_PACKET_CHANNEL_KEY, 0,
chk->data, chk->len, FALSE);
silc_buffer_free(chk);
-
} else {
/* The channel exist by that name, check whether the ID's match.
If they don't then we'll force the server to use the ID we have.
We also create a new key for the channel. */
- SilcBuffer users = NULL, users_modes = NULL;
+ SilcBuffer modes = NULL, users = NULL, users_modes = NULL;
if (!SILC_ID_CHANNEL_COMPARE(channel_id, channel->id)) {
/* They don't match, send CHANNEL_CHANGE notify to the server to
silc_free(channel_id);
+ /* Update statistics */
+ server->stat.channels++;
+ server->stat.cell_channels++;
+
/* Since the channel is coming from server and we also know about it
then send the JOIN notify to the server so that it see's our
users on the channel "joining" the channel. */
- silc_server_announce_get_channel_users(server, channel, &users,
+ silc_server_announce_get_channel_users(server, channel, &modes, &users,
&users_modes);
+ if (modes) {
+ silc_buffer_push(modes, modes->data - modes->head);
+ silc_server_packet_send_dest(server, sock,
+ SILC_PACKET_NOTIFY, SILC_PACKET_FLAG_LIST,
+ channel->id, SILC_ID_CHANNEL,
+ modes->data, modes->len, FALSE);
+ silc_buffer_free(modes);
+ }
if (users) {
silc_buffer_push(users, users->data - users->head);
silc_server_packet_send(server, sock,
/* If the sender of this packet is server and we are router we need to
broadcast this packet to other routers in the network. Broadcast
this list packet instead of multiple New Channel packets. */
- if (!server->standalone && server->server_type == SILC_ROUTER &&
+ if (server->server_type == SILC_ROUTER &&
sock->type == SILC_SOCKET_TYPE_SERVER &&
!(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
SILC_LOG_DEBUG(("Broadcasting received New Channel List packet"));
- silc_server_packet_send(server, server->router->connection,
- packet->type,
- packet->flags | SILC_PACKET_FLAG_BROADCAST,
- packet->buffer->data, packet->buffer->len, FALSE);
+ if (!server->standalone)
+ silc_server_packet_send(server, server->router->connection,
+ packet->type,
+ packet->flags | SILC_PACKET_FLAG_BROADCAST,
+ packet->buffer->data,
+ packet->buffer->len, FALSE);
silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
packet->type, packet->flags,
packet->buffer->data, packet->buffer->len,
server->stat.clients--;
if (server->stat.cell_clients)
server->stat.cell_clients--;
+ silc_server_del_from_watcher_list(server, client);
silc_idlist_del_client(server->local_list, client);
client = detached_client;
/* If the sender of this packet is server and we are router we need to
broadcast this packet to other routers in the network. */
- if (!server->standalone && server->server_type == SILC_ROUTER &&
+ if (server->server_type == SILC_ROUTER &&
sock->type == SILC_SOCKET_TYPE_SERVER &&
!(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
SILC_LOG_DEBUG(("Broadcasting received Resume Client packet"));
- silc_server_packet_send(server, server->router->connection,
- packet->type,
- packet->flags | SILC_PACKET_FLAG_BROADCAST,
- buffer->data, buffer->len, FALSE);
+ if (!server->standalone)
+ silc_server_packet_send(server, server->router->connection,
+ packet->type,
+ packet->flags | SILC_PACKET_FLAG_BROADCAST,
+ buffer->data, buffer->len, FALSE);
silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
packet->type, packet->flags,
packet->buffer->data, packet->buffer->len,