1 |
/** |
2 |
* specs.C: This file contains functionality which implements the OperServ SPECS command. |
3 |
* |
4 |
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
5 |
* Rights to this code are as documented in COPYING. |
6 |
* |
7 |
* |
8 |
* Portions of this file were derived from sources bearing the following license: |
9 |
* Copyright © 2005-2006 Patrick Fish, et al |
10 |
* Rights to this code are documented in doc/pod/license.pod. |
11 |
* |
12 |
* $Id: specs.C,v 1.7 2007-09-16 18:54:44 pippijn Exp $ |
13 |
*/ |
14 |
|
15 |
#include "atheme.h" |
16 |
#include <ermyth/module.h> |
17 |
|
18 |
static char const rcsid[] = "$Id: specs.C,v 1.7 2007-09-16 18:54:44 pippijn Exp $"; |
19 |
|
20 |
REGISTER_MODULE ("operserv/specs", false, "The Ermyth Team <http://ermyth.xinutec.org>"); |
21 |
|
22 |
E cmdvec os_cmdtree; |
23 |
E helpvec os_helptree; |
24 |
|
25 |
static const struct privname_t |
26 |
{ |
27 |
char const * const priv; |
28 |
char const * const npriv; |
29 |
char const * const cpriv; |
30 |
char const * const gpriv; |
31 |
char const * const opriv; |
32 |
} privnames[] = |
33 |
{ |
34 |
/* NickServ/UserServ */ |
35 |
{ PRIV_USER_AUSPEX, "view concealed information", NULL, NULL, NULL }, |
36 |
{ PRIV_USER_ADMIN, "drop accounts, freeze accounts, reset passwords", NULL, NULL, NULL }, |
37 |
{ PRIV_USER_SENDPASS, "send passwords", NULL, NULL, NULL }, |
38 |
{ PRIV_USER_VHOST, "set vhosts", NULL, NULL, NULL }, |
39 |
{ PRIV_USER_FREGISTER, "register accounts on behalf of another user", NULL, NULL, NULL }, |
40 |
/* ChanServ */ |
41 |
{ PRIV_CHAN_AUSPEX, NULL, "view concealed information", NULL, NULL }, |
42 |
{ PRIV_CHAN_ADMIN, NULL, "drop channels, close channels, transfer ownership", NULL, NULL }, |
43 |
{ PRIV_CHAN_CMODES, NULL, "mlock operator modes", NULL, NULL }, |
44 |
{ PRIV_JOIN_STAFFONLY, NULL, "join staff channels", NULL, NULL }, |
45 |
/* NickServ/UserServ+ChanServ */ |
46 |
{ PRIV_MARK, "mark accounts", "mark channels", NULL, NULL }, |
47 |
{ PRIV_HOLD, "hold accounts", "hold channels", NULL, NULL }, |
48 |
{ PRIV_REG_NOLIMIT, NULL, "bypass registration limits", NULL, NULL }, |
49 |
/* general */ |
50 |
{ PRIV_SERVER_AUSPEX, NULL, NULL, "view concealed information", NULL }, |
51 |
{ PRIV_VIEWPRIVS, NULL, NULL, "view privileges of other users", NULL }, |
52 |
{ PRIV_FLOOD, NULL, NULL, "exempt from flood control", NULL }, |
53 |
{ PRIV_ADMIN, NULL, NULL, "administer services", NULL }, |
54 |
{ PRIV_METADATA, NULL, NULL, "edit private metadata", NULL }, |
55 |
/* OperServ */ |
56 |
{ PRIV_OMODE, NULL, NULL, NULL, "set channel modes" }, |
57 |
{ PRIV_AKILL, NULL, NULL, NULL, "add and remove autokills" }, |
58 |
{ PRIV_MASS_AKILL, NULL, NULL, NULL, "masskill channels or regexes" }, |
59 |
{ PRIV_JUPE, NULL, NULL, NULL, "jupe servers" }, |
60 |
{ PRIV_NOOP, NULL, NULL, NULL, "NOOP access" }, |
61 |
{ PRIV_GLOBAL, NULL, NULL, NULL, "send global notices" }, |
62 |
{ PRIV_GRANT, NULL, NULL, NULL, "edit oper privileges" }, |
63 |
/* -- */ |
64 |
{ NULL, NULL, NULL, NULL, NULL } |
65 |
}; |
66 |
|
67 |
static void |
68 |
os_cmd_specs (sourceinfo_t *si, int parc, char *parv[]) |
69 |
{ |
70 |
user_t *tu = NULL; |
71 |
operclass_t *cl = NULL; |
72 |
char *targettype = parv[0]; |
73 |
char const *target = parv[1]; |
74 |
char nprivs[BUFSIZE], cprivs[BUFSIZE], gprivs[BUFSIZE], oprivs[BUFSIZE]; |
75 |
int i; |
76 |
|
77 |
if (!has_any_privs (si)) |
78 |
{ |
79 |
command_fail (si, fault::noprivs, _("You are not authorized to use %s."), opersvs.nick); |
80 |
return; |
81 |
} |
82 |
|
83 |
if (targettype != NULL) |
84 |
{ |
85 |
if (!has_priv (si, PRIV_VIEWPRIVS)) |
86 |
{ |
87 |
command_fail (si, fault::noprivs, _("You do not have %s privilege."), PRIV_VIEWPRIVS); |
88 |
return; |
89 |
} |
90 |
if (target == NULL) |
91 |
target = "?"; |
92 |
if (!strcasecmp (targettype, "USER")) |
93 |
{ |
94 |
tu = user_find_named (target); |
95 |
if (tu == NULL) |
96 |
{ |
97 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not on IRC."), target); |
98 |
return; |
99 |
} |
100 |
if (!has_any_privs_user (tu)) |
101 |
{ |
102 |
command_success_nodata (si, _("\2%s\2 is unprivileged."), tu->nick); |
103 |
return; |
104 |
} |
105 |
if (is_internal_client (tu)) |
106 |
{ |
107 |
command_fail (si, fault::noprivs, _("\2%s\2 is an internal client."), tu->nick); |
108 |
return; |
109 |
} |
110 |
} |
111 |
else if (!strcasecmp (targettype, "OPERCLASS") || !strcasecmp (targettype, "CLASS")) |
112 |
{ |
113 |
cl = operclass_find (target); |
114 |
if (cl == NULL) |
115 |
{ |
116 |
command_fail (si, fault::nosuch_target, _("No such oper class \2%s\2."), target); |
117 |
return; |
118 |
} |
119 |
} |
120 |
else |
121 |
{ |
122 |
command_fail (si, fault::badparams, _("Valid target types: USER, OPERCLASS.")); |
123 |
return; |
124 |
} |
125 |
} |
126 |
else |
127 |
tu = si->su; |
128 |
|
129 |
i = 0; |
130 |
*nprivs = *cprivs = *gprivs = *oprivs = '\0'; |
131 |
while (privnames[i].priv != NULL) |
132 |
{ |
133 |
if (targettype == NULL ? has_priv (si, privnames[i].priv) : (tu ? has_priv_user (tu, privnames[i].priv) : has_priv_operclass (cl, privnames[i].priv))) |
134 |
{ |
135 |
if (privnames[i].npriv != NULL) |
136 |
{ |
137 |
if (*nprivs) |
138 |
strcat (nprivs, ", "); |
139 |
strcat (nprivs, privnames[i].npriv); |
140 |
} |
141 |
if (privnames[i].cpriv != NULL) |
142 |
{ |
143 |
if (*cprivs) |
144 |
strcat (cprivs, ", "); |
145 |
strcat (cprivs, privnames[i].cpriv); |
146 |
} |
147 |
if (privnames[i].gpriv != NULL) |
148 |
{ |
149 |
if (*gprivs) |
150 |
strcat (gprivs, ", "); |
151 |
strcat (gprivs, privnames[i].gpriv); |
152 |
} |
153 |
if (privnames[i].opriv != NULL) |
154 |
{ |
155 |
if (*oprivs) |
156 |
strcat (oprivs, ", "); |
157 |
strcat (oprivs, privnames[i].opriv); |
158 |
} |
159 |
} |
160 |
i++; |
161 |
} |
162 |
|
163 |
if (targettype == NULL) |
164 |
command_success_nodata (si, _("Privileges for \2%s\2:"), get_source_name (si)); |
165 |
else if (tu) |
166 |
command_success_nodata (si, _("Privileges for \2%s\2:"), tu->nick); |
167 |
else |
168 |
command_success_nodata (si, _("Privileges for oper class \2%s\2:"), cl->name); |
169 |
|
170 |
if (*nprivs) |
171 |
command_success_nodata (si, _("\2Nicknames/accounts\2: %s"), nprivs); |
172 |
if (*cprivs) |
173 |
command_success_nodata (si, _("\2Channels\2: %s"), cprivs); |
174 |
if (*gprivs) |
175 |
command_success_nodata (si, _("\2General\2: %s"), gprivs); |
176 |
if (*oprivs) |
177 |
command_success_nodata (si, _("\2OperServ\2: %s"), oprivs); |
178 |
command_success_nodata (si, _("End of privileges")); |
179 |
|
180 |
if (targettype == NULL) |
181 |
logcommand (si, CMDLOG_ADMIN, "SPECS"); |
182 |
else if (tu) |
183 |
logcommand (si, CMDLOG_ADMIN, "SPECS USER %s!%s@%s", tu->nick, tu->user, tu->vhost); |
184 |
else |
185 |
logcommand (si, CMDLOG_ADMIN, "SPECS OPERCLASS %s", cl->name); |
186 |
} |
187 |
|
188 |
command_t const os_specs = { "SPECS", N_("Shows oper flags."), AC_NONE, 2, os_cmd_specs }; |
189 |
|
190 |
bool |
191 |
_modinit (module *m) |
192 |
{ |
193 |
os_cmdtree << os_specs; |
194 |
help_addentry (os_helptree, "SPECS", "help/operserv/specs", NULL); |
195 |
|
196 |
return true; |
197 |
} |
198 |
|
199 |
void |
200 |
_moddeinit () |
201 |
{ |
202 |
os_cmdtree >> os_specs; |
203 |
help_delentry (os_helptree, "SPECS"); |
204 |
} |