00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <time.h>
00038 #include <string.h>
00039 #include <stdio.h>
00040 #include <string>
00041 #include <vector>
00042 #include <map>
00043
00044 #ifndef _WIN32
00045 # include <sys/time.h>
00046 # include <sys/types.h>
00047 # include <unistd.h>
00048 #endif
00049
00050 #include "sock.h"
00051 #include "md5.h"
00052 #include "dcc.h"
00053 #include "log.h"
00054 #include "conf.h"
00055 #include "rle.h"
00056 #include "stats.h"
00057 #include "ssl.h"
00058 #include "lang.h"
00059 #include "match.h"
00060
00061 #include "params.h"
00062
00063 #pragma hdrstop
00064
00065 using namespace std;
00066
00067 #include "botnet.h"
00068
00069 #ifdef __BORLANDC__
00070 #pragma package(smart_init)
00071 #endif
00072
00073 #include "shared.h"
00074
00075 #ifdef _MSC_VER
00076 #define __FUNC__ __FUNCTION__
00077 #endif
00078
00079 #ifdef __GNUC__
00080 #define __FUNC__ "<unknown>"
00081 #endif
00082
00083 #ifdef __alpha
00084 typedef unsigned int uint32;
00085 #else
00086 typedef unsigned long uint32;
00087 #endif
00088
00089 typedef unsigned char my_bool;
00090 typedef uint32 my_time_t;
00091
00092 #ifndef _WIN32
00093 #ifndef HAVE_LTOA
00094 extern char *ltoa(long value, char *buffer, int radix);
00095 #endif
00096 #endif
00097
00098 void botnet_partyline_message(string user, string channel, string msg, uint32 id);
00099
00100
00101
00102
00103
00104
00105
00106 struct s_user_to_pull {
00107 string botname;
00108 s_user user;
00109
00110 s_user_to_pull()
00111 {
00112 botname="";
00113 }
00114 };
00115
00116
00117
00118
00119
00120
00121
00122 struct s_user_to_push {
00123 string botname;
00124 s_user user;
00125
00126 s_user_to_push()
00127 {
00128 botname="";
00129 }
00130 };
00131
00132
00133
00134
00135
00136
00137
00138 struct s_proc_to_pull {
00139 string botname;
00140 string proc_name;
00141 time_t last_changed;
00142 list<string> lines;
00143 vector<s_replication> replication;
00144 vector<string> orig_groups;
00145
00146 s_proc_to_pull()
00147 {
00148 botname="";
00149 proc_name="";
00150 last_changed=0;
00151 lines.clear();
00152 replication.clear();
00153 orig_groups.clear();
00154 }
00155 };
00156
00157
00158
00159
00160
00161
00162
00163 struct s_proc_to_push {
00164 string botname;
00165 string proc_name;
00166 time_t last_changed;
00167
00168 s_proc_to_push()
00169 {
00170 botname="";
00171 proc_name="";
00172 last_changed=0;
00173 }
00174 };
00175
00176
00177
00178
00179
00180
00181
00182 struct s_chan_def_to_push {
00183 string botname;
00184 string chan_name;
00185 time_t last_changed;
00186 s_channel_def chd;
00187
00188 s_chan_def_to_push()
00189 {
00190 botname="";
00191 chan_name="";
00192 last_changed=0;
00193 }
00194 };
00195
00196
00197
00198
00199
00200
00201
00202 struct s_chan_def_to_pull {
00203 string botname;
00204 string chan_name;
00205 time_t last_changed;
00206 s_channel_def chd;
00207
00208 s_chan_def_to_pull()
00209 {
00210 botname="";
00211 chan_name="";
00212 last_changed=0;
00213 }
00214 };
00215
00216 extern void sleep(int ms);
00217
00218 extern bool logic_botnet_get_user(string name, s_user& user);
00219 extern void logic_get_pull_users(string botname, vector<s_user>& users);
00220 extern void logic_get_push_users(string botname, vector<s_user>& users);
00221 extern void logic_get_pull_procs(string botname, vector<s_procedure>& procs);
00222 extern void logic_get_push_procs(string botname, vector<s_procedure>& procs);
00223 extern bool logic_botnet_get_user_channels(string name, vector<s_channel>& channels);
00224 extern bool logic_botnet_get_proc(string name, s_procedure& proc);
00225 extern void logic_get_pull_chan_defs(string botname, vector<s_channel_def>& chans);
00226 extern void logic_get_push_chan_defs(string botname, vector<s_channel_def>& chans);
00227 extern bool logic_botnet_get_channel_def(string channel_name, s_channel_def& chd);
00228 extern void logic_botnet_remove_channel_def(string channel_name);
00229 extern vector<s_user> r_users;
00230 extern vector<s_user> r_user_templates;
00231 extern vector<s_user> r_terminators;
00232 extern vector<s_channel> r_channels;
00233 extern vector<s_channel> r_channel_templates;
00234 extern vector<s_channel> r_channel_terminators;
00235 extern vector<s_procedure> r_procedures;
00236 extern vector<s_channel_def> r_channel_defs;
00237 extern s_private r_private;
00238
00239 extern s_ssl_conf ssl_conf;
00240
00241 char botnet_botname[256];
00242
00243 int botnet_penalty=-1;
00244
00245 int ping_time=30;
00246
00247 #define SUPPORTED_PROTO_VERSION 11
00248
00249 #if defined(__GNUC__)
00250 # define PACK_STRUCT __attribute__((packed))
00251 # define MSVC_ALIGN1
00252 # pragma align 1
00253 #elif defined(_MSC_VER)
00254 # define PACK_STRUCT
00255 # define MSVC_ALIGN1 __declspec(align(1))
00256 #endif
00257
00258
00259
00260
00261
00262
00263
00264 MSVC_ALIGN1 struct s_bot_control {
00265
00266
00267
00268
00269 #define PACKET_TYPE_CONTROL 1
00270 uint32 packet_type;
00271 uint32 size;
00272 uint32 supported_proto_version;
00273 uint32 control;
00274
00275
00276
00277
00278
00279 #define CTRL_ERROR_001 1L
00280
00281
00282
00283
00284
00285 #define CTRL_ERROR_002 2L
00286
00287
00288
00289
00290
00291 #define CTRL_LINKED 3L
00292
00293
00294
00295
00296
00297 #define CTRL_PING 4L
00298
00299
00300
00301
00302
00303 #define CTRL_PONG 5L
00304
00305
00306
00307
00308
00309
00310
00311 MSVC_ALIGN1 union u_control_data {
00312 char padding[1024*4-sizeof(uint32)*4];
00313 } control_data;
00314
00315 s_bot_control()
00316 {
00317 memset(this,0,sizeof(*this));
00318 }
00319
00320 void flip_header()
00321 {
00322 byteReverse((unsigned char*)this,4);
00323 }
00324 void flip_rest()
00325 {
00326 }
00327
00328 void hard_clear()
00329 {
00330 memset(this,0,sizeof(*this));
00331 }
00332 } PACK_STRUCT;
00333
00334 #ifdef __BORLANDC__
00335 #if sizeof(s_bot_control)!=1024*4
00336 # error sizeof(s_bot_control) MUST be equal to 1024*4 bytes long in any case! use padding member for size correction!
00337 #endif
00338 #endif
00339
00340
00341
00342
00343
00344
00345
00346 MSVC_ALIGN1 struct s_bot_command {
00347
00348
00349
00350
00351 #define PACKET_TYPE_COMMAND 2
00352 uint32 packet_type;
00353 uint32 size;
00354 uint32 version;
00355 uint32 command;
00356
00357
00358
00359
00360
00361
00362 MSVC_ALIGN1 union u_commnd_data {
00363
00364
00365
00366
00367 #define CMD_AUTH_1 10001L
00368
00369
00370
00371
00372
00373
00374 MSVC_ALIGN1 struct s_bot_auth_1 {
00375 char botname[256];
00376 unsigned char digest[32+1];
00377 } PACK_STRUCT bot_auth_1;
00378
00379
00380
00381
00382 #define CMD_CHECK_TIME_1 10002L
00383
00384
00385
00386
00387
00388
00389 MSVC_ALIGN1 struct s_check_time_1 {
00390 my_time_t now;
00391 my_bool user;
00392 my_bool procedure;
00393 my_bool channel_def;
00394 my_bool prv;
00395 char object_name[1024];
00396 my_time_t original_time;
00397 } PACK_STRUCT check_time_1;
00398
00399
00400
00401
00402 #define CMD_NO_REPL_1 10003L
00403
00404
00405
00406
00407
00408
00409 MSVC_ALIGN1 struct s_no_repl_1 {
00410 my_bool user;
00411 my_bool procedure;
00412 my_bool channel_def;
00413 my_bool prv;
00414 char object_name[1024];
00415
00416
00417
00418
00419 # define REASON_NO_REPL_1_UP_TO_DATE 1
00420
00421
00422
00423
00424
00425 # define REASON_NO_REPL_1_ACCESS_DENIED 2
00426 uint32 reason;
00427 } PACK_STRUCT no_repl_1;
00428
00429
00430
00431
00432 #define CMD_REPL_USER_01_1 10004L
00433
00434
00435
00436
00437
00438
00439 MSVC_ALIGN1 struct s_cmd_repl_user_01_1 {
00440 char name[256];
00441 my_bool host_unknown;
00442 my_bool host_bot;
00443 my_bool is_template;
00444 my_bool terminator;
00445 my_bool access_grant_partyline;
00446 my_bool access_to_backup;
00447 my_bool access_grant_backup;
00448 my_bool access_to_rehash;
00449 my_bool access_grant_rehash;
00450 my_bool access_to_partyline;
00451 my_bool access_to_plususer;
00452 my_bool access_grant_plususer;
00453 my_bool access_to_plusproc;
00454 my_bool access_grant_plusproc;
00455 my_bool access_to_can_send_all_users;
00456 my_bool access_grant_can_send_all_users;
00457 my_bool access_to_can_send_unknown_users;
00458 my_bool access_grant_can_send_unknown_users;
00459 s_flood partyline_msg_flood;
00460 my_time_t last_changed;
00461 } PACK_STRUCT cmd_repl_user_01_1;
00462
00463
00464
00465
00466 #define CMD_REPL_USER_02_1 10005L
00467
00468
00469
00470
00471
00472
00473 MSVC_ALIGN1 struct s_cmd_repl_user_02_1 {
00474 char name[256];
00475 char hostmask[1024];
00476 } PACK_STRUCT cmd_repl_user_02_1;
00477
00478
00479
00480
00481 #define CMD_REPL_USER_03_1 10006L
00482
00483
00484
00485
00486
00487
00488 MSVC_ALIGN1 struct s_cmd_repl_user_03_1 {
00489 char name[256];
00490 char fullname[1024];
00491 } PACK_STRUCT cmd_repl_user_03_1;
00492
00493
00494
00495
00496 #define CMD_REPL_USER_04_1 10007L
00497
00498
00499
00500
00501
00502
00503 MSVC_ALIGN1 struct s_cmd_repl_user_04_1 {
00504 char name[256];
00505 char access_to_group[256];
00506 } PACK_STRUCT cmd_repl_user_04_1;
00507
00508
00509
00510
00511 #define CMD_REPL_USER_05_1 10008L
00512
00513
00514
00515
00516
00517
00518 MSVC_ALIGN1 struct s_cmd_repl_user_05_1 {
00519 char name[256];
00520 char access_to_proc[256];
00521 } PACK_STRUCT cmd_repl_user_05_1;
00522
00523
00524
00525
00526 #define CMD_REPL_USER_06_1 10009L
00527
00528
00529
00530
00531
00532
00533 MSVC_ALIGN1 struct s_cmd_repl_user_06_1 {
00534 char name[256];
00535 char access_grant_proc[256];
00536 } PACK_STRUCT cmd_repl_user_06_1;
00537
00538
00539
00540
00541 #define CMD_REPL_USER_07_1 10010L
00542
00543
00544
00545
00546
00547
00548 MSVC_ALIGN1 struct s_cmd_repl_user_07_1 {
00549 char name[256];
00550 char access_grant_group[256];
00551 } PACK_STRUCT cmd_repl_user_07_1;
00552
00553
00554
00555
00556 #define CMD_REPL_USER_08_1 10011L
00557
00558
00559
00560
00561
00562
00563 MSVC_ALIGN1 struct s_cmd_repl_user_08_1 {
00564 char name[256];
00565 char access_to_channel[1024];
00566 } PACK_STRUCT cmd_repl_user_08_1;
00567
00568
00569
00570
00571 #define CMD_REPL_USER_09_1 10012L
00572
00573
00574
00575
00576
00577
00578 MSVC_ALIGN1 struct s_cmd_repl_user_09_1 {
00579 char name[256];
00580 char access_grant_channel[1024];
00581 } PACK_STRUCT cmd_repl_user_09_1;
00582
00583
00584
00585
00586 #define CMD_REPL_USER_10_1 10013L
00587
00588
00589
00590
00591
00592
00593 MSVC_ALIGN1 struct s_cmd_repl_user_10_1 {
00594 char name[256];
00595 char group[1024];
00596 } PACK_STRUCT cmd_repl_user_10_1;
00597
00598
00599
00600
00601 #define CMD_REPL_USER_11_1 10014L
00602
00603
00604
00605
00606
00607
00608 MSVC_ALIGN1 struct s_cmd_repl_user_11_1 {
00609 char name[256];
00610 uint32 dcc_group;
00611 char dcc_host[1024];
00612 } PACK_STRUCT cmd_repl_user_11_1;
00613
00614
00615
00616
00617 #define CMD_REPL_USER_12_1 10015L
00618
00619
00620
00621
00622
00623
00624 MSVC_ALIGN1 struct s_cmd_repl_user_12_1 {
00625 char name[256];
00626 char channel[1024];
00627 char on_deop[1024];
00628 char on_ban[1024];
00629 char on_unban[1024];
00630 char on_kick[1024];
00631 char on_op[1024];
00632 char on_voice[1024];
00633 char on_devoice[1024];
00634 char on_creator[1024];
00635 char on_decreator[1024];
00636 char on_join[1024];
00637 char on_banned[1024];
00638 char on_flood[1024];
00639 char on_privmsg[1024];
00640 char on_notice[1024];
00641 char on_except[1024];
00642 char on_unexcept[1024];
00643 char on_invite[1024];
00644 char on_uninvite[1024];
00645 char on_not_invited[1024];
00646 char on_not_in_reop[1024];
00647 char on_reop[1024];
00648 uint32 msg_flood_l;
00649 my_time_t msg_flood_s;
00650 uint32 notice_flood_l;
00651 my_time_t notice_flood_s;
00652 uint32 repeat_flood_l;
00653 my_time_t repeat_flood_s;
00654 uint32 nick_flood_l;
00655 my_time_t nick_flood_s;
00656 uint32 join_flood_l;
00657 my_time_t join_flood_s;
00658 uint32 mode_flood_l;
00659 my_time_t mode_flood_s;
00660 uint32 ctcp_flood_l;
00661 my_time_t ctcp_flood_s;
00662 char dynamic_plus_modes[128];
00663 char dynamic_minus_modes[128];
00664 my_bool can_send_unknown_users;
00665 } PACK_STRUCT cmd_repl_user_12_1;
00666
00667
00668
00669
00670 #define CMD_REPL_USER_13_1 10016L
00671
00672
00673
00674
00675
00676
00677 MSVC_ALIGN1 struct s_cmd_repl_user_13_1 {
00678 char name[256];
00679 char channel[1024];
00680 char group[256];
00681 char plus_modes[256];
00682 char minus_modes[256];
00683 } PACK_STRUCT cmd_repl_user_13_1;
00684
00685
00686
00687
00688 #define CMD_REPL_USER_14_1 10017L
00689
00690
00691
00692
00693
00694
00695 MSVC_ALIGN1 struct s_cmd_repl_user_14_1 {
00696 char name[256];
00697 char meta_key[1024];
00698 char meta_val[1024];
00699 } PACK_STRUCT cmd_repl_user_14_1;
00700
00701
00702
00703
00704 #define CMD_REPL_USER_15_1 10018L
00705
00706
00707
00708
00709
00710
00711 MSVC_ALIGN1 struct s_cmd_repl_user_15_1 {
00712 char name[256];
00713 char access_usage_proc[256];
00714 } PACK_STRUCT cmd_repl_user_15_1;
00715
00716
00717
00718
00719
00720 #define CMD_REPL_USER_16_5 50001L
00721
00722
00723
00724
00725
00726
00727
00728 MSVC_ALIGN1 struct s_cmd_repl_user_16_5 {
00729 char name[256];
00730 my_bool access_to_upgrade;
00731 my_bool access_grant_upgrade;
00732 } PACK_STRUCT cmd_repl_user_16_5;
00733
00734
00735
00736
00737
00738 #define CMD_REPL_USER_17_9 90001L
00739
00740
00741
00742
00743
00744
00745
00746 MSVC_ALIGN1 struct s_cmd_repl_user_17_9 {
00747 char name[256];
00748 my_bool access_to_apply;
00749 my_bool access_grant_apply;
00750 } PACK_STRUCT cmd_repl_user_17_9;
00751
00752
00753
00754
00755 #define CMD_REPL_USER_99_1 10019L
00756
00757
00758
00759
00760
00761
00762 MSVC_ALIGN1 struct s_cmd_repl_user_99_1 {
00763 char name[256];
00764 } PACK_STRUCT cmd_repl_user_99_1;
00765
00766
00767
00768
00769 #define CMD_PUSH_1 10020L
00770
00771
00772
00773
00774
00775
00776 MSVC_ALIGN1 struct s_cmd_push_1 {
00777 my_time_t now;
00778 my_bool user;
00779 my_bool procedure;
00780 my_bool channel_def;
00781 my_bool prv;
00782 char object_name[1024];
00783 my_time_t original_time;
00784 } PACK_STRUCT cmd_push_1;
00785
00786
00787
00788
00789 #define CMD_PROC_1 10021L
00790
00791
00792
00793
00794
00795
00796 MSVC_ALIGN1 struct s_cmd_proc_1 {
00797 char name[1024];
00798 my_bool init;
00799 char line[1024*2];
00800 my_time_t last_changed;
00801 } PACK_STRUCT cmd_proc_1;
00802
00803
00804
00805
00806 #define CMD_PROC_END_1 10022L
00807
00808
00809
00810
00811
00812
00813 MSVC_ALIGN1 struct s_cmd_proc_end_1 {
00814 char name[1024];
00815 } PACK_STRUCT cmd_proc_end_1;
00816
00817
00818
00819
00820 #define CMD_PARTYLINE_1 10023L
00821
00822
00823
00824
00825
00826
00827 MSVC_ALIGN1 struct s_cmd_partyline_1 {
00828 uint32 id;
00829 char user[256];
00830 my_bool msg;
00831 char message[1024];
00832 my_bool join;
00833 my_bool leave;
00834 char channel[1024];
00835 char botname[256];
00836 } PACK_STRUCT cmd_partyline_1;
00837
00838
00839
00840
00841 #define CMD_PARTYLINE_USER_1 10024L
00842
00843
00844
00845
00846
00847
00848 MSVC_ALIGN1 struct s_cmd_partyline_user_1 {
00849 uint32 id;
00850 char user[256];
00851 char channel[1024];
00852 char botname[256];
00853 } PACK_STRUCT cmd_partyline_user_1;
00854
00855
00856
00857
00858 #define CMD_REPL_CHDEF_01_1 10025L
00859
00860
00861
00862
00863
00864
00865 MSVC_ALIGN1 struct s_cmd_repl_chdef_01_1 {
00866 char name[256];
00867 char on_mode[1024];
00868 char on_key[1024];
00869 char on_limit[1024];
00870 char on_topic[1024];
00871 char on_ircop[1024];
00872 char on_ctcp[1024];
00873 char on_privmsg[1024];
00874 char on_notice[1024];
00875 char on_part[1024];
00876 char on_dynamic_ban[1024];
00877 char dynamic_plus_modes[128];
00878 char dynamic_minus_modes[128];
00879 my_time_t last_changed;
00880 } PACK_STRUCT cmd_repl_chdef_01_1;
00881
00882
00883
00884
00885 #define CMD_REPL_CHDEF_02_1 10026L
00886
00887
00888
00889
00890
00891
00892 MSVC_ALIGN1 struct s_cmd_repl_chdef_02_1 {
00893 char name[256];
00894 char group[1024];
00895 } PACK_STRUCT cmd_repl_chdef_02_1;
00896
00897
00898
00899
00900 #define CMD_REPL_CHDEF_03_1 10027L
00901
00902
00903
00904
00905
00906
00907 MSVC_ALIGN1 struct s_cmd_repl_chdef_03_1 {
00908 char name[256];
00909 char group[256];
00910 char plus_modes[256];
00911 char minus_modes[256];
00912 } PACK_STRUCT cmd_repl_chdef_03_1;
00913
00914
00915
00916
00917 #define CMD_REPL_CHDEF_04_1 10028L
00918
00919
00920
00921
00922
00923
00924 MSVC_ALIGN1 struct s_cmd_repl_chdef_04_1 {
00925 char name[256];
00926 char mask[1024];
00927 char reason[1024];
00928 } PACK_STRUCT cmd_repl_chdef_04_1;
00929
00930
00931
00932
00933 #define CMD_REPL_CHDEF_05_1 10029L
00934
00935
00936
00937
00938
00939
00940 MSVC_ALIGN1 struct s_cmd_repl_chdef_05_1 {
00941 char name[256];
00942 char group[1024];
00943 } PACK_STRUCT cmd_repl_chdef_05_1;
00944
00945
00946
00947
00948
00949 #define CMD_REPL_CHDEF_06_8 80002L
00950
00951
00952
00953
00954
00955
00956
00957 MSVC_ALIGN1 struct s_cmd_repl_chdef_06_8 {
00958 char name[256];
00959 char on_server_msg[1024];
00960 } PACK_STRUCT cmd_repl_chdef_06_8;
00961
00962
00963
00964
00965 #define CMD_REPL_CHDEF_99_1 10030L
00966
00967
00968
00969
00970
00971
00972 MSVC_ALIGN1 struct s_cmd_repl_chdef_99_1 {
00973 char name[256];
00974 } PACK_STRUCT cmd_repl_chdef_99_1;
00975
00976
00977
00978
00979 #define CMD_REPL_PRV_01_1 10031L
00980
00981
00982
00983
00984
00985
00986 MSVC_ALIGN1 struct s_cmd_repl_prv_01_1 {
00987 my_time_t last_changed;
00988 } PACK_STRUCT cmd_repl_prv_01_1;
00989
00990
00991
00992
00993 #define CMD_REPL_PRV_02_1 10032L
00994
00995
00996
00997
00998
00999
01000 MSVC_ALIGN1 struct s_cmd_repl_prv_02_1 {
01001 char group[1024];
01002 } PACK_STRUCT cmd_repl_prv_02_1;
01003
01004
01005
01006
01007 #define CMD_REPL_PRV_03_1 10033L
01008
01009
01010
01011
01012
01013
01014 MSVC_ALIGN1 struct s_cmd_repl_prv_03_1 {
01015 char on_privmsg[1024];
01016 char on_notice[1024];
01017 char on_ctcp[1024];
01018 } PACK_STRUCT cmd_repl_prv_03_1;
01019
01020
01021
01022
01023
01024 #define CMD_REPL_PRV_04_7 70001L
01025
01026
01027
01028
01029
01030
01031
01032 MSVC_ALIGN1 struct s_cmd_repl_prv_04_7 {
01033 char on_filesys_got_new[1024];
01034 char on_fnc[1024];
01035 } PACK_STRUCT cmd_repl_prv_04_7;
01036
01037
01038
01039
01040
01041 #define CMD_REPL_PRV_05_8 80001L
01042
01043
01044
01045
01046
01047
01048
01049 MSVC_ALIGN1 struct s_cmd_repl_prv_05_8 {
01050 char on_broadcast[1024];
01051 char on_server_msg[1024];
01052 } PACK_STRUCT cmd_repl_prv_05_8;
01053
01054
01055
01056
01057
01058 #define CMD_REPL_PRV_06_11 110001L
01059
01060
01061
01062
01063
01064
01065
01066 MSVC_ALIGN1 struct s_cmd_repl_prv_06_11 {
01067 char on_internal_event[1024];
01068 } PACK_STRUCT cmd_repl_prv_06_11;
01069
01070
01071
01072
01073 #define CMD_REPL_PRV_99_1 10034L
01074
01075
01076
01077
01078
01079
01080 MSVC_ALIGN1 struct s_cmd_repl_prv_99_1 {
01081 } PACK_STRUCT cmd_repl_prv_99_1;
01082
01083
01084
01085
01086
01087 #define CMD_REMOTE_PROCEDURE_CALL_3 30001L
01088
01089
01090
01091
01092
01093
01094 MSVC_ALIGN1 struct s_cmd_remote_procedure_call_3 {
01095 uint32 num_args;
01096 char args_array[63*1024];
01097 } PACK_STRUCT cmd_remote_procedure_call_3;
01098
01099
01100
01101
01102
01103
01104
01105 MSVC_ALIGN1 struct s__padding {
01106 char padding[1024*64-sizeof(uint32)*4];
01107 } PACK_STRUCT _padding;
01108 } command_data;
01109
01110 void flip()
01111 {
01112
01113 if(packet_type!=PACKET_TYPE_COMMAND)
01114 return;
01115 switch(command) {
01116 case CMD_AUTH_1:
01117 break;
01118 case CMD_CHECK_TIME_1:
01119 byteReverse((unsigned char*)&command_data.check_time_1.now,1);
01120 byteReverse((unsigned char*)&command_data.check_time_1.original_time,1);
01121 break;
01122 case CMD_NO_REPL_1:
01123 byteReverse((unsigned char*)&command_data.no_repl_1.reason,1);
01124 break;
01125 case CMD_REPL_USER_01_1:
01126 byteReverse((unsigned char*)&command_data.cmd_repl_user_01_1.partyline_msg_flood.lines,1);
01127 byteReverse((unsigned char*)&command_data.cmd_repl_user_01_1.partyline_msg_flood.seconds,1);
01128 byteReverse((unsigned char*)&command_data.cmd_repl_user_01_1.last_changed,1);
01129 break;
01130 case CMD_REPL_USER_02_1:
01131 break;
01132 case CMD_REPL_USER_03_1:
01133 break;
01134 case CMD_REPL_USER_04_1:
01135 break;
01136 case CMD_REPL_USER_05_1:
01137 break;
01138 case CMD_REPL_USER_06_1:
01139 break;
01140 case CMD_REPL_USER_07_1:
01141 break;
01142 case CMD_REPL_USER_08_1:
01143 break;
01144 case CMD_REPL_USER_09_1:
01145 break;
01146 case CMD_REPL_USER_10_1:
01147 break;
01148 case CMD_REPL_USER_11_1:
01149 byteReverse((unsigned char*)&command_data.cmd_repl_user_11_1.dcc_group,1);
01150 break;
01151 case CMD_REPL_USER_12_1:
01152 byteReverse((unsigned char*)&command_data.cmd_repl_user_12_1.msg_flood_l,14);
01153 break;
01154 case CMD_REPL_USER_13_1:
01155 break;
01156 case CMD_REPL_USER_14_1:
01157 break;
01158 case CMD_REPL_USER_15_1:
01159 break;
01160 case CMD_REPL_USER_16_5:
01161 break;
01162 case CMD_REPL_USER_17_9:
01163 break;
01164 case CMD_REPL_USER_99_1:
01165 break;
01166 case CMD_PUSH_1:
01167 byteReverse((unsigned char*)&command_data.cmd_push_1.now,1);
01168 byteReverse((unsigned char*)&command_data.cmd_push_1.original_time,1);
01169 break;
01170 case CMD_PROC_1:
01171 byteReverse((unsigned char*)&command_data.cmd_proc_1.last_changed,1);
01172 break;
01173 case CMD_PROC_END_1:
01174 break;
01175 case CMD_PARTYLINE_1:
01176 byteReverse((unsigned char*)&command_data.cmd_partyline_1.id,1);
01177 break;
01178 case CMD_PARTYLINE_USER_1:
01179 byteReverse((unsigned char*)&command_data.cmd_partyline_user_1.id,1);
01180 break;
01181 case CMD_REPL_CHDEF_01_1:
01182 byteReverse((unsigned char*)&command_data.cmd_repl_chdef_01_1.last_changed,1);
01183 break;
01184 case CMD_REPL_CHDEF_02_1:
01185 break;
01186 case CMD_REPL_CHDEF_03_1:
01187 break;
01188 case CMD_REPL_CHDEF_04_1:
01189 break;
01190 case CMD_REPL_CHDEF_05_1:
01191 break;
01192 case CMD_REPL_CHDEF_06_8:
01193 break;
01194 case CMD_REPL_CHDEF_99_1:
01195 break;
01196 case CMD_REPL_PRV_01_1:
01197 byteReverse((unsigned char*)&command_data.cmd_repl_prv_01_1.last_changed,1);
01198 break;
01199 case CMD_REPL_PRV_02_1:
01200 break;
01201 case CMD_REPL_PRV_03_1:
01202 break;
01203 case CMD_REPL_PRV_04_7:
01204 break;
01205 case CMD_REPL_PRV_05_8:
01206 break;
01207 case CMD_REPL_PRV_06_11:
01208 break;
01209 case CMD_REPL_PRV_99_1:
01210 break;
01211 case CMD_REMOTE_PROCEDURE_CALL_3:
01212 byteReverse((unsigned char*)&command_data.cmd_remote_procedure_call_3.num_args,1);
01213 break;
01214 default:
01215 {
01216 char tmp[1024];
01217 sprintf(tmp,"%s%x","in file " __FILE__ " in function " __FUNC__ " occurred error: The code shouldn't go here! It means that you should add 'case' for this packet: COMMAND 0x",command);
01218 log_debug(tmp);
01219 }
01220 break;
01221 }
01222 }
01223
01224 void hard_clear()
01225 {
01226 memset(this,0,sizeof(*this));
01227 }
01228 } PACK_STRUCT;
01229
01230 #ifdef __BORLANDC__
01231 #if sizeof(s_bot_command)!=1024*64
01232 # error sizeof(s_bot_command) MUST be equal to 1024*64 bytes long in any case! use padding member for size correction!
01233 #endif
01234 #endif
01235
01236 #if defined(__GNUC__)
01237 # pragma align 0
01238 #endif
01239
01240
01241
01242
01243
01244
01245
01246 struct s_bot {
01247 bool clean;
01248
01249 string botname;
01250 string localip;
01251 string botip;
01252 unsigned short botport;
01253
01254 int supported_proto_version;
01255
01256 s_socket socket;
01257 bool ssl_connection;
01258 SSL* ssl;
01259 time_t awaiting_ready;
01260
01261 string remote_MD5_password;
01262
01263 bool sent_bot_auth_1;
01264 bool received_bot_auth_1;
01265 bool sent_at_least_one_ping;
01266 bool got_at_least_one_pong;
01267
01268 s_bot_command command_receive_buffer;
01269 s_bot_control control_receive_buffer;
01270 size_t receive_buffer_pos;
01271 char* rle_buffer;
01272 unsigned int rle_buffer_len;
01273 bool flipped;
01274
01275 char buff_from_dcc[1024*5];
01276 size_t buff_size_from_dcc;
01277 size_t buff_pos_from_dcc;
01278
01279 time_t last_try;
01280 bool waiting;
01281 bool invoked_from_telnet;
01282 int got_bytes;
01283 bool was_linked;
01284 bool auth_ok;
01285 bool remote_pswd_ok;
01286
01287 time_t next_ping;
01288 time_t start_awaiting_pong;
01289
01290 string unlink_proc;
01291 map<string,string> vars;
01292 bool unlink_proc_called;
01293
01294 time_t users_to_pull_last_update;
01295 vector<s_user_to_pull> pulling_users;
01296
01297 time_t users_to_push_last_update;
01298 vector<s_user_to_push> pushing_users;
01299
01300 time_t procs_to_pull_last_update;
01301 vector<s_proc_to_pull> pulling_procs;
01302
01303 time_t procs_to_push_last_update;
01304 vector<s_proc_to_push> pushing_procs;
01305
01306 time_t chans_to_pull_last_update;
01307 vector<s_chan_def_to_pull> pulling_chans;
01308
01309 time_t chans_to_push_last_update;
01310 vector<s_chan_def_to_push> pushing_chans;
01311
01312 vector<string> rejected_objects;
01313
01314 time_t last_proc_push;
01315
01316 time_t prv_to_push_last_update;
01317 s_private prv_to_push;
01318 s_private prv_to_pull;
01319 bool prv_pulling;
01320
01321 bool sent_partyline_users;
01322
01323 void clear() {
01324 clean=true;
01325 ssl_connection=false;
01326 ssl=NULL;
01327 awaiting_ready=0;
01328 botname="";
01329 localip="";
01330 botip="";
01331 botport=0;
01332 supported_proto_version=0;
01333 socket.clear();
01334 remote_MD5_password="";
01335 sent_bot_auth_1=false;
01336 received_bot_auth_1=false;
01337 sent_at_least_one_ping=false;
01338 got_at_least_one_pong=false;
01339 receive_buffer_pos=0;
01340 memset(buff_from_dcc,0,sizeof(buff_from_dcc));
01341 buff_size_from_dcc=0;
01342 buff_pos_from_dcc=0;
01343 last_try=0;
01344 waiting=false;
01345 invoked_from_telnet=false;
01346 got_bytes=0;
01347 was_linked=false;
01348 auth_ok=false;
01349 remote_pswd_ok=false;
01350 next_ping=0;
01351 start_awaiting_pong=0;
01352 unlink_proc="";
01353 vars.clear();
01354 unlink_proc_called=false;
01355 users_to_pull_last_update=0;
01356 pulling_users.clear();
01357 users_to_push_last_update=0;
01358 pushing_users.clear();
01359 procs_to_pull_last_update=0;
01360 pulling_procs.clear();
01361 procs_to_push_last_update=0;
01362 pushing_procs.clear();
01363 chans_to_pull_last_update=0;
01364 pulling_chans.clear();
01365 chans_to_push_last_update=0;
01366 pushing_chans.clear();
01367 sent_partyline_users=false;
01368 rejected_objects.clear();
01369 last_proc_push=0;
01370
01371 rle_buffer=NULL;
01372 rle_buffer_len=0;
01373 flipped=false;
01374 }
01375 s_bot() {
01376 clear();
01377 }
01378 s_bot(const s_bot& orig) {
01379 clear();
01380
01381 memcpy(&command_receive_buffer,&orig.command_receive_buffer,sizeof(s_bot_command));
01382 memcpy(&control_receive_buffer,&orig.control_receive_buffer,sizeof(s_bot_control));
01383 if(orig.rle_buffer) {
01384 rle_buffer=(char*)malloc(orig.rle_buffer_len);
01385 if(rle_buffer) {
01386 memcpy(rle_buffer,orig.rle_buffer,orig.rle_buffer_len);
01387 rle_buffer_len=orig.rle_buffer_len;
01388 } else {
01389 rle_buffer_len=0;
01390 }
01391 } else {
01392 rle_buffer=NULL;
01393 rle_buffer_len=0;
01394 }
01395
01396 botname=orig.botname;
01397 localip=orig.localip;
01398 botip=orig.botip;
01399 botport=orig.botport;
01400 socket=orig.socket;
01401 remote_MD5_password=orig.remote_MD5_password;
01402 sent_bot_auth_1=orig.sent_bot_auth_1;
01403 received_bot_auth_1=orig.received_bot_auth_1;
01404 receive_buffer_pos=orig.receive_buffer_pos;
01405 memcpy(buff_from_dcc,orig.buff_from_dcc,sizeof(buff_from_dcc));
01406 buff_size_from_dcc=orig.buff_size_from_dcc;
01407 buff_pos_from_dcc=orig.buff_pos_from_dcc;
01408 last_try=orig.last_try;
01409 waiting=orig.waiting;
01410 invoked_from_telnet=orig.invoked_from_telnet;
01411 got_bytes=orig.got_bytes;
01412 was_linked=orig.was_linked;
01413 auth_ok=orig.auth_ok;
01414 remote_pswd_ok=orig.remote_pswd_ok;
01415 next_ping=orig.next_ping;
01416 start_awaiting_pong=orig.start_awaiting_pong;
01417 unlink_proc=orig.unlink_proc;
01418 vars=orig.vars;
01419 unlink_proc_called=orig.unlink_proc_called;
01420 users_to_pull_last_update=orig.users_to_pull_last_update;
01421 pulling_users=orig.pulling_users;
01422 users_to_push_last_update=orig.users_to_push_last_update;
01423 pushing_users=orig.pushing_users;
01424 procs_to_pull_last_update=orig.procs_to_pull_last_update;
01425 pulling_procs=orig.pulling_procs;
01426 procs_to_push_last_update=orig.procs_to_push_last_update;
01427 pushing_procs=orig.pushing_procs;
01428
01429 chans_to_pull_last_update=orig.chans_to_pull_last_update;
01430 pulling_chans=orig.pulling_chans;
01431 chans_to_push_last_update=orig.chans_to_push_last_update;
01432 pushing_chans=orig.pushing_chans;
01433
01434 sent_partyline_users=orig.sent_partyline_users;
01435
01436 prv_pulling=false;
01437 prv_to_pull.clear();
01438 prv_to_push.clear();
01439
01440 ssl_connection=orig.ssl_connection;
01441 ssl=orig.ssl;
01442 clean=orig.clean;
01443 }
01444 ~s_bot() {
01445 free(rle_buffer);
01446 rle_buffer=NULL;
01447 rle_buffer_len=0;
01448 }
01449 };
01450
01451 vector<s_bot*> bots;
01452
01453
01454
01455
01456
01457
01458
01459 struct s_partyline_member {
01460 string user;
01461 string botname;
01462
01463 s_partyline_member()
01464 {
01465 user="";
01466 botname="";
01467 }
01468 };
01469
01470
01471
01472
01473
01474
01475
01476 struct s_botnet_channel {
01477 string channel_name;
01478 vector<s_partyline_member> members;
01479
01480 s_botnet_channel()
01481 {
01482 channel_name="";
01483 members.clear();
01484 }
01485 };
01486
01487 vector<s_botnet_channel> botnet_channels;
01488
01489
01490
01491
01492
01493
01494
01495 struct s_msg_id {
01496 my_time_t time;
01497 uint32 id;
01498
01499 s_msg_id()
01500 {
01501 time=0;
01502 id=0;
01503 }
01504 };
01505
01506 vector<s_msg_id> msg_ids;
01507 vector<s_msg_id> msg_disp_ids;
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517 void botnet_cleanup_ids()
01518 {
01519 time_t now;
01520 time(&now);
01521
01522 vector<s_msg_id>::iterator i1;
01523
01524 again:
01525 for(i1=msg_ids.begin(); i1!=msg_ids.end(); i1++)
01526 if((time_t)(*i1).time+300<now) {
01527 msg_ids.erase(i1);
01528 goto again;
01529 }
01530
01531 again2:
01532 for(i1=msg_disp_ids.begin(); i1!=msg_disp_ids.end(); i1++)
01533 if((time_t)(*i1).time+300<now) {
01534 msg_disp_ids.erase(i1);
01535 goto again2;
01536 }
01537 }
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548 bool botnet_query_disp_id(uint32 id)
01549 {
01550 vector<s_msg_id>::iterator i1;
01551 for(i1=msg_disp_ids.begin(); i1!=msg_disp_ids.end(); i1++)
01552 if((*i1).id==id)
01553 return true;
01554 return false;
01555 }
01556
01557
01558
01559
01560
01561
01562
01563
01564 uint32 botnet_get_unique_id()
01565 {
01566 uint32 id;
01567 for(;;) {
01568 again:
01569 id=(rand()%0xffff) | ( (rand()%0xffff) << 16 );
01570 vector<s_msg_id>::iterator i1;
01571
01572 for(i1=msg_ids.begin(); i1!=msg_ids.end(); i1++) {
01573 if((*i1).id==id) {
01574 goto again;
01575 }
01576 }
01577
01578 for(i1=msg_disp_ids.begin(); i1!=msg_disp_ids.end(); i1++) {
01579 if((*i1).id==id) {
01580 goto again;
01581 }
01582 }
01583
01584 break;
01585 }
01586
01587 return id;
01588 }
01589
01590 time_t botnet_last_rehash_request=0;
01591
01592
01593
01594
01595
01596
01597
01598
01599 void botnet_backup(string botname)
01600 {
01601 botnet_last_rehash_request=time(NULL);
01602 }
01603
01604
01605
01606
01607
01608
01609
01610
01611
01612 void botnet_rehash(s_bot* bot, string botname)
01613 {
01614 botnet_last_rehash_request=time(NULL);
01615 }
01616
01617 bool botnet_send_command(s_bot* bot, s_bot_command* cmd);
01618
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629 string botnet_remote_procedure_call(string botname, string proc_name_only, list<string>& args)
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;
01655
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
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 }
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698 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)
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
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
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 }
01767
01768
01769
01770
01771
01772
01773
01774
01775
01776
01777 bool botnet_send_command(s_bot* bot, s_bot_command* cmd)
01778 {
01779 s_bot_command* data=new s_bot_command;
01780 memcpy(data,cmd,sizeof(*cmd));
01781
01782 data->flip();
01783
01784 if(!bot->socket.cmp()) {
01785 log_debug("in file " __FILE__ " in function " __FUNC__ " occurred error: Attemp to use NULL socket handle");
01786 delete data;
01787 return true;
01788 }
01789 int ec=0;
01790
01791
01792 int compressed=0;
01793 unsigned char* buf=rle_compress((unsigned char*)&data->command_data,sizeof(data->command_data),compressed);
01794 data->size=compressed;
01795 size_t sent=0;
01796 if(!bot->ssl_connection) {
01797 sent=sock_send(bot->socket,(const char*)data,4*4,ec);
01798 stats_botnet_bytes_sent(sent);
01799 sent=sock_send(bot->socket,(const char*)buf,compressed,ec);
01800 stats_botnet_bytes_sent(sent);
01801 } else {
01802 char err_str[1024];
01803 if(ssl_write(bot->ssl,&(bot->socket),err_str,(char*)data,4*4)) {
01804 ssl_close(bot->ssl,&(bot->socket));
01805 bot->ssl=NULL;
01806 ec=-1;
01807 }
01808 stats_botnet_bytes_sent(4*4);
01809 if(ssl_write(bot->ssl,&(bot->socket),err_str,(char*)buf,compressed)) {
01810 ssl_close(bot->ssl,&(bot->socket));
01811 bot->ssl=NULL;
01812 ec=-1;
01813 } else
01814 sent=compressed;
01815 stats_botnet_bytes_sent(compressed);
01816 }
01817 delete[] buf;
01818
01819 if(sent!=compressed || ec!=0) {
01820 log_socket(ec,sock_error(ec),"in file " __FILE__ " in function " __FUNC__ " (not all data had been sent)");
01821 delete data;
01822 return true;
01823 }
01824 log_botnet_debug(botnet_botname,bot->botname.c_str(),cmd->packet_type,cmd->command,"sent to remote bot - in file " __FILE__ " in function " __FUNC__);
01825 sleep(1);
01826 delete data;
01827 return false;
01828 }
01829
01830
01831
01832
01833
01834
01835
01836
01837
01838
01839
01840 bool botnet_send_control(s_bot* bot, s_bot_control* ctrl)
01841 {
01842 ctrl->flip_header();
01843 ctrl->flip_rest();
01844
01845 if(!bot->socket.cmp()) {
01846 log_debug("in file " __FILE__ " in function " __FUNC__ " occurred error: Attemp to use NULL socket handle");
01847 return true;
01848 }
01849 int ec=0;
01850
01851
01852 int compressed=0;
01853 unsigned char* buf=rle_compress((unsigned char*)&ctrl->control_data,sizeof(ctrl->control_data),compressed);
01854 ctrl->size=compressed;
01855 size_t sent=0;
01856 if(!bot->ssl_connection) {
01857 sent=sock_send(bot->socket,(char*)ctrl,4*4,ec);
01858 stats_botnet_bytes_sent(sent);
01859 sent=sock_send(bot->socket,(const char*)buf,compressed,ec);
01860 stats_botnet_bytes_sent(sent);
01861 } else {
01862 char err_str[1024];
01863 if(ssl_write(bot->ssl,&(bot->socket),err_str,(char*)ctrl,4*4)) {
01864 ssl_close(bot->ssl,&(bot->socket));
01865 bot->ssl=NULL;
01866 ec=-1;
01867 }
01868 stats_botnet_bytes_sent(4*4);
01869 if(ssl_write(bot->ssl,&(bot->socket),err_str,(char*)buf,compressed)) {
01870 ssl_close(bot->ssl,&(bot->socket));
01871 bot->ssl=NULL;
01872 ec=-1;
01873 } else
01874 sent=compressed;
01875 stats_botnet_bytes_sent(compressed);
01876 }
01877 delete[] buf;
01878
01879 if(sent!=compressed || ec!=0) {
01880 log_socket(ec,sock_error(ec),"in file " __FILE__ " in function " __FUNC__ " (not all data had been sent)");
01881 return true;
01882 }
01883 log_botnet_debug(botnet_botname,bot->botname.c_str(),ctrl->packet_type,ctrl->control,"sent to remote bot - in file " __FILE__ " in function " __FUNC__);
01884 return false;
01885 }
01886
01887
01888
01889
01890
01891
01892
01893
01894
01895
01896
01897 bool botnet_check_string_size(char* str, size_t max_size)
01898 {
01899 bool ok=false;
01900 for(size_t i1=0; i1<max_size; i1++) {
01901 if(str[i1]==0) {
01902 ok=true;
01903 break;
01904 }
01905 }
01906 return !ok;
01907 }
01908
01909
01910
01911
01912
01913
01914
01915
01916
01917
01918 bool botnet_check_for_buffer_overflow(s_bot_command& cmd)
01919 {
01920 if(cmd.packet_type!=PACKET_TYPE_COMMAND)
01921 return true;
01922
01923 if(cmd.version>SUPPORTED_PROTO_VERSION)
01924 return true;
01925
01926 switch(cmd.command) {
01927 case CMD_AUTH_1:
01928 if(botnet_check_string_size(cmd.command_data.bot_auth_1.botname,sizeof(cmd.command_data.bot_auth_1.botname)))
01929 return true;
01930 if(botnet_check_string_size((char*)cmd.command_data.bot_auth_1.digest,sizeof(cmd.command_data.bot_auth_1.digest)))
01931 return true;
01932 break;
01933 case CMD_CHECK_TIME_1:
01934 if(botnet_check_string_size(cmd.command_data.check_time_1.object_name,sizeof(cmd.command_data.check_time_1.object_name)))
01935 return true;
01936 break;
01937 case CMD_NO_REPL_1:
01938 if(botnet_check_string_size(cmd.command_data.no_repl_1.object_name,sizeof(cmd.command_data.no_repl_1.object_name)))
01939 return true;
01940 break;
01941 case CMD_REPL_USER_01_1:
01942 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_01_1.name,sizeof(cmd.command_data.cmd_repl_user_01_1.name)))
01943 return true;
01944 break;
01945 case CMD_REPL_USER_02_1:
01946 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_02_1.name,sizeof(cmd.command_data.cmd_repl_user_02_1.name)))
01947 return true;
01948 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_02_1.hostmask,sizeof(cmd.command_data.cmd_repl_user_02_1.hostmask)))
01949 return true;
01950 break;
01951 case CMD_REPL_USER_03_1:
01952 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_03_1.name,sizeof(cmd.command_data.cmd_repl_user_03_1.name)))
01953 return true;
01954 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_03_1.fullname,sizeof(cmd.command_data.cmd_repl_user_03_1.fullname)))
01955 return true;
01956 break;
01957 case CMD_REPL_USER_04_1:
01958 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_04_1.name,sizeof(cmd.command_data.cmd_repl_user_04_1.name)))
01959 return true;
01960 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_04_1.access_to_group,sizeof(cmd.command_data.cmd_repl_user_04_1.access_to_group)))
01961 return true;
01962 break;
01963 case CMD_REPL_USER_05_1:
01964 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_05_1.name,sizeof(cmd.command_data.cmd_repl_user_05_1.name)))
01965 return true;
01966 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_05_1.access_to_proc,sizeof(cmd.command_data.cmd_repl_user_05_1.access_to_proc)))
01967 return true;
01968 break;
01969 case CMD_REPL_USER_06_1:
01970 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_06_1.name,sizeof(cmd.command_data.cmd_repl_user_06_1.name)))
01971 return true;
01972 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_06_1.access_grant_proc,sizeof(cmd.command_data.cmd_repl_user_06_1.access_grant_proc)))
01973 return true;
01974 break;
01975 case CMD_REPL_USER_07_1:
01976 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_07_1.name,sizeof(cmd.command_data.cmd_repl_user_07_1.name)))
01977 return true;
01978 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_07_1.access_grant_group,sizeof(cmd.command_data.cmd_repl_user_07_1.access_grant_group)))
01979 return true;
01980 break;
01981 case CMD_REPL_USER_08_1:
01982 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_08_1.name,sizeof(cmd.command_data.cmd_repl_user_08_1.name)))
01983 return true;
01984 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_08_1.access_to_channel,sizeof(cmd.command_data.cmd_repl_user_08_1.access_to_channel)))
01985 return true;
01986 break;
01987 case CMD_REPL_USER_09_1:
01988 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_09_1.name,sizeof(cmd.command_data.cmd_repl_user_09_1.name)))
01989 return true;
01990 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_09_1.access_grant_channel,sizeof(cmd.command_data.cmd_repl_user_09_1.access_grant_channel)))
01991 return true;
01992 break;
01993 case CMD_REPL_USER_10_1:
01994 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_10_1.name,sizeof(cmd.command_data.cmd_repl_user_10_1.name)))
01995 return true;
01996 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_10_1.group,sizeof(cmd.command_data.cmd_repl_user_10_1.group)))
01997 return true;
01998 break;
01999 case CMD_REPL_USER_11_1:
02000 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_11_1.name,sizeof(cmd.command_data.cmd_repl_user_11_1.name)))
02001 return true;
02002 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_11_1.dcc_host,sizeof(cmd.command_data.cmd_repl_user_11_1.dcc_host)))
02003 return true;
02004 break;
02005 case CMD_REPL_USER_12_1:
02006 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.name,sizeof(cmd.command_data.cmd_repl_user_12_1.name)))
02007 return true;
02008 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.channel,sizeof(cmd.command_data.cmd_repl_user_12_1.channel)))
02009 return true;
02010 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_deop,sizeof(cmd.command_data.cmd_repl_user_12_1.on_deop)))
02011 return true;
02012 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_ban,sizeof(cmd.command_data.cmd_repl_user_12_1.on_ban)))
02013 return true;
02014 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_unban,sizeof(cmd.command_data.cmd_repl_user_12_1.on_unban)))
02015 return true;
02016 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_kick,sizeof(cmd.command_data.cmd_repl_user_12_1.on_kick)))
02017 return true;
02018 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_op,sizeof(cmd.command_data.cmd_repl_user_12_1.on_op)))
02019 return true;
02020 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_voice,sizeof(cmd.command_data.cmd_repl_user_12_1.on_voice)))
02021 return true;
02022 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_devoice,sizeof(cmd.command_data.cmd_repl_user_12_1.on_devoice)))
02023 return true;
02024 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_creator,sizeof(cmd.command_data.cmd_repl_user_12_1.on_creator)))
02025 return true;
02026 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_decreator,sizeof(cmd.command_data.cmd_repl_user_12_1.on_decreator)))
02027 return true;
02028 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_join,sizeof(cmd.command_data.cmd_repl_user_12_1.on_join)))
02029 return true;
02030 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_banned,sizeof(cmd.command_data.cmd_repl_user_12_1.on_banned)))
02031 return true;
02032 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_flood,sizeof(cmd.command_data.cmd_repl_user_12_1.on_flood)))
02033 return true;
02034 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_privmsg,sizeof(cmd.command_data.cmd_repl_user_12_1.on_privmsg)))
02035 return true;
02036 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_notice,sizeof(cmd.command_data.cmd_repl_user_12_1.on_notice)))
02037 return true;
02038 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_except,sizeof(cmd.command_data.cmd_repl_user_12_1.on_except)))
02039 return true;
02040 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_unexcept,sizeof(cmd.command_data.cmd_repl_user_12_1.on_unexcept)))
02041 return true;
02042 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_invite,sizeof(cmd.command_data.cmd_repl_user_12_1.on_invite)))
02043 return true;
02044 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_uninvite,sizeof(cmd.command_data.cmd_repl_user_12_1.on_uninvite)))
02045 return true;
02046 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_not_invited,sizeof(cmd.command_data.cmd_repl_user_12_1.on_not_invited)))
02047 return true;
02048 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_not_in_reop,sizeof(cmd.command_data.cmd_repl_user_12_1.on_not_in_reop)))
02049 return true;
02050 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.on_reop,sizeof(cmd.command_data.cmd_repl_user_12_1.on_reop)))
02051 return true;
02052 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.dynamic_plus_modes,sizeof(cmd.command_data.cmd_repl_user_12_1.dynamic_plus_modes)))
02053 return true;
02054 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_12_1.dynamic_minus_modes,sizeof(cmd.command_data.cmd_repl_user_12_1.dynamic_minus_modes)))
02055 return true;
02056 break;
02057 case CMD_REPL_USER_13_1:
02058 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_13_1.name,sizeof(cmd.command_data.cmd_repl_user_13_1.name)))
02059 return true;
02060 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_13_1.channel,sizeof(cmd.command_data.cmd_repl_user_13_1.channel)))
02061 return true;
02062 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_13_1.group,sizeof(cmd.command_data.cmd_repl_user_13_1.group)))
02063 return true;
02064 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_13_1.plus_modes,sizeof(cmd.command_data.cmd_repl_user_13_1.plus_modes)))
02065 return true;
02066 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_13_1.minus_modes,sizeof(cmd.command_data.cmd_repl_user_13_1.minus_modes)))
02067 return true;
02068 break;
02069 case CMD_REPL_USER_14_1:
02070 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_14_1.name,sizeof(cmd.command_data.cmd_repl_user_14_1.name)))
02071 return true;
02072 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_14_1.meta_key,sizeof(cmd.command_data.cmd_repl_user_14_1.meta_key)))
02073 return true;
02074 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_14_1.meta_val,sizeof(cmd.command_data.cmd_repl_user_14_1.meta_val)))
02075 return true;
02076 break;
02077 case CMD_REPL_USER_15_1:
02078 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_15_1.name,sizeof(cmd.command_data.cmd_repl_user_15_1.name)))
02079 return true;
02080 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_15_1.access_usage_proc,sizeof(cmd.command_data.cmd_repl_user_15_1.access_usage_proc)))
02081 return true;
02082 break;
02083 case CMD_REPL_USER_16_5:
02084 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_16_5.name,sizeof(cmd.command_data.cmd_repl_user_16_5.name)))
02085 return true;
02086 break;
02087 case CMD_REPL_USER_17_9:
02088 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_17_9.name,sizeof(cmd.command_data.cmd_repl_user_17_9.name)))
02089 return true;
02090 break;
02091 case CMD_REPL_USER_99_1:
02092 if(botnet_check_string_size(cmd.command_data.cmd_repl_user_99_1.name,sizeof(cmd.command_data.cmd_repl_user_99_1.name)))
02093 return true;
02094 break;
02095 case CMD_PUSH_1:
02096 if(botnet_check_string_size(cmd.command_data.cmd_push_1.object_name,sizeof(cmd.command_data.cmd_push_1.object_name)))
02097 return true;
02098 break;
02099 case CMD_PROC_1:
02100 if(botnet_check_string_size(cmd.command_data.cmd_proc_1.name,sizeof(cmd.command_data.cmd_proc_1.name)))
02101 return true;
02102 if(botnet_check_string_size(cmd.command_data.cmd_proc_1.line,sizeof(cmd.command_data.cmd_proc_1.line)))
02103 return true;
02104 break;
02105 case CMD_PROC_END_1:
02106 if(botnet_check_string_size(cmd.command_data.cmd_proc_end_1.name,sizeof(cmd.command_data.cmd_proc_end_1.name)))
02107 return true;
02108 break;
02109 case CMD_PARTYLINE_1:
02110 if(botnet_check_string_size(cmd.command_data.cmd_partyline_1.user,sizeof(cmd.command_data.cmd_partyline_1.user)))
02111 return true;
02112 if(botnet_check_string_size(cmd.command_data.cmd_partyline_1.message,sizeof(cmd.command_data.cmd_partyline_1.message)))
02113 return true;
02114 if(botnet_check_string_size(cmd.command_data.cmd_partyline_1.channel,sizeof(cmd.command_data.cmd_partyline_1.channel)))
02115 return true;
02116 if(botnet_check_string_size(cmd.command_data.cmd_partyline_1.botname,sizeof(cmd.command_data.cmd_partyline_1.botname)))
02117 return true;
02118 break;
02119 case CMD_PARTYLINE_USER_1:
02120 if(botnet_check_string_size(cmd.command_data.cmd_partyline_user_1.user,sizeof(cmd.command_data.cmd_partyline_user_1.user)))
02121 return true;
02122 if(botnet_check_string_size(cmd.command_data.cmd_partyline_user_1.channel,sizeof(cmd.command_data.cmd_partyline_user_1.channel)))
02123 return true;
02124 if(botnet_check_string_size(cmd.command_data.cmd_partyline_user_1.botname,sizeof(cmd.command_data.cmd_partyline_user_1.botname)))
02125 return true;
02126 break;
02127 case CMD_REPL_CHDEF_01_1:
02128 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_01_1.name,sizeof(cmd.command_data.cmd_repl_chdef_01_1.name)))
02129 return true;
02130 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_01_1.on_mode,sizeof(cmd.command_data.cmd_repl_chdef_01_1.on_mode)))
02131 return true;
02132 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_01_1.on_key,sizeof(cmd.command_data.cmd_repl_chdef_01_1.on_key)))
02133 return true;
02134 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_01_1.on_limit,sizeof(cmd.command_data.cmd_repl_chdef_01_1.on_limit)))
02135 return true;
02136 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_01_1.on_topic,sizeof(cmd.command_data.cmd_repl_chdef_01_1.on_topic)))
02137 return true;
02138 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_01_1.on_ircop,sizeof(cmd.command_data.cmd_repl_chdef_01_1.on_ircop)))
02139 return true;
02140 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_01_1.on_ctcp,sizeof(cmd.command_data.cmd_repl_chdef_01_1.on_ctcp)))
02141 return true;
02142 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_01_1.on_privmsg,sizeof(cmd.command_data.cmd_repl_chdef_01_1.on_privmsg)))
02143 return true;
02144 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_01_1.on_notice,sizeof(cmd.command_data.cmd_repl_chdef_01_1.on_notice)))
02145 return true;
02146 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_01_1.on_part,sizeof(cmd.command_data.cmd_repl_chdef_01_1.on_part)))
02147 return true;
02148 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_01_1.on_dynamic_ban,sizeof(cmd.command_data.cmd_repl_chdef_01_1.on_dynamic_ban)))
02149 return true;
02150 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_01_1.dynamic_plus_modes,sizeof(cmd.command_data.cmd_repl_chdef_01_1.dynamic_plus_modes)))
02151 return true;
02152 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_01_1.dynamic_minus_modes,sizeof(cmd.command_data.cmd_repl_chdef_01_1.dynamic_minus_modes)))
02153 return true;
02154 break;
02155 case CMD_REPL_CHDEF_02_1:
02156 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_02_1.name,sizeof(cmd.command_data.cmd_repl_chdef_02_1.name)))
02157 return true;
02158 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_02_1.group,sizeof(cmd.command_data.cmd_repl_chdef_02_1.group)))
02159 return true;
02160 break;
02161 case CMD_REPL_CHDEF_03_1:
02162 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_03_1.name,sizeof(cmd.command_data.cmd_repl_chdef_03_1.name)))
02163 return true;
02164 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_03_1.group,sizeof(cmd.command_data.cmd_repl_chdef_03_1.group)))
02165 return true;
02166 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_03_1.plus_modes,sizeof(cmd.command_data.cmd_repl_chdef_03_1.plus_modes)))
02167 return true;
02168 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_03_1.minus_modes,sizeof(cmd.command_data.cmd_repl_chdef_03_1.minus_modes)))
02169 return true;
02170 break;
02171 case CMD_REPL_CHDEF_04_1:
02172 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_04_1.name,sizeof(cmd.command_data.cmd_repl_chdef_04_1.name)))
02173 return true;
02174 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_04_1.mask,sizeof(cmd.command_data.cmd_repl_chdef_04_1.mask)))
02175 return true;
02176 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_04_1.reason,sizeof(cmd.command_data.cmd_repl_chdef_04_1.reason)))
02177 return true;
02178 break;
02179 case CMD_REPL_CHDEF_05_1:
02180 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_05_1.name,sizeof(cmd.command_data.cmd_repl_chdef_05_1.name)))
02181 return true;
02182 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_05_1.group,sizeof(cmd.command_data.cmd_repl_chdef_05_1.group)))
02183 return true;
02184 break;
02185 case CMD_REPL_CHDEF_06_8:
02186 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_06_8.name,sizeof(cmd.command_data.cmd_repl_chdef_06_8.name)))
02187 return true;
02188 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_06_8.on_server_msg,sizeof(cmd.command_data.cmd_repl_chdef_06_8.on_server_msg)))
02189 return true;
02190 case CMD_REPL_CHDEF_99_1:
02191 if(botnet_check_string_size(cmd.command_data.cmd_repl_chdef_99_1.name,sizeof(cmd.command_data.cmd_repl_chdef_99_1.name)))
02192 return true;
02193 break;
02194 case CMD_REPL_PRV_01_1:
02195 break;
02196 case CMD_REPL_PRV_02_1:
02197 if(botnet_check_string_size(cmd.command_data.cmd_repl_prv_02_1.group,sizeof(cmd.command_data.cmd_repl_prv_02_1.group)))
02198 return true;
02199 break;
02200 case CMD_REPL_PRV_03_1:
02201 if(botnet_check_string_size(cmd.command_data.cmd_repl_prv_03_1.on_privmsg,sizeof(cmd.command_data.cmd_repl_prv_03_1.on_privmsg)))
02202 return true;
02203 if(botnet_check_string_size(cmd.command_data.cmd_repl_prv_03_1.on_notice,sizeof(cmd.command_data.cmd_repl_prv_03_1.on_notice)))
02204 return true;
02205 if(botnet_check_string_size(cmd.command_data.cmd_repl_prv_03_1.on_ctcp,sizeof(cmd.command_data.cmd_repl_prv_03_1.on_ctcp)))
02206 return true;
02207 break;
02208 case CMD_REPL_PRV_04_7:
02209 if(botnet_check_string_size(cmd.command_data.cmd_repl_prv_04_7.on_filesys_got_new,sizeof(cmd.command_data.cmd_repl_prv_04_7.on_filesys_got_new)))
02210 return true;
02211 if(botnet_check_string_size(cmd.command_data.cmd_repl_prv_04_7.on_fnc,sizeof(cmd.command_data.cmd_repl_prv_04_7.on_fnc)))
02212 return true;
02213 break;
02214 case CMD_REPL_PRV_05_8:
02215 if(botnet_check_string_size(cmd.command_data.cmd_repl_prv_05_8.on_broadcast,sizeof(cmd.command_data.cmd_repl_prv_05_8.on_broadcast)))
02216 return true;
02217 if(botnet_check_string_size(cmd.command_data.cmd_repl_prv_05_8.on_server_msg,sizeof(cmd.command_data.cmd_repl_prv_05_8.on_server_msg)))
02218 return true;
02219 break;
02220 case CMD_REPL_PRV_06_11:
02221 if(botnet_check_string_size(cmd.command_data.cmd_repl_prv_06_11.on_internal_event,sizeof(cmd.command_data.cmd_repl_prv_06_11.on_internal_event)))
02222 return true;
02223 break;
02224 case CMD_REPL_PRV_99_1:
02225 break;
02226 case CMD_REMOTE_PROCEDURE_CALL_3:
02227
02228 break;
02229 default:
02230 return true;
02231 }
02232 return false;
02233 }
02234
02235
02236
02237
02238
02239
02240
02241
02242
02243
02244
02245
02246
02247
02248
02249
02250
02251
02252
02253
02254
02255
02256 int botnet_receive(s_bot* bot, int& packet_type, s_bot_command* cmd, s_bot_control* control)
02257 {
02258 int ec=0;
02259 bool closed=false;
02260 size_t len=0;
02261
02262 if(bot->receive_buffer_pos<4*4) {
02263 bot->flipped=false;
02264 char* data=(char*)&bot->control_receive_buffer;
02265
02266 if(!bot->ssl_connection) {
02267 len=sock_read(bot->socket,&data[bot->receive_buffer_pos],4*4-bot->receive_buffer_pos,ec,closed);
02268 stats_botnet_bytes_received(len);
02269 if(ec || closed) {
02270 sock_close(bot->socket);
02271 bot->socket.clear();
02272 return 4;
02273 }
02274 bot->receive_buffer_pos+=len;
02275 } else {
02276 len=0;
02277 if(bot->ssl) {
02278 char err_str[1024];
02279 if(ssl_client_read(bot->ssl,&(bot->socket),err_str,&data[bot->receive_buffer_pos],4*4-bot->receive_buffer_pos,len)) {
02280 ssl_close(bot->ssl,&(bot->socket));
02281 bot->ssl=NULL;
02282 sock_close(bot->socket);
02283 bot->socket.clear();
02284 ec=-1;
02285 closed=true;
02286 return 4;
02287 }
02288 bot->receive_buffer_pos+=len;
02289 }
02290 }
02291 }
02292
02293 if(bot->receive_buffer_pos==4*4 && !bot->flipped) {
02294 bot->control_receive_buffer.flip_header();
02295 memcpy(&bot->command_receive_buffer,&bot->control_receive_buffer,4*4);
02296 bot->flipped=true;
02297 }
02298
02299 if(bot->receive_buffer_pos>=4*4) {
02300 bool control_=false;
02301 bool command_=false;
02302
02303 control_=bot->control_receive_buffer.packet_type==PACKET_TYPE_CONTROL;
02304 command_=bot->control_receive_buffer.packet_type==PACKET_TYPE_COMMAND;
02305
02306
02307 if((!control_ && !command_) || bot->command_receive_buffer.size>sizeof(bot->command_receive_buffer.command_data)*2) {
02308 if(bot->ssl) {
02309 ssl_close(bot->ssl,&(bot->socket));
02310 bot->ssl=NULL;
02311 }
02312 sock_close(bot->socket);
02313 bot->socket.clear();
02314 return 5;
02315 }
02316
02317 {
02318 for(;;) {
02319 size_t partial_data_size=1024;
02320 char* partial_data=new char[partial_data_size];
02321
02322 len=0;
02323 if(bot->receive_buffer_pos<bot->control_receive_buffer.size+4*4) {
02324 size_t want_bytes=bot->control_receive_buffer.size-bot->receive_buffer_pos+4*4;
02325 if(want_bytes>partial_data_size)
02326 want_bytes=partial_data_size;
02327
02328 if(!bot->ssl_connection) {
02329 len=sock_read(bot->socket,partial_data,want_bytes,ec,closed);
02330 stats_botnet_bytes_received(len);
02331 } else {
02332 char err_str[1024];
02333 if(ssl_client_read(bot->ssl,&(bot->socket),err_str,partial_data,want_bytes,len)) {
02334 ssl_close(bot->ssl,&(bot->socket));
02335 bot->ssl=NULL;
02336 ec=-1;
02337 closed=true;
02338 delete[] partial_data;
02339 return 4;
02340 }
02341 stats_botnet_bytes_received(len);
02342 }
02343 }
02344 if(ec) {
02345 if(bot->ssl) {
02346 ssl_close(bot->ssl,&(bot->socket));
02347 bot->ssl=NULL;
02348 }
02349 sock_close(bot->socket);
02350 bot->socket.clear();
02351 delete[] partial_data;
02352 return 4;
02353 }
02354 if(bot->rle_buffer==NULL && len!=0) {
02355 bot->rle_buffer_len=(unsigned int)bot->receive_buffer_pos-4*4+len;
02356 bot->rle_buffer=(char*)malloc(bot->rle_buffer_len);
02357 if(!bot->rle_buffer) {
02358 if(bot->ssl) {
02359 ssl_close(bot->ssl,&(bot->socket));
02360 bot->ssl=NULL;
02361 }
02362 sock_close(bot->socket);
02363 bot->socket.clear();
02364 log_debug("malloc() failed!");
02365 log_botnet(botnet_botname,bot->botname.c_str(),"malloc() failed!");
02366 delete[] partial_data;
02367 return 4;
02368 }
02369 memcpy(bot->rle_buffer,partial_data,len);
02370 } else if(len!=0) {
02371 bot->rle_buffer=(char*)realloc(bot->rle_buffer,bot->rle_buffer_len+len);
02372 if(!bot->rle_buffer) {
02373 if(bot->ssl) {
02374 ssl_close(bot->ssl,&(bot->socket));
02375 bot->ssl=NULL;
02376 }
02377 sock_close(bot->socket);
02378 bot->socket.clear();
02379 log_debug("realloc() failed!");
02380 log_botnet(botnet_botname,bot->botname.c_str(),"realloc() failed!");
02381 delete[] partial_data;
02382 return 4;
02383 }
02384 memcpy(&(bot->rle_buffer[bot->rle_buffer_len]),partial_data,len);
02385 bot->rle_buffer_len+=(unsigned int)len;
02386 }
02387 bot->receive_buffer_pos+=len;
02388
02389 delete[] partial_data;
02390
02391 if(bot->receive_buffer_pos==bot->control_receive_buffer.size+4*4) {
02392 cmd->hard_clear();
02393 control->hard_clear();
02394
02395 int uncompress=0;
02396 unsigned char* tmp=new unsigned char[sizeof(cmd->command_data)*2];
02397 if(control_) {
02398 uncompress=sizeof(control->control_data);
02399 }
02400 if(command_) {
02401 uncompress=sizeof(cmd->command_data);
02402 }
02403 if(uncompress==0) {
02404
02405
02406 if(bot->ssl) {
02407 ssl_close(bot->ssl,&(bot->socket));
02408 bot->ssl=NULL;
02409 }
02410 sock_close(bot->socket);
02411 bot->socket.clear();
02412
02413 log_debug("internal error!");
02414 log_botnet(botnet_botname,bot->botname.c_str(),"internal error!");
02415 delete[] tmp;
02416 return 4;
02417 }
02418 if(rle_decompress((unsigned char*)bot->rle_buffer,bot->rle_buffer_len,tmp,uncompress)) {
02419 if(bot->ssl) {
02420 ssl_close(bot->ssl,&(bot->socket));
02421 bot->ssl=NULL;
02422 }
02423 sock_close(bot->socket);
02424 bot->socket.clear();
02425
02426 delete[] tmp;
02427 return 5;
02428 }
02429
02430 if(command_) {
02431 memcpy(cmd,&(bot->command_receive_buffer),4*4);
02432
02433 memcpy(&(cmd->command_data),tmp,sizeof(cmd->command_data));
02434 delete[] tmp;
02435 tmp=NULL;
02436
02437 cmd->flip();
02438
02439 if(botnet_check_for_buffer_overflow(*cmd)) {
02440 log_debug("Buffer overflow detected in commnad packet!");
02441 log_botnet(botnet_botname,bot->botname.c_str(),"Buffer overflow detected in commnad packet!");
02442 return 4;
02443 }
02444
02445 packet_type=PACKET_TYPE_COMMAND;
02446 if(!botnet_check_for_buffer_overflow(*cmd)) {
02447 if(closed)
02448 return 3;
02449 else
02450 return 1;
02451 } else {
02452 if(bot->ssl) {
02453 ssl_close(bot->ssl,&(bot->socket));
02454 bot->ssl=NULL;
02455 }
02456 sock_close(bot->socket);
02457 bot->socket.clear();
02458
02459 log_debug("Buffer overflow detected in commnad packet!");
02460 log_botnet(botnet_botname,bot->botname.c_str(),"Buffer overflow detected in commnad packet!");
02461 return 4;
02462 }
02463 }
02464 if(control_) {
02465 memcpy(control,&(bot->control_receive_buffer),4*4);
02466
02467 memcpy(&(control->control_data),tmp,sizeof(control->control_data));
02468 delete[] tmp;
02469 tmp=NULL;
02470
02471 control->flip_rest();
02472
02473 packet_type=PACKET_TYPE_CONTROL;
02474 if(closed)
02475 return 3;
02476 else
02477 return 1;
02478 }
02479 if(tmp) {
02480 delete[] tmp;
02481 tmp=NULL;
02482 }
02483 }
02484 if(len==0)
02485 return 0;
02486 }
02487 }
02488 }
02489
02490 return 0;
02491 }
02492
02493
02494
02495
02496
02497
02498
02499
02500
02501 void botnet_push_prv(s_bot* bot, s_private& prv)
02502 {
02503 stats_botnet_private_pushed();
02504
02505 if(r_private.last_changed==0)
02506 time(&r_private.last_changed);
02507
02508 s_bot_command* c=new s_bot_command;
02509 {
02510 c->hard_clear();
02511 c->packet_type=PACKET_TYPE_COMMAND;
02512 c->size=sizeof(c);
02513 c->version=1;
02514 c->command=CMD_REPL_PRV_01_1;
02515
02516 c->command_data.cmd_repl_prv_01_1.last_changed=(my_time_t)prv.last_changed;
02517 botnet_send_command(bot,c);
02518 }
02519
02520 {
02521 int data_size=sizeof(c->command_data.cmd_repl_prv_02_1.group);
02522 char* data=new char[data_size+1];
02523
02524 vector<s_group>::iterator i2;
02525 for(i2=prv.groups.begin(); i2!=prv.groups.end(); i2++) {
02526 c->hard_clear();
02527 c->packet_type=PACKET_TYPE_COMMAND;
02528 c->size=sizeof(c);
02529 c->version=1;
02530 c->command=CMD_REPL_PRV_02_1;
02531
02532 memset(data,0,data_size);
02533 strncpy(data,(*i2).name.c_str(),data_size);
02534
02535 memcpy(c->command_data.cmd_repl_prv_02_1.group,data,data_size);
02536
02537 botnet_send_command(bot,c);
02538 }
02539 delete[] data;
02540 }
02541
02542 {
02543 c->hard_clear();
02544 c->packet_type=PACKET_TYPE_COMMAND;
02545 c->size=sizeof(c);
02546 c->version=1;
02547 c->command=CMD_REPL_PRV_03_1;
02548
02549 int data_size=sizeof(c->command_data.cmd_repl_prv_03_1.on_privmsg);
02550 if(data_size>sizeof(c->command_data.cmd_repl_prv_03_1.on_notice))
02551 data_size=sizeof(c->command_data.cmd_repl_prv_03_1.on_notice);
02552 if(data_size>sizeof(c->command_data.cmd_repl_prv_03_1.on_ctcp))
02553 data_size=sizeof(c->command_data.cmd_repl_prv_03_1.on_ctcp);
02554 char* data=new char[data_size+1];
02555
02556 memset(data,0,data_size);
02557 strncpy(data,prv.on_privmsg.c_str(),data_size);
02558 memcpy(c->command_data.cmd_repl_prv_03_1.on_privmsg,data,data_size);
02559
02560 memset(data,0,data_size);
02561 strncpy(data,prv.on_notice.c_str(),data_size);
02562 memcpy(c->command_data.cmd_repl_prv_03_1.on_notice,data,data_size);
02563
02564 memset(data,0,data_size);
02565 strncpy(data,prv.on_ctcp.c_str(),data_size);
02566 memcpy(c->command_data.cmd_repl_prv_03_1.on_ctcp,data,data_size);
02567
02568 delete[] data;
02569
02570 botnet_send_command(bot,c);
02571 }
02572
02573 if(bot->supported_proto_version>=7) {
02574 c->hard_clear();
02575 c->packet_type=PACKET_TYPE_COMMAND;
02576 c->size=sizeof(c);
02577 c->version=7;
02578 c->command=CMD_REPL_PRV_04_7;
02579
02580 int data_size=sizeof(c->command_data.cmd_repl_prv_04_7.on_filesys_got_new);
02581 if(data_size>sizeof(c->command_data.cmd_repl_prv_04_7.on_filesys_got_new))
02582 data_size=sizeof(c->command_data.cmd_repl_prv_04_7.on_filesys_got_new);
02583 if(data_size>sizeof(c->command_data.cmd_repl_prv_04_7.on_fnc))
02584 data_size=sizeof(c->command_data.cmd_repl_prv_04_7.on_fnc);
02585 char* data=new char[data_size+1];
02586
02587 memset(data,0,data_size);
02588 strncpy(data,prv.on_filesys_got_new.c_str(),data_size);
02589 memcpy(c->command_data.cmd_repl_prv_04_7.on_filesys_got_new,data,data_size);
02590
02591 memset(data,0,data_size);
02592 strncpy(data,prv.on_fnc.c_str(),data_size);
02593 memcpy(c->command_data.cmd_repl_prv_04_7.on_fnc,data,data_size);
02594
02595 delete[] data;
02596
02597 botnet_send_command(bot,c);
02598 }
02599
02600 if(bot->supported_proto_version>=8) {
02601 c->hard_clear();
02602 c->packet_type=PACKET_TYPE_COMMAND;
02603 c->size=sizeof(c);
02604 c->version=8;
02605 c->command=CMD_REPL_PRV_05_8;
02606
02607 int data_size=sizeof(c->command_data.cmd_repl_prv_05_8.on_broadcast);
02608 if(data_size>sizeof(c->command_data.cmd_repl_prv_05_8.on_broadcast))
02609 data_size=sizeof(c->command_data.cmd_repl_prv_05_8.on_broadcast);
02610 if(data_size>sizeof(c->command_data.cmd_repl_prv_05_8.on_server_msg))
02611 data_size=sizeof(c->command_data.cmd_repl_prv_05_8.on_server_msg);
02612 char* data=new char[data_size+1];
02613
02614 memset(data,0,data_size);
02615 strncpy(data,prv.on_broadcast.c_str(),data_size);
02616 memcpy(c->command_data.cmd_repl_prv_05_8.on_broadcast,data,data_size);
02617
02618 memset(data,0,data_size);
02619 strncpy(data,prv.on_server_msg.c_str(),data_size);
02620 memcpy(c->command_data.cmd_repl_prv_05_8.on_server_msg,data,data_size);
02621
02622 delete[] data;
02623
02624 botnet_send_command(bot,c);
02625 }
02626
02627 if(bot->supported_proto_version>=11) {
02628 c->hard_clear();
02629 c->packet_type=PACKET_TYPE_COMMAND;
02630 c->size=sizeof(c);
02631 c->version=8;
02632 c->command=CMD_REPL_PRV_06_11;
02633
02634 int data_size=sizeof(c->command_data.cmd_repl_prv_06_11.on_internal_event);
02635 char* data=new char[data_size+1];
02636
02637 memset(data,0,data_size);
02638 strncpy(data,prv.on_internal_event.c_str(),data_size);
02639 memcpy(c->command_data.cmd_repl_prv_06_11.on_internal_event,data,data_size);
02640
02641 delete[] data;
02642
02643 botnet_send_command(bot,c);
02644 }
02645
02646 {
02647 c->hard_clear();
02648 c->packet_type=PACKET_TYPE_COMMAND;
02649 c->size=sizeof(c);
02650 c->version=1;
02651 c->command=CMD_REPL_PRV_99_1;
02652 botnet_send_command(bot,c);
02653 }
02654
02655 string d="replication: PUSH of object ";
02656 d+="(private)";
02657 log_botnet_debug(botnet_botname,bot->botname.c_str(),-1,-1,d.c_str());
02658 log_botnet(botnet_botname,bot->botname.c_str(),d.c_str());
02659
02660 {
02661 string obj_type="private";
02662 string reason="OK";
02663 string obj="private";
02664
02665 logic_on_internal_event("@botnet_replication@",bot->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,d,"PUSH");
02666 }
02667
02668 delete c;
02669 }
02670
02671
02672
02673
02674
02675
02676
02677
02678
02679 void botnet_push_user(s_bot* bot, s_user& u)
02680 {
02681 stats_botnet_user_pushed();
02682
02683 if(u.last_changed==0)
02684 time(&u.last_changed);
02685
02686 s_bot_command* c=new s_bot_command;
02687 int name_size=sizeof(c->command_data.cmd_repl_user_01_1.name);
02688 char* name=new char[name_size];
02689 memset(name,0,name_size);
02690 strncpy(name,u.name.c_str(),name_size);
02691 {
02692 c->hard_clear();
02693 c->packet_type=PACKET_TYPE_COMMAND;
02694 c->size=sizeof(c);
02695 c->version=1;
02696 c->command=CMD_REPL_USER_01_1;
02697
02698 memcpy(c->command_data.cmd_repl_user_01_1.name,name,name_size);
02699
02700 c->command_data.cmd_repl_user_01_1.host_unknown=u.host_unknown;
02701 c->command_data.cmd_repl_user_01_1.host_bot=u.host_bot;
02702 c->command_data.cmd_repl_user_01_1.is_template=u.is_template;
02703 c->command_data.cmd_repl_user_01_1.access_grant_partyline=u.access_grant_partyline;
02704 c->command_data.cmd_repl_user_01_1.access_to_backup=u.access_to_backup;
02705 c->command_data.cmd_repl_user_01_1.access_grant_backup=u.access_grant_backup;
02706 c->command_data.cmd_repl_user_01_1.access_to_rehash=u.access_to_rehash;
02707 c->command_data.cmd_repl_user_01_1.access_grant_rehash=u.access_grant_rehash;
02708
02709 c->command_data.cmd_repl_user_01_1.access_to_plususer=u.access_to_plususer;
02710 c->command_data.cmd_repl_user_01_1.access_grant_plususer=u.access_grant_plususer;
02711 c->command_data.cmd_repl_user_01_1.access_to_plusproc=u.access_to_plusproc;
02712 c->command_data.cmd_repl_user_01_1.access_grant_plusproc=u.access_grant_plusproc;
02713
02714 c->command_data.cmd_repl_user_01_1.access_to_partyline=u.access_to_partyline;
02715 c->command_data.cmd_repl_user_01_1.partyline_msg_flood.lines=u.partyline_msg_flood.lines;
02716 c->command_data.cmd_repl_user_01_1.partyline_msg_flood.seconds=u.partyline_msg_flood.seconds;
02717 c->command_data.cmd_repl_user_01_1.last_changed=(my_time_t)u.last_changed;
02718
02719 c->command_data.cmd_repl_user_01_1.access_to_can_send_all_users=u.access_to_can_send_all_users;
02720 c->command_data.cmd_repl_user_01_1.access_grant_can_send_all_users=u.access_grant_can_send_all_users;
02721
02722 c->command_data.cmd_repl_user_01_1.access_to_can_send_unknown_users=u.access_to_can_send_unknown_users;
02723 c->command_data.cmd_repl_user_01_1.access_grant_can_send_unknown_users=u.access_grant_can_send_unknown_users;
02724
02725 botnet_send_command(bot,c);
02726 }
02727 {
02728 int data_size=sizeof(c->command_data.cmd_repl_user_02_1.hostmask);
02729 char* data=new char[data_size+1];
02730
02731 vector<string>::iterator i2;
02732 for(i2=u.hostmask.begin(); i2!=u.hostmask.end(); i2++) {
02733 c->hard_clear();
02734 c->packet_type=PACKET_TYPE_COMMAND;
02735 c->size=sizeof(c);
02736 c->version=1;
02737 c->command=CMD_REPL_USER_02_1;
02738
02739 memcpy(c->command_data.cmd_repl_user_02_1.name,name,name_size);
02740
02741 memset(data,0,data_size);
02742 strncpy(data,(*i2).c_str(),data_size);
02743
02744 memcpy(c->command_data.cmd_repl_user_02_1.hostmask,data,name_size);
02745
02746 botnet_send_command(bot,c);
02747 }
02748 delete[] data;
02749 }
02750 {
02751 int data_size=sizeof(c->command_data.cmd_repl_user_03_1.fullname);
02752 char* data=new char[data_size+1];
02753
02754 vector<string>::iterator i2;
02755 for(i2=u.fullname.begin(); i2!=u.fullname.end(); i2++) {
02756 c->hard_clear();
02757 c->packet_type=PACKET_TYPE_COMMAND;
02758 c->size=sizeof(c);
02759 c->version=1;
02760 c->command=CMD_REPL_USER_03_1;
02761
02762 memcpy(c->command_data.cmd_repl_user_03_1.name,name,name_size);
02763
02764 memset(data,0,data_size);
02765 strncpy(data,(*i2).c_str(),data_size);
02766
02767 memcpy(c->command_data.cmd_repl_user_03_1.fullname,data,name_size);
02768
02769 botnet_send_command(bot,c);
02770 }
02771 delete[] data;
02772 }
02773 {
02774 int data_size=sizeof(c->command_data.cmd_repl_user_04_1.access_to_group);
02775 char* data=new char[data_size+1];
02776
02777 vector<string>::iterator i2;
02778 for(i2=u.access_to_group.begin(); i2!=u.access_to_group.end(); i2++) {
02779 c->hard_clear();
02780 c->packet_type=PACKET_TYPE_COMMAND;
02781 c->size=sizeof(c);
02782 c->version=1;
02783 c->command=CMD_REPL_USER_04_1;
02784
02785 memcpy(c->command_data.cmd_repl_user_04_1.name,name,name_size);
02786
02787 memset(data,0,data_size);
02788 strncpy(data,(*i2).c_str(),data_size);
02789
02790 memcpy(c->command_data.cmd_repl_user_04_1.access_to_group,data,name_size);
02791
02792 botnet_send_command(bot,c);
02793 }
02794 delete[] data;
02795 }
02796 {
02797 int data_size=sizeof(c->command_data.cmd_repl_user_05_1.access_to_proc);
02798 char* data=new char[data_size+1];
02799
02800 vector<string>::iterator i2;
02801 for(i2=u.access_to_proc.begin(); i2!=u.access_to_proc.end(); i2++) {
02802 c->hard_clear();
02803 c->packet_type=PACKET_TYPE_COMMAND;
02804 c->size=sizeof(c);
02805 c->version=1;
02806 c->command=CMD_REPL_USER_05_1;
02807
02808 memcpy(c->command_data.cmd_repl_user_05_1.name,name,name_size);
02809
02810 memset(data,0,data_size);
02811 strncpy(data,(*i2).c_str(),data_size);
02812
02813 memcpy(c->command_data.cmd_repl_user_05_1.access_to_proc,data,name_size);
02814
02815 botnet_send_command(bot,c);
02816 }
02817 delete[] data;
02818 }
02819 {
02820 int data_size=sizeof(c->command_data.cmd_repl_user_06_1.access_grant_proc);
02821 char* data=new char[data_size+1];
02822
02823 vector<string>::iterator i2;
02824 for(i2=u.access_grant_procedure.begin(); i2!=u.access_grant_procedure.end(); i2++) {
02825 c->hard_clear();
02826 c->packet_type=PACKET_TYPE_COMMAND;
02827 c->size=sizeof(c);
02828 c->version=1;
02829 c->command=CMD_REPL_USER_06_1;
02830
02831 memcpy(c->command_data.cmd_repl_user_06_1.name,name,name_size);
02832
02833 memset(data,0,data_size);
02834 strncpy(data,(*i2).c_str(),data_size);
02835
02836 memcpy(c->command_data.cmd_repl_user_06_1.access_grant_proc,data,name_size);
02837
02838 botnet_send_command(bot,c);
02839 }
02840 delete[] data;
02841 }
02842 {
02843 int data_size=sizeof(c->command_data.cmd_repl_user_07_1.access_grant_group);
02844 char* data=new char[data_size+1];
02845
02846 vector<string>::iterator i2;
02847 for(i2=u.access_grant_group.begin(); i2!=u.access_grant_group.end(); i2++) {
02848 c->hard_clear();
02849 c->packet_type=PACKET_TYPE_COMMAND;
02850 c->size=sizeof(c);
02851 c->version=1;
02852 c->command=CMD_REPL_USER_07_1;
02853
02854 memcpy(c->command_data.cmd_repl_user_07_1.name,name,name_size);
02855
02856 memset(data,0,data_size);
02857 strncpy(data,(*i2).c_str(),data_size);
02858
02859 memcpy(c->command_data.cmd_repl_user_07_1.access_grant_group,data,name_size);
02860
02861 botnet_send_command(bot,c);
02862 }
02863 delete[] data;
02864 }
02865 {
02866 int data_size=sizeof(c->command_data.cmd_repl_user_08_1.access_to_channel);
02867 char* data=new char[data_size+1];
02868
02869 vector<string>::iterator i2;
02870 for(i2=u.access_to_channel.begin(); i2!=u.access_to_channel.end(); i2++) {
02871 c->hard_clear();
02872 c->packet_type=PACKET_TYPE_COMMAND;
02873 c->size=sizeof(c);
02874 c->version=1;
02875 c->command=CMD_REPL_USER_08_1;
02876
02877 memcpy(c->command_data.cmd_repl_user_08_1.name,name,name_size);
02878
02879 memset(data,0,data_size);
02880 strncpy(data,(*i2).c_str(),data_size);
02881
02882 memcpy(c->command_data.cmd_repl_user_08_1.access_to_channel,data,name_size);
02883
02884 botnet_send_command(bot,c);
02885 }
02886 delete[] data;
02887 }
02888 {
02889 int data_size=sizeof(c->command_data.cmd_repl_user_09_1.access_grant_channel);
02890 char* data=new char[data_size+1];
02891
02892 vector<string>::iterator i2;
02893 for(i2=u.access_grant_channel.begin(); i2!=u.access_grant_channel.end(); i2++) {
02894 c->hard_clear();
02895 c->packet_type=PACKET_TYPE_COMMAND;
02896 c->size=sizeof(c);
02897 c->version=1;
02898 c->command=CMD_REPL_USER_09_1;
02899
02900 memcpy(c->command_data.cmd_repl_user_09_1.name,name,name_size);
02901
02902 memset(data,0,data_size);
02903 strncpy(data,(*i2).c_str(),data_size);
02904
02905 memcpy(c->command_data.cmd_repl_user_09_1.access_grant_channel,data,name_size);
02906
02907 botnet_send_command(bot,c);
02908 }
02909 delete[] data;
02910 }
02911 {
02912 int data_size=sizeof(c->command_data.cmd_repl_user_10_1.group);
02913 char* data=new char[data_size+1];
02914
02915 vector<s_group>::iterator i2;
02916 for(i2=u.groups.begin(); i2!=u.groups.end(); i2++) {
02917 c->hard_clear();
02918 c->packet_type=PACKET_TYPE_COMMAND;
02919 c->size=sizeof(c);
02920 c->version=1;
02921 c->command=CMD_REPL_USER_10_1;
02922
02923 memcpy(c->command_data.cmd_repl_user_10_1.name,name,name_size);
02924
02925 memset(data,0,data_size);
02926 strncpy(data,(*i2).name.c_str(),data_size);
02927
02928 memcpy(c->command_data.cmd_repl_user_10_1.group,data,name_size);
02929
02930 botnet_send_command(bot,c);
02931 }
02932 delete[] data;
02933 }
02934 {
02935 int data_size=sizeof(c->command_data.cmd_repl_user_11_1.dcc_host);
02936 char* data=new char[data_size+1];
02937
02938 vector<s_dcc_host>::iterator i2;
02939 for(i2=u.dcc_hosts.begin(); i2!=u.dcc_hosts.end(); i2++) {
02940 c->hard_clear();
02941 c->packet_type=PACKET_TYPE_COMMAND;
02942 c->size=sizeof(c);
02943 c->version=1;
02944 c->command=CMD_REPL_USER_11_1;
02945
02946 memcpy(c->command_data.cmd_repl_user_11_1.name,name,name_size);
02947
02948 memset(data,0,data_size);
02949 strncpy(data,(*i2).host.c_str(),data_size);
02950
02951 c->command_data.cmd_repl_user_11_1.dcc_group=(*i2).group;
02952 memcpy(c->command_data.cmd_repl_user_11_1.dcc_host,data,name_size);
02953
02954 botnet_send_command(bot,c);
02955 }
02956 delete[] data;
02957 }
02958 {
02959 int data_size=sizeof(c->command_data.cmd_repl_user_12_1.channel);
02960 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_deop))
02961 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_deop);
02962 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_ban))
02963 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_ban);
02964 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_unban))
02965 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_unban);
02966 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_kick))
02967 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_kick);
02968 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_op))
02969 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_op);
02970 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_voice))
02971 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_voice);
02972 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_devoice))
02973 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_devoice);
02974 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_creator))
02975 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_creator);
02976 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_decreator))
02977 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_decreator);
02978 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_join))
02979 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_join);
02980 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_banned))
02981 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_banned);
02982 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_flood))
02983 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_flood);
02984 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_privmsg))
02985 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_privmsg);
02986 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_notice))
02987 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_notice);
02988
02989 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_except))
02990 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_except);
02991 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_unexcept))
02992 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_unexcept);
02993 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_invite))
02994 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_invite);
02995 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_uninvite))
02996 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_uninvite);
02997 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_not_invited))
02998 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_not_invited);
02999 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_not_in_reop))
03000 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_not_in_reop);
03001 if(data_size<sizeof(c->command_data.cmd_repl_user_12_1.on_reop))
03002 data_size=sizeof(c->command_data.cmd_repl_user_12_1.on_reop);
03003
03004 char* data=new char[data_size+1];
03005
03006 int dpm_size=sizeof(c->command_data.cmd_repl_user_12_1.dynamic_plus_modes);
03007 int dmm_size=sizeof(c->command_data.cmd_repl_user_12_1.dynamic_plus_modes);
03008
03009 char* plus=new char[dpm_size];
03010 char* minus=new char[dmm_size];
03011
03012 vector<s_channel> chans;
03013 logic_botnet_get_user_channels(u.name,chans);
03014
03015 vector<s_channel>::iterator i2;
03016 for(i2=chans.begin(); i2!=chans.end(); i2++) {
03017 c->hard_clear();
03018 c->packet_type=PACKET_TYPE_COMMAND;
03019 c->size=sizeof(c);
03020 c->version=1;
03021 c->command=CMD_REPL_USER_12_1;
03022
03023 memcpy(c->command_data.cmd_repl_user_12_1.name,name,name_size);
03024
03025 memset(data,0,data_size);
03026 strncpy(data,(*i2).channel_name.c_str(),data_size);
03027 memcpy(c->command_data.cmd_repl_user_12_1.channel,data,sizeof(c->command_data.cmd_repl_user_12_1.channel));
03028
03029 memset(data,0,data_size);
03030 strncpy(data,(*i2).on_deop.c_str(),data_size);
03031 memcpy(c->command_data.cmd_repl_user_12_1.on_deop,data,sizeof(c->command_data.cmd_repl_user_12_1.on_deop));
03032
03033 memset(data,0,data_size);
03034 strncpy(data,(*i2).on_ban.c_str(),data_size);
03035 memcpy(c->command_data.cmd_repl_user_12_1.on_ban,data,sizeof(c->command_data.cmd_repl_user_12_1.on_ban));
03036
03037 memset(data,0,data_size);
03038 strncpy(data,(*i2).on_unban.c_str(),data_size);
03039 memcpy(c->command_data.cmd_repl_user_12_1.on_unban,data,sizeof(c->command_data.cmd_repl_user_12_1.on_unban));
03040
03041 memset(data,0,data_size);
03042 strncpy(data,(*i2).on_kick.c_str(),data_size);
03043 memcpy(c->command_data.cmd_repl_user_12_1.on_kick,data,sizeof(c->command_data.cmd_repl_user_12_1.on_kick));
03044
03045 memset(data,0,data_size);
03046 strncpy(data,(*i2).on_op.c_str(),data_size);
03047 memcpy(c->command_data.cmd_repl_user_12_1.on_op,data,sizeof(c->command_data.cmd_repl_user_12_1.on_op));
03048
03049 memset(data,0,data_size);
03050 strncpy(data,(*i2).on_voice.c_str(),data_size);
03051 memcpy(c->command_data.cmd_repl_user_12_1.on_voice,data,sizeof(c->command_data.cmd_repl_user_12_1.on_voice));
03052
03053 memset(data,0,data_size);
03054 strncpy(data,(*i2).on_devoice.c_str(),data_size);
03055 memcpy(c->command_data.cmd_repl_user_12_1.on_devoice,data,sizeof(c->command_data.cmd_repl_user_12_1.on_devoice));
03056
03057 memset(data,0,data_size);
03058 strncpy(data,(*i2).on_creator.c_str(),data_size);
03059 memcpy(c->command_data.cmd_repl_user_12_1.on_creator,data,sizeof(c->command_data.cmd_repl_user_12_1.on_creator));
03060
03061 memset(data,0,data_size);
03062 strncpy(data,(*i2).on_decreator.c_str(),data_size);
03063 memcpy(c->command_data.cmd_repl_user_12_1.on_decreator,data,sizeof(c->command_data.cmd_repl_user_12_1.on_decreator));
03064
03065 memset(data,0,data_size);
03066 strncpy(data,(*i2).on_join.c_str(),data_size);
03067 memcpy(c->command_data.cmd_repl_user_12_1.on_join,data,sizeof(c->command_data.cmd_repl_user_12_1.on_join));
03068
03069 memset(data,0,data_size);
03070 strncpy(data,(*i2).on_banned.c_str(),data_size);
03071 memcpy(c->command_data.cmd_repl_user_12_1.on_banned,data,sizeof(c->command_data.cmd_repl_user_12_1.on_banned));
03072
03073 memset(data,0,data_size);
03074 strncpy(data,(*i2).on_flood.c_str(),data_size);
03075 memcpy(c->command_data.cmd_repl_user_12_1.on_flood,data,sizeof(c->command_data.cmd_repl_user_12_1.on_flood));
03076
03077 memset(data,0,data_size);
03078 strncpy(data,(*i2).on_privmsg.c_str(),data_size);
03079 memcpy(c->command_data.cmd_repl_user_12_1.on_privmsg,data,sizeof(c->command_data.cmd_repl_user_12_1.on_privmsg));
03080
03081 memset(data,0,data_size);
03082 strncpy(data,(*i2).on_notice.c_str(),data_size);
03083 memcpy(c->command_data.cmd_repl_user_12_1.on_notice,data,sizeof(c->command_data.cmd_repl_user_12_1.on_notice));
03084
03085 memset(data,0,data_size);
03086 strncpy(data,(*i2).on_except.c_str(),data_size);
03087 memcpy(c->command_data.cmd_repl_user_12_1.on_except,data,sizeof(c->command_data.cmd_repl_user_12_1.on_except));
03088
03089 memset(data,0,data_size);
03090 strncpy(data,(*i2).on_unexcept.c_str(),data_size);
03091 memcpy(c->command_data.cmd_repl_user_12_1.on_unexcept,data,sizeof(c->command_data.cmd_repl_user_12_1.on_unexcept));
03092
03093 memset(data,0,data_size);
03094 strncpy(data,(*i2).on_invite.c_str(),data_size);
03095 memcpy(c->command_data.cmd_repl_user_12_1.on_invite,data,sizeof(c->command_data.cmd_repl_user_12_1.on_invite));
03096
03097 memset(data,0,data_size);
03098 strncpy(data,(*i2).on_uninvite.c_str(),data_size);
03099 memcpy(c->command_data.cmd_repl_user_12_1.on_uninvite,data,sizeof(c->command_data.cmd_repl_user_12_1.on_uninvite));
03100
03101 memset(data,0,data_size);
03102 strncpy(data,(*i2).on_not_invited.c_str(),data_size);
03103 memcpy(c->command_data.cmd_repl_user_12_1.on_not_invited,data,sizeof(c->command_data.cmd_repl_user_12_1.on_not_invited));
03104
03105 memset(data,0,data_size);
03106 strncpy(data,(*i2).on_not_in_reop.c_str(),data_size);
03107 memcpy(c->command_data.cmd_repl_user_12_1.on_not_in_reop,data,sizeof(c->command_data.cmd_repl_user_12_1.on_not_in_reop));
03108
03109 memset(data,0,data_size);
03110 strncpy(data,(*i2).on_reop.c_str(),data_size);
03111 memcpy(c->command_data.cmd_repl_user_12_1.on_reop,data,sizeof(c->command_data.cmd_repl_user_12_1.on_reop));
03112
03113 c->command_data.cmd_repl_user_12_1.msg_flood_l=(*i2).msg_flood.lines;
03114 c->command_data.cmd_repl_user_12_1.msg_flood_s=(my_time_t)(*i2).msg_flood.seconds;
03115
03116 c->command_data.cmd_repl_user_12_1.notice_flood_l=(*i2).notice_flood.lines;
03117 c->command_data.cmd_repl_user_12_1.notice_flood_s=(my_time_t)(*i2).notice_flood.seconds;
03118
03119 c->command_data.cmd_repl_user_12_1.repeat_flood_l=(*i2).repeat_flood.lines;
03120 c->command_data.cmd_repl_user_12_1.repeat_flood_s=(my_time_t)(*i2).repeat_flood.seconds;
03121
03122 c->command_data.cmd_repl_user_12_1.nick_flood_l=(*i2).nick_flood.lines;
03123 c->command_data.cmd_repl_user_12_1.nick_flood_s=(my_time_t)(*i2).nick_flood.seconds;
03124
03125 c->command_data.cmd_repl_user_12_1.join_flood_l=(*i2).join_flood.lines;
03126 c->command_data.cmd_repl_user_12_1.join_flood_s=(my_time_t)(*i2).join_flood.seconds;
03127
03128 c->command_data.cmd_repl_user_12_1.mode_flood_l=(*i2).mode_flood.lines;
03129 c->command_data.cmd_repl_user_12_1.mode_flood_s=(my_time_t)(*i2).mode_flood.seconds;
03130
03131 c->command_data.cmd_repl_user_12_1.ctcp_flood_l=(*i2).ctcp_flood.lines;
03132 c->command_data.cmd_repl_user_12_1.ctcp_flood_s=(my_time_t)(*i2).ctcp_flood.seconds;
03133
03134 memset(plus,0,dpm_size);
03135 strncpy(plus,(*i2).dynamic_plus_modes.c_str(),dpm_size);
03136 memcpy(c->command_data.cmd_repl_user_12_1.dynamic_plus_modes,data,sizeof(c->command_data.cmd_repl_user_12_1.dynamic_plus_modes));
03137
03138 memset(minus,0,dmm_size);
03139 strncpy(minus,(*i2).dynamic_minus_modes.c_str(),dmm_size);
03140 memcpy(c->command_data.cmd_repl_user_12_1.dynamic_minus_modes,data,sizeof(c->command_data.cmd_repl_user_12_1.dynamic_minus_modes));
03141
03142 c->command_data.cmd_repl_user_12_1.can_send_unknown_users=(*i2).can_send_unknown_users;
03143
03144 botnet_send_command(bot,c);
03145 }
03146 delete[] data;
03147 delete[] plus;
03148 delete[] minus;
03149 }
03150 {
03151 int g_size=sizeof(c->command_data.cmd_repl_user_13_1.group);
03152 char* g=new char[g_size+1];
03153
03154 int pm_size=sizeof(c->command_data.cmd_repl_user_13_1.plus_modes);
03155 char* pm=new char[pm_size+1];
03156
03157 int mm_size=sizeof(c->command_data.cmd_repl_user_13_1.minus_modes);
03158 char* mm=new char[mm_size+1];
03159
03160 int ch_size=sizeof(c->command_data.cmd_repl_user_13_1.channel);
03161 char* ch=new char[ch_size+1];
03162
03163 vector<s_channel> chans;
03164 logic_botnet_get_user_channels(u.name,chans);
03165
03166 vector<s_channel>::iterator i3;
03167 for(i3=chans.begin(); i3!=chans.end(); i3++) {
03168 vector<s_dynamic_rule>::iterator i2;
03169 for(i2=(*i3).allow_dynamic.begin(); i2!=(*i3).allow_dynamic.end(); i2++) {
03170 c->hard_clear();
03171 c->packet_type=PACKET_TYPE_COMMAND;
03172 c->size=sizeof(c);
03173 c->version=1;
03174 c->command=CMD_REPL_USER_13_1;
03175
03176 memcpy(c->command_data.cmd_repl_user_13_1.name,name,name_size);
03177
03178 memset(ch,0,ch_size);
03179 strncpy(ch,(*i3).channel_name.c_str(),ch_size);
03180 memcpy(c->command_data.cmd_repl_user_13_1.channel,ch,sizeof(c->command_data.cmd_repl_user_13_1.channel));
03181
03182 memset(g,0,g_size);
03183 strncpy(g,(*i2).group.c_str(),g_size);
03184
03185 memset(pm,0,pm_size);
03186 strncpy(pm,(*i2).plus_modes.c_str(),pm_size);
03187
03188 memset(mm,0,mm_size);
03189 strncpy(mm,(*i2).minus_modes.c_str(),mm_size);
03190
03191 memcpy(c->command_data.cmd_repl_user_13_1.group,g,g_size);
03192 memcpy(c->command_data.cmd_repl_user_13_1.plus_modes,pm,pm_size);
03193 memcpy(c->command_data.cmd_repl_user_13_1.minus_modes,mm,mm_size);
03194
03195 botnet_send_command(bot,c);
03196 }
03197 }
03198 delete[] g;
03199 delete[] pm;
03200 delete[] mm;
03201 delete[] ch;
03202 }
03203
03204 {
03205 int meta_key_size=sizeof(c->command_data.cmd_repl_user_14_1.meta_key);
03206 char* k=new char[meta_key_size+1];
03207
03208 int meta_val_size=sizeof(c->command_data.cmd_repl_user_14_1.meta_val);
03209 char* v=new char[meta_val_size+1];
03210
03211 map<string,string>::iterator i3;
03212 for(i3=u.meta.begin(); i3!=u.meta.end(); i3++) {
03213 c->packet_type=PACKET_TYPE_COMMAND;
03214 c->size=sizeof(c);
03215 c->version=1;
03216 c->command=CMD_REPL_USER_14_1;
03217
03218 memcpy(c->command_data.cmd_repl_user_14_1.name,name,name_size);
03219
03220 memset(k,0,meta_key_size);
03221 strncpy(k,(*i3).first.c_str(),meta_key_size);
03222 memcpy(c->command_data.cmd_repl_user_14_1.meta_key,k,sizeof(c->command_data.cmd_repl_user_14_1.meta_key));
03223
03224 memset(v,0,meta_val_size);
03225 strncpy(v,(*i3).second.c_str(),meta_val_size);
03226 memcpy(c->command_data.cmd_repl_user_14_1.meta_val,v,sizeof(c->command_data.cmd_repl_user_14_1.meta_val));
03227
03228 botnet_send_command(bot,c);
03229 }
03230
03231 delete[] k;
03232 delete[] v;
03233 }
03234
03235 {
03236 int data_size=sizeof(c->command_data.cmd_repl_user_15_1.access_usage_proc);
03237 char* data=new char[data_size+1];
03238
03239 vector<string>::iterator i2;
03240 for(i2=u.access_usage_procedure.begin(); i2!=u.access_usage_procedure.end(); i2++) {
03241 c->hard_clear();
03242 c->packet_type=PACKET_TYPE_COMMAND;
03243 c->size=sizeof(c);
03244 c->version=1;
03245 c->command=CMD_REPL_USER_15_1;
03246
03247 memcpy(c->command_data.cmd_repl_user_15_1.name,name,name_size);
03248
03249 memset(data,0,data_size);
03250 strncpy(data,(*i2).c_str(),data_size);
03251
03252 memcpy(c->command_data.cmd_repl_user_15_1.access_usage_proc,data,name_size);
03253
03254 botnet_send_command(bot,c);
03255 }
03256 delete[] data;
03257 }
03258 if(bot->supported_proto_version>=5) {
03259 c->hard_clear();
03260 c->packet_type=PACKET_TYPE_COMMAND;
03261 c->size=sizeof(c);
03262 c->version=5;
03263 c->command=CMD_REPL_USER_16_5;
03264
03265 memcpy(c->command_data.cmd_repl_user_16_5.name,name,name_size);
03266
03267 c->command_data.cmd_repl_user_16_5.access_to_upgrade=u.access_to_upgrade;
03268 c->command_data.cmd_repl_user_16_5.access_grant_upgrade=u.access_grant_upgrade;
03269
03270 botnet_send_command(bot,c);
03271 }
03272 if(bot->supported_proto_version>=9) {
03273 c->hard_clear();
03274 c->packet_type=PACKET_TYPE_COMMAND;
03275 c->size=sizeof(c);
03276 c->version=9;
03277 c->command=CMD_REPL_USER_17_9;
03278
03279 memcpy(c->command_data.cmd_repl_user_17_9.name,name,name_size);
03280
03281 c->command_data.cmd_repl_user_17_9.access_to_apply=u.access_to_apply;
03282 c->command_data.cmd_repl_user_17_9.access_grant_apply=u.access_grant_apply;
03283
03284 botnet_send_command(bot,c);
03285 }
03286
03287 {
03288 c->hard_clear();
03289 c->packet_type=PACKET_TYPE_COMMAND;
03290 c->size=sizeof(c);
03291 c->version=1;
03292 c->command=CMD_REPL_USER_99_1;
03293
03294 memcpy(c->command_data.cmd_repl_user_99_1.name,name,name_size);
03295
03296 botnet_send_command(bot,c);
03297 }
03298
03299 delete[] name;
03300 delete c;
03301
03302 string d="replication: PUSH of object ";
03303 d+="(user) ";
03304 d+=u.name;
03305 log_botnet_debug(botnet_botname,bot->botname.c_str(),-1,-1,d.c_str());
03306 log_botnet(botnet_botname,bot->botname.c_str(),d.c_str());
03307
03308 {
03309 string obj_type="user";
03310 string reason="OK";
03311 string obj=u.name;
03312
03313 logic_on_internal_event("@botnet_replication@",bot->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,d,"PUSH");
03314 }
03315 }
03316
03317
03318
03319
03320
03321
03322
03323
03324
03325 void botnet_push_proc(s_bot* bot, s_procedure& p)
03326 {
03327 bot->last_proc_push=time(NULL);
03328
03329 stats_botnet_proc_pushed();
03330
03331 if(p.last_changed==0)
03332 time(&p.last_changed);
03333
03334 list<string> commands;
03335 string decl;
03336 vector<string> groups;
03337 logic_list_proc(p.name,commands,decl,groups);
03338
03339 s_bot_command* c=new s_bot_command;
03340 int name_size=sizeof(c->command_data.cmd_proc_1.name);
03341 char* name=new char[name_size];
03342 memset(name,0,name_size);
03343 strncpy(name,p.name.c_str(),name_size);
03344 bool init=true;
03345 list<string>::iterator i1;
03346 for(i1=commands.begin(); i1!=commands.end(); i1++) {
03347 c->hard_clear();
03348 c->packet_type=PACKET_TYPE_COMMAND;
03349 c->size=sizeof(c);
03350 c->version=1;
03351 c->command=CMD_PROC_1;
03352
03353 c->command_data.cmd_proc_1.last_changed=(my_time_t)p.last_changed;
03354
03355 memcpy(c->command_data.cmd_proc_1.name,name,name_size);
03356
03357 c->command_data.cmd_proc_1.init=init;
03358 init=false;
03359
03360 if((*i1).length()<sizeof(c->command_data.cmd_proc_1.line))
03361 strcpy(c->command_data.cmd_proc_1.line,(*i1).c_str());
03362
03363 botnet_send_command(bot,c);
03364 }
03365
03366 c->hard_clear();
03367 c->packet_type=PACKET_TYPE_COMMAND;
03368 c->size=sizeof(c);
03369 c->version=1;
03370 c->command=CMD_PROC_END_1;
03371
03372 memcpy(c->command_data.cmd_proc_1.name,name,name_size);
03373
03374 botnet_send_command(bot,c);
03375
03376 delete c;
03377
03378 string d="replication: PUSH of object ";
03379 d+="(procedure) ";
03380 d+=p.name;
03381 log_botnet_debug(botnet_botname,bot->botname.c_str(),-1,-1,d.c_str());
03382 log_botnet(botnet_botname,bot->botname.c_str(),d.c_str());
03383
03384 {
03385 string obj_type="procedure";
03386 string reason="OK";
03387 string obj=p.name;
03388
03389 logic_on_internal_event("@botnet_replication@",bot->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,d,"PUSH");
03390 }
03391 }
03392
03393
03394
03395
03396
03397
03398
03399
03400
03401 void botnet_push_chan(s_bot* bot, s_channel_def& chd)
03402 {
03403 stats_botnet_chandef_pushed();
03404
03405 if(chd.last_changed==0)
03406 time(&chd.last_changed);
03407
03408 s_bot_command* c=new s_bot_command;
03409 int name_size=sizeof(c->command_data.cmd_repl_chdef_01_1.name);
03410 char* name=new char[name_size];
03411 memset(name,0,name_size);
03412 strncpy(name,chd.channel_name.c_str(),name_size);
03413
03414 {
03415 c->hard_clear();
03416 c->packet_type=PACKET_TYPE_COMMAND;
03417 c->size=sizeof(c);
03418 c->version=1;
03419 c->command=CMD_REPL_CHDEF_01_1;
03420
03421 c->command_data.cmd_repl_chdef_01_1.last_changed=(my_time_t)chd.last_changed;
03422
03423 memcpy(c->command_data.cmd_repl_chdef_01_1.name,name,name_size);
03424
03425 int _size=sizeof(c->command_data.cmd_repl_chdef_01_1.on_mode);
03426 if(_size>sizeof(c->command_data.cmd_repl_chdef_01_1.on_key))
03427 _size=sizeof(c->command_data.cmd_repl_chdef_01_1.on_key);
03428 if(_size>sizeof(c->command_data.cmd_repl_chdef_01_1.on_limit))
03429 _size=sizeof(c->command_data.cmd_repl_chdef_01_1.on_limit);
03430 if(_size>sizeof(c->command_data.cmd_repl_chdef_01_1.on_topic))
03431 _size=sizeof(c->command_data.cmd_repl_chdef_01_1.on_topic);
03432 if(_size>sizeof(c->command_data.cmd_repl_chdef_01_1.on_ircop))
03433 _size=sizeof(c->command_data.cmd_repl_chdef_01_1.on_ircop);
03434 if(_size>sizeof(c->command_data.cmd_repl_chdef_01_1.on_ctcp))
03435 _size=sizeof(c->command_data.cmd_repl_chdef_01_1.on_ctcp);
03436 if(_size>sizeof(c->command_data.cmd_repl_chdef_01_1.on_privmsg))
03437 _size=sizeof(c->command_data.cmd_repl_chdef_01_1.on_privmsg);
03438 if(_size>sizeof(c->command_data.cmd_repl_chdef_01_1.on_notice))
03439 _size=sizeof(c->command_data.cmd_repl_chdef_01_1.on_notice);
03440 if(_size>sizeof(c->command_data.cmd_repl_chdef_01_1.on_part))
03441 _size=sizeof(c->command_data.cmd_repl_chdef_01_1.on_part);
03442 if(_size>sizeof(c->command_data.cmd_repl_chdef_01_1.on_dynamic_ban))
03443 _size=sizeof(c->command_data.cmd_repl_chdef_01_1.on_dynamic_ban);
03444 int _size2=sizeof(c->command_data.cmd_repl_chdef_01_1.dynamic_plus_modes);
03445 if(_size2>sizeof(c->command_data.cmd_repl_chdef_01_1.dynamic_minus_modes))
03446 _size2=sizeof(c->command_data.cmd_repl_chdef_01_1.dynamic_minus_modes);
03447
03448 _size--;
03449 _size2--;
03450
03451 strncpy(c->command_data.cmd_repl_chdef_01_1.on_mode,chd.on_mode.c_str(),_size);
03452 strncpy(c->command_data.cmd_repl_chdef_01_1.on_key,chd.on_key.c_str(),_size);
03453 strncpy(c->command_data.cmd_repl_chdef_01_1.on_limit,chd.on_limit.c_str(),_size);
03454 strncpy(c->command_data.cmd_repl_chdef_01_1.on_topic,chd.on_topic.c_str(),_size);
03455 strncpy(c->command_data.cmd_repl_chdef_01_1.on_ircop,chd.on_ircop.c_str(),_size);
03456 strncpy(c->command_data.cmd_repl_chdef_01_1.on_ctcp,chd.on_ctcp.c_str(),_size);
03457 strncpy(c->command_data.cmd_repl_chdef_01_1.on_privmsg,chd.on_privmsg.c_str(),_size);
03458 strncpy(c->command_data.cmd_repl_chdef_01_1.on_notice,chd.on_notice.c_str(),_size);
03459 strncpy(c->command_data.cmd_repl_chdef_01_1.on_part,chd.on_part.c_str(),_size);
03460 strncpy(c->command_data.cmd_repl_chdef_01_1.on_dynamic_ban,chd.on_dynamic_ban.c_str(),_size);
03461
03462 strncpy(c->command_data.cmd_repl_chdef_01_1.dynamic_plus_modes,chd.dynamic_plus_modes.c_str(),_size2);
03463 strncpy(c->command_data.cmd_repl_chdef_01_1.dynamic_minus_modes,chd.dynamic_minus_modes.c_str(),_size2);
03464
03465 botnet_send_command(bot,c);
03466 }
03467 {
03468 vector<s_group>::iterator i1;
03469 for(i1=chd.groups.begin(); i1!=chd.groups.end(); i1++) {
03470
03471 c->hard_clear();
03472 c->packet_type=PACKET_TYPE_COMMAND;
03473 c->size=sizeof(c);
03474 c->version=1;
03475 c->command=CMD_REPL_CHDEF_02_1;
03476
03477 memcpy(c->command_data.cmd_repl_chdef_02_1.name,name,name_size);
03478
03479 strncpy(c->command_data.cmd_repl_chdef_02_1.group,(*i1).name.c_str(),sizeof(c->command_data.cmd_repl_chdef_02_1.group)-1);
03480
03481 botnet_send_command(bot,c);
03482 }
03483 }
03484 {
03485 vector<s_dynamic_rule>::iterator i1;
03486 for(i1=chd.allow_dynamic.begin(); i1!=chd.allow_dynamic.end(); i1++) {
03487
03488 c->hard_clear();
03489 c->packet_type=PACKET_TYPE_COMMAND;
03490 c->size=sizeof(c);
03491 c->version=1;
03492 c->command=CMD_REPL_CHDEF_03_1;
03493
03494 memcpy(c->command_data.cmd_repl_chdef_03_1.name,name,name_size);
03495
03496 strncpy(c->command_data.cmd_repl_chdef_03_1.group,(*i1).group.c_str(),sizeof(c->command_data.cmd_repl_chdef_03_1.group)-1);
03497 strncpy(c->command_data.cmd_repl_chdef_03_1.plus_modes,(*i1).plus_modes.c_str(),sizeof(c->command_data.cmd_repl_chdef_03_1.plus_modes)-1);
03498 strncpy(c->command_data.cmd_repl_chdef_03_1.minus_modes,(*i1).minus_modes.c_str(),sizeof(c->command_data.cmd_repl_chdef_03_1.minus_modes)-1);
03499
03500 botnet_send_command(bot,c);
03501 }
03502 }
03503 {
03504 map<string,string>::iterator i1;
03505 for(i1=chd.dynamic_bans.begin(); i1!=chd.dynamic_bans.end(); i1++) {
03506
03507 c->hard_clear();
03508 c->packet_type=PACKET_TYPE_COMMAND;
03509 c->size=sizeof(c);
03510 c->version=1;
03511 c->command=CMD_REPL_CHDEF_04_1;
03512
03513 memcpy(c->command_data.cmd_repl_chdef_04_1.name,name,name_size);
03514
03515 strncpy(c->command_data.cmd_repl_chdef_04_1.mask,(*i1).first.c_str(),sizeof(c->command_data.cmd_repl_chdef_04_1.mask)-1);
03516 strncpy(c->command_data.cmd_repl_chdef_04_1.reason,(*i1).second.c_str(),sizeof(c->command_data.cmd_repl_chdef_04_1.reason)-1);
03517
03518 botnet_send_command(bot,c);
03519 }
03520 }
03521 {
03522 vector<string>::iterator i1;
03523 for(i1=chd.dynbans_editors.begin(); i1!=chd.dynbans_editors.end(); i1++) {
03524
03525 c->hard_clear();
03526 c->packet_type=PACKET_TYPE_COMMAND;
03527 c->size=sizeof(c);
03528 c->version=1;
03529 c->command=CMD_REPL_CHDEF_05_1;
03530
03531 memcpy(c->command_data.cmd_repl_chdef_05_1.name,name,name_size);
03532
03533 strncpy(c->command_data.cmd_repl_chdef_05_1.group,(*i1).c_str(),sizeof(c->command_data.cmd_repl_chdef_05_1.group)-1);
03534
03535 botnet_send_command(bot,c);
03536 }
03537 }
03538 if(bot->supported_proto_version>=8) {
03539 c->hard_clear();
03540 c->packet_type=PACKET_TYPE_COMMAND;
03541 c->size=sizeof(c);
03542 c->version=8;
03543 c->command=CMD_REPL_CHDEF_06_8;
03544
03545 memcpy(c->command_data.cmd_repl_chdef_06_8.name,name,name_size);
03546
03547 strncpy(c->command_data.cmd_repl_chdef_06_8.on_server_msg,chd.on_server_msg.c_str(),sizeof(c->command_data.cmd_repl_chdef_06_8.on_server_msg)-1);
03548
03549 botnet_send_command(bot,c);
03550 }
03551 {
03552 c->hard_clear();
03553 c->packet_type=PACKET_TYPE_COMMAND;
03554 c->size=sizeof(c);
03555 c->version=1;
03556 c->command=CMD_REPL_CHDEF_99_1;
03557
03558 memcpy(c->command_data.cmd_repl_chdef_99_1.name,name,name_size);
03559
03560 botnet_send_command(bot,c);
03561 }
03562
03563 delete c;
03564
03565 string d="replication: PUSH of object ";
03566 d+="(channel) ";
03567 d+=chd.channel_name;
03568 log_botnet_debug(botnet_botname,bot->botname.c_str(),-1,-1,d.c_str());
03569 log_botnet(botnet_botname,bot->botname.c_str(),d.c_str());
03570
03571 {
03572 string obj_type="channel";
03573 string reason="OK";
03574 string obj=chd.channel_name;
03575
03576 logic_on_internal_event("@botnet_replication@",bot->botname,obj_type,obj,reason,PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,d,"PUSH");
03577 }
03578 }
03579
03580
03581
03582
03583
03584
03585
03586
03587
03588 void botnet_partyline_event(string origin_bot, s_bot_command* cmd)
03589 {
03590 string msg;
03591
03592 char* ch=NULL;
03593
03594 if(cmd->command==CMD_PARTYLINE_1) {
03595 uint32 id=cmd->command_data.cmd_partyline_1.id;
03596
03597 char* u=new char[sizeof(cmd->command_data.cmd_partyline_1.user)+1];
03598 u[sizeof(cmd->command_data.cmd_partyline_1.user)]=0;
03599 strncpy(u,cmd->command_data.cmd_partyline_1.user,sizeof(cmd->command_data.cmd_partyline_1.user));
03600
03601 ch=new char[sizeof(cmd->command_data.cmd_partyline_1.channel)+1];
03602 ch[sizeof(cmd->command_data.cmd_partyline_1.channel)]=0;
03603 strncpy(ch,cmd->command_data.cmd_partyline_1.channel,sizeof(cmd->command_data.cmd_partyline_1.channel));
03604
03605 char* m=new char[sizeof(cmd->command_data.cmd_partyline_1.message)+1];
03606 m[sizeof(cmd->command_data.cmd_partyline_1.message)]=0;
03607 strncpy(m,cmd->command_data.cmd_partyline_1.message,sizeof(cmd->command_data.cmd_partyline_1.message));
03608
03609 if(strlen(m)>0 && m[0]==0x01) {
03610 if(strstr(m,"\x01" "BROADCAST_PING\x01 ")==m) {
03611 msg=m;
03612
03613 char tmp[]="\x01" "BROADCAST_PONG\x01 ";
03614 strncpy(m,tmp,strlen(tmp));
03615 botnet_partyline_message(u,"",m);
03616
03617 {
03618 if(msg.find(" ",0)!=string::npos)
03619 msg.erase(0,msg.find(" ",0)+1);
03620 if(msg.find(" ",0)!=string::npos)
03621 msg.erase(0,msg.find(" ",0)+1);
03622 string user=msg;
03623 if(user.find(" ",0)!=string::npos)
03624 user.erase(user.find(" ",0),user.length()-user.find(" ",0));
03625
03626 string version="\x01" "BROADCAST_PONG\x02 VERSION ";
03627 version+=user;
03628 version+=" ";
03629 version+="VooDoo_cIRCle";
03630 version+=" ";
03631 version+=VERSION;
03632 version+=" ";
03633 version+=VERSION_COMMENT;
03634
03635 botnet_partyline_message(u,"",version);
03636 }
03637
03638 msg="";
03639 }
03640 if(strstr(m,"\x01" "BROADCAST_PONG\x01 ")==m) {
03641 msg=m;
03642 if(msg.find(" ",0)!=string::npos)
03643 msg.erase(0,msg.find(" ",0)+1);
03644 string time_=msg;
03645 if(msg.find(" ",0)!=string::npos)
03646 msg.erase(0,msg.find(" ",0)+1);
03647 if(time_.find(" ",0)!=string::npos)
03648 time_.erase(time_.find(" ",0),time_.length()-time_.find(" ",0));
03649 if(msg.find(" ",0)!=string::npos)
03650 msg.erase(msg.find(" ",0),msg.length()-msg.find(" ",0));
03651 if(!botnet_query_disp_id(cmd->command_data.cmd_partyline_1.id)) {
03652 dcc_user_pong(time_,msg,origin_bot);
03653 s_msg_id i;
03654 i.id=id;
03655 i.time=(my_time_t)time(NULL);
03656 msg_disp_ids.push_back(i);
03657 }
03658 msg="";
03659 }
03660 if(strstr(m,"\x01" "BROADCAST_PONG\x02 VERSION ")==m) {
03661 msg=m;
03662 if(msg.find(" ",0)!=string::npos)
03663 msg.erase(0,msg.find(" ",0)+1);
03664 if(msg.find(" ",0)!=string::npos)
03665 msg.erase(0,msg.find(" ",0)+1);
03666 string user=msg;
03667 if(user.find(" ",0)!=string::npos)
03668 user.erase(user.find(" ",0),user.length()-user.find(" ",0));
03669 if(msg.find(" ",0)!=string::npos)
03670 msg.erase(0,msg.find(" ",0)+1);
03671
03672 int ctx=0;
03673 string v1, v2, v3;
03674 for(unsigned i1=0; i1<msg.length(); i1++) {
03675 if(msg[i1]==0x20) {
03676 ctx++;
03677 continue;
03678 }
03679 if(ctx==0) {
03680 v1+=(string)""+msg[i1];
03681 continue;
03682 }
03683 if(ctx==1) {
03684 v2+=(string)""+msg[i1];
03685 continue;
03686 }
03687 if(ctx>=2) {
03688 v3+=(string)""+msg[i1];
03689 continue;
03690 }
03691 }
03692
03693 if(!botnet_query_disp_id(id)) {
03694 dcc_user_pong(user,origin_bot,v1,v2,v3);
03695 s_msg_id i;
03696 i.id=id;
03697 i.time=(my_time_t)time(NULL);
03698 msg_disp_ids.push_back(i);
03699 }
03700 msg="";
03701 }
03702 if(strstr(m,"\x01" "BROADCAST_ADMIN_MESSAGE\x01 ")==m) {
03703 msg=m;
03704 if(msg.find(" ",0)!=string::npos)
03705 msg.erase(0,msg.find(" ",0)+1);
03706
03707 string reserved1=msg;
03708 if(msg.find(" ",0)!=string::npos)
03709 msg.erase(0,msg.find(" ",0)+1);
03710 if(reserved1.find(" ",0)!=string::npos)
03711 reserved1.erase(reserved1.find(" ",0),reserved1.length()-reserved1.find(" ",0));
03712
03713 string reserved2=msg;
03714 if(msg.find(" ",0)!=string::npos)
03715 msg.erase(0,msg.find(" ",0)+1);
03716 if(reserved2.find(" ",0)!=string::npos)
03717 reserved2.erase(reserved2.find(" ",0),reserved2.length()-reserved2.find(" ",0));
03718
03719 string dest_bot=msg;
03720 if(msg.find(" ",0)!=string::npos)
03721 msg.erase(0,msg.find(" ",0)+1);
03722 if(dest_bot.find(" ",0)!=string::npos)
03723 dest_bot.erase(dest_bot.find(" ",0),dest_bot.length()-dest_bot.find(" ",0));
03724
03725 string dest_user=msg;
03726 if(msg.find(" ",0)!=string::npos)
03727 msg.erase(0,msg.find(" ",0)+1);
03728 if(dest_user.find(" ",0)!=string::npos)
03729 dest_user.erase(dest_user.find(" ",0),dest_user.length()-dest_user.find(" ",0));
03730
03731 if(!match((char*)dest_bot.c_str(),botnet_botname))
03732 if(!botnet_query_disp_id(id)) {
03733 dcc_broadcast(dest_user,msg,u,dest_bot);
03734 s_msg_id i;
03735 i.id=id;
03736 i.time=(my_time_t)time(NULL);
03737 msg_disp_ids.push_back(i);
03738 }
03739
03740 msg="";
03741 }
03742 } else {
03743 if(cmd->command_data.cmd_partyline_1.msg) {
03744 msg="<";
03745 msg+=u;
03746 msg+="@";
03747 msg+=origin_bot;
03748 msg+="> ";
03749 msg+=m;
03750 }
03751 if(cmd->command_data.cmd_partyline_1.join) {
03752 msg=u;
03753 msg+="@";
03754 msg+=origin_bot;
03755 msg+=" has joined channel ";
03756 msg+=ch;
03757 }
03758 if(cmd->command_data.cmd_partyline_1.leave) {
03759 msg=u;
03760 msg+="@";
03761 msg+=origin_bot;
03762 msg+=" has left channel ";
03763 msg+=ch;
03764 }
03765
03766 if(!botnet_query_disp_id(cmd->command_data.cmd_partyline_1.id)) {
03767 s_msg_id i;
03768 i.id=id;
03769 i.time=(my_time_t)time(NULL);
03770 msg_disp_ids.push_back(i);
03771 } else {
03772 msg="";
03773 }
03774 }
03775 delete[] u;
03776 delete[] m;
03777 }
03778 if(cmd->command==CMD_PARTYLINE_USER_1) {
03779 uint32 id=cmd->command_data.cmd_partyline_user_1.id;
03780
03781 char* u=new char[sizeof(cmd->command_data.cmd_partyline_user_1.user)+1];
03782 u[sizeof(cmd->command_data.cmd_partyline_user_1.user)]=0;
03783 strncpy(u,cmd->command_data.cmd_partyline_user_1.user,sizeof(cmd->command_data.cmd_partyline_user_1.user));
03784
03785 ch=new char[sizeof(cmd->command_data.cmd_partyline_user_1.channel)+1];
03786 ch[sizeof(cmd->command_data.cmd_partyline_user_1.channel)]=0;
03787 strncpy(ch,cmd->command_data.cmd_partyline_user_1.channel,sizeof(cmd->command_data.cmd_partyline_user_1.channel));
03788
03789 if(cmd->command_data.cmd_partyline_1.join) {
03790 msg=u;
03791 msg+="@";
03792 msg+=origin_bot;
03793 msg+=" has joined channel ";
03794 msg+=ch;
03795 msg+=" (after botnet-split)";
03796 }
03797
03798 if(!botnet_query_disp_id(cmd->command_data.cmd_partyline_1.id)) {
03799 s_msg_id i;
03800 i.id=id;
03801 i.time=(my_time_t)time(NULL);
03802 msg_disp_ids.push_back(i);
03803 } else {
03804 msg="";
03805 }
03806
03807 delete[] u;
03808 }
03809 if(msg.compare("") && ch!=NULL)
03810 dcc_partyline_message(ch,msg);
03811
03812 delete[] ch;
03813 }
03814
03815
03816
03817
03818
03819
03820
03821
03822
03823
03824 void botnet_on_unlink(string botname, string from_bot, int id)
03825 {
03826 vector<s_botnet_channel>::iterator i1;
03827 again2:
03828 for(i1=botnet_channels.begin(); i1!=botnet_channels.end(); i1++) {
03829 vector<s_partyline_member>::iterator i2;
03830 again:
03831 for(i2=(*i1).members.begin(); i2!=(*i1).members.end(); i2++) {
03832 if(!(*i2).botname.compare(botname)) {
03833 string msg=(*i2).user;
03834 msg+="@";
03835 msg+=botname;
03836 msg+=" has left channel ";
03837 msg+=(*i1).channel_name;
03838 msg+=" (botnet-split: ";
03839 msg+=botname;
03840 msg+=")";
03841 dcc_partyline_message((*i1).channel_name,msg);
03842 (*i1).members.erase(i2);
03843 goto again;
03844 }
03845 }
03846 if((*i1).members.empty()) {
03847 botnet_channels.erase(i1);
03848 goto again2;
03849 }
03850 }
03851 }
03852
03853
03854
03855
03856
03857
03858
03859
03860
03861
03862 bool botnet_has_grant(s_user& bot, string proc_name)
03863 {
03864 if(proc_name.empty())
03865 return true;
03866
03867 if(proc_name.find("(",0)!=string::npos)
03868 proc_name.erase(proc_name.find("(",0),proc_name.length()-proc_name.find("(",0));
03869
03870 vector<string>::iterator i1;
03871 for(i1=bot.access_usage_procedure.begin(); i1!=bot.access_usage_procedure.end(); i1++) {
03872 if(!(*i1).compare("*"))
03873 return true;
03874
03875 string name_only=*i1;
03876 if(name_only.find("(",0)!=string::npos)
03877 name_only.erase(name_only.find("(",0),name_only.length()-name_only.find("(",0));
03878
03879 if(!name_only.compare(proc_name))
03880 return true;
03881 }
03882
03883 return false;
03884 }
03885
03886
03887
03888
03889
03890
03891
03892 void botnet_loop()
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
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
03936
03937
03938
03939
03940
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
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
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:
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
04099
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) {
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
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
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
04289 proc_name_only=arg;
04290 } else {
04291
04292
04293
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
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);
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 ;
04332 }
04333 break;
04334 case CMD_CHECK_TIME_1:
04335 {
04336
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)";
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;
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)";
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;
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)";
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;
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)";
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)";
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;
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)";
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)";
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
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)";
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;
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)";
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)";
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)";
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)";
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)";
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;
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)";
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)";
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)";
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)";
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)";
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;
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)";
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)";
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)";
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)";
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)";
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;
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)";
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)";
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)";
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
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
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)";
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
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
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();
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
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
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
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
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
07964
07965
07966 l:
07967
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
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);
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
08081
08082
08083 delete *i1;
08084 bots.erase(i1);
08085 goto l;
08086 }
08087
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
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
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
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
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( 1) {
08313 time(&(*i1)->users_to_push_last_update);
08314
08315
08316
08317 for(int _i1_=0; _i1_<1; _i1_++) {
08318
08319 if((*i1)->last_proc_push==0 || (*i1)->last_proc_push+60>time(NULL))
08320 continue;
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
08376
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
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
08439
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 }
08575
08576
08577
08578
08579
08580
08581
08582
08583
08584
08585
08586
08587
08588 void botnet_received_data_from_telnet(s_socket& socket,string botname, char* buff, size_t buff_size, SSL* ssl, string remote_ip)
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 }
08641
08642
08643
08644
08645
08646
08647
08648
08649
08650 string botnet_partyline_join_channel(string user, string channel)
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
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 }
08724
08725
08726
08727
08728
08729
08730
08731
08732
08733 void botnet_partyline_leave_channel(string user, string channel)
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
08788 botnet_partyline_event(botnet_botname,c);
08789
08790 delete c;
08791 }
08792
08793
08794
08795
08796
08797
08798
08799
08800
08801
08802 void botnet_partyline_message(string user, string channel, string msg)
08803 {
08804 botnet_partyline_message(user, channel, msg, botnet_get_unique_id());
08805 }
08806
08807
08808
08809
08810
08811
08812
08813
08814
08815
08816
08817 void botnet_partyline_message(string user, string channel, string msg, uint32 id)
08818 {
08819 {
08820 vector<s_msg_id>::iterator i1;
08821 bool got=false;
08822 for(i1=msg_ids.begin(); i1!=msg_ids.end(); i1++)
08823 if((*i1).id==id) {
08824 got=true;
08825 break;
08826 }
08827 if(!got) {
08828 s_msg_id i;
08829 i.id=id;
08830 i.time=(my_time_t)time(NULL);
08831 msg_ids.push_back(i);
08832 }
08833 }
08834
08835 s_bot_command* c=new s_bot_command;
08836 c->hard_clear();
08837 c->packet_type=PACKET_TYPE_COMMAND;
08838 c->size=sizeof(c);
08839 c->version=1;
08840 c->command=CMD_PARTYLINE_1;
08841
08842 c->command_data.cmd_partyline_1.id=id;
08843
08844 c->command_data.cmd_partyline_1.msg=true;
08845 c->command_data.cmd_partyline_1.join=false;
08846 c->command_data.cmd_partyline_1.leave=false;
08847
08848 int user_size=sizeof(c->command_data.cmd_partyline_1.user);
08849 int msg_size=sizeof(c->command_data.cmd_partyline_1.message);
08850 int ch_size=sizeof(c->command_data.cmd_partyline_1.channel);
08851 int bn_size=sizeof(c->command_data.cmd_partyline_1.botname);
08852 strncpy(c->command_data.cmd_partyline_1.user,user.c_str(),user_size);
08853 strncpy(c->command_data.cmd_partyline_1.channel,channel.c_str(),ch_size);
08854 strncpy(c->command_data.cmd_partyline_1.message,msg.c_str(),msg_size);
08855 strncpy(c->command_data.cmd_partyline_1.botname,botnet_botname,bn_size);
08856
08857 bool at_least_one=false;
08858 vector<s_bot*>::iterator i1;
08859 for(i1=bots.begin(); i1!=bots.end(); i1++)
08860 if((*i1)->socket.cmp() && (*i1)->auth_ok && (*i1)->remote_pswd_ok) {
08861 at_least_one=true;
08862 botnet_send_command(*i1,c);
08863 }
08864
08865
08866 botnet_partyline_event(botnet_botname,c);
08867
08868 delete c;
08869 }
08870
08871
08872
08873
08874
08875
08876
08877
08878
08879 string botnet_showbots(string lang, string eol)
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 }
08899
08900
08901
08902
08903
08904
08905
08906
08907
08908
08909 void botnet_admin_msg(string user_mask, string bot_mask, string msg)
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 }
08920