]> jfr.im git - solanum.git/blobdiff - extensions/override.c
Use const hook data where possible
[solanum.git] / extensions / override.c
index c4fdb22dded777c8df69df0e6fa97fccf8c67181..68c56d018f38b203110297364ad02c4074e46d21 100644 (file)
 #include "privilege.h"
 #include "s_newconf.h"
 
+static const char override_desc[] =
+       "Adds user mode +p, an operator-only user mode that grants temporary privileges to override anything";
+
 static void check_umode_change(void *data);
 static void hack_channel_access(void *data);
 static void hack_can_join(void *data);
+static void hack_can_kick(void *data);
 static void hack_can_send(void *data);
 static void handle_client_exit(void *data);
 
@@ -32,11 +36,13 @@ mapi_hfn_list_av1 override_hfnlist[] = {
        { "umode_changed", (hookfn) check_umode_change },
        { "get_channel_access", (hookfn) hack_channel_access },
        { "can_join", (hookfn) hack_can_join },
+       { "can_kick", (hookfn) hack_can_kick },
        { "can_send", (hookfn) hack_can_send },
        { "client_exit", (hookfn) handle_client_exit },
        { NULL, NULL }
 };
 
+#define CHFL_OVERRIDE          0x0004
 #define IsOperOverride(x)      (HasPrivilege((x), "oper:override"))
 
 struct OverrideSession {
@@ -92,7 +98,7 @@ expire_override_deadlines(void *unused)
                        break;
                else if (session_p->deadline < rb_current_time())
                {
-                       const char *parv[4] = {session_p->client->name, session_p->client->name, "-p", NULL};
+                       const char *parv[4] = {session_p->client->name, session_p->client->name, "-p", NULL};
                        user_mode(session_p->client, session_p->client, 3, parv);
                }
        }
@@ -107,18 +113,22 @@ check_umode_change(void *vdata)
        if (!MyClient(source_p))
                return;
 
+       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;
 
-       if (!IsOperOverride(source_p))
-       {
-               source_p->umodes &= ~user_modes['p'];
-               return;
-       }
-
        if (source_p->umodes & user_modes['p'])
        {
+               if (!IsOperOverride(source_p))
+               {
+                       sendto_one_notice(source_p, ":*** You need oper:override privilege for +p");
+                       source_p->umodes &= ~user_modes['p'];
+                       return;
+               }
+
                update_session_deadline(source_p, NULL);
 
                sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s has enabled oper-override (+p)",
@@ -149,16 +159,21 @@ hack_channel_access(void *vdata)
 {
        hook_data_channel_approval *data = (hook_data_channel_approval *) vdata;
 
+       if (data->dir == MODE_QUERY)
+               return;
+
        if (data->approved == CHFL_CHANOP)
                return;
 
        if (data->client->umodes & user_modes['p'])
        {
                update_session_deadline(data->client, NULL);
-               data->approved = CHFL_CHANOP;
+               data->approved = CHFL_OVERRIDE;
 
-               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is using oper-override on %s (modehacking)",
-                                      get_oper_name(data->client), data->chptr->chname);
+               /* 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);
        }
 }
 
@@ -180,23 +195,72 @@ hack_can_join(void *vdata)
        }
 }
 
+static void
+hack_can_kick(void *vdata)
+{
+       hook_data_channel_approval *data = (hook_data_channel_approval *) vdata;
+       int alevel;
+
+       if (data->target->umodes & user_modes['p'])
+       {
+               if (data->client->umodes & user_modes['p'])
+               {
+                       /* Using oper-override to kick an oper
+                        * who's also using oper-override, better
+                        * report what happened.
+                        */
+                       update_session_deadline(data->client, NULL);
+                       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);
+               }
+               else
+               {
+                       /* Like cmode +M, let's report any attempt
+                        * to kick the immune oper.
+                        */
+                       update_session_deadline(data->target, NULL);
+                       sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s attempted to kick %s from %s (who is +p)",
+                               data->client->name, data->target->name, data->chptr->chname);
+                       sendto_one_numeric(data->client, ERR_ISCHANSERVICE, "%s %s :Cannot kick immune IRC operators.",
+                               data->target->name, data->chptr->chname);
+                       data->approved = 0;
+               }
+               return;
+       }
+
+       alevel = get_channel_access(data->client, data->chptr, data->msptr, data->dir, NULL);
+       if (alevel != CHFL_OVERRIDE)
+               return;
+
+       if (data->client->umodes & user_modes['p'])
+       {
+               update_session_deadline(data->client, NULL);
+               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);
+       }
+}
+
 static void
 hack_can_send(void *vdata)
 {
        hook_data_channel_approval *data = (hook_data_channel_approval *) vdata;
 
+       if (data->dir == MODE_QUERY)
+               return;
+
        if (data->approved == CAN_SEND_NONOP || data->approved == CAN_SEND_OPV)
                return;
 
        if (data->client->umodes & user_modes['p'])
        {
-               update_session_deadline(data->client, NULL);
-               data->approved = CAN_SEND_OPV;
+               data->approved = CAN_SEND_NONOP;
 
-#ifdef XXX_UNSURE_IF_WANT
-               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is using oper-override on %s (banwalking)",
-                                      get_oper_name(data->client), data->chptr->chname);
-#endif
+               if (MyClient(data->client))
+               {
+                       update_session_deadline(data->client, NULL);
+                       sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is using oper-override on %s (forcing message)",
+                                              get_oper_name(data->client), data->chptr->chname);
+               }
        }
 }
 
@@ -216,7 +280,7 @@ handle_client_exit(void *vdata)
 
                rb_dlinkDelete(n, &overriding_opers);
                rb_free(session_p);
-       }       
+       }
 }
 
 struct ev_entry *expire_override_deadlines_ev = NULL;
@@ -228,7 +292,7 @@ _modinit(void)
        user_modes['p'] = find_umode_slot();
        construct_umodebuf();
 
-        expire_override_deadlines_ev = rb_event_add("expire_override_deadlines", expire_override_deadlines, NULL, 60);
+       expire_override_deadlines_ev = rb_event_add("expire_override_deadlines", expire_override_deadlines, NULL, 60);
 
        return 0;
 }
@@ -243,5 +307,5 @@ _moddeinit(void)
        rb_event_delete(expire_override_deadlines_ev);
 }
 
-DECLARE_MODULE_AV1(override, _modinit, _moddeinit, NULL, NULL,
-                       override_hfnlist, "$Revision: 3526 $");
+DECLARE_MODULE_AV2(override, _modinit, _moddeinit, NULL, NULL,
+                       override_hfnlist, NULL, NULL, override_desc);