+ /* Save the users to the channel */
+ silc_server_save_users_on_channel(server, cmd->sock, entry,
+ client_id, client_id_list,
+ client_mode_list, list_count);
+
+ out:
+ SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_JOIN);
+ SILC_SERVER_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_JOIN);
+ silc_free(client_id);
+ silc_server_command_reply_free(cmd);
+
+ if (client_id_list)
+ silc_buffer_free(client_id_list);
+ if (client_mode_list)
+ silc_buffer_free(client_mode_list);
+}
+
+SILC_SERVER_CMD_REPLY_FUNC(users)
+{
+ SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
+ SilcServer server = cmd->server;
+ SilcCommandStatus status;
+ SilcChannelEntry channel;
+ SilcChannelID *channel_id = NULL;
+ SilcBuffer client_id_list;
+ SilcBuffer client_mode_list;
+ unsigned char *tmp;
+ uint32 tmp_len;
+ uint32 list_count;
+
+ COMMAND_CHECK_STATUS;
+
+ /* Get channel ID */
+ tmp = silc_argument_get_arg_type(cmd->args, 2, &tmp_len);
+ if (!tmp)
+ goto out;
+ channel_id = silc_id_payload_parse_id(tmp, tmp_len);
+ if (!channel_id)
+ goto out;
+
+ /* Get channel entry */
+ channel = silc_idlist_find_channel_by_id(server->local_list,
+ channel_id, NULL);
+ if (!channel) {
+ channel = silc_idlist_find_channel_by_id(server->global_list,
+ channel_id, NULL);
+ if (!channel) {
+ SilcBuffer idp;
+
+ if (server->server_type != SILC_SERVER)
+ goto out;
+
+ idp = silc_id_payload_encode(channel_id, SILC_ID_CHANNEL);
+ silc_server_send_command(server, server->router->connection,
+ SILC_COMMAND_IDENTIFY, ++server->cmd_ident,
+ 1, 5, idp->data, idp->len);
+ silc_buffer_free(idp);
+
+ /* Register pending command callback. After we've received the channel
+ information we will reprocess this command reply by re-calling this
+ USERS command reply callback. */
+ silc_server_command_pending(server, SILC_COMMAND_IDENTIFY,
+ server->cmd_ident,
+ NULL, silc_server_command_reply_users, cmd);
+ return;
+ }
+ }
+
+ /* Get the list count */
+ tmp = silc_argument_get_arg_type(cmd->args, 3, &tmp_len);
+ if (!tmp)
+ goto out;
+ SILC_GET32_MSB(list_count, tmp);
+
+ /* Get Client ID list */
+ tmp = silc_argument_get_arg_type(cmd->args, 4, &tmp_len);
+ if (!tmp)
+ goto out;
+
+ client_id_list = silc_buffer_alloc(tmp_len);
+ silc_buffer_pull_tail(client_id_list, tmp_len);
+ silc_buffer_put(client_id_list, tmp, tmp_len);
+
+ /* Get client mode list */
+ tmp = silc_argument_get_arg_type(cmd->args, 5, &tmp_len);
+ if (!tmp)
+ goto out;
+
+ client_mode_list = silc_buffer_alloc(tmp_len);
+ silc_buffer_pull_tail(client_mode_list, tmp_len);
+ silc_buffer_put(client_mode_list, tmp, tmp_len);
+
+ /* Save the users to the channel */
+ silc_server_save_users_on_channel(server, cmd->sock, channel, NULL,
+ client_id_list, client_mode_list,
+ list_count);
+
+ silc_buffer_free(client_id_list);
+ silc_buffer_free(client_mode_list);
+
+ out:
+ SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_USERS);
+ SILC_SERVER_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_USERS);
+ silc_free(channel_id);
+ silc_server_command_reply_free(cmd);
+}
+
+SILC_SERVER_CMD_REPLY_FUNC(getkey)
+{
+ SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
+ SilcServer server = cmd->server;
+ SilcCommandStatus status;
+ SilcClientEntry client = NULL;
+ SilcServerEntry server_entry = NULL;
+ SilcClientID *client_id = NULL;
+ SilcServerID *server_id = NULL;
+ SilcSKEPKType type;
+ unsigned char *tmp, *pk;
+ uint32 len;
+ uint16 pk_len;
+ SilcIDPayload idp = NULL;
+ SilcIdType id_type;
+ SilcPublicKey public_key = NULL;
+
+ COMMAND_CHECK_STATUS;
+
+ tmp = silc_argument_get_arg_type(cmd->args, 2, &len);
+ if (!tmp)
+ goto out;
+ idp = silc_id_payload_parse_data(tmp, len);
+ if (!idp)
+ goto out;
+
+ /* Get the public key payload */
+ tmp = silc_argument_get_arg_type(cmd->args, 3, &len);
+ if (!tmp)
+ goto out;
+
+ /* Decode the public key */
+
+ SILC_GET16_MSB(pk_len, tmp);
+ SILC_GET16_MSB(type, tmp + 2);
+ pk = tmp + 4;
+
+ if (type != SILC_SKE_PK_TYPE_SILC)
+ goto out;
+
+ if (!silc_pkcs_public_key_decode(pk, pk_len, &public_key))
+ goto out;
+
+ id_type = silc_id_payload_get_type(idp);
+ if (id_type == SILC_ID_CLIENT) {
+ client_id = silc_id_payload_get_id(idp);
+
+ client = silc_idlist_find_client_by_id(server->local_list, client_id,
+ TRUE, NULL);
+ if (!client) {
+ client = silc_idlist_find_client_by_id(server->global_list,
+ client_id, TRUE, NULL);
+ if (!client)
+ goto out;
+ }
+
+ client->data.public_key = public_key;
+ } else if (id_type == SILC_ID_SERVER) {
+ server_id = silc_id_payload_get_id(idp);
+
+ server_entry = silc_idlist_find_server_by_id(server->local_list, server_id,
+ TRUE, NULL);
+ if (!server_entry) {
+ server_entry = silc_idlist_find_server_by_id(server->global_list,
+ server_id, TRUE, NULL);
+ if (!server_entry)
+ goto out;
+ }
+
+ server_entry->data.public_key = public_key;
+ } else {
+ goto out;
+ }