5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2001 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 extern char *server_version;
30 /* Received notify packet. Server can receive notify packets from router.
31 Server then relays the notify messages to clients if needed. */
33 void silc_server_notify(SilcServer server,
34 SilcSocketConnection sock,
35 SilcPacketContext *packet)
37 SilcNotifyPayload payload;
39 SilcArgumentPayload args;
40 SilcChannelID *channel_id = NULL, *channel_id2;
41 SilcClientID *client_id, *client_id2;
42 SilcServerID *server_id;
43 SilcChannelEntry channel;
44 SilcClientEntry client;
45 SilcServerEntry server_entry;
46 SilcChannelClientEntry chl;
47 SilcIDCacheEntry cache;
48 SilcHashTableList htl;
53 SILC_LOG_DEBUG(("Start"));
55 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
56 packet->src_id_type != SILC_ID_SERVER)
62 /* If the packet is destined directly to a client then relay the packet
63 before processing it. */
64 if (packet->dst_id_type == SILC_ID_CLIENT) {
66 SilcSocketConnection dst_sock;
68 /* Get the route to the client */
69 dst_sock = silc_server_get_client_route(server, packet->dst_id,
70 packet->dst_id_len, NULL, &idata);
72 /* Relay the packet */
73 silc_server_relay_packet(server, dst_sock, idata->send_key,
74 idata->hmac_receive, idata->psn_send++,
78 /* Parse the Notify Payload */
79 payload = silc_notify_payload_parse(packet->buffer->data,
84 /* If we are router and this packet is not already broadcast packet
85 we will broadcast it. The sending socket really cannot be router or
86 the router is buggy. If this packet is coming from router then it must
87 have the broadcast flag set already and we won't do anything. */
88 if (!server->standalone && server->server_type == SILC_ROUTER &&
89 sock->type == SILC_SOCKET_TYPE_SERVER &&
90 !(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
91 SILC_LOG_DEBUG(("Broadcasting received Notify packet"));
92 if (packet->dst_id_type == SILC_ID_CHANNEL) {
93 /* Packet is destined to channel */
94 channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len,
99 silc_server_packet_send_dest(server, server->router->connection,
101 packet->flags | SILC_PACKET_FLAG_BROADCAST,
102 channel_id, SILC_ID_CHANNEL,
103 packet->buffer->data, packet->buffer->len,
105 silc_server_backup_send_dest(server, (SilcServerEntry)sock->user_data,
106 packet->type, packet->flags,
107 channel_id, SILC_ID_CHANNEL,
108 packet->buffer->data, packet->buffer->len,
111 /* Packet is destined to client or server */
112 silc_server_packet_send(server, server->router->connection,
114 packet->flags | SILC_PACKET_FLAG_BROADCAST,
115 packet->buffer->data, packet->buffer->len,
117 silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
118 packet->type, packet->flags,
119 packet->buffer->data, packet->buffer->len,
124 type = silc_notify_get_type(payload);
125 args = silc_notify_get_args(payload);
130 case SILC_NOTIFY_TYPE_JOIN:
132 * Distribute the notify to local clients on the channel
134 SILC_LOG_DEBUG(("JOIN notify"));
137 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
140 channel_id = silc_id_payload_parse_id(tmp, tmp_len);
144 /* Get channel entry */
145 channel = silc_idlist_find_channel_by_id(server->global_list,
148 channel = silc_idlist_find_channel_by_id(server->local_list,
151 silc_free(channel_id);
155 silc_free(channel_id);
158 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
161 client_id = silc_id_payload_parse_id(tmp, tmp_len);
165 /* If the the client is not in local list we check global list (ie. the
166 channel will be global channel) and if it does not exist then create
167 entry for the client. */
168 client = silc_idlist_find_client_by_id(server->global_list,
169 client_id, server->server_type,
172 client = silc_idlist_find_client_by_id(server->local_list,
173 client_id, server->server_type,
176 /* If router did not find the client the it is bogus */
177 if (server->server_type != SILC_SERVER)
181 silc_idlist_add_client(server->global_list, NULL, NULL, NULL,
182 silc_id_dup(client_id, SILC_ID_CLIENT),
183 sock->user_data, NULL);
185 SILC_LOG_ERROR(("Could not add new client to the ID Cache"));
186 silc_free(client_id);
190 client->data.status |= SILC_IDLIST_STATUS_REGISTERED;
194 /* Do not process the notify if the client is not registered */
195 if (!(client->data.status & SILC_IDLIST_STATUS_REGISTERED))
198 /* Do not add client to channel if it is there already */
199 if (silc_server_client_on_channel(client, channel)) {
200 SILC_LOG_DEBUG(("Client already on channel"));
204 /* Send to channel */
205 silc_server_packet_send_to_channel(server, sock, channel, packet->type,
206 FALSE, packet->buffer->data,
207 packet->buffer->len, FALSE);
209 if (server->server_type != SILC_ROUTER &&
210 sock->type == SILC_SOCKET_TYPE_ROUTER)
211 /* The channel is global now */
212 channel->global_users = TRUE;
214 /* JOIN the global client to the channel (local clients (if router
215 created the channel) is joined in the pending JOIN command). */
216 chl = silc_calloc(1, sizeof(*chl));
217 chl->client = client;
218 chl->channel = channel;
220 /* If this is the first one on the channel then it is the founder of
222 if (!silc_hash_table_count(channel->user_list))
223 chl->mode = (SILC_CHANNEL_UMODE_CHANOP | SILC_CHANNEL_UMODE_CHANFO);
225 silc_hash_table_add(channel->user_list, client, chl);
226 silc_hash_table_add(client->channels, channel, chl);
227 silc_free(client_id);
231 case SILC_NOTIFY_TYPE_LEAVE:
233 * Distribute the notify to local clients on the channel
235 SILC_LOG_DEBUG(("LEAVE notify"));
238 channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len,
239 packet->dst_id_type);
244 /* Get channel entry */
245 channel = silc_idlist_find_channel_by_id(server->global_list,
248 channel = silc_idlist_find_channel_by_id(server->local_list,
251 silc_free(channel_id);
257 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
259 silc_free(channel_id);
262 client_id = silc_id_payload_parse_id(tmp, tmp_len);
264 silc_free(channel_id);
268 /* Get client entry */
269 client = silc_idlist_find_client_by_id(server->global_list,
270 client_id, TRUE, NULL);
272 client = silc_idlist_find_client_by_id(server->local_list,
273 client_id, TRUE, NULL);
275 silc_free(client_id);
276 silc_free(channel_id);
280 silc_free(client_id);
282 /* Check if on channel */
283 if (!silc_server_client_on_channel(client, channel))
286 /* Send the leave notify to channel */
287 silc_server_packet_send_to_channel(server, sock, channel, packet->type,
288 FALSE, packet->buffer->data,
289 packet->buffer->len, FALSE);
291 /* Remove the user from channel */
292 silc_server_remove_from_one_channel(server, sock, channel, client, FALSE);
295 case SILC_NOTIFY_TYPE_SIGNOFF:
297 * Distribute the notify to local clients on the channel
299 SILC_LOG_DEBUG(("SIGNOFF notify"));
302 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
305 client_id = silc_id_payload_parse_id(tmp, tmp_len);
309 /* Get client entry */
310 client = silc_idlist_find_client_by_id(server->global_list,
311 client_id, TRUE, &cache);
313 client = silc_idlist_find_client_by_id(server->local_list,
314 client_id, TRUE, &cache);
316 silc_free(client_id);
320 silc_free(client_id);
322 /* Get signoff message */
323 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
327 /* Remove the client from all channels. */
328 silc_server_remove_from_channels(server, NULL, client, TRUE, tmp, FALSE);
330 client->data.status &= ~SILC_IDLIST_STATUS_REGISTERED;
331 cache->expire = SILC_ID_CACHE_EXPIRE_DEF;
332 server->stat.clients--;
333 if (server->server_type == SILC_ROUTER)
334 server->stat.cell_clients--;
337 case SILC_NOTIFY_TYPE_TOPIC_SET:
339 * Distribute the notify to local clients on the channel
342 SILC_LOG_DEBUG(("TOPIC SET notify"));
345 channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len,
346 packet->dst_id_type);
351 /* Get channel entry */
352 channel = silc_idlist_find_channel_by_id(server->global_list,
355 channel = silc_idlist_find_channel_by_id(server->local_list,
358 silc_free(channel_id);
364 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
366 silc_free(channel_id);
371 silc_free(channel->topic);
372 channel->topic = silc_calloc(tmp_len + 1, sizeof(*channel->topic));
373 memcpy(channel->topic, tmp, tmp_len);
375 /* Send the same notify to the channel */
376 silc_server_packet_send_to_channel(server, sock, channel, packet->type,
377 FALSE, packet->buffer->data,
378 packet->buffer->len, FALSE);
379 silc_free(channel_id);
382 case SILC_NOTIFY_TYPE_NICK_CHANGE:
385 * Distribute the notify to local clients on the channel
387 unsigned char *id, *id2;
389 SILC_LOG_DEBUG(("NICK CHANGE notify"));
391 /* Get old client ID */
392 id = silc_argument_get_arg_type(args, 1, &tmp_len);
395 client_id = silc_id_payload_parse_id(id, tmp_len);
399 /* Get new client ID */
400 id2 = silc_argument_get_arg_type(args, 2, &tmp_len);
403 client_id2 = silc_id_payload_parse_id(id2, tmp_len);
407 SILC_LOG_DEBUG(("Old Client ID id(%s)",
408 silc_id_render(client_id, SILC_ID_CLIENT)));
409 SILC_LOG_DEBUG(("New Client ID id(%s)",
410 silc_id_render(client_id2, SILC_ID_CLIENT)));
412 /* Replace the Client ID */
413 client = silc_idlist_replace_client_id(server->global_list, client_id,
416 client = silc_idlist_replace_client_id(server->local_list, client_id,
420 /* The nickname is not valid anymore, set it NULL. This causes that
421 the nickname will be queried if someone wants to know it. */
422 if (client->nickname)
423 silc_free(client->nickname);
424 client->nickname = NULL;
426 /* Send the NICK_CHANGE notify type to local clients on the channels
427 this client is joined to. */
428 silc_server_send_notify_on_channels(server, NULL, client,
429 SILC_NOTIFY_TYPE_NICK_CHANGE, 2,
434 silc_free(client_id);
436 silc_free(client_id2);
440 case SILC_NOTIFY_TYPE_CMODE_CHANGE:
442 * Distribute the notify to local clients on the channel
445 SILC_LOG_DEBUG(("CMODE CHANGE notify"));
448 channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len,
449 packet->dst_id_type);
454 /* Get channel entry */
455 channel = silc_idlist_find_channel_by_id(server->global_list,
458 channel = silc_idlist_find_channel_by_id(server->local_list,
461 silc_free(channel_id);
467 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
469 silc_free(channel_id);
473 SILC_GET32_MSB(mode, tmp);
475 /* Check if mode changed */
476 if (channel->mode == mode)
479 /* Send the same notify to the channel */
480 silc_server_packet_send_to_channel(server, sock, channel, packet->type,
481 FALSE, packet->buffer->data,
482 packet->buffer->len, FALSE);
484 /* If the channel had private keys set and the mode was removed then
485 we must re-generate and re-distribute a new channel key */
486 if (channel->mode & SILC_CHANNEL_MODE_PRIVKEY &&
487 !(mode & SILC_CHANNEL_MODE_PRIVKEY)) {
488 /* Re-generate channel key */
489 if (!silc_server_create_channel_key(server, channel, 0))
492 /* Send the channel key. This sends it to our local clients and if
493 we are normal server to our router as well. */
494 silc_server_send_channel_key(server, NULL, channel,
495 server->server_type == SILC_ROUTER ?
496 FALSE : !server->standalone);
500 channel->mode = mode;
501 silc_free(channel_id);
504 tmp = silc_argument_get_arg_type(args, 4, &tmp_len);
506 unsigned char hash[32];
509 silc_hmac_free(channel->hmac);
510 if (!silc_hmac_alloc(tmp, NULL, &channel->hmac))
513 /* Set the HMAC key out of current channel key. The client must do
515 silc_hash_make(silc_hmac_get_hash(channel->hmac), channel->key,
516 channel->key_len / 8,
518 silc_hmac_set_key(channel->hmac, hash,
519 silc_hash_len(silc_hmac_get_hash(channel->hmac)));
520 memset(hash, 0, sizeof(hash));
525 case SILC_NOTIFY_TYPE_CUMODE_CHANGE:
528 * Distribute the notify to local clients on the channel
530 SilcChannelClientEntry chl2 = NULL;
531 bool notify_sent = FALSE;
533 SILC_LOG_DEBUG(("CUMODE CHANGE notify"));
536 channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len,
537 packet->dst_id_type);
542 /* Get channel entry */
543 channel = silc_idlist_find_channel_by_id(server->global_list,
546 channel = silc_idlist_find_channel_by_id(server->local_list,
549 silc_free(channel_id);
555 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
557 silc_free(channel_id);
561 SILC_GET32_MSB(mode, tmp);
563 /* Get target client */
564 tmp = silc_argument_get_arg_type(args, 3, &tmp_len);
567 client_id = silc_id_payload_parse_id(tmp, tmp_len);
571 /* Get client entry */
572 client = silc_idlist_find_client_by_id(server->global_list,
573 client_id, TRUE, NULL);
575 client = silc_idlist_find_client_by_id(server->local_list,
576 client_id, TRUE, NULL);
578 silc_free(client_id);
582 silc_free(client_id);
584 /* Get entry to the channel user list */
585 silc_hash_table_list(channel->user_list, &htl);
586 while (silc_hash_table_get(&htl, NULL, (void *)&chl)) {
587 /* If the mode is channel founder and we already find a client
588 to have that mode on the channel we will enforce the sender
589 to change the channel founder mode away. There can be only one
590 channel founder on the channel. */
591 if (server->server_type == SILC_ROUTER &&
592 mode & SILC_CHANNEL_UMODE_CHANFO &&
593 chl->mode & SILC_CHANNEL_UMODE_CHANFO) {
595 unsigned char cumode[4];
597 if (chl->client == client && chl->mode == mode) {
602 mode &= ~SILC_CHANNEL_UMODE_CHANFO;
603 silc_server_send_notify_cumode(server, sock, FALSE, channel, mode,
604 client->id, SILC_ID_CLIENT,
607 idp = silc_id_payload_encode(client->id, SILC_ID_CLIENT);
608 SILC_PUT32_MSB(mode, cumode);
609 silc_server_send_notify_to_channel(server, sock, channel, FALSE,
610 SILC_NOTIFY_TYPE_CUMODE_CHANGE,
611 3, idp->data, idp->len,
613 idp->data, idp->len);
614 silc_buffer_free(idp);
617 /* Force the mode change if we alredy set the mode */
620 silc_free(channel_id);
625 if (chl->client == client) {
626 if (chl->mode == mode) {
631 /* Change the mode */
633 if (!(mode & SILC_CHANNEL_UMODE_CHANFO))
640 /* Send the same notify to the channel */
642 silc_server_packet_send_to_channel(server, sock, channel,
644 FALSE, packet->buffer->data,
645 packet->buffer->len, FALSE);
647 silc_free(channel_id);
651 case SILC_NOTIFY_TYPE_INVITE:
653 if (packet->dst_id_type == SILC_ID_CLIENT)
656 SILC_LOG_DEBUG(("INVITE notify"));
659 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
662 channel_id = silc_id_payload_parse_id(tmp, tmp_len);
666 /* Get channel entry */
667 channel = silc_idlist_find_channel_by_id(server->global_list,
670 channel = silc_idlist_find_channel_by_id(server->local_list,
673 silc_free(channel_id);
677 silc_free(channel_id);
679 /* Get the added invite */
680 tmp = silc_argument_get_arg_type(args, 3, &tmp_len);
682 if (!channel->invite_list)
683 channel->invite_list = silc_calloc(tmp_len + 2,
684 sizeof(*channel->invite_list));
686 channel->invite_list = silc_realloc(channel->invite_list,
687 sizeof(*channel->invite_list) *
689 strlen(channel->invite_list) +
691 if (tmp[tmp_len - 1] == ',')
692 tmp[tmp_len - 1] = '\0';
694 strncat(channel->invite_list, tmp, tmp_len);
695 strncat(channel->invite_list, ",", 1);
698 /* Get the deleted invite */
699 tmp = silc_argument_get_arg_type(args, 4, &tmp_len);
700 if (tmp && channel->invite_list) {
701 char *start, *end, *n;
703 if (!strncmp(channel->invite_list, tmp,
704 strlen(channel->invite_list) - 1)) {
705 silc_free(channel->invite_list);
706 channel->invite_list = NULL;
708 start = strstr(channel->invite_list, tmp);
709 if (start && strlen(start) >= tmp_len) {
710 end = start + tmp_len;
711 n = silc_calloc(strlen(channel->invite_list) - tmp_len, sizeof(*n));
712 strncat(n, channel->invite_list, start - channel->invite_list);
713 strncat(n, end + 1, ((channel->invite_list +
714 strlen(channel->invite_list)) - end) - 1);
715 silc_free(channel->invite_list);
716 channel->invite_list = n;
723 case SILC_NOTIFY_TYPE_CHANNEL_CHANGE:
725 * Distribute to the local clients on the channel and change the
729 SILC_LOG_DEBUG(("CHANNEL CHANGE"));
731 if (sock->type != SILC_SOCKET_TYPE_ROUTER)
734 /* Get the old Channel ID */
735 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
738 channel_id = silc_id_payload_parse_id(tmp, tmp_len);
742 /* Get the channel entry */
743 channel = silc_idlist_find_channel_by_id(server->global_list,
746 channel = silc_idlist_find_channel_by_id(server->local_list,
749 silc_free(channel_id);
754 /* Send the notify to the channel */
755 silc_server_packet_send_to_channel(server, sock, channel, packet->type,
756 FALSE, packet->buffer->data,
757 packet->buffer->len, FALSE);
759 /* Get the new Channel ID */
760 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
763 channel_id2 = silc_id_payload_parse_id(tmp, tmp_len);
767 SILC_LOG_DEBUG(("Old Channel ID id(%s)",
768 silc_id_render(channel_id, SILC_ID_CHANNEL)));
769 SILC_LOG_DEBUG(("New Channel ID id(%s)",
770 silc_id_render(channel_id2, SILC_ID_CHANNEL)));
772 /* Replace the Channel ID */
773 if (!silc_idlist_replace_channel_id(server->global_list, channel_id,
775 if (!silc_idlist_replace_channel_id(server->local_list, channel_id,
777 silc_free(channel_id2);
782 SilcBuffer users = NULL, users_modes = NULL;
784 /* Re-announce our clients on the channel as the ID has changed now */
785 silc_server_announce_get_channel_users(server, channel, &users,
788 silc_buffer_push(users, users->data - users->head);
789 silc_server_packet_send(server, sock,
790 SILC_PACKET_NOTIFY, SILC_PACKET_FLAG_LIST,
791 users->data, users->len, FALSE);
792 silc_buffer_free(users);
795 silc_buffer_push(users_modes, users_modes->data - users_modes->head);
796 silc_server_packet_send_dest(server, sock,
797 SILC_PACKET_NOTIFY, SILC_PACKET_FLAG_LIST,
798 channel->id, SILC_ID_CHANNEL,
800 users_modes->len, FALSE);
801 silc_buffer_free(users_modes);
805 silc_free(channel_id);
809 case SILC_NOTIFY_TYPE_SERVER_SIGNOFF:
811 * Remove the server entry and all clients that this server owns.
814 SILC_LOG_DEBUG(("SERVER SIGNOFF notify"));
817 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
820 server_id = silc_id_payload_parse_id(tmp, tmp_len);
824 /* Get server entry */
825 server_entry = silc_idlist_find_server_by_id(server->global_list,
826 server_id, TRUE, NULL);
828 server_entry = silc_idlist_find_server_by_id(server->local_list,
829 server_id, TRUE, NULL);
831 /* If we are normal server then we might not have the server. Check
832 whether router was kind enough to send the list of all clients
833 that actually was to be removed. Remove them if the list is
835 if (server->server_type != SILC_ROUTER &&
836 silc_argument_get_arg_num(args) > 1) {
839 for (i = 1; i < silc_argument_get_arg_num(args); i++) {
841 tmp = silc_argument_get_arg_type(args, i + 1, &tmp_len);
844 client_id = silc_id_payload_parse_id(tmp, tmp_len);
848 /* Get client entry */
849 client = silc_idlist_find_client_by_id(server->global_list,
850 client_id, TRUE, &cache);
852 client = silc_idlist_find_client_by_id(server->local_list,
853 client_id, TRUE, &cache);
855 silc_free(client_id);
859 silc_free(client_id);
861 /* Remove the client from all channels. */
862 silc_server_remove_from_channels(server, NULL, client,
865 client->data.status &= ~SILC_IDLIST_STATUS_REGISTERED;
866 cache->expire = SILC_ID_CACHE_EXPIRE_DEF;
867 server->stat.clients--;
868 if (server->server_type == SILC_ROUTER)
869 server->stat.cell_clients--;
873 silc_free(server_id);
877 silc_free(server_id);
879 /* Free all client entries that this server owns as they will
880 become invalid now as well. */
881 silc_server_remove_clients_by_server(server, server_entry, TRUE);
883 /* Remove the server entry */
884 if (!silc_idlist_del_server(server->global_list, server_entry))
885 silc_idlist_del_server(server->local_list, server_entry);
887 /* XXX update statistics */
891 case SILC_NOTIFY_TYPE_KICKED:
893 * Distribute the notify to local clients on the channel
896 SILC_LOG_DEBUG(("KICKED notify"));
899 channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len,
900 packet->dst_id_type);
905 /* Get channel entry */
906 channel = silc_idlist_find_channel_by_id(server->global_list,
909 channel = silc_idlist_find_channel_by_id(server->local_list,
912 silc_free(channel_id);
916 silc_free(channel_id);
919 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
922 client_id = silc_id_payload_parse_id(tmp, tmp_len);
926 /* If the the client is not in local list we check global list */
927 client = silc_idlist_find_client_by_id(server->global_list,
928 client_id, TRUE, NULL);
930 client = silc_idlist_find_client_by_id(server->local_list,
931 client_id, TRUE, NULL);
933 silc_free(client_id);
938 /* Send to channel */
939 silc_server_packet_send_to_channel(server, sock, channel, packet->type,
940 FALSE, packet->buffer->data,
941 packet->buffer->len, FALSE);
943 /* Remove the client from channel */
944 silc_server_remove_from_one_channel(server, sock, channel, client, FALSE);
948 case SILC_NOTIFY_TYPE_KILLED:
951 * Distribute the notify to local clients on channels
956 SILC_LOG_DEBUG(("KILLED notify"));
959 id = silc_argument_get_arg_type(args, 1, &id_len);
962 client_id = silc_id_payload_parse_id(id, id_len);
966 /* If the the client is not in local list we check global list */
967 client = silc_idlist_find_client_by_id(server->global_list,
968 client_id, TRUE, NULL);
970 client = silc_idlist_find_client_by_id(server->local_list,
971 client_id, TRUE, NULL);
973 silc_free(client_id);
977 silc_free(client_id);
979 /* If the client is one of ours, then close the connection to the
980 client now. This removes the client from all channels as well. */
981 if (packet->dst_id_type == SILC_ID_CLIENT && client->connection) {
982 sock = client->connection;
983 silc_server_free_client_data(server, NULL, client, FALSE, NULL);
984 silc_server_close_connection(server, sock);
989 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
993 /* Send the notify to local clients on the channels except to the
994 client who is killed. */
995 silc_server_send_notify_on_channels(server, client, client,
996 SILC_NOTIFY_TYPE_KILLED,
1001 /* Remove the client from all channels */
1002 silc_server_remove_from_channels(server, NULL, client, FALSE, NULL,
1008 case SILC_NOTIFY_TYPE_UMODE_CHANGE:
1010 * Save the mode of the client.
1013 SILC_LOG_DEBUG(("UMODE_CHANGE notify"));
1016 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
1019 client_id = silc_id_payload_parse_id(tmp, tmp_len);
1023 /* Get client entry */
1024 client = silc_idlist_find_client_by_id(server->global_list,
1025 client_id, TRUE, NULL);
1027 client = silc_idlist_find_client_by_id(server->local_list,
1028 client_id, TRUE, NULL);
1030 silc_free(client_id);
1034 silc_free(client_id);
1037 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
1042 SILC_GET32_MSB(client->mode, tmp);
1046 case SILC_NOTIFY_TYPE_BAN:
1051 SILC_LOG_DEBUG(("BAN notify"));
1053 /* Get Channel ID */
1054 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
1057 channel_id = silc_id_payload_parse_id(tmp, tmp_len);
1061 /* Get channel entry */
1062 channel = silc_idlist_find_channel_by_id(server->global_list,
1065 channel = silc_idlist_find_channel_by_id(server->local_list,
1068 silc_free(channel_id);
1072 silc_free(channel_id);
1074 /* Get the new ban and add it to the ban list */
1075 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
1077 if (!channel->ban_list)
1078 channel->ban_list = silc_calloc(tmp_len + 2,
1079 sizeof(*channel->ban_list));
1081 channel->ban_list = silc_realloc(channel->ban_list,
1082 sizeof(*channel->ban_list) *
1084 strlen(channel->ban_list) + 2));
1085 strncat(channel->ban_list, tmp, tmp_len);
1086 strncat(channel->ban_list, ",", 1);
1089 /* Get the ban to be removed and remove it from the list */
1090 tmp = silc_argument_get_arg_type(args, 3, &tmp_len);
1091 if (tmp && channel->ban_list) {
1092 char *start, *end, *n;
1094 if (!strcmp(channel->ban_list, tmp)) {
1095 silc_free(channel->ban_list);
1096 channel->ban_list = NULL;
1098 start = strstr(channel->ban_list, tmp);
1099 if (start && strlen(start) >= tmp_len) {
1100 end = start + tmp_len;
1101 n = silc_calloc(strlen(channel->ban_list) - tmp_len, sizeof(*n));
1102 strncat(n, channel->ban_list, start - channel->ban_list);
1103 strncat(n, end + 1, ((channel->ban_list +
1104 strlen(channel->ban_list)) - end) - 1);
1105 silc_free(channel->ban_list);
1106 channel->ban_list = n;
1113 /* Ignore rest of the notify types for now */
1114 case SILC_NOTIFY_TYPE_NONE:
1115 case SILC_NOTIFY_TYPE_MOTD:
1122 silc_notify_payload_free(payload);
1125 void silc_server_notify_list(SilcServer server,
1126 SilcSocketConnection sock,
1127 SilcPacketContext *packet)
1129 SilcPacketContext *new;
1133 SILC_LOG_DEBUG(("Processing Notify List"));
1135 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
1136 packet->src_id_type != SILC_ID_SERVER)
1139 /* Make copy of the original packet context, except for the actual
1140 data buffer, which we will here now fetch from the original buffer. */
1141 new = silc_packet_context_alloc();
1142 new->type = SILC_PACKET_NOTIFY;
1143 new->flags = packet->flags;
1144 new->src_id = packet->src_id;
1145 new->src_id_len = packet->src_id_len;
1146 new->src_id_type = packet->src_id_type;
1147 new->dst_id = packet->dst_id;
1148 new->dst_id_len = packet->dst_id_len;
1149 new->dst_id_type = packet->dst_id_type;
1151 buffer = silc_buffer_alloc(1024);
1152 new->buffer = buffer;
1154 while (packet->buffer->len) {
1155 SILC_GET16_MSB(len, packet->buffer->data + 2);
1156 if (len > packet->buffer->len)
1159 if (len > buffer->truelen) {
1160 silc_buffer_free(buffer);
1161 buffer = silc_buffer_alloc(1024 + len);
1164 silc_buffer_pull_tail(buffer, len);
1165 silc_buffer_put(buffer, packet->buffer->data, len);
1167 /* Process the Notify */
1168 silc_server_notify(server, sock, new);
1170 silc_buffer_push_tail(buffer, len);
1171 silc_buffer_pull(packet->buffer, len);
1174 silc_buffer_free(buffer);
1178 /* Received private message. This resolves the destination of the message
1179 and sends the packet. This is used by both server and router. If the
1180 destination is our locally connected client this sends the packet to
1181 the client. This may also send the message for further routing if
1182 the destination is not in our server (or router). */
1184 void silc_server_private_message(SilcServer server,
1185 SilcSocketConnection sock,
1186 SilcPacketContext *packet)
1188 SilcSocketConnection dst_sock;
1189 SilcIDListData idata;
1191 SILC_LOG_DEBUG(("Start"));
1193 if (packet->src_id_type != SILC_ID_CLIENT ||
1194 packet->dst_id_type != SILC_ID_CLIENT || !packet->dst_id)
1197 /* Get the route to the client */
1198 dst_sock = silc_server_get_client_route(server, packet->dst_id,
1199 packet->dst_id_len, NULL, &idata);
1201 /* Send IDENTIFY command reply with error status to indicate that
1202 such destination ID does not exist or is invalid */
1203 SilcBuffer idp = silc_id_payload_encode_data(packet->dst_id,
1205 packet->dst_id_type);
1209 silc_server_send_command_reply(server, sock, SILC_COMMAND_IDENTIFY,
1210 SILC_STATUS_ERR_NO_SUCH_CLIENT_ID, 0, 1,
1212 silc_buffer_free(idp);
1216 /* Send the private message */
1217 silc_server_send_private_message(server, dst_sock, idata->send_key,
1218 idata->hmac_send, idata->psn_send++,
1222 /* Received private message key packet.. This packet is never for us. It is to
1223 the client in the packet's destination ID. Sending of this sort of packet
1224 equals sending private message, ie. it is sent point to point from
1225 one client to another. */
1227 void silc_server_private_message_key(SilcServer server,
1228 SilcSocketConnection sock,
1229 SilcPacketContext *packet)
1231 SilcSocketConnection dst_sock;
1232 SilcIDListData idata;
1234 SILC_LOG_DEBUG(("Start"));
1236 if (packet->src_id_type != SILC_ID_CLIENT ||
1237 packet->dst_id_type != SILC_ID_CLIENT)
1240 if (!packet->dst_id)
1243 /* Get the route to the client */
1244 dst_sock = silc_server_get_client_route(server, packet->dst_id,
1245 packet->dst_id_len, NULL, &idata);
1249 /* Relay the packet */
1250 silc_server_relay_packet(server, dst_sock, idata->send_key,
1251 idata->hmac_send, idata->psn_send++, packet, FALSE);
1254 /* Processes incoming command reply packet. The command reply packet may
1255 be destined to one of our clients or it may directly for us. We will
1256 call the command reply routine after processing the packet. */
1258 void silc_server_command_reply(SilcServer server,
1259 SilcSocketConnection sock,
1260 SilcPacketContext *packet)
1262 SilcBuffer buffer = packet->buffer;
1263 SilcClientEntry client = NULL;
1264 SilcSocketConnection dst_sock;
1265 SilcIDListData idata;
1266 SilcClientID *id = NULL;
1268 SILC_LOG_DEBUG(("Start"));
1270 /* Source must be server or router */
1271 if (packet->src_id_type != SILC_ID_SERVER &&
1272 sock->type != SILC_SOCKET_TYPE_ROUTER)
1275 if (packet->dst_id_type == SILC_ID_CHANNEL)
1278 if (packet->dst_id_type == SILC_ID_CLIENT) {
1279 /* Destination must be one of ours */
1280 id = silc_id_str2id(packet->dst_id, packet->dst_id_len, SILC_ID_CLIENT);
1283 client = silc_idlist_find_client_by_id(server->local_list, id, TRUE, NULL);
1285 SILC_LOG_ERROR(("Cannot process command reply to unknown client"));
1291 if (packet->dst_id_type == SILC_ID_SERVER) {
1292 /* For now this must be for us */
1293 if (memcmp(packet->dst_id, server->id_string, packet->dst_id_len)) {
1294 SILC_LOG_ERROR(("Cannot process command reply to unknown server"));
1299 /* Execute command reply locally for the command */
1300 silc_server_command_reply_process(server, sock, buffer);
1302 if (packet->dst_id_type == SILC_ID_CLIENT && client && id) {
1303 /* Relay the packet to the client */
1305 dst_sock = (SilcSocketConnection)client->connection;
1306 silc_buffer_push(buffer, SILC_PACKET_HEADER_LEN + packet->src_id_len
1307 + packet->dst_id_len + packet->padlen);
1309 silc_packet_send_prepare(dst_sock, 0, 0, buffer->len);
1310 silc_buffer_put(dst_sock->outbuf, buffer->data, buffer->len);
1312 idata = (SilcIDListData)client;
1314 /* Encrypt packet */
1315 silc_packet_encrypt(idata->send_key, idata->hmac_send, idata->psn_send++,
1316 dst_sock->outbuf, buffer->len);
1318 /* Send the packet */
1319 silc_server_packet_send_real(server, dst_sock, TRUE);
1325 /* Process received channel message. The message can be originated from
1326 client or server. */
1328 void silc_server_channel_message(SilcServer server,
1329 SilcSocketConnection sock,
1330 SilcPacketContext *packet)
1332 SilcChannelEntry channel = NULL;
1333 SilcChannelID *id = NULL;
1334 void *sender = NULL;
1335 void *sender_entry = NULL;
1338 SILC_LOG_DEBUG(("Processing channel message"));
1341 if (packet->dst_id_type != SILC_ID_CHANNEL) {
1342 SILC_LOG_DEBUG(("Received bad message for channel, dropped"));
1346 /* Find channel entry */
1347 id = silc_id_str2id(packet->dst_id, packet->dst_id_len, SILC_ID_CHANNEL);
1350 channel = silc_idlist_find_channel_by_id(server->local_list, id, NULL);
1352 channel = silc_idlist_find_channel_by_id(server->global_list, id, NULL);
1354 SILC_LOG_DEBUG(("Could not find channel"));
1359 /* See that this client is on the channel. If the original sender is
1360 not client (as it can be server as well) we don't do the check. */
1361 sender = silc_id_str2id(packet->src_id, packet->src_id_len,
1362 packet->src_id_type);
1365 if (packet->src_id_type == SILC_ID_CLIENT) {
1366 sender_entry = silc_idlist_find_client_by_id(server->local_list,
1367 sender, TRUE, NULL);
1368 if (!sender_entry) {
1370 sender_entry = silc_idlist_find_client_by_id(server->global_list,
1371 sender, TRUE, NULL);
1373 if (!sender_entry || !silc_server_client_on_channel(sender_entry,
1375 SILC_LOG_DEBUG(("Client not on channel"));
1379 /* If the packet is coming from router, but the client entry is
1380 local entry to us then some router is rerouting this to us and it is
1382 if (server->server_type == SILC_ROUTER &&
1383 sock->type == SILC_SOCKET_TYPE_ROUTER && local) {
1384 SILC_LOG_DEBUG(("Channel message rerouted to the sender, drop it"));
1389 /* Distribute the packet to our local clients. This will send the
1390 packet for further routing as well, if needed. */
1391 silc_server_packet_relay_to_channel(server, sock, channel, sender,
1392 packet->src_id_type, sender_entry,
1393 packet->buffer->data,
1394 packet->buffer->len, FALSE);
1403 /* Received channel key packet. We distribute the key to all of our locally
1404 connected clients on the channel. */
1406 void silc_server_channel_key(SilcServer server,
1407 SilcSocketConnection sock,
1408 SilcPacketContext *packet)
1410 SilcBuffer buffer = packet->buffer;
1411 SilcChannelEntry channel;
1413 if (packet->src_id_type != SILC_ID_SERVER ||
1414 (server->server_type == SILC_ROUTER &&
1415 sock->type == SILC_SOCKET_TYPE_ROUTER))
1418 /* Save the channel key */
1419 channel = silc_server_save_channel_key(server, buffer, NULL);
1423 /* Distribute the key to everybody who is on the channel. If we are router
1424 we will also send it to locally connected servers. */
1425 silc_server_send_channel_key(server, sock, channel, FALSE);
1427 if (server->server_type != SILC_BACKUP_ROUTER) {
1428 /* Distribute to local cell backup routers. */
1429 silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
1430 SILC_PACKET_CHANNEL_KEY, 0,
1431 buffer->data, buffer->len, FALSE, TRUE);
1435 /* Received New Client packet and processes it. Creates Client ID for the
1436 client. Client becomes registered after calling this functions. */
1438 SilcClientEntry silc_server_new_client(SilcServer server,
1439 SilcSocketConnection sock,
1440 SilcPacketContext *packet)
1442 SilcBuffer buffer = packet->buffer;
1443 SilcClientEntry client;
1444 SilcClientID *client_id;
1446 SilcIDListData idata;
1447 char *username = NULL, *realname = NULL, *id_string;
1450 char *hostname, *nickname;
1453 SILC_LOG_DEBUG(("Creating new client"));
1455 if (sock->type != SILC_SOCKET_TYPE_CLIENT)
1458 /* Take client entry */
1459 client = (SilcClientEntry)sock->user_data;
1460 idata = (SilcIDListData)client;
1462 /* Remove the old cache entry */
1463 if (!silc_idcache_del_by_context(server->local_list->clients, client)) {
1464 SILC_LOG_ERROR(("Lost client's cache entry - bad thing"));
1465 silc_server_disconnect_remote(server, sock, "Server closed connection: "
1470 /* Parse incoming packet */
1471 ret = silc_buffer_unformat(buffer,
1472 SILC_STR_UI16_STRING_ALLOC(&username),
1473 SILC_STR_UI16_STRING_ALLOC(&realname),
1477 silc_free(username);
1479 silc_free(realname);
1480 silc_server_disconnect_remote(server, sock, "Server closed connection: "
1481 "Incomplete client information");
1486 silc_free(username);
1488 silc_free(realname);
1489 silc_server_disconnect_remote(server, sock, "Server closed connection: "
1490 "Incomplete client information");
1494 if (strlen(username) > 128)
1495 username[127] = '\0';
1497 nickname = strdup(username);
1499 /* Make sanity checks for the hostname of the client. If the hostname
1500 is provided in the `username' check that it is the same than the
1501 resolved hostname, or if not resolved the hostname that appears in
1502 the client's public key. If the hostname is not present then put
1503 it from the resolved name or from the public key. */
1504 if (strchr(username, '@')) {
1505 SilcPublicKeyIdentifier pident;
1506 int tlen = strcspn(username, "@");
1507 char *phostname = NULL;
1509 hostname = silc_calloc((strlen(username) - tlen) + 1, sizeof(char));
1510 memcpy(hostname, username + tlen + 1, strlen(username) - tlen - 1);
1512 if (strcmp(sock->hostname, sock->ip) &&
1513 strcmp(sock->hostname, hostname)) {
1514 silc_free(username);
1515 silc_free(hostname);
1517 silc_free(realname);
1518 silc_server_disconnect_remote(server, sock,
1519 "Server closed connection: "
1520 "Incomplete client information");
1524 pident = silc_pkcs_decode_identifier(client->data.public_key->identifier);
1526 phostname = strdup(pident->host);
1527 silc_pkcs_free_identifier(pident);
1530 if (!strcmp(sock->hostname, sock->ip) &&
1531 phostname && strcmp(phostname, hostname)) {
1532 silc_free(username);
1533 silc_free(hostname);
1535 silc_free(phostname);
1537 silc_free(realname);
1538 silc_server_disconnect_remote(server, sock,
1539 "Server closed connection: "
1540 "Incomplete client information");
1545 silc_free(phostname);
1547 /* The hostname is not present, add it. */
1549 /* XXX For now we cannot take the host name from the public key since
1550 they are not trusted or we cannot verify them as trusted. Just take
1551 what the resolved name or address is. */
1553 if (strcmp(sock->hostname, sock->ip)) {
1555 newusername = silc_calloc(strlen(username) +
1556 strlen(sock->hostname) + 2,
1557 sizeof(*newusername));
1558 strncat(newusername, username, strlen(username));
1559 strncat(newusername, "@", 1);
1560 strncat(newusername, sock->hostname, strlen(sock->hostname));
1561 silc_free(username);
1562 username = newusername;
1565 SilcPublicKeyIdentifier pident =
1566 silc_pkcs_decode_identifier(client->data.public_key->identifier);
1569 newusername = silc_calloc(strlen(username) +
1570 strlen(pident->host) + 2,
1571 sizeof(*newusername));
1572 strncat(newusername, username, strlen(username));
1573 strncat(newusername, "@", 1);
1574 strncat(newusername, pident->host, strlen(pident->host));
1575 silc_free(username);
1576 username = newusername;
1577 silc_pkcs_free_identifier(pident);
1583 /* Create Client ID */
1584 while (!silc_id_create_client_id(server, server->id, server->rng,
1585 server->md5hash, nickname, &client_id)) {
1587 snprintf(&nickname[strlen(nickname) - 1], 1, "%d", nickfail);
1590 /* Update client entry */
1591 idata->status |= SILC_IDLIST_STATUS_REGISTERED;
1592 client->nickname = nickname;
1593 client->username = username;
1594 client->userinfo = realname ? realname : strdup(" ");
1595 client->id = client_id;
1596 id_len = silc_id_get_len(client_id, SILC_ID_CLIENT);
1598 /* Add the client again to the ID cache */
1599 silc_idcache_add(server->local_list->clients, client->nickname,
1600 client_id, client, FALSE);
1602 /* Notify our router about new client on the SILC network */
1603 if (!server->standalone)
1604 silc_server_send_new_id(server, (SilcSocketConnection)
1605 server->router->connection,
1606 server->server_type == SILC_ROUTER ? TRUE : FALSE,
1607 client->id, SILC_ID_CLIENT, id_len);
1609 /* Send the new client ID to the client. */
1610 id_string = silc_id_id2str(client->id, SILC_ID_CLIENT);
1611 reply = silc_buffer_alloc(2 + 2 + id_len);
1612 silc_buffer_pull_tail(reply, SILC_BUFFER_END(reply));
1613 silc_buffer_format(reply,
1614 SILC_STR_UI_SHORT(SILC_ID_CLIENT),
1615 SILC_STR_UI_SHORT(id_len),
1616 SILC_STR_UI_XNSTRING(id_string, id_len),
1618 silc_server_packet_send(server, sock, SILC_PACKET_NEW_ID, 0,
1619 reply->data, reply->len, FALSE);
1620 silc_free(id_string);
1621 silc_buffer_free(reply);
1623 /* Send some nice info to the client */
1624 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1625 ("Welcome to the SILC Network %s",
1627 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1628 ("Your host is %s, running version %s",
1629 server->config->server_info->server_name,
1631 if (server->server_type == SILC_ROUTER) {
1632 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1633 ("There are %d clients on %d servers in SILC "
1634 "Network", server->stat.clients,
1635 server->stat.servers + 1));
1636 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1637 ("There are %d clients on %d server in our cell",
1638 server->stat.cell_clients,
1639 server->stat.cell_servers + 1));
1640 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1641 ("I have %d clients, %d channels, %d servers and "
1643 server->stat.my_clients,
1644 server->stat.my_channels,
1645 server->stat.my_servers,
1646 server->stat.my_routers));
1647 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1648 ("%d server operators and %d router operators "
1650 server->stat.my_server_ops,
1651 server->stat.my_router_ops));
1653 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1654 ("I have %d clients and %d channels formed",
1655 server->stat.my_clients,
1656 server->stat.my_channels));
1657 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1658 ("%d operators online",
1659 server->stat.my_server_ops));
1661 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1662 ("Your connection is secured with %s cipher, "
1663 "key length %d bits",
1664 idata->send_key->cipher->name,
1665 idata->send_key->cipher->key_len));
1666 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1667 ("Your current nickname is %s",
1671 silc_server_send_motd(server, sock);
1676 /* Create new server. This processes received New Server packet and
1677 saves the received Server ID. The server is our locally connected
1678 server thus we save all the information and save it to local list.
1679 This funtion can be used by both normal server and router server.
1680 If normal server uses this it means that its router has connected
1681 to the server. If router uses this it means that one of the cell's
1682 servers is connected to the router. */
1684 SilcServerEntry silc_server_new_server(SilcServer server,
1685 SilcSocketConnection sock,
1686 SilcPacketContext *packet)
1688 SilcBuffer buffer = packet->buffer;
1689 SilcServerEntry new_server, server_entry;
1690 SilcServerID *server_id;
1691 SilcIDListData idata;
1692 unsigned char *server_name, *id_string;
1693 uint16 id_len, name_len;
1697 SILC_LOG_DEBUG(("Creating new server"));
1699 if (sock->type != SILC_SOCKET_TYPE_SERVER &&
1700 sock->type != SILC_SOCKET_TYPE_ROUTER)
1703 /* Take server entry */
1704 new_server = (SilcServerEntry)sock->user_data;
1705 idata = (SilcIDListData)new_server;
1707 /* Remove the old cache entry */
1708 if (!silc_idcache_del_by_context(server->local_list->servers, new_server)) {
1709 silc_idcache_del_by_context(server->global_list->servers, new_server);
1713 /* Parse the incoming packet */
1714 ret = silc_buffer_unformat(buffer,
1715 SILC_STR_UI16_NSTRING_ALLOC(&id_string, &id_len),
1716 SILC_STR_UI16_NSTRING_ALLOC(&server_name,
1721 silc_free(id_string);
1723 silc_free(server_name);
1727 if (id_len > buffer->len) {
1728 silc_free(id_string);
1729 silc_free(server_name);
1734 server_name[255] = '\0';
1737 server_id = silc_id_str2id(id_string, id_len, SILC_ID_SERVER);
1739 silc_free(id_string);
1740 silc_free(server_name);
1743 silc_free(id_string);
1745 /* Check that we do not have this ID already */
1746 server_entry = silc_idlist_find_server_by_id(server->local_list,
1747 server_id, TRUE, NULL);
1749 silc_idcache_del_by_context(server->local_list->servers, server_entry);
1751 server_entry = silc_idlist_find_server_by_id(server->global_list,
1752 server_id, TRUE, NULL);
1754 silc_idcache_del_by_context(server->global_list->servers, server_entry);
1757 /* Update server entry */
1758 idata->status |= SILC_IDLIST_STATUS_REGISTERED;
1759 new_server->server_name = server_name;
1760 new_server->id = server_id;
1762 SILC_LOG_DEBUG(("New server id(%s)",
1763 silc_id_render(server_id, SILC_ID_SERVER)));
1765 /* Add again the entry to the ID cache. */
1766 silc_idcache_add(local ? server->local_list->servers :
1767 server->global_list->servers, server_name, server_id,
1770 /* Distribute the information about new server in the SILC network
1771 to our router. If we are normal server we won't send anything
1772 since this connection must be our router connection. */
1773 if (server->server_type == SILC_ROUTER && !server->standalone &&
1774 server->router->connection != sock)
1775 silc_server_send_new_id(server, server->router->connection,
1776 TRUE, new_server->id, SILC_ID_SERVER,
1777 silc_id_get_len(server_id, SILC_ID_SERVER));
1779 if (server->server_type == SILC_ROUTER)
1780 server->stat.cell_servers++;
1782 /* Check whether this router connection has been replaced by an
1783 backup router. If it has been then we'll disable the server and will
1784 ignore everything it will send until the backup router resuming
1785 protocol has been completed. */
1786 if (sock->type == SILC_SOCKET_TYPE_ROUTER &&
1787 silc_server_backup_replaced_get(server, server_id, NULL)) {
1788 /* Send packet to the server indicating that it cannot use this
1789 connection as it has been replaced by backup router. */
1790 SilcBuffer packet = silc_buffer_alloc(2);
1791 silc_buffer_pull_tail(packet, SILC_BUFFER_END(packet));
1792 silc_buffer_format(packet,
1793 SILC_STR_UI_CHAR(SILC_SERVER_BACKUP_REPLACED),
1794 SILC_STR_UI_CHAR(0),
1796 silc_server_packet_send(server, sock,
1797 SILC_PACKET_RESUME_ROUTER, 0,
1798 packet->data, packet->len, TRUE);
1799 silc_buffer_free(packet);
1801 /* Mark the router disabled. The data sent earlier will go but nothing
1802 after this does not go to this connection. */
1803 idata->status |= SILC_IDLIST_STATUS_DISABLED;
1805 /* If it is router announce our stuff to it. */
1806 if (sock->type == SILC_SOCKET_TYPE_ROUTER &&
1807 server->server_type == SILC_ROUTER) {
1808 silc_server_announce_servers(server, FALSE, 0, sock);
1809 silc_server_announce_clients(server, 0, sock);
1810 silc_server_announce_channels(server, 0, sock);
1817 /* Processes incoming New ID packet. New ID Payload is used to distribute
1818 information about newly registered clients and servers. */
1820 static void silc_server_new_id_real(SilcServer server,
1821 SilcSocketConnection sock,
1822 SilcPacketContext *packet,
1825 SilcBuffer buffer = packet->buffer;
1827 SilcServerEntry router, server_entry;
1828 SilcSocketConnection router_sock;
1833 SILC_LOG_DEBUG(("Processing new ID"));
1835 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
1836 server->server_type == SILC_SERVER ||
1837 packet->src_id_type != SILC_ID_SERVER)
1840 idp = silc_id_payload_parse(buffer->data, buffer->len);
1844 id_type = silc_id_payload_get_type(idp);
1846 /* Normal server cannot have other normal server connections */
1847 server_entry = (SilcServerEntry)sock->user_data;
1848 if (id_type == SILC_ID_SERVER && sock->type == SILC_SOCKET_TYPE_SERVER &&
1849 server_entry->server_type == SILC_SERVER)
1852 id = silc_id_payload_get_id(idp);
1856 /* If the packet is coming from server then use the sender as the
1857 origin of the the packet. If it came from router then check the real
1858 sender of the packet and use that as the origin. */
1859 if (sock->type == SILC_SOCKET_TYPE_SERVER) {
1860 id_list = server->local_list;
1862 router = sock->user_data;
1864 /* If the sender is backup router and ID is server (and we are not
1865 backup router) then switch the entry to global list. */
1866 if (server_entry->server_type == SILC_BACKUP_ROUTER &&
1867 id_type == SILC_ID_SERVER &&
1868 server->id_entry->server_type != SILC_BACKUP_ROUTER) {
1869 id_list = server->global_list;
1870 router_sock = server->router ? server->router->connection : sock;
1873 void *sender_id = silc_id_str2id(packet->src_id, packet->src_id_len,
1874 packet->src_id_type);
1875 router = silc_idlist_find_server_by_id(server->global_list,
1876 sender_id, TRUE, NULL);
1878 router = silc_idlist_find_server_by_id(server->local_list,
1879 sender_id, TRUE, NULL);
1880 silc_free(sender_id);
1884 id_list = server->global_list;
1888 case SILC_ID_CLIENT:
1890 SilcClientEntry entry;
1892 /* Check that we do not have this client already */
1893 entry = silc_idlist_find_client_by_id(server->global_list,
1894 id, server->server_type,
1897 entry = silc_idlist_find_client_by_id(server->local_list,
1898 id, server->server_type,
1901 SILC_LOG_DEBUG(("Ignoring client that we already have"));
1905 SILC_LOG_DEBUG(("New client id(%s) from [%s] %s",
1906 silc_id_render(id, SILC_ID_CLIENT),
1907 sock->type == SILC_SOCKET_TYPE_SERVER ?
1908 "Server" : "Router", sock->hostname));
1910 /* As a router we keep information of all global information in our
1911 global list. Cell wide information however is kept in the local
1913 entry = silc_idlist_add_client(id_list, NULL, NULL, NULL,
1916 SILC_LOG_ERROR(("Could not add new client to the ID Cache"));
1918 /* Inform the sender that the ID is not usable */
1919 silc_server_send_notify_signoff(server, sock, FALSE, id, NULL);
1922 entry->nickname = NULL;
1923 entry->data.status |= SILC_IDLIST_STATUS_REGISTERED;
1925 if (sock->type == SILC_SOCKET_TYPE_SERVER)
1926 server->stat.cell_clients++;
1927 server->stat.clients++;
1931 case SILC_ID_SERVER:
1933 SilcServerEntry entry;
1935 /* If the ID is mine, ignore it. */
1936 if (SILC_ID_SERVER_COMPARE(id, server->id)) {
1937 SILC_LOG_DEBUG(("Ignoring my own ID as new ID"));
1941 /* If the ID is the sender's ID, ignore it (we have it already) */
1942 if (SILC_ID_SERVER_COMPARE(id, router->id)) {
1943 SILC_LOG_DEBUG(("Ignoring sender's own ID"));
1947 /* Check that we do not have this server already */
1948 entry = silc_idlist_find_server_by_id(server->global_list,
1949 id, server->server_type,
1952 entry = silc_idlist_find_server_by_id(server->local_list,
1953 id, server->server_type,
1956 SILC_LOG_DEBUG(("Ignoring server that we already have"));
1960 SILC_LOG_DEBUG(("New server id(%s) from [%s] %s",
1961 silc_id_render(id, SILC_ID_SERVER),
1962 sock->type == SILC_SOCKET_TYPE_SERVER ?
1963 "Server" : "Router", sock->hostname));
1965 /* As a router we keep information of all global information in our
1966 global list. Cell wide information however is kept in the local
1968 entry = silc_idlist_add_server(id_list, NULL, 0, id, router,
1971 SILC_LOG_ERROR(("Could not add new server to the ID Cache"));
1974 entry->data.status |= SILC_IDLIST_STATUS_REGISTERED;
1976 if (sock->type == SILC_SOCKET_TYPE_SERVER)
1977 server->stat.cell_servers++;
1978 server->stat.servers++;
1982 case SILC_ID_CHANNEL:
1983 SILC_LOG_ERROR(("Channel cannot be registered with NEW_ID packet"));
1992 /* If the sender of this packet is server and we are router we need to
1993 broadcast this packet to other routers in the network. */
1994 if (broadcast && !server->standalone && server->server_type == SILC_ROUTER &&
1995 sock->type == SILC_SOCKET_TYPE_SERVER &&
1996 !(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
1997 SILC_LOG_DEBUG(("Broadcasting received New ID packet"));
1998 silc_server_packet_send(server, server->router->connection,
2000 packet->flags | SILC_PACKET_FLAG_BROADCAST,
2001 buffer->data, buffer->len, FALSE);
2002 silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
2003 packet->type, packet->flags,
2004 packet->buffer->data, packet->buffer->len,
2009 silc_id_payload_free(idp);
2013 /* Processes incoming New ID packet. New ID Payload is used to distribute
2014 information about newly registered clients and servers. */
2016 void silc_server_new_id(SilcServer server, SilcSocketConnection sock,
2017 SilcPacketContext *packet)
2019 silc_server_new_id_real(server, sock, packet, TRUE);
2022 /* Receoved New Id List packet, list of New ID payloads inside one
2023 packet. Process the New ID payloads one by one. */
2025 void silc_server_new_id_list(SilcServer server, SilcSocketConnection sock,
2026 SilcPacketContext *packet)
2028 SilcPacketContext *new_id;
2032 SILC_LOG_DEBUG(("Processing New ID List"));
2034 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
2035 packet->src_id_type != SILC_ID_SERVER)
2038 /* If the sender of this packet is server and we are router we need to
2039 broadcast this packet to other routers in the network. Broadcast
2040 this list packet instead of multiple New ID packets. */
2041 if (!server->standalone && server->server_type == SILC_ROUTER &&
2042 sock->type == SILC_SOCKET_TYPE_SERVER &&
2043 !(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
2044 SILC_LOG_DEBUG(("Broadcasting received New ID List packet"));
2045 silc_server_packet_send(server, server->router->connection,
2047 packet->flags | SILC_PACKET_FLAG_BROADCAST,
2048 packet->buffer->data, packet->buffer->len, FALSE);
2049 silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
2050 packet->type, packet->flags,
2051 packet->buffer->data, packet->buffer->len,
2055 /* Make copy of the original packet context, except for the actual
2056 data buffer, which we will here now fetch from the original buffer. */
2057 new_id = silc_packet_context_alloc();
2058 new_id->type = SILC_PACKET_NEW_ID;
2059 new_id->flags = packet->flags;
2060 new_id->src_id = packet->src_id;
2061 new_id->src_id_len = packet->src_id_len;
2062 new_id->src_id_type = packet->src_id_type;
2063 new_id->dst_id = packet->dst_id;
2064 new_id->dst_id_len = packet->dst_id_len;
2065 new_id->dst_id_type = packet->dst_id_type;
2067 idp = silc_buffer_alloc(256);
2068 new_id->buffer = idp;
2070 while (packet->buffer->len) {
2071 SILC_GET16_MSB(id_len, packet->buffer->data + 2);
2072 if ((id_len > packet->buffer->len) ||
2073 (id_len > idp->truelen))
2076 silc_buffer_pull_tail(idp, 4 + id_len);
2077 silc_buffer_put(idp, packet->buffer->data, 4 + id_len);
2079 /* Process the New ID */
2080 silc_server_new_id_real(server, sock, new_id, FALSE);
2082 silc_buffer_push_tail(idp, 4 + id_len);
2083 silc_buffer_pull(packet->buffer, 4 + id_len);
2086 silc_buffer_free(idp);
2090 /* Received New Channel packet. Information about new channels in the
2091 network are distributed using this packet. Save the information about
2092 the new channel. This usually comes from router but also normal server
2093 can send this to notify channels it has when it connects to us. */
2095 void silc_server_new_channel(SilcServer server,
2096 SilcSocketConnection sock,
2097 SilcPacketContext *packet)
2099 SilcChannelPayload payload;
2100 SilcChannelID *channel_id;
2106 SilcServerEntry server_entry;
2107 SilcChannelEntry channel;
2109 SILC_LOG_DEBUG(("Processing New Channel"));
2111 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
2112 packet->src_id_type != SILC_ID_SERVER ||
2113 server->server_type == SILC_SERVER)
2116 /* Parse the channel payload */
2117 payload = silc_channel_payload_parse(packet->buffer->data,
2118 packet->buffer->len);
2122 /* Get the channel ID */
2123 channel_id = silc_channel_get_id_parse(payload);
2125 silc_channel_payload_free(payload);
2129 channel_name = silc_channel_get_name(payload, &name_len);
2131 channel_name[255] = '\0';
2133 id = silc_channel_get_id(payload, &id_len);
2135 server_entry = (SilcServerEntry)sock->user_data;
2137 if (sock->type == SILC_SOCKET_TYPE_ROUTER) {
2138 /* Add the channel to global list as it is coming from router. It
2139 cannot be our own channel as it is coming from router. */
2141 /* Check that we don't already have this channel */
2142 channel = silc_idlist_find_channel_by_name(server->local_list,
2143 channel_name, NULL);
2145 channel = silc_idlist_find_channel_by_name(server->global_list,
2146 channel_name, NULL);
2148 SILC_LOG_DEBUG(("New channel id(%s) from [Router] %s",
2149 silc_id_render(channel_id, SILC_ID_CHANNEL),
2152 silc_idlist_add_channel(server->global_list, strdup(channel_name),
2153 0, channel_id, sock->user_data, NULL, NULL);
2154 server->stat.channels++;
2157 /* The channel is coming from our server, thus it is in our cell
2158 we will add it to our local list. */
2161 SILC_LOG_DEBUG(("Channel id(%s) from [Server] %s",
2162 silc_id_render(channel_id, SILC_ID_CHANNEL),
2165 /* Check that we don't already have this channel */
2166 channel = silc_idlist_find_channel_by_name(server->local_list,
2167 channel_name, NULL);
2169 channel = silc_idlist_find_channel_by_name(server->global_list,
2170 channel_name, NULL);
2172 /* If the channel does not exist, then create it. This creates a new
2173 key to the channel as well that we will send to the server. */
2175 /* The protocol says that the Channel ID's IP address must be based
2176 on the router's IP address. Check whether the ID is based in our
2177 IP and if it is not then create a new ID and enforce the server
2178 to switch the ID. */
2179 if (server_entry->server_type != SILC_BACKUP_ROUTER &&
2180 !SILC_ID_COMPARE(channel_id, server->id, server->id->ip.data_len)) {
2182 SILC_LOG_DEBUG(("Forcing the server to change Channel ID"));
2184 if (silc_id_create_channel_id(server, server->id, server->rng, &tmp)) {
2185 silc_server_send_notify_channel_change(server, sock, FALSE,
2187 silc_free(channel_id);
2192 /* Create the channel with the provided Channel ID */
2193 channel = silc_server_create_new_channel_with_id(server, NULL, NULL,
2197 silc_channel_payload_free(payload);
2198 silc_free(channel_id);
2202 /* Get the mode and set it to the channel */
2203 channel->mode = silc_channel_get_mode(payload);
2205 /* Send the new channel key to the server */
2206 chk = silc_channel_key_payload_encode(id_len, id,
2207 strlen(channel->channel_key->
2209 channel->channel_key->cipher->name,
2210 channel->key_len / 8,
2212 silc_server_packet_send(server, sock, SILC_PACKET_CHANNEL_KEY, 0,
2213 chk->data, chk->len, FALSE);
2214 silc_buffer_free(chk);
2217 /* The channel exist by that name, check whether the ID's match.
2218 If they don't then we'll force the server to use the ID we have.
2219 We also create a new key for the channel. */
2220 SilcBuffer users = NULL, users_modes = NULL;
2222 if (!SILC_ID_CHANNEL_COMPARE(channel_id, channel->id)) {
2223 /* They don't match, send CHANNEL_CHANGE notify to the server to
2224 force the ID change. */
2225 SILC_LOG_DEBUG(("Forcing the server to change Channel ID"));
2226 silc_server_send_notify_channel_change(server, sock, FALSE,
2227 channel_id, channel->id);
2230 /* If the mode is different from what we have then enforce the
2232 mode = silc_channel_get_mode(payload);
2233 if (channel->mode != mode) {
2234 SILC_LOG_DEBUG(("Forcing the server to change channel mode"));
2235 silc_server_send_notify_cmode(server, sock, FALSE, channel,
2236 channel->mode, server->id,
2238 channel->cipher, channel->hmac_name);
2241 /* Create new key for the channel and send it to the server and
2242 everybody else possibly on the channel. */
2244 if (!(channel->mode & SILC_CHANNEL_MODE_PRIVKEY)) {
2245 if (!silc_server_create_channel_key(server, channel, 0))
2248 /* Send to the channel */
2249 silc_server_send_channel_key(server, sock, channel, FALSE);
2250 id = silc_id_id2str(channel->id, SILC_ID_CHANNEL);
2251 id_len = SILC_ID_CHANNEL_LEN;
2253 /* Send to the server */
2254 chk = silc_channel_key_payload_encode(id_len, id,
2255 strlen(channel->channel_key->
2257 channel->channel_key->
2259 channel->key_len / 8,
2261 silc_server_packet_send(server, sock, SILC_PACKET_CHANNEL_KEY, 0,
2262 chk->data, chk->len, FALSE);
2263 silc_buffer_free(chk);
2267 silc_free(channel_id);
2269 /* Since the channel is coming from server and we also know about it
2270 then send the JOIN notify to the server so that it see's our
2271 users on the channel "joining" the channel. */
2272 silc_server_announce_get_channel_users(server, channel, &users,
2275 silc_buffer_push(users, users->data - users->head);
2276 silc_server_packet_send(server, sock,
2277 SILC_PACKET_NOTIFY, SILC_PACKET_FLAG_LIST,
2278 users->data, users->len, FALSE);
2279 silc_buffer_free(users);
2282 silc_buffer_push(users_modes, users_modes->data - users_modes->head);
2283 silc_server_packet_send_dest(server, sock,
2284 SILC_PACKET_NOTIFY, SILC_PACKET_FLAG_LIST,
2285 channel->id, SILC_ID_CHANNEL,
2287 users_modes->len, FALSE);
2288 silc_buffer_free(users_modes);
2293 silc_channel_payload_free(payload);
2296 /* Received New Channel List packet, list of New Channel List payloads inside
2297 one packet. Process the New Channel payloads one by one. */
2299 void silc_server_new_channel_list(SilcServer server,
2300 SilcSocketConnection sock,
2301 SilcPacketContext *packet)
2303 SilcPacketContext *new;
2307 SILC_LOG_DEBUG(("Processing New Channel List"));
2309 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
2310 packet->src_id_type != SILC_ID_SERVER ||
2311 server->server_type == SILC_SERVER)
2314 /* If the sender of this packet is server and we are router we need to
2315 broadcast this packet to other routers in the network. Broadcast
2316 this list packet instead of multiple New Channel packets. */
2317 if (!server->standalone && server->server_type == SILC_ROUTER &&
2318 sock->type == SILC_SOCKET_TYPE_SERVER &&
2319 !(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
2320 SILC_LOG_DEBUG(("Broadcasting received New Channel List packet"));
2321 silc_server_packet_send(server, server->router->connection,
2323 packet->flags | SILC_PACKET_FLAG_BROADCAST,
2324 packet->buffer->data, packet->buffer->len, FALSE);
2325 silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
2326 packet->type, packet->flags,
2327 packet->buffer->data, packet->buffer->len,
2331 /* Make copy of the original packet context, except for the actual
2332 data buffer, which we will here now fetch from the original buffer. */
2333 new = silc_packet_context_alloc();
2334 new->type = SILC_PACKET_NEW_CHANNEL;
2335 new->flags = packet->flags;
2336 new->src_id = packet->src_id;
2337 new->src_id_len = packet->src_id_len;
2338 new->src_id_type = packet->src_id_type;
2339 new->dst_id = packet->dst_id;
2340 new->dst_id_len = packet->dst_id_len;
2341 new->dst_id_type = packet->dst_id_type;
2343 buffer = silc_buffer_alloc(512);
2344 new->buffer = buffer;
2346 while (packet->buffer->len) {
2347 SILC_GET16_MSB(len1, packet->buffer->data);
2348 if ((len1 > packet->buffer->len) ||
2349 (len1 > buffer->truelen))
2352 SILC_GET16_MSB(len2, packet->buffer->data + 2 + len1);
2353 if ((len2 > packet->buffer->len) ||
2354 (len2 > buffer->truelen))
2357 silc_buffer_pull_tail(buffer, 8 + len1 + len2);
2358 silc_buffer_put(buffer, packet->buffer->data, 8 + len1 + len2);
2360 /* Process the New Channel */
2361 silc_server_new_channel(server, sock, new);
2363 silc_buffer_push_tail(buffer, 8 + len1 + len2);
2364 silc_buffer_pull(packet->buffer, 8 + len1 + len2);
2367 silc_buffer_free(buffer);
2371 /* Received key agreement packet. This packet is never for us. It is to
2372 the client in the packet's destination ID. Sending of this sort of packet
2373 equals sending private message, ie. it is sent point to point from
2374 one client to another. */
2376 void silc_server_key_agreement(SilcServer server,
2377 SilcSocketConnection sock,
2378 SilcPacketContext *packet)
2380 SilcSocketConnection dst_sock;
2381 SilcIDListData idata;
2383 SILC_LOG_DEBUG(("Start"));
2385 if (packet->src_id_type != SILC_ID_CLIENT ||
2386 packet->dst_id_type != SILC_ID_CLIENT)
2389 if (!packet->dst_id)
2392 /* Get the route to the client */
2393 dst_sock = silc_server_get_client_route(server, packet->dst_id,
2394 packet->dst_id_len, NULL, &idata);
2398 /* Relay the packet */
2399 silc_server_relay_packet(server, dst_sock, idata->send_key,
2400 idata->hmac_send, idata->psn_send++,
2404 /* Received connection auth request packet that is used during connection
2405 phase to resolve the mandatory authentication method. This packet can
2406 actually be received at anytime but usually it is used only during
2407 the connection authentication phase. Now, protocol says that this packet
2408 can come from client or server, however, we support only this coming
2409 from client and expect that server always knows what authentication
2412 void silc_server_connection_auth_request(SilcServer server,
2413 SilcSocketConnection sock,
2414 SilcPacketContext *packet)
2416 SilcServerConfigSectionClientConnection *client = NULL;
2419 SilcAuthMethod auth_meth;
2421 SILC_LOG_DEBUG(("Start"));
2423 if (packet->src_id_type && packet->src_id_type != SILC_ID_CLIENT)
2426 /* Parse the payload */
2427 ret = silc_buffer_unformat(packet->buffer,
2428 SILC_STR_UI_SHORT(&conn_type),
2429 SILC_STR_UI_SHORT(NULL),
2434 if (conn_type != SILC_SOCKET_TYPE_CLIENT)
2437 /* Get the authentication method for the client */
2438 auth_meth = SILC_AUTH_NONE;
2439 port = server->sockets[server->sock]->port; /* Listenning port */
2440 client = silc_server_config_find_client_conn(server->config,
2444 client = silc_server_config_find_client_conn(server->config,
2448 auth_meth = client->auth_meth;
2450 /* Send it back to the client */
2451 silc_server_send_connection_auth_request(server, sock,
2456 /* Received REKEY packet. The sender of the packet wants to regenerate
2457 its session keys. This starts the REKEY protocol. */
2459 void silc_server_rekey(SilcServer server,
2460 SilcSocketConnection sock,
2461 SilcPacketContext *packet)
2463 SilcProtocol protocol;
2464 SilcServerRekeyInternalContext *proto_ctx;
2465 SilcIDListData idata = (SilcIDListData)sock->user_data;
2467 SILC_LOG_DEBUG(("Start"));
2469 /* Allocate internal protocol context. This is sent as context
2471 proto_ctx = silc_calloc(1, sizeof(*proto_ctx));
2472 proto_ctx->server = (void *)server;
2473 proto_ctx->sock = sock;
2474 proto_ctx->responder = TRUE;
2475 proto_ctx->pfs = idata->rekey->pfs;
2477 /* Perform rekey protocol. Will call the final callback after the
2478 protocol is over. */
2479 silc_protocol_alloc(SILC_PROTOCOL_SERVER_REKEY,
2480 &protocol, proto_ctx, silc_server_rekey_final);
2481 sock->protocol = protocol;
2483 if (proto_ctx->pfs == FALSE)
2484 /* Run the protocol */
2485 silc_protocol_execute(protocol, server->schedule, 0, 0);
2488 /* Received file transger packet. This packet is never for us. It is to
2489 the client in the packet's destination ID. Sending of this sort of packet
2490 equals sending private message, ie. it is sent point to point from
2491 one client to another. */
2493 void silc_server_ftp(SilcServer server,
2494 SilcSocketConnection sock,
2495 SilcPacketContext *packet)
2497 SilcSocketConnection dst_sock;
2498 SilcIDListData idata;
2500 SILC_LOG_DEBUG(("Start"));
2502 if (packet->src_id_type != SILC_ID_CLIENT ||
2503 packet->dst_id_type != SILC_ID_CLIENT)
2506 if (!packet->dst_id)
2509 /* Get the route to the client */
2510 dst_sock = silc_server_get_client_route(server, packet->dst_id,
2511 packet->dst_id_len, NULL, &idata);
2515 /* Relay the packet */
2516 silc_server_relay_packet(server, dst_sock, idata->send_key,
2517 idata->hmac_send, idata->psn_send++,