| 1 |
adx |
30 |
/* |
| 2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
adx |
30 |
* |
| 4 |
michael |
2820 |
* Copyright (c) 2003-2014 ircd-hybrid development team |
| 5 |
adx |
30 |
* |
| 6 |
|
|
* This program is free software; you can redistribute it and/or modify |
| 7 |
|
|
* it under the terms of the GNU General Public License as published by |
| 8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
|
|
* (at your option) any later version. |
| 10 |
|
|
* |
| 11 |
|
|
* This program is distributed in the hope that it will be useful, |
| 12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
|
|
* GNU General Public License for more details. |
| 15 |
|
|
* |
| 16 |
|
|
* You should have received a copy of the GNU General Public License |
| 17 |
|
|
* along with this program; if not, write to the Free Software |
| 18 |
michael |
4565 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
adx |
30 |
* USA |
| 20 |
|
|
*/ |
| 21 |
|
|
|
| 22 |
michael |
2820 |
/*! \file m_xline.c |
| 23 |
michael |
3352 |
* \brief Includes required functions for processing the XLINE command. |
| 24 |
michael |
2820 |
* \version $Id$ |
| 25 |
|
|
*/ |
| 26 |
|
|
|
| 27 |
adx |
30 |
#include "stdinc.h" |
| 28 |
michael |
1011 |
#include "list.h" |
| 29 |
adx |
30 |
#include "client.h" |
| 30 |
|
|
#include "irc_string.h" |
| 31 |
|
|
#include "ircd.h" |
| 32 |
michael |
1632 |
#include "conf.h" |
| 33 |
adx |
30 |
#include "numeric.h" |
| 34 |
michael |
1309 |
#include "log.h" |
| 35 |
adx |
30 |
#include "send.h" |
| 36 |
michael |
3347 |
#include "server.h" |
| 37 |
adx |
30 |
#include "parse.h" |
| 38 |
|
|
#include "modules.h" |
| 39 |
michael |
1622 |
#include "conf_db.h" |
| 40 |
michael |
1666 |
#include "memory.h" |
| 41 |
adx |
30 |
|
| 42 |
|
|
|
| 43 |
michael |
2877 |
static void |
| 44 |
|
|
check_xline(struct MaskItem *conf) |
| 45 |
|
|
{ |
| 46 |
|
|
dlink_node *ptr = NULL, *ptr_next = NULL; |
| 47 |
|
|
|
| 48 |
|
|
DLINK_FOREACH_SAFE(ptr, ptr_next, local_client_list.head) |
| 49 |
|
|
{ |
| 50 |
|
|
struct Client *client_p = ptr->data; |
| 51 |
|
|
|
| 52 |
|
|
if (IsDead(client_p)) |
| 53 |
|
|
continue; |
| 54 |
|
|
|
| 55 |
michael |
4242 |
if (!match(conf->name, client_p->info)) |
| 56 |
michael |
2877 |
conf_try_ban(client_p, conf); |
| 57 |
|
|
} |
| 58 |
|
|
} |
| 59 |
|
|
|
| 60 |
michael |
2974 |
/* valid_xline() |
| 61 |
|
|
* |
| 62 |
|
|
* inputs - client to complain to, gecos, reason, whether to complain |
| 63 |
|
|
* outputs - 1 for valid, else 0 |
| 64 |
|
|
* side effects - complains to client, when warn != 0 |
| 65 |
|
|
*/ |
| 66 |
|
|
static int |
| 67 |
michael |
4274 |
valid_xline(struct Client *source_p, const char *gecos, const char *reason) |
| 68 |
michael |
2974 |
{ |
| 69 |
|
|
if (EmptyString(reason)) |
| 70 |
|
|
{ |
| 71 |
michael |
4274 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "XLINE"); |
| 72 |
michael |
2974 |
return 0; |
| 73 |
|
|
} |
| 74 |
|
|
|
| 75 |
|
|
if (!valid_wild_card_simple(gecos)) |
| 76 |
|
|
{ |
| 77 |
michael |
4274 |
sendto_one_notice(source_p, &me, ":Please include at least %u non-wildcard characters with the xline", |
| 78 |
michael |
4340 |
ConfigGeneral.min_nonwildcard_simple); |
| 79 |
michael |
2974 |
return 0; |
| 80 |
|
|
} |
| 81 |
|
|
|
| 82 |
|
|
return 1; |
| 83 |
|
|
} |
| 84 |
|
|
|
| 85 |
|
|
/* write_xline() |
| 86 |
|
|
* |
| 87 |
|
|
* inputs - client taking credit for xline, gecos, reason, xline type |
| 88 |
|
|
* outputs - none |
| 89 |
|
|
* side effects - when successful, adds an xline to the conf |
| 90 |
|
|
*/ |
| 91 |
|
|
static void |
| 92 |
|
|
write_xline(struct Client *source_p, char *gecos, char *reason, |
| 93 |
|
|
time_t tkline_time) |
| 94 |
|
|
{ |
| 95 |
|
|
struct MaskItem *conf = conf_make(CONF_XLINE); |
| 96 |
|
|
|
| 97 |
|
|
conf->name = xstrdup(gecos); |
| 98 |
|
|
conf->reason = xstrdup(reason); |
| 99 |
|
|
conf->setat = CurrentTime; |
| 100 |
|
|
|
| 101 |
|
|
SetConfDatabase(conf); |
| 102 |
|
|
|
| 103 |
michael |
3368 |
if (tkline_time) |
| 104 |
michael |
2974 |
{ |
| 105 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 106 |
|
|
"%s added temporary %d min. X-Line for [%s] [%s]", |
| 107 |
|
|
get_oper_name(source_p), (int)tkline_time/60, |
| 108 |
|
|
conf->name, conf->reason); |
| 109 |
michael |
3110 |
sendto_one_notice(source_p, &me, ":Added temporary %d min. X-Line [%s]", |
| 110 |
|
|
(int)tkline_time/60, conf->name); |
| 111 |
michael |
2974 |
ilog(LOG_TYPE_XLINE, "%s added temporary %d min. X-Line for [%s] [%s]", |
| 112 |
michael |
4629 |
get_oper_name(source_p), (int)tkline_time/60, conf->name, conf->reason); |
| 113 |
michael |
2974 |
conf->until = CurrentTime + tkline_time; |
| 114 |
|
|
} |
| 115 |
|
|
else |
| 116 |
|
|
{ |
| 117 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 118 |
|
|
"%s added X-Line for [%s] [%s]", |
| 119 |
|
|
get_oper_name(source_p), conf->name, |
| 120 |
|
|
conf->reason); |
| 121 |
michael |
3110 |
sendto_one_notice(source_p, &me, ":Added X-Line [%s] [%s]", |
| 122 |
|
|
conf->name, conf->reason); |
| 123 |
michael |
2974 |
ilog(LOG_TYPE_XLINE, "%s added X-Line for [%s] [%s]", |
| 124 |
|
|
get_oper_name(source_p), conf->name, conf->reason); |
| 125 |
|
|
} |
| 126 |
|
|
|
| 127 |
|
|
check_xline(conf); |
| 128 |
|
|
} |
| 129 |
|
|
|
| 130 |
|
|
static void |
| 131 |
|
|
relay_xline(struct Client *source_p, char *parv[]) |
| 132 |
|
|
{ |
| 133 |
|
|
struct MaskItem *conf = NULL; |
| 134 |
|
|
|
| 135 |
|
|
sendto_match_servs(source_p, parv[1], CAP_CLUSTER, |
| 136 |
|
|
"XLINE %s %s %s :%s", |
| 137 |
|
|
parv[1], parv[2], parv[3], parv[4]); |
| 138 |
|
|
|
| 139 |
|
|
if (match(parv[1], me.name)) |
| 140 |
|
|
return; |
| 141 |
|
|
|
| 142 |
|
|
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
| 143 |
|
|
source_p->username, source_p->host, |
| 144 |
|
|
SHARED_XLINE)) |
| 145 |
|
|
{ |
| 146 |
|
|
if ((conf = find_matching_name_conf(CONF_XLINE, parv[2], NULL, NULL, 0))) |
| 147 |
|
|
{ |
| 148 |
michael |
3110 |
sendto_one_notice(source_p, &me, ":[%s] already X-Lined by [%s] - %s", |
| 149 |
|
|
parv[2], conf->name, conf->reason); |
| 150 |
michael |
2974 |
return; |
| 151 |
|
|
} |
| 152 |
|
|
|
| 153 |
michael |
4625 |
write_xline(source_p, parv[2], parv[4], atoi(parv[3])); |
| 154 |
michael |
2974 |
} |
| 155 |
|
|
} |
| 156 |
|
|
|
| 157 |
adx |
30 |
/* mo_xline() |
| 158 |
|
|
* |
| 159 |
|
|
* inputs - pointer to server |
| 160 |
|
|
* - pointer to client |
| 161 |
|
|
* - parameter count |
| 162 |
|
|
* - parameter list |
| 163 |
|
|
* output - |
| 164 |
|
|
* side effects - x line is added |
| 165 |
|
|
* |
| 166 |
|
|
*/ |
| 167 |
michael |
2820 |
static int |
| 168 |
michael |
3156 |
mo_xline(struct Client *source_p, int parc, char *parv[]) |
| 169 |
adx |
30 |
{ |
| 170 |
|
|
char *reason = NULL; |
| 171 |
|
|
char *gecos = NULL; |
| 172 |
michael |
1632 |
struct MaskItem *conf = NULL; |
| 173 |
adx |
30 |
char *target_server = NULL; |
| 174 |
|
|
time_t tkline_time = 0; |
| 175 |
|
|
|
| 176 |
michael |
2852 |
if (!HasOFlag(source_p, OPER_FLAG_XLINE)) |
| 177 |
adx |
30 |
{ |
| 178 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "xline"); |
| 179 |
michael |
2820 |
return 0; |
| 180 |
adx |
30 |
} |
| 181 |
|
|
|
| 182 |
|
|
/* |
| 183 |
|
|
* XLINE <gecos> <time> ON <mask> :<reason> |
| 184 |
|
|
* XLINE <gecos> ON <mask> :<reason> |
| 185 |
|
|
*/ |
| 186 |
michael |
4274 |
if (parse_aline("XLINE", source_p, parc, parv, 0, &gecos, NULL, |
| 187 |
adx |
30 |
&tkline_time, &target_server, &reason) < 0) |
| 188 |
michael |
2820 |
return 0; |
| 189 |
adx |
30 |
|
| 190 |
michael |
3368 |
if (target_server) |
| 191 |
adx |
30 |
{ |
| 192 |
|
|
/* if a given expire time is given, ENCAP it */ |
| 193 |
michael |
3368 |
if (tkline_time) |
| 194 |
adx |
30 |
sendto_match_servs(source_p, target_server, CAP_ENCAP, |
| 195 |
michael |
2820 |
"ENCAP %s XLINE %d %s 0 :%s", |
| 196 |
|
|
target_server, (int)tkline_time, gecos, reason); |
| 197 |
adx |
30 |
else |
| 198 |
|
|
sendto_match_servs(source_p, target_server, CAP_CLUSTER, |
| 199 |
michael |
2820 |
"XLINE %s %s %d :%s", |
| 200 |
|
|
target_server, gecos, (int)tkline_time, reason); |
| 201 |
adx |
30 |
|
| 202 |
|
|
/* Allow ON to apply local xline as well if it matches */ |
| 203 |
michael |
1652 |
if (match(target_server, me.name)) |
| 204 |
michael |
2820 |
return 0; |
| 205 |
adx |
30 |
} |
| 206 |
michael |
2820 |
else |
| 207 |
adx |
30 |
{ |
| 208 |
michael |
3368 |
if (tkline_time) |
| 209 |
adx |
30 |
cluster_a_line(source_p, "ENCAP", CAP_ENCAP, SHARED_XLINE, |
| 210 |
michael |
2820 |
"XLINE %d %s 0 :%s", (int)tkline_time, gecos, reason); |
| 211 |
adx |
30 |
else |
| 212 |
|
|
cluster_a_line(source_p, "XLINE", CAP_KLN, SHARED_XLINE, |
| 213 |
michael |
2820 |
"%s 0 :%s", gecos, reason); |
| 214 |
adx |
30 |
} |
| 215 |
|
|
|
| 216 |
michael |
4274 |
if (!valid_xline(source_p, gecos, reason)) |
| 217 |
michael |
2820 |
return 0; |
| 218 |
adx |
30 |
|
| 219 |
michael |
2820 |
if ((conf = find_matching_name_conf(CONF_XLINE, gecos, NULL, NULL, 0))) |
| 220 |
adx |
30 |
{ |
| 221 |
michael |
3110 |
sendto_one_notice(source_p, &me, ":[%s] already X-Lined by [%s] - %s", |
| 222 |
|
|
gecos, conf->name, conf->reason); |
| 223 |
michael |
2820 |
return 0; |
| 224 |
adx |
30 |
} |
| 225 |
|
|
|
| 226 |
|
|
write_xline(source_p, gecos, reason, tkline_time); |
| 227 |
michael |
2820 |
return 0; |
| 228 |
adx |
30 |
} |
| 229 |
|
|
|
| 230 |
|
|
/* ms_xline() |
| 231 |
|
|
* |
| 232 |
|
|
* inputs - oper, target server, xline, {type}, reason |
| 233 |
|
|
* |
| 234 |
|
|
* outputs - none |
| 235 |
|
|
* side effects - propagates xline, applies it if we are a target |
| 236 |
|
|
*/ |
| 237 |
michael |
2820 |
static int |
| 238 |
michael |
3156 |
ms_xline(struct Client *source_p, int parc, char *parv[]) |
| 239 |
adx |
30 |
{ |
| 240 |
|
|
if (parc != 5 || EmptyString(parv[4])) |
| 241 |
michael |
2820 |
return 0; |
| 242 |
adx |
30 |
|
| 243 |
|
|
if (!IsClient(source_p)) |
| 244 |
michael |
2820 |
return 0; |
| 245 |
adx |
30 |
|
| 246 |
michael |
4274 |
if (!valid_xline(source_p, parv[2], parv[4])) |
| 247 |
michael |
2820 |
return 0; |
| 248 |
adx |
30 |
|
| 249 |
|
|
relay_xline(source_p, parv); |
| 250 |
michael |
2820 |
return 0; |
| 251 |
adx |
30 |
} |
| 252 |
|
|
|
| 253 |
|
|
/* me_xline() |
| 254 |
|
|
* |
| 255 |
|
|
* inputs - server |
| 256 |
|
|
* - client (oper) |
| 257 |
|
|
* - parc number of arguments |
| 258 |
|
|
* - parv list of arguments |
| 259 |
|
|
* via parv[] |
| 260 |
michael |
2828 |
* parv[1] = target server |
| 261 |
|
|
* parv[2] = xline |
| 262 |
|
|
* parv[3] = time |
| 263 |
|
|
* parv[4] = reason |
| 264 |
adx |
30 |
* |
| 265 |
|
|
* outputs - none |
| 266 |
michael |
2820 |
* side effects - |
| 267 |
adx |
30 |
*/ |
| 268 |
michael |
2820 |
static int |
| 269 |
michael |
3156 |
me_xline(struct Client *source_p, int parc, char *parv[]) |
| 270 |
adx |
30 |
{ |
| 271 |
|
|
if (!IsClient(source_p) || parc != 5) |
| 272 |
michael |
2820 |
return 0; |
| 273 |
adx |
30 |
|
| 274 |
|
|
relay_xline(source_p, parv); |
| 275 |
michael |
2820 |
return 0; |
| 276 |
adx |
30 |
} |
| 277 |
|
|
|
| 278 |
michael |
2820 |
static struct Message xline_msgtab = |
| 279 |
|
|
{ |
| 280 |
michael |
4545 |
"XLINE", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
| 281 |
michael |
1230 |
{ m_unregistered, m_not_oper, ms_xline, me_xline, mo_xline, m_ignore } |
| 282 |
|
|
}; |
| 283 |
|
|
|
| 284 |
|
|
static void |
| 285 |
|
|
module_init(void) |
| 286 |
|
|
{ |
| 287 |
|
|
mod_add_cmd(&xline_msgtab); |
| 288 |
|
|
} |
| 289 |
|
|
|
| 290 |
|
|
static void |
| 291 |
|
|
module_exit(void) |
| 292 |
|
|
{ |
| 293 |
|
|
mod_del_cmd(&xline_msgtab); |
| 294 |
|
|
} |
| 295 |
|
|
|
| 296 |
michael |
2820 |
struct module module_entry = |
| 297 |
|
|
{ |
| 298 |
michael |
1230 |
.node = { NULL, NULL, NULL }, |
| 299 |
|
|
.name = NULL, |
| 300 |
|
|
.version = "$Revision$", |
| 301 |
|
|
.handle = NULL, |
| 302 |
|
|
.modinit = module_init, |
| 303 |
|
|
.modexit = module_exit, |
| 304 |
|
|
.flags = 0 |
| 305 |
|
|
}; |