From aa7553abe2a7058e6a3242f5f224cb5d552ad2c5 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Fri, 26 Jun 2015 16:08:50 +0200 Subject: [PATCH] new extban ~O:operclassname. Enables you to make a netadmin only channel like +iI ~O:netadmin* &remove old adminonly (+A) channel mode a bit more --- makefile.win32 | 3 - src/modules/chanmodes/Makefile.in | 6 +- src/modules/extbans/Makefile.in | 7 +- src/modules/extbans/operclass.c | 104 ++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 src/modules/extbans/operclass.c diff --git a/makefile.win32 b/makefile.win32 index 9d184624c..8eaab0f1b 100644 --- a/makefile.win32 +++ b/makefile.win32 @@ -807,9 +807,6 @@ src/modules/cap_invitenotify.dll: src/modules/cap_invitenotify.c $(INCLUDES) src/modules/ssl_antidos.dll: src/modules/ssl_antidos.c $(INCLUDES) $(CC) $(MODCFLAGS) src/modules/ssl_antidos.c $(MODLFLAGS) -src/modules/chanmodes/adminonly.dll: src/modules/chanmodes/adminonly.c $(INCLUDES) - $(CC) $(MODCFLAGS) /Fosrc/modules/chanmodes/ /Fesrc/modules/chanmodes/ src/modules/chanmodes/adminonly.c $(MODLFLAGS) - src/modules/chanmodes/censor.dll: src/modules/chanmodes/censor.c $(INCLUDES) $(CC) $(MODCFLAGS) /Fosrc/modules/chanmodes/ /Fesrc/modules/chanmodes/ src/modules/chanmodes/censor.c $(MODLFLAGS) diff --git a/src/modules/chanmodes/Makefile.in b/src/modules/chanmodes/Makefile.in index cd0cc6a41..f18aa67c2 100644 --- a/src/modules/chanmodes/Makefile.in +++ b/src/modules/chanmodes/Makefile.in @@ -32,7 +32,7 @@ INCLUDES = ../../include/auth.h ../../include/channel.h \ R_MODULES= \ nocolor.so stripcolor.so issecure.so permanent.so jointhrottle.so floodprot.so \ noctcp.so link.so censor.so delayjoin.so noknock.so noinvite.so operonly.so \ - adminonly.so nonotice.so regonly.so nonickchange.so nokick.so regonlyspeak.so \ + nonotice.so regonly.so nonickchange.so nokick.so regonlyspeak.so \ secureonly.so MODULES=$(R_MODULES) @@ -107,10 +107,6 @@ operonly.so: operonly.c $(INCLUDES) $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ -o operonly.so operonly.c -adminonly.so: adminonly.c $(INCLUDES) - $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ - -o adminonly.so adminonly.c - nonotice.so: nonotice.c $(INCLUDES) $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ -o nonotice.so nonotice.c diff --git a/src/modules/extbans/Makefile.in b/src/modules/extbans/Makefile.in index dc6b1aee1..f9e72e8a6 100644 --- a/src/modules/extbans/Makefile.in +++ b/src/modules/extbans/Makefile.in @@ -30,7 +30,8 @@ INCLUDES = ../../include/auth.h ../../include/channel.h \ ../../include/version.h ../../include/whowas.h R_MODULES= \ - join.so quiet.so nickchange.so inchannel.so realname.so regnick.so account.so + join.so quiet.so nickchange.so inchannel.so realname.so regnick.so \ + account.so operclass.so MODULES=$(R_MODULES) MODULEFLAGS=@MODULEFLAGS@ @@ -83,3 +84,7 @@ regnick.so: regnick.c $(INCLUDES) account.so: account.c $(INCLUDES) $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ -o account.so account.c + +operclass.so: operclass.c $(INCLUDES) + $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ + -o operclass.so operclass.c diff --git a/src/modules/extbans/operclass.c b/src/modules/extbans/operclass.c new file mode 100644 index 000000000..375e54e23 --- /dev/null +++ b/src/modules/extbans/operclass.c @@ -0,0 +1,104 @@ +/* + * Extended ban type: ban (or rather: exempt or invex) an operclass. + * (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(operclass) += { + "chanmodes/extbans/operclass", + "$Id$", + "ExtBan ~O - Ban/exempt operclass", + "3.2-b8-1", + NULL +}; + +/* Forward declarations */ +char *extban_operclass_conv_param(char *para); +int extban_operclass_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type); + +/** Called upon module init */ +DLLFUNC int MOD_INIT(operclass)(ModuleInfo *modinfo) +{ + ExtbanInfo req; + + req.flag = 'O'; + req.is_ok = NULL; + req.conv_param = extban_operclass_conv_param; + req.is_banned = extban_operclass_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(operclass)(int module_load) +{ + return MOD_SUCCESS; +} + +/** Called upon unload */ +DLLFUNC int MOD_UNLOAD(operclass)(int module_unload) +{ + return MOD_SUCCESS; +} + + +#define OPERCLASSLEN 64 + +char *extban_operclass_conv_param(char *para) +{ + static char retbuf[OPERCLASSLEN + 4]; + char *p; + + strlcpy(retbuf, para, sizeof(retbuf)); + + /* allow alpha, numeric, -, _, * and ? wildcards */ + for (p = retbuf+3; *p; p++) + if (!strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_?*", *p)) + *p = '\0'; + + if (retbuf[3] == '\0') + return NULL; /* just "~O:" is invalid */ + + return retbuf; +} + +int extban_operclass_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type) +{ + char *ban = banin+3; + + if (MyClient(sptr) && IsAnOper(sptr)) + { + char *operclass = NULL; + ConfigItem_oper *oper = Find_oper(sptr->user->operlogin); + if (oper && oper->operclass) + operclass = oper->operclass; + + if (operclass && !match(ban, operclass)) + return 1; + } + + return 0; +}