unrealircd- supernets unrealircd source & configuration |
git clone git://git.acid.vegas/unrealircd.git |
Log | Files | Refs | Archive | README | LICENSE |
realname.c (2637B)
1 /* 2 * Extended ban to ban based on real name / gecos field (+b ~r) 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/realname", 24 "4.2", 25 "ExtBan ~r - Ban based on realname/gecos field", 26 "UnrealIRCd Team", 27 "unrealircd-6", 28 }; 29 30 /* Forward declarations */ 31 const char *extban_realname_conv_param(BanContext *b, Extban *extban); 32 int extban_realname_is_banned(BanContext *b); 33 34 Extban *register_realname_extban(ModuleInfo *modinfo) 35 { 36 ExtbanInfo req; 37 38 memset(&req, 0, sizeof(req)); 39 req.letter = 'r'; 40 req.name = "realname"; 41 req.is_ok = NULL; 42 req.conv_param = extban_realname_conv_param; 43 req.is_banned = extban_realname_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_realname_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_realname_extban(modinfo)) 64 { 65 config_error("could not register extended ban type"); 66 return MOD_FAILED; 67 } 68 69 MARK_AS_OFFICIAL_MODULE(modinfo); 70 return MOD_SUCCESS; 71 } 72 73 /** Called upon module load */ 74 MOD_LOAD() 75 { 76 return MOD_SUCCESS; 77 } 78 79 /** Called upon unload */ 80 MOD_UNLOAD() 81 { 82 return MOD_SUCCESS; 83 } 84 85 /** Realname bans - conv_param */ 86 const char *extban_realname_conv_param(BanContext *b, Extban *extban) 87 { 88 static char retbuf[REALLEN + 8]; 89 char *mask; 90 91 strlcpy(retbuf, b->banstr, sizeof(retbuf)); 92 93 mask = retbuf; 94 95 if (!*mask) 96 return NULL; /* don't allow "~r:" */ 97 98 if (strlen(mask) > REALLEN) 99 mask[REALLEN] = '\0'; 100 101 /* Prevent otherwise confusing extban relationship */ 102 if (*mask == '~') 103 *mask = '?'; 104 105 return retbuf; 106 } 107 108 int extban_realname_is_banned(BanContext *b) 109 { 110 if (match_esc(b->banstr, b->client->info)) 111 return 1; 112 113 return 0; 114 }