diff --git a/configure b/configure index 7afe98ed1..e1bef08c9 100755 --- a/configure +++ b/configure @@ -7798,7 +7798,7 @@ fi UNRLINCDIR="`pwd`/include" -ac_config_files="$ac_config_files Makefile src/modules/Makefile src/modules/chanmodes/Makefile src/modules/usermodes/Makefile unreal ircdcron/ircdchk ircdcron/ircd.cron" +ac_config_files="$ac_config_files Makefile src/modules/Makefile src/modules/chanmodes/Makefile src/modules/usermodes/Makefile src/modules/extbans/Makefile unreal ircdcron/ircdchk ircdcron/ircd.cron" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -8495,6 +8495,7 @@ do "src/modules/Makefile") CONFIG_FILES="$CONFIG_FILES src/modules/Makefile" ;; "src/modules/chanmodes/Makefile") CONFIG_FILES="$CONFIG_FILES src/modules/chanmodes/Makefile" ;; "src/modules/usermodes/Makefile") CONFIG_FILES="$CONFIG_FILES src/modules/usermodes/Makefile" ;; + "src/modules/extbans/Makefile") CONFIG_FILES="$CONFIG_FILES src/modules/extbans/Makefile" ;; "unreal") CONFIG_FILES="$CONFIG_FILES unreal" ;; "ircdcron/ircdchk") CONFIG_FILES="$CONFIG_FILES ircdcron/ircdchk" ;; "ircdcron/ircd.cron") CONFIG_FILES="$CONFIG_FILES ircdcron/ircd.cron" ;; diff --git a/configure.ac b/configure.ac index 7251e6d71..b9b82ca5a 100644 --- a/configure.ac +++ b/configure.ac @@ -734,6 +734,7 @@ AC_CONFIG_FILES([Makefile src/modules/Makefile src/modules/chanmodes/Makefile src/modules/usermodes/Makefile + src/modules/extbans/Makefile unreal ircdcron/ircdchk ircdcron/ircd.cron]) diff --git a/include/h.h b/include/h.h index 0796e8bbe..d9e322658 100644 --- a/include/h.h +++ b/include/h.h @@ -180,11 +180,9 @@ extern long get_access(aClient *, aChannel *); extern int is_chan_op(aClient *, aChannel *); extern int has_voice(aClient *, aChannel *); extern int is_chanowner(aClient *, aChannel *); -#ifndef DISABLE_EXTBAN_STACKING extern int ban_check_mask(aClient *, aChannel *, char *, int, int); extern int extban_is_ok_nuh_extban(aClient *, aChannel *, char *, int, int, int); extern char* extban_conv_param_nuh_or_extban(char *); -#endif extern Ban *is_banned(aClient *, aChannel *, int); extern Ban *is_banned_with_nick(aClient *, aChannel *, int, char *); extern int parse_help(aClient *, char *, char *); diff --git a/modules.conf b/modules.conf index 46a3a763c..0205f0051 100644 --- a/modules.conf +++ b/modules.conf @@ -137,3 +137,12 @@ loadmodule "modules/chanmodes/secureonly"; /* +z */ /*** User modes ***/ loadmodule "modules/usermodes/noctcp"; /* +T */ loadmodule "modules/usermodes/censor"; /* +G */ + +/*** Extended Bans ***/ +loadmodule "modules/extbans/join"; /* +b ~j */ +loadmodule "modules/extbans/quiet"; /* +b ~q */ +loadmodule "modules/extbans/nickchange"; /* +b ~n */ +loadmodule "modules/extbans/realname"; /* +b ~r */ +loadmodule "modules/extbans/regnick"; /* +b ~R */ +loadmodule "modules/extbans/account"; /* +b ~a */ +loadmodule "modules/extbans/inchannel"; /* +b ~c */ diff --git a/src/extbans.c b/src/extbans.c index 268d4d552..90db1b5c1 100644 --- a/src/extbans.c +++ b/src/extbans.c @@ -150,149 +150,6 @@ char tmpbuf[512]; * least the '~t:' part (t=type). -- Syzop */ -/* TODO: just get rid of strchr */ - -char *extban_modec_conv_param(char *para) -{ -static char retbuf[CHANNELLEN+6]; -char *chan, *p, symbol='\0'; - - strlcpy(retbuf, para, sizeof(retbuf)); - chan = retbuf+3; - - if ((*chan == '+') || (*chan == '%') || (*chan == '%') || - (*chan == '@') || (*chan == '&') || (*chan == '~')) - chan++; - - if ((*chan != '#') && (*chan != '*') && (*chan != '?')) - return NULL; - - if (strlen(chan) > CHANNELLEN) - chan[CHANNELLEN] = '\0'; - clean_channelname(chan); - p = strchr(chan, ':'); /* ~r:#chan:*.blah.net is not allowed (for now) */ - if (p) - *p = '\0'; - /* on a sidenote '#' is allowed because it's a valid channel (atm) */ - return retbuf; -} - -/* The only purpose of this function is a temporary workaround to prevent a desynch.. pfff */ -int extban_modec_is_ok(aClient *sptr, aChannel *chptr, char *para, int checkt, int what, int what2) -{ -char *p; - - if ((checkt == EXBCHK_PARAM) && MyClient(sptr) && (what == MODE_ADD) && (strlen(para) > 3)) - { - p = para + 3; - if ((*p == '+') || (*p == '%') || (*p == '%') || - (*p == '@') || (*p == '&') || (*p == '~')) - p++; - - if (*p != '#') - { - sendnotice(sptr, "Please use a # in the channelname (eg: ~c:#*blah*)"); - return 0; - } - } - return 1; -} - - -static int extban_modec_compareflags(char symbol, int flags) -{ -int require=0; - - if (symbol == '+') - require = CHFL_VOICE|CHFL_HALFOP|CHFL_CHANOP|CHFL_CHANPROT|CHFL_CHANOWNER; - else if (symbol == '%') - require = CHFL_HALFOP|CHFL_CHANOP|CHFL_CHANPROT|CHFL_CHANOWNER; - else if (symbol == '@') - require = CHFL_CHANOP|CHFL_CHANPROT|CHFL_CHANOWNER; - else if (symbol == '&') - require = CHFL_CHANPROT|CHFL_CHANOWNER; - else if (symbol == '~') - require = CHFL_CHANOWNER; - - if (flags & require) - return 1; - return 0; -} -int extban_modec_is_banned(aClient *sptr, aChannel *chptr, char *ban, int type) -{ -Membership *lp; -char *p = ban+3, symbol = '\0'; - - if (*p != '#') - { - symbol = *p; - p++; - } - for (lp = sptr->user->channel; lp; lp = lp->next) - { - if (!match_esc(p, lp->chptr->chname)) - { - /* Channel matched, check symbol if needed (+/%/@/etc) */ - if (symbol) - { - if (extban_modec_compareflags(symbol, lp->flags)) - return 1; - } else - return 1; - } - } - return 0; -} - -int extban_modeq_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type) -{ -char *ban = banin + 3; - - if (type != BANCHK_MSG) - return 0; - -#ifdef DISABLE_STACKED_EXTBANS - return extban_is_banned_helper(ban); -#else - return ban_check_mask(sptr, chptr, ban, type, 0); -#endif -} - -int extban_moden_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type) -{ -char *ban = banin + 3; - - if (type != BANCHK_NICK) - return 0; - - if (has_voice(sptr, chptr)) - return 0; - -#ifdef DISABLE_STACKED_EXTBANS - return extban_is_banned_helper(ban); -#else - return ban_check_mask(sptr, chptr, ban, type, 0); -#endif -} - -/* a ban that affects JOINs only */ -int extban_modej_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type) -{ - char *sub_ban; - - if (type != BANCHK_JOIN) - return 0; - - sub_ban = banin + 3; - -#ifdef DISABLE_STACKED_EXTBANS - return extban_is_banned_helper(sub_ban); -#else - return ban_check_mask(sptr, chptr, sub_ban, type, 0); -#endif -} - -#ifndef DISABLE_STACKED_EXTBANS /** General is_ok for n!u@h stuff that also deals with recursive extbans. */ int extban_is_ok_nuh_extban(aClient* sptr, aChannel* chptr, char* para, int checkt, int what, int what2) @@ -337,8 +194,6 @@ int extban_is_ok_nuh_extban(aClient* sptr, aChannel* chptr, char* para, int chec } return 1; /* Either not an extban, or extban has NULL is_ok. Good to go. */ } -#endif - /** Some kind of general conv_param routine, * to ensure the parameter is nick!user@host. @@ -374,7 +229,6 @@ char pfix[8]; return retbuf; } -#ifndef DISABLE_STACKED_EXTBANS /** conv_param to deal with stacked extbans. */ char* extban_conv_param_nuh_or_extban(char* para) @@ -466,142 +320,3 @@ char* extban_conv_param_nuh_or_extban(char* para) return extban_conv_param_nuh(para); } } -#endif - -/** Realname bans - conv_param */ -char *extban_moder_conv_param(char *para) -{ -char *mask; -static char retbuf[REALLEN + 8]; - - strlcpy(retbuf, para, sizeof(retbuf)); - mask = retbuf+3; - if (strlen(mask) > REALLEN + 3) - mask[REALLEN + 3] = '\0'; - if (*mask == '~') - *mask = '?'; /* Is this good? No ;) */ - return retbuf; -} - -int extban_moder_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type) -{ -char *ban = banin+3; - if (!match_esc(ban, sptr->info)) - return 1; - return 0; -} - -/** Registered user ban */ -char *extban_modeR_conv_param(char *para) -{ -static char retbuf[NICKLEN + 4]; - - strlcpy(retbuf, para, sizeof(retbuf)); - if (do_nick_name(retbuf+3) == 0) - return NULL; - return retbuf; -} - -int extban_modeR_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type) -{ -char *ban = banin+3; - - if (IsRegNick(sptr) && !strcasecmp(ban, sptr->name)) - return 1; - return 0; -} - -/** Account bans */ -char *extban_modea_conv_param(char *para) -{ -char *mask; -static char retbuf[NICKLEN + 4]; - - strlcpy(retbuf, para, sizeof(retbuf)); /* truncate */ - if (!strcmp(retbuf+3, "0")) - return NULL; /* ~a:0 would mean ban all non-regged, but we already have +R for that. */ - return retbuf; -} - -int extban_modea_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type) -{ -char *ban = banin+3; - if (!stricmp(ban, sptr->user->svid)) - return 1; - return 0; -} - -void extban_init(void) -{ - ExtbanInfo req; - - memset(&req, 0, sizeof(ExtbanInfo)); - req.flag = 'q'; -#ifdef DISABLE_STACKED_EXTBANS - req.conv_param = extban_conv_param_nuh; -#else - req.conv_param = extban_conv_param_nuh_or_extban; - req.is_ok = extban_is_ok_nuh_extban; -#endif - req.options = EXTBOPT_ACTMODIFIER; - req.is_banned = extban_modeq_is_banned; - ExtbanAdd(NULL, req); - - memset(&req, 0, sizeof(ExtbanInfo)); - req.flag = 'j'; -#ifdef DISABLE_STACKED_EXTBANS - req.conv_param = extban_conv_param_nuh; -#else - req.conv_param = extban_conv_param_nuh_or_extban; - req.is_ok = extban_is_ok_nuh_extban; -#endif - req.is_banned = extban_modej_is_banned; - req.options = EXTBOPT_ACTMODIFIER; - ExtbanAdd(NULL, req); - - memset(&req, 0, sizeof(ExtbanInfo)); - req.flag = 'n'; -#ifdef DISABLE_STACKED_EXTBANS - req.conv_param = extban_conv_param_nuh; -#else - req.conv_param = extban_conv_param_nuh_or_extban; - req.is_ok = extban_is_ok_nuh_extban; -#endif - req.is_banned = extban_moden_is_banned; - req.options = EXTBOPT_ACTMODIFIER; - ExtbanAdd(NULL, req); - - memset(&req, 0, sizeof(ExtbanInfo)); - req.flag = 'c'; - req.conv_param = extban_modec_conv_param; - req.is_banned = extban_modec_is_banned; - req.is_ok = extban_modec_is_ok; - req.options = EXTBOPT_INVEX; - ExtbanAdd(NULL, req); - - memset(&req, 0, sizeof(ExtbanInfo)); - req.flag = 'r'; - req.conv_param = extban_moder_conv_param; - req.is_banned = extban_moder_is_banned; - req.options = EXTBOPT_CHSVSMODE|EXTBOPT_INVEX; - ExtbanAdd(NULL, req); - - memset(&req, 0, sizeof(ExtbanInfo)); - req.flag = 'R'; - req.conv_param = extban_modeR_conv_param; - req.is_banned = extban_modeR_is_banned; - req.options = EXTBOPT_INVEX; - ExtbanAdd(NULL, req); - - memset(&req, 0, sizeof(ExtbanInfo)); - req.flag = 'a'; - req.conv_param = extban_modea_conv_param; - req.is_banned = extban_modea_is_banned; - req.options = EXTBOPT_INVEX; - ExtbanAdd(NULL, req); - - /* When adding new extbans, be sure to always add a prior memset like above - * so you don't "inherit" old options (we are 2005 and the 20 nanoseconds - * per-boot/rehash is NOT EXACTLY a problem....) -- Syzop. - */ -} diff --git a/src/ircd.c b/src/ircd.c index 6b9df4507..92c3ae6c9 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -1173,7 +1173,6 @@ int InitwIRCD(int argc, char *argv[]) tkl_init(); umode_init(); extcmode_init(); - extban_init(); init_random(); /* needs to be done very early!! */ clear_scache_hash_table(); #ifdef FORCE_CORE diff --git a/src/modules/Makefile.in b/src/modules/Makefile.in index 00e4ea356..9077c9b92 100644 --- a/src/modules/Makefile.in +++ b/src/modules/Makefile.in @@ -67,6 +67,7 @@ all: build build: $(MODULES) cd chanmodes; $(MAKE) all cd usermodes; $(MAKE) all + cd extbans; $(MAKE) all custommodule: $(MODULEFILE).c $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ diff --git a/src/modules/extbans/Makefile.in b/src/modules/extbans/Makefile.in new file mode 100644 index 000000000..dc6b1aee1 --- /dev/null +++ b/src/modules/extbans/Makefile.in @@ -0,0 +1,85 @@ +#************************************************************************ +#* IRC - Internet Relay Chat, src/modules/chanmodes/Makefile +#* Copyright (C) Carsten V. Munk 2001 & The UnrealIRCd Team +#* +#* This program is free software; you can redistribute it and/or modify +#* it under the terms of the GNU General Public License as published by +#* the Free Software Foundation; either version 1, or (at your option) +#* any later version. +#* +#* This program is distributed in the hope that it will be useful, +#* but WITHOUT ANY WARRANTY; without even the implied warranty of +#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#* GNU General Public License for more details. +#* +#* You should have received a copy of the GNU General Public License +#* along with this program; if not, write to the Free Software +#* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#*/ + +INCLUDES = ../../include/auth.h ../../include/channel.h \ + ../../include/class.h ../../include/common.h ../../include/config.h ../../include/dbuf.h \ + ../../include/dynconf.h ../../include/events.h ../../include/fdlist.h ../../include/h.h \ + ../../include/hash.h ../../include/inet.h ../../include/ircsprintf.h \ + ../../include/license.h ../../include/macros.h \ + ../../include/modules.h ../../include/modversion.h ../../include/msg.h \ + ../../include/numeric.h ../../include/proto.h ../../include/res.h \ + ../../include/resource.h ../../include/setup.h ../../include/sjoin.h \ + ../../include/sock.h ../../include/ssl.h ../../include/struct.h ../../include/sys.h \ + ../../include/threads.h ../../include/types.h ../../include/url.h \ + ../../include/version.h ../../include/whowas.h + +R_MODULES= \ + join.so quiet.so nickchange.so inchannel.so realname.so regnick.so account.so + +MODULES=$(R_MODULES) +MODULEFLAGS=@MODULEFLAGS@ +CC=@CC@ +RM=@RM@ + +all: build + +build: $(MODULES) + +custommodule: $(MODULEFILE).c + $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ + -o $(MODULEFILE).so $(MODULEFILE).c $(EXLIBS) + +clean: + $(RM) -f *.o *.so *~ core + +############################################################################# +# .so's section +############################################################################# + +skel.so: skel.c $(INCLUDES) + $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ + -o skel.so skel.c + +join.so: join.c $(INCLUDES) + $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ + -o join.so join.c + +quiet.so: quiet.c $(INCLUDES) + $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ + -o quiet.so quiet.c + +nickchange.so: nickchange.c $(INCLUDES) + $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ + -o nickchange.so nickchange.c + +inchannel.so: inchannel.c $(INCLUDES) + $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ + -o inchannel.so inchannel.c + +realname.so: realname.c $(INCLUDES) + $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ + -o realname.so realname.c + +regnick.so: regnick.c $(INCLUDES) + $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ + -o regnick.so regnick.c + +account.so: account.c $(INCLUDES) + $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ + -o account.so account.c diff --git a/src/modules/extbans/account.c b/src/modules/extbans/account.c new file mode 100644 index 000000000..337957112 --- /dev/null +++ b/src/modules/extbans/account.c @@ -0,0 +1,89 @@ +/* + * Extended ban to ban/exempt by services account (~b ~a:accountname) + * (C) Copyright 2011-.. Bram Matthys (Syzop) and the UnrealIRCd team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +#include "unrealircd.h" + +ModuleHeader MOD_HEADER(account) += { + "chanmodes/extbans/account", + "$Id$", + "ExtBan ~a - Ban/exempt by services account name", + "3.2-b8-1", + NULL +}; + +/* Forward declarations */ +char *extban_account_conv_param(char *para); +int extban_account_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type); + +/** Called upon module init */ +DLLFUNC int MOD_INIT(account)(ModuleInfo *modinfo) +{ + ExtbanInfo req; + + req.flag = 'a'; + req.is_ok = NULL; + req.conv_param = extban_account_conv_param; + req.is_banned = extban_account_is_banned; + req.options = EXTBOPT_ACTMODIFIER; // or not ! + if (!ExtbanAdd(modinfo->handle, req)) + { + config_error("could not register extended ban type"); + return MOD_FAILED; + } + + MARK_AS_OFFICIAL_MODULE(modinfo); + + return MOD_SUCCESS; +} + +/** Called upon module load */ +DLLFUNC int MOD_LOAD(account)(int module_load) +{ + return MOD_SUCCESS; +} + +/** Called upon unload */ +DLLFUNC int MOD_UNLOAD(account)(int module_unload) +{ + return MOD_SUCCESS; +} + +/** Account bans */ +char *extban_account_conv_param(char *para) +{ + char *mask; + static char retbuf[NICKLEN + 4]; + + strlcpy(retbuf, para, sizeof(retbuf)); /* truncate */ + + if (!strcmp(retbuf+3, "0")) + return NULL; /* ~a:0 would mean ban all non-regged, but we already have +R for that. */ + + return retbuf; +} + +int extban_account_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type) +{ + char *ban = banin+3; + + if (!stricmp(ban, sptr->user->svid)) + return 1; + + return 0; +} diff --git a/src/modules/extbans/inchannel.c b/src/modules/extbans/inchannel.c new file mode 100644 index 000000000..5be231020 --- /dev/null +++ b/src/modules/extbans/inchannel.c @@ -0,0 +1,165 @@ +/* + * Extended ban: "in channel?" (+b ~c:#chan) + * (C) Copyright 2003-.. Bram Matthys (Syzop) and the UnrealIRCd team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +#include "unrealircd.h" + +ModuleHeader MOD_HEADER(inchannel) += { + "chanmodes/extbans/inchannel", + "$Id$", + "ExtBan ~c - banned when in specified channel", + "3.2-b8-1", + NULL +}; + +/* Forward declarations */ +int extban_inchannel_is_ok(aClient *sptr, aChannel *chptr, char *para, int checkt, int what, int what2); +char *extban_inchannel_conv_param(char *para); +int extban_inchannel_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type); + +/** Called upon module init */ +DLLFUNC int MOD_INIT(inchannel)(ModuleInfo *modinfo) +{ + ExtbanInfo req; + + req.flag = 'c'; + req.is_ok = extban_inchannel_is_ok; + req.conv_param = extban_inchannel_conv_param; + req.is_banned = extban_inchannel_is_banned; + req.options = EXTBOPT_INVEX; /* for +I too */ + if (!ExtbanAdd(modinfo->handle, req)) + { + config_error("could not register extended ban type"); + return MOD_FAILED; + } + + MARK_AS_OFFICIAL_MODULE(modinfo); + + return MOD_SUCCESS; +} + +/** Called upon module load */ +DLLFUNC int MOD_LOAD(inchannel)(int module_load) +{ + return MOD_SUCCESS; +} + +/** Called upon unload */ +DLLFUNC int MOD_UNLOAD(inchannel)(int module_unload) +{ + return MOD_SUCCESS; +} + +char *extban_inchannel_conv_param(char *para) +{ + static char retbuf[CHANNELLEN+6]; + char *chan, *p, symbol='\0'; + + strlcpy(retbuf, para, sizeof(retbuf)); + chan = retbuf+3; + + if ((*chan == '+') || (*chan == '%') || (*chan == '%') || + (*chan == '@') || (*chan == '&') || (*chan == '~')) + chan++; + + if ((*chan != '#') && (*chan != '*') && (*chan != '?')) + return NULL; + + if (strlen(chan) > CHANNELLEN) + chan[CHANNELLEN] = '\0'; + + clean_channelname(chan); + + p = strchr(chan, ':'); /* ~r:#chan:*.blah.net is not allowed (for now) */ + if (p) + *p = '\0'; + + /* on a sidenote '#' is allowed because it's a valid channel (atm) */ + return retbuf; +} + +/* The only purpose of this function is a temporary workaround to prevent a desynch.. pfff */ +int extban_inchannel_is_ok(aClient *sptr, aChannel *chptr, char *para, int checkt, int what, int what2) +{ + char *p; + + if ((checkt == EXBCHK_PARAM) && MyClient(sptr) && (what == MODE_ADD) && (strlen(para) > 3)) + { + p = para + 3; + if ((*p == '+') || (*p == '%') || (*p == '%') || + (*p == '@') || (*p == '&') || (*p == '~')) + p++; + + if (*p != '#') + { + sendnotice(sptr, "Please use a # in the channelname (eg: ~c:#*blah*)"); + return 0; + } + } + return 1; +} + +static int extban_inchannel_compareflags(char symbol, int flags) +{ + int require=0; + + if (symbol == '+') + require = CHFL_VOICE|CHFL_HALFOP|CHFL_CHANOP|CHFL_CHANPROT|CHFL_CHANOWNER; + else if (symbol == '%') + require = CHFL_HALFOP|CHFL_CHANOP|CHFL_CHANPROT|CHFL_CHANOWNER; + else if (symbol == '@') + require = CHFL_CHANOP|CHFL_CHANPROT|CHFL_CHANOWNER; + else if (symbol == '&') + require = CHFL_CHANPROT|CHFL_CHANOWNER; + else if (symbol == '~') + require = CHFL_CHANOWNER; + + if (flags & require) + return 1; + + return 0; +} + +int extban_inchannel_is_banned(aClient *sptr, aChannel *chptr, char *ban, int type) +{ + Membership *lp; + char *p = ban+3, symbol = '\0'; + + if (*p != '#') + { + symbol = *p; + p++; + } + + for (lp = sptr->user->channel; lp; lp = lp->next) + { + if (!match_esc(p, lp->chptr->chname)) + { + /* Channel matched, check symbol if needed (+/%/@/etc) */ + if (symbol) + { + if (extban_inchannel_compareflags(symbol, lp->flags)) + return 1; + } else + return 1; + } + } + + return 0; +} + diff --git a/src/modules/extbans/join.c b/src/modules/extbans/join.c new file mode 100644 index 000000000..38a637876 --- /dev/null +++ b/src/modules/extbans/join.c @@ -0,0 +1,78 @@ +/* + * Extended ban that affects JOIN only (+b ~j) + * (C) Copyright 2003-.. Bram Matthys (Syzop) and the UnrealIRCd team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +#include "unrealircd.h" + +ModuleHeader MOD_HEADER(join) += { + "chanmodes/extbans/join", + "$Id$", + "Extban ~j - prevent join only", + "3.2-b8-1", + NULL +}; + +/* Forward declarations */ +int extban_modej_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type); + +/** Called upon module init */ +DLLFUNC int MOD_INIT(join)(ModuleInfo *modinfo) +{ + ExtbanInfo req; + + req.flag = 'j'; + req.is_ok = extban_is_ok_nuh_extban; + req.conv_param = extban_conv_param_nuh_or_extban; + req.is_banned = extban_modej_is_banned; + req.options = EXTBOPT_ACTMODIFIER; + if (!ExtbanAdd(modinfo->handle, req)) + { + config_error("could not register extended ban type"); + return MOD_FAILED; + } + + MARK_AS_OFFICIAL_MODULE(modinfo); + + return MOD_SUCCESS; +} + +/** Called upon module load */ +DLLFUNC int MOD_LOAD(join)(int module_load) +{ + return MOD_SUCCESS; +} + +/** Called upon unload */ +DLLFUNC int MOD_UNLOAD(join)(int module_unload) +{ + return MOD_SUCCESS; +} + +/** This ban that affects JOINs only */ +int extban_modej_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type) +{ + char *sub_ban; + + if (type != BANCHK_JOIN) + return 0; + + sub_ban = banin + 3; + + return ban_check_mask(sptr, chptr, sub_ban, type, 0); +} + diff --git a/src/modules/extbans/nickchange.c b/src/modules/extbans/nickchange.c new file mode 100644 index 000000000..43b4a28d4 --- /dev/null +++ b/src/modules/extbans/nickchange.c @@ -0,0 +1,78 @@ +/* + * Extended ban that affects nick-changes only (+b ~n) + * (C) Copyright 2003-.. Bram Matthys (Syzop) and the UnrealIRCd team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +#include "unrealircd.h" + +ModuleHeader MOD_HEADER(nickchange) += { + "chanmodes/extbans/nickchange", + "$Id$", + "ExtBan ~n - prevent nick-changes only", + "3.2-b8-1", + NULL +}; + +/* Forward declarations */ +int extban_nickchange_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type); + +/** Called upon module init */ +DLLFUNC int MOD_INIT(nickchange)(ModuleInfo *modinfo) +{ + ExtbanInfo req; + + req.flag = 'n'; + req.is_ok = extban_is_ok_nuh_extban; + req.conv_param = extban_conv_param_nuh_or_extban; + req.is_banned = extban_nickchange_is_banned; + req.options = EXTBOPT_ACTMODIFIER; + if (!ExtbanAdd(modinfo->handle, req)) + { + config_error("could not register extended ban type"); + return MOD_FAILED; + } + + MARK_AS_OFFICIAL_MODULE(modinfo); + + return MOD_SUCCESS; +} + +/** Called upon module load */ +DLLFUNC int MOD_LOAD(nickchange)(int module_load) +{ + return MOD_SUCCESS; +} + +/** Called upon unload */ +DLLFUNC int MOD_UNLOAD(nickchange)(int module_unload) +{ + return MOD_SUCCESS; +} + +/** This ban that affects nick-changes only */ +int extban_nickchange_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type) +{ + char *sub_ban; + + if (type != BANCHK_NICK) + return 0; + + sub_ban = banin + 3; + + return ban_check_mask(sptr, chptr, sub_ban, type, 0); +} + diff --git a/src/modules/extbans/quiet.c b/src/modules/extbans/quiet.c new file mode 100644 index 000000000..a3d66f0d5 --- /dev/null +++ b/src/modules/extbans/quiet.c @@ -0,0 +1,77 @@ +/* + * Extended ban that affects messages/notices only (+b ~q) + * (C) Copyright 2003-.. Bram Matthys (Syzop) and the UnrealIRCd team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +#include "unrealircd.h" + +ModuleHeader MOD_HEADER(quiet) += { + "chanmodes/extbans/quiet", + "$Id$", + "ExtBan ~q - prevent messages only (quiet)", + "3.2-b8-1", + NULL +}; + +/* Forward declarations */ +int extban_quiet_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type); + +/** Called upon module init */ +DLLFUNC int MOD_INIT(quiet)(ModuleInfo *modinfo) +{ + ExtbanInfo req; + + req.flag = 'q'; + req.is_ok = extban_is_ok_nuh_extban; + req.conv_param = extban_conv_param_nuh_or_extban; + req.is_banned = extban_quiet_is_banned; + req.options = EXTBOPT_ACTMODIFIER; + if (!ExtbanAdd(modinfo->handle, req)) + { + config_error("could not register extended ban type"); + return MOD_FAILED; + } + + MARK_AS_OFFICIAL_MODULE(modinfo); + + return MOD_SUCCESS; +} + +/** Called upon module load */ +DLLFUNC int MOD_LOAD(quiet)(int module_load) +{ + return MOD_SUCCESS; +} + +/** Called upon unload */ +DLLFUNC int MOD_UNLOAD(quiet)(int module_unload) +{ + return MOD_SUCCESS; +} + +/** This ban that affects messages/notices only */ +int extban_quiet_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type) +{ + char *sub_ban; + + if (type != BANCHK_MSG) + return 0; + + sub_ban = banin + 3; + + return ban_check_mask(sptr, chptr, sub_ban, type, 0); +} diff --git a/src/modules/extbans/realname.c b/src/modules/extbans/realname.c new file mode 100644 index 000000000..d3beb2161 --- /dev/null +++ b/src/modules/extbans/realname.c @@ -0,0 +1,94 @@ +/* + * Extended ban to ban based on real name / gecos field (+b ~r) + * (C) Copyright 2003-.. Bram Matthys (Syzop) and the UnrealIRCd team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +#include "unrealircd.h" + +ModuleHeader MOD_HEADER(realname) += { + "chanmodes/extbans/realname", + "$Id$", + "ExtBan ~r - Ban based on realname/gecos field", + "3.2-b8-1", + NULL +}; + +/* Forward declarations */ +char *extban_realname_conv_param(char *para); +int extban_realname_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type); + +/** Called upon module init */ +DLLFUNC int MOD_INIT(realname)(ModuleInfo *modinfo) +{ + ExtbanInfo req; + + req.flag = 'r'; + req.is_ok = NULL; + req.conv_param = extban_realname_conv_param; + req.is_banned = extban_realname_is_banned; + req.options = EXTBOPT_CHSVSMODE|EXTBOPT_INVEX; + if (!ExtbanAdd(modinfo->handle, req)) + { + config_error("could not register extended ban type"); + return MOD_FAILED; + } + + MARK_AS_OFFICIAL_MODULE(modinfo); + + return MOD_SUCCESS; +} + +/** Called upon module load */ +DLLFUNC int MOD_LOAD(realname)(int module_load) +{ + return MOD_SUCCESS; +} + +/** Called upon unload */ +DLLFUNC int MOD_UNLOAD(realname)(int module_unload) +{ + return MOD_SUCCESS; +} + +/** Realname bans - conv_param */ +char *extban_realname_conv_param(char *para) +{ + static char retbuf[REALLEN + 8]; + char *mask; + + strlcpy(retbuf, para, sizeof(retbuf)); + + mask = retbuf+3; + + if (strlen(mask) > REALLEN + 3) + mask[REALLEN + 3] = '\0'; + + if (*mask == '~') + *mask = '?'; /* Is this good? No ;) */ + + return retbuf; +} + +int extban_realname_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type) +{ + char *ban = banin+3; + + if (!match_esc(ban, sptr->info)) + return 1; + + return 0; +} diff --git a/src/modules/extbans/regnick.c b/src/modules/extbans/regnick.c new file mode 100644 index 000000000..ceb395a7f --- /dev/null +++ b/src/modules/extbans/regnick.c @@ -0,0 +1,88 @@ +/* + * Extended ban type: ban (or exempt or invex) registered nick (~b ~R:xyz) + * (C) Copyright 2003-.. Bram Matthys (Syzop) and the UnrealIRCd team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +#include "unrealircd.h" + +ModuleHeader MOD_HEADER(regnick) += { + "chanmodes/extbans/regnick", + "$Id$", + "ExtBan ~R - Ban/exempt specific nick, but only if registered", + "3.2-b8-1", + NULL +}; + +/* Forward declarations */ +char *extban_regnick_conv_param(char *para); +int extban_regnick_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type); + +/** Called upon module init */ +DLLFUNC int MOD_INIT(regnick)(ModuleInfo *modinfo) +{ + ExtbanInfo req; + + req.flag = 'R'; + req.is_ok = NULL; + req.conv_param = extban_regnick_conv_param; + req.is_banned = extban_regnick_is_banned; + req.options = EXTBOPT_INVEX; + if (!ExtbanAdd(modinfo->handle, req)) + { + config_error("could not register extended ban type"); + return MOD_FAILED; + } + + MARK_AS_OFFICIAL_MODULE(modinfo); + + return MOD_SUCCESS; +} + +/** Called upon module load */ +DLLFUNC int MOD_LOAD(regnick)(int module_load) +{ + return MOD_SUCCESS; +} + +/** Called upon unload */ +DLLFUNC int MOD_UNLOAD(regnick)(int module_unload) +{ + return MOD_SUCCESS; +} + +/** Registered user ban */ +char *extban_regnick_conv_param(char *para) +{ + static char retbuf[NICKLEN + 4]; + + strlcpy(retbuf, para, sizeof(retbuf)); + + if (do_nick_name(retbuf+3) == 0) + return NULL; + + return retbuf; +} + +int extban_regnick_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type) +{ + char *ban = banin+3; + + if (IsRegNick(sptr) && !strcasecmp(ban, sptr->name)) + return 1; + + return 0; +}