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 SilcIDCacheEntry id_cache = NULL;
1448 char *username = NULL, *realname = NULL, *id_string;
1451 char *hostname, *nickname;
1454 SILC_LOG_DEBUG(("Creating new client"));
1456 if (sock->type != SILC_SOCKET_TYPE_CLIENT)
1459 /* Take client entry */
1460 client = (SilcClientEntry)sock->user_data;
1461 idata = (SilcIDListData)client;
1463 /* Remove the old cache entry. */
1464 if (!silc_idcache_del_by_context(server->local_list->clients, client)) {
1465 SILC_LOG_ERROR(("Lost client's cache entry - bad thing"));
1466 silc_server_disconnect_remote(server, sock, "Server closed connection: "
1471 /* Parse incoming packet */
1472 ret = silc_buffer_unformat(buffer,
1473 SILC_STR_UI16_STRING_ALLOC(&username),
1474 SILC_STR_UI16_STRING_ALLOC(&realname),
1478 silc_free(username);
1480 silc_free(realname);
1481 silc_server_disconnect_remote(server, sock, "Server closed connection: "
1482 "Incomplete client information");
1487 silc_free(username);
1489 silc_free(realname);
1490 silc_server_disconnect_remote(server, sock, "Server closed connection: "
1491 "Incomplete client information");
1495 if (strlen(username) > 128)
1496 username[127] = '\0';
1498 nickname = strdup(username);
1500 /* Make sanity checks for the hostname of the client. If the hostname
1501 is provided in the `username' check that it is the same than the
1502 resolved hostname, or if not resolved the hostname that appears in
1503 the client's public key. If the hostname is not present then put
1504 it from the resolved name or from the public key. */
1505 if (strchr(username, '@')) {
1506 SilcPublicKeyIdentifier pident;
1507 int tlen = strcspn(username, "@");
1508 char *phostname = NULL;
1510 hostname = silc_calloc((strlen(username) - tlen) + 1, sizeof(char));
1511 memcpy(hostname, username + tlen + 1, strlen(username) - tlen - 1);
1513 if (strcmp(sock->hostname, sock->ip) &&
1514 strcmp(sock->hostname, hostname)) {
1515 silc_free(username);
1516 silc_free(hostname);
1518 silc_free(realname);
1519 silc_server_disconnect_remote(server, sock,
1520 "Server closed connection: "
1521 "Incomplete client information");
1525 pident = silc_pkcs_decode_identifier(client->data.public_key->identifier);
1527 phostname = strdup(pident->host);
1528 silc_pkcs_free_identifier(pident);
1531 if (!strcmp(sock->hostname, sock->ip) &&
1532 phostname && strcmp(phostname, hostname)) {
1533 silc_free(username);
1534 silc_free(hostname);
1536 silc_free(phostname);
1538 silc_free(realname);
1539 silc_server_disconnect_remote(server, sock,
1540 "Server closed connection: "
1541 "Incomplete client information");
1546 silc_free(phostname);
1548 /* The hostname is not present, add it. */
1550 /* XXX For now we cannot take the host name from the public key since
1551 they are not trusted or we cannot verify them as trusted. Just take
1552 what the resolved name or address is. */
1554 if (strcmp(sock->hostname, sock->ip)) {
1556 newusername = silc_calloc(strlen(username) +
1557 strlen(sock->hostname) + 2,
1558 sizeof(*newusername));
1559 strncat(newusername, username, strlen(username));
1560 strncat(newusername, "@", 1);
1561 strncat(newusername, sock->hostname, strlen(sock->hostname));
1562 silc_free(username);
1563 username = newusername;
1566 SilcPublicKeyIdentifier pident =
1567 silc_pkcs_decode_identifier(client->data.public_key->identifier);
1570 newusername = silc_calloc(strlen(username) +
1571 strlen(pident->host) + 2,
1572 sizeof(*newusername));
1573 strncat(newusername, username, strlen(username));
1574 strncat(newusername, "@", 1);
1575 strncat(newusername, pident->host, strlen(pident->host));
1576 silc_free(username);
1577 username = newusername;
1578 silc_pkcs_free_identifier(pident);
1584 /* Create Client ID */
1585 while (!silc_id_create_client_id(server, server->id, server->rng,
1586 server->md5hash, nickname, &client_id)) {
1588 snprintf(&nickname[strlen(nickname) - 1], 1, "%d", nickfail);
1591 /* Update client entry */
1592 idata->status |= SILC_IDLIST_STATUS_REGISTERED;
1593 client->nickname = nickname;
1594 client->username = username;
1595 client->userinfo = realname ? realname : strdup(" ");
1596 client->id = client_id;
1597 id_len = silc_id_get_len(client_id, SILC_ID_CLIENT);
1599 /* Add the client again to the ID cache */
1600 silc_idcache_add(server->local_list->clients, client->nickname,
1601 client_id, client, FALSE);
1603 /* Notify our router about new client on the SILC network */
1604 if (!server->standalone)
1605 silc_server_send_new_id(server, (SilcSocketConnection)
1606 server->router->connection,
1607 server->server_type == SILC_ROUTER ? TRUE : FALSE,
1608 client->id, SILC_ID_CLIENT, id_len);
1610 /* Send the new client ID to the client. */
1611 id_string = silc_id_id2str(client->id, SILC_ID_CLIENT);
1612 reply = silc_buffer_alloc(2 + 2 + id_len);
1613 silc_buffer_pull_tail(reply, SILC_BUFFER_END(reply));
1614 silc_buffer_format(reply,
1615 SILC_STR_UI_SHORT(SILC_ID_CLIENT),
1616 SILC_STR_UI_SHORT(id_len),
1617 SILC_STR_UI_XNSTRING(id_string, id_len),
1619 silc_server_packet_send(server, sock, SILC_PACKET_NEW_ID, 0,
1620 reply->data, reply->len, FALSE);
1621 silc_free(id_string);
1622 silc_buffer_free(reply);
1624 /* Send some nice info to the client */
1625 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1626 ("Welcome to the SILC Network %s",
1628 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1629 ("Your host is %s, running version %s",
1630 server->config->server_info->server_name,
1632 if (server->server_type == SILC_ROUTER) {
1633 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1634 ("There are %d clients on %d servers in SILC "
1635 "Network", server->stat.clients,
1636 server->stat.servers + 1));
1637 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1638 ("There are %d clients on %d server in our cell",
1639 server->stat.cell_clients,
1640 server->stat.cell_servers + 1));
1641 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1642 ("I have %d clients, %d channels, %d servers and "
1644 server->stat.my_clients,
1645 server->stat.my_channels,
1646 server->stat.my_servers,
1647 server->stat.my_routers));
1648 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1649 ("%d server operators and %d router operators "
1651 server->stat.my_server_ops,
1652 server->stat.my_router_ops));
1654 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1655 ("I have %d clients and %d channels formed",
1656 server->stat.my_clients,
1657 server->stat.my_channels));
1658 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1659 ("%d operators online",
1660 server->stat.my_server_ops));
1662 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1663 ("Your connection is secured with %s cipher, "
1664 "key length %d bits",
1665 idata->send_key->cipher->name,
1666 idata->send_key->cipher->key_len));
1667 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1668 ("Your current nickname is %s",
1672 silc_server_send_motd(server, sock);
1677 /* Create new server. This processes received New Server packet and
1678 saves the received Server ID. The server is our locally connected
1679 server thus we save all the information and save it to local list.
1680 This funtion can be used by both normal server and router server.
1681 If normal server uses this it means that its router has connected
1682 to the server. If router uses this it means that one of the cell's
1683 servers is connected to the router. */
1685 SilcServerEntry silc_server_new_server(SilcServer server,
1686 SilcSocketConnection sock,
1687 SilcPacketContext *packet)
1689 SilcBuffer buffer = packet->buffer;
1690 SilcServerEntry new_server, server_entry;
1691 SilcServerID *server_id;
1692 SilcIDListData idata;
1693 unsigned char *server_name, *id_string;
1694 uint16 id_len, name_len;
1698 SILC_LOG_DEBUG(("Creating new server"));
1700 if (sock->type != SILC_SOCKET_TYPE_SERVER &&
1701 sock->type != SILC_SOCKET_TYPE_ROUTER)
1704 /* Take server entry */
1705 new_server = (SilcServerEntry)sock->user_data;
1706 idata = (SilcIDListData)new_server;
1708 /* Remove the old cache entry */
1709 if (!silc_idcache_del_by_context(server->local_list->servers, new_server)) {
1710 silc_idcache_del_by_context(server->global_list->servers, new_server);
1714 /* Parse the incoming packet */
1715 ret = silc_buffer_unformat(buffer,
1716 SILC_STR_UI16_NSTRING_ALLOC(&id_string, &id_len),
1717 SILC_STR_UI16_NSTRING_ALLOC(&server_name,
1722 silc_free(id_string);
1724 silc_free(server_name);
1728 if (id_len > buffer->len) {
1729 silc_free(id_string);
1730 silc_free(server_name);
1735 server_name[255] = '\0';
1738 server_id = silc_id_str2id(id_string, id_len, SILC_ID_SERVER);
1740 silc_free(id_string);
1741 silc_free(server_name);
1744 silc_free(id_string);
1746 /* Check that we do not have this ID already */
1747 server_entry = silc_idlist_find_server_by_id(server->local_list,
1748 server_id, TRUE, NULL);
1750 silc_idcache_del_by_context(server->local_list->servers, server_entry);
1752 server_entry = silc_idlist_find_server_by_id(server->global_list,
1753 server_id, TRUE, NULL);
1755 silc_idcache_del_by_context(server->global_list->servers, server_entry);
1758 /* Update server entry */
1759 idata->status |= SILC_IDLIST_STATUS_REGISTERED;
1760 new_server->server_name = server_name;
1761 new_server->id = server_id;
1763 SILC_LOG_DEBUG(("New server id(%s)",
1764 silc_id_render(server_id, SILC_ID_SERVER)));
1766 /* Add again the entry to the ID cache. */
1767 silc_idcache_add(local ? server->local_list->servers :
1768 server->global_list->servers, server_name, server_id,
1771 /* Distribute the information about new server in the SILC network
1772 to our router. If we are normal server we won't send anything
1773 since this connection must be our router connection. */
1774 if (server->server_type == SILC_ROUTER && !server->standalone &&
1775 server->router->connection != sock)
1776 silc_server_send_new_id(server, server->router->connection,
1777 TRUE, new_server->id, SILC_ID_SERVER,
1778 silc_id_get_len(server_id, SILC_ID_SERVER));
1780 if (server->server_type == SILC_ROUTER)
1781 server->stat.cell_servers++;
1783 /* Check whether this router connection has been replaced by an
1784 backup router. If it has been then we'll disable the server and will
1785 ignore everything it will send until the backup router resuming
1786 protocol has been completed. */
1787 if (sock->type == SILC_SOCKET_TYPE_ROUTER &&
1788 silc_server_backup_replaced_get(server, server_id, NULL)) {
1789 /* Send packet to the server indicating that it cannot use this
1790 connection as it has been replaced by backup router. */
1791 SilcBuffer packet = silc_buffer_alloc(2);
1792 silc_buffer_pull_tail(packet, SILC_BUFFER_END(packet));
1793 silc_buffer_format(packet,
1794 SILC_STR_UI_CHAR(SILC_SERVER_BACKUP_REPLACED),
1795 SILC_STR_UI_CHAR(0),
1797 silc_server_packet_send(server, sock,
1798 SILC_PACKET_RESUME_ROUTER, 0,
1799 packet->data, packet->len, TRUE);
1800 silc_buffer_free(packet);
1802 /* Mark the router disabled. The data sent earlier will go but nothing
1803 after this does not go to this connection. */
1804 idata->status |= SILC_IDLIST_STATUS_DISABLED;
1806 /* If it is router announce our stuff to it. */
1807 if (sock->type == SILC_SOCKET_TYPE_ROUTER &&
1808 server->server_type == SILC_ROUTER) {
1809 silc_server_announce_servers(server, FALSE, 0, sock);
1810 silc_server_announce_clients(server, 0, sock);
1811 silc_server_announce_channels(server, 0, sock);
1818 /* Processes incoming New ID packet. New ID Payload is used to distribute
1819 information about newly registered clients and servers. */
1821 static void silc_server_new_id_real(SilcServer server,
1822 SilcSocketConnection sock,
1823 SilcPacketContext *packet,
1826 SilcBuffer buffer = packet->buffer;
1828 SilcServerEntry router, server_entry;
1829 SilcSocketConnection router_sock;
1834 SILC_LOG_DEBUG(("Processing new ID"));
1836 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
1837 server->server_type == SILC_SERVER ||
1838 packet->src_id_type != SILC_ID_SERVER)
1841 idp = silc_id_payload_parse(buffer->data, buffer->len);
1845 id_type = silc_id_payload_get_type(idp);
1847 /* Normal server cannot have other normal server connections */
1848 server_entry = (SilcServerEntry)sock->user_data;
1849 if (id_type == SILC_ID_SERVER && sock->type == SILC_SOCKET_TYPE_SERVER &&
1850 server_entry->server_type == SILC_SERVER)
1853 id = silc_id_payload_get_id(idp);
1857 /* If the packet is coming from server then use the sender as the
1858 origin of the the packet. If it came from router then check the real
1859 sender of the packet and use that as the origin. */
1860 if (sock->type == SILC_SOCKET_TYPE_SERVER) {
1861 id_list = server->local_list;
1863 router = sock->user_data;
1865 /* If the sender is backup router and ID is server (and we are not
1866 backup router) then switch the entry to global list. */
1867 if (server_entry->server_type == SILC_BACKUP_ROUTER &&
1868 id_type == SILC_ID_SERVER &&
1869 server->id_entry->server_type != SILC_BACKUP_ROUTER) {
1870 id_list = server->global_list;
1871 router_sock = server->router ? server->router->connection : sock;
1874 void *sender_id = silc_id_str2id(packet->src_id, packet->src_id_len,
1875 packet->src_id_type);
1876 router = silc_idlist_find_server_by_id(server->global_list,
1877 sender_id, TRUE, NULL);
1879 router = silc_idlist_find_server_by_id(server->local_list,
1880 sender_id, TRUE, NULL);
1881 silc_free(sender_id);
1885 id_list = server->global_list;
1889 case SILC_ID_CLIENT:
1891 SilcClientEntry entry;
1893 /* Check that we do not have this client already */
1894 entry = silc_idlist_find_client_by_id(server->global_list,
1895 id, server->server_type,
1898 entry = silc_idlist_find_client_by_id(server->local_list,
1899 id, server->server_type,
1902 SILC_LOG_DEBUG(("Ignoring client that we already have"));
1906 SILC_LOG_DEBUG(("New client id(%s) from [%s] %s",
1907 silc_id_render(id, SILC_ID_CLIENT),
1908 sock->type == SILC_SOCKET_TYPE_SERVER ?
1909 "Server" : "Router", sock->hostname));
1911 /* As a router we keep information of all global information in our
1912 global list. Cell wide information however is kept in the local
1914 entry = silc_idlist_add_client(id_list, NULL, NULL, NULL,
1917 SILC_LOG_ERROR(("Could not add new client to the ID Cache"));
1919 /* Inform the sender that the ID is not usable */
1920 silc_server_send_notify_signoff(server, sock, FALSE, id, NULL);
1923 entry->nickname = NULL;
1924 entry->data.status |= SILC_IDLIST_STATUS_REGISTERED;
1926 if (sock->type == SILC_SOCKET_TYPE_SERVER)
1927 server->stat.cell_clients++;
1928 server->stat.clients++;
1932 case SILC_ID_SERVER:
1934 SilcServerEntry entry;
1936 /* If the ID is mine, ignore it. */
1937 if (SILC_ID_SERVER_COMPARE(id, server->id)) {
1938 SILC_LOG_DEBUG(("Ignoring my own ID as new ID"));
1942 /* If the ID is the sender's ID, ignore it (we have it already) */
1943 if (SILC_ID_SERVER_COMPARE(id, router->id)) {
1944 SILC_LOG_DEBUG(("Ignoring sender's own ID"));
1948 /* Check that we do not have this server already */
1949 entry = silc_idlist_find_server_by_id(server->global_list,
1950 id, server->server_type,
1953 entry = silc_idlist_find_server_by_id(server->local_list,
1954 id, server->server_type,
1957 SILC_LOG_DEBUG(("Ignoring server that we already have"));
1961 SILC_LOG_DEBUG(("New server id(%s) from [%s] %s",
1962 silc_id_render(id, SILC_ID_SERVER),
1963 sock->type == SILC_SOCKET_TYPE_SERVER ?
1964 "Server" : "Router", sock->hostname));
1966 /* As a router we keep information of all global information in our
1967 global list. Cell wide information however is kept in the local
1969 entry = silc_idlist_add_server(id_list, NULL, 0, id, router,
1972 SILC_LOG_ERROR(("Could not add new server to the ID Cache"));
1975 entry->data.status |= SILC_IDLIST_STATUS_REGISTERED;
1977 if (sock->type == SILC_SOCKET_TYPE_SERVER)
1978 server->stat.cell_servers++;
1979 server->stat.servers++;
1983 case SILC_ID_CHANNEL:
1984 SILC_LOG_ERROR(("Channel cannot be registered with NEW_ID packet"));
1993 /* If the sender of this packet is server and we are router we need to
1994 broadcast this packet to other routers in the network. */
1995 if (broadcast && !server->standalone && server->server_type == SILC_ROUTER &&
1996 sock->type == SILC_SOCKET_TYPE_SERVER &&
1997 !(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
1998 SILC_LOG_DEBUG(("Broadcasting received New ID packet"));
1999 silc_server_packet_send(server, server->router->connection,
2001 packet->flags | SILC_PACKET_FLAG_BROADCAST,
2002 buffer->data, buffer->len, FALSE);
2003 silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
2004 packet->type, packet->flags,
2005 packet->buffer->data, packet->buffer->len,
2010 silc_id_payload_free(idp);
2014 /* Processes incoming New ID packet. New ID Payload is used to distribute
2015 information about newly registered clients and servers. */
2017 void silc_server_new_id(SilcServer server, SilcSocketConnection sock,
2018 SilcPacketContext *packet)
2020 silc_server_new_id_real(server, sock, packet, TRUE);
2023 /* Receoved New Id List packet, list of New ID payloads inside one
2024 packet. Process the New ID payloads one by one. */
2026 void silc_server_new_id_list(SilcServer server, SilcSocketConnection sock,
2027 SilcPacketContext *packet)
2029 SilcPacketContext *new_id;
2033 SILC_LOG_DEBUG(("Processing New ID List"));
2035 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
2036 packet->src_id_type != SILC_ID_SERVER)
2039 /* If the sender of this packet is server and we are router we need to
2040 broadcast this packet to other routers in the network. Broadcast
2041 this list packet instead of multiple New ID packets. */
2042 if (!server->standalone && server->server_type == SILC_ROUTER &&
2043 sock->type == SILC_SOCKET_TYPE_SERVER &&
2044 !(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
2045 SILC_LOG_DEBUG(("Broadcasting received New ID List packet"));
2046 silc_server_packet_send(server, server->router->connection,
2048 packet->flags | SILC_PACKET_FLAG_BROADCAST,
2049 packet->buffer->data, packet->buffer->len, FALSE);
2050 silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
2051 packet->type, packet->flags,
2052 packet->buffer->data, packet->buffer->len,
2056 /* Make copy of the original packet context, except for the actual
2057 data buffer, which we will here now fetch from the original buffer. */
2058 new_id = silc_packet_context_alloc();
2059 new_id->type = SILC_PACKET_NEW_ID;
2060 new_id->flags = packet->flags;
2061 new_id->src_id = packet->src_id;
2062 new_id->src_id_len = packet->src_id_len;
2063 new_id->src_id_type = packet->src_id_type;
2064 new_id->dst_id = packet->dst_id;
2065 new_id->dst_id_len = packet->dst_id_len;
2066 new_id->dst_id_type = packet->dst_id_type;
2068 idp = silc_buffer_alloc(256);
2069 new_id->buffer = idp;
2071 while (packet->buffer->len) {
2072 SILC_GET16_MSB(id_len, packet->buffer->data + 2);
2073 if ((id_len > packet->buffer->len) ||
2074 (id_len > idp->truelen))
2077 silc_buffer_pull_tail(idp, 4 + id_len);
2078 silc_buffer_put(idp, packet->buffer->data, 4 + id_len);
2080 /* Process the New ID */
2081 silc_server_new_id_real(server, sock, new_id, FALSE);
2083 silc_buffer_push_tail(idp, 4 + id_len);
2084 silc_buffer_pull(packet->buffer, 4 + id_len);
2087 silc_buffer_free(idp);
2091 /* Received New Channel packet. Information about new channels in the
2092 network are distributed using this packet. Save the information about
2093 the new channel. This usually comes from router but also normal server
2094 can send this to notify channels it has when it connects to us. */
2096 void silc_server_new_channel(SilcServer server,
2097 SilcSocketConnection sock,
2098 SilcPacketContext *packet)
2100 SilcChannelPayload payload;
2101 SilcChannelID *channel_id;
2107 SilcServerEntry server_entry;
2108 SilcChannelEntry channel;
2110 SILC_LOG_DEBUG(("Processing New Channel"));
2112 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
2113 packet->src_id_type != SILC_ID_SERVER ||
2114 server->server_type == SILC_SERVER)
2117 /* Parse the channel payload */
2118 payload = silc_channel_payload_parse(packet->buffer->data,
2119 packet->buffer->len);
2123 /* Get the channel ID */
2124 channel_id = silc_channel_get_id_parse(payload);
2126 silc_channel_payload_free(payload);
2130 channel_name = silc_channel_get_name(payload, &name_len);
2132 channel_name[255] = '\0';
2134 id = silc_channel_get_id(payload, &id_len);
2136 server_entry = (SilcServerEntry)sock->user_data;
2138 if (sock->type == SILC_SOCKET_TYPE_ROUTER) {
2139 /* Add the channel to global list as it is coming from router. It
2140 cannot be our own channel as it is coming from router. */
2142 /* Check that we don't already have this channel */
2143 channel = silc_idlist_find_channel_by_name(server->local_list,
2144 channel_name, NULL);
2146 channel = silc_idlist_find_channel_by_name(server->global_list,
2147 channel_name, NULL);
2149 SILC_LOG_DEBUG(("New channel id(%s) from [Router] %s",
2150 silc_id_render(channel_id, SILC_ID_CHANNEL),
2153 silc_idlist_add_channel(server->global_list, strdup(channel_name),
2154 0, channel_id, sock->user_data, NULL, NULL);
2155 server->stat.channels++;
2158 /* The channel is coming from our server, thus it is in our cell
2159 we will add it to our local list. */
2162 SILC_LOG_DEBUG(("Channel id(%s) from [Server] %s",
2163 silc_id_render(channel_id, SILC_ID_CHANNEL),
2166 /* Check that we don't already have this channel */
2167 channel = silc_idlist_find_channel_by_name(server->local_list,
2168 channel_name, NULL);
2170 channel = silc_idlist_find_channel_by_name(server->global_list,
2171 channel_name, NULL);
2173 /* If the channel does not exist, then create it. This creates a new
2174 key to the channel as well that we will send to the server. */
2176 /* The protocol says that the Channel ID's IP address must be based
2177 on the router's IP address. Check whether the ID is based in our
2178 IP and if it is not then create a new ID and enforce the server
2179 to switch the ID. */
2180 if (server_entry->server_type != SILC_BACKUP_ROUTER &&
2181 !SILC_ID_COMPARE(channel_id, server->id, server->id->ip.data_len)) {
2183 SILC_LOG_DEBUG(("Forcing the server to change Channel ID"));
2185 if (silc_id_create_channel_id(server, server->id, server->rng, &tmp)) {
2186 silc_server_send_notify_channel_change(server, sock, FALSE,
2188 silc_free(channel_id);
2193 /* Create the channel with the provided Channel ID */
2194 channel = silc_server_create_new_channel_with_id(server, NULL, NULL,
2198 silc_channel_payload_free(payload);
2199 silc_free(channel_id);
2203 /* Get the mode and set it to the channel */
2204 channel->mode = silc_channel_get_mode(payload);
2206 /* Send the new channel key to the server */
2207 chk = silc_channel_key_payload_encode(id_len, id,
2208 strlen(channel->channel_key->
2210 channel->channel_key->cipher->name,
2211 channel->key_len / 8,
2213 silc_server_packet_send(server, sock, SILC_PACKET_CHANNEL_KEY, 0,
2214 chk->data, chk->len, FALSE);
2215 silc_buffer_free(chk);
2218 /* The channel exist by that name, check whether the ID's match.
2219 If they don't then we'll force the server to use the ID we have.
2220 We also create a new key for the channel. */
2221 SilcBuffer users = NULL, users_modes = NULL;
2223 if (!SILC_ID_CHANNEL_COMPARE(channel_id, channel->id)) {
2224 /* They don't match, send CHANNEL_CHANGE notify to the server to
2225 force the ID change. */
2226 SILC_LOG_DEBUG(("Forcing the server to change Channel ID"));
2227 silc_server_send_notify_channel_change(server, sock, FALSE,
2228 channel_id, channel->id);
2231 /* If the mode is different from what we have then enforce the
2233 mode = silc_channel_get_mode(payload);
2234 if (channel->mode != mode) {
2235 SILC_LOG_DEBUG(("Forcing the server to change channel mode"));
2236 silc_server_send_notify_cmode(server, sock, FALSE, channel,
2237 channel->mode, server->id,
2239 channel->cipher, channel->hmac_name);
2242 /* Create new key for the channel and send it to the server and
2243 everybody else possibly on the channel. */
2245 if (!(channel->mode & SILC_CHANNEL_MODE_PRIVKEY)) {
2246 if (!silc_server_create_channel_key(server, channel, 0))
2249 /* Send to the channel */
2250 silc_server_send_channel_key(server, sock, channel, FALSE);
2251 id = silc_id_id2str(channel->id, SILC_ID_CHANNEL);
2252 id_len = SILC_ID_CHANNEL_LEN;
2254 /* Send to the server */
2255 chk = silc_channel_key_payload_encode(id_len, id,
2256 strlen(channel->channel_key->
2258 channel->channel_key->
2260 channel->key_len / 8,
2262 silc_server_packet_send(server, sock, SILC_PACKET_CHANNEL_KEY, 0,
2263 chk->data, chk->len, FALSE);
2264 silc_buffer_free(chk);
2268 silc_free(channel_id);
2270 /* Since the channel is coming from server and we also know about it
2271 then send the JOIN notify to the server so that it see's our
2272 users on the channel "joining" the channel. */
2273 silc_server_announce_get_channel_users(server, channel, &users,
2276 silc_buffer_push(users, users->data - users->head);
2277 silc_server_packet_send(server, sock,
2278 SILC_PACKET_NOTIFY, SILC_PACKET_FLAG_LIST,
2279 users->data, users->len, FALSE);
2280 silc_buffer_free(users);
2283 silc_buffer_push(users_modes, users_modes->data - users_modes->head);
2284 silc_server_packet_send_dest(server, sock,
2285 SILC_PACKET_NOTIFY, SILC_PACKET_FLAG_LIST,
2286 channel->id, SILC_ID_CHANNEL,
2288 users_modes->len, FALSE);
2289 silc_buffer_free(users_modes);
2294 silc_channel_payload_free(payload);
2297 /* Received New Channel List packet, list of New Channel List payloads inside
2298 one packet. Process the New Channel payloads one by one. */
2300 void silc_server_new_channel_list(SilcServer server,
2301 SilcSocketConnection sock,
2302 SilcPacketContext *packet)
2304 SilcPacketContext *new;
2308 SILC_LOG_DEBUG(("Processing New Channel List"));
2310 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
2311 packet->src_id_type != SILC_ID_SERVER ||
2312 server->server_type == SILC_SERVER)
2315 /* If the sender of this packet is server and we are router we need to
2316 broadcast this packet to other routers in the network. Broadcast
2317 this list packet instead of multiple New Channel packets. */
2318 if (!server->standalone && server->server_type == SILC_ROUTER &&
2319 sock->type == SILC_SOCKET_TYPE_SERVER &&
2320 !(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
2321 SILC_LOG_DEBUG(("Broadcasting received New Channel List packet"));
2322 silc_server_packet_send(server, server->router->connection,
2324 packet->flags | SILC_PACKET_FLAG_BROADCAST,
2325 packet->buffer->data, packet->buffer->len, FALSE);
2326 silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
2327 packet->type, packet->flags,
2328 packet->buffer->data, packet->buffer->len,
2332 /* Make copy of the original packet context, except for the actual
2333 data buffer, which we will here now fetch from the original buffer. */
2334 new = silc_packet_context_alloc();
2335 new->type = SILC_PACKET_NEW_CHANNEL;
2336 new->flags = packet->flags;
2337 new->src_id = packet->src_id;
2338 new->src_id_len = packet->src_id_len;
2339 new->src_id_type = packet->src_id_type;
2340 new->dst_id = packet->dst_id;
2341 new->dst_id_len = packet->dst_id_len;
2342 new->dst_id_type = packet->dst_id_type;
2344 buffer = silc_buffer_alloc(512);
2345 new->buffer = buffer;
2347 while (packet->buffer->len) {
2348 SILC_GET16_MSB(len1, packet->buffer->data);
2349 if ((len1 > packet->buffer->len) ||
2350 (len1 > buffer->truelen))
2353 SILC_GET16_MSB(len2, packet->buffer->data + 2 + len1);
2354 if ((len2 > packet->buffer->len) ||
2355 (len2 > buffer->truelen))
2358 silc_buffer_pull_tail(buffer, 8 + len1 + len2);
2359 silc_buffer_put(buffer, packet->buffer->data, 8 + len1 + len2);
2361 /* Process the New Channel */
2362 silc_server_new_channel(server, sock, new);
2364 silc_buffer_push_tail(buffer, 8 + len1 + len2);
2365 silc_buffer_pull(packet->buffer, 8 + len1 + len2);
2368 silc_buffer_free(buffer);
2372 /* Received key agreement packet. This packet is never for us. It is to
2373 the client in the packet's destination ID. Sending of this sort of packet
2374 equals sending private message, ie. it is sent point to point from
2375 one client to another. */
2377 void silc_server_key_agreement(SilcServer server,
2378 SilcSocketConnection sock,
2379 SilcPacketContext *packet)
2381 SilcSocketConnection dst_sock;
2382 SilcIDListData idata;
2384 SILC_LOG_DEBUG(("Start"));
2386 if (packet->src_id_type != SILC_ID_CLIENT ||
2387 packet->dst_id_type != SILC_ID_CLIENT)
2390 if (!packet->dst_id)
2393 /* Get the route to the client */
2394 dst_sock = silc_server_get_client_route(server, packet->dst_id,
2395 packet->dst_id_len, NULL, &idata);
2399 /* Relay the packet */
2400 silc_server_relay_packet(server, dst_sock, idata->send_key,
2401 idata->hmac_send, idata->psn_send++,
2405 /* Received connection auth request packet that is used during connection
2406 phase to resolve the mandatory authentication method. This packet can
2407 actually be received at anytime but usually it is used only during
2408 the connection authentication phase. Now, protocol says that this packet
2409 can come from client or server, however, we support only this coming
2410 from client and expect that server always knows what authentication
2413 void silc_server_connection_auth_request(SilcServer server,
2414 SilcSocketConnection sock,
2415 SilcPacketContext *packet)
2417 SilcServerConfigSectionClientConnection *client = NULL;
2420 SilcAuthMethod auth_meth;
2422 SILC_LOG_DEBUG(("Start"));
2424 if (packet->src_id_type && packet->src_id_type != SILC_ID_CLIENT)
2427 /* Parse the payload */
2428 ret = silc_buffer_unformat(packet->buffer,
2429 SILC_STR_UI_SHORT(&conn_type),
2430 SILC_STR_UI_SHORT(NULL),
2435 if (conn_type != SILC_SOCKET_TYPE_CLIENT)
2438 /* Get the authentication method for the client */
2439 auth_meth = SILC_AUTH_NONE;
2440 port = server->sockets[server->sock]->port; /* Listenning port */
2441 client = silc_server_config_find_client_conn(server->config,
2445 client = silc_server_config_find_client_conn(server->config,
2449 auth_meth = client->auth_meth;
2451 /* Send it back to the client */
2452 silc_server_send_connection_auth_request(server, sock,
2457 /* Received REKEY packet. The sender of the packet wants to regenerate
2458 its session keys. This starts the REKEY protocol. */
2460 void silc_server_rekey(SilcServer server,
2461 SilcSocketConnection sock,
2462 SilcPacketContext *packet)
2464 SilcProtocol protocol;
2465 SilcServerRekeyInternalContext *proto_ctx;
2466 SilcIDListData idata = (SilcIDListData)sock->user_data;
2468 SILC_LOG_DEBUG(("Start"));
2470 /* Allocate internal protocol context. This is sent as context
2472 proto_ctx = silc_calloc(1, sizeof(*proto_ctx));
2473 proto_ctx->server = (void *)server;
2474 proto_ctx->sock = sock;
2475 proto_ctx->responder = TRUE;
2476 proto_ctx->pfs = idata->rekey->pfs;
2478 /* Perform rekey protocol. Will call the final callback after the
2479 protocol is over. */
2480 silc_protocol_alloc(SILC_PROTOCOL_SERVER_REKEY,
2481 &protocol, proto_ctx, silc_server_rekey_final);
2482 sock->protocol = protocol;
2484 if (proto_ctx->pfs == FALSE)
2485 /* Run the protocol */
2486 silc_protocol_execute(protocol, server->schedule, 0, 0);
2489 /* Received file transger packet. This packet is never for us. It is to
2490 the client in the packet's destination ID. Sending of this sort of packet
2491 equals sending private message, ie. it is sent point to point from
2492 one client to another. */
2494 void silc_server_ftp(SilcServer server,
2495 SilcSocketConnection sock,
2496 SilcPacketContext *packet)
2498 SilcSocketConnection dst_sock;
2499 SilcIDListData idata;
2501 SILC_LOG_DEBUG(("Start"));
2503 if (packet->src_id_type != SILC_ID_CLIENT ||
2504 packet->dst_id_type != SILC_ID_CLIENT)
2507 if (!packet->dst_id)
2510 /* Get the route to the client */
2511 dst_sock = silc_server_get_client_route(server, packet->dst_id,
2512 packet->dst_id_len, NULL, &idata);
2516 /* Relay the packet */
2517 silc_server_relay_packet(server, dst_sock, idata->send_key,
2518 idata->hmac_send, idata->psn_send++,