has more than one ID set - take them all. */
*client_id = silc_calloc(1, sizeof(**client_id));
- (*client_id)[0] = silc_id_payload_parse_id(tmp, len);
+ (*client_id)[0] = silc_id_payload_parse_id(tmp, len, NULL);
if ((*client_id)[0] == NULL) {
silc_free(*client_id);
silc_server_command_send_status_reply(cmd, command,
if (tmp) {
*client_id = silc_realloc(*client_id, sizeof(**client_id) *
(*client_id_count + 1));
- (*client_id)[k] = silc_id_payload_parse_id(tmp, len);
+ (*client_id)[k] = silc_id_payload_parse_id(tmp, len, NULL);
if ((*client_id)[k] == NULL) {
/* Cleanup all and fail */
for (i = 0; i < *client_id_count; i++)
/* Get Channel ID */
tmp = silc_argument_get_arg_type(cmd->args, 1, &tmp_len);
if (tmp) {
- channel_id = silc_id_payload_parse_id(tmp, tmp_len);
+ channel_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
if (!channel_id) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_LIST,
SILC_STATUS_ERR_NO_CHANNEL_ID);
SILC_STATUS_ERR_NO_CHANNEL_ID);
goto out;
}
- channel_id = silc_id_payload_parse_id(tmp, tmp_len);
+ channel_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
if (!channel_id) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_TOPIC,
SILC_STATUS_ERR_NO_CHANNEL_ID);
}
/* See whether the client is on channel and has rights to change topic */
- if (!silc_hash_table_find(channel->user_list, client, NULL,
- (void *)&chl)) {
+ if (!silc_server_client_on_channel(client, channel, &chl)) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_TOPIC,
SILC_STATUS_ERR_NOT_ON_CHANNEL);
goto out;
}
- 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;
- }
+ if (chl->mode == SILC_CHANNEL_UMODE_NONE &&
+ channel->mode & SILC_CHANNEL_MODE_TOPIC) {
+ silc_server_command_send_status_reply(cmd, SILC_COMMAND_TOPIC,
+ SILC_STATUS_ERR_NO_CHANNEL_PRIV);
+ goto out;
}
/* Set the topic for channel */
SILC_STATUS_ERR_NO_CHANNEL_ID);
goto out;
}
- channel_id = silc_id_payload_parse_id(tmp, len);
+ channel_id = silc_id_payload_parse_id(tmp, len, NULL);
if (!channel_id) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_INVITE,
SILC_STATUS_ERR_NO_CHANNEL_ID);
/* Check whether the sender of this command is on the channel. */
sender = (SilcClientEntry)sock->user_data;
- if (!silc_server_client_on_channel(sender, channel)) {
+ if (!silc_server_client_on_channel(sender, channel, &chl)) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_INVITE,
SILC_STATUS_ERR_NOT_ON_CHANNEL);
goto out;
/* Check whether the channel is invite-only channel. If yes then the
sender of this command must be at least channel operator. */
- if (channel->mode & SILC_CHANNEL_MODE_INVITE) {
- silc_hash_table_find(channel->user_list, sender, NULL, (void *)&chl);
- if (chl->mode == SILC_CHANNEL_UMODE_NONE) {
- silc_server_command_send_status_reply(cmd, SILC_COMMAND_INVITE,
+ if (chl->mode == SILC_CHANNEL_UMODE_NONE &&
+ channel->mode & SILC_CHANNEL_MODE_INVITE) {
+ silc_server_command_send_status_reply(cmd, SILC_COMMAND_INVITE,
SILC_STATUS_ERR_NO_CHANNEL_PRIV);
- goto out;
- }
+ goto out;
}
/* Get destination client ID */
char invite[512];
bool resolve;
- dest_id = silc_id_payload_parse_id(tmp, len);
+ dest_id = silc_id_payload_parse_id(tmp, len, NULL);
if (!dest_id) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_INVITE,
SILC_STATUS_ERR_NO_CLIENT_ID);
}
/* Check whether the requested client is already on the channel. */
- if (silc_server_client_on_channel(dest, channel)) {
+ if (silc_server_client_on_channel(dest, channel, NULL)) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_INVITE,
SILC_STATUS_ERR_USER_ON_CHANNEL);
goto out;
SILC_STATUS_ERR_NOT_ENOUGH_PARAMS);
goto out;
}
- client_id = silc_id_payload_parse_id(tmp, tmp_len);
+ client_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
if (!client_id) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_KILL,
SILC_STATUS_ERR_NO_SUCH_CLIENT_ID);
/* Get Server ID */
tmp = silc_argument_get_arg_type(cmd->args, 2, &tmp_len);
if (tmp) {
- server_id = silc_id_payload_parse_id(tmp, tmp_len);
+ server_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
if (!server_id) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_INFO,
SILC_STATUS_ERR_NO_SERVER_ID);
void *auth_data = (channel->founder_method == SILC_AUTH_PASSWORD ?
(void *)channel->founder_passwd :
(void *)channel->founder_key);
- SilcUInt32 auth_data_len = (channel->founder_method == SILC_AUTH_PASSWORD ?
- channel->founder_passwd_len : 0);
+ SilcUInt32 auth_data_len =
+ (channel->founder_method == SILC_AUTH_PASSWORD ?
+ channel->founder_passwd_len : 0);
/* Check whether the client is to become founder */
if (silc_auth_verify_data(auth, auth_len, channel->founder_method,
*/
/* Check whether the client already is on the channel */
- if (silc_server_client_on_channel(client, channel)) {
+ if (silc_server_client_on_channel(client, channel, NULL)) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_JOIN,
SILC_STATUS_ERR_USER_ON_CHANNEL);
goto out;
SILC_STATUS_ERR_NOT_ENOUGH_PARAMS);
goto out;
}
- client_id = silc_id_payload_parse_id(tmp, tmp_len);
+ client_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
if (!client_id) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_JOIN,
SILC_STATUS_ERR_NOT_ENOUGH_PARAMS);
}
SILC_GET32_MSB(mask, tmp_mask);
- /*
- * Change the mode
- */
-
- if (mask & SILC_UMODE_SERVER_OPERATOR) {
- if (!(client->mode & SILC_UMODE_SERVER_OPERATOR)) {
- /* Cannot operator mode */
- silc_server_command_send_status_reply(cmd, SILC_COMMAND_UMODE,
- SILC_STATUS_ERR_PERM_DENIED);
- goto out;
- }
- } else {
- /* Remove the server operator rights */
- if (client->mode & SILC_UMODE_SERVER_OPERATOR) {
- client->mode &= ~SILC_UMODE_SERVER_OPERATOR;
- if (client->connection)
- server->stat.my_server_ops--;
- if (server->server_type == SILC_ROUTER)
- server->stat.server_ops--;
- }
- }
-
- if (mask & SILC_UMODE_ROUTER_OPERATOR) {
- if (!(client->mode & SILC_UMODE_ROUTER_OPERATOR)) {
- /* Cannot operator mode */
- silc_server_command_send_status_reply(cmd, SILC_COMMAND_UMODE,
- SILC_STATUS_ERR_PERM_DENIED);
- goto out;
- }
- } else {
- /* Remove the router operator rights */
- if (client->mode & SILC_UMODE_ROUTER_OPERATOR) {
- client->mode &= ~SILC_UMODE_ROUTER_OPERATOR;
- if (client->connection)
- server->stat.my_router_ops--;
- if (server->server_type == SILC_ROUTER)
- server->stat.router_ops--;
- }
+ /* Check that mode changing is allowed. */
+ if (!silc_server_check_umode_rights(server, client, mask)) {
+ silc_server_command_send_status_reply(cmd, SILC_COMMAND_UMODE,
+ SILC_STATUS_ERR_PERM_DENIED);
+ goto out;
}
- if (mask & SILC_UMODE_GONE) {
- client->mode |= SILC_UMODE_GONE;
- } else {
- if (client->mode & SILC_UMODE_GONE)
- /* Remove the gone status */
- client->mode &= ~SILC_UMODE_GONE;
- }
+ /* Change the mode */
+ client->mode = mask;
/* Send UMODE change to primary router */
if (!server->standalone)
silc_server_command_free(cmd);
}
-/* Checks that client has rights to add or remove channel modes. If any
- of the checks fails FALSE is returned. */
-
-int silc_server_check_cmode_rights(SilcChannelEntry channel,
- SilcChannelClientEntry client,
- SilcUInt32 mode)
-{
- int is_op = client->mode & SILC_CHANNEL_UMODE_CHANOP;
- int is_fo = client->mode & SILC_CHANNEL_UMODE_CHANFO;
-
- /* Check whether has rights to change anything */
- if (!is_op && !is_fo)
- return FALSE;
-
- /* Check whether has rights to change everything */
- if (is_op && is_fo)
- return TRUE;
-
- /* We know that client is channel operator, check that they are not
- changing anything that requires channel founder rights. Rest of the
- modes are available automatically for channel operator. */
-
- if (mode & SILC_CHANNEL_MODE_PRIVKEY) {
- if (!(channel->mode & SILC_CHANNEL_MODE_PRIVKEY))
- if (is_op && !is_fo)
- return FALSE;
- } else {
- if (channel->mode & SILC_CHANNEL_MODE_PRIVKEY) {
- if (is_op && !is_fo)
- return FALSE;
- }
- }
-
- if (mode & SILC_CHANNEL_MODE_PASSPHRASE) {
- if (!(channel->mode & SILC_CHANNEL_MODE_PASSPHRASE))
- if (is_op && !is_fo)
- return FALSE;
- } else {
- if (channel->mode & SILC_CHANNEL_MODE_PASSPHRASE) {
- if (is_op && !is_fo)
- return FALSE;
- }
- }
-
- if (mode & SILC_CHANNEL_MODE_CIPHER) {
- if (!(channel->mode & SILC_CHANNEL_MODE_CIPHER))
- if (is_op && !is_fo)
- return FALSE;
- } else {
- if (channel->mode & SILC_CHANNEL_MODE_CIPHER) {
- if (is_op && !is_fo)
- return FALSE;
- }
- }
-
- if (mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) {
- if (!(channel->mode & SILC_CHANNEL_MODE_FOUNDER_AUTH))
- if (is_op && !is_fo)
- return FALSE;
- } else {
- if (channel->mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) {
- if (is_op && !is_fo)
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
/* Server side command of CMODE. Changes channel mode */
SILC_SERVER_CMD_FUNC(cmode)
SILC_STATUS_ERR_NO_CHANNEL_ID);
goto out;
}
- channel_id = silc_id_payload_parse_id(tmp_id, tmp_len2);
+ 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);
}
/* Check whether this client is on the channel */
- if (!silc_server_client_on_channel(client, channel)) {
+ if (!silc_server_client_on_channel(client, channel, &chl)) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_CMODE,
SILC_STATUS_ERR_NOT_ON_CHANNEL);
goto out;
}
- /* Get entry to the channel user list */
- silc_hash_table_find(channel->user_list, client, NULL, (void *)&chl);
-
/* Check that client has rights to change any requested channel modes */
- if (!silc_server_check_cmode_rights(channel, chl, mode_mask)) {
+ if (!silc_server_check_cmode_rights(server, channel, chl, mode_mask)) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_CMODE,
SILC_STATUS_ERR_NO_CHANNEL_PRIV);
goto out;
SILC_STATUS_ERR_NO_CHANNEL_ID);
goto out;
}
- channel_id = silc_id_payload_parse_id(tmp_ch_id, tmp_ch_len);
+ channel_id = silc_id_payload_parse_id(tmp_ch_id, tmp_ch_len, NULL);
if (!channel_id) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_CUMODE,
SILC_STATUS_ERR_NO_CHANNEL_ID);
}
/* Check whether sender is on the channel */
- if (!silc_server_client_on_channel(client, channel)) {
+ if (!silc_server_client_on_channel(client, channel, &chl)) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_CUMODE,
SILC_STATUS_ERR_NOT_ON_CHANNEL);
goto out;
}
-
- /* Check that client has rights to change other's rights */
- silc_hash_table_find(channel->user_list, client, NULL, (void *)&chl);
sender_mask = chl->mode;
/* Get the target client's channel mode mask */
SILC_STATUS_ERR_NO_CLIENT_ID);
goto out;
}
- client_id = silc_id_payload_parse_id(tmp_id, tmp_len);
+ client_id = silc_id_payload_parse_id(tmp_id, tmp_len, NULL);
if (!client_id) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_CUMODE,
SILC_STATUS_ERR_NO_CLIENT_ID);
/* Check whether target client is on the channel */
if (target_client != client) {
- if (!silc_server_client_on_channel(target_client, channel)) {
+ if (!silc_server_client_on_channel(target_client, channel, &chl)) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_CUMODE,
SILC_STATUS_ERR_USER_NOT_ON_CHANNEL);
goto out;
}
-
- /* Get entry to the channel user list */
- silc_hash_table_find(channel->user_list, target_client, NULL,
- (void *)&chl);
}
/*
SILC_STATUS_ERR_NO_CHANNEL_ID);
goto out;
}
- channel_id = silc_id_payload_parse_id(tmp, tmp_len);
+ channel_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
if (!channel_id) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_KICK,
SILC_STATUS_ERR_NO_CHANNEL_ID);
}
/* Check whether sender is on the channel */
- if (!silc_server_client_on_channel(client, channel)) {
+ if (!silc_server_client_on_channel(client, channel, &chl)) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_KICK,
SILC_STATUS_ERR_NOT_ON_CHANNEL);
goto out;
}
/* Check that the kicker is channel operator or channel founder */
- silc_hash_table_find(channel->user_list, client, NULL, (void *)&chl);
if (chl->mode == SILC_CHANNEL_UMODE_NONE) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_KICK,
SILC_STATUS_ERR_NO_CHANNEL_PRIV);
SILC_STATUS_ERR_NO_CLIENT_ID);
goto out;
}
- client_id = silc_id_payload_parse_id(target_idp, target_idp_len);
+ client_id = silc_id_payload_parse_id(target_idp, target_idp_len, NULL);
if (!client_id) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_KICK,
SILC_STATUS_ERR_NO_CLIENT_ID);
client_id, TRUE, NULL);
}
+ /* Check whether target client is on the channel */
+ if (!silc_server_client_on_channel(target_client, channel, &chl)) {
+ silc_server_command_send_status_reply(cmd, SILC_COMMAND_KICK,
+ SILC_STATUS_ERR_USER_NOT_ON_CHANNEL);
+ goto out;
+ }
+
/* Check that the target client is not channel founder. Channel founder
cannot be kicked from the channel. */
- silc_hash_table_find(channel->user_list, target_client, NULL, (void *)&chl);
if (chl->mode & SILC_CHANNEL_UMODE_CHANFO) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_KICK,
SILC_STATUS_ERR_NO_CHANNEL_FOPRIV);
goto out;
}
- /* Check whether target client is on the channel */
- if (!silc_server_client_on_channel(target_client, channel)) {
- silc_server_command_send_status_reply(cmd, SILC_COMMAND_KICK,
- SILC_STATUS_ERR_USER_NOT_ON_CHANNEL);
- goto out;
- }
-
/* Get comment */
tmp_len = 0;
comment = silc_argument_get_arg_type(cmd->args, 3, &tmp_len);
/* Get Channel ID */
id = silc_argument_get_arg_type(cmd->args, 1, &id_len);
if (id) {
- channel_id = silc_id_payload_parse_id(id, id_len);
+ channel_id = silc_id_payload_parse_id(id, id_len, NULL);
if (!channel_id) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_BAN,
SILC_STATUS_ERR_NO_CHANNEL_ID);
}
/* Check whether this client is on the channel */
- if (!silc_server_client_on_channel(client, channel)) {
- silc_server_command_send_status_reply(cmd, SILC_COMMAND_BAN,
- SILC_STATUS_ERR_NOT_ON_CHANNEL);
- goto out;
- }
-
- /* Get entry to the channel user list */
- if (!silc_hash_table_find(channel->user_list, client, NULL, (void *)&chl)) {
+ if (!silc_server_client_on_channel(client, channel, &chl)) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_BAN,
SILC_STATUS_ERR_NOT_ON_CHANNEL);
goto out;
SILC_STATUS_ERR_NO_CHANNEL_ID);
goto out;
}
- id = silc_id_payload_parse_id(tmp, len);
+ id = silc_id_payload_parse_id(tmp, len, NULL);
if (!id) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_LEAVE,
SILC_STATUS_ERR_NO_CHANNEL_ID);
}
/* Check whether this client is on the channel */
- if (!silc_server_client_on_channel(id_entry, channel)) {
+ if (!silc_server_client_on_channel(id_entry, channel, NULL)) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_LEAVE,
SILC_STATUS_ERR_NOT_ON_CHANNEL);
goto out;
}
if (channel_id) {
- id = silc_id_payload_parse_id(channel_id, channel_id_len);
+ id = silc_id_payload_parse_id(channel_id, channel_id_len, NULL);
if (!id) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_USERS,
SILC_STATUS_ERR_NO_CHANNEL_ID);
user requesting this command is on the channel. */
if (cmd->sock->type == SILC_SOCKET_TYPE_CLIENT) {
if (channel->mode & (SILC_CHANNEL_MODE_PRIVATE | SILC_CHANNEL_MODE_SECRET)
- && !silc_server_client_on_channel(cmd->sock->user_data, channel)) {
+ && !silc_server_client_on_channel(cmd->sock->user_data, channel,
+ NULL)) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_USERS,
SILC_STATUS_ERR_NO_SUCH_CHANNEL);
goto out;