2 * oper-override for charybdis.
4 * adds usermode +p and has a timer event that is iterated over to disable
5 * usermode +p after a while...
7 * you need to have oper:override permission on the opers you want to be
8 * able to use this extension.
22 #include "privilege.h"
23 #include "s_newconf.h"
25 static const char override_desc
[] =
26 "Adds user mode +p, an operator-only user mode that grants temporary privileges to override anything";
28 static void check_umode_change(void *data
);
29 static void hack_channel_access(void *data
);
30 static void hack_can_join(void *data
);
31 static void hack_can_kick(void *data
);
32 static void hack_can_send(void *data
);
33 static void handle_client_exit(void *data
);
35 mapi_hfn_list_av1 override_hfnlist
[] = {
36 { "umode_changed", (hookfn
) check_umode_change
},
37 { "get_channel_access", (hookfn
) hack_channel_access
},
38 { "can_join", (hookfn
) hack_can_join
},
39 { "can_kick", (hookfn
) hack_can_kick
},
40 { "can_send", (hookfn
) hack_can_send
},
41 { "client_exit", (hookfn
) handle_client_exit
},
45 #define CHFL_OVERRIDE 0x0004
46 #define IsOperOverride(x) (HasPrivilege((x), "oper:override"))
48 struct OverrideSession
{
51 struct Client
*client
;
55 rb_dlink_list overriding_opers
= { NULL
, NULL
, 0 };
58 update_session_deadline(struct Client
*source_p
, struct OverrideSession
*session_p
)
60 if (session_p
== NULL
)
64 RB_DLINK_FOREACH(n
, overriding_opers
.head
)
66 struct OverrideSession
*s
= n
->data
;
68 if (s
->client
== source_p
)
76 if (session_p
== NULL
)
78 session_p
= rb_malloc(sizeof(struct OverrideSession
));
79 session_p
->client
= source_p
;
82 session_p
->deadline
= rb_current_time() + 1800;
84 rb_dlinkDelete(&session_p
->node
, &overriding_opers
);
85 rb_dlinkAdd(session_p
, &session_p
->node
, &overriding_opers
);
89 expire_override_deadlines(void *unused
)
91 rb_dlink_node
*n
, *tn
;
93 RB_DLINK_FOREACH_SAFE(n
, tn
, overriding_opers
.head
)
95 struct OverrideSession
*session_p
= n
->data
;
97 if (session_p
->deadline
> rb_current_time())
99 else if (session_p
->deadline
< rb_current_time())
101 const char *parv
[4] = {session_p
->client
->name
, session_p
->client
->name
, "-p", NULL
};
102 user_mode(session_p
->client
, session_p
->client
, 3, parv
);
108 check_umode_change(void *vdata
)
110 hook_data_umode_changed
*data
= (hook_data_umode_changed
*)vdata
;
111 bool changed
= false;
112 struct Client
*source_p
= data
->client
;
114 if (!MyClient(source_p
))
117 if (data
->oldumodes
& UMODE_OPER
&& !IsOper(source_p
))
118 source_p
->umodes
&= ~user_modes
['p'];
120 changed
= ((data
->oldumodes
^ source_p
->umodes
) & user_modes
['p']);
122 if (source_p
->umodes
& user_modes
['p'])
124 if (!IsOperOverride(source_p
))
126 sendto_one_notice(source_p
, ":*** You need oper:override privilege for +p");
127 source_p
->umodes
&= ~user_modes
['p'];
133 update_session_deadline(source_p
, NULL
);
134 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
, "%s has enabled oper-override (+p)",
135 get_oper_name(source_p
));
138 else if (changed
&& !(source_p
->umodes
& user_modes
['p']))
140 rb_dlink_node
*n
, *tn
;
142 RB_DLINK_FOREACH_SAFE(n
, tn
, overriding_opers
.head
)
144 struct OverrideSession
*session_p
= n
->data
;
146 if (session_p
->client
!= source_p
)
149 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
, "%s has disabled oper-override (+p)",
150 get_oper_name(session_p
->client
));
152 rb_dlinkDelete(n
, &overriding_opers
);
159 hack_channel_access(void *vdata
)
161 hook_data_channel_approval
*data
= (hook_data_channel_approval
*) vdata
;
163 if (data
->dir
== MODE_QUERY
)
166 if (data
->approved
== CHFL_CHANOP
)
169 if (data
->client
->umodes
& user_modes
['p'])
171 update_session_deadline(data
->client
, NULL
);
172 data
->approved
= CHFL_OVERRIDE
;
174 /* we only want to report modehacks, which are always non-NULL */
176 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
, "%s is using oper-override on %s (modehacking: %s)",
177 get_oper_name(data
->client
), data
->chptr
->chname
, data
->modestr
);
182 hack_can_join(void *vdata
)
184 hook_data_channel
*data
= (hook_data_channel
*) vdata
;
186 if (data
->approved
== 0)
189 if (data
->client
->umodes
& user_modes
['p'])
191 update_session_deadline(data
->client
, NULL
);
194 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
, "%s is using oper-override on %s (banwalking)",
195 get_oper_name(data
->client
), data
->chptr
->chname
);
200 hack_can_kick(void *vdata
)
202 hook_data_channel_approval
*data
= (hook_data_channel_approval
*) vdata
;
205 alevel
= get_channel_access(data
->client
, data
->chptr
, data
->msptr
, data
->dir
, NULL
);
206 if (alevel
!= CHFL_OVERRIDE
)
209 if (data
->client
->umodes
& user_modes
['p'])
211 update_session_deadline(data
->client
, NULL
);
212 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
, "%s is using oper-override on %s (KICK %s)",
213 get_oper_name(data
->client
), data
->chptr
->chname
, data
->target
->name
);
218 hack_can_send(void *vdata
)
220 hook_data_channel_approval
*data
= (hook_data_channel_approval
*) vdata
;
222 if (data
->dir
== MODE_QUERY
)
225 if (data
->approved
== CAN_SEND_NONOP
|| data
->approved
== CAN_SEND_OPV
)
228 if (data
->client
->umodes
& user_modes
['p'])
230 data
->approved
= CAN_SEND_NONOP
;
232 if (MyClient(data
->client
))
234 update_session_deadline(data
->client
, NULL
);
235 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
, "%s is using oper-override on %s (forcing message)",
236 get_oper_name(data
->client
), data
->chptr
->chname
);
242 handle_client_exit(void *vdata
)
244 hook_data_client_exit
*data
= (hook_data_client_exit
*) vdata
;
245 rb_dlink_node
*n
, *tn
;
246 struct Client
*source_p
= data
->target
;
248 RB_DLINK_FOREACH_SAFE(n
, tn
, overriding_opers
.head
)
250 struct OverrideSession
*session_p
= n
->data
;
252 if (session_p
->client
!= source_p
)
255 rb_dlinkDelete(n
, &overriding_opers
);
260 struct ev_entry
*expire_override_deadlines_ev
= NULL
;
267 /* add the usermode to the available slot */
268 user_modes
['p'] = find_umode_slot();
269 construct_umodebuf();
271 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
273 struct Client
*client_p
= ptr
->data
;
274 if (IsPerson(client_p
) && (client_p
->umodes
& user_modes
['p']))
275 update_session_deadline(client_p
, NULL
);
278 expire_override_deadlines_ev
= rb_event_add("expire_override_deadlines", expire_override_deadlines
, NULL
, 60);
286 rb_dlink_node
*n
, *tn
;
288 /* disable the umode and remove it from the available list */
290 construct_umodebuf();
292 RB_DLINK_FOREACH_SAFE(n
, tn
, overriding_opers
.head
)
294 rb_dlinkDelete(n
, &overriding_opers
);
298 rb_event_delete(expire_override_deadlines_ev
);
301 DECLARE_MODULE_AV2(override
, _modinit
, _moddeinit
, NULL
, NULL
,
302 override_hfnlist
, NULL
, NULL
, override_desc
);