Skip to content

Commit

Permalink
Move all built-in extended bans to modules/extbans/...
Browse files Browse the repository at this point in the history
  • Loading branch information
syzop committed Jun 5, 2015
1 parent 0994c94 commit de59bf4
Show file tree
Hide file tree
Showing 15 changed files with 767 additions and 289 deletions.
3 changes: 2 additions & 1 deletion configure
Expand Up @@ -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
Expand Down Expand Up @@ -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" ;;
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Expand Up @@ -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])
Expand Down
2 changes: 0 additions & 2 deletions include/h.h
Expand Up @@ -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 *);
Expand Down
9 changes: 9 additions & 0 deletions modules.conf
Expand Up @@ -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 */
285 changes: 0 additions & 285 deletions src/extbans.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
*/
}
1 change: 0 additions & 1 deletion src/ircd.c
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/modules/Makefile.in
Expand Up @@ -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 \
Expand Down

0 comments on commit de59bf4

Please sign in to comment.