2010-12-07 06:44:55 +01:00
|
|
|
/*
|
|
|
|
* oper-override for charybdis.
|
|
|
|
*
|
|
|
|
* adds usermode +p and has a timer event that is iterated over to disable
|
|
|
|
* usermode +p after a while...
|
|
|
|
*
|
|
|
|
* you need to have oper:override permission on the opers you want to be
|
|
|
|
* able to use this extension.
|
|
|
|
*/
|
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
using namespace ircd;
|
|
|
|
|
2016-03-07 10:50:03 +01:00
|
|
|
static const char override_desc[] =
|
|
|
|
"Adds user mode +p, an operator-only user mode that grants temporary privileges to override anything";
|
|
|
|
|
2010-12-07 06:44:55 +01:00
|
|
|
static void check_umode_change(void *data);
|
|
|
|
static void hack_channel_access(void *data);
|
2010-12-07 06:55:42 +01:00
|
|
|
static void hack_can_join(void *data);
|
2016-01-16 09:04:01 +01:00
|
|
|
static void hack_can_kick(void *data);
|
2010-12-07 07:18:22 +01:00
|
|
|
static void hack_can_send(void *data);
|
2010-12-07 07:27:00 +01:00
|
|
|
static void handle_client_exit(void *data);
|
2010-12-07 06:44:55 +01:00
|
|
|
|
|
|
|
mapi_hfn_list_av1 override_hfnlist[] = {
|
|
|
|
{ "umode_changed", (hookfn) check_umode_change },
|
|
|
|
{ "get_channel_access", (hookfn) hack_channel_access },
|
2010-12-07 06:55:42 +01:00
|
|
|
{ "can_join", (hookfn) hack_can_join },
|
2016-01-16 09:04:01 +01:00
|
|
|
{ "can_kick", (hookfn) hack_can_kick },
|
2010-12-07 07:18:22 +01:00
|
|
|
{ "can_send", (hookfn) hack_can_send },
|
2010-12-07 07:27:00 +01:00
|
|
|
{ "client_exit", (hookfn) handle_client_exit },
|
2010-12-07 06:44:55 +01:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2016-08-28 06:52:31 +02:00
|
|
|
umode::mode UMODE_OVERRIDE { 'p' };
|
|
|
|
|
2016-01-16 09:04:01 +01:00
|
|
|
#define CHFL_OVERRIDE 0x0004
|
2010-12-07 06:44:55 +01:00
|
|
|
#define IsOperOverride(x) (HasPrivilege((x), "oper:override"))
|
|
|
|
|
|
|
|
struct OverrideSession {
|
|
|
|
rb_dlink_node node;
|
|
|
|
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *client;
|
2010-12-07 06:44:55 +01:00
|
|
|
time_t deadline;
|
|
|
|
};
|
|
|
|
|
|
|
|
rb_dlink_list overriding_opers = { NULL, NULL, 0 };
|
|
|
|
|
|
|
|
static void
|
2016-08-22 03:57:43 +02:00
|
|
|
update_session_deadline(client::client *source_p, struct OverrideSession *session_p)
|
2010-12-07 06:44:55 +01:00
|
|
|
{
|
|
|
|
if (session_p == NULL)
|
|
|
|
{
|
|
|
|
rb_dlink_node *n;
|
|
|
|
|
|
|
|
RB_DLINK_FOREACH(n, overriding_opers.head)
|
|
|
|
{
|
2016-07-13 07:17:21 +02:00
|
|
|
struct OverrideSession *s = (OverrideSession *)n->data;
|
2010-12-07 06:44:55 +01:00
|
|
|
|
|
|
|
if (s->client == source_p)
|
|
|
|
{
|
|
|
|
session_p = s;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (session_p == NULL)
|
|
|
|
{
|
2016-07-13 07:17:21 +02:00
|
|
|
session_p = (OverrideSession *)rb_malloc(sizeof(struct OverrideSession));
|
2010-12-07 06:44:55 +01:00
|
|
|
session_p->client = source_p;
|
|
|
|
}
|
|
|
|
|
|
|
|
session_p->deadline = rb_current_time() + 1800;
|
|
|
|
|
|
|
|
rb_dlinkDelete(&session_p->node, &overriding_opers);
|
|
|
|
rb_dlinkAdd(session_p, &session_p->node, &overriding_opers);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
expire_override_deadlines(void *unused)
|
|
|
|
{
|
|
|
|
rb_dlink_node *n, *tn;
|
|
|
|
|
|
|
|
RB_DLINK_FOREACH_SAFE(n, tn, overriding_opers.head)
|
|
|
|
{
|
2016-07-13 07:17:21 +02:00
|
|
|
struct OverrideSession *session_p = (OverrideSession *)n->data;
|
2010-12-07 06:44:55 +01:00
|
|
|
|
|
|
|
if (session_p->deadline > rb_current_time())
|
|
|
|
break;
|
|
|
|
else if (session_p->deadline < rb_current_time())
|
|
|
|
{
|
|
|
|
const char *parv[4] = {session_p->client->name, session_p->client->name, "-p", NULL};
|
|
|
|
user_mode(session_p->client, session_p->client, 3, parv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
check_umode_change(void *vdata)
|
|
|
|
{
|
|
|
|
hook_data_umode_changed *data = (hook_data_umode_changed *)vdata;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *source_p = data->client;
|
2010-12-07 06:44:55 +01:00
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if (!my(*source_p))
|
2010-12-07 06:44:55 +01:00
|
|
|
return;
|
|
|
|
|
2016-08-24 00:25:09 +02:00
|
|
|
if (data->oldumodes & umode::OPER && !is(*source_p, umode::OPER))
|
2016-08-28 06:52:31 +02:00
|
|
|
source_p->mode &= ~UMODE_OVERRIDE;
|
2013-10-25 17:49:58 +02:00
|
|
|
|
2010-12-07 06:44:55 +01:00
|
|
|
/* didn't change +p umode, we don't need to do anything */
|
2016-08-28 06:52:31 +02:00
|
|
|
if (!((data->oldumodes ^ source_p->mode) & UMODE_OVERRIDE))
|
2010-12-07 06:44:55 +01:00
|
|
|
return;
|
|
|
|
|
2016-08-28 06:52:31 +02:00
|
|
|
if (source_p->mode & UMODE_OVERRIDE)
|
2010-12-07 06:44:55 +01:00
|
|
|
{
|
2013-10-25 17:49:58 +02:00
|
|
|
if (!IsOperOverride(source_p))
|
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":*** You need oper:override privilege for +p");
|
2016-08-28 06:52:31 +02:00
|
|
|
source_p->mode &= ~UMODE_OVERRIDE;
|
2013-10-25 17:49:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-07 06:44:55 +01:00
|
|
|
update_session_deadline(source_p, NULL);
|
|
|
|
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_NETWIDE, "%s has enabled oper-override (+p)",
|
2010-12-07 06:44:55 +01:00
|
|
|
get_oper_name(source_p));
|
|
|
|
}
|
2016-08-28 06:52:31 +02:00
|
|
|
else if (!(source_p->mode & UMODE_OVERRIDE))
|
2010-12-07 06:44:55 +01:00
|
|
|
{
|
|
|
|
rb_dlink_node *n, *tn;
|
|
|
|
|
|
|
|
RB_DLINK_FOREACH_SAFE(n, tn, overriding_opers.head)
|
|
|
|
{
|
2016-07-13 07:17:21 +02:00
|
|
|
struct OverrideSession *session_p = (OverrideSession *)n->data;
|
2010-12-07 06:44:55 +01:00
|
|
|
|
|
|
|
if (session_p->client != source_p)
|
|
|
|
continue;
|
|
|
|
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_NETWIDE, "%s has disabled oper-override (+p)",
|
2010-12-07 06:44:55 +01:00
|
|
|
get_oper_name(session_p->client));
|
|
|
|
|
|
|
|
rb_dlinkDelete(n, &overriding_opers);
|
|
|
|
rb_free(session_p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
hack_channel_access(void *vdata)
|
|
|
|
{
|
|
|
|
hook_data_channel_approval *data = (hook_data_channel_approval *) vdata;
|
|
|
|
|
2015-12-10 08:00:32 +01:00
|
|
|
if (data->dir == MODE_QUERY)
|
|
|
|
return;
|
|
|
|
|
2016-08-18 07:33:38 +02:00
|
|
|
if (data->approved == chan::CHANOP)
|
2010-12-07 06:44:55 +01:00
|
|
|
return;
|
|
|
|
|
2016-08-28 06:52:31 +02:00
|
|
|
if (data->client->mode & UMODE_OVERRIDE)
|
2010-12-07 06:44:55 +01:00
|
|
|
{
|
|
|
|
update_session_deadline(data->client, NULL);
|
2016-01-16 09:04:01 +01:00
|
|
|
data->approved = CHFL_OVERRIDE;
|
2010-12-07 06:44:55 +01:00
|
|
|
|
2016-01-12 05:40:32 +01:00
|
|
|
/* we only want to report modehacks, which are always non-NULL */
|
|
|
|
if (data->modestr)
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_NETWIDE, "%s is using oper-override on %s (modehacking: %s)",
|
2016-08-18 07:33:38 +02:00
|
|
|
get_oper_name(data->client), data->chptr->name.c_str(), data->modestr);
|
2010-12-07 06:44:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-07 06:55:42 +01:00
|
|
|
static void
|
|
|
|
hack_can_join(void *vdata)
|
|
|
|
{
|
|
|
|
hook_data_channel *data = (hook_data_channel *) vdata;
|
|
|
|
|
|
|
|
if (data->approved == 0)
|
|
|
|
return;
|
|
|
|
|
2016-08-28 06:52:31 +02:00
|
|
|
if (data->client->mode & UMODE_OVERRIDE)
|
2010-12-07 06:55:42 +01:00
|
|
|
{
|
|
|
|
update_session_deadline(data->client, NULL);
|
|
|
|
data->approved = 0;
|
|
|
|
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_NETWIDE, "%s is using oper-override on %s (banwalking)",
|
2016-08-18 07:33:38 +02:00
|
|
|
get_oper_name(data->client), data->chptr->name.c_str());
|
2010-12-07 06:55:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-16 09:04:01 +01:00
|
|
|
static void
|
|
|
|
hack_can_kick(void *vdata)
|
|
|
|
{
|
|
|
|
hook_data_channel_approval *data = (hook_data_channel_approval *) vdata;
|
|
|
|
int alevel;
|
|
|
|
|
2016-01-16 09:28:49 +01:00
|
|
|
alevel = get_channel_access(data->client, data->chptr, data->msptr, data->dir, NULL);
|
2016-01-16 09:04:01 +01:00
|
|
|
if (alevel != CHFL_OVERRIDE)
|
|
|
|
return;
|
|
|
|
|
2016-08-28 06:52:31 +02:00
|
|
|
if (data->client->mode & UMODE_OVERRIDE)
|
2016-01-16 09:04:01 +01:00
|
|
|
{
|
|
|
|
update_session_deadline(data->client, NULL);
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_NETWIDE, "%s is using oper-override on %s (KICK %s)",
|
2016-08-18 07:33:38 +02:00
|
|
|
get_oper_name(data->client), data->chptr->name.c_str(), data->target->name);
|
2016-01-16 09:04:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-07 07:18:22 +01:00
|
|
|
static void
|
|
|
|
hack_can_send(void *vdata)
|
|
|
|
{
|
|
|
|
hook_data_channel_approval *data = (hook_data_channel_approval *) vdata;
|
|
|
|
|
2015-12-10 08:00:32 +01:00
|
|
|
if (data->dir == MODE_QUERY)
|
|
|
|
return;
|
|
|
|
|
2016-08-18 07:33:38 +02:00
|
|
|
if (data->approved == chan::CAN_SEND_NONOP || data->approved == chan::CAN_SEND_OPV)
|
2010-12-07 07:18:22 +01:00
|
|
|
return;
|
|
|
|
|
2016-08-28 06:52:31 +02:00
|
|
|
if (data->client->mode & UMODE_OVERRIDE)
|
2010-12-07 07:18:22 +01:00
|
|
|
{
|
2016-08-18 07:33:38 +02:00
|
|
|
data->approved = chan::CAN_SEND_NONOP;
|
2010-12-07 07:18:22 +01:00
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if (my(*data->client))
|
2011-08-07 22:10:12 +02:00
|
|
|
{
|
|
|
|
update_session_deadline(data->client, NULL);
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_NETWIDE, "%s is using oper-override on %s (forcing message)",
|
2016-08-18 07:33:38 +02:00
|
|
|
get_oper_name(data->client), data->chptr->name.c_str());
|
2011-08-07 22:10:12 +02:00
|
|
|
}
|
2010-12-07 07:18:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-07 07:27:00 +01:00
|
|
|
static void
|
|
|
|
handle_client_exit(void *vdata)
|
|
|
|
{
|
|
|
|
hook_data_client_exit *data = (hook_data_client_exit *) vdata;
|
|
|
|
rb_dlink_node *n, *tn;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *source_p = data->target;
|
2010-12-07 07:27:00 +01:00
|
|
|
|
|
|
|
RB_DLINK_FOREACH_SAFE(n, tn, overriding_opers.head)
|
|
|
|
{
|
2016-07-13 07:17:21 +02:00
|
|
|
struct OverrideSession *session_p = (OverrideSession *)n->data;
|
2010-12-07 07:27:00 +01:00
|
|
|
|
|
|
|
if (session_p->client != source_p)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rb_dlinkDelete(n, &overriding_opers);
|
|
|
|
rb_free(session_p);
|
2014-03-03 05:25:47 +01:00
|
|
|
}
|
2010-12-07 07:27:00 +01:00
|
|
|
}
|
|
|
|
|
2010-12-07 06:44:55 +01:00
|
|
|
struct ev_entry *expire_override_deadlines_ev = NULL;
|
|
|
|
|
|
|
|
static int
|
|
|
|
_modinit(void)
|
|
|
|
{
|
2016-08-28 06:52:31 +02:00
|
|
|
expire_override_deadlines_ev = rb_event_add("expire_override_deadlines", expire_override_deadlines, NULL, 60);
|
2010-12-07 06:44:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_moddeinit(void)
|
|
|
|
{
|
|
|
|
rb_event_delete(expire_override_deadlines_ev);
|
|
|
|
}
|
|
|
|
|
2016-03-07 10:50:03 +01:00
|
|
|
DECLARE_MODULE_AV2(override, _modinit, _moddeinit, NULL, NULL,
|
|
|
|
override_hfnlist, NULL, NULL, override_desc);
|