1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360
|
/*
*
* (C) 2003-2024 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
*/
#include "module.h"
#include "modules/os_session.h"
#include "modules/bs_kick.h"
#include "modules/cs_mode.h"
#include "modules/bs_badwords.h"
#include "modules/os_news.h"
#include "modules/suspend.h"
#include "modules/os_forbid.h"
#include "modules/cs_entrymsg.h"
#define READ(x) \
if (true) \
{ \
if ((x) < 0) \
printf("Error, the database is broken, line %d, trying to continue... no guarantee.\n", __LINE__); \
} \
else \
static_cast<void>(0)
#define getc_db(f) (fgetc((f)->fp))
#define read_db(f, buf, len) (fread((buf), 1, (len), (f)->fp))
#define read_buffer(buf, f) ((read_db((f), (buf), sizeof(buf)) == sizeof(buf)) ? 0 : -1)
#define OLD_BI_PRIVATE 0x0001
#define OLD_NI_KILLPROTECT 0x00000001 /* Kill others who take this nick */
#define OLD_NI_SECURE 0x00000002 /* Don't recognize unless IDENTIFY'd */
#define OLD_NI_MSG 0x00000004 /* Use PRIVMSGs instead of NOTICEs */
#define OLD_NI_MEMO_HARDMAX 0x00000008 /* Don't allow user to change memo limit */
#define OLD_NI_MEMO_SIGNON 0x00000010 /* Notify of memos at signon and un-away */
#define OLD_NI_MEMO_RECEIVE 0x00000020 /* Notify of new memos when sent */
#define OLD_NI_PRIVATE 0x00000040 /* Don't show in LIST to non-servadmins */
#define OLD_NI_HIDE_EMAIL 0x00000080 /* Don't show E-mail in INFO */
#define OLD_NI_HIDE_MASK 0x00000100 /* Don't show last seen address in INFO */
#define OLD_NI_HIDE_QUIT 0x00000200 /* Don't show last quit message in INFO */
#define OLD_NI_KILL_QUICK 0x00000400 /* Kill in 20 seconds instead of 60 */
#define OLD_NI_KILL_IMMED 0x00000800 /* Kill immediately instead of in 60 sec */
#define OLD_NI_MEMO_MAIL 0x00010000 /* User gets email on memo */
#define OLD_NI_HIDE_STATUS 0x00020000 /* Don't show services access status */
#define OLD_NI_SUSPENDED 0x00040000 /* Nickname is suspended */
#define OLD_NI_AUTOOP 0x00080000 /* Autoop nickname in channels */
#define OLD_NS_NO_EXPIRE 0x0004 /* nick won't expire */
#define OLD_NS_VERBOTEN 0x0002
#define OLD_CI_KEEPTOPIC 0x00000001
#define OLD_CI_SECUREOPS 0x00000002
#define OLD_CI_PRIVATE 0x00000004
#define OLD_CI_TOPICLOCK 0x00000008
#define OLD_CI_RESTRICTED 0x00000010
#define OLD_CI_PEACE 0x00000020
#define OLD_CI_SECURE 0x00000040
#define OLD_CI_VERBOTEN 0x00000080
#define OLD_CI_ENCRYPTEDPW 0x00000100
#define OLD_CI_NO_EXPIRE 0x00000200
#define OLD_CI_MEMO_HARDMAX 0x00000400
#define OLD_CI_OPNOTICE 0x00000800
#define OLD_CI_SECUREFOUNDER 0x00001000
#define OLD_CI_SIGNKICK 0x00002000
#define OLD_CI_SIGNKICK_LEVEL 0x00004000
#define OLD_CI_XOP 0x00008000
#define OLD_CI_SUSPENDED 0x00010000
/* BotServ SET flags */
#define OLD_BS_DONTKICKOPS 0x00000001
#define OLD_BS_DONTKICKVOICES 0x00000002
#define OLD_BS_FANTASY 0x00000004
#define OLD_BS_SYMBIOSIS 0x00000008
#define OLD_BS_GREET 0x00000010
#define OLD_BS_NOBOT 0x00000020
/* BotServ Kickers flags */
#define OLD_BS_KICK_BOLDS 0x80000000
#define OLD_BS_KICK_COLORS 0x40000000
#define OLD_BS_KICK_REVERSES 0x20000000
#define OLD_BS_KICK_UNDERLINES 0x10000000
#define OLD_BS_KICK_BADWORDS 0x08000000
#define OLD_BS_KICK_CAPS 0x04000000
#define OLD_BS_KICK_FLOOD 0x02000000
#define OLD_BS_KICK_REPEAT 0x01000000
#define OLD_NEWS_LOGON 0
#define OLD_NEWS_OPER 1
#define OLD_NEWS_RANDOM 2
static struct mlock_info
{
char c;
uint32_t m;
} mlock_infos[] = {
{'i', 0x00000001},
{'m', 0x00000002},
{'n', 0x00000004},
{'p', 0x00000008},
{'s', 0x00000010},
{'t', 0x00000020},
{'R', 0x00000100},
{'r', 0x00000200},
{'c', 0x00000400},
{'A', 0x00000800},
{'K', 0x00002000},
{'O', 0x00008000},
{'Q', 0x00010000},
{'S', 0x00020000},
{'G', 0x00100000},
{'C', 0x00200000},
{'u', 0x00400000},
{'z', 0x00800000},
{'N', 0x01000000},
{'M', 0x04000000}
};
static Anope::string hashm;
enum
{
LANG_EN_US, /* United States English */
LANG_JA_JIS, /* Japanese (JIS encoding) */
LANG_JA_EUC, /* Japanese (EUC encoding) */
LANG_JA_SJIS, /* Japanese (SJIS encoding) */
LANG_ES, /* Spanish */
LANG_PT, /* Portuguese */
LANG_FR, /* French */
LANG_TR, /* Turkish */
LANG_IT, /* Italian */
LANG_DE, /* German */
LANG_CAT, /* Catalan */
LANG_GR, /* Greek */
LANG_NL, /* Dutch */
LANG_RU, /* Russian */
LANG_HUN, /* Hungarian */
LANG_PL /* Polish */
};
static void process_mlock(ChannelInfo *ci, uint32_t lock, bool status, uint32_t *limit, Anope::string *key)
{
ModeLocks *ml = ci->Require<ModeLocks>("modelocks");
for (unsigned i = 0; i < (sizeof(mlock_infos) / sizeof(mlock_info)); ++i)
if (lock & mlock_infos[i].m)
{
ChannelMode *cm = ModeManager::FindChannelModeByChar(mlock_infos[i].c);
if (cm && ml)
{
if (limit && mlock_infos[i].c == 'l')
ml->SetMLock(cm, status, stringify(*limit));
else if (key && mlock_infos[i].c == 'k')
ml->SetMLock(cm, status, *key);
else
ml->SetMLock(cm, status);
}
}
}
static const char Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char Pad64 = '=';
static void my_b64_encode(const Anope::string &src, Anope::string &target)
{
size_t src_pos = 0, src_len = src.length();
unsigned char input[3];
target.clear();
while (src_len - src_pos > 2)
{
input[0] = src[src_pos++];
input[1] = src[src_pos++];
input[2] = src[src_pos++];
target += Base64[input[0] >> 2];
target += Base64[((input[0] & 0x03) << 4) + (input[1] >> 4)];
target += Base64[((input[1] & 0x0f) << 2) + (input[2] >> 6)];
target += Base64[input[2] & 0x3f];
}
/* Now we worry about padding */
if (src_pos != src_len)
{
input[0] = input[1] = input[2] = 0;
for (size_t i = 0; i < src_len - src_pos; ++i)
input[i] = src[src_pos + i];
target += Base64[input[0] >> 2];
target += Base64[((input[0] & 0x03) << 4) + (input[1] >> 4)];
if (src_pos == src_len - 1)
target += Pad64;
else
target += Base64[((input[1] & 0x0f) << 2) + (input[2] >> 6)];
target += Pad64;
}
}
static Anope::string Hex(const char *data, size_t l)
{
const char hextable[] = "0123456789abcdef";
std::string rv;
for (size_t i = 0; i < l; ++i)
{
unsigned char c = data[i];
rv += hextable[c >> 4];
rv += hextable[c & 0xF];
}
return rv;
}
static Anope::string GetLevelName(int level)
{
switch (level)
{
case 0:
return "INVITE";
case 1:
return "AKICK";
case 2:
return "SET";
case 3:
return "UNBAN";
case 4:
return "AUTOOP";
case 5:
return "AUTODEOP";
case 6:
return "AUTOVOICE";
case 7:
return "OP";
case 8:
return "ACCESS_LIST";
case 9:
return "CLEAR";
case 10:
return "NOJOIN";
case 11:
return "ACCESS_CHANGE";
case 12:
return "MEMO";
case 13:
return "ASSIGN";
case 14:
return "BADWORDS";
case 15:
return "NOKICK";
case 16:
return "FANTASIA";
case 17:
return "SAY";
case 18:
return "GREET";
case 19:
return "VOICEME";
case 20:
return "VOICE";
case 21:
return "GETKEY";
case 22:
return "AUTOHALFOP";
case 23:
return "AUTOPROTECT";
case 24:
return "OPME";
case 25:
return "HALFOPME";
case 26:
return "HALFOP";
case 27:
return "PROTECTME";
case 28:
return "PROTECT";
case 29:
return "KICKME";
case 30:
return "KICK";
case 31:
return "SIGNKICK";
case 32:
return "BANME";
case 33:
return "BAN";
case 34:
return "TOPIC";
case 35:
return "INFO";
default:
return "INVALID";
}
}
static char *strscpy(char *d, const char *s, size_t len)
{
char *d_orig = d;
if (!len)
return d;
while (--len && (*d++ = *s++));
*d = '\0';
return d_orig;
}
struct dbFILE
{
int mode; /* 'r' for reading, 'w' for writing */
FILE *fp; /* The normal file descriptor */
char filename[1024]; /* Name of the database file */
};
static dbFILE *open_db_read(const char *service, const char *filename, int version)
{
dbFILE *f;
FILE *fp;
int myversion;
f = new dbFILE;
strscpy(f->filename, (Anope::DataDir + "/" + filename).c_str(), sizeof(f->filename));
f->mode = 'r';
fp = fopen(f->filename, "rb");
if (!fp)
{
Log() << "Can't read " << service << " database " << f->filename;
delete f;
return NULL;
}
f->fp = fp;
myversion = fgetc(fp) << 24 | fgetc(fp) << 16 | fgetc(fp) << 8 | fgetc(fp);
if (feof(fp))
{
Log() << "Error reading version number on " << f->filename << ": End of file detected.";
delete f;
return NULL;
}
else if (myversion < version)
{
Log() << "Unsupported database version (" << myversion << ") on " << f->filename << ".";
delete f;
return NULL;
}
return f;
}
void close_db(dbFILE *f)
{
fclose(f->fp);
delete f;
}
static int read_int16(int16_t *ret, dbFILE *f)
{
int c1, c2;
*ret = 0;
c1 = fgetc(f->fp);
c2 = fgetc(f->fp);
if (c1 == EOF || c2 == EOF)
return -1;
*ret = c1 << 8 | c2;
return 0;
}
static int read_uint16(uint16_t *ret, dbFILE *f)
{
int c1, c2;
*ret = 0;
c1 = fgetc(f->fp);
c2 = fgetc(f->fp);
if (c1 == EOF || c2 == EOF)
return -1;
*ret = c1 << 8 | c2;
return 0;
}
static int read_string(Anope::string &str, dbFILE *f)
{
str.clear();
uint16_t len;
if (read_uint16(&len, f) < 0)
return -1;
if (len == 0)
return 0;
char *s = new char[len];
if (len != fread(s, 1, len, f->fp))
{
delete [] s;
return -1;
}
str = s;
delete [] s;
return 0;
}
static int read_uint32(uint32_t *ret, dbFILE *f)
{
int c1, c2, c3, c4;
*ret = 0;
c1 = fgetc(f->fp);
c2 = fgetc(f->fp);
c3 = fgetc(f->fp);
c4 = fgetc(f->fp);
if (c1 == EOF || c2 == EOF || c3 == EOF || c4 == EOF)
return -1;
*ret = c1 << 24 | c2 << 16 | c3 << 8 | c4;
return 0;
}
int read_int32(int32_t *ret, dbFILE *f)
{
int c1, c2, c3, c4;
*ret = 0;
c1 = fgetc(f->fp);
c2 = fgetc(f->fp);
c3 = fgetc(f->fp);
c4 = fgetc(f->fp);
if (c1 == EOF || c2 == EOF || c3 == EOF || c4 == EOF)
return -1;
*ret = c1 << 24 | c2 << 16 | c3 << 8 | c4;
return 0;
}
static void LoadNicks()
{
ServiceReference<ForbidService> forbid("ForbidService", "forbid");
dbFILE *f = open_db_read("NickServ", "nick.db", 14);
if (f == NULL)
return;
for (int i = 0; i < 1024; ++i)
for (int c; (c = getc_db(f)) == 1;)
{
Anope::string buffer;
READ(read_string(buffer, f));
NickCore *nc = new NickCore(buffer);
const Anope::string settings[] = { "killprotect", "kill_quick", "ns_secure", "ns_private", "hide_email",
"hide_mask", "hide_quit", "memo_signon", "memo_receive", "autoop", "msg", "ns_keepmodes" };
for (unsigned j = 0; j < sizeof(settings) / sizeof(Anope::string); ++j)
nc->Shrink<bool>(settings[j].upper());
char pwbuf[32];
READ(read_buffer(pwbuf, f));
if (hashm == "plain")
my_b64_encode(pwbuf, nc->pass);
else if (hashm == "md5" || hashm == "oldmd5")
nc->pass = Hex(pwbuf, 16);
else if (hashm == "sha1")
nc->pass = Hex(pwbuf, 20);
else
nc->pass = Hex(pwbuf, strlen(pwbuf));
nc->pass = hashm + ":" + nc->pass;
READ(read_string(buffer, f));
nc->email = buffer;
READ(read_string(buffer, f));
if (!buffer.empty())
nc->Extend<Anope::string>("greet", buffer);
uint32_t u32;
READ(read_uint32(&u32, f));
//nc->icq = u32;
READ(read_string(buffer, f));
//nc->url = buffer;
READ(read_uint32(&u32, f));
if (u32 & OLD_NI_KILLPROTECT)
nc->Extend<bool>("KILLPROTECT");
if (u32 & OLD_NI_SECURE)
nc->Extend<bool>("NS_SECURE");
if (u32 & OLD_NI_MSG)
nc->Extend<bool>("MSG");
if (u32 & OLD_NI_MEMO_HARDMAX)
nc->Extend<bool>("MEMO_HARDMAX");
if (u32 & OLD_NI_MEMO_SIGNON)
nc->Extend<bool>("MEMO_SIGNON");
if (u32 & OLD_NI_MEMO_RECEIVE)
nc->Extend<bool>("MEMO_RECEIVE");
if (u32 & OLD_NI_PRIVATE)
nc->Extend<bool>("NS_PRIVATE");
if (u32 & OLD_NI_HIDE_EMAIL)
nc->Extend<bool>("HIDE_EMAIL");
if (u32 & OLD_NI_HIDE_MASK)
nc->Extend<bool>("HIDE_MASK");
if (u32 & OLD_NI_HIDE_QUIT)
nc->Extend<bool>("HIDE_QUIT");
if (u32 & OLD_NI_KILL_QUICK)
nc->Extend<bool>("KILL_QUICK");
if (u32 & OLD_NI_KILL_IMMED)
nc->Extend<bool>("KILL_IMMED");
if (u32 & OLD_NI_MEMO_MAIL)
nc->Extend<bool>("MEMO_MAIL");
if (u32 & OLD_NI_HIDE_STATUS)
nc->Extend<bool>("HIDE_STATUS");
if (u32 & OLD_NI_SUSPENDED)
{
SuspendInfo si;
si.what = nc->display;
si.when = si.expires = 0;
nc->Extend("NS_SUSPENDED", si);
}
if (!(u32 & OLD_NI_AUTOOP))
nc->Extend<bool>("AUTOOP");
uint16_t u16;
READ(read_uint16(&u16, f));
switch (u16)
{
case LANG_ES:
nc->language = "es_ES.UTF-8";
break;
case LANG_PT:
nc->language = "pt_PT.UTF-8";
break;
case LANG_FR:
nc->language = "fr_FR.UTF-8";
break;
case LANG_TR:
nc->language = "tr_TR.UTF-8";
break;
case LANG_IT:
nc->language = "it_IT.UTF-8";
break;
case LANG_DE:
nc->language = "de_DE.UTF-8";
break;
case LANG_CAT:
nc->language = "ca_ES.UTF-8"; // yes, iso639 defines catalan as CA
break;
case LANG_GR:
nc->language = "el_GR.UTF-8";
break;
case LANG_NL:
nc->language = "nl_NL.UTF-8";
break;
case LANG_RU:
nc->language = "ru_RU.UTF-8";
break;
case LANG_HUN:
nc->language = "hu_HU.UTF-8";
break;
case LANG_PL:
nc->language = "pl_PL.UTF-8";
break;
case LANG_EN_US:
case LANG_JA_JIS:
case LANG_JA_EUC:
case LANG_JA_SJIS: // these seem to be unused
default:
nc->language = "en";
}
READ(read_uint16(&u16, f));
for (uint16_t j = 0; j < u16; ++j)
{
READ(read_string(buffer, f));
nc->access.push_back(buffer);
}
int16_t i16;
READ(read_int16(&i16, f));
READ(read_int16(&nc->memos.memomax, f));
for (int16_t j = 0; j < i16; ++j)
{
Memo *m = new Memo;
READ(read_uint32(&u32, f));
uint16_t flags;
READ(read_uint16(&flags, f));
int32_t tmp32;
READ(read_int32(&tmp32, f));
m->time = tmp32;
char sbuf[32];
READ(read_buffer(sbuf, f));
m->sender = sbuf;
READ(read_string(m->text, f));
m->owner = nc->display;
nc->memos.memos->push_back(m);
m->mi = &nc->memos;
}
READ(read_uint16(&u16, f));
READ(read_int16(&i16, f));
Log(LOG_DEBUG) << "Loaded NickCore " << nc->display;
}
for (int i = 0; i < 1024; ++i)
for (int c; (c = getc_db(f)) == 1;)
{
Anope::string nick, last_usermask, last_realname, last_quit;
time_t time_registered, last_seen;
READ(read_string(nick, f));
READ(read_string(last_usermask, f));
READ(read_string(last_realname, f));
READ(read_string(last_quit, f));
int32_t tmp32;
READ(read_int32(&tmp32, f));
time_registered = tmp32;
READ(read_int32(&tmp32, f));
last_seen = tmp32;
uint16_t tmpu16;
READ(read_uint16(&tmpu16, f));
Anope::string core;
READ(read_string(core, f));
NickCore *nc = NickCore::Find(core);
if (nc == NULL)
{
Log() << "Skipping coreless nick " << nick << " with core " << core;
continue;
}
if (tmpu16 & OLD_NS_VERBOTEN)
{
if (!forbid)
{
delete nc;
continue;
}
if (nc->display.find_first_of("?*") != Anope::string::npos)
{
delete nc;
continue;
}
ForbidData *d = forbid->CreateForbid();
d->mask = nc->display;
d->creator = last_usermask;
d->reason = last_realname;
d->expires = 0;
d->created = 0;
d->type = FT_NICK;
delete nc;
forbid->AddForbid(d);
continue;
}
NickAlias *na = new NickAlias(nick, nc);
na->last_usermask = last_usermask;
na->last_realname = last_realname;
na->last_quit = last_quit;
na->time_registered = time_registered;
na->last_seen = last_seen;
if (tmpu16 & OLD_NS_NO_EXPIRE)
na->Extend<bool>("NS_NO_EXPIRE");
Log(LOG_DEBUG) << "Loaded NickAlias " << na->nick;
}
close_db(f); /* End of section Ia */
}
static void LoadVHosts()
{
dbFILE *f = open_db_read("HostServ", "hosts.db", 3);
if (f == NULL)
return;
for (int c; (c = getc_db(f)) == 1;)
{
Anope::string nick, ident, host, creator;
int32_t vtime;
READ(read_string(nick, f));
READ(read_string(ident, f));
READ(read_string(host, f));
READ(read_string(creator, f));
READ(read_int32(&vtime, f));
NickAlias *na = NickAlias::Find(nick);
if (na == NULL)
{
Log() << "Removing vhost for nonexistent nick " << nick;
continue;
}
na->SetVhost(ident, host, creator, vtime);
Log() << "Loaded vhost for " << na->nick;
}
close_db(f);
}
static void LoadBots()
{
dbFILE *f = open_db_read("Botserv", "bot.db", 10);
if (f == NULL)
return;
for (int c; (c = getc_db(f)) == 1;)
{
Anope::string nick, user, host, real;
int16_t flags, chancount;
int32_t created;
READ(read_string(nick, f));
READ(read_string(user, f));
READ(read_string(host, f));
READ(read_string(real, f));
READ(read_int16(&flags, f));
READ(read_int32(&created, f));
READ(read_int16(&chancount, f));
BotInfo *bi = BotInfo::Find(nick, true);
if (!bi)
bi = new BotInfo(nick, user, host, real);
bi->created = created;
if (flags & OLD_BI_PRIVATE)
bi->oper_only = true;
Log(LOG_DEBUG) << "Loaded bot " << bi->nick;
}
close_db(f);
}
static void LoadChannels()
{
ServiceReference<ForbidService> forbid("ForbidService", "forbid");
dbFILE *f = open_db_read("ChanServ", "chan.db", 16);
if (f == NULL)
return;
for (int i = 0; i < 256; ++i)
for (int c; (c = getc_db(f)) == 1;)
{
Anope::string buffer;
char namebuf[64];
READ(read_buffer(namebuf, f));
ChannelInfo *ci = new ChannelInfo(namebuf);
const Anope::string settings[] = { "keeptopic", "peace", "cs_private", "restricted", "cs_secure", "secureops", "securefounder",
"signkick", "signkick_level", "topiclock", "persist", "noautoop", "cs_keepmodes" };
for (unsigned j = 0; j < sizeof(settings) / sizeof(Anope::string); ++j)
ci->Shrink<bool>(settings[j].upper());
READ(read_string(buffer, f));
ci->SetFounder(NickCore::Find(buffer));
READ(read_string(buffer, f));
ci->SetSuccessor(NickCore::Find(buffer));
char pwbuf[32];
READ(read_buffer(pwbuf, f));
READ(read_string(ci->desc, f));
READ(read_string(buffer, f));
READ(read_string(buffer, f));
int32_t tmp32;
READ(read_int32(&tmp32, f));
ci->time_registered = tmp32;
READ(read_int32(&tmp32, f));
ci->last_used = tmp32;
READ(read_string(ci->last_topic, f));
READ(read_buffer(pwbuf, f));
ci->last_topic_setter = pwbuf;
READ(read_int32(&tmp32, f));
ci->last_topic_time = tmp32;
uint32_t tmpu32;
READ(read_uint32(&tmpu32, f));
// Temporary flags cleanup
tmpu32 &= ~0x80000000;
if (tmpu32 & OLD_CI_KEEPTOPIC)
ci->Extend<bool>("KEEPTOPIC");
if (tmpu32 & OLD_CI_SECUREOPS)
ci->Extend<bool>("SECUREOPS");
if (tmpu32 & OLD_CI_PRIVATE)
ci->Extend<bool>("CS_PRIVATE");
if (tmpu32 & OLD_CI_TOPICLOCK)
ci->Extend<bool>("TOPICLOCK");
if (tmpu32 & OLD_CI_RESTRICTED)
ci->Extend<bool>("RESTRICTED");
if (tmpu32 & OLD_CI_PEACE)
ci->Extend<bool>("PEACE");
if (tmpu32 & OLD_CI_SECURE)
ci->Extend<bool>("CS_SECURE");
if (tmpu32 & OLD_CI_NO_EXPIRE)
ci->Extend<bool>("CS_NO_EXPIRE");
if (tmpu32 & OLD_CI_MEMO_HARDMAX)
ci->Extend<bool>("MEMO_HARDMAX");
if (tmpu32 & OLD_CI_SECUREFOUNDER)
ci->Extend<bool>("SECUREFOUNDER");
if (tmpu32 & OLD_CI_SIGNKICK)
ci->Extend<bool>("SIGNKICK");
if (tmpu32 & OLD_CI_SIGNKICK_LEVEL)
ci->Extend<bool>("SIGNKICK_LEVEL");
Anope::string forbidby, forbidreason;
READ(read_string(forbidby, f));
READ(read_string(forbidreason, f));
if (tmpu32 & OLD_CI_SUSPENDED)
{
SuspendInfo si;
si.what = ci->name;
si.by = forbidby;
si.reason = forbidreason;
si.when = si.expires = 0;
ci->Extend("CS_SUSPENDED", si);
}
bool forbid_chan = tmpu32 & OLD_CI_VERBOTEN;
int16_t tmp16;
READ(read_int16(&tmp16, f));
ci->bantype = tmp16;
READ(read_int16(&tmp16, f));
if (tmp16 > 36)
tmp16 = 36;
for (int16_t j = 0; j < tmp16; ++j)
{
int16_t level;
READ(read_int16(&level, f));
if (level == ACCESS_INVALID)
level = ACCESS_FOUNDER;
if (j == 10 && level < 0) // NOJOIN
ci->Shrink<bool>("RESTRICTED"); // If CSDefRestricted was enabled this can happen
ci->SetLevel(GetLevelName(j), level);
}
bool xop = tmpu32 & OLD_CI_XOP;
ServiceReference<AccessProvider> provider_access("AccessProvider", "access/access"), provider_xop("AccessProvider", "access/xop");
uint16_t tmpu16;
READ(read_uint16(&tmpu16, f));
for (uint16_t j = 0; j < tmpu16; ++j)
{
uint16_t in_use;
READ(read_uint16(&in_use, f));
if (in_use)
{
ChanAccess *access = NULL;
if (xop)
{
if (provider_xop)
access = provider_xop->Create();
}
else
if (provider_access)
access = provider_access->Create();
if (access)
access->ci = ci;
int16_t level;
READ(read_int16(&level, f));
if (access)
{
if (xop)
{
switch (level)
{
case 3:
access->AccessUnserialize("VOP");
break;
case 4:
access->AccessUnserialize("HOP");
break;
case 5:
access->AccessUnserialize("AOP");
break;
case 10:
access->AccessUnserialize("SOP");
break;
}
}
else
access->AccessUnserialize(stringify(level));
}
Anope::string mask;
READ(read_string(mask, f));
if (access)
access->SetMask(mask, ci);
READ(read_int32(&tmp32, f));
if (access)
{
access->last_seen = tmp32;
access->creator = "Unknown";
access->created = Anope::CurTime;
ci->AddAccess(access);
}
}
}
READ(read_uint16(&tmpu16, f));
for (uint16_t j = 0; j < tmpu16; ++j)
{
uint16_t flags;
READ(read_uint16(&flags, f));
if (flags & 0x0001)
{
Anope::string mask, reason, creator;
READ(read_string(mask, f));
READ(read_string(reason, f));
READ(read_string(creator, f));
READ(read_int32(&tmp32, f));
ci->AddAkick(creator, mask, reason, tmp32);
}
}
READ(read_uint32(&tmpu32, f)); // mlock on
ci->Extend<uint32_t>("mlock_on", tmpu32);
READ(read_uint32(&tmpu32, f)); // mlock off
ci->Extend<uint32_t>("mlock_off", tmpu32);
READ(read_uint32(&tmpu32, f)); // mlock limit
ci->Extend<uint32_t>("mlock_limit", tmpu32);
READ(read_string(buffer, f)); // key
ci->Extend<Anope::string>("mlock_key", buffer);
READ(read_string(buffer, f)); // +f
READ(read_string(buffer, f)); // +L
READ(read_int16(&tmp16, f));
READ(read_int16(&ci->memos.memomax, f));
for (int16_t j = 0; j < tmp16; ++j)
{
READ(read_uint32(&tmpu32, f));
READ(read_uint16(&tmpu16, f));
Memo *m = new Memo;
READ(read_int32(&tmp32, f));
m->time = tmp32;
char sbuf[32];
READ(read_buffer(sbuf, f));
m->sender = sbuf;
READ(read_string(m->text, f));
m->owner = ci->name;
ci->memos.memos->push_back(m);
m->mi = &ci->memos;
}
READ(read_string(buffer, f));
if (!buffer.empty())
{
EntryMessageList *eml = ci->Require<EntryMessageList>("entrymsg");
if (eml)
{
EntryMsg *e = eml->Create();
e->chan = ci->name;
e->creator = "Unknown";
e->message = buffer;
e->when = Anope::CurTime;
(*eml)->push_back(e);
}
}
READ(read_string(buffer, f));
ci->bi = BotInfo::Find(buffer, true);
READ(read_int32(&tmp32, f));
if (tmp32 & OLD_BS_DONTKICKOPS)
ci->Extend<bool>("BS_DONTKICKOPS");
if (tmp32 & OLD_BS_DONTKICKVOICES)
ci->Extend<bool>("BS_DONTKICKVOICES");
if (tmp32 & OLD_BS_FANTASY)
ci->Extend<bool>("BS_FANTASY");
if (tmp32 & OLD_BS_GREET)
ci->Extend<bool>("BS_GREET");
if (tmp32 & OLD_BS_NOBOT)
ci->Extend<bool>("BS_NOBOT");
KickerData *kd = ci->Require<KickerData>("kickerdata");
if (kd)
{
if (tmp32 & OLD_BS_KICK_BOLDS)
kd->bolds = true;
if (tmp32 & OLD_BS_KICK_COLORS)
kd->colors = true;
if (tmp32 & OLD_BS_KICK_REVERSES)
kd->reverses = true;
if (tmp32 & OLD_BS_KICK_UNDERLINES)
kd->underlines = true;
if (tmp32 & OLD_BS_KICK_BADWORDS)
kd->badwords = true;
if (tmp32 & OLD_BS_KICK_CAPS)
kd->caps = true;
if (tmp32 & OLD_BS_KICK_FLOOD)
kd->flood = true;
if (tmp32 & OLD_BS_KICK_REPEAT)
kd->repeat = true;
}
READ(read_int16(&tmp16, f));
for (int16_t j = 0; j < tmp16; ++j)
{
int16_t ttb;
READ(read_int16(&ttb, f));
if (j < TTB_SIZE && kd)
kd->ttb[j] = ttb;
}
READ(read_int16(&tmp16, f));
if (kd)
kd->capsmin = tmp16;
READ(read_int16(&tmp16, f));
if (kd)
kd->capspercent = tmp16;
READ(read_int16(&tmp16, f));
if (kd)
kd->floodlines = tmp16;
READ(read_int16(&tmp16, f));
if (kd)
kd->floodsecs = tmp16;
READ(read_int16(&tmp16, f));
if (kd)
kd->repeattimes = tmp16;
BadWords *bw = ci->Require<BadWords>("badwords");
READ(read_uint16(&tmpu16, f));
for (uint16_t j = 0; j < tmpu16; ++j)
{
uint16_t in_use;
READ(read_uint16(&in_use, f));
if (in_use)
{
READ(read_string(buffer, f));
uint16_t type;
READ(read_uint16(&type, f));
BadWordType bwtype = BW_ANY;
if (type == 1)
bwtype = BW_SINGLE;
else if (type == 2)
bwtype = BW_START;
else if (type == 3)
bwtype = BW_END;
if (bw)
bw->AddBadWord(buffer, bwtype);
}
}
if (forbid_chan)
{
if (!forbid)
{
delete ci;
continue;
}
if (ci->name.find_first_of("?*") != Anope::string::npos)
{
delete ci;
continue;
}
ForbidData *d = forbid->CreateForbid();
d->mask = ci->name;
d->creator = forbidby;
d->reason = forbidreason;
d->expires = 0;
d->created = 0;
d->type = FT_CHAN;
delete ci;
forbid->AddForbid(d);
continue;
}
Log(LOG_DEBUG) << "Loaded channel " << ci->name;
}
close_db(f);
}
static void LoadOper()
{
dbFILE *f = open_db_read("OperServ", "oper.db", 13);
if (f == NULL)
return;
XLineManager *akill, *sqline, *snline, *szline;
akill = sqline = snline = szline = NULL;
for (std::list<XLineManager *>::iterator it = XLineManager::XLineManagers.begin(), it_end = XLineManager::XLineManagers.end(); it != it_end; ++it)
{
XLineManager *xl = *it;
if (xl->Type() == 'G')
akill = xl;
else if (xl->Type() == 'Q')
sqline = xl;
else if (xl->Type() == 'N')
snline = xl;
else if (xl->Type() == 'Z')
szline = xl;
}
int32_t tmp32;
READ(read_int32(&tmp32, f));
READ(read_int32(&tmp32, f));
int16_t capacity;
read_int16(&capacity, f); // AKill count
for (int16_t i = 0; i < capacity; ++i)
{
Anope::string user, host, by, reason;
int32_t seton, expires;
READ(read_string(user, f));
READ(read_string(host, f));
READ(read_string(by, f));
READ(read_string(reason, f));
READ(read_int32(&seton, f));
READ(read_int32(&expires, f));
if (!akill)
continue;
XLine *x = new XLine(user + "@" + host, by, expires, reason, XLineManager::GenerateUID());
x->created = seton;
akill->AddXLine(x);
}
read_int16(&capacity, f); // SNLines
for (int16_t i = 0; i < capacity; ++i)
{
Anope::string mask, by, reason;
int32_t seton, expires;
READ(read_string(mask, f));
READ(read_string(by, f));
READ(read_string(reason, f));
READ(read_int32(&seton, f));
READ(read_int32(&expires, f));
if (!snline)
continue;
XLine *x = new XLine(mask, by, expires, reason, XLineManager::GenerateUID());
x->created = seton;
snline->AddXLine(x);
}
read_int16(&capacity, f); // SQLines
for (int16_t i = 0; i < capacity; ++i)
{
Anope::string mask, by, reason;
int32_t seton, expires;
READ(read_string(mask, f));
READ(read_string(by, f));
READ(read_string(reason, f));
READ(read_int32(&seton, f));
READ(read_int32(&expires, f));
if (!sqline)
continue;
XLine *x = new XLine(mask, by, expires, reason, XLineManager::GenerateUID());
x->created = seton;
sqline->AddXLine(x);
}
read_int16(&capacity, f); // SZLines
for (int16_t i = 0; i < capacity; ++i)
{
Anope::string mask, by, reason;
int32_t seton, expires;
READ(read_string(mask, f));
READ(read_string(by, f));
READ(read_string(reason, f));
READ(read_int32(&seton, f));
READ(read_int32(&expires, f));
if (!szline)
continue;
XLine *x = new XLine(mask, by, expires, reason, XLineManager::GenerateUID());
x->created = seton;
szline->AddXLine(x);
}
close_db(f);
}
static void LoadExceptions()
{
if (!session_service)
return;
dbFILE *f = open_db_read("OperServ", "exception.db", 9);
if (f == NULL)
return;
int16_t num;
READ(read_int16(&num, f));
for (int i = 0; i < num; ++i)
{
Anope::string mask, reason;
int16_t limit;
char who[32];
int32_t time, expires;
READ(read_string(mask, f));
READ(read_int16(&limit, f));
READ(read_buffer(who, f));
READ(read_string(reason, f));
READ(read_int32(&time, f));
READ(read_int32(&expires, f));
Exception *exception = session_service->CreateException();
exception->mask = mask;
exception->limit = limit;
exception->who = who;
exception->time = time;
exception->expires = expires;
exception->reason = reason;
session_service->AddException(exception);
}
close_db(f);
}
static void LoadNews()
{
if (!news_service)
return;
dbFILE *f = open_db_read("OperServ", "news.db", 9);
if (f == NULL)
return;
int16_t n;
READ(read_int16(&n, f));
for (int16_t i = 0; i < n; i++)
{
int16_t type;
NewsItem *ni = news_service->CreateNewsItem();
READ(read_int16(&type, f));
switch (type)
{
case OLD_NEWS_LOGON:
ni->type = NEWS_LOGON;
break;
case OLD_NEWS_OPER:
ni->type = NEWS_OPER;
break;
case OLD_NEWS_RANDOM:
ni->type = NEWS_RANDOM;
break;
}
int32_t unused;
READ(read_int32(&unused, f));
READ(read_string(ni->text, f));
char who[32];
READ(read_buffer(who, f));
ni->who = who;
int32_t tmp;
READ(read_int32(&tmp, f));
ni->time = tmp;
news_service->AddNewsItem(ni);
}
close_db(f);
}
class DBOld : public Module
{
PrimitiveExtensibleItem<uint32_t> mlock_on, mlock_off, mlock_limit;
PrimitiveExtensibleItem<Anope::string> mlock_key;
public:
DBOld(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR),
mlock_on(this, "mlock_on"), mlock_off(this, "mlock_off"), mlock_limit(this, "mlock_limit"), mlock_key(this, "mlock_key")
{
hashm = Config->GetModule(this)->Get<const Anope::string>("hash");
if (hashm != "md5" && hashm != "oldmd5" && hashm != "sha1" && hashm != "plain" && hashm != "sha256")
throw ModuleException("Invalid hash method");
}
EventReturn OnLoadDatabase() anope_override
{
LoadNicks();
LoadVHosts();
LoadBots();
LoadChannels();
LoadOper();
LoadExceptions();
LoadNews();
return EVENT_STOP;
}
void OnUplinkSync(Server *s) anope_override
{
for (registered_channel_map::iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
{
ChannelInfo *ci = it->second;
uint32_t *limit = mlock_limit.Get(ci);
Anope::string *key = mlock_key.Get(ci);
uint32_t *u = mlock_on.Get(ci);
if (u)
{
process_mlock(ci, *u, true, limit, key);
mlock_on.Unset(ci);
}
u = mlock_off.Get(ci);
if (u)
{
process_mlock(ci, *u, false, limit, key);
mlock_off.Unset(ci);
}
mlock_limit.Unset(ci);
mlock_key.Unset(ci);
if (ci->c)
ci->c->CheckModes();
}
}
};
MODULE_INIT(DBOld)
|