From: Pekka Riikonen Date: Tue, 24 Feb 2004 14:33:16 +0000 (+0000) Subject: Added the user limit to the CMODE_CHANGE notify and CMODE and X-Git-Tag: silc.server.0.9.17~1 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=f51b03ef03083cfdf552ff7176f679a256868081 Added the user limit to the CMODE_CHANGE notify and CMODE and JOIN command replys. --- diff --git a/CHANGES b/CHANGES index f8015a5a..6f4632f5 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,10 @@ +Tue Feb 24 16:49:10 EET 2004 Pekka Riikonen + + * Implemented the user limit to the CMODE_CHANGE notify, + CMODE command reply and JOIN command reply in server. + Affected files are silcd/server.c, command.c, command_reply.c, + packet_send.c and packet_receive.c. + Mon Feb 23 23:31:15 EET 2004 Pekka Riikonen * Defined SILC_STRFMT_END that must be used now with diff --git a/TODO b/TODO index 30e93ec0..a3d03c37 100644 --- a/TODO +++ b/TODO @@ -17,9 +17,6 @@ TODO for SILC Server 1.0 o stringprep (RFC3454) for UTF-8 strings + all other UTF-8 string things. - o to CMODE_CHANGE notify, and JOIN and CMODE command - replies. - o Check that founder key is distributed ok during backup resuming. o Testing diff --git a/apps/silcd/command.c b/apps/silcd/command.c index 767a0dd3..8fefc1cb 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -1839,7 +1839,7 @@ static void silc_server_command_join_channel(SilcServer server, SilcSocketConnection sock = cmd->sock; unsigned char *tmp; SilcUInt32 tmp_len, user_count; - unsigned char *passphrase = NULL, mode[4], tmp2[4], tmp3[4]; + unsigned char *passphrase = NULL, mode[4], tmp2[4], tmp3[4], ulimit[4]; SilcClientEntry client; SilcChannelClientEntry chl; SilcBuffer reply, chidp, clidp, keyp = NULL; @@ -2124,6 +2124,8 @@ static void silc_server_command_join_channel(SilcServer server, SILC_PUT32_MSB(channel->mode, mode); SILC_PUT32_MSB(created, tmp2); SILC_PUT32_MSB(user_count, tmp3); + if (channel->mode & SILC_CHANNEL_MODE_ULIMIT) + SILC_PUT32_MSB(channel->user_limit, ulimit); if (!(channel->mode & SILC_CHANNEL_MODE_PRIVKEY)) { tmp = silc_id_id2str(channel->id, SILC_ID_CHANNEL); @@ -2182,7 +2184,7 @@ static void silc_server_command_join_channel(SilcServer server, reply = silc_command_reply_payload_encode_va(SILC_COMMAND_JOIN, - SILC_STATUS_OK, 0, ident, 15, + SILC_STATUS_OK, 0, ident, 16, 2, channel->channel_name, strlen(channel->channel_name), 3, chidp->data, chidp->len, @@ -2209,7 +2211,13 @@ static void silc_server_command_join_channel(SilcServer server, 15, fkey ? fkey->data : NULL, fkey ? fkey->len : 0, 16, chpklist ? chpklist->data : NULL, - chpklist ? chpklist->len : 0); + chpklist ? chpklist->len : 0, + 17, (channel->mode & + SILC_CHANNEL_MODE_ULIMIT ? + ulimit : NULL), + (channel->mode & + SILC_CHANNEL_MODE_ULIMIT ? + sizeof(ulimit) : 0)); /* Send command reply */ silc_server_packet_send(server, sock, SILC_PACKET_COMMAND_REPLY, 0, @@ -2762,7 +2770,7 @@ SILC_SERVER_CMD_FUNC(cmode) SilcChannelClientEntry chl; SilcBuffer packet, cidp; unsigned char *tmp, *tmp_id, *tmp_mask, *chpkdata = NULL; - char *cipher = NULL, *hmac = NULL, *passphrase = NULL; + char *cipher = NULL, *hmac = NULL, *passphrase = NULL, ulimit[4]; SilcUInt32 mode_mask = 0, old_mask = 0, tmp_len, tmp_len2, chpklen; SilcUInt16 ident = silc_command_get_ident(cmd->payload); bool set_mask = FALSE, set_chpk = FALSE; @@ -3190,8 +3198,10 @@ SILC_SERVER_CMD_FUNC(cmode) /* Send CMODE_CHANGE notify. */ cidp = silc_id_payload_encode(client->id, SILC_ID_CLIENT); + if (mode_mask & SILC_CHANNEL_MODE_ULIMIT) + SILC_PUT32_MSB(channel->user_limit, ulimit); silc_server_send_notify_to_channel(server, NULL, channel, FALSE, TRUE, - SILC_NOTIFY_TYPE_CMODE_CHANGE, 7, + SILC_NOTIFY_TYPE_CMODE_CHANGE, 8, cidp->data, cidp->len, tmp_mask, 4, cipher, cipher ? strlen(cipher) : 0, @@ -3201,7 +3211,11 @@ SILC_SERVER_CMD_FUNC(cmode) fkey ? fkey->data : NULL, fkey ? fkey->len : 0, chpkdata ? chpkdata : NULL, - chpkdata ? chpklen : 0); + chpkdata ? chpklen : 0, + mode_mask & SILC_CHANNEL_MODE_ULIMIT ? + ulimit : NULL, + mode_mask & SILC_CHANNEL_MODE_ULIMIT ? + sizeof(ulimit) : 0); /* Set CMODE notify type to network */ if (chpkdata && chpklen) @@ -3217,14 +3231,21 @@ SILC_SERVER_CMD_FUNC(cmode) /* Send command reply to sender */ packet = silc_command_reply_payload_encode_va(SILC_COMMAND_CMODE, - SILC_STATUS_OK, 0, ident, 4, + SILC_STATUS_OK, 0, ident, 5, 2, tmp_id, tmp_len2, 3, tmp_mask, 4, 4, fkey ? fkey->data : NULL, fkey ? fkey->len : 0, 5, chpklist ? chpklist->data : NULL, chpklist ? chpklist->len - : 0); + : 0, + 7, (mode_mask & + SILC_CHANNEL_MODE_ULIMIT ? + ulimit : NULL), + (mode_mask & + SILC_CHANNEL_MODE_ULIMIT ? + sizeof(ulimit) : 0)); + silc_server_packet_send(server, cmd->sock, SILC_PACKET_COMMAND_REPLY, 0, packet->data, packet->len, FALSE); diff --git a/apps/silcd/command_reply.c b/apps/silcd/command_reply.c index 15e9c930..9acb1ed8 100644 --- a/apps/silcd/command_reply.c +++ b/apps/silcd/command_reply.c @@ -1146,6 +1146,11 @@ SILC_SERVER_CMD_REPLY_FUNC(join) if (tmp && server->server_type == SILC_SERVER) silc_server_set_channel_pk_list(server, NULL, entry, tmp, len); + /* The the user limit */ + tmp = silc_argument_get_arg_type(cmd->args, 17, &len); + if (tmp && len == 4) + SILC_GET32_MSB(entry->user_limit, tmp); + /* If channel was not created we know there is global users on the channel. */ entry->global_users = (created == 0 ? TRUE : FALSE); diff --git a/apps/silcd/packet_receive.c b/apps/silcd/packet_receive.c index 8a2e2ca2..5b6fefc8 100644 --- a/apps/silcd/packet_receive.c +++ b/apps/silcd/packet_receive.c @@ -628,7 +628,7 @@ void silc_server_notify(SilcServer server, mode & SILC_CHANNEL_MODE_CHANNEL_AUTH) { SilcBuffer chpklist; SilcBuffer sidp; - unsigned char mask[4]; + unsigned char mask[4], ulimit[4]; SILC_LOG_DEBUG(("Channel public key list received from router")); tmp = silc_argument_get_arg_type(args, 7, &tmp_len); @@ -644,8 +644,10 @@ void silc_server_notify(SilcServer server, break; sidp = silc_id_payload_encode(server->router->id, SILC_ID_SERVER); SILC_PUT32_MSB(channel->mode, mask); + if (channel->mode & SILC_CHANNEL_MODE_ULIMIT) + SILC_PUT32_MSB(channel->user_limit, ulimit); silc_server_send_notify_to_channel(server, NULL, channel, FALSE, TRUE, - SILC_NOTIFY_TYPE_CMODE_CHANGE, 7, + SILC_NOTIFY_TYPE_CMODE_CHANGE, 8, sidp->data, sidp->len, mask, 4, channel->cipher, @@ -658,7 +660,13 @@ void silc_server_notify(SilcServer server, channel->passphrase ? strlen(channel->passphrase) : 0, NULL, 0, - chpklist->data, chpklist->len); + chpklist->data, chpklist->len, + (channel->mode & + SILC_CHANNEL_MODE_ULIMIT ? + ulimit : NULL), + (channel->mode & + SILC_CHANNEL_MODE_ULIMIT ? + sizeof(ulimit) : 0)); silc_buffer_free(sidp); silc_buffer_free(chpklist); goto out; @@ -813,6 +821,11 @@ void silc_server_notify(SilcServer server, } } + /* Get the user limit */ + tmp = silc_argument_get_arg_type(args, 8, &tmp_len); + if (tmp && tmp_len == 4 && mode & SILC_CHANNEL_MODE_ULIMIT) + SILC_GET32_MSB(channel->user_limit, tmp); + /* Send the same notify to the channel */ silc_server_packet_send_to_channel(server, NULL, channel, packet->type, FALSE, TRUE, packet->buffer->data, diff --git a/apps/silcd/packet_send.c b/apps/silcd/packet_send.c index 17460378..68cff9de 100644 --- a/apps/silcd/packet_send.c +++ b/apps/silcd/packet_send.c @@ -1314,16 +1314,18 @@ void silc_server_send_notify_cmode(SilcServer server, SilcBuffer channel_pubkeys) { SilcBuffer idp, fkey = NULL; - unsigned char mode[4]; + unsigned char mode[4], ulimit[4]; idp = silc_id_payload_encode((void *)id, id_type); SILC_PUT32_MSB(mode_mask, mode); if (founder_key) fkey = silc_pkcs_public_key_payload_encode(founder_key); + if (channel->mode & SILC_CHANNEL_MODE_ULIMIT) + SILC_PUT32_MSB(channel->user_limit, ulimit); silc_server_send_notify_dest(server, sock, broadcast, (void *)channel->id, SILC_ID_CHANNEL, SILC_NOTIFY_TYPE_CMODE_CHANGE, - 7, idp->data, idp->len, + 8, idp->data, idp->len, mode, 4, cipher, cipher ? strlen(cipher) : 0, hmac, hmac ? strlen(hmac) : 0, @@ -1331,7 +1333,11 @@ void silc_server_send_notify_cmode(SilcServer server, strlen(passphrase) : 0, fkey ? fkey->data : NULL, fkey ? fkey->len : 0, channel_pubkeys ? channel_pubkeys->data : NULL, - channel_pubkeys ? channel_pubkeys->len : 0); + channel_pubkeys ? channel_pubkeys->len : 0, + mode_mask & SILC_CHANNEL_MODE_ULIMIT ? + ulimit : NULL, + mode_mask & SILC_CHANNEL_MODE_ULIMIT ? + sizeof(ulimit) : 0); silc_buffer_free(fkey); silc_buffer_free(idp); } diff --git a/apps/silcd/server.c b/apps/silcd/server.c index 083206bc..3c26fcf5 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -982,7 +982,7 @@ SILC_TASK_CALLBACK(silc_server_connection_established) silc_schedule_task_del_by_fd(server->schedule, sock); silc_schedule_unset_listen_fd(server->schedule, sock); - if (silc_net_get_socket_opt(sock, SOL_SOCKET, SO_ERROR, &opt, &optlen) || + if (silc_net_get_socket_opt(sock, SOL_SOCKET, SO_ERROR, &opt, &optlen) || (opt != 0)) { SILC_LOG_ERROR(("Could not connect to router %s:%d: %s", sconn->remote_host, sconn->remote_port, @@ -4615,7 +4615,7 @@ void silc_server_announce_get_channel_users(SilcServer server, SilcBuffer chidp, clidp, csidp; SilcBuffer tmp, fkey = NULL, chpklist; int len; - unsigned char mode[4]; + unsigned char mode[4], ulimit[4]; char *hmac; SILC_LOG_DEBUG(("Start")); @@ -4626,12 +4626,14 @@ void silc_server_announce_get_channel_users(SilcServer server, /* CMODE notify */ SILC_PUT32_MSB(channel->mode, mode); + if (channel->mode & SILC_CHANNEL_MODE_ULIMIT) + SILC_PUT32_MSB(channel->user_limit, ulimit); hmac = channel->hmac ? (char *)silc_hmac_get_name(channel->hmac) : NULL; if (channel->founder_key) fkey = silc_pkcs_public_key_payload_encode(channel->founder_key); tmp = silc_server_announce_encode_notify(SILC_NOTIFY_TYPE_CMODE_CHANGE, - 7, csidp->data, csidp->len, + 8, csidp->data, csidp->len, mode, sizeof(mode), NULL, 0, hmac, hmac ? strlen(hmac) : 0, @@ -4641,7 +4643,13 @@ void silc_server_announce_get_channel_users(SilcServer server, fkey ? fkey->data : NULL, fkey ? fkey->len : 0, chpklist ? chpklist->data : NULL, - chpklist ? chpklist->len : 0); + chpklist ? chpklist->len : 0, + (channel->mode & + SILC_CHANNEL_MODE_ULIMIT ? + ulimit : NULL), + (channel->mode & + SILC_CHANNEL_MODE_ULIMIT ? + sizeof(ulimit) : 0)); len = tmp->len; *channel_modes = silc_buffer_realloc(*channel_modes, diff --git a/apps/silcd/server_util.c b/apps/silcd/server_util.c index ab824897..048757d3 100644 --- a/apps/silcd/server_util.c +++ b/apps/silcd/server_util.c @@ -2274,7 +2274,7 @@ SilcStatus silc_server_set_channel_pk_list(SilcServer server, if (chpk && type == 0x03 && channel->channel_pubkeys && server->server_type != SILC_ROUTER) { SilcBuffer sidp; - unsigned char mask[4]; + unsigned char mask[4], ulimit[4]; SILC_LOG_DEBUG(("Router enforces its list, remove old list")); silc_hash_table_free(channel->channel_pubkeys); @@ -2283,8 +2283,10 @@ SilcStatus silc_server_set_channel_pk_list(SilcServer server, /* Send notify that removes the old list */ sidp = silc_id_payload_encode(server->id, SILC_ID_SERVER); SILC_PUT32_MSB((channel->mode & (~SILC_CHANNEL_MODE_CHANNEL_AUTH)), mask); + if (channel->mode & SILC_CHANNEL_MODE_ULIMIT) + SILC_PUT32_MSB(channel->user_limit, ulimit); silc_server_send_notify_to_channel(server, NULL, channel, FALSE, TRUE, - SILC_NOTIFY_TYPE_CMODE_CHANGE, 7, + SILC_NOTIFY_TYPE_CMODE_CHANGE, 8, sidp->data, sidp->len, mask, 4, channel->cipher, @@ -2296,7 +2298,13 @@ SilcStatus silc_server_set_channel_pk_list(SilcServer server, channel->passphrase, channel->passphrase ? strlen(channel->passphrase) : 0, - NULL, 0, NULL, 0); + NULL, 0, NULL, 0, + (channel->mode & + SILC_CHANNEL_MODE_ULIMIT ? + ulimit : NULL), + (channel->mode & + SILC_CHANNEL_MODE_ULIMIT ? + sizeof(ulimit) : 0)); silc_buffer_free(sidp); }