This repository has been archived by the owner on Jun 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
cs_why.c
212 lines (186 loc) · 5.67 KB
/
cs_why.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
* Copyright (c) 2005-2006 William Pitcock, et al.
* Rights to this code are as documented in doc/LICENSE.
*
* This file contains code for the ChanServ WHY function.
*
*/
#include "atheme.h"
DECLARE_MODULE_V1
(
"freenode/cs_why", false, _modinit, _moddeinit,
PACKAGE_STRING,
"freenode <https://freenode.net>"
);
static void cs_cmd_why(sourceinfo_t *si, int parc, char *parv[]);
static void cs_cmd_fwhy(sourceinfo_t *si, int parc, char *parv[]);
static command_t cs_why = { "WHY", N_("Explains channel access logic."),
AC_NONE, 2, cs_cmd_why, { .path = "cservice/why" } };
static command_t cs_fwhy = { "FWHY", N_("Explains channel access logic, including private information."),
PRIV_USER_AUSPEX, 2, cs_cmd_fwhy, { .path = "cservice/why" } };
void _modinit(module_t *m)
{
MODULE_CONFLICT(m, "chanserv/why")
service_named_bind_command("chanserv", &cs_why);
service_named_bind_command("chanserv", &cs_fwhy);
}
void _moddeinit(module_unload_intent_t intent)
{
service_named_unbind_command("chanserv", &cs_why);
service_named_unbind_command("chanserv", &cs_fwhy);
}
static void cmd_generic_why(sourceinfo_t *si, int parc, char *parv[], bool is_fwhy)
{
const char *chan = parv[0];
const char *targ = parv[1];
mychan_t *mc;
user_t *u;
myuser_t *mu;
mowgli_node_t *n;
chanacs_t *ca;
entity_chanacs_validation_vtable_t *vt;
metadata_t *md;
bool operoverride = false;
int fl = 0;
if (!chan || (!targ && si->su == NULL))
{
if (is_fwhy)
{
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "FWHY");
command_fail(si, fault_needmoreparams, _("Syntax: FWHY <channel> [user]"));
}
else
{
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "WHY");
command_fail(si, fault_needmoreparams, _("Syntax: WHY <channel> [user]"));
}
return;
}
if (!targ)
targ = si->su->nick;
mc = mychan_find(chan);
u = user_find_named(targ);
if (u == NULL)
{
command_fail(si, fault_nosuch_target, _("\2%s\2 is not online."),
targ);
return;
}
mu = u->myuser;
if (mc == NULL)
{
command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."),
chan);
return;
}
if (!(mc->flags & MC_PUBACL) && !chanacs_source_has_flag(mc, si, CA_ACLVIEW))
{
if (has_priv(si, PRIV_CHAN_AUSPEX))
operoverride = true;
else
{
command_fail(si, fault_noprivs, _("You are not authorized to perform this operation."));
return;
}
}
if (metadata_find(mc, "private:close:closer"))
{
command_fail(si, fault_noprivs, _("\2%s\2 is closed."), chan);
return;
}
if (operoverride)
logcommand(si, CMDLOG_ADMIN, "%s: \2%s!%s@%s\2 on \2%s\2 (oper override)", is_fwhy ? "FWHY" : "WHY", u->nick, u->user, u->vhost, mc->name);
else
logcommand(si, is_fwhy ? CMDLOG_ADMIN : CMDLOG_GET, "%s: \2%s!%s@%s\2 on \2%s\2", is_fwhy ? "FWHY" : "WHY", u->nick, u->user, u->vhost, mc->name);
bool display_private = is_fwhy || u == si->su;
MOWGLI_ITER_FOREACH(n, mc->chanacs.head)
{
ca = (chanacs_t *)n->data;
if (ca->entity == NULL)
continue;
vt = myentity_get_chanacs_validator(ca->entity);
if (ca->entity == entity(u->myuser) ||
(vt->match_user != NULL ?
vt->match_user(ca, u) != NULL :
u->myuser != NULL &&
vt->match_entity(ca, entity(u->myuser)) != NULL))
{
if (ca->entity == entity(u->myuser))
{
fl |= ca->level;
command_success_nodata(si,
"\2%s\2 has flags \2%s\2 in \2%s\2 because they are logged in as \2%s\2.",
u->nick, bitmask_to_flags2(ca->level, 0), mc->name, ca->entity->name);
}
else if (isgroup(ca->entity))
{
fl |= ca->level;
command_success_nodata(si,
"\2%s\2 has flags \2%s\2 in \2%s\2 because they are a member of \2%s\2.",
u->nick, bitmask_to_flags2(ca->level, 0), mc->name, ca->entity->name);
}
else
{
// exttargets. $chanacs allows indirection
if (!display_private)
continue;
fl |= ca->level;
command_success_nodata(si,
"\2%s\2 has flags \2%s\2 in \2%s\2 because they match \2%s\2.",
u->nick, bitmask_to_flags2(ca->level, 0), mc->name, ca->entity->name);
}
if (ca->level & CA_AKICK)
{
md = metadata_find(ca, "reason");
if (md != NULL)
command_success_nodata(si, "Ban reason: %s", md->value);
}
}
}
if (display_private)
{
for (n = next_matching_host_chanacs(mc, u, mc->chanacs.head); n != NULL; n = next_matching_host_chanacs(mc, u, n->next))
{
ca = n->data;
fl |= ca->level;
command_success_nodata(si,
"\2%s\2 has flags \2%s\2 in \2%s\2 because they match the mask \2%s\2.",
u->nick, bitmask_to_flags2(ca->level, 0), mc->name, ca->host);
if (ca->level & CA_AKICK)
{
md = metadata_find(ca, "reason");
if (md != NULL)
command_success_nodata(si, "Ban reason: %s", md->value);
}
}
}
if (fl & (CA_AUTOOP | CA_AUTOHALFOP | CA_AUTOVOICE))
{
if (mc->flags & MC_NOOP)
command_success_nodata(si, _("The \2%s\2 flag is set for \2%s\2, therefore no status will be given."),
"NOOP",
mc->name);
else if (mu != NULL && mu->flags & MU_NOOP)
command_success_nodata(si, _("The \2%s\2 flag is set for \2%s\2, therefore no status will be given."),
"NOOP",
entity(mu)->name);
}
if ((fl & (CA_AKICK | CA_EXEMPT)) == (CA_AKICK | CA_EXEMPT))
command_success_nodata(si, _("+e exempts from +b."));
else if (fl == 0)
command_success_nodata(si, _("\2%s\2 has no special access to \2%s\2."),
u->nick, mc->name);
}
static void cs_cmd_why(sourceinfo_t *si, int parc, char *parv[])
{
cmd_generic_why(si, parc, parv, false);
}
static void cs_cmd_fwhy(sourceinfo_t *si, int parc, char *parv[])
{
cmd_generic_why(si, parc, parv, true);
}
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
* vim:ts=8
* vim:sw=8
* vim:noexpandtab
*/