unrealircd

- supernets unrealircd source & configuration
git clone git://git.acid.vegas/unrealircd.git
Log | Files | Refs | Archive | README | LICENSE

operclass.c (2460B)

      1 /*
      2  * Extended ban type: ban (or rather: exempt or invex) an operclass.
      3  * (C) Copyright 2003-.. Bram Matthys (Syzop) and the UnrealIRCd team
      4  *
      5  * This program is free software; you can redistribute it and/or modify
      6  * it under the terms of the GNU General Public License as published by
      7  * the Free Software Foundation; either version 1, or (at your option)
      8  * any later version.
      9  *
     10  * This program is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  * GNU General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU General Public License
     16  * along with this program; if not, write to the Free Software
     17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     18  */
     19 #include "unrealircd.h"
     20 
     21 ModuleHeader MOD_HEADER
     22 = {
     23 	"extbans/operclass",
     24 	"4.2",
     25 	"ExtBan ~O - Ban/exempt operclass",
     26 	"UnrealIRCd Team",
     27 	"unrealircd-6",
     28 };
     29 
     30 /* Forward declarations */
     31 const char *extban_operclass_conv_param(BanContext *b, Extban *extban);
     32 int extban_operclass_is_banned(BanContext *b);
     33 
     34 /** Called upon module init */
     35 MOD_INIT()
     36 {
     37 	ExtbanInfo req;
     38 	
     39 	memset(&req, 0, sizeof(req));
     40 	req.letter = 'O';
     41 	req.name = "operclass";
     42 	req.is_ok = NULL;
     43 	req.conv_param = extban_operclass_conv_param;
     44 	req.is_banned = extban_operclass_is_banned;
     45 	req.is_banned_events = BANCHK_ALL;
     46 	req.options = EXTBOPT_INVEX;
     47 	if (!ExtbanAdd(modinfo->handle, req))
     48 	{
     49 		config_error("could not register extended ban type");
     50 		return MOD_FAILED;
     51 	}
     52 
     53 	MARK_AS_OFFICIAL_MODULE(modinfo);
     54 	
     55 	return MOD_SUCCESS;
     56 }
     57 
     58 /** Called upon module load */
     59 MOD_LOAD()
     60 {
     61 	return MOD_SUCCESS;
     62 }
     63 
     64 /** Called upon unload */
     65 MOD_UNLOAD()
     66 {
     67 	return MOD_SUCCESS;
     68 }
     69 
     70 
     71 #define OPERCLASSLEN 64
     72 
     73 const char *extban_operclass_conv_param(BanContext *b, Extban *extban)
     74 {
     75 	static char retbuf[OPERCLASSLEN + 4];
     76 	char *p;
     77 
     78 	strlcpy(retbuf, b->banstr, sizeof(retbuf));
     79 
     80 	/* allow alpha, numeric, -, _, * and ? wildcards */
     81 	for (p = retbuf; *p; p++)
     82 		if (!strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_?*", *p))
     83 			*p = '\0';
     84 
     85 	if (retbuf[3] == '\0')
     86 		return NULL; /* just "~O:" is invalid */
     87 
     88 	return retbuf;
     89 }
     90 
     91 int extban_operclass_is_banned(BanContext *b)
     92 {
     93 	if (MyUser(b->client) && IsOper(b->client))
     94 	{
     95 		const char *operclass = get_operclass(b->client);
     96 		if (operclass && match_simple(b->banstr, operclass))
     97 			return 1;
     98 	}
     99 
    100 	return 0;
    101 }