5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2002 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
21 * Server packet routines to handle received packets.
25 #include "serverincludes.h"
26 #include "server_internal.h"
28 /* Received notify packet. Server can receive notify packets from router.
29 Server then relays the notify messages to clients if needed. */
31 void silc_server_notify(SilcServer server,
32 SilcSocketConnection sock,
33 SilcPacketContext *packet)
35 SilcNotifyPayload payload;
37 SilcArgumentPayload args;
38 SilcChannelID *channel_id = NULL, *channel_id2;
39 SilcClientID *client_id, *client_id2;
40 SilcServerID *server_id;
42 SilcChannelEntry channel = NULL;
43 SilcClientEntry client = NULL, client2 = NULL;
44 SilcServerEntry server_entry = NULL;
45 SilcChannelClientEntry chl;
46 SilcIDCacheEntry cache;
47 SilcHashTableList htl;
53 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
54 packet->src_id_type != SILC_ID_SERVER || !packet->dst_id) {
55 SILC_LOG_DEBUG(("Bad notify packet received"));
59 /* If the packet is destined directly to a client then relay the packet
60 before processing it. */
61 if (packet->dst_id_type == SILC_ID_CLIENT) {
63 SilcSocketConnection dst_sock;
65 /* Get the route to the client */
66 dst_sock = silc_server_get_client_route(server, packet->dst_id,
67 packet->dst_id_len, NULL,
70 /* Relay the packet */
71 silc_server_relay_packet(server, dst_sock, idata->send_key,
72 idata->hmac_send, idata->psn_send++,
76 /* Parse the Notify Payload */
77 payload = silc_notify_payload_parse(packet->buffer->data,
82 /* If we are router and this packet is not already broadcast packet
83 we will broadcast it. The sending socket really cannot be router or
84 the router is buggy. If this packet is coming from router then it must
85 have the broadcast flag set already and we won't do anything. */
86 if (server->server_type == SILC_ROUTER &&
87 sock->type == SILC_SOCKET_TYPE_SERVER &&
88 !(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
89 SILC_LOG_DEBUG(("Broadcasting received Notify packet"));
90 if (packet->dst_id_type == SILC_ID_CHANNEL) {
91 /* Packet is destined to channel */
92 channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len,
97 silc_server_packet_send_dest(server, SILC_PRIMARY_ROUTE(server),
98 packet->type, packet->flags |
99 SILC_PACKET_FLAG_BROADCAST,
100 channel_id, SILC_ID_CHANNEL,
101 packet->buffer->data,
102 packet->buffer->len, FALSE);
103 silc_server_backup_send_dest(server, (SilcServerEntry)sock->user_data,
104 packet->type, packet->flags,
105 channel_id, SILC_ID_CHANNEL,
106 packet->buffer->data, packet->buffer->len,
109 /* Packet is destined to client or server */
110 silc_server_packet_send(server, SILC_PRIMARY_ROUTE(server),
112 packet->flags | SILC_PACKET_FLAG_BROADCAST,
113 packet->buffer->data, packet->buffer->len,
115 silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
116 packet->type, packet->flags,
117 packet->buffer->data, packet->buffer->len,
122 type = silc_notify_get_type(payload);
123 args = silc_notify_get_args(payload);
128 case SILC_NOTIFY_TYPE_JOIN:
130 * Distribute the notify to local clients on the channel
132 SILC_LOG_DEBUG(("JOIN notify"));
135 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
138 channel_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
142 /* Get channel entry */
143 channel = silc_idlist_find_channel_by_id(server->global_list,
146 channel = silc_idlist_find_channel_by_id(server->local_list,
149 SILC_LOG_DEBUG(("Notify for unknown channel"));
150 silc_free(channel_id);
154 silc_free(channel_id);
157 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
160 client_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
164 /* If the the client is not in local list we check global list (ie. the
165 channel will be global channel) and if it does not exist then create
166 entry for the client. */
167 client = silc_idlist_find_client_by_id(server->global_list,
168 client_id, server->server_type,
171 client = silc_idlist_find_client_by_id(server->local_list,
172 client_id, server->server_type,
175 /* If router did not find the client the it is bogus */
176 if (server->server_type != SILC_SERVER)
180 silc_idlist_add_client(server->global_list, NULL, NULL, NULL,
181 silc_id_dup(client_id, SILC_ID_CLIENT),
182 sock->user_data, NULL, 0);
184 SILC_LOG_ERROR(("Could not add new client to the ID Cache"));
185 silc_free(client_id);
189 client->data.status |= SILC_IDLIST_STATUS_REGISTERED;
193 /* Do not process the notify if the client is not registered */
194 if (!(client->data.status & SILC_IDLIST_STATUS_REGISTERED))
197 /* Do not add client to channel if it is there already */
198 if (silc_server_client_on_channel(client, channel, NULL)) {
199 SILC_LOG_DEBUG(("Client already on channel"));
203 /* Send to channel */
204 silc_server_packet_send_to_channel(server, sock, channel, packet->type,
205 FALSE, packet->buffer->data,
206 packet->buffer->len, FALSE);
208 if (server->server_type != SILC_ROUTER &&
209 sock->type == SILC_SOCKET_TYPE_ROUTER)
210 /* The channel is global now */
211 channel->global_users = TRUE;
213 SILC_LOG_DEBUG(("Joining to channel %s", channel->channel_name));
215 /* JOIN the global client to the channel (local clients (if router
216 created the channel) is joined in the pending JOIN command). */
217 chl = silc_calloc(1, sizeof(*chl));
218 chl->client = client;
219 chl->channel = channel;
221 /* If this is the first one on the channel then it is the founder of
223 if (!silc_hash_table_count(channel->user_list))
224 chl->mode = (SILC_CHANNEL_UMODE_CHANOP | SILC_CHANNEL_UMODE_CHANFO);
226 silc_hash_table_add(channel->user_list, client, chl);
227 silc_hash_table_add(client->channels, channel, chl);
228 silc_free(client_id);
229 channel->user_count++;
230 channel->disabled = FALSE;
232 /* Update statistics */
233 if (server->server_type == SILC_ROUTER) {
234 if (sock->type != SILC_SOCKET_TYPE_ROUTER)
235 server->stat.cell_chanclients++;
236 server->stat.chanclients++;
241 case SILC_NOTIFY_TYPE_LEAVE:
243 * Distribute the notify to local clients on the channel
245 SILC_LOG_DEBUG(("LEAVE notify"));
248 channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len,
249 packet->dst_id_type);
254 /* Get channel entry */
255 channel = silc_idlist_find_channel_by_id(server->global_list,
258 channel = silc_idlist_find_channel_by_id(server->local_list,
261 SILC_LOG_DEBUG(("Notify for unknown channel"));
262 silc_free(channel_id);
268 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
270 silc_free(channel_id);
273 client_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
275 silc_free(channel_id);
279 /* Get client entry */
280 client = silc_idlist_find_client_by_id(server->global_list,
281 client_id, TRUE, NULL);
283 client = silc_idlist_find_client_by_id(server->local_list,
284 client_id, TRUE, NULL);
286 silc_free(client_id);
287 silc_free(channel_id);
291 silc_free(client_id);
293 /* Check if on channel */
294 if (!silc_server_client_on_channel(client, channel, NULL))
297 /* Send the leave notify to channel */
298 silc_server_packet_send_to_channel(server, sock, channel, packet->type,
299 FALSE, packet->buffer->data,
300 packet->buffer->len, FALSE);
302 /* Remove the user from channel */
303 silc_server_remove_from_one_channel(server, sock, channel, client, FALSE);
306 case SILC_NOTIFY_TYPE_SIGNOFF:
308 * Distribute the notify to local clients on the channel
310 SILC_LOG_DEBUG(("SIGNOFF notify"));
313 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
316 client_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
320 /* Get client entry */
321 client = silc_idlist_find_client_by_id(server->global_list,
322 client_id, TRUE, &cache);
324 client = silc_idlist_find_client_by_id(server->local_list,
325 client_id, TRUE, &cache);
327 silc_free(client_id);
331 silc_free(client_id);
333 /* Get signoff message */
334 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
338 /* Update statistics */
339 server->stat.clients--;
340 if (server->stat.cell_clients)
341 server->stat.cell_clients--;
342 SILC_OPER_STATS_UPDATE(client, server, SILC_UMODE_SERVER_OPERATOR);
343 SILC_OPER_STATS_UPDATE(client, router, SILC_UMODE_ROUTER_OPERATOR);
344 silc_schedule_task_del_by_context(server->schedule, client);
346 /* Remove the client from all channels. */
347 silc_server_remove_from_channels(server, NULL, client, TRUE, tmp, FALSE);
349 /* Check if anyone is watching this nickname */
350 if (server->server_type == SILC_ROUTER)
351 silc_server_check_watcher_list(server, client, NULL,
352 SILC_NOTIFY_TYPE_SIGNOFF);
354 /* Remove this client from watcher list if it is */
355 silc_server_del_from_watcher_list(server, client);
357 client->data.status &= ~SILC_IDLIST_STATUS_REGISTERED;
358 cache->expire = SILC_ID_CACHE_EXPIRE_DEF;
361 case SILC_NOTIFY_TYPE_TOPIC_SET:
363 * Distribute the notify to local clients on the channel
366 SILC_LOG_DEBUG(("TOPIC SET notify"));
369 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
372 client_id = silc_id_payload_parse_id(tmp, tmp_len, &id_type);
376 /* Get client entry */
377 if (id_type == SILC_ID_CLIENT) {
378 client = silc_idlist_find_client_by_id(server->global_list,
379 client_id, TRUE, &cache);
381 client = silc_idlist_find_client_by_id(server->local_list,
382 client_id, TRUE, &cache);
384 silc_free(client_id);
388 silc_free(client_id);
392 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
394 silc_free(channel_id);
399 channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len,
400 packet->dst_id_type);
405 /* Get channel entry */
406 channel = silc_idlist_find_channel_by_id(server->global_list,
409 channel = silc_idlist_find_channel_by_id(server->local_list,
412 SILC_LOG_DEBUG(("Notify for unknown channel"));
413 silc_free(channel_id);
418 if (channel->topic && !strcmp(channel->topic, tmp)) {
419 SILC_LOG_DEBUG(("Topic is already set and same"));
424 /* Get user's channel entry and check that topic set is allowed. */
425 if (!silc_server_client_on_channel(client, channel, &chl))
427 if (channel->mode & SILC_CHANNEL_MODE_TOPIC &&
428 !(chl->mode & SILC_CHANNEL_UMODE_CHANOP) &&
429 !(chl->mode & SILC_CHANNEL_UMODE_CHANFO)) {
430 SILC_LOG_DEBUG(("Topic change is not allowed"));
435 /* Change the topic */
436 silc_free(channel->topic);
437 channel->topic = strdup(tmp);
439 /* Send the same notify to the channel */
440 silc_server_packet_send_to_channel(server, NULL, channel, packet->type,
441 FALSE, packet->buffer->data,
442 packet->buffer->len, FALSE);
443 silc_free(channel_id);
446 case SILC_NOTIFY_TYPE_NICK_CHANGE:
449 * Distribute the notify to local clients on the channel
451 unsigned char *id, *id2;
453 SilcUInt32 nickname_len;
455 SILC_LOG_DEBUG(("NICK CHANGE notify"));
457 /* Get old client ID */
458 id = silc_argument_get_arg_type(args, 1, &tmp_len);
461 client_id = silc_id_payload_parse_id(id, tmp_len, NULL);
465 /* Get new client ID */
466 id2 = silc_argument_get_arg_type(args, 2, &tmp_len);
469 client_id2 = silc_id_payload_parse_id(id2, tmp_len, NULL);
473 SILC_LOG_DEBUG(("Old Client ID id(%s)",
474 silc_id_render(client_id, SILC_ID_CLIENT)));
475 SILC_LOG_DEBUG(("New Client ID id(%s)",
476 silc_id_render(client_id2, SILC_ID_CLIENT)));
478 /* From protocol version 1.1 we also get the new nickname */
479 nickname = silc_argument_get_arg_type(args, 3, &nickname_len);;
481 /* Replace the Client ID */
482 client = silc_idlist_replace_client_id(server,
483 server->global_list, client_id,
484 client_id2, nickname);
486 client = silc_idlist_replace_client_id(server,
487 server->local_list, client_id,
488 client_id2, nickname);
491 /* Send the NICK_CHANGE notify type to local clients on the channels
492 this client is joined to. */
493 silc_server_send_notify_on_channels(server, client, client,
494 SILC_NOTIFY_TYPE_NICK_CHANGE, 3,
495 id, tmp_len, id2, tmp_len,
500 silc_free(client_id);
502 silc_free(client_id2);
506 case SILC_NOTIFY_TYPE_CMODE_CHANGE:
508 * Distribute the notify to local clients on the channel
511 SILC_LOG_DEBUG(("CMODE CHANGE notify"));
514 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
517 client_id = silc_id_payload_parse_id(tmp, tmp_len, &id_type);
521 /* Get client entry */
522 if (id_type == SILC_ID_CLIENT) {
523 client = silc_idlist_find_client_by_id(server->global_list,
524 client_id, TRUE, &cache);
526 client = silc_idlist_find_client_by_id(server->local_list,
527 client_id, TRUE, &cache);
529 silc_free(client_id);
533 silc_free(client_id);
537 channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len,
538 packet->dst_id_type);
543 /* Get channel entry */
544 channel = silc_idlist_find_channel_by_id(server->global_list,
547 channel = silc_idlist_find_channel_by_id(server->local_list,
550 SILC_LOG_DEBUG(("Notify for unknown channel"));
551 silc_free(channel_id);
555 silc_free(channel_id);
558 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
561 SILC_GET32_MSB(mode, tmp);
563 /* Check if mode changed */
564 if (channel->mode == mode) {
565 SILC_LOG_DEBUG(("Mode is changed already"));
567 /* If this mode change has founder mode then we'll enforce the
568 change so that the server gets the real founder public key */
569 if (server->server_type != SILC_SERVER &&
570 sock != SILC_PRIMARY_ROUTE(server) &&
571 mode & SILC_CHANNEL_MODE_FOUNDER_AUTH && channel->founder_key) {
572 SILC_LOG_DEBUG(("Sending founder public key to server"));
573 silc_server_send_notify_cmode(server, sock, FALSE, channel,
574 channel->mode, server->id,
575 SILC_ID_SERVER, channel->cipher,
578 channel->founder_key);
581 /* If we received same mode from our primary check whether founder
582 mode and key in the notify is set. We update the founder key
583 here since we may have wrong one */
584 if (server->server_type == SILC_SERVER &&
585 sock == SILC_PRIMARY_ROUTE(server) &&
586 mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) {
587 SILC_LOG_DEBUG(("Founder public key received from primary router"));
588 tmp = silc_argument_get_arg_type(args, 6, &tmp_len);
592 if (channel->founder_key)
593 silc_pkcs_public_key_free(channel->founder_key);
594 channel->founder_key = NULL;
595 silc_pkcs_public_key_decode(tmp, tmp_len, &channel->founder_key);
601 /* Get user's channel entry and check that mode change is allowed */
603 if (!silc_server_client_on_channel(client, channel, &chl))
605 if (!silc_server_check_cmode_rights(server, channel, chl, mode)) {
606 SILC_LOG_DEBUG(("CMODE change is not allowed"));
607 silc_server_send_notify_cmode(server, sock, FALSE, channel,
608 channel->mode, server->id,
609 SILC_ID_SERVER, channel->cipher,
612 channel->founder_key);
616 /* Assure that server is not removing founder mode from us */
617 if (server->server_type == SILC_ROUTER &&
618 sock != SILC_PRIMARY_ROUTE(server) &&
619 channel->mode & SILC_CHANNEL_MODE_FOUNDER_AUTH &&
620 !(mode & SILC_CHANNEL_MODE_FOUNDER_AUTH)) {
621 SILC_LOG_DEBUG(("Enforcing sender to change channel mode"));
622 silc_server_send_notify_cmode(server, sock, FALSE, channel,
623 channel->mode, server->id,
624 SILC_ID_SERVER, channel->cipher,
627 channel->founder_key);
631 /* If server is adding founder mode, check whether there is founder
632 on channel already and is not from this server */
633 if (server->server_type == SILC_ROUTER &&
634 sock != SILC_PRIMARY_ROUTE(server) &&
635 mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) {
636 silc_hash_table_list(channel->user_list, &htl);
637 while (silc_hash_table_get(&htl, NULL, (void *)&chl))
638 if (chl->mode & SILC_CHANNEL_UMODE_CHANFO &&
639 chl->client->router != sock->user_data) {
640 SILC_LOG_DEBUG(("Enforcing sender to change channel mode"));
641 silc_server_send_notify_cmode(server, sock, FALSE, channel,
642 channel->mode, server->id,
643 SILC_ID_SERVER, channel->cipher,
646 channel->founder_key);
647 silc_hash_table_list_reset(&htl);
650 silc_hash_table_list_reset(&htl);
654 /* If the channel had private keys set and the mode was removed then
655 we must re-generate and re-distribute a new channel key */
656 if (channel->mode & SILC_CHANNEL_MODE_PRIVKEY &&
657 !(mode & SILC_CHANNEL_MODE_PRIVKEY)) {
658 /* Re-generate channel key */
659 if (!silc_server_create_channel_key(server, channel, 0))
662 /* Send the channel key. This sends it to our local clients and if
663 we are normal server to our router as well. */
664 silc_server_send_channel_key(server, NULL, channel,
665 server->server_type == SILC_ROUTER ?
666 FALSE : !server->standalone);
670 tmp = silc_argument_get_arg_type(args, 4, &tmp_len);
672 unsigned char hash[32];
675 silc_hmac_free(channel->hmac);
676 if (!silc_hmac_alloc(tmp, NULL, &channel->hmac))
679 /* Set the HMAC key out of current channel key. The client must do
681 silc_hash_make(silc_hmac_get_hash(channel->hmac), channel->key,
682 channel->key_len / 8, hash);
683 silc_hmac_set_key(channel->hmac, hash,
684 silc_hash_len(silc_hmac_get_hash(channel->hmac)));
685 memset(hash, 0, sizeof(hash));
688 /* Get the passphrase */
689 tmp = silc_argument_get_arg_type(args, 5, &tmp_len);
691 silc_free(channel->passphrase);
692 channel->passphrase = silc_memdup(tmp, tmp_len);
695 /* Get founder public key */
696 tmp = silc_argument_get_arg_type(args, 6, &tmp_len);
697 if (tmp && mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) {
698 if (channel->founder_key)
699 silc_pkcs_public_key_free(channel->founder_key);
700 channel->founder_key = NULL;
701 silc_pkcs_public_key_decode(tmp, tmp_len, &channel->founder_key);
703 if (!channel->founder_key ||
704 (client && client->data.public_key &&
705 server->server_type == SILC_ROUTER &&
706 !silc_pkcs_public_key_compare(channel->founder_key,
707 client->data.public_key))) {
708 /* A really buggy server isn't checking public keys correctly.
709 It's not possible that the mode setter and founder wouldn't
710 have same public key. */
711 SILC_LOG_DEBUG(("Enforcing sender to change channel mode"));
713 mode &= ~SILC_CHANNEL_MODE_FOUNDER_AUTH;
714 silc_server_send_notify_cmode(server, sock, FALSE, channel,
715 mode, server->id, SILC_ID_SERVER,
718 channel->passphrase, NULL);
719 if (channel->founder_key)
720 silc_pkcs_public_key_free(channel->founder_key);
721 channel->founder_key = NULL;
722 } else if (client && !client->data.public_key) {
723 client->data.public_key =
724 silc_pkcs_public_key_copy(channel->founder_key);
728 if (mode & SILC_CHANNEL_MODE_FOUNDER_AUTH && !channel->founder_key &&
729 server->server_type == SILC_ROUTER) {
730 SILC_LOG_DEBUG(("Enforcing sender to change channel mode"));
731 mode &= ~SILC_CHANNEL_MODE_FOUNDER_AUTH;
732 silc_server_send_notify_cmode(server, sock, FALSE, channel,
733 mode, server->id, SILC_ID_SERVER,
736 channel->passphrase, NULL);
739 /* Send the same notify to the channel */
740 silc_server_packet_send_to_channel(server, NULL, channel, packet->type,
741 FALSE, packet->buffer->data,
742 packet->buffer->len, FALSE);
745 channel->mode = mode;
747 if (!(channel->mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) &&
748 channel->founder_key) {
749 silc_pkcs_public_key_free(channel->founder_key);
750 channel->founder_key = NULL;
755 case SILC_NOTIFY_TYPE_CUMODE_CHANGE:
758 * Distribute the notify to local clients on the channel
760 SilcChannelClientEntry chl2 = NULL;
761 bool notify_sent = FALSE;
763 SILC_LOG_DEBUG(("CUMODE CHANGE notify"));
766 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
769 client_id = silc_id_payload_parse_id(tmp, tmp_len, &id_type);
773 /* Get client entry */
774 if (id_type == SILC_ID_CLIENT) {
775 client = silc_idlist_find_client_by_id(server->global_list,
776 client_id, TRUE, &cache);
778 client = silc_idlist_find_client_by_id(server->local_list,
779 client_id, TRUE, &cache);
781 silc_free(client_id);
785 silc_free(client_id);
789 channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len,
790 packet->dst_id_type);
795 /* Get channel entry */
796 channel = silc_idlist_find_channel_by_id(server->global_list,
799 channel = silc_idlist_find_channel_by_id(server->local_list,
802 SILC_LOG_DEBUG(("Notify for unknown channel"));
803 silc_free(channel_id);
809 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
811 silc_free(channel_id);
815 SILC_GET32_MSB(mode, tmp);
817 /* Get target client */
818 tmp = silc_argument_get_arg_type(args, 3, &tmp_len);
821 client_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
825 /* Get client entry */
826 client2 = silc_idlist_find_client_by_id(server->global_list,
827 client_id, TRUE, NULL);
829 client2 = silc_idlist_find_client_by_id(server->local_list,
830 client_id, TRUE, NULL);
832 silc_free(client_id);
836 silc_free(client_id);
839 /* Check that sender is on channel */
840 if (!silc_server_client_on_channel(client, channel, &chl))
843 if (client != client2 && server->server_type == SILC_ROUTER) {
844 /* Sender must be operator */
845 if (!(chl->mode & SILC_CHANNEL_UMODE_CHANOP) &&
846 !(chl->mode & SILC_CHANNEL_UMODE_CHANFO)) {
847 SILC_LOG_DEBUG(("CUMODE change is not allowed"));
851 if (!silc_server_client_on_channel(client2, channel, &chl))
854 /* If target is founder mode change is not allowed. */
855 if (chl->mode & SILC_CHANNEL_UMODE_CHANFO) {
856 SILC_LOG_DEBUG(("CUMODE change is not allowed"));
862 /* Get target channel user entry */
863 if (!silc_server_client_on_channel(client2, channel, &chl))
866 if (server->server_type == SILC_SERVER && chl->mode == mode) {
867 SILC_LOG_DEBUG(("Mode is changed already"));
871 if (mode & SILC_CHANNEL_UMODE_CHANFO &&
872 !(chl->mode & SILC_CHANNEL_UMODE_CHANFO) &&
873 server->server_type == SILC_ROUTER &&
874 sock != SILC_PRIMARY_ROUTE(server)) {
875 SilcPublicKey founder_key = NULL;
877 /* If channel doesn't have founder auth mode then it's impossible
878 that someone would be getting founder rights with CUMODE command.
879 In that case there already either is founder or there isn't
880 founder at all on the channel. */
881 if (client && !(channel->mode & SILC_CHANNEL_MODE_FOUNDER_AUTH)) {
882 /* Force the mode to not have founder mode */
883 chl->mode = mode &= ~SILC_CHANNEL_UMODE_CHANFO;
884 silc_server_force_cumode_change(server, sock, channel, chl, mode);
889 /* Get the founder of the channel and if found then this client
890 cannot be the founder since there already is one. */
891 silc_hash_table_list(channel->user_list, &htl);
892 while (silc_hash_table_get(&htl, NULL, (void *)&chl2))
893 if (chl2->mode & SILC_CHANNEL_UMODE_CHANFO) {
894 /* If the founder on the channel is not the one whom has set
895 the founder mode, then it's possible that this CUMODE_CHANGE
896 is correct. Due to netsplits it's possible that this
897 situation happens. */
898 if (!(channel->mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) ||
899 (channel->founder_key && chl2->client->data.public_key &&
900 silc_pkcs_public_key_compare(
901 channel->founder_key,
902 chl2->client->data.public_key))) {
903 chl->mode = mode &= ~SILC_CHANNEL_UMODE_CHANFO;
904 silc_server_force_cumode_change(server, sock, channel,
910 silc_hash_table_list_reset(&htl);
911 if (!(mode & SILC_CHANNEL_UMODE_CHANFO))
914 /* Founder not found of the channel. Since the founder auth mode
915 is set on the channel now check whether this is the client that
916 originally set the mode. */
918 /* Get public key that must be present in notify */
919 tmp = silc_argument_get_arg_type(args, 4, &tmp_len);
920 if (!tmp || !silc_pkcs_public_key_decode(tmp, tmp_len,
922 chl->mode = mode &= ~SILC_CHANNEL_UMODE_CHANFO;
923 silc_server_force_cumode_change(server, sock, channel, chl, mode);
928 if (channel->founder_key) {
929 /* Now match the public key we have cached and public key sent.
931 if (client && client->data.public_key &&
932 !silc_pkcs_public_key_compare(channel->founder_key,
933 client->data.public_key)) {
934 chl->mode = mode &= ~SILC_CHANNEL_UMODE_CHANFO;
935 silc_server_force_cumode_change(server, sock, channel, chl, mode);
939 if (!silc_pkcs_public_key_compare(channel->founder_key,
941 chl->mode = mode &= ~SILC_CHANNEL_UMODE_CHANFO;
942 silc_server_force_cumode_change(server, sock, channel, chl, mode);
948 /* There cannot be anyone else as founder on the channel now. This
949 client is definitely the founder due to this authentication */
950 silc_hash_table_list(channel->user_list, &htl);
951 while (silc_hash_table_get(&htl, NULL, (void *)&chl2))
952 if (chl2->mode & SILC_CHANNEL_UMODE_CHANFO) {
953 chl2->mode &= ~SILC_CHANNEL_UMODE_CHANFO;
954 silc_server_force_cumode_change(server, NULL, channel, chl2,
958 silc_hash_table_list_reset(&htl);
961 silc_pkcs_public_key_free(founder_key);
964 if (server->server_type != SILC_SERVER && chl->mode == mode) {
965 SILC_LOG_DEBUG(("Mode is changed already"));
969 SILC_LOG_DEBUG(("Changing %s channel user mode",
970 chl->client->nickname ? chl->client->nickname :
971 (unsigned char *)""));
973 /* Change the mode */
976 /* Send the same notify to the channel */
978 silc_server_packet_send_to_channel(server, NULL, channel,
980 FALSE, packet->buffer->data,
981 packet->buffer->len, FALSE);
983 silc_free(channel_id);
987 case SILC_NOTIFY_TYPE_INVITE:
989 if (packet->dst_id_type == SILC_ID_CLIENT)
992 SILC_LOG_DEBUG(("INVITE notify"));
995 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
998 channel_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
1002 /* Get channel entry */
1003 channel = silc_idlist_find_channel_by_id(server->global_list,
1006 channel = silc_idlist_find_channel_by_id(server->local_list,
1009 SILC_LOG_DEBUG(("Notify for unknown channel"));
1010 silc_free(channel_id);
1014 silc_free(channel_id);
1017 tmp = silc_argument_get_arg_type(args, 3, &tmp_len);
1020 client_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
1024 /* Get client entry */
1025 client = silc_idlist_find_client_by_id(server->global_list,
1026 client_id, TRUE, &cache);
1028 client = silc_idlist_find_client_by_id(server->local_list,
1029 client_id, TRUE, &cache);
1031 silc_free(client_id);
1035 silc_free(client_id);
1037 /* Get user's channel entry and check that inviting is allowed. */
1038 if (!silc_server_client_on_channel(client, channel, &chl))
1040 if (channel->mode & SILC_CHANNEL_MODE_INVITE &&
1041 !(chl->mode & SILC_CHANNEL_UMODE_CHANOP) &&
1042 !(chl->mode & SILC_CHANNEL_UMODE_CHANFO)) {
1043 SILC_LOG_DEBUG(("Inviting is not allowed"));
1047 /* Get the added invite */
1048 tmp = silc_argument_get_arg_type(args, 4, &tmp_len);
1050 if (!channel->invite_list)
1051 channel->invite_list = silc_calloc(tmp_len + 2,
1052 sizeof(*channel->invite_list));
1054 channel->invite_list = silc_realloc(channel->invite_list,
1055 sizeof(*channel->invite_list) *
1057 strlen(channel->invite_list) +
1059 if (tmp[tmp_len - 1] == ',')
1060 tmp[tmp_len - 1] = '\0';
1062 strncat(channel->invite_list, tmp, tmp_len);
1063 strncat(channel->invite_list, ",", 1);
1066 /* Get the deleted invite */
1067 tmp = silc_argument_get_arg_type(args, 5, &tmp_len);
1068 if (tmp && channel->invite_list) {
1069 char *start, *end, *n;
1071 if (!strncmp(channel->invite_list, tmp,
1072 strlen(channel->invite_list) - 1)) {
1073 silc_free(channel->invite_list);
1074 channel->invite_list = NULL;
1076 start = strstr(channel->invite_list, tmp);
1077 if (start && strlen(start) >= tmp_len) {
1078 end = start + tmp_len;
1079 n = silc_calloc(strlen(channel->invite_list) - tmp_len, sizeof(*n));
1080 strncat(n, channel->invite_list, start - channel->invite_list);
1081 strncat(n, end + 1, ((channel->invite_list +
1082 strlen(channel->invite_list)) - end) - 1);
1083 silc_free(channel->invite_list);
1084 channel->invite_list = n;
1091 case SILC_NOTIFY_TYPE_CHANNEL_CHANGE:
1093 * Distribute to the local clients on the channel and change the
1097 SILC_LOG_DEBUG(("CHANNEL CHANGE"));
1099 if (sock->type != SILC_SOCKET_TYPE_ROUTER)
1102 /* Get the old Channel ID */
1103 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
1106 channel_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
1110 /* Get the channel entry */
1111 channel = silc_idlist_find_channel_by_id(server->local_list,
1114 channel = silc_idlist_find_channel_by_id(server->global_list,
1117 SILC_LOG_DEBUG(("Notify for unknown channel"));
1118 silc_free(channel_id);
1123 /* Send the notify to the channel */
1124 silc_server_packet_send_to_channel(server, sock, channel, packet->type,
1125 FALSE, packet->buffer->data,
1126 packet->buffer->len, FALSE);
1128 /* Get the new Channel ID */
1129 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
1132 channel_id2 = silc_id_payload_parse_id(tmp, tmp_len, NULL);
1136 SILC_LOG_DEBUG(("Old Channel ID id(%s)",
1137 silc_id_render(channel_id, SILC_ID_CHANNEL)));
1138 SILC_LOG_DEBUG(("New Channel ID id(%s)",
1139 silc_id_render(channel_id2, SILC_ID_CHANNEL)));
1141 /* Replace the Channel ID */
1142 if (!silc_idlist_replace_channel_id(server->local_list, channel_id,
1144 if (!silc_idlist_replace_channel_id(server->global_list, channel_id,
1146 silc_free(channel_id2);
1151 SilcBuffer modes = NULL, users = NULL, users_modes = NULL;
1153 /* Re-announce this channel which ID was changed. */
1154 silc_server_send_new_channel(server, sock, FALSE, channel->channel_name,
1156 silc_id_get_len(channel->id,
1160 /* Re-announce our clients on the channel as the ID has changed now */
1161 silc_server_announce_get_channel_users(server, channel, &modes, &users,
1164 silc_buffer_push(users, users->data - users->head);
1165 silc_server_packet_send(server, sock,
1166 SILC_PACKET_NOTIFY, SILC_PACKET_FLAG_LIST,
1167 users->data, users->len, FALSE);
1168 silc_buffer_free(users);
1171 silc_buffer_push(modes, modes->data - modes->head);
1172 silc_server_packet_send_dest(server, sock,
1173 SILC_PACKET_NOTIFY, SILC_PACKET_FLAG_LIST,
1174 channel->id, SILC_ID_CHANNEL,
1175 modes->data, modes->len, FALSE);
1176 silc_buffer_free(modes);
1179 silc_buffer_push(users_modes, users_modes->data - users_modes->head);
1180 silc_server_packet_send_dest(server, sock,
1181 SILC_PACKET_NOTIFY, SILC_PACKET_FLAG_LIST,
1182 channel->id, SILC_ID_CHANNEL,
1184 users_modes->len, FALSE);
1185 silc_buffer_free(users_modes);
1188 /* Re-announce channel's topic */
1189 if (channel->topic) {
1190 silc_server_send_notify_topic_set(server, sock,
1191 server->server_type == SILC_ROUTER ?
1192 TRUE : FALSE, channel,
1193 server->id, SILC_ID_SERVER,
1198 silc_free(channel_id);
1202 case SILC_NOTIFY_TYPE_SERVER_SIGNOFF:
1204 * Remove the server entry and all clients that this server owns.
1207 SILC_LOG_DEBUG(("SERVER SIGNOFF notify"));
1210 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
1213 server_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
1217 /* Get server entry */
1218 server_entry = silc_idlist_find_server_by_id(server->global_list,
1219 server_id, TRUE, NULL);
1221 if (!server_entry) {
1222 server_entry = silc_idlist_find_server_by_id(server->local_list,
1223 server_id, TRUE, NULL);
1225 if (!server_entry) {
1226 /* If we are normal server then we might not have the server. Check
1227 whether router was kind enough to send the list of all clients
1228 that actually was to be removed. Remove them if the list is
1230 if (server->server_type != SILC_ROUTER &&
1231 silc_argument_get_arg_num(args) > 1) {
1234 for (i = 1; i < silc_argument_get_arg_num(args); i++) {
1236 tmp = silc_argument_get_arg_type(args, i + 1, &tmp_len);
1239 client_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
1243 /* Get client entry */
1244 client = silc_idlist_find_client_by_id(server->global_list,
1245 client_id, TRUE, &cache);
1248 client = silc_idlist_find_client_by_id(server->local_list,
1249 client_id, TRUE, &cache);
1252 silc_free(client_id);
1256 silc_free(client_id);
1258 /* Update statistics */
1259 server->stat.clients--;
1260 if (server->stat.cell_clients)
1261 server->stat.cell_clients--;
1262 SILC_OPER_STATS_UPDATE(client, server, SILC_UMODE_SERVER_OPERATOR);
1263 SILC_OPER_STATS_UPDATE(client, router, SILC_UMODE_ROUTER_OPERATOR);
1265 /* Remove the client from all channels. */
1266 silc_server_remove_from_channels(server, NULL, client,
1269 /* Check if anyone is watching this nickname */
1270 if (server->server_type == SILC_ROUTER)
1271 silc_server_check_watcher_list(server, client, NULL,
1272 SILC_NOTIFY_TYPE_SERVER_SIGNOFF);
1274 /* Remove this client from watcher list if it is */
1276 silc_server_del_from_watcher_list(server, client);
1278 /* Remove the client */
1279 silc_idlist_del_client(local ? server->local_list :
1280 server->global_list, client);
1284 silc_free(server_id);
1288 silc_free(server_id);
1290 /* Free all client entries that this server owns as they will
1291 become invalid now as well. */
1292 silc_server_remove_clients_by_server(server, server_entry, TRUE);
1294 /* Remove the server entry */
1295 silc_idlist_del_server(local ? server->local_list :
1296 server->global_list, server_entry);
1298 /* Update statistics */
1299 if (server->server_type == SILC_ROUTER)
1300 server->stat.servers--;
1304 case SILC_NOTIFY_TYPE_KICKED:
1306 * Distribute the notify to local clients on the channel
1309 SILC_LOG_DEBUG(("KICKED notify"));
1312 channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len,
1313 packet->dst_id_type);
1318 /* Get channel entry */
1319 channel = silc_idlist_find_channel_by_id(server->global_list,
1322 channel = silc_idlist_find_channel_by_id(server->local_list,
1325 SILC_LOG_DEBUG(("Notify for unknown channel"));
1326 silc_free(channel_id);
1330 silc_free(channel_id);
1333 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
1336 client_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
1340 /* If the the client is not in local list we check global list */
1341 client = silc_idlist_find_client_by_id(server->global_list,
1342 client_id, TRUE, NULL);
1344 client = silc_idlist_find_client_by_id(server->local_list,
1345 client_id, TRUE, NULL);
1347 silc_free(client_id);
1351 silc_free(client_id);
1353 /* If target is founder they cannot be kicked */
1354 if (!silc_server_client_on_channel(client, channel, &chl))
1356 if (chl->mode & SILC_CHANNEL_UMODE_CHANFO)
1359 /* From protocol version 1.1 we get the kicker's ID as well. */
1360 tmp = silc_argument_get_arg_type(args, 3, &tmp_len);
1362 client_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
1366 /* If the the client is not in local list we check global list */
1367 client2 = silc_idlist_find_client_by_id(server->global_list,
1368 client_id, TRUE, NULL);
1370 client2 = silc_idlist_find_client_by_id(server->local_list,
1371 client_id, TRUE, NULL);
1373 silc_free(client_id);
1377 silc_free(client_id);
1379 /* Kicker must be operator on channel */
1380 if (!silc_server_client_on_channel(client2, channel, &chl))
1382 if (!(chl->mode & SILC_CHANNEL_UMODE_CHANOP) &&
1383 !(chl->mode & SILC_CHANNEL_UMODE_CHANFO)) {
1384 SILC_LOG_DEBUG(("Kicking is not allowed"));
1389 /* Send to channel */
1390 silc_server_packet_send_to_channel(server, sock, channel, packet->type,
1391 FALSE, packet->buffer->data,
1392 packet->buffer->len, FALSE);
1394 /* Remove the client from channel */
1395 silc_server_remove_from_one_channel(server, sock, channel, client, FALSE);
1399 case SILC_NOTIFY_TYPE_KILLED:
1402 * Distribute the notify to local clients on channels
1404 unsigned char *id, *comment;
1405 SilcUInt32 id_len, comment_len;
1407 SILC_LOG_DEBUG(("KILLED notify"));
1410 id = silc_argument_get_arg_type(args, 1, &id_len);
1413 client_id = silc_id_payload_parse_id(id, id_len, NULL);
1417 /* If the the client is not in local list we check global list */
1418 client = silc_idlist_find_client_by_id(server->global_list,
1419 client_id, TRUE, &cache);
1421 client = silc_idlist_find_client_by_id(server->local_list,
1422 client_id, TRUE, &cache);
1424 silc_free(client_id);
1428 silc_free(client_id);
1430 /* If the client is one of ours, then close the connection to the
1431 client now. This removes the client from all channels as well. */
1432 if (packet->dst_id_type == SILC_ID_CLIENT && client->connection) {
1433 sock = client->connection;
1434 silc_server_free_client_data(server, NULL, client, FALSE, NULL);
1435 silc_server_close_connection(server, sock);
1440 comment = silc_argument_get_arg_type(args, 2, &comment_len);
1441 if (comment_len > 128)
1444 /* From protocol version 1.1 we get the killer's ID as well. */
1445 tmp = silc_argument_get_arg_type(args, 3, &tmp_len);
1447 client_id = silc_id_payload_parse_id(tmp, tmp_len, &id_type);
1451 if (id_type == SILC_ID_CLIENT) {
1452 /* If the the client is not in local list we check global list */
1453 client2 = silc_idlist_find_client_by_id(server->global_list,
1454 client_id, TRUE, NULL);
1456 client2 = silc_idlist_find_client_by_id(server->local_list,
1457 client_id, TRUE, NULL);
1459 silc_free(client_id);
1463 silc_free(client_id);
1465 /* Killer must be router operator */
1466 if (server->server_type != SILC_SERVER &&
1467 !(client2->mode & SILC_UMODE_ROUTER_OPERATOR)) {
1468 SILC_LOG_DEBUG(("Killing is not allowed"));
1474 /* Send the notify to local clients on the channels except to the
1475 client who is killed. */
1476 silc_server_send_notify_on_channels(server, client, client,
1477 SILC_NOTIFY_TYPE_KILLED, 3,
1478 id, id_len, comment, comment_len,
1481 /* Remove the client from all channels */
1482 silc_server_remove_from_channels(server, NULL, client, FALSE, NULL,
1485 /* Check if anyone is watching this nickname */
1486 silc_server_check_watcher_list(server, client, NULL,
1487 SILC_NOTIFY_TYPE_KILLED);
1489 /* Update statistics */
1490 server->stat.clients--;
1491 if (server->stat.cell_clients)
1492 server->stat.cell_clients--;
1493 SILC_OPER_STATS_UPDATE(client, server, SILC_UMODE_SERVER_OPERATOR);
1494 SILC_OPER_STATS_UPDATE(client, router, SILC_UMODE_ROUTER_OPERATOR);
1496 if (SILC_IS_LOCAL(client)) {
1497 server->stat.my_clients--;
1498 silc_schedule_task_del_by_context(server->schedule, client);
1499 silc_idlist_del_data(client);
1503 client->data.status &= ~SILC_IDLIST_STATUS_REGISTERED;
1504 cache->expire = SILC_ID_CACHE_EXPIRE_DEF;
1508 case SILC_NOTIFY_TYPE_UMODE_CHANGE:
1510 * Save the mode of the client.
1513 SILC_LOG_DEBUG(("UMODE_CHANGE notify"));
1516 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
1519 client_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
1523 /* Get client entry */
1524 client = silc_idlist_find_client_by_id(server->global_list,
1525 client_id, TRUE, NULL);
1527 client = silc_idlist_find_client_by_id(server->local_list,
1528 client_id, TRUE, NULL);
1530 silc_free(client_id);
1534 silc_free(client_id);
1537 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
1540 SILC_GET32_MSB(mode, tmp);
1542 /* Check that mode changing is allowed. */
1543 if (!silc_server_check_umode_rights(server, client, mode)) {
1544 SILC_LOG_DEBUG(("UMODE change is not allowed"));
1548 /* Remove internal resumed flag if client is marked detached now */
1549 if (mode & SILC_UMODE_DETACHED)
1550 client->data.status &= ~SILC_IDLIST_STATUS_RESUMED;
1552 /* Update statistics */
1553 if (server->server_type == SILC_ROUTER) {
1554 if (mode & SILC_UMODE_GONE) {
1555 if (!(client->mode & SILC_UMODE_GONE))
1556 server->stat.aways++;
1558 if (client->mode & SILC_UMODE_GONE)
1559 server->stat.aways--;
1561 if (mode & SILC_UMODE_DETACHED) {
1562 if (!(client->mode & SILC_UMODE_DETACHED))
1563 server->stat.detached++;
1565 if (client->mode & SILC_UMODE_DETACHED)
1566 server->stat.detached--;
1570 /* Change the mode */
1571 client->mode = mode;
1573 /* Check if anyone is watching this nickname */
1574 if (server->server_type == SILC_ROUTER)
1575 silc_server_check_watcher_list(server, client, NULL,
1576 SILC_NOTIFY_TYPE_UMODE_CHANGE);
1580 case SILC_NOTIFY_TYPE_BAN:
1585 SILC_LOG_DEBUG(("BAN notify"));
1587 /* Get Channel ID */
1588 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
1591 channel_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
1595 /* Get channel entry */
1596 channel = silc_idlist_find_channel_by_id(server->global_list,
1599 channel = silc_idlist_find_channel_by_id(server->local_list,
1602 SILC_LOG_DEBUG(("Notify for unknown channel"));
1603 silc_free(channel_id);
1607 silc_free(channel_id);
1609 /* Get the new ban and add it to the ban list */
1610 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
1612 if (!channel->ban_list)
1613 channel->ban_list = silc_calloc(tmp_len + 2,
1614 sizeof(*channel->ban_list));
1616 channel->ban_list = silc_realloc(channel->ban_list,
1617 sizeof(*channel->ban_list) *
1619 strlen(channel->ban_list) + 2));
1620 strncat(channel->ban_list, tmp, tmp_len);
1621 strncat(channel->ban_list, ",", 1);
1624 /* Get the ban to be removed and remove it from the list */
1625 tmp = silc_argument_get_arg_type(args, 3, &tmp_len);
1626 if (tmp && channel->ban_list) {
1627 char *start, *end, *n;
1629 if (!strncmp(channel->ban_list, tmp, strlen(channel->ban_list) - 1)) {
1630 silc_free(channel->ban_list);
1631 channel->ban_list = NULL;
1633 start = strstr(channel->ban_list, tmp);
1634 if (start && strlen(start) >= tmp_len) {
1635 end = start + tmp_len;
1636 n = silc_calloc(strlen(channel->ban_list) - tmp_len, sizeof(*n));
1637 strncat(n, channel->ban_list, start - channel->ban_list);
1638 strncat(n, end + 1, ((channel->ban_list +
1639 strlen(channel->ban_list)) - end) - 1);
1640 silc_free(channel->ban_list);
1641 channel->ban_list = n;
1647 case SILC_NOTIFY_TYPE_ERROR:
1654 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
1655 if (!tmp && tmp_len != 1)
1657 error = (SilcStatus)tmp[0];
1659 SILC_LOG_DEBUG(("ERROR notify (%d)", error));
1661 if (error == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID &&
1662 sock->type == SILC_SOCKET_TYPE_ROUTER) {
1663 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
1665 SILC_LOG_DEBUG(("Received invalid client ID notification, deleting "
1666 "the entry from cache"));
1667 client_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
1670 client = silc_idlist_find_client_by_id(server->global_list,
1671 client_id, FALSE, NULL);
1673 silc_server_remove_from_channels(server, NULL, client, TRUE,
1675 silc_idlist_del_client(server->global_list, client);
1677 silc_free(client_id);
1683 /* Ignore rest of the notify types for now */
1684 case SILC_NOTIFY_TYPE_NONE:
1685 case SILC_NOTIFY_TYPE_MOTD:
1692 silc_notify_payload_free(payload);
1695 void silc_server_notify_list(SilcServer server,
1696 SilcSocketConnection sock,
1697 SilcPacketContext *packet)
1699 SilcPacketContext *new;
1703 SILC_LOG_DEBUG(("Processing Notify List"));
1705 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
1706 packet->src_id_type != SILC_ID_SERVER)
1709 /* Make copy of the original packet context, except for the actual
1710 data buffer, which we will here now fetch from the original buffer. */
1711 new = silc_packet_context_alloc();
1712 new->type = SILC_PACKET_NOTIFY;
1713 new->flags = packet->flags;
1714 new->src_id = packet->src_id;
1715 new->src_id_len = packet->src_id_len;
1716 new->src_id_type = packet->src_id_type;
1717 new->dst_id = packet->dst_id;
1718 new->dst_id_len = packet->dst_id_len;
1719 new->dst_id_type = packet->dst_id_type;
1721 buffer = silc_buffer_alloc(1024);
1722 new->buffer = buffer;
1724 while (packet->buffer->len) {
1725 SILC_GET16_MSB(len, packet->buffer->data + 2);
1726 if (len > packet->buffer->len)
1729 if (len > buffer->truelen) {
1730 silc_buffer_free(buffer);
1731 buffer = silc_buffer_alloc(1024 + len);
1734 silc_buffer_pull_tail(buffer, len);
1735 silc_buffer_put(buffer, packet->buffer->data, len);
1737 /* Process the Notify */
1738 silc_server_notify(server, sock, new);
1740 silc_buffer_push_tail(buffer, len);
1741 silc_buffer_pull(packet->buffer, len);
1744 silc_buffer_free(buffer);
1748 /* Received private message. This resolves the destination of the message
1749 and sends the packet. This is used by both server and router. If the
1750 destination is our locally connected client this sends the packet to
1751 the client. This may also send the message for further routing if
1752 the destination is not in our server (or router). */
1754 void silc_server_private_message(SilcServer server,
1755 SilcSocketConnection sock,
1756 SilcPacketContext *packet)
1758 SilcSocketConnection dst_sock;
1759 SilcIDListData idata;
1760 SilcClientEntry client;
1762 SILC_LOG_DEBUG(("Start"));
1764 if (packet->src_id_type != SILC_ID_CLIENT ||
1765 packet->dst_id_type != SILC_ID_CLIENT || !packet->dst_id)
1768 /* Get the route to the client */
1769 dst_sock = silc_server_get_client_route(server, packet->dst_id,
1770 packet->dst_id_len, NULL,
1774 unsigned char error;
1776 if (client && client->mode & SILC_UMODE_DETACHED) {
1777 SILC_LOG_DEBUG(("Client is detached, discarding packet"));
1781 /* Send SILC_NOTIFY_TYPE_ERROR to indicate that such destination ID
1782 does not exist or is invalid. */
1783 idp = silc_id_payload_encode_data(packet->dst_id,
1785 packet->dst_id_type);
1789 error = SILC_STATUS_ERR_NO_SUCH_CLIENT_ID;
1790 if (packet->src_id_type == SILC_ID_CLIENT) {
1791 SilcClientID *client_id = silc_id_str2id(packet->src_id,
1793 packet->src_id_type);
1794 silc_server_send_notify_dest(server, sock, FALSE,
1795 client_id, SILC_ID_CLIENT,
1796 SILC_NOTIFY_TYPE_ERROR, 2,
1798 idp->data, idp->len);
1799 silc_free(client_id);
1801 silc_server_send_notify(server, sock, FALSE,
1802 SILC_NOTIFY_TYPE_ERROR, 2,
1804 idp->data, idp->len);
1807 silc_buffer_free(idp);
1811 /* Check whether destination client wishes to receive private messages */
1812 if (client && !(packet->flags & SILC_PACKET_FLAG_PRIVMSG_KEY) &&
1813 client->mode & SILC_UMODE_BLOCK_PRIVMSG) {
1814 SILC_LOG_DEBUG(("Client blocks private messages, discarding packet"));
1818 /* Send the private message */
1819 silc_server_send_private_message(server, dst_sock, idata->send_key,
1820 idata->hmac_send, idata->psn_send++,
1824 /* Received private message key packet.. This packet is never for us. It is to
1825 the client in the packet's destination ID. Sending of this sort of packet
1826 equals sending private message, ie. it is sent point to point from
1827 one client to another. */
1829 void silc_server_private_message_key(SilcServer server,
1830 SilcSocketConnection sock,
1831 SilcPacketContext *packet)
1833 SilcSocketConnection dst_sock;
1834 SilcIDListData idata;
1836 SILC_LOG_DEBUG(("Start"));
1838 if (packet->src_id_type != SILC_ID_CLIENT ||
1839 packet->dst_id_type != SILC_ID_CLIENT)
1842 if (!packet->dst_id)
1845 /* Get the route to the client */
1846 dst_sock = silc_server_get_client_route(server, packet->dst_id,
1847 packet->dst_id_len, NULL,
1852 /* Relay the packet */
1853 silc_server_relay_packet(server, dst_sock, idata->send_key,
1854 idata->hmac_send, idata->psn_send++, packet, FALSE);
1857 /* Processes incoming command reply packet. The command reply packet may
1858 be destined to one of our clients or it may directly for us. We will
1859 call the command reply routine after processing the packet. */
1861 void silc_server_command_reply(SilcServer server,
1862 SilcSocketConnection sock,
1863 SilcPacketContext *packet)
1865 SilcBuffer buffer = packet->buffer;
1866 SilcClientEntry client = NULL;
1867 SilcSocketConnection dst_sock;
1868 SilcIDListData idata;
1869 SilcClientID *id = NULL;
1871 SILC_LOG_DEBUG(("Start"));
1873 /* Source must be server or router */
1874 if (packet->src_id_type != SILC_ID_SERVER &&
1875 sock->type != SILC_SOCKET_TYPE_ROUTER)
1878 if (packet->dst_id_type == SILC_ID_CHANNEL)
1881 if (packet->dst_id_type == SILC_ID_CLIENT) {
1882 /* Destination must be one of ours */
1883 id = silc_id_str2id(packet->dst_id, packet->dst_id_len, SILC_ID_CLIENT);
1886 client = silc_idlist_find_client_by_id(server->local_list, id, TRUE, NULL);
1888 SILC_LOG_ERROR(("Cannot process command reply to unknown client"));
1894 if (packet->dst_id_type == SILC_ID_SERVER) {
1895 /* For now this must be for us */
1896 if (memcmp(packet->dst_id, server->id_string, server->id_string_len)) {
1897 SILC_LOG_ERROR(("Cannot process command reply to unknown server"));
1902 /* Execute command reply locally for the command */
1903 silc_server_command_reply_process(server, sock, buffer);
1905 if (packet->dst_id_type == SILC_ID_CLIENT && client && id) {
1906 /* Relay the packet to the client */
1907 const SilcBufferStruct p;
1909 dst_sock = (SilcSocketConnection)client->connection;
1910 idata = (SilcIDListData)client;
1912 silc_buffer_push(buffer, SILC_PACKET_HEADER_LEN + packet->src_id_len
1913 + packet->dst_id_len + packet->padlen);
1914 if (!silc_packet_send_prepare(dst_sock, 0, 0, buffer->len,
1915 idata->hmac_send, (const SilcBuffer)&p)) {
1916 SILC_LOG_ERROR(("Cannot send packet"));
1919 silc_buffer_put((SilcBuffer)&p, buffer->data, buffer->len);
1921 /* Encrypt packet */
1922 silc_packet_encrypt(idata->send_key, idata->hmac_send, idata->psn_send++,
1923 (SilcBuffer)&p, buffer->len);
1925 /* Send the packet */
1926 silc_server_packet_send_real(server, dst_sock, TRUE);
1932 /* Process received channel message. The message can be originated from
1933 client or server. */
1935 void silc_server_channel_message(SilcServer server,
1936 SilcSocketConnection sock,
1937 SilcPacketContext *packet)
1939 SilcChannelEntry channel = NULL;
1940 SilcChannelID *id = NULL;
1941 void *sender_id = NULL;
1942 SilcClientEntry sender_entry = NULL;
1943 SilcChannelClientEntry chl;
1946 SILC_LOG_DEBUG(("Processing channel message"));
1949 if (packet->dst_id_type != SILC_ID_CHANNEL) {
1950 SILC_LOG_DEBUG(("Received bad message for channel, dropped"));
1954 /* Find channel entry */
1955 id = silc_id_str2id(packet->dst_id, packet->dst_id_len, SILC_ID_CHANNEL);
1958 channel = silc_idlist_find_channel_by_id(server->local_list, id, NULL);
1960 channel = silc_idlist_find_channel_by_id(server->global_list, id, NULL);
1963 unsigned char error;
1965 /* Send SILC_NOTIFY_TYPE_ERROR to indicate that such destination ID
1966 does not exist or is invalid. */
1967 idp = silc_id_payload_encode_data(packet->dst_id,
1969 packet->dst_id_type);
1973 error = SILC_STATUS_ERR_NO_SUCH_CHANNEL_ID;
1974 if (packet->src_id_type == SILC_ID_CLIENT) {
1975 SilcClientID *client_id = silc_id_str2id(packet->src_id,
1977 packet->src_id_type);
1978 silc_server_send_notify_dest(server, sock, FALSE,
1979 client_id, SILC_ID_CLIENT,
1980 SILC_NOTIFY_TYPE_ERROR, 2,
1981 &error, 1, idp->data, idp->len);
1982 silc_free(client_id);
1984 silc_server_send_notify(server, sock, FALSE,
1985 SILC_NOTIFY_TYPE_ERROR, 2,
1986 &error, 1, idp->data, idp->len);
1989 silc_buffer_free(idp);
1994 /* See that this client is on the channel. If the original sender is
1995 not client (as it can be server as well) we don't do the check. */
1996 sender_id = silc_id_str2id(packet->src_id, packet->src_id_len,
1997 packet->src_id_type);
2000 if (packet->src_id_type == SILC_ID_CLIENT) {
2001 sender_entry = silc_idlist_find_client_by_id(server->local_list,
2002 sender_id, TRUE, NULL);
2003 if (!sender_entry) {
2005 sender_entry = silc_idlist_find_client_by_id(server->global_list,
2006 sender_id, TRUE, NULL);
2008 if (!sender_entry || !silc_server_client_on_channel(sender_entry,
2010 SILC_LOG_DEBUG(("Client not on channel"));
2014 /* If channel is moderated check that client is allowed to send
2016 if (channel->mode & SILC_CHANNEL_MODE_SILENCE_USERS &&
2017 !(chl->mode & SILC_CHANNEL_UMODE_CHANOP) &&
2018 !(chl->mode & SILC_CHANNEL_UMODE_CHANFO)) {
2019 SILC_LOG_DEBUG(("Channel is silenced from normal users"));
2022 if (channel->mode & SILC_CHANNEL_MODE_SILENCE_OPERS &&
2023 chl->mode & SILC_CHANNEL_UMODE_CHANOP &&
2024 !(chl->mode & SILC_CHANNEL_UMODE_CHANFO)) {
2025 SILC_LOG_DEBUG(("Channel is silenced from operators"));
2028 if (chl->mode & SILC_CHANNEL_UMODE_QUIET) {
2029 SILC_LOG_DEBUG(("Sender is quieted on the channel"));
2033 /* If the packet is coming from router, but the client entry is local
2034 entry to us then some router is rerouting this to us and it is not
2035 allowed. When the client is local to us it means that we've routed
2036 this packet to network, and now someone is routing it back to us. */
2037 if (server->server_type == SILC_ROUTER &&
2038 sock->type == SILC_SOCKET_TYPE_ROUTER && local) {
2039 SILC_LOG_DEBUG(("Channel message rerouted to the sender, drop it"));
2044 /* Distribute the packet to our local clients. This will send the
2045 packet for further routing as well, if needed. */
2046 silc_server_packet_relay_to_channel(server, sock, channel, sender_id,
2047 packet->src_id_type, sender_entry,
2048 packet->buffer->data,
2049 packet->buffer->len, FALSE);
2052 silc_free(sender_id);
2056 /* Received channel key packet. We distribute the key to all of our locally
2057 connected clients on the channel. */
2059 void silc_server_channel_key(SilcServer server,
2060 SilcSocketConnection sock,
2061 SilcPacketContext *packet)
2063 SilcBuffer buffer = packet->buffer;
2064 SilcChannelEntry channel;
2066 if (packet->src_id_type != SILC_ID_SERVER ||
2067 (server->server_type == SILC_ROUTER &&
2068 sock->type == SILC_SOCKET_TYPE_ROUTER))
2071 /* Save the channel key */
2072 channel = silc_server_save_channel_key(server, buffer, NULL);
2076 /* Distribute the key to everybody who is on the channel. If we are router
2077 we will also send it to locally connected servers. */
2078 silc_server_send_channel_key(server, sock, channel, FALSE);
2080 if (server->server_type != SILC_BACKUP_ROUTER) {
2081 /* Distribute to local cell backup routers. */
2082 silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
2083 SILC_PACKET_CHANNEL_KEY, 0,
2084 buffer->data, buffer->len, FALSE, TRUE);
2088 /* Received New Client packet and processes it. Creates Client ID for the
2089 client. Client becomes registered after calling this functions. */
2091 SilcClientEntry silc_server_new_client(SilcServer server,
2092 SilcSocketConnection sock,
2093 SilcPacketContext *packet)
2095 SilcBuffer buffer = packet->buffer;
2096 SilcClientEntry client;
2097 SilcClientID *client_id;
2098 SilcIDListData idata;
2099 char *username = NULL, *realname = NULL;
2100 SilcUInt16 username_len;
2103 char *hostname, *nickname;
2106 SILC_LOG_DEBUG(("Creating new client"));
2108 if (sock->type != SILC_SOCKET_TYPE_CLIENT)
2111 /* Take client entry */
2112 client = (SilcClientEntry)sock->user_data;
2113 idata = (SilcIDListData)client;
2115 /* Remove the old cache entry. */
2116 if (!silc_idcache_del_by_context(server->local_list->clients, client)) {
2117 SILC_LOG_INFO(("Unauthenticated client attempted to register to network"));
2118 silc_server_disconnect_remote(server, sock,
2119 SILC_STATUS_ERR_NOT_AUTHENTICATED, NULL);
2120 if (sock->user_data)
2121 silc_server_free_sock_user_data(server, sock, NULL);
2125 /* Parse incoming packet */
2126 ret = silc_buffer_unformat(buffer,
2127 SILC_STR_UI16_NSTRING_ALLOC(&username,
2129 SILC_STR_UI16_STRING_ALLOC(&realname),
2132 silc_free(username);
2133 silc_free(realname);
2134 SILC_LOG_ERROR(("Client %s (%s) sent incomplete information, closing "
2135 "connection", sock->hostname, sock->ip));
2136 silc_server_disconnect_remote(server, sock,
2137 SILC_STATUS_ERR_INCOMPLETE_INFORMATION,
2139 if (sock->user_data)
2140 silc_server_free_sock_user_data(server, sock, NULL);
2145 silc_free(username);
2146 silc_free(realname);
2147 SILC_LOG_ERROR(("Client %s (%s) did not send its username, closing "
2148 "connection", sock->hostname, sock->ip));
2149 silc_server_disconnect_remote(server, sock,
2150 SILC_STATUS_ERR_INCOMPLETE_INFORMATION,
2152 if (sock->user_data)
2153 silc_server_free_sock_user_data(server, sock, NULL);
2157 if (username_len > 128)
2158 username[128] = '\0';
2160 /* Check for bad characters for nickname, and modify the nickname if
2161 it includes those. */
2162 if (silc_server_name_bad_chars(username, username_len)) {
2163 nickname = silc_server_name_modify_bad(username, username_len);
2165 nickname = strdup(username);
2168 /* Make sanity checks for the hostname of the client. If the hostname
2169 is provided in the `username' check that it is the same than the
2170 resolved hostname, or if not resolved the hostname that appears in
2171 the client's public key. If the hostname is not present then put
2172 it from the resolved name or from the public key. */
2173 if (strchr(username, '@')) {
2174 SilcPublicKeyIdentifier pident;
2175 int tlen = strcspn(username, "@");
2176 char *phostname = NULL;
2178 hostname = silc_memdup(username + tlen + 1, strlen(username) - tlen - 1);
2180 if (strcmp(sock->hostname, sock->ip) &&
2181 strcmp(sock->hostname, hostname)) {
2182 silc_free(username);
2183 silc_free(hostname);
2184 silc_free(realname);
2185 SILC_LOG_ERROR(("Client %s (%s) sent incomplete information, closing "
2186 "connection", sock->hostname, sock->ip));
2187 silc_server_disconnect_remote(server, sock,
2188 SILC_STATUS_ERR_INCOMPLETE_INFORMATION,
2190 if (sock->user_data)
2191 silc_server_free_sock_user_data(server, sock, NULL);
2195 pident = silc_pkcs_decode_identifier(client->data.public_key->identifier);
2197 phostname = strdup(pident->host);
2198 silc_pkcs_free_identifier(pident);
2201 if (!strcmp(sock->hostname, sock->ip) &&
2202 phostname && strcmp(phostname, hostname)) {
2203 silc_free(username);
2204 silc_free(hostname);
2205 silc_free(phostname);
2206 silc_free(realname);
2207 SILC_LOG_ERROR(("Client %s (%s) sent incomplete information, closing "
2208 "connection", sock->hostname, sock->ip));
2209 silc_server_disconnect_remote(server, sock,
2210 SILC_STATUS_ERR_INCOMPLETE_INFORMATION,
2212 if (sock->user_data)
2213 silc_server_free_sock_user_data(server, sock, NULL);
2217 silc_free(phostname);
2219 /* The hostname is not present, add it. */
2221 /* XXX For now we cannot take the host name from the public key since
2222 they are not trusted or we cannot verify them as trusted. Just take
2223 what the resolved name or address is. */
2225 if (strcmp(sock->hostname, sock->ip)) {
2227 newusername = silc_calloc(strlen(username) +
2228 strlen(sock->hostname) + 2,
2229 sizeof(*newusername));
2230 strncat(newusername, username, strlen(username));
2231 strncat(newusername, "@", 1);
2232 strncat(newusername, sock->hostname, strlen(sock->hostname));
2233 silc_free(username);
2234 username = newusername;
2237 SilcPublicKeyIdentifier pident =
2238 silc_pkcs_decode_identifier(client->data.public_key->identifier);
2241 newusername = silc_calloc(strlen(username) +
2242 strlen(pident->host) + 2,
2243 sizeof(*newusername));
2244 strncat(newusername, username, strlen(username));
2245 strncat(newusername, "@", 1);
2246 strncat(newusername, pident->host, strlen(pident->host));
2247 silc_free(username);
2248 username = newusername;
2249 silc_pkcs_free_identifier(pident);
2255 /* Create Client ID */
2256 while (!silc_id_create_client_id(server, server->id, server->rng,
2257 server->md5hash, nickname, &client_id)) {
2260 silc_server_disconnect_remote(server, sock,
2261 SILC_STATUS_ERR_BAD_NICKNAME, NULL);
2262 if (sock->user_data)
2263 silc_server_free_sock_user_data(server, sock, NULL);
2266 snprintf(&nickname[strlen(nickname) - 1], 1, "%d", nickfail);
2269 /* Update client entry */
2270 idata->status |= SILC_IDLIST_STATUS_REGISTERED;
2271 client->nickname = nickname;
2272 client->username = username;
2273 client->userinfo = realname ? realname : strdup(" ");
2274 client->id = client_id;
2275 id_len = silc_id_get_len(client_id, SILC_ID_CLIENT);
2277 /* Add the client again to the ID cache */
2278 silc_idcache_add(server->local_list->clients, client->nickname,
2279 client_id, client, 0, NULL);
2281 /* Notify our router about new client on the SILC network */
2282 silc_server_send_new_id(server, SILC_PRIMARY_ROUTE(server),
2283 SILC_BROADCAST(server), client->id,
2284 SILC_ID_CLIENT, id_len);
2286 /* Distribute to backup routers */
2287 if (server->server_type == SILC_ROUTER) {
2288 SilcBuffer idp = silc_id_payload_encode(client->id, SILC_ID_CLIENT);
2289 silc_server_backup_send(server, NULL, SILC_PACKET_NEW_ID, 0,
2290 idp->data, idp->len, FALSE, TRUE);
2291 silc_buffer_free(idp);
2294 /* Send the new client ID to the client. */
2295 silc_server_send_new_id(server, sock, FALSE, client->id, SILC_ID_CLIENT,
2296 silc_id_get_len(client->id, SILC_ID_CLIENT));
2298 /* Send some nice info to the client */
2299 silc_server_send_connect_notifys(server, sock, client);
2301 /* Check if anyone is watching this nickname */
2302 if (server->server_type == SILC_ROUTER)
2303 silc_server_check_watcher_list(server, client, NULL, 0);
2308 /* Create new server. This processes received New Server packet and
2309 saves the received Server ID. The server is our locally connected
2310 server thus we save all the information and save it to local list.
2311 This funtion can be used by both normal server and router server.
2312 If normal server uses this it means that its router has connected
2313 to the server. If router uses this it means that one of the cell's
2314 servers is connected to the router. */
2316 SilcServerEntry silc_server_new_server(SilcServer server,
2317 SilcSocketConnection sock,
2318 SilcPacketContext *packet)
2320 SilcBuffer buffer = packet->buffer;
2321 SilcServerEntry new_server, server_entry;
2322 SilcServerID *server_id;
2323 SilcIDListData idata;
2324 unsigned char *server_name, *id_string;
2325 SilcUInt16 id_len, name_len;
2329 SILC_LOG_DEBUG(("Creating new server"));
2331 if (sock->type != SILC_SOCKET_TYPE_SERVER &&
2332 sock->type != SILC_SOCKET_TYPE_ROUTER)
2335 /* Take server entry */
2336 new_server = (SilcServerEntry)sock->user_data;
2337 idata = (SilcIDListData)new_server;
2339 /* Remove the old cache entry */
2340 if (!silc_idcache_del_by_context(server->local_list->servers, new_server)) {
2341 if (!silc_idcache_del_by_context(server->global_list->servers,
2343 SILC_LOG_INFO(("Unauthenticated %s attempted to register to "
2344 "network", (sock->type == SILC_SOCKET_TYPE_SERVER ?
2345 "server" : "router")));
2346 silc_server_disconnect_remote(server, sock,
2347 SILC_STATUS_ERR_NOT_AUTHENTICATED, NULL);
2348 if (sock->user_data)
2349 silc_server_free_sock_user_data(server, sock, NULL);
2355 /* Parse the incoming packet */
2356 ret = silc_buffer_unformat(buffer,
2357 SILC_STR_UI16_NSTRING_ALLOC(&id_string, &id_len),
2358 SILC_STR_UI16_NSTRING_ALLOC(&server_name,
2362 silc_free(id_string);
2363 silc_free(server_name);
2364 silc_server_disconnect_remote(server, sock,
2365 SILC_STATUS_ERR_INCOMPLETE_INFORMATION,
2367 if (sock->user_data)
2368 silc_server_free_sock_user_data(server, sock, NULL);
2372 if (id_len > buffer->len) {
2373 silc_free(id_string);
2374 silc_free(server_name);
2375 silc_server_disconnect_remote(server, sock,
2376 SILC_STATUS_ERR_INCOMPLETE_INFORMATION,
2378 if (sock->user_data)
2379 silc_server_free_sock_user_data(server, sock, NULL);
2384 server_name[255] = '\0';
2387 server_id = silc_id_str2id(id_string, id_len, SILC_ID_SERVER);
2389 silc_free(id_string);
2390 silc_free(server_name);
2391 silc_server_disconnect_remote(server, sock,
2392 SILC_STATUS_ERR_INCOMPLETE_INFORMATION,
2394 if (sock->user_data)
2395 silc_server_free_sock_user_data(server, sock, NULL);
2398 silc_free(id_string);
2400 /* Check for valid server ID */
2401 if (!silc_id_is_valid_server_id(server, server_id, sock)) {
2402 SILC_LOG_INFO(("Invalid server ID sent by %s (%s)",
2403 sock->ip, sock->hostname));
2404 silc_server_disconnect_remote(server, sock,
2405 SILC_STATUS_ERR_BAD_SERVER_ID, NULL);
2406 if (sock->user_data)
2407 silc_server_free_sock_user_data(server, sock, NULL);
2408 silc_free(server_name);
2412 /* Check that we do not have this ID already */
2413 server_entry = silc_idlist_find_server_by_id(server->local_list,
2414 server_id, TRUE, NULL);
2416 silc_idcache_del_by_context(server->local_list->servers, server_entry);
2418 server_entry = silc_idlist_find_server_by_id(server->global_list,
2419 server_id, TRUE, NULL);
2421 silc_idcache_del_by_context(server->global_list->servers, server_entry);
2424 /* Update server entry */
2425 idata->status |= SILC_IDLIST_STATUS_REGISTERED;
2426 new_server->server_name = server_name;
2427 new_server->id = server_id;
2429 SILC_LOG_DEBUG(("New server id(%s)",
2430 silc_id_render(server_id, SILC_ID_SERVER)));
2432 /* Add again the entry to the ID cache. */
2433 silc_idcache_add(local ? server->local_list->servers :
2434 server->global_list->servers, server_name, server_id,
2435 new_server, 0, NULL);
2437 /* Distribute the information about new server in the SILC network
2438 to our router. If we are normal server we won't send anything
2439 since this connection must be our router connection. */
2440 if (server->server_type == SILC_ROUTER && !server->standalone &&
2441 SILC_PRIMARY_ROUTE(server) != sock)
2442 silc_server_send_new_id(server, SILC_PRIMARY_ROUTE(server),
2443 TRUE, new_server->id, SILC_ID_SERVER,
2444 silc_id_get_len(server_id, SILC_ID_SERVER));
2446 if (server->server_type == SILC_ROUTER) {
2447 /* Distribute to backup routers */
2448 SilcBuffer idp = silc_id_payload_encode(new_server->id, SILC_ID_SERVER);
2449 silc_server_backup_send(server, NULL, SILC_PACKET_NEW_ID, 0,
2450 idp->data, idp->len, FALSE, TRUE);
2451 silc_buffer_free(idp);
2454 server->stat.cell_servers++;
2457 /* Check whether this router connection has been replaced by an
2458 backup router. If it has been then we'll disable the server and will
2459 ignore everything it will send until the backup router resuming
2460 protocol has been completed. */
2461 if (sock->type == SILC_SOCKET_TYPE_ROUTER &&
2462 silc_server_backup_replaced_get(server, server_id, NULL)) {
2463 /* Send packet to the server indicating that it cannot use this
2464 connection as it has been replaced by backup router. */
2465 SilcBuffer packet = silc_buffer_alloc(2);
2466 silc_buffer_pull_tail(packet, SILC_BUFFER_END(packet));
2467 silc_buffer_format(packet,
2468 SILC_STR_UI_CHAR(SILC_SERVER_BACKUP_REPLACED),
2469 SILC_STR_UI_CHAR(0),
2471 silc_server_packet_send(server, sock,
2472 SILC_PACKET_RESUME_ROUTER, 0,
2473 packet->data, packet->len, TRUE);
2474 silc_buffer_free(packet);
2476 /* Mark the router disabled. The data sent earlier will go but nothing
2477 after this does not go to this connection. */
2478 idata->status |= SILC_IDLIST_STATUS_DISABLED;
2480 /* If it is router announce our stuff to it. */
2481 if (sock->type == SILC_SOCKET_TYPE_ROUTER &&
2482 server->server_type == SILC_ROUTER) {
2483 silc_server_announce_servers(server, FALSE, 0, sock);
2484 silc_server_announce_clients(server, 0, sock);
2485 silc_server_announce_channels(server, 0, sock);
2492 /* Processes incoming New ID packet. New ID Payload is used to distribute
2493 information about newly registered clients and servers. */
2495 static void silc_server_new_id_real(SilcServer server,
2496 SilcSocketConnection sock,
2497 SilcPacketContext *packet,
2500 SilcBuffer buffer = packet->buffer;
2502 SilcServerEntry router, server_entry;
2503 SilcSocketConnection router_sock;
2508 SILC_LOG_DEBUG(("Processing new ID"));
2510 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
2511 server->server_type == SILC_SERVER ||
2512 packet->src_id_type != SILC_ID_SERVER)
2515 idp = silc_id_payload_parse(buffer->data, buffer->len);
2519 id_type = silc_id_payload_get_type(idp);
2521 /* Normal server cannot have other normal server connections */
2522 server_entry = (SilcServerEntry)sock->user_data;
2523 if (id_type == SILC_ID_SERVER && sock->type == SILC_SOCKET_TYPE_SERVER &&
2524 server_entry->server_type == SILC_SERVER)
2527 id = silc_id_payload_get_id(idp);
2531 /* If the packet is coming from server then use the sender as the
2532 origin of the the packet. If it came from router then check the real
2533 sender of the packet and use that as the origin. */
2534 if (sock->type == SILC_SOCKET_TYPE_SERVER) {
2535 id_list = server->local_list;
2537 router = sock->user_data;
2539 /* If the sender is backup router and ID is server (and we are not
2540 backup router) then switch the entry to global list. */
2541 if (server_entry->server_type == SILC_BACKUP_ROUTER &&
2542 id_type == SILC_ID_SERVER &&
2543 server->id_entry->server_type != SILC_BACKUP_ROUTER) {
2544 id_list = server->global_list;
2545 router_sock = server->router ? SILC_PRIMARY_ROUTE(server) : sock;
2548 void *sender_id = silc_id_str2id(packet->src_id, packet->src_id_len,
2549 packet->src_id_type);
2550 router = silc_idlist_find_server_by_id(server->global_list,
2551 sender_id, TRUE, NULL);
2553 router = silc_idlist_find_server_by_id(server->local_list,
2554 sender_id, TRUE, NULL);
2555 silc_free(sender_id);
2557 id_list = server->global_list;
2564 case SILC_ID_CLIENT:
2566 SilcClientEntry entry;
2568 /* Check that we do not have this client already */
2569 entry = silc_idlist_find_client_by_id(server->global_list,
2570 id, server->server_type,
2573 entry = silc_idlist_find_client_by_id(server->local_list,
2574 id, server->server_type,
2577 SILC_LOG_DEBUG(("Ignoring client that we already have"));
2581 SILC_LOG_DEBUG(("New client id(%s) from [%s] %s",
2582 silc_id_render(id, SILC_ID_CLIENT),
2583 sock->type == SILC_SOCKET_TYPE_SERVER ?
2584 "Server" : "Router", sock->hostname));
2586 /* As a router we keep information of all global information in our
2587 global list. Cell wide information however is kept in the local
2589 entry = silc_idlist_add_client(id_list, NULL, NULL, NULL,
2590 id, router, NULL, 0);
2592 SILC_LOG_ERROR(("Could not add new client to the ID Cache"));
2594 /* Inform the sender that the ID is not usable */
2595 silc_server_send_notify_signoff(server, sock, FALSE, id, NULL);
2598 entry->nickname = NULL;
2599 entry->data.status |= SILC_IDLIST_STATUS_REGISTERED;
2601 if (sock->type == SILC_SOCKET_TYPE_SERVER)
2602 server->stat.cell_clients++;
2603 server->stat.clients++;
2605 /* Check if anyone is watching this nickname */
2606 if (server->server_type == SILC_ROUTER && id_list == server->local_list)
2607 silc_server_check_watcher_list(server, entry, NULL, 0);
2611 case SILC_ID_SERVER:
2613 SilcServerEntry entry;
2615 /* If the ID is mine, ignore it. */
2616 if (SILC_ID_SERVER_COMPARE(id, server->id)) {
2617 SILC_LOG_DEBUG(("Ignoring my own ID as new ID"));
2621 /* If the ID is the sender's ID, ignore it (we have it already) */
2622 if (SILC_ID_SERVER_COMPARE(id, router->id)) {
2623 SILC_LOG_DEBUG(("Ignoring sender's own ID"));
2627 /* Check that we do not have this server already */
2628 entry = silc_idlist_find_server_by_id(server->global_list,
2629 id, server->server_type,
2632 entry = silc_idlist_find_server_by_id(server->local_list,
2633 id, server->server_type,
2636 SILC_LOG_DEBUG(("Ignoring server that we already have"));
2640 SILC_LOG_DEBUG(("New server id(%s) from [%s] %s",
2641 silc_id_render(id, SILC_ID_SERVER),
2642 sock->type == SILC_SOCKET_TYPE_SERVER ?
2643 "Server" : "Router", sock->hostname));
2645 /* As a router we keep information of all global information in our
2646 global list. Cell wide information however is kept in the local
2648 entry = silc_idlist_add_server(id_list, NULL, 0, id, router,
2651 SILC_LOG_ERROR(("Could not add new server to the ID Cache"));
2654 entry->data.status |= SILC_IDLIST_STATUS_REGISTERED;
2656 if (sock->type == SILC_SOCKET_TYPE_SERVER)
2657 server->stat.cell_servers++;
2658 server->stat.servers++;
2662 case SILC_ID_CHANNEL:
2663 SILC_LOG_ERROR(("Channel cannot be registered with NEW_ID packet"));
2672 /* If the sender of this packet is server and we are router we need to
2673 broadcast this packet to other routers in the network. */
2674 if (broadcast && server->server_type == SILC_ROUTER &&
2675 sock->type == SILC_SOCKET_TYPE_SERVER &&
2676 !(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
2677 SILC_LOG_DEBUG(("Broadcasting received New ID packet"));
2678 silc_server_packet_send(server, SILC_PRIMARY_ROUTE(server),
2680 packet->flags | SILC_PACKET_FLAG_BROADCAST,
2681 buffer->data, buffer->len, FALSE);
2682 silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
2683 packet->type, packet->flags,
2684 packet->buffer->data, packet->buffer->len,
2689 silc_id_payload_free(idp);
2693 /* Processes incoming New ID packet. New ID Payload is used to distribute
2694 information about newly registered clients and servers. */
2696 void silc_server_new_id(SilcServer server, SilcSocketConnection sock,
2697 SilcPacketContext *packet)
2699 silc_server_new_id_real(server, sock, packet, TRUE);
2702 /* Receoved New Id List packet, list of New ID payloads inside one
2703 packet. Process the New ID payloads one by one. */
2705 void silc_server_new_id_list(SilcServer server, SilcSocketConnection sock,
2706 SilcPacketContext *packet)
2708 SilcPacketContext *new_id;
2712 SILC_LOG_DEBUG(("Processing New ID List"));
2714 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
2715 packet->src_id_type != SILC_ID_SERVER)
2718 /* If the sender of this packet is server and we are router we need to
2719 broadcast this packet to other routers in the network. Broadcast
2720 this list packet instead of multiple New ID packets. */
2721 if (server->server_type == SILC_ROUTER &&
2722 sock->type == SILC_SOCKET_TYPE_SERVER &&
2723 !(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
2724 SILC_LOG_DEBUG(("Broadcasting received New ID List packet"));
2725 silc_server_packet_send(server, SILC_PRIMARY_ROUTE(server),
2727 packet->flags | SILC_PACKET_FLAG_BROADCAST,
2728 packet->buffer->data,
2729 packet->buffer->len, FALSE);
2730 silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
2731 packet->type, packet->flags,
2732 packet->buffer->data, packet->buffer->len,
2736 /* Make copy of the original packet context, except for the actual
2737 data buffer, which we will here now fetch from the original buffer. */
2738 new_id = silc_packet_context_alloc();
2739 new_id->type = SILC_PACKET_NEW_ID;
2740 new_id->flags = packet->flags;
2741 new_id->src_id = packet->src_id;
2742 new_id->src_id_len = packet->src_id_len;
2743 new_id->src_id_type = packet->src_id_type;
2744 new_id->dst_id = packet->dst_id;
2745 new_id->dst_id_len = packet->dst_id_len;
2746 new_id->dst_id_type = packet->dst_id_type;
2748 idp = silc_buffer_alloc(256);
2749 new_id->buffer = idp;
2751 while (packet->buffer->len) {
2752 SILC_GET16_MSB(id_len, packet->buffer->data + 2);
2753 if ((id_len > packet->buffer->len) ||
2754 (id_len > idp->truelen))
2757 silc_buffer_pull_tail(idp, 4 + id_len);
2758 silc_buffer_put(idp, packet->buffer->data, 4 + id_len);
2760 /* Process the New ID */
2761 silc_server_new_id_real(server, sock, new_id, FALSE);
2763 silc_buffer_push_tail(idp, 4 + id_len);
2764 silc_buffer_pull(packet->buffer, 4 + id_len);
2767 silc_buffer_free(idp);
2771 /* Received New Channel packet. Information about new channels in the
2772 network are distributed using this packet. Save the information about
2773 the new channel. This usually comes from router but also normal server
2774 can send this to notify channels it has when it connects to us. */
2776 void silc_server_new_channel(SilcServer server,
2777 SilcSocketConnection sock,
2778 SilcPacketContext *packet)
2780 SilcChannelPayload payload;
2781 SilcChannelID *channel_id;
2783 SilcUInt32 name_len;
2786 SilcServerEntry server_entry;
2787 SilcChannelEntry channel;
2789 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
2790 packet->src_id_type != SILC_ID_SERVER ||
2791 server->server_type == SILC_SERVER)
2794 /* Parse the channel payload */
2795 payload = silc_channel_payload_parse(packet->buffer->data,
2796 packet->buffer->len);
2800 /* Get the channel ID */
2801 channel_id = silc_channel_get_id_parse(payload);
2803 silc_channel_payload_free(payload);
2807 channel_name = silc_channel_get_name(payload, &name_len);
2809 channel_name[255] = '\0';
2811 id = silc_channel_get_id(payload, &id_len);
2813 server_entry = (SilcServerEntry)sock->user_data;
2815 if (sock->type == SILC_SOCKET_TYPE_ROUTER) {
2816 /* Add the channel to global list as it is coming from router. It
2817 cannot be our own channel as it is coming from router. */
2819 /* Check that we don't already have this channel */
2820 channel = silc_idlist_find_channel_by_name(server->local_list,
2821 channel_name, NULL);
2823 channel = silc_idlist_find_channel_by_name(server->global_list,
2824 channel_name, NULL);
2826 SILC_LOG_DEBUG(("New channel id(%s) from [Router] %s",
2827 silc_id_render(channel_id, SILC_ID_CHANNEL),
2831 silc_idlist_add_channel(server->global_list, strdup(channel_name),
2832 0, channel_id, sock->user_data, NULL, NULL, 0);
2835 channel->disabled = TRUE;
2837 server->stat.channels++;
2838 if (server->server_type == SILC_ROUTER)
2839 channel->users_resolved = TRUE;
2842 /* The channel is coming from our server, thus it is in our cell
2843 we will add it to our local list. */
2846 SILC_LOG_DEBUG(("Channel id(%s) from [Server] %s",
2847 silc_id_render(channel_id, SILC_ID_CHANNEL),
2850 /* Check that we don't already have this channel */
2851 channel = silc_idlist_find_channel_by_name(server->local_list,
2852 channel_name, NULL);
2854 channel = silc_idlist_find_channel_by_name(server->global_list,
2855 channel_name, NULL);
2857 /* If the channel does not exist, then create it. This creates a new
2858 key to the channel as well that we will send to the server. */
2860 SILC_LOG_DEBUG(("Channel is new to us"));
2862 /* The protocol says that the Channel ID's IP address must be based
2863 on the router's IP address. Check whether the ID is based in our
2864 IP and if it is not then create a new ID and enforce the server
2865 to switch the ID. */
2866 if (server_entry->server_type != SILC_BACKUP_ROUTER &&
2867 !SILC_ID_COMPARE(channel_id, server->id, server->id->ip.data_len)) {
2869 SILC_LOG_DEBUG(("Forcing the server to change Channel ID"));
2871 if (silc_id_create_channel_id(server, server->id, server->rng, &tmp)) {
2872 silc_server_send_notify_channel_change(server, sock, FALSE,
2874 silc_free(channel_id);
2879 /* Create the channel with the provided Channel ID */
2880 channel = silc_server_create_new_channel_with_id(server, NULL, NULL,
2884 silc_channel_payload_free(payload);
2885 silc_free(channel_id);
2888 channel->disabled = TRUE;
2889 channel->mode = silc_channel_get_mode(payload);
2891 /* Send the new channel key to the server */
2892 id = silc_id_id2str(channel->id, SILC_ID_CHANNEL);
2893 id_len = silc_id_get_len(channel->id, SILC_ID_CHANNEL);
2894 chk = silc_channel_key_payload_encode(id_len, id,
2895 strlen(channel->channel_key->
2897 channel->channel_key->cipher->name,
2898 channel->key_len / 8,
2900 silc_server_packet_send(server, sock, SILC_PACKET_CHANNEL_KEY, 0,
2901 chk->data, chk->len, FALSE);
2902 silc_buffer_free(chk);
2904 /* The channel exist by that name, check whether the ID's match.
2905 If they don't then we'll force the server to use the ID we have.
2906 We also create a new key for the channel. */
2907 SilcBuffer modes = NULL, users = NULL, users_modes = NULL;
2909 SILC_LOG_DEBUG(("Channel already exists"));
2911 if (!SILC_ID_CHANNEL_COMPARE(channel_id, channel->id)) {
2912 /* They don't match, send CHANNEL_CHANGE notify to the server to
2913 force the ID change. */
2914 SILC_LOG_DEBUG(("Forcing the server to change Channel ID"));
2915 silc_server_send_notify_channel_change(server, sock, FALSE,
2916 channel_id, channel->id);
2918 /* Wait that server re-announces this channel */
2922 #if 0 /* We will announce our CMODE anyway for this channel, so no need
2923 to check it (implicit enforce). */
2925 /* If the mode is different from what we have then enforce the
2927 mode = silc_channel_get_mode(payload);
2928 if (channel->mode != mode) {
2929 SILC_LOG_DEBUG(("Forcing the server to change channel mode"));
2930 silc_server_send_notify_cmode(server, sock, FALSE, channel,
2931 channel->mode, server->id,
2932 SILC_ID_SERVER, channel->cipher,
2934 channel->passphrase,
2935 channel->founder_key);
2939 /* Create new key for the channel and send it to the server and
2940 everybody else possibly on the channel. */
2941 if (!(channel->mode & SILC_CHANNEL_MODE_PRIVKEY)) {
2942 if (!silc_server_create_channel_key(server, channel, 0))
2945 /* Send to the channel */
2946 silc_server_send_channel_key(server, sock, channel, FALSE);
2947 id = silc_id_id2str(channel->id, SILC_ID_CHANNEL);
2948 id_len = silc_id_get_len(channel->id, SILC_ID_CHANNEL);
2950 /* Send to the server */
2951 chk = silc_channel_key_payload_encode(id_len, id,
2952 strlen(channel->channel_key->
2954 channel->channel_key->
2956 channel->key_len / 8,
2958 silc_server_packet_send(server, sock, SILC_PACKET_CHANNEL_KEY, 0,
2959 chk->data, chk->len, FALSE);
2960 silc_buffer_free(chk);
2964 silc_free(channel_id);
2966 /* Update statistics */
2967 server->stat.channels++;
2968 server->stat.cell_channels++;
2970 /* Since the channel is coming from server and we also know about it
2971 then send the JOIN notify to the server so that it see's our
2972 users on the channel "joining" the channel. */
2973 silc_server_announce_get_channel_users(server, channel, &modes, &users,
2976 silc_buffer_push(users, users->data - users->head);
2977 silc_server_packet_send(server, sock,
2978 SILC_PACKET_NOTIFY, SILC_PACKET_FLAG_LIST,
2979 users->data, users->len, FALSE);
2980 silc_buffer_free(users);
2983 silc_buffer_push(modes, modes->data - modes->head);
2984 silc_server_packet_send_dest(server, sock,
2985 SILC_PACKET_NOTIFY, SILC_PACKET_FLAG_LIST,
2986 channel->id, SILC_ID_CHANNEL,
2987 modes->data, modes->len, FALSE);
2988 silc_buffer_free(modes);
2991 silc_buffer_push(users_modes, users_modes->data - users_modes->head);
2992 silc_server_packet_send_dest(server, sock,
2993 SILC_PACKET_NOTIFY, SILC_PACKET_FLAG_LIST,
2994 channel->id, SILC_ID_CHANNEL,
2996 users_modes->len, FALSE);
2997 silc_buffer_free(users_modes);
2999 if (channel->topic) {
3000 silc_server_send_notify_topic_set(server, sock,
3001 server->server_type == SILC_ROUTER ?
3002 TRUE : FALSE, channel,
3003 server->id, SILC_ID_SERVER,
3009 silc_channel_payload_free(payload);
3012 /* Received New Channel List packet, list of New Channel List payloads inside
3013 one packet. Process the New Channel payloads one by one. */
3015 void silc_server_new_channel_list(SilcServer server,
3016 SilcSocketConnection sock,
3017 SilcPacketContext *packet)
3019 SilcPacketContext *new;
3021 SilcUInt16 len1, len2;
3023 SILC_LOG_DEBUG(("Processing New Channel List"));
3025 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
3026 packet->src_id_type != SILC_ID_SERVER ||
3027 server->server_type == SILC_SERVER)
3030 /* If the sender of this packet is server and we are router we need to
3031 broadcast this packet to other routers in the network. Broadcast
3032 this list packet instead of multiple New Channel packets. */
3033 if (server->server_type == SILC_ROUTER &&
3034 sock->type == SILC_SOCKET_TYPE_SERVER &&
3035 !(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
3036 SILC_LOG_DEBUG(("Broadcasting received New Channel List packet"));
3037 silc_server_packet_send(server, SILC_PRIMARY_ROUTE(server),
3039 packet->flags | SILC_PACKET_FLAG_BROADCAST,
3040 packet->buffer->data,
3041 packet->buffer->len, FALSE);
3042 silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
3043 packet->type, packet->flags,
3044 packet->buffer->data, packet->buffer->len,
3048 /* Make copy of the original packet context, except for the actual
3049 data buffer, which we will here now fetch from the original buffer. */
3050 new = silc_packet_context_alloc();
3051 new->type = SILC_PACKET_NEW_CHANNEL;
3052 new->flags = packet->flags;
3053 new->src_id = packet->src_id;
3054 new->src_id_len = packet->src_id_len;
3055 new->src_id_type = packet->src_id_type;
3056 new->dst_id = packet->dst_id;
3057 new->dst_id_len = packet->dst_id_len;
3058 new->dst_id_type = packet->dst_id_type;
3060 buffer = silc_buffer_alloc(512);
3061 new->buffer = buffer;
3063 while (packet->buffer->len) {
3064 SILC_GET16_MSB(len1, packet->buffer->data);
3065 if ((len1 > packet->buffer->len) ||
3066 (len1 > buffer->truelen))
3069 SILC_GET16_MSB(len2, packet->buffer->data + 2 + len1);
3070 if ((len2 > packet->buffer->len) ||
3071 (len2 > buffer->truelen))
3074 silc_buffer_pull_tail(buffer, 8 + len1 + len2);
3075 silc_buffer_put(buffer, packet->buffer->data, 8 + len1 + len2);
3077 /* Process the New Channel */
3078 silc_server_new_channel(server, sock, new);
3080 silc_buffer_push_tail(buffer, 8 + len1 + len2);
3081 silc_buffer_pull(packet->buffer, 8 + len1 + len2);
3084 silc_buffer_free(buffer);
3088 /* Received key agreement packet. This packet is never for us. It is to
3089 the client in the packet's destination ID. Sending of this sort of packet
3090 equals sending private message, ie. it is sent point to point from
3091 one client to another. */
3093 void silc_server_key_agreement(SilcServer server,
3094 SilcSocketConnection sock,
3095 SilcPacketContext *packet)
3097 SilcSocketConnection dst_sock;
3098 SilcIDListData idata;
3100 SILC_LOG_DEBUG(("Start"));
3102 if (packet->src_id_type != SILC_ID_CLIENT ||
3103 packet->dst_id_type != SILC_ID_CLIENT)
3106 if (!packet->dst_id)
3109 /* Get the route to the client */
3110 dst_sock = silc_server_get_client_route(server, packet->dst_id,
3111 packet->dst_id_len, NULL,
3116 /* Relay the packet */
3117 silc_server_relay_packet(server, dst_sock, idata->send_key,
3118 idata->hmac_send, idata->psn_send++,
3122 /* Received connection auth request packet that is used during connection
3123 phase to resolve the mandatory authentication method. This packet can
3124 actually be received at anytime but usually it is used only during
3125 the connection authentication phase. Now, protocol says that this packet
3126 can come from client or server, however, we support only this coming
3127 from client and expect that server always knows what authentication
3130 void silc_server_connection_auth_request(SilcServer server,
3131 SilcSocketConnection sock,
3132 SilcPacketContext *packet)
3134 SilcServerConfigClient *client = NULL;
3135 SilcUInt16 conn_type;
3137 SilcAuthMethod auth_meth = SILC_AUTH_NONE;
3139 if (packet->src_id_type && packet->src_id_type != SILC_ID_CLIENT) {
3140 SILC_LOG_DEBUG(("Request not from client"));
3144 /* Parse the payload */
3145 ret = silc_buffer_unformat(packet->buffer,
3146 SILC_STR_UI_SHORT(&conn_type),
3147 SILC_STR_UI_SHORT(NULL),
3152 if (conn_type != SILC_SOCKET_TYPE_CLIENT)
3155 /* Get the authentication method for the client */
3156 auth_meth = SILC_AUTH_NONE;
3157 client = silc_server_config_find_client(server, sock->ip);
3159 client = silc_server_config_find_client(server, sock->hostname);
3161 if (client->passphrase) {
3162 if (client->publickeys && !server->config->prefer_passphrase_auth)
3163 auth_meth = SILC_AUTH_PUBLIC_KEY;
3165 auth_meth = SILC_AUTH_PASSWORD;
3166 } else if (client->publickeys)
3167 auth_meth = SILC_AUTH_PUBLIC_KEY;
3170 SILC_LOG_DEBUG(("Authentication method is [%s]",
3171 (auth_meth == SILC_AUTH_NONE ? "None" :
3172 auth_meth == SILC_AUTH_PASSWORD ? "Passphrase" :
3173 "Digital signatures")));
3175 /* Send it back to the client */
3176 silc_server_send_connection_auth_request(server, sock, conn_type, auth_meth);
3179 /* Received REKEY packet. The sender of the packet wants to regenerate
3180 its session keys. This starts the REKEY protocol. */
3182 void silc_server_rekey(SilcServer server,
3183 SilcSocketConnection sock,
3184 SilcPacketContext *packet)
3186 SilcProtocol protocol;
3187 SilcServerRekeyInternalContext *proto_ctx;
3188 SilcIDListData idata = (SilcIDListData)sock->user_data;
3190 SILC_LOG_DEBUG(("Start"));
3192 /* Allocate internal protocol context. This is sent as context
3194 proto_ctx = silc_calloc(1, sizeof(*proto_ctx));
3195 proto_ctx->server = (void *)server;
3196 proto_ctx->sock = sock;
3197 proto_ctx->responder = TRUE;
3198 proto_ctx->pfs = idata->rekey->pfs;
3200 /* Perform rekey protocol. Will call the final callback after the
3201 protocol is over. */
3202 silc_protocol_alloc(SILC_PROTOCOL_SERVER_REKEY,
3203 &protocol, proto_ctx, silc_server_rekey_final);
3204 sock->protocol = protocol;
3206 if (proto_ctx->pfs == FALSE)
3207 /* Run the protocol */
3208 silc_protocol_execute(protocol, server->schedule, 0, 0);
3211 /* Received file transger packet. This packet is never for us. It is to
3212 the client in the packet's destination ID. Sending of this sort of packet
3213 equals sending private message, ie. it is sent point to point from
3214 one client to another. */
3216 void silc_server_ftp(SilcServer server,
3217 SilcSocketConnection sock,
3218 SilcPacketContext *packet)
3220 SilcSocketConnection dst_sock;
3221 SilcIDListData idata;
3223 SILC_LOG_DEBUG(("Start"));
3225 if (packet->src_id_type != SILC_ID_CLIENT ||
3226 packet->dst_id_type != SILC_ID_CLIENT)
3229 if (!packet->dst_id)
3232 /* Get the route to the client */
3233 dst_sock = silc_server_get_client_route(server, packet->dst_id,
3234 packet->dst_id_len, NULL,
3239 /* Relay the packet */
3240 silc_server_relay_packet(server, dst_sock, idata->send_key,
3241 idata->hmac_send, idata->psn_send++,
3247 SilcSocketConnection sock;
3248 SilcPacketContext *packet;
3250 } *SilcServerResumeResolve;
3252 SILC_SERVER_CMD_FUNC(resume_resolve)
3254 SilcServerResumeResolve r = (SilcServerResumeResolve)context;
3255 SilcServer server = r->server;
3256 SilcSocketConnection sock = r->sock;
3257 SilcServerCommandReplyContext reply = context2;
3258 SilcClientEntry client;
3260 SILC_LOG_DEBUG(("Start"));
3262 if (!reply || !silc_command_get_status(reply->payload, NULL, NULL)) {
3263 SILC_LOG_ERROR(("Client %s (%s) tried to resume unknown client, "
3264 "closing connection", sock->hostname, sock->ip));
3265 silc_server_disconnect_remote(server, sock,
3266 SILC_STATUS_ERR_INCOMPLETE_INFORMATION,
3267 "Resuming not possible");
3268 if (sock->user_data)
3269 silc_server_free_sock_user_data(server, sock, NULL);
3273 if (reply && silc_command_get(reply->payload) == SILC_COMMAND_WHOIS) {
3274 /* Get entry to the client, and resolve it if we don't have it. */
3275 client = silc_idlist_find_client_by_id(server->local_list,
3276 r->data, TRUE, NULL);
3278 client = silc_idlist_find_client_by_id(server->global_list,
3279 r->data, TRUE, NULL);
3281 SILC_LOG_ERROR(("Client %s (%s) tried to resume unknown client, "
3282 "closing connection", sock->hostname, sock->ip));
3283 silc_server_disconnect_remote(server, sock,
3284 SILC_STATUS_ERR_INCOMPLETE_INFORMATION,
3285 "Resuming not possible");
3286 if (sock->user_data)
3287 silc_server_free_sock_user_data(server, sock, NULL);
3292 if (!(client->mode & SILC_UMODE_DETACHED)) {
3293 SILC_LOG_ERROR(("Client %s (%s) tried to resume un-detached client, "
3294 "closing connection", sock->hostname, sock->ip));
3295 silc_server_disconnect_remote(server, sock,
3296 SILC_STATUS_ERR_INCOMPLETE_INFORMATION,
3297 "Resuming not possible");
3298 if (sock->user_data)
3299 silc_server_free_sock_user_data(server, sock, NULL);
3304 /* Reprocess the packet */
3305 silc_server_resume_client(server, sock, r->packet);
3308 silc_socket_free(r->sock);
3309 silc_packet_context_free(r->packet);
3314 /* Received client resuming packet. This is used to resume detached
3315 client session. It can be sent by the client who wishes to resume
3316 but this is also sent by servers and routers to notify other routers
3317 that the client is not detached anymore. */
3319 void silc_server_resume_client(SilcServer server,
3320 SilcSocketConnection sock,
3321 SilcPacketContext *packet)
3323 SilcBuffer buffer = packet->buffer, buf;
3324 SilcIDListData idata;
3325 SilcClientEntry detached_client;
3326 SilcClientID *client_id = NULL;
3327 unsigned char *id_string, *auth = NULL;
3328 SilcUInt16 id_len, auth_len = 0;
3329 int ret, nickfail = 0;
3330 bool resolved, local, nick_change = FALSE, resolve = FALSE;
3331 SilcChannelEntry channel;
3332 SilcHashTableList htl;
3333 SilcChannelClientEntry chl;
3334 SilcServerResumeResolve r;
3336 ret = silc_buffer_unformat(buffer,
3337 SILC_STR_UI16_NSTRING(&id_string, &id_len),
3340 client_id = silc_id_str2id(id_string, id_len, SILC_ID_CLIENT);
3342 if (sock->type == SILC_SOCKET_TYPE_CLIENT) {
3343 /* Client send this and is attempting to resume to old client session */
3344 SilcClientEntry client;
3348 silc_buffer_pull(buffer, 2 + id_len);
3349 auth = buffer->data;
3350 auth_len = buffer->len;
3351 silc_buffer_push(buffer, 2 + id_len);
3354 if (!client_id || auth_len < 128) {
3355 SILC_LOG_ERROR(("Client %s (%s) sent incomplete resume information, "
3356 "closing connection", sock->hostname, sock->ip));
3357 silc_server_disconnect_remote(server, sock,
3358 SILC_STATUS_ERR_INCOMPLETE_INFORMATION,
3359 "Resuming not possible");
3360 if (sock->user_data)
3361 silc_server_free_sock_user_data(server, sock, NULL);
3362 silc_free(client_id);
3366 /* Take client entry of this connection */
3367 client = (SilcClientEntry)sock->user_data;
3368 idata = (SilcIDListData)client;
3370 /* Get entry to the client, and resolve it if we don't have it. */
3371 detached_client = silc_server_get_client_resolve(server, client_id, FALSE,
3373 if (!detached_client) {
3375 /* The client info is being resolved. Reprocess this packet after
3376 receiving the reply to the query. */
3377 SILC_LOG_DEBUG(("Resolving client"));
3378 r = silc_calloc(1, sizeof(*r));
3382 r->sock = silc_socket_dup(sock);
3383 r->packet = silc_packet_context_dup(packet);
3384 r->data = client_id;
3385 silc_server_command_pending(server, SILC_COMMAND_WHOIS,
3387 silc_server_command_resume_resolve, r);
3389 SILC_LOG_ERROR(("Client %s (%s) tried to resume unknown client, "
3390 "closing connection", sock->hostname, sock->ip));
3391 silc_server_disconnect_remote(server, sock,
3392 SILC_STATUS_ERR_INCOMPLETE_INFORMATION,
3393 "Resuming not possible");
3394 if (sock->user_data)
3395 silc_server_free_sock_user_data(server, sock, NULL);
3396 silc_free(client_id);
3401 if (!(detached_client->mode & SILC_UMODE_DETACHED))
3403 if (!silc_hash_table_count(detached_client->channels) &&
3404 detached_client->router)
3406 if (!detached_client->nickname)
3410 if (server->server_type == SILC_SERVER && !server->standalone) {
3411 /* The client info is being resolved. Reprocess this packet after
3412 receiving the reply to the query. */
3413 SILC_LOG_DEBUG(("Resolving client info"));
3414 silc_server_get_client_resolve(server, client_id, TRUE, NULL);
3415 r = silc_calloc(1, sizeof(*r));
3419 r->sock = silc_socket_dup(sock);
3420 r->packet = silc_packet_context_dup(packet);
3421 r->data = client_id;
3422 silc_server_command_pending(server, SILC_COMMAND_WHOIS,
3424 silc_server_command_resume_resolve, r);
3427 if (server->server_type == SILC_SERVER) {
3428 SILC_LOG_ERROR(("Client %s (%s) tried to resume un-detached client, "
3429 "closing connection", sock->hostname, sock->ip));
3430 silc_server_disconnect_remote(server, sock,
3431 SILC_STATUS_ERR_INCOMPLETE_INFORMATION,
3432 "Resuming not possible");
3433 if (sock->user_data)
3434 silc_server_free_sock_user_data(server, sock, NULL);
3435 silc_free(client_id);
3440 /* Check that we have the public key of the client, if not then we must
3441 resolve it first. */
3442 if (!detached_client->data.public_key) {
3443 if (server->server_type == SILC_SERVER && server->standalone) {
3444 SILC_LOG_ERROR(("Detached client's public key not present, "
3445 "closing connection"));
3446 silc_server_disconnect_remote(server, sock,
3447 SILC_STATUS_ERR_INCOMPLETE_INFORMATION,
3448 "Resuming not possible");
3449 if (sock->user_data)
3450 silc_server_free_sock_user_data(server, sock, NULL);
3451 silc_free(client_id);
3453 /* We must retrieve the detached client's public key by sending
3454 GETKEY command. Reprocess this packet after receiving the key */
3455 SilcBuffer idp = silc_id_payload_encode(client_id, SILC_ID_CLIENT);
3456 SilcSocketConnection dest_sock =
3457 silc_server_get_client_route(server, NULL, 0, client_id, NULL, NULL);
3459 SILC_LOG_DEBUG(("Resolving client public key"));
3461 silc_server_send_command(server, dest_sock ? dest_sock :
3462 SILC_PRIMARY_ROUTE(server),
3463 SILC_COMMAND_GETKEY, ++server->cmd_ident,
3464 1, 1, idp->data, idp->len);
3466 r = silc_calloc(1, sizeof(*r));
3468 silc_free(client_id);
3473 r->sock = silc_socket_dup(sock);
3474 r->packet = silc_packet_context_dup(packet);
3475 silc_server_command_pending(server, SILC_COMMAND_GETKEY,
3477 silc_server_command_resume_resolve, r);
3479 silc_buffer_free(idp);
3481 silc_free(client_id);
3483 } else if (!silc_pkcs_public_key_compare(detached_client->data.public_key,
3484 idata->public_key)) {
3485 /* We require that the connection and resuming authentication data
3486 must be using same key pair. */
3487 SILC_LOG_ERROR(("Resuming attempted with wrong public key, "
3488 "closing connection"));
3489 silc_server_disconnect_remote(server, sock,
3490 SILC_STATUS_ERR_INCOMPLETE_INFORMATION,
3491 "Resuming not possible");
3492 if (sock->user_data)
3493 silc_server_free_sock_user_data(server, sock, NULL);
3494 silc_free(client_id);
3498 /* Verify the authentication payload. This has to be successful in
3499 order to allow the resuming */
3501 !silc_auth_verify_data(auth, auth_len, SILC_AUTH_PUBLIC_KEY,
3502 detached_client->data.public_key, 0,
3503 idata->hash, detached_client->id,
3505 SILC_LOG_ERROR(("Client %s (%s) resume authentication failed, "
3506 "closing connection", sock->hostname, sock->ip));
3507 silc_server_disconnect_remote(server, sock,
3508 SILC_STATUS_ERR_INCOMPLETE_INFORMATION,
3509 "Resuming not possible");
3510 if (sock->user_data)
3511 silc_server_free_sock_user_data(server, sock, NULL);
3512 silc_free(client_id);
3516 /* Now resume the client to the network */
3518 silc_schedule_task_del_by_context(server->schedule, detached_client);
3519 sock->user_data = detached_client;
3520 detached_client->connection = sock;
3522 /* Take new keys and stuff into use in the old entry */
3523 silc_idlist_del_data(detached_client);
3524 silc_idlist_add_data(detached_client, idata);
3525 detached_client->data.status |= SILC_IDLIST_STATUS_REGISTERED;
3526 detached_client->data.status |= SILC_IDLIST_STATUS_RESUMED;
3527 detached_client->mode &= ~SILC_UMODE_DETACHED;
3528 server->stat.my_detached--;
3530 /* Send the RESUME_CLIENT packet to our primary router so that others
3531 know this client isn't detached anymore. */
3532 buf = silc_buffer_alloc_size(2 + id_len);
3533 silc_buffer_format(buf,
3534 SILC_STR_UI_SHORT(id_len),
3535 SILC_STR_UI_XNSTRING(id_string, id_len),
3538 /* Send to primary router */
3539 silc_server_packet_send(server, SILC_PRIMARY_ROUTE(server),
3540 SILC_PACKET_RESUME_CLIENT, 0,
3541 buf->data, buf->len, TRUE);
3543 /* As router we must deliver this packet directly to the original
3544 server whom this client was earlier. */
3545 if (server->server_type == SILC_ROUTER && detached_client->router &&
3546 detached_client->router->server_type != SILC_ROUTER)
3547 silc_server_packet_send(server, detached_client->router->connection,
3548 SILC_PACKET_RESUME_CLIENT, 0,
3549 buf->data, buf->len, TRUE);
3550 silc_buffer_free(buf);
3552 detached_client->router = NULL;
3554 /* Delete this client entry since we're resuming to old one. */
3555 server->stat.my_clients--;
3556 server->stat.clients--;
3557 if (server->stat.cell_clients)
3558 server->stat.cell_clients--;
3559 silc_server_del_from_watcher_list(server, client);
3560 silc_idlist_del_client(server->local_list, client);
3561 client = detached_client;
3563 /* If the ID is not based in our ID then change it */
3564 if (!SILC_ID_COMPARE(client->id, server->id, server->id->ip.data_len)) {
3565 silc_free(client_id);
3566 while (!silc_id_create_client_id(server, server->id, server->rng,
3567 server->md5hash, client->nickname,
3571 silc_server_disconnect_remote(server, sock,
3572 SILC_STATUS_ERR_BAD_NICKNAME, NULL);
3573 if (sock->user_data)
3574 silc_server_free_sock_user_data(server, sock, NULL);
3577 snprintf(&client->nickname[strlen(client->nickname) - 1], 1,
3584 /* Notify about Client ID change, nickname doesn't actually change. */
3585 silc_server_send_notify_nick_change(server, SILC_PRIMARY_ROUTE(server),
3586 SILC_BROADCAST(server),
3587 client->id, client_id,
3591 /* Resolve users on those channels that client has joined but we
3592 haven't resolved user list yet. */
3593 if (server->server_type == SILC_SERVER && !server->standalone) {
3594 silc_hash_table_list(client->channels, &htl);
3595 while (silc_hash_table_get(&htl, NULL, (void **)&chl)) {
3596 channel = chl->channel;
3597 SILC_LOG_DEBUG(("Resolving users for %s channel",
3598 channel->channel_name));
3599 if (channel->disabled || !channel->users_resolved) {
3600 silc_server_send_command(server, SILC_PRIMARY_ROUTE(server),
3601 SILC_COMMAND_USERS, ++server->cmd_ident,
3602 1, 2, channel->channel_name,
3603 strlen(channel->channel_name));
3606 silc_hash_table_list_reset(&htl);
3609 /* Send the new client ID to the client. After this client may start
3610 receiving other packets, and may start sending packets too. */
3611 silc_server_send_new_id(server, sock, FALSE, client_id, SILC_ID_CLIENT,
3612 silc_id_get_len(client_id, SILC_ID_CLIENT));
3615 /* Send NICK change notify to channels as well. */
3616 SilcBuffer oidp, nidp;
3617 oidp = silc_id_payload_encode(client->id, SILC_ID_CLIENT);
3618 nidp = silc_id_payload_encode(client_id, SILC_ID_CLIENT);
3619 silc_server_send_notify_on_channels(server, NULL, client,
3620 SILC_NOTIFY_TYPE_NICK_CHANGE, 3,
3621 oidp->data, oidp->len,
3622 nidp->data, nidp->len,
3624 strlen(client->nickname));
3625 silc_buffer_free(oidp);
3626 silc_buffer_free(nidp);
3629 /* Add the client again to the ID cache to get it to correct list */
3630 if (!silc_idcache_del_by_context(server->local_list->clients, client))
3631 silc_idcache_del_by_context(server->global_list->clients, client);
3632 silc_free(client->id);
3633 client->id = client_id;
3635 silc_idcache_add(server->local_list->clients, client->nickname,
3636 client->id, client, 0, NULL);
3638 /* Send some nice info to the client */
3639 silc_server_send_connect_notifys(server, sock, client);
3641 /* Send all channel keys of channels the client has joined */
3642 silc_hash_table_list(client->channels, &htl);
3643 while (silc_hash_table_get(&htl, NULL, (void **)&chl)) {
3644 bool created = FALSE;
3645 channel = chl->channel;
3647 if (channel->mode & SILC_CHANNEL_MODE_PRIVKEY)
3650 /* If we don't have channel key, then create one */
3651 if (!channel->channel_key) {
3652 if (!silc_server_create_channel_key(server, channel, 0))
3657 id_string = silc_id_id2str(channel->id, SILC_ID_CHANNEL);
3659 silc_channel_key_payload_encode(silc_id_get_len(channel->id,
3662 strlen(channel->channel_key->
3664 channel->channel_key->cipher->name,
3665 channel->key_len / 8, channel->key);
3666 silc_free(id_string);
3668 /* Send the key packet to client */
3669 silc_server_packet_send(server, sock, SILC_PACKET_CHANNEL_KEY, 0,
3670 keyp->data, keyp->len, FALSE);
3672 if (created && server->server_type == SILC_SERVER)
3673 silc_server_packet_send(server, SILC_PRIMARY_ROUTE(server),
3674 SILC_PACKET_CHANNEL_KEY, 0,
3675 keyp->data, keyp->len, FALSE);
3677 silc_buffer_free(keyp);
3679 silc_hash_table_list_reset(&htl);
3681 } else if (sock->type != SILC_SOCKET_TYPE_CLIENT) {
3682 /* Server or router sent this to us to notify that that a client has
3684 SilcServerEntry server_entry;
3685 SilcServerID *server_id;
3688 SILC_LOG_DEBUG(("Malformed resuming packet"));
3692 /* Get entry to the client, and resolve it if we don't have it. */
3693 detached_client = silc_idlist_find_client_by_id(server->local_list,
3694 client_id, TRUE, NULL);
3695 if (!detached_client) {
3696 detached_client = silc_idlist_find_client_by_id(server->global_list,
3697 client_id, TRUE, NULL);
3698 if (!detached_client) {
3699 SILC_LOG_DEBUG(("Resuming client is unknown"));
3700 silc_free(client_id);
3705 /* Check that the client has not been resumed already because it is
3706 protocol error to attempt to resume more than once. The client
3707 will be killed if this protocol error occurs. */
3708 if (detached_client->data.status & SILC_IDLIST_STATUS_RESUMED &&
3709 !(detached_client->mode & SILC_UMODE_DETACHED)) {
3710 /* The client is clearly attempting to resume more than once and
3711 perhaps playing around by resuming from several different places
3712 at the same time. */
3713 SILC_LOG_DEBUG(("Attempting to re-resume client, killing both"));
3714 silc_server_kill_client(server, detached_client, NULL,
3715 server->id, SILC_ID_SERVER);
3716 silc_free(client_id);
3720 /* Check whether client is detached at all */
3721 if (!(detached_client->mode & SILC_UMODE_DETACHED)) {
3722 SILC_LOG_DEBUG(("Client is not detached"));
3723 silc_free(client_id);
3727 /* Client is detached, and now it is resumed. Remove the detached
3728 mode and mark that it is resumed. */
3729 detached_client->mode &= ~SILC_UMODE_DETACHED;
3730 detached_client->data.status |= SILC_IDLIST_STATUS_RESUMED;
3732 /* Get the new owner of the resumed client */
3733 server_id = silc_id_str2id(packet->src_id, packet->src_id_len,
3734 packet->src_id_type);
3736 silc_free(client_id);
3740 /* Get server entry */
3741 server_entry = silc_idlist_find_server_by_id(server->global_list,
3742 server_id, TRUE, NULL);
3744 if (!server_entry) {
3745 server_entry = silc_idlist_find_server_by_id(server->local_list,
3746 server_id, TRUE, NULL);
3748 if (!server_entry) {
3749 silc_free(server_id);
3750 silc_free(client_id);
3755 if (server->server_type == SILC_ROUTER &&
3756 sock->type == SILC_SOCKET_TYPE_ROUTER &&
3757 server_entry->server_type == SILC_ROUTER)
3760 SILC_LOG_DEBUG(("Resuming detached client"));
3762 /* Change the client to correct list. */
3763 if (!silc_idcache_del_by_context(server->local_list->clients,
3765 silc_idcache_del_by_context(server->global_list->clients,
3767 silc_idcache_add(local && server->server_type == SILC_ROUTER ?
3768 server->local_list->clients :
3769 server->global_list->clients,
3770 detached_client->nickname,
3771 detached_client->id, detached_client, FALSE, NULL);
3772 detached_client->data.status &= ~SILC_IDLIST_STATUS_LOCAL;
3774 /* Change the owner of the client if needed */
3775 if (detached_client->router != server_entry)
3776 detached_client->router = server_entry;
3778 /* Update channel information regarding global clients on channel. */
3779 if (server->server_type == SILC_SERVER) {
3780 silc_hash_table_list(detached_client->channels, &htl);
3781 while (silc_hash_table_get(&htl, NULL, (void **)&chl))
3782 chl->channel->global_users =
3783 silc_server_channel_has_global(chl->channel);
3784 silc_hash_table_list_reset(&htl);
3787 silc_schedule_task_del_by_context(server->schedule, detached_client);
3789 /* If the sender of this packet is server and we are router we need to
3790 broadcast this packet to other routers in the network. */
3791 if (server->server_type == SILC_ROUTER &&
3792 sock->type == SILC_SOCKET_TYPE_SERVER &&
3793 !(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
3794 SILC_LOG_DEBUG(("Broadcasting received Resume Client packet"));
3795 silc_server_packet_send(server, SILC_PRIMARY_ROUTE(server),
3797 packet->flags | SILC_PACKET_FLAG_BROADCAST,
3798 buffer->data, buffer->len, FALSE);
3799 silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
3800 packet->type, packet->flags,
3801 packet->buffer->data, packet->buffer->len,
3805 silc_free(server_id);
3808 silc_free(client_id);