2010-12-07 05:44:55 +00:00
|
|
|
/*
|
2020-10-15 14:51:12 +00:00
|
|
|
* oper-override for solanum.
|
2010-12-07 05:44:55 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdinc.h"
|
|
|
|
#include "modules.h"
|
|
|
|
#include "hook.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "ircd.h"
|
|
|
|
#include "send.h"
|
|
|
|
#include "hash.h"
|
|
|
|
#include "s_conf.h"
|
|
|
|
#include "s_user.h"
|
|
|
|
#include "s_serv.h"
|
|
|
|
#include "numeric.h"
|
|
|
|
#include "privilege.h"
|
|
|
|
#include "s_newconf.h"
|
|
|
|
|
2016-03-07 09:50:03 +00: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 05:44:55 +00:00
|
|
|
static void check_umode_change(void *data);
|
|
|
|
static void hack_channel_access(void *data);
|
2010-12-07 05:55:42 +00:00
|
|
|
static void hack_can_join(void *data);
|
2016-01-16 08:04:01 +00:00
|
|
|
static void hack_can_kick(void *data);
|
2010-12-07 06:18:22 +00:00
|
|
|
static void hack_can_send(void *data);
|
2010-12-07 06:27:00 +00:00
|
|
|
static void handle_client_exit(void *data);
|
2010-12-07 05:44:55 +00:00
|
|
|
|
|
|
|
mapi_hfn_list_av1 override_hfnlist[] = {
|
|
|
|
{ "umode_changed", (hookfn) check_umode_change },
|
2020-04-26 23:42:53 +00:00
|
|
|
{ "get_channel_access", (hookfn) hack_channel_access, HOOK_HIGHEST },
|
|
|
|
{ "can_join", (hookfn) hack_can_join, HOOK_HIGHEST },
|
|
|
|
{ "can_kick", (hookfn) hack_can_kick, HOOK_HIGHEST },
|
|
|
|
{ "can_send", (hookfn) hack_can_send, HOOK_HIGHEST },
|
2010-12-07 06:27:00 +00:00
|
|
|
{ "client_exit", (hookfn) handle_client_exit },
|
2010-12-07 05:44:55 +00:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2016-01-16 08:04:01 +00:00
|
|
|
#define CHFL_OVERRIDE 0x0004
|
2010-12-07 05:44:55 +00:00
|
|
|
#define IsOperOverride(x) (HasPrivilege((x), "oper:override"))
|
|
|
|
|
|
|
|
struct OverrideSession {
|
|
|
|
rb_dlink_node node;
|
|
|
|
|
|
|
|
struct Client *client;
|
|
|
|
time_t deadline;
|
|
|
|
};
|
|
|
|
|
|
|
|
rb_dlink_list overriding_opers = { NULL, NULL, 0 };
|
|
|
|
|
|
|
|
static void
|
2021-04-26 16:31:26 +00:00
|
|
|
update_session_deadline(struct Client *source_p)
|
2010-12-07 05:44:55 +00:00
|
|
|
{
|
2021-04-26 16:31:26 +00:00
|
|
|
struct OverrideSession *session_p = NULL;
|
|
|
|
rb_dlink_node *n;
|
|
|
|
|
|
|
|
RB_DLINK_FOREACH(n, overriding_opers.head)
|
2010-12-07 05:44:55 +00:00
|
|
|
{
|
2021-04-26 16:31:26 +00:00
|
|
|
struct OverrideSession *s = n->data;
|
2010-12-07 05:44:55 +00:00
|
|
|
|
2021-04-26 16:31:26 +00:00
|
|
|
if (s->client == source_p)
|
2010-12-07 05:44:55 +00:00
|
|
|
{
|
2021-04-26 16:31:26 +00:00
|
|
|
session_p = s;
|
|
|
|
break;
|
2010-12-07 05:44:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-26 00:26:43 +00:00
|
|
|
if (session_p != NULL)
|
|
|
|
{
|
|
|
|
rb_dlinkDelete(&session_p->node, &overriding_opers);
|
|
|
|
}
|
|
|
|
else
|
2010-12-07 05:44:55 +00:00
|
|
|
{
|
|
|
|
session_p = rb_malloc(sizeof(struct OverrideSession));
|
|
|
|
session_p->client = source_p;
|
|
|
|
}
|
|
|
|
|
|
|
|
session_p->deadline = rb_current_time() + 1800;
|
|
|
|
|
2021-04-26 00:26:43 +00:00
|
|
|
rb_dlinkAddTail(session_p, &session_p->node, &overriding_opers);
|
2010-12-07 05:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
expire_override_deadlines(void *unused)
|
|
|
|
{
|
|
|
|
rb_dlink_node *n, *tn;
|
|
|
|
|
|
|
|
RB_DLINK_FOREACH_SAFE(n, tn, overriding_opers.head)
|
|
|
|
{
|
|
|
|
struct OverrideSession *session_p = n->data;
|
|
|
|
|
2021-04-26 00:26:43 +00:00
|
|
|
if (session_p->deadline >= rb_current_time())
|
|
|
|
{
|
2010-12-07 05:44:55 +00:00
|
|
|
break;
|
2021-04-26 00:26:43 +00:00
|
|
|
}
|
|
|
|
else
|
2010-12-07 05:44:55 +00:00
|
|
|
{
|
2016-09-28 22:34:53 +00:00
|
|
|
const char *parv[4] = {session_p->client->name, session_p->client->name, "-p", NULL};
|
2010-12-07 05:44:55 +00:00
|
|
|
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;
|
2019-07-27 12:50:53 +00:00
|
|
|
bool changed = false;
|
2010-12-07 05:44:55 +00:00
|
|
|
struct Client *source_p = data->client;
|
|
|
|
|
|
|
|
if (!MyClient(source_p))
|
|
|
|
return;
|
|
|
|
|
2013-10-25 15:49:58 +00:00
|
|
|
if (data->oldumodes & UMODE_OPER && !IsOper(source_p))
|
|
|
|
source_p->umodes &= ~user_modes['p'];
|
|
|
|
|
2019-07-27 12:50:53 +00:00
|
|
|
changed = ((data->oldumodes ^ source_p->umodes) & user_modes['p']);
|
2010-12-07 05:44:55 +00:00
|
|
|
|
|
|
|
if (source_p->umodes & user_modes['p'])
|
|
|
|
{
|
2013-10-25 15:49:58 +00:00
|
|
|
if (!IsOperOverride(source_p))
|
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":*** You need oper:override privilege for +p");
|
|
|
|
source_p->umodes &= ~user_modes['p'];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-27 12:50:53 +00:00
|
|
|
if (changed)
|
|
|
|
{
|
2021-04-26 16:31:26 +00:00
|
|
|
update_session_deadline(source_p);
|
2019-07-27 12:50:53 +00:00
|
|
|
}
|
2010-12-07 05:44:55 +00:00
|
|
|
}
|
2019-07-27 12:50:53 +00:00
|
|
|
else if (changed && !(source_p->umodes & user_modes['p']))
|
2010-12-07 05:44:55 +00:00
|
|
|
{
|
|
|
|
rb_dlink_node *n, *tn;
|
|
|
|
|
|
|
|
RB_DLINK_FOREACH_SAFE(n, tn, overriding_opers.head)
|
|
|
|
{
|
|
|
|
struct OverrideSession *session_p = n->data;
|
|
|
|
|
|
|
|
if (session_p->client != source_p)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
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 07:00:32 +00:00
|
|
|
if (data->dir == MODE_QUERY)
|
|
|
|
return;
|
|
|
|
|
2010-12-07 05:44:55 +00:00
|
|
|
if (data->approved == CHFL_CHANOP)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (data->client->umodes & user_modes['p'])
|
|
|
|
{
|
2021-04-26 16:31:26 +00:00
|
|
|
update_session_deadline(data->client);
|
2016-01-16 08:04:01 +00:00
|
|
|
data->approved = CHFL_OVERRIDE;
|
2010-12-07 05:44:55 +00:00
|
|
|
|
2016-01-12 04:40:32 +00:00
|
|
|
/* we only want to report modehacks, which are always non-NULL */
|
|
|
|
if (data->modestr)
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is using oper-override on %s (modehacking: %s)",
|
|
|
|
get_oper_name(data->client), data->chptr->chname, data->modestr);
|
2010-12-07 05:44:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-07 05:55:42 +00:00
|
|
|
static void
|
|
|
|
hack_can_join(void *vdata)
|
|
|
|
{
|
|
|
|
hook_data_channel *data = (hook_data_channel *) vdata;
|
|
|
|
|
|
|
|
if (data->approved == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (data->client->umodes & user_modes['p'])
|
|
|
|
{
|
2021-04-26 16:31:26 +00:00
|
|
|
update_session_deadline(data->client);
|
2010-12-07 05:55:42 +00:00
|
|
|
data->approved = 0;
|
|
|
|
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is using oper-override on %s (banwalking)",
|
|
|
|
get_oper_name(data->client), data->chptr->chname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-16 08:04:01 +00:00
|
|
|
static void
|
|
|
|
hack_can_kick(void *vdata)
|
|
|
|
{
|
|
|
|
hook_data_channel_approval *data = (hook_data_channel_approval *) vdata;
|
|
|
|
int alevel;
|
|
|
|
|
2016-01-16 08:28:49 +00:00
|
|
|
alevel = get_channel_access(data->client, data->chptr, data->msptr, data->dir, NULL);
|
2016-01-16 08:04:01 +00:00
|
|
|
if (alevel != CHFL_OVERRIDE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (data->client->umodes & user_modes['p'])
|
|
|
|
{
|
2021-04-26 16:31:26 +00:00
|
|
|
update_session_deadline(data->client);
|
2016-01-16 08:04:01 +00:00
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is using oper-override on %s (KICK %s)",
|
|
|
|
get_oper_name(data->client), data->chptr->chname, data->target->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-07 06:18:22 +00:00
|
|
|
static void
|
|
|
|
hack_can_send(void *vdata)
|
|
|
|
{
|
|
|
|
hook_data_channel_approval *data = (hook_data_channel_approval *) vdata;
|
|
|
|
|
2015-12-10 07:00:32 +00:00
|
|
|
if (data->dir == MODE_QUERY)
|
|
|
|
return;
|
|
|
|
|
2010-12-07 06:18:22 +00:00
|
|
|
if (data->approved == CAN_SEND_NONOP || data->approved == CAN_SEND_OPV)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (data->client->umodes & user_modes['p'])
|
|
|
|
{
|
2011-02-06 14:50:58 +00:00
|
|
|
data->approved = CAN_SEND_NONOP;
|
2010-12-07 06:18:22 +00:00
|
|
|
|
2011-08-07 20:10:12 +00:00
|
|
|
if (MyClient(data->client))
|
|
|
|
{
|
2021-04-26 16:31:26 +00:00
|
|
|
update_session_deadline(data->client);
|
2011-08-07 20:10:12 +00:00
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is using oper-override on %s (forcing message)",
|
|
|
|
get_oper_name(data->client), data->chptr->chname);
|
|
|
|
}
|
2010-12-07 06:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-07 06:27:00 +00:00
|
|
|
static void
|
|
|
|
handle_client_exit(void *vdata)
|
|
|
|
{
|
|
|
|
hook_data_client_exit *data = (hook_data_client_exit *) vdata;
|
|
|
|
rb_dlink_node *n, *tn;
|
|
|
|
struct Client *source_p = data->target;
|
|
|
|
|
|
|
|
RB_DLINK_FOREACH_SAFE(n, tn, overriding_opers.head)
|
|
|
|
{
|
|
|
|
struct OverrideSession *session_p = n->data;
|
|
|
|
|
|
|
|
if (session_p->client != source_p)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rb_dlinkDelete(n, &overriding_opers);
|
|
|
|
rb_free(session_p);
|
2014-03-03 04:25:47 +00:00
|
|
|
}
|
2010-12-07 06:27:00 +00:00
|
|
|
}
|
|
|
|
|
2010-12-07 05:44:55 +00:00
|
|
|
struct ev_entry *expire_override_deadlines_ev = NULL;
|
|
|
|
|
|
|
|
static int
|
|
|
|
_modinit(void)
|
|
|
|
{
|
2019-07-27 00:48:36 +00:00
|
|
|
rb_dlink_node *ptr;
|
|
|
|
|
2010-12-07 05:44:55 +00:00
|
|
|
/* add the usermode to the available slot */
|
|
|
|
user_modes['p'] = find_umode_slot();
|
|
|
|
construct_umodebuf();
|
|
|
|
|
2019-07-27 00:48:36 +00:00
|
|
|
RB_DLINK_FOREACH(ptr, lclient_list.head)
|
|
|
|
{
|
|
|
|
struct Client *client_p = ptr->data;
|
|
|
|
if (IsPerson(client_p) && (client_p->umodes & user_modes['p']))
|
2021-04-26 16:31:26 +00:00
|
|
|
update_session_deadline(client_p);
|
2019-07-27 00:48:36 +00:00
|
|
|
}
|
|
|
|
|
2016-09-28 22:34:53 +00:00
|
|
|
expire_override_deadlines_ev = rb_event_add("expire_override_deadlines", expire_override_deadlines, NULL, 60);
|
2010-12-07 05:44:55 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_moddeinit(void)
|
|
|
|
{
|
2019-07-27 00:59:28 +00:00
|
|
|
rb_dlink_node *n, *tn;
|
|
|
|
|
2010-12-07 05:44:55 +00:00
|
|
|
/* disable the umode and remove it from the available list */
|
|
|
|
user_modes['p'] = 0;
|
|
|
|
construct_umodebuf();
|
|
|
|
|
2019-07-27 00:59:28 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(n, tn, overriding_opers.head)
|
|
|
|
{
|
|
|
|
rb_dlinkDelete(n, &overriding_opers);
|
|
|
|
rb_free(n->data);
|
|
|
|
}
|
|
|
|
|
2010-12-07 05:44:55 +00:00
|
|
|
rb_event_delete(expire_override_deadlines_ev);
|
|
|
|
}
|
|
|
|
|
2016-03-07 09:50:03 +00:00
|
|
|
DECLARE_MODULE_AV2(override, _modinit, _moddeinit, NULL, NULL,
|
|
|
|
override_hfnlist, NULL, NULL, override_desc);
|