]>
Commit | Line | Data |
---|---|---|
c728f993 JT |
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" | |
c728f993 JT |
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" | |
ed3ca2ff | 41 | #include "hash.h" |
c728f993 | 42 | |
eeabf33a EM |
43 | static const char privs_desc[] = "Provides the PRIVS command to inspect an operator's privileges"; |
44 | ||
3c7d6fcc EM |
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[]); | |
c728f993 JT |
48 | |
49 | struct Message privs_msgtab = { | |
7baa37a9 | 50 | "PRIVS", 0, 0, 0, 0, |
ed11b18f | 51 | {mg_unreg, {m_privs, 0}, mg_ignore, mg_ignore, {me_privs, 0}, {mo_privs, 0}} |
c728f993 JT |
52 | }; |
53 | ||
54 | mapi_clist_av1 privs_clist[] = { | |
55 | &privs_msgtab, | |
56 | NULL | |
57 | }; | |
58 | ||
66f7fe67 EM |
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 | */ | |
c728f993 JT |
64 | struct mode_table |
65 | { | |
66 | const char *name; | |
66f7fe67 | 67 | uint64_t mode; |
c728f993 JT |
68 | }; |
69 | ||
c728f993 JT |
70 | /* there is no such table like this anywhere else */ |
71 | static struct mode_table auth_client_table[] = { | |
66f7fe67 EM |
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 }, | |
c728f993 JT |
79 | {NULL, 0} |
80 | }; | |
81 | ||
d5d35409 | 82 | DECLARE_MODULE_AV2(privs, NULL, NULL, privs_clist, NULL, NULL, NULL, NULL, privs_desc); |
c728f993 | 83 | |
7e1a68ea EK |
84 | static void append_priv(struct Client *source_p, struct Client *target_p, char *buf, const char *s1, const char *s2) |
85 | { | |
86 | /* 510 - ":" - " 270 " - " " - " :* " */ | |
87 | size_t sourcelen = strlen(source_p->name); | |
88 | if (sourcelen < 9) sourcelen = 9; | |
89 | size_t limit = 499 - strlen(me.name) - sourcelen - strlen(target_p->name); | |
90 | if (strlen(s1) + strlen(s2) + strlen(buf) + 1 > limit) | |
91 | { | |
92 | sendto_one_numeric(source_p, RPL_PRIVS, "%s :* %s", target_p->name, buf); | |
93 | buf[0] = '\0'; | |
94 | } | |
95 | if (buf[0] != '\0') | |
96 | rb_strlcat(buf, " ", BUFSIZE); | |
97 | rb_strlcat(buf, s1, BUFSIZE); | |
98 | rb_strlcat(buf, s2, BUFSIZE); | |
99 | } | |
100 | ||
c728f993 JT |
101 | static void show_privs(struct Client *source_p, struct Client *target_p) |
102 | { | |
7e1a68ea | 103 | char buf[BUFSIZE]; |
c728f993 JT |
104 | struct mode_table *p; |
105 | ||
106 | buf[0] = '\0'; | |
7e1a68ea | 107 | |
ed3ca2ff | 108 | if (target_p->user->privset) |
bd8b9a37 EK |
109 | for (char *s = target_p->user->privset->privs; s != NULL; (s = strchr(s, ' ')) && s++) |
110 | { | |
111 | char *c = strchr(s, ' '); | |
112 | if (c) *c = '\0'; | |
7e1a68ea | 113 | append_priv(source_p, target_p, buf, s, ""); |
bd8b9a37 EK |
114 | if (c) *c = ' '; |
115 | } | |
7e1a68ea | 116 | |
c728f993 JT |
117 | if (IsOper(target_p)) |
118 | { | |
ed3ca2ff | 119 | if (target_p->user->opername) |
7e1a68ea | 120 | append_priv(source_p, target_p, buf, "operator:", target_p->user->opername); |
50f25792 | 121 | |
ed3ca2ff | 122 | if (target_p->user->privset) |
7e1a68ea | 123 | append_priv(source_p, target_p, buf, "privset:", target_p->user->privset->name); |
c728f993 JT |
124 | } |
125 | p = &auth_client_table[0]; | |
126 | while (p->name != NULL) | |
127 | { | |
66f7fe67 | 128 | if (target_p->flags & p->mode) |
7e1a68ea | 129 | append_priv(source_p, target_p, buf, p->name, ""); |
c728f993 JT |
130 | p++; |
131 | } | |
7e1a68ea EK |
132 | |
133 | if (buf[0] != '\0') | |
134 | sendto_one_numeric(source_p, RPL_PRIVS, "%s :%s", target_p->name, buf); | |
c728f993 JT |
135 | } |
136 | ||
3c7d6fcc EM |
137 | static void |
138 | me_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
c728f993 JT |
139 | { |
140 | struct Client *target_p; | |
141 | ||
142 | if (!IsOper(source_p) || parc < 2 || EmptyString(parv[1])) | |
3c7d6fcc | 143 | return; |
c728f993 | 144 | |
ed3ca2ff EK |
145 | target_p = find_person(parv[1]); |
146 | ||
147 | if (target_p != NULL) | |
c728f993 | 148 | show_privs(source_p, target_p); |
c728f993 JT |
149 | } |
150 | ||
3c7d6fcc EM |
151 | static void |
152 | mo_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
c728f993 JT |
153 | { |
154 | struct Client *target_p; | |
ed3ca2ff | 155 | struct Client *server_p; |
c728f993 JT |
156 | |
157 | if (parc < 2 || EmptyString(parv[1])) | |
ed3ca2ff EK |
158 | { |
159 | server_p = target_p = source_p; | |
160 | } | |
c728f993 JT |
161 | else |
162 | { | |
ed3ca2ff EK |
163 | if (parc >= 3) |
164 | { | |
165 | server_p = find_named_client(parv[1]); | |
166 | target_p = find_named_person(parv[2]); | |
167 | } | |
168 | else | |
169 | { | |
170 | server_p = target_p = find_named_person(parv[1]); | |
171 | } | |
172 | if (server_p == NULL || target_p == NULL) | |
c728f993 JT |
173 | { |
174 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, | |
175 | form_str(ERR_NOSUCHNICK), parv[1]); | |
3c7d6fcc | 176 | return; |
c728f993 JT |
177 | } |
178 | } | |
179 | ||
6d5be11f EK |
180 | if (target_p != source_p && !HasPrivilege(source_p, "oper:privs")) |
181 | { | |
182 | sendto_one(source_p, form_str(ERR_NOPRIVS), | |
183 | me.name, source_p->name, "privs"); | |
184 | return; | |
185 | } | |
186 | ||
ed3ca2ff EK |
187 | if (!IsServer(server_p)) |
188 | server_p = server_p->servptr; | |
189 | ||
190 | if (IsMe(server_p)) | |
c728f993 JT |
191 | show_privs(source_p, target_p); |
192 | else | |
ed3ca2ff EK |
193 | sendto_one(server_p, ":%s ENCAP %s PRIVS %s", |
194 | get_id(source_p, server_p), | |
195 | server_p->name, | |
c728f993 | 196 | use_id(target_p)); |
c728f993 | 197 | } |
ed11b18f | 198 | |
3c7d6fcc EM |
199 | static void |
200 | m_privs(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
ed11b18f JT |
201 | { |
202 | if (parc >= 2 && !EmptyString(parv[1]) && | |
203 | irccmp(parv[1], source_p->name)) { | |
204 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, | |
205 | form_str(ERR_NOPRIVILEGES)); | |
3c7d6fcc | 206 | return; |
ed11b18f JT |
207 | } |
208 | ||
209 | show_privs(source_p, source_p); | |
ed11b18f | 210 | } |