X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=apps%2Fsilcd%2Fcommand.c;h=9ceb7caaf403e11568a81a0eaffc75e3bdf69b07;hb=2407b5a8d55101dcc4cccb098888e0e21f6f299c;hp=11e930370cf9a98f9a45daf6eb015055670fa035;hpb=9a3e485d73ab5455dd6e2d0f76e684a70f847d8b;p=silc.git diff --git a/apps/silcd/command.c b/apps/silcd/command.c index 11e93037..9ceb7caa 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -131,7 +131,6 @@ static int silc_server_is_registered(SilcServer server, silc_server_command_send_status_reply(cmd, command, SILC_STATUS_ERR_NOT_REGISTERED); - silc_server_command_free(cmd); return FALSE; } @@ -149,6 +148,11 @@ SILC_TASK_CALLBACK(silc_server_command_process_timeout) SilcServerCommandTimeout timeout = (SilcServerCommandTimeout)context; SilcClientEntry client = (SilcClientEntry)timeout->ctx->sock->user_data; + if (!client) { + silc_server_command_free(timeout->ctx); + silc_free(timeout); + } + /* Update access time */ client->last_command = time(NULL); @@ -159,6 +163,8 @@ SILC_TASK_CALLBACK(silc_server_command_process_timeout) timeout->ctx, timeout->cmd->cmd)) timeout->cmd->cb(timeout->ctx, NULL); + else + silc_server_command_free(timeout->ctx); silc_free(timeout); } @@ -233,15 +239,12 @@ void silc_server_command_process(SilcServer server, silc_server_command_process_timeout, (void *)timeout, 2 - (time(NULL) - client->last_command), 0, - SILC_TASK_TIMEOUT, - SILC_TASK_PRI_NORMAL); + SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL); else silc_schedule_task_add(server->schedule, sock->sock, silc_server_command_process_timeout, - (void *)timeout, - 0, 1, - SILC_TASK_TIMEOUT, - SILC_TASK_PRI_NORMAL); + (void *)timeout, 0, 1, + SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL); return; } @@ -251,6 +254,8 @@ void silc_server_command_process(SilcServer server, cmd->cb(ctx, NULL); else if (silc_server_is_registered(server, sock, ctx, cmd->cmd)) cmd->cb(ctx, NULL); + else + silc_server_command_free(ctx); } /* Allocate Command Context */ @@ -561,6 +566,8 @@ silc_server_command_whois_check(SilcServerCommandContext cmd, int i, k; bool no_res = TRUE; + SILC_LOG_DEBUG(("Start")); + for (i = 0; i < clients_count; i++) { entry = clients[i]; if (!entry) @@ -1059,7 +1066,6 @@ silc_server_command_whowas_check(SilcServerCommandContext cmd, silc_server_command_whowas, silc_server_command_dup(cmd)); cmd->pending = TRUE; - silc_command_set_ident(cmd->payload, old_ident); silc_buffer_free(tmpbuf); @@ -1193,7 +1199,6 @@ silc_server_command_whowas_process(SilcServerCommandContext cmd) silc_server_command_whowas, silc_server_command_dup(cmd)); cmd->pending = TRUE; - silc_command_set_ident(cmd->payload, old_ident); silc_buffer_free(tmpbuf); @@ -2657,6 +2662,7 @@ SILC_SERVER_CMD_FUNC(kill) SilcClientID *client_id; unsigned char *tmp, *comment; uint32 tmp_len, tmp_len2; + bool local; SILC_SERVER_COMMAND_CHECK(SILC_COMMAND_KILL, cmd, 1, 2); @@ -2694,9 +2700,11 @@ SILC_SERVER_CMD_FUNC(kill) /* Get the client entry */ remote_client = silc_idlist_find_client_by_id(server->local_list, client_id, TRUE, NULL); + local = TRUE; if (!remote_client) { remote_client = silc_idlist_find_client_by_id(server->global_list, client_id, TRUE, NULL); + local = FALSE; if (!remote_client) { silc_server_command_send_status_reply(cmd, SILC_COMMAND_KILL, SILC_STATUS_ERR_NO_SUCH_CLIENT_ID); @@ -2750,9 +2758,17 @@ SILC_SERVER_CMD_FUNC(kill) silc_server_free_client_data(server, sock, remote_client, FALSE, NULL); silc_server_close_connection(server, sock); } else { + /* Update statistics */ + if (remote_client->connection) + server->stat.my_clients--; + if (server->server_type == SILC_ROUTER) + server->stat.cell_clients--; + SILC_OPER_STATS_UPDATE(remote_client, server, SILC_UMODE_SERVER_OPERATOR); + SILC_OPER_STATS_UPDATE(remote_client, router, SILC_UMODE_ROUTER_OPERATOR); + /* Remove remote client */ - if (!silc_idlist_del_client(server->global_list, remote_client)) - silc_idlist_del_client(server->local_list, remote_client); + silc_idlist_del_client(local ? server->local_list : + server->global_list, remote_client); } out: @@ -3380,6 +3396,7 @@ SILC_SERVER_CMD_FUNC(join) silc_server_command_join, silc_server_command_dup(cmd)); cmd->pending = TRUE; + silc_command_set_ident(cmd->payload, old_ident); goto out; } @@ -3443,7 +3460,8 @@ SILC_SERVER_CMD_FUNC(join) if (silc_command_get(reply->payload) == SILC_COMMAND_JOIN) { tmp = silc_argument_get_arg_type(reply->args, 6, NULL); SILC_GET32_MSB(created, tmp); - create_key = FALSE; /* Router returned the key already */ + if (silc_argument_get_arg_type(reply->args, 7, NULL) + create_key = FALSE; /* Router returned the key already */ } if (silc_command_get(reply->payload) == SILC_COMMAND_WHOIS && @@ -3640,9 +3658,14 @@ SILC_SERVER_CMD_FUNC(umode) goto out; } } else { - if (client->mode & SILC_UMODE_SERVER_OPERATOR) - /* Remove the server operator rights */ + /* 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) { @@ -3653,9 +3676,14 @@ SILC_SERVER_CMD_FUNC(umode) goto out; } } else { - if (client->mode & SILC_UMODE_ROUTER_OPERATOR) - /* Remove the router operator rights */ + /* 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--; + } } if (mask & SILC_UMODE_GONE) { @@ -3838,22 +3866,22 @@ SILC_SERVER_CMD_FUNC(cmode) /* The mode is removed and we need to generate and distribute new channel key. Clients are not using private channel keys anymore after this. */ - + /* Re-generate channel key */ if (!silc_server_create_channel_key(server, channel, 0)) goto out; - + /* Send the channel key. This sends it to our local clients and if we are normal server to our router as well. */ silc_server_send_channel_key(server, NULL, channel, server->server_type == SILC_ROUTER ? FALSE : !server->standalone); - + cipher = channel->channel_key->cipher->name; hmac = (char *)silc_hmac_get_name(channel->hmac); } } - + if (mode_mask & SILC_CHANNEL_MODE_ULIMIT) { /* User limit is set on channel */ uint32 user_limit; @@ -4590,6 +4618,12 @@ SILC_SERVER_CMD_FUNC(oper) /* Client is now server operator */ client->mode |= SILC_UMODE_SERVER_OPERATOR; + /* Update statistics */ + if (client->connection) + server->stat.my_server_ops++; + if (server->server_type == SILC_ROUTER) + server->stat.server_ops++; + /* Send UMODE change to primary router */ if (!server->standalone) silc_server_send_notify_umode(server, server->router->connection, TRUE, @@ -4668,6 +4702,12 @@ SILC_SERVER_CMD_FUNC(silcoper) /* Client is now router operator */ client->mode |= SILC_UMODE_ROUTER_OPERATOR; + /* Update statistics */ + if (client->connection) + server->stat.my_router_ops++; + if (server->server_type == SILC_ROUTER) + server->stat.router_ops++; + /* Send UMODE change to primary router */ if (!server->standalone) silc_server_send_notify_umode(server, server->router->connection, TRUE, @@ -4790,7 +4830,11 @@ SILC_SERVER_CMD_FUNC(ban) } /* Get entry to the channel user list */ - silc_hash_table_find(channel->user_list, client, NULL, (void *)&chl); + if (!silc_hash_table_find(channel->user_list, client, NULL, (void *)&chl)) { + silc_server_command_send_status_reply(cmd, SILC_COMMAND_BAN, + SILC_STATUS_ERR_NOT_ON_CHANNEL); + goto out; + } /* The client must be at least channel operator. */ if (!(chl->mode & SILC_CHANNEL_UMODE_CHANOP)) { @@ -4851,7 +4895,7 @@ SILC_SERVER_CMD_FUNC(ban) 2, id, id_len, 3, channel->ban_list, channel->ban_list ? - strlen(channel->ban_list) - 1 : 0); + strlen(channel->ban_list) : 0); silc_server_packet_send(server, cmd->sock, SILC_PACKET_COMMAND_REPLY, 0, packet->data, packet->len, FALSE); @@ -5323,7 +5367,6 @@ SILC_SERVER_CMD_FUNC(getkey) silc_server_command_getkey, silc_server_command_dup(cmd)); cmd->pending = TRUE; - silc_command_set_ident(cmd->payload, old_ident); silc_buffer_free(tmpbuf); goto out;