unrealircd

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

account.c (2931B)

      1 /*
      2  * Extended ban to ban/exempt by services account (~b ~a:accountname)
      3  * (C) Copyright 2011-.. 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/account",
     24 	"4.2",
     25 	"ExtBan ~a - Ban/exempt by services account name",
     26 	"UnrealIRCd Team",
     27 	"unrealircd-6",
     28 };
     29 
     30 /* Forward declarations */
     31 const char *extban_account_conv_param(BanContext *b, Extban *extban);
     32 int extban_account_is_banned(BanContext *b);
     33 
     34 Extban *register_account_extban(ModuleInfo *modinfo)
     35 {
     36 	ExtbanInfo req;
     37 
     38 	memset(&req, 0, sizeof(req));
     39 	req.letter = 'a';
     40 	req.name = "account";
     41 	req.is_ok = NULL;
     42 	req.conv_param = extban_account_conv_param;
     43 	req.is_banned = extban_account_is_banned;
     44 	req.is_banned_events = BANCHK_ALL|BANCHK_TKL;
     45 	req.options = EXTBOPT_INVEX|EXTBOPT_TKL;
     46 	return ExtbanAdd(modinfo->handle, req);
     47 }
     48 
     49 /** Called upon module test */
     50 MOD_TEST()
     51 {
     52 	if (!register_account_extban(modinfo))
     53 	{
     54 		config_error("could not register extended ban type");
     55 		return MOD_FAILED;
     56 	}
     57 	return MOD_SUCCESS;
     58 }
     59 
     60 /** Called upon module init */
     61 MOD_INIT()
     62 {
     63 	if (!register_account_extban(modinfo))
     64 	{
     65 		config_error("could not register extended ban type");
     66 		return MOD_FAILED;
     67 	}
     68 
     69 	ISupportAdd(modinfo->handle, "ACCOUNTEXTBAN", "account,a");
     70 
     71 	MARK_AS_OFFICIAL_MODULE(modinfo);
     72 	return MOD_SUCCESS;
     73 }
     74 
     75 /** Called upon module load */
     76 MOD_LOAD()
     77 {
     78 	return MOD_SUCCESS;
     79 }
     80 
     81 /** Called upon unload */
     82 MOD_UNLOAD()
     83 {
     84 	return MOD_SUCCESS;
     85 }
     86 
     87 /** Account bans */
     88 const char *extban_account_conv_param(BanContext *b, Extban *extban)
     89 {
     90 	char *mask, *acc;
     91 	static char retbuf[NICKLEN + 4];
     92 
     93 	strlcpy(retbuf, b->banstr, sizeof(retbuf)); /* truncate */
     94 
     95 	acc = retbuf;
     96 	if (!*acc)
     97 		return NULL; /* don't allow "~a:" */
     98 
     99 	return retbuf;
    100 }
    101 
    102 int extban_account_is_banned(BanContext *b)
    103 {
    104 	/* ~a:0 is special and matches all unauthenticated users */
    105 	if (!strcmp(b->banstr, "0"))
    106 		return IsLoggedIn(b->client) ? 0 : 1;
    107 
    108 	/* ~a:* matches all authenticated users
    109 	 * (Yes this special code is needed because account
    110 	 *  is 0 or * for unauthenticated users)
    111 	 */
    112 	if (!strcmp(b->banstr, "*"))
    113 		return IsLoggedIn(b->client) ? 1 : 0;
    114 
    115 	if (b->client->user && match_simple(b->banstr, b->client->user->account))
    116 		return 1;
    117 
    118 	return 0;
    119 }