2007-01-25 06:40:21 +00:00
|
|
|
/*
|
2020-10-15 14:51:12 +00:00
|
|
|
* Solanum: a slightly advanced ircd
|
2007-01-25 06:40:21 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006 charybdis development team
|
|
|
|
* All rights reserved
|
|
|
|
*/
|
|
|
|
#include "stdinc.h"
|
|
|
|
#include "modules.h"
|
|
|
|
#include "hook.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "ircd.h"
|
|
|
|
#include "send.h"
|
|
|
|
#include "numeric.h"
|
|
|
|
#include "hostmask.h"
|
|
|
|
#include "s_conf.h"
|
|
|
|
#include "s_newconf.h"
|
|
|
|
#include "hash.h"
|
2013-04-27 09:57:44 +00:00
|
|
|
#include "messages.h"
|
2013-09-10 05:35:56 +00:00
|
|
|
#include "s_assert.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
/* {{{ Structures */
|
|
|
|
#define HURT_CUTOFF (10) /* protocol messages. */
|
|
|
|
#define HURT_DEFAULT_EXPIRE (7 * 24 * 60) /* minutes. */
|
|
|
|
#define HURT_EXIT_REASON "Hurt: Failed to identify to services"
|
|
|
|
|
|
|
|
enum {
|
|
|
|
HEAL_NICK = 0,
|
|
|
|
HEAL_IP
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _hurt_state {
|
|
|
|
time_t start_time;
|
|
|
|
uint32_t n_hurts;
|
2008-04-01 23:48:21 +00:00
|
|
|
rb_dlink_list hurt_clients;
|
2007-01-25 06:40:21 +00:00
|
|
|
uint16_t cutoff;
|
|
|
|
time_t default_expire;
|
|
|
|
const char *exit_reason;
|
|
|
|
} hurt_state_t;
|
|
|
|
|
|
|
|
typedef struct _hurt {
|
2007-12-12 23:03:20 +00:00
|
|
|
char *ip;
|
2007-01-25 06:40:21 +00:00
|
|
|
struct sockaddr *saddr;
|
|
|
|
int saddr_bits;
|
2007-12-12 23:03:20 +00:00
|
|
|
char *reason;
|
2007-01-25 06:40:21 +00:00
|
|
|
time_t expire;
|
|
|
|
} hurt_t;
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ Prototypes */
|
2016-03-09 07:37:03 +00:00
|
|
|
static void mo_hurt(struct MsgBuf *msgbuf_p, struct Client *, struct Client *, int, const char **);
|
|
|
|
static void me_hurt(struct MsgBuf *msgbuf_p, struct Client *, struct Client *, int, const char **);
|
|
|
|
static void mo_heal(struct MsgBuf *msgbuf_p, struct Client *, struct Client *, int, const char **);
|
|
|
|
static void me_heal(struct MsgBuf *msgbuf_p, struct Client *, struct Client *, int, const char **);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
static int modinit(void);
|
|
|
|
static void modfini(void);
|
|
|
|
|
2021-08-20 03:09:40 +00:00
|
|
|
static void client_exit_hook(void *);
|
|
|
|
static void new_local_user_hook(void *);
|
|
|
|
static void doing_stats_hook(void *);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
static void hurt_check_event(void *);
|
|
|
|
static void hurt_expire_event(void *);
|
|
|
|
|
|
|
|
static hurt_t *hurt_new(time_t, const char *, const char *);
|
|
|
|
static void hurt_add(hurt_t *);
|
|
|
|
static void hurt_propagate(struct Client *, struct Client *, hurt_t *);
|
|
|
|
static hurt_t *hurt_find(const char *ip);
|
|
|
|
static hurt_t *hurt_find_exact(const char *ip);
|
|
|
|
static void hurt_remove(const char *ip);
|
|
|
|
static void hurt_destroy(void *hurt);
|
|
|
|
|
2016-03-09 07:37:03 +00:00
|
|
|
static void heal_nick(struct Client *, struct Client *);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ State containers */
|
|
|
|
|
2008-04-01 23:48:21 +00:00
|
|
|
rb_dlink_list hurt_confs = { NULL, NULL, 0 };
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ Messages */
|
|
|
|
struct Message hurt_msgtab = {
|
2016-02-19 22:42:40 +00:00
|
|
|
"HURT", 0, 0, 0, 0, {
|
2007-01-25 06:40:21 +00:00
|
|
|
mg_ignore, mg_ignore, mg_ignore,
|
|
|
|
mg_ignore, {me_hurt, 0}, {mo_hurt, 3}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Message heal_msgtab = {
|
2016-02-19 22:42:40 +00:00
|
|
|
"HEAL", 0, 0, 0, 0, {
|
2007-01-25 06:40:21 +00:00
|
|
|
mg_ignore, mg_ignore, mg_ignore,
|
|
|
|
mg_ignore, {me_heal, 0}, {mo_heal, 2}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ Misc module stuff */
|
|
|
|
mapi_hfn_list_av1 hurt_hfnlist[] = {
|
2021-08-20 03:09:40 +00:00
|
|
|
{"client_exit", client_exit_hook},
|
|
|
|
{"new_local_user", new_local_user_hook},
|
|
|
|
{"doing_stats", doing_stats_hook},
|
2007-01-25 06:40:21 +00:00
|
|
|
{NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
mapi_clist_av1 hurt_clist[] = { &hurt_msgtab, &heal_msgtab, NULL };
|
|
|
|
|
2016-03-07 09:08:40 +00:00
|
|
|
static const char hurt_desc[] =
|
|
|
|
"Prevents \"hurt\" users from messaging anyone but operators or "
|
|
|
|
"services until they identify or are \"healed\"";
|
|
|
|
|
|
|
|
DECLARE_MODULE_AV2(
|
2007-01-25 06:40:21 +00:00
|
|
|
hurt,
|
|
|
|
modinit,
|
|
|
|
modfini,
|
|
|
|
hurt_clist,
|
|
|
|
NULL,
|
|
|
|
hurt_hfnlist,
|
2016-03-07 09:08:40 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
hurt_desc
|
2007-01-25 06:40:21 +00:00
|
|
|
);
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
hurt_state_t hurt_state = {
|
|
|
|
.cutoff = HURT_CUTOFF,
|
|
|
|
.default_expire = HURT_DEFAULT_EXPIRE,
|
|
|
|
.exit_reason = HURT_EXIT_REASON,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Module constructor/destructor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* {{{ static int modinit() */
|
2008-04-01 21:20:40 +00:00
|
|
|
|
|
|
|
struct ev_entry *hurt_expire_ev = NULL;
|
|
|
|
struct ev_entry *hurt_check_ev = NULL;
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
static int
|
|
|
|
modinit(void)
|
|
|
|
{
|
|
|
|
/* set-up hurt_state. */
|
2008-04-02 00:35:13 +00:00
|
|
|
hurt_state.start_time = rb_current_time();
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
/* add our event handlers. */
|
2008-04-01 21:20:40 +00:00
|
|
|
hurt_expire_ev = rb_event_add("hurt_expire", hurt_expire_event, NULL, 60);
|
|
|
|
hurt_check_ev = rb_event_add("hurt_check", hurt_check_event, NULL, 5);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ static void modfini() */
|
|
|
|
static void
|
|
|
|
modfini(void)
|
|
|
|
{
|
2008-04-01 23:48:21 +00:00
|
|
|
rb_dlink_node *ptr, *next_ptr;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
/* and delete our events. */
|
2008-04-01 21:20:40 +00:00
|
|
|
rb_event_delete(hurt_expire_ev);
|
|
|
|
rb_event_delete(hurt_check_ev);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-01 23:48:21 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_state.hurt_clients.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
2008-04-01 23:48:21 +00:00
|
|
|
rb_dlinkDestroy(ptr, &hurt_state.hurt_clients);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Message handlers.
|
|
|
|
*/
|
|
|
|
|
2016-03-09 07:37:03 +00:00
|
|
|
/* {{{ static void mo_hurt()
|
2007-01-25 06:40:21 +00:00
|
|
|
*
|
|
|
|
* HURT [<expire>] <ip> <reason>
|
2014-03-03 04:25:47 +00:00
|
|
|
*
|
2007-01-25 06:40:21 +00:00
|
|
|
* parv[1] - expire or ip
|
|
|
|
* parv[2] - ip or reason
|
|
|
|
* parv[3] - reason or NULL
|
|
|
|
*/
|
2016-03-09 07:37:03 +00:00
|
|
|
static void
|
2016-02-11 02:14:22 +00:00
|
|
|
mo_hurt(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
|
2007-01-25 06:40:21 +00:00
|
|
|
int parc, const char **parv)
|
|
|
|
{
|
|
|
|
const char *ip, *expire, *reason;
|
|
|
|
int expire_time;
|
|
|
|
hurt_t *hurt;
|
|
|
|
struct Client *target_p;
|
|
|
|
|
|
|
|
if (!IsOperK(source_p)) {
|
|
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
|
|
|
|
source_p->name, "kline");
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parc == 3)
|
|
|
|
expire = NULL, ip = parv[1], reason = parv[2];
|
|
|
|
else
|
|
|
|
expire = parv[1], ip = parv[2], reason = parv[3];
|
|
|
|
|
|
|
|
if (!expire)
|
|
|
|
expire_time = HURT_DEFAULT_EXPIRE;
|
|
|
|
if (expire && (expire_time = valid_temp_time(expire)) < 1) {
|
2007-01-25 07:23:01 +00:00
|
|
|
sendto_one_notice(source_p, ":Permanent HURTs are not supported");
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
if (EmptyString(reason)) {
|
2007-01-25 07:23:01 +00:00
|
|
|
sendto_one_notice(source_p, ":Empty HURT reasons are bad for business");
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Is this a client? */
|
|
|
|
if (strchr(ip, '.') == NULL && strchr(ip, ':') == NULL)
|
|
|
|
{
|
|
|
|
target_p = find_named_person(ip);
|
|
|
|
if (target_p == NULL)
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_NOSUCHNICK,
|
|
|
|
form_str(ERR_NOSUCHNICK), ip);
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
ip = target_p->orighost;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!strncmp(ip, "*@", 2))
|
|
|
|
ip += 2;
|
|
|
|
if (strchr(ip, '!') || strchr(ip, '@'))
|
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":Invalid HURT mask [%s]",
|
|
|
|
ip);
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hurt_find(ip) != NULL) {
|
2007-01-25 07:23:01 +00:00
|
|
|
sendto_one(source_p, ":[%s] already HURT", ip);
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* okay, we've got this far, now it's time to add the the HURT locally
|
|
|
|
* and propagate it to other servers on the network.
|
|
|
|
*/
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
|
|
|
"%s added HURT on [%s] for %ld minutes with reason [%s]",
|
|
|
|
get_oper_name(source_p), ip, (long) expire_time / 60, reason);
|
|
|
|
|
|
|
|
hurt = hurt_new(expire_time, ip, reason);
|
|
|
|
hurt_add(hurt);
|
|
|
|
hurt_propagate(NULL, source_p, hurt);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2016-03-09 07:37:03 +00:00
|
|
|
/* {{{ static void me_hurt()
|
2007-01-25 06:40:21 +00:00
|
|
|
*
|
|
|
|
* [ENCAP mask] HURT <target> <expire> <ip> <reason>
|
|
|
|
*
|
|
|
|
* parv[1] - expire
|
|
|
|
* parv[2] - ip
|
|
|
|
* parv[3] - reason
|
|
|
|
*/
|
2016-03-09 07:37:03 +00:00
|
|
|
static void
|
2016-02-11 02:14:22 +00:00
|
|
|
me_hurt(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
|
2007-01-25 06:40:21 +00:00
|
|
|
int parc, const char **parv)
|
|
|
|
{
|
|
|
|
time_t expire_time;
|
|
|
|
hurt_t *hurt;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* right... if we don't get enough arguments, or if we get any invalid
|
|
|
|
* arguments, just ignore this request - shit happens, and it's not worth
|
|
|
|
* dropping a server over.
|
|
|
|
*/
|
|
|
|
if (parc < 4 || !IsPerson(source_p))
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
if ((expire_time = atoi(parv[1])) < 1)
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
if (hurt_find(parv[2]) != NULL)
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
if (EmptyString(parv[3]))
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
|
|
|
"%s added HURT on [%s] for %ld minutes with reason [%s]",
|
|
|
|
get_oper_name(source_p), parv[2], (long) expire_time / 60, parv[3]);
|
|
|
|
hurt = hurt_new(expire_time, parv[2], parv[3]);
|
|
|
|
hurt_add(hurt);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2016-03-09 07:37:03 +00:00
|
|
|
/* {{{ static void mo_heal()
|
2007-01-25 06:40:21 +00:00
|
|
|
*
|
|
|
|
* HURT <nick>|<ip>
|
|
|
|
*
|
|
|
|
* parv[1] - nick or ip
|
|
|
|
*/
|
2016-03-09 07:37:03 +00:00
|
|
|
static void
|
2016-02-11 02:14:22 +00:00
|
|
|
mo_heal(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
|
2007-01-25 06:40:21 +00:00
|
|
|
int parc, const char **parv)
|
|
|
|
{
|
|
|
|
struct Client *target_p;
|
|
|
|
|
|
|
|
if (!IsOperUnkline(source_p))
|
|
|
|
{
|
|
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
|
|
|
me.name, source_p->name, "unkline");
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2015-12-12 23:22:21 +00:00
|
|
|
if (clean_nick(parv[1], 0))
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
target_p = find_named_person(parv[1]);
|
|
|
|
if (target_p == NULL)
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_NOSUCHNICK,
|
|
|
|
form_str(ERR_NOSUCHNICK), parv[1]);
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
if (MyConnect(target_p))
|
|
|
|
heal_nick(source_p, target_p);
|
|
|
|
else
|
|
|
|
sendto_one(target_p, ":%s ENCAP %s HEAL %s",
|
|
|
|
get_id(source_p, target_p),
|
|
|
|
target_p->servptr->name,
|
|
|
|
get_id(target_p, target_p));
|
|
|
|
}
|
|
|
|
else if (strchr(parv[1], '.'))
|
|
|
|
{
|
|
|
|
if (hurt_find_exact(parv[1]) == NULL)
|
|
|
|
{
|
2007-01-25 07:23:01 +00:00
|
|
|
sendto_one_notice(source_p, ":Mask [%s] is not HURT", parv[1]);
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
hurt_remove(parv[1]);
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s removed HURT on %s",
|
|
|
|
get_oper_name(source_p), parv[1]);
|
|
|
|
sendto_server(NULL, NULL, NOCAPS, NOCAPS, ":%s ENCAP * HEAL %s",
|
|
|
|
source_p->name, parv[1]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-01-25 07:23:01 +00:00
|
|
|
sendto_one(source_p, ":[%s] is not a valid IP address/nick", parv[1]);
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2016-03-09 07:37:03 +00:00
|
|
|
static void
|
2016-02-11 02:14:22 +00:00
|
|
|
me_heal(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
|
2007-01-25 06:40:21 +00:00
|
|
|
int parc, const char **parv)
|
|
|
|
{
|
|
|
|
struct Client *target_p;
|
|
|
|
|
|
|
|
/* as noted in me_hurt(), if we don't get sufficient arguments...
|
|
|
|
* *poof*, it's dropped...
|
|
|
|
*/
|
|
|
|
if (parc < 2)
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2015-12-12 23:22:21 +00:00
|
|
|
if (clean_nick(parv[1], 0))
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
target_p = find_person(parv[1]);
|
|
|
|
if (target_p != NULL && MyConnect(target_p))
|
|
|
|
heal_nick(source_p, target_p);
|
|
|
|
}
|
|
|
|
else if (strchr(parv[1], '.')) /* host or mask to remove ban for */
|
|
|
|
{
|
|
|
|
if (hurt_find_exact(parv[1]) == NULL)
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
hurt_remove(parv[1]);
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s removed HURT on %s",
|
|
|
|
get_oper_name(source_p), parv[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Event handlers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* {{{ static void hurt_check_event() */
|
|
|
|
static void
|
|
|
|
hurt_check_event(void *arg)
|
|
|
|
{
|
2008-04-01 23:48:21 +00:00
|
|
|
rb_dlink_node *ptr, *next_ptr;
|
2007-01-25 06:40:21 +00:00
|
|
|
struct Client *client_p;
|
|
|
|
|
2008-04-01 23:48:21 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_state.hurt_clients.head) {
|
2007-01-25 06:40:21 +00:00
|
|
|
client_p = ptr->data;
|
|
|
|
if (!EmptyString(client_p->user->suser))
|
|
|
|
{
|
2008-04-01 23:48:21 +00:00
|
|
|
rb_dlinkDestroy(ptr, &hurt_state.hurt_clients);
|
2007-01-25 06:40:21 +00:00
|
|
|
sendto_one_notice(client_p, ":HURT restriction removed for this session");
|
2008-04-02 00:35:13 +00:00
|
|
|
client_p->localClient->target_last = rb_current_time(); /* don't ask --nenolod */
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
else if (client_p->localClient->receiveM > hurt_state.cutoff)
|
|
|
|
exit_client(NULL, client_p, &me, hurt_state.exit_reason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ static void hurt_expire_event() */
|
|
|
|
static void
|
|
|
|
hurt_expire_event(void *unused)
|
|
|
|
{
|
2008-04-01 23:48:21 +00:00
|
|
|
rb_dlink_node *ptr, *next_ptr;
|
2007-01-25 06:40:21 +00:00
|
|
|
hurt_t *hurt;
|
|
|
|
|
2008-04-01 23:48:21 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_confs.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
hurt = (hurt_t *) ptr->data;
|
|
|
|
|
2008-04-02 00:35:13 +00:00
|
|
|
if (hurt->expire <= rb_current_time())
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
2008-04-01 23:48:21 +00:00
|
|
|
rb_dlinkFindDestroy(hurt, &hurt_confs);
|
2007-01-25 06:40:21 +00:00
|
|
|
hurt_destroy(hurt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hook functions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* {{{ static void client_exit_hook() */
|
|
|
|
static void
|
2021-08-20 03:09:40 +00:00
|
|
|
client_exit_hook(void *data_)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
2021-08-20 03:09:40 +00:00
|
|
|
hook_data_client_exit *data = data_;
|
2007-01-25 06:40:21 +00:00
|
|
|
s_assert(data != NULL);
|
|
|
|
s_assert(data->target != NULL);
|
|
|
|
|
2008-04-01 23:48:21 +00:00
|
|
|
rb_dlinkFindDestroy(data->target, &hurt_state.hurt_clients);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ static void new_local_user_hook() */
|
|
|
|
static void
|
2021-08-20 03:09:40 +00:00
|
|
|
new_local_user_hook(void *data)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
2021-08-20 03:09:40 +00:00
|
|
|
struct Client *source_p = data;
|
2007-01-25 06:40:21 +00:00
|
|
|
if (IsAnyDead(source_p) || !EmptyString(source_p->user->suser) ||
|
|
|
|
IsExemptKline(source_p))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (hurt_find(source_p->sockhost) || hurt_find(source_p->orighost))
|
|
|
|
{
|
2008-04-02 00:35:13 +00:00
|
|
|
source_p->localClient->target_last = rb_current_time() + 600; /* don't ask --nenolod */
|
2007-01-25 06:40:21 +00:00
|
|
|
SetTGChange(source_p);
|
2008-04-01 23:48:21 +00:00
|
|
|
rb_dlinkAddAlloc(source_p, &hurt_state.hurt_clients);
|
2007-01-25 06:40:21 +00:00
|
|
|
sendto_one_notice(source_p, ":You are hurt. Please identify to services immediately, or use /stats p for assistance.");
|
2014-03-03 04:25:47 +00:00
|
|
|
}
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ static void doing_stats_hook() */
|
|
|
|
static void
|
2021-08-20 03:09:40 +00:00
|
|
|
doing_stats_hook(void *data)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
2021-08-20 03:09:40 +00:00
|
|
|
hook_data_int *hdata = data;
|
2008-04-01 23:48:21 +00:00
|
|
|
rb_dlink_node *ptr;
|
2007-01-25 06:40:21 +00:00
|
|
|
hurt_t *hurt;
|
|
|
|
struct Client *source_p;
|
|
|
|
|
|
|
|
s_assert(hdata);
|
|
|
|
s_assert(hdata->client);
|
|
|
|
|
|
|
|
source_p = hdata->client;
|
|
|
|
if(hdata->arg2 != (int) 's')
|
|
|
|
return;
|
2019-07-07 04:34:28 +00:00
|
|
|
if((ConfigFileEntry.stats_k_oper_only == 2) && !IsOperGeneral(source_p))
|
2007-01-25 06:40:21 +00:00
|
|
|
return;
|
2019-07-07 04:34:28 +00:00
|
|
|
if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOperGeneral(source_p))
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
hurt = hurt_find(source_p->sockhost);
|
|
|
|
if (hurt != NULL)
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, RPL_STATSKLINE,
|
|
|
|
form_str(RPL_STATSKLINE), 's',
|
|
|
|
"*", hurt->ip, hurt->reason, "", "");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hurt = hurt_find(source_p->orighost);
|
|
|
|
if (hurt != NULL)
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, RPL_STATSKLINE,
|
|
|
|
form_str(RPL_STATSKLINE), 's',
|
|
|
|
"*", hurt->ip, hurt->reason, "", "");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-01 23:48:21 +00:00
|
|
|
RB_DLINK_FOREACH(ptr, hurt_confs.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
hurt = (hurt_t *) ptr->data;
|
|
|
|
sendto_one_numeric(source_p, RPL_STATSKLINE,
|
|
|
|
form_str(RPL_STATSKLINE), 's',
|
|
|
|
"*", hurt->ip, hurt->reason, "", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ static void hurt_propagate()
|
|
|
|
*
|
|
|
|
* client_p - specific server to propagate HURT to, or NULL to propagate to all
|
|
|
|
* servers.
|
|
|
|
* source_p - source (oper who added the HURT)
|
|
|
|
* hurt - HURT to be propagated
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
hurt_propagate(struct Client *client_p, struct Client *source_p, hurt_t *hurt)
|
|
|
|
{
|
|
|
|
if (client_p)
|
|
|
|
sendto_one(client_p,
|
|
|
|
":%s ENCAP %s HURT %ld %s :%s",
|
|
|
|
source_p->name, client_p->name,
|
2008-04-02 00:35:13 +00:00
|
|
|
(long)(hurt->expire - rb_current_time()),
|
2007-01-25 06:40:21 +00:00
|
|
|
hurt->ip, hurt->reason);
|
|
|
|
else
|
|
|
|
sendto_server(&me, NULL, NOCAPS, NOCAPS,
|
|
|
|
":%s ENCAP * HURT %ld %s :%s",
|
|
|
|
source_p->name,
|
2008-04-02 00:35:13 +00:00
|
|
|
(long)(hurt->expire - rb_current_time()),
|
2007-01-25 06:40:21 +00:00
|
|
|
hurt->ip, hurt->reason);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ static hurt_t *hurt_new() */
|
|
|
|
static hurt_t *
|
|
|
|
hurt_new(time_t expire, const char *ip, const char *reason)
|
|
|
|
{
|
|
|
|
hurt_t *hurt;
|
|
|
|
|
2008-04-01 23:49:56 +00:00
|
|
|
hurt = rb_malloc(sizeof(hurt_t));
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-01 23:49:56 +00:00
|
|
|
hurt->ip = rb_strdup(ip);
|
|
|
|
hurt->reason = rb_strdup(reason);
|
2008-04-02 00:35:13 +00:00
|
|
|
hurt->expire = rb_current_time() + expire;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
return hurt;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ static void hurt_destroy() */
|
|
|
|
static void
|
|
|
|
hurt_destroy(void *hurt)
|
|
|
|
{
|
|
|
|
hurt_t *h;
|
|
|
|
|
|
|
|
if (!hurt)
|
|
|
|
return;
|
|
|
|
|
|
|
|
h = (hurt_t *) hurt;
|
2008-04-01 23:49:56 +00:00
|
|
|
rb_free(h->ip);
|
|
|
|
rb_free(h->reason);
|
|
|
|
rb_free(h);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
static void
|
|
|
|
hurt_add(hurt_t *hurt)
|
|
|
|
{
|
2008-04-01 23:48:21 +00:00
|
|
|
rb_dlinkAddAlloc(hurt, &hurt_confs);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static hurt_t *
|
|
|
|
hurt_find_exact(const char *ip)
|
|
|
|
{
|
2008-04-01 23:48:21 +00:00
|
|
|
rb_dlink_node *ptr;
|
2007-01-25 06:40:21 +00:00
|
|
|
hurt_t *hurt;
|
|
|
|
|
2008-04-01 23:48:21 +00:00
|
|
|
RB_DLINK_FOREACH(ptr, hurt_confs.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
hurt = (hurt_t *) ptr->data;
|
|
|
|
|
2016-04-05 10:39:59 +00:00
|
|
|
if (!rb_strcasecmp(ip, hurt->ip))
|
2007-01-25 06:40:21 +00:00
|
|
|
return hurt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static hurt_t *
|
|
|
|
hurt_find(const char *ip)
|
|
|
|
{
|
2008-04-01 23:48:21 +00:00
|
|
|
rb_dlink_node *ptr;
|
2007-01-25 06:40:21 +00:00
|
|
|
hurt_t *hurt;
|
|
|
|
|
2008-04-01 23:48:21 +00:00
|
|
|
RB_DLINK_FOREACH(ptr, hurt_confs.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
hurt = (hurt_t *) ptr->data;
|
|
|
|
|
|
|
|
if (match(hurt->ip, ip))
|
|
|
|
return hurt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
hurt_remove(const char *ip)
|
|
|
|
{
|
|
|
|
hurt_t *hurt = hurt_find_exact(ip);
|
|
|
|
|
2008-04-01 23:48:21 +00:00
|
|
|
rb_dlinkFindDestroy(hurt, &hurt_confs);
|
2007-01-25 06:40:21 +00:00
|
|
|
hurt_destroy(hurt);
|
|
|
|
}
|
|
|
|
|
2016-03-09 07:37:03 +00:00
|
|
|
/* {{{ static void heal_nick() */
|
|
|
|
static void
|
2007-01-25 06:40:21 +00:00
|
|
|
heal_nick(struct Client *source_p, struct Client *target_p)
|
|
|
|
{
|
2008-04-01 23:48:21 +00:00
|
|
|
if (rb_dlinkFindDestroy(target_p, &hurt_state.hurt_clients))
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
2020-11-08 19:30:41 +00:00
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s used HEAL on %s",
|
2007-01-25 06:40:21 +00:00
|
|
|
get_oper_name(source_p), get_client_name(target_p, HIDE_IP));
|
|
|
|
sendto_one_notice(target_p, ":HURT restriction temporarily removed by operator");
|
|
|
|
sendto_one_notice(source_p, ":HURT restriction on %s temporarily removed", target_p->name);
|
2008-04-02 00:35:13 +00:00
|
|
|
target_p->localClient->target_last = rb_current_time(); /* don't ask --nenolod */
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":%s was not hurt", target_p->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* vim: ts=8 sw=8 noet fdm=marker tw=80
|
|
|
|
*/
|