From 6bb31d0810eaaa174e48cb317f78a9cd93596f1a Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sat, 29 Jun 2002 15:39:29 +0000 Subject: [PATCH] Send NO_SUCH_CHANNEL error in USERS for secret and private channels. Fixed CMODE to set the old mode back correctly if error occurred. Fixed passphrase saving on normal server in JOIN command. --- CHANGES | 14 ++++++++++++++ apps/silcd/command.c | 35 +++++++++++++++++++++-------------- apps/silcd/packet_receive.c | 11 +++++++++-- apps/silcd/server.c | 11 ++++++++--- 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/CHANGES b/CHANGES index 39385ebe..14b495b0 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,17 @@ +Sat Jun 29 17:40:12 EEST 2002 Pekka Riikonen + + * Return NO_SUCH_CHANNEL error in USERS for channel that is + secret or private, otherwise it's possible to find out + whether a secret channel exists or not. Affected file + silcd/command.c. + + * If CMODE change fails during the mode setting, assure that + the old mode mask is set for the channel back. Affected + file silcd/command.c. + + * Fixed passphrase saving on +a channel on normal server + after successful JOIN command. Affected file silcd/command.c. + Fri Jun 28 11:53:25 CEST 2002 Pekka Riikonen * Remove server/router operator privileges in DETACH command, diff --git a/apps/silcd/command.c b/apps/silcd/command.c index 5d6b3cda..6d0dcd8e 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -3692,7 +3692,7 @@ SILC_SERVER_CMD_FUNC(join) /* Save channel passphrase, if user provided it successfully */ unsigned char *pa; SilcUInt32 pa_len; - pa = silc_argument_get_arg_type(reply->args, 3, &pa_len); + pa = silc_argument_get_arg_type(cmd->args, 3, &pa_len); if (pa) { silc_free(channel->passphrase); channel->passphrase = silc_memdup(pa, pa_len); @@ -3958,7 +3958,7 @@ SILC_SERVER_CMD_FUNC(cmode) SilcBuffer packet, cidp; unsigned char *tmp, *tmp_id, *tmp_mask; char *cipher = NULL, *hmac = NULL, *passphrase = NULL; - SilcUInt32 mode_mask = 0, tmp_len, tmp_len2; + SilcUInt32 mode_mask = 0, old_mask = 0, tmp_len, tmp_len2; SilcUInt16 ident = silc_command_get_ident(cmd->payload); bool set_mask = FALSE; SilcPublicKey founder_key = NULL; @@ -3972,20 +3972,15 @@ SILC_SERVER_CMD_FUNC(cmode) if (!tmp_id) { silc_server_command_send_status_reply(cmd, SILC_COMMAND_CMODE, SILC_STATUS_ERR_NO_CHANNEL_ID, 0); - goto out; + silc_server_command_free(cmd); + return; } channel_id = silc_id_payload_parse_id(tmp_id, tmp_len2, NULL); if (!channel_id) { silc_server_command_send_status_reply(cmd, SILC_COMMAND_CMODE, SILC_STATUS_ERR_NO_CHANNEL_ID, 0); - goto out; - } - - /* Get the channel mode mask */ - tmp_mask = silc_argument_get_arg_type(cmd->args, 2, &tmp_len); - if (tmp_mask) { - SILC_GET32_MSB(mode_mask, tmp_mask); - set_mask = TRUE; + silc_server_command_free(cmd); + return; } /* Get channel entry */ @@ -3998,9 +3993,19 @@ SILC_SERVER_CMD_FUNC(cmode) silc_server_command_send_status_reply(cmd, SILC_COMMAND_CMODE, SILC_STATUS_ERR_NO_SUCH_CHANNEL, 0); - goto out; + silc_free(channel_id); + silc_server_command_free(cmd); + return; } } + old_mask = channel->mode; + + /* Get the channel mode mask */ + tmp_mask = silc_argument_get_arg_type(cmd->args, 2, &tmp_len); + if (tmp_mask) { + SILC_GET32_MSB(mode_mask, tmp_mask); + set_mask = TRUE; + } /* Check whether this client is on the channel */ if (!silc_server_client_on_channel(client, channel, &chl)) { @@ -4299,7 +4304,7 @@ SILC_SERVER_CMD_FUNC(cmode) } /* Finally, set the mode */ - channel->mode = mode_mask; + old_mask = channel->mode = mode_mask; /* Send CMODE_CHANGE notify. */ cidp = silc_id_payload_encode(client->id, SILC_ID_CLIENT); @@ -4331,6 +4336,7 @@ SILC_SERVER_CMD_FUNC(cmode) silc_buffer_free(cidp); out: + channel->mode = old_mask; silc_free(fkey); silc_free(channel_id); silc_server_command_free(cmd); @@ -5636,7 +5642,8 @@ SILC_SERVER_CMD_FUNC(users) && !silc_server_client_on_channel(cmd->sock->user_data, channel, NULL)) { silc_server_command_send_status_reply(cmd, SILC_COMMAND_USERS, - SILC_STATUS_ERR_NOT_ON_CHANNEL, 0); + SILC_STATUS_ERR_NO_SUCH_CHANNEL, + 0); goto out; } } diff --git a/apps/silcd/packet_receive.c b/apps/silcd/packet_receive.c index 02d83563..fd45c463 100644 --- a/apps/silcd/packet_receive.c +++ b/apps/silcd/packet_receive.c @@ -2874,7 +2874,7 @@ void silc_server_new_channel(SilcServer server, 0, channel_id, sock->user_data, NULL, NULL, 0); if (!channel) return; - channel->disabled = TRUE; + channel->disabled = TRUE; /* Disabled until someone JOINs */ server->stat.channels++; if (server->server_type == SILC_ROUTER) @@ -2929,9 +2929,16 @@ void silc_server_new_channel(SilcServer server, silc_free(channel_id); return; } - channel->disabled = TRUE; + channel->disabled = TRUE; /* Disabled until someone JOINs */ + +#if 0 /* We assume that CMODE_CHANGE notify is sent to us after this. */ + + /* XXX Dunno if this is supposed to be set in any server type. If set + here the CMODE_CHANGE that may follow sets mode that we already + have, and we may loose data from the CMODE_CHANGE notify. */ if (server_entry->server_type != SILC_BACKUP_ROUTER) channel->mode = silc_channel_get_mode(payload); +#endif /* Send the new channel key to the server */ id = silc_id_id2str(channel->id, SILC_ID_CHANNEL); diff --git a/apps/silcd/server.c b/apps/silcd/server.c index bd30f64b..83bb1254 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -2762,6 +2762,8 @@ SILC_TASK_CALLBACK(silc_server_close_connection_final) void silc_server_close_connection(SilcServer server, SilcSocketConnection sock) { + char tmp[128]; + if (!server->sockets[sock->sock] && SILC_IS_DISCONNECTED(sock)) { silc_schedule_task_add(server->schedule, 0, silc_server_close_connection_final, @@ -2770,12 +2772,14 @@ void silc_server_close_connection(SilcServer server, return; } - SILC_LOG_INFO(("Closing connection %s:%d [%s]", sock->hostname, + memset(tmp, 0, sizeof(tmp)); + silc_socket_get_error(sock, tmp, sizeof(tmp)); + SILC_LOG_INFO(("Closing connection %s:%d [%s] %s", sock->hostname, sock->port, (sock->type == SILC_SOCKET_TYPE_UNKNOWN ? "Unknown" : sock->type == SILC_SOCKET_TYPE_CLIENT ? "Client" : sock->type == SILC_SOCKET_TYPE_SERVER ? "Server" : - "Router"))); + "Router"), tmp[0] ? tmp : "")); /* We won't listen for this connection anymore */ silc_schedule_unset_listen_fd(server->schedule, sock->sock); @@ -3802,7 +3806,8 @@ void silc_server_perform_heartbeat(SilcSocketConnection sock, { SilcServerHBContext hb = (SilcServerHBContext)hb_context; - SILC_LOG_DEBUG(("Sending heartbeat to %s (%s)", sock->hostname, sock->ip)); + SILC_LOG_DEBUG(("Sending heartbeat to %s:%d (%s)", sock->hostname, + sock->port, sock->ip)); /* Send the heartbeat */ silc_server_send_heartbeat(hb->server, sock); -- 2.24.0