From 8473cc1b1c9d8d2418cdd0e43fadb61e35c7ef98 Mon Sep 17 00:00:00 2001 From: Daniel Tan Date: Sat, 4 Jul 2015 00:39:52 +0800 Subject: [PATCH] [#4358]: Introduce certfp extban --- doc/conf/modules.default.conf | 1 + src/modules/extbans/Makefile.in | 6 +- src/modules/extbans/certfp.c | 123 ++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 src/modules/extbans/certfp.c diff --git a/doc/conf/modules.default.conf b/doc/conf/modules.default.conf index 742762611..7506e3bb7 100644 --- a/doc/conf/modules.default.conf +++ b/doc/conf/modules.default.conf @@ -183,6 +183,7 @@ loadmodule "extbans/regnick"; /* +b ~R (ban/exempt if using registered nick) */ loadmodule "extbans/account"; /* +b ~a (ban/exempt if logged in with services account) */ loadmodule "extbans/inchannel"; /* +b ~c (ban/exempt if in channel) */ loadmodule "extbans/operclass"; /* +b ~O (ban/exempt by operclass) */ +loadmodule "extbans/certfp"; /* +b ~S (ban/exempt by certfp) */ /*** Other ***/ diff --git a/src/modules/extbans/Makefile.in b/src/modules/extbans/Makefile.in index f9e72e8a6..d806c8e6b 100644 --- a/src/modules/extbans/Makefile.in +++ b/src/modules/extbans/Makefile.in @@ -31,7 +31,7 @@ INCLUDES = ../../include/auth.h ../../include/channel.h \ R_MODULES= \ join.so quiet.so nickchange.so inchannel.so realname.so regnick.so \ - account.so operclass.so + account.so operclass.so certfp.so MODULES=$(R_MODULES) MODULEFLAGS=@MODULEFLAGS@ @@ -88,3 +88,7 @@ account.so: account.c $(INCLUDES) operclass.so: operclass.c $(INCLUDES) $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ -o operclass.so operclass.c + +certfp.so: certfp.c $(INCLUDES) + $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ + -o certfp.so certfp.c diff --git a/src/modules/extbans/certfp.c b/src/modules/extbans/certfp.c new file mode 100644 index 000000000..7b30ac669 --- /dev/null +++ b/src/modules/extbans/certfp.c @@ -0,0 +1,123 @@ +/* + * Extended ban to ban/exempt by certfp (+b ~S:certfp) + * (C) Copyright 2015 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(certfp) += { + "extbans/certfp", + "$Id$", + "ExtBan ~S - Ban/exempt by certfp", + "3.2-b8-1", + NULL +}; + +/* Forward declarations */ +int extban_certfp_is_ok(aClient *sptr, aChannel *chptr, char *para, int checkt, int what, int what2); +char *extban_certfp_conv_param(char *para); +int extban_certfp_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type); + +/* Called upon module init */ +DLLFUNC int MOD_INIT(certfp)(ModuleInfo *modinfo) +{ + ExtbanInfo req; + + req.flag = 'S'; + req.is_ok = extban_certfp_is_ok; + req.conv_param = extban_certfp_conv_param; + req.is_banned = extban_certfp_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(certfp)(int module_load) +{ + return MOD_SUCCESS; +} + +/* Called upon unload */ +DLLFUNC int MOD_UNLOAD(account)(int module_unload) +{ + return MOD_SUCCESS; +} + +int extban_certfp_is_ok(aClient *sptr, aChannel *chptr, char *para, int checkt, int what, int what2) +{ + char *retbuf0; + retbuf0 = para+3; + if(checkt == EXCHK_PARAM) + { + if(BadPtr(retbuf0) || (strlen(retbuf0) != EVP_MAX_MD_SIZE)) + { + sendnotice(sptr, "Invalid certfp"); + return EX_DENY; + } + while(*retbuf0 != '\0') { + if(!isxdigit(*retbuf0)) + { + sendnotice(sptr, "Invalid certfp"); + return EX_DENY; + } + retbuf0++; + } + } + return EX_ALLOW; +} + +/* Obtain targeted certfp from the ban string */ +char *extban_certfp_conv_param(char *para) +{ + int c0unt3 = 0; + static char retbuf[EVP_MAX_MD_SIZE * 2 + 1]; + strlcpy(retbuf, para, sizeof(retbuf)); + while(c0unt3 < strlen(retbuf)) + { + if(c0unt3 > 2) + { + retbuf[c0unt3] = tolower(retbuf[c0unt3]); + } + c0unt3++; + } + + return retbuf; +} + +int extban_certfp_is_banned(aClient *sptr, aChannel *chptr, char *banin, int type) +{ + char *ban = banin+3; + char *fp; + + fp = moddata_client_get(sptr, "certfp"); + + if (!fp) + return 0; /* lolwut? */ + + if (!mycmp(ban, fp)) + return 1; + + return 0; +} \ No newline at end of file