unrealircd/src/modules/extbans/account.c

120 lines
2.9 KiB
C
Raw Normal View History

2020-03-29 02:16:53 -07:00
/*
* 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
= {
"extbans/account",
"4.2",
"ExtBan ~a - Ban/exempt by services account name",
"UnrealIRCd Team",
2022-01-14 21:16:34 -08:00
"unrealircd-6",
2020-03-29 02:16:53 -07:00
};
/* Forward declarations */
2022-01-14 21:16:34 -08:00
const char *extban_account_conv_param(BanContext *b, Extban *extban);
int extban_account_is_banned(BanContext *b);
2020-03-29 02:16:53 -07:00
2022-11-19 20:12:40 -08:00
Extban *register_account_extban(ModuleInfo *modinfo)
2020-03-29 02:16:53 -07:00
{
ExtbanInfo req;
2022-11-19 20:12:40 -08:00
2022-01-14 21:16:34 -08:00
memset(&req, 0, sizeof(req));
req.letter = 'a';
req.name = "account";
2020-03-29 02:16:53 -07:00
req.is_ok = NULL;
req.conv_param = extban_account_conv_param;
req.is_banned = extban_account_is_banned;
2022-01-14 21:16:34 -08:00
req.is_banned_events = BANCHK_ALL|BANCHK_TKL;
2020-03-29 02:16:53 -07:00
req.options = EXTBOPT_INVEX|EXTBOPT_TKL;
2022-11-19 20:12:40 -08:00
return ExtbanAdd(modinfo->handle, req);
}
/** Called upon module test */
MOD_TEST()
{
if (!register_account_extban(modinfo))
{
config_error("could not register extended ban type");
return MOD_FAILED;
}
return MOD_SUCCESS;
}
/** Called upon module init */
MOD_INIT()
{
if (!register_account_extban(modinfo))
2020-03-29 02:16:53 -07:00
{
config_error("could not register extended ban type");
return MOD_FAILED;
}
2023-05-05 15:12:01 -07:00
ISupportAdd(modinfo->handle, "ACCOUNTEXTBAN", "account,a");
2020-03-29 02:16:53 -07:00
MARK_AS_OFFICIAL_MODULE(modinfo);
return MOD_SUCCESS;
}
/** Called upon module load */
MOD_LOAD()
{
return MOD_SUCCESS;
}
/** Called upon unload */
MOD_UNLOAD()
{
return MOD_SUCCESS;
}
/** Account bans */
2022-01-14 21:16:34 -08:00
const char *extban_account_conv_param(BanContext *b, Extban *extban)
2020-03-29 02:16:53 -07:00
{
char *mask, *acc;
static char retbuf[NICKLEN + 4];
2022-01-14 21:16:34 -08:00
strlcpy(retbuf, b->banstr, sizeof(retbuf)); /* truncate */
2020-03-29 02:16:53 -07:00
2022-01-14 21:16:34 -08:00
acc = retbuf;
2020-03-29 02:16:53 -07:00
if (!*acc)
return NULL; /* don't allow "~a:" */
return retbuf;
}
2022-01-14 21:16:34 -08:00
int extban_account_is_banned(BanContext *b)
2020-03-29 02:16:53 -07:00
{
2022-01-14 21:16:34 -08:00
/* ~a:0 is special and matches all unauthenticated users */
2023-05-05 15:12:01 -07:00
if (!strcmp(b->banstr, "0"))
return IsLoggedIn(b->client) ? 0 : 1;
2022-01-14 21:16:34 -08:00
/* ~a:* matches all authenticated users
* (Yes this special code is needed because account
* is 0 or * for unauthenticated users)
*/
2023-05-05 15:12:01 -07:00
if (!strcmp(b->banstr, "*"))
return IsLoggedIn(b->client) ? 1 : 0;
2020-03-29 02:16:53 -07:00
2022-11-19 20:12:40 -08:00
if (b->client->user && match_simple(b->banstr, b->client->user->account))
2020-03-29 02:16:53 -07:00
return 1;
return 0;
}