Debian Codegraph @

modules/operserv/specs.c

raw
1 /*
2 * Copyright (c) 2005-2006 Patrick Fish, et al
3 * Copyright (c) 2011 William Pitcock <[email protected]>.
4 * Copyright (c) 2016 Atheme Development Group
5 *
6 * Rights to this code are documented in doc/LICENSE.
7 *
8 * This file contains functionality which implements the OService SPECS command.
9 */
10
11 #include "atheme.h"
12 #include "../groupserv/main/groupserv_common.h"
13
14 DECLARE_MODULE_V1
15 (
16 "operserv/specs", false, _modinit, _moddeinit,
17 PACKAGE_STRING,
18 VENDOR_STRING
19 );
20
21 static void os_cmd_specs(sourceinfo_t *si, int parc, char *parv[]);
22
23 command_t os_specs = { "SPECS", N_("Shows oper flags."), AC_NONE, 2, os_cmd_specs, { .path = "oservice/specs" } };
24
25 void _modinit(module_t *m)
26 {
27 service_named_bind_command("operserv", &os_specs);
28 }
29
30 void _moddeinit(module_unload_intent_t intent)
31 {
32 service_named_unbind_command("operserv", &os_specs);
33 }
34
35 struct privilege
36 {
37 const char *priv;
38 const char *desc;
39 };
40
41 struct priv_category
42 {
43 const char *name;
44 struct privilege privs[];
45 };
46
47 static struct priv_category nickserv_privs = {
48 N_("Nicknames/Accounts"),
49 {
50 { PRIV_USER_AUSPEX, N_("view concealed information about accounts") },
51 { PRIV_USER_ADMIN, N_("drop accounts, freeze accounts, reset passwords") },
52 { PRIV_USER_SENDPASS, N_("send passwords") },
53 { PRIV_USER_VHOST, N_("set vhosts") },
54 { PRIV_USER_FREGISTER, N_("register accounts on behalf of another user") },
55 { PRIV_MARK, N_("mark accounts") },
56 { PRIV_HOLD, N_("hold accounts") },
57 { NULL, NULL },
58 }
59 };
60
61 static struct priv_category chanserv_privs = {
62 N_("Channels"),
63 {
64 { PRIV_CHAN_AUSPEX, N_("view concealed information about channels") },
65 { PRIV_CHAN_ADMIN, N_("drop channels, close channels, transfer ownership") },
66 { PRIV_CHAN_CMODES, N_("mlock operator modes") },
67 { PRIV_JOIN_STAFFONLY, N_("join staff channels") },
68 { PRIV_MARK, N_("mark channels") },
69 { PRIV_HOLD, N_("hold channels") },
70 { PRIV_REG_NOLIMIT, N_("bypass channel registration limits") },
71 { NULL, NULL },
72 }
73 };
74
75 static struct priv_category general_privs = {
76 N_("General"),
77 {
78 { PRIV_SERVER_AUSPEX, N_("view concealed information about servers") },
79 { PRIV_VIEWPRIVS, N_("view privileges of other users") },
80 { PRIV_FLOOD, N_("exempt from flood control") },
81 { PRIV_ADMIN, N_("administer services") },
82 { PRIV_METADATA, N_("edit private and internal metadata") },
83 { NULL, NULL },
84 }
85 };
86
87 static struct priv_category operserv_privs = {
88 N_("OperServ"),
89 {
90 { PRIV_OMODE, N_("set channel modes") },
91 { PRIV_AKILL, N_("add and remove autokills") },
92 { PRIV_MASS_AKILL, N_("masskill channels or regexes") },
93 { PRIV_JUPE, N_("jupe servers") },
94 { PRIV_NOOP, N_("NOOP access") },
95 { PRIV_GLOBAL, N_("send global notices") },
96 { PRIV_GRANT, N_("edit oper privileges") },
97 { PRIV_OVERRIDE, N_("perform actions as any other user") },
98 { NULL, NULL },
99 }
100 };
101
102 static struct priv_category groupserv_privs = {
103 N_("GroupServ"),
104 {
105 { PRIV_GROUP_AUSPEX, N_("view concealed information about groups") },
106 { PRIV_GROUP_ADMIN, N_("administer groups") },
107 { PRIV_REG_NOLIMIT, N_("bypass group registration limits") },
108 { NULL, NULL },
109 }
110 };
111
112 static struct priv_category *priv_categories[] = {
113 &nickserv_privs, &chanserv_privs, &general_privs, &operserv_privs, &groupserv_privs,
114 };
115
116 static void os_cmd_specs(sourceinfo_t *si, int parc, char *parv[])
117 {
118 user_t *tu = NULL;
119 operclass_t *cl = NULL;
120 const char *targettype = parv[0];
121 const char *target = parv[1];
122 unsigned int i;
123 int j, n;
124
125 if (!has_any_privs(si))
126 {
127 command_fail(si, fault_noprivs, _("You are not authorized to use %s."), si->service->nick);
128 return;
129 }
130
131 if (targettype != NULL)
132 {
133 if (!has_priv(si, PRIV_VIEWPRIVS))
134 {
135 command_fail(si, fault_noprivs, STR_NO_PRIVILEGE, PRIV_VIEWPRIVS);
136 return;
137 }
138 if (target == NULL)
139 target = "?";
140 if (!strcasecmp(targettype, "USER"))
141 {
142 tu = user_find_named(target);
143 if (tu == NULL)
144 {
145 command_fail(si, fault_nosuch_target, _("\2%s\2 is not on IRC."), target);
146 return;
147 }
148 if (!has_any_privs_user(tu))
149 {
150 command_success_nodata(si, _("\2%s\2 is unprivileged."), tu->nick);
151 return;
152 }
153 if (is_internal_client(tu))
154 {
155 command_fail(si, fault_noprivs, _("\2%s\2 is an internal client."), tu->nick);
156 return;
157 }
158 }
159 else if (!strcasecmp(targettype, "OPERCLASS") || !strcasecmp(targettype, "CLASS"))
160 {
161 cl = operclass_find(target);
162 if (cl == NULL)
163 {
164 command_fail(si, fault_nosuch_target, _("No such oper class \2%s\2."), target);
165 return;
166 }
167 }
168 else
169 {
170 command_fail(si, fault_badparams, _("Valid target types: USER, OPERCLASS."));
171 return;
172 }
173 }
174 else
175 tu = si->su;
176
177 if (targettype == NULL)
178 command_success_nodata(si, _("Privileges for \2%s\2:"), get_source_name(si));
179 else if (tu)
180 command_success_nodata(si, _("Privileges for \2%s\2:"), tu->nick);
181 else
182 command_success_nodata(si, _("Privileges for oper class \2%s\2:"), cl->name);
183
184 for (i = 0; i < ARRAY_SIZE(priv_categories); i++)
185 {
186 struct priv_category *cat = priv_categories[i];
187
188 command_success_nodata(si, "\2%s\2:", _(cat->name));
189
190 for (j = n = 0; cat->privs[j].priv != NULL; j++)
191 {
192 if (targettype == NULL ? has_priv(si, cat->privs[j].priv) : (tu ? has_priv_user(tu, cat->privs[j].priv) : has_priv_operclass(cl, cat->privs[j].priv)))
193 {
194 command_success_nodata(si, " %s (%s)", cat->privs[j].priv, _(cat->privs[j].desc));
195 ++n;
196 }
197 }
198
199 if (!n)
200 command_success_nodata(si, " %s", _("(no privileges held)"));
201 }
202
203 command_success_nodata(si, _("End of privileges"));
204
205 if (targettype == NULL)
206 logcommand(si, CMDLOG_ADMIN, "SPECS");
207 else if (tu)
208 logcommand(si, CMDLOG_ADMIN, "SPECS:USER: \2%s!%s@%s\2", tu->nick, tu->user, tu->vhost);
209 else
210 logcommand(si, CMDLOG_ADMIN, "SPECS:OPERCLASS: \2%s\2", cl->name);
211 }
212
213 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
214 * vim:ts=8
215 * vim:sw=8
216 * vim:noexpandtab
217 */