]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * m_privs.c: Shows effective operator privileges | |
3 | * | |
4 | * Copyright (C) 2008 Jilles Tjoelker | |
5 | * Copyright (C) 2008 charybdis development team | |
6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions are | |
9 | * met: | |
10 | * | |
11 | * 1.Redistributions of source code must retain the above copyright notice, | |
12 | * this list of conditions and the following disclaimer. | |
13 | * 2.Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | |
15 | * documentation and/or other materials provided with the distribution. | |
16 | * 3.The name of the author may not be used to endorse or promote products | |
17 | * derived from this software without specific prior written permission. | |
18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
22 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | |
23 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
27 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
28 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | |
31 | ||
32 | #include "stdinc.h" | |
33 | #include "client.h" | |
34 | #include "numeric.h" | |
35 | #include "send.h" | |
36 | #include "msg.h" | |
37 | #include "parse.h" | |
38 | #include "modules.h" | |
39 | #include "s_conf.h" | |
40 | #include "s_newconf.h" | |
41 | #include "hash.h" | |
42 | ||
43 | static const char privs_desc[] = "Provides the PRIVS command to inspect an operator's privileges"; | |
44 | ||
45 | static void m_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); | |
46 | static void me_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); | |
47 | static void mo_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); | |
48 | ||
49 | struct Message privs_msgtab = { | |
50 | "PRIVS", 0, 0, 0, 0, | |
51 | {mg_unreg, {m_privs, 0}, mg_ignore, mg_ignore, {me_privs, 0}, {mo_privs, 0}} | |
52 | }; | |
53 | ||
54 | mapi_clist_av1 privs_clist[] = { | |
55 | &privs_msgtab, | |
56 | NULL | |
57 | }; | |
58 | ||
59 | /* XXX this is a copy, not so nice | |
60 | * | |
61 | * Sort of... it's int in newconf.c since oper confs don't need 64-bit wide flags. | |
62 | * --Elizafox | |
63 | */ | |
64 | struct mode_table | |
65 | { | |
66 | const char *name; | |
67 | uint64_t mode; | |
68 | }; | |
69 | ||
70 | /* there is no such table like this anywhere else */ | |
71 | static struct mode_table auth_client_table[] = { | |
72 | {"resv_exempt", FLAGS_EXEMPTRESV }, | |
73 | {"kline_exempt", FLAGS_EXEMPTKLINE }, | |
74 | {"flood_exempt", FLAGS_EXEMPTFLOOD }, | |
75 | {"spambot_exempt", FLAGS_EXEMPTSPAMBOT }, | |
76 | {"shide_exempt", FLAGS_EXEMPTSHIDE }, | |
77 | {"jupe_exempt", FLAGS_EXEMPTJUPE }, | |
78 | {"extend_chans", FLAGS_EXTENDCHANS }, | |
79 | {NULL, 0} | |
80 | }; | |
81 | ||
82 | DECLARE_MODULE_AV2(privs, NULL, NULL, privs_clist, NULL, NULL, NULL, NULL, privs_desc); | |
83 | ||
84 | static void show_privs(struct Client *source_p, struct Client *target_p) | |
85 | { | |
86 | struct mode_table *p; | |
87 | ||
88 | send_multiline_init(source_p, " ", form_str(RPL_PRIVS), | |
89 | get_id(&me, source_p), | |
90 | get_id(source_p, source_p), | |
91 | target_p->name, | |
92 | "* "); | |
93 | ||
94 | send_multiline_remote_pad(source_p, &me); | |
95 | send_multiline_remote_pad(source_p, source_p); | |
96 | ||
97 | if (target_p->user->privset) | |
98 | for (char *s = target_p->user->privset->privs; s != NULL; (s = strchr(s, ' ')) && s++) | |
99 | { | |
100 | char *c = strchr(s, ' '); | |
101 | if (c) *c = '\0'; | |
102 | send_multiline_item(source_p, "%s", s); | |
103 | if (c) *c = ' '; | |
104 | } | |
105 | ||
106 | if (IsOper(target_p)) | |
107 | { | |
108 | if (target_p->user->opername) | |
109 | send_multiline_item(source_p, "operator:%s", target_p->user->opername); | |
110 | ||
111 | if (target_p->user->privset) | |
112 | send_multiline_item(source_p, "privset:%s", target_p->user->privset->name); | |
113 | } | |
114 | p = &auth_client_table[0]; | |
115 | while (p->name != NULL) | |
116 | { | |
117 | if (target_p->flags & p->mode) | |
118 | send_multiline_item(source_p, "%s", p->name); | |
119 | p++; | |
120 | } | |
121 | ||
122 | send_multiline_fini(source_p, form_str(RPL_PRIVS), | |
123 | get_id(&me, source_p), | |
124 | get_id(source_p, source_p), | |
125 | target_p->name, | |
126 | ""); | |
127 | } | |
128 | ||
129 | static void | |
130 | me_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
131 | { | |
132 | struct Client *target_p; | |
133 | ||
134 | if (!IsOper(source_p) || parc < 2 || EmptyString(parv[1])) | |
135 | return; | |
136 | ||
137 | target_p = find_person(parv[1]); | |
138 | ||
139 | if (target_p != NULL) | |
140 | show_privs(source_p, target_p); | |
141 | } | |
142 | ||
143 | static void | |
144 | mo_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
145 | { | |
146 | struct Client *target_p; | |
147 | struct Client *server_p; | |
148 | ||
149 | if (parc < 2 || EmptyString(parv[1])) | |
150 | { | |
151 | server_p = target_p = source_p; | |
152 | } | |
153 | else | |
154 | { | |
155 | if (parc >= 3) | |
156 | { | |
157 | server_p = find_named_client(parv[1]); | |
158 | target_p = find_named_person(parv[2]); | |
159 | } | |
160 | else | |
161 | { | |
162 | server_p = target_p = find_named_person(parv[1]); | |
163 | } | |
164 | if (server_p == NULL || target_p == NULL) | |
165 | { | |
166 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, | |
167 | form_str(ERR_NOSUCHNICK), parv[1]); | |
168 | return; | |
169 | } | |
170 | } | |
171 | ||
172 | if (target_p != source_p && !HasPrivilege(source_p, "oper:privs")) | |
173 | { | |
174 | sendto_one(source_p, form_str(ERR_NOPRIVS), | |
175 | me.name, source_p->name, "privs"); | |
176 | return; | |
177 | } | |
178 | ||
179 | if (!IsServer(server_p)) | |
180 | server_p = server_p->servptr; | |
181 | ||
182 | if (IsMe(server_p)) | |
183 | show_privs(source_p, target_p); | |
184 | else | |
185 | sendto_one(server_p, ":%s ENCAP %s PRIVS %s", | |
186 | get_id(source_p, server_p), | |
187 | server_p->name, | |
188 | use_id(target_p)); | |
189 | } | |
190 | ||
191 | static void | |
192 | m_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
193 | { | |
194 | if (parc >= 2 && !EmptyString(parv[1]) && | |
195 | irccmp(parv[1], source_p->name)) { | |
196 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
197 | form_str(ERR_NOPRIVILEGES)); | |
198 | return; | |
199 | } | |
200 | ||
201 | show_privs(source_p, source_p); | |
202 | } |