| 1 |
michael |
1058 |
/* |
| 2 |
michael |
2810 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
michael |
1058 |
* |
| 4 |
michael |
8280 |
* Copyright (c) 1997-2018 ircd-hybrid development team |
| 5 |
michael |
1058 |
* |
| 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 |
4564 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
michael |
1058 |
* USA |
| 20 |
|
|
*/ |
| 21 |
|
|
|
| 22 |
michael |
2810 |
/*! \file m_dline.c |
| 23 |
michael |
3348 |
* \brief Includes required functions for processing the DLINE command. |
| 24 |
michael |
2810 |
* \version $Id$ |
| 25 |
|
|
*/ |
| 26 |
|
|
|
| 27 |
michael |
1058 |
#include "stdinc.h" |
| 28 |
|
|
#include "list.h" |
| 29 |
|
|
#include "client.h" |
| 30 |
|
|
#include "irc_string.h" |
| 31 |
michael |
1632 |
#include "conf.h" |
| 32 |
michael |
7208 |
#include "conf_cluster.h" |
| 33 |
|
|
#include "conf_shared.h" |
| 34 |
michael |
1058 |
#include "ircd.h" |
| 35 |
|
|
#include "hostmask.h" |
| 36 |
|
|
#include "numeric.h" |
| 37 |
michael |
1309 |
#include "log.h" |
| 38 |
michael |
3347 |
#include "misc.h" |
| 39 |
michael |
1058 |
#include "send.h" |
| 40 |
michael |
8165 |
#include "server_capab.h" |
| 41 |
michael |
1058 |
#include "parse.h" |
| 42 |
|
|
#include "modules.h" |
| 43 |
michael |
1666 |
#include "memory.h" |
| 44 |
michael |
1058 |
|
| 45 |
|
|
|
| 46 |
michael |
3930 |
static void |
| 47 |
michael |
7434 |
dline_check(const struct AddressRec *arec) |
| 48 |
michael |
3930 |
{ |
| 49 |
michael |
8058 |
dlink_node *node, *node_next; |
| 50 |
michael |
3930 |
|
| 51 |
michael |
4816 |
DLINK_FOREACH_SAFE(node, node_next, local_client_list.head) |
| 52 |
michael |
3930 |
{ |
| 53 |
michael |
4816 |
struct Client *client_p = node->data; |
| 54 |
michael |
3930 |
|
| 55 |
|
|
if (IsDead(client_p)) |
| 56 |
|
|
continue; |
| 57 |
|
|
|
| 58 |
|
|
switch (arec->masktype) |
| 59 |
|
|
{ |
| 60 |
|
|
case HM_IPV4: |
| 61 |
michael |
8499 |
if (client_p->ip.ss.ss_family == AF_INET) |
| 62 |
michael |
8495 |
if (match_ipv4(&client_p->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits)) |
| 63 |
michael |
7303 |
conf_try_ban(client_p, CLIENT_BAN_DLINE, arec->conf->reason); |
| 64 |
michael |
3930 |
break; |
| 65 |
|
|
case HM_IPV6: |
| 66 |
michael |
8499 |
if (client_p->ip.ss.ss_family == AF_INET6) |
| 67 |
michael |
8495 |
if (match_ipv6(&client_p->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits)) |
| 68 |
michael |
7303 |
conf_try_ban(client_p, CLIENT_BAN_DLINE, arec->conf->reason); |
| 69 |
michael |
3930 |
break; |
| 70 |
|
|
default: break; |
| 71 |
|
|
} |
| 72 |
|
|
} |
| 73 |
|
|
|
| 74 |
michael |
4816 |
DLINK_FOREACH_SAFE(node, node_next, unknown_list.head) |
| 75 |
michael |
3930 |
{ |
| 76 |
michael |
4816 |
struct Client *client_p = node->data; |
| 77 |
michael |
3930 |
|
| 78 |
|
|
if (IsDead(client_p)) |
| 79 |
|
|
continue; |
| 80 |
|
|
|
| 81 |
|
|
switch (arec->masktype) |
| 82 |
|
|
{ |
| 83 |
|
|
case HM_IPV4: |
| 84 |
michael |
8499 |
if (client_p->ip.ss.ss_family == AF_INET) |
| 85 |
michael |
8495 |
if (match_ipv4(&client_p->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits)) |
| 86 |
michael |
7303 |
conf_try_ban(client_p, CLIENT_BAN_DLINE, arec->conf->reason); |
| 87 |
michael |
3930 |
break; |
| 88 |
|
|
case HM_IPV6: |
| 89 |
michael |
8499 |
if (client_p->ip.ss.ss_family == AF_INET6) |
| 90 |
michael |
8495 |
if (match_ipv6(&client_p->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits)) |
| 91 |
michael |
7303 |
conf_try_ban(client_p, CLIENT_BAN_DLINE, arec->conf->reason); |
| 92 |
michael |
3930 |
break; |
| 93 |
|
|
default: break; |
| 94 |
|
|
} |
| 95 |
|
|
} |
| 96 |
|
|
} |
| 97 |
|
|
|
| 98 |
michael |
5830 |
/* dline_add() |
| 99 |
michael |
1058 |
* |
| 100 |
|
|
* inputs - |
| 101 |
|
|
* output - NONE |
| 102 |
michael |
5830 |
* side effects - dline as given is placed |
| 103 |
michael |
1058 |
*/ |
| 104 |
|
|
static void |
| 105 |
michael |
8669 |
dline_handle(struct Client *source_p, struct aline_ctx *aline) |
| 106 |
michael |
1058 |
{ |
| 107 |
michael |
5830 |
char buf[IRCD_BUFSIZE]; |
| 108 |
michael |
8669 |
struct irc_ssaddr addr; |
| 109 |
michael |
7418 |
int bits = 0, aftype = 0; |
| 110 |
michael |
5830 |
|
| 111 |
michael |
8669 |
if (!HasFlag(source_p, FLAGS_SERVICE) && valid_wild_card(1, aline->host) == false) |
| 112 |
michael |
7428 |
{ |
| 113 |
|
|
sendto_one_notice(source_p, &me, |
| 114 |
|
|
":Please include at least %u non-wildcard characters with the mask", |
| 115 |
|
|
ConfigGeneral.min_nonwildcard); |
| 116 |
|
|
return; |
| 117 |
|
|
} |
| 118 |
|
|
|
| 119 |
michael |
8669 |
switch (parse_netmask(aline->host, &addr, &bits)) |
| 120 |
michael |
7418 |
{ |
| 121 |
|
|
case HM_IPV4: |
| 122 |
|
|
if (!HasFlag(source_p, FLAGS_SERVICE) && (unsigned int)bits < ConfigGeneral.dline_min_cidr) |
| 123 |
|
|
{ |
| 124 |
|
|
if (IsClient(source_p)) |
| 125 |
|
|
sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.", |
| 126 |
|
|
ConfigGeneral.dline_min_cidr); |
| 127 |
|
|
return; |
| 128 |
|
|
} |
| 129 |
|
|
|
| 130 |
|
|
aftype = AF_INET; |
| 131 |
|
|
break; |
| 132 |
|
|
case HM_IPV6: |
| 133 |
|
|
if (!HasFlag(source_p, FLAGS_SERVICE) && (unsigned int)bits < ConfigGeneral.dline_min_cidr6) |
| 134 |
|
|
{ |
| 135 |
|
|
if (IsClient(source_p)) |
| 136 |
|
|
sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.", |
| 137 |
|
|
ConfigGeneral.dline_min_cidr6); |
| 138 |
|
|
return; |
| 139 |
|
|
} |
| 140 |
|
|
|
| 141 |
|
|
aftype = AF_INET6; |
| 142 |
|
|
break; |
| 143 |
|
|
default: /* HM_HOST */ |
| 144 |
|
|
return; |
| 145 |
|
|
} |
| 146 |
|
|
|
| 147 |
michael |
8430 |
struct MaskItem *conf; |
| 148 |
michael |
8669 |
if ((conf = find_conf_by_address(NULL, &addr, CONF_DLINE, aftype, NULL, NULL, 1))) |
| 149 |
michael |
7418 |
{ |
| 150 |
|
|
if (IsClient(source_p)) |
| 151 |
|
|
sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s", |
| 152 |
michael |
8669 |
aline->host, conf->host, conf->reason); |
| 153 |
michael |
7418 |
return; |
| 154 |
|
|
} |
| 155 |
|
|
|
| 156 |
michael |
8669 |
if (aline->duration) |
| 157 |
michael |
6781 |
snprintf(buf, sizeof(buf), "Temporary D-line %ju min. - %.*s (%s)", |
| 158 |
michael |
8669 |
aline->duration / 60, REASONLEN, aline->reason, date_iso8601(0)); |
| 159 |
michael |
5830 |
else |
| 160 |
michael |
8669 |
snprintf(buf, sizeof(buf), "%.*s (%s)", REASONLEN, aline->reason, date_iso8601(0)); |
| 161 |
michael |
5830 |
|
| 162 |
michael |
7418 |
conf = conf_make(CONF_DLINE); |
| 163 |
michael |
8669 |
conf->host = xstrdup(aline->host); |
| 164 |
michael |
5830 |
conf->reason = xstrdup(buf); |
| 165 |
|
|
conf->setat = CurrentTime; |
| 166 |
|
|
SetConfDatabase(conf); |
| 167 |
|
|
|
| 168 |
michael |
8669 |
if (aline->duration) |
| 169 |
michael |
1622 |
{ |
| 170 |
michael |
8669 |
conf->until = CurrentTime + aline->duration; |
| 171 |
michael |
4640 |
|
| 172 |
|
|
if (IsClient(source_p)) |
| 173 |
michael |
6781 |
sendto_one_notice(source_p, &me, ":Added temporary %ju min. D-Line [%s]", |
| 174 |
michael |
8669 |
aline->duration / 60, conf->host); |
| 175 |
michael |
4889 |
|
| 176 |
michael |
6317 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
| 177 |
michael |
6781 |
"%s added temporary %ju min. D-Line for [%s] [%s]", |
| 178 |
michael |
8669 |
get_oper_name(source_p), aline->duration / 60, |
| 179 |
michael |
1632 |
conf->host, conf->reason); |
| 180 |
michael |
6781 |
ilog(LOG_TYPE_DLINE, "%s added temporary %ju min. D-Line for [%s] [%s]", |
| 181 |
michael |
8669 |
get_oper_name(source_p), aline->duration / 60, conf->host, conf->reason); |
| 182 |
michael |
1622 |
} |
| 183 |
|
|
else |
| 184 |
|
|
{ |
| 185 |
michael |
4640 |
if (IsClient(source_p)) |
| 186 |
|
|
sendto_one_notice(source_p, &me, ":Added D-Line [%s]", conf->host); |
| 187 |
|
|
|
| 188 |
michael |
6317 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
| 189 |
michael |
1622 |
"%s added D-Line for [%s] [%s]", |
| 190 |
michael |
1632 |
get_oper_name(source_p), conf->host, conf->reason); |
| 191 |
michael |
1622 |
ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]", |
| 192 |
michael |
1632 |
get_oper_name(source_p), conf->host, conf->reason); |
| 193 |
michael |
1622 |
} |
| 194 |
|
|
|
| 195 |
michael |
5831 |
dline_check(add_conf_by_address(CONF_DLINE, conf)); |
| 196 |
michael |
1058 |
} |
| 197 |
|
|
|
| 198 |
|
|
/* mo_dline() |
| 199 |
|
|
* |
| 200 |
|
|
* inputs - pointer to server |
| 201 |
|
|
* - pointer to client |
| 202 |
|
|
* - parameter count |
| 203 |
|
|
* - parameter list |
| 204 |
|
|
* output - |
| 205 |
|
|
* side effects - D line is added |
| 206 |
|
|
* |
| 207 |
|
|
*/ |
| 208 |
michael |
2820 |
static int |
| 209 |
michael |
3156 |
mo_dline(struct Client *source_p, int parc, char *parv[]) |
| 210 |
michael |
1058 |
{ |
| 211 |
michael |
8669 |
struct aline_ctx aline = { .add = true, .requires_user = false }; |
| 212 |
michael |
1058 |
const struct Client *target_p = NULL; |
| 213 |
michael |
7418 |
int t = 0; |
| 214 |
michael |
1398 |
char hostip[HOSTIPLEN + 1]; |
| 215 |
michael |
1058 |
|
| 216 |
michael |
1301 |
if (!HasOFlag(source_p, OPER_FLAG_DLINE)) |
| 217 |
michael |
1058 |
{ |
| 218 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "dline"); |
| 219 |
michael |
2820 |
return 0; |
| 220 |
michael |
1058 |
} |
| 221 |
|
|
|
| 222 |
michael |
8669 |
if (parse_aline("DLINE", source_p, parc, parv, &aline) == false) |
| 223 |
michael |
2820 |
return 0; |
| 224 |
michael |
1058 |
|
| 225 |
michael |
8669 |
if (aline.server) |
| 226 |
michael |
1301 |
{ |
| 227 |
michael |
8669 |
sendto_match_servs(source_p, aline.server, CAPAB_DLN, "DLINE %s %ju %s :%s", |
| 228 |
|
|
aline.server, aline.duration, aline.host, aline.reason); |
| 229 |
michael |
1301 |
|
| 230 |
michael |
6431 |
/* Allow ON to apply local dline as well if it matches */ |
| 231 |
michael |
8669 |
if (match(aline.server, me.name)) |
| 232 |
michael |
2820 |
return 0; |
| 233 |
michael |
1301 |
} |
| 234 |
|
|
else |
| 235 |
michael |
7208 |
cluster_distribute(source_p, "DLINE", CAPAB_DLN, CLUSTER_DLINE, |
| 236 |
michael |
8669 |
"%ju %s :%s", aline.duration, aline.host, aline.reason); |
| 237 |
michael |
1301 |
|
| 238 |
michael |
8669 |
if ((t = parse_netmask(aline.host, NULL, NULL)) == HM_HOST) |
| 239 |
michael |
1058 |
{ |
| 240 |
michael |
8669 |
if ((target_p = find_chasing(source_p, aline.host)) == NULL) |
| 241 |
michael |
3736 |
return 0; /* find_chasing sends ERR_NOSUCHNICK */ |
| 242 |
michael |
1058 |
|
| 243 |
|
|
if (!MyConnect(target_p)) |
| 244 |
|
|
{ |
| 245 |
michael |
3118 |
sendto_one_notice(source_p, &me, ":Cannot DLINE nick on another server"); |
| 246 |
michael |
2820 |
return 0; |
| 247 |
michael |
1058 |
} |
| 248 |
|
|
|
| 249 |
michael |
6314 |
if (HasFlag(target_p, FLAGS_EXEMPTKLINE)) |
| 250 |
michael |
1058 |
{ |
| 251 |
michael |
4935 |
sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name); |
| 252 |
michael |
2820 |
return 0; |
| 253 |
michael |
1058 |
} |
| 254 |
|
|
|
| 255 |
michael |
8495 |
getnameinfo((const struct sockaddr *)&target_p->ip, target_p->ip.ss_len, |
| 256 |
|
|
hostip, sizeof(hostip), NULL, 0, NI_NUMERICHOST); |
| 257 |
michael |
8669 |
aline.host = hostip; |
| 258 |
michael |
1058 |
} |
| 259 |
|
|
|
| 260 |
michael |
8669 |
dline_handle(source_p, &aline); |
| 261 |
michael |
2820 |
return 0; |
| 262 |
michael |
1058 |
} |
| 263 |
|
|
|
| 264 |
michael |
7093 |
/*! \brief DLINE command handler |
| 265 |
|
|
* |
| 266 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
| 267 |
|
|
* originally comes from. This can be a local or remote client. |
| 268 |
|
|
* \param parc Integer holding the number of supplied arguments. |
| 269 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 270 |
|
|
* pointers. |
| 271 |
|
|
* \note Valid arguments for this command are: |
| 272 |
|
|
* - parv[0] = command |
| 273 |
|
|
* - parv[1] = target server mask |
| 274 |
|
|
* - parv[2] = duration in seconds |
| 275 |
|
|
* - parv[3] = IP address |
| 276 |
|
|
* - parv[4] = reason |
| 277 |
|
|
*/ |
| 278 |
michael |
2820 |
static int |
| 279 |
michael |
3156 |
ms_dline(struct Client *source_p, int parc, char *parv[]) |
| 280 |
michael |
1301 |
{ |
| 281 |
michael |
8669 |
struct aline_ctx aline = |
| 282 |
|
|
{ |
| 283 |
|
|
.add = true, |
| 284 |
|
|
.requires_user = false, |
| 285 |
|
|
.host = parv[3], |
| 286 |
|
|
.reason = parv[4], |
| 287 |
|
|
.server = parv[1], |
| 288 |
|
|
.duration = strtoumax(parv[2], NULL, 10) |
| 289 |
|
|
}; |
| 290 |
michael |
1301 |
|
| 291 |
michael |
8669 |
if (parc != 5 || EmptyString(parv[parc - 1])) |
| 292 |
michael |
2820 |
return 0; |
| 293 |
michael |
1301 |
|
| 294 |
michael |
8669 |
sendto_match_servs(source_p, aline.server, CAPAB_DLN, "DLINE %s %ju %s :%s", |
| 295 |
|
|
aline.server, aline.duration, aline.host, aline.reason); |
| 296 |
michael |
1301 |
|
| 297 |
michael |
8669 |
if (match(aline.server, me.name)) |
| 298 |
michael |
2820 |
return 0; |
| 299 |
michael |
1301 |
|
| 300 |
michael |
2810 |
if (HasFlag(source_p, FLAGS_SERVICE) || |
| 301 |
michael |
7208 |
shared_find(SHARED_DLINE, source_p->servptr->name, |
| 302 |
|
|
source_p->username, source_p->host)) |
| 303 |
michael |
8669 |
dline_handle(source_p, &aline); |
| 304 |
michael |
5810 |
|
| 305 |
michael |
2820 |
return 0; |
| 306 |
michael |
1301 |
} |
| 307 |
|
|
|
| 308 |
michael |
2810 |
static struct Message dline_msgtab = |
| 309 |
|
|
{ |
| 310 |
michael |
5880 |
.cmd = "DLINE", |
| 311 |
|
|
.args_min = 2, |
| 312 |
|
|
.args_max = MAXPARA, |
| 313 |
|
|
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
| 314 |
|
|
.handlers[CLIENT_HANDLER] = m_not_oper, |
| 315 |
|
|
.handlers[SERVER_HANDLER] = ms_dline, |
| 316 |
|
|
.handlers[ENCAP_HANDLER] = m_ignore, |
| 317 |
|
|
.handlers[OPER_HANDLER] = mo_dline |
| 318 |
michael |
1230 |
}; |
| 319 |
|
|
|
| 320 |
|
|
static void |
| 321 |
|
|
module_init(void) |
| 322 |
|
|
{ |
| 323 |
|
|
mod_add_cmd(&dline_msgtab); |
| 324 |
michael |
8165 |
capab_add("DLN", CAPAB_DLN); |
| 325 |
michael |
1230 |
} |
| 326 |
|
|
|
| 327 |
|
|
static void |
| 328 |
|
|
module_exit(void) |
| 329 |
|
|
{ |
| 330 |
|
|
mod_del_cmd(&dline_msgtab); |
| 331 |
michael |
8165 |
capab_del("DLN"); |
| 332 |
michael |
1230 |
} |
| 333 |
|
|
|
| 334 |
michael |
2810 |
struct module module_entry = |
| 335 |
|
|
{ |
| 336 |
michael |
1230 |
.version = "$Revision$", |
| 337 |
|
|
.modinit = module_init, |
| 338 |
|
|
.modexit = module_exit, |
| 339 |
|
|
}; |