From 6c55e0a529c7f1216ff6f63a4fc77ea06a2a3a38 Mon Sep 17 00:00:00 2001 From: rburchell Date: Fri, 14 Nov 2008 20:57:20 +0000 Subject: Insane commit of doom: s/ \t/g git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1681 5417fbe8-f217-4b02-8779-1006273d7864 --- src/actions.c | 316 +-- src/base64.c | 592 ++--- src/bots.cpp | 42 +- src/botserv.c | 1648 ++++++------ src/channels.c | 3564 +++++++++++++------------- src/chanserv.c | 3536 ++++++++++++------------- src/commands.c | 256 +- src/compat.c | 50 +- src/config.c | 940 +++---- src/core/bs_act.c | 64 +- src/core/bs_assign.c | 52 +- src/core/bs_badwords.c | 476 ++-- src/core/bs_bot.c | 8 +- src/core/bs_botlist.c | 70 +- src/core/bs_fantasy.c | 58 +- src/core/bs_fantasy_kick.c | 72 +- src/core/bs_fantasy_kickban.c | 74 +- src/core/bs_fantasy_owner.c | 40 +- src/core/bs_fantasy_seen.c | 152 +- src/core/bs_help.c | 20 +- src/core/bs_info.c | 394 +-- src/core/bs_kick.c | 544 ++-- src/core/bs_say.c | 56 +- src/core/bs_set.c | 222 +- src/core/bs_unassign.c | 40 +- src/core/cs_access.c | 872 +++---- src/core/cs_akick.c | 1110 ++++---- src/core/cs_ban.c | 286 +-- src/core/cs_clear.c | 606 ++--- src/core/cs_drop.c | 118 +- src/core/cs_forbid.c | 142 +- src/core/cs_getkey.c | 34 +- src/core/cs_getpass.c | 60 +- src/core/cs_help.c | 56 +- src/core/cs_identify.c | 88 +- src/core/cs_info.c | 348 +-- src/core/cs_invite.c | 40 +- src/core/cs_kick.c | 170 +- src/core/cs_list.c | 254 +- src/core/cs_logout.c | 100 +- src/core/cs_modes.c | 420 +-- src/core/cs_register.c | 240 +- src/core/cs_sendpass.c | 100 +- src/core/cs_set.c | 1084 ++++---- src/core/cs_status.c | 62 +- src/core/cs_suspend.c | 264 +- src/core/cs_topic.c | 96 +- src/core/cs_xop.c | 746 +++--- src/core/enc_md5.c | 56 +- src/core/enc_none.c | 40 +- src/core/enc_old.c | 388 +-- src/core/enc_sha1.c | 266 +- src/core/he_help.c | 30 +- src/core/hs_del.c | 44 +- src/core/hs_delall.c | 54 +- src/core/hs_group.c | 106 +- src/core/hs_help.c | 18 +- src/core/hs_list.c | 220 +- src/core/hs_off.c | 38 +- src/core/hs_on.c | 68 +- src/core/hs_set.c | 218 +- src/core/hs_setall.c | 220 +- src/core/ms_cancel.c | 66 +- src/core/ms_check.c | 98 +- src/core/ms_del.c | 242 +- src/core/ms_help.c | 20 +- src/core/ms_info.c | 328 +-- src/core/ms_list.c | 198 +- src/core/ms_read.c | 218 +- src/core/ms_rsend.c | 100 +- src/core/ms_send.c | 12 +- src/core/ms_sendall.c | 48 +- src/core/ms_set.c | 334 +-- src/core/ms_staff.c | 46 +- src/core/ns_access.c | 240 +- src/core/ns_alist.c | 212 +- src/core/ns_drop.c | 158 +- src/core/ns_forbid.c | 160 +- src/core/ns_getemail.c | 60 +- src/core/ns_getpass.c | 86 +- src/core/ns_ghost.c | 104 +- src/core/ns_group.c | 434 ++-- src/core/ns_help.c | 42 +- src/core/ns_identify.c | 194 +- src/core/ns_info.c | 406 +-- src/core/ns_list.c | 322 +-- src/core/ns_logout.c | 104 +- src/core/ns_recover.c | 114 +- src/core/ns_register.c | 744 +++--- src/core/ns_release.c | 90 +- src/core/ns_saset.c | 678 ++--- src/core/ns_sendpass.c | 100 +- src/core/ns_set.c | 600 ++--- src/core/ns_status.c | 48 +- src/core/ns_suspend.c | 226 +- src/core/ns_update.c | 40 +- src/core/os_admin.c | 320 +-- src/core/os_akill.c | 560 ++-- src/core/os_chankill.c | 122 +- src/core/os_chanlist.c | 88 +- src/core/os_clearmodes.c | 452 ++-- src/core/os_defcon.c | 162 +- src/core/os_global.c | 26 +- src/core/os_help.c | 20 +- src/core/os_ignore.c | 136 +- src/core/os_jupe.c | 34 +- src/core/os_kick.c | 62 +- src/core/os_logonnews.c | 22 +- src/core/os_mode.c | 60 +- src/core/os_modinfo.c | 118 +- src/core/os_modlist.c | 254 +- src/core/os_modload.c | 8 +- src/core/os_modunload.c | 6 +- src/core/os_noop.c | 68 +- src/core/os_oline.c | 70 +- src/core/os_oper.c | 312 +-- src/core/os_opernews.c | 28 +- src/core/os_quit.c | 26 +- src/core/os_randomnews.c | 6 +- src/core/os_raw.c | 34 +- src/core/os_reload.c | 32 +- src/core/os_restart.c | 30 +- src/core/os_session.c | 8 +- src/core/os_set.c | 322 +-- src/core/os_sgline.c | 492 ++-- src/core/os_shutdown.c | 28 +- src/core/os_sqline.c | 498 ++-- src/core/os_staff.c | 140 +- src/core/os_stats.c | 698 ++--- src/core/os_svsnick.c | 106 +- src/core/os_szline.c | 488 ++-- src/core/os_umode.c | 84 +- src/core/os_update.c | 12 +- src/core/os_userlist.c | 94 +- src/datafiles.c | 786 +++--- src/encrypt.c | 56 +- src/events.c | 962 +++---- src/helpserv.c | 26 +- src/hostserv.c | 780 +++--- src/init.c | 942 +++---- src/ircd.c | 74 +- src/language.c | 428 ++-- src/log.c | 380 +-- src/mail.c | 356 +-- src/main.c | 898 +++---- src/memory.c | 84 +- src/memoserv.c | 638 ++--- src/messages.c | 422 +-- src/misc.c | 1962 +++++++------- src/module.cpp | 288 +-- src/modulemanager.cpp | 76 +- src/modules.c | 2414 ++++++++--------- src/modules/bs_fantasy_unban.c | 40 +- src/modules/cs_enforce.c | 358 +-- src/modules/cs_tban.c | 180 +- src/modules/demos/catserv/catserv_messages.c | 10 +- src/modules/demos/catserv/ircd_catserv.c | 112 +- src/modules/demos/catserv/purr.c | 4 +- src/modules/demos/events.c | 46 +- src/modules/demos/hs_conf.c | 52 +- src/modules/demos/hs_moo.c | 54 +- src/modules/hs_request.c | 1000 ++++---- src/modules/ns_maxemail.c | 110 +- src/modules/ns_noop_convert.c | 110 +- src/modules/os_ignore_db.c | 62 +- src/modules/os_info.c | 624 ++--- src/news.c | 662 ++--- src/nickserv.c | 2542 +++++++++--------- src/operserv.c | 2438 +++++++++--------- src/process.c | 610 ++--- src/protocol/bahamut.c | 1032 ++++---- src/protocol/charybdis.c | 1416 +++++----- src/protocol/inspircd11.c | 1530 +++++------ src/protocol/inspircd12.cpp | 1282 ++++----- src/protocol/obsolete/hybrid.c | 1854 +++++++------- src/protocol/obsolete/hybrid.h | 18 +- src/protocol/obsolete/plexus3.c | 700 ++--- src/protocol/obsolete/ptlink.c | 2010 +++++++-------- src/protocol/obsolete/ptlink.h | 2 +- src/protocol/obsolete/rageircd.c | 2004 +++++++-------- src/protocol/obsolete/rageircd.h | 2 +- src/protocol/obsolete/solidircd.c | 2006 +++++++-------- src/protocol/obsolete/solidircd.h | 8 +- src/protocol/obsolete/ultimate3.c | 2188 ++++++++-------- src/protocol/obsolete/ultimate3.h | 4 +- src/protocol/obsolete/viagra.c | 1974 +++++++------- src/protocol/ratbox.c | 1364 +++++----- src/protocol/unreal32.c | 1354 +++++----- src/send.c | 172 +- src/servers.c | 782 +++--- src/sessions.c | 1230 ++++----- src/slist.c | 460 ++-- src/sockutil.c | 918 +++---- src/timeout.c | 112 +- src/tools/anopesmtp.c | 680 ++--- src/tools/db-merger.c | 3414 ++++++++++++------------ src/tools/obsolete/epona2anope.c | 1162 ++++----- src/tools/smtp.h | 18 +- src/users.c | 1246 ++++----- 199 files changed, 43387 insertions(+), 43387 deletions(-) (limited to 'src') diff --git a/src/actions.c b/src/actions.c index 2a4a9a1de..c455dfa61 100644 --- a/src/actions.c +++ b/src/actions.c @@ -24,20 +24,20 @@ */ void bad_password(User * u) { - time_t now = time(NULL); - - if (!u || !BadPassLimit) { - return; - } - - if (BadPassTimeout > 0 && u->invalid_pw_time > 0 - && u->invalid_pw_time < now - BadPassTimeout) - u->invalid_pw_count = 0; - u->invalid_pw_count++; - u->invalid_pw_time = now; - if (u->invalid_pw_count >= BadPassLimit) { - kill_user(NULL, u->nick, "Too many invalid passwords"); - } + time_t now = time(NULL); + + if (!u || !BadPassLimit) { + return; + } + + if (BadPassTimeout > 0 && u->invalid_pw_time > 0 + && u->invalid_pw_time < now - BadPassTimeout) + u->invalid_pw_count = 0; + u->invalid_pw_count++; + u->invalid_pw_time = now; + if (u->invalid_pw_count >= BadPassLimit) { + kill_user(NULL, u->nick, "Too many invalid passwords"); + } } /*************************************************************************/ @@ -51,25 +51,25 @@ void bad_password(User * u) */ void kill_user(const char *source, const char *user, const char *reason) { - char buf[BUFSIZE]; + char buf[BUFSIZE]; - if (!user || !*user) { - return; - } - if (!source || !*source) { - source = ServerName; - } - if (!reason) { - reason = ""; - } + if (!user || !*user) { + return; + } + if (!source || !*source) { + source = ServerName; + } + if (!reason) { + reason = ""; + } - snprintf(buf, sizeof(buf), "%s (%s)", source, reason); + snprintf(buf, sizeof(buf), "%s (%s)", source, reason); - ircdproto->SendSVSKill(source, user, buf); + ircdproto->SendSVSKill(source, user, buf); - if (!ircd->quitonkill && finduser(user)) { - do_kill(user, buf); - } + if (!ircd->quitonkill && finduser(user)) { + do_kill(user, buf); + } } /*************************************************************************/ @@ -82,42 +82,42 @@ void kill_user(const char *source, const char *user, const char *reason) */ void sqline(char *mask, char *reason) { - int i; - Channel *c, *next; - const char *av[3]; - struct c_userlist *cu, *cunext; - - if (ircd->chansqline) { - if (*mask == '#') { - ircdproto->SendSQLine(mask, reason); - - for (i = 0; i < 1024; i++) { - for (c = chanlist[i]; c; c = next) { - next = c->next; - - if (!match_wild_nocase(mask, c->name)) { - continue; - } - for (cu = c->users; cu; cu = cunext) { - cunext = cu->next; - if (is_oper(cu->user)) { - continue; - } - av[0] = c->name; - av[1] = cu->user->nick; - av[2] = reason; - ircdproto->SendKick(findbot(s_OperServ), av[0], av[1], - "Q-Lined: %s", av[2]); - do_kick(s_ChanServ, 3, av); - } - } - } - } else { - ircdproto->SendSQLine(mask, reason); - } - } else { - ircdproto->SendSQLine(mask, reason); - } + int i; + Channel *c, *next; + const char *av[3]; + struct c_userlist *cu, *cunext; + + if (ircd->chansqline) { + if (*mask == '#') { + ircdproto->SendSQLine(mask, reason); + + for (i = 0; i < 1024; i++) { + for (c = chanlist[i]; c; c = next) { + next = c->next; + + if (!match_wild_nocase(mask, c->name)) { + continue; + } + for (cu = c->users; cu; cu = cunext) { + cunext = cu->next; + if (is_oper(cu->user)) { + continue; + } + av[0] = c->name; + av[1] = cu->user->nick; + av[2] = reason; + ircdproto->SendKick(findbot(s_OperServ), av[0], av[1], + "Q-Lined: %s", av[2]); + do_kick(s_ChanServ, 3, av); + } + } + } + } else { + ircdproto->SendSQLine(mask, reason); + } + } else { + ircdproto->SendSQLine(mask, reason); + } } /*************************************************************************/ @@ -130,72 +130,72 @@ void sqline(char *mask, char *reason) */ void common_unban(ChannelInfo * ci, char *nick) { - const char *av[4]; - char *host = NULL; - char buf[BUFSIZE]; - int ac; - uint32 ip = 0; - User *u; - Entry *ban, *next; - - if (!ci || !ci->c || !nick) { - return; - } - - if (!(u = finduser(nick))) { - return; - } - - if (!ci->c->bans || (ci->c->bans->count == 0)) - return; - - if (u->hostip == NULL) { - host = host_resolve(u->host); - /* we store the just resolved hostname so we don't - * need to do this again */ - if (host) { - u->hostip = sstrdup(host); - } - } else { - host = sstrdup(u->hostip); - } - /* Convert the host to an IP.. */ - if (host) - ip = str_is_ip(host); - - if (ircd->svsmode_unban) { - ircdproto->SendBanDel(ci->name, nick); - } else { - if (ircdcap->tsmode) { - snprintf(buf, BUFSIZE - 1, "%ld", (long int) time(NULL)); - av[0] = ci->name; - av[1] = buf; - av[2] = "-b"; - ac = 4; - } else { - av[0] = ci->name; - av[1] = "-b"; - ac = 3; - } - - for (ban = ci->c->bans->entries; ban; ban = next) { - next = ban->next; - if (entry_match(ban, u->nick, u->username, u->host, ip) || - entry_match(ban, u->nick, u->username, u->vhost, ip)) { - ircdproto->SendMode(whosends(ci), ci->name, "-b %s", ban->mask); - if (ircdcap->tsmode) - av[3] = ban->mask; - else - av[2] = ban->mask; - - do_cmode(whosends(ci)->nick, ac, av); - } - } - } - /* host_resolve() sstrdup us this info so we gotta free it */ - if (host) { - free(host); - } + const char *av[4]; + char *host = NULL; + char buf[BUFSIZE]; + int ac; + uint32 ip = 0; + User *u; + Entry *ban, *next; + + if (!ci || !ci->c || !nick) { + return; + } + + if (!(u = finduser(nick))) { + return; + } + + if (!ci->c->bans || (ci->c->bans->count == 0)) + return; + + if (u->hostip == NULL) { + host = host_resolve(u->host); + /* we store the just resolved hostname so we don't + * need to do this again */ + if (host) { + u->hostip = sstrdup(host); + } + } else { + host = sstrdup(u->hostip); + } + /* Convert the host to an IP.. */ + if (host) + ip = str_is_ip(host); + + if (ircd->svsmode_unban) { + ircdproto->SendBanDel(ci->name, nick); + } else { + if (ircdcap->tsmode) { + snprintf(buf, BUFSIZE - 1, "%ld", (long int) time(NULL)); + av[0] = ci->name; + av[1] = buf; + av[2] = "-b"; + ac = 4; + } else { + av[0] = ci->name; + av[1] = "-b"; + ac = 3; + } + + for (ban = ci->c->bans->entries; ban; ban = next) { + next = ban->next; + if (entry_match(ban, u->nick, u->username, u->host, ip) || + entry_match(ban, u->nick, u->username, u->vhost, ip)) { + ircdproto->SendMode(whosends(ci), ci->name, "-b %s", ban->mask); + if (ircdcap->tsmode) + av[3] = ban->mask; + else + av[2] = ban->mask; + + do_cmode(whosends(ci)->nick, ac, av); + } + } + } + /* host_resolve() sstrdup us this info so we gotta free it */ + if (host) { + free(host); + } } /*************************************************************************/ @@ -209,17 +209,17 @@ void common_unban(ChannelInfo * ci, char *nick) */ void common_svsmode(User * u, const char *modes, const char *arg) { - int ac = 1; - const char *av[2]; + int ac = 1; + const char *av[2]; - av[0] = modes; - if (arg) { - av[1] = arg; - ac++; - } + av[0] = modes; + if (arg) { + av[1] = arg; + ac++; + } - ircdproto->SendSVSMode(u, ac, av); - ircdproto->ProcessUsermodes(u, ac, av); + ircdproto->SendSVSMode(u, ac, av); + ircdproto->ProcessUsermodes(u, ac, av); } /*************************************************************************/ @@ -232,15 +232,15 @@ void common_svsmode(User * u, const char *modes, const char *arg) */ char *common_get_vhost(User * u) { - if (!u) - return NULL; - - if (ircd->vhostmode && (u->mode & ircd->vhostmode)) - return u->vhost; - else if (ircd->vhost && u->vhost) - return u->vhost; - else - return u->host; + if (!u) + return NULL; + + if (ircd->vhostmode && (u->mode & ircd->vhostmode)) + return u->vhost; + else if (ircd->vhost && u->vhost) + return u->vhost; + else + return u->host; } /*************************************************************************/ @@ -253,13 +253,13 @@ char *common_get_vhost(User * u) */ char *common_get_vident(User * u) { - if (!u) - return NULL; - - if (ircd->vhostmode && (u->mode & ircd->vhostmode)) - return u->vident; - else if (ircd->vident && u->vident) - return u->vident; - else - return u->username; + if (!u) + return NULL; + + if (ircd->vhostmode && (u->mode & ircd->vhostmode)) + return u->vident; + else if (ircd->vident && u->vident) + return u->vident; + else + return u->username; } diff --git a/src/base64.c b/src/base64.c index af3378cf4..5a11b9237 100644 --- a/src/base64.c +++ b/src/base64.c @@ -22,22 +22,22 @@ static long base64_to_int(char *); const char* base64enc(long i) { - if (i < 0) - return ("0"); - return int_to_base64(i); + if (i < 0) + return ("0"); + return int_to_base64(i); } long base64dec(char* b64) { - if (b64) - return base64_to_int(b64); - else - return 0; + if (b64) + return base64_to_int(b64); + else + return 0; } static const char Base64[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static const char Pad64 = '='; /* (From RFC1521 and draft-ietf-dnssec-secext-03.txt) @@ -59,26 +59,26 @@ static const char Pad64 = '='; characters. The character referenced by the index is placed in the output string. - Table 1: The Base64 Alphabet - - Value Encoding Value Encoding Value Encoding Value Encoding - 0 A 17 R 34 i 51 z - 1 B 18 S 35 j 52 0 - 2 C 19 T 36 k 53 1 - 3 D 20 U 37 l 54 2 - 4 E 21 V 38 m 55 3 - 5 F 22 W 39 n 56 4 - 6 G 23 X 40 o 57 5 - 7 H 24 Y 41 p 58 6 - 8 I 25 Z 42 q 59 7 - 9 J 26 a 43 r 60 8 - 10 K 27 b 44 s 61 9 - 11 L 28 c 45 t 62 + - 12 M 29 d 46 u 63 / - 13 N 30 e 47 v - 14 O 31 f 48 w (pad) = - 15 P 32 g 49 x - 16 Q 33 h 50 y + Table 1: The Base64 Alphabet + + Value Encoding Value Encoding Value Encoding Value Encoding + 0 A 17 R 34 i 51 z + 1 B 18 S 35 j 52 0 + 2 C 19 T 36 k 53 1 + 3 D 20 U 37 l 54 2 + 4 E 21 V 38 m 55 3 + 5 F 22 W 39 n 56 4 + 6 G 23 X 40 o 57 5 + 7 H 24 Y 41 p 58 6 + 8 I 25 Z 42 q 59 7 + 9 J 26 a 43 r 60 8 + 10 K 27 b 44 s 61 9 + 11 L 28 c 45 t 62 + + 12 M 29 d 46 u 63 / + 13 N 30 e 47 v + 14 O 31 f 48 w (pad) = + 15 P 32 g 49 x + 16 Q 33 h 50 y Special processing is performed if fewer than 24 bits are available at the end of the data being encoded. A full encoding quantum is @@ -88,72 +88,72 @@ static const char Pad64 = '='; end of the data is performed using the '=' character. Since all base64 input is an integral number of octets, only the - ------------------------------------------------- + ------------------------------------------------- following cases can arise: - (1) the final quantum of encoding input is an integral - multiple of 24 bits; here, the final unit of encoded + (1) the final quantum of encoding input is an integral + multiple of 24 bits; here, the final unit of encoded output will be an integral multiple of 4 characters with no "=" padding, - (2) the final quantum of encoding input is exactly 8 bits; - here, the final unit of encoded output will be two + (2) the final quantum of encoding input is exactly 8 bits; + here, the final unit of encoded output will be two characters followed by two "=" padding characters, or - (3) the final quantum of encoding input is exactly 16 bits; - here, the final unit of encoded output will be three + (3) the final quantum of encoding input is exactly 16 bits; + here, the final unit of encoded output will be three characters followed by one "=" padding character. */ int b64_encode(char *src, size_t srclength, char *target, size_t targsize) { - size_t datalength = 0; - unsigned char input[3]; - unsigned char output[4]; - size_t i; - - while (2 < srclength) { - input[0] = *src++; - input[1] = *src++; - input[2] = *src++; - srclength -= 3; - - output[0] = input[0] >> 2; - output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); - output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); - output[3] = input[2] & 0x3f; - - if (datalength + 4 > targsize) - return (-1); - target[datalength++] = Base64[output[0]]; - target[datalength++] = Base64[output[1]]; - target[datalength++] = Base64[output[2]]; - target[datalength++] = Base64[output[3]]; - } - - /* Now we worry about padding. */ - if (0 != srclength) { - /* Get what's left. */ - input[0] = input[1] = input[2] = '\0'; - for (i = 0; i < srclength; i++) - input[i] = *src++; - - output[0] = input[0] >> 2; - output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); - output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); - - if (datalength + 4 > targsize) - return (-1); - target[datalength++] = Base64[output[0]]; - target[datalength++] = Base64[output[1]]; - if (srclength == 1) - target[datalength++] = Pad64; - else - target[datalength++] = Base64[output[2]]; - target[datalength++] = Pad64; - } - if (datalength >= targsize) - return (-1); - target[datalength] = '\0'; /* Returned value doesn't count \0. */ - return (datalength); + size_t datalength = 0; + unsigned char input[3]; + unsigned char output[4]; + size_t i; + + while (2 < srclength) { + input[0] = *src++; + input[1] = *src++; + input[2] = *src++; + srclength -= 3; + + output[0] = input[0] >> 2; + output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); + output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); + output[3] = input[2] & 0x3f; + + if (datalength + 4 > targsize) + return (-1); + target[datalength++] = Base64[output[0]]; + target[datalength++] = Base64[output[1]]; + target[datalength++] = Base64[output[2]]; + target[datalength++] = Base64[output[3]]; + } + + /* Now we worry about padding. */ + if (0 != srclength) { + /* Get what's left. */ + input[0] = input[1] = input[2] = '\0'; + for (i = 0; i < srclength; i++) + input[i] = *src++; + + output[0] = input[0] >> 2; + output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); + output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); + + if (datalength + 4 > targsize) + return (-1); + target[datalength++] = Base64[output[0]]; + target[datalength++] = Base64[output[1]]; + if (srclength == 1) + target[datalength++] = Pad64; + else + target[datalength++] = Base64[output[2]]; + target[datalength++] = Pad64; + } + if (datalength >= targsize) + return (-1); + target[datalength] = '\0'; /* Returned value doesn't count \0. */ + return (datalength); } /* skips all whitespace anywhere. @@ -164,247 +164,247 @@ int b64_encode(char *src, size_t srclength, char *target, size_t targsize) int b64_decode(const char *src, char *target, size_t targsize) { - int tarindex, state, ch; - char *pos; - - state = 0; - tarindex = 0; - - while ((ch = *src++) != '\0') { - if (isspace(ch)) /* Skip whitespace anywhere. */ - continue; - - if (ch == Pad64) - break; - - pos = strchr(Base64, ch); - if (pos == 0) /* A non-base64 character. */ - return (-1); - - switch (state) { - case 0: - if (target) { - if ((size_t) tarindex >= targsize) - return (-1); - target[tarindex] = (pos - Base64) << 2; - } - state = 1; - break; - case 1: - if (target) { - if ((size_t) tarindex + 1 >= targsize) - return (-1); - target[tarindex] |= (pos - Base64) >> 4; - target[tarindex + 1] = ((pos - Base64) & 0x0f) - << 4; - } - tarindex++; - state = 2; - break; - case 2: - if (target) { - if ((size_t) tarindex + 1 >= targsize) - return (-1); - target[tarindex] |= (pos - Base64) >> 2; - target[tarindex + 1] = ((pos - Base64) & 0x03) - << 6; - } - tarindex++; - state = 3; - break; - case 3: - if (target) { - if ((size_t) tarindex >= targsize) - return (-1); - target[tarindex] |= (pos - Base64); - } - tarindex++; - state = 0; - break; - default: - abort(); - } - } - - /* - * We are done decoding Base-64 chars. Let's see if we ended - * on a byte boundary, and/or with erroneous trailing characters. - */ - - if (ch == Pad64) { /* We got a pad char. */ - ch = *src++; /* Skip it, get next. */ - switch (state) { - case 0: /* Invalid = in first position */ - case 1: /* Invalid = in second position */ - return (-1); - - case 2: /* Valid, means one byte of info */ - /* Skip any number of spaces. */ - for ((void) NULL; ch != '\0'; ch = *src++) - if (!isspace(ch)) - break; - /* Make sure there is another trailing = sign. */ - if (ch != Pad64) - return (-1); - ch = *src++; /* Skip the = */ - /* Fall through to "single trailing =" case. */ - /* FALLTHROUGH */ - - case 3: /* Valid, means two bytes of info */ - /* - * We know this char is an =. Is there anything but - * whitespace after it? - */ - for ((void) NULL; ch != '\0'; ch = *src++) - if (!isspace(ch)) - return (-1); - - /* - * Now make sure for cases 2 and 3 that the "extra" - * bits that slopped past the last full byte were - * zeros. If we don't check them, they become a - * subliminal channel. - */ - if (target && target[tarindex] != 0) - return (-1); - } - } else { - /* - * We ended by seeing the end of the string. Make sure we - * have no partial bytes lying around. - */ - if (state != 0) - return (-1); - } - - return (tarindex); + int tarindex, state, ch; + char *pos; + + state = 0; + tarindex = 0; + + while ((ch = *src++) != '\0') { + if (isspace(ch)) /* Skip whitespace anywhere. */ + continue; + + if (ch == Pad64) + break; + + pos = strchr(Base64, ch); + if (pos == 0) /* A non-base64 character. */ + return (-1); + + switch (state) { + case 0: + if (target) { + if ((size_t) tarindex >= targsize) + return (-1); + target[tarindex] = (pos - Base64) << 2; + } + state = 1; + break; + case 1: + if (target) { + if ((size_t) tarindex + 1 >= targsize) + return (-1); + target[tarindex] |= (pos - Base64) >> 4; + target[tarindex + 1] = ((pos - Base64) & 0x0f) + << 4; + } + tarindex++; + state = 2; + break; + case 2: + if (target) { + if ((size_t) tarindex + 1 >= targsize) + return (-1); + target[tarindex] |= (pos - Base64) >> 2; + target[tarindex + 1] = ((pos - Base64) & 0x03) + << 6; + } + tarindex++; + state = 3; + break; + case 3: + if (target) { + if ((size_t) tarindex >= targsize) + return (-1); + target[tarindex] |= (pos - Base64); + } + tarindex++; + state = 0; + break; + default: + abort(); + } + } + + /* + * We are done decoding Base-64 chars. Let's see if we ended + * on a byte boundary, and/or with erroneous trailing characters. + */ + + if (ch == Pad64) { /* We got a pad char. */ + ch = *src++; /* Skip it, get next. */ + switch (state) { + case 0: /* Invalid = in first position */ + case 1: /* Invalid = in second position */ + return (-1); + + case 2: /* Valid, means one byte of info */ + /* Skip any number of spaces. */ + for ((void) NULL; ch != '\0'; ch = *src++) + if (!isspace(ch)) + break; + /* Make sure there is another trailing = sign. */ + if (ch != Pad64) + return (-1); + ch = *src++; /* Skip the = */ + /* Fall through to "single trailing =" case. */ + /* FALLTHROUGH */ + + case 3: /* Valid, means two bytes of info */ + /* + * We know this char is an =. Is there anything but + * whitespace after it? + */ + for ((void) NULL; ch != '\0'; ch = *src++) + if (!isspace(ch)) + return (-1); + + /* + * Now make sure for cases 2 and 3 that the "extra" + * bits that slopped past the last full byte were + * zeros. If we don't check them, they become a + * subliminal channel. + */ + if (target && target[tarindex] != 0) + return (-1); + } + } else { + /* + * We ended by seeing the end of the string. Make sure we + * have no partial bytes lying around. + */ + if (state != 0) + return (-1); + } + + return (tarindex); } const char* encode_ip(unsigned char *ip) { - static char buf[25]; - unsigned char *cp; - struct in_addr ia; /* For IPv4 */ - char *s_ip; /* Signed ip string */ - - if (!ip) - return "*"; - - if (strchr((char *) ip, ':')) { - return NULL; - } else { - s_ip = str_signed(ip); - ia.s_addr = inet_addr(s_ip); - cp = (unsigned char *) ia.s_addr; - b64_encode((char *) &cp, sizeof(struct in_addr), buf, 25); - } - return buf; + static char buf[25]; + unsigned char *cp; + struct in_addr ia; /* For IPv4 */ + char *s_ip; /* Signed ip string */ + + if (!ip) + return "*"; + + if (strchr((char *) ip, ':')) { + return NULL; + } else { + s_ip = str_signed(ip); + ia.s_addr = inet_addr(s_ip); + cp = (unsigned char *) ia.s_addr; + b64_encode((char *) &cp, sizeof(struct in_addr), buf, 25); + } + return buf; } int decode_ip(const char *buf) { - int len = strlen(buf); - char targ[25]; - struct in_addr ia; - - b64_decode(buf, targ, 25); - ia = *(struct in_addr *) targ; - if (len == 24) { /* IPv6 */ - return 0; - } else if (len == 8) /* IPv4 */ - return ia.s_addr; - else /* Error?? */ - return 0; + int len = strlen(buf); + char targ[25]; + struct in_addr ia; + + b64_decode(buf, targ, 25); + ia = *(struct in_addr *) targ; + if (len == 24) { /* IPv6 */ + return 0; + } else if (len == 8) /* IPv4 */ + return ia.s_addr; + else /* Error?? */ + return 0; } /* ':' and '#' and '&' and '+' and '@' must never be in this table. */ /* these tables must NEVER CHANGE! >) */ char int6_to_base64_map[] = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', - 'E', 'F', - 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', - 'U', 'V', - 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', - 'k', 'l', - 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '{', '}' + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', + 'E', 'F', + 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', + 'U', 'V', + 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', + 'k', 'l', + 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '{', '}' }; char base64_to_int6_map[] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, - -1, 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, -1, -1, -1, -1, -1, - -1, 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, -1, 63, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, + -1, 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, -1, -1, -1, -1, -1, + -1, 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, -1, 63, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; static char *int_to_base64(long val) { - /* 32/6 == max 6 bytes for representation, - * +1 for the null, +1 for byte boundaries - */ - static char base64buf[8]; - long i = 7; - - base64buf[i] = '\0'; - - /* Temporary debugging code.. remove before 2038 ;p. - * This might happen in case of 64bit longs (opteron/ia64), - * if the value is then too large it can easily lead to - * a buffer underflow and thus to a crash. -- Syzop - */ - if (val > 2147483647L) { - abort(); - } - - do { - base64buf[--i] = int6_to_base64_map[val & 63]; - } - while (val >>= 6); - - return base64buf + i; + /* 32/6 == max 6 bytes for representation, + * +1 for the null, +1 for byte boundaries + */ + static char base64buf[8]; + long i = 7; + + base64buf[i] = '\0'; + + /* Temporary debugging code.. remove before 2038 ;p. + * This might happen in case of 64bit longs (opteron/ia64), + * if the value is then too large it can easily lead to + * a buffer underflow and thus to a crash. -- Syzop + */ + if (val > 2147483647L) { + abort(); + } + + do { + base64buf[--i] = int6_to_base64_map[val & 63]; + } + while (val >>= 6); + + return base64buf + i; } static long base64_to_int(char *b64) { - int v = base64_to_int6_map[(unsigned char) *b64++]; + int v = base64_to_int6_map[(unsigned char) *b64++]; - if (!b64) - return 0; + if (!b64) + return 0; - while (*b64) { - v <<= 6; - v += base64_to_int6_map[(unsigned char) *b64++]; - } + while (*b64) { + v <<= 6; + v += base64_to_int6_map[(unsigned char) *b64++]; + } - return v; + return v; } long base64dects(const char *ts) { - char *token; - long value; - - if (!ts) { - return 0; - } - token = myStrGetToken(ts, '!', 1); - - if (!token) { - return strtoul(ts, NULL, 10); - } - value = base64dec(token); - Anope_Free(token); - return value; + char *token; + long value; + + if (!ts) { + return 0; + } + token = myStrGetToken(ts, '!', 1); + + if (!token) { + return strtoul(ts, NULL, 10); + } + value = base64dec(token); + Anope_Free(token); + return value; } diff --git a/src/bots.cpp b/src/bots.cpp index 98c903ebe..a86f37076 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -34,27 +34,27 @@ BotInfo::BotInfo(const char *nnick, const char *nuser, const char *nhost, const BotInfo::~BotInfo() { - int i; - ChannelInfo *ci; - - for (i = 0; i < 256; i++) - for (ci = chanlists[i]; ci; ci = ci->next) - if (ci->bi == this) - ci->bi = NULL; - - if (this->next) - this->next->prev = this->prev; - if (this->prev) - this->prev->next = this->next; - else - botlists[tolower(*this->nick)] = this->next; - - nbots--; - - free(this->nick); - free(this->user); - free(this->host); - free(this->real); + int i; + ChannelInfo *ci; + + for (i = 0; i < 256; i++) + for (ci = chanlists[i]; ci; ci = ci->next) + if (ci->bi == this) + ci->bi = NULL; + + if (this->next) + this->next->prev = this->prev; + if (this->prev) + this->prev->next = this->next; + else + botlists[tolower(*this->nick)] = this->next; + + nbots--; + + free(this->nick); + free(this->user); + free(this->host); + free(this->real); } diff --git a/src/botserv.c b/src/botserv.c index 13d483114..62b19fb1a 100644 --- a/src/botserv.c +++ b/src/botserv.c @@ -19,7 +19,7 @@ /*************************************************************************/ -BotInfo *botlists[256]; /* Hash list of bots */ +BotInfo *botlists[256]; /* Hash list of bots */ int nbots = 0; /*************************************************************************/ @@ -34,7 +34,7 @@ E void moduleAddBotServCmds(void); /*************************************************************************/ /* *INDENT-OFF* */ void moduleAddBotServCmds(void) { - ModuleManager::LoadModuleList(BotServCoreNumber, BotServCoreModules); + ModuleManager::LoadModuleList(BotServCoreNumber, BotServCoreModules); } /* *INDENT-ON* */ /*************************************************************************/ @@ -44,23 +44,23 @@ void moduleAddBotServCmds(void) { void get_botserv_stats(long *nrec, long *memuse) { - long count = 0, mem = 0; - int i; - BotInfo *bi; - - for (i = 0; i < 256; i++) { - for (bi = botlists[i]; bi; bi = bi->next) { - count++; - mem += sizeof(*bi); - mem += strlen(bi->nick) + 1; - mem += strlen(bi->user) + 1; - mem += strlen(bi->host) + 1; - mem += strlen(bi->real) + 1; - } - } - - *nrec = count; - *memuse = mem; + long count = 0, mem = 0; + int i; + BotInfo *bi; + + for (i = 0; i < 256; i++) { + for (bi = botlists[i]; bi; bi = bi->next) { + count++; + mem += sizeof(*bi); + mem += strlen(bi->nick) + 1; + mem += strlen(bi->user) + 1; + mem += strlen(bi->host) + 1; + mem += strlen(bi->real) + 1; + } + } + + *nrec = count; + *memuse = mem; } /*************************************************************************/ @@ -70,9 +70,9 @@ void get_botserv_stats(long *nrec, long *memuse) void bs_init(void) { - if (s_BotServ) { - moduleAddBotServCmds(); - } + if (s_BotServ) { + moduleAddBotServCmds(); + } } /*************************************************************************/ @@ -81,20 +81,20 @@ void bs_init(void) void botserv(User * u, char *buf) { - char *cmd, *s; + char *cmd, *s; - cmd = strtok(buf, " "); + cmd = strtok(buf, " "); - if (!cmd) { - return; - } else if (stricmp(cmd, "\1PING") == 0) { - if (!(s = strtok(NULL, ""))) { - *s = 0; - } - ircdproto->SendCTCP(findbot(s_BotServ), u->nick, "PING %s", s); - } else { - mod_run_cmd(s_BotServ, u, BOTSERV, cmd); - } + if (!cmd) { + return; + } else if (stricmp(cmd, "\1PING") == 0) { + if (!(s = strtok(NULL, ""))) { + *s = 0; + } + ircdproto->SendCTCP(findbot(s_BotServ), u->nick, "PING %s", s); + } else { + mod_run_cmd(s_BotServ, u, BOTSERV, cmd); + } } @@ -104,18 +104,18 @@ void botserv(User * u, char *buf) void botmsgs(User * u, BotInfo * bi, char *buf) { - char *cmd = strtok(buf, " "); - char *s; - - if (!cmd || !u) - return; - - if (!stricmp(cmd, "\1PING")) { - if (!(s = strtok(NULL, ""))) { - *s = 0; - } - ircdproto->SendCTCP(bi, u->nick, "PING %s", s); - } + char *cmd = strtok(buf, " "); + char *s; + + if (!cmd || !u) + return; + + if (!stricmp(cmd, "\1PING")) { + if (!(s = strtok(NULL, ""))) { + *s = 0; + } + ircdproto->SendCTCP(bi, u->nick, "PING %s", s); + } } /*************************************************************************/ @@ -127,305 +127,305 @@ void botmsgs(User * u, BotInfo * bi, char *buf) void botchanmsgs(User * u, ChannelInfo * ci, char *buf) { - int c; - int16 cstatus = 0; - char *cmd; - UserData *ud; - - if (!u || !buf || !ci) { - return; - } - - /* Answer to ping if needed, without breaking the buffer. */ - if (!strnicmp(buf, "\1PING", 5)) { - ircdproto->SendCTCP(ci->bi, u->nick, "PING %s", buf); - } - - /* If it's a /me, cut the CTCP part at the beginning (not - * at the end, because one character just doesn't matter, - * but the ACTION may create strange behaviours with the - * caps or badwords kickers */ - if (!strnicmp(buf, "\1ACTION ", 8)) - buf += 8; - - /* Now we can make kicker stuff. We try to order the checks - * from the fastest one to the slowest one, since there's - * no need to process other kickers if an user is kicked before - * the last kicker check. - * - * But FIRST we check whether the user is protected in any - * way. - */ - - /* We first retrieve the user status on the channel if needed */ - if (ci->botflags & (BS_DONTKICKOPS | BS_DONTKICKVOICES)) - cstatus = chan_get_user_status(ci->c, u); - - if (buf && !check_access(u, ci, CA_NOKICK) && - (!(ci->botflags & BS_DONTKICKOPS) - || !(cstatus & (CUS_HALFOP | CUS_OP | CUS_OWNER | CUS_PROTECT))) - - && (!(ci->botflags & BS_DONTKICKVOICES) || !(cstatus & CUS_VOICE))) { - /* Bolds kicker */ - if ((ci->botflags & BS_KICK_BOLDS) && strchr(buf, 2)) { - check_ban(ci, u, TTB_BOLDS); - bot_kick(ci, u, BOT_REASON_BOLD); - return; - } - - /* Color kicker */ - if ((ci->botflags & BS_KICK_COLORS) && strchr(buf, 3)) { - check_ban(ci, u, TTB_COLORS); - bot_kick(ci, u, BOT_REASON_COLOR); - return; - } - - /* Reverses kicker */ - if ((ci->botflags & BS_KICK_REVERSES) && strchr(buf, 22)) { - check_ban(ci, u, TTB_REVERSES); - bot_kick(ci, u, BOT_REASON_REVERSE); - return; - } - - /* Underlines kicker */ - if ((ci->botflags & BS_KICK_UNDERLINES) && strchr(buf, 31)) { - check_ban(ci, u, TTB_UNDERLINES); - bot_kick(ci, u, BOT_REASON_UNDERLINE); - return; - } - - /* Caps kicker */ - if ((ci->botflags & BS_KICK_CAPS) - && ((c = strlen(buf)) >= ci->capsmin)) { - int i = 0; - int l = 0; - char *s = buf; - - do { - if (isupper(*s)) - i++; - else if (islower(*s)) - l++; - } while (*s++); - - /* i counts uppercase chars, l counts lowercase chars. Only - * alphabetic chars (so islower || isupper) qualify for the - * percentage of caps to kick for; the rest is ignored. -GD - */ - - if (i >= ci->capsmin && i * 100 / (i + l) >= ci->capspercent) { - check_ban(ci, u, TTB_CAPS); - bot_kick(ci, u, BOT_REASON_CAPS); - return; - } - } - - /* Bad words kicker */ - if (ci->botflags & BS_KICK_BADWORDS) { - int i; - int mustkick = 0; - char *nbuf; - BadWord *bw; - - /* Normalize the buffer */ - nbuf = normalizeBuffer(buf); - - for (i = 0, bw = ci->badwords; i < ci->bwcount; i++, bw++) { - if (!bw->in_use) - continue; - - if (bw->type == BW_ANY - && ((BSCaseSensitive && strstr(nbuf, bw->word)) - || (!BSCaseSensitive && stristr(nbuf, bw->word)))) { - mustkick = 1; - } else if (bw->type == BW_SINGLE) { - int len = strlen(bw->word); - - if ((BSCaseSensitive && !strcmp(nbuf, bw->word)) - || (!BSCaseSensitive - && (!stricmp(nbuf, bw->word)))) { - mustkick = 1; - /* two next if are quite odd isn't it? =) */ - } else if ((strchr(nbuf, ' ') == nbuf + len) - && - ((BSCaseSensitive - && !strcmp(nbuf, bw->word)) - || (!BSCaseSensitive - && (stristr(nbuf, bw->word) == - nbuf)))) { - mustkick = 1; - } else { - if ((strrchr(nbuf, ' ') == - nbuf + strlen(nbuf) - len - 1) - && - ((BSCaseSensitive - && (strstr(nbuf, bw->word) == - nbuf + strlen(nbuf) - len)) - || (!BSCaseSensitive - && (stristr(nbuf, bw->word) == - nbuf + strlen(nbuf) - len)))) { - mustkick = 1; - } else { - char *wordbuf = (char *)scalloc(len + 3, 1); - - wordbuf[0] = ' '; - wordbuf[len + 1] = ' '; - wordbuf[len + 2] = '\0'; - memcpy(wordbuf + 1, bw->word, len); - - if ((BSCaseSensitive - && (strstr(nbuf, wordbuf))) - || (!BSCaseSensitive - && (stristr(nbuf, wordbuf)))) { - mustkick = 1; - } - - /* free previous (sc)allocated memory (#850) */ - free(wordbuf); - } - } - } else if (bw->type == BW_START) { - int len = strlen(bw->word); - - if ((BSCaseSensitive - && (!strncmp(nbuf, bw->word, len))) - || (!BSCaseSensitive - && (!strnicmp(nbuf, bw->word, len)))) { - mustkick = 1; - } else { - char *wordbuf = (char *)scalloc(len + 2, 1); - - memcpy(wordbuf + 1, bw->word, len); - wordbuf[0] = ' '; - wordbuf[len + 1] = '\0'; - - if ((BSCaseSensitive && (strstr(nbuf, wordbuf))) - || (!BSCaseSensitive - && (stristr(nbuf, wordbuf)))) - mustkick = 1; - - free(wordbuf); - } - } else if (bw->type == BW_END) { - int len = strlen(bw->word); - - if ((BSCaseSensitive - && - (!strncmp - (nbuf + strlen(nbuf) - len, bw->word, len))) - || (!BSCaseSensitive - && - (!strnicmp - (nbuf + strlen(nbuf) - len, bw->word, - len)))) { - mustkick = 1; - } else { - char *wordbuf = (char *)scalloc(len + 2, 1); - - memcpy(wordbuf, bw->word, len); - wordbuf[len] = ' '; - wordbuf[len + 1] = '\0'; - - if ((BSCaseSensitive && (strstr(nbuf, wordbuf))) - || (!BSCaseSensitive - && (stristr(nbuf, wordbuf)))) - mustkick = 1; - - free(wordbuf); - } - } - - if (mustkick) { - check_ban(ci, u, TTB_BADWORDS); - if (BSGentleBWReason) - bot_kick(ci, u, BOT_REASON_BADWORD_GENTLE); - else - bot_kick(ci, u, BOT_REASON_BADWORD, bw->word); - - /* free the normalized buffer before return (#850) */ - Anope_Free(nbuf); - - return; - } - } - - /* Free the normalized buffer */ - Anope_Free(nbuf); - } - - /* Flood kicker */ - if (ci->botflags & BS_KICK_FLOOD) { - time_t now = time(NULL); - - ud = get_user_data(ci->c, u); - if (!ud) { - return; - } - - if (now - ud->last_start > ci->floodsecs) { - ud->last_start = time(NULL); - ud->lines = 0; - } - - ud->lines++; - if (ud->lines >= ci->floodlines) { - check_ban(ci, u, TTB_FLOOD); - bot_kick(ci, u, BOT_REASON_FLOOD); - return; - } - } - - /* Repeat kicker */ - if (ci->botflags & BS_KICK_REPEAT) { - ud = get_user_data(ci->c, u); - if (!ud) { - return; - } - if (ud->lastline && stricmp(ud->lastline, buf)) { - free(ud->lastline); - ud->lastline = sstrdup(buf); - ud->times = 0; - } else { - if (!ud->lastline) - ud->lastline = sstrdup(buf); - ud->times++; - } - - if (ud->times >= ci->repeattimes) { - check_ban(ci, u, TTB_REPEAT); - bot_kick(ci, u, BOT_REASON_REPEAT); - return; - } - } - } - - - /* return if the user is on the ignore list */ - if (get_ignore(u->nick) != NULL) { - return; - } - - /* Fantaisist commands */ - - if (buf && (ci->botflags & BS_FANTASY) && *buf == *BSFantasyCharacter) { - cmd = strtok(buf, " "); - - if (cmd && (cmd[0] == *BSFantasyCharacter)) { - char *params = strtok(NULL, ""); - const char *event_name = EVENT_BOT_FANTASY_NO_ACCESS; - - /* Strip off the fantasy character */ - cmd++; - - if (check_access(u, ci, CA_FANTASIA)) - event_name = EVENT_BOT_FANTASY; - - if (params) - send_event(event_name, 4, cmd, u->nick, ci->name, params); - else - send_event(event_name, 3, cmd, u->nick, ci->name); - } - } + int c; + int16 cstatus = 0; + char *cmd; + UserData *ud; + + if (!u || !buf || !ci) { + return; + } + + /* Answer to ping if needed, without breaking the buffer. */ + if (!strnicmp(buf, "\1PING", 5)) { + ircdproto->SendCTCP(ci->bi, u->nick, "PING %s", buf); + } + + /* If it's a /me, cut the CTCP part at the beginning (not + * at the end, because one character just doesn't matter, + * but the ACTION may create strange behaviours with the + * caps or badwords kickers */ + if (!strnicmp(buf, "\1ACTION ", 8)) + buf += 8; + + /* Now we can make kicker stuff. We try to order the checks + * from the fastest one to the slowest one, since there's + * no need to process other kickers if an user is kicked before + * the last kicker check. + * + * But FIRST we check whether the user is protected in any + * way. + */ + + /* We first retrieve the user status on the channel if needed */ + if (ci->botflags & (BS_DONTKICKOPS | BS_DONTKICKVOICES)) + cstatus = chan_get_user_status(ci->c, u); + + if (buf && !check_access(u, ci, CA_NOKICK) && + (!(ci->botflags & BS_DONTKICKOPS) + || !(cstatus & (CUS_HALFOP | CUS_OP | CUS_OWNER | CUS_PROTECT))) + + && (!(ci->botflags & BS_DONTKICKVOICES) || !(cstatus & CUS_VOICE))) { + /* Bolds kicker */ + if ((ci->botflags & BS_KICK_BOLDS) && strchr(buf, 2)) { + check_ban(ci, u, TTB_BOLDS); + bot_kick(ci, u, BOT_REASON_BOLD); + return; + } + + /* Color kicker */ + if ((ci->botflags & BS_KICK_COLORS) && strchr(buf, 3)) { + check_ban(ci, u, TTB_COLORS); + bot_kick(ci, u, BOT_REASON_COLOR); + return; + } + + /* Reverses kicker */ + if ((ci->botflags & BS_KICK_REVERSES) && strchr(buf, 22)) { + check_ban(ci, u, TTB_REVERSES); + bot_kick(ci, u, BOT_REASON_REVERSE); + return; + } + + /* Underlines kicker */ + if ((ci->botflags & BS_KICK_UNDERLINES) && strchr(buf, 31)) { + check_ban(ci, u, TTB_UNDERLINES); + bot_kick(ci, u, BOT_REASON_UNDERLINE); + return; + } + + /* Caps kicker */ + if ((ci->botflags & BS_KICK_CAPS) + && ((c = strlen(buf)) >= ci->capsmin)) { + int i = 0; + int l = 0; + char *s = buf; + + do { + if (isupper(*s)) + i++; + else if (islower(*s)) + l++; + } while (*s++); + + /* i counts uppercase chars, l counts lowercase chars. Only + * alphabetic chars (so islower || isupper) qualify for the + * percentage of caps to kick for; the rest is ignored. -GD + */ + + if (i >= ci->capsmin && i * 100 / (i + l) >= ci->capspercent) { + check_ban(ci, u, TTB_CAPS); + bot_kick(ci, u, BOT_REASON_CAPS); + return; + } + } + + /* Bad words kicker */ + if (ci->botflags & BS_KICK_BADWORDS) { + int i; + int mustkick = 0; + char *nbuf; + BadWord *bw; + + /* Normalize the buffer */ + nbuf = normalizeBuffer(buf); + + for (i = 0, bw = ci->badwords; i < ci->bwcount; i++, bw++) { + if (!bw->in_use) + continue; + + if (bw->type == BW_ANY + && ((BSCaseSensitive && strstr(nbuf, bw->word)) + || (!BSCaseSensitive && stristr(nbuf, bw->word)))) { + mustkick = 1; + } else if (bw->type == BW_SINGLE) { + int len = strlen(bw->word); + + if ((BSCaseSensitive && !strcmp(nbuf, bw->word)) + || (!BSCaseSensitive + && (!stricmp(nbuf, bw->word)))) { + mustkick = 1; + /* two next if are quite odd isn't it? =) */ + } else if ((strchr(nbuf, ' ') == nbuf + len) + && + ((BSCaseSensitive + && !strcmp(nbuf, bw->word)) + || (!BSCaseSensitive + && (stristr(nbuf, bw->word) == + nbuf)))) { + mustkick = 1; + } else { + if ((strrchr(nbuf, ' ') == + nbuf + strlen(nbuf) - len - 1) + && + ((BSCaseSensitive + && (strstr(nbuf, bw->word) == + nbuf + strlen(nbuf) - len)) + || (!BSCaseSensitive + && (stristr(nbuf, bw->word) == + nbuf + strlen(nbuf) - len)))) { + mustkick = 1; + } else { + char *wordbuf = (char *)scalloc(len + 3, 1); + + wordbuf[0] = ' '; + wordbuf[len + 1] = ' '; + wordbuf[len + 2] = '\0'; + memcpy(wordbuf + 1, bw->word, len); + + if ((BSCaseSensitive + && (strstr(nbuf, wordbuf))) + || (!BSCaseSensitive + && (stristr(nbuf, wordbuf)))) { + mustkick = 1; + } + + /* free previous (sc)allocated memory (#850) */ + free(wordbuf); + } + } + } else if (bw->type == BW_START) { + int len = strlen(bw->word); + + if ((BSCaseSensitive + && (!strncmp(nbuf, bw->word, len))) + || (!BSCaseSensitive + && (!strnicmp(nbuf, bw->word, len)))) { + mustkick = 1; + } else { + char *wordbuf = (char *)scalloc(len + 2, 1); + + memcpy(wordbuf + 1, bw->word, len); + wordbuf[0] = ' '; + wordbuf[len + 1] = '\0'; + + if ((BSCaseSensitive && (strstr(nbuf, wordbuf))) + || (!BSCaseSensitive + && (stristr(nbuf, wordbuf)))) + mustkick = 1; + + free(wordbuf); + } + } else if (bw->type == BW_END) { + int len = strlen(bw->word); + + if ((BSCaseSensitive + && + (!strncmp + (nbuf + strlen(nbuf) - len, bw->word, len))) + || (!BSCaseSensitive + && + (!strnicmp + (nbuf + strlen(nbuf) - len, bw->word, + len)))) { + mustkick = 1; + } else { + char *wordbuf = (char *)scalloc(len + 2, 1); + + memcpy(wordbuf, bw->word, len); + wordbuf[len] = ' '; + wordbuf[len + 1] = '\0'; + + if ((BSCaseSensitive && (strstr(nbuf, wordbuf))) + || (!BSCaseSensitive + && (stristr(nbuf, wordbuf)))) + mustkick = 1; + + free(wordbuf); + } + } + + if (mustkick) { + check_ban(ci, u, TTB_BADWORDS); + if (BSGentleBWReason) + bot_kick(ci, u, BOT_REASON_BADWORD_GENTLE); + else + bot_kick(ci, u, BOT_REASON_BADWORD, bw->word); + + /* free the normalized buffer before return (#850) */ + Anope_Free(nbuf); + + return; + } + } + + /* Free the normalized buffer */ + Anope_Free(nbuf); + } + + /* Flood kicker */ + if (ci->botflags & BS_KICK_FLOOD) { + time_t now = time(NULL); + + ud = get_user_data(ci->c, u); + if (!ud) { + return; + } + + if (now - ud->last_start > ci->floodsecs) { + ud->last_start = time(NULL); + ud->lines = 0; + } + + ud->lines++; + if (ud->lines >= ci->floodlines) { + check_ban(ci, u, TTB_FLOOD); + bot_kick(ci, u, BOT_REASON_FLOOD); + return; + } + } + + /* Repeat kicker */ + if (ci->botflags & BS_KICK_REPEAT) { + ud = get_user_data(ci->c, u); + if (!ud) { + return; + } + if (ud->lastline && stricmp(ud->lastline, buf)) { + free(ud->lastline); + ud->lastline = sstrdup(buf); + ud->times = 0; + } else { + if (!ud->lastline) + ud->lastline = sstrdup(buf); + ud->times++; + } + + if (ud->times >= ci->repeattimes) { + check_ban(ci, u, TTB_REPEAT); + bot_kick(ci, u, BOT_REASON_REPEAT); + return; + } + } + } + + + /* return if the user is on the ignore list */ + if (get_ignore(u->nick) != NULL) { + return; + } + + /* Fantaisist commands */ + + if (buf && (ci->botflags & BS_FANTASY) && *buf == *BSFantasyCharacter) { + cmd = strtok(buf, " "); + + if (cmd && (cmd[0] == *BSFantasyCharacter)) { + char *params = strtok(NULL, ""); + const char *event_name = EVENT_BOT_FANTASY_NO_ACCESS; + + /* Strip off the fantasy character */ + cmd++; + + if (check_access(u, ci, CA_FANTASIA)) + event_name = EVENT_BOT_FANTASY; + + if (params) + send_event(event_name, 4, cmd, u->nick, ci->name, params); + else + send_event(event_name, 3, cmd, u->nick, ci->name); + } + } } /*************************************************************************/ @@ -434,51 +434,51 @@ void botchanmsgs(User * u, ChannelInfo * ci, char *buf) #define SAFE(x) do { \ - if ((x) < 0) { \ + if ((x) < 0) { \ if (!forceload) \ - fatal("Read error on %s", BotDBName); \ + fatal("Read error on %s",