| 29 |
|
#include "irc_string.h" |
| 30 |
|
#include "sprintf_irc.h" |
| 31 |
|
#include "ircd.h" |
| 32 |
+ |
#include "conf.h" |
| 33 |
|
#include "hostmask.h" |
| 34 |
|
#include "numeric.h" |
| 35 |
|
#include "fdlist.h" |
| 36 |
|
#include "s_bsd.h" |
| 37 |
< |
#include "s_conf.h" |
| 37 |
< |
#include "s_log.h" |
| 37 |
> |
#include "log.h" |
| 38 |
|
#include "s_misc.h" |
| 39 |
|
#include "send.h" |
| 40 |
|
#include "hash.h" |
| 42 |
|
#include "s_gline.h" |
| 43 |
|
#include "parse.h" |
| 44 |
|
#include "modules.h" |
| 45 |
+ |
#include "conf_db.h" |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
static int already_placed_kline(struct Client *, const char *, const char *, int); |
| 49 |
< |
static void apply_kline(struct Client *, struct ConfItem *, const char *, time_t); |
| 49 |
< |
static void apply_tkline(struct Client *, struct ConfItem *, int); |
| 49 |
> |
static void m_kline_add_kline(struct Client *, struct MaskItem *, time_t); |
| 50 |
|
|
| 51 |
|
static char buffer[IRCD_BUFSIZE]; |
| 52 |
< |
static int remove_tkline_match(const char *, const char *); |
| 52 |
> |
static int remove_kline_match(const char *, const char *); |
| 53 |
|
|
| 54 |
|
|
| 55 |
|
/* mo_kline() |
| 63 |
|
*/ |
| 64 |
|
static void |
| 65 |
|
mo_kline(struct Client *client_p, struct Client *source_p, |
| 66 |
< |
int parc, char **parv) |
| 66 |
> |
int parc, char *parv[]) |
| 67 |
|
{ |
| 68 |
|
char *reason = NULL; |
| 69 |
– |
char *oper_reason; |
| 69 |
|
char *user = NULL; |
| 70 |
|
char *host = NULL; |
| 71 |
|
const char *current_date; |
| 72 |
|
char *target_server = NULL; |
| 73 |
< |
struct ConfItem *conf; |
| 75 |
< |
struct AccessItem *aconf; |
| 73 |
> |
struct MaskItem *conf; |
| 74 |
|
time_t tkline_time = 0; |
| 75 |
|
time_t cur_time; |
| 76 |
|
|
| 89 |
|
{ |
| 90 |
|
if (HasID(source_p)) |
| 91 |
|
{ |
| 92 |
< |
sendto_server(NULL, NULL, CAP_KLN|CAP_TS6, NOCAPS, |
| 92 |
> |
sendto_server(NULL, CAP_KLN|CAP_TS6, NOCAPS, |
| 93 |
|
":%s KLINE %s %lu %s %s :%s", |
| 94 |
|
source_p->id, target_server, (unsigned long)tkline_time, |
| 95 |
|
user, host, reason); |
| 96 |
< |
sendto_server(NULL, NULL, CAP_KLN, CAP_TS6, |
| 96 |
> |
sendto_server(NULL, CAP_KLN, CAP_TS6, |
| 97 |
|
":%s KLINE %s %lu %s %s :%s", |
| 98 |
|
source_p->name, target_server, (unsigned long)tkline_time, |
| 99 |
|
user, host, reason); |
| 100 |
|
} |
| 101 |
|
else |
| 102 |
< |
sendto_server(NULL, NULL, CAP_KLN, NOCAPS, |
| 102 |
> |
sendto_server(NULL, CAP_KLN, NOCAPS, |
| 103 |
|
":%s KLINE %s %lu %s %s :%s", |
| 104 |
|
source_p->name, target_server, (unsigned long)tkline_time, |
| 105 |
|
user, host, reason); |
| 115 |
|
if (already_placed_kline(source_p, user, host, 1)) |
| 116 |
|
return; |
| 117 |
|
|
| 120 |
– |
/* Look for an oper reason */ |
| 121 |
– |
if ((oper_reason = strchr(reason, '|')) != NULL) |
| 122 |
– |
*oper_reason++ = '\0'; |
| 123 |
– |
|
| 118 |
|
cur_time = CurrentTime; |
| 119 |
|
current_date = smalldate(cur_time); |
| 120 |
< |
conf = make_conf_item(KLINE_TYPE); |
| 127 |
< |
aconf = map_to_conf(conf); |
| 120 |
> |
conf = conf_make(CONF_KLINE); |
| 121 |
|
|
| 122 |
< |
DupString(aconf->host, host); |
| 123 |
< |
DupString(aconf->user, user); |
| 122 |
> |
DupString(conf->host, host); |
| 123 |
> |
DupString(conf->user, user); |
| 124 |
|
|
| 125 |
|
if (tkline_time != 0) |
| 133 |
– |
{ |
| 126 |
|
snprintf(buffer, sizeof(buffer), "Temporary K-line %d min. - %s (%s)", |
| 127 |
|
(int)(tkline_time/60), reason, current_date); |
| 136 |
– |
DupString(aconf->reason, buffer); |
| 137 |
– |
|
| 138 |
– |
if (oper_reason != NULL) |
| 139 |
– |
DupString(aconf->oper_reason, oper_reason); |
| 140 |
– |
apply_tkline(source_p, conf, tkline_time); |
| 141 |
– |
} |
| 128 |
|
else |
| 143 |
– |
{ |
| 129 |
|
snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date); |
| 145 |
– |
DupString(aconf->reason, buffer); |
| 130 |
|
|
| 131 |
< |
if (oper_reason != NULL) |
| 132 |
< |
DupString(aconf->oper_reason, oper_reason); |
| 149 |
< |
apply_kline(source_p, conf, current_date, cur_time); |
| 150 |
< |
} |
| 131 |
> |
DupString(conf->reason, buffer); |
| 132 |
> |
m_kline_add_kline(source_p, conf, tkline_time); |
| 133 |
|
} |
| 134 |
|
|
| 135 |
|
/* me_kline - handle remote kline. no propagation */ |
| 137 |
|
me_kline(struct Client *client_p, struct Client *source_p, |
| 138 |
|
int parc, char *parv[]) |
| 139 |
|
{ |
| 140 |
< |
struct ConfItem *conf=NULL; |
| 141 |
< |
struct AccessItem *aconf=NULL; |
| 160 |
< |
int tkline_time; |
| 140 |
> |
struct MaskItem *conf = NULL; |
| 141 |
> |
int tkline_time = 0; |
| 142 |
|
const char* current_date; |
| 143 |
|
time_t cur_time; |
| 144 |
< |
char *kuser, *khost, *kreason, *oper_reason; |
| 144 |
> |
char *kuser, *khost, *kreason; |
| 145 |
|
|
| 146 |
|
if (parc != 6 || EmptyString(parv[5])) |
| 147 |
|
return; |
| 154 |
|
khost = parv[4]; |
| 155 |
|
kreason = parv[5]; |
| 156 |
|
|
| 176 |
– |
if ((oper_reason = strchr(kreason, '|')) != NULL) |
| 177 |
– |
*oper_reason++ = '\0'; |
| 178 |
– |
|
| 157 |
|
cur_time = CurrentTime; |
| 158 |
|
current_date = smalldate(cur_time); |
| 159 |
|
|
| 160 |
< |
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(ULINE_TYPE, source_p->servptr->name, |
| 160 |
> |
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
| 161 |
|
source_p->username, source_p->host, |
| 162 |
|
SHARED_KLINE)) |
| 163 |
|
{ |
| 165 |
|
already_placed_kline(source_p, kuser, khost, 1)) |
| 166 |
|
return; |
| 167 |
|
|
| 168 |
< |
conf = make_conf_item(KLINE_TYPE); |
| 169 |
< |
aconf = map_to_conf(conf); |
| 170 |
< |
DupString(aconf->host, khost); |
| 193 |
< |
DupString(aconf->user, kuser); |
| 168 |
> |
conf = conf_make(CONF_KLINE); |
| 169 |
> |
DupString(conf->host, khost); |
| 170 |
> |
DupString(conf->user, kuser); |
| 171 |
|
|
| 172 |
|
if (tkline_time != 0) |
| 196 |
– |
{ |
| 173 |
|
snprintf(buffer, sizeof(buffer), "Temporary K-line %d min. - %s (%s)", |
| 174 |
|
(int)(tkline_time/60), kreason, 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 |
– |
} |
| 175 |
|
else |
| 206 |
– |
{ |
| 176 |
|
snprintf(buffer, sizeof(buffer), "%s (%s)", kreason, current_date); |
| 208 |
– |
DupString(aconf->reason, buffer); |
| 177 |
|
|
| 178 |
< |
if (oper_reason != NULL) |
| 179 |
< |
DupString(aconf->oper_reason, oper_reason); |
| 212 |
< |
apply_kline(source_p, conf, current_date, cur_time); |
| 213 |
< |
} |
| 178 |
> |
DupString(conf->reason, buffer); |
| 179 |
> |
m_kline_add_kline(source_p, conf, tkline_time); |
| 180 |
|
} |
| 181 |
|
} |
| 182 |
|
|
| 196 |
|
me_kline(client_p, source_p, parc, parv); |
| 197 |
|
} |
| 198 |
|
|
| 233 |
– |
/* apply_kline() |
| 234 |
– |
* |
| 235 |
– |
* inputs - |
| 236 |
– |
* output - NONE |
| 237 |
– |
* side effects - kline as given, is added to the hashtable |
| 238 |
– |
* and conf file |
| 239 |
– |
*/ |
| 240 |
– |
static void |
| 241 |
– |
apply_kline(struct Client *source_p, struct ConfItem *conf, |
| 242 |
– |
const char *current_date, time_t cur_time) |
| 243 |
– |
{ |
| 244 |
– |
struct AccessItem *aconf = map_to_conf(conf); |
| 245 |
– |
|
| 246 |
– |
add_conf_by_address(CONF_KILL, aconf); |
| 247 |
– |
write_conf_line(source_p, conf, current_date, cur_time); |
| 248 |
– |
/* Now, activate kline against current online clients */ |
| 249 |
– |
rehashed_klines = 1; |
| 250 |
– |
} |
| 251 |
– |
|
| 199 |
|
/* apply_tkline() |
| 200 |
|
* |
| 201 |
|
* inputs - |
| 203 |
|
* side effects - tkline as given is placed |
| 204 |
|
*/ |
| 205 |
|
static void |
| 206 |
< |
apply_tkline(struct Client *source_p, struct ConfItem *conf, |
| 207 |
< |
int tkline_time) |
| 206 |
> |
m_kline_add_kline(struct Client *source_p, struct MaskItem *conf, |
| 207 |
> |
time_t tkline_time) |
| 208 |
|
{ |
| 209 |
< |
struct AccessItem *aconf; |
| 209 |
> |
if (tkline_time) |
| 210 |
> |
{ |
| 211 |
> |
conf->hold = CurrentTime + tkline_time; |
| 212 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 213 |
> |
"%s added temporary %d min. K-Line for [%s@%s] [%s]", |
| 214 |
> |
get_oper_name(source_p), tkline_time/60, |
| 215 |
> |
conf->user, conf->host, |
| 216 |
> |
conf->reason); |
| 217 |
> |
sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. K-Line [%s@%s]", |
| 218 |
> |
MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from), |
| 219 |
> |
source_p->name, tkline_time/60, conf->user, conf->host); |
| 220 |
> |
ilog(LOG_TYPE_KLINE, "%s added temporary %d min. K-Line for [%s@%s] [%s]", |
| 221 |
> |
source_p->name, tkline_time/60, |
| 222 |
> |
conf->user, conf->host, conf->reason); |
| 223 |
> |
} |
| 224 |
> |
else |
| 225 |
> |
{ |
| 226 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 227 |
> |
"%s added K-Line for [%s@%s] [%s]", |
| 228 |
> |
get_oper_name(source_p), |
| 229 |
> |
conf->user, conf->host, conf->reason); |
| 230 |
> |
sendto_one(source_p, ":%s NOTICE %s :Added K-Line [%s@%s]", |
| 231 |
> |
MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from), |
| 232 |
> |
source_p->name, conf->user, conf->host); |
| 233 |
> |
ilog(LOG_TYPE_KLINE, "%s added K-Line for [%s@%s] [%s]", |
| 234 |
> |
source_p->name, conf->user, conf->host, conf->reason); |
| 235 |
> |
} |
| 236 |
|
|
| 237 |
< |
aconf = (struct AccessItem *)map_to_conf(conf); |
| 238 |
< |
aconf->hold = CurrentTime + tkline_time; |
| 266 |
< |
add_temp_line(conf); |
| 267 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 268 |
< |
"%s added temporary %d min. K-Line for [%s@%s] [%s]", |
| 269 |
< |
get_oper_name(source_p), tkline_time/60, |
| 270 |
< |
aconf->user, aconf->host, |
| 271 |
< |
aconf->reason); |
| 272 |
< |
sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. K-Line [%s@%s]", |
| 273 |
< |
MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from), |
| 274 |
< |
source_p->name, tkline_time/60, aconf->user, aconf->host); |
| 275 |
< |
ilog(LOG_TYPE_KLINE, "%s added temporary %d min. K-Line for [%s@%s] [%s]", |
| 276 |
< |
source_p->name, tkline_time/60, |
| 277 |
< |
aconf->user, aconf->host, aconf->reason); |
| 237 |
> |
conf->setat = CurrentTime; |
| 238 |
> |
SetConfDatabase(conf); |
| 239 |
|
|
| 240 |
+ |
add_conf_by_address(CONF_KLINE, conf); |
| 241 |
|
rehashed_klines = 1; |
| 242 |
|
} |
| 243 |
|
|
| 256 |
|
{ |
| 257 |
|
const char *reason; |
| 258 |
|
struct irc_ssaddr iphost, *piphost; |
| 259 |
< |
struct AccessItem *aconf; |
| 259 |
> |
struct MaskItem *conf = NULL; |
| 260 |
|
int t; |
| 261 |
|
|
| 262 |
|
if ((t = parse_netmask(lhost, &iphost, &t)) != HM_HOST) |
| 275 |
|
piphost = NULL; |
| 276 |
|
} |
| 277 |
|
|
| 278 |
< |
if ((aconf = find_conf_by_address(lhost, piphost, CONF_KILL, t, luser, NULL))) |
| 278 |
> |
if ((conf = find_conf_by_address(lhost, piphost, CONF_KLINE, t, luser, NULL, 0))) |
| 279 |
|
{ |
| 280 |
|
if (warn) |
| 281 |
|
{ |
| 282 |
< |
reason = aconf->reason ? aconf->reason : "No reason"; |
| 282 |
> |
reason = conf->reason ? conf->reason : "No reason"; |
| 283 |
|
sendto_one(source_p, |
| 284 |
|
":%s NOTICE %s :[%s@%s] already K-Lined by [%s@%s] - %s", |
| 285 |
< |
me.name, source_p->name, luser, lhost, aconf->user, |
| 286 |
< |
aconf->host, reason); |
| 285 |
> |
me.name, source_p->name, luser, lhost, conf->user, |
| 286 |
> |
conf->host, reason); |
| 287 |
|
} |
| 288 |
< |
return(1); |
| 288 |
> |
|
| 289 |
> |
return 1; |
| 290 |
|
} |
| 291 |
|
|
| 292 |
< |
return(0); |
| 292 |
> |
return 0; |
| 293 |
|
} |
| 294 |
|
|
| 295 |
|
/* |
| 316 |
|
return; |
| 317 |
|
} |
| 318 |
|
|
| 319 |
< |
if (parc < 2 || EmptyString(parv[1])) |
| 319 |
> |
if (EmptyString(parv[1])) |
| 320 |
|
{ |
| 321 |
|
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
| 322 |
|
me.name, source_p->name, "UNKLINE"); |
| 341 |
|
cluster_a_line(source_p, "UNKLINE", CAP_UNKLN, SHARED_UNKLINE, |
| 342 |
|
"%s %s", user, host); |
| 343 |
|
|
| 344 |
< |
if (remove_tkline_match(host, user)) |
| 344 |
> |
if (remove_kline_match(host, user)) |
| 345 |
|
{ |
| 346 |
|
sendto_one(source_p, |
| 347 |
< |
":%s NOTICE %s :Un-klined [%s@%s] from temporary K-Lines", |
| 347 |
> |
":%s NOTICE %s :K-Line for [%s@%s] is removed", |
| 348 |
|
me.name, source_p->name, user, host); |
| 349 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 387 |
< |
"%s has removed the temporary K-Line for: [%s@%s]", |
| 388 |
< |
get_oper_name(source_p), user, host); |
| 389 |
< |
ilog(LOG_TYPE_KLINE, "%s removed temporary K-Line for [%s@%s]", |
| 390 |
< |
source_p->name, user, host); |
| 391 |
< |
return; |
| 392 |
< |
} |
| 393 |
< |
|
| 394 |
< |
if (remove_conf_line(KLINE_TYPE, source_p, user, host) > 0) |
| 395 |
< |
{ |
| 396 |
< |
sendto_one(source_p, ":%s NOTICE %s :K-Line for [%s@%s] is removed", |
| 397 |
< |
me.name, source_p->name, user,host); |
| 398 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 349 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 350 |
|
"%s has removed the K-Line for: [%s@%s]", |
| 351 |
|
get_oper_name(source_p), user, host); |
| 352 |
|
ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]", |
| 382 |
|
if (!IsClient(source_p) || !match(parv[1], me.name)) |
| 383 |
|
return; |
| 384 |
|
|
| 385 |
< |
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(ULINE_TYPE, |
| 385 |
> |
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, |
| 386 |
|
source_p->servptr->name, |
| 387 |
|
source_p->username, source_p->host, |
| 388 |
|
SHARED_UNKLINE)) |
| 389 |
|
{ |
| 390 |
< |
if (remove_tkline_match(khost, kuser)) |
| 390 |
> |
if (remove_kline_match(khost, kuser)) |
| 391 |
|
{ |
| 392 |
|
sendto_one(source_p, |
| 393 |
< |
":%s NOTICE %s :Un-klined [%s@%s] from temporary K-Lines", |
| 443 |
< |
me.name, source_p->name, kuser, khost); |
| 444 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 445 |
< |
"%s has removed the temporary K-Line for: [%s@%s]", |
| 446 |
< |
get_oper_name(source_p), kuser, khost); |
| 447 |
< |
ilog(LOG_TYPE_KLINE, "%s removed temporary K-Line for [%s@%s]", |
| 448 |
< |
source_p->name, kuser, khost); |
| 449 |
< |
return; |
| 450 |
< |
} |
| 451 |
< |
|
| 452 |
< |
if (remove_conf_line(KLINE_TYPE, source_p, kuser, khost) > 0) |
| 453 |
< |
{ |
| 454 |
< |
sendto_one(source_p, ":%s NOTICE %s :K-Line for [%s@%s] is removed", |
| 393 |
> |
":%s NOTICE %s :K-Line for [%s@%s] is removed", |
| 394 |
|
me.name, source_p->name, kuser, khost); |
| 395 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 395 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 396 |
|
"%s has removed the K-Line for: [%s@%s]", |
| 397 |
< |
get_oper_name(source_p), kuser, khost); |
| 459 |
< |
|
| 397 |
> |
get_oper_name(source_p), kuser, khost); |
| 398 |
|
ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]", |
| 399 |
|
source_p->name, kuser, khost); |
| 400 |
|
} |
| 425 |
|
* Side effects: Any matching tklines are removed. |
| 426 |
|
*/ |
| 427 |
|
static int |
| 428 |
< |
remove_tkline_match(const char *host, const char *user) |
| 428 |
> |
remove_kline_match(const char *host, const char *user) |
| 429 |
|
{ |
| 430 |
< |
struct AccessItem *tk_c; |
| 431 |
< |
dlink_node *tk_n; |
| 432 |
< |
struct irc_ssaddr addr, caddr; |
| 433 |
< |
int nm_t, cnm_t, bits, cbits; |
| 434 |
< |
nm_t = parse_netmask(host, &addr, &bits); |
| 435 |
< |
|
| 498 |
< |
DLINK_FOREACH(tk_n, temporary_klines.head) |
| 499 |
< |
{ |
| 500 |
< |
tk_c = map_to_conf(tk_n->data); |
| 501 |
< |
cnm_t = parse_netmask(tk_c->host, &caddr, &cbits); |
| 502 |
< |
if (cnm_t != nm_t || irccmp(user, tk_c->user)) |
| 503 |
< |
continue; |
| 504 |
< |
if ((nm_t==HM_HOST && !irccmp(tk_c->host, host)) || |
| 505 |
< |
(nm_t==HM_IPV4 && bits==cbits && match_ipv4(&addr, &caddr, bits)) |
| 430 |
> |
struct irc_ssaddr iphost, *piphost; |
| 431 |
> |
struct MaskItem *conf = NULL; |
| 432 |
> |
int t; |
| 433 |
> |
|
| 434 |
> |
if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST) |
| 435 |
> |
{ |
| 436 |
|
#ifdef IPV6 |
| 437 |
< |
|| (nm_t==HM_IPV6 && bits==cbits && match_ipv6(&addr, &caddr, bits)) |
| 437 |
> |
if (t == HM_IPV6) |
| 438 |
> |
t = AF_INET6; |
| 439 |
> |
else |
| 440 |
|
#endif |
| 441 |
< |
) |
| 442 |
< |
{ |
| 443 |
< |
dlinkDelete(tk_n, &temporary_klines); |
| 444 |
< |
delete_one_address_conf(tk_c->host, tk_c); |
| 445 |
< |
return 1; |
| 446 |
< |
} |
| 441 |
> |
t = AF_INET; |
| 442 |
> |
piphost = &iphost; |
| 443 |
> |
} |
| 444 |
> |
else |
| 445 |
> |
{ |
| 446 |
> |
t = 0; |
| 447 |
> |
piphost = NULL; |
| 448 |
> |
} |
| 449 |
> |
|
| 450 |
> |
if ((conf = find_conf_by_address(host, piphost, CONF_KLINE, t, user, NULL, 0))) |
| 451 |
> |
{ |
| 452 |
> |
if (IsConfDatabase(conf)) |
| 453 |
> |
{ |
| 454 |
> |
delete_one_address_conf(host, conf); |
| 455 |
> |
return 1; |
| 456 |
> |
} |
| 457 |
|
} |
| 458 |
|
|
| 459 |
|
return 0; |