From cc75db3f3f0d2968fa1ae5f59403af61abb41094 Mon Sep 17 00:00:00 2001 From: Ed Kellett Date: Sat, 27 Jul 2019 01:48:36 +0100 Subject: [PATCH 1/3] override: start timers for +p clients on modinit Reloading override previously would have the effect of cancelling +p expiry. With this change, reloading the module just refreshes the timers, so expiry is delayed a bit rather than forgotten entirely. --- extensions/override.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/extensions/override.c b/extensions/override.c index 68c56d01..4e7667b1 100644 --- a/extensions/override.c +++ b/extensions/override.c @@ -288,10 +288,19 @@ struct ev_entry *expire_override_deadlines_ev = NULL; static int _modinit(void) { + rb_dlink_node *ptr; + /* add the usermode to the available slot */ user_modes['p'] = find_umode_slot(); construct_umodebuf(); + RB_DLINK_FOREACH(ptr, lclient_list.head) + { + struct Client *client_p = ptr->data; + if (IsPerson(client_p) && (client_p->umodes & user_modes['p'])) + update_session_deadline(client_p, NULL); + } + expire_override_deadlines_ev = rb_event_add("expire_override_deadlines", expire_override_deadlines, NULL, 60); return 0; From 6637a5472810729d9e3b844294da2a5fc1cbee38 Mon Sep 17 00:00:00 2001 From: Ed Kellett Date: Sat, 27 Jul 2019 01:59:28 +0100 Subject: [PATCH 2/3] override: don't leak the old expiry timer list --- extensions/override.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/extensions/override.c b/extensions/override.c index 4e7667b1..4df177a0 100644 --- a/extensions/override.c +++ b/extensions/override.c @@ -309,10 +309,18 @@ _modinit(void) static void _moddeinit(void) { + rb_dlink_node *n, *tn; + /* disable the umode and remove it from the available list */ user_modes['p'] = 0; construct_umodebuf(); + RB_DLINK_FOREACH_SAFE(n, tn, overriding_opers.head) + { + rb_dlinkDelete(n, &overriding_opers); + rb_free(n->data); + } + rb_event_delete(expire_override_deadlines_ev); } From dbeda234e6b70b6479f5be8331bfe6661243bbf7 Mon Sep 17 00:00:00 2001 From: Ed Kellett Date: Sat, 27 Jul 2019 13:50:53 +0100 Subject: [PATCH 3/3] override: always check oper:override It's possible to have the oper:override privilege removed by /grant. /grant triggers an empty umode change event to allow privileged umodes to be set or removed, so checking for oper:override on all umode changes (and not just ones where +o or +p is changed) allows us to remove +p when necessary. --- extensions/override.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/extensions/override.c b/extensions/override.c index 4df177a0..6f679e92 100644 --- a/extensions/override.c +++ b/extensions/override.c @@ -108,6 +108,7 @@ static void check_umode_change(void *vdata) { hook_data_umode_changed *data = (hook_data_umode_changed *)vdata; + bool changed = false; struct Client *source_p = data->client; if (!MyClient(source_p)) @@ -116,9 +117,7 @@ check_umode_change(void *vdata) if (data->oldumodes & UMODE_OPER && !IsOper(source_p)) source_p->umodes &= ~user_modes['p']; - /* didn't change +p umode, we don't need to do anything */ - if (!((data->oldumodes ^ source_p->umodes) & user_modes['p'])) - return; + changed = ((data->oldumodes ^ source_p->umodes) & user_modes['p']); if (source_p->umodes & user_modes['p']) { @@ -129,12 +128,14 @@ check_umode_change(void *vdata) return; } - update_session_deadline(source_p, NULL); - - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s has enabled oper-override (+p)", - get_oper_name(source_p)); + if (changed) + { + update_session_deadline(source_p, NULL); + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s has enabled oper-override (+p)", + get_oper_name(source_p)); + } } - else if (!(source_p->umodes & user_modes['p'])) + else if (changed && !(source_p->umodes & user_modes['p'])) { rb_dlink_node *n, *tn;