| 1 |
adx |
30 |
/* |
| 2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
|
|
* m_kline.c: Bans a user. |
| 4 |
|
|
* |
| 5 |
|
|
* Copyright (C) 2002 by the past and present ircd coders, and others. |
| 6 |
|
|
* |
| 7 |
|
|
* This program is free software; you can redistribute it and/or modify |
| 8 |
|
|
* it under the terms of the GNU General Public License as published by |
| 9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
|
|
* (at your option) any later version. |
| 11 |
|
|
* |
| 12 |
|
|
* This program is distributed in the hope that it will be useful, |
| 13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
|
|
* GNU General Public License for more details. |
| 16 |
|
|
* |
| 17 |
|
|
* You should have received a copy of the GNU General Public License |
| 18 |
|
|
* along with this program; if not, write to the Free Software |
| 19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 20 |
|
|
* USA |
| 21 |
|
|
* |
| 22 |
knight |
31 |
* $Id$ |
| 23 |
adx |
30 |
*/ |
| 24 |
|
|
|
| 25 |
|
|
#include "stdinc.h" |
| 26 |
|
|
#include "tools.h" |
| 27 |
|
|
#include "channel.h" |
| 28 |
|
|
#include "client.h" |
| 29 |
|
|
#include "common.h" |
| 30 |
|
|
#include "irc_string.h" |
| 31 |
|
|
#include "sprintf_irc.h" |
| 32 |
|
|
#include "ircd.h" |
| 33 |
|
|
#include "hostmask.h" |
| 34 |
|
|
#include "numeric.h" |
| 35 |
|
|
#include "list.h" |
| 36 |
|
|
#include "fdlist.h" |
| 37 |
|
|
#include "s_bsd.h" |
| 38 |
|
|
#include "s_conf.h" |
| 39 |
|
|
#include "s_log.h" |
| 40 |
|
|
#include "s_misc.h" |
| 41 |
|
|
#include "send.h" |
| 42 |
|
|
#include "hash.h" |
| 43 |
|
|
#include "handlers.h" |
| 44 |
|
|
#include "s_serv.h" |
| 45 |
|
|
#include "msg.h" |
| 46 |
|
|
#include "s_gline.h" |
| 47 |
|
|
#include "parse.h" |
| 48 |
|
|
#include "modules.h" |
| 49 |
|
|
#include "tools.h" |
| 50 |
michael |
611 |
#include "irc_getnameinfo.h" |
| 51 |
adx |
30 |
|
| 52 |
michael |
611 |
|
| 53 |
adx |
30 |
static void me_kline(struct Client *, struct Client *, int, char **); |
| 54 |
|
|
static void mo_kline(struct Client *, struct Client *, int, char **); |
| 55 |
|
|
static void ms_kline(struct Client *, struct Client *, int, char **); |
| 56 |
|
|
static void mo_dline(struct Client *, struct Client *, int, char **); |
| 57 |
|
|
static void me_unkline(struct Client *, struct Client *, int, char **); |
| 58 |
|
|
static void mo_unkline(struct Client *, struct Client *, int, char **); |
| 59 |
|
|
static void ms_unkline(struct Client *, struct Client *, int, char **); |
| 60 |
|
|
static void mo_undline(struct Client *, struct Client *, int, char **); |
| 61 |
|
|
|
| 62 |
|
|
static int remove_tkline_match(const char *, const char *); |
| 63 |
|
|
static int remove_tdline_match(const char *); |
| 64 |
|
|
|
| 65 |
|
|
struct Message kline_msgtab = { |
| 66 |
|
|
"KLINE", 0, 0, 2, 0, MFLG_SLOW, 0, |
| 67 |
|
|
{m_unregistered, m_not_oper, ms_kline, me_kline, mo_kline, m_ignore} |
| 68 |
|
|
}; |
| 69 |
|
|
|
| 70 |
|
|
struct Message dline_msgtab = { |
| 71 |
|
|
"DLINE", 0, 0, 2, 0, MFLG_SLOW, 0, |
| 72 |
|
|
{m_unregistered, m_not_oper, m_error, m_ignore, mo_dline, m_ignore} |
| 73 |
|
|
}; |
| 74 |
|
|
|
| 75 |
|
|
struct Message unkline_msgtab = { |
| 76 |
|
|
"UNKLINE", 0, 0, 2, 0, MFLG_SLOW, 0, |
| 77 |
|
|
{m_unregistered, m_not_oper, ms_unkline, me_unkline, mo_unkline, m_ignore} |
| 78 |
|
|
}; |
| 79 |
|
|
|
| 80 |
|
|
struct Message undline_msgtab = { |
| 81 |
|
|
"UNDLINE", 0, 0, 2, 0, MFLG_SLOW, 0, |
| 82 |
|
|
{m_unregistered, m_not_oper, m_error, m_ignore, mo_undline, m_ignore} |
| 83 |
|
|
}; |
| 84 |
|
|
|
| 85 |
|
|
#ifndef STATIC_MODULES |
| 86 |
|
|
void |
| 87 |
|
|
_modinit(void) |
| 88 |
|
|
{ |
| 89 |
|
|
mod_add_cmd(&kline_msgtab); |
| 90 |
|
|
mod_add_cmd(&unkline_msgtab); |
| 91 |
|
|
mod_add_cmd(&dline_msgtab); |
| 92 |
|
|
mod_add_cmd(&undline_msgtab); |
| 93 |
|
|
add_capability("KLN", CAP_KLN, 1); |
| 94 |
|
|
add_capability("UNKLN", CAP_UNKLN, 1); |
| 95 |
|
|
} |
| 96 |
|
|
|
| 97 |
|
|
void |
| 98 |
|
|
_moddeinit(void) |
| 99 |
|
|
{ |
| 100 |
|
|
mod_del_cmd(&kline_msgtab); |
| 101 |
|
|
mod_del_cmd(&unkline_msgtab); |
| 102 |
|
|
mod_del_cmd(&dline_msgtab); |
| 103 |
|
|
mod_del_cmd(&undline_msgtab); |
| 104 |
|
|
delete_capability("UNKLN"); |
| 105 |
|
|
delete_capability("KLN"); |
| 106 |
|
|
} |
| 107 |
|
|
|
| 108 |
knight |
31 |
const char *_version = "$Revision$"; |
| 109 |
adx |
30 |
#endif |
| 110 |
|
|
|
| 111 |
|
|
/* Local function prototypes */ |
| 112 |
|
|
static int already_placed_kline(struct Client *, const char *, const char *, int); |
| 113 |
|
|
static void apply_kline(struct Client *, struct ConfItem *, const char *, time_t); |
| 114 |
|
|
static void apply_tkline(struct Client *, struct ConfItem *, int); |
| 115 |
|
|
|
| 116 |
|
|
static char buffer[IRCD_BUFSIZE]; |
| 117 |
|
|
|
| 118 |
|
|
/* mo_kline() |
| 119 |
|
|
* |
| 120 |
|
|
* inputs - pointer to server |
| 121 |
|
|
* - pointer to client |
| 122 |
|
|
* - parameter count |
| 123 |
|
|
* - parameter list |
| 124 |
|
|
* output - |
| 125 |
|
|
* side effects - k line is added |
| 126 |
|
|
*/ |
| 127 |
|
|
static void |
| 128 |
|
|
mo_kline(struct Client *client_p, struct Client *source_p, |
| 129 |
|
|
int parc, char **parv) |
| 130 |
|
|
{ |
| 131 |
|
|
char *reason = NULL; |
| 132 |
|
|
char *oper_reason; |
| 133 |
|
|
char *user = NULL; |
| 134 |
|
|
char *host = NULL; |
| 135 |
|
|
const char *current_date; |
| 136 |
|
|
char *target_server = NULL; |
| 137 |
|
|
struct ConfItem *conf; |
| 138 |
|
|
struct AccessItem *aconf; |
| 139 |
|
|
time_t tkline_time = 0; |
| 140 |
|
|
time_t cur_time; |
| 141 |
|
|
|
| 142 |
|
|
if (!IsOperK(source_p)) |
| 143 |
|
|
{ |
| 144 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS), |
| 145 |
|
|
me.name, source_p->name, "kline"); |
| 146 |
|
|
return; |
| 147 |
|
|
} |
| 148 |
|
|
|
| 149 |
|
|
if (parse_aline("KLINE", source_p, parc, parv, |
| 150 |
|
|
AWILD, &user, &host, &tkline_time, &target_server, &reason) < 0) |
| 151 |
|
|
return; |
| 152 |
|
|
|
| 153 |
|
|
if (target_server != NULL) |
| 154 |
|
|
{ |
| 155 |
|
|
if (HasID(source_p)) |
| 156 |
|
|
{ |
| 157 |
michael |
885 |
sendto_server(NULL, NULL, CAP_KLN|CAP_TS6, NOCAPS, |
| 158 |
adx |
30 |
":%s KLINE %s %lu %s %s :%s", |
| 159 |
|
|
source_p->id, target_server, (unsigned long)tkline_time, |
| 160 |
|
|
user, host, reason); |
| 161 |
michael |
885 |
sendto_server(NULL, NULL, CAP_KLN, CAP_TS6, |
| 162 |
adx |
30 |
":%s KLINE %s %lu %s %s :%s", |
| 163 |
|
|
source_p->name, target_server, (unsigned long)tkline_time, |
| 164 |
|
|
user, host, reason); |
| 165 |
|
|
} |
| 166 |
|
|
else |
| 167 |
michael |
885 |
sendto_server(NULL, NULL, CAP_KLN, NOCAPS, |
| 168 |
adx |
30 |
":%s KLINE %s %lu %s %s :%s", |
| 169 |
|
|
source_p->name, target_server, (unsigned long)tkline_time, |
| 170 |
|
|
user, host, reason); |
| 171 |
|
|
|
| 172 |
|
|
/* Allow ON to apply local kline as well if it matches */ |
| 173 |
|
|
if (!match(target_server, me.name)) |
| 174 |
|
|
return; |
| 175 |
|
|
} |
| 176 |
|
|
else |
| 177 |
|
|
cluster_a_line(source_p, "KLINE", CAP_KLN, SHARED_KLINE, |
| 178 |
|
|
"%d %s %s :%s", tkline_time, user, host, reason); |
| 179 |
|
|
|
| 180 |
|
|
if (already_placed_kline(source_p, user, host, YES)) |
| 181 |
|
|
return; |
| 182 |
|
|
|
| 183 |
|
|
/* Look for an oper reason */ |
| 184 |
|
|
if ((oper_reason = strchr(reason, '|')) != NULL) |
| 185 |
|
|
*oper_reason++ = '\0'; |
| 186 |
|
|
|
| 187 |
|
|
cur_time = CurrentTime; |
| 188 |
|
|
current_date = smalldate(cur_time); |
| 189 |
|
|
conf = make_conf_item(KLINE_TYPE); |
| 190 |
|
|
aconf = map_to_conf(conf); |
| 191 |
|
|
|
| 192 |
|
|
DupString(aconf->host, host); |
| 193 |
|
|
DupString(aconf->user, user); |
| 194 |
|
|
|
| 195 |
|
|
if (tkline_time != 0) |
| 196 |
|
|
{ |
| 197 |
|
|
ircsprintf(buffer, "Temporary K-line %d min. - %s (%s)", |
| 198 |
|
|
(int)(tkline_time/60), reason, current_date); |
| 199 |
|
|
DupString(aconf->reason, buffer); |
| 200 |
|
|
|
| 201 |
|
|
if (oper_reason != NULL) |
| 202 |
|
|
DupString(aconf->oper_reason, oper_reason); |
| 203 |
|
|
apply_tkline(source_p, conf, tkline_time); |
| 204 |
|
|
} |
| 205 |
|
|
else |
| 206 |
|
|
{ |
| 207 |
|
|
ircsprintf(buffer, "%s (%s)", reason, current_date); |
| 208 |
|
|
DupString(aconf->reason, buffer); |
| 209 |
|
|
|
| 210 |
|
|
if (oper_reason != NULL) |
| 211 |
|
|
DupString(aconf->oper_reason, oper_reason); |
| 212 |
|
|
apply_kline(source_p, conf, current_date, cur_time); |
| 213 |
|
|
} |
| 214 |
|
|
} |
| 215 |
|
|
|
| 216 |
|
|
/* me_kline - handle remote kline. no propagation */ |
| 217 |
|
|
static void |
| 218 |
|
|
me_kline(struct Client *client_p, struct Client *source_p, |
| 219 |
|
|
int parc, char *parv[]) |
| 220 |
|
|
{ |
| 221 |
|
|
struct ConfItem *conf=NULL; |
| 222 |
|
|
struct AccessItem *aconf=NULL; |
| 223 |
|
|
int tkline_time; |
| 224 |
|
|
const char* current_date; |
| 225 |
|
|
time_t cur_time; |
| 226 |
|
|
char *kuser, *khost, *kreason, *oper_reason; |
| 227 |
|
|
|
| 228 |
michael |
352 |
if (parc != 6 || EmptyString(parv[5])) |
| 229 |
adx |
30 |
return; |
| 230 |
|
|
|
| 231 |
|
|
if (!match(parv[1], me.name)) |
| 232 |
|
|
return; |
| 233 |
|
|
|
| 234 |
|
|
tkline_time = valid_tkline(parv[2], TK_SECONDS); |
| 235 |
|
|
kuser = parv[3]; |
| 236 |
|
|
khost = parv[4]; |
| 237 |
|
|
kreason = parv[5]; |
| 238 |
|
|
|
| 239 |
|
|
if ((oper_reason = strchr(kreason, '|')) != NULL) |
| 240 |
|
|
*oper_reason++ = '\0'; |
| 241 |
|
|
|
| 242 |
|
|
cur_time = CurrentTime; |
| 243 |
|
|
current_date = smalldate(cur_time); |
| 244 |
|
|
|
| 245 |
|
|
if (find_matching_name_conf(ULINE_TYPE, source_p->servptr->name, |
| 246 |
|
|
source_p->username, source_p->host, |
| 247 |
|
|
SHARED_KLINE)) |
| 248 |
|
|
{ |
| 249 |
|
|
if (!IsClient(source_p) || |
| 250 |
|
|
already_placed_kline(source_p, kuser, khost, YES)) |
| 251 |
|
|
return; |
| 252 |
|
|
|
| 253 |
|
|
conf = make_conf_item(KLINE_TYPE); |
| 254 |
|
|
aconf = map_to_conf(conf); |
| 255 |
|
|
DupString(aconf->host, khost); |
| 256 |
|
|
DupString(aconf->user, kuser); |
| 257 |
|
|
|
| 258 |
|
|
if (tkline_time != 0) |
| 259 |
|
|
{ |
| 260 |
|
|
ircsprintf(buffer, "Temporary K-line %d min. - %s (%s)", |
| 261 |
|
|
(int)(tkline_time/60), kreason, current_date); |
| 262 |
|
|
DupString(aconf->reason, buffer); |
| 263 |
|
|
|
| 264 |
|
|
if (oper_reason != NULL) |
| 265 |
|
|
DupString(aconf->oper_reason, oper_reason); |
| 266 |
|
|
apply_tkline(source_p, conf, tkline_time); |
| 267 |
|
|
} |
| 268 |
|
|
else |
| 269 |
|
|
{ |
| 270 |
|
|
ircsprintf(buffer, "%s (%s)", kreason, current_date); |
| 271 |
|
|
DupString(aconf->reason, buffer); |
| 272 |
|
|
|
| 273 |
|
|
if (oper_reason != NULL) |
| 274 |
|
|
DupString(aconf->oper_reason, oper_reason); |
| 275 |
|
|
apply_kline(source_p, conf, current_date, cur_time); |
| 276 |
|
|
} |
| 277 |
|
|
} |
| 278 |
|
|
} |
| 279 |
|
|
|
| 280 |
|
|
static void |
| 281 |
|
|
ms_kline(struct Client *client_p, struct Client *source_p, |
| 282 |
|
|
int parc, char *parv[]) |
| 283 |
|
|
{ |
| 284 |
michael |
352 |
if (parc != 6 || EmptyString(parv[5])) |
| 285 |
adx |
30 |
return; |
| 286 |
|
|
|
| 287 |
|
|
/* parv[0] parv[1] parv[2] parv[3] parv[4] parv[5] */ |
| 288 |
|
|
/* oper target_server tkline_time user host reason */ |
| 289 |
|
|
sendto_match_servs(source_p, parv[1], CAP_KLN, |
| 290 |
|
|
"KLINE %s %s %s %s :%s", |
| 291 |
|
|
parv[1], parv[2], parv[3], parv[4], parv[5]); |
| 292 |
|
|
|
| 293 |
|
|
me_kline(client_p, source_p, parc, parv); |
| 294 |
|
|
} |
| 295 |
|
|
|
| 296 |
|
|
/* apply_kline() |
| 297 |
|
|
* |
| 298 |
|
|
* inputs - |
| 299 |
|
|
* output - NONE |
| 300 |
|
|
* side effects - kline as given, is added to the hashtable |
| 301 |
|
|
* and conf file |
| 302 |
|
|
*/ |
| 303 |
|
|
static void |
| 304 |
|
|
apply_kline(struct Client *source_p, struct ConfItem *conf, |
| 305 |
|
|
const char *current_date, time_t cur_time) |
| 306 |
|
|
{ |
| 307 |
|
|
struct AccessItem *aconf = map_to_conf(conf); |
| 308 |
|
|
|
| 309 |
|
|
add_conf_by_address(CONF_KILL, aconf); |
| 310 |
|
|
write_conf_line(source_p, conf, current_date, cur_time); |
| 311 |
|
|
/* Now, activate kline against current online clients */ |
| 312 |
|
|
rehashed_klines = 1; |
| 313 |
|
|
} |
| 314 |
|
|
|
| 315 |
|
|
/* apply_tkline() |
| 316 |
|
|
* |
| 317 |
|
|
* inputs - |
| 318 |
|
|
* output - NONE |
| 319 |
|
|
* side effects - tkline as given is placed |
| 320 |
|
|
*/ |
| 321 |
|
|
static void |
| 322 |
|
|
apply_tkline(struct Client *source_p, struct ConfItem *conf, |
| 323 |
|
|
int tkline_time) |
| 324 |
|
|
{ |
| 325 |
|
|
struct AccessItem *aconf; |
| 326 |
|
|
|
| 327 |
|
|
aconf = (struct AccessItem *)map_to_conf(conf); |
| 328 |
|
|
aconf->hold = CurrentTime + tkline_time; |
| 329 |
|
|
add_temp_line(conf); |
| 330 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 331 |
|
|
"%s added temporary %d min. K-Line for [%s@%s] [%s]", |
| 332 |
|
|
get_oper_name(source_p), tkline_time/60, |
| 333 |
|
|
aconf->user, aconf->host, |
| 334 |
|
|
aconf->reason); |
| 335 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. K-Line [%s@%s]", |
| 336 |
|
|
MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from), |
| 337 |
|
|
source_p->name, tkline_time/60, aconf->user, aconf->host); |
| 338 |
|
|
ilog(L_TRACE, "%s added temporary %d min. K-Line for [%s@%s] [%s]", |
| 339 |
|
|
source_p->name, tkline_time/60, |
| 340 |
|
|
aconf->user, aconf->host, aconf->reason); |
| 341 |
|
|
log_oper_action(LOG_TEMP_KLINE_TYPE, source_p, "[%s@%s] [%s]\n", |
| 342 |
|
|
aconf->user, aconf->host, aconf->reason); |
| 343 |
|
|
rehashed_klines = 1; |
| 344 |
|
|
} |
| 345 |
|
|
|
| 346 |
|
|
/* apply_tdline() |
| 347 |
|
|
* |
| 348 |
|
|
* inputs - |
| 349 |
|
|
* output - NONE |
| 350 |
|
|
* side effects - tkline as given is placed |
| 351 |
|
|
*/ |
| 352 |
|
|
static void |
| 353 |
|
|
apply_tdline(struct Client *source_p, struct ConfItem *conf, |
| 354 |
|
|
const char *current_date, int tkline_time) |
| 355 |
|
|
{ |
| 356 |
|
|
struct AccessItem *aconf; |
| 357 |
|
|
|
| 358 |
|
|
aconf = map_to_conf(conf); |
| 359 |
|
|
aconf->hold = CurrentTime + tkline_time; |
| 360 |
|
|
|
| 361 |
|
|
add_temp_line(conf); |
| 362 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 363 |
|
|
"%s added temporary %d min. D-Line for [%s] [%s]", |
| 364 |
|
|
get_oper_name(source_p), tkline_time/60, |
| 365 |
|
|
aconf->host, aconf->reason); |
| 366 |
|
|
|
| 367 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]", |
| 368 |
|
|
MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from), |
| 369 |
|
|
source_p->name, tkline_time/60, aconf->host); |
| 370 |
|
|
ilog(L_TRACE, "%s added temporary %d min. D-Line for [%s] [%s]", |
| 371 |
|
|
source_p->name, tkline_time/60, aconf->host, aconf->reason); |
| 372 |
|
|
log_oper_action(LOG_TEMP_DLINE_TYPE, source_p, "[%s@%s] [%s]\n", |
| 373 |
|
|
aconf->user, aconf->host, aconf->reason); |
| 374 |
|
|
rehashed_klines = 1; |
| 375 |
|
|
} |
| 376 |
|
|
|
| 377 |
|
|
/* mo_dline() |
| 378 |
|
|
* |
| 379 |
|
|
* inputs - pointer to server |
| 380 |
|
|
* - pointer to client |
| 381 |
|
|
* - parameter count |
| 382 |
|
|
* - parameter list |
| 383 |
|
|
* output - |
| 384 |
|
|
* side effects - D line is added |
| 385 |
|
|
* |
| 386 |
|
|
*/ |
| 387 |
|
|
static void |
| 388 |
|
|
mo_dline(struct Client *client_p, struct Client *source_p, |
| 389 |
|
|
int parc, char *parv[]) |
| 390 |
|
|
{ |
| 391 |
|
|
char def_reason[] = "No reason"; |
| 392 |
|
|
char *dlhost, *oper_reason, *reason; |
| 393 |
|
|
const char *creason; |
| 394 |
michael |
611 |
const struct Client *target_p = NULL; |
| 395 |
adx |
30 |
struct irc_ssaddr daddr; |
| 396 |
|
|
struct ConfItem *conf=NULL; |
| 397 |
|
|
struct AccessItem *aconf=NULL; |
| 398 |
|
|
time_t tkline_time=0; |
| 399 |
|
|
int bits, t; |
| 400 |
michael |
611 |
const char *current_date = NULL; |
| 401 |
adx |
30 |
time_t cur_time; |
| 402 |
michael |
611 |
char hostip[HOSTIPLEN]; |
| 403 |
adx |
30 |
|
| 404 |
|
|
if (!IsOperK(source_p)) |
| 405 |
|
|
{ |
| 406 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS), |
| 407 |
|
|
me.name, source_p->name, "kline"); |
| 408 |
|
|
return; |
| 409 |
|
|
} |
| 410 |
|
|
|
| 411 |
michael |
611 |
if (parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost, |
| 412 |
|
|
NULL, &tkline_time, NULL, &reason) < 0) |
| 413 |
adx |
30 |
return; |
| 414 |
|
|
|
| 415 |
|
|
if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST) |
| 416 |
|
|
{ |
| 417 |
michael |
611 |
if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL) |
| 418 |
|
|
return; |
| 419 |
adx |
30 |
|
| 420 |
michael |
611 |
if (!MyConnect(target_p)) |
| 421 |
|
|
{ |
| 422 |
|
|
sendto_one(source_p, |
| 423 |
|
|
":%s NOTICE %s :Can't DLINE nick on another server", |
| 424 |
|
|
me.name, source_p->name); |
| 425 |
|
|
return; |
| 426 |
|
|
} |
| 427 |
adx |
30 |
|
| 428 |
michael |
611 |
if (IsExemptKline(target_p)) |
| 429 |
|
|
{ |
| 430 |
|
|
sendto_one(source_p, |
| 431 |
|
|
":%s NOTICE %s :%s is E-lined", me.name, |
| 432 |
|
|
source_p->name, target_p->name); |
| 433 |
|
|
return; |
| 434 |
|
|
} |
| 435 |
adx |
30 |
|
| 436 |
michael |
611 |
irc_getnameinfo((struct sockaddr *)&target_p->localClient->ip, |
| 437 |
|
|
target_p->localClient->ip.ss_len, hostip, |
| 438 |
|
|
sizeof(hostip), NULL, 0, NI_NUMERICHOST); |
| 439 |
adx |
30 |
|
| 440 |
michael |
611 |
dlhost = hostip; |
| 441 |
|
|
t = parse_netmask(dlhost, NULL, &bits); |
| 442 |
|
|
assert(t == HM_IPV4 || t == HM_IPV6); |
| 443 |
|
|
} |
| 444 |
adx |
30 |
|
| 445 |
|
|
if (bits < 8) |
| 446 |
|
|
{ |
| 447 |
|
|
sendto_one(source_p, |
| 448 |
michael |
611 |
":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.", |
| 449 |
|
|
me.name, source_p->name); |
| 450 |
adx |
30 |
return; |
| 451 |
|
|
} |
| 452 |
|
|
|
| 453 |
|
|
#ifdef IPV6 |
| 454 |
|
|
if (t == HM_IPV6) |
| 455 |
|
|
t = AF_INET6; |
| 456 |
|
|
else |
| 457 |
|
|
#endif |
| 458 |
|
|
t = AF_INET; |
| 459 |
|
|
|
| 460 |
|
|
parse_netmask(dlhost, &daddr, NULL); |
| 461 |
|
|
|
| 462 |
|
|
if ((aconf = find_dline_conf(&daddr, t)) != NULL) |
| 463 |
|
|
{ |
| 464 |
|
|
creason = aconf->reason ? aconf->reason : def_reason; |
| 465 |
|
|
if (IsConfExemptKline(aconf)) |
| 466 |
|
|
sendto_one(source_p, |
| 467 |
|
|
":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s", |
| 468 |
|
|
me.name, source_p->name, dlhost, aconf->host, creason); |
| 469 |
|
|
else |
| 470 |
|
|
sendto_one(source_p, |
| 471 |
|
|
":%s NOTICE %s :[%s] already D-lined by [%s] - %s", |
| 472 |
|
|
me.name, source_p->name, dlhost, aconf->host, creason); |
| 473 |
|
|
return; |
| 474 |
|
|
} |
| 475 |
|
|
|
| 476 |
|
|
cur_time = CurrentTime; |
| 477 |
|
|
current_date = smalldate(cur_time); |
| 478 |
|
|
|
| 479 |
|
|
/* Look for an oper reason */ |
| 480 |
|
|
if ((oper_reason = strchr(reason, '|')) != NULL) |
| 481 |
|
|
*oper_reason++ = '\0'; |
| 482 |
|
|
|
| 483 |
|
|
if (!valid_comment(source_p, reason, YES)) |
| 484 |
|
|
return; |
| 485 |
|
|
|
| 486 |
|
|
conf = make_conf_item(DLINE_TYPE); |
| 487 |
|
|
aconf = map_to_conf(conf); |
| 488 |
|
|
DupString(aconf->host, dlhost); |
| 489 |
|
|
|
| 490 |
|
|
if (tkline_time != 0) |
| 491 |
|
|
{ |
| 492 |
|
|
ircsprintf(buffer, "Temporary D-line %d min. - %s (%s)", |
| 493 |
|
|
(int)(tkline_time/60), reason, current_date); |
| 494 |
|
|
DupString(aconf->reason, buffer); |
| 495 |
|
|
if (oper_reason != NULL) |
| 496 |
|
|
DupString(aconf->oper_reason, oper_reason); |
| 497 |
|
|
apply_tdline(source_p, conf, current_date, tkline_time); |
| 498 |
|
|
} |
| 499 |
|
|
else |
| 500 |
|
|
{ |
| 501 |
|
|
ircsprintf(buffer, "%s (%s)", reason, current_date); |
| 502 |
|
|
DupString(aconf->reason, buffer); |
| 503 |
|
|
if (oper_reason != NULL) |
| 504 |
|
|
DupString(aconf->oper_reason, oper_reason); |
| 505 |
|
|
add_conf_by_address(CONF_DLINE, aconf); |
| 506 |
|
|
write_conf_line(source_p, conf, current_date, cur_time); |
| 507 |
|
|
} |
| 508 |
|
|
|
| 509 |
|
|
rehashed_klines = 1; |
| 510 |
michael |
611 |
} |
| 511 |
adx |
30 |
|
| 512 |
|
|
/* already_placed_kline() |
| 513 |
|
|
* inputs - user to complain to, username & host to check for |
| 514 |
|
|
* outputs - returns 1 on existing K-line, 0 if doesn't exist |
| 515 |
|
|
* side effects - notifies source_p if the K-line already exists |
| 516 |
|
|
*/ |
| 517 |
|
|
/* |
| 518 |
|
|
* Note: This currently works if the new K-line is a special case of an |
| 519 |
|
|
* existing K-line, but not the other way round. To do that we would |
| 520 |
|
|
* have to walk the hash and check every existing K-line. -A1kmm. |
| 521 |
|
|
*/ |
| 522 |
|
|
static int |
| 523 |
|
|
already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int warn) |
| 524 |
|
|
{ |
| 525 |
|
|
const char *reason; |
| 526 |
|
|
struct irc_ssaddr iphost, *piphost; |
| 527 |
|
|
struct AccessItem *aconf; |
| 528 |
|
|
int t; |
| 529 |
|
|
|
| 530 |
|
|
if ((t = parse_netmask(lhost, &iphost, &t)) != HM_HOST) |
| 531 |
|
|
{ |
| 532 |
|
|
#ifdef IPV6 |
| 533 |
|
|
if (t == HM_IPV6) |
| 534 |
|
|
t = AF_INET6; |
| 535 |
|
|
else |
| 536 |
|
|
#endif |
| 537 |
|
|
t = AF_INET; |
| 538 |
|
|
piphost = &iphost; |
| 539 |
|
|
} |
| 540 |
|
|
else |
| 541 |
|
|
{ |
| 542 |
|
|
t = 0; |
| 543 |
|
|
piphost = NULL; |
| 544 |
|
|
} |
| 545 |
|
|
|
| 546 |
|
|
if ((aconf = find_conf_by_address(lhost, piphost, CONF_KILL, t, luser, NULL))) |
| 547 |
|
|
{ |
| 548 |
|
|
if (warn) |
| 549 |
|
|
{ |
| 550 |
|
|
reason = aconf->reason ? aconf->reason : "No reason"; |
| 551 |
|
|
sendto_one(source_p, |
| 552 |
|
|
":%s NOTICE %s :[%s@%s] already K-Lined by [%s@%s] - %s", |
| 553 |
|
|
me.name, source_p->name, luser, lhost, aconf->user, |
| 554 |
|
|
aconf->host, reason); |
| 555 |
|
|
} |
| 556 |
|
|
return(1); |
| 557 |
|
|
} |
| 558 |
|
|
|
| 559 |
|
|
return(0); |
| 560 |
|
|
} |
| 561 |
|
|
|
| 562 |
|
|
/* |
| 563 |
|
|
** mo_unkline |
| 564 |
|
|
** Added Aug 31, 1997 |
| 565 |
|
|
** common (Keith Fralick) fralick@gate.net |
| 566 |
|
|
** |
| 567 |
|
|
** parv[0] = sender |
| 568 |
|
|
** parv[1] = address to remove |
| 569 |
|
|
* |
| 570 |
|
|
* |
| 571 |
|
|
*/ |
| 572 |
|
|
static void |
| 573 |
|
|
mo_unkline(struct Client *client_p,struct Client *source_p, |
| 574 |
|
|
int parc, char *parv[]) |
| 575 |
|
|
{ |
| 576 |
|
|
char *target_server = NULL; |
| 577 |
|
|
char *user, *host; |
| 578 |
|
|
|
| 579 |
|
|
if (!IsOperUnkline(source_p)) |
| 580 |
|
|
{ |
| 581 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS), |
| 582 |
|
|
me.name, source_p->name, "unkline"); |
| 583 |
|
|
return; |
| 584 |
|
|
} |
| 585 |
|
|
|
| 586 |
|
|
if (parc < 2 || EmptyString(parv[1])) |
| 587 |
|
|
{ |
| 588 |
|
|
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
| 589 |
|
|
me.name, source_p->name, "UNKLINE"); |
| 590 |
|
|
return; |
| 591 |
|
|
} |
| 592 |
|
|
|
| 593 |
|
|
if (parse_aline("UNKLINE", source_p, parc, parv, 0, &user, |
| 594 |
|
|
&host, NULL, &target_server, NULL) < 0) |
| 595 |
|
|
return; |
| 596 |
|
|
|
| 597 |
|
|
if (target_server != NULL) |
| 598 |
|
|
{ |
| 599 |
|
|
sendto_match_servs(source_p, target_server, CAP_UNKLN, |
| 600 |
|
|
"UNKLINE %s %s %s", |
| 601 |
|
|
target_server, user, host); |
| 602 |
|
|
|
| 603 |
|
|
/* Allow ON to apply local unkline as well if it matches */ |
| 604 |
|
|
if (!match(target_server, me.name)) |
| 605 |
|
|
return; |
| 606 |
|
|
} |
| 607 |
|
|
else |
| 608 |
|
|
cluster_a_line(source_p, "UNKLINE", CAP_UNKLN, SHARED_UNKLINE, |
| 609 |
|
|
"%s %s", user, host); |
| 610 |
|
|
|
| 611 |
|
|
if (remove_tkline_match(host, user)) |
| 612 |
|
|
{ |
| 613 |
|
|
sendto_one(source_p, |
| 614 |
|
|
":%s NOTICE %s :Un-klined [%s@%s] from temporary K-Lines", |
| 615 |
|
|
me.name, source_p->name, user, host); |
| 616 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 617 |
|
|
"%s has removed the temporary K-Line for: [%s@%s]", |
| 618 |
|
|
get_oper_name(source_p), user, host); |
| 619 |
|
|
ilog(L_NOTICE, "%s removed temporary K-Line for [%s@%s]", |
| 620 |
|
|
source_p->name, user, host); |
| 621 |
|
|
return; |
| 622 |
|
|
} |
| 623 |
|
|
|
| 624 |
|
|
if (remove_conf_line(KLINE_TYPE, source_p, user, host) > 0) |
| 625 |
|
|
{ |
| 626 |
|
|
sendto_one(source_p, ":%s NOTICE %s :K-Line for [%s@%s] is removed", |
| 627 |
|
|
me.name, source_p->name, user,host); |
| 628 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 629 |
|
|
"%s has removed the K-Line for: [%s@%s]", |
| 630 |
|
|
get_oper_name(source_p), user, host); |
| 631 |
|
|
ilog(L_NOTICE, "%s removed K-Line for [%s@%s]", |
| 632 |
|
|
source_p->name, user, host); |
| 633 |
|
|
} |
| 634 |
|
|
else |
| 635 |
|
|
sendto_one(source_p, ":%s NOTICE %s :No K-Line for [%s@%s] found", |
| 636 |
|
|
me.name, source_p->name, user, host); |
| 637 |
|
|
} |
| 638 |
|
|
|
| 639 |
|
|
/* me_unkline() |
| 640 |
|
|
* |
| 641 |
|
|
* inputs - server |
| 642 |
|
|
* - client |
| 643 |
|
|
* - parc |
| 644 |
|
|
* - parv |
| 645 |
|
|
* outputs - none |
| 646 |
|
|
* side effects - if server is authorized, kline is removed |
| 647 |
|
|
* does not propagate message |
| 648 |
|
|
*/ |
| 649 |
|
|
static void |
| 650 |
|
|
me_unkline(struct Client *client_p, struct Client *source_p, |
| 651 |
|
|
int parc, char *parv[]) |
| 652 |
|
|
{ |
| 653 |
|
|
const char *kuser, *khost; |
| 654 |
|
|
|
| 655 |
|
|
if (parc != 4) |
| 656 |
|
|
return; |
| 657 |
|
|
|
| 658 |
|
|
kuser = parv[2]; |
| 659 |
|
|
khost = parv[3]; |
| 660 |
|
|
|
| 661 |
|
|
if (!IsClient(source_p) || !match(parv[1], me.name)) |
| 662 |
|
|
return; |
| 663 |
|
|
|
| 664 |
|
|
if (find_matching_name_conf(ULINE_TYPE, |
| 665 |
|
|
source_p->servptr->name, |
| 666 |
|
|
source_p->username, source_p->host, |
| 667 |
|
|
SHARED_UNKLINE)) |
| 668 |
|
|
{ |
| 669 |
|
|
if (remove_tkline_match(khost, kuser)) |
| 670 |
|
|
{ |
| 671 |
|
|
sendto_one(source_p, |
| 672 |
|
|
":%s NOTICE %s :Un-klined [%s@%s] from temporary K-Lines", |
| 673 |
|
|
me.name, source_p->name, kuser, khost); |
| 674 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 675 |
|
|
"%s has removed the temporary K-Line for: [%s@%s]", |
| 676 |
|
|
get_oper_name(source_p), kuser, khost); |
| 677 |
|
|
ilog(L_NOTICE, "%s removed temporary K-Line for [%s@%s]", |
| 678 |
|
|
source_p->name, kuser, khost); |
| 679 |
|
|
return; |
| 680 |
|
|
} |
| 681 |
|
|
|
| 682 |
|
|
if (remove_conf_line(KLINE_TYPE, source_p, kuser, khost) > 0) |
| 683 |
|
|
{ |
| 684 |
|
|
sendto_one(source_p, ":%s NOTICE %s :K-Line for [%s@%s] is removed", |
| 685 |
|
|
me.name, source_p->name, kuser, khost); |
| 686 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 687 |
|
|
"%s has removed the K-Line for: [%s@%s]", |
| 688 |
|
|
get_oper_name(source_p), kuser, khost); |
| 689 |
|
|
|
| 690 |
|
|
ilog(L_NOTICE, "%s removed K-Line for [%s@%s]", |
| 691 |
|
|
source_p->name, kuser, khost); |
| 692 |
|
|
} |
| 693 |
|
|
else |
| 694 |
|
|
sendto_one(source_p, ":%s NOTICE %s :No K-Line for [%s@%s] found", |
| 695 |
|
|
me.name, source_p->name, kuser, khost); |
| 696 |
|
|
} |
| 697 |
|
|
} |
| 698 |
|
|
|
| 699 |
|
|
/* ms_unkline - propagates and handles a remote unkline message */ |
| 700 |
|
|
static void |
| 701 |
|
|
ms_unkline(struct Client *client_p, struct Client *source_p, |
| 702 |
|
|
int parc, char *parv[]) |
| 703 |
|
|
{ |
| 704 |
|
|
if (parc != 4) |
| 705 |
|
|
return; |
| 706 |
|
|
|
| 707 |
|
|
sendto_match_servs(source_p, parv[1], CAP_UNKLN, |
| 708 |
|
|
"UNKLINE %s %s %s", |
| 709 |
|
|
parv[1], parv[2], parv[3]); |
| 710 |
|
|
|
| 711 |
|
|
me_unkline(client_p, source_p, parc, parv); |
| 712 |
|
|
} |
| 713 |
|
|
|
| 714 |
|
|
/* static int remove_tkline_match(const char *host, const char *user) |
| 715 |
|
|
* Input: A hostname, a username to unkline. |
| 716 |
|
|
* Output: returns YES on success, NO if no tkline removed. |
| 717 |
|
|
* Side effects: Any matching tklines are removed. |
| 718 |
|
|
*/ |
| 719 |
|
|
static int |
| 720 |
|
|
remove_tkline_match(const char *host, const char *user) |
| 721 |
|
|
{ |
| 722 |
|
|
struct AccessItem *tk_c; |
| 723 |
|
|
dlink_node *tk_n; |
| 724 |
|
|
struct irc_ssaddr addr, caddr; |
| 725 |
|
|
int nm_t, cnm_t, bits, cbits; |
| 726 |
|
|
nm_t = parse_netmask(host, &addr, &bits); |
| 727 |
|
|
|
| 728 |
|
|
DLINK_FOREACH(tk_n, temporary_klines.head) |
| 729 |
|
|
{ |
| 730 |
|
|
tk_c = map_to_conf(tk_n->data); |
| 731 |
|
|
cnm_t = parse_netmask(tk_c->host, &caddr, &cbits); |
| 732 |
|
|
if (cnm_t != nm_t || irccmp(user, tk_c->user)) |
| 733 |
|
|
continue; |
| 734 |
|
|
if ((nm_t==HM_HOST && !irccmp(tk_c->host, host)) || |
| 735 |
|
|
(nm_t==HM_IPV4 && bits==cbits && match_ipv4(&addr, &caddr, bits)) |
| 736 |
|
|
#ifdef IPV6 |
| 737 |
|
|
|| (nm_t==HM_IPV6 && bits==cbits && match_ipv6(&addr, &caddr, bits)) |
| 738 |
|
|
#endif |
| 739 |
|
|
) |
| 740 |
|
|
{ |
| 741 |
|
|
dlinkDelete(tk_n, &temporary_klines); |
| 742 |
|
|
delete_one_address_conf(tk_c->host, tk_c); |
| 743 |
|
|
return(YES); |
| 744 |
|
|
} |
| 745 |
|
|
} |
| 746 |
|
|
|
| 747 |
|
|
return(NO); |
| 748 |
|
|
} |
| 749 |
|
|
|
| 750 |
|
|
/* static int remove_tdline_match(const char *host, const char *user) |
| 751 |
|
|
* Input: An ip to undline. |
| 752 |
|
|
* Output: returns YES on success, NO if no tdline removed. |
| 753 |
|
|
* Side effects: Any matching tdlines are removed. |
| 754 |
|
|
*/ |
| 755 |
|
|
static int |
| 756 |
|
|
remove_tdline_match(const char *cidr) |
| 757 |
|
|
{ |
| 758 |
|
|
struct AccessItem *td_conf; |
| 759 |
|
|
dlink_node *td_node; |
| 760 |
|
|
struct irc_ssaddr addr, caddr; |
| 761 |
|
|
int nm_t, cnm_t, bits, cbits; |
| 762 |
|
|
nm_t = parse_netmask(cidr, &addr, &bits); |
| 763 |
|
|
|
| 764 |
|
|
DLINK_FOREACH(td_node, temporary_dlines.head) |
| 765 |
|
|
{ |
| 766 |
|
|
td_conf = map_to_conf(td_node->data); |
| 767 |
|
|
cnm_t = parse_netmask(td_conf->host, &caddr, &cbits); |
| 768 |
|
|
|
| 769 |
|
|
if (cnm_t != nm_t) |
| 770 |
|
|
continue; |
| 771 |
|
|
|
| 772 |
|
|
if((nm_t==HM_HOST && !irccmp(td_conf->host, cidr)) || |
| 773 |
|
|
(nm_t==HM_IPV4 && bits==cbits && match_ipv4(&addr, &caddr, bits)) |
| 774 |
|
|
#ifdef IPV6 |
| 775 |
|
|
|| (nm_t==HM_IPV6 && bits==cbits && match_ipv6(&addr, &caddr, bits)) |
| 776 |
|
|
#endif |
| 777 |
|
|
) |
| 778 |
|
|
{ |
| 779 |
|
|
dlinkDelete(td_node, &temporary_dlines); |
| 780 |
|
|
delete_one_address_conf(td_conf->host, td_conf); |
| 781 |
|
|
return(YES); |
| 782 |
|
|
} |
| 783 |
|
|
} |
| 784 |
|
|
|
| 785 |
|
|
return(NO); |
| 786 |
|
|
} |
| 787 |
|
|
|
| 788 |
|
|
/* |
| 789 |
|
|
** m_undline |
| 790 |
|
|
** added May 28th 2000 by Toby Verrall <toot@melnet.co.uk> |
| 791 |
|
|
** based totally on m_unkline |
| 792 |
|
|
** added to hybrid-7 7/11/2000 --is |
| 793 |
|
|
** |
| 794 |
|
|
** parv[0] = sender nick |
| 795 |
|
|
** parv[1] = dline to remove |
| 796 |
|
|
*/ |
| 797 |
|
|
static void |
| 798 |
|
|
mo_undline(struct Client *client_p, struct Client *source_p, |
| 799 |
|
|
int parc, char *parv[]) |
| 800 |
|
|
{ |
| 801 |
|
|
const char *cidr; |
| 802 |
|
|
|
| 803 |
|
|
if (!IsOperUnkline(source_p)) |
| 804 |
|
|
{ |
| 805 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS), |
| 806 |
|
|
me.name, source_p->name, "undline"); |
| 807 |
|
|
return; |
| 808 |
|
|
} |
| 809 |
|
|
|
| 810 |
|
|
cidr = parv[1]; |
| 811 |
|
|
|
| 812 |
|
|
if (remove_tdline_match(cidr)) |
| 813 |
|
|
{ |
| 814 |
|
|
sendto_one(source_p, |
| 815 |
|
|
":%s NOTICE %s :Un-Dlined [%s] from temporary D-Lines", |
| 816 |
|
|
me.name, source_p->name, cidr); |
| 817 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 818 |
|
|
"%s has removed the temporary D-Line for: [%s]", |
| 819 |
|
|
get_oper_name(source_p), cidr); |
| 820 |
|
|
ilog(L_NOTICE, "%s removed temporary D-Line for [%s]", source_p->name, cidr); |
| 821 |
|
|
return; |
| 822 |
|
|
} |
| 823 |
|
|
|
| 824 |
|
|
if (remove_conf_line(DLINE_TYPE, source_p, cidr, NULL) > 0) |
| 825 |
|
|
{ |
| 826 |
|
|
sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed", |
| 827 |
|
|
me.name, source_p->name, cidr); |
| 828 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 829 |
|
|
"%s has removed the D-Line for: [%s]", |
| 830 |
|
|
get_oper_name(source_p), cidr); |
| 831 |
|
|
ilog(L_NOTICE, "%s removed D-Line for [%s]", |
| 832 |
|
|
get_oper_name(source_p), cidr); |
| 833 |
|
|
} |
| 834 |
|
|
else |
| 835 |
|
|
sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found", |
| 836 |
|
|
me.name, source_p->name, cidr); |
| 837 |
|
|
} |