From 2a2db637fb3b961add7baa38b057648e100df046 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Wed, 21 Feb 2001 14:42:30 +0000 Subject: [PATCH] updates. --- CHANGES | 10 +++ apps/silcd/command.c | 60 ++++++++----- apps/silcd/packet_receive.c | 164 +++++++++++++++++++++++++++++++++--- lib/silcclient/idlist.c | 2 + lib/silccore/silcauth.c | 2 +- lib/silccore/silcmode.c | 12 +-- 6 files changed, 212 insertions(+), 38 deletions(-) diff --git a/CHANGES b/CHANGES index 26f2563c..f0e7830c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,13 @@ +Wed Feb 21 14:17:04 EET 2001 Pekka Riikonen + + * Implemented CMODE_CHANGE, CUMODE_CHANGE and TOPIC_SET notify + types in the server's silcd/packet_receive.c. + + * Implemented CMODE and CUMODE to work in router environment. + + * Fixed minor encoding and decoding buglet from the + lib/silccore/silcmode.c. + Wed Feb 21 12:44:00 EET 2001 Mika Boström * Changed all SilcConfigServer* and silc_config_server* to diff --git a/apps/silcd/command.c b/apps/silcd/command.c index 4f0749cb..5ddd6111 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -1402,15 +1402,15 @@ SILC_SERVER_CMD_FUNC(topic) /* See whether has rights to change topic */ silc_list_start(channel->user_list); - while ((chl = silc_list_get(channel->user_list)) != SILC_LIST_END) { - if (chl->client == client) { - if (chl->mode == SILC_CHANNEL_UMODE_NONE) { - silc_server_command_send_status_reply(cmd, SILC_COMMAND_TOPIC, - SILC_STATUS_ERR_NO_CHANNEL_PRIV); - goto out; - } else { - break; - } + while ((chl = silc_list_get(channel->user_list)) != SILC_LIST_END) + if (chl->client == client) + break; + + if (chl->mode == SILC_CHANNEL_UMODE_NONE) { + if (channel->mode & SILC_CHANNEL_MODE_TOPIC) { + silc_server_command_send_status_reply(cmd, SILC_COMMAND_TOPIC, + SILC_STATUS_ERR_NO_CHANNEL_PRIV); + goto out; } } @@ -2569,7 +2569,15 @@ SILC_SERVER_CMD_FUNC(cmode) SILC_NOTIFY_TYPE_CMODE_CHANGE, 2, cidp->data, cidp->len, tmp_mask, tmp_len); - silc_free(cidp); + + /* Set SET_MODE packet to network */ + if (!server->standalone) + silc_server_send_set_mode(server, server->router->connection, + server->server_type == SILC_ROUTER ? + TRUE : FALSE, SILC_MODE_TYPE_CHANNEL, + mode_mask, 2, + tmp_id, tmp_len2, + cidp->data, cidp->len); /* Send command reply to sender */ packet = silc_command_reply_payload_encode_va(SILC_COMMAND_CMODE, @@ -2580,6 +2588,7 @@ SILC_SERVER_CMD_FUNC(cmode) silc_buffer_free(packet); silc_free(channel_id); + silc_free(cidp); out: silc_server_command_free(cmd); @@ -2598,20 +2607,20 @@ SILC_SERVER_CMD_FUNC(cumode) SilcClientEntry target_client; SilcChannelClientEntry chl; SilcBuffer packet, idp; - unsigned char *tmp_id, *tmp_mask; - unsigned int target_mask, sender_mask, tmp_len; + unsigned char *tmp_id, *tmp_ch_id, *tmp_mask; + unsigned int target_mask, sender_mask, tmp_len, tmp_ch_len; int notify = FALSE; SILC_SERVER_COMMAND_CHECK_ARGC(SILC_COMMAND_CUMODE, cmd, 3, 3); /* Get Channel ID */ - tmp_id = silc_argument_get_arg_type(cmd->args, 1, &tmp_len); - if (!tmp_id) { + tmp_ch_id = silc_argument_get_arg_type(cmd->args, 1, &tmp_ch_len); + if (!tmp_ch_id) { silc_server_command_send_status_reply(cmd, SILC_COMMAND_CUMODE, SILC_STATUS_ERR_NO_CHANNEL_ID); goto out; } - channel_id = silc_id_payload_parse_id(tmp_id, tmp_len); + channel_id = silc_id_payload_parse_id(tmp_ch_id, tmp_ch_len); if (!channel_id) { silc_server_command_send_status_reply(cmd, SILC_COMMAND_CUMODE, SILC_STATUS_ERR_NO_CHANNEL_ID); @@ -2677,7 +2686,8 @@ SILC_SERVER_CMD_FUNC(cumode) target_client = silc_idlist_find_client_by_id(server->local_list, client_id, NULL); if (!target_client) { - /* XXX If target client is not one of mine send to primary route */ + target_client = silc_idlist_find_client_by_id(server->global_list, + client_id, NULL); } /* Check whether target client is on the channel */ @@ -2738,16 +2748,27 @@ SILC_SERVER_CMD_FUNC(cumode) } } + idp = silc_id_payload_encode(client->id, SILC_ID_CLIENT); + /* Send notify to channel, notify only if mode was actually changed. */ if (notify) { - idp = silc_id_payload_encode(client->id, SILC_ID_CLIENT); silc_server_send_notify_to_channel(server, NULL, channel, TRUE, SILC_NOTIFY_TYPE_CUMODE_CHANGE, 3, idp->data, idp->len, - tmp_mask, 4, tmp_id, tmp_len); - silc_buffer_free(idp); + tmp_mask, 4, + tmp_id, tmp_len); } + /* Set SET_MODE packet to network */ + if (!server->standalone) + silc_server_send_set_mode(server, server->router->connection, + server->server_type == SILC_ROUTER ? + TRUE : FALSE, SILC_MODE_TYPE_UCHANNEL, + target_mask, 3, + tmp_ch_id, tmp_ch_len, + idp->data, idp->len, + tmp_id, tmp_len); + /* Send command reply to sender */ packet = silc_command_reply_payload_encode_va(SILC_COMMAND_CUMODE, SILC_STATUS_OK, 0, 2, @@ -2759,6 +2780,7 @@ SILC_SERVER_CMD_FUNC(cumode) silc_buffer_free(packet); silc_free(channel_id); silc_free(client_id); + silc_buffer_free(idp); out: silc_server_command_free(cmd); diff --git a/apps/silcd/packet_receive.c b/apps/silcd/packet_receive.c index 9c01d848..5621960a 100644 --- a/apps/silcd/packet_receive.c +++ b/apps/silcd/packet_receive.c @@ -1364,6 +1364,8 @@ void silc_server_notify(SilcServer server, SilcClientID *client_id, *client_id2; SilcChannelEntry channel; SilcClientEntry client; + SilcChannelClientEntry chl; + unsigned int mode; unsigned char *tmp; unsigned int tmp_len; @@ -1548,6 +1550,49 @@ void silc_server_notify(SilcServer server, silc_idlist_del_client(server->global_list, client); break; + case SILC_NOTIFY_TYPE_TOPIC_SET: + /* + * Distribute the notify to local clients on the channel + */ + + SILC_LOG_DEBUG(("TOPIC SET notify")); + + channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len, + packet->dst_id_type); + 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) { + silc_free(channel_id); + goto out; + } + } + + /* Get the topic */ + tmp = silc_argument_get_arg_type(args, 2, &tmp_len); + if (!tmp) { + silc_free(channel_id); + goto out; + } + + if (channel->topic) + silc_free(channel->topic); + channel->topic = silc_calloc(tmp_len, sizeof(*channel->topic)); + memcpy(channel->topic, tmp, tmp_len); + + /* Send the same notify to the channel */ + silc_server_packet_send_to_channel(server, NULL, channel, packet->type, + FALSE, packet->buffer->data, + packet->buffer->len, FALSE); + silc_free(channel_id); + break; + case SILC_NOTIFY_TYPE_NICK_CHANGE: { /* @@ -1598,31 +1643,128 @@ void silc_server_notify(SilcServer server, silc_free(client_id2); break; } - case SILC_NOTIFY_TYPE_TOPIC_SET: - /* - * Distribute the notify to local clients on the channel - */ - SILC_LOG_DEBUG(("TOPIC SET notify (not-impl XXX)")); - break; case SILC_NOTIFY_TYPE_CMODE_CHANGE: /* * Distribute the notify to local clients on the channel */ - SILC_LOG_DEBUG(("CMODE CHANGE notify (not-impl XXX)")); + + SILC_LOG_DEBUG(("CMODE CHANGE notify")); + + channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len, + packet->dst_id_type); + 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) { + silc_free(channel_id); + goto out; + } + } + + /* Send the same notify to the channel */ + silc_server_packet_send_to_channel(server, NULL, channel, packet->type, + FALSE, packet->buffer->data, + packet->buffer->len, FALSE); + + /* Get the mode */ + tmp = silc_argument_get_arg_type(args, 2, &tmp_len); + if (!tmp) { + silc_free(channel_id); + goto out; + } + + SILC_GET32_MSB(mode, tmp); + + /* Change mode */ + channel->mode = mode; + silc_free(channel_id); break; case SILC_NOTIFY_TYPE_CUMODE_CHANGE: /* * Distribute the notify to local clients on the channel */ - SILC_LOG_DEBUG(("CUMODE CHANGE notify (not-impl XXX)")); + + SILC_LOG_DEBUG(("CUMODE CHANGE notify")); + + channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len, + packet->dst_id_type); + 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) { + silc_free(channel_id); + goto out; + } + } + + /* Get the mode */ + tmp = silc_argument_get_arg_type(args, 2, &tmp_len); + if (!tmp) { + silc_free(channel_id); + goto out; + } + + SILC_GET32_MSB(mode, tmp); + + /* Get target client */ + tmp = silc_argument_get_arg_type(args, 3, &tmp_len); + if (!tmp) + goto out; + client_id = silc_id_payload_parse_id(tmp, tmp_len); + if (!client_id) + goto out; + + /* Get client entry */ + client = silc_idlist_find_client_by_id(server->global_list, + client_id, NULL); + if (!client) { + client = silc_idlist_find_client_by_id(server->local_list, + client_id, NULL); + if (!client) { + silc_free(client_id); + goto out; + } + } + silc_free(client_id); + + /* Get entry to the channel user list */ + silc_list_start(channel->user_list); + while ((chl = silc_list_get(channel->user_list)) != SILC_LIST_END) + if (chl->client == client) { + /* Change the mode */ + chl->mode = mode; + break; + } + + /* Send the same notify to the channel */ + silc_server_packet_send_to_channel(server, NULL, channel, packet->type, + FALSE, packet->buffer->data, + packet->buffer->len, FALSE); + silc_free(channel_id); + break; + + case SILC_NOTIFY_TYPE_INVITE: + SILC_LOG_DEBUG(("INVITE notify (not-impl XXX)")); break; /* Ignore rest notify types for now */ case SILC_NOTIFY_TYPE_NONE: - case SILC_NOTIFY_TYPE_INVITE: case SILC_NOTIFY_TYPE_MOTD: + break; default: break; } @@ -1876,7 +2018,7 @@ void silc_server_set_mode(SilcServer server, /* Send CUMODE_CHANGE notify to local channel */ silc_server_send_notify_to_channel(server, sock, channel, FALSE, - SILC_NOTIFY_TYPE_CUMODE_CHANGE, 2, + SILC_NOTIFY_TYPE_CUMODE_CHANGE, 3, tmp, tmp_len, mode, sizeof(mode), tmp2, tmp_len2); @@ -1899,8 +2041,6 @@ void silc_server_set_mode(SilcServer server, out: if (channel_id) silc_free(channel_id); - if (args) - silc_argument_payload_free(args); if (payload) silc_set_mode_payload_free(payload); } diff --git a/lib/silcclient/idlist.c b/lib/silcclient/idlist.c index e3f30554..8da74caf 100644 --- a/lib/silcclient/idlist.c +++ b/lib/silcclient/idlist.c @@ -118,6 +118,8 @@ SilcClientEntry silc_idlist_get_client_by_id(SilcClient client, SILC_ID_CLIENT, &id_cache)) return NULL; + SILC_LOG_DEBUG(("Found")); + return (SilcClientEntry)id_cache->context; } diff --git a/lib/silccore/silcauth.c b/lib/silccore/silcauth.c index 139ec176..9a00903b 100644 --- a/lib/silccore/silcauth.c +++ b/lib/silccore/silcauth.c @@ -244,7 +244,7 @@ int silc_auth_public_key_auth_verify(SilcAuthPayload payload, return FALSE; } - /* Verify the authencation data */ + /* Verify the authentication data */ if (!silc_pkcs_verify_with_hash(pkcs, hash, payload->auth_data, payload->auth_len, tmp, tmp_len)) { diff --git a/lib/silccore/silcmode.c b/lib/silccore/silcmode.c index a937e365..d0f4f4d6 100644 --- a/lib/silccore/silcmode.c +++ b/lib/silccore/silcmode.c @@ -60,9 +60,9 @@ SilcSetModePayload silc_set_mode_payload_parse(SilcBuffer buffer) goto err; if (new->argc) { - silc_buffer_pull(buffer, 5); + silc_buffer_pull(buffer, 9); new->args = silc_argument_payload_parse(buffer, new->argc); - silc_buffer_push(buffer, 5); + silc_buffer_push(buffer, 9); } return new; @@ -114,22 +114,22 @@ SilcBuffer silc_set_mode_payload_encode(unsigned short mode_type, silc_free(argv_types); } - len += 5; + len += 9; buffer = silc_buffer_alloc(len); silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer)); silc_buffer_format(buffer, SILC_STR_UI_SHORT(mode_type), SILC_STR_UI_SHORT(len), SILC_STR_UI_INT(mode_mask), - SILC_STR_UI_CHAR(argc), + SILC_STR_UI_CHAR((unsigned char)argc), SILC_STR_END); if (argc) { - silc_buffer_pull(buffer, 5); + silc_buffer_pull(buffer, 9); silc_buffer_format(buffer, SILC_STR_UI_XNSTRING(args->data, args->len), SILC_STR_END); - silc_buffer_push(buffer, 5); + silc_buffer_push(buffer, 9); silc_buffer_free(args); } -- 2.43.0