Definition in file botnet.h.
#include <string>
#include <map>
#include "ssl.h"
Include dependency graph for botnet.h:
This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Functions | |
void | botnet_admin_msg (string user_mask, string bot_mask, string msg) |
Sends admin message (for command "admin_msg" in file "logic.txt"). | |
void | botnet_link (string botname, string localip, string botip, unsigned short botport, string remote_MD5_password, string bot_link_type, string unlink_proc, map< string, string > vars) |
Links to new bot. | |
void | botnet_loop () |
Process the communication with other bots, this should be called in loop. | |
string | botnet_partyline_join_channel (string user, string channel) |
Called from partyline, when user connected to this bot is joining partline channel. | |
void | botnet_partyline_leave_channel (string user, string channel) |
Called from partyline, when user connected to this bot is leaving partline channel. | |
void | botnet_partyline_message (string user, string channel, string msg) |
Called from partyline, when user connected to this bot is writing a message to partline channel. | |
void | botnet_received_data_from_telnet (s_socket &socket, string botname, char *buff, size_t buff_size, SSL *ssl, string remote_ip) |
Called when remote bot connects via telnet. | |
string | botnet_remote_procedure_call (string botname, string proc_name_only, list< string > &args) |
Sends to other bot remote procedure call request. | |
string | botnet_showbots (string lang, string eol) |
Used for partyline to show connected bots (.showbots). |
|
Sends admin message (for command "admin_msg" in file "logic.txt").
Definition at line 8909 of file botnet.cpp. References botnet_botname, and botnet_partyline_message(). Referenced by logic_exec(). 08910 { 08911 string c="\x01" "BROADCAST_ADMIN_MESSAGE\x01 * * "; 08912 c+=bot_mask; 08913 c+=" "; 08914 c+=user_mask; 08915 c+=" "; 08916 c+=msg; 08917 08918 botnet_partyline_message(botnet_botname,"",c); 08919 }
Here is the call graph for this function: ![]() |
|
Links to new bot.
Definition at line 1698 of file botnet.cpp. References s_bot::auth_ok, s_bot::botip, s_bot::botname, s_bot::botport, bots, s_bot::buff_size_from_dcc, s_socket::clear(), s_bot::clear(), s_bot::command_receive_buffer, s_bot::control_receive_buffer, s_bot::got_bytes, s_bot_control::hard_clear(), s_bot_command::hard_clear(), s_bot::invoked_from_telnet, s_bot::last_try, s_bot::localip, log_debug(), s_bot::receive_buffer_pos, s_bot::received_bot_auth_1, s_bot::remote_MD5_password, s_bot::remote_pswd_ok, s_bot::sent_bot_auth_1, s_bot::socket, s_bot::ssl, ssl_close(), s_bot::ssl_connection, s_bot::unlink_proc, s_bot::unlink_proc_called, s_bot::vars, and s_bot::was_linked. Referenced by logic_exec(). 01699 { 01700 if(bot_link_type.compare("telnet") && bot_link_type.compare("telnet_ssl")) { 01701 log_debug("in file " __FILE__ " in function " __FUNC__ " occurred error: Unknown link type (PANIC!) - assuming \"telnet\""); 01702 } 01703 01704 bool got=false; 01705 bool got_one=false; 01706 vector<s_bot*>::iterator i1; 01707 label: 01708 for(i1=bots.begin(); i1!=bots.end(); i1++) 01709 if(!(*i1)->botname.compare(botname)) { 01710 // we already got link bot in the vector 01711 got_one=true; 01712 if((*i1)->socket.cmp()==false && !(*i1)->waiting) { 01713 if((*i1)->ssl_connection) { 01714 ssl_close((*i1)->ssl,&((*i1)->socket)); 01715 } 01716 delete *i1; 01717 bots.erase(i1); 01718 goto label; 01719 } 01720 got=true; 01721 //(*i1)->unlink_proc_called=false; 01722 } 01723 if(got || got_one) 01724 return; 01725 01726 s_bot* s=new s_bot; 01727 s->clear(); 01728 s->botname=""; 01729 s->localip=""; 01730 s->botip=""; 01731 s->botport=0; 01732 s->socket.clear(); 01733 s->remote_MD5_password=""; 01734 s->sent_bot_auth_1=false; 01735 s->received_bot_auth_1=false; 01736 s->receive_buffer_pos=0; 01737 01738 s->buff_size_from_dcc=0; 01739 01740 s->botname=botname; 01741 s->localip=localip; 01742 s->botip=botip; 01743 s->botport=botport; 01744 s->socket.clear(); 01745 s->remote_MD5_password=remote_MD5_password; 01746 01747 s->command_receive_buffer.hard_clear(); 01748 s->control_receive_buffer.hard_clear(); 01749 s->receive_buffer_pos=0; 01750 01751 s->unlink_proc=unlink_proc; 01752 s->vars=vars; 01753 s->unlink_proc_called=false; 01754 01755 s->got_bytes=0; 01756 s->auth_ok=false; 01757 s->remote_pswd_ok=false; 01758 s->was_linked=false; 01759 s->last_try=0x7FFFFFFF; 01760 s->invoked_from_telnet=false; 01761 01762 s->ssl_connection=!bot_link_type.compare("telnet_ssl"); 01763 s->ssl=NULL; 01764 01765 bots.push_back(s); 01766 }
Here is the call graph for this function: ![]() |
|
Process the communication with other bots, this should be called in loop.
Definition at line 3892 of file botnet.cpp. References s_bot_command::u_commnd_data::s_cmd_repl_user_17_9::access_grant_apply, s_user::access_grant_apply, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::access_grant_backup, s_user::access_grant_backup, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::access_grant_can_send_all_users, s_user::access_grant_can_send_all_users, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::access_grant_can_send_unknown_users, s_user::access_grant_can_send_unknown_users, s_bot_command::u_commnd_data::s_cmd_repl_user_09_1::access_grant_channel, s_user::access_grant_channel, s_user::access_grant_die, s_user::access_grant_filesystem, s_bot_command::u_commnd_data::s_cmd_repl_user_07_1::access_grant_group, s_user::access_grant_group, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::access_grant_partyline, s_user::access_grant_partyline, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::access_grant_plusproc, s_user::access_grant_plusproc, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::access_grant_plususer, s_user::access_grant_plususer, s_user::access_grant_private, s_bot_command::u_commnd_data::s_cmd_repl_user_06_1::access_grant_proc, s_user::access_grant_procedure, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::access_grant_rehash, s_user::access_grant_rehash, s_user::access_grant_replication, s_user::access_grant_restart, s_bot_command::u_commnd_data::s_cmd_repl_user_16_5::access_grant_upgrade, s_user::access_grant_upgrade, s_bot_command::u_commnd_data::s_cmd_repl_user_17_9::access_to_apply, s_user::access_to_apply, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::access_to_backup, s_user::access_to_backup, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::access_to_can_send_all_users, s_user::access_to_can_send_all_users, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::access_to_can_send_unknown_users, s_user::access_to_can_send_unknown_users, s_bot_command::u_commnd_data::s_cmd_repl_user_08_1::access_to_channel, s_user::access_to_channel, s_user::access_to_die, s_user::access_to_filesystem, s_bot_command::u_commnd_data::s_cmd_repl_user_04_1::access_to_group, s_user::access_to_group, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::access_to_partyline, s_user::access_to_partyline, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::access_to_plusproc, s_user::access_to_plusproc, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::access_to_plususer, s_user::access_to_plususer, s_user::access_to_private, s_bot_command::u_commnd_data::s_cmd_repl_user_05_1::access_to_proc, s_user::access_to_proc, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::access_to_rehash, s_user::access_to_rehash, s_user::access_to_replication, s_user::access_to_restart, s_bot_command::u_commnd_data::s_cmd_repl_user_16_5::access_to_upgrade, s_user::access_to_upgrade, s_bot_command::u_commnd_data::s_cmd_repl_user_15_1::access_usage_proc, s_user::access_usage_procedure, s_channel_def::allow_dynamic, s_bot_command::u_commnd_data::s_cmd_remote_procedure_call_3::args_array, s_bot_command::u_commnd_data::bot_auth_1, s_chan_def_to_push::botname, s_proc_to_push::botname, s_user_to_push::botname, s_bot_command::u_commnd_data::s_bot_auth_1::botname, s_chan_def_to_pull::botname, s_bot_command::u_commnd_data::s_cmd_partyline_user_1::botname, s_partyline_member::botname, s_bot_command::u_commnd_data::s_cmd_partyline_1::botname, s_proc_to_pull::botname, s_user_to_pull::botname, botnet_backup(), botnet_botname, botnet_channels, botnet_cleanup_ids(), botnet_get_unique_id(), botnet_has_grant(), botnet_last_rehash_request, botnet_on_unlink(), botnet_partyline_event(), botnet_penalty, botnet_push_chan(), botnet_push_proc(), botnet_push_prv(), botnet_push_user(), botnet_receive(), botnet_rehash(), botnet_send_command(), botnet_send_control(), bots, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::can_send_unknown_users, s_channel::can_send_unknown_users, s_chan_def_to_push::chan_name, s_chan_def_to_pull::chan_name, s_bot_command::u_commnd_data::s_cmd_partyline_user_1::channel, s_bot_command::u_commnd_data::s_cmd_partyline_1::channel, s_bot_command::u_commnd_data::s_cmd_repl_user_13_1::channel, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::channel, s_bot_command::u_commnd_data::s_cmd_push_1::channel_def, s_bot_command::u_commnd_data::s_check_time_1::channel_def, s_bot_command::u_commnd_data::s_no_repl_1::channel_def, s_botnet_channel::channel_name, s_channel::channel_name, s_channel_def::channel_name, s_chan_def_to_pull::chd, s_bot_command::u_commnd_data::check_time_1, s_channel::clear(), s_ssl_conf::client_cert, s_ssl_conf::client_key, CMD_AUTH_1, CMD_CHECK_TIME_1, CMD_NO_REPL_1, s_bot_command::u_commnd_data::cmd_partyline_1, CMD_PARTYLINE_1, s_bot_command::u_commnd_data::cmd_partyline_user_1, CMD_PARTYLINE_USER_1, s_bot_command::u_commnd_data::cmd_proc_1, CMD_PROC_1, s_bot_command::u_commnd_data::cmd_proc_end_1, CMD_PROC_END_1, s_bot_command::u_commnd_data::cmd_push_1, CMD_PUSH_1, s_bot_command::u_commnd_data::cmd_remote_procedure_call_3, CMD_REMOTE_PROCEDURE_CALL_3, s_bot_command::u_commnd_data::cmd_repl_chdef_01_1, CMD_REPL_CHDEF_01_1, s_bot_command::u_commnd_data::cmd_repl_chdef_02_1, CMD_REPL_CHDEF_02_1, s_bot_command::u_commnd_data::cmd_repl_chdef_03_1, CMD_REPL_CHDEF_03_1, s_bot_command::u_commnd_data::cmd_repl_chdef_04_1, CMD_REPL_CHDEF_04_1, s_bot_command::u_commnd_data::cmd_repl_chdef_05_1, CMD_REPL_CHDEF_05_1, s_bot_command::u_commnd_data::cmd_repl_chdef_06_8, CMD_REPL_CHDEF_06_8, s_bot_command::u_commnd_data::cmd_repl_chdef_99_1, CMD_REPL_CHDEF_99_1, s_bot_command::u_commnd_data::cmd_repl_prv_01_1, CMD_REPL_PRV_01_1, s_bot_command::u_commnd_data::cmd_repl_prv_02_1, CMD_REPL_PRV_02_1, s_bot_command::u_commnd_data::cmd_repl_prv_03_1, CMD_REPL_PRV_03_1, s_bot_command::u_commnd_data::cmd_repl_prv_04_7, CMD_REPL_PRV_04_7, s_bot_command::u_commnd_data::cmd_repl_prv_05_8, CMD_REPL_PRV_05_8, s_bot_command::u_commnd_data::cmd_repl_prv_06_11, CMD_REPL_PRV_06_11, CMD_REPL_PRV_99_1, s_bot_command::u_commnd_data::cmd_repl_user_01_1, CMD_REPL_USER_01_1, s_bot_command::u_commnd_data::cmd_repl_user_02_1, CMD_REPL_USER_02_1, s_bot_command::u_commnd_data::cmd_repl_user_03_1, CMD_REPL_USER_03_1, s_bot_command::u_commnd_data::cmd_repl_user_04_1, CMD_REPL_USER_04_1, s_bot_command::u_commnd_data::cmd_repl_user_05_1, CMD_REPL_USER_05_1, s_bot_command::u_commnd_data::cmd_repl_user_06_1, CMD_REPL_USER_06_1, s_bot_command::u_commnd_data::cmd_repl_user_07_1, CMD_REPL_USER_07_1, s_bot_command::u_commnd_data::cmd_repl_user_08_1, CMD_REPL_USER_08_1, s_bot_command::u_commnd_data::cmd_repl_user_09_1, CMD_REPL_USER_09_1, s_bot_command::u_commnd_data::cmd_repl_user_10_1, CMD_REPL_USER_10_1, s_bot_command::u_commnd_data::cmd_repl_user_11_1, CMD_REPL_USER_11_1, s_bot_command::u_commnd_data::cmd_repl_user_12_1, CMD_REPL_USER_12_1, s_bot_command::u_commnd_data::cmd_repl_user_13_1, CMD_REPL_USER_13_1, s_bot_command::u_commnd_data::cmd_repl_user_14_1, CMD_REPL_USER_14_1, s_bot_command::u_commnd_data::cmd_repl_user_15_1, CMD_REPL_USER_15_1, s_bot_command::u_commnd_data::cmd_repl_user_16_5, CMD_REPL_USER_16_5, s_bot_command::u_commnd_data::cmd_repl_user_17_9, CMD_REPL_USER_17_9, s_bot_command::u_commnd_data::cmd_repl_user_99_1, CMD_REPL_USER_99_1, s_bot_command::command, s_bot_command::command_data, conf_getvar(), s_bot_control::control, s_channel::ctcp_flood, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::ctcp_flood_l, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::ctcp_flood_s, CTRL_ERROR_001, CTRL_ERROR_002, CTRL_LINKED, CTRL_PING, CTRL_PONG, dcc_get_password(), s_bot_command::u_commnd_data::s_cmd_repl_user_11_1::dcc_group, s_bot_command::u_commnd_data::s_cmd_repl_user_11_1::dcc_host, s_user::dcc_hosts, dcc_users_to_lock_out, s_bot_command::u_commnd_data::s_bot_auth_1::digest, s_channel_def::dynamic_bans, s_bot_command::u_commnd_data::s_cmd_repl_chdef_01_1::dynamic_minus_modes, s_channel_def::dynamic_minus_modes, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::dynamic_minus_modes, s_channel::dynamic_minus_modes, s_bot_command::u_commnd_data::s_cmd_repl_chdef_01_1::dynamic_plus_modes, s_channel_def::dynamic_plus_modes, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::dynamic_plus_modes, s_channel::dynamic_plus_modes, s_channel_def::dynbans_editors, s_bot_command::u_commnd_data::s_cmd_repl_user_03_1::fullname, s_user::fullname, s_bot_command::u_commnd_data::s_cmd_repl_chdef_05_1::group, s_bot_command::u_commnd_data::s_cmd_repl_chdef_03_1::group, s_bot_command::u_commnd_data::s_cmd_repl_chdef_02_1::group, s_bot_command::u_commnd_data::s_cmd_repl_prv_02_1::group, s_dynamic_rule::group, s_bot_command::u_commnd_data::s_cmd_repl_user_13_1::group, s_dcc_host::group, s_bot_command::u_commnd_data::s_cmd_repl_user_10_1::group, s_channel_def::groups, s_user::groups, s_bot_control::hard_clear(), s_bot_command::hard_clear(), s_dcc_host::host, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::host_bot, s_user::host_bot, s_channel::host_unknown, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::host_unknown, s_user::host_unknown, s_bot_command::u_commnd_data::s_cmd_repl_user_02_1::hostmask, s_user::hostmask, s_bot_command::u_commnd_data::s_cmd_partyline_user_1::id, s_bot_command::u_commnd_data::s_cmd_partyline_1::id, s_bot_command::u_commnd_data::s_cmd_proc_1::init, s_channel::is_template, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::is_template, s_user::is_template, s_channel::join_flood, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::join_flood_l, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::join_flood_s, s_chan_def_to_push::last_changed, s_proc_to_push::last_changed, s_bot_command::u_commnd_data::s_cmd_repl_chdef_01_1::last_changed, s_chan_def_to_pull::last_changed, s_bot_command::u_commnd_data::s_cmd_proc_1::last_changed, s_proc_to_pull::last_changed, s_bot_command::u_commnd_data::s_cmd_repl_prv_01_1::last_changed, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::last_changed, s_private::last_changed, s_channel_def::last_changed, s_procedure::last_changed, s_user::last_changed, s_bot_command::u_commnd_data::s_cmd_proc_1::line, s_proc_to_pull::lines, s_flood::lines, log_botnet(), log_botnet_debug(), log_socket(), logic_botnet_backup(), logic_botnet_get_channel_def(), logic_botnet_get_proc(), logic_botnet_get_user(), logic_botnet_rehash(), logic_botnet_remove_channel_def(), logic_botnet_remove_user(), logic_call_proc_ex2(), logic_eval(), logic_find_proc_by_name(), logic_get_push_chan_defs(), logic_get_push_procs(), logic_get_push_users(), logic_on_internal_event(), logic_parse_proc(), logic_partyline_get_user(), logic_partyline_get_user_template(), ltoa(), s_bot_command::u_commnd_data::s_cmd_repl_chdef_04_1::mask, MD5Final(), MD5Init(), MD5Update(), s_user::meta, s_bot_command::u_commnd_data::s_cmd_repl_user_14_1::meta_key, s_bot_command::u_commnd_data::s_cmd_repl_user_14_1::meta_val, s_bot_command::u_commnd_data::s_cmd_repl_chdef_03_1::minus_modes, s_dynamic_rule::minus_modes, s_bot_command::u_commnd_data::s_cmd_repl_user_13_1::minus_modes, s_channel::mode_flood, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::mode_flood_l, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::mode_flood_s, s_channel::msg_flood, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::msg_flood_l, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::msg_flood_s, msg_ids, s_bot_command::u_commnd_data::s_cmd_repl_chdef_99_1::name, s_bot_command::u_commnd_data::s_cmd_repl_chdef_06_8::name, s_bot_command::u_commnd_data::s_cmd_repl_chdef_05_1::name, s_bot_command::u_commnd_data::s_cmd_repl_chdef_04_1::name, s_bot_command::u_commnd_data::s_cmd_repl_chdef_03_1::name, s_bot_command::u_commnd_data::s_cmd_repl_chdef_02_1::name, s_bot_command::u_commnd_data::s_cmd_repl_chdef_01_1::name, s_bot_command::u_commnd_data::s_cmd_proc_end_1::name, s_bot_command::u_commnd_data::s_cmd_proc_1::name, s_bot_command::u_commnd_data::s_cmd_repl_user_99_1::name, s_bot_command::u_commnd_data::s_cmd_repl_user_17_9::name, s_bot_command::u_commnd_data::s_cmd_repl_user_16_5::name, s_bot_command::u_commnd_data::s_cmd_repl_user_15_1::name, s_bot_command::u_commnd_data::s_cmd_repl_user_14_1::name, s_bot_command::u_commnd_data::s_cmd_repl_user_13_1::name, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::name, s_bot_command::u_commnd_data::s_cmd_repl_user_11_1::name, s_group::name, s_bot_command::u_commnd_data::s_cmd_repl_user_10_1::name, s_bot_command::u_commnd_data::s_cmd_repl_user_09_1::name, s_bot_command::u_commnd_data::s_cmd_repl_user_08_1::name, s_bot_command::u_commnd_data::s_cmd_repl_user_07_1::name, s_bot_command::u_commnd_data::s_cmd_repl_user_06_1::name, s_bot_command::u_commnd_data::s_cmd_repl_user_05_1::name, s_bot_command::u_commnd_data::s_cmd_repl_user_04_1::name, s_bot_command::u_commnd_data::s_cmd_repl_user_03_1::name, s_bot_command::u_commnd_data::s_cmd_repl_user_02_1::name, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::name, s_procedure::name, s_user::name, s_channel::nick_flood, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::nick_flood_l, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::nick_flood_s, s_bot_command::u_commnd_data::no_repl_1, s_channel::notice_flood, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::notice_flood_l, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::notice_flood_s, s_bot_command::u_commnd_data::s_check_time_1::now, s_bot_command::u_commnd_data::s_cmd_remote_procedure_call_3::num_args, s_bot_command::u_commnd_data::s_cmd_push_1::object_name, s_bot_command::u_commnd_data::s_no_repl_1::object_name, s_bot_command::u_commnd_data::s_check_time_1::object_name, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_ban, s_channel::on_ban, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_banned, s_channel::on_banned, s_bot_command::u_commnd_data::s_cmd_repl_prv_05_8::on_broadcast, s_private::on_broadcast, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_creator, s_channel::on_creator, s_bot_command::u_commnd_data::s_cmd_repl_chdef_01_1::on_ctcp, s_channel_def::on_ctcp, s_bot_command::u_commnd_data::s_cmd_repl_prv_03_1::on_ctcp, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_decreator, s_channel::on_decreator, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_deop, s_channel::on_deop, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_devoice, s_channel::on_devoice, s_bot_command::u_commnd_data::s_cmd_repl_chdef_01_1::on_dynamic_ban, s_channel_def::on_dynamic_ban, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_except, s_channel::on_except, s_bot_command::u_commnd_data::s_cmd_repl_prv_04_7::on_filesys_got_new, s_private::on_filesys_got_new, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_flood, s_channel::on_flood, s_bot_command::u_commnd_data::s_cmd_repl_prv_04_7::on_fnc, s_private::on_fnc, s_bot_command::u_commnd_data::s_cmd_repl_prv_06_11::on_internal_event, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_invite, s_channel::on_invite, s_bot_command::u_commnd_data::s_cmd_repl_chdef_01_1::on_ircop, s_channel_def::on_ircop, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_join, s_channel::on_join, s_bot_command::u_commnd_data::s_cmd_repl_chdef_01_1::on_key, s_channel_def::on_key, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_kick, s_channel::on_kick, s_bot_command::u_commnd_data::s_cmd_repl_chdef_01_1::on_limit, s_channel_def::on_limit, s_bot_command::u_commnd_data::s_cmd_repl_chdef_01_1::on_mode, s_channel_def::on_mode, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_not_in_reop, s_channel::on_not_in_reop, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_not_invited, s_channel::on_not_invited, s_bot_command::u_commnd_data::s_cmd_repl_chdef_01_1::on_notice, s_channel_def::on_notice, s_bot_command::u_commnd_data::s_cmd_repl_prv_03_1::on_notice, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_notice, s_channel::on_notice, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_op, s_channel::on_op, s_bot_command::u_commnd_data::s_cmd_repl_chdef_01_1::on_part, s_channel_def::on_part, s_bot_command::u_commnd_data::s_cmd_repl_chdef_01_1::on_privmsg, s_channel_def::on_privmsg, s_bot_command::u_commnd_data::s_cmd_repl_prv_03_1::on_privmsg, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_privmsg, s_channel::on_privmsg, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_reop, s_channel::on_reop, s_channel_def::on_server_msg, s_bot_command::u_commnd_data::s_cmd_repl_chdef_06_8::on_server_msg, s_bot_command::u_commnd_data::s_cmd_repl_prv_05_8::on_server_msg, s_private::on_server_msg, s_bot_command::u_commnd_data::s_cmd_repl_chdef_01_1::on_topic, s_channel_def::on_topic, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_unban, s_channel::on_unban, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_unexcept, s_channel::on_unexcept, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_uninvite, s_channel::on_uninvite, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::on_voice, s_channel::on_voice, s_proc_to_pull::orig_groups, s_bot_command::u_commnd_data::s_cmd_push_1::original_time, s_bot_command::u_commnd_data::s_check_time_1::original_time, s_bot_command::packet_type, s_bot_control::packet_type, PACKET_TYPE_COMMAND, PACKET_TYPE_CONTROL, s_replication::partner, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::partyline_msg_flood, s_user::partyline_msg_flood, ping_time, s_bot_command::u_commnd_data::s_cmd_repl_chdef_03_1::plus_modes, s_dynamic_rule::plus_modes, s_bot_command::u_commnd_data::s_cmd_repl_user_13_1::plus_modes, PRIVATE_EVENT_SEVERITY_CODE_CRITICAL_ERROR, PRIVATE_EVENT_SEVERITY_CODE_ERROR, PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL, PRIVATE_EVENT_SEVERITY_CODE_WARNING, s_proc_to_push::proc_name, s_proc_to_pull::proc_name, s_bot_command::u_commnd_data::s_cmd_push_1::procedure, s_bot_command::u_commnd_data::s_check_time_1::procedure, s_bot_command::u_commnd_data::s_no_repl_1::procedure, s_bot_command::u_commnd_data::s_cmd_push_1::prv, s_bot_command::u_commnd_data::s_check_time_1::prv, s_bot_command::u_commnd_data::s_no_repl_1::prv, r_channel_defs, r_channel_templates, r_channel_terminators, r_channels, r_procedures, r_terminators, r_user_templates, r_users, s_bot_command::u_commnd_data::s_cmd_repl_chdef_04_1::reason, s_bot_command::u_commnd_data::s_no_repl_1::reason, REASON_NO_REPL_1_ACCESS_DENIED, REASON_NO_REPL_1_UP_TO_DATE, s_user_to_lock_out::remote, s_channel::repeat_flood, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::repeat_flood_l, s_bot_command::u_commnd_data::s_cmd_repl_user_12_1::repeat_flood_s, REPL_PULL, REPL_PUSH, REPL_PUSHPULL, s_proc_to_pull::replication, s_private::replication, s_channel_def::replication, s_procedure::replication, s_user::replication, s_user::replication_partner, s_flood::seconds, s_bot_command::size, sleep(), sock_close(), sock_connect(), sock_error(), sock_read(), sock_send(), sock_set_blocking(), ssl_client_connection(), ssl_close(), ssl_do_read_write(), stats_botnet_auth_error(), stats_botnet_auth_ok(), stats_botnet_auth_proto_error(), stats_botnet_bytes_received(), stats_botnet_bytes_sent(), stats_botnet_chandef_pulled(), stats_botnet_new_connection(), stats_botnet_partyline_event(), stats_botnet_private_pulled(), stats_botnet_proc_pulled(), stats_botnet_user_pulled(), SUPPORTED_PROTO_VERSION, s_bot_control::supported_proto_version, s_bot_command::u_commnd_data::s_cmd_repl_user_01_1::terminator, s_user::terminator, s_user_to_lock_out::timestamp, s_replication::type, s_user_to_push::user, s_bot_command::u_commnd_data::s_cmd_partyline_user_1::user, s_partyline_member::user, s_bot_command::u_commnd_data::s_cmd_partyline_1::user, s_user_to_pull::user, s_bot_command::u_commnd_data::s_cmd_push_1::user, s_bot_command::u_commnd_data::s_no_repl_1::user, s_bot_command::u_commnd_data::s_check_time_1::user, s_channel::username, and s_bot_command::version. Referenced by main(). 03893 { 03894 if(botnet_last_rehash_request && botnet_last_rehash_request+120<time(NULL)) { 03895 botnet_last_rehash_request=0; 03896 logic_botnet_backup("BOTNET"); 03897 logic_botnet_rehash("BOTNET"); 03898 } 03899 03900 if(botnet_penalty==-1) 03901 botnet_penalty=atol(conf_getvar("botnet_penalty").c_str()); 03902 03903 vector<s_bot*>::iterator i1; 03904 03905 vector<string> bots_; 03906 label: 03907 for(i1=bots.begin(); i1!=bots.end(); i1++) { 03908 vector<string>::iterator i2; 03909 for(i2=bots_.begin(); i2!=bots_.end(); i2++) { 03910 if(!(*i2).compare((*i1)->botname)) { 03911 if((*i1)->ssl_connection) { 03912 ssl_close((*i1)->ssl,&((*i1)->socket)); 03913 } 03914 delete *i1; 03915 bots.erase(i1); 03916 goto label; 03917 } 03918 } 03919 bots_.push_back((*i1)->botname); 03920 } 03921 03922 static s_bot_command* cmd=new s_bot_command; 03923 static s_bot_control* ctrl=new s_bot_control; 03924 03925 // receive 03926 for(i1=bots.begin(); i1!=bots.end(); i1++) { 03927 if((*i1)->ssl) 03928 ssl_do_read_write((*i1)->ssl); 03929 if((*i1)->socket.cmp()==false) 03930 continue; 03931 03932 cmd->hard_clear(); 03933 ctrl->hard_clear(); 03934 03935 // returns 0 for empty buffer 03936 // returns 1 for got data 03937 // returns 3 for got data, but connection closed 03938 // returns 4 for don't have data, and connection closed 03939 // returns 5 connection should be closed for error 03940 //int botnet_receive(s_bot& bot, int& packet_type, s_bot_command& cmd, s_bot_control& control) 03941 03942 int packet_type; 03943 int result=botnet_receive(*i1,packet_type,cmd,ctrl); 03944 if(result==0) 03945 continue; 03946 if(result==5) { 03947 (*i1)->receive_buffer_pos=0; 03948 if((*i1)->rle_buffer) { 03949 free((*i1)->rle_buffer); 03950 (*i1)->rle_buffer=NULL; 03951 (*i1)->rle_buffer_len=0; 03952 } 03953 string log1="connection forced to close because of serious errors - in file " __FILE__ " in function " __FUNC__; 03954 string log2="closing LINK connection (error)"; 03955 03956 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),-1,-1,log1.c_str()); 03957 log_botnet(botnet_botname,(*i1)->botname.c_str(),log2.c_str()); 03958 03959 logic_on_internal_event("@botnet_link@",(*i1)->botname,"DELINKED","","",PRIVATE_EVENT_SEVERITY_CODE_ERROR,log2+(string)"; "+log1,""); 03960 03961 if((*i1)->ssl) { 03962 ssl_close((*i1)->ssl,&((*i1)->socket)); 03963 (*i1)->ssl=NULL; 03964 } 03965 sock_close((*i1)->socket); 03966 (*i1)->socket.clear(); 03967 continue; 03968 } 03969 if(result==4) { 03970 (*i1)->receive_buffer_pos=0; 03971 if((*i1)->rle_buffer) { 03972 free((*i1)->rle_buffer); 03973 (*i1)->rle_buffer=NULL; 03974 (*i1)->rle_buffer_len=0; 03975 } 03976 string log1="connection closed before all data had been received - in file " __FILE__ " in function " __FUNC__; 03977 string log2="closing LINK connection (error)"; 03978 03979 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),-1,-1,log1.c_str()); 03980 log_botnet(botnet_botname,(*i1)->botname.c_str(),log1.c_str()); 03981 03982 logic_on_internal_event("@botnet_link@",(*i1)->botname,"DELINKED","","",PRIVATE_EVENT_SEVERITY_CODE_ERROR,log2+(string)"; "+log1,""); 03983 03984 if((*i1)->ssl) { 03985 ssl_close((*i1)->ssl,&((*i1)->socket)); 03986 (*i1)->ssl=NULL; 03987 } 03988 sock_close((*i1)->socket); 03989 (*i1)->socket.clear(); 03990 continue; 03991 } 03992 if(result==3) { 03993 // log 03994 if((*i1)->ssl) { 03995 ssl_close((*i1)->ssl,&((*i1)->socket)); 03996 (*i1)->ssl=NULL; 03997 } 03998 sock_close((*i1)->socket); 03999 (*i1)->socket.clear(); 04000 } 04001 if(result==1 || result==3) { 04002 // if we got at least one PONG already, we have received packet, so waiting for PONG is not required (coz we got packet! thus we know that connection is alive!) 04003 if((*i1)->got_at_least_one_pong) 04004 (*i1)->start_awaiting_pong=0; 04005 04006 (*i1)->receive_buffer_pos=0; 04007 if((*i1)->rle_buffer) { 04008 free((*i1)->rle_buffer); 04009 (*i1)->rle_buffer=NULL; 04010 (*i1)->rle_buffer_len=0; 04011 } 04012 04013 if(packet_type==PACKET_TYPE_CONTROL) { 04014 (*i1)->supported_proto_version=ctrl->supported_proto_version; 04015 switch(ctrl->control) { 04016 case CTRL_ERROR_001: // remote is using greater protocol version than me! 04017 stats_botnet_auth_proto_error(); 04018 if((*i1)->ssl) { 04019 ssl_close((*i1)->ssl,&((*i1)->socket)); 04020 (*i1)->ssl=NULL; 04021 } 04022 sock_close((*i1)->socket); 04023 (*i1)->socket.clear(); 04024 04025 { 04026 string log1="connection closed: remote bot is using newer unsupported protocol - in file " __FILE__ " in function " __FUNC__; 04027 string log2="closing LINK connection (unsupported protocol)"; 04028 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),packet_type,ctrl->control,log1.c_str()); 04029 log_botnet(botnet_botname,(*i1)->botname.c_str(),log2.c_str()); 04030 04031 logic_on_internal_event("@botnet_link@",(*i1)->botname,"DELINKED","","",PRIVATE_EVENT_SEVERITY_CODE_ERROR,log2+(string)"; "+log1,""); 04032 } 04033 04034 break; 04035 case CTRL_ERROR_002: 04036 stats_botnet_auth_error(); 04037 if((*i1)->ssl) { 04038 ssl_close((*i1)->ssl,&((*i1)->socket)); 04039 (*i1)->ssl=NULL; 04040 } 04041 sock_close((*i1)->socket); 04042 (*i1)->socket.clear(); 04043 04044 { 04045 string log1="connection closed: bad password - in file " __FILE__ " in function " __FUNC__; 04046 string log2="BAD PASSWORD on my side"; 04047 04048 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),packet_type,ctrl->control,log1.c_str()); 04049 log_botnet(botnet_botname,(*i1)->botname.c_str(),log2.c_str()); 04050 04051 logic_on_internal_event("@botnet_link@",(*i1)->botname,"BAD_PASSWORD_HERE","","",PRIVATE_EVENT_SEVERITY_CODE_CRITICAL_ERROR,log2+(string)"; "+log1,""); 04052 } 04053 break; 04054 case CTRL_LINKED: 04055 (*i1)->remote_pswd_ok=true; 04056 if((*i1)->auth_ok && (*i1)->remote_pswd_ok) { 04057 vector<s_bot*>::iterator i2; 04058 label_2: 04059 for(i2=bots.begin(); i2!=bots.end(); i2++) 04060 if(!(*i2)->botname.compare((*i1)->botname) && (*i2)->socket.handle!=(*i1)->socket.handle) { 04061 bots.erase(i2); 04062 goto label_2; 04063 } 04064 04065 stats_botnet_auth_ok(); 04066 (*i1)->was_linked=true; 04067 04068 { 04069 string log1="LINKED"; 04070 string log2="LINK connection established"; 04071 04072 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),-1,-1,log1.c_str()); 04073 log_botnet(botnet_botname,(*i1)->botname.c_str(),log2.c_str()); 04074 04075 logic_on_internal_event("@botnet_link@",(*i1)->botname,"LINKED","","",PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,log2+(string)"; "+log1,""); 04076 } 04077 } 04078 break; 04079 case CTRL_PING: 04080 { 04081 s_bot_control* c=new s_bot_control; 04082 c->hard_clear(); 04083 c->packet_type=PACKET_TYPE_CONTROL; 04084 c->supported_proto_version=SUPPORTED_PROTO_VERSION; 04085 c->control=CTRL_PONG; 04086 botnet_send_control(*i1,c); 04087 delete c; 04088 } 04089 break; 04090 case CTRL_PONG: 04091 (*i1)->start_awaiting_pong=0; 04092 (*i1)->got_at_least_one_pong=true; 04093 break; 04094 default: 04095 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),cmd->packet_type,ctrl->control,"unknown PACKET_TYPE_CONTROL from remote bot - in file " __FILE__ " in function " __FUNC__); 04096 break; 04097 } 04098 /*delete cmd; 04099 delete ctrl;*/ 04100 return; 04101 } 04102 if(packet_type==PACKET_TYPE_COMMAND) { 04103 if(cmd->version>SUPPORTED_PROTO_VERSION) { 04104 s_bot_control* c=new s_bot_control; 04105 c->hard_clear(); 04106 04107 c->packet_type=PACKET_TYPE_CONTROL; 04108 c->supported_proto_version=SUPPORTED_PROTO_VERSION; 04109 c->control=CTRL_ERROR_001; 04110 04111 if(botnet_send_control(*i1,c)) { 04112 string log1="unable to send PACKET_TYPE_CONTROL to remote bot - in file " __FILE__ " in function " __FUNC__; 04113 string log2="closing LINK connection (error)"; 04114 04115 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->control,log1.c_str()); 04116 log_botnet(botnet_botname,(*i1)->botname.c_str(),log2.c_str()); 04117 04118 logic_on_internal_event("@botnet_link@",(*i1)->botname,"DELINKED","","",PRIVATE_EVENT_SEVERITY_CODE_ERROR,log2+(string)"; "+log1,""); 04119 04120 if((*i1)->ssl) { 04121 ssl_close((*i1)->ssl,&((*i1)->socket)); 04122 (*i1)->ssl=NULL; 04123 } 04124 sock_close((*i1)->socket); 04125 (*i1)->socket.clear(); 04126 04127 delete c; 04128 04129 continue; 04130 } 04131 delete c; 04132 } 04133 if(cmd->version==1 || 1) { // always true 04134 if((!(*i1)->auth_ok || !(*i1)->remote_pswd_ok) && cmd->command!=CMD_AUTH_1) { 04135 s_bot_control* c=new s_bot_control; 04136 c->hard_clear(); 04137 04138 c->packet_type=PACKET_TYPE_CONTROL; 04139 c->supported_proto_version=SUPPORTED_PROTO_VERSION; 04140 c->control=CTRL_ERROR_002; 04141 04142 if(botnet_send_control(*i1,c)) { 04143 string log1="unable to send PACKET_TYPE_CONTROL to remote bot - in file " __FILE__ " in function " __FUNC__; 04144 string log2="closing LINK connection (error)"; 04145 04146 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->control,log1.c_str()); 04147 log_botnet(botnet_botname,(*i1)->botname.c_str(),log2.c_str()); 04148 04149 logic_on_internal_event("@botnet_link@",(*i1)->botname,"DELINKED","","",PRIVATE_EVENT_SEVERITY_CODE_ERROR,log2+(string)"; "+log1,""); 04150 04151 if((*i1)->ssl) { 04152 ssl_close((*i1)->ssl,&((*i1)->socket)); 04153 (*i1)->ssl=NULL; 04154 } 04155 sock_close((*i1)->socket); 04156 (*i1)->socket.clear(); 04157 } 04158 04159 if((*i1)->ssl) { 04160 ssl_close((*i1)->ssl,&((*i1)->socket)); 04161 (*i1)->ssl=NULL; 04162 } 04163 sock_close((*i1)->socket); 04164 (*i1)->socket.clear(); 04165 04166 delete c; 04167 continue; 04168 } 04169 switch(cmd->command) { 04170 case CMD_AUTH_1: 04171 { 04172 unsigned char signature[32+1]; 04173 signature[32]=0; 04174 04175 if((*i1)->remote_MD5_password.length()==sizeof(signature)-1) 04176 strcpy((char*)signature,(*i1)->remote_MD5_password.c_str()); 04177 04178 MD5Context md5c; 04179 MD5Init(&md5c); 04180 MD5Update(&md5c,signature,sizeof(signature)-1); 04181 MD5Final(signature,&md5c); 04182 04183 char sig[128]; 04184 sig[0]=0; 04185 for(int i1_=0; i1_<16; i1_++) { 04186 char tmp[16]; 04187 sprintf(tmp,"%02X",signature[i1_]); 04188 strcat(sig,tmp); 04189 } 04190 04191 bool equal=true; 04192 for(unsigned int i=0; i<sizeof(signature)-1; i++) 04193 if(cmd->command_data.bot_auth_1.digest[i]!=sig[i]) { 04194 equal=false; 04195 break; 04196 } 04197 if(!equal) { 04198 extern vector<s_user_to_lock_out> dcc_users_to_lock_out; 04199 04200 s_user_to_lock_out u; 04201 u.timestamp=time(NULL); 04202 u.remote=(*i1)->botip; 04203 dcc_users_to_lock_out.push_back(u); 04204 04205 string log1="incorrect password from remote bot - in file " __FILE__ " in function " __FUNC__; 04206 string log2="BAD PASSWORD on the other side"; 04207 04208 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),cmd->packet_type,cmd->command,log1.c_str()); 04209 log_botnet(botnet_botname,(*i1)->botname.c_str(),log2.c_str()); 04210 04211 logic_on_internal_event("@botnet_link@",(*i1)->botname,"BAD_PASSWORD_THERE","","",PRIVATE_EVENT_SEVERITY_CODE_CRITICAL_ERROR,log2+(string)"; "+log1,""); 04212 04213 if(result==1) { 04214 s_bot_control* c=new s_bot_control; 04215 c->hard_clear(); 04216 04217 c->packet_type=PACKET_TYPE_CONTROL; 04218 c->supported_proto_version=SUPPORTED_PROTO_VERSION; 04219 c->control=CTRL_ERROR_002; 04220 04221 if(botnet_send_control(*i1,c)) { 04222 string log1="unable to send PACKET_TYPE_CONTROL to remote bot - in file " __FILE__ " in function " __FUNC__; 04223 string log2="closing LINK connection (error)"; 04224 04225 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->control,log1.c_str()); 04226 log_botnet(botnet_botname,(*i1)->botname.c_str(),log2.c_str()); 04227 04228 logic_on_internal_event("@botnet_link@",(*i1)->botname,"DELINKED","","",PRIVATE_EVENT_SEVERITY_CODE_ERROR,log2+(string)"; "+log1,""); 04229 04230 if((*i1)->ssl) { 04231 ssl_close((*i1)->ssl,&((*i1)->socket)); 04232 (*i1)->ssl=NULL; 04233 } 04234 sock_close((*i1)->socket); 04235 (*i1)->socket.clear(); 04236 } 04237 04238 if((*i1)->ssl) { 04239 ssl_close((*i1)->ssl,&((*i1)->socket)); 04240 (*i1)->ssl=NULL; 04241 } 04242 sock_close((*i1)->socket); 04243 (*i1)->socket.clear(); 04244 04245 delete c; 04246 } 04247 //result==3 : connection already closed, so do nothing 04248 continue; 04249 } else { 04250 (*i1)->auth_ok=true; 04251 04252 s_bot_control* c=new s_bot_control; 04253 c->hard_clear(); 04254 c->packet_type=PACKET_TYPE_CONTROL; 04255 c->supported_proto_version=SUPPORTED_PROTO_VERSION; 04256 c->control=CTRL_LINKED; 04257 botnet_send_control(*i1,c); 04258 04259 if((*i1)->auth_ok && (*i1)->remote_pswd_ok) { 04260 (*i1)->was_linked=true; 04261 04262 string log1="LINKED"; 04263 string log2="LINK connection established"; 04264 04265 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),-1,-1,log1.c_str()); 04266 log_botnet(botnet_botname,(*i1)->botname.c_str(),log2.c_str()); 04267 04268 logic_on_internal_event("@botnet_link@",(*i1)->botname,"LINKED","","",PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,log2+(string)"; "+log1,""); 04269 } 04270 delete c; 04271 } 04272 } 04273 break; 04274 case CMD_REMOTE_PROCEDURE_CALL_3: 04275 { 04276 //string call_string; 04277 string proc_name_only; 04278 list<string> params; 04279 04280 int num_args=cmd->command_data.cmd_remote_procedure_call_3.num_args; 04281 int curr_arg=0; 04282 string arg; 04283 for(int i2=0; i2<sizeof(cmd->command_data.cmd_remote_procedure_call_3.args_array); i2++) { 04284 if(curr_arg>=num_args) 04285 break; 04286 if(cmd->command_data.cmd_remote_procedure_call_3.args_array[i2]==0) { 04287 if(curr_arg==0) { 04288 //call_string=arg+"("; 04289 proc_name_only=arg; 04290 } else { 04291 /*if(curr_arg!=1) 04292 call_string+=","; 04293 call_string+=(string)"\""+arg+"\"";*/ 04294 params.push_back(arg); 04295 } 04296 arg=""; 04297 curr_arg++; 04298 } else { 04299 arg+=cmd->command_data.cmd_remote_procedure_call_3.args_array[i2]; 04300 } 04301 } 04302 //call_string+=")"; 04303 04304 string call_string; 04305 04306 bool got=false; 04307 vector<s_procedure>::iterator i3; 04308 for(i3=r_procedures.begin(); i3!=r_procedures.end(); i3++) { 04309 string s=(*i3).name; 04310 unsigned int i2; 04311 for(i2=0; i2<s.length(); i2++) 04312 if(s[i2]=='(') 04313 break; 04314 s.erase(i2,s.length()-i2); // erase everything after '(' 04315 if(!s.compare(proc_name_only)) { 04316 vector<s_rproc>::iterator i4; 04317 for(i4=(*i3).rproc.begin(); i4!=(*i3).rproc.end(); i4++) 04318 if(!(*i4).remote_bot.compare((*i1)->botname)) { 04319 got=true; 04320 break; 04321 } 04322 call_string=(*i3).name; 04323 break; 04324 } 04325 } 04326 04327 map<string,string> vars; 04328 if(got) 04329 logic_call_proc_ex2(call_string.c_str(),vars,params); 04330 else 04331 ; // access denied, or procedure not found = ignore! 04332 } 04333 break; 04334 case CMD_CHECK_TIME_1: 04335 { 04336 // remote is trying to PULL 04337 string obj=cmd->command_data.check_time_1.object_name; 04338 string remote=(*i1)->botname; 04339 if(cmd->command_data.check_time_1.user) { 04340 s_user u; 04341 bool got2=false; 04342 if(logic_botnet_get_user(obj,u)) 04343 got2=true; 04344 bool got=false; 04345 if(got2) { 04346 vector<s_replication>::iterator i2; 04347 for(i2=u.replication.begin(); i2!=u.replication.end(); i2++) 04348 if(!(*i2).partner.compare(remote) && ((*i2).type==REPL_PUSH || (*i2).type==REPL_PUSHPULL)) { 04349 got=true; 04350 break; 04351 } 04352 } 04353 if(got2 && !got) { 04354 s_bot_command* c=new s_bot_command; 04355 c->hard_clear(); 04356 c->packet_type=PACKET_TYPE_COMMAND; 04357 c->size=sizeof(c); 04358 c->version=1; 04359 c->command=CMD_NO_REPL_1; 04360 c->command_data.no_repl_1.user=cmd->command_data.check_time_1.user; 04361 c->command_data.no_repl_1.procedure=cmd->command_data.check_time_1.procedure; 04362 c->command_data.no_repl_1.channel_def=cmd->command_data.check_time_1.channel_def; 04363 c->command_data.no_repl_1.prv=cmd->command_data.check_time_1.prv; 04364 c->command_data.no_repl_1.reason=REASON_NO_REPL_1_ACCESS_DENIED; 04365 memcpy(c->command_data.no_repl_1.object_name,cmd->command_data.check_time_1.object_name,sizeof(c->command_data.no_repl_1.object_name)); 04366 botnet_send_command(*i1,c); 04367 04368 string d="I have rejected replication of object "; 04369 if(c->command_data.no_repl_1.user) 04370 d+="(user) "; 04371 if(c->command_data.no_repl_1.procedure) 04372 d+="(procedure) "; 04373 if(c->command_data.no_repl_1.channel_def) 04374 d+="(channel) "; 04375 if(c->command_data.no_repl_1.prv) 04376 d+="(private)"; // no trailing SPACE!!! 04377 d+=obj; 04378 d+=", reason: "; 04379 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 04380 d+="up to date"; 04381 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 04382 d+="access denied"; 04383 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->command,d.c_str()); 04384 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 04385 04386 { 04387 string obj_type="?"; 04388 if(c->command_data.no_repl_1.user) 04389 obj_type="user"; 04390 if(c->command_data.no_repl_1.procedure) 04391 obj_type="procedure"; 04392 if(c->command_data.no_repl_1.channel_def) 04393 obj_type="channel"; 04394 if(c->command_data.no_repl_1.prv) 04395 obj_type="private"; 04396 04397 string reason="?"; 04398 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 04399 reason="up to date"; 04400 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 04401 reason="access denied"; 04402 04403 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"LOCAL"); 04404 } 04405 04406 delete c; 04407 04408 break; 04409 } 04410 time_t now; 04411 time(&now); 04412 time_t diff=cmd->command_data.check_time_1.now-now; // -x == remote is older 04413 time_t obj_diff=u.last_changed-(cmd->command_data.check_time_1.original_time-diff); 04414 if(got2 && ((signed)obj_diff>60 || cmd->command_data.check_time_1.original_time==0)) { 04415 botnet_push_user(*i1,u); 04416 } 04417 } 04418 if(cmd->command_data.check_time_1.procedure) { 04419 s_procedure p; 04420 bool got2=false; 04421 if(logic_botnet_get_proc(obj,p)) 04422 got2=true; 04423 bool got=false; 04424 if(got2) { 04425 vector<s_replication>::iterator i2; 04426 for(i2=p.replication.begin(); i2!=p.replication.end(); i2++) 04427 if(!(*i2).partner.compare(remote) && ((*i2).type==REPL_PUSH || (*i2).type==REPL_PUSHPULL)) { 04428 got=true; 04429 break; 04430 } 04431 } 04432 if(got2 && !got) { 04433 s_bot_command* c=new s_bot_command; 04434 c->hard_clear(); 04435 c->packet_type=PACKET_TYPE_COMMAND; 04436 c->size=sizeof(c); 04437 c->version=1; 04438 c->command=CMD_NO_REPL_1; 04439 c->command_data.no_repl_1.user=cmd->command_data.check_time_1.user; 04440 c->command_data.no_repl_1.procedure=cmd->command_data.check_time_1.procedure; 04441 c->command_data.no_repl_1.channel_def=cmd->command_data.check_time_1.channel_def; 04442 c->command_data.no_repl_1.prv=cmd->command_data.check_time_1.prv; 04443 c->command_data.no_repl_1.reason=REASON_NO_REPL_1_ACCESS_DENIED; 04444 memcpy(c->command_data.no_repl_1.object_name,cmd->command_data.check_time_1.object_name,sizeof(c->command_data.no_repl_1.object_name)); 04445 botnet_send_command(*i1,c); 04446 04447 string d="I have rejected replication of object "; 04448 if(c->command_data.no_repl_1.user) 04449 d+="(user) "; 04450 if(c->command_data.no_repl_1.procedure) 04451 d+="(procedure) "; 04452 if(c->command_data.no_repl_1.channel_def) 04453 d+="(channel) "; 04454 if(c->command_data.no_repl_1.prv) 04455 d+="(private)"; // no trailing SPACE!!! 04456 d+=obj; 04457 d+=", reason: "; 04458 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 04459 d+="up to date"; 04460 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 04461 d+="access denied"; 04462 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->command,d.c_str()); 04463 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 04464 04465 { 04466 string obj_type="?"; 04467 if(c->command_data.no_repl_1.user) 04468 obj_type="user"; 04469 if(c->command_data.no_repl_1.procedure) 04470 obj_type="procedure"; 04471 if(c->command_data.no_repl_1.channel_def) 04472 obj_type="channel"; 04473 if(c->command_data.no_repl_1.prv) 04474 obj_type="private"; 04475 04476 string reason="?"; 04477 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 04478 reason="up to date"; 04479 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 04480 reason="access denied"; 04481 04482 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"LOCAL"); 04483 } 04484 04485 delete c; 04486 04487 break; 04488 } 04489 time_t now; 04490 time(&now); 04491 time_t diff=cmd->command_data.check_time_1.now-now; // -x == remote is older 04492 time_t obj_diff=p.last_changed-(cmd->command_data.check_time_1.original_time-diff); 04493 if(got2 && ((signed)obj_diff>60 || cmd->command_data.check_time_1.original_time==0)) { 04494 botnet_push_proc(*i1,p); 04495 } 04496 } 04497 if(cmd->command_data.check_time_1.channel_def) { 04498 s_channel_def chd; 04499 bool got2=false; 04500 if(logic_botnet_get_channel_def(obj,chd)) 04501 got2=true; 04502 bool got=false; 04503 if(got2) { 04504 vector<s_replication>::iterator i2; 04505 for(i2=chd.replication.begin(); i2!=chd.replication.end(); i2++) 04506 if(!(*i2).partner.compare(remote) && ((*i2).type==REPL_PUSH || (*i2).type==REPL_PUSHPULL)) { 04507 got=true; 04508 break; 04509 } 04510 } 04511 if(got2 && !got) { 04512 s_bot_command* c=new s_bot_command; 04513 c->hard_clear(); 04514 c->packet_type=PACKET_TYPE_COMMAND; 04515 c->size=sizeof(c); 04516 c->version=1; 04517 c->command=CMD_NO_REPL_1; 04518 c->command_data.no_repl_1.user=cmd->command_data.check_time_1.user; 04519 c->command_data.no_repl_1.procedure=cmd->command_data.check_time_1.procedure; 04520 c->command_data.no_repl_1.channel_def=cmd->command_data.check_time_1.channel_def; 04521 c->command_data.no_repl_1.prv=cmd->command_data.check_time_1.prv; 04522 c->command_data.no_repl_1.reason=REASON_NO_REPL_1_ACCESS_DENIED; 04523 memcpy(c->command_data.no_repl_1.object_name,cmd->command_data.check_time_1.object_name,sizeof(c->command_data.no_repl_1.object_name)); 04524 botnet_send_command(*i1,c); 04525 04526 string d="I have rejected replication of object "; 04527 if(c->command_data.no_repl_1.user) 04528 d+="(user) "; 04529 if(c->command_data.no_repl_1.procedure) 04530 d+="(procedure) "; 04531 if(c->command_data.no_repl_1.channel_def) 04532 d+="(channel) "; 04533 if(c->command_data.no_repl_1.prv) 04534 d+="(private)"; // no trailing SPACE!!! 04535 d+=obj; 04536 d+=", reason: "; 04537 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 04538 d+="up to date"; 04539 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 04540 d+="access denied"; 04541 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->command,d.c_str()); 04542 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 04543 04544 { 04545 string obj_type="?"; 04546 if(c->command_data.no_repl_1.user) 04547 obj_type="user"; 04548 if(c->command_data.no_repl_1.procedure) 04549 obj_type="procedure"; 04550 if(c->command_data.no_repl_1.channel_def) 04551 obj_type="channel"; 04552 if(c->command_data.no_repl_1.prv) 04553 obj_type="private"; 04554 04555 string reason="?"; 04556 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 04557 reason="up to date"; 04558 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 04559 reason="access denied"; 04560 04561 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"LOCAL"); 04562 } 04563 04564 delete c; 04565 04566 break; 04567 } 04568 time_t now; 04569 time(&now); 04570 time_t diff=cmd->command_data.check_time_1.now-now; // -x == remote is older 04571 time_t obj_diff=chd.last_changed-(cmd->command_data.check_time_1.original_time-diff); 04572 if(got2 && ((signed)obj_diff>60 || cmd->command_data.check_time_1.original_time==0)) { 04573 botnet_push_chan(*i1,chd); 04574 } else { 04575 s_bot_command* c=new s_bot_command; 04576 c->hard_clear(); 04577 c->packet_type=PACKET_TYPE_COMMAND; 04578 c->size=sizeof(c); 04579 c->version=1; 04580 c->command=CMD_NO_REPL_1; 04581 c->command_data.no_repl_1.user=cmd->command_data.check_time_1.user; 04582 c->command_data.no_repl_1.procedure=cmd->command_data.check_time_1.procedure; 04583 c->command_data.no_repl_1.channel_def=cmd->command_data.check_time_1.channel_def; 04584 c->command_data.no_repl_1.prv=cmd->command_data.check_time_1.prv; 04585 c->command_data.no_repl_1.reason=REASON_NO_REPL_1_UP_TO_DATE; 04586 memcpy(c->command_data.no_repl_1.object_name,cmd->command_data.check_time_1.object_name,sizeof(c->command_data.no_repl_1.object_name)); 04587 botnet_send_command(*i1,c); 04588 04589 string d="I have rejected replication of object "; 04590 if(c->command_data.no_repl_1.user) 04591 d+="(user)"; 04592 if(c->command_data.no_repl_1.procedure) 04593 d+="(procedure)"; 04594 if(c->command_data.no_repl_1.channel_def) 04595 d+="(channel)"; 04596 if(c->command_data.no_repl_1.prv) 04597 d+="(private)"; // no trailing SPACE!!! 04598 d+=", reason: "; 04599 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 04600 d+="up to date"; 04601 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 04602 d+="access denied"; 04603 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->command,d.c_str()); 04604 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 04605 04606 { 04607 string obj_type="channel"; 04608 04609 string reason="?"; 04610 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 04611 reason="up to date"; 04612 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 04613 reason="access denied"; 04614 04615 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"LOCAL"); 04616 } 04617 04618 delete c; 04619 } 04620 } 04621 if(cmd->command_data.check_time_1.prv) { 04622 bool got=false; 04623 vector<s_replication>::iterator i2; 04624 for(i2=r_private.replication.begin(); i2!=r_private.replication.end(); i2++) 04625 if(!(*i2).partner.compare(remote) && ((*i2).type==REPL_PUSH || (*i2).type==REPL_PUSHPULL)) { 04626 got=true; 04627 break; 04628 } 04629 s_user bot; 04630 logic_botnet_get_user((*i1)->botname,bot); 04631 if(!got) { 04632 s_bot_command* c=new s_bot_command; 04633 c->hard_clear(); 04634 c->packet_type=PACKET_TYPE_COMMAND; 04635 c->size=sizeof(c); 04636 c->version=1; 04637 c->command=CMD_NO_REPL_1; 04638 c->command_data.no_repl_1.user=cmd->command_data.check_time_1.user; 04639 c->command_data.no_repl_1.procedure=cmd->command_data.check_time_1.procedure; 04640 c->command_data.no_repl_1.channel_def=cmd->command_data.check_time_1.channel_def; 04641 c->command_data.no_repl_1.prv=cmd->command_data.check_time_1.prv; 04642 c->command_data.no_repl_1.reason=REASON_NO_REPL_1_ACCESS_DENIED; 04643 memcpy(c->command_data.no_repl_1.object_name,cmd->command_data.check_time_1.object_name,sizeof(c->command_data.no_repl_1.object_name)); 04644 botnet_send_command(*i1,c); 04645 04646 string d="I have rejected replication of object "; 04647 if(c->command_data.no_repl_1.user) 04648 d+="(user)"; 04649 if(c->command_data.no_repl_1.procedure) 04650 d+="(procedure)"; 04651 if(c->command_data.no_repl_1.channel_def) 04652 d+="(channel)"; 04653 if(c->command_data.no_repl_1.prv) 04654 d+="(private)"; // no trailing SPACE!!! 04655 d+=", reason: "; 04656 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 04657 d+="up to date"; 04658 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 04659 d+="access denied"; 04660 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->command,d.c_str()); 04661 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 04662 04663 { 04664 string obj_type="private"; 04665 04666 string reason="?"; 04667 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 04668 reason="up to date"; 04669 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 04670 reason="access denied"; 04671 04672 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"LOCAL"); 04673 } 04674 04675 delete c; 04676 04677 break; 04678 } 04679 time_t now; 04680 time(&now); 04681 time_t diff=cmd->command_data.check_time_1.now-now; // -x == remote is older 04682 time_t obj_diff=r_private.last_changed-(cmd->command_data.check_time_1.original_time-diff); 04683 if(((signed)obj_diff>60 || cmd->command_data.check_time_1.original_time==0)) { 04684 botnet_push_prv(*i1,r_private); 04685 } else { 04686 s_bot_command* c=new s_bot_command; 04687 c->hard_clear(); 04688 c->packet_type=PACKET_TYPE_COMMAND; 04689 c->size=sizeof(c); 04690 c->version=1; 04691 c->command=CMD_NO_REPL_1; 04692 c->command_data.no_repl_1.user=cmd->command_data.check_time_1.user; 04693 c->command_data.no_repl_1.procedure=cmd->command_data.check_time_1.procedure; 04694 c->command_data.no_repl_1.channel_def=cmd->command_data.check_time_1.channel_def; 04695 c->command_data.no_repl_1.prv=cmd->command_data.check_time_1.prv; 04696 c->command_data.no_repl_1.reason=REASON_NO_REPL_1_UP_TO_DATE; 04697 memcpy(c->command_data.no_repl_1.object_name,cmd->command_data.check_time_1.object_name,sizeof(c->command_data.no_repl_1.object_name)); 04698 botnet_send_command(*i1,c); 04699 04700 string d="I have rejected replication of object "; 04701 if(c->command_data.no_repl_1.user) 04702 d+="(user)"; 04703 if(c->command_data.no_repl_1.procedure) 04704 d+="(procedure)"; 04705 if(c->command_data.no_repl_1.channel_def) 04706 d+="(channel)"; 04707 if(c->command_data.no_repl_1.prv) 04708 d+="(private)"; // no trailing SPACE!!! 04709 d+=", reason: "; 04710 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 04711 d+="up to date"; 04712 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 04713 d+="access denied"; 04714 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->command,d.c_str()); 04715 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 04716 04717 { 04718 string obj_type="private"; 04719 04720 string reason="?"; 04721 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 04722 reason="up to date"; 04723 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 04724 reason="access denied"; 04725 04726 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"LOCAL"); 04727 } 04728 04729 delete c; 04730 } 04731 } 04732 } 04733 break; 04734 case CMD_NO_REPL_1: 04735 { 04736 char* obj=new char[sizeof(cmd->command_data.no_repl_1.object_name)+1]; 04737 obj[sizeof(cmd->command_data.no_repl_1.object_name)]=0; 04738 memcpy(obj,cmd->command_data.no_repl_1.object_name,sizeof(cmd->command_data.no_repl_1.object_name)); 04739 string d="remote bot rejected replication of object "; 04740 04741 string obj_type="?"; 04742 04743 if(cmd->command_data.no_repl_1.user) { 04744 obj_type="user"; 04745 d+="(user) "; 04746 (*i1)->rejected_objects.push_back((string)"USER "+obj); 04747 } 04748 if(cmd->command_data.no_repl_1.procedure) { 04749 obj_type="procedure"; 04750 d+="(procedure) "; 04751 (*i1)->rejected_objects.push_back((string)"PROC "+obj); 04752 } 04753 if(cmd->command_data.no_repl_1.channel_def) { 04754 obj_type="channel"; 04755 d+="(channel) "; 04756 (*i1)->rejected_objects.push_back((string)"CHAN "+obj); 04757 } 04758 if(cmd->command_data.no_repl_1.prv) { 04759 obj_type="private"; 04760 d+="(private)"; // no trailing SPACE!!! 04761 (*i1)->rejected_objects.push_back((string)"PRIV"); 04762 } 04763 04764 if(!cmd->command_data.no_repl_1.prv) 04765 d+=obj; 04766 d+=", reason: "; 04767 if(cmd->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 04768 d+="up to date"; 04769 if(cmd->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 04770 d+="access denied"; 04771 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),cmd->packet_type,cmd->command,d.c_str()); 04772 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 04773 04774 { 04775 string reason="?"; 04776 if(cmd->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 04777 reason="up to date"; 04778 if(cmd->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 04779 reason="access denied"; 04780 04781 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"REMOTE"); 04782 } 04783 04784 delete[] obj; 04785 } 04786 break; 04787 case CMD_PUSH_1: 04788 { 04789 // remote is trying to PUSH 04790 string obj=cmd->command_data.cmd_push_1.object_name; 04791 string remote=(*i1)->botname; 04792 if(cmd->command_data.cmd_push_1.user) { 04793 s_user us; 04794 bool got2=false; 04795 if(logic_botnet_get_user(obj,us)) 04796 got2=true; 04797 bool got=false; 04798 if(got2) { 04799 vector<s_replication>::iterator i2; 04800 for(i2=us.replication.begin(); i2!=us.replication.end(); i2++) 04801 if(!(*i2).partner.compare(remote) && ((*i2).type==REPL_PULL || (*i2).type==REPL_PUSHPULL)) { 04802 got=true; 04803 break; 04804 } 04805 } 04806 if(got2 && !got) { 04807 s_bot_command* c=new s_bot_command; 04808 c->hard_clear(); 04809 c->packet_type=PACKET_TYPE_COMMAND; 04810 c->size=sizeof(c); 04811 c->version=1; 04812 c->command=CMD_NO_REPL_1; 04813 c->command_data.no_repl_1.user=cmd->command_data.cmd_push_1.user; 04814 c->command_data.no_repl_1.procedure=cmd->command_data.cmd_push_1.procedure; 04815 c->command_data.no_repl_1.channel_def=cmd->command_data.cmd_push_1.channel_def; 04816 c->command_data.no_repl_1.prv=cmd->command_data.check_time_1.prv; 04817 c->command_data.no_repl_1.reason=REASON_NO_REPL_1_ACCESS_DENIED; 04818 memcpy(c->command_data.no_repl_1.object_name,cmd->command_data.cmd_push_1.object_name,sizeof(c->command_data.no_repl_1.object_name)); 04819 botnet_send_command(*i1,c); 04820 04821 string d="I have rejected replication of object "; 04822 if(c->command_data.no_repl_1.user) 04823 d+="(user) "; 04824 if(c->command_data.no_repl_1.procedure) 04825 d+="(procedure) "; 04826 if(c->command_data.no_repl_1.channel_def) 04827 d+="(channel) "; 04828 if(c->command_data.no_repl_1.prv) 04829 d+="(private)"; // no trailing SPACE!!! 04830 d+=obj; 04831 d+=", reason: "; 04832 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 04833 d+="up to date"; 04834 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 04835 d+="access denied"; 04836 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->command,d.c_str()); 04837 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 04838 04839 { 04840 string obj_type="?"; 04841 if(c->command_data.no_repl_1.user) 04842 obj_type="user"; 04843 if(c->command_data.no_repl_1.procedure) 04844 obj_type="procedure"; 04845 if(c->command_data.no_repl_1.channel_def) 04846 obj_type="channel"; 04847 if(c->command_data.no_repl_1.prv) 04848 obj_type="private"; 04849 04850 string reason="?"; 04851 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 04852 reason="up to date"; 04853 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 04854 reason="access denied"; 04855 04856 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"LOCAL"); 04857 } 04858 04859 delete c; 04860 04861 break; 04862 } 04863 time_t now; 04864 time(&now); 04865 time_t diff=cmd->command_data.check_time_1.now-now; // -x == remote is older 04866 time_t obj_diff=us.last_changed-(cmd->command_data.cmd_push_1.original_time-diff); 04867 if(!got2) { 04868 s_user bot; 04869 logic_botnet_get_user((*i1)->botname,bot); 04870 if((cmd->command_data.cmd_push_1.user && bot.access_to_plususer) || (cmd->command_data.cmd_push_1.procedure && bot.access_to_plusproc)) { 04871 s_bot_command* c=new s_bot_command; 04872 c->hard_clear(); 04873 c->packet_type=PACKET_TYPE_COMMAND; 04874 c->size=sizeof(c); 04875 c->version=1; 04876 c->command=CMD_CHECK_TIME_1; 04877 c->command_data.check_time_1.now=(my_time_t)time(NULL); 04878 c->command_data.check_time_1.user=true; 04879 c->command_data.check_time_1.procedure=false; 04880 c->command_data.check_time_1.channel_def=false; 04881 c->command_data.check_time_1.prv=false; 04882 char* user=c->command_data.cmd_push_1.object_name; 04883 memset(user,0,sizeof(c->command_data.cmd_push_1.object_name)); 04884 strncpy(user,obj.c_str(),sizeof(c->command_data.check_time_1.object_name)); 04885 c->command_data.check_time_1.original_time=0; 04886 botnet_send_command(*i1,c); 04887 04888 string d="replication: sent PULL request for object "; 04889 if(c->command_data.check_time_1.user) 04890 d+="(user) "; 04891 if(c->command_data.check_time_1.procedure) 04892 d+="(procedure) "; 04893 if(c->command_data.check_time_1.channel_def) 04894 d+="(channel) "; 04895 if(c->command_data.check_time_1.prv) 04896 d+="(private)"; // no trailing SPACE!!! 04897 d+=obj; 04898 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),-1,-1,d.c_str()); 04899 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 04900 04901 { 04902 string obj_type="?"; 04903 if(c->command_data.check_time_1.user) 04904 obj_type="user"; 04905 if(c->command_data.check_time_1.procedure) 04906 obj_type="procedure"; 04907 if(c->command_data.check_time_1.channel_def) 04908 obj_type="channel"; 04909 if(c->command_data.check_time_1.prv) 04910 obj_type="private"; 04911 04912 string reason="OK"; 04913 04914 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,d,"PULL_REQUEST"); 04915 } 04916 04917 delete c; 04918 } else { 04919 s_bot_command* c=new s_bot_command; 04920 c->hard_clear(); 04921 c->packet_type=PACKET_TYPE_COMMAND; 04922 c->size=sizeof(c); 04923 c->version=1; 04924 c->command=CMD_NO_REPL_1; 04925 c->command_data.no_repl_1.user=cmd->command_data.cmd_push_1.user; 04926 c->command_data.no_repl_1.procedure=cmd->command_data.cmd_push_1.procedure; 04927 c->command_data.no_repl_1.channel_def=cmd->command_data.cmd_push_1.channel_def; 04928 c->command_data.no_repl_1.prv=cmd->command_data.check_time_1.prv; 04929 c->command_data.no_repl_1.reason=REASON_NO_REPL_1_ACCESS_DENIED; 04930 memcpy(c->command_data.no_repl_1.object_name,cmd->command_data.cmd_push_1.object_name,sizeof(c->command_data.no_repl_1.object_name)); 04931 botnet_send_command(*i1,c); 04932 04933 string d="I have rejected replication of object "; 04934 if(c->command_data.no_repl_1.user) 04935 d+="(user) "; 04936 if(c->command_data.no_repl_1.procedure) 04937 d+="(procedure) "; 04938 if(c->command_data.no_repl_1.channel_def) 04939 d+="(channel) "; 04940 if(c->command_data.no_repl_1.prv) 04941 d+="(private)"; // no trailing SPACE!!! 04942 d+=obj; 04943 d+=", reason: "; 04944 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 04945 d+="up to date"; 04946 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 04947 d+="access denied"; 04948 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->command,d.c_str()); 04949 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 04950 04951 { 04952 string obj_type="?"; 04953 if(c->command_data.no_repl_1.user) 04954 obj_type="user"; 04955 if(c->command_data.no_repl_1.procedure) 04956 obj_type="procedure"; 04957 if(c->command_data.no_repl_1.channel_def) 04958 obj_type="channel"; 04959 if(c->command_data.no_repl_1.prv) 04960 obj_type="private"; 04961 04962 string reason="?"; 04963 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 04964 reason="up to date"; 04965 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 04966 reason="access denied"; 04967 04968 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"LOCAL"); 04969 } 04970 04971 delete c; 04972 04973 break; 04974 } 04975 } else 04976 if((signed)obj_diff>60) { 04977 s_bot_command* c=new s_bot_command; 04978 c->hard_clear(); 04979 c->packet_type=PACKET_TYPE_COMMAND; 04980 c->size=sizeof(c); 04981 c->version=1; 04982 c->command=CMD_CHECK_TIME_1; 04983 c->command_data.check_time_1.now=(my_time_t)time(NULL); 04984 c->command_data.check_time_1.user=true; 04985 c->command_data.check_time_1.procedure=false; 04986 c->command_data.check_time_1.channel_def=false; 04987 c->command_data.check_time_1.prv=false; 04988 char* user=c->command_data.cmd_push_1.object_name; 04989 memset(user,0,sizeof(c->command_data.cmd_push_1.object_name)); 04990 strncpy(user,us.name.c_str(),sizeof(c->command_data.check_time_1.object_name)); 04991 c->command_data.check_time_1.original_time=(my_time_t)us.last_changed; 04992 botnet_send_command(*i1,c); 04993 04994 string d="replication: sent PULL request for object "; 04995 if(c->command_data.check_time_1.user) 04996 d+="(user) "; 04997 if(c->command_data.check_time_1.procedure) 04998 d+="(procedure) "; 04999 if(c->command_data.check_time_1.channel_def) 05000 d+="(channel) "; 05001 if(c->command_data.check_time_1.prv) 05002 d+="(private)"; // no trailing SPACE!!! 05003 d+=us.name; 05004 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),-1,-1,d.c_str()); 05005 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 05006 05007 { 05008 string obj_type="?"; 05009 if(c->command_data.check_time_1.user) 05010 obj_type="user"; 05011 if(c->command_data.check_time_1.procedure) 05012 obj_type="procedure"; 05013 if(c->command_data.check_time_1.channel_def) 05014 obj_type="channel"; 05015 if(c->command_data.check_time_1.prv) 05016 obj_type="private"; 05017 05018 string reason="OK"; 05019 05020 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,d,"PULL_REQUEST"); 05021 } 05022 05023 delete c; 05024 } 05025 if((signed)obj_diff<=60) { 05026 s_bot_command* c=new s_bot_command; 05027 c->hard_clear(); 05028 c->packet_type=PACKET_TYPE_COMMAND; 05029 c->size=sizeof(c); 05030 c->version=1; 05031 c->command=CMD_NO_REPL_1; 05032 c->command_data.no_repl_1.user=cmd->command_data.cmd_push_1.user; 05033 c->command_data.no_repl_1.procedure=cmd->command_data.cmd_push_1.procedure; 05034 c->command_data.no_repl_1.channel_def=cmd->command_data.cmd_push_1.channel_def; 05035 c->command_data.no_repl_1.prv=cmd->command_data.check_time_1.prv; 05036 c->command_data.no_repl_1.reason=REASON_NO_REPL_1_UP_TO_DATE; 05037 memcpy(c->command_data.no_repl_1.object_name,cmd->command_data.cmd_push_1.object_name,sizeof(c->command_data.no_repl_1.object_name)); 05038 botnet_send_command(*i1,c); 05039 05040 string d="I have rejected replication of object "; 05041 if(c->command_data.no_repl_1.user) 05042 d+="(user) "; 05043 if(c->command_data.no_repl_1.procedure) 05044 d+="(procedure) "; 05045 if(c->command_data.no_repl_1.channel_def) 05046 d+="(channel) "; 05047 if(c->command_data.no_repl_1.prv) 05048 d+="(private)"; // no trailing SPACE!!! 05049 d+=obj; 05050 d+=", reason: "; 05051 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05052 d+="up to date"; 05053 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05054 d+="access denied"; 05055 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->command,d.c_str()); 05056 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 05057 05058 { 05059 string obj_type="?"; 05060 if(c->command_data.no_repl_1.user) 05061 obj_type="user"; 05062 if(c->command_data.no_repl_1.procedure) 05063 obj_type="procedure"; 05064 if(c->command_data.no_repl_1.channel_def) 05065 obj_type="channel"; 05066 if(c->command_data.no_repl_1.prv) 05067 obj_type="private"; 05068 05069 string reason="?"; 05070 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05071 reason="up to date"; 05072 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05073 reason="access denied"; 05074 05075 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"LOCAL"); 05076 } 05077 05078 delete c; 05079 } 05080 } 05081 if(cmd->command_data.cmd_push_1.procedure) { 05082 s_procedure p; 05083 bool got2=false; 05084 if(logic_botnet_get_proc(obj,p)) 05085 got2=true; 05086 bool got=false; 05087 if(got2) { 05088 vector<s_replication>::iterator i2; 05089 for(i2=p.replication.begin(); i2!=p.replication.end(); i2++) 05090 if(!(*i2).partner.compare(remote) && ((*i2).type==REPL_PULL || (*i2).type==REPL_PUSHPULL)) { 05091 got=true; 05092 break; 05093 } 05094 } 05095 if(got2 && !got) { 05096 s_bot_command* c=new s_bot_command; 05097 c->hard_clear(); 05098 c->packet_type=PACKET_TYPE_COMMAND; 05099 c->size=sizeof(c); 05100 c->version=1; 05101 c->command=CMD_NO_REPL_1; 05102 c->command_data.no_repl_1.user=cmd->command_data.cmd_push_1.user; 05103 c->command_data.no_repl_1.procedure=cmd->command_data.cmd_push_1.procedure; 05104 c->command_data.no_repl_1.channel_def=cmd->command_data.cmd_push_1.channel_def; 05105 c->command_data.no_repl_1.prv=cmd->command_data.check_time_1.prv; 05106 c->command_data.no_repl_1.reason=REASON_NO_REPL_1_ACCESS_DENIED; 05107 memcpy(c->command_data.no_repl_1.object_name,cmd->command_data.cmd_push_1.object_name,sizeof(c->command_data.no_repl_1.object_name)); 05108 botnet_send_command(*i1,c); 05109 05110 string d="I have rejected replication of object "; 05111 if(c->command_data.no_repl_1.user) 05112 d+="(user) "; 05113 if(c->command_data.no_repl_1.procedure) 05114 d+="(procedure) "; 05115 if(c->command_data.no_repl_1.channel_def) 05116 d+="(channel) "; 05117 if(c->command_data.no_repl_1.prv) 05118 d+="(private)"; // no trailing SPACE!!! 05119 d+=obj; 05120 d+=", reason: "; 05121 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05122 d+="up to date"; 05123 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05124 d+="access denied"; 05125 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->command,d.c_str()); 05126 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 05127 05128 { 05129 string obj_type="?"; 05130 if(c->command_data.no_repl_1.user) 05131 obj_type="user"; 05132 if(c->command_data.no_repl_1.procedure) 05133 obj_type="procedure"; 05134 if(c->command_data.no_repl_1.channel_def) 05135 obj_type="channel"; 05136 if(c->command_data.no_repl_1.prv) 05137 obj_type="private"; 05138 05139 string reason="?"; 05140 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05141 reason="up to date"; 05142 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05143 reason="access denied"; 05144 05145 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"LOCAL"); 05146 } 05147 05148 delete c; 05149 05150 break; 05151 } 05152 time_t now; 05153 time(&now); 05154 time_t diff=cmd->command_data.check_time_1.now-now; // -x == remote is older 05155 time_t obj_diff=p.last_changed-(cmd->command_data.cmd_push_1.original_time-diff); 05156 if(!got2) { 05157 s_user bot; 05158 logic_botnet_get_user((*i1)->botname,bot); 05159 if(bot.access_to_plusproc) { 05160 s_bot_command* c=new s_bot_command; 05161 c->hard_clear(); 05162 c->packet_type=PACKET_TYPE_COMMAND; 05163 c->size=sizeof(c); 05164 c->version=1; 05165 c->command=CMD_CHECK_TIME_1; 05166 c->command_data.check_time_1.now=(my_time_t)time(NULL); 05167 c->command_data.check_time_1.user=false; 05168 c->command_data.check_time_1.procedure=true; 05169 c->command_data.check_time_1.channel_def=false; 05170 c->command_data.check_time_1.prv=false; 05171 char* proc=c->command_data.cmd_push_1.object_name; 05172 memset(proc,0,sizeof(c->command_data.cmd_push_1.object_name)); 05173 strncpy(proc,obj.c_str(),sizeof(c->command_data.check_time_1.object_name)); 05174 c->command_data.check_time_1.original_time=0; 05175 botnet_send_command(*i1,c); 05176 05177 string d="replication: sent PULL request for object "; 05178 if(c->command_data.check_time_1.user) 05179 d+="(user) "; 05180 if(c->command_data.check_time_1.procedure) 05181 d+="(procedure) "; 05182 if(c->command_data.check_time_1.channel_def) 05183 d+="(channel) "; 05184 if(c->command_data.check_time_1.prv) 05185 d+="(private)"; // no trailing SPACE!!! 05186 d+=obj; 05187 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),-1,-1,d.c_str()); 05188 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 05189 05190 { 05191 string obj_type="?"; 05192 if(c->command_data.check_time_1.user) 05193 obj_type="user"; 05194 if(c->command_data.check_time_1.procedure) 05195 obj_type="procedure"; 05196 if(c->command_data.check_time_1.channel_def) 05197 obj_type="channel"; 05198 if(c->command_data.check_time_1.prv) 05199 obj_type="private"; 05200 05201 string reason="OK"; 05202 05203 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,d,"PULL_REQUEST"); 05204 } 05205 05206 delete c; 05207 } else { 05208 s_bot_command* c=new s_bot_command; 05209 c->hard_clear(); 05210 c->packet_type=PACKET_TYPE_COMMAND; 05211 c->size=sizeof(c); 05212 c->version=1; 05213 c->command=CMD_NO_REPL_1; 05214 c->command_data.no_repl_1.user=cmd->command_data.cmd_push_1.user; 05215 c->command_data.no_repl_1.procedure=cmd->command_data.cmd_push_1.procedure; 05216 c->command_data.no_repl_1.channel_def=cmd->command_data.cmd_push_1.channel_def; 05217 c->command_data.no_repl_1.prv=cmd->command_data.check_time_1.prv; 05218 c->command_data.no_repl_1.reason=REASON_NO_REPL_1_ACCESS_DENIED; 05219 memcpy(c->command_data.no_repl_1.object_name,cmd->command_data.cmd_push_1.object_name,sizeof(c->command_data.no_repl_1.object_name)); 05220 botnet_send_command(*i1,c); 05221 05222 string d="I have rejected replication of object "; 05223 if(c->command_data.no_repl_1.user) 05224 d+="(user) "; 05225 if(c->command_data.no_repl_1.procedure) 05226 d+="(procedure) "; 05227 if(c->command_data.no_repl_1.channel_def) 05228 d+="(channel) "; 05229 if(c->command_data.no_repl_1.prv) 05230 d+="(private)"; // no trailing SPACE!!! 05231 d+=obj; 05232 d+=", reason: "; 05233 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05234 d+="up to date"; 05235 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05236 d+="access denied"; 05237 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->command,d.c_str()); 05238 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 05239 05240 { 05241 string obj_type="?"; 05242 if(c->command_data.no_repl_1.user) 05243 obj_type="user"; 05244 if(c->command_data.no_repl_1.procedure) 05245 obj_type="procedure"; 05246 if(c->command_data.no_repl_1.channel_def) 05247 obj_type="channel"; 05248 if(c->command_data.no_repl_1.prv) 05249 obj_type="private"; 05250 05251 string reason="?"; 05252 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05253 reason="up to date"; 05254 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05255 reason="access denied"; 05256 05257 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"LOCAL"); 05258 } 05259 05260 delete c; 05261 05262 break; 05263 } 05264 } else 05265 if((signed)obj_diff>60) { 05266 s_bot_command* c=new s_bot_command; 05267 c->hard_clear(); 05268 c->packet_type=PACKET_TYPE_COMMAND; 05269 c->size=sizeof(c); 05270 c->version=1; 05271 c->command=CMD_CHECK_TIME_1; 05272 c->command_data.check_time_1.now=(my_time_t)time(NULL); 05273 c->command_data.check_time_1.user=false; 05274 c->command_data.check_time_1.procedure=true; 05275 c->command_data.check_time_1.channel_def=false; 05276 c->command_data.check_time_1.prv=false; 05277 char* proc=c->command_data.cmd_push_1.object_name; 05278 memset(proc,0,sizeof(c->command_data.cmd_push_1.object_name)); 05279 strncpy(proc,p.name.c_str(),sizeof(c->command_data.check_time_1.object_name)); 05280 c->command_data.check_time_1.original_time=(my_time_t)p.last_changed; 05281 botnet_send_command(*i1,c); 05282 05283 string d="replication: sent PULL request for object "; 05284 if(c->command_data.check_time_1.user) 05285 d+="(user) "; 05286 if(c->command_data.check_time_1.procedure) 05287 d+="(procedure) "; 05288 if(c->command_data.check_time_1.channel_def) 05289 d+="(channel) "; 05290 if(c->command_data.check_time_1.prv) 05291 d+="(private)"; // no trailing SPACE!!! 05292 d+=p.name; 05293 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),-1,-1,d.c_str()); 05294 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 05295 05296 { 05297 string obj_type="?"; 05298 if(c->command_data.check_time_1.user) 05299 obj_type="user"; 05300 if(c->command_data.check_time_1.procedure) 05301 obj_type="procedure"; 05302 if(c->command_data.check_time_1.channel_def) 05303 obj_type="channel"; 05304 if(c->command_data.check_time_1.prv) 05305 obj_type="private"; 05306 05307 string reason="OK"; 05308 05309 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,d,"PULL_REQUEST"); 05310 } 05311 05312 delete c; 05313 } 05314 if((signed)obj_diff<=60) { 05315 s_bot_command* c=new s_bot_command; 05316 c->hard_clear(); 05317 c->packet_type=PACKET_TYPE_COMMAND; 05318 c->size=sizeof(c); 05319 c->version=1; 05320 c->command=CMD_NO_REPL_1; 05321 c->command_data.no_repl_1.user=cmd->command_data.cmd_push_1.user; 05322 c->command_data.no_repl_1.procedure=cmd->command_data.cmd_push_1.procedure; 05323 c->command_data.no_repl_1.channel_def=cmd->command_data.cmd_push_1.channel_def; 05324 c->command_data.no_repl_1.prv=cmd->command_data.check_time_1.prv; 05325 c->command_data.no_repl_1.reason=REASON_NO_REPL_1_UP_TO_DATE; 05326 memcpy(c->command_data.no_repl_1.object_name,cmd->command_data.cmd_push_1.object_name,sizeof(c->command_data.no_repl_1.object_name)); 05327 botnet_send_command(*i1,c); 05328 05329 string d="I have rejected replication of object "; 05330 if(c->command_data.no_repl_1.user) 05331 d+="(user) "; 05332 if(c->command_data.no_repl_1.procedure) 05333 d+="(procedure) "; 05334 if(c->command_data.no_repl_1.channel_def) 05335 d+="(channel) "; 05336 if(c->command_data.no_repl_1.prv) 05337 d+="(private)"; // no trailing SPACE!!! 05338 d+=obj; 05339 d+=", reason: "; 05340 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05341 d+="up to date"; 05342 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05343 d+="access denied"; 05344 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->command,d.c_str()); 05345 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 05346 05347 { 05348 string obj_type="?"; 05349 if(c->command_data.no_repl_1.user) 05350 obj_type="user"; 05351 if(c->command_data.no_repl_1.procedure) 05352 obj_type="procedure"; 05353 if(c->command_data.no_repl_1.channel_def) 05354 obj_type="channel"; 05355 if(c->command_data.no_repl_1.prv) 05356 obj_type="private"; 05357 05358 string reason="?"; 05359 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05360 reason="up to date"; 05361 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05362 reason="access denied"; 05363 05364 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"LOCAL"); 05365 } 05366 05367 delete c; 05368 } 05369 } 05370 if(cmd->command_data.cmd_push_1.channel_def) { 05371 s_channel_def chd; 05372 bool got2=false; 05373 if(logic_botnet_get_channel_def(obj,chd)) 05374 got2=true; 05375 bool got=false; 05376 if(got2) { 05377 vector<s_replication>::iterator i2; 05378 for(i2=chd.replication.begin(); i2!=chd.replication.end(); i2++) 05379 if(!(*i2).partner.compare(remote) && ((*i2).type==REPL_PULL || (*i2).type==REPL_PUSHPULL)) { 05380 got=true; 05381 break; 05382 } 05383 } 05384 if(got2 && !got) { 05385 s_bot_command* c=new s_bot_command; 05386 c->hard_clear(); 05387 c->packet_type=PACKET_TYPE_COMMAND; 05388 c->size=sizeof(c); 05389 c->version=1; 05390 c->command=CMD_NO_REPL_1; 05391 c->command_data.no_repl_1.user=cmd->command_data.cmd_push_1.user; 05392 c->command_data.no_repl_1.procedure=cmd->command_data.cmd_push_1.procedure; 05393 c->command_data.no_repl_1.channel_def=cmd->command_data.cmd_push_1.channel_def; 05394 c->command_data.no_repl_1.prv=cmd->command_data.check_time_1.prv; 05395 c->command_data.no_repl_1.reason=REASON_NO_REPL_1_ACCESS_DENIED; 05396 memcpy(c->command_data.no_repl_1.object_name,cmd->command_data.cmd_push_1.object_name,sizeof(c->command_data.no_repl_1.object_name)); 05397 botnet_send_command(*i1,c); 05398 05399 string d="I have rejected replication of object "; 05400 if(c->command_data.no_repl_1.user) 05401 d+="(user) "; 05402 if(c->command_data.no_repl_1.procedure) 05403 d+="(procedure) "; 05404 if(c->command_data.no_repl_1.channel_def) 05405 d+="(channel) "; 05406 if(c->command_data.no_repl_1.prv) 05407 d+="(private)"; // no trailing SPACE!!! 05408 d+=obj; 05409 d+=", reason: "; 05410 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05411 d+="up to date"; 05412 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05413 d+="access denied"; 05414 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->command,d.c_str()); 05415 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 05416 05417 { 05418 string obj_type="?"; 05419 if(c->command_data.no_repl_1.user) 05420 obj_type="user"; 05421 if(c->command_data.no_repl_1.procedure) 05422 obj_type="procedure"; 05423 if(c->command_data.no_repl_1.channel_def) 05424 obj_type="channel"; 05425 if(c->command_data.no_repl_1.prv) 05426 obj_type="private"; 05427 05428 string reason="?"; 05429 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05430 reason="up to date"; 05431 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05432 reason="access denied"; 05433 05434 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"LOCAL"); 05435 } 05436 05437 delete c; 05438 05439 break; 05440 } 05441 time_t now; 05442 time(&now); 05443 time_t diff=cmd->command_data.check_time_1.now-now; // -x == remote is older 05444 time_t obj_diff=chd.last_changed-(cmd->command_data.cmd_push_1.original_time-diff); 05445 if(!got2) { 05446 s_user bot; 05447 logic_botnet_get_user((*i1)->botname,bot); 05448 vector<string>::iterator i2; 05449 bool access=false; 05450 map<string,string> vars; 05451 for(i2=bot.access_to_channel.begin(); i2!=bot.access_to_channel.end(); i2++) 05452 if(!(logic_eval(*i2,vars)).compare(obj) || !(*i2).compare("*")) { 05453 access=true; 05454 break; 05455 } 05456 if(access) { 05457 s_bot_command* c=new s_bot_command; 05458 c->hard_clear(); 05459 c->packet_type=PACKET_TYPE_COMMAND; 05460 c->size=sizeof(c); 05461 c->version=1; 05462 c->command=CMD_CHECK_TIME_1; 05463 c->command_data.check_time_1.now=(my_time_t)time(NULL); 05464 c->command_data.check_time_1.user=false; 05465 c->command_data.check_time_1.procedure=false; 05466 c->command_data.check_time_1.channel_def=true; 05467 c->command_data.check_time_1.prv=false; 05468 char* user=c->command_data.cmd_push_1.object_name; 05469 memset(user,0,sizeof(c->command_data.cmd_push_1.object_name)); 05470 strncpy(user,obj.c_str(),sizeof(c->command_data.check_time_1.object_name)); 05471 c->command_data.check_time_1.original_time=0; 05472 botnet_send_command(*i1,c); 05473 05474 string d="replication: sent PULL request for object "; 05475 if(c->command_data.check_time_1.user) 05476 d+="(user) "; 05477 if(c->command_data.check_time_1.procedure) 05478 d+="(procedure) "; 05479 if(c->command_data.check_time_1.channel_def) 05480 d+="(channel) "; 05481 if(c->command_data.check_time_1.prv) 05482 d+="(private)"; // no trailing SPACE!!! 05483 d+=obj; 05484 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),-1,-1,d.c_str()); 05485 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 05486 05487 { 05488 string obj_type="?"; 05489 if(c->command_data.check_time_1.user) 05490 obj_type="user"; 05491 if(c->command_data.check_time_1.procedure) 05492 obj_type="procedure"; 05493 if(c->command_data.check_time_1.channel_def) 05494 obj_type="channel"; 05495 if(c->command_data.check_time_1.prv) 05496 obj_type="private"; 05497 05498 string reason="OK"; 05499 05500 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,d,"PULL_REQUEST"); 05501 } 05502 05503 delete c; 05504 } else { 05505 s_bot_command* c=new s_bot_command; 05506 c->hard_clear(); 05507 c->packet_type=PACKET_TYPE_COMMAND; 05508 c->size=sizeof(c); 05509 c->version=1; 05510 c->command=CMD_NO_REPL_1; 05511 c->command_data.no_repl_1.user=cmd->command_data.cmd_push_1.user; 05512 c->command_data.no_repl_1.procedure=cmd->command_data.cmd_push_1.procedure; 05513 c->command_data.no_repl_1.channel_def=cmd->command_data.cmd_push_1.channel_def; 05514 c->command_data.no_repl_1.prv=cmd->command_data.check_time_1.prv; 05515 c->command_data.no_repl_1.reason=REASON_NO_REPL_1_ACCESS_DENIED; 05516 memcpy(c->command_data.no_repl_1.object_name,cmd->command_data.cmd_push_1.object_name,sizeof(c->command_data.no_repl_1.object_name)); 05517 botnet_send_command(*i1,c); 05518 05519 string d="I have rejected replication of object "; 05520 if(c->command_data.no_repl_1.user) 05521 d+="(user) "; 05522 if(c->command_data.no_repl_1.procedure) 05523 d+="(procedure) "; 05524 if(c->command_data.no_repl_1.channel_def) 05525 d+="(channel) "; 05526 if(c->command_data.no_repl_1.prv) 05527 d+="(private)"; // no trailing SPACE!!! 05528 d+=obj; 05529 d+=", reason: "; 05530 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05531 d+="up to date"; 05532 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05533 d+="access denied"; 05534 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->command,d.c_str()); 05535 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 05536 05537 { 05538 string obj_type="?"; 05539 if(c->command_data.no_repl_1.user) 05540 obj_type="user"; 05541 if(c->command_data.no_repl_1.procedure) 05542 obj_type="procedure"; 05543 if(c->command_data.no_repl_1.channel_def) 05544 obj_type="channel"; 05545 if(c->command_data.no_repl_1.prv) 05546 obj_type="private"; 05547 05548 string reason="?"; 05549 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05550 reason="up to date"; 05551 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05552 reason="access denied"; 05553 05554 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"LOCAL"); 05555 } 05556 05557 delete c; 05558 05559 break; 05560 } 05561 } else 05562 if((signed)obj_diff>60) { 05563 s_bot_command* c=new s_bot_command; 05564 c->hard_clear(); 05565 c->packet_type=PACKET_TYPE_COMMAND; 05566 c->size=sizeof(c); 05567 c->version=1; 05568 c->command=CMD_CHECK_TIME_1; 05569 c->command_data.check_time_1.now=(my_time_t)time(NULL); 05570 c->command_data.check_time_1.user=false; 05571 c->command_data.check_time_1.procedure=false; 05572 c->command_data.check_time_1.channel_def=true; 05573 c->command_data.check_time_1.prv=false; 05574 char* chan=c->command_data.cmd_push_1.object_name; 05575 memset(chan,0,sizeof(c->command_data.cmd_push_1.object_name)); 05576 strncpy(chan,chd.channel_name.c_str(),sizeof(c->command_data.check_time_1.object_name)); 05577 c->command_data.check_time_1.original_time=(my_time_t)chd.last_changed; 05578 botnet_send_command(*i1,c); 05579 05580 string d="replication: sent PULL request for object "; 05581 if(c->command_data.check_time_1.user) 05582 d+="(user) "; 05583 if(c->command_data.check_time_1.procedure) 05584 d+="(procedure) "; 05585 if(c->command_data.check_time_1.channel_def) 05586 d+="(channel) "; 05587 if(c->command_data.check_time_1.prv) 05588 d+="(private)"; // no trailing SPACE!!! 05589 d+=chd.channel_name; 05590 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),-1,-1,d.c_str()); 05591 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 05592 05593 { 05594 string obj_type="?"; 05595 if(c->command_data.check_time_1.user) 05596 obj_type="user"; 05597 if(c->command_data.check_time_1.procedure) 05598 obj_type="procedure"; 05599 if(c->command_data.check_time_1.channel_def) 05600 obj_type="channel"; 05601 if(c->command_data.check_time_1.prv) 05602 obj_type="private"; 05603 05604 string reason="OK"; 05605 05606 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,d,"PULL_REQUEST"); 05607 } 05608 05609 delete c; 05610 } 05611 if((signed)obj_diff<=60) { 05612 s_bot_command* c=new s_bot_command; 05613 c->hard_clear(); 05614 c->packet_type=PACKET_TYPE_COMMAND; 05615 c->size=sizeof(c); 05616 c->version=1; 05617 c->command=CMD_NO_REPL_1; 05618 c->command_data.no_repl_1.user=cmd->command_data.cmd_push_1.user; 05619 c->command_data.no_repl_1.procedure=cmd->command_data.cmd_push_1.procedure; 05620 c->command_data.no_repl_1.channel_def=cmd->command_data.cmd_push_1.channel_def; 05621 c->command_data.no_repl_1.prv=cmd->command_data.check_time_1.prv; 05622 c->command_data.no_repl_1.reason=REASON_NO_REPL_1_UP_TO_DATE; 05623 memcpy(c->command_data.no_repl_1.object_name,cmd->command_data.cmd_push_1.object_name,sizeof(c->command_data.no_repl_1.object_name)); 05624 botnet_send_command(*i1,c); 05625 05626 string d="I have rejected replication of object "; 05627 if(c->command_data.no_repl_1.user) 05628 d+="(user) "; 05629 if(c->command_data.no_repl_1.procedure) 05630 d+="(procedure) "; 05631 if(c->command_data.no_repl_1.channel_def) 05632 d+="(channel) "; 05633 if(c->command_data.no_repl_1.prv) 05634 d+="(private)"; // no trailing SPACE!!! 05635 d+=obj; 05636 d+=", reason: "; 05637 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05638 d+="up to date"; 05639 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05640 d+="access denied"; 05641 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->command,d.c_str()); 05642 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 05643 05644 { 05645 string obj_type="?"; 05646 if(c->command_data.no_repl_1.user) 05647 obj_type="user"; 05648 if(c->command_data.no_repl_1.procedure) 05649 obj_type="procedure"; 05650 if(c->command_data.no_repl_1.channel_def) 05651 obj_type="channel"; 05652 if(c->command_data.no_repl_1.prv) 05653 obj_type="private"; 05654 05655 string reason="?"; 05656 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05657 reason="up to date"; 05658 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05659 reason="access denied"; 05660 05661 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"LOCAL"); 05662 } 05663 05664 delete c; 05665 } 05666 } 05667 if(cmd->command_data.cmd_push_1.prv) { 05668 bool got=false; 05669 vector<s_replication>::iterator i2; 05670 for(i2=r_private.replication.begin(); i2!=r_private.replication.end(); i2++) 05671 if(!(*i2).partner.compare(remote) && ((*i2).type==REPL_PULL || (*i2).type==REPL_PUSHPULL)) { 05672 got=true; 05673 break; 05674 } 05675 if(!got) { 05676 s_bot_command* c=new s_bot_command; 05677 c->hard_clear(); 05678 c->packet_type=PACKET_TYPE_COMMAND; 05679 c->size=sizeof(c); 05680 c->version=1; 05681 c->command=CMD_NO_REPL_1; 05682 c->command_data.no_repl_1.user=cmd->command_data.check_time_1.user; 05683 c->command_data.no_repl_1.procedure=cmd->command_data.check_time_1.procedure; 05684 c->command_data.no_repl_1.channel_def=cmd->command_data.check_time_1.channel_def; 05685 c->command_data.no_repl_1.prv=cmd->command_data.check_time_1.prv; 05686 c->command_data.no_repl_1.reason=REASON_NO_REPL_1_ACCESS_DENIED; 05687 memcpy(c->command_data.no_repl_1.object_name,cmd->command_data.check_time_1.object_name,sizeof(c->command_data.no_repl_1.object_name)); 05688 botnet_send_command(*i1,c); 05689 05690 string d="I have rejected replication of object "; 05691 if(c->command_data.no_repl_1.user) 05692 d+="(user) "; 05693 if(c->command_data.no_repl_1.procedure) 05694 d+="(procedure) "; 05695 if(c->command_data.no_repl_1.channel_def) 05696 d+="(channel) "; 05697 if(c->command_data.no_repl_1.prv) 05698 d+="(private)"; // no trailing SPACE!!! 05699 d+=", reason: "; 05700 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05701 d+="up to date"; 05702 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05703 d+="access denied"; 05704 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->command,d.c_str()); 05705 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 05706 05707 { 05708 string obj_type="?"; 05709 if(c->command_data.no_repl_1.user) 05710 obj_type="user"; 05711 if(c->command_data.no_repl_1.procedure) 05712 obj_type="procedure"; 05713 if(c->command_data.no_repl_1.channel_def) 05714 obj_type="channel"; 05715 if(c->command_data.no_repl_1.prv) 05716 obj_type="private"; 05717 05718 string reason="?"; 05719 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05720 reason="up to date"; 05721 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05722 reason="access denied"; 05723 05724 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"LOCAL"); 05725 } 05726 05727 delete c; 05728 05729 break; 05730 } 05731 time_t now; 05732 time(&now); 05733 time_t diff=cmd->command_data.check_time_1.now-now; // -x == remote is older 05734 time_t obj_diff=r_private.last_changed-(cmd->command_data.cmd_push_1.original_time-diff); 05735 05736 s_user bot; 05737 logic_botnet_get_user((*i1)->botname,bot); 05738 05739 if(cmd->command_data.cmd_push_1.prv && bot.access_to_private) { 05740 if((signed)obj_diff>60) { 05741 s_bot_command* c=new s_bot_command; 05742 c->hard_clear(); 05743 c->packet_type=PACKET_TYPE_COMMAND; 05744 c->size=sizeof(c); 05745 c->version=1; 05746 c->command=CMD_CHECK_TIME_1; 05747 c->command_data.check_time_1.now=(my_time_t)time(NULL); 05748 c->command_data.check_time_1.user=false; 05749 c->command_data.check_time_1.procedure=false; 05750 c->command_data.check_time_1.channel_def=false; 05751 c->command_data.check_time_1.prv=true; 05752 c->command_data.check_time_1.original_time=(my_time_t)r_private.last_changed; 05753 botnet_send_command(*i1,c); 05754 05755 string d="replication: sent PULL request for object "; 05756 d+="(private)"; // no trailing SPACE!!! 05757 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),-1,-1,d.c_str()); 05758 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 05759 05760 (*i1)->prv_pulling=true; 05761 05762 { 05763 string obj_type="?"; 05764 if(c->command_data.check_time_1.user) 05765 obj_type="user"; 05766 if(c->command_data.check_time_1.procedure) 05767 obj_type="procedure"; 05768 if(c->command_data.check_time_1.channel_def) 05769 obj_type="channel"; 05770 if(c->command_data.check_time_1.prv) 05771 obj_type="private"; 05772 05773 string reason="OK"; 05774 05775 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,d,"PULL_REQUEST"); 05776 } 05777 05778 delete c; 05779 } 05780 if((signed)obj_diff<=60) { 05781 s_bot_command* c=new s_bot_command; 05782 c->hard_clear(); 05783 c->packet_type=PACKET_TYPE_COMMAND; 05784 c->size=sizeof(c); 05785 c->version=1; 05786 c->command=CMD_NO_REPL_1; 05787 c->command_data.check_time_1.user=false; 05788 c->command_data.no_repl_1.procedure=false; 05789 c->command_data.no_repl_1.channel_def=false; 05790 c->command_data.no_repl_1.prv=true; 05791 c->command_data.no_repl_1.reason=REASON_NO_REPL_1_UP_TO_DATE; 05792 memcpy(c->command_data.no_repl_1.object_name,cmd->command_data.cmd_push_1.object_name,sizeof(c->command_data.no_repl_1.object_name)); 05793 botnet_send_command(*i1,c); 05794 05795 string d="I have rejected replication of object "; 05796 if(c->command_data.no_repl_1.user) 05797 d+="(user) "; 05798 if(c->command_data.no_repl_1.procedure) 05799 d+="(procedure) "; 05800 if(c->command_data.no_repl_1.channel_def) 05801 d+="(channel) "; 05802 if(c->command_data.no_repl_1.prv) 05803 d+="(private)"; // no trailing SPACE!!! 05804 d+=", reason: "; 05805 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05806 d+="up to date"; 05807 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05808 d+="access denied"; 05809 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->command,d.c_str()); 05810 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 05811 05812 { 05813 string obj_type="?"; 05814 if(c->command_data.no_repl_1.user) 05815 obj_type="user"; 05816 if(c->command_data.no_repl_1.procedure) 05817 obj_type="procedure"; 05818 if(c->command_data.no_repl_1.channel_def) 05819 obj_type="channel"; 05820 if(c->command_data.no_repl_1.prv) 05821 obj_type="private"; 05822 05823 string reason="?"; 05824 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05825 reason="up to date"; 05826 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05827 reason="access denied"; 05828 05829 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"LOCAL"); 05830 } 05831 05832 delete c; 05833 } 05834 } else { 05835 s_bot_command* c=new s_bot_command; 05836 c->hard_clear(); 05837 c->packet_type=PACKET_TYPE_COMMAND; 05838 c->size=sizeof(c); 05839 c->version=1; 05840 c->command=CMD_NO_REPL_1; 05841 c->command_data.check_time_1.user=false; 05842 c->command_data.no_repl_1.procedure=false; 05843 c->command_data.no_repl_1.channel_def=false; 05844 c->command_data.no_repl_1.prv=true; 05845 c->command_data.no_repl_1.reason=REASON_NO_REPL_1_ACCESS_DENIED; 05846 memcpy(c->command_data.no_repl_1.object_name,cmd->command_data.cmd_push_1.object_name,sizeof(c->command_data.no_repl_1.object_name)); 05847 botnet_send_command(*i1,c); 05848 05849 string d="I have rejected replication of object "; 05850 if(c->command_data.no_repl_1.user) 05851 d+="(user) "; 05852 if(c->command_data.no_repl_1.procedure) 05853 d+="(procedure) "; 05854 if(c->command_data.no_repl_1.channel_def) 05855 d+="(channel) "; 05856 if(c->command_data.no_repl_1.prv) 05857 d+="(private)"; // no trailing SPACE!!! 05858 d+=", reason: "; 05859 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05860 d+="up to date"; 05861 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05862 d+="access denied"; 05863 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->command,d.c_str()); 05864 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 05865 05866 { 05867 string obj_type="?"; 05868 if(c->command_data.no_repl_1.user) 05869 obj_type="user"; 05870 if(c->command_data.no_repl_1.procedure) 05871 obj_type="procedure"; 05872 if(c->command_data.no_repl_1.channel_def) 05873 obj_type="channel"; 05874 if(c->command_data.no_repl_1.prv) 05875 obj_type="private"; 05876 05877 string reason="?"; 05878 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_UP_TO_DATE) 05879 reason="up to date"; 05880 if(c->command_data.no_repl_1.reason==REASON_NO_REPL_1_ACCESS_DENIED) 05881 reason="access denied"; 05882 05883 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"LOCAL"); 05884 } 05885 05886 delete c; 05887 05888 break; 05889 } 05890 } 05891 } 05892 break; 05893 case CMD_REPL_USER_01_1: 05894 { 05895 int n_size=sizeof(cmd->command_data.cmd_repl_user_01_1.name); 05896 char* n=new char[n_size+1]; 05897 memset(n,0,n_size+1); 05898 memcpy(n,cmd->command_data.cmd_repl_user_01_1.name,n_size); 05899 string name=n; 05900 delete[] n; 05901 n=NULL; 05902 05903 { 05904 again_erase: 05905 vector<s_user_to_pull>::iterator i2; 05906 for(i2=(*i1)->pulling_users.begin(); i2!=(*i1)->pulling_users.end(); i2++) { 05907 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).user.name.compare(name)) { 05908 (*i1)->pulling_users.erase(i2); 05909 goto again_erase; 05910 } 05911 } 05912 05913 bool got=false; 05914 vector<s_user>::iterator i3; 05915 for(i3=r_users.begin(); i3!=r_users.end(); i3++) { 05916 if(!(*i3).name.compare(name)) { 05917 got=true; 05918 vector<s_replication>::iterator i4; 05919 for(i4=(*i3).replication.begin(); i4!=(*i3).replication.end(); i4++) { 05920 if(!(*i4).partner.compare((*i1)->botname) && ((*i4).type==REPL_PULL || (*i4).type==REPL_PUSHPULL)) { 05921 s_user_to_pull u; 05922 u.botname=(*i1)->botname; 05923 u.user=*i3; 05924 (*i1)->pulling_users.push_back(u); 05925 got=true; 05926 break; 05927 } 05928 } 05929 if(got) 05930 break; 05931 } 05932 } 05933 if(!got) { 05934 s_user_to_pull u; 05935 u.botname=(*i1)->botname; 05936 u.user.name=name; 05937 u.user.replication_partner=false; 05938 u.user.meta.clear(); 05939 05940 // we got a new user, so set them replication flags 05941 s_replication r; 05942 r.partner=(*i1)->botname; 05943 r.type=REPL_PULL; 05944 u.user.replication.push_back(r); 05945 05946 (*i1)->pulling_users.push_back(u); 05947 } 05948 } 05949 05950 s_user_to_pull* u=NULL; 05951 bool got=false; 05952 vector<s_user_to_pull>::iterator i2; 05953 for(i2=(*i1)->pulling_users.begin(); i2!=(*i1)->pulling_users.end(); i2++) { 05954 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).user.name.compare(name)) { 05955 u=&(*i2); 05956 got=true; 05957 break; 05958 } 05959 } 05960 if(got) { 05961 u->user.host_unknown=cmd->command_data.cmd_repl_user_01_1.host_unknown; 05962 u->user.host_bot=cmd->command_data.cmd_repl_user_01_1.host_bot; 05963 u->user.is_template=cmd->command_data.cmd_repl_user_01_1.is_template; 05964 u->user.terminator=cmd->command_data.cmd_repl_user_01_1.terminator; 05965 u->user.access_grant_partyline=cmd->command_data.cmd_repl_user_01_1.access_grant_partyline; 05966 u->user.access_to_backup=cmd->command_data.cmd_repl_user_01_1.access_to_backup; 05967 u->user.access_grant_backup=cmd->command_data.cmd_repl_user_01_1.access_grant_backup; 05968 u->user.access_to_rehash=cmd->command_data.cmd_repl_user_01_1.access_to_rehash; 05969 u->user.access_grant_rehash=cmd->command_data.cmd_repl_user_01_1.access_grant_rehash; 05970 u->user.access_to_partyline=cmd->command_data.cmd_repl_user_01_1.access_to_partyline; 05971 u->user.access_grant_partyline=cmd->command_data.cmd_repl_user_01_1.access_grant_partyline; 05972 05973 u->user.access_to_plususer=cmd->command_data.cmd_repl_user_01_1.access_to_plususer; 05974 u->user.access_grant_plususer=cmd->command_data.cmd_repl_user_01_1.access_grant_plususer; 05975 u->user.access_to_plusproc=cmd->command_data.cmd_repl_user_01_1.access_to_plusproc; 05976 u->user.access_grant_plusproc=cmd->command_data.cmd_repl_user_01_1.access_grant_plusproc; 05977 05978 u->user.access_to_can_send_all_users=cmd->command_data.cmd_repl_user_01_1.access_to_can_send_all_users; 05979 u->user.access_grant_can_send_all_users=cmd->command_data.cmd_repl_user_01_1.access_grant_can_send_all_users; 05980 05981 u->user.access_to_can_send_unknown_users=cmd->command_data.cmd_repl_user_01_1.access_to_can_send_unknown_users; 05982 u->user.access_grant_can_send_unknown_users=cmd->command_data.cmd_repl_user_01_1.access_grant_can_send_unknown_users; 05983 05984 u->user.last_changed=cmd->command_data.cmd_repl_user_01_1.last_changed; 05985 05986 u->user.hostmask.clear(); 05987 u->user.fullname.clear(); 05988 u->user.access_to_group.clear(); 05989 u->user.access_to_proc.clear(); 05990 u->user.access_grant_procedure.clear(); 05991 u->user.access_grant_group.clear(); 05992 u->user.access_to_channel.clear(); 05993 u->user.access_grant_channel.clear(); 05994 u->user.groups.clear(); 05995 u->user.dcc_hosts.clear(); 05996 05997 u->user.partyline_msg_flood.lines=cmd->command_data.cmd_repl_user_01_1.partyline_msg_flood.lines; 05998 u->user.partyline_msg_flood.seconds=cmd->command_data.cmd_repl_user_01_1.partyline_msg_flood.seconds; 05999 } 06000 } 06001 break; 06002 case CMD_REPL_USER_02_1: 06003 { 06004 int n_size=sizeof(cmd->command_data.cmd_repl_user_02_1.name); // !!! 06005 char* n=new char[n_size+1]; 06006 memset(n,0,n_size+1); 06007 memcpy(n,cmd->command_data.cmd_repl_user_02_1.name,n_size); // !!! 06008 string name=n; 06009 delete[] n; 06010 n=NULL; 06011 06012 s_user_to_pull* u=NULL; 06013 bool got=false; 06014 vector<s_user_to_pull>::iterator i2; 06015 for(i2=(*i1)->pulling_users.begin(); i2!=(*i1)->pulling_users.end(); i2++) { 06016 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).user.name.compare(name)) { 06017 u=&(*i2); 06018 got=true; 06019 break; 06020 } 06021 } 06022 if(got) { 06023 int d_size=sizeof(cmd->command_data.cmd_repl_user_02_1.hostmask); // !!! 06024 char* d=new char[d_size+1]; 06025 memset(d,0,d_size+1); 06026 memcpy(d,cmd->command_data.cmd_repl_user_02_1.hostmask,d_size); // !!! 06027 string data=d; 06028 delete[] d; 06029 d=NULL; 06030 06031 u->user.hostmask.push_back(data); 06032 } 06033 } 06034 break; 06035 case CMD_REPL_USER_03_1: 06036 { 06037 int n_size=sizeof(cmd->command_data.cmd_repl_user_03_1.name); // !!! 06038 char* n=new char[n_size+1]; 06039 memset(n,0,n_size+1); 06040 memcpy(n,cmd->command_data.cmd_repl_user_03_1.name,n_size); // !!! 06041 string name=n; 06042 delete[] n; 06043 n=NULL; 06044 06045 s_user_to_pull* u=NULL; 06046 bool got=false; 06047 vector<s_user_to_pull>::iterator i2; 06048 for(i2=(*i1)->pulling_users.begin(); i2!=(*i1)->pulling_users.end(); i2++) { 06049 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).user.name.compare(name)) { 06050 u=&(*i2); 06051 got=true; 06052 break; 06053 } 06054 } 06055 if(got) { 06056 int d_size=sizeof(cmd->command_data.cmd_repl_user_03_1.fullname); // !!! 06057 char* d=new char[d_size+1]; 06058 memset(d,0,d_size+1); 06059 memcpy(d,cmd->command_data.cmd_repl_user_03_1.fullname,d_size); // !!! 06060 string data=d; 06061 delete[] d; 06062 d=NULL; 06063 06064 u->user.fullname.push_back(data); 06065 } 06066 } 06067 break; 06068 case CMD_REPL_USER_04_1: 06069 { 06070 int n_size=sizeof(cmd->command_data.cmd_repl_user_04_1.name); // !!! 06071 char* n=new char[n_size+1]; 06072 memset(n,0,n_size+1); 06073 memcpy(n,cmd->command_data.cmd_repl_user_04_1.name,n_size); // !!! 06074 string name=n; 06075 delete[] n; 06076 n=NULL; 06077 06078 s_user_to_pull* u=NULL; 06079 bool got=false; 06080 vector<s_user_to_pull>::iterator i2; 06081 for(i2=(*i1)->pulling_users.begin(); i2!=(*i1)->pulling_users.end(); i2++) { 06082 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).user.name.compare(name)) { 06083 u=&(*i2); 06084 got=true; 06085 break; 06086 } 06087 } 06088 if(got) { 06089 int d_size=sizeof(cmd->command_data.cmd_repl_user_04_1.access_to_group); // !!! 06090 char* d=new char[d_size+1]; 06091 memset(d,0,d_size+1); 06092 memcpy(d,cmd->command_data.cmd_repl_user_04_1.access_to_group,d_size); // !!! 06093 string data=d; 06094 delete[] d; 06095 d=NULL; 06096 06097 u->user.access_to_group.push_back(data); 06098 } 06099 } 06100 break; 06101 case CMD_REPL_USER_05_1: 06102 { 06103 int n_size=sizeof(cmd->command_data.cmd_repl_user_05_1.name); // !!! 06104 char* n=new char[n_size+1]; 06105 memset(n,0,n_size+1); 06106 memcpy(n,cmd->command_data.cmd_repl_user_05_1.name,n_size); // !!! 06107 string name=n; 06108 delete[] n; 06109 n=NULL; 06110 06111 s_user_to_pull* u=NULL; 06112 bool got=false; 06113 vector<s_user_to_pull>::iterator i2; 06114 for(i2=(*i1)->pulling_users.begin(); i2!=(*i1)->pulling_users.end(); i2++) { 06115 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).user.name.compare(name)) { 06116 u=&(*i2); 06117 got=true; 06118 break; 06119 } 06120 } 06121 if(got) { 06122 int d_size=sizeof(cmd->command_data.cmd_repl_user_05_1.access_to_proc); // !!! 06123 char* d=new char[d_size+1]; 06124 memset(d,0,d_size+1); 06125 memcpy(d,cmd->command_data.cmd_repl_user_05_1.access_to_proc,d_size); // !!! 06126 string data=d; 06127 delete[] d; 06128 d=NULL; 06129 06130 u->user.access_to_proc.push_back(data); 06131 } 06132 } 06133 break; 06134 case CMD_REPL_USER_06_1: 06135 { 06136 int n_size=sizeof(cmd->command_data.cmd_repl_user_06_1.name); // !!! 06137 char* n=new char[n_size+1]; 06138 memset(n,0,n_size+1); 06139 memcpy(n,cmd->command_data.cmd_repl_user_06_1.name,n_size); // !!! 06140 string name=n; 06141 delete[] n; 06142 n=NULL; 06143 06144 s_user_to_pull* u=NULL; 06145 bool got=false; 06146 vector<s_user_to_pull>::iterator i2; 06147 for(i2=(*i1)->pulling_users.begin(); i2!=(*i1)->pulling_users.end(); i2++) { 06148 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).user.name.compare(name)) { 06149 u=&(*i2); 06150 got=true; 06151 break; 06152 } 06153 } 06154 if(got) { 06155 int d_size=sizeof(cmd->command_data.cmd_repl_user_06_1.access_grant_proc); // !!! 06156 char* d=new char[d_size+1]; 06157 memset(d,0,d_size+1); 06158 memcpy(d,cmd->command_data.cmd_repl_user_06_1.access_grant_proc,d_size); // !!! 06159 string data=d; 06160 delete[] d; 06161 d=NULL; 06162 06163 u->user.access_grant_procedure.push_back(data); 06164 } 06165 } 06166 break; 06167 case CMD_REPL_USER_07_1: 06168 { 06169 int n_size=sizeof(cmd->command_data.cmd_repl_user_07_1.name); // !!! 06170 char* n=new char[n_size+1]; 06171 memset(n,0,n_size+1); 06172 memcpy(n,cmd->command_data.cmd_repl_user_07_1.name,n_size); // !!! 06173 string name=n; 06174 delete[] n; 06175 n=NULL; 06176 06177 s_user_to_pull* u=NULL; 06178 bool got=false; 06179 vector<s_user_to_pull>::iterator i2; 06180 for(i2=(*i1)->pulling_users.begin(); i2!=(*i1)->pulling_users.end(); i2++) { 06181 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).user.name.compare(name)) { 06182 u=&(*i2); 06183 got=true; 06184 break; 06185 } 06186 } 06187 if(got) { 06188 int d_size=sizeof(cmd->command_data.cmd_repl_user_07_1.access_grant_group); // !!! 06189 char* d=new char[d_size+1]; 06190 memset(d,0,d_size+1); 06191 memcpy(d,cmd->command_data.cmd_repl_user_07_1.access_grant_group,d_size); // !!! 06192 string data=d; 06193 delete[] d; 06194 d=NULL; 06195 06196 u->user.access_grant_group.push_back(data); 06197 } 06198 } 06199 break; 06200 case CMD_REPL_USER_08_1: 06201 { 06202 int n_size=sizeof(cmd->command_data.cmd_repl_user_08_1.name); // !!! 06203 char* n=new char[n_size+1]; 06204 memset(n,0,n_size+1); 06205 memcpy(n,cmd->command_data.cmd_repl_user_08_1.name,n_size); // !!! 06206 string name=n; 06207 delete[] n; 06208 n=NULL; 06209 06210 s_user_to_pull* u=NULL; 06211 bool got=false; 06212 vector<s_user_to_pull>::iterator i2; 06213 for(i2=(*i1)->pulling_users.begin(); i2!=(*i1)->pulling_users.end(); i2++) { 06214 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).user.name.compare(name)) { 06215 u=&(*i2); 06216 got=true; 06217 break; 06218 } 06219 } 06220 if(got) { 06221 int d_size=sizeof(cmd->command_data.cmd_repl_user_08_1.access_to_channel); // !!! 06222 char* d=new char[d_size+1]; 06223 memset(d,0,d_size+1); 06224 memcpy(d,cmd->command_data.cmd_repl_user_08_1.access_to_channel,d_size); // !!! 06225 string data=d; 06226 delete[] d; 06227 d=NULL; 06228 06229 u->user.access_to_channel.push_back(data); 06230 } 06231 } 06232 break; 06233 case CMD_REPL_USER_09_1: 06234 { 06235 int n_size=sizeof(cmd->command_data.cmd_repl_user_09_1.name); // !!! 06236 char* n=new char[n_size+1]; 06237 memset(n,0,n_size+1); 06238 memcpy(n,cmd->command_data.cmd_repl_user_09_1.name,n_size); // !!! 06239 string name=n; 06240 delete[] n; 06241 n=NULL; 06242 06243 s_user_to_pull* u=NULL; 06244 bool got=false; 06245 vector<s_user_to_pull>::iterator i2; 06246 for(i2=(*i1)->pulling_users.begin(); i2!=(*i1)->pulling_users.end(); i2++) { 06247 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).user.name.compare(name)) { 06248 u=&(*i2); 06249 got=true; 06250 break; 06251 } 06252 } 06253 if(got) { 06254 int d_size=sizeof(cmd->command_data.cmd_repl_user_09_1.access_grant_channel); // !!! 06255 char* d=new char[d_size+1]; 06256 memset(d,0,d_size+1); 06257 memcpy(d,cmd->command_data.cmd_repl_user_09_1.access_grant_channel,d_size); // !!! 06258 string data=d; 06259 delete[] d; 06260 d=NULL; 06261 06262 u->user.access_grant_channel.push_back(data); 06263 } 06264 } 06265 break; 06266 case CMD_REPL_USER_10_1: 06267 { 06268 int n_size=sizeof(cmd->command_data.cmd_repl_user_10_1.name); // !!! 06269 char* n=new char[n_size+1]; 06270 memset(n,0,n_size+1); 06271 memcpy(n,cmd->command_data.cmd_repl_user_10_1.name,n_size); // !!! 06272 string name=n; 06273 delete[] n; 06274 n=NULL; 06275 06276 s_user_to_pull* u=NULL; 06277 bool got=false; 06278 vector<s_user_to_pull>::iterator i2; 06279 for(i2=(*i1)->pulling_users.begin(); i2!=(*i1)->pulling_users.end(); i2++) { 06280 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).user.name.compare(name)) { 06281 u=&(*i2); 06282 got=true; 06283 break; 06284 } 06285 } 06286 if(got) { 06287 int d_size=sizeof(cmd->command_data.cmd_repl_user_10_1.group); // !!! 06288 char* d=new char[d_size+1]; 06289 memset(d,0,d_size+1); 06290 memcpy(d,cmd->command_data.cmd_repl_user_10_1.group,d_size); // !!! 06291 string data=d; 06292 delete[] d; 06293 d=NULL; 06294 06295 s_group g; 06296 g.name=data; 06297 06298 u->user.groups.push_back(g); 06299 } 06300 } 06301 break; 06302 case CMD_REPL_USER_11_1: 06303 { 06304 int n_size=sizeof(cmd->command_data.cmd_repl_user_11_1.name); // !!! 06305 char* n=new char[n_size+1]; 06306 memset(n,0,n_size+1); 06307 memcpy(n,cmd->command_data.cmd_repl_user_11_1.name,n_size); // !!! 06308 string name=n; 06309 delete[] n; 06310 n=NULL; 06311 06312 s_user_to_pull* u=NULL; 06313 bool got=false; 06314 vector<s_user_to_pull>::iterator i2; 06315 for(i2=(*i1)->pulling_users.begin(); i2!=(*i1)->pulling_users.end(); i2++) { 06316 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).user.name.compare(name)) { 06317 u=&(*i2); 06318 got=true; 06319 break; 06320 } 06321 } 06322 if(got) { 06323 int d_size=sizeof(cmd->command_data.cmd_repl_user_11_1.dcc_host); // !!! 06324 char* d=new char[d_size+1]; 06325 memset(d,0,d_size+1); 06326 memcpy(d,cmd->command_data.cmd_repl_user_11_1.dcc_host,d_size); // !!! 06327 string data=d; 06328 delete[] d; 06329 d=NULL; 06330 06331 s_dcc_host h; 06332 h.host=data; 06333 h.group=cmd->command_data.cmd_repl_user_11_1.dcc_group; 06334 u->user.dcc_hosts.push_back(h); 06335 } 06336 } 06337 break; 06338 case CMD_REPL_USER_12_1: 06339 { 06340 int n_size=sizeof(cmd->command_data.cmd_repl_user_12_1.name); // !!! 06341 char* n=new char[n_size+1]; 06342 memset(n,0,n_size+1); 06343 memcpy(n,cmd->command_data.cmd_repl_user_12_1.name,n_size); // !!! 06344 string name=n; 06345 delete[] n; 06346 n=NULL; 06347 06348 s_user_to_pull* u=NULL; 06349 bool got=false; 06350 vector<s_user_to_pull>::iterator i2; 06351 for(i2=(*i1)->pulling_users.begin(); i2!=(*i1)->pulling_users.end(); i2++) { 06352 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).user.name.compare(name)) { 06353 u=&(*i2); 06354 got=true; 06355 break; 06356 } 06357 } 06358 if(got) { 06359 { 06360 s_user bot; 06361 logic_botnet_get_user((*i1)->botname,bot); 06362 06363 map<string,string> vars; 06364 bool got=false; 06365 vector<string>::iterator i_1; 06366 for(i_1=bot.access_to_channel.begin(); i_1!=bot.access_to_channel.end(); i_1++) 06367 if(!(*i_1).compare(cmd->command_data.cmd_repl_user_12_1.channel) || !(*i_1).compare("*")) { 06368 got=true; 06369 break; 06370 } 06371 if(!got) { 06372 string d="I have partially rejected replication of object "; 06373 d+="(user) "; 06374 d+=cmd->command_data.cmd_repl_user_12_1.name; 06375 d+=", rejected sub-object=channel: "; 06376 d+=cmd->command_data.cmd_repl_user_12_1.channel; 06377 d+=", reason: Remote bot doesn't have privilege access_to_channel"; 06378 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),cmd->packet_type,cmd->command,d.c_str()); 06379 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 06380 06381 { 06382 string obj_type="user"; 06383 string obj=cmd->command_data.cmd_repl_user_12_1.name; 06384 string reason="not have: access_to_channel"; 06385 06386 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_WARNING,d,"LOCAL"); 06387 } 06388 break; 06389 } 06390 } 06391 06392 s_user bot; 06393 logic_botnet_get_user((*i1)->botname,bot); 06394 06395 s_channel ch; 06396 ch.username=cmd->command_data.cmd_repl_user_12_1.name; 06397 ch.channel_name=cmd->command_data.cmd_repl_user_12_1.channel; 06398 ch.host_unknown=u->user.host_unknown; 06399 { 06400 s_user old_user; 06401 vector<s_channel> old_channels; 06402 if(!u->user.is_template) { 06403 if(!u->user.terminator) 06404 logic_partyline_get_user(u->user.name,old_user,old_channels); 06405 else 06406 logic_partyline_get_user(u->user.name,old_user,old_channels); 06407 } else { 06408 logic_partyline_get_user_template(u->user.name,old_user,old_channels); 06409 } 06410 s_channel old_channel; 06411 old_channel.clear(); 06412 vector<s_channel>::iterator i2; 06413 for(i2=old_channels.begin(); i2!=old_channels.end(); i2++) 06414 if(!(*i2).channel_name.compare(ch.channel_name)) { 06415 old_channel=*i2; 06416 break; 06417 } 06418 06419 ch.on_deop=old_channel.on_deop; 06420 if(botnet_has_grant(bot,old_channel.on_deop) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_deop)) 06421 ch.on_deop=cmd->command_data.cmd_repl_user_12_1.on_deop; 06422 06423 ch.on_ban=old_channel.on_ban; 06424 if(botnet_has_grant(bot,old_channel.on_ban) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_ban)) 06425 ch.on_ban=cmd->command_data.cmd_repl_user_12_1.on_ban; 06426 06427 ch.on_unban=old_channel.on_unban; 06428 if(botnet_has_grant(bot,old_channel.on_unban) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_unban)) 06429 ch.on_unban=cmd->command_data.cmd_repl_user_12_1.on_unban; 06430 06431 ch.on_kick=old_channel.on_kick; 06432 if(botnet_has_grant(bot,old_channel.on_kick) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_kick)) 06433 ch.on_kick=cmd->command_data.cmd_repl_user_12_1.on_kick; 06434 06435 ch.on_op=old_channel.on_op; 06436 if(botnet_has_grant(bot,old_channel.on_op) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_op)) 06437 ch.on_op=cmd->command_data.cmd_repl_user_12_1.on_op; 06438 06439 ch.on_voice=old_channel.on_voice; 06440 if(botnet_has_grant(bot,old_channel.on_voice) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_voice)) 06441 ch.on_voice=cmd->command_data.cmd_repl_user_12_1.on_voice; 06442 06443 ch.on_devoice=old_channel.on_devoice; 06444 if(botnet_has_grant(bot,old_channel.on_devoice) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_devoice)) 06445 ch.on_devoice=cmd->command_data.cmd_repl_user_12_1.on_devoice; 06446 06447 ch.on_creator=old_channel.on_creator; 06448 if(botnet_has_grant(bot,old_channel.on_creator) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_creator)) 06449 ch.on_creator=cmd->command_data.cmd_repl_user_12_1.on_creator; 06450 06451 ch.on_decreator=old_channel.on_decreator; 06452 if(botnet_has_grant(bot,old_channel.on_decreator) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_decreator)) 06453 ch.on_decreator=cmd->command_data.cmd_repl_user_12_1.on_decreator; 06454 06455 ch.on_join=old_channel.on_join; 06456 if(botnet_has_grant(bot,old_channel.on_join) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_join)) 06457 ch.on_join=cmd->command_data.cmd_repl_user_12_1.on_join; 06458 06459 ch.on_banned=old_channel.on_banned; 06460 if(botnet_has_grant(bot,old_channel.on_banned) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_banned)) 06461 ch.on_banned=cmd->command_data.cmd_repl_user_12_1.on_banned; 06462 06463 ch.on_flood=old_channel.on_flood; 06464 if(botnet_has_grant(bot,old_channel.on_flood) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_flood)) 06465 ch.on_flood=cmd->command_data.cmd_repl_user_12_1.on_flood; 06466 06467 ch.on_privmsg=old_channel.on_privmsg; 06468 if(botnet_has_grant(bot,old_channel.on_privmsg) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_privmsg)) 06469 ch.on_privmsg=cmd->command_data.cmd_repl_user_12_1.on_privmsg; 06470 06471 ch.on_notice=old_channel.on_notice; 06472 if(botnet_has_grant(bot,old_channel.on_notice) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_notice)) 06473 ch.on_notice=cmd->command_data.cmd_repl_user_12_1.on_notice; 06474 06475 ch.on_except=old_channel.on_except; 06476 if(botnet_has_grant(bot,old_channel.on_except) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_except)) 06477 ch.on_except=cmd->command_data.cmd_repl_user_12_1.on_except; 06478 06479 ch.on_unexcept=old_channel.on_unexcept; 06480 if(botnet_has_grant(bot,old_channel.on_unexcept) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_unexcept)) 06481 ch.on_unexcept=cmd->command_data.cmd_repl_user_12_1.on_unexcept; 06482 06483 ch.on_invite=old_channel.on_invite; 06484 if(botnet_has_grant(bot,old_channel.on_invite) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_invite)) 06485 ch.on_invite=cmd->command_data.cmd_repl_user_12_1.on_invite; 06486 06487 ch.on_uninvite=old_channel.on_uninvite; 06488 if(botnet_has_grant(bot,old_channel.on_uninvite) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_uninvite)) 06489 ch.on_uninvite=cmd->command_data.cmd_repl_user_12_1.on_uninvite; 06490 06491 ch.on_not_invited=old_channel.on_not_invited; 06492 if(botnet_has_grant(bot,old_channel.on_not_invited) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_not_invited)) 06493 ch.on_not_invited=cmd->command_data.cmd_repl_user_12_1.on_not_invited; 06494 06495 ch.on_not_in_reop=old_channel.on_not_in_reop; 06496 if(botnet_has_grant(bot,old_channel.on_not_in_reop) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_not_in_reop)) 06497 ch.on_not_in_reop=cmd->command_data.cmd_repl_user_12_1.on_not_in_reop; 06498 06499 ch.on_reop=old_channel.on_reop; 06500 if(botnet_has_grant(bot,old_channel.on_reop) && botnet_has_grant(bot,cmd->command_data.cmd_repl_user_12_1.on_reop)) 06501 ch.on_reop=cmd->command_data.cmd_repl_user_12_1.on_reop; 06502 06503 ch.can_send_unknown_users=old_channel.can_send_unknown_users; 06504 if(bot.access_grant_can_send_unknown_users) 06505 ch.can_send_unknown_users=cmd->command_data.cmd_repl_user_12_1.can_send_unknown_users; 06506 } 06507 06508 ch.msg_flood.lines=cmd->command_data.cmd_repl_user_12_1.msg_flood_l; 06509 ch.msg_flood.seconds=cmd->command_data.cmd_repl_user_12_1.msg_flood_s; 06510 06511 ch.notice_flood.lines=cmd->command_data.cmd_repl_user_12_1.notice_flood_l; 06512 ch.notice_flood.seconds=cmd->command_data.cmd_repl_user_12_1.notice_flood_s; 06513 06514 ch.repeat_flood.lines=cmd->command_data.cmd_repl_user_12_1.repeat_flood_l; 06515 ch.repeat_flood.seconds=cmd->command_data.cmd_repl_user_12_1.repeat_flood_s; 06516 06517 ch.nick_flood.lines=cmd->command_data.cmd_repl_user_12_1.nick_flood_l; 06518 ch.nick_flood.seconds=cmd->command_data.cmd_repl_user_12_1.nick_flood_s; 06519 06520 ch.join_flood.lines=cmd->command_data.cmd_repl_user_12_1.join_flood_l; 06521 ch.join_flood.seconds=cmd->command_data.cmd_repl_user_12_1.join_flood_s; 06522 06523 ch.mode_flood.lines=cmd->command_data.cmd_repl_user_12_1.mode_flood_l; 06524 ch.mode_flood.seconds=cmd->command_data.cmd_repl_user_12_1.mode_flood_s; 06525 06526 ch.ctcp_flood.lines=cmd->command_data.cmd_repl_user_12_1.ctcp_flood_l; 06527 ch.ctcp_flood.seconds=cmd->command_data.cmd_repl_user_12_1.ctcp_flood_s; 06528 06529 ch.dynamic_plus_modes=cmd->command_data.cmd_repl_user_12_1.dynamic_plus_modes; 06530 ch.dynamic_minus_modes=cmd->command_data.cmd_repl_user_12_1.dynamic_minus_modes; 06531 06532 { 06533 s_user u2; 06534 if(!logic_botnet_get_user(u->user.name,u2)) { 06535 u2.access_to_backup=false; 06536 u2.access_grant_backup=false; 06537 u2.access_to_rehash=false; 06538 u2.access_grant_rehash=false; 06539 u2.access_to_plususer=false; 06540 u2.access_grant_plususer=false; 06541 u2.access_to_plusproc=false; 06542 u2.access_grant_plusproc=false; 06543 } 06544 if(!bot.access_grant_backup) { 06545 u->user.access_to_backup=u2.access_to_backup; 06546 u->user.access_grant_backup=u2.access_grant_backup; 06547 } 06548 if(!bot.access_grant_rehash) { 06549 u->user.access_to_rehash=u2.access_to_rehash; 06550 u->user.access_grant_rehash=u2.access_grant_rehash; 06551 } 06552 if(!bot.access_grant_plususer) { 06553 u->user.access_to_plususer=u2.access_to_plususer; 06554 u->user.access_grant_plususer=u2.access_grant_plususer; 06555 } 06556 if(!bot.access_grant_plusproc) { 06557 u->user.access_to_plusproc=u2.access_to_plusproc; 06558 u->user.access_grant_plusproc=u2.access_grant_plusproc; 06559 } 06560 } 06561 06562 bool got2=false; 06563 { 06564 s_user us; 06565 if(logic_botnet_get_user(u->user.name,us)) 06566 got2=true; 06567 } 06568 06569 if(got2 || (!got2 && bot.access_to_plususer)) { 06570 erase_again: 06571 vector<s_channel>::iterator i2; 06572 for(i2=r_channels.begin(); i2!=r_channels.end(); i2++) { 06573 if(!(*i2).username.compare(ch.username) && !(*i2).channel_name.compare(ch.channel_name)) { 06574 r_channels.erase(i2); 06575 goto erase_again; 06576 } 06577 } 06578 for(i2=r_channel_templates.begin(); i2!=r_channel_templates.end(); i2++) { 06579 if(!(*i2).username.compare(ch.username) && !(*i2).channel_name.compare(ch.channel_name)) { 06580 r_channels.erase(i2); 06581 goto erase_again; 06582 } 06583 } 06584 for(i2=r_channel_terminators.begin(); i2!=r_channel_terminators.end(); i2++) { 06585 if(!(*i2).username.compare(ch.username) && !(*i2).channel_name.compare(ch.channel_name)) { 06586 r_channels.erase(i2); 06587 goto erase_again; 06588 } 06589 } 06590 06591 if(!u->user.is_template) { 06592 if(!u->user.terminator) 06593 r_channels.push_back(ch); 06594 else 06595 r_channel_terminators.push_back(ch); 06596 } else { 06597 ch.is_template=true; 06598 r_channel_templates.push_back(ch); 06599 } 06600 } 06601 } 06602 } 06603 break; 06604 case CMD_REPL_USER_13_1: 06605 { 06606 int n_size=sizeof(cmd->command_data.cmd_repl_user_13_1.name); // !!! 06607 char* n=new char[n_size+1]; 06608 memset(n,0,n_size+1); 06609 memcpy(n,cmd->command_data.cmd_repl_user_13_1.name,n_size); // !!! 06610 string name=n; 06611 delete[] n; 06612 n=NULL; 06613 06614 s_user_to_pull* u=NULL; 06615 bool got=false; 06616 vector<s_user_to_pull>::iterator i2; 06617 for(i2=(*i1)->pulling_users.begin(); i2!=(*i1)->pulling_users.end(); i2++) { 06618 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).user.name.compare(name)) { 06619 u=&(*i2); 06620 got=true; 06621 break; 06622 } 06623 } 06624 if(got) { 06625 bool got_ch=false; 06626 vector<s_channel>::iterator i2; 06627 for(i2=r_channels.begin(); i2!=r_channels.end(); i2++) { 06628 if(!(*i2).username.compare(u->user.name) && !(*i2).channel_name.compare(cmd->command_data.cmd_repl_user_13_1.channel)) { 06629 got_ch=true; 06630 break; 06631 } 06632 } 06633 06634 if(got_ch) { 06635 int g_size=sizeof(cmd->command_data.cmd_repl_user_13_1.group); // !!! 06636 char* g=new char[g_size+1]; 06637 memset(g,0,g_size+1); 06638 memcpy(g,cmd->command_data.cmd_repl_user_13_1.group,g_size); // !!! 06639 string group=g; 06640 delete[] g; 06641 g=NULL; 06642 06643 int pm_size=sizeof(cmd->command_data.cmd_repl_user_13_1.plus_modes); // !!! 06644 char* pm=new char[pm_size+1]; 06645 memset(pm,0,pm_size+1); 06646 memcpy(pm,cmd->command_data.cmd_repl_user_13_1.plus_modes,pm_size); // !!! 06647 string plus_modes=pm; 06648 delete[] pm; 06649 pm=NULL; 06650 06651 int mm_size=sizeof(cmd->command_data.cmd_repl_user_13_1.minus_modes); // !!! 06652 char* mm=new char[mm_size+1]; 06653 memset(mm,0,mm_size+1); 06654 memcpy(mm,cmd->command_data.cmd_repl_user_13_1.minus_modes,mm_size); // !!! 06655 string minus_modes=mm; 06656 delete[] mm; 06657 mm=NULL; 06658 06659 s_dynamic_rule r; 06660 r.group=group; 06661 r.plus_modes=plus_modes; 06662 r.minus_modes=minus_modes; 06663 (*i2).allow_dynamic.push_back(r); 06664 } 06665 } 06666 } 06667 break; 06668 case CMD_REPL_USER_14_1: 06669 { 06670 int n_size=sizeof(cmd->command_data.cmd_repl_user_14_1.name); // !!! 06671 char* n=new char[n_size+1]; 06672 memset(n,0,n_size+1); 06673 memcpy(n,cmd->command_data.cmd_repl_user_14_1.name,n_size); // !!! 06674 string name=n; 06675 delete[] n; 06676 n=NULL; 06677 06678 s_user_to_pull* u=NULL; 06679 bool got=false; 06680 vector<s_user_to_pull>::iterator i2; 06681 for(i2=(*i1)->pulling_users.begin(); i2!=(*i1)->pulling_users.end(); i2++) { 06682 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).user.name.compare(name)) { 06683 u=&(*i2); 06684 got=true; 06685 break; 06686 } 06687 } 06688 if(got) { 06689 pair<string,string> p; 06690 p.first=cmd->command_data.cmd_repl_user_14_1.meta_key; 06691 p.second=cmd->command_data.cmd_repl_user_14_1.meta_val; 06692 (*i2).user.meta.insert(p); 06693 } 06694 } 06695 break; 06696 case CMD_REPL_USER_15_1: 06697 { 06698 int n_size=sizeof(cmd->command_data.cmd_repl_user_15_1.name); // !!! 06699 char* n=new char[n_size+1]; 06700 memset(n,0,n_size+1); 06701 memcpy(n,cmd->command_data.cmd_repl_user_15_1.name,n_size); // !!! 06702 string name=n; 06703 delete[] n; 06704 n=NULL; 06705 06706 s_user_to_pull* u=NULL; 06707 bool got=false; 06708 vector<s_user_to_pull>::iterator i2; 06709 for(i2=(*i1)->pulling_users.begin(); i2!=(*i1)->pulling_users.end(); i2++) { 06710 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).user.name.compare(name)) { 06711 u=&(*i2); 06712 got=true; 06713 break; 06714 } 06715 } 06716 if(got) { 06717 int d_size=sizeof(cmd->command_data.cmd_repl_user_15_1.access_usage_proc); // !!! 06718 char* d=new char[d_size+1]; 06719 memset(d,0,d_size+1); 06720 memcpy(d,cmd->command_data.cmd_repl_user_15_1.access_usage_proc,d_size); // !!! 06721 string data=d; 06722 delete[] d; 06723 d=NULL; 06724 06725 u->user.access_usage_procedure.push_back(data); 06726 } 06727 } 06728 break; 06729 case CMD_REPL_USER_16_5: 06730 { 06731 int n_size=sizeof(cmd->command_data.cmd_repl_user_16_5.name); // !!! 06732 char* n=new char[n_size+1]; 06733 memset(n,0,n_size+1); 06734 memcpy(n,cmd->command_data.cmd_repl_user_16_5.name,n_size); // !!! 06735 string name=n; 06736 delete[] n; 06737 n=NULL; 06738 06739 s_user_to_pull* u=NULL; 06740 bool got=false; 06741 vector<s_user_to_pull>::iterator i2; 06742 for(i2=(*i1)->pulling_users.begin(); i2!=(*i1)->pulling_users.end(); i2++) { 06743 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).user.name.compare(name)) { 06744 u=&(*i2); 06745 got=true; 06746 break; 06747 } 06748 } 06749 if(got) { 06750 u->user.access_to_upgrade=cmd->command_data.cmd_repl_user_16_5.access_to_upgrade; 06751 u->user.access_grant_upgrade=cmd->command_data.cmd_repl_user_16_5.access_grant_upgrade; 06752 } 06753 } 06754 break; 06755 case CMD_REPL_USER_17_9: 06756 { 06757 int n_size=sizeof(cmd->command_data.cmd_repl_user_17_9.name); // !!! 06758 char* n=new char[n_size+1]; 06759 memset(n,0,n_size+1); 06760 memcpy(n,cmd->command_data.cmd_repl_user_17_9.name,n_size); // !!! 06761 string name=n; 06762 delete[] n; 06763 n=NULL; 06764 06765 s_user_to_pull* u=NULL; 06766 bool got=false; 06767 vector<s_user_to_pull>::iterator i2; 06768 for(i2=(*i1)->pulling_users.begin(); i2!=(*i1)->pulling_users.end(); i2++) { 06769 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).user.name.compare(name)) { 06770 u=&(*i2); 06771 got=true; 06772 break; 06773 } 06774 } 06775 if(got) { 06776 u->user.access_to_apply=cmd->command_data.cmd_repl_user_17_9.access_to_apply; 06777 u->user.access_grant_apply=cmd->command_data.cmd_repl_user_17_9.access_grant_apply; 06778 } 06779 } 06780 break; 06781 case CMD_REPL_USER_99_1: 06782 { 06783 int n_size=sizeof(cmd->command_data.cmd_repl_user_99_1.name); // !!! 06784 char* n=new char[n_size+1]; 06785 memset(n,0,n_size+1); 06786 memcpy(n,cmd->command_data.cmd_repl_user_99_1.name,n_size); // !!! 06787 string name=n; 06788 delete[] n; 06789 n=NULL; 06790 { 06791 s_bot_control* c=new s_bot_control; 06792 c->hard_clear(); 06793 c->packet_type=PACKET_TYPE_CONTROL; 06794 c->supported_proto_version=SUPPORTED_PROTO_VERSION; 06795 c->control=CTRL_PING; 06796 botnet_send_control(*i1,c); 06797 (*i1)->next_ping=time(NULL)+ping_time; 06798 (*i1)->start_awaiting_pong=time(NULL); 06799 delete c; 06800 06801 string obj=(string)"USER "+name; 06802 vector<s_bot*>::iterator i2; 06803 again_1: 06804 for(i2=bots.begin(); i2!=bots.end(); i2++) { 06805 vector<string>::iterator i3; 06806 for(i3=(*i2)->rejected_objects.begin(); i3!=(*i2)->rejected_objects.end(); i3++) { 06807 if(!(*i3).compare(obj)) { 06808 (*i2)->rejected_objects.erase(i3); 06809 goto again_1; 06810 } 06811 } 06812 } 06813 } 06814 06815 s_user_to_pull* u=NULL; 06816 bool got=false; 06817 vector<s_user_to_pull>::iterator i2; 06818 for(i2=(*i1)->pulling_users.begin(); i2!=(*i1)->pulling_users.end(); i2++) { 06819 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).user.name.compare(name)) { 06820 u=&(*i2); 06821 got=true; 06822 break; 06823 } 06824 } 06825 if(got) { 06826 s_user bot; 06827 logic_botnet_get_user((*i1)->botname,bot); 06828 06829 { 06830 s_user u2; 06831 if(!logic_botnet_get_user(u->user.name,u2)) { 06832 u2.access_to_backup=false; 06833 u2.access_grant_backup=false; 06834 u2.access_to_can_send_all_users=false; 06835 u2.access_grant_can_send_all_users=false; 06836 u2.access_to_can_send_unknown_users=false; 06837 u2.access_grant_can_send_unknown_users=false; 06838 u2.access_to_die=false; 06839 u2.access_grant_die=false; 06840 u2.access_to_filesystem=false; 06841 u2.access_grant_filesystem=false; 06842 u2.access_to_partyline=false; 06843 u2.access_grant_partyline=false; 06844 u2.access_to_plusproc=false; 06845 u2.access_grant_plusproc=false; 06846 u2.access_to_plususer=false; 06847 u2.access_grant_plususer=false; 06848 u2.access_to_private=false; 06849 u2.access_grant_private=false; 06850 u2.access_to_rehash=false; 06851 u2.access_grant_rehash=false; 06852 u2.access_to_replication=false; 06853 u2.access_grant_replication=false; 06854 u2.access_to_restart=false; 06855 u2.access_grant_restart=false; 06856 u2.access_to_upgrade=false; 06857 u2.access_grant_upgrade=false; 06858 u2.access_to_apply=false; 06859 u2.access_grant_apply=false; 06860 } 06861 if(!bot.access_grant_backup) { 06862 u->user.access_to_backup=u2.access_to_backup; 06863 u->user.access_grant_backup=u2.access_grant_backup; 06864 } 06865 if(!bot.access_grant_can_send_all_users) { 06866 u->user.access_to_can_send_all_users=u2.access_to_can_send_all_users; 06867 u->user.access_grant_can_send_all_users=u2.access_grant_can_send_all_users; 06868 } 06869 if(!bot.access_grant_can_send_unknown_users) { 06870 u->user.access_to_can_send_unknown_users=u2.access_to_can_send_unknown_users; 06871 u->user.access_grant_can_send_unknown_users=u2.access_grant_can_send_unknown_users; 06872 } 06873 if(!bot.access_grant_die) { 06874 u->user.access_to_die=u2.access_to_die; 06875 u->user.access_grant_die=u2.access_grant_die; 06876 } 06877 if(!bot.access_grant_filesystem) { 06878 u->user.access_to_filesystem=u2.access_to_filesystem; 06879 u->user.access_grant_filesystem=u2.access_grant_filesystem; 06880 } 06881 if(!bot.access_grant_partyline) { 06882 u->user.access_to_partyline=u2.access_to_partyline; 06883 u->user.access_grant_partyline=u2.access_grant_partyline; 06884 } 06885 if(!bot.access_grant_plusproc) { 06886 u->user.access_to_plusproc=u2.access_to_plusproc; 06887 u->user.access_grant_plusproc=u2.access_grant_plusproc; 06888 } 06889 if(!bot.access_grant_plususer) { 06890 u->user.access_to_plususer=u2.access_to_plususer; 06891 u->user.access_grant_plususer=u2.access_grant_plususer; 06892 } 06893 if(!bot.access_grant_private) { 06894 u->user.access_to_private=u2.access_to_private; 06895 u->user.access_grant_private=u2.access_grant_private; 06896 } 06897 if(!bot.access_grant_rehash) { 06898 u->user.access_to_rehash=u2.access_to_rehash; 06899 u->user.access_grant_rehash=u2.access_grant_rehash; 06900 } 06901 if(!bot.access_grant_replication) { 06902 u->user.access_to_replication=u2.access_to_replication; 06903 u->user.access_grant_replication=u2.access_grant_replication; 06904 } 06905 if(!bot.access_grant_restart) { 06906 u->user.access_to_restart=u2.access_to_restart; 06907 u->user.access_grant_restart=u2.access_grant_restart; 06908 } 06909 if(!bot.access_grant_upgrade) { 06910 u->user.access_to_upgrade=u2.access_to_upgrade; 06911 u->user.access_grant_upgrade=u2.access_grant_upgrade; 06912 } 06913 if(!bot.access_grant_apply) { 06914 u->user.access_to_apply=u2.access_to_apply; 06915 u->user.access_grant_apply=u2.access_grant_apply; 06916 } 06917 } 06918 vector<string> new_right; 06919 vector<string>::iterator i_1; 06920 06921 new_right.clear(); 06922 for(i_1=u->user.access_to_group.begin(); i_1!=u->user.access_to_group.end(); i_1++) { 06923 vector<string>::iterator i_2; 06924 for(i_2=bot.access_grant_group.begin(); i_2!=bot.access_grant_group.end(); i_2++) 06925 if(!(*i_2).compare("*") || !(*i_2).compare(*i_1)) { 06926 new_right.push_back(*i_1); 06927 break; 06928 } 06929 } 06930 u->user.access_to_group=new_right; 06931 06932 new_right.clear(); 06933 for(i_1=u->user.access_grant_group.begin(); i_1!=u->user.access_grant_group.end(); i_1++) { 06934 vector<string>::iterator i_2; 06935 for(i_2=bot.access_grant_group.begin(); i_2!=bot.access_grant_group.end(); i_2++) 06936 if(!(*i_2).compare("*") || !(*i_2).compare(*i_1)) { 06937 new_right.push_back(*i_1); 06938 break; 06939 } 06940 } 06941 u->user.access_grant_group=new_right; 06942 06943 new_right.clear(); 06944 for(i_1=u->user.access_to_proc.begin(); i_1!=u->user.access_to_proc.end(); i_1++) { 06945 vector<string>::iterator i_2; 06946 for(i_2=bot.access_grant_procedure.begin(); i_2!=bot.access_grant_procedure.end(); i_2++) 06947 if(!(*i_2).compare("*") || !(*i_2).compare(*i_1)) { 06948 new_right.push_back(*i_1); 06949 break; 06950 } 06951 } 06952 u->user.access_to_proc=new_right; 06953 06954 new_right.clear(); 06955 for(i_1=u->user.access_grant_procedure.begin(); i_1!=u->user.access_grant_procedure.end(); i_1++) { 06956 vector<string>::iterator i_2; 06957 for(i_2=bot.access_grant_procedure.begin(); i_2!=bot.access_grant_procedure.end(); i_2++) 06958 if(!(*i_2).compare("*") || !(*i_2).compare(*i_1)) { 06959 new_right.push_back(*i_1); 06960 break; 06961 } 06962 } 06963 u->user.access_grant_procedure=new_right; 06964 06965 new_right.clear(); 06966 for(i_1=u->user.access_to_channel.begin(); i_1!=u->user.access_to_channel.end(); i_1++) { 06967 vector<string>::iterator i_2; 06968 for(i_2=bot.access_grant_channel.begin(); i_2!=bot.access_grant_channel.end(); i_2++) 06969 if(!(*i_2).compare("*") || !(*i_2).compare(*i_1)) { 06970 new_right.push_back(*i_1); 06971 break; 06972 } 06973 } 06974 u->user.access_to_channel=new_right; 06975 06976 new_right.clear(); 06977 for(i_1=u->user.access_grant_channel.begin(); i_1!=u->user.access_grant_channel.end(); i_1++) { 06978 vector<string>::iterator i_2; 06979 for(i_2=bot.access_grant_channel.begin(); i_2!=bot.access_grant_channel.end(); i_2++) 06980 if(!(*i_2).compare("*") || !(*i_2).compare(*i_1)) { 06981 new_right.push_back(*i_1); 06982 break; 06983 } 06984 } 06985 u->user.access_grant_channel=new_right; 06986 06987 bool got2=false; 06988 { 06989 s_user us; 06990 if(logic_botnet_get_user(u->user.name,us)) 06991 got2=true; 06992 } 06993 06994 if(got2 || (!got2 && bot.access_to_plususer)) { 06995 if(u->user.last_changed==0) 06996 u->user.last_changed++; 06997 06998 s_replication r; 06999 r.partner=bot.name; 07000 r.type=REPL_PULL; 07001 u->user.replication.push_back(r); 07002 07003 logic_botnet_remove_user(u->user.name); 07004 if(!u->user.is_template) { 07005 if(!u->user.terminator) 07006 r_users.push_back(u->user); 07007 else 07008 r_terminators.push_back(u->user); 07009 } else 07010 r_user_templates.push_back(u->user); 07011 07012 if(bot.access_to_backup) { 07013 botnet_backup((*i1)->botname); 07014 07015 if(bot.access_to_rehash) 07016 botnet_rehash(*i1,(*i1)->botname); 07017 } 07018 07019 string d="pulling of object "; 07020 d+="(user) "; 07021 d+=u->user.name; 07022 d+=" successful"; 07023 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),cmd->packet_type,cmd->command,d.c_str()); 07024 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 07025 07026 stats_botnet_user_pulled(); 07027 07028 { 07029 string obj_type="user"; 07030 string reason="OK"; 07031 string obj=u->user.name; 07032 07033 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,d,"PULL"); 07034 } 07035 } 07036 07037 (*i1)->pulling_users.erase(i2); 07038 } 07039 } 07040 break; 07041 case CMD_REPL_PRV_01_1: 07042 { 07043 if(!(*i1)->prv_pulling) 07044 break; 07045 07046 (*i1)->prv_to_pull.clear(); 07047 (*i1)->prv_to_pull.last_changed=cmd->command_data.cmd_repl_prv_01_1.last_changed; 07048 } 07049 break; 07050 case CMD_REPL_PRV_02_1: 07051 { 07052 if(!(*i1)->prv_pulling) 07053 break; 07054 07055 s_group g; 07056 g.name=cmd->command_data.cmd_repl_prv_02_1.group; 07057 (*i1)->prv_to_pull.groups.push_back(g); 07058 } 07059 break; 07060 case CMD_REPL_PRV_03_1: 07061 { 07062 if(!(*i1)->prv_pulling) 07063 break; 07064 07065 (*i1)->prv_to_pull.on_privmsg=cmd->command_data.cmd_repl_prv_03_1.on_privmsg; 07066 (*i1)->prv_to_pull.on_notice=cmd->command_data.cmd_repl_prv_03_1.on_notice; 07067 (*i1)->prv_to_pull.on_ctcp=cmd->command_data.cmd_repl_prv_03_1.on_ctcp; 07068 07069 // for older BOTNET protocols (e.g. older bots) keep this event current 07070 if((*i1)->supported_proto_version<7) { 07071 (*i1)->prv_to_pull.on_filesys_got_new=r_private.on_filesys_got_new; 07072 (*i1)->prv_to_pull.on_fnc=r_private.on_fnc; 07073 } 07074 if((*i1)->supported_proto_version<8) { 07075 (*i1)->prv_to_pull.on_broadcast=r_private.on_broadcast; 07076 (*i1)->prv_to_pull.on_server_msg=r_private.on_server_msg; 07077 } 07078 } 07079 break; 07080 case CMD_REPL_PRV_04_7: 07081 { 07082 if(!(*i1)->prv_pulling) 07083 break; 07084 07085 (*i1)->prv_to_pull.on_filesys_got_new=cmd->command_data.cmd_repl_prv_04_7.on_filesys_got_new; 07086 (*i1)->prv_to_pull.on_fnc=cmd->command_data.cmd_repl_prv_04_7.on_fnc; 07087 } 07088 break; 07089 case CMD_REPL_PRV_05_8: 07090 { 07091 if(!(*i1)->prv_pulling) 07092 break; 07093 07094 (*i1)->prv_to_pull.on_broadcast=cmd->command_data.cmd_repl_prv_05_8.on_broadcast; 07095 (*i1)->prv_to_pull.on_server_msg=cmd->command_data.cmd_repl_prv_05_8.on_server_msg; 07096 } 07097 break; 07098 case CMD_REPL_PRV_06_11: 07099 { 07100 if(!(*i1)->prv_pulling) 07101 break; 07102 07103 (*i1)->prv_to_pull.on_internal_event=cmd->command_data.cmd_repl_prv_06_11.on_internal_event; 07104 } 07105 break; 07106 case CMD_REPL_PRV_99_1: 07107 { 07108 { 07109 s_bot_control* c=new s_bot_control; 07110 c->hard_clear(); 07111 c->packet_type=PACKET_TYPE_CONTROL; 07112 c->supported_proto_version=SUPPORTED_PROTO_VERSION; 07113 c->control=CTRL_PING; 07114 botnet_send_control(*i1,c); 07115 (*i1)->next_ping=time(NULL)+ping_time; 07116 (*i1)->start_awaiting_pong=time(NULL); 07117 delete c; 07118 07119 string obj=(string)"PRIV"; 07120 vector<s_bot*>::iterator i2; 07121 again_4: 07122 for(i2=bots.begin(); i2!=bots.end(); i2++) { 07123 vector<string>::iterator i3; 07124 for(i3=(*i2)->rejected_objects.begin(); i3!=(*i2)->rejected_objects.end(); i3++) { 07125 if(!(*i3).compare(obj)) { 07126 (*i2)->rejected_objects.erase(i3); 07127 goto again_4; 07128 } 07129 } 07130 } 07131 } 07132 if(!(*i1)->prv_pulling) 07133 break; 07134 07135 s_user bot; 07136 logic_botnet_get_user((*i1)->botname,bot); 07137 07138 if(bot.access_to_private) { 07139 s_replication r; 07140 r.partner=bot.name; 07141 r.type=REPL_PULL; 07142 (*i1)->prv_to_pull.replication.push_back(r); 07143 r_private=(*i1)->prv_to_pull; 07144 07145 if(bot.access_to_backup) 07146 botnet_backup((*i1)->botname); 07147 07148 if(bot.access_to_rehash) 07149 botnet_rehash(*i1,(*i1)->botname); 07150 07151 string d="pulling of object "; 07152 d+="(private)"; // no trailing SPACE!!! 07153 d+=" successful"; 07154 07155 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),cmd->packet_type,cmd->command,d.c_str()); 07156 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 07157 07158 stats_botnet_private_pulled(); 07159 07160 { 07161 string obj_type="private"; 07162 string reason="OK"; 07163 string obj="private"; 07164 07165 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,d,"PULL"); 07166 } 07167 } 07168 } 07169 break; 07170 case CMD_PROC_1: 07171 { 07172 int n_size=sizeof(cmd->command_data.cmd_proc_1.name); 07173 char* n=new char[n_size+1]; 07174 memset(n,0,n_size+1); 07175 memcpy(n,cmd->command_data.cmd_proc_1.name,n_size); 07176 string name=n; 07177 delete[] n; 07178 n=NULL; 07179 07180 { 07181 if(cmd->command_data.cmd_proc_1.init) { 07182 again_erase2: 07183 vector<s_proc_to_pull>::iterator i2; 07184 for(i2=(*i1)->pulling_procs.begin(); i2!=(*i1)->pulling_procs.end(); i2++) { 07185 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).proc_name.compare(name)) { 07186 (*i1)->pulling_procs.erase(i2); 07187 goto again_erase2; 07188 } 07189 } 07190 } 07191 07192 bool got=false; 07193 vector<s_procedure>::iterator i3; 07194 for(i3=r_procedures.begin(); i3!=r_procedures.end(); i3++) { 07195 if(!(*i3).name.compare(name)) { 07196 got=true; 07197 vector<s_replication>::iterator i4; 07198 for(i4=(*i3).replication.begin(); i4!=(*i3).replication.end(); i4++) { 07199 if(!(*i4).partner.compare((*i1)->botname) && ((*i4).type==REPL_PULL || (*i4).type==REPL_PUSHPULL)) { 07200 s_proc_to_pull p; 07201 p.botname=(*i1)->botname; 07202 p.proc_name=name; 07203 if(cmd->command_data.cmd_proc_1.init) { 07204 p.lines.clear(); 07205 p.replication=(*i3).replication; 07206 vector<s_group>::iterator i5; 07207 for(i5=(*i3).groups.begin(); i5!=(*i3).groups.end(); i5++) 07208 p.orig_groups.push_back((*i5).name); 07209 } 07210 (*i1)->pulling_procs.push_back(p); 07211 got=true; 07212 break; 07213 } 07214 } 07215 if(got) 07216 break; 07217 } 07218 } 07219 if(!got) { 07220 s_proc_to_pull p; 07221 p.botname=(*i1)->botname; 07222 p.proc_name=name; 07223 07224 // we got a new procedure, so set them replication flags 07225 s_replication r; 07226 r.partner=(*i1)->botname; 07227 r.type=REPL_PULL; 07228 p.replication.clear(); 07229 p.replication.push_back(r); 07230 p.orig_groups.clear(); 07231 07232 (*i1)->pulling_procs.push_back(p); 07233 } 07234 } 07235 07236 s_proc_to_pull* p=NULL; 07237 bool got=false; 07238 vector<s_proc_to_pull>::iterator i2; 07239 for(i2=(*i1)->pulling_procs.begin(); i2!=(*i1)->pulling_procs.end(); i2++) { 07240 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).proc_name.compare(name)) { 07241 p=&(*i2); 07242 got=true; 07243 break; 07244 } 07245 } 07246 if(got) { 07247 p->last_changed=cmd->command_data.cmd_proc_1.last_changed; 07248 if(p->last_changed==0) 07249 p->last_changed++; 07250 string ln=cmd->command_data.cmd_proc_1.line; 07251 string token; 07252 for(unsigned int i1=0; i1<ln.length()+1; i1++) { 07253 if(i1<ln.length() && ln[i1]!=0x20) 07254 token+=ln[i1]; 07255 else { 07256 break; 07257 } 07258 } 07259 07260 if(!token.compare("replication") || !token.compare("member_of_group")) { 07261 // silently ignore 07262 } else { 07263 p->lines.push_back(ln); 07264 } 07265 } 07266 } 07267 break; 07268 case CMD_PROC_END_1: 07269 { 07270 int n_size=sizeof(cmd->command_data.cmd_proc_end_1.name); // !!! 07271 char* n=new char[n_size+1]; 07272 memset(n,0,n_size+1); 07273 memcpy(n,cmd->command_data.cmd_proc_end_1.name,n_size); // !!! 07274 string name=n; 07275 delete[] n; 07276 n=NULL; 07277 { 07278 s_bot_control* c=new s_bot_control; 07279 c->hard_clear(); 07280 c->packet_type=PACKET_TYPE_CONTROL; 07281 c->supported_proto_version=SUPPORTED_PROTO_VERSION; 07282 c->control=CTRL_PING; 07283 botnet_send_control(*i1,c); 07284 (*i1)->next_ping=time(NULL)+ping_time; 07285 (*i1)->start_awaiting_pong=time(NULL); 07286 delete c; 07287 07288 string obj=(string)"PROC "+name; 07289 vector<s_bot*>::iterator i2; 07290 again_2: 07291 for(i2=bots.begin(); i2!=bots.end(); i2++) { 07292 vector<string>::iterator i3; 07293 for(i3=(*i2)->rejected_objects.begin(); i3!=(*i2)->rejected_objects.end(); i3++) { 07294 if(!(*i3).compare(obj)) { 07295 (*i2)->rejected_objects.erase(i3); 07296 goto again_2; 07297 } 07298 } 07299 } 07300 } 07301 07302 s_proc_to_pull* p=NULL; 07303 bool got=false; 07304 vector<s_proc_to_pull>::iterator i2; 07305 for(i2=(*i1)->pulling_procs.begin(); i2!=(*i1)->pulling_procs.end(); i2++) { 07306 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).proc_name.compare(name)) { 07307 p=&(*i2); 07308 got=true; 07309 break; 07310 } 07311 } 07312 if(got) { 07313 p->lines.pop_back(); // erase ending '}' bracket 07314 07315 string l="last_changed "; 07316 char tmp[128]; 07317 ltoa((long)p->last_changed,tmp,10); 07318 l+=tmp; 07319 p->lines.push_back(l); 07320 07321 vector<string>::iterator i4; 07322 for(i4=p->orig_groups.begin(); i4!=p->orig_groups.end(); i4++) { 07323 string l="member_of_group "; 07324 l+=*i4; 07325 p->lines.push_back(l); 07326 } 07327 vector<s_replication>::iterator i3; 07328 for(i3=p->replication.begin(); i3!=p->replication.end(); i3++) { 07329 string type; 07330 if((*i3).type==REPL_PUSH) 07331 type="push"; 07332 if((*i3).type==REPL_PULL) 07333 type="pull"; 07334 if((*i3).type==REPL_PUSHPULL) 07335 type="pushpull"; 07336 string l=(string)"replication "+(*i3).partner+" "+type; 07337 p->lines.push_back(l); 07338 } 07339 07340 s_user bot; 07341 logic_botnet_get_user((*i1)->botname,bot); 07342 07343 bool got2=false; 07344 vector<s_procedure>::iterator i5; 07345 for(i5=r_procedures.begin(); i5!=r_procedures.end(); i5++) 07346 if(!(*i5).name.compare(p->proc_name)) { 07347 got2=true; 07348 break; 07349 } 07350 07351 if(got2 || (!got2 && bot.access_to_plusproc)) { 07352 int error_line; 07353 const char* error_reason=NULL; 07354 logic_parse_proc(error_reason,error_line,p->lines,false,p->proc_name,p->orig_groups); 07355 07356 string d="pulling of object "; 07357 d+="(procedure) "; 07358 d+=p->proc_name; 07359 07360 if(error_line!=0) { 07361 // an compilation error 07362 } else { 07363 logic_parse_proc(error_reason,error_line,p->lines,true,p->proc_name,p->orig_groups); 07364 07365 if(bot.access_to_backup) 07366 botnet_backup((*i1)->botname); 07367 07368 if(bot.access_to_rehash) 07369 botnet_rehash(*i1,(*i1)->botname); 07370 07371 stats_botnet_proc_pulled(); 07372 } 07373 if(error_line==0) { 07374 d+=" successful"; 07375 07376 { 07377 string obj_type="procedure"; 07378 string reason="OK"; 07379 string obj=p->proc_name; 07380 07381 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,d,"PULL"); 07382 } 07383 07384 if(!botnet_has_grant(bot,p->proc_name)) { 07385 string x="\""; 07386 x+=p->proc_name; 07387 x+="\""; 07388 07389 bot.access_usage_procedure.push_back(x); 07390 07391 logic_botnet_remove_user((*i1)->botname); 07392 if(!bot.is_template) { 07393 if(!bot.terminator) 07394 r_users.push_back(bot); 07395 else 07396 r_terminators.push_back(bot); 07397 } else 07398 r_user_templates.push_back(bot); 07399 } 07400 } else { 07401 d+=" error: "; 07402 d+=error_reason; 07403 d+=" on line #"; 07404 char tmp[64]; 07405 ltoa(error_line,tmp,10); 07406 d+=tmp; 07407 07408 { 07409 string obj_type="procedure"; 07410 string reason="compile error"; 07411 string obj=p->proc_name; 07412 07413 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_CRITICAL_ERROR,d,"PULL"); 07414 } 07415 } 07416 07417 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),cmd->packet_type,cmd->command,d.c_str()); 07418 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 07419 } 07420 07421 (*i1)->pulling_procs.erase(i2); 07422 } 07423 } 07424 break; 07425 case CMD_PARTYLINE_1: 07426 { 07427 int user_size=sizeof(cmd->command_data.cmd_partyline_1.user); 07428 int ch_size=sizeof(cmd->command_data.cmd_partyline_1.channel); 07429 int bn_size=sizeof(cmd->command_data.cmd_partyline_1.botname); 07430 07431 char* x=new char[ch_size+1]; 07432 memset(x,0,ch_size+1); 07433 strncpy(x,cmd->command_data.cmd_partyline_1.channel,ch_size); 07434 bool got=false; 07435 again3: 07436 vector<s_botnet_channel>::iterator i2; 07437 for(i2=botnet_channels.begin(); i2!=botnet_channels.end(); i2++) 07438 if(!(*i2).channel_name.compare(x)) { 07439 got=true; 07440 break; 07441 } 07442 string channel=x; 07443 if(!got && !channel.empty()) { 07444 s_botnet_channel c; 07445 c.channel_name=x; 07446 botnet_channels.push_back(c); 07447 goto again3; 07448 } 07449 s_partyline_member me; 07450 delete[] x; 07451 x=new char[user_size+1]; 07452 memset(x,0,user_size+1); 07453 strncpy(x,cmd->command_data.cmd_partyline_1.user,user_size); 07454 me.user=x; 07455 delete[] x; 07456 07457 x=new char[bn_size+1]; 07458 memset(x,0,bn_size+1); 07459 strncpy(x,cmd->command_data.cmd_partyline_1.botname,bn_size); 07460 me.botname=x; 07461 delete[] x; 07462 07463 bool got2=false; 07464 if(!channel.empty()) { 07465 vector<s_partyline_member>::iterator i3; 07466 for(i3=(*i2).members.begin(); i3!=(*i2).members.end(); i3++) 07467 if(!(*i3).user.compare(me.user)) { 07468 got2=true; 07469 break; 07470 } 07471 if(!got2) 07472 (*i2).members.push_back(me); 07473 } 07474 07475 botnet_cleanup_ids(); 07476 bool got_id=false; 07477 vector<s_msg_id>::iterator i5; 07478 for(i5=msg_ids.begin(); i5!=msg_ids.end(); i5++) 07479 if((*i5).id==cmd->command_data.cmd_partyline_1.id) { 07480 got_id=true; 07481 break; 07482 } 07483 07484 if(!got_id) { 07485 s_msg_id id; 07486 time((time_t*)&id.time); 07487 id.id=cmd->command_data.cmd_partyline_1.id; 07488 msg_ids.push_back(id); 07489 07490 vector<s_bot*>::iterator i4; 07491 for(i4=bots.begin(); i4!=bots.end(); i4++) { 07492 //if((*i4).botname.compare(me.botname) && (*i4).botname.compare((*i1)->botname)) 07493 botnet_send_command(*i4,cmd); 07494 } 07495 07496 botnet_partyline_event(me.botname,cmd); 07497 07498 stats_botnet_partyline_event(); 07499 } 07500 } 07501 break; 07502 case CMD_PARTYLINE_USER_1: 07503 { 07504 int user_size=sizeof(cmd->command_data.cmd_partyline_user_1.user); 07505 int ch_size=sizeof(cmd->command_data.cmd_partyline_user_1.channel); 07506 int bn_size=sizeof(cmd->command_data.cmd_partyline_user_1.botname); 07507 07508 char* x=new char[ch_size+1]; 07509 memset(x,0,ch_size+1); 07510 strncpy(x,cmd->command_data.cmd_partyline_user_1.channel,ch_size); 07511 bool got=false; 07512 again4: 07513 vector<s_botnet_channel>::iterator i2; 07514 for(i2=botnet_channels.begin(); i2!=botnet_channels.end(); i2++) 07515 if(!(*i2).channel_name.compare(x)) { 07516 got=true; 07517 break; 07518 } 07519 if(!got) { 07520 s_botnet_channel c; 07521 c.channel_name=x; 07522 botnet_channels.push_back(c); 07523 goto again4; 07524 } 07525 s_partyline_member me; 07526 delete[] x; 07527 x=new char[user_size+1]; 07528 memset(x,0,user_size+1); 07529 strncpy(x,cmd->command_data.cmd_partyline_user_1.user,user_size); 07530 me.user=x; 07531 delete[] x; 07532 x=new char[bn_size+1]; 07533 memset(x,0,bn_size+1); 07534 strncpy(x,cmd->command_data.cmd_partyline_user_1.botname,bn_size); 07535 me.botname=x; 07536 delete[] x; 07537 bool got2=false; 07538 vector<s_partyline_member>::iterator i3; 07539 for(i3=(*i2).members.begin(); i3!=(*i2).members.end(); i3++) 07540 if(!(*i3).user.compare(me.user) && !(*i3).botname.compare(me.botname)) { 07541 got2=true; 07542 break; 07543 } 07544 if(!got2) 07545 (*i2).members.push_back(me); 07546 07547 botnet_cleanup_ids(); 07548 bool got_id=false; 07549 vector<s_msg_id>::iterator i5; 07550 for(i5=msg_ids.begin(); i5!=msg_ids.end(); i5++) 07551 if((*i5).id==cmd->command_data.cmd_partyline_user_1.id) { 07552 got_id=true; 07553 break; 07554 } 07555 07556 if(!got_id) { 07557 s_msg_id id; 07558 time((time_t*)&id.time); 07559 id.id=cmd->command_data.cmd_partyline_user_1.id; 07560 msg_ids.push_back(id); 07561 07562 vector<s_bot*>::iterator i4; 07563 for(i4=bots.begin(); i4!=bots.end(); i4++) 07564 //if((*i4).botname.compare((*i1)->botname)) 07565 botnet_send_command(*i4,cmd); 07566 07567 botnet_partyline_event((*i1)->botname,cmd); 07568 07569 stats_botnet_partyline_event(); 07570 } 07571 } 07572 break; 07573 case CMD_REPL_CHDEF_01_1: 07574 { 07575 int n_size=sizeof(cmd->command_data.cmd_repl_chdef_01_1.name); 07576 char* n=new char[n_size+1]; 07577 memset(n,0,n_size+1); 07578 memcpy(n,cmd->command_data.cmd_repl_chdef_01_1.name,n_size); 07579 string name=n; 07580 delete[] n; 07581 n=NULL; 07582 07583 { 07584 again_erase_2: 07585 vector<s_chan_def_to_pull>::iterator i2; 07586 for(i2=(*i1)->pulling_chans.begin(); i2!=(*i1)->pulling_chans.end(); i2++) { 07587 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).chan_name.compare(name)) { 07588 (*i1)->pulling_chans.erase(i2); 07589 goto again_erase_2; 07590 } 07591 } 07592 07593 bool got=false; 07594 vector<s_channel_def>::iterator i3; 07595 for(i3=r_channel_defs.begin(); i3!=r_channel_defs.end(); i3++) { 07596 if(!(*i3).channel_name.compare(name)) { 07597 got=true; 07598 vector<s_replication>::iterator i4; 07599 for(i4=(*i3).replication.begin(); i4!=(*i3).replication.end(); i4++) { 07600 if(!(*i4).partner.compare((*i1)->botname) && ((*i4).type==REPL_PULL || (*i4).type==REPL_PUSHPULL)) { 07601 s_chan_def_to_pull ch; 07602 ch.botname=(*i1)->botname; 07603 ch.chan_name=(*i3).channel_name; 07604 (*i1)->pulling_chans.push_back(ch); 07605 got=true; 07606 break; 07607 } 07608 } 07609 if(got) 07610 break; 07611 } 07612 } 07613 if(!got) { 07614 s_chan_def_to_pull ch; 07615 ch.botname=(*i1)->botname; 07616 ch.chan_name=name; 07617 07618 // we got a new channel definition, so set them replication flags 07619 s_replication r; 07620 r.partner=(*i1)->botname; 07621 r.type=REPL_PULL; 07622 ch.chd.replication.push_back(r); 07623 07624 (*i1)->pulling_chans.push_back(ch); 07625 } 07626 } 07627 07628 s_chan_def_to_pull* ch=NULL; 07629 bool got=false; 07630 vector<s_chan_def_to_pull>::iterator i2; 07631 for(i2=(*i1)->pulling_chans.begin(); i2!=(*i1)->pulling_chans.end(); i2++) { 07632 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).chan_name.compare(name)) { 07633 ch=&(*i2); 07634 got=true; 07635 break; 07636 } 07637 } 07638 if(got) { 07639 ch->last_changed=cmd->command_data.cmd_repl_chdef_01_1.last_changed; 07640 07641 ch->chd.channel_name=name; 07642 ch->chd.on_mode=cmd->command_data.cmd_repl_chdef_01_1.on_mode; 07643 ch->chd.on_key=cmd->command_data.cmd_repl_chdef_01_1.on_key; 07644 ch->chd.on_limit=cmd->command_data.cmd_repl_chdef_01_1.on_limit; 07645 ch->chd.on_topic=cmd->command_data.cmd_repl_chdef_01_1.on_topic; 07646 ch->chd.on_ircop=cmd->command_data.cmd_repl_chdef_01_1.on_ircop; 07647 ch->chd.on_ctcp=cmd->command_data.cmd_repl_chdef_01_1.on_ctcp; 07648 ch->chd.on_privmsg=cmd->command_data.cmd_repl_chdef_01_1.on_privmsg; 07649 ch->chd.on_notice=cmd->command_data.cmd_repl_chdef_01_1.on_notice; 07650 ch->chd.on_part=cmd->command_data.cmd_repl_chdef_01_1.on_part; 07651 ch->chd.on_dynamic_ban=cmd->command_data.cmd_repl_chdef_01_1.on_dynamic_ban; 07652 ch->chd.allow_dynamic.clear(); 07653 ch->chd.dynamic_plus_modes=cmd->command_data.cmd_repl_chdef_01_1.dynamic_plus_modes; 07654 ch->chd.dynamic_minus_modes=cmd->command_data.cmd_repl_chdef_01_1.dynamic_minus_modes; 07655 ch->chd.groups.clear(); 07656 ch->chd.replication.clear(); 07657 ch->chd.dynamic_bans.clear(); 07658 ch->chd.dynbans_editors.clear(); 07659 } 07660 } 07661 break; 07662 case CMD_REPL_CHDEF_02_1: 07663 { 07664 int n_size=sizeof(cmd->command_data.cmd_repl_chdef_02_1.name); // !!! 07665 char* n=new char[n_size+1]; 07666 memset(n,0,n_size+1); 07667 memcpy(n,cmd->command_data.cmd_repl_chdef_02_1.name,n_size); // !!! 07668 string name=n; 07669 delete[] n; 07670 n=NULL; 07671 07672 s_chan_def_to_pull* ch=NULL; 07673 bool got=false; 07674 vector<s_chan_def_to_pull>::iterator i2; 07675 for(i2=(*i1)->pulling_chans.begin(); i2!=(*i1)->pulling_chans.end(); i2++) { 07676 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).chan_name.compare(name)) { 07677 ch=&(*i2); 07678 got=true; 07679 break; 07680 } 07681 } 07682 if(got) { 07683 int d_size=sizeof(cmd->command_data.cmd_repl_chdef_02_1.group); // !!! 07684 char* d=new char[d_size+1]; 07685 memset(d,0,d_size+1); 07686 memcpy(d,cmd->command_data.cmd_repl_chdef_02_1.group,d_size); // !!! 07687 string data=d; 07688 delete[] d; 07689 d=NULL; 07690 07691 s_group g; 07692 g.name=data; 07693 ch->chd.groups.push_back(g); 07694 } 07695 } 07696 break; 07697 case CMD_REPL_CHDEF_03_1: 07698 { 07699 int n_size=sizeof(cmd->command_data.cmd_repl_chdef_03_1.name); // !!! 07700 char* n=new char[n_size+1]; 07701 memset(n,0,n_size+1); 07702 memcpy(n,cmd->command_data.cmd_repl_chdef_03_1.name,n_size); // !!! 07703 string name=n; 07704 delete[] n; 07705 n=NULL; 07706 07707 s_chan_def_to_pull* ch=NULL; 07708 bool got=false; 07709 vector<s_chan_def_to_pull>::iterator i2; 07710 for(i2=(*i1)->pulling_chans.begin(); i2!=(*i1)->pulling_chans.end(); i2++) { 07711 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).chan_name.compare(name)) { 07712 ch=&(*i2); 07713 got=true; 07714 break; 07715 } 07716 } 07717 if(got) { 07718 int d_size=sizeof(cmd->command_data.cmd_repl_chdef_03_1.group); // !!! 07719 char* d=new char[d_size+1]; 07720 memset(d,0,d_size+1); 07721 memcpy(d,cmd->command_data.cmd_repl_chdef_03_1.group,d_size); // !!! 07722 string data=d; 07723 delete[] d; 07724 d=NULL; 07725 07726 s_dynamic_rule dr; 07727 dr.group=data; 07728 dr.plus_modes=cmd->command_data.cmd_repl_chdef_03_1.plus_modes; 07729 dr.minus_modes=cmd->command_data.cmd_repl_chdef_03_1.minus_modes; 07730 ch->chd.allow_dynamic.push_back(dr); 07731 } 07732 } 07733 break; 07734 case CMD_REPL_CHDEF_04_1: 07735 { 07736 int n_size=sizeof(cmd->command_data.cmd_repl_chdef_04_1.name); // !!! 07737 char* n=new char[n_size+1]; 07738 memset(n,0,n_size+1); 07739 memcpy(n,cmd->command_data.cmd_repl_chdef_04_1.name,n_size); // !!! 07740 string name=n; 07741 delete[] n; 07742 n=NULL; 07743 07744 s_chan_def_to_pull* ch=NULL; 07745 bool got=false; 07746 vector<s_chan_def_to_pull>::iterator i2; 07747 for(i2=(*i1)->pulling_chans.begin(); i2!=(*i1)->pulling_chans.end(); i2++) { 07748 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).chan_name.compare(name)) { 07749 ch=&(*i2); 07750 got=true; 07751 break; 07752 } 07753 } 07754 if(got) { 07755 int d_size=sizeof(cmd->command_data.cmd_repl_chdef_04_1.mask); // !!! 07756 char* d=new char[d_size+1]; 07757 memset(d,0,d_size+1); 07758 memcpy(d,cmd->command_data.cmd_repl_chdef_04_1.mask,d_size); // !!! 07759 string mask=d; 07760 delete[] d; 07761 d=NULL; 07762 07763 d_size=sizeof(cmd->command_data.cmd_repl_chdef_04_1.reason); // !!! 07764 d=new char[d_size+1]; 07765 memset(d,0,d_size+1); 07766 memcpy(d,cmd->command_data.cmd_repl_chdef_04_1.reason,d_size); // !!! 07767 string reason=d; 07768 delete[] d; 07769 d=NULL; 07770 07771 pair<string,string> p; 07772 p.first=mask; 07773 p.second=reason; 07774 07775 ch->chd.dynamic_bans.insert(p); 07776 } 07777 } 07778 break; 07779 case CMD_REPL_CHDEF_05_1: 07780 { 07781 int n_size=sizeof(cmd->command_data.cmd_repl_chdef_05_1.name); // !!! 07782 char* n=new char[n_size+1]; 07783 memset(n,0,n_size+1); 07784 memcpy(n,cmd->command_data.cmd_repl_chdef_05_1.name,n_size); // !!! 07785 string name=n; 07786 delete[] n; 07787 n=NULL; 07788 07789 s_chan_def_to_pull* ch=NULL; 07790 bool got=false; 07791 vector<s_chan_def_to_pull>::iterator i2; 07792 for(i2=(*i1)->pulling_chans.begin(); i2!=(*i1)->pulling_chans.end(); i2++) { 07793 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).chan_name.compare(name)) { 07794 ch=&(*i2); 07795 got=true; 07796 break; 07797 } 07798 } 07799 if(got) { 07800 int d_size=sizeof(cmd->command_data.cmd_repl_chdef_05_1.group); // !!! 07801 char* d=new char[d_size+1]; 07802 memset(d,0,d_size+1); 07803 memcpy(d,cmd->command_data.cmd_repl_chdef_05_1.group,d_size); // !!! 07804 string data=d; 07805 delete[] d; 07806 d=NULL; 07807 07808 ch->chd.dynbans_editors.push_back(data); 07809 } 07810 } 07811 break; 07812 case CMD_REPL_CHDEF_06_8: 07813 { 07814 int n_size=sizeof(cmd->command_data.cmd_repl_chdef_06_8.name); // !!! 07815 char* n=new char[n_size+1]; 07816 memset(n,0,n_size+1); 07817 memcpy(n,cmd->command_data.cmd_repl_chdef_06_8.name,n_size); // !!! 07818 string name=n; 07819 delete[] n; 07820 n=NULL; 07821 07822 s_chan_def_to_pull* ch=NULL; 07823 bool got=false; 07824 vector<s_chan_def_to_pull>::iterator i2; 07825 for(i2=(*i1)->pulling_chans.begin(); i2!=(*i1)->pulling_chans.end(); i2++) { 07826 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).chan_name.compare(name)) { 07827 ch=&(*i2); 07828 got=true; 07829 break; 07830 } 07831 } 07832 if(got) { 07833 int d_size=sizeof(cmd->command_data.cmd_repl_chdef_06_8.on_server_msg); // !!! 07834 char* d=new char[d_size+1]; 07835 memset(d,0,d_size+1); 07836 memcpy(d,cmd->command_data.cmd_repl_chdef_06_8.on_server_msg,d_size); // !!! 07837 string data=d; 07838 delete[] d; 07839 d=NULL; 07840 07841 ch->chd.channel_name=name; 07842 ch->chd.on_server_msg=data; 07843 } 07844 } 07845 break; 07846 case CMD_REPL_CHDEF_99_1: 07847 { 07848 int n_size=sizeof(cmd->command_data.cmd_repl_chdef_99_1.name); // !!! 07849 char* n=new char[n_size+1]; 07850 memset(n,0,n_size+1); 07851 memcpy(n,cmd->command_data.cmd_repl_chdef_99_1.name,n_size); // !!! 07852 string name=n; 07853 delete[] n; 07854 n=NULL; 07855 { 07856 s_bot_control* c=new s_bot_control; 07857 c->hard_clear(); 07858 c->packet_type=PACKET_TYPE_CONTROL; 07859 c->supported_proto_version=SUPPORTED_PROTO_VERSION; 07860 c->control=CTRL_PING; 07861 botnet_send_control(*i1,c); 07862 (*i1)->next_ping=time(NULL)+ping_time; 07863 (*i1)->start_awaiting_pong=time(NULL); 07864 delete c; 07865 07866 string obj=(string)"CHAN "+name; 07867 vector<s_bot*>::iterator i2; 07868 again_3: 07869 for(i2=bots.begin(); i2!=bots.end(); i2++) { 07870 vector<string>::iterator i3; 07871 for(i3=(*i2)->rejected_objects.begin(); i3!=(*i2)->rejected_objects.end(); i3++) { 07872 if(!(*i3).compare(obj)) { 07873 (*i2)->rejected_objects.erase(i3); 07874 goto again_3; 07875 } 07876 } 07877 } 07878 } 07879 07880 s_chan_def_to_pull* ch=NULL; 07881 bool got=false; 07882 vector<s_chan_def_to_pull>::iterator i2; 07883 for(i2=(*i1)->pulling_chans.begin(); i2!=(*i1)->pulling_chans.end(); i2++) { 07884 if(!(*i2).botname.compare((*i1)->botname) && !(*i2).chan_name.compare(name)) { 07885 ch=&(*i2); 07886 got=true; 07887 break; 07888 } 07889 } 07890 if(got) { 07891 s_user bot; 07892 logic_botnet_get_user((*i1)->botname,bot); 07893 07894 { 07895 s_channel_def chd; 07896 logic_botnet_get_channel_def(ch->chan_name,chd); 07897 s_replication r; 07898 r.partner=(*i1)->botname; 07899 r.type=REPL_PULL; 07900 ch->chd.replication.clear(); 07901 vector<s_replication>::iterator i2; 07902 bool got_this_repl=false; 07903 for(i2=chd.replication.begin(); i2!=chd.replication.end(); i2++) { 07904 ch->chd.replication.push_back(*i2); 07905 if(!(*i2).partner.compare(r.partner)) 07906 got_this_repl=true; 07907 } 07908 if(!got_this_repl) 07909 ch->chd.replication.push_back(r); 07910 } 07911 07912 s_replication r; 07913 r.partner=bot.name; 07914 r.type=REPL_PULL; 07915 ch->chd.replication.push_back(r); 07916 07917 logic_botnet_remove_channel_def(ch->chan_name); 07918 r_channel_defs.push_back(ch->chd); 07919 07920 if(bot.access_to_backup) 07921 botnet_backup((*i1)->botname); 07922 07923 if(bot.access_to_rehash) 07924 botnet_rehash(*i1,(*i1)->botname); 07925 07926 string d="pulling of object "; 07927 d+="(channel) "; 07928 d+=ch->chan_name; 07929 d+=" successful"; 07930 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),cmd->packet_type,cmd->command,d.c_str()); 07931 log_botnet(botnet_botname,(*i1)->botname.c_str(),d.c_str()); 07932 07933 (*i1)->pulling_chans.erase(i2); 07934 07935 stats_botnet_chandef_pulled(); 07936 07937 { 07938 string obj_type="channel"; 07939 string reason="OK"; 07940 string obj=ch->chan_name; 07941 07942 logic_on_internal_event("@botnet_replication@",(*i1)->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,d,"PULL"); 07943 } 07944 } 07945 } 07946 break; 07947 default: 07948 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),cmd->packet_type,cmd->command,"unknown PACKET_TYPE_COMMAND from remote bot - in file " __FILE__ " in function " __FUNC__); 07949 break; 07950 } 07951 } 07952 } 07953 if(packet_type!=PACKET_TYPE_COMMAND && packet_type!=PACKET_TYPE_CONTROL) 07954 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),cmd->packet_type,cmd->command,"invalid PACKET_TYPE from remote bot"); 07955 else { 07956 if(packet_type==PACKET_TYPE_COMMAND) 07957 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),cmd->packet_type,cmd->command,"COMMAND from remote bot"); 07958 if(packet_type==PACKET_TYPE_CONTROL) 07959 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),ctrl->packet_type,ctrl->control,"CONTROL from remote bot"); 07960 } 07961 } 07962 } 07963 /*delete cmd; 07964 delete ctrl;*/ 07965 07966 l: 07967 // send 07968 for(i1=bots.begin(); i1!=bots.end(); i1++) { 07969 if((*i1)->ssl) 07970 ssl_do_read_write((*i1)->ssl); 07971 if((*i1)->socket.cmp()==true && (*i1)->ssl_connection && (*i1)->awaiting_ready!=0) { 07972 time_t now=time(NULL); 07973 //time_t x=(*i1)->awaiting_ready+10-now; 07974 if((*i1)->awaiting_ready+10<now) { 07975 (*i1)->awaiting_ready=0; 07976 ssl_close((*i1)->ssl,&((*i1)->socket)); 07977 (*i1)->ssl=NULL; 07978 sock_close((*i1)->socket); 07979 (*i1)->socket.clear(); 07980 continue; 07981 } 07982 char buff; 07983 size_t len=recv((*i1)->socket.handle,&buff,1,0); 07984 if(len<=0) 07985 continue; 07986 07987 if(len==1 && buff==0x01) { 07988 (*i1)->awaiting_ready=0; 07989 char err_str[1024]; 07990 if(ssl_client_connection((*i1)->ssl,&((*i1)->socket),err_str,(char*)ssl_conf.client_cert.c_str(),(char*)ssl_conf.client_key.c_str())) { 07991 ssl_close((*i1)->ssl,&((*i1)->socket)); 07992 (*i1)->ssl=NULL; 07993 sock_close((*i1)->socket); 07994 (*i1)->socket.clear(); 07995 continue; 07996 } 07997 } 07998 continue; 07999 } 08000 if((*i1)->socket.cmp()==false) { 08001 if((*i1)->was_linked) { 08002 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),-1,-1,"LINK connection broken"); 08003 log_botnet(botnet_botname,(*i1)->botname.c_str(),"LINK connection broken"); 08004 (*i1)->was_linked=false; 08005 botnet_on_unlink((*i1)->botname,botnet_botname,botnet_get_unique_id()); 08006 } 08007 08008 bool got=false; 08009 vector<s_bot*>::iterator i2; 08010 for(i2=bots.begin(); i2!=bots.end(); i2++) 08011 if(!(*i2)->botname.compare((*i1)->botname) && (*i1)->socket.cmp()!=false) 08012 got=true; 08013 08014 if(!(*i1)->invoked_from_telnet && !(*i1)->unlink_proc_called && !got) { 08015 (*i1)->unlink_proc_called=true; 08016 08017 string call_string=(*i1)->unlink_proc; 08018 string cs=call_string; 08019 unsigned int i2; 08020 for(i2=0; i2<cs.length(); i2++) 08021 if(cs[i2]=='(') 08022 break; 08023 cs.erase(i2,cs.length()-i2); // erase everything after '(' 08024 call_string=logic_find_proc_by_name(cs); 08025 cs=(*i1)->unlink_proc; 08026 for(i2=0; i2<cs.length(); i2++) 08027 if(cs[i2]=='(') 08028 break; 08029 cs.erase(0,i2+1); 08030 if(cs.length()>0 && cs[cs.length()-1]==')') 08031 cs.erase(cs.length()-1,1); 08032 cs+=","; 08033 08034 map<string,string> vars=(*i1)->vars; 08035 08036 list<string> params; 08037 bool str=false; 08038 string p; 08039 for(i2=0; i2<cs.length(); i2++) { 08040 if(cs[i2]=='\"') { 08041 str=!str; 08042 continue; 08043 } 08044 if(!str && cs[i2]==',') { 08045 if(p.length()>0 && p[0]=='$') { 08046 map<string,string>::iterator i3; 08047 for(i3=vars.begin(); i3!=vars.end(); i3++) { 08048 if(!(*i3).first.compare(p)) { 08049 p=(*i3).second; 08050 break; 08051 } 08052 } 08053 } 08054 params.push_back(p); 08055 p=""; 08056 continue; 08057 } 08058 if(!str && cs[i2]==')') { 08059 if(p!="") { 08060 if(p.length()>0 && p[0]=='$') { 08061 map<string,string>::iterator i3; 08062 for(i3=vars.begin(); i3!=vars.end(); i3++) { 08063 if(!(*i3).first.compare(p)) { 08064 p=(*i3).second; 08065 break; 08066 } 08067 } 08068 } 08069 params.push_back(p); 08070 } 08071 break; 08072 } 08073 p+=cs[i2]; 08074 } 08075 08076 logic_call_proc_ex2(call_string.c_str(),vars,params); 08077 } 08078 08079 if((*i1)->invoked_from_telnet) { 08080 /*(*i1)->command_receive_buffer=NULL; 08081 (*i1)->control_receive_buffer=NULL; 08082 (*i1)->rle_buffer=NULL;*/ 08083 delete *i1; 08084 bots.erase(i1); 08085 goto l; 08086 } 08087 // init again 08088 if(!(*i1)->clean) { 08089 (*i1)->clean=true; 08090 (*i1)->socket.clear(); 08091 (*i1)->sent_bot_auth_1=false; 08092 (*i1)->received_bot_auth_1=false; 08093 (*i1)->receive_buffer_pos=0; 08094 if((*i1)->rle_buffer) { 08095 free((*i1)->rle_buffer); 08096 (*i1)->rle_buffer=NULL; 08097 (*i1)->rle_buffer_len=0; 08098 } 08099 (*i1)->buff_size_from_dcc=0; 08100 (*i1)->buff_pos_from_dcc=0; 08101 (*i1)->got_bytes=0; 08102 (*i1)->auth_ok=false; 08103 (*i1)->remote_pswd_ok=false; 08104 (*i1)->was_linked=false; 08105 time(&(*i1)->next_ping); 08106 (*i1)->next_ping+=ping_time; 08107 (*i1)->start_awaiting_pong=0; 08108 // (*i1)->unlink_proc_called=false; // do NOT execute this! it causes multiple unlink_proc calls! 08109 (*i1)->users_to_pull_last_update=0; 08110 (*i1)->pulling_users.clear(); 08111 (*i1)->users_to_push_last_update=0; 08112 (*i1)->pushing_users.clear(); 08113 (*i1)->procs_to_pull_last_update=0; 08114 (*i1)->pulling_procs.clear(); 08115 (*i1)->procs_to_push_last_update=0; 08116 (*i1)->pushing_procs.clear(); 08117 08118 (*i1)->chans_to_pull_last_update=0; 08119 (*i1)->pulling_chans.clear(); 08120 08121 (*i1)->chans_to_push_last_update; 08122 (*i1)->pushing_chans.clear(); 08123 08124 (*i1)->rejected_objects.clear(); 08125 08126 (*i1)->prv_to_push_last_update=0; 08127 (*i1)->prv_to_push.clear(); 08128 (*i1)->prv_to_pull.clear(); 08129 (*i1)->prv_pulling=false; 08130 08131 (*i1)->last_proc_push=0; 08132 08133 (*i1)->sent_partyline_users=false; 08134 08135 if((*i1)->ssl) 08136 ssl_close((*i1)->ssl,&((*i1)->socket)); 08137 (*i1)->ssl=NULL; 08138 } 08139 08140 time_t now; 08141 time(&now); 08142 if((*i1)->last_try+botnet_penalty>now) { 08143 (*i1)->waiting=true; 08144 continue; 08145 } 08146 time(&(*i1)->last_try); 08147 08148 int ec=0; 08149 (*i1)->socket=sock_connect((char*)(*i1)->localip.c_str(),(char*)(*i1)->botip.c_str(),(*i1)->botport,ec,(*i1)->ssl_connection?false:true); 08150 if((*i1)->socket.cmp()==false) { 08151 //log_socket(ec,sock_error(ec),"while calling sock_connect in file " __FILE__ " in function " __FUNC__); 08152 continue; 08153 } 08154 (*i1)->clean=false; 08155 if((*i1)->ssl_connection) { 08156 sock_set_blocking((*i1)->socket,true); 08157 } 08158 08159 stats_botnet_new_connection(); 08160 08161 sleep(1000); 08162 size_t len=0; 08163 do { 08164 char buff[1024]; 08165 int ec=0; 08166 bool closed; 08167 if(!(*i1)->ssl_connection) 08168 len=sock_read((*i1)->socket,buff,1024,ec,closed); 08169 else { 08170 timeval t; 08171 t.tv_sec=0; 08172 t.tv_usec=10; 08173 08174 fd_set a; 08175 FD_ZERO(&a); 08176 FD_SET((*i1)->socket.handle,&a); 08177 08178 int i=select((int)(*i1)->socket.handle+1,&a,NULL,NULL,&t); 08179 if(i==0) 08180 break; 08181 len=recv((*i1)->socket.handle,buff,1024,0); 08182 } 08183 if((signed)len<0) 08184 len=0; 08185 stats_botnet_bytes_received(len); 08186 if(ec) 08187 len=0; 08188 } while(len); 08189 08190 ec=0; 08191 string nick=botnet_botname; 08192 nick+="\r\n"; 08193 size_t sent=0; 08194 if(!(*i1)->ssl_connection) 08195 sent=sock_send((*i1)->socket,(char*)nick.c_str(),nick.length(),ec); 08196 else 08197 sent=send((*i1)->socket.handle,(char*)nick.c_str(),(int)nick.length(),0); 08198 stats_botnet_bytes_sent(sent); 08199 if(sent!=nick.length() || ec!=0) { 08200 log_socket(ec,sock_error(ec),"in file " __FILE__ " in function " __FUNC__ " (not all the data were sent)"); 08201 if((*i1)->ssl) { 08202 ssl_close((*i1)->ssl,&((*i1)->socket)); 08203 (*i1)->ssl=NULL; 08204 } 08205 sock_close((*i1)->socket); 08206 (*i1)->socket.clear(); 08207 continue; 08208 } 08209 08210 if((*i1)->ssl_connection) 08211 (*i1)->awaiting_ready=time(NULL); 08212 } else { 08213 if((*i1)->socket.cmp()==false) 08214 continue; 08215 08216 time_t now; 08217 time(&now); 08218 08219 if((*i1)->next_ping<now) { 08220 s_bot_control* c=new s_bot_control; 08221 c->hard_clear(); 08222 c->packet_type=PACKET_TYPE_CONTROL; 08223 c->supported_proto_version=SUPPORTED_PROTO_VERSION; 08224 c->control=CTRL_PING; 08225 botnet_send_control(*i1,c); 08226 (*i1)->next_ping=now+ping_time; 08227 (*i1)->start_awaiting_pong=now; 08228 delete c; 08229 } 08230 if((*i1)->start_awaiting_pong!=0) { 08231 if((*i1)->start_awaiting_pong+10<now) { 08232 // ping timeout 08233 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),-1,-1,"PING timeout - in file " __FILE__ " in function " __FUNC__); 08234 log_botnet(botnet_botname,(*i1)->botname.c_str(),"PING timeout"); 08235 if((*i1)->ssl) { 08236 ssl_close((*i1)->ssl,&((*i1)->socket)); 08237 (*i1)->ssl=NULL; 08238 } 08239 sock_close((*i1)->socket); 08240 (*i1)->socket.clear(); 08241 continue; 08242 } 08243 } 08244 08245 if(!(*i1)->sent_at_least_one_ping) { 08246 // send dummy ping packet first 08247 s_bot_control* c=new s_bot_control; 08248 c->hard_clear(); 08249 c->packet_type=PACKET_TYPE_CONTROL; 08250 c->supported_proto_version=SUPPORTED_PROTO_VERSION; 08251 c->control=CTRL_PING; 08252 botnet_send_control(*i1,c); 08253 (*i1)->next_ping=now+ping_time; 08254 (*i1)->start_awaiting_pong=now; 08255 delete c; 08256 08257 (*i1)->sent_at_least_one_ping=true; 08258 } 08259 08260 if(!(*i1)->sent_bot_auth_1 && (*i1)->got_at_least_one_pong) { 08261 s_bot_command* c=new s_bot_command; 08262 c->hard_clear(); 08263 08264 c->packet_type=PACKET_TYPE_COMMAND; 08265 c->size=sizeof(c); 08266 c->version=1; 08267 c->command=CMD_AUTH_1; 08268 strcpy(c->command_data.bot_auth_1.botname,botnet_botname); 08269 08270 unsigned char signature[32+1]; 08271 signature[32]=0; 08272 08273 if((*i1)->remote_MD5_password.length()==sizeof(signature)-1) 08274 strcpy((char*)signature,dcc_get_password(botnet_botname).c_str()); 08275 08276 MD5Context md5c; 08277 MD5Init(&md5c); 08278 MD5Update(&md5c,signature,sizeof(signature)-1); 08279 MD5Final(signature,&md5c); 08280 08281 char sig[128]; 08282 sig[0]=0; 08283 for(int i1_=0; i1_<16; i1_++) { 08284 char tmp[16]; 08285 sprintf(tmp,"%02X",signature[i1_]); 08286 strcat(sig,tmp); 08287 } 08288 08289 memset(c->command_data.bot_auth_1.digest,0,sizeof(c->command_data.bot_auth_1.digest)); 08290 memcpy(c->command_data.bot_auth_1.digest,sig,sizeof(signature)-1); 08291 08292 if(botnet_send_command(*i1,c)) { 08293 log_botnet_debug(botnet_botname,(*i1)->botname.c_str(),c->packet_type,c->command,"unable to send PACKET_TYPE_COMMAND to remote bot - in file " __FILE__ " in function " __FUNC__); 08294 log_botnet(botnet_botname,(*i1)->botname.c_str(),"closing LINK connection (error)"); 08295 if((*i1)->ssl) { 08296 ssl_close((*i1)->ssl,&((*i1)->socket)); 08297 (*i1)->ssl=NULL; 08298 } 08299 sock_close((*i1)->socket); 08300 (*i1)->socket.clear(); 08301 continue; 08302 } 08303 08304 (*i1)->sent_bot_auth_1=true; 08305 08306 delete c; 08307 } 08308 08309 if((*i1)->auth_ok && (*i1)->remote_pswd_ok) { 08310 time_t now; 08311 time(&now); 08312 if(/*(*i1)->users_to_push_last_update+120<now*/ 1) { // commented out because we got last_proc_push functionality 08313 time(&(*i1)->users_to_push_last_update); 08314 08315 /*vector<s_bot*>::iterator i1; 08316 for(i1=bots.begin(); i1!=bots.end(); i1++) {*/ 08317 for(int _i1_=0; _i1_<1; _i1_++) { // for continue command we use later 08318 // procedures first! 08319 if((*i1)->last_proc_push==0 || (*i1)->last_proc_push+60>time(NULL)) 08320 continue; // it is not the right time now! procedures first! 08321 (*i1)->last_proc_push=0; 08322 08323 vector<s_user> users; 08324 logic_get_push_users((*i1)->botname,users); 08325 vector<s_user>::iterator i2; 08326 for(i2=users.begin(); i2!=users.end(); i2++) { 08327 if((*i2).last_changed==0) 08328 (*i2).last_changed=1; 08329 { 08330 bool reject=false; 08331 string obj=(string)"USER "+(*i2).name; 08332 vector<string>::iterator i2; 08333 for(i2=(*i1)->rejected_objects.begin(); i2!=(*i1)->rejected_objects.end(); i2++) { 08334 if(!(*i2).compare(obj)) { 08335 reject=true; 08336 break; 08337 } 08338 } 08339 if(reject) 08340 continue; 08341 } 08342 s_user_to_push u; 08343 u.botname=(*i1)->botname; 08344 u.user=*i2; 08345 08346 s_bot_command* c=new s_bot_command; 08347 c->hard_clear(); 08348 c->packet_type=PACKET_TYPE_COMMAND; 08349 c->size=sizeof(c); 08350 c->version=1; 08351 c->command=CMD_PUSH_1; 08352 c->command_data.check_time_1.now=(my_time_t)time(NULL); 08353 c->command_data.check_time_1.user=true; 08354 c->command_data.check_time_1.procedure=false; 08355 c->command_data.check_time_1.channel_def=false; 08356 c->command_data.check_time_1.prv=false; 08357 char* user=c->command_data.check_time_1.object_name; 08358 memset(user,0,sizeof(c->command_data.check_time_1.object_name)); 08359 strncpy(user,u.user.name.c_str(),sizeof(c->command_data.check_time_1.object_name)); 08360 c->command_data.check_time_1.original_time=(my_time_t)u.user.last_changed; 08361 botnet_send_command(*i1,c); 08362 08363 delete c; 08364 } 08365 } 08366 } 08367 } 08368 08369 if((*i1)->auth_ok && (*i1)->remote_pswd_ok) { 08370 time_t now; 08371 time(&now); 08372 if((*i1)->procs_to_push_last_update+120+40<now) { 08373 time(&(*i1)->procs_to_push_last_update); 08374 08375 /*vector<s_bot*>::iterator i1; 08376 for(i1=bots.begin(); i1!=bots.end(); i1++) { 08377 */ 08378 { 08379 (*i1)->last_proc_push=time(NULL); 08380 vector<s_procedure> procs; 08381 logic_get_push_procs((*i1)->botname,procs); 08382 vector<s_procedure>::iterator i2; 08383 for(i2=procs.begin(); i2!=procs.end(); i2++) { 08384 if((*i2).last_changed==0) 08385 (*i2).last_changed=1; 08386 { 08387 bool reject=false; 08388 if((*i2).minimal_botnet_version>(*i1)->supported_proto_version) 08389 reject=true; 08390 string obj=(string)"PROC "+(*i2).name; 08391 vector<string>::iterator i2; 08392 for(i2=(*i1)->rejected_objects.begin(); i2!=(*i1)->rejected_objects.end(); i2++) { 08393 if(!(*i2).compare(obj)) { 08394 reject=true; 08395 break; 08396 } 08397 } 08398 if(reject) 08399 continue; 08400 } 08401 s_proc_to_push p; 08402 p.botname=(*i1)->botname; 08403 p.proc_name=(*i2).name; 08404 vector<string> groups; 08405 //logic_list_proc((*i2).name,p.lines,p.proc_name,groups); 08406 p.last_changed=(*i2).last_changed; 08407 p.proc_name=(*i2).name; 08408 08409 s_bot_command* c=new s_bot_command; 08410 c->hard_clear(); 08411 c->packet_type=PACKET_TYPE_COMMAND; 08412 c->size=sizeof(c); 08413 c->version=1; 08414 c->command=CMD_PUSH_1; 08415 c->command_data.check_time_1.now=(my_time_t)time(NULL); 08416 c->command_data.check_time_1.user=false; 08417 c->command_data.check_time_1.procedure=true; 08418 c->command_data.check_time_1.channel_def=false; 08419 c->command_data.check_time_1.prv=false; 08420 char* proc=c->command_data.check_time_1.object_name; 08421 memset(proc,0,sizeof(c->command_data.check_time_1.object_name)); 08422 strncpy(proc,p.proc_name.c_str(),sizeof(c->command_data.check_time_1.object_name)); 08423 c->command_data.check_time_1.original_time=(my_time_t)p.last_changed; 08424 botnet_send_command(*i1,c); 08425 08426 delete c; 08427 } 08428 } 08429 } 08430 } 08431 08432 if((*i1)->auth_ok && (*i1)->remote_pswd_ok) { 08433 time_t now; 08434 time(&now); 08435 if((*i1)->chans_to_push_last_update+120+25<now) { 08436 time(&(*i1)->chans_to_push_last_update); 08437 08438 /*vector<s_bot*>::iterator i1; 08439 for(i1=bots.begin(); i1!=bots.end(); i1++) {*/ 08440 { 08441 vector<s_channel_def> chans; 08442 logic_get_push_chan_defs((*i1)->botname,chans); 08443 vector<s_channel_def>::iterator i2; 08444 for(i2=chans.begin(); i2!=chans.end(); i2++) { 08445 if((*i2).last_changed==0) 08446 (*i2).last_changed=1; 08447 { 08448 bool reject=false; 08449 string obj=(string)"CHAN "+(*i2).channel_name; 08450 vector<string>::iterator i2; 08451 for(i2=(*i1)->rejected_objects.begin(); i2!=(*i1)->rejected_objects.end(); i2++) { 08452 if(!(*i2).compare(obj)) { 08453 reject=true; 08454 break; 08455 } 08456 } 08457 if(reject) 08458 continue; 08459 } 08460 s_chan_def_to_push ch; 08461 ch.botname=(*i1)->botname; 08462 ch.chan_name=(*i2).channel_name; 08463 vector<string> groups; 08464 ch.last_changed=(*i2).last_changed; 08465 08466 s_bot_command* c=new s_bot_command; 08467 c->hard_clear(); 08468 c->packet_type=PACKET_TYPE_COMMAND; 08469 c->size=sizeof(c); 08470 c->version=1; 08471 c->command=CMD_PUSH_1; 08472 c->command_data.check_time_1.now=(my_time_t)time(NULL); 08473 c->command_data.check_time_1.user=false; 08474 c->command_data.check_time_1.procedure=false; 08475 c->command_data.check_time_1.channel_def=true; 08476 c->command_data.check_time_1.prv=false; 08477 char* chan=c->command_data.check_time_1.object_name; 08478 memset(chan,0,sizeof(c->command_data.check_time_1.object_name)); 08479 strncpy(chan,ch.chan_name.c_str(),sizeof(c->command_data.check_time_1.object_name)); 08480 c->command_data.check_time_1.original_time=(my_time_t)ch.last_changed; 08481 botnet_send_command(*i1,c); 08482 08483 delete c; 08484 } 08485 } 08486 } 08487 } 08488 08489 if((*i1)->auth_ok && (*i1)->remote_pswd_ok && !(*i1)->sent_partyline_users) { 08490 (*i1)->sent_partyline_users=true; 08491 vector<s_botnet_channel>::iterator i2; 08492 for(i2=botnet_channels.begin(); i2!=botnet_channels.end(); i2++) { 08493 vector<s_partyline_member>::iterator i3; 08494 for(i3=(*i2).members.begin(); i3!=(*i2).members.end(); i3++) { 08495 s_bot_command* c=new s_bot_command; 08496 c->hard_clear(); 08497 08498 c->packet_type=PACKET_TYPE_COMMAND; 08499 c->size=sizeof(c); 08500 c->version=1; 08501 c->command=CMD_PARTYLINE_USER_1; 08502 08503 c->command_data.cmd_partyline_user_1.id=botnet_get_unique_id(); 08504 08505 int user_size=sizeof(c->command_data.cmd_partyline_user_1.user); 08506 int ch_size=sizeof(c->command_data.cmd_partyline_user_1.channel); 08507 int bn_size=sizeof(c->command_data.cmd_partyline_user_1.botname); 08508 strncpy(c->command_data.cmd_partyline_user_1.user,(*i3).user.c_str(),user_size); 08509 strncpy(c->command_data.cmd_partyline_user_1.channel,(*i2).channel_name.c_str(),ch_size); 08510 strncpy(c->command_data.cmd_partyline_user_1.botname,(*i3).botname.c_str(),bn_size); 08511 08512 botnet_send_command(*i1,c); 08513 08514 botnet_partyline_event(botnet_botname,c); 08515 08516 delete c; 08517 } 08518 } 08519 } 08520 08521 if((*i1)->auth_ok && (*i1)->remote_pswd_ok) { 08522 time_t now; 08523 time(&now); 08524 if((*i1)->prv_to_push_last_update+120-10<now) { 08525 time(&(*i1)->prv_to_push_last_update); 08526 08527 vector<s_replication>::iterator i2; 08528 bool skip=true; 08529 for(i2=r_private.replication.begin(); i2!=r_private.replication.end(); i2++) { 08530 if(!(*i2).partner.compare((*i1)->botname) && ((*i2).type==REPL_PUSH || (*i2).type==REPL_PUSHPULL)) { 08531 skip=false; 08532 break; 08533 } 08534 } 08535 { 08536 bool reject=false; 08537 string obj=(string)"PRIV"; 08538 vector<string>::iterator i2; 08539 for(i2=(*i1)->rejected_objects.begin(); i2!=(*i1)->rejected_objects.end(); i2++) { 08540 if(!(*i2).compare(obj)) { 08541 reject=true; 08542 break; 08543 } 08544 } 08545 if(reject) 08546 skip=true; 08547 } 08548 08549 if(!skip) { 08550 (*i1)->prv_to_push=r_private; 08551 if(r_private.last_changed==0) 08552 r_private.last_changed=1; 08553 s_bot_command* c=new s_bot_command; 08554 c->hard_clear(); 08555 c->packet_type=PACKET_TYPE_COMMAND; 08556 c->size=sizeof(c); 08557 c->version=1; 08558 c->command=CMD_CHECK_TIME_1; 08559 c->command_data.check_time_1.now=(my_time_t)time(NULL); 08560 c->command_data.check_time_1.user=false; 08561 c->command_data.check_time_1.procedure=false; 08562 c->command_data.check_time_1.channel_def=false; 08563 c->command_data.check_time_1.prv=true; 08564 c->command_data.check_time_1.original_time=(my_time_t)(*i1)->prv_to_push.last_changed; 08565 botnet_send_command(*i1,c); 08566 08567 delete c; 08568 } 08569 } 08570 } 08571 } 08572 } 08573 08574 }
Here is the call graph for this function: ![]() |
|
Called from partyline, when user connected to this bot is joining partline channel.
Definition at line 8650 of file botnet.cpp. References s_partyline_member::botname, s_bot_command::u_commnd_data::s_cmd_partyline_1::botname, botnet_botname, botnet_channels, botnet_get_unique_id(), botnet_partyline_event(), botnet_send_command(), bots, s_bot_command::u_commnd_data::s_cmd_partyline_1::channel, s_botnet_channel::channel_name, s_bot_command::u_commnd_data::cmd_partyline_1, CMD_PARTYLINE_1, s_bot_command::command, s_bot_command::command_data, s_bot_command::hard_clear(), s_bot_command::u_commnd_data::s_cmd_partyline_1::id, s_bot_command::u_commnd_data::s_cmd_partyline_1::join, s_bot_command::u_commnd_data::s_cmd_partyline_1::leave, s_bot_command::u_commnd_data::s_cmd_partyline_1::msg, s_bot_command::packet_type, PACKET_TYPE_COMMAND, s_bot_command::size, s_partyline_member::user, s_bot_command::u_commnd_data::s_cmd_partyline_1::user, and s_bot_command::version. Referenced by dcc_loop(). 08651 { 08652 s_bot_command* c=new s_bot_command; 08653 c->hard_clear(); 08654 c->packet_type=PACKET_TYPE_COMMAND; 08655 c->size=sizeof(c); 08656 c->version=1; 08657 c->command=CMD_PARTYLINE_1; 08658 08659 c->command_data.cmd_partyline_1.id=botnet_get_unique_id(); 08660 08661 c->command_data.cmd_partyline_1.msg=false; 08662 c->command_data.cmd_partyline_1.join=true; 08663 c->command_data.cmd_partyline_1.leave=false; 08664 08665 int user_size=sizeof(c->command_data.cmd_partyline_1.user); 08666 int ch_size=sizeof(c->command_data.cmd_partyline_1.channel); 08667 int bn_size=sizeof(c->command_data.cmd_partyline_1.botname); 08668 strncpy(c->command_data.cmd_partyline_1.user,user.c_str(),user_size); 08669 strncpy(c->command_data.cmd_partyline_1.channel,channel.c_str(),ch_size); 08670 strncpy(c->command_data.cmd_partyline_1.botname,botnet_botname,bn_size); 08671 08672 char* ch=new char[ch_size+1]; 08673 memset(ch,0,ch_size+1); 08674 strncpy(ch,channel.c_str(),ch_size); 08675 bool got=false; 08676 again: 08677 vector<s_botnet_channel>::iterator i2; 08678 for(i2=botnet_channels.begin(); i2!=botnet_channels.end(); i2++) 08679 if(!(*i2).channel_name.compare(ch)) { 08680 got=true; 08681 break; 08682 } 08683 if(!got) { 08684 s_botnet_channel c; 08685 c.channel_name=ch; 08686 botnet_channels.push_back(c); 08687 goto again; 08688 } 08689 s_partyline_member me; 08690 delete[] ch; 08691 ch=new char[user_size+1]; 08692 memset(ch,0,user_size+1); 08693 strncpy(ch,user.c_str(),user_size); 08694 me.user=ch; 08695 delete[] ch; 08696 me.botname=botnet_botname; 08697 (*i2).members.push_back(me); 08698 08699 bool at_least_one=false; 08700 vector<s_bot*>::iterator i1; 08701 for(i1=bots.begin(); i1!=bots.end(); i1++) 08702 if((*i1)->socket.cmp() && (*i1)->auth_ok && (*i1)->remote_pswd_ok) { 08703 at_least_one=true; 08704 botnet_send_command(*i1,c); 08705 } 08706 08707 //if(!at_least_one) 08708 botnet_partyline_event(botnet_botname,c); 08709 08710 string users; 08711 vector<s_partyline_member>::iterator i3; 08712 for(i3=(*i2).members.begin(); i3!=(*i2).members.end(); i3++) { 08713 if(users.compare("")) 08714 users+=", "; 08715 users+=(*i3).user; 08716 users+="@"; 08717 users+=(*i3).botname; 08718 } 08719 08720 delete c; 08721 08722 return users; 08723 }
Here is the call graph for this function: ![]() |
|
Called from partyline, when user connected to this bot is leaving partline channel.
Definition at line 8733 of file botnet.cpp. References s_bot_command::u_commnd_data::s_cmd_partyline_1::botname, botnet_botname, botnet_channels, botnet_get_unique_id(), botnet_partyline_event(), botnet_send_command(), bots, s_bot_command::u_commnd_data::s_cmd_partyline_1::channel, s_bot_command::u_commnd_data::cmd_partyline_1, CMD_PARTYLINE_1, s_bot_command::command, s_bot_command::command_data, s_bot_command::hard_clear(), s_bot_command::u_commnd_data::s_cmd_partyline_1::id, s_bot_command::u_commnd_data::s_cmd_partyline_1::join, s_bot_command::u_commnd_data::s_cmd_partyline_1::leave, s_bot_command::u_commnd_data::s_cmd_partyline_1::msg, s_bot_command::packet_type, PACKET_TYPE_COMMAND, s_bot_command::size, s_bot_command::u_commnd_data::s_cmd_partyline_1::user, and s_bot_command::version. Referenced by dcc_loop(). 08734 { 08735 s_bot_command* c=new s_bot_command; 08736 c->hard_clear(); 08737 c->packet_type=PACKET_TYPE_COMMAND; 08738 c->size=sizeof(c); 08739 c->version=1; 08740 c->command=CMD_PARTYLINE_1; 08741 08742 c->command_data.cmd_partyline_1.id=botnet_get_unique_id(); 08743 08744 c->command_data.cmd_partyline_1.msg=false; 08745 c->command_data.cmd_partyline_1.join=false; 08746 c->command_data.cmd_partyline_1.leave=true; 08747 08748 int user_size=sizeof(c->command_data.cmd_partyline_1.user); 08749 int ch_size=sizeof(c->command_data.cmd_partyline_1.channel); 08750 int bn_size=sizeof(c->command_data.cmd_partyline_1.botname); 08751 strncpy(c->command_data.cmd_partyline_1.user,user.c_str(),user_size); 08752 strncpy(c->command_data.cmd_partyline_1.channel,channel.c_str(),ch_size); 08753 strncpy(c->command_data.cmd_partyline_1.botname,botnet_botname,bn_size); 08754 08755 char* ch=new char[ch_size+1]; 08756 memset(ch,0,ch_size+1); 08757 strncpy(ch,channel.c_str(),ch_size); 08758 bool got=false; 08759 vector<s_botnet_channel>::iterator i2; 08760 for(i2=botnet_channels.begin(); i2!=botnet_channels.end(); i2++) 08761 if(!(*i2).channel_name.compare(ch)) { 08762 got=true; 08763 break; 08764 } 08765 if(got) { 08766 bool got2=false; 08767 vector<s_partyline_member>::iterator i3; 08768 for(i3=(*i2).members.begin(); i3!=(*i2).members.end(); i3++) 08769 if(!(*i3).user.compare(user) && !(*i3).botname.compare(botnet_botname)) { 08770 got2=true; 08771 break; 08772 } 08773 if(got2) 08774 (*i2).members.erase(i3); 08775 if((*i2).members.empty()) 08776 botnet_channels.erase(i2); 08777 } 08778 08779 bool at_least_one=false; 08780 vector<s_bot*>::iterator i1; 08781 for(i1=bots.begin(); i1!=bots.end(); i1++) 08782 if((*i1)->socket.cmp() && (*i1)->auth_ok && (*i1)->remote_pswd_ok) { 08783 at_least_one=true; 08784 botnet_send_command(*i1,c); 08785 } 08786 08787 //if(!at_least_one) 08788 botnet_partyline_event(botnet_botname,c); 08789 08790 delete c; 08791 }
Here is the call graph for this function: ![]() |
|
Called from partyline, when user connected to this bot is writing a message to partline channel.
Definition at line 8802 of file botnet.cpp. References botnet_get_unique_id(), and botnet_partyline_message(). 08803 { 08804 botnet_partyline_message(user, channel, msg, botnet_get_unique_id()); 08805 }
Here is the call graph for this function: ![]() |
|
Called when remote bot connects via telnet.
Definition at line 8588 of file botnet.cpp. References s_bot::auth_ok, s_bot::botip, s_bot::botname, s_bot::botport, bots, s_bot::buff_from_dcc, s_bot::buff_pos_from_dcc, s_bot::buff_size_from_dcc, s_bot::clean, s_socket::clear(), s_bot::clear(), dcc_get_password(), s_bot::got_bytes, s_bot::invoked_from_telnet, s_bot::last_try, s_bot::localip, s_bot::receive_buffer_pos, s_bot::received_bot_auth_1, s_bot::remote_MD5_password, s_bot::remote_pswd_ok, s_bot::sent_bot_auth_1, s_bot::socket, s_bot::ssl, s_bot::ssl_connection, stats_botnet_bytes_received(), stats_botnet_new_connection(), s_bot::unlink_proc, s_bot::unlink_proc_called, and s_bot::was_linked. Referenced by dcc_loop(). 08589 { 08590 stats_botnet_new_connection(); 08591 stats_botnet_bytes_received(buff_size); 08592 08593 vector<s_bot*>::iterator i1; 08594 bool got=false; 08595 for(i1=bots.begin(); i1!=bots.end(); i1++) { 08596 if(!(*i1)->botname.compare(botname)) 08597 if((*i1)->socket==socket) { 08598 got=true; 08599 break; 08600 } 08601 } 08602 if(!got) { 08603 s_bot* s=new s_bot; 08604 s->clear(); 08605 s->clean=false; 08606 s->ssl_connection=ssl?true:false; 08607 s->ssl=ssl; 08608 s->botname=""; 08609 s->localip=""; 08610 s->botip=remote_ip; 08611 s->botport=0; 08612 s->socket.clear(); 08613 s->remote_MD5_password=""; 08614 s->sent_bot_auth_1=false; 08615 s->received_bot_auth_1=false; 08616 s->receive_buffer_pos=0; 08617 s->botname=botname; 08618 s->socket=socket; 08619 s->remote_MD5_password=dcc_get_password(botname); 08620 s->buff_size_from_dcc=0; 08621 if(buff_size) { 08622 s->buff_size_from_dcc=buff_size; 08623 if(s->buff_size_from_dcc>sizeof(s->buff_from_dcc)) 08624 s->buff_size_from_dcc=sizeof(s->buff_from_dcc); 08625 memcpy(s->buff_from_dcc,buff,s->buff_size_from_dcc); 08626 s->buff_pos_from_dcc=0; 08627 } 08628 08629 s->unlink_proc=""; 08630 s->unlink_proc_called=true; 08631 08632 s->got_bytes=0; 08633 s->auth_ok=false; 08634 s->remote_pswd_ok=false; 08635 s->last_try=0x7FFFFFFF; 08636 s->invoked_from_telnet=true; 08637 s->was_linked=false; 08638 bots.push_back(s); 08639 } 08640 }
Here is the call graph for this function: ![]() |
|
Sends to other bot remote procedure call request.
Definition at line 1629 of file botnet.cpp. References s_bot_command::u_commnd_data::s_cmd_remote_procedure_call_3::args_array, botnet_send_command(), bots, s_bot_command::u_commnd_data::cmd_remote_procedure_call_3, CMD_REMOTE_PROCEDURE_CALL_3, s_bot_command::command, s_bot_command::command_data, s_bot_command::hard_clear(), index(), s_bot_command::u_commnd_data::s_cmd_remote_procedure_call_3::num_args, s_bot_command::packet_type, PACKET_TYPE_COMMAND, s_bot_command::size, and s_bot_command::version. Referenced by logic_exec(). 01630 { 01631 bool got=false; 01632 vector<s_bot*>::iterator i1; 01633 for(i1=bots.begin(); i1!=bots.end(); i1++) 01634 if(!(*i1)->botname.compare(botname)) { 01635 got=true; 01636 break; 01637 } 01638 if(!got) 01639 return "@not_linked@"; 01640 if(!(*i1)->auth_ok || !(*i1)->remote_pswd_ok) 01641 return "@not_linked@"; 01642 if((*i1)->supported_proto_version<3) 01643 return "@remote_not_supported@"; 01644 01645 s_bot_command* c=new s_bot_command; 01646 c->hard_clear(); 01647 c->packet_type=PACKET_TYPE_COMMAND; 01648 c->size=sizeof(c); 01649 c->version=3; 01650 c->command=CMD_REMOTE_PROCEDURE_CALL_3; 01651 01652 unsigned int index=0; 01653 01654 c->command_data.cmd_remote_procedure_call_3.num_args=1; // first "argument" is actually the name of procedure 01655 // +1 == binary zero delimiter/terminator 01656 if(index+proc_name_only.length()+1>=sizeof(c->command_data.cmd_remote_procedure_call_3.args_array)) { 01657 delete c; 01658 return "@args_too_long@"; 01659 } 01660 memcpy(&(c->command_data.cmd_remote_procedure_call_3.args_array[index]),proc_name_only.c_str(),proc_name_only.length()); 01661 index+=(unsigned int)proc_name_only.length(); 01662 c->command_data.cmd_remote_procedure_call_3.args_array[index]=0; 01663 index++; 01664 01665 list<string>::iterator i2; 01666 for(i2=args.begin(); i2!=args.end(); i2++) { 01667 c->command_data.cmd_remote_procedure_call_3.num_args++; 01668 // +1 == binary zero delimiter/terminator 01669 if(index+(*i2).length()+1>=sizeof(c->command_data.cmd_remote_procedure_call_3.args_array)) { 01670 delete c; 01671 return "@args_too_long@"; 01672 } 01673 memcpy(&(c->command_data.cmd_remote_procedure_call_3.args_array[index]),(*i2).c_str(),(*i2).length()); 01674 index+=(unsigned int)(*i2).length(); 01675 c->command_data.cmd_remote_procedure_call_3.args_array[index]=0; 01676 index++; 01677 } 01678 botnet_send_command(*i1,c); 01679 delete c; 01680 01681 return "@ok@"; 01682 }
Here is the call graph for this function: ![]() |
|
Used for partyline to show connected bots (.showbots).
Definition at line 8879 of file botnet.cpp. References bots, and lang_get_string(). Referenced by dcc_loop(). 08880 { 08881 string res; 08882 res+=lang_get_string(1,lang,649)+eol; 08883 vector<s_bot*>::iterator i1; 08884 for(i1=bots.begin(); i1!=bots.end(); i1++) 08885 if((*i1)->socket.cmp() && (*i1)->auth_ok && (*i1)->remote_pswd_ok) { 08886 res+=(*i1)->botname; 08887 res+=" "; 08888 res+=lang_get_string(1,lang,650)+eol; 08889 } else { 08890 res+=(*i1)->botname; 08891 res+=" "; 08892 res+=lang_get_string(1,lang,651)+eol; 08893 } 08894 08895 res+=lang_get_string(1,lang,652)+eol; 08896 08897 return res; 08898 }
Here is the call graph for this function: ![]() |