]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd). | |
3 | * m_etrace.c: Gives local opers a trace output with added info. | |
4 | * | |
5 | * Copyright (C) 2002-2003 Lee Hardy <lee@leeh.co.uk> | |
6 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions are | |
10 | * met: | |
11 | * | |
12 | * 1.Redistributions of source code must retain the above copyright notice, | |
13 | * this list of conditions and the following disclaimer. | |
14 | * 2.Redistributions in binary form must reproduce the above copyright | |
15 | * notice, this list of conditions and the following disclaimer in the | |
16 | * documentation and/or other materials provided with the distribution. | |
17 | * 3.The name of the author may not be used to endorse or promote products | |
18 | * derived from this software without specific prior written permission. | |
19 | * | |
20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | |
24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
30 | * POSSIBILITY OF SUCH DAMAGE. | |
212380e3 AC |
31 | */ |
32 | ||
33 | #include "stdinc.h" | |
34 | #include "class.h" | |
35 | #include "hook.h" | |
36 | #include "client.h" | |
37 | #include "hash.h" | |
212380e3 | 38 | #include "hash.h" |
4562c604 | 39 | #include "match.h" |
212380e3 AC |
40 | #include "ircd.h" |
41 | #include "numeric.h" | |
212380e3 AC |
42 | #include "s_serv.h" |
43 | #include "s_conf.h" | |
44 | #include "s_newconf.h" | |
45 | #include "send.h" | |
46 | #include "msg.h" | |
47 | #include "parse.h" | |
48 | #include "modules.h" | |
77d3d2db | 49 | #include "logger.h" |
0b904d91 | 50 | #include "supported.h" |
212380e3 | 51 | |
eeabf33a EM |
52 | static const char etrace_desc[] = |
53 | "Provides enhanced tracing facilities to opers (ETRACE, CHANTRACE, and MASKTRACE)"; | |
54 | ||
3c7d6fcc EM |
55 | static void mo_etrace(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
56 | static void me_etrace(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
57 | static void m_chantrace(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
58 | static void mo_masktrace(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
212380e3 AC |
59 | |
60 | struct Message etrace_msgtab = { | |
7baa37a9 | 61 | "ETRACE", 0, 0, 0, 0, |
212380e3 AC |
62 | {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, {me_etrace, 0}, {mo_etrace, 0}} |
63 | }; | |
64 | struct Message chantrace_msgtab = { | |
7baa37a9 | 65 | "CHANTRACE", 0, 0, 0, 0, |
5807e0be | 66 | {mg_ignore, {m_chantrace, 2}, mg_ignore, mg_ignore, mg_ignore, {m_chantrace, 2}} |
212380e3 AC |
67 | }; |
68 | struct Message masktrace_msgtab = { | |
7baa37a9 | 69 | "MASKTRACE", 0, 0, 0, 0, |
212380e3 AC |
70 | {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_masktrace, 2}} |
71 | }; | |
72 | ||
0b904d91 AC |
73 | static int |
74 | _modinit(void) | |
75 | { | |
76 | add_isupport("ETRACE", isupport_string, ""); | |
77 | ||
78 | return 0; | |
79 | } | |
80 | ||
81 | static void | |
82 | _moddeinit(void) | |
83 | { | |
84 | delete_isupport("ETRACE"); | |
85 | } | |
86 | ||
212380e3 | 87 | mapi_clist_av1 etrace_clist[] = { &etrace_msgtab, &chantrace_msgtab, &masktrace_msgtab, NULL }; |
9fd8e7cb | 88 | |
9fd8e7cb | 89 | DECLARE_MODULE_AV2(etrace, _modinit, _moddeinit, etrace_clist, NULL, NULL, NULL, NULL, etrace_desc); |
212380e3 AC |
90 | |
91 | static void do_etrace(struct Client *source_p, int ipv4, int ipv6); | |
92 | static void do_etrace_full(struct Client *source_p); | |
93 | static void do_single_etrace(struct Client *source_p, struct Client *target_p); | |
94 | ||
95 | static const char *empty_sockhost = "255.255.255.255"; | |
96 | static const char *spoofed_sockhost = "0"; | |
97 | ||
98 | /* | |
99 | * m_etrace | |
212380e3 AC |
100 | * parv[1] = options [or target] |
101 | * parv[2] = [target] | |
102 | */ | |
3c7d6fcc | 103 | static void |
428ca87b | 104 | mo_etrace(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
105 | { |
106 | if(parc > 1 && !EmptyString(parv[1])) | |
107 | { | |
108 | if(!irccmp(parv[1], "-full")) | |
109 | do_etrace_full(source_p); | |
ccda6e3f | 110 | #ifdef RB_IPV6 |
212380e3 AC |
111 | else if(!irccmp(parv[1], "-v6")) |
112 | do_etrace(source_p, 0, 1); | |
113 | else if(!irccmp(parv[1], "-v4")) | |
114 | do_etrace(source_p, 1, 0); | |
115 | #endif | |
116 | else | |
117 | { | |
118 | struct Client *target_p = find_named_person(parv[1]); | |
119 | ||
120 | if(target_p) | |
121 | { | |
122 | if(!MyClient(target_p)) | |
123 | sendto_one(target_p, ":%s ENCAP %s ETRACE %s", | |
124 | get_id(source_p, target_p), | |
c88cdb00 | 125 | target_p->servptr->name, |
212380e3 AC |
126 | get_id(target_p, target_p)); |
127 | else | |
128 | do_single_etrace(source_p, target_p); | |
129 | } | |
130 | else | |
131 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, | |
132 | form_str(ERR_NOSUCHNICK), parv[1]); | |
133 | } | |
134 | } | |
135 | else | |
136 | do_etrace(source_p, 1, 1); | |
212380e3 AC |
137 | } |
138 | ||
3c7d6fcc | 139 | static void |
428ca87b | 140 | me_etrace(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
141 | { |
142 | struct Client *target_p; | |
143 | ||
144 | if(!IsOper(source_p) || parc < 2 || EmptyString(parv[1])) | |
3c7d6fcc | 145 | return; |
212380e3 AC |
146 | |
147 | /* we cant etrace remote clients.. we shouldnt even get sent them */ | |
148 | if((target_p = find_person(parv[1])) && MyClient(target_p)) | |
149 | do_single_etrace(source_p, target_p); | |
150 | ||
55abcbb2 | 151 | sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), |
212380e3 | 152 | target_p ? target_p->name : parv[1]); |
212380e3 AC |
153 | } |
154 | ||
155 | static void | |
156 | do_etrace(struct Client *source_p, int ipv4, int ipv6) | |
157 | { | |
158 | struct Client *target_p; | |
5b96d9a6 | 159 | rb_dlink_node *ptr; |
212380e3 AC |
160 | |
161 | /* report all direct connections */ | |
5b96d9a6 | 162 | RB_DLINK_FOREACH(ptr, lclient_list.head) |
212380e3 AC |
163 | { |
164 | target_p = ptr->data; | |
165 | ||
ccda6e3f | 166 | #ifdef RB_IPV6 |
032ef5ef AC |
167 | if((!ipv4 && GET_SS_FAMILY(&target_p->localClient->ip) == AF_INET) || |
168 | (!ipv6 && GET_SS_FAMILY(&target_p->localClient->ip) == AF_INET6)) | |
212380e3 AC |
169 | continue; |
170 | #endif | |
171 | ||
172 | sendto_one(source_p, form_str(RPL_ETRACE), | |
55abcbb2 KB |
173 | me.name, source_p->name, |
174 | IsOper(target_p) ? "Oper" : "User", | |
212380e3 AC |
175 | get_client_class(target_p), |
176 | target_p->name, target_p->username, target_p->host, | |
177 | show_ip(source_p, target_p) ? target_p->sockhost : "255.255.255.255", | |
178 | target_p->info); | |
179 | } | |
180 | ||
181 | sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); | |
182 | } | |
183 | ||
184 | static void | |
185 | do_etrace_full(struct Client *source_p) | |
186 | { | |
5b96d9a6 | 187 | rb_dlink_node *ptr; |
212380e3 | 188 | |
5b96d9a6 | 189 | RB_DLINK_FOREACH(ptr, lclient_list.head) |
212380e3 AC |
190 | { |
191 | do_single_etrace(source_p, ptr->data); | |
192 | } | |
193 | ||
194 | sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); | |
195 | } | |
196 | ||
197 | /* | |
198 | * do_single_etrace - searches local clients and displays those matching | |
199 | * a pattern | |
200 | * input - source client, target client | |
201 | * output - etrace results | |
202 | * side effects - etrace results are displayed | |
203 | */ | |
204 | static void | |
205 | do_single_etrace(struct Client *source_p, struct Client *target_p) | |
206 | { | |
207 | /* note, we hide fullcaps for spoofed users, as mirc can often | |
208 | * advertise its internal ip address in the field --fl | |
209 | */ | |
210 | if(!show_ip(source_p, target_p)) | |
211 | sendto_one(source_p, form_str(RPL_ETRACEFULL), | |
55abcbb2 | 212 | me.name, source_p->name, |
212380e3 AC |
213 | IsOper(target_p) ? "Oper" : "User", |
214 | get_client_class(target_p), | |
55abcbb2 | 215 | target_p->name, target_p->username, target_p->host, |
212380e3 AC |
216 | "255.255.255.255", "<hidden> <hidden>", target_p->info); |
217 | else | |
218 | sendto_one(source_p, form_str(RPL_ETRACEFULL), | |
55abcbb2 | 219 | me.name, source_p->name, |
212380e3 AC |
220 | IsOper(target_p) ? "Oper" : "User", |
221 | get_client_class(target_p), | |
55abcbb2 | 222 | target_p->name, target_p->username, |
212380e3 AC |
223 | target_p->host, target_p->sockhost, |
224 | target_p->localClient->fullcaps, target_p->info); | |
225 | } | |
226 | ||
3c7d6fcc | 227 | static void |
428ca87b | 228 | m_chantrace(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
229 | { |
230 | struct Client *target_p; | |
231 | struct Channel *chptr; | |
232 | struct membership *msptr; | |
233 | const char *sockhost; | |
234 | const char *name; | |
5b96d9a6 | 235 | rb_dlink_node *ptr; |
212380e3 AC |
236 | int operspy = 0; |
237 | ||
238 | name = parv[1]; | |
239 | ||
240 | if(IsOperSpy(source_p) && parv[1][0] == '!') | |
241 | { | |
242 | name++; | |
243 | operspy = 1; | |
244 | ||
245 | if(EmptyString(name)) | |
246 | { | |
247 | sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), | |
248 | me.name, source_p->name, "CHANTRACE"); | |
3c7d6fcc | 249 | return; |
212380e3 AC |
250 | } |
251 | } | |
252 | ||
253 | if((chptr = find_channel(name)) == NULL) | |
254 | { | |
255 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), | |
256 | name); | |
3c7d6fcc | 257 | return; |
212380e3 AC |
258 | } |
259 | ||
260 | /* dont report operspys for nonexistant channels. */ | |
261 | if(operspy) | |
262 | report_operspy(source_p, "CHANTRACE", chptr->chname); | |
263 | ||
264 | if(!operspy && !IsMember(client_p, chptr)) | |
265 | { | |
266 | sendto_one_numeric(source_p, ERR_NOTONCHANNEL, form_str(ERR_NOTONCHANNEL), | |
267 | chptr->chname); | |
3c7d6fcc | 268 | return; |
212380e3 AC |
269 | } |
270 | ||
5b96d9a6 | 271 | RB_DLINK_FOREACH(ptr, chptr->members.head) |
212380e3 AC |
272 | { |
273 | msptr = ptr->data; | |
274 | target_p = msptr->client_p; | |
275 | ||
276 | if(EmptyString(target_p->sockhost)) | |
277 | sockhost = empty_sockhost; | |
278 | else if(!show_ip(source_p, target_p)) | |
279 | sockhost = spoofed_sockhost; | |
280 | else | |
281 | sockhost = target_p->sockhost; | |
282 | ||
283 | sendto_one(source_p, form_str(RPL_ETRACE), | |
55abcbb2 | 284 | me.name, source_p->name, |
212380e3 AC |
285 | IsOper(target_p) ? "Oper" : "User", |
286 | /* class field -- pretend its server.. */ | |
287 | target_p->servptr->name, | |
288 | target_p->name, target_p->username, target_p->host, | |
289 | sockhost, target_p->info); | |
290 | } | |
291 | ||
292 | sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); | |
212380e3 AC |
293 | } |
294 | ||
295 | static void | |
5b96d9a6 | 296 | match_masktrace(struct Client *source_p, rb_dlink_list *list, |
212380e3 AC |
297 | const char *username, const char *hostname, const char *name, |
298 | const char *gecos) | |
299 | { | |
300 | struct Client *target_p; | |
5b96d9a6 | 301 | rb_dlink_node *ptr; |
55abcbb2 KB |
302 | const char *sockhost; |
303 | ||
5b96d9a6 | 304 | RB_DLINK_FOREACH(ptr, list->head) |
212380e3 AC |
305 | { |
306 | target_p = ptr->data; | |
307 | if(!IsPerson(target_p)) | |
308 | continue; | |
55abcbb2 | 309 | |
212380e3 AC |
310 | if(EmptyString(target_p->sockhost)) |
311 | sockhost = empty_sockhost; | |
312 | else if(!show_ip(source_p, target_p)) | |
313 | sockhost = spoofed_sockhost; | |
314 | else | |
315 | sockhost = target_p->sockhost; | |
316 | ||
317 | if(match(username, target_p->username) && | |
318 | (match(hostname, target_p->host) || | |
319 | match(hostname, target_p->orighost) || | |
320 | match(hostname, sockhost) || match_ips(hostname, sockhost))) | |
321 | { | |
322 | if(name != NULL && !match(name, target_p->name)) | |
323 | continue; | |
324 | ||
39b23540 | 325 | if(gecos != NULL && !match_esc(gecos, target_p->info)) |
212380e3 | 326 | continue; |
55abcbb2 | 327 | |
212380e3 | 328 | sendto_one(source_p, form_str(RPL_ETRACE), |
55abcbb2 | 329 | me.name, source_p->name, |
212380e3 AC |
330 | IsOper(target_p) ? "Oper" : "User", |
331 | /* class field -- pretend its server.. */ | |
332 | target_p->servptr->name, | |
333 | target_p->name, target_p->username, target_p->host, | |
334 | sockhost, target_p->info); | |
335 | } | |
336 | } | |
337 | } | |
338 | ||
3c7d6fcc | 339 | static void |
428ca87b | 340 | mo_masktrace(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, |
212380e3 AC |
341 | const char *parv[]) |
342 | { | |
343 | char *name, *username, *hostname, *gecos; | |
344 | const char *mask; | |
345 | int operspy = 0; | |
346 | ||
55abcbb2 KB |
347 | mask = parv[1]; |
348 | name = LOCAL_COPY(parv[1]); | |
212380e3 AC |
349 | collapse(name); |
350 | ||
351 | if(IsOperSpy(source_p) && parv[1][0] == '!') | |
352 | { | |
353 | name++; | |
354 | mask++; | |
355 | operspy = 1; | |
55abcbb2 KB |
356 | } |
357 | ||
212380e3 AC |
358 | if(parc > 2 && !EmptyString(parv[2])) |
359 | { | |
360 | gecos = LOCAL_COPY(parv[2]); | |
361 | collapse_esc(gecos); | |
362 | } else | |
363 | gecos = NULL; | |
55abcbb2 | 364 | |
212380e3 AC |
365 | |
366 | if((hostname = strchr(name, '@')) == NULL) | |
367 | { | |
5366977b | 368 | sendto_one_notice(source_p, ":Invalid parameters"); |
3c7d6fcc | 369 | return; |
212380e3 AC |
370 | } |
371 | ||
372 | *hostname++ = '\0'; | |
55abcbb2 | 373 | |
212380e3 AC |
374 | if((username = strchr(name, '!')) == NULL) |
375 | { | |
376 | username = name; | |
377 | name = NULL; | |
378 | } else | |
379 | *username++ = '\0'; | |
380 | ||
381 | if(EmptyString(username) || EmptyString(hostname)) | |
382 | { | |
5366977b | 383 | sendto_one_notice(source_p, ":Invalid parameters"); |
3c7d6fcc | 384 | return; |
212380e3 | 385 | } |
55abcbb2 | 386 | |
212380e3 AC |
387 | if(operspy) { |
388 | if (!ConfigFileEntry.operspy_dont_care_user_info) | |
389 | { | |
390 | char buf[512]; | |
f427c8b0 | 391 | rb_strlcpy(buf, mask, sizeof(buf)); |
212380e3 | 392 | if(!EmptyString(gecos)) { |
1f9de103 VY |
393 | rb_strlcat(buf, " ", sizeof(buf)); |
394 | rb_strlcat(buf, gecos, sizeof(buf)); | |
55abcbb2 | 395 | } |
212380e3 | 396 | |
55abcbb2 | 397 | report_operspy(source_p, "MASKTRACE", buf); |
212380e3 | 398 | } |
55abcbb2 | 399 | match_masktrace(source_p, &global_client_list, username, hostname, name, gecos); |
212380e3 AC |
400 | } else |
401 | match_masktrace(source_p, &lclient_list, username, hostname, name, gecos); | |
402 | ||
55abcbb2 | 403 | sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); |
212380e3 | 404 | } |